CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/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 <iostream>
00010 
00011 struct PFTauSelectorDefinition {
00012 
00013   typedef reco::PFTauCollection collection;
00014   typedef edm::Handle< collection > HandleToCollection;
00015   typedef std::vector< reco::PFTau *> container;
00016   typedef container::const_iterator const_iterator;
00017 
00018   struct TDiscCutPair {
00019     edm::Handle<reco::PFTauDiscriminator> m_discHandle;
00020     double m_cut;
00021   };
00022   typedef std::vector<TDiscCutPair> TDiscCutPairVec;
00023 
00024   PFTauSelectorDefinition ( const edm::ParameterSet & cfg ) {
00025     discriminators_ = cfg.getParameter< std::vector<edm::ParameterSet> >( "discriminators" );
00026     cut_ = ( cfg.exists("cut") ) ? new StringCutObjectSelector<reco::PFTau>( cfg.getParameter<std::string>( "cut" ) ) : 0;
00027   }
00028 
00029   ~PFTauSelectorDefinition () { delete cut_; }
00030 
00031   const_iterator begin() const { return selected_.begin(); }
00032 
00033   const_iterator end() const { return selected_.end(); }
00034 
00035   void select( const HandleToCollection & hc,
00036                const edm::Event & e,
00037                const edm::EventSetup& s)
00038   {
00039 
00040     selected_.clear();
00041     assert( hc.isValid() ); // collection of PFTaus
00042 
00043     // get discriminators and coresponding cuts from stored vpset
00044     static TDiscCutPairVec discriminators;
00045     discriminators.clear();
00046 
00047     for(std::vector< edm::ParameterSet >::iterator it = discriminators_.begin();
00048         it != discriminators_.end();
00049         ++it)
00050     {
00051       TDiscCutPair disc;
00052       // get discriminator, check if valid
00053       // assert isn't a good method to do it
00054       if(!(e.getByLabel( it->getParameter<edm::InputTag>("discriminator"), disc.m_discHandle))) assert(0);
00055       disc.m_cut = it->getParameter<double>("selectionCut");
00056       // the discriminator collection and the PFTau collection
00057       // must have the same size
00058       assert( disc.m_discHandle->size() ==  hc->size());
00059       discriminators.push_back(disc);
00060     }
00061 
00062     unsigned key=0;
00063     static bool passedAllCuts;
00064     for( collection::const_iterator pftau = hc->begin();
00065           pftau != hc->end();
00066           ++pftau, ++key)
00067     {
00068       passedAllCuts = true;
00069       reco::PFTauRef pfTauRef(hc, key);
00070 
00071       //iterate over all discriminators, check the cuts
00072       for (TDiscCutPairVec::iterator discIt = discriminators.begin();
00073            discIt!=discriminators.end();
00074            ++discIt)
00075       {
00076         if ( (*(discIt->m_discHandle))[pfTauRef] <= discIt->m_cut)
00077           passedAllCuts = false;
00078       }
00079 
00080       if ( cut_ ) passedAllCuts &= (*cut_)(*pftau);
00081 
00082       if(passedAllCuts)
00083         selected_.push_back( new reco::PFTau(*pftau) );
00084     } // end collection iteration
00085   } // end select()
00086 
00087   size_t size() const { return selected_.size(); }
00088 
00089  private:
00090   container selected_;
00091   std::vector< edm::ParameterSet > discriminators_;
00092   StringCutObjectSelector<reco::PFTau>* cut_;
00093 
00094 };
00095 
00096 #endif