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>

Classes

struct  RegressionResults
 

Public Member Functions

void build (const CTPPSGeometry &, const edm::DetSetVector< TotemTimingDigi > &, edm::DetSetVector< TotemTimingRecHit > &)
 
void setCalibration (const PPSTimingCalibration &)
 
 TotemTimingRecHitProducerAlgorithm (const edm::ParameterSet &conf)
 

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 saturationLimit_
 
int smoothingPoints_
 

Static Private Attributes

static constexpr float SINC_COEFFICIENT = M_PI * 2 / 7.8
 

Detailed Description

Definition at line 28 of file TotemTimingRecHitProducerAlgorithm.h.

Constructor & Destructor Documentation

◆ TotemTimingRecHitProducerAlgorithm()

TotemTimingRecHitProducerAlgorithm::TotemTimingRecHitProducerAlgorithm ( const edm::ParameterSet conf)

Definition at line 17 of file TotemTimingRecHitProducerAlgorithm.cc.

19  : mergeTimePeaks_(iConfig.getParameter<bool>("mergeTimePeaks")),
20  baselinePoints_(iConfig.getParameter<int>("baselinePoints")),
21  saturationLimit_(iConfig.getParameter<double>("saturationLimit")),
22  cfdFraction_(iConfig.getParameter<double>("cfdFraction")),
23  smoothingPoints_(iConfig.getParameter<int>("smoothingPoints")),
24  lowPassFrequency_(iConfig.getParameter<double>("lowPassFrequency")),

Member Function Documentation

◆ build()

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

Definition at line 34 of file TotemTimingRecHitProducerAlgorithm.cc.

