REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorSignal.h
1
21
22#ifndef RestCore_TRestDetectorSignal
23#define RestCore_TRestDetectorSignal
24
25#include <TGraph.h>
26#include <TRestStringOutput.h>
27#include <TString.h>
28#include <TVector2.h>
29
30#include <iostream>
31#include <optional>
32
34 private:
35 Int_t GetMinIndex() const;
36 Int_t GetTimeIndex(Double_t t);
37
38 protected:
39 Int_t fSignalID = -1;
40
41 std::vector<Double_t> fSignalTime; // Vector with the time of the signal
42 std::vector<Double_t> fSignalCharge; // Vector with the charge of the signal
43
44 // TODO: remove this and use readout
45 std::string fName; // Name of the signal
46 std::string fType; // Type of the signal
47
48 public:
49 TGraph* fGraph;
50
51 std::vector<Int_t> fPointsOverThreshold;
52
53 void IncreaseAmplitude(const TVector2& p);
54 void SetPoint(const TVector2& p);
55
56 // TODO other objects should probably skip using GetMaxIndex directly
57 Int_t GetMaxIndex(Int_t from = 0, Int_t to = 0);
58
59 std::optional<std::pair<Double_t, Double_t>> GetPeakGauss();
60 std::optional<std::pair<Double_t, Double_t>> GetPeakLandau();
61 std::optional<std::pair<Double_t, Double_t>> GetPeakAget();
62
63 std::string GetSignalName() const { return fName; }
64 std::string GetSignalType() const { return fType; }
65
66 void SetSignalName(const std::string& name) { fName = name; }
67 void SetSignalType(const std::string& type) { fType = type; }
68
69 // Getters
70 TVector2 GetPoint(Int_t n) { return {GetTime(n), GetData(n)}; }
71
72 inline Int_t GetSignalID() const { return fSignalID; }
73 inline Int_t GetID() const { return fSignalID; }
74
75 void IncreaseTimeBinBy(Int_t bin, Double_t data) {
76 if (bin >= GetNumberOfPoints()) {
77 std::cout << "Increase time bin: outside limits" << std::endl;
78 return;
79 }
80
81 fSignalCharge[bin] += data;
82 }
83
84 Int_t GetNumberOfPoints() const {
85 if (fSignalTime.size() != fSignalCharge.size()) {
86 RESTError << "WARNING, the two std::vector sizes did not match" << RESTendl;
87 exit(1);
88 }
89 return fSignalTime.size();
90 }
91
92 Double_t GetIntegralWithTime(Double_t startTime, Double_t endTime) const;
93 Double_t GetIntegral(Int_t startBin = 0, Int_t endBin = 0) const;
94
95 void Normalize(Double_t scale = 1.);
96
97 std::vector<Int_t> GetPointsOverThreshold() const { return fPointsOverThreshold; }
98
99 Double_t GetAverage(Int_t start = 0, Int_t end = 0);
100 Int_t GetMaxPeakWidth();
101 Double_t GetMaxPeakWithTime(Double_t startTime, Double_t endTime) const;
102
103 Double_t GetMaxPeakValue();
104 Double_t GetMinPeakValue();
105
106 Double_t GetMaxPeakTime(Int_t from = 0, Int_t to = 0);
107
108 Double_t GetMaxValue() { return GetMaxPeakValue(); }
109 Double_t GetMinValue() { return GetMinPeakValue(); }
110
111 Double_t GetMinTime() const;
112 Double_t GetMaxTime() const;
113
114 Double_t GetData(Int_t index) const { return fSignalCharge[index]; }
115 Double_t GetTime(Int_t index) const { return fSignalTime[index]; }
116
117 // Setters
118 void SetSignalID(Int_t sID) { fSignalID = sID; }
119 void SetID(Int_t sID) { fSignalID = sID; }
120
121 void NewPoint(Double_t time, Double_t data);
122 void IncreaseAmplitude(Double_t t, Double_t d);
123
124 void SetPoint(Double_t t, Double_t d);
125 void SetPoint(Int_t index, Double_t t, Double_t d);
126
127 Double_t GetStandardDeviation(Int_t startBin, Int_t endBin);
128 Double_t GetBaseLine(Int_t startBin, Int_t endBin);
129 Double_t GetBaseLineSigma(Int_t startBin, Int_t endBin, Double_t baseline = 0);
130
131 Double_t SubstractBaseline(Int_t startBin, Int_t endBin);
132 void AddOffset(Double_t offset);
133
134 void MultiplySignalBy(Double_t factor);
135 void ExponentialConvolution(Double_t fromTime, Double_t decayTime, Double_t offset = 0);
136 void SignalAddition(TRestDetectorSignal* inSgnl);
137
138 Bool_t isSorted() const;
139 void Sort();
140
141 void GetDifferentialSignal(TRestDetectorSignal* diffSgnl, Int_t smearPoints = 5);
142 void GetSignalDelayed(TRestDetectorSignal* delayedSignal, Int_t delay);
143 void GetSignalSmoothed(TRestDetectorSignal* smthSignal, Int_t averagingPoints = 3);
144
145 void GetWhiteNoiseSignal(TRestDetectorSignal* noiseSgnl, Double_t noiseLevel = 1.);
146 void GetSignalGaussianConvolution(TRestDetectorSignal* convSgnl, Double_t sigma = 100.,
147 Int_t nSigmas = 5);
148
149 void AddGaussianSignal(Double_t amp, Double_t sigma, Double_t time, Int_t N, Double_t fromTime,
150 Double_t toTime);
151
152 void Reset() {
153 fSignalTime.clear();
154 fSignalCharge.clear();
155 }
156
157 void WriteSignalToTextFile(const TString& filename) const;
158 void Print() const;
159
160 TGraph* GetGraph(Int_t color = 1);
161
162 // Constructor
164 // Destructor
166
167 ClassDef(TRestDetectorSignal, 4);
168};
169#endif
void IncreaseAmplitude(const TVector2 &p)
If the point already exists inside the detector signal event, the amplitude value will be added to th...
void SetPoint(const TVector2 &p)
If the point already exists inside the detector signal event, it will be overwritten....