source: trunk/MagicSoft/Mars/msignal/MExtractSignal2.cc@ 3712

Last change on this file since 3712 was 3558, checked in by gaug, 21 years ago
*** empty log message ***
File size: 7.4 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, 02/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Hendrik Bartko, 01/2004 <mailto:hbartko@mppmu.mpg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MExtractSignal2
29//
30// Calculate the signal as the fWindowSize time slices which have the highest
31// integral contents.
32//
33//
34//
35//////////////////////////////////////////////////////////////////////////////
36#include "MExtractSignal2.h"
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MParList.h"
42
43#include "MRawEvtData.h"
44#include "MRawEvtPixelIter.h"
45
46#include "MPedestalCam.h"
47#include "MPedestalPix.h"
48
49#include "MExtractedSignalCam.h"
50#include "MExtractedSignalPix.h"
51
52//#include "MArrivalTime.h"
53
54ClassImp(MExtractSignal2);
55
56using namespace std;
57
58const Byte_t MExtractSignal2::fgSaturationLimit = 254;
59const Byte_t MExtractSignal2::fgFirst = 0;
60const Byte_t MExtractSignal2::fgLast = 14;
61const Byte_t MExtractSignal2::fgWindowSize = 6;
62
63// --------------------------------------------------------------------------
64//
65// Default constructor.
66//
67MExtractSignal2::MExtractSignal2(const char *name, const char *title)
68 : fSaturationLimit(fgSaturationLimit)
69{
70
71 fName = name ? name : "MExtractSignal2";
72 fTitle = title ? title : "Task to extract the signal from the FADC slices";
73
74 AddToBranchList("MRawEvtData.*");
75
76 SetRange();
77}
78
79void MExtractSignal2::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t windowh, Byte_t lofirst, Byte_t lolast, Byte_t windowl)
80{
81
82 fNumHiGainSamples = hilast-hifirst+1;
83 fNumLoGainSamples = lolast-lofirst+1;
84
85 fHiGainFirst = hifirst;
86 fLoGainFirst = lofirst;
87
88 fWindowSizeHiGain = windowh & ~1;
89 fWindowSizeLoGain = windowl & ~1;
90
91 if (fWindowSizeHiGain != windowh)
92 *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size has to be even, set to: "
93 << int(fWindowSizeHiGain) << " samples " << endl;
94
95 if (fWindowSizeLoGain != windowl)
96 *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size has to be even, set to: "
97 << int(fWindowSizeLoGain) << " samples " << endl;
98
99 if (fWindowSizeHiGain<2)
100 {
101 fWindowSizeHiGain = 2;
102 *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size set to two samples" << endl;
103 }
104
105 if (fWindowSizeLoGain<2)
106 {
107 fWindowSizeLoGain = 2;
108 *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size set to two samples" << endl;
109 }
110
111 if (fWindowSizeHiGain > fNumHiGainSamples)
112 {
113 fWindowSizeHiGain = fNumHiGainSamples & ~1;
114 *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size set to "
115 << int(fWindowSizeHiGain) << " samples " << endl;
116 }
117
118 if (fWindowSizeLoGain > fNumLoGainSamples)
119 {
120 fWindowSizeLoGain = fNumLoGainSamples & ~1;
121 *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size set to "
122 << int(fWindowSizeLoGain) << " samples " << endl;
123 }
124
125 fWindowSqrtHiGain = TMath::Sqrt((Float_t)fWindowSizeHiGain);
126 fWindowSqrtLoGain = TMath::Sqrt((Float_t)fWindowSizeLoGain);
127
128}
129
130
131
132// --------------------------------------------------------------------------
133//
134// The PreProcess searches for the following input containers:
135// - MRawEvtData
136// - MPedestalCam
137//
138// The following output containers are also searched and created if
139// they were not found:
140//
141// - MExtractedSignalCam
142//
143Int_t MExtractSignal2::PreProcess(MParList *pList)
144{
145 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
146 if (!fRawEvt)
147 {
148 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
149 return kFALSE;
150 }
151
152
153 fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
154 if (!fSignals)
155 return kFALSE;
156
157 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1, (Float_t)fWindowSizeHiGain,
158 fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1, (Float_t)fWindowSizeLoGain);
159
160 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
161 if (!fPedestals)
162 {
163 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
164 return kFALSE;
165 }
166 return kTRUE;
167}
168
169void MExtractSignal2::FindSignal(Byte_t *ptr, Byte_t size, Byte_t window, Int_t &max, Int_t &sat) const
170{
171 const Byte_t *end = ptr + size;
172
173 Int_t sum=0;
174
175 //
176 // Calculate the sum of the first fWindowSize slices
177 //
178 sat = 0;
179 Byte_t *p = ptr;
180 while (p<ptr+window)
181 {
182 sum += *p;
183 if (*p++ >= fSaturationLimit)
184 sat++;
185 }
186
187 //
188 // Check for saturation in all other slices
189 //
190 while (p<end)
191 if (*p++ >= fSaturationLimit)
192 sat++;
193
194 //
195 // Calculate the i-th sum as
196 // sum_i+1 = sum_i + slice[i+8] - slice[i]
197 // This is fast and accurate (because we are using int's)
198 //
199 max=sum;
200 for (p=ptr; p+window<end; p++)
201 {
202 sum += *(p+window) - *p;
203 if (sum>max)
204 max = sum;
205 }
206}
207
208// --------------------------------------------------------------------------
209//
210// Calculate the integral of the FADC of fWindowSize time slices which have the
211// highest signal
212//
213Int_t MExtractSignal2::Process()
214{
215 MRawEvtPixelIter pixel(fRawEvt);
216 fSignals->Clear();
217
218 Int_t sat=0;
219 while (pixel.Next())
220 {
221 //
222 // Find signal in hi- and lo-gain
223 //
224 Int_t sumhi, sathi;
225 FindSignal(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, fWindowSizeHiGain, sumhi, sathi);
226
227 Int_t sumlo=0;
228 Int_t satlo=0;
229 if (pixel.HasLoGain())
230 {
231 FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, fWindowSizeLoGain, sumlo, satlo);
232 if (satlo)
233 sat++;
234 }
235
236 //
237 // Take correspodning pedestal
238 //
239 const Int_t pixid = pixel.GetPixelId();
240
241 const MPedestalPix &ped = (*fPedestals)[pixid];
242 MExtractedSignalPix &pix = (*fSignals)[pixid];
243
244 const Float_t pedes = ped.GetPedestal();
245 const Float_t pedrms = ped.GetPedestalRms();
246
247 //
248 // Set extracted signal with pedestal substracted
249 //
250 pix.SetExtractedSignal(sumhi - pedes*fWindowSizeHiGain, pedrms*fWindowSqrtHiGain,
251 sumlo - pedes*fWindowSizeLoGain, pedrms*fWindowSqrtLoGain);
252
253 pix.SetGainSaturation(sathi, sathi, satlo);
254 } /* while (pixel.Next()) */
255
256
257 fSignals->SetReadyToSave();
258
259 return kTRUE;
260}
Note: See TracBrowser for help on using the repository browser.