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

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