Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-13 02:58:09

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 #include "Validation/HLTrigger/interface/HLTGenValObject.h"
0037 
0038 namespace hltdqm {
0039   //here we define needed functions that otherwise dont exist
0040   template <typename ObjType>
0041   float scEtaFunc(const ObjType& obj) {
0042     return obj.superCluster()->eta();
0043   }
0044 
0045   //additional functions specific to a given type (specialised later on)
0046   template <typename ObjType>
0047   std::function<float(const ObjType&)> getUnaryFuncExtraFloat(const std::string& varName) {
0048     std::function<float(const ObjType&)> varFunc;
0049     return varFunc;
0050   }
0051 
0052   //the generic function to call
0053   template <typename ObjType>
0054   std::function<float(const ObjType&)> getUnaryFuncFloat(const std::string& varName) {
0055     std::function<float(const ObjType&)> varFunc;
0056     if (varName == "et")
0057       varFunc = &ObjType::et;
0058     else if (varName == "pt")
0059       varFunc = &ObjType::pt;
0060     else if (varName == "eta")
0061       varFunc = &ObjType::eta;
0062     else if (varName == "phi")
0063       varFunc = &ObjType::phi;
0064     else if (varName == "mass")
0065       varFunc = &ObjType::mass;
0066     else
0067       varFunc = getUnaryFuncExtraFloat<ObjType>(varName);
0068     //check if we never set varFunc and throw an error for anything but an empty input string
0069     if (!varFunc && !varName.empty()) {
0070       throw cms::Exception("ConfigError")
0071           << "var " << varName << " not recognised " << __FILE__ << "," << __LINE__ << std::endl;
0072     }
0073     return varFunc;
0074   }
0075 
0076   template <>
0077   std::function<float(const reco::GsfElectron&)> getUnaryFuncExtraFloat<reco::GsfElectron>(const std::string& varName);
0078   template <>
0079   std::function<float(const reco::Photon&)> getUnaryFuncExtraFloat<reco::Photon>(const std::string& varName);
0080   template <>
0081   std::function<float(const HLTGenValObject&)> getUnaryFuncExtraFloat<HLTGenValObject>(const std::string& varName);
0082 
0083 }  // namespace hltdqm
0084 
0085 #endif