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 float SINC_COEFFICIENT = M_PI*2 / 7.8
 

Detailed Description

Definition at line 28 of file TotemTimingRecHitProducerAlgorithm.h.

Constructor & Destructor Documentation

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

Definition at line 18 of file TotemTimingRecHitProducerAlgorithm.cc.

18  :
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")),
25  hysteresis_ (iConfig.getParameter<double>("hysteresis"))
26 {}

Member Function Documentation

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

Definition at line 39 of file TotemTimingRecHitProducerAlgorithm.cc.

References baselinePoints_, TotemTimingRecHit::CFD, constantFractionDiscriminator(), data, Exception, edm::DetSetVector< T >::find_or_insert(), CTPPSGeometry::getSensorNoThrow(), mps_fire::i, mode_, TotemTimingRecHit::NO_T_AVAILABLE, DetGeomDesc::params(), DetGeomDesc::parentZPosition(), edm::DetSet< T >::push_back(), sampicConversions_, saturationLimit_, simplifiedLinearRegression(), protons_cff::t, protons_cff::time, and DetGeomDesc::translation().

Referenced by TotemTimingRecHitProducer::produce().

42 {
43  for (const auto& vec : input) {
44  const TotemTimingDetId 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.getSensorNoThrow(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  x_width = 2.0 * det->params()[0], // parameters stand for half the size
58  y_width = 2.0 * det->params()[1],
59  z_width = 2.0 * det->params()[2];
60  }
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 max_it = std::max_element(data.begin(), data.end());
76 
77  RegressionResults baselineRegression =
79 
80  // remove baseline
81  std::vector<float> dataCorrected(data.size());
82  for (unsigned int i = 0; i < data.size(); ++i)
83  dataCorrected[i] = data[i] - (baselineRegression.q + baselineRegression.m * time[i]);
84  auto max_corrected_it =
85  std::max_element(dataCorrected.begin(), dataCorrected.end());
86 
88  if (*max_it < saturationLimit_)
89  t = constantFractionDiscriminator(time, dataCorrected);
90 
92 
94  x_pos, x_width, y_pos, y_width, z_pos, z_width, // spatial information
95  t, triggerCellTimeInstant, timePrecision, *max_corrected_it,
96  baselineRegression.rms, mode_));
97  }
98  }
99 }
Translation translation() const
Definition: DetGeomDesc.h:66
void push_back(const T &t)
Definition: DetSet.h:68
const DetGeomDesc * getSensorNoThrow(unsigned int id) const
reference find_or_insert(det_id_type id)
Definition: DetSetVector.h:254
float constantFractionDiscriminator(const std::vector< float > &time, const std::vector< float > &data)
Geometrical description of a sensor.
Definition: DetGeomDesc.h:35
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:58
std::unique_ptr< TotemTimingConversions > sampicConversions_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::vector< double > params() const
Definition: DetGeomDesc.h:68
Detector ID class for CTPPS Totem Timing detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bits ...
float TotemTimingRecHitProducerAlgorithm::constantFractionDiscriminator ( const std::vector< float > &  time,
const std::vector< float > &  data 
)
private

Definition at line 174 of file TotemTimingRecHitProducerAlgorithm.cc.

References baselinePoints_, cfdFraction_, fastDiscriminator(), mps_fire::i, lowPassFrequency_, SiStripPI::max, TotemTimingRecHit::NO_T_AVAILABLE, funct::sin(), SINC_COEFFICIENT, smoothingPoints_, electronIdCutBased_cfi::threshold, and x.

Referenced by build(), and TotemTimingRecHitProducerAlgorithm::RegressionResults::RegressionResults().

