CbmRoot
CbmL1TofMerger.cxx
Go to the documentation of this file.
1 // ------------------------------------------------------------------
2 // ----- CbmL1TofMerger -----
3 // ----- Created 24-01-2006 by D.Kresan -----
4 // ------------------------------------------------------------------
5 #include "CbmL1TofMerger.h"
6 
7 #include "CbmL1Def.h"
8 
9 #include "CbmGlobalTrack.h"
10 #include "CbmKFTrack.h"
11 #include "CbmTofHit.h"
12 #include "CbmTrdTrack.h"
13 #include "FairRootManager.h"
14 
15 #include "TClonesArray.h"
16 #include "TMath.h"
17 
18 #include <iostream>
19 #include <map>
20 #include <utility>
21 
22 using std::cout;
23 using std::endl;
24 using std::make_pair;
25 using std::map;
26 using std::pair;
27 
28 //___________________________________________________________________
29 //
30 // CbmL1TofMerger
31 //
32 // Concrete implementation of the global track - TOF hit merging
33 // algorithm
34 //
35 
36 
37 // ------------------------------------------------------------------
38 CbmL1TofMerger::CbmL1TofMerger() : fArrayTrdTrack(0) {
39  // Default constructor
40 }
41 // ------------------------------------------------------------------
42 
43 
44 // ------------------------------------------------------------------
45 CbmL1TofMerger::CbmL1TofMerger(Int_t) : fArrayTrdTrack(0) {
46  // Standard constructor
47  fVerbose = 1;
48 }
49 // ------------------------------------------------------------------
50 
51 
52 // ------------------------------------------------------------------
54  // Destructor
55 }
56 // ------------------------------------------------------------------
57 
58 
59 // ------------------------------------------------------------------
61  // Initialisation
62  FairRootManager* rootMgr = FairRootManager::Instance();
63  if (NULL == rootMgr) {
64  cout << "-E- CbmL1TofMerger::Init(): "
65  << "ROOT manager is not instantiated!" << endl;
66  return;
67  }
69  L1_DYNAMIC_CAST<TClonesArray*>(rootMgr->GetObject("TrdTrack"));
70  if (NULL == fArrayTrdTrack) {
71  cout << "-W- CbmL1TofMerger::Init: "
72  << "no TRD track array" << endl;
73  }
74 }
75 // ------------------------------------------------------------------
76 
77 
78 // ------------------------------------------------------------------
79 Int_t CbmL1TofMerger::DoMerge(TClonesArray* glbTracks, TClonesArray* tofHits) {
80  // Implementation of the merging algorithm
81  Int_t nMerged = 0;
82 
83  // Map from tof hit index to boolean flag
84  map<Int_t, Bool_t> mapTofHitUsed;
85  mapTofHitUsed.clear();
86  // Map from tof hit index to chi2 value
87  map<Int_t, Double_t> mapTofHitChi2;
88  mapTofHitChi2.clear();
89  // Map from tof hit index to track index
90  map<Int_t, Int_t> mapTofHitTrack;
91  mapTofHitTrack.clear();
92  // Map from track index to the boolean flag
93  map<Int_t, Bool_t> mapTrack;
94  mapTrack.clear();
95  for (Int_t iTrack = 0; iTrack < glbTracks->GetEntriesFast(); iTrack++) {
96  mapTrack[iTrack] = kTRUE;
97  }
98  // Map from track-tof index to boolean flag
99  map<pair<Int_t, Int_t>, Bool_t> mapForbidden;
100  mapForbidden.clear();
101 
102  // Declare variables outside the loop
103  CbmGlobalTrack* track;
104  Int_t oldTrackIndex;
105  CbmGlobalTrack* track2;
106  Int_t trdTrackIndex;
107  CbmTrdTrack* trdTrack;
108  CbmKFTrack kfTrack;
109  CbmTofHit* tofHit;
110  Double_t zposTof;
111  Double_t chi2;
112  Double_t chi2min;
113  Int_t indexOfClosest;
114 
115 
116  while (mapTrack.size() > 0) {
117 
118  // Loop over global tracks
119  for (Int_t iTrack = 0; iTrack < glbTracks->GetEntriesFast(); iTrack++) {
120 
121  // Skip if not in list
122  if (mapTrack.find(iTrack) == mapTrack.end()) continue;
123 
124  // Get pointer to the global track
125  track = L1_DYNAMIC_CAST<CbmGlobalTrack*>(glbTracks->At(iTrack));
126  if (NULL == track) {
127  mapTrack.erase(iTrack);
128  continue;
129  }
130 
131  // Skip if has no STS or TRD track
132  if (track->GetStsTrackIndex() < 0 || track->GetTrdTrackIndex() < 0) {
133  mapTrack.erase(iTrack);
134  continue;
135  }
136 
137  // Get TRD track
138  trdTrackIndex = track->GetTrdTrackIndex();
139  trdTrack =
140  L1_DYNAMIC_CAST<CbmTrdTrack*>(fArrayTrdTrack->At(trdTrackIndex));
141  if (NULL == trdTrack) {
142  mapTrack.erase(iTrack);
143  continue;
144  }
145 
146  // Set track parameters
147  kfTrack.SetTrackParam(
148  *(const_cast<FairTrackParam*>(trdTrack->GetParamLast())));
149  chi2min = 1e16;
150  indexOfClosest = -1;
151 
152  // Loop over TOF hits
153  for (Int_t iTof = 0; iTof < tofHits->GetEntriesFast(); iTof++) {
154  // Check if pair is not forbidden
155  if (mapForbidden[make_pair(iTrack, iTof)]) continue;
156  // Get TOF hit
157  tofHit = L1_DYNAMIC_CAST<CbmTofHit*>(tofHits->At(iTof));
158  if (NULL == tofHit) continue;
159  // Get z position of hit
160  zposTof = tofHit->GetZ();
161  // Extrapolate to current z-plane
162  kfTrack.Extrapolate(zposTof);
163  // Check for geometrical overlap
164  if (kFALSE == Overlap(kfTrack, tofHit)) continue;
165  // Get chi2 to hit
166  chi2 = GetChi2ToHit(kfTrack, tofHit);
167  // Find smallest chi2
168  if (chi2 < chi2min) {
169  chi2min = chi2;
170  indexOfClosest = iTof;
171  }
172  } // Loop over TOF hits
173 
174  // Save index of TOF hit
175  if (-1 != indexOfClosest) {
176  // Check if already used
177  if (mapTofHitUsed[indexOfClosest]) {
178  // Check if this track is closer
179  if (chi2min < mapTofHitChi2[indexOfClosest]) {
180  // Force previous track to be reprocessed
181  oldTrackIndex = mapTofHitTrack[indexOfClosest];
182  track2 =
183  L1_DYNAMIC_CAST<CbmGlobalTrack*>(glbTracks->At(oldTrackIndex));
184  track2->SetTofHitIndex(-1);
185  mapTrack[oldTrackIndex] = kTRUE;
186  nMerged -= 1;
187  // Forbid this combination
188  mapForbidden[make_pair(oldTrackIndex, indexOfClosest)] = kTRUE;
189  // Attach hit to current track
190  track->SetTofHitIndex(indexOfClosest);
191  mapTofHitChi2[indexOfClosest] = chi2min;
192  mapTofHitTrack[indexOfClosest] = iTrack;
193  mapTrack.erase(iTrack);
194  nMerged += 1;
195  } else {
196  // Forbid this combination
197  mapForbidden[make_pair(iTrack, indexOfClosest)] = kTRUE;
198  }
199  } else {
200  track->SetTofHitIndex(indexOfClosest);
201  mapTofHitUsed[indexOfClosest] = kTRUE;
202  mapTofHitChi2[indexOfClosest] = chi2min;
203  mapTofHitTrack[indexOfClosest] = iTrack;
204  mapTrack.erase(iTrack);
205  nMerged += 1;
206  }
207  } else {
208  mapTrack.erase(iTrack);
209  }
210 
211  } // Loop over global tracks
212  }
213 
214 
215  return nMerged;
216 }
217 // ------------------------------------------------------------------
218 
219 
220 // ------------------------------------------------------------------
221 Bool_t CbmL1TofMerger::Overlap(CbmKFTrack& track, const CbmTofHit* tofHit) {
222  // Check for geometrical overlap between track extrapolation
223  // and TOF hit
224  Double_t x1 = track.GetTrack()[0];
225  Double_t x2 = tofHit->GetX();
226  Double_t dx2 = tofHit->GetDx();
227  Bool_t overlap_x = TMath::Abs(x1 - x2) <= (5 + 3 * dx2);
228  Double_t y1 = track.GetTrack()[1];
229  Double_t y2 = tofHit->GetY();
230  Double_t dy2 = tofHit->GetDy();
231  Bool_t overlap_y = TMath::Abs(y1 - y2) <= (5 + 3 * dy2);
232  return (overlap_x && overlap_y);
233 }
234 // ------------------------------------------------------------------
235 
236 
237 // ------------------------------------------------------------------
239  const CbmTofHit* tofHit) {
240  // Get chi2 from the track extrapolation to the TOF hit
241  Double_t dx = track.GetTrack()[0] - tofHit->GetX();
242  Double_t dy = track.GetTrack()[1] - tofHit->GetY();
243  /* Double_t c0 = track.GetCovMatrix()[0] + TMath::Power(tofHit->GetDx(),2);
244  Double_t c1 = track.GetCovMatrix()[1];
245  Double_t c2 = track.GetCovMatrix()[2] + TMath::Power(tofHit->GetDy(),2);
246  Double_t chi2 = 0.5*(dx*dx*c0-2*dx*dy*c1+dy*dy*c2)/(c0*c2-c1*c1);*/
247  Double_t chi2 = TMath::Sqrt(dx * dx + dy * dy);
248  return chi2;
249 }
250 // ------------------------------------------------------------------
251 
252 
CbmHit::GetZ
Double_t GetZ() const
Definition: CbmHit.h:70
CbmTrack::GetParamLast
const FairTrackParam * GetParamLast() const
Definition: CbmTrack.h:62
CbmL1TofMerger::~CbmL1TofMerger
~CbmL1TofMerger()
Definition: CbmL1TofMerger.cxx:53
CbmL1TofMerger::Init
void Init()
Definition: CbmL1TofMerger.cxx:60
CbmPixelHit::GetX
Double_t GetX() const
Definition: CbmPixelHit.h:83
CbmPixelHit::GetY
Double_t GetY() const
Definition: CbmPixelHit.h:84
CbmPixelHit::GetDx
Double_t GetDx() const
Definition: CbmPixelHit.h:85
CbmTofMerger::fVerbose
Int_t fVerbose
Definition: CbmTofMerger.h:16
rootMgr
static FairRootManager * rootMgr
Definition: CbmDeviceHitBuilderTof.cxx:72
CbmKFTrack::GetTrack
Double_t * GetTrack()
Is it electron.
Definition: CbmKFTrack.h:58
CbmGlobalTrack.h
ClassImp
ClassImp(CbmL1TofMerger)
CbmPixelHit::GetDy
Double_t GetDy() const
Definition: CbmPixelHit.h:86
CbmL1TofMerger::GetChi2ToHit
Double_t GetChi2ToHit(CbmKFTrack &track, const CbmTofHit *tofHit)
Definition: CbmL1TofMerger.cxx:238
CbmL1Def.h
CbmGlobalTrack::GetStsTrackIndex
Int_t GetStsTrackIndex() const
Definition: CbmGlobalTrack.h:38
CbmL1TofMerger::fArrayTrdTrack
TClonesArray * fArrayTrdTrack
Definition: CbmL1TofMerger.h:22
CbmGlobalTrack::GetTrdTrackIndex
Int_t GetTrdTrackIndex() const
Definition: CbmGlobalTrack.h:39
CbmKFTrack.h
CbmL1TofMerger
Definition: CbmL1TofMerger.h:16
CbmL1TofMerger::DoMerge
Int_t DoMerge(TClonesArray *glbTracks, TClonesArray *tofHits)
Definition: CbmL1TofMerger.cxx:79
CbmL1TofMerger::CbmL1TofMerger
CbmL1TofMerger()
Definition: CbmL1TofMerger.cxx:38
CbmL1TofMerger::Overlap
Bool_t Overlap(CbmKFTrack &track, const CbmTofHit *tofHit)
Definition: CbmL1TofMerger.cxx:221
CbmTrdTrack
Definition: CbmTrdTrack.h:22
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
CbmGlobalTrack::SetTofHitIndex
void SetTofHitIndex(Int_t iTofHit)
Definition: CbmGlobalTrack.h:58
CbmTofHit
Definition: core/data/tof/CbmTofHit.h:26
CbmTrdTrack.h
CbmKFTrack
Definition: CbmKFTrack.h:21
CbmKFTrack::SetTrackParam
void SetTrackParam(const FairTrackParam &track)
Definition: CbmKFTrack.cxx:34
CbmL1TofMerger.h
CbmKFTrackInterface::Extrapolate
Int_t Extrapolate(Double_t z, Double_t *QP0=0)
Access to i-th hit.
Definition: CbmKFTrackInterface.cxx:39