1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: MPedCalcFromLoGain.cc,v 1.38 2007-05-11 10:25:45 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 |
|
---|
149 | ClassImp(MPedCalcFromLoGain);
|
---|
150 |
|
---|
151 | using namespace std;
|
---|
152 |
|
---|
153 | const UShort_t MPedCalcFromLoGain::fgExtractWinFirst = 17;
|
---|
154 | const UShort_t MPedCalcFromLoGain::fgExtractWinSize = 6;
|
---|
155 | const UInt_t MPedCalcFromLoGain::fgNumDump = 500;
|
---|
156 |
|
---|
157 | // --------------------------------------------------------------------------
|
---|
158 | //
|
---|
159 | // Default constructor:
|
---|
160 | //
|
---|
161 | // Calls:
|
---|
162 | // - SetExtractWindow(fgExtractWinFirst, fgExtractWinSize)
|
---|
163 | //
|
---|
164 | MPedCalcFromLoGain::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 | //
|
---|
183 | Bool_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 | //
|
---|
201 | Int_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 | if (fPedestalUpdate)
|
---|
241 | fPedestalsOut->SetReadyToSave();
|
---|
242 |
|
---|
243 | return kTRUE;
|
---|
244 | }
|
---|
245 |
|
---|
246 | // --------------------------------------------------------------------------
|
---|
247 | //
|
---|
248 | // Compute signal mean and rms in the whole run and store it in MPedestalCam
|
---|
249 | //
|
---|
250 | Int_t MPedCalcFromLoGain::PostProcess()
|
---|
251 | {
|
---|
252 | // Compute pedestals and rms from the whole run
|
---|
253 | if (fPedestalUpdate)
|
---|
254 | return kTRUE;
|
---|
255 |
|
---|
256 | *fLog << flush << inf << "Calculating Pedestals..." << flush;
|
---|
257 |
|
---|
258 | CalcPixResult();
|
---|
259 | CalcAreaResult();
|
---|
260 | CalcSectorResult();
|
---|
261 |
|
---|
262 | fPedestalsOut->SetReadyToSave();
|
---|
263 |
|
---|
264 | return MExtractPedestal::PostProcess();
|
---|
265 | }
|
---|
266 |
|
---|
267 | // --------------------------------------------------------------------------
|
---|
268 | //
|
---|
269 | // The following resources are available:
|
---|
270 | //
|
---|
271 | Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
272 | {
|
---|
273 | Int_t rc=MExtractPedestal::ReadEnv(env, prefix, print);
|
---|
274 | if (rc==kERROR)
|
---|
275 | return kERROR;
|
---|
276 |
|
---|
277 | // find resource for pedestal update
|
---|
278 | if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
|
---|
279 | {
|
---|
280 | SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
|
---|
281 | rc = kTRUE;
|
---|
282 | }
|
---|
283 |
|
---|
284 | // find resource for numdump
|
---|
285 | if (IsEnvDefined(env, prefix, "NumDump", print))
|
---|
286 | {
|
---|
287 | const Int_t num = GetEnvValue(env, prefix, "NumDump", -1);
|
---|
288 | if (num<=0)
|
---|
289 | {
|
---|
290 | *fLog << err << GetDescriptor() << ": ERROR - NumDump invalid!" << endl;
|
---|
291 | return kERROR;
|
---|
292 | }
|
---|
293 |
|
---|
294 | SetNumDump(num);
|
---|
295 | rc = kTRUE;
|
---|
296 | }
|
---|
297 |
|
---|
298 | // find resource for numeventsdump
|
---|
299 | if (IsEnvDefined(env, prefix, "NumEventsDump", print))
|
---|
300 | {
|
---|
301 | SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
|
---|
302 | rc = kTRUE;
|
---|
303 | }
|
---|
304 |
|
---|
305 | // find resource for numeventsdump
|
---|
306 | if (IsEnvDefined(env, prefix, "NumAreasDump", print))
|
---|
307 | {
|
---|
308 | SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
|
---|
309 | rc = kTRUE;
|
---|
310 | }
|
---|
311 |
|
---|
312 | // find resource for numeventsdump
|
---|
313 | if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
|
---|
314 | {
|
---|
315 | SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
|
---|
316 | rc = kTRUE;
|
---|
317 | }
|
---|
318 |
|
---|
319 | return rc;
|
---|
320 | }
|
---|
321 |
|
---|
322 | void MPedCalcFromLoGain::Print(Option_t *o) const
|
---|
323 | {
|
---|
324 | MExtractPedestal::Print(o);
|
---|
325 |
|
---|
326 | *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;
|
---|
327 | if (fPedestalUpdate)
|
---|
328 | {
|
---|
329 | *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl;
|
---|
330 | *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl;
|
---|
331 | *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
|
---|
332 | }
|
---|
333 | }
|
---|