NDXSecBPFMuonPID.cxx
Go to the documentation of this file.
1 
3 
4 namespace ana
5 {
6  static float TMVAvars[5] = {-999.0};
7  static TMVA::Reader* fReaderBDT = 0;
8 
9 
10  //-------------------------------------------------------------
12 
13  float heighstpid = -2.0;
14  float bdtvalue = -2.0;
15 
16  if(!fReaderBDT) InitTMVA();
17  float dedxll = -999.0;
18  float chi2scat = -999.0;
19  float fAvededxlast10cm = -999.0;
20  float fAvededxlast40cm = -999.0;
21  float fHitRatio = -999.0;
22 
23  if(sr->vtx.elastic.size() == 0)return heighstpid;
24 
25  int npngs = sr->vtx.elastic[0].fuzzyk.png.size();
26 
27  for(int p = 0; p < npngs; p++){
28  auto &pbpf = sr->vtx.elastic[0].fuzzyk.png[p].bpf;
29  for(unsigned int k = 0; k < pbpf.size(); k++){
30  if(abs(pbpf[k].pdg) != 13) continue;
31 
32  dedxll = pbpf[k].dEdXLL;
33  chi2scat = pbpf[k].chi2Scat;
34  if (pbpf[k].avedEdxlast10cm == -5) continue;
35  if (pbpf[k].avedEdxlast40cm == -5) continue;
36  fAvededxlast10cm = pbpf[k].avedEdxlast10cm;
37  fAvededxlast40cm = pbpf[k].avedEdxlast40cm;
38  fHitRatio = pbpf[k].hitRatio;
39 
40  //Check for any nan or inf:
41  bool is_inf = (isinf(dedxll)!=0) || (isinf(chi2scat)!=0) || (isinf(fAvededxlast10cm)!=0) || (isinf(fAvededxlast40cm)!=0);
42  bool is_nan = (dedxll != dedxll) || (chi2scat != chi2scat) || (fAvededxlast10cm != fAvededxlast10cm) ||
43  (fAvededxlast40cm != fAvededxlast40cm);
44  if(is_nan || is_inf) continue;
45 
46  TMVAvars[0] = dedxll;
47  TMVAvars[1] = chi2scat;
48  TMVAvars[2] = fAvededxlast10cm;
49  TMVAvars[3] = fAvededxlast40cm;
50  TMVAvars[4] = fHitRatio;
51 
52  if(!fReaderBDT) InitTMVA();
53  bdtvalue = fReaderBDT->EvaluateMVA("BDTG_1k");
54 
55  if (bdtvalue > heighstpid){
56  heighstpid = bdtvalue;
57  }
58  else continue;
59 
60  } //end loop on bpfs
61  }//end loop prongs
62 
63 
64  return heighstpid;
65  }
66 
67 
69 
70  float heighstpid = -2.0;
71  int imax = -1; //this can be used as your prong index with highest PID score.
72  float bdtvalue = -2.0;
73 
74  if(!fReaderBDT) InitTMVA();
75  float dedxll = -999.0;
76  float chi2scat = -999.0;
77  float fAvededxlast10cm = -999.0;
78  float fAvededxlast40cm = -999.0;
79  float fHitRatio = -999.0;
80 
81  if(sr->vtx.elastic.size() == 0)return imax;
82 
83  for(unsigned int p = 0; p < sr->vtx.elastic[0].fuzzyk.png.size(); p++){
84  auto &pbpf = sr->vtx.elastic[0].fuzzyk.png[p].bpf;
85  for(unsigned int k = 0; k < pbpf.size(); k++){
86  if(abs(pbpf[k].pdg) != 13) continue;
87 
88  dedxll = pbpf[k].dEdXLL;
89  chi2scat = pbpf[k].chi2Scat;
90  if (pbpf[k].avedEdxlast10cm == -5) continue;
91  if (pbpf[k].avedEdxlast40cm == -5) continue;
92  fAvededxlast10cm = pbpf[k].avedEdxlast10cm;
93  fAvededxlast40cm = pbpf[k].avedEdxlast40cm;
94  fHitRatio = pbpf[k].hitRatio;
95 
96  bool is_inf = (isinf(dedxll)!=0) || (isinf(chi2scat)!=0) || (isinf(fAvededxlast10cm)!=0) || (isinf(fAvededxlast40cm)!=0);
97  bool is_nan = (dedxll != dedxll) || (chi2scat != chi2scat) || (fAvededxlast10cm != fAvededxlast10cm) ||
98  (fAvededxlast40cm != fAvededxlast40cm);
99  if(is_nan || is_inf) continue;
100 
101  TMVAvars[0] = dedxll;
102  TMVAvars[1] = chi2scat;
103  TMVAvars[2] = fAvededxlast10cm;
104  TMVAvars[3] = fAvededxlast40cm;
105  TMVAvars[4] = fHitRatio;
106 
107  if(!fReaderBDT) InitTMVA();
108 
109  bdtvalue = fReaderBDT->EvaluateMVA("BDTG_1k");
110  if (bdtvalue > heighstpid){
111  imax = p;
112  heighstpid = bdtvalue;
113  }
114  else continue;
115  }//end loop on bpfs
116  }//end loop prongs
117 
118  return imax;
119  }
120 
121  //---------------------------------------------------
123  {
124  if(!fReaderBDT) fReaderBDT = new TMVA::Reader( "!Color:!Silent" );
125  // const char* path = getenv("SRT_PUBLIC_CONTEXT");
126  const char* path = getenv("SRT_PRIVATE_CONTEXT");
127  std::string pidlib = std::string(path) + "/NDAna/numucc_0Pi/BPF_MuonID_BDTG.weights.xml";
128 
129  fReaderBDT->AddVariable("DedxLL", &TMVAvars[0]);
130  fReaderBDT->AddVariable("Chi2Scat", &TMVAvars[1]);
131  fReaderBDT->AddVariable("Avededxlast10cm", &TMVAvars[2]);
132  fReaderBDT->AddVariable("Avededxlast40cm", &TMVAvars[3]);
133  fReaderBDT->AddSpectator("HitRatio", &TMVAvars[4]);
134  fReaderBDT->BookMVA("BDTG_1k", pidlib);
135  return -5.0f;
136  }
137 
139  {
140  if(!fReaderBDT) fReaderBDT = new TMVA::Reader( "!Color:!Silent" );
141  const char* path = getenv("SRT_PRIVATE_CONTEXT");
142  std::string pidlib = std::string(path) + "/NDAna/numucc_0Pi/BPF_MuonID_BDTG.weights.xml";
143 
144  fReaderBDT->AddVariable("DedxLL", &TMVAvars[0]);
145  fReaderBDT->AddVariable("Chi2Scat", &TMVAvars[1]);
146  fReaderBDT->AddVariable("Avededxlast10cm", &TMVAvars[2]);
147  fReaderBDT->AddVariable("Avededxlast40cm", &TMVAvars[3]);
148  fReaderBDT->AddSpectator("HitRatio", &TMVAvars[4]);
149 
150  fReaderBDT->BookMVA("BDTG_1k", pidlib);
151  return -5.0f;
152  }
153 } // name space ana
154 
int isinf(const stan::math::var &a)
Definition: std_isinf.hpp:16
static TMVA::Reader * fReaderBDT
Definition: NDNCPi0Xsec.cxx:11
caf::Proxy< caf::SRFuzzyK > fuzzyk
Definition: SRProxy.h:2058
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const char * p
Definition: xmltok.h:285
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2125
float operator()(const caf::SRProxy *sr) const
void abs(TH1 *hist)
float InitTMVA() const
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)
static float TMVAvars[4]
Definition: NDNCPi0Xsec.cxx:10
caf::StandardRecord * sr
float operator()(const caf::SRProxy *sr) const
const std::string path
Definition: plot_BEN.C:43
int is_inf(const fvar< T > &x)
Definition: is_inf.hpp:19
int is_nan(const fvar< T > &x)
Definition: is_nan.hpp:19
caf::Proxy< caf::SRVertexBranch > vtx
Definition: SRProxy.h:2145
enum BeamMode string