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 > &)
 
 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, const 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_
 
TotemTimingRecHit::TimingAlgorithm mode_
 
TotemTimingConversions sampicConversions_
 
double saturationLimit_
 
int smoothingPoints_
 

Static Private Attributes

static const float SINC_COEFFICIENT = std::acos(-1) * 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.

20  : sampicConversions_(iConfig.getParameter<std::string>("calibrationFile")),
21  baselinePoints_(iConfig.getParameter<int>("baselinePoints")),
22  saturationLimit_(iConfig.getParameter<double>("saturationLimit")),
23  cfdFraction_(iConfig.getParameter<double>("cfdFraction")),
24  smoothingPoints_(iConfig.getParameter<int>("smoothingPoints")),
25  lowPassFrequency_(iConfig.getParameter<double>("lowPassFrequency")),
26  hysteresis_(iConfig.getParameter<double>("hysteresis")) {}

Member Function Documentation

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

Definition at line 28 of file TotemTimingRecHitProducerAlgorithm.cc.

References baselinePoints_, TotemTimingRecHit::CFD, constantFractionDiscriminator(), data, edm::DetSetVector< T >::find_or_insert(), CTPPSGeometry::getSensorNoThrow(), TotemTimingConversions::getTimeSamples(), TotemTimingConversions::getTriggerTime(), TotemTimingConversions::getVoltSamples(), mps_fire::i, mode_, TotemTimingRecHit::NO_T_AVAILABLE, DetGeomDesc::params(), DetGeomDesc::parents(), edm::DetSet< T >::push_back(), sampicConversions_, saturationLimit_, simplifiedLinearRegression(), lumiQTWidget::t, ntuplemaker::time, and DetGeomDesc::translation().

Referenced by TotemTimingRecHitProducer::produce().

30  {
31  for (const auto &vec : input) {
32  const TotemTimingDetId detid(vec.detId());
33 
34  float x_pos = 0, y_pos = 0, z_pos = 0, x_width = 0, y_width = 0,
35  z_width = 0;
36 
37  // retrieve the geometry element associated to this DetID ( if present )
38  const DetGeomDesc *det = geom->getSensorNoThrow(detid);
39 
40  if (det) {
41  x_pos = det->translation().x(), y_pos = det->translation().y();
42  if (det->parents().empty())
43  edm::LogWarning("TotemTimingRecHitProducerAlgorithm")
44  << "The geometry element for " << detid
45  << " has no parents. Check the geometry hierarchy!";
46  else
47  z_pos = det->parents()[det->parents().size() - 1]
48  .absTranslation()
49  .z(); // retrieve the plane position;
50 
51  x_width = 2.0 * det->params().at(0), // parameters stand for half the size
52  y_width = 2.0 * det->params().at(1),
53  z_width = 2.0 * det->params().at(2);
54  } else
55  edm::LogWarning("TotemTimingRecHitProducerAlgorithm")
56  << "Failed to retrieve a sensor for " << detid;
57 
58  edm::DetSet<TotemTimingRecHit> &rec_hits = output.find_or_insert(detid);
59 
60  for (const auto &digi : vec) {
61  const float triggerCellTimeInstant(
63  const std::vector<float> time(sampicConversions_.getTimeSamples(digi));
64  std::vector<float> data(sampicConversions_.getVoltSamples(digi));
65 
66  auto max_it = std::max_element(data.begin(), data.end());
67 
68  RegressionResults baselineRegression =
70 
71  // remove baseline
72  std::vector<float> dataCorrected(data.size());
73  for (unsigned int i = 0; i < data.size(); ++i)
74  dataCorrected.at(i) = data.at(i) -
75  (baselineRegression.q + baselineRegression.m * time.at(i));
76  auto max_corrected_it =
77  std::max_element(dataCorrected.begin(), dataCorrected.end());
78 
80  if (*max_it < saturationLimit_)
81  t = constantFractionDiscriminator(time, dataCorrected);
82 
84 
86  x_pos, x_width, y_pos, y_width, z_pos, z_width, // spatial information
87  t, triggerCellTimeInstant, .0, *max_corrected_it,
88  baselineRegression.rms, mode_));
89  }
90  }
91 }
void push_back(const T &t)
Definition: DetSet.h:68
std::vector< float > getTimeSamples(const TotemTimingDigi &digi) const
const DetGeomDesc * getSensorNoThrow(unsigned int id) const
std::vector< float > getVoltSamples(const TotemTimingDigi &digi) const
const float getTriggerTime(const TotemTimingDigi &digi) 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:37
virtual std::vector< DDExpandedNode > parents() const
returns all the components below
Definition: DetGeomDesc.h:67
DDTranslation translation() const
Definition: DetGeomDesc.h:84
RegressionResults simplifiedLinearRegression(const std::vector< float > &time, const std::vector< float > &data, const unsigned int start_at, const unsigned int points) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::vector< double > params() const
Definition: DetGeomDesc.h:89
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 169 of file TotemTimingRecHitProducerAlgorithm.cc.

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

