Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hback_Fisher.class.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file hback_Fisher.class.C
1 // Class: ReadFisher
2 // Automatically generated by MethodBase::MakeClass
3 //
4 
5 /* configuration options =====================================================
6 
7 #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8 
9 Method : Fisher::Fisher
10 TMVA Release : 4.2.0 [262656]
11 ROOT Release : 5.34/38 [336422]
12 Creator : vassalli
13 Date : Wed Jan 23 17:51:47 2019
14 Host : Linux cvmfswrite02.sdcc.bnl.gov 3.10.0-693.11.6.el7.x86_64 #1 SMP Wed Jan 3 18:09:42 CST 2018 x86_64 x86_64 x86_64 GNU/Linux
15 Dir : /direct/phenix+u/vassalli/sphenix/single/Training
16 Training events: 2407
17 Analysis type : [Classification]
18 
19 
20 #OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-
21 
22 # Set by User:
23 # Default:
24 V: "False" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
25 VerbosityLevel: "Default" [Verbosity level]
26 VarTransform: "None" [List of variable transformations performed before training, e.g., "D_Background,P_Signal,G,N_AllClasses" for: "Decorrelation, PCA-transformation, Gaussianisation, Normalisation, each for the given class of events ('AllClasses' denotes all events of all classes, if no class indication is given, 'All' is assumed)"]
27 H: "False" [Print method-specific help message]
28 CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
29 IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
30 Method: "Fisher" [Discrimination method]
31 ##
32 
33 
34 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
35 
36 NVar 10
37 track_deta track_deta track_deta track_deta 'F' [1.05425715446e-06,1.83402311802]
38 track_dlayer track_dlayer track_dlayer track_dlayer 'I' [0,14]
39 track_layer track_layer track_layer track_layer 'I' [0,23]
40 track_pT track_pT track_pT track_pT 'F' [0.209833949804,34.1584281921]
41 approach_dist approach_dist approach_dist approach_dist 'F' [1.69032391568e-05,12.8133029938]
42 vtx_radius vtx_radius vtx_radius vtx_radius 'F' [0.00339345191605,20.9999389648]
43 vtxTrack_dist vtxTrack_dist vtxTrack_dist vtxTrack_dist 'F' [0.0258899498731,10.0588207245]
44 photon_m photon_m photon_m photon_m 'F' [1.044480443,713.936157227]
45 photon_pT photon_pT photon_pT photon_pT 'F' [0.061235960573,5008.76708984]
46 cluster_prob cluster_prob cluster_prob cluster_prob 'F' [0,0.999874174595]
47 NSpec 1
48 vtx_chi2 vtx_chi2 vtx_chi2 F 'F' [0,3.33078734987e-36]
49 
50 
51 ============================================================================ */
52 
53 #include <vector>
54 #include <cmath>
55 #include <string>
56 #include <iostream>
57 
58 #ifndef IClassifierReader__def
59 #define IClassifierReader__def
60 
61 class IClassifierReader {
62 
63  public:
64 
65  // constructor
67  virtual ~IClassifierReader() {}
68 
69  // return classifier response
70  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
71 
72  // returns classifier status
73  bool IsStatusClean() const { return fStatusIsClean; }
74 
75  protected:
76 
77  bool fStatusIsClean;
78 };
79 
80 #endif
81 
82 class ReadFisher : public IClassifierReader {
83 
84  public:
85 
86  // constructor
87  ReadFisher( std::vector<std::string>& theInputVars )
89  fClassName( "ReadFisher" ),
90  fNvars( 10 ),
92  {
93  // the training input variables
94  const char* inputVars[] = { "track_deta", "track_dlayer", "track_layer", "track_pT", "approach_dist", "vtx_radius", "vtxTrack_dist", "photon_m", "photon_pT", "cluster_prob" };
95 
96  // sanity checks
97  if (theInputVars.size() <= 0) {
98  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
99  fStatusIsClean = false;
100  }
101 
102  if (theInputVars.size() != fNvars) {
103  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
104  << theInputVars.size() << " != " << fNvars << std::endl;
105  fStatusIsClean = false;
106  }
107 
108  // validate input variables
109  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
110  if (theInputVars[ivar] != inputVars[ivar]) {
111  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
112  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
113  fStatusIsClean = false;
114  }
115  }
116 
117  // initialize min and max vectors (for normalisation)
118  fVmin[0] = 0;
119  fVmax[0] = 0;
120  fVmin[1] = 0;
121  fVmax[1] = 0;
122  fVmin[2] = 0;
123  fVmax[2] = 0;
124  fVmin[3] = 0;
125  fVmax[3] = 0;
126  fVmin[4] = 0;
127  fVmax[4] = 0;
128  fVmin[5] = 0;
129  fVmax[5] = 0;
130  fVmin[6] = 0;
131  fVmax[6] = 0;
132  fVmin[7] = 0;
133  fVmax[7] = 0;
134  fVmin[8] = 0;
135  fVmax[8] = 0;
136  fVmin[9] = 0;
137  fVmax[9] = 0;
138 
139  // initialize input variable types
140  fType[0] = 'F';
141  fType[1] = 'I';
142  fType[2] = 'I';
143  fType[3] = 'F';
144  fType[4] = 'F';
145  fType[5] = 'F';
146  fType[6] = 'F';
147  fType[7] = 'F';
148  fType[8] = 'F';
149  fType[9] = 'F';
150 
151  // initialize constants
152  Initialize();
153 
154  }
155 
156  // destructor
157  virtual ~ReadFisher() {
158  Clear(); // method-specific
159  }
160 
161  // the classifier response
162  // "inputValues" is a vector of input values in the same order as the
163  // variables given to the constructor
164  double GetMvaValue( const std::vector<double>& inputValues ) const;
165 
166  private:
167 
168  // method-specific destructor
169  void Clear();
170 
171  // common member variables
172  const char* fClassName;
173 
174  const size_t fNvars;
175  size_t GetNvar() const { return fNvars; }
176  char GetType( int ivar ) const { return fType[ivar]; }
177 
178  // normalisation of input variables
179  const bool fIsNormalised;
180  bool IsNormalised() const { return fIsNormalised; }
181  double fVmin[10];
182  double fVmax[10];
183  double NormVariable( double x, double xmin, double xmax ) const {
184  // normalise to output range: [-1, 1]
185  return 2*(x - xmin)/(xmax - xmin) - 1.0;
186  }
187 
188  // type of input variable: 'F' or 'I'
189  char fType[10];
190 
191  // initialize internal variables
192  void Initialize();
193  double GetMvaValue__( const std::vector<double>& inputValues ) const;
194 
195  // private members (method specific)
196  double fFisher0;
197  std::vector<double> fFisherCoefficients;
198 };
199 
200 inline void ReadFisher::Initialize()
201 {
202  fFisher0 = -0.0844739600992;
203  fFisherCoefficients.push_back( -1.43051579213 );
204  fFisherCoefficients.push_back( -0.269539620647 );
205  fFisherCoefficients.push_back( 0.402262492209 );
206  fFisherCoefficients.push_back( 0.114840085395 );
207  fFisherCoefficients.push_back( -0.0512308893762 );
208  fFisherCoefficients.push_back( 0.0867003372772 );
209  fFisherCoefficients.push_back( -0.312953668051 );
210  fFisherCoefficients.push_back( -0.00686129058321 );
211  fFisherCoefficients.push_back( 0.000764347437541 );
212  fFisherCoefficients.push_back( -0.614808771127 );
213 
214  // sanity check
215  if (fFisherCoefficients.size() != fNvars) {
216  std::cout << "Problem in class \"" << fClassName << "\"::Initialize: mismatch in number of input values"
217  << fFisherCoefficients.size() << " != " << fNvars << std::endl;
218  fStatusIsClean = false;
219  }
220 }
221 
222 inline double ReadFisher::GetMvaValue__( const std::vector<double>& inputValues ) const
223 {
224  double retval = fFisher0;
225  for (size_t ivar = 0; ivar < fNvars; ivar++) {
226  retval += fFisherCoefficients[ivar]*inputValues[ivar];
227  }
228 
229  return retval;
230 }
231 
232 // Clean up
233 inline void ReadFisher::Clear()
234 {
235  // clear coefficients
236  fFisherCoefficients.clear();
237 }
238  inline double ReadFisher::GetMvaValue( const std::vector<double>& inputValues ) const
239  {
240  // classifier response value
241  double retval = 0;
242 
243  // classifier response, sanity check first
244  if (!IsStatusClean()) {
245  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
246  << " because status is dirty" << std::endl;
247  retval = 0;
248  }
249  else {
250  if (IsNormalised()) {
251  // normalise variables
252  std::vector<double> iV;
253  iV.reserve(inputValues.size());
254  int ivar = 0;
255  for (std::vector<double>::const_iterator varIt = inputValues.begin();
256  varIt != inputValues.end(); varIt++, ivar++) {
257  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
258  }
259  retval = GetMvaValue__( iV );
260  }
261  else {
262  retval = GetMvaValue__( inputValues );
263  }
264  }
265 
266  return retval;
267  }