CMS 3D CMS Logo

Public Types | Public Member Functions | Private Attributes

RecoTauProducer Class Reference

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

List of all members.

Public Types

typedef
reco::tau::RecoTauBuilderPlugin 
Builder
typedef boost::ptr_vector
< Builder
BuilderList
typedef
reco::tau::RecoTauModifierPlugin 
Modifier
typedef boost::ptr_vector
< Modifier
ModifierList

Public Member Functions

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

Private Attributes

BuilderList builders_
bool buildNullTaus_
edm::InputTag jetRegionSrc_
edm::InputTag jetSrc_
ModifierList modifiers_
std::auto_ptr
< StringCutObjectSelector
< reco::PFTau > > 
outputSelector_
edm::InputTag piZeroSrc_

Detailed Description

Definition at line 41 of file RecoTauProducer.cc.


Member Typedef Documentation

Definition at line 43 of file RecoTauProducer.cc.

typedef boost::ptr_vector<Builder> RecoTauProducer::BuilderList

Definition at line 45 of file RecoTauProducer.cc.

Definition at line 44 of file RecoTauProducer.cc.

typedef boost::ptr_vector<Modifier> RecoTauProducer::ModifierList

Definition at line 46 of file RecoTauProducer.cc.


Constructor & Destructor Documentation

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

Definition at line 66 of file RecoTauProducer.cc.

References builders_, buildNullTaus_, SurfaceDeformationFactory::create(), edm::ParameterSet::exists(), reco::get(), edm::ParameterSet::getParameter(), jetRegionSrc_, jetSrc_, modifiers_, outputSelector_, piZeroSrc_, and corrVsCorr::selection.

                                                            {
  jetSrc_ = pset.getParameter<edm::InputTag>("jetSrc");
  jetRegionSrc_ = pset.getParameter<edm::InputTag>("jetRegionSrc");
  piZeroSrc_ = pset.getParameter<edm::InputTag>("piZeroSrc");

  typedef std::vector<edm::ParameterSet> VPSet;
  // Get each of our tau builders
  const VPSet& builders = pset.getParameter<VPSet>("builders");
  for (VPSet::const_iterator builderPSet = builders.begin();
      builderPSet != builders.end(); ++builderPSet) {
    // Get plugin name
    const std::string& pluginType =
        builderPSet->getParameter<std::string>("plugin");
    const std::string& pluginName =
        builderPSet->getParameter<std::string>("name");
    // Build the plugin
    try {
      builders_.push_back(
          RecoTauBuilderPluginFactory::get()->create(
            pluginType, *builderPSet));
    } catch (...) {
      edm::LogError("RecoTauBuilderException")
        << "Exception when building a RecoTauBuilder plugin of type: "
        << pluginType << " name: " << pluginName << std::endl;
      throw; // rethrow
    }
  }

  const VPSet& modfiers = pset.getParameter<VPSet>("modifiers");
  for (VPSet::const_iterator modfierPSet = modfiers.begin();
      modfierPSet != modfiers.end(); ++modfierPSet) {
    // Get plugin name
    const std::string& pluginType =
        modfierPSet->getParameter<std::string>("plugin");
    const std::string& pluginName =
        modfierPSet->getParameter<std::string>("name");
    // Build the plugin
    try {
      modifiers_.push_back(
          RecoTauModifierPluginFactory::get()->create(
            pluginType, *modfierPSet));
    } catch (...) {
      edm::LogError("RecoTauModifierException")
        << "Exception when building a RecoTauModifier plugin of type: "
        << pluginType << " name: " << pluginName << std::endl;
      throw; // rethrow
    }
  }

  // Check if we want to apply a final output selection
  if (pset.exists("outputSelection")) {
    std::string selection = pset.getParameter<std::string>("outputSelection");
    if (selection != "") {
      outputSelector_.reset(
          new StringCutObjectSelector<reco::PFTau>(selection));
    }
  }
  buildNullTaus_ = pset.getParameter<bool>("buildNullTaus");
  produces<reco::PFTauCollection>();
}
RecoTauProducer::~RecoTauProducer ( ) [inline]

Definition at line 49 of file RecoTauProducer.cc.

{}

Member Function Documentation

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

Implements edm::EDProducer.

Definition at line 127 of file RecoTauProducer.cc.

