Diana Software
MAdvancedPeakFinder.cc
Go to the documentation of this file.
1 #include "MAdvancedPeakFinder.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 <TMath.h>
11 #include "QCountPulsesData.hh"
12 
14 
15 using namespace Diana;
16 
18 {
19  //Getting Arguments from cfg
20  fPulseLabel = GetString("PulseLabel","DAQ@Pulse",false);
21  TriggerAlgo = GetString("Algorithm","BULLDAQ",false);
22  fDebounce = GetDouble("Debounce",0,false);
23  fSaveFiltered = GetBool("SaveFiltered",false,false);
24  fSaveHeight = GetBool("SaveHeight", false, false);
25  if(fDebounce >=1){
26  Panic("Choose a value between 0 and 1 excluded!");
27  }
28  //adding members to .root file
29  if(fSaveFiltered){
30  ev.Add<QPulse>("Peaks");
31  }
32  if(fSaveHeight){
33  ev.Add<QDouble>("HighestTrigger");
34  }
35  ev.Add<QCountPulsesData>("CountPulsesData");
36 
37 
38 
39  //Require
40  ev.RequireByLabel<QPulse>(fPulseLabel);
41  ev.Require<QPulseInfo>("DAQ","PulseInfo");
42  ev.Require<QHeader>("DAQ","Header");
43 }
44 
46 {
47 
48  const QPulseInfo& pulseInfo = ev.Get<QPulseInfo>("DAQ","PulseInfo");
49  const QHeader& header = ev.Get<QHeader>("DAQ","Header");
50  const int chan = pulseInfo.GetChannelId();
51 
52  QRunDataHandle rHandle(header.GetRun());
53  GlobalData().Get("",&rHandle,"");
54 
55  const QRunData& runData = rHandle.Get();
56  const QChannelRunData& channelRunData = runData.GetChannelRunData(chan);
57 
58 
59  const QPulse& rawPulse = ev.GetByLabel<QPulse>(fPulseLabel);
60  QPulse fff = rawPulse;
61  QVector ppp = rawPulse.GetSamples();
62 
63  it = channel2trigger.find(chan);
64  if(it==channel2trigger.end()){
65  Info("Adding trigger for channel %d",chan);
66  QTrigger* Trigger = QTriggerFactory(TriggerAlgo);
67  channel2trigger.insert(std::pair<int,QTrigger*>(chan,Trigger));
68  channel2trigger[chan]->SetDebounce((int)(fDebounce*ppp.Size()));
69  channel2trigger[chan]->SetReader(this);
70  channel2trigger[chan]->SetSamplingFrequency(channelRunData.fSamplingFrequency);
71  channel2trigger[chan]->SetWindow(ppp.Size());
72  channel2trigger[chan]->SetChannel(chan);
73  }
74 
75  vector<double> trace (ppp.Size());
76  for(size_t i =0; i <ppp.Size();i++){
77  trace[i] = ppp[i];
78  }
79 
80  channel2trigger[chan]->TriggerStream(trace);
81  vector<int> trigs = channel2trigger[chan]->GetTriggers();
82  QVector Intervals;
83  if(trigs.size()>1){
84  Intervals.Resize(trigs.size()-1);
85  for(size_t i =1; i <trigs.size();i++){
86  Intervals[i-1] = trigs[i]-trigs[i-1];
87  }
88  Intervals/=channelRunData.fSamplingFrequency;
89  }else{
90  Intervals.Resize(1);
91  Intervals.Initialize(0);
92  }
93  if(fSaveFiltered){
94  vector<double> filt_stream = channel2trigger[chan]->GetFilteredStream();
95 
96  QVector stream(filt_stream.size());
97  for(size_t i =0; i <filt_stream.size();i++){
98  stream[i] = filt_stream[i];
99  }
100 
101  fff.SetSamplesADC(stream);
102 
103  ev.Get<QPulse>("Peaks") =fff;
104  }
105  if(fSaveHeight){
106  vector<double> THeights = channel2trigger[chan]->GetTriggerHeights();
107  std::set<double> Triggers (THeights.begin(), THeights.end());
108  ev.Get<QDouble>("HighestTrigger") = *Triggers.rbegin();
109  }
110  ev.Get<QCountPulsesData>("CountPulsesData").fNumberOfPulses =(int)trigs.size();
111  ev.Get<QCountPulsesData>("CountPulsesData").fTimeIntervals = Intervals;
112 }
113 
114 
116 {
117  /* This method is called at the end of the event loop.
118  * Here you can:
119  *
120  * 1) Operate on the sequence execution parameters(see QBaseModule.hh).
121  *
122  * 2) Read/Write global data.
123  */
124 }
125 
QRunDataHandle rHandle(753)
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
Q_BEGIN_NAMESPACE QTrigger * QTriggerFactory(const std::string name)
Function for selecting trigger type.
Peak Finder module that lets you choose which peak finding algorithm to choose.
void Done()
Done method.
void Do(Diana::QEvent &ev)
Do method. Declare and implement only one of the two versions.
void Init(Diana::QEvent &ev)
Init method.
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
basic channel and run based info. Used in the QRunData object.
double fSamplingFrequency
sampling frequency in Hz
number of pulses and time interval beetwen peaks in the same acquired window
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
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...