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  *
9  ****************************************************************************/
10 
13 
14 //----------------------------------------------------------------------------------------------------
15 
17  : calibration_(calibration), mergeTimePeaks_(mergeTimePeaks), calibrationFunction_(calibration_.formula()) {}
18 
19 //----------------------------------------------------------------------------------------------------
20 
22  unsigned int offsetOfSamples = digi.eventInfo().offsetOfSamples();
23  if (offsetOfSamples == 0)
24  offsetOfSamples = SAMPIC_DEFAULT_OFFSET; // FW 0 is not sending this, FW > 0 yes
25 
26  unsigned int timestamp =
27  (digi.cellInfo() <= SAMPIC_MAX_NUMBER_OF_SAMPLES / 2) ? digi.timestampA() : digi.timestampB();
28 
29  int cell0TimeClock = timestamp + ((digi.fpgaTimestamp() - timestamp) & CELL0_MASK) - digi.eventInfo().l1ATimestamp() +
30  digi.eventInfo().l1ALatency();
31 
32  // time of first cell
33  float cell0TimeInstant = SAMPIC_MAX_NUMBER_OF_SAMPLES * SAMPIC_SAMPLING_PERIOD_NS * cell0TimeClock;
34 
35  // time of triggered cell
36  float firstCellTimeInstant =
37  (digi.cellInfo() < offsetOfSamples)
38  ? cell0TimeInstant + digi.cellInfo() * SAMPIC_SAMPLING_PERIOD_NS
39  : cell0TimeInstant - (SAMPIC_MAX_NUMBER_OF_SAMPLES - digi.cellInfo()) * SAMPIC_SAMPLING_PERIOD_NS;
40 
41  int db = digi.hardwareBoardId();
42  int sampic = digi.hardwareSampicId();
43  int channel = digi.hardwareChannelId();
44  float t = firstCellTimeInstant + calibration_.timeOffset(db, sampic, channel);
45  //NOTE: If no time offset is set, timeOffset returns 0
46 
47  if (mergeTimePeaks_) {
48  if (t < -ACCEPTED_TIME_RADIUS)
50  if (t > ACCEPTED_TIME_RADIUS)
52  }
53  return t;
54 }
55 
56 //----------------------------------------------------------------------------------------------------
57 
59  unsigned int offsetOfSamples = digi.eventInfo().offsetOfSamples();
60  if (offsetOfSamples == 0)
61  offsetOfSamples = 30; // FW 0 is not sending this, FW > 0 yes
62 
64 }
65 
66 //----------------------------------------------------------------------------------------------------
67 
69  int db = digi.hardwareBoardId();
70  int sampic = digi.hardwareSampicId();
71  int channel = digi.hardwareChannelId();
72  return calibration_.timePrecision(db, sampic, channel);
73 }
74 
75 //----------------------------------------------------------------------------------------------------
76 
77 std::vector<float> TotemTimingConversions::timeSamples(const TotemTimingDigi& digi) const {
78  std::vector<float> time(digi.numberOfSamples());
79  for (unsigned int i = 0; i < time.size(); ++i)
81  return time;
82 }
83 
84 //----------------------------------------------------------------------------------------------------
85 // NOTE: If no proper file is specified, calibration is not applied
86 
87 std::vector<float> TotemTimingConversions::voltSamples(const TotemTimingDigi& digi) const {
88  std::vector<float> data;
90  for (const auto& sample : digi.samples())
91  data.emplace_back(SAMPIC_ADC_V * sample);
92  else {
93  unsigned int db = digi.hardwareBoardId();
94  unsigned int sampic = digi.hardwareSampicId();
95  unsigned int channel = digi.hardwareChannelId();
96  unsigned int cell = digi.cellInfo();
97  for (const auto& sample : digi.samples()) {
98  // ring buffer on Sampic, so accounting for samples register boundary
99  const unsigned short sample_cell = (cell++) % SAMPIC_MAX_NUMBER_OF_SAMPLES;
100  auto parameters = calibration_.parameters(db, sampic, channel, sample_cell);
102  throw cms::Exception("TotemTimingConversions:voltSamples")
103  << "Invalid calibrations retrieved for Sampic digi"
104  << " (" << db << ", " << sampic << ", " << channel << ", " << sample_cell << ")!";
105  data.emplace_back(calibrationFunction_.evaluate(std::vector<double>{(double)sample}, parameters));
106  }
107  }
108  return data;
109 }
unsigned int numberOfParameters() const
TotemTimingEventInfo eventInfo() const
unsigned int numberOfSamples() const
unsigned int timestampA() const
static constexpr unsigned long CELL0_MASK
unsigned int offsetOfSamples() const
double timeOffset(int key1, int key2, int key3, int key4=-1) const
unsigned int l1ALatency() const
std::vector< float > voltSamples(const TotemTimingDigi &digi) const
reco::FormulaEvaluator calibrationFunction_
static constexpr float SAMPIC_SAMPLING_PERIOD_NS
static constexpr float SAMPIC_ADC_V
std::vector< double > parameters(int key1, int key2, int key3, int key4) const
unsigned int hardwareSampicId() const
float triggerTime(const TotemTimingDigi &digi) const
unsigned int numberOfVariables() const
std::vector< uint8_t > samples() const
unsigned int l1ATimestamp() const
TotemTimingConversions(bool mergeTimePeaks, const PPSTimingCalibration &calibration)
static constexpr int SAMPIC_DEFAULT_OFFSET
double evaluate(V const &iVariables, P const &iParameters) const
static constexpr int SAMPIC_MAX_NUMBER_OF_SAMPLES
unsigned int cellInfo() const
float timePrecision(const TotemTimingDigi &digi) const
unsigned int hardwareBoardId() const
float timeOfFirstSample(const TotemTimingDigi &digi) const
std::vector< float > timeSamples(const TotemTimingDigi &digi) const
unsigned int fpgaTimestamp() const
PPSTimingCalibration calibration_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
unsigned int hardwareChannelId() const
double timePrecision(int key1, int key2, int key3, int key4=-1) const
static constexpr int ACCEPTED_TIME_RADIUS
unsigned int timestampB() const