CbmRoot
Loading...
Searching...
No Matches
CbmTrackMergerIdeal.cxx
Go to the documentation of this file.
1/* Copyright (C) 2005-2012 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Denis Bertini [committer], Florian Uhlig */
4
5// -------------------------------------------------------------------------
6// ----- CbmTrackMergerIdeal source file -----
7// ----- Created 01/12/05 by V. Friese -----
8// -------------------------------------------------------------------------
10
11#include "CbmGlobalTrack.h"
12#include "CbmTrackMatch.h"
13#include "FairRootManager.h"
14#include "TClonesArray.h"
15
16#include <iostream>
17#include <map>
18
19using std::cout;
20using std::endl;
21using std::map;
22
23
24// ----- Default constructor -------------------------------------------
25CbmTrackMergerIdeal::CbmTrackMergerIdeal() : CbmTrackMerger(), fStsMatch(NULL), fTrdMatch(NULL) { fVerbose = 1; }
26// -------------------------------------------------------------------------
27
28
29// ----- Destructor ----------------------------------------------------
31// -------------------------------------------------------------------------
32
33
34// ----- Public method Init --------------------------------------------
36{
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 -----------------------------------------
64Int_t CbmTrackMergerIdeal::DoMerge(TClonesArray* stsTracks, TClonesArray* trdTracks, TClonesArray* glbTracks)
65{
66
67 // Check existence of output array
68 if (!glbTracks) {
69 cout << "-E- CbmTrackMergerIdel::DoMerge: "
70 << "No GlobalTrack array!" << endl;
71 return 0;
72 }
73
74 // Create some variables outside loops
75 Int_t nMerged = 0;
76 Int_t nGlb = 0;
77 Int_t nSts = 0;
78 Int_t nTrd = 0;
79 Int_t iMC = 0;
80 CbmTrackMatch* stsMatch = NULL;
81 CbmTrackMatch* trdMatch = NULL;
82
83 // Create map from TrdTrack index to StsTrack index
84 map<Int_t, Int_t> trdStsMap;
85
86 // Create map from MCTrack index tp TrdTrack index
87 map<Int_t, Int_t> mcTrdMap;
88
89 // Determine number of StsTracks and StsTrackMatches
90 if (stsTracks && fStsMatch) {
91 nSts = stsTracks->GetEntriesFast();
92 if (nSts != fStsMatch->GetEntriesFast()) {
93 cout << "-E- CbmTrackMergerIdeal::DoMerge: "
94 << "Unequal array sizes of StsTrack and StsTrackMatch! (" << nSts << ", " << fStsMatch->GetEntriesFast()
95 << endl;
96 nSts = 0;
97 }
98 }
99
100 // Determine number of TrdTracks and TrdTrackMatches
101 if (trdTracks && fTrdMatch) {
102 nTrd = trdTracks->GetEntriesFast();
103 if (nTrd != fTrdMatch->GetEntriesFast()) {
104 cout << "-E- CbmTrackMergerIdeal::DoMerge: "
105 << "Unequal array sizes of TrdTrack and TrdTrackMatch! (" << nTrd << ", " << fTrdMatch->GetEntriesFast()
106 << endl;
107 nTrd = 0;
108 }
109 }
110
111 if (fVerbose > 1)
112 cout << endl << "-I- CbmTrackMergerIdeal: " << nSts << " StsTracks, " << nTrd << " TrdTracks" << endl;
113
114 // Loop over TrdTracks and fill map to MCTrack index
115 for (Int_t iTrd = 0; iTrd < nTrd; iTrd++) {
116 trdMatch = (CbmTrackMatch*) fTrdMatch->At(iTrd);
117 iMC = trdMatch->GetMCTrackId();
118 if (!trdMatch) {
119 cout << "-W- CbmTrackMergerIdeal::DoMerge: "
120 << "Empty TrdTrackMatch at position " << iTrd << endl;
121 continue;
122 }
123 if (mcTrdMap.find(iMC) != mcTrdMap.end()) {
124 cout << "-W- CbmTrackMergerIdeal::DoMerge: "
125 << "MCTrack " << iMC << " matched to TrdTrack " << mcTrdMap[iMC] << " and " << iTrd << endl;
126 continue;
127 }
128 mcTrdMap[iMC] = iTrd;
129 }
130
131 // Loop over STS tracks, create Global track and attach TrdTrack
132 for (Int_t iSts = 0; iSts < nSts; iSts++) {
133 stsMatch = (CbmTrackMatch*) fStsMatch->At(iSts);
134 if (!stsMatch) {
135 cout << "-W- CbmTrackMergerIdeal::DoMerge: "
136 << "Empty StsTrackMatch at position " << iSts << endl;
137 continue;
138 }
139 CbmGlobalTrack* gTrack = new ((*glbTracks)[nGlb++]) CbmGlobalTrack();
140 gTrack->SetStsTrackIndex(iSts);
141 iMC = stsMatch->GetMCTrackId();
142 if (mcTrdMap.find(iMC) != mcTrdMap.end()) {
143 gTrack->SetTrdTrackIndex(mcTrdMap[iMC]);
144 trdStsMap[mcTrdMap[iMC]] = iSts;
145 nMerged++;
146 }
147 }
148 if (fVerbose > 1) {
149 cout << "-I- CbmTrackMergerIdeal: " << nGlb << " GlobalTracks created from StsTracks" << endl;
150 cout << "-I- CbmTrackMergerIdeal: " << nMerged << " StsTracks merged with TrdTracks" << endl;
151 }
152
153 // Loop over TRD tracks and create GlobalTracks for those not used
154 Int_t nTrdOnly = 0;
155 for (Int_t iTrd = 0; iTrd < nTrd; iTrd++) {
156 if (trdStsMap.find(iTrd) == trdStsMap.end()) {
157 CbmGlobalTrack* gTrack = new ((*glbTracks)[nGlb++]) CbmGlobalTrack();
158 gTrack->SetTrdTrackIndex(iTrd);
159 nTrdOnly++;
160 }
161 }
162 if (fVerbose > 1) {
163 cout << "-I- CbmTrackMergerIdeal: " << nTrdOnly << " GlobalTracks created from TrdTracks" << endl;
164 cout << "-I- CbmTrackMergerIdeal: Total " << nGlb << " GlobalTracks created" << endl;
165 }
166
167
168 return nMerged;
169}
170// -------------------------------------------------------------------------
int Int_t
void SetTrdTrackIndex(int32_t iTrd)
void SetStsTrackIndex(int32_t iSts)
int32_t GetMCTrackId() const
virtual Int_t DoMerge(TClonesArray *stsTracks, TClonesArray *trdTracks, TClonesArray *glbTracks)