CbmRoot
CbmL1TrackMerger.cxx
Go to the documentation of this file.
1 // ------------------------------------------------------------------
2 // ----- CbmL1TrackMerger -----
3 // ----- Created 2006-01-24 by D.Kresan -----
4 // ------------------------------------------------------------------
5 #include "CbmL1TrackMerger.h"
6 
7 #include "CbmL1Def.h"
8 
9 #include "CbmGlobalTrack.h"
10 #include "CbmKFTrack.h"
11 #include "CbmStsTrack.h"
12 #include "CbmTrackMatch.h"
13 #include "CbmTrdTrack.h"
14 #include "FairRootManager.h"
15 
16 #include "TClonesArray.h"
17 #include "TH2F.h"
18 #include "TMath.h"
19 
20 #include <iostream>
21 #include <map>
22 
23 using std::cout;
24 using std::endl;
25 using std::map;
26 
27 //___________________________________________________________________
28 //
29 // CbmL1TrackMerger
30 //
31 // Concrete implementation of the STS-TRD track merging.
32 // Two methods are availible:
33 // 1) Merging based on the value of CbmTrdTrack::GetStsTrackIndex().
34 // Selected by ::SetMethod(1). To be used for STS-based TRD track
35 // finder
36 // 2) Merging at the first TRD plane. Selected by ::SetMethod(2). To
37 // be used for standalone TRD track finder
38 //
39 
40 
41 // ------------------------------------------------------------------
43  : fMethod(1)
44  , // Merging method: 1 - based on StsTrackIndex from TRD track
45  fArrayStsTrackM(NULL)
46  , // Array of STS track matches
47  fArrayTrdTrackM(NULL)
48  , // Array of TRD track matches
49  fh_dx_true(0)
50  , // Control histogramm
51  fh_dx_false(0)
52  , // Control histogramm
53  fh_dy_true(0)
54  , // Control histogramm
55  fh_dy_false(0)
56  , // Control histogramm
57  fh_dtx_true(0)
58  , // Control histogramm
59  fh_dtx_false(0)
60  , // Control histogramm
61  fh_dty_true(0)
62  , // Control histogramm
63  fh_dty_false(0) // Control histogramm
64 {
65  // Default constructor
66  fVerbose = 1;
68 }
69 // ------------------------------------------------------------------
70 
71 
72 // ------------------------------------------------------------------
74  : fMethod(1)
75  , // Merging method: 1 - based on StsTrackIndex from TRD track
76  fArrayStsTrackM(NULL)
77  , // Array of STS track matches
78  fArrayTrdTrackM(NULL)
79  , // Array of TRD track matches
80  fh_dx_true(0)
81  , // Control histogramm
82  fh_dx_false(0)
83  , // Control histogramm
84  fh_dy_true(0)
85  , // Control histogramm
86  fh_dy_false(0)
87  , // Control histogramm
88  fh_dtx_true(0)
89  , // Control histogramm
90  fh_dtx_false(0)
91  , // Control histogramm
92  fh_dty_true(0)
93  , // Control histogramm
94  fh_dty_false(0) // Control histogramm
95 {
96  // Standard constructor
97  fVerbose = verbose;
99 }
100 // ------------------------------------------------------------------
101 
102 
103 // ------------------------------------------------------------------
105  // Destructor
106 }
107 // ------------------------------------------------------------------
108 
109 
110 // ------------------------------------------------------------------
112  // Initialisation
113  FairRootManager* rootMgr = FairRootManager::Instance();
114  if (NULL == rootMgr) {
115  cout << "-E- CbmL1TrackMerger::Init : "
116  << "FairRootManager is not instantiated!" << endl;
117  return;
118  }
120  L1_DYNAMIC_CAST<TClonesArray*>(rootMgr->GetObject("StsTrackMatch"));
121  if (NULL == fArrayStsTrackM) {
122  cout << "-W- CbmL1TrackMerger::Init : "
123  << "no STS track match array" << endl;
124  }
126  L1_DYNAMIC_CAST<TClonesArray*>(rootMgr->GetObject("TrdTrackMatch"));
127  if (NULL == fArrayTrdTrackM) {
128  cout << "-W- CbmL1TrackMerger::Init : "
129  << "no TRD track match array" << endl;
130  }
131 }
132 // ------------------------------------------------------------------
133 
134 
135 // ------------------------------------------------------------------
136 Int_t CbmL1TrackMerger::DoMerge(TClonesArray* stsTracks,
137  TClonesArray* trdTracks,
138  TClonesArray* glbTracks) {
139  // Implementation of the merging algorithm
140  if (1 == fMethod) {
141  return MergeSimple(stsTracks, trdTracks, glbTracks);
142  } else if (2 == fMethod) {
143  return MergeImPlane(stsTracks, trdTracks, glbTracks);
144  } else {
145  cout << "-E- CbmL1TrackMerger::DoMerge : "
146  << "unknown method " << fMethod << endl;
147  }
148  return 0;
149 }
150 // ------------------------------------------------------------------
151 
152 
153 // ------------------------------------------------------------------
154 Int_t CbmL1TrackMerger::MergeSimple(TClonesArray* stsTracks,
155  TClonesArray* trdTracks,
156  TClonesArray* glbTracks) {
157  // Simple merging algorithm. To be used for STS based TRD track
158  // finding
159  Int_t nGlb = 0;
160 
161  CbmTrdTrack* trdTrack = NULL;
162  CbmGlobalTrack* glbTrack = NULL;
163 
164  map<Int_t, Int_t> mapStsTrackUsed;
165 
166  // Loop over TRD tracks, create corresponding global track
167  // and attach STS track
168  for (Int_t iTrdTrack = 0; iTrdTrack < trdTracks->GetEntriesFast();
169  iTrdTrack++) {
170  // Get pointer to the TRD track
171  trdTrack = L1_DYNAMIC_CAST<CbmTrdTrack*>(trdTracks->At(iTrdTrack));
172  if (NULL == trdTrack) continue;
173  // Create global track
174  glbTrack = new ((*glbTracks)[nGlb]) CbmGlobalTrack();
175  nGlb += 1;
176  // Set STS and TRD track indices
177  glbTrack->SetStsTrackIndex(trdTrack->GetPreviousTrackId());
178  glbTrack->SetTrdTrackIndex(iTrdTrack);
179  // Mark STS track as used
180  mapStsTrackUsed[trdTrack->GetPreviousTrackId()] = kTRUE;
181  if (fVerbose > 1) {
182  cout << "-I- CbmL1TrackMerger::MergeSimple" << endl
183  << " global track : " << nGlb - 1
184  << " sts track : "
185  << trdTrack->GetPreviousTrackId() << endl
186  << " trd track : " << iTrdTrack << endl;
187  }
188  } // Loop over TRD tracks
189 
190  // Loop over STS tracks
191  for (Int_t iSts = 0; iSts < stsTracks->GetEntriesFast(); iSts++) {
192  // Skip, if already used
193  if (mapStsTrackUsed[iSts]) continue;
194  // Create global track
195  glbTrack = new ((*glbTracks)[nGlb]) CbmGlobalTrack();
196  nGlb += 1;
197  glbTrack->SetStsTrackIndex(iSts);
198  if (fVerbose > 1) {
199  cout << "-I- CbmL1TrackMerger::MergeSimple" << endl
200  << " global track : " << nGlb - 1
201  << " sts track : " << iSts
202  << " trd track : " << -1 << endl;
203  }
204  }
205 
206  return nGlb;
207 }
208 // ------------------------------------------------------------------
209 
210 
211 // ------------------------------------------------------------------
212 Int_t CbmL1TrackMerger::MergeImPlane(TClonesArray* stsTracks,
213  TClonesArray* trdTracks,
214  TClonesArray* glbTracks) {
215  // Real merging algorithm. To be used for standalone
216  // TRD track finders
217  if (!stsTracks || !trdTracks || !glbTracks) return 0;
218  if (!fArrayStsTrackM || !fArrayTrdTrackM) return 0;
219 
220  CbmStsTrack* stsTrack;
221  CbmKFTrack kfTrack;
222  CbmTrdTrack* trdTrack;
223  CbmGlobalTrack* glbTrack;
224  CbmTrackMatch* stsTrackM;
225  CbmTrackMatch* trdTrackM;
226  Int_t nGlb = 0;
227  Int_t nMerged = 0;
228  Double_t dx;
229  Double_t dy;
230  Double_t dtx;
231  Double_t dty;
232  Double_t theta;
233  Double_t chi2XY;
234  Double_t dx_cut;
235  Double_t dy_cut;
236  Double_t dtx_cut;
237 
238  // Map from the TRD track index to the boolean flag
239  map<Int_t, Bool_t> mapTrdTrackUsed;
240 
241  // Loop over STS tracks
242  for (Int_t iStsTrack = 0; iStsTrack < stsTracks->GetEntriesFast();
243  iStsTrack++) {
244  // Get pointer to the STS track and track match
245  stsTrack = L1_DYNAMIC_CAST<CbmStsTrack*>(stsTracks->At(iStsTrack));
246  if (NULL == stsTrack) continue;
247  stsTrackM = L1_DYNAMIC_CAST<CbmTrackMatch*>(fArrayStsTrackM->At(iStsTrack));
248  if (NULL == stsTrackM) continue;
249 
250  // Create global track
251  new ((*glbTracks)[nGlb]) CbmGlobalTrack();
252  glbTrack = L1_DYNAMIC_CAST<CbmGlobalTrack*>(glbTracks->At(nGlb));
253  if (NULL == glbTrack) continue;
254  nGlb += 1;
255  // Set STS track index
256  glbTrack->SetStsTrackIndex(iStsTrack);
257  // Merge with TRD
258  kfTrack.SetTrackParam(*stsTrack->GetParamLast());
259  // Loop over TRD tracks
260  Double_t minChi2XY = 1e16;
261  Int_t indexOfClosest = -1;
262  for (Int_t iTrdTrack = 0; iTrdTrack < trdTracks->GetEntriesFast();
263  iTrdTrack++) {
264  // Skip if already merged
265  if (mapTrdTrackUsed[iTrdTrack]) continue;
266  // Get pointer to the TRD track and track match
267  trdTrack = L1_DYNAMIC_CAST<CbmTrdTrack*>(trdTracks->At(iTrdTrack));
268  if (NULL == trdTrack) continue;
269  trdTrackM =
270  L1_DYNAMIC_CAST<CbmTrackMatch*>(fArrayTrdTrackM->At(iTrdTrack));
271  if (NULL == trdTrackM) continue;
272  // Extrapolate STS track to the first plane of TRD track
273  kfTrack.Extrapolate(trdTrack->GetParamFirst()->GetZ());
274 
275  // Fill histogramms
276  dx = kfTrack.GetTrack()[0] - trdTrack->GetParamFirst()->GetX();
277  dy = kfTrack.GetTrack()[1] - trdTrack->GetParamFirst()->GetY();
278  dtx = kfTrack.GetTrack()[2] - trdTrack->GetParamFirst()->GetTx();
279  dty = kfTrack.GetTrack()[3] - trdTrack->GetParamFirst()->GetTy();
280  theta =
281  180. / TMath::Pi()
282  * TMath::ACos(1.
283  / TMath::Sqrt(1 + TMath::Power(kfTrack.GetTrack()[2], 2)
284  + TMath::Power(kfTrack.GetTrack()[3], 2)));
285  if (stsTrackM->GetMCTrackId() == trdTrackM->GetMCTrackId()) {
286  fh_dx_true->Fill(dx, theta);
287  } else {
288  fh_dx_false->Fill(dx, theta);
289  }
290 
291  // Cut on dx
292  if (theta < 5) {
293  dx_cut = 1;
294  } else if (theta < 10) {
295  dx_cut = 4;
296  } else if (theta < 15) {
297  dx_cut = 4;
298  } else if (theta < 20) {
299  dx_cut = 4;
300  } else if (theta < 25) {
301  dx_cut = 4;
302  } else if (theta < 30) {
303  dx_cut = 4;
304  } else if (theta < 35) {
305  dx_cut = 4;
306  } else if (theta < 40) {
307  dx_cut = 2;
308  } else {
309  dx_cut = 0.;
310  }
311  if (TMath::Abs(dx) > dx_cut) continue;
312  // Fill histogramms
313  if (stsTrackM->GetMCTrackId() == trdTrackM->GetMCTrackId()) {
314  fh_dy_true->Fill(dy, theta);
315  } else {
316  fh_dy_false->Fill(dy, theta);
317  }
318 
319  // Cut on dy
320  if (theta < 5) {
321  dy_cut = 1;
322  } else if (theta < 10) {
323  dy_cut = 2;
324  } else if (theta < 15) {
325  dy_cut = 2;
326  } else if (theta < 20) {
327  dy_cut = 3;
328  } else if (theta < 25) {
329  dy_cut = 3;
330  } else if (theta < 30) {
331  dy_cut = 3;
332  } else if (theta < 35) {
333  dy_cut = 3;
334  } else {
335  dy_cut = 0.;
336  }
337  if (TMath::Abs(dy) > dy_cut) continue;
338  // Fill histogramms
339  if (stsTrackM->GetMCTrackId() == trdTrackM->GetMCTrackId()) {
340  fh_dtx_true->Fill(dtx, theta);
341  } else {
342  fh_dtx_false->Fill(dtx, theta);
343  }
344 
345  // Cut on dtx
346  if (theta < 10) {
347  dtx_cut = 0.001;
348  } else if (theta < 15) {
349  dtx_cut = 0.002;
350  } else if (theta < 20) {
351  dtx_cut = 0.003;
352  } else if (theta < 25) {
353  dtx_cut = 0.004;
354  } else if (theta < 30) {
355  dtx_cut = 0.005;
356  } else if (theta < 35) {
357  dtx_cut = 0.013;
358  } else {
359  dtx_cut = 0.;
360  }
361  dtx_cut *= 10;
362  if (TMath::Abs(dtx) > dtx_cut) continue;
363  // Fill histogramms
364  if (stsTrackM->GetMCTrackId() == trdTrackM->GetMCTrackId()) {
365  fh_dty_true->Fill(dty, theta);
366  } else {
367  fh_dty_false->Fill(dty, theta);
368  }
369 
370  if (TMath::Abs(dty) > dtx_cut) continue;
371 
372  // Get chi2
373  chi2XY = GetChi2XY(
374  kfTrack, const_cast<FairTrackParam*>(trdTrack->GetParamFirst()));
375  // Choose the closest
376  if (chi2XY < minChi2XY) {
377  minChi2XY = chi2XY;
378  indexOfClosest = iTrdTrack;
379  }
380  }
381  if (indexOfClosest < 0) continue;
382  // Attach TRD track
383  glbTrack->SetTrdTrackIndex(indexOfClosest);
384  mapTrdTrackUsed[indexOfClosest] = kTRUE;
385  nMerged += 1;
386  }
387 
388  // Loop over free TRD tracks
389  for (Int_t iTrdTrack = 0; iTrdTrack < trdTracks->GetEntriesFast();
390  iTrdTrack++) {
391  // Skip if already merged
392  if (mapTrdTrackUsed[iTrdTrack]) continue;
393  // Create global track
394  new ((*glbTracks)[nGlb]) CbmGlobalTrack();
395  glbTrack = L1_DYNAMIC_CAST<CbmGlobalTrack*>(glbTracks->At(nGlb));
396  if (NULL == glbTrack) continue;
397  nGlb += 1;
398  // Set TRD track index
399  glbTrack->SetTrdTrackIndex(iTrdTrack);
400  }
401 
402  return nMerged;
403 }
404 // ------------------------------------------------------------------
405 
406 
407 // ------------------------------------------------------------------
409  FairTrackParam* trackParam) {
410  // Get the chi2 from track extrapolation to TRD track parameters
411  Double_t dx = kfTrack.GetTrack()[0] - trackParam->GetX();
412  Double_t dy = kfTrack.GetTrack()[1] - trackParam->GetY();
413  Double_t c0 = kfTrack.GetCovMatrix()[0] + trackParam->GetCovariance(0, 0);
414  Double_t c1 = kfTrack.GetCovMatrix()[1] + trackParam->GetCovariance(0, 1);
415  Double_t c2 = kfTrack.GetCovMatrix()[2] + trackParam->GetCovariance(1, 1);
416  Double_t chi2 = 0.5 * (dx * dx * c0 - 2 * dx * dy * c1 + dy * dy * c2)
417  / (c0 * c2 - c1 * c1);
418  // Double_t chi2 = TMath::Sqrt(dx*dx + dy*dy);
419  return chi2;
420 }
421 // ------------------------------------------------------------------
422 
423 
424 // ------------------------------------------------------------------
426  // Create control histogramms
427  fh_dx_true = new TH2F("h_dx_true", "", 200, -10., 10., 9, 0., 45.);
428  fh_dx_false = new TH2F("h_dx_false", "", 200, -10., 10., 9, 0., 45.);
429 
430  fh_dy_true = new TH2F("h_dy_true", "", 200, -10., 10., 9, 0., 45.);
431  fh_dy_false = new TH2F("h_dy_false", "", 200, -10., 10., 9, 0., 45.);
432 
433  fh_dtx_true = new TH2F("h_dtx_true", "", 200, -0.1, 0.1, 9, 0., 45.);
434  fh_dtx_false = new TH2F("h_dtx_false", "", 200, -0.1, 0.1, 9, 0., 45.);
435 
436  fh_dty_true = new TH2F("h_dty_true", "", 200, -0.1, 0.1, 9, 0., 45.);
437  fh_dty_false = new TH2F("h_dty_false", "", 200, -0.1, 0.1, 9, 0., 45.);
438 }
439 // ------------------------------------------------------------------
440 
441 
442 // ------------------------------------------------------------------
444  // Write control histogramms to the file
445  fh_dx_true->Write();
446  fh_dx_false->Write();
447  fh_dy_true->Write();
448  fh_dy_false->Write();
449 
450  fh_dtx_true->Write();
451  fh_dtx_false->Write();
452  fh_dty_true->Write();
453  fh_dty_false->Write();
454 }
455 // ------------------------------------------------------------------
456 
457 
CbmL1TrackMerger::GetChi2XY
Double_t GetChi2XY(CbmKFTrack &kfTrack, FairTrackParam *trackParam)
Definition: CbmL1TrackMerger.cxx:408
CbmL1TrackMerger::CbmL1TrackMerger
CbmL1TrackMerger()
Definition: CbmL1TrackMerger.cxx:42
CbmTrack::GetParamLast
const FairTrackParam * GetParamLast() const
Definition: CbmTrack.h:62
CbmL1TrackMerger::fh_dy_false
TH2F * fh_dy_false
Definition: CbmL1TrackMerger.h:29
CbmL1TrackMerger::fh_dx_false
TH2F * fh_dx_false
Definition: CbmL1TrackMerger.h:27
CbmGlobalTrack::SetTrdTrackIndex
void SetTrdTrackIndex(Int_t iTrd)
Definition: CbmGlobalTrack.h:55
rootMgr
static FairRootManager * rootMgr
Definition: CbmDeviceHitBuilderTof.cxx:72
CbmKFTrack::GetTrack
Double_t * GetTrack()
Is it electron.
Definition: CbmKFTrack.h:58
CbmL1TrackMerger::fh_dtx_true
TH2F * fh_dtx_true
Definition: CbmL1TrackMerger.h:30
CbmTrackMatch
Definition: CbmTrackMatch.h:18
CbmGlobalTrack.h
CbmTrackMerger::fVerbose
Int_t fVerbose
Definition: CbmTrackMerger.h:60
CbmTrackMatch.h
CbmL1TrackMerger::MergeSimple
Int_t MergeSimple(TClonesArray *stsTracks, TClonesArray *trdTracks, TClonesArray *glbTracks)
Definition: CbmL1TrackMerger.cxx:154
CbmL1TrackMerger::fh_dty_true
TH2F * fh_dty_true
Definition: CbmL1TrackMerger.h:32
CbmL1TrackMerger::fArrayStsTrackM
TClonesArray * fArrayStsTrackM
Definition: CbmL1TrackMerger.h:24
CbmL1TrackMerger
Definition: CbmL1TrackMerger.h:16
CbmL1Def.h
CbmL1TrackMerger::WriteHistogramms
void WriteHistogramms()
Definition: CbmL1TrackMerger.cxx:443
CbmL1TrackMerger::MergeImPlane
Int_t MergeImPlane(TClonesArray *stsTracks, TClonesArray *trdTracks, TClonesArray *glbTracks)
Definition: CbmL1TrackMerger.cxx:212
CbmStsTrack.h
Data class for STS tracks.
CbmGlobalTrack::SetStsTrackIndex
void SetStsTrackIndex(Int_t iSts)
Definition: CbmGlobalTrack.h:54
CbmKFTrack::GetCovMatrix
Double_t * GetCovMatrix()
array[6] of track parameters(x,y,tx,ty,qp,z)
Definition: CbmKFTrack.h:59
ClassImp
ClassImp(CbmL1TrackMerger)
CbmKFTrack.h
CbmTrack::GetPreviousTrackId
Int_t GetPreviousTrackId() const
Definition: CbmTrack.h:60
xMath::Pi
double Pi()
Definition: xMath.h:5
CbmTrack::GetParamFirst
const FairTrackParam * GetParamFirst() const
Definition: CbmTrack.h:61
CbmL1TrackMerger.h
CbmL1TrackMerger::fh_dy_true
TH2F * fh_dy_true
Definition: CbmL1TrackMerger.h:28
CbmTrdTrack
Definition: CbmTrdTrack.h:22
CbmL1TrackMerger::fh_dtx_false
TH2F * fh_dtx_false
Definition: CbmL1TrackMerger.h:31
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
CbmL1TrackMerger::fMethod
Int_t fMethod
Definition: CbmL1TrackMerger.h:22
CbmTrackMatch::GetMCTrackId
Int_t GetMCTrackId() const
Definition: CbmTrackMatch.h:44
CbmL1TrackMerger::fh_dx_true
TH2F * fh_dx_true
Definition: CbmL1TrackMerger.h:26
CbmTrdTrack.h
CbmStsTrack
Definition: CbmStsTrack.h:37
CbmKFTrack
Definition: CbmKFTrack.h:21
CbmL1TrackMerger::fh_dty_false
TH2F * fh_dty_false
Definition: CbmL1TrackMerger.h:33
CbmKFTrack::SetTrackParam
void SetTrackParam(const FairTrackParam &track)
Definition: CbmKFTrack.cxx:34
CbmL1TrackMerger::fArrayTrdTrackM
TClonesArray * fArrayTrdTrackM
Definition: CbmL1TrackMerger.h:25
CbmL1TrackMerger::CreateHistogramms
void CreateHistogramms()
Definition: CbmL1TrackMerger.cxx:425
CbmL1TrackMerger::~CbmL1TrackMerger
virtual ~CbmL1TrackMerger()
Definition: CbmL1TrackMerger.cxx:104
CbmL1TrackMerger::DoMerge
Int_t DoMerge(TClonesArray *stsTracks, TClonesArray *trdTracks, TClonesArray *glbTracks)
Definition: CbmL1TrackMerger.cxx:136
CbmL1TrackMerger::Init
void Init()
Definition: CbmL1TrackMerger.cxx:111
CbmKFTrackInterface::Extrapolate
Int_t Extrapolate(Double_t z, Double_t *QP0=0)
Access to i-th hit.
Definition: CbmKFTrackInterface.cxx:39