ATLAS Offline Software
PileupAreaCalibStep.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <TEnv.h>
7 
9 
11 #include "xAODJet/JetAccessors.h"
13 
15  : asg::AsgTool( name ) { }
16 
17 
18 
19 
21 
22  ATH_MSG_INFO("Initializing pileup area correction.");
23 
24  ATH_CHECK( m_rhoKey.initialize() );
25  return StatusCode::SUCCESS;
26 }
27 
29 
31  double rho=0;
32  if(!rhRhoKey.isValid()){
33  ATH_MSG_FATAL("Could not retrieve xAOD::EventShape DataHandle : "<< m_rhoKey.key());
34  return StatusCode::FAILURE;
35  }
36  const xAOD::EventShape * eventShape = rhRhoKey.cptr();
37 
38  if ( !eventShape->getDensity( xAOD::EventShape::Density, rho ) ) {
39  ATH_MSG_FATAL("Could not retrieve xAOD::EventShape::Density from xAOD::EventShape "<< m_rhoKey.key());
40  return StatusCode::FAILURE;
41  }
42 
43  ATH_MSG_DEBUG(" Rho = " << 0.001*rho << " GeV");
44 
46  const xAOD::JetAttributeAccessor::AccessorWrapper<xAOD::JetFourMom_t> puScaleMomAcc("JetPileupScaleMomentum");
47  SG::AuxElement::Accessor<int> puCorrectedAcc("PileupCorrected");
48  for(xAOD::Jet *jet : jetCont){
49 
50  xAOD::JetFourMom_t jetStartP4 = jet->jetP4();
51  xAOD::JetFourMom_t jetareaP4 = areaAcc.getAttribute(*jet);
52  ATH_MSG_VERBOSE(" Area = " << jetareaP4);
53 
54  xAOD::JetFourMom_t calibP4;
55 
56 
58  calibP4 = jetStartP4 - rho*jetareaP4;
59  } else {
60  ATH_MSG_VERBOSE(" Applying postive-only area-subtraction calibration to jet " << jet->index() << " with pT = " << 0.001*jet->pt() << " GeV");
61  const double pT_det = jetStartP4.pt();
62  const double E_det = jetStartP4.e();
63  //Set the jet pT to 10 MeV if the pT or energy is negative after the jet area correction
64  const double area_SF = (pT_det-rho*jetareaP4.pt()<=0 || E_det-rho*jetareaP4.e()<=0) ? 10/pT_det : (pT_det-rho*jetareaP4.pt())/pT_det;
65  calibP4 = jetStartP4*area_SF;
66  }
67 
68  //Attribute to track if a jet has received the pileup subtraction (always true if this code was run)
69  puCorrectedAcc(*jet) = 1 ;
70  //Transfer calibrated jet properties to the Jet object
71  puScaleMomAcc.setAttribute(*jet, calibP4 );
72  jet->setJetP4( calibP4 );
73  }
74  return StatusCode::SUCCESS;
75 }
76 
xAOD::EventShape_v1::getDensity
bool getDensity(EventDensityID id, double &v) const
Get a density variable from the object.
Definition: EventShape_v1.cxx:135
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::JetAttributeAccessor::AccessorWrapper::setAttribute
void setAttribute(SG::AuxElement &p, const TYPE &v) const
Definition: JetAccessors.h:54
asg
Definition: DataHandleTestTool.h:28
xAOD::JetAttributeAccessor::AccessorWrapper::getAttribute
void getAttribute(const SG::AuxElement &p, TYPE &v) const
Definition: JetAccessors.h:58
PileupAreaCalibStep::m_useFull4vectorArea
Gaudi::Property< bool > m_useFull4vectorArea
Definition: PileupAreaCalibStep.h:40
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
IJetCalibrationTool.h
xAOD::EventShape_v1::Density
@ Density
Definition: EventShape_v1.h:47
PileupAreaCalibStep::m_rhoKey
SG::ReadHandleKey< xAOD::EventShape > m_rhoKey
Definition: PileupAreaCalibStep.h:38
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
PileupAreaCalibStep::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: PileupAreaCalibStep.cxx:20
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PileupAreaCalibStep::calibrate
virtual StatusCode calibrate(xAOD::JetContainer &jetCont) const override
Apply calibration to a jet container.
Definition: PileupAreaCalibStep.cxx:28
PileupAreaCalibStep.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::EventShape_v1
Data class for event shapes.
Definition: EventShape_v1.h:28
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
PileupAreaCalibStep::PileupAreaCalibStep
PileupAreaCalibStep(const std::string &name="PileupAreaCalibStep")
Definition: PileupAreaCalibStep.cxx:14
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::JetAttributeAccessor::AccessorWrapper< xAOD::JetFourMom_t >
ReadDecorHandle.h
Handle class for reading a decoration on an object.
JetAccessors.h
This header defines wrapper classes around SG::AuxElement::Accessor used internally in the Jet EDM.
fitman.rho
rho
Definition: fitman.py:532