CMS 3D CMS Logo

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