FairRoot/PandaRoot
PndHypIdealTrackFinderTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndHypIdealTrackFinderTask source file -----
3 // -------------------------------------------------------------------------
4 
5 
6 #include "TClonesArray.h"
7 #include "TArrayD.h"
8 #include "TGeoManager.h"
9 
10 #include "FairRootManager.h"
11 #include "FairRunAna.h"
12 #include "FairRuntimeDb.h"
13 
15 #include "PndHypDigiStrip.h"
16 //#include "PndHypDigiPixel.h"
17 //nclude "PndHypPixelCluster.h"
18 
19 
20 // ----- Default constructor -------------------------------------------
22  FairTask("HYP Ideal Track Finding Task")
23 {
24  fHitBranchStrip = "HypHit";
25  //fHitBranchPixel = "MVDHitsPixel";
26  /* fClusterBranchStrip = "MVDStripClusterCand";
27  //fClusterBranchPixel = "MVDClusterCand";
28  fDigiBranchStrip = "MVDStripDigis";
29  //fDigiBranchPixel = "MVDPixelDigis";*/
30 
31  fMcBranch = "HypPoint";
32  fTrackBranch = "MCTrack";
33 }
34 
35 
36 // -------------------------------------------------------------------------
37 
38 
39 // ----- Destructor ----------------------------------------------------
41 {
42 }
43 // -------------------------------------------------------------------------
44 
45 // ----- Initialization of Parameter Containers -------------------------
47 {
48  // Get Base Container
49 /*
50  FairRunAna* ana = FairRunAna::Instance();
51  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
52  fGeoPar = (PndHypGeoPar*)(rtdb->getContainer("PndHypGeoPar"));
53 */
54 }
55 
57 {
58 
59  InitStatus stat=kERROR;
60  return stat;
61 
62  /*
63  FairRunAna* ana = FairRunAna::Instance();
64  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
65  fGeoPar=(PndHypGeoPar*)(rtdb->getContainer("PndHypGeoPar"));
66 
67  return kSUCCESS;
68  */
69 }
70 
71 // ----- Public method Init --------------------------------------------
73 {
74 
75  FairRootManager* ioman = FairRootManager::Instance();
76 
77  if ( ! ioman )
78  {
79  std::cout << "-E- PndHypIdealTrackFinderTask::Init: "
80  << "RootManager not instantiated!" << std::endl;
81  return kFATAL;
82  }
83 
84 
85 // Get input array
86  fStripHitArray = (TClonesArray*) ioman->GetObject(fHitBranchStrip);
87  if ( !fStripHitArray){
88  std::cout << "-W- PndHypIdealTrackFinderTask::Init: " << "No hitArray!" << std::endl;
89  return kERROR;
90  }
91 
92  /* fStripClusterArray = (TClonesArray*) ioman->GetObject(fClusterBranchStrip);
93  if ( !fStripClusterArray){
94  std::cout << "-W- PndHypIdealTrackFinderTask::Init: " << "No clusterArray!" << std::endl;
95  return kERROR;
96  }
97 
98  fStripDigiArray = (TClonesArray*) ioman->GetObject(fDigiBranchStrip);
99  if ( !fStripDigiArray){
100  std::cout << "-W- PndHypIdealTrackFinderTask::Init: " << "No digiArray!" << std::endl;
101  return kERROR;
102  }
103 
104 */
105  fMcArray = (TClonesArray*) ioman->GetObject(fMcBranch);
106  if ( !fMcArray){
107  std::cout << "-W- PndHypIdealTrackFinderTask::Init: " << "No mcArray!" << std::endl;
108  return kERROR;
109  }
110 
111  fTrackArray = (TClonesArray*) ioman->GetObject(fTrackBranch);
112  if ( !fTrackArray){
113  std::cout << "-W- PndHypIdealTrackFinderTask::Init: " << "No trackArray!" << std::endl;
114  return kERROR;
115  }
116 
117 
118 
119  fTrackCandArray = new TClonesArray("GFTrackCand");
120  ioman->Register("HypTrackCand", "HYP", fTrackCandArray, kTRUE);
121 
122  std::cout << "-I- PndHypIdealTrackFinderTask: Initialisation successfull" << std::endl;
123  return kSUCCESS;
124 }
125 // -------------------------------------------------------------------------
126 
127 
128 
129 // ----- Public method Exec --------------------------------------------
131 {
132 // Reset output array
133  if ( ! fTrackCandArray )
134  Fatal("Exec", "No trackCandArray");
135  fTrackCandArray->Delete();
136 
137  Int_t
138  nStripHits = fStripHitArray->GetEntriesFast();
139 
140  for (Int_t iHit = 0; iHit < nStripHits; iHit++){
141  PndHypHit* myHit = (PndHypHit*)(fStripHitArray->At(iHit));
142 
143  /*PndHypCluster* myCluster =(PndHypCluster*)(fStripClusterArray->At(myHit->GetRefIndex()));
144  PndHypDigiStrip* astripdigi = (PndHypDigiStrip*)fStripDigiArray->At(myCluster->GetDigiIndex(0));*/
145 
146  PndHypPoint* myPoint = (PndHypPoint*)(fMcArray->At(myHit->GetRefIndex()));
147 
148  AddAndExpand(myPoint->GetTrackID(),2,iHit);
149  }
150 
151 
152  if(fVerbose>0) PrintResult();
153 
154  Int_t i = 0;
155  for (std::map<Int_t,GFTrackCand*>::const_iterator ci=fTrackCandMap.begin();
156  ci != fTrackCandMap.end(); ci++){
157  new((*fTrackCandArray)[i]) GFTrackCand(*(ci->second));
158  i++;
159  }
161  fMcArray->Delete();
162  fTrackArray->Delete();
163 
164 }
165 
166 
167 void PndHypIdealTrackFinderTask::AddAndExpand(Int_t trackID, Int_t detnum, Int_t iHit){
168  if (fTrackCandMap[trackID] == 0){
169  GFTrackCand *myTCand = new GFTrackCand();
170  PndMCTrack* myMCTrack = (PndMCTrack*)fTrackArray->At(trackID);
171  myTCand->setCurv(GetTrackCurvature(myMCTrack));
172  myTCand->setDip(GetTrackDip(myMCTrack));
173  myTCand->setInverted(false);
174  //myTCand->setMCID(trackID);
175  fTrackCandMap[trackID] = myTCand;
176  }
177  fTrackCandMap[trackID]->addHit(detnum,iHit);
178 }
179 
180 
182 {
183  TVector3 p = myTrack->GetMomentum();
184  return (2/TMath::Sqrt(p.Px()*p.Px() + p.Py()*p.Py()));
185 }
186 
188 {
189  TVector3 p= myTrack->GetMomentum();
190  return (p.Mag()/TMath::Sqrt(p.Px()*p.Px() + p.Py()*p.Py()));
191 }
192 
194 {
195  std::cout << "**** TrackFinding *****" << std::endl;
196  Int_t nStripHits = fStripHitArray->GetEntriesFast();
197  for (std::map<Int_t, GFTrackCand*>::const_iterator ci=fTrackCandMap.begin();
198  ci != fTrackCandMap.end(); ci++){
199  std::cout << "TrackID: " << ci->first << std::endl;
200  GFTrackCand* trackCand = ci->second;
201  for (unsigned int i = 0; i < trackCand->getNHits(); i++){
202  unsigned int detId, hitId;
203  trackCand->getHit(i, detId, hitId);
204  PndHypHit* myHit;
205  myHit = (PndHypHit*)fStripHitArray->At(hitId);
206  std::cout << "Detector no. " << detId <<": "<< *myHit;
207  }
208  }
209  std::cout << std::endl;
210 }
211 
213 {
214  for (std::map<Int_t,GFTrackCand*>::const_iterator ci=fTrackCandMap.begin();
215  ci != fTrackCandMap.end(); ci++){
216  delete(ci->second);
217  }
218  fTrackCandMap.clear();
219 }
221 
Double_t p
Definition: anasim.C:58
Int_t i
Definition: run_full.C:25
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
unsigned int getNHits() const
Definition: GFTrackCand.h:113
virtual void Exec(Option_t *opt)
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
void setDip(double d)
Definition: GFTrackCand.h:145
Double_t
void getHit(unsigned int i, unsigned int &detId, unsigned int &hitId) const
Get detector ID and cluster index (hitId) for hit number i.
Definition: GFTrackCand.h:84
void AddAndExpand(Int_t trackID, Int_t detnum, Int_t iHit)
void setInverted(bool f=true)
Definition: GFTrackCand.h:146
Track candidate – a list of cluster indices.
Definition: GFTrackCand.h:55
void setCurv(double c)
Definition: GFTrackCand.h:144
ClassImp(PndAnaContFact)
Double_t GetTrackCurvature(PndMCTrack *myTrack)
std::map< Int_t, GFTrackCand * > fTrackCandMap
Double_t GetTrackDip(PndMCTrack *myTrack)