Warning, /detector_benchmarks/benchmarks/calo_pid/Snakefile is written in an unsupported language. File is not indexed.
0001 def format_energy_for_dd4hep(s):
0002 return s.rstrip("kMGeV") + "*" + s.lstrip("0123456789")
0003
0004 rule calo_pid_sim:
0005 input:
0006 warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
0007 geometry_lib=find_epic_libraries(),
0008 output:
0009 "sim_output/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY_MIN}to{ENERGY_MAX}/{THETA_MIN}to{THETA_MAX}deg/{PARTICLE}_{ENERGY}_{THETA_MIN}to{THETA_MAX}deg.{INDEX}.edm4hep.root",
0010 log:
0011 "sim_output/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY_MIN}to{ENERGY_MAX}/{THETA_MIN}to{THETA_MAX}deg/{PARTICLE}_{ENERGY}_{THETA_MIN}to{THETA_MAX}deg.{INDEX}.edm4hep.root.log",
0012 wildcard_constraints:
0013 PARTICLE="(e-|pi-)",
0014 ENERGY_MIN="[0-9]+[kMG]eV",
0015 ENERGY_MAX="[0-9]+[kMG]eV",
0016 THETA_MIN="[0-9]+",
0017 THETA_MAX="[0-9]+",
0018 INDEX=r"\d{4}",
0019 params:
0020 N_EVENTS=1000,
0021 SEED=lambda wildcards: "1" + wildcards.INDEX,
0022 DETECTOR_PATH=os.environ["DETECTOR_PATH"],
0023 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0024 ENERGY_MIN=lambda wildcards: format_energy_for_dd4hep(wildcards.ENERGY_MIN),
0025 ENERGY_MAX=lambda wildcards: format_energy_for_dd4hep(wildcards.ENERGY_MAX),
0026 DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0027 NPSIM_HASH=get_spack_package_hash("npsim"),
0028 cache: True
0029 shell:
0030 """
0031 set -m # monitor mode to prevent lingering processes
0032 exec ddsim \
0033 --runType batch \
0034 --enableGun \
0035 --gun.momentumMin "{params.ENERGY_MIN}" \
0036 --gun.momentumMax "{params.ENERGY_MAX}" \
0037 --gun.thetaMin "{wildcards.THETA_MIN}*deg" \
0038 --gun.thetaMax "{wildcards.THETA_MAX}*deg" \
0039 --gun.particle {wildcards.PARTICLE} \
0040 --gun.distribution eta \
0041 --random.seed {params.SEED} \
0042 --filter.tracker edep0 \
0043 -v WARNING \
0044 --numberOfEvents {params.N_EVENTS} \
0045 --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}.xml \
0046 --outputFile {output}
0047 """
0048
0049
0050 rule calo_pid_recon:
0051 input:
0052 "sim_output/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0053 output:
0054 "sim_output/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.tree.edm4eic.root",
0055 log:
0056 "sim_output/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.tree.edm4eic.root.log",
0057 wildcard_constraints:
0058 INDEX=r"\d{4}",
0059 shell: """
0060 set -m # monitor mode to prevent lingering processes
0061 exec env DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
0062 eicrecon {input} -Ppodio:output_file={output} \
0063 -Ppodio:output_collections=MCParticles,EcalEndcapNRecHits,EcalEndcapNClusters,EcalEndcapNParticleIDInput_features,EcalEndcapNParticleIDTarget,EcalEndcapNParticleIDOutput_probability_tensor
0064 """
0065
0066
0067 rule calo_pid_input_list:
0068 input:
0069 electrons=expand(
0070 "sim_output/calo_pid/{{DETECTOR_CONFIG}}/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.tree.edm4eic.root",
0071 ENERGY=["100MeVto20GeV"],
0072 PHASE_SPACE=["130to177deg"],
0073 INDEX=range(100),
0074 ),
0075 output:
0076 "listing/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}.lst",
0077 run:
0078 with open(output[0], "wt") as fp:
0079 fp.write("\n".join(input))
0080
0081
0082 rule calo_pid:
0083 input:
0084 electrons="listing/calo_pid/{DETECTOR_CONFIG}/e-.lst",
0085 pions="listing/calo_pid/{DETECTOR_CONFIG}/pi-.lst",
0086 matplotlibrc=".matplotlibrc",
0087 script="benchmarks/calo_pid/calo_pid.py",
0088 output:
0089 directory("results/{DETECTOR_CONFIG}/calo_pid")
0090 shell:
0091 """
0092 env \
0093 MATPLOTLIBRC={input.matplotlibrc} \
0094 DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
0095 PLOT_TITLE={wildcards.DETECTOR_CONFIG} \
0096 INPUT_ELECTRONS="{input.electrons}" \
0097 INPUT_PIONS="{input.pions}" \
0098 OUTPUT_DIR={output} \
0099 python {input.script}
0100 """