CMS 3D CMS Logo

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