Diana Software
MFilterInInterval.cc
Go to the documentation of this file.
1 #include "MFilterInInterval.hh"
2 #include "QEvent.hh"
3 #include "QBaseType.hh"
4 #include <map>
5 #include <set>
6 #include <string>
7 
8 using std::map;
9 using std::set;
10 using std::string;
11 
12 using namespace Diana;
13 
15 
16 void MFilterInInterval::GetCuts(const Diana::QEvent& ev)
17 {
18  // Get parameters from cfg
19 
20  // define variable label (variable on which the cut is applied)
21  fVariableLabel = GetString("VariableLabel","");
22 
23  // define minimum and maximum value for the variable
24  fMinValue = GetDouble("MinValue",Q_DOUBLE_DEFAULT);
25  fMaxValue = GetDouble("MaxValue",Q_DOUBLE_DEFAULT);
26 
27  fIsWarned = false;
28 
29  ev.RequireByLabel<QDouble>(fVariableLabel);
30 }
31 
32 bool MFilterInInterval::Filter(const Diana::QEvent& ev)
33 {
34  // get variable from event
35  const double variable = ev.GetByLabel<QDouble>(fVariableLabel);
36 
37  bool passed = false;
38 
39  // perform selection: true if the event passes the cuts
40  if(fMinValue==Q_DOUBLE_DEFAULT && fMaxValue!=Q_DOUBLE_DEFAULT)
41  {
42  // applies only upper limit
43  if (variable<=fMaxValue) passed = true;
44  }
45  if(fMaxValue==Q_DOUBLE_DEFAULT && fMinValue!=Q_DOUBLE_DEFAULT)
46  {
47  // applies only lower limit
48  if (variable>=fMinValue) passed = true;
49  }
50  // no range specified
51  if(fMaxValue==Q_DOUBLE_DEFAULT && fMinValue==Q_DOUBLE_DEFAULT && !fIsWarned)
52  {
53  Warn("No range specified. The variable will not be filtered");
54  fIsWarned= true;
55  }
56  // wrong range (max < min)
57  if(fMaxValue!=Q_DOUBLE_DEFAULT && fMinValue!=Q_DOUBLE_DEFAULT && fMaxValue <= fMinValue && !fIsWarned)
58  {
59  Warn("Wrong Range (Max %f <= Min %f). The variable will not be filtered",fMaxValue,fMinValue);
60  fIsWarned= true;
61  }
62  else
63  {
64  if (variable>fMinValue && variable<fMaxValue) passed = true;
65  }
66 
67  return passed;
68 
69 }
#define Q_DOUBLE_DEFAULT
Definition: QDiana.hh:24
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
Generic module to filter a double variable withing a range [min, max], inclusive.
bool Filter(const Diana::QEvent &ev)
return true if ev passes the cuts
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
diana event
Definition: QEvent.hh:46
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...