Back to home page

EIC code displayed by LXR

 
 

    


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

0001 def get_total_energy_neutron(kinetic_energy):
0002     ke = float(kinetic_energy)
0003     neutron_mass = 0.94
0004     return f"{ke + neutron_mass:.2f}"
0005 
0006 rule nhcal_basic_distribution_simulate:
0007     input:
0008         warmup="warmup.edm4hep.root",
0009         geometry_lib=find_epic_libraries(),
0010     output:
0011         "sim_output/nhcal_basic_distribution/E{ENERGY}GeV/sim_{DETECTOR_CONFIG}.{INDEX}.edm4hep.rnt.root",
0012     params:
0013         N_EVENTS=10000,
0014         SEED=lambda wildcards: "1" + wildcards.INDEX,
0015         DETECTOR_PATH=config["DETECTOR_PREFIX"] + "/share/epic",
0016         DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0017         DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0018         NPSIM_HASH=get_spack_package_hash("npsim"),
0019         TOTAL_ENERGY=lambda wildcards: get_total_energy_neutron(wildcards.ENERGY),
0020     cache: True
0021     singularity: EIC_SINGULARITY_CONTAINER,
0022     shell:
0023         """
0024 exec npsim \
0025     --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}.xml \
0026     --numberOfEvents {params.N_EVENTS} \
0027     --random.seed {params.SEED} \
0028     --enableGun \
0029     -v WARNING \
0030     --gun.particle neutron \
0031     --gun.thetaMin 120*degree \
0032     --gun.thetaMax 180*degree \
0033     --gun.distribution uniform \
0034     --gun.energy "{params.TOTAL_ENERGY}*GeV" \
0035     --outputConfig.useRNTuple true \
0036     --outputFile {output}
0037 """
0038 
0039 rule nhcal_basic_distribution_analysis:
0040     input:
0041         workflow.source_path("scripts/HistogramsNeutronThresholds.h"),
0042         workflow.source_path("scripts/NeutronThresholdUtil.h"),
0043         sim=lambda wildcards: expand(
0044             "sim_output/nhcal_basic_distribution/E{ENERGY:.1f}GeV/sim_{DETECTOR_CONFIG}.{INDEX}.edm4hep.rnt.root",
0045             DETECTOR_CONFIG=wildcards.DETECTOR_CONFIG,
0046             ENERGY=float(wildcards.ENERGY),
0047             INDEX=range(int(wildcards.N)),
0048         ),
0049         script=workflow.source_path("scripts/basic_distribution_analysis.cxx"),
0050     output:
0051         png="results/nhcal_basic_distribution/analysis_E{ENERGY}GeV_{DETECTOR_CONFIG}_{N}files.png",
0052         root="sim_output/nhcal_basic_distribution/energy_resolution_E{ENERGY}GeV_{DETECTOR_CONFIG}_{N}files.root",
0053     wildcard_constraints:
0054         ENERGY=r"\d+(\.\d+)?",
0055         N=r"\d+",
0056     params:
0057         DETECTOR_PATH   = config["DETECTOR_PREFIX"] + "/share/epic",
0058         DETECTOR_CONFIG = lambda wildcards: f"{wildcards.DETECTOR_CONFIG}.xml",
0059         SIM_GLOB = lambda wildcards: f"sim_output/nhcal_basic_distribution/E{float(wildcards.ENERGY):.1f}GeV/sim_{wildcards.DETECTOR_CONFIG}.*.edm4hep.rnt.root",
0060     singularity: EIC_SINGULARITY_CONTAINER,
0061     shell:
0062         """
0063             root -l -b -q '{input.script}+("{params.SIM_GLOB}","{output.png}","{output.root}","{params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}")'
0064         """
0065 
0066 rule nhcal_basic_distribution_combine_energy_resolution:
0067     input:
0068         lambda wildcards: [
0069             f"sim_output/nhcal_basic_distribution/energy_resolution_E{e}GeV_{wildcards.DETECTOR_CONFIG}_10files.root"
0070             for e in ["0.5", "0.7", "1.0", "2.0", "5.0"]
0071         ]
0072     output:
0073         "sim_output/nhcal_basic_distribution/energy_resolution_combined_{DETECTOR_CONFIG}.root",
0074     wildcard_constraints:
0075         DETECTOR_CONFIG=r"[\w]+",
0076     singularity: EIC_SINGULARITY_CONTAINER,
0077     shell:
0078         """
0079             hadd -f {output} {input}
0080         """
0081 
0082 rule nhcal_basic_distribution_analysis_energy_resolution:
0083     input:
0084         root="sim_output/nhcal_basic_distribution/energy_resolution_combined_{DETECTOR_CONFIG}.root",
0085         script=workflow.source_path("scripts/basic_distribution_energy_resolution.cxx"),
0086     output:
0087         png="results/nhcal_basic_distribution/energy_resolution_analysis_{DETECTOR_CONFIG}.png",
0088     singularity: EIC_SINGULARITY_CONTAINER,
0089     shell:
0090         """
0091             root -l -b -q '{input.script}("{input.root}","{output.png}")'
0092         """