GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TDetectorHit.h
Go to the documentation of this file.
1#ifndef TDETECTORHIT_H
2#define TDETECTORHIT_H
3
4/** \addtogroup Detectors
5 * @{
6 */
7
8#include <vector>
9#include <cstdint>
10
11#include "TChannel.h"
12#include "TVector3.h"
13#include "TObject.h"
14#include "Rtypes.h"
15#include "TRandom.h"
16
17#include "TPPG.h"
18#include "TTransientBits.h"
19
20class TDetector;
21
22/////////////////////////////////////////////////////////////////
23///
24/// \class TDetectorHit
25///
26/// This is class that contains the basic info about detector
27/// hits:
28/// 1. An address. The whoami for the detector. This is the value used by TChannel::GetChannel(address);
29///
30/// 2. An "Energy value." What this is left the parent class, but it is going to return a double.
31///
32/// 3. A Time value. This should be a time value common for detectors (derived from the timestamp)
33/// Units matter here, I am adobting the ns as the standard.
34///
35/// 4. A Position. Tvector3s are nice, they make doing geometery trival. Each hit needs one to determine
36/// where it is in space, the actual memory of the thing will be stored here.
37/// *** This is not actually needed here unless we start do waveform analysis to
38/// *** better determine where the hit is.
39///
40/// 5. The waveform. Since we are dealing with digital daqs, a waveform is a fairly common thing to have. It
41/// may not always be present, put it is echoed enough that the storage for it belongs here.
42///
43/////////////////////////////////////////////////////////////////
44
45class TDetectorHit : public TObject {
46public:
47 enum class EBitFlag : std::uint16_t {
48 kIsEnergySet = BIT(0), // same as BIT(0);
49 kIsChannelSet = BIT(1),
50 kBit2 = BIT(2),
51 kBit3 = BIT(3),
52 kIsPPGSet = BIT(4),
53 kIsTimeSet = BIT(5),
54 kBit6 = BIT(6),
55 kBit7 = BIT(7),
56 kBit8 = BIT(8),
57 // reserved for derived class.
58 kDetHitBit0 = BIT(9),
59 kDetHitBit1 = BIT(10),
60 kDetHitBit2 = BIT(11),
61 kDetHitBit3 = BIT(12),
62 kDetHitBit4 = BIT(13),
63 kDetHitBit5 = BIT(14),
64 kDetHitBit6 = BIT(15),
65 kBase = BIT(9),
66 kIsAllSet = 0xFFFF
67 };
68
69 enum class ETimeFlag : std::uint16_t { kNoneSet = BIT(0),
70 kCFD = BIT(1),
71 kWalk = BIT(2),
72 kOffset = BIT(3),
73 kAll = 0xFFFF };
74
75 explicit TDetectorHit(const int& Address = 0xffffffff);
76 TDetectorHit(const TDetectorHit&, bool copywave = true);
77 TDetectorHit(TDetectorHit&&) noexcept = default;
79
80 TDetectorHit& operator=(const TDetectorHit&) = default;
81 TDetectorHit& operator=(TDetectorHit&&) noexcept = default;
82
83 // static void SetPPGPtr(TPPG* ptr) { fPPG = ptr; }
84
85 bool operator<(const TDetectorHit& rhs) const { return GetEnergy() > rhs.GetEnergy(); } // sorts large->small
86
87 void Copy(TObject&) const override; //!<!
88 virtual void Copy(TObject&, bool copywave) const; //!<!
89 virtual void CopyWave(TObject&) const; //!<!
90 void Clear(Option_t* opt = "") override; //!<!
91 virtual void ClearTransients() const { fBitFlags = 0; }
92 void Print(Option_t* opt = "") const override; //!<!
93 virtual void Print(std::ostream& out) const;
94 friend std::ostream& operator<<(std::ostream& out, const TDetectorHit& hit)
95 {
96 hit.Print(out);
97 return out;
98 }
99 virtual bool HasWave() const { return !fWaveform.empty(); } //!<!
100 virtual size_t WaveSize() const { return fWaveform.size(); } //!<!
101
102 static bool CompareEnergy(TDetectorHit* lhs, TDetectorHit* rhs);
103 // We need a common function for all detectors in here
104 // static bool Compare(TDetectorHit* lhs,TDetectorHit* rhs); //!<!
105
106 void SetAddress(const UInt_t& temp_address) { fAddress = temp_address; } //!<!
107 void SetKValue(const Short_t& temp_kval) { fKValue = temp_kval; } //!<!
108 void SetCharge(const Float_t& temp_charge) { fCharge = temp_charge; } //!<!
109 void SetCharge(const Int_t& temp_charge) { fCharge = static_cast<Float_t>(temp_charge) + static_cast<Float_t>(gRandom->Uniform()); } //!<! this function automatically randomizes the integer provided
110 virtual void SetCfd(const Float_t& val) { fCfd = val; } //!<!
111 virtual void SetCfd(const uint32_t& val) { fCfd = static_cast<Float_t>(val) + static_cast<Float_t>(gRandom->Uniform()); } //!<! this function automatically randomizes the integer provided
112 virtual void SetCfd(const Int_t& val) { fCfd = static_cast<Float_t>(val) + static_cast<Float_t>(gRandom->Uniform()); } //!<! this function automatically randomizes the integer provided
113 void SetWaveform(const std::vector<Short_t>& val) { fWaveform = val; } //!<!
114 void AddWaveformSample(const Short_t& val) { fWaveform.push_back(val); } //!<!
115 virtual void SetTimeStamp(const Long64_t& val) { fTimeStamp = val; } //!<!
116 virtual void AppendTimeStamp(const Long64_t& val) { fTimeStamp += val; } //!<!
117
118 Double_t SetEnergy(const double& energy) const
119 {
120 fEnergy = energy;
122 return fEnergy;
123 }
124 Double_t SetTime(const Double_t& time) const
125 {
126 fTime = time;
128 return fTime;
129 }
130
131 virtual TVector3 GetPosition(Double_t) const { return GetPosition(); } //!<!
132 virtual TVector3 GetPosition() const { return {0., 0., 0.}; } //!<!
133 virtual double GetEnergy(Option_t* opt = "") const;
134 virtual Double_t GetEnergyNonlinearity(double energy) const;
135 virtual Double_t GetTimeNonlinearity(Long64_t mytimestamp) const;
136 virtual Long64_t GetTimeStamp(Option_t* = "") const { return fTimeStamp; }
137 virtual Long64_t GetTimeStampNs(Option_t* opt = "") const;
138 virtual Double_t GetTime(const ETimeFlag& correct_flag = ETimeFlag::kAll,
139 Option_t* opt = "") const; ///< Returns a time value to the nearest nanosecond!
140 virtual Float_t GetCfd() const { return fCfd; } //!<!
141 virtual UInt_t GetAddress() const { return fAddress; } //!<!
142 virtual Float_t GetCharge() const; //!<!
143 virtual Float_t Charge() const { return fCharge; } //!<!
144 virtual Short_t GetKValue() const { return fKValue; } //!<!
145 const std::vector<Short_t>* GetWaveform() const { return &fWaveform; } //!<!
147 {
148 if(!IsChannelSet()) {
151 }
152 return fChannel;
153 } //!<!
154
155 // stored in the tchannel (things common to all hits of this address)
156 virtual int GetChannelNumber() const; //!<!
157 virtual Int_t GetDetector() const; //!<!
158 virtual Int_t GetSegment() const; //!<!
159 virtual Int_t GetCrystal() const; //!<!
160 const char* GetName() const override; //!<!
161 virtual UShort_t GetArrayNumber() const { return GetDetector(); } //!<! Simply returns the detector number, overwritten for detectors that have crystals/segments
162 virtual Int_t GetTimeStampUnit() const; //!<!
163
164 // The PPG is only stored in events that come out of the GRIFFIN DAQ
166 Long64_t GetCycleTimeStamp() const;
167 double GetTimeSinceTapeMove() const;
168
170 {
171 fEnergy = 0.0;
173 }
175 {
176 fChannel = nullptr;
178 }
179
180 static TVector3* GetBeamDirection() { return &fBeamDirection; }
181
182 virtual void Add(const TDetectorHit*) {} //!<!
183
184 void SetHitBit(EBitFlag, Bool_t set = true) const; // const here is dirty
185 bool TestHitBit(EBitFlag flag) const { return fBitFlags.TestBit(flag); }
186
187protected:
190 Bool_t IsTimeSet() const { return (fBitFlags.TestBit(EBitFlag::kIsTimeSet)); }
191 Bool_t IsPPGSet() const { return (fBitFlags.TestBit(EBitFlag::kIsPPGSet)); }
192
193private:
194 UInt_t fAddress{0}; ///< address of the the channel in the DAQ.
195 Float_t fCharge{0.}; ///< charge collected from the hit
196 Short_t fKValue{0}; ///< integration value.
197 Float_t fCfd{0}; ///< CFD time of the Hit
198 Long64_t fTimeStamp{0}; ///< Timestamp given to hit in ns
199 std::vector<Short_t> fWaveform; ///<
200 mutable Double_t fTime{0.}; //!<! Calibrated Time of the hit
201
202 mutable Double_t fEnergy{0.}; //!<! Energy of the Hit.
204
205 mutable Long64_t fCycleTimeStamp{0}; //!<!
206 mutable TChannel* fChannel{nullptr}; //!<!
207
208 // flags
210
211 static TVector3 fBeamDirection; //!
212
213 /// \cond CLASSIMP
214 ClassDefOverride(TDetectorHit, 1) // NOLINT(readability-else-after-return)
215 /// \endcond
216};
217/*! @} */
218#endif
static TChannel * GetChannel(unsigned int temp_address, bool warn=false)
Definition TChannel.cxx:476
void SetKValue(const Short_t &temp_kval)
!
virtual Float_t GetCharge() const
!
Double_t SetEnergy(const double &energy) const
double GetTimeSinceTapeMove() const
TChannel * fChannel
!
virtual UInt_t GetAddress() const
!
TDetectorHit(const int &Address=0xffffffff)
virtual void SetCfd(const Float_t &val)
!
virtual Long64_t GetTimeStampNs(Option_t *opt="") const
virtual Long64_t GetTimeStamp(Option_t *="") const
virtual TVector3 GetPosition() const
!
virtual double GetEnergy(Option_t *opt="") const
EPpgPattern GetPPGStatus() const
virtual Short_t GetKValue() const
!
void SetWaveform(const std::vector< Short_t > &val)
!
virtual void ClearTransients() const
const char * GetName() const override
!
std::vector< Short_t > fWaveform
const std::vector< Short_t > * GetWaveform() const
!
Bool_t IsTimeSet() const
TTransientBits< UChar_t > fBitFlags
virtual UShort_t GetArrayNumber() const
! Simply returns the detector number, overwritten for detectors that have crystals/segments
virtual Int_t GetCrystal() const
!
Long64_t fCycleTimeStamp
!
virtual void SetCfd(const uint32_t &val)
! this function automatically randomizes the integer provided
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
void SetCharge(const Float_t &temp_charge)
!
bool TestHitBit(EBitFlag flag) const
Bool_t IsPPGSet() const
virtual TVector3 GetPosition(Double_t) const
!
UInt_t fAddress
address of the the channel in the DAQ.
void AddWaveformSample(const Short_t &val)
!
void ClearEnergy()
EPpgPattern fPPGStatus
!
Double_t fEnergy
! Energy of the Hit.
static bool CompareEnergy(TDetectorHit *lhs, TDetectorHit *rhs)
void Clear(Option_t *opt="") override
!
virtual void SetCfd(const Int_t &val)
! this function automatically randomizes the integer provided
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.
virtual bool HasWave() const
!
virtual size_t WaveSize() const
!
Bool_t IsEnergySet() const
void SetAddress(const UInt_t &temp_address)
!
static TVector3 fBeamDirection
void SetCharge(const Int_t &temp_charge)
! this function automatically randomizes the integer provided
Bool_t IsChannelSet() const
static TVector3 * GetBeamDirection()
Long64_t fTimeStamp
Timestamp given to hit in ns.
Long64_t GetCycleTimeStamp() const
Float_t fCfd
CFD time of the Hit.
TDetectorHit(TDetectorHit &&) noexcept=default
Double_t SetTime(const Double_t &time) const
virtual void Add(const TDetectorHit *)
!
virtual void AppendTimeStamp(const Long64_t &val)
!
void ClearChannel()
virtual void SetTimeStamp(const Long64_t &val)
!
virtual void CopyWave(TObject &) const
!
friend std::ostream & operator<<(std::ostream &out, const TDetectorHit &hit)
void Print(Option_t *opt="") const override
!
Bool_t TestBit(T bit) const
EPpgPattern
Definition TPPG.h:36