Back to home page

EIC code displayed by LXR

 
 

    


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         warmup="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_dcaT="benchmarks/tracking_performances/doCompare_truth_real_widebins_dcaT.C",
0170         script_dcaz="benchmarks/tracking_performances/doCompare_truth_real_widebins_dcaz.C",
0171     output:
0172         expand(
0173             "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/mom/{SEEDING}_mom_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0174             SEEDING=["real", "truth"],
0175             MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0176         ),
0177         expand(
0178             "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/dca/{SEEDING}_dcaxy_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0179             SEEDING=["real", "truth"],
0180             MOMENTUM=[0.2, 0.3, 0.5,1.0, 1.5, 2.0, 5.0, 8.0, 10., 15.0],
0181         ),
0182         expand(
0183             "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/dca/{SEEDING}_dcaz_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         "{CAMPAIGN}/Final_Results/pi-/mom/mom_resol_{ETA_MIN}_eta_{ETA_MAX}.png",
0188         "{CAMPAIGN}/Final_Results/pi-/mom/mom_resol_{ETA_MIN}_eta_{ETA_MAX}.root",
0189         "{CAMPAIGN}/Final_Results/pi-/dca/dcaxy_resol_{ETA_MIN}_eta_{ETA_MAX}.png", 
0190         "{CAMPAIGN}/Final_Results/pi-/dca/dcaxy_resol_{ETA_MIN}_eta_{ETA_MAX}.root", 
0191         "{CAMPAIGN}/Final_Results/pi-/dca/dcaz_resol_{ETA_MIN}_eta_{ETA_MAX}.png", 
0192         "{CAMPAIGN}/Final_Results/pi-/dca/dcaz_resol_{ETA_MIN}_eta_{ETA_MAX}.root",    
0193     shell:
0194         r"""
0195 if [[ "{wildcards.CAMPAIGN}" == "local" ]]; then
0196         set +e
0197         EPIC_VERSION="${{DETECTOR_VERSION:-}}"
0198         EICRECON_VERSION="$(eicrecon -v | sed -n -e 's/.*\(v[0-9\.]\+\).*/\\1/p')"
0199         # Legacy detection
0200         : ${{EPIC_VERSION:="$(echo $DETECTOR_PATH | sed -n -e 's/.*epic-\([^-/]\+\).*/\\1/p')"}}
0201         set -e
0202 
0203         echo "ePIC version: $EPIC_VERSION"
0204         echo "EICrecon version: $EICRECON_VERSION"
0205         EXTRA_LEGEND="ePIC $EPIC_VERSION / EICrecon $EICRECON_VERSION"
0206 else
0207         EXTRA_LEGEND="ePIC Simulation {wildcards.CAMPAIGN}"
0208 fi
0209 cd {wildcards.CAMPAIGN}
0210 root -l -b -q ../{input.script_mom}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, 1., true, "'"$EXTRA_LEGEND"'")'
0211 root -l -b -q ../{input.script_dcaT}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, true, "'"$EXTRA_LEGEND"'")'
0212 root -l -b -q ../{input.script_dcaz}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, true, "'"$EXTRA_LEGEND"'")'
0213 """
0214 
0215 
0216 rule tracking_performance_debug_montage:
0217     input:
0218         expand(
0219             [
0220                 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/mom/{SEEDING}_mom_resol_mom{MOMENTUM:.1f}_{{ETA_BIN}}.png",
0221             ],
0222             MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0223             SEEDING=["truth", "real"],
0224         ),
0225     output:
0226         "{CAMPAIGN}/Debug_Plots/pi-/mom/mom_resol_debug_{ETA_BIN}.png",
0227     shell:
0228         """
0229 montage -mode concatenate {input} {output} || true
0230 ls {output}
0231 """
0232 
0233 
0234 TRACKING_PERFORMANCE_ETA_BINS = [-3.5, -2.5, -1.0, 1.0, 2.5, 3.5]
0235 
0236 rule tracking_performance:
0237     input:
0238         expand(
0239             [
0240                 "{{CAMPAIGN}}/Final_Results/pi-/mom/mom_resol_{ETA_BIN}.png",
0241                 "{{CAMPAIGN}}/Final_Results/pi-/mom/mom_resol_{ETA_BIN}.root",
0242                 "{{CAMPAIGN}}/Debug_Plots/pi-/mom/mom_resol_debug_{ETA_BIN}.png",
0243             ],
0244             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:])],
0245         ),
0246         lambda wildcards: branch(
0247             wildcards.CAMPAIGN == "local",
0248             then=[
0249                 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsxy_dd4hep.png",
0250                 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsxy_dd4hep.root",
0251                 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsrz_dd4hep.png",
0252                 "local/epic_craterlake_tracking_only/pi-/1GeV/hitsrz_dd4hep.root",
0253                 "local/epic_craterlake_tracking_only/pi-/1GeV/Nhits_vs_eta.png",
0254                 "local/epic_craterlake_tracking_only/pi-/1GeV/Nhits_vs_eta.root",
0255             ],
0256             otherwise=[],
0257         )
0258     output:
0259         directory("results/tracking_performances/{CAMPAIGN}/")
0260     shell:
0261         """
0262 mkdir {output}
0263 cp {input} {output}
0264 """
0265 
0266 
0267 rule tracking_performance_local:
0268     input:
0269         "results/tracking_performances/local",
0270 
0271 
0272 rule tracking_performance_campaigns:
0273     input:
0274         expand(
0275             "results/tracking_performances/{CAMPAIGN}",
0276             CAMPAIGN=[
0277                 "24.10.1",
0278                 "25.04.1",
0279             ],
0280         )