17 using namespace Diana;
22 fPulseLabel = GetString(
"PulseLabel",
"DAQ@Pulse",
false);
23 fThreshold = GetDouble(
"ThresholdNumberOfSigma", 5);
24 if(fThreshold <= 2) Panic(
"ThresholdNumberOfSigma must be > 2");
25 fSubSampling = GetInt(
"SubSampling",5,
false);
26 if(fSubSampling < 2) Panic(
"SubSampling must be > 1");
33 if(fSubSampling > 1) {
35 configuration.
fCutoff = 2./(fSubSampling);
38 if(configuration.
fM%2 == 0) configuration.
fM++;
40 fFir =
new QFir(configuration);
55 vector<int> peakPositions = GetPeaks(samples,minSamples,1);
57 vector<int> peakPositionsSub = GetPeaks(samples,minSamples,fSubSampling);
60 std::vector<int> save = peakPositions;
61 for(
size_t p = 0; p < peakPositions.size(); p++) {
62 int peakPos = peakPositions[p];
63 for(vector<int>::iterator pr = peakPositionsSub.begin(); pr != peakPositionsSub.end(); ) {
65 int delta =
abs(peakPosSub - peakPos);
66 if(delta <= 3*fSubSampling) {
67 pr = peakPositionsSub.erase(pr);
73 for(
size_t pr = 0; pr < peakPositionsSub.size(); pr++) {
74 save.push_back(peakPositionsSub[pr]);
76 std::sort(save.begin(),save.end());
80 QVector peakpos(save.size());
81 for(
size_t i =0; i < save.size(); i++) peakpos[i] = save[i];
92 QVector samplesReduced;
93 const int numSamples = samples.Size();
97 offset = fFir->GetFilterReduction();
99 fFir->Filter(samples,filtered);
100 samplesReduced.Resize(samples.Size()/red-offset);
101 samplesReduced.Initialize(0);
103 for(
int i = 0; i < numSamples; i++) {
104 if( i % red == 0 && j < samplesReduced.Size()) {
105 samplesReduced[j]=filtered[i];
110 samplesReduced = samples;
115 QVector derivative = samplesReduced.Derivative3P();
120 double rmsMin = 1e20;
121 while(i < derivative.Size()-minSamples) {
122 double rms = derivative.GetRMS(minSamples,i);
123 if(rms < rmsMin) rmsMin = rms;
126 double thrrms = fThreshold*rmsMin;
128 vector<int> peakPositions;
130 while ( i < derivative.Size() ) {
131 double prevDerivative = derivative[i];
133 if(prevDerivative < 0) sign = -1;
136 if(prevDerivative*sign > thrrms) {
139 while(i < derivative.Size()) {
140 if(derivative[i]*sign < -2*rmsMin) {
147 while (i < derivative.Size()) {
148 if(derivative[i]*sign > (fThreshold-1)*rmsMin) {
153 peakPositions.push_back(maxPos*red+offset);
160 return peakPositions;
#define REGISTER_MODULE(clazz)
Diana::QVector abs(const Diana::QVector &v)
Module to detect peaks in window alternative to MBCountPulses.
void Init(Diana::QEvent &ev)
Init method.
void Do(Diana::QEvent &ev)
Do method. Declare and implement only one of the two versions.
std::vector< int > GetPeaks(const Diana::QVector &samples, int minSamples, const size_t red)
Data class for QFir (Ported from Calder)
number of pulses and time interval beetwen peaks in the same acquired window
const Q & GetByLabel(const QEventLabel &label) const
Get a QObject in read mode by label.
void RequireByLabel(const QEventLabel &label) const
notify the QEvent that we need a QObject, if not found an exception is thrown
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
void Add(WriteHandle< Q > &handle)
Add a QObject to the event.
QFir FIR low pass filter (Ported from Calder)
Raw event: bolometer channel, trigger positions and types.
const QSampleInfo & GetMasterSample() const
Get MasterSample.
Raw event: sampled waveform.
Int_t GetSampleIndex() const
Get SampleIndex from the beginning of the waveform.
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...