Warning, /detector_benchmarks/benchmarks/lfhcal/Snakefile is written in an unsupported language. File is not indexed.
0001 def get_n_events(wildcards):
0002 energy = float(wildcards.ENERGY.replace("GeV", "").replace("MeV", "e-3"))
0003 n_events = 1000
0004 n_events = int(n_events // (energy ** 0.5))
0005 return n_events
0006
0007
0008 rule lfhcal_sim:
0009 input:
0010 steering_file="EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer",
0011 warmup="warmup.edm4hep.root",
0012 geometry_lib=find_epic_libraries(),
0013 output:
0014 "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0015 log:
0016 "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root.log",
0017 wildcard_constraints:
0018 ENERGY="[0-9]+[kMG]eV",
0019 PARTICLE="(neutron|pi-|gamma)",
0020 PHASE_SPACE="3to50deg",
0021 INDEX=r"\d{4}",
0022 params:
0023 N_EVENTS=get_n_events,
0024 SEED=lambda wildcards: "1" + wildcards.INDEX,
0025 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0026 DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0027 NPSIM_HASH=get_spack_package_hash("npsim"),
0028 cache: True
0029 singularity: EIC_SINGULARITY_CONTAINER,
0030 shell:
0031 """
0032 npsim \
0033 --runType batch \
0034 --enableGun \
0035 --steeringFile "{input.steering_file}" \
0036 --random.seed {params.SEED} \
0037 --filter.tracker edep0 \
0038 -v INFO \
0039 --numberOfEvents {params.N_EVENTS} \
0040 --compactFile $DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml \
0041 --outputFile {output}
0042 """
0043
0044
0045 rule lfhcal_recon:
0046 input:
0047 sim="sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0048 warmup="warmup.edm4hep.root",
0049 output:
0050 "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root",
0051 log:
0052 "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root.log",
0053 wildcard_constraints:
0054 INDEX=r"\d{4}",
0055 params:
0056 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0057 EICRECON_HASH=get_spack_package_hash("eicrecon"),
0058 cache: True
0059 singularity: EIC_SINGULARITY_CONTAINER,
0060 shell: """
0061 env DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
0062 eicrecon {input.sim} -Ppodio:output_file={output} \
0063 -Ppodio:output_collections=MCParticles,ReconstructedParticles,LFHCALTruthClusters,LFHCALClusters,LFHCALHits,EcalEndcapPTruthClusters,EcalEndcapPClusters,EcalEndcapPHits
0064 """
0065
0066 rule lfhcal_at_momentum:
0067 input:
0068 script=workflow.source_path("LFHCAL_Performance.C"),
0069 # TODO pass as a file list?
0070 sim=lambda wildcards:
0071 expand(
0072 "sim_output/lfhcal/{DETECTOR_CONFIG}/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.edm4eic.root",
0073 DETECTOR_CONFIG="epic_craterlake",
0074 ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0075 PHASE_SPACE=["3to50deg"],
0076 INDEX=range(1),
0077 )
0078 if wildcards.CAMPAIGN == "local" else
0079 ancient(expand(
0080 "EPIC/RECO/{{CAMPAIGN}}/epic_craterlake/SINGLE/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon{TREE_SUFFIX}.edm4eic.root",
0081 DETECTOR_CONFIG="epic_craterlake",
0082 ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0083 PHASE_SPACE=["3to50deg"],
0084 INDEX=range(1),
0085 TREE_SUFFIX=".tree" if int(wildcards.CAMPAIGN[:2]) < 25 else "", # backwards compatibility
0086 )),
0087 output:
0088 "{CAMPAIGN}/{PARTICLE}/mom/lfhcal_mom_{MOMENTUM}_mom_resol_{PARTICLE}.root",
0089 combined_root=temp("{CAMPAIGN}/lfhcal_sim_{MOMENTUM}_{PARTICLE}.root"),
0090 singularity: EIC_SINGULARITY_CONTAINER,
0091 shell:
0092 """
0093 hadd {output.combined_root} {input.sim}
0094 root -l -b -q {input.script}'("{output.combined_root}", "{wildcards.PARTICLE}", {wildcards.MOMENTUM}, 0.15, "", "{wildcards.CAMPAIGN}")'
0095 """
0096
0097 rule lfhcal_summary_at_eta:
0098 input:
0099 expand(
0100 [
0101 "{{CAMPAIGN}}/{{PARTICLE}}/mom/lfhcal_mom_{MOMENTUM:.1f}_mom_resol_{{PARTICLE}}.root",
0102 ],
0103 MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0104 ),
0105 script=workflow.source_path("doCompare_widebins_mom.C"),
0106 output:
0107 "{CAMPAIGN}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_MIN}_eta_{ETA_MAX}.png",
0108 "{CAMPAIGN}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_MIN}_eta_{ETA_MAX}.root",
0109 singularity: EIC_SINGULARITY_CONTAINER,
0110 shell:
0111 r"""
0112 if [[ "{wildcards.CAMPAIGN}" == "local" ]]; then
0113 set +e
0114 EPIC_VERSION="${{DETECTOR_VERSION:-}}"
0115 EICRECON_VERSION="$(eicrecon -v | sed -n -e 's/.*\(v[0-9\.]\+\).*/\\1/p')"
0116 # Legacy detection
0117 : ${{EPIC_VERSION:="$(echo $DETECTOR_PATH | sed -n -e 's/.*epic-\([^-/]\+\).*/\\1/p')"}}
0118 set -e
0119
0120 echo "ePIC version: $EPIC_VERSION"
0121 echo "EICrecon version: $EICRECON_VERSION"
0122 EXTRA_LEGEND="ePIC $EPIC_VERSION / EICrecon $EICRECON_VERSION"
0123 else
0124 EXTRA_LEGEND="ePIC Simulation {wildcards.CAMPAIGN}"
0125 fi
0126 root -l -b -q {input.script}'("{wildcards.PARTICLE}", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, 1., true, "'"$EXTRA_LEGEND"'", "{wildcards.CAMPAIGN}")'
0127 """
0128
0129 LFHCAL_ETA_BINS = [1.2,1.5,2,2.5,3,3.5]
0130
0131 rule lfhcal:
0132 input:
0133 lambda wildcards: expand(
0134 [
0135 "{{CAMPAIGN}}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_BIN}.png",
0136 "{{CAMPAIGN}}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_BIN}.root",
0137 ],
0138 ETA_BIN=[f"{eta_min:.1f}_eta_{eta_max:.1f}" for eta_min, eta_max in zip(LFHCAL_ETA_BINS[:-1], LFHCAL_ETA_BINS[1:])],
0139 PARTICLE=["neutron", "pi-", "gamma"] if wildcards.CAMPAIGN == "local" else ["pi-"],
0140 )
0141 output:
0142 directory("results/lfhcal/{CAMPAIGN}/")
0143 singularity: EIC_SINGULARITY_CONTAINER,
0144 shell:
0145 """
0146 mkdir {output}
0147 cp {input} {output}
0148 """
0149
0150
0151 rule lfhcal_local:
0152 input:
0153 "results/lfhcal/local",
0154
0155
0156 rule lfhcal_campaigns:
0157 input:
0158 expand(
0159 "results/lfhcal/{CAMPAIGN}",
0160 CAMPAIGN=[
0161 "24.10.1",
0162 "25.10.4",
0163 ],
0164 )