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