175 {
176  std::vector<float> dataProcessed(data);
177  if (lowPassFrequency_ != 0) // Smoothing
178  for (unsigned short i = 0; i < data.size(); ++i)
179  for (unsigned short j = -smoothingPoints_/2; j <= +smoothingPoints_/2; ++j)
180  if ((i+j) >= 0 && (i+j) < data.size() && j != 0) {
181  float x = SINC_COEFFICIENT * lowPassFrequency_ * j;
182  dataProcessed[i] += data[i + j] * std::sin(x) / x;
183  }
184  auto max_it = std::max_element(dataProcessed.begin(), dataProcessed.end());
185  float max = *max_it;
186 
187  float threshold = cfdFraction_ * max;
188  int indexOfThresholdCrossing = fastDiscriminator(dataProcessed, threshold);
189 
190  //--- necessary sanity checks before proceeding with the extrapolation
191  return (indexOfThresholdCrossing >= 1
192  && indexOfThresholdCrossing >= baselinePoints_
193  && indexOfThresholdCrossing < (int)time.size())
194  ? (time[indexOfThresholdCrossing-1]-time[indexOfThresholdCrossing])
195  / (dataProcessed[indexOfThresholdCrossing-1] -dataProcessed[indexOfThresholdCrossing]) * (threshold-dataProcessed[indexOfThresholdCrossing])
196  + time[indexOfThresholdCrossing]
198 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
int fastDiscriminator(const std::vector< float > &data, float threshold) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
int TotemTimingRecHitProducerAlgorithm::fastDiscriminator ( const std::vector< float > &  data,
float  threshold 
) const
private

Definition at line 142 of file TotemTimingRecHitProducerAlgorithm.cc.

References hysteresis_, and mps_fire::i.

Referenced by constantFractionDiscriminator(), and TotemTimingRecHitProducerAlgorithm::RegressionResults::RegressionResults().

143 {
144  int threholdCrossingIndex = -1;
145  bool above = false;
146  bool lockForHysteresis = false;
147 
148  for (unsigned int i = 0; i < data.size(); ++i) {
149  // Look for first edge
150  if (!above && !lockForHysteresis && data[i] > threshold) {
151  threholdCrossingIndex = i;
152  above = true;
153  lockForHysteresis = true;
154  }
155  if (above && lockForHysteresis) // NOTE: not else if!, "above" can be set in
156  // the previous if
157  {
158  // Lock until above threshold_+hysteresis
159  if (lockForHysteresis && data[i] > threshold + hysteresis_)
160  lockForHysteresis = false;
161  // Ignore noise peaks
162  if (lockForHysteresis && data[i] < threshold) {
163  above = false;
164  lockForHysteresis = false;
165  threholdCrossingIndex = -1; // assigned because of noise
166  }
167  }
168  }
169 
170  return threholdCrossingIndex;
171 }
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void TotemTimingRecHitProducerAlgorithm::setCalibration ( const PPSTimingCalibration calib)
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 104 of file TotemTimingRecHitProducerAlgorithm.cc.

References mps_fire::i, TotemTimingRecHitProducerAlgorithm::RegressionResults::m, min(), GetRecoTauVFromDQM_MC_cff::next, hiPixelPairStep_cff::points, funct::pow(), TotemTimingRecHitProducerAlgorithm::RegressionResults::q, TotemTimingRecHitProducerAlgorithm::RegressionResults::rms, mathSSE::sqrt(), fftjetcommon_cfi::sx, and fftjetcommon_cfi::sy.

Referenced by build(), and TotemTimingRecHitProducerAlgorithm::RegressionResults::RegressionResults().

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;
137 }
T sqrt(T t)
Definition: SSEVec.h:18
T min(T a, T b)
Definition: MathUtil.h:58
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40

Member Data Documentation

int TotemTimingRecHitProducerAlgorithm::baselinePoints_
private

Definition at line 60 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build(), and constantFractionDiscriminator().

double TotemTimingRecHitProducerAlgorithm::cfdFraction_
private

Definition at line 62 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

double TotemTimingRecHitProducerAlgorithm::hysteresis_
private

Definition at line 65 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by fastDiscriminator().

double TotemTimingRecHitProducerAlgorithm::lowPassFrequency_
private

Definition at line 64 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

bool TotemTimingRecHitProducerAlgorithm::mergeTimePeaks_
private

Definition at line 59 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by setCalibration().

TotemTimingRecHit::TimingAlgorithm TotemTimingRecHitProducerAlgorithm::mode_
private

Definition at line 66 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

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

Definition at line 57 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build(), and setCalibration().

double TotemTimingRecHitProducerAlgorithm::saturationLimit_
private

Definition at line 61 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

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

Definition at line 55 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

int TotemTimingRecHitProducerAlgorithm::smoothingPoints_
private

Definition at line 63 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().