diff --git a/Reconstruction/EventShapes/EventShapeTools/EventShapeTools/EventShapeCopier.h b/Reconstruction/EventShapes/EventShapeTools/EventShapeTools/EventShapeCopier.h new file mode 100644 index 0000000000000000000000000000000000000000..5d6984627e4a4b1e2aac3eca9f6985df9ecfea85 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeTools/EventShapeTools/EventShapeCopier.h @@ -0,0 +1,63 @@ +// EventDensityTool.h -*- C++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +#ifndef EVENTSHAPETOOLS_EVENTSHAPECOPIER_H +#define EVENTSHAPETOOLS_EVENTSHAPECOPIER_H + +////////////////////////////////////////////////////// +/// \class EventShapeCopier +/// \author P-A Delsart +/// +/// A dual-use tool to copy EventShape objects +/// +/// The intent of this tool is primarily to rename EventShape objects produced +/// in the very first DxAOD files before the final naming scheme was chosen. +/// +/// In RootCore analysis : the easiest is to simply call the static "renameEventDensities()" +/// function before attempting to access the "Kt4/6LCTopoEventShape" objects. +/// +/// In Athena : schedule an athena alg by : +/// from EventShapeTools.EventDensityConfig import configEventShapeCopierAlg +/// topSequence += configEventShapeCopierAlg("LCTopo") +/// +/////////////////////////////////////////// + +#include "AsgTools/AsgTool.h" +#include "EventShapeInterface/IEventShapeTool.h" + +class EventShapeCopier : + public asg::AsgTool, + virtual public ::IEventShapeTool { + ASG_TOOL_CLASS(EventShapeCopier, IEventShapeTool) + +public: + + /// Constructor with parameters: + EventShapeCopier( const std::string& name); + + /// Destructor: + ~EventShapeCopier(); + + /// Initialization. + StatusCode initialize(); + + /// Action. + StatusCode fillEventShape() const; + StatusCode fillEventShape(xAOD::EventShape* es) const; + StatusCode fillEventShape(xAOD::EventShape* es, const xAOD::IParticleContainer* input) const; + + + static void renameEventDensities(); +protected: + + std::string m_inputEventShape; + std::string m_outputEventShape; + std::string m_eventDensityName; + +}; + +#endif diff --git a/Reconstruction/EventShapes/EventShapeTools/EventShapeTools/EventShapeToolsDict.h b/Reconstruction/EventShapes/EventShapeTools/EventShapeTools/EventShapeToolsDict.h new file mode 100644 index 0000000000000000000000000000000000000000..c1ee28069904774b692b2fc4e0b2eef43f5481c7 --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeTools/EventShapeTools/EventShapeToolsDict.h @@ -0,0 +1,10 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef EVENTSHAPETOOLS_EVENTSHAPETOOLSDICT_H +#define EVENTSHAPETOOLS_EVENTSHAPETOOLSDICT_H + +#include "EventShapeTools/EventDensityTool.h" + +#endif //EVENTSHAPETOOLS_EVENTSHAPETOOLSDICT_H diff --git a/Reconstruction/EventShapes/EventShapeTools/EventShapeTools/selection.xml b/Reconstruction/EventShapes/EventShapeTools/EventShapeTools/selection.xml new file mode 100644 index 0000000000000000000000000000000000000000..3aaa7ced8e8619703b6e7c9ad5b1b22b45d702ea --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeTools/EventShapeTools/selection.xml @@ -0,0 +1,4 @@ +<lcgdict> + <class name="EventDensityTool" /> + +</lcgdict> diff --git a/Reconstruction/EventShapes/EventShapeTools/Root/EventDensityTool.cxx b/Reconstruction/EventShapes/EventShapeTools/Root/EventDensityTool.cxx index 52f895b4e8b320cce1d0234e6835f6c02547ed36..c5eaee243b408aa13dcc7839903ee69c33aff535 100644 --- a/Reconstruction/EventShapes/EventShapeTools/Root/EventDensityTool.cxx +++ b/Reconstruction/EventShapes/EventShapeTools/Root/EventDensityTool.cxx @@ -22,7 +22,10 @@ using fastjet::VoronoiAreaSpec; EventDensityTool::EventDensityTool(const std::string& name) : asg::AsgTool(name), - m_rhoDec(""), m_sigmaDec(""), m_areaDec("") { + m_useAreaFourMom(false), + m_rhoDec(""), + m_sigmaDec(""), + m_areaDec("") { declareProperty("JetAlgorithm", m_jetalg = "Kt"); declareProperty("JetRadius", m_jetrad = 0.4); declareProperty("JetInput", m_pjgetter); @@ -58,7 +61,7 @@ StatusCode EventDensityTool::initialize() { m_fjjetdef = JetDefinition(fjalg, m_jetrad); // Build area definition. - m_useAreaFourMom = m_areadef == "ActiveFourVector"; + m_useAreaFourMom = (m_areadef == "ActiveFourVector"); if ( m_areadef == "Voronoi" ) { m_fjareadef = AreaDefinition(fastjet::voronoi_area, VoronoiAreaSpec(m_vrfact)); } else if ( m_areadef == "Active" || m_useAreaFourMom ) { diff --git a/Reconstruction/EventShapes/EventShapeTools/Root/EventShapeCopier.cxx b/Reconstruction/EventShapes/EventShapeTools/Root/EventShapeCopier.cxx new file mode 100644 index 0000000000000000000000000000000000000000..89b4ff34812c54f2944b6fed6f8c2439566eb24b --- /dev/null +++ b/Reconstruction/EventShapes/EventShapeTools/Root/EventShapeCopier.cxx @@ -0,0 +1,97 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// EventShapeCopier.cxx + +#include "EventShapeTools/EventShapeCopier.h" + +#include "xAODEventShape/EventShape.h" +#include "xAODEventShape/EventShapeAuxInfo.h" + +//********************************************************************** + +EventShapeCopier::EventShapeCopier(const std::string& name) +: asg::AsgTool(name), + m_inputEventShape("LCTopoEventShape"), m_outputEventShape(""), m_eventDensityName("") { + declareProperty("InputEventShape", m_inputEventShape ); + declareProperty("OutputEventShape", m_outputEventShape ); + declareProperty("EventDensityName", m_eventDensityName ); + +} + +//********************************************************************** + +EventShapeCopier::~EventShapeCopier() {} + +//********************************************************************** + +StatusCode EventShapeCopier::initialize() { + + return StatusCode::SUCCESS; +} + +//********************************************************************** + +StatusCode EventShapeCopier::fillEventShape() const { + + ATH_MSG_DEBUG("Begin fillEventShape()"); + + if ( evtStore()->contains<xAOD::EventShape>(m_outputEventShape) ){ + ATH_MSG_WARNING( "EventShape with key "<< m_outputEventShape << " already exists. " ); + return StatusCode::SUCCESS; + } + + xAOD::EventShape *evs = new xAOD::EventShape(); + xAOD::EventShapeAuxInfo* aux = new xAOD::EventShapeAuxInfo(); + evs->setStore( aux ); + ATH_CHECK( evtStore()->record( aux, m_outputEventShape + "Aux." ) ); + ATH_CHECK( evtStore()->record( evs, m_outputEventShape ) ); + ATH_MSG_DEBUG("Created new EventShape container: " << m_outputEventShape); + + return fillEventShape(evs); +} + +//********************************************************************** +StatusCode EventShapeCopier::fillEventShape(xAOD::EventShape *evs) const { + const xAOD::EventShape * inputES; + ATH_CHECK( evtStore()->retrieve(inputES, m_inputEventShape) ); + + evs->auxdata<float> ("Density") = inputES->auxdata<float>( m_eventDensityName ) ; + evs->auxdata<float> ("DensitySigma") = inputES->auxdata<float>( m_eventDensityName+"Sigma" ) ; + evs->auxdata<float> ("DensityArea") = inputES->auxdata<float>( m_eventDensityName+"Area" ) ; + + return StatusCode::SUCCESS; +} + + +StatusCode EventShapeCopier::fillEventShape(xAOD::EventShape *evs, const xAOD::IParticleContainer*) const { + // Ignore IParticleContainer argument. + + return fillEventShape( evs); +} + +//********************************************************************** + +#ifdef XAOD_ANALYSIS +void EventShapeCopier::renameEventDensities(){ + static EventShapeCopier kt4copier("Kt4LCTopoEDCopier"); + static EventShapeCopier kt6copier("Kt6LCTopoEDCopier"); + static bool needinit = true; + if(needinit){ + kt4copier.setProperty("InputEventShape", "LCTopoEventShape"); + kt4copier.setProperty("OutputEventShape", "Kt4LCTopoEventShape"); + kt4copier.setProperty("EventDensityName", "DensityForJetsR4"); + + kt6copier.setProperty("InputEventShape", "LCTopoEventShape"); + kt6copier.setProperty("OutputEventShape", "Kt6LCTopoEventShape"); + kt6copier.setProperty("EventDensityName", "DensityForJetsR6"); + needinit = false; + } + kt4copier.fillEventShape(); + kt6copier.fillEventShape(); +} +#else +// In Athena, do nothing. Use an Athena alg as defined in python/EventDensityConfig.py +void EventShapeCopier::renameEventDensities(){} +#endif diff --git a/Reconstruction/EventShapes/EventShapeTools/cmt/Makefile.RootCore b/Reconstruction/EventShapes/EventShapeTools/cmt/Makefile.RootCore index 552435d88021ed29cd2881e0092ebf7e6d967fb5..25bda3a2dda64f20e072af70a2017bab86824bf2 100644 --- a/Reconstruction/EventShapes/EventShapeTools/cmt/Makefile.RootCore +++ b/Reconstruction/EventShapes/EventShapeTools/cmt/Makefile.RootCore @@ -12,7 +12,7 @@ PACKAGE_OBJFLAGS = PACKAGE_LDFLAGS = PACKAGE_BINFLAGS = PACKAGE_LIBFLAGS = -PACKAGE_DEP = AsgTools PATCore PATInterfaces xAODJet JetInterface xAODEventShape +PACKAGE_DEP = AsgTools PATCore PATInterfaces xAODJet JetInterface xAODEventShape Asg_FastJet PACKAGE_TRYDEP = PACKAGE_CLEAN = PACKAGE_PEDANTIC = 0 diff --git a/Reconstruction/EventShapes/EventShapeTools/cmt/requirements b/Reconstruction/EventShapes/EventShapeTools/cmt/requirements index 61a65fd9153fab35e8fb014a55318746f03dbd19..1a797f8cd2430b7805f63cb170381fb1d7f90342 100755 --- a/Reconstruction/EventShapes/EventShapeTools/cmt/requirements +++ b/Reconstruction/EventShapes/EventShapeTools/cmt/requirements @@ -9,7 +9,8 @@ use EventShapeInterface EventShapeInterface-* Reconstruction/EventShapes use JetInterface JetInterface-* Reconstruction/Jet private -use xAODEventShape xAODEventShape-* Event/xAOD +use xAODEventShape xAODEventShape-* Event/xAOD +use AtlasReflex AtlasReflex-* External end_private apply_pattern dual_use_library files="../Root/*.cxx *.cxx" @@ -18,3 +19,8 @@ apply_pattern declare_joboptions files="*.txt *.py" apply_pattern declare_python_modules files="*.py" +# +# Create a dictionary for the persistent representation +# of transient classes +private +apply_pattern lcgdict dict=EventShapeTools selectionfile=selection.xml headerfiles="../EventShapeTools/EventShapeToolsDict.h" diff --git a/Reconstruction/EventShapes/EventShapeTools/python/EventDensityConfig.py b/Reconstruction/EventShapes/EventShapeTools/python/EventDensityConfig.py index c04c76af91729163eed2710f1baed292a664e4b5..4ca9431925aaeeb706c895242f5bea311a766cab 100644 --- a/Reconstruction/EventShapes/EventShapeTools/python/EventDensityConfig.py +++ b/Reconstruction/EventShapes/EventShapeTools/python/EventDensityConfig.py @@ -1,6 +1,6 @@ # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -from EventShapeTools.EventShapeToolsConf import EventDensityTool +from EventShapeTools.EventShapeToolsConf import EventDensityTool, EventShapeCopier def configEventDensityTool( name, pjGetter, radius, **options ): """ options can be used to pass any EventDensityTool properties @@ -21,6 +21,22 @@ def configEventDensityTool( name, pjGetter, radius, **options ): # Build the tool : return EventDensityTool(name, **toolProperties) + +def configEventShapeCopierAlg( input ): + """ Returns an Athena alg copying EventShape objects with old key/names to objects with new key/names + """ + def buildTool( alg): + from AthenaCommon.AppMgr import ToolSvc + t= EventShapeCopier( input+alg+"EvtShapeCopier", + InputEventShape=input+"EventShape", + OutputEventShape=alg+input+"EventShape", + EventDensityName = "DensityForJetsR" + alg[-1]) + ToolSvc +=t + return t + return EventDensityAlg(input+"EventShapeCopierAlg", EventDensityTool = [ buildTool("Kt4"), buildTool("Kt6") ] ) + + + ## EventDensity Alg for Athena import AthenaCommon.SystemOfUnits as Units import AthenaPython.PyAthena as PyAthena @@ -39,12 +55,23 @@ class EventDensityAlg (PyAthena.Alg): def initialize(self): self.msg.info('==> initialize...') - self.edTool = PyAthena.py_tool(self.EventDensityTool.getFullName(), iface='IEventShapeTool') + tools = self.EventDensityTool + if not isinstance( tools, list): + tools = [tools] + + self.edTools = [PyAthena.py_tool(t.getFullName(), iface='IEventShapeTool') for t in tools ] + self.msg.info(" using density tools : %s"%( self.edTools, ) ) + return StatusCode.Success def execute(self): self.msg.debug('==> executing ...') - return self.edTool.fillEventShape() + for t in self.edTools: + sc = t.fillEventShape() + if not sc.isSuccess(): + self.msg.error(" Error while computing density with tool %s "%(t.name(),)) + return StatusCode.Recoverable + return StatusCode.Success def finalize(self): diff --git a/Reconstruction/EventShapes/EventShapeTools/src/components/EventShapeTools_entries.cxx b/Reconstruction/EventShapes/EventShapeTools/src/components/EventShapeTools_entries.cxx index 4bb0df6f2b28628888871f8a29f8ee9ed4bf9a47..3c04df17922bfab672aee24b6e0a25b82fb42d63 100755 --- a/Reconstruction/EventShapes/EventShapeTools/src/components/EventShapeTools_entries.cxx +++ b/Reconstruction/EventShapes/EventShapeTools/src/components/EventShapeTools_entries.cxx @@ -1,8 +1,12 @@ #include "EventShapeTools/EventDensityTool.h" +#include "EventShapeTools/EventShapeCopier.h" #include "GaudiKernel/DeclareFactoryEntries.h" DECLARE_TOOL_FACTORY( EventDensityTool ) +DECLARE_TOOL_FACTORY( EventShapeCopier ) DECLARE_FACTORY_ENTRIES( EventShapeTools ) { DECLARE_TOOL( EventDensityTool ); + DECLARE_TOOL( EventShapeCopier ); + }