Diana Software
MTwoVariablesEnergyFilter.cc
Go to the documentation of this file.
2 #include "QEvent.hh"
3 #include "QEventList.hh"
4 #include "QRunData.hh"
5 #include "QBaseType.hh"
6 #include "QString.hh"
7 #include "QPulseInfo.hh"
8 #include "QHeader.hh"
9 #include "QInterval.hh"
10 #include "QRunDataHandle.hh"
11 #include "QEnergyRangesHandle.hh"
12 #include "QFrameWorkConfig.hh"
13 #include <map>
14 #include <set>
15 #include <string>
16 
17 using std::map;
18 using std::set;
19 using std::string;
20 
21 using namespace Diana;
22 
24 
25 void MTwoVariablesEnergyFilter::GetCuts(const QEvent& ev)
26 {
27 
28  // define Energy ranges input (file ore DB, for the moment only file work)
29  fEnergyRangesInput = GetString("EnergyRangesInput", "EnergyRanges.txt");
30  fChiSquareRangesInput = GetString("ChiSquareRangesInput", "ChiSquareRanges.txt");
31 
32  QEnergyRangesHandle eHandle;
33  QEnergyRangesHandle csHandle;
34  fEnergyRangesName = GetString("EnergyRangesName",eHandle.GetName(),false);
35  fChiSquareRangesName = GetString("ChiSquareRangesName",csHandle.GetName(),false);
36 
37  // define Energy label
38  fEnergyLabel = GetString("EnergyLabel","ApplyCalibration@Energy");
39  fChiSquareLabel = GetString("ChiSquareLabel","OTAnalysis@FitChiSquare");
40 
41  // max energy for flat ChiSquare cut
42  fChiSquareCutMaxEnergy = GetDouble("ChiSquareCutMaxEnergy",1100);
43 
44  ev.RequireByLabel<QDouble>(fEnergyLabel);
45  ev.RequireByLabel<QDouble>(fChiSquareLabel);
46  ev.Require<QPulseInfo>("DAQ","PulseInfo");
47  ev.Require<QHeader>("DAQ","Header");
48  fBlackList.clear();
49  fChannelList.clear();
50 
51 }
52 
53 //bool MTwoVariablesEnergyFilter::Filter(const QEvent& ev, const QEventList& neighbours)
55 {
56 
57  // perform selection: true if the event passes the cuts
58  const QPulseInfo& pi = ev.Get<QPulseInfo>("DAQ","PulseInfo");
59  const QHeader& header = ev.Get<QHeader>("DAQ","Header");
60  const int run = header.GetRun();
61 
62  if(run != fRunData.fNumber) {
64  GlobalData().Get<QRunData>("",&rHandle,"");
65  fRunData = rHandle.Get();
66 
67  // get dataset
68  GlobalHandle<QInt> dHandle("Dataset");
69  GlobalData().Get("",&dHandle,"");
70  fDataset = dHandle.Get();
71  }
72 
73  // get channel of event
74  const int& channel = pi.GetChannelId();
75  fEnergyRange.Clear();
76 
77 
78  // get energy ranges for that channel
79  QEnergyRangesHandle eHandle(fEnergyRangesName);
80  eHandle.SetChannel(channel);
81  GlobalData().Get("User",&eHandle,fEnergyRangesInput);
82  if(!eHandle.IsValid()) {
83  eHandle.SetCalibVersion(GetConfig().fVersionTag);
84  eHandle.SetDataset(fDataset);
85  GlobalHandle<QString> clabelh("CalibrationLabel");
86  clabelh.SetDataset(fDataset);
87  clabelh.SetChannel(channel);
88  GlobalData().Get(fEnergyLabel.owner,&clabelh,"CurrentReader");
89  if(clabelh.IsValid()) {
90  eHandle.SetCalibLabel(clabelh.Get());
91  } else {
92  eHandle.SetCalibLabel("");
93  }
94  GlobalData().Get("EnergyFilter",&eHandle,fEnergyRangesInput);
95  }
96 
97  if(!eHandle.IsValid() && !fBlackList.count(channel))
98  {
99  fEnergyMin = GetDouble("EnergyMin",0);
100  fEnergyMax = GetDouble("EnergyMax",100000);
101  Info("Channel %d has no energy range: %s. Using [%f,%f]",channel,eHandle.GetError().GetDescription().c_str(),fEnergyMin,fEnergyMax);
102  fBlackList.insert(channel);
103  }
104  if(eHandle.IsValid() && !fBlackList.count(channel)
105  && eHandle.Get().GetMax() < eHandle.Get().GetMin()) {
106 
107  fEnergyMin = GetDouble("EnergyMin",0);
108  fEnergyMax = GetDouble("EnergyMax",100000);
109  Error("Channel %d has wrong energy range. fMin = %f; fMax = %f. Using [%f,%f]",channel,eHandle.Get().GetMin(),eHandle.Get().GetMax(),fEnergyMin,fEnergyMax);
110  fBlackList.insert(channel);
111  }
112 
113  // cfg defined range, to be applied to channels for which no energy range is defined in the file
114  if(fBlackList.count(channel)) {
115  fEnergyRange.SetMax(fEnergyMax);
116  fEnergyRange.SetMin(fEnergyMin);
117  }
118  else fEnergyRange = eHandle.Get();
119 
120 
121  // get energy of the event
122  const double energy = ev.GetByLabel<QDouble>(fEnergyLabel);
123 
124 
125  bool passed = false;
126 
127  // if energy is in the desired range check the ChiSquare
128  if(fEnergyRange.Contains(energy)){
129 
130  // get ChiSquare ranges for that channel
131  QEnergyRangesHandle csHandle(fChiSquareRangesName);
132  csHandle.SetChannel(channel);
133  GlobalData().Get("User",&csHandle,fChiSquareRangesInput);
134 
135  if(!csHandle.IsValid()) {
136  //csHandle.SetCalibVersion(GetConfig().fVersionTag);
137  csHandle.SetDataset(fDataset);
138  GlobalHandle<QString> cslabelh("ChiSquareLabel");
139  cslabelh.SetDataset(fDataset);
140  cslabelh.SetChannel(channel);
141  GlobalData().Get(fChiSquareLabel.owner,&cslabelh,"CurrentReader");
142  if(cslabelh.IsValid()) {
143  csHandle.SetCalibLabel(cslabelh.Get());
144  } else {
145  csHandle.SetCalibLabel("");
146  }
147  GlobalData().Get("EnergyFilter",&csHandle,fChiSquareRangesInput);
148  }
149 
150 
151  if(!csHandle.IsValid() && !fBlackList.count(channel))
152  {
153  fChiSquareMin = GetDouble("ChiSquareMin",0);
154  fChiSquareMax = GetDouble("ChiSquareMax",3);
155  Info("Channel %d has no ChiSquare range: %s. Using [%f,%f]",channel,csHandle.GetError().GetDescription().c_str(),fChiSquareMin,fChiSquareMax);
156  fBlackList.insert(channel);
157  }
158  if(csHandle.IsValid() && !fBlackList.count(channel)
159  && csHandle.Get().GetMax() < csHandle.Get().GetMin()) {
160 
161  fChiSquareMin = GetDouble("ChiSquareMin",0);
162  fChiSquareMax = GetDouble("ChiSquareMax",3);
163  Error("Channel %d has wrong ChiSquare range. fMin = %f; fMax = %f. Using [%f,%f]",channel,csHandle.Get().GetMin(),csHandle.Get().GetMax(),fChiSquareMin,fChiSquareMax);
164  fBlackList.insert(channel);
165  }
166 
167  // cfg defined range, to be applied to channels for which no ChiSquare range is defined in the file
168  if(fBlackList.count(channel)) {
169  fChiSquareRange.SetMax(fChiSquareMax);
170  fChiSquareRange.SetMin(fChiSquareMin);
171  }
172  else fChiSquareRange = csHandle.Get();
173 
174 
175  // get ChiSquare of the event
176  const double ChiSquare = ev.GetByLabel<QDouble>(fChiSquareLabel);
177 
178 
179  if((energy <= fChiSquareCutMaxEnergy && fChiSquareRange.Contains(ChiSquare)) || energy > fChiSquareCutMaxEnergy) passed = true;
180 
181  }
182 
183  return passed;
184 
185 
186 }
187 /*
188 void MTwoVariablesEnergyFilter::Done(){
189 
190  return;
191 
192 }
193 */
QRunDataHandle rHandle(753)
const int channel
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
energy threshold cut and flat ChiSquare cut (on a finite range) depending on the channel
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
global handle for EnergyRanges
void SetCalibVersion(const std::string &stabv)
void SetCalibLabel(const std::string &stabl)
diana event
Definition: QEvent.hh:46
const Q & GetByLabel(const QEventLabel &label) const
Get a QObject in read mode by label.
Definition: QEvent.hh:135
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
Raw event: basic information like run number and time.
Definition: QHeader.hh:16
int GetRun() const
destructor
Definition: QHeader.hh:22
Raw event: bolometer channel, trigger positions and types.
Definition: QPulseInfo.hh:18
const int & GetChannelId() const
Get ChannelId.
Definition: QPulseInfo.hh:22
global handle for QRunData
Basic run based info.
Definition: QRunData.hh:20
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...