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

Last change on this file since 2539 was 2538, checked in by gaug, 21 years ago
*** empty log message ***
File size: 12.4 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{
60 fName = name ? name : "MCalibrationCam";
61 fTitle = title ? title : "Storage container for the Calibration Information in the camera";
62
63 fPixels = new TClonesArray("MCalibrationPix",0);
64 fBlindPixel = new MCalibrationBlindPix();
65 fPINDiode = new MCalibrationPINDiode();
66}
67
68// --------------------------------------------------------------------------
69//
70// Delete the TClonesArray or MCalibrationPix's
71// Delete the MCalibrationPINDiode and the MCalibrationBlindPix
72//
73MCalibrationCam::~MCalibrationCam()
74{
75
76 //
77 // delete fPixels should delete all Objects stored inside
78 //
79 delete fPixels;
80 delete fBlindPixel;
81 delete fPINDiode;
82}
83
84// --------------------------------------------------------------------------
85//
86// This function return the size of the FILLED MCalibrationCam
87// It is NOT the size of the array fPixels !!!
88// Note that with every call to AddPixels, GetSize() might change
89//
90Int_t MCalibrationCam::GetSize() const
91{
92
93 //
94 // Here it is important to use GetEntriesFast,
95 // We get the array index of the last "filled" fPixel entry
96 // (Not 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
119Bool_t MCalibrationCam::AddPixel(Int_t idx)
120{
121
122 //
123 // Check bounds first
124 //
125 if (!CheckBounds(idx))
126 InitSize(idx);
127
128 //
129 // in case, new cannot allocate memory,
130 // return FALSE
131 //
132 return (new ((*fPixels)[idx]) MCalibrationPix(idx));
133
134}
135
136
137// --------------------------------------------------------------------------
138//
139// Return a pointer to the pixel with the requested idx.
140// NULL if it doesn't exist.
141//
142MCalibrationPix *MCalibrationCam::GetCalibrationPix(Int_t idx) const
143{
144 if (idx<0)
145 return NULL;
146
147 if (!CheckBounds(idx))
148 return NULL;
149
150// return (*this)[idx];
151 return (MCalibrationPix*)fPixels->At(idx);
152}
153
154
155
156// --------------------------------------------------------------------------
157//
158// Check if position i is inside bounds
159//
160Bool_t MCalibrationCam::CheckBounds(Int_t i) const
161{
162 return i < fPixels->GetEntriesFast();
163}
164
165Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const
166{
167 if (!CheckBounds(idx))
168 return kFALSE;
169
170 return (&(*this)[idx]);
171}
172
173Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const
174{
175 if (!IsPixelUsed(idx))
176 return kFALSE;
177
178 return ((*this)[idx].GetRQ() > 0. && (*this)[idx].GetErrRQ() > 0.);
179}
180
181
182
183void MCalibrationCam::Clear(Option_t *o)
184{
185 fPixels->ForEach(TObject, Clear)();
186}
187
188//
189// Perform the fits of the charges
190// If i=-1, then all pixels will be fitted
191// Otherwise only the one with index i
192//
193// The number of succesful fits is returned
194//
195UShort_t MCalibrationCam::FitQ(Int_t i)
196{
197
198 UShort_t nsuccess = 0;
199
200 // invalidate i if it exceeds the number of entries in fPixels
201 if (i > fPixels->GetEntriesFast())
202 {
203 *fLog << warn << "Tried to fit pixel out of allowed range " << endl;
204 return 0;
205 }
206
207 if (i == -1) // loop over all events
208 {
209
210 Int_t id = 0;
211
212 TIter Next(fPixels);
213 MCalibrationPix *pix;
214 while ((pix=(MCalibrationPix*)Next()))
215 {
216 if (!IsPixelUsed(id++))
217 continue;
218 if (pix->FitQ())
219 nsuccess++;
220 }
221 }
222 else // fit only the pixel with index i
223 {
224 if (!IsPixelUsed(i))
225 return 0;
226 if((*this)[i].FitQ())
227 nsuccess++;
228 }
229
230 return nsuccess;
231
232}
233
234//
235// Perform the fits of the charges of all pixels
236// plus the blind pixel and the PIN Diode
237//
238// The number of succesful fits is returned
239//
240UShort_t MCalibrationCam::FitAllQ()
241{
242
243 // FIXME: Once the blind pixel is fully working,
244 // there must be some penalty in case the
245 // fit does not succeed
246 //
247 UShort_t nsuccess = 0;
248
249 Int_t id = 0;
250
251 TIter Next(fPixels);
252 MCalibrationPix *pix;
253 while ((pix=(MCalibrationPix*)Next()))
254 {
255 if (!IsPixelUsed(id++))
256 continue;
257 if (pix->FitQ())
258 nsuccess++;
259 }
260
261 if (fBlindPixel->FitQ())
262 nsuccess++;
263
264 if (fPINDiode->FitQ())
265 nsuccess++;
266
267 return nsuccess;
268
269}
270
271
272
273//
274// Perform the fits of the arrival times
275// If i=-1, then all pixels will be fitted
276// Otherwise only the one with index i
277//
278// The number of succesful fits is returned
279//
280UShort_t MCalibrationCam::FitT(Int_t i)
281{
282
283 UShort_t nsuccess = 0;
284
285 // invalidate i if it exceeds the number of entries in fPixels
286 if (i > fPixels->GetEntriesFast())
287 {
288 *fLog << warn << "Tried to fit pixel out of allowed range " << endl;
289 return 0;
290 }
291
292 if (i == -1) // loop over all events
293 {
294
295 Int_t id = 0;
296
297 TIter Next(fPixels);
298 MCalibrationPix *pix;
299 while ((pix=(MCalibrationPix*)Next()))
300 {
301 if (!IsPixelUsed(id++))
302 continue;
303 if (pix->FitT())
304 nsuccess++;
305 }
306 }
307 else // fit only the pixel with index i
308 {
309 if((*this)[i].FitT())
310 nsuccess++;
311 }
312
313 return nsuccess;
314
315}
316
317
318//
319// Perform the fits of the times of all pixels
320// plus the blind pixel and the PIN Diode
321//
322// The number of succesful fits is returned
323//
324UShort_t MCalibrationCam::FitAllT()
325{
326
327 // FIXME: Once the blind pixel is fully working,
328 // there must be some penalty in case the
329 // fit does not succeed
330 //
331 UShort_t nsuccess = 0;
332
333 Int_t id = 0;
334
335 TIter Next(fPixels);
336 MCalibrationPix *pix;
337 while ((pix=(MCalibrationPix*)Next()))
338 {
339 if (!IsPixelUsed(id++))
340 continue;
341 if (pix->FitT())
342 nsuccess++;
343 }
344
345 if (fBlindPixel->FitT())
346 nsuccess++;
347
348 if (fPINDiode->FitT())
349 nsuccess++;
350
351 return nsuccess;
352
353}
354
355
356
357void MCalibrationCam::CutEdges()
358{
359
360 fBlindPixel->GetHist()->CutAllEdges();
361
362 TIter Next(fPixels);
363 MCalibrationPix *pix;
364 while ((pix=(MCalibrationPix*)Next()))
365 {
366 pix->GetHist()->CutAllEdges();
367 }
368
369 return;
370}
371
372// ---------------------------------------------------------------------
373//
374// This function simply allocates memory via the ROOT command:
375// (TObject**) TStorage::ReAlloc(fCont, newSize * sizeof(TObject*),
376// fSize * sizeof(TObject*));
377// newSize corresponds to size in our case
378// fSize is the old size (in most cases: 0)
379//
380void MCalibrationCam::InitSize(Int_t size)
381{
382
383 //
384 // check if we have already initialized to size
385 //
386 if (CheckBounds(size))
387 return;
388
389 //
390 // It is important to use Expand and NOT ExpandCreate, because
391 // we want to keep all pixel not used with a NULL pointer.
392 //
393 fPixels->Expand(size);
394 //
395 // Set all entries to the null pointer.
396 // Later we fill the array per pixId with the contruction: new (fPixels[i]) MCalibrationPix(pixid)
397 // To check, if pixels is already filled, we test the NULL pointer (see IsPixelUsed)
398 //
399 for (Int_t i=0; i< size; i++)
400 {
401 MCalibrationPix *pix = &(*this)[i];
402 pix = NULL;
403 }
404}
405
406void MCalibrationCam::Print(Option_t *o) const
407{
408 *fLog << all << GetDescriptor() << ":" << endl;
409 int id = 0;
410
411 TIter Next(fPixels);
412 MCalibrationPix *pix;
413 while ((pix=(MCalibrationPix*)Next()))
414 {
415 if (!IsPixelUsed(id))
416 continue;
417
418 *fLog << id << ": ";
419 *fLog << pix->GetQ() << " " << pix->GetRQ() << endl;
420
421 id++;
422 }
423}
424
425
426Bool_t MCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
427{
428
429 if (!IsPixelFitted(idx))
430 return kFALSE;
431
432 switch (type)
433 {
434 case 0:
435 val = (*this)[idx].GetQ();
436 break;
437 case 1:
438 val = (*this)[idx].GetErrQ();
439 break;
440 case 2:
441 val = (*this)[idx].GetSigmaQ();
442 break;
443 case 3:
444 val = (*this)[idx].GetErrSigmaQ();
445 break;
446 case 4:
447 val = (*this)[idx].GetQProb();
448 break;
449 case 5:
450 val = (*this)[idx].GetT();
451 break;
452 case 6:
453 val = (*this)[idx].GetErrT();
454 break;
455 case 7:
456 val = (*this)[idx].GetTProb();
457 break;
458 case 8:
459 val = (*this)[idx].GetPed();
460 break;
461 case 9:
462 val = (*this)[idx].GetPedRms();
463 break;
464 case 10:
465 val = (*this)[idx].GetRQ();
466 break;
467 case 11:
468 val = (*this)[idx].GetErrRQ();
469 break;
470 }
471 return val>=0;
472}
473
474void MCalibrationCam::DrawPixelContent(Int_t num) const
475{
476 *fLog << warn << "MCalibrationCam::DrawPixelContent - not available." << endl;
477}
478
479Bool_t MCalibrationCam::CalcNrPhotInnerPixel()
480{
481 if (!fBlindPixel->IsValid())
482 return kFALSE;
483
484 const Float_t mean = fBlindPixel->GetLambda();
485 // const Float_t merr = fBlindPixel->GetErrLambda();
486
487 switch (fColor)
488 {
489 case kECGreen:
490 fMeanNrPhotInnerPix = mean /
491 (gkCalibrationBlindPixelQEGreen
492 *TMath::Power(10,gkCalibrationBlindPixelAttGreen)
493 *gkCalibrationBlindPixelArea);
494 break;
495 case kECBlue:
496 fMeanNrPhotInnerPix = mean /
497 (gkCalibrationBlindPixelQEBlue
498 *TMath::Power(10,gkCalibrationBlindPixelAttBlue)
499 *gkCalibrationBlindPixelArea);
500 break;
501 case kECUV:
502 fMeanNrPhotInnerPix = mean /
503 (gkCalibrationBlindPixelQEUV
504 *TMath::Power(10,gkCalibrationBlindPixelAttUV)
505 *gkCalibrationBlindPixelArea);
506 break;
507 }
508
509 fMeanNrPhotAvailable = kTRUE;
510 return kTRUE;
511}
512
513
514
515Bool_t MCalibrationCam::GetConversionFactor(Int_t ipx, Float_t &mean, Float_t &err)
516{
517
518 if (ipx < 0 || !IsPixelFitted(ipx))
519 return kFALSE;
520
521 if (!fMeanNrPhotAvailable)
522 if (!CalcNrPhotInnerPixel())
523 return kFALSE;
524
525 mean = fMeanNrPhotInnerPix / (*this)[ipx].GetRQ();
526
527 //
528 // Not yet ready , sorry
529 //
530 err = 100000000000.;
531
532 return kTRUE;
533}
Note: See TracBrowser for help on using the repository browser.