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

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