CMS 3D CMS Logo

DivisiveVertexFinder.cc
Go to the documentation of this file.
7 #include <utility>
8 #include <vector>
9 #include <map>
10 #include <algorithm>
11 #include <cmath>
12 
14  double track_pt_max,
15  double track_chi2_max,
16  double track_prob_min,
17  double zOffset,
18  int ntrkMin,
19  bool useError,
20  double zSeparation,
21  bool wtAverage,
22  int verbosity)
23  : zOffset_(zOffset),
24  zSeparation_(zSeparation),
25  ntrkMin_(ntrkMin),
26  useError_(useError),
27  wtAverage_(wtAverage),
28  divmeth_(zOffset, ntrkMin, useError, zSeparation, wtAverage),
29  verbose_(verbosity) {
31 }
32 
34 
36  reco::VertexCollection &vertexes) { // output
38  Measurement1D vz;
39  if (wtAverage_) {
40  vz = pos.wtAverage(trks);
41  } else {
42  vz = pos.average(trks);
43  }
45  err(2, 2) = vz.error() * vz.error();
46 
47  reco::Vertex v(reco::Vertex::Point(0, 0, vz.value()), err, 0, 1, trks.size());
48  for (unsigned int i = 0; i < trks.size(); i++) {
49  double vz = trks[i]->vz();
50  if (edm::isNotFinite(vz))
51  continue;
52  v.add(reco::TrackBaseRef(trks[i]));
53  }
54 
55  vertexes.push_back(v);
56 
57  return true;
58 }
59 
62  const math::XYZPoint &bs) { // output
63  std::vector<PVCluster> in;
64  std::pair<std::vector<PVCluster>, std::vector<const reco::Track *> > out;
65 
66  // Convert input track collection into container needed by Wolfgang's templated code
67  // Need to save a map to reconvert from bare pointers, oy vey
68  std::map<const reco::Track *, reco::TrackRef> mapa;
69  // std::vector< std::vector< const reco::Track* > > trkps;
70  for (unsigned int i = 0; i < trks.size(); ++i) {
71  double vz = trks[i]->vz();
72  if (edm::isNotFinite(vz))
73  continue;
74  std::vector<const reco::Track *> temp;
75  temp.clear();
76  temp.push_back(&(*trks[i]));
77 
78  in.push_back(PVCluster(Measurement1D(trks[i]->dz(bs), trks[i]->dzError()), temp));
79  mapa[temp[0]] = trks[i];
80  }
81 
82  if (verbose_ > 0) {
83  edm::LogInfo("DivisiveVertexFinder") << "size of input vector of clusters " << in.size();
84  for (unsigned int i = 0; i < in.size(); ++i) {
85  edm::LogInfo("DivisiveVertexFinder")
86  << "Track " << i << " addr " << in[i].tracks()[0] << " dz " << in[i].tracks()[0]->dz(bs) << " +- "
87  << in[i].tracks()[0]->dzError() << " prodID " << mapa[in[i].tracks()[0]].id() << " dz from RefTrack "
88  << mapa[in[i].tracks()[0]]->dz(bs) << " +- " << mapa[in[i].tracks()[0]]->dzError();
89  }
90  }
91 
92  // Run the darn thing
94  out = divmeth_(in);
95 
96  if (verbose_ > 0)
97  edm::LogInfo("DivisiveVertexFinder") << " DivisiveClusterizer1D found " << out.first.size() << " vertexes";
98 
99  // Now convert the output yet again into something we can safely store in the event
100  for (unsigned int iv = 0; iv < out.first.size(); ++iv) { // loop over output vertexes
102  err(2, 2) = out.first[iv].position().error() * out.first[iv].position().error();
103 
104  reco::Vertex v(reco::Vertex::Point(0, 0, out.first[iv].position().value()), err, 0, 1, out.second.size());
105  if (verbose_ > 0)
106  edm::LogInfo("DivisiveVertexFinder")
107  << " DivisiveClusterizer1D vertex " << iv << " has " << out.first[iv].tracks().size()
108  << " tracks and a position of " << v.z() << " +- " << std::sqrt(v.covariance(2, 2));
109  for (unsigned int itrk = 0; itrk < out.first[iv].tracks().size(); ++itrk) {
110  v.add(reco::TrackBaseRef(mapa[out.first[iv].tracks()[itrk]]));
111  }
112  vertexes.push_back(v); // Done with horrible conversion, save it
113  }
114 
115  // Finally, sort the vertexes in decreasing sumPtSquared
116  // std::sort(vertexes.begin(), vertexes.end(), PVClusterComparer());
117  std::sort(vertexes.begin(), vertexes.end(), *pvComparer_);
118 
119  return true;
120 }
int32_t *__restrict__ iv
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
bool findVertexesAlt(const reco::TrackRefVector &trks, reco::VertexCollection &vertexes, const math::XYZPoint &bs)
PVClusterComparer * pvComparer_
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
T sqrt(T t)
Definition: SSEVec.h:19
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
bool findVertexes(const reco::TrackRefVector &trks, reco::VertexCollection &vertexes)
Run the divisive algorithm and return a vector of vertexes for the input track collection.
Log< level::Info, false > LogInfo
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
DivisiveVertexFinder(double track_pt_min, double track_pt_max, double track_chi2_max, double track_prob_min, double zOffset=5.0, int ntrkMin=5, bool useError=true, double zSeparation=0.05, bool wtAverage=true, int verbosity=0)
void setBeamSpot(const math::XYZPoint &bs)
double value() const
Definition: Measurement1D.h:25
double error() const
Definition: Measurement1D.h:27
Cluster1D< reco::Track > PVCluster
Definition: PVCluster.h:14
pixeltemp::DivisiveClusterizer1D< reco::Track > divmeth_
We use Wolfgang&#39;s templated class that implements the actual divisive method.