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

Produces discriminated optical waveforms. More...

Inheritance diagram for icarus::trigger::DiscriminatePMTwaveforms:

Classes

struct  Config
 

Public Types

using TriggerGateData_t = icarus::trigger::OpticalTriggerGate::GateData_t
 The type of data produced for a single channel. More...
 
using Parameters = art::EDProducer::Table< Config >
 

Public Member Functions

 DiscriminatePMTwaveforms (Parameters const &config)
 
 DiscriminatePMTwaveforms (DiscriminatePMTwaveforms const &)=delete
 
 DiscriminatePMTwaveforms (DiscriminatePMTwaveforms &&)=delete
 
DiscriminatePMTwaveformsoperator= (DiscriminatePMTwaveforms const &)=delete
 
DiscriminatePMTwaveformsoperator= (DiscriminatePMTwaveforms &&)=delete
 
virtual void produce (art::Event &event) override
 Creates the data products. More...
 

Private Member Functions

icarus::trigger::TriggerGateBuilder::TriggerGates::GateData_t fillChannelGaps (icarus::trigger::TriggerGateBuilder::TriggerGates::GateData_t gates) const
 Creates a collection with one gate per channel and no gaps. More...
 

Static Private Member Functions

static unsigned int getNOpDetChannels (fhicl::OptionalAtom< unsigned int > const &param)
 Fetches the optical detector count from geometry unless in param. More...
 

Private Attributes

art::InputTag const fOpDetWaveformTag
 Input optical waveform tag. More...
 
std::optional< art::InputTag >
const 
fBaselineTag
 
std::optional< float > const fBaseline
 A constant baseline level. More...
 
unsigned int const fNOpDetChannels
 Number of optical detector channels. More...
 
std::map
< icarus::trigger::ADCCounts_t,
std::string > 
fSelectedThresholds
 Thresholds selected for saving, and their instance name. More...
 
bool const fSavePMTcoverage
 Whether to save also sbn::OpDetWaveformMeta. More...
 
std::string const fLogCategory
 Category name for the console output stream. More...
 
std::unique_ptr
< icarus::trigger::TriggerGateBuilder
fTriggerGateBuilder
 Algorithms to simulate trigger gates out of optical channel output. More...
 

Detailed Description

Produces discriminated optical waveforms.

This module produces a "discriminated waveform" for each optical detector channel and for each configured threshold, via an algorithm of the class of icarus::trigger::TriggerGateBuilder (TriggerGateBuilder configuration parameter).

Thresholds are ultimately chosen by the tool in charge of actually run the discrimination algorithm. Out of the thresholds that this algorithm produces, it is possible to choose only a subset of them (SelectThresholds).

Output data products

Input data products

Service requirements

The following services are required:

Configuration parameters

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

Definition at line 151 of file DiscriminatePMTwaveforms_module.cc.

Member Typedef Documentation

Definition at line 211 of file DiscriminatePMTwaveforms_module.cc.

The type of data produced for a single channel.

Definition at line 156 of file DiscriminatePMTwaveforms_module.cc.

Constructor & Destructor Documentation

icarus::trigger::DiscriminatePMTwaveforms::DiscriminatePMTwaveforms ( Parameters const &  config)
explicit

Definition at line 304 of file DiscriminatePMTwaveforms_module.cc.

