FairRoot/PandaRoot
PndHypIdealTrackingTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndMvdIdealTrackingTask source file -----
3 // ----- Created 20/03/07 by R.Kliemt -----
4 // -------------------------------------------------------------------------
5 // libc includes
6 #include <iostream>
7 
8 // Root includes
9 #include "TROOT.h"
10 #include "TString.h"
11 #include "TClonesArray.h"
12 #include "TParticlePDG.h"
13 
14 // framework includes
15 #include "FairRootManager.h"
17 #include "FairRunAna.h"
18 #include "FairRuntimeDb.h"
19 #include "PndMCTrack.h"
20 
21 
22 // PndHyp includes
23 #include "PndHypRecoHit.h"
24 // #include "PndHypGFTrackCand.h"
25 #include "../../genfit/GFTrack.h"
26 #include "../../genfit/GFTrackCand.h"
27 #include "PndHypHit.h"
28 #include "PndHypPoint.h"
29 #include "PndHypCluster.h"
30 #include "PndHypDigi.h"
31 
32 // ----- Default constructor -------------------------------------------
34 FairTask("Digitization task for PANDA PndHyp")
35 {
36  //fBranchName = "HYPStripClusterHit";
37  fBranchName = "";
38 }
39 // -------------------------------------------------------------------------
40 
41 
42 
43 // ----- Destructor ----------------------------------------------------
45 {
46 }
47 
48 // ----- Public method Init --------------------------------------------
50 {
51  // Get RootManager
52  FairRootManager* ioman = FairRootManager::Instance();
53  if ( ! ioman ) {
54  std::cout << "-E- PndHypIdealTrackingTask::Init: "<< "RootManager not instantiated!" << std::endl;
55  return kFATAL; }
56 
57  // Get input array
58  fHitArray = (TClonesArray*) ioman->GetObject("HYPHit");
59  if ( ! fHitArray ) {
60  std::cout << "-W- PndHypIdealTrackingTask::Init: "<< "No fHitarray!" << std::endl;
61  return kERROR; }
62 
63  fClusterStripArray = (TClonesArray*) ioman->GetObject("HYPStripClusterCand");
64  if ( ! fClusterStripArray ) {
65  std::cout << "-W- PndMvdIdealTrackingTask::Init: "<< "No fClusterStripArray!" << std::endl;
66  return kERROR; }
67 
68  fDigiStripArray = (TClonesArray*) ioman->GetObject("HypStripDigis");
69  if ( ! fDigiStripArray ) {
70  std::cout << "-W- PndMvdIdealTrackingTask::Init: "<< "No fDigiStripArray array!" << std::endl;
71  return kERROR; }
72 
73  fPointArray = (TClonesArray*) ioman->GetObject("HypPoint");
74  if ( ! fPointArray )
75  {
76  std::cout << "-W- PndHypStripHitProducer::Init: "
77  << "No MVDPoint array!" << std::endl;
78  return kERROR;
79  }
80 
81  // Get MCTruth collection
82  fMctruthArray=(TClonesArray*) ioman->GetObject("MCTrack");
83  if(fMctruthArray==0) {
84  std::cout << "-W- PndHypIdealTrackingTask::Init: "<< "No McTruth array!" << std::endl;
85  return kERROR; }
86 
87  // Create and register output array
88  fTrackOutputArray = new TClonesArray("GFTrackCand");
89  ioman->Register("HypTrackCand", "PndHyp ideal tracklets", fTrackOutputArray, kTRUE);
90 
91 
92  return kSUCCESS;
93 }
94 // -------------------------------------------------------------------------
96 {
97  // Get Base Container
98  FairRunAna* ana = FairRunAna::Instance();
99  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
100 
101 }
102 
103 
104 // ----- Public method Exec --------------------------------------------
106 {
107  if ( ! fTrackOutputArray ) Fatal("Exec", "No fTrackOutputArray");
108  fTrackOutputArray->Delete();
109 
110  // CREATE MONTECARLO MAP
111  std::map<Int_t, PndMCTrack*> mcmap;
112  Int_t nmc=fMctruthArray->GetEntriesFast();
113  for(Int_t imc=0;imc<nmc;++imc){
114  PndMCTrack* mc=(PndMCTrack*)fMctruthArray->At(imc);
115  mcmap[imc]=mc;
116  //if(mc->GetPdgCode()>100)cout<<imc<<" "<<mc->GetPdgCode()<<endl;
117 
118  }
119 
120  // BUILD TRACK Candidates
121  std::map<Int_t, GFTrackCand*> trackMap;
122 
123  Int_t nPndHypHits=fHitArray->GetEntriesFast();
124  cout<<nPndHypHits<<endl;
125 
126 
127  for(Int_t iHit=0;iHit<nPndHypHits;++iHit)
128  {
129  PndHypHit* hit=(PndHypHit*)fHitArray->At(iHit);
130  Int_t clustid=hit->GetRefIndex();
131  Int_t digiid,pointid,MCid;
132 
133 
134  if(hit->GetBotIndex()>0)
135  {
136  digiid=((PndHypCluster*)fClusterStripArray->At(clustid))->GetDigiIndex(0);
137  pointid=((PndHypDigi*)fDigiStripArray->At(digiid))->GetIndex();
138  }
139 
140  //cout<<iHit<<" "<<pointid<<" "<<fPointArray->GetEntriesFast()<<endl;
141 
142 
143  //if(pointid >fPointArray->GetEntriesFast())continue;
144 
145 
146  PndHypPoint* point = (PndHypPoint*)fPointArray->At(pointid);
147  MCid = point->GetTrackID();
148 
149  //if(point)cout<<point->GetVolumeID()<<endl;
150 
151  // cut on secondaries (deltas) etc
152  if(MCid<0)continue;
153 
154  cout<<MCid<<endl;
155  TVector3 pos;
156  hit->Position(pos);
157 
158  // build tracks here:
159 
160  // check if track already candidated:
161  if(trackMap[MCid]==0)
162  {Int_t size = fTrackOutputArray->GetEntriesFast();
163  //caution this should be an intrinsic assignment, so trackMap and
164  //fTrackOutputArray contain the same pointers.
165  trackMap[MCid]=new ((*fTrackOutputArray)[size]) GFTrackCand();
166 
167  Int_t pdgcode;
168  if( mcmap[MCid]==0)continue;
169 
170  pdgcode = mcmap[MCid]->GetPdgCode();
171  cout<<pdgcode<<endl;
172 
173  TParticlePDG pdgpart(pdgcode);
174  Int_t mcCharge = (Int_t)pdgpart.Charge();
175 
176  TVector3 vtx = mcmap[MCid]->GetStartVertex();
177  TVector3 mom = mcmap[MCid]->GetMomentum();
178 
179 
180  Double_t invp = 1 / mom.Mag();
181  Double_t dxdz = invp*mom.x()*mom.z();
182  Double_t dydz = invp*mom.y()*mom.z();
183  Double_t sigx = 0.01, sigy = 0.01, sigdxdz = 0.01, sigdydz = 0.01, siginvp = 0.01;
184 
185  sigx*=vtx.x();
186  sigy*=vtx.y();
187  sigdxdz*=dxdz;
188  sigdydz*=dydz;
189  siginvp*=invp;
190 
191  if(fVerbose>1) std::cout<<"PndHypIdealTrackingTask::Exec(), Particle Info: "
192  <<pdgpart.GetName()<<" ("<<pdgcode<<") Q="<<mcCharge<<std::endl;
193 
194  trackMap[MCid]->setCurv(GetTrackCurvature(mcmap[MCid]));
195  trackMap[MCid]->setDip(GetTrackDip(mcmap[MCid]));
196  trackMap[MCid]->setInverted(false);
197 
198 
199 
200  }
201 
202  // add the hit index
203  // trackMap[MCid]->addHit(,hit->GetDetectorID(),iHit);
204  // PndHypRecoHit arecohit(hit);
205 
207  trackMap[MCid]->addHit(3,iHit);
208  cout<<iHit<<endl;
209 
210 
211 
212  }//end for hit
213 
214 
215  std::cout<<fTrackOutputArray->GetEntriesFast()
216  <<" Tracks created"<<std::endl;
217 
218 
219 
220 
221 }
222 
224 {
225  TVector3 p = myTrack->GetMomentum();
226  return (2/TMath::Sqrt(p.Px()*p.Px() + p.Py()*p.Py()));
227 }
228 
230 {
231  TVector3 p= myTrack->GetMomentum();
232  return (p.Mag()/TMath::Sqrt(p.Px()*p.Px() + p.Py()*p.Py()));
233 }
234 
235 // -------------------------------------------------------------------------
236 
237 
TVector3 pos
Double_t p
Definition: anasim.C:58
int fVerbose
Definition: poormantracks.C:24
Class to store the Digis which belong to one cluster This class holds the information which Digi belo...
Definition: PndHypCluster.h:18
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
Double_t mom
Definition: plot_dirc.C:14
virtual void Exec(Option_t *opt)
Double_t
Int_t GetBotIndex() const
Definition: PndHypHit.h:88
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
Track candidate – a list of cluster indices.
Definition: GFTrackCand.h:55
Double_t GetTrackDip(PndMCTrack *myTrack)
ClassImp(PndAnaContFact)
PndSdsMCPoint * hit
Definition: anasim.C:70
Base class for Digi information.
Definition: PndHypDigi.h:23
Double_t GetTrackCurvature(PndMCTrack *myTrack)
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72