CosmicRejBDTVars.cxx
Go to the documentation of this file.
2 
4 #include "CAFAna/Vars/BPFVars.h"
6 #include "TMVA/Reader.h"
8 
9 namespace ana
10 {
11  // --- Some Vars that I want internally within my BDT computations.
12  // --- Min Kal / Cos Trk Cell
13  const Var kMinTrkCell([](const caf::SRProxy* sr) {
14  float CosCell = kCosmicForwardCell(sr) + kCosmicBackwardCell(sr);
15  float KalCell = kKalmanForwardCell(sr) + kKalmanBackwardCell(sr);
16  return std::min( CosCell, KalCell );
17  });
18 
19  // --- Kalman hit ratio.
20  const Var kKalHitRat([](const caf::SRProxy* sr) {
21  if(sr->trk.kalman.ntracks < 1) return -5.f;
22  float TrkHit = kTrkNhits(sr);
23  float SlcHit = kNHit(sr);
24  return TrkHit / SlcHit;
25  });
26  // --- Max Kal Trk Start / End Y
27  const Var kMaxKalTrStEnY([](const caf::SRProxy* sr) {
28  return std::max(kTrkStartY(sr), kTrkEndY(sr) );
29  });
30 
31  // --- BPF hit ratio.
32  const Var kBPFHitRat([](const caf::SRProxy* sr) {
33  float BPFHit = kBPFBestMuonNhits(sr);
34  float SlcHit = kNHit(sr);
35  if ( BPFHit == -5 )
36  return BPFHit;
37  else
38  return BPFHit / SlcHit;
39  });
40  // --- Max BPF Start / End Y
41  const Var kMaxBPFStEnY([](const caf::SRProxy* sr) {
43  });
44 
45  // --- Is this a neutrino interaction?
46  const Var kIsNuVar([](const caf::SRProxy* sr) {
47  if (sr->mc.nnu == 0) return -1;
48  if (sr->mc.nu[0].pdg > 0) { return 1; }
49  else { return 0; }
50  });
51  // --- Is this a CC interaction?
52  const Var kIsCCVar([](const caf::SRProxy* sr) {
53  if (sr->mc.nnu == 0) return -1;
54  if (sr->mc.nu[0].iscc) { return 1; }
55  else { return 0; }
56  });
57  // --- Is this a NuMu interaction?
58  const Var kIsNuMuVar([](const caf::SRProxy* sr) {
59  if (sr->mc.nnu == 0) return -1;
60  if (abs(sr->mc.nu[0].pdg) == 14) { return 1; }
61  else { return 0; }
62  });
63 
64 
65  // ================ Period 1 BPF ================
66  // FHC Period 1 BDT
67  float FHC_BPF_BDT_Per1_Vars[12] = {0};
68  static TMVA::Reader* fReader_FHC_BPF_BDT_Per1 = 0;
69 
70  // ================ Period 2 BPF ================
71  // FHC Period 2 BDT
72  float FHC_BPF_BDT_Per2_Vars[12] = {0};
73  static TMVA::Reader* fReader_FHC_BPF_BDT_Per2 = 0;
74 
75  // ================ FHC High Gain BPF ===========
76  // FHC High Gain BDT
77  float FHC_BPF_BDT_High_Vars[12] = {0};
78  static TMVA::Reader* fReader_FHC_BPF_BDT_High = 0;
79 
80  // ================ RHC High Gain BPF ===========
81  // RHC High Gain BDT
82  float RHC_BPF_BDT_High_Vars[12] = {0};
83  static TMVA::Reader* fReader_RHC_BPF_BDT_High = 0;
84 
85  // ==============================================
86  // ==============================================
87  // ================ Period 1 Kal ================
88  // FHC Period 1 BDT
89  float FHC_Kal_BDT_Per1_Vars[12] = {0};
90  static TMVA::Reader* fReader_FHC_Kal_BDT_Per1 = 0;
91 
92  // ================ Period 2 Kal ================
93  // FHC Period 2 BDT
94  float FHC_Kal_BDT_Per2_Vars[12] = {0};
95  static TMVA::Reader* fReader_FHC_Kal_BDT_Per2 = 0;
96 
97  // ================ FHC High Gain Kal ===========
98  // FHC High Gain BDT
99  float FHC_Kal_BDT_High_Vars[12] = {0};
100  static TMVA::Reader* fReader_FHC_Kal_BDT_High = 0;
101 
102  // ================ RHC High Gain Kal ===========
103  // RHC High Gain BDT
104  float RHC_Kal_BDT_High_Vars[12] = {0};
105  static TMVA::Reader* fReader_RHC_Kal_BDT_High = 0;
106 
107 
108  // -----------------------------------
109  // ----- FHC_Per1_BDT
110  // -----------------------------------
111  // ---- Operator class
113  {
114  float score = -5.;
115 
116  FHC_BPF_BDT_Per1_Vars[0 ] = kMinTrkCell (sr);
117  FHC_BPF_BDT_Per1_Vars[1 ] = kBPFBestMuonCosNumi(sr);
118  FHC_BPF_BDT_Per1_Vars[2 ] = kBPFBestMuonTrkLen (sr);
119  FHC_BPF_BDT_Per1_Vars[3 ] = kMaxBPFStEnY (sr);
120  FHC_BPF_BDT_Per1_Vars[4 ] = kBPFBestMuonCosDirY(sr);
121  FHC_BPF_BDT_Per1_Vars[5 ] = kBPFHitRat (sr);
122  FHC_BPF_BDT_Per1_Vars[6 ] = kBPFBestMuonPtP (sr);
123  // And my spectators
124  FHC_BPF_BDT_Per1_Vars[7 ] = kIsNuVar (sr);
125  FHC_BPF_BDT_Per1_Vars[8 ] = kIsCCVar (sr);
126  FHC_BPF_BDT_Per1_Vars[9 ] = kCVNm (sr);
127  FHC_BPF_BDT_Per1_Vars[10] = -5; // kCVNm2017(sr) doesn't exist anymore
128  FHC_BPF_BDT_Per1_Vars[11] = kRemID (sr);
129 
130  // Init TMVA
131  if(!fReader_FHC_BPF_BDT_Per1) InitTMVA();
132  score = fReader_FHC_BPF_BDT_Per1->EvaluateMVA("BDT");
133  return score;
134  }
135  // ---- InitTMVA class.
137  {
138  if(!fReader_FHC_BPF_BDT_Per1) fReader_FHC_BPF_BDT_Per1 = new TMVA::Reader;
139 
140  std::string pidlib = util::EnvExpansion("$UCANA_LIB_PATH/")+"/TMVA_MProd5_BPF_FHC_Per1_BDT.weights.xml";
141 
142  fReader_FHC_BPF_BDT_Per1 -> AddVariable( "min(CosFwdCell+CosBakCell,KalTrkFwdCell+KalTrkBakCell)", &FHC_BPF_BDT_Per1_Vars[0 ]);
143  fReader_FHC_BPF_BDT_Per1 -> AddVariable( "BPFCosNumi" , &FHC_BPF_BDT_Per1_Vars[1 ]);
144  fReader_FHC_BPF_BDT_Per1 -> AddVariable( "BPFLen" , &FHC_BPF_BDT_Per1_Vars[2 ]);
145  fReader_FHC_BPF_BDT_Per1 -> AddVariable( "max(BPFStY,BPFEndY)" , &FHC_BPF_BDT_Per1_Vars[3 ]);
146  fReader_FHC_BPF_BDT_Per1 -> AddVariable( "cos(BPFDirY)" , &FHC_BPF_BDT_Per1_Vars[4 ]);
147  fReader_FHC_BPF_BDT_Per1 -> AddVariable( "BPFNHit/SliceNHit" , &FHC_BPF_BDT_Per1_Vars[5 ]);
148  fReader_FHC_BPF_BDT_Per1 -> AddVariable( "BPFPtOverP" , &FHC_BPF_BDT_Per1_Vars[6 ]);
149  // And my spectators
150  fReader_FHC_BPF_BDT_Per1 -> AddSpectator( "IsNu" , &FHC_BPF_BDT_Per1_Vars[7 ]);
151  fReader_FHC_BPF_BDT_Per1 -> AddSpectator( "IsNuMu" , &FHC_BPF_BDT_Per1_Vars[8 ]);
152  fReader_FHC_BPF_BDT_Per1 -> AddSpectator( "CVNMuon17" , &FHC_BPF_BDT_Per1_Vars[9 ]);
153  fReader_FHC_BPF_BDT_Per1 -> AddSpectator( "CVNMuon18" , &FHC_BPF_BDT_Per1_Vars[10]);
154  fReader_FHC_BPF_BDT_Per1 -> AddSpectator( "KalTrkRemID", &FHC_BPF_BDT_Per1_Vars[11]);
155  fReader_FHC_BPF_BDT_Per1 -> BookMVA("BDT", pidlib);
156  }
157 
158  // -----------------------------------
159  // ----- FHC_Per2_BDT
160  // -----------------------------------
161  // ---- Operator class
163  {
164  float score = -5.;
165 
166  FHC_BPF_BDT_Per2_Vars[0 ] = kMinTrkCell (sr);
167  FHC_BPF_BDT_Per2_Vars[1 ] = kBPFBestMuonCosNumi(sr);
168  FHC_BPF_BDT_Per2_Vars[2 ] = kBPFBestMuonTrkLen (sr);
169  FHC_BPF_BDT_Per2_Vars[3 ] = kMaxBPFStEnY (sr);
170  FHC_BPF_BDT_Per2_Vars[4 ] = kBPFBestMuonCosDirY(sr);
171  FHC_BPF_BDT_Per2_Vars[5 ] = kBPFHitRat (sr);
172  FHC_BPF_BDT_Per2_Vars[6 ] = kBPFBestMuonPtP (sr);
173  // And my spectators
174  FHC_BPF_BDT_Per2_Vars[7 ] = kIsNuVar (sr);
175  FHC_BPF_BDT_Per2_Vars[8 ] = kIsCCVar (sr);
176  FHC_BPF_BDT_Per2_Vars[9 ] = kCVNm (sr);
177  FHC_BPF_BDT_Per2_Vars[10] = -5; // kCVNm2017(sr) doesn't exist anymore
178  FHC_BPF_BDT_Per2_Vars[11] = kRemID (sr);
179 
180  // Init TMVA
181  if(!fReader_FHC_BPF_BDT_Per2) InitTMVA();
182  score = fReader_FHC_BPF_BDT_Per2->EvaluateMVA("BDT");
183  return score;
184  }
185  // ---- InitTMVA class.
187  {
188  if(!fReader_FHC_BPF_BDT_Per2) fReader_FHC_BPF_BDT_Per2 = new TMVA::Reader;
189 
190  std::string pidlib = util::EnvExpansion("$UCANA_LIB_PATH/")+"/TMVA_MProd5_BPF_FHC_Per2_BDT.weights.xml";
191 
192  fReader_FHC_BPF_BDT_Per2 -> AddVariable( "min(CosFwdCell+CosBakCell,KalTrkFwdCell+KalTrkBakCell)", &FHC_BPF_BDT_Per2_Vars[0 ]);
193  fReader_FHC_BPF_BDT_Per2 -> AddVariable( "BPFCosNumi" , &FHC_BPF_BDT_Per2_Vars[1 ]);
194  fReader_FHC_BPF_BDT_Per2 -> AddVariable( "BPFLen" , &FHC_BPF_BDT_Per2_Vars[2 ]);
195  fReader_FHC_BPF_BDT_Per2 -> AddVariable( "max(BPFStY,BPFEndY)" , &FHC_BPF_BDT_Per2_Vars[3 ]);
196  fReader_FHC_BPF_BDT_Per2 -> AddVariable( "cos(BPFDirY)" , &FHC_BPF_BDT_Per2_Vars[4 ]);
197  fReader_FHC_BPF_BDT_Per2 -> AddVariable( "BPFNHit/SliceNHit" , &FHC_BPF_BDT_Per2_Vars[5 ]);
198  fReader_FHC_BPF_BDT_Per2 -> AddVariable( "BPFPtOverP" , &FHC_BPF_BDT_Per2_Vars[6 ]);
199  // And my spectators
200  fReader_FHC_BPF_BDT_Per2 -> AddSpectator( "IsNu" , &FHC_BPF_BDT_Per2_Vars[7 ]);
201  fReader_FHC_BPF_BDT_Per2 -> AddSpectator( "IsNuMu" , &FHC_BPF_BDT_Per2_Vars[8 ]);
202  fReader_FHC_BPF_BDT_Per2 -> AddSpectator( "CVNMuon17" , &FHC_BPF_BDT_Per2_Vars[9 ]);
203  fReader_FHC_BPF_BDT_Per2 -> AddSpectator( "CVNMuon18" , &FHC_BPF_BDT_Per2_Vars[10]);
204  fReader_FHC_BPF_BDT_Per2 -> AddSpectator( "KalTrkRemID", &FHC_BPF_BDT_Per2_Vars[11]);
205  fReader_FHC_BPF_BDT_Per2 -> BookMVA("BDT", pidlib);
206  }
207 
208  // -----------------------------------
209  // ----- FHC_High_BDT
210  // -----------------------------------
211  // ---- Operator class
213  {
214  float score = -5.;
215 
216  FHC_BPF_BDT_High_Vars[0 ] = kMinTrkCell (sr);
217  FHC_BPF_BDT_High_Vars[1 ] = kBPFBestMuonCosNumi(sr);
218  FHC_BPF_BDT_High_Vars[2 ] = kBPFBestMuonTrkLen (sr);
219  FHC_BPF_BDT_High_Vars[3 ] = kMaxBPFStEnY (sr);
220  FHC_BPF_BDT_High_Vars[4 ] = kBPFBestMuonCosDirY(sr);
221  FHC_BPF_BDT_High_Vars[5 ] = kBPFHitRat (sr);
222  FHC_BPF_BDT_High_Vars[6 ] = kBPFBestMuonPtP (sr);
223  // And my spectators
224  FHC_BPF_BDT_High_Vars[7 ] = kIsNuVar (sr);
225  FHC_BPF_BDT_High_Vars[8 ] = kIsCCVar (sr);
226  FHC_BPF_BDT_High_Vars[9 ] = kCVNm (sr);
227  FHC_BPF_BDT_High_Vars[10] = -5; // kCVNm2017(sr) doesn't exist anymore
228  FHC_BPF_BDT_High_Vars[11] = kRemID (sr);
229 
230  // Init TMVA
231  if(!fReader_FHC_BPF_BDT_High) InitTMVA();
232  score = fReader_FHC_BPF_BDT_High->EvaluateMVA("BDT");
233  return score;
234  }
235  // ---- InitTMVA class.
237  {
238  if(!fReader_FHC_BPF_BDT_High) fReader_FHC_BPF_BDT_High = new TMVA::Reader;
239 
240  std::string pidlib = util::EnvExpansion("$UCANA_LIB_PATH/")+"/TMVA_MProd5_BPF_FHC_High_BDT.weights.xml";
241 
242  fReader_FHC_BPF_BDT_High -> AddVariable( "min(CosFwdCell+CosBakCell,KalTrkFwdCell+KalTrkBakCell)", &FHC_BPF_BDT_High_Vars[0 ]);
243  fReader_FHC_BPF_BDT_High -> AddVariable( "BPFCosNumi" , &FHC_BPF_BDT_High_Vars[1 ]);
244  fReader_FHC_BPF_BDT_High -> AddVariable( "BPFLen" , &FHC_BPF_BDT_High_Vars[2 ]);
245  fReader_FHC_BPF_BDT_High -> AddVariable( "max(BPFStY,BPFEndY)" , &FHC_BPF_BDT_High_Vars[3 ]);
246  fReader_FHC_BPF_BDT_High -> AddVariable( "cos(BPFDirY)" , &FHC_BPF_BDT_High_Vars[4 ]);
247  fReader_FHC_BPF_BDT_High -> AddVariable( "BPFNHit/SliceNHit" , &FHC_BPF_BDT_High_Vars[5 ]);
248  fReader_FHC_BPF_BDT_High -> AddVariable( "BPFPtOverP" , &FHC_BPF_BDT_High_Vars[6 ]);
249  // And my spectators
250  fReader_FHC_BPF_BDT_High -> AddSpectator( "IsNu" , &FHC_BPF_BDT_High_Vars[7 ]);
251  fReader_FHC_BPF_BDT_High -> AddSpectator( "IsNuMu" , &FHC_BPF_BDT_High_Vars[8 ]);
252  fReader_FHC_BPF_BDT_High -> AddSpectator( "CVNMuon17" , &FHC_BPF_BDT_High_Vars[9 ]);
253  fReader_FHC_BPF_BDT_High -> AddSpectator( "CVNMuon18" , &FHC_BPF_BDT_High_Vars[10]);
254  fReader_FHC_BPF_BDT_High -> AddSpectator( "KalTrkRemID", &FHC_BPF_BDT_High_Vars[11]);
255  fReader_FHC_BPF_BDT_High -> BookMVA("BDT", pidlib);
256  }
257 
258  // -----------------------------------
259  // ----- RHC_High_BDT
260  // -----------------------------------
261  // ---- Operator class
263  {
264  float score = -5.;
265 
266  RHC_BPF_BDT_High_Vars[0 ] = kMinTrkCell (sr);
267  RHC_BPF_BDT_High_Vars[1 ] = kBPFBestMuonCosNumi(sr);
268  RHC_BPF_BDT_High_Vars[2 ] = kBPFBestMuonTrkLen (sr);
269  RHC_BPF_BDT_High_Vars[3 ] = kMaxBPFStEnY (sr);
270  RHC_BPF_BDT_High_Vars[4 ] = kBPFBestMuonCosDirY(sr);
271  RHC_BPF_BDT_High_Vars[5 ] = kBPFHitRat (sr);
272  RHC_BPF_BDT_High_Vars[6 ] = kBPFBestMuonPtP (sr);
273  // And my spectators
274  RHC_BPF_BDT_High_Vars[7 ] = kIsNuVar (sr);
275  RHC_BPF_BDT_High_Vars[8 ] = kIsCCVar (sr);
276  RHC_BPF_BDT_High_Vars[9 ] = kCVNm (sr);
277  RHC_BPF_BDT_High_Vars[10] = -5; // kCVNm2017(sr) doesn't exist anymore
278  RHC_BPF_BDT_High_Vars[11] = kRemID (sr);
279 
280  // Init TMVA
281  if(!fReader_RHC_BPF_BDT_High) InitTMVA();
282  score = fReader_RHC_BPF_BDT_High->EvaluateMVA("BDT");
283  return score;
284  }
285  // ---- InitTMVA class.
287  {
288  if(!fReader_RHC_BPF_BDT_High) fReader_RHC_BPF_BDT_High = new TMVA::Reader;
289 
290  std::string pidlib = util::EnvExpansion("$UCANA_LIB_PATH/")+"/TMVA_MProd5_BPF_RHC_High_BDT.weights.xml";
291 
292  fReader_RHC_BPF_BDT_High -> AddVariable( "min(CosFwdCell+CosBakCell,KalTrkFwdCell+KalTrkBakCell)", &RHC_BPF_BDT_High_Vars[0 ]);
293  fReader_RHC_BPF_BDT_High -> AddVariable( "BPFCosNumi" , &RHC_BPF_BDT_High_Vars[1 ]);
294  fReader_RHC_BPF_BDT_High -> AddVariable( "BPFLen" , &RHC_BPF_BDT_High_Vars[2 ]);
295  fReader_RHC_BPF_BDT_High -> AddVariable( "max(BPFStY,BPFEndY)" , &RHC_BPF_BDT_High_Vars[3 ]);
296  fReader_RHC_BPF_BDT_High -> AddVariable( "cos(BPFDirY)" , &RHC_BPF_BDT_High_Vars[4 ]);
297  fReader_RHC_BPF_BDT_High -> AddVariable( "BPFNHit/SliceNHit" , &RHC_BPF_BDT_High_Vars[5 ]);
298  fReader_RHC_BPF_BDT_High -> AddVariable( "BPFPtOverP" , &RHC_BPF_BDT_High_Vars[6 ]);
299  // And my spectators
300  fReader_RHC_BPF_BDT_High -> AddSpectator( "IsNu" , &RHC_BPF_BDT_High_Vars[7 ]);
301  fReader_RHC_BPF_BDT_High -> AddSpectator( "IsNuMu" , &RHC_BPF_BDT_High_Vars[8 ]);
302  fReader_RHC_BPF_BDT_High -> AddSpectator( "CVNMuon17" , &RHC_BPF_BDT_High_Vars[9 ]);
303  fReader_RHC_BPF_BDT_High -> AddSpectator( "CVNMuon18" , &RHC_BPF_BDT_High_Vars[10]);
304  fReader_RHC_BPF_BDT_High -> AddSpectator( "KalTrkRemID", &RHC_BPF_BDT_High_Vars[11]);
305  fReader_RHC_BPF_BDT_High -> BookMVA("BDT", pidlib);
306  }
307 
308  // ==============================================
309  // ==============================================
310  // Kalman Track algorithms
311  // ==============================================
312  // ==============================================
313 
314  // -----------------------------------
315  // ----- FHC_Per1_BDT
316  // -----------------------------------
317  // ---- Operator class
319  {
320  float score = -5.;
321 
322  FHC_Kal_BDT_Per1_Vars[0 ] = kMinTrkCell (sr);
323  FHC_Kal_BDT_Per1_Vars[1 ] = kCosNumi (sr);
324  FHC_Kal_BDT_Per1_Vars[2 ] = kTrkLength (sr);
325  FHC_Kal_BDT_Per1_Vars[3 ] = kMaxKalTrStEnY(sr);
326  FHC_Kal_BDT_Per1_Vars[4 ] = kcosDirY (sr);
327  FHC_Kal_BDT_Per1_Vars[5 ] = kKalHitRat (sr);
328  FHC_Kal_BDT_Per1_Vars[6 ] = kNumuMuonPtP (sr);
329  // And my spectators
330  FHC_Kal_BDT_Per1_Vars[7 ] = kIsNuVar (sr);
331  FHC_Kal_BDT_Per1_Vars[8 ] = kIsCCVar (sr);
332  FHC_Kal_BDT_Per1_Vars[9 ] = kCVNm (sr);
333  FHC_Kal_BDT_Per1_Vars[10] = -5; // kCVNm2017(sr) doesn't exist anymore
334  FHC_Kal_BDT_Per1_Vars[11] = kRemID (sr);
335 
336  // Init TMVA
337  if(!fReader_FHC_Kal_BDT_Per1) InitTMVA();
338  score = fReader_FHC_Kal_BDT_Per1->EvaluateMVA("BDT");
339 
340  return score;
341  }
342  // ---- InitTMVA class.
344  {
345  if(!fReader_FHC_Kal_BDT_Per1) fReader_FHC_Kal_BDT_Per1 = new TMVA::Reader;
346 
347  std::string pidlib = util::EnvExpansion("$UCANA_LIB_PATH/")+"/TMVA_MProd5_Kal_FHC_Per1_BDT.weights.xml";
348 
349  fReader_FHC_Kal_BDT_Per1 -> AddVariable( "min(CosFwdCell+CosBakCell,KalTrkFwdCell+KalTrkBakCell)", &FHC_Kal_BDT_Per1_Vars[0 ]);
350  fReader_FHC_Kal_BDT_Per1 -> AddVariable( "KalTrkCosNumi" , &FHC_Kal_BDT_Per1_Vars[1 ]);
351  fReader_FHC_Kal_BDT_Per1 -> AddVariable( "KalTrkLen" , &FHC_Kal_BDT_Per1_Vars[2 ]);
352  fReader_FHC_Kal_BDT_Per1 -> AddVariable( "max(KalTrkStY,KalTrkEndY)" , &FHC_Kal_BDT_Per1_Vars[3 ]);
353  fReader_FHC_Kal_BDT_Per1 -> AddVariable( "cos(KalTrkDirY)" , &FHC_Kal_BDT_Per1_Vars[4 ]);
354  fReader_FHC_Kal_BDT_Per1 -> AddVariable( "KalTrkNHit/SliceNHit" , &FHC_Kal_BDT_Per1_Vars[5 ]);
355  fReader_FHC_Kal_BDT_Per1 -> AddVariable( "KalTrkPtOverP" , &FHC_Kal_BDT_Per1_Vars[6 ]);
356  // And my spectators
357  fReader_FHC_Kal_BDT_Per1 -> AddSpectator( "IsNu" , &FHC_Kal_BDT_Per1_Vars[7 ]);
358  fReader_FHC_Kal_BDT_Per1 -> AddSpectator( "IsNuMu" , &FHC_Kal_BDT_Per1_Vars[8 ]);
359  fReader_FHC_Kal_BDT_Per1 -> AddSpectator( "CVNMuon17" , &FHC_Kal_BDT_Per1_Vars[9 ]);
360  fReader_FHC_Kal_BDT_Per1 -> AddSpectator( "CVNMuon18" , &FHC_Kal_BDT_Per1_Vars[10]);
361  fReader_FHC_Kal_BDT_Per1 -> AddSpectator( "KalTrkRemID", &FHC_Kal_BDT_Per1_Vars[11]);
362  fReader_FHC_Kal_BDT_Per1 -> BookMVA("BDT", pidlib);
363  }
364 
365  // -----------------------------------
366  // ----- FHC_Per2_BDT
367  // -----------------------------------
368  // ---- Operator class
370  {
371  float score = -5.;
372 
373  FHC_Kal_BDT_Per2_Vars[0 ] = kMinTrkCell (sr);
374  FHC_Kal_BDT_Per2_Vars[1 ] = kCosNumi (sr);
375  FHC_Kal_BDT_Per2_Vars[2 ] = kTrkLength (sr);
376  FHC_Kal_BDT_Per2_Vars[3 ] = kMaxKalTrStEnY(sr);
377  FHC_Kal_BDT_Per2_Vars[4 ] = kcosDirY (sr);
378  FHC_Kal_BDT_Per2_Vars[5 ] = kKalHitRat (sr);
379  FHC_Kal_BDT_Per2_Vars[6 ] = kNumuMuonPtP (sr);
380  // And my spectators
381  FHC_Kal_BDT_Per2_Vars[7 ] = kIsNuVar (sr);
382  FHC_Kal_BDT_Per2_Vars[8 ] = kIsCCVar (sr);
383  FHC_Kal_BDT_Per2_Vars[9 ] = kCVNm (sr);
384  FHC_Kal_BDT_Per2_Vars[10] = -5; // kCVNm2017(sr) doesn't exist anymore
385  FHC_Kal_BDT_Per2_Vars[11] = kRemID (sr);
386 
387  // Init TMVA
388  if(!fReader_FHC_Kal_BDT_Per2) InitTMVA();
389  score = fReader_FHC_Kal_BDT_Per2->EvaluateMVA("BDT");
390 
391  return score;
392  }
393  // ---- InitTMVA class.
395  {
396  if(!fReader_FHC_Kal_BDT_Per2) fReader_FHC_Kal_BDT_Per2 = new TMVA::Reader;
397 
398  std::string pidlib = util::EnvExpansion("$UCANA_LIB_PATH/")+"/TMVA_MProd5_Kal_FHC_Per2_BDT.weights.xml";
399 
400  fReader_FHC_Kal_BDT_Per2 -> AddVariable( "min(CosFwdCell+CosBakCell,KalTrkFwdCell+KalTrkBakCell)", &FHC_Kal_BDT_Per2_Vars[0 ]);
401  fReader_FHC_Kal_BDT_Per2 -> AddVariable( "KalTrkCosNumi" , &FHC_Kal_BDT_Per2_Vars[1 ]);
402  fReader_FHC_Kal_BDT_Per2 -> AddVariable( "KalTrkLen" , &FHC_Kal_BDT_Per2_Vars[2 ]);
403  fReader_FHC_Kal_BDT_Per2 -> AddVariable( "max(KalTrkStY,KalTrkEndY)" , &FHC_Kal_BDT_Per2_Vars[3 ]);
404  fReader_FHC_Kal_BDT_Per2 -> AddVariable( "cos(KalTrkDirY)" , &FHC_Kal_BDT_Per2_Vars[4 ]);
405  fReader_FHC_Kal_BDT_Per2 -> AddVariable( "KalTrkNHit/SliceNHit" , &FHC_Kal_BDT_Per2_Vars[5 ]);
406  fReader_FHC_Kal_BDT_Per2 -> AddVariable( "KalTrkPtOverP" , &FHC_Kal_BDT_Per2_Vars[6 ]);
407  // And my spectators
408  fReader_FHC_Kal_BDT_Per2 -> AddSpectator( "IsNu" , &FHC_Kal_BDT_Per2_Vars[7 ]);
409  fReader_FHC_Kal_BDT_Per2 -> AddSpectator( "IsNuMu" , &FHC_Kal_BDT_Per2_Vars[8 ]);
410  fReader_FHC_Kal_BDT_Per2 -> AddSpectator( "CVNMuon17" , &FHC_Kal_BDT_Per2_Vars[9 ]);
411  fReader_FHC_Kal_BDT_Per2 -> AddSpectator( "CVNMuon18" , &FHC_Kal_BDT_Per2_Vars[10]);
412  fReader_FHC_Kal_BDT_Per2 -> AddSpectator( "KalTrkRemID", &FHC_Kal_BDT_Per2_Vars[11]);
413  fReader_FHC_Kal_BDT_Per2 -> BookMVA("BDT", pidlib);
414  }
415 
416  // -----------------------------------
417  // ----- FHC_High_BDT
418  // -----------------------------------
419  // ---- Operator class
421  {
422  float score = -5.;
423 
424  FHC_Kal_BDT_High_Vars[0 ] = kMinTrkCell (sr);
425  FHC_Kal_BDT_High_Vars[1 ] = kCosNumi (sr);
426  FHC_Kal_BDT_High_Vars[2 ] = kTrkLength (sr);
427  FHC_Kal_BDT_High_Vars[3 ] = kMaxKalTrStEnY(sr);
428  FHC_Kal_BDT_High_Vars[4 ] = kcosDirY (sr);
429  FHC_Kal_BDT_High_Vars[5 ] = kKalHitRat (sr);
430  FHC_Kal_BDT_High_Vars[6 ] = kNumuMuonPtP (sr);
431  // And my spectators
432  FHC_Kal_BDT_High_Vars[7 ] = kIsNuVar (sr);
433  FHC_Kal_BDT_High_Vars[8 ] = kIsCCVar (sr);
434  FHC_Kal_BDT_High_Vars[9 ] = kCVNm (sr);
435  FHC_Kal_BDT_High_Vars[10] = -5; // kCVNm2017(sr) doesn't exist anymore
436  FHC_Kal_BDT_High_Vars[11] = kRemID (sr);
437 
438  // Init TMVA
439  if(!fReader_FHC_Kal_BDT_High) InitTMVA();
440  score = fReader_FHC_Kal_BDT_High->EvaluateMVA("BDT");
441  return score;
442  }
443  // ---- InitTMVA class.
445  {
446  if(!fReader_FHC_Kal_BDT_High) fReader_FHC_Kal_BDT_High = new TMVA::Reader;
447 
448  std::string pidlib = util::EnvExpansion("$UCANA_LIB_PATH/")+"/TMVA_MProd5_Kal_FHC_High_BDT.weights.xml";
449 
450  fReader_FHC_Kal_BDT_High -> AddVariable( "min(CosFwdCell+CosBakCell,KalTrkFwdCell+KalTrkBakCell)", &FHC_Kal_BDT_High_Vars[0 ]);
451  fReader_FHC_Kal_BDT_High -> AddVariable( "KalTrkCosNumi" , &FHC_Kal_BDT_High_Vars[1 ]);
452  fReader_FHC_Kal_BDT_High -> AddVariable( "KalTrkLen" , &FHC_Kal_BDT_High_Vars[2 ]);
453  fReader_FHC_Kal_BDT_High -> AddVariable( "max(KalTrkStY,KalTrkEndY)" , &FHC_Kal_BDT_High_Vars[3 ]);
454  fReader_FHC_Kal_BDT_High -> AddVariable( "cos(KalTrkDirY)" , &FHC_Kal_BDT_High_Vars[4 ]);
455  fReader_FHC_Kal_BDT_High -> AddVariable( "KalTrkNHit/SliceNHit" , &FHC_Kal_BDT_High_Vars[5 ]);
456  fReader_FHC_Kal_BDT_High -> AddVariable( "KalTrkPtOverP" , &FHC_Kal_BDT_High_Vars[6 ]);
457  // And my spectators
458  fReader_FHC_Kal_BDT_High -> AddSpectator( "IsNu" , &FHC_Kal_BDT_High_Vars[7 ]);
459  fReader_FHC_Kal_BDT_High -> AddSpectator( "IsNuMu" , &FHC_Kal_BDT_High_Vars[8 ]);
460  fReader_FHC_Kal_BDT_High -> AddSpectator( "CVNMuon17" , &FHC_Kal_BDT_High_Vars[9 ]);
461  fReader_FHC_Kal_BDT_High -> AddSpectator( "CVNMuon18" , &FHC_Kal_BDT_High_Vars[10]);
462  fReader_FHC_Kal_BDT_High -> AddSpectator( "KalTrkRemID", &FHC_Kal_BDT_High_Vars[11]);
463  fReader_FHC_Kal_BDT_High -> BookMVA("BDT", pidlib);
464 
465  }
466 
467  // -----------------------------------
468  // ----- RHC_High_BDT
469  // -----------------------------------
470  // ---- Operator class
472  {
473  float score = -5.;
474 
475  RHC_Kal_BDT_High_Vars[0 ] = kMinTrkCell (sr);
476  RHC_Kal_BDT_High_Vars[1 ] = kCosNumi (sr);
477  RHC_Kal_BDT_High_Vars[2 ] = kTrkLength (sr);
478  RHC_Kal_BDT_High_Vars[3 ] = kMaxKalTrStEnY(sr);
479  RHC_Kal_BDT_High_Vars[4 ] = kcosDirY (sr);
480  RHC_Kal_BDT_High_Vars[5 ] = kKalHitRat (sr);
481  RHC_Kal_BDT_High_Vars[6 ] = kNumuMuonPtP (sr);
482  // And my spectators
483  RHC_Kal_BDT_High_Vars[7 ] = kIsNuVar (sr);
484  RHC_Kal_BDT_High_Vars[8 ] = kIsCCVar (sr);
485  RHC_Kal_BDT_High_Vars[9 ] = kCVNm (sr);
486  RHC_Kal_BDT_High_Vars[10] = -5; // kCVNm2017(sr) doesn't exist anymore
487  RHC_Kal_BDT_High_Vars[11] = kRemID (sr);
488 
489  // Init TMVA
490  if(!fReader_RHC_Kal_BDT_High) InitTMVA();
491  score = fReader_RHC_Kal_BDT_High->EvaluateMVA("BDT");
492 
493  return score;
494  }
495  // ---- InitTMVA class.
497  {
498  if(!fReader_RHC_Kal_BDT_High) fReader_RHC_Kal_BDT_High = new TMVA::Reader;
499 
500  std::string pidlib = util::EnvExpansion("$UCANA_LIB_PATH/")+"/TMVA_MProd5_Kal_RHC_High_BDT.weights.xml";
501 
502  fReader_RHC_Kal_BDT_High -> AddVariable( "min(CosFwdCell+CosBakCell,KalTrkFwdCell+KalTrkBakCell)", &RHC_Kal_BDT_High_Vars[0 ]);
503  fReader_RHC_Kal_BDT_High -> AddVariable( "KalTrkCosNumi" , &RHC_Kal_BDT_High_Vars[1 ]);
504  fReader_RHC_Kal_BDT_High -> AddVariable( "KalTrkLen" , &RHC_Kal_BDT_High_Vars[2 ]);
505  fReader_RHC_Kal_BDT_High -> AddVariable( "max(KalTrkStY,KalTrkEndY)" , &RHC_Kal_BDT_High_Vars[3 ]);
506  fReader_RHC_Kal_BDT_High -> AddVariable( "cos(KalTrkDirY)" , &RHC_Kal_BDT_High_Vars[4 ]);
507  fReader_RHC_Kal_BDT_High -> AddVariable( "KalTrkNHit/SliceNHit" , &RHC_Kal_BDT_High_Vars[5 ]);
508  fReader_RHC_Kal_BDT_High -> AddVariable( "KalTrkPtOverP" , &RHC_Kal_BDT_High_Vars[6 ]);
509  // And my spectators
510  fReader_RHC_Kal_BDT_High -> AddSpectator( "IsNu" , &RHC_Kal_BDT_High_Vars[7 ]);
511  fReader_RHC_Kal_BDT_High -> AddSpectator( "IsNuMu" , &RHC_Kal_BDT_High_Vars[8 ]);
512  fReader_RHC_Kal_BDT_High -> AddSpectator( "CVNMuon17" , &RHC_Kal_BDT_High_Vars[9 ]);
513  fReader_RHC_Kal_BDT_High -> AddSpectator( "CVNMuon18" , &RHC_Kal_BDT_High_Vars[10]);
514  fReader_RHC_Kal_BDT_High -> AddSpectator( "KalTrkRemID", &RHC_Kal_BDT_High_Vars[11]);
515  fReader_RHC_Kal_BDT_High -> BookMVA("BDT", pidlib);
516  }
517 
518 }
const Var kIsNuVar([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return-1;if(sr->mc.nu[0].pdg > 0){return 1;}else{return 0;}})
T max(const caf::Proxy< T > &a, T b)
float operator()(const caf::SRProxy *sr) const
float operator()(const caf::SRProxy *sr) const
float operator()(const caf::SRProxy *sr) const
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var kKalHitRat([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-5.f;float TrkHit=kTrkNhits(sr);float SlcHit=kNHit(sr);return TrkHit/SlcHit;})
const Var kKalmanBackwardCell
Definition: NumuVars.cxx:552
float operator()(const caf::SRProxy *sr) const
static TMVA::Reader * fReader_FHC_BPF_BDT_Per2
GenericVar< caf::SRProxy > Var
Representation of a variable to be retrieved from a caf::StandardRecord object.
Definition: Var.h:76
caf::Proxy< size_t > ntracks
Definition: SRProxy.h:1724
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2038
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:570
std::string EnvExpansion(const std::string &inString)
Function to expand environment variables.
Definition: EnvExpand.cxx:8
float FHC_BPF_BDT_Per1_Vars[12]
const Var kTrkStartY([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-10.0f;return sr->trk.kalman.tracks[0].start.Y()/100;})
Definition: NumuVars.h:52
void abs(TH1 *hist)
caf::Proxy< short int > nnu
Definition: SRProxy.h:569
static TMVA::Reader * fReader_RHC_BPF_BDT_High
float FHC_Kal_BDT_Per2_Vars[12]
const Var kTrkLength([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-5.f;return sr->trk.kalman.tracks[0].len/100;})
Definition: NumuVars.h:65
const Var kCosmicForwardCell
Definition: NumuVars.cxx:549
float operator()(const caf::SRProxy *sr) const
float FHC_BPF_BDT_Per2_Vars[12]
static TMVA::Reader * fReader_RHC_Kal_BDT_High
const Var kMaxBPFStEnY([](const caf::SRProxy *sr){return std::max(kBPFBestMuonStarty(sr), kBPFBestMuonStopy(sr));})
static TMVA::Reader * fReader_FHC_Kal_BDT_Per1
const Var kIsCCVar([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return-1;if(sr->mc.nu[0].iscc){return 1;}else{return 0;}})
const Var kMaxKalTrStEnY([](const caf::SRProxy *sr){return std::max(kTrkStartY(sr), kTrkEndY(sr));})
const Var kBPFBestMuonCosNumi([](const caf::SRProxy *sr){float cosnumi=-5.0;if(kBPFValidMuon(sr)==false) return-5.f; unsigned int muIdx=(unsigned int) kCVNMuonIdx(sr);if(sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.IsValid){if(sr->hdr.det==caf::kNEARDET) cosnumi=sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.dir.Dot(beamDirND);if(sr->hdr.det==caf::kFARDET) cosnumi=sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.dir.Dot(beamDirFD);}return cosnumi;})
: Cos(NuMI beam dir) w.r.t. Best BPF Muon track
Definition: BPFVars.h:156
if(dump)
const Var kRemID
PID
Definition: Vars.cxx:81
caf::Proxy< caf::SRTrackBranch > trk
Definition: SRProxy.h:2057
static TMVA::Reader * fReader_FHC_BPF_BDT_High
const Var kNHit
Definition: Vars.cxx:71
const Var kNumuMuonPtP([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks > 0 &&sr->trk.kalman.idxremid!=999){if(sr->hdr.det==1){double Zbeam=sr->trk.kalman.tracks[0].dir.Dot(beamDirND);double ptp=sqrt(1-Zbeam *Zbeam);return(float) ptp;}if(sr->hdr.det==2){double Zbeam=sr->trk.kalman.tracks[0].dir.Dot(beamDirFD);double ptp=sqrt(1-Zbeam *Zbeam);return(float) ptp;}}return-5.f;})
Definition: NumuVars.h:49
const Var kBPFBestMuonNhits([](const caf::SRProxy *sr){float Nhits=-5.0;if(kBPFValidMuon(sr)==false) return-999.f; unsigned int muIdx=(unsigned int) kCVNMuonIdx(sr);if(sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.IsValid) Nhits=sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.nhit;return Nhits;})
: Number of hits in the best muon track
Definition: BPFVars.h:39
const Var kKalmanForwardCell
Definition: NumuVars.cxx:551
float RHC_Kal_BDT_High_Vars[12]
const Var kBPFBestMuonStopy([](const caf::SRProxy *sr){float stopy=-999.0;if(kBPFValidMuon(sr)==false) return-999.f; unsigned int muIdx=(unsigned int) kCVNMuonIdx(sr);if(sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.IsValid) stopy=sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.stop.y/100.0;return stopy;})
: Reco End Y-position for the best muon track
Definition: BPFVars.h:69
const Var kBPFHitRat([](const caf::SRProxy *sr){float BPFHit=kBPFBestMuonNhits(sr);float SlcHit=kNHit(sr);if(BPFHit==-5) return BPFHit;else return BPFHit/SlcHit;})
float FHC_Kal_BDT_High_Vars[12]
const Var kBPFBestMuonStarty([](const caf::SRProxy *sr){float starty=-999.0;if(kBPFValidMuon(sr)==false) return-999.f; unsigned int muIdx=(unsigned int) kCVNMuonIdx(sr);if(sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.IsValid) starty=sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.start.y/100.0;return starty;})
: Reco Start Y-position for the best muon track
Definition: BPFVars.h:51
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2050
const Var kIsNuMuVar([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return-1;if(abs(sr->mc.nu[0].pdg)==14){return 1;}else{return 0;}})
static TMVA::Reader * fReader_FHC_Kal_BDT_Per2
caf::Proxy< caf::SRKalman > kalman
Definition: SRProxy.h:1743
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Var kTrkEndY([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-10.0f;return sr->trk.kalman.tracks[0].stop.Y()/100;})
Definition: NumuVars.h:56
float FHC_Kal_BDT_Per1_Vars[12]
const Var kBPFBestMuonCosDirY([](const caf::SRProxy *sr){float diry=kBPFBestMuonDiry(sr);if(diry==-5) return diry;else return(float) cos(diry);})
: Cosine of Reco Start Y-direction for the best muon track
Definition: BPFVars.h:93
const Var kCosmicBackwardCell
Definition: NumuVars.cxx:550
static TMVA::Reader * fReader_FHC_BPF_BDT_Per1
float operator()(const caf::SRProxy *sr) const
float FHC_BPF_BDT_High_Vars[12]
const Var kcosDirY([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-5.f;return(float) cos(kDirY(sr));})
Definition: NumuVars.h:41
T min(const caf::Proxy< T > &a, T b)
float operator()(const caf::SRProxy *sr) const
float operator()(const caf::SRProxy *sr) const
const Var kCVNm
PID
Definition: Vars.cxx:39
float RHC_BPF_BDT_High_Vars[12]
const Var kCosNumi([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks > 0 &&sr->trk.kalman.idxremid!=999){if(sr->hdr.det==1){return sr->trk.kalman.tracks[0].dir.Dot(beamDirND);}if(sr->hdr.det==2){return sr->trk.kalman.tracks[0].dir.Dot(beamDirFD);}}return-5.f;})
Definition: NumuVars.h:43
static TMVA::Reader * fReader_FHC_Kal_BDT_High
const Var kBPFBestMuonPtP([](const caf::SRProxy *sr){float ptp=-5.0;if(kBPFValidMuon(sr)==false) return-5.f; unsigned int muIdx=(unsigned int) kCVNMuonIdx(sr);double Zbeam=-5.0;if(sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.IsValid){if(sr->hdr.det==caf::kNEARDET) Zbeam=sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.dir.Dot(beamDirND);if(sr->hdr.det==caf::kFARDET) Zbeam=sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.dir.Dot(beamDirFD);}if(Zbeam==-5.0) ptp=-5.0;else ptp=sqrt(1-Zbeam *Zbeam);return ptp;})
: Pt/P for Best Muon track
Definition: BPFVars.h:152
static constexpr Double_t sr
Definition: Munits.h:164
const Var kTrkNhits([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return 65535;return int(sr->trk.kalman.tracks[0].nhit);})
Definition: NumuVars.h:59
const Var kMinTrkCell([](const caf::SRProxy *sr){float CosCell=kCosmicForwardCell(sr)+kCosmicBackwardCell(sr);float KalCell=kKalmanForwardCell(sr)+kKalmanBackwardCell(sr);return std::min(CosCell, KalCell);})
const Var kBPFBestMuonTrkLen([](const caf::SRProxy *sr){float len=-1.0;if(kBPFValidMuon(sr)==false) return-5.f; unsigned int muIdx=(unsigned int) kCVNMuonIdx(sr);if(sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.IsValid) len=sr->vtx.elastic.fuzzyk.png[muIdx].bpf.muon.len/100.0;return len;})
: Reco length for the best muon track
Definition: BPFVars.h:135