CMS 3D CMS Logo

PFPileUp.cc
Go to the documentation of this file.
2 
6 
8 
9 // #include "FWCore/MessageLogger/interface/MessageLogger.h"
12 
13 
14 using namespace std;
15 using namespace edm;
16 using namespace reco;
17 
19 
20  tokenPFCandidates_
21  = consumes<PFCollection>(iConfig.getParameter<InputTag>("PFCandidates"));
22  tokenPFCandidatesView_
23  = mayConsume<PFView>(iConfig.getParameter<InputTag>("PFCandidates"));
24 
25  tokenVertices_
26  = consumes<VertexCollection>(iConfig.getParameter<InputTag>("Vertices"));
27 
28  enable_ = iConfig.getParameter<bool>("Enable");
29 
30  verbose_ =
31  iConfig.getUntrackedParameter<bool>("verbose",false);
32 
33 
34  if ( iConfig.exists("checkClosestZVertex") ) {
35  checkClosestZVertex_ = iConfig.getParameter<bool>("checkClosestZVertex");
36  } else {
37  checkClosestZVertex_ = false;
38  }
39 
40  // Configure the algo
41  pileUpAlgo_.setVerbose(verbose_);
42  pileUpAlgo_.setCheckClosestZVertex(checkClosestZVertex_);
43 
44  //produces<reco::PFCandidateCollection>();
45  produces< PFCollection > ();
46  // produces< PFCollectionByValue > ();
47 }
48 
49 
50 
52 
53 
54 
56  const EventSetup& iSetup) {
57 
58 // LogDebug("PFPileUp")<<"START event: "<<iEvent.id().event()
59 // <<" in run "<<iEvent.id().run()<<endl;
60 
61 
62  // get PFCandidates
63 
64  unique_ptr< PFCollection >
65  pOutput( new PFCollection );
66 
67  unique_ptr< PFCollectionByValue >
68  pOutputByValue ( new PFCollectionByValue );
69 
70  if(enable_) {
71 
72 
73  // get vertices
75  iEvent.getByToken( tokenVertices_, vertices);
76 
77  // get PF Candidates
79  PFCollection const * pfCandidatesRef = nullptr;
80  PFCollection usedIfNoFwdPtrs;
81  bool getFromFwdPtr = iEvent.getByToken( tokenPFCandidates_, pfCandidates);
82  if ( getFromFwdPtr ) {
83  pfCandidatesRef = pfCandidates.product();
84  }
85  // Maintain backwards-compatibility.
86  // If there is no vector of FwdPtr<PFCandidate> found, then
87  // make a dummy vector<FwdPtr<PFCandidate> > for the PFPileupAlgo,
88  // set the pointer "pfCandidatesRef" to point to it, and
89  // then we can pass it to the PFPileupAlgo.
90  else {
91  Handle<PFView> pfView;
92  bool getFromView = iEvent.getByToken( tokenPFCandidatesView_, pfView );
93  if ( ! getFromView ) {
94  throw cms::Exception("PFPileUp is misconfigured. This needs to be either vector<FwdPtr<PFCandidate> >, or View<PFCandidate>");
95  }
96  for ( edm::View<reco::PFCandidate>::const_iterator viewBegin = pfView->begin(),
97  viewEnd = pfView->end(), iview = viewBegin;
98  iview != viewEnd; ++iview ) {
99  usedIfNoFwdPtrs.push_back( edm::FwdPtr<reco::PFCandidate>( pfView->ptrAt(iview-viewBegin), pfView->ptrAt(iview-viewBegin) ) );
100  }
101  pfCandidatesRef = &usedIfNoFwdPtrs;
102  }
103 
104  if ( pfCandidatesRef == nullptr ) {
105  throw cms::Exception("Something went dreadfully wrong with PFPileUp. pfCandidatesRef should never be zero, so this is a logic error.");
106  }
107 
108 
109 
110  pileUpAlgo_.process(*pfCandidatesRef,*vertices);
111  pOutput->insert(pOutput->end(),pileUpAlgo_.getPFCandidatesFromPU().begin(),pileUpAlgo_.getPFCandidatesFromPU().end());
112 
113  // for ( PFCollection::const_iterator byValueBegin = pileUpAlgo_.getPFCandidatesFromPU().begin(),
114  // byValueEnd = pileUpAlgo_.getPFCandidatesFromPU().end(), ibyValue = byValueBegin;
115  // ibyValue != byValueEnd; ++ibyValue ) {
116  // pOutputByValue->push_back( **ibyValue );
117  // }
118 
119  } // end if enabled
120  // outsize of the loop to fill the collection anyway even when disabled
121  iEvent.put(std::move(pOutput));
122  // iEvent.put(std::move(pOutputByValue));
123 }
124 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
bool exists(std::string const &parameterName) const
checks if a parameter exists
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PFPileUp.cc:55
int iEvent
Definition: GenABIO.cc:230
std::vector< reco::PFCandidate > PFCollectionByValue
Definition: PFPileUp.h:39
std::vector< edm::FwdPtr< reco::PFCandidate > > PFCollection
Definition: PFPileUp.h:37
T const * product() const
Definition: Handle.h:81
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
~PFPileUp() override
Definition: PFPileUp.cc:51
PFPileUp(const edm::ParameterSet &)
Definition: PFPileUp.cc:18
def move(src, dest)
Definition: eostools.py:510