ATLAS Offline Software
Loading...
Searching...
No Matches
PileupAreaResidualCalibStep.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
10
12
14
15#include <memory>
16#include <utility>
17
19 : asg::AsgTool( name ) { }
20
22
23 ATH_MSG_DEBUG("Reading from " << m_jetInScale << " and writing to " << m_jetOutScale);
24
25 ATH_CHECK( m_muKey.initialize() );
26 ATH_CHECK( m_pvKey.initialize() );
27 ATH_CHECK( m_rhoKey.initialize() );
28
29 if(m_doJetArea) ATH_MSG_DEBUG("Jet area pile up correction will be applied.");
30
31 if(m_doSequentialResidual) ATH_MSG_INFO("The pileup residual calibrations will be applied sequentially.");
32 else ATH_MSG_DEBUG("The pileup residual calibrations will be applied simultaneously (default).");
33
34 if(m_doMuOnly) ATH_MSG_INFO("Only the pileup mu-based calibration will be applied.");
35 if(m_doNPVOnly) ATH_MSG_INFO("Only the pileup NPV-based calibration will be applied.");
36
37 // Protections
39 "Sequential residual calibration can not be applied in doMuOnly or doNPVOnly cases.");
40
42 "It was requested to apply only the mu-based AND the NPV-based calibrations.");
43
45 "OffsetCorrection.DefaultMuRef not specified.");
46
48 "OffsetCorrection.DefaultNPVRef not specified.");
49
50 return StatusCode::SUCCESS;
51}
52
54
55 ATH_MSG_DEBUG("Calibrating jet collection with 1D pile-up correction");
56
58 CHECK_THEN_ERROR( ! eventInfoDecor.isPresent() , "EventInfo decoration not available! "<< m_muKey.key() );
59 double mu = eventInfoDecor(0);
60
62 CHECK_THEN_ERROR( ! PVCont.isValid() , "No Primary Vertices "<< m_pvKey.key() );
63 double NPV = JetCalibUtils::countNPV(*PVCont);
64
66 CHECK_THEN_ERROR( ! eventShape.isValid() , "Could not retrieve xAOD::EventShape : "<< m_rhoKey.key());
67 double rho=0;
68 CHECK_THEN_ERROR( ! eventShape->getDensity(xAOD::EventShape::Density, rho ),
69 "Could not retrieve xAOD::EventShape::Density from xAOD::EventShape "<< m_rhoKey.key() );
70
71 ATH_MSG_DEBUG(" Rho = " << 0.001*rho << " GeV");
72
76
78
79 for( xAOD::Jet * jet : jetCont){
80
81 xAOD::JetFourMom_t jetStartP4 = startScaleMomAcc.getAttribute(*jet);
82
83 const double E_det = jetStartP4.e();
84 const double pT_det = jetStartP4.pt();
85 const double mass_det = jetStartP4.mass();
86
87 if ( E_det < mass_det ) {
88 ATH_MSG_ERROR( "PileupAreaResidualCalibStep: jet has mass=" << mass_det << " MeV, which is greater than it's energy=" << E_det << " MeV! Aborting." );
89 return StatusCode::FAILURE;
90 }
91
92 xAOD::JetFourMom_t jetareaP4 = areaAcc.getAttribute(*jet);
93 ATH_MSG_VERBOSE(" Area = " << jetareaP4);
94
95 double offsetET = 0; // pT residual subtraction
96 double pT_offset = pT_det; // pT difference before/after pileup corrections
97 double pileup_SF = 1; // final calibration factor applied to the four vector
98
99 xAOD::JetFourMom_t calibP4;
100 if(!m_doSequentialResidual){ // Default, both corrections are applied simultaneously
101 offsetET = getResidualOffset(*jet, jc, mu, NPV, m_doMuOnly, m_doNPVOnly);
102
103 // Calculate the pT after jet areas and residual offset
104 pT_offset = m_doJetArea ? pT_det - rho*jetareaP4.pt() - offsetET : pT_det - offsetET;
105
106 // Set the jet pT to 10 MeV if the pT is negative after the jet area and residual offset corrections
107 pileup_SF = pT_offset >= 0 ? pT_offset / pT_det : 10./pT_det;
108
109 calibP4 = jetStartP4*pileup_SF;
110
111 }else{
112 // Calculate mu-based correction factor
113 offsetET = getResidualOffset(*jet, jc, mu, NPV, true, false);
114 pT_offset = m_doJetArea ? pT_det - rho*jetareaP4.pt() - offsetET : pT_det - offsetET;
115 double muSF = pT_offset >= 0 ? pT_offset / pT_det : 10./pT_det;
116 calibP4 = jetStartP4*muSF;
117
118 // Calculate and apply NPV/Njet-based calibration
119 offsetET = getResidualOffset(*jet, jc, mu, NPV, false, true);
120 double pT_afterMuCalib = calibP4.pt();
121 pT_offset = pT_afterMuCalib - offsetET;
122 double SF = pT_offset >= 0 ? pT_offset / pT_afterMuCalib : 10./pT_afterMuCalib;
123 calibP4 = calibP4*SF;
124 }
125
126 //Transfer calibrated jet properties to the jet
127 outScaleMomAcc.setAttribute(*jet, calibP4 );
128 jet->setJetP4( calibP4 );
129 }
130
131 return StatusCode::SUCCESS;
132}
133
134double PileupAreaResidualCalibStep::getResidualOffset(const xAOD::Jet& jet, const JetHelper::JetContext& jc, double mu, double NPV, bool MuOnly, bool NPVOnly) const{
135
136 double alpha = 0.0, beta = 0.0;
137
138 if(!NPVOnly){
139 alpha = m_histTool_mu->getValue(jet, jc);
140 }
141 if(!MuOnly){
142 beta = m_histTool_NPV->getValue(jet, jc);
143 }
144
145 static const double toMeV= 1000.;
146 //mu rescaling
147 const double muCorr = m_isData ? mu : mu*m_muSF;
148
149 return (alpha*(muCorr-m_mu_ref) + beta*(NPV-m_NPV_ref))*toMeV;
150}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
This header defines wrapper classes around SG::AuxElement::Accessor used internally in the Jet EDM.
#define CHECK_THEN_ERROR(checkcode, message)
Class JetContext Designed to read AOD information related to the event, N vertices,...
Definition JetContext.h:23
PileupAreaResidualCalibStep(const std::string &name="PileupAreaResidualCalibStep")
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Gaudi::Property< std::string > m_jetInScale
In and out scales.
Gaudi::Property< bool > m_doMuOnly
Properties.
SG::ReadHandleKey< xAOD::EventShape > m_rhoKey
Event properties.
virtual StatusCode calibrate(xAOD::JetContainer &jetCont) const override
Apply calibration to a jet container.
ToolHandle< JetHelper::IVarTool > m_histTool_mu
Histograms with PU residual correction factors.
ToolHandle< JetHelper::IVarTool > m_histTool_NPV
Gaudi::Property< bool > m_doSequentialResidual
double getResidualOffset(const xAOD::Jet &jet, const JetHelper::JetContext &jc, double mu, double NPV, bool MuOnly, bool NOnly) const
SG::ReadDecorHandleKey< xAOD::EventInfo > m_muKey
SG::ReadHandleKey< xAOD::VertexContainer > m_pvKey
Gaudi::Property< std::string > m_jetOutScale
Handle class for reading a decoration on an object.
bool isPresent() const
Is the referenced container present in SG?
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
void getAttribute(const SG::AuxElement &p, TYPE &v) const
void setAttribute(SG::AuxElement &p, const TYPE &v) const
int countNPV(const VXCONT &vxCont)
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