source: branches/MarsMoreSimulationTruth/mpedestal/MPedCalcPedRun.cc@ 20115

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