All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
icarus::PMTWaveformBaselines Class Reference

Extracts the baseline of PMT waveforms. More...

Inheritance diagram for icarus::PMTWaveformBaselines:

Classes

struct  Config
 

Public Types

using Parameters = art::EDProducer::Table< Config >
 

Public Member Functions

 PMTWaveformBaselines (Parameters const &config)
 
virtual void beginJob () override
 Prepares the plots to be filled. More...
 
virtual void produce (art::Event &event) override
 Creates the data products. More...
 
virtual void endJob () override
 Remove empty plots. More...
 

Private Member Functions

void setupPlots ()
 Creates all the plots to be filled by the module. More...
 
void buildBaselineGraphs ()
 Removes the empty plots. More...
 
icarus::WaveformBaseline baselineFromMedian (raw::OpDetWaveform const &waveform) const
 Extracts a baseline as median from a single waveform. More...
 

Private Attributes

art::InputTag const fOpDetWaveformTag
 Input optical waveform tag. More...
 
bool fPlotBaselines
 Whether to produce plots. More...
 
double const fBaselineTimeAverage { 0.0 }
 Width of baseline time profile binning [s]. More...
 
std::string const fLogCategory
 Category name for the console output stream. More...
 
std::size_t fNPlotChannels = 0U
 Number of plotted channels. More...
 
TH2 * fHBaselines = nullptr
 All baselines, per channel. More...
 
std::vector< std::vector
< std::pair< double, double > > > 
fBaselinesVsTime
 For each channel, all event times and their baselines. More...
 

Detailed Description

Extracts the baseline of PMT waveforms.

This module produces a baseline data product for each optical detector waveform.

The waveforms on the same channels are currently treated as independent (which is less than ideal).

Output data products

Output plots

Input data products

Service requirements

Configuration parameters

A terse description of the parameters is printed by running lar --print-description PMTWaveformBaselines.

Definition at line 116 of file PMTWaveformBaselines_module.cc.

Member Typedef Documentation

using icarus::PMTWaveformBaselines::Parameters = art::EDProducer::Table<Config>

Definition at line 152 of file PMTWaveformBaselines_module.cc.

Constructor & Destructor Documentation

icarus::PMTWaveformBaselines::PMTWaveformBaselines ( Parameters const &  config)
explicit

Definition at line 250 of file PMTWaveformBaselines_module.cc.

251  : art::EDProducer(config)
252  // configuration
253  , fOpDetWaveformTag(config().OpticalWaveforms())
254  , fPlotBaselines(config().PlotBaselines())
255  , fBaselineTimeAverage(config().BaselineTimeAverage())
256  , fLogCategory(config().OutputCategory())
257 {
258  //
259  // optional configuration parameters
260  //
261 
262  //
263  // configuration report (currently, more like a placeholder)
264  //
265  mf::LogInfo(fLogCategory)
266  << "Using the standard (median) algorithm, waveform by waveform, on '"
267  << fOpDetWaveformTag.encode() << "'.";
268 
269  //
270  // declaration of input
271  //
272  consumes<std::vector<raw::OpDetWaveform>>(fOpDetWaveformTag);
273 
274  //
275  // declaration of output
276  //
277  produces<std::vector<icarus::WaveformBaseline>>();
278  produces<art::Assns<icarus::WaveformBaseline, raw::OpDetWaveform>>();
279 
280 } // icarus::PMTWaveformBaselines::PMTWaveformBaselines()
bool fPlotBaselines
Whether to produce plots.
art::InputTag const fOpDetWaveformTag
Input optical waveform tag.
double const fBaselineTimeAverage
Width of baseline time profile binning [s].
physics producers discrimopdaq OpticalWaveforms
std::string const fLogCategory
Category name for the console output stream.

Member Function Documentation

icarus::WaveformBaseline icarus::PMTWaveformBaselines::baselineFromMedian ( raw::OpDetWaveform const &  waveform) const
private

Extracts a baseline as median from a single waveform.

Definition at line 478 of file PMTWaveformBaselines_module.cc.

479 {
480 
482  { waveform.empty()? 0.0f: median(waveform.begin(), waveform.end()) };
483 
484 } // icarus::PMTWaveformBaselines::baselineFromMedian()
Class containing a waveform baseline value.
void icarus::PMTWaveformBaselines::beginJob ( )
overridevirtual

Prepares the plots to be filled.

Definition at line 284 of file PMTWaveformBaselines_module.cc.

284  {
285 
286  //
287  // set up the plots, if needed
288  //
289  if (fPlotBaselines) setupPlots();
290 
291 } // icarus::PMTWaveformBaselines::beginJob()
void setupPlots()
Creates all the plots to be filled by the module.
bool fPlotBaselines
Whether to produce plots.
void icarus::PMTWaveformBaselines::buildBaselineGraphs ( )
private

Removes the empty plots.

