source: trunk/Mars/mpedestal/MPedCalcPedRun.cc@ 9969

Last change on this file since 9969 was 9462, checked in by tbretz, 15 years ago
*** empty log message ***
File size: 10.0 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MPedCalcPedRun.cc,v 1.55 2009-06-20 09:14:33 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!
26! Copyright: MAGIC Software Development, 2000-2007
27!
28!
29\* ======================================================================== */
30/////////////////////////////////////////////////////////////////////////////
31//
32// MPedCalcPedRun
33//
34// This task takes a pedestal run file and fills MPedestalCam during
35// the Process() with the pedestal and rms computed in an event basis.
36// In the PostProcess() MPedestalCam is finally filled with the pedestal
37// mean and rms computed in a run basis.
38// More than one run (file) can be merged
39//
40// MPedCalcPedRun applies the following formula (1):
41//
42// Pedestal per slice = sum(x_i) / n / slices
43// PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices )
44//
45// where x_i is the sum of "slices" FADC slices and sum means the sum over all
46// events. "n" is the number of events, "slices" is the number of summed FADC samples.
47//
48// Note that the slice-to-slice fluctuations are not Gaussian, but Poissonian, thus
49// asymmetric and they are correlated.
50//
51// It is important to know that the Pedestal per slice and PedRMS per slice depend
52// on the number of used FADC slices, as seen in the following plots:
53//
54//Begin_Html
55/*
56<img src="images/PedestalStudyInner.gif">
57*/
58//End_Html
59//
60//Begin_Html
61/*
62<img src="images/PedestalStudyOuter.gif">
63*/
64//
65// The plots show the inner and outer pixels, respectivly and have the following meaning:
66//
67// 1) The calculated mean pedestal per slice (from MPedCalcPedRun)
68// 2) The fitted mean pedestal per slice (from MHPedestalCam)
69// 3) The calculated pedestal RMS per slice (from MPedCalcPedRun)
70// 4) The fitted sigma of the pedestal distribution per slice
71// (from MHPedestalCam)
72// 5) The relative difference between calculation and histogram fit
73// for the mean
74// 6) The relative difference between calculation and histogram fit
75// for the sigma or RMS, respectively.
76//
77// The calculated means do not change significantly except for the case of 2 slices,
78// however the RMS changes from 5.7 per slice in the case of 2 extracted slices
79// to 8.3 per slice in the case of 26 extracted slices. This change is very significant.
80//
81// The plots have been produced on run 20123. You can reproduce them using
82// the macro pedestalstudies.C
83//
84// Usage of this class:
85// ====================
86//
87// Call: SetRange(higainfirst, higainlast, logainfirst, logainlast)
88// to modify the ranges in which the window is allowed to move.
89// Defaults are:
90//
91// fHiGainFirst = fgHiGainFirst = 0
92// fHiGainLast = fgHiGainLast = 29
93// fLoGainFirst = fgLoGainFirst = 0
94// fLoGainLast = fgLoGainLast = 14
95//
96// Call: SetWindowSize(windowhigain, windowlogain)
97// to modify the sliding window widths. Windows have to be an even number.
98// In case of odd numbers, the window will be modified.
99//
100// Defaults are:
101//
102// fHiGainWindowSize = fgHiGainWindowSize = 14
103// fLoGainWindowSize = fgLoGainWindowSize = 0
104//
105//
106// ToDo:
107// - Take a setup file (ReadEnv-implementation) as input
108//
109//
110// Input Containers:
111// MRawEvtData
112// MRawRunHeader
113// MRawEvtHeader
114// MGeomCam
115//
116// Output Containers:
117// MPedestalCam
118//
119// See also: MPedestalCam, MPedestalPix, MHPedestalCam, MExtractor
120//
121/////////////////////////////////////////////////////////////////////////////
122#include "MPedCalcPedRun.h"
123
124#include "MParList.h"
125
126#include "MLog.h"
127#include "MLogManip.h"
128
129#include "MRawRunHeader.h"
130#include "MRawEvtPixelIter.h"
131
132#include "MPedestalCam.h"
133
134#include "MTriggerPattern.h"
135
136ClassImp(MPedCalcPedRun);
137
138using namespace std;
139
140const UShort_t MPedCalcPedRun::fgExtractWinFirst = 0;
141const UShort_t MPedCalcPedRun::fgExtractWinSize = 6;
142
143const UInt_t MPedCalcPedRun::gkFirstRunWithFinalBits = 45605;
144
145// --------------------------------------------------------------------------
146//
147// Default constructor:
148//
149// Calls:
150// - SetExtractWindow(fgExtractWinFirst, fgExtractWinSize)
151//
152MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title)
153 : fIsFirstPedRun(kFALSE), fTrigPattern(NULL)
154{
155 fName = name ? name : "MPedCalcPedRun";
156 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
157
158 SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
159}
160
161// --------------------------------------------------------------------------
162//
163// Call MExtractPedestal::ResetArrays
164//
165void MPedCalcPedRun::Reset()
166{
167 MExtractPedestal::ResetArrays();
168}
169
170// --------------------------------------------------------------------------
171//
172// Set fIsFirstPedRun=kTRUE
173//
174Int_t MPedCalcPedRun::PreProcess(MParList *pList)
175{
176 fIsFirstPedRun = kTRUE;
177 fIsNotPedRun = kFALSE;
178
179 fTrigPattern = (MTriggerPattern*)pList->FindObject("MTriggerPattern");
180 if (!fTrigPattern)
181 *fLog << inf << "MTriggerPattern not found... Cannot use interlaced pedestal events." << endl;
182
183 return MExtractPedestal::PreProcess(pList);
184}
185
186// --------------------------------------------------------------------------
187//
188// The run type is checked for "kRTPedestal"
189// and the variable fIsNotPedRun is set in that case
190//
191Bool_t MPedCalcPedRun::ReInit(MParList *pList)
192{
193 if (!MExtractPedestal::ReInit(pList))
194 return kFALSE;
195
196 CheckExtractionWindow();
197
198 //
199 // If this is the first ped run, the next run (call to ReInit)
200 // is not the first anymore
201 //
202 switch (fRunHeader->GetRunType())
203 {
204 case MRawRunHeader::kRTPedestal:
205 case MRawRunHeader::kRTMonteCarlo:
206 fIsFirstPedRun = kFALSE;
207 fIsNotPedRun = kFALSE;
208 return kTRUE;
209
210 case MRawRunHeader::kRTCalibration:
211 {
212 TString proj(fRunHeader->GetProjectName());
213 proj.ToLower();
214
215 // test if a continuous light run has been declared as calibration...
216 if (proj.Contains("cl"))
217 {
218 fIsFirstPedRun = kFALSE;
219 fIsNotPedRun = kFALSE;
220 return kTRUE;
221 }
222 }
223 }
224
225 fIsNotPedRun = kTRUE;
226
227 //
228 // If this is the first call to ReInit (before reading the first file)
229 // nothing should be done. It occurs for the case that the first treated
230 // file is not of pedestal type.
231 //
232 if (fIsFirstPedRun)
233 return kTRUE;
234
235 //
236 // In the other case, produce the MPedestalCam to be use the subsequent
237 // (non-pedestal) events
238 //
239 *fLog << inf << "Finalizing pedestal calculations..." << flush;
240
241 if (!Finalize())
242 return kFALSE;
243
244 Reset();
245
246 return kTRUE;
247}
248
249// --------------------------------------------------------------------------
250//
251// Return kTRUE (without doing anything) in case that the run type is not
252// equal to 1 (pedestal run)
253//
254// Fill the MPedestalCam container with the signal mean and rms for the event.
255// Store the measured signal in arrays fSumx and fSumx2 so that we can
256// calculate the overall mean and rms in the PostProcess()
257//
258void MPedCalcPedRun::Calc()
259{
260 if (fIsNotPedRun && !IsPedBitSet())
261 return;
262
263 MRawEvtPixelIter pixel(fRawEvt);
264 while (pixel.Next())
265 CalcPixel(pixel, 0, fUseSpecialPixels);
266
267 fCounter++;
268
269 fPedestalsOut->SetReadyToSave();
270}
271
272// --------------------------------------------------------------------------
273//
274// Compute signal mean and rms in the whole run and store it in MPedestalCam
275//
276Int_t MPedCalcPedRun::Finalize()
277{
278 //
279 // Necessary check for extraction of special pixels
280 // together with data which does not yet have them
281 //
282 if (fSumx.GetSize()==0)
283 return kTRUE;
284
285 CalcPixResult();
286
287 if (!fUseSpecialPixels)
288 {
289 CalcAreaResult();
290 CalcSectorResult();
291 }
292
293 fPedestalsOut->SetNumSlices(fExtractWinSize);
294 fPedestalsOut->SetReadyToSave();
295
296 return kTRUE;
297}
298
299//-----------------------------------------------------------------------
300//
301// PostProcess MExtractPedestal and call Finalize
302//
303Int_t MPedCalcPedRun::PostProcess()
304{
305 if (!fRawEvt)
306 return kTRUE;
307
308 if (!Finalize())
309 return kFALSE;
310
311 return MExtractPedestal::PostProcess();
312}
313
314//-----------------------------------------------------------------------
315//
316// Return if the pedestal bit was set from the calibration trigger box.
317// The last but one bit is used for the "pedestal-bit".
318//
319// This bit is set since run gkFirstRunWithFinalBits
320//
321Bool_t MPedCalcPedRun::IsPedBitSet()
322{
323 if (!fRunHeader->IsMonteCarloRun() && fRunHeader->GetTelescopeNumber()==1 && fRunHeader->GetRunNumber()<gkFirstRunWithFinalBits)
324 return kFALSE;
325
326 if (!fTrigPattern)
327 return kFALSE;
328
329 return (fTrigPattern->GetPrescaled() & MTriggerPattern::kPedestal) ? kTRUE : kFALSE;
330}
331
332//-----------------------------------------------------------------------
333//
334void MPedCalcPedRun::Print(Option_t *o) const
335{
336 MExtractPedestal::Print(o);
337
338 *fLog << "First pedrun out of sequence: " << (fIsFirstPedRun?"yes":"no") << endl;
339}
Note: See TracBrowser for help on using the repository browser.