CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2019CheckDtInDet.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
6
7#include "CbmDigiManager.h"
10#include "CbmPsdDigi.h"
11#include "CbmRichDigi.h"
12#include "CbmStsDigi.h"
13#include "CbmTofDigi.h"
14#include "CbmTrdDigi.h"
15
16#include "FairRootManager.h"
17#include "FairRunOnline.h"
18#include <Logger.h>
19
20#include "TClonesArray.h"
21#include "TH1.h"
22#include "TH2.h"
23#include "THttpServer.h"
24#include "TProfile.h"
25#include <TDirectory.h>
26#include <TFile.h>
27#include <type_traits>
28
29#include <iomanip>
30#include <iostream>
31using std::fixed;
32using std::setprecision;
33
34// ---- Default constructor -------------------------------------------
35CbmMcbm2019CheckDtInDet::CbmMcbm2019CheckDtInDet() : FairTask("CbmMcbm2019CheckDtInDet") {}
36
37// ---- Destructor ----------------------------------------------------
39
40// ---- Initialisation ----------------------------------------------
42{
43 // Load all necessary parameter containers from the runtime data base
44 /*
45 FairRunAna* ana = FairRunAna::Instance();
46 FairRuntimeDb* rtdb=ana->GetRuntimeDb();
47
48 <CbmMcbm2019CheckDtInDetDataMember> = (<ClassPointer>*)
49 (rtdb->getContainer("<ContainerName>"));
50 */
51}
52
53// ---- Init ----------------------------------------------------------
55{
56
57 // Get a handle from the IO manager
58 FairRootManager* ioman = FairRootManager::Instance();
59
60 // Digi manager
63 fDigiMan->Init();
64
65 // Bmon is not included in DigiManager; have to take care here
66 // Try to find a vector branch for the digi
67 fBmonDigiVector = ioman->InitObjectAs<std::vector<CbmTofDigi> const*>("BmonDigi");
68 if (!fBmonDigiVector) {
69 LOG(info) << "No Bmon digi vector found; trying TClonesArray";
70 if (std::is_convertible<TObject*, CbmTofDigi*>::value) {
71 fBmonDigiArray = dynamic_cast<TClonesArray*>(ioman->GetObject("BmonDigi"));
72 if (!fBmonDigiArray) LOG(info) << "No Bmon digi input found.";
73 } //? CbmTofDigi derives from TObject
74 } //? No vector for Bmon digis
75
76 if (!fDigiMan->IsPresent(ECbmModuleId::kSts)) { LOG(info) << "No STS digi input found."; }
77
78 if (!fDigiMan->IsPresent(ECbmModuleId::kMuch)) { LOG(info) << "No MUCH digi input found."; }
79
81 LOG(info) << "No TRD digi input found.";
82 } // if ( ! fDigiMan->IsPresent( ECbmModuleId::kTrd) )
83 else {
85 fTimeSliceMetaDataArray = dynamic_cast<TClonesArray*>(ioman->GetObject("TimesliceMetaData"));
86 if (!fTimeSliceMetaDataArray) LOG(fatal) << "No TS metadata input found while TRD needs it.";
87 } // else of if ( ! fDigiMan->IsPresent( ECbmModuleId::kTrd) )
88
89 if (!fDigiMan->IsPresent(ECbmModuleId::kTof)) { LOG(info) << "No TOF digi input found."; }
90
91 if (!fDigiMan->IsPresent(ECbmModuleId::kRich)) { LOG(info) << "No RICH digi input found."; }
92
93 if (!fDigiMan->IsPresent(ECbmModuleId::kPsd)) { LOG(info) << "No PSD digi input found."; }
94
96
97 return kSUCCESS;
98}
99
101{
103 uint32_t iNbBinsLog = 0;
105 std::vector<double> dBinsLogVector = GenerateLogBinArray(9, 9, 1, iNbBinsLog);
106 double* dBinsLog = dBinsLogVector.data();
107 // double * dBinsLog = GenerateLogBinArray( 9, 9, 1, iNbBinsLog );
108
110 // Bmon vs. Bmon
111 fBmonBmonSameTime = new TH1F("fBmonBmonSameTime", "Fract. same time Bmon;Same Time? [];Counts", 2, -0.5, 1.5);
112 // sts vs. Sts
113 fStsStsSameTime = new TH1F("fStsStsSameTime", "Fract. same time Sts;Same Time? [];Counts", 2, -0.5, 1.5);
114 // Much vs. Much
115 fMuchMuchSameTime = new TH1F("fMuchMuchSameTime", "Fract. same time Much;Same Time? [];Counts", 2, -0.5, 1.5);
116 // Trd vs. Trd
117 fTrdTrdSameTime = new TH1F("fTrdTrdSameTime", "Fract. same time Trd;Same Time? [];Counts", 2, -0.5, 1.5);
118 // Tof vs. Tof
119 fTofTofSameTime = new TH1F("fTofTofSameTime", "Fract. same time Tof;Same Time? [];Counts", 2, -0.5, 1.5);
120 // Rich vs. Rich
121 fRichRichSameTime = new TH1F("fRichRichSameTime", "Fract. same time Rich;Same Time? [];Counts", 2, -0.5, 1.5);
122 // Psd vs. Psd
123 fPsdPsdSameTime = new TH1F("fPsdPsdSameTime", "Fract. same time Psd;Same Time? [];Counts", 2, -0.5, 1.5);
124
126 // Bmon vs. Bmon
127 fBmonBmonDiff = new TH1F("fBmonBmonDiff", "Bmon-Bmon_prev;time diff [ns];Counts", 10001, -0.5, 10000.5);
128 // sts vs. Sts
129 fStsStsDiff = new TH1F("fStsStsDiff", "Sts-Sts_prev;time diff [ns];Counts", 10001, -0.5, 10000.5);
130 // Much vs. Much
131 fMuchMuchDiff = new TH1F("fMuchMuchDiff", "Much-Much_prev;time diff [ns];Counts", 10001, -0.5, 10000.5);
132 // Trd vs. Trd
133 fTrdTrdDiff = new TH1F("fTrdTrdDiff", "Trd-Trd_prev;time diff [ns];Counts", 10001, -0.5, 10000.5);
134 // Tof vs. Tof
135 fTofTofDiff = new TH1F("fTofTofDiff", "Tof-Tof_prev;time diff [ns];Counts", 10001, -0.5, 10000.5);
136 // Rich vs. Rich
137 fRichRichDiff = new TH1F("fRichRichDiff", "Rich-Rich_prev;time diff [ns];Counts", 10001, -0.5, 10000.5);
138 // Psd vs. Psd
139 fPsdPsdDiff = new TH1F("fPsdPsdDiff", "Psd-Psd_prev;time diff [ns];Counts", 10001, -0.5, 10000.5);
140 // Bmon vs. Bmon
141 fBmonBmonDiffLog = new TH1F("fBmonBmonDiffLog", "Bmon-Bmon_prev;time diff [ns];Counts", iNbBinsLog, dBinsLog);
142 // sts vs. Sts
143 fStsStsDiffLog = new TH1F("fStsStsDiffLog", "Sts-Sts_prev;time diff [ns];Counts", iNbBinsLog, dBinsLog);
144 // Much vs. Much
145 fMuchMuchDiffLog = new TH1F("fMuchMuchDiffLog", "Much-Much_prev;time diff [ns];Counts", iNbBinsLog, dBinsLog);
146 // Trd vs. Trd
147 fTrdTrdDiffLog = new TH1F("fTrdTrdDiffLog", "Trd-Trd_prev;time diff [ns];Counts", iNbBinsLog, dBinsLog);
148 // Tof vs. Tof
149 fTofTofDiffLog = new TH1F("fTofTofDiffLog", "Tof-Tof_prev;time diff [ns];Counts", iNbBinsLog, dBinsLog);
150 // Rich vs. Rich
151 fRichRichDiffLog = new TH1F("fRichRichDiffLog", "Rich-Rich_prev;time diff [ns];Counts", iNbBinsLog, dBinsLog);
152 // Psd vs. Psd
153 fPsdPsdDiffLog = new TH1F("fPsdPsdDiffLog", "Psd-Psd_prev;time diff [ns];Counts", iNbBinsLog, dBinsLog);
154
156 // Bmon vs. Bmon
158 new TH2F("fBmonBmonDiffPerChan", "Bmon-Bmon_prev Per Channel;time diff [ns]; Channel [];Counts", iNbBinsLog,
159 dBinsLog, fuNbChanBmon, 0, fuNbChanBmon);
160 // sts vs. Sts
161 fStsStsDiffPerChan = new TH2F("fStsStsDiffPerChan", "Sts-Sts_prev Per Channel;time diff [ns]; Channel [];Counts",
162 iNbBinsLog, dBinsLog, fuNbChanSts, 0, fuNbChanSts);
163 // Much vs. Much
165 new TH2F("fMuchMuchDiffPerChan", "Much-Much_prev Per Channel;time diff [ns]; Channel [];Counts", iNbBinsLog,
166 dBinsLog, fuNbChanMuch, 0, fuNbChanMuch);
167 // Trd vs. Trd
168 fTrdTrdDiffPerChan = new TH2F("fTrdTrdDiffPerChan", "Trd-Trd_prev Per Channel;time diff [ns]; Channel [];Counts",
169 iNbBinsLog, dBinsLog, fuNbChanTrd, 0, fuNbChanTrd);
170 // Tof vs. Tof
171 fTofTofDiffPerChan = new TH2F("fTofTofDiffPerChan", "Tof-Tof_prev Per Channel;time diff [ns]; Channel [];Counts",
172 iNbBinsLog, dBinsLog, fuNbChanTof, 0, fuNbChanTof);
173 // Rich vs. Rich
175 new TH2F("fRichRichDiffPerChan", "Rich-Rich_prev Per Channel;time diff [ns]; Channel [];Counts", iNbBinsLog,
176 dBinsLog, fuNbChanRich, 0, fuNbChanRich);
177 // Psd vs. Psd
178 fPsdPsdDiffPerChan = new TH2F("fPsdPsdDiffPerChan", "Psd-Psd_prev Per Channel;time diff [ns]; Channel [];Counts",
179 iNbBinsLog, dBinsLog, fuNbChanPsd, 0, fuNbChanPsd);
180
182 FairRunOnline* run = FairRunOnline::Instance();
183 if (run) {
184 THttpServer* server = run->GetHttpServer();
185 if (nullptr != server) {
186
187 server->Register("/Dt", fBmonBmonDiff);
188 server->Register("/Dt", fStsStsDiff);
189 server->Register("/Dt", fMuchMuchDiff);
190 server->Register("/Dt", fTrdTrdDiff);
191 server->Register("/Dt", fTofTofDiff);
192 server->Register("/Dt", fRichRichDiff);
193 server->Register("/Dt", fPsdPsdDiff);
194
195 server->Register("/Dt", fBmonBmonDiffLog);
196 server->Register("/Dt", fStsStsDiffLog);
197 server->Register("/Dt", fMuchMuchDiffLog);
198 server->Register("/Dt", fTrdTrdDiffLog);
199 server->Register("/Dt", fTofTofDiffLog);
200 server->Register("/Dt", fRichRichDiffLog);
201 server->Register("/Dt", fPsdPsdDiffLog);
202
203 server->Register("/DtPerChan", fBmonBmonDiffPerChan);
204 server->Register("/DtPerChan", fStsStsDiffPerChan);
205 server->Register("/DtPerChan", fMuchMuchDiffPerChan);
206 server->Register("/DtPerChan", fTrdTrdDiffPerChan);
207 server->Register("/DtPerChan", fTofTofDiffPerChan);
208 server->Register("/DtPerChan", fRichRichDiffPerChan);
209 server->Register("/DtPerChan", fPsdPsdDiffPerChan);
210 }
211 }
212}
213// ---- ReInit -------------------------------------------------------
214InitStatus CbmMcbm2019CheckDtInDet::ReInit() { return kSUCCESS; }
215
216// ---- Exec ----------------------------------------------------------
217void CbmMcbm2019CheckDtInDet::Exec(Option_t* /*option*/)
218{
219 LOG(debug) << "executing TS " << fNrTs;
220
221 if (0 < fNrTs && 0 == fNrTs % 1000) LOG(info) << Form("Processing TS %6d", fNrTs);
222
224 LOG(debug) << "Begin";
225 Int_t nrBmonDigis = 0;
226 if (fBmonDigiVector) nrBmonDigis = fBmonDigiVector->size();
227 else if (fBmonDigiArray)
228 nrBmonDigis = fBmonDigiArray->GetEntriesFast();
229 LOG(debug) << "BmonDigis: " << nrBmonDigis;
230
231 /*
232 Int_t nrStsDigis = fDigiMan->GetNofDigis( ECbmModuleId::kSts);
233 Int_t nrMuchDigis = fDigiMan->GetNofDigis( ECbmModuleId::kMuch);
234 Int_t nrTrdDigis = fDigiMan->GetNofDigis( ECbmModuleId::kTrd);
235 Int_t nrTofDigis = fDigiMan->GetNofDigis( ECbmModuleId::kTof);
236 Int_t nrRichDigis = fDigiMan->GetNofDigis( ECbmModuleId::kRich);
237 Int_t nrPsdDigis = fDigiMan->GetNofDigis( ECbmModuleId::kPsd);
238*/
239
241 for (Int_t iBmon = 0; iBmon < nrBmonDigis; ++iBmon) {
242
243 if (iBmon % 1000 == 0) LOG(debug) << "Executing entry " << iBmon;
244
245 const CbmTofDigi* BmonDigi = nullptr;
246 if (fBmonDigiVector) BmonDigi = &(fBmonDigiVector->at(iBmon));
247 else if (fBmonDigiArray)
248 BmonDigi = dynamic_cast<CbmTofDigi*>(fBmonDigiArray->At(iBmon));
249 assert(BmonDigi);
250
251 Double_t T0Time = BmonDigi->GetTime();
252 // Int_t BmonAddress = BmonDigi->GetAddress();
253
254 Double_t T0TimeDiff = T0Time - fPrevTimeBmon;
255
256 if (0 < iBmon) {
257 fBmonBmonDiff->Fill(T0TimeDiff);
258 if (0 < T0TimeDiff) {
259 fBmonBmonSameTime->Fill(0);
260 fBmonBmonDiffLog->Fill(T0TimeDiff);
261 } // if( 0 < T0TimeDiff)
262 else
263 fBmonBmonSameTime->Fill(1);
264 } // if( 0 < iBmon )
265
266 fPrevTimeBmon = T0Time;
267 } // for( Int_t iBmon = 0; iBmon < nrBmonDigis; ++iBmon )
268
278
279 fNrTs++;
280
281 if (0 < fNrTs && 0 == fNrTs % 90000) WriteHistos();
282}
283
284
285template<class Digi>
286void CbmMcbm2019CheckDtInDet::FillHistosPerDet(TH1* histoSameTime, TH1* histoDt, TH1* histoDtLog,
287 TH2* /*histoDtPerChan*/, ECbmModuleId iDetId)
288{
289 UInt_t uNrDigis = fDigiMan->GetNofDigis(iDetId);
290
291 Double_t dPrevTime = -1;
292
293 for (UInt_t uDigiIdx = 0; uDigiIdx < uNrDigis; ++uDigiIdx) {
294 const Digi* digi = fDigiMan->Get<Digi>(uDigiIdx);
295
296 Double_t dNewDigiTime = digi->GetTime();
297
298 if (0 < uDigiIdx) {
299 Double_t dTimeDiff = dNewDigiTime - dPrevTime;
300
301 histoDt->Fill(dTimeDiff);
302 if (0 < dTimeDiff) {
303 histoSameTime->Fill(0);
304 histoDtLog->Fill(dTimeDiff);
305 } // if( 0 < dTimeDiff )
306 else
307 histoSameTime->Fill(1);
308 } //
309 /*
311 switch( iDetId )
312 {
313 case kSts: ///< Silicon Tracking System
314 {
315 const CbmStsDigi* stsDigi;
316 try {
317 stsDigi =
318 boost::any_cast<const CbmStsDigi*>( digi );
319 } catch( ... ) {
320 LOG( fatal ) << "Failed boost any_cast in CbmMcbm2019CheckPulser::FillSystemOffsetHistos for a digi of type "
321 << Digi::GetClassName();
322 } // try/catch
323 assert(stsDigi);
324 UInt_t uAddr = stsDigi->GetAddress();
325 UInt_t uChan = stsDigi->GetChannel();
326
327 break;
328 } // case kSts:
329 case kMuch: ///< Muon detection system
330 {
331 const CbmMuchBeamTimeDigi* muchDigi;
332 try {
333 muchDigi =
334 boost::any_cast<const CbmMuchBeamTimeDigi*>( digi );
335 } catch( ... ) {
336 LOG( fatal ) << "Failed boost any_cast in CbmMcbm2019CheckPulser::FillSystemOffsetHistos for a digi of type "
337 << Digi::GetClassName();
338 } // try/catch
339 assert(muchDigi);
340 UInt_t uAsic = muchDigi->GetNxId();
341 UInt_t uChan = muchDigi->GetNxCh();
342
343 break;
344 } // case kMuch:
345 case kTrd: ///< Time-of-flight Detector
346 {
347 UInt_t uAddr = digi->GetAddress();
348 break;
349 } // case kTrd:
350 case kTof: ///< Time-of-flight Detector
351 {
352
353 break;
354 } // case kTof:
355 case kRich: ///< Ring-Imaging Cherenkov Detector
356 {
357
358 break;
359 } // case kRich:
360 case kPsd: ///< Projectile spectator detector
361 {
362 UInt_t uAddr = digi->GetAddress();
363
364 break;
365 } // case kPsd:
366 default:
367 return 0;
368 } // switch( iDetId )
369*/
370 dPrevTime = dNewDigiTime;
371 } // for( UInt_t uDigiIdx = 0; uDigiIdx < uNrDigis; ++uDigiIdx )
372}
373
374// ---- Finish --------------------------------------------------------
376
378{
379 TFile* oldFile = gFile;
380 TDirectory* oldDir = gDirectory;
381
382
383 TFile* outfile = TFile::Open(fOutFileName, "RECREATE");
384
385 fBmonBmonSameTime->Write();
386 fStsStsSameTime->Write();
387 fMuchMuchSameTime->Write();
388 fTrdTrdSameTime->Write();
389 fTofTofSameTime->Write();
390 fRichRichSameTime->Write();
391 fPsdPsdSameTime->Write();
392
393 fBmonBmonDiff->Write();
394 fStsStsDiff->Write();
395 fMuchMuchDiff->Write();
396 fTrdTrdDiff->Write();
397 fTofTofDiff->Write();
398 fRichRichDiff->Write();
399 fPsdPsdDiff->Write();
400
401 fBmonBmonDiffLog->Write();
402 fStsStsDiffLog->Write();
403 fMuchMuchDiffLog->Write();
404 fTrdTrdDiffLog->Write();
405 fTofTofDiffLog->Write();
406 fRichRichDiffLog->Write();
407 fPsdPsdDiffLog->Write();
408
409 fBmonBmonDiffPerChan->Write();
410 fStsStsDiffPerChan->Write();
411 fMuchMuchDiffPerChan->Write();
412 fTrdTrdDiffPerChan->Write();
413 fTofTofDiffPerChan->Write();
414 fRichRichDiffPerChan->Write();
415 fPsdPsdDiffPerChan->Write();
416
417 outfile->Close();
418 delete outfile;
419
420 gFile = oldFile;
421 gDirectory = oldDir;
422}
423
ClassImp(CbmConverterManager)
ECbmModuleId
Definition CbmDefs.h:39
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kRich
Ring-Imaging Cherenkov Detector.
std::vector< double > GenerateLogBinArray(uint32_t uNbDecadesLog, uint32_t uNbStepsDecade, uint32_t uNbSubStepsInStep, uint32_t &uNbBinsLog, int32_t iStartExp, bool bAddZeroStart)
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
void UseMuchBeamTimeDigi(Bool_t)
Use CbmMuchBeamTimeDigi instead of CbmMuchDigi for MUCH.
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
UInt_t fuNbChanBmon
User settings: Data correction parameters.
const std::vector< CbmTofDigi > * fBmonDigiVector
Double_t fPrevTimeBmon
Variables to store the previous digi time.
virtual void Exec(Option_t *)
void FillHistosPerDet(TH1 *histoSameTime, TH1 *histoDt, TH1 *histoDtLog, TH2 *histoDtPerChan, ECbmModuleId iDetId=ECbmModuleId::kLastModule)
Data class for expanded digital TOF information.
Definition CbmTofDigi.h:47
double GetTime() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:131