Warning, /detector_benchmarks/benchmarks/ecal_gaps/Snakefile is written in an unsupported language. File is not indexed.
0001 import os
0002
0003
0004 rule ecal_gaps_sim:
0005 input:
0006 warmup="warmup.edm4hep.root",
0007 geometry_lib=find_epic_libraries(),
0008 output:
0009 "sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.rnt.root",
0010 log:
0011 "sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.rnt.root.log",
0012 wildcard_constraints:
0013 PARTICLE="e-",
0014 ENERGY="(500MeV|5GeV|20GeV)",
0015 PHASE_SPACE="(3to50|45to135|130to177)deg",
0016 INDEX=r"\d{4}",
0017 params:
0018 # gun settings of the EPIC/EVGEN/SINGLE steering files; params (unlike wildcards) are part of the cache hash
0019 GUN_PARTICLE=lambda wildcards: wildcards.PARTICLE,
0020 GUN_ENERGY=lambda wildcards: gun_energy(wildcards.ENERGY),
0021 GUN_THETA_MIN=lambda wildcards: gun_theta_range(wildcards.PHASE_SPACE)[0],
0022 GUN_THETA_MAX=lambda wildcards: gun_theta_range(wildcards.PHASE_SPACE)[1],
0023 N_EVENTS=1000,
0024 SEED=lambda wildcards: "1" + wildcards.INDEX,
0025 DETECTOR_PATH=config["DETECTOR_PREFIX"] + "/share/epic",
0026 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0027 DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0028 NPSIM_HASH=get_spack_package_hash("npsim"),
0029 cache: True
0030 singularity: EIC_SINGULARITY_CONTAINER,
0031 shell:
0032 """
0033 set -m # monitor mode to prevent lingering processes
0034 exec npsim \
0035 --runType batch \
0036 --enableGun \
0037 --gun.particle "{params.GUN_PARTICLE}" \
0038 --gun.energy "{params.GUN_ENERGY}" \
0039 --gun.distribution "cos(theta)" \
0040 --gun.thetaMin "{params.GUN_THETA_MIN}*degree" \
0041 --gun.thetaMax "{params.GUN_THETA_MAX}*degree" \
0042 --random.seed {params.SEED} \
0043 --filter.tracker edep0 \
0044 -v WARNING \
0045 --numberOfEvents {params.N_EVENTS} \
0046 --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}.xml \
0047 --outputConfig.useRNTuple true \
0048 --outputFile {output}
0049 """
0050
0051
0052 rule ecal_gaps_recon:
0053 input:
0054 sim="sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.rnt.root",
0055 warmup="warmup.edm4hep.root",
0056 output:
0057 "sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root",
0058 log:
0059 "sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root.log",
0060 wildcard_constraints:
0061 INDEX=r"\d{4}",
0062 params:
0063 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0064 EICRECON_HASH=get_spack_package_hash("eicrecon"),
0065 cache: True
0066 singularity: EIC_SINGULARITY_CONTAINER,
0067 shell: """
0068 set -m # monitor mode to prevent lingering processes
0069 exec env DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
0070 eicrecon {input.sim} -Ppodio:output_file={output} \
0071 -Ppodio:output_collections=EcalEndcapNRecHits,EcalBarrelScFiRecHits,EcalBarrelImagingRecHits,EcalEndcapPRecHits,MCParticles,EcalEndcapNTruthClusters,EcalEndcapNTruthClusterAssociations,EcalBarrelTruthClusters,EcalBarrelTruthClusterAssociations,EcalEndcapPTruthClusters,EcalEndcapPTruthClusterAssociations
0072 """
0073
0074
0075 rule ecal_gaps:
0076 input:
0077 matplotlibrc=".matplotlibrc",
0078 script="benchmarks/ecal_gaps/ecal_gaps.org2py.py",
0079 truth_script=workflow.source_path("truth_clusters.py"),
0080 # TODO pass as a file list?
0081 _=expand(
0082 "sim_output/ecal_gaps/{{DETECTOR_CONFIG}}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.edm4eic.root",
0083 PARTICLE=["e-"],
0084 ENERGY=["500MeV", "5GeV", "20GeV"],
0085 PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0086 INDEX=range(1),
0087 ),
0088 output:
0089 directory("results/{DETECTOR_CONFIG}/ecal_gaps"),
0090 log:
0091 scheduler=".logs/results/{DETECTOR_CONFIG}/ecal_gaps/scheduler.log",
0092 worker=".logs/results/{DETECTOR_CONFIG}/ecal_gaps/worker.log",
0093 threads: workflow.cores
0094 singularity: EIC_SINGULARITY_CONTAINER,
0095 shell:
0096 """
0097 set -m # monitor mode to prevent lingering shells
0098 cleanup() {{
0099 echo Cleaning up
0100 kill $WORKER_PID $SCHEDULER_PID
0101 }}
0102 trap cleanup EXIT
0103
0104 PORT=$RANDOM
0105 dask scheduler --port $PORT 2>{log.scheduler} &
0106 export DASK_SCHEDULER=localhost:$PORT
0107 SCHEDULER_PID=$!
0108 dask worker tcp://$DASK_SCHEDULER --nworkers {threads} --nthreads 1 2>{log.worker} &
0109 WORKER_PID=$!
0110 env \
0111 MATPLOTLIBRC={input.matplotlibrc} \
0112 OUTPUT_DIR={output} \
0113 DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
0114 python {input.script}
0115 python {input.truth_script} --detector-config {wildcards.DETECTOR_CONFIG} --output-dir {output}
0116 """