ATLAS Offline Software
HITowerWeightTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 HITowerWeightTool::HITowerWeightTool(const std::string& type, const std::string& name, const IInterface* parent) :
9  base_class(type, name, parent),
10  m_h3W(nullptr),
11  m_h3Eta(nullptr),
12  m_h3Phi(nullptr),
13  m_h3Mag(nullptr),
14  m_h3EtaPhiResponse(nullptr),
15  m_h3EtaPhiOffset(nullptr)
16 {
17 }
18 
19 
20 float HITowerWeightTool::getWeight(float eta, float phi, int sample) const
21 {
22  return m_h3W->GetBinContent(m_h3W->FindFixBin(eta,phi,sample));
23 }
24 float HITowerWeightTool::getWeightEta(float eta, float phi, int sample) const
25 {
26  return m_h3Eta->GetBinContent(m_h3Eta->FindFixBin(eta,phi,sample));
27 }
28 float HITowerWeightTool::getWeightPhi(float eta, float phi, int sample) const
29 {
30  return m_h3Phi->GetBinContent(m_h3Phi->FindFixBin(eta,phi,sample));
31 }
32 float HITowerWeightTool::getWeightMag(float eta, float phi, int sample) const
33 {
34  return m_h3Mag->GetBinContent(m_h3Mag->FindFixBin(eta,phi,sample));
35 }
36 
37 
38 float HITowerWeightTool::getEtaPhiResponse(float eta, float phi, int runIndex) const
39 {
40  if(runIndex<=0) return 1;
41 
42  int eb=std::as_const(m_h3EtaPhiResponse)->GetXaxis()->FindFixBin(eta);
43  int pb=std::as_const(m_h3EtaPhiResponse)->GetYaxis()->FindFixBin(phi);
44  return m_h3EtaPhiResponse->GetBinContent(eb,pb,runIndex);
45 }
46 
47 
48 float HITowerWeightTool::getEtaPhiOffset(float eta, float phi, int runIndex) const
49 {
50  if(runIndex<=0) return 0;
51 
52  int eb=std::as_const(m_h3EtaPhiOffset)->GetXaxis()->FindFixBin(eta);
53  int pb=std::as_const(m_h3EtaPhiOffset)->GetYaxis()->FindFixBin(phi);
54  return m_h3EtaPhiOffset->GetBinContent(eb,pb,runIndex)*std::cosh(eta);
55 }
56 
57 
58 int HITowerWeightTool::getRunIndex(const EventContext& ctx) const
59 {
60  if (!m_applycorrection){
61  ATH_MSG_DEBUG("Using unit weights and doing no eta-phi correction.");
62  return 0;
63  }
64 
65  unsigned int run_number=ctx.eventID().run_number();
66 
67  auto itr=m_runMap.find(run_number);
68  if(itr==m_runMap.end())
69  {
70  //trying generic run numbers <=> no run dependence
72  {
73  auto itrg=m_runMap.find(run_number);
74  if(itrg!=m_runMap.end())
75  {
76  ATH_MSG_DEBUG("Using run " << run_number << " generic calibration for eta-phi correction.");
77  return itrg->second;
78  }
79  }
80 
81  if(m_defaultRunNumbers.empty())
82  {
83  ATH_MSG_WARNING("No calibration for " << run_number << " is avaliable and no generic run numbers were set. Doing no eta-phi correction.");
84  }
85  else
86  {
87  std::string str_defaultRunNumbers="";
89  {
90  str_defaultRunNumbers+=std::to_string(run_number)+", ";
91  }
92  str_defaultRunNumbers.resize(str_defaultRunNumbers.length()-2);
93 
94  ATH_MSG_WARNING("No calibration for " << run_number << " is avaliable; no generic calibration for runs "<<str_defaultRunNumbers<<". Doing no eta-phi correction.");
95  }
96 
97  return 0;
98  }
99  else
100  {
101  return itr->second;
102  }
103 }
104 
105 
107 {
108  std::string local_path = static_cast<std::string>(m_configDir)+m_inputFile;
109  std::string full_path=PathResolverFindCalibFile(local_path);
110  ATH_MSG_INFO("Reading input file "<< m_inputFile << " from " << full_path);
111  TFile* f=TFile::Open(full_path.c_str());
112  if(f==nullptr)
113  {
114  ATH_MSG_FATAL("Cannot read config file " << full_path );
115  return StatusCode::FAILURE;
116  }
117 
118  m_h3W=(TH3F*)f->GetObjectChecked("h3_w","TH3F");
119  if(m_h3W==nullptr)
120  {
121  ATH_MSG_FATAL("Cannot find TH3F m_h3W in config file " << full_path );
122  return StatusCode::FAILURE;
123  }
124 
125  m_h3Eta=(TH3F*)f->GetObjectChecked("h3_eta","TH3F");
126  if(m_h3Eta==nullptr)
127  {
128  ATH_MSG_FATAL("Cannot find TH3F m_h3Eta in config file " << full_path );
129  return StatusCode::FAILURE;
130  }
131 
132  m_h3Phi=(TH3F*)f->GetObjectChecked("h3_phi","TH3F");
133  if(m_h3Phi==nullptr)
134  {
135  ATH_MSG_FATAL("Cannot find TH3F m_h3Phi in config file " << full_path );
136  return StatusCode::FAILURE;
137  }
138 
139  m_h3Mag=(TH3F*)f->GetObjectChecked("h3_R","TH3F");
140  if(m_h3Mag==nullptr)
141  {
142  ATH_MSG_FATAL("Cannot find TH3F m_h3Mag in config file " << full_path );
143  return StatusCode::FAILURE;
144  }
145 
146  m_h3W->SetDirectory(0);
147  m_h3Eta->SetDirectory(0);
148  m_h3Phi->SetDirectory(0);
149  m_h3Mag->SetDirectory(0);
150 
152  {
153  ATH_MSG_DEBUG("ApplyCorrection is set to true, now loading h3_eta_phi_response, h3_eta_phi_offset, and h1_run_index.");
154 
155  m_h3EtaPhiResponse=(TH3F*)f->GetObjectChecked("h3_eta_phi_response","TH3F");
156  if(m_h3EtaPhiResponse==nullptr)
157  {
158  ATH_MSG_FATAL("Cannot find TH3F h3_eta_phi_response in config file " << full_path );
159  return StatusCode::FAILURE;
160  }
161  m_h3EtaPhiResponse->SetDirectory(0);
162  m_h3EtaPhiOffset=(TH3F*)f->GetObjectChecked("h3_eta_phi_offset","TH3F");
163  if(m_h3EtaPhiOffset==nullptr)
164  {
165  ATH_MSG_FATAL("Cannot find TH3F h3_eta_phi_offset in config file " << full_path );
166  return StatusCode::FAILURE;
167  }
168  m_h3EtaPhiOffset->SetDirectory(0);
169 
170  TH1I* h1_run_index=(TH1I*)f->GetObjectChecked("h1_run_index","TH1I");
171  if(h1_run_index==nullptr)
172  {
173  ATH_MSG_FATAL("Cannot find TH3F h1_run_index in config file " << full_path );
174  return StatusCode::FAILURE;
175  }
176  for(int xbin=1; xbin<=h1_run_index->GetNbinsX(); xbin++) {
177  m_runMap.emplace_hint(m_runMap.end(),std::make_pair(h1_run_index->GetBinContent(xbin),xbin));
178  }
179  }
180  else
181  {
182  ATH_MSG_DEBUG("ApplyCorrection is set to false, not loading h3_eta_phi_response, h3_eta_phi_offset, and h1_run_index.");
183  }
184 
185  f->Close();
186  return StatusCode::SUCCESS;
187 }
HITowerWeightTool::getEtaPhiResponse
virtual float getEtaPhiResponse(float eta, float phi, int runIndex) const override
Definition: HITowerWeightTool.cxx:38
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
HITowerWeightTool::m_h3Phi
TH3F * m_h3Phi
Definition: HITowerWeightTool.h:46
plotting.plot_kinematics.run_number
run_number
Definition: plot_kinematics.py:29
HITowerWeightTool::m_h3EtaPhiOffset
TH3F * m_h3EtaPhiOffset
Definition: HITowerWeightTool.h:49
HITowerWeightTool::m_inputFile
Gaudi::Property< std::string > m_inputFile
Definition: HITowerWeightTool.h:41
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
keylayer_zslicemap.pb
pb
Definition: keylayer_zslicemap.py:188
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HITowerWeightTool::m_h3EtaPhiResponse
TH3F * m_h3EtaPhiResponse
Definition: HITowerWeightTool.h:48
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
HITowerWeightTool::getWeightMag
virtual float getWeightMag(float eta, float phi, int sampling) const override
Definition: HITowerWeightTool.cxx:32
HITowerWeightTool::m_h3W
TH3F * m_h3W
Definition: HITowerWeightTool.h:44
HITowerWeightTool::getWeightEta
virtual float getWeightEta(float eta, float phi, int sampling) const override
Definition: HITowerWeightTool.cxx:24
HITowerWeightTool::getWeight
virtual float getWeight(float eta, float phi, int sampling) const override
Definition: HITowerWeightTool.cxx:20
HITowerWeightTool::m_defaultRunNumbers
Gaudi::Property< std::vector< int > > m_defaultRunNumbers
Definition: HITowerWeightTool.h:40
HITowerWeightTool::m_applycorrection
Gaudi::Property< bool > m_applycorrection
Definition: HITowerWeightTool.h:38
HITowerWeightTool::HITowerWeightTool
HITowerWeightTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: HITowerWeightTool.cxx:8
HITowerWeightTool::getWeightPhi
virtual float getWeightPhi(float eta, float phi, int sampling) const override
Definition: HITowerWeightTool.cxx:28
HITowerWeightTool.h
HITowerWeightTool::getRunIndex
virtual int getRunIndex(const EventContext &ctx) const override
Definition: HITowerWeightTool.cxx:58
HITowerWeightTool::m_runMap
std::map< unsigned int, int > m_runMap
Definition: HITowerWeightTool.h:50
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
hist_file_dump.f
f
Definition: hist_file_dump.py:135
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
HITowerWeightTool::m_h3Eta
TH3F * m_h3Eta
Definition: HITowerWeightTool.h:45
HITowerWeightTool::m_configDir
Gaudi::Property< std::string > m_configDir
Definition: HITowerWeightTool.h:42
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
HITowerWeightTool::initialize
virtual StatusCode initialize() override
Definition: HITowerWeightTool.cxx:106
HITowerWeightTool::m_h3Mag
TH3F * m_h3Mag
Definition: HITowerWeightTool.h:47
HITowerWeightTool::getEtaPhiOffset
virtual float getEtaPhiOffset(float eta, float phi, int runIndex) const override
Definition: HITowerWeightTool.cxx:48