Back to home page

EIC code displayed by LXR

 
 

    


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