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