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=ancient("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 npsim \
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 warmup=ancient("warmup/{DETECTOR_CONFIG}.edm4hep.root"),
0047 output:
0048 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root",
0049 log:
0050 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root.log",
0051 wildcard_constraints:
0052 INDEX=r"\d{4}",
0053 params:
0054 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0055 PARTICLE=lambda wildcards: wildcards.PARTICLE,
0056 ENERGY=lambda wildcards: wildcards.ENERGY,
0057 PHASE_SPACE=lambda wildcards: wildcards.PHASE_SPACE,
0058 INDEX=lambda wildcards: wildcards.INDEX,
0059 EICRECON_HASH=get_spack_package_hash("eicrecon"),
0060 cache: True
0061 shell: """
0062 set -m # monitor mode to prevent lingering processes
0063 exec env DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
0064 eicrecon {input} -Ppodio:output_file={output} \
0065 -Ppodio:output_collections=MCParticles,CentralCKFTrajectories,CentralCKFTrackParameters,CentralCKFSeededTrackParameters,CentralCKFTruthSeededTrackParameters,CentralTrackVertices
0066 """
0067
0068 rule tracking_performance_hit_maps:
0069 input:
0070 script_hitsmap="benchmarks/tracking_performances/draw_hits.C",
0071 script_nhits_eta="benchmarks/tracking_performances/NhitsvsEta_ePIC.C",
0072 sim=lambda wildcards: expand(
0073 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.edm4hep.root",
0074 DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG},
0075 ENERGY=wildcards.ENERGY,
0076 PARTICLE=wildcards.PARTICLE,
0077 PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0078 INDEX=range(1),
0079 ),
0080 output:
0081 hitsxy_png="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/hitsxy_dd4hep.png",
0082 hitsxy_root="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/hitsxy_dd4hep.root",
0083 hitsrz_png="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/hitsrz_dd4hep.png",
0084 hitsrz_root="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/hitsrz_dd4hep.root",
0085 nhits_eta_png="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/Nhits_vs_eta.png",
0086 nhits_eta_root="local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/Nhits_vs_eta.root",
0087 sim_hadd=temporary("sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PARTICLE}.{ENERGY}.edm4hep.root"),
0088 params:
0089 MOMENTUM=lambda wildcards: str(float(wildcards.ENERGY.replace("GeV", "").replace("MeV", "e-3"))),
0090 shell: """
0091 echo "Merging simulation files into: {output}"
0092 hadd -f {output.sim_hadd} {input.sim}
0093 OUTPUT_PREFIX="$(dirname {output.hitsxy_png})"
0094 echo "Generating hit maps and Nhits vs eta for: {output.sim_hadd}"
0095 root -l -b -q {input.script_hitsmap}'("{output.sim_hadd}", "'$OUTPUT_PREFIX'")'
0096 root -l -b -q {input.script_nhits_eta}'("{output.sim_hadd}", "{params.MOMENTUM}", "'$OUTPUT_PREFIX'")'
0097 """
0098
0099 rule tracking_performance_at_momentum:
0100 input:
0101 script="benchmarks/tracking_performances/Tracking_Performances.C",
0102 # TODO pass as a file list?
0103 sim=lambda wildcards: branch(
0104 wildcards.CAMPAIGN == "local",
0105 then=expand(
0106 "sim_output/tracking_performance/{DETECTOR_CONFIG}/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.edm4eic.root",
0107 DETECTOR_CONFIG="epic_craterlake_tracking_only",
0108 ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0109 PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0110 INDEX=range(1),
0111 ),
0112 otherwise=expand(
0113 "EPIC/RECO/{{CAMPAIGN}}/epic_craterlake/SINGLE/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon{TREE_SUFFIX}.edm4eic.root",
0114 DETECTOR_CONFIG="epic_craterlake",
0115 ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0116 PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0117 INDEX=range(1),
0118 TREE_SUFFIX=".tree" if wildcards.CAMPAIGN != "local" and int(wildcards.CAMPAIGN[:2]) < 25 else "", # backwards compatibility
0119 ),
0120 ),
0121 output:
0122 "{CAMPAIGN}/{SEEDING}/pi-/mom/Performances_mom_{MOMENTUM}_mom_resol_{SEEDING_IGNORE}_{PARTICLE}.root",
0123 "{CAMPAIGN}/{SEEDING}/pi-/dca/Performances_dca_{MOMENTUM}_dca_resol_{SEEDING_IGNORE}_{PARTICLE}.root",
0124 combined_root=temp("{CAMPAIGN}/sim_{SEEDING}_{MOMENTUM}_{SEEDING_IGNORE}_{PARTICLE}.root"),
0125 shell:
0126 """
0127 if [[ "{wildcards.SEEDING}" == "truthseed" ]]; then
0128 TRUTH_SEEDING="true"
0129 elif [[ "{wildcards.SEEDING}" == "realseed" ]]; then
0130 TRUTH_SEEDING="false"
0131 fi
0132 hadd {output.combined_root} {input.sim}
0133 cd {wildcards.CAMPAIGN}
0134 root -l -b -q ../{input.script}'("../{output.combined_root}", "{wildcards.PARTICLE}", {wildcards.MOMENTUM}, 0.15, '$TRUTH_SEEDING')'
0135 """
0136
0137
0138 rule tracking_performance_hadd_final_hist_dca:
0139 input:
0140 lambda wildcards: expand(
0141 [
0142 "{{CAMPAIGN}}/{{SEEDING}}/pi-/dca/Performances_dca_{MOMENTUM:.1f}_dca_resol_{SEEDING_ALT}_pi-.root",
0143 ],
0144 MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0145 SEEDING_ALT={"truthseed": "truth", "realseed": "realseed"}[wildcards.SEEDING],
0146 ),
0147 output:
0148 "{CAMPAIGN}/{SEEDING}/pi-/dca/final_hist_dca_{SEEDING}.root",
0149 shell:
0150 """
0151 hadd -f {output} {input}
0152 """
0153
0154
0155 rule tracking_performance_summary_at_eta:
0156 input:
0157 expand(
0158 [
0159 "{{CAMPAIGN}}/truthseed/pi-/mom/Performances_mom_{MOMENTUM:.1f}_mom_resol_truth_pi-.root",
0160 "{{CAMPAIGN}}/truthseed/pi-/dca/Performances_dca_{MOMENTUM:.1f}_dca_resol_truth_pi-.root",
0161 "{{CAMPAIGN}}/realseed/pi-/mom/Performances_mom_{MOMENTUM:.1f}_mom_resol_realseed_pi-.root",
0162 "{{CAMPAIGN}}/realseed/pi-/dca/Performances_dca_{MOMENTUM:.1f}_dca_resol_realseed_pi-.root",
0163 ],
0164 MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0165 ),
0166 "{CAMPAIGN}/truthseed/pi-/dca/final_hist_dca_truthseed.root",
0167 "{CAMPAIGN}/realseed/pi-/dca/final_hist_dca_realseed.root",
0168 script_mom="benchmarks/tracking_performances/doCompare_truth_real_widebins_mom.C",
0169 script_pulls="benchmarks/tracking_performances/draw_Pulls.C",
0170 script_dcaT="benchmarks/tracking_performances/doCompare_truth_real_widebins_dcaT.C",
0171 script_dcaz="benchmarks/tracking_performances/doCompare_truth_real_widebins_dcaz.C",
0172 output:
0173 expand(
0174 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/mom/{SEEDING}_mom_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0175 SEEDING=["real", "truth"],
0176 MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0177 ),
0178 expand(
0179 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/dca/{SEEDING}_dcaxy_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0180 SEEDING=["real", "truth"],
0181 MOMENTUM=[0.2, 0.3, 0.5,1.0, 1.5, 2.0, 5.0, 8.0, 10., 15.0],
0182 ),
0183 expand(
0184 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/dca/{SEEDING}_dcaz_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0185 SEEDING=["real", "truth"],
0186 MOMENTUM=[0.2, 0.3, 0.5,1.0, 1.5, 2.0, 5.0, 8.0, 10., 15.0],
0187 ),
0188 "{CAMPAIGN}/Final_Results/pi-/mom/mom_resol_{ETA_MIN}_eta_{ETA_MAX}.png",
0189 "{CAMPAIGN}/Final_Results/pi-/mom/mom_resol_{ETA_MIN}_eta_{ETA_MAX}.root",
0190 "{CAMPAIGN}/Final_Results/pi-/mom/hpulls_{ETA_MIN}_eta_{ETA_MAX}_pmax_0.5.png",
0191 "{CAMPAIGN}/Final_Results/pi-/mom/hpulls_{ETA_MIN}_eta_{ETA_MAX}_pmax_0.5.root",
0192 "{CAMPAIGN}/Final_Results/pi-/mom/hpulls_{ETA_MIN}_eta_{ETA_MAX}_pmax_1.0.png",
0193 "{CAMPAIGN}/Final_Results/pi-/mom/hpulls_{ETA_MIN}_eta_{ETA_MAX}_pmax_1.0.root",
0194 "{CAMPAIGN}/Final_Results/pi-/mom/hpulls_{ETA_MIN}_eta_{ETA_MAX}_pmax_2.0.png",
0195 "{CAMPAIGN}/Final_Results/pi-/mom/hpulls_{ETA_MIN}_eta_{ETA_MAX}_pmax_2.0.root",
0196 "{CAMPAIGN}/Final_Results/pi-/mom/hpulls_{ETA_MIN}_eta_{ETA_MAX}_pmax_20.0.png",
0197 "{CAMPAIGN}/Final_Results/pi-/mom/hpulls_{ETA_MIN}_eta_{ETA_MAX}_pmax_20.0.root",
0198 "{CAMPAIGN}/Final_Results/pi-/dca/dcaxy_resol_{ETA_MIN}_eta_{ETA_MAX}.png",
0199 "{CAMPAIGN}/Final_Results/pi-/dca/dcaxy_resol_{ETA_MIN}_eta_{ETA_MAX}.root",
0200 "{CAMPAIGN}/Final_Results/pi-/dca/dcaz_resol_{ETA_MIN}_eta_{ETA_MAX}.png",
0201 "{CAMPAIGN}/Final_Results/pi-/dca/dcaz_resol_{ETA_MIN}_eta_{ETA_MAX}.root",
0202 shell:
0203 r"""
0204 if [[ "{wildcards.CAMPAIGN}" == "local" ]]; then
0205 set +e
0206 EPIC_VERSION="${{DETECTOR_VERSION:-}}"
0207 EICRECON_VERSION="$(eicrecon -v | sed -n -e 's/.*\(v[0-9\.]\+\).*/\\1/p')"
0208 # Legacy detection
0209 : ${{EPIC_VERSION:="$(echo $DETECTOR_PATH | sed -n -e 's/.*epic-\([^-/]\+\).*/\\1/p')"}}
0210 set -e
0211
0212 echo "ePIC version: $EPIC_VERSION"
0213 echo "EICrecon version: $EICRECON_VERSION"
0214 EXTRA_LEGEND="ePIC $EPIC_VERSION / EICrecon $EICRECON_VERSION"
0215 else
0216 EXTRA_LEGEND="ePIC Simulation {wildcards.CAMPAIGN}"
0217 fi
0218 cd {wildcards.CAMPAIGN}
0219 root -l -b -q ../{input.script_mom}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, 1., true, "'"$EXTRA_LEGEND"'")'
0220 root -l -b -q ../{input.script_pulls}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX})'
0221 root -l -b -q ../{input.script_dcaT}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, true, "'"$EXTRA_LEGEND"'")'
0222 root -l -b -q ../{input.script_dcaz}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, true, "'"$EXTRA_LEGEND"'")'
0223 """
0224
0225
0226 rule tracking_performance_debug_montage:
0227 input:
0228 expand(
0229 [
0230 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/mom/{SEEDING}_mom_resol_mom{MOMENTUM:.1f}_{{ETA_BIN}}.png",
0231 ],
0232 MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0233 SEEDING=["truth", "real"],
0234 ),
0235 output:
0236 "{CAMPAIGN}/Debug_Plots/pi-/mom/mom_resol_debug_{ETA_BIN}.png",
0237 shell:
0238 """
0239 montage -mode concatenate {input} {output} || true
0240 ls {output}
0241 """
0242
0243
0244 TRACKING_PERFORMANCE_ETA_BINS = [-3.5, -2.5, -1.0, 1.0, 2.5, 3.5]
0245
0246 rule tracking_performance:
0247 input:
0248 expand(
0249 [
0250 "{{CAMPAIGN}}/Final_Results/pi-/mom/mom_resol_{ETA_BIN}.png",
0251 "{{CAMPAIGN}}/Final_Results/pi-/mom/mom_resol_{ETA_BIN}.root",
0252 "{{CAMPAIGN}}/Final_Results/pi-/mom/hpulls_{ETA_BIN}_pmax_{PMAX}.png",
0253 "{{CAMPAIGN}}/Final_Results/pi-/mom/hpulls_{ETA_BIN}_pmax_{PMAX}.root",
0254 "{{CAMPAIGN}}/Debug_Plots/pi-/mom/mom_resol_debug_{ETA_BIN}.png",
0255 ],
0256 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:])],
0257 PMAX=["0.5","1.0","2.0","20.0"],
0258 ),
0259 lambda wildcards: branch(
0260 wildcards.CAMPAIGN == "local",
0261 then=[
0262 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsxy_dd4hep.png",
0263 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsxy_dd4hep.root",
0264 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsrz_dd4hep.png",
0265 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsrz_dd4hep.root",
0266 "local/epic_craterlake_tracking_only/pi-/1GeV/Nhits_vs_eta.png",
0267 "local/epic_craterlake_tracking_only/pi-/1GeV/Nhits_vs_eta.root",
0268 ],
0269 otherwise=[],
0270 )
0271 output:
0272 directory("results/tracking_performances/{CAMPAIGN}/")
0273 shell:
0274 """
0275 mkdir {output}
0276 cp {input} {output}
0277 """
0278
0279
0280 rule tracking_performance_local:
0281 input:
0282 "results/tracking_performances/local",
0283
0284
0285 rule tracking_performance_campaigns:
0286 input:
0287 expand(
0288 "results/tracking_performances/{CAMPAIGN}",
0289 CAMPAIGN=[
0290 "25.07.0",
0291 "25.08.0",
0292 "25.10.4",
0293 ],
0294 )