14#include <initializer_list>
19using std::make_unique;
40 std::array<double, 3>
m_p;
48 std::array<double, 3>
m_p;
57 declareInterface<IL1DynamicPedestalProvider>(
this);
93 if(fileNameEMShort.empty()) {
95 return StatusCode::FAILURE;
97 ATH_MSG_VERBOSE(
"::initialize: resolved input file: " << fileNameEMShort);
102 ATH_MSG_FATAL(
"Could not parse input file: " << fileNameEMShort <<
"; error: " << e.what());
103 return StatusCode::FAILURE;
107 if(fileNameEMLong.empty()) {
109 return StatusCode::FAILURE;
111 ATH_MSG_VERBOSE(
"::initialize: resolved input file: " << fileNameEMLong);
116 ATH_MSG_FATAL(
"Could not parse input file: " << fileNameEMLong <<
"; error: " << e.what());
117 return StatusCode::FAILURE;
122 if(fileNameHADShort.empty()) {
124 return StatusCode::FAILURE;
126 ATH_MSG_VERBOSE(
"::initialize: resolved input file: " << fileNameHADShort);
131 ATH_MSG_FATAL(
"Could not parse input file: " << fileNameHADShort <<
"; error: " << e.what());
132 return StatusCode::FAILURE;
136 if(fileNameHADLong.empty()) {
138 return StatusCode::FAILURE;
140 ATH_MSG_VERBOSE(
"::initialize: resolved input file: " << fileNameHADLong);
145 ATH_MSG_FATAL(
"Could not parse input file: " << fileNameHADLong <<
"; error: " << e.what());
146 return StatusCode::FAILURE;
149 return StatusCode::SUCCESS;
155template<
typename ResultVector>
158 for(bcid_t bcid = 0; bcid < MAX_BCID; bcid += 20) {
161 log << MSG::VERBOSE <<
"Filled ";
162 for(bcid_t j = bcid; j != std::min(MAX_BCID, bcid+20); ++j) log << std::setw(3) << bcData.
isFilled(j) <<
" ";
165 log << MSG::VERBOSE <<
"Distance ";
166 for(bcid_t j = bcid; j != std::min(MAX_BCID, bcid+20); ++j) log << std::setw(3) <<
result[j].second <<
" ";
169 log << MSG::VERBOSE <<
"LongGap? ";
170 for(bcid_t j = bcid; j != std::min(MAX_BCID, bcid+20); ++j) log << std::setw(3) <<
result[j].first <<
" ";
186 return {bcData->gapBeforeTrain(bcid) > 250, bcData->distanceFromFront(bcid, BC)};
188 if(bcData->gapAfterBunch(bcid, BC) == 0) {
189 const bcid_t
head = ((bcid + 1) == MAX_BCID ? 0 : bcid + 1);
190 return {bcData->gapBeforeTrain(
head) > 250, -1};
191 }
else if(bcData->gapBeforeBunch(bcid, BC) == 0) {
192 const bcid_t
tail = bcid ? bcid - 1 : MAX_BCID - 1;
193 return {bcData->gapBeforeTrain(
tail) > 250,
194 bcData->distanceFromFront(
tail, BC) + 1};
223 if(iBCID < 0 || (
unsigned)iBCID >= MAX_BCID)
return pedestal;
229 bool longGap = bcidInfo.first;
230 int bcid = bcidInfo.second + 1;
232 if(bcid < 0)
return pedestal;
241 }
else if(layer == 1) {
244 ATH_MSG_ERROR(
"Wrong layer index. Give 0 for Em, 1 for Had.");
248 int dynamic_pedestal = correction + pedestal;
249 if (dynamic_pedestal < 0) dynamic_pedestal = 0;
251 return dynamic_pedestal;
265 std::vector<size_t> poly;
266 std::vector<size_t> exp;
296 std::vector<std::vector<std::unique_ptr<ParamFunc>>>& params)
298 using std::istream_iterator;
300 std::ifstream
F(fileName);
304 const std::set<char> whitespaces{
'\t',
' ',
'\n',
'\r'};
305 for(std::string L; std::getline(
F, L); ) {
306 while ((!L.empty()) && whitespaces.count(L.back())) L.pop_back();
307 if(L.empty())
continue;
308 if(L[0] ==
'#')
continue;
310 std::istringstream S(L);
313 if(ctx.P == Context::Element) {
320 throw ParseException(
"element number (" + std::to_string(ctx.E) +
") out-of-range.");
322 ctx.P = Context::Poly;
323 }
else if(ctx.P == Context::Poly) {
328 std::copy(istream_iterator<size_t>(S), istream_iterator<size_t>(), std::back_inserter(ctx.poly));
330 ctx.P = Context::Exp;
331 }
else if(ctx.P == Context::Exp) {
336 std::copy(istream_iterator<size_t>(S), istream_iterator<size_t>(), std::back_inserter(ctx.exp));
338 ctx.P = Context::BCID;
339 }
else if(ctx.P == Context::BCID) {
341 std::vector<float>
P;
343 std::copy(istream_iterator<float>(S), istream_iterator<float>(), back_inserter(
P));
346 ": expected 3 parameters got " + std::to_string(
P.size()));
348 if(std::binary_search(ctx.poly.begin(), ctx.poly.end(), B)) {
349 params[ctx.E][B] = make_unique<ParamFuncPol2>(
P[0],
P[1],
P[2]);
350 }
else if(std::binary_search(ctx.exp.begin(), ctx.exp.end(), B)) {
351 params[ctx.E][B] = make_unique<ParamFuncExp>(
P[0],
P[1],
P[2]);
353 throw ParseException(
"BCID '" + std::to_string(B) +
"' didn't appear in 'poly' or 'exp' for element '" +
354 std::to_string(ctx.E) +
"'.");
357 if(++ctx.N == (ctx.poly.size() + ctx.exp.size())) {
368 for(
auto& V : params) {
369 if(std::find_if(V.begin(), V.end(), [](std::unique_ptr<ParamFunc>& p) { return p == nullptr; }) != V.end()) {
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
@ BunchCrossings
Distance in units of 25 nanoseconds.
static constexpr int m_MAX_BCID
bool isFilled(const bcid_type bcid) const
The simplest query: Is the bunch crossing filled or not?
@ MiddleEmpty
An empty BCID in the middle of a train.
virtual double operator()(double mu)=0
std::string m_inputFileEMShort
static const unsigned s_nElements
void parseInputFile(const std::string &fileName, std::vector< std::vector< std::unique_ptr< ParamFunc > > > ¶ms)
std::string m_inputFileEMLong
virtual int dynamicPedestal(int iEta, int layer, int pedestal, int iBCID, float mu) const override
retrieve the bcidCorrection value
L1DynamicPedestalProviderTxt(const std::string &, const std::string &, const IInterface *)
constructor
virtual StatusCode initialize() override
standard Athena-Algorithm method
virtual ~L1DynamicPedestalProviderTxt()
default destructor
static const unsigned s_nBCIDPerTrain
std::pair< bool, int > distanceFromHeadOfTrain(int bcid) const
std::array< std::vector< std::vector< std::unique_ptr< ParamFunc > > >, 2 > m_emParameterizations
std::string m_inputFileHADShort
std::string m_inputFileHADLong
SG::ReadCondHandleKey< BunchCrossingCondData > m_bcDataKey
std::array< std::vector< std::vector< std::unique_ptr< ParamFunc > > >, 2 > m_hadParameterizations
virtual double operator()(double mu)
ParamFuncExp(double p0, double p1, double p2)
std::array< double, 3 > m_p
std::array< double, 3 > m_p
ParamFuncPol2(double p0, double p1, double p2)
virtual double operator()(double mu)
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
std::string tail(std::string s, const std::string &pattern)
tail of a string
std::string head(std::string s, const std::string &pattern)
head of a string
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...