CbmRoot
PairAnalysisTrack.cxx
Go to the documentation of this file.
1 //
3 //
4 // Authors:
5 // Julian Book <Julian.Book@cern.ch>
6 /*
7 
8  Analysis track that keep references to all tracklets of sub detectors and
9  provides easy access to them via e.g. GetTrack(ECbmModuleId det).
10 
11  Two TLorentzVector hold information on the momentum components and
12  position. Further the SetMassHypo is calculated according to the
13  setting of PairAnalysis::SetLegPdg(pdgLeg1, pdgLeg2) and the actual charge.
14  In addition a track can be refitted using this mass assumption if enabled
15  using PairAnalysis::SetRefitWithMassAssump(kTRUE)
16 
17  TObject bits are used to flag the matching between detector tracklets and MC tracks.
18  Bits used are >14 and correspond to CbmDetectorList.h -> ECbmModuleId
19 */
20 // //
22 
23 //#include <TObjArray.h>
24 #include <vector>
25 
26 #include <TDatabasePDG.h>
27 #include <TLorentzVector.h>
28 #include <TParticle.h>
29 #include <TParticlePDG.h>
30 
31 #include "FairTrackParam.h"
32 
33 #include "CbmGlobalTrack.h"
34 #include "CbmKFVertex.h"
35 #include "CbmMCTrack.h"
36 #include "CbmMuchTrack.h"
37 #include "CbmMvdDetector.h"
38 #include "CbmMvdStationPar.h"
39 #include "CbmRichRing.h"
40 #include "CbmStsTrack.h"
41 #include "CbmTofHit.h"
42 #include "CbmTrack.h"
43 #include "CbmTrackMatchNew.h"
44 #include "CbmTrackParam.h"
45 #include "CbmTrdTrack.h"
46 
47 #include "CbmL1PFFitter.h"
48 #include "L1Field.h"
49 
51 #include "CbmLitPtrTypes.h"
52 #include "CbmLitToolFactory.h"
53 #include "CbmLitTrackParam.h"
54 
55 #include "PairAnalysisTrack.h"
56 
58 
60  : TNamed(), fMomentum(), fPosition() {
61  //
62  // Default Constructor
63  //
64 }
65 
66 //______________________________________________
67 PairAnalysisTrack::PairAnalysisTrack(const char* name, const char* title)
68  : TNamed(name, title), fMomentum(), fPosition() {
69  //
70  // Named Constructor
71  //
72 }
73 
74 //______________________________________________
76  : TNamed()
77  , fMCTrack(mctrk)
78  , fMomentum()
79  , fPosition()
80  , fPdgCode(fastTrk->GetPdgCode())
81  , fLabel(fastTrk->GetFirstMother())
82  , fFastTrack(kTRUE) {
83  //
84  // Constructor
85  //
86  fastTrk->Momentum(fMomentum);
87  fastTrk->ProductionVertex(fPosition);
88 
89  TParticlePDG* mcPart = fastTrk->GetPDG(0);
90  if (mcPart) fCharge = mcPart->Charge() / 3;
91 }
92 
93 //______________________________________________
95  CbmGlobalTrack* gtrk,
96  CbmStsTrack* ststrk,
97  CbmMuchTrack* muchtrk,
98  CbmTrdTrack* trdtrk,
99  CbmRichRing* richring,
100  CbmTofHit* tofhit,
101  CbmMCTrack* mctrk,
102  CbmTrackMatchNew* stsmatch,
103  CbmTrackMatchNew* muchmatch,
104  CbmTrackMatchNew* trdmatch,
105  CbmTrackMatchNew* richmatch,
106  FairTrackParam* richproj,
107  Int_t gIndex)
108  : TNamed()
109  , fPrimVertex(vtx)
110  , fGlblTrack(gtrk)
111  , fGlblTrackIndex(gIndex)
112  , fStsTrack(ststrk)
113  , fMuchTrack(muchtrk)
114  , fTrdTrack(trdtrk)
115  , fRichRing(richring)
116  , fTofHit(tofhit)
117  , fMCTrack(mctrk)
118  , fStsTrackMatch(stsmatch)
119  , fMuchTrackMatch(muchmatch)
120  , fTrdTrackMatch(trdmatch)
121  , fRichRingMatch(richmatch)
122  , fRichProj(richproj)
123  , fMvdEntrance(new FairTrackParam())
124  , fMomentum()
125  , fPosition() {
126  //
127  // Constructor
128  //
129  Double_t m2 =
130  TMath::Power(TDatabasePDG::Instance()->GetParticle(11)->Mass(), 2);
131 
134  if (mvdpar && mvdpar->GetStationCount()) {
135  Double_t zMvd =
136  mvdpar->GetZPosition(0); // z-position of the first mvd station
137  TrackExtrapolatorPtr fExtrapolator =
139  CbmLitTrackParam litParamIn;
141  ststrk->GetParamFirst(), &litParamIn);
142  CbmLitTrackParam litParamOut;
143  fExtrapolator->Extrapolate(&litParamIn, &litParamOut, zMvd, NULL);
145  &litParamOut, fMvdEntrance);
146  }
147 
149  const CbmTrackParam* ppar = fGlblTrack->GetParamVertex();
150  if (ppar) {
151  fMomentum.SetPxPyPzE(ppar->GetPx(), ppar->GetPy(), ppar->GetPz(), 0.);
152  fMomentum.SetE(TMath::Sqrt(fMomentum.Vect().Mag2() + m2));
153  fPosition.SetXYZM(
154  ppar->GetX(), ppar->GetY(), ppar->GetZ(), TMath::Sqrt(m2));
155  fCharge = (ppar->GetQp() > 0. ? +1. : -1.);
157  } else {
158  Refit(211);
159  }
160 
161  if (mctrk) fPdgCode = mctrk->GetPdgCode();
162 }
163 
164 //______________________________________________
166  : TNamed(track.GetName(), track.GetTitle())
167  , fPrimVertex(track.fPrimVertex)
168  , fGlblTrack(track.GetGlobalTrack())
169  , fGlblTrackIndex(track.GetGlobalIndex())
170  , fStsTrack(track.fStsTrack)
171  , fMuchTrack(track.fMuchTrack)
172  , fTrdTrack(track.fTrdTrack)
173  , fRichRing(track.GetRichRing())
174  , fTofHit(track.GetTofHit())
175  , fMCTrack(track.GetMCTrack())
176  , fStsTrackMatch(track.GetTrackMatch(ECbmModuleId::kSts))
177  , fMuchTrackMatch(track.GetTrackMatch(ECbmModuleId::kMuch))
178  , fTrdTrackMatch(track.GetTrackMatch(ECbmModuleId::kTrd))
179  , fRichRingMatch(track.GetTrackMatch(ECbmModuleId::kRich))
180  , fRichProj(track.GetRichProj())
181  , fMvdEntrance(track.GetMvdEntrance())
182  , fMomentum(track.fMomentum)
183  , fPosition(track.fPosition)
184  , fChi2Vtx(track.ChiToVertex())
185  , fCharge(track.Charge())
186  , fPdgCode(track.PdgCode())
187  , fLabel(track.GetLabel())
188  , fWeight(track.GetWeight())
189  , fFastTrack(track.fFastTrack) {
190  //
191  // Copy Constructor
192  //
193 
194  this->SetBit(BIT(14 + ToIntegralType(ECbmModuleId::kTof)),
195  track.TestBit(BIT(14 + ToIntegralType(ECbmModuleId::kTof))));
196  this->SetBit(BIT(14 + ToIntegralType(ECbmModuleId::kRich)),
197  track.TestBit(BIT(14 + ToIntegralType(ECbmModuleId::kRich))));
198  this->SetBit(BIT(14 + ToIntegralType(ECbmModuleId::kTrd)),
199  track.TestBit(BIT(14 + ToIntegralType(ECbmModuleId::kTrd))));
200  this->SetBit(BIT(14 + ToIntegralType(ECbmModuleId::kSts)),
201  track.TestBit(BIT(14 + ToIntegralType(ECbmModuleId::kSts))));
202  this->SetBit(BIT(14 + ToIntegralType(ECbmModuleId::kMuch)),
203  track.TestBit(BIT(14 + ToIntegralType(ECbmModuleId::kMuch))));
204 }
205 
206 //______________________________________________
208  //
209  // Default Destructor
210  //
211  // if(fPrimVertex) delete fPrimVertex;
212 }
213 
214 //______________________________________________
216  //
217  // get track match depending on detector id
218  //
219  switch (det) {
220  case ECbmModuleId::kMvd:
221  return fStsTrackMatch; // there is no mvd track, hit are associtaed to sts track
222  case ECbmModuleId::kSts: return fStsTrackMatch;
223  case ECbmModuleId::kTrd: return fTrdTrackMatch;
225  case ECbmModuleId::kRich: return fRichRingMatch;
226  default: return 0x0;
227  }
228 }
229 
230 //______________________________________________
232  //
233  // get track depending on detector id
234  //
235  switch (det) {
236  case ECbmModuleId::kMvd:
237  return fStsTrack; // there is no mvd track, hit are associtaed to sts track
238  case ECbmModuleId::kSts: return fStsTrack;
239  case ECbmModuleId::kTrd: return fTrdTrack;
240  case ECbmModuleId::kMuch: return fMuchTrack;
241  case ECbmModuleId::kRich: return 0x0;
242  default: return 0x0;
243  }
244 }
245 
246 //______________________________________________
248  Int_t pdg2,
249  Bool_t refitMassAssump) {
250  //
251  // use charge, time and track length information to assign
252  // the best guessed mass hypothesis
253  //
254  const Double_t mpdg1 = TDatabasePDG::Instance()->GetParticle(pdg1)->Mass();
255  const Double_t mpdg2 = TDatabasePDG::Instance()->GetParticle(pdg2)->Mass();
256  const Double_t cpdg1 =
257  TDatabasePDG::Instance()->GetParticle(pdg1)->Charge() * 3;
258  const Double_t cpdg2 =
259  TDatabasePDG::Instance()->GetParticle(pdg2)->Charge() * 3;
260 
261  Double_t m2 = 0.;
262  Int_t ppdg = 0; // prefered pdg
263  // match STS charge of track to pid and set mass accordingly
264  if (fCharge * cpdg1 < 0) {
265  m2 = mpdg2 * mpdg2;
266  ppdg = pdg2;
267  } else if (fCharge * cpdg2 < 0) {
268  m2 = mpdg1 * mpdg1;
269  ppdg = pdg1;
270  } else
271  Error("SetMassHypo", "via STS charge went wrong!");
272 
273  // use TOF time(ns) and track length(cm) if available
274  if (fTofHit && kFALSE) { //TODO: switched OFF!!
275  m2 = fMomentum.Mag2()
276  * (TMath::Power((fTofHit->GetTime() * 1e-9 * TMath::C())
277  / fGlblTrack->GetLength() / 100,
278  2)
279  - 1);
280  }
281 
282  // refit (under pdg assumption if activated)
283  if (!refitMassAssump && !fFastTrack) {
285  const CbmTrackParam* ppar = fGlblTrack->GetParamVertex();
286  if (ppar) {
287  fMomentum.SetPxPyPzE(ppar->GetPx(), ppar->GetPy(), ppar->GetPz(), 0.);
288  fMomentum.SetE(TMath::Sqrt(fMomentum.Vect().Mag2() + m2));
289  fPosition.SetXYZM(
290  ppar->GetX(), ppar->GetY(), ppar->GetZ(), TMath::Sqrt(m2));
291  fCharge = (ppar->GetQp() > 0. ? +1. : -1.);
293  } else
294  Refit(211);
295  } else {
296  Refit(ppdg);
297  // fMomentum.Print();
299  fMomentum.SetE(TMath::Sqrt(fMomentum.Vect().Mag2() + m2));
300  // fMomentum.Print();
301  }
302 }
303 
304 //______________________________________________
305 void PairAnalysisTrack::Refit(Int_t pidHypo) {
306  //
307  // refit the track under certain mass assumption using CbmL1PFFitter
308  // to the primary vertex
309  //
310 
312  if (fFastTrack) return;
313 
314  vector<CbmStsTrack> stsTracks;
315  stsTracks.resize(1);
316  stsTracks[0] = *fStsTrack;
317  vector<L1FieldRegion> vField;
318  vector<float> chiPrim;
319  vector<int> pidHypos;
320  pidHypos.push_back(pidHypo);
321 
322  // printf("stst track: %p \t prim vertex: %p\n",fStsTrack,fPrimVertex);
323  // printf(" fit track with mass assumption, pdg: %d (default is: %d)\n",pidHypo,fStsTrack->GetPidHypo());
324 
325  CbmL1PFFitter fPFFitter;
326  if (pidHypo) fPFFitter.Fit(stsTracks, pidHypos); // fit with mass hypo
327  // printf(" fit done for mass hypo (%p)\n",&stsTracks[0]);
328 
329  // NOTE: as an alternative to fPFFitter.Fit one can use fStsTrack->SetPidHypo(pidHypo);
330  fPFFitter.GetChiToVertex(stsTracks, vField, chiPrim, *fPrimVertex, 3.e6);
331  fChi2Vtx = chiPrim[0];
332  // printf(" track refitted with chi2/ndf: %.3f , param %p \n",fChi2Vtx,stsTracks[0].GetParamFirst());
333 
334  const FairTrackParam* vtxTrack = stsTracks[0].GetParamFirst();
335  if (!vtxTrack) Error("Refit", "No track param found!");
336 
337  // update position and momentum vectors
338  TVector3 mom;
339  vtxTrack->Momentum(mom);
340  fMomentum.SetVect(mom);
341 
342  TVector3 pos;
343  vtxTrack->Position(pos);
344  fPosition.SetVect(pos);
345 
346  // set charge based on fit
347  fCharge = (vtxTrack->GetQp() > 0. ? +1. : -1.);
348 }
349 
350 //______________________________________________
352  //
353  // calculation according to CbmL1PFFitter::GetChiToVertex
354  //
355 
356  // primary vertex
357  Double_t Cv[3] = {fPrimVertex->GetCovMatrix()[0],
359  fPrimVertex->GetCovMatrix()[2]};
360 
361  // track params at prim vertex
362  const CbmTrackParam* ppar = fGlblTrack->GetParamVertex();
363 
364  // impact param
365  Double_t dx = ppar->GetX() - fPrimVertex->GetRefX();
366  Double_t dy = ppar->GetY() - fPrimVertex->GetRefY();
367 
368 
369  Double_t c[3] = {ppar->GetCovariance(0, 0),
370  ppar->GetCovariance(1, 0),
371  ppar->GetCovariance(1, 1)};
372  c[0] += Cv[0];
373  c[1] += Cv[1];
374  c[2] += Cv[2];
375 
376  Double_t d = c[0] * c[2] - c[1] * c[1];
377  Double_t chi = TMath::Sqrt(TMath::Abs(
378  0.5 * (dx * dx * c[0] - 2 * dx * dy * c[1] + dy * dy * c[2]) / d));
379  Bool_t isNull = (TMath::Abs(d) < 1.e-20);
380 
381  if (isNull)
382  fChi2Vtx = -1.;
383  else
384  fChi2Vtx = chi;
385 }
CbmMvdDetector::Instance
static CbmMvdDetector * Instance()
Definition: CbmMvdDetector.cxx:47
CbmLitTrackParam.h
Data class for track parameters.
CbmMvdDetector.h
PairAnalysisTrack::fCharge
Short_t fCharge
Definition: PairAnalysisTrack.h:137
PairAnalysisTrack::PairAnalysisTrack
PairAnalysisTrack()
PairAnalysisTrack::fMuchTrackMatch
CbmTrackMatchNew * fMuchTrackMatch
Definition: PairAnalysisTrack.h:127
CbmMvdStationPar::GetZPosition
Double_t GetZPosition(Int_t stationNumber) const
Definition: CbmMvdStationPar.cxx:82
PairAnalysisTrack::SetMassHypo
void SetMassHypo(Int_t pdg1, Int_t pdg2, Bool_t refitMassAssump)
Definition: PairAnalysisTrack.cxx:247
CbmMvdDetector::GetParameterFile
CbmMvdStationPar * GetParameterFile()
Definition: CbmMvdDetector.h:111
CbmTrackParam::GetPx
Double_t GetPx() const
Definition: CbmTrackParam.h:39
L1Field.h
CbmL1PFFitter
Definition: CbmL1PFFitter.h:31
PairAnalysisTrack::~PairAnalysisTrack
virtual ~PairAnalysisTrack()
Definition: PairAnalysisTrack.cxx:207
CbmL1PFFitter::Fit
void Fit(std::vector< CbmStsTrack > &Tracks, std::vector< int > &pidHypo)
Definition: CbmL1PFFitter.cxx:81
CbmLitTrackParam
Data class for track parameters.
Definition: CbmLitTrackParam.h:29
CbmKFVertex::GetRefX
Double_t & GetRefX()
Definition: CbmKFVertex.h:23
CbmMCTrack::GetPdgCode
Int_t GetPdgCode() const
Definition: CbmMCTrack.h:70
CbmLitToolFactory.h
Tool factory for creation of littrack algorithms.
CbmGlobalTrack.h
ECbmModuleId::kMvd
@ kMvd
Micro-Vertex Detector.
ECbmModuleId
ECbmModuleId
Definition: CbmDefs.h:33
CbmRichRing
Definition: CbmRichRing.h:17
CbmGlobalTrack::GetLength
Double_t GetLength() const
Definition: CbmGlobalTrack.h:50
PairAnalysisTrack
Definition: PairAnalysisTrack.h:37
PairAnalysisTrack::GetTrack
CbmTrack * GetTrack(ECbmModuleId det) const
Definition: PairAnalysisTrack.cxx:231
CbmRichRing.h
ECbmModuleId::kTof
@ kTof
Time-of-flight Detector.
PairAnalysisTrack::fMvdEntrance
FairTrackParam * fMvdEntrance
Definition: PairAnalysisTrack.h:132
PairAnalysisTrack::fTofHit
CbmTofHit * fTofHit
Definition: PairAnalysisTrack.h:123
PairAnalysisTrack::fRichRingMatch
CbmTrackMatchNew * fRichRingMatch
Definition: PairAnalysisTrack.h:129
CbmLitConverterFairTrackParam::CbmLitTrackParamToFairTrackParam
static void CbmLitTrackParamToFairTrackParam(const CbmLitTrackParam *litPar, FairTrackParam *par)
Definition: CbmLitConverterFairTrackParam.h:110
CbmMuchTrack
Definition: CbmMuchTrack.h:16
CbmGlobalTrack::GetParamVertex
const CbmTrackParam * GetParamVertex() const
Definition: CbmGlobalTrack.h:45
PairAnalysisTrack::fStsTrackMatch
CbmTrackMatchNew * fStsTrackMatch
Definition: PairAnalysisTrack.h:126
CbmLitToolFactory::CreateTrackExtrapolator
static TrackExtrapolatorPtr CreateTrackExtrapolator(const string &name)
Create track extrapolation tool by name.
Definition: CbmLitToolFactory.cxx:42
ClassImp
ClassImp(PairAnalysisTrack) PairAnalysisTrack
Definition: PairAnalysisTrack.cxx:57
PairAnalysisTrack::fPrimVertex
CbmKFVertex * fPrimVertex
Definition: PairAnalysisTrack.h:116
CbmTrack
Definition: CbmTrack.h:32
CbmStsTrack.h
Data class for STS tracks.
CbmMuchTrack.h
CbmL1PFFitter::GetChiToVertex
void GetChiToVertex(std::vector< CbmStsTrack > &Tracks, std::vector< L1FieldRegion > &field, std::vector< float > &chiToVtx, CbmKFVertex &primVtx, float chiPrim=-1)
Definition: CbmL1PFFitter.cxx:403
PairAnalysisTrack::GetTrackMatch
CbmTrackMatchNew * GetTrackMatch(ECbmModuleId det) const
Definition: PairAnalysisTrack.cxx:215
d
double d
Definition: P4_F64vec2.h:24
CbmTrack.h
CbmHit::GetTime
Double_t GetTime() const
Definition: CbmHit.h:75
CbmLitConverterFairTrackParam.h
CbmTrackMatchNew.h
CbmMvdStationPar.h
CbmTrackParam::GetPy
Double_t GetPy() const
Definition: CbmTrackParam.h:40
CbmL1PFFitter.h
ECbmModuleId::kRich
@ kRich
Ring-Imaging Cherenkov Detector.
PairAnalysisTrack::fTrdTrack
CbmTrdTrack * fTrdTrack
Definition: PairAnalysisTrack.h:121
TrackExtrapolatorPtr
boost::shared_ptr< CbmLitTrackExtrapolator > TrackExtrapolatorPtr
Definition: CbmTofPtrTypes.h:22
CbmTrack::GetParamFirst
const FairTrackParam * GetParamFirst() const
Definition: CbmTrack.h:61
PairAnalysisTrack.h
ECbmModuleId::kTrd
@ kTrd
Transition Radiation Detector.
CbmTrdTrack
Definition: CbmTrdTrack.h:22
PairAnalysisTrack::fChi2Vtx
Double_t fChi2Vtx
Definition: PairAnalysisTrack.h:136
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
PairAnalysisTrack::CalculateChi2Vtx
void CalculateChi2Vtx()
Definition: PairAnalysisTrack.cxx:351
CbmMCTrack.h
CbmKFVertex::GetCovMatrix
Double_t * GetCovMatrix()
Definition: CbmKFVertex.h:26
PairAnalysisTrack::fStsTrack
CbmStsTrack * fStsTrack
Definition: PairAnalysisTrack.h:119
CbmMCTrack
Definition: CbmMCTrack.h:34
ToIntegralType
constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition: CbmDefs.h:24
CbmTrackParam
Definition: CbmTrackParam.h:22
CbmTrackParam::GetPz
Double_t GetPz() const
Definition: CbmTrackParam.h:41
PairAnalysisTrack::fPdgCode
Int_t fPdgCode
Definition: PairAnalysisTrack.h:138
CbmMvdStationPar
Definition: CbmMvdStationPar.h:22
PairAnalysisTrack::fGlblTrack
CbmGlobalTrack * fGlblTrack
Definition: PairAnalysisTrack.h:117
pos
TVector3 pos
Definition: CbmMvdSensorDigiToHitTask.cxx:60
CbmKFVertex::GetRefY
Double_t & GetRefY()
Definition: CbmKFVertex.h:24
ECbmModuleId::kMuch
@ kMuch
Muon detection system.
CbmTrackMatchNew
Definition: CbmTrackMatchNew.h:19
PairAnalysisTrack::fMuchTrack
CbmMuchTrack * fMuchTrack
Definition: PairAnalysisTrack.h:120
PairAnalysisTrack::fMomentum
TLorentzVector fMomentum
Definition: PairAnalysisTrack.h:134
CbmTofHit
Definition: core/data/tof/CbmTofHit.h:26
PairAnalysisTrack::fFastTrack
Bool_t fFastTrack
Definition: PairAnalysisTrack.h:143
CbmTrdTrack.h
CbmLitPtrTypes.h
Typedefs for algorithm interfaces.
CbmStsTrack
Definition: CbmStsTrack.h:37
PairAnalysisTrack::Refit
void Refit(Int_t pidHypo)
Definition: PairAnalysisTrack.cxx:305
ECbmModuleId::kSts
@ kSts
Silicon Tracking System.
CbmKFVertex.h
PairAnalysisTrack::fTrdTrackMatch
CbmTrackMatchNew * fTrdTrackMatch
Definition: PairAnalysisTrack.h:128
CbmLitConverterFairTrackParam::FairTrackParamToCbmLitTrackParam
static void FairTrackParamToCbmLitTrackParam(const FairTrackParam *par, CbmLitTrackParam *litPar)
Definition: CbmLitConverterFairTrackParam.h:40
CbmTrackParam.h
PairAnalysisTrack::fPosition
TLorentzVector fPosition
Definition: PairAnalysisTrack.h:135
CbmKFVertex
Definition: CbmKFVertex.h:6
CbmMvdStationPar::GetStationCount
Int_t GetStationCount() const
Definition: CbmMvdStationPar.h:34