CMS 3D CMS Logo

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 
11 public:
15  const std::string name_ = pset.getParameter<std::string>("fname");
16  TString ts(pset.getParameter<std::string>("formula"));
17  //find the variables. register and replace
18  int open = ts.Index("[");
19  int close = ts.Index("]");
20  while (open > 0) {
21  ++open;
22  TString sub(ts(open, close - open));
23  //std::cout<<"found:"<< sub <<std::endl;
24  vars_.insert(sub.Data());
25  //vars_.insert( ts(open,close-open));
26  open = ts.Index("[", open);
27  close = ts.Index("]", open);
28  }
29 
30  unsigned int v_i;
31  std::set<std::string>::iterator v_it;
32  for (v_i = 0, v_it = vars_.begin(); v_i != vars_.size(); ++v_i, ++v_it) {
33  ts.ReplaceAll(TString::Format("[%s]", v_it->c_str()), TString::Format("[%d]", v_i));
34  }
35 
36  //std::cout<<" formula found:"<< ts <<std::endl;
37  formula_ = new TFormula(name_.c_str(), ts);
38  //vars_ = pset.getParameter<std::vector<std::string>>("variables");
39  threshold_ = pset.getParameter<double>("threshold");
40  }
41 
42  bool select(const edm::Event& e) const override {
43  unsigned int v_i;
44  std::set<std::string>::iterator v_it;
45 
46  for (v_i = 0, v_it = vars_.begin(); v_i != vars_.size(); ++v_i, ++v_it) {
47  const CachingVariable* var = edm::Service<VariableHelperService>()->get().variable(*v_it);
48  if (!var->compute(e))
49  return false;
50  double v = (*var)(e);
51  formula_->SetParameter(v_i, v);
52  }
53 
54  //should be valuated 0. or 1. in double
55  return (formula_->Eval(0.) >= threshold_);
56  }
57 
58 private:
59  //std::string formula_;
60  TFormula* formula_;
61  std::set<std::string> vars_;
62  double threshold_;
63 };
64 
66 public:
69  var_ = pset.getParameter<std::string>("var");
70  doMin_ = pset.exists("min");
71  if (doMin_)
72  min_ = pset.getParameter<double>("min");
73  doMax_ = pset.exists("max");
74  if (doMax_)
75  max_ = pset.getParameter<double>("max");
76 
77  std::stringstream ss;
78  ss << "event selector based on VariableHelper variable: " << var_;
79  description_.push_back(ss.str());
80  ss.str("");
81  if (doMin_) {
82  ss << "with minimum boundary: " << min_;
83  description_.push_back(ss.str());
84  ss.str("");
85  }
86  if (doMax_) {
87  ss << "with maximum boundary: " << max_;
88  description_.push_back(ss.str());
89  ss.str("");
90  }
91  }
92  bool select(const edm::Event& e) const override {
93  const CachingVariable* var = edm::Service<VariableHelperService>()->get().variable(var_);
94  if (!var->compute(e))
95  return false;
96 
97  double v = (*var)(e);
98 
99  if (doMin_ && v < min_)
100  return false;
101  else if (doMax_ && v > max_)
102  return false;
103  else
104  return true;
105  }
106 
107 private:
109  bool doMin_;
110  double min_;
111  bool doMax_;
112  double max_;
113 };
114 
115 #endif
EventSelector.h
VariableEventSelector::VariableEventSelector
VariableEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
Definition: VariableEventSelector.h:68
VariableEventSelector::min_
double min_
Definition: VariableEventSelector.h:110
CachingVariable
Definition: CachingVariable.h:40
VariableEventSelector::doMax_
bool doMax_
Definition: VariableEventSelector.h:111
VariableFormulaEventSelector::vars_
std::set< std::string > vars_
Definition: VariableEventSelector.h:61
findQualityFiles.v
v
Definition: findQualityFiles.py:179
VariableFormulaEventSelector::select
bool select(const edm::Event &e) const override
decision of the selector module
Definition: VariableEventSelector.h:42
VariableFormulaEventSelector::VariableFormulaEventSelector
VariableFormulaEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
Definition: VariableEventSelector.h:14
EventSelector::description_
std::vector< std::string > description_
Definition: EventSelector.h:33
trigObjTnPSource_cfi.var
var
Definition: trigObjTnPSource_cfi.py:21
EventSelector::name_
std::string name_
Definition: EventSelector.h:32
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
VariableEventSelector::VariableEventSelector
VariableEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
Definition: VariableEventSelector.h:67
VariableEventSelector::max_
double max_
Definition: VariableEventSelector.h:112
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:36
VariableFormulaEventSelector
Definition: VariableEventSelector.h:10
edm::Service
Definition: Service.h:30
VariableEventSelector::var_
std::string var_
Definition: VariableEventSelector.h:108
VariableEventSelector::doMin_
bool doMin_
Definition: VariableEventSelector.h:109
VariableFormulaEventSelector::VariableFormulaEventSelector
VariableFormulaEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
Definition: VariableEventSelector.h:12
VariableFormulaEventSelector::threshold_
double threshold_
Definition: VariableEventSelector.h:62
VariableEventSelector::select
bool select(const edm::Event &e) const override
decision of the selector module
Definition: VariableEventSelector.h:92
EventSelector
A selector of events.
Definition: EventSelector.h:16
VariableHelper.h
ConsumesCollector.h
edm::Event
Definition: Event.h:73
VariableEventSelector
Definition: VariableEventSelector.h:65
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
VariableFormulaEventSelector::formula_
TFormula * formula_
Definition: VariableEventSelector.h:60
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37