CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static 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...

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

Public Types

typedef edm::Association< reco::VertexCollectionCandToVertex
 
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<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::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
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Attributes

bool checkClosestZVertex_
 use the closest z vertex if a track is not in a vertex More...
 
bool enable_
 enable PFPileUp selection More...
 
double fDzCutForChargedFromPUVtxs_
 
unsigned int fNumOfPUVtxsForCharged_
 
bool fUseVertexAssociation
 
PFPileUpAlgo pileUpAlgo_
 
edm::EDGetTokenT< PFCollectiontokenPFCandidates_
 PFCandidates to be analyzed. More...
 
edm::EDGetTokenT< PFViewtokenPFCandidatesView_
 fall-back token More...
 
edm::EDGetTokenT< CandToVertextokenVertexAssociation_
 
edm::EDGetTokenT< edm::ValueMap< int > > tokenVertexAssociationQuality_
 
edm::EDGetTokenT< reco::VertexCollectiontokenVertices_
 vertices More...
 
bool verbose_
 verbose ? More...
 
int vertexAssociationQuality_
 

Detailed Description

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

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

Definition at line 42 of file PFPileUp.cc.

Member Typedef Documentation

◆ CandToVertex

Definition at line 47 of file PFPileUp.cc.

◆ PFCollection

Definition at line 44 of file PFPileUp.cc.

◆ PFCollectionByValue

Definition at line 46 of file PFPileUp.cc.

◆ PFView

Definition at line 45 of file PFPileUp.cc.

Constructor & Destructor Documentation

◆ PFPileUp()

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

Definition at line 85 of file PFPileUp.cc.

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

85  {
86  tokenPFCandidates_ = consumes<PFCollection>(iConfig.getParameter<InputTag>("PFCandidates"));
87  tokenPFCandidatesView_ = mayConsume<PFView>(iConfig.getParameter<InputTag>("PFCandidates"));
88 
89  tokenVertices_ = consumes<VertexCollection>(iConfig.getParameter<InputTag>("Vertices"));
90 
91  fUseVertexAssociation = iConfig.getParameter<bool>("useVertexAssociation");
92  vertexAssociationQuality_ = iConfig.getParameter<int>("vertexAssociationQuality");
94  tokenVertexAssociation_ = consumes<CandToVertex>(iConfig.getParameter<edm::InputTag>("vertexAssociation"));
96  consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("vertexAssociation"));
97  }
98  fNumOfPUVtxsForCharged_ = iConfig.getParameter<unsigned int>("NumOfPUVtxsForCharged");
99  fDzCutForChargedFromPUVtxs_ = iConfig.getParameter<double>("DzCutForChargedFromPUVtxs");
100 
101  enable_ = iConfig.getParameter<bool>("enable");
102 
103  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
104 
105  checkClosestZVertex_ = iConfig.getParameter<bool>("checkClosestZVertex");
106 
107  // Configure the algo
112 
113  //produces<reco::PFCandidateCollection>();
114  produces<PFCollection>();
115  // produces< PFCollectionByValue > ();
116 }
int vertexAssociationQuality_
Definition: PFPileUp.cc:80
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::VertexCollection > tokenVertices_
vertices
Definition: PFPileUp.cc:66
edm::EDGetTokenT< PFView > tokenPFCandidatesView_
fall-back token
Definition: PFPileUp.cc:63
unsigned int fNumOfPUVtxsForCharged_
Definition: PFPileUp.cc:81
T getUntrackedParameter(std::string const &, T const &) const
void setCheckClosestZVertex(bool val)
Definition: PFPileUpAlgo.h:29
bool verbose_
verbose ?
Definition: PFPileUp.cc:72
void setDzCutForChargedFromPUVtxs(double val)
Definition: PFPileUpAlgo.h:31
edm::EDGetTokenT< PFCollection > tokenPFCandidates_
PFCandidates to be analyzed.
Definition: PFPileUp.cc:61
edm::EDGetTokenT< CandToVertex > tokenVertexAssociation_
Definition: PFPileUp.cc:77
bool enable_
enable PFPileUp selection
Definition: PFPileUp.cc:69
double fDzCutForChargedFromPUVtxs_
Definition: PFPileUp.cc:82
bool fUseVertexAssociation
Definition: PFPileUp.cc:79
edm::EDGetTokenT< edm::ValueMap< int > > tokenVertexAssociationQuality_
Definition: PFPileUp.cc:78
void setNumOfPUVtxsForCharged(unsigned int val)
Definition: PFPileUpAlgo.h:30
PFPileUpAlgo pileUpAlgo_
Definition: PFPileUp.cc:58
bool checkClosestZVertex_
use the closest z vertex if a track is not in a vertex
Definition: PFPileUp.cc:75
void setVerbose(bool verbose)
Definition: PFPileUpAlgo.h:27

