source: trunk/MagicSoft/Mars/mextralgo/MExtralgoDigitalFilter.cc@ 8049

Last change on this file since 8049 was 7942, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 4.1 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): Hendrik Bartko, 09/2004 <mailto:hbartko@mppmu.mpg.de>
19! Author(s): Thomas Bretz, 08/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2006
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MExtralgoDigitalFilter
29//
30//////////////////////////////////////////////////////////////////////////////
31#include "MExtralgoDigitalFilter.h"
32
33using namespace std;
34
35Float_t MExtralgoDigitalFilter::ExtractNoise(Int_t iter, Int_t windowsize) const
36{
37 Double_t sum, dummy;
38 Eval(sum, dummy, windowsize, 0, iter-fWeightsPerBin/2);
39 return sum;
40}
41
42void MExtralgoDigitalFilter::Extract(Int_t windowsize, Float_t timeshift)
43{
44 fSignal = 0; // default is: no pulse found
45 fTime = -1; // default is: out if range (--> random)
46 fSignalDev = 0; // default is: valid
47 fTimeDev = 0; // default is: valid
48
49 // FIXME: How to handle saturation?
50
51 Float_t maxamp = -FLT_MAX;
52 Float_t maxtime = 0;
53 Int_t maxp = -1;
54
55 //
56 // Calculate the sum of the first fWindowSize slices
57 //
58 for (Int_t i=0; i<fNum-windowsize+1; i++)
59 {
60 Double_t sumamp, sumtime;
61 Eval(sumamp, sumtime, windowsize, i);
62
63 if (sumamp>maxamp)
64 {
65 maxamp = sumamp;
66 maxtime = sumtime;
67 maxp = i;
68 }
69 }
70
71 // The number of available slices were smaller than the
72 // extraction window size of the extractor
73 if (maxp<0)
74 {
75 fSignalDev = -1; // means: is invalid
76 fTimeDev = -1; // means: is invalid
77 return;
78 }
79
80 // For some reason (by chance or because all slices contain 0)
81 // maxamp is 0. This means the signal is zero and no arrival
82 // time can be extracted (but both informations are valid)
83 if (maxamp==0)
84 return;
85
86 // This is the time offset from the extraction position
87 const Float_t time = maxtime/maxamp;
88
89 // This is used to align the weights to bins between
90 // -0.5/fWeightsPerBin and 0.5/fWeightsPerBin instead of
91 // 0 and 1./fWeightsPerBin
92 const Float_t halfres = 0.5/fWeightsPerBin;
93
94 // move the extractor by an offset number of slices
95 // determined by the extracted time
96 const Int_t integ = TMath::FloorNint(time+halfres+0.5);
97 maxp -= integ;
98
99 // Convert the residual fraction of one slice into an
100 // offset position in the extraction weights
101 Int_t frac = TMath::FloorNint((time+halfres-integ)*fWeightsPerBin);
102
103 // Align maxp into available range
104 if (maxp < 0)
105 {
106 maxp = 0;
107 frac = -fWeightsPerBin/2; // Assume peak at the beginning of the first slice
108 }
109 if (maxp+windowsize > fNum)
110 {
111 maxp = fNum-windowsize;
112 frac = fWeightsPerBin/2-1; // Assume peak at the end of the last slice
113 }
114
115 Double_t sumamp, sumtime;
116 Eval(sumamp, sumtime, windowsize, maxp, frac);
117
118 fSignal = sumamp;
119 if (sumamp == 0)
120 return;
121
122 // here, the first high-gain slice is already included
123 // in the fTimeShiftHiGain this shifts the time to the
124 // start of the rising edge
125 fTime = maxp - Float_t(frac)/fWeightsPerBin + timeshift;
126
127 const Float_t timefineadjust = sumtime/sumamp;
128
129 // FIXME: Is 3 a good value?
130 if (TMath::Abs(timefineadjust)*fWeightsPerBin < 3.)
131 fTime -= timefineadjust;
132}
Note: See TracBrowser for help on using the repository browser.