source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.cc@ 6329

Last change on this file since 6329 was 5864, checked in by gaug, 20 years ago
*** empty log message ***
File size: 15.3 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 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24/////////////////////////////////////////////////////////////////////////////
25//
26// MHCalibrationChargeBlindCam
27//
28// Histogram class for blind pixels in the camera. Incorporates the TObjArray's:
29// - fBlindPixelsArray (for calibrated High Gains per pixel)
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MHCalibrationChargeBlindCam.h"
33
34#include <TVirtualPad.h>
35#include <TCanvas.h>
36#include <TPad.h>
37#include <TOrdCollection.h>
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42#include "MRawEvtData.h"
43#include "MRawEvtPixelIter.h"
44
45#include "MExtractedSignalBlindPixel.h"
46
47#include "MCalibrationBlindPix.h"
48#include "MCalibrationIntensityBlindCam.h"
49
50#include "MParList.h"
51
52#include "MRawRunHeader.h"
53
54ClassImp(MHCalibrationChargeBlindCam);
55
56using namespace std;
57const Int_t MHCalibrationChargeBlindCam::fgNbins = 128;
58const Axis_t MHCalibrationChargeBlindCam::fgFirst = -0.5;
59const Axis_t MHCalibrationChargeBlindCam::fgLast = 511.5;
60const Axis_t MHCalibrationChargeBlindCam::fgSPheCut = 20.;
61const TString MHCalibrationChargeBlindCam::gsHistName = "ChargeBlind";
62const TString MHCalibrationChargeBlindCam::gsHistTitle = "Signals Blind";
63const TString MHCalibrationChargeBlindCam::gsHistXTitle = "Signal [FADC counts]";
64const TString MHCalibrationChargeBlindCam::gsHistYTitle = "Nr. events";
65// --------------------------------------------------------------------------
66//
67// Default Constructor.
68//
69// Sets:
70// - all pointers to NULL
71//
72// - fFitFunc to kEPoisson4
73// - fNbins to fgNbins
74// - fFirst to fgFirst
75// - fLast to fgLast
76// - fSPheCut to fgSPheCut
77//
78// - fHistName to gsHistName
79// - fHistTitle to gsHistTitle
80// - fHistXTitle to gsHistXTitle
81// - fHistYTitle to gsHistYTitle
82//
83// - SetAverageing (kFALSE);
84// - SetLoGain (kFALSE);
85// - SetOscillations(kFALSE);
86// - SetSizeCheck (kFALSE);
87//
88MHCalibrationChargeBlindCam::MHCalibrationChargeBlindCam(const char *name, const char *title)
89 : fRawEvt(NULL)
90{
91
92 fName = name ? name : "MHCalibrationChargeBlindCam";
93 fTitle = title ? title : "Class to fille the blind pixel histograms";
94
95 SetSPheCut();
96
97 SetNbins(fgNbins);
98 SetFirst(fgFirst);
99 SetLast (fgLast );
100
101 SetHistName (gsHistName .Data());
102 SetHistTitle (gsHistTitle .Data());
103 SetHistXTitle(gsHistXTitle.Data());
104 SetHistYTitle(gsHistYTitle.Data());
105
106 SetAverageing (kFALSE);
107 SetLoGain (kFALSE);
108 SetOscillations(kFALSE);
109 SetSizeCheck (kFALSE);
110
111 SetFitFunc(MHCalibrationChargeBlindPix::kEPoisson4);
112}
113
114// --------------------------------------------------------------------------
115//
116// Gets the pointers to:
117// - MRawEvtData
118//
119Bool_t MHCalibrationChargeBlindCam::SetupHists(const MParList *pList)
120{
121
122 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
123 if (!fRawEvt)
124 {
125 *fLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
126 return kFALSE;
127 }
128
129 return kTRUE;
130}
131
132// --------------------------------------------------------------------------
133//
134// Gets or creates the pointers to:
135// - MExtractedSignalBlindPixel
136// - MCalibrationChargeCam or MCalibrationIntensityBlindCam
137//
138// Initializes the number of used FADC slices from MExtractedSignalCam
139// into MCalibrationChargeCam and test for changes in that variable
140//
141// Retrieve:
142// - fRunHeader->GetNumSamplesHiGain();
143//
144// Initializes the High Gain Arrays:
145//
146// - Expand fHiGainArrays to nblindpixels
147//
148// - For every entry in the expanded arrays:
149// * Initialize an MHCalibrationPix
150// * Set Binning from fNbins, fFirst and fLast
151// * Set Histgram names and titles from fHistName and fHistTitle
152// * Set X-axis and Y-axis titles from fHistXTitle and fHistYTitle
153// * Call InitHists
154//
155Bool_t MHCalibrationChargeBlindCam::ReInitHists(MParList *pList)
156{
157
158 if (!InitCams(pList,"Blind"))
159 return kFALSE;
160
161 MExtractedSignalBlindPixel *signal =
162 (MExtractedSignalBlindPixel*)pList->FindObject(AddSerialNumber("MExtractedSignalBlindPixel"));
163 if (!signal)
164 {
165 *fLog << err << "MExtractedSignalBlindPixel not found... abort." << endl;
166 return kFALSE;
167 }
168
169 const Int_t nblindpixels = signal->GetNumBlindPixels();
170 const Int_t samples = signal->GetNumFADCSamples();
171 const Int_t integ = signal->IsExtractionType( MExtractBlindPixel::kIntegral );
172
173 if (fHiGainArray->GetSize()==0)
174 {
175 for (Int_t i=0; i<nblindpixels; i++)
176 {
177 fHiGainArray->AddAt(new MHCalibrationChargeBlindPix(Form("%s%s%d",fHistName.Data(),"Pix",i),
178 Form("%s%s%d",fHistTitle.Data()," Pixel ",i)),i);
179
180 MHCalibrationChargeBlindPix &pix = (MHCalibrationChargeBlindPix&)(*this)[i];
181
182 pix.SetNbins ( fNbins );
183 pix.SetFirst ( fFirst );
184 pix.SetLast ( integ ? ((fLast+0.5)*samples)-0.5 : fLast );
185 pix.SetSinglePheCut ( integ ? fSPheCut * samples : fSPheCut );
186 pix.SetFitFunc ( integ ? MHCalibrationChargeBlindPix::kEPoisson5 : fFitFunc );
187
188 pix.InitBins();
189
190 }
191 }
192 return kTRUE;
193}
194
195// --------------------------------------------------------------------------
196//
197// Resets the histogram titles for each entry in:
198// - fHiGainArray
199//
200void MHCalibrationChargeBlindCam::ResetHistTitles()
201{
202
203 TH1F *h;
204
205 if (fHiGainArray)
206 for (Int_t i=0;i<fHiGainArray->GetSize(); i++)
207 {
208 MHCalibrationPix &pix = (*this)[i];
209 h = pix.GetHGausHist();
210 h->SetName (Form("%s%s%s%d","H",fHistName.Data(),"Pix",i));
211 h->SetTitle(Form("%s%s%d%s",fHistTitle.Data()," Pixel ",i," Runs: "));
212 h->SetXTitle(fHistXTitle.Data());
213 h->SetYTitle(fHistYTitle.Data());
214 }
215}
216
217// --------------------------------------------------------------------------
218//
219// Retrieves from MExtractedSignalBlindPixel:
220// - number of blind pixels
221//
222// Retrieves from MExtractedSignalBlindPixel:
223// - number of FADC samples
224// - extracted signal
225// - blind Pixel ID
226//
227// Resizes (if necessary):
228// - fASinglePheFADCSlices to sum of HiGain and LoGain samples
229// - fAPedestalFADCSlices to sum of HiGain and LoGain samples
230//
231// Fills the following histograms:
232// - MHGausEvents::FillHistAndArray(signal)
233//
234// Creates MRawEvtPixelIter, jumps to blind pixel ID,
235// fills the vectors fASinglePheFADCSlices and fAPedestalFADCSlices
236// with the full FADC slices, depending on the size of the signal w.r.t. fSinglePheCut
237//
238Bool_t MHCalibrationChargeBlindCam::FillHists(const MParContainer *par, const Stat_t w)
239{
240
241 MExtractedSignalBlindPixel *signal = (MExtractedSignalBlindPixel*)par;
242 if (!signal)
243 {
244 *fLog << err << "No argument in MExtractedSignalBlindCam::Fill... abort." << endl;
245 return kFALSE;
246 }
247
248 const Int_t nblindpixels = signal->GetNumBlindPixels();
249
250 if (GetSize() != nblindpixels)
251 {
252 gLog << err << "ERROR - Size mismatch... abort." << endl;
253 return kFALSE;
254 }
255
256 Float_t slices = (Float_t)signal->GetNumFADCSamples();
257
258 if (slices == 0.)
259 {
260 *fLog << err << dbginf
261 << "Number of used signal slices in MExtractedSignalBlindPix "
262 << "is zero ... abort."
263 << endl;
264 return kFALSE;
265 }
266
267 for (Int_t i=0; i<nblindpixels; i++)
268 {
269
270 //
271 // Signal extraction and histogram filling
272 // If filter has been applied, sig has been set to -1.
273 //
274 const Float_t sig = signal->GetExtractedSignal(i);
275
276 if (sig < -0.5)
277 continue;
278
279 MHCalibrationChargeBlindPix &hist = (MHCalibrationChargeBlindPix&)(*this)[i];
280
281 hist.FillHist(sig);
282 //
283 // In order to study the single-phe posistion, we extract the slices
284 //
285 const Int_t blindpixIdx = signal->GetBlindPixelIdx(i);
286
287 MRawEvtPixelIter pixel(fRawEvt);
288 pixel.Jump(blindpixIdx);
289
290 if (sig > fSPheCut)
291 hist.FillSinglePheFADCSlices(pixel);
292 else
293 hist.FillPedestalFADCSlices(pixel);
294
295 }
296
297 return kTRUE;
298}
299
300// --------------------------------------------------------------------------
301//
302// For all TObjArray's (including the averaged ones), the following steps are performed:
303//
304// 1) Returns if the pixel is excluded.
305// 2) Tests saturation. In case yes, set the flag: MCalibrationPix::SetHiGainSaturation()
306// or the flag: MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainSaturated )
307// 3) Store the absolute arrival times in the MCalibrationChargePix's. If flag
308// MCalibrationPix::IsHiGainSaturation() is set, the Low-Gain arrival times are stored,
309// otherwise the Hi-Gain ones.
310// 4) Calls to MHCalibrationCam::FitHiGainArrays() and MCalibrationCam::FitLoGainArrays()
311// with the flags:
312// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainNotFitted )
313// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainNotFitted )
314// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainOscillating )
315// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainOscillating )
316//
317Bool_t MHCalibrationChargeBlindCam::FinalizeHists()
318{
319
320 *fLog << endl;
321
322 MCalibrationCam *blindcam = fIntensCam ? fIntensCam->GetCam() : fCam;
323
324 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
325 {
326 MHCalibrationChargeBlindPix &hist = (MHCalibrationChargeBlindPix&)(*this)[i];
327
328 TH1F *h = hist.GetHGausHist();
329
330 switch (fColor)
331 {
332 case MCalibrationCam::kNONE:
333 break;
334 case MCalibrationCam::kBLUE:
335 h->SetTitle( Form("%s%s", h->GetTitle(),"BLUE "));
336 break;
337 case MCalibrationCam::kGREEN:
338 h->SetTitle( Form("%s%s", h->GetTitle(),"GREEN "));
339 break;
340 case MCalibrationCam::kUV:
341 h->SetTitle( Form("%s%s", h->GetTitle(),"UV "));
342 break;
343 case MCalibrationCam::kCT1:
344 h->SetTitle( Form("%s%s", h->GetTitle(),"CT1-Pulser "));
345 break;
346 }
347
348 Stat_t overflow = h->GetBinContent(h->GetNbinsX()+1);
349 if (overflow > 0.1)
350 {
351 *fLog << warn << GetDescriptor()
352 << ": Histogram Overflow occurred " << overflow
353 << " times in blind pixel: " << i << endl;
354 }
355
356 overflow = h->GetBinContent(0);
357 if (overflow > 0.1)
358 {
359 *fLog << warn << GetDescriptor()
360 << ": Histogram Underflow occurred " << overflow
361 << " times in blind pixel: " << i << endl;
362 }
363
364 MCalibrationBlindPix &pix = (MCalibrationBlindPix&)(*blindcam)[i];
365
366 FitBlindPixel(hist,pix);
367 }
368
369 return kTRUE;
370}
371
372
373// --------------------------------------------------------------------------
374//
375// Returns kFALSE, if empty
376//
377// - Creates the fourier spectrum and sets bit MHGausEvents::IsFourierSpectrumOK()
378// - Retrieves the pedestals from MExtractedSignalBlindPixel
379// - Normalizes fASinglePheFADCSlices and fAPedestalFADCSlices
380// - Executes FitPedestal()
381// - Executes FitSinglePhe()
382// - Retrieves fit results and stores them in MCalibrationBlindPix
383//
384void MHCalibrationChargeBlindCam::FitBlindPixel(MHCalibrationChargeBlindPix &hist, MCalibrationBlindPix &pix)
385{
386
387 if (hist.IsEmpty())
388 {
389 *fLog << err << GetDescriptor() << " ID: " << hist.GetName()
390 << " My histogram has not been filled !! " << endl;
391 return;
392 }
393
394 hist.FinalizeSinglePheSpectrum();
395
396 hist.FitPedestal();
397
398 pix.SetValid(kTRUE);
399
400 if (hist.FitSinglePhe())
401 pix.SetSinglePheFitOK();
402 else
403 pix.SetValid(hist.IsPedestalFitOK());
404
405 pix.SetLambda ( hist.GetLambda () );
406 pix.SetLambdaVar ( hist.GetLambdaErr()*hist.GetLambdaErr() );
407 pix.SetMu0 ( hist.GetMu0 () );
408 pix.SetMu0Err ( hist.GetMu0Err () );
409 pix.SetMu1 ( hist.GetMu1 () );
410 pix.SetMu1Err ( hist.GetMu1Err () );
411 pix.SetSigma0 ( hist.GetSigma0 () );
412 pix.SetSigma0Err ( hist.GetSigma0Err() );
413 pix.SetSigma1 ( hist.GetSigma1 () );
414 pix.SetSigma1Err ( hist.GetSigma1Err() );
415 pix.SetProb ( hist.GetProb () );
416
417 pix.SetLambdaCheck ( hist.GetLambdaCheck() );
418 pix.SetLambdaCheckErr ( hist.GetLambdaCheckErr() );
419}
420
421// --------------------------------------------------------------------------
422//
423// This Clone-function has to be different from the MHCalibrationCam
424// Clone function since it does not store and display the averaged values
425// (in fAverageAreas), but the blind pixels stored in fHiGainArray.
426//
427// Creates new MHCalibrationChargeBlindCam and
428// Clones MHCalibrationChargeBlindPix's individually
429//
430#if 0
431TObject *MHCalibrationChargeBlindCam::Clone(const char *name) const
432{
433
434 MHCalibrationChargeBlindCam *cam = new MHCalibrationChargeBlindCam();
435
436 //
437 // Copy the data members
438 //
439 cam->fRunNumbers = fRunNumbers;
440 cam->fPulserFrequency = fPulserFrequency;
441 cam->fFlags = fFlags;
442 cam->fNbins = fNbins;
443 cam->fFirst = fFirst;
444 cam->fLast = fLast;
445 cam->fFitFunc = fFitFunc;
446
447 const Int_t nhi = fHiGainArray->GetSize();
448
449 for (int i=0; i<nhi; i++)
450 cam->fHiGainArray->AddAt((*this)[i].Clone(),i);
451
452 return cam;
453}
454#endif
455// -----------------------------------------------------------------------------
456//
457// Default draw:
458//
459// Displays the averaged areas, both High Gain and Low Gain
460//
461// Calls the Draw of the fAverageHiGainAreas and fAverageLoGainAreas objects with options
462//
463void MHCalibrationChargeBlindCam::Draw(Option_t *opt)
464{
465
466 const Int_t size = fHiGainArray->GetSize();
467
468 if (size == 0)
469 return;
470
471 TString option(opt);
472 option.ToLower();
473
474 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
475 pad->SetBorderMode(0);
476
477 switch (size)
478 {
479 case 1:
480 break;
481 case 2:
482 pad->Divide(2,1);
483 break;
484 case 3:
485 case 4:
486 pad->Divide(2,2);
487 break;
488 default:
489 pad->Divide(size/2+1,size/2+1);
490 break;
491 }
492
493 for (Int_t i=0; i<size;i++)
494 {
495 pad->cd(i+1);
496 (*this)[i].Draw(option);
497 }
498
499 pad->Modified();
500 pad->Update();
501
502}
503
504Int_t MHCalibrationChargeBlindCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
505{
506
507 Bool_t rc = kFALSE;
508
509 if (MHCalibrationCam::ReadEnv(env,prefix,print))
510 rc = kTRUE;
511
512 if (IsEnvDefined(env, prefix, "SPheCut", print))
513 {
514 SetSPheCut(GetEnvValue(env, prefix, "SPheCut", fSPheCut));
515 rc = kTRUE;
516 }
517
518 // FIXME: GetEnvValue does not work with enums yet
519 /*
520 if (IsEnvDefined(env, prefix, "FitFunc", print))
521 {
522 SetFitFunc((Int_t)GetEnvValue(env, prefix, "FitFunc", fFitFunc));
523 rc = kTRUE;
524 }
525 */
526 return rc;
527}
Note: See TracBrowser for help on using the repository browser.