CMS 3D CMS Logo

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;
29  } else {
30  if (verbose_)
31  std::cout << "PU " << i << " " << *(pfCandidates[i]) << std::endl;
32  // associated to a vertex
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 }
zmumugammaAnalyzer_cfi.pfCandidates
pfCandidates
Definition: zmumugammaAnalyzer_cfi.py:11
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
MessageLogger.h
PFCandidate.h
gpuVertexFinder::iv
int32_t *__restrict__ iv
Definition: gpuClusterTracksDBSCAN.h:42
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
gather_cfg.cout
cout
Definition: gather_cfg.py:144
reco::PFCandidate::h
Definition: PFCandidate.h:46
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
PFPileUpAlgo::process
void process(const PFCollection &pfCandidates, const reco::VertexCollection &vertices)
Definition: PFPileUpAlgo.cc:6
pfDeepBoostedJetPreprocessParams_cfi.pfcand
pfcand
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:8
w
const double w
Definition: UKUtility.cc:23
Vertex.h
cand
Definition: decayParser.h:32
PFPileUpAlgo.h
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
PVValHelper::dz
Definition: PVValidationHelpers.h:51
PFPileUpAlgo::pfCandidatesFromPU_
PFCollection pfCandidatesFromPU_
Definition: PFPileUpAlgo.h:46
PFPileUpAlgo::pfCandidatesFromVtx_
PFCollection pfCandidatesFromVtx_
Definition: PFPileUpAlgo.h:45
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
PFPileUpAlgo::chargedHadronVertex
int chargedHadronVertex(const reco::VertexCollection &vertices, const reco::PFCandidate &pfcand) const
Definition: PFPileUpAlgo.cc:38
PFPileUpAlgo::verbose_
bool verbose_
verbose ?
Definition: PFPileUpAlgo.h:43
PFPileUpAlgo::checkClosestZVertex_
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUpAlgo.h:40
PFPileUpAlgo::PFCollection
std::vector< edm::FwdPtr< reco::PFCandidate > > PFCollection
Definition: PFPileUpAlgo.h:14
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7