305  : art::EDProducer(config)
306  // configuration
307  , fOpDetWaveformTag(config().OpticalWaveforms())
308  , fBaselineTag(util::fhicl::getOptionalValue(config().Baselines))
309  , fBaseline(util::fhicl::getOptionalValue(config().Baseline))
311  , fSavePMTcoverage(config().SavePMTcoverage())
312  , fLogCategory(config().OutputCategory())
314  (
315  art::make_tool<icarus::trigger::TriggerGateBuilder>
316  (config().TriggerGateBuilder_.get<fhicl::ParameterSet>())
317  )
318 {
319  //
320  // optional configuration parameters
321  //
322  if (fBaseline && fBaselineTag) {
323  throw art::Exception(art::errors::Configuration)
324  << "Both `Baselines` ('" << fBaselineTag->encode()
325  << "') and `Baseline` (" << *fBaseline
326  << ") parameters specified, but they are exclusive!\n";
327  }
328  if (!fBaseline && !fBaselineTag) {
329  throw art::Exception(art::errors::Configuration)
330  << "Either `Baselines` or `Baseline` parameters is required.\n";
331  }
332 
333  std::vector<raw::ADC_Count_t> selectedThresholds;
334  if (!config().SelectThresholds(selectedThresholds)) {
335  std::vector<ADCCounts_t> const& allThresholds
336  = fTriggerGateBuilder->channelThresholds();
337 
338  if (allThresholds.empty()) {
339  throw art::Exception(art::errors::Configuration)
340  << "Trigger building algorithm reports no threshold!\n"
341  << "Check the configuration of `TriggerGateBuilder` tool.\n";
342  }
344  allThresholds.begin(), allThresholds.end(),
345  std::back_inserter(selectedThresholds),
347  );
348 
349  }
350  else if (selectedThresholds.empty()) {
351  throw art::Exception(art::errors::Configuration)
352  << "Configured to save no thresholds!\n"
353  << "Add values to the `SelectThresholds` configuration parameter.\n";
354  }
355 
356  for (auto const& threshold: selectedThresholds) {
358  = util::to_string(threshold);
359  }
360 
361  {
362  mf::LogInfo log(fLogCategory);
363  log << "Selected thresholds:";
364  for (auto const& [ threshold, instance ]: fSelectedThresholds)
365  log << " " << threshold << " (\"" << instance << "\")";
366  } // nameless block
367 
368  //
369  // declaration of input
370  //
371  consumes<std::vector<raw::OpDetWaveform>>(fOpDetWaveformTag);
372 
373  //
374  // declaration of output
375  //
376 
377  if (fSavePMTcoverage) {
378  produces<std::vector<sbn::OpDetWaveformMeta>>();
379  produces<art::Assns<raw::OpDetWaveform, sbn::OpDetWaveformMeta>>();
380  }
381  for (std::string const& instanceName: util::const_values(fSelectedThresholds))
382  {
383  produces<std::vector<TriggerGateData_t>>(instanceName);
384  produces<art::Assns<TriggerGateData_t, raw::OpDetWaveform>>(instanceName);
385  if (fSavePMTcoverage) {
386  produces<art::Assns<sbn::OpDetWaveformMeta, TriggerGateData_t>>
387  (instanceName);
388  }
389  } // for
390 
391 } // icarus::trigger::DiscriminatePMTwaveforms::DiscriminatePMTwaveforms()
unsigned int const fNOpDetChannels
Number of optical detector channels.
std::optional< typename Optional::value_type > getOptionalValue(Optional const &parameter)
Returns the value of an optional parameter as std::optional.
Definition: FHiCLutils.h:188
static constexpr Sample_t transform(Sample_t sample)
std::optional< float > const fBaseline
A constant baseline level.
std::unique_ptr< icarus::trigger::TriggerGateBuilder > fTriggerGateBuilder
Algorithms to simulate trigger gates out of optical channel output.
bool const fSavePMTcoverage
Whether to save also sbn::OpDetWaveformMeta.
decltype(auto) const_values(Coll &&coll)
Range-for loop helper iterating across the constant values of the specified collection.
const std::string instance
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
std::string const fLogCategory
Category name for the console output stream.
art::InputTag const fOpDetWaveformTag
Input optical waveform tag.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
A value measured in the specified unit.
Definition: quantities.h:566
static unsigned int getNOpDetChannels(fhicl::OptionalAtom< unsigned int > const &param)
Fetches the optical detector count from geometry unless in param.
physics producers discrimopdaq OpticalWaveforms
std::map< icarus::trigger::ADCCounts_t, std::string > fSelectedThresholds
Thresholds selected for saving, and their instance name.
icarus::trigger::DiscriminatePMTwaveforms::DiscriminatePMTwaveforms ( DiscriminatePMTwaveforms const &  )
delete
icarus::trigger::DiscriminatePMTwaveforms::DiscriminatePMTwaveforms ( DiscriminatePMTwaveforms &&  )
delete

Member Function Documentation

icarus::trigger::TriggerGateBuilder::TriggerGates::GateData_t icarus::trigger::DiscriminatePMTwaveforms::fillChannelGaps ( icarus::trigger::TriggerGateBuilder::TriggerGates::GateData_t  gates) const
private

Creates a collection with one gate per channel and no gaps.

