Diana Software
MPulseTimeConstants.cc
Go to the documentation of this file.
1 #include "MPulseTimeConstants.hh"
2 #include "QEvent.hh"
3 #include "QEventList.hh"
4 #include "QBaseType.hh"
5 #include "QInterval.hh"
6 #include "QRawEvent.hh"
7 #include "QBaselineData.hh"
8 #include "QPulseParameters.hh"
9 #include "QRunDataHandle.hh"
10 
11 
13 
14 using namespace Diana;
15 using namespace std;
16 
18 {
19  fTimeConstants = 0;
20  fRiseVars.clear(); fDecayVars.clear();
21 
22  int nrise = GetInt("NumberOfRiseTimes", 1);
23  if(nrise < 0) Panic("NumberOfRiseTimes must be >= 0");
24  vector<QInterval> rises;
25  for(int i = 1; i < nrise+1; i++) {
26  char buf[256];
27  char buf2[256];
28  snprintf(buf,256,"RiseTime%d_Interval",i);
29  vector<int> in; in.push_back(10); in.push_back(90);
30  in = GetVectorInt(buf,in);
31  if(in.size() != 2) Panic("%s needs 2 parameters instead of %d",buf,in.size());
32  else if(in[0] > in[1]) Panic("%s: first element (%d) must be smaller than second element (%d)",buf,in[0],in[1]);
33  else if(in[1] > 100) Panic("%s: elements cannot be greater than 100",buf);
34  else if(in[0] < 0 ) Panic("%s: elements cannot be negative",buf);
35 
36  QInterval rise;
37  rise.SetMin(double(in[0])/100); rise.SetMax(double(in[1])/100);
38  rises.push_back(rise);
39 
40  snprintf(buf,256,"RiseTime%02d%02d",in[0],in[1]);
41  snprintf(buf2,256,"RiseTime%02d%02dWindow",in[0],in[1]);
42  ev.Add<QDouble>(buf);
43  ev.Add<QDouble>(buf2);
44  fRiseVars.push_back(buf);
45  }
46 
47  int ndecay = GetInt("NumberOfDecayTimes", 1);
48  if(ndecay < 0) Panic("NumberOfDecayTimes must be >= 0");
49  vector<QInterval> decays;
50  for(int i = 1; i < ndecay+1; i++) {
51  char buf[256];
52  char buf2[256];
53  snprintf(buf,256,"DecayTime%d_Interval",i);
54  vector<int> in; in.push_back(90); in.push_back(30);
55  in = GetVectorInt(buf,in);
56  if(in.size() != 2) Panic("%s needs 2 parameters instead of %d",buf,in.size());
57  else if(in[1] > in[0]) Panic("%s: first element (%d) must be greater than second element (%d)",buf,in[0],in[1]);
58  else if(in[0] > 100) Panic("%s: elements cannot be greater than 100",buf);
59  else if(in[1] < 0 ) Panic("%s: elements cannot be negative",buf);
60 
61  QInterval decay;
62  decay.SetMin(double(in[1])/100); decay.SetMax(double(in[0])/100);
63  decays.push_back(decay);
64 
65  snprintf(buf,256,"DecayTime%02d%02d",in[0],in[1]);
66  snprintf(buf2,256,"DecayTime%02d%02dWindow",in[0],in[1]);
67  ev.Add<QDouble>(buf);
68  ev.Add<QDouble>(buf2);
69  fDecayVars.push_back(buf);
70  }
71 
72  fTimeConstants = new QPulseTimeConstants(rises,decays);
73 
74  fPulseLabel = GetString("PulseLabel","DAQ@Pulse",false);
75  fInputExtraLabel = GetString("InputExtraLabel","",false);
76  fBaselineOwner = GetString("BaselineOwner","BaselineModule",false);
77  fPulseBasicParamsOwner = GetString("PulseBasicParametersOwner","PulseBasicParameters",false);
78  if(!fInputExtraLabel.empty()) {
79  fInputExtraLabel.insert(0,"_");
80  fBaselineOwner += fInputExtraLabel;
81  fPulseBasicParamsOwner += fInputExtraLabel;
82  }
83  fTomV = GetBool("ConvertTomV",true,false);
84 
85  ev.RequireByLabel<QPulse>(fPulseLabel);
86  ev.Require<QBaselineData>(fBaselineOwner,"BaselineData");
87  ev.Require<QPulseParameters>(fPulseBasicParamsOwner,"Parameters");
88  ev.Require<QHeader>("DAQ","Header");
89  ev.Require<QPulseInfo>("DAQ","PulseInfo");
90 
91 }
92 
94 {
95  const QHeader& header = ev.Get<QHeader>("DAQ","Header");
96  const int channel = ev.Get<QPulseInfo>("DAQ","PulseInfo").GetChannelId();
97  const int run = header.GetRun();
99  GlobalData().Get("",&rHandle,"");
100  const QRunData& runData = rHandle.Get();
102 
103  double ADC2mV = 1;
104  if(fTomV) ADC2mV = chanRunData.fADC2mV;
105  const double samplingFreq = chanRunData.fSamplingFrequency;
106 
107  const QVector& samples = ev.GetByLabel<QPulse>(fPulseLabel).GetSamples();
108  const double baseline = ev.Get<QBaselineData>(fBaselineOwner.c_str(),"BaselineData").GetBaseline()/ADC2mV;
109  int maxPos = ev.Get<QPulseParameters>(fPulseBasicParamsOwner.c_str(),"Parameters").fMaxPosition;
110 
111 
112  vector<double> outputRise,outputDecay;
113  QError err = fTimeConstants->Compute(samples,maxPos,baseline,outputRise,outputDecay);
114  if(err != QERR_SUCCESS) return;
115 
116  if(outputRise.size() != fRiseVars.size()) Panic("Output rise time variables differ in number from expected");
117  for(size_t i = 0; i < outputRise.size(); i++) {
118  ev.Get<QDouble>(fRiseVars[i].c_str()) = outputRise[i]/samplingFreq;
119  ev.Get<QDouble>((fRiseVars[i]+"Window").c_str()) = outputRise[i]/(double)samples.Size();
120  }
121 
122  if(outputDecay.size() != fDecayVars.size()) Panic("Output decay time variables differ in number from expected");
123  for(size_t i = 0; i < outputDecay.size(); i++) {
124  ev.Get<QDouble>(fDecayVars[i].c_str()) = outputDecay[i]/samplingFreq;
125  ev.Get<QDouble>((fDecayVars[i]+"Window").c_str()) = outputDecay[i]/(double)samples.Size();
126  }
127 }
128 
130 {
131  if(fTimeConstants) delete fTimeConstants;
132 }
133 
err
Definition: CheckOF.C:114
QRunDataHandle rHandle(753)
const int channel
QChannelRunData chanRunData
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
@ QERR_SUCCESS
Definition: QError.hh:27
Computes rise and decay times of a pulse.
void Do(Diana::QEvent &ev)
Do method. Declare and implement only one of the two versions.
void Done()
Done method.
void Init(Diana::QEvent &ev)
Init method.
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
baseline data
basic channel and run based info. Used in the QRunData object.
double fSamplingFrequency
sampling frequency in Hz
double fADC2mV
conversion: mV = ADC * fADC2mV
error class with error type and description
Definition: QError.hh:115
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 RequireByLabel(const QEventLabel &label) const
notify the QEvent that we need a QObject, if not found an exception is thrown
Definition: QEvent.hh:242
void Require(const std::string &owner, const std::string &name) const
notify the QEvent that we need a QObject, if not found an exception is thrown
Definition: QEvent.hh:232
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
void Add(WriteHandle< Q > &handle)
Add a QObject to the event.
Definition: QEvent.hh:193
Raw event: basic information like run number and time.
Definition: QHeader.hh:16
int GetRun() const
destructor
Definition: QHeader.hh:22
Interval of real numbers.
Definition: QInterval.hh:17
void SetMin(const double min)
Set minimum of the interval.
Definition: QInterval.hh:71
void SetMax(const double max)
Set maximum of the interval.
Definition: QInterval.hh:68
Raw event: bolometer channel, trigger positions and types.
Definition: QPulseInfo.hh:18
basic pulse informations
Raw event: sampled waveform.
Definition: QPulse.hh:22
global handle for QRunData
Basic run based info.
Definition: QRunData.hh:20
const QChannelRunData & GetChannelRunData(const int channel) const
get channel based run data quantities
Definition: QRunData.cc:339
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...