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