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 }
TotemTimingEventInfo::l1ATimestamp
unsigned int l1ATimestamp() const
Definition: TotemTimingEventInfo.h:47
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
mps_fire.i
i
Definition: mps_fire.py:428
TotemTimingConversions::SAMPIC_SAMPLING_PERIOD_NS
static constexpr float SAMPIC_SAMPLING_PERIOD_NS
Definition: TotemTimingConversions.h:39
TotemTimingDigi::timestampA
unsigned int timestampA() const
Definition: TotemTimingDigi.h:48
simplePhotonAnalyzer_cfi.sample
sample
Definition: simplePhotonAnalyzer_cfi.py:12
TotemTimingDigi::hardwareBoardId
unsigned int hardwareBoardId() const
Definition: TotemTimingDigi.h:40
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
TotemTimingConversions::SAMPIC_MAX_NUMBER_OF_SAMPLES
static constexpr int SAMPIC_MAX_NUMBER_OF_SAMPLES
Definition: TotemTimingConversions.h:41
TotemTimingConversions::voltSamples
std::vector< float > voltSamples(const TotemTimingDigi &digi) const
Definition: TotemTimingConversions.cc:86
TotemTimingDigi::fpgaTimestamp
unsigned int fpgaTimestamp() const
Definition: TotemTimingDigi.h:46
protons_cff.time
time
Definition: protons_cff.py:35
TotemTimingDigi::hardwareSampicId
unsigned int hardwareSampicId() const
Definition: TotemTimingDigi.h:42
TotemTimingConversions::TotemTimingConversions
TotemTimingConversions(bool mergeTimePeaks, const PPSTimingCalibration &calibration)
Definition: TotemTimingConversions.cc:15
TotemTimingConversions::mergeTimePeaks_
bool mergeTimePeaks_
Definition: TotemTimingConversions.h:47
TotemTimingDigi::numberOfSamples
unsigned int numberOfSamples() const
Definition: TotemTimingDigi.h:60
dqmiodatasetharvest.db
db
Definition: dqmiodatasetharvest.py:119
cond::timestamp
Definition: Time.h:19
PPSTimingCalibration::timeOffset
double timeOffset(int key1, int key2, int key3, int key4=-1) const
Definition: PPSTimingCalibration.cc:40
TotemTimingConversions::triggerTime
float triggerTime(const TotemTimingDigi &digi) const
Definition: TotemTimingConversions.cc:57
TotemTimingDigi
Definition: TotemTimingDigi.h:19
TotemTimingConversions::calibration_
PPSTimingCalibration calibration_
Definition: TotemTimingConversions.h:46
PPSTimingCalibration::timePrecision
double timePrecision(int key1, int key2, int key3, int key4=-1) const
Definition: PPSTimingCalibration.cc:48
Phase1L1TJetCalibrator_9x9Jets_cfi.calibration
calibration
Definition: Phase1L1TJetCalibrator_9x9Jets_cfi.py:2
reco::FormulaEvaluator::numberOfVariables
unsigned int numberOfVariables() const
Definition: FormulaEvaluator.h:84
TotemTimingDigi::cellInfo
unsigned int cellInfo() const
Definition: TotemTimingDigi.h:52
PPSTimingCalibration::parameters
std::vector< double > parameters(int key1, int key2, int key3, int key4) const
Definition: PPSTimingCalibration.cc:32
reco::FormulaEvaluator::numberOfParameters
unsigned int numberOfParameters() const
Definition: FormulaEvaluator.h:83
TotemTimingConversions::timeSamples
std::vector< float > timeSamples(const TotemTimingDigi &digi) const
Definition: TotemTimingConversions.cc:76
TotemTimingConversions::SAMPIC_ADC_V
static constexpr float SAMPIC_ADC_V
Definition: TotemTimingConversions.h:40
TotemTimingConversions::timePrecision
float timePrecision(const TotemTimingDigi &digi) const
Definition: TotemTimingConversions.cc:67
TotemTimingConversions::ACCEPTED_TIME_RADIUS
static constexpr int ACCEPTED_TIME_RADIUS
Definition: TotemTimingConversions.h:43
TotemTimingConversions::SAMPIC_DEFAULT_OFFSET
static constexpr int SAMPIC_DEFAULT_OFFSET
Definition: TotemTimingConversions.h:42
TotemTimingEventInfo::l1ALatency
unsigned int l1ALatency() const
Definition: TotemTimingEventInfo.h:57
TotemTimingConversions.h
reco::FormulaEvaluator::evaluate
double evaluate(V const &iVariables, P const &iParameters) const
Definition: FormulaEvaluator.h:73
TotemTimingDigi::hardwareChannelId
unsigned int hardwareChannelId() const
Definition: TotemTimingDigi.h:44
TotemTimingConversions::timeOfFirstSample
float timeOfFirstSample(const TotemTimingDigi &digi) const
Definition: TotemTimingConversions.cc:20
TotemTimingEventInfo::offsetOfSamples
unsigned int offsetOfSamples() const
Definition: TotemTimingEventInfo.h:61
Exception.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
cms::Exception
Definition: Exception.h:70
PPSTimingCalibration
Definition: PPSTimingCalibration.h:17
TotemTimingConversions::CELL0_MASK
static constexpr unsigned long CELL0_MASK
Definition: TotemTimingConversions.h:44
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
TotemTimingDigi::timestampB
unsigned int timestampB() const
Definition: TotemTimingDigi.h:50
TotemTimingConversions::calibrationFunction_
reco::FormulaEvaluator calibrationFunction_
Definition: TotemTimingConversions.h:48
TotemTimingDigi::eventInfo
TotemTimingEventInfo eventInfo() const
Definition: TotemTimingDigi.h:69
TotemTimingDigi::samples
std::vector< uint8_t > samples() const
Definition: TotemTimingDigi.h:54