source: trunk/Mars/mpedestal/MPedCalcFromLoGain.cc@ 12740

Last change on this file since 12740 was 10166, checked in by tbretz, 14 years ago
Removed the old obsolete cvs header line.
File size: 10.6 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): Josep Flix 04/2001 <mailto:jflix@ifae.es>
19! Author(s): Thomas Bretz 05/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
20! Author(s): Sebastian Commichau 12/2003
21! Author(s): Javier Rico 01/2004 <mailto:jrico@ifae.es>
22! Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es>
23! Author(s): Florian Goebel 06/2004 <mailto:fgoebel@mppmu.mpg.de>
24! Author(s): Nepomuk Otte 10/2004 <mailto:otte@mppmu.mpg.de>
25!
26! Copyright: MAGIC Software Development, 2000-2007
27!
28!
29\* ======================================================================== */
30
31/////////////////////////////////////////////////////////////////////////////
32//
33// MPedCalcLoGain
34//
35// This task derives from MExtractPedestal.
36// It calculates the pedestals using the low gain slices, whenever the difference
37// between the highest and the lowest slice in the high gain
38// slices is below a given threshold (SetMaxHiGainVar). In this case the receiver
39// boards do not switch to lo gain and the so called lo gain slices are actually
40// high gain slices.
41//
42// MPedCalcLoGain also fills the ABoffset in MPedestalPix which allows to correct
43// the 150 MHz clock noise.
44//
45// This task takes a pedestal run file and fills MPedestalCam during
46// the Process() with the pedestal and rms computed in an event basis.
47// In the PostProcess() MPedestalCam is finally filled with the pedestal
48// mean and rms computed in a run basis.
49// More than one run (file) can be merged
50//
51// MPedCalcPedRun applies the following formula (1):
52//
53// Pedestal per slice = sum(x_i) / n / slices
54// PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices )
55//
56// where x_i is the sum of "slices" FADC slices and sum means the sum over all
57// events. "n" is the number of events, "slices" is the number of summed FADC samples.
58//
59// Note that the slice-to-slice fluctuations are not Gaussian, but Poissonian, thus
60// asymmetric and they are correlated.
61//
62// It is important to know that the Pedestal per slice and PedRMS per slice depend
63// on the number of used FADC slices, as seen in the following plots:
64//
65//Begin_Html
66/*
67<img src="images/PedestalStudyInner.gif">
68*/
69//End_Html
70//
71//Begin_Html
72/*
73<img src="images/PedestalStudyOuter.gif">
74*/
75//End_Html
76//
77// The plots show the inner and outer pixels, respectivly and have the following meaning:
78//
79// 1) The calculated mean pedestal per slice (from MPedCalcFromLoGain)
80// 2) The fitted mean pedestal per slice (from MHPedestalCam)
81// 3) The calculated pedestal RMS per slice (from MPedCalcFromLoGain)
82// 4) The fitted sigma of the pedestal distribution per slice
83// (from MHPedestalCam)
84// 5) The relative difference between calculation and histogram fit
85// for the mean
86// 6) The relative difference between calculation and histogram fit
87// for the sigma or RMS, respectively.
88//
89// The calculated means do not change significantly except for the case of 2 slices,
90// however the RMS changes from 5.7 per slice in the case of 2 extracted slices
91// to 8.3 per slice in the case of 26 extracted slices. This change is very significant.
92//
93// The plots have been produced on run 20123. You can reproduce them using
94// the macro pedestalstudies.C
95//
96// Usage of this class:
97// ====================
98//
99//
100// fCheckWinFirst = fgCheckWinFirst = 0
101// fCheckWinLast = fgCheckWinLast = 29
102// fExtractWinFirst = fgExtractWinFirst = 17
103// fExtractWinSize = fgExtractWinSize = 6
104// fMaxSignalVar = fgMaxSignalVar = 40;
105//
106// Call:
107// SetCheckRange(fCheckWinFirst,fCheckWinLast);
108// to set the Window in which a signal is searched
109//
110// SetExtractWindow(fExtractWinFirst,fExtractWinSize);
111// to set the Window from which a signal is extracted
112//
113// SetMaxSignalVar(fMaxSignalVar);
114// set the maximum allowed difference between maximum and minimal signal in CheckWindow
115//
116// Variables:
117// fgCheckWinFirst; First FADC slice to check for signal (currently set to: 0)
118// fgCheckWinLast: Last FADC slice to check for signal (currently set to: 29)
119// fgExtractWinFirst: First FADC slice to be used for pedestal extraction (currently set to: 15)
120// fgExtractWinSize: Window size in slices used for pedestal extraction (currently set to: 6)
121// fgMaxSignalVar: The maximum difference between the highest and lowest slice
122// in the check window allowed in order to use event
123//
124// Input Containers:
125// MRawEvtData
126// MRawRunHeader
127// MGeomCam
128//
129// Output Containers:
130// MPedestalCam
131//
132// See also: MPedestalCam, MPedestalPix, MHPedestalCam, MExtractor
133//
134/////////////////////////////////////////////////////////////////////////////
135#include "MPedCalcFromLoGain.h"
136
137#include "MParList.h"
138
139#include "MLog.h"
140#include "MLogManip.h"
141
142#include "MRawRunHeader.h"
143#include "MRawEvtPixelIter.h"
144
145#include "MPedestalCam.h"
146
147ClassImp(MPedCalcFromLoGain);
148
149using namespace std;
150
151const UShort_t MPedCalcFromLoGain::fgExtractWinFirst = 17;
152const UShort_t MPedCalcFromLoGain::fgExtractWinSize = 6;
153const UInt_t MPedCalcFromLoGain::fgNumDump = 500;
154
155// --------------------------------------------------------------------------
156//
157// Default constructor:
158//
159// Calls:
160// - SetExtractWindow(fgExtractWinFirst, fgExtractWinSize)
161//
162MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title)
163{
164 fName = name ? name : "MPedCalcFromLoGain";
165 fTitle = title ? title : "Task to calculate pedestals from lo-gains";
166
167 SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
168 SetPedestalUpdate(kTRUE);
169 SetNumDump();
170}
171
172// ---------------------------------------------------------------------------------
173//
174// Checks:
175// - if the number of available slices
176// (fRunHeader->GetNumSamplesHiGain()+(Int_t)fRunHeader->GetNumSamplesLoGain()-1)
177// is smaller than the number of used slices
178// (fExtractWinSize+ fExtractWinFirst-1) or
179// fCheckWinLast
180//
181Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
182{
183 if (!MExtractPedestal::ReInit(pList))
184 return kFALSE;
185
186 const Int_t nhi = fRunHeader->GetNumSamplesHiGain();
187 const Int_t nlo = fRunHeader->GetNumSamplesLoGain();
188 CheckExtractionWindow(nlo>0?nhi:0);
189
190 return kTRUE;
191}
192
193// --------------------------------------------------------------------------
194//
195// Fill the MPedestalCam container with the signal mean and rms for the event.
196// Store the measured signal in arrays fSumx and fSumx2 so that we can
197// calculate the overall mean and rms in the PostProcess()
198//
199void MPedCalcFromLoGain::Calc()
200{
201 const Int_t nhi = fRunHeader->GetNumSamplesHiGain();
202 const Int_t nlo = fRunHeader->GetNumSamplesLoGain();
203
204 const Int_t offset = nlo>0?nhi:0;
205
206 // Real Process
207 MRawEvtPixelIter pixel(fRawEvt);
208 while (pixel.Next())
209 {
210 if (!CalcPixel(pixel, offset))
211 continue;
212
213 const UInt_t idx = pixel.GetPixelId();
214 if (!fPedestalUpdate || (UInt_t)fNumEventsUsed[idx]<fNumEventsDump)
215 continue;
216
217 CalcPixResults(idx);
218
219 fNumEventsUsed[idx]=0;
220 fSumx[idx]=0;
221 fSumx2[idx]=0;
222 fSumAB0[idx]=0;
223 fSumAB1[idx]=0;
224 }
225
226 if (fNumAreasDump>0 && !(GetNumExecutions() % fNumAreasDump))
227 {
228 CalcAreaResult();
229 fAreaFilled.Reset();
230 }
231
232 if (fNumSectorsDump>0 && !(GetNumExecutions() % fNumSectorsDump))
233 {
234 CalcSectorResult();
235 fSectorFilled.Reset();
236 }
237
238 fCounter++;
239
240 if (fPedestalUpdate)
241 fPedestalsOut->SetReadyToSave();
242}
243
244// --------------------------------------------------------------------------
245//
246// Compute signal mean and rms in the whole run and store it in MPedestalCam
247//
248Int_t MPedCalcFromLoGain::PostProcess()
249{
250 // Compute pedestals and rms from the whole run
251 if (fPedestalUpdate)
252 return kTRUE;
253
254 *fLog << flush << inf << "Calculating Pedestals..." << flush;
255
256 CalcPixResult();
257 CalcAreaResult();
258 CalcSectorResult();
259
260 fPedestalsOut->SetReadyToSave();
261
262 return MExtractPedestal::PostProcess();
263}
264
265// --------------------------------------------------------------------------
266//
267// The following resources are available:
268//
269Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
270{
271 Int_t rc=MExtractPedestal::ReadEnv(env, prefix, print);
272 if (rc==kERROR)
273 return kERROR;
274
275 // find resource for pedestal update
276 if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
277 {
278 SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
279 rc = kTRUE;
280 }
281
282 // find resource for numdump
283 if (IsEnvDefined(env, prefix, "NumDump", print))
284 {
285 const Int_t num = GetEnvValue(env, prefix, "NumDump", -1);
286 if (num<=0)
287 {
288 *fLog << err << GetDescriptor() << ": ERROR - NumDump invalid!" << endl;
289 return kERROR;
290 }
291
292 SetNumDump(num);
293 rc = kTRUE;
294 }
295
296 // find resource for numeventsdump
297 if (IsEnvDefined(env, prefix, "NumEventsDump", print))
298 {
299 SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
300 rc = kTRUE;
301 }
302
303 // find resource for numeventsdump
304 if (IsEnvDefined(env, prefix, "NumAreasDump", print))
305 {
306 SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
307 rc = kTRUE;
308 }
309
310 // find resource for numeventsdump
311 if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
312 {
313 SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
314 rc = kTRUE;
315 }
316
317 return rc;
318}
319
320void MPedCalcFromLoGain::Print(Option_t *o) const
321{
322 MExtractPedestal::Print(o);
323
324 *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;
325 if (fPedestalUpdate)
326 {
327 *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl;
328 *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl;
329 *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
330 }
331}
Note: See TracBrowser for help on using the repository browser.