22 : mergeTimePeaks_(iConfig.getParameter<bool>(
"mergeTimePeaks")),
23 baselinePoints_(iConfig.getParameter<int>(
"baselinePoints")),
24 saturationLimit_(iConfig.getParameter<double>(
"saturationLimit")),
25 cfdFraction_(iConfig.getParameter<double>(
"cfdFraction")),
26 smoothingPoints_(iConfig.getParameter<int>(
"smoothingPoints")),
27 lowPassFrequency_(iConfig.getParameter<double>(
"lowPassFrequency")),
28 hysteresis_(iConfig.getParameter<double>(
"hysteresis")),
29 sampicOffset_(iConfig.getParameter<double>(
"sampicOffset")),
30 sampicSamplingPeriodNs_(iConfig.getParameter<double>(
"sampicSamplingPeriodNs")) {}
43 for (
const auto& vec : input) {
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;
59 y_width = 2.0 * diamondDimensions.yHalfWidth;
60 z_width = 2.0 * diamondDimensions.zHalfWidth;
62 throw cms::Exception(
"TotemTimingRecHitProducerAlgorithm") <<
"Failed to retrieve a sensor for " << detid;
65 throw cms::Exception(
"TotemTimingRecHitProducerAlgorithm") <<
"No timing conversion retrieved.";
69 for (
const auto& digi : vec) {
75 auto [min_it, max_it] = std::minmax_element(
data.begin(),
data.end());
77 if (det->
name() ==
"CTPPS_Diamond_Segment") {
79 for (
unsigned int i = 0;
i <
data.size(); ++
i)
85 std::vector<float> dataCorrected(
data.size());
86 for (
unsigned int i = 0;
i <
data.size(); ++
i)
87 dataCorrected[
i] =
data[
i] - (baselineRegression.
q + baselineRegression.
m * time[
i]);
89 auto max_corrected_it = std::max_element(dataCorrected.begin(), dataCorrected.end());
107 triggerCellTimeInstant,
110 baselineRegression.
rms,
119 const std::vector<float>& time,
120 const std::vector<float>&
data,
121 const unsigned int start_at,
122 const unsigned int points)
const {
124 if (time.size() != data.size())
126 if (start_at > time.size())
128 unsigned int stop_at =
std::min((
unsigned int)time.size(), start_at + points);
129 unsigned int realPoints = stop_at - start_at;
130 auto t_begin =
std::next(time.begin(), start_at);
131 auto t_end =
std::next(time.begin(), stop_at);
132 auto d_begin =
std::next(data.begin(), start_at);
133 auto d_end =
std::next(data.begin(), stop_at);
135 const float sx = std::accumulate(t_begin, t_end, 0.);
136 const float sxx = std::inner_product(t_begin, t_end, t_begin, 0.);
137 const float sy = std::accumulate(d_begin, d_end, 0.);
140 for (
unsigned int i = 0;
i < realPoints; ++
i)
141 sxy += time[
i] * data[
i];
144 results.
m = (sxy * realPoints - sx * sy) / (sxx * realPoints - sx * sx);
145 results.
q = sy / realPoints - results.
m * sx / realPoints;
147 float correctedSyy = 0.;
148 for (
unsigned int i = 0;
i < realPoints; ++
i)
149 correctedSyy +=
pow(data[
i] - (results.
m * time[
i] + results.
q), 2);
150 results.
rms =
sqrt(correctedSyy / realPoints);
158 int threholdCrossingIndex = -1;
160 bool lockForHysteresis =
false;
162 for (
unsigned int i = 0;
i < data.size(); ++
i) {
164 if (!above && !lockForHysteresis && data[
i] > threshold) {
165 threholdCrossingIndex =
i;
167 lockForHysteresis =
true;
169 if (above && lockForHysteresis)
173 if (lockForHysteresis && data[
i] > threshold +
hysteresis_)
174 lockForHysteresis =
false;
176 if (lockForHysteresis && data[
i] < threshold) {
178 lockForHysteresis =
false;
179 threholdCrossingIndex = -1;
184 return threholdCrossingIndex;
188 const std::vector<float>&
data) {
189 std::vector<float> dataProcessed(data);
191 for (
unsigned short i = 0;
i < data.size(); ++
i)
193 if ((
i +
j) >= 0 && (
i +
j) < data.size() &&
j != 0) {
197 auto max_it = std::max_element(dataProcessed.begin(), dataProcessed.end());
204 return (indexOfThresholdCrossing >= 1 && indexOfThresholdCrossing >=
baselinePoints_ &&
205 indexOfThresholdCrossing < (
int)time.size())
206 ? (time[indexOfThresholdCrossing - 1] - time[indexOfThresholdCrossing]) /
207 (dataProcessed[indexOfThresholdCrossing - 1] - dataProcessed[indexOfThresholdCrossing]) *
208 (threshold - dataProcessed[indexOfThresholdCrossing]) +
209 time[indexOfThresholdCrossing]
const Translation & translation() const
const DiamondDimensions & getDiamondDimensions() const
Sin< T >::type sin(const T &t)
static std::string const input
reference find_or_insert(det_id_type id)
static constexpr float SINC_COEFFICIENT
const DetGeomDesc * sensorNoThrow(unsigned int id) const noexcept
decltype(auto) emplace_back(Args &&...args)
float constantFractionDiscriminator(const std::vector< float > &time, const std::vector< float > &data)
int fastDiscriminator(const std::vector< float > &data, float threshold) const
double sampicSamplingPeriodNs_
TotemTimingRecHitProducerAlgorithm(const edm::ParameterSet &conf)
void build(const CTPPSGeometry &, const edm::DetSetVector< TotemTimingDigi > &, edm::DetSetVector< TotemTimingRecHit > &)
RegressionResults simplifiedLinearRegression(const std::vector< float > &time, const std::vector< float > &data, const unsigned int start_at, const unsigned int points) const
The manager class for TOTEM RP geometry.
const std::string & name() const
float parentZPosition() const
Base class for CTPPS detector IDs.
std::unique_ptr< TotemTimingConversions > sampicConversions_
void setCalibration(const PPSTimingCalibration &)
char data[epos_bytes_allocation]
TotemTimingRecHit::TimingAlgorithm mode_
Power< A, B >::type pow(const A &a, const B &b)