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

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