Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
opdet::WaveformDigitizerSim Class Reference
Inheritance diagram for opdet::WaveformDigitizerSim:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Classes

struct  Config
 

Public Types

using Parameters = art::EDProducer::Table< Config >
 
- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 

Public Member Functions

 WaveformDigitizerSim (Parameters const &config)
 
void produce (art::Event &)
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void CreateSinglePEWaveform ()
 
double Pulse1PE (double time_in_us) const
 
void SetDefaultBeginEndTimes ()
 
void CheckFHiCLParameters () const
 
void AddPEsToWaveform (const sim::OpDetDivRec *dr_p, vector< double > &pdWaveform, FocusList &fls) const
 
void AddLineNoise (vector< double > &waveform, const FocusList &fls)
 
vector< uint16_t > Digitize (vector< double >::iterator itBegin, vector< double >::iterator itEnd) const
 
template<typename T >
Ranges_t CFDTrigger (vector< T > const &wf, const FocusList &fls) const
 
double Tick2us (size_t tick) const
 
double Tick2ns (size_t tick) const
 
size_t us2Tick (double time_in_us) const
 
size_t ns2Tick (double time_in_ns) const
 

Private Attributes

vector< art::InputTagfInputTags
 
double fVoltageToADC
 
double fPulseLength
 
double fPeakTime
 
double fMaxAmplitude
 
double fFrontTime
 
double fBackTime
 
size_t fPadding
 
size_t fReadoutWindow
 
size_t fPreTrigger
 
double fThresholdPE
 
size_t fDwindow
 
short fPedestal
 
double fLineNoiseRMS
 
int fMaxSaturationCutOff
 
double fTimeBegin
 
double fTimeEnd
 
bool fFullWaveformOutput
 
CLHEP::HepRandomEngine & fOpDigiEngine
 
CLHEP::RandGauss fRandGauss
 
double fSampleFreqMHz
 
size_t fPulseLengthTicks
 
double fThresholdADC
 
vector< double > fSinglePEWaveform
 

Additional Inherited Members

- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 122 of file WaveformDigitizerSim_module.cc.

Member Typedef Documentation

Definition at line 176 of file WaveformDigitizerSim_module.cc.

Constructor & Destructor Documentation

opdet::WaveformDigitizerSim::WaveformDigitizerSim ( Parameters const &  config)
explicit

Definition at line 293 of file WaveformDigitizerSim_module.cc.

294  : EDProducer{config}
295  , fInputTags{ config().InputTags() }
296 
299  , fPeakTime{ config().PeakTime() }
301  , fFrontTime{ config().FrontTime() }
302  , fBackTime{ config().BackTime() }
303 
304  , fPadding{ config().Padding() }
306  , fPreTrigger{ config().PreTrigger() }
307  , fThresholdPE{ config().Threshold() }
308  , fDwindow{ config().Dwindow() }
309 
310  , fPedestal{ config().Pedestal() }
313 
315 
317  "HepJamesRandom",
318  "waveformdigi",
319  config.get_PSet(),
320  "SeedWaveformDigi") )
322  {
323 
324  // This module produces (infrastructure piece)
325  produces< vector< raw::OpDetWaveform > >();
326 
327  for (auto tag: fInputTags) {
328  consumes< vector< sim::OpDetDivRec > >(tag);
329  }
330 
331  mf::LogInfo logger("WaveformDigitizerSim");
332 
333  // Get the optical clock frequency
334  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
335  fSampleFreqMHz = clockData.OpticalClock().Frequency();
336  logger << "Using a sampling frequency of " << fSampleFreqMHz << " MHz" << "\n";
337 
338 
339  // Creating a single photoelectron waveform template
340  // based on fhicl configuration
342  logger << "Requested pulse length of, " << fPulseLength << " us "
343  << "which is " << fPulseLengthTicks << " ticks" << "\n";
344  logger << "Requested PE threshold, " << std::fixed
346  << ", converted to ADC threshold "
347  << std::setprecision(0) << fThresholdADC << "\n";
348 
349 
350  // Set a dynamic range if given
351  short br;
352  if ( config().DynamicBitRange(br) ) {
353  fMaxSaturationCutOff = pow(2, br) - 1;
354  logger << "Limiting output to " << br << " bits" << "\n";
355  }
356 
357 
358  // Set earliest and latest allowed times
359  std::string tsource;
360  if (config().TimeBegin(fTimeBegin) && config().TimeEnd(fTimeEnd))
361  tsource = "override";
362  else {
363  tsource = "default";
365  }
366  logger << "Using " << tsource << " time limits on PD digitizer: " << fTimeBegin << " us to " << fTimeEnd << " us";
367 
368  // Check for valid configuration
370  }
base_engine_t & createEngine(seed_t seed)
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
constexpr T pow(T x)
Definition: pow.h:72
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
static Config * config
Definition: config.cpp:1054
static int max(int a, int b)
fhicl::Sequence< art::InputTag > InputTags

