ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimBinTool.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
9
11
14
15FPGATrackSimBinTool::FPGATrackSimBinTool(const std::string &algname, const std::string &name,
16 const IInterface *ifc)
17: AthAlgTool(algname, name, ifc) {
18}
19
20
21// ----------------------------------------------------------------------------------------
22// AthTool Methods
23// ----------------------------------------------------------------------------------------
24
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
34 // Retrieve
35 ATH_MSG_INFO("Using " << m_steps.size() << " steps");
36 ATH_CHECK(m_steps.retrieve());
37
38 if (m_steps.empty()) {
39 ATH_MSG_FATAL("initialize() Step list empty");
40 return StatusCode::FAILURE;
41 }
42
43 m_parMin = std::vector<double>(m_parMinConfig);
44 m_parMax = std::vector<double>(m_parMaxConfig);
45
46 FPGATrackSimBinStep* prev = 0;
47 for (auto &step : m_steps) {
48 ATH_MSG_INFO("Got Binning Step " << step->stepName());
49 m_stepNames.push_back(step->stepName());
50 if (!step->setRanges(prev, m_parMin, m_parMax)) {
51 ATH_MSG_FATAL("Failed to setRange on step");
52 return StatusCode::FAILURE;
53 }
54 prev = step.get();
55 }
56
57 ATH_MSG_DEBUG("Finished initializing BinTool");
58
59 return StatusCode::SUCCESS;
60}
61
62// ----------------------------------------------------------------------------------------
63// Other methods
64// ----------------------------------------------------------------------------------------
65
66bool FPGATrackSimBinTool::FPGATrackSimBinTool::inRange(
67 const ParSet &parset) const {
68 for (unsigned par = 0; par < FPGATrackSimTrackPars::NPARS; par++) {
69 if (!inRange(par,parset[par]))
70 return false;
71 }
72 return true;
73}
74
75// ----------------------------------------------------------------------------------------
76// Valid Bin Function Implementation
77// ----------------------------------------------------------------------------------------
78
79void FPGATrackSimBinTool::setValidBin(const std::vector<unsigned>& idx) {
80 lastStep()->setValidBin(idx);
81}
82
84 for (auto& step: m_steps) step->initValidBins();
85}
86
88 for (auto &step : m_steps) {
89 step->printValidBin();
90 }
91}
92
93// Compute which bins correspond to track parameters that are in the region
94// i.e. the pT, eta, phi, z0 and d0 bounds
96 // determine which bins are valid
97
98 FPGATrackSimTrackPars min_padded;
99 FPGATrackSimTrackPars max_padded;
100 FPGATrackSimTrackPars padding;
106 for (unsigned par = 0; par < FPGATrackSimTrackPars::NPARS; par++)
107 {
108 min_padded[par] = evtSel->getMin()[par] - padding[par] * (evtSel->getMax()[par]-evtSel->getMin()[par]);
109 max_padded[par] = evtSel->getMax()[par] + padding[par] * (evtSel->getMax()[par]-evtSel->getMin()[par]);
111 // working in units of GeV internally
112 min_padded[par] *= 1000;
113 max_padded[par] *= 1000;
114 }
115 ATH_MSG_INFO("Padded Parameter Range: " << FPGATrackSimTrackPars::parName(par)
116 << " min=" << min_padded[par] << " max=" << max_padded[par]);
117 }
118
119 // iterator over the finest binning used which is the laststep
120 // setting lastSteps valid bins sets all the previous steps
121 auto laststep = lastStep();
122 for (FPGATrackSimBinArray<int>::Iterator bin : laststep->m_validBinFull)
123 {
124 // this finds the parameters at all 2^5 corners of the bin and then finds the min and max of those
125 std::vector<IdxSet> idxsets = FPGATrackSimBinUtil::makeVariationSet(std::vector<unsigned>({0,1,2,3,4}),bin.idx());
126 FPGATrackSimTrackPars minvals = m_binDesc->parSetToTrackPars(laststep->binCenter(bin.idx()));
127 FPGATrackSimTrackPars maxvals = m_binDesc->parSetToTrackPars(laststep->binCenter(bin.idx()));
128 for (IdxSet & idxset : idxsets) {
129 FPGATrackSimTrackPars trackpars = m_binDesc->parSetToTrackPars(laststep->binLowEdge(idxset));
130 for (unsigned par =0; par < FPGATrackSimTrackPars::NPARS; par++) {
131 minvals[par] = std::min(minvals[par],trackpars[par]);
132 maxvals[par] = std::max(maxvals[par],trackpars[par]);
133 }
134 }
135
136 // make sure bin overlaps with active region
137 bool inRange = true;
138 for (unsigned par =0; par < FPGATrackSimTrackPars::NPARS; par++) {
139 inRange = inRange && (minvals[par] < max_padded[par]) && (maxvals[par] > min_padded[par]);
140 }
141 if (inRange)
142 {
143 setValidBin(bin.idx());
144 }
145
146 if (bin.data() == false)
147 {
148 ATH_MSG_VERBOSE("Invalid bin: " << bin.idx() << " :" << m_binDesc->parSetToTrackPars(laststep->binCenter(bin.idx()))
149 << " minvals: " << minvals << " maxvals: " << maxvals );
150 }
151 }
152}
153
155{
156 ParSet parset;
157 for (unsigned i = 0; i < FPGATrackSimTrackPars::NPARS; i++)
158 {
159 parset[i] = parCenter(i);
160 }
161 return parset;
162}
163
164// ----------------------------------------------------------------------------------------
165// Write Firmware LUTs (constants)
166// ----------------------------------------------------------------------------------------
168 for (const auto &step : m_steps) {
169 m_binDesc->writeLUTs(*step.get());
170 }
171}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Binning Classes for BinTool.
bool inRange(const double *boundaries, const double value, const double tolerance=0.02)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
void setValidBin(const std::vector< unsigned > &idx)
FPGATrackSimBinTool(const std::string &algname, const std::string &name, const IInterface *ifc)
void computeValidBins(const IFPGATrackSimEventSelectionSvc *evtSel)
FPGATrackSimBinUtil::ParSet center() const
FPGATrackSimBinUtil::ParSet m_parMax
ToolHandleArray< FPGATrackSimBinStep > m_steps
Gaudi::Property< double > m_etaFractionalPadding
Gaudi::Property< double > m_z0FractionalPadding
Gaudi::Property< std::vector< double > > m_parMaxConfig
virtual StatusCode initialize() override
Gaudi::Property< double > m_d0FractionalPadding
ToolHandle< IFPGATrackSimBinDesc > m_binDesc
void setValidBin(const std::vector< unsigned > &idx)
Gaudi::Property< double > m_qOverPtFractionalPadding
std::vector< std::string > m_stepNames
FPGATrackSimBinStep * lastStep()
Gaudi::Property< std::vector< double > > m_parMinConfig
Gaudi::Property< double > m_phiFractionalPadding
double parCenter(unsigned par) const
bool inRange(unsigned par, double val) const
FPGATrackSimBinUtil::ParSet m_parMin
static std::string parName(unsigned i)
virtual FPGATrackSimTrackPars getMin() const =0
virtual FPGATrackSimTrackPars getMax() const =0
std::vector< IdxSet > makeVariationSet(const std::vector< unsigned > &scanpars, const IdxSet &idx)