ATLAS Offline Software
FPGATrackSimBinUtil.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 #ifndef FPGATrackSimBinUtil_H
4 #define FPGATrackSimBinUtil_H
5 
24 #include <array>
25 #include <fstream>
26 #include <map>
27 #include <string>
28 #include <vector>
29 
33 
34 
36 
37 //--------------------------------------------------------------------------------------------------
38 //
39 // These just makes ParSet and IdxSet types that have 5 double or unsigned int
40 // for the 5-track parameters. The point of the structs is that they are fixed
41 // to the right length and can be converted back and forth to std::vector
42 // through cast operators and constructors
43 //
44 //--------------------------------------------------------------------------------------------------
45 struct ParSet : public std::array<double, FPGATrackSimTrackPars::NPARS> {
47  ParSet(const std::vector<double> &val);
48  operator const std::vector<double>() const;
49 };
50 struct IdxSet : public std::array<unsigned, FPGATrackSimTrackPars::NPARS> {
52  IdxSet(const std::vector<unsigned> &val);
53  operator const std::vector<unsigned>() const;
54 };
55 
56 // invalid bin value, there is no way a true bin could be there
59 
60 
61 // Generic Utility for splitting in vector (e.g. idx or #bins 5-d vectors)
62 // into subvectors (e.g. idx for just the scan parameters). Technically, for
63 // a list of parameter indices (elems) gives the subvector of the invec with
64 // just those indices
65 std::vector<unsigned> subVec(const std::vector<unsigned> &elems,
66  const IdxSet &invec);
67 
68 // Opposite of above subVec, this sets the subvector
69 void setIdxSubVec(IdxSet &idx, const std::vector<unsigned> &subvecelems,
70  const std::vector<unsigned> &subvecidx);
71 
72 // Makes are set of parameters corresponding to the corners specified by
73 // scanpars of the bin specified by idx e.g. if scan pars is (pT,d0) then the
74 // set is (low pT,low d0), (low pT, high d0), (high pT,low d0), (high pT, high
75 // d0)
76 std::vector<IdxSet> makeVariationSet(const std::vector<unsigned> &scanpars,
77  const IdxSet &idx);
78 
79 // this is needed by the stream manager below for outputing std::vector<unsigned>
80 std::ostream &operator<<(std::ostream &os, const std::vector<unsigned> &idx);
81 
82 // Class for writing const files formatted for firmware
83 struct StreamManager {
84  StreamManager(const std::string &setname) : m_setname(setname) {}
86  template <typename T> void writeVar(const std::string &var, T val) {
87  auto emplace_result = m_map.try_emplace(
88  var, m_setname + "_" + var + "_const.txt", std::ios_base::out);
89  if (!emplace_result.second) {
90  emplace_result.first->second << ",\n";
91  }
92  emplace_result.first->second << val;
93  }
94 
95 private:
96  std::string m_setname;
97  std::map<std::string, std::fstream> m_map;
98 };
99 
100 // Stores hit plus the phi/etashift from the nominal bin center
101 struct StoredHit {
102  StoredHit(const std::shared_ptr<const FPGATrackSimHit>& hit) : hitptr(hit), phiShift(0), etaShift(0), layer(-1) {}
103  std::shared_ptr<const FPGATrackSimHit> hitptr;
104  double phiShift; // shift in r-phi plane as quantified by BinDesc
105  double etaShift; // shift in r-z plane as quantified by BinDesc
106  unsigned layer;
107  double rzrad() const;
109 };
110 std::ostream &operator<<(std::ostream &os, const StoredHit &hit);
111 
112 
113 //-------------------------------------------------------------------------------------------------------
114 //
115 // Geometry Helpers -- does basic helix calculations
116 //
117 //-------------------------------------------------------------------------------------------------------
119 {
120 public:
121  // This is the constant needed to relate hit phi to track phi due to curvature
122  static constexpr double CurvatureConstant = fpgatracksim::A;
123 
124  // standard eta to theta calculation
125  static double ThetaFromEta(double eta);
126 
127  // standard theta to eta calculation
128  static double EtaFromTheta(double theta);
129 
130  // find the expected z position from the radius and track parameters
131  static double zFromPars(double r, const FPGATrackSimTrackPars &pars);
132 
133  // find the expected z position from the radius and track parameters
134  static double phiFromPars(double r, const FPGATrackSimTrackPars &pars);
135 
136  // find the track phi that would be consistent with the other track parameters and the hit (r,phi)
137  static double parsToTrkPhi(const FPGATrackSimTrackPars &pars, FPGATrackSimHit const *hit);
138 
139  // find the difference between the hit and trk phi as a function of r and track pars
140  static double dPhiHitTrkFromPars(double r, const FPGATrackSimTrackPars &pars);
141 
142  // for padding
143  static double dZdEta(double eta);
144  static double dPhidQOverPt(double hitr);
145 
146 };
147 
148 
149 }; // namespace FPGATrackSimBinUtil
150 
151 #endif // FPGATrackSimBinUtil_H
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
beamspotman.r
def r
Definition: beamspotman.py:674
beamspotnt.var
var
Definition: bin/beamspotnt.py:1393
FPGATrackSimBinUtil::operator<<
std::ostream & operator<<(std::ostream &os, const std::vector< unsigned > &idx)
Definition: FPGATrackSimBinUtil.cxx:120
FPGATrackSimBinUtil::StoredHit::hitptr
std::shared_ptr< const FPGATrackSimHit > hitptr
Definition: FPGATrackSimBinUtil.h:103
FPGATrackSimBinUtil::IdxSet::IdxSet
IdxSet(const std::vector< unsigned > &val)
Definition: FPGATrackSimBinUtil.cxx:30
FPGATrackSimBinUtil::StoredHit::StoredHit
StoredHit(const std::shared_ptr< const FPGATrackSimHit > &hit)
Definition: FPGATrackSimBinUtil.h:102
FPGATrackSimBinUtil::GeomHelpers
Definition: FPGATrackSimBinUtil.h:119
FPGATrackSimBinUtil::GeomHelpers::phiFromPars
static double phiFromPars(double r, const FPGATrackSimTrackPars &pars)
Definition: FPGATrackSimBinUtil.cxx:166
FPGATrackSimBinUtil::invalidBin
const IdxSet invalidBin
Definition: FPGATrackSimBinUtil.h:57
FPGATrackSimTrackPars
Definition: FPGATrackSimTrackPars.h:22
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
FPGATrackSimBinUtil::StoredHit::layer
unsigned layer
Definition: FPGATrackSimBinUtil.h:106
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
FPGATrackSimBinUtil::StreamManager::StreamManager
StreamManager(const std::string &setname)
Definition: FPGATrackSimBinUtil.h:84
FPGATrackSimBinUtil::StoredHit::rzrad
double rzrad() const
Definition: FPGATrackSimBinUtil.cxx:53
FPGATrackSimBinUtil::subVec
std::vector< unsigned > subVec(const std::vector< unsigned > &elems, const IdxSet &invec)
Definition: FPGATrackSimBinUtil.cxx:61
FPGATrackSimBinUtil::GeomHelpers::dPhidQOverPt
static double dPhidQOverPt(double hitr)
Definition: FPGATrackSimBinUtil.cxx:185
FPGATrackSimConstants.h
FPGATrackSimBinUtil::StreamManager::m_setname
std::string m_setname
Definition: FPGATrackSimBinUtil.h:96
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
FPGATrackSimBinUtil::GeomHelpers::dPhiHitTrkFromPars
static double dPhiHitTrkFromPars(double r, const FPGATrackSimTrackPars &pars)
Definition: FPGATrackSimBinUtil.cxx:162
FPGATrackSimBinUtil::GeomHelpers::ThetaFromEta
static double ThetaFromEta(double eta)
Definition: FPGATrackSimBinUtil.cxx:138
FPGATrackSimBinUtil::GeomHelpers::CurvatureConstant
static constexpr double CurvatureConstant
Definition: FPGATrackSimBinUtil.h:122
FPGATrackSimBinUtil::StreamManager
Definition: FPGATrackSimBinUtil.h:83
FPGATrackSimBinUtil::ParSet
Definition: FPGATrackSimBinUtil.h:45
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
FPGATrackSimBinUtil::GeomHelpers::parsToTrkPhi
static double parsToTrkPhi(const FPGATrackSimTrackPars &pars, FPGATrackSimHit const *hit)
Definition: FPGATrackSimBinUtil.cxx:171
FPGATrackSimBinUtil::setIdxSubVec
void setIdxSubVec(IdxSet &idx, const std::vector< unsigned > &subvecelems, const std::vector< unsigned > &subvecidx)
Definition: FPGATrackSimBinUtil.cxx:70
lumiFormat.array
array
Definition: lumiFormat.py:91
FPGATrackSimBinUtil::StoredHit::invalidLayer
static const unsigned invalidLayer
Definition: FPGATrackSimBinUtil.h:108
FPGATrackSimBinUtil::GeomHelpers::EtaFromTheta
static double EtaFromTheta(double theta)
Definition: FPGATrackSimBinUtil.cxx:143
FPGATrackSimBinUtil::makeVariationSet
std::vector< IdxSet > makeVariationSet(const std::vector< unsigned > &scanpars, const IdxSet &idx)
Definition: FPGATrackSimBinUtil.cxx:93
FPGATrackSimBinUtil::StoredHit
Definition: FPGATrackSimBinUtil.h:101
FPGATrackSimHit.h
: FPGATrackSim-specific class to represent an hit in the detector.
FPGATrackSimBinUtil::StreamManager::~StreamManager
~StreamManager()
Definition: FPGATrackSimBinUtil.cxx:113
FPGATrackSimBinUtil::StreamManager::m_map
std::map< std::string, std::fstream > m_map
Definition: FPGATrackSimBinUtil.h:97
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
FPGATrackSimBinUtil::GeomHelpers::dZdEta
static double dZdEta(double eta)
Definition: FPGATrackSimBinUtil.cxx:179
FPGATrackSimBinUtil::GeomHelpers::zFromPars
static double zFromPars(double r, const FPGATrackSimTrackPars &pars)
Definition: FPGATrackSimBinUtil.cxx:151
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
FPGATrackSimBinUtil::StreamManager::writeVar
void writeVar(const std::string &var, T val)
Definition: FPGATrackSimBinUtil.h:86
FPGATrackSimBinUtil::StoredHit::etaShift
double etaShift
Definition: FPGATrackSimBinUtil.h:105
FPGATrackSimBinUtil::StoredHit::phiShift
double phiShift
Definition: FPGATrackSimBinUtil.h:104
FPGATrackSimBinUtil::ParSet::ParSet
ParSet(const std::vector< double > &val)
Definition: FPGATrackSimBinUtil.cxx:19
FPGATrackSimBinUtil::IdxSet
Definition: FPGATrackSimBinUtil.h:50
FPGATrackSimTrackPars.h
Structs that store the 5 track parameters.
FPGATrackSimBinUtil
Definition: FPGATrackSimBinUtil.h:35