ATLAS Offline Software
Loading...
Searching...
No Matches
InSituCalibStep.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// InSituCalibStep.cxx
8// Implementation file for class InSituCalibStep
10
14
15InSituCalibStep::InSituCalibStep(const std::string& name)
16 : asg::AsgTool( name ){ }
17
19// Public methods:
21
23 ATH_MSG_DEBUG ("Initializing " << name() );
24 ATH_MSG_DEBUG("Reading from " << m_jetInScale << " and writing to " << m_jetOutScale);
25 // Initialise ReadHandle(s)
26 ATH_CHECK( m_evtInfoKey.initialize() );
27
28 if ( m_isMC )
29 ATH_MSG_WARNING("InSituCalibStep::calibrate : Running over MC, will not calibrate unless expert option CalibrateMC is set to true");
30
31 ATH_CHECK( m_histTool_EtaInter.retrieve() );
32 ATH_CHECK( m_histTool_Abs.retrieve() );
33
34 if( m_histTool_Abs.size() != m_histTool_EtaInter.size() )
35 return StatusCode::FAILURE;
36
37 return StatusCode::SUCCESS;
38}
39
40
42
43 ATH_MSG_DEBUG("calibrating jet collection.");
44
45 // Retrieve EventInfo object, for time-dependent calibration and isMC flag
46 unsigned int rNumber = 0;
47 if (retrieveEventInfo(rNumber).isFailure())
48 return StatusCode::FAILURE;
49 if( (bool)(m_isMC) && !( (bool)(m_CalibrateMC)) ) //no calibration
50 return StatusCode::SUCCESS;
51 unsigned int runNumber = static_cast<unsigned int>(rNumber+0.5);
52 // Pick up the correct time-dependent histogram
53 unsigned int periodInd = 9999;
54 for(unsigned int i=0; i<m_RunNumBoundaries.size()-1; i++){
55 unsigned int firstRun = m_RunNumBoundaries[i] + 1.5;
56 unsigned int lastRun = m_RunNumBoundaries[i+1]+0.5;
57 if (firstRun<=runNumber && runNumber <= lastRun ){
58 periodInd = i;
59 break;
60 }
61 }
62
63 if (periodInd==9999){ // periodInd could not be set
64 ATH_MSG_WARNING("No calibration found for run number "<<runNumber);
65 }
66
67 if( periodInd >= m_histTool_Abs.size() ) //outside run numbers, return no calibration
68 return StatusCode::SUCCESS;
69
71 for (xAOD::Jet* jet : jets){
72 const xAOD::JetFourMom_t jetStartP4 = jet->getAttribute<xAOD::JetFourMom_t>(m_jetInScale);
73 jet->setJetP4(jetStartP4);
74
75 // Retrieve absolute and relative calibration factors
76 const double R_abs = m_histTool_Abs[periodInd]->getValue(*jet,jc);
77 double c_rel = m_histTool_EtaInter[periodInd]->getValue(*jet,jc);
78 double correction = c_rel/R_abs;
79
80 xAOD::JetFourMom_t calibP4=jet->jetP4();
81 calibP4 = calibP4 * correction;
82 // Set the output scale
83 jet->setAttribute<xAOD::JetFourMom_t>(m_jetOutScale,calibP4);
84 jet->setJetP4(calibP4);
85 }
86 return StatusCode::SUCCESS;
87}
88
89StatusCode InSituCalibStep::retrieveEventInfo(unsigned int &r) const {
90
91 const xAOD::EventInfo * eventObj = nullptr;
92 static std::atomic<unsigned int> eventInfoWarnings = 0;
94 if ( rhEvtInfo.isValid() ) {
95 eventObj = rhEvtInfo.cptr();
96 r = eventObj->runNumber();
97 } else {
98 ++eventInfoWarnings;
99 if ( eventInfoWarnings < 20 )
100 ATH_MSG_ERROR(" InSituCalibStep::calibrate : Failed to retrieve event information.");
101 return StatusCode::SUCCESS; //error is recoverable, so return SUCCESS
102 }
103 return StatusCode::SUCCESS;
104}
105
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
ToolHandleArray< JetHelper::IVarTool > m_histTool_Abs
Gaudi::Property< std::string > m_jetInScale
Gaudi::Property< bool > m_CalibrateMC
StatusCode retrieveEventInfo(unsigned int &r) const
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual StatusCode calibrate(xAOD::JetContainer &) const override
Apply calibration to a jet container.
Gaudi::Property< std::string > m_jetOutScale
ToolHandleArray< JetHelper::IVarTool > m_histTool_EtaInter
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
InSituCalibStep(const std::string &name="InSituCalibStep")
Constructor with parameters:
Gaudi::Property< std::vector< unsigned int > > m_RunNumBoundaries
Gaudi::Property< bool > m_isMC
Class JetContext Designed to read AOD information related to the event, N vertices,...
Definition JetContext.h:23
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
uint32_t runNumber() const
The current event's run number.
int r
Definition globals.cxx:22
Jet_v1 Jet
Definition of the current "jet version".
EventInfo_v1 EventInfo
Definition of the latest event info 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