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 | // MHCalibrationChargePINDiode
|
---|
28 | //
|
---|
29 | // Histogram class for the charge calibration of the PIN Diode.
|
---|
30 | // Stores and fits the charges, the RMS of the charges and stores the
|
---|
31 | // location of the maximum FADC slice. Charges are taken from MExtractedSignalPINDiode.
|
---|
32 | //
|
---|
33 | //////////////////////////////////////////////////////////////////////////////
|
---|
34 | #include "MHCalibrationChargePINDiode.h"
|
---|
35 |
|
---|
36 | #include <TH1.h>
|
---|
37 | #include <TF1.h>
|
---|
38 | #include <TPad.h>
|
---|
39 | #include <TVirtualPad.h>
|
---|
40 | #include <TCanvas.h>
|
---|
41 |
|
---|
42 | #include "MLog.h"
|
---|
43 | #include "MLogManip.h"
|
---|
44 |
|
---|
45 | #include "MParList.h"
|
---|
46 |
|
---|
47 | #include "MExtractedSignalPINDiode.h"
|
---|
48 | #include "MCalibrationChargePINDiode.h"
|
---|
49 |
|
---|
50 | ClassImp(MHCalibrationChargePINDiode);
|
---|
51 |
|
---|
52 | using namespace std;
|
---|
53 |
|
---|
54 | const Axis_t MHCalibrationChargePINDiode::fgAbsTimeFirst = -0.5;
|
---|
55 | const Axis_t MHCalibrationChargePINDiode::fgAbsTimeLast = 29.5;
|
---|
56 | const Int_t MHCalibrationChargePINDiode::fgAbsTimeNbins = 30;
|
---|
57 | const Axis_t MHCalibrationChargePINDiode::fgChargeFirst = -0.5;
|
---|
58 | const Axis_t MHCalibrationChargePINDiode::fgChargeLast = 1999.5;
|
---|
59 | const Int_t MHCalibrationChargePINDiode::fgChargeNbins = 2000;
|
---|
60 | const Int_t MHCalibrationChargePINDiode::fgRmsChargeNbins = 200;
|
---|
61 | const Axis_t MHCalibrationChargePINDiode::fgRmsChargeFirst = 0.;
|
---|
62 | const Axis_t MHCalibrationChargePINDiode::fgRmsChargeLast = 200.;
|
---|
63 | const Float_t MHCalibrationChargePINDiode::fgTimeLowerLimit = 3.;
|
---|
64 | const Float_t MHCalibrationChargePINDiode::fgTimeUpperLimit = 4.;
|
---|
65 | // --------------------------------------------------------------------------
|
---|
66 | //
|
---|
67 | // Default Constructor.
|
---|
68 | //
|
---|
69 | // Sets:
|
---|
70 | // - the default number for fAbsTimeFirst (fgAbsTimeFirst)
|
---|
71 | // - the default number for fAbsTimeLast (fgAbsTimeLast)
|
---|
72 | // - the default number for fAbsTimeNbins (fgAbsTimeNbins)
|
---|
73 | // - the default number for MHGausEvents::fNbins (fgChargeNbins)
|
---|
74 | // - the default number for MHGausEvents::fFirst (fgChargeFirst)
|
---|
75 | // - the default number for MHGausEvents::fLast (fgChargeLast)
|
---|
76 | // - the default number for fRmsChargeNbins (fgRmsChargeNbins)
|
---|
77 | // - the default number for fRmsChargeFirst (fgRmsChargeFirst)
|
---|
78 | // - the default number for fRmsChargeLast (fgRmsChargeLast)
|
---|
79 | // - the default number for fTimeLowerLimit (fgTimeLowerLimit)
|
---|
80 | // - the default number for fTimeUpperLimit (fgTimeUpperLimit)
|
---|
81 | //
|
---|
82 | // - the default name of the fHGausHist ("HCalibrationChargePINDiode")
|
---|
83 | // - the default title of the fHGausHist ("Distribution of Summed FADC slices PIN Diode")
|
---|
84 | // - the default x-axis title for fHGausHist ("Sum FADC Slices")
|
---|
85 | // - the default y-axis title for fHGausHist ("Nr. of events")
|
---|
86 | // - the default name of the fHAbsTime ("HAbsTimePINDiode")
|
---|
87 | // - the default title of the fHAbsTime ("Distribution of Absolute Arrival Times PIN Diode")
|
---|
88 | // - the default x-axis title for fHAbsTime ("Absolute Arrival Time [FADC slice nr]")
|
---|
89 | // - the default y-axis title for fHAbsTime ("Nr. of events")
|
---|
90 | // - the default name of the fHRmsCharge ("HRmsChargePINDiode")
|
---|
91 | // - the default title of the fHRmsCharge ("Distribution of Variances of summed FADC slices PIN Diode")
|
---|
92 | // - the default x-axis title for fHRmsCharge ("RMS (sum) [FADC slices]")
|
---|
93 | // - the default y-axis title for fHRmsCharge ("Nr. of events")
|
---|
94 | // - the default directory of the fHRmsCharge (NULL)
|
---|
95 | // - the current style for fHRmsCharge (NULL)
|
---|
96 | //
|
---|
97 | // Initializes:
|
---|
98 | // - fHRmsCharge()
|
---|
99 | // - all pointers to NULL
|
---|
100 | //
|
---|
101 | // Calls:
|
---|
102 | // - Clear()
|
---|
103 | //
|
---|
104 | MHCalibrationChargePINDiode::MHCalibrationChargePINDiode(const char *name, const char *title)
|
---|
105 | : fPINDiode(NULL), fSigPIN(NULL), fHRmsCharge()
|
---|
106 | {
|
---|
107 |
|
---|
108 | fName = name ? name : "MHCalibrationChargePINDiode";
|
---|
109 | fTitle = title ? title : "Fill the FADC sums of the PINDiode events and perform the fits";
|
---|
110 |
|
---|
111 | SetAbsTimeFirst();
|
---|
112 | SetAbsTimeLast();
|
---|
113 | SetAbsTimeNbins();
|
---|
114 |
|
---|
115 | SetNbins( fgChargeNbins );
|
---|
116 | SetFirst( fgChargeFirst );
|
---|
117 | SetLast ( fgChargeLast );
|
---|
118 |
|
---|
119 | SetRmsChargeNbins();
|
---|
120 | SetRmsChargeFirst();
|
---|
121 | SetRmsChargeLast();
|
---|
122 |
|
---|
123 | SetTimeLowerLimit();
|
---|
124 | SetTimeUpperLimit();
|
---|
125 |
|
---|
126 | fHGausHist.SetName("HCalibrationChargePINDiode");
|
---|
127 | fHGausHist.SetTitle("Distribution of Summed FADC slices PIN Diode");
|
---|
128 | fHGausHist.SetXTitle("Sum FADC Slices");
|
---|
129 | fHGausHist.SetYTitle("Nr. of events");
|
---|
130 |
|
---|
131 | fHAbsTime.SetName("HAbsTimePINDiode");
|
---|
132 | fHAbsTime.SetTitle("Distribution of Absolute Arrival Times PIN Diode");
|
---|
133 | fHAbsTime.SetXTitle("Absolute Arrival Time [FADC slice nr]");
|
---|
134 | fHAbsTime.SetYTitle("Nr. of events");
|
---|
135 |
|
---|
136 | fHRmsCharge.SetName("HRmsChargePINDiode");
|
---|
137 | fHRmsCharge.SetTitle("Distribution of Variances of summed FADC slices PIN Diode");
|
---|
138 | fHRmsCharge.SetXTitle("RMS (sum) [FADC slices]");
|
---|
139 | fHRmsCharge.SetYTitle("Nr. of events");
|
---|
140 | fHRmsCharge.UseCurrentStyle();
|
---|
141 | fHRmsCharge.SetDirectory(NULL);
|
---|
142 |
|
---|
143 | Clear();
|
---|
144 | }
|
---|
145 |
|
---|
146 | // --------------------------------------------------------------------------
|
---|
147 | //
|
---|
148 | // Initializes Binning of the following histograms:
|
---|
149 | // - fHGausHist.SetBins(fNbins,fFirst,fLast);
|
---|
150 | // - fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
|
---|
151 | // - fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
|
---|
152 | //
|
---|
153 | Bool_t MHCalibrationChargePINDiode::SetupFill(const MParList *pList)
|
---|
154 | {
|
---|
155 |
|
---|
156 | MHCalibrationPix::InitBins();
|
---|
157 |
|
---|
158 | fHAbsTime. SetBins(fAbsTimeNbins, fAbsTimeFirst, fAbsTimeLast);
|
---|
159 | fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
|
---|
160 |
|
---|
161 | return kTRUE;
|
---|
162 |
|
---|
163 | }
|
---|
164 |
|
---|
165 | // --------------------------------------------------------------------------
|
---|
166 | //
|
---|
167 | // Use the MHCalibrationChargePix::Clone function and clone additionally
|
---|
168 | // the rest of the data members.
|
---|
169 | //
|
---|
170 | TObject *MHCalibrationChargePINDiode::Clone(const char *name) const
|
---|
171 | {
|
---|
172 |
|
---|
173 | MHCalibrationChargePINDiode &pix = (MHCalibrationChargePINDiode&)*MHCalibrationChargePix::Clone(name);
|
---|
174 | //
|
---|
175 | // Copy data members
|
---|
176 | //
|
---|
177 | pix.fHRmsCharge = fHRmsCharge;
|
---|
178 |
|
---|
179 | pix.fRmsChargeFirst = fRmsChargeFirst;
|
---|
180 | pix.fRmsChargeLast = fRmsChargeLast;
|
---|
181 | pix.fRmsChargeNbins = fRmsChargeNbins;
|
---|
182 | pix.fRmsChargeMean = fRmsChargeMean;
|
---|
183 | pix.fRmsChargeMeanErr = fRmsChargeMeanErr;
|
---|
184 | pix.fRmsChargeSigma = fRmsChargeSigma;
|
---|
185 | pix.fRmsChargeSigmaErr = fRmsChargeSigmaErr;
|
---|
186 | pix.fTimeLowerLimit = fTimeLowerLimit;
|
---|
187 | pix.fTimeUpperLimit = fTimeUpperLimit;
|
---|
188 |
|
---|
189 | return &pix;
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | // --------------------------------------------------------------------------
|
---|
194 | //
|
---|
195 | // Gets or creates the pointers to:
|
---|
196 | // - MExtractedSignalPINDiode
|
---|
197 | // - MCalibrationChargePINDiode
|
---|
198 | //
|
---|
199 | Bool_t MHCalibrationChargePINDiode::ReInit(MParList *pList)
|
---|
200 | {
|
---|
201 |
|
---|
202 | fSigPIN = (MExtractedSignalPINDiode*)pList->FindCreateObj("MExtractedSignalPINDiode");
|
---|
203 | if (!fSigPIN)
|
---|
204 | {
|
---|
205 | *fLog << err << "MExtractedSignalPINDiode not found... aborting " << endl;
|
---|
206 | return kFALSE;
|
---|
207 | }
|
---|
208 |
|
---|
209 | fPINDiode = (MCalibrationChargePINDiode*)pList->FindCreateObj("MCalibrationChargePINDiode");
|
---|
210 | if (!fPINDiode)
|
---|
211 | {
|
---|
212 | *fLog << err << "MCalibrationChargePINDiode not found... aborting " << endl;
|
---|
213 | return kFALSE;
|
---|
214 | }
|
---|
215 |
|
---|
216 | return kTRUE;
|
---|
217 | }
|
---|
218 |
|
---|
219 | // --------------------------------------------------------------------------
|
---|
220 | //
|
---|
221 | // Retrieves from MExtractedSignalPINDiode:
|
---|
222 | // - Number of used FADC samples via MExtractedSignalPINDiode::GetNumFADCSamples()
|
---|
223 | // - Extracted signal via MExtractedSignalPINDiode::GetExtractedSignal()
|
---|
224 | // - Signal Rms MExtractedSignalPINDiode::GetExtractedRms()
|
---|
225 | // - Arrival Time MExtractedSignalPINDiode::GetExtractedTime()
|
---|
226 | //
|
---|
227 | // Fills the following histograms:
|
---|
228 | // - MHGausEvents::FillHistAndArray(signal)
|
---|
229 | // - MHCalibrationChargePix::FillAbsTime(time);
|
---|
230 | // - FillRmsCharge(rms);
|
---|
231 | //
|
---|
232 | Bool_t MHCalibrationChargePINDiode::Fill(const MParContainer *par, const Stat_t w)
|
---|
233 | {
|
---|
234 |
|
---|
235 | MExtractedSignalPINDiode *extractor = (MExtractedSignalPINDiode*)par;
|
---|
236 |
|
---|
237 | if (!extractor)
|
---|
238 | {
|
---|
239 | *fLog << err << "No argument in MExtractedSignalPINDiode::Fill... abort." << endl;
|
---|
240 | return kFALSE;
|
---|
241 | }
|
---|
242 |
|
---|
243 | Float_t slices = (Float_t)extractor->GetNumFADCSamples();
|
---|
244 |
|
---|
245 | if (slices == 0.)
|
---|
246 | {
|
---|
247 | *fLog << err << "Number of used signal slices in MExtractedSignalPINDiode is zero ... abort."
|
---|
248 | << endl;
|
---|
249 | return kFALSE;
|
---|
250 | }
|
---|
251 |
|
---|
252 | const Float_t signal = (float)extractor->GetExtractedSignal();
|
---|
253 | const Float_t time = extractor->GetExtractedTime();
|
---|
254 | const Float_t rms = extractor->GetExtractedRms();
|
---|
255 |
|
---|
256 | FillHistAndArray(signal);
|
---|
257 | FillAbsTime(time);
|
---|
258 | FillRmsCharge(rms);
|
---|
259 |
|
---|
260 | return kTRUE;
|
---|
261 | }
|
---|
262 |
|
---|
263 | // --------------------------------------------------------------------------
|
---|
264 | //
|
---|
265 | // Returns kTRUE, if empty
|
---|
266 | //
|
---|
267 | // Performs the following fits:
|
---|
268 | // - MHGausEvents::FitGaus()
|
---|
269 | // - FitRmsCharge()
|
---|
270 | //
|
---|
271 | // Creates the fourier spectrum (MHGausEvents::CreateFourierSpectrum()
|
---|
272 | // and sets bit MCalibrationChargePINDiode::SetOscillating( MHGausEvents::IsFourierSpectrumOK() )
|
---|
273 | // Retrieves the results of the following fits and stores them in MCalibrationChargePINDiode:
|
---|
274 | // - Mean Charge and Error
|
---|
275 | // - Sigma Charge and Error
|
---|
276 | // - Fit Probability
|
---|
277 | // - Abs Time Mean
|
---|
278 | // - Abs Time Rms
|
---|
279 | // - Rms Charge Mean and Error
|
---|
280 | // - Rms Charge Sigma and Error
|
---|
281 | //
|
---|
282 | // Performs one consistency check on the arrival time:
|
---|
283 | // The check returns kFALSE if:
|
---|
284 | //
|
---|
285 | // -The mean arrival time is in fTimeLowerLimit slices from the lower edge
|
---|
286 | // and fUpperLimit slices from the upper edge
|
---|
287 | //
|
---|
288 | Bool_t MHCalibrationChargePINDiode::Finalize()
|
---|
289 | {
|
---|
290 |
|
---|
291 | if (IsGausFitOK() || IsEmpty())
|
---|
292 | return kTRUE;
|
---|
293 |
|
---|
294 | FitGaus();
|
---|
295 | FitRmsCharge();
|
---|
296 |
|
---|
297 | CreateFourierSpectrum();
|
---|
298 | fPINDiode->SetOscillating ( !IsFourierSpectrumOK() );
|
---|
299 |
|
---|
300 | fPINDiode->SetMean ( fMean );
|
---|
301 | fPINDiode->SetMeanVar ( fMeanErr * fMeanErr );
|
---|
302 | fPINDiode->SetSigma ( fSigma );
|
---|
303 | fPINDiode->SetSigmaVar ( fSigmaErr * fMeanErr );
|
---|
304 | fPINDiode->SetProb ( fProb );
|
---|
305 |
|
---|
306 | fPINDiode->SetAbsTimeMean( GetAbsTimeMean() );
|
---|
307 | fPINDiode->SetAbsTimeRms( GetAbsTimeRms() );
|
---|
308 |
|
---|
309 | fPINDiode->SetRmsChargeMean( GetRmsChargeMean() );
|
---|
310 | fPINDiode->SetRmsChargeMeanErr( GetRmsChargeMeanErr() );
|
---|
311 | fPINDiode->SetRmsChargeSigma( GetRmsChargeSigma() );
|
---|
312 | fPINDiode->SetRmsChargeSigmaErr( GetRmsChargeSigmaErr() );
|
---|
313 |
|
---|
314 | fPINDiode->SetValid(kTRUE);
|
---|
315 |
|
---|
316 | const Byte_t loweredge = fSigPIN->GetFirstUsedSlice();
|
---|
317 | const Byte_t upperedge = fSigPIN->GetLastUsedSlice();
|
---|
318 | const Float_t lowerlimit = (Float_t)loweredge + fTimeLowerLimit;
|
---|
319 | const Float_t upperlimit = (Float_t)upperedge + fTimeUpperLimit;
|
---|
320 |
|
---|
321 | if (GetAbsTimeMean() < lowerlimit)
|
---|
322 | {
|
---|
323 | *fLog << warn << GetDescriptor()
|
---|
324 | << Form("%s%3.1f%s%2.1f%s",": Mean ArrivalTime: ",GetAbsTimeMean()," smaller than ",
|
---|
325 | lowerlimit," FADC slices from lower edge in PIN Diode") << endl;
|
---|
326 | *fLog << warn << GetDescriptor() << ": No PIN Diode calibration!! " << endl;
|
---|
327 | fPINDiode->SetValid(kFALSE);
|
---|
328 | }
|
---|
329 |
|
---|
330 | if ( GetAbsTimeMean() > upperlimit )
|
---|
331 | {
|
---|
332 | *fLog << warn << GetDescriptor()
|
---|
333 | << Form("%s%3.1f%s%2.1f%s",": Mean ArrivalTime: ",GetAbsTimeMean()," bigger than ",
|
---|
334 | upperlimit," FADC slices from upper edge in PIN Diode") << endl;
|
---|
335 | *fLog << warn << GetDescriptor() << ": No PIN Diode calibration!! " << endl;
|
---|
336 | fPINDiode->SetValid(kFALSE);
|
---|
337 | }
|
---|
338 |
|
---|
339 | return kTRUE;
|
---|
340 | }
|
---|
341 |
|
---|
342 | // --------------------------------------------------------------------------
|
---|
343 | //
|
---|
344 | // Fills fHRmsCharge with q
|
---|
345 | // Returns kFALSE, if overflow or underflow occurred, else kTRUE
|
---|
346 | //
|
---|
347 | Bool_t MHCalibrationChargePINDiode::FillRmsCharge(const Float_t q)
|
---|
348 | {
|
---|
349 | return fHRmsCharge.Fill(q) > -1;
|
---|
350 | }
|
---|
351 |
|
---|
352 | // -----------------------------------------------------------
|
---|
353 | //
|
---|
354 | // Fits -- not yet implemented
|
---|
355 | //
|
---|
356 | Bool_t MHCalibrationChargePINDiode::FitRmsCharge(Option_t *option)
|
---|
357 | {
|
---|
358 | return 1;
|
---|
359 | }
|
---|
360 |
|
---|
361 |
|
---|
362 | // -------------------------------------------------------------------------
|
---|
363 | //
|
---|
364 | // Draw the histogram
|
---|
365 | //
|
---|
366 | // The following options can be chosen:
|
---|
367 | //
|
---|
368 | // "": displays the fHGausHist with fits and fHRmsCharge
|
---|
369 | // "all": executes additionally MHCalibrationPix::Draw(), with option "fourierevents"
|
---|
370 | //
|
---|
371 | void MHCalibrationChargePINDiode::Draw(const Option_t *opt)
|
---|
372 | {
|
---|
373 |
|
---|
374 | TString option(opt);
|
---|
375 | option.ToLower();
|
---|
376 |
|
---|
377 | Int_t win = 1;
|
---|
378 |
|
---|
379 | TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
|
---|
380 | TVirtualPad *pad = NULL;
|
---|
381 |
|
---|
382 | oldpad->SetBorderMode(0);
|
---|
383 |
|
---|
384 | if (option.Contains("all"))
|
---|
385 | {
|
---|
386 | option.ReplaceAll("all","");
|
---|
387 | oldpad->Divide(2,1);
|
---|
388 | win = 2;
|
---|
389 | oldpad->cd(1);
|
---|
390 | TVirtualPad *newpad = gPad;
|
---|
391 | pad = newpad;
|
---|
392 | pad->Divide(1,2);
|
---|
393 | pad->cd(1);
|
---|
394 | }
|
---|
395 | else
|
---|
396 | {
|
---|
397 | pad = oldpad;
|
---|
398 | pad->Divide(1,2);
|
---|
399 | pad->cd(1);
|
---|
400 | }
|
---|
401 |
|
---|
402 | if (IsEmpty())
|
---|
403 | return;
|
---|
404 |
|
---|
405 | if (!IsOnlyOverflow() && !IsOnlyUnderflow())
|
---|
406 | gPad->SetLogy();
|
---|
407 |
|
---|
408 | gPad->SetTicks();
|
---|
409 |
|
---|
410 | fHGausHist.Draw(opt);
|
---|
411 | if (fFGausFit)
|
---|
412 | {
|
---|
413 | fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
|
---|
414 | fFGausFit->Draw("same");
|
---|
415 | }
|
---|
416 |
|
---|
417 | pad->cd(2);
|
---|
418 | fHRmsCharge.Draw(opt);
|
---|
419 |
|
---|
420 | oldpad->cd(2);
|
---|
421 | MHCalibrationPix::Draw("fourierevents");
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 |
|
---|
426 |
|
---|