Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-25 04:55:28

0001 #ifndef RecoTauTag_RecoTau_RecoTauCleaningTools_h
0002 #define RecoTauTag_RecoTau_RecoTauCleaningTools_h
0003 
0004 #include <algorithm>
0005 
0006 namespace reco::tau {
0007 
0008   template <typename RankingList, typename Type>
0009   class RecoTauLexicographicalRanking {
0010   public:
0011     // Store our list of ranking functions and intialize the vectors
0012     // that hold the comparison result
0013     explicit RecoTauLexicographicalRanking(const RankingList& rankers) : rankers_(rankers) {}
0014     // Predicate to compare a and b
0015     bool operator()(const Type& a, const Type& b) const {
0016       for (auto const& ranker : rankers_) {
0017         double aResult = (*ranker)(a);
0018         double bResult = (*ranker)(b);
0019         if (aResult != bResult)
0020           return (aResult < bResult);
0021       }
0022       // If all aare equal return false
0023       return false;
0024     }
0025 
0026   private:
0027     const RankingList& rankers_;
0028   };
0029 
0030   template <typename Container, class OverlapFunction>
0031   Container cleanOverlaps(const Container& dirty) {
0032     // Output container of clean objects
0033     Container clean;
0034     OverlapFunction overlapChecker;
0035     for (auto const& candidate : dirty) {
0036       // Check if this overlaps with a pizero already in the clean list
0037       bool overlaps = false;
0038       for (auto cleaned = clean.begin(); cleaned != clean.end() && !overlaps; ++cleaned) {
0039         overlaps = overlapChecker(candidate, *cleaned);
0040       }
0041       // If it didn't overlap with anything clean, add it to the clean list
0042       if (!overlaps)
0043         clean.insert(clean.end(), candidate);
0044     }
0045     return clean;
0046   }
0047 
0048 }  // namespace reco::tau
0049 
0050 #endif