diff --git a/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventEtDensityCalculator.h b/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventEtDensityCalculator.h new file mode 100644 index 0000000000000000000000000000000000000000..b2a2964e94fd26874b1f3c8fce3271eb26795b1c --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventEtDensityCalculator.h @@ -0,0 +1,31 @@ +// -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef EVENTSHAPEREC_EVENTETDENSITYCALCULATOR_H +#define EVENTSHAPEREC_EVENTETDENSITYCALCULATOR_H + +#include "GaudiKernel/ToolHandle.h" + +#include "EventShapeInterface/IEventEtDensityTool.h" + +#include "EventShapeRec/EventFeatureAlgorithmBase.h" + +class EventEtDensityCalculator : public EventFeatureAlgorithmBase +{ +public: + EventEtDensityCalculator(const std::string& name,ISvcLocator* pSvcLocator); + virtual ~EventEtDensityCalculator(); + +protected: + + virtual StatusCode appInitialize(); + virtual StatusCode appExecute(EventFeatureStore* pStore, + const INavigable4MomentumCollection* pColl); + virtual StatusCode appExecute(EventFeatureStore* pStore); + + // ToolHandleArray<IEventEtDensityTool> m_densityTools; +}; +#endif diff --git a/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventEtDensityTester.h b/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventEtDensityTester.h new file mode 100644 index 0000000000000000000000000000000000000000..dbf104fbfb16613da0de6fd90b2b9e32b7dea868 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventEtDensityTester.h @@ -0,0 +1,51 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// -*-c++-*- +#ifndef EVENTSHAPEREC_EVENTETDENSITYTESTER_H +#define EVENTSHAPEREC_EVENTETDENSITYTESTER_H + +#include "GaudiKernel/ToolHandle.h" + +#include "AthenaBaseComps/AthAlgorithm.h" + +#include "EventShapeInterface/IEventEtDensityProvider.h" + +#include "TH1D.h" +#include "TProfile.h" + +#include <vector> + +class EventEtDensityTester: public AthAlgorithm +{ +public: + + EventEtDensityTester(const std::string& name,ISvcLocator* pSvcLocator); + virtual ~EventEtDensityTester(); + + virtual StatusCode initialize(); + virtual StatusCode execute(); + +protected: + + virtual double getNPV(); + +private: + + ToolHandleArray<IEventEtDensityProvider> m_tools; + + std::string m_histPath; + std::string m_vtxContainerKey; + + std::vector<TH1D*> h_densities; + std::vector<TProfile*> p_densities; + + bool m_fillEvtStore; + bool m_fillHistos; + + +}; + +#endif + diff --git a/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventFeatureAlgorithmBase.h b/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventFeatureAlgorithmBase.h new file mode 100644 index 0000000000000000000000000000000000000000..2ba8cc5996bfae3348aa814fd8a7584e452574a5 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventFeatureAlgorithmBase.h @@ -0,0 +1,125 @@ +// -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef EVENTSHAPEREC_EVENTFEATUREALGORITHMBASE_H +#define EVENTSHAPEREC_EVENTFEATUREALGORITHMBASE_H + + +#include "GaudiKernel/ToolHandle.h" + +#include "AthenaBaseComps/AthAlgorithm.h" + +#include "EventShapeInterface/IEventFeatureTool.h" +#include "EventShapeInterface/IEventFeatureAlgorithm.h" + +#include <map> + +class EventFeatureStore; + +class EventFeatureAlgorithmBase : virtual public IEventFeatureAlgorithm, + public AthAlgorithm +{ +public: + + /*! @brief Default @c Algorithm constructor */ + EventFeatureAlgorithmBase(const std::string& name,ISvcLocator* pSvcLocator); + /*! @brief Baseclass destructor */ + virtual ~EventFeatureAlgorithmBase(); + + + /*! @brief Default algorithm initialize + * + * Invokes @c appInitialize() after setting up the basic features and + * process controls. + */ + virtual StatusCode initialize(); + /*! @brief Default algorithm execution + * + * Invokes @c appExecute(...) according to the process control switches. + */ + virtual StatusCode execute(); + virtual StatusCode finalize(); + + virtual const std::string& getFeatureStoreKey() const; + +protected: + + virtual StatusCode appInitialize(); + virtual StatusCode appExecute(EventFeatureStore* pStore, + const INavigable4MomentumCollection* pColl); + virtual StatusCode appExecute(EventFeatureStore* pStore); + virtual StatusCode appFinalize(); + + virtual void executeMonitor(const std::string& toolName, + const std::string& toolType, + StatusCode checkOut); + + virtual void executeSummary(bool cleanUp=false); + + const std::string& collectionKey() const; + const std::string& featureStoreKey() const; + + bool haveFeatureTools() const; + bool haveInputCollection() const; + bool createFeatureStore() const; + + StatusCode recordStore(EventFeatureStore* pStore,const std::string& sgKey); + +private: + + std::string m_inputCollectionKey; + bool m_haveInputCollection; + + std::string m_eventFeatureStoreKey; + bool m_createFeatureStore; + + typedef ToolHandleArray<IEventFeatureTool> tool_array_t; + typedef tool_array_t::iterator tool_iterator_t; + typedef tool_array_t::const_iterator tool_const_iterator_t; + + tool_array_t m_eventFeatureTools; + bool m_haveFeatureTools; + + typedef std::pair<std::string,std::string> tag_t; + typedef std::pair<unsigned int,unsigned int> data_t; + typedef std::map<tag_t,data_t> map_t; + + map_t m_executeStats; +}; + +/*! @class EventFeatureAlgorithmBase + * + * Basic implementations for managing and executing @c IEventFeatureTool + * typed tools. This implementation baseclass provides a complete + * implementation of the @c IEventFeatureAlgorithm interface and of all + * virtual functions in the @c Algorithm class (here used through the + * @c AthAlgorithm sub-class). + * + * Sub-class should implement the @c appInitialize() , @c appExecute(...) and + * @c appFinalize() methods as needed and if the baseclass behaviour in + * @c initialize() , @c execute() and @c finalize() methods are desired. + */ +inline const std::string& EventFeatureAlgorithmBase::collectionKey() const +{ return m_inputCollectionKey; } + +inline const std::string& EventFeatureAlgorithmBase::featureStoreKey() const +{ return m_eventFeatureStoreKey; } + +inline bool EventFeatureAlgorithmBase::haveFeatureTools() const +{ return m_haveFeatureTools; } + +inline bool EventFeatureAlgorithmBase::haveInputCollection() const +{ return m_haveInputCollection; } + +inline bool EventFeatureAlgorithmBase::createFeatureStore() const +{ return m_createFeatureStore; } + +inline StatusCode +EventFeatureAlgorithmBase::recordStore(EventFeatureStore* pStore, + const std::string& sgKey) +{ return evtStore()->record(pStore,sgKey); } +#endif + diff --git a/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventShapeCalculator.h b/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventShapeCalculator.h new file mode 100755 index 0000000000000000000000000000000000000000..da27248ccdbb8c9eddef16b2dacb06dc20c68fda --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/EventShapeRec/EventShapeCalculator.h @@ -0,0 +1,64 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef EVENTSHAPEREC_EVENTSHAPECALCULATOR_H +#define EVENTSHAPEREC_EVENTSHAPECALCULATOR_H + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "GaudiKernel/ToolHandle.h" + +#include "CLHEP/Vector/ThreeVector.h" +#include "CLHEP/Vector/LorentzVector.h" + +#include "EventShapeInterface/IEventShapeToolBase.h" + +#include <vector> +#include <string> + +class EventShapeCalculator : public AthAlgorithm +{ + public: + class etaSelector + { + public: + etaSelector(double etaCut) { m_cutCentral = etaCut; }; + bool operator()(const EventShapeTypes::es_fourvector_t* a) + { return fabs(a->eta()) > m_cutCentral && a->e() > 0; } + + private: + double m_cutCentral; + etaSelector() {}; + }; + + //! Standard algorithm constructor + EventShapeCalculator(const std::string& name, ISvcLocator* pSvcLocator); + + //! Algorithm destructor + virtual ~EventShapeCalculator() {}; + + virtual StatusCode initialize(); + virtual StatusCode execute(); + virtual StatusCode finalize(); + + private: + + std::string m_inputCollection; + std::string m_jetCollection; + std::string m_OutputCollection; + + // std::vector<std::string> m_eventShapeToolNames; + // std::string m_forwardTermToolName; + + typedef ToolHandleArray<IEventShapeToolBase> tool_store_t; + typedef ToolHandle<IEventShapeToolBase> tool_handle_t; + + tool_store_t m_eventShapeTools; + tool_handle_t m_forwardTermTool; + + double m_cutCentral; + double m_jetcutCentral; + double m_jetcutEt; +}; + +#endif diff --git a/Reconstruction/EventShapes/EventShapeRec/cmt/requirements b/Reconstruction/EventShapes/EventShapeRec/cmt/requirements new file mode 100755 index 0000000000000000000000000000000000000000..7c836a621e9fff7d5c2c01c1650c117e02edec61 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/cmt/requirements @@ -0,0 +1,31 @@ +package EventShapeRec + +author Rolf Seuster <Rolf.Seuster@cern.ch> +author Peter Loch <loch@physics.arizona.edu> + +use AtlasPolicy AtlasPolicy-* + +use GaudiInterface GaudiInterface-* External +use AtlasCLHEP AtlasCLHEP-* External +use AtlasROOT AtlasROOT-* External +use AtlasFastJet AtlasFastJet-* External + +use AthenaBaseComps AthenaBaseComps-* Control + +private + +use AthContainers AthContainers-* Control +use JetEvent JetEvent-* Reconstruction/Jet +use EventShapeEvent EventShapeEvent-* Reconstruction/EventShapes +use VxVertex VxVertex-* Tracking/TrkEvent + +end_private + +use EventShapeInterface EventShapeInterface-* Reconstruction/EventShapes + +apply_pattern dual_use_library files=*.cxx +apply_pattern declare_python_modules files="*.py" + +# private +# macro cppdebugflags '$(cppdebugflags_s)' +# macro_remove componentshr_linkopts "-Wl,-s" diff --git a/Reconstruction/EventShapes/EventShapeRec/python/EventEtDensityConfig.py b/Reconstruction/EventShapes/EventShapeRec/python/EventEtDensityConfig.py new file mode 100644 index 0000000000000000000000000000000000000000..97710b3e497cd5b07d3dcb17b0fa2a75fb7cd492 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/python/EventEtDensityConfig.py @@ -0,0 +1,65 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +from AthenaCommon.AlgSequence import AlgSequence +from AthenaCommon.SystemOfUnits import GeV +from EventShapeTools.EventEtClusterDensityConfig import configureJetAreaDensity, getDefaultEtDensityClusterDict +from EventShapeRec.EventShapeRecConf import EventEtDensityTester +from AthenaCommon.AppMgr import ToolSvc + +from AthenaCommon.AppMgr import ServiceMgr as svcMgr +from AthenaServices.TheUserDataSvc import TheUserDataSvc +svcMgr += TheUserDataSvc("UserDataSvc") + +# -- common tool settings +commonDict = dict(getDefaultEtDensityClusterDict()) +commonDict['Algorithm'] = "kt" +commonDict['JetAreaMethod'] = "VoronoiArea" +commonDict['VoronoiEffectiveRfact'] = 0.9 +commonDict['InclusivePtMin'] = 0.*GeV +commonDict['EtaMin'] = -2. +commonDict['EtaMax'] = 2. +commonDict['UseAreaFourMomentum'] = True +del commonDict['SignalState'] + + +def suffix (radius, calibrated): + suff = 'Kt%d' % int(radius*10 + 0.5) + return suff + ( 'LC' if calibrated else 'EM') + +def areaDensityTool (radius, calibrated): + + toolName = "ClusterRho"+ suffix (radius, calibrated) + + ss = 'CALIBRATED' if calibrated else 'UNCALIBRATED' + if not hasattr(ToolSvc, toolName): + rhoTool = configureJetAreaDensity (toolName, + Radius = radius, + SignalState = ss, + **commonDict) + else: + rhoTool = getattr(ToolSvc, toolName) + return rhoTool + +def calculateSimpleEventDensity(Radius = 0.4,SignalState="UNCALIBRATED", UseAreaFourMomentum=True, seq=AlgSequence() ): + """This function schedule an algorithm which compute a simple event et density, rho, variable and then stores it in userStore() + The key in userStore is in the form ClusterRhoKtXY where + - X = Radius*10 + - Y = EM if SignalState="UNCALIBRATED" and LC in other cases. + for example "ClusterRhoKt4EM" + + Subsequent calls of this function will simply schedule new calculations from the same athena algorithm. + """ + + # Check if an alg already exists + if hasattr( seq, "EventEtDensityTester" ): + alg = seq.EventEtDensityTester + elif hasattr( AlgSequence(), "EventEtDensityTester" ): + alg = seq.EventEtDensityTester + else: + alg = EventEtDensityTester("EventEtDensityTester", FillHistos=False, FillEventStore=True, VertexContainerKey="PrimaryVertices") + seq += alg + + rhoTool= areaDensityTool(Radius, SignalState=="CALIBRATED" ) + + alg.EventEtDensityTools += [ rhoTool ] + diff --git a/Reconstruction/EventShapes/EventShapeRec/share/EventEtDensity.py b/Reconstruction/EventShapes/EventShapeRec/share/EventEtDensity.py new file mode 100644 index 0000000000000000000000000000000000000000..e636978dbea097b2a9f584e5bbba7d1b273250a6 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/share/EventEtDensity.py @@ -0,0 +1,50 @@ + +from AthenaCommon.SystemOfUnits import * + +from EventShapeRec.EventShapeRecConf import EventEtDensityTester + +tester = EventEtDensityTester("EventEtDensityTester") + +#from EventShapeTools.EventShapeToolsConf import EventEtClusterDensityTool +from EventShapeTools.EventEtClusterDensityConfig import * + +# -- common tool settings +commonDict = dict(getDefaultEtDensityClusterDict()) +commonDict['Algorithm'] = "kt" +commonDict['JetAreaMethod'] = "VoronoiArea" +commonDict['VoronoiEffectiveRfact'] = 1.0 +commonDict['InclusivePtMin'] = 0.*GeV +commonDict['EtaMin'] = -2. +commonDict['EtaMax'] = 2. + +# -- configuration 1: kT, R = 0.3, LW, Voronoi +cadict = dict(commonDict) +cadict['Radius'] = 0.3 +cadict['SignalState'] = "CALIBRATED" +catool = configureJetAreaDensity("ClusterRhoKt3LCW",**cadict) +# -- configuration 2: kT, R = 0.4, LW, Voronoi +cbdict = dict(commonDict) +cbdict['Radius'] = 0.4 +cbdict['SignalState'] = "CALIBRATED" +cbtool = configureJetAreaDensity("ClusterRhoKt4LCW",**cbdict) +# -- configuration 3: kT, R = 0.3, EM, Voronoi +ccdict = dict(commonDict) +ccdict['Radius'] = 0.3 +ccdict['SignalState'] = "UNCALIBRATED" +cctool = configureJetAreaDensity("ClusterRhoKt3EM",**ccdict) +# -- configuration 4: kT, R = 0.4, EM, Voronoi +cddict = dict(commonDict) +cddict['Radius'] = 0.4 +cddict['SignalState'] = "UNCALIBRATED" +cdtool = configureJetAreaDensity("ClusterRhoKt4EM",**cddict) + +tester.EventEtDensityTools = [ catool.getFullName(), + cbtool.getFullName(), + cctool.getFullName(), + cdtool.getFullName() ] +tester += [ catool, cbtool, cctool, cdtool ] + +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() +topSequence += tester + diff --git a/Reconstruction/EventShapes/EventShapeRec/src/EventEtDensityCalculator.cxx b/Reconstruction/EventShapes/EventShapeRec/src/EventEtDensityCalculator.cxx new file mode 100644 index 0000000000000000000000000000000000000000..72323ae75cfdbe4fffabdb7caf715913ef2b80a4 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/src/EventEtDensityCalculator.cxx @@ -0,0 +1,73 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + + +// #include "EventShapeUtils/StaticHelpers.h" + +#include "EventShapeRec/EventEtDensityCalculator.h" + +#include <iostream> +#include <sstream> +#include <iomanip> + +EventEtDensityCalculator::EventEtDensityCalculator(const std::string& name, + ISvcLocator* pSvcLocator) + : EventFeatureAlgorithmBase(name,pSvcLocator) + // , m_densityTools(0) +{ + // declareProperty("EventEtDensityTools",m_densityTools); +} + +EventEtDensityCalculator::~EventEtDensityCalculator() +{ } + +StatusCode EventEtDensityCalculator::appInitialize() +{ + // if ( !m_densityTools.empty() && m_densityTools.retrieve().isFailure() ) + // { + // ATH_MSG_ERROR("Cannot allocate event Et density calculator tools"); + // return StatusCode::FAILURE; + // } + // ToolHandleArray<IEventEtDensityTool>::iterator fTool(m_densityTools.begin()); + // ToolHandleArray<IEventEtDensityTool>::iterator lTool(m_densityTools.end()); + // for ( ; fTool != lTool; ++fTool ) + // { + /* std::ostringstream ostr; + ostr << "Allocated tool <" + << EventShapeHelpers::stringFormatter(fTool->type(),32) + << "/" << EventShapeHelpers::stringFormatter(fTool->name(),32) + << ">"; + ATH_MSG_INFO(ostr.str()); */ + // } + return StatusCode::SUCCESS; +} + +StatusCode +EventEtDensityCalculator::appExecute(EventFeatureStore* /* pStore */, + const INavigable4MomentumCollection* /* pColl */ ) +{ + // ToolHandleArray<IEventEtDensityTool>::iterator fTool(m_densityTools.begin()); + // ToolHandleArray<IEventEtDensityTool>::iterator lTool(m_densityTools.end()); + // for ( ; fTool != lTool; ++fTool ) + // { + // this->executeMonitor(fTool->name(),fTool->type(), + // (*fTool)->execute(pStore,pColl)); + // } + return StatusCode::SUCCESS; +} + +StatusCode +EventEtDensityCalculator::appExecute(EventFeatureStore* /* pStore */ ) +{ + // ToolHandleArray<IEventEtDensityTool>::iterator fTool(m_densityTools.begin()); + // ToolHandleArray<IEventEtDensityTool>::iterator lTool(m_densityTools.end()); + // for ( ; fTool != lTool; ++fTool ) + // { + // this->executeMonitor(fTool->name(),fTool->type(), + // (*fTool)->execute(pStore)); + // } + return StatusCode::SUCCESS; +} + diff --git a/Reconstruction/EventShapes/EventShapeRec/src/EventEtDensityTester.cxx b/Reconstruction/EventShapes/EventShapeRec/src/EventEtDensityTester.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c2c22371db00fdb0dc82fc7beaa477584322ac3e --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/src/EventEtDensityTester.cxx @@ -0,0 +1,144 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +#include "GaudiKernel/ITHistSvc.h" + +#include "VxVertex/VxContainer.h" + +#include "EventShapeRec/EventEtDensityTester.h" + +EventEtDensityTester::EventEtDensityTester(const std::string& name, + ISvcLocator* pSvcLocator) + : AthAlgorithm(name,pSvcLocator) + , m_tools(0) + , m_histPath("EventEtDensity") + , m_vtxContainerKey("VxPrimaryCandidate") + , h_densities() + , p_densities() + , m_fillEvtStore(false) + , m_fillHistos(false) +{ + declareProperty("EventEtDensityTools",m_tools); + declareProperty("HistogramPath",m_histPath); + declareProperty("VertexContainerKey",m_vtxContainerKey); + declareProperty("FillEventStore",m_fillEvtStore); + declareProperty("FillHistos",m_fillHistos); +} + +EventEtDensityTester::~EventEtDensityTester() +{ } + +StatusCode EventEtDensityTester::initialize() +{ + // allocate tools + if ( m_tools.retrieve().isFailure() || m_tools.empty() ) + { + ATH_MSG_ERROR("No tools allocated for algorithm"); + return StatusCode::FAILURE; + } + + if(m_fillHistos){ + // book histograms for tools + ITHistSvc* pHistSvc = 0; + if ( service("THistSvc",pHistSvc).isFailure() ) + { + ATH_MSG_ERROR("Cannot allocate HistSvc"); + return StatusCode::FAILURE; + } + // + ToolHandleArray<IEventEtDensityProvider>::iterator fTool(m_tools.begin()); + ToolHandleArray<IEventEtDensityProvider>::iterator lTool(m_tools.end()); + for ( ; fTool != lTool; ++fTool ) + { + // rho distributions + std::string hName = m_histPath+"/Rho_"+(*fTool)->name(); + TH1D* h = new TH1D(hName.c_str(),hName.c_str(),80,0.,20.); + if ( pHistSvc->regHist(hName,h).isFailure() ) + { + ATH_MSG_WARNING("Cannot register histogram <" << hName << ">"); + h_densities.push_back((TH1D*)0); + } + else + { + ATH_MSG_INFO("Registered histogram <" << hName << ">"); + h_densities.push_back(h); + } + // rho versus NPV + std::string pName = m_histPath+"/RhoVsNpv_"+(*fTool)->name(); + TProfile* p = new TProfile(pName.c_str(),pName.c_str(), + 50,0.,50.); + if ( pHistSvc->regHist(pName,p).isFailure() ) + { + ATH_MSG_WARNING("Cannot register profile <" << pName << ">"); + p_densities.push_back((TProfile*)0); + } + else + { + ATH_MSG_INFO("Registered profile <" << pName << ">"); + p_densities.push_back(p); + } + } + } + + ATH_CHECK( userStore().retrieve() ); + return StatusCode::SUCCESS; +} + +StatusCode EventEtDensityTester::execute() +{ + // get event characteristics + double npv; + if(m_fillHistos) { + npv=this->getNPV(); + if (npv < 0. ) { + ATH_MSG_WARNING("Invalid Npv " << npv); + return StatusCode::SUCCESS; + } + } + // loop tools + ToolHandleArray<IEventEtDensityProvider>::iterator fTool(m_tools.begin()); + ToolHandleArray<IEventEtDensityProvider>::iterator lTool(m_tools.end()); + std::vector<TH1D*>::iterator fHist(h_densities.begin()); + std::vector<TProfile*>::iterator fProf(p_densities.begin()); + for ( ; fTool != lTool; ++fTool, ++fHist, ++fProf ) + { + double rho((*fTool)->rho()); + if(m_fillHistos && (npv>=0 )){ + (*fHist)->Fill(rho); + (*fProf)->Fill(npv,rho); + } + if(m_fillEvtStore){ + std::string n = (*fTool)->name(); + n = n.substr(n.find_last_of(".")+1); + ATH_CHECK ( userStore()->record( n, rho) ); + ATH_MSG_DEBUG( " stored "<< n << " "<<rho) ; + } + } + return StatusCode::SUCCESS; +} + +double EventEtDensityTester::getNPV() +{ + // picking up the vertex container for all methods + const VxContainer* pVxColl = 0; + if ( evtStore()->retrieve(pVxColl,m_vtxContainerKey).isFailure() ) + { + ATH_MSG_WARNING("Cannot allocate VxContainer with key <" + << m_vtxContainerKey << ">"); + return StatusCode::SUCCESS; + } + // count primary vertices + VxContainer::const_iterator fVtx(pVxColl->begin()); + VxContainer::const_iterator lVtx(pVxColl->end()); + size_t npvCtr(0); + for ( ; fVtx != lVtx; ++fVtx ) + { if ( (*fVtx)->vertexType() == Trk::PriVtx ) ++npvCtr; } + if ( npvCtr == 0 ) + { + ATH_MSG_WARNING("No primary vertex in event"); + return double(-1.0); + } + return (double)npvCtr; +} diff --git a/Reconstruction/EventShapes/EventShapeRec/src/EventFeatureAlgorithmBase.cxx b/Reconstruction/EventShapes/EventShapeRec/src/EventFeatureAlgorithmBase.cxx new file mode 100644 index 0000000000000000000000000000000000000000..eadd32dbd7b53492d50fe901a7592986a545c327 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/src/EventFeatureAlgorithmBase.cxx @@ -0,0 +1,189 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +// #include "EventShapeEvent/EventFeatureStore.h" + +// #include "EventShapeUtils/StaticHelpers.h" + +// #include "EventShapeInterface/StaticConstants.h" + +#include "EventShapeRec/EventFeatureAlgorithmBase.h" + +#include <iostream> +#include <iomanip> +#include <sstream> + +EventFeatureAlgorithmBase::EventFeatureAlgorithmBase(const std::string& name, + ISvcLocator* pSvcLocator) + : AthAlgorithm(name,pSvcLocator) + // , m_inputCollectionKey(EventShapeConstants::invalidKey()) + , m_haveInputCollection(false) + // , m_eventFeatureStoreKey(EventShapeConstants::invalidKey()) + , m_createFeatureStore(false) + , m_eventFeatureTools(0) + , m_haveFeatureTools(false) +{ + declareProperty("InputCollectionKey", m_inputCollectionKey); + declareProperty("EventFeatureStoreKey",m_eventFeatureStoreKey); + declareProperty("EventFeatureTools", m_eventFeatureTools); +} + +EventFeatureAlgorithmBase::~EventFeatureAlgorithmBase() +{ } + +StatusCode EventFeatureAlgorithmBase::initialize() +{ + // retrieve tool + m_haveFeatureTools = !m_eventFeatureTools.empty(); + if ( m_haveFeatureTools ) + { + if ( m_eventFeatureTools.retrieve().isFailure() ) + { + ATH_MSG_ERROR("Could not retrieve EventFeatureTools"); + return StatusCode::FAILURE; + } + } + // process control + /* m_haveInputCollection = + m_inputCollectionKey != EventShapeConstants::invalidKey(); + m_createFeatureStore = + m_eventFeatureStoreKey != EventShapeConstants::invalidKey(); */ + + // execute sub-class initialization + return this->appInitialize(); +} + +StatusCode EventFeatureAlgorithmBase::appInitialize() +{ return StatusCode::SUCCESS; } + +StatusCode EventFeatureAlgorithmBase::execute() +{ + // create new feature store + EventFeatureStore* pStore = new EventFeatureStore(); + // retrieve input + if ( m_haveInputCollection ) + { + const INavigable4MomentumCollection* pColl = 0; + if ( evtStore()->retrieve(pColl,m_inputCollectionKey).isFailure() ) + { + ATH_MSG_ERROR("Cannot retrieve INavigable4MomentumCollection with " + << " key <" << m_inputCollectionKey << ">"); + return StatusCode::FAILURE; + } + // loop tools if requested + if ( m_haveFeatureTools ) + { + tool_iterator_t fTool(m_eventFeatureTools.begin()); + tool_iterator_t lTool(m_eventFeatureTools.end()); + for ( ; fTool != lTool; ++fTool ) + { + this->executeMonitor(fTool->name(),fTool->type(), + (*fTool)->execute(pStore,pColl)); + } + } + // check client application + if ( m_createFeatureStore ) + { + return this->recordStore(pStore,m_eventFeatureStoreKey).isSuccess() + ? this->appExecute(pStore,pColl) + : StatusCode::FAILURE; + } + else + { + StatusCode checkOut(this->appExecute(pStore,pColl)); + if ( pStore != 0 ) delete pStore; + return checkOut.isSuccess() + ? StatusCode::SUCCESS : StatusCode::SUCCESS; + } + } + // no input + else + { + if ( m_haveFeatureTools ) + { + tool_iterator_t fTool(m_eventFeatureTools.begin()); + tool_iterator_t lTool(m_eventFeatureTools.end()); + for ( ; fTool != lTool; ++fTool ) + { + this->executeMonitor(fTool->name(),fTool->type(), + (*fTool)->execute(pStore)); + } + } + if ( m_createFeatureStore ) + { + return this->recordStore(pStore,m_eventFeatureStoreKey).isSuccess() + ? this->appExecute(pStore) + : StatusCode::FAILURE; + } + else + { + StatusCode checkOut(this->appExecute(pStore)); + if ( pStore != 0 ) delete pStore; + return checkOut.isSuccess() + ? StatusCode::SUCCESS : StatusCode::SUCCESS; + } + } +} + +StatusCode +EventFeatureAlgorithmBase::appExecute(EventFeatureStore* /*pStore*/, + const INavigable4MomentumCollection* + /*pColl*/) +{ return StatusCode::SUCCESS; } + +StatusCode +EventFeatureAlgorithmBase::appExecute(EventFeatureStore* /*pStore*/) +{ return StatusCode::SUCCESS; } + +StatusCode EventFeatureAlgorithmBase::finalize() +{ this->executeSummary(); return this->appFinalize(); } + +StatusCode EventFeatureAlgorithmBase::appFinalize() +{ return StatusCode::SUCCESS; } + +void EventFeatureAlgorithmBase::executeMonitor(const std::string& name, + const std::string& type, + StatusCode checkOut) +{ + tag_t tag(name,type); + map_t::iterator fMap(m_executeStats.find(tag)); + if ( fMap == m_executeStats.end() ) + { + m_executeStats[tag] = data_t(0,0); + fMap = m_executeStats.find(tag); + } + // + if ( checkOut.isSuccess() ) + { ((*fMap).second).first++; } + else + { ((*fMap).second).second++; } +} + +void EventFeatureAlgorithmBase::executeSummary(bool cleanUp) +{ + // static size_t _mstrlen(32); + ATH_MSG_INFO("Tool execution summary: "); + map_t::iterator fMap(m_executeStats.begin()); + map_t::iterator lMap(m_executeStats.end()); + for ( ; fMap != lMap; ++fMap ) + { + /* std::ostringstream ostr; + ostr << "Tool <name/type> success/failures: <" + << std::setw(_mstrlen) << std::right + << EventShapeHelpers::stringFormatter(fMap->first.first,_mstrlen) + << "/" + << std::setw(_mstrlen) << std::left + << EventShapeHelpers::stringFormatter(fMap->first.second,_mstrlen) + << "> " << std::setw(8) << std::right + << fMap->second.first << "/" + << std::setw(8) << std::left + << fMap->second.second; + ATH_MSG_INFO(ostr.str()); */ + } + if ( cleanUp ) m_executeStats.clear(); +} + +const std::string& EventFeatureAlgorithmBase::getFeatureStoreKey() const +{ return this->featureStoreKey(); } diff --git a/Reconstruction/EventShapes/EventShapeRec/src/EventShapeCalculator.cxx b/Reconstruction/EventShapes/EventShapeRec/src/EventShapeCalculator.cxx new file mode 100755 index 0000000000000000000000000000000000000000..8e0add5857825c85a08e8b93bfe82db298f95983 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/src/EventShapeCalculator.cxx @@ -0,0 +1,185 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +#include "EventShapeRec/EventShapeCalculator.h" +#include "JetEvent/JetCollection.h" + +#include "EventShapeEvent/EventShapes.h" +#include "EventShapeEvent/EventShapeStore.h" +#include "EventShapeEvent/EventShapeTypes.h" +#include "AthContainers/ConstDataVector.h" + +#include <cmath> + +EventShapeCalculator::EventShapeCalculator(const std::string& name, + ISvcLocator* pSvcLocator) + : AthAlgorithm(name,pSvcLocator) + , m_eventShapeTools() + , m_forwardTermTool("") +{ + // input data + declareProperty("InputCollection",m_inputCollection); + declareProperty("CentralRegionCut",m_cutCentral=2.5); + + declareProperty("JetCollection",m_jetCollection="Cone4TowerJets"); + declareProperty("JetRegionCut", m_jetcutCentral=2.0); + declareProperty("JetEtCut", m_jetcutEt=25.0); + + declareProperty("OutputCollection",m_OutputCollection); + // declareProperty("EventShapeToolNames",m_eventShapeToolNames); + // declareProperty("ForwardTermToolName",m_forwardTermToolName=""); + declareProperty("EventShapeTools",m_eventShapeTools); + declareProperty("ForwardTermTool",m_forwardTermTool); +} + +StatusCode EventShapeCalculator::initialize() +{ + StatusCode checkOut = m_eventShapeTools.retrieve(); + if ( checkOut.isFailure() ) + { + msg(MSG::ERROR) << "cannot allocate tools " << m_eventShapeTools << endreq; + return checkOut; + } + + for ( tool_store_t::const_iterator tool_iter = m_eventShapeTools.begin(); + tool_iter != m_eventShapeTools.end(); tool_iter++ ) + if (((*tool_iter)->initTool(m_cutCentral)).isFailure() ) + msg(MSG::ERROR) << "initTool() for tool " << tool_iter->name() << " failed" << endreq; + + checkOut = m_forwardTermTool.retrieve(); + if ( checkOut.isFailure() ) + { + msg(MSG::ERROR) << "cannot allocate tool " << m_forwardTermTool << endreq; + return checkOut; + } + if ((m_forwardTermTool->initTool(m_cutCentral)).isFailure() ) + msg(MSG::ERROR) << "initTool() for tool " << m_forwardTermTool->name() << " failed" << endreq; + + msg(MSG::INFO) << "List of tools:" << endreq; + for ( tool_store_t::const_iterator tool_iter = m_eventShapeTools.begin(); + tool_iter != m_eventShapeTools.end(); tool_iter++ ) + msg(MSG::INFO) << ".. " << tool_iter->name() << endreq; + msg(MSG::INFO) << "Calculation of forward Term:" << endreq; + msg(MSG::INFO) << ".. " << m_forwardTermTool->name() << endreq; + return StatusCode::SUCCESS; +} + +StatusCode EventShapeCalculator::execute() +{ + // message service + MsgStream log(messageService(),name()); + if (msgLvl(MSG::INFO)) + msg(MSG::INFO) << "execute" << endreq; + + // pre-cuts. highest two energetic jets (detault: Cone4Tower) within eta range + // defined by m_cutCentral + const JetCollection* pJets = 0; + StatusCode checkOut(evtStore()->retrieve(pJets,m_jetCollection)); + if ( checkOut.isFailure() ) + { + msg(MSG::ERROR) << "cannot allocate jet collection with key <" + << m_jetCollection << ">" << endreq; + return checkOut; + } + + // jets are sorted, more than 2 ? + if ( pJets->size()<2 ) + { + if (msgLvl(MSG::DEBUG)) + msg(MSG::DEBUG) << "Not enough jets in this event" << endreq; + return StatusCode::SUCCESS; + } + + double et_jet1=0; + double et_jet2=0; + + bool callTools = true; + + if ( fabs((*pJets)[0]->et()) < m_jetcutEt ) + { + if (msgLvl(MSG::DEBUG)) + msg(MSG::DEBUG) << "jet one outside of Et region!" << endreq; + callTools = false; + } + + if ( fabs((*pJets)[0]->eta()) > m_jetcutCentral || + fabs((*pJets)[1]->eta()) > m_jetcutCentral ) + { + if (msgLvl(MSG::DEBUG)) + msg(MSG::DEBUG) << "jets outside of cut region!" << endreq; + callTools = false; + } + + et_jet1=(*pJets)[0]->et(); + et_jet2=(*pJets)[1]->et(); + + // particles.clear(); + + StatusCode checkColl = StatusCode::SUCCESS; + + // allocate collection + const INavigable4MomentumCollection* thisColl; + + checkColl = evtStore()->retrieve(thisColl,m_inputCollection); + + if ( checkColl.isFailure() ) + { + msg(MSG::ERROR) + << "Error retrieving collection with key <" + << m_inputCollection << ">" << endreq; + return StatusCode::FAILURE; + } + + EventShapeStore *ess = new EventShapeStore(); + StatusCode writeOut = evtStore()->record(ess,m_OutputCollection); + + ess->insert(EventShapes::JET1_ET, et_jet1); + ess->insert(EventShapes::JET2_ET, et_jet2); + ess->insert(EventShapes::CENTRAL_CUT, m_cutCentral); + ess->insert(EventShapes::JET_ETA_CUT, m_jetcutCentral); + + if(callTools) + { + typedef ConstDataVector<EventShapeTypes::es_4vect_vect_t> + selected_particles_t; + selected_particles_t selectedParticles(SG::VIEW_ELEMENTS); + + std::remove_copy_if(thisColl->begin(), + thisColl->end(), + std::back_insert_iterator<selected_particles_t>(selectedParticles), + etaSelector(m_cutCentral) ); + + for ( tool_store_t::const_iterator tool_iter = m_eventShapeTools.begin(); + tool_iter != m_eventShapeTools.end(); tool_iter++ ) + (*tool_iter)->calculate(selectedParticles.asDataVector(),ess); + + // this is the only tool to run on the full collection + selectedParticles.clear(); + std::copy(thisColl->begin(), + thisColl->end(), + std::back_insert_iterator<selected_particles_t>(selectedParticles)); + if(bool(m_forwardTermTool)) + m_forwardTermTool->calculate(selectedParticles.asDataVector(),ess); + } + + writeOut = evtStore()->setConst(ess); + + if ( writeOut.isFailure() ) + { + msg(MSG::FATAL) + << "Error writing out the EventShapeStore with key <" + << m_OutputCollection << ">" << endreq; + return StatusCode::FAILURE; + } + + return StatusCode::SUCCESS; +} + +StatusCode EventShapeCalculator::finalize() +{ + if (msgLvl(MSG::INFO)) + msg(MSG::INFO) << "finalialize" << endreq; + return StatusCode::SUCCESS; +} diff --git a/Reconstruction/EventShapes/EventShapeRec/src/components/EventShapeRec_entries.cxx b/Reconstruction/EventShapes/EventShapeRec/src/components/EventShapeRec_entries.cxx new file mode 100755 index 0000000000000000000000000000000000000000..c2edd73fb52a4023c465d265a340fc5b45e9e130 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/src/components/EventShapeRec_entries.cxx @@ -0,0 +1,16 @@ + +#include "EventShapeRec/EventShapeCalculator.h" +#include "EventShapeRec/EventEtDensityCalculator.h" +#include "EventShapeRec/EventEtDensityTester.h" + +#include "GaudiKernel/DeclareFactoryEntries.h" + +DECLARE_ALGORITHM_FACTORY( EventShapeCalculator ) +DECLARE_ALGORITHM_FACTORY( EventEtDensityCalculator ) +DECLARE_ALGORITHM_FACTORY( EventEtDensityTester ) + +DECLARE_FACTORY_ENTRIES( EventShapeRec ) { + DECLARE_ALGORITHM( EventShapeCalculator ); + DECLARE_ALGORITHM( EventEtDensityCalculator ); + DECLARE_ALGORITHM( EventEtDensityTester ); +} diff --git a/Reconstruction/EventShapes/EventShapeRec/src/components/EventShapeRec_load.cxx b/Reconstruction/EventShapes/EventShapeRec/src/components/EventShapeRec_load.cxx new file mode 100755 index 0000000000000000000000000000000000000000..9b872fb4f64fbd1df5f3a2cbc220e311de91d9d0 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeRec/src/components/EventShapeRec_load.cxx @@ -0,0 +1,3 @@ +#include "GaudiKernel/LoadFactoryEntries.h" + +LOAD_FACTORY_ENTRIES(EventShapeRec)