ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
ElectronPhotonID
PhotonEfficiencyCorrection
src
testAthenaPhotonAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// PhotonEfficiencyCorrection includes
6
#include "
testAthenaPhotonAlg.h
"
7
8
#include "
xAODEventInfo/EventInfo.h
"
9
#include "
xAODEgamma/PhotonContainer.h
"
10
#include "
xAODEgamma/PhotonAuxContainer.h
"
11
#include "
xAODCore/ShallowCopy.h
"
12
13
#include "
EgammaAnalysisInterfaces/IAsgPhotonEfficiencyCorrectionTool.h
"
14
15
testAthenaPhotonAlg::testAthenaPhotonAlg
(
const
std::string& name, ISvcLocator* pSvcLocator ) :
AthAlgorithm
( name, pSvcLocator ),
m_photonSF
(
"AsgPhotonEfficiencyCorrectionTool/AsgPhotonEfficiencyCorrectionTool"
,this){
16
17
//declareProperty( "Property", m_nProperty ); //example property declaration
18
declareProperty
(
"PhotonEfficiencyCorrectionTool"
,
m_photonSF
);
19
}
20
//
21
testAthenaPhotonAlg::~testAthenaPhotonAlg
() =
default
;
22
23
24
StatusCode
testAthenaPhotonAlg::initialize
() {
25
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
);
26
// Retrieve the tool
27
ATH_CHECK
(
m_photonSF
.retrieve() );
28
return
StatusCode::SUCCESS;
29
}
30
31
StatusCode
testAthenaPhotonAlg::finalize
() {
32
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
33
// Clean up
34
ATH_CHECK
(
m_photonSF
.release() );
35
return
StatusCode::SUCCESS;
36
}
37
38
StatusCode
testAthenaPhotonAlg::execute
(
const
EventContext&
/*ctx*/
) {
39
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
40
41
//----------------------------
42
// Event information
43
//---------------------------
44
const
xAOD::EventInfo
* eventInfo =
nullptr
;
//NOTE: Everything that comes from the storegate direct from the input files is const!
45
46
// ask the event store to retrieve the xAOD EventInfo container
47
//ATH_CHECK( evtStore()->retrieve( eventInfo, "EventInfo") ); // the second argument ("EventInfo") is the key name
48
ATH_CHECK
(
evtStore
()->retrieve( eventInfo) );
49
// if there is only one container of that type in the xAOD (as with the EventInfo container), you do not need to pass
50
// the key name, the default will be taken as the only key name in the xAOD
51
52
// check if data or MC
53
bool
isMC =
true
;
54
if
(!eventInfo->
eventType
(
xAOD::EventInfo::IS_SIMULATION
) ){
55
isMC =
false
;
56
}
57
if
(!isMC)
ATH_MSG_ERROR
(
"This is data, no scale factors should be used on the data!"
);
58
59
//---------
60
// photons
61
//---------
62
const
xAOD::PhotonContainer
* photons =
nullptr
;
63
ATH_CHECK
(
evtStore
()->retrieve( photons,
"Photons"
) );
64
ATH_MSG_DEBUG
(
"Found "
<<photons->
size
() <<
" photons in event, itterate...."
);
65
66
// Let's create a shallow copy of the const photon container, and decorate it with the obtained SF
67
auto
inContShallowCopy =
xAOD::shallowCopy
( *photons );
68
69
//creates a new photon container to hold the subset as well as the needed auxiliary container
70
auto
umyphotons = std::make_unique<xAOD::PhotonContainer>();
71
auto
myphotonsAux = std::make_unique<xAOD::PhotonAuxContainer>();
72
// You need to tell the photon container in which auxiliary container it should write its member variables
73
umyphotons->setStore( myphotonsAux.get() );
//gives it a new associated aux container
74
75
// Also record to storegate: you must record both the container and the auxcontainer.
76
// Note that storegate takes ownership of these objects, i.e., you must not try to delete them yourself.
77
xAOD::PhotonContainer
* myphotons = umyphotons.get();
78
ATH_CHECK
(
evtStore
()->record(std::move(umyphotons),
"MyPhotons"
) );
79
ATH_CHECK
(
evtStore
()->record(std::move(myphotonsAux),
"MyPhotonsAux"
) );
80
81
// Loop over all Photons in the shallow-copy container, decorate it with SF, and store in new xAOD file, in addition print out all SF (with get* function)
82
for
(
xAOD::Photon
* ph : *(inContShallowCopy.first) ) {
83
84
//if ( std::abs(ph->eta()) > 2.37 || ph->pt()<15000. ) continue;
85
//if (std::abs(ph->eta())>=1.37 && std::abs(ph->eta())<=1.52) continue;
86
ATH_MSG_DEBUG
(
" photon pt = "
<< ph->pt() <<
", photon eta = "
<< ph->eta() );
87
88
double
SF, SFerr;
// for photon SF and the apropriate error
89
if
(!
m_photonSF
->getEfficiencyScaleFactor(*ph,SF)){
90
ATH_MSG_WARNING
(
"Couldn't get photon scale factor!"
);
91
continue
;
92
}
93
if
(!
m_photonSF
->getEfficiencyScaleFactorError(*ph,SFerr)){
94
ATH_MSG_WARNING
(
"Couldn't get photon scale factor uncertainty!"
);
95
continue
;
96
}
97
ATH_MSG_DEBUG
(
" photon SF = "
<< SF <<
", photon SF sys error = "
<< SFerr );
98
99
// applyEfficiencyScaleFactor - decorate the object (*photon)
100
if
(
m_photonSF
->applyEfficiencyScaleFactor(*ph) ==
CP::CorrectionCode::Error
) {
101
ATH_MSG_ERROR
(
"PhotonEfficiencyCorrectionTool reported a CP::CorrectionCode::Error"
);
102
return
StatusCode::FAILURE;
103
}
104
105
// add it to a new photon container which will be writed to a new file
106
myphotons->
push_back
(std::make_unique<xAOD::Photon>());
107
*(myphotons->
back
()) = *ph;
108
}
// and loop on photons
109
110
return
StatusCode::SUCCESS;
111
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x,...)
Definition
AthMsgStreamMacros.h:46
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
PhotonContainer.h
IAsgPhotonEfficiencyCorrectionTool.h
PhotonAuxContainer.h
ShallowCopy.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition
CorrectionCode.h:36
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
testAthenaPhotonAlg::initialize
virtual StatusCode initialize()
Definition
testAthenaPhotonAlg.cxx:24
testAthenaPhotonAlg::~testAthenaPhotonAlg
virtual ~testAthenaPhotonAlg()
testAthenaPhotonAlg::testAthenaPhotonAlg
testAthenaPhotonAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
testAthenaPhotonAlg.cxx:15
testAthenaPhotonAlg::finalize
virtual StatusCode finalize()
Definition
testAthenaPhotonAlg.cxx:31
testAthenaPhotonAlg::execute
virtual StatusCode execute(const EventContext &ctx)
Execute method.
Definition
testAthenaPhotonAlg.cxx:38
testAthenaPhotonAlg::m_photonSF
ToolHandle< IAsgPhotonEfficiencyCorrectionTool > m_photonSF
The tool handle to our photon efficiency correction.
Definition
testAthenaPhotonAlg.h:25
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition
EventInfo_v1.h:151
xAOD::PhotonContainer
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/PhotonContainer.h:17
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition
IEventInfoCnvTool.h:16
xAOD::shallowCopy
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
testAthenaPhotonAlg.h
EventInfo.h
Generated on
for ATLAS Offline Software by
1.17.0