ATLAS Offline Software
Loading...
Searching...
No Matches
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>
13using namespace std;
14
15// first stage only
16
17// We need a destructor apparently?
19
20std::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
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
39std::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
57float 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
67float 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)
115void 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
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
155void FPGATrackSimTrack::setParameter(int ipar, float val)
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
177ostream& 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());
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.
241 FPGATrackSimMultiTruth mt(std::accumulate(mtv.begin(), mtv.end(), FPGATrackSimMultiTruth(), FPGATrackSimMultiTruth::AddAccumulator()));
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);
256 }
257}
258
259void FPGATrackSimTrack::setPassedOR(unsigned int code)
260{
261 m_ORcode = code;
262}
263
264
#define M_PI
Scalar phi() const
phi method
#define x
bool best(FPGATrackSimMultiTruth::Barcode &code, FPGATrackSimMultiTruth::Weight &weight) const
std::pair< unsigned long, unsigned long > Barcode
void setParameter(int, float)
TrackCorrType m_trackCorrType
void setPassedOR(unsigned int)
void setEventIndex(const signed long &v)
float getHoughX() const
float getEtaCoord(int ilayer) const
void setPhi(float v, bool ForceRange=true)
std::vector< float > getCoords(unsigned ilayer) const
void setBarcode(const HepMcParticleLink::barcode_type &v)
float getHoughY() const
std::vector< double > m_idealRadii
void setBarcodeFrac(const float &v)
std::vector< float > computeIdealCoords(unsigned ilayer) const
void setNLayers(int)
set the number of layers in the track.
std::vector< FPGATrackSimHit > m_hits
void setFPGATrackSimHit(unsigned i, const FPGATrackSimHit &hit)
float getPhiCoord(int ilayer) const
FPGATrackSimTrack()=default
float getParameter(int) const
STL namespace.
ostream & operator<<(ostream &s, const SG::VarHandleKey &m)