Back to home page

EIC code displayed by LXR

 
 

    


Warning, /detector_benchmarks/benchmarks/lfhcal/Snakefile is written in an unsupported language. File is not indexed.

0001 def get_n_events(wildcards):
0002     energy = float(wildcards.ENERGY.replace("GeV", "").replace("MeV", "e-3"))
0003     n_events = 1000
0004     n_events = int(n_events // (energy ** 0.5))
0005     return n_events
0006 
0007 
0008 rule lfhcal_sim:
0009     input:
0010         steering_file="EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer",
0011         warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
0012     output:
0013         "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0014     log:
0015         "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root.log",
0016     wildcard_constraints:
0017         ENERGY="[0-9]+[kMG]eV",
0018         PARTICLE="(neutron|pi-|gamma)",
0019         PHASE_SPACE="3to50deg",
0020         INDEX=r"\d{4}",
0021     params:
0022         N_EVENTS=get_n_events,
0023     shell:
0024         """
0025 ddsim \
0026   --runType batch \
0027   --enableGun \
0028   --steeringFile "{input.steering_file}" \
0029   --random.seed 1{wildcards.INDEX} \
0030   --filter.tracker edep0 \
0031   -v INFO \
0032   --numberOfEvents {params.N_EVENTS} \
0033   --compactFile $DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml \
0034   --outputFile {output}
0035 """
0036 
0037 
0038 rule lfhcal_recon:
0039     input:
0040         "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0041     output:
0042         "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root",
0043     log:
0044         "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root.log",
0045     wildcard_constraints:
0046         INDEX=r"\d{4}",
0047     shell: """
0048 env DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
0049   eicrecon {input} -Ppodio:output_file={output} \
0050   -Ppodio:output_collections=MCParticles,ReconstructedParticles,LFHCALTruthClusters,LFHCALClusters,LFHCALHits,EcalEndcapPTruthClusters,EcalEndcapPClusters,EcalEndcapPHits
0051 """
0052 
0053 rule lfhcal_at_momentum:
0054     input:
0055         script="benchmarks/lfhcal/LFHCAL_Performance.C",
0056         # TODO pass as a file list?
0057         sim=lambda wildcards:
0058           expand(
0059               "sim_output/lfhcal/{DETECTOR_CONFIG}/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.edm4eic.root",
0060               DETECTOR_CONFIG="epic_craterlake",
0061               ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0062               PHASE_SPACE=["3to50deg"],
0063               INDEX=range(1),
0064           )
0065           if wildcards.CAMPAIGN == "local" else
0066           ancient(expand(
0067               "EPIC/RECO/{{CAMPAIGN}}/epic_craterlake/SINGLE/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon{TREE_SUFFIX}.edm4eic.root",
0068               DETECTOR_CONFIG="epic_craterlake",
0069               ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0070               PHASE_SPACE=["3to50deg"],
0071               INDEX=range(1),
0072               TREE_SUFFIX=".tree" if int(wildcards.CAMPAIGN[:2]) < 25 else "", # backwards compatibility
0073           )),
0074     output:
0075         "{CAMPAIGN}/{PARTICLE}/mom/lfhcal_mom_{MOMENTUM}_mom_resol_{PARTICLE}.root",
0076         combined_root=temp("{CAMPAIGN}/lfhcal_sim_{MOMENTUM}_{PARTICLE}.root"),
0077     shell:
0078         """
0079 hadd {output.combined_root} {input.sim}
0080 cd {wildcards.CAMPAIGN}
0081 root -l -b -q ../{input.script}'("../{output.combined_root}", "{wildcards.PARTICLE}", {wildcards.MOMENTUM}, 0.15)'
0082 """
0083 
0084 rule lfhcal_summary_at_eta:
0085     input:
0086         expand(
0087             [
0088                 "{{CAMPAIGN}}/{{PARTICLE}}/mom/lfhcal_mom_{MOMENTUM:.1f}_mom_resol_{{PARTICLE}}.root",
0089             ],
0090             MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0091         ),
0092         script="benchmarks/lfhcal/doCompare_widebins_mom.C",
0093     output:
0094         "{CAMPAIGN}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_MIN}_eta_{ETA_MAX}.png",
0095         "{CAMPAIGN}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_MIN}_eta_{ETA_MAX}.root",
0096     shell:
0097         r"""
0098 if [[ "{wildcards.CAMPAIGN}" == "local" ]]; then
0099         set +e
0100         EPIC_VERSION="${{DETECTOR_VERSION:-}}"
0101         EICRECON_VERSION="$(eicrecon -v | sed -n -e 's/.*\(v[0-9\.]\+\).*/\\1/p')"
0102         # Legacy detection
0103         : ${{EPIC_VERSION:="$(echo $DETECTOR_PATH | sed -n -e 's/.*epic-\([^-/]\+\).*/\\1/p')"}}
0104         set -e
0105 
0106         echo "ePIC version: $EPIC_VERSION"
0107         echo "EICrecon version: $EICRECON_VERSION"
0108         EXTRA_LEGEND="ePIC $EPIC_VERSION / EICrecon $EICRECON_VERSION"
0109 else
0110         EXTRA_LEGEND="ePIC Simulation {wildcards.CAMPAIGN}"
0111 fi
0112 cd {wildcards.CAMPAIGN}
0113 root -l -b -q ../{input.script}'("{wildcards.PARTICLE}", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, 1., true, "'"$EXTRA_LEGEND"'")'
0114 """
0115 
0116 LFHCAL_ETA_BINS = [1.2,1.5,2,2.5,3,3.5]
0117 
0118 rule lfhcal:
0119     input:
0120         lambda wildcards: expand(
0121             [
0122               "{{CAMPAIGN}}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_BIN}.png",
0123               "{{CAMPAIGN}}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_BIN}.root",
0124             ],
0125             ETA_BIN=[f"{eta_min:.1f}_eta_{eta_max:.1f}" for eta_min, eta_max in zip(LFHCAL_ETA_BINS[:-1], LFHCAL_ETA_BINS[1:])],
0126             PARTICLE=["neutron", "pi-", "gamma"] if wildcards.CAMPAIGN == "local" else ["pi-"],
0127         )
0128     output:
0129         directory("results/lfhcal/{CAMPAIGN}/")
0130     shell:
0131         """
0132 mkdir {output}
0133 cp {input} {output}
0134 """
0135 
0136 
0137 rule lfhcal_local:
0138     input:
0139         "results/lfhcal/local",
0140 
0141 
0142 rule lfhcal_campaigns:
0143     input:
0144         expand(
0145             "results/lfhcal/{CAMPAIGN}",
0146             CAMPAIGN=[
0147                 "24.10.1",
0148             ],
0149         )