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 
35 
36 namespace hltdqm {
37  //here we define needed functions that otherwise dont exist
38  template<typename ObjType> float scEtaFunc(const ObjType& obj){return obj.superCluster()->eta();}
39 
40 
41  //additional functions specific to a given type (specialised later on)
42  template<typename ObjType>
43  std::function<float(const ObjType&)> getUnaryFuncExtraFloat(const std::string& varName){
44  std::function<float(const ObjType&)> varFunc;
45  return varFunc;
46  }
47 
48  //the generic function to call
49  template<typename ObjType>
50  std::function<float(const ObjType&)> getUnaryFuncFloat(const std::string& varName){
51  std::function<float(const ObjType&)> varFunc;
52  if(varName=="et") varFunc = &ObjType::et;
53  else if(varName=="pt") varFunc = &ObjType::pt;
54  else if(varName=="eta") varFunc = &ObjType::eta;
55  else if(varName=="phi") varFunc = &ObjType::phi;
56  else varFunc = getUnaryFuncExtraFloat<ObjType>(varName);
57  //check if we never set varFunc and throw an error for anything but an empty input string
58  if(!varFunc && !varName.empty()){
59  throw cms::Exception("ConfigError") <<"var "<<varName<<" not recognised "<<__FILE__<<","<<__LINE__<<std::endl;
60  }
61  return varFunc;
62  }
63 
64 
65  template<>
66  std::function<float(const reco::GsfElectron&)> getUnaryFuncExtraFloat<reco::GsfElectron>(const std::string& varName){
67  std::function<float(const reco::GsfElectron&)> varFunc;
68  if(varName=="scEta") varFunc = scEtaFunc<reco::GsfElectron>;
69  else if(varName=="hOverE") varFunc = &reco::GsfElectron::hcalOverEcal;
70  return varFunc;
71  }
72 
73 
74 }
75 
76 
77 #endif
float scEtaFunc(const ObjType &obj)
Definition: FunctionDefs.h:38
float hcalOverEcal() const
Definition: GsfElectron.h:442
std::function< float(const ObjType &)> getUnaryFuncFloat(const std::string &varName)
Definition: FunctionDefs.h:50
et
define resolution functions of each parameter
std::function< float(const ObjType &)> getUnaryFuncExtraFloat(const std::string &varName)
Definition: FunctionDefs.h:43