Skip to content
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/snakemake/snakefmt
rev: v0.10.2
hooks:
- id: snakefmt
37 changes: 26 additions & 11 deletions Snakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
configfile: "snakemake.yml"


include: "benchmarks/backgrounds/Snakefile"
include: "benchmarks/backwards_ecal/Snakefile"
include: "benchmarks/barrel_ecal/Snakefile"
Expand All @@ -19,6 +20,7 @@ include: "benchmarks/femc_electron/Snakefile"
include: "benchmarks/femc_photon/Snakefile"
include: "benchmarks/femc_pi0/Snakefile"


use_s3 = config["remote_provider"].lower() == "s3"
use_xrootd = config["remote_provider"].lower() == "xrootd"

Expand All @@ -29,32 +31,45 @@ def get_remote_path(path):
elif use_xrootd:
return f"root://dtn-eic.jlab.org//work/eic2/{path}"
else:
raise runtime_exception('Unexpected value for config["remote_provider"]: {config["remote_provider"]}')
raise runtime_exception(
'Unexpected value for config["remote_provider"]: {config["remote_provider"]}'
)


rule fetch_epic:
output:
filepath="EPIC/{PATH}"
filepath="EPIC/{PATH}",
params:
# wildcards are not included in hash for caching, we need to add them as params
PATH=lambda wildcards: wildcards.PATH
PATH=lambda wildcards: wildcards.PATH,
cache: True
retries: 3
shell: """
shell:
(
"""
xrdcp --debug 2 root://dtn-eic.jlab.org//work/eic2/{output.filepath} {output.filepath}
""" if use_xrootd else """
"""
if use_xrootd
else (
"""
mc cp S3/eictest/{output.filepath} {output.filepath}
""" if use_s3 else f"""
echo 'Unexpected value for config["remote_provider"]: {config["remote_provider"]}'
exit 1
"""
if use_s3
else f"""
echo 'Unexpected value for config["remote_provider"]: {config["remote_provider"]}'
exit 1
"""
)
)


rule warmup_run:
output:
"warmup/{DETECTOR_CONFIG}.edm4hep.root",
message: "Ensuring that calibrations/fieldmaps are available for {wildcards.DETECTOR_CONFIG}"
shell: """
message:
"Ensuring that calibrations/fieldmaps are available for {wildcards.DETECTOR_CONFIG}"
shell:
"""
set -m # monitor mode to prevent lingering processes
exec ddsim \
--runType batch \
Expand All @@ -80,7 +95,7 @@ rule org2py:
notebook=workflow.basedir + "/{NOTEBOOK}.org",
converter=workflow.source_path("benchmarks/common/org2py.awk"),
output:
"{NOTEBOOK}.py"
"{NOTEBOOK}.py",
shell:
"""
awk -f {input.converter} {input.notebook} > {output}
Expand Down
17 changes: 12 additions & 5 deletions benchmarks/backgrounds/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,24 @@ exec ddsim \
"""


DETECTOR_CONFIG=os.environ["DETECTOR_CONFIG"]
DETECTOR_CONFIG = os.environ["DETECTOR_CONFIG"]


rule backgrounds_ecal_backwards:
input:
matplotlibrc=".matplotlibrc",
script="benchmarks/backgrounds/ecal_backwards.py",
electron_beam_gas_sim="sim_output/" + DETECTOR_CONFIG + "/backgrounds/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/electron/GETaLM1.0.0-1.0/10GeV/GETaLM1.0.0-1.0_ElectronBeamGas_10GeV_foam_emin10keV_run001.edm4hep.root",
physics_signal_sim="sim_output/" + DETECTOR_CONFIG + "/backgrounds/EPIC/EVGEN/DIS/NC/10x100/minQ2=1/pythia8NCDIS_10x100_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.edm4hep.root",
proton_beam_gas_sim="sim_output/" + DETECTOR_CONFIG + "/backgrounds/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/proton/pythia8.306-1.0/100GeV/pythia8.306-1.0_ProtonBeamGas_100GeV_run001.edm4hep.root",
electron_beam_gas_sim="sim_output/"
+ DETECTOR_CONFIG
+ "/backgrounds/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/electron/GETaLM1.0.0-1.0/10GeV/GETaLM1.0.0-1.0_ElectronBeamGas_10GeV_foam_emin10keV_run001.edm4hep.root",
physics_signal_sim="sim_output/"
+ DETECTOR_CONFIG
+ "/backgrounds/EPIC/EVGEN/DIS/NC/10x100/minQ2=1/pythia8NCDIS_10x100_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.edm4hep.root",
proton_beam_gas_sim="sim_output/"
+ DETECTOR_CONFIG
+ "/backgrounds/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/proton/pythia8.306-1.0/100GeV/pythia8.306-1.0_ProtonBeamGas_100GeV_run001.edm4hep.root",
output:
directory("results/backgrounds/backwards_ecal")
directory("results/backgrounds/backwards_ecal"),
threads: workflow.cores
shell:
"""
Expand Down
46 changes: 31 additions & 15 deletions benchmarks/backwards_ecal/Snakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
def get_n_events(wildcards):
energy = float(wildcards.ENERGY.replace("GeV", "").replace("MeV", "e-3"))
n_events = 1000 if wildcards.PARTICLE == "e-" else 2000
n_events = int(n_events // (energy ** 0.5))
n_events = int(n_events // (energy**0.5))
return n_events


rule backwards_ecal_sim:
input:
steering_file=ancient("EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer"),
steering_file=ancient(
"EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer"
),
warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
output:
"sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
Expand All @@ -19,7 +21,7 @@ rule backwards_ecal_sim:
PHASE_SPACE="(3to50|45to135|130to177)deg",
INDEX="\d{4}",
params:
N_EVENTS=get_n_events
N_EVENTS=get_n_events,
shell:
"""
set -m # monitor mode to prevent lingering processes
Expand All @@ -45,7 +47,8 @@ rule backwards_ecal_recon:
"sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.tree.edm4eic.root.log",
wildcard_constraints:
INDEX="\d{4}",
shell: """
shell:
"""
set -m # monitor mode to prevent lingering processes
exec env DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
eicrecon {input} -Ppodio:output_file={output} \
Expand All @@ -60,15 +63,20 @@ rule backwards_ecal_recon_many:
INDEX=range(20),
),
output:
touch("sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/flag"),
touch(
"sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/flag"
),


DETECTOR_CONFIG=os.environ["DETECTOR_CONFIG"]
DETECTOR_CONFIG = os.environ["DETECTOR_CONFIG"]


rule backwards_ecal:
input:
expand(
"sim_output/backwards_ecal/" + DETECTOR_CONFIG + "/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/flag",
"sim_output/backwards_ecal/"
+ DETECTOR_CONFIG
+ "/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/flag",
PARTICLE=["pi-", "e-"],
ENERGY=[
"100MeV",
Expand All @@ -85,14 +93,22 @@ rule backwards_ecal:
matplotlibrc=".matplotlibrc",
script="benchmarks/backwards_ecal/backwards_ecal.py",
output:
directory("results/backwards_ecal")
directory("results/backwards_ecal"),
shell:
"""
(
"""
env \
MATPLOTLIBRC={input.matplotlibrc} \
DETECTOR_CONFIG=""" + DETECTOR_CONFIG + """ \
PLOT_TITLE=""" + DETECTOR_CONFIG + """ \
INPUT_PATH_FORMAT=sim_output/backwards_ecal/""" + DETECTOR_CONFIG + """/{{particle}}/{{energy}}/130to177deg/{{particle}}_{{energy}}_130to177deg.{{ix:04d}}.eicrecon.tree.edm4eic.root \
OUTPUT_DIR={output} \
python {input.script}
"""
DETECTOR_CONFIG="""
+ DETECTOR_CONFIG
+ """ \
PLOT_TITLE="""
+ DETECTOR_CONFIG
+ """ \
INPUT_PATH_FORMAT=sim_output/backwards_ecal/"""
+ DETECTOR_CONFIG
+ """/{{particle}}/{{energy}}/130to177deg/{{particle}}_{{energy}}_130to177deg.{{ix:04d}}.eicrecon.tree.edm4eic.root \
OUTPUT_DIR={output} \
python {input.script}
"""
)
64 changes: 48 additions & 16 deletions benchmarks/barrel_ecal/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rule emcal_barrel_particles_gen:
workflow.source_path("scripts/emcal_barrel_common_functions.h"),
script=workflow.source_path("scripts/emcal_barrel_particles_gen.cxx"),
params:
JUGGLER_N_EVENTS = 100,
JUGGLER_N_EVENTS=100,
output:
"data/emcal_barrel_{PARTICLE}_energies{E_MIN}_{E_MAX}.hepmc",
shell:
Expand All @@ -19,24 +19,28 @@ env \

rule emcal_barrel_particles:
input:
"data/emcal_barrel_{PARTICLE}_energies{E_MIN}_{E_MAX}.hepmc"
"data/emcal_barrel_{PARTICLE}_energies{E_MIN}_{E_MAX}.hepmc",
params:
JUGGLER_N_EVENTS = 100,
JUGGLER_N_EVENTS=100,
output:
"{DETECTOR_CONFIG}/sim_output/sim_emcal_barrel_{PARTICLE}_energies{E_MIN}_{E_MAX}.edm4hep.root"
"{DETECTOR_CONFIG}/sim_output/sim_emcal_barrel_{PARTICLE}_energies{E_MIN}_{E_MAX}.edm4hep.root",
shell:
"""
(
"""
set -m # monitor mode to prevent lingering processes
exec ddsim \
--runType batch \
-v WARNING \
--part.minimalKineticEnergy 0.5*GeV \
--filter.tracker edep0 \
--numberOfEvents {params.JUGGLER_N_EVENTS} \
--compactFile """ + DETECTOR_PATH + """/{wildcards.DETECTOR_CONFIG}.xml \
--inputFiles {input} \
--outputFile {output}
"""
--compactFile """
+ DETECTOR_PATH
+ """/{wildcards.DETECTOR_CONFIG}.xml \
--inputFiles {input} \
--outputFile {output}
"""
)


# This is needed to bridge snakemake rule files to "normal" benchmarks
Expand Down Expand Up @@ -73,7 +77,7 @@ rule emcal_barrel_particles_analysis:
script=workflow.source_path("scripts/emcal_barrel_particles_analysis.cxx"),
sim="{DETECTOR_CONFIG}/sim_output/sim_emcal_barrel_{PARTICLE}.edm4hep.root",
wildcard_constraints:
PARTICLE="(electron|photon|piplus|piminus)", # avoid clash with "pions"
PARTICLE="(electron|photon|piplus|piminus)", # avoid clash with "pions"
output:
"{DETECTOR_CONFIG}/results/emcal_barrel_{PARTICLE}_calibration.json",
"{DETECTOR_CONFIG}/results/emcal_barrel_{PARTICLE}_Ethr.png",
Expand Down Expand Up @@ -123,19 +127,24 @@ rule emcal_barrel_pi0_analysis:
var_name=["Ethr", "nhits", "Esim", "dE_rel"],
extension=["pdf", "png"],
),
"{DETECTOR_CONFIG}/results/Barrel_emcal_pi0.json"
"{DETECTOR_CONFIG}/results/Barrel_emcal_pi0.json",
shell:
"""
cd {wildcards.DETECTOR_CONFIG}
root -l -b -q '{input.script}+("../{input.sim}")'
"""


ENERGY_SCAN_ENERGIES = [0.5, 1., 2., 5., 10.]
ENERGY_SCAN_ENERGIES = [0.5, 1.0, 2.0, 5.0, 10.0]


rule emcal_energy_scan:
input:
# Require all simulations produced for this rule
expand("{{DETECTOR_CONFIG}}/sim_output/energy_scan/{energy}/sim_emcal_barrel_{{PARTICLE}}.edm4hep.root", energy=ENERGY_SCAN_ENERGIES),
expand(
"{{DETECTOR_CONFIG}}/sim_output/energy_scan/{energy}/sim_emcal_barrel_{{PARTICLE}}.edm4hep.root",
energy=ENERGY_SCAN_ENERGIES,
),
output:
"{DETECTOR_CONFIG}/sim_output/emcal_barrel_energy_scan_points_{PARTICLE}.txt",
run:
Expand All @@ -154,7 +163,15 @@ rule emcal_barrel_particles_energy_scan_analysis:
expand(
"{{DETECTOR_CONFIG}}/results/energy_scan/{energy}/emcal_barrel_{{PARTICLE}}_{plot}.png",
energy=ENERGY_SCAN_ENERGIES,
plot=["Esim_layer", "Layer_nodep", "Layer_Esim_mean", "Ethr", "nhits", "Esim", "fsam"],
plot=[
"Esim_layer",
"Layer_nodep",
"Layer_Esim_mean",
"Ethr",
"nhits",
"Esim",
"fsam",
],
),
shell:
"""
Expand All @@ -174,7 +191,16 @@ rule emcal_barrel_pion_rejection_analysis:
"{DETECTOR_CONFIG}/results/Barrel_emcal_pion_rej.json",
expand(
"{{DETECTOR_CONFIG}}/results/emcal_barrel_pion_rej_uncut_comb_{var_save}.png",
var_save=["Esim", "EsimTot", "EDep6", "EDep6OverP", "pT", "eta", "EsimScFi", "EsimScFiOverP"],
var_save=[
"Esim",
"EsimTot",
"EDep6",
"EDep6OverP",
"pT",
"eta",
"EsimScFi",
"EsimScFiOverP",
],
),
expand(
"{{DETECTOR_CONFIG}}/results/emcal_barrel_pion_rej_uncut_comb_E{i}Eta{j}.png",
Expand All @@ -187,7 +213,13 @@ rule emcal_barrel_pion_rejection_analysis:
eta_bin=range(2, 4),
tag=(
["cut_mom_ele", "cut_mom_pim", "cut_ratio_pim"]
+ sum([[f"cut_{var}_ele", f"cut_{var}_pim", f"cut_{var}_comb"] for var in ["pT", "EDep6OverP"]], [])
+ sum(
[
[f"cut_{var}_ele", f"cut_{var}_pim", f"cut_{var}_comb"]
for var in ["pT", "EDep6OverP"]
],
[],
)
),
extension=["pdf", "png"],
),
Expand Down
12 changes: 8 additions & 4 deletions benchmarks/ecal_gaps/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import os

rule ecal_gaps_sim:
input:
steering_file=ancient("EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer"),
steering_file=ancient(
"EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer"
),
warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
output:
"sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
Expand All @@ -15,7 +17,7 @@ rule ecal_gaps_sim:
PHASE_SPACE="(3to50|45to135|130to177)deg",
INDEX="\d{4}",
params:
N_EVENTS=1000
N_EVENTS=1000,
shell:
"""
set -m # monitor mode to prevent lingering processes
Expand All @@ -41,15 +43,17 @@ rule ecal_gaps_recon:
"sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.tree.edm4eic.root.log",
wildcard_constraints:
INDEX="\d{4}",
shell: """
shell:
"""
set -m # monitor mode to prevent lingering processes
exec env DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
eicrecon {input} -Ppodio:output_file={output} \
-Ppodio:output_collections=EcalEndcapNRecHits,EcalBarrelScFiRecHits,EcalBarrelImagingRecHits,EcalEndcapPRecHits,MCParticles
"""


DETECTOR_CONFIG=os.environ["DETECTOR_CONFIG"]
DETECTOR_CONFIG = os.environ["DETECTOR_CONFIG"]


rule ecal_gaps:
input:
Expand Down
Loading