ATLAS Offline Software
Loading...
Searching...
No Matches
PileupProfileWeight.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9#include <fstream>
10
12 std::ifstream fs(m_weightsFile);
13 try {
14 m_weightsMap = nlohmann::json::parse(fs);
15 } catch (const std::exception&) {
16 ATH_MSG_ERROR("Failed to parse input " << m_weightsFile);
17 return StatusCode::FAILURE;
18 }
19 return StatusCode::SUCCESS;
20}
21
22StatusCode PileupProfileWeight::getValue(double& value) const {
23 const xAOD::EventInfo* evt {nullptr};
24 ATH_CHECK(evtStore()->retrieve(evt, "EventInfo"));
25
26 auto mu_actual = static_cast<std::size_t>(std::ceil(evt->actualInteractionsPerCrossing()));
27 auto mu = std::to_string(mu_actual);
28
29 // mu values that are not included in the weight mapping will be skipped
30 if (m_weightsMap.find(mu) == m_weightsMap.end()) {
31 value = 0.0;
32 return StatusCode::SUCCESS;
33 }
34
35 // retrieve the weigths
36 try {
37 auto wt = m_weightsMap.at(mu).get<double>();
38 value = wt;
39 } catch (const std::exception&) {
40 ATH_MSG_ERROR("Failed to get the mu weight!");
41 return StatusCode::FAILURE;
42 }
43
44 return StatusCode::SUCCESS;
45}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
static Double_t fs
Gaudi::Property< std::string > m_weightsFile
nlohmann::json m_weightsMap
virtual StatusCode initialize() override
virtual StatusCode getValue(double &value) const override
EventInfo_v1 EventInfo
Definition of the latest event info version.