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

Last change on this file since 17836 was 17836, checked in by tbretz, 10 years ago
First working version.
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
58// --------------------------------------------------------------------------
59//
60Int_t MFilterData::PreProcess(MParList *pList)
61{
62 fSignalIn = (MPedestalSubtractedEvt*)pList->FindObject(fNameSignalIn);
63 if (!fSignalIn)
64 {
65 *fLog << err << fNameSignalIn << " [MPedestalSubtractedEvt] not found... aborting." << endl;
66 return kFALSE;
67 }
68
69 fSignalOut = (MPedestalSubtractedEvt*)pList->FindCreateObj("MPedestalSubtractedEvt", fNameSignalOut);
70 if (!fSignalOut)
71 return kFALSE;
72
73 if (fWeights.size()==0)
74 {
75 fWeights.resize(14);
76 fWeights[ 0] = -0.217305;
77 fWeights[ 1] = -0.213277;
78 fWeights[ 2] = -0.193537;
79 fWeights[ 3] = -0.181686;
80 fWeights[ 4] = -0.15356;
81 fWeights[ 5] = -0.129926;
82 fWeights[ 6] = -0.0792033;
83 fWeights[ 7] = -0.0219311;
84 fWeights[ 8] = 0.0550301;
85 fWeights[ 9] = 0.127364;
86 fWeights[10] = 0.206711;
87 fWeights[11] = 0.246864;
88 fWeights[12] = 0.271012;
89 fWeights[13] = 0.283444;
90 }
91
92 return kTRUE;
93}
94
95// --------------------------------------------------------------------------
96//
97//
98Int_t MFilterData::Process()
99{
100 // FIXME: Implement an alternative: the simple filter
101 // (p[10]+p[11]+p[12]) - (p[0]+p[1]+p[2])
102 // Store first sum in ring-buffer
103
104 const uint16_t nroi = fSignalIn->GetNumSamples();
105 const uint16_t npix = fSignalIn->GetNumPixels();
106 const uint16_t nw = fWeights.size();
107 //const uint16_t last = nroi-1;
108
109 if (fSignalIn!=fSignalOut)
110 fSignalOut->InitSamples(nroi); // contains setting to 0
111
112 const float *begw = fWeights.data();
113 const float *endw = fWeights.data()+nw;
114
115 const Float_t *beg = fSignalIn->GetSamples();
116
117 Float_t *out = fSignalOut->GetSamples();
118 for (const Float_t *in=beg; in<beg+nroi*npix; )
119 {
120 // Loop from 0 to nroi-nw-1
121 const Float_t *end = in+nroi-nw;
122 for (; in<end; in++, out++)
123 {
124 // This works even if out==in
125 const float *w = begw;
126 const float *p = in;
127
128 // Loop over weights
129 *out = *p++ * *w++;
130 while (w<endw)
131 *out = *p++ * *w++;
132 }
133
134 // skip last nw samples
135 in += nw;
136 out += nw;
137
138 // Loop from nroi-nw to nroi
139 // end = in+nw;
140 // for (; in<end; in++)
141 // {
142 // Double_t sum = 0;
143 // for (uint16_t j=0; j<nw; j++)
144 // sum += in[min(j, last)]*fWeights[j];
145 // *out++ = sum;
146 // }
147 }
148
149 return kTRUE;
150}
Note: See TracBrowser for help on using the repository browser.