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

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