CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VarRangeCut.h
Go to the documentation of this file.
1 #ifndef DQMOffline_Trigger_VarRangeCut_h
2 #define DQMOffline_Trigger_VarRangeCut_h
3 
4 //********************************************************************************
5 //
6 // Description:
7 // A object containing a minimal set of selection cuts.
8 // These selection cuts are intended to be simple selections on kinematic variables.
9 // Currently these are implimented as simple allowed ranges X<var<Y which are ORed together
10 // So for example we may want to have an eta cut of 0<|eta|<1.4442 || 1.556<|eta|<2.5
11 //
12 // Implimentation:
13 // std::function holds the function which generates the variable from the object
14 // the name of the variable is also stored so we can determine if we should not apply
15 // a given selection cut
16 //
17 // Author : Sam Harper , RAL, May 2017
18 //
19 //***********************************************************************************
20 
23 
25 
26 #include <boost/algorithm/string.hpp>
27 
28 template <typename ObjType>
29 class VarRangeCut {
30 public:
31  explicit VarRangeCut(const edm::ParameterSet& config);
33 
34  bool operator()(const ObjType& obj) const;
35  const std::string& varName() const { return varName_; }
36 
37 private:
39  std::function<float(const ObjType&)> varFunc_;
40  std::vector<std::pair<float, float> > allowedRanges_;
41 };
42 
43 template <typename ObjType>
45  varName_ = config.getParameter<std::string>("rangeVar");
46  varFunc_ = hltdqm::getUnaryFuncFloat<ObjType>(varName_);
47  auto ranges = config.getParameter<std::vector<std::string> >("allowedRanges");
48  for (auto range : ranges) {
49  std::vector<std::string> splitRange;
50  boost::split(splitRange, range, boost::is_any_of(":"));
51  if (splitRange.size() != 2)
52  throw cms::Exception("ConfigError")
53  << "in VarRangeCut::VarRangeCut range " << range << " is not of format X:Y" << std::endl;
54  allowedRanges_.push_back({std::stof(splitRange[0]), std::stof(splitRange[1])});
55  }
56 }
57 
58 template <typename ObjType>
61  desc.add<std::string>("rangeVar", "");
62  desc.add<std::vector<std::string> >("allowedRanges", std::vector<std::string>());
63  return desc;
64 }
65 
66 template <typename ObjType>
67 bool VarRangeCut<ObjType>::operator()(const ObjType& obj) const {
68  if (!varFunc_)
69  return true; //auto pass if we dont specify a variable function
70  else {
71  float varVal = varFunc_(obj);
72  for (auto& range : allowedRanges_) {
73  if (varVal >= range.first && varVal < range.second)
74  return true;
75  }
76  return false;
77  }
78 }
79 
80 #endif
std::vector< std::pair< float, float > > allowedRanges_
Definition: VarRangeCut.h:40
static edm::ParameterSetDescription makePSetDescription()
Definition: VarRangeCut.h:59
std::string varName_
Definition: VarRangeCut.h:38
const uint16_t range(const Frame &aFrame)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
string ranges
Definition: diffTwoXMLs.py:79
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool operator()(const ObjType &obj) const
Definition: VarRangeCut.h:67
tuple config
parse the configuration file
const std::string & varName() const
Definition: VarRangeCut.h:35
std::function< float(const ObjType &)> varFunc_
Definition: VarRangeCut.h:39
VarRangeCut(const edm::ParameterSet &config)
Definition: VarRangeCut.h:44