Skip to content
Snippets Groups Projects
Commit d1481bef authored by John Derek Chapman's avatar John Derek Chapman Committed by Vakhtang Tsulaia
Browse files

Migrate SimEventFilter to be an AthReentrantAlgorithm

parent 6856b7cc
No related branches found
No related tags found
7 merge requests!69091Fix correlated smearing bug in JER in JetUncertainties in 22.0,!58791DataQualityConfigurations: Modify L1Calo config for web display,!51674Fixing hotSpotInHIST for Run3 HIST,!50012RecExConfig: Adjust log message levels from GetRunNumber and GetLBNumber,!46784MuonCondInterface: Enable thread-safety checking.,!46776Updated LArMonitoring config file for WD to match new files produced using MT,!46504Migrate SimEventFilter to be an AthReentrantAlgorithm
......@@ -11,6 +11,10 @@ find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread )
find_package( GTest )
find_package( GMock )
find_package( Eigen )
set( extra_libs )
if( NOT SIMULATIONBASE )
set( extra_libs EventBookkeeperToolsLib )
endif()
# Component(s) in the package:
atlas_add_component( ISF_Algorithms
......@@ -19,7 +23,8 @@ atlas_add_component( ISF_Algorithms
LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} GaudiKernel
AthenaBaseComps StoreGateLib AtlasDetDescr GeneratorObjects HepMC_InterfacesLib
ISF_Event ISF_InterfacesLib ISF_HepMC_Interfaces PmbCxxUtils InDetSimEvent
CaloSimEvent LArSimEvent TileSimEvent MuonSimEvent TrackRecordLib RecEvent )
CaloSimEvent LArSimEvent TileSimEvent MuonSimEvent TrackRecordLib RecEvent
${extra_libs} )
atlas_add_test( CollectionMerger_test
SOURCES test/CollectionMerger_test.cxx src/CollectionMerger.h
......
......@@ -60,6 +60,7 @@ def getSimEventFilter(name="ISF_SimEventFilter", **kwargs):
return simEventFilter
def getInvertedSimEventFilter(name="ISF_InvertedSimEventFilter", **kwargs):
kwargs.setdefault("FilterKey", "ISF_InvertedSimEventFilter")
kwargs.setdefault("InvertFilter", True)
return getSimEventFilter(name, **kwargs)
......
......@@ -18,6 +18,7 @@ def SimEventFilterCfg(flags, name="ISF_SimEventFilter", sequenceName='SimSequenc
return result
def InvertedSimEventFilterCfg(flags, name="ISF_InvertedSimEventFilter", sequenceName='CopyHitSequence', **kwargs):
kwargs.setdefault("FilterKey", "ISF_InvertedSimEventFilter")
kwargs.setdefault("InvertFilter", True)
return SimEventFilterCfg(flags, name, sequenceName, **kwargs)
......
......@@ -2,12 +2,16 @@
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
#ifndef SIMULATIONBASE
// ISF_Algs includes
#include "SimEventFilter.h"
// FrameWork includes
#include "Gaudi/Property.h"
// McEventCollection
#include "GeneratorObjects/McEventCollection.h"
//
#include "EventBookkeeperTools/FilterReporter.h"
///////////////////////////////////////////////////////////////////
// Public methods:
......@@ -16,17 +20,15 @@
// Constructors
////////////////
ISF::SimEventFilter::SimEventFilter( const std::string& name, ISvcLocator* pSvcLocator ) :
::AthFilterAlgorithm( name, pSvcLocator )
::AthReentrantAlgorithm( name, pSvcLocator )
{
setFilterDescription("Filter to select events where two particle filter chains gave different selection results for at least one particle");
}
// Athena Algorithm's Hooks
////////////////////////////
StatusCode ISF::SimEventFilter::initialize()
{
ATH_CHECK(m_filterParams.initialize(false));
ATH_MSG_VERBOSE ( "--------------------------------------------------------" );
ATH_MSG_VERBOSE ( "Initializing the ISF Sim Filter " );
......@@ -44,16 +46,14 @@ StatusCode ISF::SimEventFilter::finalize()
{
ATH_MSG_VERBOSE ( "Finalizing ..." );
//TODO: thread safe output of filter decisions
ATH_MSG_INFO(" pass = "<<m_pass<<" / "<<m_total<<" = "<<(m_total>0 ? (100.0*m_pass)/m_total : 0)<<"%");
ATH_MSG_INFO(m_filterParams.summary());
ATH_MSG_VERBOSE(" =====================================================================");
return StatusCode::SUCCESS;
}
/** check if the given particle passes all filters */
bool ISF::SimEventFilter::passesFilters(HepMC::ConstGenParticlePtr part, ToolHandleArray<IGenParticleFilter>& filters) const
bool ISF::SimEventFilter::passesFilters(HepMC::ConstGenParticlePtr part, const ToolHandleArray<IGenParticleFilter>& filters) const
{
// TODO: implement this as a std::find_if with a lambda function
for ( const auto& filter : filters ) {
......@@ -73,11 +73,12 @@ bool ISF::SimEventFilter::passesFilters(HepMC::ConstGenParticlePtr part, ToolHan
return true;
}
StatusCode ISF::SimEventFilter::execute()
StatusCode ISF::SimEventFilter::execute(const EventContext &ctx) const
{
ATH_MSG_DEBUG ("Executing ...");
SG::ReadHandle<McEventCollection> inputHardScatterEvgen(m_inputHardScatterEvgenKey);
FilterReporter filter(m_filterParams, false, ctx);
SG::ReadHandle<McEventCollection> inputHardScatterEvgen(m_inputHardScatterEvgenKey, ctx);
if (!inputHardScatterEvgen.isValid()) {
ATH_MSG_FATAL("Unable to read input GenEvent collection '" << inputHardScatterEvgen.key() << "'");
return StatusCode::FAILURE;
......@@ -162,13 +163,8 @@ StatusCode ISF::SimEventFilter::execute()
pass =! pass;
}
if (pass) {
++m_pass;
}
++m_total;
setFilterPassed(pass);
filter.setPassed(pass);
return StatusCode::SUCCESS;
}
#endif // SimEventFilter currently will not compile in the AthSimulation Project
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ISF_ALGORITHMS_SIMEVENTFILTER_H
#define ISF_ALGORITHMS_SIMEVENTFILTER_H 1
#ifndef SIMULATIONBASE
// STL includes
#include <string>
// FrameWork includes
#include "StoreGate/ReadHandle.h"
#include "GaudiKernel/ToolHandle.h"
#include "AthenaBaseComps/AthFilterAlgorithm.h"
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
#include <EventBookkeeperTools/FilterReporterParams.h>
// ISF_Interfaces includes
#include "ISF_HepMC_Interfaces/IGenParticleFilter.h"
......@@ -21,7 +24,7 @@
namespace ISF {
class SimEventFilter : public AthFilterAlgorithm {
class SimEventFilter : public AthReentrantAlgorithm {
public:
/** Constructor with parameters */
......@@ -32,13 +35,13 @@ namespace ISF {
/** Athena algorithm's interface method initialize() */
virtual StatusCode initialize() override final; /** Athena algorithm's interface method execute() */
virtual StatusCode execute() override final;
virtual StatusCode execute(const EventContext& ctx) const override final;
/** Athena algorithm's interface method finalize() */
virtual StatusCode finalize() override final;
private:
bool passesFilters(HepMC::ConstGenParticlePtr part, ToolHandleArray<IGenParticleFilter>& filters) const;
bool passesFilters(HepMC::ConstGenParticlePtr part, const ToolHandleArray<IGenParticleFilter>& filters) const;
/** Input truth collections */
SG::ReadHandleKey<McEventCollection> m_inputHardScatterEvgenKey{this, "InputHardScatterCollection", "", "Input Hard Scatter EVGEN collection."}; //!< input hard scatter collection
......@@ -51,11 +54,10 @@ namespace ISF {
ToolHandleArray<IGenParticleFilter> m_genParticleOldFilters{this, "GenParticleOldFilters", {}, "Tools for filtering out GenParticles with the old selection."}; //!< HepMC::GenParticle filters for old selection
ToolHandleArray<IGenParticleFilter> m_genParticleNewFilters{this, "GenParticleNewFilters", {}, "Tools for filtering out GenParticles with the new selection."}; //!< HepMC::GenParticle filters for new selection
FilterReporterParams m_filterParams {this, "ISF_SimEventFilter", "Decides whether particles should be resimulated or simply copied."};
Gaudi::Property<bool> m_invertfilter{this, "InvertFilter", false, "Invert filter decision."}; //!< invert filter decision at the end
int m_pass = 0; //< number of events passing the filter
int m_total = 0 ; //< number of total events seen
};
}
#endif // SimEventFilter currently will not compile in the AthSimulation Project
#endif //> !ISF_ALGORITHMS_SIMEVENTFILTER_H
......@@ -2,12 +2,16 @@
#include "../SimKernelMT.h"
#include "../CollectionMerger.h"
#include "../SimHitTreeCreator.h"
#ifndef SIMULATIONBASE
#include "../SimEventFilter.h"
#endif // SimEventFilter currently will not compile in the AthSimulation Project
#include "../RenameHitCollectionsAlg.h"
DECLARE_COMPONENT( ISF::SimKernel )
DECLARE_COMPONENT( ISF::SimKernelMT )
DECLARE_COMPONENT( ISF::CollectionMerger )
DECLARE_COMPONENT( ISF::SimHitTreeCreator )
#ifndef SIMULATIONBASE
DECLARE_COMPONENT( ISF::SimEventFilter )
#endif // SimEventFilter currently will not compile in the AthSimulation Project
DECLARE_COMPONENT( ISF::RenameHitCollectionsAlg )
......@@ -1664,10 +1664,10 @@ def bind_port(host, port):
def reportEventsPassedSimFilter(log):
# Currently the pattern which contains the information for passed events is for example like:
# ISF_SimEventFilter INFO pass = 0 / 0 = 0%
# ISF_SimEventFilter INFO accepted 1 out of 10 events for filter ISF_SimEventFilter (SimEventFilter)
# In case the filter name truncated by ... due to long timestamps, the pattern could still match
# e.g. ISF_SimEventFi... or ISF_SimEventFil...
regExp = re.compile(r'ISF_SimEventFi[lter|...]+\s.*INFO.*pass\s*=\s*(?P<events>[0-9]*)\s*\/\s*(?P<total>[0-9]*).*')
regExp = re.compile(r'ISF_SimEventFi[lter|...]+\s.*INFO.*accepted\s*(?P<events>[0-9]*)\s*out of\s*(?P<total>[0-9]*).*')
try:
myGen = lineByLine(log)
except IOError as e:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment