FairRoot/PandaRoot
PndGenfitAdapters2.cxx
Go to the documentation of this file.
1 //modified by Elisabetta Prencipe, 19/05/2014
2 
3 #include"PndGenfitAdapters2.h"
4 
5 #include <iostream>
6 
7 #include"PndTrack.h"
8 #include"PndTrackCand.h"
9 #include"FairTrackParP.h"
10 
11 #include"AbsTrackRep.h"
12 #include"DetPlane.h"
13 #include"Exception.h"
14 #include"RKTrackRep.h"
15 #include"SharedPlanePtr.h"
16 #include"Track.h"
17 #include"TrackCand.h"
18 
19 #include <TMatrixD.h>
20 #include <TMatrixDSym.h>
21 
22 #include <cmath>
23 
25 {
26  // Utility to convert from genfit TrackCand to PndTrackCand.
27  // Since PndTrackCand does not store any seed value, those componets
28  // will not be present in the final object.
29 
30  PndTrackCand* retVal = new PndTrackCand();
31  const unsigned nhits = cand->getNHits();
32  int detId,hitId;
33  double rho;
34  for(unsigned int i=0;i<nhits;++i){
35  cand->getHit(i,detId,hitId,rho);//
36  retVal->AddHit(detId,hitId,rho);//
37  }
38 
39  retVal->setMcTrackId(cand->getMcTrackId());
40  return retVal;
41 }
42 
44 {
45  // Utility to convert from PndTrackCand to genfit TrackCand.
46  // PndTrackCand does not store any Seed, then to create a proper TrackCand you need
47  // to fill the seed afterwards taking the values from the PndTrack
48 
49  genfit::TrackCand* retVal = new genfit::TrackCand();
50  unsigned int nhits = cand->GetNHits();
51  for(unsigned int i=0;i<nhits;++i){
52  PndTrackCandHit candHit = cand->GetSortedHit(i);
53  retVal->addHit(candHit.GetDetId(),candHit.GetHitId(),i,candHit.GetRho());
54  }
55 
56  retVal->setMcTrackId(cand->getMcTrackId());
57  return retVal;
58 }
59 
61 
62  if (dynamic_cast<genfit::RKTrackRep*>(tr->getCardinalRep())==NULL) {
63  std::cerr << " GenfitAbsTrackRep2PndTrack() can currently only handle RKTrackRep" << std::endl;
64  throw;
65  }
66 
67  const TVectorD& firstState = tr->getFittedState().getState();
68  const TVectorD& lastState = tr->getFittedState(-1).getState();
69  const TMatrixDSym& firstCov = tr->getFittedState().getCov();
70  const TMatrixDSym& lastCov = tr->getFittedState(-1).getCov();
71  genfit::SharedPlanePtr firstPlane = tr->getFittedState().getPlane();
72  genfit::SharedPlanePtr lastPlane = tr->getFittedState(-1).getPlane();
73 
74  //make the FairTrackParP for first and last hit
75  double firstCova[15];
76  int count=0;
77  for(int i=0; i<5;++i){
78  for(int j=i;j<5;++j){
79  firstCova[count++]=firstCov(i,j);
80  }
81  }
82  double lastCova[15];
83  count=0;
84  for(int i=0; i<5;++i){
85  for(int j=i;j<5;++j){
86  lastCova[count++]=lastCov(i,j);
87  }
88  }
89 
90  double first_spu = (tr->getFittedState().getAuxInfo())(0);
91  double last_spu = (tr->getFittedState(-1).getAuxInfo())(0);
92 
93  FairTrackParP first(firstState[3],firstState[4],firstState[1],firstState[2],firstState[0],firstCova,firstPlane->getO(),firstPlane->getU(),firstPlane->getV(),first_spu);
94  FairTrackParP last(lastState[3],lastState[4],lastState[1],lastState[2],lastState[0],lastCova,lastPlane->getO(),lastPlane->getU(),lastPlane->getV(),last_spu);
95 
96  //copy the trackCand
97  genfit::TrackCand* genfitCand = tr->constructTrackCand();
98  PndTrackCand* pndCand = Genfit2TrackCand2PndTrackCand(genfitCand);
99  PndTrack* retVal = new PndTrack(first,last,*pndCand);
100  retVal->SetChi2(tr->getFitStatus()->getChi2());
101  retVal->SetNDF(tr->getFitStatus()->getNdf());
102  if (tr->getFitStatus()->isFitConverged()) {
103  retVal->SetFlag(1);
104  }
105  else {
106  retVal->SetFlag(-1);
107  }
108  delete genfitCand;
109  delete pndCand;
110  return retVal;
111 
112 }
Track candidate – seed values and indices.
Definition: TrackCand.h:69
TrackCandHit * getHit(int i) const
boost::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
int getMcTrackId() const
Definition: PndTrackCand.h:60
Int_t i
Definition: run_full.C:25
void addHit(int detId, int hitId, int planeId=-1, double sortingParameter=0)
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
Definition: Track.h:71
PndTrackCandHit GetSortedHit(UInt_t i)
Definition: PndTrackCand.h:54
void setMcTrackId(int i)
Definition: PndTrackCand.h:72
double getChi2() const
Get chi^2 of the fit.
Definition: FitStatus.h:118
void SetChi2(Double_t d)
Definition: PndTrack.h:39
const TMatrixDSym & getCov() const
const TVectorD & getAuxInfo() const
Definition: StateOnPlane.h:62
PndTrackCand * Genfit2TrackCand2PndTrackCand(const genfit::TrackCand *cand)
double getNdf() const
Get the degrees of freedom of the fit.
Definition: FitStatus.h:120
genfit::TrackCand * PndTrackCand2Genfit2TrackCand(PndTrackCand *cand)
bool isFitConverged(bool inAllPoints=true) const
Did the fit converge (in all Points or only partially)?
Definition: FitStatus.h:105
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
FitStatus * getFitStatus(const AbsTrackRep *rep=NULL) const
Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep.
Definition: Track.h:150
Double_t GetRho() const
AbsTrackRep * getCardinalRep() const
Get cardinal track representation.
Definition: Track.h:141
TrackCand * constructTrackCand() const
Construct a new TrackCand containing the hit IDs of the measurements.
void SetFlag(Int_t i)
Definition: PndTrack.h:38
void SetNDF(Int_t i)
Definition: PndTrack.h:40
UInt_t GetNHits() const
Definition: PndTrackCand.h:59
unsigned int getNHits() const
Definition: TrackCand.h:103
PndTrack * Genfit2Track2PndTrack(const genfit::Track *tr)
int count
const MeasuredStateOnPlane & getFittedState(int id=0, const AbsTrackRep *rep=NULL, bool biased=true) const
Shortcut to get FittedStates.
Int_t GetHitId() const
void setMcTrackId(int i)
Set the MCT track id, for MC simulations.
Definition: TrackCand.h:151
Int_t GetDetId() const
const TVectorD & getState() const
Definition: StateOnPlane.h:60
const SharedPlanePtr & getPlane() const
Definition: StateOnPlane.h:64
int getMcTrackId() const
Get the MCT track id, for MC simulations - default value = -1.
Definition: TrackCand.h:119