ATLAS Offline Software
Loading...
Searching...
No Matches
Generic4VecCorrectionStep.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include <cmath>
9
11 : asg::AsgTool( name ){ }
12
14
15 ATH_MSG_DEBUG("Initializing Generic4VecCorrectionStep tool");
16 ATH_MSG_DEBUG("Reading from " << m_jetInScale << " and writing to " << m_jetOutScale);
17
18 if(m_isMC2MCCorr){
19 std::vector<int> considered_PIDs = {MC::DQUARK,MC::UQUARK,MC::SQUARK,MC::GLUON};
20
21 ATH_CHECK(m_hist_q.retrieve());
22 ATH_CHECK(m_hist_g.retrieve());
24 considered_PIDs.push_back(MC::CQUARK);
25 ATH_CHECK(m_hist_c.retrieve());
26 }
28 considered_PIDs.push_back(MC::BQUARK);
29 ATH_CHECK(m_hist_b.retrieve());
30 }
31
32 for (auto this_PID : considered_PIDs){
33 if(this_PID == MC::DQUARK || this_PID == MC::UQUARK || this_PID == MC::SQUARK){
34 m_correctionHists.try_emplace(this_PID, m_hist_q);
35 } else if(this_PID == MC::CQUARK){
36 m_correctionHists.try_emplace(this_PID, m_hist_c);
37 } else if(this_PID == MC::BQUARK){
38 m_correctionHists.try_emplace(this_PID, m_hist_b);
39 } else if(this_PID == MC::GLUON){
40 m_correctionHists.try_emplace(this_PID, m_hist_g);
41 }
42 }
43 }
44 else{
45 ATH_CHECK(m_histTool.retrieve());
46
48 JetHelper::HistoInputBase* histoTool = dynamic_cast<JetHelper::HistoInputBase*>( &(*m_histTool) );
49 if(histoTool){
50 TH1 *h = &histoTool->getHistogram();
51 m_etaAxis = *(h->GetYaxis());
52 }
53 }
54 }
55
56 return StatusCode::SUCCESS;
57
58}
59
61
62 ATH_MSG_DEBUG("Applying generic four-vector correction");
63
65
66 for(xAOD::Jet* jet: jets){
67
68 const xAOD::JetFourMom_t jetStartP4 = jet->getAttribute<xAOD::JetFourMom_t>(m_jetInScale);
69 jet->setJetP4(jetStartP4);
70
72 // In some cases, we want to avoid the interpolation along eta
73 // Therefore, we set the eta value to the histogram bin center before reading the histograms
75 // Using a varTool lets us configure eta (eta, y, detectorEta) via yaml file
76 int eta_bin = m_etaAxis.FindBin(m_varTool->getValue(*jet, jc));
77 jc.setValue("binCenterEta", m_etaAxis.GetBinCenter(eta_bin));
78 }
79
80 // Get the correction factor:
81 double correctionFactor = 1.0;
82
83 // MC2MC correction depending on the parton truth label
84 if(m_isMC2MCCorr){
85 // Retrieve the parton truth label
86 static const SG::ConstAccessor<int> PartonTruthLabelIDAcc(m_pidLabel);
87 if(!PartonTruthLabelIDAcc.isAvailable(*jet)){
88 ATH_MSG_ERROR("The parton truth label could not be retrieved");
89 return StatusCode::FAILURE;
90 }
91 int label = std::abs(PartonTruthLabelIDAcc(*jet));
92
93 // If this parton truth label ID is in the map, get the correction factor
94 auto correction_from_map = m_correctionHists.find(label);
95 if (correction_from_map != m_correctionHists.end()){
96 auto h_corr_map = correction_from_map->second;
97 correctionFactor = h_corr_map->getValue(*jet, jc);
98 }
99 }
100 // other generic 2D corrections (e.g. AF3, PtResidual)
101 else{
102 correctionFactor = m_histTool->getValue(*jet, jc);
103 }
104
105 xAOD::JetFourMom_t calibP4 = jet->jetP4() * correctionFactor;
106 scaleMomAcc.setAttribute(*jet,calibP4);
107 jet->setJetP4(calibP4);
108 }
109
110 return StatusCode::SUCCESS;
111
112}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Header file for AthHistogramAlgorithm.
Gaudi::Property< std::string > m_jetOutScale
TAxis m_etaAxis
Needed to avoid interpolation between eta bins.
ToolHandle< JetHelper::IVarTool > m_varTool
Variable to be used for bin center.
Generic4VecCorrectionStep(const std::string &name="Generic4VecCorrectionStep")
Constructor with parameters:
Gaudi::Property< bool > m_isMC2MCCorr
Properties for MC2MC correction:
std::map< int, ToolHandle< JetHelper::IVarTool > > m_correctionHists
Gaudi::Property< bool > m_useBinCenter
use bin center to avoid interpolation along eta (e.g. for PtResidual correction)
virtual StatusCode calibrate(xAOD::JetContainer &) const override
Apply calibration to a jet container.
ToolHandle< JetHelper::IVarTool > m_hist_c
2D histogram containing the calibration factors for charm quarks
ToolHandle< JetHelper::IVarTool > m_hist_g
2D histogram containing the calibration factors for gluons
ToolHandle< JetHelper::IVarTool > m_hist_q
2D histogram containing the calibration factors for light quarks
Gaudi::Property< std::string > m_jetInScale
ToolHandle< JetHelper::IVarTool > m_histTool
Generic histogram with correction factor (e.g. 2D)
Gaudi::Property< std::string > m_pidLabel
Which truth label should be used.
Gaudi::Property< bool > m_doCjetCorrection
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
ToolHandle< JetHelper::IVarTool > m_hist_b
2D histogram containing the calibration factors for bottom quarks
Gaudi::Property< bool > m_doBjetCorrection
Class HistoInputBase This class implement common function used by HistoInput1D and HistoInput2D.
TH1 & getHistogram()
Returns the underlying histogram.
Class JetContext Designed to read AOD information related to the event, N vertices,...
Definition JetContext.h:24
bool setValue(const std::string &name, const T value, bool allowOverwrite=false)
Definition JetContext.h:52
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
void setAttribute(SG::AuxElement &p, const TYPE &v) const
std::string label(const std::string &format, int i)
Definition label.h:19
static const int UQUARK
static const int SQUARK
static const int DQUARK
static const int CQUARK
static const int GLUON
static const int BQUARK
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17