WrongSignBDTVars.cxx
Go to the documentation of this file.
2 
5 
7 
9 
10 #include "TMVA/Reader.h"
11 
12 namespace ana
13 {
14 
15  float BDTNueVars[5] = {0};
16  float BDTNumuVars[5] = {0};
17  float BDTCVNNue_p1Vars[4] = {0};
18  float BDTCVNNue_p2Vars[6] = {0};
19  float BDTCVNNumu_p1Vars[4] = {0};
20  float BDTCVNNumu_p2Vars[6] = {0};
21  static TMVA::Reader* fReaderBDTNue = 0;
22  static TMVA::Reader* fReaderBDTNumu = 0;
23  static TMVA::Reader* fReaderBDTCVNNue_p1 = 0;
24  static TMVA::Reader* fReaderBDTCVNNue_p2 = 0;
25  static TMVA::Reader* fReaderBDTCVNNumu_p1 = 0;
26  static TMVA::Reader* fReaderBDTCVNNumu_p2 = 0;
27 
29  {
30  float antinuebdt = -5.;
31 
32  BDTNueVars[0] = kStretch(sr);
33  BDTNueVars[1] = kInElasticity(sr);
34  BDTNueVars[2] = kPrimDedx0(sr);
35  BDTNueVars[3] = kSecShwGap(sr);
36  BDTNueVars[4] = kSecAvgDedx(sr);
37 
38  if(!fReaderBDTNue) InitTMVA();
39  antinuebdt = fReaderBDTNue->EvaluateMVA("BDTG");
40  return antinuebdt;
41  }
42 
44  {
45  if(!fReaderBDTNue) fReaderBDTNue = new TMVA::Reader;
46  std::string pidlib = FindCAFAnaDir()+"/data/wrong_sign/weights/TMVAClassification_BDTG2.weights.xml";
47  fReaderBDTNue->AddVariable("stretch", &BDTNueVars[0]);
48  fReaderBDTNue->AddVariable("inelasticity", &BDTNueVars[1]);
49  fReaderBDTNue->AddVariable("prim_dedx0", &BDTNueVars[2]);
50  fReaderBDTNue->AddVariable("sec_shw_gap", &BDTNueVars[3]);
51  fReaderBDTNue->AddVariable("sec_avg_dedx", &BDTNueVars[4]);
52  fReaderBDTNue->BookMVA("BDTG", pidlib);
53  }
54 
56  {
57  float antinumubdt = -5.;
58 
59  BDTNumuVars[0] = kStretch(sr);
60  BDTNumuVars[1] = kNumuHadVisEFrac(sr);
61  BDTNumuVars[2] = kPrimDedx0(sr);
62  BDTNumuVars[3] = kSecShwGap(sr);
63  BDTNumuVars[4] = kSecAvgDedx(sr);
64 
65  if(!fReaderBDTNumu) InitTMVA();
66  antinumubdt = fReaderBDTNumu->EvaluateMVA("BDTG");
67  return antinumubdt;
68  }
69 
71  {
72  if(!fReaderBDTNumu) fReaderBDTNumu = new TMVA::Reader;
73  std::string pidlib = FindCAFAnaDir()+"/data/wrong_sign/weights/TMVAClassification_BDTG2.weights.xml";
74  fReaderBDTNumu->AddVariable("stretch", &BDTNumuVars[0]);
75  fReaderBDTNumu->AddVariable("inelasticity", &BDTNumuVars[1]);
76  fReaderBDTNumu->AddVariable("prim_dedx0", &BDTNumuVars[2]);
77  fReaderBDTNumu->AddVariable("sec_shw_gap", &BDTNumuVars[3]);
78  fReaderBDTNumu->AddVariable("sec_avg_dedx", &BDTNumuVars[4]);
79  fReaderBDTNumu->BookMVA("BDTG", pidlib);
80  }
81 
82 
84  {
85  float antinuebdt = -5.;
86 
87  BDTCVNNue_p1Vars[0] = kStretch(sr);
88  BDTCVNNue_p1Vars[1] = kInElasticity(sr);
89  BDTCVNNue_p1Vars[2] = kPrimDedx0(sr);
90  BDTCVNNue_p1Vars[3] = kCVNFSProtonScore2018(sr);
91 
92  BDTCVNNue_p2Vars[0] = kStretch(sr);
93  BDTCVNNue_p2Vars[1] = kInElasticity(sr);
94  BDTCVNNue_p2Vars[2] = kPrimDedx0(sr);
95  BDTCVNNue_p2Vars[3] = kCVNFSProtonScore2018(sr);
96  BDTCVNNue_p2Vars[4] = kProngCVNMaxProtonDist(sr);
97  BDTCVNNue_p2Vars[5] = kProngCVNMaxProton(sr);
98 
99  if(!fReaderBDTCVNNue_p1 || !fReaderBDTCVNNue_p2) InitTMVA();
100  if(kNProng(sr) == 1)
101  antinuebdt = fReaderBDTCVNNue_p1->EvaluateMVA("BDTG");
102  if(kNProng(sr) > 1)
103  antinuebdt = fReaderBDTCVNNue_p2->EvaluateMVA("BDTG");
104 
105  return antinuebdt;
106  }
107 
109  {
110  if(!fReaderBDTCVNNue_p1) fReaderBDTCVNNue_p1 = new TMVA::Reader;
111  if(!fReaderBDTCVNNue_p2) fReaderBDTCVNNue_p2 = new TMVA::Reader;
112  std::string pidlib_p1 = FindCAFAnaDir()+"/data/wrong_sign/weights/TMVAClassification_BDTGCVN2_p1.weights.xml";
113  std::string pidlib_p2 = FindCAFAnaDir()+"/data/wrong_sign/weights/TMVAClassification_BDTGCVN2_p2.weights.xml";
114  fReaderBDTCVNNue_p1->AddVariable("stretch", &BDTCVNNue_p1Vars[0]);
115  fReaderBDTCVNNue_p1->AddVariable("inelasticity", &BDTCVNNue_p1Vars[1]);
116  fReaderBDTCVNNue_p1->AddVariable("prim_dedx0", &BDTCVNNue_p1Vars[2]);
117  fReaderBDTCVNNue_p1->AddVariable("cvnfsp", &BDTCVNNue_p1Vars[3]);
118  fReaderBDTCVNNue_p1->BookMVA("BDTG", pidlib_p1);
119 
120  fReaderBDTCVNNue_p2->AddVariable("stretch", &BDTCVNNue_p2Vars[0]);
121  fReaderBDTCVNNue_p2->AddVariable("inelasticity", &BDTCVNNue_p2Vars[1]);
122  fReaderBDTCVNNue_p2->AddVariable("prim_dedx0", &BDTCVNNue_p2Vars[2]);
123  fReaderBDTCVNNue_p2->AddVariable("cvnfsp", &BDTCVNNue_p2Vars[3]);
124  fReaderBDTCVNNue_p2->AddVariable("maxprotondist", &BDTCVNNue_p2Vars[4]);
125  fReaderBDTCVNNue_p2->AddVariable("maxproton", &BDTCVNNue_p2Vars[5]);
126  fReaderBDTCVNNue_p2->BookMVA("BDTG", pidlib_p2);
127  }
128 
130  {
131  float antinumubdt = -5.;
132 
133  BDTCVNNumu_p1Vars[0] = kStretch(sr);
134  BDTCVNNumu_p1Vars[1] = kNumuHadVisEFrac(sr);
135  BDTCVNNumu_p1Vars[2] = kPrimDedx0(sr);
136  BDTCVNNumu_p1Vars[3] = kCVNFSProtonScore2018(sr);
137 
138  BDTCVNNumu_p2Vars[0] = kStretch(sr);
139  BDTCVNNumu_p2Vars[1] = kNumuHadVisEFrac(sr);
140  BDTCVNNumu_p2Vars[2] = kPrimDedx0(sr);
141  BDTCVNNumu_p2Vars[3] = kCVNFSProtonScore2018(sr);
142  BDTCVNNumu_p2Vars[4] = kProngCVNMaxProtonDist(sr);
143  BDTCVNNumu_p2Vars[5] = kProngCVNMaxProton(sr);
144 
145  if(!fReaderBDTCVNNumu_p1 || !fReaderBDTCVNNumu_p2) InitTMVA();
146  if(kNProng(sr) == 1)
147  antinumubdt = fReaderBDTCVNNumu_p1->EvaluateMVA("BDTG");
148  if(kNProng(sr) > 1)
149  antinumubdt = fReaderBDTCVNNumu_p2->EvaluateMVA("BDTG");
150 
151  return antinumubdt;
152  }
153 
155  {
156  if(!fReaderBDTCVNNumu_p1) fReaderBDTCVNNumu_p1 = new TMVA::Reader;
157  if(!fReaderBDTCVNNumu_p2) fReaderBDTCVNNumu_p2 = new TMVA::Reader;
158  std::string pidlib_p1 = FindCAFAnaDir()+"/data/wrong_sign/weights/TMVAClassification_BDTGCVN2_p1.weights.xml";
159  std::string pidlib_p2 = FindCAFAnaDir()+"/data/wrong_sign/weights/TMVAClassification_BDTGCVN2_p2.weights.xml";
160  fReaderBDTCVNNumu_p1->AddVariable("stretch", &BDTCVNNumu_p1Vars[0]);
161  fReaderBDTCVNNumu_p1->AddVariable("inelasticity", &BDTCVNNumu_p1Vars[1]);
162  fReaderBDTCVNNumu_p1->AddVariable("prim_dedx0", &BDTCVNNumu_p1Vars[2]);
163  fReaderBDTCVNNumu_p1->AddVariable("cvnfsp", &BDTCVNNumu_p1Vars[3]);
164  fReaderBDTCVNNumu_p1->BookMVA("BDTG", pidlib_p1);
165 
166  fReaderBDTCVNNumu_p2->AddVariable("stretch", &BDTCVNNumu_p2Vars[0]);
167  fReaderBDTCVNNumu_p2->AddVariable("inelasticity", &BDTCVNNumu_p2Vars[1]);
168  fReaderBDTCVNNumu_p2->AddVariable("prim_dedx0", &BDTCVNNumu_p2Vars[2]);
169  fReaderBDTCVNNumu_p2->AddVariable("cvnfsp", &BDTCVNNumu_p2Vars[3]);
170  fReaderBDTCVNNumu_p2->AddVariable("maxprotondist", &BDTCVNNumu_p2Vars[4]);
171  fReaderBDTCVNNumu_p2->AddVariable("maxproton", &BDTCVNNumu_p2Vars[5]);
172  fReaderBDTCVNNumu_p2->BookMVA("BDTG", pidlib_p2);
173  }
174 
175  const Var kStretch([](const caf::SRProxy* sr)
176  {
177  if(sr->slc.meanpos.z == sr->slc.boxmin.z)
178  return -5.;
179  return (double)((sr->slc.boxmax.z-sr->slc.meanpos.z)/(sr->slc.meanpos.z-sr->slc.boxmin.z));
180  });
181 
182  const Var kEthetaSqr([](const caf::SRProxy* sr)
183  {
184  if(!sr->vtx.elastic.IsValid)
185  return -5.;
186  if(sr->vtx.elastic.fuzzyk.png.size() == 0)
187  return -5.;
188  return (double)(sr->vtx.elastic.fuzzyk.png[0].calE*std::pow(acos(sr->vtx.elastic.fuzzyk.png[0].dir.z),2));
189  });
190 
191  const Var kInElasticity([](const caf::SRProxy* sr)
192  {
193  if(!sr->vtx.elastic.IsValid) return 1.f;
194  if(sr->vtx.elastic.fuzzyk.nshwlid < 1) return 1.f;
195  return ((sr->slc.calE -
196  sr->vtx.elastic.fuzzyk.png[0].shwlid.calE)/(sr->slc.calE));
197  });
198 
199  const Var kNumuHadVisEFrac(
200  [](const caf::SRProxy* sr)
201  {
202  if(sr->slc.calE == 0) return -5.;
203  return (double)(sr->energy.numu.hadcalE+sr->energy.numu.hadtrkE)/(sr->slc.calE);
204  });
205 
206  const Var kNumuHadEFrac(
207  [](const caf::SRProxy* sr)
208  {
209  if(sr->slc.calE == 0) return -5.;
210  return (double)(sr->energy.numu.hadcalE)/(sr->slc.calE);
211  });
212 
213  const Var kLeptonAngle([](const caf::SRProxy* sr)
214  {
215  if(!sr->vtx.elastic.IsValid)
216  return -5.;
217  if(sr->vtx.elastic.fuzzyk.png.size() == 0)
218  return -5.;
219  return (double)acos(sr->vtx.elastic.fuzzyk.png[0].dir.z)*180./M_PI;
220  });
221 
222  #define PrimVAR(VAR) \
223  Var( \
224  [](const caf::SRProxy* sr) \
225  { \
226  if(!sr->vtx.elastic.IsValid) return -5.; \
227  if(sr->vtx.elastic.fuzzyk.nshwlid < 1) return -5.; \
228  return double(sr->vtx.elastic.fuzzyk.png[0].shwlid.VAR); \
229  });
230 
231  #define SecVAR(VAR) \
232  Var( \
233  [](const caf::SRProxy* sr) \
234  { \
235  if(!sr->vtx.elastic.IsValid) return -5.; \
236  if(sr->vtx.elastic.fuzzyk.nshwlid< 2) return 0.; \
237  return double(sr->vtx.elastic.fuzzyk.png[1].shwlid.VAR); \
238  });
239 
240  const Var kPrimDedx0 = PrimVAR(lid.dedx0)
241  const Var kPrimDedx1 = PrimVAR(lid.dedx1)
242 
244  {
245  if(!sr->vtx.elastic.IsValid)
246  return -5.;
247  if(sr->vtx.elastic.fuzzyk.nshwlid < 1) return -5.;
248  if(sr->vtx.elastic.fuzzyk.npng < 1) return -5.;
249  if(sr->vtx.elastic.fuzzyk.png[0].len < 1e-10) return -5.;
250  return (double)(sr->vtx.elastic.fuzzyk.png[0].calE/sr->vtx.elastic.fuzzyk.png[0].len);
251  });
252  const Var kSecAvgDedx([](const caf::SRProxy* sr)
253  {
254  if(!sr->vtx.elastic.IsValid)
255  return -5.;
256  if(sr->vtx.elastic.fuzzyk.nshwlid < 2) return 0.;
257  if(sr->vtx.elastic.fuzzyk.npng < 2) return 0.;
258  if(sr->vtx.elastic.fuzzyk.png[1].len < 1e-10) return -5.;
259  return (double)(sr->vtx.elastic.fuzzyk.png[1].calE/sr->vtx.elastic.fuzzyk.png[1].len);
260  });
261 
262  const Var kSecShwGap(
263  [](const caf::SRProxy* sr)
264  {
265  if(!sr->vtx.elastic.IsValid) return -5.;
266  if(sr->vtx.elastic.fuzzyk.nshwlid< 1) return -5.;
267  if(sr->vtx.elastic.fuzzyk.nshwlid < 2) return (double)sr->vtx.elastic.fuzzyk.png[0].shwlid.gap;
268  return double(sr->vtx.elastic.fuzzyk.png[1].shwlid.gap);
269  });
271 
272  const Var kNProng(
273  [](const caf::SRProxy* sr)
274  {
275  if(!sr->vtx.elastic.IsValid) return -5;
276  return (int)sr->vtx.elastic.fuzzyk.npng;
277  });
278 
279 }
const XML_Char int len
Definition: expat.h:262
caf::Proxy< size_t > npng
Definition: SRProxy.h:2038
caf::Proxy< unsigned int > nshwlid
Definition: SRProxy.h:2040
const Var kEthetaSqr([](const caf::SRProxy *sr){if(!sr->vtx.elastic.IsValid) return-5.;if(sr->vtx.elastic.fuzzyk.png.size()==0) return-5.;return(double)(sr->vtx.elastic.fuzzyk.png[0].calE *std::pow(acos(sr->vtx.elastic.fuzzyk.png[0].dir.z), 2));})
float operator()(const caf::SRProxy *sr) const
float BDTNueVars[5]
const Var kInElasticity([](const caf::SRProxy *sr){if(!sr->vtx.elastic.IsValid) return 1.f;if(sr->vtx.elastic.fuzzyk.nshwlid< 1) return 1.f;return((sr->slc.calE- sr->vtx.elastic.fuzzyk.png[0].shwlid.calE)/(sr->slc.calE));})
caf::Proxy< caf::SRFuzzyK > fuzzyk
Definition: SRProxy.h:2059
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var kSecAvgDedx([](const caf::SRProxy *sr){if(!sr->vtx.elastic.IsValid) return-5.;if(sr->vtx.elastic.fuzzyk.nshwlid< 2) return 0.;if(sr->vtx.elastic.fuzzyk.npng< 2) return 0.;if(sr->vtx.elastic.fuzzyk.png[1].len< 1e-10) return-5.;return(double)(sr->vtx.elastic.fuzzyk.png[1].calE/sr->vtx.elastic.fuzzyk.png[1].len);})
const Var kLeptonAngle([](const caf::SRProxy *sr){if(!sr->vtx.elastic.IsValid) return-5.;if(sr->vtx.elastic.fuzzyk.png.size()==0) return-5.;return(double) acos(sr->vtx.elastic.fuzzyk.png[0].dir.z)*180./M_PI;})
const Var kNumuHadVisEFrac([](const caf::SRProxy *sr){if(sr->slc.calE==0) return-5.;return(double)(sr->energy.numu.hadcalE+sr->energy.numu.hadtrkE)/(sr->slc.calE);})
const Var kProngCVNMaxProtonDist([](const caf::SRProxy *sr){double score=-5;double dist=-5;const caf::SRVector3DProxy &vtx=sr->vtx.elastic.vtx;for(unsigned int i=0;i< sr->vtx.elastic.fuzzyk.npng;++i){if(sr->vtx.elastic.fuzzyk.png[i].cvnpart.protonid > score){score=sr->vtx.elastic.fuzzyk.png[i].cvnpart.protonid;const caf::SRVector3DProxy &st=sr->vtx.elastic.fuzzyk.png[i].start;dist=util::pythag(vtx.X()-st.X(), vtx.Y()-st.Y(), vtx.Z()-st.Z());}}return dist;})
return distance from vertex for most proton-like prong
Definition: NueVarsExtra.h:137
caf::Proxy< caf::SRNumuEnergy > numu
Definition: SRProxy.h:214
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
constexpr T pow(T x)
Definition: pow.h:75
caf::Proxy< float > hadtrkE
Definition: SRProxy.h:171
caf::Proxy< caf::SREnergyBranch > energy
Definition: SRProxy.h:2136
T acos(T number)
Definition: d0nt_math.hpp:54
std::string FindCAFAnaDir()
Definition: Utilities.cxx:204
#define M_PI
Definition: SbMath.h:34
caf::Proxy< caf::SRVector3D > boxmin
Definition: SRProxy.h:1291
caf::Proxy< caf::SRElastic > elastic
Definition: SRProxy.h:2118
caf::Proxy< std::vector< caf::SRFuzzyKProng > > png
Definition: SRProxy.h:2043
caf::Proxy< float > z
Definition: SRProxy.h:108
void InitTMVA() const
#define PrimVAR(VAR)
const Var kPrimDedx0
#define SecVAR(VAR)
float BDTCVNNue_p1Vars[4]
caf::Proxy< caf::StandardRecord > SRProxy
Definition: EpilogFwd.h:2
static TMVA::Reader * fReaderBDTCVNNue_p1
caf::StandardRecord * sr
caf::Proxy< float > hadcalE
Definition: SRProxy.h:169
const Var kNProng
const Var kCVNFSProtonScore2018([](const caf::SRProxy *sr){return CVNFinalStateScore2018(sr, 2212);})
Proton score from CVN Final State labels, using Prod3Train CVN.
float operator()(const caf::SRProxy *sr) const
float operator()(const caf::SRProxy *sr) const
const Var kSecShwLen
static TMVA::Reader * fReaderBDTNumu
float BDTNumuVars[5]
caf::Proxy< bool > IsValid
Definition: SRProxy.h:2058
static TMVA::Reader * fReaderBDTCVNNue_p2
const Var kProngCVNMaxProton([](const caf::SRProxy *sr){double score=-5;for(unsigned int i=0;i< sr->vtx.elastic.fuzzyk.npng;++i){if(sr->vtx.elastic.fuzzyk.png[i].cvnpart.protonid > score) score=sr->vtx.elastic.fuzzyk.png[i].cvnpart.protonid;}return score;})
return CVN proton score for most proton-like prong
Definition: NueVarsExtra.h:134
static TMVA::Reader * fReaderBDTCVNNumu_p2
caf::Proxy< caf::SRSlice > slc
Definition: SRProxy.h:2142
const Var kNumuHadEFrac([](const caf::SRProxy *sr){if(sr->slc.calE==0) return-5.;return(double)(sr->energy.numu.hadcalE)/(sr->slc.calE);})
float BDTCVNNue_p2Vars[6]
caf::Proxy< float > calE
Definition: SRProxy.h:1292
caf::Proxy< caf::SRVector3D > meanpos
Definition: SRProxy.h:1310
static TMVA::Reader * fReaderBDTCVNNumu_p1
const Var kPrimAvgDedx
float operator()(const caf::SRProxy *sr) const
const Var kStretch([](const caf::SRProxy *sr){if(sr->slc.meanpos.z==sr->slc.boxmin.z) return-5.;return(double)((sr->slc.boxmax.z-sr->slc.meanpos.z)/(sr->slc.meanpos.z-sr->slc.boxmin.z));})
const Var kSecShwGap([](const caf::SRProxy *sr){if(!sr->vtx.elastic.IsValid) return-5.;if(sr->vtx.elastic.fuzzyk.nshwlid< 1) return-5.;if(sr->vtx.elastic.fuzzyk.nshwlid< 2) return(double) sr->vtx.elastic.fuzzyk.png[0].shwlid.gap;return double(sr->vtx.elastic.fuzzyk.png[1].shwlid.gap);})
This module creates Common Analysis Files.
Definition: FileReducer.h:10
caf::Proxy< caf::SRVertexBranch > vtx
Definition: SRProxy.h:2146
static TMVA::Reader * fReaderBDTNue
Float_t e
Definition: plot.C:35
const Var kPrimDedx1
float BDTCVNNumu_p1Vars[4]
caf::Proxy< caf::SRVector3D > boxmax
Definition: SRProxy.h:1290
float BDTCVNNumu_p2Vars[6]
enum BeamMode string