CMS 3D CMS Logo

PFPileUpAlgo.cc
Go to the documentation of this file.
4 
7 
8  pfCandidatesFromVtx_.clear();
9  pfCandidatesFromPU_.clear();
10 
11  for( unsigned i=0; i<pfCandidates.size(); i++ ) {
12 
13  const reco::PFCandidate& cand = * ( pfCandidates[i] );
14 
15  int ivertex;
16 
17  switch( cand.particleId() ) {
19  ivertex = chargedHadronVertex( vertices, cand );
20  break;
21  default:
22  continue;
23  }
24 
25  // no associated vertex, or primary vertex
26  // not pile-up
27  if( ivertex == -1 ||
28  ivertex == 0 ) {
29  if(verbose_)
30  std::cout<<"VTX "<<i<<" "<< *(pfCandidates[i])<<std::endl;
31  pfCandidatesFromVtx_.push_back( pfCandidates[i] );
32  } else {
33  if(verbose_)
34  std::cout<<"PU "<<i<<" "<< *(pfCandidates[i])<<std::endl;
35  // associated to a vertex
36  pfCandidatesFromPU_.push_back( pfCandidates[i] );
37  }
38  }
39 }
40 
41 
42 int
44 
45  auto const & track = pfcand.trackRef();
46  size_t iVertex = 0;
47  unsigned int index=0;
48  unsigned int nFoundVertex = 0;
49  float bestweight=0;
50  for( auto const & vtx : vertices) {
51  float w = vtx.trackWeight(track);
52  //select the vertex for which the track has the highest weight
53  if (w > bestweight){
54  bestweight=w;
55  iVertex=index;
56  nFoundVertex++;
57  }
58  ++index;
59  }
60 
61  if (nFoundVertex>0){
62  if (nFoundVertex!=1)
63  edm::LogWarning("TrackOnTwoVertex")<<"a track is shared by at least two verteces. Used to be an assert";
64  return iVertex;
65  }
66  // no vertex found with this track.
67 
68  // optional: as a secondary solution, associate the closest vertex in z
69  if ( checkClosestZVertex_ ) {
70 
71  double dzmin = 10000;
72  double ztrack = pfcand.vertex().z();
73  bool foundVertex = false;
74  index = 0;
75  for(auto iv=vertices.begin(); iv!=vertices.end(); ++iv, ++index) {
76 
77  double dz = fabs(ztrack - iv->z());
78  if(dz<dzmin) {
79  dzmin = dz;
80  iVertex = index;
81  foundVertex = true;
82  }
83  }
84 
85  if( foundVertex )
86  return iVertex;
87 
88  }
89 
90 
91  return -1 ;
92 }
93 
const double w
Definition: UKUtility.cc:23
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
const Point & vertex() const override
vertex position (overwritten by PF...)
Definition: PFCandidate.cc:656
PFCollection pfCandidatesFromVtx_
Definition: PFPileUpAlgo.h:50
bool verbose_
verbose ?
Definition: PFPileUpAlgo.h:48
PFCollection pfCandidatesFromPU_
Definition: PFPileUpAlgo.h:51
int chargedHadronVertex(const reco::VertexCollection &vertices, const reco::PFCandidate &pfcand) const
Definition: PFPileUpAlgo.cc:43
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUpAlgo.h:44
std::vector< edm::FwdPtr< reco::PFCandidate > > PFCollection
Definition: PFPileUpAlgo.h:16
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
void process(const PFCollection &pfCandidates, const reco::VertexCollection &vertices)
Definition: PFPileUpAlgo.cc:5
virtual ParticleType particleId() const
Definition: PFCandidate.h:374