NDXSecElectronPID.cxx
Go to the documentation of this file.
2 
3 namespace ana
4 {
5  namespace nueccinc{
6  static float ElecIDVars[6] = {-999.0};
7  static TMVA::Reader* fReaderElecIDBDT = 0;
8 
10  {
11  float heighestpid = -999.0;
12  float prongNum = -999.0;
13  float bdtvalue = -999.0;
14 
15  if(!fReaderElecIDBDT) InitTMVA();
16 
17  float shwwidth = -999.0;
18  float shwgap = -999.0;
19  float elecid = -999.0;
20  float photonid = -999.0;
21  float otherid = -999.0;
22  float maxplanegap = -999.0;
23 
24  if (sr->vtx.nelastic < 1) return -999.f;
25  if (sr->vtx.elastic[0].fuzzyk.npng < 1) return -999.f;
26 
27  int nprongs = sr->vtx.elastic[0].fuzzyk.npng;
28 
29  for(int iprong = 0; iprong < nprongs; iprong++){
30  shwwidth = sr->vtx.elastic[0].fuzzyk.png[iprong].shwlid.width;
31  shwgap = sr->vtx.elastic[0].fuzzyk.png[iprong].shwlid.gap;
32  elecid =
33  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.electronid;
34  photonid =
35  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.photonid;
36  otherid =
37  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.muonid +
38  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.protonid +
39  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.pionid;
40  if(sr->vtx.elastic[0].fuzzyk.png[iprong].shwlid.len > 500){
41  elecid = 0;
42  photonid = 0;
43  otherid = 1;
44  }
45  maxplanegap = sr->vtx.elastic[0].fuzzyk.png[iprong].shwlid.maxplanegap;
46 
47 
48  if( isnan(shwwidth) || isnan(shwgap) || isnan(elecid) ||
49  isnan(photonid) || isnan(otherid) || isnan(maxplanegap))
50  continue;
51 
52  ElecIDVars[0] = shwwidth;
53  ElecIDVars[1] = shwgap;
54  ElecIDVars[2] = elecid;
55  ElecIDVars[3] = photonid;
56  ElecIDVars[4] = otherid;
57  ElecIDVars[5] = maxplanegap;
58 
59  if(!fReaderElecIDBDT) InitTMVA();
60 
61  bdtvalue = fReaderElecIDBDT->EvaluateMVA("BDT");
62 
63  if(bdtvalue > heighestpid)
64  heighestpid = bdtvalue;
65  else continue;
66  }
67  return heighestpid;
68  }
69 
71  {
72  float heighestpid = -999.0;
73  int imax = -1;
74  float bdtvalue = -999.0;
75 
76  if(!fReaderElecIDBDT) InitTMVA();
77 
78  float shwwidth = -999.0;
79  float shwgap = -999.0;
80  float elecid = -999.0;
81  float photonid = -999.0;
82  float otherid = -999.0;
83  float maxplanegap = -999.0;
84 
85  if (sr->vtx.nelastic < 1) return -999.f;
86  if (sr->vtx.elastic[0].fuzzyk.npng < 1) return -999.f;
87  int nprongs = sr->vtx.elastic[0].fuzzyk.npng;
88 
89  for(int iprong = 0; iprong < nprongs; iprong++){
90  shwwidth = sr->vtx.elastic[0].fuzzyk.png[iprong].shwlid.width;
91  shwgap = sr->vtx.elastic[0].fuzzyk.png[iprong].shwlid.gap;
92  elecid =
93  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.electronid;
94  photonid =
95  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.photonid;
96  otherid =
97  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.muonid +
98  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.protonid +
99  sr->vtx.elastic[0].fuzzyk.png[iprong].cvnpart2FlatFluxBal.pionid;
100  if(sr->vtx.elastic[0].fuzzyk.png[iprong].shwlid.len > 500){
101  elecid = 0;
102  photonid = 0;
103  otherid = 1;
104  }
105  maxplanegap = sr->vtx.elastic[0].fuzzyk.png[iprong].shwlid.maxplanegap;
106 
107 
108  ElecIDVars[0] = shwwidth;
109  ElecIDVars[1] = shwgap;
110  ElecIDVars[2] = elecid;
111  ElecIDVars[3] = photonid;
112  ElecIDVars[4] = otherid;
113  ElecIDVars[5] = maxplanegap;
114 
115  if(!fReaderElecIDBDT) InitTMVA();
116 
117  bdtvalue = fReaderElecIDBDT->EvaluateMVA("BDT");
118 
119  if(bdtvalue > heighestpid){
120  heighestpid = bdtvalue;
121  imax = iprong;
122  }
123  else continue;
124  }
125  return imax;
126  }
127 
128  std::vector<float> GetElectronIDForProng::operator()
129  (const caf::SRProxy* sr, int pngNum) const
130  {
131  float bdtvalue = -999.0;
132 
133  if(!fReaderElecIDBDT) InitTMVA();
134 
135  float shwwidth = -999.0;
136  float shwgap = -999.0;
137  float elecid = -999.0;
138  float photonid = -999.0;
139  float otherid = -999.0;
140  float maxplanegap = -999.0;
141 
142 
143  std::vector<float> badResult = {bdtvalue, shwwidth,
144  shwgap,
145  elecid,
146  photonid,
147  otherid,
148  maxplanegap};
149 
150  if (sr->vtx.nelastic < 1) return badResult;
151  if (sr->vtx.elastic[0].fuzzyk.npng < (uint)pngNum) return badResult;
152 
153  shwwidth = sr->vtx.elastic[0].fuzzyk.png[pngNum].shwlid.width;
154  shwgap = sr->vtx.elastic[0].fuzzyk.png[pngNum].shwlid.gap;
155  elecid =
156  sr->vtx.elastic[0].fuzzyk.png[pngNum].cvnpart2FlatFluxBal.electronid;
157  photonid =
158  sr->vtx.elastic[0].fuzzyk.png[pngNum].cvnpart2FlatFluxBal.photonid;
159  otherid =
160  sr->vtx.elastic[0].fuzzyk.png[pngNum].cvnpart2FlatFluxBal.muonid +
161  sr->vtx.elastic[0].fuzzyk.png[pngNum].cvnpart2FlatFluxBal.protonid +
162  sr->vtx.elastic[0].fuzzyk.png[pngNum].cvnpart2FlatFluxBal.pionid;
163  if(sr->vtx.elastic[0].fuzzyk.png[pngNum].shwlid.len > 500){
164  elecid = 0;
165  photonid = 0;
166  otherid = 1;
167  }
168  maxplanegap = sr->vtx.elastic[0].fuzzyk.png[pngNum].shwlid.maxplanegap;
169 
170 
171  if( isnan(shwwidth) || isnan(shwgap) || isnan(elecid) ||
172  isnan(photonid) || isnan(otherid) || isnan(maxplanegap))
173  return badResult;
174 
175  ElecIDVars[0] = shwwidth;
176  ElecIDVars[1] = shwgap;
177  ElecIDVars[2] = elecid;
178  ElecIDVars[3] = photonid;
179  ElecIDVars[4] = otherid;
180  ElecIDVars[5] = maxplanegap;
181 
182  if(!fReaderElecIDBDT) InitTMVA();
183 
184  bdtvalue = fReaderElecIDBDT->EvaluateMVA("BDT");
185 
186  std::vector<float> Result = {bdtvalue, shwwidth,
187  shwgap,
188  elecid,
189  photonid,
190  otherid,
191  maxplanegap};
192  return Result;
193  }
194 
196  {
197  if(!fReaderElecIDBDT)
198  fReaderElecIDBDT = new TMVA::Reader( "!Color:!Silent" );
199  const char* path = getenv("SRT_PRIVATE_CONTEXT");
200  std::string pidlib =
201  std::string(path) + "/NDAna/nuecc_inc/fElectronID_BDT.weights.xml";
202 
203  fReaderElecIDBDT->AddVariable("ShwWidth", &ElecIDVars[0]);
204  fReaderElecIDBDT->AddVariable("ShwGap", &ElecIDVars[1]);
205  fReaderElecIDBDT->AddVariable("ElecID", &ElecIDVars[2]);
206  fReaderElecIDBDT->AddVariable("PhotonID", &ElecIDVars[3]);
207  fReaderElecIDBDT->AddVariable("OtherID", &ElecIDVars[4]);
208  fReaderElecIDBDT->AddSpectator("MaxPlaneGap", &ElecIDVars[5]);
209  fReaderElecIDBDT->BookMVA("BDT", pidlib);
210  return -5.0f;
211  }
212 
214  {
215  if(!fReaderElecIDBDT)
216  fReaderElecIDBDT = new TMVA::Reader( "!Color:!Silent" );
217  const char* path = getenv("SRT_PRIVATE_CONTEXT");
218  std::string pidlib =
219  std::string(path) + "/NDAna/nuecc_inc/fElectronID_BDT.weights.xml";
220 
221  fReaderElecIDBDT->AddVariable("ShwWidth", &ElecIDVars[0]);
222  fReaderElecIDBDT->AddVariable("ShwGap", &ElecIDVars[1]);
223  fReaderElecIDBDT->AddVariable("ElecID", &ElecIDVars[2]);
224  fReaderElecIDBDT->AddVariable("PhotonID", &ElecIDVars[3]);
225  fReaderElecIDBDT->AddVariable("OtherID", &ElecIDVars[4]);
226  fReaderElecIDBDT->AddSpectator("MaxPlaneGap", &ElecIDVars[5]);
227  fReaderElecIDBDT->BookMVA("BDT", pidlib);
228  return -5.0f;
229  }
230 
232  {
233  if(!fReaderElecIDBDT)
234  fReaderElecIDBDT = new TMVA::Reader( "!Color:!Silent" );
235  const char* path = getenv("SRT_PRIVATE_CONTEXT");
236  std::string pidlib =
237  std::string(path) + "/NDAna/nuecc_inc/fElectronID_BDT.weights.xml";
238 
239  fReaderElecIDBDT->AddVariable("ShwWidth", &ElecIDVars[0]);
240  fReaderElecIDBDT->AddVariable("ShwGap", &ElecIDVars[1]);
241  fReaderElecIDBDT->AddVariable("ElecID", &ElecIDVars[2]);
242  fReaderElecIDBDT->AddVariable("PhotonID", &ElecIDVars[3]);
243  fReaderElecIDBDT->AddVariable("OtherID", &ElecIDVars[4]);
244  fReaderElecIDBDT->AddSpectator("MaxPlaneGap", &ElecIDVars[5]);
245  fReaderElecIDBDT->BookMVA("BDT", pidlib);
246  return -5.0f;
247  }
248  }
249 
250 }
caf::Proxy< size_t > npng
Definition: SRProxy.h:2037
caf::Proxy< caf::SRFuzzyK > fuzzyk
Definition: SRProxy.h:2058
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
float shwwidth
int nprongs
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2125
int isnan(const stan::math::var &a)
Definition: std_isnan.hpp:18
caf::Proxy< caf::SRElastic > elastic
Definition: SRProxy.h:2117
caf::Proxy< std::vector< caf::SRFuzzyKProng > > png
Definition: SRProxy.h:2042
std::string getenv(std::string const &name)
caf::StandardRecord * sr
const std::string path
Definition: plot_BEN.C:43
float operator()(const caf::SRProxy *sr) const
static float ElecIDVars[6]
float operator()(const caf::SRProxy *sr) const
caf::Proxy< caf::SRVertexBranch > vtx
Definition: SRProxy.h:2145
static TMVA::Reader * fReaderElecIDBDT
enum BeamMode string
unsigned int uint