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.5))
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/{DETECTOR_CONFIG}.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.root",
0015 log:
0016 "sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.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 shell:
0031 """
0032 set -m # monitor mode to prevent lingering processes
0033 exec ddsim \
0034 --runType batch \
0035 --enableGun \
0036 --steeringFile "{input.steering_file}" \
0037 --random.seed {params.SEED} \
0038 --filter.tracker edep0 \
0039 -v WARNING \
0040 --numberOfEvents {params.N_EVENTS} \
0041 --compactFile {params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}.xml \
0042 --outputFile {output}
0043 """
0044
0045
0046 rule backwards_ecal_recon:
0047 input:
0048 "sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
0049 output:
0050 "sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.tree.edm4eic.root",
0051 log:
0052 "sim_output/backwards_ecal/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.tree.edm4eic.root.log",
0053 wildcard_constraints:
0054 INDEX=r"\d{4}",
0055 params:
0056 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0057 EICRECON_HASH=get_spack_package_hash("eicrecon"),
0058 cache: True
0059 shell: """
0060 set -m # monitor mode to prevent lingering processes
0061 exec env DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
0062 eicrecon {input} -Ppodio:output_file={output} \
0063 -Ppodio:output_collections=MCParticles,EcalEndcapNRecHits,EcalEndcapNClusters
0064 """
0065
0066
0067 rule backwards_ecal_local_sim_list:
0068 input:
0069 expand(
0070 "sim_output/backwards_ecal/{{DETECTOR_CONFIG}}/{{PARTICLE}}/{{ENERGY}}/{{PHASE_SPACE}}/{{PARTICLE}}_{{ENERGY}}_{{PHASE_SPACE}}.{INDEX:04d}.eicrecon.tree.edm4eic.root",
0071 INDEX=range(20),
0072 ),
0073 output:
0074 "listing/backwards_ecal/local/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst",
0075 run:
0076 with open(output[0], "wt") as fp:
0077 fp.write("\n".join(input))
0078
0079
0080 if config.get("stream_from_xrootd", True) not in [False, "", "0", "false"]:
0081 rule backwards_ecal_campaign_sim_list:
0082 output:
0083 "listing/backwards_ecal/{CAMPAIGN}/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst",
0084 params:
0085 search_path=lambda wildcards: f"EPIC/RECO/{wildcards.CAMPAIGN}/epic_craterlake/SINGLE/{wildcards.PARTICLE}/{wildcards.ENERGY}/{wildcards.PHASE_SPACE}/",
0086 shell: """
0087 xrdfs root://dtn-eic.jlab.org/ ls /work/eic2/{params.search_path} \
0088 | awk '{{ print "root://dtn-eic.jlab.org/"$1; }}' \
0089 | sort \
0090 > {output}
0091 if [ ! -s {output} ]; then
0092 echo "Got an empty file listing for path \"\""
0093 exit 1
0094 fi
0095 """
0096 else:
0097 checkpoint backwards_ecal_campaign_sim_list_checkpoint:
0098 output:
0099 "listing/backwards_ecal/{CAMPAIGN}/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst.orig",
0100 params:
0101 search_path=lambda wildcards: f"EPIC/RECO/{wildcards.CAMPAIGN}/epic_craterlake/SINGLE/{wildcards.PARTICLE}/{wildcards.ENERGY}/{wildcards.PHASE_SPACE}/",
0102 shell: """
0103 xrdfs root://dtn-eic.jlab.org/ ls /work/eic2/{params.search_path} \
0104 | sed -e 's#^/work/eic2/##' \
0105 | sort \
0106 > {output}
0107 if [ ! -s {output} ]; then
0108 echo "Got an empty file listing for path \"\""
0109 exit 1
0110 fi
0111 """
0112
0113 def get_backwards_ecal_campaign_sim_list(wildcards):
0114 with checkpoints.backwards_ecal_campaign_sim_list_checkpoint.get(**wildcards).output[0].open() as fp:
0115 return [line.rstrip() for line in fp.readlines()]
0116
0117 rule backwards_ecal_campaign_sim_list:
0118 input:
0119 # depend on paths from the file list
0120 get_backwards_ecal_campaign_sim_list,
0121 orig_list="listing/backwards_ecal/{CAMPAIGN}/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst.orig",
0122 output:
0123 "listing/backwards_ecal/{CAMPAIGN}/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst",
0124 shell: """
0125 cp {input.orig_list} {output}
0126 """
0127
0128
0129 ruleorder: backwards_ecal_local_sim_list > backwards_ecal_campaign_sim_list
0130
0131
0132 DETECTOR_CONFIG=os.environ["DETECTOR_CONFIG"]
0133
0134 rule backwards_ecal:
0135 input:
0136 expand(
0137 "listing/backwards_ecal/{{CAMPAIGN}}/" + DETECTOR_CONFIG + "/{PARTICLE}/{ENERGY}/{PHASE_SPACE}.lst",
0138 PARTICLE=["pi-", "e-"],
0139 ENERGY=[
0140 "100MeV",
0141 "200MeV",
0142 "500MeV",
0143 "1GeV",
0144 "2GeV",
0145 "5GeV",
0146 "10GeV",
0147 "20GeV",
0148 ],
0149 PHASE_SPACE=["130to177deg"],
0150 ),
0151 matplotlibrc=".matplotlibrc",
0152 script="benchmarks/backwards_ecal/backwards_ecal.py",
0153 output:
0154 directory("results/backwards_ecal/{CAMPAIGN}/")
0155 log:
0156 scheduler=".logs/results/backwards_ecal/{CAMPAIGN}/scheduler.log",
0157 worker=".logs/results/backwards_ecal/{CAMPAIGN}/worker.log",
0158 threads: workflow.cores
0159 shell:
0160 """
0161 if [[ "{wildcards.CAMPAIGN}" == "local" ]]; then
0162 export PLOT_TITLE="Benchmark simulation"
0163 else
0164 export PLOT_TITLE="\\textbf{{ePIC}} Simulation {wildcards.CAMPAIGN}"
0165 fi
0166
0167 set -m # monitor mode to prevent lingering processes
0168 cleanup() {{
0169 echo Cleaning up
0170 kill $WORKER_PID $SCHEDULER_PID
0171 }}
0172 trap cleanup EXIT
0173
0174 PORT=$RANDOM
0175 dask scheduler --port $PORT 2>{log.scheduler} &
0176 export DASK_SCHEDULER=localhost:$PORT
0177 SCHEDULER_PID=$!
0178 dask worker tcp://$DASK_SCHEDULER --nworkers {threads} --nthreads 1 2>{log.worker} &
0179 WORKER_PID=$!
0180 env \
0181 MATPLOTLIBRC={input.matplotlibrc} \
0182 DETECTOR_CONFIG=""" + DETECTOR_CONFIG + """ \
0183 INPUT_PATH_FORMAT=listing/backwards_ecal/{wildcards.CAMPAIGN}/""" + DETECTOR_CONFIG + """/{{particle}}/{{energy}}/130to177deg.lst \
0184 OUTPUT_DIR={output} \
0185 python {input.script}
0186 """