ATLAS Offline Software
FPGATrackSimKeyLayerBinDesc.cxx
Go to the documentation of this file.
1 
2 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 
18 
19 
20 
23 
25 {
26  // Dump the configuration to make sure it propagated through right
27  const std::vector<Gaudi::Details::PropertyBase*> props = this->getProperties();
28  for( Gaudi::Details::PropertyBase* prop : props ) {
29  if (prop->ownerTypeName()==this->type()) {
30  ATH_MSG_DEBUG("Property:\t" << prop->name() << "\t : \t"<< prop->toString());
31  }
32  }
33 
36 
37  return StatusCode::SUCCESS;
38 }
39 
41  const IdxSet &idx,
42  StoredHit &storedhit) const
43 {
44  double r1 = m_keylyrtool.R1();
45  double r2 = m_keylyrtool.R2();
46  double hitr= storedhit.hitptr->getR();
47 
48  bool passesPhi = true;
49  bool passesEta = true;
50 
51  FPGATrackSimTrackPars trackpars = parSetToTrackPars(step.binCenter(idx));
52 
53  bool isTruthBin = ((m_truthbin.size()>step.stepNum())&&(m_truthbin[step.stepNum()]==idx));
54 
55  if (stepIsRPhi(step)) {
56  // distance of hit from bin center
57  storedhit.phiShift =
58  phiResidual(step.binCenter(idx), storedhit.hitptr.get());
59 
60  // Get expected curvature shift from bin center
61  auto half_xm_bin_pars = parSetToKeyPars(step.binCenter(idx));
62  half_xm_bin_pars.xm = step.binWidth(4)/2.0; // 4 = xm par
63  double xshift =
64  m_keylyrtool.xExpected(half_xm_bin_pars, storedhit.hitptr.get());
65  double xrange = std::abs(xshift) + r1 * step.binWidth(2) / 2.0
66  + ((r2*step.binWidth(3) - r1*step.binWidth(2)) / (r2 - r1) * (hitr - r1))/2.0;
67 
68  if (xrange < 0) {
69  ATH_MSG_ERROR("Negative xrange: " << std::abs(xshift) << " " << r1 * step.binWidth(2) / 2.0 << " "
70  << ((r2*step.binWidth(3) - r1*step.binWidth(2)) / (r2 - r1) * (hitr - r1))/2.0);
71  }
72 
73  double padding = 0.0;
74  double stripLength = 25.0;
75  if (storedhit.hitptr->getDetType() == SiliconTech::strip) {
76  if (!storedhit.hitptr->isBarrel()) {
77  // varying strip lengths per eta mod in endcap
78  int etamod = storedhit.hitptr->getEtaModule();
79  stripLength = m_slPerEtaMod[etamod]/2.0;
80  }
81  padding += stripLength*std::abs(FPGATrackSimBinUtil::GeomHelpers::dPhiHitTrkFromPars(hitr,trackpars));
82  }
83  // add phiShift resolution padding, 1000.0 is the GeV to MeV conversion
85  passesPhi = std::abs(storedhit.phiShift) < (xrange+padding);
86  ATH_MSG_DEBUG("Phi qpt pad: " << storedhit.phiShift << " " << hitr*m_qptpad*1000.0*FPGATrackSimBinUtil::GeomHelpers::dPhidQOverPt(hitr) << " " << m_qptpad);
87  if (isTruthBin && !passesPhi) ATH_MSG_DEBUG("Hit fails Phi cut, lyr=" << storedhit.hitptr->getPhysLayer() << " "
88  << storedhit.phiShift << " " << xrange + padding << " " <<xrange << " "<< padding
89  << " " << m_d0pad << " " << hitr*m_phipad << " " << hitr*m_qptpad*FPGATrackSimBinUtil::GeomHelpers::dPhidQOverPt(hitr)
90  << " " << ((storedhit.hitptr->getDetType() == SiliconTech::strip) ? (stripLength*std::abs(FPGATrackSimBinUtil::GeomHelpers::dPhiHitTrkFromPars(hitr,trackpars))) : 99999)
91  << " " << hitr << " " << trackpars);
92  }
93 
94  if (stepIsREta(step)) {
95  // distance of hit from bin center
96  storedhit.etaShift = etaResidual(step.binCenter(idx),storedhit.hitptr.get());
97 
98  double width_z_in = step.binWidth(0)/2.0;
99  double width_z_out = step.binWidth(1)/2.0;
100  double zrange = width_z_in + (width_z_out-width_z_in) * std::abs((hitr-r1))/(r2-r1);
101 
102  // pad for strip length or imprecise SP.
103  double padding = 0;
104  double stripLength = 25.0; //barrel strip length
105  if (storedhit.hitptr->getDetType() == SiliconTech::strip) {
106  if (!storedhit.hitptr->isBarrel()) {
107  // varying strip lengths per eta mod in endcap
108  int etamod = storedhit.hitptr->getEtaModule();
109  stripLength = m_slPerEtaMod[etamod]/2.0;
110  }
111  // length of longest correspinding to endcap or barrel strip
112  padding += stripLength;
113  }
114  // add etaShift resolution padding
115  padding += (m_z0pad + std::abs(hitr*m_etapad*FPGATrackSimBinUtil::GeomHelpers::dZdEta(trackpars.eta)));
116  passesEta = std::abs(storedhit.etaShift) < (zrange+padding);
117  if (isTruthBin && !passesEta) ATH_MSG_DEBUG("Hit fails Eta cut , lyr=" << storedhit.hitptr->getPhysLayer() << " r=" << hitr << " "
118  << storedhit.etaShift << " " << zrange + padding << " " <<zrange << " "<< padding << " " << hitr << " " << trackpars);
119  }
120 
121 
122  if (isTruthBin && !(passesPhi && passesEta)) ATH_MSG_DEBUG("Hit in truth bin fails cuts: " << " passesPhi=" << passesPhi << " passesEta=" << passesEta);
123 
124  return passesPhi && passesEta;
125 }
126 
127 // figure out if step is r-phi or r-eta plan
129  const FPGATrackSimBinStep &step) const {
130  for (const unsigned &steppar : step.stepPars()) {
131  for (const unsigned &phipar : m_phipars) {
132  if (steppar == phipar)
133  return true;
134  }
135  }
136  return false;
137 }
138 
140  const FPGATrackSimBinStep &step) const {
141  for (const unsigned &steppar : step.stepPars()) {
142  for (const unsigned &etapar : m_etapars) {
143  if (steppar == etapar)
144  return true;
145  }
146  }
147  return false;
148 }
149 
150 //---------------------------------------------------------------------------------------
151 //
152 // Write the relevant LUT tables for firmware
153 //
154 //---------------------------------------------------------------------------------------
156  double r_in = m_keylyrtool.R1();
157  double r_out = m_keylyrtool.R2();
158 
159  ATH_MSG_INFO("Writing constants for step:" << step.stepName() << " isRPhi="<< stepIsRPhi(step) << " isREta="<< stepIsREta(step));
160 
161  // write the keylayer definition
162  if (step.isFirstStep()) {
163  FPGATrackSimBinUtil::StreamManager sm("KeyLayer");
164  sm.writeVar("r_in",r_in);
165  sm.writeVar("r_out",r_out);
166  }
167 
168  if (stepIsRPhi(step)) {
169 
171  int nbins = 0;
172  for (FPGATrackSimBinArray<int>::ConstIterator &bin : step.validBinsLocal()) {
173  if (!bin.data())
174  continue;
175 
176  sm.writeVar("phi_bin", bin.idx());
177 
179  keypars.phi1 = step.binCenter(2,bin.idx()[0]);
180  keypars.phi2 = step.binCenter(3,bin.idx()[1]);
181  keypars.xm = step.binCenter(4, bin.idx()[2]);
182 
183  auto rotated_coords = m_keylyrtool.getRotatedConfig(keypars);
184 
185  sm.writeVar("y", rotated_coords.y);
186  sm.writeVar("x1p", rotated_coords.xy1p.first);
187  sm.writeVar("y1p", rotated_coords.xy1p.second);
188  sm.writeVar("cosb", rotated_coords.rotang.first);
189  sm.writeVar("sinb", rotated_coords.rotang.second);
190 
191  sm.writeVar("x_m", keypars.xm);
192  sm.writeVar("x_factor", 4.0 * keypars.xm / (rotated_coords.y * rotated_coords.y));
193 
194  nbins++;
195  }
196 
197  double w_in = r_in * step.binWidth(2) / 2.0;
198  double w_out = r_out * step.binWidth(3) / 2.0;
199  double w_x = step.binWidth(4) / 2.0;
200  double dw_dr = (w_out - w_in) / (r_out - r_in);
201 
202  sm.writeVar("w_x", 4.0 * w_x / ((r_out - r_in) * (r_out - r_in)));
203  sm.writeVar("w_in", w_in);
204  sm.writeVar("dw_dr", dw_dr);
205 
206  sm.writeVar("nbins", nbins);
207  }
208 
209  if (stepIsREta(step)) {
210 
212 
213  int nbins = 0;
214  for (FPGATrackSimBinArray<int>::ConstIterator &bin : step.validBinsLocal()) {
215  if (!bin.data())
216  continue;
217 
218  // write just this steps idxs
219  sm.writeVar("z_bin", bin.idx());
220 
221  double z_in = step.binCenter(0, bin.idx()[0]);
222  double z_out = step.binCenter(1, bin.idx()[1]);
223  double dz_dr = (z_out - z_in) / (r_out - r_in);
224 
225  sm.writeVar("z_in", z_in);
226  sm.writeVar("dz_dr", dz_dr);
227 
228  nbins++;
229  }
230  sm.writeVar("nbins", nbins);
231 
232  // same for all bins
233  double w_in = step.binWidth(0) / 2.0;
234  double w_out = step.binWidth(1) / 2.0;
235  double dw_dr = (w_out - w_in) / (r_out - r_in);
236  sm.writeVar("w_in", w_in);
237  sm.writeVar("dw_dr", dw_dr);
238 
239  }
240 
241 
242 
243 
244 }
245 
FPGATrackSimKeyLayerTool::setR1
void setR1(const double r1)
Definition: FPGATrackSimKeyLayerTool.h:101
xrange
void xrange(TH1 *h, bool symmetric)
Definition: computils.cxx:517
FPGATrackSimKeyLayerBinDesc::m_etapars
const std::vector< unsigned > m_etapars
Definition: FPGATrackSimKeyLayerBinDesc.h:128
FPGATrackSimBinUtil::StoredHit::hitptr
std::shared_ptr< const FPGATrackSimHit > hitptr
Definition: FPGATrackSimBinUtil.h:103
SiliconTech::strip
@ strip
FPGATrackSimBinStep
Definition: FPGATrackSimBinStep.h:45
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthMsgStreamMacros.h
FPGATrackSimTrackPars
Definition: FPGATrackSimTrackPars.h:22
FPGATrackSimKeyLayerTool.h
Binning Classes for BinTool.
FPGATrackSimKeyLayerTool::R2
double R2() const
Definition: FPGATrackSimKeyLayerTool.h:100
FPGATrackSimKeyLayerBinDesc::etaResidual
virtual double etaResidual(const FPGATrackSimBinUtil::ParSet &parset, FPGATrackSimHit const *hit) const override
Definition: FPGATrackSimKeyLayerBinDesc.h:76
bin
Definition: BinsDiffFromStripMedian.h:43
FPGATrackSimKeyLayerBinDesc::m_rout
Gaudi::Property< double > m_rout
Definition: FPGATrackSimKeyLayerBinDesc.h:95
FPGATrackSimKeyLayerTool::KeyLyrPars::xm
double xm
Definition: FPGATrackSimKeyLayerTool.h:56
FPGATrackSimKeyLayerBinDesc::m_etapad
Gaudi::Property< double > m_etapad
Definition: FPGATrackSimKeyLayerBinDesc.h:101
FPGATrackSimTrackPars::eta
double eta
Definition: FPGATrackSimTrackPars.h:28
FPGATrackSimKeyLayerBinDesc::parSetToTrackPars
virtual const FPGATrackSimTrackPars parSetToTrackPars(const FPGATrackSimBinUtil::ParSet &parset) const override
Definition: FPGATrackSimKeyLayerBinDesc.h:65
FPGATrackSimBinStep.h
Binning Classes for BinStep.
dqutils::padding
std::atomic< int > padding
Definition: MonitoringFile_MoveVertexMonitoring.cxx:20
FPGATrackSimKeyLayerTool::KeyLyrPars::phi2
double phi2
Definition: FPGATrackSimKeyLayerTool.h:55
FPGATrackSimBinUtil::GeomHelpers::dPhidQOverPt
static double dPhidQOverPt(double hitr)
Definition: FPGATrackSimBinUtil.cxx:185
FPGATrackSimBinUtil::GeomHelpers::dPhiHitTrkFromPars
static double dPhiHitTrkFromPars(double r, const FPGATrackSimTrackPars &pars)
Definition: FPGATrackSimBinUtil.cxx:162
CaloSwCorrections.etamod
def etamod(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:206
FPGATrackSimKeyLayerBinDesc::m_phipars
const std::vector< unsigned > m_phipars
Definition: FPGATrackSimKeyLayerBinDesc.h:127
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
FPGATrackSimKeyLayerBinDesc::m_phipad
Gaudi::Property< double > m_phipad
Definition: FPGATrackSimKeyLayerBinDesc.h:98
FPGATrackSimKeyLayerBinDesc::hitInBin
virtual bool hitInBin(const FPGATrackSimBinStep &step, const FPGATrackSimBinUtil::IdxSet &idx, FPGATrackSimBinUtil::StoredHit &storedhit) const override
Definition: FPGATrackSimKeyLayerBinDesc.cxx:40
FPGATrackSimBinUtil::StreamManager
Definition: FPGATrackSimBinUtil.h:83
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FPGATrackSimBinUtil.h
Binning Utilities for GenScanTool.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FPGATrackSimKeyLayerBinDesc::m_qptpad
Gaudi::Property< double > m_qptpad
Definition: FPGATrackSimKeyLayerBinDesc.h:99
FPGATrackSimKeyLayerBinDesc::m_d0pad
Gaudi::Property< double > m_d0pad
Definition: FPGATrackSimKeyLayerBinDesc.h:97
FPGATrackSimKeyLayerBinDesc::m_rin
Gaudi::Property< double > m_rin
Definition: FPGATrackSimKeyLayerBinDesc.h:94
FPGATrackSimBinArray
Definition: FPGATrackSimBinArray.h:41
FPGATrackSimKeyLayerBinDesc::stepIsREta
bool stepIsREta(const FPGATrackSimBinStep &step) const
Definition: FPGATrackSimKeyLayerBinDesc.cxx:139
FPGATrackSimKeyLayerTool::KeyLyrPars::phi1
double phi1
Definition: FPGATrackSimKeyLayerTool.h:54
FPGATrackSimKeyLayerTool::setR2
void setR2(const double r2)
Definition: FPGATrackSimKeyLayerTool.h:102
FPGATrackSimKeyLayerTool::getRotatedConfig
rotatedConfig getRotatedConfig(const KeyLyrPars &keypars) const
Definition: FPGATrackSimKeyLayerTool.cxx:32
FPGATrackSimBinUtil::StoredHit
Definition: FPGATrackSimBinUtil.h:101
FPGATrackSimKeyLayerTool::R1
double R1() const
Definition: FPGATrackSimKeyLayerTool.h:99
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
FPGATrackSimKeyLayerBinDesc::phiResidual
virtual double phiResidual(const FPGATrackSimBinUtil::ParSet &parset, FPGATrackSimHit const *hit) const override
Definition: FPGATrackSimKeyLayerBinDesc.h:72
zrange
void zrange(double nsigma, double fence, double &zed, double &zedMinus, double &zedPlus, const SG::ReadCondHandleKey< InDet::BeamSpotData > &bs, const EventContext &ctx)
Definition: RoiUpdaterTool.cxx:33
FPGATrackSimKeyLayerTool::xExpected
double xExpected(const KeyLyrPars &keypars, const FPGATrackSimHit *hit) const
Definition: FPGATrackSimKeyLayerTool.cxx:170
FPGATrackSimKeyLayerBinDesc::m_keylyrtool
FPGATrackSimKeyLayerTool m_keylyrtool
Definition: FPGATrackSimKeyLayerBinDesc.h:124
FPGATrackSimKeyLayerBinDesc::stepIsRPhi
bool stepIsRPhi(const FPGATrackSimBinStep &step) const
Definition: FPGATrackSimKeyLayerBinDesc.cxx:128
FPGATrackSimBinUtil::GeomHelpers::dZdEta
static double dZdEta(double eta)
Definition: FPGATrackSimBinUtil.cxx:179
FPGATrackSimKeyLayerBinDesc::parSetToKeyPars
FPGATrackSimKeyLayerTool::KeyLyrPars parSetToKeyPars(const FPGATrackSimBinUtil::ParSet &parset) const
Definition: FPGATrackSimKeyLayerBinDesc.h:119
FPGATrackSimKeyLayerBinDesc::m_z0pad
Gaudi::Property< double > m_z0pad
Definition: FPGATrackSimKeyLayerBinDesc.h:100
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
FPGATrackSimKeyLayerBinDesc.h
Binning Classes for BinTool.
LArCellBinning.step
step
Definition: LArCellBinning.py:158
FPGATrackSimKeyLayerBinDesc::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimKeyLayerBinDesc.cxx:24
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::IdxSet
Definition: FPGATrackSimBinUtil.h:50
FPGATrackSimTypes.h
FPGATrackSimKeyLayerBinDesc::writeLUTs
virtual void writeLUTs(const FPGATrackSimBinStep &step) const override
Definition: FPGATrackSimKeyLayerBinDesc.cxx:155
FPGATrackSimKeyLayerBinDesc::m_slPerEtaMod
Gaudi::Property< std::vector< double > > m_slPerEtaMod
Definition: FPGATrackSimKeyLayerBinDesc.h:102
FPGATrackSimTrackPars.h
Structs that store the 5 track parameters.
FPGATrackSimKeyLayerTool::KeyLyrPars
Definition: FPGATrackSimKeyLayerTool.h:48