00001 #ifndef PILEUPREWEIGHTINGPROVIDER
00002 #define PILEUPREWEIGHTINGPROVIDER
00003
00004 #include "AsgAnalysisInterfaces/IPileupReweightingTool.h"
00005 #include "AthenaBaseComps/AthAlgorithm.h"
00006 #include "GaudiKernel/ToolHandle.h"
00007
00008 #include "xAODEventInfo/EventInfoAuxContainer.h"
00009
00010 #include "PATInterfaces/SystematicRegistry.h"
00011
00012 namespace CP {
00013
00014 class PileupReweightingProvider : public AthAlgorithm {
00015
00016 public:
00017 PileupReweightingProvider( const std::string& name, ISvcLocator* svcloc) : AthAlgorithm(name,svcloc),m_tool("CP::PileupReweightingTool/auto") {
00018 declareProperty("Tool",m_tool,"The configured PileupReweightingTool");
00019 declareProperty("Input",m_inputKey="","Specify a specific EventInfo object");
00020 declareProperty("Output",m_outputKey="","Specify an output EventInfo object. If differs from input, will create a clone of EventInfo and decorate that");
00021 declareProperty("ConfigOutputStream",m_configStream="","Specify the stream to output config file to");
00022 }
00023
00024 ~PileupReweightingProvider() { }
00025
00026 virtual StatusCode initialize() {
00027 CHECK( m_tool.retrieve() );
00028
00029 IProperty* myTool = dynamic_cast<IProperty*>(&*m_tool);
00030 if (!myTool)
00031 return StatusCode::FAILURE;
00032 CHECK( myTool->setProperty("ConfigOutputStream",m_configStream) );
00033
00034
00035 CP::SystematicRegistry& registry = CP::SystematicRegistry::getInstance();
00036 m_allSysts = registry.recommendedSystematics();
00037
00038 if(m_configStream!="") ATH_MSG_INFO("Now running config file making .... please be patient! ... ");
00039
00040 return StatusCode::SUCCESS;
00041 }
00042 virtual StatusCode execute() {
00043 const xAOD::EventInfo* evtInfo =0;
00044
00045 if(m_inputKey.length()>0) ATH_CHECK(evtStore()->retrieve(evtInfo,m_inputKey));
00046 else {
00047 #ifdef XAOD_STANDALONE
00048 ATH_CHECK( evtStore()->retrieve(evtInfo,"") );
00049 #else
00050 ATH_CHECK(evtStore()->retrieve(evtInfo));
00051 #endif
00052 }
00053
00054
00055 if(m_inputKey!=m_outputKey && m_outputKey!="") {
00056 xAOD::EventInfo* evtInfoCopy = new xAOD::EventInfo( *evtInfo );
00057 xAOD::EventInfoAuxContainer* aux = new xAOD::EventInfoAuxContainer;
00058 evtInfoCopy->setStore(aux);
00059 ATH_CHECK( evtStore()->record( evtInfoCopy , m_outputKey ) );
00060 ATH_CHECK( evtStore()->record( aux , m_outputKey+"Aux." ) );
00061 evtInfo = evtInfoCopy;
00062 }
00063
00064 CHECK( m_tool->apply(*evtInfo) );
00065
00066
00067
00068 for(auto& syst : m_allSysts) {
00069 ATH_MSG_VERBOSE("Doing systematic : " << syst.name());
00070 if(! m_tool->isAffectedBySystematic( syst )) continue;
00071 CP::SystematicSet tmp; tmp.insert( syst );
00072 if( m_tool->applySystematicVariation( tmp ) != CP::SystematicCode::Ok ) continue;
00073 CHECK( m_tool->apply(*evtInfo) );
00074 }
00075
00076 if( m_tool->applySystematicVariation( CP::SystematicSet() ) != CP::SystematicCode::Ok ) return StatusCode::FAILURE;
00077
00078 return StatusCode::SUCCESS;
00079 }
00080
00081 private:
00082 ToolHandle<IPileupReweightingTool> m_tool;
00083
00084 std::string m_inputKey,m_outputKey,m_configStream;
00085
00086 CP::SystematicSet m_allSysts;
00087
00088 };
00089
00090 }
00091
00092 #endif