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 | !
|
---|
25 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
26 | !
|
---|
27 | !
|
---|
28 | \* ======================================================================== */
|
---|
29 |
|
---|
30 | /////////////////////////////////////////////////////////////////////////////
|
---|
31 | //
|
---|
32 | // MPedCalcLoGain
|
---|
33 | //
|
---|
34 | //
|
---|
35 | // This task is devide form MPedCalcPedRun, described below. However, It
|
---|
36 | // calculates the pedstals 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 | //
|
---|
76 | // The plots show the inner and outer pixels, respectivly and have the following meaning:
|
---|
77 | //
|
---|
78 | // 1) The calculated mean pedestal per slice (from MPedCalcFromLoGain)
|
---|
79 | // 2) The fitted mean pedestal per slice (from MHPedestalCam)
|
---|
80 | // 3) The calculated pedestal RMS per slice (from MPedCalcFromLoGain)
|
---|
81 | // 4) The fitted sigma of the pedestal distribution per slice
|
---|
82 | // (from MHPedestalCam)
|
---|
83 | // 5) The relative difference between calculation and histogram fit
|
---|
84 | // for the mean
|
---|
85 | // 6) The relative difference between calculation and histogram fit
|
---|
86 | // for the sigma or RMS, respectively.
|
---|
87 | //
|
---|
88 | // The calculated means do not change significantly except for the case of 2 slices,
|
---|
89 | // however the RMS changes from 5.7 per slice in the case of 2 extracted slices
|
---|
90 | // to 8.3 per slice in the case of 26 extracted slices. This change is very significant.
|
---|
91 | //
|
---|
92 | // The plots have been produced on run 20123. You can reproduce them using
|
---|
93 | // the macro pedestalstudies.C
|
---|
94 | //
|
---|
95 | // Usage of this class:
|
---|
96 | // ====================
|
---|
97 | //
|
---|
98 | // Call: SetRange(higainfirst, higainlast, logainfirst, logainlast)
|
---|
99 | // to modify the ranges in which the window is allowed to move.
|
---|
100 | // Defaults are:
|
---|
101 | //
|
---|
102 | // fHiGainFirst = fgHiGainFirst = 0
|
---|
103 | // fHiGainLast = fgHiGainLast = 29
|
---|
104 | // fLoGainFirst = fgLoGainFirst = 0
|
---|
105 | // fLoGainLast = fgLoGainLast = 14
|
---|
106 | //
|
---|
107 | // Call: SetWindowSize(windowhigain, windowlogain)
|
---|
108 | // to modify the sliding window widths. Windows have to be an even number.
|
---|
109 | // In case of odd numbers, the window will be modified.
|
---|
110 | //
|
---|
111 | // Defaults are:
|
---|
112 | //
|
---|
113 | // fHiGainWindowSize = fgHiGainWindowSize = 14
|
---|
114 | // fLoGainWindowSize = fgLoGainWindowSize = 0
|
---|
115 | //
|
---|
116 | // Variables:
|
---|
117 | // fgHiGainFirst; First FADC slice Hi-Gain (currently set to: 3)
|
---|
118 | // fgHiGainLast: Last FADC slice Hi-Gain (currently set to: 14)
|
---|
119 | // fgLoGainFirst: First FADC slice Lo-Gain (currently set to: 3)
|
---|
120 | // fgLoGainLast: Last FADC slice Lo-Gain (currently set to: 14)
|
---|
121 | // fgHiGainWindowSize: The extraction window Hi-Gain
|
---|
122 | // fgLoGainWindowSize: The extraction window Lo-Gain
|
---|
123 | // fgMaxHiGainVar: The maximum difference between the highest and lowest slice
|
---|
124 | // in the high gain window allowed in order to use low gain
|
---|
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 | #include "MExtractor.h"
|
---|
139 |
|
---|
140 | #include "MParList.h"
|
---|
141 |
|
---|
142 | #include "MLog.h"
|
---|
143 | #include "MLogManip.h"
|
---|
144 |
|
---|
145 | #include "MRawRunHeader.h"
|
---|
146 | #include "MRawEvtPixelIter.h"
|
---|
147 | #include "MRawEvtData.h"
|
---|
148 |
|
---|
149 | #include "MPedestalPix.h"
|
---|
150 | #include "MPedestalCam.h"
|
---|
151 |
|
---|
152 | #include "MGeomPix.h"
|
---|
153 | #include "MGeomCam.h"
|
---|
154 |
|
---|
155 | ClassImp(MPedCalcFromLoGain);
|
---|
156 |
|
---|
157 | using namespace std;
|
---|
158 |
|
---|
159 | const Byte_t MPedCalcFromLoGain::fgHiGainFirst = 0;
|
---|
160 | const Byte_t MPedCalcFromLoGain::fgHiGainLast = 11;
|
---|
161 | const Byte_t MPedCalcFromLoGain::fgLoGainFirst = 1;
|
---|
162 | const Byte_t MPedCalcFromLoGain::fgLoGainLast = 14;
|
---|
163 | const Byte_t MPedCalcFromLoGain::fgHiGainWindowSize = 12;
|
---|
164 | const Byte_t MPedCalcFromLoGain::fgLoGainWindowSize = 14;
|
---|
165 | const Byte_t MPedCalcFromLoGain::fgMaxHiGainVar = 40;
|
---|
166 |
|
---|
167 | // --------------------------------------------------------------------------
|
---|
168 | //
|
---|
169 | // Default constructor:
|
---|
170 | //
|
---|
171 | // Sets:
|
---|
172 | // - all pointers to NULL
|
---|
173 | // - fWindowSizeHiGain to fgHiGainWindowSize
|
---|
174 | // - fWindowSizeLoGain to fgLoGainWindowSize
|
---|
175 | //
|
---|
176 | // Calls:
|
---|
177 | // - AddToBranchList("fHiGainPixId");
|
---|
178 | // - AddToBranchList("fHiGainFadcSamples");
|
---|
179 | // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
|
---|
180 | // - Clear()
|
---|
181 | //
|
---|
182 | MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title)
|
---|
183 | : fWindowSizeHiGain(fgHiGainWindowSize),
|
---|
184 | fWindowSizeLoGain(fgLoGainWindowSize),
|
---|
185 | fGeom(NULL), fPedContainerName("MPedestalCam")
|
---|
186 | {
|
---|
187 | fName = name ? name : "MPedCalcFromLoGain";
|
---|
188 | fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
|
---|
189 |
|
---|
190 | AddToBranchList("fHiGainPixId");
|
---|
191 | AddToBranchList("fLoGainPixId");
|
---|
192 | AddToBranchList("fHiGainFadcSamples");
|
---|
193 | AddToBranchList("fLoGainFadcSamples");
|
---|
194 |
|
---|
195 | SetRange();
|
---|
196 | SetMaxHiGainVar();
|
---|
197 | SetPedestalUpdate(kTRUE);
|
---|
198 |
|
---|
199 | Clear();
|
---|
200 | }
|
---|
201 |
|
---|
202 | // --------------------------------------------------------------------------
|
---|
203 | //
|
---|
204 | // Sets:
|
---|
205 | // - fNumSamplesTot to 0
|
---|
206 | // - fRawEvt to NULL
|
---|
207 | // - fRunHeader to NULL
|
---|
208 | // - fPedestals to NULL
|
---|
209 | //
|
---|
210 | void MPedCalcFromLoGain::Clear(const Option_t *o)
|
---|
211 | {
|
---|
212 | fRawEvt = NULL;
|
---|
213 | fRunHeader = NULL;
|
---|
214 | fPedestals = NULL;
|
---|
215 |
|
---|
216 | // If the size is yet set, set the size
|
---|
217 | if (fSumx.GetSize()>0)
|
---|
218 | {
|
---|
219 | // Reset contents of arrays.
|
---|
220 | fSumx.Reset();
|
---|
221 | fSumx2.Reset();
|
---|
222 | fSumAB0.Reset();
|
---|
223 | fSumAB1.Reset();
|
---|
224 | fNumEventsUsed.Reset();
|
---|
225 | fTotalCounter.Reset();
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | // --------------------------------------------------------------------------
|
---|
230 | //
|
---|
231 | // SetRange:
|
---|
232 | //
|
---|
233 | // Calls:
|
---|
234 | // - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
---|
235 | // - SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);
|
---|
236 | //
|
---|
237 | void MPedCalcFromLoGain::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
238 | {
|
---|
239 | MExtractor::SetRange(hifirst, hilast, lofirst, lolast);
|
---|
240 |
|
---|
241 | //
|
---|
242 | // Redo the checks if the window is still inside the ranges
|
---|
243 | //
|
---|
244 | SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);
|
---|
245 | }
|
---|
246 |
|
---|
247 | // --------------------------------------------------------------------------
|
---|
248 | //
|
---|
249 | void MPedCalcFromLoGain::SetMaxHiGainVar(Byte_t maxvar)
|
---|
250 | {
|
---|
251 | fMaxHiGainVar = maxvar;
|
---|
252 | }
|
---|
253 |
|
---|
254 | // --------------------------------------------------------------------------
|
---|
255 | //
|
---|
256 | // Checks:
|
---|
257 | // - if a window is odd, subtract one
|
---|
258 | // - if a window is bigger than the one defined by the ranges, set it to the available range
|
---|
259 | // - if a window is smaller than 2, set it to 2
|
---|
260 | //
|
---|
261 | // Sets:
|
---|
262 | // - fNumHiGainSamples to: (Float_t)fWindowSizeHiGain
|
---|
263 | // - fNumLoGainSamples to: (Float_t)fWindowSizeLoGain
|
---|
264 | // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
|
---|
265 | // - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)
|
---|
266 | //
|
---|
267 | void MPedCalcFromLoGain::SetWindowSize(Byte_t windowh, Byte_t windowl)
|
---|
268 | {
|
---|
269 | fWindowSizeHiGain = windowh & ~1;
|
---|
270 | fWindowSizeLoGain = windowl & ~1;
|
---|
271 |
|
---|
272 | if (fWindowSizeHiGain != windowh)
|
---|
273 | {
|
---|
274 | *fLog << warn;
|
---|
275 | *fLog << GetDescriptor() << ": HiGain window has to be even, set to: ";
|
---|
276 | *fLog << int(fWindowSizeHiGain) << " samples " << endl;
|
---|
277 | }
|
---|
278 |
|
---|
279 | if (fWindowSizeLoGain != windowl)
|
---|
280 | {
|
---|
281 | *fLog << warn;
|
---|
282 | *fLog << GetDescriptor() << ": Lo Gain window has to be even, set to: ";
|
---|
283 | *fLog << int(fWindowSizeLoGain) << " samples " << endl;
|
---|
284 | }
|
---|
285 |
|
---|
286 | const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1;
|
---|
287 | const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1;
|
---|
288 |
|
---|
289 | if (fWindowSizeHiGain > availhirange)
|
---|
290 | {
|
---|
291 | *fLog << warn;
|
---|
292 | *fLog << GetDescriptor() << ": HiGain window " << (int)fWindowSizeHiGain;
|
---|
293 | *fLog << " out of range [" << (int)fHiGainFirst;
|
---|
294 | *fLog << "," << (int)fHiGainLast << "]" << endl;
|
---|
295 | *fLog << "Will set window size to " << (int)availhirange << endl;
|
---|
296 | fWindowSizeHiGain = availhirange;
|
---|
297 | }
|
---|
298 |
|
---|
299 | if (fWindowSizeLoGain > availlorange)
|
---|
300 | {
|
---|
301 | *fLog << warn;
|
---|
302 | *fLog << GetDescriptor() << ": LoGain window " << (int)fWindowSizeLoGain;
|
---|
303 | *fLog << " out of range [" << (int)fLoGainFirst;
|
---|
304 | *fLog << "," << (int)fLoGainLast << "]" << endl;
|
---|
305 | *fLog << "Will set window size to " << (int)availlorange << endl;
|
---|
306 | fWindowSizeLoGain = availlorange;
|
---|
307 | }
|
---|
308 | /*
|
---|
309 | fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
|
---|
310 | fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
|
---|
311 |
|
---|
312 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
---|
313 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
---|
314 | */
|
---|
315 | }
|
---|
316 |
|
---|
317 | // --------------------------------------------------------------------------
|
---|
318 | //
|
---|
319 | // Look for the following input containers:
|
---|
320 | //
|
---|
321 | // - MRawEvtData
|
---|
322 | // - MRawRunHeader
|
---|
323 | // - MGeomCam
|
---|
324 | //
|
---|
325 | // The following output containers are also searched and created if
|
---|
326 | // they were not found:
|
---|
327 | //
|
---|
328 | // - MPedestalCam
|
---|
329 | //
|
---|
330 | Int_t MPedCalcFromLoGain::PreProcess(MParList *pList)
|
---|
331 | {
|
---|
332 | Clear();
|
---|
333 |
|
---|
334 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
335 | if (!fRawEvt)
|
---|
336 | {
|
---|
337 | *fLog << err << "MRawEvtData not found... aborting." << endl;
|
---|
338 | return kFALSE;
|
---|
339 | }
|
---|
340 |
|
---|
341 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
---|
342 | if (!fRunHeader)
|
---|
343 | {
|
---|
344 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
---|
345 | return kFALSE;
|
---|
346 | }
|
---|
347 |
|
---|
348 | fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
349 | if (!fGeom)
|
---|
350 | {
|
---|
351 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
---|
352 | return kFALSE;
|
---|
353 | }
|
---|
354 |
|
---|
355 | fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fPedContainerName));
|
---|
356 | if (!fPedestals)
|
---|
357 | return kFALSE;
|
---|
358 |
|
---|
359 | if (fNumEventsDump<=0 && fPedestalUpdate)
|
---|
360 | {
|
---|
361 | *fLog << warn << "Pedestal Update switched on and Number of Events to dump <= 0... fNumEventsDump=1000" << endl;
|
---|
362 | fNumEventsDump=1000;
|
---|
363 | }
|
---|
364 |
|
---|
365 | return kTRUE;
|
---|
366 | }
|
---|
367 |
|
---|
368 | // --------------------------------------------------------------------------
|
---|
369 | //
|
---|
370 | // The ReInit searches for:
|
---|
371 | // - MRawRunHeader::GetNumSamplesHiGain()
|
---|
372 | // - MRawRunHeader::GetNumSamplesLoGain()
|
---|
373 | //
|
---|
374 | // In case that the variables fHiGainLast and fLoGainLast are smaller than
|
---|
375 | // the even part of the number of samples obtained from the run header, a
|
---|
376 | // warning is given an the range is set back accordingly. A call to:
|
---|
377 | // - SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast) or
|
---|
378 | // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
|
---|
379 | // is performed in that case. The variable diff means here the difference
|
---|
380 | // between the requested range (fHiGainLast) and the available one. Note that
|
---|
381 | // the functions SetRange() are mostly overloaded and perform more checks,
|
---|
382 | // modifying the ranges again, if necessary.
|
---|
383 | //
|
---|
384 | Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
|
---|
385 | {
|
---|
386 | if (fRunHeader->GetNumSamplesHiGain()<1)
|
---|
387 | {
|
---|
388 | *fLog << err << "ERROR - Number of available HiGainSamples<1... abort." << endl;
|
---|
389 | return kFALSE;
|
---|
390 | }
|
---|
391 | if (fRunHeader->GetNumSamplesLoGain()<1)
|
---|
392 | {
|
---|
393 | *fLog << err << "ERROR - Number of available LoGainSamples<1... abort." << endl;
|
---|
394 | return kFALSE;
|
---|
395 | }
|
---|
396 |
|
---|
397 | fHiGainFirst = TMath::Max(fHiGainFirst, 0);
|
---|
398 | fHiGainLast = TMath::Min(fHiGainLast, fRunHeader->GetNumSamplesHiGain()-1);
|
---|
399 |
|
---|
400 | fLoGainFirst = TMath::Max(fLoGainFirst, 0);
|
---|
401 | fLoGainLast = TMath::Min(fLoGainLast, fRunHeader->GetNumSamplesLoGain()-1);
|
---|
402 |
|
---|
403 | fWindowSizeHiGain = TMath::Min(fWindowSizeHiGain, fHiGainLast-fHiGainFirst+1);
|
---|
404 | fWindowSizeLoGain = TMath::Min(fWindowSizeLoGain, fLoGainLast-fLoGainFirst+1);
|
---|
405 |
|
---|
406 | SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast);
|
---|
407 |
|
---|
408 | *fLog << inf << endl;
|
---|
409 | *fLog << "Taking " << Form("%2d", (int)fWindowSizeHiGain) << " HiGain from " << (int)fHiGainFirst << endl;
|
---|
410 | *fLog << "Taking " << Form("%2d", (int)fWindowSizeLoGain) << " LoGain from " << (int)fLoGainFirst << endl;
|
---|
411 |
|
---|
412 | if (fWindowSizeHiGain==0)
|
---|
413 | {
|
---|
414 | *fLog << err << "ERROR - HiGain windows size == 0... abort." << endl;
|
---|
415 | return kFALSE;
|
---|
416 | }
|
---|
417 | if (fWindowSizeLoGain==0)
|
---|
418 | {
|
---|
419 | *fLog << err << "ERROR - HiGain windows size == 0... abort." << endl;
|
---|
420 | return kFALSE;
|
---|
421 | }
|
---|
422 |
|
---|
423 | // If the size is not yet set, set the size
|
---|
424 | if (fSumx.GetSize()==0)
|
---|
425 | {
|
---|
426 | const Int_t npixels = fPedestals->GetSize();
|
---|
427 |
|
---|
428 | fSumx. Set(npixels);
|
---|
429 | fSumx2.Set(npixels);
|
---|
430 | fSumAB0.Set(npixels);
|
---|
431 | fSumAB1.Set(npixels);
|
---|
432 | fNumEventsUsed.Set(npixels);
|
---|
433 | fTotalCounter.Set(npixels);
|
---|
434 |
|
---|
435 | // Reset contents of arrays.
|
---|
436 | fSumx.Reset();
|
---|
437 | fSumx2.Reset();
|
---|
438 | fSumAB0.Reset();
|
---|
439 | fSumAB1.Reset();
|
---|
440 | fNumEventsUsed.Reset();
|
---|
441 | fTotalCounter.Reset();
|
---|
442 | }
|
---|
443 |
|
---|
444 | return kTRUE;
|
---|
445 | }
|
---|
446 |
|
---|
447 | void MPedCalcFromLoGain::Calc(ULong_t n, UInt_t idx)
|
---|
448 | {
|
---|
449 | const ULong_t nsamplestot = n*fWindowSizeLoGain;
|
---|
450 |
|
---|
451 | const Float_t sum = fSumx.At(idx);
|
---|
452 | const Float_t sum2 = fSumx2.At(idx);
|
---|
453 | const Float_t ped = sum/nsamplestot;
|
---|
454 |
|
---|
455 | // 1. Calculate the Variance of the sums:
|
---|
456 | Float_t var = (sum2-sum*sum/n)/(n-1.);
|
---|
457 |
|
---|
458 | // 2. Scale the variance to the number of slices:
|
---|
459 | var /= (Float_t)(fWindowSizeLoGain);
|
---|
460 |
|
---|
461 | // 3. Calculate the RMS from the Variance:
|
---|
462 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
---|
463 |
|
---|
464 | // 4. Calculate the amplitude of the 150MHz "AB" noise
|
---|
465 | const Float_t abOffs = (fSumAB0[idx] - fSumAB1[idx]) / nsamplestot;
|
---|
466 |
|
---|
467 | (*fPedestals)[idx].Set(ped, rms, abOffs, n);
|
---|
468 |
|
---|
469 | fTotalCounter[idx]++;
|
---|
470 | }
|
---|
471 |
|
---|
472 | // --------------------------------------------------------------------------
|
---|
473 | //
|
---|
474 | // Fill the MPedestalCam container with the signal mean and rms for the event.
|
---|
475 | // Store the measured signal in arrays fSumx and fSumx2 so that we can
|
---|
476 | // calculate the overall mean and rms in the PostProcess()
|
---|
477 | //
|
---|
478 | Int_t MPedCalcFromLoGain::Process()
|
---|
479 | {
|
---|
480 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
481 |
|
---|
482 | while (pixel.Next())
|
---|
483 | {
|
---|
484 | const UInt_t idx = pixel.GetPixelId();
|
---|
485 |
|
---|
486 | Byte_t *ptr = pixel.GetHiGainSamples() + fHiGainFirst;
|
---|
487 | Byte_t *end = ptr + fWindowSizeHiGain;
|
---|
488 |
|
---|
489 | UInt_t sum = 0;
|
---|
490 | UInt_t sqr = 0;
|
---|
491 |
|
---|
492 | UInt_t max = 0;
|
---|
493 | UInt_t min = 255;
|
---|
494 |
|
---|
495 | // Find the maximum and minimum signal per slice in the high gain window
|
---|
496 | do {
|
---|
497 | if (*ptr > max)
|
---|
498 | max = *ptr;
|
---|
499 | if (*ptr < min)
|
---|
500 | min = *ptr;
|
---|
501 | } while (++ptr != end);
|
---|
502 |
|
---|
503 | // If the maximum in the high gain window is smaller than
|
---|
504 | if (max-min>=fMaxHiGainVar || max>=255)
|
---|
505 | continue;
|
---|
506 |
|
---|
507 | ptr = pixel.GetLoGainSamples() + fLoGainFirst;
|
---|
508 | end = ptr + fWindowSizeLoGain;
|
---|
509 |
|
---|
510 | Byte_t *firstSlice = ptr;
|
---|
511 |
|
---|
512 | do {
|
---|
513 | sum += *ptr;
|
---|
514 | sqr += *ptr * *ptr;
|
---|
515 | } while (++ptr != end);
|
---|
516 |
|
---|
517 | const Float_t msum = (Float_t)sum;
|
---|
518 | const Float_t sqrsum = msum*msum;
|
---|
519 |
|
---|
520 | fSumx[idx] += msum;
|
---|
521 | fSumx2[idx] += sqrsum;
|
---|
522 | fNumEventsUsed[idx]++;
|
---|
523 |
|
---|
524 | // Calculate the amplitude of the 150MHz "AB" noise
|
---|
525 |
|
---|
526 | if (pixel.IsABFlagValid())
|
---|
527 | {
|
---|
528 | const Int_t abFlag = (fRunHeader->GetNumSamplesHiGain()
|
---|
529 | + fLoGainFirst + pixel.HasABFlag()) & 0x1;
|
---|
530 | for (Int_t islice=0; islice<fWindowSizeLoGain; islice+=2)
|
---|
531 | {
|
---|
532 | const Int_t sliceAB0 = islice + abFlag;
|
---|
533 | const Int_t sliceAB1 = islice - abFlag + 1;
|
---|
534 | fSumAB0[idx] += firstSlice[sliceAB0];
|
---|
535 | fSumAB1[idx] += firstSlice[sliceAB1];
|
---|
536 | }
|
---|
537 | }
|
---|
538 |
|
---|
539 | if (!fPedestalUpdate || fNumEventsUsed[idx]<fNumEventsDump)
|
---|
540 | continue;
|
---|
541 |
|
---|
542 | Calc(fNumEventsDump, idx);
|
---|
543 |
|
---|
544 | fNumEventsUsed[idx]=0;
|
---|
545 | fSumx[idx]=0;
|
---|
546 | fSumx2[idx]=0;
|
---|
547 | fSumAB0[idx]=0;
|
---|
548 | fSumAB1[idx]=0;
|
---|
549 | }
|
---|
550 |
|
---|
551 | if (fPedestalUpdate)
|
---|
552 | {
|
---|
553 | //fPedestals->ReCalc(*fGeom);
|
---|
554 | fPedestals->SetReadyToSave();
|
---|
555 | }
|
---|
556 |
|
---|
557 | return kTRUE;
|
---|
558 | }
|
---|
559 |
|
---|
560 | // --------------------------------------------------------------------------
|
---|
561 | //
|
---|
562 | // Compute signal mean and rms in the whole run and store it in MPedestalCam
|
---|
563 | //
|
---|
564 | Int_t MPedCalcFromLoGain::PostProcess()
|
---|
565 | {
|
---|
566 | // Compute pedestals and rms from the whole run
|
---|
567 | if (fPedestalUpdate || GetNumExecutions()<1)
|
---|
568 | return kTRUE;
|
---|
569 |
|
---|
570 | *fLog << flush << inf << "Calculating pedestals..." << flush;
|
---|
571 |
|
---|
572 | Double_t sum = 0;
|
---|
573 |
|
---|
574 | const Int_t npix = fGeom->GetNumPixels();
|
---|
575 | for (Int_t idx=0; idx<npix; idx++)
|
---|
576 | {
|
---|
577 | const ULong_t n = fNumEventsUsed[idx];
|
---|
578 | if (n>1)
|
---|
579 | Calc(n, idx);
|
---|
580 | sum += n;
|
---|
581 | }
|
---|
582 |
|
---|
583 | *fLog << flush << inf << "Calculating means..." << flush;
|
---|
584 |
|
---|
585 | fPedestals->SetTotalEntries((UInt_t)(sum/npix*(fWindowSizeLoGain+fWindowSizeHiGain)));
|
---|
586 | fPedestals->ReCalc(*fGeom);
|
---|
587 | fPedestals->SetReadyToSave();
|
---|
588 | return kTRUE;
|
---|
589 | }
|
---|
590 |
|
---|
591 | Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
592 | {
|
---|
593 | if (MExtractor::ReadEnv(env, prefix, print)==kERROR)
|
---|
594 | return kERROR;
|
---|
595 |
|
---|
596 | Bool_t rc=kFALSE;
|
---|
597 |
|
---|
598 | Byte_t hw = fWindowSizeHiGain;
|
---|
599 | Byte_t lw = fWindowSizeLoGain;
|
---|
600 | if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print))
|
---|
601 | {
|
---|
602 | hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw);
|
---|
603 | rc = kTRUE;
|
---|
604 | }
|
---|
605 | if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print))
|
---|
606 | {
|
---|
607 | lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw);
|
---|
608 | rc = kTRUE;
|
---|
609 | }
|
---|
610 |
|
---|
611 | if (rc)
|
---|
612 | SetWindowSize(hw, lw);
|
---|
613 |
|
---|
614 | if (IsEnvDefined(env, prefix, "NumEventsDump", print))
|
---|
615 | {
|
---|
616 | SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", fNumEventsDump));
|
---|
617 | rc = kTRUE;
|
---|
618 | }
|
---|
619 |
|
---|
620 | if (IsEnvDefined(env, prefix, "MaxHiGainVar", print))
|
---|
621 | {
|
---|
622 | SetMaxHiGainVar(GetEnvValue(env, prefix, "MaxHiGainVar", fMaxHiGainVar));
|
---|
623 | rc = kTRUE;
|
---|
624 | }
|
---|
625 |
|
---|
626 | if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
|
---|
627 | {
|
---|
628 | SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
|
---|
629 | rc = kTRUE;
|
---|
630 | }
|
---|
631 |
|
---|
632 | return rc;
|
---|
633 | }
|
---|