Diana Software
MTutorialAveragePulse.cc

Example module which produces a raw average pulse for each channel, implementation file.

Author
Marco Vignati

See header in MTutorialAveragePulse.hh.

#include "QEvent.hh"
#include "QEventList.hh"
#include "QPulseInfo.hh"
#include "QPulse.hh"
using namespace Diana;
// Init method is called before the event loop
{
// Get output file name from config file
fOutput = GetString("Output","avg/averagepulses.root");
}
// Do method is called on each event which passes
// filter selection
{
// Get channel number and raw samples from the event
const QPulseInfo& pulseInfo = ev.Get<QPulseInfo>("DAQ","PulseInfo");
const int chan = pulseInfo.GetChannelId();
const QPulse& pulse = ev.Get<QPulse>("DAQ","Pulse");
const QVector& samples = pulse.GetSamples();
// if this is the first event for this channel, initialize to zero the variables for the average.
if(fAveragePulses.find(chan) == fAveragePulses.end()) {
fAveragePulses[chan].fNumberOfEvents = 0;
fAveragePulses[chan].fSamples.Resize(samples.Size());
fAveragePulses[chan].fSamples.Initialize(0.);
}
// sum up QVectors and record the number of calls for each channel
fAveragePulses[chan].fSamples += samples;
fAveragePulses[chan].fNumberOfEvents++;
}
// Done method is called at the end of the event loop
{
std::map<int,ChannelInfo>::const_iterator iter = fAveragePulses.begin();
while(iter != fAveragePulses.end()) {
// divide the sum by the number of calls
const int chan = iter->first;
QVector ap = iter->second.fSamples;
int nev = iter->second.fNumberOfEvents;
ap /= nev;
// store average QVector on output file with name Samples, and set the channel number as key for this object.
// The label of this object will be: TutorialAveragePulse@Samples_chan%04d
// (In official data processing the module used is MAveragePulses,
// which saves objects of type QAveragePulse via the QAveragePulseHandle which implements the I/O with the DB.
GlobalHandle<QVector> apHandle("Samples");
apHandle.SetChannel(chan);
apHandle.Set(ap);
GlobalData().Set(&apHandle,fOutput);
iter++;
}
}
ap
Definition: CheckOFShape.C:47
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
template class to handle diana global QObject with QGlobalDataManager
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
Interface for vectors in Diana analysis.
Definition: QVector.hh:30
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...