CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/RecoTauTag/TauTagTools/plugins/PFTauSelectorDefinition.h

Go to the documentation of this file.
00001 #ifndef RecoTauTag_TauTagTools_PFTauSelectorDefinition
00002 #define RecoTauTag_TauTagTools_PFTauSelectorDefinition
00003 
00004 #include "DataFormats/TauReco/interface/PFTau.h"
00005 #include "DataFormats/TauReco/interface/PFTauDiscriminator.h"
00006 
00007 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00008 
00009 #include <memory>
00010 #include <boost/foreach.hpp>
00011 
00012 #include <iostream>
00013 
00014 struct PFTauSelectorDefinition {
00015 
00016   typedef reco::PFTauCollection collection;
00017   typedef edm::Handle< collection > HandleToCollection;
00018   typedef std::vector< const reco::PFTau *> container;
00019   typedef container::const_iterator const_iterator;
00020 
00021   struct DiscCutPair {
00022     edm::Handle<reco::PFTauDiscriminator> handle;
00023     edm::InputTag inputTag;
00024     double cut;
00025   };
00026   typedef std::vector<DiscCutPair> DiscCutPairVec;
00027 
00028   PFTauSelectorDefinition (const edm::ParameterSet &cfg) {
00029     std::vector<edm::ParameterSet> discriminators =
00030       cfg.getParameter<std::vector<edm::ParameterSet> >("discriminators");
00031     // Build each of our cuts
00032     BOOST_FOREACH(const edm::ParameterSet &pset, discriminators) {
00033       DiscCutPair newCut;
00034       newCut.inputTag = pset.getParameter<edm::InputTag>("discriminator");
00035       newCut.cut = pset.getParameter<double>("selectionCut");
00036       discriminators_.push_back(newCut);
00037     }
00038 
00039     // Build a string cut if desired
00040     if (cfg.exists("cut")) {
00041       cut_.reset(new StringCutObjectSelector<reco::PFTau>(
00042             cfg.getParameter<std::string>( "cut" )));
00043     }
00044   }
00045 
00046   const_iterator begin() const { return selected_.begin(); }
00047   const_iterator end() const { return selected_.end(); }
00048 
00049   void select(const HandleToCollection & hc, const edm::Event & e,
00050       const edm::EventSetup& s) {
00051     selected_.clear();
00052 
00053     if (!hc.isValid()) {
00054       throw cms::Exception("PFTauSelectorBadHandle")
00055         << "an invalid PFTau handle with ProductID"
00056         << hc.id() << " passed to PFTauSelector.";
00057     }
00058 
00059     // Load each discriminator
00060     BOOST_FOREACH(DiscCutPair &disc, discriminators_) {
00061       e.getByLabel(disc.inputTag, disc.handle);
00062     }
00063 
00064     const size_t nTaus = hc->size();
00065     for (size_t iTau = 0; iTau < nTaus; ++iTau) {
00066       bool passed = true;
00067       reco::PFTauRef tau(hc, iTau);
00068       // Check if it passed all the discrimiantors
00069       BOOST_FOREACH(const DiscCutPair &disc, discriminators_) {
00070         // Check this discriminator passes
00071         if (!(*disc.handle)[tau] > disc.cut) {
00072           passed = false;
00073           break;
00074         }
00075       }
00076 
00077       if (passed && cut_.get()) {
00078         passed = (*cut_)(*tau);
00079       }
00080 
00081       if (passed)
00082         selected_.push_back(tau.get());
00083     }
00084   } // end select()
00085 
00086   size_t size() const { return selected_.size(); }
00087 
00088  private:
00089   container selected_;
00090   DiscCutPairVec discriminators_;
00091   std::auto_ptr<StringCutObjectSelector<reco::PFTau> > cut_;
00092 
00093 };
00094 
00095 #endif