Diana Software
MFilterInIntervalI.cc
Go to the documentation of this file.
1 #include "MFilterInIntervalI.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 MFilterInIntervalI::GetCuts(const Diana::QEvent& ev)
17 {
18  // Get parameters from cfg
19  // define variable label (variable on which the cut is applied)
20  fVariableLabel = GetString("VariableLabel", "");
21 
22  // define minimum and maximum value for the variable
23  fMinValue = GetInt("MinValue", Q_INT_DEFAULT);
24  fMaxValue = GetInt("MaxValue", Q_INT_DEFAULT);
25 
26  fError = false;
27  if (fMaxValue == Q_INT_DEFAULT && fMinValue == Q_INT_DEFAULT) {
28  Error("No range specified. The variable (%s) will not be filtered", fVariableLabel.GetStringLabel().c_str());
29  fError = true;
30  }
31  else if (fMaxValue != Q_INT_DEFAULT && fMinValue != Q_INT_DEFAULT && fMaxValue < fMinValue) {
32  Error("Bad range (max < min). The variable (%s) will not be filtered", fVariableLabel.GetStringLabel().c_str());
33  fError = true;
34  }
35 
36  ev.RequireByLabel<QInt>(fVariableLabel);
37 }
38 
39 bool MFilterInIntervalI::Filter(const Diana::QEvent& ev)
40 {
41  // get variable from event
42  const int variable = ev.GetByLabel<QInt>(fVariableLabel);
43 
44  if (fError)
45  return false;
46  if (fMinValue == Q_INT_DEFAULT && fMaxValue != Q_INT_DEFAULT)
47  return variable <= fMaxValue; // applies only upper limit
48  if (fMaxValue == Q_INT_DEFAULT && fMinValue != Q_INT_DEFAULT)
49  return variable >= fMinValue; // applies only lower limit
50 
51  return (variable >= fMinValue && variable <= fMaxValue);
52 }
#define Q_INT_DEFAULT
Definition: QDiana.hh:26
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
Generic module to filter an int 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...