Public Member Functions | Private Attributes | List of all members
slid::SPIDAlg Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-21/ShowerLID/SPIDAlg.h"

Public Member Functions

 SPIDAlg (fhicl::ParameterSet const &pset, NuEEnergyAlg *fNuEEnergyAlgIn, int pidType)
 Algorithm name with ENu. More...
 
 SPIDAlg (const SPIDAlg &orig)
 
virtual ~SPIDAlg ()
 
void Initialize ()
 Initialize the MVA algorithm. The parameter detectorID is an int corresponding to the detector definitions in novadaq::cnv : novadaq::cnv::kFARDET, novadaq::cnv::kNDOS, novadaq::cnv::kNEARDET. More...
 
double CalcMVAResult (slid::ShowerPID &showerspid)
 Calculate value of predictors for MVA Algorithm using candidate rb::Shower. A pointer to the object of ParticleIDAlg is also passed so that expensive calculations may not need to be done again if this particular shower is already loaded. More...
 
std::string Name ()
 
std::string Description ()
 
void InitializeTrainingTree ()
 Initialize tree to be used for training the algorithms. More...
 
void DefineTrainingTree ()
 Define mapping of branches to class fields for tree to be used for training the algorithms. More...
 
void FillTrainingTree (const slid::ShowerPID &showerspid)
 Fill tree to be used for training the algorithms. More...
 

Private Attributes

std::string fAlgorithmName
 FCL Parameters for LIDAlg. More...
 
NuEEnergyAlgfNuEEnergyAlg
 NuE energy calculations object. More...
 
int fPIDType
 If true, the ANN is computed with event energy as an input variable. More...
 
const std::string fMVAMethod = "TMlpANN"
 
const std::string fName = fMVAMethod + "NoNuE"
 
const std::string fDescription = "TMVA ANN algorithm TMlpANN with no nu(E)"
 Name of algorithm. More...
 
std::string fLibPath
 Location of weight files. Set from FCL file. More...
 
bool fUseTMVATraining
 Use TMVA training or RecoJMShower training. More...
 
TMultiLayerPerceptron * fMlp
 FCL parameters for Nue energy calculation algorithm. More...
 
TMVA::Reader * fReader
 TMVA reader object used to store MVA model. More...
 
TMVAClassification_TMlpANN_WithENufTMVAModuleTMlpANNWithENu
 
TMVAClassification_TMlpANN_NoENufTMVAModuleTMlpANNNoENu
 
int fType
 event classification answer: 1 = signal, 0 = background More...
 
slid::ShowerPIDfShowerPID
 
float fVtxgev
 
float fShE
 
float fNueRecEnergy
 

Detailed Description

Definition at line 31 of file SPIDAlg.h.

Constructor & Destructor Documentation

slid::SPIDAlg::SPIDAlg ( fhicl::ParameterSet const &  pset,
NuEEnergyAlg fNuEEnergyAlgIn,
int  pidType 
)
explicit

Algorithm name with ENu.

Definition at line 16 of file SPIDAlg.cxx.

References util::EnvExpansion(), fAlgorithmName, fLibPath, fUseTMVATraining, fhicl::ParameterSet::get(), Initialize(), and string.

18  :
19  fNuEEnergyAlg(fNuEEnergyAlgIn),
20  fPIDType(pidType),
21  fMlp(0),
22  fReader(0) {
23  //
24  // read and set FCL parameters
25  //
26  fLibPath = util::EnvExpansion(pset.get< std::string >("LibPath"));
27  fUseTMVATraining = pset.get< bool >("UseTMVATraining");
28 
29  mf::LogInfo("SPIDAlg") << " SPIDAlg::SPIDAlg() Alg = " << fAlgorithmName << "\n";
30 
31  Initialize();
32  }
TMultiLayerPerceptron * fMlp
FCL parameters for Nue energy calculation algorithm.
Definition: SPIDAlg.h:105
NuEEnergyAlg * fNuEEnergyAlg
NuE energy calculations object.
Definition: SPIDAlg.h:82
std::string fLibPath
Location of weight files. Set from FCL file.
Definition: SPIDAlg.h:95
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::string fAlgorithmName
FCL Parameters for LIDAlg.
Definition: SPIDAlg.h:79
std::string EnvExpansion(const std::string &inString)
Function to expand environment variables.
Definition: EnvExpand.cxx:8
void Initialize()
Initialize the MVA algorithm. The parameter detectorID is an int corresponding to the detector defini...
Definition: SPIDAlg.cxx:48
int fPIDType
If true, the ANN is computed with event energy as an input variable.
Definition: SPIDAlg.h:85
bool fUseTMVATraining
Use TMVA training or RecoJMShower training.
Definition: SPIDAlg.h:98
TMVA::Reader * fReader
TMVA reader object used to store MVA model.
Definition: SPIDAlg.h:109
enum BeamMode string
slid::SPIDAlg::SPIDAlg ( const SPIDAlg orig)
explicit

Definition at line 34 of file SPIDAlg.cxx.

35  {
36  }
slid::SPIDAlg::~SPIDAlg ( )
virtual

Definition at line 38 of file SPIDAlg.cxx.

References fMlp, and fReader.

39  {
40  if (fReader) delete fReader;
41  if (fMlp) delete fMlp;
42  }
TMultiLayerPerceptron * fMlp
FCL parameters for Nue energy calculation algorithm.
Definition: SPIDAlg.h:105
TMVA::Reader * fReader
TMVA reader object used to store MVA model.
Definition: SPIDAlg.h:109