Member Function Documentation

void opdet::WaveformDigitizerSim::AddLineNoise ( vector< double > &  waveform,
const FocusList fls 
)
private

Definition at line 543 of file WaveformDigitizerSim_module.cc.

544  {
545  if (fLineNoiseRMS <= 0.0) return;
546 
547  for (auto p: fls.ranges) {
548  for(auto k = p.first; k <= p.second; ++k){
549  waveform[k] += fRandGauss.fire(0, fLineNoiseRMS);
550  }
551  }
552  }
p
Definition: test.py:223
void opdet::WaveformDigitizerSim::AddPEsToWaveform ( const sim::OpDetDivRec dr_p,
vector< double > &  pdWaveform,
FocusList fls 
) const
private

Definition at line 508 of file WaveformDigitizerSim_module.cc.

511  {
512  // Vector of DivRec time bins (struct OpDet_Time_Chans)
513  for (auto odtc: dr_p->GetTimeChans()) {
514 
515  // Extract time for this odtc within the event
516  double photonTime_ns = odtc.time;
517  size_t timeBin = ns2Tick(photonTime_ns);
518 
519  // Check if the photon is inside the digitization range. If not, skip it.
520  if ( timeBin < 0 || timeBin >= pdWaveform.size() ) {
521  mf::LogWarning("WaveformDigitizerSim") << "Skipping a photon at " << photonTime_ns/1000. << " us, outside digitization window of " << fTimeBegin << " to " << fTimeEnd;
522  continue;
523  }
524 
525  // Loop through records at this time and count photons
526  int nPE = 0;
527  for (auto const& sdp : odtc.phots)
528  nPE += sdp.phot;
529 
530  // Add ticks until the end of the single PE waveform or end of the whole pdWaveform
531  size_t stop = std::min(fPulseLengthTicks, pdWaveform.size()-timeBin);
532 
533  // Add this range to the focus list
534  fls.AddRange(timeBin, timeBin+stop-1);
535 
536  // Add the nPE pulse to the waveform
537  for (size_t tick = 0; tick < stop; ++tick)
538  pdWaveform[timeBin+tick] += fSinglePEWaveform[tick]*nPE;
539  }
540  }
Time_Chans_t const & GetTimeChans() const
Definition: OpDetDivRec.h:101
size_t size
Definition: lodepng.cpp:55
size_t ns2Tick(double time_in_ns) const
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
template<typename T >
Ranges_t opdet::WaveformDigitizerSim::CFDTrigger ( vector< T > const &  wf,
const FocusList fls 
) const
private

Definition at line 568 of file WaveformDigitizerSim_module.cc.

569  {
570 
571  Ranges_t readouts;
572 
573  for (auto range: fls.ranges) {
574  size_t wstart = -1;
575  size_t wend = -1;
576  bool fire = false;
577 
578  for (size_t tick = range.first; tick < range.second - fDwindow; ++tick) {
579 
580  // Fire CFD
581  if (wf[tick+fDwindow] - wf[tick] > fThresholdADC) {
582 
583  if (!fire) {
584  // Start a new readout window
585  fire = true;
586  wstart = tick-fPreTrigger;
587  wend = tick-fPreTrigger+fReadoutWindow;
588  }
589  else {
590  // Extend the current readout window
591  // Simplest to implement here, update to the
592  // actual DAPHNE algorithm once known
594  }
595 
596  }
597  else if (fire && tick >= wend) {
598  // We've reached the end of a window, save it
599  fire = false;
600  readouts.emplace_back(wstart, wend);
601  }
602 
603  }
604 
605  // Check for lingering window, add a final window
606  // up to the end of the waveform if so.
607  if (fire == true) {
608  readouts.emplace_back(wstart, range.second-1);
609  }
610  }
611 
612  return readouts;
613  }
std::vector< std::pair< size_t, size_t > > Ranges_t
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
void opdet::WaveformDigitizerSim::CheckFHiCLParameters ( ) const
private

Definition at line 418 of file WaveformDigitizerSim_module.cc.

