LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DetectorClocksStandard.h
Go to the documentation of this file.
1 //
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 //
12 
13 #ifndef LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARD_H
14 #define LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARD_H
15 
16 #include "fhiclcpp/ParameterSet.h"
17 
19 
20 namespace detinfo{
21 
118 
119  public:
124 
125  bool Configure(fhicl::ParameterSet const& pset);
126  bool Update(uint64_t ts=0);
127 
133  virtual double TriggerOffsetTPC() const override
134  {
135  if (fTriggerOffsetTPC<0)
136  return fTriggerOffsetTPC;
137  else
138  return -fTriggerOffsetTPC/fTPCClock.Frequency(); //convert ticks to us
139  }
140 
142  virtual double TPCTime() const override { return doTPCTime(); }
143 
144  void debugReport() const;
145 
153  std::string TrigModuleName() const { return fTrigModuleName; }
154 
156  void SetDefaultTriggerTime();
157 
159  virtual double G4ToElecTime(double g4_time) const override {return g4_time * 1.e-3 - fG4RefTime; }
160 
162  virtual double TriggerTime() const override { return fTriggerTime; }
163 
165  virtual double BeamGateTime() const override { return fBeamGateTime; }
166 
167  virtual std::vector<std::string> ConfigNames() const override { return fConfigName; }
168  virtual std::vector<double> ConfigValues() const override { return fConfigValue; }
169 
170  void SetConfigValue(size_t i, double val) { fConfigValue[i] = val; }
171 
181  virtual void SetTriggerTime(double trig_time, double beam_time)
182  {
183  fTriggerTime = trig_time;
184  fBeamGateTime = beam_time;
185  fTPCClock.SetTime(trig_time);
186  fOpticalClock.SetTime(trig_time);
187  fTriggerClock.SetTime(trig_time);
188  }
189 
190  //
191  // Getters of TPC ElecClock
192  //
194  virtual const ::detinfo::ElecClock& TPCClock() const override
195  { return fTPCClock; }
196 
198  virtual ::detinfo::ElecClock TPCClock(double time) const override
199  { return ::detinfo::ElecClock(time,fTPCClock.FramePeriod(),fTPCClock.Frequency());}
200 
202  detinfo::ElecClock TPCClock(unsigned int sample,
203  unsigned int frame) const override
204  { detinfo::ElecClock clock = TPCClock(); clock.SetTime(sample,frame); return clock; }
205 
206  //
207  // Getters of Optical ElecClock
208  //
210  virtual const detinfo::ElecClock& OpticalClock() const override
211  { return fOpticalClock; }
212 
214  virtual detinfo::ElecClock OpticalClock(double time) const override
216 
218  virtual detinfo::ElecClock OpticalClock(unsigned int sample,
219  unsigned int frame) const override
220  { detinfo::ElecClock clock = OpticalClock(); clock.SetTime(sample,frame); return clock; }
221 
222  //
223  // Getters of Trigger ElecClock
224  //
226  virtual const detinfo::ElecClock& TriggerClock() const override
227  { return fTriggerClock; }
228 
230  virtual detinfo::ElecClock TriggerClock(double time) const override
232 
234  virtual detinfo::ElecClock TriggerClock(unsigned int sample,
235  unsigned int frame) const override
236  { detinfo::ElecClock clock = TriggerClock(); clock.SetTime(sample,frame); return clock; }
237 
238  //
239  // Getters of External ElecClock
240  //
242  virtual const detinfo::ElecClock& ExternalClock() const override
243  { return fExternalClock; }
244 
247  virtual detinfo::ElecClock ExternalClock(double time) const override
249 
251  virtual detinfo::ElecClock ExternalClock(unsigned int sample,
252  unsigned int frame) const override
253  { detinfo::ElecClock clock = ExternalClock(); clock.SetTime(sample,frame); return clock; }
254 
255  //
256  // Getters for time [us] w.r.t. trigger given information from waveform
257  //
258 
260  virtual double TPCTick2TrigTime(double tick) const override
261  { return fTPCClock.TickPeriod() * tick + TriggerOffsetTPC(); }
263  virtual double TPCTick2BeamTime(double tick) const override
264  { return TPCTick2TrigTime(tick) + TriggerTime() - BeamGateTime(); }
266  virtual double OpticalTick2TrigTime(double tick, size_t sample, size_t frame) const override
267  { return fOpticalClock.TickPeriod() * tick + fOpticalClock.Time(sample,frame) - TriggerTime(); }
269  virtual double OpticalTick2BeamTime(double tick, size_t sample, size_t frame) const override
270  { return fOpticalClock.TickPeriod() * tick + fOpticalClock.Time(sample,frame) - BeamGateTime(); }
272  virtual double ExternalTick2TrigTime(double tick, size_t sample, size_t frame) const override
273  { return fExternalClock.TickPeriod() * tick + fExternalClock.Time(sample,frame) - TriggerTime(); }
275  virtual double ExternalTick2BeamTime(double tick, size_t sample, size_t frame) const override
276  { return fExternalClock.TickPeriod() * tick + fExternalClock.Time(sample,frame) - BeamGateTime(); }
277 
279  virtual double Time2Tick(double time) const override
280  { return doTime2Tick(time); }
281 
282  //
283  // Getters for time [tdc] (electronics clock counting ... in double precision)
284  //
285 
287  virtual double TPCTick2TDC(double tick) const override
288  { return ( doTPCTime() / fTPCClock.TickPeriod() + tick ); }
290  virtual double TPCG4Time2TDC(double g4time) const override
291  { return G4ToElecTime(g4time) / fTPCClock.TickPeriod(); }
293  virtual double OpticalTick2TDC(double tick, size_t sample, size_t frame) const override
294  { return fOpticalClock.Ticks(sample,frame) + tick; }
296  virtual double OpticalG4Time2TDC(double g4time) const override
297  { return G4ToElecTime(g4time) / fOpticalClock.TickPeriod(); }
299  virtual double ExternalTick2TDC(double tick, size_t sample, size_t frame) const override
300  { return fExternalClock.Ticks(sample,frame) + tick; }
302  virtual double ExternalG4Time2TDC(double g4time) const override
303  { return G4ToElecTime(g4time) / fExternalClock.TickPeriod(); }
304 
305  //
306  // Getters for time [us] (electronics clock counting ... in double precision)
307  //
309  virtual double TPCTick2Time(double tick) const override
310  { return doTPCTime() + tick * fTPCClock.TickPeriod(); }
312  virtual double OpticalTick2Time(double tick, size_t sample, size_t frame) const override
313  { return fOpticalClock.Time(sample,frame) + tick * fOpticalClock.TickPeriod(); }
315  virtual double ExternalTick2Time(double tick, size_t sample, size_t frame) const override
316  { return fExternalClock.Time(sample,frame) + tick * fExternalClock.TickPeriod(); }
317 
318  //
319  // Getters for time [ticks] (waveform index number)
320  //
321 
323  virtual double TPCTDC2Tick(double tdc) const override
324  { return ( tdc - doTPCTime() / fTPCClock.TickPeriod() ); }
326  virtual double TPCG4Time2Tick(double g4time) const override
327  { return (G4ToElecTime(g4time) - doTPCTime()) / fTPCClock.TickPeriod(); }
328 
330 
332  void ApplyParams();
333 
335  bool IsRightConfig(const fhicl::ParameterSet& ps) const;
336 
337  protected:
338 
339  std::vector<std::string> fConfigName;
340 
341  std::vector<double> fConfigValue;
342 
344 
345  std::string fTrigModuleName;
346 
348  double fG4RefTime;
349 
351  double fFramePeriod;
352 
355 
358 
361 
364 
367 
369  double fTriggerTime;
370 
373 
375  double doTPCTime() const { return TriggerTime() + TriggerOffsetTPC(); }
376 
378  double doTime2Tick(double time) const
379  { return (time - doTPCTime()) / fTPCClock.TickPeriod(); }
380 
381  }; // class DetectorClocksStandard
382 
383 } //namespace detinfo
384 
385 
386 #endif // LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARD_H
387 
::detinfo::ElecClock fTPCClock
TPC clock.
bool Configure(fhicl::ParameterSet const &pset)
virtual double G4ToElecTime(double g4_time) const override
Given Geant4 time [ns], returns relative time [us] w.r.t. electronics time T0.
virtual double ExternalTick2Time(double tick, size_t sample, size_t frame) const override
Given External time-tick (waveform index), sample and frame number, returns electronics clock [us]...
virtual double TPCTime() const override
Returns the TPC electronics start time in electronics time.
bool IsRightConfig(const fhicl::ParameterSet &ps) const
Internal function used to search for the right configuration set in the data file.
virtual double TPCTDC2Tick(double tdc) const override
Given electronics clock count [tdc] returns TPC time-tick.
void SetTime(double time)
Directly sets the current time on the clock.
Definition: ElecClock.h:138
std::vector< std::string > fConfigName
virtual detinfo::ElecClock ExternalClock(double time) const override
virtual const ::detinfo::ElecClock & TPCClock() const override
Borrow a const TPC clock with time set to Trigger time [us].
::detinfo::ElecClock fOpticalClock
Optical clock.
virtual double ExternalG4Time2TDC(double g4time) const override
Given G4 time [ns], returns corresponding External electronics clock count [tdc]. ...
virtual double ExternalTick2BeamTime(double tick, size_t sample, size_t frame) const override
Given External time-tick (waveform index), sample and frame number, returns time [us] w...
std::string TrigModuleName() const
Returns the input tag of the trigger data product.
::detinfo::ElecClock fTriggerClock
Trigger clock.
int Ticks() const
Current clock tick (that is, the number of tick Time() falls in).
Definition: ElecClock.h:235
virtual double OpticalTick2Time(double tick, size_t sample, size_t frame) const override
Given Optical time-tick (waveform index), sample and frame number, returns electronics clock [us]...
virtual void SetTriggerTime(double trig_time, double beam_time)
Setter for trigger times.
virtual double OpticalTick2TDC(double tick, size_t sample, size_t frame) const override
Given Optical time-tick (waveform index), sample and frame number, returns time electronics clock cou...
virtual double ExternalTick2TDC(double tick, size_t sample, size_t frame) const override
Given External time-tick (waveform index), sample and frame number, returns time electronics clock co...
virtual double OpticalTick2BeamTime(double tick, size_t sample, size_t frame) const override
Given Optical time-tick (waveform index), sample and frame number, returns time [us] w...
pure virtual base interface for detector clocks
double fTriggerTime
Trigger time in [us].
virtual detinfo::ElecClock TriggerClock(unsigned int sample, unsigned int frame) const override
Create a Trigger clock for a given sample/frame number in Trigger clock frequency.
double fG4RefTime
Electronics clock counting start time in G4 time frame [us].
detinfo::ElecClock TPCClock(unsigned int sample, unsigned int frame) const override
Create a TPC clock for a given sample/frame number in TPC clock frequency.
virtual const detinfo::ElecClock & OpticalClock() const override
Borrow a const Optical clock with time set to Trigger time [us].
virtual const detinfo::ElecClock & TriggerClock() const override
Borrow a const Trigger clock with time set to Trigger time [us].
virtual ::detinfo::ElecClock TPCClock(double time) const override
Create a TPC clock for a given time [us] from clock counting start.
void ApplyParams()
Internal function to apply loaded parameters to member attributes.
virtual detinfo::ElecClock ExternalClock(unsigned int sample, unsigned int frame) const override
Create a External clock for a given sample/frame number in External clock frequency.
virtual double TPCTick2TDC(double tick) const override
Given TPC time-tick (waveform index), returns electronics clock count [tdc].
virtual double OpticalG4Time2TDC(double g4time) const override
Given G4 time [ns], returns corresponding Optical electronics clock count [tdc].
virtual std::vector< double > ConfigValues() const override
double fBeamGateTime
BeamGate time in [us].
virtual double TriggerOffsetTPC() const override
double fTriggerOffsetTPC
Time offset from trigger to TPC readout start.
virtual const detinfo::ElecClock & ExternalClock() const override
Borrow a const Trigger clock with time set to External Time [us].
virtual std::vector< std::string > ConfigNames() const override
General LArSoft Utilities.
virtual double TriggerTime() const override
Trigger electronics clock time in [us].
void SetDefaultTriggerTime()
Sets trigger and beam gate time from default configuration values.
double doTime2Tick(double time) const
Implementation of Time2Tick().
Conversion of times between different formats and references.
double FramePeriod() const
A single frame period in microseconds.
Definition: ElecClock.h:232
void SetConfigValue(size_t i, double val)
virtual detinfo::ElecClock OpticalClock(double time) const override
Create a Optical clock for a given time [us] from clock counting start.
virtual double OpticalTick2TrigTime(double tick, size_t sample, size_t frame) const override
Given Optical time-tick (waveform index), sample and frame number, returns time [us] w...
double TickPeriod() const
A single tick period in microseconds.
Definition: ElecClock.h:342
::detinfo::ElecClock fExternalClock
External clock.
Implementation of detinfo::DetectorClocks interface with fixed settings from configuration.
virtual double TPCG4Time2TDC(double g4time) const override
Given G4 time [ns], returns corresponding TPC electronics clock count [tdc].
virtual double TPCG4Time2Tick(double g4time) const override
Given G4 time returns electronics clock count [tdc].
double Time() const
Current time (as stored) in microseconds.
Definition: ElecClock.h:191
Class representing the time measured by an electronics clock.
Definition: ElecClock.h:91
double doTPCTime() const
Implementation of TPCTime().
virtual double TPCTick2BeamTime(double tick) const override
Given TPC time-tick (waveform index), returns time [us] w.r.t. beam gate time.
virtual double Time2Tick(double time) const override
Returns the specified electronics time in TDC electronics ticks.
virtual double BeamGateTime() const override
Beam gate electronics clock time in [us].
virtual double ExternalTick2TrigTime(double tick, size_t sample, size_t frame) const override
Given External time-tick (waveform index), sample and frame number, returns time [us] w...
double Frequency() const
Frequency in MHz.
Definition: ElecClock.h:229
virtual double TPCTick2Time(double tick) const override
Given TPC time-tick (waveform index), returns electronics clock [us].
virtual double TPCTick2TrigTime(double tick) const override
Given TPC time-tick (waveform index), returns time [us] w.r.t. trigger time stamp.
virtual detinfo::ElecClock TriggerClock(double time) const override
Create a Trigger clock for a given time [us] from clock counting start.
virtual detinfo::ElecClock OpticalClock(unsigned int sample, unsigned int frame) const override
Create a Optical clock for a given sample/frame number in Optical clock frequency.