Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TMVAClassification_Cuts.class.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TMVAClassification_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.1 [262657]
11 ROOT Release : 6.22/02 [398850]
12 Creator : cdean
13 Date : Tue Apr 20 16:38:02 2021
14 Host : Linux cvmfswrite02.sdcc.bnl.gov 3.10.0-957.12.2.el7.x86_64 #1 SMP Tue May 14 15:23:27 CDT 2019 x86_64 x86_64 x86_64 GNU/Linux
15 Dir : /gpfs/mnt/gpfs02/sphenix/user/cdean/scripts/HF_trigger_ML/TMVA/Odd/wCalo
16 Training events: 31922
17 Analysis type : [Classification]
18 
19 
20 #OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-
21 
22 # Set by User:
23 V: "False" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
24 H: "False" [Print method-specific help message]
25 FitMethod: "MC" [Minimisation Method (GA, SA, and MC are the primary methods to be used; the others have been introduced for testing purposes and are depreciated)]
26 EffMethod: "EffSel" [Selection Method]
27 # Default:
28 VerbosityLevel: "Default" [Verbosity level]
29 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)"]
30 CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
31 IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
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]: "FSmart" [Categorisation of cuts]
41  VarProp[1]: "FSmart"
42  VarProp[2]: "FSmart"
43  VarProp[3]: "FSmart"
44 ##
45 
46 
47 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
48 
49 NVar 4
50 max(track_1_IP,track_2_IP) maxTrackDCA_3D maxTrackDCA_3D track-vertex 3D DCA, max units 'F' [0.00383873376995,4.99581956863]
51 max(abs(track_1_IP_xy),abs(track_2_IP_xy)) maxTrackDCA_2D maxTrackDCA_2D track-vertex 2D DCA, max units 'F' [9.33057162911e-05,4.8996257782]
52 track_1_track_2_DCA track_1_track_2_DCA track_1_track_2_DCA track-track 3D DCA units 'F' [1.57269468559e-07,0.0499997623265]
53 INTT_meanHits INTT_meanHits INTT_meanHits INTT avg. hits units 'F' [0,93]
54 NSpec 0
55 
56 
57 ============================================================================ */
58 
59 #include <array>
60 #include <vector>
61 #include <cmath>
62 #include <string>
63 #include <iostream>
64 
65 #ifndef IClassifierReader__def
66 #define IClassifierReader__def
67 
68 class IClassifierReader {
69 
70  public:
71 
72  // constructor
74  virtual ~IClassifierReader() {}
75 
76  // return classifier response
77  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
78 
79  // returns classifier status
80  bool IsStatusClean() const { return fStatusIsClean; }
81 
82  protected:
83 
84  bool fStatusIsClean;
85 };
86 
87 #endif
88 
89 class ReadCuts : public IClassifierReader {
90 
91  public:
92 
93  // constructor
94  ReadCuts( std::vector<std::string>& theInputVars )
96  fClassName( "ReadCuts" ),
97  fNvars( 4 )
98  {
99  // the training input variables
100  const char* inputVars[] = { "max(track_1_IP,track_2_IP)", "max(abs(track_1_IP_xy),abs(track_2_IP_xy))", "track_1_track_2_DCA", "INTT_meanHits" };
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] = 'F';
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 override;
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  double fVmin[4];
168  double fVmax[4];
169  double NormVariable( double x, double xmin, double xmax ) const {
170  // normalise to output range: [-1, 1]
171  return 2*(x - xmin)/(xmax - xmin) - 1.0;
172  }
173 
174  // type of input variable: 'F' or 'I'
175  char fType[4];
176 
177  // initialize internal variables
178  void Initialize();
179  double GetMvaValue__( const std::vector<double>& inputValues ) const;
180 
181  // private members (method specific)
182  // not implemented for class: "ReadCuts"
183 };
184 inline double ReadCuts::GetMvaValue( const std::vector<double>& inputValues ) const
185 {
186  // classifier response value
187  double retval = 0;
188 
189  // classifier response, sanity check first
190  if (!IsStatusClean()) {
191  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
192  << " because status is dirty" << std::endl;
193  }
194  else {
195  retval = GetMvaValue__( inputValues );
196  }
197 
198  return retval;
199 }