CbmRoot
Loading...
Searching...
No Matches
CbmMcbmCheckTimingAlgo.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020-2024 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer], Andreas Redelbach, Alexandru Bercuci */
4
6
7#include "CbmBmonDigi.h"
8#include "CbmDigiManager.h"
10#include "CbmMuchBeamTimeDigi.h"
11#include "CbmPsdDigi.h"
12#include "CbmRichDigi.h"
13#include "CbmStsDigi.h"
14#include "CbmTofDigi.h"
15#include "CbmTrdDigi.h"
16
17#include <FairRootManager.h>
18#include <FairRunOnline.h>
19#include <Logger.h>
20
21#include <TDirectory.h>
22#include <TF1.h>
23#include <TFile.h>
24#include <TH1.h>
25#include <TH2.h>
26#include <THttpServer.h>
27
28#include <iomanip>
29#include <iostream>
30using std::fixed;
31using std::setprecision;
32
33// ---- Default constructor -------------------------------------------
35
36// ---- Destructor ----------------------------------------------------
38
39// ---- Initialisation ----------------------------------------------
41{
42 // Load all necessary parameter containers from the runtime data base
43 /*
44 FairRunAna* ana = FairRunAna::Instance();
45 FairRuntimeDb* rtdb=ana->GetRuntimeDb();
46
47 <CbmMcbmCheckTimingAlgoDataMember> = (<ClassPointer>*)
48 (rtdb->getContainer("<ContainerName>"));
49 */
50}
51
52// ---- Init ----------------------------------------------------------
54{
59 for (std::vector<CheckTimingDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
61 } // for( std::vector< CheckTimingDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
62
65 fCbmTsEventHeader = FairRootManager::Instance()->InitObjectAs<CbmTsEventHeader const*>("EventHeader.");
66 if (nullptr != fCbmTsEventHeader) {
67 LOG(info) << "CbmMcbmCheckTimingAlgo => Using the index from the TS Event header for Evo plots";
68 }
69
71
72 return kTRUE;
73}
74
76{
77 // Get a handle from the IO manager
78 FairRootManager* ioman = FairRootManager::Instance();
81 fDigiMan->Init();
82
84 if (ECbmModuleId::kBmon == detToCheck.detId) {
85 // Get a pointer to the previous already existing data level
86 fpBmonDigiVec = ioman->InitObjectAs<std::vector<CbmBmonDigi> const*>("BmonDigi");
87 if (!fpBmonDigiVec) {
88 LOG(fatal) << "No storage with Bmon digis found while it should be used. "
89 "Stopping there!";
90 } // if ( ! fpBmonDigiVec )
91 } // if( ECbmModuleId::kBmon == detToCheck.detId )
92 else if (!fDigiMan->IsPresent(detToCheck.detId)) {
93 LOG(fatal) << "No " << detToCheck.sName << " digis found while it should be used. Stopping there!";
94 } // else if ( ! fDigiMan->IsPresent( detToCheck.detId ) ) of if( ECbmModuleId::kBmon == detToCheck.detId )
95}
96
98{
100 uint32_t iNbBinsLog = 0;
102 std::vector<double> dBinsLogVector = GenerateLogBinArray( 9, 9, 1, iNbBinsLog );
103 double* dBinsLog = dBinsLogVector.data();
104
105 for( std::vector< CheckTimingDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
106 {
107 for (uint i(0); i < (*det).uNviews; i++) {
108 fvhDetSelfDiff[(*det).detId].push_back(
109 new TH1D(Form("h%sSelfDiff%d", (*det).sName.data(), i),
110 Form("time difference between consecutivs %s (%s) Digis;time diff [ns];Counts", (*det).sName.data(),
111 (*det).vName[i].data()),
112 iNbBinsLog, dBinsLog));
113
114 fvhDetToRefDiff[(*det).detId].push_back(
115 new TH1D(Form("h%s%sDiff%d", (*det).sName.data(), fRefDet.sName.data(), i),
116 Form("%s(%s) - %s time difference;time diff [ns];Counts", (*det).sName.data(), (*det).vName[i].data(),
117 fRefDet.sName.data()),
118 (*det).uRangeNbBins, (*det).dTimeRangeBeg, (*det).dTimeRangeEnd));
119
120 fvhDetToRefDiffRefCharge[(*det).detId].push_back(
121 new TH2F(Form("h%s%sDiffRefCharge%d", (*det).sName.data(), fRefDet.sName.data(), i),
122 Form("%s(%s) - %s;time diff [ns]; %s Charge [a.u]; Counts", (*det).sName.data(),
123 (*det).vName[i].data(), fRefDet.sName.data(), fRefDet.sName.data()),
124 (*det).uRangeNbBins, (*det).dTimeRangeBeg, (*det).dTimeRangeEnd, 256, 0, 256));
125
126 fvhDetToRefDiffDetCharge[(*det).detId].push_back(
127 new TH2F(Form("h%s%sDiffDetCharge%d", (*det).sName.data(), fRefDet.sName.data(), i),
128 Form("%s(%s) - %s;time diff [ns]; %s(%s) Charge [a.u]; Counts", (*det).sName.data(),
129 (*det).vName[i].data(), fRefDet.sName.data(), (*det).sName.data(), (*det).vName[i].data()),
130 (*det).uRangeNbBins, (*det).dTimeRangeBeg, (*det).dTimeRangeEnd, 256, 0, 256));
131
132 fvhDetToRefDiffEvo[(*det).detId].push_back(
133 new TH2F(Form("h%s%sDiffEvo%d", (*det).sName.data(), fRefDet.sName.data(), i),
134 Form("%s(%s) - %s;TS; time diff [ns];Counts", (*det).sName.data(), (*det).vName[i].data(),
135 fRefDet.sName.data()),
136 10000, -0.5, 10000 - 0.5, (*det).uRangeNbBins, (*det).dTimeRangeBeg, (*det).dTimeRangeEnd));
137
138 fvhDetToRefDiffEvoLong[(*det).detId].push_back(
139 new TH2F(Form("h%s%sDiffEvoLong%d", (*det).sName.data(), fRefDet.sName.data(), i),
140 Form("%s(%s) - %s;TS; time diff [ns];Counts", (*det).sName.data(), (*det).vName[i].data(),
141 fRefDet.sName.data()),
142 1800, 0, 18000, (*det).uRangeNbBins, (*det).dTimeRangeBeg, (*det).dTimeRangeEnd));
143 }
144 LOG( info ) << "Created histos for " << (*det).sName;
145 } // for( std::vector< CheckTimingDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
146
148 fvhDetSelfDiff[fRefDet.detId].push_back(
149 new TH1D(Form("h%sSelfDiff", fRefDet.sName.data()),
150 Form("time difference between consecutivs %s Digis;time diff [ns];Counts", fRefDet.sName.data()),
151 iNbBinsLog, dBinsLog));
152
154 FairRunOnline* run = FairRunOnline::Instance();
155 if( run )
156 {
157 THttpServer* server = run->GetHttpServer();
158 if( nullptr != server )
159 {
161 for (auto uDetIdx : fvDets) {
162 server->Register("/CheckTiming/SelfDiff", fvhDetSelfDiff[uDetIdx.detId][0]);
163 server->Register("/CheckTiming/RefDiff", fvhDetToRefDiff[uDetIdx.detId][0]);
164 server->Register("/CheckTiming/DiffCharge", fvhDetToRefDiffRefCharge[uDetIdx.detId][0]);
165 server->Register("/CheckTiming/DiffCharge", fvhDetToRefDiffDetCharge[uDetIdx.detId][0]);
166 server->Register("/CheckTiming/DiffEvo", fvhDetToRefDiffEvo[uDetIdx.detId][0]);
167 server->Register("/CheckTiming/DiffEvo", fvhDetToRefDiffEvoLong[uDetIdx.detId][0]);
168 } // for( std::vector< CheckTimingDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
169
171 server->Register("/CheckTiming/SelfDiff", fvhDetSelfDiff[fRefDet.detId][0]);
172 } // if( nullptr != server )
173 } // if( run )
174}
175// ---- ReInit -------------------------------------------------------
176Bool_t CbmMcbmCheckTimingAlgo::ReInit() { return kTRUE; }
177
178// ---- Exec ----------------------------------------------------------
180{
181 LOG(info) << "executing TS " << fuNbTs << " index ["
182 << (fCbmTsEventHeader != nullptr ? fCbmTsEventHeader->GetTsIndex() : -1) << "]";
183
184 switch (fRefDet.detId) {
185 case ECbmModuleId::kSts: {
187 break;
188 } // case ECbmModuleId::kSts:
189 case ECbmModuleId::kMuch: {
191 break;
192 } // case ECbmModuleId::kMuch:
193 case ECbmModuleId::kTrd: {
195 break;
196 } // case ECbmModuleId::kTrd:
199 break;
200 } // case ECbmModuleId::kTrd2d:
201 case ECbmModuleId::kTof: {
203 break;
204 } // case ECbmModuleId::kTof:
205 case ECbmModuleId::kRich: {
207 break;
208 } // case ECbmModuleId::kRich:
209 case ECbmModuleId::kPsd: {
211 break;
212 } // case ECbmModuleId::kPsd:
213 case ECbmModuleId::kBmon: {
215 break;
216 } // case ECbmModuleId::kBmon:
217 default: {
218 LOG(fatal) << "CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
219 << "Trying to search matches with unsupported det: " << fRefDet.sName;
220 break;
221 } // default:
222 } // switch( fRefDet )
223
224 fuNbTs++;
225}
226
227template<class DigiRef>
229{
230 UInt_t uNbRefDigis = 0;
231 switch (fRefDet.detId) {
233 LOG(fatal) << "CbmMcbmCheckTimingAlgo::Exec => Unknow reference detector enum! " << fRefDet.sName;
234 break;
235 } // Digi containers controlled by DigiManager
236 case ECbmModuleId::kBmon: {
237 uNbRefDigis = fpBmonDigiVec->size();
238 break;
239 } // case ECbmModuleId::kBmon
240 default: {
241 uNbRefDigis = fDigiMan->GetNofDigis(fRefDet.detId);
242 break;
243 } // default:
244 } // switch( fRefDet.detId )
245
247 for (std::vector<CheckTimingDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
248 (*det).iPrevRefFirstDigi = 0;
249 } // for( std::vector< CheckTimingDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
250
251 for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
252 //LOG(debug) << Form("Checking seed %6u / %6u", uDigi, uNbRefDigis);
253
254 Double_t dRefTime = 0;
255 Double_t dRefCharge = 0;
256 UInt_t uRefAddress = 0;
258 dRefTime = fpBmonDigiVec->at(uDigi).GetTime();
259 dRefCharge = fpBmonDigiVec->at(uDigi).GetCharge();
260 }
261 else {
262 dRefTime = fDigiMan->Get<DigiRef>(uDigi)->GetTime();
263 dRefCharge = fDigiMan->Get<DigiRef>(uDigi)->GetCharge();
264 uRefAddress = fDigiMan->Get<DigiRef>(uDigi)->GetAddress();
265 } // else of if( ECbmModuleId::kBmon == fRefDet.detId )
266
268 (fvhDetSelfDiff[fRefDet.detId])[0]->Fill(dRefTime - fRefDet.dPrevTime);
269 fRefDet.dPrevTime = dRefTime;
270
275 if (fRefDet.uChargeCutMin < dRefCharge && dRefCharge < fRefDet.uChargeCutMax) {
276 continue;
277 } // if( fRefDet.uChargeCutMin < dRefCharge && dRefCharge < fRefDet.uChargeCutMax )
278 } // if( fRefDet.uChargeCutMin < fRefDet.uChargeCutMax )
279 else {
281 if (fRefDet.uChargeCutMin < dRefCharge || dRefCharge < fRefDet.uChargeCutMax) {
282 continue;
283 } // if( fRefDet.uChargeCutMin < dRefCharge || dRefCharge < fRefDet.uChargeCutMax )
285 if (ECbmModuleId::kPsd == fRefDet.detId && CbmPsdAddress::GetSectionId(uRefAddress) != 10) continue;
286 } // else of if( fRefDet.uChargeCutMin < fRefDet.uChargeCutMax )
287 } // if( fRefDet.uChargeCutMin =! fRefDet.uChargeCutMax )
288
290 for (UInt_t uDetIdx = 0; uDetIdx < fvDets.size(); ++uDetIdx) {
291 switch (fvDets[uDetIdx].detId) {
292 case ECbmModuleId::kSts: {
293 FillTimeOffsetHistos<CbmStsDigi>(dRefTime, dRefCharge, uDetIdx);
294 break;
295 } // case ECbmModuleId::kSts:
296 case ECbmModuleId::kMuch: {
297 FillTimeOffsetHistos<CbmMuchBeamTimeDigi>(dRefTime, dRefCharge, uDetIdx);
298 break;
299 } // case ECbmModuleId::kMuch:
300 case ECbmModuleId::kTrd: {
301 FillTimeOffsetHistos<CbmTrdDigi>(dRefTime, dRefCharge, uDetIdx);
302 break;
303 } // case ECbmModuleId::kTrd:
305 FillTimeOffsetHistos<CbmTrdDigi>(dRefTime, dRefCharge, uDetIdx);
306 break;
307 } // case ECbmModuleId::kTrd:
308 case ECbmModuleId::kTof: {
309 FillTimeOffsetHistos<CbmTofDigi>(dRefTime, dRefCharge, uDetIdx);
310 break;
311 } // case ECbmModuleId::kTof:
312 case ECbmModuleId::kRich: {
313 FillTimeOffsetHistos<CbmRichDigi>(dRefTime, dRefCharge, uDetIdx);
314 break;
315 } // case ECbmModuleId::kRich:
316 case ECbmModuleId::kPsd: {
317 FillTimeOffsetHistos<CbmPsdDigi>(dRefTime, dRefCharge, uDetIdx);
318 break;
319 } // case ECbmModuleId::kPsd:
320 case ECbmModuleId::kBmon: {
321 FillTimeOffsetHistos<CbmBmonDigi>(dRefTime, dRefCharge, uDetIdx);
322 break;
323 } // case ECbmModuleId::kBmon:
324 default: {
325 LOG(fatal) << "CbmMcbmCheckTimingAlgo::CheckInterSystemOffset => "
326 << "Trying to search matches with unsupported det: " << fvDets[uDetIdx].sName;
327 break;
328 } // default:
329 } // switch( fvDets[ uDetIdx ].detId )
330 } // for( UInt_t uDetIdx = 0; uDetIdx < fvDets.size(); ++uDetIdx )
331 } // for( UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi )
332}
333
334template<class Digi>
335void CbmMcbmCheckTimingAlgo::FillTimeOffsetHistos(const Double_t dRefTime, const Double_t dRefCharge, UInt_t uDetIdx)
336{
337 UInt_t uNbDigis = 0;
338 ECbmModuleId edetId = fvDets[uDetIdx].detId;
339 switch (edetId) {
341 LOG(fatal) << "CbmMcbmCheckTimingAlgo::FillTimeOffsetHistos => Unknow "
342 "detector enum! "
343 << fRefDet.sName;
344 break;
345 } // Digi containers controlled by DigiManager
346 case ECbmModuleId::kBmon: {
347 uNbDigis = fpBmonDigiVec->size();
348 break;
349 } // case ECbmModuleId::kBmon
350 default: {
351 uNbDigis = fDigiMan->GetNofDigis(edetId);
352 break;
353 } // default:
354 } // switch( fRefDet.detId )
355
356 UInt_t uFirstDigiInWin = fvDets[uDetIdx].iPrevRefFirstDigi;
357
358 bool exit = false;
359 std::vector<Double_t> vSelDiff = {};
360 std::vector<std::tuple<double, double, uint>> vDigiInfo = {}; // digi info containing (time, charge, address)
361 for (UInt_t uDigiIdx = fvDets[uDetIdx].iPrevRefFirstDigi; uDigiIdx < uNbDigis; ++uDigiIdx) {
362 if (!GetDigiInfo<Digi>(uDigiIdx, &vDigiInfo, edetId)) continue;
363 for (auto dInfo : vDigiInfo) {
364 Double_t dTime = std::get<0>(dInfo);
365 Double_t dCharge = std::get<1>(dInfo);
366 UInt_t uAddress = std::get<2>(dInfo);
367
370 if (fvDets[uDetIdx].dPrevTime <= dTime) {
371 vSelDiff.push_back(dTime - fvDets[uDetIdx].dPrevTime);
372 fvDets[uDetIdx].dPrevTime = dTime;
373 } // if( fvDets[ uDetIdx ].dPrevTime < dTime )
374 Double_t dDiffTime = dTime - dRefTime;
375 if (dDiffTime < fvDets[uDetIdx].dTimeRangeBeg) {
376 ++uFirstDigiInWin; // Update Index of first digi in Win to next digi
377 //continue; // not yet in interesting range
378 break; // not yet in interesting range
379 } // if (diffTime > offsetRange)
380 if (fvDets[uDetIdx].dTimeRangeEnd < dDiffTime) {
381 exit = true;
383 break;
384 } // if( fvDets[ uDetIdx ].dTimeRangeEnd < dDiffTime )
385
387 if (fvDets[uDetIdx].uChargeCutMin != fvDets[uDetIdx].uChargeCutMax) {
388 if (fvDets[uDetIdx].uChargeCutMin < fvDets[uDetIdx].uChargeCutMax) {
390 if (fvDets[uDetIdx].uChargeCutMin < dCharge && dCharge < fvDets[uDetIdx].uChargeCutMax) {
391 continue;
392 } // if( fvDets[ uDetIdx ].uChargeCutMin < dCharge && dCharge < fvDets[ uDetIdx ].uChargeCutMax )
393 } // if( fvDets[ uDetIdx ].uChargeCutMin < fvDets[ uDetIdx ].uChargeCutMax )
394 else {
396 if (fvDets[uDetIdx].uChargeCutMin < dCharge || dCharge < fvDets[uDetIdx].uChargeCutMax) {
397 continue;
398 } // if( fvDets[ uDetIdx ].uChargeCutMin < dCharge || dCharge < fvDets[ uDetIdx ].uChargeCutMax )
400 if (ECbmModuleId::kPsd == fvDets[uDetIdx].detId && CbmPsdAddress::GetSectionId(uAddress) != 10) continue;
401 } // else of if( fvDets[ uDetIdx ].uChargeCutMin < fvDets[ uDetIdx ].uChargeCutMax )
402 } // if( fvDets[ uDetIdx ].uChargeCutMin != fvDets[ uDetIdx ].uChargeCutMax )
403
404 int uid = GetViewId<Digi>(fvDets[uDetIdx], dInfo);
405 if (uid < 0 || uint(uid) >= fvDets[uDetIdx].uNviews) continue;
406
408 for (auto dt : vSelDiff)
409 fvhDetSelfDiff[edetId][uid]->Fill(dt);
410 vSelDiff.clear();
411
412 fvhDetToRefDiff[edetId][uid]->Fill(dDiffTime);
413 fvhDetToRefDiffRefCharge[edetId][uid]->Fill(dDiffTime, dRefCharge);
414 fvhDetToRefDiffDetCharge[edetId][uid]->Fill(dDiffTime, dCharge);
415 if (nullptr == fCbmTsEventHeader) {
416 fvhDetToRefDiffEvo[edetId][uid]->Fill(fuNbTs, dDiffTime);
417 fvhDetToRefDiffEvoLong[edetId][uid]->Fill(fuNbTs, dDiffTime);
418 }
419 else {
420 fvhDetToRefDiffEvo[edetId][uid]->Fill(fCbmTsEventHeader->GetTsIndex(), dDiffTime);
421 fvhDetToRefDiffEvoLong[edetId][uid]->Fill(fCbmTsEventHeader->GetTsIndex(), dDiffTime);
422 }
423 } // for (auto dInfo : vDigiInfo) {
424 if (exit) break;
425 } // for( UInt_t uDigiIdx = fvDets[ uDetIdx ].iPrevRefFirstDigi; uDigiIdx < uNbDigis; ++uDigiIdx )
426
428 fvDets[uDetIdx].iPrevRefFirstDigi = uFirstDigiInWin;
429}
430
431// ---- GetDigiInfo ------------------------------------------------------
432template<class Digi>
433uint CbmMcbmCheckTimingAlgo::GetDigiInfo(UInt_t uDigi, std::vector<std::tuple<double, double, uint>>* vec, ECbmModuleId)
434{
435 const Digi* digi = fDigiMan->Get<Digi>(uDigi);
436 vec->clear();
437 if (digi == nullptr) return 0;
438 vec->push_back(std::make_tuple(digi->GetTime(), digi->GetCharge(), digi->GetAddress()));
439 return 1;
440}
441// --- STS specific digi info ---------------------
442template<>
443uint CbmMcbmCheckTimingAlgo::GetDigiInfo<CbmStsDigi>(UInt_t uDigi, std::vector<std::tuple<double, double, uint>>* vec,
445{
446 const CbmStsDigi* digi = fDigiMan->Get<CbmStsDigi>(uDigi);
447 vec->clear();
448 if (digi == nullptr) return 0;
449 int32_t add = digi->GetAddress(), uId(CbmStsAddress::GetElementId(add, EStsElementLevel::kStsUnit)),
452 vec->push_back(std::make_tuple(digi->GetTime(), digi->GetCharge(), uId * 10 + lId * 3 + mId));
453 return 1;
454}
455// --- TRD(1D,2D) specific digi info ---------------------
456template<>
457uint CbmMcbmCheckTimingAlgo::GetDigiInfo<CbmTrdDigi>(UInt_t uDigi, std::vector<std::tuple<double, double, uint>>* vec,
459{
462 vec->clear();
463 const CbmTrdDigi* trdDigi = fDigiMan->Get<CbmTrdDigi>(uDigi);
464 if (trdDigi == nullptr) return 0;
465
466 double dt = trdDigi->GetTime();
467
469 vec->push_back(std::make_tuple(trdDigi->GetTime(), trdDigi->GetCharge(), trdDigi->GetAddressModule()));
470 return 1;
471 }
472
473 int toff(0);
474 uint n(0);
475 double t, r = trdDigi->GetCharge(t, toff);
476 if (toff < 0) { // keep increasing order in time of digi
477 double tmp = t;
478 t = r;
480 r = tmp;
481 toff = -toff;
482 }
483 if (t > 0) {
484 vec->push_back(std::make_tuple(dt, t / 20., trdDigi->GetAddressModule()));
485 n++;
486 }
487 if (r > 0) {
488 vec->push_back(std::make_tuple(dt + toff * CbmTrdDigi::Clk(CbmTrdDigi::eCbmTrdAsicType::kFASP), r / 20.,
489 trdDigi->GetAddressModule()));
490 n++;
491 }
492 return n;
493}
494// --- ToF specific digi info ---------------------
495template<>
496uint CbmMcbmCheckTimingAlgo::GetDigiInfo<CbmTofDigi>(UInt_t uDigi, std::vector<std::tuple<double, double, uint>>* vec,
498{
499 const CbmTofDigi* digi = fDigiMan->Get<CbmTofDigi>(uDigi);
500 vec->clear();
501 if (digi == nullptr) return 0;
502 int32_t add = digi->GetAddress(), smID(CbmTofAddress::GetSmId(add)), smTyp(CbmTofAddress::GetSmType(add)),
503 rpcID(CbmTofAddress::GetRpcId(add));
504 // chID(CbmTofAddress::GetChannelId(add))
505 // chSd(CbmTofAddress::GetChannelSide(add));
506 vec->push_back(std::make_tuple(digi->GetTime(), digi->GetCharge(), smTyp * 100 + smID * 10 + rpcID));
507 return 1;
508}
509
510// ---- GetViewId ------------------------------------------------------
511template<class Digi>
512int CbmMcbmCheckTimingAlgo::GetViewId(CheckTimingDetector det, std::tuple<double, double, uint> info)
513{
514 if (det.vName.size() == 1) return 0;
515
516 uint modId = std::get<2>(info);
517 uint iview = 0;
518 for (auto view : det.vName) {
519 if (view.compare(std::to_string(modId)) == 0) return iview;
520 iview++;
521 }
522
523 std::string sFullId = det.sName + " mod " + std::to_string(modId);
524 if (0 == fUnimplementedView[det.detId].count(sFullId)) {
525 LOG(warning) << det.sName << " condition not implemented for " << sFullId << ". Skipping it from now on.";
526 fUnimplementedView[det.detId].insert(sFullId);
527 }
528 return -1;
529}
530
531// ---- Finish --------------------------------------------------------
532void CbmMcbmCheckTimingAlgo::Finish() { LOG(info) << Form("Checked %6d Timeslices", fuNbTs); }
533
535{
536 TFile* oldFile = gFile;
537 TDirectory* oldDir = gDirectory;
538
539 TFile* outfile = TFile::Open(fOutFileName, "RECREATE");
540
541 for (auto uDet : fvDets) {
542 LOG(debug) << "Saving histos for " << uDet.sName;
543 outfile->mkdir(uDet.sName.data());
544 outfile->cd(uDet.sName.data());
545 for (uint id(0); id < uDet.uNviews; id++)
546 fvhDetSelfDiff[uDet.detId][id]->Write();
547 for (uint id(0); id < uDet.uNviews; id++)
548 fvhDetToRefDiffRefCharge[uDet.detId][id]->Write();
549 for (uint id(0); id < uDet.uNviews; id++)
550 fvhDetToRefDiffDetCharge[uDet.detId][id]->Write();
551 for (uint id(0); id < uDet.uNviews; id++)
552 fvhDetToRefDiffEvo[uDet.detId][id]->Write();
553 for (uint id(0); id < uDet.uNviews; id++)
554 fvhDetToRefDiffEvoLong[uDet.detId][id]->Write();
555 for (uint id(0); id < uDet.uNviews; id++) {
556 LOG(debug) << "WriteHistos, Det, entries = " << uDet.sName << " "
557 << fvhDetToRefDiff[uDet.detId][id]->GetEntries();
558 LOG(info) << "Saved histos for " << uDet.sName << "(" << uDet.vName[id] << ")";
560 fvhDetToRefDiff[uDet.detId][id]->GetMaximumBin() * fvhDetToRefDiff[uDet.detId][id]->GetBinWidth(1)
561 + fvhDetToRefDiff[uDet.detId][id]->GetXaxis()->GetXmin();
562 DetAverageSingle = (fvhDetToRefDiff[uDet.detId][id]->Integral()) / (fvhDetToRefDiff[uDet.detId][id]->GetNbinsX());
563
564 switch (uDet.detId) {
565 case ECbmModuleId::kSts: {
566 if (DetAverageSingle > 0) {
567 TF1* gs_sts = new TF1("gs_sts", "gaus(0)+pol0(3)", DetPeakPosSingle - 2 * fStsPeakWidthNs,
570 fvhDetToRefDiff[uDet.detId][id]->Fit("gs_sts", "R");
571 TF1* fitresult_sts = fvhDetToRefDiff[uDet.detId][id]->GetFunction("gs_sts");
572 LOG(debug) << uDet.sName << " parameters from Gauss fit = " << fitresult_sts->GetParameter(0) << ", "
573 << fitresult_sts->GetParameter(1) << ", " << fitresult_sts->GetParameter(2);
574 }
575 break;
576 }
577 case ECbmModuleId::kMuch: {
578 if (DetAverageSingle > 0) {
579 TF1* gs_much = new TF1("gs_much", "gaus(0)+pol0(3)", DetPeakPosSingle - 2 * fMuchPeakWidthNs,
582 fvhDetToRefDiff[uDet.detId][id]->Fit("gs_much", "R");
583 TF1* fitresult_much = fvhDetToRefDiff[uDet.detId][id]->GetFunction("gs_much");
584 LOG(debug) << uDet.sName << " parameters from Gauss fit = " << fitresult_much->GetParameter(0) << ", "
585 << fitresult_much->GetParameter(1) << ", " << fitresult_much->GetParameter(2);
586 }
587 break;
588 }
589 case ECbmModuleId::kTrd: {
590 if (DetAverageSingle > 0) {
591 TF1* gs_trd = new TF1("gs_trd", "gaus(0)+pol0(3)", DetPeakPosSingle - 2 * fTrdPeakWidthNs,
594 fvhDetToRefDiff[uDet.detId][id]->Fit("gs_trd", "R");
595 TF1* fitresult_trd = fvhDetToRefDiff[uDet.detId][id]->GetFunction("gs_trd");
596 LOG(debug) << uDet.sName << " parameters from Gauss fit = " << fitresult_trd->GetParameter(0) << ", "
597 << fitresult_trd->GetParameter(1) << ", " << fitresult_trd->GetParameter(2);
598 }
599 break;
600 }
601 case ECbmModuleId::kBmon: {
602 if (DetAverageSingle > 0) {
603 TF1* gs_tof = new TF1("gs_tof", "gaus(0)+pol0(3)", DetPeakPosSingle - 2 * fTofPeakWidthNs,
606 fvhDetToRefDiff[uDet.detId][id]->Fit("gs_tof", "R");
607 TF1* fitresult_tof = fvhDetToRefDiff[uDet.detId][id]->GetFunction("gs_tof");
608 LOG(debug) << uDet.sName << " parameters from Gauss fit = " << fitresult_tof->GetParameter(0) << ", "
609 << fitresult_tof->GetParameter(1) << ", " << fitresult_tof->GetParameter(2);
610 }
611 break;
612 }
613 case ECbmModuleId::kTof: {
614 if (DetAverageSingle > 0) {
615 TF1* gs_tof = new TF1("gs_tof", "gaus(0)+pol0(3)", DetPeakPosSingle - 2 * fTofPeakWidthNs,
618 fvhDetToRefDiff[uDet.detId][id]->Fit("gs_tof", "R");
619 TF1* fitresult_tof = fvhDetToRefDiff[uDet.detId][id]->GetFunction("gs_tof");
620 LOG(debug) << uDet.sName << " parameters from Gauss fit = " << fitresult_tof->GetParameter(0) << ", "
621 << fitresult_tof->GetParameter(1) << ", " << fitresult_tof->GetParameter(2);
622 }
623 break;
624 }
625 case ECbmModuleId::kRich: {
626 if (DetAverageSingle > 0) {
627 TF1* gs_rich = new TF1("gs_rich", "gaus(0)+pol0(3)", DetPeakPosSingle - 2 * fRichPeakWidthNs,
630 fvhDetToRefDiff[uDet.detId][id]->Fit("gs_rich", "R");
631 TF1* fitresult_rich = fvhDetToRefDiff[uDet.detId][id]->GetFunction("gs_rich");
632 LOG(debug) << uDet.sName << " parameters from Gauss fit = " << fitresult_rich->GetParameter(0) << ", "
633 << fitresult_rich->GetParameter(1) << ", " << fitresult_rich->GetParameter(2);
634 }
635 break;
636 }
637 case ECbmModuleId::kPsd: {
638 if (DetAverageSingle > 0) {
639 TF1* gs_psd = new TF1("gs_psd", "gaus(0)+pol0(3)", DetPeakPosSingle - 2 * fPsdPeakWidthNs,
642 fvhDetToRefDiff[uDet.detId][id]->Fit("gs_psd", "R");
643 TF1* fitresult_psd = fvhDetToRefDiff[uDet.detId][id]->GetFunction("gs_psd");
644 LOG(debug) << uDet.sName << " parameters from Gauss fit = " << fitresult_psd->GetParameter(0) << ", "
645 << fitresult_psd->GetParameter(1) << ", " << fitresult_psd->GetParameter(2);
646 }
647 break;
648 }
649 default: {
650 LOG(info) << "Detector ID for fitting is not valid.";
651 break;
652 }
653 }
654 fvhDetToRefDiff[uDet.detId][id]->Write(); //At the end in order to include fitting results in histos
655 }
656 outfile->cd();
657 } // for( std::vector< CheckTimingDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
658
660 outfile->mkdir(fRefDet.sName.data());
661 outfile->cd(fRefDet.sName.data());
662 for (uint id(0); id < fRefDet.uNviews; id++)
663 fvhDetSelfDiff[fRefDet.detId][id]->Write();
664 outfile->cd();
665
666 outfile->Close();
667 delete outfile;
668
669 gFile = oldFile;
670 gDirectory = oldDir;
671}
672
673// ---- Finish --------------------------------------------------------
674void CbmMcbmCheckTimingAlgo::SetReferenceDetector(ECbmModuleId refDetIn, std::string sNameIn, Double_t dTimeRangeBegIn,
675 Double_t dTimeRangeEndIn, UInt_t uRangeNbBinsIn,
676 UInt_t uChargeCutMinIn, UInt_t uChargeCutMaxIn)
677{
678 fRefDet.detId = refDetIn;
679 fRefDet.sName = sNameIn;
680 fRefDet.dTimeRangeBeg = dTimeRangeBegIn;
681 fRefDet.dTimeRangeEnd = dTimeRangeEndIn;
682 fRefDet.uRangeNbBins = uRangeNbBinsIn;
683 fRefDet.uChargeCutMin = uChargeCutMinIn;
684 fRefDet.uChargeCutMax = uChargeCutMaxIn;
685}
686
687void CbmMcbmCheckTimingAlgo::SetDetectorDifferential(ECbmModuleId detIn, std::vector<std::string> vName)
688{
689 bool found(false);
690 std::vector<CheckTimingDetector>::iterator det;
691 for (det = fvDets.begin(); det != fvDets.end(); ++det) {
692 if ((*det).detId != detIn) continue;
693 found = true;
694 (*det).vName = vName;
695 (*det).uNviews = vName.size();
696 break;
697 }
698
699 if (!found)
700 LOG(warning) << "CbmMcbmCheckTimingAlgo::SetDetectorDifferential => Detector not in the "
701 "list, Nothing done at this point!";
702}
703
704void CbmMcbmCheckTimingAlgo::AddCheckDetector(ECbmModuleId detIn, std::string sNameIn, Double_t dTimeRangeBegIn,
705 Double_t dTimeRangeEndIn, UInt_t uRangeNbBinsIn, UInt_t uChargeCutMinIn,
706 UInt_t uChargeCutMaxIn)
707{
708 std::vector<CheckTimingDetector>::iterator det;
709 for (det = fvDets.begin(); det != fvDets.end(); ++det) {
710 if ((*det).detId == detIn) {
711 (*det).dTimeRangeBeg = dTimeRangeBegIn;
712 (*det).dTimeRangeEnd = dTimeRangeEndIn;
713 (*det).uRangeNbBins = uRangeNbBinsIn;
714 (*det).uChargeCutMin = uChargeCutMinIn;
715 (*det).uChargeCutMax = uChargeCutMaxIn;
716 LOG(info) << "CbmMcbmCheckTimingAlgo::AddCheckDetector => Detector " << (*det).sName << " range "
717 << (*det).dTimeRangeBeg << " :: " << (*det).dTimeRangeEnd << " bins " << (*det).uRangeNbBins
718 << " charge " << (*det).uChargeCutMin << "::" << (*det).uChargeCutMax;
719 break;
720 } // if( (*det).detId == detIn )
721 } // for( det = fvDets.begin(); det != fvDets.end(); ++det )
722
723 if (fvDets.end() == det) {
724 fvDets.push_back(CheckTimingDetector(detIn, sNameIn));
725 det = fvDets.end();
726 det--;
727 (*det).dTimeRangeBeg = dTimeRangeBegIn;
728 (*det).dTimeRangeEnd = dTimeRangeEndIn;
729 (*det).uRangeNbBins = uRangeNbBinsIn;
730 (*det).uChargeCutMin = uChargeCutMinIn;
731 (*det).uChargeCutMax = uChargeCutMaxIn;
732 } // if( fvDets.end() == det )
733}
734
736{
737 for (std::vector<CheckTimingDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
738 if ((*det).detId == detIn) {
739 fvDets.erase(det);
740 break;
741 } // if( (*det).detId == detIn )
742 } // for( std::vector< CheckTimingDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
743}
744
ClassImp(CbmConverterManager)
ECbmModuleId
Definition CbmDefs.h:39
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kNotExist
If not found.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kTrd2d
TRD-FASP Detector (FIXME)
@ 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)
@ kStsModule
@ kStsLadder
@ kStsUnit
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.
std::map< ECbmModuleId, std::vector< TH2 * > > fvhDetToRefDiffEvo
void AddCheckDetector(ECbmModuleId detIn, std::string sNameIn, Double_t dTimeRangeBegIn=-1000.0, Double_t dTimeRangeEndIn=1000.0, UInt_t uRangeNbBinsIn=320, UInt_t uChargeCutMinIn=0, UInt_t uChargeCutMaxIn=0)
void SetDetectorDifferential(ECbmModuleId detIn, std::vector< std::string > vName)
std::map< ECbmModuleId, std::vector< TH2 * > > fvhDetToRefDiffDetCharge
UInt_t GetDigiInfo(UInt_t iDigi, std::vector< std::tuple< double, double, UInt_t > > *vec, ECbmModuleId detId=ECbmModuleId::kNotExist)
Retrieve digi (time,charge,addres) info. SHOULD BE IMPLEMENTED BY DETECTORS IF MORE DIFFERENTIAL STUD...
std::map< ECbmModuleId, std::unordered_set< std::string > > fUnimplementedView
const CbmTsEventHeader * fCbmTsEventHeader
Pointer to the Timeslice start time used to write it to the output tree.
const std::vector< CbmBmonDigi > * fpBmonDigiVec
std::map< ECbmModuleId, std::vector< TH1 * > > fvhDetSelfDiff
vectors storing histograms for each detector under investigation
std::map< ECbmModuleId, std::vector< TH1 * > > fvhDetToRefDiff
void SetReferenceDetector(ECbmModuleId refDetIn, std::string sNameIn, Double_t dTimeRangeBegIn=-1000.0, Double_t dTimeRangeEndIn=1000.0, UInt_t uRangeNbBinsIn=320, UInt_t uChargeCutMinIn=0, UInt_t uChargeCutMaxIn=0)
void CheckDataPresence(CheckTimingDetector detToCheck)
std::map< ECbmModuleId, std::vector< TH2 * > > fvhDetToRefDiffRefCharge
void FillTimeOffsetHistos(const Double_t dRefTime, const Double_t dRefCharge, UInt_t uDetIdx)
int GetViewId(CheckTimingDetector det, std::tuple< double, double, UInt_t > info)
Retrieve the detector view corresponding to the digi data (.
void RemoveCheckDetector(ECbmModuleId detIn)
std::map< ECbmModuleId, std::vector< TH2 * > > fvhDetToRefDiffEvoLong
std::vector< CheckTimingDetector > fvDets
static uint32_t GetSectionId(uint32_t address)
Return sector ID from address.
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40
XPU_D int32_t GetAddress() const
Definition CbmStsDigi.h:74
static int32_t GetSmId(uint32_t address)
static int32_t GetRpcId(uint32_t address)
static int32_t GetSmType(uint32_t address)
Data class for expanded digital TOF information.
Definition CbmTofDigi.h:47
int32_t GetAddress() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:112
double GetTime() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:131
double GetCharge() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:136
int32_t GetAddressModule() const
Getter module address in the experiment.
static float Clk(eCbmTrdAsicType ty)
DAQ clock accessor for each ASIC.
Definition CbmTrdDigi.h:109
eCbmTrdAsicType GetType() const
Channel FEE SPADIC/FASP according to CbmTrdAsicType.
Definition CbmTrdDigi.h:173
double GetTime() const
Getter for physical time [ns]. Accounts for clock representation of each ASIC. In SPADIC case physica...
Definition CbmTrdDigi.h:153
double GetCharge() const
Common purpose charge getter.
uint64_t GetTsIndex() const
std::vector< std::string > vName
No of views for each detector.
UInt_t uChargeCutMax
Charge cut used for example to reject/select pulser, no effect if equal, select if min < max,...
Double_t dPrevTime
Book-keeping variables.
UInt_t uNviews
Charge cut used for example to reject/select pulser, no effect if equal, select if min < max,...
ECbmModuleId detId
Settings.
uint32_t GetElementId(int32_t address, int32_t level)
Get the index of an element.