1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: MPedCalcFromLoGain.cc,v 1.35 2007-02-03 20:03:35 tbretz Exp $
|
---|
3 | ! --------------------------------------------------------------------------
|
---|
4 | !
|
---|
5 | ! *
|
---|
6 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | ! *
|
---|
11 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
12 | ! * documentation for any purpose is hereby granted without fee,
|
---|
13 | ! * provided that the above copyright notice appear in all copies and
|
---|
14 | ! * that both that copyright notice and this permission notice appear
|
---|
15 | ! * in supporting documentation. It is provided "as is" without express
|
---|
16 | ! * or implied warranty.
|
---|
17 | ! *
|
---|
18 | !
|
---|
19 | !
|
---|
20 | ! Author(s): Josep Flix 04/2001 <mailto:jflix@ifae.es>
|
---|
21 | ! Author(s): Thomas Bretz 05/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
22 | ! Author(s): Sebastian Commichau 12/2003
|
---|
23 | ! Author(s): Javier Rico 01/2004 <mailto:jrico@ifae.es>
|
---|
24 | ! Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es>
|
---|
25 | ! Author(s): Florian Goebel 06/2004 <mailto:fgoebel@mppmu.mpg.de>
|
---|
26 | ! Author(s): Nepomuk Otte 10/2004 <mailto:otte@mppmu.mpg.de>
|
---|
27 | !
|
---|
28 | ! Copyright: MAGIC Software Development, 2000-2006
|
---|
29 | !
|
---|
30 | !
|
---|
31 | \* ======================================================================== */
|
---|
32 |
|
---|
33 | /////////////////////////////////////////////////////////////////////////////
|
---|
34 | //
|
---|
35 | // MPedCalcLoGain
|
---|
36 | //
|
---|
37 | // This task derives from MExtractPedestal.
|
---|
38 | // It calculates the pedestals using the low gain slices, whenever the difference
|
---|
39 | // between the highest and the lowest slice in the high gain
|
---|
40 | // slices is below a given threshold (SetMaxHiGainVar). In this case the receiver
|
---|
41 | // boards do not switch to lo gain and the so called lo gain slices are actually
|
---|
42 | // high gain slices.
|
---|
43 | //
|
---|
44 | // MPedCalcLoGain also fills the ABoffset in MPedestalPix which allows to correct
|
---|
45 | // the 150 MHz clock noise.
|
---|
46 | //
|
---|
47 | // This task takes a pedestal run file and fills MPedestalCam during
|
---|
48 | // the Process() with the pedestal and rms computed in an event basis.
|
---|
49 | // In the PostProcess() MPedestalCam is finally filled with the pedestal
|
---|
50 | // mean and rms computed in a run basis.
|
---|
51 | // More than one run (file) can be merged
|
---|
52 | //
|
---|
53 | // MPedCalcPedRun applies the following formula (1):
|
---|
54 | //
|
---|
55 | // Pedestal per slice = sum(x_i) / n / slices
|
---|
56 | // PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices )
|
---|
57 | //
|
---|
58 | // where x_i is the sum of "slices" FADC slices and sum means the sum over all
|
---|
59 | // events. "n" is the number of events, "slices" is the number of summed FADC samples.
|
---|
60 | //
|
---|
61 | // Note that the slice-to-slice fluctuations are not Gaussian, but Poissonian, thus
|
---|
62 | // asymmetric and they are correlated.
|
---|
63 | //
|
---|
64 | // It is important to know that the Pedestal per slice and PedRMS per slice depend
|
---|
65 | // on the number of used FADC slices, as seen in the following plots:
|
---|
66 | //
|
---|
67 | //Begin_Html
|
---|
68 | /*
|
---|
69 | <img src="images/PedestalStudyInner.gif">
|
---|
70 | */
|
---|
71 | //End_Html
|
---|
72 | //
|
---|
73 | //Begin_Html
|
---|
74 | /*
|
---|
75 | <img src="images/PedestalStudyOuter.gif">
|
---|
76 | */
|
---|
77 | //End_Html
|
---|
78 | //
|
---|
79 | // The plots show the inner and outer pixels, respectivly and have the following meaning:
|
---|
80 | //
|
---|
81 | // 1) The calculated mean pedestal per slice (from MPedCalcFromLoGain)
|
---|
82 | // 2) The fitted mean pedestal per slice (from MHPedestalCam)
|
---|
83 | // 3) The calculated pedestal RMS per slice (from MPedCalcFromLoGain)
|
---|
84 | // 4) The fitted sigma of the pedestal distribution per slice
|
---|
85 | // (from MHPedestalCam)
|
---|
86 | // 5) The relative difference between calculation and histogram fit
|
---|
87 | // for the mean
|
---|
88 | // 6) The relative difference between calculation and histogram fit
|
---|
89 | // for the sigma or RMS, respectively.
|
---|
90 | //
|
---|
91 | // The calculated means do not change significantly except for the case of 2 slices,
|
---|
92 | // however the RMS changes from 5.7 per slice in the case of 2 extracted slices
|
---|
93 | // to 8.3 per slice in the case of 26 extracted slices. This change is very significant.
|
---|
94 | //
|
---|
95 | // The plots have been produced on run 20123. You can reproduce them using
|
---|
96 | // the macro pedestalstudies.C
|
---|
97 | //
|
---|
98 | // Usage of this class:
|
---|
99 | // ====================
|
---|
100 | //
|
---|
101 | //
|
---|
102 | // fCheckWinFirst = fgCheckWinFirst = 0
|
---|
103 | // fCheckWinLast = fgCheckWinLast = 29
|
---|
104 | // fExtractWinFirst = fgExtractWinFirst = 17
|
---|
105 | // fExtractWinSize = fgExtractWinSize = 6
|
---|
106 | // fMaxSignalVar = fgMaxSignalVar = 40;
|
---|
107 | //
|
---|
108 | // Call:
|
---|
109 | // SetCheckRange(fCheckWinFirst,fCheckWinLast);
|
---|
110 | // to set the Window in which a signal is searched
|
---|
111 | //
|
---|
112 | // SetExtractWindow(fExtractWinFirst,fExtractWinSize);
|
---|
113 | // to set the Window from which a signal is extracted
|
---|
114 | //
|
---|
115 | // SetMaxSignalVar(fMaxSignalVar);
|
---|
116 | // set the maximum allowed difference between maximum and minimal signal in CheckWindow
|
---|
117 | //
|
---|
118 | // Variables:
|
---|
119 | // fgCheckWinFirst; First FADC slice to check for signal (currently set to: 0)
|
---|
120 | // fgCheckWinLast: Last FADC slice to check for signal (currently set to: 29)
|
---|
121 | // fgExtractWinFirst: First FADC slice to be used for pedestal extraction (currently set to: 15)
|
---|
122 | // fgExtractWinSize: Window size in slices used for pedestal extraction (currently set to: 6)
|
---|
123 | // fgMaxSignalVar: The maximum difference between the highest and lowest slice
|
---|
124 | // in the check window allowed in order to use event
|
---|
125 | //
|
---|
126 | // Input Containers:
|
---|
127 | // MRawEvtData
|
---|
128 | // MRawRunHeader
|
---|
129 | // MGeomCam
|
---|
130 | //
|
---|
131 | // Output Containers:
|
---|
132 | // MPedestalCam
|
---|
133 | //
|
---|
134 | // See also: MPedestalCam, MPedestalPix, MHPedestalCam, MExtractor
|
---|
135 | //
|
---|
136 | /////////////////////////////////////////////////////////////////////////////
|
---|
137 | #include "MPedCalcFromLoGain.h"
|
---|
138 |
|
---|
139 | #include "MParList.h"
|
---|
140 |
|
---|
141 | #include "MLog.h"
|
---|
142 | #include "MLogManip.h"
|
---|
143 |
|
---|
144 | #include "MRawRunHeader.h"
|
---|
145 | #include "MRawEvtPixelIter.h"
|
---|
146 |
|
---|
147 | #include "MPedestalPix.h"
|
---|
148 | #include "MPedestalCam.h"
|
---|
149 |
|
---|
150 | #include "MGeomPix.h"
|
---|
151 | #include "MGeomCam.h"
|
---|
152 |
|
---|
153 | #include "MExtractPedestal.h"
|
---|
154 | #include "MPedestalSubtractedEvt.h"
|
---|
155 |
|
---|
156 | ClassImp(MPedCalcFromLoGain);
|
---|
157 |
|
---|
158 | using namespace std;
|
---|
159 |
|
---|
160 | const UShort_t MPedCalcFromLoGain::fgExtractWinFirst = 17;
|
---|
161 | const UShort_t MPedCalcFromLoGain::fgExtractWinSize = 6;
|
---|
162 | const UInt_t MPedCalcFromLoGain::fgNumDump = 500;
|
---|
163 |
|
---|
164 | // --------------------------------------------------------------------------
|
---|
165 | //
|
---|
166 | // Default constructor:
|
---|
167 | //
|
---|
168 | // Calls:
|
---|
169 | // - SetExtractWindow(fgExtractWinFirst, fgExtractWinSize)
|
---|
170 | //
|
---|
171 | MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title)
|
---|
172 | {
|
---|
173 | fName = name ? name : "MPedCalcFromLoGain";
|
---|
174 | fTitle = title ? title : "Task to calculate pedestals from lo-gains";
|
---|
175 |
|
---|
176 | SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
|
---|
177 | SetPedestalUpdate(kTRUE);
|
---|
178 | SetNumDump();
|
---|
179 | }
|
---|
180 |
|
---|
181 | // --------------------------------------------------------------------------
|
---|
182 | //
|
---|
183 | // Call MExtractPedestl::ResetArrays aand reset fNumAventsUsed and
|
---|
184 | // fTotalCounter
|
---|
185 | //
|
---|
186 | void MPedCalcFromLoGain::ResetArrays()
|
---|
187 | {
|
---|
188 | MExtractPedestal::ResetArrays();
|
---|
189 |
|
---|
190 | fNumEventsUsed.Reset();
|
---|
191 | fTotalCounter.Reset();
|
---|
192 | }
|
---|
193 |
|
---|
194 | // ---------------------------------------------------------------------------------
|
---|
195 | //
|
---|
196 | // Checks:
|
---|
197 | // - if the number of available slices
|
---|
198 | // (fRunHeader->GetNumSamplesHiGain()+(Int_t)fRunHeader->GetNumSamplesLoGain()-1)
|
---|
199 | // is smaller than the number of used slices
|
---|
200 | // (fExtractWinSize+ fExtractWinFirst-1) or
|
---|
201 | // fCheckWinLast
|
---|
202 | //
|
---|
203 | Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
|
---|
204 | {
|
---|
205 | // If the size is not yet set, set the size
|
---|
206 | if (fSumx.GetSize()==0)
|
---|
207 | {
|
---|
208 | const Int_t npixels = fPedestalsOut->GetSize();
|
---|
209 | fNumEventsUsed.Set(npixels);
|
---|
210 | fTotalCounter.Set(npixels);
|
---|
211 | }
|
---|
212 |
|
---|
213 | if (!MExtractPedestal::ReInit(pList))
|
---|
214 | return kFALSE;
|
---|
215 |
|
---|
216 | CheckExtractionWindow(fRunHeader->GetNumSamplesHiGain());
|
---|
217 |
|
---|
218 | return kTRUE;
|
---|
219 | }
|
---|
220 |
|
---|
221 | // --------------------------------------------------------------------------
|
---|
222 | //
|
---|
223 | // Fill the MPedestalCam container with the signal mean and rms for the event.
|
---|
224 | // Store the measured signal in arrays fSumx and fSumx2 so that we can
|
---|
225 | // calculate the overall mean and rms in the PostProcess()
|
---|
226 | //
|
---|
227 | Int_t MPedCalcFromLoGain::Calc()
|
---|
228 | {
|
---|
229 | // Real Process
|
---|
230 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
231 |
|
---|
232 | while (pixel.Next())
|
---|
233 | {
|
---|
234 | const UInt_t idx = pixel.GetPixelId();
|
---|
235 |
|
---|
236 | if (!CheckVariation(idx))
|
---|
237 | continue;
|
---|
238 |
|
---|
239 | //extract pedestal
|
---|
240 | UInt_t ab[2];
|
---|
241 | const Float_t sum = fExtractor ?
|
---|
242 | CalcExtractor(pixel, pixel.GetNumHiGainSamples()) :
|
---|
243 | CalcSums(pixel, pixel.GetNumHiGainSamples(), ab[0], ab[1]);
|
---|
244 |
|
---|
245 | const UInt_t aidx = (*fGeom)[idx].GetAidx();
|
---|
246 | const UInt_t sector = (*fGeom)[idx].GetSector();
|
---|
247 |
|
---|
248 | const Float_t sqrsum = sum*sum;
|
---|
249 |
|
---|
250 | fSumx[idx] += sum;
|
---|
251 | fSumx2[idx] += sqrsum;
|
---|
252 | fAreaSumx[aidx] += sum;
|
---|
253 | fAreaSumx2[aidx] += sqrsum;
|
---|
254 | fSectorSumx[sector] += sum;
|
---|
255 | fSectorSumx2[sector] += sqrsum;
|
---|
256 |
|
---|
257 | if (fIntermediateStorage)
|
---|
258 | (*fPedestalsInter)[idx].Set(sum, 0, 0, fNumEventsUsed[idx]);
|
---|
259 |
|
---|
260 | fNumEventsUsed[idx] ++;
|
---|
261 | fAreaFilled [aidx] ++;
|
---|
262 | fSectorFilled [sector]++;
|
---|
263 |
|
---|
264 | if (!fExtractor && pixel.IsABFlagValid())
|
---|
265 | {
|
---|
266 | fSumAB0[idx] += ab[0];
|
---|
267 | fSumAB1[idx] += ab[1];
|
---|
268 | fAreaSumAB0[aidx] += ab[0];
|
---|
269 | fAreaSumAB1[aidx] += ab[1];
|
---|
270 | fSectorSumAB0[aidx] += ab[0];
|
---|
271 | fSectorSumAB1[aidx] += ab[1];
|
---|
272 | }
|
---|
273 |
|
---|
274 | if (!fPedestalUpdate || (UInt_t)fNumEventsUsed[idx]<fNumEventsDump)
|
---|
275 | continue;
|
---|
276 |
|
---|
277 | CalcPixResults(fNumEventsDump, idx);
|
---|
278 | fTotalCounter[idx]++;
|
---|
279 |
|
---|
280 | fNumEventsUsed[idx]=0;
|
---|
281 | fSumx[idx]=0;
|
---|
282 | fSumx2[idx]=0;
|
---|
283 | fSumAB0[idx]=0;
|
---|
284 | fSumAB1[idx]=0;
|
---|
285 | }
|
---|
286 |
|
---|
287 | if (!(GetNumExecutions() % fNumAreasDump))
|
---|
288 | CalcAreaResult();
|
---|
289 |
|
---|
290 | if (!(GetNumExecutions() % fNumSectorsDump))
|
---|
291 | CalcSectorResult();
|
---|
292 |
|
---|
293 | if (fPedestalUpdate)
|
---|
294 | fPedestalsOut->SetReadyToSave();
|
---|
295 |
|
---|
296 | return kTRUE;
|
---|
297 | }
|
---|
298 |
|
---|
299 | // --------------------------------------------------------------------------
|
---|
300 | //
|
---|
301 | // Loop over the sector indices to get the averaged pedestal per sector
|
---|
302 | //
|
---|
303 | void MPedCalcFromLoGain::CalcSectorResult()
|
---|
304 | {
|
---|
305 | for (UInt_t sector=0; sector<fSectorFilled.GetSize(); sector++)
|
---|
306 | if (fSectorValid[sector]>0)
|
---|
307 | CalcSectorResults(fSectorFilled[sector], fSectorValid[sector], sector);
|
---|
308 | }
|
---|
309 |
|
---|
310 | // --------------------------------------------------------------------------
|
---|
311 | //
|
---|
312 | // Loop over the (two) area indices to get the averaged pedestal per aidx
|
---|
313 | //
|
---|
314 | void MPedCalcFromLoGain::CalcAreaResult()
|
---|
315 | {
|
---|
316 | for (UInt_t aidx=0; aidx<fAreaFilled.GetSize(); aidx++)
|
---|
317 | if (fAreaValid[aidx]>0)
|
---|
318 | CalcAreaResults(fAreaFilled[aidx], fAreaValid[aidx], aidx);
|
---|
319 |
|
---|
320 | }
|
---|
321 |
|
---|
322 | // --------------------------------------------------------------------------
|
---|
323 | //
|
---|
324 | // Compute signal mean and rms in the whole run and store it in MPedestalCam
|
---|
325 | //
|
---|
326 | Int_t MPedCalcFromLoGain::PostProcess()
|
---|
327 | {
|
---|
328 | // Compute pedestals and rms from the whole run
|
---|
329 | if (fPedestalUpdate)
|
---|
330 | return kTRUE;
|
---|
331 |
|
---|
332 | *fLog << flush << inf << "Calculating Pedestals..." << flush;
|
---|
333 |
|
---|
334 | const Int_t npix = fGeom->GetNumPixels();
|
---|
335 | for (Int_t idx=0; idx<npix; idx++)
|
---|
336 | {
|
---|
337 | const ULong_t n = fNumEventsUsed[idx];
|
---|
338 | if (n>1)
|
---|
339 | {
|
---|
340 | CalcPixResults(n, idx);
|
---|
341 | fTotalCounter[idx]++;
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | CalcAreaResult();
|
---|
346 | CalcSectorResult();
|
---|
347 |
|
---|
348 | fPedestalsOut->SetReadyToSave();
|
---|
349 |
|
---|
350 | return MExtractPedestal::PostProcess();
|
---|
351 | }
|
---|
352 |
|
---|
353 | // --------------------------------------------------------------------------
|
---|
354 | //
|
---|
355 | // The following resources are available:
|
---|
356 | //
|
---|
357 | Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
358 | {
|
---|
359 | Bool_t rc=kFALSE;
|
---|
360 |
|
---|
361 | // find resource for pedestal update
|
---|
362 | if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
|
---|
363 | {
|
---|
364 | SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
|
---|
365 | rc = kTRUE;
|
---|
366 | }
|
---|
367 |
|
---|
368 | // find resource for numdump
|
---|
369 | if (IsEnvDefined(env, prefix, "NumDump", print))
|
---|
370 | {
|
---|
371 | const Int_t num = GetEnvValue(env, prefix, "NumDump", -1);
|
---|
372 | if (num<=0)
|
---|
373 | {
|
---|
374 | *fLog << err << GetDescriptor() << ": ERROR - NumDump invalid!" << endl;
|
---|
375 | return kERROR;
|
---|
376 | }
|
---|
377 |
|
---|
378 | SetNumDump(num);
|
---|
379 | rc = kTRUE;
|
---|
380 | }
|
---|
381 |
|
---|
382 | // find resource for numeventsdump
|
---|
383 | if (IsEnvDefined(env, prefix, "NumEventsDump", print))
|
---|
384 | {
|
---|
385 | SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
|
---|
386 | rc = kTRUE;
|
---|
387 | }
|
---|
388 |
|
---|
389 | // find resource for numeventsdump
|
---|
390 | if (IsEnvDefined(env, prefix, "NumAreasDump", print))
|
---|
391 | {
|
---|
392 | SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
|
---|
393 | rc = kTRUE;
|
---|
394 | }
|
---|
395 |
|
---|
396 | // find resource for numeventsdump
|
---|
397 | if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
|
---|
398 | {
|
---|
399 | SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
|
---|
400 | rc = kTRUE;
|
---|
401 | }
|
---|
402 |
|
---|
403 | return rc;
|
---|
404 | }
|
---|
405 |
|
---|
406 | void MPedCalcFromLoGain::Print(Option_t *o) const
|
---|
407 | {
|
---|
408 | MExtractPedestal::Print(o);
|
---|
409 |
|
---|
410 | *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;
|
---|
411 | if (fPedestalUpdate)
|
---|
412 | {
|
---|
413 | *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl;
|
---|
414 | *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl;
|
---|
415 | *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
|
---|
416 | }
|
---|
417 | }
|
---|