EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndRecoKalmanTask.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndRecoKalmanTask.cxx
1 //-----------------------------------------------------------
2 // File and Version Information:
3 // $Id$
4 //
5 // Description:
6 // Implementation of class PndRecoKalmanTask
7 // see PndRecoKalmanTask.hh for details
8 //
9 // Environment:
10 // Software developed for the PANDA Detector at FAIR.
11 //
12 // Author List:
13 // Sebastian Neubert TUM (original author)
14 // Stefano Spataro, UNI Torino
15 //
16 //-----------------------------------------------------------
17 
18 // Panda Headers ----------------------
19 
20 // This Class' Header ------------------
21 #include "PndRecoKalmanTask.h"
22 
23 // C/C++ Headers ----------------------
24 #include <iostream>
25 #include <cmath>
26 
27 // Collaborating Class Headers --------
28 #include "TClonesArray.h"
29 #include "TParticlePDG.h"
30 #include "PndTrack.h"
31 #include "PndTrackID.h"
32 #include "PndMCTrack.h"
33 #include "FairRootManager.h"
34 #include "FairGeanePro.h"
35 #include "FairRunAna.h"
36 #include "FairRuntimeDb.h"
37 
38 PndRecoKalmanTask::PndRecoKalmanTask(const char* name, Int_t iVerbose)
39 : FairTask(name, iVerbose), fTrackInBranchName(""), fTrackInIDBranchName(""),
40 fTrackOutBranchName(""), fMvdBranchName(""), fCentralTrackerBranchName(""),
41 fFitTrackArray(), fFitter(), fDafFitter(), fPDGHyp(-13),
42 fUseGeane(kTRUE), fIdealHyp(kFALSE), fDaf(kFALSE), fPersistence(kTRUE),
43 fPropagateToIP(kTRUE), fPerpPlane(kFALSE),
44  fNumIt(1), fBusyCut(20), fTrackRep(0), mStoreTrackParameterization(false)
45 {
46  fFitTrackArray = new TClonesArray("PndTrack");
47  fFitter = new PndRecoKalmanFit();
48  fDafFitter = new PndRecoDafFit();
49 }
50 
51 
53 {
54 }
55 
58 {
59 
60  switch (fTrackRep)
61  {
62  case 0:
63  std::cout << " -I- PndRecoKalmanTask:Init :: Using GeaneTrackRep" << std::endl;
64  break;
65  case 1:
66  std::cout << " -I- PndRecoKalmanTask:Init :: Using RKTrackRep" << std::endl;
67  break;
68  default:
69  Error("PndRecoKalmanTask::Init","Not existing Track Representation!!");
70  return kERROR;
71  }
72 
73  if (!fDaf)
74  {
83  if (!fFitter->Init()) return kFATAL;
84  }
85  else
86  {
94  if (!fDafFitter->Init()) return kFATAL;
95  }
96 
97  //Get ROOT Manager
99 
100  if(ioman==0)
101  {
102  Error("PndRecoKalmanTask::Init","RootManager not instantiated!");
103  return kERROR;
104  }
105 
106  // Get input collection
107  fTrackArray=(TClonesArray*) ioman->GetObject(fTrackInBranchName);
108  if(fTrackArray==0)
109  {
110  Error("PndRecoKalmanTask::Init","track-array not found!");
111  return kERROR;
112  }
113  if (fIdealHyp)
114  {
115  pdg = new TDatabasePDG();
116  fTrackIDArray=(TClonesArray*) ioman->GetObject(fTrackInIDBranchName);
117  if(fTrackIDArray==0)
118  {
119  Error("PndRecoKalmanTask::Init","track ID array not found! It is not possible to run ideal particle hypothesis");
120  return kERROR;
121  }
122 
123  fMCTrackArray=(TClonesArray*) ioman->GetObject("MCTrack");
124  if(fMCTrackArray==0)
125  {
126  Error("PndRecoKalmanTask::Init","MCTrack array not found! It is not possible to run ideal particle hypothesis");
127  return kERROR;
128  }
129  }
130 
132 
133  return kSUCCESS;
134 }
135 
138 #if _EIC_OFF_
139  rtdb->getContainer("PndGeoSttPar");
140  rtdb->getContainer("PndGeoFtsPar");
141 #endif
142 }
143 
144 void PndRecoKalmanTask::Exec(Option_t* opt)
145 {
146  if (fVerbose>0) std::cout<<"PndRecoKalmanTask::Exec"<<std::endl;
147 
148  fFitTrackArray->Delete();
149 
150  Int_t ntracks=fTrackArray->GetEntriesFast();
151 
152  // Detailed output
153  if (fVerbose>1) std::cout << " -I- PndRecoKalmanTask: contains " << ntracks << " Tracks."<< std::endl;
154 
155  // Cut too busy events TODO
156  if(ntracks>fBusyCut)
157  {
158  std::cout<<" -I- PndRecoKalmanTask::Exec: ntracks=" << ntracks << " Evil Event! skipping" << std::endl;
159  return;
160  }
161 
162 
163  for(Int_t itr=0;itr<ntracks;++itr)
164  {
165  if (fVerbose>1) std::cout<<"starting track"<<itr<<std::endl;
166 
167  TClonesArray& trkRef = *fFitTrackArray;
168  Int_t size = trkRef.GetEntriesFast();
169 
170  PndTrack *prefitTrack = (PndTrack*)fTrackArray->At(itr);
171  Int_t fCharge= prefitTrack->GetParamFirst().GetQ();
172  Int_t PDGCode = 0;
173  if (fIdealHyp)
174  {
175  PndTrackID *prefitTrackID = (PndTrackID*)fTrackIDArray->At(itr);
176  if (prefitTrackID->GetNCorrTrackId()>0)
177  {
178  Int_t mcTrackId = prefitTrackID->GetCorrTrackID();
179  if (mcTrackId!=-1)
180  {
181  PndMCTrack *mcTrack = (PndMCTrack*)fMCTrackArray->At(mcTrackId);
182  if (!mcTrack)
183  {
184  PDGCode = 211*fCharge;
185  std::cout << "-I- PndRecoKalmanTask::Exec: MCTrack #" << mcTrackId << " is not existing!! Trying with pion hyp" << std::endl;
186  }
187  else
188  {
189  PDGCode = mcTrack->GetPdgCode();
190  }
191  if (PDGCode>=100000000)
192  {
193  PDGCode = 211*fCharge;
194  std::cout << "-I- PndRecoKalmanTask::Exec: Track is an ion (PDGCode>100000000)! Trying with pion hyp" << std::endl;
195  }
196  else if ((((TParticlePDG*)pdg->GetParticle(PDGCode))->Charge())==0)
197  {
198  PDGCode = 211*fCharge;
199  std::cout << "-E- PndRecoKalmanTask::Exec: Track MC charge is 0!!!! Trying with pion hyp" << std::endl;
200  }
201  } // end of MCTrack ID != -1
202  else
203  {
204  PDGCode = 211*fCharge;
205  std::cout << "-E- PndRecoKalmanTask::Exec: No MCTrack index in PndTrackID!! Trying with pion hyp" << std::endl;
206  }
207  } // end of "at least one correlated mc index"
208  else
209  {
210  PDGCode = 211*fCharge;
211  std::cout << "-E- PndRecoKalmanTask::Exec: No Correlated MCTrack id in PndTrackID!! Trying with pion hyp" << std::endl;
212  }
213  } // end of ideal hyp condition
214  else
215  {
216  PDGCode = fPDGHyp*fCharge;
217  }
218 
219  PndTrack *fitTrack = new PndTrack();
220  if (PDGCode!=0)
221  {
222  if (fDaf) fitTrack = fDafFitter->Fit(prefitTrack, PDGCode);
223  else fitTrack = fFitter->Fit(prefitTrack, PDGCode, mStoreTrackParameterization);
224 
225 #if _OFF_
226  {
227  for(unsigned iq=0; iq<fitTrack->mSmoothedValues.size(); iq++) {
228  TVector3 &pos = fitTrack->mSmoothedValues[iq].first;
229  TVector3 &mom = fitTrack->mSmoothedValues[iq].second;
230 
231  printf("%10.4f %10.4f %10.4f -> %10.4f %10.4f %10.4f\n",
232  pos.X(), pos.Y(), pos.Z(), mom.X(), mom.Y(), mom.Z());
233  } //for iq
234  }
235 #endif
236  }
237  else
238  {
239  fitTrack = prefitTrack;
240  fitTrack->SetFlag(22);
241  std::cout << "-I- PndRecoKalmanTask::Exec: Kalman cannot run on this track because of the bad MonteCarlo PDC code" << std::endl;
242  }
243 
244  PndTrack* pndTrack = new(trkRef[size]) PndTrack(fitTrack->GetParamFirst(), fitTrack->GetParamLast(), fitTrack->GetTrackCand(),
245  fitTrack->GetFlag(), fitTrack->GetChi2(), fitTrack->GetNDF(), fitTrack->GetPidHypo(), itr, FairRootManager::Instance()->GetBranchId(fTrackInBranchName));
246 
247  // Yes, copy over by hand, sorry;
248  pndTrack->mParameterizations = fitTrack->mParameterizations;
249  }
250 
251  if (fVerbose>0) std::cout<<"Fitting done"<<std::endl;
252 
253  return;
254 }
255 
257 {
258  // Set the hypothesis for the fit, charge will be applied later
259  if(h.BeginsWith("e") || h.BeginsWith("E")){
260  fPDGHyp=-11; //electrons
261  }else if(h.BeginsWith("m") || h.BeginsWith("M")){
262  fPDGHyp=-13; //muons
263  }else if(h.BeginsWith("pi") || h.BeginsWith("Pi") || h.BeginsWith("PI")){
264  fPDGHyp=211; //pions
265  }else if(h.BeginsWith("K") || h.BeginsWith("K")){
266  fPDGHyp=321; //kaons
267  }else if(h.BeginsWith("p") || h.BeginsWith("P") || h.BeginsWith("antip")){
268  fPDGHyp=2212; //protons/antiprotons
269  }else{
270  std::cout << "-I- PndRecoKalmanTask::SetParticleHypo: Not recognised PID set -> Using default MUON hypothesis" << std::endl;
271  fPDGHyp=-13; // Muon is default.
272  }
273 }
274 
276 {
277  switch (abs(h))
278  {
279  case 11:
280  fPDGHyp = -11;
281  break;
282  case 13:
283  fPDGHyp = -13;
284  break;
285  case 211:
286  fPDGHyp = 211;
287  break;
288  case 321:
289  fPDGHyp = 321;
290  break;
291  case 2212:
292  fPDGHyp = 2212;
293  break;
294  default:
295  std::cout << "-I- PndRecoKalmanTask::SetParticleHypo: Not recognised PID set -> Using default MUON hypothesis" << std::endl;
296  fPDGHyp = -13;
297  break;
298  }
299 }