CbmRoot
CbmFindPrimaryVertex.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmFindPrimaryVertex source file -----
3 // ----- Created 28/11/05 by V. Friese -----
4 // -------------------------------------------------------------------------
5 #include "CbmFindPrimaryVertex.h"
6 
8 #include "CbmVertex.h"
9 
10 #include "FairLogger.h"
11 #include "FairRootManager.h"
12 
13 #include "TClonesArray.h"
14 
15 #include <iomanip>
16 #include <iostream>
17 
18 using namespace std;
19 
20 // ----- Default constructor -------------------------------------------
22  : FairTask()
23  , fTimer()
24  , fFinder(nullptr)
25  , fTracks(nullptr)
26  , fPrimVert(nullptr)
27  , fNofEvents(0)
28  , fTimeTot(0.) {
29  fName = "FindPrimaryVertex";
30 }
31 // -------------------------------------------------------------------------
32 
33 
34 // ----- Standard constructor ------------------------------------------
36  : FairTask()
37  , fTimer()
38  , fFinder(pvFinder)
39  , fTracks(nullptr)
40  , fPrimVert(nullptr)
41  , fNofEvents(0)
42  , fTimeTot(0.) {
43  fName = "FindPrimaryVertex";
44 }
45 // -------------------------------------------------------------------------
46 
47 
48 // ----- Constructor with name and title ---------------------------------
50  const char*,
51  CbmPrimaryVertexFinder* finder)
52  : FairTask(name)
53  , fTimer()
54  , fFinder(finder)
55  , fTracks(nullptr)
56  , fPrimVert(nullptr)
57  , fNofEvents(0)
58  , fTimeTot(0.) {}
59 // -------------------------------------------------------------------------
60 
61 
62 // ----- Destructor ----------------------------------------------------
64 // -------------------------------------------------------------------------
65 
66 
67 // ----- Public method Init --------------------------------------------
69 
70  // Check for vertex finder
71  if (!fFinder) {
72  cout << "-E- CbmFindPrimaryVertex::Init : "
73  << "No vertex finder selected! " << endl;
74  return kERROR;
75  }
76 
77  // Get FairRootManager
78  FairRootManager* ioman = FairRootManager::Instance();
79  if (!ioman) {
80  cout << "-E- CbmFindPrimaryVertex::Init: "
81  << "RootManager not instantised!" << endl;
82  return kFATAL;
83  }
84 
85  // Get CbmStsTrack array
86  fTracks = (TClonesArray*) ioman->GetObject("StsTrack");
87  if (!fTracks) {
88  cout << "-W- CbmFindPrimaryVertex::Init: No STSTrack array!" << endl;
89  return kERROR;
90  }
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  // Call the Init method of the vertex finder
101  fFinder->Init();
102 
103  return kSUCCESS;
104 }
105 // -------------------------------------------------------------------------
106 
107 
108 // ----- Public method Exec --------------------------------------------
109 void CbmFindPrimaryVertex::Exec(Option_t*) {
110 
111  // Event number
112  Int_t iEvent = fNofEvents;
113 
114  // Reset primary vertex
115  fTimer.Start();
116  fPrimVert->Reset();
117 
118  // Call find method of vertex finder
119  Int_t iFind = fFinder->FindPrimaryVertex(fTracks, fPrimVert);
120  if (iFind)
121  cout << "-W- CbmFindPrimaryVertex::Exec: "
122  << "Vertex finder returned " << iFind << endl;
123 
124  // --- Event log
125  fTimer.Stop();
126  fNofEvents++;
127  fTimeTot += fTimer.RealTime();
128  LOG(info) << "+ " << setw(20) << GetName() << ": Event " << setw(6) << right
129  << iEvent << ", real time " << fixed << setprecision(6)
130  << fTimer.RealTime()
131  << " s, tracks used: " << fPrimVert->GetNTracks();
132  LOG(debug) << fPrimVert->ToString();
133 }
134 // -------------------------------------------------------------------------
135 
136 
137 // ----- Public method Finish ------------------------------------------
139  fPrimVert->Reset();
140  std::cout << std::endl;
141  LOG(info) << "=====================================";
142  LOG(info) << GetName() << ": Run summary";
143  LOG(info) << "Events processed : " << fNofEvents;
144  LOG(info) << "Time per event : " << setprecision(6)
145  << fTimeTot / Double_t(fNofEvents) << " s ";
146  LOG(info) << "=====================================";
147 }
148 // -------------------------------------------------------------------------
149 
150 
CbmVertex::GetNTracks
Int_t GetNTracks() const
Definition: CbmVertex.h:73
CbmVertex.h
CbmVertex::Reset
void Reset()
Definition: CbmVertex.cxx:159
CbmFindPrimaryVertex::fPrimVert
CbmVertex * fPrimVert
Definition: CbmFindPrimaryVertex.h:75
CbmFindPrimaryVertex::fTimer
TStopwatch fTimer
Definition: CbmFindPrimaryVertex.h:72
CbmFindPrimaryVertex::Exec
virtual void Exec(Option_t *opt)
Definition: CbmFindPrimaryVertex.cxx:109
CbmFindPrimaryVertex::Init
virtual InitStatus Init()
Definition: CbmFindPrimaryVertex.cxx:68
CbmFindPrimaryVertex::CbmFindPrimaryVertex
CbmFindPrimaryVertex()
Definition: CbmFindPrimaryVertex.cxx:21
CbmFindPrimaryVertex::fNofEvents
Int_t fNofEvents
Total number of events processed.
Definition: CbmFindPrimaryVertex.h:77
CbmPrimaryVertexFinder::Init
virtual void Init()
Definition: CbmPrimaryVertexFinder.h:43
CbmPrimaryVertexFinder
Definition: CbmPrimaryVertexFinder.h:29
CbmVertex
Definition: CbmVertex.h:26
CbmFindPrimaryVertex::~CbmFindPrimaryVertex
virtual ~CbmFindPrimaryVertex()
Definition: CbmFindPrimaryVertex.cxx:63
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmPrimaryVertexFinder.h
CbmFindPrimaryVertex::Finish
virtual void Finish()
Definition: CbmFindPrimaryVertex.cxx:138
CbmFindPrimaryVertex::fFinder
CbmPrimaryVertexFinder * fFinder
Definition: CbmFindPrimaryVertex.h:73
CbmPrimaryVertexFinder::FindPrimaryVertex
virtual Int_t FindPrimaryVertex(TClonesArray *tracks, CbmVertex *vertex)=0
CbmFindPrimaryVertex.h
CbmFindPrimaryVertex
Definition: CbmFindPrimaryVertex.h:31
CbmFindPrimaryVertex::fTimeTot
Double_t fTimeTot
Total execution time [s].
Definition: CbmFindPrimaryVertex.h:78
CbmVertex::ToString
virtual std::string ToString() const
Definition: CbmVertex.cxx:169
CbmFindPrimaryVertex::fTracks
TClonesArray * fTracks
Definition: CbmFindPrimaryVertex.h:74