GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TGriffin.cxx
Go to the documentation of this file.
1#include "TGriffin.h"
2
3#include <sstream>
4#include <iostream>
5#include <iomanip>
6
7#include "TRandom.h"
8#include "TMath.h"
9#include "TInterpreter.h"
10#include "TMnemonic.h"
11
12#include "TGRSIOptions.h"
13
14////////////////////////////////////////////////////////////
15//
16// TGriffin
17//
18// The TGriffin class defines the observables and algorithms used
19// when analyzing GRIFFIN data. It includes detector positions,
20// add-back methods, etc.
21//
22////////////////////////////////////////////////////////////
23
25{
26 return ((one->GetDetector() == two->GetDetector()) &&
27 (std::fabs(one->GetTime() - two->GetTime()) < TGRSIOptions::AnalysisOptions()->AddbackWindow()));
28}
29
31
33{
34 //return ((hit.GetDetector() == bgoHit.GetDetector() && hit.GetCrystal() == bgoHit.GetCrystal()) &&
35 return ((hit->GetDetector() == bgoHit->GetDetector()) &&
36 (std::fabs(hit->GetTime() - bgoHit->GetTime()) < TGRSIOptions::AnalysisOptions()->SuppressionWindow()) &&
38}
39
41
42bool TGriffin::fSetCoreWave = false;
44
45// This seems unnecessary, and why 17?;// they are static members, and need
46// to be defined outside the header
47// 17 is to have the detectors go from 1-16
48// plus we can use position zero
49// when the detector winds up back in
50// one of the stands like Alex used in the
51// gps run. pcb.
52// Initiallizes the HPGe Clover positions as per the wiki
53// <https://www.triumf.info/wiki/tigwiki/index.php/HPGe_Coordinate_Table>
54// theta phi
55// theta phi
56// theta
57std::array<TVector3, 17> TGriffin::fCloverPosition = {
58 TVector3(TMath::Sin(TMath::DegToRad() * (0.0)) * TMath::Cos(TMath::DegToRad() * (0.0)),
59 TMath::Sin(TMath::DegToRad() * (0.0)) * TMath::Sin(TMath::DegToRad() * (0.0)),
60 TMath::Cos(TMath::DegToRad() * (0.0))),
61 // Downstream lampshade
62 TVector3(TMath::Sin(TMath::DegToRad() * (45.0)) * TMath::Cos(TMath::DegToRad() * (67.5)),
63 TMath::Sin(TMath::DegToRad() * (45.0)) * TMath::Sin(TMath::DegToRad() * (67.5)),
64 TMath::Cos(TMath::DegToRad() * (45.0))),
65 TVector3(TMath::Sin(TMath::DegToRad() * (45.0)) * TMath::Cos(TMath::DegToRad() * (157.5)),
66 TMath::Sin(TMath::DegToRad() * (45.0)) * TMath::Sin(TMath::DegToRad() * (157.5)),
67 TMath::Cos(TMath::DegToRad() * (45.0))),
68 TVector3(TMath::Sin(TMath::DegToRad() * (45.0)) * TMath::Cos(TMath::DegToRad() * (247.5)),
69 TMath::Sin(TMath::DegToRad() * (45.0)) * TMath::Sin(TMath::DegToRad() * (247.5)),
70 TMath::Cos(TMath::DegToRad() * (45.0))),
71 TVector3(TMath::Sin(TMath::DegToRad() * (45.0)) * TMath::Cos(TMath::DegToRad() * (337.5)),
72 TMath::Sin(TMath::DegToRad() * (45.0)) * TMath::Sin(TMath::DegToRad() * (337.5)),
73 TMath::Cos(TMath::DegToRad() * (45.0))),
74 // Corona
75 TVector3(TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Cos(TMath::DegToRad() * (22.5)),
76 TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Sin(TMath::DegToRad() * (22.5)),
77 TMath::Cos(TMath::DegToRad() * (90.0))),
78 TVector3(TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Cos(TMath::DegToRad() * (67.5)),
79 TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Sin(TMath::DegToRad() * (67.5)),
80 TMath::Cos(TMath::DegToRad() * (90.0))),
81 TVector3(TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Cos(TMath::DegToRad() * (112.5)),
82 TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Sin(TMath::DegToRad() * (112.5)),
83 TMath::Cos(TMath::DegToRad() * (90.0))),
84 TVector3(TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Cos(TMath::DegToRad() * (157.5)),
85 TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Sin(TMath::DegToRad() * (157.5)),
86 TMath::Cos(TMath::DegToRad() * (90.0))),
87 TVector3(TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Cos(TMath::DegToRad() * (202.5)),
88 TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Sin(TMath::DegToRad() * (202.5)),
89 TMath::Cos(TMath::DegToRad() * (90.0))),
90 TVector3(TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Cos(TMath::DegToRad() * (247.5)),
91 TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Sin(TMath::DegToRad() * (247.5)),
92 TMath::Cos(TMath::DegToRad() * (90.0))),
93 TVector3(TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Cos(TMath::DegToRad() * (292.5)),
94 TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Sin(TMath::DegToRad() * (292.5)),
95 TMath::Cos(TMath::DegToRad() * (90.0))),
96 TVector3(TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Cos(TMath::DegToRad() * (337.5)),
97 TMath::Sin(TMath::DegToRad() * (90.0)) * TMath::Sin(TMath::DegToRad() * (337.5)),
98 TMath::Cos(TMath::DegToRad() * (90.0))),
99 // Upstream lampshade
100 TVector3(TMath::Sin(TMath::DegToRad() * (135.0)) * TMath::Cos(TMath::DegToRad() * (67.5)),
101 TMath::Sin(TMath::DegToRad() * (135.0)) * TMath::Sin(TMath::DegToRad() * (67.5)),
102 TMath::Cos(TMath::DegToRad() * (135.0))),
103 TVector3(TMath::Sin(TMath::DegToRad() * (135.0)) * TMath::Cos(TMath::DegToRad() * (157.5)),
104 TMath::Sin(TMath::DegToRad() * (135.0)) * TMath::Sin(TMath::DegToRad() * (157.5)),
105 TMath::Cos(TMath::DegToRad() * (135.0))),
106 TVector3(TMath::Sin(TMath::DegToRad() * (135.0)) * TMath::Cos(TMath::DegToRad() * (247.5)),
107 TMath::Sin(TMath::DegToRad() * (135.0)) * TMath::Sin(TMath::DegToRad() * (247.5)),
108 TMath::Cos(TMath::DegToRad() * (135.0))),
109 TVector3(TMath::Sin(TMath::DegToRad() * (135.0)) * TMath::Cos(TMath::DegToRad() * (337.5)),
110 TMath::Sin(TMath::DegToRad() * (135.0)) * TMath::Sin(TMath::DegToRad() * (337.5)),
111 TMath::Cos(TMath::DegToRad() * (135.0)))};
112
114{
115 /// Default ctor. Ignores TObjectStreamer in ROOT < 6
116 Clear();
117}
118
120{
121 /// Copy ctor. Ignores TObjectStreamer in ROOT < 6
122 rhs.Copy(*this);
123}
124
125void TGriffin::Copy(TObject& rhs) const
126{
127 // Copy function.
129
130 // no need to copy low gain, this is already taken care of by TDetector::Copy (called by TSuppressed::Copy)
131 static_cast<TGriffin&>(rhs).fGriffinHighGainHits.resize(fGriffinHighGainHits.size(), nullptr);
132 for(size_t i = 0; i < fGriffinHighGainHits.size(); ++i) {
133 static_cast<TGriffin&>(rhs).fGriffinHighGainHits[i] = new TGriffinHit(*static_cast<TGriffinHit*>(fGriffinHighGainHits[i]));
134 }
135 // not copying addback or suppressed vectors
136 for(auto& hit : static_cast<TGriffin&>(rhs).fAddbackLowGainHits) {
137 delete hit;
138 }
139 for(auto& hit : static_cast<TGriffin&>(rhs).fAddbackHighGainHits) {
140 delete hit;
141 }
142 for(auto& hit : static_cast<TGriffin&>(rhs).fSuppressedLowGainHits) {
143 delete hit;
144 }
145 for(auto& hit : static_cast<TGriffin&>(rhs).fSuppressedHighGainHits) {
146 delete hit;
147 }
148 for(auto& hit : static_cast<TGriffin&>(rhs).fSuppressedAddbackLowGainHits) {
149 delete hit;
150 }
151 for(auto& hit : static_cast<TGriffin&>(rhs).fSuppressedAddbackHighGainHits) {
152 delete hit;
153 }
154 static_cast<TGriffin&>(rhs).fGriffinBits = 0;
155 static_cast<TGriffin&>(rhs).fAddbackLowGainHits.clear();
156 static_cast<TGriffin&>(rhs).fAddbackHighGainHits.clear();
157 static_cast<TGriffin&>(rhs).fAddbackLowGainFrags.clear();
158 static_cast<TGriffin&>(rhs).fAddbackHighGainFrags.clear();
159 static_cast<TGriffin&>(rhs).fSuppressedLowGainHits.clear();
160 static_cast<TGriffin&>(rhs).fSuppressedHighGainHits.clear();
161 static_cast<TGriffin&>(rhs).fSuppressedAddbackLowGainHits.clear();
162 static_cast<TGriffin&>(rhs).fSuppressedAddbackHighGainHits.clear();
163 static_cast<TGriffin&>(rhs).fSuppressedAddbackLowGainFrags.clear();
164 static_cast<TGriffin&>(rhs).fSuppressedAddbackHighGainFrags.clear();
165
166 static_cast<TGriffin&>(rhs).fCycleStart = fCycleStart;
167}
168
170{
171 // Default Destructor
172 // no need to delete low gain hits, this is taken care of by the destructor of TDetector
173 for(auto& hit : fGriffinHighGainHits) {
174 delete hit;
175 }
176 for(auto& hit : fAddbackLowGainHits) {
177 delete hit;
178 }
179 for(auto& hit : fAddbackHighGainHits) {
180 delete hit;
181 }
182 for(auto& hit : fSuppressedLowGainHits) {
183 delete hit;
184 }
185 for(auto& hit : fSuppressedHighGainHits) {
186 delete hit;
187 }
188 for(auto& hit : fSuppressedAddbackLowGainHits) {
189 delete hit;
190 }
191 for(auto& hit : fSuppressedAddbackHighGainHits) {
192 delete hit;
193 }
194}
195
196void TGriffin::Clear(Option_t* opt)
197{
198 // Clears the mother, and all of the hits
199 ClearStatus();
201 // low gain hits cleared by TDetector::Clear
202 for(auto& hit : fGriffinHighGainHits) {
203 delete hit;
204 }
205 for(auto& hit : fAddbackLowGainHits) {
206 delete hit;
207 }
208 for(auto& hit : fAddbackHighGainHits) {
209 delete hit;
210 }
211 for(auto& hit : fSuppressedLowGainHits) {
212 delete hit;
213 }
214 for(auto& hit : fSuppressedHighGainHits) {
215 delete hit;
216 }
217 for(auto& hit : fSuppressedAddbackLowGainHits) {
218 delete hit;
219 }
220 for(auto& hit : fSuppressedAddbackHighGainHits) {
221 delete hit;
222 }
223 fGriffinHighGainHits.clear();
224 fAddbackLowGainHits.clear();
225 fAddbackHighGainHits.clear();
226 fAddbackLowGainFrags.clear();
227 fAddbackHighGainFrags.clear();
234
235 fCycleStart = 0;
236}
237
238void TGriffin::Print(Option_t*) const
239{
240 Print(std::cout);
241}
242
243void TGriffin::Print(std::ostream& out) const
244{
245 std::ostringstream str;
246 str << "Griffin Contains: " << std::endl;
247 str << std::setw(6) << GetLowGainMultiplicity() << " Low gain hits" << std::endl;
248 //if(TString(opt).Contains("all", TString::ECaseCompare::kIgnoreCase)) {
249 for(const auto& hit : Hits()) {
250 static_cast<TGriffinHit*>(hit)->Print(str);
251 }
252 //}
253 str << std::setw(6) << GetHighGainMultiplicity() << " High gain hits" << std::endl;
254 //if(TString(opt).Contains("all", TString::ECaseCompare::kIgnoreCase)) {
255 for(const auto& hit : fGriffinHighGainHits) {
256 static_cast<TGriffinHit*>(hit)->Print(str);
257 }
258 //}
259
261 str << std::setw(6) << fAddbackLowGainHits.size() << " Low gain addback hits" << std::endl;
262 } else {
263 str << std::setw(6) << " "
264 << " Low Gain Addback not set" << std::endl;
265 }
266
268 str << std::setw(6) << fAddbackHighGainHits.size() << " High gain addback hits" << std::endl;
269 } else {
270 str << std::setw(6) << " "
271 << " High Gain Addback not set" << std::endl;
272 }
273
274 str << std::setw(6) << " "
275 << " Cross-talk Set? Low gain: " << IsCrossTalkSet(EGainBits::kLowGain)
276 << " High gain: " << IsCrossTalkSet(EGainBits::kHighGain) << std::endl;
277 str << std::setw(6) << fCycleStart << " cycle start" << std::endl;
278 out << str.str();
279}
280
282{
283 rhs.Copy(*this);
284 return *this;
285}
286
288{
289 if((gain_type == EGainBits::kLowGain) || (gain_type == EGainBits::kHighGain)) {
290 fDefaultGainType = gain_type;
291 } else {
292 std::cerr << static_cast<std::underlying_type<EGainBits>::type>(gain_type) << " is not a known gain type. Please use kLowGain or kHighGain" << std::endl;
293 }
294}
295
296Short_t TGriffin::GetMultiplicity(const EGainBits& gain_type) const
297{
298 switch(gain_type) {
300 case EGainBits::kHighGain: return fGriffinHighGainHits.size();
301 };
302 return 0;
303}
304
305const std::vector<TDetectorHit*>& TGriffin::GetHitVector(const EGainBits& gain_type) const
306{
307 switch(gain_type) {
308 case EGainBits::kLowGain: return Hits();
310 };
311 return Hits();
312}
313
314std::vector<TDetectorHit*>& TGriffin::GetHitVector(const EGainBits& gain_type)
315{
316 switch(gain_type) {
317 case EGainBits::kLowGain: return Hits();
319 };
320 return Hits();
321}
322
323std::vector<TDetectorHit*>& TGriffin::GetAddbackVector(const EGainBits& gain_type)
324{
325 switch(gain_type) {
328 };
329 return fAddbackLowGainHits;
330}
331
332std::vector<UShort_t>& TGriffin::GetAddbackFragVector(const EGainBits& gain_type)
333{
334 switch(gain_type) {
337 };
339}
340
341bool TGriffin::IsAddbackSet(const EGainBits& gain_type) const
342{
343 switch(gain_type) {
346 };
347 return false;
348}
349
350bool TGriffin::IsCrossTalkSet(const EGainBits& gain_type) const
351{
352 switch(gain_type) {
355 };
356 return false;
357}
358
359void TGriffin::SetAddback(const EGainBits& gain_type, const bool flag) const
360{
361 switch(gain_type) {
364 };
365}
366
367void TGriffin::SetCrossTalk(const EGainBits& gain_type, const bool flag) const
368{
369 switch(gain_type) {
372 };
373}
374
376{
377 return GetGriffinHit(idx);
378}
379
384
389
390TGriffinHit* TGriffin::GetGriffinHit(const int& i, const EGainBits& gain_type)
391{
392 try {
393 if(!IsCrossTalkSet(gain_type)) {
394 FixCrossTalk(gain_type);
395 }
396 return static_cast<TGriffinHit*>(GetHitVector(gain_type).at(i));
397 } catch(const std::out_of_range& oor) {
398 std::cerr << ClassName() << " Hits are out of range: " << oor.what() << std::endl;
399 if(!gInterpreter) {
400 throw grsi::exit_exception(1);
401 }
402 }
403 return nullptr;
404}
405
410
415
417{
418 // Automatically builds the addback hits using the fAddbackCriterion (if the size of the fAddbackHits vector is zero)
419 // and return the number of addback hits.
420 if(!IsCrossTalkSet(gain_type)) {
421 // Calculate Cross Talk on each hit
422 FixCrossTalk(gain_type);
423 }
424 auto& hit_vec = GetHitVector(gain_type);
425 auto& ab_vec = GetAddbackVector(gain_type);
426 auto& frag_vec = GetAddbackFragVector(gain_type);
427 if(hit_vec.empty()) {
428 return 0;
429 }
430 // if the addback has been reset, clear the addback hits
431 if(!IsAddbackSet(gain_type)) {
432 for(auto& hit : ab_vec) {
433 delete hit;
434 }
435 ab_vec.clear();
436 frag_vec.clear();
437 }
438 if(ab_vec.empty()) {
439 CreateAddback(hit_vec, ab_vec, frag_vec);
440 SetAddback(gain_type, true);
441 }
442
443 return ab_vec.size();
444}
445
450
455
456TGriffinHit* TGriffin::GetAddbackHit(const int& i, const EGainBits& gain_type)
457{
458 if(i < GetAddbackMultiplicity(gain_type)) {
459 return static_cast<TGriffinHit*>(GetAddbackVector(gain_type)[i]);
460 }
461 std::cerr << "Addback hits are out of range" << std::endl;
462 throw grsi::exit_exception(1);
463 return nullptr;
464}
465
466void TGriffin::AddFragment(const std::shared_ptr<const TFragment>& frag, TChannel* chan)
467{
468 // Builds the GRIFFIN Hits directly from the TFragment. Basically, loops through the hits for an event and sets
469 // observables.
470 // This is done for both GRIFFIN and it's suppressors.
471 if(frag == nullptr || chan == nullptr) {
472 return;
473 }
474 const TMnemonic* mnemonic = chan->GetMnemonic();
475 if(mnemonic == nullptr) {
476 std::cerr << "Trying to add fragment to TGriffin w/o mnemonic in TChannel!" << std::endl;
477 return;
478 }
479
480 if(mnemonic->SubSystem() != TMnemonic::EMnemonic::kG) {
481 std::cerr << __PRETTY_FUNCTION__ << ": not a GRIFFIN detector: " << static_cast<std::underlying_type<TMnemonic::EMnemonic>::type>(mnemonic->SubSystem()) << std::endl; // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
482 return;
483 }
484
485 // only create the hit if we have a HPGe signal (A or B), not a suppressor (S)
486 switch(mnemonic->OutputSensor()) {
488 auto* hit = new TGriffinHit(*frag);
489 GetHitVector(EGainBits::kLowGain).push_back(hit);
490 } break;
492 auto* hit = new TGriffinHit(*frag);
493 GetHitVector(EGainBits::kHighGain).push_back(hit);
494 } break;
495 default:
496 std::cout << "output sensor " << static_cast<std::underlying_type<TMnemonic::EMnemonic>::type>(mnemonic->OutputSensor()) << ", skipping it" << std::endl;
497 break;
498 };
499}
500
501TVector3 TGriffin::GetPosition(int DetNbr, int CryNbr, double dist)
502{
503 // Gets the position vector for a crystal specified by CryNbr within Clover DetNbr at a distance of dist mm away.
504 // This is calculated to the most likely interaction point within the crystal.
505 if(DetNbr > 16) {
506 return {0, 0, 1};
507 }
508
509 TVector3 temp_pos(fCloverPosition[DetNbr]);
510
511 // Interaction points may eventually be set externally. May make these members of each crystal, or pass from
512 // waveforms.
513 Double_t cp = 26.0; // Crystal Center Point mm.
514 Double_t id = 45.0; // 45.0; //Crystal interaction depth mm.
515 // Set Theta's of the center of each DETECTOR face
516 ////Define one Detector position
517 TVector3 shift;
518 switch(CryNbr) {
519 case 0: shift.SetXYZ(-cp, cp, id); break;
520 case 1: shift.SetXYZ(cp, cp, id); break;
521 case 2: shift.SetXYZ(cp, -cp, id); break;
522 case 3: shift.SetXYZ(-cp, -cp, id); break;
523 default: shift.SetXYZ(0, 0, 1); break;
524 };
525 shift.RotateY(temp_pos.Theta());
526 shift.RotateZ(temp_pos.Phi());
527
528 temp_pos.SetMag(dist);
529
530 return (temp_pos + shift);
531}
532
534{
535 // Gets the position vector for a Clover DetNbr.
536 if(DetNbr > 16) {
537 return {0, 0, 1};
538 }
539
540 return fCloverPosition[DetNbr];
541}
542
544{
545 fGriffinBits = 0;
546}
547
552
557
558void TGriffin::ResetAddback(const EGainBits& gain_type)
559{
560 SetAddback(gain_type, false);
561 SetCrossTalk(gain_type, false);
562 for(auto& hit : GetAddbackVector(gain_type)) {
563 delete hit;
564 }
565 GetAddbackVector(gain_type).clear();
566 GetAddbackFragVector(gain_type).clear();
567}
568
569UShort_t TGriffin::GetNLowGainAddbackFrags(const size_t& idx)
570{
572}
573
574UShort_t TGriffin::GetNHighGainAddbackFrags(const size_t& idx)
575{
577}
578
579UShort_t TGriffin::GetNAddbackFrags(const size_t& idx, const EGainBits& gain_type)
580{
581 // Get the number of addback "fragments" contributing to the total addback hit
582 // with index idx.
583 if(idx < GetAddbackFragVector(gain_type).size()) {
584 return GetAddbackFragVector(gain_type)[idx];
585 }
586 return 0;
587}
588
589void TGriffin::SetBitNumber(enum EGriffinBits bit, Bool_t set) const
590{
591 // Used to set the flags that are stored in TGriffin.
592 fGriffinBits.SetBit(bit, set);
593}
594
595Double_t TGriffin::CTCorrectedEnergy(const TGriffinHit* const hit_to_correct, const TGriffinHit* const other_hit,
596 Bool_t time_constraint)
597{
598 if((hit_to_correct == nullptr) || (other_hit == nullptr)) {
599 std::cerr << "One of the hits is invalid in TGriffin::CTCorrectedEnergy" << std::endl;
600 return 0;
601 }
602
603 if(time_constraint) {
604 // Figure out if this passes the selected window
605 if(TMath::Abs(other_hit->GetTime() - hit_to_correct->GetTime()) >
606 TGRSIOptions::AnalysisOptions()->AddbackWindow()) { // placeholder
607 return hit_to_correct->GetEnergy();
608 }
609 }
610
611 if(hit_to_correct->GetDetector() != other_hit->GetDetector()) {
612 return hit_to_correct->GetEnergy();
613 }
614 static std::array<bool, 256> been_warned = {false};
615 double fixed_energy = hit_to_correct->GetEnergy();
616 try {
617 if(hit_to_correct->GetChannel() != nullptr) {
618 fixed_energy -= hit_to_correct->GetChannel()->GetCTCoeff().at(other_hit->GetCrystal()) * other_hit->GetNoCTEnergy();
619 }
620 } catch(const std::out_of_range& oor) {
621 int id = 16 * hit_to_correct->GetDetector() + 4 * hit_to_correct->GetCrystal() + other_hit->GetCrystal();
622 if(!been_warned[id]) {
623 been_warned[id] = true;
624 std::cerr << DRED << "Missing CT correction for Det: " << hit_to_correct->GetDetector()
625 << " Crystals: " << hit_to_correct->GetCrystal() << " " << other_hit->GetCrystal() << " (id " << id << ")" << RESET_COLOR << std::endl;
626 }
627 return hit_to_correct->GetEnergy();
628 }
629
630 return fixed_energy;
631}
632
637
642
643void TGriffin::FixCrossTalk(const EGainBits& gain_type)
644{
645 if(!TGRSIOptions::AnalysisOptions()->IsCorrectingCrossTalk()) { return; }
646
647 auto& hit_vec = GetHitVector(gain_type);
648 if(hit_vec.size() < 2) {
649 SetCrossTalk(gain_type, true);
650 return;
651 }
652 for(auto& hit : hit_vec) {
653 static_cast<TGriffinHit*>(hit)->ClearEnergy();
654 }
655
656 for(auto& one : hit_vec) {
657 for(auto& two : hit_vec) {
658 one->SetEnergy(CTCorrectedEnergy(static_cast<TGriffinHit*>(one), static_cast<TGriffinHit*>(two)));
659 }
660 }
661 SetCrossTalk(gain_type, true);
662}
663
664const char* TGriffin::GetColorFromNumber(int number)
665{
666 switch(number) {
667 case(0): return "B";
668 case(1): return "G";
669 case(2): return "R";
670 case(3): return "W";
671 };
672 return "X";
673}
674
679
684
689
694
695bool TGriffin::IsSuppressed(const EGainBits& gain_type) const
696{
697 switch(gain_type) {
700 };
701 return false;
702}
703
708
713
718
723
728
733
734bool TGriffin::IsSuppressedAddbackSet(const EGainBits& gain_type) const
735{
736 switch(gain_type) {
739 };
740 return false;
741}
742
747
752
757
762
763std::vector<TDetectorHit*>& TGriffin::GetSuppressedVector(const EGainBits& gain_type)
764{
765 switch(gain_type) {
768 };
770}
771
772std::vector<TDetectorHit*>& TGriffin::GetSuppressedAddbackVector(const EGainBits& gain_type)
773{
774 switch(gain_type) {
777 };
779}
780
781std::vector<UShort_t>& TGriffin::GetSuppressedAddbackFragVector(const EGainBits& gain_type)
782{
783 switch(gain_type) {
786 };
788}
789
790TGriffinHit* TGriffin::GetSuppressedHit(const int& i, const EGainBits& gain_type)
791{
792 try {
793 if(!IsCrossTalkSet(gain_type)) {
794 FixCrossTalk(gain_type);
795 }
796 return static_cast<TGriffinHit*>(GetSuppressedVector(gain_type).at(i));
797 } catch(const std::out_of_range& oor) {
798 std::cerr << ClassName() << " Suppressed hits are out of range: " << oor.what() << std::endl;
799 if(!gInterpreter) {
800 throw grsi::exit_exception(1);
801 }
802 }
803 return nullptr;
804}
805
806Short_t TGriffin::GetSuppressedMultiplicity(const TBgo* bgo, const EGainBits& gain_type)
807{
808 /// Automatically builds the suppressed hits using the fSuppressionCriterion and returns the number of suppressed hits
809 if(!IsCrossTalkSet(gain_type)) {
810 // Calculate Cross Talk on each hit
811 FixCrossTalk(gain_type);
812 }
813 auto& hit_vec = GetHitVector(gain_type);
814 auto& sup_vec = GetSuppressedVector(gain_type);
815 if(hit_vec.empty()) {
816 return 0;
817 }
818 // if the suppressed has been reset, clear the suppressed hits
819 if(!IsSuppressed(gain_type)) {
820 for(auto& hit : sup_vec) {
821 delete hit;
822 }
823 sup_vec.clear();
824 }
825 if(sup_vec.empty()) {
826 CreateSuppressed(bgo, hit_vec, sup_vec);
827 SetSuppressed(gain_type, true);
828 }
829
830 return sup_vec.size();
831}
832
833void TGriffin::SetSuppressed(const EGainBits& gain_type, const bool flag) const
834{
835 switch(gain_type) {
838 };
839}
840
842{
843 SetSuppressed(gain_type, false);
844 //SetCrossTalk(gain_type, false);
845 for(auto& hit : GetSuppressedVector(gain_type)) {
846 delete hit;
847 }
848 GetSuppressedVector(gain_type).clear();
849}
850
852{
853 try {
854 if(!IsCrossTalkSet(gain_type)) {
855 FixCrossTalk(gain_type);
856 }
857 return static_cast<TGriffinHit*>(GetSuppressedAddbackVector(gain_type).at(i));
858 } catch(const std::out_of_range& oor) {
859 std::cerr << ClassName() << " Suppressed addback hits are out of range: " << oor.what() << std::endl;
860 if(!gInterpreter) {
861 throw grsi::exit_exception(1);
862 }
863 }
864 return nullptr;
865}
866
867Short_t TGriffin::GetSuppressedAddbackMultiplicity(const TBgo* bgo, const EGainBits& gain_type)
868{
869 /// Automatically builds the suppressed addback hits using the fAddbackCriterion (if the size of the fAddbackHits vector is zero)
870 /// and return the number of suppressed addback hits.
871 if(!IsCrossTalkSet(gain_type)) {
872 // Calculate Cross Talk on each hit
873 FixCrossTalk(gain_type);
874 }
875 auto& hit_vec = GetHitVector(gain_type);
876 auto& ab_vec = GetSuppressedAddbackVector(gain_type);
877 auto& frag_vec = GetSuppressedAddbackFragVector(gain_type);
878 if(hit_vec.empty()) {
879 return 0;
880 }
881 // if the addback has been reset, clear the addback hits
882 if(!IsSuppressedAddbackSet(gain_type)) {
883 for(auto& hit : ab_vec) {
884 delete hit;
885 }
886 ab_vec.clear();
887 frag_vec.clear();
888 }
889 if(ab_vec.empty()) {
890 CreateSuppressedAddback(bgo, hit_vec, ab_vec, frag_vec);
891 SetSuppressedAddback(gain_type, true);
892 }
893
894 return ab_vec.size();
895}
896
897void TGriffin::SetSuppressedAddback(const EGainBits& gain_type, const bool flag) const
898{
899 switch(gain_type) {
902 };
903}
904
906{
907 SetSuppressedAddback(gain_type, false);
908 //SetCrossTalk(gain_type, false);
909 for(auto& hit : GetSuppressedAddbackVector(gain_type)) {
910 delete hit;
911 }
912 GetSuppressedAddbackVector(gain_type).clear();
913 GetSuppressedAddbackFragVector(gain_type).clear();
914}
915
916UShort_t TGriffin::GetNSuppressedAddbackFrags(const size_t& idx, const EGainBits& gain_type)
917{
918 try {
919 return GetSuppressedAddbackFragVector(gain_type).at(idx);
920 } catch(const std::out_of_range& oor) {
921 std::cerr << ClassName() << " Suppressed addback frags are out of range: " << oor.what() << std::endl;
922 if(!gInterpreter) {
923 throw grsi::exit_exception(1);
924 }
925 }
926 return 0;
927}
#define DRED
Definition Globals.h:18
#define RESET_COLOR
Definition Globals.h:5
bool DefaultGriffinAddback(const TDetectorHit *one, const TDetectorHit *two)
Definition TGriffin.cxx:24
bool DefaultGriffinSuppression(const TDetectorHit *hit, const TDetectorHit *bgoHit)
Definition TGriffin.cxx:32
double SuppressionWindow() const
double AddbackWindow() const
double SuppressionEnergy() const
Definition TBgo.h:22
std::vector< double > GetCTCoeff() const
Definition TChannel.h:197
const TMnemonic * GetMnemonic() const
virtual double GetEnergy(Option_t *opt="") const
virtual Int_t GetCrystal() const
!
TChannel * GetChannel() const
!
virtual Int_t GetDetector() const
!
virtual Double_t GetTime(const ETimeFlag &correct_flag=ETimeFlag::kAll, Option_t *opt="") const
Returns a time value to the nearest nanosecond!
virtual Short_t GetMultiplicity() const
Definition TDetector.h:73
std::vector< TDetectorHit * > & Hits()
Definition TDetector.h:78
static TAnalysisOptions * AnalysisOptions()
Double_t GetNoCTEnergy(Option_t *opt="") const
void ResetHighGainAddback()
!
Definition TGriffin.cxx:553
bool IsSuppressed(const EGainBits &gain_type) const
Definition TGriffin.cxx:695
TGriffinHit * GetSuppressedHighGainHit(const int &i)
!
Definition TGriffin.cxx:680
void ResetSuppressedAddback()
!
Definition TGriffin.h:126
static const char * GetColorFromNumber(int number)
Definition TGriffin.cxx:664
std::vector< TDetectorHit * > fSuppressedLowGainHits
! The set of suppressed crystal hits
Definition TGriffin.h:152
Short_t GetSuppressedAddbackLowGainMultiplicity(const TBgo *bgo)
Definition TGriffin.cxx:714
Short_t GetSuppressedHighGainMultiplicity(const TBgo *bgo)
Definition TGriffin.cxx:690
std::vector< UShort_t > & GetAddbackFragVector(const EGainBits &gain_type)
!
Definition TGriffin.cxx:332
UShort_t GetNHighGainSuppressedAddbackFrags(const size_t &idx)
Definition TGriffin.cxx:758
void Clear(Option_t *opt="all") override
!
Definition TGriffin.cxx:196
TGriffinHit * GetAddbackHit(const int &i)
Definition TGriffin.h:87
Short_t GetAddbackMultiplicity()
Definition TGriffin.h:84
static EGainBits fDefaultGainType
Definition TGriffin.h:160
Short_t GetSuppressedAddbackHighGainMultiplicity(const TBgo *bgo)
Definition TGriffin.cxx:719
void FixHighGainCrossTalk()
Definition TGriffin.cxx:638
static std::function< bool(const TDetectorHit *, const TDetectorHit *)> fAddbackCriterion
Definition TGriffin.h:133
Short_t GetAddbackLowGainMultiplicity()
Definition TGriffin.cxx:406
void ResetHighGainSuppressed()
!
Definition TGriffin.cxx:709
std::vector< TDetectorHit * > & GetSuppressedVector(const EGainBits &gain_type)
!
Definition TGriffin.cxx:763
void Print(Option_t *opt="") const override
!
Definition TGriffin.cxx:238
std::vector< UShort_t > fSuppressedAddbackLowGainFrags
! Number of crystals involved in creating in the suppressed addback hit
Definition TGriffin.h:157
UShort_t GetNLowGainSuppressedAddbackFrags(const size_t &idx)
Definition TGriffin.cxx:753
TDetectorHit * GetHit(const int &idx)
Definition TGriffin.cxx:375
int64_t fCycleStart
! The start of the cycle
Definition TGriffin.h:144
static std::array< TVector3, 17 > fCloverPosition
! Position of each HPGe Clover
Definition TGriffin.h:57
static TVector3 GetPosition(int DetNbr, int CryNbr=5, double dist=110.0)
!
Definition TGriffin.cxx:501
void ResetAddback()
!
Definition TGriffin.h:91
void ResetLowGainAddback()
!
Definition TGriffin.cxx:548
TGriffinHit * GetAddbackHighGainHit(const int &i)
Definition TGriffin.cxx:451
void ResetLowGainSuppressed()
!
Definition TGriffin.cxx:704
TGriffinHit * GetGriffinLowGainHit(const int &i)
!
Definition TGriffin.cxx:380
void ClearStatus() const
!
Definition TGriffin.h:169
std::vector< TDetectorHit * > & GetSuppressedAddbackVector(const EGainBits &gain_type)
!
Definition TGriffin.cxx:772
UShort_t GetNSuppressedAddbackFrags(const size_t &idx)
Definition TGriffin.h:129
void FixLowGainCrossTalk()
Definition TGriffin.cxx:633
UShort_t GetNLowGainAddbackFrags(const size_t &idx)
Definition TGriffin.cxx:569
TGriffinHit * GetAddbackLowGainHit(const int &i)
Definition TGriffin.cxx:446
~TGriffin() override
Definition TGriffin.cxx:169
void SetCrossTalk(const EGainBits &gain_type, bool flag=true) const
Definition TGriffin.cxx:367
void FixCrossTalk(const EGainBits &gain_type)
Definition TGriffin.cxx:643
std::vector< TDetectorHit * > fGriffinHighGainHits
Definition TGriffin.h:137
UShort_t GetNAddbackFrags(const size_t &idx)
Definition TGriffin.h:94
void SetSuppressed(const EGainBits &gain_type, bool flag=true) const
Definition TGriffin.cxx:833
TGriffinHit * GetSuppressedAddbackHit(const int &i)
Definition TGriffin.h:122
void ResetHighGainSuppressedAddback()
!
Definition TGriffin.cxx:748
bool IsSuppressedAddbackSet(const EGainBits &gain_type) const
Definition TGriffin.cxx:734
std::vector< UShort_t > fAddbackHighGainFrags
! Number of crystals involved in creating in the addback hit
Definition TGriffin.h:150
bool IsAddbackSet(const EGainBits &gain_type) const
Definition TGriffin.cxx:341
void ResetFlags() const
Definition TGriffin.cxx:543
TGriffin & operator=(const TGriffin &)
!
Definition TGriffin.cxx:281
std::vector< TDetectorHit * > fAddbackHighGainHits
! Used to create addback hits on the fly
Definition TGriffin.h:148
TTransientBits< UChar_t > fGriffinBits
Definition TGriffin.h:145
Short_t GetAddbackHighGainMultiplicity()
Definition TGriffin.cxx:411
static std::function< bool(const TDetectorHit *, const TDetectorHit *)> fSuppressionCriterion
Definition TGriffin.h:134
Short_t GetSuppressedMultiplicity(const TBgo *bgo)
Definition TGriffin.h:111
Short_t GetSuppressedAddbackMultiplicity(const TBgo *bgo)
Definition TGriffin.h:119
Short_t GetMultiplicity() const override
Definition TGriffin.h:52
void SetSuppressedAddback(const EGainBits &gain_type, bool flag=true) const
Definition TGriffin.cxx:897
TGriffinHit * GetSuppressedAddbackLowGainHit(const int &i)
Definition TGriffin.cxx:724
Short_t GetSuppressedLowGainMultiplicity(const TBgo *bgo)
Definition TGriffin.cxx:685
Short_t GetLowGainMultiplicity() const
Definition TGriffin.h:50
std::vector< UShort_t > fSuppressedAddbackHighGainFrags
! Number of crystals involved in creating in the suppressed addback hit
Definition TGriffin.h:158
std::vector< TDetectorHit * > fSuppressedAddbackLowGainHits
! Used to create suppressed addback hits on the fly
Definition TGriffin.h:155
UShort_t GetNHighGainAddbackFrags(const size_t &idx)
Definition TGriffin.cxx:574
Bool_t IsCrossTalkSet(const EGainBits &gain_type) const
Definition TGriffin.cxx:350
TGriffinHit * GetSuppressedLowGainHit(const int &i)
!
Definition TGriffin.cxx:675
void SetBitNumber(EGriffinBits bit, Bool_t set) const
Definition TGriffin.cxx:589
void ResetSuppressed()
!
Definition TGriffin.h:115
std::vector< TDetectorHit * > & GetAddbackVector(const EGainBits &gain_type)
!
Definition TGriffin.cxx:323
void AddFragment(const std::shared_ptr< const TFragment > &, TChannel *) override
!
Definition TGriffin.cxx:466
std::vector< TDetectorHit * > fSuppressedAddbackHighGainHits
! Used to create suppressed addback hits on the fly
Definition TGriffin.h:156
TGriffinHit * GetSuppressedHit(const int &i)
!
Definition TGriffin.h:108
void SetAddback(const EGainBits &gain_type, bool flag=true) const
Definition TGriffin.cxx:359
const std::vector< TDetectorHit * > & GetHitVector() const override
!
Definition TGriffin.h:182
TGriffinHit * GetGriffinHit(const int &i)
!
Definition TGriffin.h:47
std::vector< UShort_t > fAddbackLowGainFrags
! Number of crystals involved in creating in the addback hit
Definition TGriffin.h:149
TGriffinHit * GetGriffinHighGainHit(const int &i)
!
Definition TGriffin.cxx:385
std::vector< TDetectorHit * > fAddbackLowGainHits
! Used to create addback hits on the fly
Definition TGriffin.h:147
static Double_t CTCorrectedEnergy(const TGriffinHit *hit_to_correct, const TGriffinHit *other_hit, bool time_constraint=true)
Definition TGriffin.cxx:595
std::vector< TDetectorHit * > fSuppressedHighGainHits
! The set of suppressed crystal hits
Definition TGriffin.h:153
static TVector3 GetDetectorPosition(int DetNbr)
!
Definition TGriffin.cxx:533
Bool_t TestBitNumber(EGriffinBits bit) const
Definition TGriffin.h:171
void ResetLowGainSuppressedAddback()
!
Definition TGriffin.cxx:743
static bool fSetCoreWave
! Flag for Waveforms ON/OFF
Definition TGriffin.h:141
void Copy(TObject &) const override
!
Definition TGriffin.cxx:125
Short_t GetHighGainMultiplicity() const
Definition TGriffin.h:51
static void SetDefaultGainType(const EGainBits &gain_type)
Definition TGriffin.cxx:287
TGriffinHit * GetSuppressedAddbackHighGainHit(const int &i)
Definition TGriffin.cxx:729
std::vector< UShort_t > & GetSuppressedAddbackFragVector(const EGainBits &gain_type)
!
Definition TGriffin.cxx:781
virtual EMnemonic OutputSensor() const
Definition TMnemonic.h:65
virtual EMnemonic SubSystem() const
Definition TMnemonic.h:61
void Clear(Option_t *opt="all") override
!
void Copy(TObject &) const override
!
void CreateAddback(const std::vector< T * > &hits, std::vector< T * > &addbacks, std::vector< UShort_t > &nofFragments)
Definition TSuppressed.h:38
void CreateSuppressed(const TBgo *bgo, const std::vector< T * > &hits, std::vector< T * > &suppressedHits)
Definition TSuppressed.h:69
void CreateSuppressedAddback(const TBgo *bgo, const std::vector< T * > &hits, std::vector< T * > &addbacks, std::vector< UShort_t > &nofFragments)
Definition TSuppressed.h:94
void SetBit(T bit, Bool_t flag)