source: trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc@ 7115

Last change on this file since 7115 was 7099, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 28.3 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Javier Lopez 12/2003 <mailto:jlopez@ifae.es>
19! Author(s): Javier Rico 01/2004 <mailto:jrico@ifae.es>
20! Author(s): Wolfgang Wittek 02/2004 <mailto:wittek@mppmu.mpg.de>
21! Author(s): Markus Gaug 04/2004 <mailto:markus@ifae.es>
22! Author(s): Hendrik Bartko 08/2004 <mailto:hbartko@mppmu.mpg.de>
23! Author(s): Thomas Bretz 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
24!
25! Copyright: MAGIC Software Development, 2000-2004
26!
27!
28\* ======================================================================== */
29
30///////////////////////////////////////////////////////////////////////////////////
31//
32// MCalibrateData
33//
34// This task takes the integrated charge from MExtractedSignal and applies
35// the calibration constants from MCalibrationCam to convert the summed FADC
36// slices into photons. The number of photons obtained is stored in MSignalCam.
37// Optionally, the calibration of pedestals from an MPedestalCam container into
38// an MPedPhotCam container can be chosen with the member functions
39// SetPedestalType(). Default is 'kRun', i.e. calibration of pedestals from a
40// dedicated pedestal run.
41// In case, the chosen pedestal type is kRun or kEvent, in ReInit() the MPedPhotCam
42// container is filled using the information from MPedestalCam, MExtractedSignalCam,
43// MCalibrationChargeCam and MCalibrationQECam
44//
45// Selection of different calibration methods is allowed through the
46// SetCalibrationMode() member function (default: kFfactor)
47//
48// The calibration modes which exclude non-valid pixels are the following:
49//
50// kFfactor: calibrates using the F-Factor method
51// kBlindpixel: calibrates using the BlindPixel method
52// kBlindpixel: calibrates using the BlindPixel method
53// kFlatCharge: perform a charge flat-flatfielding. Outer pixels are area-corrected.
54// kDummy: calibrates with fixed conversion factors of 1 and errors of 0.
55//
56// The calibration modes which include all pixels regardless of their validity is:
57//
58// kNone: calibrates with fixed conversion factors of 1 and errors of 0.
59//
60// Use the kDummy and kNone methods ONLY FOR DEBUGGING!
61//
62//
63// This class can calibrate data and/or pedestals. To switch off calibration of data
64// set the Calibration Mode to kSkip. To switch on pedestal calibration call either
65// SetPedestalFlag(MCalibrateData::kRun) (calibration is done once in ReInit)
66// SetPedestalFlag(MCalibrateData::kEvent) (calibration is done for each event)
67//
68// By calling AddPedestal() you can control the name of the
69// MPedestalCam and/or MPedPhotCam container which is used.
70//
71// Assume you want to calibrate "MPedestalCam" once and "MPedestalFromLoGain" [MPedestalCam]
72// event-by-event, so:
73// MCalibrateData cal1;
74// cal1.SetCalibrationMode(MCalibrateData::kSkip);
75// cal1.SetPedestalFlag(MCalibrateData::kRun);
76// MCalibrateData cal2;
77// cal2.SetCalibrationMode(MCalibrateData::kSkip);
78// cal2.AddPedestal("FromLoGain");
79// cal2.SetPedestalFlag(MCalibrateData::kEvent);
80//
81//
82// Input Containers:
83// [MPedestalCam]
84// [MExtractedSignalCam]
85// [MCalibrationChargeCam]
86// [MCalibrationQECam]
87// MBadPixelsCam
88//
89// Output Containers:
90// [MPedPhotCam]
91// [MSignalCam]
92//
93// See also: MJCalibration, MJPedestal, MJExtractSignal, MJExtractCalibTest
94//
95//////////////////////////////////////////////////////////////////////////////
96#include "MCalibrateData.h"
97
98#include <fstream>
99
100#include <TEnv.h>
101
102#include "MLog.h"
103#include "MLogManip.h"
104
105#include "MParList.h"
106#include "MH.h"
107
108#include "MGeomCam.h"
109
110#include "MPedestalCam.h"
111#include "MPedestalPix.h"
112
113#include "MCalibrationChargeCam.h"
114#include "MCalibrationChargePix.h"
115
116#include "MCalibrationQECam.h"
117#include "MCalibrationQEPix.h"
118
119#include "MCalibConstCam.h"
120#include "MCalibConstPix.h"
121
122#include "MExtractedSignalCam.h"
123#include "MExtractedSignalPix.h"
124
125#include "MPedPhotCam.h"
126#include "MPedPhotPix.h"
127
128#include "MBadPixelsCam.h"
129#include "MBadPixelsPix.h"
130
131#include "MSignalCam.h"
132
133ClassImp(MCalibrateData);
134
135using namespace std;
136
137const Float_t MCalibrateData::gkCalibConvMinLimit = 0.01;
138const Float_t MCalibrateData::gkCalibConvMaxLimit = 5.;
139
140const MCalibrateData::CalibrationMode_t MCalibrateData::gkDefault = kFfactor;
141
142// --------------------------------------------------------------------------
143//
144// Default constructor.
145//
146// Sets all pointers to NULL
147//
148// Initializes:
149// - fCalibrationMode to kDefault
150// - fPedestalFlag to kNo
151//
152MCalibrateData::MCalibrateData(CalibrationMode_t calmode,const char *name, const char *title)
153 : fGeomCam(NULL), fBadPixels(NULL), fCalibrations(NULL),
154 fQEs(NULL), fSignals(NULL), fCerPhotEvt(NULL), fCalibConstCam(NULL),
155 fPedestalFlag(kNo), fSignalType(kPhot), fRenormFactor(1.)
156{
157
158 fName = name ? name : "MCalibrateData";
159 fTitle = title ? title : "Task to calculate the number of photons in one event";
160
161 SetCalibrationMode(calmode);
162
163 SetCalibConvMinLimit();
164 SetCalibConvMaxLimit();
165
166 fNamesPedestal.SetOwner();
167}
168
169void MCalibrateData::AddPedestal(const char *name)
170{
171 TString ped(name);
172 TString pho(name);
173 ped.Prepend("MPedestal");
174 pho.Prepend("MPedPhot");
175
176 fNamesPedestal.Add(new TNamed(ped, pho));
177}
178
179void MCalibrateData::AddPedestal(const char *pedestal, const char *pedphot)
180{
181 fNamesPedestal.Add(new TNamed(pedestal, pedphot));
182}
183
184// --------------------------------------------------------------------------
185//
186// The PreProcess searches for the following input containers:
187//
188// - MGeomCam
189// - MPedestalCam
190// - MCalibrationChargeCam
191// - MCalibrationQECam
192// - MExtractedSignalCam
193// - MBadPixelsCam
194//
195// The following output containers are also searched and created if
196// they were not found:
197//
198// - MPedPhotCam
199// - MSignalCam
200//
201Int_t MCalibrateData::PreProcess(MParList *pList)
202{
203 // input containers
204
205 fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
206 if (!fBadPixels)
207 {
208 *fLog << err << AddSerialNumber("MBadPixelsCam") << " not found ... aborting" << endl;
209 return kFALSE;
210 }
211
212 fSignals = 0;
213 fCerPhotEvt = 0;
214 if (fCalibrationMode>kSkip)
215 {
216 fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
217 if (!fSignals)
218 {
219 *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
220 return kFALSE;
221 }
222
223 fCerPhotEvt = (MSignalCam*)pList->FindCreateObj(AddSerialNumber("MSignalCam"));
224 if (!fCerPhotEvt)
225 return kFALSE;
226
227 fCalibConstCam = (MCalibConstCam*)pList->FindCreateObj(AddSerialNumber("MCalibConstCam"));
228 if (!fCalibConstCam)
229 return kFALSE;
230 }
231
232 fCalibrations = 0;
233 fQEs = 0;
234 if (fCalibrationMode>kNone)
235 {
236 fCalibrations = (MCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
237 if (!fCalibrations)
238 {
239 *fLog << err << AddSerialNumber("MCalibrationChargeCam") << " not found ... aborting." << endl;
240 return kFALSE;
241 }
242
243 fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
244 if (!fQEs)
245 {
246 *fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
247 return kFALSE;
248 }
249
250 }
251
252 if (fNamesPedestal.GetSize()>0 && fPedestalFlag==kNo)
253 {
254 *fLog << warn << "Pedestal list contains entries, but mode is set to kNo... setting to kEvent." << endl;
255 fPedestalFlag = kEvent;
256 }
257
258 if (fPedestalFlag!=kNo)
259 {
260 if (fNamesPedestal.GetSize()==0)
261 {
262 *fLog << inf << "No container names specified... using default: MPedestalCam and MPedPhotCam." << endl;
263 AddPedestal();
264 }
265
266 fPedestalCams.Clear();
267 fPedPhotCams.Clear();
268
269 TIter Next(&fNamesPedestal);
270 TObject *o=0;
271 while ((o=Next()))
272 {
273 TObject *pedcam = pList->FindObject(AddSerialNumber(o->GetName()), "MPedestalCam");
274 if (!pedcam)
275 {
276 *fLog << err << AddSerialNumber(o->GetName()) << " [MPedestalCam] not found ... aborting" << endl;
277 return kFALSE;
278 }
279 TObject *pedphot = pList->FindCreateObj("MPedPhotCam", AddSerialNumber(o->GetTitle()));
280 if (!pedphot)
281 return kFALSE;
282
283 fPedestalCams.Add(pedcam);
284 fPedPhotCams.Add(pedphot);
285 }
286 }
287
288 switch (fSignalType)
289 {
290 case kPhe:
291 fRenormFactor = MCalibrationQEPix::gkDefaultAverageQE;
292 break;
293 case kPhot:
294 fRenormFactor = 1.;
295 break;
296 }
297
298 fCalibConsts.Reset();
299 fCalibFFactors.Reset();
300 fHiLoConv.Reset();
301 fHiLoConvErr.Reset();
302
303 return kTRUE;
304}
305
306// --------------------------------------------------------------------------
307//
308// The ReInit searches for the following input containers:
309//
310// - MGeomCam
311//
312// Check for validity of the selected calibration method, switch to a
313// different one in case of need
314//
315// Fill the MPedPhotCam container using the information from MPedestalCam,
316// MExtractedSignalCam and MCalibrationCam
317//
318Bool_t MCalibrateData::ReInit(MParList *pList)
319{
320 fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
321 if (!fGeomCam)
322 {
323 *fLog << err << "No MGeomCam found... aborting." << endl;
324 return kFALSE;
325 }
326
327 // Sizes might have changed
328 if (fPedestalFlag!=kNo)
329 {
330 TIter Next(&fPedestalCams);
331 MPedestalCam *cam=0;
332 while ((cam=(MPedestalCam*)Next()))
333 if ((Int_t)cam->GetSize() != fSignals->GetSize())
334 {
335 *fLog << err << "Size mismatch of " << cam->GetDescriptor() << " and MCalibrationCam... abort." << endl;
336 return kFALSE;
337 }
338 }
339
340 if(fCalibrationMode == kBlindPixel && !fQEs->IsBlindPixelMethodValid())
341 {
342 *fLog << warn << "Blind pixel calibration method not valid, switching to F-factor method" << endl;
343 fCalibrationMode = kFfactor;
344 }
345
346 if(fCalibrationMode == kPinDiode && !fQEs->IsPINDiodeMethodValid())
347 {
348 *fLog << warn << "PIN diode calibration method not valid, switching to F-factor method" << endl;
349 fCalibrationMode = kFfactor;
350 }
351
352 if(fCalibrationMode == kCombined && !fQEs->IsCombinedMethodValid())
353 {
354 *fLog << warn << "Combined calibration method not valid, switching to F-factor method" << endl;
355 fCalibrationMode = kFfactor;
356 }
357
358 //
359 // output information or warnings:
360 //
361 switch(fCalibrationMode)
362 {
363 case kBlindPixel:
364 break;
365 case kFfactor:
366 break;
367 case kPinDiode:
368 *fLog << err << "PIN Diode Calibration mode not yet available!" << endl;
369 return kFALSE;
370 break;
371 case kCombined:
372 *fLog << err << "Combined Calibration mode not yet available!" << endl;
373 return kFALSE;
374 break;
375 case kFlatCharge:
376 *fLog << warn << "WARNING - Flat-fielding charges - only for muon calibration!" << endl;
377 break;
378 case kDummy:
379 *fLog << warn << "WARNING - Dummy calibration, no calibration applied!" << endl;
380 break;
381 case kNone:
382 *fLog << warn << "WARNING - No calibration applied!" << endl;
383 break;
384 default:
385 *fLog << warn << "WARNING - Calibration mode value (" << fCalibrationMode << ") not known" << endl;
386 return kFALSE;
387 }
388
389 //
390 // output information or warnings:
391 //
392 switch(fSignalType)
393 {
394 case kPhe:
395 *fLog << inf << "Calibrating in units of equivalent (outer/inner=4) photo-electrons." << endl;
396 break;
397 case kPhot:
398 *fLog << inf << "Calibrating in units of photons." << endl;
399 break;
400 }
401
402 const Int_t npixels = fGeomCam->GetNumPixels();
403
404 if (fCalibrationMode > kNone)
405 {
406
407 if (fCalibrations->GetSize() != npixels)
408 {
409 *fLog << "Size mismatch between MGeomCam and MCalibrationChargeCam... abort!" << endl;
410 return kFALSE;
411 }
412
413 if (fBadPixels->GetSize() != npixels)
414 {
415 *fLog << "Size mismatch between MGeomCam and MBadPixelsCam... abort!" << endl;
416 return kFALSE;
417 }
418 }
419
420 fCalibConsts .Set(npixels);
421 fCalibFFactors.Set(npixels);
422 fHiLoConv .Set(npixels);
423 fHiLoConvErr .Set(npixels);
424
425 if (!UpdateConversionFactors())
426 return kFALSE;
427
428 if (TestPedestalFlag(kRun))
429 Calibrate(kFALSE, kTRUE);
430
431 return kTRUE;
432}
433
434// --------------------------------------------------------------------------
435//
436// Update the conversion factors and F-Factors from MCalibrationCams into
437// the arrays. Later, the here pre-calcualted conversion factors get simply
438// copied from memory.
439//
440// This function can be called from outside in case that the MCalibrationCams
441// have been updated...
442//
443Bool_t MCalibrateData::UpdateConversionFactors( const MCalibrationChargeCam *updatecam)
444{
445
446 *fLog << inf << GetDescriptor() << ": Updating Conversion Factors... " << endl;
447
448 fCalibConsts.Reset();
449 fCalibFFactors.Reset();
450 fHiLoConv.Reset();
451 fHiLoConvErr.Reset();
452
453 //
454 // For the moment, we use only a dummy zenith for the calibration:
455 //
456 const Float_t zenith = -1.;
457
458 UInt_t skip = 0;
459
460 for (UInt_t pixidx=0; pixidx<fGeomCam->GetNumPixels(); pixidx++)
461 {
462
463 Float_t hiloconv = 1.;
464 Float_t hiloconverr = 0.;
465 Float_t calibConv = 1.;
466 Float_t calibConvVar = 0.;
467 Float_t calibFFactor = 0.;
468
469 Float_t calibQE = 1.;
470 Float_t calibQEVar = 0.;
471
472 Float_t calibUpdate = 1.;
473
474 MCalibConstPix &cpix = (*fCalibConstCam)[pixidx];
475
476 if(fCalibrationMode!=kNone)
477 {
478 if ((*fBadPixels)[pixidx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
479 {
480 skip++;
481 calibConv = -1.;
482 continue;
483 }
484
485 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCalibrations)[pixidx];
486 MCalibrationChargePix &avpix = (MCalibrationChargePix&)fCalibrations->GetAverageArea(0);
487
488 hiloconv = pix.GetConversionHiLo ();
489 hiloconverr= pix.GetConversionHiLoErr();
490
491 calibConv = pix.GetMeanConvFADC2Phe();
492 calibConvVar = pix.GetMeanConvFADC2PheVar();
493 calibFFactor = pix.GetMeanFFactorFADC2Phot();
494
495 MCalibrationQEPix &qe = (MCalibrationQEPix&) (*fQEs)[pixidx];
496
497 if (updatecam)
498 {
499 const MCalibrationChargePix &upix = (MCalibrationChargePix&)(*updatecam)[pixidx];
500
501 //
502 // Correct for the possible change in amplification of the individual pixels chain
503 //
504 const Float_t pixmean = upix.GetConvertedMean();
505 calibUpdate = pixmean==0 ? 1 : pix.GetConvertedMean()/pixmean;
506
507 //
508 // Correct for global shifts in light emission
509 //
510 const MCalibrationChargePix &ugpix = (MCalibrationChargePix&)updatecam->GetAverageArea(0);
511
512 const Float_t globmean = avpix.GetConvertedMean();
513 calibUpdate = globmean==0 ? 1 : ugpix.GetConvertedMean()/globmean;
514
515 MBadPixelsPix &ubad = (MBadPixelsPix&)updatecam->GetAverageBadArea(0);
516 if (ubad.IsUncalibrated(MBadPixelsPix::kChargeIsPedestal))
517 {
518 *fLog << warn << GetDescriptor() << ": Mean charge in inner pixels is smaller than 3 ped. RMS." << endl;
519 *fLog << "Maybe calibration pulses have been lost!" << endl;
520 calibUpdate = 1.;
521
522 }
523 }
524
525 switch(fCalibrationMode)
526 {
527 case kFlatCharge:
528 {
529 calibConv = avpix.GetConvertedMean()
530 / (pix.GetConvertedMean() * fGeomCam->GetPixRatio(pixidx));
531 calibConvVar = (avpix.GetMeanRelVar() + pix.GetMeanRelVar()) * calibConv * calibConv;
532 if (pix.IsFFactorMethodValid())
533 {
534 const Float_t convmin1 = qe.GetQECascadesFFactor(zenith)/pix.GetMeanConvFADC2Phe();
535 if (convmin1 > 0)
536 calibFFactor *= TMath::Sqrt(convmin1);
537 else
538 calibFFactor = -1.;
539 }
540 break;
541 }
542 case kBlindPixel:
543 if (!qe.IsBlindPixelMethodValid())
544 {
545 skip++;
546 continue;
547 }
548 calibQE = qe.GetQECascadesBlindPixel ( zenith );
549 calibQEVar = qe.GetQECascadesBlindPixelVar( zenith );
550 break;
551
552 case kPinDiode:
553 if (!qe.IsPINDiodeMethodValid())
554 {
555 skip++;
556 continue;
557 }
558 calibQE = qe.GetQECascadesPINDiode ( zenith );
559 calibQEVar = qe.GetQECascadesPINDiodeVar( zenith );
560 break;
561
562 case kFfactor:
563 if (!pix.IsFFactorMethodValid())
564 {
565 skip++;
566 continue;
567 }
568 calibQE = qe.GetQECascadesFFactor ( zenith );
569 calibQEVar = qe.GetQECascadesFFactorVar( zenith );
570 break;
571
572 case kCombined:
573 if (!qe.IsCombinedMethodValid())
574 {
575 skip++;
576 continue;
577 }
578 calibQE = qe.GetQECascadesCombined ( zenith );
579 calibQEVar = qe.GetQECascadesCombinedVar( zenith );
580 break;
581
582 case kDummy:
583 hiloconv = 1.;
584 hiloconverr = 0.;
585 calibUpdate = 1.;
586 break;
587
588 default:
589 break;
590 } /* switch calibration mode */
591 } /* if(fCalibrationMode!=kNone) */
592 else
593 {
594 calibConv = 1./fGeomCam->GetPixRatio(pixidx);
595 }
596
597 calibConv /= calibQE;
598
599 if (calibConv != 0. && calibQE != 0.)
600 {
601 calibConvVar = calibConvVar/(calibConv*calibConv) + calibQEVar/(calibQE*calibQE);
602 calibConvVar *= (calibConv*calibConv);
603 }
604
605 calibConv *= fRenormFactor * calibUpdate;
606 calibFFactor *= TMath::Sqrt(fRenormFactor);
607
608 fHiLoConv [pixidx] = hiloconv;
609 fHiLoConvErr [pixidx] = hiloconverr;
610 fCalibConsts [pixidx] = calibConv;
611 fCalibFFactors[pixidx] = calibFFactor;
612
613 if (calibConv < fCalibConvMinLimit || calibConv > fCalibConvMaxLimit)
614 {
615 (*fBadPixels)[pixidx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
616 calibConv = -1.;
617 calibFFactor = -1.;
618 }
619 cpix.SetCalibConst(calibConv);
620 cpix.SetCalibFFactor(calibFFactor);
621
622 } /* for (Int_t pixidx=0; pixidx<fGeomCam->GetNumPixels(); pixidx++) */
623
624 if (skip>fGeomCam->GetNumPixels()*0.9)
625 {
626 *fLog << warn << GetDescriptor()
627 << ": WARNING - GetConversionFactor has skipped more than 90% of the pixels... abort." << endl;
628 return kFALSE;
629 }
630
631 return kTRUE;
632}
633
634
635// --------------------------------------------------------------------------
636//
637// Apply the conversion factors and F-Factors from the arrays to the data.
638//
639// The flags 'data' and 'pedestal' decide whether the signal and/or the pedetals
640// shall be calibrated, respectively.
641//
642Int_t MCalibrateData::Calibrate(Bool_t data, Bool_t pedestal) const
643{
644 if (!data && !pedestal)
645 return kTRUE;
646
647 const UInt_t npix = fSignals->GetSize();
648 const Float_t slices = fSignals->GetNumUsedHiGainFADCSlices();
649 const Float_t sqrtslices = TMath::Sqrt(slices);
650
651 Int_t numsatlo=0;
652 Int_t numsathi=0;
653
654 for (UInt_t pixidx=0; pixidx<npix; pixidx++)
655 {
656
657 if (data)
658 {
659 const MExtractedSignalPix &sig = (*fSignals)[pixidx];
660
661 Float_t signal = 0.;
662 Float_t signalErr = 0.;
663
664 if (sig.IsLoGainUsed())
665 {
666 if (fHiLoConv[pixidx] < 0.5)
667 {
668 signal = sig.GetExtractedSignalHiGain()*1.5;
669 signalErr = sig.GetExtractedSignalHiGain()*0.5;
670 }
671 else
672 {
673 const Float_t siglo = sig.GetExtractedSignalLoGain();
674
675 if (siglo > 0.1) // low-gain signal has been extracted successfully
676 {
677 signal = siglo*fHiLoConv [pixidx];
678 signalErr = siglo*fHiLoConvErr[pixidx];
679 }
680 else // low-gain signal has not been extracted successfully, get a rough estimate from the high-gain
681 {
682 signal = sig.GetExtractedSignalHiGain()*1.5;
683 signalErr = sig.GetExtractedSignalHiGain()*0.5;
684 }
685 }
686 }
687 else
688 {
689 if (sig.GetExtractedSignalHiGain() <= 9999.)
690 signal = sig.GetExtractedSignalHiGain();
691 }
692
693 const Float_t nphot = signal * fCalibConsts [pixidx];
694 const Float_t nphotErr = TMath::Sqrt(TMath::Abs(nphot)) * fCalibFFactors[pixidx];
695
696 fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
697
698 if (sig.GetNumHiGainSaturated() > 0)
699 numsathi++;
700
701 if (sig.GetNumLoGainSaturated() > 0)
702 numsatlo++;
703 } /* if (data) */
704
705
706 if (pedestal)
707 {
708 TIter NextPed(&fPedestalCams);
709 TIter NextPhot(&fPedPhotCams);
710
711 MPedestalCam *pedestal = 0;
712 MPedPhotCam *pedphot = 0;
713
714 const Float_t pedmeancalib = slices *fCalibConsts[pixidx];
715 const Float_t pedrmscalib = sqrtslices*fCalibConsts[pixidx];
716
717 while ((pedestal=(MPedestalCam*)NextPed()) &&
718 (pedphot =(MPedPhotCam*)NextPhot()))
719 {
720 // pedestals/(used FADC slices) in [number of photons]
721 const Float_t mean = (*pedestal)[pixidx].GetPedestal() *pedmeancalib;
722 const Float_t rms = (*pedestal)[pixidx].GetPedestalRms()*pedrmscalib;
723
724 (*pedphot)[pixidx].Set(mean, rms);
725 pedphot->SetReadyToSave();
726 }
727 } /* if (pedestal) */
728 }
729
730 if (data)
731 {
732 fCerPhotEvt->SetNumPixelsSaturated(numsathi, numsatlo);
733 fCerPhotEvt->SetReadyToSave();
734 }
735 return kTRUE;
736}
737
738// --------------------------------------------------------------------------
739//
740// Apply the calibration factors to the extracted signal according to the
741// selected calibration method
742//
743Int_t MCalibrateData::Process()
744{
745 return Calibrate(fCalibrationMode!=kSkip, TestPedestalFlag(kEvent));
746}
747
748// --------------------------------------------------------------------------
749//
750// Implementation of SavePrimitive. Used to write the call to a constructor
751// to a macro. In the original root implementation it is used to write
752// gui elements to a macro-file.
753//
754void MCalibrateData::StreamPrimitive(ofstream &out) const
755{
756 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
757 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
758
759 if (TestPedestalFlag(kEvent))
760 out << " " << GetUniqueName() << ".EnablePedestalType(MCalibrateData::kEvent)" << endl;
761 if (TestPedestalFlag(kRun))
762 out << " " << GetUniqueName() << ".EnablePedestalType(MCalibrateData::kRun)" << endl;
763
764 if (fCalibrationMode != gkDefault)
765 {
766 out << " " << GetUniqueName() << ".SetCalibrationMode(MCalibrateData::";
767 switch (fCalibrationMode)
768 {
769 case kSkip: out << "kSkip"; break;
770 case kNone: out << "kNone"; break;
771 case kFlatCharge: out << "kFlatCharge"; break;
772 case kBlindPixel: out << "kBlindPixel"; break;
773 case kFfactor: out << "kFfactor"; break;
774 case kPinDiode: out << "kPinDiode"; break;
775 case kCombined: out << "kCombined"; break;
776 case kDummy: out << "kDummy"; break;
777 default: out << (int)fCalibrationMode; break;
778 }
779 out << ")" << endl;
780 }
781
782 TIter Next(&fNamesPedestal);
783 TObject *o=0;
784 while ((o=Next()))
785 {
786 out << " " << GetUniqueName() << ".AddPedestal(\"";
787 out << o->GetName() << "\", \"" << o->GetTitle() << "\");" << endl;
788 }
789}
790
791// --------------------------------------------------------------------------
792//
793// Read the setup from a TEnv, eg:
794// MJPedestal.MCalibrateDate.PedestalFlag: no,run,event
795// MJPedestal.MCalibrateDate.CalibrationMode: skip,none,flatcharge,blindpixel,ffactor,pindiode,combined,dummy,default
796//
797Int_t MCalibrateData::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
798{
799 Bool_t rc = kFALSE;
800 if (IsEnvDefined(env, prefix, "PedestalFlag", print))
801 {
802 rc = kTRUE;
803 TString s = GetEnvValue(env, prefix, "PedestalFlag", "");
804 s.ToLower();
805 if (s.BeginsWith("no"))
806 SetPedestalFlag(kNo);
807 if (s.BeginsWith("run"))
808 SetPedestalFlag(kRun);
809 if (s.BeginsWith("event"))
810 SetPedestalFlag(kEvent);
811 }
812
813 if (IsEnvDefined(env, prefix, "CalibrationMode", print))
814 {
815 rc = kTRUE;
816 TString s = GetEnvValue(env, prefix, "CalibrationMode", "");
817 s.ToLower();
818 if (s.BeginsWith("skip"))
819 SetCalibrationMode(kSkip);
820 if (s.BeginsWith("none"))
821 SetCalibrationMode(kNone);
822 if (s.BeginsWith("flatcharge"))
823 SetCalibrationMode(kFlatCharge);
824 if (s.BeginsWith("blindpixel"))
825 SetCalibrationMode(kBlindPixel);
826 if (s.BeginsWith("ffactor"))
827 SetCalibrationMode(kFfactor);
828 if (s.BeginsWith("pindiode"))
829 SetCalibrationMode(kPinDiode);
830 if (s.BeginsWith("combined"))
831 SetCalibrationMode(kCombined);
832 if (s.BeginsWith("dummy"))
833 SetCalibrationMode(kDummy);
834 if (s.BeginsWith("default"))
835 SetCalibrationMode();
836 }
837
838 if (IsEnvDefined(env, prefix, "SignalType", print))
839 {
840 rc = kTRUE;
841 TString s = GetEnvValue(env, prefix, "SignalType", "");
842 s.ToLower();
843 if (s.BeginsWith("phot"))
844 SetSignalType(kPhot);
845 if (s.BeginsWith("phe"))
846 SetSignalType(kPhe);
847 if (s.BeginsWith("default"))
848 SetSignalType();
849 }
850
851 if (IsEnvDefined(env, prefix, "CalibConvMinLimit", print))
852 {
853 fCalibConvMinLimit = GetEnvValue(env, prefix, "CalibConvMinLimit", fCalibConvMinLimit);
854 rc = kTRUE;
855 }
856
857 if (IsEnvDefined(env, prefix, "CalibConvMaxLimit", print))
858 {
859 fCalibConvMaxLimit = GetEnvValue(env, prefix, "CalibConvMaxLimit", fCalibConvMaxLimit);
860 rc = kTRUE;
861 }
862
863 return rc;
864}
865
866void MCalibrateData::Print(Option_t *o) const
867{
868
869 *fLog << all << GetDescriptor() << ":" << endl;
870
871 for (UInt_t pixidx=0; pixidx<fGeomCam->GetNumPixels(); pixidx++)
872 {
873 *fLog << all
874 << "Pixel: " << Form("%3i",pixidx)
875 << " CalibConst: " << Form("%4.2f",fCalibConsts[pixidx])
876 << " F-Factor: " << Form("%4.2f",fCalibFFactors[pixidx])
877 << " HiLoConv: " << Form("%4.2f",fHiLoConv[pixidx])
878 << endl;
879 }
880}
881
Note: See TracBrowser for help on using the repository browser.