Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:20

0001 #ifndef DQMOffline_Trigger_VarRangeCut_h
0002 #define DQMOffline_Trigger_VarRangeCut_h
0003 
0004 //********************************************************************************
0005 //
0006 // Description:
0007 //   A object containing a minimal set of selection cuts.
0008 //   These selection cuts are intended to be simple selections on kinematic variables.
0009 //   Currently these are implimented as simple allowed ranges  X<var<Y which are ORed together
0010 //   So for example we may want to have an eta cut of 0<|eta|<1.4442 || 1.556<|eta|<2.5
0011 //
0012 // Implimentation:
0013 //   std::function holds the function which generates the variable from the object
0014 //   the name of the variable is also stored so we can determine if we should not apply
0015 //   a given selection cut
0016 //
0017 // Author : Sam Harper , RAL, May 2017
0018 //
0019 //***********************************************************************************
0020 
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0023 
0024 #include "DQMOffline/Trigger/interface/FunctionDefs.h"
0025 
0026 #include <boost/algorithm/string.hpp>
0027 
0028 template <typename ObjType>
0029 class VarRangeCut {
0030 public:
0031   explicit VarRangeCut(const edm::ParameterSet& config);
0032   static edm::ParameterSetDescription makePSetDescription();
0033 
0034   bool operator()(const ObjType& obj) const;
0035   const std::string& varName() const { return varName_; }
0036 
0037 private:
0038   std::string varName_;
0039   std::function<float(const ObjType&)> varFunc_;
0040   std::vector<std::pair<float, float> > allowedRanges_;
0041 };
0042 
0043 template <typename ObjType>
0044 VarRangeCut<ObjType>::VarRangeCut(const edm::ParameterSet& config) {
0045   varName_ = config.getParameter<std::string>("rangeVar");
0046   varFunc_ = hltdqm::getUnaryFuncFloat<ObjType>(varName_);
0047   auto ranges = config.getParameter<std::vector<std::string> >("allowedRanges");
0048   for (auto range : ranges) {
0049     std::vector<std::string> splitRange;
0050     boost::split(splitRange, range, boost::is_any_of(":"));
0051     if (splitRange.size() != 2)
0052       throw cms::Exception("ConfigError")
0053           << "in VarRangeCut::VarRangeCut range " << range << " is not of format X:Y" << std::endl;
0054     allowedRanges_.push_back({std::stof(splitRange[0]), std::stof(splitRange[1])});
0055   }
0056 }
0057 
0058 template <typename ObjType>
0059 edm::ParameterSetDescription VarRangeCut<ObjType>::makePSetDescription() {
0060   edm::ParameterSetDescription desc;
0061   desc.add<std::string>("rangeVar", "");
0062   desc.add<std::vector<std::string> >("allowedRanges", std::vector<std::string>());
0063   return desc;
0064 }
0065 
0066 template <typename ObjType>
0067 bool VarRangeCut<ObjType>::operator()(const ObjType& obj) const {
0068   if (!varFunc_)
0069     return true;  //auto pass if we dont specify a variable function
0070   else {
0071     float varVal = varFunc_(obj);
0072     for (auto& range : allowedRanges_) {
0073       if (varVal >= range.first && varVal < range.second)
0074         return true;
0075     }
0076     return false;
0077   }
0078 }
0079 
0080 #endif