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