FairRoot/PandaRoot
PndMcListConverter.cxx
Go to the documentation of this file.
1 /******************************************************
2 Converts the MCTracks to a TCA holding RhoCandidates
3 *******************************************************/
4 
5 #include "TClonesArray.h"
6 
7 #include "FairRootManager.h"
8 #include "FairRunAna.h"
9 #include "FairRuntimeDb.h"
10 
11 #include "FairRun.h"
12 #include "FairRuntimeDb.h"
13 #include "PndMcListConverter.h"
14 #include <string>
15 #include <iostream>
16 #include "PndMCTrack.h"
17 
18 //Root stuff
19 #include "TClonesArray.h"
20 #include "TParticle.h"
21 #include "TDatabasePDG.h"
22 #include "TParticlePDG.h"
23 
24 //RHO stuff
25 #include "RhoBase/RhoCandidate.h"
26 
27 
28 using std::cout;
29 using std::endl;
30 
31 
32 // ----- Default constructor -------------------------------------------
34  FairTask("Panda MCTracks to RhoCandidates Converter")
35 {
36 }
37 // -------------------------------------------------------------------------
38 
39 // ----- Destructor ----------------------------------------------------
41 {
42  if(fMcCandidates) { delete fMcCandidates; }
43 }
44 // -------------------------------------------------------------------------
45 
46 
47 
48 // ----- Public method Init --------------------------------------------
50 {
51 
52  //cout << " Inside the Init function****" << endl;
53 
54  //FairDetector::Initialize();
55  //FairRun* sim = FairRun::Instance();
56  //FairRuntimeDb* rtdb=sim->GetRuntimeDb();
57 
58  // Get RootManager
59  FairRootManager* ioman = FairRootManager::Instance();
60  if ( ! ioman ) {
61  cout << "-E- PndMcListConverter::Init: "
62  << "RootManager not instantiated!" << endl;
63  return kFATAL;
64  }
65 
66 // Get input array
67  fMcTracks = (TClonesArray*) ioman->GetObject("MCTrack");
68 
69 
70  if ( !fMcTracks ) {
71  cout << "-W- PndMcListConverter::Init: "
72  << "No MCTracks array!" << endl;
73  return kERROR;
74  }
75 
76  fMcCandidates =new TClonesArray("RhoCandidate");
77  ioman->Register("PndMcTracks","PndMcTracks", fMcCandidates, kTRUE);
78 
79  // Create and register output array
80  cout << "-I- PndMcListConverter: Intialization successfull" << endl;
81 
82  return kSUCCESS;
83 
84 }
85 
87 {
88 
89  // Get run and runtime database
90  FairRun* run = FairRun::Instance();
91  if ( ! run ) { Fatal("SetParContainers", "No analysis run"); }
92 
93  //FairRuntimeDb* db = run->GetRuntimeDb();
94  //if ( ! db ) Fatal("SetParContainers", "No runtime database");
95 
96 
97 }
98 
99 // -------------------------------------------------------------------------
100 
101 // ----- Public method Exec --------------------------------------------
103 {
104 
105  if(fVerbose) { cout << "-I- Start PndMcListConverter. "<<endl; }
106  if(fVerbose) { cout <<"-I- PndMcListConverter: nMcTracks="<<fMcTracks->GetEntriesFast()<<endl; }
107 
108  // Get the Candidates
109  for(Int_t i=0; i<fMcTracks->GetEntriesFast(); i++) {
110  PndMCTrack* part = (PndMCTrack*)fMcTracks->At(i);
111  if (part->GetMotherID()!=-1) { continue; }
112 
113  TLorentzVector p4 = part->Get4Momentum();
114  TVector3 stvtx = part->GetStartVertex();
115 
116  TParticlePDG* ppdg = TDatabasePDG::Instance()->GetParticle(part->GetPdgCode());
117 
118  double charge=0.0;
119 
120  if (ppdg) { charge=ppdg->Charge(); }
121  else if (fVerbose) { cout <<"-W- PndMcListConverter: strange PDG code:"<<part->GetPdgCode()<<endl; }
122  if (fabs(charge)>2) { charge/=3.; }
123 
124  TClonesArray& ref = *fMcCandidates;
125  Int_t size = ref.GetEntriesFast();
126 
127  RhoCandidate* pmc=new (ref[size]) RhoCandidate(p4,charge);
128 
129  pmc->SetMcTruth(0);// Mc truth has no truth object....
130  pmc->SetPos(stvtx);
131  pmc->SetType(part->GetPdgCode());//mass is overwirtten internally
132  pmc->SetP4(p4);//reset to generator output
133  }
134 
135  if(fVerbose) { cout <<"-I- PndMcListConverter: found primaries="<<fMcCandidates->GetEntriesFast()<<endl; }
136 
137 }
138 // -------------------------------------------------------------------------
139 
141 {
142  fMcCandidates->Delete();
143 }
144 
int fVerbose
Definition: poormantracks.C:24
Int_t run
Definition: autocutx.C:47
void SetPos(const TVector3 &pos)
Definition: RhoCandidate.h:235
Int_t i
Definition: run_full.C:25
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
TLorentzVector Get4Momentum() const
Definition: PndMCTrack.cxx:102
TClonesArray * fMcCandidates
void SetType(const TParticlePDG *pdt)
void SetP4(Double_t mass, const TVector3 &p3)
virtual void FinishEvent()
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
void SetMcTruth(RhoCandidate *mct)
Definition: RhoCandidate.h:436
virtual void SetParContainers()
ClassImp(PndAnaContFact)
TVector3 GetStartVertex() const
Definition: PndMCTrack.h:76
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
TClonesArray * fMcTracks