Diana Software
MTutorialAveragePulse.cc
Go to the documentation of this file.
1 
11 #include "MTutorialAveragePulse.hh"
12 #include "QEvent.hh"
13 #include "QEventList.hh"
14 #include "QPulseInfo.hh"
15 #include "QPulse.hh"
16 
18 
19 using namespace Diana;
20 
21 // Init method is called before the event loop
23 {
24  // Get output file name from config file
25  fOutput = GetString("Output","avg/averagepulses.root");
26 }
27 
28 // Do method is called on each event which passes
29 // filter selection
31 {
32  // Get channel number and raw samples from the event
33  const QPulseInfo& pulseInfo = ev.Get<QPulseInfo>("DAQ","PulseInfo");
34  const int chan = pulseInfo.GetChannelId();
35  const QPulse& pulse = ev.Get<QPulse>("DAQ","Pulse");
36  const QVector& samples = pulse.GetSamples();
37 
38  // if this is the first event for this channel, initialize to zero the variables for the average.
39  if(fAveragePulses.find(chan) == fAveragePulses.end()) {
40  fAveragePulses[chan].fNumberOfEvents = 0;
41  fAveragePulses[chan].fSamples.Resize(samples.Size());
42  fAveragePulses[chan].fSamples.Initialize(0.);
43  }
44 
45  // sum up QVectors and record the number of calls for each channel
46  fAveragePulses[chan].fSamples += samples;
47  fAveragePulses[chan].fNumberOfEvents++;
48 }
49 
50 // Done method is called at the end of the event loop
52 {
53  std::map<int,ChannelInfo>::const_iterator iter = fAveragePulses.begin();
54  while(iter != fAveragePulses.end()) {
55  // divide the sum by the number of calls
56  const int chan = iter->first;
57  QVector ap = iter->second.fSamples;
58  int nev = iter->second.fNumberOfEvents;
59  ap /= nev;
60 
61  // store average QVector on output file with name Samples, and set the channel number as key for this object.
62  // The label of this object will be: TutorialAveragePulse@Samples_chan%04d
63  // (In official data processing the module used is MAveragePulses,
64  // which saves objects of type QAveragePulse via the QAveragePulseHandle which implements the I/O with the DB.
65  GlobalHandle<QVector> apHandle("Samples");
66  apHandle.SetChannel(chan);
67  apHandle.Set(ap);
68  GlobalData().Set(&apHandle,fOutput);
69  iter++;
70  }
71 }
72 
ap
Definition: CheckOFShape.C:47
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
void Do(Diana::QEvent &ev)
Do method. Declare and implement only one of the two versions.
void Init(Diana::QEvent &ev)
Init method.
diana event
Definition: QEvent.hh:46
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
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...