CMS 3D CMS Logo

Public Member Functions | Private Attributes

pat::PATGenericParticleProducer Class Reference

Produces the pat::GenericParticle. More...

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

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

List of all members.

Public Member Functions

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

Private Attributes

bool addEfficiencies_
bool addGenMatch_
bool addQuality_
bool addResolutions_
pat::helper::EfficiencyLoader efficiencyLoader_
bool embedCaloTower_
bool embedCombined_
bool embedGenMatch_
bool embedGsfTrack_
bool embedStandalone_
bool embedSuperCluster_
bool embedTrack_
bool embedTracks_
GreaterByEt< GenericParticleeTComparator_
std::vector< edm::InputTaggenMatchSrc_
std::vector< std::pair
< pat::IsolationKeys,
edm::InputTag > > 
isoDepositLabels_
pat::helper::MultiIsolator isolator_
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
edm::InputTag qualitySrc_
pat::helper::KinResolutionsLoader resolutionLoader_
edm::InputTag src_
pat::PATUserDataHelper
< pat::GenericParticle
userDataHelper_
bool useUserData_
pat::helper::VertexingHelper vertexingHelper_

Detailed Description

Produces the pat::GenericParticle.

The PATGenericParticleProducer produces the analysis-level pat::GenericParticle starting from any collection of Candidates

Author:
Giovanni Petrucciani
Version:
Id:
PATGenericParticleProducer.h,v 1.9 2009/06/25 23:49:35 gpetrucc Exp

Definition at line 43 of file PATGenericParticleProducer.h.


Constructor & Destructor Documentation

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

Definition at line 12 of file PATGenericParticleProducer.cc.

References addEfficiencies_, addGenMatch_, addQuality_, addResolutions_, pat::EcalIso, efficiencyLoader_, embedCaloTower_, embedCombined_, embedGenMatch_, embedGsfTrack_, embedStandalone_, embedSuperCluster_, embedTrack_, embedTracks_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), genMatchSrc_, edm::ParameterSet::getParameter(), pat::HcalIso, isoDepositLabels_, combine::key, qualitySrc_, resolutionLoader_, src_, pat::TrackIso, pat::UserBaseIso, useUserData_, and vertexingHelper_.

                                                                                      :
  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), false),
  userDataHelper_ ( iConfig.getParameter<edm::ParameterSet>("userData") )
{
  // initialize the configurables
  src_ = iConfig.getParameter<edm::InputTag>( "src" );

  // RECO embedding
  embedTrack_        = iConfig.getParameter<bool>( "embedTrack" );
  embedGsfTrack_     = iConfig.getParameter<bool>( "embedGsfTrack" );
  embedStandalone_   = iConfig.getParameter<bool>( "embedStandAloneMuon" );
  embedCombined_     = iConfig.getParameter<bool>( "embedCombinedMuon" );
  embedSuperCluster_ = iConfig.getParameter<bool>( "embedSuperCluster" );
  embedTracks_       = iConfig.getParameter<bool>( "embedMultipleTracks" );
  embedCaloTower_    = iConfig.getParameter<bool>( "embedCaloTower" );
  
  // 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" );
      }
  }

  // quality
  addQuality_ = iConfig.getParameter<bool>("addQuality");
  qualitySrc_ = iConfig.getParameter<edm::InputTag>("qualitySource");

  // produces vector of particles
  produces<std::vector<GenericParticle> >();

  if (iConfig.exists("isoDeposits")) {
     edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
     if (depconf.exists("tracker")) isoDepositLabels_.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
     if (depconf.exists("ecal"))    isoDepositLabels_.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
     if (depconf.exists("hcal"))    isoDepositLabels_.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
     if (depconf.exists("user")) {
        std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
        std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
        int key = UserBaseIso;
        for ( ; it != ed; ++it, ++key) {
            isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
        }
     }
  }

  // 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"));
  }

  if (iConfig.exists("vertexing")) {
     vertexingHelper_ = pat::helper::VertexingHelper(iConfig.getParameter<edm::ParameterSet>("vertexing")); 
  }

  // Check to see if the user wants to add user data
  useUserData_ = false;
  if ( iConfig.exists("userData") ) {
    useUserData_ = true;
  }
}
PATGenericParticleProducer::~PATGenericParticleProducer ( )

Definition at line 84 of file PATGenericParticleProducer.cc.

                                                        {
}

Member Function Documentation

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

Implements edm::EDProducer.

Definition at line 87 of file PATGenericParticleProducer.cc.

