3#include "BmnEventHeader.h"
4#include "BmnStripDigit.h"
5#include "BmnTof1Digit.h"
6#include "BmnTrigDigit.h"
7#include "BmnTrigWaveDigit.h"
8#include "FairRootManager.h"
26 LOG(debug) <<
"Default Constructor of BmnEventSelector";
32 LOG(debug) <<
"Destructor of BmnEventSelector";
38 LOG(debug) <<
"SetParContainers of BmnEventSelector";
52 auto branch = (T)
ioman->GetObject(name);
54 LOG(fatal) <<
Form(
"BmnEventSelector: %s branch not found!!!\n", name);
61 LOG(info) << __func__ <<
": " << histName;
63 auto h2 =
static_cast<TH2*
>(
fInputFile->Get(histName.c_str()));
66 LOG(error) <<
"No input histogram: " << histName;
70 auto h1 = h2->ProjectionY(
Form(
"%s_fit", h2->GetName()), runBin, runBin);
71 if (!h1 || h1->GetEntries() == 0) {
73 LOG(error) <<
"No input histogram " << histName <<
" for run number " <<
fRunId;
75 h1->Fit(
"gaus",
"",
"", fitMin, fitMax);
76 auto f = (
TF1*)h1->GetListOfFunctions()->FindObject(
"gaus");
79 LOG(error) <<
"ERROR fitting distribution for run number " <<
fRunId;
84 fitPar = {f->GetParameter(0), f->GetParameter(1), f->GetParameter(2)};
91 LOG(debug) <<
"Initilization of BmnEventSelector";
101 vector<double> fitPar;
102 if (
FitRunDistr(
"h2runId_time_SingleBC1S", fitPar, 2000, 2500))
106 if (
FitRunDistr(
"h2runId_shapeShifted_SingleBC1S", fitPar, 0, 100)) {
112 if (
FitRunDistr(
"h2runId_time_SingleVCS_BC1S", fitPar, -10, 10)) {
119 if (
FitRunDistr(
"h2runId_shapeShiftedBC1S_SingleVCS", fitPar, 0, 80)) {
125 if (
FitRunDistr(
"h2runId_time_SingleBC2AS_BC1S", fitPar, -20, 0)) {
132 if (
FitRunDistr(
"h2runId_shapeShiftedBC1S_SingleBC2AS", fitPar, 0, 80)) {
138 if (
FitRunDistr(
"h2runId_peak_BC2AS", fitPar, 0., 1.e4))
142 if (
FitRunDistr(
"h2runId_time_SingleFD_BC1S", fitPar, 100, 200)) {
149 if (
FitRunDistr(
"h2runId_shapeShiftedBC1S_SingleFD", fitPar, 150, 250)) {
155 if (
FitRunDistr(
"h2runId_peak_FD_nc", fitPar, 4.e3, 7.e3))
159 if (
FitRunDistr(
"h2runId_shapeShiftedBC1S_BD", fitPar, -150, -50)) {
165 if (
FitRunDistr(
"h2runId_shapeShiftedBC1S_TOF400digit", fitPar)) {
171 if (
FitRunDistr(
"h2runId_shapeShiftedBC1S_TOF700digit", fitPar, -520, -450)) {
179 LOG(error) <<
"No input histogram file!!!";
182 ioman = FairRootManager::Instance();
185 <<
"FairRootManager is not instantiated";
212 new TH2F(
"h2runId_time",
"TDC time;runId;TDC time (ns);N entries", 1,
fRunId,
fRunId + 1, 900, 0, 3600);
225 new TH2F(
"h2runId_shape",
"TQDC shape;runId;Time (ns);TQDC signal", 1,
fRunId,
fRunId + 1, 500, -400, 3600);
240 auto h2runId_NdigitsTOF =
241 new TH2F(
"h2runId_NdigitsTOF",
"NdigitsTOF;runId;NdigitsTOF", 1,
fRunId,
fRunId + 1, 400, 0, 400);
248 auto h2runId_peak =
new TH2F(
"h2runId_peak",
"Peak;runId;Peak;N entries", 1,
fRunId,
fRunId + 1, 300, 0, 3e4);
260 AddHist(
new TH2F(
"h2runId_shapeShiftedBC1S_TOF400digit",
"TOF400 digit times;runId;Time (ns)", 1,
fRunId,
261 fRunId + 1, 500, -700, -600));
263 AddHist(
new TH2F(
"h2runId_shapeShiftedBC1S_TOF700digit",
"TOF700 digit times;runId;Time (ns)", 1,
fRunId,
264 fRunId + 1, 500, -550, -450));
267 vector<string> trigNames{
"BT",
"CCT1",
"CCT2",
"MBT"};
272 double(
fRunMin), 0, 0, -2200, 0,
277 auto h5runId_trigger_eventClass_dt_n =
278 new THnSparseI(
"h5runId_trigger_eventClass_dt_n",
"Number of;runId;trigger;Event class;#Deltat (ns);N",
279 bins.size(), bins.data(), xmin.data(), xmax.data());
280 for (uint
i = 0;
i < trigNames.size();
i++)
281 h5runId_trigger_eventClass_dt_n->GetAxis(1)->SetBinLabel(
i + 1, trigNames.at(
i).c_str());
286 vector<int> rebin = {1, 1, 1, 1, int(xmax.at(4) /
n)};
287 auto h5runId_trigger_eventClass_dt_nTOF =
288 static_cast<THnSparse*
>(h5runId_trigger_eventClass_dt_n->Clone())->
Rebin(rebin.data());
289 h5runId_trigger_eventClass_dt_nTOF->
SetName(
"h5runId_trigger_eventClass_dt_nTOF");
290 h5runId_trigger_eventClass_dt_nTOF->SetTitle(
"Number of TOF");
291 h5runId_trigger_eventClass_dt_nTOF->GetAxis(4)->SetLimits(0,
n);
296 rebin = {1, 1, 1, 1, int(xmax.at(4) /
n)};
297 auto h5runId_trigger_eventClass_dt_nSILICON =
298 static_cast<THnSparse*
>(h5runId_trigger_eventClass_dt_n->Clone())->
Rebin(rebin.data());
299 h5runId_trigger_eventClass_dt_nSILICON->
SetName(
"h5runId_trigger_eventClass_dt_nSILICON");
300 h5runId_trigger_eventClass_dt_nSILICON->SetTitle(
"Number of SILICON");
301 h5runId_trigger_eventClass_dt_nSILICON->GetAxis(4)->SetLimits(0,
n);
311 LOG(debug) <<
"Initilization of BmnEventSelector";
317 if (hitTimes.size() == 0)
320 float min =
fabs(hitTimes.at(0) - refTime);
321 for (uint
i = 1;
i < hitTimes.size();
i++) {
322 auto dt =
fabs(hitTimes.at(
i) - refTime);
339 return digit->
GetPeak(binMin, binMax);
344 std::vector<double> hitTimes,
348 std::vector<float> sum(hitTimes.size(), 0.);
349 for (uint
i = 0;
i < hitTimes.size();
i++) {
350 for (
auto obj : *array) {
351 auto digit =
static_cast<T
>(obj);
352 auto relTime = digit->GetTime() - hitTimes.at(
i);
353 if (relTimeMin < relTime && relTime < relTimeMax)
354 sum.at(
i) += digit->GetAmp();
362 std::vector<double> hitTimes,
366 std::vector<int>
n(hitTimes.size(), 0);
367 for (uint
i = 0;
i < hitTimes.size();
i++) {
368 for (
auto obj : *array) {
369 auto relTime =
static_cast<T
>(obj)->GetTime() - hitTimes.at(
i);
370 if (relTimeMin < relTime && relTime < relTimeMax)
378 std::vector<double> hitTimes,
384 std::vector<int> ret(hitTimes.size(), -999);
389 for (uint
i = 0;
i < hitTimes.size();
i++) {
390 auto hitTime = hitTimes.at(
i);
391 auto hitTimeMin = hitTime + relHitTimeMin;
392 auto hitTimeMax = hitTime + relHitTimeMax;
393 if (hitTimeMin < 0 || hitTimeMax > tMax)
395 auto hitFound =
true;
396 for (uint j = 0; j < hitTimesDigit.size(); j++) {
397 auto hitTimeDigit = hitTimesDigit.at(j);
398 if (hitTimeMin <= hitTimeDigit && hitTimeDigit <= hitTimeMax) {
403 auto timeMin = hitTime + relTimeMin;
404 auto timeMax = hitTime + relTimeMax;
406 ret.at(
i) =
GetPeak(digit, timeMin, timeMax);
482 const float DTmax = 300;
532 vector<bool> trigAR = {isBT_AR, isCCT1_AR, isCCT2_AR, isMBT_AR};
602 auto pulseFD =
fTQDC_FD->GetValue();
603 for (uint
i = 0;
i <
fTQDC_FD->GetNSamples();
i++) {
623 auto closestBC1Stime =
fTimesBC1S.at(closestBC1Sindex);
634 float dtLeft = 1e10, dtRight = 1e10;
639 if (
fabs(dtLeft) < dtRight)
646 for (uint
i = 0;
i < trigAR.size();
i++) {
707 LOG(debug) <<
"Finish of BmnEventSelector";
711 string className = h->ClassName();
712 if (className.find(
"THn") == 0) {
713 vector<int> axes = {0, 1, 2, 4};
714 static_cast<THnSparse*
>(h)->Projection(axes.size(), axes.data())->
Write();
716 static_cast<THnSparse*
>(h)->Projection(axes.size(), axes.data())->
Write();
721 string name = h->GetName();
722 string className = h->ClassName();
723 if (className.find(
"TH2") == 0 && name.find(
"h2runId") == 0) {
725 static_cast<TH2*
>(h)->ProjectionY()->
Write();
friend F32vec4 fabs(const F32vec4 &a)
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
THnSparseT< TArrayI > THnSparseI
char * Form(const char *fmt,...)
TClonesArray * fArrBDdigits
TH2F * h2runId_time_BC1S_k0
TClonesArray * fArrTOF400digits
TH2F * h2runId_shapeShiftedBC1S_SingleVCS
float fSingleBC1hitTimeMean
BmnEventHeader * fEventHeader
TClonesArray * fArrTOF700digits
TClonesArray * fArrTQDC_BC1S
TH2F * h2runId_peak_SingleBC1S
std::vector< int > fBC2ASpeaks
TH2F * h2runId_time_BC1S_kV1
THnSparse * h5runId_trigger_eventClass_dt_nTOF700digits
TH2F * h2runId_shapeShiftedBC1S_SingleFD
float fTOF400digitTimeMax
TH2F * h2runId_SumAmpBD_SingleBC1S
float fTOF700digitTimeMin
float fSingleFD_BC1S_hitTimeMax
virtual InitStatus ReInit()
ReInitiliazation of task when the runID changes.
BmnTrigWaveDigit * fTQDC_FD
TClonesArray * fArrGEMdigits
std::vector< double > fTimesBC1S
std::vector< double > fTimesBC2AS
std::string fInputFileName
BmnEventClass::id fEventClass
float fCentralHitTimeBC1S
std::vector< int > fBC1hitClasses
int GetClosestHitIndex(std::vector< double > hitTimes, float refTime)
TH2F * h2runId_time_SingleFD_BC1S
float fTOF400digitTimeMin
std::vector< int > GetPeaks(BmnTrigWaveDigit *digit, std::vector< double > hitTimes, float relTimeMin, float relTimeMax, float relHitTimeMin=-1, float relHitTimeMax=1)
TH2F * h2runId_shapeShiftedBC1S_SingleBC2AS
THnSparse * h5runId_trigger_eventClass_dt_nTOF400digits
std::string fOutputFileName
TH2F * h2runId_time_BC1S_k1
float fSingleFD_BC1S_hitTimeMin
float fTOF700digitTimeMax
T AddHistClone(T h, const char *postfix="")
float fSingleVCS_BC1S_hitTimeMin
T ReadBranch(const char *name)
TH2F * h2runId_peak_FD_nc
std::vector< int > fNdigitsBD
std::vector< int > fFDpeaks
float fSingleBC2AS_BC1S_hitTimeMax
std::vector< int > fNdigitsTOF400
~BmnEventSelector()
Constructor with parameters (Optional).
TH2F * h2runId_time_SingleVCS_BC1S
std::vector< int > GetNdigits(TClonesArray *array, std::vector< double > hitTimes, float relTimeMin, float relTimeMax)
bool fFillPerformanceHists
TH2F * h2runId_NdigitsTOF700_nc
std::vector< double > fRelTimesBC1S
virtual void Finish()
Finish task called at the end of the run.
BmnBC1hitInfo fBC1hitInfo
std::vector< int > fBC1Speaks
std::vector< double > fTimesVCS
TH2F * h2runId_peak_BC2AS
TH2F * h2runId_NdigitsTOF400
THnSparse * h5runId_trigger_eventClass_dt_nGEMdigits
BmnTrigWaveDigit * fTQDC_VCS
TH2F * h2runId_NdigitsTOF400_SingleBC1S
virtual void Exec(Option_t *opt)
Executed for each event.
bool FitRunDistr(std::string histName, std::vector< double > &fitPar, float fitMin=0, float fitMax=0)
TH2F * h2runId_shapeShiftedBC1S_TOF700digit
std::vector< float > GetSumAmp(TClonesArray *digits, std::vector< double > hitTimes, float relTimeMin, float relTimeMax)
TH2F * h2runId_time_SingleBC1S
TH2F * h2runId_shapeShiftedBC1S_TOF400digit
unsigned int fNdigitsSILICON
BmnTrigWaveDigit * fTQDC_BC1S
TH2F * h2runId_peak_SingleVCS
THnSparse * h5runId_trigger_eventClass_dt_nSILICONdigits
TH2F * h2runId_eventClass
float fSingleBC2ASpeakMin
TH2F * h2runId_NdigitsBD_nc
TH2F * h2runId_NdigitsTOF700_SingleBC1S
std::vector< float > fSumAmpBD
int GetPeak(BmnTrigWaveDigit *digit, float timeMin=0, float timeMax=1e9)
virtual void SetParContainers()
Load the parameter container from the runtime database.
TClonesArray * fArrTQDC_FD
BmnEventSelector()
Default constructor.
float fSingleVCS_BC1S_hitTimeMax
TH2F * h2runId_shapeShiftedBC1S_BD
TClonesArray * fArrSILICONdigits
TH2F * h2runId_NdigitsBD_SingleBC1S
virtual InitStatus Init()
Initiliazation of task at the beginning of a run.
TClonesArray * fArrTQDC_VCS
BmnEventClass::id Classify()
bool fFillCalibrationHists
TH2F * h2runId_shapeShifted_SingleBC1S
BmnTrigWaveDigit * fTQDC_BC2AS
TH2F * h2runId_NdigitsTOF400_nc
std::vector< int > fNdigitsTOF700
TH2F * h2runId_NdigitsTOF700
std::vector< double > fTimesFD
TH2F * h2runId_time_BC1S_kV0
TClonesArray * fArrTQDC_BC2AS
TH2F * h2runId_time_SingleBC2AS_BC1S
std::vector< int > fVCSpeaks
float fSingleBC2AS_BC1S_hitTimeMin
TH2F * h2runId_peak_SingleFD
TH2F * h2runId_SumAmpBD_nc
TH2F * h2runId_peak_SingleBC2AS
Class BmnStripDigit Base class for strip detector digits.
class for TQDC data including waveform can be initialized both from an std::vector and raw pointer to...
size_t GetNSamples() const
int16_t GetPeak(size_t start=0, size_t stop=SIZE_MAX) const
vector< Double_t > & TdcVector()
virtual Int_t FindBin(const char *label)
THnSparse * Rebin(const Int_t *group) const
virtual void SetName(const char *name)
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
RVec< PromoteType< T > > abs(const RVec< T > &v)
*brief user defined string literal for JSON values *sa std::size_t n
const std::map< int, std::string > names