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=ancient("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         warmup=ancient("warmup/{DETECTOR_CONFIG}.edm4hep.root"),
0042     output:
0043         "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root",
0044     log:
0045         "sim_output/lfhcal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root.log",
0046     wildcard_constraints:
0047         INDEX=r"\d{4}",
0048     shell: """
0049 env DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
0050   eicrecon {input} -Ppodio:output_file={output} \
0051   -Ppodio:output_collections=MCParticles,ReconstructedParticles,LFHCALTruthClusters,LFHCALClusters,LFHCALHits,EcalEndcapPTruthClusters,EcalEndcapPClusters,EcalEndcapPHits
0052 """
0053 
0054 rule lfhcal_at_momentum:
0055     input:
0056         script="benchmarks/lfhcal/LFHCAL_Performance.C",
0057         # TODO pass as a file list?
0058         sim=lambda wildcards:
0059           expand(
0060               "sim_output/lfhcal/{DETECTOR_CONFIG}/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.edm4eic.root",
0061               DETECTOR_CONFIG="epic_craterlake",
0062               ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0063               PHASE_SPACE=["3to50deg"],
0064               INDEX=range(1),
0065           )
0066           if wildcards.CAMPAIGN == "local" else
0067           ancient(expand(
0068               "EPIC/RECO/{{CAMPAIGN}}/epic_craterlake/SINGLE/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon{TREE_SUFFIX}.edm4eic.root",
0069               DETECTOR_CONFIG="epic_craterlake",
0070               ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
0071               PHASE_SPACE=["3to50deg"],
0072               INDEX=range(1),
0073               TREE_SUFFIX=".tree" if int(wildcards.CAMPAIGN[:2]) < 25 else "", # backwards compatibility
0074           )),
0075     output:
0076         "{CAMPAIGN}/{PARTICLE}/mom/lfhcal_mom_{MOMENTUM}_mom_resol_{PARTICLE}.root",
0077         combined_root=temp("{CAMPAIGN}/lfhcal_sim_{MOMENTUM}_{PARTICLE}.root"),
0078     shell:
0079         """
0080 hadd {output.combined_root} {input.sim}
0081 cd {wildcards.CAMPAIGN}
0082 root -l -b -q ../{input.script}'("../{output.combined_root}", "{wildcards.PARTICLE}", {wildcards.MOMENTUM}, 0.15)'
0083 """
0084 
0085 rule lfhcal_summary_at_eta:
0086     input:
0087         expand(
0088             [
0089                 "{{CAMPAIGN}}/{{PARTICLE}}/mom/lfhcal_mom_{MOMENTUM:.1f}_mom_resol_{{PARTICLE}}.root",
0090             ],
0091             MOMENTUM=[0.5, 1.0, 2.0, 5.0, 10.0, 20.0],
0092         ),
0093         script="benchmarks/lfhcal/doCompare_widebins_mom.C",
0094     output:
0095         "{CAMPAIGN}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_MIN}_eta_{ETA_MAX}.png",
0096         "{CAMPAIGN}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_MIN}_eta_{ETA_MAX}.root",
0097     shell:
0098         r"""
0099 if [[ "{wildcards.CAMPAIGN}" == "local" ]]; then
0100         set +e
0101         EPIC_VERSION="${{DETECTOR_VERSION:-}}"
0102         EICRECON_VERSION="$(eicrecon -v | sed -n -e 's/.*\(v[0-9\.]\+\).*/\\1/p')"
0103         # Legacy detection
0104         : ${{EPIC_VERSION:="$(echo $DETECTOR_PATH | sed -n -e 's/.*epic-\([^-/]\+\).*/\\1/p')"}}
0105         set -e
0106 
0107         echo "ePIC version: $EPIC_VERSION"
0108         echo "EICrecon version: $EICRECON_VERSION"
0109         EXTRA_LEGEND="ePIC $EPIC_VERSION / EICrecon $EICRECON_VERSION"
0110 else
0111         EXTRA_LEGEND="ePIC Simulation {wildcards.CAMPAIGN}"
0112 fi
0113 cd {wildcards.CAMPAIGN}
0114 root -l -b -q ../{input.script}'("{wildcards.PARTICLE}", {wildcards.ETA_MIN}, {wildcards.ETA_MAX}, 1., true, "'"$EXTRA_LEGEND"'")'
0115 """
0116 
0117 LFHCAL_ETA_BINS = [1.2,1.5,2,2.5,3,3.5]
0118 
0119 rule lfhcal:
0120     input:
0121         lambda wildcards: expand(
0122             [
0123               "{{CAMPAIGN}}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_BIN}.png",
0124               "{{CAMPAIGN}}/Final_Results/{PARTICLE}/mom/lfhcal_mom_resol_{PARTICLE}_{ETA_BIN}.root",
0125             ],
0126             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:])],
0127             PARTICLE=["neutron", "pi-", "gamma"] if wildcards.CAMPAIGN == "local" else ["pi-"],
0128         )
0129     output:
0130         directory("results/lfhcal/{CAMPAIGN}/")
0131     shell:
0132         """
0133 mkdir {output}
0134 cp {input} {output}
0135 """
0136 
0137 
0138 rule lfhcal_local:
0139     input:
0140         "results/lfhcal/local",
0141 
0142 
0143 rule lfhcal_campaigns:
0144     input:
0145         expand(
0146             "results/lfhcal/{CAMPAIGN}",
0147             CAMPAIGN=[
0148                 "24.10.1",
0149             ],
0150         )