File indexing completed on 2025-03-05 03:16:37
0001 #include "L1Trigger/L1TGEM/interface/ME0StubPrimitive.h"
0002
0003
0004 ME0StubPrimitive::ME0StubPrimitive() : layerCount_{0}, hitCount_{0}, patternId_{0}, strip_{0}, etaPartition_{0} {
0005 updateQuality();
0006 }
0007 ME0StubPrimitive::ME0StubPrimitive(int layerCount, int hitCount, int patternId, int strip, int etaPartition)
0008 : layerCount_{layerCount}, hitCount_{hitCount}, patternId_{patternId}, strip_{strip}, etaPartition_{etaPartition} {
0009 updateQuality();
0010 }
0011 ME0StubPrimitive::ME0StubPrimitive(int layerCount, int hitCount, int patternId, int strip, int etaPartition, double bx)
0012 : layerCount_{layerCount},
0013 hitCount_{hitCount},
0014 patternId_{patternId},
0015 strip_{strip},
0016 etaPartition_{etaPartition},
0017 bx_{bx} {
0018 updateQuality();
0019 }
0020 ME0StubPrimitive::ME0StubPrimitive(
0021 int layerCount, int hitCount, int patternId, int strip, int etaPartition, double bx, std::vector<double>& centroids)
0022 : layerCount_{layerCount},
0023 hitCount_{hitCount},
0024 patternId_{patternId},
0025 strip_{strip},
0026 etaPartition_{etaPartition},
0027 bx_{bx},
0028 centroids_{centroids} {
0029 updateQuality();
0030 }
0031 void ME0StubPrimitive::reset() {
0032 layerCount_ = 0;
0033 hitCount_ = 0;
0034 patternId_ = 0;
0035 updateQuality();
0036 }
0037 void ME0StubPrimitive::updateQuality() {
0038 int idMask;
0039 if (layerCount_) {
0040 if (ignoreBend_) {
0041 idMask = 0xfe;
0042 } else {
0043 idMask = 0xff;
0044 }
0045 quality_ = (layerCount_ << 23) | (hitCount_ << 17) | ((patternId_ & idMask) << 12) | (strip_ << 4) | etaPartition_;
0046 } else {
0047 quality_ = 0;
0048 }
0049 }
0050 void ME0StubPrimitive::fit(int maxSpan) {
0051 if (patternId_ != 0) {
0052 std::vector<double> tmp;
0053 tmp.reserve(centroids_.size());
0054 for (double centroid : centroids_) {
0055 tmp.push_back(centroid - (maxSpan / 2 + 1));
0056 }
0057 std::vector<double> x;
0058 std::vector<double> centroids;
0059 for (uint32_t i = 0; i < tmp.size(); ++i) {
0060 if (tmp[i] != -1 * (maxSpan / 2 + 1)) {
0061 x.push_back(i - 2.5);
0062 centroids.push_back(tmp[i]);
0063 }
0064 }
0065 std::vector<double> fit = llseFit(x, centroids);
0066 bendingAngle_ = fit[0];
0067 subStrip_ = fit[1];
0068 mse_ = fit[2];
0069 }
0070 }
0071 std::vector<double> ME0StubPrimitive::llseFit(const std::vector<double>& x, const std::vector<double>& y) {
0072 double xSum = 0;
0073 double ySum = 0;
0074 for (double val : x) {
0075 xSum += val;
0076 }
0077 for (double val : y) {
0078 ySum += val;
0079 }
0080 int n = x.size();
0081
0082 double product = 0;
0083 double squares = 0;
0084 for (int i = 0; i < n; ++i) {
0085 product += (n * x[i] - xSum) * (n * y[i] - ySum);
0086 squares += (n * x[i] - xSum) * (n * x[i] - xSum);
0087 }
0088
0089 double m = product / squares;
0090 double b = (ySum - m * xSum) / n;
0091 double sse = 0.0;
0092 for (int i = 0; i < n; ++i) {
0093 sse += (y[i] - m * x[i] - b) * (y[i] - m * x[i] - b);
0094 }
0095
0096 std::vector<double> fit = {m, b, sse / n};
0097 return fit;
0098 }