CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/UtilAlgos/plugins/VariableEventSelector.h

Go to the documentation of this file.
00001 #ifndef _VariableEventSelector_H
00002 #define _VariableEventSelector_H
00003 
00004 #include "PhysicsTools/UtilAlgos/interface/EventSelector.h"
00005 #include "PhysicsTools/UtilAlgos/interface/VariableHelper.h"
00006 
00007 class VariableEventSelector : public EventSelector {
00008  public:
00009   VariableEventSelector(const edm::ParameterSet& pset) :
00010     EventSelector(pset)
00011     {
00012       var_=pset.getParameter<std::string>("var");
00013       doMin_=pset.exists("min");
00014       if (doMin_) min_=pset.getParameter<double>("min");
00015       doMax_=pset.exists("max");
00016       if (doMax_) max_=pset.getParameter<double>("max");
00017 
00018       std::stringstream ss;
00019       ss<<"event selector based on VariableHelper variable: "<<var_;
00020       description_.push_back(ss.str());       ss.str("");
00021       if (doMin_){
00022         ss<<"with minimum boundary: "<<min_;
00023         description_.push_back(ss.str());       ss.str("");}
00024       if (doMax_){
00025         ss<<"with maximum boundary: "<<max_;
00026         description_.push_back(ss.str());       ss.str("");}
00027     }
00028     bool select(const edm::Event& e) const{
00029       const CachingVariable * var=edm::Service<VariableHelperService>()->get().variable(var_);
00030       if (!var->compute(e)) return false;
00031 
00032       double v=(*var)(e);
00033       
00034       if (doMin_ && v<min_) return false;
00035       else if (doMax_ && v>max_) return false;
00036       else return true;
00037     }
00038 
00039  private:
00040   std::string var_;
00041   bool doMin_;
00042   double min_;
00043   bool doMax_;
00044   double max_;
00045 };
00046 
00047 #endif