CbmRoot
Loading...
Searching...
No Matches
CbmFindPrimaryVertex.cxx
Go to the documentation of this file.
1/* Copyright (C) 2005-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Denis Bertini [committer], Florian Uhlig */
4
5// -------------------------------------------------------------------------
6// ----- CbmFindPrimaryVertex source file -----
7// ----- Created 28/11/05 by V. Friese -----
8// -------------------------------------------------------------------------
10
11#include "CbmDefs.h"
12#include "CbmEvent.h"
14#include "CbmVertex.h"
15#include "FairRootManager.h"
16#include "TClonesArray.h"
17
18#include <Logger.h>
19
20#include <iomanip>
21#include <iostream>
22
23using namespace std;
24
25// ----- Default constructor -------------------------------------------
27 : FairTask()
28 , fTimer()
29 , fFinder(nullptr)
30 , fTracks(nullptr)
31 , fPrimVert(nullptr)
32 , fNofEvents(0)
33 , fTimeTot(0.)
34{
35 fName = "FindPrimaryVertex";
36}
37// -------------------------------------------------------------------------
38
39
40// ----- Standard constructor ------------------------------------------
42 : FairTask()
43 , fTimer()
44 , fFinder(pvFinder)
45 , fTracks(nullptr)
46 , fPrimVert(nullptr)
47 , fNofEvents(0)
48 , fTimeTot(0.)
49{
50 fName = "FindPrimaryVertex";
51}
52// -------------------------------------------------------------------------
53
54
55// ----- Constructor with name and title ---------------------------------
57 : FairTask(name)
58 , fTimer()
59 , fFinder(finder)
60 , fTracks(nullptr)
61 , fPrimVert(nullptr)
62 , fNofEvents(0)
63 , fTimeTot(0.)
64{
65}
66// -------------------------------------------------------------------------
67
68
69// ----- Destructor ----------------------------------------------------
71// -------------------------------------------------------------------------
72
73
74// ----- Public method Init --------------------------------------------
76{
77
78 // Check for vertex finder
79 if (!fFinder) {
80 cout << "-E- CbmFindPrimaryVertex::Init : "
81 << "No vertex finder selected! " << endl;
82 return kERROR;
83 }
84
85 // Get FairRootManager
86 FairRootManager* ioman = FairRootManager::Instance();
87 if (!ioman) {
88 cout << "-E- CbmFindPrimaryVertex::Init: "
89 << "RootManager not instantised!" << endl;
90 return kFATAL;
91 }
92
93 // Get CbmStsTrack or CbmGlobalTrack array
94 fTracks = (TClonesArray*) ioman->GetObject((ECbmDataType::kGlobalTrack == fTrackType) ? "GlobalTrack" : "StsTrack");
95 if (!fTracks) {
96 cout << "-W- CbmFindPrimaryVertex::Init: No STSTrack array!" << endl;
97 return kERROR;
98 }
99
100 // Get CbmEvent array
101 fEvents = dynamic_cast<TClonesArray*>(ioman->GetObject("Event"));
102 if (fEvents)
103 LOG(info) << GetName() << ": Found Event branch; run event-by-event";
104 else {
105 fEvents = dynamic_cast<TClonesArray*>(ioman->GetObject("CbmEvent"));
106 if (fEvents)
107 LOG(info) << GetName() << ": Found CbmEvent branch; run event-by-event";
108 else {
109 LOG(info) << GetName() << ": No event branch found! Run in time-based mode.";
110 LOG(warning) << GetName() << "*** The primary vertex finder is not designed to find mutiple vertices.";
111 LOG(warning) << GetName() << "*** Running it on an entire time slice will not produce sensible results.";
112 }
113 }
114
115 // Create and register CbmVertex object
116 // if (!fEvents) {
117 // TODO: This is here for legacy, since many analysis tasks use the vertex branch instead
118 // of retrieving the vertex from the event object. It shall be removed after the all analysis tasks
119 // are adjusted. Neither in event-based nor in time-based reconstruction a branch with a single
120 // vertex object makes sense.
121 fPrimVert = new CbmVertex("Primary Vertex", "Global");
122 ioman->Register("PrimaryVertex.", "Global", fPrimVert, IsOutputBranchPersistent("PrimaryVertex"));
123 // }
124
125 // Call the Init method of the vertex finder
126 fFinder->Init();
127
128 return kSUCCESS;
129}
130// -------------------------------------------------------------------------
131
132
133// ----- Public method Exec --------------------------------------------
135{
136
137 // Timer
138 TStopwatch timer;
139 timer.Start();
140
141 // Local variables
142 Int_t nEvents = 0;
143 Int_t nTracks = fTracks->GetEntriesFast();
144 Int_t nTracksUsed = 0;
145 Int_t result = 0;
146
147 // Time-based mode: process entire track array
148 if (!fEvents) {
149 fPrimVert->Reset();
151 }
152
153 // Event-based mode
154 else {
155 fPrimVert->Reset(); // TODO: Legacy
156 nEvents = fEvents->GetEntriesFast();
157 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
158 CbmEvent* event = dynamic_cast<CbmEvent*>(fEvents->At(iEvent));
159 assert(event);
160 result = fFinder->FindEventVertex(event, fTracks);
161 LOG(debug) << GetName() << ": Event " << iEvent << " " << event->GetVertex()->ToString();
162 nTracksUsed += result;
163
164 // Legacy: copy event vertex object to event branch
165 if (iEvent == 0) *fPrimVert = *(event->GetVertex());
166 }
167 }
168
169 // Log to screen
170 timer.Stop();
171 stringstream logOut;
172 logOut << setw(20) << left << GetName() << " [";
173 logOut << fixed << setw(8) << setprecision(1) << right << timer.RealTime() * 1000. << " ms] ";
174 logOut << "TS " << fNofTs;
175 if (fEvents) logOut << ", events " << nEvents;
176 logOut << ", tracks used " << nTracksUsed << " / " << nTracks;
177 LOG(info) << logOut.str();
178
179 // Counters
180 fNofTs++;
181 fNofEvents += nEvents;
182 fNofTracks += nTracks;
183 fNofTracksUsed += nTracksUsed;
184 fTimeTot += timer.RealTime();
185}
186// -------------------------------------------------------------------------
187
188
189// ----- Public method Finish ------------------------------------------
191{
192
193 std::cout << std::endl;
194 LOG(info) << "=====================================";
195 LOG(info) << GetName() << ": Run summary";
196 LOG(info) << "Time slices : " << fNofTs;
197 LOG(info) << "Tracks/ TS : " << fixed << setprecision(2) << fNofTracks / Double_t(fNofTs);
198 LOG(info) << "Used Tracks / TS : " << fixed << setprecision(2) << fNofTracksUsed / Double_t(fNofTs);
199 LOG(info) << "Time / TS : " << fixed << setprecision(2) << 1000. * fTimeTot / Double_t(fNofTs) << " ms";
200 if (fEvents) {
201 LOG(info) << "Events : " << fNofEvents;
202 LOG(info) << "Events / TS : " << fixed << setprecision(2) << Double_t(fNofEvents) / Double_t(fNofTs);
203 LOG(info) << "Tracks / event : " << fixed << setprecision(2) << Double_t(fNofTracks) / Double_t(fNofEvents);
204 LOG(info) << "Used tracks / event : " << fixed << setprecision(2)
205 << Double_t(fNofTracksUsed) / Double_t(fNofEvents);
206 }
207 LOG(info) << "=====================================";
208}
209// -------------------------------------------------------------------------
210
211
ClassImp(CbmConverterManager)
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
virtual void Exec(Option_t *opt)
Double_t fNofTracks
Number of input tracks.
CbmPrimaryVertexFinder * fFinder
virtual InitStatus Init()
Int_t fNofEvents
Number of processed events.
Double_t fNofTracksUsed
Number of tracks used for vertex finding.
Int_t fNofTs
Number of processed timeslices.
Double_t fTimeTot
Total execution time [s].
virtual Int_t FindEventVertex(CbmEvent *event, TClonesArray *tracks)=0
virtual Int_t FindPrimaryVertex(TClonesArray *tracks, CbmVertex *vertex)=0
void Reset()
Hash for CbmL1LinkKey.