CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

pat::MatcherUsingTracks Class Reference

Matcher of reconstructed objects to other reconstructed objects using the tracks inside them. More...

Inheritance diagram for pat::MatcherUsingTracks:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 MatcherUsingTracks (const edm::ParameterSet &iConfig)
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual ~MatcherUsingTracks ()

Private Member Functions

template<typename T >
void storeValueMap (edm::Event &iEvent, const edm::Handle< edm::View< reco::Candidate > > &handle, const std::vector< T > &values, const std::string &label) const
 Store extra information in a ValueMap.

Private Attributes

MatcherUsingTracksAlgorithm algo_
 The real workhorse.
bool dontFailOnMissingInput_
 Some extra configurables.
edm::InputTag matched_
edm::InputTag src_
 Labels for input collections.
bool writeExtraPATOutput_

Detailed Description

Matcher of reconstructed objects to other reconstructed objects using the tracks inside them.

Author:
Giovanni Petrucciani
Version:
Id:
MatcherUsingTracks.cc,v 1.5 2010/07/12 20:56:11 gpetrucc Exp

Definition at line 32 of file MatcherUsingTracks.cc.


Constructor & Destructor Documentation

pat::MatcherUsingTracks::MatcherUsingTracks ( const edm::ParameterSet iConfig) [explicit]

Definition at line 61 of file MatcherUsingTracks.cc.

References algo_, and writeExtraPATOutput_.

                                                                         :
    src_(iConfig.getParameter<edm::InputTag>("src")),
    matched_(iConfig.getParameter<edm::InputTag>("matched")),
    algo_(iConfig),
    dontFailOnMissingInput_(iConfig.existsAs<bool>("dontFailOnMissingInput") ? iConfig.getParameter<bool>("dontFailOnMissingInput") : false),
    writeExtraPATOutput_(iConfig.existsAs<bool>("writeExtraPATOutput") ? iConfig.getParameter<bool>("writeExtraPATOutput") : false)
{
    // this is the basic output (edm::Association is not generic)
    produces<edm::ValueMap<reco::CandidatePtr> >(); 
    if (writeExtraPATOutput_) {
        // this is the crazy stuff to get the same with UserData
        produces<edm::OwnVector<pat::UserData> >();
        produces<edm::ValueMap<edm::Ptr<pat::UserData> > >();
    }
    // this is the extra stuff
    if (algo_.hasMetrics()) {
        produces<edm::ValueMap<float> >("deltaR");
        produces<edm::ValueMap<float> >("deltaEta");
        produces<edm::ValueMap<float> >("deltaPhi");
        produces<edm::ValueMap<float> >("deltaLocalPos");
        produces<edm::ValueMap<float> >("deltaPtRel");
        if (algo_.hasChi2()) {
            produces<edm::ValueMap<float> >("chi2");
        }
    } else {
        produces<edm::ValueMap<int> >("matched");
    }
}
virtual pat::MatcherUsingTracks::~MatcherUsingTracks ( ) [inline, virtual]

Definition at line 35 of file MatcherUsingTracks.cc.

{ }

Member Function Documentation

void pat::MatcherUsingTracks::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 91 of file MatcherUsingTracks.cc.

