Back to home page

EIC code displayed by LXR

 
 

    


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         steering_file="EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer",
0007         warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
0008         geometry_lib=find_epic_libraries(),
0009     output:
0010         "sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0011     log:
0012         "sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root.log",
0013     wildcard_constraints:
0014         PARTICLE="e-",
0015         ENERGY="(500MeV|5GeV|20GeV)",
0016         PHASE_SPACE="(3to50|45to135|130to177)deg",
0017         INDEX=r"\d{4}",
0018     params:
0019         N_EVENTS=1000,
0020         SEED=lambda wildcards: "1" + wildcards.INDEX,
0021         DETECTOR_PATH=os.environ["DETECTOR_PATH"],
0022         DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0023         DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0024         NPSIM_HASH=get_spack_package_hash("npsim"),
0025     cache: True
0026     shell:
0027         """
0028 set -m # monitor mode to prevent lingering processes
0029 exec ddsim \
0030   --runType batch \
0031   --enableGun \
0032   --steeringFile "{input.steering_file}" \
0033   --random.seed {params.SEED} \
0034   --filter.tracker edep0 \
0035   -v WARNING \
0036   --numberOfEvents {params.N_EVENTS} \
0037   --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}.xml \
0038   --outputFile {output}
0039 """
0040 
0041 
0042 rule ecal_gaps_recon:
0043     input:
0044         "sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0045     output:
0046         "sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.tree.edm4eic.root",
0047     log:
0048         "sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.tree.edm4eic.root.log",
0049     wildcard_constraints:
0050         INDEX=r"\d{4}",
0051     params:
0052         DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0053         EICRECON_HASH=get_spack_package_hash("eicrecon"),
0054     cache: True
0055     shell: """
0056 set -m # monitor mode to prevent lingering processes
0057 exec env DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
0058   eicrecon {input} -Ppodio:output_file={output} \
0059   -Ppodio:output_collections=EcalEndcapNRecHits,EcalBarrelScFiRecHits,EcalBarrelImagingRecHits,EcalEndcapPRecHits,MCParticles
0060 """
0061 
0062 
0063 rule ecal_gaps:
0064     input:
0065         matplotlibrc=".matplotlibrc",
0066         script="benchmarks/ecal_gaps/ecal_gaps.py",
0067         # TODO pass as a file list?
0068         _=expand(
0069             "sim_output/ecal_gaps/{{DETECTOR_CONFIG}}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.tree.edm4eic.root",
0070             PARTICLE=["e-"],
0071             ENERGY=["500MeV", "5GeV", "20GeV"],
0072             PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0073             INDEX=range(1),
0074         ),
0075     output:
0076         directory("results/{DETECTOR_CONFIG}/ecal_gaps"),
0077     log:
0078         scheduler=".logs/results/{DETECTOR_CONFIG}/ecal_gaps/scheduler.log",
0079         worker=".logs/results/{DETECTOR_CONFIG}/ecal_gaps/worker.log",
0080     threads: workflow.cores
0081     shell:
0082         """
0083 set -m # monitor mode to prevent lingering shells
0084 cleanup() {{
0085   echo Cleaning up
0086   kill $WORKER_PID $SCHEDULER_PID
0087 }}
0088 trap cleanup EXIT
0089 
0090 PORT=$RANDOM
0091 dask scheduler --port $PORT 2>{log.scheduler} &
0092 export DASK_SCHEDULER=localhost:$PORT
0093 SCHEDULER_PID=$!
0094 dask worker tcp://$DASK_SCHEDULER --nworkers {threads} --nthreads 1 2>{log.worker} &
0095 WORKER_PID=$!
0096 env \
0097 MATPLOTLIBRC={input.matplotlibrc} \
0098 OUTPUT_DIR={output} \
0099 DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
0100 python {input.script}
0101 """