CbmRoot
CbmFindPrimaryVertexEvents.cxx
Go to the documentation of this file.
1 
8 
9 
10 #include "CbmEvent.h"
11 #include "CbmPrimaryVertexFinder.h"
12 #include "CbmVertex.h"
13 #include "FairLogger.h"
14 #include "FairRootManager.h"
15 #include "TClonesArray.h"
16 #include <cassert>
17 #include <iomanip>
18 #include <iostream>
19 
20 using namespace std;
21 
22 
23 // ----- Default constructor -------------------------------------------
25  : FairTask()
26  , fTimer()
27  , fFinder(NULL)
28  , fEvents(NULL)
29  , fTracks(NULL)
30  , fPrimVert(NULL)
31  , fNofEvents(0)
32  , fTimeTot(0.) {
33  fName = "FindPrimaryVertex";
34 }
35 // -------------------------------------------------------------------------
36 
37 
38 // ----- Standard constructor ------------------------------------------
40  CbmPrimaryVertexFinder* pvFinder)
41  : FairTask()
42  , fTimer()
43  , fFinder(pvFinder)
44  , fEvents(NULL)
45  , fTracks(NULL)
46  , fPrimVert(NULL)
47  , fNofEvents(0)
48  , fTimeTot(0.) {
49  fName = "FindPrimaryVertex";
50 }
51 // -------------------------------------------------------------------------
52 
53 
54 // ----- Constructor with name and title ---------------------------------
56  const char* name,
57  const char*,
58  CbmPrimaryVertexFinder* finder)
59  : FairTask(name)
60  , fTimer()
61  , fFinder(finder)
62  , fEvents(NULL)
63  , fTracks(NULL)
64  , fPrimVert(NULL)
65  , fNofEvents(0)
66  , fTimeTot(0.) {}
67 // -------------------------------------------------------------------------
68 
69 
70 // ----- Destructor ----------------------------------------------------
72 // -------------------------------------------------------------------------
73 
74 
75 // ----- Initialisation --------------------------------------------------
77 
78  assert(fFinder);
79 
80  // Get FairRootManager
81  FairRootManager* ioman = FairRootManager::Instance();
82  assert(ioman);
83 
84  // Get event array
85  fEvents = (TClonesArray*) ioman->GetObject("Event");
86  assert(fEvents);
87 
88  // Get CbmStsTrack array
89  fTracks = (TClonesArray*) ioman->GetObject("StsTrack");
90  assert(fTracks);
91 
92  // Create and register CbmVertex object
93  fPrimVert = new CbmVertex("Primary Vertex", "Global");
94  ioman->Register("PrimaryVertex.",
95  "Global",
96  fPrimVert,
97  IsOutputBranchPersistent("PrimaryVertex"));
98 
99 
100  // Initialise vertex finder
101  fFinder->Init();
102 
103  return kSUCCESS;
104 }
105 // -------------------------------------------------------------------------
106 
107 
108 // ----- Task execution ------------------------------------------------
110 
111  // --- Event loop
112  Int_t nEvents = fEvents->GetEntriesFast();
113  LOG(debug) << GetName() << ": reading time slice with " << nEvents
114  << " events ";
115  for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
116 
117  fTimer.Start();
118  CbmEvent* event = static_cast<CbmEvent*>(fEvents->At(iEvent));
119 
120  // --- Call find method of vertex finder
121  // Int_t status = fFinder->FindEventVertex(event, fTracks);
123 
124  // --- Event log
125  LOG(info) << "+ " << setw(20) << GetName() << ": Event " << setw(6) << right
126  << event->GetNumber() << ", real time " << fixed
127  << setprecision(6) << fTimer.RealTime()
128  << " s, tracks used: " << event->GetVertex()->GetNTracks();
129  LOG(debug) << fPrimVert->ToString();
130 
131  // --- Counters
132  fNofEvents++;
133  fTimeTot += fTimer.RealTime();
134 
135  } //# events
136 }
137 // -------------------------------------------------------------------------
138 
139 
140 // ----- End-of-run action ---------------------------------------------
142 
143  std::cout << std::endl;
144  LOG(info) << "=====================================";
145  LOG(info) << GetName() << ": Run summary";
146  LOG(info) << "Events processed : " << fNofEvents;
147  LOG(info) << "Time per event : " << fTimeTot / Double_t(fNofEvents)
148  << " s ";
149  LOG(info) << "=====================================";
150 }
151 // -------------------------------------------------------------------------
152 
153 
CbmFindPrimaryVertexEvents::Finish
virtual void Finish()
Definition: CbmFindPrimaryVertexEvents.cxx:141
CbmVertex.h
CbmFindPrimaryVertexEvents::Exec
virtual void Exec(Option_t *opt)
Definition: CbmFindPrimaryVertexEvents.cxx:109
CbmFindPrimaryVertexEvents::Init
virtual InitStatus Init()
Definition: CbmFindPrimaryVertexEvents.cxx:76
CbmFindPrimaryVertexEvents::fNofEvents
Int_t fNofEvents
Total number of events processed.
Definition: CbmFindPrimaryVertexEvents.h:80
CbmEvent.h
CbmFindPrimaryVertexEvents::~CbmFindPrimaryVertexEvents
virtual ~CbmFindPrimaryVertexEvents()
Definition: CbmFindPrimaryVertexEvents.cxx:71
CbmFindPrimaryVertexEvents::fTracks
TClonesArray * fTracks
event array
Definition: CbmFindPrimaryVertexEvents.h:77
CbmPrimaryVertexFinder::Init
virtual void Init()
Definition: CbmPrimaryVertexFinder.h:43
CbmPrimaryVertexFinder::FindEventVertex
virtual Int_t FindEventVertex(CbmEvent *event, TClonesArray *tracks)=0
CbmPrimaryVertexFinder
Definition: CbmPrimaryVertexFinder.h:29
CbmVertex
Definition: CbmVertex.h:26
CbmFindPrimaryVertexEvents.h
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmPrimaryVertexFinder.h
CbmFindPrimaryVertexEvents::fTimeTot
Double_t fTimeTot
Total execution time [s].
Definition: CbmFindPrimaryVertexEvents.h:81
CbmFindPrimaryVertexEvents
Task class for PV finding.
Definition: CbmFindPrimaryVertexEvents.h:29
CbmFindPrimaryVertexEvents::fTimer
TStopwatch fTimer
ROOT stopwatch.
Definition: CbmFindPrimaryVertexEvents.h:74
CbmFindPrimaryVertexEvents::fPrimVert
CbmVertex * fPrimVert
track array
Definition: CbmFindPrimaryVertexEvents.h:78
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
CbmFindPrimaryVertexEvents::fFinder
CbmPrimaryVertexFinder * fFinder
Concrete finder instance.
Definition: CbmFindPrimaryVertexEvents.h:75
CbmVertex::ToString
virtual std::string ToString() const
Definition: CbmVertex.cxx:169
CbmFindPrimaryVertexEvents::fEvents
TClonesArray * fEvents
Definition: CbmFindPrimaryVertexEvents.h:76
CbmFindPrimaryVertexEvents::CbmFindPrimaryVertexEvents
CbmFindPrimaryVertexEvents()
Definition: CbmFindPrimaryVertexEvents.cxx:24