ATLAS Offline Software
Loading...
Searching...
No Matches
AlfaLocalHits.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include "AlfaLocalHits.h"
9#include "GaudiKernel/MsgStream.h"
11#include "TObjArray.h"
12#include "TObjString.h"
13#include <iostream>
14#include <iomanip>
15using std::cout;
16using std::endl;
17
19//
20// implementation of AlfaLocalHit
21// which stores information about one hit
22//
25 m_pot (0),
26 m_potname (""),
27 m_ishit (0),
28 m_x (0.0),
29 m_y (0.0),
30 m_z (0.0),
31 m_LocRecCorr (nullptr)
32{
33}
34
35
37 // explicit constructor
38 SetHit(LocRecCorrHit);
39}
40
42 m_pot = h->GetPotNum();
44 m_ishit = 1;
45 m_x = h->GetX();
46 m_y = h->GetY();
47 m_z = h->GetZ();
48 m_LocRecCorr = h->GetLocRecCorr();
49}
50
51
52void AlfaLocalHit::SetHit(const ALFA_LocRecCorrEvent * LocRecCorrHit){
53 m_pot = LocRecCorrHit->getPotNum();
54 //cout << "AlfaLocalHit::SetHit... m_pot = " << m_pot << endl;
56 m_ishit = 1;
57 m_x = LocRecCorrHit->getXpositionLHC();
58 m_y = LocRecCorrHit->getYpositionLHC();
59 m_LocRecCorr = LocRecCorrHit;
60 AssignZ();
61}
62
63
65 if(m_pot < 0) {
66 throw std::runtime_error("AlfaLocalHit::AssignZ() m_pot not assigned");
67 }
68 m_z = 1.e10;
69 if(m_potname.Contains("B7L1U")) m_z = 241528.;
70 if(m_potname.Contains("A7L1U")) m_z = 237388.;
71 if(m_potname.Contains("B7L1L")) m_z = 241538.;
72 if(m_potname.Contains("A7L1L")) m_z = 237398.;
73 if(m_potname.Contains("B7R1U")) m_z = -241548.;
74 if(m_potname.Contains("A7R1U")) m_z = -237408.;
75 if(m_potname.Contains("B7R1L")) m_z = -241538.;
76 if(m_potname.Contains("A7R1L")) m_z = -237398.;
77 if(!(m_z < 1.e10)){
78 throw std::runtime_error("AlfaLocalHit::AssignZ: z coordinate was not assigned for the hit");
79 }
80}
81
83 cout << "pot = " << m_pot
84 << " i.e " << m_potname.Data()
85 << " x = " << m_x
86 << " m_y = " << m_y
87 ;
88}
89
90int AlfaLocalHit::GetMDindex(const char * name){
91 TString n(name);
92 if(n.Contains("B7L1U")) return 0;
93 if(n.Contains("B7L1L")) return 1;
94 if(n.Contains("A7L1U")) return 2;
95 if(n.Contains("A7L1L")) return 3;
96 if(n.Contains("A7R1U")) return 4;
97 if(n.Contains("A7R1L")) return 5;
98 if(n.Contains("B7R1U")) return 6;
99 if(n.Contains("B7R1L")) return 7;
100 throw std::runtime_error("AlfaLocalHit::GetMDindex ... Not recognised detector name: " + n);
101}
103 if(i == 0) return {"B7L1U"};
104 if(i == 1) return {"B7L1L"};
105 if(i == 2) return {"A7L1U"};
106 if(i == 3) return {"A7L1L"};
107 if(i == 4) return {"A7R1U"};
108 if(i == 5) return {"A7R1L"};
109 if(i == 6) return {"B7R1U"};
110 if(i == 7) return {"B7R1L"};
111 throw std::runtime_error("AlfaLocalHit::GetMDname ... Not recognised detector number: " + std::to_string(i));
112}
113
114
115
117//
118// implementation of AlfaLocalHits
119// which stores ithe AlfaLocalHit objects
120//
122// .. default ctor.
124 m_hits.clear();
125 m_paths.clear();
126 m_nhits = m_hits.size();
127 m_npaths = m_paths.size();
128 m_pathpattern ="";
129}
131 m_nhits = m_hits.size();
132 m_npaths = m_paths.size();
133}
135 m_hits.push_back(h);
136 update();
137 return m_hits.size();
138}
140 m_hits.clear();
141 m_paths.clear();
142 m_pathpattern ="";
143 update();
144}
146 m_paths.clear();
147 m_pathpattern ="";
148 update();
149}
150
151// .. size
153 if(m_nhits != (int) m_hits.size()){
154 throw std::runtime_error("Class AlfaLocalHits: m_nhits != m_hits.size() !!! ");
155 }
156 return m_nhits;
157}
158// .. Dump
160 if(m_nhits == 0){
161 cout << "Cannot dump the AlfaLocalHits object, it has zero size." << endl;
162 }else{
163 cout << "Dumping object of AlfaLocalHits class:" << endl;
164 for(Int_t i = 0; i < m_nhits; i++){
165 cout << "at " << i << " ";
166 m_hits.at(i).Print();
167 cout << endl;
168 }
169 }
170}
172 cout << "Dumping paths for " << m_pathpattern.Data() << " pattern" << endl;
173 for(int i = 0; i < m_npaths; i++){
174 m_paths.at(i).Dump();
175 }
176}
177
178void AlfaLocalHits::ApplyPathPattern(const char * pattern){
180// ... apply path pattern to all the hits
181// paths will be the same objects contaioning
182// only the wanted hits
183// pattern examples: B7L1U_A7L1U_X_B7R1L etc. X ... anything
185 m_pathpattern = pattern;
186 TString ts_pattern(pattern);
187 TObjArray toa_tokenized_pattern(4,0);
188 toa_tokenized_pattern = * ts_pattern.Tokenize("_");
189 if(toa_tokenized_pattern.GetEntries() != 4){
190 std::runtime_error("AlfaLocalHits: Pattern of wrong length!!! " + ts_pattern);
191 }
192 TString patternitem("");
193 AlfaLocalHits alh_tmp;
194 for(int i1 = 0; i1 < m_nhits; i1++){
195 int i1last = (i1 == m_nhits-1);
196 AlfaLocalHit h1(m_hits.at(i1));
197 TString patternitem0 = TString(((TObjString*) toa_tokenized_pattern.At(0))->GetString());
198 if((h1.GetPotName().Contains(patternitem0))
199 || (i1last && patternitem0.Contains("X"))
200 ){
201 for(int i2 = 0; i2 < m_nhits; i2++){
202 int i2last = (i2 == m_nhits-1);
203 if(i2 == i1 && !i2last) continue;
204 AlfaLocalHit h2(m_hits.at(i2));
205 TString patternitem1 = TString(((TObjString*) toa_tokenized_pattern.At(1))->GetString());
206 if((h2.GetPotName().Contains(patternitem1))
207 ||(i2last && patternitem1.Contains("X"))
208 ){
209 for(int i3 = 0; i3 < m_nhits; i3++){
210 int i3last = (i3 == m_nhits-1);
211 if(i3 == i1 && !i3last) continue;
212 if(i3 == i2 && !i3last) continue;
213 AlfaLocalHit h3(m_hits.at(i3));
214 TString patternitem2 = TString(((TObjString*) toa_tokenized_pattern.At(2))->GetString());
215 if((h3.GetPotName().Contains(patternitem2))
216 ||(i3last && patternitem2.Contains("X"))
217 ){
218 for(int i4 = 0; i4 < m_nhits; i4++){
219 int i4last = (i4 == m_nhits-1);
220 if(i4 == i1 && !i4last) continue;
221 if(i4 == i2 && !i4last) continue;
222 if(i4 == i3 && !i4last) continue;
223 AlfaLocalHit h4(m_hits.at(i4));
224 TString patternitem3 = TString(((TObjString*) toa_tokenized_pattern.At(3))->GetString());
225 if((h4.GetPotName().Contains(patternitem3))
226 ||(i4last && patternitem3.Contains("X"))
227 ){
228 if(patternitem0!='X') {alh_tmp.AddHit(h1);}
229 if(patternitem1!='X') {alh_tmp.AddHit(h2);}
230 if(patternitem2!='X') {alh_tmp.AddHit(h3);}
231 if(patternitem3!='X') {alh_tmp.AddHit(h4);}
232 }
233 }
234 }
235 }
236 }
237 }
238 }
239 }
240 alh_tmp.SetPathPattern(m_pathpattern.Data());
241 m_paths.push_back(std::move(alh_tmp));
242 update();
243}
244
245void AlfaLocalHits::SetPathPattern(const char * pattern){
246 m_pathpattern = pattern;
247}
248
250 if(ipath >= m_npaths){
251 throw std::runtime_error("Requesting path with overflow index");
252 }
253 return &(m_paths.at(ipath));
254}
255
256
258 if(ihit >= m_nhits){
259 throw std::runtime_error("Requesting hit with overflow index");
260 }
261 return &(m_hits.at(ihit));
262}
263
264
265
267//
268// implementation of AlfaTrack
269// which stores information about one track
270//
273 // ... initialize
274 m_arm = -1.;
275 m_x = 1.e10;
276 m_y = 1.e10;
277 m_z = 1.e10;
278 m_xslope = 1.e10;
279 m_yslope = 1.e10;
280 m_nearlocalhit = nullptr;
281 m_farlocalhit = nullptr;
282
283 // ... asign hits that create the track
284 m_trackcandhits = hits;
285
286 // ... calculate track kinematics and project track back to "pot planes"
291 cout << "Left and right side ALFA tracks at one time not supported in AlfaTrackCand class" << endl;
292 cout << "Consider using another class for them or change path pattern." << endl;
293 }
294}
295
297 if((m_trackcandhits->GetPathPattern().Contains("B7L1U")
298 && m_trackcandhits->GetPathPattern().Contains("A7L1U"))
299 || (m_trackcandhits->GetPathPattern().Contains("B7L1L")
300 && m_trackcandhits->GetPathPattern().Contains("A7L1L"))
301 ){
302 MsgStream LogStream(Athena::getMessageSvc(), "ALFA_TrackCand::IsLeftTrack");
303 LogStream << MSG::DEBUG << "Track candidate is left" << endmsg;
304 return 1;
305 }else{
306 return 0;
307 }
308}
309
311 if((m_trackcandhits->GetPathPattern().Contains("B7R1U")
312 && m_trackcandhits->GetPathPattern().Contains("A7R1U"))
313 || (m_trackcandhits->GetPathPattern().Contains("B7R1L")
314 && m_trackcandhits->GetPathPattern().Contains("A7R1L"))
315 ){
316 MsgStream LogStream(Athena::getMessageSvc(), "ALFA_TrackCand::IsRightTrack");
317 LogStream << MSG::DEBUG << "Track candidate is right" << endmsg;
318 return 1;
319 }else{
320 return 0;
321 }
322}
323
325 if((m_trackcandhits->GetPathPattern().Contains("B7L1L")
326 && m_trackcandhits->GetPathPattern().Contains("A7L1L"))
327 || (m_trackcandhits->GetPathPattern().Contains("B7R1L")
328 && m_trackcandhits->GetPathPattern().Contains("A7R1L"))
329 ){
330 MsgStream LogStream(Athena::getMessageSvc(), "ALFA_TrackCand::IsLowerArmTrack");
331 LogStream << MSG::DEBUG << "Track candidate is in the lower arm" << endmsg;
332 return 1;
333 }else{
334 return 0;
335 }
336}
337
339 if((m_trackcandhits->GetPathPattern().Contains("B7L1U")
340 && m_trackcandhits->GetPathPattern().Contains("A7L1U"))
341 || (m_trackcandhits->GetPathPattern().Contains("B7R1U")
342 && m_trackcandhits->GetPathPattern().Contains("A7R1U"))
343 ){
344 MsgStream LogStream(Athena::getMessageSvc(), "ALFA_TrackCand::IsUpperArmTrack");
345 LogStream << MSG::DEBUG << "Track candidate is in the upper arm" << endmsg;
346 return 1;
347 }else{
348 return 0;
349 }
350}
351
352
355 return 1;
356 }else{
357 return 0;
358 }
359}
360
363 return 1;
364 }else{
365 return 0;
366 }
367}
368
370 float xM = 1.e10;
371 float xm = 1.e10;
372 float yM = 1.e10;
373 float ym = 1.e10;
374 float zM = 1.e10;
375 float zm = 1.e10;
376 for(int i = 0; i < m_trackcandhits->GetNhits(); i++){
378 if(m_trackcandhits->GetHit(i)->GetPotName().Contains("B7")){
379 xM = m_trackcandhits->GetHit(i)->GetX();
380 yM = m_trackcandhits->GetHit(i)->GetY();
381 zM = m_trackcandhits->GetHit(i)->GetZ();
382 m_farlocalhit = m_trackcandhits->GetHit(i);
383 }else if(m_trackcandhits->GetHit(i)->GetPotName().Contains("A7")){
384 xm = m_trackcandhits->GetHit(i)->GetX();
385 ym = m_trackcandhits->GetHit(i)->GetY();
386 zm = m_trackcandhits->GetHit(i)->GetZ();
387 m_nearlocalhit = m_trackcandhits->GetHit(i);
388 }
390 m_arm = 2;
392 m_arm = 1;
393 }else{
394 throw std::runtime_error("AlfaTrackCand::CalcTrack() ... track is in left but unknown upper/lower arm");
395 }
396 }else if(AlfaTrackCand::IsRightTrack()){
397 if(m_trackcandhits->GetHit(i)->GetPotName().Contains("B7")){
398 xm = m_trackcandhits->GetHit(i)->GetX();
399 ym = m_trackcandhits->GetHit(i)->GetY();
400 zm = m_trackcandhits->GetHit(i)->GetZ();
401 m_nearlocalhit = m_trackcandhits->GetHit(i);
402 }else if(m_trackcandhits->GetHit(i)->GetPotName().Contains("A7")){
403 xM = m_trackcandhits->GetHit(i)->GetX();
404 yM = m_trackcandhits->GetHit(i)->GetY();
405 zM = m_trackcandhits->GetHit(i)->GetZ();
406 m_farlocalhit = m_trackcandhits->GetHit(i);
407 }
409 m_arm = 4;
411 m_arm = 3;
412 }else{
413 std::runtime_error("AlfaTrackCand::CalcTrack() ... track is in right but unknown upper/lower arm");
414 }
415 }else{
416 std::runtime_error("AlfaTrackCand::CalcTrack() ... track must be left or right");
417 }
418 }
419
420 m_x = (xM + xm) / 2.;
421 m_y = (yM + ym) / 2.;
422 m_z = (zM + zm) / 2.;
423 m_xslope = (xM - xm) / (zM - zm);
424 m_yslope = (yM - ym) / (zM - zm);
425
426}
427
428
430 // ... distance from intercept to xy plane at pot z is
431 // half of the distance between the pots
432 // ... the direction vector starting at x,y needs to be
433 // scaled to touch the plane at pot's z
434 double z_nearpot = m_nearlocalhit->GetZ();
435 double scalefactortonearpot = z_nearpot - m_z;
436 double ximpact_nearpot = m_x + m_xslope * scalefactortonearpot;
437 double yimpact_nearpot = m_y + m_yslope * scalefactortonearpot;
438 double zimpact_nearpot = z_nearpot;
439 m_nearimpactpoint.setX(ximpact_nearpot);
440 m_nearimpactpoint.setY(yimpact_nearpot);
441 m_nearimpactpoint.setZ(zimpact_nearpot);
442
443 double z_farpot = m_farlocalhit->GetZ();
444 double scalefactortofarpot = z_farpot - m_z;
445 double ximpact_farpot = m_x + m_xslope * scalefactortofarpot;
446 double yimpact_farpot = m_y + m_yslope * scalefactortofarpot;
447 double zimpact_farpot = z_farpot;
448 m_farimpactpoint.setX(ximpact_farpot);
449 m_farimpactpoint.setY(yimpact_farpot);
450 m_farimpactpoint.setZ(zimpact_farpot);
451
452}
453
454
456 std::ios oldState(nullptr);
457 oldState.copyfmt(std::cout);
458 cout << "Dumping AlfaTrackCand:" << endl;
459 cout << " arm = " << std::setprecision(8) << m_arm
460 << " x = " << std::setprecision(8) << m_x
461 << " y = " << std::setprecision(8) << m_y
462 << " z = " << std::setprecision(8) << m_z
463 << " x'= " << std::setprecision(8) << m_xslope
464 << " y' = " << std::setprecision(8) << m_yslope
465 << endl;
466 std::cout.copyfmt(oldState);
467
468}
469
470
471
#define endmsg
const ALFA_LocRecCorrEvent * m_LocRecCorr
TString m_potname
void SetHit(const ALFA_LocRecCorrEvent *LocRecCorrHit)
TString GetPotName() const
TString GetMDname(int i)
int GetMDindex(const char *name)
int AddHit(const AlfaLocalHit &h)
AlfaLocalHit * GetHit(int ihit)
TString m_pathpattern
void SetPathPattern(const char *pattern)
void ApplyPathPattern(const char *pattern)
std::vector< AlfaLocalHits > m_paths
std::vector< AlfaLocalHit > m_hits
AlfaLocalHits * GetPathHits(int ipath)
void Dump() const
HepGeom::Point3D< double > m_farimpactpoint
HepGeom::Point3D< double > m_nearimpactpoint
AlfaLocalHits * m_trackcandhits
AlfaLocalHit * m_farlocalhit
AlfaLocalHit * m_nearlocalhit
AlfaTrackCand(AlfaLocalHits *hits)
Header file for AthHistogramAlgorithm.
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)