CMS 3D CMS Logo

FunctionDefs.h
Go to the documentation of this file.
1 #ifndef DQMOffline_Trigger_FunctionDefs_h
2 #define DQMOffline_Trigger_FunctionDefs_h
3 
4 //***************************************************************************
5 //
6 // Description:
7 // These are the functions we wish to access via strings
8 // The function returns a std::function holding the function
9 // Have to admit, I'm not happy with the implimentation but fine
10 // no time to do something better
11 //
12 // There are various issues. The main is the awkward specialisations
13 // needed for the different types. Its a nasty hack. Probably
14 // can do it cleaner with ROOT dictionaries
15 //
16 // Useage:
17 // 1) define any extra functions you need at the top (seed scEtaFunc as example)
18 // 2) generic functions applicable to all normal objects are set in
19 // getUnaryFuncFloat (if they are floats, other types will need seperate
20 // functions which can be done with this as example
21 // 3) object specific functions are done with getUnaryFuncExtraFloat
22 // by specialising that function approprately for the object
23 // 4) user should simply call getUnaryFuncFloat()
24 //
25 // Author: Sam Harper (RAL) , 2017
26 //
27 //***************************************************************************
28 
30 
31 #include <vector>
32 #include <functional>
33 
36 
37 namespace hltdqm {
38  //here we define needed functions that otherwise dont exist
39  template<typename ObjType> float scEtaFunc(const ObjType& obj){return obj.superCluster()->eta();}
40 
41 
42  //additional functions specific to a given type (specialised later on)
43  template<typename ObjType>
44  std::function<float(const ObjType&)> getUnaryFuncExtraFloat(const std::string& varName){
45  std::function<float(const ObjType&)> varFunc;
46  return varFunc;
47  }
48 
49  //the generic function to call
50  template<typename ObjType>
51  std::function<float(const ObjType&)> getUnaryFuncFloat(const std::string& varName){
52  std::function<float(const ObjType&)> varFunc;
53  if(varName=="et") varFunc = &ObjType::et;
54  else if(varName=="pt") varFunc = &ObjType::pt;
55  else if(varName=="eta") varFunc = &ObjType::eta;
56  else if(varName=="phi") varFunc = &ObjType::phi;
57  else varFunc = getUnaryFuncExtraFloat<ObjType>(varName);
58  //check if we never set varFunc and throw an error for anything but an empty input string
59  if(!varFunc && !varName.empty()){
60  throw cms::Exception("ConfigError") <<"var "<<varName<<" not recognised "<<__FILE__<<","<<__LINE__<<std::endl;
61  }
62  return varFunc;
63  }
64 
65  template<>
66  std::function<float(const reco::GsfElectron&)> getUnaryFuncExtraFloat<reco::GsfElectron>(const std::string& varName);
67  template<>
68  std::function<float(const reco::Photon&)> getUnaryFuncExtraFloat<reco::Photon>(const std::string& varName);
69 
70 }
71 
72 
73 #endif
float scEtaFunc(const ObjType &obj)
Definition: FunctionDefs.h:39
std::function< float(const ObjType &)> getUnaryFuncFloat(const std::string &varName)
Definition: FunctionDefs.h:51
et
define resolution functions of each parameter
std::function< float(const ObjType &)> getUnaryFuncExtraFloat(const std::string &varName)
Definition: FunctionDefs.h:44