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.root",
0012     params:
0013         N_EVENTS=10000,
0014         SEED=lambda wildcards: "1" + wildcards.INDEX,
0015         DETECTOR_PATH=os.environ["DETECTOR_PATH"],
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     --outputFile {output}
0036 """
0037 
0038 rule nhcal_basic_distribution_combine:
0039     input:
0040         lambda wildcards: expand(
0041             "sim_output/nhcal_basic_distribution/E{ENERGY:.1f}GeV/sim_{DETECTOR_CONFIG}.{INDEX}.edm4hep.root", 
0042             DETECTOR_CONFIG=wildcards.DETECTOR_CONFIG,
0043             ENERGY=float(wildcards.ENERGY),
0044             INDEX=range(int(wildcards.N)),
0045         ),
0046     wildcard_constraints:
0047         N=r"\d+",
0048         ENERGY=r"\d+(\.\d+)?"
0049     output:
0050         temp("sim_output/nhcal_basic_distribution/sim_E{ENERGY}GeV_{DETECTOR_CONFIG}_{N}files.edm4hep.root"),
0051     singularity: EIC_SINGULARITY_CONTAINER,
0052     shell:
0053         """
0054             hadd -f {output} {input} 
0055         """
0056 
0057 rule nhcal_basic_distribution_analysis:
0058     input:
0059         workflow.source_path("scripts/HistogramsNeutronThresholds.h"),
0060         workflow.source_path("scripts/NeutronThresholdUtil.h"),
0061         combined="sim_output/nhcal_basic_distribution/sim_E{ENERGY}GeV_{DETECTOR_CONFIG}_{N}files.edm4hep.root",
0062         script=workflow.source_path("scripts/basic_distribution_analysis.cxx"),
0063     output:
0064         png="results/nhcal_basic_distribution/analysis_E{ENERGY}GeV_{DETECTOR_CONFIG}_{N}files.png",
0065         root="sim_output/nhcal_basic_distribution/energy_resolution_E{ENERGY}GeV_{DETECTOR_CONFIG}_{N}files.root",
0066     wildcard_constraints:
0067         ENERGY=r"\d+(\.\d+)?",
0068         N=r"\d+",
0069     params:
0070         DETECTOR_PATH   = os.environ["DETECTOR_PATH"],
0071         DETECTOR_CONFIG = lambda wildcards: f"{wildcards.DETECTOR_CONFIG}.xml", 
0072     singularity: EIC_SINGULARITY_CONTAINER,
0073     shell:
0074         """
0075             root -l -b -q '{input.script}+("{input.combined}","{output.png}","{output.root}","{params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}")'
0076         """
0077     
0078 rule nhcal_basic_distribution_combine_energy_resolution:
0079     input:
0080         lambda wildcards: [
0081             f"sim_output/nhcal_basic_distribution/energy_resolution_E{e}GeV_{wildcards.DETECTOR_CONFIG}_10files.root"
0082             for e in ["0.5", "0.7", "1.0", "2.0", "5.0"]
0083         ]
0084     output:
0085         "sim_output/nhcal_basic_distribution/energy_resolution_combined_{DETECTOR_CONFIG}.root",
0086     wildcard_constraints:
0087         DETECTOR_CONFIG=r"[\w]+",
0088     singularity: EIC_SINGULARITY_CONTAINER,
0089     shell:
0090         """
0091             hadd -f {output} {input} 
0092         """
0093 
0094 rule nhcal_basic_distribution_analysis_energy_resolution:
0095     input:
0096         root="sim_output/nhcal_basic_distribution/energy_resolution_combined_{DETECTOR_CONFIG}.root",
0097         script=workflow.source_path("scripts/basic_distribution_energy_resolution.cxx"),
0098     output:
0099         png="results/nhcal_basic_distribution/energy_resolution_analysis_{DETECTOR_CONFIG}.png",
0100     singularity: EIC_SINGULARITY_CONTAINER,
0101     shell:
0102         """
0103             root -l -b -q '{input.script}("{input.root}","{output.png}")'
0104         """