ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkHI
src
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
5
#include "
PathResolver/PathResolver.h
"
6
#include "
HICentralityDecorationTool.h
"
7
#include "
xAODEventInfo/EventInfo.h
"
8
#include <vector>
9
#include <fstream>
10
11
namespace
DerivationFramework
12
{
13
// Athena initialize
14
StatusCode
HICentralityDecorationTool::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
59
SG::ReadHandle<xAOD::EventInfo>
eventInfo (
m_eventInfoKey
, ctx);
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
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
HICentralityDecorationTool.h
PathResolver.h
DerivationFramework::HICentralityDecorationTool::initialize
virtual StatusCode initialize() override final
Definition
HICentralityDecorationTool.cxx:14
DerivationFramework::HICentralityDecorationTool::m_fCalValues
std::vector< float > m_fCalValues
Definition
HICentralityDecorationTool.h:35
DerivationFramework::HICentralityDecorationTool::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition
HICentralityDecorationTool.h:31
DerivationFramework::HICentralityDecorationTool::m_centralityPercentiles
std::vector< float > m_centralityPercentiles
Definition
HICentralityDecorationTool.h:34
DerivationFramework::HICentralityDecorationTool::m_centralityDefinitionFile
Gaudi::Property< std::string > m_centralityDefinitionFile
Definition
HICentralityDecorationTool.h:32
DerivationFramework::HICentralityDecorationTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override
Definition
HICentralityDecorationTool.cxx:56
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition
PathResolver.cxx:220
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework
THE reconstruction tool.
Definition
CascadeTools.h:16
EventInfo.h
Generated on
for ATLAS Offline Software by
1.17.0