Back to home page

EIC code displayed by LXR

 
 

    


Warning, /physics_benchmarks/benchmarks/Exclusive-Diffraction-Tagging/dvmp/Snakefile is written in an unsupported language. File is not indexed.

0001 import os
0002 
0003 # Compile the analysis scripts
0004 rule dvmp_compile:
0005     input:
0006         ROOT_BUILD_DIR_PREFIX + "benchmarks/Exclusive-Diffraction-Tagging/dvmp/analysis/vm_mass_cxx.so",
0007         ROOT_BUILD_DIR_PREFIX + "benchmarks/Exclusive-Diffraction-Tagging/dvmp/analysis/vm_invar_cxx.so",
0008 
0009 # Generation rule (uses lager event generator)
0010 rule dvmp_gen:
0011     output:
0012         hepmc="input/gen-{CONFIG}_{DECAY}_{N_EVENTS}.hepmc",
0013         config=temp("tmp/gen-{CONFIG}_{DECAY}_{N_EVENTS}.json"),
0014     params:
0015         N_EVENTS=lambda wildcards: int(wildcards.N_EVENTS),
0016         RNG_SEED=os.getenv("JUGGLER_RNG_SEED", 1),
0017         EBEAM=lambda wildcards: 10,  # Default for 10x100
0018         PBEAM=lambda wildcards: 100,
0019         BRANCHING=lambda wildcards: "0.05961" if wildcards.DECAY == "muon" else "0.05971",
0020         DECAY_PID=lambda wildcards: "13" if wildcards.DECAY == "muon" else "11",
0021     wildcard_constraints:
0022         CONFIG=r"[a-z_]+",
0023         DECAY=r"(muon|electron)",
0024         N_EVENTS=r"\d+",
0025     shell:
0026         """
0027 # Create generator configuration from template
0028 mkdir -p tmp input
0029 sed -e "s/@TAG@/gen-{wildcards.CONFIG}_{wildcards.DECAY}_{params.N_EVENTS}/" \
0030     -e "s/@EBEAM@/{params.EBEAM}/" \
0031     -e "s/@PBEAM@/{params.PBEAM}/" \
0032     -e "s/@DECAY_LEPTON@/{params.DECAY_PID}/" \
0033     -e "s/@BRANCHING@/{params.BRANCHING}/" \
0034     benchmarks/Exclusive-Diffraction-Tagging/dvmp/generator/{wildcards.CONFIG}.json.in > {output.config}
0035 
0036 # Run the generator
0037 lager -r {params.RNG_SEED} \
0038       -c {output.config} \
0039       -e {params.N_EVENTS} \
0040       -o tmp
0041 
0042 # Move output to input directory
0043 for ext in hepmc json log root ; do
0044   if [ -f tmp/*.gen-{wildcards.CONFIG}_{wildcards.DECAY}_{params.N_EVENTS}.*.${{ext}} ]; then
0045     mv tmp/*.gen-{wildcards.CONFIG}_{wildcards.DECAY}_{params.N_EVENTS}.*.${{ext}} input/gen-{wildcards.CONFIG}_{wildcards.DECAY}_{params.N_EVENTS}.${{ext}}
0046   fi
0047 done
0048 """
0049 
0050 # Simulation rule
0051 rule dvmp_sim:
0052     input:
0053         warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
0054         geometry_lib=find_epic_libraries(),
0055         gen_file="input/gen-{CONFIG}_{DECAY}_{N_EVENTS}.hepmc",
0056     output:
0057         "sim/{DETECTOR_CONFIG}/sim-{CONFIG}_{DECAY}_{N_EVENTS}.edm4hep.root",
0058     params:
0059         N_EVENTS=lambda wildcards: int(wildcards.N_EVENTS),
0060         DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0061         NPSIM_HASH=get_spack_package_hash("npsim"),
0062     wildcard_constraints:
0063         CONFIG=r"[a-z_]+",
0064         DECAY=r"(muon|electron)",
0065         N_EVENTS=r"\d+",
0066     cache: True
0067     shell:
0068         """
0069 npsim \
0070   --runType batch \
0071   --part.minimalKineticEnergy 100*GeV  \
0072   --filter.tracker edep0 \
0073   -v WARNING \
0074   --numberOfEvents {params.N_EVENTS} \
0075   --compactFile $DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml \
0076   --inputFiles {input.gen_file} \
0077   --outputFile {output}
0078 """
0079 
0080 # Reconstruction rule
0081 rule dvmp_reco:
0082     input:
0083         "sim/{DETECTOR_CONFIG}/sim-{CONFIG}_{DECAY}_{N_EVENTS}.edm4hep.root",
0084     output:
0085         "reco/{DETECTOR_CONFIG}/rec-{CONFIG}_{DECAY}_{N_EVENTS}.edm4eic.root",
0086     params:
0087         EICRECON_HASH=get_spack_package_hash("eicrecon"),
0088     wildcard_constraints:
0089         CONFIG=r"[a-z_]+",
0090         DECAY=r"(muon|electron)",
0091         N_EVENTS=r"\d+",
0092     cache: True
0093     shell:
0094         """
0095 DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} eicrecon {input} -Ppodio:output_file={output}
0096 """
0097 
0098 # Analysis rule for vm_mass
0099 rule dvmp_analysis_vm_mass:
0100     input:
0101         script="benchmarks/Exclusive-Diffraction-Tagging/dvmp/analysis/vm_mass.cxx",
0102         script_compiled=ROOT_BUILD_DIR_PREFIX + "benchmarks/Exclusive-Diffraction-Tagging/dvmp/analysis/vm_mass_cxx.so",
0103         data="reco/{DETECTOR_CONFIG}/rec-{CONFIG}_{DECAY}_{N_EVENTS}.edm4eic.root",
0104     output:
0105         config="results/{DETECTOR_CONFIG}/dvmp/{CONFIG}_{DECAY}_{N_EVENTS}/vm_mass_config.json",
0106         done="results/{DETECTOR_CONFIG}/dvmp/{CONFIG}_{DECAY}_{N_EVENTS}/vm_mass_done.txt",
0107     params:
0108         EBEAM=10,
0109         PBEAM=100,
0110         LEADING="jpsi",
0111     wildcard_constraints:
0112         CONFIG=r"[a-z_]+",
0113         DECAY=r"(muon|electron)",
0114         N_EVENTS=r"\d+",
0115     shell:
0116         """
0117 mkdir -p results/{wildcards.DETECTOR_CONFIG}/dvmp/{wildcards.CONFIG}_{wildcards.DECAY}_{wildcards.N_EVENTS}
0118 cat > {output.config} <<EOF
0119 {{
0120   "rec_file": "{input.data}",
0121   "vm_name": "{params.LEADING}",
0122   "decay": "{wildcards.DECAY}",
0123   "detector": "{wildcards.DETECTOR_CONFIG}",
0124   "output_prefix": "results/{wildcards.DETECTOR_CONFIG}/dvmp/{wildcards.CONFIG}_{wildcards.DECAY}_{wildcards.N_EVENTS}/{wildcards.CONFIG}_{wildcards.DECAY}",
0125   "test_tag": "{params.LEADING}_{wildcards.DECAY}_{params.EBEAM}x{params.PBEAM}"
0126 }}
0127 EOF
0128 root -l -b -q '{input.script}+("{output.config}")'
0129 touch {output.done}
0130 """
0131 
0132 # Analysis rule for vm_invar
0133 rule dvmp_analysis_vm_invar:
0134     input:
0135         script="benchmarks/Exclusive-Diffraction-Tagging/dvmp/analysis/vm_invar.cxx",
0136         script_compiled=ROOT_BUILD_DIR_PREFIX + "benchmarks/Exclusive-Diffraction-Tagging/dvmp/analysis/vm_invar_cxx.so",
0137         data="reco/{DETECTOR_CONFIG}/rec-{CONFIG}_{DECAY}_{N_EVENTS}.edm4eic.root",
0138     output:
0139         config="results/{DETECTOR_CONFIG}/dvmp/{CONFIG}_{DECAY}_{N_EVENTS}/vm_invar_config.json",
0140         done="results/{DETECTOR_CONFIG}/dvmp/{CONFIG}_{DECAY}_{N_EVENTS}/vm_invar_done.txt",
0141     params:
0142         EBEAM=10,
0143         PBEAM=100,
0144         LEADING="jpsi",
0145     wildcard_constraints:
0146         CONFIG=r"[a-z_]+",
0147         DECAY=r"(muon|electron)",
0148         N_EVENTS=r"\d+",
0149     shell:
0150         """
0151 mkdir -p results/{wildcards.DETECTOR_CONFIG}/dvmp/{wildcards.CONFIG}_{wildcards.DECAY}_{wildcards.N_EVENTS}
0152 cat > {output.config} <<EOF
0153 {{
0154   "rec_file": "{input.data}",
0155   "vm_name": "{params.LEADING}",
0156   "decay": "{wildcards.DECAY}",
0157   "detector": "{wildcards.DETECTOR_CONFIG}",
0158   "output_prefix": "results/{wildcards.DETECTOR_CONFIG}/dvmp/{wildcards.CONFIG}_{wildcards.DECAY}_{wildcards.N_EVENTS}/{wildcards.CONFIG}_{wildcards.DECAY}",
0159   "test_tag": "{params.LEADING}_{wildcards.DECAY}_{params.EBEAM}x{params.PBEAM}"
0160 }}
0161 EOF
0162 root -l -b -q '{input.script}+("{output.config}")'
0163 touch {output.done}
0164 """
0165 
0166 # Aggregate both analysis outputs
0167 rule dvmp_analysis_complete:
0168     input:
0169         "results/{DETECTOR_CONFIG}/dvmp/{CONFIG}_{DECAY}_{N_EVENTS}/vm_mass_done.txt",
0170         "results/{DETECTOR_CONFIG}/dvmp/{CONFIG}_{DECAY}_{N_EVENTS}/vm_invar_done.txt",
0171     output:
0172         "results/{DETECTOR_CONFIG}/dvmp/{CONFIG}_{DECAY}_{N_EVENTS}/analysis_done.txt",
0173     shell:
0174         """
0175 touch {output}
0176 """
0177 
0178 # Top-level rule to run generation for a specific config
0179 rule dvmp_gen_config:
0180     input:
0181         "input/gen-{CONFIG}_muon_{N_EVENTS}.hepmc",
0182         "input/gen-{CONFIG}_electron_{N_EVENTS}.hepmc",
0183     message:
0184         "Generation complete for {wildcards.CONFIG}"
0185 
0186 # Top-level rule to run everything for a specific config
0187 rule dvmp_run_config:
0188     input:
0189         "results/{DETECTOR_CONFIG}/dvmp/{CONFIG}_muon_{N_EVENTS}/analysis_done.txt",
0190         "results/{DETECTOR_CONFIG}/dvmp/{CONFIG}_electron_{N_EVENTS}/analysis_done.txt",
0191     message:
0192         "DVMP benchmark complete for {wildcards.CONFIG}. See output in results/{wildcards.DETECTOR_CONFIG}/dvmp/"
0193 
0194 # Default run for local execution (jpsi_barrel with default event count from env)
0195 rule dvmp_run_locally:
0196     input:
0197         expand("results/{{DETECTOR_CONFIG}}/dvmp/jpsi_barrel_{decay}_{n_events}/analysis_done.txt",
0198                decay=["muon", "electron"],
0199                n_events=[os.getenv("JUGGLER_N_EVENTS", "100")]),
0200     message:
0201         "DVMP benchmark complete. See output in results/{DETECTOR_CONFIG}/dvmp/"