CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
PFPileUpAlgo Class Reference

#include <PFPileUpAlgo.h>

Public Types

typedef std::vector< edm::FwdPtr< reco::PFCandidate > > PFCollection
 

Public Member Functions

int chargedHadronVertex (const reco::VertexCollection &vertices, const reco::PFCandidate &pfcand) const
 
const PFCollectiongetPFCandidatesFromPU () const
 
const PFCollectiongetPFCandidatesFromVtx () const
 
 PFPileUpAlgo ()
 
 PFPileUpAlgo (bool checkClosestZVertex, bool verbose=false)
 
void process (const PFCollection &pfCandidates, const reco::VertexCollection &vertices)
 
void setCheckClosestZVertex (bool val)
 
void setVerbose (bool verbose)
 
 ~PFPileUpAlgo ()
 

Private Attributes

bool checkClosestZVertex_
 use the closest z vertex if a track is not in a vertex More...
 
PFCollection pfCandidatesFromPU_
 
PFCollection pfCandidatesFromVtx_
 
bool verbose_
 verbose ? More...
 

Detailed Description

Definition at line 12 of file PFPileUpAlgo.h.

Member Typedef Documentation

◆ PFCollection

Definition at line 14 of file PFPileUpAlgo.h.

Constructor & Destructor Documentation

◆ PFPileUpAlgo() [1/2]

PFPileUpAlgo::PFPileUpAlgo ( )
inline

Definition at line 16 of file PFPileUpAlgo.h.

16 : checkClosestZVertex_(true), verbose_(false) { ; }

◆ PFPileUpAlgo() [2/2]

PFPileUpAlgo::PFPileUpAlgo ( bool  checkClosestZVertex,
bool  verbose = false 
)
inline

Definition at line 18 of file PFPileUpAlgo.h.

◆ ~PFPileUpAlgo()

PFPileUpAlgo::~PFPileUpAlgo ( )
inline

Definition at line 23 of file PFPileUpAlgo.h.

23 { ; }

Member Function Documentation

◆ chargedHadronVertex()

int PFPileUpAlgo::chargedHadronVertex ( const reco::VertexCollection vertices,
const reco::PFCandidate pfcand 
) const

Definition at line 37 of file PFPileUpAlgo.cc.

37  {
38  auto const& track = pfcand.trackRef();
39  size_t iVertex = 0;
40  unsigned int index = 0;
41  unsigned int nFoundVertex = 0;
42  float bestweight = 0;
43  for (auto const& vtx : vertices) {
44  float w = vtx.trackWeight(track);
45  //select the vertex for which the track has the highest weight
46  if (w > bestweight) {
47  bestweight = w;
48  iVertex = index;
49  nFoundVertex++;
50  }
51  ++index;
52  }
53 
54  if (nFoundVertex > 0) {
55  if (nFoundVertex != 1)
56  edm::LogWarning("TrackOnTwoVertex") << "a track is shared by at least two verteces. Used to be an assert";
57  return iVertex;
58  }
59  // no vertex found with this track.
60 
61  // optional: as a secondary solution, associate the closest vertex in z
63  double dzmin = 10000;
64  double ztrack = pfcand.vertex().z();
65  bool foundVertex = false;
66  index = 0;
67  for (auto iv = vertices.begin(); iv != vertices.end(); ++iv, ++index) {
68  double dz = fabs(ztrack - iv->z());
69  if (dz < dzmin) {
70  dzmin = dz;
71  iVertex = index;
72  foundVertex = true;
73  }
74  }
75 
76  if (foundVertex)
77  return iVertex;
78  }
79 
80  return -1;
81 }

References checkClosestZVertex_, PVValHelper::dz, pfDeepBoostedJetPreprocessParams_cfi::pfcand, HLT_FULL_cff::track, pwdgSkimBPark_cfi::vertices, extraflags_cff::vtx, and w.

Referenced by process().

◆ getPFCandidatesFromPU()

const PFCollection& PFPileUpAlgo::getPFCandidatesFromPU ( ) const
inline

