ATLAS Offline Software
Loading...
Searching...
No Matches
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
8HITowerWeightTool::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
20float HITowerWeightTool::getWeight(float eta, float phi, int sample) const
21{
22 return m_h3W->GetBinContent(m_h3W->FindFixBin(eta,phi,sample));
23}
24float HITowerWeightTool::getWeightEta(float eta, float phi, int sample) const
25{
26 return m_h3Eta->GetBinContent(m_h3Eta->FindFixBin(eta,phi,sample));
27}
28float HITowerWeightTool::getWeightPhi(float eta, float phi, int sample) const
29{
30 return m_h3Phi->GetBinContent(m_h3Phi->FindFixBin(eta,phi,sample));
31}
32float HITowerWeightTool::getWeightMag(float eta, float phi, int sample) const
33{
34 return m_h3Mag->GetBinContent(m_h3Mag->FindFixBin(eta,phi,sample));
35}
36
37
38float 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
48float 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
58int HITowerWeightTool::getRunIndex(const EventContext& ctx) const
59{
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
71 for(auto run_number : m_defaultRunNumbers)
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="";
88 for(auto run_number : m_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}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Gaudi::Property< std::vector< int > > m_defaultRunNumbers
Gaudi::Property< std::string > m_configDir
virtual float getEtaPhiOffset(float eta, float phi, int runIndex) const override
virtual int getRunIndex(const EventContext &ctx) const override
HITowerWeightTool(const std::string &type, const std::string &name, const IInterface *parent)
virtual float getWeightEta(float eta, float phi, int sampling) const override
virtual StatusCode initialize() override
virtual float getWeightMag(float eta, float phi, int sampling) const override
virtual float getEtaPhiResponse(float eta, float phi, int runIndex) const override
std::map< unsigned int, int > m_runMap
Gaudi::Property< std::string > m_inputFile
virtual float getWeight(float eta, float phi, int sampling) const override
virtual float getWeightPhi(float eta, float phi, int sampling) const override
Gaudi::Property< bool > m_applycorrection