Member Function Documentation

double slid::SPIDAlg::CalcMVAResult ( slid::ShowerPID showerspid)

Calculate value of predictors for MVA Algorithm using candidate rb::Shower. A pointer to the object of ParticleIDAlg is also passed so that expensive calculations may not need to be done again if this particular shower is already loaded.

Definition at line 247 of file SPIDAlg.cxx.

References slid::ShowerLID::CosTheta(), slid::ShowerPID::Dedx0(), slid::ShowerPID::Dedx1(), slid::ShowerPID::Dedx2(), slid::ShowerPID::Dedx3(), slid::ShowerLID::EGLLL(), slid::ShowerLID::EGLLT(), slid::ShowerLID::EMuLLL(), slid::ShowerLID::EMuLLT(), slid::ShowerLID::ENLLL(), slid::ShowerLID::ENLLT(), slid::ShowerLID::EPi0LLL(), slid::ShowerLID::EPi0LLT(), slid::ShowerLID::EPiLLL(), slid::ShowerLID::EPiLLT(), slid::ShowerLID::EPLLL(), slid::ShowerLID::EPLLT(), fMlp, fPIDType, fTMVAModuleTMlpANNNoENu, fTMVAModuleTMlpANNWithENu, fUseTMVATraining, slid::ShowerLID::Gap(), MECModelEnuComparisons::i, std::isnan(), slid::ShowerLID::NueEnergy(), slid::ShowerLID::Pi0mass(), slid::ShowerLID::ShowerEFrac(), TMVAClassification_TMlpANN_WithENu::Value(), TMVAClassification_TMlpANN_NoENu::Value(), and slid::ShowerLID::VertexEnergy().

Referenced by slid::SPIDBuilder::produce().

