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