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

21  : mergeTimePeaks_(iConfig.getParameter<bool>("mergeTimePeaks")),
22  baselinePoints_(iConfig.getParameter<int>("baselinePoints")),
23  saturationLimit_(iConfig.getParameter<double>("saturationLimit")),
24  cfdFraction_(iConfig.getParameter<double>("cfdFraction")),
25  smoothingPoints_(iConfig.getParameter<int>("smoothingPoints")),
26  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 36 of file TotemTimingRecHitProducerAlgorithm.cc.

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

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

Referenced by TotemTimingRecHitProducer::produce().

◆ constantFractionDiscriminator()

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

Definition at line 174 of file TotemTimingRecHitProducerAlgorithm.cc.

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

Referenced by build().

◆ fastDiscriminator()

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

Definition at line 144 of file TotemTimingRecHitProducerAlgorithm.cc.

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

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

Referenced by constantFractionDiscriminator().

◆ setCalibration()

void TotemTimingRecHitProducerAlgorithm::setCalibration ( const PPSTimingCalibration calib)

Definition at line 30 of file TotemTimingRecHitProducerAlgorithm.cc.

31  {
32  sampicConversions_ = std::make_unique<TotemTimingConversions>(mergeTimePeaks_, calib);

References mergeTimePeaks_, and sampicConversions_.

Referenced by TotemTimingRecHitProducer::produce().

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

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

References data, mps_fire::i, min(), GetRecoTauVFromDQM_MC_cff::next, HLT_FULL_cff::points, funct::pow(), bookConverter::results, mathSSE::sqrt(), fftjetcommon_cfi::sx, fftjetcommon_cfi::sy, and protons_cff::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:174
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
DetGeomDesc::translation
const Translation & translation() const
Definition: DetGeomDesc.h:79
HLT_FULL_cff.points
points
Definition: HLT_FULL_cff.py:21469
TotemTimingRecHitProducerAlgorithm::mergeTimePeaks_
bool mergeTimePeaks_
Definition: TotemTimingRecHitProducerAlgorithm.h:60
edm::DetSet
Definition: DetSet.h:23
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
min
T min(T a, T b)
Definition: MathUtil.h:58
protons_cff.time
time
Definition: protons_cff.py:35
bookConverter.results
results
Definition: bookConverter.py:144
TotemTimingRecHit::CFD
Definition: TotemTimingRecHit.h:30
DDAxes::x
DetGeomDesc::parentZPosition
float parentZPosition() const
Definition: DetGeomDesc.h:105
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
DetGeomDesc::getDiamondDimensions
const DiamondDimensions & getDiamondDimensions() const
Definition: DetGeomDesc.h:89
TotemTimingRecHit::NO_T_AVAILABLE
Definition: TotemTimingRecHit.h:25
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:144
DiamondDimensions::xHalfWidth
double xHalfWidth
Definition: DetGeomDesc.h:45
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
edm::DetSet::emplace_back
decltype(auto) emplace_back(Args &&... args)
Definition: DetSet.h:68
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
DetGeomDesc
Definition: DetGeomDesc.h:50
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
TotemTimingRecHitProducerAlgorithm::cfdFraction_
double cfdFraction_
Definition: TotemTimingRecHitProducerAlgorithm.h:63
Exception
Definition: hltDiff.cc:245
TotemTimingRecHitProducerAlgorithm::hysteresis_
double hysteresis_
Definition: TotemTimingRecHitProducerAlgorithm.h:66
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:430
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
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:105
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
fftjetcommon_cfi.sx
sx
Definition: fftjetcommon_cfi.py:202