Diana Software
MCOFBiComponent.cc
Go to the documentation of this file.
1 #include "MCOFBiComponent.hh"
2 #include "QEvent.hh"
3 #include "QEventList.hh"
4 #include "QRawEvent.hh"
5 #include "QBaseModule.hh"
6 #include "QSampleInfo.hh"
7 #include "QRunDataHandle.hh"
8 #include "QBaseType.hh"
9 #include "QBaselineData.hh"
10 #include "QTObjectHandle.hh"
11 #include "QAveragePulseHandle.hh"
12 #include "QAverageNoiseHandle.hh"
14 
16 
17 using namespace Diana;
18 
20 {
21  fAvgNoiseInput = GetString("AvgNoiseInput","");
22  fAvgPulseInputHomeMade = GetString("AvgPulseInput","");
23 
24  fAvgPulseSlowOwner = GetString("AvgPulseSlowOwner","AveragePulses",true);
25  fAvgPulseFastOwner = GetString("AvgPulseFastOwner","AveragePulses",true);
26  fAvgNoiseOwner = GetString("AvgNoiseOwner","NoiseAvgPowerSpectrum",false);
27  fMaxJitter = GetInt("MaxJitter",15);
28 
29  fDebugOn = GetBool("DebugOn",false,false);
30  fInterpolationOn = GetBool("InterpolationOn",true,true);
31  fUseDiff = GetBool("UseDiff",true,true);
32  fTomV = GetBool("ConvertTomV",true,false);
33 
34  ev.Add<QDouble>("AmplitudeSlow");
35  ev.Add<QDouble>("AmplitudeFast");
36  ev.Add<QDouble>("Integral");
37 
38  ev.Add<QDouble>("ChiSquare");
39  ev.Add<QDouble>("Jitter");
40 
41  if(fDebugOn){
42  ev.Add<QVector>("FitFunction");
43  ev.Add<QVector>("FilteredSlow");
44  ev.Add<QVector>("FilteredFast");
45  }
46  fPulseLabel = GetString("PulseLabel","DAQ@Pulse",false);
47  ev.RequireByLabel<QPulse>(fPulseLabel);
48  ev.Require<QPulseInfo>("DAQ","PulseInfo");
49  ev.Require<QHeader>("DAQ","Header");
50 
51 }
52 
53 //void MCOFBiComponent::Do(QEvent& ev, const QEventList& neighbours)
55 {
56  const QPulseInfo& pulseInfo = ev.Get<QPulseInfo>("DAQ","PulseInfo");
57  const QHeader& header = ev.Get<QHeader>("DAQ","Header");
58  const int chan = pulseInfo.GetChannelId();
59 
60  QRunDataHandle rHandle(header.GetRun());
61  GlobalData().Get("",&rHandle,"");
62 
63  const QRunData& runData = rHandle.Get();
64  const QChannelRunData& channelRunData = runData.GetChannelRunData(chan);
65  double samplingFreq = channelRunData.fSamplingFrequency;
66  double ADC2mV = 1;
67  if(fTomV) ADC2mV = channelRunData.fADC2mV;
68 
69 
70  if(fMap.find(chan) == fMap.end()) {
71 
72  GlobalHandle<QInt> dHandle("Dataset");
73  GlobalData().Get("",&dHandle,"");
74 
75 
76  fMap[chan].BlackSheep = false;
77 
78  QAverageNoiseHandle AVG_Noise_Handle(chan);
79  AVG_Noise_Handle.SetDataset(dHandle.Get());
80  GlobalData().Get(fAvgNoiseOwner,&AVG_Noise_Handle,fAvgNoiseInput);
81  if(!AVG_Noise_Handle.IsValid()) {
82  Warn("%s. Channel %d will not be processed",AVG_Noise_Handle.GetError().GetDescription().c_str(),chan);
83  fMap[chan].BlackSheep = true;
84  }
85  QAveragePulseHandle AVG_Pulse_Slow_Handle(chan);
86  AVG_Pulse_Slow_Handle.SetDataset(dHandle.Get());
87  GlobalData().Get(fAvgPulseSlowOwner,&AVG_Pulse_Slow_Handle,fAvgPulseInputHomeMade);
88  if(!fMap[chan].BlackSheep && !AVG_Pulse_Slow_Handle.IsValid()) {
89  Warn("%s. Channel %d will not be processed",AVG_Pulse_Slow_Handle.GetError().GetDescription().c_str(),chan);
90  fMap[chan].BlackSheep = true;
91  }
92  QAveragePulseHandle AVG_Pulse_Fast_Handle(chan);
93  AVG_Pulse_Fast_Handle.SetDataset(dHandle.Get());
94  GlobalData().Get(fAvgPulseFastOwner,&AVG_Pulse_Fast_Handle,fAvgPulseInputHomeMade);
95  if(!fMap[chan].BlackSheep && !AVG_Pulse_Fast_Handle.IsValid()) {
96  Warn("%s. Channel %d will not be processed",AVG_Pulse_Fast_Handle.GetError().GetDescription().c_str(),chan);
97  fMap[chan].BlackSheep = true;
98  }
99  if(!fMap[chan].BlackSheep) {
100 
101  fMap[chan].ADC2Time = 1000./samplingFreq; //ms
102 
103  QVector avg_noise = AVG_Noise_Handle.Get();
104  QVector avg_pulse_slow = AVG_Pulse_Slow_Handle.Get();
105  QVector avg_pulse_fast = AVG_Pulse_Fast_Handle.Get();
106 
107  fMap[chan].of2 = new QBiComponentOptimumFilter(avg_pulse_fast, avg_pulse_slow, avg_noise, fMaxJitter, fUseDiff);
108  }
109  }
110 
111  if (fMap[chan].BlackSheep) return;
112  const QPulse& rawPulse = ev.GetByLabel<QPulse>(fPulseLabel);
113 
114  const QVector& Samples = rawPulse.GetSamples();
115  QError err = fMap[chan].of2->Filter(Samples);
116  if(err!=QERR_SUCCESS) return;
117 
118  double a1, a2,integral, jitter;
119 
120  if(fInterpolationOn){
121  err = fMap[chan].of2->GetInterpolated(jitter,a1,a2,integral);
122  if(err!=QERR_SUCCESS) return;
123  } else {
124  jitter = fMap[chan].of2->GetJitterAtMinimum();
125  fMap[chan].of2->GetAmplitude(a1,a2,integral);
126 
127  }
128  ev.Get<QDouble>("AmplitudeFast") = a1*ADC2mV;
129  ev.Get<QDouble>("AmplitudeSlow") = a2*ADC2mV;
130  ev.Get<QDouble>("Integral") = integral*ADC2mV/samplingFreq;
131 
132  ev.Get<QDouble>("ChiSquare") = fMap[chan].of2->GetChiSquareAtMinimium();
133  ev.Get<QDouble>("Jitter") = jitter*fMap[chan].ADC2Time;
134 
135  if(fDebugOn){
136  QVector AP1f, AP2f;
137  fMap[chan].of2->GetFiltered(AP1f,AP2f);
138  ev.Get<QVector>("FilteredSlow") = AP2f;
139  ev.Get<QVector>("FilteredFast") = AP1f;
140  ev.Get<QVector>("FitFunction") = fMap[chan].of2->GetFitFunction(jitter,a1,a2);
141  }
142 }
143 
144 
146 {
147  /* This method is called at the end of the event loop.
148  * Here you can:
149  *
150  * 1) Operate on the sequence execution parameters(see QBaseModule.hh).
151  *
152  * 2) Read/Write global data.
153  */
154 }
155 
err
Definition: CheckOF.C:114
QOptimumFilter of2(ap2, an,-1, false)
QRunDataHandle rHandle(753)
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
@ QERR_SUCCESS
Definition: QError.hh:27
one-line description of your module
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.
global handle for average noise power spectra
global handle for average pulse
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
Dual component optimum filter.
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
Diana::QVector GetFitFunction(const double jitter, const double a1) const
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
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...