BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
CbmStsTrackFinderIdeal.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- CbmStsTrackFinderIdeal source file -----
3// ----- Created 01/02/05 by V. Friese -----
4// -------------------------------------------------------------------------
5
7
8#include "CbmStsHit.h"
9#include "CbmStsTrack.h"
10
11// CBM includes
12#include "BmnDetectorList.h"
13#include "CbmMCTrack.h"
14#include "FairMCPoint.h"
15#include "FairRootManager.h"
16
17// ROOT includes
18#include "TClonesArray.h"
19
20// C++ includes
21#include <iomanip>
22#include <iostream>
23#include <map>
24
25using std::cout;
26using std::endl;
27using std::left;
28using std::map;
29using std::setw;
30
31// ----- Default constructor -------------------------------------------
34 , fMCTrackArray(NULL)
35 , fMCPointArray(NULL)
36{
37 fVerbose = 1;
38 fName = "STSTrackFinderIdeal";
39}
40// -------------------------------------------------------------------------
41
42// ----- Standard constructor ------------------------------------------
45 , fMCTrackArray(NULL)
46 , fMCPointArray(NULL)
47{
48 fVerbose = verbose;
49 fName = "STSTrackFinderIdeal";
50}
51// -------------------------------------------------------------------------
52
53// ----- Destructor ----------------------------------------------------
55// -------------------------------------------------------------------------
56
57// ----- Public method Init --------------------------------------------
59{
60
61 // Get and check FairRootManager
62 FairRootManager* ioman = FairRootManager::Instance();
63 if (!ioman) {
64 cout << "-E- " << fName << "::Init: "
65 << "RootManager not instantised!" << endl;
66 return;
67 }
68
69 // Get MCTrack array
70 fMCTrackArray = (TClonesArray*)ioman->GetObject("MCTrack");
71 if (!fMCTrackArray) {
72 cout << "-E- " << fName << "::Init: No MCTrack array!" << endl;
73 return;
74 }
75
76 // Get MCPoint array
77 fMCPointArray = (TClonesArray*)ioman->GetObject("StsPoint");
78 if (!fMCPointArray) {
79 cout << "-E- " << fName << "::Init: No MCPoint array!" << endl;
80 return;
81 }
82}
83// -------------------------------------------------------------------------
84
85// ----- Public method DoFind ------------------------------------------
87{
88
89 Bool_t success = kTRUE;
90
91 // Check pointers
92 if (!fMCTrackArray) {
93 cout << "-E- " << fName << "::DoFind: "
94 << "MCTrack array missing! " << endl;
95 return -1;
96 }
97 if (!fMCPointArray) {
98 cout << "-E- " << fName << "::DoFind: "
99 << "MCPoint array missing! " << endl;
100 return -1;
101 }
102
103 if (!fStsHits) {
104 cout << "-E- " << fName << "::DoFind: "
105 << "Hit array missing! " << endl;
106 return -1;
107 }
108
109 if (!fTracks) {
110 cout << "-E- " << fName << "::DoFind: "
111 << "Track array missing! " << endl;
112 return -1;
113 }
114
115 // Initialise control counters
116 Int_t nNoMCTrack = 0;
117 Int_t nNoTrack = 0;
118 Int_t nNoStsPoint = 0;
119 Int_t nNoStsHit = 0;
120
121 // Create pointers to StsHit and StsPoint
122 CbmStsHit* pHit = NULL;
123 FairMCPoint* pMCpt = NULL;
124 CbmMCTrack* pMCtr = NULL;
125 CbmStsTrack* pTrck = NULL;
126
127 // Number of Sts hits
128 Int_t nHits = fStsHits->GetEntriesFast();
129 ;
130
131 // Declare some variables outside the loops
132 Int_t ptIndex = 0; // MCPoint index
133 Int_t mcTrackIndex = 0; // MCTrack index
134 Int_t trackIndex = 0; // StsTrack index
135
136 // Create STL map from MCtrack index to number of valid StsHits
137 map<Int_t, Int_t> hitMap;
138
139 // Loop over Sts hits
140 for (Int_t iHit = 0; iHit < nHits; iHit++) {
141 pHit = (CbmStsHit*)fStsHits->At(iHit);
142 if (!pHit)
143 continue;
144 ptIndex = pHit->GetRefIndex();
145 if (ptIndex < 0)
146 continue; // fake or background hit
147 pMCpt = (FairMCPoint*)(fMCPointArray->At(ptIndex));
148 if (!pMCpt)
149 continue;
150 mcTrackIndex = pMCpt->GetTrackID();
151 hitMap[mcTrackIndex]++;
152 }
153
154 // Create STL map from MCTrack index to StsTrack index
155 map<Int_t, Int_t> trackMap;
156
157 // Create StsTracks for reconstructable MCTracks
158 Int_t nMCacc = 0; // accepted MCTracks
159 Int_t nTracks = 0; // reconstructable MCTracks
160 Int_t nMCTracks = fMCTrackArray->GetEntriesFast();
161 for (Int_t iMCTrack = 0; iMCTrack < nMCTracks; iMCTrack++) {
162 pMCtr = (CbmMCTrack*)fMCTrackArray->At(iMCTrack);
163 if (!pMCtr)
164 continue;
165 if (pMCtr->GetNPoints(kGEM) < 3)
166 continue;
167 nMCacc++;
168 if (hitMap[iMCTrack] < 3)
169 continue;
170 new ((*fTracks)[nTracks]) CbmStsTrack();
171 if (fVerbose > 1)
172 cout << "-I- " << fName << ": StsTrack " << nTracks << " created from MCTrack " << iMCTrack << " ("
173 << pMCtr->GetNPoints(kGEM) << " StsPoints)" << endl;
174 trackMap[iMCTrack] = nTracks++;
175 }
176
177 if (fVerbose > 2)
178 cout << "-I- " << GetName() << ": " << endl;
179
180 // Loop over Sts hits. Get corresponding MCPoint and MCTrack index
181 for (Int_t iHit = 0; iHit < nHits; iHit++) {
182 pHit = (CbmStsHit*)fStsHits->At(iHit);
183 if (!pHit) {
184 cout << "-E- " << fName << "::DoFind: Empty slot "
185 << "in StsHitArray at position " << iHit << endl;
186 nNoStsHit++;
187 success = kFALSE;
188 continue;
189 }
190 ptIndex = pHit->GetRefIndex();
191 if (ptIndex < 0)
192 continue; // fake or background hit
193 pMCpt = (FairMCPoint*)(fMCPointArray->At(ptIndex));
194 if (!pMCpt) {
195 cout << "-E- " << fName << "::DoFind: No reference "
196 << "MCPoint " << ptIndex << " for hit " << iHit << endl;
197 nNoStsPoint++;
198 success = kFALSE;
199 continue;
200 }
201 mcTrackIndex = pMCpt->GetTrackID();
202 if (mcTrackIndex < 0 || mcTrackIndex > nMCTracks) {
203 cout << "-E- " << fName << "::DoFind: "
204 << "MCTrack index out of range. " << mcTrackIndex << " " << nMCTracks << endl;
205 nNoMCTrack++;
206 success = kFALSE;
207 continue;
208 }
209 if (trackMap.find(mcTrackIndex) == trackMap.end())
210 continue;
211 trackIndex = trackMap[mcTrackIndex];
212 pTrck = (CbmStsTrack*)fTracks->At(trackIndex);
213 if (!pTrck) {
214 cout << "-E- " << fName << "::DoFind: "
215 << "No StsTrack pointer. " << iHit << " " << ptIndex << " " << mcTrackIndex << " " << trackIndex
216 << endl;
217 nNoTrack++;
218 success = kFALSE;
219 continue;
220 }
221 pTrck->AddStsHit(iHit, pHit);
222 if (fVerbose > 2)
223 cout << "Sts Hit " << iHit << " from StsPoint " << ptIndex << " (MCTrack " << mcTrackIndex
224 << ") added to StsTrack " << trackIndex << endl;
225 }
226
227 if (fVerbose) {
228 cout << endl;
229 cout << "-------------------------------------------------------" << endl;
230 cout << "-I- " << fName << endl;
231 cout << "Sts hits: " << nHits << endl;
232 cout << "MCTracks: total " << nMCTracks << ", accepted " << nMCacc << ", reconstructable: " << nTracks << endl;
233 if (nNoStsHit)
234 cout << "StsHits not found : " << nNoStsHit << endl;
235 if (nNoStsPoint)
236 cout << "StsPoints not found : " << nNoStsPoint << endl;
237 if (nNoMCTrack)
238 cout << "MCTracks not found : " << nNoMCTrack << endl;
239 if (nNoTrack)
240 cout << "StsTracks not found : " << nNoTrack << endl;
241 cout << "-------------------------------------------------------" << endl;
242 } else if (success)
243 cout << "+ ";
244 else
245 cout << "- ";
246 cout << setw(15) << left << fName << ": " << nMCTracks << ", acc. " << nMCacc << ", rec. " << nTracks << endl;
247
248 return nTracks;
249}
250// -------------------------------------------------------------------------
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
@ kGEM
CbmMCTrack.h.
Definition CbmMCTrack.h:26
Long64_t GetNPoints(DetectorId detId) const
Accessors to the number of MCPoints in the detectors.
virtual void Init()
Initialisation.
virtual Int_t DoFind()
Track finding algorithm This just reads MC truth (MCTracks and MCPoints), creates one StsTrack for ea...
CbmStsTrackFinderIdeal()
Default constructor.
TClonesArray * fMCTrackArray
Arrays of MC information.
virtual ~CbmStsTrackFinderIdeal()
Destructor.
TClonesArray * fTracks
CbmStsTrackFinder()
Default constructor.
TClonesArray * fStsHits
void AddStsHit(Int_t hitIndex, FairHit *hit)
Add a StsHit to the list.
const char * GetName() const override
TString fName
friend friend class TClonesArray