Go to the documentation of this file.00001 #include "CommonTools/ParticleFlow/plugins/PFPileUp.h"
00002
00003 #include "DataFormats/ParticleFlowCandidate/interface/PileUpPFCandidate.h"
00004 #include "DataFormats/ParticleFlowCandidate/interface/PileUpPFCandidateFwd.h"
00005 #include "DataFormats/VertexReco/interface/Vertex.h"
00006
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008
00009
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012
00013
00014 using namespace std;
00015 using namespace edm;
00016 using namespace reco;
00017
00018 PFPileUp::PFPileUp(const edm::ParameterSet& iConfig) {
00019
00020 inputTagPFCandidates_
00021 = iConfig.getParameter<InputTag>("PFCandidates");
00022
00023 inputTagVertices_
00024 = iConfig.getParameter<InputTag>("Vertices");
00025
00026 enable_ = iConfig.getParameter<bool>("Enable");
00027
00028 verbose_ =
00029 iConfig.getUntrackedParameter<bool>("verbose",false);
00030
00031
00032 if ( iConfig.exists("checkClosestZVertex") ) {
00033 checkClosestZVertex_ = iConfig.getParameter<bool>("checkClosestZVertex");
00034 } else {
00035 checkClosestZVertex_ = false;
00036 }
00037
00038
00039 pileUpAlgo_.setVerbose(verbose_);
00040 pileUpAlgo_.setCheckClosestZVertex(checkClosestZVertex_);
00041
00042
00043 produces< PFCollection > ();
00044 produces< PFCollectionByValue > ();
00045 }
00046
00047
00048
00049 PFPileUp::~PFPileUp() { }
00050
00051
00052
00053 void PFPileUp::beginJob() { }
00054
00055
00056 void PFPileUp::produce(Event& iEvent,
00057 const EventSetup& iSetup) {
00058
00059
00060
00061
00062
00063
00064
00065 auto_ptr< PFCollection >
00066 pOutput( new PFCollection );
00067
00068 auto_ptr< PFCollectionByValue >
00069 pOutputByValue ( new PFCollectionByValue );
00070
00071 if(enable_) {
00072
00073
00074
00075 Handle<VertexCollection> vertices;
00076 iEvent.getByLabel( inputTagVertices_, vertices);
00077
00078
00079 Handle<PFCollection> pfCandidates;
00080 PFCollection const * pfCandidatesRef = 0;
00081 PFCollection usedIfNoFwdPtrs;
00082 bool getFromFwdPtr = iEvent.getByLabel( inputTagPFCandidates_, pfCandidates);
00083 if ( getFromFwdPtr ) {
00084 pfCandidatesRef = pfCandidates.product();
00085 }
00086
00087
00088
00089
00090
00091 else {
00092 Handle<PFView> pfView;
00093 bool getFromView = iEvent.getByLabel( inputTagPFCandidates_, pfView );
00094 if ( ! getFromView ) {
00095 throw cms::Exception("PFPileUp is misconfigured. This needs to be either vector<FwdPtr<PFCandidate> >, or View<PFCandidate>");
00096 }
00097 for ( edm::View<reco::PFCandidate>::const_iterator viewBegin = pfView->begin(),
00098 viewEnd = pfView->end(), iview = viewBegin;
00099 iview != viewEnd; ++iview ) {
00100 usedIfNoFwdPtrs.push_back( edm::FwdPtr<reco::PFCandidate>( pfView->ptrAt(iview-viewBegin), pfView->ptrAt(iview-viewBegin) ) );
00101 }
00102 pfCandidatesRef = &usedIfNoFwdPtrs;
00103 }
00104
00105 if ( pfCandidatesRef == 0 ) {
00106 throw cms::Exception("Something went dreadfully wrong with PFPileUp. pfCandidatesRef should never be zero, so this is a logic error.");
00107 }
00108
00109
00110
00111 pileUpAlgo_.process(*pfCandidatesRef,*vertices);
00112 pOutput->insert(pOutput->end(),pileUpAlgo_.getPFCandidatesFromPU().begin(),pileUpAlgo_.getPFCandidatesFromPU().end());
00113
00114 for ( PFCollection::const_iterator byValueBegin = pileUpAlgo_.getPFCandidatesFromPU().begin(),
00115 byValueEnd = pileUpAlgo_.getPFCandidatesFromPU().end(), ibyValue = byValueBegin;
00116 ibyValue != byValueEnd; ++ibyValue ) {
00117 pOutputByValue->push_back( **ibyValue );
00118 }
00119
00120 }
00121
00122 iEvent.put( pOutput );
00123 iEvent.put( pOutputByValue );
00124 }
00125