ATLAS Offline Software
Loading...
Searching...
No Matches
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
6#include <TParameter.h>
7
8#include <exception>
9
10template <typename T>
11T 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
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
47 get_value_parameter<double>(*m_file, "sensitivity_temperature_barrel");
49 get_value_parameter<double>(*m_file, "sensitivity_temperature_endcapA");
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
67 temp.barrel = 1. - (temp.barrel - base_temperature.barrel) *
69 temp.endcapA = 1. - (temp.endcapA - base_temperature.endcapA) *
71 temp.endcapC = 1. - (temp.endcapC - base_temperature.endcapC) *
73 return temp;
74}
75
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
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) {
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}
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
if(febId1==febId2)
T get_value_parameter(TFile &f, const std::string &name)
LArTemperatureCorrectionTool(const std::string &filename)
AllValues get_corrections(int run)
correction should be applied on MC as a multiplication: E = E * correction
AsgMessaging(const std::string &name)
Constructor with a name.
Definition run.py:1