BmnRoot
Loading...
Searching...
No Matches
CbmFindPrimaryVertex.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- CbmFindPrimaryVertex source file -----
3// ----- Created 28/11/05 by V. Friese -----
4// -------------------------------------------------------------------------
6
8#include "CbmVertex.h"
9#include "FairRootManager.h"
10#include "TClonesArray.h"
11
12#include <TStopwatch.h>
13#include <iostream>
14
15static Double_t workTime = 0.0;
16
17using std::cout;
18using std::endl;
19
20// ----- Default constructor -------------------------------------------
22 : FairTask("CbmFindPrimaryVertex")
23 , fFinder(NULL)
24 , fTracks(NULL)
25 , fPrimVert(NULL)
26 , fTrBranch("") // AZ
27{}
28// -------------------------------------------------------------------------
29
30// ----- Standard constructor ------------------------------------------
32 : FairTask("CbmFindPrimaryVertex")
33 , fFinder(pvFinder)
34 , fTracks(NULL)
35 , fPrimVert(NULL)
36 , fTrBranch("") // AZ
37{}
38// -------------------------------------------------------------------------
39
40// ----- Constructor with name and title ---------------------------------
41CbmFindPrimaryVertex::CbmFindPrimaryVertex(const char* name, const char* title, CbmPrimaryVertexFinder* finder)
42 : FairTask(name)
43 , fFinder(finder)
44 , fTracks(NULL)
45 , fPrimVert(NULL)
46 , fTrBranch("") // AZ
47{}
48// -------------------------------------------------------------------------
49
50// ----- Destructor ----------------------------------------------------
52{
53 if (fPrimVert)
54 delete fPrimVert;
55}
56// -------------------------------------------------------------------------
57
58// ----- Public method Init --------------------------------------------
60{
61
62 // Check for vertex finder
63 if (!fFinder) {
64 cout << "-E- CbmFindPrimaryVertex::Init : "
65 << "No vertex finder selected! " << endl;
66 return kERROR;
67 }
68
69 // Get FairRootManager
70 FairRootManager* ioman = FairRootManager::Instance();
71 if (!ioman) {
72 cout << "-E- CbmFindPrimaryVertex::Init: "
73 << "RootManager not instantised!" << endl;
74 return kFATAL;
75 }
76
77 // Get CbmStsTrack array
78 // AZ fTracks = (TClonesArray*) ioman->GetObject("StsTrack");
79 if (fTrBranch == "")
80 fTracks = (TClonesArray*)ioman->GetObject("StsTrack"); // AZ
81 else
82 fTracks = (TClonesArray*)ioman->GetObject(fTrBranch); // AZ
83 if (!fTracks) {
84 cout << "-W- CbmFindPrimaryVertex::Init: No STSTrack array!" << endl;
85 return kERROR;
86 }
87
88 // Create and register CbmVertex object
89 fPrimVert = new CbmVertex("Primary Vertex", "Global");
90 ioman->Register("PrimaryVertex.", "Global", fPrimVert, kTRUE);
91
92 // Call the Init method of the vertex finder
93 fFinder->Init();
94
95 return kSUCCESS;
96}
97// -------------------------------------------------------------------------
98
99// ----- Public method Exec --------------------------------------------
100void CbmFindPrimaryVertex::Exec(Option_t* opt)
101{
102
103 TStopwatch sw;
104 sw.Start();
105
106 // Reset primary vertex
107 fPrimVert->Reset();
108
109 // Call find method of vertex finder
110 Int_t iFind = fFinder->FindPrimaryVertex(fTracks, fPrimVert);
111 if (iFind)
112 cout << "-W- CbmFindPrimaryVertex::Exec: "
113 << "Vertex finder returned " << iFind << endl;
114
115 if (fVerbose > 0) {
116 // Print vertex
117 cout << endl;
118 cout << "-------------------------------------------------------" << endl;
119 cout << "-I- Primary Vertex Finder -I-" << endl;
120 fPrimVert->Print();
121 cout << "-------------------------------------------------------" << endl;
122 }
123
124 sw.Stop();
125 workTime += sw.RealTime();
126}
127// -------------------------------------------------------------------------
128
129// ----- Public method Finish ------------------------------------------
131{
132 fPrimVert->Reset();
133 printf("Work time of CbmFindPrimaryVertex: %4.2f sec.\n", workTime);
134}
135// -------------------------------------------------------------------------
virtual void Exec(Option_t *opt)
virtual InitStatus Init()
virtual Int_t FindPrimaryVertex(TClonesArray *tracks, CbmVertex *vertex)=0
void Reset()
void Print()
Definition CbmVertex.cxx:82