source: trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc@ 2699

Last change on this file since 2699 was 2699, checked in by gaug, 21 years ago
*** empty log message ***
File size: 15.1 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#include "MCalibrationPix.h"
42#include "MHCalibrationPixel.h"
43#include "MCalibrationBlindPix.h"
44#include "MCalibrationConfig.h"
45
46#include <TClonesArray.h>
47
48#include "MLog.h"
49#include "MLogManip.h"
50
51#include "TCanvas.h"
52
53#include "MGeomCam.h"
54
55ClassImp(MCalibrationCam);
56
57using namespace std;
58// --------------------------------------------------------------------------
59//
60// Default constructor.
61//
62// Creates a TClonesArray of MCalibrationPix containers, initialized to 1 entry
63// Later, a call to MCalibrationCam::InitSize(Int_t size) has to be performed
64//
65// Creates an MCalibrationBlindPix container
66// Creates an MCalibrationPINDiode container
67//
68MCalibrationCam::MCalibrationCam(const char *name, const char *title)
69 : fNumPhotInsidePlexiglassAvailable(kFALSE),
70 fMeanPhotInsidePlexiglass(-1.),
71 fMeanPhotErrInsidePlexiglass(-1.),
72 fNumPhotOutsidePlexiglassAvailable(kFALSE),
73 fMeanPhotOutsidePlexiglass(-1.),
74 fMeanPhotErrOutsidePlexiglass(-1.),
75 fOffsets(NULL),
76 fSlopes(NULL),
77 fOffvsSlope(NULL)
78{
79 fName = name ? name : "MCalibrationCam";
80 fTitle = title ? title : "Storage container for the Calibration Information in the camera";
81
82 fPixels = new TClonesArray("MCalibrationPix",1);
83 fBlindPixel = new MCalibrationBlindPix();
84 fPINDiode = new MCalibrationPINDiode();
85}
86
87// --------------------------------------------------------------------------
88//
89// Delete the TClonesArray of MCalibrationPix containers
90// Delete the MCalibrationPINDiode and the MCalibrationBlindPix
91//
92// Delete the histograms if they exist
93//
94MCalibrationCam::~MCalibrationCam()
95{
96
97 //
98 // delete fPixels should delete all Objects stored inside
99 //
100 delete fPixels;
101 delete fBlindPixel;
102 delete fPINDiode;
103
104 if (fOffsets)
105 delete fOffsets;
106 if (fSlopes)
107 delete fSlopes;
108 if (fOffvsSlope)
109 delete fOffvsSlope;
110
111}
112
113// -------------------------------------------------------------------
114//
115// This function simply allocates memory via the ROOT command:
116// (TObject**) TStorage::ReAlloc(fCont, newSize * sizeof(TObject*),
117// fSize * sizeof(TObject*));
118// newSize corresponds to size in our case
119// fSize is the old size (in most cases: 1)
120//
121void MCalibrationCam::InitSize(Int_t size)
122{
123
124 //
125 // check if we have already initialized to size
126 //
127 if (CheckBounds(size))
128 return;
129
130 fPixels->ExpandCreate(size);
131
132}
133
134// --------------------------------------------------------------------------
135//
136// This function returns the current size of the TClonesArray
137// independently if the MCalibrationPix is filled with values or not.
138//
139// It is the size of the array fPixels.
140//
141Int_t MCalibrationCam::GetSize() const
142{
143 return fPixels->GetEntriesFast();
144}
145
146// --------------------------------------------------------------------------
147//
148// Check if position i is inside the current bounds of the TClonesArray
149//
150Bool_t MCalibrationCam::CheckBounds(Int_t i) const
151{
152 return i < fPixels->GetEntriesFast();
153}
154
155
156// --------------------------------------------------------------------------
157//
158// Get i-th pixel (pixel number)
159//
160MCalibrationPix &MCalibrationCam::operator[](Int_t i)
161{
162
163 if (!CheckBounds(i))
164 return *static_cast<MCalibrationPix*>(NULL);
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// Return a pointer to the pixel with the requested idx.
181// NULL if it doesn't exist.
182//
183MCalibrationPix *MCalibrationCam::GetCalibrationPix(Int_t idx) const
184{
185 if (idx<0)
186 return NULL;
187
188 if (!CheckBounds(idx))
189 return NULL;
190
191 return (MCalibrationPix*)fPixels->At(idx);
192}
193
194
195
196
197Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const
198{
199 if (!CheckBounds(idx))
200 return kFALSE;
201
202 return kTRUE;
203}
204
205Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const
206{
207 return ((*this)[idx].GetCharge() > 0. && (*this)[idx].GetErrCharge() > 0.);
208}
209
210
211
212void MCalibrationCam::Clear(Option_t *o)
213{
214 fPixels->ForEach(TObject, Clear)();
215}
216
217void MCalibrationCam::CutEdges()
218{
219
220 fBlindPixel->GetHist()->CutAllEdges();
221
222 TIter Next(fPixels);
223 MCalibrationPix *pix;
224 while ((pix=(MCalibrationPix*)Next()))
225 {
226 pix->GetHist()->CutAllEdges();
227 }
228
229 return;
230}
231
232void MCalibrationCam::Print(Option_t *o) const
233{
234
235 *fLog << all << GetDescriptor() << ":" << endl;
236 int id = 0;
237
238 *fLog << "Succesfully calibrated pixels:" << endl;
239 *fLog << endl;
240
241 TIter Next(fPixels);
242 MCalibrationPix *pix;
243 while ((pix=(MCalibrationPix*)Next()))
244 {
245
246 if (pix->GetCharge() >= 0.)
247 {
248 *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms()
249 << " Reduced Charge: " << pix->GetCharge() << " +- "
250 << pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
251 id++;
252 }
253 }
254
255 *fLog << id << " succesful pixels :-))" << endl;
256 id = 0;
257
258 *fLog << endl;
259 *fLog << "Pixels with errors:" << endl;
260 *fLog << endl;
261
262 TIter Next2(fPixels);
263 while ((pix=(MCalibrationPix*)Next2()))
264 {
265
266 if (pix->GetCharge() == -1.)
267 {
268 *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms()
269 << " Reduced Charge: " << pix->GetCharge() << " +- "
270 << pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
271 id++;
272 }
273 }
274 *fLog << id << " pixels with errors :-((" << endl;
275
276}
277
278
279Bool_t MCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
280{
281
282 if (idx > GetSize())
283 return kFALSE;
284
285 switch (type)
286 {
287 case 0:
288 val = (*this)[idx].GetCharge();
289 break;
290 case 1:
291 val = (*this)[idx].GetErrCharge();
292 break;
293 case 2:
294 val = (*this)[idx].GetSigmaCharge();
295 break;
296 case 3:
297 val = (*this)[idx].GetErrSigmaCharge();
298 break;
299 case 4:
300 val = (*this)[idx].GetChargeProb();
301 break;
302 case 5:
303 val = (*this)[idx].GetTime();
304 break;
305 case 6:
306 val = (*this)[idx].GetSigmaTime();
307 break;
308 case 7:
309 val = (*this)[idx].GetTimeChiSquare();
310 break;
311 case 8:
312 val = (*this)[idx].GetPed();
313 break;
314 case 9:
315 val = (*this)[idx].GetPedRms();
316 break;
317 case 10:
318 if ((*this)[idx].GetRSigmaSquare() > 0.)
319 val = TMath::Sqrt((*this)[idx].GetRSigmaSquare());
320 else
321 val = -1.;
322 break;
323 case 15:
324 if ((*this)[idx].GetCharge() != 0.)
325 val = ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge())*
326 ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge());
327 else
328 val = -1.;
329 break;
330 case 11:
331 val = (*this)[idx].GetPheFFactorMethod();
332 break;
333 case 12:
334 val = (*this)[idx].GetMeanConversionFFactorMethod();
335 break;
336 case 13:
337 if (idx < 397)
338 val = (double)fMeanPhotInsidePlexiglass;
339 else
340 val = (double)fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
341 break;
342 case 14:
343 if (idx < 397)
344 val = (*this)[idx].GetMeanConversionBlindPixelMethod();
345 else
346 val = (*this)[idx].GetMeanConversionBlindPixelMethod()*gkCalibrationOutervsInnerPixelArea;
347 break;
348 default:
349 return kFALSE;
350 }
351 return val>=0;
352}
353
354void MCalibrationCam::DrawPixelContent(Int_t idx) const
355{
356
357 (*this)[idx].Draw();
358
359}
360
361Bool_t MCalibrationCam::CalcNumPhotInsidePlexiglass()
362{
363
364 if (!fBlindPixel->IsFitOK())
365 return kFALSE;
366
367 const Float_t mean = fBlindPixel->GetLambda();
368 const Float_t merr = fBlindPixel->GetErrLambda();
369
370 switch (fColor)
371 {
372 case kECGreen:
373 fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEGreen) // real photons
374 *TMath::Power(10,gkCalibrationBlindPixelAttGreen) // correct for absorption
375 * gkCalibrationInnerPixelArea; // correct for area
376 break;
377 case kECBlue:
378 fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEBlue )
379 *TMath::Power(10,gkCalibrationBlindPixelAttBlue)
380 * gkCalibrationInnerPixelArea;
381 break;
382 case kECUV:
383 fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEUV )
384 *TMath::Power(10,gkCalibrationBlindPixelAttUV)
385 * gkCalibrationInnerPixelArea;
386 break;
387 case kECCT1:
388 default:
389 fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQECT1 )
390 *TMath::Power(10,gkCalibrationBlindPixelAttCT1)
391 * gkCalibrationInnerPixelArea;
392 break;
393 }
394
395 fNumPhotInsidePlexiglassAvailable = kTRUE;
396
397 *fLog << endl;
398 *fLog << mean << " Mean number of Photons for an Inner Pixel: " << fMeanPhotInsidePlexiglass << endl;
399 *fLog << endl;
400
401 TIter Next(fPixels);
402 MCalibrationPix *pix;
403 while ((pix=(MCalibrationPix*)Next()))
404 {
405 if((pix->GetCharge() > 0.) && (fMeanPhotInsidePlexiglass > 0.))
406 pix->SetConversionBlindPixelMethod(fMeanPhotInsidePlexiglass/pix->GetCharge(), 0., 0.);
407 }
408 return kTRUE;
409}
410
411
412Bool_t MCalibrationCam::CalcNumPhotOutsidePlexiglass()
413{
414
415 if (!fPINDiode->IsFitOK())
416 return kFALSE;
417
418 const Float_t mean = fPINDiode->GetMean();
419 const Float_t merr = fPINDiode->GetMeanError();
420
421 switch (fColor)
422 {
423 case kECGreen:
424 fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEGreen) // real photons
425 * gkCalibrationInnerPixelvsPINDiodeArea; // correct for area
426 break;
427 case kECBlue:
428 fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEBlue )
429 * gkCalibrationInnerPixelvsPINDiodeArea;
430 break;
431 case kECUV:
432 fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEUV )
433 * gkCalibrationInnerPixelvsPINDiodeArea;
434 break;
435 case kECCT1:
436 default:
437 fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQECT1 )
438 * gkCalibrationInnerPixelvsPINDiodeArea;
439 break;
440 }
441
442 fNumPhotOutsidePlexiglassAvailable = kTRUE;
443
444 TIter Next(fPixels);
445 MCalibrationPix *pix;
446 while ((pix=(MCalibrationPix*)Next()))
447 {
448
449 if((pix->GetCharge() > 0.) && (fMeanPhotInsidePlexiglass > 0.))
450 pix->SetConversionPINDiodeMethod(fMeanPhotOutsidePlexiglass/pix->GetCharge(), 0., 0.);
451 }
452 return kTRUE;
453}
454
455
456
457Bool_t MCalibrationCam::GetConversionFactorBlindPixel(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
458{
459
460 if (ipx < 0 || !IsPixelFitted(ipx))
461 return kFALSE;
462
463 if (!fNumPhotInsidePlexiglassAvailable)
464 if (!CalcNumPhotInsidePlexiglass())
465 return kFALSE;
466
467 mean = (*this)[ipx].GetMeanConversionBlindPixelMethod();
468 err = (*this)[ipx].GetErrorConversionBlindPixelMethod();
469 sigma = (*this)[ipx].GetSigmaConversionBlindPixelMethod();
470
471 return kTRUE;
472}
473
474
475Bool_t MCalibrationCam::GetConversionFactorFFactor(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
476{
477
478 if (ipx < 0 || !IsPixelFitted(ipx))
479 return kFALSE;
480
481 Float_t conv = (*this)[ipx].GetMeanConversionFFactorMethod();
482
483 if (conv < 0.)
484 return kFALSE;
485
486 mean = conv;
487 err = (*this)[ipx].GetErrorConversionFFactorMethod();
488 sigma = (*this)[ipx].GetSigmaConversionFFactorMethod();
489
490 return kTRUE;
491}
492
493
494//-----------------------------------------------------------------------------------
495//
496// Calculates the conversion factor between the integral of FADCs slices
497// (as defined in the signal extractor MExtractSignal.cc)
498// and the number of photons reaching the plexiglass for one Inner Pixel
499//
500// FIXME: The PINDiode is still not working and so is the code
501//
502Bool_t MCalibrationCam::GetConversionFactorPINDiode(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
503{
504
505 if (ipx < 0 || !IsPixelFitted(ipx))
506 return kFALSE;
507
508 return kFALSE;
509
510}
511
512//-----------------------------------------------------------------------------------
513//
514// Calculates the best combination of the three used methods possible
515// between the integral of FADCs slices
516// (as defined in the signal extractor MExtractSignal.cc)
517// and the number of photons reaching one Inner Pixel.
518// The procedure is not yet defined.
519//
520// FIXME: The PINDiode is still not working and so is the code
521//
522Bool_t MCalibrationCam::GetConversionFactorCombined(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
523{
524
525 if (ipx < 0 || !IsPixelFitted(ipx))
526 return kFALSE;
527
528 return kFALSE;
529
530}
531
532
533void MCalibrationCam::DrawHiLoFits()
534{
535
536 if (!fOffsets)
537 fOffsets = new TH1D("pp","Offsets of the HiGain LoGain Fit",100,-600.,400.);
538 if (!fSlopes)
539 fSlopes = new TH1D("mm","Slopes of the HiGain LoGain Fit",100,-2.,2.);
540 if (!fOffvsSlope)
541 fOffvsSlope = new TH2D("aa","Slopes vs Offsets of the HiGain LoGain Fit",100,-600.,400.,100,-2.,2.);
542
543 TIter Next(fPixels);
544 MCalibrationPix *pix;
545 MHCalibrationPixel *hist;
546 while ((pix=(MCalibrationPix*)Next()))
547 {
548 hist = pix->GetHist();
549 hist->FitHiGainvsLoGain();
550 fOffsets->Fill(hist->GetOffset(),1.);
551 fSlopes->Fill(hist->GetSlope(),1.);
552 fOffvsSlope->Fill(hist->GetOffset(),hist->GetSlope(),1.);
553 }
554
555 TCanvas *c1 = new TCanvas();
556
557 c1->Divide(1,3);
558 c1->cd(1);
559 fOffsets->Draw();
560 gPad->Modified();
561 gPad->Update();
562
563 c1->cd(2);
564 fSlopes->Draw();
565 gPad->Modified();
566 gPad->Update();
567
568 c1->cd(3);
569 fOffvsSlope->Draw("col1");
570 gPad->Modified();
571 gPad->Update();
572}
573
Note: See TracBrowser for help on using the repository browser.