CMS 3D CMS Logo

Public Types | Public Member Functions | Private Types | Private Attributes

RecoTauPiZeroProducer Class Reference

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

List of all members.

Public Types

typedef
reco::tau::RecoTauPiZeroBuilderPlugin 
Builder
typedef
reco::tau::RecoTauPiZeroQualityPlugin 
Ranker

Public Member Functions

void print (const std::vector< reco::RecoTauPiZero > &piZeros, std::ostream &out)
void produce (edm::Event &evt, const edm::EventSetup &es)
 RecoTauPiZeroProducer (const edm::ParameterSet &pset)
 ~RecoTauPiZeroProducer ()

Private Types

typedef boost::ptr_vector
< Builder
builderList
typedef boost::ptr_list
< reco::RecoTauPiZero
PiZeroList
typedef
reco::tau::RecoTauLexicographicalRanking
< rankerList,
reco::RecoTauPiZero
PiZeroPredicate
typedef boost::ptr_vector
< reco::RecoTauPiZero
PiZeroVector
typedef boost::ptr_vector< RankerrankerList

Private Attributes

builderList builders_
std::auto_ptr
< StringCutObjectSelector
< reco::RecoTauPiZero > > 
outputSelector_
double piZeroMass_
std::auto_ptr< PiZeroPredicatepredicate_
rankerList rankers_
edm::InputTag src_

Detailed Description

Definition at line 40 of file RecoTauPiZeroProducer.cc.


Member Typedef Documentation

Definition at line 42 of file RecoTauPiZeroProducer.cc.

typedef boost::ptr_vector<Builder> RecoTauPiZeroProducer::builderList [private]

Definition at line 52 of file RecoTauPiZeroProducer.cc.

typedef boost::ptr_list<reco::RecoTauPiZero> RecoTauPiZeroProducer::PiZeroList [private]

Definition at line 55 of file RecoTauPiZeroProducer.cc.

Definition at line 58 of file RecoTauPiZeroProducer.cc.

typedef boost::ptr_vector<reco::RecoTauPiZero> RecoTauPiZeroProducer::PiZeroVector [private]

Definition at line 54 of file RecoTauPiZeroProducer.cc.

Definition at line 43 of file RecoTauPiZeroProducer.cc.

typedef boost::ptr_vector<Ranker> RecoTauPiZeroProducer::rankerList [private]

Definition at line 53 of file RecoTauPiZeroProducer.cc.


Constructor & Destructor Documentation

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

Definition at line 71 of file RecoTauPiZeroProducer.cc.

References builders_, SurfaceDeformationFactory::create(), edm::ParameterSet::exists(), reco::get(), edm::ParameterSet::getParameter(), outputSelector_, piZeroMass_, predicate_, rankers_, elec_selection::selection(), and src_.

                                                                        {
  src_ = pset.getParameter<edm::InputTag>("jetSrc");

  typedef std::vector<edm::ParameterSet> VPSet;
  // Get the mass hypothesis for the pizeros
  piZeroMass_ = pset.getParameter<double>("massHypothesis");

  // Get each of our PiZero 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");
    // Build the plugin
    builders_.push_back(RecoTauPiZeroBuilderPluginFactory::get()->create(
          pluginType, *builderPSet));
  }

  // Get each of our quality rankers
  const VPSet& rankers = pset.getParameter<VPSet>("ranking");
  for (VPSet::const_iterator rankerPSet = rankers.begin();
      rankerPSet != rankers.end(); ++rankerPSet) {
    const std::string& pluginType =
      rankerPSet->getParameter<std::string>("plugin");
    rankers_.push_back(RecoTauPiZeroQualityPluginFactory::get()->create(
          pluginType, *rankerPSet));
  }

  // Build the sorting predicate
  predicate_ = std::auto_ptr<PiZeroPredicate>(new PiZeroPredicate(rankers_));

  // 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::RecoTauPiZero>(selection));
    }
  }

  produces<reco::JetPiZeroAssociation>();
}
RecoTauPiZeroProducer::~RecoTauPiZeroProducer ( ) [inline]

Definition at line 46 of file RecoTauPiZeroProducer.cc.

{}

Member Function Documentation

void RecoTauPiZeroProducer::print ( const std::vector< reco::RecoTauPiZero > &  piZeros,
std::ostream &  out 
)

Definition at line 220 of file RecoTauPiZeroProducer.cc.

References rankers_, and tablePrinter::width.

                                                                  {
  const unsigned int width = 25;
  BOOST_FOREACH(const reco::RecoTauPiZero& piZero, piZeros) {
    out << piZero;
    out << "* Rankers:" << std::endl;
    for (rankerList::const_iterator ranker = rankers_.begin();
        ranker != rankers_.end(); ++ranker) {
      out << "* " << std::setiosflags(std::ios::left)
        << std::setw(width) << ranker->name()
        << " " << std::resetiosflags(std::ios::left)
        << std::setprecision(3) << (*ranker)(piZero);
      out << std::endl;
    }
  }
}
void RecoTauPiZeroProducer::produce ( edm::Event evt,
const edm::EventSetup es 
) [virtual]

Implements edm::EDProducer.

Definition at line 116 of file RecoTauPiZeroProducer.cc.

