ATLAS Offline Software
FPGATrackSimKeyLayerBinDesc.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 #ifndef FPGATrackSimKeyLayerBinDesc_H
4 #define FPGATrackSimKeyLayerBinDesc_H
5 
25 
31 
32 
34 
35 #include <cmath>
36 #include <initializer_list>
37 #include <string>
38 #include <vector>
39 
41 
42 class FPGATrackSimKeyLayerBinDesc : public extends<AthAlgTool, IFPGATrackSimBinDesc> {
43 
44 public:
46  using base_class::base_class;
47 
48  virtual StatusCode initialize() override;
49 
50  virtual const std::string &parNames(unsigned i) const override { return m_parNames[i]; }
51 
52  // convert back and forth from pT, eta, phi, d0, z0 and internal paramater set
53  virtual const FPGATrackSimBinUtil::ParSet
54  trackParsToParSet(const FPGATrackSimTrackPars &pars) const override {
56  if (m_fieldCorrection) {
57  keypars.phi1+=fieldCorrection(m_fieldCorRegion, pars.qOverPt/1000.0 ,m_keylyrtool.R1());
58  keypars.phi2+=fieldCorrection(m_fieldCorRegion, pars.qOverPt/1000.0 ,m_keylyrtool.R2());
59  }
60  keypars.phi1=remainder(keypars.phi1+m_phiOffset,2*M_PI);
61  keypars.phi2=remainder(keypars.phi2+m_phiOffset,2*M_PI);
62  return keyparsToParSet(keypars);
63  }
64 
65 
66 
67  virtual const FPGATrackSimTrackPars parSetToTrackPars(const FPGATrackSimBinUtil::ParSet &parset) const override {
69  keypars.phi1=remainder(keypars.phi1-m_phiOffset,2*M_PI);
70  keypars.phi2=remainder(keypars.phi2-m_phiOffset,2*M_PI);
71  return m_keylyrtool.keyParsToTrackPars(keypars);
72  }
73 
74  // calculate the distance in phi or eta from a track defined by parset to a
75  // hit these can be implemented as any variable in the r-phi or r-eta plane
76  // (not necessarily eta and phi).
77  virtual double phiResidual(const FPGATrackSimBinUtil::ParSet &parset, FPGATrackSimHit const *hit) const override {
78  return m_keylyrtool.deltaX(parSetToKeyPars(parset), hit->getR(), hit->getGPhi() + m_phiOffset);
79  }
80 
81  virtual double etaResidual(const FPGATrackSimBinUtil::ParSet &parset, FPGATrackSimHit const *hit) const override {
82  return hit->getZ()- m_keylyrtool.zExpected(parSetToKeyPars(parset),hit->getR());
83  }
84 
85  // figure out if step is r-phi or r-eta plan
86  bool stepIsRPhi(const FPGATrackSimBinStep &step) const;
87  bool stepIsREta(const FPGATrackSimBinStep &step) const;
88 
89  // idx should be with the definition specifed in the step
90  // NOTE: the stored hit may be modified!
92  FPGATrackSimBinUtil::StoredHit &storedhit) const override;
93 
94 
95  // Structs to hold firmware LUTs for one bin
96  // This allows the firmware calculation to be exactly reproduced
97  // here and comapared to the original/main algorithm
98  struct phiLUTConsts {
99  double r_in;
100  double r_out;
101  double y;
102  double x1p;
103  double y1p;
104  double cosb;
105  double sinb;
106  double x_m;
107  double x_factor;
108  double w_x;
109  double w_in;
110  double dw_dr;
111  double phiShift(double phi, double r);
112  double phiWindow(double r);
113  };
114  struct etaLUTConsts {
115  double r_in;
116  double r_out;
117  double z_in;
118  double dz_dr;
119  double w_in;
120  double dw_dr;
121  double etaShift(double z, double r);
122  double etaWindow(double r);
123  };
124  phiLUTConsts getPhiLUTConsts(const FPGATrackSimBinStep &step, const std::vector<unsigned>& idx) const;
125  etaLUTConsts getEtaLUTConsts(const FPGATrackSimBinStep &step, const std::vector<unsigned>& idx) const;
126 
127 
128  // Write the relevant LUT tables for firmware
129  virtual void writeLUTs(const FPGATrackSimBinStep &step) const override;
130 
131 
132  private:
133  // Configurable Properties
134  Gaudi::Property<double> m_rin{this, "rin", {-1.0}, "Radius of inner layer for keylayer definition"};
135  Gaudi::Property<double> m_rout{this, "rout", {-1.0}, "Radius of outer layer for keylayer definition"};
136  Gaudi::Property<bool> m_approxMath{this, "approxMath", {false}, "Use approximate math to emulate possible firmware"};
137  Gaudi::Property<double> m_d0pad{this, "D0Pad", 0.0, "Extra phi padding from d0 resolution"};
138  Gaudi::Property<double> m_phipad{this, "PhiPad", 0.0, "Extra phi padding from phi resolution"};
139  Gaudi::Property<double> m_qptpad{this, "QPtPad", 0.0, "Extra phi padding from q/pT resolution"};
140  Gaudi::Property<double> m_z0pad{this, "Z0Pad", 0.0, "Extra eta padding from z0 resolution"};
141  Gaudi::Property<double> m_etapad{this, "EtaPad", 0.0, "Extra eta padding from eta resolution"};
142  Gaudi::Property<unsigned> m_region{this, "region", 0, "Region number, needed to write out lookup tables for test vectors"};
143  Gaudi::Property<std::vector<double>> m_slPerEtaMod{
144  this,
145  "slPerEtaMod",
146  std::vector<double>{19.0, 24.0, 29.0, 32.0, 18.1, 27.1, 24.1, 15.1, 30.8,
147  30.8, 26.2, 32.2, 32.2, 26.2, 54.6, 54.6, 40.2, 60.2},
148  "Strip length per eta eta mod"
149  };
150 
151  Gaudi::Property<double> m_phiOffset{this, "PhiOffset", 0.0, "Phi offset between local and global parameters (avoids phi wrap around effects in region code)"};
152 
153  Gaudi::Property<unsigned> m_fieldCorRegion { this, "fieldCorRegion", 2, "region for fieldCorrection"};
154  Gaudi::Property<bool> m_fieldCorrection {this, "fieldCorrection", true, "Use magnetic field correction for Hough transform"};
155 
156 
157  // convert to/from the KeyLyrPars struct and the ParSet
159  return FPGATrackSimBinUtil::ParSet({keypars.z1,keypars.z2,keypars.phi1,keypars.phi2,keypars.xm});
160  }
163  }
164 
165  // Internal
167  const std::vector<std::string> m_parNames{"zR1", "zR2", "phiR1", "phiR2", "xm"};
168 
169  const std::vector<unsigned> m_phipars{2, 3, 4};
170  const std::vector<unsigned> m_etapars{0, 1};
171 
172 };
173 
174 
175 #endif // FPGATrackSimKeyLayerBinDesc_H
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
FPGATrackSimKeyLayerBinDesc::parNames
virtual const std::string & parNames(unsigned i) const override
Definition: FPGATrackSimKeyLayerBinDesc.h:50
beamspotman.r
def r
Definition: beamspotman.py:672
FPGATrackSimKeyLayerBinDesc::m_etapars
const std::vector< unsigned > m_etapars
Definition: FPGATrackSimKeyLayerBinDesc.h:170
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::x1p
double x1p
Definition: FPGATrackSimKeyLayerBinDesc.h:102
FPGATrackSimKeyLayerBinDesc::etaLUTConsts::r_in
double r_in
Definition: FPGATrackSimKeyLayerBinDesc.h:115
FPGATrackSimBinStep
Definition: FPGATrackSimBinStep.h:45
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
AthMsgStreamMacros.h
FPGATrackSimTrackPars
Definition: FPGATrackSimTrackPars.h:22
FPGATrackSimKeyLayerTool.h
Binning Classes for BinTool.
FPGATrackSimKeyLayerTool::R2
double R2() const
Definition: FPGATrackSimKeyLayerTool.h:99
FPGATrackSimKeyLayerBinDesc::etaResidual
virtual double etaResidual(const FPGATrackSimBinUtil::ParSet &parset, FPGATrackSimHit const *hit) const override
Definition: FPGATrackSimKeyLayerBinDesc.h:81
FPGATrackSimKeyLayerBinDesc::m_fieldCorRegion
Gaudi::Property< unsigned > m_fieldCorRegion
Definition: FPGATrackSimKeyLayerBinDesc.h:153
FPGATrackSimKeyLayerBinDesc::etaLUTConsts::etaWindow
double etaWindow(double r)
Definition: FPGATrackSimKeyLayerBinDesc.cxx:246
M_PI
#define M_PI
Definition: ActiveFraction.h:11
FPGATrackSimKeyLayerBinDesc::getPhiLUTConsts
phiLUTConsts getPhiLUTConsts(const FPGATrackSimBinStep &step, const std::vector< unsigned > &idx) const
Definition: FPGATrackSimKeyLayerBinDesc.cxx:175
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::dw_dr
double dw_dr
Definition: FPGATrackSimKeyLayerBinDesc.h:110
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::x_m
double x_m
Definition: FPGATrackSimKeyLayerBinDesc.h:106
FPGATrackSimKeyLayerBinDesc::m_rout
Gaudi::Property< double > m_rout
Definition: FPGATrackSimKeyLayerBinDesc.h:135
FPGATrackSimKeyLayerBinDesc::keyparsToParSet
FPGATrackSimBinUtil::ParSet keyparsToParSet(const FPGATrackSimKeyLayerTool::KeyLyrPars &keypars) const
Definition: FPGATrackSimKeyLayerBinDesc.h:158
FPGATrackSimKeyLayerBinDesc::m_parNames
const std::vector< std::string > m_parNames
Definition: FPGATrackSimKeyLayerBinDesc.h:167
FPGATrackSimKeyLayerTool::KeyLyrPars::xm
double xm
Definition: FPGATrackSimKeyLayerTool.h:55
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::w_in
double w_in
Definition: FPGATrackSimKeyLayerBinDesc.h:109
FPGATrackSimKeyLayerBinDesc::m_etapad
Gaudi::Property< double > m_etapad
Definition: FPGATrackSimKeyLayerBinDesc.h:141
FPGATrackSimKeyLayerBinDesc::parSetToTrackPars
virtual const FPGATrackSimTrackPars parSetToTrackPars(const FPGATrackSimBinUtil::ParSet &parset) const override
Definition: FPGATrackSimKeyLayerBinDesc.h:67
FPGATrackSimKeyLayerBinDesc::getEtaLUTConsts
etaLUTConsts getEtaLUTConsts(const FPGATrackSimBinStep &step, const std::vector< unsigned > &idx) const
Definition: FPGATrackSimKeyLayerBinDesc.cxx:209
FPGATrackSimKeyLayerBinDesc::m_phiOffset
Gaudi::Property< double > m_phiOffset
Definition: FPGATrackSimKeyLayerBinDesc.h:151
FPGATrackSimKeyLayerTool::KeyLyrPars::phi2
double phi2
Definition: FPGATrackSimKeyLayerTool.h:54
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
FPGATrackSimKeyLayerTool
Definition: FPGATrackSimKeyLayerTool.h:42
FPGATrackSimHit::getGPhi
float getGPhi() const
Definition: FPGATrackSimHit.h:153
FPGATrackSimKeyLayerBinDesc::etaLUTConsts::etaShift
double etaShift(double z, double r)
Definition: FPGATrackSimKeyLayerBinDesc.cxx:243
FPGATrackSimKeyLayerBinDesc::m_phipars
const std::vector< unsigned > m_phipars
Definition: FPGATrackSimKeyLayerBinDesc.h:169
FPGATrackSimKeyLayerBinDesc::phiLUTConsts
Definition: FPGATrackSimKeyLayerBinDesc.h:98
FPGATrackSimKeyLayerBinDesc::m_phipad
Gaudi::Property< double > m_phipad
Definition: FPGATrackSimKeyLayerBinDesc.h:138
lumiFormat.i
int i
Definition: lumiFormat.py:85
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::r_out
double r_out
Definition: FPGATrackSimKeyLayerBinDesc.h:100
z
#define z
FPGATrackSimKeyLayerBinDesc::etaLUTConsts::z_in
double z_in
Definition: FPGATrackSimKeyLayerBinDesc.h:117
FPGATrackSimKeyLayerBinDesc::hitInBin
virtual bool hitInBin(const FPGATrackSimBinStep &step, const FPGATrackSimBinUtil::IdxSet &idx, FPGATrackSimBinUtil::StoredHit &storedhit) const override
Definition: FPGATrackSimKeyLayerBinDesc.cxx:41
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FPGATrackSimKeyLayerBinDesc::m_qptpad
Gaudi::Property< double > m_qptpad
Definition: FPGATrackSimKeyLayerBinDesc.h:139
AthAlgTool.h
FPGATrackSimKeyLayerBinDesc::m_d0pad
Gaudi::Property< double > m_d0pad
Definition: FPGATrackSimKeyLayerBinDesc.h:137
FPGATrackSimKeyLayerBinDesc::m_rin
Gaudi::Property< double > m_rin
Definition: FPGATrackSimKeyLayerBinDesc.h:134
FPGATrackSimKeyLayerBinDesc::etaLUTConsts
Definition: FPGATrackSimKeyLayerBinDesc.h:114
FPGATrackSimKeyLayerBinDesc::etaLUTConsts::dz_dr
double dz_dr
Definition: FPGATrackSimKeyLayerBinDesc.h:118
FPGATrackSimKeyLayerBinDesc::stepIsREta
bool stepIsREta(const FPGATrackSimBinStep &step) const
Definition: FPGATrackSimKeyLayerBinDesc.cxx:159
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::x_factor
double x_factor
Definition: FPGATrackSimKeyLayerBinDesc.h:107
FPGATrackSimBinUtil::ParSet
Definition: FPGATrackSimBinUtil.h:45
FPGATrackSimKeyLayerTool::KeyLyrPars::z2
double z2
Definition: FPGATrackSimKeyLayerTool.h:52
FPGATrackSimHit::getZ
float getZ() const
Definition: FPGATrackSimHit.h:151
FPGATrackSimKeyLayerTool::KeyLyrPars::phi1
double phi1
Definition: FPGATrackSimKeyLayerTool.h:53
FPGATrackSimKeyLayerTool::trackParsToKeyPars
KeyLyrPars trackParsToKeyPars(const FPGATrackSimTrackPars &pars) const
Definition: FPGATrackSimKeyLayerTool.cxx:53
FPGATrackSimKeyLayerBinDesc::m_approxMath
Gaudi::Property< bool > m_approxMath
Definition: FPGATrackSimKeyLayerBinDesc.h:136
FPGATrackSimBinUtil::StoredHit
Definition: FPGATrackSimBinUtil.h:101
remainder
std::vector< std::string > remainder(const std::vector< std::string > &v1, const std::vector< std::string > &v2)
Definition: compareFlatTrees.cxx:44
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::sinb
double sinb
Definition: FPGATrackSimKeyLayerBinDesc.h:105
IFPGATrackSimBinDesc.h
Defines Parameters used for binning.
FPGATrackSimFunctions.h
FPGATrackSimHit.h
: FPGATrackSim-specific class to represent an hit in the detector.
FPGATrackSimKeyLayerBinDesc::trackParsToParSet
virtual const FPGATrackSimBinUtil::ParSet trackParsToParSet(const FPGATrackSimTrackPars &pars) const override
Definition: FPGATrackSimKeyLayerBinDesc.h:54
FPGATrackSimKeyLayerBinDesc
Definition: FPGATrackSimKeyLayerBinDesc.h:42
FPGATrackSimKeyLayerTool::R1
double R1() const
Definition: FPGATrackSimKeyLayerTool.h:98
FPGATrackSimKeyLayerBinDesc::phiResidual
virtual double phiResidual(const FPGATrackSimBinUtil::ParSet &parset, FPGATrackSimHit const *hit) const override
Definition: FPGATrackSimKeyLayerBinDesc.h:77
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::cosb
double cosb
Definition: FPGATrackSimKeyLayerBinDesc.h:104
FPGATrackSimKeyLayerTool::KeyLyrPars::z1
double z1
Definition: FPGATrackSimKeyLayerTool.h:51
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::phiWindow
double phiWindow(double r)
Definition: FPGATrackSimKeyLayerBinDesc.cxx:240
FPGATrackSimHit::getR
float getR() const
Definition: FPGATrackSimHit.h:152
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::y1p
double y1p
Definition: FPGATrackSimKeyLayerBinDesc.h:103
FPGATrackSimKeyLayerBinDesc::etaLUTConsts::w_in
double w_in
Definition: FPGATrackSimKeyLayerBinDesc.h:119
FPGATrackSimKeyLayerBinDesc::m_keylyrtool
FPGATrackSimKeyLayerTool m_keylyrtool
Definition: FPGATrackSimKeyLayerBinDesc.h:166
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::r_in
double r_in
Definition: FPGATrackSimKeyLayerBinDesc.h:99
FPGATrackSimKeyLayerBinDesc::stepIsRPhi
bool stepIsRPhi(const FPGATrackSimBinStep &step) const
Definition: FPGATrackSimKeyLayerBinDesc.cxx:148
FPGATrackSimKeyLayerTool::deltaX
double deltaX(const KeyLyrPars &keypars, double rHit, double phiHit) const
Definition: FPGATrackSimKeyLayerTool.cxx:157
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::y
double y
Definition: FPGATrackSimKeyLayerBinDesc.h:101
FPGATrackSimKeyLayerTool::zExpected
double zExpected(const KeyLyrPars &keypars, double r) const
Definition: FPGATrackSimKeyLayerTool.cxx:127
FPGATrackSimKeyLayerBinDesc::parSetToKeyPars
FPGATrackSimKeyLayerTool::KeyLyrPars parSetToKeyPars(const FPGATrackSimBinUtil::ParSet &parset) const
Definition: FPGATrackSimKeyLayerBinDesc.h:161
FPGATrackSimKeyLayerBinDesc::m_z0pad
Gaudi::Property< double > m_z0pad
Definition: FPGATrackSimKeyLayerBinDesc.h:140
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::w_x
double w_x
Definition: FPGATrackSimKeyLayerBinDesc.h:108
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
LArCellBinning.step
step
Definition: LArCellBinning.py:158
FPGATrackSimKeyLayerBinDesc::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimKeyLayerBinDesc.cxx:25
fieldCorrection
double fieldCorrection(unsigned region, double qoverpt, double r)
Definition: FPGATrackSimFunctions.cxx:163
FPGATrackSimKeyLayerBinDesc::etaLUTConsts::dw_dr
double dw_dr
Definition: FPGATrackSimKeyLayerBinDesc.h:120
FPGATrackSimKeyLayerBinDesc::m_fieldCorrection
Gaudi::Property< bool > m_fieldCorrection
Definition: FPGATrackSimKeyLayerBinDesc.h:154
FPGATrackSimBinUtil::IdxSet
Definition: FPGATrackSimBinUtil.h:50
FPGATrackSimKeyLayerBinDesc::writeLUTs
virtual void writeLUTs(const FPGATrackSimBinStep &step) const override
Definition: FPGATrackSimKeyLayerBinDesc.cxx:256
FPGATrackSimKeyLayerBinDesc::m_slPerEtaMod
Gaudi::Property< std::vector< double > > m_slPerEtaMod
Definition: FPGATrackSimKeyLayerBinDesc.h:143
FPGATrackSimTrackPars.h
Structs that store the 5 track parameters.
FPGATrackSimKeyLayerBinDesc::etaLUTConsts::r_out
double r_out
Definition: FPGATrackSimKeyLayerBinDesc.h:116
FPGATrackSimKeyLayerBinDesc::phiLUTConsts::phiShift
double phiShift(double phi, double r)
Definition: FPGATrackSimKeyLayerBinDesc.cxx:233
FPGATrackSimKeyLayerTool::keyParsToTrackPars
FPGATrackSimTrackPars keyParsToTrackPars(const KeyLyrPars &keypars) const
Definition: FPGATrackSimKeyLayerTool.cxx:79
FPGATrackSimKeyLayerBinDesc::m_region
Gaudi::Property< unsigned > m_region
Definition: FPGATrackSimKeyLayerBinDesc.h:142
FPGATrackSimKeyLayerTool::KeyLyrPars
Definition: FPGATrackSimKeyLayerTool.h:47