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