ATLAS Offline Software
Loading...
Searching...
No Matches
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
23
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//--------------------------------------------------------------------------------------------------
45struct ParSet : public std::array<double, FPGATrackSimTrackPars::NPARS> {
46 using array<double, FPGATrackSimTrackPars::NPARS>::array;
47 ParSet(const std::vector<double> &val);
48 operator const std::vector<double>() const;
49};
50struct IdxSet : public std::array<unsigned, FPGATrackSimTrackPars::NPARS> {
51 using array<unsigned, FPGATrackSimTrackPars::NPARS>::array;
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
57const IdxSet invalidBin{std::initializer_list<unsigned>({std::numeric_limits<unsigned>::max(),std::numeric_limits<unsigned>::max(),
58 std::numeric_limits<unsigned>::max(),std::numeric_limits<unsigned>::max(),std::numeric_limits<unsigned>::max()})};
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
65std::vector<unsigned> subVec(const std::vector<unsigned> &elems,
66 const IdxSet &invec);
67
68// Opposite of above subVec, this sets the subvector
69void 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)
76std::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>
80std::ostream &operator<<(std::ostream &os, const std::vector<unsigned> &idx);
81
82// Class for writing const files formatted for firmware
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
95private:
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
101struct 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;
108 static const unsigned invalidLayer = std::numeric_limits<unsigned>::max();
109};
110std::ostream &operator<<(std::ostream &os, const StoredHit &hit);
111
112
113//-------------------------------------------------------------------------------------------------------
114//
115// Geometry Helpers -- does basic helix calculations
116//
117//-------------------------------------------------------------------------------------------------------
119{
120public:
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
Scalar eta() const
pseudorapidity method
Scalar theta() const
theta method
: FPGATrackSim-specific class to represent an hit in the detector.
Structs that store the 5 track parameters.
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)
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)
static constexpr double A
IdxSet(const std::vector< unsigned > &val)
ParSet(const std::vector< double > &val)
StoredHit(const std::shared_ptr< const FPGATrackSimHit > &hit)
std::shared_ptr< const FPGATrackSimHit > hitptr
StreamManager(const std::string &setname)
std::map< std::string, std::fstream > m_map
void writeVar(const std::string &var, T val)