248  {
249  double ann = -5.0;
250  // // This is the correct way, except that there seems to be a bug in TMVA that makes in not work
251  // ann = fReader->EvaluateMVA(annInputs, (fMVAMethod + TString(" method")));
252 
253 
254  //
255  // Set the trained models. **NOTE** due to a bug in TMVA model using weights from file
256  // does not work. As a workaround, loading the C++ code created by TMVA DOES work, so we use
257  // that in order to move ahead. Loading the XML weights file would be preferable however,
258  // so that recompilation is not required to pick up a new MVA model.
259  //
260  if (fUseTMVATraining){
261  if (fPIDType==0) {
262 
265  showerpid.EGLLL(),
266  showerpid.EGLLT(),
267  showerpid.EMuLLL(),
268  showerpid.EMuLLT(),
269  showerpid.EPi0LLL(),
270  showerpid.EPi0LLT(),
271  showerpid.EPLLL(),
272  showerpid.EPLLT(),
273  showerpid.ENLLL(),
274  showerpid.ENLLT(),
275  showerpid.EPiLLL(),
276  showerpid.EPiLLT(),
277  showerpid.Gap(),
278  showerpid.Pi0mass(),
279  showerpid.ShowerEFrac(),
280  showerpid.VertexEnergy() );
282  }
283 
284  else if (fPIDType==1) {
287  showerpid.EGLLL(),
288  showerpid.EGLLT(),
289  showerpid.EMuLLL(),
290  showerpid.EMuLLT(),
291  showerpid.EPi0LLL(),
292  showerpid.EPi0LLT(),
293  showerpid.EPLLL(),
294  showerpid.EPLLT(),
295  showerpid.ENLLL(),
296  showerpid.ENLLT(),
297  showerpid.EPiLLL(),
298  showerpid.EPiLLT(),
299  showerpid.Gap(),
300  showerpid.Pi0mass(),
301  showerpid.ShowerEFrac(),
302  showerpid.VertexEnergy(),
303  showerpid.NueEnergy());
305  }
306  else {
307  throw cet::exception("MVAALgorithmNotDefined2")
308  << " not found. See SPIDBuilder_module.cc for list of defined algorithms.";
309  }
310  }
311  else{
312  if (fPIDType==0) {
313  Double_t params_shape[17];
314  for(int i=0;i<17;i++){
315  params_shape[i]=0;
316  }
317  params_shape[0] = showerpid.EGLLL();
318  params_shape[1] = showerpid.EGLLT();
319  params_shape[2] = showerpid.EMuLLL();
320  params_shape[3] = showerpid.EMuLLT();
321  params_shape[4] = showerpid.EPi0LLL();
322  params_shape[5] = showerpid.EPi0LLT();
323  params_shape[6] = showerpid.EPLLL();
324  params_shape[7] = showerpid.EPLLT();
325  params_shape[8] = showerpid.ENLLL();
326  params_shape[9] = showerpid.ENLLT();
327  params_shape[10] = showerpid.EPiLLL();
328  params_shape[11] = showerpid.EPiLLT();
329  params_shape[12] = showerpid.Pi0mass();
330  params_shape[13] = showerpid.ShowerEFrac();
331  params_shape[14] = showerpid.VertexEnergy();
332  params_shape[15] = showerpid.Gap();
333  params_shape[16] = showerpid.CosTheta();
334 
335  ann = fMlp->Evaluate(0,params_shape);
336 
337  }
338 
339  else if (fPIDType==1){
340  Double_t params_shape[18];
341  for(int i=0;i<18;i++){
342  params_shape[i]=0;
343  }
344  params_shape[0] = showerpid.EGLLL();
345  params_shape[1] = showerpid.EGLLT();
346  params_shape[2] = showerpid.EMuLLL();
347  params_shape[3] = showerpid.EMuLLT();
348  params_shape[4] = showerpid.EPi0LLL();
349  params_shape[5] = showerpid.EPi0LLT();
350  params_shape[6] = showerpid.EPLLL();
351  params_shape[7] = showerpid.EPLLT();
352  params_shape[8] = showerpid.ENLLL();
353  params_shape[9] = showerpid.ENLLT();
354  params_shape[10] = showerpid.EPiLLL();
355  params_shape[11] = showerpid.EPiLLT();
356  params_shape[12] = showerpid.Pi0mass();
357  params_shape[13] = showerpid.ShowerEFrac();
358  params_shape[14] = showerpid.VertexEnergy();
359  params_shape[15] = showerpid.Gap();
360  params_shape[16] = showerpid.CosTheta();
361  params_shape[17] = showerpid.NueEnergy();
362 
363  ann = fMlp->Evaluate(0,params_shape);
364 
365  }
366  else if (fPIDType==2){
367  Double_t params_shape[5];
368  for(int i=0;i<5;i++){
369  params_shape[i]=0;
370  }
371  params_shape[0] = showerpid.Dedx0();
372  params_shape[1] = showerpid.Dedx1();
373  params_shape[2] = showerpid.Dedx2();
374  params_shape[3] = showerpid.Dedx3();
375  params_shape[4] = showerpid.CosTheta();
376  ann = fMlp->Evaluate(0,params_shape);
377 
378  }
379  else if (fPIDType==3){
380  Double_t params_shape[4];
381  for(int i=0;i<4;i++){
382  params_shape[i]=0;
383  }
384  params_shape[0] = showerpid.Dedx0();
385  params_shape[1] = showerpid.Dedx1();
386  params_shape[2] = showerpid.Dedx2();
387  params_shape[3] = showerpid.Dedx3();
388  ann = fMlp->Evaluate(0,params_shape);
389  }
390  else {
391  throw cet::exception("MVAALgorithmNotDefined2")
392  << " not found. See SPIDBuilder_module.cc for list of defined algorithms.";
393  }
394  }
395 
396  // protect against nan values
397  if(std::isnan(ann)){
398  ann = -5;
399  // These messages fire all the time. Disable them but keep them in case
400  // they're useful for someone actually debugging the problem.
401  /*
402  std::cout<<"!!!!!!!!!!!!!!!!!!!"<<std::endl;
403  std::cout<<" PID returned NaN value from calculation!"<<std::endl;
404  std::cout<<" EGLLL: "<<showerpid.EGLLL()<<" EGLLT: "<<showerpid.EGLLT()<<std::endl;
405  std::cout<<" EMuLLL: "<<showerpid.EMuLLL()<<" EMuLLT: "<<showerpid.EMuLLT()<<std::endl;
406  std::cout<<" ENLLL: "<<showerpid.ENLLL()<<" ENLLT: "<<showerpid.ENLLT()<<std::endl;
407  std::cout<<" EPLLL: "<<showerpid.EPLLL()<<" EPLLT: "<<showerpid.EPLLT()<<std::endl;
408  std::cout<<" EPiLLL: "<<showerpid.EPiLLL()<<" EPiLLT: "<<showerpid.EPiLLT()<<std::endl;
409  std::cout<<" EPiLLL: "<<showerpid.EPi0LLL()<<" EPi0LLT: "<<showerpid.EPi0LLT()<<std::endl;
410  std::cout<<" Pi0Mass: "<<showerpid.Pi0mass()<<" ShowerEFrac: "<<showerpid.ShowerEFrac()<<std::endl;
411  std::cout<<" Gap: "<<showerpid.Gap()<<" Costheta: "<<showerpid.CosTheta()<<std::endl;
412  std::cout<<"!!!!!!!!!!!!!!!!!!!"<<std::endl;
413  */
414  }
415 
416  return ann;
417  }
TMultiLayerPerceptron * fMlp
FCL parameters for Nue energy calculation algorithm.
Definition: SPIDAlg.h:105
double Value(int index, double in0, double in1, double in2, double in3, double in4, double in5, double in6, double in7, double in8, double in9, double in10, double in11, double in12, double in13, double in14, double in15, double in16)
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
int isnan(const stan::math::var &a)
Definition: std_isnan.hpp:18
int fPIDType
If true, the ANN is computed with event energy as an input variable.
Definition: SPIDAlg.h:85
TMVAClassification_TMlpANN_NoENu * fTMVAModuleTMlpANNNoENu
Definition: SPIDAlg.h:115
double Value(int index, double in0, double in1, double in2, double in3, double in4, double in5, double in6, double in7, double in8, double in9, double in10, double in11, double in12, double in13, double in14, double in15)
bool fUseTMVATraining
Use TMVA training or RecoJMShower training.
Definition: SPIDAlg.h:98
TMVAClassification_TMlpANN_WithENu * fTMVAModuleTMlpANNWithENu
Definition: SPIDAlg.h:114
void slid::SPIDAlg::DefineTrainingTree ( )

Define mapping of branches to class fields for tree to be used for training the algorithms.

Definition at line 424 of file SPIDAlg.cxx.

Referenced by Description().

