Diana Software
MBaselineModule.cc
Go to the documentation of this file.
1 /* Diana Reconstruction program
2  *
3  * Author: Laura Kogler 29/01/07
4  * $Id: MBaselineModule.cc 544 2006-12-11 17:57:43Z vignatim $
5  *
6  * Class MBaselineModule: Calculate baseline parameters
7  *
8 */
9 
10 
11 #include "MBaselineModule.hh"
12 #include "QVector.hh"
13 #include "QEvent.hh"
14 #include "QRawEvent.hh"
15 #include "QRunData.hh"
16 #include "QBaselineData.hh"
17 #include "QRunDataHandle.hh"
18 #include "QTypes.hh"
19 #include <math.h>
20 #include <gsl/gsl_fit.h>
21 
22 using namespace Diana;
23 
25 
26 // Init method is called before event loop
27 void MBaselineModule::Init(QEvent& ev)
28 {
29 
30  fNumberOfBaselinePoints = GetInt("NumPoints",0,false);
31  ev.Add<QBaselineData>("BaselineData");
32  ev.Require<QPulseInfo>("DAQ","PulseInfo");
33  ev.Require<QHeader>("DAQ","Header");
34  fPulseLabel = GetString("PulseLabel","DAQ@Pulse",false);
35  fTomV = GetBool("ConvertTomV",true,false);
36  ev.RequireByLabel<QPulse>(fPulseLabel);
37 
38 }
39 
40 // Doit method is called for each event, getting the event as argument
42 {
43 
44  const QVector& samples = ev.GetByLabel<QPulse>(fPulseLabel).GetSamples();
45  const int run = ev.Get<QHeader>("DAQ","Header").GetRun();
46  const int channel = ev.Get<QPulseInfo>("DAQ","PulseInfo").GetChannelId();
47  QBaselineData& bData = ev.Get<QBaselineData>("BaselineData");
48 
49  size_t nSamples = samples.Size();
50  const double* SampleArray = samples.GetConstArray();
51  size_t nPoints;
52  if(fNumberOfBaselinePoints < 0.)
53  nPoints = nSamples;
54  else if(fNumberOfBaselinePoints == 0) {
55  nPoints = int(ev.Get<QPulseInfo>("DAQ","PulseInfo").GetMasterSample().GetSampleIndex()*3./4);
56  } else {
57  nPoints = fNumberOfBaselinePoints;
58  }
59  if(nPoints > nSamples) {
60  Warn("Number of points (%d) exceeds number of samples (%d): setting it to %d",
61  nPoints, nSamples, nSamples);
62  nPoints = nSamples;
63  }
64  Double_t* TimeArray = new Double_t[nPoints];
65  for(size_t i = 0; i < nPoints; i++)
66  TimeArray[i] = (Double_t)i;
67 
68  fBaseline = samples.Sum(nPoints,0);
69  fBaseline /= nPoints;
70  fRightBaseline = samples.Sum(nPoints,samples.Size()-1-nPoints)/nPoints;
71  fRightLeftBaseline = fRightBaseline - fBaseline;
72 
73  double cov00, cov01, cov11;
74  gsl_fit_linear (TimeArray, 1, SampleArray, 1, nPoints,
75  &fBaselineIntercept, &fBaselineSlope, &cov00, &cov01, &cov11, &fBaselineRMS);
76 
77 
78  fBaselineRMS = sqrt(fBaselineRMS/nPoints); // this gives RMS of deviation from best fit to baseline
79  double baselineFlatRMS = samples.GetRMS(nPoints,0);
80 
81  fBaselineSlopeRMSWindow = fBaselineSlope/fBaselineRMS*(double)nSamples;
82  fRightBaselineInRMS = fRightBaseline/fBaselineRMS;
83  fRightLeftBaselineInRMS = fRightLeftBaseline/fBaselineRMS;
84 
86  GlobalData().Get("",&rHandle,"");
87  const QRunData& runData = rHandle.Get();
89  double ADC2mV = 1;
90  if(fTomV) ADC2mV = chanRunData.fADC2mV;
91 
92  // Event assignement
93  bData.SetBaseline(fBaseline*ADC2mV);
94  bData.SetRightBaseline(fRightBaseline*ADC2mV);
95  bData.SetRightLeftBaseline(fRightLeftBaseline*ADC2mV);
96  bData.SetRightBaselineInRMS(fRightBaselineInRMS);
97  bData.SetRightLeftBaselineInRMS(fRightLeftBaselineInRMS);
98  bData.SetBaselineIntercept(fBaselineIntercept*ADC2mV);
99  bData.SetBaselineSlope(fBaselineSlope*ADC2mV);
100  bData.SetBaselineSlopeRMSWindow(fBaselineSlopeRMSWindow);
101  bData.SetBaselineRMS(fBaselineRMS*ADC2mV);
102  bData.SetBaselineFlatRMS(baselineFlatRMS*ADC2mV);
103 
104  Debug("Mean is %f, Intercept is %f, Slope is %f, RMS is %f",fBaseline, fBaselineIntercept,fBaselineSlope, fBaselineRMS);
105  delete [] TimeArray;
106 }
107 
108 // Done method is called after event loop
110 {
111 
112 }
QRunDataHandle rHandle(753)
const int channel
QChannelRunData chanRunData
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
Module to calculate baseline parameters.
void Do(Diana::QEvent &ev)
baseline data
void SetRightBaselineInRMS(double b)
void SetBaselineRMS(double b)
void SetRightBaseline(double b)
void SetRightLeftBaseline(double b)
void SetRightLeftBaselineInRMS(double b)
void SetBaselineSlopeRMSWindow(double b)
void SetBaselineSlope(double b)
void SetBaseline(double b)
void SetBaselineIntercept(double b)
void SetBaselineFlatRMS(double b)
basic channel and run based info. Used in the QRunData object.
double fADC2mV
conversion: mV = ADC * fADC2mV
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
Raw event: bolometer channel, trigger positions and types.
Definition: QPulseInfo.hh:18
const QSampleInfo & GetMasterSample() const
Get MasterSample.
Definition: QPulseInfo.hh:26
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
Int_t GetSampleIndex() const
Get SampleIndex from the beginning of the waveform.
Definition: QSampleInfo.hh:51
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...