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

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