CbmRoot
Loading...
Searching...
No Matches
CbmStsFindTracksEvents.cxx
Go to the documentation of this file.
1/* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
12// Includes from STS
14
15#include "CbmEvent.h"
16#include "CbmStsHit.h"
17#include "CbmStsTrack.h"
19
20#include <cassert>
21
22// Includes from base
23#include "FairField.h"
24#include "FairRootManager.h"
25#include "FairRunAna.h"
26#include "FairRuntimeDb.h"
27
28#include <Logger.h>
29
30// Includes from ROOT
31#include "TClonesArray.h"
32
33// Includes from C++
34#include <iomanip>
35#include <iostream>
36
37using std::cout;
38using std::endl;
39using std::fixed;
40using std::left;
41using std::pair;
42using std::right;
43using std::setprecision;
44using std::setw;
45using std::stringstream;
46
47// ----- Standard constructor ------------------------------------------
49 : FairTask("StsFindTracksEvents")
50 , fUseMvd(useMvd)
51 , fFinder(finder)
52 , fEvents(NULL)
53 , fMvdHits(NULL)
54 , fStsHits(NULL)
55 , fTracks(NULL)
56 , fTimer()
57 , fNofEvents(0)
58 , fNofHits(0.)
59 , fNofTracks(0.)
60 , fTime(0.)
61{
62 if (!finder) fFinder = new CbmStsTrackFinderIdeal();
63}
64// -------------------------------------------------------------------------
65
66
67// ----- Destructor ----------------------------------------------------
73// -------------------------------------------------------------------------
74
75
76// ----- Task execution ------------------------------------------------
77void CbmStsFindTracksEvents::Exec(Option_t* /*opt*/)
78{
79
80 // --- Local variables
81 Long64_t nEvents = 0;
82 Long64_t nHits = 0;
83 Long64_t nTracks = 0;
84 pair<UInt_t, UInt_t> result;
85 TStopwatch timer;
86 timer.Start();
87
88 // --- Clear output array
89 fTracks->Delete();
90
91 // --- Event loop (from event objects)
92 if (fEvents) {
93 nEvents = fEvents->GetEntriesFast();
94 LOG(debug) << GetName() << ": reading time slice with " << nEvents << " events ";
95 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
96 CbmEvent* event = static_cast<CbmEvent*>(fEvents->At(iEvent));
97 result = ProcessEvent(event);
98 nHits += result.first;
99 nTracks += result.second;
100 } //# events
101 } //? event branch present
102
103 else { // Timeslice reconstruction without events
104 result = ProcessEvent(nullptr);
105 nHits = result.first;
106 nTracks = result.second;
107 }
108
109 // --- Timeslice log and statistics
110 timer.Stop();
111 stringstream logOut;
112 logOut << setw(20) << left << GetName() << " [";
113 logOut << fixed << setw(8) << setprecision(1) << right << timer.RealTime() * 1000. << " ms] ";
114 logOut << "TS " << fNofTs;
115 if (fEvents) logOut << ", events " << nEvents;
116 logOut << ", hits " << nHits << ", tracks " << nTracks;
117 LOG(info) << logOut.str();
118 fNofTs++;
119 fNofEvents += nEvents;
120 fNofHits += nHits;
121 fNofTracks += nTracks;
122 fTime += timer.RealTime();
123}
124// -------------------------------------------------------------------------
125
126
127// ----- Initialisation ------------------------------------------------
129{
130
131 LOG(info) << "=====================================";
132 LOG(info) << GetName() << ": initialising";
133
134 // I/O manager
135 FairRootManager* ioman = FairRootManager::Instance();
136 assert(ioman);
137
138 // --- Get input array (Events)
139 fEvents = dynamic_cast<TClonesArray*>(ioman->GetObject("CbmEvent"));
140 if (nullptr == fEvents) {
141 LOG(warn) << GetName() << ": No event array! Will process entire tree.";
142 }
143
144 // --- Get input array (StsHits)
145 fStsHits = (TClonesArray*) ioman->GetObject("StsHit");
146 assert(fStsHits);
147
148 // Array of MvdHits
149 if (fUseMvd) {
150 fMvdHits = (TClonesArray*) ioman->GetObject("MvdHit");
151 if (fMvdHits == nullptr) {
152 LOG(error) << GetName() << ": Use of MVD hits selected, but no hit branch present! "
153 << "Tracking will be done without MVD hits.";
154 }
155 else
156 LOG(info) << GetName() << ": including MVD hits in tracking";
157 }
158
159 // Create and register output array for StsTracks
160 fTracks = new TClonesArray("CbmStsTrack", 100);
161 ioman->Register("StsTrack", "STS", fTracks, IsOutputBranchPersistent("StsTrack"));
162
163 // Check for Track finder
164 if (!fFinder) {
165 LOG(fatal) << GetName() << ": no track finding engine selected!";
166 return kERROR;
167 }
168 LOG(info) << GetName() << ": Use track finder " << fFinder->GetName();
169
170 // Set members of track finder and initialise it
174 fFinder->Init();
175
176 // Screen output
177 LOG(info) << GetName() << ": successfully initialised.";
178 LOG(info) << "=====================================\n";
179
180 return kSUCCESS;
181}
182// -------------------------------------------------------------------------
183
184
185// ----- End-of-run action ---------------------------------------------
187{
188 std::cout << std::endl;
189 LOG(info) << "=====================================";
190 LOG(info) << GetName() << ": Run summary";
191 LOG(info) << "Time slices : " << fNofTs;
192 LOG(info) << "Hits / TS : " << fixed << setprecision(2) << Double_t(fNofHits) / Double_t(fNofTs);
193 LOG(info) << "Tracks / TS : " << fixed << setprecision(2) << Double_t(fNofTracks) / Double_t(fNofTs);
194 LOG(info) << "Hits per track : " << fNofHits / fNofTracks;
195 LOG(info) << "Time per TS : " << 1000. * fTime / Double_t(fNofTs) << " ms ";
196 if (fEvents) {
197 LOG(info) << "Events processed : " << fNofEvents;
198 LOG(info) << "Hits / event : " << fNofHits / Double_t(fNofEvents);
199 LOG(info) << "Tracks / event : " << fNofTracks / Double_t(fNofEvents);
200 }
201 LOG(info) << "=====================================";
202}
203// -------------------------------------------------------------------------
204
205
206// ------ Process one event --------------------------------------------
208{
209
210 // --- Call track finder
211 fTimer.Start();
212 Int_t nTracks = fFinder->FindTracks(event);
214 fTimer.Stop();
215
216 // --- Event log
217 Int_t eventNumber = (event ? event->GetNumber() : fNofEvents);
218 Int_t nHits = (event ? event->GetNofData(ECbmDataType::kStsHit) : fStsHits->GetEntriesFast());
219 LOG(debug) << "+ " << setw(20) << GetName() << ": Event " << setw(6) << right << eventNumber << ", real time "
220 << fixed << setprecision(6) << fTimer.RealTime() << " s, hits: " << nHits << ", tracks: " << nTracks;
221
222 return std::make_pair(nHits, nTracks);
223}
224// -------------------------------------------------------------------------
225
226
ClassImp(CbmConverterManager)
Data class for a reconstructed hit in the STS.
Data class for STS tracks.
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
Task class for finding STS tracks in an event.
TClonesArray * fTracks
Input array of STS hits.
TClonesArray * fMvdHits
Array of CbmEvent objects.
virtual void Exec(Option_t *opt)
TClonesArray * fStsHits
Input array of MVD hits.
TStopwatch fTimer
Output array of CbmStsTracks.
std::pair< UInt_t, UInt_t > ProcessEvent(CbmEvent *event)
Process one event or timeslice.
Int_t fNofEvents
Number of events with success.
Double_t fNofTracks
Number of tracks created.
Double_t fTime
Total real time used for good events.
Double_t fNofHits
Number of hits.
CbmStsFindTracksEvents(CbmStsTrackFinder *finder=NULL, Bool_t useMvd=kFALSE)
MC-based track finding in the STS.
void SetMvdHitArray(TClonesArray *hits)
virtual void Init()
void SetTrackArray(TClonesArray *tracks)
virtual Int_t FindTracks(CbmEvent *event)=0
void FillEloss()
Calculate the median energy loss for the tracks and fill the respective data members.
void SetStsHitArray(TClonesArray *hits)