419  {
420  // Check that we have input tags
421  if (fInputTags.size() == 0)
423  << "No input tags were given to WaveformDigitizerSim.\n";
424 
425  // Sanity check the line noise
426  if (fLineNoiseRMS < 0.0)
428  << "fLineNoiseRMS: " << fLineNoiseRMS << '\n'
429  << "Line noise RMS should be non-negative!\n";
430 
431  // Sanity check beginning and end times
432  if (fTimeBegin >= fTimeEnd) {
434  << "TimeBegin: " << fTimeBegin << " and " << "TimeEnd: " << fTimeEnd << '\n'
435  << "TimeBegin should be less than TimeEnd!\n";
436  }
437  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void opdet::WaveformDigitizerSim::CreateSinglePEWaveform ( )
private

Definition at line 373 of file WaveformDigitizerSim_module.cc.

374  {
375  double maxADC = 0.;
378 
379  for (size_t tick = 0; tick < fPulseLengthTicks; ++tick) {
380  double val = Pulse1PE(static_cast< double >(tick)/fSampleFreqMHz);
382  if (val > maxADC) maxADC = val;
383  }
384 
385  // Set the ADC threshold based on the PE threshold
386  fThresholdADC = fThresholdPE * maxADC;
387  }
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
double Pulse1PE(double time_in_us) const
vector< uint16_t > opdet::WaveformDigitizerSim::Digitize ( vector< double >::iterator  itBegin,
vector< double >::iterator  itEnd 
) const
private

Definition at line 555 of file WaveformDigitizerSim_module.cc.

556  {
557  for(auto it = itBegin; it != itEnd; ++it) {
558  if(*it > fMaxSaturationCutOff)
559  *it = fMaxSaturationCutOff;
560  }
561 
562  // Don't bother to round properly, it's faster this way
563  return vector< uint16_t >(itBegin, itEnd);
564  }
size_t opdet::WaveformDigitizerSim::ns2Tick ( double  time_in_ns) const
inlineprivate

Definition at line 272 of file WaveformDigitizerSim_module.cc.

272 { return us2Tick(time_in_ns/1000.); };
size_t us2Tick(double time_in_us) const
void opdet::WaveformDigitizerSim::produce ( art::Event event)
virtual

Implements art::EDProducer.

Definition at line 448 of file WaveformDigitizerSim_module.cc.

449  {
450  // A pointer that will store produced OpDetWaveforms
451  auto wave_forms_p = std::make_unique< vector< raw::OpDetWaveform > >();
452 
453  // Total number of ticks in the whole event
454  unsigned int nSamples = (fTimeEnd - fTimeBegin)*fSampleFreqMHz;
455 
456  // First, pull all of the DivRec handles from the event, and collect up
457  // all DivRecs on the same channel into a single vector
458  std::map< int, vector<const sim::OpDetDivRec *> > DivRecsByChannel;
459  for (auto tag: fInputTags) {
460  auto dr_handle = event.getHandle< vector< sim::OpDetDivRec > >(tag);
461  if (!dr_handle) {
462  mf::LogWarning("WaveformDigitizerSim") << "Could not load OpDetDivRecs " << tag << ". Skipping.";
463  continue;
464  }
465  for (auto const& dr : *dr_handle) {
466  DivRecsByChannel[dr.OpDetNum()].push_back( &dr );
467  }
468  }
469 
470  // Now, loop through channels, treating all photons on a cha
471  for (auto const& [opDet, vDivRecs]: DivRecsByChannel)
472  {
473  // Create the empty waveform vector and focus list
474  vector< double > pdWaveform(nSamples, fPedestal);
475  FocusList fls(nSamples, fPadding);
476 
477  // Add a PE template to the waveform for each true photon
478  for (auto dr_p: vDivRecs) AddPEsToWaveform(dr_p, pdWaveform, fls);
479 
480  // So that line noise is added to all ticks in full output mode
481  if (fFullWaveformOutput) fls.everything();
482 
483  // Add line noise
484  AddLineNoise(pdWaveform, fls);
485 
486  if (fFullWaveformOutput) {
487  wave_forms_p->emplace_back(Tick2us(0), opDet, Digitize(pdWaveform.begin(), pdWaveform.end()));
488  }
489  else {
490  // Checking for tiggers on floats, rather than shorts.
491  // This is an approximation, but it saves making an extra copy
492  // of the waveform and makes the code easier to follow.
493  for ( auto t: CFDTrigger(pdWaveform, fls) ) {
494 
495  // Digitize and store
496  auto shortWF = Digitize(pdWaveform.begin()+t.first, pdWaveform.begin()+t.second+1);
497  wave_forms_p->emplace_back(Tick2us(t.first), opDet, shortWF);
498  }
499  }
500  }
501 
502  // Push the OpDetWaveforms into the event
503  event.put(std::move(wave_forms_p));
504 
505  }
void AddLineNoise(vector< double > &waveform, const FocusList &fls)
def move(depos, offset)
Definition: depos.py:107
Ranges_t CFDTrigger(vector< T > const &wf, const FocusList &fls) const
void AddPEsToWaveform(const sim::OpDetDivRec *dr_p, vector< double > &pdWaveform, FocusList &fls) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
vector< uint16_t > Digitize(vector< double >::iterator itBegin, vector< double >::iterator itEnd) const
double opdet::WaveformDigitizerSim::Pulse1PE ( double  time_in_us) const
private

Definition at line 390 of file WaveformDigitizerSim_module.cc.

void opdet::WaveformDigitizerSim::SetDefaultBeginEndTimes ( )
private

Definition at line 401 of file WaveformDigitizerSim_module.cc.

402  {
403  // A little wasteful to get clockData again, but only happens once per job
404  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
405  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clockData);
406 
407  // Take the TPC readout window size and convert to us with the electronics
408  // clock frequency, adding 5 us of padding
409  fTimeEnd = detProp.ReadOutWindowSize() / clockData.TPCClock().Frequency() + 5;
410 
411  // Assume the readout is symmetrical around 0
412  fTimeBegin = -1.*fTimeEnd;
413 
414  }
double opdet::WaveformDigitizerSim::Tick2ns ( size_t  tick) const
inlineprivate

