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