Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:58:28

0001 #ifndef DQMOffline_Trigger_FunctionDefs_h
0002 #define DQMOffline_Trigger_FunctionDefs_h
0003 
0004 //***************************************************************************
0005 //
0006 // Description:
0007 //   These are the functions we wish to access via strings
0008 //   The function returns a std::function holding the function
0009 //   Have to admit, I'm not happy with the implimentation but fine
0010 //   no time to do something better
0011 //
0012 //   There are various issues. The main is the awkward specialisations
0013 //   needed for the different types. Its a nasty hack. Probably
0014 //   can do it cleaner with ROOT dictionaries
0015 //
0016 // Useage:
0017 //   1) define any extra functions you need at the top (seed scEtaFunc as example)
0018 //   2) generic functions applicable to all normal objects are set in
0019 //      getUnaryFuncFloat (if they are floats, other types will need seperate
0020 //      functions which can be done with this as example
0021 //   3) object specific functions are done with getUnaryFuncExtraFloat
0022 //      by specialising that function approprately for the object
0023 //   4) user should simply call getUnaryFuncFloat()
0024 //
0025 // Author: Sam Harper (RAL) , 2017
0026 //
0027 //***************************************************************************
0028 
0029 #include "FWCore/Utilities/interface/Exception.h"
0030 
0031 #include <vector>
0032 #include <functional>
0033 
0034 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0035 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0036 
0037 namespace hltdqm {
0038   //here we define needed functions that otherwise dont exist
0039   template <typename ObjType>
0040   float scEtaFunc(const ObjType& obj) {
0041     return obj.superCluster()->eta();
0042   }
0043 
0044   //additional functions specific to a given type (specialised later on)
0045   template <typename ObjType>
0046   std::function<float(const ObjType&)> getUnaryFuncExtraFloat(const std::string& varName) {
0047     std::function<float(const ObjType&)> varFunc;
0048     return varFunc;
0049   }
0050 
0051   //the generic function to call
0052   template <typename ObjType>
0053   std::function<float(const ObjType&)> getUnaryFuncFloat(const std::string& varName) {
0054     std::function<float(const ObjType&)> varFunc;
0055     if (varName == "et")
0056       varFunc = &ObjType::et;
0057     else if (varName == "pt")
0058       varFunc = &ObjType::pt;
0059     else if (varName == "eta")
0060       varFunc = &ObjType::eta;
0061     else if (varName == "phi")
0062       varFunc = &ObjType::phi;
0063     else
0064       varFunc = getUnaryFuncExtraFloat<ObjType>(varName);
0065     //check if we never set varFunc and throw an error for anything but an empty input string
0066     if (!varFunc && !varName.empty()) {
0067       throw cms::Exception("ConfigError")
0068           << "var " << varName << " not recognised " << __FILE__ << "," << __LINE__ << std::endl;
0069     }
0070     return varFunc;
0071   }
0072 
0073   template <>
0074   std::function<float(const reco::GsfElectron&)> getUnaryFuncExtraFloat<reco::GsfElectron>(const std::string& varName);
0075   template <>
0076   std::function<float(const reco::Photon&)> getUnaryFuncExtraFloat<reco::Photon>(const std::string& varName);
0077 
0078 }  // namespace hltdqm
0079 
0080 #endif