ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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].getEtaIndex());
29  coords.push_back(m_hits[ilayer].getPhiIndex());
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  // If this is a spacepoint, and if this is the "outer" hit on a strip module
70  // (side = 1) then we actually return the z/eta coord.
71  // Since spacepoints are duplicated, this avoids using the same phi coord
72  // twice and alsp avoids having to teach the code that strip spacepoints are
73  // "2D" hits despite being in the strips, which everything assumes is 1D.
74  // This makes it easy to mix and match spacepoints with strip hits that aren't
75  // spacepoints (since the number of strip layers is held fixed).
76  unsigned target_coord = 1;
77  if (m_hits[ilayer].getHitType() == HitType::spacepoint && (m_hits[ilayer].getPhysLayer() % 2) == 1) {
78  target_coord = 0;
79  }
80 
81  if (coords.size() > target_coord) {
82  return coords.at(target_coord);
83  }
84  else {
85  throw std::range_error("FPGATrackSimTrack::getCoord(layer,coord) out of bounds");
86  }
87 }
88 
90  int nCoords = 0;
91  for (const auto& hit : m_hits) {
92  nCoords += hit.getDim();
93  }
94  return nCoords;
95 }
96 
97 //set a specific position in m_hits
99 {
100  if (m_hits.size() > i)
101  m_hits[i] = hit;
102  else
103  throw std::range_error("FPGATrackSimTrack::setFPGATrackSimHit() out of bounds");
104 }
105 
108 {
109  if (m_hits.size() > 0) m_hits.clear();
110  m_hits.resize(dim);
111 }
112 
113 
114 // if ForceRange==true, then phi = [-pi..pi)
115 void FPGATrackSimTrack::setPhi(float phi, bool ForceRange) {
116  if (ForceRange) {
117  // when phi is ridiculously large, there is no point in adjusting it
118  if (std::abs(phi) > 100) {
119  if (m_chi2 < 100) { // this is a BAD track, so fail it if chi2 hasn't done so already
120  m_chi2 += 100; // we want to fail this event anyway
121  }
122  }
123  else {
124  while (phi >= M_PI) phi -= (2. * M_PI);
125  while (phi < -M_PI) phi += (2. * M_PI);
126  }
127  }
128  m_phi = phi;
129 }
130 
131 float FPGATrackSimTrack::getParameter(int ipar) const
132 {
133  switch (ipar) {
134  case 0:
135  return m_qoverpt;
136  break;
137  case 1:
138  return m_d0;
139  break;
140  case 2:
141  return m_phi;
142  break;
143  case 3:
144  return m_z0;
145  break;
146  case 4:
147  return m_eta;
148  break;
149  }
150 
151  return 0.;
152 }
153 
154 
156 {
157  switch (ipar) {
158  case 0:
159  m_qoverpt = val;
160  break;
161  case 1:
162  m_d0 = val;
163  break;
164  case 2:
165  m_phi = val;
166  break;
167  case 3:
168  m_z0 = val;
169  break;
170  case 4:
171  m_eta = val;
172  break;
173  }
174 }
175 
176 
177 ostream& operator<<(ostream& out, const FPGATrackSimTrack& track)
178 {
179 
180  out << "TRACK: ID=" << std::left << setw(8) << track.m_trackID;
181  out << " SECTOR1=" << std::left << setw(8) << track.m_firstSectorID;
182  out << " BANK=" << std::left << setw(8) << track.m_bankID;
183  out << " BARCODE=" << std::left << setw(6) << track.m_barcode;
184  out << " BARCODE_F=" << std::left << setw(9) << track.m_barcode_frac;
185  out << " EVENT=" << std::left << setw(6) << track.m_eventindex;
186  out << " HITMAP=" << std::left << setw(8) << track.getHitMap();
187  out << " TYPE=" << std::left << setw(3) << track.m_typemask;
188  out << " NMISS=" << std::left << setw(3) << track.getNMissing();
189  out << "\n";
190  streamsize oldprec = out.precision();
191  out.precision(4);
192  out << " PHI=" << std::left << setw(10) << track.m_phi;
193  out.setf(ios_base::scientific);
194  out.precision(2);
195  out << " Q/PT=" << std::left << setw(10) << track.m_qoverpt;
196  out.unsetf(ios_base::scientific);
197  out.precision(4);
198  out << " d0=" << std::left << setw(10) << track.m_d0;
199  out << " ETA=" << std::left << setw(10) << track.m_eta;
200  out << " z0=" << std::left << setw(10) << track.m_z0;
201  out << " Chi2=" << std::left << setw(12) << track.m_chi2;
202  out << " OChi2=" << std::left << setw(12) << track.m_origchi2;
203 
204  out << endl;
205  out.precision(oldprec);
206 
207  out << endl;
208 
209  // print the hits
210  int iter = 0;
211  for (const auto& hit : track.m_hits) {
212  out << "Hit " << iter << ": " << hit << "\n";
213  iter++;
214  }
215 
216  return out;
217 }
218 
219 
221 {
222  vector<FPGATrackSimMultiTruth> mtv;
223  mtv.reserve(m_hits.size());
224 
225  // 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
226  for (const auto& thishit : m_hits)
227  {
228  if (thishit.isReal())
229  {
230  FPGATrackSimMultiTruth this_mt(thishit.getTruth());
231  this_mt.assign_equal_normalization();
232  if (thishit.isPixel())
233  for ( auto& x : this_mt)
234  x.second *= 2;
235  mtv.push_back(this_mt);
236  }
237  }
238 
239  // compute the best geant match, the barcode with the largest number of hits contributing to the track.
240  // frac is then the fraction of the total number of hits on the track attributed to the barcode.
244  const bool ok = mt.best(tbarcode, tfrac);
245  if (ok)
246  {
247  setEventIndex(tbarcode.first);
248  setBarcode(tbarcode.second);
249  setBarcodeFrac(tfrac);
250  }
251  else
252  {
253  setEventIndex(-1);
254  setBarcode(-1);
255  setBarcodeFrac(0);
256  }
257 }
258 
260 {
261  m_ORcode = code;
262 }
263 
264 
FPGATrackSimTrack::getPhiCoord
float getPhiCoord(int ilayer) const
Definition: FPGATrackSimTrack.cxx:67
FPGATrackSimTrack::calculateTruth
void calculateTruth()
Definition: FPGATrackSimTrack.cxx:220
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:259
HitType::spacepoint
@ spacepoint
FPGATrackSimTrack::getNCoords
int getNCoords() const
Definition: FPGATrackSimTrack.cxx:89
x
#define x
FPGATrackSimTrack::setFPGATrackSimHit
void setFPGATrackSimHit(unsigned i, const FPGATrackSimHit &hit)
Definition: FPGATrackSimTrack.cxx:98
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:115
operator<<
ostream & operator<<(ostream &out, const FPGATrackSimTrack &track)
Definition: FPGATrackSimTrack.cxx:177
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:131
FPGATrackSimTrack::setParameter
void setParameter(int, float)
Definition: FPGATrackSimTrack.cxx:155
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:513
FPGATrackSimTrack::setNLayers
void setNLayers(int)
set the number of layers in the track.
Definition: FPGATrackSimTrack.cxx:107
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