#include <RecoJets/FFTJetProducers/plugins/FFTJetPFPileupCleaner.cc>
Description: cleans up a collection of partice flow objects
Implementation: [Notes on implementation]
Definition at line 46 of file FFTJetPFPileupCleaner.cc.
FFTJetPFPileupCleaner::FFTJetPFPileupCleaner | ( | const edm::ParameterSet & | ps | ) | [explicit] |
Definition at line 134 of file FFTJetPFPileupCleaner.cc.
References buildRemovalMask().
: init_param(edm::InputTag, PFCandidates), init_param(edm::InputTag, Vertices), init_param(edm::InputTag, FakePrimaryVertices), init_param(bool, useFakePrimaryVertex), init_param(bool, checkClosestZVertex), init_param(bool, keepIfPVneighbor), init_param(bool, removeMainVertex), init_param(bool, removeUnassociated), init_param(bool, reverseRemovalDecision), init_param(bool, remove_X ), init_param(bool, remove_h ), init_param(bool, remove_e ), init_param(bool, remove_mu ), init_param(bool, remove_gamma ), init_param(bool, remove_h0 ), init_param(bool, remove_h_HF ), init_param(bool, remove_egamma_HF), removalMask(0), init_param(double, etaMin), init_param(double, etaMax), init_param(double, vertexNdofCut), init_param(double, vertexZmaxCut) { buildRemovalMask(); produces<reco::PFCandidateCollection>(); }
FFTJetPFPileupCleaner::~FFTJetPFPileupCleaner | ( | ) |
Definition at line 163 of file FFTJetPFPileupCleaner.cc.
{ }
FFTJetPFPileupCleaner::FFTJetPFPileupCleaner | ( | ) | [private] |
FFTJetPFPileupCleaner::FFTJetPFPileupCleaner | ( | const FFTJetPFPileupCleaner & | ) | [private] |
void FFTJetPFPileupCleaner::beginJob | ( | void | ) | [protected, virtual] |
void FFTJetPFPileupCleaner::buildRemovalMask | ( | ) | [private] |
Definition at line 487 of file FFTJetPFPileupCleaner.cc.
References reco::PFCandidate::e, reco::PFCandidate::egamma_HF, reco::PFCandidate::gamma, reco::PFCandidate::h, reco::PFCandidate::h0, reco::PFCandidate::h_HF, reco::PFCandidate::mu, remove_e, remove_egamma_HF, remove_gamma, remove_h, remove_h0, remove_h_HF, remove_mu, remove_X, setRemovalBit(), and reco::PFCandidate::X.
Referenced by FFTJetPFPileupCleaner().
{ setRemovalBit(reco::PFCandidate::X, remove_X ); setRemovalBit(reco::PFCandidate::h, remove_h ); setRemovalBit(reco::PFCandidate::e, remove_e ); setRemovalBit(reco::PFCandidate::mu, remove_mu ); setRemovalBit(reco::PFCandidate::gamma, remove_gamma ); setRemovalBit(reco::PFCandidate::h0, remove_h0 ); setRemovalBit(reco::PFCandidate::h_HF, remove_h_HF ); setRemovalBit(reco::PFCandidate::egamma_HF, remove_egamma_HF); }
void FFTJetPFPileupCleaner::endJob | ( | void | ) | [protected, virtual] |
reco::VertexRef FFTJetPFPileupCleaner::findSomeVertexWFakes | ( | const edm::Handle< reco::VertexCollection > & | vertices, |
const edm::Handle< reco::VertexCollection > & | fakeVertices, | ||
const reco::PFCandidate & | pfcand, | ||
bool * | fromFakeSet | ||
) | const [private] |
Definition at line 282 of file FFTJetPFPileupCleaner.cc.
References abs, checkClosestZVertex, first, getHLTprescales::index, isAcceptableVtx(), keepIfPVneighbor, python::multivaluedict::sort(), reco::PFCandidate::trackRef(), reco::Vertex::tracks_begin(), reco::Vertex::tracks_end(), reco::Vertex::trackWeight(), useFakePrimaryVertex, reco::PFCandidate::vertex(), w(), z, and zAssoc.
Referenced by produce().
{ typedef reco::VertexCollection::const_iterator IV; typedef reco::Vertex::trackRef_iterator IT; *fromFakeSet = false; reco::TrackBaseRef trackBaseRef(pfcand.trackRef()); size_t iVertex = 0; unsigned nFoundVertex = 0; const IV vertend(vertices->end()); { unsigned index = 0; double bestweight = 0.0; for (IV iv=vertices->begin(); iv!=vertend; ++iv, ++index) if (isAcceptableVtx(iv)) { const reco::Vertex& vtx = *iv; // loop on tracks in vertices IT trackend(vtx.tracks_end()); for (IT iTrack=vtx.tracks_begin(); iTrack!=trackend; ++iTrack) { const reco::TrackBaseRef& baseRef = *iTrack; // one of the tracks in the vertex is the same as // the track considered in the function if (baseRef == trackBaseRef) { // select the vertex for which the track has the highest weight const double w = vtx.trackWeight(baseRef); if (w > bestweight) { bestweight=w; iVertex=index; nFoundVertex++; } } } } } if (nFoundVertex > 0) { if (nFoundVertex != 1) edm::LogWarning("TrackOnTwoVertex") << "a track is shared by at least two vertices. " << "Used to be an assert"; // Check if we can re-associate this track with one // of the fake vertices if (useFakePrimaryVertex) { const double ztrack = pfcand.vertex().z(); double dzmin = std::abs(ztrack - ((*vertices)[iVertex]).z()); const IV fakeEnd(fakeVertices->end()); unsigned index = 0; for (IV iv=fakeVertices->begin(); iv!=fakeEnd; ++iv, ++index) if (isAcceptableVtx(iv)) { const double dz = std::abs(ztrack - iv->z()); if (dz < dzmin) { dzmin = dz; iVertex = index; *fromFakeSet = true; } } } return reco::VertexRef(*fromFakeSet ? fakeVertices : vertices, iVertex); } // optional: as a secondary solution, associate the closest vertex in z if (checkClosestZVertex) { const double ztrack = pfcand.vertex().z(); bool foundVertex = false; if (keepIfPVneighbor) { // Sort all vertices according to their Z coordinate zAssoc.clear(); unsigned index = 0; for (IV iv=vertices->begin(); iv!=vertend; ++iv, ++index) if (isAcceptableVtx(iv)) zAssoc.push_back(std::pair<double,unsigned>(iv->z(), index)); const unsigned numRealVertices = index; // Mix the fake vertex collection into zAssoc. // Note that we do not reset "index" before doing this. if (useFakePrimaryVertex) { const IV fakeEnd(fakeVertices->end()); for (IV iv=fakeVertices->begin(); iv!=fakeEnd; ++iv, ++index) if (isAcceptableVtx(iv)) zAssoc.push_back(std::pair<double,unsigned>(iv->z(), index)); } // Check where the track z position fits into this sequence if (!zAssoc.empty()) { std::sort(zAssoc.begin(), zAssoc.end()); std::pair<double,unsigned> tPair(ztrack, UINT_MAX); const unsigned iAbove = std::upper_bound( zAssoc.begin(), zAssoc.end(), tPair) - zAssoc.begin(); // Check whether one of the vertices with indices // iAbove or (iAbove - 1) is a primary vertex. // If so, return it. Otherwise return the one // with closest distance to the track. unsigned ich[2] = {0U, 0U}; unsigned nch = 1; if (iAbove) { ich[0] = iAbove - 1U; ich[1] = iAbove; if (iAbove < zAssoc.size()) nch = 2; } double dzmin = 1.0e100; unsigned bestVertexNum = UINT_MAX; for (unsigned icheck=0; icheck<nch; ++icheck) { const unsigned zAssocIndex = ich[icheck]; const unsigned vertexNum = zAssoc[zAssocIndex].second; if (vertexNum == numRealVertices || (!useFakePrimaryVertex && vertexNum == 0U)) { bestVertexNum = vertexNum; break; } const double dz = std::abs(ztrack - zAssoc[zAssocIndex].first); if (dz < dzmin) { dzmin = dz; bestVertexNum = vertexNum; } } foundVertex = bestVertexNum < UINT_MAX; if (foundVertex) { iVertex = bestVertexNum; if (iVertex >= numRealVertices) { *fromFakeSet = true; iVertex -= numRealVertices; } } } } else { // This is a simple association algorithm (from PFPileUp) // extended to take fake vertices into account double dzmin = 1.0e100; unsigned index = 0; for (IV iv=vertices->begin(); iv!=vertend; ++iv, ++index) if (isAcceptableVtx(iv)) { const double dz = std::abs(ztrack - iv->z()); if (dz < dzmin) { dzmin = dz; iVertex = index; foundVertex = true; } } if (useFakePrimaryVertex) { const IV fakeEnd(fakeVertices->end()); index = 0; for (IV iv=fakeVertices->begin(); iv!=fakeEnd; ++iv, ++index) if (isAcceptableVtx(iv)) { const double dz = std::abs(ztrack - iv->z()); if (dz < dzmin) { dzmin = dz; iVertex = index; *fromFakeSet = true; foundVertex = true; } } } } if (foundVertex) return reco::VertexRef(*fromFakeSet ? fakeVertices : vertices, iVertex); } return reco::VertexRef(); }
bool FFTJetPFPileupCleaner::isAcceptableVtx | ( | reco::VertexCollection::const_iterator | iv | ) | const [private] |
Definition at line 168 of file FFTJetPFPileupCleaner.cc.
References abs, vertexNdofCut, and vertexZmaxCut.
Referenced by findSomeVertexWFakes().
{ return !iv->isFake() && static_cast<double>(iv->ndof()) > vertexNdofCut && std::abs(iv->z()) < vertexZmaxCut; }
bool FFTJetPFPileupCleaner::isRemovable | ( | reco::PFCandidate::ParticleType | ptype | ) | const [private] |
Definition at line 257 of file FFTJetPFPileupCleaner.cc.
References removalMask, and edm::shift.
Referenced by produce().
{ const unsigned shift = static_cast<unsigned>(ptype); assert(shift < 32U); return removalMask & (1U << shift); }
FFTJetPFPileupCleaner& FFTJetPFPileupCleaner::operator= | ( | const FFTJetPFPileupCleaner & | ) | [private] |
void FFTJetPFPileupCleaner::produce | ( | edm::Event & | iEvent, |
const edm::EventSetup & | iSetup | ||
) | [protected, virtual] |
Implements edm::EDProducer.
Definition at line 178 of file FFTJetPFPileupCleaner.cc.
References eta, etaMax, FakePrimaryVertices, findSomeVertexWFakes(), edm::Event::getByLabel(), i, edm::Ref< C, T, F >::isNull(), isRemovable(), edm::HandleBase::isValid(), edm::Ref< C, T, F >::key(), PFCandidates, reco::tau::pfCandidates(), edm::Event::put(), removeMainVertex, removeUnassociated, reverseRemovalDecision, reco::PFCandidate::setSourceCandidatePtr(), useFakePrimaryVertex, and Vertices.
{ // get PFCandidates std::auto_ptr<reco::PFCandidateCollection> pOutput(new reco::PFCandidateCollection); edm::Handle<reco::PFCandidateCollection> pfCandidates; iEvent.getByLabel(PFCandidates, pfCandidates); // get vertices edm::Handle<reco::VertexCollection> vertices; iEvent.getByLabel(Vertices, vertices); edm::Handle<reco::VertexCollection> fakeVertices; if (useFakePrimaryVertex) { iEvent.getByLabel(FakePrimaryVertices, fakeVertices); if (!fakeVertices.isValid()) throw cms::Exception("FFTJetBadConfig") << "ERROR in FFTJetPFPileupCleaner:" " could not find fake vertices" << std::endl; } const unsigned ncand = pfCandidates->size(); for (unsigned i=0; i<ncand; ++i) { reco::PFCandidatePtr candptr(pfCandidates, i); bool remove = false; if (isRemovable(candptr->particleId())) { bool fromFakeSet = false; reco::VertexRef vertexref(findSomeVertexWFakes(vertices, fakeVertices, *candptr, &fromFakeSet)); if (vertexref.isNull()) { // Track is not associated with any vertex // in any of the vertex sets remove = removeUnassociated; } else if (vertexref.key() == 0 && (!useFakePrimaryVertex || fromFakeSet)) { // Track is associated with the main primary vertex // However, if we are using fake vertices, this only // matters if the vertex comes from the fake set. If // it comes from the real set, remove the track anyway // because in the combined set the associated vertex // would not be the main primary vertex. remove = removeMainVertex; } else remove = true; } // Check the eta range if (!remove) { const double eta = candptr->p4().Eta(); remove = eta < etaMin || eta > etaMax; } // Should we remember this candidate? if (reverseRemovalDecision) remove = !remove; if (!remove) { const reco::PFCandidate& cand = (*pfCandidates)[i]; pOutput->push_back(cand); pOutput->back().setSourceCandidatePtr(candptr); } } iEvent.put(pOutput); }
void FFTJetPFPileupCleaner::setRemovalBit | ( | reco::PFCandidate::ParticleType | ptype, |
bool | onOff | ||
) | [private] |
Definition at line 266 of file FFTJetPFPileupCleaner.cc.
References removalMask, and edm::shift.
Referenced by buildRemovalMask().
{ const unsigned shift = static_cast<unsigned>(ptype); assert(shift < 32U); const unsigned mask = (1U << shift); if (value) removalMask |= mask; else removalMask &= ~mask; }
bool FFTJetPFPileupCleaner::checkClosestZVertex [private] |
Definition at line 83 of file FFTJetPFPileupCleaner.cc.
Referenced by findSomeVertexWFakes().
double FFTJetPFPileupCleaner::etaMax [private] |
Definition at line 119 of file FFTJetPFPileupCleaner.cc.
Referenced by produce().
double FFTJetPFPileupCleaner::etaMin [private] |
Definition at line 118 of file FFTJetPFPileupCleaner.cc.
Definition at line 75 of file FFTJetPFPileupCleaner.cc.
Referenced by produce().
bool FFTJetPFPileupCleaner::keepIfPVneighbor [private] |
Definition at line 90 of file FFTJetPFPileupCleaner.cc.
Referenced by findSomeVertexWFakes().
Definition at line 73 of file FFTJetPFPileupCleaner.cc.
Referenced by produce().
unsigned FFTJetPFPileupCleaner::removalMask [private] |
Definition at line 115 of file FFTJetPFPileupCleaner.cc.
Referenced by isRemovable(), and setRemovalBit().
bool FFTJetPFPileupCleaner::remove_e [private] |
Definition at line 107 of file FFTJetPFPileupCleaner.cc.
Referenced by buildRemovalMask().
bool FFTJetPFPileupCleaner::remove_egamma_HF [private] |
Definition at line 112 of file FFTJetPFPileupCleaner.cc.
Referenced by buildRemovalMask().
bool FFTJetPFPileupCleaner::remove_gamma [private] |
Definition at line 109 of file FFTJetPFPileupCleaner.cc.
Referenced by buildRemovalMask().
bool FFTJetPFPileupCleaner::remove_h [private] |
Definition at line 106 of file FFTJetPFPileupCleaner.cc.
Referenced by buildRemovalMask().
bool FFTJetPFPileupCleaner::remove_h0 [private] |
Definition at line 110 of file FFTJetPFPileupCleaner.cc.
Referenced by buildRemovalMask().
bool FFTJetPFPileupCleaner::remove_h_HF [private] |
Definition at line 111 of file FFTJetPFPileupCleaner.cc.
Referenced by buildRemovalMask().
bool FFTJetPFPileupCleaner::remove_mu [private] |
Definition at line 108 of file FFTJetPFPileupCleaner.cc.
Referenced by buildRemovalMask().
bool FFTJetPFPileupCleaner::remove_X [private] |
Definition at line 105 of file FFTJetPFPileupCleaner.cc.
Referenced by buildRemovalMask().
bool FFTJetPFPileupCleaner::removeMainVertex [private] |
Definition at line 94 of file FFTJetPFPileupCleaner.cc.
Referenced by produce().
bool FFTJetPFPileupCleaner::removeUnassociated [private] |
Definition at line 98 of file FFTJetPFPileupCleaner.cc.
Referenced by produce().
bool FFTJetPFPileupCleaner::reverseRemovalDecision [private] |
Definition at line 101 of file FFTJetPFPileupCleaner.cc.
Referenced by produce().
bool FFTJetPFPileupCleaner::useFakePrimaryVertex [private] |
Definition at line 79 of file FFTJetPFPileupCleaner.cc.
Referenced by findSomeVertexWFakes(), and produce().
double FFTJetPFPileupCleaner::vertexNdofCut [private] |
Definition at line 122 of file FFTJetPFPileupCleaner.cc.
Referenced by isAcceptableVtx().
double FFTJetPFPileupCleaner::vertexZmaxCut [private] |
Definition at line 125 of file FFTJetPFPileupCleaner.cc.
Referenced by isAcceptableVtx().
edm::InputTag FFTJetPFPileupCleaner::Vertices [private] |
Definition at line 74 of file FFTJetPFPileupCleaner.cc.
Referenced by produce().
std::vector<std::pair<double, unsigned> > FFTJetPFPileupCleaner::zAssoc [mutable, private] |
Definition at line 128 of file FFTJetPFPileupCleaner.cc.
Referenced by findSomeVertexWFakes().