CMS 3D CMS Logo

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
diffTwoXMLs.ranges
string ranges
Definition: diffTwoXMLs.py:79
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
VarRangeCut::varName
const std::string & varName() const
Definition: VarRangeCut.h:35
VarRangeCut::makePSetDescription
static edm::ParameterSetDescription makePSetDescription()
Definition: VarRangeCut.h:59
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
VarRangeCut::varName_
std::string varName_
Definition: VarRangeCut.h:38
cms::dd::split
std::vector< std::string_view > split(std::string_view, const char *)
config
Definition: config.py:1
FunctionDefs.h
ParameterSetDescription.h
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:36
VarRangeCut::operator()
bool operator()(const ObjType &obj) const
Definition: VarRangeCut.h:67
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
VarRangeCut::VarRangeCut
VarRangeCut(const edm::ParameterSet &config)
Definition: VarRangeCut.h:44
VarRangeCut
Definition: VarRangeCut.h:29
cms::Exception
Definition: Exception.h:70
ParameterSet.h
VarRangeCut::varFunc_
std::function< float(const ObjType &)> varFunc_
Definition: VarRangeCut.h:39
VarRangeCut::allowedRanges_
std::vector< std::pair< float, float > > allowedRanges_
Definition: VarRangeCut.h:40