CMS 3D CMS Logo

Public Types | Public Member Functions | Private Attributes

RecoTauJetRegionProducer Class Reference

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

List of all members.

Public Types

typedef edm::Association
< reco::PFJetCollection
PFJetMatchMap

Public Member Functions

void produce (edm::Event &evt, const edm::EventSetup &es)
 RecoTauJetRegionProducer (const edm::ParameterSet &pset)
 ~RecoTauJetRegionProducer ()

Private Attributes

double deltaR_
edm::InputTag inputJets_
edm::InputTag pfSrc_

Detailed Description

Definition at line 26 of file RecoTauJetRegionProducer.cc.


Member Typedef Documentation

Definition at line 28 of file RecoTauJetRegionProducer.cc.


Constructor & Destructor Documentation

RecoTauJetRegionProducer::RecoTauJetRegionProducer ( const edm::ParameterSet pset) [explicit]

Definition at line 38 of file RecoTauJetRegionProducer.cc.

References deltaR_, edm::ParameterSet::getParameter(), inputJets_, and pfSrc_.

                                 {
  deltaR_ = pset.getParameter<double>("deltaR");
  inputJets_ = pset.getParameter<edm::InputTag>("src");
  pfSrc_ = pset.getParameter<edm::InputTag>("pfSrc");
  produces<reco::PFJetCollection>("jets");
  produces<PFJetMatchMap>();
}
RecoTauJetRegionProducer::~RecoTauJetRegionProducer ( ) [inline]

Definition at line 30 of file RecoTauJetRegionProducer.cc.

{}

Member Function Documentation

void RecoTauJetRegionProducer::produce ( edm::Event evt,
const edm::EventSetup es 
) [virtual]

Implements edm::EDProducer.

Definition at line 47 of file RecoTauJetRegionProducer.cc.

References reco::CompositePtrCandidate::addDaughter(), reco::CompositePtrCandidate::clearDaughters(), deltaR_, alignCSCRings::e, edm::helper::Filler< Map >::fill(), alcazmumu_cfi::filter, edm::Event::get(), edm::Event::getByLabel(), edm::RefVector< C, T, F >::id(), inputJets_, edm::helper::Filler< Map >::insert(), analyzePatCleaning_cfg::jets, edm::Ref< C, T, F >::key(), pfSrc_, edm::Event::put(), and edm::RefVector< C, T, F >::size().

                             {

  edm::Handle<reco::PFCandidateCollection> pfCandsHandle;
  evt.getByLabel(pfSrc_, pfCandsHandle);

  // Build Ptrs for all the PFCandidates
  typedef edm::Ptr<reco::PFCandidate> PFCandPtr;
  std::vector<PFCandPtr> pfCands;
  pfCands.reserve(pfCandsHandle->size());
  for (size_t icand = 0; icand < pfCandsHandle->size(); ++icand) {
    pfCands.push_back(PFCandPtr(pfCandsHandle, icand));
  }

  // Get the jets
  edm::Handle<reco::CandidateView> jetView;
  evt.getByLabel(inputJets_, jetView);
  // Convert to a vector of PFJetRefs
  reco::PFJetRefVector jets =
      reco::tau::castView<reco::PFJetRefVector>(jetView);
  size_t nJets = jets.size();

  // Get the original product, so we can match against it - otherwise the
  // indices don't match up.
  edm::ProductID originalId = jets.id();
  edm::Handle<reco::PFJetCollection> originalJets;
  size_t nOriginalJets = 0;
  // We have to make sure that we have some selected jets, otherwise we don't
  // actually have a valid product ID to the original jets.
  if (nJets) {
    try {
      evt.get(originalId, originalJets);
    } catch(const cms::Exception &e) {
      edm::LogError("MissingOriginalCollection")
        << "Can't get the original jets that made: " << inputJets_
        << " that have product ID: " << originalId
        << " from the event!!";
      throw e;
    }
    nOriginalJets = originalJets->size();
  }

  std::auto_ptr<reco::PFJetCollection> newJets(new reco::PFJetCollection);

  // Keep track of the indices of the current jet and the old (original) jet
  // -1 indicats no match.
  std::vector<int> matchInfo(nOriginalJets, -1);

  for (size_t ijet = 0; ijet < nJets; ++ijet) {
    // Get a ref to jet
    reco::PFJetRef jetRef = jets[ijet];
    // Make an initial copy.
    reco::PFJet newJet(*jetRef);
    // Clear out all the constituents
    newJet.clearDaughters();
    // Build a DR cone filter about our jet
    reco::tau::cone::DeltaRPtrFilter<PFCandPtr>
      filter(jetRef->p4(), 0, deltaR_);

    // Loop over all the PFCands
    std::for_each(
        // filtering those that don't pass our filter
        boost::make_filter_iterator(filter,
          pfCands.begin(), pfCands.end()),
        boost::make_filter_iterator(filter,
          pfCands.end(), pfCands.end()),
        // For the ones that do, call newJet.addDaughter(..) on them
        boost::bind(&reco::PFJet::addDaughter, boost::ref(newJet), _1));
    newJets->push_back(newJet);
    // Match the index of the jet we just made to the index into the original
    // collection.
    matchInfo[jetRef.key()] = ijet;
  }

  // Put our new jets into the event
  edm::OrphanHandle<reco::PFJetCollection> newJetsInEvent =
    evt.put(newJets, "jets");

  // Create a matching between original jets -> extra collection
  std::auto_ptr<PFJetMatchMap> matching(new PFJetMatchMap(newJetsInEvent));
  if (nJets) {
    PFJetMatchMap::Filler filler(*matching);
    filler.insert(originalJets, matchInfo.begin(), matchInfo.end());
    filler.fill();
  }
  evt.put(matching);
}

Member Data Documentation

Definition at line 33 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

Definition at line 34 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

Definition at line 35 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().