EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndGenfitAdapters.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndGenfitAdapters.cxx
1 #include"PndGenfitAdapters.h"
2 
3 #include <iostream>
4 
5 #include"GFTrack.h"
6 #include"GFAbsTrackRep.h"
7 #include"GFTrackCand.h"
8 #include"PndTrack.h"
9 #include"PndTrackCand.h"
10 #include"GFDetPlane.h"
11 #include"GFException.h"
12 #include"TMatrixT.h"
13 #include"FairTrackParP.h"
14 
15 #include"GeaneTrackRep.h"
16 #include"RKTrackRep.h"
17 #include <cmath>
18 
20  PndTrackCand* retVal = new PndTrackCand();
21  unsigned int nhits = cand->getNHits();
22  unsigned detId,hitId;
23  double rho;
24  for(unsigned int i=0;i<nhits;++i){
25  cand->getHit(i,detId,hitId,rho);
26  retVal->AddHit(detId,hitId,rho);
27  }
28  retVal->setMcTrackId(cand->getMcTrackId());
29  //retVal->setTrackSeed(cand->getPosSeed(),
30  // cand->getDirSeed(),
31  // cand->getQoverPseed());
32  retVal->setTrackSeed(cand->getPosSeed(),
33  cand->getMomSeed(),
34  cand->getChargeSeed());
35 
36  return retVal;
37 }
38 
39 
41  GFTrackCand* retVal = new GFTrackCand();
42  unsigned int nhits = cand->GetNHits();
43  for(unsigned int i=0;i<nhits;++i){
44  PndTrackCandHit candHit = cand->GetSortedHit(i);
45  retVal->addHit(candHit.GetDetId(),candHit.GetHitId(),candHit.GetRho(),i);
46  }
47  retVal->setMcTrackId(cand->getMcTrackId());
48  //retVal->setTrackSeed(cand->getPosSeed(),
49  // cand->getDirSeed(),
50  // cand->getQoverPseed());
51  retVal->setPosMomSeed(cand->getPosSeed(),
52  cand->getMomSeed(),
53  cand->getChargeSeed());
54 #if 0
55  // Poor man's choice; do better later; for +/-1 charge should work fine;
56  {
57  //printf("%f\n", cand->getQoverPseed()); exit(0);
58  // Be dumb; regularize in whatever way does not cause core dump;
59  double mom = fabs(cand->getQoverPseed()) ? 1./fabs(cand->getQoverPseed()) : 1E6;
60  TVector3 pseed = mom * cand->getDirSeed();
61 
62  retVal->setPosMomSeed(cand->getPosSeed(), pseed, cand->getQoverPseed() >= 0 ? 1. : -1.);
63  }
64 #endif
65 
66  return retVal;
67 }
68 
70  GFAbsTrackRep* clone = tr->getCardinalRep()->clone();
71  TMatrixT<double> firstState = clone->getFirstState();
72  TMatrixT<double> lastState = clone->getLastState();
73  TMatrixT<double> firstCov = clone->getFirstCov();
74  TMatrixT<double> lastCov = clone->getLastCov();
75  GFDetPlane firstPlane = clone->getFirstPlane();
76  GFDetPlane lastPlane = clone->getLastPlane();
77 
78  GFAbsTrackRep* gtr;
79  if (dynamic_cast<GeaneTrackRep*>(clone)!=NULL)
80  gtr = dynamic_cast<GeaneTrackRep*>(clone);
81  else if (dynamic_cast<RKTrackRep*>(clone)!=NULL)
82  gtr = dynamic_cast<RKTrackRep*>(clone);
83  else {
84  std::cerr << " GenfitGFAbsTrackRep2PndTrack() can currently only handle GeaneTrackRep and RKTrackRep" << std::endl;
85  throw;
86  }
87 
88  //make the FairTrackParP for first and last hit
89  double firstCova[15];
90  int count=0;;
91  for(int i=0; i<5;++i){
92  for(int j=i;j<5;++j){
93  firstCova[count++]=firstCov[i][j];
94  }
95  }
96  double lastCova[15];
97  count=0;;
98  for(int i=0; i<5;++i){
99  for(int j=i;j<5;++j){
100  lastCova[count++]=lastCov[i][j];
101  }
102  }
103 
104  // calculation of spu = sign[p(DJ x DK)]
105  double first_pro(0), last_pro(0), first_spu, last_spu;
106  bool exc(false);
107 
108  try{
109  first_pro = gtr->getMom(firstPlane).Dot(firstPlane.getNormal());
110  last_pro = gtr->getMom(lastPlane).Dot(lastPlane.getNormal());
111  }
112  catch (GFException& e){
113  exc=true;
114  std::cerr<<"could not convert GenfitTrack to PndTrack"<<std::endl;
115  e.what();
116  }
117 
118  first_spu = (first_pro>=0) ? 1 : -1;
119  last_spu = (last_pro>=0) ? 1 : -1;
120 
121  FairTrackParP first(firstState[3][0],firstState[4][0],firstState[1][0],firstState[2][0],firstState[0][0],firstCova,firstPlane.getO(),firstPlane.getU(),firstPlane.getV(),first_spu);
122  FairTrackParP last(lastState[3][0],lastState[4][0],lastState[1][0],lastState[2][0],lastState[0][0],lastCova,lastPlane.getO(),lastPlane.getU(),lastPlane.getV(),last_spu);
123 
124  //copy the trackCand
125  GFTrackCand genfitCand = tr->getCand();
126  PndTrackCand* pndCand = GenfitTrackCand2PndTrackCand(&genfitCand);
127  PndTrack* retVal = new PndTrack(first,last,*pndCand);
128  retVal->SetChi2(tr->getChiSqu());
129  retVal->SetNDF(tr->getNDF());
130  if (tr->getNDF()==0 || exc) {
131  retVal->SetFlag(-1);
132  }
133  else {
134  retVal->SetFlag(1);
135  }
136 
137  delete pndCand;
138  return retVal;
139 
140 }