ATLAS Offline Software
FPGATrackSimTrack.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 
10 #include <iostream>
11 #include <iomanip>
12 #include <cmath>
13 using namespace std;
14 
15 // first stage only
16 
17 // We need a destructor apparently?
19 
20 std::vector<float> FPGATrackSimTrack::getCoords(unsigned ilayer) const
21 {
22  std::vector<float> coords;
23  if (ilayer >= m_hits.size())
24  throw std::range_error("FPGATrackSimTrack::getCoords() out of bounds");
25 
26  if (m_trackCorrType == TrackCorrType::None)
27  {
28  coords.push_back(m_hits[ilayer].getEtaCoord());
29  coords.push_back(m_hits[ilayer].getPhiCoord());
30  }
31  else
32  {
33  coords = computeIdealCoords(ilayer);
34  }
35 
36  return coords;
37 }
38 
39 std::vector<float> FPGATrackSimTrack::computeIdealCoords(unsigned ilayer) const
40 {
41 
42  double target_r = m_idealRadii[ilayer];
43  if (m_hits[ilayer].getHitType() == HitType::spacepoint) {
44  unsigned other_layer = (m_hits[ilayer].getSide() == 0) ? ilayer + 1 : ilayer - 1;
45  target_r = (target_r + m_idealRadii[other_layer]) / 2.;
46  }
47 
48  double hough_x = getHoughX();
49  double hough_y = getHoughY();
50 
51  // Use the centralized computeIdealCoords function from FPGATrackSimFunctions
52  std::vector<float> coords = ::computeIdealCoords(m_hits[ilayer], hough_x, hough_y, target_r, m_doDeltaGPhis, m_trackCorrType);
53 
54  return coords;
55 }
56 
57 float FPGATrackSimTrack::getEtaCoord(int ilayer) const {
58  auto coords = getCoords(ilayer);
59  if (coords.size() > 0) {
60  return coords.at(0);
61  }
62  else {
63  throw std::range_error("FPGATrackSimTrack::getCoord(layer,coord) out of bounds");
64  }
65 }
66 
67 float FPGATrackSimTrack::getPhiCoord(int ilayer) const {
68  auto coords = getCoords(ilayer);
69 
70  // If this is a spacepoint, and if this is the "outer" hit on a strip module
71  // (side = 1) then we actually return the z/eta coord.
72  // Since spacepoints are duplicated, this avoids using the same phi coord
73  // twice and alsp avoids having to teach the code that strip spacepoints are
74  // "2D" hits despite being in the strips, which everything assumes is 1D.
75  // This makes it easy to mix and match spacepoints with strip hits that aren't
76  // spacepoints (since the number of strip layers is held fixed).
77  unsigned target_coord = 1;
78  if (m_hits[ilayer].getHitType() == HitType::spacepoint && (m_hits[ilayer].getPhysLayer() % 2) == 1) {
79  target_coord = 0;
80  }
81 
82  if (coords.size() > target_coord) {
83  return coords.at(target_coord);
84  }
85  else {
86  throw std::range_error("FPGATrackSimTrack::getCoord(layer,coord) out of bounds");
87  }
88 }
89 
91  int nCoords = 0;
92  for (const auto& hit : m_hits) {
93  nCoords += hit.getDim();
94  }
95  return nCoords;
96 }
97 
98 //set a specific position in m_hits
100 {
101  if (m_hits.size() > i)
102  m_hits[i] = hit;
103  else
104  throw std::range_error("FPGATrackSimTrack::setFPGATrackSimHit() out of bounds");
105 }
106 
109 {
110  if (m_hits.size() > 0) m_hits.clear();
111  m_hits.resize(dim);
112 }
113 
114 
115 // if ForceRange==true, then phi = [-pi..pi)
116 void FPGATrackSimTrack::setPhi(float phi, bool ForceRange) {
117  if (ForceRange) {
118  // when phi is ridiculously large, there is no point in adjusting it
119  if (std::abs(phi) > 100) {
120  if (m_chi2 < 100) { // this is a BAD track, so fail it if chi2 hasn't done so already
121  m_chi2 += 100; // we want to fail this event anyway
122  }
123  }
124  else {
125  while (phi >= M_PI) phi -= (2. * M_PI);
126  while (phi < -M_PI) phi += (2. * M_PI);
127  }
128  }
129  m_phi = phi;
130 }
131 
132 float FPGATrackSimTrack::getParameter(int ipar) const
133 {
134  switch (ipar) {
135  case 0:
136  return m_qoverpt;
137  break;
138  case 1:
139  return m_d0;
140  break;
141  case 2:
142  return m_phi;
143  break;
144  case 3:
145  return m_z0;
146  break;
147  case 4:
148  return m_eta;
149  break;
150  }
151 
152  return 0.;
153 }
154 
155 
157 {
158  switch (ipar) {
159  case 0:
160  m_qoverpt = val;
161  break;
162  case 1:
163  m_d0 = val;
164  break;
165  case 2:
166  m_phi = val;
167  break;
168  case 3:
169  m_z0 = val;
170  break;
171  case 4:
172  m_eta = val;
173  break;
174  }
175 }
176 
177 
178 ostream& operator<<(ostream& out, const FPGATrackSimTrack& track)
179 {
180 
181  out << "TRACK: ID=" << std::left << setw(8) << track.m_trackID;
182  out << " SECTOR1=" << std::left << setw(8) << track.m_firstSectorID;
183  out << " BANK=" << std::left << setw(8) << track.m_bankID;
184  out << " BARCODE=" << std::left << setw(6) << track.m_barcode;
185  out << " BARCODE_F=" << std::left << setw(9) << track.m_barcode_frac;
186  out << " EVENT=" << std::left << setw(6) << track.m_eventindex;
187  out << " HITMAP=" << std::left << setw(8) << track.getHitMap();
188  out << " TYPE=" << std::left << setw(3) << track.m_typemask;
189  out << " NMISS=" << std::left << setw(3) << track.getNMissing();
190  out << "\n";
191  streamsize oldprec = out.precision();
192  out.precision(4);
193  out << " PHI=" << std::left << setw(10) << track.m_phi;
194  out.setf(ios_base::scientific);
195  out.precision(2);
196  out << " Q/PT=" << std::left << setw(10) << track.m_qoverpt;
197  out.unsetf(ios_base::scientific);
198  out.precision(4);
199  out << " d0=" << std::left << setw(10) << track.m_d0;
200  out << " ETA=" << std::left << setw(10) << track.m_eta;
201  out << " z0=" << std::left << setw(10) << track.m_z0;
202  out << " Chi2=" << std::left << setw(12) << track.m_chi2;
203  out << " OChi2=" << std::left << setw(12) << track.m_origchi2;
204 
205  out << endl;
206  out.precision(oldprec);
207 
208  out << endl;
209 
210  // print the hits
211  int iter = 0;
212  for (const auto& hit : track.m_hits) {
213  out << "Hit " << iter << ": " << hit << "\n";
214  iter++;
215  }
216 
217  return out;
218 }
219 
220 
222 {
223  vector<FPGATrackSimMultiTruth> mtv;
224  mtv.reserve(m_hits.size());
225 
226  // don't loop over coordinates, since we only calculate truth *per hit* and not per coordinate, though hitmap is saved for coordinates, so be careful
227  for (const auto& thishit : m_hits)
228  {
229  if (thishit.isReal())
230  {
231  FPGATrackSimMultiTruth this_mt(thishit.getTruth());
232  this_mt.assign_equal_normalization();
233  if (thishit.isPixel())
234  for ( auto& x : this_mt)
235  x.second *= 2;
236  mtv.push_back(this_mt);
237  }
238  }
239 
240  // compute the best geant match, the barcode with the largest number of hits contributing to the track.
241  // frac is then the fraction of the total number of hits on the track attributed to the barcode.
245  const bool ok = mt.best(tbarcode, tfrac);
246  if (ok)
247  {
248  setEventIndex(tbarcode.first);
249  setBarcode(tbarcode.second);
250  setBarcodeFrac(tfrac);
251  }
252  else
253  {
254  setEventIndex(-1);
255  setBarcode(-1);
256  setBarcodeFrac(0);
257  }
258 }
259 
261 {
262  m_ORcode = code;
263 }
264 
265 
FPGATrackSimTrack::getPhiCoord
float getPhiCoord(int ilayer) const
Definition: FPGATrackSimTrack.cxx:67
FPGATrackSimTrack::calculateTruth
void calculateTruth()
Definition: FPGATrackSimTrack.cxx:221
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
FPGATrackSimTrack
Definition: FPGATrackSimTrack.h:18
FPGATrackSimMultiTruth::Weight
float Weight
Definition: FPGATrackSimMultiTruth.h:50
FPGATrackSimTrack::getCoords
std::vector< float > getCoords(unsigned ilayer) const
Definition: FPGATrackSimTrack.cxx:20
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
M_PI
#define M_PI
Definition: ActiveFraction.h:11
FPGATrackSimTrack::setPassedOR
void setPassedOR(unsigned int)
Definition: FPGATrackSimTrack.cxx:260
HitType::spacepoint
@ spacepoint
FPGATrackSimTrack::getNCoords
int getNCoords() const
Definition: FPGATrackSimTrack.cxx:90
x
#define x
FPGATrackSimTrack::setFPGATrackSimHit
void setFPGATrackSimHit(unsigned i, const FPGATrackSimHit &hit)
Definition: FPGATrackSimTrack.cxx:99
FPGATrackSimMultiTruth::best
bool best(FPGATrackSimMultiTruth::Barcode &code, FPGATrackSimMultiTruth::Weight &weight) const
Definition: FPGATrackSimMultiTruth.h:86
FPGATrackSimConstants.h
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
FPGATrackSimTrack::setPhi
void setPhi(float v, bool ForceRange=true)
Definition: FPGATrackSimTrack.cxx:116
operator<<
ostream & operator<<(ostream &out, const FPGATrackSimTrack &track)
Definition: FPGATrackSimTrack.cxx:178
computeIdealCoords
std::vector< float > computeIdealCoords(const FPGATrackSimHit &hit, const double hough_x, const double hough_y, const double target_r, const bool doDeltaGPhis, const TrackCorrType trackCorrType)
Definition: FPGATrackSimFunctions.cxx:116
histSizes.code
code
Definition: histSizes.py:129
lumiFormat.i
int i
Definition: lumiFormat.py:85
FPGATrackSimMultiTruth::Barcode
std::pair< unsigned long, unsigned long > Barcode
Definition: FPGATrackSimMultiTruth.h:49
FPGATrackSimTrack::getEtaCoord
float getEtaCoord(int ilayer) const
Definition: FPGATrackSimTrack.cxx:57
FPGATrackSimTrack::getParameter
float getParameter(int) const
Definition: FPGATrackSimTrack.cxx:132
FPGATrackSimTrack::setParameter
void setParameter(int, float)
Definition: FPGATrackSimTrack.cxx:156
FPGATrackSimMultiTruth
Definition: FPGATrackSimMultiTruth.h:46
FPGATrackSimMultiTruth::AddAccumulator
Definition: FPGATrackSimMultiTruth.h:57
TrackCorrType::None
@ None
FPGATrackSimFunctions.h
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
FPGATrackSimTrack::~FPGATrackSimTrack
virtual ~FPGATrackSimTrack()
Definition: FPGATrackSimTrack.cxx:18
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
FPGATrackSimTrack::setNLayers
void setNLayers(int)
set the number of layers in the track.
Definition: FPGATrackSimTrack.cxx:108
FPGATrackSimTrack::computeIdealCoords
std::vector< float > computeIdealCoords(unsigned ilayer) const
Definition: FPGATrackSimTrack.cxx:39
FPGATrackSimTrack.h
FPGATrackSimMultiTruth::assign_equal_normalization
void assign_equal_normalization()
Definition: FPGATrackSimMultiTruth.cxx:69