File indexing completed on 2025-08-06 08:17:53
0001 #ifndef MBD_MBDSIG_H
0002 #define MBD_MBDSIG_H
0003
0004 #include "MbdRunningStats.h"
0005
0006 #include <TH1.h>
0007
0008 #include <fstream>
0009 #include <vector>
0010
0011 class TTree;
0012 class TGraphErrors;
0013 class TH2;
0014 class MbdCalib;
0015
0016
0017
0018
0019
0020
0021
0022 class MbdSig
0023 {
0024 public:
0025 explicit MbdSig(const int chnum = 0, const int nsamp = 0);
0026
0027 virtual ~MbdSig();
0028
0029
0030
0031 void SetNSamples( const int s ) { _nsamples = s; }
0032 void SetY(const Float_t *y, const int invert = 1);
0033 void SetXY(const Float_t *x, const Float_t *y, const int invert = 1);
0034
0035 void SetCalib(MbdCalib *mcal);
0036
0037 TH1 *GetHist() { return hpulse; }
0038 TGraphErrors *GetGraph() { return gpulse; }
0039 Double_t GetAmpl() { return f_ampl; }
0040 Double_t GetTime() { return f_time; }
0041 Double_t GetIntegral() { return f_integral; }
0042
0043
0044
0045
0046
0047
0048 void FillPed0(const Int_t sampmin, const Int_t sampmax);
0049 void FillPed0(const Double_t begin, const Double_t end);
0050
0051 Double_t GetPed0() { return ped0; }
0052 Double_t GetPed0RMS() { return ped0rms; }
0053
0054
0055 void SetPed0(const Double_t mean, const Double_t rms = 0.);
0056
0057
0058 void SetEventPed0Range(const Int_t minsamp, const Int_t maxsamp)
0059 {
0060 minped0samp = minsamp;
0061 maxped0samp = maxsamp;
0062 }
0063
0064 void SetEventPed0Range(const Double_t minx, const Double_t maxx)
0065 {
0066 minped0x = minx;
0067 maxped0x = maxx;
0068 }
0069
0070 void SetEventPed0PreSamp(const Int_t presample, const Int_t nsamps = -1, const int max_samp = -1);
0071
0072 void CalcEventPed0(const Int_t minpedsamp, const Int_t maxpedsamp);
0073 void CalcEventPed0(const Double_t minpedx, const Double_t maxpedx);
0074 int CalcEventPed0_PreSamp(const Int_t presample, const Int_t nsamps = 1);
0075 void Remove_Pileup();
0076
0077 TH1 *GetPedHist() { return hPed0; }
0078
0079
0080 Double_t LeadingEdge(const Double_t threshold);
0081
0082
0083 Double_t dCFD(const Double_t fraction_threshold);
0084
0085
0086 Double_t MBDTDC(const Int_t max_samp);
0087
0088
0089 Double_t GetSplineAmpl();
0090
0091
0092 Double_t Integral(const Double_t xmin, const Double_t xmax);
0093
0094
0095 void LocMax(Double_t &x_at_max, Double_t &ymax, Double_t xminrange = 0., Double_t xmaxrange = 0.);
0096
0097
0098 void LocMin(Double_t &x_at_min, Double_t &ymin, Double_t xminrange = 0., Double_t xmaxrange = 0.);
0099
0100
0101 Int_t FitTemplate(const Int_t sampmax = -1);
0102
0103
0104
0105
0106 void SetTemplateSize(const Int_t nptsx, const Int_t nptsy, const Double_t begt, const Double_t endt);
0107 Int_t SetTemplate(const std::vector<float> &shape, const std::vector<float> &sherr);
0108
0109
0110 void SetTimeOffset(const Double_t o) { f_time_offset = o; }
0111 Double_t TemplateFcn(const Double_t *x, const Double_t *par);
0112 TF1 *GetTemplateFcn() { return template_fcn; }
0113 void SetMinMaxFitTime(const Double_t mintime, const Double_t maxtime);
0114
0115 void WritePedHist();
0116
0117 void DrawWaveform();
0118 void PadUpdate() const;
0119 void Print();
0120 void Verbose(const int v) { _verbose = v; }
0121
0122 private:
0123 void Init();
0124
0125 int _ch;
0126 int _nsamples;
0127 int _status{0};
0128
0129 int _evt_counter{0};
0130 MbdCalib *_mbdcal{nullptr};
0131 float _pileup_p0{0.};
0132 float _pileup_p1{0.};
0133 float _pileup_p2{0.};
0134 TF1 *fit_pileup{nullptr};
0135
0136
0137
0138 Double_t f_ampl{0,};
0139 Double_t f_time{0.};
0140
0141 Double_t f_time_offset{4.0};
0142
0143 Double_t f_integral{0.};
0144
0145 TH1 *hRawPulse{nullptr};
0146 TH1 *hSubPulse{nullptr};
0147 TH1 *hpulse{nullptr};
0148 TGraphErrors *gRawPulse{nullptr};
0149 TGraphErrors *gSubPulse{nullptr};
0150 TGraphErrors *gpulse{nullptr};
0151
0152
0153
0154 MbdRunningStats *ped0stats{nullptr};
0155 TH1 *hPed0{nullptr};
0156 TH1 *hPedEvt{nullptr};
0157 TF1 *ped_fcn{nullptr};
0158 TF1 *ped_tail{nullptr};
0159 Double_t ped0{0.};
0160 Double_t ped0rms{0.};
0161 int use_ped0{0};
0162 Int_t minped0samp{-9999};
0163 Int_t maxped0samp{-9999};
0164 Double_t minped0x{0.};
0165 Double_t maxped0x{0.};
0166 Double_t ped_presamp{};
0167 Double_t ped_presamp_nsamps{};
0168 Double_t ped_presamp_maxsamp{-1};
0169
0170
0171
0172
0173
0174 TH2 *h2Template{nullptr};
0175 TH2 *h2Residuals{nullptr};
0176
0177 TH1 *hAmpl{nullptr};
0178 TH1 *hTime{nullptr};
0179 Int_t template_npointsx{0};
0180 Int_t template_npointsy{0};
0181 Double_t template_begintime{0.};
0182 Double_t template_endtime{0.};
0183
0184
0185
0186
0187 std::vector<float> template_y;
0188 std::vector<float> template_yrms;
0189 TF1 *template_fcn{nullptr};
0190 Double_t fit_min_time{};
0191 Double_t fit_max_time{};
0192
0193 std::ofstream *_pileupfile{nullptr};
0194
0195
0196
0197 int _verbose{0};
0198 };
0199
0200 #endif