source: trunk/MagicSoft/Mars/manalysis/MHPedestalCam.cc@ 3163

Last change on this file since 3163 was 3158, checked in by gaug, 21 years ago
*** empty log message ***
File size: 9.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! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
19! Markus Gaug 02/2004 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27// //
28// MHPedestalCam //
29// //
30// Hold the Pedestal information for all pixels in the camera //
31// //
32/////////////////////////////////////////////////////////////////////////////
33#include "MHPedestalCam.h"
34
35#include "MLog.h"
36#include "MLogManip.h"
37
38#include "MParList.h"
39
40#include "MHPedestalPix.h"
41
42#include "MExtractedSignalCam.h"
43#include "MExtractedSignalPix.h"
44
45#include "MPedestalCam.h"
46#include "MPedestalPix.h"
47
48ClassImp(MHPedestalCam);
49
50using namespace std;
51// --------------------------------------------------------------------------
52//
53// Default constructor. Creates a MHPedestalPix object for each pixel
54//
55MHPedestalCam::MHPedestalCam(const char *name, const char *title)
56 : fExtractSlices(0.)
57{
58 fName = name ? name : "MHPedestalCam";
59 fTitle = title ? title : "";
60
61 //
62 // loop over all Pixels and create two histograms
63 // one for the Low and one for the High gain
64 // connect all the histogram with the container fHist
65 //
66 fArray = new TObjArray;
67 fArray->SetOwner();
68
69}
70
71// --------------------------------------------------------------------------
72//
73// Delete the array conatining the pixel pedest information
74//
75MHPedestalCam::~MHPedestalCam()
76{
77 delete fArray;
78}
79
80// --------------------------------------------------------------------------
81//
82// Get i-th pixel (pixel number)
83//
84MHPedestalPix &MHPedestalCam::operator[](UInt_t i)
85{
86 return *(MHPedestalPix*)(fArray->At(i));
87}
88
89// --------------------------------------------------------------------------
90//
91// Get i-th pixel (pixel number)
92//
93const MHPedestalPix &MHPedestalCam::operator[](UInt_t i) const
94{
95 return *(MHPedestalPix*)(fArray->At(i));
96}
97
98
99// --------------------------------------------------------------------------
100//
101// Our own clone function is necessary since root 3.01/06 or Mars 0.4
102// I don't know the reason
103//
104TObject *MHPedestalCam::Clone(const char *) const
105{
106
107 const Int_t n = fArray->GetSize();
108
109 //
110 // FIXME, this might be done faster and more elegant, by direct copy.
111 //
112 MHPedestalCam *cam = new MHPedestalCam;
113
114 cam->fArray->Expand(n);
115
116 for (int i=0; i<n; i++)
117 {
118 delete (*cam->fArray)[i];
119 (*cam->fArray)[i] = (*fArray)[i]->Clone();
120 }
121
122 return cam;
123}
124
125
126
127// --------------------------------------------------------------------------
128//
129// To setup the object we get the number of pixels from a MGeomCam object
130// in the Parameter list.
131// MHPedestalPix sets its parameters to 0. (other than default which is -1.)
132//
133Bool_t MHPedestalCam::SetupFill(const MParList *pList)
134{
135
136 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
137
138 if (!fPedestals)
139 {
140 gLog << err << "Cannot find MPedestalCam ... abort." << endl;
141 return kFALSE;
142 }
143
144 fArray->Delete();
145 return kTRUE;
146
147}
148
149// --------------------------------------------------------------------------
150//
151Bool_t MHPedestalCam::Fill(const MParContainer *par, const Stat_t w)
152{
153
154 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
155 if (!signal)
156 {
157 gLog << err << "No argument in MExtractedSignalCam::Fill... abort." << endl;
158 return kFALSE;
159 }
160
161
162 Float_t slices = (Float_t)signal->GetNumUsedFADCSlices();
163
164 if (slices == 0.)
165 {
166 gLog << err << "Number of used signal slices in MExtractedSignalCam is zero ... abort."
167 << endl;
168 return kFALSE;
169 }
170
171 if (fExtractSlices != 0. && slices != fExtractSlices )
172 {
173 gLog << err << "Number of used signal slices changed in MExtractedSignalCam ... abort."
174 << endl;
175 return kFALSE;
176 }
177
178 fExtractSlices = slices;
179
180 const Int_t n = signal->GetSize();
181
182 if (fArray->GetEntries()==0)
183 {
184 fArray->Expand(n);
185
186 for (Int_t i=0; i<n; i++)
187 {
188 (*fArray)[i] = new MHPedestalPix;
189 MPedestalPix &pix = (*fPedestals)[i];
190 pix.InitUseHists();
191 MHPedestalPix &hist = (*this)[i];
192 hist.ChangeHistId(i);
193 hist.InitBins();
194 }
195 }
196
197 if (fArray->GetEntries() != n)
198 {
199 gLog << err << "ERROR - Size mismatch... abort." << endl;
200 return kFALSE;
201 }
202
203 for (Int_t i=0; i<n; i++)
204 {
205
206 const MExtractedSignalPix &pix = (*signal)[i];
207
208 const Float_t signal = pix.GetExtractedSignalHiGain();
209
210 MHPedestalPix &hist = (*this)[i];
211 //
212 // Don't fill signal per slice, we get completely screwed up
213 // with the sigma. Better fill like it is and renorm later
214 //
215 hist.FillHistAndArray(signal);
216 }
217
218 return kTRUE;
219}
220
221Bool_t MHPedestalCam::Finalize()
222{
223 for (Int_t i=0; i<fArray->GetSize(); i++)
224 {
225
226 MHPedestalPix &hist = (*this)[i];
227
228 //
229 // 1) Return if the charge distribution is already succesfully fitted
230 // or if the histogram is empty
231 //
232 if (hist.IsGausFitOK() || hist.IsEmpty())
233 continue;
234
235 //
236 // 2) Fit the Hi Gain histograms with a Gaussian
237 //
238 hist.FitGaus();
239 hist.Renorm(fExtractSlices);
240 hist.CreateFourierSpectrum();
241
242 }
243 return kTRUE;
244}
245
246// --------------------------------------------------------------------------
247//
248// The types are as follows:
249//
250// Fitted values:
251// ==============
252//
253// 0: Fitted Charge
254// 1: Error of fitted Charge
255// 2: Sigma of fitted Charge
256// 3: Error of Sigma of fitted Charge
257//
258//
259// Useful variables derived from the fit results:
260// =============================================
261//
262// 4: Returned probability of Gauss fit to Charge distribution
263// 5: Relative differenc of calculated pedestal (per slice) and fitted (per slice)
264// 6: Error of the Relative differenc of calculated pedestal (per slice) and fitted (per slice)
265// 7: Relative difference of the error of the mean pedestal (per slice) - calculated and fitted
266// 8: Relative differenc of calculated pedestal RMS (per slice) and fitted sigma (per slice)
267// 9: Error of Relative differenc of calculated pedestal RMS (per slice) and fitted sigma (per slice)
268// 10: Relative difference of the error of the pedestal RMS (per slice) - calculated and fitted
269//
270// Localized defects:
271// ==================
272//
273// 11: Gaus fit not OK
274// 12: Fourier spectrum not OK
275//
276Bool_t MHPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
277{
278
279 if (fArray->GetSize() <= idx)
280 return kFALSE;
281
282 if (!(*this)[idx].IsGausFitOK())
283 return kFALSE;
284
285 const Float_t ped = (*fPedestals)[idx].GetPedestal();
286 const Float_t rms = (*fPedestals)[idx].GetPedestalRms();
287
288 const Float_t entsqr = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
289
290 const Float_t pederr = rms/entsqr;
291 const Float_t rmserr = rms/entsqr/2.;
292
293 const Float_t mean = (*this)[idx].GetMean();
294 const Float_t meanerr = (*this)[idx].GetMeanErr();
295 const Float_t sigma = (*this)[idx].GetSigma() ;
296 const Float_t sigmaerr = (*this)[idx].GetSigmaErr();
297
298 switch (type)
299 {
300 case 0:
301 val = mean;
302 break;
303 case 1:
304 val = meanerr;
305 break;
306 case 2:
307 val = sigma;
308 break;
309 case 3:
310 val = sigmaerr;
311 break;
312 case 4:
313 val = (*this)[idx].GetProb();
314 break;
315 case 5:
316 val = 2.*(ped-mean)/(ped+mean);
317 break;
318 case 6:
319 val = TMath::Sqrt((pederr*pederr + meanerr*meanerr) * (ped*ped + mean*mean))
320 *2./(ped+mean)/(ped+mean);
321 break;
322 case 7:
323 val = 2.*(pederr - meanerr)/(pederr + meanerr);
324 break;
325 case 8:
326 val = 2.*(sigma-rms)/(sigma+rms);
327 break;
328 case 9:
329 val = TMath::Sqrt((rmserr*rmserr + sigmaerr*sigmaerr) * (rms*rms + sigma*sigma))
330 *2./(rms+sigma)/(rms+sigma);
331 break;
332 case 10:
333 val = 2.*(sigmaerr - rmserr)/(sigmaerr + rmserr);
334 break;
335 case 11:
336 if ((*this)[idx].IsGausFitOK())
337 val = 1.;
338 case 12:
339 if ((*this)[idx].IsFourierSpectrumOK())
340 val = 1.;
341 default:
342 return kFALSE;
343 }
344 return kTRUE;
345}
346
347void MHPedestalCam::DrawPixelContent(Int_t idx) const
348{
349 (*this)[idx].DrawClone();
350}
Note: See TracBrowser for help on using the repository browser.