CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/PhysicsTools/PatAlgos/interface/MultiIsolator.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_PatAlgos_interface_MultiIsolator_h
00002 #define PhysicsTools_PatAlgos_interface_MultiIsolator_h
00003 
00004 #include "DataFormats/Common/interface/View.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007 
00008 #include "PhysicsTools/PatAlgos/interface/BaseIsolator.h"
00009 #include "boost/ptr_container/ptr_vector.hpp"
00010 
00011 #include "DataFormats/PatCandidates/interface/Isolation.h"
00012 
00013 namespace pat { namespace helper {
00014 class MultiIsolator {
00015     public:
00016         typedef std::vector<std::pair<pat::IsolationKeys,float> > IsolationValuePairs;
00017         MultiIsolator() {}
00018         MultiIsolator(const edm::ParameterSet &conf, bool cuts=true) ;
00019         ~MultiIsolator() {}
00020 
00021         // adds an isolator (and takes onwership of the pointer)
00022         void addIsolator(BaseIsolator *iso, uint32_t mask, pat::IsolationKeys key) ;
00023 
00024         // parses an isolator and adds it to the list
00025         void addIsolator(const edm::ParameterSet &conf, bool withCut, uint32_t mask, pat::IsolationKeys key) ;
00026 
00027         // Parses out an isolator, and returns a pointer to it.
00028         // For an empty PSet, it returns a null pointer.
00029         // You own the returned pointer!
00030         static BaseIsolator * make(const edm::ParameterSet &conf, bool withCut) ;
00031        
00032         void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup);
00033         void endEvent() ; 
00034 
00035         template<typename T>
00036         uint32_t test(const edm::View<T> &coll, int idx) const;
00037 
00038         template<typename T>
00039         void fill(const edm::View<T> &coll, int idx, IsolationValuePairs& isolations) const ;
00040 
00042         template<typename RefType>
00043         void fill(const RefType &ref, IsolationValuePairs& isolations) const ;
00044 
00045         void print(std::ostream &out) const ;
00046 
00047         std::string printSummary() const ;
00048 
00050         bool enabled() const  { return !isolators_.empty(); }
00051     private:
00052         boost::ptr_vector<BaseIsolator> isolators_;
00053         std::vector<uint32_t>           masks_;
00054         std::vector<pat::IsolationKeys> keys_;
00055 };
00056 
00057     template<typename T>
00058     uint32_t 
00059     MultiIsolator::test(const edm::View<T> &coll, int idx) const {
00060         uint32_t retval = 0;
00061         edm::RefToBase<T> rb = coll.refAt(idx); // edm::Ptr<T> in a shiny new future to come one remote day ;-)
00062         for (size_t i = 0, n = isolators_.size(); i < n; ++i) {
00063             if (!isolators_[i].test(rb)) retval |= masks_[i];
00064         }
00065         return retval;
00066     }
00067 
00068     template<typename RefType>
00069     void 
00070     MultiIsolator::fill(const RefType &rb, IsolationValuePairs & isolations) const 
00071     {
00072         isolations.resize(isolators_.size());
00073         for (size_t i = 0, n = isolators_.size(); i < n; ++i) {
00074            isolations[i].first  = keys_[i];
00075            isolations[i].second = isolators_[i].getValue(rb); 
00076         }
00077     }
00078 
00079 
00080     template<typename T>
00081     void 
00082     MultiIsolator::fill(const edm::View<T> &coll, int idx, IsolationValuePairs & isolations) const 
00083     {
00084         edm::RefToBase<T> rb = coll.refAt(idx); 
00085         fill(rb, isolations);
00086     }
00087 
00088 }} // namespace
00089 
00090 #endif
00091