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     shell:
0024         """
0025 set -m
0026 exec npsim \
0027     --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG} \
0028     --numberOfEvents {params.N_EVENTS} \
0029     --random.seed $RANDOM \
0030     --enableGun \
0031     -v WARNING \
0032     --gun.particle {wildcards.PARTICLE} \
0033     --gun.thetaMin 120*degree \
0034     --gun.thetaMax 180*degree \
0035     --gun.distribution uniform \
0036     --gun.energy "{params.TOTAL_ENERGY}*GeV" \
0037     --outputFile {output}
0038 """
0039 
0040 
0041 rule nhcal_sampling_fraction_combine:
0042     input:
0043         lambda wildcards: expand(
0044             "sim_output/nhcal_sampling_fraction/{PARTICLE}/Ekin{ENERGY}GeV/sim.edm4hep.root", 
0045             ENERGY=["0.5", "0.7", "1.0", "2.0", "5.0", "10.0"],
0046             PARTICLE=["pi-", "neutron", "e-"],
0047         ),
0048     wildcard_constraints:
0049         ENERGY=r"\d+"
0050     output:
0051         f"sim_output/nhcal_sampling_fraction/sim_combined.edm4hep.root",
0052     shell:
0053         """
0054 hadd -f {output} {input} 
0055 """
0056 
0057 rule nhcal_sampling_fraction_analysis:
0058     input:
0059         combined="sim_output/nhcal_sampling_fraction/sim_combined.edm4hep.root",
0060         script="benchmarks/nhcal_sampling_fraction/scripts/sampling_fraction_analysis.cxx",
0061     output:
0062         pdf="results/nhcal_sampling_fraction/hist_sampf_vs_Ehit.pdf",
0063         png="results/nhcal_sampling_fraction/hist_sampf_vs_Ehit.png",
0064     params:
0065         DETECTOR_PATH=os.environ["DETECTOR_PATH"],
0066         DETECTOR_CONFIG="epic_backward_hcal_only_sampF.xml",
0067         binary="results/nhcal_sampling_fraction/sampling_fraction_analysis"
0068     shell:
0069         """
0070         g++ {input.script} \
0071             $(root-config --cflags --libs) \
0072             $(python-config --includes) \
0073             -I/opt/local/include \
0074             -L/opt/local/lib \
0075             -lpodio -lpodioRootIO -ledm4hep -lDDCore -lDDRec \
0076             -o {output.pdf}.bin && \
0077         {output.pdf}.bin "{input.combined}" "{output.pdf}" "{output.png}" "{params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}" && \
0078         rm {output.pdf}.bin
0079         """