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
namespace
ADD_CMODE(CP) {
16
17
testAthenaPhotonAlg::testAthenaPhotonAlg(
const
std::string& name, ISvcLocator* pSvcLocator ) :
AthAlgorithm
( name, pSvcLocator ), m_photonSF(
"CP::AsgPhotonEfficiencyCorrectionTool/AsgPhotonEfficiencyCorrectionTool"
,
this
){
18
19
//declareProperty( "Property", m_nProperty ); //example property declaration
20
declareProperty(
"PhotonEfficiencyCorrectionTool"
, m_photonSF );
21
}
22
//
23
testAthenaPhotonAlg::~testAthenaPhotonAlg() =
default
;
24
25
26
StatusCode testAthenaPhotonAlg::initialize() {
27
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
);
28
// Retrieve the tool
29
ATH_CHECK
( m_photonSF.retrieve() );
30
return
StatusCode::SUCCESS;
31
}
32
33
StatusCode testAthenaPhotonAlg::finalize() {
34
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
35
// Clean up
36
ATH_CHECK
( m_photonSF.release() );
37
return
StatusCode::SUCCESS;
38
}
39
40
StatusCode testAthenaPhotonAlg::execute(
const
EventContext&
/*ctx*/
) {
41
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
42
43
//----------------------------
44
// Event information
45
//---------------------------
46
const
xAOD::EventInfo
* eventInfo =
nullptr
;
//NOTE: Everything that comes from the storegate direct from the input files is const!
47
48
// ask the event store to retrieve the xAOD EventInfo container
49
//ATH_CHECK( evtStore()->retrieve( eventInfo, "EventInfo") ); // the second argument ("EventInfo") is the key name
50
ATH_CHECK
( evtStore()->retrieve( eventInfo) );
51
// if there is only one container of that type in the xAOD (as with the EventInfo container), you do not need to pass
52
// the key name, the default will be taken as the only key name in the xAOD
53
54
// check if data or MC
55
bool
isMC =
true
;
56
if
(!eventInfo->
eventType
(
xAOD::EventInfo::IS_SIMULATION
) ){
57
isMC =
false
;
58
}
59
if
(!isMC)
ATH_MSG_ERROR
(
"This is data, no scale factors should be used on the data!"
);
60
61
//---------
62
// photons
63
//---------
64
const
xAOD::PhotonContainer
* photons =
nullptr
;
65
ATH_CHECK
( evtStore()->retrieve( photons,
"Photons"
) );
66
ATH_MSG_DEBUG
(
"Found "
<<photons->
size
() <<
" photons in event, itterate...."
);
67
68
// Let's create a shallow copy of the const photon container, and decorate it with the obtained SF
69
auto
inContShallowCopy =
xAOD::shallowCopy
( *photons );
70
71
//creates a new photon container to hold the subset as well as the needed auxiliary container
72
auto
umyphotons = std::make_unique<xAOD::PhotonContainer>();
73
auto
myphotonsAux = std::make_unique<xAOD::PhotonAuxContainer>();
74
// You need to tell the photon container in which auxiliary container it should write its member variables
75
umyphotons->setStore( myphotonsAux.get() );
//gives it a new associated aux container
76
77
// Also record to storegate: you must record both the container and the auxcontainer.
78
// Note that storegate takes ownership of these objects, i.e., you must not try to delete them yourself.
79
xAOD::PhotonContainer
* myphotons = umyphotons.get();
80
ATH_CHECK
( evtStore()->record(std::move(umyphotons),
"MyPhotons"
) );
81
ATH_CHECK
( evtStore()->record(std::move(myphotonsAux),
"MyPhotonsAux"
) );
82
83
// 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)
84
for
(
xAOD::Photon
* ph : *(inContShallowCopy.first) ) {
85
86
//if ( std::abs(ph->eta()) > 2.37 || ph->pt()<15000. ) continue;
87
//if (std::abs(ph->eta())>=1.37 && std::abs(ph->eta())<=1.52) continue;
88
ATH_MSG_DEBUG
(
" photon pt = "
<< ph->pt() <<
", photon eta = "
<< ph->eta() );
89
90
double
SF, SFerr;
// for photon SF and the apropriate error
91
if
(!m_photonSF->getEfficiencyScaleFactor(*ph,SF)){
92
ATH_MSG_WARNING
(
"Couldn't get photon scale factor!"
);
93
continue
;
94
}
95
if
(!m_photonSF->getEfficiencyScaleFactorError(*ph,SFerr)){
96
ATH_MSG_WARNING
(
"Couldn't get photon scale factor uncertainty!"
);
97
continue
;
98
}
99
ATH_MSG_DEBUG
(
" photon SF = "
<< SF <<
", photon SF sys error = "
<< SFerr );
100
101
// applyEfficiencyScaleFactor - decorate the object (*photon)
102
if
( m_photonSF->applyEfficiencyScaleFactor(*ph) ==
CP::CorrectionCode::Error
) {
103
ATH_MSG_ERROR
(
"PhotonEfficiencyCorrectionTool reported a CP::CorrectionCode::Error"
);
104
return
StatusCode::FAILURE;
105
}
106
107
// add it to a new photon container which will be writed to a new file
108
myphotons->
push_back
(std::make_unique<xAOD::Photon>());
109
*(myphotons->
back
()) = *ph;
110
}
// and loop on photons
111
112
return
StatusCode::SUCCESS;
113
}
114
}
// namespace ADD_CMODE(CP)
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
IAsgPhotonEfficiencyCorrectionTool.h
PhotonAuxContainer.h
PhotonContainer.h
ShallowCopy.h
AthAlgorithm
Base class from which non-reentrant (not thread-safe) Athena algorithm classes should be derived.
Definition
AthAlgorithm.h:27
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.
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
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
Photon.h:17
testAthenaPhotonAlg.h
EventInfo.h
Generated on
for ATLAS Offline Software by
1.17.0