CbmRoot
CbmTrackMergerIdeal.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmTrackMergerIdeal source file -----
3 // ----- Created 01/12/05 by V. Friese -----
4 // -------------------------------------------------------------------------
5 #include "CbmTrackMergerIdeal.h"
6 
7 #include "CbmGlobalTrack.h"
8 
9 #include "CbmTrackMatch.h"
10 #include "FairRootManager.h"
11 
12 #include "TClonesArray.h"
13 
14 #include <iostream>
15 #include <map>
16 
17 using std::cout;
18 using std::endl;
19 using std::map;
20 
21 
22 // ----- Default constructor -------------------------------------------
24  : CbmTrackMerger(), fStsMatch(NULL), fTrdMatch(NULL) {
25  fVerbose = 1;
26 }
27 // -------------------------------------------------------------------------
28 
29 
30 // ----- Destructor ----------------------------------------------------
32 // -------------------------------------------------------------------------
33 
34 
35 // ----- Public method Init --------------------------------------------
37 
38  // Get and check FairRootManager
39  FairRootManager* ioman = FairRootManager::Instance();
40  if (!ioman) {
41  cout << "-E- CbmStsTrackFinderIdeal::Init: "
42  << "RootManager not instantised!" << endl;
43  return;
44  }
45 
46  // Get StsTrackMatch array
47  fStsMatch = (TClonesArray*) ioman->GetObject("StsTrackMatch");
48  if (!fStsMatch) {
49  cout << "-W- CbmTrackMergerIdeal::Init: "
50  << "No StsTrackMatch array!" << endl;
51  }
52 
53  // Get TrdTrackMatch array
54  fTrdMatch = (TClonesArray*) ioman->GetObject("TrdTrackMatch");
55  if (!fTrdMatch) {
56  cout << "-W- CbmTrackMergerIdeal::Init: "
57  << "No TrdTrackMatch array!" << endl;
58  }
59 }
60 // -------------------------------------------------------------------------
61 
62 
63 // ----- Public method DoMerge -----------------------------------------
64 Int_t CbmTrackMergerIdeal::DoMerge(TClonesArray* stsTracks,
65  TClonesArray* trdTracks,
66  TClonesArray* glbTracks) {
67 
68  // Check existence of output array
69  if (!glbTracks) {
70  cout << "-E- CbmTrackMergerIdel::DoMerge: "
71  << "No GlobalTrack array!" << endl;
72  return 0;
73  }
74 
75  // Create some variables outside loops
76  Int_t nMerged = 0;
77  Int_t nGlb = 0;
78  Int_t nSts = 0;
79  Int_t nTrd = 0;
80  Int_t iMC = 0;
81  CbmTrackMatch* stsMatch = NULL;
82  CbmTrackMatch* trdMatch = NULL;
83 
84  // Create map from TrdTrack index to StsTrack index
85  map<Int_t, Int_t> trdStsMap;
86 
87  // Create map from MCTrack index tp TrdTrack index
88  map<Int_t, Int_t> mcTrdMap;
89 
90  // Determine number of StsTracks and StsTrackMatches
91  if (stsTracks && fStsMatch) {
92  nSts = stsTracks->GetEntriesFast();
93  if (nSts != fStsMatch->GetEntriesFast()) {
94  cout << "-E- CbmTrackMergerIdeal::DoMerge: "
95  << "Unequal array sizes of StsTrack and StsTrackMatch! (" << nSts
96  << ", " << fStsMatch->GetEntriesFast() << endl;
97  nSts = 0;
98  }
99  }
100 
101  // Determine number of TrdTracks and TrdTrackMatches
102  if (trdTracks && fTrdMatch) {
103  nTrd = trdTracks->GetEntriesFast();
104  if (nTrd != fTrdMatch->GetEntriesFast()) {
105  cout << "-E- CbmTrackMergerIdeal::DoMerge: "
106  << "Unequal array sizes of TrdTrack and TrdTrackMatch! (" << nTrd
107  << ", " << fTrdMatch->GetEntriesFast() << endl;
108  nTrd = 0;
109  }
110  }
111 
112  if (fVerbose > 1)
113  cout << endl
114  << "-I- CbmTrackMergerIdeal: " << nSts << " StsTracks, " << nTrd
115  << " TrdTracks" << endl;
116 
117  // Loop over TrdTracks and fill map to MCTrack index
118  for (Int_t iTrd = 0; iTrd < nTrd; iTrd++) {
119  trdMatch = (CbmTrackMatch*) fTrdMatch->At(iTrd);
120  iMC = trdMatch->GetMCTrackId();
121  if (!trdMatch) {
122  cout << "-W- CbmTrackMergerIdeal::DoMerge: "
123  << "Empty TrdTrackMatch at position " << iTrd << endl;
124  continue;
125  }
126  if (mcTrdMap.find(iMC) != mcTrdMap.end()) {
127  cout << "-W- CbmTrackMergerIdeal::DoMerge: "
128  << "MCTrack " << iMC << " matched to TrdTrack " << mcTrdMap[iMC]
129  << " and " << iTrd << endl;
130  continue;
131  }
132  mcTrdMap[iMC] = iTrd;
133  }
134 
135  // Loop over STS tracks, create Global track and attach TrdTrack
136  for (Int_t iSts = 0; iSts < nSts; iSts++) {
137  stsMatch = (CbmTrackMatch*) fStsMatch->At(iSts);
138  if (!stsMatch) {
139  cout << "-W- CbmTrackMergerIdeal::DoMerge: "
140  << "Empty StsTrackMatch at position " << iSts << endl;
141  continue;
142  }
143  CbmGlobalTrack* gTrack = new ((*glbTracks)[nGlb++]) CbmGlobalTrack();
144  gTrack->SetStsTrackIndex(iSts);
145  iMC = stsMatch->GetMCTrackId();
146  if (mcTrdMap.find(iMC) != mcTrdMap.end()) {
147  gTrack->SetTrdTrackIndex(mcTrdMap[iMC]);
148  trdStsMap[mcTrdMap[iMC]] = iSts;
149  nMerged++;
150  }
151  }
152  if (fVerbose > 1) {
153  cout << "-I- CbmTrackMergerIdeal: " << nGlb
154  << " GlobalTracks created from StsTracks" << endl;
155  cout << "-I- CbmTrackMergerIdeal: " << nMerged
156  << " StsTracks merged with TrdTracks" << endl;
157  }
158 
159  // Loop over TRD tracks and create GlobalTracks for those not used
160  Int_t nTrdOnly = 0;
161  for (Int_t iTrd = 0; iTrd < nTrd; iTrd++) {
162  if (trdStsMap.find(iTrd) == trdStsMap.end()) {
163  CbmGlobalTrack* gTrack = new ((*glbTracks)[nGlb++]) CbmGlobalTrack();
164  gTrack->SetTrdTrackIndex(iTrd);
165  nTrdOnly++;
166  }
167  }
168  if (fVerbose > 1) {
169  cout << "-I- CbmTrackMergerIdeal: " << nTrdOnly
170  << " GlobalTracks created from TrdTracks" << endl;
171  cout << "-I- CbmTrackMergerIdeal: Total " << nGlb << " GlobalTracks created"
172  << endl;
173  }
174 
175 
176  return nMerged;
177 }
178 // -------------------------------------------------------------------------
CbmTrackMergerIdeal::fTrdMatch
TClonesArray * fTrdMatch
Definition: CbmTrackMergerIdeal.h:49
CbmGlobalTrack::SetTrdTrackIndex
void SetTrdTrackIndex(Int_t iTrd)
Definition: CbmGlobalTrack.h:55
CbmTrackMatch
Definition: CbmTrackMatch.h:18
CbmGlobalTrack.h
CbmTrackMergerIdeal::CbmTrackMergerIdeal
CbmTrackMergerIdeal()
Definition: CbmTrackMergerIdeal.cxx:23
CbmTrackMerger::fVerbose
Int_t fVerbose
Definition: CbmTrackMerger.h:60
CbmTrackMergerIdeal::fStsMatch
TClonesArray * fStsMatch
Definition: CbmTrackMergerIdeal.h:48
CbmTrackMatch.h
CbmTrackMergerIdeal::DoMerge
virtual Int_t DoMerge(TClonesArray *stsTracks, TClonesArray *trdTracks, TClonesArray *glbTracks)
Definition: CbmTrackMergerIdeal.cxx:64
CbmGlobalTrack::SetStsTrackIndex
void SetStsTrackIndex(Int_t iSts)
Definition: CbmGlobalTrack.h:54
CbmTrackMergerIdeal::~CbmTrackMergerIdeal
virtual ~CbmTrackMergerIdeal()
Definition: CbmTrackMergerIdeal.cxx:31
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
CbmTrackMergerIdeal.h
CbmTrackMatch::GetMCTrackId
Int_t GetMCTrackId() const
Definition: CbmTrackMatch.h:44
CbmTrackMergerIdeal::Init
virtual void Init()
Definition: CbmTrackMergerIdeal.cxx:36
CbmTrackMerger
Definition: CbmTrackMerger.h:25