FairRoot/PandaRoot
PndHypPidIdealTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndMvdPidIdealTask source file -----
3 // ----- Created 11/07/07 by T.Baldauf -----
4 // ----- modified for hyp prupose by A. Sanchez -----
5 // -------------------------------------------------------------------------
6 // libc includes
7 #include <iostream>
8 #include <vector>
9 
10 // Root includes
11 #include "TROOT.h"
12 #include "TString.h"
13 #include "TClonesArray.h"
14 #include "TParticlePDG.h"
15 #include "TObject.h"
16 #include "TH1.h"
17 #include "TH2.h"
18 #include "TCanvas.h"
19 
20 // framework includes
21 #include "FairRootManager.h"
22 #include "PndHypPidIdealTask.h"
23 #include "FairRunAna.h"
24 #include "FairRuntimeDb.h"
25 #include "../pnddata/PndMCTrack.h"
26 
27 
28 // PndHyp includes
29 #include "PndHypPoint.h"
30 #include "PndHypPidCand.h"
31 // #include "PndHypHit.h"
32 
33 // #include "PndHypIdealPidAlgo.h"
34 // #include "HypPid/PndHypSimplePidAlgo.h"
35 #include "PndHypAdvancedPidAlgo.h"
36 
37 // ----- Default constructor -------------------------------------------
38 PndHypPidIdealTask::PndHypPidIdealTask(TString algoName) : FairTask("Digitization task for PANDA PndHyp") {
39  fBranchName = "HypPoint";
40  fAlgoName = algoName;
41 }
42 
43 // ----- Public method Init --------------------------------------------
45 {
46  // Get RootManager
47  FairRootManager* ioman = FairRootManager::Instance();
48  if ( ! ioman ) {
49  std::cout << "-E- PndHypPidIdealTask::Init: "<< "RootManager not instantiated!" << std::endl;
50  return kFATAL; }
51 
52  // Get input array
53  fPointArray = (TClonesArray*) ioman->GetObject(fBranchName);
54  if ( ! fPointArray ) {
55  std::cout << "-W- PndHypPidIdealTask::Init: "<< "No "<<fBranchName<<" array!" << std::endl;
56  return kERROR; }
57 
58  // Get MCTruth collection
59  fMcArray=(TClonesArray*) ioman->GetObject("MCTrack");
60  if(fMcArray==0) {
61  std::cout << "-W- PndHypPidIdealTask::Init: "<< "No McTruth array!" << std::endl;
62  return kERROR; }
63 
64  // Create and register output array
65  fTrackOutputArray = new TClonesArray("PndHypPidCand");
66  ioman->Register("PndHypPidCand", "PndHyp ideal tracklets", fTrackOutputArray, kTRUE);
67 
68  if (fAlgoName!="ideal"&&fAlgoName!="simple"&&fAlgoName!="advanced") {
69  std::cout << "-W- PndHypPidIdealTask::Init: "<< "No pid algorithm named '"<< fAlgoName <<"'! Names are 'ideal', 'simple', 'advanced'" << std::endl;
70  return kERROR;
71  }
72  return kSUCCESS;
73 }
74 // -------------------------------------------------------------------------
76 {
77  // Get Base Container
78  //FairRunAna* ana = FairRunAna::Instance(); //[R.K. 01/2017] unused variable?
79  //FairRuntimeDb* rtdb=ana->GetRuntimeDb(); //[R.K. 01/2017] unused variable
80 
81 }
82 
83 
84 
85 //----------------Exec----------------
86 void PndHypPidIdealTask::Exec(Option_t*)
87 {
88  if ( ! fTrackOutputArray ) Fatal("Exec", "No fTrackOutputArray");
89  fTrackOutputArray->Clear();
90 
91  // the dE/dx information of PndmvdPidCand is obtained by PndHypMCPoints
92  std::map<int, PndHypPidCand*> pidcand;
93  TVector3 Out,In;
94 
95  for(int i=0;i<fPointArray->GetEntriesFast();i++) {
96  PndHypPoint* mvdpoint=(PndHypPoint*) fPointArray->At(i);
97  mvdpoint->PositionOut(Out);
98  mvdpoint->PositionIn(In);
99 
100  int track = mvdpoint->GetTrackID();
101  if(!pidcand[track])
102  pidcand[track]=new PndHypPidCand();
103  double dx = ( Out - In ).Mag();
104  double dE = mvdpoint->GetEnergyLoss();
105  TVector3 momentum;
106  mvdpoint->Momentum(momentum);
107 
108  std::cout<<dE<<" "<<dx<<" "<<momentum.Mag()<<std::endl;
109 
110  if(dx>0)pidcand[track]->AddHypHit(dE, dx, momentum.Mag());
111  }
112 
113  // invoke likelohood calculation, TClonesArray output
114  for(std::map<int, PndHypPidCand*>::iterator it=pidcand.begin();it!=pidcand.end();it++) {
115  int track = it->first;
116  if (fAlgoName=="advanced")
118  std::cout<<" track to be piditized "<<std::endl;
119 
120  int size = fTrackOutputArray->GetEntriesFast();
121  new ((*fTrackOutputArray)[size]) PndHypPidCand(*(pidcand[track]));
122  }
123 }
124 
125 
126 // -------------------------------------------------------------------------
127 
virtual void Exec(Option_t *opt)
Int_t i
Definition: run_full.C:25
virtual void SetParContainers()
Double_t dE
Definition: anasim.C:58
void PositionIn(TVector3 &pos)
Definition: PndHypPoint.h:125
static void CalcLikelihood(PndHypPidCand *cand)
PndMCTrack * track
Definition: anaLmdCluster.C:89
PndHypPidIdealTask(const TString algoName="ideal")
double dx
TClonesArray * fPointArray
void PositionOut(TVector3 &pos)
Definition: PndHypPoint.h:128
TClonesArray * fMcArray
ClassImp(PndAnaContFact)
TClonesArray * fTrackOutputArray
virtual InitStatus Init()