ATLAS Offline Software
Loading...
Searching...
No Matches
testAthenaEgammaCalibTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// EDM include(s):
6
9#include "xAODEgamma/Egamma.h"
17#include "TString.h"
18// local include
20
21testAthenaEgammaCalibTool::testAthenaEgammaCalibTool( const std::string& name, ISvcLocator* svcLoc )
22 : AthAlgorithm( name, svcLoc ),
23 m_EgammaCalibrationAndSmearingTool("CP::EgammaCalibrationAndSmearingTool/EgammaCalibrationAndSmearingTool", this)
24{
25 declareProperty( "SG_Electrons", m_sg_electrons = "Electrons" );
26 declareProperty( "EgammaCalibrationAndSmearingTool", m_EgammaCalibrationAndSmearingTool);
27}
28
29
31{
32 // Greet the user:
33 ATH_MSG_INFO( "Initialising..." );
34
35 // Retrieve the tools:
37
38 return StatusCode::SUCCESS;
39}
40
41
43{
44 const xAOD::EventInfo* event_info = nullptr;
45 ATH_CHECK( evtStore()->retrieve( event_info) );
46
47 const xAOD::ElectronContainer* electrons;
48 ATH_CHECK( evtStore()->retrieve(electrons, m_sg_electrons) );
49
50 //Clone
51 std::pair< xAOD::ElectronContainer*, xAOD::ShallowAuxContainer* > electrons_shallowCopy = xAOD::shallowCopyContainer( *electrons );
52 //Record in StoreGate
53 CHECK( evtStore()->record( electrons_shallowCopy.first, "ElectronCollectionCorr") );
54 CHECK( evtStore()->record( electrons_shallowCopy.second, "ElectronCollectionCorrAux.") );
55
56 //===========SYSTEMATICS
58 const CP::SystematicSet& recommendedSystematics = registry.recommendedSystematics();
59 std::vector<CP::SystematicSet> sysList;
60 // this is the nominal set
61 sysList.emplace_back();
62
63 ATH_MSG_INFO("SIZE of the systematics set:" << recommendedSystematics.size());
64
65 for(const auto & recommendedSystematic : recommendedSystematics)
66 {
67 sysList.emplace_back();
68 sysList.back().insert(recommendedSystematic);
69 }
70
71 std::vector<CP::SystematicSet>::const_iterator sysListItr;
72
73 //Iterate over the shallow copy
74 xAOD::ElectronContainer* elsCorr = electrons_shallowCopy.first;
76 xAOD::ElectronContainer::iterator el_it_last = elsCorr->end();
77 unsigned int i = 0;
78 for (; el_it != el_it_last; ++el_it, ++i) {
79 xAOD::Electron* el = *el_it;
80 ATH_MSG_INFO("Electron " << i);
81 ATH_MSG_INFO("xAOD/raw pt, eta, phi = " << el->pt() << ", " << el->eta() << ", " << el->phi());
82
84 ATH_MSG_WARNING("Cannot calibrate electron");
85 }
86 ATH_MSG_INFO("Calibrated pt = " << el->pt());
87
88 //systematics
89 ATH_MSG_INFO("=============SYSTEMATICS CHECK NOW");
90 for (sysListItr = sysList.begin(); sysListItr != sysList.end(); ++sysListItr)
91 {
92 // Tell the calibration tool which variation to apply
93 if (m_EgammaCalibrationAndSmearingTool->applySystematicVariation(*sysListItr) != StatusCode::SUCCESS)
94 {
95 ATH_MSG_ERROR("Cannot configure calibration tool for systematics");
96 }
97 //For now remove by hand the photon ones
98 TString syst_name = TString(sysListItr->name());
99 if(!syst_name.BeginsWith("EL") && !syst_name.BeginsWith("EG")) continue;
100
102 ATH_MSG_WARNING("Cannot calibrate electron");
103 }
104
105 ATH_MSG_INFO("Calibrated pt with systematic " << syst_name << " = " << el->pt());
106 }
107 ATH_MSG_INFO("=============END SYSTEMATICS ");
108 }
109
110 //test the correctedCopy method
111 unsigned int j = 0;
112 for (; el_it != el_it_last; ++el_it, ++j) {
113 xAOD::Electron *copy_el = nullptr; // new object
114 if (m_EgammaCalibrationAndSmearingTool->correctedCopy( **el_it, copy_el) != CP::CorrectionCode::Ok){
115 ATH_MSG_WARNING("Could not apply correction to new electron object");
116 continue;
117 }
118 }
119
120 return StatusCode::SUCCESS;
121}
122
#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 CHECK(...)
Evaluate an expression and check for errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
@ Ok
The correction was done successfully.
This module implements the central registry for handling systematic uncertainties with CP tools.
const SystematicSet & recommendedSystematics() const
returns: the recommended set of systematics
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Class to wrap a set of SystematicVariations.
size_t size() const
returns: size of the set
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
ToolHandle< CP::IEgammaCalibrationAndSmearingTool > m_EgammaCalibrationAndSmearingTool
virtual StatusCode execute()
Function executing the algorithm.
testAthenaEgammaCalibTool(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
virtual StatusCode initialize()
Function initialising the algorithm.
ElectronContainer_v1 ElectronContainer
Definition of the current "electron 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.
Electron_v1 Electron
Definition of the current "egamma version".