ATLAS Offline Software
Loading...
Searching...
No Matches
PileupProfileWeight Class Reference

This class provides the weight used to reweight pileup (mu) distribution by querying JSON. More...

#include <PileupProfileWeight.h>

Inheritance diagram for PileupProfileWeight:
Collaboration diagram for PileupProfileWeight:

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode getValue (double &value) const override

Private Attributes

Gaudi::Property< std::string > m_weightsFile {this, "WeightsFile", "", "Path to the weights file"}
nlohmann::json m_weightsMap

Detailed Description

This class provides the weight used to reweight pileup (mu) distribution by querying JSON.

Definition at line 19 of file PileupProfileWeight.h.

Member Function Documentation

◆ getValue()

StatusCode PileupProfileWeight::getValue ( double & value) const
overridevirtual

Definition at line 22 of file PileupProfileWeight.cxx.

22 {
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)
nlohmann::json m_weightsMap
EventInfo_v1 EventInfo
Definition of the latest event info version.

◆ initialize()

StatusCode PileupProfileWeight::initialize ( )
overridevirtual

Definition at line 11 of file PileupProfileWeight.cxx.

11 {
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}
static Double_t fs
Gaudi::Property< std::string > m_weightsFile

Member Data Documentation

◆ m_weightsFile

Gaudi::Property<std::string> PileupProfileWeight::m_weightsFile {this, "WeightsFile", "", "Path to the weights file"}
private

Definition at line 27 of file PileupProfileWeight.h.

27{this, "WeightsFile", "", "Path to the weights file"};

◆ m_weightsMap

nlohmann::json PileupProfileWeight::m_weightsMap
private

Definition at line 28 of file PileupProfileWeight.h.


The documentation for this class was generated from the following files: