CMS 3D CMS Logo

TotemTimingRecHitProducerAlgorithm.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of CTPPS offline software.
4  * Authors:
5  * Laurent Forthomme (laurent.forthomme@cern.ch)
6  * Nicola Minafra
7  *
8  ****************************************************************************/
9 
11 
13 
14 #include <memory>
15 
16 #include <numeric>
17 
18 //----------------------------------------------------------------------------------------------------
19 
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")),
27  hysteresis_(iConfig.getParameter<double>("hysteresis")) {}
28 
29 //----------------------------------------------------------------------------------------------------
30 
32  sampicConversions_ = std::make_unique<TotemTimingConversions>(mergeTimePeaks_, calib);
33 }
34 
35 //----------------------------------------------------------------------------------------------------
36 
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 
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  }
102 }
103 
104 //----------------------------------------------------------------------------------------------------
105 
107  const std::vector<float>& time,
108  const std::vector<float>& data,
109  const unsigned int start_at,
110  const unsigned int points) const {
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;
141 }
142 
143 //----------------------------------------------------------------------------------------------------
144 
145 int TotemTimingRecHitProducerAlgorithm::fastDiscriminator(const std::vector<float>& data, float threshold) const {
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;
173 }
174 
176  const std::vector<float>& data) {
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]
199 }
TotemTimingRecHitProducerAlgorithm::constantFractionDiscriminator
float constantFractionDiscriminator(const std::vector< float > &time, const std::vector< float > &data)
Definition: TotemTimingRecHitProducerAlgorithm.cc:174
edm::DetSetVector
Definition: DetSetVector.h:61
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
CTPPSGeometry
The manager class for TOTEM RP geometry.
Definition: CTPPSGeometry.h:29
TotemTimingRecHitProducerAlgorithm::build
void build(const CTPPSGeometry &, const edm::DetSetVector< TotemTimingDigi > &, edm::DetSetVector< TotemTimingRecHit > &)
Definition: TotemTimingRecHitProducerAlgorithm.cc:36
DetGeomDesc::translation
const Translation & translation() const
Definition: DetGeomDesc.h:75
HLT_FULL_cff.points
points
Definition: HLT_FULL_cff.py:21449
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
TotemTimingRecHitProducerAlgorithm::TotemTimingRecHitProducerAlgorithm
TotemTimingRecHitProducerAlgorithm(const edm::ParameterSet &conf)
Definition: TotemTimingRecHitProducerAlgorithm.cc:19
protons_cff.time
time
Definition: protons_cff.py:39
bookConverter.results
results
Definition: bookConverter.py:144
TotemTimingRecHit::CFD
Definition: TotemTimingRecHit.h:30
DDAxes::x
DetGeomDesc::parentZPosition
float parentZPosition() const
Definition: DetGeomDesc.h:101
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
TotemTimingRecHitProducerAlgorithm.h
TotemTimingRecHitProducerAlgorithm::setCalibration
void setCalibration(const PPSTimingCalibration &)
Definition: TotemTimingRecHitProducerAlgorithm.cc:30
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DetGeomDesc::getDiamondDimensions
const DiamondDimensions & getDiamondDimensions() const
Definition: DetGeomDesc.h:85
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:44
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::ParameterSet
Definition: ParameterSet.h:47
edm::DetSet::emplace_back
decltype(auto) emplace_back(Args &&... args)
Definition: DetSet.h:68
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
DetGeomDesc
Definition: DetGeomDesc.h:49
fftjetcommon_cfi.sy
sy
Definition: fftjetcommon_cfi.py:203
TotemTimingRecHitProducerAlgorithm::RegressionResults
Definition: TotemTimingRecHitProducerAlgorithm.h:42
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: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
PPSTimingCalibration
Definition: PPSTimingCalibration.h:17
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