CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
TotemTimingRecHitProducerAlgorithm Class Reference

#include <TotemTimingRecHitProducerAlgorithm.h>

Inheritance diagram for TotemTimingRecHitProducerAlgorithm:
TimingRecHitProducerAlgorithm< CTPPSGeometry, edm::DetSetVector< TotemTimingDigi >, edm::DetSetVector< TotemTimingRecHit > >

Classes

struct  RegressionResults
 

Public Member Functions

void build (const CTPPSGeometry &, const edm::DetSetVector< TotemTimingDigi > &, edm::DetSetVector< TotemTimingRecHit > &) override
 
void setCalibration (const PPSTimingCalibration &)
 
 TotemTimingRecHitProducerAlgorithm (const edm::ParameterSet &)
 
- Public Member Functions inherited from TimingRecHitProducerAlgorithm< CTPPSGeometry, edm::DetSetVector< TotemTimingDigi >, edm::DetSetVector< TotemTimingRecHit > >
void setCalibration (const PPSTimingCalibration &calib, const PPSTimingCalibrationLUT &calibLUT)
 
 TimingRecHitProducerAlgorithm (const edm::ParameterSet &iConfig)
 
virtual ~TimingRecHitProducerAlgorithm ()=default
 

Private Member Functions

float constantFractionDiscriminator (const std::vector< float > &time, const std::vector< float > &data)
 
int fastDiscriminator (const std::vector< float > &data, float threshold) const
 
RegressionResults simplifiedLinearRegression (const std::vector< float > &time, const std::vector< float > &data, const unsigned int start_at, const unsigned int points) const
 

Private Attributes

int baselinePoints_
 
double cfdFraction_
 
double hysteresis_
 
double lowPassFrequency_
 
bool mergeTimePeaks_
 
TotemTimingRecHit::TimingAlgorithm mode_
 
std::unique_ptr< TotemTimingConversionssampicConversions_
 
double sampicOffset_
 
double sampicSamplingPeriodNs_
 
double saturationLimit_
 
int smoothingPoints_
 

Static Private Attributes

static constexpr float SINC_COEFFICIENT = M_PI * 2 / 7.8
 

Additional Inherited Members

- Protected Attributes inherited from TimingRecHitProducerAlgorithm< CTPPSGeometry, edm::DetSetVector< TotemTimingDigi >, edm::DetSetVector< TotemTimingRecHit > >
bool apply_calib_
 Switch on/off the timing calibration. More...
 
const PPSTimingCalibrationcalib_
 DB-loaded calibration object. More...
 
std::unique_ptr< reco::FormulaEvaluatorcalib_fct_
 Timing correction formula. More...
 
const PPSTimingCalibrationLUTcalibLUT_
 
double ts_to_ns_
 Conversion constant between time slice and absolute time (in ns) More...
 

Detailed Description

Definition at line 25 of file TotemTimingRecHitProducerAlgorithm.h.

Constructor & Destructor Documentation

◆ TotemTimingRecHitProducerAlgorithm()

TotemTimingRecHitProducerAlgorithm::TotemTimingRecHitProducerAlgorithm ( const edm::ParameterSet iConfig)
explicit

Definition at line 20 of file TotemTimingRecHitProducerAlgorithm.cc.

22  mergeTimePeaks_(iConfig.getParameter<bool>("mergeTimePeaks")),
23  baselinePoints_(iConfig.getParameter<int>("baselinePoints")),
24  saturationLimit_(iConfig.getParameter<double>("saturationLimit")),
25  cfdFraction_(iConfig.getParameter<double>("cfdFraction")),
26  smoothingPoints_(iConfig.getParameter<int>("smoothingPoints")),
27  lowPassFrequency_(iConfig.getParameter<double>("lowPassFrequency")),
28  hysteresis_(iConfig.getParameter<double>("hysteresis")),
29  sampicOffset_(iConfig.getParameter<double>("sampicOffset")),
30  sampicSamplingPeriodNs_(iConfig.getParameter<double>("sampicSamplingPeriodNs")) {}
T getParameter(std::string const &) const
Definition: ParameterSet.h:303

Member Function Documentation

◆ build()

void TotemTimingRecHitProducerAlgorithm::build ( const CTPPSGeometry geom,
const edm::DetSetVector< TotemTimingDigi > &  input,
edm::DetSetVector< TotemTimingRecHit > &  output 
)
overridevirtual

