GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TCSM.cxx
Go to the documentation of this file.
1#include "TCSM.h"
2#include "TMath.h"
3
4constexpr bool RecoverHits = true;
5constexpr bool SumHits = false;
6
8
10 : fAlmostEqualWindow(0.2)
11{
12}
13
14void TCSM::AddFragment(const std::shared_ptr<const TFragment>& frag, TChannel* chan)
15{
16 /// This function just stores the fragments and mnemonics in vectors, separated by detector number and type
17 /// (horizontal/vertical strip or pad).
18 /// The hits themselves are built in the BuildHits function because the way we build them depends on the number of
19 /// hits.
20
21 // first index: detector number, second index: 0 = deltaE, 1 = E; third index: 0 = horizontal, 1 = vertical; fourth
22 // index: fragments
23 int type = -1;
24 if(chan->GetMnemonic()->ArraySubPositionString().compare(0, 1, "D") == 0) {
25 type = 0;
26 } else if(chan->GetMnemonic()->ArraySubPositionString().compare(0, 1, "E") == 0) {
27 type = 1;
28 }
29 int orientation = -1;
30 if(chan->GetMnemonic()->CollectedChargeString().compare(0, 1, "N") == 0) {
31 // N = Horizontal Strips. aka "front"
32 orientation = 0;
33 } else if(chan->GetMnemonic()->CollectedChargeString().compare(0, 1, "P") == 0) {
34 // P = Vertical Strips. aka "back"
35 orientation = 1;
36 }
37
38 if(type < 0 || orientation < 0) {
39 return;
40 }
41
42 // if this is the first time we got this detector number we make a new vector (of a vector) of fragments
43 if(fFragments.find(chan->GetMnemonic()->ArrayPosition()) == fFragments.end()) {
44 fFragments[chan->GetMnemonic()->ArrayPosition()].resize(
45 2, std::vector<std::vector<std::pair<TFragment, TGRSIMnemonic>>>(2));
46 }
47
48 fFragments[chan->GetMnemonic()->ArrayPosition()][type][orientation].push_back(
49 std::make_pair(*frag, *static_cast<const TGRSIMnemonic*>(chan->GetMnemonic())));
50}
51
53{
54 /// This function takes the fragments that were stored in the successive AddFragment calls and builds hits out of
55 /// them
56 std::vector<std::vector<TDetectorHit*>> hits(2);
57
58 // first index: detector number, second index: 0 = deltaE, 1 = E; third index: 0 = horizontal, 1 = vertical
59 // loop over all found detectors
60 for(auto& fFragment : fFragments) {
61 // loop over all types (only detectors 1/2 should have both D and E, detectors 3/4 should only have D)
62 for(size_t i = 0; i < fFragment.second.size(); ++i) {
63 BuildVH(fFragment.second.at(i), hits[i]);
64 }
65 }
66 BuilddEE(hits, Hits());
67}
68
69TVector3 TCSM::GetPosition(int detector, char pos, int horizontalstrip, int verticalstrip, double X, double Y, double Z)
70{
71 // horizontal strips collect N charge!
72 // vertical strips collect P charge!
73 TVector3 Pos;
74 double SideX = 68;
75 double SideZ = -4.8834;
76 double dEX = 54.9721;
77 double dEZ = 42.948977;
78 double EX = 58.062412;
79 double EZ = 48.09198;
80 double detTheta = 31. * (TMath::Pi() / 180.);
81 double x = 0.;
82 double y = 0.;
83 double z = 0.;
84
85 if(detector == 3 && pos == 'D') {
86 // Right Side
87 verticalstrip = 15 - verticalstrip;
88 x = SideX;
89 z = SideZ + (50. / 32.) * (2 * verticalstrip + 1);
90 } else if(detector == 4 && pos == 'D') {
91 // Left Side
92 x = -SideX;
93 z = SideZ + (50. / 32.) * (2 * verticalstrip + 1);
94 } else if(detector == 1 && pos == 'D') {
95 // Right dE
96 verticalstrip = 15 - verticalstrip;
97 x = dEX - (50. / 32.) * cos(detTheta) * (2 * verticalstrip + 1);
98 z = dEZ + (50. / 32.) * sin(detTheta) * (2 * verticalstrip + 1);
99 } else if(detector == 2 && pos == 'D') {
100 // Left dE
101 x = -dEX + (50. / 32.) * cos(detTheta) * (2 * verticalstrip + 1);
102 z = dEZ + (50. / 32.) * sin(detTheta) * (2 * verticalstrip + 1);
103 } else if(detector == 1 && pos == 'E') {
104 // Right E
105 x = EX - (50. / 32.) * cos(detTheta) * (2 * verticalstrip + 1);
106 z = EZ + (50. / 32.) * sin(detTheta) * (2 * verticalstrip + 1);
107 } else if(detector == 2 && pos == 'E') {
108 // Left E
109 verticalstrip = 15 - verticalstrip;
110 x = -EX + (50. / 32.) * cos(detTheta) * (2 * verticalstrip + 1);
111 z = EZ + (50. / 32.) * sin(detTheta) * (2 * verticalstrip + 1);
112 } else {
113 std::cout << "***Error, unrecognized detector and position combo!***" << std::endl;
114 }
115
116 y = (50. / 32.) * (2 * horizontalstrip + 1) - (50 / 16.) * 8;
117 Pos.SetX(x + X);
118 Pos.SetY(y + Y);
119 Pos.SetZ(z + Z);
120
121 return Pos;
122}
123
124void TCSM::BuildVH(std::vector<std::vector<std::pair<TFragment, TGRSIMnemonic>>>& strips, std::vector<TDetectorHit*>& hitVector)
125{
126 /// Build hits from horizontal (index = 0) and vertical (index = 1) strips into the hitVector
127 if(strips[0].empty() && strips[1].empty()) {
128 return;
129 }
130 if(strips[0].size() == 1 && strips[1].empty()) {
131 RecoverHit('H', strips[0][0], hitVector);
132 } else if(strips[0].empty() && strips[1].size() == 1) {
133 RecoverHit('V', strips[1][0], hitVector);
134 } else if(strips[0].size() == 1 && strips[1].size() == 1) {
135 hitVector.push_back(MakeHit(strips[0][0], strips[1][0]));
136 } else if(strips[1].size() == 1 && strips[0].size() == 2) {
137 auto he1 = static_cast<int>(strips[0][0].first.GetEnergy());
138 auto he2 = static_cast<int>(strips[0][1].first.GetEnergy());
139 auto ve1 = static_cast<int>(strips[1][0].first.GetEnergy());
140 if(AlmostEqual(ve1, he1 + he2) && SumHits) {
141 hitVector.push_back(MakeHit(strips[0], strips[1]));
142 } else if(AlmostEqual(ve1, he1)) {
143 hitVector.push_back(MakeHit(strips[0][0], strips[1][0]));
144 RecoverHit('H', strips[0][1], hitVector);
145 } else if(AlmostEqual(ve1, he2)) {
146 hitVector.push_back(MakeHit(strips[0][1], strips[1][0]));
147 RecoverHit('H', strips[0][0], hitVector);
148 }
149 } else if(strips[1].size() == 2 && strips[0].size() == 1) {
150 auto he1 = static_cast<int>(strips[0][0].first.GetEnergy());
151 auto ve1 = static_cast<int>(strips[1][0].first.GetEnergy());
152 auto ve2 = static_cast<int>(strips[1][1].first.GetEnergy());
153 if(AlmostEqual(ve1 + ve2, he1) && SumHits) {
154 hitVector.push_back(MakeHit(strips[0], strips[1]));
155 } else if(AlmostEqual(ve1, he1)) {
156 hitVector.push_back(MakeHit(strips[0][0], strips[1][0]));
157 RecoverHit('V', strips[1][1], hitVector);
158 } else if(AlmostEqual(ve2, he1)) {
159 hitVector.push_back(MakeHit(strips[0][0], strips[1][1]));
160 RecoverHit('V', strips[1][0], hitVector);
161 }
162 } else if(strips[1].size() == 2 && strips[0].size() == 2) {
163 auto he1 = static_cast<int>(strips[0][0].first.GetEnergy());
164 auto he2 = static_cast<int>(strips[0][1].first.GetEnergy());
165 auto ve1 = static_cast<int>(strips[1][0].first.GetEnergy());
166 auto ve2 = static_cast<int>(strips[1][1].first.GetEnergy());
167 if((AlmostEqual(ve1, he1) && AlmostEqual(ve2, he2)) || (AlmostEqual(ve1, he2) && AlmostEqual(ve2, he1))) {
168 // I can build both 1,1 and 2,2 or 1,2 and 2,1
169 if(std::abs(ve1 - he1) + std::abs(ve2 - he2) <= std::abs(ve1 - he2) + std::abs(ve2 - he1)) {
170 // 1,1 and 2,2 mimimizes difference
171 hitVector.push_back(MakeHit(strips[0][0], strips[1][0]));
172 hitVector.push_back(MakeHit(strips[0][1], strips[1][1]));
173 } else if(std::abs(ve1 - he1) + std::abs(ve2 - he2) > std::abs(ve1 - he2) + std::abs(ve2 - he1)) {
174 // 1,2 and 2,1 mimimizes difference
175 hitVector.push_back(MakeHit(strips[0][0], strips[1][1]));
176 hitVector.push_back(MakeHit(strips[0][1], strips[1][0]));
177 }
178 } else if(AlmostEqual(ve1, he1)) {
179 hitVector.push_back(MakeHit(strips[0][0], strips[1][0]));
180 } else if(AlmostEqual(ve2, he1)) {
181 hitVector.push_back(MakeHit(strips[0][1], strips[1][0]));
182 } else if(AlmostEqual(ve1, he2)) {
183 hitVector.push_back(MakeHit(strips[0][0], strips[1][1]));
184 } else if(AlmostEqual(ve2, he2)) {
185 hitVector.push_back(MakeHit(strips[0][1], strips[1][1]));
186 }
187 }
188}
189
190TCSMHit* TCSM::MakeHit(std::pair<TFragment, TGRSIMnemonic>& h, std::pair<TFragment, TGRSIMnemonic>& v)
191{
192 auto* csmHit = new TCSMHit;
193
194 if(h.second.ArrayPosition() != v.second.ArrayPosition()) {
195 std::cerr << "\tSomething is wrong, Horizontal and Vertical detector numbers don't match." << std::endl;
196 }
197 if(h.second.ArraySubPositionString().c_str()[0] != v.second.ArraySubPositionString().c_str()[0]) {
198 std::cerr << "\tSomething is wrong, Horizontal and Vertical positions don't match." << std::endl;
199 }
200
201 if(h.second.ArraySubPositionString()[0] == 'D') {
202 csmHit->SetDetectorNumber(h.second.ArrayPosition());
203 csmHit->SetDHorizontalCharge(h.first.GetCharge());
204 csmHit->SetDVerticalCharge(v.first.GetCharge());
205 csmHit->SetDHorizontalStrip(h.second.Segment());
206 csmHit->SetDVerticalStrip(v.second.Segment());
207 csmHit->SetDHorizontalCFD(static_cast<int>(h.first.GetCfd()));
208 csmHit->SetDVerticalCFD(static_cast<int>(v.first.GetCfd()));
209 csmHit->SetDHorizontalTime(h.first.GetTimeStamp());
210 csmHit->SetDVerticalTime(v.first.GetTimeStamp());
211 csmHit->SetDHorizontalEnergy(h.first.GetEnergy());
212 csmHit->SetDVerticalEnergy(v.first.GetEnergy());
213 csmHit->SetDPosition(TCSM::GetPosition(h.second.ArrayPosition(), h.second.ArraySubPositionString()[0],
214 h.second.Segment(), v.second.Segment()));
215 } else if(h.second.ArraySubPositionString().c_str()[0] == 'E') {
216 csmHit->SetDetectorNumber(h.second.ArrayPosition());
217 csmHit->SetEHorizontalCharge(h.first.GetCharge());
218 csmHit->SetEVerticalCharge(v.first.GetCharge());
219 csmHit->SetEHorizontalStrip(h.second.Segment());
220 csmHit->SetEVerticalStrip(v.second.Segment());
221 csmHit->SetEHorizontalCFD(static_cast<int>(h.first.GetCfd()));
222 csmHit->SetEVerticalCFD(static_cast<int>(v.first.GetCfd()));
223 csmHit->SetEHorizontalTime(h.first.GetTimeStamp());
224 csmHit->SetEVerticalTime(v.first.GetTimeStamp());
225 csmHit->SetEHorizontalEnergy(h.first.GetEnergy());
226 csmHit->SetEVerticalEnergy(v.first.GetEnergy());
227 csmHit->SetEPosition(TCSM::GetPosition(h.second.ArrayPosition(), h.second.ArraySubPositionString()[0],
228 h.second.Segment(), v.second.Segment()));
229 }
230
231 return csmHit;
232}
233
234TCSMHit* TCSM::MakeHit(std::vector<std::pair<TFragment, TGRSIMnemonic>>& hhV,
235 std::vector<std::pair<TFragment, TGRSIMnemonic>>& vvV)
236{
237 auto* csmHit = new TCSMHit;
238
239 if(hhV.empty() || vvV.empty()) {
240 std::cerr << "\tSomething is wrong, empty vector in MakeHit" << std::endl;
241 }
242
243 //-------------------- horizontal strips
244 int DetNumH = hhV[0].second.ArrayPosition();
245 char DetPosH = hhV[0].second.ArraySubPositionString()[0];
246 int ChargeH = static_cast<int>(hhV[0].first.GetCharge());
247 double EnergyH = hhV[0].first.GetEnergy();
248 int biggestH = 0;
249
250 // get accumulative charge/energy and find the strip with the highest charge (why not energy?)
251 for(size_t i = 1; i < hhV.size(); ++i) {
252 if(hhV[i].first.GetCharge() > hhV[biggestH].first.GetCharge()) {
253 biggestH = i;
254 }
255
256 if(hhV[i].second.ArrayPosition() != DetNumH) {
257 std::cerr << "\tSomething is wrong, Horizontal detector numbers don't match in vector loop." << std::endl;
258 }
259 if(hhV[i].second.ArraySubPositionString()[0] != DetPosH) {
260 std::cerr << "\tSomething is wrong, Horizontal detector positions don't match in vector loop." << std::endl;
261 }
262 ChargeH += static_cast<int>(hhV[i].first.GetCharge());
263 EnergyH += hhV[i].first.GetEnergy();
264 }
265
266 int StripH = hhV[biggestH].second.Segment();
267 auto ConFraH = static_cast<int>(hhV[biggestH].first.GetCfd());
268 auto TimeH = static_cast<double>(hhV[biggestH].first.GetTimeStamp());
269
270 //-------------------- vertical strips
271 int DetNumV = vvV[0].second.ArrayPosition();
272 char DetPosV = vvV[0].second.ArraySubPositionString()[0];
273 auto ChargeV = static_cast<int>(vvV[0].first.GetCharge());
274 double EnergyV = vvV[0].first.GetEnergy();
275 int biggestV = 0;
276
277 // get accumulative charge/energy and find the strip with the highest charge (why not energy?)
278 for(size_t i = 1; i < vvV.size(); ++i) {
279 if(vvV[i].first.GetCharge() > vvV[biggestV].first.GetCharge()) {
280 biggestV = i;
281 }
282
283 if(vvV[i].second.ArrayPosition() != DetNumV) {
284 std::cerr << "\tSomething is wrong, Vertical detector numbers don't match in vector loop." << std::endl;
285 }
286 if(vvV[i].second.ArraySubPositionString()[0] != DetPosV) {
287 std::cerr << "\tSomething is wrong, Vertical detector positions don't match in vector loop." << std::endl;
288 }
289 ChargeV += static_cast<int>(vvV[i].first.GetCharge());
290 EnergyV += vvV[i].first.GetEnergy();
291 }
292
293 int StripV = vvV[biggestV].second.Segment();
294 auto ConFraV = static_cast<int>(vvV[biggestV].first.GetCfd());
295 auto TimeV = static_cast<double>(vvV[biggestV].first.GetTimeStamp());
296
297 if(DetNumH != DetNumV) {
298 std::cerr << "\tSomething is wrong, Horizontal and Vertical detector numbers don't match in vector." << std::endl;
299 }
300 if(DetPosH != DetPosV) {
301 std::cerr << "\tSomething is wrong, Horizontal and Vertical positions don't match in vector." << std::endl;
302 }
303
304 if(DetPosH == 'D') {
305 csmHit->SetDetectorNumber(DetNumH);
306 csmHit->SetDHorizontalCharge(static_cast<float>(ChargeH));
307 csmHit->SetDVerticalCharge(static_cast<float>(ChargeV));
308 csmHit->SetDHorizontalStrip(StripH);
309 csmHit->SetDVerticalStrip(StripV);
310 csmHit->SetDHorizontalCFD(ConFraH);
311 csmHit->SetDVerticalCFD(ConFraV);
312 csmHit->SetDHorizontalTime(static_cast<int>(TimeH));
313 csmHit->SetDVerticalTime(static_cast<int>(TimeV));
314 csmHit->SetDHorizontalEnergy(EnergyH);
315 csmHit->SetDVerticalEnergy(EnergyV);
316 csmHit->SetDPosition(TCSM::GetPosition(DetNumH, DetPosH, StripH, StripV));
317 } else if(DetPosH == 'E') {
318 csmHit->SetDetectorNumber(DetNumH);
319 csmHit->SetEHorizontalCharge(static_cast<float>(ChargeH));
320 csmHit->SetEVerticalCharge(static_cast<float>(ChargeV));
321 csmHit->SetEHorizontalStrip(StripH);
322 csmHit->SetEVerticalStrip(StripV);
323 csmHit->SetEHorizontalCFD(ConFraH);
324 csmHit->SetEVerticalCFD(ConFraV);
325 csmHit->SetEHorizontalTime(static_cast<int>(TimeH));
326 csmHit->SetEVerticalTime(static_cast<int>(TimeV));
327 csmHit->SetEHorizontalEnergy(EnergyH);
328 csmHit->SetEVerticalEnergy(EnergyV);
329 csmHit->SetEPosition(TCSM::GetPosition(DetNumH, DetPosH, StripH, StripV));
330 }
331
332 return csmHit;
333}
334
335void TCSM::BuilddEE(std::vector<std::vector<TDetectorHit*>>& hitVec, std::vector<TDetectorHit*>& builtHits)
336{
337 std::vector<TDetectorHit*> d1;
338 std::vector<TDetectorHit*> d2;
339 std::vector<TDetectorHit*> e1;
340 std::vector<TDetectorHit*> e2;
341
342 for(auto& i : hitVec[0]) {
343 auto* hit = static_cast<TCSMHit*>(i);
344 if(hit->GetDetectorNumber() == 3 || hit->GetDetectorNumber() == 4) { // I am in side detectors
345 // I will never have a pair in the side detector, so go ahead and send it through.
346 builtHits.push_back(i);
347 } else if(hit->GetDetectorNumber() == 1) {
348 d1.push_back(i);
349 } else if(hit->GetDetectorNumber() == 2) {
350 d2.push_back(i);
351 } else {
352 std::cerr << " Caution, in BuilddEE detector number in D vector is out of bounds." << std::endl;
353 }
354 }
355
356 for(auto& i : hitVec[1]) {
357 auto* hit = static_cast<TCSMHit*>(i);
358 if(hit->GetDetectorNumber() == 1) {
359 e1.push_back(i);
360 } else if(hit->GetDetectorNumber() == 2) {
361 e2.push_back(i);
362 } else {
363 std::cerr << " Caution, in BuilddEE detector number in E vector is out of bounds." << std::endl;
364 }
365 }
366
367 MakedEE(d1, e1, builtHits);
368 MakedEE(d2, e2, builtHits);
369}
370
371void TCSM::MakedEE(std::vector<TDetectorHit*>& DHitVec, std::vector<TDetectorHit*>& EHitVec, std::vector<TDetectorHit*>& BuiltHits)
372{
373 if(DHitVec.empty() && EHitVec.empty()) {
374 return;
375 }
376 if(DHitVec.size() == 1 && EHitVec.empty()) {
377 BuiltHits.push_back(DHitVec.at(0));
378 } else if(DHitVec.empty() && EHitVec.size() == 1) {
379 BuiltHits.push_back(EHitVec.at(0));
380 } else if(DHitVec.size() == 1 && EHitVec.size() == 1) {
381 BuiltHits.push_back(CombineHits(DHitVec.at(0), EHitVec.at(0)));
382 } else if(DHitVec.size() == 2 && EHitVec.empty()) {
383 BuiltHits.push_back(DHitVec.at(0));
384 BuiltHits.push_back(DHitVec.at(1));
385 } else if(DHitVec.empty() && EHitVec.size() == 2) {
386 BuiltHits.push_back(EHitVec.at(0));
387 BuiltHits.push_back(EHitVec.at(1));
388 } else if(DHitVec.size() == 2 && EHitVec.size() == 1) {
389 double dt1 = static_cast<TCSMHit*>(DHitVec.at(0))->GetDPosition().Theta();
390 double dt2 = static_cast<TCSMHit*>(DHitVec.at(1))->GetDPosition().Theta();
391 double et = static_cast<TCSMHit*>(EHitVec.at(0))->GetEPosition().Theta();
392
393 if(std::abs(dt1 - et) <= std::abs(dt2 - et)) {
394 BuiltHits.push_back(CombineHits(DHitVec.at(0), EHitVec.at(0)));
395 // BuiltHits.back().Print();
396 BuiltHits.push_back(DHitVec.at(1));
397 // BuiltHits.back().Print();
398 } else {
399 BuiltHits.push_back(CombineHits(DHitVec.at(1), EHitVec.at(0)));
400 // BuiltHits.back().Print();
401 BuiltHits.push_back(DHitVec.at(0));
402 // BuiltHits.back().Print();
403 }
404 } else if(DHitVec.size() == 1 && EHitVec.size() == 2) {
405 double dt = static_cast<TCSMHit*>(DHitVec.at(0))->GetDPosition().Theta();
406 double et1 = static_cast<TCSMHit*>(EHitVec.at(0))->GetEPosition().Theta();
407 double et2 = static_cast<TCSMHit*>(EHitVec.at(0))->GetEPosition().Theta();
408
409 if(std::abs(dt - et1) <= std::abs(dt - et2)) {
410 BuiltHits.push_back(CombineHits(DHitVec.at(0), EHitVec.at(0)));
411 // BuiltHits.back().Print();
412 BuiltHits.push_back(EHitVec.at(1));
413 // BuiltHits.back().Print();
414 } else {
415 BuiltHits.push_back(CombineHits(DHitVec.at(0), EHitVec.at(1)));
416 // BuiltHits.back().Print();
417 BuiltHits.push_back(EHitVec.at(0));
418 // BuiltHits.back().Print();
419 }
420 } else if(DHitVec.size() == 2 && EHitVec.size() == 2) {
421 double dt1 = static_cast<TCSMHit*>(DHitVec.at(0))->GetDPosition().Theta();
422 double dt2 = static_cast<TCSMHit*>(DHitVec.at(1))->GetDPosition().Theta();
423 double et1 = static_cast<TCSMHit*>(EHitVec.at(0))->GetEPosition().Theta();
424 double et2 = static_cast<TCSMHit*>(EHitVec.at(1))->GetEPosition().Theta();
425
426 if(std::abs(dt1 - et1) + std::abs(dt2 - et2) <= std::abs(dt1 - et2) + std::abs(dt2 - et1)) {
427 BuiltHits.push_back(CombineHits(DHitVec.at(0), EHitVec.at(0)));
428 // BuiltHits.back().Print();
429 BuiltHits.push_back(CombineHits(DHitVec.at(1), EHitVec.at(1)));
430 // BuiltHits.back().Print();
431 } else {
432 BuiltHits.push_back(CombineHits(DHitVec.at(0), EHitVec.at(1)));
433 // BuiltHits.back().Print();
434 BuiltHits.push_back(CombineHits(DHitVec.at(1), EHitVec.at(0)));
435 // BuiltHits.back().Print();
436 }
437 } else {
438 std::cout << "D Size: " << DHitVec.size() << " E Size: " << EHitVec.size() << std::endl;
439 }
440}
441
442void TCSM::OldBuilddEE(std::vector<TDetectorHit*>& DHitVec, std::vector<TDetectorHit*>& EHitVec, std::vector<TDetectorHit*>& BuiltHits)
443{
444 bool printbit = false;
445 if(DHitVec.empty() && EHitVec.empty()) { // Why am I even here?!
446 return;
447 }
448
449 std::vector<bool> EUsed(EHitVec.size(), false);
450 std::vector<bool> DUsed(DHitVec.size(), false);
451
452 for(size_t diter = 0; diter < DHitVec.size(); diter++) {
453 if(DUsed.at(diter)) {
454 continue;
455 }
456
457 for(size_t eiter = 0; eiter < EHitVec.size(); eiter++) {
458 if(EUsed.at(eiter)) {
459 continue;
460 }
461
462 if(static_cast<TCSMHit*>(DHitVec.at(diter))->GetDetectorNumber() ==
463 static_cast<TCSMHit*>(EHitVec.at(eiter))->GetDetectorNumber()) { // Hits are in the same stack
464 if(AlmostEqual(static_cast<TCSMHit*>(DHitVec.at(diter))->GetDPosition().Theta(),
465 static_cast<TCSMHit*>(EHitVec.at(eiter))->GetEPosition().Theta())) { // Same-ish Theta
466 //&& AlmostEqual(DHitVec.at(diter).GetDPosition().Phi(),EHitVec.at(eiter).GetEPosition().Phi())
467 //)//Same-ish Phi
468 BuiltHits.push_back(CombineHits(DHitVec.at(diter), EHitVec.at(eiter)));
469 DUsed.at(diter) = true;
470 EUsed.at(eiter) = true;
471 break;
472 }
473 }
474 }
475 }
476
477 // This loop adds uncorrelated events in the telescope together. This may be bad, but let's see.
478 for(size_t i = 0; i < DHitVec.size(); i++) {
479 if(!DUsed.at(i)) {
480 for(size_t j = 0; j < EHitVec.size(); j++) {
481 if(!EUsed.at(j)) {
482 if(static_cast<TCSMHit*>(EHitVec.at(j))->GetDetectorNumber() == static_cast<TCSMHit*>(DHitVec.at(i))->GetDetectorNumber()) {
483 BuiltHits.push_back(CombineHits(DHitVec.at(i), EHitVec.at(j)));
484 DUsed.at(i) = true;
485 EUsed.at(j) = true;
486 break;
487 }
488 }
489 }
490 }
491 }
492
493 // Send through the stragglers. This is very permissive, but we trust BuildVH to take care of the riff-raff
494 for(size_t i = 0; i < DHitVec.size(); i++) {
495 if(!DUsed.at(i)) {
496 BuiltHits.push_back(DHitVec.at(i));
497 }
498 }
499 for(size_t j = 0; j < EHitVec.size(); j++) {
500 if(!EUsed.at(j)) {
501 BuiltHits.push_back(EHitVec.at(j));
502 }
503 }
504
505 if(printbit) {
506 for(auto& BuiltHit : BuiltHits) {
507 std::cout << DGREEN;
508 BuiltHit->Print();
509 std::cout << RESET_COLOR << std::endl;
510 }
511 }
512}
513
514void TCSM::RecoverHit(char orientation, std::pair<TFragment, TGRSIMnemonic>& hit, std::vector<TDetectorHit*>& hits)
515{
516 if(!RecoverHits) {
517 return;
518 }
519
520 auto* csmHit = new TCSMHit;
521
522 int detno = hit.second.ArrayPosition();
523 char pos = hit.second.ArraySubPositionString()[0];
524
525 switch(detno) {
526 case 1: return;
527 case 2:
528 if(pos == 'D' && orientation == 'V') { // Recover 2DN09, channel 1040
529 csmHit->SetDetectorNumber(detno);
530 csmHit->SetDHorizontalCharge(hit.first.GetCharge());
531 csmHit->SetDVerticalCharge(hit.first.GetCharge());
532 csmHit->SetDHorizontalStrip(9);
533 csmHit->SetDVerticalStrip(hit.second.Segment());
534 csmHit->SetDHorizontalCFD(static_cast<int>(hit.first.GetCfd()));
535 csmHit->SetDVerticalCFD(static_cast<int>(hit.first.GetCfd()));
536 csmHit->SetDHorizontalTime(hit.first.GetTimeStamp());
537 csmHit->SetDVerticalTime(hit.first.GetTimeStamp());
538 csmHit->SetDHorizontalEnergy(hit.first.GetEnergy());
539 csmHit->SetDVerticalEnergy(hit.first.GetEnergy());
540 csmHit->SetDPosition(TCSM::GetPosition(detno, pos, 9, hit.second.Segment()));
541 }
542 break;
543 case 3:
544 if(pos == 'E') {
545 std::cerr << "3E in RecoverHit" << std::endl;
546
547 return;
548 } else if(orientation == 'H') { // Recover 3DP11, channel 1145
549 csmHit->SetDetectorNumber(detno);
550 csmHit->SetDHorizontalCharge(hit.first.GetCharge());
551 csmHit->SetDVerticalCharge(hit.first.GetCharge());
552 csmHit->SetDHorizontalStrip(hit.second.Segment());
553 csmHit->SetDVerticalStrip(11);
554 csmHit->SetDHorizontalCFD(static_cast<int>(hit.first.GetCfd()));
555 csmHit->SetDVerticalCFD(static_cast<int>(hit.first.GetCfd()));
556 csmHit->SetDHorizontalTime(hit.first.GetTimeStamp());
557 csmHit->SetDVerticalTime(hit.first.GetTimeStamp());
558 csmHit->SetDHorizontalEnergy(hit.first.GetEnergy());
559 csmHit->SetDVerticalEnergy(hit.first.GetEnergy());
560 csmHit->SetDPosition(TCSM::GetPosition(detno, pos, hit.second.Segment(), 11));
561 }
562 break;
563 case 4:
564 if(pos == 'E') {
565 std::cerr << "4E in RecoverHit" << std::endl;
566 return;
567 } else if(orientation == 'H') { // Recover 4DP15, channel 1181
568 csmHit->SetDetectorNumber(detno);
569 csmHit->SetDHorizontalCharge(hit.first.GetCharge());
570 csmHit->SetDVerticalCharge(hit.first.GetCharge());
571 csmHit->SetDHorizontalStrip(hit.second.Segment());
572 csmHit->SetDVerticalStrip(15);
573 csmHit->SetDHorizontalCFD(static_cast<int>(hit.first.GetCfd()));
574 csmHit->SetDVerticalCFD(static_cast<int>(hit.first.GetCfd()));
575 csmHit->SetDHorizontalTime(hit.first.GetTimeStamp());
576 csmHit->SetDVerticalTime(hit.first.GetTimeStamp());
577 csmHit->SetDHorizontalEnergy(hit.first.GetEnergy());
578 csmHit->SetDVerticalEnergy(hit.first.GetEnergy());
579 csmHit->SetDPosition(TCSM::GetPosition(detno, pos, hit.second.Segment(), 15));
580 }
581 break;
582 default:
583 std::cerr << "Something is wrong. The detector number in recover hit is out of bounds." << std::endl;
584 return;
585 }
586
587 if(!csmHit->IsEmpty()) {
588 hits.push_back(csmHit);
589 }
590}
591
593{
594 auto* dHit = static_cast<TCSMHit*>(d_hit);
595 auto* eHit = static_cast<TCSMHit*>(e_hit);
596 if(dHit->GetDetectorNumber() != eHit->GetDetectorNumber()) {
597 std::cerr << "Something is wrong. In combine hits, the detector numbers don't match" << std::endl;
598 }
599
600 dHit->SetEHorizontalStrip(eHit->GetEHorizontalStrip());
601 dHit->SetEVerticalStrip(eHit->GetEVerticalStrip());
602
603 dHit->SetEHorizontalCharge(eHit->GetEHorizontalCharge());
604 dHit->SetEVerticalCharge(eHit->GetEVerticalCharge());
605
606 dHit->SetEHorizontalEnergy(eHit->GetEHorizontalEnergy());
607 dHit->SetEVerticalEnergy(eHit->GetEVerticalEnergy());
608
609 dHit->SetEHorizontalCFD(eHit->GetEHorizontalCFD());
610 dHit->SetEVerticalCFD(eHit->GetEVerticalCFD());
611
612 dHit->SetEHorizontalTime(static_cast<int>(eHit->GetEHorizontalTime()));
613 dHit->SetEVerticalTime(static_cast<int>(eHit->GetEVerticalTime()));
614
615 dHit->SetEPosition(eHit->GetEPosition());
616
617 return dHit;
618}
619
620bool TCSM::AlmostEqual(int val1, int val2) const
621{
622 auto diff = static_cast<double>(std::abs(val1 - val2));
623 double ave = (val1 + val2) / 2.;
624 double frac = diff / ave;
625 return frac < fAlmostEqualWindow;
626}
627
628bool TCSM::AlmostEqual(double val1, double val2) const
629{
630 double frac = std::fabs(val1 - val2) / ((val1 + val2) / 2.);
631 return frac < fAlmostEqualWindow;
632}
#define DGREEN
Definition Globals.h:17
#define RESET_COLOR
Definition Globals.h:5
constexpr bool SumHits
Definition TCSM.cxx:5
constexpr bool RecoverHits
Definition TCSM.cxx:4
Double_t GetEnergy(Option_t *="") const override
!
Definition TCSMHit.h:118
TVector3 GetEPosition() const
!
Definition TCSMHit.h:111
void SetEHorizontalStrip(const Int_t temp)
!
Definition TCSMHit.h:133
UShort_t GetDetectorNumber() const
!
Definition TCSMHit.h:85
TVector3 GetDPosition() const
!
Definition TCSMHit.h:112
bool AlmostEqual(int, int) const
Definition TCSM.cxx:620
void BuilddEE(std::vector< std::vector< TDetectorHit * > > &, std::vector< TDetectorHit * > &)
Definition TCSM.cxx:335
void OldBuilddEE(std::vector< TDetectorHit * > &, std::vector< TDetectorHit * > &, std::vector< TDetectorHit * > &)
Definition TCSM.cxx:442
void BuildVH(std::vector< std::vector< std::pair< TFragment, TGRSIMnemonic > > > &, std::vector< TDetectorHit * > &)
Definition TCSM.cxx:124
static TVector3 GetPosition(int detector, char pos, int horizontalstrip, int verticalstrip, double X=0.00, double Y=0.00, double Z=0.00)
Definition TCSM.cxx:69
TCSM()
Definition TCSM.cxx:9
std::map< int16_t, std::vector< std::vector< std::vector< std::pair< TFragment, TGRSIMnemonic > > > > > fFragments
!
Definition TCSM.h:56
double fAlmostEqualWindow
Definition TCSM.h:57
void MakedEE(std::vector< TDetectorHit * > &DHitVec, std::vector< TDetectorHit * > &EHitVec, std::vector< TDetectorHit * > &BuiltHits)
Definition TCSM.cxx:371
TCSMHit * MakeHit(std::pair< TFragment, TGRSIMnemonic > &, std::pair< TFragment, TGRSIMnemonic > &)
Definition TCSM.cxx:190
TCSMHit * CombineHits(TDetectorHit *, TDetectorHit *)
Definition TCSM.cxx:592
void BuildHits() override
!
Definition TCSM.cxx:52
void RecoverHit(char, std::pair< TFragment, TGRSIMnemonic > &, std::vector< TDetectorHit * > &)
Definition TCSM.cxx:514
static int fCfdBuildDiff
! largest acceptable time difference between events (clock ticks) (50 ns)
Definition TCSM.h:59
void AddFragment(const std::shared_ptr< const TFragment > &, TChannel *) override
!
Definition TCSM.cxx:14
const TMnemonic * GetMnemonic() const
std::vector< TDetectorHit * > & Hits()
Definition TDetector.h:78
virtual int16_t ArrayPosition() const
Definition TMnemonic.h:66
virtual std::string ArraySubPositionString() const
Definition TMnemonic.h:71
virtual std::string CollectedChargeString() const
Definition TMnemonic.h:72