CbmRoot
CbmStsFindTracksEvents.cxx
Go to the documentation of this file.
1 
8 // Includes from STS
10 
11 #include "CbmEvent.h"
12 #include <cassert>
13 
14 #include "CbmStsHit.h"
15 #include "CbmStsTrack.h"
16 #include "CbmStsTrackFinderIdeal.h"
17 
18 // Includes from base
19 #include "FairField.h"
20 #include "FairRootManager.h"
21 #include "FairRunAna.h"
22 #include "FairRuntimeDb.h"
23 
24 // Includes from ROOT
25 #include "TClonesArray.h"
26 
27 // Includes from C++
28 #include <iomanip>
29 #include <iostream>
30 
31 using std::cout;
32 using std::endl;
33 using std::fixed;
34 using std::left;
35 using std::right;
36 using std::setprecision;
37 using std::setw;
38 
39 // ----- Standard constructor ------------------------------------------
41  Bool_t useMvd)
42  : FairTask("StsFindTracksEvents")
43  , fUseMvd(useMvd)
44  , fFinder(finder)
45  , fEvents(NULL)
46  , fMvdHits(NULL)
47  , fStsHits(NULL)
48  , fTracks(NULL)
49  , fTimer()
50  , fNofEvents(0)
51  , fNofHits(0.)
52  , fNofTracks(0.)
53  , fTime(0.) {
54  if (!finder) fFinder = new CbmStsTrackFinderIdeal();
55 }
56 // -------------------------------------------------------------------------
57 
58 
59 // ----- Destructor ----------------------------------------------------
61  fTracks->Delete();
62  if (fFinder) delete fFinder;
63 }
64 // -------------------------------------------------------------------------
65 
66 
67 // ----- Task execution ------------------------------------------------
68 void CbmStsFindTracksEvents::Exec(Option_t* /*opt*/) {
69 
70  // --- Clear output array
71  fTracks->Delete();
72 
73  // --- Event loop (from event objects)
74  if (fEvents) {
75  Int_t nEvents = fEvents->GetEntriesFast();
76  LOG(debug) << GetName() << ": reading time slice with " << nEvents
77  << " events ";
78  for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
79  CbmEvent* event = static_cast<CbmEvent*>(fEvents->At(iEvent));
80  ProcessEvent(event);
81  } //# events
82  } //? event branch present
83 
84  else // Old event-by-event simulation without event branch
85  ProcessEvent(NULL);
86 }
87 // -------------------------------------------------------------------------
88 
89 
90 // ----- Initialisation ------------------------------------------------
92 
93  LOG(info) << "=====================================";
94  LOG(info) << GetName() << ": initialising";
95 
96  // I/O manager
97  FairRootManager* ioman = FairRootManager::Instance();
98  assert(ioman);
99 
100  // --- Get input array (Events)
101  fEvents = dynamic_cast<TClonesArray*>(ioman->GetObject("Event"));
102  if (!fEvents) {
103  LOG(warn) << GetName() << ": No event array! Will process entire tree.";
104  }
105 
106  // --- Get input array (StsHits)
107  fStsHits = (TClonesArray*) ioman->GetObject("StsHit");
108  assert(fStsHits);
109 
110  // Array of MvdHits
111  if (fUseMvd) {
112  LOG(info) << GetName() << ": including MVD hits in tracking";
113  fMvdHits = (TClonesArray*) ioman->GetObject("MvdHit");
114  assert(fMvdHits);
115  }
116 
117  // Create and register output array for StsTracks
118  fTracks = new TClonesArray("CbmStsTrack", 100);
119  ioman->Register(
120  "StsTrack", "STS", fTracks, IsOutputBranchPersistent("StsTrack"));
121 
122  // Check for Track finder
123  if (!fFinder) {
124  LOG(fatal) << GetName() << ": no track finding engine selected!";
125  return kERROR;
126  }
127  LOG(info) << GetName() << ": Use track finder " << fFinder->GetName();
128 
129  // Set members of track finder and initialise it
133  fFinder->Init();
134 
135  // Screen output
136  LOG(info) << GetName() << ": successfully initialised.";
137  LOG(info) << "=====================================\n";
138 
139  return kSUCCESS;
140 }
141 // -------------------------------------------------------------------------
142 
143 
144 // ----- End-of-run action ---------------------------------------------
146  std::cout << std::endl;
147  LOG(info) << "=====================================";
148  LOG(info) << GetName() << ": Run summary";
149  LOG(info) << "Events processed : " << fNofEvents;
150  LOG(info) << "Hits / event : " << fNofHits / Double_t(fNofEvents);
151  LOG(info) << "Tracks / event : " << fNofTracks / Double_t(fNofEvents);
152  LOG(info) << "Hits per track : " << fNofHits / fNofTracks;
153  LOG(info) << "Time per event : " << fTime / Double_t(fNofEvents) << " s ";
154  LOG(info) << "=====================================";
155 }
156 // -------------------------------------------------------------------------
157 
158 
159 // ------ Process one event --------------------------------------------
161 
162  // --- Call track finder
163  fTimer.Start();
164  Int_t nTracks = fFinder->FindTracks(event);
165  fTimer.Stop();
166 
167  // --- Event log
168  Int_t eventNumber = (event ? event->GetNumber() : fNofEvents);
169  Int_t nHits = (event ? event->GetNofData(ECbmDataType::kStsHit)
170  : fStsHits->GetEntriesFast());
171  LOG(info) << "+ " << setw(20) << GetName() << ": Event " << setw(6) << right
172  << eventNumber << ", real time " << fixed << setprecision(6)
173  << fTimer.RealTime() << " s, hits: " << nHits
174  << ", tracks: " << nTracks;
175 
176  // --- Counters
177  fNofEvents++;
178  fNofHits += Double_t(nHits);
179  fNofTracks += Double_t(nTracks);
180  fTime += fTimer.RealTime();
181 }
182 // -------------------------------------------------------------------------
183 
184 
CbmStsTrackFinderIdeal
MC-based track finding in the STS.
Definition: CbmStsTrackFinderIdeal.h:38
CbmStsFindTracksEvents::~CbmStsFindTracksEvents
virtual ~CbmStsFindTracksEvents()
Definition: CbmStsFindTracksEvents.cxx:60
ECbmDataType::kStsHit
@ kStsHit
CbmStsFindTracksEvents::fUseMvd
Bool_t fUseMvd
Definition: CbmStsFindTracksEvents.h:68
CbmStsFindTracksEvents.h
CbmStsFindTracksEvents
Task class for finding STS tracks in an event.
Definition: CbmStsFindTracksEvents.h:31
CbmStsFindTracksEvents::Init
virtual InitStatus Init()
Definition: CbmStsFindTracksEvents.cxx:91
CbmStsFindTracksEvents::fMvdHits
TClonesArray * fMvdHits
Array of CbmEvent objects.
Definition: CbmStsFindTracksEvents.h:75
CbmStsTrackFinder::Init
virtual void Init()
Definition: CbmStsTrackFinder.h:44
CbmStsFindTracksEvents::ProcessEvent
void ProcessEvent(CbmEvent *event)
Definition: CbmStsFindTracksEvents.cxx:160
CbmStsTrackFinder::SetStsHitArray
void SetStsHitArray(TClonesArray *hits)
Definition: CbmStsTrackFinder.h:73
CbmEvent.h
CbmStsTrack.h
Data class for STS tracks.
CbmStsFindTracksEvents::fTime
Double_t fTime
Total real time used for good events.
Definition: CbmStsFindTracksEvents.h:82
CbmStsTrackFinder
Definition: CbmStsTrackFinder.h:30
CbmStsTrackFinderIdeal.h
CbmStsFindTracksEvents::fStsHits
TClonesArray * fStsHits
Input array of MVD hits.
Definition: CbmStsFindTracksEvents.h:76
CbmStsFindTracksEvents::Exec
virtual void Exec(Option_t *opt)
Definition: CbmStsFindTracksEvents.cxx:68
CbmStsTrackFinder::FindTracks
virtual Int_t FindTracks(CbmEvent *event)=0
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmStsFindTracksEvents::fFinder
CbmStsTrackFinder * fFinder
Definition: CbmStsFindTracksEvents.h:73
CbmStsFindTracksEvents::CbmStsFindTracksEvents
CbmStsFindTracksEvents(CbmStsTrackFinder *finder=NULL, Bool_t useMvd=kFALSE)
Definition: CbmStsFindTracksEvents.cxx:40
CbmStsTrackFinder::SetMvdHitArray
void SetMvdHitArray(TClonesArray *hits)
Definition: CbmStsTrackFinder.h:72
CbmStsFindTracksEvents::fTracks
TClonesArray * fTracks
Input array of STS hits.
Definition: CbmStsFindTracksEvents.h:77
CbmStsFindTracksEvents::fNofTracks
Double_t fNofTracks
Number of tracks created.
Definition: CbmStsFindTracksEvents.h:81
CbmStsFindTracksEvents::fTimer
TStopwatch fTimer
Output array of CbmStsTracks.
Definition: CbmStsFindTracksEvents.h:78
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
CbmStsFindTracksEvents::fNofEvents
Int_t fNofEvents
Timer.
Definition: CbmStsFindTracksEvents.h:79
CbmStsFindTracksEvents::fEvents
TClonesArray * fEvents
Definition: CbmStsFindTracksEvents.h:74
CbmStsFindTracksEvents::fNofHits
Double_t fNofHits
Number of hits.
Definition: CbmStsFindTracksEvents.h:80
eventNumber
Int_t eventNumber
Definition: riplet/Lx.cxx:78
CbmStsTrackFinder::SetTrackArray
void SetTrackArray(TClonesArray *tracks)
Definition: CbmStsTrackFinder.h:74
CbmStsFindTracksEvents::Finish
virtual void Finish()
Definition: CbmStsFindTracksEvents.cxx:145
CbmStsHit.h
Data class for a reconstructed hit in the STS.