ATLAS Offline Software
HICentralityDecorationTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // HICentralityDecorationTool.cxx, (c) ATLAS Detector software
8 
12 #include <vector>
13 #include <fstream>
14 
15 namespace DerivationFramework
16 {
17  HICentralityDecorationTool::HICentralityDecorationTool(const std::string& type, const std::string& name, const IInterface* parent)
18  : base_class(type, name, parent) {
19  }
20 
21  // Athena initialize and finalize
23 
24  // Resolve the path to the centrality definition file
25  std::string resolvedPath = PathResolver::find_file(m_centralityDefinitionFile, "CALIBPATH");
26 
27  // Debug message to print the resolved path or indicate failure
28  if (resolvedPath.empty()) {
29  ATH_MSG_ERROR("Could not find centrality definition file: " << m_centralityDefinitionFile);
30  return StatusCode::FAILURE;
31  }
32 
33  std::ifstream infile(resolvedPath);
34  if (!infile.is_open()) {
35  ATH_MSG_ERROR("Could not open centrality definition file: " << resolvedPath);
36  return StatusCode::FAILURE;
37  }
38 
39  std::string line;
40  for (int i = 0; i < 3; ++i) {
41  std::getline(infile, line); // Skip header lines
42  }
43 
44  while (std::getline(infile, line)) {
45  std::istringstream iss(line);
46  std::string centileStr;
47  float fCal, centile;
48 
49  if (iss >> centileStr >> std::skipws >> fCal) {
50  centileStr.pop_back(); // Remove '%' character
51  centile = std::stof(centileStr);
52  m_centralityPercentiles.push_back(centile);
53  m_fCalValues.push_back(fCal);
54  } else {
55  ATH_MSG_WARNING("Could not parse line: " << line);
56  }
57  }
58 
59  infile.close();
60  return StatusCode::SUCCESS;
61  }
62 
64  {
65  // Load event EventInfo
66  const xAOD::EventInfo* eventInfo = nullptr;
67  ATH_CHECK(evtStore()->retrieve( eventInfo ));
68 
69  // Set up the decorators for centrality
70  const static SG::AuxElement::Decorator< float > ecCentralityMin("CentralityMin") ;
71  const static SG::AuxElement::Decorator< float > ecCentralityMax("CentralityMax") ;
72 
73  const static SG::AuxElement::ConstAccessor<float> acc_FCalEtA("FCalEtA");
74  const static SG::AuxElement::ConstAccessor<float> acc_FCalEtC("FCalEtC");
75 
76  // Calculate total FCal ET
77  float total_fcal_et = (acc_FCalEtA(*eventInfo) + acc_FCalEtC(*eventInfo)) / 1.e6;
78 
79  float centralityMin = 0.0;
80  float centralityMax = 100.0;
81  bool foundRange = false;
82  for (size_t i = 0; i < m_fCalValues.size(); ++i) {
83  if (total_fcal_et < m_fCalValues[i]) {
84  centralityMin = m_centralityPercentiles[i];
85  foundRange = true;
86  break;
87  }
88  centralityMax = m_centralityPercentiles[i];
89  }
90  if (!foundRange) {
91  // Top possible range
92  centralityMin = 0.;
93  }
94 
95  // Decorate eventInfo with centrality values
96  ecCentralityMin(*eventInfo) = centralityMin;
97  ecCentralityMax(*eventInfo) = centralityMax;
98 
99  return StatusCode::SUCCESS;
100  }
101 }
102 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
DerivationFramework::HICentralityDecorationTool::m_fCalValues
std::vector< float > m_fCalValues
Definition: HICentralityDecorationTool.h:36
run.infile
string infile
Definition: run.py:13
DerivationFramework::HICentralityDecorationTool::m_centralityPercentiles
std::vector< float > m_centralityPercentiles
Definition: HICentralityDecorationTool.h:35
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 override
Definition: HICentralityDecorationTool.cxx:63
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:22
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:17
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
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:33
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
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:183