ATLAS Offline Software
PileupReweightingProvider.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef PILEUPREWEIGHTINGPROVIDER
6 #define PILEUPREWEIGHTINGPROVIDER
7 
10 #include "GaudiKernel/ToolHandle.h"
11 
13 
15 
16 namespace CP {
17 
19 
20  public:
21  PileupReweightingProvider( const std::string& name, ISvcLocator* svcloc) : AthAlgorithm(name,svcloc),m_tool("CP::PileupReweightingTool/auto") {
22  declareProperty("Tool",m_tool,"The configured PileupReweightingTool");
23  declareProperty("Input",m_inputKey="","Specify a specific EventInfo object");
24  declareProperty("Output",m_outputKey="","Specify an output EventInfo object. If differs from input, will create a clone of EventInfo and decorate that");
25  declareProperty("ConfigOutputStream",m_configStream="","Specify the stream to output config file to");
26  declareProperty("RunSystematics",m_systematics=true,"Enable systematics during run");
27  }
28 
30 
31  virtual StatusCode initialize() {
32  CHECK( m_tool.retrieve() );
33 
34  IProperty* myTool = dynamic_cast<IProperty*>(&*m_tool);
35  if (!myTool)
36  return StatusCode::FAILURE;
37  CHECK( myTool->setProperty("ConfigOutputStream",m_configStream) );
38 
39  //get the list of systematics
41  m_allSysts = registry.recommendedSystematics();
42 
43  if(m_configStream!="") ATH_MSG_INFO("Now running config file making .... please be patient! ... ");
44 
45  return StatusCode::SUCCESS;
46  }
47  virtual StatusCode execute() {
48  const xAOD::EventInfo* evtInfo =0;
49 
50  if(m_inputKey.length()>0) ATH_CHECK(evtStore()->retrieve(evtInfo,m_inputKey));
51  else {
52  #ifdef XAOD_STANDALONE
53  ATH_CHECK( evtStore()->retrieve(evtInfo,"") ); //apparently TEvent can't do keyless retrieves!!??
54  #else
55  ATH_CHECK(evtStore()->retrieve(evtInfo));
56  #endif
57  }
58 
59  //do we need to make a copy??
60  if(m_inputKey!=m_outputKey && m_outputKey!="") {
61  xAOD::EventInfo* evtInfoCopy = new xAOD::EventInfo( *evtInfo );
63  evtInfoCopy->setStore(aux);
64  ATH_CHECK( evtStore()->record( evtInfoCopy , m_outputKey ) );
65  ATH_CHECK( evtStore()->record( aux , m_outputKey+"Aux." ) );
66  evtInfo = evtInfoCopy;
67  }
68 
69  CHECK( m_tool->apply(*evtInfo) );
70 
71 
72  //here's an example of systematic variations
73  if (m_systematics){
74  for(auto& syst : m_allSysts) {
75  ATH_MSG_VERBOSE("Doing systematic : " << syst.name());
76  if(! m_tool->isAffectedBySystematic( syst )) continue;
77  CP::SystematicSet tmp; tmp.insert( syst );
78  if( m_tool->applySystematicVariation( tmp ) != StatusCode::SUCCESS ) continue;
79  CHECK( m_tool->apply(*evtInfo) );
80  }
81  //make sure we leave the tool in the nominal mode
82  if( m_tool->applySystematicVariation( CP::SystematicSet() ) != StatusCode::SUCCESS ) return StatusCode::FAILURE;
83  }
84 
85  return StatusCode::SUCCESS;
86  }
87 
88  private:
89  ToolHandle<IPileupReweightingTool> m_tool;
90 
92 
94 
96 
97 };
98 
99 } //end of CP namespace
100 
101 #endif
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
CP::PileupReweightingProvider::m_systematics
bool m_systematics
Definition: PileupReweightingProvider.h:95
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition: IEventInfoCnvTool.h:17
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CP::PileupReweightingProvider::initialize
virtual StatusCode initialize()
Definition: PileupReweightingProvider.h:31
CP::PileupReweightingProvider::m_configStream
std::string m_configStream
Definition: PileupReweightingProvider.h:91
xAOD::EventInfoAuxContainer
EventInfoAuxContainer_v1 EventInfoAuxContainer
Define the latest version of the auxiliary container.
Definition: EventInfoAuxContainer.h:16
EventInfoAuxContainer.h
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::PileupReweightingProvider::m_tool
ToolHandle< IPileupReweightingTool > m_tool
Definition: PileupReweightingProvider.h:89
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
AthAlgorithm.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
IPileupReweightingTool.h
CP::PileupReweightingProvider
Definition: PileupReweightingProvider.h:18
SG::AuxElement::setStore
void setStore(const SG::IConstAuxStore *store)
Set the store associated with this object.
Definition: AuxElement.cxx:221
SystematicRegistry.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::PileupReweightingProvider::execute
virtual StatusCode execute()
Definition: PileupReweightingProvider.h:47
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CP::PileupReweightingProvider::m_allSysts
CP::SystematicSet m_allSysts
Definition: PileupReweightingProvider.h:93
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
AthAlgorithm
Definition: AthAlgorithm.h:47
xAOD::EventInfoAuxContainer_v1
Auxiliary information about the pileup events.
Definition: EventInfoAuxContainer_v1.h:31
CP::PileupReweightingProvider::m_outputKey
std::string m_outputKey
Definition: PileupReweightingProvider.h:91
CP::PileupReweightingProvider::m_inputKey
std::string m_inputKey
Definition: PileupReweightingProvider.h:91
CP::PileupReweightingProvider::~PileupReweightingProvider
~PileupReweightingProvider()
Definition: PileupReweightingProvider.h:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CP::PileupReweightingProvider::PileupReweightingProvider
PileupReweightingProvider(const std::string &name, ISvcLocator *svcloc)
Definition: PileupReweightingProvider.h:21
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition: SystematicRegistry.h:25
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25