CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

pat::PATPFParticleProducer Class Reference

Produces pat::PFParticle's. More...

#include <PhysicsTools/PatAlgos/interface/PATPFParticleProducer.h>

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

List of all members.

Public Member Functions

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

Private Member Functions

void fetchCandidateCollection (edm::Handle< edm::View< reco::PFCandidate > > &c, const edm::InputTag &tag, const edm::Event &iSetup) const

Private Attributes

bool addEfficiencies_
bool addGenMatch_
bool addResolutions_
pat::helper::EfficiencyLoader efficiencyLoader_
bool embedGenMatch_
bool embedPFCandidate_
std::vector< edm::InputTaggenMatchSrc_
edm::InputTag pfCandidateSrc_
GreaterByPt< PFParticlepTComparator_
pat::helper::KinResolutionsLoader resolutionLoader_

Detailed Description

Produces pat::PFParticle's.

The PATPFParticleProducer produces analysis-level pat::PFParticle's starting from a collection of objects of reco::PFCandidate.

Author:
Steven Lowette, Roger Wolf
Version:
Id:
PATPFParticleProducer.h,v 1.7 2010/02/20 21:00:26 wmtan Exp

Definition at line 41 of file PATPFParticleProducer.h.


Constructor & Destructor Documentation

PATPFParticleProducer::PATPFParticleProducer ( const edm::ParameterSet iConfig) [explicit]

Definition at line 26 of file PATPFParticleProducer.cc.

References addEfficiencies_, addGenMatch_, addResolutions_, efficiencyLoader_, embedGenMatch_, edm::ParameterSet::existsAs(), genMatchSrc_, edm::ParameterSet::getParameter(), pfCandidateSrc_, and resolutionLoader_.

                                                                            {
  // general configurables
  pfCandidateSrc_ = iConfig.getParameter<edm::InputTag>( "pfCandidateSource" );
 
  // MC matching configurables
  addGenMatch_   = iConfig.getParameter<bool>         ( "addGenMatch" );
  if (addGenMatch_) {
      embedGenMatch_ = iConfig.getParameter<bool>         ( "embedGenMatch" );
      if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
          genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
      } else {
          genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
      }
  }

  // Efficiency configurables
  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
  if (addEfficiencies_) {
     efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
  }

  // Resolution configurables
  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
  if (addResolutions_) {
     resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
  }



  // produces vector of muons
  produces<std::vector<PFParticle> >();

}
PATPFParticleProducer::~PATPFParticleProducer ( )

Definition at line 61 of file PATPFParticleProducer.cc.

                                              {
}

Member Function Documentation

void PATPFParticleProducer::fetchCandidateCollection ( edm::Handle< edm::View< reco::PFCandidate > > &  c,
const edm::InputTag tag,
const edm::Event iSetup 
) const [private]

Definition at line 129 of file PATPFParticleProducer.cc.

References trackerHits::c, Exception, newFWLiteAna::found, and edm::Event::getByLabel().

Referenced by produce().

                                                                               {
  
  bool found = iEvent.getByLabel(tag, c);
  
  if(!found ) {
    std::ostringstream  err;
    err<<" cannot get PFCandidates: "
       <<tag<<std::endl;
    edm::LogError("PFCandidates")<<err.str();
    throw cms::Exception( "MissingProduct", err.str());
  }
  
}
void PATPFParticleProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 65 of file PATPFParticleProducer.cc.

References addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), efficiencyLoader_, embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), pat::helper::KinResolutionsLoader::enabled(), pat::helper::EfficiencyLoader::enabled(), fetchCandidateCollection(), genMatchSrc_, edm::Event::getByLabel(), i, UserOptions_cff::idx, j, n, pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), pfParticleProducer_cfi::patPFParticles, reco::tau::pfCandidates(), pfCandidateSrc_, pTComparator_, edm::Event::put(), resolutionLoader_, pat::helper::EfficiencyLoader::setEfficiencies(), pat::helper::KinResolutionsLoader::setResolutions(), and python::multivaluedict::sort().

                                                                  {

  // Get the collection of PFCandidates from the event
  edm::Handle<edm::View<reco::PFCandidate> > pfCandidates;

  fetchCandidateCollection(pfCandidates, 
                           pfCandidateSrc_, 
                           iEvent );

  // prepare the MC matching
  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size());
  if (addGenMatch_) {
        for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
            iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
        }
  }

  if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent);
  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);

  // loop over PFCandidates
  std::vector<PFParticle> * patPFParticles = new std::vector<PFParticle>();
  for (edm::View<reco::PFCandidate>::const_iterator 
         itPFParticle = pfCandidates->begin(); 
       itPFParticle != pfCandidates->end(); 
       ++itPFParticle) {

    // construct the PFParticle from the ref -> save ref to original object
    unsigned int idx = itPFParticle - pfCandidates->begin();
    edm::RefToBase<reco::PFCandidate> pfCandidatesRef = pfCandidates->refAt(idx);

    PFParticle aPFParticle(pfCandidatesRef);

    if (addGenMatch_) {
      for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
          reco::GenParticleRef genPFParticle = (*genMatches[i])[pfCandidatesRef];
          aPFParticle.addGenParticleRef(genPFParticle);
      }
      if (embedGenMatch_) aPFParticle.embedGenParticle();
    }
      
    if (efficiencyLoader_.enabled()) {
        efficiencyLoader_.setEfficiencies( aPFParticle, pfCandidatesRef );
    }

    if (resolutionLoader_.enabled()) {
        resolutionLoader_.setResolutions(aPFParticle);
    }

    // add sel to selected
    patPFParticles->push_back(aPFParticle);
  }

  // sort pfCandidates in pt
  std::sort(patPFParticles->begin(), patPFParticles->end(), pTComparator_);

  // put genEvt object in Event
  std::auto_ptr<std::vector<PFParticle> > ptr(patPFParticles);
  iEvent.put(ptr);

}

Member Data Documentation

Definition at line 65 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

Definition at line 59 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

Definition at line 68 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

Definition at line 66 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

Definition at line 60 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

Definition at line 58 of file PATPFParticleProducer.h.

Definition at line 61 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

Definition at line 57 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

Definition at line 63 of file PATPFParticleProducer.h.

Referenced by produce().

Definition at line 69 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().