Definition at line 414 of file PMTWaveformBaselines_module.cc.

414  {
415 
416  auto& tfs = *(art::ServiceHandle<art::TFileService>());
417 
418  art::TFileDirectory graphDir = tfs.mkdir("graphs", "Baseline vs. time");
419  art::TFileDirectory profileDir
420  = tfs.mkdir("profiles", "Baseline profiles vs. time");
421 
422  for (auto const channel: util::counter(fBaselinesVsTime.size())) {
423 
424  auto& timeAndBaselines = fBaselinesVsTime[channel];
425  if (timeAndBaselines.empty()) continue;
426 
427  // sort by time (entries with the same time would be sorted by baseline,
428  // but that does not really happen nor it mattered if it happened)
429  std::sort(timeAndBaselines.begin(), timeAndBaselines.end());
430 
431  // graph, one point per event
432  auto* const graph = graphDir.makeAndRegister<TGraph>(
433  "BaselineCh" + std::to_string(channel),
434  "PMT channel #" + std::to_string(channel) + ": baseline vs. run time",
435  timeAndBaselines.size()
436  );
437  assert(graph->GetXaxis());
438  assert(graph->GetYaxis());
439  graph->GetXaxis()->SetTitle("event time");
440  graph->GetYaxis()->SetTitle("baseline [ ADC ]");
441 
442 
443  // profile, one point every 10 minutes (or best offer)
444  double const startTime = timeAndBaselines.front().first;
445  double const totalTime = timeAndBaselines.back().first - startTime;
446  auto const nBins = std::max(1U,
447  static_cast<unsigned int>(std::ceil(totalTime / fBaselineTimeAverage))
448  );
449  double const endTime = startTime + nBins * fBaselineTimeAverage;
450 
451  auto* const profile = profileDir.make<TProfile>(
452  ("BaselineCh" + std::to_string(channel) + "profile").c_str(),
453  ("PMT channel #" + std::to_string(channel) + ": baseline vs. run time")
454  .c_str(),
455  nBins, startTime, endTime
456  );
457  assert(profile->GetXaxis());
458  assert(profile->GetYaxis());
459  profile->GetXaxis()->SetTitle(
460  ("event time [ / " + std::to_string(fBaselineTimeAverage) + " s ]")
461  .c_str()
462  );
463  profile->GetYaxis()->SetTitle("average baseline [ ADC ]");
464 
465  for (auto const& [ i, data ]: util::enumerate(timeAndBaselines)) {
466  auto const [ time, baseline ] = data;
467  graph->SetPoint(i, time, baseline);
468  profile->Fill(time, baseline);
469  } // for
470 
471  } // for
472 
473 } // icarus::PMTWaveformBaselines::buildBaselineGraphs()
std::vector< std::vector< std::pair< double, double > > > fBaselinesVsTime
For each channel, all event times and their baselines.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
BEGIN_PROLOG baseline
double const fBaselineTimeAverage
Width of baseline time profile binning [s].
std::string to_string(WindowPattern const &pattern)
art::ServiceHandle< art::TFileService > tfs
void icarus::PMTWaveformBaselines::endJob ( )
overridevirtual

Remove empty plots.

Definition at line 382 of file PMTWaveformBaselines_module.cc.

382  {
383 
385 
386 } // icarus::PMTWaveformBaselines::endJob()
void buildBaselineGraphs()
Removes the empty plots.
bool fPlotBaselines
Whether to produce plots.
void icarus::PMTWaveformBaselines::produce ( art::Event &  event)
overridevirtual

Creates the data products.

Definition at line 295 of file PMTWaveformBaselines_module.cc.

