Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eback_LD.class.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eback_LD.class.C
1 // Class: ReadLD
2 // Automatically generated by MethodBase::MakeClass
3 //
4 
5 /* configuration options =====================================================
6 
7 #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8 
9 Method : LD::LD
10 TMVA Release : 4.2.0 [262656]
11 ROOT Release : 5.34/38 [336422]
12 Creator : vassalli
13 Date : Wed Jan 23 17:52:07 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: 2540
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 ##
31 
32 
33 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
34 
35 NVar 10
36 track_deta track_deta track_deta track_deta 'F' [4.76837158203e-07,1.92375802994]
37 track_dlayer track_dlayer track_dlayer track_dlayer 'I' [0,14]
38 track_layer track_layer track_layer track_layer 'I' [0,23]
39 track_pT track_pT track_pT track_pT 'F' [0.238087445498,34.1584281921]
40 approach_dist approach_dist approach_dist approach_dist 'F' [1.40332131195e-05,12.8133029938]
41 vtx_radius vtx_radius vtx_radius vtx_radius 'F' [5.07211098011e-06,20.9999389648]
42 vtxTrack_dist vtxTrack_dist vtxTrack_dist vtxTrack_dist 'F' [0.0258899498731,8.61121940613]
43 photon_m photon_m photon_m photon_m 'F' [1.044480443,713.936157227]
44 photon_pT photon_pT photon_pT photon_pT 'F' [0.0209014415741,5008.76708984]
45 cluster_prob cluster_prob cluster_prob cluster_prob 'F' [0,0.999874174595]
46 NSpec 1
47 vtx_chi2 vtx_chi2 vtx_chi2 F 'F' [0,3.33078734987e-36]
48 
49 
50 ============================================================================ */
51 
52 #include <vector>
53 #include <cmath>
54 #include <string>
55 #include <iostream>
56 
57 #ifndef IClassifierReader__def
58 #define IClassifierReader__def
59 
60 class IClassifierReader {
61 
62  public:
63 
64  // constructor
66  virtual ~IClassifierReader() {}
67 
68  // return classifier response
69  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
70 
71  // returns classifier status
72  bool IsStatusClean() const { return fStatusIsClean; }
73 
74  protected:
75 
76  bool fStatusIsClean;
77 };
78 
79 #endif
80 
81 class ReadLD : public IClassifierReader {
82 
83  public:
84 
85  // constructor
86  ReadLD( std::vector<std::string>& theInputVars )
88  fClassName( "ReadLD" ),
89  fNvars( 10 ),
91  {
92  // the training input variables
93  const char* inputVars[] = { "track_deta", "track_dlayer", "track_layer", "track_pT", "approach_dist", "vtx_radius", "vtxTrack_dist", "photon_m", "photon_pT", "cluster_prob" };
94 
95  // sanity checks
96  if (theInputVars.size() <= 0) {
97  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
98  fStatusIsClean = false;
99  }
100 
101  if (theInputVars.size() != fNvars) {
102  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
103  << theInputVars.size() << " != " << fNvars << std::endl;
104  fStatusIsClean = false;
105  }
106 
107  // validate input variables
108  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
109  if (theInputVars[ivar] != inputVars[ivar]) {
110  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
111  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
112  fStatusIsClean = false;
113  }
114  }
115 
116  // initialize min and max vectors (for normalisation)
117  fVmin[0] = 0;
118  fVmax[0] = 0;
119  fVmin[1] = 0;
120  fVmax[1] = 0;
121  fVmin[2] = 0;
122  fVmax[2] = 0;
123  fVmin[3] = 0;
124  fVmax[3] = 0;
125  fVmin[4] = 0;
126  fVmax[4] = 0;
127  fVmin[5] = 0;
128  fVmax[5] = 0;
129  fVmin[6] = 0;
130  fVmax[6] = 0;
131  fVmin[7] = 0;
132  fVmax[7] = 0;
133  fVmin[8] = 0;
134  fVmax[8] = 0;
135  fVmin[9] = 0;
136  fVmax[9] = 0;
137 
138  // initialize input variable types
139  fType[0] = 'F';
140  fType[1] = 'I';
141  fType[2] = 'I';
142  fType[3] = 'F';
143  fType[4] = 'F';
144  fType[5] = 'F';
145  fType[6] = 'F';
146  fType[7] = 'F';
147  fType[8] = 'F';
148  fType[9] = 'F';
149 
150  // initialize constants
151  Initialize();
152 
153  }
154 
155  // destructor
156  virtual ~ReadLD() {
157  Clear(); // method-specific
158  }
159 
160  // the classifier response
161  // "inputValues" is a vector of input values in the same order as the
162  // variables given to the constructor
163  double GetMvaValue( const std::vector<double>& inputValues ) const;
164 
165  private:
166 
167  // method-specific destructor
168  void Clear();
169 
170  // common member variables
171  const char* fClassName;
172 
173  const size_t fNvars;
174  size_t GetNvar() const { return fNvars; }
175  char GetType( int ivar ) const { return fType[ivar]; }
176 
177  // normalisation of input variables
178  const bool fIsNormalised;
179  bool IsNormalised() const { return fIsNormalised; }
180  double fVmin[10];
181  double fVmax[10];
182  double NormVariable( double x, double xmin, double xmax ) const {
183  // normalise to output range: [-1, 1]
184  return 2*(x - xmin)/(xmax - xmin) - 1.0;
185  }
186 
187  // type of input variable: 'F' or 'I'
188  char fType[10];
189 
190  // initialize internal variables
191  void Initialize();
192  double GetMvaValue__( const std::vector<double>& inputValues ) const;
193 
194  // private members (method specific)
195  std::vector<double> fLDCoefficients;
196 };
197 
198 inline void ReadLD::Initialize()
199 {
200  fLDCoefficients.push_back( -0.103337323692 );
201  fLDCoefficients.push_back( -0.11719017447 );
202  fLDCoefficients.push_back( -0.0902872860029 );
203  fLDCoefficients.push_back( 0.135020960387 );
204  fLDCoefficients.push_back( 0.0219393769769 );
205  fLDCoefficients.push_back( -0.0092373246713 );
206  fLDCoefficients.push_back( 0.00572440018382 );
207  fLDCoefficients.push_back( -0.0847369223905 );
208  fLDCoefficients.push_back( -0.000454128861645 );
209  fLDCoefficients.push_back( 3.23480379708e-05 );
210  fLDCoefficients.push_back( 0.0888983090497 );
211 
212  // sanity check
213  if (fLDCoefficients.size() != fNvars+1) {
214  std::cout << "Problem in class \"" << fClassName << "\"::Initialize: mismatch in number of input values"
215  << fLDCoefficients.size() << " != " << fNvars+1 << std::endl;
216  fStatusIsClean = false;
217  }
218 }
219 
220 inline double ReadLD::GetMvaValue__( const std::vector<double>& inputValues ) const
221 {
222  double retval = fLDCoefficients[0];
223  for (size_t ivar = 1; ivar < fNvars+1; ivar++) {
224  retval += fLDCoefficients[ivar]*inputValues[ivar-1];
225  }
226 
227  return retval;
228 }
229 
230 // Clean up
231 inline void ReadLD::Clear()
232 {
233  // clear coefficients
234  fLDCoefficients.clear();
235 }
236  inline double ReadLD::GetMvaValue( const std::vector<double>& inputValues ) const
237  {
238  // classifier response value
239  double retval = 0;
240 
241  // classifier response, sanity check first
242  if (!IsStatusClean()) {
243  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
244  << " because status is dirty" << std::endl;
245  retval = 0;
246  }
247  else {
248  if (IsNormalised()) {
249  // normalise variables
250  std::vector<double> iV;
251  iV.reserve(inputValues.size());
252  int ivar = 0;
253  for (std::vector<double>::const_iterator varIt = inputValues.begin();
254  varIt != inputValues.end(); varIt++, ivar++) {
255  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
256  }
257  retval = GetMvaValue__( iV );
258  }
259  else {
260  retval = GetMvaValue__( inputValues );
261  }
262  }
263 
264  return retval;
265  }