ATLAS Offline Software
Loading...
Searching...
No Matches
testAthenaPhotonAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// PhotonEfficiencyCorrection includes
7
12
14
15testAthenaPhotonAlg::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//
22
23
25 ATH_MSG_INFO ("Initializing " << name() << "...");
26 // Retrieve the tool
27 ATH_CHECK( m_photonSF.retrieve() );
28 return StatusCode::SUCCESS;
29}
30
32 ATH_MSG_INFO ("Finalizing " << name() << "...");
33 // Clean up
34 ATH_CHECK( m_photonSF.release() );
35 return StatusCode::SUCCESS;
36}
37
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;
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
67auto inContShallowCopy = xAOD::shallowCopyContainer( *photons );
68
69//creates a new photon container to hold the subset as well as the needed auxiliary container
72 // You need to tell the photon container in which auxiliary container it should write its member variables
73 myphotons->setStore( myphotonsAux ); //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 ATH_CHECK( evtStore()->record(myphotons, "MyPhotons" ) );
78 ATH_CHECK( evtStore()->record(myphotonsAux, "MyPhotonsAux" ) );
79
80// 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)
81for ( xAOD::Photon* ph : *(inContShallowCopy.first) ) {
82
83 //if ( std::abs(ph->eta()) > 2.37 || ph->pt()<15000. ) continue;
84 //if (std::abs(ph->eta())>=1.37 && std::abs(ph->eta())<=1.52) continue;
85 ATH_MSG_DEBUG( " photon pt = " << ph->pt() <<", photon eta = " << ph->eta() );
86
87 double SF, SFerr; // for photon SF and the apropriate error
88 if(!m_photonSF->getEfficiencyScaleFactor(*ph,SF)){
89 ATH_MSG_WARNING( "Couldn't get photon scale factor!" );
90 continue;
91 }
92 if(!m_photonSF->getEfficiencyScaleFactorError(*ph,SFerr)){
93 ATH_MSG_WARNING( "Couldn't get photon scale factor uncertainty!" );
94 continue;
95 }
96 ATH_MSG_DEBUG( " photon SF = " << SF <<", photon SF sys error = " << SFerr );
97
98 // applyEfficiencyScaleFactor - decorate the object (*photon)
99 if ( m_photonSF->applyEfficiencyScaleFactor(*ph) == CP::CorrectionCode::Error ) {
100 ATH_MSG_ERROR("PhotonEfficiencyCorrectionTool reported a CP::CorrectionCode::Error");
101 return StatusCode::FAILURE;
102 }
103
104 myphotons->push_back(ph); // add it to a new photon container which will be writed to a new file
105} // and loop on photons
106
107 return StatusCode::SUCCESS;
108}
109
110
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
@ Error
Some error happened during the object correction.
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.
virtual StatusCode initialize()
virtual StatusCode execute()
virtual ~testAthenaPhotonAlg()
testAthenaPhotonAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode finalize()
ToolHandle< IAsgPhotonEfficiencyCorrectionTool > m_photonSF
The tool handle to our photon efficiency correction.
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
PhotonAuxContainer_v3 PhotonAuxContainer
Definition of the current photon auxiliary container.
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.
Photon_v1 Photon
Definition of the current "egamma version".