1 #ifndef RecoVertex_PrimaryVertexProducer_WeightedMeanFitter_h 2 #define RecoVertex_PrimaryVertexProducer_WeightedMeanFitter_h 22 double ox = iclus.
vx();
23 double oy = iclus.
vy();
24 double oz = iclus.
vz();
26 double vx = iclus.
px();
27 double vy = iclus.
py();
28 double vz = iclus.
pz();
30 double opx =
vertex.x() - ox;
31 double opy =
vertex.y() - oy;
32 double opz =
vertex.z() - oz;
35 double t = (
vx * opx +
vy * opy +
vz * opz) / (vnorm2);
38 return std::pair<GlobalPoint, double>(
44 std::vector<reco::TransientTrack> iclus) {
45 float x = 0., y = 0., z = 0.;
46 float s_wx = 0., s_wz = 0.;
47 float s2_wx = 0., s2_wz = 0.;
48 float wx = 0., wz = 0.,
chi2 = 0.;
55 for (
const auto&
p : points) {
60 x +=
p.first.x() * wx;
61 y +=
p.first.y() * wx;
62 z +=
p.first.z() * wz;
68 if (s_wx == 0. || s_wz == 0.) {
69 edm::LogWarning(
"WeightedMeanFitter") <<
"Vertex fitting failed at beginning\n";
77 float old_x, old_y, old_z;
87 while ((niter++) < 2) {
100 for (
unsigned int i = 0;
i < (
unsigned int)points.size();
i++) {
118 x += wx *
p.first.x();
119 y += wx *
p.first.y();
120 z += wz *
p.first.z();
129 if (s_wx == 0. || s_wz == 0.) {
131 <<
"Vertex fitting failed, either all tracks are outliers or they have a very large error\n";
152 for (
const auto&
p : points) {
165 ndof_x > 1 ? (2 * ndof_x - 3) : 0.00001;
171 const std::vector<std::pair<GlobalPoint, GlobalPoint>>& points,
172 std::vector<reco::TransientTrack> iclus,
174 float x = 0., y = 0., z = 0.;
175 float s_wx = 0., s_wz = 0.;
176 float s2_wx = 0., s2_wz = 0.;
177 float wx = 0., wz = 0.,
chi2 = 0.;
178 float wy = 0., s_wy = 0., s2_wy = 0.;
189 for (
const auto&
p : points) {
195 x +=
p.first.x() * wx;
196 y +=
p.first.y() * wy;
197 z +=
p.first.z() * wz;
204 if (s_wx == 0. || s_wy == 0. || s_wz == 0.) {
205 edm::LogWarning(
"WeightedMeanFitter") <<
"Vertex fitting failed at beginning\n";
219 float old_x, old_y, old_z;
230 while ((niter++) < 2) {
247 for (
unsigned int i = 0;
i < (
unsigned int)points.size();
i++) {
267 x += wx *
p.first.x();
268 y += wy *
p.first.y();
269 z += wz *
p.first.z();
280 if (s_wx == 0. || s_wy == 0. || s_wz == 0.) {
282 <<
"Vertex fitting failed, either all tracks are outliers or they have a very large error\n";
312 for (
const auto&
p : points) {
329 const std::vector<std::pair<GlobalPoint, GlobalPoint>>& points,
330 std::vector<std::vector<reco::TransientTrack>>::const_iterator iclus) {
331 float x = 0, y = 0, z = 0, s_wx = 0, s_wy = 0, s_wz = 0, wx = 0, wy = 0, wz = 0,
chi2 = 0;
335 err(0, 0) =
err(1, 1) =
err(2, 2) / 100.;
337 for (
const auto&
p : points) {
344 x +=
p.first.x() * wx;
345 y +=
p.first.y() * wx;
346 z +=
p.first.z() * wz;
352 if (s_wx == 0. || s_wz == 0.) {
353 edm::LogWarning(
"WeightedMeanFitter") <<
"Vertex fitting failed at beginning\n";
361 float old_x, old_y, old_z;
368 float s_err_x = 0., s_err_y = 0., s_err_z = 0.;
383 for (
const auto&
p : points) {
387 wy = wx * wx +
err_y;
388 wx = wx * wx +
err_x;
392 wz = wz * wz +
err_z;
394 xpull =
std::pow((
p.first.x() - old_x), 2) / wx;
395 xpull +=
std::pow((
p.first.y() - old_y), 2) / wy;
396 xpull +=
std::pow((
p.first.z() - old_z), 2) / wz;
408 x += wx *
p.first.x();
409 y += wy *
p.first.y();
410 z += wz *
p.first.z();
416 s_err_x += wx *
pow(
p.first.x() - old_x, 2);
417 s_err_y += wy *
pow(
p.first.y() - old_y, 2);
418 s_err_z += wz *
pow(
p.first.z() - old_z, 2);
420 if (s_wx == 0. || s_wy == 0. || s_wz == 0.) {
422 <<
"Vertex fitting failed, either all tracks are outliers or they have a very large error\n";
429 err_x = s_err_x / s_wx;
430 err_y = s_err_y / s_wy;
431 err_z = s_err_z / s_wz;
443 for (
const auto&
p : points) {
469 std::vector<TransientVertex>
fit(
const std::vector<reco::TransientTrack>&
dummy,
470 const std::vector<TransientVertex>&
clusters,
473 std::vector<TransientVertex>
pvs;
474 std::vector<TransientVertex>
seed(1);
477 if (cluster.originalTracks().size() > 1) {
478 std::vector<reco::TransientTrack> tracklist = cluster.originalTracks();
480 std::vector<std::pair<GlobalPoint, GlobalPoint>> points;
482 for (
const auto& itrack : tracklist) {
483 GlobalPoint p = itrack.stateAtBeamLine().trackStateAtPCA().position();
484 GlobalPoint err(itrack.stateAtBeamLine().transverseImpactParameter().error(),
485 itrack.stateAtBeamLine().transverseImpactParameter().error(),
486 itrack.track().dzError());
487 std::pair<GlobalPoint, GlobalPoint>
p2(
p,
err);
488 points.push_back(
p2);
492 if (!
v.hasTrackWeight()) {
495 for (
const auto& trk :
v.originalTracks()) {
496 trkWeightMap[trk] = 1.;
498 v.weightMap(trkWeightMap);
503 for (
const auto& itrack : tracklist) {
504 GlobalPoint p = itrack.impactPointState().globalPosition();
505 GlobalPoint err(itrack.track().dxyError(), itrack.track().dxyError(), itrack.track().dzError());
506 std::pair<GlobalPoint, GlobalPoint>
p2(
p,
err);
507 points.push_back(
p2);
511 if (!
v.hasTrackWeight()) {
514 for (
const auto& trk :
v.originalTracks()) {
515 trkWeightMap[trk] = 1.;
517 v.weightMap(trkWeightMap);
double vx() const
x coordinate of the reference point on track
double px() const
x coordinate of momentum vector
constexpr float corr_x_bs
std::map< reco::TransientTrack, float > TransientTrackToFloatMap
Global3DPoint GlobalPoint
double py() const
y coordinate of momentum vector
WeightedMeanPrimaryVertexEstimator()=default
std::vector< TransientVertex > fit(const std::vector< reco::TransientTrack > &dummy, const std::vector< TransientVertex > &clusters, const reco::BeamSpot &beamSpot, const bool useBeamConstraint) override
U second(std::pair< T, U > const &p)
TransientVertex weightedMeanOutlierRejectionVarianceAsError(const std::vector< std::pair< GlobalPoint, GlobalPoint >> &points, std::vector< std::vector< reco::TransientTrack >>::const_iterator iclus)
double vz() const
z coordinate of the reference point on track
constexpr float precision
TransientVertex weightedMeanOutlierRejectionBeamSpot(const std::vector< std::pair< GlobalPoint, GlobalPoint >> &points, std::vector< reco::TransientTrack > iclus, const reco::BeamSpot &beamSpot)
Abs< T >::type abs(const T &t)
constexpr int maxIterations
double pz() const
z coordinate of momentum vector
std::pair< GlobalPoint, double > nearestPoint(const GlobalPoint &vertex, reco::Track iclus)
double vy() const
y coordinate of the reference point on track
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
Log< level::Warning, false > LogWarning
~WeightedMeanPrimaryVertexEstimator() override=default
Power< A, B >::type pow(const A &a, const B &b)
TransientVertex weightedMeanOutlierRejection(const std::vector< std::pair< GlobalPoint, GlobalPoint >> &points, std::vector< reco::TransientTrack > iclus)
constexpr float startError