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 |
|
---|
41 | ClassImp(MFilterData);
|
---|
42 |
|
---|
43 | using namespace std;
|
---|
44 |
|
---|
45 | // --------------------------------------------------------------------------
|
---|
46 | //
|
---|
47 | // Default constructor.
|
---|
48 | //
|
---|
49 | MFilterData::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 | //
|
---|
60 | Int_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("MPedestalSibtractedEvt", 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 | //
|
---|
98 | Int_t MFilterData::Process()
|
---|
99 | {
|
---|
100 | const uint16_t nroi = fSignalIn->GetNumSamples();
|
---|
101 | const uint16_t npix = fSignalIn->GetNumPixels();
|
---|
102 | const uint16_t nw = fWeights.size();
|
---|
103 | //const uint16_t last = nroi-1;
|
---|
104 |
|
---|
105 | if (fSignalIn!=fSignalOut)
|
---|
106 | fSignalOut->InitSamples(nroi); // contains setting to 0
|
---|
107 |
|
---|
108 | const float *begw = fWeights.data();
|
---|
109 | const float *endw = fWeights.data()+nw;
|
---|
110 |
|
---|
111 | const Float_t *beg = fSignalIn->GetSamples();
|
---|
112 |
|
---|
113 | Float_t *out = fSignalOut->GetSamples();
|
---|
114 | for (const Float_t *in=beg; in<beg+nroi*npix; )
|
---|
115 | {
|
---|
116 | // Loop from 0 to nroi-nw-1
|
---|
117 | const Float_t *end = in+nroi-nw;
|
---|
118 | for (; in<end; in++, out++)
|
---|
119 | {
|
---|
120 | // This works even if out==in
|
---|
121 | const float *w = begw;
|
---|
122 | const float *p = in;
|
---|
123 |
|
---|
124 | // Loop over weights
|
---|
125 | *out = *p++ * *w++;
|
---|
126 | while (w<endw)
|
---|
127 | *out = *p++ * *w++;
|
---|
128 | }
|
---|
129 |
|
---|
130 | // skip last nw samples
|
---|
131 | in += nw;
|
---|
132 | out += nw;
|
---|
133 |
|
---|
134 | // Loop from nroi-nw to nroi
|
---|
135 | // end = in+nw;
|
---|
136 | // for (; in<end; in++)
|
---|
137 | // {
|
---|
138 | // Double_t sum = 0;
|
---|
139 | // for (uint16_t j=0; j<nw; j++)
|
---|
140 | // sum += in[min(j, last)]*fWeights[j];
|
---|
141 | // *out++ = sum;
|
---|
142 | // }
|
---|
143 | }
|
---|
144 |
|
---|
145 | return kTRUE;
|
---|
146 | }
|
---|