425  {
426  // //
427  // // I think this in Jianming's output training TTree. Should be packaged up
428  // // for readability
429  // //
430  // art::ServiceHandle<art::TFileService> tfs;
431  // //True neutrino information
432  // fEvent = tfs->make<TTree>("fEvent", "fEvent");
433  //// fEvent->Branch("evtTrueNuCCNC", &m_evtTrueNuCCNC);
434  //// fEvent->Branch("evtTrueNuMode", &m_evtTrueNuMode);
435  //// fEvent->Branch("evtTrueNuPdg", &m_evtTrueNuPdg);
436  //// fEvent->Branch("evtTrueNuEnergy", &m_evtTrueNuEnergy);
437  //// fEvent->Branch("evtTrueNuIsFid", &m_evtTrueNuIsFid);
438  //// fEvent->Branch("evtTrueNuP4[4]", m_evtTrueNuP4);
439  //// fEvent->Branch("evtTrueNuVtx[3]", m_evtTrueNuVtx);
440  //// fEvent->Branch("evtTrueEnergy[20]", m_evtTrueEnergy);
441  //// fEvent->Branch("evtTruePdg[20]", m_evtTruePdg);
442  //// fEvent->Branch("evtTrueMother[20]", m_evtTrueMother);
443  //
444  // //Reconstructed information
445  // fEvent->Branch("evtRun", &m_evtRun);
446  // fEvent->Branch("evtSRun", &m_evtSRun);
447  // fEvent->Branch("evtNSlice", &m_evtNSlice);
448  // fEvent->Branch("evtNSh", &m_evtNSh);
449  //
450  //// fEvent->Branch("evtEtot", &m_evtEtot);
451  //// fEvent->Branch("evtSigOscW", &m_evtSigOscW);
452  //// fEvent->Branch("evtBkgOscW", &m_evtBkgOscW);
453  //// fEvent->Branch("evtIsMuon", &m_evtIsMuon);
454  //// fEvent->Branch("evtIsMuonSh1", &m_evtIsMuonSh1);
455  //// fEvent->Branch("evtIsInvPhoton", &m_evtIsInvPhoton);
456  //// fEvent->Branch("evtDetEnergy", &m_evtDetEnergy);
457  //// fEvent->Branch("evtNuEnergy", &m_evtNuEnergy);
458  //// fEvent->Branch("evtSh1ExclEnergy", &m_evtSh1ExclEnergy);
459  //// fEvent->Branch("evtSh1Length", &m_evtSh1Length);
460  //// fEvent->Branch("evtSh1Start[3]", m_evtSh1Start);
461  //// fEvent->Branch("evtSh1Stop[3]", m_evtSh1Stop);
462  //// fEvent->Branch("evtSh1Dir[3]", m_evtSh1Dir);
463  //
464  //// fEvent->Branch("evtVtx[3]", m_evtVtx);
465  //
466  // fEvent->Branch("sh1EGLLL", &m_sh1EGLLL);
467  // fEvent->Branch("sh1EGLLT", &m_sh1EGLLT);
468  // fEvent->Branch("sh1EMuLLL", &m_sh1EMuLLL);
469  // fEvent->Branch("sh1EMuLLT", &m_sh1EMuLLT);
470  // fEvent->Branch("sh1EPi0LLL", &m_sh1EPi0LLL);
471  // fEvent->Branch("sh1EPi0LLT", &m_sh1EPi0LLT);
472  // fEvent->Branch("sh1EPLLL", &m_sh1EPLLL);
473  // fEvent->Branch("sh1EPLLT", &m_sh1EPLLT);
474  // fEvent->Branch("sh1ENLLL", &m_sh1ENLLL);
475  // fEvent->Branch("sh1ENLLT", &m_sh1ENLLT);
476  // fEvent->Branch("sh1EPiLLL", &m_sh1EPiLLL);
477  // fEvent->Branch("sh1EPiLLT", &m_sh1EPiLLT);
478  // fEvent->Branch("sh1VtxGeV", &m_sh1VtxGeV);
479  // fEvent->Branch("sh1Pi0Mass", &m_sh1Pi0Mass);
480  // fEvent->Branch("sh1ShE", &m_sh1ShE);
481  // fEvent->Branch("sh1Gap", &m_sh1Gap);
482  // fEvent->Branch("sh1Energy", &m_sh1Energy);
483  //
484  //// fEvent->Branch("evtSh1ELLL", &m_evtSh1ELLL);
485  //// fEvent->Branch("evtSh1ELLT", &m_evtSh1ELLT);
486  //// fEvent->Branch("evtSh1MuLLL", &m_evtSh1MuLLL);
487  //// fEvent->Branch("evtSh1MuLLT", &m_evtSh1MuLLT);
488  //// fEvent->Branch("evtSh1GLLL", &m_evtSh1GLLL);
489  //// fEvent->Branch("evtSh1InvGLLL", &m_evtSh1InvGLLL);
490  //// fEvent->Branch("evtSh1DistToEdge", &m_evtSh1DistToEdge);
491  //// fEvent->Branch("evtSh1SliceEdge2GeV", &m_evtSh1SliceEdge2GeV);
492  //// fEvent->Branch("evtSh1SliceEdge5GeV", &m_evtSh1SliceEdge5GeV);
493  //// fEvent->Branch("evtSh1SliceEdge10GeV", &m_evtSh1SliceEdge10GeV);
494  //
495  //
496  // fEvent->Branch("eIdANNNoNuE", &m_eIdANNNoNuE);
497  // fEvent->Branch("eIdANNWithNuE", &m_eIdANNWithNuE);
498 
499  }
std::string slid::SPIDAlg::Description ( )
inline

