GRSISort "v4.1.1.0"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TDetectorHit.cxx
Go to the documentation of this file.
1#include "TDetectorHit.h"
2#include "TGRSIOptions.h"
3
4#include <iostream>
5
6#include "TClass.h"
7
8TVector3 TDetectorHit::fBeamDirection(0, 0, 1);
9
10TDetectorHit::TDetectorHit(const int& address)
11{
12 /// Default constructor
13 Clear();
14 // this needs to happen here, after we call Clear
15 // otherwise if will be cleared as well
16 fAddress = address; // NOLINT(cppcoreguidelines-prefer-member-initializer)
17}
18
19TDetectorHit::TDetectorHit(const TDetectorHit& rhs, bool copywave) : TObject(rhs)
20{
21 /// Default Copy constructor
22 rhs.Copy(*this);
23 // if we can get the commandline options, we respect whether ExtracWaves has been set or not
24 // otherwise we rely on the copywave flag (defaults to true)
25 if((TGRSIOptions::Get() != nullptr && TGRSIOptions::Get()->ExtractWaves()) ||
26 (TGRSIOptions::Get() == nullptr && copywave)) {
27 rhs.CopyWave(*this);
28 }
30}
31
33
34void TDetectorHit::Streamer(TBuffer& R__b)
35{
36 /// Stream an object of class TDetectorHit.
37 if(R__b.IsReading()) {
38 R__b.ReadClassBuffer(TDetectorHit::Class(), this);
39 } else {
40 fBitFlags = 0;
41 R__b.WriteClassBuffer(TDetectorHit::Class(), this);
42 }
43}
44
45Double_t TDetectorHit::GetTime(const ETimeFlag&, Option_t*) const
46{
47 if(IsTimeSet()) {
48 return fTime;
49 }
50 TChannel* tmpChan = GetChannel();
51 if(tmpChan == nullptr) {
52 return SetTime(static_cast<Double_t>(static_cast<double>(GetTimeStamp()) + gRandom->Uniform()));
53 }
54
55 //return SetTime(tmpChan->GetTime(GetTimeStamp(), GetCfd(), GetEnergy()) * (1. - tmpChan->GetTimeDrift()));
56 return SetTime(tmpChan->GetTime(GetTimeStamp(), GetCfd(), GetEnergy()) * (1. - tmpChan->GetTimeDrift()) - tmpChan->GetTimeNonlinearity(GetTimeStamp()));
57}
58
60{
61 TChannel* channel = GetChannel();
62 if(channel == nullptr) {
63 return Charge();
64 }
65 if(fKValue > 0 && !channel->UseCalFileIntegration()) {
66 return Charge() / (static_cast<Float_t>(fKValue)); // this will use the integration value
67 }
68 if(channel->UseCalFileIntegration()) {
69 return Charge() / (static_cast<Float_t>(channel->GetIntegration())); // this will use the integration value
70 } // in the TChannel if it exists.
71 return Charge(); // this will use no integration value
72}
73
74double TDetectorHit::GetEnergy(Option_t*) const
75{
77 return fEnergy;
78 }
79 TChannel* channel = GetChannel();
80 if(channel == nullptr) {
81 return SetEnergy(static_cast<Double_t>(Charge()));
82 }
83 if(channel->UseCalFileIntegration()) {
84 double energy = channel->CalibrateENG(Charge(), 0);
85 return SetEnergy(energy +
86 GetEnergyNonlinearity(energy)); // this will use the integration value
87 // in the TChannel if it exists.
88 }
89 if(fKValue > 0) {
90 double energy = channel->CalibrateENG(Charge(), static_cast<int>(fKValue));
91 return SetEnergy(energy + GetEnergyNonlinearity(energy));
92 }
93 double energy = channel->CalibrateENG(Charge());
94 return SetEnergy(energy + GetEnergyNonlinearity(energy));
95}
96
97Double_t TDetectorHit::GetEnergyNonlinearity(double energy) const
98{
99 TChannel* channel = GetChannel();
100 if(channel == nullptr) {
101 return 0.;
102 }
103 return -(channel->GetEnergyNonlinearity(energy));
104}
105
106Double_t TDetectorHit::GetTimeNonlinearity(Long64_t mytimestamp) const
107{
108 TChannel* channel = GetChannel();
109 if(channel == nullptr) {
110 return 0.;
111 }
112 return -(channel->GetTimeNonlinearity(mytimestamp));
113}
114
115void TDetectorHit::Copy(TObject& rhs) const
116{
117 TObject::Copy(rhs);
118 static_cast<TDetectorHit&>(rhs).fAddress = fAddress;
119 // static_cast<TDetectorHit&>(rhs).fPosition = fPosition;
120 static_cast<TDetectorHit&>(rhs).fCfd = fCfd;
121 static_cast<TDetectorHit&>(rhs).fTimeStamp = fTimeStamp;
122 static_cast<TDetectorHit&>(rhs).fCharge = fCharge;
123 static_cast<TDetectorHit&>(rhs).fKValue = fKValue;
124 static_cast<TDetectorHit&>(rhs).fEnergy = fEnergy;
125 static_cast<TDetectorHit&>(rhs).fTime = fTime;
126 static_cast<TDetectorHit&>(rhs).fChannel = fChannel;
127
128 static_cast<TDetectorHit&>(rhs).fBitFlags = fBitFlags;
129 static_cast<TDetectorHit&>(rhs).fPPGStatus = fPPGStatus;
130 static_cast<TDetectorHit&>(rhs).fCycleTimeStamp = fCycleTimeStamp;
131 if(IsEnergySet()) {
132 static_cast<TDetectorHit&>(rhs).fEnergy = fEnergy;
133 }
134 if(IsChannelSet()) {
135 static_cast<TDetectorHit&>(rhs).fChannel = fChannel;
136 }
137 if(IsTimeSet()) {
138 static_cast<TDetectorHit&>(rhs).fTime = fTime;
139 }
140 if(IsPPGSet()) {
141 static_cast<TDetectorHit&>(rhs).fPPGStatus = fPPGStatus;
142 static_cast<TDetectorHit&>(rhs).fCycleTimeStamp = fCycleTimeStamp;
143 }
144}
145
146void TDetectorHit::CopyWave(TObject& rhs) const
147{
148 static_cast<TDetectorHit&>(rhs).fWaveform = fWaveform;
149}
150
151void TDetectorHit::Copy(TObject& rhs, bool copywave) const
152{
153 Copy(rhs);
154 if(copywave) {
155 CopyWave(rhs);
156 }
157}
158
159//void TDetectorHit::CopyFragment(const TFragment& frag)
160//{
161// frag.Copy(*this);
162//}
163
164void TDetectorHit::Print(Option_t*) const
165{
166 /// General print statement for a TDetectorHit.
167 Print(std::cout);
168}
169
170void TDetectorHit::Print(std::ostream& out) const
171{
172 /// Print detector hit to stream out.
173 std::ostringstream str;
174 str << "==== " << ClassName() << " @ " << this << " ====" << std::endl;
175 str << "\t" << GetName() << std::endl;
176 str << "\tCharge: " << Charge() << std::endl;
177 str << "\tTime: " << GetTime() << std::endl;
178 str << "\tTimestamp: " << GetTimeStamp() << " in " << GetTimeStampUnit() << " ns = " << GetTimeStampNs() << std::endl;
179 str << "============================" << std::endl;
180 out << str.str();
181}
182
183const char* TDetectorHit::GetName() const
184{
185 TChannel* channel = GetChannel();
186 if(channel == nullptr) {
187 return Class()->ClassName();
188 }
189 return channel->GetName();
190}
191
192void TDetectorHit::Clear(Option_t*)
193{
194 /// General clear statement for a TDetectorHit.
195 fAddress = 0xffffffff; // -1
196 fCharge = 0;
197 fKValue = 0;
198 fCfd = -1;
199 fTimeStamp = 0;
200 fWaveform.clear(); // reset size to zero.
201 fTime = 0.;
202 fEnergy = 0.;
204 fCycleTimeStamp = 0;
205 fChannel = nullptr;
206 fBitFlags = 0;
207}
208
210{
211 TChannel* channel = GetChannel();
212 if(channel == nullptr) {
213 return -1;
214 }
215 return channel->GetDetectorNumber(); // mnemonic.arrayposition;
216}
217
219{
220 TChannel* channel = GetChannel();
221 if(channel == nullptr) {
222 return -1;
223 }
224 return channel->GetSegmentNumber();
225}
226
228{
229 TChannel* channel = GetChannel();
230 if(channel != nullptr) {
231 return channel->GetCrystalNumber();
232 }
233 return -1;
234}
235
237{
238 return (lhs->GetEnergy() > rhs->GetEnergy());
239}
240
242{
244 if(chan == nullptr) {
245 return 0;
246 }
247 return chan->GetNumber();
248}
249
250Long64_t TDetectorHit::GetTimeStampNs(Option_t*) const
251{
252 TChannel* tmpChan = GetChannel();
253 if(tmpChan == nullptr) {
254 return GetTimeStamp(); // GetTimeStampUnit returns 1 if there is no channel
255 }
256 return GetTimeStamp() * GetTimeStampUnit() - tmpChan->GetTimeOffset();
257}
258
260{
261 TChannel* chan = GetChannel();
262 if(chan == nullptr) {
263 return 1;
264 }
265 return chan->GetTimeStampUnit();
266}
267
269{
270 if(IsPPGSet()) {
271 return fPPGStatus;
272 }
273
274 if(TPPG::Get() == nullptr) {
275 return EPpgPattern::kJunk;
276 }
277
281 return fPPGStatus;
282}
283
285{
286 if(IsPPGSet()) {
287 return fCycleTimeStamp;
288 }
289
290 if(TPPG::Get() == nullptr) {
291 return 0;
292 }
293
297 return fCycleTimeStamp;
298}
299
301{
302 /// returns time in ns, minus the time of the last tape move
303 return GetTime() - static_cast<double>(TPPG::Get()->GetLastStatusTime(GetTimeStampNs(), EPpgPattern::kTapeMove));
304}
305
306// const here is rather dirty
307void TDetectorHit::SetHitBit(enum EBitFlag flag, Bool_t set) const
308{
309 fBitFlags.SetBit(flag, set);
310}
double CalibrateENG(double) const
Definition TChannel.cxx:668
int GetDetectorNumber() const
int GetCrystalNumber() const
double GetTime(Long64_t timestamp, Float_t cfd, double energy) const
int GetSegmentNumber() const
TGraph GetEnergyNonlinearity() const
Definition TChannel.h:195
bool UseCalFileIntegration()
Definition TChannel.h:186
static TChannel * GetChannel(unsigned int temp_address, bool warn=false)
Definition TChannel.cxx:476
Long64_t GetTimeOffset() const
Definition TChannel.h:173
TGraph GetTimeNonlinearity() const
Definition TChannel.h:197
double GetTimeDrift() const
Definition TChannel.h:174
int GetNumber() const
Definition TChannel.h:166
int GetTimeStampUnit() const
Definition TChannel.h:172
int GetIntegration() const
Definition TChannel.h:168
virtual Float_t GetCharge() const
!
Double_t SetEnergy(const double &energy) const
double GetTimeSinceTapeMove() const
TChannel * fChannel
!
TDetectorHit(const int &Address=0xffffffff)
virtual Long64_t GetTimeStampNs(Option_t *opt="") const
virtual Long64_t GetTimeStamp(Option_t *="") const
virtual double GetEnergy(Option_t *opt="") const
EPpgPattern GetPPGStatus() const
virtual void ClearTransients() const
const char * GetName() const override
!
std::vector< Short_t > fWaveform
Bool_t IsTimeSet() const
TTransientBits< UChar_t > fBitFlags
virtual Int_t GetCrystal() const
!
Long64_t fCycleTimeStamp
!
virtual Float_t Charge() const
!
Float_t fCharge
charge collected from the hit
virtual Double_t GetEnergyNonlinearity(double energy) const
virtual int GetChannelNumber() const
!
TChannel * GetChannel() const
!
virtual Int_t GetTimeStampUnit() const
!
Double_t fTime
! Calibrated Time of the hit
bool TestHitBit(EBitFlag flag) const
Bool_t IsPPGSet() const
UInt_t fAddress
address of the the channel in the DAQ.
EPpgPattern fPPGStatus
!
Double_t fEnergy
! Energy of the Hit.
static bool CompareEnergy(TDetectorHit *lhs, TDetectorHit *rhs)
void Clear(Option_t *opt="") override
!
virtual Int_t GetDetector() const
!
virtual Double_t GetTimeNonlinearity(Long64_t mytimestamp) const
virtual Float_t GetCfd() const
!
virtual Int_t GetSegment() 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!
void SetHitBit(EBitFlag, Bool_t set=true) const
Short_t fKValue
integration value.
Bool_t IsEnergySet() const
static TVector3 fBeamDirection
Bool_t IsChannelSet() const
Long64_t fTimeStamp
Timestamp given to hit in ns.
Long64_t GetCycleTimeStamp() const
Float_t fCfd
CFD time of the Hit.
Double_t SetTime(const Double_t &time) const
virtual void CopyWave(TObject &) const
!
void Print(Option_t *opt="") const override
!
static TGRSIOptions * Get(int argc=0, char **argv=nullptr)
Do not use!
EPpgPattern GetStatus(ULong64_t time) const
Definition TPPG.cxx:189
ULong64_t GetLastStatusTime(ULong64_t time, EPpgPattern pat=EPpgPattern::kJunk) const
Definition TPPG.cxx:133
static TPPG * Get(bool verbose=false)
Definition TSingleton.h:33
void SetBit(T bit, Bool_t flag)
EPpgPattern
Definition TPPG.h:36