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

Last change on this file since 2662 was 2661, checked in by gaug, 22 years ago
*** empty log message ***
File size: 15.0 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 Calibration information for all pixels in the camera //
31// //
32// The Classes MCalibrationPix's are stored in a TClonesArray //
33// The Class MCalibrationBlindPix and the MCalibrationPINDiode //
34// are stored in separate pointers //
35// //
36/////////////////////////////////////////////////////////////////////////////
37#include "MCalibrationCam.h"
38#include "MCalibrationPix.h"
39#include "MCalibrationBlindPix.h"
40#include "MCalibrationConfig.h"
41
42#include <TClonesArray.h>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "TCanvas.h"
48
49#include "MGeomCam.h"
50
51ClassImp(MCalibrationCam);
52
53using namespace std;
54// --------------------------------------------------------------------------
55//
56// Default constructor.
57// Creates a TClonesArray of MHCalibrationPix objects, initialized to 0 entries
58// Creates an MCalibrationBlindPix and an MCalibrationPINDiode
59//
60MCalibrationCam::MCalibrationCam(const char *name, const char *title)
61 : fMeanNrPhotAvailable(kFALSE),
62 fMeanNrPhotInnerPix(-1.),
63 fMeanNrPhotInnerPixErr(-1.),
64 fOffsets(NULL),
65 fSlopes(NULL)
66{
67 fName = name ? name : "MCalibrationCam";
68 fTitle = title ? title : "Storage container for the Calibration Information in the camera";
69
70 fPixels = new TClonesArray("MCalibrationPix",1);
71 fBlindPixel = new MCalibrationBlindPix();
72 fPINDiode = new MCalibrationPINDiode();
73}
74
75// --------------------------------------------------------------------------
76//
77// Delete the TClonesArray or MCalibrationPix's
78// Delete the MCalibrationPINDiode and the MCalibrationBlindPix
79//
80MCalibrationCam::~MCalibrationCam()
81{
82
83 //
84 // delete fPixels should delete all Objects stored inside
85 //
86 delete fPixels;
87 delete fBlindPixel;
88 delete fPINDiode;
89
90 if (fOffsets)
91 delete fOffsets;
92 if (fSlopes)
93 delete fSlopes;
94
95}
96
97void MCalibrationCam::DrawHiLoFits()
98{
99
100 fOffsets = new TH1D("pp","Offsets of the HiGain LoGain Fit",100,-300.,300.);
101 fSlopes = new TH1D("mm","Slopess of the HiGain LoGain Fit",100,-3.,3.);
102
103 TIter Next(fPixels);
104 MCalibrationPix *pix;
105 while ((pix=(MCalibrationPix*)Next()))
106 {
107
108 fOffsets->Fill(pix->GetHist()->GetOffset());
109 fSlopes->Fill(pix->GetHist()->GetSlope());
110
111 }
112
113 TCanvas *c1 = new TCanvas();
114 c1->Divide(1,2);
115 c1->cd(1);
116 fOffsets->Draw();
117 gPad->Modified();
118 gPad->Update();
119
120 c1->cd(2);
121 fSlopes->Draw();
122 gPad->Modified();
123 gPad->Update();
124}
125
126
127// --------------------------------------------------------------------------
128//
129// This function return the size of the FILLED MCalibrationCam
130// It is NOT the size of the array fPixels !!!
131// Note that with every call to AddPixels, GetSize() might change
132//
133Int_t MCalibrationCam::GetSize() const
134{
135
136 //
137 // Here we get the number of "filled" fPixels!!
138 //
139 return fPixels->GetEntriesFast();
140}
141
142// --------------------------------------------------------------------------
143//
144// Get i-th pixel (pixel number)
145//
146MCalibrationPix &MCalibrationCam::operator[](Int_t i)
147{
148 return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
149}
150
151// --------------------------------------------------------------------------
152//
153// Get i-th pixel (pixel number)
154//
155MCalibrationPix &MCalibrationCam::operator[](Int_t i) const
156{
157 return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
158}
159
160// --------------------------------------------------------------------------
161//
162// Return a pointer to the pixel with the requested idx.
163// NULL if it doesn't exist.
164//
165MCalibrationPix *MCalibrationCam::GetCalibrationPix(Int_t idx) const
166{
167 if (idx<0)
168 return NULL;
169
170 if (!CheckBounds(idx))
171 return NULL;
172
173 return (MCalibrationPix*)fPixels->At(idx);
174}
175
176
177
178// --------------------------------------------------------------------------
179//
180// Check if position i is inside bounds
181//
182Bool_t MCalibrationCam::CheckBounds(Int_t i) const
183{
184 return i < fPixels->GetEntriesFast();
185}
186
187Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const
188{
189 if (!CheckBounds(idx))
190 return kFALSE;
191
192 return kTRUE;
193}
194
195Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const
196{
197 return ((*this)[idx].GetCharge() > 0. && (*this)[idx].GetErrCharge() > 0.);
198}
199
200
201
202void MCalibrationCam::Clear(Option_t *o)
203{
204 fPixels->ForEach(TObject, Clear)();
205}
206
207//
208// Perform the fits of the charges
209// If i=-1, then all pixels will be fitted
210// Otherwise only the one with index i
211//
212// The number of succesful fits is returned
213//
214UShort_t MCalibrationCam::FitCharge(Int_t i)
215{
216
217 UShort_t nsuccess = 0;
218
219 // invalidate i if it exceeds the number of entries in fPixels
220 if (i > fPixels->GetEntriesFast())
221 {
222 *fLog << warn << "Tried to fit pixel out of allowed range " << endl;
223 return 0;
224 }
225
226 if (i == -1) // loop over all events
227 {
228
229 TIter Next(fPixels);
230 MCalibrationPix *pix;
231 while ((pix=(MCalibrationPix*)Next()))
232 {
233 if (pix->FitCharge())
234 nsuccess++;
235 }
236 }
237 else // fit only the pixel with index i
238 {
239 if((*this)[i].FitCharge())
240 nsuccess++;
241 }
242
243 return nsuccess;
244
245}
246
247//
248// Perform the fits of the charges of all pixels
249// plus the blind pixel and the PIN Diode
250//
251// The number of succesful fits is returned
252//
253UShort_t MCalibrationCam::FitAllCharge()
254{
255
256 // FIXME: Once the blind pixel is fully working,
257 // there must be some penalty in case the
258 // fit does not succeed
259 //
260 UShort_t nsuccess = 0;
261
262 TIter Next(fPixels);
263 MCalibrationPix *pix;
264 while ((pix=(MCalibrationPix*)Next()))
265 {
266 if (pix->FitCharge())
267 nsuccess++;
268 }
269
270 if (fBlindPixel->FitCharge())
271 nsuccess++;
272
273 if (fPINDiode->FitCharge())
274 nsuccess++;
275
276 return nsuccess;
277
278}
279
280
281
282//
283// Perform the fits of the arrival times
284// If i=-1, then all pixels will be fitted
285// Otherwise only the one with index i
286//
287// The number of succesful fits is returned
288//
289UShort_t MCalibrationCam::FitTime(Int_t i)
290{
291
292 UShort_t nsuccess = 0;
293
294 // invalidate i if it exceeds the number of entries in fPixels
295 if (i > fPixels->GetEntriesFast())
296 {
297 *fLog << warn << "Tried to fit pixel out of allowed range " << endl;
298 return 0;
299 }
300
301 if (i == -1) // loop over all events
302 {
303
304 TIter Next(fPixels);
305 MCalibrationPix *pix;
306 while ((pix=(MCalibrationPix*)Next()))
307 {
308 if (pix->FitTime())
309 nsuccess++;
310 }
311 }
312 else // fit only the pixel with index i
313 {
314 if((*this)[i].FitTime())
315 nsuccess++;
316 }
317
318 return nsuccess;
319
320}
321
322
323//
324// Perform the fits of the times of all pixels
325// plus the blind pixel and the PIN Diode
326//
327// The number of succesful fits is returned
328//
329UShort_t MCalibrationCam::FitAllTime()
330{
331
332 // FIXME: Once the blind pixel is fully working,
333 // there must be some penalty in case the
334 // fit does not succeed
335 //
336 UShort_t nsuccess = 0;
337
338 TIter Next(fPixels);
339 MCalibrationPix *pix;
340 while ((pix=(MCalibrationPix*)Next()))
341 {
342 if (pix->FitTime())
343 nsuccess++;
344 }
345
346 if (fBlindPixel->FitTime())
347 nsuccess++;
348
349 if (fPINDiode->FitTime())
350 nsuccess++;
351
352 return nsuccess;
353
354}
355
356
357
358void MCalibrationCam::CutEdges()
359{
360
361 fBlindPixel->GetHist()->CutAllEdges();
362
363 TIter Next(fPixels);
364 MCalibrationPix *pix;
365 while ((pix=(MCalibrationPix*)Next()))
366 {
367 pix->GetHist()->CutAllEdges();
368 }
369
370 return;
371}
372
373// ---------------------------------------------------------------------
374//
375// This function simply allocates memory via the ROOT command:
376// (TObject**) TStorage::ReAlloc(fCont, newSize * sizeof(TObject*),
377// fSize * sizeof(TObject*));
378// newSize corresponds to size in our case
379// fSize is the old size (in most cases: 0)
380//
381void MCalibrationCam::InitSize(Int_t size)
382{
383
384 //
385 // check if we have already initialized to size
386 //
387 if (CheckBounds(size))
388 return;
389
390 //
391 // It is important to use Expand and NOT ExpandCreate, because
392 // we want to keep all pixel not used with a NULL pointer.
393 //
394 fPixels->ExpandCreate(size);
395
396}
397
398void MCalibrationCam::Print(Option_t *o) const
399{
400 *fLog << all << GetDescriptor() << ":" << endl;
401 int id = 0;
402
403 *fLog << "Succesfully calibrated pixels:" << endl;
404 *fLog << endl;
405
406 TIter Next(fPixels);
407 MCalibrationPix *pix;
408 while ((pix=(MCalibrationPix*)Next()))
409 {
410
411 if (pix->GetCharge() >= 0.)
412 {
413 *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms()
414 << " Reduced Charge: " << pix->GetCharge() << " +- "
415 << pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
416 id++;
417 }
418 }
419
420 *fLog << id << " succesful pixels :-))" << endl;
421 id = 0;
422
423 *fLog << endl;
424 *fLog << "Pixels with errors:" << endl;
425 *fLog << endl;
426
427 TIter Next2(fPixels);
428 while ((pix=(MCalibrationPix*)Next2()))
429 {
430
431 if (pix->GetCharge() == -1.)
432 {
433 *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms()
434 << " Reduced Charge: " << pix->GetCharge() << " +- "
435 << pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
436 id++;
437 }
438 }
439 *fLog << id << " pixels with errors :-((" << endl;
440
441}
442
443
444Bool_t MCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
445{
446
447 if (idx > GetSize())
448 return kFALSE;
449
450 switch (type)
451 {
452 case 0:
453 val = (*this)[idx].GetCharge();
454 break;
455 case 1:
456 val = (*this)[idx].GetErrCharge();
457 break;
458 case 2:
459 val = (*this)[idx].GetSigmaCharge();
460 break;
461 case 3:
462 val = (*this)[idx].GetErrSigmaCharge();
463 break;
464 case 4:
465 val = (*this)[idx].GetChargeProb();
466 break;
467 case 5:
468 val = (*this)[idx].GetTime();
469 break;
470 case 6:
471 val = (*this)[idx].GetSigmaTime();
472 break;
473 case 7:
474 val = (*this)[idx].GetTimeChiSquare();
475 break;
476 case 8:
477 val = (*this)[idx].GetPed();
478 break;
479 case 9:
480 val = (*this)[idx].GetPedRms();
481 break;
482 case 10:
483 if ((*this)[idx].GetRSigmaSquare() > 0.)
484 val = TMath::Sqrt((*this)[idx].GetRSigmaSquare());
485 else
486 val = -1.;
487 break;
488 case 15:
489 val = ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge())*
490 ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge());
491 break;
492 case 11:
493 val = (*this)[idx].GetPheFFactorMethod();
494 break;
495 case 12:
496 val = (*this)[idx].GetConversionFFactorMethod();
497 break;
498 case 13:
499 if (idx < 397)
500 val = (double)fMeanNrPhotInnerPix;
501 else
502 val = (double)fMeanNrPhotInnerPix*gkCalibrationOuterPixelArea;
503 break;
504 case 14:
505 if ((fMeanNrPhotInnerPix > 0. ) && ((*this)[idx].GetCharge() != -1.))
506 {
507 if (idx < 397)
508 val = fMeanNrPhotInnerPix / (*this)[idx].GetCharge();
509 else
510 val = fMeanNrPhotInnerPix*gkCalibrationOuterPixelArea / (*this)[idx].GetCharge();
511 }
512 else
513 {
514 val = -1.;
515 }
516 break;
517 default:
518 return kFALSE;
519 }
520 return val>=0;
521}
522
523void MCalibrationCam::DrawPixelContent(Int_t idx) const
524{
525
526 (*this)[idx].Draw();
527
528}
529
530Bool_t MCalibrationCam::CalcNrPhotInnerPixel()
531{
532
533 if (!fBlindPixel->IsFitOK())
534 return kFALSE;
535
536 const Float_t mean = fBlindPixel->GetLambda();
537 // const Float_t merr = fBlindPixel->GetErrLambda();
538
539 switch (fColor)
540 {
541 case kECGreen:
542 fMeanNrPhotInnerPix = (mean / gkCalibrationBlindPixelQEGreen) // real photons
543 *TMath::Power(10,gkCalibrationBlindPixelAttGreen) // correct for absorption
544 / gkCalibrationBlindPixelArea; // correct for area
545 break;
546 case kECBlue:
547 fMeanNrPhotInnerPix = (mean / gkCalibrationBlindPixelQEBlue )
548 *TMath::Power(10,gkCalibrationBlindPixelAttBlue)
549 / gkCalibrationBlindPixelArea;
550 break;
551 case kECUV:
552 fMeanNrPhotInnerPix = (mean / gkCalibrationBlindPixelQEUV )
553 *TMath::Power(10,gkCalibrationBlindPixelAttUV)
554 / gkCalibrationBlindPixelArea;
555 break;
556 case kECCT1:
557 default:
558 fMeanNrPhotInnerPix = (mean / gkCalibrationBlindPixelQECT1 )
559 *TMath::Power(10,gkCalibrationBlindPixelAttCT1)
560 / gkCalibrationBlindPixelArea;
561 break;
562 }
563
564 fMeanNrPhotAvailable = kTRUE;
565
566 TIter Next(fPixels);
567 MCalibrationPix *pix;
568 while ((pix=(MCalibrationPix*)Next()))
569 {
570
571 if((pix->GetCharge() > 0.) && (fMeanNrPhotInnerPix > 0.))
572 pix->SetConversionBlindPixelMethod(fMeanNrPhotInnerPix/pix->GetCharge(), 0., 0.);
573 }
574 return kTRUE;
575}
576
577
578Bool_t MCalibrationCam::GetConversionFactorBlindPixel(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
579{
580
581 if (ipx < 0 || !IsPixelFitted(ipx))
582 return kFALSE;
583
584 if (!fMeanNrPhotAvailable)
585 if (!CalcNrPhotInnerPixel())
586 return kFALSE;
587
588 mean = (*this)[ipx].GetMeanConversionBlindPixelMethod();
589 err = (*this)[ipx].GetErrorConversionBlindPixelMethod();
590 sigma = (*this)[ipx].GetSigmaConversionBlindPixelMethod();
591
592 return kTRUE;
593}
594
595
596Bool_t MCalibrationCam::GetConversionFactorFFactor(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
597{
598
599 if (ipx < 0 || !IsPixelFitted(ipx))
600 return kFALSE;
601
602 Float_t conv = (*this)[ipx].GetConversionFFactorMethod();
603
604 if (conv < 0.)
605 return kFALSE;
606
607 mean = conv;
608
609 //
610 // Not yet ready , sorry
611 //
612 err = -1.;
613 sigma = -1.;
614
615 return kTRUE;
616}
617
618
619Bool_t MCalibrationCam::GetConversionFactorPINDiode(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
620{
621
622 return kTRUE;
623
624}
625
626Bool_t MCalibrationCam::GetConversionFactorCombined(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
627{
628
629 return kTRUE;
630
631}
Note: See TracBrowser for help on using the repository browser.