ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimBinUtil.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
9
12
13
14namespace FPGATrackSimBinUtil {
15
16// ----------------------------------------------------------------------------------------
17// IdxSet and ParSet implementations
18// ----------------------------------------------------------------------------------------
19ParSet::ParSet(const std::vector<double> &val) {
20 if (val.size() != 5) {
21 throw std::invalid_argument(
22 "Not enough parameters in ParSet initialization");
23 }
24 std::copy(val.begin(), val.end(), this->begin());
25}
26ParSet::operator const std::vector<double>() const {
27 return std::vector<double>(this->begin(), this->end());
28}
29
30IdxSet::IdxSet(const std::vector<unsigned> &val) {
31 if (val.size() != 5) {
32 throw std::invalid_argument(
33 "Not enough parameters in IdxSet initialization");
34 }
35 std::copy(val.begin(), val.end(), this->begin());
36}
37IdxSet::operator const std::vector<unsigned>() const {
38 return std::vector<unsigned>(this->begin(), this->end());
39}
40
41// ----------------------------------------------------------------------------------------
42// StoredHit implementations
43// ----------------------------------------------------------------------------------------
44std::ostream& operator<<(std::ostream &os, const StoredHit &hit)
45{
46 os << " lyr: " << hit.layer << " ";
47 os << " hash: " << hit.hitptr->getIdentifierHash() << " ";
48 os << "(" << hit.hitptr->getR() << ", " << hit.hitptr->getGPhi() << ", " << hit.hitptr->getZ() << ") ";
49 os << "[" << hit.phiShift << ", " << hit.etaShift << "]";
50 return os;
51}
52
53double StoredHit::rzrad() const {
54 return sqrt(hitptr->getR()*hitptr->getR()+hitptr->getZ()*hitptr->getZ());
55}
56
57
58// ----------------------------------------------------------------------------------------
59// SubVec implementations
60// ----------------------------------------------------------------------------------------
61std::vector<unsigned> subVec(const std::vector<unsigned> &elems,
62 const IdxSet &invec) {
63 std::vector<unsigned> retv;
64 for (auto elem : elems) {
65 retv.push_back(invec[elem]);
66 }
67 return retv;
68}
69
70void setIdxSubVec(IdxSet &idx, const std::vector<unsigned> &subvecelems,
71 const std::vector<unsigned> &subvecidx) {
72
73 if (subvecelems.size() != subvecidx.size()) {
74 throw std::invalid_argument(
75 "Setting FPGATrackSimGenScanBinningBase::setIdxSubVec with mismatched "
76 "sizes");
77 }
78
79 for (unsigned i = 0; i < subvecelems.size(); i++) {
80 if (subvecelems[i] >= idx.size()) {
81 throw std::invalid_argument(
82 "FPGATrackSimGenScanBinningBase::setIdxSubVec input out of range");
83 }
84 idx[subvecelems[i]] = subvecidx[i];
85 }
86}
87
88// ----------------------------------------------------------------------------------------
89// makeVariationSet implementation
90// ----------------------------------------------------------------------------------------
91// This gives a list tracks parameters for the corners of bin of dimensions
92// scanpars.size()
93std::vector<IdxSet> makeVariationSet(const std::vector<unsigned> &scanpars,
94 const IdxSet &idx) {
95 std::vector<IdxSet> retv;
96 for (unsigned corners = 0; corners < unsigned((1 << scanpars.size()));
97 corners++) {
98 IdxSet newidx = idx;
99 int scanDimCnt = 0;
100 for (auto &par : scanpars) {
101 newidx[par] = idx[par] + ((corners >> scanDimCnt) & 1);
102 scanDimCnt++;
103 }
104 retv.push_back(newidx);
105 }
106 return retv;
107}
108
109// ----------------------------------------------------------------------------------------
110// StreamManager implementation
111// ----------------------------------------------------------------------------------------
112// Class for writing const files formatted for firmware
114 for (auto &f : m_map) {
115 f.second << "\n";
116 }
117}
118
119// FW constants writer
120std::ostream &operator<<(std::ostream &os, const std::vector<unsigned>& idx) {
121 bool first = true;
122 for (auto &val : idx) {
123 if (!first)
124 os << ",";
125 os << val;
126 first = false;
127 }
128 return os;
129}
130
131
132
133//-------------------------------------------------------------------------------------------------------
134//
135// Geometry Helpers -- does basic helix calculations
136//
137//-------------------------------------------------------------------------------------------------------
139{
140 return 2.0 * atan(exp(-1.0 * eta));
141}
142
144{
145 return -log(tan(theta / 2.0));
146}
147
148
149
150
152{
153 double theta = ThetaFromEta(pars.eta);
154 double zhit = pars.z0 + r / tan(theta);
155 if (std::abs(pars.qOverPt) > 0)
156 {
157 zhit = pars.z0 + 1.0 / tan(theta) * asin(r * CurvatureConstant * pars.qOverPt) / (CurvatureConstant * pars.qOverPt);
158 }
159 return zhit;
160}
161
163 return asin(r * CurvatureConstant * pars.qOverPt - pars.d0 / r);
164}
165
167 double phi_hit = xAOD::P4Helpers::deltaPhi(pars.phi,dPhiHitTrkFromPars(r,pars));
168 return phi_hit;
169}
170
172{
173 double r = hit->getR(); // mm
174 double phi_hit = hit->getGPhi(); // radians
175 double phi_trk = xAOD::P4Helpers::deltaPhi(phi_hit,dPhiHitTrkFromPars(r,pars));
176 return phi_trk;
177}
178
180{
181 // dtheta/deta = -sin(theta)
182 return -1.0/std::sin(ThetaFromEta(eta));
183}
184
185double GeomHelpers::dPhidQOverPt(double hitr)
186{
187 // full answer = rA/cos(dphi)
188 // approx answer = rA b/c dphi is small (~0.4 max)
189 return hitr*CurvatureConstant;
190}
191
192} // namespace FPGATrackSimBinUtil
Scalar eta() const
pseudorapidity method
Scalar theta() const
theta method
Binning Utilities for GenScanTool.
static double parsToTrkPhi(const FPGATrackSimTrackPars &pars, FPGATrackSimHit const *hit)
static double dPhiHitTrkFromPars(double r, const FPGATrackSimTrackPars &pars)
static double phiFromPars(double r, const FPGATrackSimTrackPars &pars)
static double ThetaFromEta(double eta)
static constexpr double CurvatureConstant
static double zFromPars(double r, const FPGATrackSimTrackPars &pars)
static double dPhidQOverPt(double hitr)
static double EtaFromTheta(double theta)
unsigned getIdentifierHash() const
float getGPhi() const
float getZ() const
float getR() const
int r
Definition globals.cxx:22
std::vector< IdxSet > makeVariationSet(const std::vector< unsigned > &scanpars, const IdxSet &idx)
std::vector< unsigned > subVec(const std::vector< unsigned > &elems, const IdxSet &invec)
std::ostream & operator<<(std::ostream &os, const std::vector< unsigned > &idx)
void setIdxSubVec(IdxSet &idx, const std::vector< unsigned > &subvecelems, const std::vector< unsigned > &subvecidx)
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
IdxSet(const std::vector< unsigned > &val)
ParSet(const std::vector< double > &val)
std::shared_ptr< const FPGATrackSimHit > hitptr
std::map< std::string, std::fstream > m_map