ATLAS Offline Software
Loading...
Searching...
No Matches
testAthenaPhotonAlg.cxx File Reference
Include dependency graph for testAthenaPhotonAlg.cxx:

Go to the source code of this file.

Functions

namespace ADD_CMODE (CP)

Function Documentation

◆ ADD_CMODE()

namespace ADD_CMODE ( CP )

Definition at line 1 of file testAthenaPhotonAlg.cxx.

15 {
16
17testAthenaPhotonAlg::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//
23testAthenaPhotonAlg::~testAthenaPhotonAlg() = default;
24
25
26StatusCode testAthenaPhotonAlg::initialize() {
27 ATH_MSG_INFO ("Initializing " << name() << "...");
28 // Retrieve the tool
29 ATH_CHECK( m_photonSF.retrieve() );
30 return StatusCode::SUCCESS;
31}
32
33StatusCode testAthenaPhotonAlg::finalize() {
34 ATH_MSG_INFO ("Finalizing " << name() << "...");
35 // Clean up
36 ATH_CHECK( m_photonSF.release() );
37 return StatusCode::SUCCESS;
38}
39
40StatusCode 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;
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
69auto 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)
84for ( 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
Base class from which non-reentrant (not thread-safe) Athena algorithm classes should be derived.
@ Error
Some error happened during the object correction.
const T * back() const
Access the last element in the collection as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
::StatusCode StatusCode
StatusCode definition for legacy code.
const float SF[NF]
Cross sections for Fluor.
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
Photon_v1 Photon
Definition of the current "egamma version".
Definition Photon.h:17