GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TRcmp.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <vector>
3#include "TRcmp.h"
4
5#include <cstdlib>
6#include <cmath>
7
9{
10 /// this is the default constructor
11 Clear();
12}
13
15{
16 /// this is the destructor for the class that deletes the pointers to avoid memory leaks
17
18 // using range-based for-loop to iterate through the containers
19 for(auto* hit : fFrontPMulVector) { // "hit" is a pointer to the element inside the vector
20 delete hit;
21 }
22 for(auto* hit : fBackNMulVector) {
23 delete hit;
24 }
25 for(auto* hit : fPixelMulVector) {
26 delete hit;
27 }
28}
29
31{
32 rhs.Copy(*this);
33 return *this;
34}
35
36TRcmp::TRcmp(const TRcmp& rhs) : TDetector(rhs)
37{
38 /// this is the copy constructor
39 rhs.Copy(*this);
40}
41
42void TRcmp::Copy(TObject& rhs) const
43{
44 /// Copy function
45 TDetector::Copy(rhs); // first call the copy function from the parent class
46
47 // copy the data members of the TRcmp class now
48
49 // copy the fragment vectors
50 static_cast<TRcmp&>(rhs).fFrontPFragVector = fFrontPFragVector;
51 static_cast<TRcmp&>(rhs).fBackNFragVector = fBackNFragVector;
52
53 static_cast<TRcmp&>(rhs).fZeroMultiplicity = fZeroMultiplicity;
54
55 static_cast<TRcmp&>(rhs).fCoincidenceTime = fCoincidenceTime;
56
57 // delete the entries and then clear the transient vectors since these are not written to file
58 // we first delete the pointers and then clear the vectors, because the vectors are of TRcmpHit class not TRcmp
59 for(auto* hit : static_cast<TRcmp&>(rhs).fFrontPMulVector) {
60 delete hit;
61 }
62 static_cast<TRcmp&>(rhs).fFrontPMulVector.clear();
63 for(auto* hit : static_cast<TRcmp&>(rhs).fBackNMulVector) {
64 delete hit;
65 }
66 static_cast<TRcmp&>(rhs).fBackNMulVector.clear();
67 for(auto* hit : static_cast<TRcmp&>(rhs).fPixelMulVector) {
68 delete hit;
69 }
70 static_cast<TRcmp&>(rhs).fPixelMulVector.clear();
71}
72
73void TRcmp::Clear(Option_t* opt)
74{
75 // Clears the mother and all of the hits
77 // delete all hits from the transient vectors
78 for(auto* hit : fFrontPMulVector) {
79 delete hit;
80 }
81 for(auto* hit : fBackNMulVector) {
82 delete hit;
83 }
84 for(auto* hit : fPixelMulVector) {
85 delete hit;
86 }
87 // clear all vectors
88 fFrontPMulVector.clear();
89 fBackNMulVector.clear();
90 fPixelMulVector.clear();
91 fFrontPFragVector.clear();
92 fBackNFragVector.clear();
93
94 // set data members to default values
96}
97
98void TRcmp::AddFragment(const std::shared_ptr<const TFragment>& frag, TChannel* chan)
99{
100 /// this function takes the fragments and stores them into separate front and back vectors
101
102 if(frag == nullptr || chan == nullptr) {
103 return;
104 }
105
106 const TMnemonic* mnemonic = chan->GetMnemonic(); // declaring a pointer to the TMnemonic class that has the mnemonic for the channel
107
108 if(mnemonic == nullptr) {
109 std::cerr << "Trying to add fragment to TRcmp w/o mnemonic in TChannel! mnemonic == nullptr" << std::endl;
110 return;
111 }
112
113 // group the fragments into two vectors: 1) front fragments and 2) back fragments
114 // P means the junction-side (it is front-side for RCMP)
115 if(mnemonic->CollectedCharge() == TMnemonic::EMnemonic::kP) { fFrontPFragVector.push_back(*frag); } // add the fragment to the front vector is collected charge is on the P-side
116 // N means the ohmic-side (it is back-side for RCMP)
117 else if(mnemonic->CollectedCharge() == TMnemonic::EMnemonic::kN) {
118 fBackNFragVector.push_back(*frag);
119 } // add the fragment to the back vector is collected charge is on the N-side
120}
121
123{
124 /// this function returns the multiplicity of front strip hits
125
126 // clear the vector when calling the function for the first time in the helper (i.e., the bit for the transient vector is not set)
127 if(!fRcmpBits.TestBit(ERcmpBits::kFrontSet)) { // if the flag for transient vector is true then don't clear the vector
128 for(auto* hit : fFrontPMulVector) {
129 delete hit;
130 }
131 fFrontPMulVector.clear();
132 }
133
134 if(fFrontPFragVector.empty()) { // only go ahead if the vector contains at least 1 entry
135 return 0;
136 }
137
138 if(fFrontPMulVector.empty()) { // only add hits to the transient vector if the vector is cleared and empty
139 for(const TFragment& frag : fFrontPFragVector) {
140 fFrontPMulVector.push_back(new TRcmpHit(frag)); // building an RCMP hit out of the fragment and adding it to the front multiplicity vector
141 }
142 }
143
144 SetBitNumber(ERcmpBits::kFrontSet, true); // set the bit for the transient vector to indicate that it has been filled for this build window
145
146 return fFrontPMulVector.size(); // return the size of the vector (i.e., front multiplicity)
147}
148
150{
151 /// this function returns the multiplicity of back strip hits
152
153 // clear the vector when calling the function for the first time in the helper (i.e., the bit for the transient vector is not set)
154 if(!fRcmpBits.TestBit(ERcmpBits::kBackSet)) { // if the flag for transient vector is true then don't clear the vector
155 for(auto* hit : fBackNMulVector) {
156 delete hit;
157 }
158 fBackNMulVector.clear();
159 }
160
161 if(fBackNFragVector.empty()) { // only go ahead if the vector contains at least 1 entry
162 return 0;
163 }
164
165 if(fBackNMulVector.empty()) { // only add hits to the transient vector if the vector is cleared and empty
166 for(auto& frag : fBackNFragVector) {
167 fBackNMulVector.push_back(new TRcmpHit(frag)); // building an RCMP hit out of the fragment and adding it to the front multiplicity vector
168 }
169 }
170
171 SetBitNumber(ERcmpBits::kBackSet, true); // set the bit for the transient vector to indicate that it has been filled for this build window
172
173 return fBackNMulVector.size(); // return the size of the vector (i.e., back multiplicity)
174}
175
177{
178 /// this function returns the multiplicity of hits that were combined for front and back strips (i.e., pixels)
179
180 // clear the vector when calling the function for the first time in the helper (i.e., the bit for the transient vector is not set)
181 if(!fRcmpBits.TestBit(ERcmpBits::kPixelSet)) { // if the flag for transient vector is true then don't clear the vector
182 for(auto* hit : fPixelMulVector) {
183 delete hit;
184 }
185 fPixelMulVector.clear();
186 }
187
188 if(fFrontPFragVector.empty() || fBackNFragVector.empty()) { // only go ahead if both vectors contain at least 1 entry
189 return 0;
190 }
191
192 if(fPixelMulVector.empty()) { // only add hits to the transient vector if the vector is cleared and empty
193 for(UInt_t i = 0; i < GetFrontFragmentMultiplicity(); i++) { // loop over the front strips
194 for(UInt_t j = 0; j < GetBackFragmentMultiplicity(); j++) { // loop over the back strips
195 // if(check threshold condition for both front and back) { // software threshold can be enabled here
196 if((fFrontPFragVector.at(i).GetDetector() == fBackNFragVector.at(j).GetDetector())) { // check if the front and back strips are from the same detector
197 fPixelMulVector.push_back(new TRcmpHit(fFrontPFragVector.at(i), fBackNFragVector.at(j))); // building an RCMP hit out of the two fragment and adding it to the pixel multiplicity vector
198 } else {
199 fZeroMultiplicity++; // increment this counter if the condition above was not met
200 }
201 // }
202 }
203 }
204 }
205
206 SetBitNumber(ERcmpBits::kPixelSet, true); // set the bit for the transient vector to indicate that it has been filled for this build window
207
208 return fPixelMulVector.size(); // return the size of the vector (i.e., pixel multiplicity)
209}
210
211void TRcmp::Print(Option_t*) const
212{
213 Print(std::cout);
214}
215
216void TRcmp::Print(std::ostream& out) const
217{
218 std::ostringstream str;
219 str << "Rcmp contains: " << std::endl;
220 str << std::setw(6) << GetFrontFragmentMultiplicity() << " front hits" << std::endl;
221 str << std::setw(6) << GetBackFragmentMultiplicity() << " back hits" << std::endl;
222
223 out << str.str();
224}
225
226void TRcmp::SetBitNumber(ERcmpBits bit, Bool_t set)
227{
228 /// Used to set the flags that are stored in TRcmp
229 fRcmpBits.SetBit(bit, set);
230}
const TMnemonic * GetMnemonic() const
void Copy(TObject &) const override
!
Definition TDetector.cxx:24
void Clear(Option_t *="") override
!
Definition TDetector.cxx:67
virtual EMnemonic CollectedCharge() const
Definition TMnemonic.h:65
Definition TRcmp.h:35
Int_t fCoincidenceTime
GetTime for TDetectorHit is in nanoseconds, so this is in nanoseconds, too!
Definition TRcmp.h:111
~TRcmp() override
destructor
Definition TRcmp.cxx:14
void SetBitNumber(ERcmpBits bit, Bool_t set=true)
second argument shows that set is true by default
Definition TRcmp.cxx:226
size_t GetFrontFragmentMultiplicity() const
returns the size of the vector that contains all the front fragments (within a build window)
Definition TRcmp.h:79
Short_t GetFrontMultiplicity()
returns the size of the vector that contains all the front hits (within a build window)
Definition TRcmp.cxx:122
TRcmp & operator=(const TRcmp &)
Definition TRcmp.cxx:30
void AddFragment(const std::shared_ptr< const TFragment > &, TChannel *) override
! //adds front and back fragments to their respective fragment vectors
Definition TRcmp.cxx:98
std::vector< TFragment > fBackNFragVector
stores all back strip fragments
Definition TRcmp.h:96
void Clear(Option_t *opt="all") override
!
Definition TRcmp.cxx:73
std::vector< TRcmpHit * > fBackNMulVector
! transient vector that stores hits for the back strips (i.e., back multiplicity)
Definition TRcmp.h:100
Short_t GetPixelMultiplicity()
returns the size of the vector that contains all the pixel hits (within a build window)
Definition TRcmp.cxx:176
ERcmpBits
Definition TRcmp.h:40
std::vector< TRcmpHit * > fPixelMulVector
! transient vector that stores hits for front+back (i.e., pixel multiplicity)
Definition TRcmp.h:101
void Copy(TObject &) const override
!
Definition TRcmp.cxx:42
std::vector< TRcmpHit * > fFrontPMulVector
! transient vector that stores hits for the front strips (i.e., front multiplicity)
Definition TRcmp.h:99
Short_t GetBackMultiplicity()
returns the size of the vector that contains all the back hits (within a build window)
Definition TRcmp.cxx:149
TRcmp()
default constructor
Definition TRcmp.cxx:8
Int_t fZeroMultiplicity
keep track of zero multiplicty with this counter (it is incremented every time the Pixel Multiplicity...
Definition TRcmp.h:108
TTransientBits< UChar_t > fRcmpBits
flags for transient members
Definition TRcmp.h:103
size_t GetBackFragmentMultiplicity() const
returns the size of the vector that contains all the back fragments (within a build window)
Definition TRcmp.h:80
std::vector< TFragment > fFrontPFragVector
stores all front strip fragments
Definition TRcmp.h:95
void Print(Option_t *opt="") const override
!
Definition TRcmp.cxx:211
void SetBit(T bit, Bool_t flag)
Bool_t TestBit(T bit) const