Snakemake Rules Reference¶
workflow/rules/aux.smk module¶
print_statsPrints a table with summary runtime information for each
simid.Can be run with
snakemake print_stats. The listed tiers are taken from the Simflow config fieldmake_steps.Note
The statistics refer to the total job wall time, as measured by Snakemake.
No wildcards are used.
print_benchmark_statsPrints a table with summary runtime information of a benchmarking run.
Can be run with
snakemake print_benchmark_stats. This functionality is useful to tune the number of remage primaries and jobs in the Simflow configuration. After printing the table, also writes an updatedgenerated/benchmarks/generated-simconfig.yamlwith suggestedprimaries_per_jobandnumber_of_jobsvalues that can optionally be swapped in place of the sourcesimconfig.yaml.Note
The runtime and the simulation speed are extracted from the event simulation loop statistics reported by remage. These values do not account for other remage steps like initialization or post-processing.
No wildcards are used.
_init_julia_envNo description provided.
cache_detector_usabilitiesCache detector usabilities.
Querying the metadata for detector usability can be slow and constitute the bottleneck in post-processing (
optandhittiers). This rule caches, underpars/detinfo/, one file per flag (usability.yaml,psd_usability.yaml,crystal_metadata_usability.yaml), each a mappingrunid -> detector -> value.archive_plotsArchive all validation plots into a single tarball.
Must be triggered manually with
snakemake archive_plots— it is not part of the defaultalltarget. Collects allplots/subdirectories produced by the Simflow under thegenerated/directory and packs them intotarballs/<cycle>-plots.tar.xz, preserving the directory tree structure.No wildcards are used.
workflow/rules/cvt.smk module¶
gen_all_tier_cvtAggregate and produce all the
cvttier files.build_tier_cvtProduce a
cvttier file.cvtstands for “concatenatedevttier”.evtfiles for each simulation job are concatenated/aggregated into a single file.Uses wildcards
simid.plot_tier_cvt_observablesProduce validation plots of observable distributions from the
cvttier.Generates diagnostic plots from all
cvtoutput files for the givensimid.Uses wildcard
simid.
workflow/rules/evt.smk module¶
gen_all_tier_evtAggregate and produce all the
evttier files.build_tier_evtProduce an
evttier file.Event files re-organize the
hitandopttier data into a single, event-oriented table where each row correspond to an event.a unified TCM is built from the
optandhitdata. It is different from thestptier TCM since it includes also the SiPM channels;each chunk of the unified TCM is partitioned according to the livetime span of each run (see the
make_simstat_partition_filerule);fields from lower tiers are restructured into events;
new event-level fields are computed and stored in the output file;
optionally, random-coincidence (RC) SiPM data from real evt files is added as
spms/rc_energyandspms/rc_time(controlled byadd_random_coincidencesintier/evt/{experiment}/settings.yaml).
A top-level
detector_uidsstruct mapping detector names to reboost UIDs (union of hit and opt tiers) is also written, to enable downstream per-group filtering in thepdftier.Uses wildcards
simidandjobid.
workflow/rules/hit.smk module¶
gen_all_tier_hitAggregate and produce all the hit tier files.
build_tier_hitProduce a
hittier file starting from a singlestptier file.This rule implements the post-processing of the
stptier HPGe data in chunks, in the following steps:each chunk is partitioned according to the livetime span of each run (see the
make_simstat_partition_filerule). For each partition:the detector usability and PSD usability are retrieved from
legend-metadataand stored in the output;the active volume model is applied based on information from
legend-metadata;A/E is simulated based on current signal templates extracted from LEGEND-200 data;
energy is smeared according to the measured energy resolution (extracted from the data production parameters database);
a new time-coincidence map (TCM) across the processed detectors is created and stored in the output file.
The
stpdata format is preserved: detector tables are stored separately in the output file below/hit/{detector_name}.When the
two_pass_aoe_correctionhit-tier setting is enabled, this final build additionally consumes the merged A/E energy-dependence correction (merge_hpge_aoemean_energy_dependence_pars), computed from a pre-correction pass (seebuild_tier_hit_precorr).Uses wildcards
simidandjobid.build_tier_hit_precorrNote
Derived from
build_tier_hitviause rule ... with:; see that rule for the shared behavior.No description provided.
plot_tier_hit_observablesProduce validation plots of observable distributions from the
hittier.Generates diagnostic plots from all
hitoutput files for the givensimid.Uses wildcard
simid.
workflow/rules/opt.smk module¶
gen_all_tier_optAggregate and produce all the opt tier files.
build_tier_optProduce a
opttier file starting from a singlestptier file.This rule implements the post-processing of the
stptier liquid argon energy depositions in chunks, in the following steps:each chunk is partitioned according to the livetime span of each run (see the
make_simstat_partition_filerule). For each partition:the detector usability is retrieved from
legend-metadataand stored in the output;scintillation photons are generated corresponding to simulated energy depositions;
detected photoelectrons are sampled according to the input optical map;
a finite resolution is applied to each photoelectron amplitude (see script);
photoelectrons are clustered in time to simulate the effect of finite time resolution of the system;
a new time-coincidence map (TCM) across the processed SiPMs is created and stored in the output file.
This rule can sample photoelectrons in each SiPM individually or for all SiPMs at the same time, see relevant
paramflag.The
stpdata format is preserved: SiPM tables are stored separately in the output file below/hit/{sipm_name}.Uses wildcards
simidandjobid.plot_tier_opt_observablesProduce validation plots of observable distributions from the
opttier.Generates diagnostic plots from all
optoutput files for the givensimid.Uses wildcard
simid.
workflow/rules/par.smk module¶
Rules to compute the simulation parameters (par step).
gen_all_tier_parProduce all
parstep outputs.make_simstat_partition_fileCreate the simulation event statistics partitioning file.
This rule maps chunks of event indices to partitions associated to the data taking runs specified in the “runlist” (from e.g.
config.runlist) and stores them on disk as YAML files. The format is the following:job_000: l200-p03-r001-phy: [0, 300] l200-p03-r002-phy: [301, 456] job_001: l200-p03-r002-phy: [0, 200] l200-p03-r003-phy: [201, 156] job_002: l200-p03-r003-phy: [0, 50]
The events simulated in job
0(456) are split betweenr001andr002. The partition corresponding tor002is however incomplete, and 200 events are taken from the simulation job1.The fraction of total simulated events (summed over all simulation jobs) that belong to a partition is determined by weighting with the fraction of livetime that belongs to that run.
Uses wildcard
simid.build_hpge_drift_time_mapProduce an HPGe drift-time map.
Run a Julia script based on a pulse-shape simulation performed with the
SolidStateDetectors.jlpackage, using crystal geometry information fromlegend-metadata. The drift time recorded at each grid point is the time at which the simulated hole charge-collection signal reaches its maximum current (the argmax of the charge-signal derivative); one map is produced per crystal-axis angle.The output is one LH5 file per
(detector, voltage)pair with a single top-level group named after the detector, holding the gridded map in the(r, z)-field format read back byreboost.hpge.utils.get_hpge_rz_field()and consumed byreboost.hpge.psd.drift_time()when thehittier is built:Field
Type
Units
Description
rArraym
Radial coordinates of the rectangular
(r, z)grid.zArraym
Axial coordinates of the grid. The origin
(r, z) = (0, 0)is the centre of the p+ contact.drift_time_<angle>_degArray(2D)ns
Drift time over the
(r, z)grid at crystal-axis azimuth<angle>. Pixels outside the detector profile hold NaN.Uses wildcards
hpge_detectorandhpge_voltage.merge_hpge_drift_time_mapsMerge HPGe drift-time maps in a single file.
Copy the top-level LH5 objects from each individual detector drift-time map file into a single merged file using
h5copy.Uses wildcard
runid.aggregate_hpge_ssd_modeling_infoAggregate the HPGe SSD-modeling provenance into a
detinfofile.Each
build_hpge_drift_time_mapjob writes, next to its LH5 map, a small YAML sidecar holding the SSD simulation provenance scalars for that(detector, voltage)pair (impurity scaling factor, measured and simulated depletion voltages). This rule collects those sidecars and pivots them into a singlepars/detinfo/hpge_ssd_modeling.yamlmappingrunid -> detector -> {impurity_scaling_factor, measured_depletion_voltage_in_V, simulated_depletion_voltage_raw_in_V, simulated_depletion_voltage_in_V}, following thedetinfoconvention (see par tier — detector-info cache (pars/detinfo/)).No wildcards are used.
plot_hpge_drift_time_mapsProduce a validation plot of an HPGe drift-time map.
Generates diagnostic plots of the computed drift-time map for a single detector at the specified operational voltage.
Uses wildcards
hpge_detectorandhpge_voltage.build_hpge_pulse_shape_libraryProduce an (ideal) HPGe pulse-shape library.
Run a Julia script based on a pulse-shape simulation performed with the
SolidStateDetectors.jlpackage, using crystal geometry information fromlegend-metadata. It simulates the full charge-collection transient at every(r, z, angle)grid point. These are un-convolved (ideal) charge waveforms; the electronics transfer function is applied later, inconvolve_hpge_ideal_pulse_shape_lib.The output is one LH5 file per
(detector, voltage)pair with a single top-level group named after the detector:Field
Type
Units
Description
rArraym
Radial coordinates of the simulation grid.
zArraym
Axial coordinates of the simulation grid.
dtScalarns
Time step between waveform samples.
waveform_<angle>_degArray(3D)Ideal charge waveforms at azimuth
<angle>, shape(n_z, n_r, n_samples).The sample times of a waveform are
t_i = i * dt(not0offset is stored).Uses wildcards
hpge_detectorandhpge_voltage.convolve_hpge_ideal_pulse_shape_libConvolve ideal HPGe pulse-shape libraries with electronics response.
Produce one realistic pulse-shape library per detector and run by selecting the ideal library for the detector operational voltage in that run and convolving it with the electronics parameters (
sigma,tau) from a merged electronics-model YAML file, then differentiating, moving-window-averaging, aligning, and normalising to obtain current waveforms.The output is one LH5 file per
(runid, detector)pair with a top-level group named after the detector, in the pulse-shape-library format read back byreboost.hpge.utils.get_hpge_pulse_shape_library()when thehittier is built:Field
Type
Units
Description
rArraymm
Radial coordinates of the simulation grid (converted from metres).
zArraymm
Axial coordinates of the simulation grid (converted from metres).
dtScalarns
Sampling time step of the realistic current waveforms.
t0Scalarns
Global time offset: time of the alignment index relative to the current peak.
waveform_<angle>_degArray(3D)Processed, normalised current waveforms at azimuth
<angle>, shape(n_r, n_z, n_samples); NaN outside the detector.drift_time_<angle>_degArray(2D)ns
Drift time per
(r, z)pixel at azimuth<angle>, shape(n_r, n_z); NaN outside the detector.The current-waveform sample times are
t_i = t0 + i * dt.Uses wildcards
runidandhpge_detector.merge_hpge_realistic_pslsMerge HPGe realistic PSL in a single file.
Copy the top-level LH5 objects from each individual detector realistic-PSL file into a single merged file using
h5copy.Uses wildcard
runid.extract_current_pulse_modelExtract the HPGe current-pulse model.
Perform a fit of current signals recorded in LEGEND-200 and stores the best-fit model parameters in a YAML file.
Warning
This rule does not have the relevant LEGEND-200 data files as input, since they are dynamically discovered and this would therefore slow down the DAG generation. Therefore, remember to force-rerun if the input data is updated!
Uses wildcards
runidandhpge_detector.merge_current_pulse_model_parsMerge the HPGe current-pulse model parameters in a single file per
runid.Collect the individual best-fit parameter files (one per detector) and write them into a single YAML file keyed by detector name.
Uses wildcard
runid.extract_hpge_aoemean_energy_dependenceFit the A/E energy-dependence correction for one HPGe detector.
Reads raw (uncorrected) A/E vs. energy from the temporary pre-correction
hitfiles (build_tier_hit_precorr) for simulation IDs matchingsimid_regex(defaultsis*_z*_slot*_Pb212_to_Pb208, overridable via theaoemeanmodpar settings) and fits the energy dependence withpygama.pargen.AoE_cal.CalAoE, mirroring the LEGEND-200 data calibration procedure. Only built when thetwo_pass_aoe_correctionhit-tier setting is enabled.Uses wildcard
hpge_detector.merge_hpge_aoemean_energy_dependence_parsMerge the per-detector A/E energy-dependence corrections into one file.
Collect each detector’s
energy_correctionsblock into a single detector-keyed YAML matching the schema consumed by thehittier (nodefaultentry). Global and run-independent, unlike the currmod/elecmod merges.No wildcards are used.
build_superpulses_from_dataBuild HPGe data superpulses (average waveforms per drift-time slice).
Accumulate waveforms from LEGEND-200 data per detector (across all configured runs, or per run when
build_per_runidis set) and average them within drift-time slices to form “super” pulses, after a self-similarity chi2 cut.The output LH5 file contains one group per drift-time slice, named
{detector}/dt_{lo}_{hi}_ns/, each holding:Field
Type
Units
Description
charge_wfArrayADC/cuspEmax
Average normalised charge waveform.
current_wfArray(ADC/cuspEmax)/ns
Average current waveform.
charge_time_axisArrayns
Time axis for the charge waveform, aligned to
tp_aoe_max = 0.current_time_axisArrayns
Time axis for the current waveform.
drift_time_centerScalarns
Centre of the drift-time bin.
drift_time_loScalarns
Lower bound of the drift-time bin.
drift_time_hiScalarns
Upper bound of the drift-time bin.
energy_loScalarkeV
Lower bound of the energy selection.
energy_hiScalarkeV
Upper bound of the energy selection.
detectorScalarDetector name string.
n_events_preliminaryScalarWaveforms before the chi2 cut.
n_events_finalScalarWaveforms after the chi2 cut.
Uses wildcard
hpge_detector, andrunidif per-run superpulses are requested (build_per_runid).extract_electronics_model_parsExtract the HPGe electronics-response model.
Fit the electronics transfer function (a Gaussian digitizer bandwidth
sigmaconvolved with a causal exponential preamplifier decaytau) by comparing processed ideal PSL waveforms to the measured data superpulses. When adefaultkey is present in theelecmodvalidity metadata the fit is bypassed and the metadata values are written directly.The (temporary, per-detector) output YAML, consumed by
merge_electronics_model_pars, contains:Key
Type
Description
detectorstr
Detector name.
sigmafloat
Fitted Gaussian sigma of the digitizer bandwidth, in ns.
taufloat
Fitted preamplifier decay constant, in ns.
rmsfloat
Best-fit mean RMS across slices.
anglestr
Crystal-axis angle tag used for PSL waveform selection (e.g.
"000").aoe_datafloat (optional)
Max current amplitude of the data superpulse in the highest drift-time slice; present with diagnostic plots.
aoe_mcfloat (optional)
Max current amplitude of the simulation superpulse in the highest drift-time slice; present with plots.
Only
sigmaandtauare required by the consumer (convolve_hpge_ideal_pulse_shape_lib).Uses wildcards
runidandhpge_detector.merge_electronics_model_parsMerge the HPGe electronics-response model parameters in a single file per
runid.Collect the individual best-fit parameter files (one per detector) and write them into a single YAML file keyed by detector name.
Uses wildcard
runid.extract_hpge_observables_modelsExtract and store on disk models of the HPGe observables for a run.
Stores YAML files with a mapping between HPGe detectors and respective information to reconstruct:
the energy resolution as a function of energy;
the A/E resolution as a function of energy;
as determined during energy calibration. This is done in a separate rule because the data production parameter database is large and we don’t want to use a lot of memory in the
build_tier_hitrule.Design: this rule is a collection step, not a validation step. It gathers what it can from l200data and
simprod/config/pars/geds/eresmod/; the output may be incomplete. Completeness is validated downstream inbuild_tier_hit.Uses wildcard
runid.
workflow/rules/pdf.smk module¶
gen_all_tier_pdfAggregate and produce all the
pdftier files.No wildcards are used.
archive_pdfsArchive all pdf tier files into a single tarball.
Must be triggered manually with
snakemake archive_pdfs— it is not part of the defaultalltarget. Collects all LH5 files produced undertier/pdf/and packs them intotarballs/<cycle>-pdfs.tar.xz, preserving the directory tree structure.No wildcards are used.
build_tier_pdfProduce a
pdftier file.Reads
cvttier data and bins it into histograms (the PDFs) according to the PDF configuration file.Uses wildcard
simid.
workflow/rules/stp.smk module¶
Rules to build the stp tier.
gen_all_tier_stpBuild the entire
stptier.gen_geom_configWrite a geometry configuration file for legend-pygeom-l200.
Start from the template/default geometry configuration file and eventually add extra configuration options in case requested in
simconfig.yamlthrough thegeom_config_extrafield.Uses wildcards
tierandsimid.build_geom_gdmlBuild a concrete geometry GDML file with
pygeoml200.Run
legend-pygeom-l200to convert the geometry configuration file into a GDML file.Uses wildcards
tierandsimid.gen_remage_macroWrite the remage macro file for a
stptier simulation to disk.Renders the macro template for the given
simidusinglegendsimflow.commands.make_remage_macro()and writes it to the canonical macro path undergenerated/macros/.Uses wildcard
simid.build_tier_stpRun a single simulation job for the
stptier.Invoke remage using the macro generated by
legendsimflow.commands.make_remage_macro()fromsimconfig.yaml.Uses wildcards
simidandjobid.Note
The output remage file is declared as
protectedto avoid accidental deletions, since it typically takes a lot of resources to produce it.plot_tier_stp_verticesProduce plots of the primary event vertices of tier
stp.Only the first file of the simulation (i.e. job ID 0) is used. The rule is given a high priority to make sure that the plot is produced early. The maximum number of plotted events is set in the plotting script.
Uses wildcard
simid.plot_geomProduce the geometry validation plots (HPGe mass comparison and rendering).
Both are derived from the
stpgeometry config bylegendsimflow.geometry.make_hpge_mass_plot()andlegendsimflow.geometry.render_geometry().Uses wildcard
simid.
workflow/rules/vtx.smk module¶
build_tier_vtxRun a single simulation job for the
vtxtier.Run the user-defined vertex generation command from
vtx_simconfig.yaml, templating it with the geometry file path, output file path, and number of events.Uses wildcards
simidandjobid.