ATLAS Offline Software
Loading...
Searching...
No Matches
PileupCalibStep.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
18PileupCalibStep::PileupCalibStep(const std::string& name)
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 if(m_doResidual) ATH_MSG_DEBUG("Residual pile up correction will be applied.");
31
32 if(m_doMuOnly) ATH_MSG_INFO("Only the pileup mu-based calibration will be applied.");
33 if(m_doNPVOnly) ATH_MSG_INFO("Only the pileup NPV-based calibration will be applied.");
34
35 // Protections
36 CHECK_THEN_ERROR(!m_doJetArea && !m_doResidual, "No correction requested to be applied, must be a misconfiguration!");
38 "It was requested to apply only the mu-based AND the NPV-based calibrations.");
39
40 CHECK_THEN_ERROR((m_mu_ref==-99 && !m_doNPVOnly), "OffsetCorrection.DefaultMuRef not specified.");
41
42 CHECK_THEN_ERROR( (m_NPV_ref==-99 && !m_doMuOnly), "OffsetCorrection.DefaultNPVRef not specified.");
43
44 return StatusCode::SUCCESS;
45}
46
48
49 ATH_MSG_DEBUG("Applying the pile up correction");
50
51 double rho=0;
52 if(m_doJetArea){
54 CHECK_THEN_ERROR(!eventShape.isValid() , "Could not retrieve xAOD::EventShape : "<< m_rhoKey.key());
55 CHECK_THEN_ERROR(!eventShape->getDensity(xAOD::EventShape::Density, rho ),
56 "Could not retrieve xAOD::EventShape::Density from xAOD::EventShape "<< m_rhoKey.key() );
57 ATH_MSG_DEBUG(" Rho = " << 0.001*rho << " GeV");
58 }
59
60 double muCorr=0;
61 int NPV=0;
62 if(m_doResidual){
64 CHECK_THEN_ERROR( ! eventInfoDecor.isPresent() , "EventInfo decoration not available! "<< m_muKey.key() );
65 double mu = eventInfoDecor(0);
66 //mu rescaling
67 muCorr = m_isData ? mu : mu*m_muSF;
69 CHECK_THEN_ERROR( ! PVCont.isValid() , "No Primary Vertices "<< m_pvKey.key() );
70 NPV = JetCalibUtils::countNPV(*PVCont);
71 }
72
77
79
80 for( xAOD::Jet * jet : jetCont){
81
82 xAOD::JetFourMom_t jetStartP4 = startScaleMomAcc.getAttribute(*jet);
83
84 const double E_det = jetStartP4.e();
85 const double pT_det = jetStartP4.pt();
86 const double mass_det = jetStartP4.mass();
87
88 if ( E_det < mass_det ) {
89 ATH_MSG_ERROR("PileupCalibStep: jet mass (" << mass_det << " MeV) is greater than E (" << E_det << " MeV!) Aborting.");
90 return StatusCode::FAILURE;
91 }
92
93 double pT_offset = pT_det; // pT difference before/after pileup corrections
94 double pileup_SF = 1; // final calibration factor applied to the four vector
95
96 xAOD::JetFourMom_t calibP4;
97
98 if(m_doJetArea){
99 xAOD::JetFourMom_t jetareaP4 = areaAcc.getAttribute(*jet);
100 ATH_MSG_VERBOSE(" Area = " << jetareaP4);
101
102 xAOD::JetFourMom_t rhoAreaP4;
103 pT_offset = pT_det - rho*jetareaP4.pt();
104 rhoAreaP4 = jetStartP4*pT_offset/pT_det;
105 outAreaScaleMomAcc.setAttribute(*jet, rhoAreaP4);
106 }
107
108 if(m_doResidual){
109 double alpha = 0.0, beta = 0.0;
110
111 if(!m_doNPVOnly){
112 alpha = m_histTool_mu->getValue(*jet, jc);
113 }
114 if(!m_doMuOnly){
115 beta = m_histTool_NPV->getValue(*jet, jc);
116 }
117
118 double offsetET = (alpha*(muCorr-m_mu_ref) + beta*(NPV-m_NPV_ref))*m_GeV;
119 pT_offset = pT_offset - offsetET;
120 }
121
122 // Set the jet pT to 10 MeV if the pT is negative after the jet area and residual offset corrections
123 pileup_SF = pT_offset >= 0 ? pT_offset / pT_det : 10./pT_det;
124
125 calibP4 = jetStartP4*pileup_SF;
126
127 //Transfer calibrated jet properties to the jet
128 outScaleMomAcc.setAttribute(*jet, calibP4 );
129 jet->setJetP4( calibP4 );
130 }
131
132 return StatusCode::SUCCESS;
133}
#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:27
Gaudi::Property< float > m_muSF
static constexpr float m_GeV
Gaudi::Property< float > m_mu_ref
virtual StatusCode calibrate(xAOD::JetContainer &jetCont) const override
Apply calibration to a jet container.
PileupCalibStep(const std::string &name="PileupCalibStep")
Gaudi::Property< std::string > m_jetOutScale
Gaudi::Property< bool > m_doMuOnly
Gaudi::Property< bool > m_doJetArea
Gaudi::Property< bool > m_doNPVOnly
ToolHandle< JetHelper::IVarTool > m_histTool_mu
Histograms with PU residual correction factors.
Gaudi::Property< std::string > m_jetInScale
In and out scales.
Gaudi::Property< std::string > m_jetAreaOutScale
Gaudi::Property< float > m_NPV_ref
Properties.
Gaudi::Property< bool > m_isData
Gaudi::Property< bool > m_doResidual
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
SG::ReadHandleKey< xAOD::EventShape > m_rhoKey
Event properties.
SG::ReadHandleKey< xAOD::VertexContainer > m_pvKey
ToolHandle< JetHelper::IVarTool > m_histTool_NPV
SG::ReadDecorHandleKey< xAOD::EventInfo > m_muKey
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