REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorSignalEvent.cxx
1
21
22#include "TRestDetectorSignalEvent.h"
23
24#include <TMath.h>
25
26using namespace std;
27
29
30TRestDetectorSignalEvent::TRestDetectorSignalEvent() {
31 // TRestDetectorSignalEvent default constructor
32 Initialize();
33}
34
35TRestDetectorSignalEvent::~TRestDetectorSignalEvent() {
36 // TRestDetectorSignalEvent destructor
37}
38
41 fSignal.clear();
42 fPad = nullptr;
43 fMinValue = std::numeric_limits<Double_t>::max();
44 fMaxValue = std::numeric_limits<Double_t>::min();
45 fMinTime = std::numeric_limits<Double_t>::max();
46 fMaxTime = std::numeric_limits<Double_t>::min();
47}
48
49void TRestDetectorSignalEvent::AddSignal(const TRestDetectorSignal& signal) {
50 if (signalIDExists(signal.GetSignalID())) {
51 cout << "Warning. Signal ID : " << signal.GetSignalID()
52 << " already exists. Signal will not be added to signal event" << endl;
53 return;
54 }
55
56 fSignal.emplace_back(signal);
57}
58
59void TRestDetectorSignalEvent::RemoveSignalWithId(Int_t sId) {
60 Int_t index = GetSignalIndex(sId);
61
62 if (index == -1) {
63 std::cout << "Warning. Signal ID : " << sId
64 << " does not exist. Signal will not be removed from signal event" << std::endl;
65 return;
66 }
67
68 fSignal.erase(fSignal.begin() + index);
69}
70
71Int_t TRestDetectorSignalEvent::GetSignalIndex(Int_t signalID) {
72 for (int i = 0; i < GetNumberOfSignals(); i++)
73 if (fSignal[i].GetSignalID() == signalID) return i;
74 return -1;
75}
76
77Double_t TRestDetectorSignalEvent::GetIntegral(Int_t startBin, Int_t endBin) {
78 Double_t sum = 0;
79
80 for (int i = 0; i < GetNumberOfSignals(); i++) sum += fSignal[i].GetIntegral(startBin, endBin);
81
82 return sum;
83}
84
85Double_t TRestDetectorSignalEvent::GetIntegralWithTime(Double_t startTime, Double_t endTime) {
86 Double_t sum = 0;
87 for (int n = 0; n < GetNumberOfSignals(); n++) sum += fSignal[n].GetIntegralWithTime(startTime, endTime);
88
89 return sum;
90}
91
92void TRestDetectorSignalEvent::AddChargeToSignal(Int_t signalID, Double_t time, Double_t charge) {
93 Int_t signalIndex = GetSignalIndex(signalID);
94 if (signalIndex == -1) {
95 signalIndex = GetNumberOfSignals();
97 signal.SetSignalID(signalID);
98 AddSignal(signal);
99 }
100
101 fSignal[signalIndex].IncreaseAmplitude(time, charge);
102}
103
104void TRestDetectorSignalEvent::PrintEvent() {
106
107 for (int i = 0; i < GetNumberOfSignals(); i++) {
108 const auto& signal = fSignal[i];
109 signal.Print();
110 }
111}
112
113// TODO: GetMaxTimeFast, GetMinTimeFast, GetMaxValueFast that return the value of fMinTime, fMaxTime, etc.
114void TRestDetectorSignalEvent::SetMaxAndMin() {
115 fMinValue = std::numeric_limits<Double_t>::max();
116 fMaxValue = std::numeric_limits<Double_t>::min();
117 fMinTime = std::numeric_limits<Double_t>::max();
118 fMaxTime = std::numeric_limits<Double_t>::min();
119
120 for (int s = 0; s < GetNumberOfSignals(); s++) {
121 if (fMinTime > fSignal[s].GetMinTime()) fMinTime = fSignal[s].GetMinTime();
122 if (fMaxTime < fSignal[s].GetMaxTime()) fMaxTime = fSignal[s].GetMaxTime();
123
124 if (fMinValue > fSignal[s].GetMinValue()) fMinValue = fSignal[s].GetMinValue();
125 if (fMaxValue < fSignal[s].GetMaxValue()) fMaxValue = fSignal[s].GetMaxValue();
126 }
127}
128
129Double_t TRestDetectorSignalEvent::GetMaxValue() {
130 SetMaxAndMin();
131 return fMaxValue;
132}
133
134Double_t TRestDetectorSignalEvent::GetMinValue() {
135 SetMaxAndMin();
136 return fMinValue;
137}
138
139Double_t TRestDetectorSignalEvent::GetMinTime() {
140 Double_t minTime = numeric_limits<Double_t>::max();
141 for (int s = 0; s < GetNumberOfSignals(); s++) {
142 if (minTime > fSignal[s].GetMinTime()) {
143 minTime = fSignal[s].GetMinTime();
144 }
145 }
146 return minTime;
147}
148
149Double_t TRestDetectorSignalEvent::GetMaxTime() {
150 Double_t maxTime = numeric_limits<Double_t>::min();
151 for (int s = 0; s < GetNumberOfSignals(); s++) {
152 if (maxTime < fSignal[s].GetMaxTime()) {
153 maxTime = fSignal[s].GetMaxTime();
154 }
155 }
156 return maxTime;
157}
158
159// Draw current event in a TPad
160TPad* TRestDetectorSignalEvent::DrawEvent(const TString& option) {
161 delete fPad;
162
163 int nSignals = this->GetNumberOfSignals();
164
165 if (nSignals == 0) {
166 cout << "Empty event " << endl;
167 return nullptr;
168 }
169
170 fMinValue = std::numeric_limits<Double_t>::max();
171 fMaxValue = std::numeric_limits<Double_t>::min();
172 fMinTime = std::numeric_limits<Double_t>::max();
173 fMaxTime = std::numeric_limits<Double_t>::min();
174
175 fPad = new TPad(this->GetName(), " ", 0, 0, 1, 1);
176 fPad->Draw();
177 fPad->cd();
178 fPad->DrawFrame(GetMinTime(), GetMinValue(), GetMaxTime(), GetMaxValue());
179
180 char title[256];
181 sprintf(title, "Event ID %d", this->GetID());
182
183 TMultiGraph* mg = new TMultiGraph();
184 mg->SetTitle(title);
185 mg->GetXaxis()->SetTitle("Time [us]");
186 mg->GetXaxis()->SetTitleOffset(1.1);
187 mg->GetYaxis()->SetTitle("Amplitude [a.u.]");
188 mg->GetYaxis()->SetTitleOffset(0.8);
189
190 mg->GetYaxis()->SetTitleSize(1.4 * mg->GetYaxis()->GetTitleSize());
191 mg->GetXaxis()->SetTitleSize(1.4 * mg->GetXaxis()->GetTitleSize());
192 mg->GetYaxis()->SetLabelSize(1.25 * mg->GetYaxis()->GetLabelSize());
193 mg->GetXaxis()->SetLabelSize(1.25 * mg->GetXaxis()->GetLabelSize());
194
195 for (int n = 0; n < nSignals; n++) {
196 TGraph* gr = fSignal[n].GetGraph(n + 1);
197 mg->Add(gr);
198 }
199
200 fPad->cd();
201 mg->Draw("");
202
203 return fPad;
204}
TPad * DrawEvent(const TString &option="")
Draw the event.
virtual void PrintEvent() const
Definition: TRestEvent.cxx:187
virtual void Initialize()=0
Definition: TRestEvent.cxx:73