ATLAS Offline Software
HICentralityDecorationTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include <vector>
9 #include <fstream>
10 
11 namespace DerivationFramework
12 {
13  HICentralityDecorationTool::HICentralityDecorationTool(const std::string& type, const std::string& name, const IInterface* parent)
14  : base_class(type, name, parent) {
15  }
16 
17  // Athena initialize and finalize
19 
21  // Resolve the path to the centrality definition file
22  std::string resolvedPath = PathResolver::find_file(m_centralityDefinitionFile, "CALIBPATH");
23 
24  // Debug message to print the resolved path or indicate failure
25  if (resolvedPath.empty()) {
26  ATH_MSG_ERROR("Could not find centrality definition file: " << m_centralityDefinitionFile);
27  return StatusCode::FAILURE;
28  }
29 
30  std::ifstream infile(resolvedPath);
31  if (!infile.is_open()) {
32  ATH_MSG_ERROR("Could not open centrality definition file: " << resolvedPath);
33  return StatusCode::FAILURE;
34  }
35 
36  std::string line;
37  for (int i = 0; i < 3; ++i) {
38  std::getline(infile, line); // Skip header lines
39  }
40 
41  while (std::getline(infile, line)) {
42  std::istringstream iss(line);
43  std::string centileStr;
44  float fCal, centile;
45 
46  if (iss >> centileStr >> std::skipws >> fCal) {
47  centileStr.pop_back(); // Remove '%' character
48  centile = std::stof(centileStr);
49  m_centralityPercentiles.push_back(centile);
50  m_fCalValues.push_back(fCal);
51  } else {
52  ATH_MSG_WARNING("Could not parse line: " << line);
53  }
54  }
55 
56  infile.close();
57  return StatusCode::SUCCESS;
58  }
59 
60  StatusCode HICentralityDecorationTool::addBranches(const EventContext& ctx) const
61  {
62  // Load event EventInfo
64 
65  // Set up the decorators for centrality
66  const static SG::AuxElement::Decorator< float > ecCentralityMin("CentralityMin") ;
67  const static SG::AuxElement::Decorator< float > ecCentralityMax("CentralityMax") ;
68 
69  const static SG::AuxElement::ConstAccessor<float> acc_FCalEtA("FCalEtA");
70  const static SG::AuxElement::ConstAccessor<float> acc_FCalEtC("FCalEtC");
71 
72  // Calculate total FCal ET
73  float total_fcal_et = (acc_FCalEtA(*eventInfo) + acc_FCalEtC(*eventInfo)) / 1.e6;
74 
75  float centralityMin = 0.0;
76  float centralityMax = 100.0;
77  bool foundRange = false;
78  for (size_t i = 0; i < m_fCalValues.size(); ++i) {
79  if (total_fcal_et < m_fCalValues[i]) {
80  centralityMin = m_centralityPercentiles[i];
81  foundRange = true;
82  break;
83  }
84  centralityMax = m_centralityPercentiles[i];
85  }
86  if (!foundRange) {
87  // Top possible range
88  centralityMin = 0.;
89  }
90 
91  // Decorate eventInfo with centrality values
92  ecCentralityMin(*eventInfo) = centralityMin;
93  ecCentralityMax(*eventInfo) = centralityMax;
94 
95  return StatusCode::SUCCESS;
96  }
97 }
98 
DerivationFramework::HICentralityDecorationTool::m_fCalValues
std::vector< float > m_fCalValues
Definition: HICentralityDecorationTool.h:34
run.infile
string infile
Definition: run.py:13
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::HICentralityDecorationTool::m_centralityPercentiles
std::vector< float > m_centralityPercentiles
Definition: HICentralityDecorationTool.h:33
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
dq_defect_bulk_create_defects.line
line
Definition: dq_defect_bulk_create_defects.py:27
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
DerivationFramework::HICentralityDecorationTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override
Definition: HICentralityDecorationTool.cxx:60
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
lumiFormat.i
int i
Definition: lumiFormat.py:85
DerivationFramework::HICentralityDecorationTool::initialize
StatusCode initialize() override final
Definition: HICentralityDecorationTool.cxx:18
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::HICentralityDecorationTool::HICentralityDecorationTool
HICentralityDecorationTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: HICentralityDecorationTool.cxx:13
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
DerivationFramework::HICentralityDecorationTool::m_centralityDefinitionFile
Gaudi::Property< std::string > m_centralityDefinitionFile
Definition: HICentralityDecorationTool.h:31
EventInfo.h
DerivationFramework::HICentralityDecorationTool::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: HICentralityDecorationTool.h:30
HICentralityDecorationTool.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition: PathResolver.cxx:221