ATLAS Offline Software
Loading...
Searching...
No Matches
BcidOffsetCorrection.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <utility>
6
11
16
17BcidOffsetCorrection::BcidOffsetCorrection(const std::string& name, TEnv* config, TString jetAlgo, TString calibAreaTag, bool isData)
18 : JetCalibrationStep(name.c_str()),
19 m_config(config), m_jetAlgo(std::move(jetAlgo)), m_calibAreaTag(std::move(calibAreaTag)), m_isData(isData)
20{}
21
23= default;
24
26
27 ATH_MSG_INFO("Initializing BCID offset correction");
28
29 if(!m_config){
30 ATH_MSG_ERROR("BCID offset correction tool received a null config pointer.");
31 return StatusCode::FAILURE;
32 }
33
34 m_doEMECIW2bcid = m_config->GetValue("ApplyEMECIW2bcid",true);
35 m_doEMECIW3bcid = m_config->GetValue("ApplyEMECIW3bcid",false);
36 m_doHEC0bcid = m_config->GetValue("ApplyHEC0bcid",true);
37 m_doHEC1bcid = m_config->GetValue("ApplyHEC1bcid",true);
38 m_doHEC2bcid = m_config->GetValue("ApplyHEC2bcid",false);
39 m_doHEC3bcid = m_config->GetValue("ApplyHEC3bcid",false);
40 m_doFCal0OuterBcid = m_config->GetValue("ApplyFCal0OuterBcid",false);
41 m_doFCal1OuterBcid = m_config->GetValue("ApplyFCal1OuterBcid",false);
42 m_doFCal2OuterBcid = m_config->GetValue("ApplyFCal2OuterBcid",false);
43 m_doFCal0bcid = m_config->GetValue("ApplyFCal0bcid",true);
44 m_doFCal1bcid = m_config->GetValue("ApplyFCal1bcid",false);
45 m_doFCal2bcid = m_config->GetValue("ApplyFCal2bcid",false);
46 m_doFCal0InnerBcid = m_config->GetValue("ApplyFCal0InnerBcid",false);
47 m_doFCal1InnerBcid = m_config->GetValue("ApplyFCal1InnerBcid",false);
48 m_doFCal2InnerBcid = m_config->GetValue("ApplyFCal2InnerBcid",false);
49
51 ATH_MSG_ERROR("You are attempting to apply the BCID offset correction to the EMEC3 or HEC back wheel cells which is not implemented.");
52 return StatusCode::FAILURE;
53 }
55 ATH_MSG_ERROR("You are attempting to apply the BCID offset correction to the outer small FCal cells which is not implemented.");
56 return StatusCode::FAILURE;
57 }
59 ATH_MSG_ERROR("You are attempting to apply the BCID offset correction to the large FCal1/2 cells which is not implemented.");
60 return StatusCode::FAILURE;
61 }
63 ATH_MSG_ERROR("You are attempting to apply the BCID offset correction to the inner small FCal cells which is not implemented.");
64 return StatusCode::FAILURE;
65 }
66
67 m_jetStartScale = m_config->GetValue("BcidStartingScale","JetConstitScaleMomentum");
68
69 //find the ROOT file containing the BCID slopes and numbers of cells.
70 TString BCIDFile = m_config->GetValue("BCIDOffsetFile","");
71 if ( BCIDFile.EqualTo("empty") ) {
72 ATH_MSG_ERROR("No BCIDOffsetFile specified. Aborting.");
73 return StatusCode::FAILURE;
74 }
75 BCIDFile.Insert(14,m_calibAreaTag);
76 TString fileName = PathResolverFindCalibFile(BCIDFile.Data());
77 std::unique_ptr<TFile> inputFile(TFile::Open(fileName));
78 if (!inputFile){
79 ATH_MSG_ERROR("Cannot open BCID offset calibration file" << fileName);
80 return StatusCode::FAILURE;
81 }
82
83 m_bcid_nCells_EMECIW2 = JetCalibUtils::GetHisto2(*inputFile,"bcid_nCells_EMECIW2");
84 m_bcid_nCells_HEC0 = JetCalibUtils::GetHisto2(*inputFile,"bcid_nCells_HEC0");
85 m_bcid_nCells_HEC1 = JetCalibUtils::GetHisto2(*inputFile,"bcid_nCells_HEC1");
86 m_bcid_nCells_FCal0 = JetCalibUtils::GetHisto2(*inputFile,"bcid_nCells_FCal0big");
87
88 m_bcid_slope_EMECIW2_pos = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_EMECIW2_pos");
89 m_bcid_slope_EMECIW2_neg = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_EMECIW2_neg");
90 m_bcid_slope_HEC0_pos = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_HEC0_pos");
91 m_bcid_slope_HEC0_neg = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_HEC0_neg");
92 m_bcid_slope_HEC1_pos = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_HEC1_pos");
93 m_bcid_slope_HEC1_neg = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_HEC1_neg");
94 m_bcid_slope_FCal0 = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_FCal0big");
95
96 m_bcid_slope_EMECIW2_8b4e_pos = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_EMECIW2_8b4e_pos");
97 m_bcid_slope_EMECIW2_8b4e_neg = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_EMECIW2_8b4e_neg");
98 m_bcid_slope_HEC0_8b4e_pos = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_HEC0_8b4e_pos");
99 m_bcid_slope_HEC0_8b4e_neg = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_HEC0_8b4e_neg");
100 m_bcid_slope_HEC1_8b4e_pos = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_HEC1_8b4e_pos");
101 m_bcid_slope_HEC1_8b4e_neg = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_HEC1_8b4e_neg");
102 m_bcid_slope_FCal0_8b4e = JetCalibUtils::GetHisto2(*inputFile,"bcid_slope_FCal0big_8b4e");
103
104 return StatusCode::SUCCESS;
105}
106
108
109 // correction should only be applied to data
110 if (!m_isData){
111 jet.setAttribute<xAOD::JetFourMom_t>("JetBcidScaleMomentum",jet.jetP4());
112 return StatusCode::SUCCESS;
113 }
114
115 xAOD::JetFourMom_t jetStartP4;
117 jetStartP4 = jet.jetP4();
118
119 float startPt=jet.pt();
120 float calibPt=jet.pt();
121
122 // if we are not looking at 2017 or 2018 data then apply no correction and pass on the new jet name
123 if (jetEventInfo.runNumber()>358656 || jetEventInfo.runNumber()<325713){
124 jet.setAttribute<xAOD::JetFourMom_t>("JetBcidScaleMomentum",jetStartP4);
125 return StatusCode::SUCCESS;
126 }
127
128 bool is8b4e=false;
129 if (jetEventInfo.runNumber()>=334842 && jetEventInfo.runNumber()<=340453) is8b4e=true;
130
131 int bcidDistanceFromFront = jetEventInfo.bcidDistanceFromFront();
132 int bcidGapBeforeTrain = jetEventInfo.bcidGapBeforeTrain();
133 int bcidGapBeforeTrainMinus12 = jetEventInfo.bcidGapBeforeTrainMinus12();
134 if (!is8b4e){// this separates the sub-trains
135 if (bcidGapBeforeTrain<=15) bcidDistanceFromFront+=55;
136 }
137 if (is8b4e){// this separates sub-trains and the 1st and 2nd sets of 8b4e
138 if (bcidGapBeforeTrain==5 && bcidGapBeforeTrainMinus12==5) bcidDistanceFromFront+=24;
139 if (bcidGapBeforeTrain>5 && bcidGapBeforeTrain<20) bcidDistanceFromFront+=60;
140 if (bcidGapBeforeTrain==5 && bcidGapBeforeTrainMinus12>5 && bcidGapBeforeTrainMinus12<20) bcidDistanceFromFront+=72;
141 if (bcidGapBeforeTrain==5 && bcidGapBeforeTrainMinus12>20) bcidDistanceFromFront+=12;
142 }
143
144 xAOD::JetFourMom_t calibP4;
145 calibP4 = jet.jetP4();
146 static const SG::ConstAccessor<float> DetectorEtaAcc ("DetectorEta");
147 float detEta=DetectorEtaAcc(jet);
148 float mu=jetEventInfo.mu();
149
150 if (m_doEMECIW2bcid && !is8b4e){
151 if ((bcidDistanceFromFront>=0 && bcidDistanceFromFront<12) || (bcidDistanceFromFront>=55 && bcidDistanceFromFront<67)){// only apply correction to 1st 12 BCIDs
152 for (unsigned int i=1; i<=7; i++){
153 float nCells = m_bcid_nCells_EMECIW2->GetBinContent(i,static_cast<int>(abs(detEta)*10.0+1.0));
154 float slope = 0;
155 if (detEta>0) slope = m_bcid_slope_EMECIW2_pos->GetBinContent(i,bcidDistanceFromFront+1);
156 if (detEta<0) slope = m_bcid_slope_EMECIW2_neg->GetBinContent(i,bcidDistanceFromFront+1);
157 calibPt -= mu*nCells*slope;
158 }
159 }
160 }
161 if (m_doEMECIW2bcid && is8b4e){
162 if (bcidDistanceFromFront>=0 && bcidDistanceFromFront<115){// apply to all BCIDs
163 for (unsigned int i=1; i<=7; i++){
164 float nCells = m_bcid_nCells_EMECIW2->GetBinContent(i,static_cast<int>(abs(detEta)*10.0+1.0));
165 float slope = 0;
166 if (detEta>0) slope = m_bcid_slope_EMECIW2_8b4e_pos->GetBinContent(i,bcidDistanceFromFront+1);
167 if (detEta<0) slope = m_bcid_slope_EMECIW2_8b4e_neg->GetBinContent(i,bcidDistanceFromFront+1);
168 calibPt -= mu*nCells*slope;
169 }
170 }
171 }
172 if (m_doHEC0bcid && !is8b4e){
173 if ((bcidDistanceFromFront>=0 && bcidDistanceFromFront<10) || (bcidDistanceFromFront>=55 && bcidDistanceFromFront<65) || bcidDistanceFromFront==47 || bcidDistanceFromFront==102){// only apply correction to 1st 10 and last BCIDs
174 for (unsigned int i=1; i<=4; i++){
175 float nCells = m_bcid_nCells_HEC0->GetBinContent(i,static_cast<int>(abs(detEta)*10.0+1.0));
176 float slope = 0;
177 if (detEta>0) slope = m_bcid_slope_HEC0_pos->GetBinContent(i,bcidDistanceFromFront+1);
178 if (detEta<0) slope = m_bcid_slope_HEC0_neg->GetBinContent(i,bcidDistanceFromFront+1);
179 calibPt -= mu*nCells*slope;
180 }
181 }
182 }
183 if (m_doHEC0bcid && is8b4e){
184 if (bcidDistanceFromFront>=0 && bcidDistanceFromFront<115){// apply to all BCIDs
185 for (unsigned int i=1; i<=4; i++){
186 float nCells = m_bcid_nCells_HEC0->GetBinContent(i,static_cast<int>(abs(detEta)*10.0+1.0));
187 float slope = 0;
188 if (detEta>0) slope = m_bcid_slope_HEC0_8b4e_pos->GetBinContent(i,bcidDistanceFromFront+1);
189 if (detEta<0) slope = m_bcid_slope_HEC0_8b4e_neg->GetBinContent(i,bcidDistanceFromFront+1);
190 calibPt -= mu*nCells*slope;
191 }
192 }
193 }
194 if (m_doHEC1bcid && !is8b4e){
195 if ((bcidDistanceFromFront>=0 && bcidDistanceFromFront<10) || (bcidDistanceFromFront>=55 && bcidDistanceFromFront<65) || bcidDistanceFromFront==47 || bcidDistanceFromFront==102){// only apply correction to 1st 10 and last BCIDs
196 for (unsigned int i=1; i<=3; i++){
197 float nCells = m_bcid_nCells_HEC1->GetBinContent(i,static_cast<int>(abs(detEta)*10.0+1.0));
198 float slope = 0;
199 if (detEta>0) slope = m_bcid_slope_HEC1_pos->GetBinContent(i,bcidDistanceFromFront+1);
200 if (detEta<0) slope = m_bcid_slope_HEC1_neg->GetBinContent(i,bcidDistanceFromFront+1);
201 calibPt -= mu*nCells*slope;
202 }
203 }
204 }
205 if (m_doHEC1bcid && is8b4e){
206 if (bcidDistanceFromFront>=0 && bcidDistanceFromFront<115){// apply to all BCIDs
207 for (unsigned int i=1; i<=3; i++){
208 float nCells = m_bcid_nCells_HEC1->GetBinContent(i,static_cast<int>(abs(detEta)*10.0+1.0));
209 float slope = 0;
210 if (detEta>0) slope = m_bcid_slope_HEC1_8b4e_pos->GetBinContent(i,bcidDistanceFromFront+1);
211 if (detEta<0) slope = m_bcid_slope_HEC1_8b4e_neg->GetBinContent(i,bcidDistanceFromFront+1);
212 calibPt -= mu*nCells*slope;
213 }
214 }
215 }
216 if (m_doFCal0bcid && !is8b4e){
217 if ((bcidDistanceFromFront>=0 && bcidDistanceFromFront<12) || (bcidDistanceFromFront>=55 && bcidDistanceFromFront<67)){// only apply correction to 1st 12 BCIDs
218 for (unsigned int i=1; i<=6; i++){
219 float nCells = m_bcid_nCells_FCal0->GetBinContent(i,static_cast<int>(abs(detEta)*10.0+1.0));
220 float slope = 0;
221 slope = m_bcid_slope_FCal0->GetBinContent(i,bcidDistanceFromFront+1);
222 calibPt -= mu*nCells*slope;
223 }
224 }
225 }
226 if (m_doFCal0bcid && is8b4e){
227 if (bcidDistanceFromFront>=0 && bcidDistanceFromFront<115){// apply to all BCIDs
228 for (unsigned int i=1; i<=6; i++){
229 float nCells = m_bcid_nCells_FCal0->GetBinContent(i,static_cast<int>(abs(detEta)*10.0+1.0));
230 float slope = 0;
231 slope = m_bcid_slope_FCal0_8b4e->GetBinContent(i,bcidDistanceFromFront+1);
232 calibPt -= mu*nCells*slope;
233 }
234 }
235 }
236
237 calibP4*=calibPt/startPt;
238
239 //Transfer calibrated jet properties to the Jet object
240 jet.setAttribute<xAOD::JetFourMom_t>("JetBcidScaleMomentum",calibP4);
241 jet.setJetP4( calibP4 );
242
243 return StatusCode::SUCCESS;
244}
245
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
Helper class to provide constant type-safe access to aux data.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
std::unique_ptr< const TH2 > m_bcid_nCells_HEC0
std::unique_ptr< const TH2 > m_bcid_slope_HEC1_neg
std::unique_ptr< const TH2 > m_bcid_slope_HEC0_pos
std::unique_ptr< const TH2 > m_bcid_slope_EMECIW2_8b4e_pos
std::unique_ptr< const TH2 > m_bcid_slope_HEC1_8b4e_pos
std::unique_ptr< const TH2 > m_bcid_nCells_FCal0
std::unique_ptr< const TH2 > m_bcid_slope_EMECIW2_pos
std::unique_ptr< const TH2 > m_bcid_slope_EMECIW2_neg
std::unique_ptr< const TH2 > m_bcid_slope_HEC0_8b4e_pos
std::unique_ptr< const TH2 > m_bcid_slope_HEC1_pos
std::unique_ptr< const TH2 > m_bcid_slope_HEC0_8b4e_neg
virtual StatusCode initialize() override
virtual StatusCode calibrate(xAOD::Jet &jet, JetEventInfo &) const override
std::unique_ptr< const TH2 > m_bcid_nCells_EMECIW2
std::unique_ptr< const TH2 > m_bcid_slope_HEC0_neg
std::unique_ptr< const TH2 > m_bcid_slope_FCal0
std::unique_ptr< const TH2 > m_bcid_slope_HEC1_8b4e_neg
virtual ~BcidOffsetCorrection()
std::unique_ptr< const TH2 > m_bcid_nCells_HEC1
std::unique_ptr< const TH2 > m_bcid_slope_FCal0_8b4e
std::unique_ptr< const TH2 > m_bcid_slope_EMECIW2_8b4e_neg
virtual StatusCode setStartP4(xAOD::Jet &jet) const
JetCalibrationStep(const char *name="JetCalibrationStep")
Int_t bcidGapBeforeTrainMinus12()
UInt_t runNumber()
Int_t bcidDistanceFromFront()
Int_t bcidGapBeforeTrain()
double mu()
Helper class to provide constant type-safe access to aux data.
std::unique_ptr< const TH2 > GetHisto2(TFile &file, const TString &hname)
STL namespace.
Jet_v1 Jet
Definition of the current "jet version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17