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 setDzCutForChargedFromPUVtxs (double val)
 
void setNumOfPUVtxsForCharged (unsigned int val)
 
void setVerbose (bool verbose)
 
 ~PFPileUpAlgo ()
 

Private Attributes

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

Detailed Description

Definition at line 11 of file PFPileUpAlgo.h.

Member Typedef Documentation

◆ PFCollection

Definition at line 13 of file PFPileUpAlgo.h.

Constructor & Destructor Documentation

◆ PFPileUpAlgo() [1/2]

PFPileUpAlgo::PFPileUpAlgo ( )
inline

Definition at line 15 of file PFPileUpAlgo.h.

15 : checkClosestZVertex_(true), verbose_(false) { ; }
bool verbose_
verbose ?
Definition: PFPileUpAlgo.h:46
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUpAlgo.h:41

◆ PFPileUpAlgo() [2/2]

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

Definition at line 17 of file PFPileUpAlgo.h.

19  ;
20  }
bool verbose
bool verbose_
verbose ?
Definition: PFPileUpAlgo.h:46
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUpAlgo.h:41

◆ ~PFPileUpAlgo()

PFPileUpAlgo::~PFPileUpAlgo ( )
inline

Definition at line 22 of file PFPileUpAlgo.h.

22 { ; }

Member Function Documentation

◆ chargedHadronVertex()

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

Definition at line 40 of file PFPileUpAlgo.cc.

References checkClosestZVertex_, PVValHelper::dz, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::iv, pfDeepBoostedJetPreprocessParams_cfi::pfcand, HLT_2024v14_cff::track, AlignmentTracksFromVertexSelector_cfi::vertices, L1BJetProducer_cff::vtx, and w().

Referenced by process().

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

◆ getPFCandidatesFromPU()

const PFCollection& PFPileUpAlgo::getPFCandidatesFromPU ( ) const
inline

Definition at line 33 of file PFPileUpAlgo.h.

References pfCandidatesFromPU_.

33 { return pfCandidatesFromPU_; }
PFCollection pfCandidatesFromPU_
Definition: PFPileUpAlgo.h:49

◆ getPFCandidatesFromVtx()

const PFCollection& PFPileUpAlgo::getPFCandidatesFromVtx ( ) const
inline

Definition at line 35 of file PFPileUpAlgo.h.

References pfCandidatesFromVtx_.

35 { return pfCandidatesFromVtx_; }
PFCollection pfCandidatesFromVtx_
Definition: PFPileUpAlgo.h:48

◆ process()

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

Definition at line 6 of file PFPileUpAlgo.cc.

References funct::abs(), chargedHadronVertex(), gather_cfg::cout, fDzCutForChargedFromPUVtxs_, fNumOfPUVtxsForCharged_, reco::PFCandidate::h, mps_fire::i, createfilelist::int, zmumugammaAnalyzer_cfi::pfCandidates, pfCandidatesFromPU_, pfCandidatesFromVtx_, verbose_, and AlignmentTracksFromVertexSelector_cfi::vertices.

6  {
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  (fNumOfPUVtxsForCharged_ > 0 && !vertices.empty() && ivertex <= int(fNumOfPUVtxsForCharged_) &&
27  std::abs(cand.vertex().z() - vertices[0].z()) < fDzCutForChargedFromPUVtxs_))) {
28  if (verbose_)
29  std::cout << "VTX " << i << " " << *(pfCandidates[i]) << std::endl;
31  } else {
32  if (verbose_)
33  std::cout << "PU " << i << " " << *(pfCandidates[i]) << std::endl;
34  // associated to a vertex
36  }
37  }
38 }
double fDzCutForChargedFromPUVtxs_
Definition: PFPileUpAlgo.h:43
int chargedHadronVertex(const reco::VertexCollection &vertices, const reco::PFCandidate &pfcand) const
Definition: PFPileUpAlgo.cc:40
unsigned int fNumOfPUVtxsForCharged_
Definition: PFPileUpAlgo.h:42
PFCollection pfCandidatesFromVtx_
Definition: PFPileUpAlgo.h:48
bool verbose_
verbose ?
Definition: PFPileUpAlgo.h:46
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PFCollection pfCandidatesFromPU_
Definition: PFPileUpAlgo.h:49
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41

◆ setCheckClosestZVertex()

void PFPileUpAlgo::setCheckClosestZVertex ( bool  val)
inline

Definition at line 29 of file PFPileUpAlgo.h.

References checkClosestZVertex_, and heppy_batch::val.

bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUpAlgo.h:41

◆ setDzCutForChargedFromPUVtxs()

void PFPileUpAlgo::setDzCutForChargedFromPUVtxs ( double  val)
inline

Definition at line 31 of file PFPileUpAlgo.h.

References fDzCutForChargedFromPUVtxs_, and heppy_batch::val.

◆ setNumOfPUVtxsForCharged()

void PFPileUpAlgo::setNumOfPUVtxsForCharged ( unsigned int  val)
inline

Definition at line 30 of file PFPileUpAlgo.h.

References fNumOfPUVtxsForCharged_, and heppy_batch::val.

unsigned int fNumOfPUVtxsForCharged_
Definition: PFPileUpAlgo.h:42

◆ setVerbose()

void PFPileUpAlgo::setVerbose ( bool  verbose)
inline

Definition at line 27 of file PFPileUpAlgo.h.

References verbose, and verbose_.

27 { verbose_ = verbose; }
bool verbose
bool verbose_
verbose ?
Definition: PFPileUpAlgo.h:46

Member Data Documentation

◆ checkClosestZVertex_

bool PFPileUpAlgo::checkClosestZVertex_
private

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

Definition at line 41 of file PFPileUpAlgo.h.

Referenced by chargedHadronVertex(), and setCheckClosestZVertex().

◆ fDzCutForChargedFromPUVtxs_

double PFPileUpAlgo::fDzCutForChargedFromPUVtxs_
private

Definition at line 43 of file PFPileUpAlgo.h.

Referenced by process(), and setDzCutForChargedFromPUVtxs().

◆ fNumOfPUVtxsForCharged_

unsigned int PFPileUpAlgo::fNumOfPUVtxsForCharged_
private

Definition at line 42 of file PFPileUpAlgo.h.

Referenced by process(), and setNumOfPUVtxsForCharged().

◆ pfCandidatesFromPU_

PFCollection PFPileUpAlgo::pfCandidatesFromPU_
private

Definition at line 49 of file PFPileUpAlgo.h.

Referenced by getPFCandidatesFromPU(), and process().

◆ pfCandidatesFromVtx_

PFCollection PFPileUpAlgo::pfCandidatesFromVtx_
private

Definition at line 48 of file PFPileUpAlgo.h.

Referenced by getPFCandidatesFromVtx(), and process().

◆ verbose_

bool PFPileUpAlgo::verbose_
private

verbose ?

Definition at line 46 of file PFPileUpAlgo.h.

Referenced by process(), and setVerbose().