37  {
38  for (const auto& vec : input) {
39  const TotemTimingDetId detid(vec.detId());
40 
41  float x_pos = 0.f, y_pos = 0.f, z_pos = 0.f;
42  float x_width = 0.f, y_width = 0.f, z_width = 0.f;
43 
44  // retrieve the geometry element associated to this DetID ( if present )
45  const DetGeomDesc* det = geom.sensorNoThrow(detid);
46 
47  if (det) {
48  x_pos = det->translation().x();
49  y_pos = det->translation().y();
50  z_pos = det->parentZPosition(); // retrieve the plane position;
51 
52  x_width = 2.0 * det->params()[0], // parameters stand for half the size
53  y_width = 2.0 * det->params()[1], z_width = 2.0 * det->params()[2];
54  } else
55  throw cms::Exception("TotemTimingRecHitProducerAlgorithm") << "Failed to retrieve a sensor for " << detid;
56 
57  if (!sampicConversions_)
58  throw cms::Exception("TotemTimingRecHitProducerAlgorithm") << "No timing conversion retrieved.";
59 
60  edm::DetSet<TotemTimingRecHit>& rec_hits = output.find_or_insert(detid);
61 
62  for (const auto& digi : vec) {
63  const float triggerCellTimeInstant(sampicConversions_->triggerTime(digi));
64  const float timePrecision(sampicConversions_->timePrecision(digi));
65  const std::vector<float> time(sampicConversions_->timeSamples(digi));
66  std::vector<float> data(sampicConversions_->voltSamples(digi));
67 
68  auto max_it = std::max_element(data.begin(), data.end());
69 
70  RegressionResults baselineRegression = simplifiedLinearRegression(time, data, 0, baselinePoints_);
71 
72  // remove baseline
73  std::vector<float> dataCorrected(data.size());
74  for (unsigned int i = 0; i < data.size(); ++i)
75  dataCorrected[i] = data[i] - (baselineRegression.q + baselineRegression.m * time[i]);
76  auto max_corrected_it = std::max_element(dataCorrected.begin(), dataCorrected.end());
77 
79  if (*max_it < saturationLimit_)
80  t = constantFractionDiscriminator(time, dataCorrected);
81 
83 
84  rec_hits.push_back(TotemTimingRecHit(x_pos,
85  x_width,
86  y_pos,
87  y_width,
88  z_pos,
89  z_width, // spatial information
90  t,
91  triggerCellTimeInstant,
92  timePrecision,
93  *max_corrected_it,
94  baselineRegression.rms,
95  mode_));
96  }
97  }

References baselinePoints_, TotemTimingRecHit::CFD, constantFractionDiscriminator(), data, Exception, relativeConstraints::geom, mps_fire::i, input, mode_, TotemTimingRecHit::NO_T_AVAILABLE, convertSQLitetoXML_cfg::output, DetGeomDesc::params(), DetGeomDesc::parentZPosition(), edm::DetSet< T >::push_back(), sampicConversions_, saturationLimit_, simplifiedLinearRegression(), OrderedSet::t, ntuplemaker::time, and DetGeomDesc::translation().

Referenced by TotemTimingRecHitProducer::produce().

◆ constantFractionDiscriminator()

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

Definition at line 170 of file TotemTimingRecHitProducerAlgorithm.cc.

172  {
173  std::vector<float> dataProcessed(data);
174  if (lowPassFrequency_ != 0) // Smoothing
175  for (unsigned short i = 0; i < data.size(); ++i)
176  for (unsigned short j = -smoothingPoints_ / 2; j <= +smoothingPoints_ / 2; ++j)
177  if ((i + j) >= 0 && (i + j) < data.size() && j != 0) {
179  dataProcessed[i] += data[i + j] * std::sin(x) / x;
180  }
181  auto max_it = std::max_element(dataProcessed.begin(), dataProcessed.end());
182  float max = *max_it;
183 
184  float threshold = cfdFraction_ * max;
185  int indexOfThresholdCrossing = fastDiscriminator(dataProcessed, threshold);
186 
187  //--- necessary sanity checks before proceeding with the extrapolation
188  return (indexOfThresholdCrossing >= 1 && indexOfThresholdCrossing >= baselinePoints_ &&
189  indexOfThresholdCrossing < (int)time.size())
190  ? (time[indexOfThresholdCrossing - 1] - time[indexOfThresholdCrossing]) /
191  (dataProcessed[indexOfThresholdCrossing - 1] - dataProcessed[indexOfThresholdCrossing]) *
192  (threshold - dataProcessed[indexOfThresholdCrossing]) +
193  time[indexOfThresholdCrossing]

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_LED_IterMethod_cfg::threshold, ntuplemaker::time, and x.

Referenced by build().

◆ fastDiscriminator()

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

Definition at line 140 of file TotemTimingRecHitProducerAlgorithm.cc.

141  {
142  int threholdCrossingIndex = -1;
143  bool above = false;
144  bool lockForHysteresis = false;
145 
146  for (unsigned int i = 0; i < data.size(); ++i) {
147  // Look for first edge
148  if (!above && !lockForHysteresis && data[i] > threshold) {
149  threholdCrossingIndex = i;
150  above = true;
151  lockForHysteresis = true;
152  }
153  if (above && lockForHysteresis) // NOTE: not else if!, "above" can be set in
154  // the previous if
155  {
156  // Lock until above threshold_+hysteresis
157  if (lockForHysteresis && data[i] > threshold + hysteresis_)
158  lockForHysteresis = false;
159  // Ignore noise peaks
160  if (lockForHysteresis && data[i] < threshold) {
161  above = false;
162  lockForHysteresis = false;
163  threholdCrossingIndex = -1; // assigned because of noise
164  }
165  }
166  }
167 
168  return threholdCrossingIndex;

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

Referenced by constantFractionDiscriminator().

◆ 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 101 of file TotemTimingRecHitProducerAlgorithm.cc.

106  {
107  RegressionResults results;
108  if (time.size() != data.size())
109  return results;
110  if (start_at > time.size())
111  return results;
112  unsigned int stop_at = std::min((unsigned int)time.size(), start_at + points);
113  unsigned int realPoints = stop_at - start_at;
114  auto t_begin = std::next(time.begin(), start_at);
115  auto t_end = std::next(time.begin(), stop_at);
116  auto d_begin = std::next(data.begin(), start_at);
117  auto d_end = std::next(data.begin(), stop_at);
118 
119  const float sx = std::accumulate(t_begin, t_end, 0.);
120  const float sxx = std::inner_product(t_begin, t_end, t_begin, 0.); // sum(t**2)
121  const float sy = std::accumulate(d_begin, d_end, 0.);
122 
123  float sxy = 0.;
124  for (unsigned int i = 0; i < realPoints; ++i)
125  sxy += time[i] * data[i];
126 
127  // y = mx + q
128  results.m = (sxy * realPoints - sx * sy) / (sxx * realPoints - sx * sx);
129  results.q = sy / realPoints - results.m * sx / realPoints;
130 
131  float correctedSyy = 0.;
132  for (unsigned int i = 0; i < realPoints; ++i)
133  correctedSyy += pow(data[i] - (results.m * time[i] + results.q), 2);
134  results.rms = sqrt(correctedSyy / realPoints);
135 
136  return results;

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

Referenced by build().

Member Data Documentation

◆ baselinePoints_

int TotemTimingRecHitProducerAlgorithm::baselinePoints_
private

Definition at line 61 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build(), and constantFractionDiscriminator().

◆ cfdFraction_

double TotemTimingRecHitProducerAlgorithm::cfdFraction_
private

Definition at line 63 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

◆ hysteresis_

double TotemTimingRecHitProducerAlgorithm::hysteresis_
private

Definition at line 66 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by fastDiscriminator().

◆ lowPassFrequency_

double TotemTimingRecHitProducerAlgorithm::lowPassFrequency_
private

Definition at line 65 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

◆ mergeTimePeaks_

bool TotemTimingRecHitProducerAlgorithm::mergeTimePeaks_
private

Definition at line 60 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by setCalibration().

◆ mode_

TotemTimingRecHit::TimingAlgorithm TotemTimingRecHitProducerAlgorithm::mode_
private

Definition at line 67 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

◆ sampicConversions_

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

Definition at line 58 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build(), and setCalibration().

◆ saturationLimit_

double TotemTimingRecHitProducerAlgorithm::saturationLimit_
private

Definition at line 62 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

◆ SINC_COEFFICIENT

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

Definition at line 56 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

◆ smoothingPoints_

int TotemTimingRecHitProducerAlgorithm::smoothingPoints_
private

Definition at line 64 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

TotemTimingRecHitProducerAlgorithm::constantFractionDiscriminator
float constantFractionDiscriminator(const std::vector< float > &time, const std::vector< float > &data)
Definition: TotemTimingRecHitProducerAlgorithm.cc:170
edm::DetSet::push_back
void push_back(const T &t)
Definition: DetSet.h:66
HLT_2018_cff.points
points
Definition: HLT_2018_cff.py:20125
mps_fire.i
i
Definition: mps_fire.py:355
input
static const std::string input
Definition: EdmProvDump.cc:48
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
TotemTimingConversions
Definition: TotemTimingConversions.h:21
TotemTimingRecHitProducerAlgorithm::mergeTimePeaks_
bool mergeTimePeaks_
Definition: TotemTimingRecHitProducerAlgorithm.h:60
edm::DetSet
Definition: DetSet.h:23
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
min
T min(T a, T b)
Definition: MathUtil.h:58
bookConverter.results
results
Definition: bookConverter.py:144
TotemTimingRecHit::CFD
Definition: TotemTimingRecHit.h:30
DDAxes::x
DetGeomDesc::parentZPosition
float parentZPosition() const
Definition: DetGeomDesc.h:56
TotemTimingRecHitProducerAlgorithm::smoothingPoints_
int smoothingPoints_
Definition: TotemTimingRecHitProducerAlgorithm.h:64
TotemTimingRecHitProducerAlgorithm::sampicConversions_
std::unique_ptr< TotemTimingConversions > sampicConversions_
Definition: TotemTimingRecHitProducerAlgorithm.h:58
TotemTimingRecHitProducerAlgorithm::baselinePoints_
int baselinePoints_
Definition: TotemTimingRecHitProducerAlgorithm.h:61
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
TotemTimingRecHitProducerAlgorithm::mode_
TotemTimingRecHit::TimingAlgorithm mode_
Definition: TotemTimingRecHitProducerAlgorithm.h:67
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
TotemTimingRecHitProducerAlgorithm::fastDiscriminator
int fastDiscriminator(const std::vector< float > &data, float threshold) const
Definition: TotemTimingRecHitProducerAlgorithm.cc:140
TotemTimingRecHit
Definition: TotemTimingRecHit.h:16
OrderedSet.t
t
Definition: OrderedSet.py:90
calib
Definition: CalibElectron.h:12
TotemTimingDetId
Detector ID class for CTPPS Totem Timing detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bits ...
Definition: TotemTimingDetId.h:26
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
DetGeomDesc
Geometrical description of a sensor.
Definition: DetGeomDesc.h:34
fftjetcommon_cfi.sy
sy
Definition: fftjetcommon_cfi.py:203
TotemTimingRecHitProducerAlgorithm::lowPassFrequency_
double lowPassFrequency_
Definition: TotemTimingRecHitProducerAlgorithm.h:65
TotemTimingRecHitProducerAlgorithm::saturationLimit_
double saturationLimit_
Definition: TotemTimingRecHitProducerAlgorithm.h:62
TotemTimingRecHit::NO_T_AVAILABLE
Definition: TotemTimingRecHit.h:25
TotemTimingRecHitProducerAlgorithm::cfdFraction_
double cfdFraction_
Definition: TotemTimingRecHitProducerAlgorithm.h:63
Exception
Definition: hltDiff.cc:246
TotemTimingRecHitProducerAlgorithm::hysteresis_
double hysteresis_
Definition: TotemTimingRecHitProducerAlgorithm.h:66
DetGeomDesc::params
std::vector< double > params() const
Definition: DetGeomDesc.h:66
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
DetGeomDesc::translation
Translation translation() const
Definition: DetGeomDesc.h:64
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
ntuplemaker.time
time
Definition: ntuplemaker.py:310
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:426
TotemTimingRecHitProducerAlgorithm::SINC_COEFFICIENT
static constexpr float SINC_COEFFICIENT
Definition: TotemTimingRecHitProducerAlgorithm.h:56
TotemTimingRecHitProducerAlgorithm::simplifiedLinearRegression
RegressionResults simplifiedLinearRegression(const std::vector< float > &time, const std::vector< float > &data, const unsigned int start_at, const unsigned int points) const
Definition: TotemTimingRecHitProducerAlgorithm.cc:101
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
fftjetcommon_cfi.sx
sx
Definition: fftjetcommon_cfi.py:202