BmnRoot
Loading...
Searching...
No Matches
CbmStsAcceptance.cxx
Go to the documentation of this file.
1
6#include "CbmStsAcceptance.h"
7
8#include <cassert>
9#include <sstream>
10#include <iomanip>
11
12#include "TClonesArray.h"
13#include "FairLogger.h"
14#include "CbmMCTrack.h"
15#include "CbmStsAddress.h"
16#include "CbmStsPoint.h"
17
18using std::stringstream;
19using std::right;
20using std::setw;
21using std::fixed;
22using std::setprecision;
23using std::map;
24using std::string;
25
26// ----- Initialisation of static data members -----------------------------
27Int_t CbmStsAcceptance::fNofInstances = 0;
28map<Int_t, map<Int_t, Int_t>>CbmStsAcceptance::fCountMap =
29 map<Int_t, map<Int_t, Int_t>>();
30// --------------------------------------------------------------------------
31
32// ----- Constructor -----------------------------------------------------
34 : FairTask("CbmStsAcceptance"),
35 fPoints(NULL), fTracks(NULL), fTimer(), fNofEvents(0), fNofPointsTot(0), fTimeTot(0.)
36{
37
38 // TODO: This is a sloppy way of preventing more than one instance.
39 // Should be a real single ton class.
40 if ( fNofInstances ) LOG(fatal) << GetName()
41 << ": Instance of this class is already present! Aborting...";
42
43 fNofInstances++;
44}
45// --------------------------------------------------------------------------
46
47
48
49// ----- Destructor -----------------------------------------------------
52// --------------------------------------------------------------------------
53
54
55// ----- Clear the count map -------------------------------------------
56void CbmStsAcceptance::Clear(Option_t*) {
57 map<Int_t, map<Int_t, Int_t>>::iterator it1;
58 for (it1 = fCountMap.begin(); it1 != fCountMap.end(); it1++) {
59 it1->second.clear();
60 }
61}
62// --------------------------------------------------------------------------
63
64
65
66// ----- Task execution -------------------------------------------------
67void CbmStsAcceptance::Exec(Option_t* /*opt*/) {
68
69 fTimer.Start();
70
71 // Reset bookkeeping
72 Clear();
73
74 CbmStsPoint* point = NULL;
75 Int_t nPoints = fPoints->GetEntriesFast();
76
77 // Loop over points in array
78 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++ ) {
79 point = dynamic_cast<CbmStsPoint*> (fPoints->At(iPoint));
80 assert(point);
81
82 // Track index and station number
83 Int_t trackId = point->GetTrackID();
84 Int_t address = point->GetDetectorID();
85 Int_t stationNr = CbmStsAddress::GetElementId(address, kSts);
86
87 // Increment entry in count map
88 Int_t nCounts = fCountMap[trackId][stationNr];
89 fCountMap[trackId][stationNr] = ++nCounts;
90 } //# StsPoints
91
92 // Perform consistency check
93 if ( ! Test() ) LOG(fatal) << GetName() << ": consistency check failed!";
94
95 fTimer.Stop();
96 LOG(debug) << ToString();
97 LOG(info) << "+ " << setw(20) << GetName() << ": Event " << setw(6)
98 << right << fNofEvents << ", time " << fixed << setprecision(6)
99 << fTimer.RealTime() << " s, STS points: " << nPoints
100 << ", map size " << fCountMap.size()
101 << ", test OK";
102
103 // Counters
104 fNofEvents++;
105 fNofPointsTot += nPoints;
106 fTimeTot += fTimer.RealTime();
107
108}
109// --------------------------------------------------------------------------
110
111
112
113// ----- End-of-run action ----------------------------------------------
115 std::cout << std::endl;
116 LOG(info) << "=====================================";
117 LOG(info) << GetName() << ": Run summary";
118 LOG(info) << "Events processed : " << fNofEvents;
119 LOG(info) << "StsPoints / event : " << setprecision(1)
120 << fNofPointsTot / Double_t(fNofEvents)
121 ;
122 LOG(info) << "Real time per event : " << setprecision(6)
123 << fTimeTot / Double_t(fNofEvents)
124 << " s";
125 LOG(info) << "=====================================";
126}
127// --------------------------------------------------------------------------
128
129
130
131// ----- Total number of StsPoint objects -------------------------------
132Int_t CbmStsAcceptance::GetNofPoints(Int_t trackId) {
133
134 Int_t nPoints = 0;
135 map<Int_t, map<Int_t, Int_t>>::iterator it1 = fCountMap.find(trackId);
136 if ( it1 == fCountMap.end() ) return 0;
137 map<Int_t, Int_t>::iterator it2;
138 for (it2 = (it1->second).begin(); it2 != (it1->second).end(); it2++) {
139 nPoints += it2->second;
140 }
141
142 return nPoints;
143}
144// --------------------------------------------------------------------------
145
146
147
148// ----- Number of StsPoints in a given STS station ---------------------
149Int_t CbmStsAcceptance::GetNofPoints(Int_t trackId, Int_t stationNr) {
150
151 // Note: the implementation avoids automatic instantiation of
152 // entries in the outer and inner map as would be the case
153 // when using the index operator []. In that way, the size of the
154 // inner map always corresponds to the number of activated stations.
155 map<Int_t, map<Int_t, Int_t>>::iterator it1 = fCountMap.find(trackId);
156 if ( it1 == fCountMap.end() ) return 0;
157 map<Int_t, Int_t>::iterator it2 = (it1->second).find(stationNr);
158 if ( it2 == (it1->second).end() ) return 0;
159 return it2->second;
160
161}
162// --------------------------------------------------------------------------
163
164
165
166// ----- Number of STS stations the track is registered in --------------
168 if ( fCountMap.find(trackId) == fCountMap.end() ) return 0;
169 return fCountMap[trackId].size();
170}
171// --------------------------------------------------------------------------
172
173
174
175// ----- Task initialisation ---------------------------------------------
177
178 // --- Get IO-Manager
179 FairRootManager* ioman = FairRootManager::Instance();
180 assert (ioman);
181
182 // --- Get input array (StsPoint)
183 fPoints = (TClonesArray*) ioman->GetObject("StsPoint");
184 if ( ! fPoints ) {
185 LOG(error) << GetName()
186 << ": No StsPoint array. Task will be deactivated."
187 ;
188 SetActive(kFALSE);
189 return kERROR;
190 }
191
192 // --- Get input array (MCTrack)
193 fTracks = (TClonesArray*) ioman->GetObject("MCTrack");
194 if ( ! fTracks ) {
195 LOG(error) << GetName()
196 << ": No MCTrack array. Task will be deactivated."
197 ;
198 SetActive(kFALSE);
199 return kERROR;
200 }
201
202 return kSUCCESS;
203}
204// --------------------------------------------------------------------------
205
206
207
208// ----- Test internal consistency --------------------------------------
209Bool_t CbmStsAcceptance::Test() {
210
211 Bool_t result = kTRUE;
212
213 // Loop over MCTracks
214 CbmMCTrack* track = 0;
215 Int_t nPoints1 = 0;
216 Int_t nPoints2 = 0;
217 Int_t nTracks = fTracks->GetEntriesFast();
218 for (Int_t trackId = 0; trackId < nTracks; trackId++) {
219 track = dynamic_cast<CbmMCTrack*>(fTracks->At(trackId));
220 assert (track);
221 nPoints1 = track->GetNPoints(kSts);
222 nPoints2 = GetNofPoints(trackId);
223 // The value of 31 is the maximal number that can be stored in CbmMCTrack
224 // for the count of StsPoints. Sometimes there are more (spiralling electrons).
225 if ( nPoints1 != nPoints2 && nPoints1 < 31) {
226 LOG(error) << GetName() << ": Track " << trackId
227 << " points from MCTrack " << nPoints1
228 << ", points from StsAcceptance " << nPoints2;
229 LOG(error) << track->ToString();
230 result = kFALSE;
231 }
232 } //# MCTracks
233
234 return result;
235}
236// --------------------------------------------------------------------------
237
238
239
240// ----- Status info ----------------------------------------------------
242{
243 stringstream ss;
244 Int_t nEntries = fCountMap.size();
245 Int_t firstIndex = 0;
246 Int_t lastIndex = 0;
247 if ( nEntries ) {
248 firstIndex = fCountMap.begin()->first;
249 lastIndex = fCountMap.rbegin()->first;
250 }
251 ss << "StsAcceptance: map size " << nEntries << " (from " << firstIndex
252 << " to " << lastIndex << " )" << std::endl;
253 return ss.str();
254}
255// -------------------------------------------------------------------------
Long64_t GetNPoints(DetectorId detId) const
static Int_t GetNofPoints(Int_t trackId)
static Int_t GetNofStations(Int_t trackId)
virtual void Finish()
virtual void Exec(Option_t *opt)
virtual InitStatus Init()
std::string ToString() const
static Int_t GetElementId(UInt_t address, Int_t level)