EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndRecoDafFit.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndRecoDafFit.cxx
1 //-----------------------------------------------------------
2 // File and Version Information:
3 // $Id$
4 //
5 // Description:
6 // Implementation of class PndRecoDafFit
7 // see PndRecoDafFit.h for details
8 //
9 // Environment:
10 // Software developed for the PANDA Detector at FAIR.
11 //
12 // Author List:
13 // Stefano Spataro, UNI Torino
14 //
15 //-----------------------------------------------------------
16 
17 // Panda Headers ----------------------
18 
19 // This Class' Header ------------------
20 #include "PndRecoDafFit.h"
21 
22 // C/C++ Headers ----------------------
23 #include <algorithm>
24 #include <iostream>
25 #include <assert.h>
26 #include <cmath>
27 
28 // Collaborating Class Headers --------
29 #include "FairRootManager.h"
30 #include "FairRuntimeDb.h"
31 #include "FairRunAna.h"
32 #include "TClonesArray.h"
33 
34 #include "GFTrack.h"
35 //#include "TDatabasePDG.h"
36 
37 #include "PndGenfitAdapters.h"
38 #include "PndTrack.h"
39 #include "PndTrackCand.h"
40 #include "PndDetectorList.h"
41 #include "PndGeoHandling.h"
42 #include "GFRecoHitFactory.h"
43 #include "GFDaf.h"
44 #include "GFException.h"
45 #include "TLorentzVector.h"
46 
47 #include "FairTrackParH.h"
48 
49 
50 #include "GeaneTrackRep.h"
51 #include "RKTrackRep.h"
52 #include "GFFieldManager.h"
53 #include "PndGenfitField.h"
54 #include "FairGeanePro.h"
55 
56 // Class Member definitions -----------
57 
58 
59 PndRecoDafFit::PndRecoDafFit(): TNamed("Genfit", "Fit Tracks"),
60  fMvdBranchName(""), fCentralTrackerBranchName(""),
61  fUseGeane(kTRUE), fPropagateToIP(kTRUE), fPerpPlane(kFALSE), fNumIt(1), fVerbose(0), fTrackRep(0)
62 {
64 }
65 
67 {
68  //Get ROOT Manager
70  if(ioman==0)
71  {
72  Error("PndRecoDafFit::Init","RootManager not instantiated!");
73  return kFALSE;
74  }
75 
76  // STT map loading
77  //FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
78 
79  // Build hit factory -----------------------------
81  if (fVerbose<2) GFException::quiet(true);
82 
83  if (fUseGeane)
84  {
85  fPro = new FairGeanePro();
86  }
87  else
88  {
89  Error("PndRecoDafFit::Init","Only GEANE Propagatio available!!!");
90  return kFALSE;
91  }
92 
93  //fGenFitter.setNumIterations(fNumIt);
95 
96  std::cout << "===PndRecoDafFit::Init() finished ===================================================" << std::endl;
97 
98  return kTRUE;
99 }
100 
101 
103 
104 PndTrack* PndRecoDafFit::Fit(PndTrack *tBefore, Int_t PDG)
105 {
106  PndTrack* tAfter = NULL;
107  if (fVerbose>0) std::cout<<"PndRecoDafFit::Fit"<<std::endl;
108  if (fabs(tBefore->GetParamFirst().GetPz())<1e-9)
109  {
110  tAfter = tBefore;
111  tAfter->SetFlag(-10);
112  return tAfter; // flag -10 : pz==0
113  }
114 
115  Int_t fCharge= tBefore->GetParamFirst().GetQ();
116  Int_t PDGCode= PDG;
117  TVector3 StartPos(tBefore->GetParamFirst().GetX(),tBefore->GetParamFirst().GetY(),tBefore->GetParamFirst().GetZ());
118  TVector3 StartMom(tBefore->GetParamFirst().GetPx(),tBefore->GetParamFirst().GetPy(),tBefore->GetParamFirst().GetPz());
119  TVector3 StartPosErr(tBefore->GetParamFirst().GetDX(),tBefore->GetParamFirst().GetDY(),tBefore->GetParamFirst().GetDZ());
120  TVector3 StartMomErr(tBefore->GetParamFirst().GetDPx(),tBefore->GetParamFirst().GetDPy(),tBefore->GetParamFirst().GetDPz());
121 
122  GFAbsTrackRep* rep = 0;
123 
124  if (fPropagateToIP)
125  {
126  // Calculating params at PCA to Origin
127  FairTrackParP par = tBefore->GetParamFirst();
128  Int_t ierr = 0;
129  FairTrackParH *helix = new FairTrackParH(&par, ierr);
130  FairGeanePro *fPro0 = new FairGeanePro();
131  FairTrackParH *fRes= new FairTrackParH();
132  fPro0->SetPoint(TVector3(0,0,0));
133  fPro0->PropagateToPCA(1, -1);
134  Bool_t rc = fPro0->Propagate(helix, fRes, PDGCode);
135  if (rc)
136  {
137  StartPos.SetXYZ(fRes->GetX(), fRes->GetY(), fRes->GetZ());
138  StartMom.SetXYZ(fRes->GetPx(), fRes->GetPy(), fRes->GetPz());
139  StartPosErr.SetXYZ(fRes->GetDX(), fRes->GetDY(), fRes->GetDZ());
140  StartMomErr.SetXYZ(fRes->GetDPx(), fRes->GetDPy(), fRes->GetDPz());
141  }
142  }
143 
144  TVector3 plane_v1, plane_v2;
145  if (fPerpPlane)
146  {
147  plane_v1 = StartMom.Orthogonal();
148  plane_v2 = StartPos.Cross(plane_v1);
149  }
150  else
151  {
152  plane_v1.SetXYZ(1.,0.,0.);
153  plane_v2.SetXYZ(0.,1.,0.);
154  }
155  GFDetPlane start_pl(StartPos, plane_v1, plane_v2);
156  GFTrack* trk;
157  if (fTrackRep==0)
158  {
159  GeaneTrackRep *grep = new GeaneTrackRep(fPro,
160  start_pl,StartMom,
161  StartPosErr,StartMomErr,
162  fCharge,PDGCode);
163  grep->setPropDir(1);
164  rep = grep;
165  }
166  else if (fTrackRep==1)
167  {
168  RKTrackRep *grep = new RKTrackRep(StartPos, StartMom,
169  StartPosErr, StartMomErr,
170  PDGCode);
171  rep = grep;
172  }
173  else
174  {
175  std::cout << "*** PndRecoDafFit::Exec" << "\t" << "Not existing Track Representation " << fTrackRep << std::endl;
176  return NULL; // any smarted ideas?
177  }
178 
179  trk= new GFTrack(rep);
180 
181  PndTrackCand trackCand = tBefore->GetTrackCand();
182  trk->setCandidate(*PndTrackCand2GenfitTrackCand(&trackCand));
183 
184  // Load RecoHits
185  try
186  {
188  if (fVerbose>0) std::cout<<trk->getNumHits()<<" hits in track " << std::endl;
189  }
190  catch(GFException& e)
191  {
192  std::cout << "*** PndRecoDafFit::Exec" << "\t" << "Genfit Exception: trk->addHitVector " << e.what() << std::endl;
193  //throw e;
194  }
195  // Start Fitter
196  try
197  {
199  }
200  catch (GFException& e)
201  {
202  std::cout<<"*** FITTER EXCEPTION ***"<<std::endl;
203  std::cout<<e.what()<<std::endl;
204  }
205 
206  if (fVerbose>0) std::cout<<"SUCCESSFULL FIT!"<<std::endl;
207 
208  try
209  {
210  tAfter = (PndTrack*)GenfitTrack2PndTrack(trk);
211  }
212  catch (GFException e)
213  {
214  std::cout<<"*** PndGenfitAdapters EXCEPTION ***"<<std::endl;
215  std::cout<<e.what()<<std::endl;
216  tAfter = tBefore;
217  tAfter->SetFlag(-2); // flag -2: conversion failed
218  }
219 
220  if (fVerbose>0) std::cout<<"Fitting done"<<std::endl;
221 
222  return tAfter;
223 }
224