295  {
296 
297  //
298  // fetch input
299  //
300  auto const& waveformHandle
301  = event.getValidHandle<std::vector<raw::OpDetWaveform>>(fOpDetWaveformTag);
302  auto const& waveforms = *waveformHandle;
303 
304  /*
305  * this may be needed in a future where processing happens per channel
306  * rather than per waveform:
307  // map address of waveform to art pointer to that waveform
308  auto const& opDetWavePtrs
309  = util::mapDataProductPointers(event, waveformHandle);
310  */
311 
312 
313  //
314  // compute all the baselines
315  //
316  std::vector<icarus::WaveformBaseline> baselines;
317  baselines.reserve(waveforms.size());
318 
319  std::vector<lar::util::StatCollector<double>> averages;
320  if (fHBaselines || !fBaselinesVsTime.empty())
321  averages.resize(fNPlotChannels);
322 
323  art::Assns<icarus::WaveformBaseline, raw::OpDetWaveform> baselineToWaveforms;
324 
325  art::PtrMaker<icarus::WaveformBaseline> const makeBaselinePtr(event);
326 
327  for (auto const& [ iWaveform, waveform ]: util::enumerate(waveforms)) {
328  assert(iWaveform == baselines.size());
329 
331 
332  if (!averages.empty())
333  averages[waveform.ChannelNumber()].add(baseline.baseline());
334  baselines.push_back(baseline);
335 
336  baselineToWaveforms.addSingle(
337  makeBaselinePtr(iWaveform),
338  art::Ptr<raw::OpDetWaveform>(waveformHandle, iWaveform)
339  );
340 
341  } // for waveforms
342 
343  //
344  // plot filling
345  //
346  if (!averages.empty()) {
347 
348  double const eventTime = static_cast<double>(event.time().timeHigh())
349  + static_cast<double>(event.time().timeHigh()) * 1e-9;
350 
351  for (auto const& [ channel, stat ]: util::enumerate(averages)) {
352  if (stat.N() == 0) continue;
353 
354  double const aveBaseline = stat.Average();
355 
356  fHBaselines->Fill(double(channel), aveBaseline);
357 
358  if (channel < fBaselinesVsTime.size())
359  fBaselinesVsTime[channel].emplace_back(eventTime, aveBaseline);
360 
361  } // for baselines
362 
363  } // if plots
364 
365  //
366  // output
367  //
368  event.put(
369  std::make_unique<std::vector<icarus::WaveformBaseline>>
370  (std::move(baselines))
371  );
372  event.put(
373  std::make_unique<art::Assns<icarus::WaveformBaseline, raw::OpDetWaveform>>
374  (std::move(baselineToWaveforms))
375  );
376 
377 
378 } // icarus::PMTWaveformBaselines::produce()
std::vector< std::vector< std::pair< double, double > > > fBaselinesVsTime
For each channel, all event times and their baselines.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
BEGIN_PROLOG baseline
art::InputTag const fOpDetWaveformTag
Input optical waveform tag.
icarus::WaveformBaseline baselineFromMedian(raw::OpDetWaveform const &waveform) const
Extracts a baseline as median from a single waveform.
Class containing a waveform baseline value.
do i e
TH2 * fHBaselines
All baselines, per channel.
std::size_t fNPlotChannels
Number of plotted channels.
void icarus::PMTWaveformBaselines::setupPlots ( )
private

Creates all the plots to be filled by the module.

Definition at line 390 of file PMTWaveformBaselines_module.cc.

390  {
391 
392  auto const& tfs = *(art::ServiceHandle<art::TFileService>());
393  auto const& geom = *(lar::providerFrom<geo::Geometry const>());
394 
395  fNPlotChannels = geom.NOpChannels();
396 
397  fHBaselines = tfs.make<TH2F>(
398  "Baselines",
399  "PMT baseline;channel;baseline per channel [ / 8 ADC ]",
400  fNPlotChannels, 0.0, double(fNPlotChannels),
401  256, 13312.0, 15360.0
402  );
403 
404  // these are graphs, and it is more convenient to carry around their data
405  // in a vector than carrying around the graphs themselves;
406  // `buildBaselineGraphs()` will turn that data into graph at end of the job;
407  // here we just declare which channels we are going to plot.
408  fBaselinesVsTime.resize(fNPlotChannels);
409 
410 } // icarus::PMTWaveformBaselines::setupPlots()
std::vector< std::vector< std::pair< double, double > > > fBaselinesVsTime
For each channel, all event times and their baselines.
TH2 * fHBaselines
All baselines, per channel.
art::ServiceHandle< art::TFileService > tfs
std::size_t fNPlotChannels
Number of plotted channels.

Member Data Documentation

std::vector<std::vector<std::pair<double, double> > > icarus::PMTWaveformBaselines::fBaselinesVsTime
private

For each channel, all event times and their baselines.

Definition at line 205 of file PMTWaveformBaselines_module.cc.

double const icarus::PMTWaveformBaselines::fBaselineTimeAverage { 0.0 }
private

Width of baseline time profile binning [s].

Definition at line 185 of file PMTWaveformBaselines_module.cc.

TH2* icarus::PMTWaveformBaselines::fHBaselines = nullptr
private

All baselines, per channel.

Definition at line 202 of file PMTWaveformBaselines_module.cc.

std::string const icarus::PMTWaveformBaselines::fLogCategory
private

Category name for the console output stream.

Definition at line 187 of file PMTWaveformBaselines_module.cc.

std::size_t icarus::PMTWaveformBaselines::fNPlotChannels = 0U
private

Number of plotted channels.

Definition at line 201 of file PMTWaveformBaselines_module.cc.

art::InputTag const icarus::PMTWaveformBaselines::fOpDetWaveformTag
private

Input optical waveform tag.

Definition at line 180 of file PMTWaveformBaselines_module.cc.

bool icarus::PMTWaveformBaselines::fPlotBaselines
private

Whether to produce plots.

Definition at line 182 of file PMTWaveformBaselines_module.cc.


The documentation for this class was generated from the following file: