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 |
|
---|
48 | ClassImp(MHPedestalCam);
|
---|
49 |
|
---|
50 | using namespace std;
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // Default constructor. Creates a MHPedestalPix object for each pixel
|
---|
54 | //
|
---|
55 | MHPedestalCam::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 | //
|
---|
75 | MHPedestalCam::~MHPedestalCam()
|
---|
76 | {
|
---|
77 | delete fArray;
|
---|
78 | }
|
---|
79 |
|
---|
80 | // --------------------------------------------------------------------------
|
---|
81 | //
|
---|
82 | // Get i-th pixel (pixel number)
|
---|
83 | //
|
---|
84 | MHPedestalPix &MHPedestalCam::operator[](UInt_t i)
|
---|
85 | {
|
---|
86 | return *(MHPedestalPix*)(fArray->At(i));
|
---|
87 | }
|
---|
88 |
|
---|
89 | // --------------------------------------------------------------------------
|
---|
90 | //
|
---|
91 | // Get i-th pixel (pixel number)
|
---|
92 | //
|
---|
93 | const 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 | //
|
---|
104 | TObject *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 | //
|
---|
133 | Bool_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 | //
|
---|
151 | Bool_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 |
|
---|
221 | Bool_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 | //
|
---|
276 | Bool_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 | const Float_t ped = (*fPedestals)[idx].GetPedestal();
|
---|
283 | const Float_t rms = (*fPedestals)[idx].GetPedestalRms();
|
---|
284 |
|
---|
285 | const Float_t entsqr = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
|
---|
286 |
|
---|
287 | const Float_t pederr = rms/entsqr;
|
---|
288 | const Float_t rmserr = rms/entsqr/2.;
|
---|
289 |
|
---|
290 | const Float_t mean = (*this)[idx].GetMean();
|
---|
291 | const Float_t meanerr = (*this)[idx].GetMeanErr();
|
---|
292 | const Float_t sigma = (*this)[idx].GetSigma() ;
|
---|
293 | const Float_t sigmaerr = (*this)[idx].GetSigmaErr();
|
---|
294 |
|
---|
295 | switch (type)
|
---|
296 | {
|
---|
297 | case 0:
|
---|
298 | val = mean;
|
---|
299 | break;
|
---|
300 | case 1:
|
---|
301 | val = meanerr;
|
---|
302 | break;
|
---|
303 | case 2:
|
---|
304 | val = sigma;
|
---|
305 | break;
|
---|
306 | case 3:
|
---|
307 | val = sigmaerr;
|
---|
308 | break;
|
---|
309 | case 4:
|
---|
310 | val = (*this)[idx].GetProb();
|
---|
311 | break;
|
---|
312 | case 5:
|
---|
313 | val = 2.*(ped-mean)/(ped+mean);
|
---|
314 | break;
|
---|
315 | case 6:
|
---|
316 | val = TMath::Sqrt((pederr*pederr + meanerr*meanerr) * (ped*ped + mean*mean))
|
---|
317 | *2./(ped+mean)/(ped+mean);
|
---|
318 | break;
|
---|
319 | case 7:
|
---|
320 | val = 2.*(pederr - meanerr)/(pederr + meanerr);
|
---|
321 | break;
|
---|
322 | case 8:
|
---|
323 | val = 2.*(sigma-rms)/(sigma+rms);
|
---|
324 | break;
|
---|
325 | case 9:
|
---|
326 | val = TMath::Sqrt((rmserr*rmserr + sigmaerr*sigmaerr) * (rms*rms + sigma*sigma))
|
---|
327 | *2./(rms+sigma)/(rms+sigma);
|
---|
328 | break;
|
---|
329 | case 10:
|
---|
330 | val = 2.*(sigmaerr - rmserr)/(sigmaerr + rmserr);
|
---|
331 | break;
|
---|
332 | case 11:
|
---|
333 | if (!(*this)[idx].IsGausFitOK())
|
---|
334 | val = 1.;
|
---|
335 | break;
|
---|
336 | case 12:
|
---|
337 | if (!(*this)[idx].IsFourierSpectrumOK())
|
---|
338 | val = 1.;
|
---|
339 | break;
|
---|
340 | default:
|
---|
341 | return kFALSE;
|
---|
342 | }
|
---|
343 | return kTRUE;
|
---|
344 | }
|
---|
345 |
|
---|
346 | void MHPedestalCam::DrawPixelContent(Int_t idx) const
|
---|
347 | {
|
---|
348 | (*this)[idx].DrawClone();
|
---|
349 | }
|
---|