ATLAS Offline Software
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"
12 #include "xAODCore/ShallowCopy.h"
17 #include "TString.h"
18 // local include
20 
21 testAthenaEgammaCalibTool::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 
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;
75  xAOD::ElectronContainer::iterator el_it = elsCorr->begin();
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ShallowCopy.h
python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
testAthenaEgammaCalibTool.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
testAthenaEgammaCalibTool::testAthenaEgammaCalibTool
testAthenaEgammaCalibTool(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: testAthenaEgammaCalibTool.cxx:21
CP::SystematicSet::size
size_t size() const
returns: size of the set
Definition: SystematicSet.h:71
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
Egamma.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
testAthenaEgammaCalibTool::m_sg_electrons
std::string m_sg_electrons
Definition: testAthenaEgammaCalibTool.h:29
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ElectronContainer.h
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloCluster.h
SystematicRegistry.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
StatusCode.h
testAthenaEgammaCalibTool::m_EgammaCalibrationAndSmearingTool
ToolHandle< CP::IEgammaCalibrationAndSmearingTool > m_EgammaCalibrationAndSmearingTool
Definition: testAthenaEgammaCalibTool.h:31
testAthenaEgammaCalibTool::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: testAthenaEgammaCalibTool.cxx:42
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition: SystematicRegistry.h:25
testAthenaEgammaCalibTool::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: testAthenaEgammaCalibTool.cxx:30
EgammaCalibrationAndSmearingTool.h
PhotonContainer.h
SystematicVariation.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25