Back to home page

EIC code displayed by LXR

 
 

    


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.root",
0080     log:
0081         "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/sim.edm4hep.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   --outputFile {output} \
0118   > {log} 2>&1
0119 """
0120 
0121 
0122 rule irt_recon:
0123     input:
0124         sim="sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/sim.edm4hep.root",
0125         warmup="warmup.edm4hep.root",
0126     output:
0127         "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/rec.edm4eic.root",
0128     log:
0129         "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/rec.edm4eic.root.log",
0130     wildcard_constraints:
0131         RICH="(DRICH|PFRICH)",
0132         PARTICLE="[a-z0-9+-]+",
0133     params:
0134         DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
0135         RICH=lambda wildcards: wildcards.RICH,
0136         PARTICLE=lambda wildcards: wildcards.PARTICLE,
0137         COLLECTIONS=lambda wildcards: ",".join(irt_collections(wildcards.RICH)),
0138         EICRECON_HASH=get_spack_package_hash("eicrecon"),
0139     cache: True
0140     singularity: EIC_SINGULARITY_CONTAINER,
0141     shell:
0142         """
0143 DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
0144 exec eicrecon {input.sim} \
0145   -Ppodio:output_file={output} \
0146   -Ppodio:output_collections={params.COLLECTIONS} \
0147   > {log} 2>&1
0148 """
0149 
0150 
0151 rule irt_analysis:
0152     input:
0153         rec="sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/rec.edm4eic.root",
0154         executable="sim_output/irt/bin/irt_analysis",
0155     output:
0156         "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/hists.root",
0157     log:
0158         "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/hists.root.log",
0159     wildcard_constraints:
0160         RICH="(DRICH|PFRICH)",
0161         PARTICLE="[a-z0-9+-]+",
0162     singularity: EIC_SINGULARITY_CONTAINER,
0163     shell:
0164         """
0165 {input.executable} {wildcards.RICH} {input.rec} {output} > {log} 2>&1
0166 """
0167 
0168 
0169 rule irt_plots:
0170     input:
0171         hists=lambda wildcards: expand(
0172             "sim_output/irt/{DETECTOR_CONFIG}/{RICH}/{PARTICLE}/hists.root",
0173             DETECTOR_CONFIG=[wildcards.DETECTOR_CONFIG],
0174             RICH=[wildcards.RICH],
0175             PARTICLE=IRT_PARTICLES,
0176         ),
0177         script=workflow.source_path("scripts/plot_irt.py"),
0178     output:
0179         directory("results/{DETECTOR_CONFIG}/irt/{RICH}"),
0180     wildcard_constraints:
0181         RICH="(DRICH|PFRICH)",
0182     singularity: EIC_SINGULARITY_CONTAINER,
0183     shell:
0184         """
0185 python {input.script} \
0186   --output-dir {output} \
0187   --title "{wildcards.DETECTOR_CONFIG} {wildcards.RICH}" \
0188   {input.hists}
0189 """