Definition at line 61 of file SPIDAlg.h.

References DefineTrainingTree(), fDescription, FillTrainingTree(), and InitializeTrainingTree().

62  {
63  return fDescription;
64  }
const std::string fDescription
Name of algorithm.
Definition: SPIDAlg.h:92
void slid::SPIDAlg::FillTrainingTree ( const slid::ShowerPID showerspid)

Fill tree to be used for training the algorithms.

Definition at line 419 of file SPIDAlg.cxx.

Referenced by Description().

420  {
421 
422  }
void slid::SPIDAlg::Initialize ( )

Initialize the MVA algorithm. The parameter detectorID is an int corresponding to the detector definitions in novadaq::cnv : novadaq::cnv::kFARDET, novadaq::cnv::kNDOS, novadaq::cnv::kNEARDET.

Definition at line 48 of file SPIDAlg.cxx.

References om::cout, geo::GeometryBase::DetId(), allTimeWatchdog::endl, slid::ShowerLID::fEGLLL, slid::ShowerLID::fEGLLT, slid::ShowerLID::fEMuLLL, slid::ShowerLID::fEMuLLT, slid::ShowerLID::fENLLL, slid::ShowerLID::fENLLT, slid::ShowerLID::fEPi0LLL, slid::ShowerLID::fEPi0LLT, slid::ShowerLID::fEPiLLL, slid::ShowerLID::fEPiLLT, slid::ShowerLID::fEPLLL, slid::ShowerLID::fEPLLT, slid::ShowerLID::fGap, fLibPath, fMlp, fMVAMethod, slid::ShowerLID::fNueEnergy, slid::ShowerLID::fPi0mass, fPIDType, fReader, fShowerPID, slid::ShowerLID::fShwEFrac, fType, fUseTMVATraining, slid::ShowerLID::fVtxE, geom(), novadaq::cnv::kFARDET, novadaq::cnv::kNDOS, novadaq::cnv::kNEARDET, demo0::length, and string.

Referenced by SPIDAlg().

