Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hback_Cuts.class.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file hback_Cuts.class.C
1 // Class: ReadCuts
2 // Automatically generated by MethodBase::MakeClass
3 //
4 
5 /* configuration options =====================================================
6 
7 #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8 
9 Method : Cuts::Cuts
10 TMVA Release : 4.2.0 [262656]
11 ROOT Release : 5.34/38 [336422]
12 Creator : vassalli
13 Date : Wed Jan 23 17:59:24 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 FitMethod: "GA" [Minimisation Method (GA, SA, and MC are the primary methods to be used; the others have been introduced for testing purposes and are depreciated)]
31 EffMethod: "EffSel" [Selection Method]
32 CutRangeMin[0]: "-1.000000e+00" [Minimum of allowed cut range (set per variable)]
33  CutRangeMin[1]: "-1.000000e+00"
34  CutRangeMin[2]: "-1.000000e+00"
35  CutRangeMin[3]: "-1.000000e+00"
36  CutRangeMin[4]: "-1.000000e+00"
37  CutRangeMin[5]: "-1.000000e+00"
38  CutRangeMin[6]: "-1.000000e+00"
39 CutRangeMax[0]: "-1.000000e+00" [Maximum of allowed cut range (set per variable)]
40  CutRangeMax[1]: "-1.000000e+00"
41  CutRangeMax[2]: "-1.000000e+00"
42  CutRangeMax[3]: "-1.000000e+00"
43  CutRangeMax[4]: "-1.000000e+00"
44  CutRangeMax[5]: "-1.000000e+00"
45  CutRangeMax[6]: "-1.000000e+00"
46 VarProp[0]: "NotEnforced" [Categorisation of cuts]
47  VarProp[1]: "NotEnforced"
48  VarProp[2]: "NotEnforced"
49  VarProp[3]: "NotEnforced"
50  VarProp[4]: "NotEnforced"
51  VarProp[5]: "NotEnforced"
52  VarProp[6]: "NotEnforced"
53 ##
54 
55 
56 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
57 
58 NVar 7
59 track_deta track_deta track_deta track_deta 'F' [1.05425715446e-06,1.83402311802]
60 track_dlayer track_dlayer track_dlayer track_dlayer 'I' [0,14]
61 track_layer track_layer track_layer track_layer 'I' [0,23]
62 track_pT track_pT track_pT track_pT 'F' [0.209833949804,34.1584281921]
63 vtx_radius vtx_radius vtx_radius vtx_radius 'F' [0.00339345191605,20.9999389648]
64 vtxTrack_dist vtxTrack_dist vtxTrack_dist vtxTrack_dist 'F' [0.0258899498731,10.0588207245]
65 cluster_prob cluster_prob cluster_prob cluster_prob 'F' [0,0.999874174595]
66 NSpec 1
67 vtx_chi2 vtx_chi2 vtx_chi2 F 'F' [0,3.33078734987e-36]
68 
69 
70 ============================================================================ */
71 
72 #include <vector>
73 #include <cmath>
74 #include <string>
75 #include <iostream>
76 
77 #ifndef IClassifierReader__def
78 #define IClassifierReader__def
79 
80 class IClassifierReader {
81 
82  public:
83 
84  // constructor
86  virtual ~IClassifierReader() {}
87 
88  // return classifier response
89  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
90 
91  // returns classifier status
92  bool IsStatusClean() const { return fStatusIsClean; }
93 
94  protected:
95 
96  bool fStatusIsClean;
97 };
98 
99 #endif
100 
101 class ReadCuts : public IClassifierReader {
102 
103  public:
104 
105  // constructor
106  ReadCuts( std::vector<std::string>& theInputVars )
107  : IClassifierReader(),
108  fClassName( "ReadCuts" ),
109  fNvars( 7 ),
111  {
112  // the training input variables
113  const char* inputVars[] = { "track_deta", "track_dlayer", "track_layer", "track_pT", "vtx_radius", "vtxTrack_dist", "cluster_prob" };
114 
115  // sanity checks
116  if (theInputVars.size() <= 0) {
117  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
118  fStatusIsClean = false;
119  }
120 
121  if (theInputVars.size() != fNvars) {
122  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
123  << theInputVars.size() << " != " << fNvars << std::endl;
124  fStatusIsClean = false;
125  }
126 
127  // validate input variables
128  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
129  if (theInputVars[ivar] != inputVars[ivar]) {
130  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
131  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
132  fStatusIsClean = false;
133  }
134  }
135 
136  // initialize min and max vectors (for normalisation)
137  fVmin[0] = 0;
138  fVmax[0] = 0;
139  fVmin[1] = 0;
140  fVmax[1] = 0;
141  fVmin[2] = 0;
142  fVmax[2] = 0;
143  fVmin[3] = 0;
144  fVmax[3] = 0;
145  fVmin[4] = 0;
146  fVmax[4] = 0;
147  fVmin[5] = 0;
148  fVmax[5] = 0;
149  fVmin[6] = 0;
150  fVmax[6] = 0;
151 
152  // initialize input variable types
153  fType[0] = 'F';
154  fType[1] = 'I';
155  fType[2] = 'I';
156  fType[3] = 'F';
157  fType[4] = 'F';
158  fType[5] = 'F';
159  fType[6] = 'F';
160 
161  // initialize constants
162  Initialize();
163 
164  }
165 
166  // destructor
167  virtual ~ReadCuts() {
168  Clear(); // method-specific
169  }
170 
171  // the classifier response
172  // "inputValues" is a vector of input values in the same order as the
173  // variables given to the constructor
174  double GetMvaValue( const std::vector<double>& inputValues ) const;
175 
176  private:
177 
178  // method-specific destructor
179  void Clear();
180 
181  // common member variables
182  const char* fClassName;
183 
184  const size_t fNvars;
185  size_t GetNvar() const { return fNvars; }
186  char GetType( int ivar ) const { return fType[ivar]; }
187 
188  // normalisation of input variables
189  const bool fIsNormalised;
190  bool IsNormalised() const { return fIsNormalised; }
191  double fVmin[7];
192  double fVmax[7];
193  double NormVariable( double x, double xmin, double xmax ) const {
194  // normalise to output range: [-1, 1]
195  return 2*(x - xmin)/(xmax - xmin) - 1.0;
196  }
197 
198  // type of input variable: 'F' or 'I'
199  char fType[7];
200 
201  // initialize internal variables
202  void Initialize();
203  double GetMvaValue__( const std::vector<double>& inputValues ) const;
204 
205  // private members (method specific)
206  // not implemented for class: "ReadCuts"
207 };
208  inline double ReadCuts::GetMvaValue( const std::vector<double>& inputValues ) const
209  {
210  // classifier response value
211  double retval = 0;
212 
213  // classifier response, sanity check first
214  if (!IsStatusClean()) {
215  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
216  << " because status is dirty" << std::endl;
217  retval = 0;
218  }
219  else {
220  if (IsNormalised()) {
221  // normalise variables
222  std::vector<double> iV;
223  iV.reserve(inputValues.size());
224  int ivar = 0;
225  for (std::vector<double>::const_iterator varIt = inputValues.begin();
226  varIt != inputValues.end(); varIt++, ivar++) {
227  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
228  }
229  retval = GetMvaValue__( iV );
230  }
231  else {
232  retval = GetMvaValue__( inputValues );
233  }
234  }
235 
236  return retval;
237  }