References pat::PATUserDataHelper< ObjectType >::add(), addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), addQuality_, pat::helper::MultiIsolator::beginEvent(), ExpressReco_HICollisions_FallBack::deposits, efficiencyLoader_, pat::GenericParticle::embedCaloTower(), embedCaloTower_, pat::GenericParticle::embedCombined(), embedCombined_, embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), pat::GenericParticle::embedGsfTrack(), embedGsfTrack_, pat::GenericParticle::embedStandalone(), embedStandalone_, pat::GenericParticle::embedSuperCluster(), embedSuperCluster_, pat::GenericParticle::embedTrack(), embedTrack_, pat::GenericParticle::embedTracks(), embedTracks_, pat::helper::KinResolutionsLoader::enabled(), pat::helper::MultiIsolator::enabled(), pat::helper::VertexingHelper::enabled(), pat::helper::EfficiencyLoader::enabled(), pat::helper::MultiIsolator::endEvent(), eTComparator_, pat::helper::MultiIsolator::fill(), first, genMatchSrc_, edm::Event::getByLabel(), i, isoDepositLabels_, isolator_, isolatorTmpStorage_, j, n, pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), pat::helper::VertexingHelper::newEvent(), edm::Event::put(), qualitySrc_, resolutionLoader_, edm::second(), pat::helper::EfficiencyLoader::setEfficiencies(), pat::GenericParticle::setIsoDeposit(), pat::GenericParticle::setIsolation(), pat::GenericParticle::setQuality(), pat::helper::KinResolutionsLoader::setResolutions(), pat::GenericParticle::setVertexAssociation(), python::multivaluedict::sort(), src_, userDataHelper_, useUserData_, and vertexingHelper_.

                                                                                        {
  // Get the vector of GenericParticle's from the event
  edm::Handle<edm::View<reco::Candidate> > cands;
  iEvent.getByLabel(src_, cands);

  // prepare isolation
  if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);

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

  // prepare IsoDeposits
  std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositLabels_.size());
  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
    iEvent.getByLabel(isoDepositLabels_[j].second, deposits[j]);
  }

  // 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]);
        }
  }

  // prepare the quality
  edm::Handle<edm::ValueMap<float> > qualities;
  if (addQuality_) iEvent.getByLabel(qualitySrc_, qualities);

  // loop over cands
  std::vector<GenericParticle> * PATGenericParticles = new std::vector<GenericParticle>(); 
  for (edm::View<reco::Candidate>::const_iterator itGenericParticle = cands->begin(); itGenericParticle != cands->end(); itGenericParticle++) {
    // construct the GenericParticle from the ref -> save ref to original object
    unsigned int idx = itGenericParticle - cands->begin();
    edm::RefToBase<reco::Candidate> candRef = cands->refAt(idx);

    PATGenericParticles->push_back(GenericParticle(candRef));
    GenericParticle & aGenericParticle = PATGenericParticles->back();

    // embed RECO
    if (embedTrack_)        aGenericParticle.embedTrack();
    if (embedGsfTrack_)     aGenericParticle.embedGsfTrack();
    if (embedTracks_)       aGenericParticle.embedTracks();
    if (embedStandalone_)   aGenericParticle.embedStandalone();
    if (embedCombined_)     aGenericParticle.embedCombined();
    if (embedSuperCluster_) aGenericParticle.embedSuperCluster();
    if (embedCaloTower_)    aGenericParticle.embedCaloTower();

    // isolation
    if (isolator_.enabled()) {
        isolator_.fill(*cands, idx, isolatorTmpStorage_);
        typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
        // better to loop backwards, so the vector is resized less times
        for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
            aGenericParticle.setIsolation(it->first, it->second);
        }
    }

    // isodeposit
    for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
        aGenericParticle.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[candRef]);
    }

    // store the match to the generated final state muons
    if (addGenMatch_) {
      for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
          reco::GenParticleRef genGenericParticle = (*genMatches[i])[candRef];
          aGenericParticle.addGenParticleRef(genGenericParticle);
      }
      if (embedGenMatch_) aGenericParticle.embedGenParticle();
    }

    if (addQuality_) {
      aGenericParticle.setQuality( (*qualities)[candRef] );
    }

    if (efficiencyLoader_.enabled()) {
        efficiencyLoader_.setEfficiencies( aGenericParticle, candRef );
    }

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

    if (vertexingHelper_.enabled()) {
        aGenericParticle.setVertexAssociation( vertexingHelper_(candRef) );
    }

    if ( useUserData_ ) {
        userDataHelper_.add( aGenericParticle, iEvent, iSetup );
    }

    // PATGenericParticles->push_back(aGenericParticle); // NOOOOO!!!!
    // We have already pushed_back this generic particle in the collection
    // (we first push an empty particle and then fill it, to avoid useless copies)
  }

  // sort GenericParticles in ET
  std::sort(PATGenericParticles->begin(), PATGenericParticles->end(), eTComparator_);

  // put genEvt object in Event
  std::auto_ptr<std::vector<GenericParticle> > myGenericParticles(PATGenericParticles);
  iEvent.put(myGenericParticles);
  if (isolator_.enabled()) isolator_.endEvent();

}

Member Data Documentation

Definition at line 74 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer().

Definition at line 63 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 60 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 77 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer().

Definition at line 75 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 58 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 58 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 64 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 58 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 58 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 58 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 58 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 58 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 68 of file PATGenericParticleProducer.h.

Referenced by produce().

Definition at line 65 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 72 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 70 of file PATGenericParticleProducer.h.

Referenced by produce().

Definition at line 71 of file PATGenericParticleProducer.h.

Referenced by produce().

Definition at line 61 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 78 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 55 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 83 of file PATGenericParticleProducer.h.

Referenced by produce().

Definition at line 82 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().

Definition at line 80 of file PATGenericParticleProducer.h.

Referenced by PATGenericParticleProducer(), and produce().