Definition at line 32 of file PFPileUpAlgo.h.

32 { return pfCandidatesFromPU_; }

References pfCandidatesFromPU_.

◆ getPFCandidatesFromVtx()

const PFCollection& PFPileUpAlgo::getPFCandidatesFromVtx ( ) const
inline

Definition at line 34 of file PFPileUpAlgo.h.

34 { return pfCandidatesFromVtx_; }

References pfCandidatesFromVtx_.

◆ process()

void PFPileUpAlgo::process ( const PFCollection pfCandidates,
const reco::VertexCollection vertices 
)

Definition at line 5 of file PFPileUpAlgo.cc.

5  {
6  pfCandidatesFromVtx_.clear();
7  pfCandidatesFromPU_.clear();
8 
9  for (unsigned i = 0; i < pfCandidates.size(); i++) {
10  const reco::PFCandidate& cand = *(pfCandidates[i]);
11 
12  int ivertex;
13 
14  switch (cand.particleId()) {
16  ivertex = chargedHadronVertex(vertices, cand);
17  break;
18  default:
19  continue;
20  }
21 
22  // no associated vertex, or primary vertex
23  // not pile-up
24  if (ivertex == -1 || ivertex == 0) {
25  if (verbose_)
26  std::cout << "VTX " << i << " " << *(pfCandidates[i]) << std::endl;
28  } else {
29  if (verbose_)
30  std::cout << "PU " << i << " " << *(pfCandidates[i]) << std::endl;
31  // associated to a vertex
33  }
34  }
35 }

References chargedHadronVertex(), gather_cfg::cout, reco::PFCandidate::h, mps_fire::i, zmumugammaAnalyzer_cfi::pfCandidates, pfCandidatesFromPU_, pfCandidatesFromVtx_, verbose_, and pwdgSkimBPark_cfi::vertices.

◆ setCheckClosestZVertex()

void PFPileUpAlgo::setCheckClosestZVertex ( bool  val)
inline

Definition at line 30 of file PFPileUpAlgo.h.

References checkClosestZVertex_, and heppy_batch::val.

◆ setVerbose()

void PFPileUpAlgo::setVerbose ( bool  verbose)
inline

Definition at line 28 of file PFPileUpAlgo.h.

28 { verbose_ = verbose; }

References verbose, and verbose_.

Member Data Documentation

◆ checkClosestZVertex_

bool PFPileUpAlgo::checkClosestZVertex_
private

use the closest z vertex if a track is not in a vertex

Definition at line 40 of file PFPileUpAlgo.h.

Referenced by chargedHadronVertex(), and setCheckClosestZVertex().

◆ pfCandidatesFromPU_

PFCollection PFPileUpAlgo::pfCandidatesFromPU_
private

Definition at line 46 of file PFPileUpAlgo.h.

Referenced by getPFCandidatesFromPU(), and process().

◆ pfCandidatesFromVtx_

PFCollection PFPileUpAlgo::pfCandidatesFromVtx_
private

Definition at line 45 of file PFPileUpAlgo.h.

Referenced by getPFCandidatesFromVtx(), and process().

◆ verbose_

bool PFPileUpAlgo::verbose_
private

verbose ?

Definition at line 43 of file PFPileUpAlgo.h.

Referenced by process(), and setVerbose().

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
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
pfDeepBoostedJetPreprocessParams_cfi.pfcand
pfcand
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:8
w
const double w
Definition: UKUtility.cc:23
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
cand
Definition: decayParser.h:32
heppy_batch.val
val
Definition: heppy_batch.py:351
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
PVValHelper::dz
Definition: PVValidationHelpers.h:50
PFPileUpAlgo::pfCandidatesFromPU_
PFCollection pfCandidatesFromPU_
Definition: PFPileUpAlgo.h:46
pfIsolationCalculator_cfi.checkClosestZVertex
checkClosestZVertex
Definition: pfIsolationCalculator_cfi.py:20
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:37
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
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7