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