Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trackback_Cuts.class.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file trackback_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 : Fri Aug 23 18:23:25 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: 7408
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 CutRangeMax[0]: "-1.000000e+00" [Maximum of allowed cut range (set per variable)]
37  CutRangeMax[1]: "-1.000000e+00"
38  CutRangeMax[2]: "-1.000000e+00"
39  CutRangeMax[3]: "-1.000000e+00"
40 VarProp[0]: "NotEnforced" [Categorisation of cuts]
41  VarProp[1]: "NotEnforced"
42  VarProp[2]: "NotEnforced"
43  VarProp[3]: "NotEnforced"
44 ##
45 
46 
47 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
48 
49 NVar 4
50 track_layer track_layer track_layer track_layer 'I' [0,23]
51 track_pT track_pT track_pT track_pT 'F' [2.00562024117,23268.8671875]
52 track_dca track_dca track_dca track_dca 'F' [1.9280396657e-07,64.1147155762]
53 cluster_prob cluster_prob cluster_prob cluster_prob 'F' [0,0.999049782753]
54 NSpec 0
55 
56 
57 ============================================================================ */
58 
59 #include <vector>
60 #include <cmath>
61 #include <string>
62 #include <iostream>
63 
64 #ifndef IClassifierReader__def
65 #define IClassifierReader__def
66 
67 class IClassifierReader {
68 
69  public:
70 
71  // constructor
73  virtual ~IClassifierReader() {}
74 
75  // return classifier response
76  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
77 
78  // returns classifier status
79  bool IsStatusClean() const { return fStatusIsClean; }
80 
81  protected:
82 
83  bool fStatusIsClean;
84 };
85 
86 #endif
87 
88 class ReadCuts : public IClassifierReader {
89 
90  public:
91 
92  // constructor
93  ReadCuts( std::vector<std::string>& theInputVars )
95  fClassName( "ReadCuts" ),
96  fNvars( 4 ),
98  {
99  // the training input variables
100  const char* inputVars[] = { "track_layer", "track_pT", "track_dca", "cluster_prob" };
101 
102  // sanity checks
103  if (theInputVars.size() <= 0) {
104  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
105  fStatusIsClean = false;
106  }
107 
108  if (theInputVars.size() != fNvars) {
109  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
110  << theInputVars.size() << " != " << fNvars << std::endl;
111  fStatusIsClean = false;
112  }
113 
114  // validate input variables
115  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
116  if (theInputVars[ivar] != inputVars[ivar]) {
117  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
118  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
119  fStatusIsClean = false;
120  }
121  }
122 
123  // initialize min and max vectors (for normalisation)
124  fVmin[0] = 0;
125  fVmax[0] = 0;
126  fVmin[1] = 0;
127  fVmax[1] = 0;
128  fVmin[2] = 0;
129  fVmax[2] = 0;
130  fVmin[3] = 0;
131  fVmax[3] = 0;
132 
133  // initialize input variable types
134  fType[0] = 'I';
135  fType[1] = 'F';
136  fType[2] = 'F';
137  fType[3] = 'F';
138 
139  // initialize constants
140  Initialize();
141 
142  }
143 
144  // destructor
145  virtual ~ReadCuts() {
146  Clear(); // method-specific
147  }
148 
149  // the classifier response
150  // "inputValues" is a vector of input values in the same order as the
151  // variables given to the constructor
152  double GetMvaValue( const std::vector<double>& inputValues ) const;
153 
154  private:
155 
156  // method-specific destructor
157  void Clear();
158 
159  // common member variables
160  const char* fClassName;
161 
162  const size_t fNvars;
163  size_t GetNvar() const { return fNvars; }
164  char GetType( int ivar ) const { return fType[ivar]; }
165 
166  // normalisation of input variables
167  const bool fIsNormalised;
168  bool IsNormalised() const { return fIsNormalised; }
169  double fVmin[4];
170  double fVmax[4];
171  double NormVariable( double x, double xmin, double xmax ) const {
172  // normalise to output range: [-1, 1]
173  return 2*(x - xmin)/(xmax - xmin) - 1.0;
174  }
175 
176  // type of input variable: 'F' or 'I'
177  char fType[4];
178 
179  // initialize internal variables
180  void Initialize();
181  double GetMvaValue__( const std::vector<double>& inputValues ) const;
182 
183  // private members (method specific)
184  // not implemented for class: "ReadCuts"
185 };
186  inline double ReadCuts::GetMvaValue( const std::vector<double>& inputValues ) const
187  {
188  // classifier response value
189  double retval = 0;
190 
191  // classifier response, sanity check first
192  if (!IsStatusClean()) {
193  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
194  << " because status is dirty" << std::endl;
195  retval = 0;
196  }
197  else {
198  if (IsNormalised()) {
199  // normalise variables
200  std::vector<double> iV;
201  iV.reserve(inputValues.size());
202  int ivar = 0;
203  for (std::vector<double>::const_iterator varIt = inputValues.begin();
204  varIt != inputValues.end(); varIt++, ivar++) {
205  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
206  }
207  retval = GetMvaValue__( iV );
208  }
209  else {
210  retval = GetMvaValue__( inputValues );
211  }
212  }
213 
214  return retval;
215  }