Implements TimingRecHitProducerAlgorithm< CTPPSGeometry, edm::DetSetVector< TotemTimingDigi >, edm::DetSetVector< TotemTimingRecHit > >.

Definition at line 40 of file TotemTimingRecHitProducerAlgorithm.cc.

References baselinePoints_, TotemTimingRecHit::CFD, constantFractionDiscriminator(), data, edm::DetSet< T >::emplace_back(), Exception, relativeConstraints::geom, DetGeomDesc::getDiamondDimensions(), mps_fire::i, input, TotemTimingRecHitProducerAlgorithm::RegressionResults::m, mode_, DetGeomDesc::name(), TotemTimingRecHit::NO_T_AVAILABLE, convertSQLitetoXML_cfg::output, DetGeomDesc::parentZPosition(), TotemTimingRecHitProducerAlgorithm::RegressionResults::q, TotemTimingRecHitProducerAlgorithm::RegressionResults::rms, sampicConversions_, sampicOffset_, saturationLimit_, simplifiedLinearRegression(), submitPVValidationJobs::t, protons_cff::time, DetGeomDesc::translation(), and DiamondDimensions::xHalfWidth.

Referenced by TotemTimingRecHitProducer::produce().

42  {
43  for (const auto& vec : input) {
44  const CTPPSDetId detid(vec.detId());
45 
46  float x_pos = 0.f, y_pos = 0.f, z_pos = 0.f;
47  float x_width = 0.f, y_width = 0.f, z_width = 0.f;
48 
49  // retrieve the geometry element associated to this DetID ( if present )
50  const DetGeomDesc* det = geom.sensorNoThrow(detid);
51 
52  if (det) {
53  x_pos = det->translation().x();
54  y_pos = det->translation().y();
55  z_pos = det->parentZPosition(); // retrieve the plane position;
56 
57  const auto& diamondDimensions = det->getDiamondDimensions();
58  x_width = 2.0 * diamondDimensions.xHalfWidth; // parameters stand for half the size
59  y_width = 2.0 * diamondDimensions.yHalfWidth;
60  z_width = 2.0 * diamondDimensions.zHalfWidth;
61  } else
62  throw cms::Exception("TotemTimingRecHitProducerAlgorithm") << "Failed to retrieve a sensor for " << detid;
63 
64  if (!sampicConversions_)
65  throw cms::Exception("TotemTimingRecHitProducerAlgorithm") << "No timing conversion retrieved.";
66 
67  edm::DetSet<TotemTimingRecHit>& rec_hits = output.find_or_insert(detid);
68 
69  for (const auto& digi : vec) {
70  const float triggerCellTimeInstant(sampicConversions_->triggerTime(digi));
71  const float timePrecision(sampicConversions_->timePrecision(digi));
72  const std::vector<float> time(sampicConversions_->timeSamples(digi));
73  std::vector<float> data(sampicConversions_->voltSamples(digi));
74 
75  auto [min_it, max_it] = std::minmax_element(data.begin(), data.end());
76 
77  if (det->name() == "CTPPS_Diamond_Segment") {
78  //flip the signal
79  for (unsigned int i = 0; i < data.size(); ++i)
80  data[i] = -data[i] + sampicOffset_;
81  }
82  RegressionResults baselineRegression = simplifiedLinearRegression(time, data, 0, baselinePoints_);
83 
84  // remove baseline
85  std::vector<float> dataCorrected(data.size());
86  for (unsigned int i = 0; i < data.size(); ++i)
87  dataCorrected[i] = data[i] - (baselineRegression.q + baselineRegression.m * time[i]);
88 
89  auto max_corrected_it = std::max_element(dataCorrected.begin(), dataCorrected.end());
90 
92 
93  //if det==diamond then if (*min_it) > saturationLimit_), calculate the t, otherwise t=-100
94  //if det==ufsd then if (*max_it) < saturationLimit_), calculate the t, otherwise t=-100
95  //the difference between ufsd and sampic conditions comes from the signal flip
96  if ((det->name() == "CTPPS_Diamond_Segment" && (*min_it) > saturationLimit_) ||
97  (det->name() == "CTPPS_UFSD_Segment" && (*max_it) < saturationLimit_))
98  t = constantFractionDiscriminator(time, dataCorrected);
100  rec_hits.emplace_back(x_pos,
101  x_width,
102  y_pos,
103  y_width,
104  z_pos,
105  z_width,
106  t,
107  triggerCellTimeInstant,
108  timePrecision,
109  *max_corrected_it,
110  baselineRegression.rms,
111  mode_);
112  }
113  }
114 }
const Translation & translation() const
Definition: DetGeomDesc.h:80
static std::string const input
Definition: EdmProvDump.cc:50
RegressionResults simplifiedLinearRegression(const std::vector< float > &time, const std::vector< float > &data, const unsigned int start_at, const unsigned int points) const
float parentZPosition() const
Definition: DetGeomDesc.h:106
decltype(auto) emplace_back(Args &&... args)
Definition: DetSet.h:68
float constantFractionDiscriminator(const std::vector< float > &time, const std::vector< float > &data)
const DiamondDimensions & getDiamondDimensions() const
Definition: DetGeomDesc.h:90
const std::string & name() const
Definition: DetGeomDesc.h:73
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
std::unique_ptr< TotemTimingConversions > sampicConversions_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79