Referenced by build().

170  {
171  std::vector<float> dataProcessed(data);
172  if (lowPassFrequency_ != 0) {
173  // Smoothing
174  for (int i = 0; i < (int)data.size(); ++i) {
175  for (int j = -smoothingPoints_ / 2;
176  j <= +smoothingPoints_ / 2; ++j) {
177  if ((i + j) >= 0 && (i + j) < (int)data.size() && j != 0) {
178  float x = SINC_COEFFICIENT * lowPassFrequency_ * j;
179  dataProcessed.at(i) += data.at(i + j) * std::sin(x) / x;
180  }
181  }
182  }
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 
191  if (indexOfThresholdCrossing >= baselinePoints_ &&
192  indexOfThresholdCrossing < (int)time.size()) {
193  t = (time.at(indexOfThresholdCrossing - 1) -
194  time.at(indexOfThresholdCrossing)) /
195  (dataProcessed.at(indexOfThresholdCrossing - 1) -
196  dataProcessed.at(indexOfThresholdCrossing)) *
197  (threshold - dataProcessed.at(indexOfThresholdCrossing)) +
198  time.at(indexOfThresholdCrossing);
199  }
200 
201  return t;
202 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
int fastDiscriminator(const std::vector< float > &data, const float &threshold) const
int TotemTimingRecHitProducerAlgorithm::fastDiscriminator ( const std::vector< float > &  data,
const float &  threshold 
) const
private

Definition at line 137 of file TotemTimingRecHitProducerAlgorithm.cc.

References hysteresis_, mps_fire::i, and electronIdCutBased_cfi::threshold.

Referenced by constantFractionDiscriminator().

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

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

Referenced by build().

96  {
97  RegressionResults results;
98  if (time.size() != data.size()) {
99  return results;
100  }
101  if (start_at > time.size()) {
102  return results;
103  }
104  unsigned int stop_at = std::min((unsigned int)time.size(), start_at + points);
105  unsigned int realPoints = stop_at - start_at;
106  auto t_begin = std::next(time.begin(), start_at);
107  auto t_end = std::next(time.begin(), stop_at);
108  auto d_begin = std::next(data.begin(), start_at);
109  auto d_end = std::next(data.begin(), stop_at);
110 
111  float sx = .0;
112  std::for_each(t_begin, t_end, [&](float value) { sx += value; });
113  float sxx = .0;
114  std::for_each(t_begin, t_end, [&](float value) { sxx += value * value; });
115 
116  float sy = .0;
117  std::for_each(d_begin, d_end, [&](float value) { sy += value; });
118  float syy = .0;
119  std::for_each(d_begin, d_end, [&](float value) { syy += value * value; });
120 
121  float sxy = .0;
122  for (unsigned int i = 0; i < realPoints; ++i)
123  sxy += (time.at(i)) * (data.at(i));
124 
125  // y = mx + q
126  results.m = (sxy * realPoints - sx * sy) / (sxx * realPoints - sx * sx);
127  results.q = sy / realPoints - results.m * sx / realPoints;
128 
129  float correctedSyy = .0;
130  for (unsigned int i = 0; i < realPoints; ++i)
131  correctedSyy += pow(data.at(i) - (results.m * time.at(i) + results.q), 2);
132  results.rms = sqrt(correctedSyy / realPoints);
133 
134  return results;
135 }
T sqrt(T t)
Definition: SSEVec.h:18
Definition: value.py:1
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 46 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build(), and constantFractionDiscriminator().

double TotemTimingRecHitProducerAlgorithm::cfdFraction_
private

Definition at line 48 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

double TotemTimingRecHitProducerAlgorithm::hysteresis_
private

Definition at line 51 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by fastDiscriminator().

double TotemTimingRecHitProducerAlgorithm::lowPassFrequency_
private

Definition at line 50 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

TotemTimingRecHit::TimingAlgorithm TotemTimingRecHitProducerAlgorithm::mode_
private

Definition at line 52 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

TotemTimingConversions TotemTimingRecHitProducerAlgorithm::sampicConversions_
private

Definition at line 45 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

double TotemTimingRecHitProducerAlgorithm::saturationLimit_
private

Definition at line 47 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by build().

const float TotemTimingRecHitProducerAlgorithm::SINC_COEFFICIENT = std::acos(-1) * 2 / 7.8
staticprivate

Definition at line 43 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().

int TotemTimingRecHitProducerAlgorithm::smoothingPoints_
private

Definition at line 49 of file TotemTimingRecHitProducerAlgorithm.h.

Referenced by constantFractionDiscriminator().