Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:45

0001 #ifndef Utils_h
0002 #define Utils_h
0003 
0004 #include <map>
0005 #include <utility>
0006 #include <vector>
0007 
0008 //! Generic matching function
0009 template <typename Reference, typename Association>
0010 std::pair<typename Association::data_type::first_type, double> match(Reference key,
0011                                                                      Association association,
0012                                                                      bool bestMatchByMaxValue) {
0013   typename Association::data_type::first_type value;
0014 
0015   typename Association::const_iterator pos = association.find(key);
0016 
0017   if (pos == association.end())
0018     return std::pair<typename Association::data_type::first_type, double>(value, 0);
0019 
0020   const std::vector<typename Association::data_type> &matches = pos->val;
0021 
0022   double q = bestMatchByMaxValue ? -1e30 : 1e30;
0023 
0024   for (std::size_t i = 0; i < matches.size(); ++i)
0025     if (bestMatchByMaxValue ? (matches[i].second > q) : (matches[i].second < q)) {
0026       value = matches[i].first;
0027       q = matches[i].second;
0028     }
0029 
0030   return std::pair<typename Association::data_type::first_type, double>(value, q);
0031 }
0032 
0033 //! Class that maps the native Geant4 process types to the legacy CMS process
0034 //! types
0035 class G4toCMSLegacyProcTypeMap {
0036 public:
0037   typedef std::map<unsigned int, unsigned int> MapType;
0038 
0039   G4toCMSLegacyProcTypeMap();
0040 
0041   const unsigned int processId(unsigned int g4ProcessId) const;
0042 
0043 private:
0044   MapType m_map;
0045 };
0046 
0047 #endif