Parameters
gatesthe trigger gates to be put in the collection
Returns
a collection with with one gate per channel and no gaps

The returned collection includes one gate per channel, and at least fNOpDetChannels channels (more if there are channels with higher number than that). For each channel, a gate is set in the item of the collection with index the channel ID (i.e. the first gate in the collection will be the one for channel 0, the next the one for channel 1 and so on). It is assumed that there is only at most one gate per channel. The gates specified in the argument are moved to the proper item in the returned collection. The other gates are assigned the proper channel number but are closed gates and associated with no waveform.

Definition at line 572 of file DiscriminatePMTwaveforms_module.cc.

573 {
574 
575  using GateDataColl_t
577  using Gate_t = GateDataColl_t::value_type; // TrackedOpticalTriggerGate
578 
579  //
580  // fill a map channel -> gate (missing channels have a nullptr gate)
581  //
582  std::vector<Gate_t const*> gateMap(fNOpDetChannels, nullptr);
583  for (Gate_t const& gate: gates) {
584  assert(!gate.channels().empty());
585 
586  auto const channel = gate.channels().front();
587  if (static_cast<std::size_t>(channel) >= gateMap.size())
588  gateMap.resize(channel + 1U, nullptr);
589  assert(gateMap[channel] == nullptr);
590  gateMap[channel] = &gate;
591 
592  } // for all gates
593 
594  //
595  // fill
596  //
597  GateDataColl_t allGates;
598  allGates.reserve(gateMap.size());
599  for (auto const& [ channelNo, gate ]: util::enumerate(gateMap)) {
600 
601  if (gate) {
602  assert(gate->channels().front() == channelNo);
603  allGates.push_back(std::move(*gate));
604  }
605  else {
606  allGates.emplace_back(
608  );
609  }
610 
611  } // for
612 
613  return allGates;
614 } // icarus::trigger::DiscriminatePMTwaveforms::fillChannelGaps()
unsigned int const fNOpDetChannels
Number of optical detector channels.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
Logical multi-level gate associated to one or more readout channels.
unsigned int icarus::trigger::DiscriminatePMTwaveforms::getNOpDetChannels ( fhicl::OptionalAtom< unsigned int > const &  param)
staticprivate

Fetches the optical detector count from geometry unless in param.

Definition at line 619 of file DiscriminatePMTwaveforms_module.cc.

620 {
621  unsigned int nChannels;
622  return
623  param(nChannels)? nChannels: lar::providerFrom<geo::Geometry>()->NOpDets();
624 } // icarus::trigger::DiscriminatePMTwaveforms::getNOpDetChannels()
DiscriminatePMTwaveforms& icarus::trigger::DiscriminatePMTwaveforms::operator= ( DiscriminatePMTwaveforms const &  )
delete
DiscriminatePMTwaveforms& icarus::trigger::DiscriminatePMTwaveforms::operator= ( DiscriminatePMTwaveforms &&  )
delete
void icarus::trigger::DiscriminatePMTwaveforms::produce ( art::Event &  event)
overridevirtual

Creates the data products.

Definition at line 395 of file DiscriminatePMTwaveforms_module.cc.