Definition at line 270 of file WaveformDigitizerSim_module.cc.

270 { return 1000.*Tick2us(tick); };
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
double opdet::WaveformDigitizerSim::Tick2us ( size_t  tick) const
inlineprivate

Definition at line 269 of file WaveformDigitizerSim_module.cc.

269 { return fTimeBegin + static_cast<double>(tick)/fSampleFreqMHz; };
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
size_t opdet::WaveformDigitizerSim::us2Tick ( double  time_in_us) const
inlineprivate

Definition at line 271 of file WaveformDigitizerSim_module.cc.

271 { return static_cast<size_t>(std::round( (time_in_us-fTimeBegin)*fSampleFreqMHz) ); }

Member Data Documentation

double opdet::WaveformDigitizerSim::fBackTime
private

Definition at line 195 of file WaveformDigitizerSim_module.cc.

size_t opdet::WaveformDigitizerSim::fDwindow
private

Definition at line 202 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fFrontTime
private

Definition at line 194 of file WaveformDigitizerSim_module.cc.

bool opdet::WaveformDigitizerSim::fFullWaveformOutput
private

Definition at line 214 of file WaveformDigitizerSim_module.cc.

vector<art::InputTag> opdet::WaveformDigitizerSim::fInputTags
private

Definition at line 187 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fLineNoiseRMS
private

Definition at line 208 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fMaxAmplitude
private

Definition at line 193 of file WaveformDigitizerSim_module.cc.

int opdet::WaveformDigitizerSim::fMaxSaturationCutOff
private

Definition at line 209 of file WaveformDigitizerSim_module.cc.

CLHEP::HepRandomEngine& opdet::WaveformDigitizerSim::fOpDigiEngine
private

Definition at line 222 of file WaveformDigitizerSim_module.cc.

size_t opdet::WaveformDigitizerSim::fPadding
private

Definition at line 198 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fPeakTime
private

Definition at line 192 of file WaveformDigitizerSim_module.cc.

short opdet::WaveformDigitizerSim::fPedestal
private

Definition at line 207 of file WaveformDigitizerSim_module.cc.

size_t opdet::WaveformDigitizerSim::fPreTrigger
private

Definition at line 200 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fPulseLength
private

Definition at line 191 of file WaveformDigitizerSim_module.cc.

size_t opdet::WaveformDigitizerSim::fPulseLengthTicks
private

Definition at line 226 of file WaveformDigitizerSim_module.cc.

CLHEP::RandGauss opdet::WaveformDigitizerSim::fRandGauss
private

Definition at line 223 of file WaveformDigitizerSim_module.cc.

size_t opdet::WaveformDigitizerSim::fReadoutWindow
private

Definition at line 199 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fSampleFreqMHz
private

Definition at line 225 of file WaveformDigitizerSim_module.cc.

vector< double > opdet::WaveformDigitizerSim::fSinglePEWaveform
private

Definition at line 230 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fThresholdADC
private

Definition at line 227 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fThresholdPE
private

Definition at line 201 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fTimeBegin
private

Definition at line 212 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fTimeEnd
private

Definition at line 213 of file WaveformDigitizerSim_module.cc.

double opdet::WaveformDigitizerSim::fVoltageToADC
private

Definition at line 190 of file WaveformDigitizerSim_module.cc.


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