GRSISort "v4.1.1.0"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TTigressHit.cxx
Go to the documentation of this file.
1#include "TTigressHit.h"
2
3#include <cmath>
4#include <iostream>
5
6#include "TTigress.h"
7#include "TPulseAnalyzer.h"
8
10{
11 /// Default Ctor. Ignores TObject Streamer in ROOT < 6.
12 Clear();
13}
14
16{
17 /// Copy Ctor. Ignores TObject Streamer in ROOT < 6.
18 Clear();
19 rhs.Copy(*this);
20}
21
23{
24 frag.Copy(*this);
26}
27
29{
30 frag.Copy(*this);
32}
33
34void TTigressHit::Copy(TObject& rhs) const
35{
37 static_cast<TTigressHit&>(rhs).fFilter = fFilter;
38 // We should copy over a 0 and let the hit recalculate, this is safest
39 static_cast<TTigressHit&>(rhs).fTigressHitBits = 0;
40 static_cast<TTigressHit&>(rhs).fTimeFit = fTimeFit;
41 static_cast<TTigressHit&>(rhs).fSegments = fSegments;
42 static_cast<TTigressHit&>(rhs).fCoreSet = fCoreSet;
43 static_cast<TTigressHit&>(rhs).fBgoFired = fBgoFired;
44}
45
46void TTigressHit::Copy(TObject& obj, bool waveform) const
47{
48 Copy(obj);
49 if(waveform) {
50 CopyWave(obj);
51 }
52}
53
55{
56 // check if the desired filter is in wanted filter;
57 // return the answer;
58 return true;
59}
60
61void TTigressHit::Clear(Option_t* opt)
62{
63 // Clears the information stored in the TTigressHit.
64 TDetectorHit::Clear(opt); // clears the base (address, position and waveform)
65 fFilter = 0;
67
68 fTimeFit = 0.0;
69 fSig2Noise = 0.0;
70
71 fCoreSet = false;
72 fBgoFired = false;
73 fSegments.clear();
74}
75
76void TTigressHit::Print(Option_t*) const
77{
78 // Prints the Detector Number, Crystal Number, Energy, Time and Angle.
79 Print(std::cout);
80}
81
82void TTigressHit::Print(std::ostream& out) const
83{
84 std::ostringstream str;
85 str << "==== TigressHit @ " << this << " ====" << std::endl
86 << "\t" << GetName() << std::endl
87 << "\tCharge: " << GetCharge() << std::endl
88 << "\tEnergy: " << GetEnergy() << std::endl
89 << "\tTime: " << GetTime() << std::endl
90 << "\tCore set: " << (CoreSet() ? "true" : "false") << std::endl
91 << "\tBGO Fired: " << (BGOFired() ? "true" : "false") << std::endl
92 << "\tTime: " << GetTimeStamp() << std::endl
93 << "\thit contains " << GetNSegments() << " segments:" << std::endl;
94 str << "Name Charge" << std::endl;
95 for(int x = 0; x < GetNSegments(); x++) {
96 str << "\t\t" << GetSegmentHit(x).GetName() << " | " << GetSegmentHit(x).GetCharge() << std::endl;
97 }
98 auto p = GetPosition();
99 str << p.GetName() << " " << p.GetTitle() << " (x,y,z)=(" << p.X() << "," << p.Y() << "," << p.Z() << ") (rho,theta,phi)=(" << p.Mag() << "," << p.Theta() << "," << p.Phi() << ")" << std::endl;
100 str << "============================" << std::endl;
101
102 out << str.str();
103}
104
105TVector3 TTigressHit::GetPosition(double dist) const
106{
108}
109
110TVector3 TTigressHit::GetLastPosition(double dist) const
111{
112 const TDetectorHit* seg = nullptr;
113 if(GetNSegments() > 0) {
114 seg = &fSegments.back(); // last segment in the segment vector.
115 } else {
116 seg = this; // if no segments, use the core.
117 }
118
119 return TTigress::GetPosition(seg->GetDetector(), seg->GetCrystal(), seg->GetSegment(), dist);
120}
121
123{
125}
126
127bool TTigressHit::Compare(const TTigressHit* lhs, const TTigressHit* rhs)
128{
129 if(lhs->GetDetector() == rhs->GetDetector()) {
130 return lhs->GetCrystal() < rhs->GetCrystal();
131 }
132 return lhs->GetDetector() < rhs->GetDetector();
133}
134
136{
137 if(hit == this) { return; }
138
139 const auto* tigressHit = dynamic_cast<const TTigressHit*>(hit);
140 if(tigressHit == nullptr) {
141 throw std::runtime_error("trying to add non-tigress hit to tigress hit!");
142 }
143 // add another tigress hit to this one (for addback),
144 // using the time and position information of the one with the higher energy
145 if(!CompareEnergy(this, tigressHit)) {
146 SetCfd(tigressHit->GetCfd());
147 SetTime(tigressHit->GetTime());
148 SetAddress(tigressHit->GetAddress());
149 fSegments = tigressHit->fSegments;
150 } else {
151 SetTime(GetTime());
152 }
153 SetEnergy(GetEnergy() + tigressHit->GetEnergy());
154 // this has to be done at the very end, otherwise GetEnergy() might not work
155 SetCharge(0);
156 // Add all of the pileups.This should be changed when the max number of pileups changes
157 if((NPileUps() + tigressHit->NPileUps()) < 4) {
158 SetNPileUps(NPileUps() + tigressHit->NPileUps());
159 } else {
160 SetNPileUps(3);
161 }
162 if((PUHit() + tigressHit->PUHit()) < 4) {
163 SetPUHit(PUHit() + tigressHit->PUHit());
164 } else {
165 SetPUHit(3);
166 }
167 // KValue is somewhat meaningless in addback, so I am using it as an indicator that a piledup tigressHit was added-back RD
168 if(GetKValue() > tigressHit->GetKValue()) {
169 SetKValue(tigressHit->GetKValue());
170 }
171}
172
174{
175 fTigressHitBits.SetBit(flag, set);
176}
177
178UShort_t TTigressHit::NPileUps() const
179{
180 // The pluralized test bits returns the actual value of the fBits masked. Not just a bool.
182}
183
184UShort_t TTigressHit::PUHit() const
185{
186 // The pluralized test bits returns the actual value of the fBits masked. Not just a bool.
187 return static_cast<UShort_t>(fTigressHitBits.TestBits(ETigressHitBits::kPUHit1) +
188 (fTigressHitBits.TestBits(ETigressHitBits::kPUHit2) >> static_cast<std::underlying_type<ETigressHitBits>::type>(ETigressHitBits::kPUHitOffset)));
189}
190
191void TTigressHit::SetNPileUps(UChar_t npileups)
192{
193 SetTigressFlag(ETigressHitBits::kTotalPU1, (npileups & static_cast<std::underlying_type<ETigressHitBits>::type>(ETigressHitBits::kTotalPU1)) != 0);
194 SetTigressFlag(ETigressHitBits::kTotalPU2, (npileups & static_cast<std::underlying_type<ETigressHitBits>::type>(ETigressHitBits::kTotalPU2)) != 0);
195}
196
197void TTigressHit::SetPUHit(UChar_t puhit)
198{
199 if(puhit > 2) {
200 puhit = 3;
201 }
202 // The pluralized test bits returns the actual value of the fBits masked. Not just a bool.
203
204 SetTigressFlag(ETigressHitBits::kPUHit1, ((puhit << static_cast<std::underlying_type<ETigressHitBits>::type>(ETigressHitBits::kPUHitOffset)) & static_cast<std::underlying_type<ETigressHitBits>::type>(ETigressHitBits::kPUHit1)) != 0);
205 SetTigressFlag(ETigressHitBits::kPUHit2, ((puhit << static_cast<std::underlying_type<ETigressHitBits>::type>(ETigressHitBits::kPUHitOffset)) & static_cast<std::underlying_type<ETigressHitBits>::type>(ETigressHitBits::kPUHit2)) != 0);
206}
207
208Double_t TTigressHit::GetNoCTEnergy(Option_t*) const
209{
210 TChannel* chan = GetChannel();
211 if(chan == nullptr) {
212 Error("GetEnergy", "No TChannel exists for address 0x%08x", GetAddress());
213 return 0.;
214 }
215 return chan->CalibrateENG(Charge(), GetKValue());
216}
217
219{
220 TPulseAnalyzer pulse(frag);
221 if(pulse.IsSet()) {
222 fTimeFit = static_cast<Float_t>(pulse.fit_newT0());
223 fSig2Noise = static_cast<Float_t>(pulse.get_sig2noise());
224 }
225}
226
228{
229 TPulseAnalyzer pulse(*GetWaveform(), 0, GetName());
230 if(pulse.IsSet()) {
231 fTimeFit = static_cast<Float_t>(pulse.fit_newT0());
232 fSig2Noise = static_cast<Float_t>(pulse.get_sig2noise());
233 }
234}
double CalibrateENG(double) const
Definition TChannel.cxx:678
void SetKValue(const Short_t &temp_kval)
!
virtual Float_t GetCharge() const
!
Double_t SetEnergy(const double &energy) const
virtual UInt_t GetAddress() const
!
virtual void SetCfd(const Float_t &val)
!
virtual Long64_t GetTimeStamp(Option_t *="") const
virtual double GetEnergy(Option_t *opt="") const
virtual Short_t GetKValue() const
!
static bool CompareEnergy(const TDetectorHit *lhs, const TDetectorHit *rhs)
const char * GetName() const override
!
const std::vector< Short_t > * GetWaveform() const
!
virtual Int_t GetCrystal() const
!
virtual Float_t Charge() const
!
TChannel * GetChannel() const
!
void SetCharge(const Float_t &temp_charge)
!
void Clear(Option_t *opt="") override
!
virtual Int_t GetDetector() 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 SetAddress(const UInt_t &temp_address)
!
Double_t SetTime(const Double_t &time) const
virtual void CopyWave(TObject &) const
!
Short_t GetNumberOfPileups() const
Definition TFragment.h:77
bool IsSet() const
int GetNSegments() const
!
Definition TTigressHit.h:85
Double_t GetNoCTEnergy(Option_t *opt="") const
TTransientBits< UChar_t > fTigressHitBits
Transient Member Flags.
Definition TTigressHit.h:43
void Print(Option_t *opt="") const override
!
int GetFirstSegment() const
Definition TTigressHit.h:89
void Clear(Option_t *opt="") override
!
void SetPUHit(UChar_t puhit)
UShort_t NPileUps() const
Double_t GetDefaultDistance() const
bool BGOFired() const
Definition TTigressHit.h:79
TVector3 GetPosition() const override
!
void CopyFragment(const TFragment &)
Float_t fSig2Noise
Definition TTigressHit.h:51
void Add(const TDetectorHit *) override
!
Int_t fFilter
The Filter Word.
Definition TTigressHit.h:42
static bool Compare(const TTigressHit *, const TTigressHit *)
!
std::vector< TDetectorHit > fSegments
Definition TTigressHit.h:46
void SetWavefit()
const TDetectorHit & GetSegmentHit(int i) const
!
Definition TTigressHit.h:87
void SetNPileUps(UChar_t npileups)
bool InFilter(Int_t)
!
Float_t fTimeFit
Definition TTigressHit.h:50
UShort_t PUHit() const
TVector3 GetLastPosition(double dist) const
!
bool CoreSet() const
Definition TTigressHit.h:77
void Copy(TObject &) const override
!
void SetTigressFlag(ETigressHitBits, Bool_t set)
static TVector3 GetPosition(int DetNbr, int CryNbr, int SegNbr, double dist=110.0, bool smear=false)
!
Definition TTigress.cxx:562
void SetBit(T bit, Bool_t flag)
T TestBits(T bit) const