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