CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTauTag/TauTagTools/plugins/CaloTauSelectorDefinition.h

Go to the documentation of this file.
00001 #ifndef RecoTauTag_TauTagTools_CaloTauSelectorDefinition
00002 #define RecoTauTag_TauTagTools_CaloTauSelectorDefinition
00003 
00004 #include "DataFormats/TauReco/interface/CaloTau.h"
00005 #include "DataFormats/TauReco/interface/CaloTauDiscriminator.h"
00006 
00007 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00008 
00009 #include <iostream>
00010 
00011 struct CaloTauSelectorDefinition {
00012 
00013   typedef reco::CaloTauCollection collection;
00014   typedef edm::Handle< collection > HandleToCollection;
00015   typedef std::vector< reco::CaloTau *> container;
00016   typedef container::const_iterator const_iterator;
00017 
00018   struct TDiscCutPair {
00019     edm::Handle<reco::CaloTauDiscriminator> m_discHandle;
00020     double m_cut;
00021   };    
00022   typedef std::vector<TDiscCutPair> TDiscCutPairVec;
00023   
00024   CaloTauSelectorDefinition ( const edm::ParameterSet & cfg ) {
00025     discriminators_ = cfg.getParameter< std::vector<edm::ParameterSet> >( "discriminators" ); 
00026     cut_ = ( cfg.exists("cut") ) ? new StringCutObjectSelector<reco::CaloTau>( cfg.getParameter<std::string>( "cut" ) ) : 0;
00027   }
00028 
00029   ~CaloTauSelectorDefinition () { 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 CaloTaus
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 CaloTau 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 calotau = hc->begin(); 
00065           calotau != hc->end();
00066           ++calotau, ++key) 
00067     {
00068       passedAllCuts = true;
00069       reco::CaloTauRef calotauRef(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))[calotauRef] <= discIt->m_cut)
00077           passedAllCuts = false;
00078       }
00079       
00080       if ( cut_ ) passedAllCuts &= (*cut_)(*calotau);
00081          
00082       if(passedAllCuts)
00083         selected_.push_back( new reco::CaloTau(*calotau) );
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::CaloTau>* cut_;
00093   
00094 };
00095 
00096 #endif