◆ ~PFPileUp()

PFPileUp::~PFPileUp ( )
override

Definition at line 118 of file PFPileUp.cc.

118 {}

Member Function Documentation

◆ fillDescriptions()

void PFPileUp::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 200 of file PFPileUp.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and HLT_2022v15_cff::InputTag.

200  {
202  desc.add<edm::InputTag>("PFCandidates", edm::InputTag("particleFlowTmpPtrs"));
203  desc.add<edm::InputTag>("Vertices", edm::InputTag("offlinePrimaryVertices"));
204  desc.add<bool>("enable", true);
205  desc.addUntracked<bool>("verbose", false);
206  desc.add<bool>("checkClosestZVertex", true);
207  desc.add<bool>("useVertexAssociation", false);
208  desc.add<int>("vertexAssociationQuality", 0);
209  desc.add<edm::InputTag>("vertexAssociation", edm::InputTag(""));
210  desc.add<unsigned int>("NumOfPUVtxsForCharged", 0);
211  desc.add<double>("DzCutForChargedFromPUVtxs", .2);
212  descriptions.add("pfPileUp", desc);
213 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

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

Definition at line 120 of file PFPileUp.cc.

References Exception, iEvent, edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::key(), eostools::move(), AlCaHLTBitMon_ParallelJobs::p, zmumugammaAnalyzer_cfi::pfCandidates, quality, and AlignmentTracksFromVertexSelector_cfi::vertices.

120  {
121  // LogDebug("PFPileUp")<<"START event: "<<iEvent.id().event()
122  // <<" in run "<<iEvent.id().run()<<endl;
123 
124  // get PFCandidates
125 
126  unique_ptr<PFCollection> pOutput(new PFCollection);
127 
128  unique_ptr<PFCollectionByValue> pOutputByValue(new PFCollectionByValue);
129 
130  if (enable_) {
131  // get vertices
133  iEvent.getByToken(tokenVertices_, vertices);
134 
135  // get PF Candidates
137  PFCollection const* pfCandidatesRef = nullptr;
138  PFCollection usedIfNoFwdPtrs;
139  bool getFromFwdPtr = iEvent.getByToken(tokenPFCandidates_, pfCandidates);
140  if (getFromFwdPtr) {
141  pfCandidatesRef = pfCandidates.product();
142  }
143  // Maintain backwards-compatibility.
144  // If there is no vector of FwdPtr<PFCandidate> found, then
145  // make a dummy vector<FwdPtr<PFCandidate> > for the PFPileupAlgo,
146  // set the pointer "pfCandidatesRef" to point to it, and
147  // then we can pass it to the PFPileupAlgo.
148  else {
149  Handle<PFView> pfView;
150  bool getFromView = iEvent.getByToken(tokenPFCandidatesView_, pfView);
151  if (!getFromView) {
152  throw cms::Exception(
153  "PFPileUp is misconfigured. This needs to be either vector<FwdPtr<PFCandidate> >, or View<PFCandidate>");
154  }
155  for (edm::View<reco::PFCandidate>::const_iterator viewBegin = pfView->begin(),
156  viewEnd = pfView->end(),
157  iview = viewBegin;
158  iview != viewEnd;
159  ++iview) {
160  usedIfNoFwdPtrs.push_back(
161  edm::FwdPtr<reco::PFCandidate>(pfView->ptrAt(iview - viewBegin), pfView->ptrAt(iview - viewBegin)));
162  }
163  pfCandidatesRef = &usedIfNoFwdPtrs;
164  }
165 
166  if (pfCandidatesRef == nullptr) {
167  throw cms::Exception(
168  "Something went dreadfully wrong with PFPileUp. pfCandidatesRef should never be zero, so this is a logic "
169  "error.");
170  }
171 
172  if (fUseVertexAssociation) {
174  const edm::ValueMap<int>& associationQuality = iEvent.get(tokenVertexAssociationQuality_);
175  PFCollection pfCandidatesFromPU;
176  for (auto& p : (*pfCandidatesRef)) {
177  const reco::VertexRef& PVOrig = associatedPV[p];
178  int quality = associationQuality[p];
179  if (PVOrig.isNonnull() && (PVOrig.key() > 0) && (quality >= vertexAssociationQuality_))
180  pfCandidatesFromPU.push_back(p);
181  }
182  pOutput->insert(pOutput->end(), pfCandidatesFromPU.begin(), pfCandidatesFromPU.end());
183  } else {
184  pileUpAlgo_.process(*pfCandidatesRef, *vertices);
185  pOutput->insert(
186  pOutput->end(), pileUpAlgo_.getPFCandidatesFromPU().begin(), pileUpAlgo_.getPFCandidatesFromPU().end());
187  }
188  // for ( PFCollection::const_iterator byValueBegin = pileUpAlgo_.getPFCandidatesFromPU().begin(),
189  // byValueEnd = pileUpAlgo_.getPFCandidatesFromPU().end(), ibyValue = byValueBegin;
190  // ibyValue != byValueEnd; ++ibyValue ) {
191  // pOutputByValue->push_back( **ibyValue );
192  // }
193 
194  } // end if enabled
195  // outsize of the loop to fill the collection anyway even when disabled
196  iEvent.put(std::move(pOutput));
197  // iEvent.put(std::move(pOutputByValue));
198 }
int vertexAssociationQuality_
Definition: PFPileUp.cc:80
Ptr< value_type > ptrAt(size_type i) const
edm::EDGetTokenT< reco::VertexCollection > tokenVertices_
vertices
Definition: PFPileUp.cc:66
edm::EDGetTokenT< PFView > tokenPFCandidatesView_
fall-back token
Definition: PFPileUp.cc:63
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
key_type key() const
Accessor for product key.
Definition: Ref.h:250
string quality
int iEvent
Definition: GenABIO.cc:224
std::vector< reco::PFCandidate > PFCollectionByValue
Definition: PFPileUp.cc:46
edm::EDGetTokenT< PFCollection > tokenPFCandidates_
PFCandidates to be analyzed.
Definition: PFPileUp.cc:61
std::vector< edm::FwdPtr< reco::PFCandidate > > PFCollection
Definition: PFPileUp.cc:44
edm::EDGetTokenT< CandToVertex > tokenVertexAssociation_
Definition: PFPileUp.cc:77
bool enable_
enable PFPileUp selection
Definition: PFPileUp.cc:69
bool fUseVertexAssociation
Definition: PFPileUp.cc:79
edm::EDGetTokenT< edm::ValueMap< int > > tokenVertexAssociationQuality_
Definition: PFPileUp.cc:78
const PFCollection & getPFCandidatesFromPU() const
Definition: PFPileUpAlgo.h:33
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
void process(const PFCollection &pfCandidates, const reco::VertexCollection &vertices)
Definition: PFPileUpAlgo.cc:6
PFPileUpAlgo pileUpAlgo_
Definition: PFPileUp.cc:58
const_iterator begin() const
const_iterator end() const
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ checkClosestZVertex_

bool PFPileUp::checkClosestZVertex_
private

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

Definition at line 75 of file PFPileUp.cc.

◆ enable_

bool PFPileUp::enable_
private

enable PFPileUp selection

Definition at line 69 of file PFPileUp.cc.

◆ fDzCutForChargedFromPUVtxs_

double PFPileUp::fDzCutForChargedFromPUVtxs_
private

Definition at line 82 of file PFPileUp.cc.

◆ fNumOfPUVtxsForCharged_

unsigned int PFPileUp::fNumOfPUVtxsForCharged_
private

Definition at line 81 of file PFPileUp.cc.

◆ fUseVertexAssociation

bool PFPileUp::fUseVertexAssociation
private

Definition at line 79 of file PFPileUp.cc.

◆ pileUpAlgo_

PFPileUpAlgo PFPileUp::pileUpAlgo_
private

Definition at line 58 of file PFPileUp.cc.

◆ tokenPFCandidates_

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

PFCandidates to be analyzed.

Definition at line 61 of file PFPileUp.cc.

◆ tokenPFCandidatesView_

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

fall-back token

Definition at line 63 of file PFPileUp.cc.

◆ tokenVertexAssociation_

edm::EDGetTokenT<CandToVertex> PFPileUp::tokenVertexAssociation_
private

Definition at line 77 of file PFPileUp.cc.

◆ tokenVertexAssociationQuality_

edm::EDGetTokenT<edm::ValueMap<int> > PFPileUp::tokenVertexAssociationQuality_
private

Definition at line 78 of file PFPileUp.cc.

◆ tokenVertices_

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

vertices

Definition at line 66 of file PFPileUp.cc.

◆ verbose_

bool PFPileUp::verbose_
private

verbose ?

Definition at line 72 of file PFPileUp.cc.

◆ vertexAssociationQuality_

int PFPileUp::vertexAssociationQuality_
private

Definition at line 80 of file PFPileUp.cc.