source: trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc@ 8907

Last change on this file since 8907 was 8788, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 10.8 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MPedCalcFromLoGain.cc,v 1.39 2007-12-14 09:56:03 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-2007
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 "MPedestalCam.h"
148
149ClassImp(MPedCalcFromLoGain);
150
151using namespace std;
152
153const UShort_t MPedCalcFromLoGain::fgExtractWinFirst = 17;
154const UShort_t MPedCalcFromLoGain::fgExtractWinSize = 6;
155const UInt_t MPedCalcFromLoGain::fgNumDump = 500;
156
157// --------------------------------------------------------------------------
158//
159// Default constructor:
160//
161// Calls:
162// - SetExtractWindow(fgExtractWinFirst, fgExtractWinSize)
163//
164MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title)
165{
166 fName = name ? name : "MPedCalcFromLoGain";
167 fTitle = title ? title : "Task to calculate pedestals from lo-gains";
168
169 SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
170 SetPedestalUpdate(kTRUE);
171 SetNumDump();
172}
173
174// ---------------------------------------------------------------------------------
175//
176// Checks:
177// - if the number of available slices
178// (fRunHeader->GetNumSamplesHiGain()+(Int_t)fRunHeader->GetNumSamplesLoGain()-1)
179// is smaller than the number of used slices
180// (fExtractWinSize+ fExtractWinFirst-1) or
181// fCheckWinLast
182//
183Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
184{
185 if (!MExtractPedestal::ReInit(pList))
186 return kFALSE;
187
188 const Int_t nhi = fRunHeader->GetNumSamplesHiGain();
189 const Int_t nlo = fRunHeader->GetNumSamplesLoGain();
190 CheckExtractionWindow(nlo>0?nhi:0);
191
192 return kTRUE;
193}
194
195// --------------------------------------------------------------------------
196//
197// Fill the MPedestalCam container with the signal mean and rms for the event.
198// Store the measured signal in arrays fSumx and fSumx2 so that we can
199// calculate the overall mean and rms in the PostProcess()
200//
201Int_t MPedCalcFromLoGain::Calc()
202{
203 const Int_t nhi = fRunHeader->GetNumSamplesHiGain();
204 const Int_t nlo = fRunHeader->GetNumSamplesLoGain();
205
206 const Int_t offset = nlo>0?nhi:0;
207
208 // Real Process
209 MRawEvtPixelIter pixel(fRawEvt);
210 while (pixel.Next())
211 {
212 if (!CalcPixel(pixel, offset))
213 continue;
214
215 const UInt_t idx = pixel.GetPixelId();
216 if (!fPedestalUpdate || (UInt_t)fNumEventsUsed[idx]<fNumEventsDump)
217 continue;
218
219 CalcPixResults(idx);
220
221 fNumEventsUsed[idx]=0;
222 fSumx[idx]=0;
223 fSumx2[idx]=0;
224 fSumAB0[idx]=0;
225 fSumAB1[idx]=0;
226 }
227
228 if (fNumAreasDump>0 && !(GetNumExecutions() % fNumAreasDump))
229 {
230 CalcAreaResult();
231 fAreaFilled.Reset();
232 }
233
234 if (fNumSectorsDump>0 && !(GetNumExecutions() % fNumSectorsDump))
235 {
236 CalcSectorResult();
237 fSectorFilled.Reset();
238 }
239
240 fCounter++;
241
242 if (fPedestalUpdate)
243 fPedestalsOut->SetReadyToSave();
244
245 return kTRUE;
246}
247
248// --------------------------------------------------------------------------
249//
250// Compute signal mean and rms in the whole run and store it in MPedestalCam
251//
252Int_t MPedCalcFromLoGain::PostProcess()
253{
254 // Compute pedestals and rms from the whole run
255 if (fPedestalUpdate)
256 return kTRUE;
257
258 *fLog << flush << inf << "Calculating Pedestals..." << flush;
259
260 CalcPixResult();
261 CalcAreaResult();
262 CalcSectorResult();
263
264 fPedestalsOut->SetReadyToSave();
265
266 return MExtractPedestal::PostProcess();
267}
268
269// --------------------------------------------------------------------------
270//
271// The following resources are available:
272//
273Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
274{
275 Int_t rc=MExtractPedestal::ReadEnv(env, prefix, print);
276 if (rc==kERROR)
277 return kERROR;
278
279 // find resource for pedestal update
280 if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
281 {
282 SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
283 rc = kTRUE;
284 }
285
286 // find resource for numdump
287 if (IsEnvDefined(env, prefix, "NumDump", print))
288 {
289 const Int_t num = GetEnvValue(env, prefix, "NumDump", -1);
290 if (num<=0)
291 {
292 *fLog << err << GetDescriptor() << ": ERROR - NumDump invalid!" << endl;
293 return kERROR;
294 }
295
296 SetNumDump(num);
297 rc = kTRUE;
298 }
299
300 // find resource for numeventsdump
301 if (IsEnvDefined(env, prefix, "NumEventsDump", print))
302 {
303 SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
304 rc = kTRUE;
305 }
306
307 // find resource for numeventsdump
308 if (IsEnvDefined(env, prefix, "NumAreasDump", print))
309 {
310 SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
311 rc = kTRUE;
312 }
313
314 // find resource for numeventsdump
315 if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
316 {
317 SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
318 rc = kTRUE;
319 }
320
321 return rc;
322}
323
324void MPedCalcFromLoGain::Print(Option_t *o) const
325{
326 MExtractPedestal::Print(o);
327
328 *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;
329 if (fPedestalUpdate)
330 {
331 *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl;
332 *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl;
333 *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
334 }
335}
Note: See TracBrowser for help on using the repository browser.