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()));
56}
57
59{
60 TChannel* channel = GetChannel();
61 if(channel == nullptr) {
62 return Charge();
63 }
64 if(fKValue > 0 && !channel->UseCalFileIntegration()) {
65 return Charge() / (static_cast<Float_t>(fKValue)); // this will use the integration value
66 }
67 if(channel->UseCalFileIntegration()) {
68 return Charge() / (static_cast<Float_t>(channel->GetIntegration())); // this will use the integration value
69 } // in the TChannel if it exists.
70 return Charge(); // this will use no integration value
71}
72
73double TDetectorHit::GetEnergy(Option_t*) const
74{
76 return fEnergy;
77 }
78 TChannel* channel = GetChannel();
79 if(channel == nullptr) {
80 return SetEnergy(static_cast<Double_t>(Charge()));
81 }
82 if(channel->UseCalFileIntegration()) {
83 double energy = channel->CalibrateENG(Charge(), 0);
84 return SetEnergy(energy +
85 GetEnergyNonlinearity(energy)); // this will use the integration value
86 // in the TChannel if it exists.
87 }
88 if(fKValue > 0) {
89 double energy = channel->CalibrateENG(Charge(), static_cast<int>(fKValue));
90 return SetEnergy(energy + GetEnergyNonlinearity(energy));
91 }
92 double energy = channel->CalibrateENG(Charge());
93 return SetEnergy(energy + GetEnergyNonlinearity(energy));
94}
95
96Double_t TDetectorHit::GetEnergyNonlinearity(double energy) const
97{
98 TChannel* channel = GetChannel();
99 if(channel == nullptr) {
100 return 0.;
101 }
102 return -(channel->GetEnergyNonlinearity(energy));
103}
104
105void TDetectorHit::Copy(TObject& rhs) const
106{
107 TObject::Copy(rhs);
108 static_cast<TDetectorHit&>(rhs).fAddress = fAddress;
109 // static_cast<TDetectorHit&>(rhs).fPosition = fPosition;
110 static_cast<TDetectorHit&>(rhs).fCfd = fCfd;
111 static_cast<TDetectorHit&>(rhs).fTimeStamp = fTimeStamp;
112 static_cast<TDetectorHit&>(rhs).fCharge = fCharge;
113 static_cast<TDetectorHit&>(rhs).fKValue = fKValue;
114 static_cast<TDetectorHit&>(rhs).fEnergy = fEnergy;
115 static_cast<TDetectorHit&>(rhs).fTime = fTime;
116 static_cast<TDetectorHit&>(rhs).fChannel = fChannel;
117
118 static_cast<TDetectorHit&>(rhs).fBitFlags = 0;
119 static_cast<TDetectorHit&>(rhs).fPPGStatus = fPPGStatus;
120 static_cast<TDetectorHit&>(rhs).fCycleTimeStamp = fCycleTimeStamp;
121}
122
123void TDetectorHit::CopyWave(TObject& rhs) const
124{
125 static_cast<TDetectorHit&>(rhs).fWaveform = fWaveform;
126}
127
128void TDetectorHit::Copy(TObject& rhs, bool copywave) const
129{
130 Copy(rhs);
131 if(copywave) {
132 CopyWave(rhs);
133 }
134}
135
136//void TDetectorHit::CopyFragment(const TFragment& frag)
137//{
138// frag.Copy(*this);
139//}
140
141void TDetectorHit::Print(Option_t*) const
142{
143 /// General print statement for a TDetectorHit.
144 Print(std::cout);
145}
146
147void TDetectorHit::Print(std::ostream& out) const
148{
149 /// Print detector hit to stream out.
150 std::ostringstream str;
151 str << "==== " << ClassName() << " @ " << this << " ====" << std::endl;
152 str << "\t" << GetName() << std::endl;
153 str << "\tCharge: " << Charge() << std::endl;
154 str << "\tTime: " << GetTime() << std::endl;
155 str << "\tTimestamp: " << GetTimeStamp() << " in " << GetTimeStampUnit() << " ns = " << GetTimeStampNs() << std::endl;
156 str << "============================" << std::endl;
157 out << str.str();
158}
159
160const char* TDetectorHit::GetName() const
161{
162 TChannel* channel = GetChannel();
163 if(channel == nullptr) {
164 return Class()->ClassName();
165 }
166 return channel->GetName();
167}
168
169void TDetectorHit::Clear(Option_t*)
170{
171 /// General clear statement for a TDetectorHit.
172 fAddress = 0xffffffff; // -1
173 fCharge = 0;
174 fKValue = 0;
175 fCfd = -1;
176 fTimeStamp = 0;
177 fWaveform.clear(); // reset size to zero.
178 fTime = 0.;
179 fEnergy = 0.;
181 fCycleTimeStamp = 0;
182 fChannel = nullptr;
183 fBitFlags = 0;
184}
185
187{
188 TChannel* channel = GetChannel();
189 if(channel == nullptr) {
190 return -1;
191 }
192 return channel->GetDetectorNumber(); // mnemonic.arrayposition;
193}
194
196{
197 TChannel* channel = GetChannel();
198 if(channel == nullptr) {
199 return -1;
200 }
201 return channel->GetSegmentNumber();
202}
203
205{
206 TChannel* channel = GetChannel();
207 if(channel != nullptr) {
208 return channel->GetCrystalNumber();
209 }
210 return -1;
211}
212
214{
215 return (lhs->GetEnergy() > rhs->GetEnergy());
216}
217
219{
221 if(chan == nullptr) {
222 return 0;
223 }
224 return chan->GetNumber();
225}
226
227Long64_t TDetectorHit::GetTimeStampNs(Option_t*) const
228{
229 TChannel* tmpChan = GetChannel();
230 if(tmpChan == nullptr) {
231 return GetTimeStamp(); // GetTimeStampUnit returns 1 of there is no channel
232 }
233 return GetTimeStamp() * GetTimeStampUnit() * static_cast<Long64_t>((1.0 - tmpChan->GetTimeDrift())) - tmpChan->GetTimeOffset();
234}
235
237{
238 TChannel* chan = GetChannel();
239 if(chan == nullptr) {
240 return 1;
241 }
242 return chan->GetTimeStampUnit();
243}
244
246{
247 if(IsPPGSet()) {
248 return fPPGStatus;
249 }
250
251 if(TPPG::Get() == nullptr) {
252 return EPpgPattern::kJunk;
253 }
254
258 return fPPGStatus;
259}
260
262{
263 if(IsPPGSet()) {
264 return fCycleTimeStamp;
265 }
266
267 if(TPPG::Get() == nullptr) {
268 return 0;
269 }
270
274 return fCycleTimeStamp;
275}
276
278{
279 /// returns time in ns, minus the time of the last tape move
280 return GetTime() - static_cast<double>(TPPG::Get()->GetLastStatusTime(GetTimeStampNs(), EPpgPattern::kTapeMove));
281}
282
283// const here is rather dirty
284void TDetectorHit::SetHitBit(enum EBitFlag flag, Bool_t set) const
285{
286 fBitFlags.SetBit(flag, set);
287}
double CalibrateENG(double) const
Definition TChannel.cxx:646
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:198
bool UseCalFileIntegration()
Definition TChannel.h:189
static TChannel * GetChannel(unsigned int temp_address, bool warn=false)
Definition TChannel.cxx:459
Long64_t GetTimeOffset() const
Definition TChannel.h:176
double GetTimeDrift() const
Definition TChannel.h:177
int GetNumber() const
Definition TChannel.h:169
int GetTimeStampUnit() const
Definition TChannel.h:175
int GetIntegration() const
Definition TChannel.h:171
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 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:187
ULong64_t GetLastStatusTime(ULong64_t time, EPpgPattern pat=EPpgPattern::kJunk) const
Definition TPPG.cxx:131
static TPPG * Get(bool verbose=false)
Definition TSingleton.h:33
void SetBit(T bit, Bool_t flag)
EPpgPattern
Definition TPPG.h:38