source: tags/Mars-V0.9.3/mcalib/MCalibrateData.cc

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