ATLAS Offline Software
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 
14  m_config(nullptr), m_jetAlgo(""), m_calibAreaTag(""), m_isData(false)
15 {}
16 
17 BcidOffsetCorrection::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 
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");
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 
BcidOffsetCorrection::m_doFCal0OuterBcid
bool m_doFCal0OuterBcid
Definition: BcidOffsetCorrection.h:47
BcidOffsetCorrection::m_bcid_slope_HEC0_8b4e_pos
std::unique_ptr< const TH2 > m_bcid_slope_HEC0_8b4e_pos
Definition: BcidOffsetCorrection.h:73
JetEventInfo::bcidGapBeforeTrainMinus12
Int_t bcidGapBeforeTrainMinus12()
Definition: JetEventInfo.h:34
BcidOffsetCorrection::calibrate
virtual StatusCode calibrate(xAOD::Jet &jet, JetEventInfo &) const override
Definition: BcidOffsetCorrection.cxx:107
JetEventInfo::bcidGapBeforeTrain
Int_t bcidGapBeforeTrain()
Definition: JetEventInfo.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetCalibrationStep::setStartP4
virtual StatusCode setStartP4(xAOD::Jet &jet) const
Definition: JetCalibrationStep.cxx:21
BcidOffsetCorrection::m_doFCal2InnerBcid
bool m_doFCal2InnerBcid
Definition: BcidOffsetCorrection.h:55
JetCalibUtils::GetHisto2
std::unique_ptr< const TH2 > GetHisto2(TFile &file, const TString &hname)
Definition: JetCalibUtils.cxx:53
BcidOffsetCorrection::m_doFCal1bcid
bool m_doFCal1bcid
Definition: BcidOffsetCorrection.h:51
BcidOffsetCorrection::m_bcid_slope_HEC1_pos
std::unique_ptr< const TH2 > m_bcid_slope_HEC1_pos
Definition: BcidOffsetCorrection.h:64
BcidOffsetCorrection::m_doHEC3bcid
bool m_doHEC3bcid
Definition: BcidOffsetCorrection.h:46
BcidOffsetCorrection::initialize
virtual StatusCode initialize() override
Definition: BcidOffsetCorrection.cxx:25
SG::ConstAccessor< float >
BcidOffsetCorrection::m_config
TEnv * m_config
Definition: BcidOffsetCorrection.h:37
BcidOffsetCorrection::m_doHEC0bcid
bool m_doHEC0bcid
Definition: BcidOffsetCorrection.h:43
BcidOffsetCorrection::m_bcid_slope_FCal0_8b4e
std::unique_ptr< const TH2 > m_bcid_slope_FCal0_8b4e
Definition: BcidOffsetCorrection.h:80
BcidOffsetCorrection::m_doEMECIW3bcid
bool m_doEMECIW3bcid
Definition: BcidOffsetCorrection.h:42
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
BcidOffsetCorrection::m_bcid_slope_HEC1_8b4e_pos
std::unique_ptr< const TH2 > m_bcid_slope_HEC1_8b4e_pos
Definition: BcidOffsetCorrection.h:74
BcidOffsetCorrection::m_bcid_nCells_FCal0
std::unique_ptr< const TH2 > m_bcid_nCells_FCal0
Definition: BcidOffsetCorrection.h:60
BcidOffsetCorrection::m_doFCal2OuterBcid
bool m_doFCal2OuterBcid
Definition: BcidOffsetCorrection.h:49
BcidOffsetCorrection.h
BcidOffsetCorrection::m_bcid_slope_HEC0_neg
std::unique_ptr< const TH2 > m_bcid_slope_HEC0_neg
Definition: BcidOffsetCorrection.h:67
BcidOffsetCorrection::m_doHEC2bcid
bool m_doHEC2bcid
Definition: BcidOffsetCorrection.h:45
JetEventInfo
Definition: JetEventInfo.h:8
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
JetEventInfo::mu
double mu()
Definition: JetEventInfo.h:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
BcidOffsetCorrection::m_doFCal0bcid
bool m_doFCal0bcid
Definition: BcidOffsetCorrection.h:50
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
xAOD::nCells
setRawEt setRawPhi nCells
Definition: TrigCaloCluster_v1.cxx:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
BcidOffsetCorrection::m_bcid_slope_FCal0
std::unique_ptr< const TH2 > m_bcid_slope_FCal0
Definition: BcidOffsetCorrection.h:70
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
BcidOffsetCorrection::m_bcid_nCells_HEC1
std::unique_ptr< const TH2 > m_bcid_nCells_HEC1
Definition: BcidOffsetCorrection.h:59
BcidOffsetCorrection::m_bcid_slope_HEC1_neg
std::unique_ptr< const TH2 > m_bcid_slope_HEC1_neg
Definition: BcidOffsetCorrection.h:68
BcidOffsetCorrection::m_bcid_slope_EMECIW2_neg
std::unique_ptr< const TH2 > m_bcid_slope_EMECIW2_neg
Definition: BcidOffsetCorrection.h:66
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
BcidOffsetCorrection::m_doFCal0InnerBcid
bool m_doFCal0InnerBcid
Definition: BcidOffsetCorrection.h:53
BcidOffsetCorrection::m_bcid_slope_EMECIW2_pos
std::unique_ptr< const TH2 > m_bcid_slope_EMECIW2_pos
Definition: BcidOffsetCorrection.h:62
BcidOffsetCorrection::m_bcid_slope_EMECIW2_8b4e_pos
std::unique_ptr< const TH2 > m_bcid_slope_EMECIW2_8b4e_pos
Definition: BcidOffsetCorrection.h:72
BcidOffsetCorrection::m_bcid_nCells_HEC0
std::unique_ptr< const TH2 > m_bcid_nCells_HEC0
Definition: BcidOffsetCorrection.h:58
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
BcidOffsetCorrection::~BcidOffsetCorrection
virtual ~BcidOffsetCorrection()
PathResolver.h
JetCalibUtils.h
BcidOffsetCorrection::m_bcid_slope_HEC1_8b4e_neg
std::unique_ptr< const TH2 > m_bcid_slope_HEC1_8b4e_neg
Definition: BcidOffsetCorrection.h:78
JetCalibrationStep::m_jetStartScale
std::string m_jetStartScale
Definition: JetCalibrationStep.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
BcidOffsetCorrection::m_doFCal1InnerBcid
bool m_doFCal1InnerBcid
Definition: BcidOffsetCorrection.h:54
BcidOffsetCorrection::m_bcid_slope_HEC0_8b4e_neg
std::unique_ptr< const TH2 > m_bcid_slope_HEC0_8b4e_neg
Definition: BcidOffsetCorrection.h:77
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
BcidOffsetCorrection::m_calibAreaTag
TString m_calibAreaTag
Definition: BcidOffsetCorrection.h:38
BcidOffsetCorrection::m_doFCal1OuterBcid
bool m_doFCal1OuterBcid
Definition: BcidOffsetCorrection.h:48
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
BcidOffsetCorrection::m_isData
bool m_isData
Definition: BcidOffsetCorrection.h:39
BcidOffsetCorrection::m_bcid_slope_EMECIW2_8b4e_neg
std::unique_ptr< const TH2 > m_bcid_slope_EMECIW2_8b4e_neg
Definition: BcidOffsetCorrection.h:76
JetEventInfo::bcidDistanceFromFront
Int_t bcidDistanceFromFront()
Definition: JetEventInfo.h:32
BcidOffsetCorrection::BcidOffsetCorrection
BcidOffsetCorrection()
Definition: BcidOffsetCorrection.cxx:12
BcidOffsetCorrection::m_bcid_slope_HEC0_pos
std::unique_ptr< const TH2 > m_bcid_slope_HEC0_pos
Definition: BcidOffsetCorrection.h:63
BcidOffsetCorrection::m_doHEC1bcid
bool m_doHEC1bcid
Definition: BcidOffsetCorrection.h:44
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
BcidOffsetCorrection::m_bcid_nCells_EMECIW2
std::unique_ptr< const TH2 > m_bcid_nCells_EMECIW2
Definition: BcidOffsetCorrection.h:57
JetEventInfo::runNumber
UInt_t runNumber()
Definition: JetEventInfo.h:31
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
BcidOffsetCorrection::m_doEMECIW2bcid
bool m_doEMECIW2bcid
Definition: BcidOffsetCorrection.h:41
BcidOffsetCorrection::m_doFCal2bcid
bool m_doFCal2bcid
Definition: BcidOffsetCorrection.h:52
JetCalibrationStep
Definition: JetCalibrationStep.h:20