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