Back to home page

EIC code displayed by LXR

 
 

    


Warning, /detector_benchmarks/benchmarks/nhcal_sampling_fraction/Snakefile is written in an unsupported language. File is not indexed.

0001 def get_total_energy(particle, kinetic_energy):
0002     """Convert kinetic energy to total energy by adding particle mass."""
0003     masses = {
0004         "neutron": 0.94, 
0005         "pi-": 0.14,      
0006         "e-": 0.0005      
0007     }
0008     ke = float(kinetic_energy)
0009     mass = masses[particle]
0010     return f"{ke + mass:.2f}"
0011 
0012 rule nhcal_sampling_fraction_simulate:
0013     output:
0014         "sim_output/nhcal_sampling_fraction/{PARTICLE}/Ekin{ENERGY}GeV/sim.edm4hep.root",
0015     params:
0016         N_EVENTS=5000,
0017         DETECTOR_PATH=os.environ["DETECTOR_PATH"],
0018         DETECTOR_CONFIG="epic_backward_hcal_only_sampF.xml",
0019         DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0020         NPSIM_HASH=get_spack_package_hash("npsim"),
0021         TOTAL_ENERGY=lambda wildcards: get_total_energy(wildcards.PARTICLE, wildcards.ENERGY),
0022     cache: True
0023     singularity: EIC_SINGULARITY_CONTAINER,
0024     shell:
0025         """
0026 set -m
0027 exec npsim \
0028     --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG} \
0029     --numberOfEvents {params.N_EVENTS} \
0030     --random.seed $RANDOM \
0031     --enableGun \
0032     -v WARNING \
0033     --gun.particle {wildcards.PARTICLE} \
0034     --gun.thetaMin 120*degree \
0035     --gun.thetaMax 180*degree \
0036     --gun.distribution uniform \
0037     --gun.energy "{params.TOTAL_ENERGY}*GeV" \
0038     --outputFile {output}
0039 """
0040 
0041 
0042 rule nhcal_sampling_fraction_combine:
0043     input:
0044         lambda wildcards: expand(
0045             "sim_output/nhcal_sampling_fraction/{PARTICLE}/Ekin{ENERGY}GeV/sim.edm4hep.root", 
0046             ENERGY=["0.5", "0.7", "1.0", "2.0", "5.0", "10.0"],
0047             PARTICLE=["pi-", "neutron", "e-"],
0048         ),
0049     wildcard_constraints:
0050         ENERGY=r"\d+"
0051     output:
0052         f"sim_output/nhcal_sampling_fraction/sim_combined.edm4hep.root",
0053     singularity: EIC_SINGULARITY_CONTAINER,
0054     shell:
0055         """
0056 hadd -f {output} {input} 
0057 """
0058 
0059 rule nhcal_sampling_fraction_analysis:
0060     input:
0061         combined="sim_output/nhcal_sampling_fraction/sim_combined.edm4hep.root",
0062         script=workflow.source_path("scripts/sampling_fraction_analysis.cxx"),
0063     output:
0064         pdf="results/nhcal_sampling_fraction/hist_sampf_vs_Ehit.pdf",
0065         png="results/nhcal_sampling_fraction/hist_sampf_vs_Ehit.png",
0066     params:
0067         DETECTOR_PATH=os.environ["DETECTOR_PATH"],
0068         DETECTOR_CONFIG="epic_backward_hcal_only_sampF.xml",
0069         binary="results/nhcal_sampling_fraction/sampling_fraction_analysis"
0070     singularity: EIC_SINGULARITY_CONTAINER,
0071     shell:
0072         """
0073         g++ {input.script} \
0074             $(root-config --cflags --libs) \
0075             $(python-config --includes) \
0076             -I/opt/local/include \
0077             -L/opt/local/lib \
0078             -lpodio -lpodioRootIO -ledm4hep -lDDCore -lDDRec \
0079             -o {output.pdf}.bin && \
0080         {output.pdf}.bin "{input.combined}" "{output.pdf}" "{output.png}" "{params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}" && \
0081         rm {output.pdf}.bin
0082         """