Diana Software
MTutorialPulseShape.cc
Go to the documentation of this file.
1 
11 #include "MTutorialPulseShape.hh"
12 #include "QEvent.hh"
13 #include "QRawEvent.hh"
14 #include "QVector.hh"
15 #include "QBaseType.hh"
16 #include "QBaselineData.hh"
17 
19 
20 using namespace Diana;
21 
23 {
24  fAveragePulseInput = GetString("AveragePulseInput","NODEFAULT");
25 
26  // require presence in the events of quantities read by this module
27  ev.Require<QPulseInfo>("DAQ","PulseInfo");
28  ev.Require<QPulse>("DAQ","Pulse");
29  ev.Require<QBaselineData>("BaselineModule","BaselineData");
30 
31  // add to event quantities written by this module.
32  ev.Add<QDouble>("ChiSquare");
33 }
34 
36 {
37  // get channel number and samples from raw event
38  const QPulseInfo& pi = ev.Get<QPulseInfo>("DAQ","PulseInfo");
39  const int chan = pi.GetChannelId();
40  const QPulse& pulse = ev.Get<QPulse>("DAQ","Pulse");
41  const QVector& samples = pulse.GetSamples();
42 
43  // get baseline value and rms computed by MBaselineModule in a previous sequence (diana_tutorial.cfg).
44  const QBaselineData& baseData = ev.Get<QBaselineData>("BaselineModule","BaselineData");
45  double baseline = baseData.GetBaseline();
46  double baselineRMS = baseData.GetBaselineRMS();
47 
48  // get amplitude (Maximum minus baseline) computed in a previous sequence (diana_tutorial.cfg).
49  const QDouble& amplitude = ev.Get<QDouble>("PulseBasicParameters","MaxBaseline");
50 
51  // get average pulse of this channel
52  GlobalHandle<QVector> apHandle("Samples");
53  apHandle.SetChannel(chan);
54  GlobalData().Get("TutorialAveragePulse",&apHandle,fAveragePulseInput);
55 
56  if(!apHandle.IsValid()) {
57  if(fChannelsWithoutAP.count(chan) == 0) {
58  fChannelsWithoutAP.insert(chan);
59  Warn("Average pulse not found for channel %04d",chan);
60  }
61  return;
62  }
63 
64  const QVector& averagePulse = apHandle.Get();
65 
66  // compute amplitude and baseline of the average pulse
67  double apBaseline = averagePulse[0];
68  double apAmplitude = averagePulse.GetMax()-apBaseline;
69 
70  // estimate chi square
71  double chisq = 0.;
72  for(size_t i =0; i < samples.Size(); i++) {
73  double res = (samples[i]-baseline) - (averagePulse[i]-apBaseline)*amplitude/apAmplitude;
74  chisq += res*res;
75 
76  }
77  chisq /= (samples.Size() - 1)*baselineRMS*baselineRMS;
78 
79  // save chi square value of this event
80  ev.Get<QDouble>("ChiSquare") = chisq;
81 
82 }
83 
85 {
86 }
87 
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
void Done()
Done method.
void Init(Diana::QEvent &ev)
Init method.
void Do(Diana::QEvent &ev)
Do method. Declare and implement only one of the two versions.
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
baseline data
double GetBaseline() const
double GetBaselineRMS() const
diana event
Definition: QEvent.hh:46
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: bolometer channel, trigger positions and types.
Definition: QPulseInfo.hh:18
const int & GetChannelId() const
Get ChannelId.
Definition: QPulseInfo.hh:22
Raw event: sampled waveform.
Definition: QPulse.hh:22
const Diana::QVector & GetSamples() const
Get Samples casted to double (QVector instead of QVectorI). Use this method in place of GetSamplesADC...
Definition: QPulse.cc:49
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...