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  : AthAlgTool(type, name, parent) {
19  declareInterface<DerivationFramework::IAugmentationTool>(this);
20  }
21 
22  // Athena initialize and finalize
24 
25  // Resolve the path to the centrality definition file
26  std::string resolvedPath = PathResolver::find_file(m_centralityDefinitionFile, "CALIBPATH");
27 
28  // Debug message to print the resolved path or indicate failure
29  if (resolvedPath.empty()) {
30  ATH_MSG_ERROR("Could not find centrality definition file: " << m_centralityDefinitionFile);
31  return StatusCode::FAILURE;
32  }
33 
34  std::ifstream infile(resolvedPath);
35  if (!infile.is_open()) {
36  ATH_MSG_ERROR("Could not open centrality definition file: " << resolvedPath);
37  return StatusCode::FAILURE;
38  }
39 
40  std::string line;
41  for (int i = 0; i < 3; ++i) {
42  std::getline(infile, line); // Skip header lines
43  }
44 
45  while (std::getline(infile, line)) {
46  std::istringstream iss(line);
47  std::string centileStr;
48  float fCal, centile;
49 
50  if (iss >> centileStr >> std::skipws >> fCal) {
51  centileStr.pop_back(); // Remove '%' character
52  centile = std::stof(centileStr);
53  m_centralityPercentiles.push_back(centile);
54  m_fCalValues.push_back(fCal);
55  } else {
56  ATH_MSG_WARNING("Could not parse line: " << line);
57  }
58  }
59 
60  infile.close();
61  return StatusCode::SUCCESS;
62  }
63 
65  {
66  // Load event EventInfo
67  const xAOD::EventInfo* eventInfo = nullptr;
68  ATH_CHECK(evtStore()->retrieve( eventInfo ));
69 
70  // Set up the decorators for centrality
71  const static SG::AuxElement::Decorator< float > ecCentralityMin("CentralityMin") ;
72  const static SG::AuxElement::Decorator< float > ecCentralityMax("CentralityMax") ;
73 
74  const static SG::AuxElement::ConstAccessor<float> acc_FCalEtA("FCalEtA");
75  const static SG::AuxElement::ConstAccessor<float> acc_FCalEtC("FCalEtC");
76 
77  // Calculate total FCal ET
78  float total_fcal_et = (acc_FCalEtA(*eventInfo) + acc_FCalEtC(*eventInfo)) / 1.e6;
79 
80  float centralityMin = 0.0;
81  float centralityMax = 100.0;
82  bool foundRange = false;
83  for (size_t i = 0; i < m_fCalValues.size(); ++i) {
84  if (total_fcal_et < m_fCalValues[i]) {
85  centralityMin = m_centralityPercentiles[i];
86  foundRange = true;
87  break;
88  }
89  centralityMax = m_centralityPercentiles[i];
90  }
91  if (!foundRange) {
92  // Top possible range
93  centralityMin = 80.;
94  }
95 
96  // Decorate eventInfo with centrality values
97  ecCentralityMin(*eventInfo) = centralityMin;
98  ecCentralityMax(*eventInfo) = centralityMax;
99 
100  return StatusCode::SUCCESS;
101  }
102 }
103 
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
checkFileSG.line
line
Definition: checkFileSG.py:75
run.infile
string infile
Definition: run.py:13
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
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
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
DerivationFramework::HICentralityDecorationTool::addBranches
virtual StatusCode addBranches() const override
Pass the thinning service
Definition: HICentralityDecorationTool.cxx:64
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:23
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:221
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthAlgTool
Definition: AthAlgTool.h:26