CMS 3D CMS Logo

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

Identifies pile-up candidates from a collection of PFCandidates, and produces the corresponding collection of PileUpCandidates. More...

#include <PFPileUp.h>

Inheritance diagram for PFPileUp:
edm::stream::EDProducer<>

Public Types

typedef std::vector< edm::FwdPtr< reco::PFCandidate > > PFCollection
 
typedef std::vector< reco::PFCandidatePFCollectionByValue
 
typedef edm::View< reco::PFCandidatePFView
 
- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Public Member Functions

 PFPileUp (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~PFPileUp () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Private Attributes

bool checkClosestZVertex_
 use the closest z vertex if a track is not in a vertex More...
 
bool enable_
 enable PFPileUp selection More...
 
PFPileUpAlgo pileUpAlgo_
 
edm::EDGetTokenT< PFCollectiontokenPFCandidates_
 PFCandidates to be analyzed. More...
 
edm::EDGetTokenT< PFViewtokenPFCandidatesView_
 fall-back token More...
 
edm::EDGetTokenT< reco::VertexCollectiontokenVertices_
 vertices More...
 
bool verbose_
 verbose ? More...
 

Detailed Description

Identifies pile-up candidates from a collection of PFCandidates, and produces the corresponding collection of PileUpCandidates.

Author
Colin Bernet
Date
february 2008 \updated Florian Beaudette 30/03/2012

Definition at line 31 of file PFPileUp.h.

Member Typedef Documentation

◆ PFCollection

Definition at line 33 of file PFPileUp.h.

◆ PFCollectionByValue

Definition at line 35 of file PFPileUp.h.

◆ PFView

Definition at line 34 of file PFPileUp.h.

Constructor & Destructor Documentation

◆ PFPileUp()

PFPileUp::PFPileUp ( const edm::ParameterSet iConfig)
explicit

Definition at line 17 of file PFPileUp.cc.

17  {
18  tokenPFCandidates_ = consumes<PFCollection>(iConfig.getParameter<InputTag>("PFCandidates"));
19  tokenPFCandidatesView_ = mayConsume<PFView>(iConfig.getParameter<InputTag>("PFCandidates"));
20 
21  tokenVertices_ = consumes<VertexCollection>(iConfig.getParameter<InputTag>("Vertices"));
22 
23  enable_ = iConfig.getParameter<bool>("Enable");
24 
25  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
26 
27  if (iConfig.exists("checkClosestZVertex")) {
28  checkClosestZVertex_ = iConfig.getParameter<bool>("checkClosestZVertex");
29  } else {
30  checkClosestZVertex_ = false;
31  }
32 
33  // Configure the algo
36 
37  //produces<reco::PFCandidateCollection>();
38  produces<PFCollection>();
39  // produces< PFCollectionByValue > ();
40 }

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), and edm::ParameterSet::getUntrackedParameter().

◆ ~PFPileUp()

PFPileUp::~PFPileUp ( )
override

Definition at line 42 of file PFPileUp.cc.

42 {}

Member Function Documentation

◆ produce()

void PFPileUp::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 44 of file PFPileUp.cc.

44  {
45  // LogDebug("PFPileUp")<<"START event: "<<iEvent.id().event()
46  // <<" in run "<<iEvent.id().run()<<endl;
47 
48  // get PFCandidates
49 
50  unique_ptr<PFCollection> pOutput(new PFCollection);
51 
52  unique_ptr<PFCollectionByValue> pOutputByValue(new PFCollectionByValue);
53 
54  if (enable_) {
55  // get vertices
57  iEvent.getByToken(tokenVertices_, vertices);
58 
59  // get PF Candidates
61  PFCollection const* pfCandidatesRef = nullptr;
62  PFCollection usedIfNoFwdPtrs;
63  bool getFromFwdPtr = iEvent.getByToken(tokenPFCandidates_, pfCandidates);
64  if (getFromFwdPtr) {
65  pfCandidatesRef = pfCandidates.product();
66  }
67  // Maintain backwards-compatibility.
68  // If there is no vector of FwdPtr<PFCandidate> found, then
69  // make a dummy vector<FwdPtr<PFCandidate> > for the PFPileupAlgo,
70  // set the pointer "pfCandidatesRef" to point to it, and
71  // then we can pass it to the PFPileupAlgo.
72  else {
73  Handle<PFView> pfView;
74  bool getFromView = iEvent.getByToken(tokenPFCandidatesView_, pfView);
75  if (!getFromView) {
76  throw cms::Exception(
77  "PFPileUp is misconfigured. This needs to be either vector<FwdPtr<PFCandidate> >, or View<PFCandidate>");
78  }
79  for (edm::View<reco::PFCandidate>::const_iterator viewBegin = pfView->begin(),
80  viewEnd = pfView->end(),
81  iview = viewBegin;
82  iview != viewEnd;
83  ++iview) {
84  usedIfNoFwdPtrs.push_back(
85  edm::FwdPtr<reco::PFCandidate>(pfView->ptrAt(iview - viewBegin), pfView->ptrAt(iview - viewBegin)));
86  }
87  pfCandidatesRef = &usedIfNoFwdPtrs;
88  }
89 
90  if (pfCandidatesRef == nullptr) {
91  throw cms::Exception(
92  "Something went dreadfully wrong with PFPileUp. pfCandidatesRef should never be zero, so this is a logic "
93  "error.");
94  }
95 
96  pileUpAlgo_.process(*pfCandidatesRef, *vertices);
97  pOutput->insert(
98  pOutput->end(), pileUpAlgo_.getPFCandidatesFromPU().begin(), pileUpAlgo_.getPFCandidatesFromPU().end());
99 
100  // for ( PFCollection::const_iterator byValueBegin = pileUpAlgo_.getPFCandidatesFromPU().begin(),
101  // byValueEnd = pileUpAlgo_.getPFCandidatesFromPU().end(), ibyValue = byValueBegin;
102  // ibyValue != byValueEnd; ++ibyValue ) {
103  // pOutputByValue->push_back( **ibyValue );
104  // }
105 
106  } // end if enabled
107  // outsize of the loop to fill the collection anyway even when disabled
108  iEvent.put(std::move(pOutput));
109  // iEvent.put(std::move(pOutputByValue));
110 }

