source: trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc@ 3007

Last change on this file since 3007 was 3007, checked in by gaug, 21 years ago
*** empty log message ***
File size: 19.8 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!
19! Author(s): Markus Gaug 11/2003 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MCalibrationCam
29//
30// Hold the whole Calibration results of the camera:
31//
32// 1) MCalibrationCam initializes a TClonesArray whose elements are
33// pointers to MCalibrationPix Containers
34// 2) It initializes a pointer to an MCalibrationBlindPix container
35// 3) It initializes a pointer to an MCalibrationPINDiode container
36//
37// 4)
38//
39/////////////////////////////////////////////////////////////////////////////
40#include "MCalibrationCam.h"
41
42#include <TH2.h>
43#include <TCanvas.h>
44#include <TClonesArray.h>
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MGeomCam.h"
50
51#include "MCalibrationPix.h"
52#include "MCalibrationConfig.h"
53#include "MCalibrationBlindPix.h"
54#include "MCalibrationPINDiode.h"
55
56#include "MHCalibrationPixel.h"
57
58ClassImp(MCalibrationCam);
59
60using namespace std;
61
62const Int_t MCalibrationCam::gkBlindPixelId = 559;
63const Int_t MCalibrationCam::gkPINDiodeId = 9999;
64const Float_t MCalibrationCam::gkTimeSliceWidth = 3.3;
65
66// --------------------------------------------------------------------------
67//
68// Default constructor.
69//
70// Creates a TClonesArray of MCalibrationPix containers, initialized to 1 entry
71// Later, a call to MCalibrationCam::InitSize(Int_t size) has to be performed
72//
73// Creates an MCalibrationBlindPix container
74// Creates an MCalibrationPINDiode container
75//
76MCalibrationCam::MCalibrationCam(const char *name, const char *title)
77 : fOffsets(NULL),
78 fSlopes(NULL),
79 fOffvsSlope(NULL)
80{
81 fName = name ? name : "MCalibrationCam";
82 fTitle = title ? title : "Storage container for the Calibration Information in the camera";
83
84 fPixels = new TClonesArray("MCalibrationPix",1);
85 fBlindPixel = new MCalibrationBlindPix();
86 fPINDiode = new MCalibrationPINDiode();
87
88 Clear();
89}
90
91// --------------------------------------------------------------------------
92//
93// Delete the TClonesArray of MCalibrationPix containers
94// Delete the MCalibrationPINDiode and the MCalibrationBlindPix
95//
96// Delete the histograms if they exist
97//
98MCalibrationCam::~MCalibrationCam()
99{
100
101 //
102 // delete fPixels should delete all Objects stored inside
103 //
104 delete fPixels;
105 delete fBlindPixel;
106 delete fPINDiode;
107
108 if (fOffsets)
109 delete fOffsets;
110 if (fSlopes)
111 delete fSlopes;
112 if (fOffvsSlope)
113 delete fOffvsSlope;
114
115}
116
117// -------------------------------------------------------------------
118//
119// This function simply allocates memory via the ROOT command:
120// (TObject**) TStorage::ReAlloc(fCont, newSize * sizeof(TObject*),
121// fSize * sizeof(TObject*));
122// newSize corresponds to size in our case
123// fSize is the old size (in most cases: 1)
124//
125void MCalibrationCam::InitSize(const UInt_t i)
126{
127
128 //
129 // check if we have already initialized to size
130 //
131 if (CheckBounds(i))
132 return;
133
134 fPixels->ExpandCreate(i);
135
136}
137
138// --------------------------------------------------------------------------
139//
140// This function returns the current size of the TClonesArray
141// independently if the MCalibrationPix is filled with values or not.
142//
143// It is the size of the array fPixels.
144//
145Int_t MCalibrationCam::GetSize() const
146{
147 return fPixels->GetEntriesFast();
148}
149
150// --------------------------------------------------------------------------
151//
152// Check if position i is inside the current bounds of the TClonesArray
153//
154Bool_t MCalibrationCam::CheckBounds(Int_t i) const
155{
156 return i < GetSize();
157}
158
159
160// --------------------------------------------------------------------------
161//
162// Get i-th pixel (pixel number)
163//
164MCalibrationPix &MCalibrationCam::operator[](Int_t i)
165{
166 return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
167}
168
169// --------------------------------------------------------------------------
170//
171// Get i-th pixel (pixel number)
172//
173MCalibrationPix &MCalibrationCam::operator[](Int_t i) const
174{
175 return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
176}
177
178
179// --------------------------------------
180//
181void MCalibrationCam::Clear(Option_t *o)
182{
183
184 fPixels->ForEach(TObject, Clear)();
185 fBlindPixel->Clear();
186 fPINDiode->Clear();
187
188 fMeanPhotInsidePlexiglass = -1.;
189 fMeanPhotErrInsidePlexiglass = -1.;
190 fMeanPhotOutsidePlexiglass = -1.;
191 fMeanPhotErrOutsidePlexiglass = -1.;
192
193 fNumExcludedPixels = 0;
194
195 CLRBIT(fFlags,kBlindPixelMethodValid);
196 CLRBIT(fFlags,kPINDiodeMethodValid);
197 CLRBIT(fFlags,kNumPhotInsidePlexiglassAvailable);
198 CLRBIT(fFlags,kNumPhotOutsidePlexiglassAvailable);
199
200 return;
201}
202
203void MCalibrationCam::SetBlindPixelMethodValid(const Bool_t b)
204{
205
206 if (b)
207 SETBIT(fFlags, kBlindPixelMethodValid);
208 else
209 CLRBIT(fFlags, kBlindPixelMethodValid);
210
211}
212
213void MCalibrationCam::SetPINDiodeMethodValid(const Bool_t b)
214{
215
216 if (b)
217 SETBIT(fFlags, kPINDiodeMethodValid);
218 else
219 CLRBIT(fFlags, kPINDiodeMethodValid);
220
221
222}
223
224Bool_t MCalibrationCam::IsBlindPixelMethodValid() const
225{
226 return TESTBIT(fFlags,kBlindPixelMethodValid);
227}
228
229Bool_t MCalibrationCam::IsPINDiodeMethodValid() const
230{
231 return TESTBIT(fFlags,kPINDiodeMethodValid);
232}
233
234
235Bool_t MCalibrationCam::IsNumPhotInsidePlexiglassAvailable() const
236{
237 return TESTBIT(fFlags,kNumPhotInsidePlexiglassAvailable);
238}
239
240Bool_t MCalibrationCam::IsNumPhotOutsidePlexiglassAvailable() const
241{
242 return TESTBIT(fFlags,kNumPhotOutsidePlexiglassAvailable);
243}
244
245
246
247// --------------------------------------------------------------------------
248//
249// Print first the well fitted pixels
250// and then the ones which are not FitValid
251//
252void MCalibrationCam::Print(Option_t *o) const
253{
254
255 *fLog << all << GetDescriptor() << ":" << endl;
256 int id = 0;
257
258 *fLog << all << "Succesfully calibrated pixels:" << endl;
259 *fLog << all << endl;
260
261 TIter Next(fPixels);
262 MCalibrationPix *pix;
263 while ((pix=(MCalibrationPix*)Next()))
264 {
265
266 if (pix->IsChargeFitValid() && !pix->IsExcluded())
267 {
268
269 Float_t rsigma = pix->GetRSigmaSquare();
270 if (rsigma > 0.)
271 rsigma = TMath::Sqrt(rsigma);
272
273 *fLog << all << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- "
274 << pix->GetPedRms() << " Reduced Charge: " << pix->GetCharge() << " +- "
275 << pix->GetSigmaCharge() << " Reduced Sigma: " << rsigma
276 << " Nr Phe's: " << pix->GetPheFFactorMethod() << endl;
277 id++;
278 }
279 }
280
281 *fLog << all << id << " succesful pixels :-))" << endl;
282 id = 0;
283
284 *fLog << all << endl;
285 *fLog << all << "Pixels with errors:" << endl;
286 *fLog << all << endl;
287
288 TIter Next2(fPixels);
289 while ((pix=(MCalibrationPix*)Next2()))
290 {
291
292 if (!pix->IsChargeFitValid() && !pix->IsExcluded())
293 {
294
295 Float_t rsigma = pix->GetRSigmaSquare();
296 if (rsigma > 0.)
297 rsigma = TMath::Sqrt(rsigma);
298
299 *fLog << all << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- "
300 << pix->GetPedRms() << " Reduced Charge: " << pix->GetCharge() << " +- "
301 << pix->GetSigmaCharge() << " Reduced Sigma: " << rsigma << endl;
302 id++;
303 }
304 }
305 *fLog << all << id << " pixels with errors :-((" << endl;
306
307 *fLog << all << endl;
308 *fLog << all << "Excluded pixels:" << endl;
309 *fLog << all << endl;
310
311 TIter Next3(fPixels);
312 while ((pix=(MCalibrationPix*)Next3()))
313 if (pix->IsExcluded())
314 *fLog << all << pix->GetPixId() << endl;
315
316 *fLog << all << fNumExcludedPixels << " excluded pixels " << endl;
317}
318
319// --------------------------------------------------------------------------
320//
321// Return true if pixel is inside bounds of the TClonesArray fPixels
322//
323Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const
324{
325 if (!CheckBounds(idx))
326 return kFALSE;
327
328 return kTRUE;
329}
330
331// --------------------------------------------------------------------------
332//
333// Return true if pixel has already been fitted once (independent of the result)
334//
335Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const
336{
337
338 if (!CheckBounds(idx))
339 return kFALSE;
340
341 return (*this)[idx].IsFitted();
342}
343
344// --------------------------------------------------------------------------
345//
346// Sets the user ranges of all histograms such that
347// empty bins at the edges are not used. Additionally, it rebins the
348// histograms such that in total, 50 bins are used.
349//
350void MCalibrationCam::CutEdges()
351{
352
353 fBlindPixel->GetHist()->CutAllEdges();
354 fPINDiode->GetHist()->CutAllEdges();
355
356 TIter Next(fPixels);
357 MCalibrationPix *pix;
358 while ((pix=(MCalibrationPix*)Next()))
359 {
360 pix->GetHist()->CutAllEdges();
361 }
362
363 return;
364}
365
366
367// The types are as follows:
368//
369// 0: Fitted Charge
370// 1: Error of fitted Charge
371// 2: Sigma of fitted Charge
372// 3: Error of Sigma of fitted Charge
373// 4: Returned probability of Gauss fit to Charge distribution
374// 5: Mean arrival time
375// 6: Sigma of the arrival time
376// 7: Chi-square of the Gauss fit to the arrival times
377// 8: Pedestal
378// 9: Pedestal RMS
379// 10: Reduced Sigma Square
380// 11: Number of Photo-electrons after the F-Factor method
381// 12: Error on the Number of Photo-electrons after the F-Factor method
382// 13: Mean conversion factor after the F-Factor method
383// 14: Error on the conversion factor after the F-Factor method
384// 15: Number of Photons after the Blind Pixel method
385// 16: Mean conversion factor after the Blind Pixel method
386//
387Bool_t MCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
388{
389
390 if (idx > GetSize())
391 return kFALSE;
392
393 if ( (!(*this)[idx].IsChargeFitValid()) || (*this)[idx].IsExcluded())
394 return kFALSE;
395
396 if (idx == gkBlindPixelId)
397 return kFALSE;
398
399 if (idx == gkPINDiodeId)
400 return kFALSE;
401
402 switch (type)
403 {
404 case 0:
405 val = (*this)[idx].GetCharge();
406 break;
407 case 1:
408 val = (*this)[idx].GetErrCharge();
409 break;
410 case 2:
411 val = (*this)[idx].GetSigmaCharge();
412 break;
413 case 3:
414 val = (*this)[idx].GetErrSigmaCharge();
415 break;
416 case 4:
417 val = (*this)[idx].GetChargeProb();
418 break;
419 case 5:
420 if (!(*this)[idx].IsTimeFitValid())
421 return kFALSE;
422 val = (*this)[idx].GetTime() * gkTimeSliceWidth;
423 break;
424 case 6:
425 if (!(*this)[idx].IsTimeFitValid())
426 return kFALSE;
427 val = (*this)[idx].GetSigmaTime() * gkTimeSliceWidth;
428 break;
429 case 7:
430 if (!(*this)[idx].IsTimeFitValid())
431 return kFALSE;
432 val = (*this)[idx].GetTimeProb();
433 break;
434 case 8:
435 val = (*this)[idx].GetPed();
436 break;
437 case 9:
438 val = (*this)[idx].GetPedRms();
439 break;
440 case 10:
441 if ((*this)[idx].GetRSigmaSquare() > 0.)
442 val = TMath::Sqrt((*this)[idx].GetRSigmaSquare());
443 else
444 val = -1.;
445 break;
446 case 11:
447 val = (*this)[idx].GetPheFFactorMethod();
448 break;
449 case 12:
450 val = (*this)[idx].GetPheFFactorMethodError();
451 break;
452 case 13:
453 val = (*this)[idx].GetMeanConversionFFactorMethod();
454 break;
455 case 14:
456 val = (*this)[idx].GetErrorConversionFFactorMethod();
457 break;
458 case 15:
459 if (idx < 397)
460 val = (double)fMeanPhotInsidePlexiglass;
461 else
462 val = (double)fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
463 break;
464 case 16:
465 if (idx < 397)
466 val = (*this)[idx].GetMeanConversionBlindPixelMethod();
467 else
468 val = (*this)[idx].GetMeanConversionBlindPixelMethod()*gkCalibrationOutervsInnerPixelArea;
469 break;
470 case 17:
471 if ( (*this)[idx].GetRSigmaSquare() > 0. && (*this)[idx].GetCharge() > 0. )
472 val = TMath::Sqrt((*this)[idx].GetRSigmaSquare()) / (*this)[idx].GetCharge();
473 else
474 val = -1.;
475 break;
476 default:
477 return kFALSE;
478 }
479 return val!=-1.;
480}
481
482// --------------------------------------------------------------------------
483//
484// What MHCamera needs in order to draw an individual pixel in the camera
485//
486void MCalibrationCam::DrawPixelContent(Int_t idx) const
487{
488 (*this)[idx].Draw();
489}
490
491
492// --------------------------------------------------------------------------
493//
494//
495//
496Bool_t MCalibrationCam::CalcNumPhotInsidePlexiglass()
497{
498
499 if (!fBlindPixel->IsFitOK())
500 return kFALSE;
501
502 const Float_t mean = fBlindPixel->GetLambda();
503 const Float_t merr = fBlindPixel->GetErrLambda();
504
505 switch (fColor)
506 {
507 case kECGreen:
508 fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEGreen) // real photons
509 *TMath::Power(10,gkCalibrationBlindPixelAttGreen) // correct for absorption
510 * gkCalibrationInnerPixelArea; // correct for area
511
512
513 break;
514 case kECBlue:
515 fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEBlue )
516 *TMath::Power(10,gkCalibrationBlindPixelAttBlue)
517 * gkCalibrationInnerPixelArea;
518 break;
519 case kECUV:
520 fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEUV )
521 *TMath::Power(10,gkCalibrationBlindPixelAttUV)
522 * gkCalibrationInnerPixelArea;
523 break;
524 case kECCT1:
525 default:
526 fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQECT1 )
527 *TMath::Power(10,gkCalibrationBlindPixelAttCT1)
528 * gkCalibrationInnerPixelArea;
529 break;
530 }
531
532 SETBIT(fFlags,kNumPhotInsidePlexiglassAvailable);
533
534 *fLog << inf << endl;
535 *fLog << inf << "Mean number of Photons for an Inner Pixel (inside Plexiglass): "
536 << fMeanPhotInsidePlexiglass << endl;
537
538 TIter Next(fPixels);
539 MCalibrationPix *pix;
540 while ((pix=(MCalibrationPix*)Next()))
541 {
542 if((pix->GetCharge() > 0.) && (fMeanPhotInsidePlexiglass > 0.))
543 {
544
545 Float_t conversion = fMeanPhotInsidePlexiglass/pix->GetCharge();
546 Float_t conversionerr = 0.;
547 Float_t conversionsigma = 0.;
548 pix->SetConversionBlindPixelMethod(conversion, conversionerr, conversionsigma);
549
550 if (conversionerr/conversion < 0.1)
551 pix->SetBlindPixelMethodValid();
552 }
553 }
554 return kTRUE;
555}
556
557
558Bool_t MCalibrationCam::CalcNumPhotOutsidePlexiglass()
559{
560
561 if (!fPINDiode->IsChargeFitValid())
562 return kFALSE;
563
564 const Float_t mean = fPINDiode->GetCharge();
565 const Float_t merr = fPINDiode->GetErrCharge();
566
567 switch (fColor)
568 {
569 case kECGreen:
570 fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEGreen) // real photons
571 * gkCalibrationInnerPixelvsPINDiodeArea; // correct for area
572 break;
573 case kECBlue:
574 fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEBlue )
575 * gkCalibrationInnerPixelvsPINDiodeArea;
576 break;
577 case kECUV:
578 fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEUV )
579 * gkCalibrationInnerPixelvsPINDiodeArea;
580 break;
581 case kECCT1:
582 default:
583 fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQECT1 )
584 * gkCalibrationInnerPixelvsPINDiodeArea;
585 break;
586 }
587
588 SETBIT(fFlags,kNumPhotOutsidePlexiglassAvailable);
589
590 *fLog << inf << endl;
591 *fLog << inf << mean << " Mean number of Photons for an Inner Pixel (outside Plexiglass): "
592 << fMeanPhotOutsidePlexiglass << endl;
593 *fLog << inf << endl;
594
595 TIter Next(fPixels);
596 MCalibrationPix *pix;
597 while ((pix=(MCalibrationPix*)Next()))
598 {
599
600 if((pix->GetCharge() > 0.) && (fMeanPhotInsidePlexiglass > 0.))
601 pix->SetConversionPINDiodeMethod(fMeanPhotOutsidePlexiglass/pix->GetCharge(), 0., 0.);
602 }
603 return kTRUE;
604}
605
606
607
608Bool_t MCalibrationCam::GetConversionFactorBlindPixel(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
609{
610
611 if (ipx < 0 || !IsPixelFitted(ipx))
612 return kFALSE;
613
614 if (!IsNumPhotInsidePlexiglassAvailable())
615 if (!CalcNumPhotInsidePlexiglass())
616 return kFALSE;
617
618 mean = (*this)[ipx].GetMeanConversionBlindPixelMethod();
619 err = (*this)[ipx].GetErrorConversionBlindPixelMethod();
620 sigma = (*this)[ipx].GetSigmaConversionBlindPixelMethod();
621
622 return kTRUE;
623}
624
625
626Bool_t MCalibrationCam::GetConversionFactorFFactor(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
627{
628
629 if (ipx < 0 || !IsPixelFitted(ipx))
630 return kFALSE;
631
632 Float_t conv = (*this)[ipx].GetMeanConversionFFactorMethod();
633
634 if (conv < 0.)
635 return kFALSE;
636
637 mean = conv;
638 err = (*this)[ipx].GetErrorConversionFFactorMethod();
639 sigma = (*this)[ipx].GetSigmaConversionFFactorMethod();
640
641 return kTRUE;
642}
643
644
645//-----------------------------------------------------------------------------------
646//
647// Calculates the conversion factor between the integral of FADCs slices
648// (as defined in the signal extractor MExtractSignal.cc)
649// and the number of photons reaching the plexiglass for one Inner Pixel
650//
651// FIXME: The PINDiode is still not working and so is the code
652//
653Bool_t MCalibrationCam::GetConversionFactorPINDiode(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
654{
655
656 if (ipx < 0 || !IsPixelFitted(ipx))
657 return kFALSE;
658
659 if (!IsNumPhotOutsidePlexiglassAvailable())
660 if (!CalcNumPhotOutsidePlexiglass())
661 return kFALSE;
662
663 mean = (*this)[ipx].GetMeanConversionPINDiodeMethod();
664 err = (*this)[ipx].GetErrorConversionPINDiodeMethod();
665 sigma = (*this)[ipx].GetSigmaConversionPINDiodeMethod();
666
667 return kFALSE;
668
669}
670
671//-----------------------------------------------------------------------------------
672//
673// Calculates the best combination of the three used methods possible
674// between the integral of FADCs slices
675// (as defined in the signal extractor MExtractSignal.cc)
676// and the number of photons reaching one Inner Pixel.
677// The procedure is not yet defined.
678//
679// FIXME: The PINDiode is still not working and so is the code
680//
681Bool_t MCalibrationCam::GetConversionFactorCombined(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
682{
683
684 if (ipx < 0 || !IsPixelFitted(ipx))
685 return kFALSE;
686
687 return kFALSE;
688
689}
690
691
692void MCalibrationCam::DrawHiLoFits()
693{
694
695 if (!fOffsets)
696 fOffsets = new TH1D("pp","Offsets of the HiGain LoGain Fit",100,-600.,400.);
697 if (!fSlopes)
698 fSlopes = new TH1D("mm","Slopes of the HiGain LoGain Fit",100,-2.,2.);
699 if (!fOffvsSlope)
700 fOffvsSlope = new TH2D("aa","Slopes vs Offsets of the HiGain LoGain Fit",100,-600.,400.,100,-2.,2.);
701
702 TIter Next(fPixels);
703 MCalibrationPix *pix;
704 MHCalibrationPixel *hist;
705 while ((pix=(MCalibrationPix*)Next()))
706 {
707 hist = pix->GetHist();
708 hist->FitHiGainvsLoGain();
709 fOffsets->Fill(hist->GetOffset(),1.);
710 fSlopes->Fill(hist->GetSlope(),1.);
711 fOffvsSlope->Fill(hist->GetOffset(),hist->GetSlope(),1.);
712 }
713
714 TCanvas *c1 = new TCanvas();
715
716 c1->Divide(1,3);
717 c1->cd(1);
718 fOffsets->Draw();
719 gPad->Modified();
720 gPad->Update();
721
722 c1->cd(2);
723 fSlopes->Draw();
724 gPad->Modified();
725 gPad->Update();
726
727 c1->cd(3);
728 fOffvsSlope->Draw("col1");
729 gPad->Modified();
730 gPad->Update();
731}
732
Note: See TracBrowser for help on using the repository browser.