49  {
51  int detectorID = geom->DetId();
52  //
53  // TMVA MVA Methods
54  //
55  std::string weightfile0(fLibPath);
56  std::string weightfile2(fLibPath);
57  std::string weightfileEPi0(fLibPath);
58  std::string weightfileEPi0EL(fLibPath);
59  switch (detectorID) {
61  if (fUseTMVATraining){
62  weightfile0 += "TMVAClassification_" + fMVAMethod + ".weights_FD_elec.xml";
63  weightfile2 += "TMVAClassification_" + fMVAMethod + ".weights_FD_elec_withNue.xml";
64  }
65  else {
66  weightfile0 += "weights_shape_fd_elec.txt";
67  weightfile2 += "weights_shape_fd_elec_E.txt";
68  weightfileEPi0 += "weights_shape_fd_elec_E_epi0.txt";
69  weightfileEPi0EL += "weights_shape_fd_elec_E_epi0EL.txt";
70  }
71  break;
73  if (fUseTMVATraining){
74  weightfile0 += "TMVAClassification_" + fMVAMethod + ".weights_NDOS_elec.xml";
75  weightfile2 += "TMVAClassification_" + fMVAMethod + ".weights_NDOS_elec_withNue.xml";
76  }
77  else {
78  weightfile0 += "weights_shape_fd_elec.txt";
79  weightfile2 += "weights_shape_fd_elec_E.txt";
80  weightfileEPi0 += "weights_shape_fd_elec_E_epi0.txt";
81  weightfileEPi0EL += "weights_shape_fd_elec_E_epi0EL.txt";
82  }
83  break;
85  if (fUseTMVATraining){
86  weightfile0 += "TMVAClassification_" + fMVAMethod + ".weights_ND_elec.xml";
87  weightfile2 += "TMVAClassification_" + fMVAMethod + ".weights_ND_elec_withNue.xml";
88  }
89  else {
90  weightfile0 += "weights_shape_fd_elec.txt";
91  weightfile2 += "weights_shape_fd_elec_E.txt";
92  weightfileEPi0 += "weights_shape_fd_elec_E_epi0.txt";
93  weightfileEPi0EL += "weights_shape_fd_elec_E_epi0EL.txt";
94  }
95  break;
96  default:
97  throw cet::exception("BAD DETID") << __FILE__ << ":" << __LINE__
98  << " Bad detector id = " << detectorID;
99  }
100 
101 
102  //
103  // mode 0 training variable set (base, without reco nue energy)
104  //
105  if (fUseTMVATraining){
106  if (fPIDType==0) {// Without energy
107  std::cout << "Defining TMVA::Reader object for mode 0..." << std::endl;
108  fReader = new TMVA::Reader("!Color:!Silent");
109  std::cout << "Adding variables to Reader for mode 0..." << std::endl;
110  fReader->AddVariable("egLLL", &fShowerPID->fEGLLL);
111  fReader->AddVariable("egLLT", &fShowerPID->fEGLLT);
112  fReader->AddVariable("emuLLL", &fShowerPID->fEMuLLL);
113  fReader->AddVariable("emuLLT", &fShowerPID->fEMuLLT);
114  fReader->AddVariable("epi0LLL", &fShowerPID->fEPi0LLL);
115  fReader->AddVariable("epi0LLT", &fShowerPID->fEPi0LLT);
116  fReader->AddVariable("epLLL", &fShowerPID->fEPLLL);
117  fReader->AddVariable("epLLT", &fShowerPID->fEPLLT);
118  fReader->AddVariable("enLLL", &fShowerPID->fENLLL);
119  fReader->AddVariable("enLLT", &fShowerPID->fENLLT);
120  fReader->AddVariable("epiLLL", &fShowerPID->fEPiLLL);
121  fReader->AddVariable("epiLLT", &fShowerPID->fEPiLLT);
122  fReader->AddVariable("gap", &fShowerPID->fGap);
123  fReader->AddVariable("pi0mass", &fShowerPID->fPi0mass);
124  fReader->AddVariable("vtxgev", &fShowerPID->fVtxE);
125  fReader->AddVariable("shE", &fShowerPID->fShwEFrac);
126  fReader->AddSpectator("sbtype", &fType);
127  // Book the TMVA Algorithms
128  //
129  // Set the training weights file. **NOTE** due to a bug in TMVA model using weights from file
130  // does not work.
131  //
132  // fWeightsFile = fXMLPath + "TMVAClassification_KNN.weights.xml";
133  // Book Method
134  fReader->BookMVA((fMVAMethod + TString(" method")), weightfile0);
135  }
136  else if(fPIDType==1){// With energy
137  std::cout << "Defining TMVA::Reader object for mode 2..." << std::endl;
138  fReader = new TMVA::Reader("!Color:!Silent");
139  std::cout << "Adding variables to Reader for mode 2..." << std::endl;
140  fReader->AddVariable("egLLL", &(fShowerPID->fEGLLL));
141  fReader->AddVariable("egLLT", &(fShowerPID->fEGLLT));
142  fReader->AddVariable("emuLLL", &(fShowerPID->fEMuLLL));
143  fReader->AddVariable("emuLLT", &(fShowerPID->fEMuLLT));
144  fReader->AddVariable("epi0LLL", &(fShowerPID->fEPi0LLL));
145  fReader->AddVariable("epi0LLT", &(fShowerPID->fEPi0LLT));
146  fReader->AddVariable("epLLL", &(fShowerPID->fEPLLL));
147  fReader->AddVariable("epLLT", &(fShowerPID->fEPLLT));
148  fReader->AddVariable("enLLL", &(fShowerPID->fENLLL));
149  fReader->AddVariable("enLLT", &(fShowerPID->fENLLT));
150  fReader->AddVariable("epiLLL", &(fShowerPID->fEPiLLL));
151  fReader->AddVariable("epiLLT", &(fShowerPID->fEPiLLT));
152  fReader->AddVariable("gap", &(fShowerPID->fGap));
153  fReader->AddVariable("pi0mass", &(fShowerPID->fPi0mass));
154  fReader->AddVariable("vtxgev", &(fShowerPID->fVtxE));
155  fReader->AddVariable("shE", &(fShowerPID->fShwEFrac));
156  fReader->AddVariable("nueRecEnergy",&(fShowerPID->fNueEnergy));
157  fReader->AddSpectator("sbtype", &fType);
158  // Book the TMVA Algorithms
159  //
160  // Set the training weights file. **NOTE** due to a bug in TMVA model using weights from file
161  // does not work.
162  //
163  // fWeightsFile = fXMLPath + "TMVAClassification_KNN.weights.xml";
164  // Book Method
165  fReader->BookMVA((fMVAMethod + TString(" method")), weightfile2);
166  }
167  }
168  else{
169 
170  //NOTE the varialbe shE really means showerEnergy/SliceEnergy. I am not changing the name here because this is how it is listed in the training files.
171  //At some point the training should be updated so that this name makes more sense.
172 
173  double egLLL;
174  double egLLT;
175  double emuLLL;
176  double emuLLT;
177  double epi0LLL;
178  double epi0LLT;
179  double epLLL;
180  double epLLT;
181  double enLLL;
182  double enLLT;
183  double epiLLL;
184  double epiLLT;
185  double vtxgev;
186  double pi0mass;
187  double shE;
188  double nuE;
189  double gap;
190  double length;
191  double costheta;
192  double dedx0;
193  double dedx1;
194  double dedx2;
195  double dedx3;
196  int type;
197 
198  TTree *trainTree = new TTree("trainTree","m_trainTree");
199  trainTree->Branch("egLLL", &egLLL, "egLLL/D");
200  trainTree->Branch("egLLT", &egLLT, "egLLT/D");
201  trainTree->Branch("emuLLL", &emuLLL, "emuLLL/D");
202  trainTree->Branch("emuLLT", &emuLLT, "emuLLT/D");
203  trainTree->Branch("epi0LLL", &epi0LLL, "epi0LLL/D");
204  trainTree->Branch("epi0LLT", &epi0LLT, "epi0LLT/D");
205  trainTree->Branch("epLLL", &epLLL, "epLLL/D");
206  trainTree->Branch("epLLT", &epLLT, "epLLT/D");
207  trainTree->Branch("enLLL", &enLLL, "enLLL/D");
208  trainTree->Branch("enLLT", &enLLT, "enLLT/D");
209  trainTree->Branch("epiLLL", &epiLLL, "epiLLL/D");
210  trainTree->Branch("epiLLT", &epiLLT, "epiLLT/D");
211  trainTree->Branch("gap", &gap, "gap/D");
212  trainTree->Branch("pi0mass", &pi0mass, "pi0mass/D");
213  trainTree->Branch("vtxgev", &vtxgev, "vtxgev/D");
214  trainTree->Branch("shE", &shE, "shE/D");
215  trainTree->Branch("nuE", &nuE, "nuE/D");
216  trainTree->Branch("costheta", &costheta, "costheta/D");
217  trainTree->Branch("length", &length, "length/D");
218  trainTree->Branch("dedx0", &dedx0, "dedx0/D");
219  trainTree->Branch("dedx1", &dedx1, "dedx1/D");
220  trainTree->Branch("dedx2", &dedx2, "dedx2/D");
221  trainTree->Branch("dedx3", &dedx3, "dedx3/D");
222  trainTree->Branch("type", &type, "type/I");
223 
224  if (fPIDType!=1&&fPIDType!=2&&fPIDType!=3)fPIDType = 0;
225  if (fPIDType==0) {// ANN without E
226  fMlp = new TMultiLayerPerceptron("@egLLL,@egLLT,@emuLLL,@emuLLT,@epi0LLL,@epi0LLT,@epLLL,@epLLT,@enLLL,@enLLT,@epiLLL,@epiLLT,@pi0mass,@shE,@vtxgev,@gap,@costheta:22:12:6:type", trainTree);
227  fMlp->LoadWeights(weightfile0.c_str());
228  }
229  else if (fPIDType==1){// ANN with E
230  fMlp = new TMultiLayerPerceptron("@egLLL,@egLLT,@emuLLL,@emuLLT,@epi0LLL,@epi0LLT,@epLLL,@epLLT,@enLLL,@enLLT,@epiLLL,@epiLLT,@pi0mass,@shE,@vtxgev,@gap,@costheta,@nuE:22:12:6:type", trainTree);
231  fMlp->LoadWeights(weightfile2.c_str());
232  }
233  else if (fPIDType==2){// e/pi0 PID
234  fMlp = new TMultiLayerPerceptron("@dedx0,@dedx1,@dedx2,@dedx3,@costheta:25:12:6:type", trainTree);
235  fMlp->LoadWeights(weightfileEPi0.c_str());
236  }
237  else if (fPIDType==3){// e/pi PID for nu-E scattering
238  fMlp = new TMultiLayerPerceptron("@dedx0,@dedx1,@dedx2,@dedx3:25:12:6:type", trainTree);
239  fMlp->LoadWeights(weightfileEPi0EL.c_str());
240  }
241 
242  delete trainTree;
243  }
244 
245  }
TMultiLayerPerceptron * fMlp
FCL parameters for Nue energy calculation algorithm.
Definition: SPIDAlg.h:105
std::string fLibPath
Location of weight files. Set from FCL file.
Definition: SPIDAlg.h:95
slid::ShowerPID * fShowerPID
Definition: SPIDAlg.h:124
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
const std::string fMVAMethod
Definition: SPIDAlg.h:87
Far Detector at Ash River, MN.
length
Definition: demo0.py:21
Prototype Near Detector on the surface at FNAL.
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Near Detector in the NuMI cavern.
int fPIDType
If true, the ANN is computed with event energy as an input variable.
Definition: SPIDAlg.h:85
int fType
event classification answer: 1 = signal, 0 = background
Definition: SPIDAlg.h:119
OStream cout
Definition: OStream.cxx:6
bool fUseTMVATraining
Use TMVA training or RecoJMShower training.
Definition: SPIDAlg.h:98
void geom(int which=0)
Definition: geom.C:163
TMVA::Reader * fReader
TMVA reader object used to store MVA model.
Definition: SPIDAlg.h:109
float fNueEnergy
Definition: ShowerLID.h:208
enum BeamMode string
void slid::SPIDAlg::InitializeTrainingTree ( )

