source: trunk/MagicSoft/Mars/msignal/MExtractBlindPixel.cc@ 3967

Last change on this file since 3967 was 3962, checked in by gaug, 21 years ago
*** empty log message ***
File size: 6.7 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): Markus Gaug, 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractBlindPixel
28//
29// Extracts the signal from a fixed window in a given range.
30//
31// Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast)
32// to modify the ranges. The "lo-gain" ranges are used for the NSB rejection
33// whereas the high-gain ranges for blind pixel signal extraction. "High-gain"
34// ranges can extend to the slices stored as "low-gain" in MRawEvtPixelIter
35// Defaults are:
36//
37// fHiGainFirst = fgHiGainFirst = 12
38// fHiGainLast = fgHiGainLast = 16
39// fLoGainFirst = fgLoGainFirst = 0
40// fLoGainLast = fgLoGainLast = 10
41//
42//////////////////////////////////////////////////////////////////////////////
43#include "MExtractBlindPixel.h"
44
45#include <fstream>
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50#include "MParList.h"
51
52#include "MRawEvtData.h"
53#include "MRawEvtPixelIter.h"
54
55#include "MExtractedSignalBlindPixel.h"
56
57#include "MPedestalCam.h"
58#include "MPedestalPix.h"
59
60ClassImp(MExtractBlindPixel);
61
62using namespace std;
63
64const Int_t MExtractBlindPixel::fgBlindPixelIdx = 559;
65const Int_t MExtractBlindPixel::fgNSBFilterLimit = 800;
66const Byte_t MExtractBlindPixel::fgHiGainFirst = 12;
67const Byte_t MExtractBlindPixel::fgHiGainLast = 29;
68const Byte_t MExtractBlindPixel::fgLoGainFirst = 0;
69const Byte_t MExtractBlindPixel::fgLoGainLast = 10;
70// --------------------------------------------------------------------------
71//
72// Default constructor.
73//
74// Initializes:
75// - fBlindPixelIdx to fgBlindPixelIdx
76// - fNSBFilterLimit to fgNSBFilterLimit
77//
78// Calls:
79// - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
80//
81MExtractBlindPixel::MExtractBlindPixel(const char *name, const char *title)
82{
83
84 fName = name ? name : "MExtractBlindPixel";
85 fTitle = title ? title : "Task to extract the signal from the FADC slices";
86
87 AddToBranchList("MRawEvtData.*");
88
89 SetBlindPixelIdx();
90 SetNSBFilterLimit();
91 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
92
93}
94
95void MExtractBlindPixel::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
96{
97
98 MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
99
100 fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1);
101 fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst+1);
102
103 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
104 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
105
106}
107
108// --------------------------------------------------------------------------
109//
110// The PreProcess searches for the following input containers:
111// - MRawEvtData
112//
113// The following output containers are also searched and created if
114// they were not found:
115//
116// - MExtractedBlindPixel
117//
118Int_t MExtractBlindPixel::PreProcess(MParList *pList)
119{
120
121 if (!MExtractor::PreProcess(pList))
122 return kFALSE;
123
124 fBlindPixel = (MExtractedSignalBlindPixel*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalBlindPixel"));
125 if (!fBlindPixel)
126 return kFALSE;
127
128 fBlindPixel->SetBlindPixelIdx(fBlindPixelIdx);
129 fBlindPixel->SetUsedFADCSlices(fHiGainFirst, fHiGainLast);
130
131 MPedestalPix &pedpix = (*fPedestals)[fBlindPixelIdx];
132
133 if (&pedpix)
134 {
135 fBlindPixel->SetPed ( pedpix.GetPedestal() * fNumLoGainSamples );
136 fBlindPixel->SetPedErr ( pedpix.GetPedestalRms()* fNumLoGainSamples
137 / TMath::Sqrt((Float_t)fPedestals->GetTotalEntries()) );
138 fBlindPixel->SetPedRms ( pedpix.GetPedestalRms()* TMath::Sqrt((Float_t)fNumLoGainSamples) );
139 fBlindPixel->SetPedRmsErr( fBlindPixel->GetPedErr()/2. );
140 }
141
142 return kTRUE;
143}
144
145// --------------------------------------------------------------------------
146//
147// FindSignalHiGain:
148//
149// - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
150// - Sum up contents of *ptr
151// - If *ptr is greater than fSaturationLimit, raise sat by 1
152// - If fHiLoLast is set, loop from logain to (logain+fHiLoLast)
153// - Add contents of *logain to sum
154//
155void MExtractBlindPixel::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &sum, Byte_t &sat) const
156{
157
158 Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
159
160 while (ptr<end)
161 {
162 sum += *ptr;
163
164 if (*ptr++ >= fSaturationLimit)
165 sat++;
166 }
167
168 if (fHiLoLast == 0)
169 return;
170
171 end = logain + fHiLoLast;
172 while (logain<end)
173 {
174 sum += *logain;
175
176 if (*logain++ >= fSaturationLimit)
177 sat++;
178 }
179
180}
181
182// --------------------------------------------------------------------------
183//
184// FindSignalFilter:
185//
186// - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst)
187// - Sum up contents of *ptr
188// - If *ptr is greater than fSaturationLimit, raise sat by 1
189//
190void MExtractBlindPixel::FindSignalFilter(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
191{
192
193 Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
194
195 while (ptr<end)
196 {
197 sum += *ptr;
198
199 if (*ptr++ >= fSaturationLimit)
200 sat++;
201 }
202}
203
204// --------------------------------------------------------------------------
205//
206// Calculate the integral of the FADC time slices and store them as a new
207// pixel in the MExtractedBlindPixel container.
208//
209Int_t MExtractBlindPixel::Process()
210{
211
212 MRawEvtPixelIter pixel(fRawEvt);
213
214 fBlindPixel->Clear();
215
216 pixel.Jump(fBlindPixelIdx);
217
218 Int_t sum = 0;
219 Byte_t sat = 0;
220
221 FindSignalFilter(pixel.GetHiGainSamples()+fLoGainFirst, sum, sat);
222
223 if (sum > fNSBFilterLimit)
224 {
225 sum = -1;
226 fBlindPixel->SetExtractedSignal(sum);
227 fBlindPixel->SetNumSaturated(sat);
228 fBlindPixel->SetReadyToSave();
229 return kTRUE;
230 }
231
232 sum = 0;
233 sat = 0;
234
235 FindSignalHiGain(pixel.GetHiGainSamples()+fLoGainFirst, pixel.GetLoGainSamples(), sum, sat);
236
237 fBlindPixel->SetExtractedSignal(sum);
238 fBlindPixel->SetNumSaturated(sat);
239 fBlindPixel->SetReadyToSave();
240
241 return kTRUE;
242}
243
Note: See TracBrowser for help on using the repository browser.