ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
ElectronPhotonID
ElectronPhotonFourMomentumCorrection
Root
LArTemperatureCorrectionTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include <
ElectronPhotonFourMomentumCorrection/LArTemperatureCorrectionTool.h
>
6
#include <TParameter.h>
7
8
#include <exception>
9
10
template
<
typename
T>
11
T
get_value_parameter
(TFile& f,
const
std::string& name) {
12
TParameter<T>* p =
dynamic_cast<
TParameter<T>*
>
(f.Get(name.c_str()));
13
if
(not p) {
14
return
0;
15
}
16
return
p->GetVal();
17
}
18
19
LArTemperatureCorrectionTool::LArTemperatureCorrectionTool
(
20
const
std::string& filename)
21
:
asg
::
AsgMessaging
(
"LArTemperatureCorrectionTool"
),
22
m_file
(TFile::Open(filename.c_str())) {
23
if
(!
m_file
or
m_file
->IsZombie()) {
24
throw std::runtime_error(
"LArTemperatureCorrectionTool: Cannot open file"
);
25
}
26
27
m_tree
=
dynamic_cast<
TTree*
>
(
m_file
->Get(
"temperature"
));
28
if
(!
m_tree
) {
29
throw
std::runtime_error(
"LArTemperatureCorrectionTool: Cannot find tree"
);
30
}
31
32
Int_t t_run = 0;
33
m_tree
->SetBranchAddress(
"run"
, &t_run);
34
m_tree
->GetEntry(0);
35
m_first_run
= t_run;
36
m_tree
->GetEntry(
m_tree
->GetEntries() - 1);
37
m_last_run
= t_run;
38
39
base_temperature
.barrel =
40
get_value_parameter<double>
(*
m_file
,
"base_temperature_barrel"
);
41
base_temperature
.endcapA =
42
get_value_parameter<double>
(*
m_file
,
"base_temperature_endcapA"
);
43
base_temperature
.endcapC =
44
get_value_parameter<double>
(*
m_file
,
"base_temperature_endcapC"
);
45
46
sensitivity_temperature
.barrel =
47
get_value_parameter<double>
(*
m_file
,
"sensitivity_temperature_barrel"
);
48
sensitivity_temperature
.endcapA =
49
get_value_parameter<double>
(*
m_file
,
"sensitivity_temperature_endcapA"
);
50
sensitivity_temperature
.endcapC =
51
get_value_parameter<double>
(*
m_file
,
"sensitivity_temperature_endcapC"
);
52
53
ATH_MSG_INFO
(
"LArTemperatureCorrectionTool initialized for runs "
54
<<
m_first_run
<<
".."
<<
m_last_run
);
55
ATH_MSG_INFO
(
"base temperatures (barrel/endcapA/endcapC) = "
56
<<
base_temperature
.barrel <<
"/"
<<
base_temperature
.endcapA
57
<<
"/"
<<
base_temperature
.endcapC);
58
ATH_MSG_INFO
(
"sensitivity relE/K (barrel/endcapA/endcapC) = "
59
<<
sensitivity_temperature
.barrel <<
"/"
60
<<
sensitivity_temperature
.endcapA <<
"/"
61
<<
sensitivity_temperature
.endcapC);
62
}
63
64
LArTemperatureCorrectionTool::AllValues
65
LArTemperatureCorrectionTool::search_correction
(
int
run
) {
66
AllValues
temp =
search_temperature
(
run
);
67
temp.barrel = 1. - (temp.barrel -
base_temperature
.barrel) *
68
sensitivity_temperature
.barrel;
69
temp.endcapA = 1. - (temp.endcapA -
base_temperature
.endcapA) *
70
sensitivity_temperature
.endcapA;
71
temp.endcapC = 1. - (temp.endcapC -
base_temperature
.endcapC) *
72
sensitivity_temperature
.endcapC;
73
return
temp;
74
}
75
76
LArTemperatureCorrectionTool::AllValues
77
LArTemperatureCorrectionTool::search_temperature
(
int
run
) {
78
Float_t t_barrel =
base_temperature
.barrel;
79
Float_t t_endcapA =
base_temperature
.endcapA;
80
Float_t t_endcapC =
base_temperature
.endcapC;
81
Int_t t_run = 0;
82
m_tree
->SetBranchAddress(
"run"
, &t_run);
83
m_tree
->SetBranchAddress(
"average_temperature_barrel"
, &t_barrel);
84
m_tree
->SetBranchAddress(
"average_temperature_endcapA"
, &t_endcapA);
85
m_tree
->SetBranchAddress(
"average_temperature_endcapC"
, &t_endcapC);
86
87
// use bisection, tree is ordered by run number
88
int
low = 0;
89
int
high =
m_tree
->GetEntries() - 1;
90
int
mid = 0;
91
while
(low <= high) {
92
93
if
(high - low < 50) {
// prefer sequential scan
94
for
(
int
i = low; i <= high; ++i) {
95
m_tree
->GetEntry(i);
96
if
(
run
== t_run) {
97
return
AllValues
{t_barrel, t_endcapA, t_endcapC};
98
}
99
}
100
break
;
101
}
102
103
mid = low + (high - low) / 2;
// scared of overflow?
104
m_tree
->GetEntry(mid);
105
if
(
run
== t_run) {
106
return
AllValues
{t_barrel, t_endcapA, t_endcapC};
107
}
else
if
(
run
< t_run) {
108
high = mid - 1;
109
}
else
{
110
low = mid + 1;
111
}
112
}
113
114
ATH_MSG_WARNING
(
"run "
<<
run
<<
" not found - no temperature correction"
);
115
return
base_temperature
;
116
}
117
118
LArTemperatureCorrectionTool::AllValues
119
LArTemperatureCorrectionTool::get_corrections
(
int
run
) {
120
const
auto
it =
m_cache
.find(
run
);
121
if
(it !=
m_cache
.end()) {
122
return
it->second;
123
}
else
{
124
AllValues
corrections{};
125
if
(
run
<
m_first_run
) {
126
ATH_MSG_WARNING
(
127
"run "
<<
run
<<
" is before the first run - using the first run"
);
128
corrections =
search_correction
(
m_first_run
);
129
}
else
if
(
run
>
m_last_run
) {
130
ATH_MSG_WARNING
(
"run "
<<
run
131
<<
" is after the last run - using the last run"
);
132
corrections =
search_correction
(
m_last_run
);
133
}
else
{
134
corrections =
search_correction
(
run
);
135
}
136
m_cache
[
run
] = corrections;
137
return
corrections;
138
}
139
}
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
get_value_parameter
T get_value_parameter(TFile &f, const std::string &name)
Definition
LArTemperatureCorrectionTool.cxx:11
LArTemperatureCorrectionTool.h
if
if(pathvar)
Definition
SealSharedLib.cxx:168
LArTemperatureCorrectionTool::sensitivity_temperature
AllValues sensitivity_temperature
Definition
LArTemperatureCorrectionTool.h:55
LArTemperatureCorrectionTool::m_file
std::unique_ptr< TFile > m_file
Definition
LArTemperatureCorrectionTool.h:58
LArTemperatureCorrectionTool::m_last_run
int m_last_run
Definition
LArTemperatureCorrectionTool.h:63
LArTemperatureCorrectionTool::search_temperature
AllValues search_temperature(int run)
Definition
LArTemperatureCorrectionTool.cxx:77
LArTemperatureCorrectionTool::LArTemperatureCorrectionTool
LArTemperatureCorrectionTool(const std::string &filename)
Definition
LArTemperatureCorrectionTool.cxx:19
LArTemperatureCorrectionTool::search_correction
AllValues search_correction(int run)
Definition
LArTemperatureCorrectionTool.cxx:65
LArTemperatureCorrectionTool::m_cache
std::map< int, AllValues > m_cache
Definition
LArTemperatureCorrectionTool.h:62
LArTemperatureCorrectionTool::base_temperature
AllValues base_temperature
Definition
LArTemperatureCorrectionTool.h:54
LArTemperatureCorrectionTool::get_corrections
AllValues get_corrections(int run)
correction should be applied on MC as a multiplication: E = E * correction
Definition
LArTemperatureCorrectionTool.cxx:119
LArTemperatureCorrectionTool::m_tree
TTree * m_tree
Definition
LArTemperatureCorrectionTool.h:59
LArTemperatureCorrectionTool::m_first_run
int m_first_run
Definition
LArTemperatureCorrectionTool.h:63
asg::AsgMessaging::AsgMessaging
AsgMessaging(const std::string &name)
Constructor with a name.
Definition
AsgMessaging.cxx:17
asg
Definition
DataHandleTestTool.h:28
LArTemperatureCorrectionTool::AllValues
Definition
LArTemperatureCorrectionTool.h:35
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0