File indexing completed on 2024-04-06 12:04:52
0001 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedVertexSeed.h"
0002
0003 #include "DataFormats/TrackReco/interface/Track.h"
0004 #include "DataFormats/Math/interface/Point3D.h"
0005
0006 using namespace std;
0007 using namespace reco;
0008
0009 PFDisplacedVertexSeed::PFDisplacedVertexSeed() : seedPoint_(GlobalPoint(0, 0, 0)), totalWeight_(0) {}
0010
0011 void PFDisplacedVertexSeed::addElement(TrackBaseRef element) {
0012 if (std::find(elements_.begin(), elements_.end(), element) == elements_.end()) {
0013 elements_.emplace_back(std::move(element));
0014 }
0015 }
0016
0017 void PFDisplacedVertexSeed::reserveElements(size_t newSize) { elements_.reserve(newSize); }
0018
0019 void PFDisplacedVertexSeed::updateSeedPoint(const GlobalPoint& dcaPoint,
0020 TrackBaseRef r1,
0021 TrackBaseRef r2,
0022 double weight) {
0023 if (isEmpty()) {
0024 seedPoint_ = dcaPoint;
0025 totalWeight_ = weight;
0026 } else {
0027 Basic3DVector<double> vertexSeedVector(seedPoint_);
0028 Basic3DVector<double> dcaVector(dcaPoint);
0029
0030 dcaVector = (dcaVector * weight + vertexSeedVector * totalWeight_) / (totalWeight_ + weight);
0031 GlobalPoint P(dcaVector.x(), dcaVector.y(), dcaVector.z());
0032 totalWeight_ += weight;
0033 seedPoint_ = P;
0034 }
0035
0036 reserveElements(elements_.size() + 2);
0037 addElement(r1);
0038 addElement(r2);
0039 }
0040
0041 void PFDisplacedVertexSeed::mergeWith(const PFDisplacedVertexSeed& displacedVertex) {
0042 double weight = displacedVertex.totalWeight();
0043 const GlobalPoint& dcaPoint = displacedVertex.seedPoint();
0044
0045 Basic3DVector<double> vertexSeedVector(seedPoint_);
0046 Basic3DVector<double> dcaVector(dcaPoint);
0047
0048 dcaVector = (dcaVector * weight + vertexSeedVector * totalWeight_) / (totalWeight_ + weight);
0049 GlobalPoint P(dcaVector.x(), dcaVector.y(), dcaVector.z());
0050 totalWeight_ += weight;
0051 seedPoint_ = P;
0052
0053 reserveElements(elements_.size() + displacedVertex.elements().size());
0054 auto const oldSize = elements_.size();
0055
0056 for (auto const& e : displacedVertex.elements()) {
0057 if (std::find(elements_.begin(), elements_.begin() + oldSize, e) == elements_.begin() + oldSize) {
0058 elements_.emplace_back(e);
0059 }
0060 }
0061 }
0062
0063 void PFDisplacedVertexSeed::Dump(ostream& out) const {
0064 if (!out)
0065 return;
0066
0067 out << "\t--- DisplacedVertexSeed --- " << endl;
0068 out << "\tnumber of elements: " << elements_.size() << endl;
0069
0070 out << "\t Seed Point x = " << seedPoint().x() << "\t Seed Point y = " << seedPoint().y()
0071 << "\t Seed Point z = " << seedPoint().z() << endl;
0072
0073
0074
0075 for (auto const& ie : elements_) {
0076 math::XYZPoint Pi(ie.get()->innerPosition());
0077 math::XYZPoint Po(ie.get()->outerPosition());
0078
0079 float innermost_radius = sqrt(Pi.x() * Pi.x() + Pi.y() * Pi.y() + Pi.z() * Pi.z());
0080 float outermost_radius = sqrt(Po.x() * Po.x() + Po.y() * Po.y() + Po.z() * Po.z());
0081 float innermost_rho = sqrt(Pi.x() * Pi.x() + Pi.y() * Pi.y());
0082 float outermost_rho = sqrt(Po.x() * Po.x() + Po.y() * Po.y());
0083
0084 double pt = ie->pt();
0085
0086 out << "ie = " << ie.key() << " pt = " << pt << " innermost hit radius = " << innermost_radius
0087 << " rho = " << innermost_rho << " outermost hit radius = " << outermost_radius << " rho = " << outermost_rho
0088 << endl;
0089
0090 out << "ie = " << ie.key() << " pt = "
0091 << pt
0092
0093 << " out hit pos x = " << Po.x() << " y = " << Po.y() << " z = " << Po.z() << endl;
0094 }
0095
0096 out << endl;
0097 }