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