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