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