17#include <FairRootManager.h>
18#include <FairRunOnline.h>
21#include <TDirectory.h>
26#include <THttpServer.h>
31using std::setprecision;
59 for (std::vector<CheckTimingDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
67 LOG(info) <<
"CbmMcbmCheckTimingAlgo => Using the index from the TS Event header for Evo plots";
78 FairRootManager* ioman = FairRootManager::Instance();
86 fpBmonDigiVec = ioman->InitObjectAs<std::vector<CbmBmonDigi>
const*>(
"BmonDigi");
88 LOG(fatal) <<
"No storage with Bmon digis found while it should be used. "
93 LOG(fatal) <<
"No " << detToCheck.
sName <<
" digis found while it should be used. Stopping there!";
100 uint32_t iNbBinsLog = 0;
103 double* dBinsLog = dBinsLogVector.data();
105 for( std::vector< CheckTimingDetector >::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det )
107 for (uint i(0); i < (*det).uNviews; i++) {
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));
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(),
118 (*det).uRangeNbBins, (*det).dTimeRangeBeg, (*det).dTimeRangeEnd));
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(),
124 (*det).uRangeNbBins, (*det).dTimeRangeBeg, (*det).dTimeRangeEnd, 256, 0, 256));
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));
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(),
136 10000, -0.5, 10000 - 0.5, (*det).uRangeNbBins, (*det).dTimeRangeBeg, (*det).dTimeRangeEnd));
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(),
142 1800, 0, 18000, (*det).uRangeNbBins, (*det).dTimeRangeBeg, (*det).dTimeRangeEnd));
144 LOG( info ) <<
"Created histos for " << (*det).sName;
150 Form(
"time difference between consecutivs %s Digis;time diff [ns];Counts",
fRefDet.
sName.data()),
151 iNbBinsLog, dBinsLog));
154 FairRunOnline* run = FairRunOnline::Instance();
157 THttpServer* server = run->GetHttpServer();
158 if(
nullptr != server )
161 for (
auto uDetIdx :
fvDets) {
162 server->Register(
"/CheckTiming/SelfDiff",
fvhDetSelfDiff[uDetIdx.detId][0]);
163 server->Register(
"/CheckTiming/RefDiff",
fvhDetToRefDiff[uDetIdx.detId][0]);
181 LOG(info) <<
"executing TS " <<
fuNbTs <<
" index ["
218 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
219 <<
"Trying to search matches with unsupported det: " <<
fRefDet.
sName;
227template<
class DigiRef>
230 UInt_t uNbRefDigis = 0;
233 LOG(fatal) <<
"CbmMcbmCheckTimingAlgo::Exec => Unknow reference detector enum! " <<
fRefDet.
sName;
247 for (std::vector<CheckTimingDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
248 (*det).iPrevRefFirstDigi = 0;
251 for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
254 Double_t dRefTime = 0;
255 Double_t dRefCharge = 0;
256 UInt_t uRefAddress = 0;
262 dRefTime =
fDigiMan->
Get<DigiRef>(uDigi)->GetTime();
263 dRefCharge =
fDigiMan->
Get<DigiRef>(uDigi)->GetCharge();
264 uRefAddress =
fDigiMan->
Get<DigiRef>(uDigi)->GetAddress();
290 for (UInt_t uDetIdx = 0; uDetIdx <
fvDets.size(); ++uDetIdx) {
291 switch (
fvDets[uDetIdx].detId) {
325 LOG(fatal) <<
"CbmMcbmCheckTimingAlgo::CheckInterSystemOffset => "
326 <<
"Trying to search matches with unsupported det: " <<
fvDets[uDetIdx].sName;
341 LOG(fatal) <<
"CbmMcbmCheckTimingAlgo::FillTimeOffsetHistos => Unknow "
356 UInt_t uFirstDigiInWin =
fvDets[uDetIdx].iPrevRefFirstDigi;
359 std::vector<Double_t> vSelDiff = {};
360 std::vector<std::tuple<double, double, uint>> vDigiInfo = {};
361 for (UInt_t uDigiIdx =
fvDets[uDetIdx].iPrevRefFirstDigi; uDigiIdx < uNbDigis; ++uDigiIdx) {
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);
370 if (
fvDets[uDetIdx].dPrevTime <= dTime) {
371 vSelDiff.push_back(dTime -
fvDets[uDetIdx].dPrevTime);
372 fvDets[uDetIdx].dPrevTime = dTime;
374 Double_t dDiffTime = dTime - dRefTime;
375 if (dDiffTime <
fvDets[uDetIdx].dTimeRangeBeg) {
380 if (
fvDets[uDetIdx].dTimeRangeEnd < dDiffTime) {
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) {
396 if (
fvDets[uDetIdx].uChargeCutMin < dCharge || dCharge <
fvDets[uDetIdx].uChargeCutMax) {
405 if (uid < 0 || uint(uid) >=
fvDets[uDetIdx].uNviews)
continue;
408 for (
auto dt : vSelDiff)
428 fvDets[uDetIdx].iPrevRefFirstDigi = uFirstDigiInWin;
437 if (digi ==
nullptr)
return 0;
438 vec->push_back(std::make_tuple(digi->GetTime(), digi->GetCharge(), digi->GetAddress()));
448 if (digi ==
nullptr)
return 0;
452 vec->push_back(std::make_tuple(digi->GetTime(), digi->GetCharge(), uId * 10 + lId * 3 + mId));
464 if (trdDigi ==
nullptr)
return 0;
466 double dt = trdDigi->
GetTime();
475 double t, r = trdDigi->
GetCharge(t, toff);
501 if (digi ==
nullptr)
return 0;
506 vec->push_back(std::make_tuple(digi->
GetTime(), digi->
GetCharge(), smTyp * 100 + smID * 10 + rpcID));
514 if (det.
vName.size() == 1)
return 0;
516 uint modId = std::get<2>(info);
518 for (
auto view : det.
vName) {
519 if (view.compare(std::to_string(modId)) == 0)
return iview;
523 std::string sFullId = det.
sName +
" mod " + std::to_string(modId);
525 LOG(warning) << det.
sName <<
" condition not implemented for " << sFullId <<
". Skipping it from now on.";
536 TFile* oldFile = gFile;
537 TDirectory* oldDir = gDirectory;
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++)
547 for (uint
id(0);
id < uDet.uNviews;
id++)
549 for (uint
id(0);
id < uDet.uNviews;
id++)
551 for (uint
id(0);
id < uDet.uNviews;
id++)
553 for (uint
id(0);
id < uDet.uNviews;
id++)
555 for (uint
id(0);
id < uDet.uNviews;
id++) {
556 LOG(debug) <<
"WriteHistos, Det, entries = " << uDet.sName <<
" "
558 LOG(info) <<
"Saved histos for " << uDet.sName <<
"(" << uDet.vName[id] <<
")";
564 switch (uDet.detId) {
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);
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);
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);
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);
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);
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);
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);
650 LOG(info) <<
"Detector ID for fitting is not valid.";
675 Double_t dTimeRangeEndIn, UInt_t uRangeNbBinsIn,
676 UInt_t uChargeCutMinIn, UInt_t uChargeCutMaxIn)
690 std::vector<CheckTimingDetector>::iterator det;
691 for (det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
692 if ((*det).detId != detIn)
continue;
694 (*det).vName = vName;
695 (*det).uNviews = vName.size();
700 LOG(warning) <<
"CbmMcbmCheckTimingAlgo::SetDetectorDifferential => Detector not in the "
701 "list, Nothing done at this point!";
705 Double_t dTimeRangeEndIn, UInt_t uRangeNbBinsIn, UInt_t uChargeCutMinIn,
706 UInt_t uChargeCutMaxIn)
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;
723 if (
fvDets.end() == det) {
727 (*det).dTimeRangeBeg = dTimeRangeBegIn;
728 (*det).dTimeRangeEnd = dTimeRangeEndIn;
729 (*det).uRangeNbBins = uRangeNbBinsIn;
730 (*det).uChargeCutMin = uChargeCutMinIn;
731 (*det).uChargeCutMax = uChargeCutMaxIn;
737 for (std::vector<CheckTimingDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
738 if ((*det).detId == detIn) {
ClassImp(CbmConverterManager)
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kTrd2d
TRD-FASP Detector (FIXME)
@ kMuch
Muon detection system.
@ kRich
Ring-Imaging Cherenkov Detector.
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)
Double_t fMuchPeakWidthNs
Double_t DetPeakPosSingle
std::map< ECbmModuleId, std::vector< TH2 * > > fvhDetToRefDiffDetCharge
CheckTimingDetector fRefDet
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
Double_t fRichPeakWidthNs
std::map< ECbmModuleId, std::vector< TH1 * > > fvhDetSelfDiff
vectors storing histograms for each detector under investigation
void CheckInterSystemOffset()
Double_t DetAverageSingle
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)
~CbmMcbmCheckTimingAlgo()
void CheckDataPresence(CheckTimingDetector detToCheck)
std::map< ECbmModuleId, std::vector< TH2 * > > fvhDetToRefDiffRefCharge
CbmDigiManager * fDigiMan
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.
XPU_D int32_t GetAddress() const
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.
int32_t GetAddress() const
Inherited from CbmDigi.
double GetTime() const
Inherited from CbmDigi.
double GetCharge() const
Inherited from CbmDigi.
int32_t GetAddressModule() const
Getter module address in the experiment.
static float Clk(eCbmTrdAsicType ty)
DAQ clock accessor for each ASIC.
eCbmTrdAsicType GetType() const
Channel FEE SPADIC/FASP according to CbmTrdAsicType.
double GetTime() const
Getter for physical time [ns]. Accounts for clock representation of each ASIC. In SPADIC case physica...
double GetCharge() const
Common purpose charge getter.
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.