12#include "TClonesArray.h"
13#include "FairLogger.h"
14#include "CbmMCTrack.h"
16#include "CbmStsPoint.h"
18using std::stringstream;
22using std::setprecision;
27Int_t CbmStsAcceptance::fNofInstances = 0;
28map<Int_t, map<Int_t, Int_t>>CbmStsAcceptance::fCountMap =
29 map<Int_t, map<Int_t, Int_t>>();
34 : FairTask(
"CbmStsAcceptance"),
35 fPoints(NULL), fTracks(NULL), fTimer(), fNofEvents(0), fNofPointsTot(0), fTimeTot(0.)
40 if ( fNofInstances ) LOG(fatal) << GetName()
41 <<
": Instance of this class is already present! Aborting...";
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++) {
75 Int_t nPoints = fPoints->GetEntriesFast();
78 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++ ) {
79 point =
dynamic_cast<CbmStsPoint*
> (fPoints->At(iPoint));
83 Int_t trackId = point->GetTrackID();
84 Int_t address = point->GetDetectorID();
88 Int_t nCounts = fCountMap[trackId][stationNr];
89 fCountMap[trackId][stationNr] = ++nCounts;
93 if ( ! Test() ) LOG(fatal) << GetName() <<
": consistency check failed!";
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()
105 fNofPointsTot += nPoints;
106 fTimeTot += fTimer.RealTime();
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)
122 LOG(info) <<
"Real time per event : " << setprecision(6)
123 << fTimeTot / Double_t(fNofEvents)
125 LOG(info) <<
"=====================================";
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;
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;
168 if ( fCountMap.find(trackId) == fCountMap.end() )
return 0;
169 return fCountMap[trackId].size();
179 FairRootManager* ioman = FairRootManager::Instance();
183 fPoints = (TClonesArray*) ioman->GetObject(
"StsPoint");
185 LOG(error) << GetName()
186 <<
": No StsPoint array. Task will be deactivated."
193 fTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
195 LOG(error) << GetName()
196 <<
": No MCTrack array. Task will be deactivated."
209Bool_t CbmStsAcceptance::Test() {
211 Bool_t result = kTRUE;
217 Int_t nTracks = fTracks->GetEntriesFast();
218 for (Int_t trackId = 0; trackId < nTracks; trackId++) {
219 track =
dynamic_cast<CbmMCTrack*
>(fTracks->At(trackId));
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();
244 Int_t nEntries = fCountMap.size();
245 Int_t firstIndex = 0;
248 firstIndex = fCountMap.begin()->first;
249 lastIndex = fCountMap.rbegin()->first;
251 ss <<
"StsAcceptance: map size " << nEntries <<
" (from " << firstIndex
252 <<
" to " << lastIndex <<
" )" << std::endl;
Long64_t GetNPoints(DetectorId detId) const
static Int_t GetNofPoints(Int_t trackId)
static Int_t GetNofStations(Int_t trackId)
virtual void Exec(Option_t *opt)
virtual InitStatus Init()
virtual ~CbmStsAcceptance()
std::string ToString() const
static Int_t GetElementId(UInt_t address, Int_t level)