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): Markus Gaug 09/2003 <mailto:markus@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MCalibrationCalc
|
---|
28 | //
|
---|
29 | // Task to calculate the calibration conversion factors from the FADC
|
---|
30 | // time slices. The integrated time slices have to be delivered by an
|
---|
31 | // MExtractedSignalCam. The pedestals by an MPedestalCam.
|
---|
32 | //
|
---|
33 | // The output container MCalibrationCam holds one entry of type MCalibrationPix
|
---|
34 | // for every pixel. It is filled in the following way:
|
---|
35 | //
|
---|
36 | // ProProcess: Search for MPedestalCam, MExtractedSignalCam
|
---|
37 | // Initialize MCalibrationCam
|
---|
38 | // Initialize pulser light wavelength
|
---|
39 | //
|
---|
40 | // ReInit: MCalibrationCam::InitSize(NumPixels) is called which allocates
|
---|
41 | // memory in a TClonesArray of type MCalibrationPix
|
---|
42 | // Initialize number of used FADC slices
|
---|
43 | // Optionally exclude pixels from calibration
|
---|
44 | //
|
---|
45 | // Process: Every MCalibrationPix holds a histogram class,
|
---|
46 | // MHCalibrationPixel which itself hold histograms of type:
|
---|
47 | // HCharge(npix) (distribution of summed FADC time slice
|
---|
48 | // entries)
|
---|
49 | // HTime(npix) (distribution of position of maximum)
|
---|
50 | // HChargevsN(npix) (distribution of charges vs. event number.
|
---|
51 | //
|
---|
52 | // PostProcess: All histograms HCharge(npix) are fitted to a Gaussian
|
---|
53 | // All histograms HTime(npix) are fitted to a Gaussian
|
---|
54 | // The histogram HBlindPixelCharge (blind pixel) is fitted to
|
---|
55 | // a single PhE fit
|
---|
56 | //
|
---|
57 | // The histograms of the PIN Diode are fitted to Gaussians
|
---|
58 | //
|
---|
59 | // Fits can be excluded via the commands:
|
---|
60 | // MalibrationCam::SkipBlindPixelFits() (skip all blind
|
---|
61 | // pixel fits)
|
---|
62 | // MalibrationCam::SkipPinDiodeFits() (skip all PIN Diode
|
---|
63 | // fits)
|
---|
64 | //
|
---|
65 | // Hi-Gain vs. Lo-Gain Calibration (very memory-intensive)
|
---|
66 | // can be skipped with the command:
|
---|
67 | // MalibrationCam::SkipHiLoGainCalibration()
|
---|
68 | //
|
---|
69 | // Input Containers:
|
---|
70 | // MRawEvtData
|
---|
71 | // MPedestalCam
|
---|
72 | // MExtractedSignalCam
|
---|
73 | //
|
---|
74 | // Output Containers:
|
---|
75 | // MCalibrationCam
|
---|
76 | //
|
---|
77 | //////////////////////////////////////////////////////////////////////////////
|
---|
78 | #include "MCalibrationCalc.h"
|
---|
79 |
|
---|
80 | // FXIME: Usage of fstream is a preliminary workaround!
|
---|
81 | #include <fstream>
|
---|
82 |
|
---|
83 | // FXIME: This has to be removed!!!! (YES, WHEN WE HAVE ACCESS TO THE DATABASE!!!!!)
|
---|
84 | #include "MCalibrationConfig.h"
|
---|
85 |
|
---|
86 | #include <TSystem.h>
|
---|
87 | #include <TH1.h>
|
---|
88 |
|
---|
89 | #include "MLog.h"
|
---|
90 | #include "MLogManip.h"
|
---|
91 |
|
---|
92 | #include "MParList.h"
|
---|
93 |
|
---|
94 | #include "MGeomCam.h"
|
---|
95 | #include "MRawRunHeader.h"
|
---|
96 | #include "MRawEvtPixelIter.h"
|
---|
97 |
|
---|
98 | #include "MPedestalCam.h"
|
---|
99 | #include "MPedestalPix.h"
|
---|
100 |
|
---|
101 | #include "MCalibrationCam.h"
|
---|
102 | #include "MCalibrationPix.h"
|
---|
103 |
|
---|
104 | #include "MExtractedSignalCam.h"
|
---|
105 | #include "MExtractedSignalPix.h"
|
---|
106 |
|
---|
107 | #include "MCalibrationBlindPix.h"
|
---|
108 | #include "MCalibrationPINDiode.h"
|
---|
109 |
|
---|
110 | ClassImp(MCalibrationCalc);
|
---|
111 |
|
---|
112 | using namespace std;
|
---|
113 |
|
---|
114 | const UInt_t MCalibrationCalc::fBlindPixelId = 559;
|
---|
115 | const UInt_t MCalibrationCalc::fPINDiodeId = 9999;
|
---|
116 | const Byte_t MCalibrationCalc::fgSaturationLimit = 254;
|
---|
117 | const Byte_t MCalibrationCalc::fgBlindPixelFirst = 3;
|
---|
118 | const Byte_t MCalibrationCalc::fgBlindPixelLast = 12;
|
---|
119 |
|
---|
120 | // --------------------------------------------------------------------------
|
---|
121 | //
|
---|
122 | // Default constructor.
|
---|
123 | //
|
---|
124 | MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
|
---|
125 | : fPedestals(NULL), fCalibrations(NULL), fSignals(NULL),
|
---|
126 | fRawEvt(NULL), fRunHeader(NULL), fEvtTime(NULL)
|
---|
127 | {
|
---|
128 |
|
---|
129 | fName = name ? name : "MCalibrationCalc";
|
---|
130 | fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
|
---|
131 |
|
---|
132 | AddToBranchList("MRawEvtData.fHiGainPixId");
|
---|
133 | AddToBranchList("MRawEvtData.fLoGainPixId");
|
---|
134 | AddToBranchList("MRawEvtData.fHiGainFadcSamples");
|
---|
135 | AddToBranchList("MRawEvtData.fLoGainFadcSamples");
|
---|
136 |
|
---|
137 | Clear();
|
---|
138 | SetBlindPixelRange();
|
---|
139 | }
|
---|
140 |
|
---|
141 | void MCalibrationCalc::Clear(const Option_t *o)
|
---|
142 | {
|
---|
143 |
|
---|
144 | SETBIT(fFlags, kUseBlindPixelFit);
|
---|
145 | SETBIT(fFlags, kUseQualityChecks);
|
---|
146 | SETBIT(fFlags, kHiLoGainCalibration);
|
---|
147 |
|
---|
148 | CLRBIT(fFlags, kHiGainOverFlow);
|
---|
149 | CLRBIT(fFlags, kLoGainOverFlow);
|
---|
150 | // As long as we don't have the PIN Diode:
|
---|
151 | CLRBIT(fFlags, kUsePinDiodeFit);
|
---|
152 |
|
---|
153 | fBlindPixelFirst = 0;
|
---|
154 | fBlindPixelLast = 0;
|
---|
155 |
|
---|
156 | fNumHiGainSamples = 0;
|
---|
157 | fNumLoGainSamples = 0;
|
---|
158 | fConversionHiLo = 0;
|
---|
159 | fNumExcludedPixels = 0;
|
---|
160 |
|
---|
161 | fColor = kECT1;
|
---|
162 | }
|
---|
163 |
|
---|
164 | void MCalibrationCalc::SetBlindPixelRange(Byte_t first, Byte_t last)
|
---|
165 | {
|
---|
166 |
|
---|
167 | fBlindPixelFirst = first;
|
---|
168 | fBlindPixelLast = last;
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 | MCalibrationBlindPix *MCalibrationCalc::GetBlindPixel() const
|
---|
173 | {
|
---|
174 | return fCalibrations->GetBlindPixel();
|
---|
175 | }
|
---|
176 |
|
---|
177 | MCalibrationPINDiode *MCalibrationCalc::GetPINDiode() const
|
---|
178 | {
|
---|
179 | return fCalibrations->GetPINDiode();
|
---|
180 | }
|
---|
181 |
|
---|
182 | // --------------------------------------------------------------------------
|
---|
183 | //
|
---|
184 | // The PreProcess searches for the following input containers:
|
---|
185 | // - MRawEvtData
|
---|
186 | // - MPedestalCam
|
---|
187 | //
|
---|
188 | // The following output containers are also searched and created if
|
---|
189 | // they were not found:
|
---|
190 | //
|
---|
191 | // - MHCalibrationBlindPixel
|
---|
192 | // - MCalibrationCam
|
---|
193 | //
|
---|
194 | // The following output containers are only searched, but not created
|
---|
195 | //
|
---|
196 | // - MTime
|
---|
197 | //
|
---|
198 | Int_t MCalibrationCalc::PreProcess(MParList *pList)
|
---|
199 | {
|
---|
200 |
|
---|
201 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
202 | if (!fRawEvt)
|
---|
203 | {
|
---|
204 | *fLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
|
---|
205 | return kFALSE;
|
---|
206 | }
|
---|
207 |
|
---|
208 | const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
209 | if (!runheader)
|
---|
210 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
211 | else
|
---|
212 | if (runheader->GetRunType() == kRTMonteCarlo)
|
---|
213 | {
|
---|
214 | return kTRUE;
|
---|
215 | }
|
---|
216 |
|
---|
217 | fCalibrations = (MCalibrationCam*)pList->FindCreateObj("MCalibrationCam");
|
---|
218 | if (!fCalibrations)
|
---|
219 | {
|
---|
220 | *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;
|
---|
221 | return kFALSE;
|
---|
222 | }
|
---|
223 |
|
---|
224 | fEvtTime = (MTime*)pList->FindObject("MTime");
|
---|
225 |
|
---|
226 | switch (fColor)
|
---|
227 | {
|
---|
228 | case kEBlue:
|
---|
229 | fCalibrations->SetColor(MCalibrationCam::kECBlue);
|
---|
230 | break;
|
---|
231 | case kEGreen:
|
---|
232 | fCalibrations->SetColor(MCalibrationCam::kECGreen);
|
---|
233 | break;
|
---|
234 | case kEUV:
|
---|
235 | fCalibrations->SetColor(MCalibrationCam::kECUV);
|
---|
236 | break;
|
---|
237 | case kECT1:
|
---|
238 | fCalibrations->SetColor(MCalibrationCam::kECCT1);
|
---|
239 | break;
|
---|
240 | default:
|
---|
241 | fCalibrations->SetColor(MCalibrationCam::kECCT1);
|
---|
242 | }
|
---|
243 |
|
---|
244 | fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
|
---|
245 | if (!fPedestals)
|
---|
246 | {
|
---|
247 | *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
|
---|
248 | return kFALSE;
|
---|
249 | }
|
---|
250 |
|
---|
251 |
|
---|
252 | fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
|
---|
253 | if (!fSignals)
|
---|
254 | {
|
---|
255 | *fLog << err << dbginf << "Cannot find MExtractedSignalCam ... aborting" << endl;
|
---|
256 | return kFALSE;
|
---|
257 | }
|
---|
258 |
|
---|
259 | return kTRUE;
|
---|
260 | }
|
---|
261 |
|
---|
262 |
|
---|
263 | // --------------------------------------------------------------------------
|
---|
264 | //
|
---|
265 | // The ReInit searches for the following input containers:
|
---|
266 | // - MRawRunHeader
|
---|
267 | //
|
---|
268 | Bool_t MCalibrationCalc::ReInit(MParList *pList )
|
---|
269 | {
|
---|
270 |
|
---|
271 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
272 | if (!fRunHeader)
|
---|
273 | {
|
---|
274 | *fLog << err << dbginf << ": MRawRunHeader not found... aborting." << endl;
|
---|
275 | return kFALSE;
|
---|
276 | }
|
---|
277 |
|
---|
278 |
|
---|
279 | MGeomCam *cam = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
280 | if (!cam)
|
---|
281 | {
|
---|
282 | *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
|
---|
283 | return kFALSE;
|
---|
284 | }
|
---|
285 |
|
---|
286 |
|
---|
287 | fCalibrations->SetGeomCam(cam);
|
---|
288 |
|
---|
289 | fNumHiGainSamples = fSignals->GetNumUsedHiGainFADCSlices();
|
---|
290 | fNumLoGainSamples = fSignals->GetNumUsedLoGainFADCSlices();
|
---|
291 | fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
|
---|
292 |
|
---|
293 | UInt_t npixels = cam->GetNumPixels();
|
---|
294 |
|
---|
295 | for (UInt_t i=0; i<npixels; i++)
|
---|
296 | {
|
---|
297 |
|
---|
298 | MCalibrationPix &pix = (*fCalibrations)[i];
|
---|
299 | pix.DefinePixId(i);
|
---|
300 |
|
---|
301 | pix.SetAbsTimeBordersHiGain(fSignals->GetFirstUsedSliceHiGain(),
|
---|
302 | fSignals->GetLastUsedSliceHiGain());
|
---|
303 | pix.SetAbsTimeBordersLoGain(fSignals->GetFirstUsedSliceLoGain(),
|
---|
304 | fSignals->GetLastUsedSliceLoGain());
|
---|
305 |
|
---|
306 | if (!TESTBIT(fFlags,kUseQualityChecks))
|
---|
307 | pix.SetExcludeQualityCheck();
|
---|
308 |
|
---|
309 | // Exclude the blind pixel and the PIN Diode from normal pixel calibration:
|
---|
310 | if (i == fBlindPixelId)
|
---|
311 | pix.SetExcluded();
|
---|
312 |
|
---|
313 | if (i == fPINDiodeId)
|
---|
314 | pix.SetExcluded();
|
---|
315 |
|
---|
316 | }
|
---|
317 |
|
---|
318 | //
|
---|
319 | // Look for file to exclude pixels from analysis
|
---|
320 | //
|
---|
321 | if (!fExcludedPixelsFile.IsNull())
|
---|
322 | {
|
---|
323 |
|
---|
324 | fExcludedPixelsFile = gSystem->ExpandPathName(fExcludedPixelsFile.Data());
|
---|
325 |
|
---|
326 | //
|
---|
327 | // Initialize reading the file
|
---|
328 | //
|
---|
329 | ifstream in(fExcludedPixelsFile.Data(),ios::in);
|
---|
330 |
|
---|
331 | if (in)
|
---|
332 | {
|
---|
333 | *fLog << inf << "Use excluded pixels from file: '" << fExcludedPixelsFile.Data() << "'" << endl;
|
---|
334 | //
|
---|
335 | // Read the file and count the number of entries
|
---|
336 | //
|
---|
337 | UInt_t pixel = 0;
|
---|
338 |
|
---|
339 | while (++fNumExcludedPixels)
|
---|
340 | {
|
---|
341 |
|
---|
342 | in >> pixel;
|
---|
343 |
|
---|
344 | if (!in.good())
|
---|
345 | break;
|
---|
346 | //
|
---|
347 | // Check for out of range
|
---|
348 | //
|
---|
349 | if (pixel > npixels)
|
---|
350 | {
|
---|
351 | *fLog << warn << "WARNING: To be excluded pixel: " << pixel
|
---|
352 | << " is out of range " << endl;
|
---|
353 | continue;
|
---|
354 | }
|
---|
355 | //
|
---|
356 | // Exclude pixel
|
---|
357 | //
|
---|
358 | MCalibrationPix &pix = (*fCalibrations)[pixel];
|
---|
359 | pix.SetExcluded();
|
---|
360 |
|
---|
361 | *fLog << GetDescriptor() << inf << ": Exclude Pixel: " << pixel << endl;
|
---|
362 |
|
---|
363 | }
|
---|
364 |
|
---|
365 | if (--fNumExcludedPixels == 0)
|
---|
366 | *fLog << warn << "WARNING: File '" << fExcludedPixelsFile.Data()
|
---|
367 | << "'" << " is empty " << endl;
|
---|
368 | else
|
---|
369 | fCalibrations->SetNumPixelsExcluded(fNumExcludedPixels);
|
---|
370 |
|
---|
371 | }
|
---|
372 | else
|
---|
373 | *fLog << warn << dbginf << "Cannot open file '" << fExcludedPixelsFile.Data() << "'" << endl;
|
---|
374 | }
|
---|
375 |
|
---|
376 | return kTRUE;
|
---|
377 | }
|
---|
378 |
|
---|
379 |
|
---|
380 | // --------------------------------------------------------------------------
|
---|
381 | //
|
---|
382 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
383 | // pixel in the MCerPhotEvt container.
|
---|
384 | //
|
---|
385 | Int_t MCalibrationCalc::Process()
|
---|
386 | {
|
---|
387 |
|
---|
388 | //
|
---|
389 | // Initialize pointers to blind pixel, PIN Diode and individual pixels
|
---|
390 | //
|
---|
391 | MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
|
---|
392 | MCalibrationPINDiode &pindiode = *(fCalibrations->GetPINDiode());
|
---|
393 |
|
---|
394 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
395 |
|
---|
396 | //
|
---|
397 | // Create a (second) loop to do fill the calibration histograms
|
---|
398 | // Search for: a signal in MExtractedSignalCam
|
---|
399 | // Fill histograms with:
|
---|
400 | // charge
|
---|
401 | // charge vs. event nr.
|
---|
402 | // relative arrival time w.r.t. pixel 1
|
---|
403 | //
|
---|
404 | while (pixel.Next())
|
---|
405 | {
|
---|
406 |
|
---|
407 | const UInt_t pixid = pixel.GetPixelId();
|
---|
408 |
|
---|
409 | MCalibrationPix &pix = (*fCalibrations)[pixid];
|
---|
410 |
|
---|
411 | MExtractedSignalPix &sig = (*fSignals)[pixid];
|
---|
412 |
|
---|
413 | const Float_t sumhi = sig.GetExtractedSignalHiGain();
|
---|
414 | const Float_t sumlo = sig.GetExtractedSignalLoGain();
|
---|
415 |
|
---|
416 | Float_t abstime = 0.;
|
---|
417 | #if 0
|
---|
418 | Float_t reltime = 0.;
|
---|
419 |
|
---|
420 | if (TESTBIT(fFlags,kUseTimes))
|
---|
421 | {
|
---|
422 |
|
---|
423 | //
|
---|
424 | // Have a look in MArrivalTime,
|
---|
425 | // otherwise search the position of maximum bin
|
---|
426 | // in MRawEvtData
|
---|
427 | //
|
---|
428 | if (fArrivalTime)
|
---|
429 | {
|
---|
430 | abstime = (*fArrivalTime)[pixid];
|
---|
431 | reltime = abstime - (*fArrivalTime)[1];
|
---|
432 | }
|
---|
433 |
|
---|
434 | else
|
---|
435 | {
|
---|
436 | if (pixid == 1)
|
---|
437 | referencetime = (Float_t)pixel.GetIdxMaxHiGainSample();
|
---|
438 | if (sig.IsLoGainUsed())
|
---|
439 | {
|
---|
440 | abstime = (Float_t)pixel.GetIdxMaxLoGainSample();
|
---|
441 | // reltime = abstime - referencetime;
|
---|
442 | }
|
---|
443 | else
|
---|
444 | {
|
---|
445 | abstime = (Float_t)pixel.GetIdxMaxHiGainSample();
|
---|
446 | // reltime = abstime - referencetime;
|
---|
447 | }
|
---|
448 | // }
|
---|
449 | // } /* if Use Times */
|
---|
450 |
|
---|
451 | #endif
|
---|
452 | switch(pixid)
|
---|
453 | {
|
---|
454 |
|
---|
455 | case fBlindPixelId:
|
---|
456 |
|
---|
457 | if (TESTBIT(fFlags,kUseBlindPixelFit))
|
---|
458 | {
|
---|
459 |
|
---|
460 | Byte_t *ptr = pixel.GetHiGainSamples();
|
---|
461 |
|
---|
462 | Float_t blindpixelsumhi = 0.;
|
---|
463 | Float_t blindpixelsumlo = 0.;
|
---|
464 | //
|
---|
465 | // We need a dedicated signal extractor for the blind pixel
|
---|
466 | //
|
---|
467 | Int_t diff = 0;
|
---|
468 |
|
---|
469 | if (fBlindPixelLast > 15)
|
---|
470 | {
|
---|
471 | diff = fBlindPixelLast - 15;
|
---|
472 | fBlindPixelLast = 15;
|
---|
473 | }
|
---|
474 |
|
---|
475 | Byte_t *start = ptr + fBlindPixelFirst - 1;
|
---|
476 | Byte_t *end = start + fBlindPixelLast - fBlindPixelFirst + 1;
|
---|
477 |
|
---|
478 | ptr = start;
|
---|
479 |
|
---|
480 | Int_t sum = 0;
|
---|
481 |
|
---|
482 | while (ptr<end)
|
---|
483 | {
|
---|
484 | sum += *ptr;
|
---|
485 | ptr++;
|
---|
486 | }
|
---|
487 |
|
---|
488 | if (diff > 0)
|
---|
489 | {
|
---|
490 | ptr = pixel.GetLoGainSamples();
|
---|
491 |
|
---|
492 | end = ptr + diff + 1;
|
---|
493 |
|
---|
494 | while (ptr<end)
|
---|
495 | {
|
---|
496 | sum += *ptr;
|
---|
497 | ptr++;
|
---|
498 | }
|
---|
499 | }
|
---|
500 |
|
---|
501 | blindpixelsumhi = (Float_t)sum;
|
---|
502 |
|
---|
503 | ptr = pixel.GetLoGainSamples();
|
---|
504 |
|
---|
505 | start = ptr + fBlindPixelFirst - 1;
|
---|
506 | end = ptr + fBlindPixelLast;
|
---|
507 |
|
---|
508 | ptr = start;
|
---|
509 |
|
---|
510 | sum = 0;
|
---|
511 |
|
---|
512 | while (++ptr<end)
|
---|
513 | sum += *ptr;
|
---|
514 |
|
---|
515 | blindpixelsumlo = (Float_t)sum;
|
---|
516 |
|
---|
517 | // if (!CalcSignalBlindPixel(hiptr, blindpixelsumhi))
|
---|
518 | // return kFALSE;
|
---|
519 |
|
---|
520 | if (!blindpixel.FillCharge(blindpixelsumhi))
|
---|
521 | *fLog << warn <<
|
---|
522 | "Overflow or Underflow occurred filling Blind Pixel sum = " << blindpixelsumhi << endl;
|
---|
523 |
|
---|
524 | // Byte_t *loptr = pixel.GetLoGainSamples();
|
---|
525 | // CalcSignalBlindPixel(loptr, blindpixelsumlo);
|
---|
526 |
|
---|
527 | blindpixel.FillGraphs(blindpixelsumhi,blindpixelsumlo);
|
---|
528 |
|
---|
529 | #if 0
|
---|
530 | TH1I *hist = blindpixel.GetSinglePheFADCSlices();
|
---|
531 |
|
---|
532 | if (blindpixelsumhi > 300.)
|
---|
533 | {
|
---|
534 | ptr = pixel.GetHiGainSamples();
|
---|
535 | for (Int_t i=0;i<15;i++)
|
---|
536 | hist->Fill(i,*ptr++);
|
---|
537 | ptr = pixel.GetLoGainSamples();
|
---|
538 | for (Int_t i=15;i<30;i++)
|
---|
539 | hist->Fill(i,*ptr++);
|
---|
540 | }
|
---|
541 | #endif
|
---|
542 | } /* if use blind pixel */
|
---|
543 |
|
---|
544 | // break;
|
---|
545 | case fPINDiodeId:
|
---|
546 |
|
---|
547 | if (TESTBIT(fFlags,kUsePinDiodeFit))
|
---|
548 | {
|
---|
549 |
|
---|
550 | if (!pindiode.FillCharge(sumhi))
|
---|
551 | *fLog << warn
|
---|
552 | << "Overflow or Underflow occurred filling PINDiode: sum = "
|
---|
553 | << sumhi << endl;
|
---|
554 |
|
---|
555 | if (!pindiode.FillAbsTime(abstime))
|
---|
556 | *fLog << warn
|
---|
557 | << "Overflow or Underflow occurred filling PINDiode abs. time = "
|
---|
558 | << abstime << endl;
|
---|
559 |
|
---|
560 | if (!pindiode.FillGraphs(sumhi,sumlo))
|
---|
561 | *fLog << warn
|
---|
562 | << "Overflow or Underflow occurred filling PINDiode: eventnr = " << endl;
|
---|
563 |
|
---|
564 | } /* if use PIN Diode */
|
---|
565 |
|
---|
566 | // break;
|
---|
567 |
|
---|
568 | default:
|
---|
569 |
|
---|
570 | if (pix.IsExcluded())
|
---|
571 | continue;
|
---|
572 |
|
---|
573 | pix.FillGraphs(sumhi,sumlo);
|
---|
574 |
|
---|
575 | if (sig.IsLoGainUsed())
|
---|
576 | {
|
---|
577 |
|
---|
578 | if (!pix.FillChargeLoGain(sumlo))
|
---|
579 | *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid
|
---|
580 | << " signal = " << sumlo << endl;
|
---|
581 |
|
---|
582 | if (!pix.FillAbsTimeLoGain(abstime))
|
---|
583 | *fLog << warn << "Could not fill Lo Gain Abs. Time of pixel: "
|
---|
584 | << pixid << " time = " << abstime << endl;
|
---|
585 | /*
|
---|
586 | if (!pix.FillRelTimeLoGain(reltime))
|
---|
587 | *fLog << warn << "Could not fill Lo Gain Rel. Time of pixel: "
|
---|
588 | << pixid << " time = " << reltime << endl;
|
---|
589 | */
|
---|
590 | } /* if (sig.IsLoGainUsed()) */
|
---|
591 | else
|
---|
592 | {
|
---|
593 | if (!pix.FillChargeHiGain(sumhi))
|
---|
594 | *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid
|
---|
595 | << " signal = " << sumhi << endl;
|
---|
596 |
|
---|
597 | if (!pix.FillAbsTimeHiGain(abstime))
|
---|
598 | *fLog << warn << "Could not fill Hi Gain Abs. Time of pixel: "
|
---|
599 | << pixid << " time = " << abstime << endl;
|
---|
600 | /*
|
---|
601 | if (!pix.FillRelTimeHiGain(reltime))
|
---|
602 | *fLog << warn << "Could not fill Hi Gain Rel. Time of pixel: "
|
---|
603 | << pixid << " time = " << reltime << endl;
|
---|
604 | */
|
---|
605 | } /* else (sig.IsLoGainUsed()) */
|
---|
606 | break;
|
---|
607 |
|
---|
608 | } /* switch(pixid) */
|
---|
609 |
|
---|
610 | } /* while (pixel.Next()) */
|
---|
611 |
|
---|
612 | return kTRUE;
|
---|
613 | }
|
---|
614 |
|
---|
615 | Int_t MCalibrationCalc::PostProcess()
|
---|
616 | {
|
---|
617 |
|
---|
618 | *fLog << inf << endl;
|
---|
619 |
|
---|
620 | *fLog << inf << GetDescriptor() << ": Cut Histogram Edges" << endl;
|
---|
621 |
|
---|
622 | //
|
---|
623 | // Cut edges to make fits and viewing of the hists easier
|
---|
624 | //
|
---|
625 | fCalibrations->CutEdges();
|
---|
626 |
|
---|
627 | //
|
---|
628 | // Fit the blind pixel
|
---|
629 | //
|
---|
630 | if (TESTBIT(fFlags,kUseBlindPixelFit))
|
---|
631 | {
|
---|
632 | //
|
---|
633 | // Get pointer to blind pixel
|
---|
634 | //
|
---|
635 | MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
|
---|
636 |
|
---|
637 | *fLog << inf << GetDescriptor() << ": Fitting the Blind Pixel" << endl;
|
---|
638 |
|
---|
639 | //
|
---|
640 | // retrieve mean and sigma of the blind pixel pedestal,
|
---|
641 | // so that we can use it for the fit
|
---|
642 | //
|
---|
643 | if (fPedestals->GetHistSize() > fBlindPixelId)
|
---|
644 | {
|
---|
645 |
|
---|
646 | Float_t pedestal;
|
---|
647 | Float_t pederr;
|
---|
648 | Float_t pedsigma;
|
---|
649 | Float_t pedsigmaerr;
|
---|
650 |
|
---|
651 | const ULong_t nentries = fPedestals->GetTotalEntries();
|
---|
652 | const Float_t nslices = (Float_t)(fgBlindPixelLast-fgBlindPixelFirst+1);
|
---|
653 | const Float_t sqrslice = TMath::Sqrt(nslices);
|
---|
654 | //
|
---|
655 | // retrieve the pedestal pix of the blind pixel
|
---|
656 | //
|
---|
657 | if (fPedestals->GetHistSize() != 0)
|
---|
658 | {
|
---|
659 | MHPedestalPixel &pedhist = (*fPedestals)(fBlindPixelId);
|
---|
660 | pedestal = pedhist.GetChargeMean()*nslices;
|
---|
661 | pederr = pedhist.GetChargeMeanErr()*nslices;
|
---|
662 | //
|
---|
663 | // Fitted sigma: 1. one sqrt(Nr. slices) for the division which is not
|
---|
664 | // not appropriate: sigma(real)/slice = GetSigma*sqrt(nslices)
|
---|
665 | // 2. another sqrt(Nr. slices) to calculate back to number
|
---|
666 | // of slices
|
---|
667 | //
|
---|
668 | pedsigma = pedhist.GetChargeSigma()*nslices;
|
---|
669 | pedsigmaerr = pedhist.GetChargeSigmaErr()*nslices;
|
---|
670 | }
|
---|
671 | else
|
---|
672 | {
|
---|
673 | MPedestalPix &pedpix = (*fPedestals)[fBlindPixelId];
|
---|
674 | pedestal = pedpix.GetPedestal()*nslices;
|
---|
675 | pederr = pedpix.GetPedestalRms()*nslices/nentries;
|
---|
676 | pedsigma = pedpix.GetPedestalRms()*sqrslice;
|
---|
677 | pedsigmaerr = pederr/2.;
|
---|
678 | }
|
---|
679 | //
|
---|
680 | // retrieve the histogram containers
|
---|
681 | //
|
---|
682 | MHCalibrationBlindPixel *hist = blindpixel.GetHist();
|
---|
683 |
|
---|
684 | hist->SetMeanPedestal(pedestal);
|
---|
685 | hist->SetMeanPedestalErr(pederr);
|
---|
686 | hist->SetSigmaPedestal(pedsigma);
|
---|
687 | hist->SetSigmaPedestalErr(pedsigmaerr);
|
---|
688 | }
|
---|
689 |
|
---|
690 | if (!blindpixel.FitCharge())
|
---|
691 | {
|
---|
692 | *fLog << warn << "Could not fit the blind pixel! " << endl;
|
---|
693 | *fLog << warn << "Setting bit kBlindPixelMethodValid to FALSE in MCalibrationCam" << endl;
|
---|
694 | fCalibrations->SetBlindPixelMethodValid(kFALSE);
|
---|
695 | }
|
---|
696 | else
|
---|
697 | fCalibrations->SetBlindPixelMethodValid(kTRUE);
|
---|
698 |
|
---|
699 | if (blindpixel.CheckOscillations())
|
---|
700 | fCalibrations->SetBlindPixelMethodValid(kFALSE);
|
---|
701 |
|
---|
702 | blindpixel.DrawClone();
|
---|
703 | }
|
---|
704 | else
|
---|
705 | *fLog << inf << GetDescriptor() << ": Skipping Blind Pixel Fit " << endl;
|
---|
706 |
|
---|
707 |
|
---|
708 | *fLog << inf << GetDescriptor() << ": Fitting the Normal Pixels" << endl;
|
---|
709 |
|
---|
710 | //
|
---|
711 | // loop over the pedestal events and check if we have calibration
|
---|
712 | //
|
---|
713 | for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
|
---|
714 | {
|
---|
715 |
|
---|
716 | MCalibrationPix &pix = (*fCalibrations)[pixid];
|
---|
717 |
|
---|
718 | //
|
---|
719 | // Check if the pixel has been excluded from the fits
|
---|
720 | //
|
---|
721 | if (pix.IsExcluded())
|
---|
722 | continue;
|
---|
723 |
|
---|
724 | //
|
---|
725 | // get the pedestals
|
---|
726 | //
|
---|
727 | const Float_t ped = (*fPedestals)[pixid].GetPedestal();
|
---|
728 | const Float_t prms = (*fPedestals)[pixid].GetPedestalRms();
|
---|
729 |
|
---|
730 | //
|
---|
731 | // set them in the calibration camera
|
---|
732 | //
|
---|
733 | pix.SetPedestal(ped,prms,(Float_t)fNumHiGainSamples,(Float_t)fNumLoGainSamples);
|
---|
734 |
|
---|
735 | //
|
---|
736 | // perform the Gauss fits to the charges
|
---|
737 | //
|
---|
738 | pix.FitCharge();
|
---|
739 |
|
---|
740 | //
|
---|
741 | // check also for oscillations
|
---|
742 | //
|
---|
743 | pix.CheckOscillations();
|
---|
744 |
|
---|
745 | }
|
---|
746 |
|
---|
747 | if (TESTBIT(fFlags,kUseBlindPixelFit) && fCalibrations->IsBlindPixelMethodValid())
|
---|
748 | {
|
---|
749 | if (!fCalibrations->CalcFluxInsidePlexiglass())
|
---|
750 | {
|
---|
751 | *fLog << err
|
---|
752 | << "Could not calculate the number of photons from the blind pixel " << endl;
|
---|
753 | *fLog << err
|
---|
754 | << "You can try to calibrate using the MCalibrationCalc::SkipBlindPixelFit()" << endl;
|
---|
755 | fCalibrations->SetBlindPixelMethodValid(kFALSE);
|
---|
756 | }
|
---|
757 | }
|
---|
758 | else
|
---|
759 | *fLog << inf << GetDescriptor() << ": Skipping Blind Pixel Calibration! " << endl;
|
---|
760 |
|
---|
761 |
|
---|
762 | if (TESTBIT(fFlags,kUsePinDiodeFit) && fCalibrations->IsPINDiodeMethodValid())
|
---|
763 | {
|
---|
764 | if (!fCalibrations->CalcFluxOutsidePlexiglass())
|
---|
765 | {
|
---|
766 | *fLog << err
|
---|
767 | << "Could not calculate the number of photons from the blind pixel " << endl;
|
---|
768 | *fLog << err
|
---|
769 | << "You can try to calibrate using the MCalibrationCalc::SkipPINDiodeFit()" << endl;
|
---|
770 | fCalibrations->SetPINDiodeMethodValid(kFALSE);
|
---|
771 | }
|
---|
772 | }
|
---|
773 | else
|
---|
774 | *fLog << inf << GetDescriptor() << ": Skipping PIN Diode Calibration! " << endl;
|
---|
775 |
|
---|
776 | fCalibrations->SetReadyToSave();
|
---|
777 |
|
---|
778 | return kTRUE;
|
---|
779 | }
|
---|
780 |
|
---|
781 |
|
---|
782 | Bool_t MCalibrationCalc::CalcSignalBlindPixel(Byte_t *ptr, Float_t &signal) const
|
---|
783 | {
|
---|
784 |
|
---|
785 | Byte_t *newptr = ptr;
|
---|
786 | Byte_t *start = ptr + fBlindPixelFirst-1;
|
---|
787 | Byte_t *end = ptr + fBlindPixelLast;
|
---|
788 | Byte_t nsamples = fBlindPixelLast-fgBlindPixelFirst+1;
|
---|
789 |
|
---|
790 | Byte_t sum = 0;
|
---|
791 | Int_t sat = 0;
|
---|
792 |
|
---|
793 | newptr = start;
|
---|
794 |
|
---|
795 | while (ptr<end)
|
---|
796 | {
|
---|
797 | sum += *ptr;
|
---|
798 | if (*ptr++ >= fgSaturationLimit)
|
---|
799 | sat++;
|
---|
800 | }
|
---|
801 |
|
---|
802 | if (sat)
|
---|
803 | {
|
---|
804 | *fLog << err << "HI Gain Saturation occurred in the blind pixel! "
|
---|
805 | << " Do not know yet how to treat this ... aborting " << endl;
|
---|
806 | *fLog << err << "If you need absolutely any other kind of calibration, "
|
---|
807 | << " use SkipBlindPixelFit() " << endl;
|
---|
808 | return kFALSE;
|
---|
809 | }
|
---|
810 |
|
---|
811 | signal = (Float_t)sum;
|
---|
812 |
|
---|
813 | return kTRUE;
|
---|
814 | }
|
---|