CbmRoot
Loading...
Searching...
No Matches
CbmTofAnaTestbeam_Template.cxx
Go to the documentation of this file.
1/* Copyright (C) 2014-2021 PI-UHd, GSI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Norbert Herrmann [committer] */
4
5// ------------------------------------------------------------------
6// ----- CbmTofAnaTestbeam -----
7// ----- Created 12/04/2014 by nh -----
8// ------------------------------------------------------------------
9
10#include "CbmTofAnaTestbeam.h"
11
12// TOF Classes and includes
13#include "CbmMatch.h"
14#include "CbmTofAddress.h" // in cbmdata/tof
15#include "CbmTofCell.h" // in tof/TofData
16#include "CbmTofDetectorId_v12b.h" // in cbmdata/tof
17#include "CbmTofDetectorId_v14a.h" // in cbmdata/tof
18#include "CbmTofDigi.h" // in cbmdata/tof
19#include "CbmTofDigiBdfPar.h" // in tof/TofParam
20#include "CbmTofDigiExp.h" // in cbmdata/tof
21#include "CbmTofDigiPar.h" // in tof/TofParam
22#include "CbmTofGeoHandler.h" // in tof/TofTools
23#include "CbmTofHit.h" // in cbmdata/tof
24
25// CBMroot classes and includes
26
27
28// FAIR classes and includes
29#include "FairRootManager.h"
30#include "FairRunAna.h"
31#include "FairRuntimeDb.h"
32#include <Logger.h>
33
34// ROOT Classes and includes
35#include "TClonesArray.h"
36#include "TFile.h"
37#include "TH1.h"
38#include "TH2.h"
39#include "TMath.h"
40#include "TROOT.h"
41#include "TRandom.h"
42#include "TString.h"
43
44#include "Riostream.h"
45
46//___________________________________________________________________
47//
48// CbmTofAnaTestbeam
49//
50// Task for analysis of Testbeam data
51//
52// ------------------------------------------------------------------
54 : FairTask("HadronAnalysis")
55 , fEvents(0)
56 , fGeoHandler(new CbmTofGeoHandler())
57 , fTofId(NULL)
58 , fChannelInfo(NULL)
59 , iNbSmTot(0)
60 , fvTypeSmOffs()
61 , iNbRpcTot(0)
62 , fvSmRpcOffs()
63 , iNbChTot(0)
64 , fvRpcChOffs()
65 , fDigiPar(NULL)
66 , fDigiBdfPar(NULL)
67 , fTofDigisColl(NULL)
68 , fTofDigiMatchColl(NULL)
69 , fTofHitsColl(NULL)
70 , fStart()
71 , fStop()
72{
73 cout << "CbmTofTests: Task started " << endl;
74}
75// ------------------------------------------------------------------
76
77// ------------------------------------------------------------------
78CbmTofAnaTestbeam::CbmTofAnaTestbeam(const char* name, Int_t verbose)
79 : FairTask(name, verbose)
80 , fEvents(0)
81 , fGeoHandler(new CbmTofGeoHandler())
82 , fTofId(NULL)
83 , fChannelInfo(NULL)
84 , iNbSmTot(0)
85 , fvTypeSmOffs()
86 , iNbRpcTot(0)
87 , fvSmRpcOffs()
88 , iNbChTot(0)
89 , fvRpcChOffs()
90 , fDigiPar(NULL)
91 , fDigiBdfPar(NULL)
92 , fTofDigisColl(NULL)
93 , fTofDigiMatchColl(NULL)
94 , fTofHitsColl(NULL)
95 , fStart()
96 , fStop()
97{
98}
99// ------------------------------------------------------------------
100
101// ------------------------------------------------------------------
103{
104 // Destructor
105}
106// ------------------------------------------------------------------
107/************************************************************************************/
108// FairTasks inherited functions
109InitStatus CbmTofAnaTestbeam::Init()
110{
111 if (kFALSE == RegisterInputs()) return kFATAL;
112
113 // fTofId = new ( CbmTofDetectorId )CbmTofDetectorId_v14a();
114 if (kFALSE == InitParameters()) return kFATAL;
115
116 if (kFALSE == LoadGeometry()) return kFATAL;
117
118 if (kFALSE == CreateHistos()) return kFATAL;
119
120 return kSUCCESS;
121}
122
124{
125 LOG(info) << " CbmTofAnaTestbeam => Get the digi parameters for tof";
126 return;
127 // Get Base Container
128 FairRunAna* ana = FairRunAna::Instance();
129 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
130
131 fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));
132
133 fDigiBdfPar = (CbmTofDigiBdfPar*) (rtdb->getContainer("CbmTofDigiBdfPar"));
134}
135
136void CbmTofAnaTestbeam::Exec(Option_t* /*option*/)
137{
138 // Task execution
139
140 LOG(debug) << " CbmTofAnaTestbeam => New event";
141
142 fStart.Set();
143 FillHistos();
144 fStop.Set();
145
146
147 if (0 == (fEvents % 100) && 0 < fEvents) {
148 cout << "-I- CbmTofAnaTestbeam::Exec : "
149 << "event " << fEvents << " processed." << endl;
150 }
151 fEvents += 1;
152}
153
155{
156 // Normalisations
157 cout << "CbmTofAnaTestbeam::Finish up with " << fEvents << " analyzed events " << endl;
158
159 WriteHistos();
160 // Prevent them from being sucked in by the CbmHadronAnalysis WriteHistograms method
161 DeleteHistos();
162}
163
164/************************************************************************************/
165// Functions common for all clusters approximations
167{
168 FairRootManager* fManager = FairRootManager::Instance();
169
170 fTofDigisColl = (TClonesArray*) fManager->GetObject("CbmTofDigiExp");
171
172 if (NULL == fTofDigisColl) fTofDigisColl = (TClonesArray*) fManager->GetObject("CbmTofDigi");
173
174 if (NULL == fTofDigisColl) {
175 LOG(error) << "CbmTofAnaTestbeam::RegisterInputs => Could not get the "
176 "TofDigi TClonesArray!!!";
177 return kFALSE;
178 } // if( NULL == fTofDigisColl)
179
180 fTofHitsColl = (TClonesArray*) fManager->GetObject("TofHit");
181 if (NULL == fTofHitsColl) {
182 LOG(error) << "CbmTofAnaTestbeam::RegisterInputs => Could not get the "
183 "TofHit TClonesArray!!!";
184 return kFALSE;
185 } // if( NULL == fTofHitsColl)
186
187 fTofDigiMatchColl = (TClonesArray*) fManager->GetObject("TofDigiMatch");
188 if (NULL == fTofDigiMatchColl) {
189 LOG(error) << "CbmTofAnaTestbeam::RegisterInputs => Could not get the "
190 "Match TClonesArray!!!";
191 return kFALSE;
192 } // if( NULL == fTofDigiMatchColl)
193
194 return kTRUE;
195}
196/************************************************************************************/
198{
199
200 // Initialize the TOF GeoHandler
201 Bool_t isSimulation = kFALSE;
202 LOG(info) << "CbmTofAnaTestbeam::InitParameters - Geometry, Mapping, ... ";
203 // Get Base Container
204 FairRun* ana = FairRun::Instance();
205 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
206
207 Int_t iGeoVersion = fGeoHandler->Init(isSimulation);
208 if (k14a > iGeoVersion) {}
209
210 fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));
211 if (0 == fDigiPar) {
212 LOG(error) << "CbmTofAnaTestbeam::InitParameters => Could not obtain the "
213 "CbmTofDigiPar ";
214 return kFALSE;
215 }
216
217 fDigiBdfPar = (CbmTofDigiBdfPar*) (rtdb->getContainer("CbmTofDigiBdfPar"));
218 if (0 == fDigiBdfPar) {
219 LOG(error) << "CbmTofAnaTestbeam::InitParameters => Could not obtain the "
220 "CbmTofDigiBdfPar ";
221 return kFALSE;
222 }
223
224 return kTRUE;
225}
226/************************************************************************************/
228{
229 // Count the total number of channels and
230 // generate an array with the global channel index of the first channe in each RPC
231
232 return kTRUE;
233}
234/************************************************************************************/
235// ------------------------------------------------------------------
237{
238 // Create histogramms
239
240 TDirectory* oldir = gDirectory; // <= To prevent histos from being sucked in by the param file of the TRootManager!
241 gROOT->cd(); // <= To prevent histos from being sucked in by the param file of the TRootManager !
242
243 // define histos here
244
245
246 gDirectory->cd(oldir->GetPath()); // <= To prevent histos from being sucked in by the param file of the TRootManager!
247
248 return kTRUE;
249}
250
251// ------------------------------------------------------------------
253{
254 // Constants, TODO => put as parameter !!!
255
256 Int_t kTOF = 6;
257
258 // Declare variables outside the loop
259 CbmTofHit* pTofHit;
260
261 Int_t iNbTofDigis, iNbTofHits;
262
263
264 iNbTofDigis = fTofDigisColl->GetEntriesFast();
265 iNbTofHits = fTofHitsColl->GetEntriesFast();
266
267 // Digis info
268 Double_t dTotalDataSize = 0;
269 if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
270 CbmTofDigiExp* pDigi;
271 for (Int_t iDigInd = 0; iDigInd < iNbTofDigis; iDigInd++) {
272 pDigi = (CbmTofDigiExp*) fTofDigisColl->At(iDigInd);
273
274 Int_t iSmType = pDigi->GetType();
275 Int_t iSm = pDigi->GetSm();
276 Int_t iRpc = pDigi->GetRpc();
277 Int_t iCh = pDigi->GetChannel();
278 // First Get X/Y position info
279 /*
280 CbmTofDetectorInfo xDetInfo(kTOF, iSmType, iSm, iRpc, 0, iCh + 1);
281 Int_t iChId = fTofId->SetDetectorInfo( xDetInfo );
282 fChannelInfo = fDigiPar->GetCell( iChId );
283
284 Double_t dX = fChannelInfo->GetX();
285 Double_t dY = fChannelInfo->GetY();
286 Double_t dZ = fChannelInfo->GetZ();
287 /*
288 fhDigiMapXY->Fill( dX, dY );
289 fhDigiMapXZ->Fill( dX, dZ );
290 fhDigiMapYZ->Fill( dY, dZ );
291 */
292 } // for( Int_t iDigInd = 0; iDigInd < iNbTofDigis; iDigInd++ )
293 } // if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
294
295 // Hits info
296 Int_t iNbMixedHits = 0;
297 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
298 pTofHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
299
300 // Need a method to reconvert position in a "central channel"
301 // fhHitRateCh->Fill();
302
303 Double_t dX = pTofHit->GetX();
304 Double_t dY = pTofHit->GetY();
305 Double_t dZ = pTofHit->GetZ();
306 /*
307 fhHitMapXY->Fill( dX, dY );
308 fhHitMapXZ->Fill( dX, dZ );
309 fhHitMapYZ->Fill( dY, dZ );
310 */
311 } // for( Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++)
312 return kTRUE;
313}
314// ------------------------------------------------------------------
315
317{
318 // TODO: add sub-folders
319
321 TFile* oldFile = gFile;
322 TDirectory* oldDir = gDirectory;
323
324 // Write histogramms to the file
325 TFile* fHist = new TFile("./tofTests.hst.root", "RECREATE");
326 fHist->cd();
327
328 // Mapping
329 /*
330 fhDigiMapXY->Write();
331 fhDigiMapXZ->Write();
332 fhDigiMapYZ->Write();
333 fhHitMapXY->Write();
334 fhHitMapXZ->Write();
335 fhHitMapYZ->Write();
336 */
337
339 gFile = oldFile;
340 gDirectory = oldDir;
341
342 fHist->Close();
343
344 return kTRUE;
345}
347{
348 // Test class performance
349
350 // Mapping
351 /*
352 delete fhDigiMapXY;
353 delete fhDigiMapXZ;
354 delete fhDigiMapYZ;
355
356 delete fhHitMapXY;
357 delete fhHitMapXZ;
358 delete fhHitMapYZ;
359 */
360
361 return kTRUE;
362}
363
static TFile * fHist
TClonesArray * fTofHitsColl
ClassImp(CbmTofAnaTestbeam)
@ k14a
double GetZ() const
Definition CbmHit.h:71
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
TClonesArray * fTofDigisColl
virtual void SetParContainers()
Inherited from FairTask.
CbmTofGeoHandler * fGeoHandler
TClonesArray * fTofDigiMatchColl
CbmTofDigiBdfPar * fDigiBdfPar
CbmTofDigiPar * fDigiPar
TClonesArray * fTofHitsColl
virtual void Exec(Option_t *option)
Bool_t InitParameters()
Initialize other parameters not included in parameter classes.
virtual InitStatus Init()
Parameters class for the CBM ToF digitizer using beam data distributions.
Bool_t UseExpandedDigi() const
Int_t Init(Bool_t isSimulation=kFALSE)