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=ancient("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 THETA_MIN=lambda wildcards: wildcards.THETA_MIN,
0027 THETA_MAX=lambda wildcards: wildcards.THETA_MAX,
0028 DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0029 NPSIM_HASH=get_spack_package_hash("npsim"),
0030 cache: True
0031 shell:
0032 """
0033 set -m # monitor mode to prevent lingering processes
0034 exec ddsim \
0035 --runType batch \
0036 --enableGun \
0037 --gun.momentumMin "{params.ENERGY_MIN}" \
0038 --gun.momentumMax "{params.ENERGY_MAX}" \
0039 --gun.thetaMin "{wildcards.THETA_MIN}*deg" \
0040 --gun.thetaMax "{wildcards.THETA_MAX}*deg" \
0041 --gun.particle {wildcards.PARTICLE} \
0042 --gun.distribution eta \
0043 --random.seed {params.SEED} \
0044 --filter.tracker edep0 \
0045 -v WARNING \
0046 --numberOfEvents {params.N_EVENTS} \
0047 --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}.xml \
0048 --outputFile {output}
0049 """
0050
0051
0052 rule calo_pid_recon:
0053 input:
0054 sim="sim_output/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0055 warmup=ancient("warmup/{DETECTOR_CONFIG}.edm4hep.root"),
0056 output:
0057 "sim_output/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root",
0058 log:
0059 "sim_output/calo_pid/{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 shell: """
0067 DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
0068 exec eicrecon {input.sim} -Ppodio:output_file={output} \
0069 -Ppodio:output_collections=MCParticles,EcalEndcapNRecHits,EcalEndcapNClusters,EcalEndcapNParticleIDInput_features,EcalEndcapNParticleIDTarget,EcalEndcapNParticleIDOutput_probability_tensor
0070 """
0071
0072
0073 rule calo_pid_input_list:
0074 input:
0075 electrons=expand(
0076 "sim_output/calo_pid/{{DETECTOR_CONFIG}}/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.edm4eic.root",
0077 ENERGY=["100MeVto20GeV"],
0078 PHASE_SPACE=["130to177deg"],
0079 INDEX=range(100),
0080 ),
0081 output:
0082 "listing/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}.lst",
0083 run:
0084 with open(output[0], "wt") as fp:
0085 fp.write("\n".join(input))
0086
0087
0088 rule calo_pid:
0089 input:
0090 electrons="listing/calo_pid/{DETECTOR_CONFIG}/e-.lst",
0091 pions="listing/calo_pid/{DETECTOR_CONFIG}/pi-.lst",
0092 matplotlibrc=".matplotlibrc",
0093 script="benchmarks/calo_pid/calo_pid.py",
0094 output:
0095 directory("results/{DETECTOR_CONFIG}/calo_pid")
0096 shell:
0097 """
0098 env \
0099 MATPLOTLIBRC={input.matplotlibrc} \
0100 DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
0101 PLOT_TITLE={wildcards.DETECTOR_CONFIG} \
0102 INPUT_ELECTRONS="{input.electrons}" \
0103 INPUT_PIONS="{input.pions}" \
0104 OUTPUT_DIR={output} \
0105 python {input.script}
0106 """