CbmRoot
CbmStsFindTracks.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmStsFindTracks source file -----
3 // ----- Created 02/02/05 by V. Friese -----
4 // -------------------------------------------------------------------------
5 // Includes from STS
6 #include "CbmStsFindTracks.h"
7 
8 #include "CbmStsHit.h"
9 #include "CbmStsTrack.h"
10 #include "CbmStsTrackFinderIdeal.h"
11 
12 // Includes from base
13 #include "FairField.h"
14 #include "FairRootManager.h"
15 #include "FairRunAna.h"
16 #include "FairRuntimeDb.h"
17 
18 // Includes from ROOT
19 #include "TClonesArray.h"
20 
21 // Includes from C++
22 #include <iomanip>
23 #include <iostream>
24 
25 using std::cout;
26 using std::endl;
27 using std::fixed;
28 using std::left;
29 using std::right;
30 using std::setprecision;
31 using std::setw;
32 
33 // ----- Default constructor -------------------------------------------
35  : FairTask("STSFindTracks")
36  , fUseMvd(kFALSE)
37  , fGeoPar(NULL)
38  , fDigiPar(NULL)
39  ,
40  // fDigiScheme(new CbmStsDigiScheme()),
41  fField(NULL)
42  , fFinder(new CbmStsTrackFinderIdeal(1))
43  , fMvdHits(NULL)
44  , fStsHits(NULL)
45  , fTracks(NULL)
46  , fTimer()
47  , fNEvents(0)
48  , fNEventsFailed(0)
49  , fTime(0.)
50  , fNTracks(0.) {
51  fVerbose = 1;
52 }
53 // -------------------------------------------------------------------------
54 
55 
56 // ----- Standard constructor ------------------------------------------
58  CbmStsTrackFinder* finder,
59  Bool_t useMvd,
60  const char* name)
61  : FairTask(name, iVerbose)
62  , fUseMvd(useMvd)
63  , fGeoPar(NULL)
64  , fDigiPar(NULL)
65  ,
66  // fDigiScheme(new CbmStsDigiScheme()),
67  fField(NULL)
68  , fFinder(NULL)
69  , fMvdHits(NULL)
70  , fStsHits(NULL)
71  , fTracks(NULL)
72  , fTimer()
73  , fNEvents(0)
74  , fNEventsFailed(0)
75  , fTime(0.)
76  , fNTracks(0.) {
77  if (finder)
78  fFinder = finder;
79  else
80  fFinder = new CbmStsTrackFinderIdeal(iVerbose);
81 }
82 // -------------------------------------------------------------------------
83 
84 
85 // ----- Destructor ----------------------------------------------------
87  // if ( fDigiScheme ) delete fDigiScheme;
88  fTracks->Delete();
89  if (fFinder) delete fFinder;
90 }
91 // -------------------------------------------------------------------------
92 
93 
94 // ----- Virtual public method Exec ------------------------------------
95 void CbmStsFindTracks::Exec(Option_t* /*opt*/) {
96 
97  fTimer.Start();
98 
99  fTracks->Delete();
100  Int_t nTracks = fFinder->DoFind();
101  // for (Int_t iTrack=0; iTrack<fTracks->GetEntriesFast(); iTrack++) {
102  // CbmStsTrack* track = (CbmStsTrack*) fTracks->At(iTrack);
103  // track->SortHits();
104  // }
105 
106  fTimer.Stop();
107 
108  // --- Event log
109  LOG(info) << "+ " << setw(20) << GetName() << ": Event " << setw(6) << right
110  << fNEvents << ", real time " << fixed << setprecision(6)
111  << fTimer.RealTime() << " s, hits: " << fStsHits->GetEntriesFast()
112  << ", tracks: " << nTracks;
113 
114 
115  fNEvents++;
116  fTime += fTimer.RealTime();
117  fNTracks += Double_t(nTracks);
118 }
119 // -------------------------------------------------------------------------
120 
121 
122 // ----- Private virtual method SetParContainers -----------------------
124 
125  // Get run and runtime database
126  FairRunAna* run = FairRunAna::Instance();
127  if (!run) Fatal("SetParContainers", "No analysis run");
128 
129  FairRuntimeDb* db = run->GetRuntimeDb();
130  if (!db) Fatal("SetParContainers", "No runtime database");
131 
132  // Get STS geometry parameter container
133  fGeoPar = (CbmGeoStsPar*) db->getContainer("CbmGeoStsPar");
134 
135  // Get STS digitisation parameter container
136  fDigiPar = (CbmStsDigiPar*) db->getContainer("CbmStsDigiPar");
137 }
138 // -------------------------------------------------------------------------
139 
140 
141 // ----- Private virtual method Init ------------------------------------
143 
144  cout << endl;
145  cout << "---------------------------------------------" << endl;
146  cout << "-I- Initialising " << GetName() << " ...." << endl;
147 
148  // Get input hit arrays
149  FairRootManager* ioman = FairRootManager::Instance();
150  if (!ioman) Fatal("Init", "No FairRootManager");
151  fStsHits = (TClonesArray*) ioman->GetObject("StsHit");
152  if (!fStsHits) {
153  cout << "-E- " << GetName() << "::Init: No StsHit array!" << endl;
154  return kERROR;
155  }
156  if (fUseMvd) {
157  fMvdHits = (TClonesArray*) ioman->GetObject("MvdHit");
158  if (!fMvdHits) {
159  cout << "-W- " << GetName() << "::Init: No MVD hits available!" << endl;
160  cout << " Running track finding without MVD hits" << endl;
161  }
162  }
163 
164  // Create and register output array STSTrack
165  fTracks = new TClonesArray("CbmStsTrack", 100);
166  ioman->Register(
167  "StsTrack", "STS", fTracks, IsOutputBranchPersistent("StsTrack"));
168 
169  // Build digitisation scheme
170  /*
171  if ( fDigiScheme->Init(fGeoPar, fDigiPar) ) {
172  if (fVerbose == 1 || fVerbose == 2) fDigiScheme->Print(kFALSE);
173  else if (fVerbose > 2) fDigiScheme->Print(kTRUE);
174  cout << "-I- "
175  << "STS digitisation scheme succesfully initialised" << endl;
176  cout << " Stations: " << fDigiScheme->GetNStations()
177  << ", Sectors: " << fDigiScheme->GetNSectors() << ", Channels: "
178  << fDigiScheme->GetNChannels() << endl;
179  }
180  */
181 
182  // Check for Track finder
183  if (!fFinder) {
184  cout << "-E- " << GetName() << "::Init: No track finder selected!" << endl;
185  return kERROR;
186  }
187  cout << "-I- Track finder engine " << fFinder->GetName() << " selected"
188  << endl;
189 
190 
191  // Set members of track finder and verbosity and initialise track finder
192  //fFinder->SetDigiScheme(fDigiScheme);
197  fFinder->SetVerbose(fVerbose);
198  fFinder->Init();
199 
200  // Screen output
201  cout << "-I- " << GetName() << " intialised " << endl;
202  cout << "---------------------------------------------" << endl;
203 
204  return kSUCCESS;
205 }
206 // -------------------------------------------------------------------------
207 
208 
209 // ----- Virtual private method Finish ---------------------------------
211 
212  fFinder->Finish();
213 
214  cout << endl;
215  cout << "============================================================"
216  << endl;
217  cout << "===== " << GetName() << ": Run summary " << endl;
218  cout << "===== " << endl;
219  cout << "===== Good events : " << setw(6) << fNEvents << endl;
220  cout << "===== Failed events : " << setw(6) << fNEventsFailed << endl;
221  cout << "===== Average time : " << setprecision(4) << setw(8) << right
222  << fTime / Double_t(fNEvents) << " s" << endl;
223  cout << "===== " << endl;
224  cout << "===== Found tracks per event : " << fixed << setprecision(0)
225  << fNTracks / Double_t(fNEvents) << endl;
226  cout << "============================================================"
227  << endl;
228 }
229 // -------------------------------------------------------------------------
230 
231 
CbmStsFindTracks::CbmStsFindTracks
CbmStsFindTracks()
Definition: CbmStsFindTracks.cxx:34
CbmStsTrackFinderIdeal
MC-based track finding in the STS.
Definition: CbmStsTrackFinderIdeal.h:38
CbmStsFindTracks::fField
FairField * fField
Definition: CbmStsFindTracks.h:79
CbmStsFindTracks::SetParContainers
virtual void SetParContainers()
Definition: CbmStsFindTracks.cxx:123
CbmStsTrackFinder::DoFind
virtual Int_t DoFind()=0
CbmStsFindTracks::fMvdHits
TClonesArray * fMvdHits
Definition: CbmStsFindTracks.h:81
CbmStsFindTracks::Exec
virtual void Exec(Option_t *opt)
Definition: CbmStsFindTracks.cxx:95
CbmStsFindTracks::fGeoPar
CbmGeoStsPar * fGeoPar
Definition: CbmStsFindTracks.h:76
CbmStsTrackFinder::SetVerbose
void SetVerbose(Int_t verbose)
Definition: CbmStsTrackFinder.h:75
CbmStsTrackFinder::Init
virtual void Init()
Definition: CbmStsTrackFinder.h:44
CbmStsTrackFinder::SetStsHitArray
void SetStsHitArray(TClonesArray *hits)
Definition: CbmStsTrackFinder.h:73
CbmStsFindTracks::Finish
virtual void Finish()
Definition: CbmStsFindTracks.cxx:210
CbmStsFindTracks::fUseMvd
Bool_t fUseMvd
Definition: CbmStsFindTracks.h:71
CbmStsTrack.h
Data class for STS tracks.
CbmStsTrackFinder::Finish
virtual void Finish()
Definition: CbmStsTrackFinder.h:59
CbmStsFindTracks
Definition: CbmStsFindTracks.h:34
CbmStsTrackFinder
Definition: CbmStsTrackFinder.h:30
CbmStsFindTracks::fNEvents
Int_t fNEvents
Definition: CbmStsFindTracks.h:85
CbmStsTrackFinderIdeal.h
CbmStsFindTracks::fNTracks
Double_t fNTracks
Definition: CbmStsFindTracks.h:88
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmStsFindTracks::Init
virtual InitStatus Init()
Definition: CbmStsFindTracks.cxx:142
CbmStsTrackFinder::SetMvdHitArray
void SetMvdHitArray(TClonesArray *hits)
Definition: CbmStsTrackFinder.h:72
CbmStsFindTracks::fNEventsFailed
Int_t fNEventsFailed
Definition: CbmStsFindTracks.h:86
CbmStsFindTracks::fTime
Double_t fTime
Definition: CbmStsFindTracks.h:87
CbmStsFindTracks::fTracks
TClonesArray * fTracks
Definition: CbmStsFindTracks.h:83
CbmStsFindTracks::fTimer
TStopwatch fTimer
Definition: CbmStsFindTracks.h:84
CbmStsFindTracks::fFinder
CbmStsTrackFinder * fFinder
Definition: CbmStsFindTracks.h:80
CbmStsTrackFinder::SetField
void SetField(FairField *field)
Definition: CbmStsTrackFinder.h:71
CbmStsFindTracks.h
CbmStsFindTracks::fDigiPar
CbmStsDigiPar * fDigiPar
Definition: CbmStsFindTracks.h:77
CbmStsTrackFinder::SetTrackArray
void SetTrackArray(TClonesArray *tracks)
Definition: CbmStsTrackFinder.h:74
CbmStsHit.h
Data class for a reconstructed hit in the STS.
CbmStsFindTracks::~CbmStsFindTracks
virtual ~CbmStsFindTracks()
Definition: CbmStsFindTracks.cxx:86
CbmStsFindTracks::fStsHits
TClonesArray * fStsHits
Definition: CbmStsFindTracks.h:82