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     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 
0068 rule tracking_performance_at_momentum:
0069     input:
0070         script="benchmarks/tracking_performances/Tracking_Performances.C",
0071         # TODO pass as a file list?
0072         sim=lambda wildcards:
0073           expand(
0074               "sim_output/tracking_performance/{DETECTOR_CONFIG}/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.edm4eic.root",
0075               DETECTOR_CONFIG="epic_craterlake_tracking_only",
0076               ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0077               PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0078               INDEX=range(1),
0079           )
0080           if wildcards.CAMPAIGN == "local" else
0081           ancient(expand(
0082               "EPIC/RECO/{{CAMPAIGN}}/epic_craterlake/SINGLE/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon{TREE_SUFFIX}.edm4eic.root",
0083               DETECTOR_CONFIG="epic_craterlake",
0084               ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0085               PHASE_SPACE=["3to50deg", "45to135deg", "130to177deg"],
0086               INDEX=range(1),
0087               TREE_SUFFIX=".tree" if int(wildcards.CAMPAIGN[:2]) < 25 else "", # backwards compatibility
0088           )),
0089     output:
0090         "{CAMPAIGN}/{SEEDING}/pi-/mom/Performances_mom_{MOMENTUM}_mom_resol_{SEEDING_IGNORE}_{PARTICLE}.root",
0091         "{CAMPAIGN}/{SEEDING}/pi-/dca/Performances_dca_{MOMENTUM}_dca_resol_{SEEDING_IGNORE}_{PARTICLE}.root",
0092         combined_root=temp("{CAMPAIGN}/sim_{SEEDING}_{MOMENTUM}_{SEEDING_IGNORE}_{PARTICLE}.root"),
0093     shell:
0094         """
0095 if [[ "{wildcards.SEEDING}" == "truthseed" ]]; then
0096         TRUTH_SEEDING="true"
0097 elif [[ "{wildcards.SEEDING}" == "realseed" ]]; then
0098         TRUTH_SEEDING="false"
0099 fi
0100 hadd {output.combined_root} {input.sim}
0101 cd {wildcards.CAMPAIGN}
0102 root -l -b -q ../{input.script}'("../{output.combined_root}", "{wildcards.PARTICLE}", {wildcards.MOMENTUM}, 0.15, '$TRUTH_SEEDING')'
0103 """
0104 
0105 
0106 rule tracking_performance_hadd_final_hist_dca:
0107     input:
0108         lambda wildcards: expand(
0109             [
0110                 "{{CAMPAIGN}}/{{SEEDING}}/pi-/dca/Performances_dca_{MOMENTUM:.1f}_dca_resol_{SEEDING_ALT}_pi-.root",
0111             ],
0112             MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0113             SEEDING_ALT={"truthseed": "truth", "realseed": "realseed"}[wildcards.SEEDING],
0114         ),
0115     output:
0116         "{CAMPAIGN}/{SEEDING}/pi-/dca/final_hist_dca_{SEEDING}.root",
0117     shell:
0118         """
0119 hadd -f {output} {input}
0120 """
0121 
0122 
0123 rule tracking_performance_summary_at_eta:
0124     input:
0125         expand(
0126             [
0127                 "{{CAMPAIGN}}/truthseed/pi-/mom/Performances_mom_{MOMENTUM:.1f}_mom_resol_truth_pi-.root",
0128                 "{{CAMPAIGN}}/truthseed/pi-/dca/Performances_dca_{MOMENTUM:.1f}_dca_resol_truth_pi-.root",
0129                 "{{CAMPAIGN}}/realseed/pi-/mom/Performances_mom_{MOMENTUM:.1f}_mom_resol_realseed_pi-.root",
0130                 "{{CAMPAIGN}}/realseed/pi-/dca/Performances_dca_{MOMENTUM:.1f}_dca_resol_realseed_pi-.root",
0131             ],
0132             MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0133         ),
0134         "{CAMPAIGN}/truthseed/pi-/dca/final_hist_dca_truthseed.root",
0135         "{CAMPAIGN}/realseed/pi-/dca/final_hist_dca_realseed.root",
0136         script_mom="benchmarks/tracking_performances/doCompare_truth_real_widebins_mom.C",
0137         script_dcaT="benchmarks/tracking_performances/doCompare_truth_real_widebins_dcaT.C",
0138         script_dcaz="benchmarks/tracking_performances/doCompare_truth_real_widebins_dcaz.C",
0139     output:
0140         expand(
0141             "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/mom/{SEEDING}_mom_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0142             SEEDING=["real", "truth"],
0143             MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0144         ),
0145         expand(
0146             "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/dca/{SEEDING}_dcaxy_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0147             SEEDING=["real", "truth"],
0148             MOMENTUM=[0.2, 0.3, 0.5,1.0, 1.5, 2.0, 5.0, 8.0, 10., 15.0],
0149         ),
0150         expand(
0151             "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/dca/{SEEDING}_dcaz_resol_mom{MOMENTUM:.1f}_{{ETA_MIN}}_eta_{{ETA_MAX}}.png",
0152             SEEDING=["real", "truth"],
0153             MOMENTUM=[0.2, 0.3, 0.5,1.0, 1.5, 2.0, 5.0, 8.0, 10., 15.0],
0154         ),
0155         "{CAMPAIGN}/Final_Results/pi-/mom/mom_resol_{ETA_MIN}_eta_{ETA_MAX}.png",
0156         "{CAMPAIGN}/Final_Results/pi-/mom/mom_resol_{ETA_MIN}_eta_{ETA_MAX}.root",
0157         "{CAMPAIGN}/Final_Results/pi-/dca/dcaxy_resol_{ETA_MIN}_eta_{ETA_MAX}.png", 
0158         "{CAMPAIGN}/Final_Results/pi-/dca/dcaxy_resol_{ETA_MIN}_eta_{ETA_MAX}.root", 
0159         "{CAMPAIGN}/Final_Results/pi-/dca/dcaz_resol_{ETA_MIN}_eta_{ETA_MAX}.png", 
0160         "{CAMPAIGN}/Final_Results/pi-/dca/dcaz_resol_{ETA_MIN}_eta_{ETA_MAX}.root",    
0161     shell:
0162         r"""
0163 if [[ "{wildcards.CAMPAIGN}" == "local" ]]; then
0164         set +e
0165         EPIC_VERSION="${{DETECTOR_VERSION:-}}"
0166         EICRECON_VERSION="$(eicrecon -v | sed -n -e 's/.*\(v[0-9\.]\+\).*/\\1/p')"
0167         # Legacy detection
0168         : ${{EPIC_VERSION:="$(echo $DETECTOR_PATH | sed -n -e 's/.*epic-\([^-/]\+\).*/\\1/p')"}}
0169         set -e
0170 
0171         echo "ePIC version: $EPIC_VERSION"
0172         echo "EICrecon version: $EICRECON_VERSION"
0173         EXTRA_LEGEND="ePIC $EPIC_VERSION / EICrecon $EICRECON_VERSION"
0174 else
0175         EXTRA_LEGEND="ePIC Simulation {wildcards.CAMPAIGN}"
0176 fi
0177 cd {wildcards.CAMPAIGN}
0178 root -l -b -q ../{input.script_mom}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, 1., true, "'"$EXTRA_LEGEND"'")'
0179 root -l -b -q ../{input.script_dcaT}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, true, "'"$EXTRA_LEGEND"'")'
0180 root -l -b -q ../{input.script_dcaz}'("pi-", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, true, "'"$EXTRA_LEGEND"'")'
0181 """
0182 
0183 
0184 rule tracking_performance_debug_montage:
0185     input:
0186         expand(
0187             [
0188                 "{{CAMPAIGN}}/Debug_Plots/{SEEDING}/pi-/mom/{SEEDING}_mom_resol_mom{MOMENTUM:.1f}_{{ETA_BIN}}.png",
0189             ],
0190             MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0191             SEEDING=["truth", "real"],
0192         ),
0193     output:
0194         "{CAMPAIGN}/Debug_Plots/pi-/mom/mom_resol_debug_{ETA_BIN}.png",
0195     shell:
0196         """
0197 montage -mode concatenate {input} {output} || true
0198 ls {output}
0199 """
0200 
0201 
0202 TRACKING_PERFORMANCE_ETA_BINS = [-3.5, -2.5, -1.0, 1.0, 2.5, 3.5]
0203 
0204 rule tracking_performance:
0205     input:
0206         expand(
0207             [
0208                 "{{CAMPAIGN}}/Final_Results/pi-/mom/mom_resol_{ETA_BIN}.png",
0209                 "{{CAMPAIGN}}/Final_Results/pi-/mom/mom_resol_{ETA_BIN}.root",
0210                 "{{CAMPAIGN}}/Debug_Plots/pi-/mom/mom_resol_debug_{ETA_BIN}.png",
0211             ],
0212             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:])],
0213         ),
0214     output:
0215         directory("results/tracking_performances/{CAMPAIGN}/")
0216     shell:
0217         """
0218 mkdir {output}
0219 cp {input} {output}
0220 """
0221 
0222 
0223 rule tracking_performance_local:
0224     input:
0225         "results/tracking_performances/local",
0226 
0227 
0228 rule tracking_performance_campaigns:
0229     input:
0230         expand(
0231             "results/tracking_performances/{CAMPAIGN}",
0232             CAMPAIGN=[
0233                 "24.10.1",
0234                 "25.04.1",
0235             ],
0236         )