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