Back to home page

EIC code displayed by LXR

 
 

    


Warning, /detector_benchmarks/benchmarks/backwards_ecal/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 if wildcards.PARTICLE == "e-" else 2000
0004     n_events = int(n_events // (energy ** 0.75))
0005     return n_events
0006 
0007 
0008 rule backwards_ecal_sim:
0009     input:
0010         steering_file=ancient("EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer"),
0011         warmup="warmup.edm4hep.root",
0012         geometry_lib=find_epic_libraries(),
0013     output:
0014         "sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.rnt.root",
0015     log:
0016         "logs/sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.rnt.root.log",
0017     wildcard_constraints:
0018         PARTICLE="(e-|pi-)",
0019         ENERGY="[0-9]+[kMG]eV",
0020         PHASE_SPACE="(3to50|45to135|130to177)deg",
0021         INDEX=r"\d{4}",
0022     params:
0023         N_EVENTS=get_n_events,
0024         SEED=lambda wildcards: "1" + wildcards.INDEX,
0025         DETECTOR_PATH=os.environ["DETECTOR_PATH"],
0026         DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0027         DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0028         NPSIM_HASH=get_spack_package_hash("npsim"),
0029     cache: True
0030     singularity: EIC_SINGULARITY_CONTAINER,
0031     shell:
0032         """
0033 set -m # monitor mode to prevent lingering processes
0034 set -o pipefail
0035 exec npsim \
0036   --runType batch \
0037   --enableGun \
0038   --steeringFile "{input.steering_file}" \
0039   --random.seed {params.SEED} \
0040   --filter.tracker edep0 \
0041   -v WARNING \
0042   --numberOfEvents {params.N_EVENTS} \
0043   --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}.xml \
0044   --outputFile {output} \
0045   --outputConfig.useRNTuple true | tee {log}
0046 """
0047 
0048 
0049 rule backwards_ecal_recon:
0050     input:
0051         sim="sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.rnt.root",
0052         warmup="warmup.edm4hep.root",
0053     output:
0054         "sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root",
0055     log:
0056         "logs/sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.edm4eic.root.log",
0057     wildcard_constraints:
0058         INDEX=r"\d{4}",
0059     params:
0060         DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0061         EICRECON_HASH=get_spack_package_hash("eicrecon"),
0062     cache: True
0063     singularity: EIC_SINGULARITY_CONTAINER,
0064     shell: """
0065 set -m # monitor mode to prevent lingering processes
0066 exec env DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
0067   eicrecon {input.sim} -Ppodio:output_file={output} \
0068   -Ppodio:output_collections=MCParticles,EcalEndcapNRecHits,EcalEndcapNClusters | tee {log}
0069 """
0070 
0071 
0072 rule backwards_ecal_dis_recon:
0073     input:
0074         # Reuse the centrally defined DIS simulation from the tracking benchmark.
0075         sim="sim_output/tracking_performances_dis/{DETECTOR_CONFIG}/pythia8NCDIS_{EBEAM}x{PBEAM}_minQ2={MINQ2}_beamEffects_xAngle=-0.025_hiDiv_{INDEX}.edm4hep.root",
0076         warmup="warmup.edm4hep.root",
0077     output:
0078         "sim_output/backwards_ecal_dis/{DETECTOR_CONFIG}/pythia8NCDIS_{EBEAM}x{PBEAM}_minQ2={MINQ2}_beamEffects_xAngle=-0.025_hiDiv_{INDEX}.edm4eic.root",
0079     log:
0080         "logs/sim_output/backwards_ecal_dis/{DETECTOR_CONFIG}/pythia8NCDIS_{EBEAM}x{PBEAM}_minQ2={MINQ2}_beamEffects_xAngle=-0.025_hiDiv_{INDEX}.edm4eic.root.log",
0081     wildcard_constraints:
0082         EBEAM=r"\d+",
0083         PBEAM=r"\d+",
0084         MINQ2=r"\d+",
0085         INDEX=r"\d+",
0086     params:
0087         DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0088         EICRECON_HASH=get_spack_package_hash("eicrecon"),
0089     cache: True
0090     singularity: EIC_SINGULARITY_CONTAINER,
0091     shell:
0092         """
0093 set -m # monitor mode to prevent lingering processes
0094 set -o pipefail
0095 exec env DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
0096   eicrecon {input.sim} -Ppodio:output_file={output} \
0097   -Ppodio:output_collections=MCParticles,MCScatteredElectrons,EcalEndcapNClusters \
0098   | tee {log}
0099 """
0100 
0101 
0102 rule backwards_ecal_dis_local_sim_list:
0103     input:
0104         expand(
0105             "sim_output/backwards_ecal_dis/{{DETECTOR_CONFIG}}/pythia8NCDIS_{{EBEAM}}x{{PBEAM}}_minQ2={{MINQ2}}_beamEffects_xAngle=-0.025_hiDiv_{INDEX}.edm4eic.root",
0106             INDEX=range(1, 6),
0107         ),
0108     output:
0109         "listing/backwards_ecal_dis/local/{DETECTOR_CONFIG}/{EBEAM}x{PBEAM}/minQ2={MINQ2}.lst",
0110     run:
0111         with open(output[0], "wt") as fp:
0112             fp.write("\n".join(input) + "\n")
0113 
0114 
0115 rule backwards_ecal_local_sim_list:
0116     input:
0117         expand(
0118             "sim_output/backwards_ecal/{{DETECTOR_CONFIG}}/{{PARTICLE}}/{{ENERGY}}/{{PHASE_SPACE}}/{{PARTICLE}}_{{ENERGY}}_{{PHASE_SPACE}}.{INDEX:04d}.eicrecon.edm4eic.root",
0119             INDEX=range(20),
0120         ),
0121     output:
0122         "listing/backwards_ecal/local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst",
0123     run:
0124         with open(output[0], "wt") as fp:
0125             fp.write("\n".join(input))
0126 
0127 
0128 if config.get("stream_from_xrootd", True) not in [False, "", "0", "false"]:
0129     rule backwards_ecal_campaign_sim_list:
0130         output:
0131             "listing/backwards_ecal/{CAMPAIGN}/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst",
0132         params:
0133             search_path=lambda wildcards: f"EPIC/RECO/{wildcards.CAMPAIGN}/epic_craterlake/SINGLE/{wildcards.PARTICLE}/{wildcards.ENERGY}/{wildcards.PHASE_SPACE}/",
0134         singularity: EIC_SINGULARITY_CONTAINER,
0135         shell: """
0136     xrdfs root://dtn-eic.jlab.org/ ls /volatile/eic/{params.search_path} \
0137       | awk '{{ print "root://dtn-eic.jlab.org/"$1; }}' \
0138       | sort \
0139       > {output}
0140     if [ ! -s {output} ]; then
0141       echo "Got an empty file listing for path \"\""
0142       exit 1
0143     fi
0144     """
0145 else:
0146     checkpoint backwards_ecal_campaign_sim_list_checkpoint:
0147         output:
0148             "listing/backwards_ecal/{CAMPAIGN}/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst.orig",
0149         params:
0150             search_path=lambda wildcards: f"EPIC/RECO/{wildcards.CAMPAIGN}/epic_craterlake/SINGLE/{wildcards.PARTICLE}/{wildcards.ENERGY}/{wildcards.PHASE_SPACE}/",
0151         singularity: EIC_SINGULARITY_CONTAINER,
0152         shell: """
0153     xrdfs root://dtn-eic.jlab.org/ ls /volatile/eic/{params.search_path} \
0154       | sed -e 's#^/volatile/eic/##' \
0155       | sort \
0156       > {output}
0157     if [ ! -s {output} ]; then
0158       echo "Got an empty file listing for path \"\""
0159       exit 1
0160     fi
0161     """
0162 
0163     def get_backwards_ecal_campaign_sim_list(wildcards):
0164         with checkpoints.backwards_ecal_campaign_sim_list_checkpoint.get(**wildcards).output[0].open() as fp:
0165             return [line.rstrip() for line in fp.readlines()]
0166 
0167     rule backwards_ecal_campaign_sim_list:
0168         input:
0169             # depend on paths from the file list
0170             get_backwards_ecal_campaign_sim_list,
0171             orig_list="listing/backwards_ecal/{CAMPAIGN}/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst.orig",
0172         output:
0173             "listing/backwards_ecal/{CAMPAIGN}/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst",
0174         shell: """
0175     cp {input.orig_list} {output}
0176     """
0177 
0178 
0179 ruleorder: backwards_ecal_local_sim_list > backwards_ecal_campaign_sim_list
0180 
0181 
0182 DETECTOR_CONFIG=os.environ["DETECTOR_CONFIG"]
0183 
0184 rule backwards_ecal:
0185     input:
0186         expand(
0187             "listing/backwards_ecal/{{CAMPAIGN}}/" + DETECTOR_CONFIG + "/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst",
0188             PARTICLE=["pi-", "e-"],
0189             ENERGY=[
0190                 "100MeV",
0191                 "200MeV",
0192                 "500MeV",
0193                 "1GeV",
0194                 "2GeV",
0195                 "5GeV",
0196                 "10GeV",
0197                 "20GeV",
0198             ],
0199             PHASE_SPACE=["130to177deg"],
0200         ),
0201         matplotlibrc=".matplotlibrc",
0202         script="benchmarks/backwards_ecal/backwards_ecal.org2py.py",
0203     output:
0204         directory("results/backwards_ecal/{CAMPAIGN}/")
0205     log:
0206         scheduler=".logs/results/backwards_ecal/{CAMPAIGN}/scheduler.log",
0207         worker=".logs/results/backwards_ecal/{CAMPAIGN}/worker.log",
0208     threads: workflow.cores
0209     singularity: EIC_SINGULARITY_CONTAINER,
0210     shell:
0211         """
0212 if [[ "{wildcards.CAMPAIGN}" == "local" ]]; then
0213 export PLOT_TITLE="Benchmark simulation"
0214 else
0215 export PLOT_TITLE="\\textbf{{ePIC}} Simulation {wildcards.CAMPAIGN}"
0216 fi
0217 
0218 set -m # monitor mode to prevent lingering processes
0219 cleanup() {{
0220   echo Cleaning up
0221   kill $WORKER_PID $SCHEDULER_PID
0222 }}
0223 trap cleanup EXIT
0224 
0225 PORT=$RANDOM
0226 dask scheduler --port $PORT 2>{log.scheduler} &
0227 export DASK_SCHEDULER=localhost:$PORT
0228 SCHEDULER_PID=$!
0229 dask worker tcp://$DASK_SCHEDULER --nworkers {threads} --nthreads 1 2>{log.worker} &
0230 WORKER_PID=$!
0231 env \
0232 MATPLOTLIBRC={input.matplotlibrc} \
0233 DETECTOR_CONFIG=""" + DETECTOR_CONFIG + """ \
0234 INPUT_PATH_FORMAT=listing/backwards_ecal/{wildcards.CAMPAIGN}/""" + DETECTOR_CONFIG + """/{{particle}}/{{energy}}/130to177deg.lst \
0235 OUTPUT_DIR={output} \
0236 python {input.script}
0237 """
0238 
0239 
0240 rule backwards_ecal_dis:
0241     input:
0242         file_list="listing/backwards_ecal_dis/{CAMPAIGN}/" + DETECTOR_CONFIG + "/{EBEAM}x{PBEAM}/minQ2={MINQ2}.lst",
0243         matplotlibrc=".matplotlibrc",
0244         script="benchmarks/backwards_ecal/backwards_ecal_dis.org2py.py",
0245     output:
0246         directory("results/backwards_ecal_dis/{CAMPAIGN}/{EBEAM}x{PBEAM}/minQ2={MINQ2}"),
0247     wildcard_constraints:
0248         EBEAM=r"\d+",
0249         PBEAM=r"\d+",
0250         MINQ2=r"\d+",
0251     singularity: EIC_SINGULARITY_CONTAINER,
0252     shell:
0253         """
0254 env \
0255   MATPLOTLIBRC={input.matplotlibrc} \
0256   INPUT_FILE_LIST={input.file_list} \
0257   OUTPUT_DIR={output} \
0258   SAMPLE_LABEL="ePIC DIS {wildcards.EBEAM}x{wildcards.PBEAM} GeV, min Q2={wildcards.MINQ2} GeV2" \
0259   python {input.script}
0260 """
0261 
0262 
0263 rule backwards_ecal_dis_run_locally:
0264     input:
0265         "results/backwards_ecal_dis/local/10x100/minQ2=1",
0266     message:
0267         "See output in {input[0]}"