ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimKeyLayerBinDesc.cxx
Go to the documentation of this file.
1
2// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
10
18#include <cmath>
19
20
21
24
26{
27 // Dump the configuration to make sure it propagated through right
28 const std::vector<Gaudi::Details::PropertyBase*> props = this->getProperties();
29 for( Gaudi::Details::PropertyBase* prop : props ) {
30 if (prop->ownerTypeName()==this->type()) {
31 ATH_MSG_DEBUG("Property:\t" << prop->name() << "\t : \t"<< prop->toString());
32 }
33 }
34
35 m_keylyrtool.setR1(m_rin);
36 m_keylyrtool.setR2(m_rout);
37
38 return StatusCode::SUCCESS;
39}
40
42 const IdxSet &idx,
43 StoredHit &storedhit) const
44{
45 double r1 = m_keylyrtool.R1();
46 double r2 = m_keylyrtool.R2();
47 double hitr= storedhit.hitptr->getR();
48
49 bool passesPhi = true;
50 bool passesEta = true;
51
52 FPGATrackSimTrackPars trackpars = parSetToTrackPars(step.binCenter(idx));
53
54 bool isTruthBin = ((m_truthbin.size()>step.stepNum())&&(m_truthbin[step.stepNum()]==idx));
55
56 if (stepIsRPhi(step)) {
57 // distance of hit from bin center
58 storedhit.phiShift =
59 phiResidual(step.binCenter(idx), storedhit.hitptr.get());
60
61 // Get expected curvature shift from bin center
62 auto half_xm_bin_pars = parSetToKeyPars(step.binCenter(idx));
63 half_xm_bin_pars.xm = step.binWidth(4)/2.0; // 4 = xm par
64 double xshift =
65 m_keylyrtool.xExpected(half_xm_bin_pars, storedhit.hitptr->getR(), remainder(storedhit.hitptr->getGPhi()+m_phiOffset,2*M_PI));
66 double xrange = std::abs(xshift) + r1 * step.binWidth(2) / 2.0
67 + ((r2*step.binWidth(3) - r1*step.binWidth(2)) / (r2 - r1) * (hitr - r1))/2.0;
68
69 if (xrange < 0) {
70 ATH_MSG_ERROR("Negative xrange: " << std::abs(xshift) << " " << r1 * step.binWidth(2) / 2.0 << " "
71 << ((r2*step.binWidth(3) - r1*step.binWidth(2)) / (r2 - r1) * (hitr - r1))/2.0);
72 }
73
74 double padding = 0.0;
75 double stripLength = 25.0;
76 if (storedhit.hitptr->getDetType() == SiliconTech::strip) {
77 if (!storedhit.hitptr->isBarrel()) {
78 // varying strip lengths per eta mod in endcap
79 int etamod = storedhit.hitptr->getEtaModule();
80 stripLength = m_slPerEtaMod[etamod]/2.0;
81 }
82 padding += stripLength*std::abs(FPGATrackSimBinUtil::GeomHelpers::dPhiHitTrkFromPars(hitr,trackpars));
83 }
84 // add phiShift resolution padding, 1000.0 is the GeV to MeV conversion
85 padding += m_d0pad + hitr*m_phipad + hitr*m_qptpad*1000.0*FPGATrackSimBinUtil::GeomHelpers::dPhidQOverPt(hitr);
86 passesPhi = std::abs(storedhit.phiShift) < (xrange+padding);
87 ATH_MSG_VERBOSE("Phi qpt pad: " << storedhit.phiShift << " " << hitr*m_qptpad*1000.0*FPGATrackSimBinUtil::GeomHelpers::dPhidQOverPt(hitr) << " " << m_qptpad);
88 if (isTruthBin && !passesPhi) ATH_MSG_DEBUG("Hit fails Phi cut, lyr=" << storedhit.hitptr->getPhysLayer() << " "
89 << storedhit.phiShift << " " << xrange + padding << " " <<xrange << " "<< padding
90 << " " << m_d0pad << " " << hitr*m_phipad << " " << hitr*m_qptpad*FPGATrackSimBinUtil::GeomHelpers::dPhidQOverPt(hitr)
91 << " " << ((storedhit.hitptr->getDetType() == SiliconTech::strip) ? (stripLength*std::abs(FPGATrackSimBinUtil::GeomHelpers::dPhiHitTrkFromPars(hitr,trackpars))) : 99999)
92 << " " << hitr << " " << trackpars);
93
94 // Firmware x-check
95 phiLUTConsts phiconsts = getPhiLUTConsts(step,step.stepIdx(idx));
96 double fw_phiShift = phiconsts.phiShift(remainder(storedhit.hitptr->getGPhi() + m_phiOffset,2*M_PI), hitr);
97 double fw_phiWindow = phiconsts.phiWindow( hitr);
98 ATH_MSG_VERBOSE("FW x-check: phiShift orig: " << storedhit.phiShift << " fwcalc: " << fw_phiShift << " diff: " << storedhit.phiShift-fw_phiShift);
99 ATH_MSG_VERBOSE("FW " << phiconsts.w_in << " " << phiconsts.dw_dr*(hitr-phiconsts.r_in) << " " << phiconsts.w_x*(hitr-phiconsts.r_in)*(phiconsts.r_out-hitr)
100 << " Orig: " << r1 * step.binWidth(2) / 2.0 << " " << ((r2*step.binWidth(3) - r1*step.binWidth(2)) / (r2 - r1) * (hitr - r1))/2.0 << " " << std::abs(xshift));
101 ATH_MSG_VERBOSE("FW x-check: phiWindow orig: " << xrange << " fwcalc: " << fw_phiWindow << " diff: " << xrange-fw_phiWindow);
102
103 }
104
105 if (stepIsREta(step)) {
106 // distance of hit from bin center
107 storedhit.etaShift = etaResidual(step.binCenter(idx),storedhit.hitptr.get());
108
109 double width_z_in = step.binWidth(0)/2.0;
110 double width_z_out = step.binWidth(1)/2.0;
111 double zrange = width_z_in + (width_z_out-width_z_in) * std::abs((hitr-r1))/(r2-r1);
112
113 // pad for strip length or imprecise SP.
114 double padding = 0;
115 double stripLength = 25.0; //barrel strip length
116 if (storedhit.hitptr->getDetType() == SiliconTech::strip) {
117 if (!storedhit.hitptr->isBarrel()) {
118 // varying strip lengths per eta mod in endcap
119 int etamod = storedhit.hitptr->getEtaModule();
120 stripLength = m_slPerEtaMod[etamod]/2.0;
121 }
122 // length of longest correspinding to endcap or barrel strip
123 padding += stripLength;
124 }
125 // add etaShift resolution padding
126 padding += (m_z0pad + std::abs(hitr*m_etapad*FPGATrackSimBinUtil::GeomHelpers::dZdEta(trackpars.eta)));
127 passesEta = std::abs(storedhit.etaShift) < (zrange+padding);
128 if (isTruthBin && !passesEta) ATH_MSG_DEBUG("Hit fails Eta cut , lyr=" << storedhit.hitptr->getPhysLayer() << " r=" << hitr << " "
129 << storedhit.etaShift << " " << zrange + padding << " " <<zrange << " "<< padding << " " << hitr << " " << trackpars);
130
131 // Firmware x-check
132 etaLUTConsts etaconsts = getEtaLUTConsts(step,step.stepIdx(idx));
133 double fw_etaShift = etaconsts.etaShift(storedhit.hitptr->getZ(), hitr);
134 double fw_etaWindow = etaconsts.etaWindow( hitr);
135 ATH_MSG_VERBOSE("FW x-check: etaShift orig: " << storedhit.etaShift << " fwcalc: " << fw_etaShift << " diff: " << storedhit.etaShift-fw_etaShift);
136 ATH_MSG_VERBOSE("FW x-check: etaWindow orig: " << zrange << " fwcalc: " << fw_etaWindow << " diff: " << zrange-fw_etaWindow);
137
138
139 }
140
141
142 if (isTruthBin && !(passesPhi && passesEta)) ATH_MSG_DEBUG("Hit in truth bin fails cuts: " << " passesPhi=" << passesPhi << " passesEta=" << passesEta);
143
144 return passesPhi && passesEta;
145}
146
147// figure out if step is r-phi or r-eta plan
149 const FPGATrackSimBinStep &step) const {
150 for (const unsigned &steppar : step.stepPars()) {
151 for (const unsigned &phipar : m_phipars) {
152 if (steppar == phipar)
153 return true;
154 }
155 }
156 return false;
157}
158
160 const FPGATrackSimBinStep &step) const {
161 for (const unsigned &steppar : step.stepPars()) {
162 for (const unsigned &etapar : m_etapars) {
163 if (steppar == etapar)
164 return true;
165 }
166 }
167 return false;
168}
169
170//---------------------------------------------------------------------------------------
171//
172// Calculate the Firmware LUT for a bin
173//
174//---------------------------------------------------------------------------------------
176 phiLUTConsts retv;
177
179 keypars.phi1 = step.binCenter(2,idx[0]);
180 keypars.phi2 = step.binCenter(3,idx[1]);
181 keypars.xm = step.binCenter(4, idx[2]);
182
183 auto rotated_coords = m_keylyrtool.getRotatedConfig(keypars);
184
185 retv.y = rotated_coords.y;
186 retv.x1p = rotated_coords.xy1p.first;
187 retv.y1p = rotated_coords.xy1p.second;
188 retv.cosb = rotated_coords.rotang.first;
189 retv.sinb = rotated_coords.rotang.second;
190 retv.x_m = keypars.xm;
191 retv.x_factor = 4.0 * keypars.xm / (rotated_coords.y * rotated_coords.y);
192
193 double r_in = m_keylyrtool.R1();
194 double r_out = m_keylyrtool.R2();
195 retv.r_in = r_in;
196 retv.r_out= r_out;
197
198 double w_in = r_in * step.binWidth(2) / 2.0;
199 double w_out = r_out * step.binWidth(3) / 2.0;
200 double w_x = step.binWidth(4) / 2.0;
201
202 retv.w_x = 4.0 * w_x / ((r_out - r_in) * (r_out - r_in));
203 retv.w_in = w_in;
204 retv.dw_dr = (w_out - w_in) / (r_out - r_in);
205
206 return retv;
207}
208
210 etaLUTConsts retv;
211
212 double r_in = m_keylyrtool.R1();
213 double r_out = m_keylyrtool.R2();
214 retv.r_in = r_in;
215 retv.r_out= r_out;
216
217 double z_in = step.binCenter(0, idx[0]);
218 double z_out = step.binCenter(1, idx[1]);
219 double dz_dr = (z_out - z_in) / (r_out - r_in);
220
221 retv.z_in = z_in;
222 retv.dz_dr = dz_dr;
223
224 double w_in = step.binWidth(0) / 2.0;
225 double w_out = step.binWidth(1) / 2.0;
226 double dw_dr = (w_out - w_in) / (r_out - r_in);
227 retv.w_in = w_in;
228 retv.dw_dr = dw_dr;
229
230 return retv;
231}
232
234 double xc = r*cos(phi);
235 double yc = r*sin(phi);
236 double xh = xc*cosb+yc*sinb-x1p;
237 double yh = -xc*sinb+yc*cosb-y1p;
238 return xh - x_factor*yh*(y-yh);
239}
244 return z - z_in - dz_dr*(r-r_in);
245}
249
250
251//---------------------------------------------------------------------------------------
252//
253// Write the relevant LUT tables for firmware
254//
255//---------------------------------------------------------------------------------------
257 double r_in = m_keylyrtool.R1();
258 double r_out = m_keylyrtool.R2();
259
260 ATH_MSG_INFO("Writing constants for step:" << step.stepName() << " isRPhi="<< stepIsRPhi(step) << " isREta="<< stepIsREta(step));
261
262 // write the keylayer definition
263 if (step.isFirstStep()) {
264 std::string keylayerName = "reg_" + std::to_string(m_region.value()) + "_KeyLayer";
265 FPGATrackSimBinUtil::StreamManager sm(keylayerName);
266 sm.writeVar("r_in",r_in);
267 sm.writeVar("r_out",r_out);
268 sm.writeVar("phi_offset",m_phiOffset.value());
269 }
270
271 if (stepIsRPhi(step)) {
272
273 std::string stepName = "reg_" + std::to_string(m_region.value()) + "_" + step.stepName();
275 int nbins = 0;
276 for (FPGATrackSimBinArray<int>::ConstIterator &bin : step.validBinsLocal()) {
277 if (!bin.data())
278 continue;
279 phiLUTConsts phiconsts = getPhiLUTConsts(step,bin.idx());
280
281 sm.writeVar("phi_bin", bin.idx());
282
283 sm.writeVar("y", phiconsts.y);
284 sm.writeVar("x1p", phiconsts.x1p);
285 sm.writeVar("y1p", phiconsts.y1p);
286 sm.writeVar("cosb", phiconsts.cosb);
287 sm.writeVar("sinb", phiconsts.sinb);
288
289 sm.writeVar("x_m", phiconsts.x_m);
290 sm.writeVar("x_factor", phiconsts.x_factor);
291
292 if (nbins == 0) {
293 sm.writeVar("w_x", phiconsts.w_x);
294 sm.writeVar("w_in", phiconsts.w_in);
295 sm.writeVar("dw_dr", phiconsts.dw_dr);
296 }
297
298 nbins++;
299 }
300
301 sm.writeVar("nbins", nbins);
302 }
303
304 if (stepIsREta(step)) {
305
306 std::string stepName = "reg_" + std::to_string(m_region.value()) + "_" + step.stepName();
308
309 int nbins = 0;
310 for (FPGATrackSimBinArray<int>::ConstIterator &bin : step.validBinsLocal()) {
311 if (!bin.data())
312 continue;
313
314 etaLUTConsts etaconsts = getEtaLUTConsts(step,bin.idx());
315
316 // write just this steps idxs
317 sm.writeVar("z_bin", bin.idx());
318 sm.writeVar("z_in", etaconsts.z_in);
319 sm.writeVar("dz_dr", etaconsts.dz_dr);
320
321 if (nbins==0) {
322 sm.writeVar("w_in", etaconsts.w_in);
323 sm.writeVar("dw_dr", etaconsts.dw_dr);
324 };
325
326 nbins++;
327 }
328 sm.writeVar("nbins", nbins);
329
330 }
331
332}
333
#define M_PI
Scalar phi() const
phi method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Binning Classes for BinStep.
Binning Utilities for GenScanTool.
Binning Classes for BinTool.
Binning Classes for BinTool.
Structs that store the 5 track parameters.
void zrange(double nsigma, double fence, double &zed, double &zedMinus, double &zedPlus, const SG::ReadCondHandleKey< InDet::BeamSpotData > &bs, const EventContext &ctx)
#define z
static double dPhiHitTrkFromPars(double r, const FPGATrackSimTrackPars &pars)
static double dPhidQOverPt(double hitr)
float getGPhi() const
bool isBarrel() const
int getEtaModule(bool old=false) const
float getZ() const
float getR() const
unsigned getPhysLayer(bool old=false) const
SiliconTech getDetType() const
virtual StatusCode initialize() override
Gaudi::Property< std::vector< double > > m_slPerEtaMod
const std::vector< unsigned > m_phipars
virtual double etaResidual(const FPGATrackSimBinUtil::ParSet &parset, FPGATrackSimHit const *hit) const override
virtual void writeLUTs(const FPGATrackSimBinStep &step) const override
phiLUTConsts getPhiLUTConsts(const FPGATrackSimBinStep &step, const std::vector< unsigned > &idx) const
bool stepIsREta(const FPGATrackSimBinStep &step) const
bool stepIsRPhi(const FPGATrackSimBinStep &step) const
const std::vector< unsigned > m_etapars
virtual double phiResidual(const FPGATrackSimBinUtil::ParSet &parset, FPGATrackSimHit const *hit) const override
FPGATrackSimKeyLayerTool::KeyLyrPars parSetToKeyPars(const FPGATrackSimBinUtil::ParSet &parset) const
etaLUTConsts getEtaLUTConsts(const FPGATrackSimBinStep &step, const std::vector< unsigned > &idx) const
Gaudi::Property< unsigned > m_region
virtual const FPGATrackSimTrackPars parSetToTrackPars(const FPGATrackSimBinUtil::ParSet &parset) const override
virtual bool hitInBin(const FPGATrackSimBinStep &step, const FPGATrackSimBinUtil::IdxSet &idx, FPGATrackSimBinUtil::StoredHit &storedhit) const override
std::vector< std::string > remainder(const std::vector< std::string > &v1, const std::vector< std::string > &v2)
void xrange(TH1 *h, bool symmetric)
int r
Definition globals.cxx:22
std::shared_ptr< const FPGATrackSimHit > hitptr
void writeVar(const std::string &var, T val)