DetectorClocksStandardGAr.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // DetectorClocks.h
4 //
5 // This class provides electronics various electronics clocks. Currently supports
6 // three types of clocks: TPC, Optical, and Trigger in order to support the
7 // MicroBooNE experiment.
8 //
9 // Formally known as TimeService.
10 //
11 ////////////////////////////////////////////////////////////////////////
12 
13 #ifndef DETINFO_DETCLOCKSSTD_H
14 #define DETINFO_DETCLOCKSSTD_H
15 
16 #include "fhiclcpp/ParameterSet.h"
17 
18 #include "DetectorInfo/DetectorClocks.h"
20 
21 namespace gar {
22  namespace detinfo{
23 
25 
26  public:
31 
32  bool Configure(fhicl::ParameterSet const& pset);
33  bool Update(uint64_t ts=0);
34 
35  virtual double TriggerOffsetTPC() const
36  {
37  if (fTriggerOffsetTPC<0)
38  return fTriggerOffsetTPC;
39  else
40  return -fTriggerOffsetTPC/fTPCClock.Frequency(); //convert ticks to us
41  }
42 
43  void debugReport() const;
44 
46 
47  /// Given Geant4 time [ns], returns relative time [ns] w.r.t. electronics time T0
48  virtual double G4ToElecTime(double g4_time) const {return g4_time - fG4RefTime; }
49 
50  /// Trigger electronics clock time in [us]
51  virtual double TriggerTime() const { return fTriggerTime; }
52 
53  /// Beam gate electronics clock time in [us]
54  virtual double BeamGateTime() const { return fBeamGateTime; }
55 
56  // Beam spill duration in ns.
57  virtual double SpillLength() const { return fSpillLength; }
58 
59 
60  virtual std::vector<std::string> ConfigNames() const { return fConfigName; }
61  virtual std::vector<double> ConfigValues() const { return fConfigValue; }
62 
63  void SetConfigValue(size_t i, double val) { fConfigValue[i] = val; }
64 
65  /// Setter for trigger times
66  virtual void SetTriggerTime(double trig_time, double beam_time)
67  {
68  fTriggerTime = trig_time;
69  fBeamGateTime = beam_time;
70  fTPCClock.SetTime(trig_time);
71  fTriggerClock.SetTime(trig_time);
72  }
73  virtual void SetSpillLength(double spillLength) { fSpillLength = spillLength; }
74 
75  //
76  // Getters of TPC ElecClock
77  //
78  /// Borrow a const TPC clock with time set to Trigger time [us]
79  virtual const ElecClock& TPCClock() const
80  { return fTPCClock; }
81 
82  /// Create a TPC clock for a given time [us] from clock counting start
83  virtual ElecClock TPCClock(double time) const
85 
86  /// Create a TPC clock for a given sample/frame number in TPC clock frequency
87  detinfo::ElecClock TPCClock(unsigned int sample,
88  unsigned int frame) const
89  { detinfo::ElecClock clock = TPCClock(); clock.SetTime(sample,frame); return clock; }
90 
91  //
92  // Getters of Trigger ElecClock
93  //
94  /// Borrow a const Trigger clock with time set to Trigger time [us]
95  virtual const detinfo::ElecClock& TriggerClock() const
96  { return fTriggerClock; }
97 
98  /// Create a Trigger clock for a given time [us] from clock counting start
99  virtual detinfo::ElecClock TriggerClock(double time) const
101 
102  /// Create a Trigger clock for a given sample/frame number in Trigger clock frequency
103  virtual detinfo::ElecClock TriggerClock(unsigned int sample,
104  unsigned int frame) const
105  { detinfo::ElecClock clock = TriggerClock(); clock.SetTime(sample,frame); return clock; }
106 
107  //
108  // Getters of External ElecClock
109  //
110  /// Borrow a const Trigger clock with time set to External Time [us]
111  virtual const detinfo::ElecClock& ExternalClock() const
112  { return fExternalClock; }
113 
114  /// Create a External clock for a given time [us] from clock counting start
115  virtual detinfo::ElecClock ExternalClock(double time) const
117 
118  /// Create a External clock for a given sample/frame number in External clock frequency
119  virtual detinfo::ElecClock ExternalClock(unsigned int sample,
120  unsigned int frame) const
121  { detinfo::ElecClock clock = ExternalClock(); clock.SetTime(sample,frame); return clock; }
122 
123  //
124  // Getters for time [ns] w.r.t. trigger given information from waveform
125  //
126 
127 
128  /// Given TPC time-tick (waveform index), returns time [ns] w.r.t. trigger time stamp
129  virtual double TPCTick2TrigTime(double tick) const
130  { return fTPCClock.TickPeriod() * tick + TriggerOffsetTPC(); }
131 
132  /// Given TPC time-tick (waveform index), returns time [ns] w.r.t. beam gate time
133  virtual double TPCTick2BeamTime(double tick) const
134  { return fTPCClock.TickPeriod() * tick + TriggerOffsetTPC() + TriggerTime() - BeamGateTime(); }
135 
136  /// Given External time-tick (waveform index), sample and frame number, returns time [ns] w.r.t. trigger time stamp
137  virtual double ExternalTick2TrigTime(double tick, size_t sample, size_t frame) const
138  { return fExternalClock.TickPeriod() * tick + fExternalClock.Time(sample,frame) - TriggerTime(); }
139 
140  /// Given External time-tick (waveform index), sample and frame number, returns time [ns] w.r.t. beam gate time stamp
141  virtual double ExternalTick2BeamTime(double tick, size_t sample, size_t frame) const
142  { return fExternalClock.TickPeriod() * tick + fExternalClock.Time(sample,frame) - BeamGateTime(); }
143 
144  //
145  // Getters for time [tdc] (electronics clock counting ... in double precision)
146  //
147 
148  /// Given TPC time-tick (waveform index), returns electronics clock count [tdc]
149  virtual double TPCTick2TDC(double tick) const
150  { return ( (TriggerTime() + TriggerOffsetTPC()) / fTPCClock.TickPeriod() + tick ); }
151 
152  /// Given G4 time [ns], returns corresponding TPC electronics clock count [tdc]
153  virtual double TPCG4Time2TDC(double g4time) const
154  { return G4ToElecTime(g4time) / fTPCClock.TickPeriod(); }
155 
156  /// Given External time-tick (waveform index), sample and frame number, returns time electronics clock count [tdc]
157  virtual double ExternalTick2TDC(double tick, size_t sample, size_t frame) const
158  { return fExternalClock.Ticks(sample,frame) + tick; }
159 
160  /// Given G4 time [ns], returns corresponding External electronics clock count [tdc]
161  virtual double ExternalG4Time2TDC(double g4time) const
162  { return G4ToElecTime(g4time) / fExternalClock.TickPeriod(); }
163 
164  //
165  // Getters for time [ns] (electronics clock counting ... in double precision)
166  //
167  /// Given TPC time-tick (waveform index), returns electronics clock [us]
168  virtual double TPCTick2Time(double tick) const
169  { return TriggerTime() + TriggerOffsetTPC() + tick * fTPCClock.TickPeriod(); }
170 
171  /// Given External time-tick (waveform index), sample and frame number, returns electronics clock [us]
172  virtual double ExternalTick2Time(double tick, size_t sample, size_t frame) const
173  { return fExternalClock.Time(sample,frame) + tick * fExternalClock.TickPeriod(); }
174 
175  //
176  // Getters for time [ticks] (waveform index number)
177  //
178 
179  /// Given electronics clock count [tdc] returns TPC time-tick
180  virtual double TPCTDC2Tick(double tdc) const
181  { return ( tdc - (TriggerTime() + TriggerOffsetTPC()) / fTPCClock.TickPeriod() ); }
182 
183  /// Given G4 time returns electronics clock count [tdc]
184  virtual double TPCG4Time2Tick(double g4time) const
185  { return (G4ToElecTime(g4time) - (TriggerTime() + TriggerOffsetTPC())) / fTPCClock.TickPeriod(); }
186 
188 
189  /// Internal function to apply loaded parameters to member attributes
190  void ApplyParams();
191 
192  /// Internal function used to search for the right configuration set in the data file
193  bool IsRightConfig(const fhicl::ParameterSet& ps) const;
194 
195  protected:
196 
197  std::vector<std::string> fConfigName;
198 
199  std::vector<double> fConfigValue;
200 
202 
204 
205  /// Electronics clock counting start time in G4 time frame [us]
206  double fG4RefTime;
207 
208  /// Frame period
209  double fFramePeriod;
210 
211  /// TPC clock
213 
214  /// Trigger clock
216 
217  /// External clock
219 
220  /// Time offset from trigger to TPC readout start
222 
223  /// Trigger time in [ns]
224  double fTriggerTime;
225 
226  /// BeamGate time in [ns]
228 
229  /// Duration of beam spill, ns.
230  double fSpillLength;
231 
232  }; // class DetectorClocksStandardGAr
233 
234  } //namespace detinfo
235 }
236 
237 #endif
virtual double TPCTick2TrigTime(double tick) const
Given TPC time-tick (waveform index), returns time [ns] w.r.t. trigger time stamp.
virtual void SetTriggerTime(double trig_time, double beam_time)
Setter for trigger times.
bool IsRightConfig(const fhicl::ParameterSet &ps) const
Internal function used to search for the right configuration set in the data file.
std::string string
Definition: nybbler.cc:12
virtual double ExternalTick2TrigTime(double tick, size_t sample, size_t frame) const
Given External time-tick (waveform index), sample and frame number, returns time [ns] w...
virtual double TPCTick2Time(double tick) const
Given TPC time-tick (waveform index), returns electronics clock [us].
virtual ElecClock TPCClock(double time) const
Create a TPC clock for a given time [us] from clock counting start.
virtual double TPCG4Time2TDC(double g4time) const
Given G4 time [ns], returns corresponding TPC electronics clock count [tdc].
void ApplyParams()
Internal function to apply loaded parameters to member attributes.
virtual double ExternalTick2BeamTime(double tick, size_t sample, size_t frame) const
Given External time-tick (waveform index), sample and frame number, returns time [ns] w...
virtual double SpillLength() const
Duration of spill [ns].
virtual double BeamGateTime() const
Beam gate electronics clock time in [us].
virtual detinfo::ElecClock ExternalClock(double time) const
Create a External clock for a given time [us] from clock counting start.
virtual detinfo::ElecClock ExternalClock(unsigned int sample, unsigned int frame) const
Create a External clock for a given sample/frame number in External clock frequency.
double TickPeriod() const
A single tick period in nano-second, frequency is in MHz.
Definition: ElecClock.h:125
double fSpillLength
Duration of beam spill, ns.
double FramePeriod() const
A single frame period in micro-second.
Definition: ElecClock.h:92
virtual double ExternalTick2TDC(double tick, size_t sample, size_t frame) const
Given External time-tick (waveform index), sample and frame number, returns time electronics clock co...
double fG4RefTime
Electronics clock counting start time in G4 time frame [us].
virtual double TPCG4Time2Tick(double g4time) const
Given G4 time returns electronics clock count [tdc].
double fTriggerOffsetTPC
Time offset from trigger to TPC readout start.
bool Configure(fhicl::ParameterSet const &pset)
detinfo::ElecClock TPCClock(unsigned int sample, unsigned int frame) const
Create a TPC clock for a given sample/frame number in TPC clock frequency.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
General LArSoft Utilities.
static constexpr double ps
Definition: Units.h:99
virtual detinfo::ElecClock TriggerClock(unsigned int sample, unsigned int frame) const
Create a Trigger clock for a given sample/frame number in Trigger clock frequency.
General GArSoft Utilities.
virtual std::vector< std::string > ConfigNames() const
virtual double ExternalTick2Time(double tick, size_t sample, size_t frame) const
Given External time-tick (waveform index), sample and frame number, returns electronics clock [us]...
virtual std::vector< double > ConfigValues() const
int Ticks() const
of Ticks
Definition: ElecClock.h:95
double Frequency() const
Frequency in MHz.
Definition: ElecClock.h:89
virtual double TPCTDC2Tick(double tdc) const
Given electronics clock count [tdc] returns TPC time-tick.
virtual double TPCTick2TDC(double tick) const
Given TPC time-tick (waveform index), returns electronics clock count [tdc].
virtual const ElecClock & TPCClock() const
Borrow a const TPC clock with time set to Trigger time [us].
virtual double TPCTick2BeamTime(double tick) const
Given TPC time-tick (waveform index), returns time [ns] w.r.t. beam gate time.
void SetTime(double time)
Definition: ElecClock.h:58
virtual const detinfo::ElecClock & ExternalClock() const
Borrow a const Trigger clock with time set to External Time [us].
virtual double TriggerTime() const
Trigger electronics clock time in [us].
virtual double ExternalG4Time2TDC(double g4time) const
Given G4 time [ns], returns corresponding External electronics clock count [tdc]. ...
virtual detinfo::ElecClock TriggerClock(double time) const
Create a Trigger clock for a given time [us] from clock counting start.
virtual double G4ToElecTime(double g4_time) const
Given Geant4 time [ns], returns relative time [ns] w.r.t. electronics time T0.
virtual void SetSpillLength(double spillLength)
virtual const detinfo::ElecClock & TriggerClock() const
Borrow a const Trigger clock with time set to Trigger time [us].
double Time() const
Time (stored) in nano-second.
Definition: ElecClock.h:77