Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:20

0001 #ifndef CaloDigiCollectionSorter_h
0002 #define CaloDigiCollectionSorter_h
0003 
0004 /** For test purposes, users might want to sort
0005     a collection of digis to find the highest
0006     energies.  This class does that, and should
0007     work for all ECAL and HCAL digi types
0008 
0009     \Author Rick Wilkinson
0010 */
0011 
0012 #include "DataFormats/Common/interface/SortedCollection.h"
0013 #include <algorithm>
0014 #include <vector>
0015 
0016 class CaloDigiCollectionSorter {
0017 public:
0018   CaloDigiCollectionSorter(int bin) : theMaxBin(bin) {}
0019 
0020   /// embedded class to be used as a sort predicate
0021   template <class T>
0022   class CaloDigiSortByMaxBin {
0023   public:
0024     CaloDigiSortByMaxBin(int bin) : theMaxBin(bin) {}
0025 
0026     bool operator()(const T &df1, const T &df2) const {
0027       // should work for HcalQIESamples & EcalMPGASamples
0028       // sort in reverse order, so highest bins come first
0029       return (df1[theMaxBin].raw() > df2[theMaxBin].raw());
0030     }
0031 
0032   private:
0033     int theMaxBin;
0034   };
0035 
0036   /// takes a digi collection and returns a vector of digis,
0037   /// sorted by the peak bin
0038   template <class T>
0039   std::vector<T> sortedVector(const edm::SortedCollection<T> &input) const {
0040     std::vector<T> result;
0041     result.reserve(input.size());
0042     for (unsigned int i = 0; i < input.size(); ++i) {
0043       result.push_back(input[i]);
0044     }
0045     // now sort
0046     std::sort(result.begin(), result.end(), CaloDigiSortByMaxBin<T>(theMaxBin));
0047     return result;
0048   }
0049 
0050 private:
0051   int theMaxBin;
0052 };
0053 
0054 #endif