Initialize tree to be used for training the algorithms.

Definition at line 501 of file SPIDAlg.cxx.

Referenced by Description().

502  {
503  // //fEvent
504  // m_evtTrueNuCCNC = 0;
505  // m_evtTrueNuMode = 0;
506  // m_evtTrueNuPdg = 0;
507  // m_evtTrueNuEnergy = 0;
508  // m_evtTrueNuIsFid = 0;
509  // for (int i = 0; i < 4; i++) {
510  // m_evtTrueNuP4[i] = 0;
511  // }
512  // for (int i = 0; i < 3; i++) {
513  // m_evtTrueNuVtx[i] = 0;
514  // }
515  // for (int i = 0; i < 20; i++) {
516  // m_evtTruePdg[i] = 0;
517  // }
518  // for (int i = 0; i < 20; i++) {
519  // m_evtTrueMother[i] = 0;
520  // }
521  // for (int i = 0; i < 20; i++) {
522  // m_evtTrueEnergy[i] = 0;
523  // }
524  // m_evtRun = 0;
525  // m_evtSRun = 0;
526  // m_evtEvent = 0;
527  // m_evtNSlice = 0;
528  // m_evtNSh = 0;
529  // m_evt = 0;
530  // m_evtANN = -5;
531  // m_evtSh1DedxANN = -5;
532  // m_evtSh1DedxANNE = -5;
533  // m_evtEtot = 0;
534  // m_evtSigOscW = 0;
535  // m_evtBkgOscW = 0;
536  // m_evtIsMuon = 0;
537  // m_evtIsInvPhoton = 0;
538  // m_evtDetEnergy = 0;
539  // m_evtTrueNuEnergy = 0;
540  // m_evtNuEnergy = 0;
541  // m_evtSh1Energy = 0;
542  // m_evtSh1ExclEnergy = 0;
543  // m_evtSh1Length = 0;
544  //
545  // for (int i = 0; i < 3; i++) {
546  // m_evtVtx[i] = 0;
547  // m_evtSh1Start[i] = 0;
548  // m_evtSh1Stop[i] = 0;
549  // m_evtSh1Dir[i] = 0;
550  // }
551  //
552  // m_evtSh1EGLLL = 0;
553  // m_evtSh1EGLLT = 0;
554  // m_evtSh1EMuLLL = 0;
555  // m_evtSh1EMuLLT = 0;
556  // m_evtSh1EPi0LLL = 0;
557  // m_evtSh1EPi0LLT = 0;
558  // m_evtSh1EPLLL = 0;
559  // m_evtSh1EPLLT = 0;
560  // m_evtSh1ENLLL = 0;
561  // m_evtSh1ENLLT = 0;
562  // m_evtSh1EPiLLL = 0;
563  // m_evtSh1EPiLLT = 0;
564  // m_evtSh1VtxGeV = 0;
565  // m_evtSh1Pi0Mass = 0;
566  // m_evtSh1ShE = 0;
567  // m_evtSh1Gap = 0;
568  // m_evtSh1ELLL = 0;
569  // m_evtSh1ELLT = 0;
570  // m_evtSh1MuLLL = 0;
571  // m_evtSh1MuLLT = 0;
572  // m_evtSh1GLLL = 0;
573  // m_evtSh1InvGLLL = 0;
574  // m_evtSh1DistToEdge = 0;
575  // m_evtSh1SliceEdge2GeV = 0;
576  // m_evtSh1SliceEdge5GeV = 0;
577  // m_evtSh1SliceEdge10GeV = 0;
578  }
std::string slid::SPIDAlg::Name ( )
inline

