Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef SimDataFormats_Associations_MtdSimLayerClusterToRecoClusterAssociationMap_h
0002 #define SimDataFormats_Associations_MtdSimLayerClusterToRecoClusterAssociationMap_h
0003 
0004 #include "DataFormats/Provenance/interface/ProductID.h"
0005 #include "DataFormats/Common/interface/HandleBase.h"
0006 #include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
0007 #include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"
0008 
0009 #include <vector>
0010 #include <utility>
0011 #include <algorithm>
0012 
0013 /**
0014  * Maps MtdSimLayerCluserRef to FTLClusterRef
0015  *
0016  */
0017 class MtdSimLayerClusterToRecoClusterAssociationMap {
0018 public:
0019   using key_type = MtdSimLayerClusterRef;
0020   using mapped_type = FTLClusterRef;
0021   using value_type = std::pair<key_type, std::vector<mapped_type>>;
0022   using map_type = std::vector<value_type>;
0023   using const_iterator = typename map_type::const_iterator;
0024   using range = std::pair<const_iterator, const_iterator>;
0025 
0026   /// Constructor
0027   MtdSimLayerClusterToRecoClusterAssociationMap();
0028   /// Destructor
0029   ~MtdSimLayerClusterToRecoClusterAssociationMap();
0030 
0031   void emplace_back(const MtdSimLayerClusterRef& simClus, std::vector<FTLClusterRef>& recoClusVect) {
0032     map_.emplace_back(simClus, recoClusVect);
0033   }
0034 
0035   void post_insert() { std::sort(map_.begin(), map_.end(), compare); }
0036 
0037   bool empty() const { return map_.empty(); }
0038   size_t size() const { return map_.size(); }
0039 
0040   const_iterator begin() const { return map_.begin(); }
0041   const_iterator cbegin() const { return map_.cbegin(); }
0042   const_iterator end() const { return map_.end(); }
0043   const_iterator cend() const { return map_.cend(); }
0044 
0045   range equal_range(const MtdSimLayerClusterRef& key) const {
0046     return std::equal_range(map_.begin(), map_.end(), value_type(key, std::vector<FTLClusterRef>()), compare);
0047   }
0048 
0049   const map_type& map() const { return map_; }
0050 
0051 private:
0052   static bool compare(const value_type& i, const value_type& j) {
0053     const auto& i_hAndE = (i.first)->hits_and_energies();
0054     const auto& j_hAndE = (j.first)->hits_and_energies();
0055 
0056     auto imin = std::min_element(i_hAndE.begin(),
0057                                  i_hAndE.end(),
0058                                  [](std::pair<uint64_t, float> a, std::pair<uint64_t, float> b) { return a < b; });
0059 
0060     auto jmin = std::min_element(j_hAndE.begin(),
0061                                  j_hAndE.end(),
0062                                  [](std::pair<uint64_t, float> a, std::pair<uint64_t, float> b) { return a < b; });
0063 
0064     return (*imin < *jmin);
0065   }
0066 
0067   map_type map_;
0068 };
0069 
0070 #endif