source: trunk/MagicSoft/Mars/mcalib/MHCalibrationRelTimeCam.cc@ 3481

Last change on this file since 3481 was 3317, checked in by gaug, 21 years ago
*** empty log message ***
File size: 7.6 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// //
27// MHCalibrationRelTimeCam //
28// //
29// Hold the CalibrationRelTime information for all pixels in the camera //
30// //
31/////////////////////////////////////////////////////////////////////////////
32#include "MHCalibrationRelTimeCam.h"
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38
39#include "MHCalibrationRelTimePix.h"
40
41#include "MArrivalTimeCam.h"
42#include "MArrivalTimePix.h"
43
44ClassImp(MHCalibrationRelTimeCam);
45
46using namespace std;
47const Float_t MHCalibrationRelTimeCam::fgTimeSliceWidth = 3.3;
48// --------------------------------------------------------------------------
49//
50// Default constructor. Creates a MHCalibrationRelTimePix object for each pixel
51//
52MHCalibrationRelTimeCam::MHCalibrationRelTimeCam(const char *name, const char *title)
53{
54
55 fName = name ? name : "MHCalibrationRelTimeCam";
56 fTitle = title ? title : "Histogram container for the relative time calibration of the camera";
57
58 //
59 // loop over all Pixels and create two histograms
60 // one for the Low and one for the High gain
61 // connect all the histogram with the container fHist
62 //
63 fArray = new TObjArray;
64 fArray->SetOwner();
65
66
67 SetTimeSliceWidth();
68}
69
70// --------------------------------------------------------------------------
71//
72// Delete the array conatining the pixel pedest information
73//
74MHCalibrationRelTimeCam::~MHCalibrationRelTimeCam()
75{
76 delete fArray;
77}
78
79// --------------------------------------
80//
81void MHCalibrationRelTimeCam::Clear(Option_t *o)
82{
83
84 fArray->ForEach(TObject, Clear)();
85 return;
86}
87
88// --------------------------------------------------------------------------
89//
90// Get i-th pixel (pixel number)
91//
92MHCalibrationRelTimePix &MHCalibrationRelTimeCam::operator[](UInt_t i)
93{
94 return *(MHCalibrationRelTimePix*)(fArray->At(i));
95}
96
97// --------------------------------------------------------------------------
98//
99// Get i-th pixel (pixel number)
100//
101const MHCalibrationRelTimePix &MHCalibrationRelTimeCam::operator[](UInt_t i) const
102{
103 return *(MHCalibrationRelTimePix*)(fArray->At(i));
104}
105
106
107// --------------------------------------------------------------------------
108//
109// Our own clone function is necessary since root 3.01/06 or Mars 0.4
110// I don't know the reason
111//
112TObject *MHCalibrationRelTimeCam::Clone(const char *) const
113{
114
115 const Int_t n = fArray->GetSize();
116
117 //
118 // FIXME, this might be done faster and more elegant, by direct copy.
119 //
120 MHCalibrationRelTimeCam *cam = new MHCalibrationRelTimeCam;
121
122 cam->fArray->Expand(n);
123
124 for (int i=0; i<n; i++)
125 {
126 delete (*cam->fArray)[i];
127 (*cam->fArray)[i] = (*fArray)[i]->Clone();
128 }
129
130 return cam;
131}
132
133
134
135// --------------------------------------------------------------------------
136//
137//
138Bool_t MHCalibrationRelTimeCam::SetupFill(const MParList *pList)
139{
140
141 return kTRUE;
142
143}
144
145// --------------------------------------------------------------------------
146//
147Bool_t MHCalibrationRelTimeCam::Fill(const MParContainer *par, const Stat_t w)
148{
149
150 MArrivalTimeCam *arrtime = (MArrivalTimeCam*)par;
151 if (!arrtime)
152 {
153 gLog << err << "No argument in MArrivalTime::Fill... abort." << endl;
154 return kFALSE;
155 }
156
157 const Int_t n = arrtime->GetSize();
158
159 if (fArray->GetEntries()==0)
160 {
161 fArray->Expand(n);
162
163 for (Int_t i=0; i<n; i++)
164 {
165 (*fArray)[i] = new MHCalibrationRelTimePix;
166 MHCalibrationRelTimePix &hist = (*this)[i];
167 hist.ChangeHistId(i);
168 hist.InitBins();
169 }
170 }
171
172 if (fArray->GetEntries() != n)
173 {
174 gLog << err << "ERROR - Size mismatch... abort." << endl;
175 return kFALSE;
176 }
177
178 const MArrivalTimePix &refpix = (*arrtime)[1];
179 const Float_t reftime = refpix.IsLoGainUsed() ? refpix.GetArrivalTimeLoGain() : refpix.GetArrivalTimeHiGain();
180
181 for (Int_t i=0; i<n; i++)
182 {
183 const MArrivalTimePix &pix = (*arrtime)[i];
184 const Float_t time = pix.IsLoGainUsed() ? pix.GetArrivalTimeLoGain() : pix.GetArrivalTimeHiGain();
185
186 MHCalibrationRelTimePix &hist = (*this)[i];
187 hist.FillHistAndArray(time - reftime);
188 }
189
190 return kTRUE;
191}
192
193Bool_t MHCalibrationRelTimeCam::Finalize()
194{
195
196 for (Int_t i=0; i<fArray->GetSize(); i++)
197 {
198
199 MHCalibrationRelTimePix &hist = (*this)[i];
200
201 //
202 // 1) Return if the charge distribution is already succesfully fitted
203 // or if the histogram is empty
204 //
205 if (hist.IsGausFitOK() || hist.IsEmpty())
206 continue;
207
208 //
209 // 2) Fit the Hi Gain histograms with a Gaussian
210 //
211 hist.FitGaus();
212
213 //
214 // 3) If fit does not succeed , bypass the fit and take the histogram means and sigmas
215 //
216 if (!hist.IsGausFitOK())
217 hist.BypassFit();
218
219 //
220 // 4) Create the fourier transform of the arrays
221 //
222 hist.CreateFourierSpectrum();
223
224 //
225 // 5) Renormalize to the real time in ns.
226 //
227 hist.Renorm(fTimeSliceWidth);
228
229 }
230 return kTRUE;
231}
232
233// --------------------------------------------------------------------------
234//
235// The types are as follows:
236//
237// Fitted values:
238// ==============
239//
240// 0: Fitted Mean Relative Arrival Time
241// 1: Error of fitted Mean Relative Arrival Time
242// 2: Sigma of fitted Relative Arrival Time
243// 3: Error of Sigma of fitted Relative Arrival Time
244//
245//
246// Useful variables derived from the fit results:
247// =============================================
248//
249// 4: Returned probability of Gauss fit to Charge distribution
250//
251// Localized defects:
252// ==================
253//
254// 5: Gaus fit not OK
255// 6: Fourier spectrum not OK
256//
257Bool_t MHCalibrationRelTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
258{
259
260 if (fArray->GetSize() <= idx)
261 return kFALSE;
262
263 switch (type)
264 {
265 case 0:
266 val = (*this)[idx].GetMean();
267 break;
268 case 1:
269 val = (*this)[idx].GetMeanErr();
270 break;
271 case 2:
272 val = (*this)[idx].GetSigma();
273 break;
274 case 3:
275 val = (*this)[idx].GetSigmaErr();
276 break;
277 case 4:
278 val = (*this)[idx].GetProb();
279 break;
280 case 5:
281 if (!(*this)[idx].IsGausFitOK())
282 val = 1.;
283 break;
284 case 6:
285 if (!(*this)[idx].IsFourierSpectrumOK())
286 val = 1.;
287 break;
288 default:
289 return kFALSE;
290 }
291 return kTRUE;
292}
293
294void MHCalibrationRelTimeCam::DrawPixelContent(Int_t idx) const
295{
296 (*this)[idx].DrawClone();
297}
Note: See TracBrowser for help on using the repository browser.