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 
16 TotemTimingConversions::TotemTimingConversions(bool mergeTimePeaks, const PPSTimingCalibration& calibration) :
17  calibration_(calibration), mergeTimePeaks_(mergeTimePeaks),
18  calibrationFunction_(calibration_.formula())
19 {}
20 
21 //----------------------------------------------------------------------------------------------------
22 
23 float
25 {
26  unsigned int offsetOfSamples = digi.getEventInfo().getOffsetOfSamples();
27  if (offsetOfSamples == 0)
28  offsetOfSamples = SAMPIC_DEFAULT_OFFSET; // FW 0 is not sending this, FW > 0 yes
29 
30  unsigned int timestamp = (digi.getCellInfo() <= SAMPIC_MAX_NUMBER_OF_SAMPLES/2)
31  ? digi.getTimestampA()
32  : digi.getTimestampB();
33 
34  int cell0TimeClock = timestamp +
36  - digi.getEventInfo().getL1ATimestamp()
37  + digi.getEventInfo().getL1ALatency();
38 
39  // time of first cell
40  float cell0TimeInstant = SAMPIC_MAX_NUMBER_OF_SAMPLES * SAMPIC_SAMPLING_PERIOD_NS * cell0TimeClock;
41 
42  // time of triggered cell
43  float firstCellTimeInstant = (digi.getCellInfo() < offsetOfSamples)
44  ? cell0TimeInstant + digi.getCellInfo() * SAMPIC_SAMPLING_PERIOD_NS
46 
47  int db = digi.getHardwareBoardId();
48  int sampic = digi.getHardwareSampicId();
49  int channel = digi.getHardwareChannelId();
50  float t = firstCellTimeInstant + calibration_.timeOffset(db, sampic, channel);
51  //NOTE: If no time offset is set, timeOffset returns 0
52 
53  if (mergeTimePeaks_) {
54  if (t < -ACCEPTED_TIME_RADIUS)
56  if (t > ACCEPTED_TIME_RADIUS)
58  }
59  return t;
60 }
61 
62 //----------------------------------------------------------------------------------------------------
63 
64 float
66 {
67  unsigned int offsetOfSamples = digi.getEventInfo().getOffsetOfSamples();
68  if (offsetOfSamples == 0)
69  offsetOfSamples = 30; // FW 0 is not sending this, FW > 0 yes
70 
72 }
73 
74 //----------------------------------------------------------------------------------------------------
75 
76 float
78 {
79  int db = digi.getHardwareBoardId();
80  int sampic = digi.getHardwareSampicId();
81  int channel = digi.getHardwareChannelId();
82  return calibration_.timePrecision(db, sampic, channel);
83 }
84 
85 //----------------------------------------------------------------------------------------------------
86 
87 std::vector<float>
89 {
90  std::vector<float> time(digi.getNumberOfSamples());
91  for (unsigned int i = 0; i < time.size(); ++i)
93  return time;
94 }
95 
96 //----------------------------------------------------------------------------------------------------
97 // NOTE: If no proper file is specified, calibration is not applied
98 
99 std::vector<float>
101 {
102  std::vector<float> data;
104  for (const auto& sample : digi.getSamples())
105  data.emplace_back(SAMPIC_ADC_V * sample);
106  else {
107  unsigned int db = digi.getHardwareBoardId();
108  unsigned int sampic = digi.getHardwareSampicId();
109  unsigned int channel = digi.getHardwareChannelId();
110  unsigned int cell = digi.getCellInfo();
111  for (const auto& sample : digi.getSamples()) {
112  // ring buffer on Sampic, so accounting for samples register boundary
113  const unsigned short sample_cell = (cell++) % SAMPIC_MAX_NUMBER_OF_SAMPLES;
114  auto parameters = calibration_.parameters(db, sampic, channel, sample_cell);
116  throw cms::Exception("TotemTimingConversions:voltSamples")
117  << "Invalid calibrations retrieved for Sampic digi"
118  << " (" << db << ", " << sampic << ", " << channel << ", " << sample_cell << ")!";
119  data.emplace_back(calibrationFunction_.evaluate(std::vector<double>{(double)sample}, parameters));
120  }
121  }
122  return data;
123 }
124 
unsigned int numberOfParameters() const
TotemTimingEventInfo getEventInfo() const
static constexpr unsigned long CELL0_MASK
double timeOffset(int key1, int key2, int key3, int key4=-1) const
std::vector< float > voltSamples(const TotemTimingDigi &digi) const
unsigned int getTimestampA() 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
std::vector< uint8_t > getSamples() const
float triggerTime(const TotemTimingDigi &digi) const
unsigned int getFPGATimestamp() const
unsigned int numberOfVariables() const
TotemTimingConversions(bool mergeTimePeaks, const PPSTimingCalibration &calibration)
static constexpr int SAMPIC_DEFAULT_OFFSET
unsigned int getL1ALatency() const
double evaluate(V const &iVariables, P const &iParameters) const
static constexpr int SAMPIC_MAX_NUMBER_OF_SAMPLES
unsigned int getTimestampB() const
float timePrecision(const TotemTimingDigi &digi) const
unsigned int getCellInfo() const
unsigned int getNumberOfSamples() const
float timeOfFirstSample(const TotemTimingDigi &digi) const
std::vector< float > timeSamples(const TotemTimingDigi &digi) const
unsigned int getL1ATimestamp() const
unsigned int getHardwareChannelId() const
PPSTimingCalibration calibration_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int getHardwareBoardId() const
unsigned int getHardwareSampicId() const
unsigned int getOffsetOfSamples() const
double timePrecision(int key1, int key2, int key3, int key4=-1) const
static constexpr int ACCEPTED_TIME_RADIUS