◆ constantFractionDiscriminator()

float TotemTimingRecHitProducerAlgorithm::constantFractionDiscriminator ( const std::vector< float > &  time,
const std::vector< float > &  data 
)
private

Definition at line 187 of file TotemTimingRecHitProducerAlgorithm.cc.

References baselinePoints_, cfdFraction_, data, fastDiscriminator(), dqmMemoryStats::float, mps_fire::i, dqmiolumiharvest::j, lowPassFrequency_, SiStripPI::max, TotemTimingRecHit::NO_T_AVAILABLE, funct::sin(), SINC_COEFFICIENT, smoothingPoints_, remoteMonitoring_LASER_era2018_cfg::threshold, protons_cff::time, and x.

Referenced by build().

188  {
189  std::vector<float> dataProcessed(data);
190  if (lowPassFrequency_ != 0) // Smoothing
191  for (unsigned short i = 0; i < data.size(); ++i)
192  for (unsigned short j = -smoothingPoints_ / 2; j <= +smoothingPoints_ / 2; ++j)
193  if ((i + j) >= 0 && (i + j) < data.size() && j != 0) {
195  dataProcessed[i] += data[i + j] * std::sin(x) / x;
196  }
197  auto max_it = std::max_element(dataProcessed.begin(), dataProcessed.end());
198  float max = *max_it;
199 
200  float threshold = cfdFraction_ * max;
201  int indexOfThresholdCrossing = fastDiscriminator(dataProcessed, threshold);
202 
203  //--- necessary sanity checks before proceeding with the extrapolation
204  return (indexOfThresholdCrossing >= 1 && indexOfThresholdCrossing >= baselinePoints_ &&
205  indexOfThresholdCrossing < (int)time.size())
206  ? (time[indexOfThresholdCrossing - 1] - time[indexOfThresholdCrossing]) /
207  (dataProcessed[indexOfThresholdCrossing - 1] - dataProcessed[indexOfThresholdCrossing]) *
208  (threshold - dataProcessed[indexOfThresholdCrossing]) +
209  time[indexOfThresholdCrossing]
211 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
int fastDiscriminator(const std::vector< float > &data, float threshold) const

◆ fastDiscriminator()

int TotemTimingRecHitProducerAlgorithm::fastDiscriminator ( const std::vector< float > &  data,
float  threshold 
) const
private

Definition at line 157 of file TotemTimingRecHitProducerAlgorithm.cc.

References data, hysteresis_, mps_fire::i, and remoteMonitoring_LASER_era2018_cfg::threshold.

Referenced by constantFractionDiscriminator().

157  {
158  int threholdCrossingIndex = -1;
159  bool above = false;
160  bool lockForHysteresis = false;
161 
162  for (unsigned int i = 0; i < data.size(); ++i) {
163  // Look for first edge
164  if (!above && !lockForHysteresis && data[i] > threshold) {
165  threholdCrossingIndex = i;
166  above = true;
167  lockForHysteresis = true;
168  }
169  if (above && lockForHysteresis) // NOTE: not else if!, "above" can be set in
170  // the previous if
171  {
172  // Lock until above threshold_+hysteresis
173  if (lockForHysteresis && data[i] > threshold + hysteresis_)
174  lockForHysteresis = false;
175  // Ignore noise peaks
176  if (lockForHysteresis && data[i] < threshold) {
177  above = false;
178  lockForHysteresis = false;
179  threholdCrossingIndex = -1; // assigned because of noise
180  }
181  }
182  }
183 
184  return threholdCrossingIndex;
185 }
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79

◆ setCalibration()

void TotemTimingRecHitProducerAlgorithm::setCalibration ( const PPSTimingCalibration calib)

◆ simplifiedLinearRegression()

TotemTimingRecHitProducerAlgorithm::RegressionResults TotemTimingRecHitProducerAlgorithm::simplifiedLinearRegression ( const std::vector< float > &  time,
const std::vector< float > &  data,
const unsigned int  start_at,
const unsigned int  points 
) const
private

Definition at line 118 of file TotemTimingRecHitProducerAlgorithm.cc.

References data, mps_fire::i, SiStripPI::min, GetRecoTauVFromDQM_MC_cff::next, hiPixelPairStep_cff::points, funct::pow(), bookConverter::results, mathSSE::sqrt(), fftjetcommon_cfi::sx, fftjetcommon_cfi::sy, and protons_cff::time.

Referenced by build().

122  {
123  RegressionResults results;
124  if (time.size() != data.size())
125  return results;
126  if (start_at > time.size())
127  return results;
128  unsigned int stop_at = std::min((unsigned int)time.size(), start_at + points);
129  unsigned int realPoints = stop_at - start_at;
130  auto t_begin = std::next(time.begin(), start_at);
131  auto t_end = std::next(time.begin(), stop_at);
132  auto d_begin = std::next(data.begin(), start_at);
133  auto d_end = std::next(data.begin(), stop_at);
134 
135  const float sx = std::accumulate(t_begin, t_end, 0.);
136  const float sxx = std::inner_product(t_begin, t_end, t_begin, 0.); // sum(t**2)
137  const float sy = std::accumulate(d_begin, d_end, 0.);
138 
139  float sxy = 0.;
140  for (unsigned int i = 0; i < realPoints; ++i)
141  sxy += time[i] * data[i];
142 
143  // y = mx + q
144  results.m = (sxy * realPoints - sx * sy) / (sxx * realPoints - sx * sx);
145  results.q = sy / realPoints - results.m * sx / realPoints;
146 
147  float correctedSyy = 0.;
148  for (unsigned int i = 0; i < realPoints; ++i)
149  correctedSyy += pow(data[i] - (results.m * time[i] + results.q), 2);
150  results.rms = sqrt(correctedSyy / realPoints);
151 
152  return results;
153 }
T sqrt(T t)
Definition: SSEVec.h:19
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

Member Data Documentation

◆ baselinePoints_

int TotemTimingRecHitProducerAlgorithm::baselinePoints_
private

Definition at line 56 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build(), and constantFractionDiscriminator().

◆ cfdFraction_

double TotemTimingRecHitProducerAlgorithm::cfdFraction_
private

Definition at line 58 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

◆ hysteresis_

double TotemTimingRecHitProducerAlgorithm::hysteresis_
private

Definition at line 61 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by fastDiscriminator().

◆ lowPassFrequency_

double TotemTimingRecHitProducerAlgorithm::lowPassFrequency_
private

Definition at line 60 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

◆ mergeTimePeaks_

bool TotemTimingRecHitProducerAlgorithm::mergeTimePeaks_
private

Definition at line 55 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by setCalibration().

◆ mode_

TotemTimingRecHit::TimingAlgorithm TotemTimingRecHitProducerAlgorithm::mode_
private

Definition at line 64 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

◆ sampicConversions_

std::unique_ptr<TotemTimingConversions> TotemTimingRecHitProducerAlgorithm::sampicConversions_
private

Definition at line 53 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build(), and setCalibration().

◆ sampicOffset_

double TotemTimingRecHitProducerAlgorithm::sampicOffset_
private

Definition at line 62 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

◆ sampicSamplingPeriodNs_

double TotemTimingRecHitProducerAlgorithm::sampicSamplingPeriodNs_
private

Definition at line 63 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by setCalibration().

◆ saturationLimit_

double TotemTimingRecHitProducerAlgorithm::saturationLimit_
private

Definition at line 57 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

◆ SINC_COEFFICIENT

constexpr float TotemTimingRecHitProducerAlgorithm::SINC_COEFFICIENT = M_PI * 2 / 7.8
staticprivate

Definition at line 51 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

◆ smoothingPoints_

int TotemTimingRecHitProducerAlgorithm::smoothingPoints_
private

Definition at line 59 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().