source: trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc@ 3308

Last change on this file since 3308 was 3283, checked in by gaug, 21 years ago
*** empty log message ***
File size: 11.2 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!
19! Author(s): Markus Gaug 02/2004 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHCalibrationChargeCam
29//
30// Contains a list of MHCalibrationPix
31// plus the MHCalibrationBlindPix
32// and the MHCalibrationPINDiode
33/////////////////////////////////////////////////////////////////////////////
34#include "MHCalibrationChargeCam.h"
35
36#include "MLog.h"
37#include "MLogManip.h"
38
39#include "MParList.h"
40
41#include "MHCalibrationChargeHiGainPix.h"
42#include "MHCalibrationChargeLoGainPix.h"
43
44#include "MCalibrationChargeCam.h"
45#include "MCalibrationChargePix.h"
46
47#include "MRawEvtData.h"
48#include "MRawEvtPixelIter.h"
49
50#include "MExtractedSignalCam.h"
51#include "MExtractedSignalPix.h"
52
53ClassImp(MHCalibrationChargeCam);
54
55using namespace std;
56
57const Float_t MHCalibrationChargeCam::fgNumHiGainSaturationLimit = 0.01;
58const Float_t MHCalibrationChargeCam::fgNumLoGainSaturationLimit = 0.01;
59//
60//
61//
62MHCalibrationChargeCam::MHCalibrationChargeCam(const char *name, const char *title)
63{
64 fName = name ? name : "MHCalibrationChargeCam";
65 fTitle = title ? title : "";
66
67 fHiGainArray = new TObjArray;
68 fHiGainArray->SetOwner();
69
70 fLoGainArray = new TObjArray;
71 fLoGainArray->SetOwner();
72
73 SetNumHiGainSaturationLimit();
74 SetNumLoGainSaturationLimit();
75}
76
77// --------------------------------------------------------------------------
78//
79// Delete the TClonesArray of MHCalibrationChargePix containers
80// Delete the MHCalibrationPINDiode and the MHCalibrationBlindPix
81//
82// Delete the histograms if they exist
83//
84MHCalibrationChargeCam::~MHCalibrationChargeCam()
85{
86 delete fHiGainArray;
87 delete fLoGainArray;
88}
89
90// --------------------------------------------------------------------------
91//
92// Get i-th pixel (pixel number)
93//
94MHCalibrationChargeHiGainPix &MHCalibrationChargeCam::operator[](UInt_t i)
95{
96 return *static_cast<MHCalibrationChargeHiGainPix*>(fHiGainArray->UncheckedAt(i));
97}
98
99// --------------------------------------------------------------------------
100//
101// Get i-th pixel (pixel number)
102//
103const MHCalibrationChargeHiGainPix &MHCalibrationChargeCam::operator[](UInt_t i) const
104{
105 return *static_cast<MHCalibrationChargeHiGainPix*>(fHiGainArray->UncheckedAt(i));
106}
107
108// --------------------------------------------------------------------------
109//
110// Get i-th pixel (pixel number)
111//
112MHCalibrationChargeLoGainPix &MHCalibrationChargeCam::operator()(UInt_t i)
113{
114 return *static_cast<MHCalibrationChargeLoGainPix*>(fLoGainArray->UncheckedAt(i));
115}
116
117// --------------------------------------------------------------------------
118//
119// Get i-th pixel (pixel number)
120//
121const MHCalibrationChargeLoGainPix &MHCalibrationChargeCam::operator()(UInt_t i) const
122{
123 return *static_cast<MHCalibrationChargeLoGainPix*>(fLoGainArray->UncheckedAt(i));
124}
125
126// --------------------------------------------------------------------------
127//
128// Our own clone function is necessary since root 3.01/06 or Mars 0.4
129// I don't know the reason
130//
131TObject *MHCalibrationChargeCam::Clone(const char *) const
132{
133 const Int_t nhi = fHiGainArray->GetSize();
134 const Int_t nlo = fLoGainArray->GetSize();
135
136 //
137 // FIXME, this might be done faster and more elegant, by direct copy.
138 //
139 MHCalibrationChargeCam *cam = new MHCalibrationChargeCam;
140
141 cam->fHiGainArray->Expand(nhi);
142 cam->fLoGainArray->Expand(nlo);
143
144 for (int i=0; i<nhi; i++)
145 {
146 delete (*cam->fHiGainArray)[i];
147 (*cam->fHiGainArray)[i] = (*fHiGainArray)[i]->Clone();
148 }
149 for (int i=0; i<nlo; i++)
150 {
151 delete (*cam->fLoGainArray)[i];
152 (*cam->fLoGainArray)[i] = (*fLoGainArray)[i]->Clone();
153 }
154 return cam;
155}
156
157// --------------------------------------------------------------------------
158//
159// To setup the object we get the number of pixels from a MGeomCam object
160// in the Parameter list.
161//
162Bool_t MHCalibrationChargeCam::SetupFill(const MParList *pList)
163{
164
165 fHiGainArray->Delete();
166 fLoGainArray->Delete();
167 return kTRUE;
168
169}
170
171Bool_t MHCalibrationChargeCam::ReInit(MParList *pList)
172{
173
174 fCam = (MCalibrationChargeCam*)pList->FindCreateObj("MCalibrationChargeCam");
175 if (!fCam)
176 {
177 gLog << err << GetDescriptor() << ": ERROR: Could not find MCalibrationChargeCam ... aborting " << endl;
178 return kFALSE;
179 }
180
181 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
182 if (!fRawEvt)
183 {
184 gLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
185 return kFALSE;
186 }
187
188 MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
189 if (!signal)
190 {
191 gLog << err << "No argument in MExtractedSignalCam::ReInit... abort." << endl;
192 return kFALSE;
193 }
194
195 const Int_t n = signal->GetSize();
196
197 fHiGainArray->Expand(n);
198
199 for (Int_t i=0; i<n; i++)
200 {
201 (*fHiGainArray)[i] = new MHCalibrationChargeHiGainPix;
202 (*this)[i].Init();
203 (*this)[i].ChangeHistId(i);
204
205 }
206
207 fLoGainArray->Expand(n);
208
209 for (Int_t i=0; i<n; i++)
210 {
211 (*fLoGainArray)[i] = new MHCalibrationChargeLoGainPix;
212 (*this)(i).Init();
213 (*this)(i).ChangeHistId(i);
214 }
215
216 return kTRUE;
217}
218
219
220// --------------------------------------------------------------------------
221Bool_t MHCalibrationChargeCam::Fill(const MParContainer *par, const Stat_t w)
222{
223
224 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
225 if (!signal)
226 {
227 gLog << err << "No argument in MExtractedSignalCam::Fill... abort." << endl;
228 return kFALSE;
229 }
230
231 const Int_t n = signal->GetSize();
232
233 if (fHiGainArray->GetEntries() != n)
234 {
235 gLog << err << "ERROR - Size mismatch... abort." << endl;
236 return kFALSE;
237 }
238
239 if (fLoGainArray->GetEntries() != n)
240 {
241 gLog << err << "ERROR - Size mismatch... abort." << endl;
242 return kFALSE;
243 }
244
245 for (int i=0; i<n; i++)
246 {
247 const MExtractedSignalPix &pix = (*signal)[i];
248
249 const Float_t sumhi = pix.GetExtractedSignalHiGain();
250 const Float_t sumlo = pix.GetExtractedSignalLoGain();
251
252 (*this)[i].FillHistAndArray(sumhi);
253 (*this)(i).FillHistAndArray(sumlo);
254
255 (*this)[i].SetSaturated((Int_t)pix.GetNumHiGainSaturated());
256 (*this)(i).SetSaturated((Int_t)pix.GetNumLoGainSaturated());
257 }
258
259 MRawEvtPixelIter pixel(fRawEvt);
260
261 while (pixel.Next())
262 {
263
264 const UInt_t pixid = pixel.GetPixelId();
265
266 const Float_t timehi = (Float_t)pixel.GetIdxMaxHiGainSample();
267 const Float_t timelo = (Float_t)pixel.GetIdxMaxLoGainSample();
268
269 (*this)[pixid].FillAbsTime(timehi);
270 (*this)(pixid).FillAbsTime(timelo);
271
272 }
273
274 return kTRUE;
275}
276
277// --------------------------------------------------------------------------
278//
279// 1) Return if the charge distribution is already succesfully fitted
280// or if the histogram is empty
281// 2) Fit the histograms with a Gaussian
282// 3) In case of failure set the bit kFitted to false and take histogram means and RMS
283// 4) Check for pickup noise
284// 5) Check the fourier spectrum
285// 5) Retrieve the results and store them in this class
286//
287Bool_t MHCalibrationChargeCam::Finalize()
288{
289
290 for (int i=0; i<fHiGainArray->GetSize(); i++)
291 {
292
293 MHCalibrationChargeHiGainPix &pixhi = (*this)[i];
294 MCalibrationChargePix &pix = (*fCam)[i];
295
296 if (pixhi.IsEmpty())
297 continue;
298
299 if (pixhi.GetSaturated() > fNumHiGainSaturationLimit*pixhi.GetHGausHist()->GetEntries())
300 {
301 pix.SetHiGainSaturation();
302 continue;
303 }
304
305 //
306 // 2) Fit the Hi Gain histograms with a Gaussian
307 //
308 if (pixhi.FitGaus())
309 pix.SetHiGainFitted();
310 //
311 // 3) In case of failure set the bit kFitted to false and take histogram means and RMS
312 //
313 else if (pixhi.RepeatFit())
314 pix.SetHiGainFitted();
315 else
316 pixhi.BypassFit();
317
318 //
319 // 4) Check for pickup
320 //
321 pixhi.CountPickup();
322
323 //
324 // 5) Check for oscillations
325 //
326 pixhi.CreateFourierSpectrum();
327
328 //
329 // 6) Retrieve the results and store them in this class
330 //
331 pix.SetHiGainMeanCharge( pixhi.GetMean() );
332 pix.SetHiGainMeanChargeErr( pixhi.GetMeanErr() );
333 pix.SetHiGainSigmaCharge( pixhi.GetSigma() );
334 pix.SetHiGainSigmaChargeErr( pixhi.GetSigmaErr() );
335 pix.SetHiGainChargeProb ( pixhi.GetProb() );
336
337 pix.SetAbsTimeMean ( pixhi.GetAbsTimeMean());
338 pix.SetAbsTimeRms ( pixhi.GetAbsTimeRms() );
339
340 pix.SetHiGainOscillating ( !pixhi.IsFourierSpectrumOK() );
341 pix.SetHiGainNumPickup ( pixhi.GetPickup() );
342 }
343
344 for (int i=0; i<fLoGainArray->GetSize(); i++)
345 {
346
347 MHCalibrationChargeLoGainPix &pixlo = (*this)(i);
348 MCalibrationChargePix &pix = (*fCam)[i];
349
350 if (pixlo.IsEmpty())
351 continue;
352
353 if (pixlo.GetSaturated() > fNumHiGainSaturationLimit*pixlo.GetHGausHist()->GetEntries())
354 {
355 pix.SetLoGainSaturation();
356 continue;
357 }
358 //
359 // 2) Fit the Lo Gain histograms with a Gaussian
360 //
361 if (pixlo.FitGaus())
362 pix.SetLoGainFitted();
363 //
364 // 3) In case of failure set the bit kFitted to false and take histogram means and RMS
365 //
366 else if (pixlo.RepeatFit())
367 pix.SetLoGainFitted();
368 else
369 pixlo.BypassFit();
370
371 //
372 // 4) Check for pickup
373 //
374 pixlo.CountPickup();
375
376 //
377 // 5) Check for oscillations
378 //
379 pixlo.CreateFourierSpectrum();
380
381 //
382 // 6) Retrieve the results and store them in this class
383 //
384 pix.SetLoGainMeanCharge( pixlo.GetMean() );
385 pix.SetLoGainMeanChargeErr( pixlo.GetMeanErr() );
386 pix.SetLoGainSigmaCharge( pixlo.GetSigma() );
387 pix.SetLoGainSigmaChargeErr( pixlo.GetSigmaErr() );
388 pix.SetLoGainChargeProb ( pixlo.GetProb() );
389
390 if (pix.IsHiGainSaturation())
391 {
392 pix.SetAbsTimeMean ( pixlo.GetAbsTimeMean());
393 pix.SetAbsTimeRms ( pixlo.GetAbsTimeRms() );
394 }
395
396 pix.SetLoGainOscillating ( !pixlo.IsFourierSpectrumOK() );
397 pix.SetLoGainNumPickup ( pixlo.GetPickup() );
398
399 }
400
401 return kTRUE;
402}
403
404Bool_t MHCalibrationChargeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
405{
406 return kTRUE;
407}
408
409// --------------------------------------------------------------------------
410//
411// What MHCamera needs in order to draw an individual pixel in the camera
412//
413void MHCalibrationChargeCam::DrawPixelContent(Int_t idx) const
414{
415 (*this)[idx].DrawClone();
416}
417
Note: See TracBrowser for help on using the repository browser.