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  // Athena initialize
15 
17  // Resolve the path to the centrality definition file
18  std::string resolvedPath = PathResolver::find_file(m_centralityDefinitionFile, "CALIBPATH");
19 
20  // Debug message to print the resolved path or indicate failure
21  if (resolvedPath.empty()) {
22  ATH_MSG_ERROR("Could not find centrality definition file: " << m_centralityDefinitionFile);
23  return StatusCode::FAILURE;
24  }
25 
26  std::ifstream infile(resolvedPath);
27  if (!infile.is_open()) {
28  ATH_MSG_ERROR("Could not open centrality definition file: " << resolvedPath);
29  return StatusCode::FAILURE;
30  }
31 
32  std::string line;
33  for (int i = 0; i < 3; ++i) {
34  std::getline(infile, line); // Skip header lines
35  }
36 
37  while (std::getline(infile, line)) {
38  std::istringstream iss(line);
39  std::string centileStr;
40  float fCal, centile;
41 
42  if (iss >> centileStr >> std::skipws >> fCal) {
43  centileStr.pop_back(); // Remove '%' character
44  centile = std::stof(centileStr);
45  m_centralityPercentiles.push_back(centile);
46  m_fCalValues.push_back(fCal);
47  } else {
48  ATH_MSG_WARNING("Could not parse line: " << line);
49  }
50  }
51 
52  infile.close();
53  return StatusCode::SUCCESS;
54  }
55 
56  StatusCode HICentralityDecorationTool::addBranches(const EventContext& ctx) const
57  {
58  // Load event EventInfo
60 
61  // Set up the decorators for centrality
62  const static SG::AuxElement::Decorator< float > ecCentralityMin("CentralityMin") ;
63  const static SG::AuxElement::Decorator< float > ecCentralityMax("CentralityMax") ;
64 
65  const static SG::AuxElement::ConstAccessor<float> acc_FCalEtA("FCalEtA");
66  const static SG::AuxElement::ConstAccessor<float> acc_FCalEtC("FCalEtC");
67 
68  // Calculate total FCal ET
69  float total_fcal_et = (acc_FCalEtA(*eventInfo) + acc_FCalEtC(*eventInfo)) / 1.e6;
70 
71  float centralityMin = 0.0;
72  float centralityMax = 100.0;
73  bool foundRange = false;
74  for (size_t i = 0; i < m_fCalValues.size(); ++i) {
75  if (total_fcal_et < m_fCalValues[i]) {
76  centralityMin = m_centralityPercentiles[i];
77  foundRange = true;
78  break;
79  }
80  centralityMax = m_centralityPercentiles[i];
81  }
82  if (!foundRange) {
83  // Top possible range
84  centralityMin = 0.;
85  }
86 
87  // Decorate eventInfo with centrality values
88  ecCentralityMin(*eventInfo) = centralityMin;
89  ecCentralityMax(*eventInfo) = centralityMax;
90 
91  return StatusCode::SUCCESS;
92  }
93 }
DerivationFramework::HICentralityDecorationTool::m_fCalValues
std::vector< float > m_fCalValues
Definition: HICentralityDecorationTool.h:35
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:34
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
DerivationFramework::HICentralityDecorationTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override
Definition: HICentralityDecorationTool.cxx:56
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
virtual StatusCode initialize() override final
Definition: HICentralityDecorationTool.cxx:14
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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
DerivationFramework::HICentralityDecorationTool::m_centralityDefinitionFile
Gaudi::Property< std::string > m_centralityDefinitionFile
Definition: HICentralityDecorationTool.h:32
EventInfo.h
DerivationFramework::HICentralityDecorationTool::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: HICentralityDecorationTool.h:31
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