395  {
396 
397  //
398  // set up the algorithm to create the trigger gates
399  //
401  art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event)
402  };
404 
405  //
406  // fetch input
407  //
408  auto const& waveformHandle
409  = event.getValidHandle<std::vector<raw::OpDetWaveform>>(fOpDetWaveformTag);
410  auto const& waveforms = *waveformHandle;
411 
412  // map address of waveform to art pointer to that waveform
413  auto const& opDetWavePtrs
414  = util::mapDataProductPointers(event, waveformHandle);
415 
416  //
417  // retrieve the baseline information
418  //
419  std::vector<icarus::WaveformBaseline> fixedBaselines;
420  std::vector<icarus::WaveformBaseline> const* baselines = nullptr;
421  if (fBaselineTag) {
422  baselines =
423  &(event.getProduct<std::vector<icarus::WaveformBaseline>>(*fBaselineTag));
424  }
425  else {
426  fixedBaselines.resize
427  (waveforms.size(), icarus::WaveformBaseline{ *fBaseline });
428  baselines = &fixedBaselines;
429  }
430 
431  //
432  // provide each waveform with additional information: baseline
433  //
434  if (baselines->size() != waveforms.size()) {
435  assert(fBaselineTag);
436  throw cet::exception("DiscriminatePMTwaveforms")
437  << "Incompatible baseline information for the waveforms: "
438  << waveforms.size() << " waveforms (" << fOpDetWaveformTag.encode()
439  << ") for " << baselines->size() << " baselines ("
440  << fBaselineTag->encode() << ")!\n";
441  }
442  std::vector<icarus::trigger::WaveformWithBaseline> waveformInfo;
443  waveformInfo.reserve(waveforms.size());
444  for (auto const& [ waveform, baseline ]: util::zip(waveforms, *baselines))
445  waveformInfo.emplace_back(&waveform, &baseline);
446 
447  {
448  mf::LogDebug log { fLogCategory };
449  log << "Discrimination of " << waveforms.size() << " PMT waveforms from '"
450  << fOpDetWaveformTag.encode() << "'";
451  if (fBaselineTag)
452  log << " with baselines from '" << fBaselineTag->encode() << "'";
453  }
454 
455 
456  //
457  // define channel-level trigger gate openings as function on threshold
458  //
459 
460  // this is a collection where each entry (of type `TriggerGates`) contains
461  // the complete set of trigger gates for an event.
462  std::vector<icarus::trigger::TriggerGateBuilder::TriggerGates> const&
463  triggerGatesByThreshold = fTriggerGateBuilder->build(waveformInfo);
464 
465  { // nameless block
466  mf::LogTrace log(fLogCategory);
467  log << "Trigger gates from " << triggerGatesByThreshold.size()
468  << " thresholds:\n";
469  for (auto const& triggerGates: triggerGatesByThreshold)
470  triggerGates.dump(log);
471 
472  } // nameless block
473 
474 
475  //
476  // prepare output
477  //
478  std::optional<art::PtrMaker<sbn::OpDetWaveformMeta>> const makePMTinfoPtr
480  ? std::optional<art::PtrMaker<sbn::OpDetWaveformMeta>>(event)
481  : std::nullopt
482  ;
483 
485  : triggerGatesByThreshold
486  ) {
487 
488  ADCCounts_t const thr = gates.threshold();
489 
490  //
491  // find the threshold and its label, if we care of it
492  //
493  auto iThr = fSelectedThresholds.find(thr);
494  if (iThr == fSelectedThresholds.end()) continue; // not interested
495 
496  std::string const& instanceName = iThr->second;
497  art::PtrMaker<TriggerGateData_t> const makeGatePtr(event, instanceName);
498 
499  //
500  // reformat the results for the threshold
501  //
502  auto [ discrGates, waveGateAssns ]
504  (fillChannelGaps(std::move(gates).gates()), makeGatePtr, opDetWavePtrs)
505  ;
506 
507  if (fSavePMTcoverage) {
508  // replica of discriminated gate-waveform association replacing the latter
509  // with the PMT coverage with the same index as the waveform
510  assert(makePMTinfoPtr);
511  art::Assns<sbn::OpDetWaveformMeta, TriggerGateData_t> assns;
512  for (auto [ gatePtr, wavePtr ]: waveGateAssns)
513  assns.addSingle((*makePMTinfoPtr)(wavePtr.key()), gatePtr);
514  event.put(
515  std::make_unique<art::Assns<sbn::OpDetWaveformMeta, TriggerGateData_t>>
516  (std::move(assns)),
517  instanceName
518  );
519  } // if save PMT coverage
520 
521  //
522  // move the reformatted data into the event
523  //
524  event.put(
525  std::make_unique<std::vector<TriggerGateData_t>>(std::move(discrGates)),
526  instanceName
527  );
528  event.put(
529  std::make_unique<art::Assns<TriggerGateData_t, raw::OpDetWaveform>>
530  (std::move(waveGateAssns)),
531  instanceName
532  );
533 
534  } // for all extracted thresholds
535 
536 
537  // add a simple one-to-one PMT coverage - waveform association just in case
538  if (fSavePMTcoverage) {
539  assert(makePMTinfoPtr);
540 
541  sbn::OpDetWaveformMetaMaker const makePMTinfo { detTimings };
542 
543  std::vector<sbn::OpDetWaveformMeta> PMTinfo;
544  art::Assns<raw::OpDetWaveform, sbn::OpDetWaveformMeta> assns;
545  art::PtrMaker<raw::OpDetWaveform> const makeWavePtr
546  { event, waveformHandle.id() };
547 
548  for (auto const& [ iWaveform, waveform ]: util::enumerate(waveforms)) {
549 
550  PMTinfo.push_back(makePMTinfo(waveform));
551 
552  assns.addSingle(makeWavePtr(iWaveform), (*makePMTinfoPtr)(iWaveform));
553 
554  } // for
555 
556  event.put
557  (std::make_unique<std::vector<sbn::OpDetWaveformMeta>>(std::move(PMTinfo)));
558  event.put(
559  std::make_unique<art::Assns<raw::OpDetWaveform, sbn::OpDetWaveformMeta>>
560  (std::move(assns))
561  );
562 
563  } // if save PMT coverage
564 
565 
566 } // icarus::trigger::DiscriminatePMTwaveforms::produce()
std::optional< float > const fBaseline
A constant baseline level.
std::unique_ptr< icarus::trigger::TriggerGateBuilder > fTriggerGateBuilder
Algorithms to simulate trigger gates out of optical channel output.
bool const fSavePMTcoverage
Whether to save also sbn::OpDetWaveformMeta.
std::vector< icarus::trigger::OpticalTriggerGateData_t > transformIntoOpticalTriggerGate(Gates &&gates)
Returns the trigger gates in serializable format.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
std::string const fLogCategory
Category name for the console output stream.
icarus::trigger::TriggerGateBuilder::TriggerGates::GateData_t fillChannelGaps(icarus::trigger::TriggerGateBuilder::TriggerGates::GateData_t gates) const
Creates a collection with one gate per channel and no gaps.
util::quantities::counts_as< raw::ADC_Count_t > ADCCounts_t
ADC counts for optical detector readout.
Definition: TriggerTypes.h:40
Container of logical gates for all triggering channels for a threshold.
art::InputTag const fOpDetWaveformTag
Input optical waveform tag.
BEGIN_PROLOG baseline
Converter from raw::OpDetWaveform into sbn::OpDetWaveformMeta.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Class containing a waveform baseline value.
DataProductPointerMap_t< ArtHandleData_t< Handle > > mapDataProductPointers(art::Event const &event, Handle const &handle)
Creates a map from address of data product element to art pointer to it.
std::map< icarus::trigger::ADCCounts_t, std::string > fSelectedThresholds
Thresholds selected for saving, and their instance name.
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
fDetProps &fDetProps fDetProps &fDetProps detTimings