References edm::Event::getByLabel(), iEvent, pat::UserData::make(), match(), edm::Event::put(), and alcazmumu_cfi::src.

                                                                              {
    using namespace edm;
    using namespace std;

    algo_.init(iSetup);

    Handle<View<reco::Candidate> > src, matched;

    iEvent.getByLabel(src_, src);
    iEvent.getByLabel(matched_, matched);

    // declare loop variables and some intermediate stuff
    View<reco::Candidate>::const_iterator itsrc, edsrc;
    int isrc, nsrc = src->size();

    // working and output variables
    vector<int>   match(nsrc, -1);
    vector<float> deltaRs(nsrc, 999);
    vector<float> deltaEtas(nsrc, 999);
    vector<float> deltaPhis(nsrc, 999);
    vector<float> deltaPtRel(nsrc, 999);
    vector<float> deltaLocalPos(nsrc, 999);
    vector<float> chi2(nsrc, 999999);

    // don't try matching if the input collection is missing and the module is configured to fail silently
    if (!(matched.failedToGet() && dontFailOnMissingInput_)) {
        // loop on the source collection, and request for the match
        for (itsrc = src->begin(), edsrc = src->end(), isrc = 0; itsrc != edsrc; ++itsrc, ++isrc) {
            match[isrc] = algo_.match(*itsrc, *matched, deltaRs[isrc], deltaEtas[isrc], deltaPhis[isrc], deltaLocalPos[isrc], deltaPtRel[isrc], chi2[isrc]); 
        }
    }

    std::vector<reco::CandidatePtr> ptrs(nsrc);
    for (isrc = 0; isrc < nsrc; ++isrc) {
        if (match[isrc] != -1) {
            ptrs[isrc] = matched->ptrAt(match[isrc]);
        }
    }
    storeValueMap<reco::CandidatePtr>(iEvent, src, ptrs, "");

    if (writeExtraPATOutput_) {
        std::auto_ptr<edm::OwnVector<pat::UserData> > outUDVect(new edm::OwnVector<pat::UserData>());
        std::vector<int>                              idxUD(nsrc, -1);
        for (isrc = 0; isrc < nsrc; ++isrc) {
            if (match[isrc] != -1) {
                outUDVect->push_back(pat::UserData::make(ptrs[isrc]));
                idxUD[isrc] = outUDVect->size() - 1; 
            }
        }
        edm::OrphanHandle<edm::OwnVector<pat::UserData> > doneUDVect = iEvent.put(outUDVect);
        std::vector<edm::Ptr<pat::UserData> > ptrUD(nsrc);
        for (isrc = 0; isrc < nsrc; ++isrc) {
            if (idxUD[isrc] != -1) ptrUD[isrc] = edm::Ptr<pat::UserData>(doneUDVect, idxUD[isrc]);
        }
        storeValueMap<edm::Ptr<pat::UserData> >(iEvent, src, ptrUD, "");
    }

    if (algo_.hasMetrics()) {
        storeValueMap<float>(iEvent, src, deltaRs,   "deltaR");
        storeValueMap<float>(iEvent, src, deltaEtas, "deltaEta");
        storeValueMap<float>(iEvent, src, deltaPhis, "deltaPhi");
        storeValueMap<float>(iEvent, src, deltaLocalPos, "deltaLocalPos");
        storeValueMap<float>(iEvent, src, deltaPtRel,    "deltaPtRel");
        if (algo_.hasChi2()) {
            storeValueMap<float>(iEvent, src, chi2, "chi2");
        }
    } else  {
        std::vector<int> ismatched(nsrc, 0);
        for (isrc = 0; isrc < nsrc; ++isrc) {
            ismatched[isrc] = (match[isrc] != -1);
        }
        storeValueMap<int>(iEvent, src, ismatched, "matched");
    }
}
template<typename T >
void pat::MatcherUsingTracks::storeValueMap ( edm::Event iEvent,
const edm::Handle< edm::View< reco::Candidate > > &  handle,
const std::vector< T > &  values,
const std::string &  label 
) const [private]

Store extra information in a ValueMap.

Definition at line 168 of file MatcherUsingTracks.cc.

References edm::helper::Filler< Map >::fill(), patZpeak::handle, edm::helper::Filler< Map >::insert(), and edm::Event::put().

                                                       {
    using namespace edm; using namespace std;
    auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
    typename edm::ValueMap<T>::Filler filler(*valMap);
    filler.insert(handle, values.begin(), values.end());
    filler.fill();
    iEvent.put(valMap, label);
}

Member Data Documentation

The real workhorse.

Definition at line 44 of file MatcherUsingTracks.cc.

Referenced by MatcherUsingTracks().

Some extra configurables.

Definition at line 47 of file MatcherUsingTracks.cc.

Definition at line 41 of file MatcherUsingTracks.cc.

Labels for input collections.

Definition at line 41 of file MatcherUsingTracks.cc.

Definition at line 48 of file MatcherUsingTracks.cc.

Referenced by MatcherUsingTracks().