ATLAS Offline Software
Loading...
Searching...
No Matches
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
11namespace DerivationFramework
12{
13 // Athena initialize
15
16 ATH_CHECK( m_eventInfoKey.initialize() );
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
virtual StatusCode addBranches(const EventContext &ctx) const override
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:575
THE reconstruction tool.