From a79cb65080da45d6b3d355b59514172c5876c2bf Mon Sep 17 00:00:00 2001 From: Juraj Smiesko Date: Fri, 24 Nov 2023 15:00:19 +0100 Subject: [PATCH 1/6] Event filtering algorithm --- k4Gen/options/pythiaEventsFiltered.py | 77 +++++++++++++++++ k4Gen/src/components/GenEventFilter.cpp | 105 ++++++++++++++++++++++++ k4Gen/src/components/GenEventFilter.h | 60 ++++++++++++++ 3 files changed, 242 insertions(+) create mode 100644 k4Gen/options/pythiaEventsFiltered.py create mode 100644 k4Gen/src/components/GenEventFilter.cpp create mode 100644 k4Gen/src/components/GenEventFilter.h diff --git a/k4Gen/options/pythiaEventsFiltered.py b/k4Gen/options/pythiaEventsFiltered.py new file mode 100644 index 0000000..e95dffb --- /dev/null +++ b/k4Gen/options/pythiaEventsFiltered.py @@ -0,0 +1,77 @@ +''' +Pythia8, integrated in the Key4hep ecosystem. + +Generate events according to a Pythia .cmd file and save them in EDM4hep +format. +''' + +import os + +from GaudiKernel import SystemOfUnits as units +from Gaudi.Configuration import INFO, DEBUG + +from Configurables import ApplicationMgr, k4DataSvc, PodioOutput +from Configurables import GaussSmearVertex, PythiaInterface, GenAlg +from Configurables import HepMCToEDMConverter, GenParticleFilter +from Configurables import GenEventFilter + + +ApplicationMgr().EvtSel = 'NONE' +ApplicationMgr().EvtMax = 20 +ApplicationMgr().OutputLevel = INFO +ApplicationMgr().ExtSvc += ["RndmGenSvc"] + +# Data service +podioevent = k4DataSvc("EventDataSvc") +ApplicationMgr().ExtSvc += [podioevent] + +smeartool = GaussSmearVertex() +smeartool.xVertexSigma = 0.5 * units.mm +smeartool.yVertexSigma = 0.5 * units.mm +smeartool.zVertexSigma = 40.0 * units.mm +smeartool.tVertexSigma = 180.0 * units.picosecond + +pythia8gentool = PythiaInterface() +# Example of Pythia configuration file to generate events +# taken from $K4GEN if defined, locally otherwise +path_to_pythiafile = os.environ.get("K4GEN", "") +PYTHIA_FILENAME = "Pythia_standard.cmd" +pythiafile = os.path.join(path_to_pythiafile, PYTHIA_FILENAME) +# Example of pythia configuration file to read LH event file +# pythiafile="options/Pythia_LHEinput.cmd" +pythia8gentool.pythiacard = pythiafile +pythia8gentool.doEvtGenDecays = False +pythia8gentool.printPythiaStatistics = True +pythia8gentool.pythiaExtraSettings = [""] + +pythia8gen = GenAlg("Pythia8") +pythia8gen.SignalProvider = pythia8gentool +pythia8gen.VertexSmearingTool = smeartool +pythia8gen.hepmc.Path = "hepmc" +ApplicationMgr().TopAlg += [pythia8gen] + +# Reads an HepMC::GenEvent from the data service and writes a collection of +# EDM Particles +hepmc_converter = HepMCToEDMConverter() +hepmc_converter.hepmc.Path = "hepmc" +hepmc_converter.hepmcStatusList = [] # convert particles with all statuses +hepmc_converter.GenParticles.Path = "GenParticles" +ApplicationMgr().TopAlg += [hepmc_converter] + +# Filters generated particles +# accept is a list of particle statuses that should be accepted +genfilter = GenParticleFilter("StableParticles") +genfilter.accept = [1] +genfilter.GenParticles.Path = "GenParticles" +genfilter.GenParticlesFiltered.Path = "GenParticlesStable" +ApplicationMgr().TopAlg += [genfilter] + +# Filters events +eventfilter = GenEventFilter("EventFilter") +eventfilter.particles.Path = "GenParticlesStable" +eventfilter.OutputLevel = DEBUG +ApplicationMgr().TopAlg += [eventfilter] + +out = PodioOutput("out") +out.outputCommands = ["keep *"] +ApplicationMgr().TopAlg += [out] diff --git a/k4Gen/src/components/GenEventFilter.cpp b/k4Gen/src/components/GenEventFilter.cpp new file mode 100644 index 0000000..4bb5fdc --- /dev/null +++ b/k4Gen/src/components/GenEventFilter.cpp @@ -0,0 +1,105 @@ +#include "GenEventFilter.h" + +// Gaudi +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/StatusCode.h" +#include "GaudiKernel/ISvcLocator.h" +#include "GaudiKernel/IEventProcessor.h" +#include "GaudiKernel/Incident.h" + +// Datamodel +#include "edm4hep/MCParticleCollection.h" + +DECLARE_COMPONENT(GenEventFilter) + +GenEventFilter::GenEventFilter( + const std::string& name, + ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) { + declareProperty("particles", m_inColl, + "Generated particles to decide on (input)"); +} + +StatusCode GenEventFilter::initialize() { + { + StatusCode sc = GaudiAlgorithm::initialize(); + if (sc.isFailure()) { + return sc; + } + } + + m_property = service("ApplicationMgr", m_property); + Gaudi::Property evtMax; + evtMax.assign(m_property->getProperty("EvtMax")); + m_nEventsTarget = evtMax; + debug() << "Targeted number of events: " << m_nEventsTarget << endmsg; + m_nEventsAccepted = 0; + m_nEventsSeen = 0; + + m_incidentSvc = service("IncidentSvc"); + + m_eventProcessor = service("ApplicationMgr"); + + return StatusCode::SUCCESS; +} + +StatusCode GenEventFilter::execute() { + const edm4hep::MCParticleCollection* inParticles = m_inColl.get(); + m_nEventsSeen++; + bool accept = true; + /* + int cntr = 0; + for (auto ptc : (*inParticles)) { + accept = false; + for (auto status : m_accept) { + if (ptc.getGeneratorStatus() == status) { + accept = true; + } + } + if (accept) { + } + cntr++; + } + */ + + + Gaudi::Property go; + go.assign(m_property->getProperty("Go")); + debug() << "Go: " << go << endmsg; + + if (inParticles->size() < 1000) { + accept = false; + } + + if (!accept) { + debug() << "Skipping event..." << endmsg; + + { + StatusCode sc = m_eventProcessor->nextEvent(1); + if (sc.isFailure()) { + error() << "Error when attempting to skip the event! Aborting..." + << endmsg; + return sc; + } + } + + m_incidentSvc->fireIncident(Incident(name(), IncidentType::AbortEvent)); + + return StatusCode::SUCCESS; + } + + m_nEventsAccepted++; + + debug() << "Event contains " << inParticles->size() << " particles." + << endmsg; + debug() << "Targeted number of events to generate: " << m_nEventsTarget + << endmsg; + debug() << "Number of events already generated: " << m_nEventsAccepted + << endmsg; + debug() << "Remaining number of event to generate: " + << m_nEventsTarget - m_nEventsAccepted << endmsg; + debug() << "Number of events seen: " << m_nEventsSeen << endmsg; + + return StatusCode::SUCCESS; +} + +StatusCode GenEventFilter::finalize() { return GaudiAlgorithm::finalize(); } diff --git a/k4Gen/src/components/GenEventFilter.h b/k4Gen/src/components/GenEventFilter.h new file mode 100644 index 0000000..ea48fe7 --- /dev/null +++ b/k4Gen/src/components/GenEventFilter.h @@ -0,0 +1,60 @@ +#ifndef GENERATION_GENEVENTFILTER_H +#define GENERATION_GENEVENTFILTER_H + +// Gaudi +#include "GaudiAlg/GaudiAlgorithm.h" +class IProperty; +class IIncidentSvc; +class IEventProcessor; + +// k4FWCore +#include "k4FWCore/DataHandle.h" + +// Datamodel +namespace edm4hep { + class MCParticleCollection; +} + +/** @class GenEventFilter Generation/src/components/GenEventFilter.h GenEventFilter.h + * + * Skips events if MCParticle collection does not contain desired particles. + * + * @author J. Smiesko +*/ + +class GenEventFilter : public GaudiAlgorithm { + +public: + /// Constructor + GenEventFilter(const std::string& name, ISvcLocator* svcLoc); + /// Initialize + virtual StatusCode initialize(); + /// Execute: Applies the filter + virtual StatusCode execute(); + /// Finalize + virtual StatusCode finalize(); + +private: + /// Handle for the MCParticle collection to be read + DataHandle m_inColl{ + "particles", Gaudi::DataHandle::Reader, this}; + + /// Rules to accept an event. + Gaudi::Property> m_rules{ + this, "rules", {"e-"}, "Rules to accept an event"}; + + /// Targeted number of events. + size_t m_nEventsTarget; + /// Keep track of how many events were already accepted. + size_t m_nEventsAccepted; + /// Keep track of how many events we went through. + size_t m_nEventsSeen; + /// Pointer to the property. + SmartIF m_property; + /// Pointer to the incident service. + SmartIF m_incidentSvc; + /// Pointer to the event processor. + SmartIF m_eventProcessor; +}; + +#endif // GENERATION_GENEVENTFILTER_H From be4eff6e59c85bae45c08c10c4efab6e8942b86f Mon Sep 17 00:00:00 2001 From: Juraj Smiesko Date: Tue, 28 Nov 2023 19:10:48 +0100 Subject: [PATCH 2/6] Loading filter rule dynamically --- k4Gen/src/components/GenEventFilter.cpp | 51 +++++++++++++++++++------ k4Gen/src/components/GenEventFilter.h | 2 + 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/k4Gen/src/components/GenEventFilter.cpp b/k4Gen/src/components/GenEventFilter.cpp index 4bb5fdc..7bea6d8 100644 --- a/k4Gen/src/components/GenEventFilter.cpp +++ b/k4Gen/src/components/GenEventFilter.cpp @@ -10,6 +10,9 @@ // Datamodel #include "edm4hep/MCParticleCollection.h" +// ROOT +#include "TInterpreter.h" + DECLARE_COMPONENT(GenEventFilter) GenEventFilter::GenEventFilter( @@ -39,13 +42,41 @@ StatusCode GenEventFilter::initialize() { m_eventProcessor = service("ApplicationMgr"); + { + bool success = gInterpreter->Declare("#include \"edm4hep/MCParticleCollection.h\""); + if (!success) { + error() << "Unable to find edm4hep::MCParticleCollection header file!" << endmsg; + return StatusCode::FAILURE; + } + debug() << "Found edm4hep::MCParticleCollection header file." << endmsg; + } + + { + bool success = gInterpreter->Declare("bool filterRule(const edm4hep::MCParticleCollection& inColl){return inColl.size() > 1000;}"); + if (!success) { + error() << "Unable to compile filter rule!" << endmsg; + return StatusCode::FAILURE; + } + debug() << "Filter rule compiled successfully." << endmsg; + } + + { + enum TInterpreter::EErrorCode err = TInterpreter::kProcessing; + m_filterRulePtr = (bool (*)(const edm4hep::MCParticleCollection*)) gInterpreter->ProcessLineSynch("&filterRule", &err); + if (err != TInterpreter::kNoError) { + error() << "Unable to obtain filter rule pointer!" << endmsg; + return StatusCode::FAILURE; + } + debug() << "Filter rule pointer obtained successfully." << endmsg; + } + return StatusCode::SUCCESS; } StatusCode GenEventFilter::execute() { const edm4hep::MCParticleCollection* inParticles = m_inColl.get(); m_nEventsSeen++; - bool accept = true; + /* int cntr = 0; for (auto ptc : (*inParticles)) { @@ -62,15 +93,7 @@ StatusCode GenEventFilter::execute() { */ - Gaudi::Property go; - go.assign(m_property->getProperty("Go")); - debug() << "Go: " << go << endmsg; - - if (inParticles->size() < 1000) { - accept = false; - } - - if (!accept) { + if (!(*m_filterRulePtr)(inParticles)) { debug() << "Skipping event..." << endmsg; { @@ -97,9 +120,13 @@ StatusCode GenEventFilter::execute() { << endmsg; debug() << "Remaining number of event to generate: " << m_nEventsTarget - m_nEventsAccepted << endmsg; - debug() << "Number of events seen: " << m_nEventsSeen << endmsg; + debug() << "Number of events seen so far: " << m_nEventsSeen << endmsg; return StatusCode::SUCCESS; } -StatusCode GenEventFilter::finalize() { return GaudiAlgorithm::finalize(); } +StatusCode GenEventFilter::finalize() { + debug() << "Number of events seen: " << m_nEventsSeen << endmsg; + + return GaudiAlgorithm::finalize(); +} diff --git a/k4Gen/src/components/GenEventFilter.h b/k4Gen/src/components/GenEventFilter.h index ea48fe7..cb1af65 100644 --- a/k4Gen/src/components/GenEventFilter.h +++ b/k4Gen/src/components/GenEventFilter.h @@ -55,6 +55,8 @@ class GenEventFilter : public GaudiAlgorithm { SmartIF m_incidentSvc; /// Pointer to the event processor. SmartIF m_eventProcessor; + /// Filter rule pointer. + bool (*m_filterRulePtr)(const edm4hep::MCParticleCollection*); }; #endif // GENERATION_GENEVENTFILTER_H From 4d6832f5614813fc33b8aaba708086c1d4545927 Mon Sep 17 00:00:00 2001 From: Juraj Smiesko Date: Wed, 29 Nov 2023 13:15:05 +0100 Subject: [PATCH 3/6] Loading filter rule from file or from a string --- k4Gen/options/filterRule.hxx | 5 ++ k4Gen/options/pythiaEventsFiltered.py | 4 + k4Gen/src/components/GenEventFilter.cpp | 108 ++++++++++++++++++------ k4Gen/src/components/GenEventFilter.h | 13 ++- 4 files changed, 98 insertions(+), 32 deletions(-) create mode 100644 k4Gen/options/filterRule.hxx diff --git a/k4Gen/options/filterRule.hxx b/k4Gen/options/filterRule.hxx new file mode 100644 index 0000000..01694d8 --- /dev/null +++ b/k4Gen/options/filterRule.hxx @@ -0,0 +1,5 @@ +#include "edm4hep/MCParticleCollection.h" + +bool filterRule(const edm4hep::MCParticleCollection* inColl) { + return inColl->size() > 1000; +} diff --git a/k4Gen/options/pythiaEventsFiltered.py b/k4Gen/options/pythiaEventsFiltered.py index e95dffb..18af75e 100644 --- a/k4Gen/options/pythiaEventsFiltered.py +++ b/k4Gen/options/pythiaEventsFiltered.py @@ -69,6 +69,10 @@ # Filters events eventfilter = GenEventFilter("EventFilter") eventfilter.particles.Path = "GenParticlesStable" +# eventfilter.filterRule = \ +# "bool filterRule(const edm4hep::MCParticleCollection* inColl){" \ +# " return inColl->size() > 1000;}" +eventfilter.filterRulePath = "k4Gen/options/filterRule.hxx" eventfilter.OutputLevel = DEBUG ApplicationMgr().TopAlg += [eventfilter] diff --git a/k4Gen/src/components/GenEventFilter.cpp b/k4Gen/src/components/GenEventFilter.cpp index 7bea6d8..0458f56 100644 --- a/k4Gen/src/components/GenEventFilter.cpp +++ b/k4Gen/src/components/GenEventFilter.cpp @@ -11,7 +11,10 @@ #include "edm4hep/MCParticleCollection.h" // ROOT +#include "TROOT.h" +#include "TSystem.h" #include "TInterpreter.h" +#include "TGlobal.h" DECLARE_COMPONENT(GenEventFilter) @@ -42,27 +45,67 @@ StatusCode GenEventFilter::initialize() { m_eventProcessor = service("ApplicationMgr"); - { - bool success = gInterpreter->Declare("#include \"edm4hep/MCParticleCollection.h\""); - if (!success) { - error() << "Unable to find edm4hep::MCParticleCollection header file!" << endmsg; - return StatusCode::FAILURE; + if (m_filterRuleStr.value().empty() && m_filterRulePath.value().empty()) { + error() << "Filter rule not found!" << endmsg; + error() << "Provide it as a string or in the cxx file." << endmsg; + return StatusCode::FAILURE; + } + + if (!m_filterRuleStr.value().empty() && !m_filterRulePath.value().empty()) { + error() << "Multiple ilter rules found!" << endmsg; + error() << "Provide either a string or the cxx file." << endmsg; + return StatusCode::FAILURE; + } + + if (!m_filterRuleStr.value().empty()) { + // Include(s) needed + { + bool success = gInterpreter->Declare( + "#include \"edm4hep/MCParticleCollection.h\""); + if (!success) { + error() << "Unable to find edm4hep::MCParticleCollection header file!" + << endmsg; + return StatusCode::FAILURE; + } + debug() << "Found edm4hep::MCParticleCollection header file." << endmsg; + } + + // Filter rule provided directly as a string + { + bool success = gInterpreter->Declare(m_filterRuleStr.value().c_str()); + if (!success) { + error() << "Unable to compile filter rule!" << endmsg; + return StatusCode::FAILURE; + } + debug() << "Filter rule compiled successfully." << endmsg; } - debug() << "Found edm4hep::MCParticleCollection header file." << endmsg; } - { - bool success = gInterpreter->Declare("bool filterRule(const edm4hep::MCParticleCollection& inColl){return inColl.size() > 1000;}"); - if (!success) { - error() << "Unable to compile filter rule!" << endmsg; + if (!m_filterRulePath.value().empty()) { + if (gSystem->AccessPathName(m_filterRulePath.value().c_str())) { + error() << "Unable to access filter rule file!" << endmsg; + error() << "Provided filter rule file path: " << m_filterRulePath.value() << endmsg; return StatusCode::FAILURE; } - debug() << "Filter rule compiled successfully." << endmsg; + // Include and compile the file + { + bool success = gInterpreter->Declare( + ("#include \"" + m_filterRulePath + "\"").c_str()); + if (!success) { + error() << "Unable to include filter rule file!" + << endmsg; + return StatusCode::FAILURE; + } + debug() << "Included filter rule file." << endmsg; + } } + // Get the address of the compiled filter rule from the interpreter { enum TInterpreter::EErrorCode err = TInterpreter::kProcessing; - m_filterRulePtr = (bool (*)(const edm4hep::MCParticleCollection*)) gInterpreter->ProcessLineSynch("&filterRule", &err); + m_filterRulePtr = + reinterpret_cast( + gInterpreter->ProcessLineSynch("&filterRule", &err)); if (err != TInterpreter::kNoError) { error() << "Unable to obtain filter rule pointer!" << endmsg; return StatusCode::FAILURE; @@ -70,6 +113,31 @@ StatusCode GenEventFilter::initialize() { debug() << "Filter rule pointer obtained successfully." << endmsg; } + // Check if the filter rule pointer has correct signature + { + auto success = gInterpreter->Declare("auto filterRulePtr = &filterRule;"); + if (!success) { + error() << "Unable to declare filter rule pointer in the interpreter!" + << endmsg; + return StatusCode::FAILURE; + } + auto global = gROOT->GetGlobal("filterRulePtr"); + if (!global) { + error() << "Unable to obtain filter rule pointer from the interpreter!" + << endmsg; + return StatusCode::FAILURE; + } + std::string filterRuleType = global->GetTypeName(); + if (filterRuleType != "bool(*)(const edm4hep::MCParticleCollection*)") { + error() << "Found filter rule pointer has wrong signature!" << endmsg; + error() << "Required: bool(*)(const edm4hep::MCParticleCollection*)" + << endmsg; + error() << "Found: " << filterRuleType << endmsg; + return StatusCode::FAILURE; + } + debug() << "Found filter rule pointer has correct signature." << endmsg; + } + return StatusCode::SUCCESS; } @@ -77,22 +145,6 @@ StatusCode GenEventFilter::execute() { const edm4hep::MCParticleCollection* inParticles = m_inColl.get(); m_nEventsSeen++; - /* - int cntr = 0; - for (auto ptc : (*inParticles)) { - accept = false; - for (auto status : m_accept) { - if (ptc.getGeneratorStatus() == status) { - accept = true; - } - } - if (accept) { - } - cntr++; - } - */ - - if (!(*m_filterRulePtr)(inParticles)) { debug() << "Skipping event..." << endmsg; diff --git a/k4Gen/src/components/GenEventFilter.h b/k4Gen/src/components/GenEventFilter.h index cb1af65..a1a4719 100644 --- a/k4Gen/src/components/GenEventFilter.h +++ b/k4Gen/src/components/GenEventFilter.h @@ -17,7 +17,8 @@ namespace edm4hep { /** @class GenEventFilter Generation/src/components/GenEventFilter.h GenEventFilter.h * - * Skips events if MCParticle collection does not contain desired particles. + * Filters events based on the user defined filter rule applied on MCParticle + * collection. * * @author J. Smiesko */ @@ -39,9 +40,13 @@ class GenEventFilter : public GaudiAlgorithm { DataHandle m_inColl{ "particles", Gaudi::DataHandle::Reader, this}; - /// Rules to accept an event. - Gaudi::Property> m_rules{ - this, "rules", {"e-"}, "Rules to accept an event"}; + /// Rule to filter the events with + Gaudi::Property m_filterRuleStr{ + this, "filterRule", "", "Filter rule to apply on the events"}; + + /// Path of the filter rule file + Gaudi::Property m_filterRulePath{ + this, "filterRulePath", "", "Path to the filter rule file"}; /// Targeted number of events. size_t m_nEventsTarget; From ba03ab55106b31f49c3999301a627a9cd6674058 Mon Sep 17 00:00:00 2001 From: Juraj Smiesko Date: Fri, 16 Feb 2024 13:22:55 +0100 Subject: [PATCH 4/6] Removing filter for stable particles --- k4Gen/options/pythiaEventsFiltered.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/k4Gen/options/pythiaEventsFiltered.py b/k4Gen/options/pythiaEventsFiltered.py index 18af75e..5bc6c45 100644 --- a/k4Gen/options/pythiaEventsFiltered.py +++ b/k4Gen/options/pythiaEventsFiltered.py @@ -58,17 +58,9 @@ hepmc_converter.GenParticles.Path = "GenParticles" ApplicationMgr().TopAlg += [hepmc_converter] -# Filters generated particles -# accept is a list of particle statuses that should be accepted -genfilter = GenParticleFilter("StableParticles") -genfilter.accept = [1] -genfilter.GenParticles.Path = "GenParticles" -genfilter.GenParticlesFiltered.Path = "GenParticlesStable" -ApplicationMgr().TopAlg += [genfilter] - # Filters events eventfilter = GenEventFilter("EventFilter") -eventfilter.particles.Path = "GenParticlesStable" +eventfilter.particles.Path = "GenParticles" # eventfilter.filterRule = \ # "bool filterRule(const edm4hep::MCParticleCollection* inColl){" \ # " return inColl->size() > 1000;}" From 0854134b60ee05b4430c842bccf45e4592f0d591 Mon Sep 17 00:00:00 2001 From: Juraj Smiesko Date: Tue, 20 Feb 2024 15:37:45 +0100 Subject: [PATCH 5/6] Adding endpoint vertex of MCParticle --- k4Gen/src/components/HepMCToEDMConverter.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/k4Gen/src/components/HepMCToEDMConverter.cpp b/k4Gen/src/components/HepMCToEDMConverter.cpp index 9b8148c..dbd4e52 100644 --- a/k4Gen/src/components/HepMCToEDMConverter.cpp +++ b/k4Gen/src/components/HepMCToEDMConverter.cpp @@ -33,6 +33,12 @@ edm4hep::MutableMCParticle HepMCToEDMConverter::convert(std::shared_ptrend_vertex(); + if ( endVtx != nullptr ) { + auto& pos = endVtx->position(); + edm_particle.setEndpoint( {pos.x(), pos.y(), pos.z()} ); + } + return edm_particle; } From f7b7a0e6cf86863ddb8c22595b1946c5f1687630 Mon Sep 17 00:00:00 2001 From: Juraj Smiesko Date: Thu, 22 Feb 2024 13:37:56 +0100 Subject: [PATCH 6/6] Converting to Gaudi::Algorithm --- k4Gen/src/components/GenEventFilter.cpp | 11 ++++++----- k4Gen/src/components/GenEventFilter.h | 14 +++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/k4Gen/src/components/GenEventFilter.cpp b/k4Gen/src/components/GenEventFilter.cpp index 0458f56..c0ddc70 100644 --- a/k4Gen/src/components/GenEventFilter.cpp +++ b/k4Gen/src/components/GenEventFilter.cpp @@ -16,18 +16,17 @@ #include "TInterpreter.h" #include "TGlobal.h" -DECLARE_COMPONENT(GenEventFilter) GenEventFilter::GenEventFilter( const std::string& name, - ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) { + ISvcLocator* svcLoc) : Gaudi::Algorithm(name, svcLoc) { declareProperty("particles", m_inColl, "Generated particles to decide on (input)"); } StatusCode GenEventFilter::initialize() { { - StatusCode sc = GaudiAlgorithm::initialize(); + StatusCode sc = Gaudi::Algorithm::initialize(); if (sc.isFailure()) { return sc; } @@ -141,7 +140,7 @@ StatusCode GenEventFilter::initialize() { return StatusCode::SUCCESS; } -StatusCode GenEventFilter::execute() { +StatusCode GenEventFilter::execute(const EventContext& evtCtx) const { const edm4hep::MCParticleCollection* inParticles = m_inColl.get(); m_nEventsSeen++; @@ -180,5 +179,7 @@ StatusCode GenEventFilter::execute() { StatusCode GenEventFilter::finalize() { debug() << "Number of events seen: " << m_nEventsSeen << endmsg; - return GaudiAlgorithm::finalize(); + return Gaudi::Algorithm::finalize(); } + +DECLARE_COMPONENT(GenEventFilter) diff --git a/k4Gen/src/components/GenEventFilter.h b/k4Gen/src/components/GenEventFilter.h index a1a4719..7db6e34 100644 --- a/k4Gen/src/components/GenEventFilter.h +++ b/k4Gen/src/components/GenEventFilter.h @@ -2,7 +2,7 @@ #define GENERATION_GENEVENTFILTER_H // Gaudi -#include "GaudiAlg/GaudiAlgorithm.h" +#include "GaudiKernel/Algorithm.h" class IProperty; class IIncidentSvc; class IEventProcessor; @@ -23,7 +23,7 @@ namespace edm4hep { * @author J. Smiesko */ -class GenEventFilter : public GaudiAlgorithm { +class GenEventFilter : public Gaudi::Algorithm { public: /// Constructor @@ -31,13 +31,13 @@ class GenEventFilter : public GaudiAlgorithm { /// Initialize virtual StatusCode initialize(); /// Execute: Applies the filter - virtual StatusCode execute(); + virtual StatusCode execute(const EventContext& evtCtx) const; /// Finalize virtual StatusCode finalize(); private: /// Handle for the MCParticle collection to be read - DataHandle m_inColl{ + mutable DataHandle m_inColl{ "particles", Gaudi::DataHandle::Reader, this}; /// Rule to filter the events with @@ -49,11 +49,11 @@ class GenEventFilter : public GaudiAlgorithm { this, "filterRulePath", "", "Path to the filter rule file"}; /// Targeted number of events. - size_t m_nEventsTarget; + mutable std::atomic m_nEventsTarget; /// Keep track of how many events were already accepted. - size_t m_nEventsAccepted; + mutable std::atomic m_nEventsAccepted; /// Keep track of how many events we went through. - size_t m_nEventsSeen; + mutable std::atomic m_nEventsSeen; /// Pointer to the property. SmartIF m_property; /// Pointer to the incident service.