Analysis-Utilities 26.9.9
C++/ROOT utilities for nuclear measurement data analysis
Loading...
Searching...
No Matches
WaveformProcessingUtils.hpp
Go to the documentation of this file.
1#ifndef WAVEFORMPROCESSOR_H
2#define WAVEFORMPROCESSOR_H
3
4#include "PlottingUtils.hpp"
5#include <TArrayF.h>
6#include <TArrayI.h>
7#include <TFile.h>
8#include <TMath.h>
9#include <TROOT.h>
10#include <TSystem.h>
11#include <TTree.h>
12#include <fstream>
13#include <future>
14#include <iostream>
15#include <mutex>
16#include <thread>
17#include <vector>
18
50
72
79
91 Int_t polarity = -1;
93 Float_t trigger_threshold = 0.15;
97 Int_t pre_samples = 17;
99 Int_t post_samples = 190;
102 Int_t pre_gate = 10;
104 Int_t short_gate = 10;
106 Int_t long_gate = 200;
110 Int_t max_events = -1;
111 Bool_t verbose = kTRUE;
112 Bool_t store_waveforms = kTRUE;
116 Int_t adc_saturation_code = 16384;
117};
118
138private:
139 Int_t polarity_;
140 Double_t trigger_threshold_;
141 Int_t num_samples_baseline_;
142 Int_t pre_samples_;
143 Int_t post_samples_;
144 Int_t pre_gate_;
145 Int_t short_gate_;
146 Int_t long_gate_;
147 Int_t max_events_;
148 Bool_t verbose_;
149 Int_t adc_saturation_code_;
150
151 static std::mutex canvas_mutex_;
152 Int_t sample_waveforms_to_save_;
153 Int_t sample_waveforms_saved_;
154 TString current_output_name_;
155
156 ProcessingStats stats_;
157
158 Float_t current_baseline_rms_ = 0.0f;
159 Bool_t current_baseline_rms_valid_ = kFALSE;
160
161 TFile *output_file_;
162 TTree *output_tree_;
163 WaveformFeatures current_features_;
164 Bool_t store_waveforms_;
165 TArrayF *save_waveform_;
166 ULong64_t current_timestamp_;
167 InputFormat input_format_;
168
169public:
172
176
179
182 void SetPolarity(const Int_t polarity) { polarity_ = polarity; }
183
187 void SetTriggerThreshold(Double_t threshold) {
188 trigger_threshold_ = threshold;
189 }
190
196 void SetNumberOfSamplesForBaseline(Int_t num_samples_baseline) {
197 num_samples_baseline_ = num_samples_baseline;
198 }
199
203 void SetSampleWindows(Int_t pre_samples, Int_t post_samples) {
204 pre_samples_ = pre_samples;
205 post_samples_ = post_samples;
206 }
207
214 void SetGates(Int_t pre_gate, Int_t short_gate, Int_t long_gate) {
215 pre_gate_ = pre_gate;
216 short_gate_ = short_gate;
217 long_gate_ = long_gate;
218 }
219
222 void SetMaxEvents(Int_t max_events) { max_events_ = max_events; }
223
226 void SetVerbose(Bool_t verbose) { verbose_ = verbose; }
227
231 void SetStoreWaveforms(Bool_t store = kTRUE) { store_waveforms_ = store; }
232
235 void SetSaveSampleWaveforms(Int_t count) {
236 sample_waveforms_to_save_ = count;
237 }
238
242 void SetAdcSaturationCode(Int_t adc_saturation_code) {
243 adc_saturation_code_ = adc_saturation_code;
244 }
245
263 Bool_t ProcessWaveform(const TArrayI &samples);
264
279 void SubtractBaseline(const TArrayI &samples);
280
292 Float_t FindTrigger(const TArrayF &waveform);
293
309 void CropWaveform(const TArrayF &waveform, Int_t trigger_pos);
310
324 WaveformFeatures ExtractFeatures(const TArrayF &cropped_wf);
325
340 Bool_t ApplyQualityCuts(const WaveformFeatures &features);
341
351 void SaveSampleWaveform(const TArrayF &waveform);
352
360 void PrintAllStatistics() const;
361
364 ProcessingStats GetStats() const { return stats_; };
365
380 Bool_t ProcessFile(const TString filepath, const TString output_name);
381
405 static void ProcessFilesParallel(const std::vector<TString> &filepaths,
406 const std::vector<TString> &output_names,
407 const FileProcessingConfig &config,
408 Int_t max_workers = 4);
409};
410
411#endif
InputFormat
Acquisition software that produced the input file.
@ kWAVEDUMP
CAEN WaveDump (DT5742 family).
@ kSOLARIS
SOLARIS DAQ (SOL).
@ kCOMPASS
CAEN CoMPASS.
Bool_t ApplyQualityCuts(const WaveformFeatures &features)
Decide whether a waveform survives the quality cuts.
static void ProcessFilesParallel(const std::vector< TString > &filepaths, const std::vector< TString > &output_names, const FileProcessingConfig &config, Int_t max_workers=4)
Process many files concurrently, one instance per worker.
void PrintAllStatistics() const
Print the run statistics, including mean baseline RMS.
void SetMaxEvents(Int_t max_events)
Cap the number of waveforms read per file.
void SetAdcSaturationCode(Int_t adc_saturation_code)
Set the ADC code that counts as full scale.
Bool_t ProcessFile(const TString filepath, const TString output_name)
Process one input file end to end.
void SetVerbose(Bool_t verbose)
Enable or disable progress and summary output.
void SetNumberOfSamplesForBaseline(Int_t num_samples_baseline)
Set how many leading samples are averaged for the baseline.
WaveformProcessingUtils()
Construct with the FileProcessingConfig defaults.
Bool_t ProcessWaveform(const TArrayI &samples)
Run one raw waveform through the whole pipeline.
void SetTriggerThreshold(Double_t threshold)
Set the trigger level as a fraction of each waveform's peak.
void SetPolarity(const Int_t polarity)
Set the pulse polarity.
ProcessingStats GetStats() const
Snapshot of the current statistics.
~WaveformProcessingUtils()
Closes any open output file and releases the internal buffer.
void SetSampleWindows(Int_t pre_samples, Int_t post_samples)
Set the crop window around the trigger.
WaveformFeatures ExtractFeatures(const TArrayF &cropped_wf)
Compute the per-waveform features of a cropped waveform.
void SetSaveSampleWaveforms(Int_t count)
Set how many example waveforms are saved as figures.
void CropWaveform(const TArrayF &waveform, Int_t trigger_pos)
Cut the region of interest around the trigger.
void SaveSampleWaveform(const TArrayF &waveform)
Write one waveform out as a figure for visual inspection.
void SetGates(Int_t pre_gate, Int_t short_gate, Int_t long_gate)
Set the integration gates, in samples.
void SetStoreWaveforms(Bool_t store=kTRUE)
Choose whether cropped waveforms are written to the output tree.
Float_t FindTrigger(const TArrayF &waveform)
Find the first sample crossing the fractional trigger level.
void SubtractBaseline(const TArrayI &samples)
Estimate and remove the baseline, writing to the internal buffer.
Everything needed to configure one processing run.
Int_t max_events
Cap on waveforms to read per file; -1 means no limit.
Int_t polarity
Pulse polarity: -1 for negative-going pulses (inverted during baseline subtraction),...
Int_t sample_waveforms_to_save
How many example waveforms to write out as figures, for eyeballing.
Int_t adc_saturation_code
ADC code that means full scale.
Int_t long_gate
Width of the long integration gate.
InputFormat input_format
Input file format.
Int_t post_samples
Samples kept after the trigger when cropping.
Int_t num_samples_baseline
Leading samples averaged to estimate the baseline.
Int_t short_gate
Width of the short integration gate.
Int_t pre_gate
Samples before pre_samples at which integration starts, so integration begins at pre_samples - pre_ga...
Int_t pre_samples
Samples kept before the trigger when cropping.
Bool_t store_waveforms
Write the cropped waveform to the tree.
Float_t trigger_threshold
Trigger level as a fraction of the waveform's peak, in (0, 1].
Bool_t verbose
Print progress and per-file summaries.
Running counters and accumulators for one processing run.
Int_t rejected_no_trigger
No sample reached the trigger level.
Int_t rejected_negative_integral
Long-gate integral <= 0.
Int_t rejected_insufficient_samples
Trigger too close to either end to crop the requested window.
Int_t rejected_baseline
More than 50% negative samples.
Int_t rejected_clipped
Raw extremum hit the ADC rail.
Double_t sum_baseline_rms_accepted
Sum of baseline RMS over accepted waveforms only.
Int_t total_processed
Waveforms examined.
Double_t sum_baseline_rms
Sum of per-waveform baseline RMS.
Int_t baseline_rms_count_accepted
Accepted waveforms in that sum.
Int_t accepted
Waveforms that passed every cut.
Int_t baseline_rms_count
Waveforms contributing to that sum.
Per-waveform quantities extracted by WaveformProcessingUtils::ExtractFeatures().
Int_t peak_position
Index of that maximum within the cropped waveform, in samples.
Int_t trigger_position
Trigger index re-evaluated on the cropped waveform, in samples.
Float_t pulse_height
Maximum of the baseline-subtracted cropped waveform, in ADC counts.
Int_t raw_pulse_height
Extremum of the raw, pre-baseline-subtraction trace, as a magnitude.
Bool_t passes_cuts
Whether this waveform survived the quality cuts.
Float_t long_integral
Sum over the long gate, in ADC counts x samples.
Float_t negative_fraction
Fraction of samples in the long gate that are below zero, in [0, 1].
Float_t short_integral
Sum over the short gate, in ADC counts x samples.
ULong64_t timestamp
Acquisition timestamp carried through from the input record.