ATLAS Offline Software
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 
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 
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 
40  get_value_parameter<double>(*m_file, "base_temperature_barrel");
42  get_value_parameter<double>(*m_file, "base_temperature_endcapA");
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) = "
57  << "/" << base_temperature.endcapC);
58  ATH_MSG_INFO("sensitivity relE/K (barrel/endcapA/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 }
LArTemperatureCorrectionTool::base_temperature
AllValues base_temperature
Definition: LArTemperatureCorrectionTool.h:54
LArTemperatureCorrectionTool::AllValues::barrel
double barrel
Definition: LArTemperatureCorrectionTool.h:36
LArTemperatureCorrectionTool::m_first_run
int m_first_run
Definition: LArTemperatureCorrectionTool.h:63
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
get_value_parameter
T get_value_parameter(TFile &f, const std::string &name)
Definition: LArTemperatureCorrectionTool.cxx:11
LArTemperatureCorrectionTool::search_temperature
AllValues search_temperature(int run)
Definition: LArTemperatureCorrectionTool.cxx:77
LArTemperatureCorrectionTool::m_file
std::unique_ptr< TFile > m_file
Definition: LArTemperatureCorrectionTool.h:58
skel.it
it
Definition: skel.GENtoEVGEN.py:396
asg
Definition: DataHandleTestTool.h:28
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
LArTemperatureCorrectionTool.h
LArTemperatureCorrectionTool::m_tree
TTree * m_tree
Definition: LArTemperatureCorrectionTool.h:59
m_file
std::unique_ptr< TFile > m_file
description: this is a custom writer for the old-school drivers that don't use an actual writer
Definition: OutputStreamData.cxx:52
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
LArTemperatureCorrectionTool::AllValues::endcapC
double endcapC
Definition: LArTemperatureCorrectionTool.h:38
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArTemperatureCorrectionTool::search_correction
AllValues search_correction(int run)
Definition: LArTemperatureCorrectionTool.cxx:65
hist_file_dump.f
f
Definition: hist_file_dump.py:135
run
Definition: run.py:1
LArTemperatureCorrectionTool::m_last_run
int m_last_run
Definition: LArTemperatureCorrectionTool.h:63
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
LArTemperatureCorrectionTool::sensitivity_temperature
AllValues sensitivity_temperature
Definition: LArTemperatureCorrectionTool.h:55
LArTemperatureCorrectionTool::AllValues
Definition: LArTemperatureCorrectionTool.h:35
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
LArTemperatureCorrectionTool::AllValues::endcapA
double endcapA
Definition: LArTemperatureCorrectionTool.h:37
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
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_cache
std::map< int, AllValues > m_cache
Definition: LArTemperatureCorrectionTool.h:62
LArTemperatureCorrectionTool::LArTemperatureCorrectionTool
LArTemperatureCorrectionTool(const std::string &filename)
Definition: LArTemperatureCorrectionTool.cxx:19