CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

FFTJetPFPileupCleaner Class Reference

#include <RecoJets/FFTJetProducers/plugins/FFTJetPFPileupCleaner.cc>

Inheritance diagram for FFTJetPFPileupCleaner:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 FFTJetPFPileupCleaner (const edm::ParameterSet &)
 ~FFTJetPFPileupCleaner ()

Protected Member Functions

void beginJob ()
void endJob ()
void produce (edm::Event &, const edm::EventSetup &)

Private Member Functions

void buildRemovalMask ()
 FFTJetPFPileupCleaner (const FFTJetPFPileupCleaner &)
 FFTJetPFPileupCleaner ()
reco::VertexRef findSomeVertex (const edm::Handle< reco::VertexCollection > &vertices, const reco::PFCandidate &pfcand) const
bool isRemovable (reco::PFCandidate::ParticleType ptype) const
FFTJetPFPileupCleaneroperator= (const FFTJetPFPileupCleaner &)
void setRemovalBit (reco::PFCandidate::ParticleType ptype, bool onOff)

Private Attributes

bool checkClosestZVertex
double etaMax
double etaMin
edm::InputTag PFCandidates
unsigned removalMask
bool remove_e
bool remove_egamma_HF
bool remove_gamma
bool remove_h
bool remove_h0
bool remove_h_HF
bool remove_mu
bool remove_X
bool removeMainVertex
bool removeUnassociated
bool reverseRemovalDecision
double vertexNdofCut
edm::InputTag Vertices

Detailed Description

Description: cleans up a collection of partice flow objects

Implementation: [Notes on implementation]

Definition at line 42 of file FFTJetPFPileupCleaner.cc.


Constructor & Destructor Documentation

FFTJetPFPileupCleaner::FFTJetPFPileupCleaner ( const edm::ParameterSet ps) [explicit]
FFTJetPFPileupCleaner::~FFTJetPFPileupCleaner ( )

Definition at line 135 of file FFTJetPFPileupCleaner.cc.

{
}
FFTJetPFPileupCleaner::FFTJetPFPileupCleaner ( ) [private]
FFTJetPFPileupCleaner::FFTJetPFPileupCleaner ( const FFTJetPFPileupCleaner ) [private]

Member Function Documentation

void FFTJetPFPileupCleaner::beginJob ( void  ) [protected, virtual]

Reimplemented from edm::EDProducer.

Definition at line 316 of file FFTJetPFPileupCleaner.cc.

{
}
void FFTJetPFPileupCleaner::buildRemovalMask ( ) [private]
void FFTJetPFPileupCleaner::endJob ( void  ) [protected, virtual]

Reimplemented from edm::EDProducer.

Definition at line 322 of file FFTJetPFPileupCleaner.cc.

{
}
reco::VertexRef FFTJetPFPileupCleaner::findSomeVertex ( const edm::Handle< reco::VertexCollection > &  vertices,
const reco::PFCandidate pfcand 
) const [private]

Definition at line 218 of file FFTJetPFPileupCleaner.cc.

References checkClosestZVertex, getHLTprescales::index, reco::PFCandidate::trackRef(), reco::Vertex::tracks_begin(), reco::Vertex::tracks_end(), reco::Vertex::trackWeight(), reco::PFCandidate::vertex(), vertexNdofCut, and w().

Referenced by produce().

{  
    typedef reco::VertexCollection::const_iterator IV;
    typedef reco::Vertex::trackRef_iterator IT;

    reco::TrackBaseRef trackBaseRef(pfcand.trackRef());

    size_t iVertex = 0;
    unsigned index = 0;
    unsigned nFoundVertex = 0;
    double bestweight = 0;

    const IV vertend(vertices->end());
    for (IV iv=vertices->begin(); iv!=vertend; ++iv, ++index)
    {
        const double ndof = iv->ndof();
        if (!iv->isFake() && ndof > vertexNdofCut)
        {
            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";
        return reco::VertexRef(vertices, iVertex);
    }

    // optional: as a secondary solution, associate the closest vertex in z
    if (checkClosestZVertex) 
    {
        double dzmin = 10000;
        double ztrack = pfcand.vertex().z();
        bool foundVertex = false;
        index = 0;
        for (IV iv=vertices->begin(); iv!=vertend; ++iv, ++index)
        {
            const double ndof = iv->ndof();
            if (!iv->isFake() && ndof > vertexNdofCut)
            {
                const double dz = fabs(ztrack - iv->z());
                if (dz < dzmin)
                {
                    dzmin = dz; 
                    iVertex = index;
                    foundVertex = true;
                }
            }
        }

        if (foundVertex) 
            return reco::VertexRef(vertices, iVertex);
    }

    return reco::VertexRef();
}
bool FFTJetPFPileupCleaner::isRemovable ( reco::PFCandidate::ParticleType  ptype) const [private]

Definition at line 194 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 141 of file FFTJetPFPileupCleaner.cc.

References eta(), etaMax, findSomeVertex(), edm::Event::getByLabel(), i, edm::Ref< C, T, F >::isNull(), isRemovable(), edm::Ref< C, T, F >::key(), PFCandidates, reco::tau::pfCandidates(), edm::Event::put(), removeMainVertex, removeUnassociated, reverseRemovalDecision, reco::PFCandidate::setSourceCandidatePtr(), 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);

    const unsigned ncand = pfCandidates->size();
    for (unsigned i=0; i<ncand; ++i)
    {
        reco::PFCandidatePtr candptr(pfCandidates, i);
        bool remove = false;

        if (isRemovable(candptr->particleId()))
        {
            reco::VertexRef vertexref(findSomeVertex(vertices, *candptr));
            if (vertexref.isNull())
                remove = removeUnassociated;
            else if (vertexref.key() == 0)
                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 203 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;
}

Member Data Documentation

Definition at line 72 of file FFTJetPFPileupCleaner.cc.

Referenced by findSomeVertex().

Definition at line 101 of file FFTJetPFPileupCleaner.cc.

Referenced by produce().

Definition at line 100 of file FFTJetPFPileupCleaner.cc.

Definition at line 67 of file FFTJetPFPileupCleaner.cc.

Referenced by produce().

Definition at line 97 of file FFTJetPFPileupCleaner.cc.

Referenced by isRemovable(), and setRemovalBit().

Definition at line 89 of file FFTJetPFPileupCleaner.cc.

Referenced by buildRemovalMask().

Definition at line 94 of file FFTJetPFPileupCleaner.cc.

Referenced by buildRemovalMask().

Definition at line 91 of file FFTJetPFPileupCleaner.cc.

Referenced by buildRemovalMask().

Definition at line 88 of file FFTJetPFPileupCleaner.cc.

Referenced by buildRemovalMask().

Definition at line 92 of file FFTJetPFPileupCleaner.cc.

Referenced by buildRemovalMask().

Definition at line 93 of file FFTJetPFPileupCleaner.cc.

Referenced by buildRemovalMask().

Definition at line 90 of file FFTJetPFPileupCleaner.cc.

Referenced by buildRemovalMask().

Definition at line 87 of file FFTJetPFPileupCleaner.cc.

Referenced by buildRemovalMask().

Definition at line 76 of file FFTJetPFPileupCleaner.cc.

Referenced by produce().

Definition at line 80 of file FFTJetPFPileupCleaner.cc.

Referenced by produce().

Definition at line 83 of file FFTJetPFPileupCleaner.cc.

Referenced by produce().

Definition at line 104 of file FFTJetPFPileupCleaner.cc.

Referenced by findSomeVertex().

Definition at line 68 of file FFTJetPFPileupCleaner.cc.

Referenced by produce().