GRSISort "v4.0.0.5"
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 = 0;
129 static_cast<TDetectorHit&>(rhs).fPPGStatus = fPPGStatus;
130 static_cast<TDetectorHit&>(rhs).fCycleTimeStamp = fCycleTimeStamp;
131}
132
133void TDetectorHit::CopyWave(TObject& rhs) const
134{
135 static_cast<TDetectorHit&>(rhs).fWaveform = fWaveform;
136}
137
138void TDetectorHit::Copy(TObject& rhs, bool copywave) const
139{
140 Copy(rhs);
141 if(copywave) {
142 CopyWave(rhs);
143 }
144}
145
146//void TDetectorHit::CopyFragment(const TFragment& frag)
147//{
148// frag.Copy(*this);
149//}
150
151void TDetectorHit::Print(Option_t*) const
152{
153 /// General print statement for a TDetectorHit.
154 Print(std::cout);
155}
156
157void TDetectorHit::Print(std::ostream& out) const
158{
159 /// Print detector hit to stream out.
160 std::ostringstream str;
161 str << "==== " << ClassName() << " @ " << this << " ====" << std::endl;
162 str << "\t" << GetName() << std::endl;
163 str << "\tCharge: " << Charge() << std::endl;
164 str << "\tTime: " << GetTime() << std::endl;
165 str << "\tTimestamp: " << GetTimeStamp() << " in " << GetTimeStampUnit() << " ns = " << GetTimeStampNs() << std::endl;
166 str << "============================" << std::endl;
167 out << str.str();
168}
169
170const char* TDetectorHit::GetName() const
171{
172 TChannel* channel = GetChannel();
173 if(channel == nullptr) {
174 return Class()->ClassName();
175 }
176 return channel->GetName();
177}
178
179void TDetectorHit::Clear(Option_t*)
180{
181 /// General clear statement for a TDetectorHit.
182 fAddress = 0xffffffff; // -1
183 fCharge = 0;
184 fKValue = 0;
185 fCfd = -1;
186 fTimeStamp = 0;
187 fWaveform.clear(); // reset size to zero.
188 fTime = 0.;
189 fEnergy = 0.;
191 fCycleTimeStamp = 0;
192 fChannel = nullptr;
193 fBitFlags = 0;
194}
195
197{
198 TChannel* channel = GetChannel();
199 if(channel == nullptr) {
200 return -1;
201 }
202 return channel->GetDetectorNumber(); // mnemonic.arrayposition;
203}
204
206{
207 TChannel* channel = GetChannel();
208 if(channel == nullptr) {
209 return -1;
210 }
211 return channel->GetSegmentNumber();
212}
213
215{
216 TChannel* channel = GetChannel();
217 if(channel != nullptr) {
218 return channel->GetCrystalNumber();
219 }
220 return -1;
221}
222
224{
225 return (lhs->GetEnergy() > rhs->GetEnergy());
226}
227
229{
231 if(chan == nullptr) {
232 return 0;
233 }
234 return chan->GetNumber();
235}
236
237Long64_t TDetectorHit::GetTimeStampNs(Option_t*) const
238{
239 TChannel* tmpChan = GetChannel();
240 if(tmpChan == nullptr) {
241 return GetTimeStamp(); // GetTimeStampUnit returns 1 if there is no channel
242 }
243 return GetTimeStamp() * GetTimeStampUnit() - tmpChan->GetTimeOffset();
244}
245
247{
248 TChannel* chan = GetChannel();
249 if(chan == nullptr) {
250 return 1;
251 }
252 return chan->GetTimeStampUnit();
253}
254
256{
257 if(IsPPGSet()) {
258 return fPPGStatus;
259 }
260
261 if(TPPG::Get() == nullptr) {
262 return EPpgPattern::kJunk;
263 }
264
268 return fPPGStatus;
269}
270
272{
273 if(IsPPGSet()) {
274 return fCycleTimeStamp;
275 }
276
277 if(TPPG::Get() == nullptr) {
278 return 0;
279 }
280
284 return fCycleTimeStamp;
285}
286
288{
289 /// returns time in ns, minus the time of the last tape move
290 return GetTime() - static_cast<double>(TPPG::Get()->GetLastStatusTime(GetTimeStampNs(), EPpgPattern::kTapeMove));
291}
292
293// const here is rather dirty
294void TDetectorHit::SetHitBit(enum EBitFlag flag, Bool_t set) const
295{
296 fBitFlags.SetBit(flag, set);
297}
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.
static TVector3 fBeamDirection
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