Member Data Documentation

std::optional<float> const icarus::trigger::DiscriminatePMTwaveforms::fBaseline
private

A constant baseline level.

Definition at line 244 of file DiscriminatePMTwaveforms_module.cc.

std::optional<art::InputTag> const icarus::trigger::DiscriminatePMTwaveforms::fBaselineTag
private

Definition at line 242 of file DiscriminatePMTwaveforms_module.cc.

std::string const icarus::trigger::DiscriminatePMTwaveforms::fLogCategory
private

Category name for the console output stream.

Definition at line 253 of file DiscriminatePMTwaveforms_module.cc.

unsigned int const icarus::trigger::DiscriminatePMTwaveforms::fNOpDetChannels
private

Number of optical detector channels.

Definition at line 246 of file DiscriminatePMTwaveforms_module.cc.

art::InputTag const icarus::trigger::DiscriminatePMTwaveforms::fOpDetWaveformTag
private

Input optical waveform tag.

Input waveform baseline tag.

Definition at line 239 of file DiscriminatePMTwaveforms_module.cc.

bool const icarus::trigger::DiscriminatePMTwaveforms::fSavePMTcoverage
private

Whether to save also sbn::OpDetWaveformMeta.

Definition at line 251 of file DiscriminatePMTwaveforms_module.cc.

std::map<icarus::trigger::ADCCounts_t, std::string> icarus::trigger::DiscriminatePMTwaveforms::fSelectedThresholds
private

Thresholds selected for saving, and their instance name.

Definition at line 249 of file DiscriminatePMTwaveforms_module.cc.

std::unique_ptr<icarus::trigger::TriggerGateBuilder> icarus::trigger::DiscriminatePMTwaveforms::fTriggerGateBuilder
private

Algorithms to simulate trigger gates out of optical channel output.

Definition at line 266 of file DiscriminatePMTwaveforms_module.cc.


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