Warning, /detector_benchmarks/benchmarks/tracking_performances/Snakefile is written in an unsupported language. File is not indexed.
0001 rule tracking_performance_sim:
0002 input:
0003 steering_file="EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer",
0004 warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
0005 geometry_lib=find_epic_libraries(),
0006 output:
0007 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0008 log:
0009 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root.log",
0010 wildcard_constraints:
0011 PARTICLE="pi-",
0012 ENERGY="[0-9]+[kMG]eV",
0013 PHASE_SPACE="(3to50|45to135|130to177)deg",
0014 INDEX=r"\d{4}",
0015 params:
0016 N_EVENTS=10000,
0017 SEED=lambda wildcards: "1" + wildcards.INDEX,
0018 DETECTOR_PATH=os.environ["DETECTOR_PATH"],
0019 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0020 PARTICLE=lambda wildcards: wildcards.PARTICLE,
0021 ENERGY=lambda wildcards: wildcards.ENERGY,
0022 PHASE_SPACE=lambda wildcards: wildcards.PHASE_SPACE,
0023 INDEX=lambda wildcards: wildcards.INDEX,
0024 DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0025 NPSIM_HASH=get_spack_package_hash("npsim"),
0026 cache: True
0027 shell:
0028 """
0029 set -m # monitor mode to prevent lingering processes
0030 exec ddsim \
0031 --runType batch \
0032 --enableGun \
0033 --steeringFile "{input.steering_file}" \
0034 --random.seed {params.SEED} \
0035 --filter.tracker edep0 \
0036 -v WARNING \
0037 --numberOfEvents {params.N_EVENTS} \
0038 --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}.xml \
0039 --outputFile {output}
0040 """
0041
0042
0043 rule tracking_performance_recon:
0044 input:
0045 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0046 output:
0047 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root",
0048 log:
0049 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root.log",
0050 wildcard_constraints:
0051 INDEX=r"\d{4}",
0052 params:
0053 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0054 PARTICLE=lambda wildcards: wildcards.PARTICLE,
0055 ENERGY=lambda wildcards: wildcards.ENERGY,
0056 PHASE_SPACE=lambda wildcards: wildcards.PHASE_SPACE,
0057 INDEX=lambda wildcards: wildcards.INDEX,
0058 EICRECON_HASH=get_spack_package_hash("eicrecon"),
0059 cache: True
0060 shell: """
0061 set -m # monitor mode to prevent lingering processes
0062 exec env DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
0063 eicrecon {input} -Ppodio:output_file={output} \
0064 -Ppodio:output_collections=MCParticles,CentralCKFTrajectories,CentralCKFTrackParameters,CentralCKFSeededTrackParameters,CentralCKFTruthSeededTrackParameters,CentralTrackVertices
0065 """
0066
0067 rule tracking_performance_hit_maps:
0068 input:
0069 script_hitsmap="benchmarks/tracking_performances/draw_hits.C",
0070 script_nhits_eta="benchmarks/tracking_performances/NhitsvsEta_ePIC.C",
0071 sim=lambda wildcards: expand(
0072 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.edm4hep.root",
0073 DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG},
0074 ENERGY=wildcards.ENERGY,
0075 PARTICLE=wildcards.PARTICLE,
0076 PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0077 INDEX=range(1),
0078 ),
0079 output:
0080 hitsxy_png="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/hitsxy_dd4hep.png",
0081 hitsxy_root="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/hitsxy_dd4hep.root",
0082 hitsrz_png="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/hitsrz_dd4hep.png",
0083 hitsrz_root="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/hitsrz_dd4hep.root",
0084 nhits_eta_png="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/Nhits_vs_eta.png",
0085 nhits_eta_root="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/Nhits_vs_eta.root",
0086 sim_hadd=temporary("sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PARTICLE}.{ENERGY}.edm4hep.root"),
0087 params:
0088 MOMENTUM=lambda wildcards: str(float(wildcards.ENERGY.replace("GeV", "").replace("MeV", "e-3"))),
0089 shell: """
0090 echo "Merging simulation files into: {output}"
0091 hadd -f {output.sim_hadd} {input.sim}
0092 OUTPUT_PREFIX="$(dirname {output.hitsxy_png})"
0093 echo "Generating hit maps and Nhits vs eta for: {output.sim_hadd}"
0094 root -l -b -q {input.script_hitsmap}'("{output.sim_hadd}", "'$OUTPUT_PREFIX'")'
0095 root -l -b -q {input.script_nhits_eta}'("{output.sim_hadd}", "{params.MOMENTUM}", "'$OUTPUT_PREFIX'")'
0096 """
0097
0098 rule tracking_performance_at_momentum:
0099 input:
0100 script="benchmarks/tracking_performances/Tracking_Performances.C",
0101 # TODO pass as a file list?
0102 sim=lambda wildcards: branch(
0103 wildcards.CAMPAIGN == "local",
0104 then=expand(
0105 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.edm4eic.root",
0106 DETECTOR_CONFIG="epic_craterlake_tracking_only",
0107 ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0108 PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0109 INDEX=range(1),
0110 ),
0111 otherwise=expand(
0112 "EPIC/RECO/{{CAMPAIGN}}/epic_craterlake/SINGLE/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon{TREE_SUFFIX}.edm4eic.root",
0113 DETECTOR_CONFIG="epic_craterlake",
0114 ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0115 PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0116 INDEX=range(1),
0117 TREE_SUFFIX=".tree" if wildcards.CAMPAIGN != "local" and int(wildcards.CAMPAIGN[:2]) < 25 else "", # backwards compatibility
0118 ),
0119 ),
0120 output:
0121 "{CAMPAIGN}/{SEEDING}/pi-/mom/Performances_mom_{MOMENTUM}_mom_resol_{SEEDING_IGNORE}_{PARTICLE}.root",
0122 "{CAMPAIGN}/{SEEDING}/pi-/dca/Performances_dca_{MOMENTUM}_dca_resol_{SEEDING_IGNORE}_{PARTICLE}.root",
0123 combined_root=temp("{CAMPAIGN}/sim_{SEEDING}_{MOMENTUM}_{SEEDING_IGNORE}_{PARTICLE}.root"),
0124 shell:
0125 """
0126 if [[ "{wildcards.SEEDING}" == "truthseed" ]]; then
0127 TRUTH_SEEDING="true"
0128 elif [[ "{wildcards.SEEDING}" == "realseed" ]]; then
0129 TRUTH_SEEDING="false"
0130 fi
0131 hadd {output.combined_root} {input.sim}
0132 cd {wildcards.CAMPAIGN}
0133 root -l -b -q ../{input.script}'("../{output.combined_root}", "{wildcards.PARTICLE}", {wildcards.MOMENTUM}, 0.15, '$TRUTH_SEEDING')'
0134 """
0135
0136
0137 rule tracking_performance_hadd_final_hist_dca:
0138 input:
0139 lambda wildcards: expand(
0140 [
0141 "{{CAMPAIGN}}/{{SEEDING}}/pi-/dca/Performances_dca_{MOMENTUM:.1f}_dca_resol_{SEEDING_ALT}_pi-.root",
0142 ],
0143 MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0144 SEEDING_ALT={"truthseed": "truth", "realseed": "realseed"}[wildcards.SEEDING],
0145 ),
0146 output:
0147 "{CAMPAIGN}/{SEEDING}/pi-/dca/final_hist_dca_{SEEDING}.root",
0148 shell:
0149 """
0150 hadd -f {output} {input}
0151 """
0152
0153
0154 rule tracking_performance_summary_at_eta:
0155 input:
0156 expand(
0157 [
0158 "{{CAMPAIGN}}/truthseed/pi-/mom/Performances_mom_{MOMENTUM:.1f}_mom_resol_truth_pi-.root",
0159 "{{CAMPAIGN}}/truthseed/pi-/dca/Performances_dca_{MOMENTUM:.1f}_dca_resol_truth_pi-.root",
0160 "{{CAMPAIGN}}/realseed/pi-/mom/Performances_mom_{MOMENTUM:.1f}_mom_resol_realseed_pi-.root",
0161 "{{CAMPAIGN}}/realseed/pi-/dca/Performances_dca_{MOMENTUM:.1f}_dca_resol_realseed_pi-.root",
0162 ],
0163 MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0164 ),
0165 "{CAMPAIGN}/truthseed/pi-/dca/final_hist_dca_truthseed.root",
0166 "{CAMPAIGN}/realseed/pi-/dca/final_hist_dca_realseed.root",
0167 script_mom="benchmarks/tracking_performances/doCompare_truth_real_widebins_mom.C",
0168 script_dcaT="benchmarks/tracking_performances/doCompare_truth_real_widebins_dcaT.C",
0169 script_dcaz="benchmarks/tracking_performances/doCompare_truth_real_widebins_dcaz.C",
0170 output:
0171 expand(
0172 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/mom/{SEEDING}_mom_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0173 SEEDING=["real", "truth"],
0174 MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0175 ),
0176 expand(
0177 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/dca/{SEEDING}_dcaxy_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0178 SEEDING=["real", "truth"],
0179 MOMENTUM=[0.2, 0.3, 0.5,1.0, 1.5, 2.0, 5.0, 8.0, 10., 15.0],
0180 ),
0181 expand(
0182 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/dca/{SEEDING}_dcaz_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0183 SEEDING=["real", "truth"],
0184 MOMENTUM=[0.2, 0.3, 0.5,1.0, 1.5, 2.0, 5.0, 8.0, 10., 15.0],
0185 ),
0186 "{CAMPAIGN}/Final_Results/pi-/mom/mom_resol_{ETA_MIN}_eta_{ETA_MAX}.png",
0187 "{CAMPAIGN}/Final_Results/pi-/mom/mom_resol_{ETA_MIN}_eta_{ETA_MAX}.root",
0188 "{CAMPAIGN}/Final_Results/pi-/dca/dcaxy_resol_{ETA_MIN}_eta_{ETA_MAX}.png",
0189 "{CAMPAIGN}/Final_Results/pi-/dca/dcaxy_resol_{ETA_MIN}_eta_{ETA_MAX}.root",
0190 "{CAMPAIGN}/Final_Results/pi-/dca/dcaz_resol_{ETA_MIN}_eta_{ETA_MAX}.png",
0191 "{CAMPAIGN}/Final_Results/pi-/dca/dcaz_resol_{ETA_MIN}_eta_{ETA_MAX}.root",
0192 shell:
0193 r"""
0194 if [[ "{wildcards.CAMPAIGN}" == "local" ]]; then
0195 set +e
0196 EPIC_VERSION="${{DETECTOR_VERSION:-}}"
0197 EICRECON_VERSION="$(eicrecon -v | sed -n -e 's/.*\(v[0-9\.]\+\).*/\\1/p')"
0198 # Legacy detection
0199 : ${{EPIC_VERSION:="$(echo $DETECTOR_PATH | sed -n -e 's/.*epic-\([^-/]\+\).*/\\1/p')"}}
0200 set -e
0201
0202 echo "ePIC version: $EPIC_VERSION"
0203 echo "EICrecon version: $EICRECON_VERSION"
0204 EXTRA_LEGEND="ePIC $EPIC_VERSION / EICrecon $EICRECON_VERSION"
0205 else
0206 EXTRA_LEGEND="ePIC Simulation {wildcards.CAMPAIGN}"
0207 fi
0208 cd {wildcards.CAMPAIGN}
0209 root -l -b -q ../{input.script_mom}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, 1., true, "'"$EXTRA_LEGEND"'")'
0210 root -l -b -q ../{input.script_dcaT}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, true, "'"$EXTRA_LEGEND"'")'
0211 root -l -b -q ../{input.script_dcaz}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, true, "'"$EXTRA_LEGEND"'")'
0212 """
0213
0214
0215 rule tracking_performance_debug_montage:
0216 input:
0217 expand(
0218 [
0219 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/mom/{SEEDING}_mom_resol_mom{MOMENTUM:.1f}_{{ETA_BIN}}.png",
0220 ],
0221 MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0222 SEEDING=["truth", "real"],
0223 ),
0224 output:
0225 "{CAMPAIGN}/Debug_Plots/pi-/mom/mom_resol_debug_{ETA_BIN}.png",
0226 shell:
0227 """
0228 montage -mode concatenate {input} {output} || true
0229 ls {output}
0230 """
0231
0232
0233 TRACKING_PERFORMANCE_ETA_BINS = [-3.5, -2.5, -1.0, 1.0, 2.5, 3.5]
0234
0235 rule tracking_performance:
0236 input:
0237 expand(
0238 [
0239 "{{CAMPAIGN}}/Final_Results/pi-/mom/mom_resol_{ETA_BIN}.png",
0240 "{{CAMPAIGN}}/Final_Results/pi-/mom/mom_resol_{ETA_BIN}.root",
0241 "{{CAMPAIGN}}/Debug_Plots/pi-/mom/mom_resol_debug_{ETA_BIN}.png",
0242 ],
0243 ETA_BIN=[f"{eta_min:.1f}_eta_{eta_max:.1f}" for eta_min, eta_max in zip(TRACKING_PERFORMANCE_ETA_BINS[:-1], TRACKING_PERFORMANCE_ETA_BINS[1:])],
0244 ),
0245 lambda wildcards: branch(
0246 wildcards.CAMPAIGN == "local",
0247 then=[
0248 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsxy_dd4hep.png",
0249 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsxy_dd4hep.root",
0250 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsrz_dd4hep.png",
0251 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsrz_dd4hep.root",
0252 "local/epic_craterlake_tracking_only/pi-/1GeV/Nhits_vs_eta.png",
0253 "local/epic_craterlake_tracking_only/pi-/1GeV/Nhits_vs_eta.root",
0254 ],
0255 otherwise=[],
0256 )
0257 output:
0258 directory("results/tracking_performances/{CAMPAIGN}/")
0259 shell:
0260 """
0261 mkdir {output}
0262 cp {input} {output}
0263 """
0264
0265
0266 rule tracking_performance_local:
0267 input:
0268 "results/tracking_performances/local",
0269
0270
0271 rule tracking_performance_campaigns:
0272 input:
0273 expand(
0274 "results/tracking_performances/{CAMPAIGN}",
0275 CAMPAIGN=[
0276 "24.10.1",
0277 "25.04.1",
0278 ],
0279 )