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