References Exception, iEvent, eostools::move(), zmumugammaAnalyzer_cfi::pfCandidates, and pwdgSkimBPark_cfi::vertices.

Member Data Documentation

◆ checkClosestZVertex_

bool PFPileUp::checkClosestZVertex_
private

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

Definition at line 61 of file PFPileUp.h.

◆ enable_

bool PFPileUp::enable_
private

enable PFPileUp selection

Definition at line 55 of file PFPileUp.h.

◆ pileUpAlgo_

PFPileUpAlgo PFPileUp::pileUpAlgo_
private

Definition at line 44 of file PFPileUp.h.

◆ tokenPFCandidates_

edm::EDGetTokenT<PFCollection> PFPileUp::tokenPFCandidates_
private

PFCandidates to be analyzed.

Definition at line 47 of file PFPileUp.h.

◆ tokenPFCandidatesView_

edm::EDGetTokenT<PFView> PFPileUp::tokenPFCandidatesView_
private

fall-back token

Definition at line 49 of file PFPileUp.h.

◆ tokenVertices_

edm::EDGetTokenT<reco::VertexCollection> PFPileUp::tokenVertices_
private

vertices

Definition at line 52 of file PFPileUp.h.

◆ verbose_

bool PFPileUp::verbose_
private

verbose ?

Definition at line 58 of file PFPileUp.h.

edm::View::begin
const_iterator begin() const
zmumugammaAnalyzer_cfi.pfCandidates
pfCandidates
Definition: zmumugammaAnalyzer_cfi.py:11
PFPileUp::tokenVertices_
edm::EDGetTokenT< reco::VertexCollection > tokenVertices_
vertices
Definition: PFPileUp.h:52
PFPileUpAlgo::getPFCandidatesFromPU
const PFCollection & getPFCandidatesFromPU() const
Definition: PFPileUpAlgo.h:32
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
PFPileUp::tokenPFCandidatesView_
edm::EDGetTokenT< PFView > tokenPFCandidatesView_
fall-back token
Definition: PFPileUp.h:49
edm::Handle< VertexCollection >
PFPileUpAlgo::process
void process(const PFCollection &pfCandidates, const reco::VertexCollection &vertices)
Definition: PFPileUpAlgo.cc:5
PFPileUp::verbose_
bool verbose_
verbose ?
Definition: PFPileUp.h:58
PFPileUpAlgo::setVerbose
void setVerbose(bool verbose)
Definition: PFPileUpAlgo.h:28
edm::FwdPtr
Definition: FwdPtr.h:40
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:674
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
PFPileUp::enable_
bool enable_
enable PFPileUp selection
Definition: PFPileUp.h:55
Exception
Definition: hltDiff.cc:246
PFPileUp::PFCollection
std::vector< edm::FwdPtr< reco::PFCandidate > > PFCollection
Definition: PFPileUp.h:33
PFPileUp::PFCollectionByValue
std::vector< reco::PFCandidate > PFCollectionByValue
Definition: PFPileUp.h:35
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
PFPileUp::checkClosestZVertex_
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUp.h:61
PFPileUp::tokenPFCandidates_
edm::EDGetTokenT< PFCollection > tokenPFCandidates_
PFCandidates to be analyzed.
Definition: PFPileUp.h:47
edm::View::end
const_iterator end() const
edm::View::ptrAt
Ptr< value_type > ptrAt(size_type i) const
edm::InputTag
Definition: InputTag.h:15
PFPileUp::pileUpAlgo_
PFPileUpAlgo pileUpAlgo_
Definition: PFPileUp.h:44
PFPileUpAlgo::setCheckClosestZVertex
void setCheckClosestZVertex(bool val)
Definition: PFPileUpAlgo.h:30
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7