Warning, /detector_benchmarks/benchmarks/irt/Snakefile is written in an unsupported language. File is not indexed.
0001 """
0002 RICH IRT (Indirect Ray Tracing) benchmark.
0003
0004 Single particles are shot into the dRICH (or the pfRICH) acceptance, are
0005 reconstructed with eicrecon, and the IRT output collections are analyzed by a
0006 small C++ program (``benchmarks/irt/src``) which fills Cherenkov angle, photo
0007 electron and PID confusion matrix histograms.
0008 """
0009
0010
0011 # Phase space covered for each of the RICH detectors
0012 IRT_SETTINGS = {
0013 "DRICH": {
0014 "THETA_MIN": 3,
0015 "THETA_MAX": 25,
0016 "P_MIN": 1.0,
0017 "P_MAX": 50.0,
0018 },
0019 "PFRICH": {
0020 "THETA_MIN": 155,
0021 "THETA_MAX": 177,
0022 "P_MIN": 0.5,
0023 "P_MAX": 15.0,
0024 },
0025 }
0026
0027 IRT_PARTICLES = ["pi-", "kaon-", "proton"]
0028
0029 IRT_N_EVENTS = 1000
0030
0031
0032 def irt_collections(rich):
0033 """Collections that have to be present in the reconstructed file."""
0034 return [
0035 "MCParticles",
0036 "CentralCKFTracks",
0037 f"{rich}Tracks",
0038 f"{rich}IrtRadiatorInfo",
0039 f"{rich}IrtParticles",
0040 ]
0041
0042
0043 rule irt_compile:
0044 input:
0045 cmakelists=workflow.source_path("CMakeLists.txt"),
0046 sources=[
0047 workflow.source_path(path)
0048 for path in [
0049 "include/Confusion.h",
0050 "include/RICHIRT.h",
0051 "include/Setup.h",
0052 "src/Confusion.cpp",
0053 "src/RICHIRT.cpp",
0054 "src/Setup.cpp",
0055 "src/main.cpp",
0056 ]
0057 ],
0058 output:
0059 executable="sim_output/irt/bin/irt_analysis",
0060 params:
0061 source_dir=lambda wildcards, input: os.path.dirname(input.cmakelists),
0062 threads: 4
0063 singularity: EIC_SINGULARITY_CONTAINER,
0064 shell:
0065 """
0066 BUILD_DIR="$(mktemp -d)"
0067 trap 'rm -rf "$BUILD_DIR"' EXIT
0068 cmake -S "{params.source_dir}" -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release
0069 cmake --build "$BUILD_DIR" --parallel {threads}
0070 install -D "$BUILD_DIR/irt_analysis" {output.executable}
0071 """
0072
0073
0074 rule irt_sim:
0075 input:
0076 warmup="warmup.edm4hep.root",
0077 geometry_lib=find_epic_libraries(),
0078 output:
0079 "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/sim.edm4hep.rnt.root",
0080 log:
0081 "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/sim.edm4hep.rnt.root.log",
0082 wildcard_constraints:
0083 RICH="(DRICH|PFRICH)",
0084 PARTICLE="[a-z0-9+-]+",
0085 params:
0086 N_EVENTS=IRT_N_EVENTS,
0087 SEED=1,
0088 DETECTOR_PATH=os.environ["DETECTOR_PATH"],
0089 # wildcards are not included in the cache hash, add them as params
0090 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0091 RICH=lambda wildcards: wildcards.RICH,
0092 PARTICLE=lambda wildcards: wildcards.PARTICLE,
0093 THETA_MIN=lambda wildcards: IRT_SETTINGS[wildcards.RICH]["THETA_MIN"],
0094 THETA_MAX=lambda wildcards: IRT_SETTINGS[wildcards.RICH]["THETA_MAX"],
0095 P_MIN=lambda wildcards: IRT_SETTINGS[wildcards.RICH]["P_MIN"],
0096 P_MAX=lambda wildcards: IRT_SETTINGS[wildcards.RICH]["P_MAX"],
0097 DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0098 NPSIM_HASH=get_spack_package_hash("npsim"),
0099 cache: True
0100 singularity: EIC_SINGULARITY_CONTAINER,
0101 shell:
0102 """
0103 set -m # monitor mode to prevent lingering processes
0104 exec npsim \
0105 --runType batch \
0106 --enableGun \
0107 --gun.particle {params.PARTICLE} \
0108 --gun.momentumMin "{params.P_MIN}*GeV" \
0109 --gun.momentumMax "{params.P_MAX}*GeV" \
0110 --gun.thetaMin "{params.THETA_MIN}*deg" \
0111 --gun.thetaMax "{params.THETA_MAX}*deg" \
0112 --gun.distribution eta \
0113 --random.seed {params.SEED} \
0114 -v WARNING \
0115 --numberOfEvents {params.N_EVENTS} \
0116 --compactFile "{params.DETECTOR_PATH}/{params.DETECTOR_CONFIG}.xml" \
0117 --outputConfig.useRNTuple true \
0118 --outputFile {output} \
0119 > {log} 2>&1
0120 """
0121
0122
0123 rule irt_recon:
0124 input:
0125 sim="sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/sim.edm4hep.rnt.root",
0126 warmup="warmup.edm4hep.root",
0127 output:
0128 "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/rec.edm4eic.root",
0129 log:
0130 "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/rec.edm4eic.root.log",
0131 wildcard_constraints:
0132 RICH="(DRICH|PFRICH)",
0133 PARTICLE="[a-z0-9+-]+",
0134 params:
0135 DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0136 RICH=lambda wildcards: wildcards.RICH,
0137 PARTICLE=lambda wildcards: wildcards.PARTICLE,
0138 COLLECTIONS=lambda wildcards: ",".join(irt_collections(wildcards.RICH)),
0139 EICRECON_HASH=get_spack_package_hash("eicrecon"),
0140 cache: True
0141 singularity: EIC_SINGULARITY_CONTAINER,
0142 shell:
0143 """
0144 DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
0145 exec eicrecon {input.sim} \
0146 -Ppodio:output_file={output} \
0147 -Ppodio:output_collections={params.COLLECTIONS} \
0148 > {log} 2>&1
0149 """
0150
0151
0152 rule irt_analysis:
0153 input:
0154 rec="sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/rec.edm4eic.root",
0155 executable="sim_output/irt/bin/irt_analysis",
0156 output:
0157 "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/hists.root",
0158 log:
0159 "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/hists.root.log",
0160 wildcard_constraints:
0161 RICH="(DRICH|PFRICH)",
0162 PARTICLE="[a-z0-9+-]+",
0163 singularity: EIC_SINGULARITY_CONTAINER,
0164 shell:
0165 """
0166 {input.executable} {wildcards.RICH} {input.rec} {output} > {log} 2>&1
0167 """
0168
0169
0170 rule irt_plots:
0171 input:
0172 hists=lambda wildcards: expand(
0173 "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/hists.root",
0174 DETECTOR_CONFIG=[wildcards.DETECTOR_CONFIG],
0175 RICH=[wildcards.RICH],
0176 PARTICLE=IRT_PARTICLES,
0177 ),
0178 script=workflow.source_path("scripts/plot_irt.py"),
0179 output:
0180 directory("results/{DETECTOR_CONFIG}/irt/{RICH}"),
0181 wildcard_constraints:
0182 RICH="(DRICH|PFRICH)",
0183 singularity: EIC_SINGULARITY_CONTAINER,
0184 shell:
0185 """
0186 python {input.script} \
0187 --output-dir {output} \
0188 --title "{wildcards.DETECTOR_CONFIG} {wildcards.RICH}" \
0189 {input.hists}
0190 """