source: trunk/Mars/msignal/MFilterData.cc@ 19853

Last change on this file since 19853 was 17886, checked in by Daniela Dorner, 10 years ago
bugfix
File size: 4.2 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 2013<mailto:thomas.bretz@phys.ethz.ch>
19!
20! Copyright: MAGIC Software Development, 2013
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MFilterData
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MFilterData.h"
31
32#include <algorithm>
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38
39#include "MPedestalSubtractedEvt.h"
40
41ClassImp(MFilterData);
42
43using namespace std;
44
45// --------------------------------------------------------------------------
46//
47// Default constructor.
48//
49MFilterData::MFilterData(const char *name, const char *title)
50 : fSignalIn(NULL), fSignalOut(NULL),
51 fNameSignalIn("MPedestalSubtractedEvt"),
52 fNameSignalOut("FilteredEvt")
53{
54 fName = name ? name : "MFilterData";
55 fTitle = title ? title : "Class to filter the data";
56
57 // Default weights
58 fWeights.resize(14);
59 fWeights[ 0] = -0.217305;
60 fWeights[ 1] = -0.213277;
61 fWeights[ 2] = -0.193537;
62 fWeights[ 3] = -0.181686;
63 fWeights[ 4] = -0.15356;
64 fWeights[ 5] = -0.129926;
65 fWeights[ 6] = -0.0792033;
66 fWeights[ 7] = -0.0219311;
67 fWeights[ 8] = 0.0550301;
68 fWeights[ 9] = 0.127364;
69 fWeights[10] = 0.206711;
70 fWeights[11] = 0.246864;
71 fWeights[12] = 0.271012;
72 fWeights[13] = 0.283444;
73}
74
75// --------------------------------------------------------------------------
76//
77Int_t MFilterData::PreProcess(MParList *pList)
78{
79 fSignalIn = (MPedestalSubtractedEvt*)pList->FindObject(fNameSignalIn);
80 if (!fSignalIn)
81 {
82 *fLog << err << fNameSignalIn << " [MPedestalSubtractedEvt] not found... aborting." << endl;
83 return kFALSE;
84 }
85
86 fSignalOut = (MPedestalSubtractedEvt*)pList->FindCreateObj("MPedestalSubtractedEvt", fNameSignalOut);
87 if (!fSignalOut)
88 return kFALSE;
89
90 return kTRUE;
91}
92
93void MFilterData::Filter(UShort_t npix, UShort_t nroi, const Float_t *beg, Float_t *out) const
94{
95 const uint16_t nw = fWeights.size();
96
97 const float *begw = fWeights.data();
98 const float *endw = fWeights.data()+nw;
99
100 for (const Float_t *in=beg; in<beg+nroi*npix; )
101 {
102 // Loop from 0 to nroi-nw-1
103 const Float_t *end = in+nroi-nw;
104 for (; in<end; in++, out++)
105 {
106 // This works even if out==in
107 const float *w = begw;
108 const float *p = in;
109
110 // Loop over weights
111 *out = *p++ * *w++;
112 while (w<endw)
113 *out += *p++ * *w++;
114 }
115
116 // skip last nw samples
117 in += nw;
118 out += nw;
119
120 // Loop from nroi-nw to nroi
121 // end = in+nw;
122 // for (; in<end; in++)
123 // {
124 // Double_t sum = 0;
125 // for (uint16_t j=0; j<nw; j++)
126 // sum += in[min(j, last)]*fWeights[j];
127 // *out++ = sum;
128 // }
129 }
130}
131
132// --------------------------------------------------------------------------
133//
134//
135Int_t MFilterData::Process()
136{
137 // FIXME: Implement an alternative: the simple filter
138 // (p[10]+p[11]+p[12]) - (p[0]+p[1]+p[2])
139 // Store first sum in ring-buffer
140
141 const uint16_t nroi = fSignalIn->GetNumSamples();
142 const uint16_t npix = fSignalIn->GetNumPixels();
143
144 if (fSignalIn!=fSignalOut)
145 fSignalOut->InitSamples(nroi); // contains setting to 0
146
147 Filter(npix, nroi, fSignalIn->GetSamples(), fSignalOut->GetSamples());
148
149 return kTRUE;
150}
Note: See TracBrowser for help on using the repository browser.