test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VariableEventSelector.h
Go to the documentation of this file.
1 #ifndef _VariableEventSelector_H
2 #define _VariableEventSelector_H
3 
7 #include "TFormula.h"
8 #include "TString.h"
9 
12  VariableFormulaEventSelector(pset, iC) {}
14  EventSelector(pset, iC)
15  {
16  const std::string name_ = pset.getParameter<std::string>("fname");
17  TString ts(pset.getParameter<std::string>("formula"));
18  //find the variables. register and replace
19  int open = ts.Index("[");
20  int close = ts.Index("]");
21  while (open>0){
22  ++open;
23  TString sub( ts(open,close-open));
24  //std::cout<<"found:"<< sub <<std::endl;
25  vars_.insert( sub.Data() );
26  //vars_.insert( ts(open,close-open));
27  open = ts.Index("[",open);
28  close = ts.Index("]",open);
29  }
30 
31  unsigned int v_i;
32  std::set<std::string>::iterator v_it;
33  for (v_i = 0, v_it=vars_.begin();
34  v_i!=vars_.size(); ++v_i,++v_it)
35  {
36  ts.ReplaceAll(TString::Format("[%s]", v_it->c_str()),TString::Format("[%d]", v_i));
37  }
38 
39  //std::cout<<" formula found:"<< ts <<std::endl;
40  formula_ = new TFormula(name_.c_str(), ts);
41  //vars_ = pset.getParameter<std::vector<std::string>>("variables");
42  threshold_= pset.getParameter<double>("threshold");
43  }
44 
45  bool select(const edm::Event& e) const{
46  unsigned int v_i;
47  std::set<std::string>::iterator v_it;
48 
49  for (v_i = 0, v_it=vars_.begin();
50  v_i!=vars_.size(); ++v_i,++v_it)
51  {
52  const CachingVariable * var = edm::Service<VariableHelperService>()->get().variable(*v_it);
53  if (!var->compute(e)) return false;
54  double v=(*var)(e);
55  formula_->SetParameter(v_i, v);
56  }
57 
58  //should be valuated 0. or 1. in double
59  return (formula_->Eval(0.)>=threshold_);
60  }
61  private:
62  //std::string formula_;
63  TFormula * formula_;
64  std::set<std::string> vars_;
65  double threshold_;
66 };
67 
69  public:
71  VariableEventSelector(pset, iC) {}
73  EventSelector(pset, iC)
74  {
75  var_=pset.getParameter<std::string>("var");
76  doMin_=pset.exists("min");
77  if (doMin_) min_=pset.getParameter<double>("min");
78  doMax_=pset.exists("max");
79  if (doMax_) max_=pset.getParameter<double>("max");
80 
81  std::stringstream ss;
82  ss<<"event selector based on VariableHelper variable: "<<var_;
83  description_.push_back(ss.str()); ss.str("");
84  if (doMin_){
85  ss<<"with minimum boundary: "<<min_;
86  description_.push_back(ss.str()); ss.str("");}
87  if (doMax_){
88  ss<<"with maximum boundary: "<<max_;
89  description_.push_back(ss.str()); ss.str("");}
90  }
91  bool select(const edm::Event& e) const{
93  if (!var->compute(e)) return false;
94 
95  double v=(*var)(e);
96 
97  if (doMin_ && v<min_) return false;
98  else if (doMax_ && v>max_) return false;
99  else return true;
100  }
101 
102  private:
104  bool doMin_;
105  double min_;
106  bool doMax_;
107  double max_;
108 };
109 
110 #endif
T getParameter(std::string const &) const
VariableFormulaEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
bool exists(std::string const &parameterName) const
checks if a parameter exists
VariableEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
bool select(const edm::Event &e) const
decision of the selector module
A selector of events.
Definition: EventSelector.h:16
bool compute(const edm::Event &iEvent) const
std::vector< std::string > description_
Definition: EventSelector.h:34
std::string name_
Definition: EventSelector.h:33
VariableEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
bool select(const edm::Event &e) const
decision of the selector module
std::set< std::string > vars_
VariableFormulaEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)