Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Functional filter #36

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions k4Gen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gaudi_add_module(k4Gen

target_include_directories(k4Gen PUBLIC ${PYTHIA8_INCLUDE_DIRS}
${HEPMC3_INCLUDE_DIR}
${HEPMC_INCLUDE_DIR}
${HEPMC_INCLUDE_DIR}
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

Expand Down Expand Up @@ -75,10 +75,17 @@ set_tests_properties(Pythia8ExtraSettings PROPERTIES
)
set_test_env(Pythia8ExtraSettings)

add_test(
NAME Pythia8EventsFiltered
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND k4run ${CMAKE_CURRENT_LIST_DIR}/options/pythiaEventsFiltered.py
)
set_test_env(Pythia8EventsFiltered)

add_test(NAME MDIreader
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND k4run ${CMAKE_CURRENT_LIST_DIR}/options/mdireader_test.py
)
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND k4run ${CMAKE_CURRENT_LIST_DIR}/options/mdireader_test.py
)
set_test_env(MDIreader)

#--- Install the example options to the directory where the spack installation
Expand Down
4 changes: 2 additions & 2 deletions k4Gen/options/filterRule.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "edm4hep/MCParticleCollection.h"

bool filterRule(const edm4hep::MCParticleCollection* inColl) {
return inColl->size() > 1000;
bool filterRule(const edm4hep::MCParticleCollection& inColl) {
return inColl->sijze() > 1000;
}
61 changes: 29 additions & 32 deletions k4Gen/options/pythia.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,70 @@
"""
Pythia8, integrated in the FCCSW framework.
'''
Pythia8, integrated in the Key4hep ecosystem.

Generates according to a pythia .cmd file and saves them in fcc edm format.

"""
This example generates events according to a Pythia .cmd file and saves them
into a root file in EDM4hep format.
'''

import os

from GaudiKernel import SystemOfUnits as units
from Gaudi.Configuration import *
from Gaudi.Configuration import INFO

from Configurables import ApplicationMgr, k4DataSvc, PodioOutput
from Configurables import GaussSmearVertex, PythiaInterface, GenAlg
from Configurables import HepMCToEDMConverter, GenParticleFilter

from Configurables import ApplicationMgr
ApplicationMgr().EvtSel = 'NONE'

ApplicationMgr().EvtSel = 'NONE'
ApplicationMgr().EvtMax = 2
ApplicationMgr().OutputLevel = INFO
ApplicationMgr().ExtSvc +=["RndmGenSvc"]
ApplicationMgr().ExtSvc += ["RndmGenSvc"]

#### Data service
from Configurables import k4DataSvc
# Data service
podioevent = k4DataSvc("EventDataSvc")
ApplicationMgr().ExtSvc += [podioevent]

from Configurables import GaussSmearVertex
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
smeartool.xVertexSigma = 0.5 * units.mm
smeartool.yVertexSigma = 0.5 * units.mm
smeartool.zVertexSigma = 40.0 * units.mm
smeartool.tVertexSigma = 180.0 * units.picosecond

from Configurables import PythiaInterface
pythia8gentool = PythiaInterface()
### Example of pythia configuration file to generate events
# take from $K4GEN if defined, locally if not
# Example of a Pythia configuration file to generate events,
# taken from $K4GEN location if defined, locally otherwise
path_to_pythiafile = os.environ.get("K4GEN", "")
pythiafilename = "Pythia_standard.cmd"
pythiafile = os.path.join(path_to_pythiafile, pythiafilename)
# Example of pythia configuration file to read LH event file
#pythiafile="options/Pythia_LHEinput.cmd"
# pythiafile="options/Pythia_LHEinput.cmd"
pythia8gentool.pythiacard = pythiafile
pythia8gentool.doEvtGenDecays = False
pythia8gentool.printPythiaStatistics = True
pythia8gentool.pythiaExtraSettings = [""]

from Configurables import GenAlg
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
from Configurables import HepMCToEDMConverter
# Reads an HepMC::GenEvent from the data service and writes a collection of
# EDM4hep Particles
hepmc_converter = HepMCToEDMConverter()
hepmc_converter.hepmc.Path="hepmc"
hepmc_converter.hepmcStatusList = [] # convert particles with all statuses
hepmc_converter.GenParticles.Path="GenParticles"
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
from Configurables import GenParticleFilter
# Filters generated particles
# User needs to provide 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]

from Configurables import PodioOutput
out = PodioOutput("out")
out.outputCommands = ["keep *"]
ApplicationMgr().TopAlg += [out]


29 changes: 15 additions & 14 deletions k4Gen/options/pythiaEventsFiltered.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'''
Pythia8, integrated in the Key4hep ecosystem.

Generate events according to a Pythia .cmd file and save them in EDM4hep
format.
This example generates events according to a Pythia .cmd file and saves them
into a root file in EDM4hep format.
'''

import os
Expand All @@ -12,12 +12,11 @@

from Configurables import ApplicationMgr, k4DataSvc, PodioOutput
from Configurables import GaussSmearVertex, PythiaInterface, GenAlg
from Configurables import HepMCToEDMConverter, GenParticleFilter
from Configurables import GenEventFilter
from Configurables import HepMCToEDMConverter, GenEventFilter


ApplicationMgr().EvtSel = 'NONE'
ApplicationMgr().EvtMax = 20
ApplicationMgr().EvtMax = 2
ApplicationMgr().OutputLevel = INFO
ApplicationMgr().ExtSvc += ["RndmGenSvc"]

Expand All @@ -32,11 +31,11 @@
smeartool.tVertexSigma = 180.0 * units.picosecond

pythia8gentool = PythiaInterface()
# Example of Pythia configuration file to generate events
# taken from $K4GEN if defined, locally otherwise
# Example of a Pythia configuration file to generate events,
# taken from $K4GEN location 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)
pythiafilename = "Pythia_standard.cmd"
pythiafile = os.path.join(path_to_pythiafile, pythiafilename)
# Example of pythia configuration file to read LH event file
# pythiafile="options/Pythia_LHEinput.cmd"
pythia8gentool.pythiacard = pythiafile
Expand All @@ -51,7 +50,7 @@
ApplicationMgr().TopAlg += [pythia8gen]

# Reads an HepMC::GenEvent from the data service and writes a collection of
# EDM Particles
# EDM4hep Particles
hepmc_converter = HepMCToEDMConverter()
hepmc_converter.hepmc.Path = "hepmc"
hepmc_converter.hepmcStatusList = [] # convert particles with all statuses
Expand All @@ -61,10 +60,12 @@
# Filters events
eventfilter = GenEventFilter("EventFilter")
eventfilter.particles.Path = "GenParticles"
# eventfilter.filterRule = \
# "bool filterRule(const edm4hep::MCParticleCollection* inColl){" \
# " return inColl->size() > 1000;}"
eventfilter.filterRulePath = "k4Gen/options/filterRule.hxx"
# Filter rule can be provided as a string
eventfilter.filterRule = \
"bool filterRule(const edm4hep::MCParticleCollection& inColl){" \
" return inColl->size() > 1000;}"
# Or as hxx/cxx file
eventfilter.filterRulePath = "./k4Gen/options/filterRule.hxx"
eventfilter.OutputLevel = DEBUG
ApplicationMgr().TopAlg += [eventfilter]

Expand Down
Loading
Loading