CMS 3D CMS Logo

TotemTimingConversions.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of CTPPS offline software.
4  * Authors:
5  * Laurent Forthomme (laurent.forthomme@cern.ch)
6  * Nicola Minafra (nicola.minafra@cern.ch)
7  * Filip Dej
8  * Christopher Misan (krzysztof.misan@cern.ch)
9  *
10  ****************************************************************************/
11 
14 
15 //----------------------------------------------------------------------------------------------------
16 
17 TotemTimingConversions::TotemTimingConversions(double sampicSamplingPeriodNs,
18  bool mergeTimePeaks,
20  : calibration_(calibration),
21  sampicSamplingPeriodNs_(sampicSamplingPeriodNs),
22  mergeTimePeaks_(mergeTimePeaks),
23  calibrationFunction_(calibration_.formula()) {}
24 
25 //----------------------------------------------------------------------------------------------------
26 
28  unsigned int offsetOfSamples = digi.eventInfo().offsetOfSamples();
29 
30  unsigned int timestamp =
31  (digi.cellInfo() <= SAMPIC_MAX_NUMBER_OF_SAMPLES / 2) ? digi.timestampA() : digi.timestampB();
32 
33  int cell0TimeClock = timestamp + ((digi.fpgaTimestamp() - timestamp) & CELL0_MASK) - digi.eventInfo().l1ATimestamp() +
34  digi.eventInfo().l1ALatency();
35 
36  // time of first cell
37  float cell0TimeInstant = SAMPIC_MAX_NUMBER_OF_SAMPLES * sampicSamplingPeriodNs_ * cell0TimeClock;
38 
39  // time of triggered cell
40  float firstCellTimeInstant =
41  (digi.cellInfo() < offsetOfSamples)
42  ? cell0TimeInstant + digi.cellInfo() * sampicSamplingPeriodNs_
43  : cell0TimeInstant - (SAMPIC_MAX_NUMBER_OF_SAMPLES - digi.cellInfo()) * sampicSamplingPeriodNs_;
44 
45  int db = digi.hardwareBoardId();
46  int sampic = digi.hardwareSampicId();
47  int channel = digi.hardwareChannelId();
48  float t = firstCellTimeInstant + calibration_.timeOffset(db, sampic, channel);
49  //NOTE: If no time offset is set, timeOffset returns 0
50 
51  if (mergeTimePeaks_) {
52  if (t < -ACCEPTED_TIME_RADIUS)
54  if (t > ACCEPTED_TIME_RADIUS)
56  }
57 
58  return t;
59 }
60 
61 //----------------------------------------------------------------------------------------------------
62 
64  unsigned int offsetOfSamples = digi.eventInfo().offsetOfSamples();
65  return timeOfFirstSample(digi) + (SAMPIC_MAX_NUMBER_OF_SAMPLES - offsetOfSamples) * sampicSamplingPeriodNs_;
66 }
67 
68 //----------------------------------------------------------------------------------------------------
69 
71  int db = digi.hardwareBoardId();
72  int sampic = digi.hardwareSampicId();
73  int channel = digi.hardwareChannelId();
74  return calibration_.timePrecision(db, sampic, channel);
75 }
76 
77 //----------------------------------------------------------------------------------------------------
78 
79 std::vector<float> TotemTimingConversions::timeSamples(const TotemTimingDigi& digi) const {
80  std::vector<float> time(digi.numberOfSamples());
81  for (unsigned int i = 0; i < time.size(); ++i)
83  return time;
84 }
85 
86 //----------------------------------------------------------------------------------------------------
87 // NOTE: If no proper file is specified, calibration is not applied
88 
89 std::vector<float> TotemTimingConversions::voltSamples(const TotemTimingDigi& digi) const {
90  std::vector<float> data;
92  for (const auto& sample : digi.samples())
93  data.emplace_back(SAMPIC_ADC_V * sample);
94  else {
95  unsigned int db = digi.hardwareBoardId();
96  unsigned int sampic = digi.hardwareSampicId();
97  unsigned int channel = digi.hardwareChannelId();
98  unsigned int cell = digi.cellInfo();
99  for (const auto& sample : digi.samples()) {
100  // ring buffer on Sampic, so accounting for samples register boundary
101  const unsigned short sample_cell = (cell++) % SAMPIC_MAX_NUMBER_OF_SAMPLES;
102  auto parameters = calibration_.parameters(db, sampic, channel, sample_cell);
104  throw cms::Exception("TotemTimingConversions:voltSamples")
105  << "Invalid calibrations retrieved for Sampic digi"
106  << " (" << db << ", " << sampic << ", " << channel << ", " << sample_cell << ")!";
107  data.emplace_back(calibrationFunction_.evaluate(std::vector<double>{(double)sample}, parameters));
108  }
109  }
110  return data;
111 }
double evaluate(V const &iVariables, P const &iParameters) const
unsigned int timestampA() const
unsigned int l1ALatency() const
double timeOffset(int key1, int key2, int key3, int key4=-1) const
unsigned int timestampB() const
unsigned int numberOfSamples() const
static constexpr unsigned long CELL0_MASK
unsigned int fpgaTimestamp() const
reco::FormulaEvaluator calibrationFunction_
static constexpr float SAMPIC_ADC_V
unsigned int l1ATimestamp() const
unsigned int offsetOfSamples() const
std::vector< float > voltSamples(const TotemTimingDigi &digi) const
unsigned int hardwareSampicId() const
std::vector< uint8_t > samples() const
static constexpr int SAMPIC_MAX_NUMBER_OF_SAMPLES
float timeOfFirstSample(const TotemTimingDigi &digi) const
double timePrecision(int key1, int key2, int key3, int key4=-1) const
unsigned int numberOfParameters() const
float triggerTime(const TotemTimingDigi &digi) const
std::vector< double > parameters(int key1, int key2, int key3, int key4) const
unsigned int hardwareChannelId() const
TotemTimingEventInfo eventInfo() const
PPSTimingCalibration calibration_
unsigned int hardwareBoardId() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
unsigned int cellInfo() const
std::vector< float > timeSamples(const TotemTimingDigi &digi) const
unsigned int numberOfVariables() const
float timePrecision(const TotemTimingDigi &digi) const
TotemTimingConversions(double sampicSamplingPeriodNs, bool mergeTimePeaks, const PPSTimingCalibration &calibration)
static constexpr int ACCEPTED_TIME_RADIUS