source: branches/Mars_use_drstimefiles/msignal/MExtractSignal2.cc@ 18481

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