FairRoot/PandaRoot
PndLmdNoiseTrkSuppressionTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndLmdNoiseTrkSuppressionTask source file -----
3 // ----- Created 21/07/15 by A.Karavdina -----
4 // -------------------------------------------------------------------------
5 
6 // libc includes
7 #include <iostream>
8 #include <map>
9 #include <vector>
10 
11 // Root includes
12 #include <TMatrixDSym.h>
13 #include "TClonesArray.h"
14 #include "TROOT.h"
15 #include "TTree.h"
16 #include "TVector3.h"
17 
18 // framework includes
19 #include "FairRootManager.h"
20 #include "FairRun.h"
21 #include "FairRunAna.h"
22 #include "FairRuntimeDb.h"
23 #include "FairTrackParH.h"
24 #include "FairTrackParP.h"
26 #include "PndTrack.h"
27 // ----- Default constructor -------------------------------------------
29  : FairTask("Cleaning Tracks from noise hits Task for PANDA Lmd"),
30  fEventNr(0) {
31  // tprop = new TNtuple();
32  // fEventNr = 0;
33 }
34 // -------------------------------------------------------------------------
35 
37  TString dir)
38  : FairTask("Cleaning Tracks from noise hits Task for PANDA Lmd"),
39  fEventNr(0) {
40  fdir = dir;
41  fPbeam = pBeam;
42  std::cout << "Beam Momentum in this run is " << fPbeam << std::endl;
43 }
44 
45 // ----- Destructor ----------------------------------------------------
47 
48 // ----- Public method Init --------------------------------------------
50  // Get RootManager
51  FairRootManager* ioman = FairRootManager::Instance();
52  if (!ioman) {
53  std::cout << "-E- PndLmdNoiseTrkSuppressionTask::Init: "
54  << "RootManager not instantiated!" << std::endl;
55  return kFATAL;
56  }
57 
58  fTrkInArray = (TClonesArray*)ioman->GetObject("LMDPndTrackFilt");
59  if (!fTrkInArray) {
60  std::cout << "-W- PndLmdNoiseTrkSuppressionTask::Init: "
61  << "No LMDPndTrack"
62  << " array!" << std::endl;
63  return kERROR;
64  }
65 
66  fTrkOutArray = new TClonesArray("PndTrack");
67  ioman->Register("LMDPndTrackFilt", "PndLmd", fTrkOutArray, kTRUE);
68 
69  // fGeoH = PndGeoHandling::Instance();
70  // FairRun* fRun = FairRun::Instance(); //[R.K. 01/2017] unused variable?
71  // FairRuntimeDb* rtdb = fRun->GetRuntimeDb(); //[R.K. 01/2017] unused
72  // variable
73 
74  // TMVA -----------------------------------------------------
75  // This loads the library
76  // if(fabs(fPbeam-1.5)<1e-1 || fabs(fPbeam-15)<1e-1){
77  TMVA::Tools::Instance();
78 
79  // TMVA::Reader *
80  reader = new TMVA::Reader("!Color:!Silent");
81 
82  // Create a set of variables and declare them to the reader
83  // - the variable names MUST corresponds in name and type to those given in
84  // the weight file(s) used
85  reader->AddVariable("LMDTrackQ.fThetarecLMD", &athrec);
86  reader->AddVariable("LMDTrackQ.fPhirecLMD", &aphrec);
87  reader->AddVariable("LMDTrackQ.fXrecLMD", &axrec);
88  reader->AddVariable("LMDTrackQ.fYrecLMD", &ayrec);
89 
90  // TString dir = "weights/";
91  TString prefix = "TMVAClassification";
92  fmethodName = "BDT method";
93  TString weightfile =
94  fdir + prefix + TString("_BDT") + TString(".weights.xml");
95  reader->BookMVA(fmethodName, weightfile);
96  // }
97  // else{
98  // std::cout << "-W- PndLmdNoiseTrkSuppressionTask::Init: "<< "This method was
99  // not trained for momentum"<< fPbeam << std::endl;
100  // return kERROR;
101  // }
102  //------------------------------------------------------
103  return kSUCCESS;
104 }
105 // -------------------------------------------------------------------------
107  // Get Base Container
109  // FairRuntimeDb* rtdb=ana->GetRuntimeDb();
110 }
111 
112 // ----- Public method Exec --------------------------------------------
114  fTrkOutArray->Delete();
115  if (fVerbose > 2) {
116  std::cout << " ---- Info: " << fEventNr << std::endl;
117  }
118 
119  // go through all tracks
120  const int nTrks = fTrkInArray->GetEntries();
121  int rec_trk = 0;
122  for (Int_t iN = 0; iN < nTrks; iN++) { // loop over all reconstructed trks
123  PndTrack* trkpnd = (PndTrack*)(fTrkInArray->At(iN));
124  FairTrackParP fFittedTrkP = trkpnd->GetParamFirst();
125 
126  // check the track
127  axrec = fFittedTrkP.GetX();
128  ayrec = fFittedTrkP.GetY();
129  TVector3 MomRecLMD(fFittedTrkP.GetPx(), fFittedTrkP.GetPy(),
130  fFittedTrkP.GetPz());
131  MomRecLMD *= 1. / MomRecLMD.Mag();
132  athrec = MomRecLMD.Theta();
133  aphrec = MomRecLMD.Phi();
134  double mva_response = reader->EvaluateMVA(fmethodName);
135  if (fVerbose > 2)
136  std::cout << "mva_response = " << mva_response << std::endl;
137  bool isSigTrk;
138  if (mva_response < 0)
139  isSigTrk = false;
140  else
141  isSigTrk = true;
142  if (isSigTrk) {
143  // save good trks
144  new ((*fTrkOutArray)[rec_trk]) PndTrack(*(trkpnd)); // save Track
145  rec_trk++;
146  }
147  }
148  if (fVerbose > 2)
149  std::cout << "Ev#" << fEventNr << ": " << rec_trk << " trks saved out of "
150  << nTrks << std::endl;
151  fEventNr++;
152 }
153 
int fVerbose
Definition: poormantracks.C:24
ClassImp(PndLmdNoiseTrkSuppressionTask)
Double_t
FairTrackParP GetParamFirst()
Definition: PndTrack.h:49