References builders_, exception, edm::Event::getByLabel(), metsig::jet, edm::Ref< C, T, F >::key(), reco::tau::RecoTauNamedPlugin::name(), outputSelector_, piZeroMass_, predicate_, edm::Event::put(), query::result, AddFourMomenta::set(), reco::LeafCandidate::setMass(), reco::tau::RecoTauEventHolderPlugin::setup(), edm::RefVector< C, T, F >::size(), and src_.

                                                             {
  // Get a view of our jets via the base candidates
  edm::Handle<reco::CandidateView> jetView;
  evt.getByLabel(src_, jetView);

  // Give each of our plugins a chance at doing something with the edm::Event
  BOOST_FOREACH(Builder& builder, builders_) {
    builder.setup(evt, es);
  }

  // Convert the view to a RefVector of actual PFJets
  reco::PFJetRefVector jetRefs =
      reco::tau::castView<reco::PFJetRefVector>(jetView);
  // Make our association
  std::auto_ptr<reco::JetPiZeroAssociation> association;

  if (jetRefs.size()) {
    association.reset(
        new reco::JetPiZeroAssociation(reco::PFJetRefProd(jetRefs)));
  } else {
    association.reset(new reco::JetPiZeroAssociation);
  }

  // Loop over our jets
  BOOST_FOREACH(const reco::PFJetRef& jet, jetRefs) {
    // Build our global list of RecoTauPiZero
    PiZeroList dirtyPiZeros;

    // Compute the pi zeros from this jet for all the desired algorithms
    BOOST_FOREACH(const Builder& builder, builders_) {
      try {
        PiZeroVector result(builder(*jet));
        dirtyPiZeros.transfer(dirtyPiZeros.end(), result);
      } catch ( cms::Exception &exception) {
        edm::LogError("BuilderPluginException")
            << "Exception caught in builder plugin " << builder.name()
            << ", rethrowing" << std::endl;
        throw exception;
      }
    }
    // Rank the candidates according to our quality plugins
    dirtyPiZeros.sort(*predicate_);

    // Keep track of the photons in the clean collection
    std::vector<reco::RecoTauPiZero> cleanPiZeros;
    std::set<reco::CandidatePtr> photonsInCleanCollection;
    while (dirtyPiZeros.size()) {
      // Pull our candidate pi zero from the front of the list
      std::auto_ptr<reco::RecoTauPiZero> toAdd(
          dirtyPiZeros.pop_front().release());
      // If this doesn't pass our basic selection, discard it.
      if (!(*outputSelector_)(*toAdd)) {
        continue;
      }
      // Find the sub-gammas that are not already in the cleaned collection
      std::vector<reco::CandidatePtr> uniqueGammas;
      std::set_difference(toAdd->daughterPtrVector().begin(),
                          toAdd->daughterPtrVector().end(),
                          photonsInCleanCollection.begin(),
                          photonsInCleanCollection.end(),
                          std::back_inserter(uniqueGammas));
      // If the pi zero has no unique gammas, discard it.  Note toAdd is deleted
      // when it goes out of scope.
      if (!uniqueGammas.size()) {
        continue;
      } else if (uniqueGammas.size() == toAdd->daughterPtrVector().size()) {
        // Check if it is composed entirely of unique gammas.  In this case
        // immediately add it to the clean collection.
        photonsInCleanCollection.insert(toAdd->daughterPtrVector().begin(),
                                        toAdd->daughterPtrVector().end());
        cleanPiZeros.push_back(*toAdd);
      } else {
        // Otherwise update the pizero that contains only the unique gammas and
        // add it back into the sorted list of dirty PiZeros
        toAdd->clearDaughters();
        // Add each of the unique daughters back to the pizero
        BOOST_FOREACH(const reco::CandidatePtr& gamma, uniqueGammas) {
          toAdd->addDaughter(gamma);
        }
        // Update the four vector
        AddFourMomenta p4Builder_;
        p4Builder_.set(*toAdd);
        // Put this pi zero back into the collection of sorted dirty pizeros
        PiZeroList::iterator insertionPoint = std::lower_bound(
            dirtyPiZeros.begin(), dirtyPiZeros.end(), *toAdd, *predicate_);
        dirtyPiZeros.insert(insertionPoint, toAdd);
      }
    }
    // Apply the mass hypothesis if desired
    if (piZeroMass_ >= 0) {
      std::for_each(
          cleanPiZeros.begin(), cleanPiZeros.end(),
          std::bind2nd(
              std::mem_fun_ref(&reco::RecoTauPiZero::setMass), piZeroMass_));
    }
    // Add to association
    //print(cleanPiZeros, std::cout);
    association->setValue(jet.key(), cleanPiZeros);
  }
  evt.put(association);
}

Member Data Documentation

Definition at line 61 of file RecoTauPiZeroProducer.cc.

Referenced by produce(), and RecoTauPiZeroProducer().

Definition at line 68 of file RecoTauPiZeroProducer.cc.

Referenced by produce(), and RecoTauPiZeroProducer().

Definition at line 64 of file RecoTauPiZeroProducer.cc.

Referenced by produce(), and RecoTauPiZeroProducer().

Definition at line 63 of file RecoTauPiZeroProducer.cc.

Referenced by produce(), and RecoTauPiZeroProducer().

Definition at line 62 of file RecoTauPiZeroProducer.cc.

Referenced by print(), and RecoTauPiZeroProducer().

Definition at line 60 of file RecoTauPiZeroProducer.cc.

Referenced by produce(), and RecoTauPiZeroProducer().