Definition at line 56 of file SPIDAlg.h.

References fName.

57  {
58  return fName;
59  }
const std::string fName
Definition: SPIDAlg.h:88

Member Data Documentation

std::string slid::SPIDAlg::fAlgorithmName
private

FCL Parameters for LIDAlg.

Name of MVA algorithm to use

Definition at line 79 of file SPIDAlg.h.

Referenced by SPIDAlg().

const std::string slid::SPIDAlg::fDescription = "TMVA ANN algorithm TMlpANN with no nu(E)"
private

Name of algorithm.

Definition at line 92 of file SPIDAlg.h.

Referenced by Description().

std::string slid::SPIDAlg::fLibPath
private

Location of weight files. Set from FCL file.

Definition at line 95 of file SPIDAlg.h.

Referenced by Initialize(), and SPIDAlg().

TMultiLayerPerceptron* slid::SPIDAlg::fMlp
private

FCL parameters for Nue energy calculation algorithm.

Definition at line 105 of file SPIDAlg.h.

Referenced by CalcMVAResult(), Initialize(), and ~SPIDAlg().

const std::string slid::SPIDAlg::fMVAMethod = "TMlpANN"
private

Definition at line 87 of file SPIDAlg.h.

Referenced by Initialize().

const std::string slid::SPIDAlg::fName = fMVAMethod + "NoNuE"
private

Definition at line 88 of file SPIDAlg.h.

Referenced by Name().

NuEEnergyAlg* slid::SPIDAlg::fNuEEnergyAlg
private

NuE energy calculations object.

Definition at line 82 of file SPIDAlg.h.

float slid::SPIDAlg::fNueRecEnergy
private

Definition at line 129 of file SPIDAlg.h.

int slid::SPIDAlg::fPIDType
private

If true, the ANN is computed with event energy as an input variable.

Definition at line 85 of file SPIDAlg.h.

Referenced by CalcMVAResult(), and Initialize().

TMVA::Reader* slid::SPIDAlg::fReader
private

TMVA reader object used to store MVA model.

Definition at line 109 of file SPIDAlg.h.

Referenced by Initialize(), and ~SPIDAlg().

float slid::SPIDAlg::fShE
private

Definition at line 128 of file SPIDAlg.h.

slid::ShowerPID* slid::SPIDAlg::fShowerPID
private

Definition at line 124 of file SPIDAlg.h.

Referenced by Initialize().

TMVAClassification_TMlpANN_NoENu* slid::SPIDAlg::fTMVAModuleTMlpANNNoENu
private

Definition at line 115 of file SPIDAlg.h.

Referenced by CalcMVAResult().

TMVAClassification_TMlpANN_WithENu* slid::SPIDAlg::fTMVAModuleTMlpANNWithENu
private

XML weights file, but there seems to be a bug in TMVA that the module simply does not work when loading from the weights for the TMlPANN algorithm. Needs to be investigated further.

Definition at line 114 of file SPIDAlg.h.

Referenced by CalcMVAResult().

int slid::SPIDAlg::fType
private

event classification answer: 1 = signal, 0 = background

Definition at line 119 of file SPIDAlg.h.

Referenced by Initialize().

bool slid::SPIDAlg::fUseTMVATraining
private

Use TMVA training or RecoJMShower training.

Definition at line 98 of file SPIDAlg.h.

Referenced by CalcMVAResult(), Initialize(), and SPIDAlg().

float slid::SPIDAlg::fVtxgev
private

Definition at line 127 of file SPIDAlg.h.


The documentation for this class was generated from the following files: