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.
7 #include <utility>
8 #include <vector>
9 #include <map>
10 #include <algorithm>
11 #include <cmath>
12 
13 DivisiveVertexFinder::DivisiveVertexFinder(double zOffset, int ntrkMin,
14  bool useError, double zSeparation, bool wtAverage,
15  int verbosity)
16  : zOffset_(zOffset), zSeparation_(zSeparation), ntrkMin_(ntrkMin), useError_(useError),
17  wtAverage_(wtAverage),
18  divmeth_(zOffset, ntrkMin, useError, zSeparation, wtAverage),
19  verbose_(verbosity)
20 {
21 
22 }
23 
25 
27  reco::VertexCollection &vertexes){ // output
29  Measurement1D vz;
30  if (wtAverage_) {
31  vz = pos.wtAverage(trks);
32  }
33  else {
34  vz = pos.average(trks);
35  }
37  err(2,2) = vz.error()*vz.error();
38 
39  reco::Vertex v( reco::Vertex::Point(0,0,vz.value()), err, 0, 1, trks.size() );
40  for (unsigned int i=0; i<trks.size(); i++) {
41  double vz = trks[i]->vz();
42  if(std::isnan(vz)) continue;
43  v.add(reco::TrackBaseRef(trks[i]));
44  }
45 
46  vertexes.push_back(v);
47 
48  return true;
49 }
50 
52  reco::VertexCollection &vertexes, const math::XYZPoint & bs){ // output
53  std::vector< PVCluster > in;
54  std::pair< std::vector< PVCluster >, std::vector< const reco::Track* > > out;
55 
56  // Convert input track collection into container needed by Wolfgang's templated code
57  // Need to save a map to reconvert from bare pointers, oy vey
58  std::map< const reco::Track*, reco::TrackRef > mapa;
59  // std::vector< std::vector< const reco::Track* > > trkps;
60  for (unsigned int i=0; i<trks.size(); ++i) {
61  double vz = trks[i]->vz();
62  if(std::isnan(vz)) continue;
63  std::vector< const reco::Track* > temp;
64  temp.clear();
65  temp.push_back( &(*trks[i]) );
66 
67  in.push_back( PVCluster( Measurement1D(trks[i]->dz(bs), trks[i]->dzError() ), temp ) );
68  mapa[temp[0]] = trks[i];
69  }
70 
71  if (verbose_ > 0 ) {
72  edm::LogInfo("DivisiveVertexFinder") << "size of input vector of clusters " << in.size();
73  for (unsigned int i=0; i<in.size(); ++i) {
74  edm::LogInfo("DivisiveVertexFinder") << "Track " << i << " addr " << in[i].tracks()[0]
75  << " dz " << in[i].tracks()[0]->dz(bs)
76  << " +- " << in[i].tracks()[0]->dzError()
77  << " prodID " << mapa[in[i].tracks()[0]].id()
78  << " dz from RefTrack " << mapa[in[i].tracks()[0]]->dz(bs)
79  << " +- " << mapa[in[i].tracks()[0]]->dzError();
80  }
81  }
82 
83  // Run the darn thing
85  out = divmeth_(in);
86 
87  if (verbose_ > 0) edm::LogInfo("DivisiveVertexFinder") << " DivisiveClusterizer1D found "
88  << out.first.size() << " vertexes";
89 
90  // Now convert the output yet again into something we can safely store in the event
91  for (unsigned int iv=0; iv<out.first.size(); ++iv) { // loop over output vertexes
93  err(2,2) = out.first[iv].position().error()*out.first[iv].position().error();
94 
95  reco::Vertex v( reco::Vertex::Point(0,0,out.first[iv].position().value()), err, 0, 1, out.second.size() );
96  if (verbose_ > 0 ) edm::LogInfo("DivisiveVertexFinder") << " DivisiveClusterizer1D vertex " << iv
97  << " has " << out.first[iv].tracks().size()
98  << " tracks and a position of " << v.z()
99  << " +- " << std::sqrt(v.covariance(2,2));
100  for (unsigned int itrk=0; itrk<out.first[iv].tracks().size(); ++itrk) {
101  v.add( reco::TrackBaseRef(mapa[out.first[iv].tracks()[itrk]] ) );
102  }
103  vertexes.push_back(v); // Done with horrible conversion, save it
104  }
105 
106  // Finally, sort the vertexes in decreasing sumPtSquared
107  std::sort(vertexes.begin(), vertexes.end(), PVClusterComparer());
108 
109  return true;
110 }
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:44
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool isnan(float x)
Definition: math.h:13
T sqrt(T t)
Definition: SSEVec.h:46
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.
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:13
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:16
mathSSE::Vec4< T > v
Measurement1D wtAverage(const reco::TrackRefVector &trks) const
Calculate Error-Weighted average of Z of tracks from const collection of track pointers.