test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

Definition at line 16 of file PFPileUpAlgo.h.

Constructor & Destructor Documentation

PFPileUpAlgo::PFPileUpAlgo ( )
inline

Definition at line 18 of file PFPileUpAlgo.h.

18 :checkClosestZVertex_(true), verbose_(false) {;}
bool verbose_
verbose ?
Definition: PFPileUpAlgo.h:48
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUpAlgo.h:44
PFPileUpAlgo::PFPileUpAlgo ( bool  checkClosestZVertex,
bool  verbose = false 
)
inline

Definition at line 20 of file PFPileUpAlgo.h.

20  :
21  checkClosestZVertex_(checkClosestZVertex), verbose_(verbose) {;}
bool verbose_
verbose ?
Definition: PFPileUpAlgo.h:48
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUpAlgo.h:44
PFPileUpAlgo::~PFPileUpAlgo ( )
inline

Definition at line 23 of file PFPileUpAlgo.h.

23 {;}

Member Function Documentation

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

Definition at line 43 of file PFPileUpAlgo.cc.

References checkClosestZVertex_, cmsHarvester::index, reco::PFCandidate::trackRef(), reco::PFCandidate::vertex(), and w.

Referenced by process().

43  {
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 }
const double w
Definition: UKUtility.cc:23
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:433
virtual const Point & vertex() const
vertex position (overwritten by PF...)
Definition: PFCandidate.cc:647
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUpAlgo.h:44
const PFCollection& PFPileUpAlgo::getPFCandidatesFromPU ( ) const
inline

Definition at line 33 of file PFPileUpAlgo.h.

References pfCandidatesFromPU_.

33 {return pfCandidatesFromPU_;}
PFCollection pfCandidatesFromPU_
Definition: PFPileUpAlgo.h:51
const PFCollection& PFPileUpAlgo::getPFCandidatesFromVtx ( ) const
inline

Definition at line 35 of file PFPileUpAlgo.h.

References pfCandidatesFromVtx_.

35 {return pfCandidatesFromVtx_;}
PFCollection pfCandidatesFromVtx_
Definition: PFPileUpAlgo.h:50
void PFPileUpAlgo::process ( const PFCollection pfCandidates,
const reco::VertexCollection vertices 
)

Definition at line 5 of file PFPileUpAlgo.cc.

References chargedHadronVertex(), gather_cfg::cout, reco::PFCandidate::h, i, reco::PFCandidate::particleId(), pfCandidatesFromPU_, pfCandidatesFromVtx_, and verbose_.

Referenced by ConfigBuilder.ConfigBuilder::addExtraStream(), ConfigBuilder.ConfigBuilder::completeInputCommand(), ConfigBuilder.ConfigBuilder::doNotInlineEventContent(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::dumpPython(), ConfigBuilder.ConfigBuilder.PrintAllModules::leave(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::open(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::outputEventContent(), ConfigBuilder.ConfigBuilder::prepare_HLT(), ConfigBuilder.ConfigBuilder::prepare_LHE(), ConfigBuilder.ConfigBuilder::prepare_PATFILTER(), ConfigBuilder.ConfigBuilder::prepare_VALIDATION(), ConfigBuilder.ConfigBuilder::renameHLTprocessInSequence(), ConfigBuilder.ConfigBuilder::renameInputTagsInSequence(), ConfigBuilder.ConfigBuilder::scheduleSequence(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::setProcess(), and Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::setProperty().

6  {
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 }
int i
Definition: DBlmapReader.cc:9
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
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
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
tuple cout
Definition: gather_cfg.py:145
virtual ParticleType particleId() const
Definition: PFCandidate.h:373
void PFPileUpAlgo::setCheckClosestZVertex ( bool  val)
inline

Definition at line 31 of file PFPileUpAlgo.h.

References checkClosestZVertex_.

31 { checkClosestZVertex_ = val;}
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUpAlgo.h:44
void PFPileUpAlgo::setVerbose ( bool  verbose)
inline

Definition at line 29 of file PFPileUpAlgo.h.

References verbose, and verbose_.

29 { verbose_ = verbose; }
bool verbose
bool verbose_
verbose ?
Definition: PFPileUpAlgo.h:48

Member Data Documentation

bool PFPileUpAlgo::checkClosestZVertex_
private

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

Definition at line 44 of file PFPileUpAlgo.h.

Referenced by chargedHadronVertex(), and setCheckClosestZVertex().

PFCollection PFPileUpAlgo::pfCandidatesFromPU_
private

Definition at line 51 of file PFPileUpAlgo.h.

Referenced by getPFCandidatesFromPU(), and process().

PFCollection PFPileUpAlgo::pfCandidatesFromVtx_
private

Definition at line 50 of file PFPileUpAlgo.h.

Referenced by getPFCandidatesFromVtx(), and process().

bool PFPileUpAlgo::verbose_
private

verbose ?

Definition at line 48 of file PFPileUpAlgo.h.

Referenced by process(), and setVerbose().