References builders_, buildNullTaus_, Exception, edm::Event::getByLabel(), edm::Ref< C, T, F >::id(), edm::Ref< C, T, F >::isNull(), jetRegionSrc_, analyzePatCleaning_cfg::jets, jetSrc_, modifiers_, convertSQLitetoXML_cfg::output, outputSelector_, piZeroSrc_, edm::Event::put(), reco::PFTau::setjetRef(), python::multivaluedict::sort(), and metsig::tau.

                                                                    {
  // Get the jet input collection via a view of Candidates
  edm::Handle<reco::CandidateView> jetView;
  evt.getByLabel(jetSrc_, jetView);

  // Convert to a vector of PFJetRefs
  reco::PFJetRefVector jets =
      reco::tau::castView<reco::PFJetRefVector>(jetView);

  // Get the jet region producer
  edm::Handle<edm::Association<reco::PFJetCollection> > jetRegionHandle;
  evt.getByLabel(jetRegionSrc_, jetRegionHandle);

  // Get the pizero input collection
  edm::Handle<reco::JetPiZeroAssociation> piZeroAssoc;
  evt.getByLabel(piZeroSrc_, piZeroAssoc);

  // Update all our builders and modifiers with the event info
  for (BuilderList::iterator builder = builders_.begin();
      builder != builders_.end(); ++builder) {
    builder->setup(evt, es);
  }
  for (ModifierList::iterator modifier = modifiers_.begin();
      modifier != modifiers_.end(); ++modifier) {
    modifier->setup(evt, es);
  }

  // Create output collection
  std::auto_ptr<reco::PFTauCollection> output(new reco::PFTauCollection());

  // Loop over the jets and build the taus for each jet
  BOOST_FOREACH(reco::PFJetRef jetRef, jets) {
    // Get the jet with extra constituents from an area around the jet
    reco::PFJetRef jetRegionRef = (*jetRegionHandle)[jetRef];
    if (jetRegionRef.isNull()) {
      throw cms::Exception("BadJetRegionRef") << "No jet region can be"
        << " found for the current jet: " << jetRef.id();
    }
    // Remove all the jet constituents from the jet extras
    std::vector<reco::PFCandidatePtr> jetCands = jetRef->getPFConstituents();
    std::vector<reco::PFCandidatePtr> allRegionalCands =
      jetRegionRef->getPFConstituents();
    // Sort both by ref key
    std::sort(jetCands.begin(), jetCands.end());
    std::sort(allRegionalCands.begin(), allRegionalCands.end());
    // Get the regional junk candidates not in the jet.
    std::vector<reco::PFCandidatePtr> uniqueRegionalCands;

    // This can actually be less than zero, if the jet has really crazy soft
    // stuff really far away from the jet axis.
    if (allRegionalCands.size() > jetCands.size())
      uniqueRegionalCands.reserve(allRegionalCands.size() - jetCands.size());

    // Subtract the jet cands from the regional cands
    std::set_difference(allRegionalCands.begin(), allRegionalCands.end(),
        jetCands.begin(), jetCands.end(),
        std::back_inserter(uniqueRegionalCands));

    // Get the PiZeros associated with this jet
    const std::vector<reco::RecoTauPiZero>& piZeros = (*piZeroAssoc)[jetRef];
    // Loop over our builders and create the set of taus for this jet
    unsigned int nTausBuilt = 0;
    for (BuilderList::const_iterator builder = builders_.begin();
        builder != builders_.end(); ++builder) {
      // Get a ptr_vector of taus from the builder
      reco::tau::RecoTauBuilderPlugin::output_type taus(
          (*builder)(jetRef, piZeros, uniqueRegionalCands));
      // Make sure all taus have their jetref set correctly
      std::for_each(taus.begin(), taus.end(),
          boost::bind(&reco::PFTau::setjetRef, _1, jetRef));
      // Check this size of the taus built.
      // Grow the vector if necessary
      output->reserve(output->size() + taus.size());
      // Copy without selection
      if (!outputSelector_.get()) {
        output->insert(output->end(), taus.begin(), taus.end());
        nTausBuilt += taus.size();
      } else {
        // Copy only those that pass the selection.
        BOOST_FOREACH(const reco::PFTau& tau, taus) {
          if ((*outputSelector_)(tau)) {
            nTausBuilt++;
            output->push_back(tau);
          }
        }
      }
    }
    // If we didn't build *any* taus for this jet, build a null tau if desired.
    // The null PFTau has no content, but it's four vector is set to that of the
    // jet.
    if (!nTausBuilt && buildNullTaus_) {
      reco::PFTau nullTau(std::numeric_limits<int>::quiet_NaN(), jetRef->p4());
      nullTau.setjetRef(jetRef);
      output->push_back(nullTau);
    }
  }

  // Loop over the taus we have created and apply our modifiers to the taus
  for (reco::PFTauCollection::iterator tau = output->begin();
      tau != output->end(); ++tau) {
    for (ModifierList::const_iterator modifier = modifiers_.begin();
        modifier != modifiers_.end(); ++modifier) {
      (*modifier)(*tau);
    }
  }
  evt.put(output);
}

Member Data Documentation

Definition at line 56 of file RecoTauProducer.cc.

Referenced by produce(), and RecoTauProducer().

Definition at line 63 of file RecoTauProducer.cc.

Referenced by produce(), and RecoTauProducer().

Definition at line 54 of file RecoTauProducer.cc.

Referenced by produce(), and RecoTauProducer().

Definition at line 53 of file RecoTauProducer.cc.

Referenced by produce(), and RecoTauProducer().

Definition at line 57 of file RecoTauProducer.cc.

Referenced by produce(), and RecoTauProducer().

Definition at line 59 of file RecoTauProducer.cc.

Referenced by produce(), and RecoTauProducer().

Definition at line 55 of file RecoTauProducer.cc.

Referenced by produce(), and RecoTauProducer().