GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TSceptarHit.cxx
Go to the documentation of this file.
1#include "TSceptarHit.h"
2
3#include <iostream>
4#include <algorithm>
5#include <climits>
6
7#include "TSceptar.h"
8
10{
11 // Default Constructor
12 Clear();
13}
14
16{
17 // Copy Constructor
18 Clear();
19 rhs.Copy(*this);
20}
21
23{
24 frag.Copy(*this);
25 if(TSceptar::SetWave()) {
26 if(frag.GetWaveform()->empty()) {
27 std::cout << "Warning, TSceptar::SetWave() set, but data waveform size is zero!" << std::endl;
28 }
29 frag.CopyWave(*this);
30 if(!GetWaveform()->empty()) {
32 }
33 }
34}
35
36void TSceptarHit::Copy(TObject& rhs) const
37{
38 // Copies a TSceptarHit
40 static_cast<TSceptarHit&>(rhs).fFilter = fFilter;
41}
42
43void TSceptarHit::Copy(TObject& obj, bool waveform) const
44{
45 Copy(obj);
46 if(waveform) {
47 CopyWave(obj);
48 }
49}
50
51TVector3 TSceptarHit::GetPosition(Double_t) const
52{
53 // Gets the position of the current TSceptarHit
55}
56
58{
59 // Gets the position of the current TSceptarHit
61}
62
64{
65 // check if the desired filter is in wanted filter;
66 // return the answer;
67 return true;
68}
69
70void TSceptarHit::Clear(Option_t*)
71{
72 // Clears the SceptarHit
73 fFilter = 0;
75}
76
77void TSceptarHit::Print(Option_t*) const
78{
79 /// Prints the SceptarHit. Returns:
80 /// Detector
81 /// Energy
82 /// Time
83 Print(std::cout);
84}
85
86void TSceptarHit::Print(std::ostream& out) const
87{
88 std::ostringstream str;
89 str << "Sceptar Detector: " << GetDetector() << std::endl;
90 str << "Sceptar hit energy: " << GetEnergy() << std::endl;
91 str << "Sceptar hit time: " << GetTime() << std::endl;
92 out << str.str();
93}
94
96{
97 // Calculates the cfd time from the waveform
98 bool error = false;
99 if(!HasWave()) {
100 return false; // Error!
101 }
102
103 std::vector<Int_t> baselineCorrections(8, 0);
104 std::vector<Short_t> newWaveform(*GetWaveform());
105
106 // all timing algorithms use interpolation with this many steps between two samples (all times are stored as
107 // integers)
108 unsigned int interpolationSteps = 256;
109 int delay = 8;
110 double attenuation = 24. / 64.;
111 int halfsmoothingwindow = 0; // 2*halfsmoothingwindow + 1 = number of samples in moving window.
112
113 // baseline algorithm: correct each adc with average of first two samples in that adc
114 for(size_t i = 0; i < 8 && i < WaveSize(); ++i) {
115 baselineCorrections[i] = GetWaveform()->at(i);
116 }
117 for(size_t i = 8; i < 16 && i < WaveSize(); ++i) {
118 baselineCorrections[i - 8] =
119 ((baselineCorrections[i - 8] + GetWaveform()->at(i)) + ((baselineCorrections[i - 8] + GetWaveform()->at(i)) > 0 ? 1 : -1)) >>
120 1;
121 }
122 for(size_t i = 0; i < WaveSize(); ++i) {
123 newWaveform[i] -= baselineCorrections[i % 8];
124 }
125 SetWaveform(newWaveform);
126
127 SetCfd(CalculateCfd(attenuation, delay, halfsmoothingwindow, interpolationSteps));
128
129 return !error;
130}
131
132Int_t TSceptarHit::CalculateCfd(double attenuation, unsigned int delay, int halfsmoothingwindow,
133 unsigned int interpolationSteps)
134{
135 // Used when calculating the CFD from the waveform
136 std::vector<Short_t> monitor;
137
138 return CalculateCfdAndMonitor(attenuation, delay, halfsmoothingwindow, interpolationSteps, monitor);
139}
140
141Int_t TSceptarHit::CalculateCfdAndMonitor(double attenuation, unsigned int delay, int halfsmoothingwindow,
142 unsigned int interpolationSteps, std::vector<Short_t>& monitor)
143{
144 // Used when calculating the CFD from the waveform
145
146 Short_t monitormax = 0;
147
148 bool armed = false;
149
150 Int_t cfd = 0;
151
152 std::vector<Short_t> smoothedWaveform;
153
154 if(!HasWave()) {
155 return INT_MAX; // Error!
156 }
157
158 if(static_cast<unsigned int>(WaveSize()) > delay + 1) {
159
160 if(halfsmoothingwindow > 0) {
161 smoothedWaveform = TSceptarHit::CalculateSmoothedWaveform(halfsmoothingwindow);
162 } else {
163 smoothedWaveform = *GetWaveform();
164 }
165
166 monitor.resize(smoothedWaveform.size() - delay);
167 monitor[0] = static_cast<Short_t>(attenuation * smoothedWaveform[delay] - smoothedWaveform[0]);
168 if(monitor[0] > monitormax) {
169 armed = true;
170 monitormax = monitor[0];
171 }
172
173 for(unsigned int i = delay + 1; i < smoothedWaveform.size(); ++i) {
174 monitor[i - delay] = static_cast<Short_t>(attenuation * smoothedWaveform[i] - smoothedWaveform[i - delay]);
175 if(monitor[i - delay] > monitormax) {
176 armed = true;
177 monitormax = monitor[i - delay];
178 } else {
179 if(armed && monitor[i - delay] < 0) {
180 armed = false;
181 if(monitor[i - delay - 1] - monitor[i - delay] != 0) {
182 // Linear interpolation.
183 cfd = (i - delay - 1) * interpolationSteps +
184 (monitor[i - delay - 1] * interpolationSteps) / (monitor[i - delay - 1] - monitor[i - delay]);
185 } else {
186 // Should be impossible, since monitor[i-delay-1] => 0 and monitor[i-delay] > 0
187 cfd = 0;
188 }
189 }
190 }
191 }
192 } else {
193 monitor.resize(0);
194 }
195
196 return cfd;
197}
198
199std::vector<Short_t> TSceptarHit::CalculateSmoothedWaveform(unsigned int halfsmoothingwindow)
200{
201 // Used when calculating the CFD from the waveform
202
203 if(!HasWave()) {
204 return {}; // Error!
205 }
206
207 std::vector<Short_t> smoothedWaveform(std::max(static_cast<size_t>(0), WaveSize() - 2 * halfsmoothingwindow),
208 0);
209
210 for(size_t i = halfsmoothingwindow; i < WaveSize() - halfsmoothingwindow; ++i) {
211 for(int j = -static_cast<int>(halfsmoothingwindow); j <= static_cast<int>(halfsmoothingwindow); ++j) {
212 smoothedWaveform[i - halfsmoothingwindow] += GetWaveform()->at(i + j);
213 }
214 }
215
216 return smoothedWaveform;
217}
218
219std::vector<Short_t> TSceptarHit::CalculateCfdMonitor(double attenuation, int delay, int halfsmoothingwindow)
220{
221 // Used when calculating the CFD from the waveform
222
223 if(!HasWave()) {
224 return {}; // Error!
225 }
226
227 std::vector<Short_t> smoothedWaveform;
228
229 if(halfsmoothingwindow > 0) {
230 smoothedWaveform = TSceptarHit::CalculateSmoothedWaveform(halfsmoothingwindow);
231 } else {
232 smoothedWaveform = *GetWaveform();
233 }
234
235 std::vector<Short_t> monitor(std::max(static_cast<size_t>(0), smoothedWaveform.size() - delay), 0);
236
237 for(size_t i = delay; i < smoothedWaveform.size(); ++i) {
238 monitor[i - delay] = static_cast<Short_t>(attenuation * smoothedWaveform[i] - smoothedWaveform[i - delay]);
239 }
240
241 return monitor;
242}
virtual void SetCfd(const Float_t &val)
!
virtual double GetEnergy(Option_t *opt="") const
void SetWaveform(const std::vector< Short_t > &val)
!
const std::vector< Short_t > * GetWaveform() const
!
void Clear(Option_t *opt="") override
!
virtual Int_t GetDetector() const
!
void Copy(TObject &) const override
!
virtual Double_t GetTime(const ETimeFlag &correct_flag=ETimeFlag::kAll, Option_t *opt="") const
Returns a time value to the nearest nanosecond!
virtual bool HasWave() const
!
virtual size_t WaveSize() const
!
virtual void CopyWave(TObject &) const
!
Double_t GetDefaultDistance() const
Definition TSceptarHit.h:66
Int_t CalculateCfdAndMonitor(double attenuation, unsigned int delay, int halfsmoothingwindow, unsigned int interpolationSteps, std::vector< Short_t > &monitor)
!
void Print(Option_t *opt="") const override
!
bool InFilter(Int_t)
!
Int_t fFilter
Definition TSceptarHit.h:64
void Clear(Option_t *opt="") override
!
std::vector< Short_t > CalculateSmoothedWaveform(unsigned int halfsmoothingwindow)
!
void Copy(TObject &) const override
!
Int_t CalculateCfd(double attenuation, unsigned int delay, int halfsmoothingwindow, unsigned int interpolationSteps)
!
TVector3 GetPosition() const override
!
bool AnalyzeWaveform()
!
std::vector< Short_t > CalculateCfdMonitor(double attenuation, int delay, int halfsmoothingwindow)
!
static TVector3 GetPosition(int DetNbr)
!
Definition TSceptar.h:42
static bool SetWave()
!
Definition TSceptar.h:44