LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DetectorClocksData.h
Go to the documentation of this file.
1 #ifndef LARDATAALG_DETECTORINFO_DETECTORCLOCKSDATA_H
2 #define LARDATAALG_DETECTORINFO_DETECTORCLOCKSDATA_H
3 
5 
6 namespace detinfo {
7 
283  public:
325  DetectorClocksData(double const g4_ref_time,
326  double const trigger_offset_tpc,
327  double const trig_time,
328  double const beam_time,
329  ElecClock const& tpc_clock,
330  ElecClock const& optical_clock,
331  ElecClock const& trigger_clock,
332  ElecClock const& external_clock)
333  : fTriggerTime{trig_time}
334  , fTriggerOffsetTPC{trigger_offset_tpc}
335  , fBeamGateTime{beam_time}
336  , fG4RefTime{g4_ref_time}
337  , fTPCClock{tpc_clock}
338  , fOpticalClock{optical_clock}
339  , fTriggerClock{trigger_clock}
340  , fExternalClock{external_clock}
341  {}
342 
348  double TriggerOffsetTPC() const
349  {
350  if (fTriggerOffsetTPC < 0)
351  return fTriggerOffsetTPC;
352  else
353  return -fTriggerOffsetTPC / fTPCClock.Frequency(); // convert ticks to
354  // us
355  }
356 
359  double TPCTime() const { return doTPCTime(); }
360 
363  double G4ToElecTime(double const g4_time) const { return g4_time * 1.e-3 - fG4RefTime; }
364 
366  double TriggerTime() const { return fTriggerTime; }
367 
369  double BeamGateTime() const { return fBeamGateTime; }
370 
371  //
372  // Getters of TPC ElecClock
373  //
375  ElecClock const& TPCClock() const noexcept { return fTPCClock; }
376 
377  //
378  // Getters of Optical ElecClock
379  //
381  ElecClock const& OpticalClock() const noexcept { return fOpticalClock; }
382 
383  //
384  // Getters of Trigger ElecClock
385  //
387  ElecClock const& TriggerClock() const noexcept { return fTriggerClock; }
388 
389  //
390  // Getters of External ElecClock
391  //
393  ElecClock const& ExternalClock() const noexcept { return fExternalClock; }
394 
395  //
396  // Getters for time [us] w.r.t. trigger given information from waveform
397  //
398 
401  double TPCTick2TrigTime(double const tick) const
402  {
403  return fTPCClock.TickPeriod() * tick + TriggerOffsetTPC();
404  }
407  double TPCTick2BeamTime(double const tick) const
408  {
409  return TPCTick2TrigTime(tick) + TriggerTime() - BeamGateTime();
410  }
413  double OpticalTick2TrigTime(double const tick, size_t const sample, size_t const frame) const
414  {
415  return fOpticalClock.TickPeriod() * tick + fOpticalClock.Time(sample, frame) - TriggerTime();
416  }
419  double OpticalTick2BeamTime(double const tick, size_t const sample, size_t const frame) const
420  {
421  return fOpticalClock.TickPeriod() * tick + fOpticalClock.Time(sample, frame) - BeamGateTime();
422  }
425  double ExternalTick2TrigTime(double const tick, size_t const sample, size_t const frame) const
426  {
427  return fExternalClock.TickPeriod() * tick + fExternalClock.Time(sample, frame) -
428  TriggerTime();
429  }
432  double ExternalTick2BeamTime(double const tick, size_t const sample, size_t const frame) const
433  {
434  return fExternalClock.TickPeriod() * tick + fExternalClock.Time(sample, frame) -
435  BeamGateTime();
436  }
437 
439  double Time2Tick(double const time) const { return doTime2Tick(time); }
440 
441  //
442  // Getters for time [tdc] (electronics clock counting ... in double
443  // precision)
444  //
445 
448  double TPCTick2TDC(double const tick) const
449  {
450  return (doTPCTime() / fTPCClock.TickPeriod() + tick);
451  }
454  double TPCG4Time2TDC(double const g4time) const
455  {
456  return G4ToElecTime(g4time) / fTPCClock.TickPeriod();
457  }
460  double OpticalTick2TDC(double const tick, size_t const sample, size_t const frame) const
461  {
462  return fOpticalClock.Ticks(sample, frame) + tick;
463  }
466  double OpticalG4Time2TDC(double const g4time) const
467  {
468  return G4ToElecTime(g4time) / fOpticalClock.TickPeriod();
469  }
472  double ExternalTick2TDC(double const tick, size_t const sample, size_t const frame) const
473  {
474  return fExternalClock.Ticks(sample, frame) + tick;
475  }
478  double ExternalG4Time2TDC(double const g4time) const
479  {
480  return G4ToElecTime(g4time) / fExternalClock.TickPeriod();
481  }
482 
483  //
484  // Getters for time [us] (electronics clock counting ... in double
485  // precision)
486  //
488  double TPCTick2Time(double const tick) const
489  {
490  return doTPCTime() + tick * fTPCClock.TickPeriod();
491  }
494  double OpticalTick2Time(double const tick, size_t const sample, size_t const frame) const
495  {
496  return fOpticalClock.Time(sample, frame) + tick * fOpticalClock.TickPeriod();
497  }
500  double ExternalTick2Time(double const tick, size_t const sample, size_t const frame) const
501  {
502  return fExternalClock.Time(sample, frame) + tick * fExternalClock.TickPeriod();
503  }
504 
505  //
506  // Getters for time [ticks] (waveform index number)
507  //
508 
510  double TPCTDC2Tick(double const tdc) const
511  {
512  return (tdc - doTPCTime() / fTPCClock.TickPeriod());
513  }
515  double TPCG4Time2Tick(double const g4time) const
516  {
517  return (G4ToElecTime(g4time) - doTPCTime()) / fTPCClock.TickPeriod();
518  }
519 
520  template <typename Stream>
521  void debugReport(Stream& out) const
522  {
523  out << "Trigger time @ " << fTriggerTime << "\nBeamGate time @ " << fBeamGateTime
524  << "\nTrigOffsetTPC @ " << TriggerOffsetTPC() << "\nG4RefTime @ " << fG4RefTime
525  << "\nTPC Freq. @ " << fTPCClock.Frequency() << "\nOptical Freq. @ "
526  << fOpticalClock.Frequency() << "\nTrigger Freq. @ " << fTriggerClock.Frequency()
527  << "\nExternal Freq. @ " << fExternalClock.Frequency()
528  << "\nTPC start tick [tdc] : " << TPCTick2TDC(0)
529  << "\nTPC start tick from trigger [us] : " << TPCTick2TrigTime(0)
530  << "\nTPC start tick from beam [us] : " << TPCTick2BeamTime(0)
531  << "\nTPC tdc=0 in tick : " << TPCTDC2Tick(0)
532  << "\nTPC G4 time 0 in tick : " << TPCG4Time2Tick(0)
533  << "\nTrigger in TPC tick : " << Time2Tick(TriggerTime()) << "\n";
534  }
535 
536  private:
538  double fTriggerTime;
539 
542 
545 
547  double fG4RefTime;
548 
553 
555  double doTPCTime() const { return fTriggerTime + fTriggerOffsetTPC; }
556 
558  double doTime2Tick(double const time) const
559  {
560  return (time - doTPCTime()) / fTPCClock.TickPeriod();
561  }
562 
563  }; // class DetectorClocksData
564 
565  inline int trigger_offset(DetectorClocksData const& data)
566  {
567  return data.TPCClock().Ticks(data.TriggerOffsetTPC() * -1.);
568  }
569 
575  inline double sampling_rate(DetectorClocksData const& data)
576  {
577  return data.TPCClock().TickPeriod() * 1.e3;
578  }
579 
580 } // namespace detinfo
581 
582 #endif // LARDATAALG_DETECTORINFO_DETECTORCLOCKSDATA_H
double OpticalTick2TrigTime(double const tick, size_t const sample, size_t const frame) const
double TPCTick2BeamTime(double const tick) const
double fTriggerOffsetTPC
Time offset from trigger to TPC readout start.
double ExternalTick2BeamTime(double const tick, size_t const sample, size_t const frame) const
double OpticalTick2BeamTime(double const tick, size_t const sample, size_t const frame) const
double TPCG4Time2Tick(double const g4time) const
Given G4 time returns electronics clock count [tdc].
double TPCTick2Time(double const tick) const
Given TPC time-tick (waveform index), returns electronics clock [us].
ElecClock const & TriggerClock() const noexcept
Borrow a const Trigger clock with time set to Trigger time [us].
double TPCTDC2Tick(double const tdc) const
Given electronics clock count [tdc] returns TPC time-tick.
constexpr int Ticks() const noexcept
Current clock tick (that is, the number of tick Time() falls in).
Definition: ElecClock.h:182
double fBeamGateTime
BeamGate time in [us].
constexpr double TickPeriod() const noexcept
A single tick period in microseconds.
Definition: ElecClock.h:310
double doTPCTime() const
Implementation of TPCTime().
double fG4RefTime
Electronics clock counting start time in G4 time frame [us].
double BeamGateTime() const
Beam gate electronics clock time in [us].
double fTriggerTime
Trigger time in [us].
double TPCG4Time2TDC(double const g4time) const
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:73
ElecClock const & TPCClock() const noexcept
Borrow a const TPC clock with time set to Trigger time [us].
double OpticalTick2TDC(double const tick, size_t const sample, size_t const frame) const
ElecClock const & OpticalClock() const noexcept
Borrow a const Optical clock with time set to Trigger time [us].
constexpr double Time() const noexcept
Current time (as stored) in microseconds.
Definition: ElecClock.h:132
General LArSoft Utilities.
double TriggerTime() const
Trigger electronics clock time in [us].
DetectorClocksData(double const g4_ref_time, double const trigger_offset_tpc, double const trig_time, double const beam_time, ElecClock const &tpc_clock, ElecClock const &optical_clock, ElecClock const &trigger_clock, ElecClock const &external_clock)
Returns a complete detinfo::DetectorClocksData object.
double ExternalG4Time2TDC(double const g4time) const
double G4ToElecTime(double const g4_time) const
double OpticalG4Time2TDC(double const g4time) const
Contains all timing reference information for the detector.
double ExternalTick2TDC(double const tick, size_t const sample, size_t const frame) const
double OpticalTick2Time(double const tick, size_t const sample, size_t const frame) const
double ExternalTick2TrigTime(double const tick, size_t const sample, size_t const frame) const
int trigger_offset(DetectorClocksData const &data)
constexpr double Frequency() const
Frequency in MHz.
Definition: ElecClock.h:176
Class def header for a class ElecClock.
ElecClock const & ExternalClock() const noexcept
Borrow a const Trigger clock with time set to External Time [us].
double TPCTick2TrigTime(double const tick) const
double doTime2Tick(double const time) const
Implementation of Time2Tick().
Class representing the time measured by an electronics clock.
Definition: ElecClock.h:91
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
void debugReport(Stream &out) const
double TPCTick2TDC(double const tick) const
double Time2Tick(double const time) const
Returns the specified electronics time in TDC electronics ticks.
double ExternalTick2Time(double const tick, size_t const sample, size_t const frame) const