17 covariance(Eigen::Matrix2d::Zero())
22 const Eigen::Vector2d &
sum,
23 const Eigen::Matrix2d &covariance) :
sum(
sum), covariance(covariance) {}
30 sum += Eigen::Vector2d(kin.
px(), kin.
py());
36 const std::vector<double> &
sorted,
42 std::size_t nTrim =
sorted.size() * (1 - trimFraction) / 2;
49 for (std::size_t ii = 0; ii <
sorted.size() - nTrim; ++ii)
52 variance +=
val *
val * (ii < nTrim ? 2 : 1);
63 std::vector<double>
sorted;
67 std::lower_bound(
sorted.begin(),
sorted.end(), tower.sumEt()),
78 double squaredSum = 0;
86 squaredSum += tower.sumEt() * tower.sumEt();
99 for (std::size_t
d = 0;
d < 4; ++
d)
104 sum += tower.sumEt();
115 const Eigen::Vector2d &pileupSum,
116 const Eigen::Matrix2d &pileupCovariance,
117 const Eigen::VectorXd &towerExpectations,
118 const Eigen::VectorXd &towerVariances,
119 const Eigen::VectorXd &correctionDirections,
120 double constraintImportance)
123 std::size_t nCorr = correctionDirections.size();
128 Eigen::Matrix<double, 2, Eigen::Dynamic> cosSin(2, nCorr);
129 cosSin.row(0) = correctionDirections.array().cos();
130 cosSin.row(1) = correctionDirections.array().sin();
137 constraintImportance);
141 const Eigen::Vector2d &pileupSum,
142 const Eigen::Matrix2d &pileupCovariance,
144 double towerVariance,
145 const Eigen::VectorXd &correctionDirections,
146 double constraintImportance)
148 std::size_t nCorr = correctionDirections.size();
152 Eigen::VectorXd::Constant(nCorr, towerMean),
153 Eigen::VectorXd::Constant(nCorr, towerVariance),
154 correctionDirections,
155 constraintImportance);
159 const Eigen::Vector2d &pileupSum,
160 const Eigen::Matrix2d &pileupCovariance,
161 const Eigen::VectorXd &towerExpectations,
162 const Eigen::VectorXd &towerVariances,
163 const Eigen::Matrix<double, 2, Eigen::Dynamic> &cosSin,
164 double constraintImportance)
167 std::size_t nCorr = cosSin.cols();
177 if (pileupCovariance.determinant() == 0)
182 return towerExpectations;
186 towerExpectations.cwiseQuotient(towerVariances) -
188 constraintImportance * cosSin.transpose() * pileupCovariance.inverse() * pileupSum;
189 Eigen::MatrixXd diagonal = towerVariances.cwiseInverse().asDiagonal();
194 constraintImportance * (cosSin.transpose() * pileupCovariance.inverse() * cosSin);
196 return coeffMatrix.inverse() *
constants;
200 const Eigen::Vector2d &pileupSum,
201 const Eigen::Matrix2d &pileupCovariance,
203 double towerVariance,
204 const Eigen::Matrix<double, 2, Eigen::Dynamic> &cosSin,
205 double constraintImportance)
207 std::size_t nCorr = cosSin.cols();
211 Eigen::VectorXd::Constant(nCorr, towerMean),
212 Eigen::VectorXd::Constant(nCorr, towerVariance),
214 constraintImportance);
217 std::vector<SignedKinematics>
pufit(
218 const Eigen::Vector2d &pileupSum,
219 const Eigen::Matrix2d &pileupCovariance,
220 const std::vector<double> &towerExpectations,
221 const std::vector<double> &towerVariances,
222 const std::vector<SignedKinematics> &toCorrect,
223 double constraintImportance)
226 std::size_t nCorr = toCorrect.size();
232 Eigen::Matrix<double, 2, Eigen::Dynamic> cosSin(2, nCorr);
233 Eigen::VectorXd vecTowerExpectations(nCorr);
234 Eigen::VectorXd vecTowerVariances(nCorr);
235 for (std::size_t ii = 0; ii < nCorr; ++ii)
237 cosSin(0, ii) = toCorrect.at(ii).cosPhi();
238 cosSin(1, ii) = toCorrect.at(ii).sinPhi();
239 vecTowerExpectations(ii) = towerExpectations.at(ii);
240 vecTowerVariances(ii) = towerVariances.at(ii);
242 Eigen::VectorXd corrections =
pufit(
245 vecTowerExpectations,
248 constraintImportance);
250 std::vector<SignedKinematics> kinCorrections;
251 kinCorrections.reserve(nCorr);
252 for (std::size_t ii = 0; ii < nCorr; ++ii)
254 -corrections.coeff(ii),
255 toCorrect.at(ii).eta(),
256 toCorrect.at(ii).phi()));
257 return kinCorrections;
259 std::vector<SignedKinematics>
pufit(
260 const Eigen::Vector2d &pileupSum,
261 const Eigen::Matrix2d &pileupCovariance,
263 double towerVariance,
264 const std::vector<SignedKinematics> &toCorrect,
265 double constraintImportance)
268 std::size_t nCorr = toCorrect.size();
276 std::vector<double>(nCorr, towerMean),
277 std::vector<double>(nCorr, towerVariance),
279 constraintImportance);