CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoTauTag/RecoTau/interface/RecoTauCleaningTools.h

Go to the documentation of this file.
00001 #ifndef RecoTauTag_RecoTau_RecoTauCleaningTools_h
00002 #define RecoTauTag_RecoTau_RecoTauCleaningTools_h
00003 #include <algorithm>
00004 #include <functional>
00005 
00006 namespace reco { namespace tau {
00007 
00008 template<typename RankingList, typename Type>
00009   class RecoTauLexicographicalRanking :
00010       public std::binary_function<Type, Type, bool> {
00011     public:
00012       // Store our list of ranking functions and intialize the vectors
00013       // that hold the comparison result
00014       explicit RecoTauLexicographicalRanking(const RankingList& rankers):
00015         rankers_(rankers) {}
00016       // Predicate to compare a and b
00017       bool operator()(const Type& a, const Type& b) const {
00018         typename RankingList::const_iterator ranker = rankers_.begin();
00019         while (ranker != rankers_.end()) {
00020           double aResult = (*ranker)(a);
00021           double bResult = (*ranker)(b);
00022           if (aResult != bResult)
00023             return (aResult < bResult);
00024           ++ranker;
00025         }
00026         // If all aare equal return false
00027         return false;
00028       }
00029     private:
00030       const RankingList& rankers_;
00031   };
00032 
00033 template<typename Container, class OverlapFunction>
00034 Container cleanOverlaps(const Container& dirty) {
00035   typedef typename Container::const_iterator Iterator;
00036   // Output container of clean objects
00037   Container clean;
00038   OverlapFunction overlapChecker;
00039   for (Iterator candidate = dirty.begin(); candidate != dirty.end();
00040        ++candidate) {
00041     // Check if this overlaps with a pizero already in the clean list
00042     bool overlaps = false;
00043     for (Iterator cleaned = clean.begin();
00044          cleaned != clean.end() && !overlaps; ++cleaned) {
00045       overlaps = overlapChecker(*candidate, *cleaned);
00046     }
00047     // If it didn't overlap with anything clean, add it to the clean list
00048     if (!overlaps)
00049       clean.insert(clean.end(), *candidate);
00050   }
00051   return clean;
00052 }
00053 
00054 template<typename T>
00055 class SortByDescendingPt {
00056   public:
00057     bool operator()(const T& a, const T& b) const {
00058       return a.pt() > b.pt();
00059     }
00060 };
00061 }}  // end reco::tau::
00062 #endif