GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TSuppressed.h
Go to the documentation of this file.
1#ifndef TSUPPRESSED_H
2#define TSUPPRESSED_H
3
4#include "TDetector.h"
5#include "TDetectorHit.h"
6#include "TBgo.h"
7
8/** \addtogroup Detectors
9 * @{
10 */
11
12/////////////////////////////////////////////////////////////////
13///
14/// \class TSuppressed
15///
16/// This is an abstract class that adds basic functionality for
17/// Compton suppressed detectors like GRIFFIN.
18///
19/////////////////////////////////////////////////////////////////
20
21class TSuppressed : public TDetector {
22public:
23 TSuppressed() = default;
24 TSuppressed(const TSuppressed&) = default;
25 TSuppressed(TSuppressed&&) noexcept = default;
26 TSuppressed& operator=(const TSuppressed&) = default;
27 TSuppressed& operator=(TSuppressed&&) noexcept = default;
28 ~TSuppressed() = default;
29
30 virtual bool AddbackCriterion(const TDetectorHit*, const TDetectorHit*) { return false; }
31 virtual bool SuppressionCriterion(const TDetectorHit*, const TDetectorHit*) { return false; }
32
33 void Copy(TObject&) const override; //!<!
34 void Clear(Option_t* opt = "all") override; //!<!
35
36protected:
37 template <class T>
38 void CreateAddback(const std::vector<T*>& hits, std::vector<T*>& addbacks, std::vector<UShort_t>& nofFragments)
39 {
40 /// This funxtion always(!) re-creates the vectors of addback hits and number of fragments per addback hit based on the provided vector of hits
41 addbacks.clear();
42 nofFragments.clear();
43 size_t j = 0;
44 for(auto hit : hits) {
45 // check for each existing addback hit if this hit should be added to it
46 for(j = 0; j < addbacks.size(); ++j) {
47 if(AddbackCriterion(addbacks[j], hit)) {
48 addbacks[j]->Add(hit);
49 // copy constructor does not copy the bit field, so we need to set it
50 addbacks[j]->SetHitBit(TDetectorHit::EBitFlag::kIsEnergySet); // this must be set for summed hits
51 addbacks[j]->SetHitBit(TDetectorHit::EBitFlag::kIsTimeSet); // this must be set for summed hits
52 ++(nofFragments.at(j));
53 break;
54 }
55 }
56 // if we haven't found an addback hit to add this hit to, or if there are no addback hits yet we create a new addback hit
57 if(j == addbacks.size()) {
58 /// Because the functions to return hit vectors etc. are almost always returning vectors of TDetectorHits, T is most likely TDetectorHit.
59 /// This means we can't use T directly to create a new hit, we need to use TClass::New().
60 T* tmpT = static_cast<T*>(hit->IsA()->New());
61 *tmpT = *hit;
62 addbacks.push_back(tmpT);
63 nofFragments.push_back(1);
64 }
65 }
66 }
67
68 template <class T>
69 void CreateSuppressed(const TBgo* bgo, const std::vector<T*>& hits, std::vector<T*>& suppressedHits)
70 {
71 /// This function always(!) re-creates the vector of suppressed hits based on the provided TBgo and vector of hits
72 suppressedHits.clear();
73 for(auto hit : hits) {
74 bool suppress = false;
75 if(bgo != nullptr) {
76 for(auto* b : bgo->GetHitVector()) {
77 if(SuppressionCriterion(hit, b)) {
78 suppress = true;
79 break;
80 }
81 }
82 }
83 /// Because the functions to return hit vectors etc. are almost always returning vectors of TDetectorHits, T is most likely TDetectorHit.
84 /// This means we can't use T directly to create a new hit, we need to use TClass::New().
85 if(!suppress) {
86 T* tmpT = static_cast<T*>(hit->IsA()->New());
87 *tmpT = *hit;
88 suppressedHits.push_back(tmpT);
89 }
90 }
91 }
92
93 template <class T>
94 void CreateSuppressedAddback(const TBgo* bgo, const std::vector<T*>& hits, std::vector<T*>& addbacks, std::vector<UShort_t>& nofFragments)
95 {
96 /// This funxtion always(!) re-creates the vectors of suppressed addback hits and number of fragments per suppressed addback hit based on the provided TBgo and vector of hits
97 addbacks.clear();
98 nofFragments.clear();
99 size_t j = 0;
100 std::vector<bool> suppressed;
101 for(auto hit : hits) {
102 // check if this hit is suppressed
103 bool suppress = false;
104 if(bgo != nullptr) {
105 for(auto* b : bgo->GetHitVector()) {
106 if(SuppressionCriterion(hit, b)) {
107 suppress = true;
108 break;
109 }
110 }
111 }
112 // check for each existing addback hit if this hit should be added to it
113 for(j = 0; j < addbacks.size(); ++j) {
114 if(AddbackCriterion(addbacks[j], hit)) {
115 addbacks[j]->Add(hit);
116 // copy constructor does not copy the bit field, so we need to set it
117 addbacks[j]->SetHitBit(TDetectorHit::EBitFlag::kIsEnergySet); // this must be set for summed hits
118 addbacks[j]->SetHitBit(TDetectorHit::EBitFlag::kIsTimeSet); // this must be set for summed hits
119 ++(nofFragments.at(j));
120 if(suppress) {
121 suppressed[j] = true;
122 }
123 break;
124 }
125 }
126 // if we haven't found an addback hit to add this hit to, or if there are no addback hits yet we create a new addback hit
127 if(j == addbacks.size()) {
128 /// Because the functions to return hit vectors etc. are almost always returning vectors of TDetectorHits, T is most likely TDetectorHit.
129 /// This means we can't use T directly to create a new hit, we need to use TClass::New().
130 T* tmpT = static_cast<T*>(hit->IsA()->New());
131 *tmpT = *hit;
132 addbacks.push_back(tmpT);
133 nofFragments.push_back(1);
134 suppressed.push_back(suppress);
135 }
136 }
137 // loop over all created addback hits and check if they contain a suppressed hit
138 for(j = 0; j < addbacks.size(); ++j) {
139 // if this hit is suppressed we need to suppress the whole addback event
140 if(suppressed[j]) {
141 addbacks.erase(addbacks.begin() + j);
142 nofFragments.erase(nofFragments.begin() + j);
143 suppressed.erase(suppressed.begin() + j);
144 --j;
145 }
146 }
147 }
148
149 /// \cond CLASSIMP
150 ClassDefOverride(TSuppressed, 1) // NOLINT(readability-else-after-return)
151 /// \endcond
152};
153/*! @} */
154#endif
Definition TBgo.h:22
virtual const std::vector< TDetectorHit * > & GetHitVector() const
Definition TDetector.h:75
void Clear(Option_t *opt="all") override
!
TSuppressed()=default
void Copy(TObject &) const override
!
TSuppressed(TSuppressed &&) noexcept=default
void CreateAddback(const std::vector< T * > &hits, std::vector< T * > &addbacks, std::vector< UShort_t > &nofFragments)
Definition TSuppressed.h:38
virtual bool AddbackCriterion(const TDetectorHit *, const TDetectorHit *)
Definition TSuppressed.h:30
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
virtual bool SuppressionCriterion(const TDetectorHit *, const TDetectorHit *)
Definition TSuppressed.h:31
TSuppressed(const TSuppressed &)=default