source: trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc@ 5232

Last change on this file since 5232 was 5143, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 23.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): Thomas Bretz, 8/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Wolfgang Wittek, 1/2002 <mailto:wittek@mppmu.mpg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MHEffectiveOnTime
29//
30// Filling this you will get the effective on-time versus theta and
31// observation time.
32//
33// From this histogram the effective on-time is determined by a fit.
34// The result of the fit (see Fit()) and the fit-parameters (like chi^2)
35// are stored in corresponding histograms
36//
37// To determin the efective on time a poisson fit is done. For more details
38// please have a look into the source code of FitH() it should be simple
39// to understand. In this function a Delta-T distribution is fitted, while
40// Delta-T is the time between two consecutive events.
41//
42// The fit is done for projections of a 2D histogram in Theta and Delta T.
43// So you get the effective on time versus theta.
44//
45// To get the effective on-time versus time a histogram is filled with
46// the Delta-T distribution of a number of events set by SetNumEvents().
47// The default is 12000 (roughly 1min at 200Hz)
48//
49// For each "time-bin" the histogram is fitted and the resulting effective
50// on-time is stored in the fHTimeEffOn histogram. Each entry in this
51// histogram is the effective observation time between the upper and
52// lower edges of the bins.
53//
54// In addition the calculated effective on time is stored in a
55// "MEffectiveOnTime [MParameterDerr]" and the corresponding time-stamp
56// (the upper edge of the bin) "MTimeEffectiveOnTime [MTime]"
57//
58// The class takes two binnings from the Parameter list; if these binnings
59// are not available the defaultbinning is used:
60// MBinning("BinningDeltaT"); // Units of seconds
61// MBinning("BinningTheta"); // Units of degrees
62//
63//
64// Usage:
65// ------
66// MFillH fill("MHEffectiveOnTime", "MTime");
67// tlist.AddToList(&fill);
68//
69//
70// Input Container:
71// MPointingPos
72//
73// Output Container:
74// MEffectiveOnTime [MParameterDerr]
75// MTimeEffectiveOnTime [MTime]
76//
77//////////////////////////////////////////////////////////////////////////////
78#include "MHEffectiveOnTime.h"
79
80#include <TF1.h>
81#include <TMinuit.h>
82#include <TRandom.h>
83
84#include <TLatex.h>
85#include <TGaxis.h>
86#include <TCanvas.h>
87#include <TPaveStats.h>
88
89#include "MTime.h"
90#include "MParameters.h"
91#include "MPointingPos.h"
92
93#include "MBinning.h"
94#include "MParList.h"
95
96#include "MLog.h"
97#include "MLogManip.h"
98
99ClassImp(MHEffectiveOnTime);
100
101using namespace std;
102
103// --------------------------------------------------------------------------
104//
105// Default Constructor. It initializes all histograms.
106//
107MHEffectiveOnTime::MHEffectiveOnTime(const char *name, const char *title)
108 : fPointPos(0), fTime(0), fParam(0), fIsFinalized(kFALSE),
109 fNumEvents(200*60), fNameProjDeltaT(Form("DeltaT_%p", this)),
110 fNameProjTheta(Form("Theta_%p", this))
111{
112 //
113 // set the name and title of this object
114 //
115 fName = name ? name : "MHEffectiveOnTime";
116 fTitle = title ? title : "Histogram to determin effective On-Time vs Time and Zenith Angle";
117
118 // Main histogram
119 fH2DeltaT.SetName("DeltaT");
120 fH2DeltaT.SetXTitle("\\Delta t [s]");
121 fH2DeltaT.SetYTitle("\\Theta [\\circ]");
122 fH2DeltaT.SetZTitle("Count");
123 fH2DeltaT.UseCurrentStyle();
124 fH2DeltaT.SetDirectory(NULL);
125
126 // Main histogram
127 fH1DeltaT.SetName("DeltaT");
128 fH1DeltaT.SetXTitle("\\Delta t [s]");
129 fH1DeltaT.SetYTitle("Counts");
130 fH1DeltaT.UseCurrentStyle();
131 fH1DeltaT.SetDirectory(NULL);
132
133 // effective on time versus theta
134 fHThetaEffOn.SetName("EffOnTheta");
135 fHThetaEffOn.SetTitle("Effective On Time T_{eff}");
136 fHThetaEffOn.SetXTitle("\\Theta [\\circ]");
137 fHThetaEffOn.SetYTitle("T_{eff} [s]");
138 fHThetaEffOn.UseCurrentStyle();
139 fHThetaEffOn.SetDirectory(NULL);
140 fHThetaEffOn.GetYaxis()->SetTitleOffset(1.2);
141 fHThetaEffOn.GetYaxis()->SetTitleColor(kBlue);
142 fHThetaEffOn.SetLineColor(kBlue);
143 //fHEffOn.Sumw2();
144
145 // effective on time versus time
146 fHTimeEffOn.SetName("EffOnTime");
147 fHTimeEffOn.SetTitle("Effective On Time T_{eff}");
148 fHTimeEffOn.SetXTitle("Time");
149 fHTimeEffOn.SetYTitle("T_{eff} [s]");
150 fHTimeEffOn.UseCurrentStyle();
151 fHTimeEffOn.SetDirectory(NULL);
152 fHTimeEffOn.GetYaxis()->SetTitleOffset(1.2);
153 fHTimeEffOn.GetXaxis()->SetLabelSize(0.033);
154 fHTimeEffOn.GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
155 fHTimeEffOn.GetXaxis()->SetTimeDisplay(1);
156 fHTimeEffOn.GetYaxis()->SetTitleColor(kBlue);
157 fHTimeEffOn.SetLineColor(kBlue);
158
159 // chi2 probability
160 fHThetaProb.SetName("ProbTheta");
161 fHThetaProb.SetTitle("\\chi^{2} Probability of Fit");
162 fHThetaProb.SetXTitle("\\Theta [\\circ]");
163 fHThetaProb.SetYTitle("p [%]");
164 fHThetaProb.UseCurrentStyle();
165 fHThetaProb.SetDirectory(NULL);
166 fHThetaProb.GetYaxis()->SetTitleOffset(1.2);
167 fHThetaProb.SetMaximum(101);
168 fHThetaProb.GetYaxis()->SetTitleColor(kBlue);
169 fHThetaProb.SetLineColor(kBlue);
170
171 // chi2 probability
172 fHTimeProb.SetName("ProbTime");
173 fHTimeProb.SetTitle("\\chi^{2} Probability of Fit");
174 fHTimeProb.SetXTitle("Time");
175 fHTimeProb.SetYTitle("p [%]");
176 fHTimeProb.UseCurrentStyle();
177 fHTimeProb.SetDirectory(NULL);
178 fHTimeProb.GetYaxis()->SetTitleOffset(1.2);
179 fHTimeProb.GetXaxis()->SetLabelSize(0.033);
180 fHTimeProb.GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
181 fHTimeProb.GetXaxis()->SetTimeDisplay(1);
182 fHTimeProb.SetMaximum(101);
183 fHTimeProb.GetYaxis()->SetTitleColor(kBlue);
184 fHTimeProb.SetLineColor(kBlue);
185
186 // lambda versus theta
187 fHThetaLambda.SetName("LambdaTheta");
188 fHThetaLambda.SetTitle("Slope (Rate) vs Theta");
189 fHThetaLambda.SetXTitle("\\Theta [\\circ]");
190 fHThetaLambda.SetYTitle("\\lambda [s^{-1}]");
191 fHThetaLambda.UseCurrentStyle();
192 fHThetaLambda.SetDirectory(NULL);
193 fHThetaLambda.SetLineColor(kGreen);
194
195 // lambda versus time
196 fHTimeLambda.SetName("LambdaTime");
197 fHTimeLambda.SetTitle("Slope (Rate) vs Time");
198 fHTimeLambda.SetXTitle("\\Time [\\circ]");
199 fHTimeLambda.SetYTitle("\\lambda [s^{-1}]");
200 fHTimeLambda.UseCurrentStyle();
201 fHTimeLambda.SetDirectory(NULL);
202 fHTimeLambda.GetYaxis()->SetTitleOffset(1.2);
203 fHTimeLambda.GetXaxis()->SetLabelSize(0.033);
204 fHTimeLambda.GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
205 fHTimeLambda.GetXaxis()->SetTimeDisplay(1);
206 fHTimeLambda.SetLineColor(kGreen);
207
208 // NDoF versus theta
209 fHThetaNDF.SetName("NDofTheta");
210 fHThetaNDF.SetTitle("Number of Degrees of freedom vs Theta");
211 fHThetaNDF.SetXTitle("\\Theta [\\circ]");
212 fHThetaNDF.SetYTitle("NDoF [#]");
213 fHThetaNDF.UseCurrentStyle();
214 fHThetaNDF.SetDirectory(NULL);
215 fHThetaNDF.SetLineColor(kGreen);
216
217 // NDoF versus time
218 /*
219 fHTimeNDF.SetName("NDofTime");
220 fHTimeNDF.SetTitle("Number of Degrees of freedom vs Time");
221 fHTimeNDF.SetXTitle("Time");
222 fHTimeNDF.SetYTitle("NDoF [#]");
223 fHTimeNDF.UseCurrentStyle();
224 fHTimeNDF.SetDirectory(NULL);
225 fHTimeNDF.GetYaxis()->SetTitleOffset(1.2);
226 fHTimeNDF.GetXaxis()->SetLabelSize(0.033);
227 fHTimeNDF.GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
228 fHTimeNDF.GetXaxis()->SetTimeDisplay(1);
229 fHTimeNDF.SetLineColor(kBlue);
230 */
231 // setup binning
232 MBinning btheta("BinningTheta");
233 btheta.SetEdgesCos(100, 0, 60);
234
235 MBinning btime("BinningDeltaT");
236 btime.SetEdges(50, 0, 0.1);
237
238 MH::SetBinning(&fH2DeltaT, &btime, &btheta);
239
240 btime.Apply(fH1DeltaT);
241
242 btheta.Apply(fHThetaEffOn);
243 btheta.Apply(fHThetaLambda);
244 btheta.Apply(fHThetaNDF);
245 btheta.Apply(fHThetaProb);
246 //btheta.Apply(fHChi2);
247}
248
249// --------------------------------------------------------------------------
250//
251// Set the binnings and prepare the filling of the histogram
252//
253Bool_t MHEffectiveOnTime::SetupFill(const MParList *plist)
254{
255 fPointPos = (MPointingPos*)plist->FindObject("MPointingPos");
256 if (!fPointPos)
257 {
258 *fLog << err << dbginf << "MPointingPos not found... aborting." << endl;
259 return kFALSE;
260 }
261
262 // FIXME: Remove const-qualifier from base-class!
263 fTime = (MTime*)const_cast<MParList*>(plist)->FindCreateObj("MTime", "MTimeEffectiveOnTime");
264 if (!fTime)
265 return kFALSE;
266 fParam = (MParameterDerr*)const_cast<MParList*>(plist)->FindCreateObj("MParameterDerr", "MEffectiveOnTime");
267 if (!fParam)
268 return kFALSE;
269
270 const MBinning* binsdtime = (MBinning*)plist->FindObject("BinningDeltaT");
271 const MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta");
272 if (binsdtime)
273 binsdtime->Apply(fH1DeltaT);
274 if (binstheta)
275 {
276 binstheta->Apply(fHThetaEffOn);
277 binstheta->Apply(fHThetaLambda);
278 binstheta->Apply(fHThetaNDF);
279 binstheta->Apply(fHThetaProb);
280 //binstheta->Apply(fHChi2);
281 }
282 if (binstheta && binsdtime)
283 SetBinning(&fH2DeltaT, binsdtime, binstheta);
284
285 return kTRUE;
286}
287
288// --------------------------------------------------------------------------
289//
290// Fit a single Delta-T distribution. See source code for more details
291//
292Bool_t MHEffectiveOnTime::FitH(TH1D *h, Double_t *res, Bool_t paint) const
293{
294 const Double_t Nm = h->Integral();
295
296 // FIXME: Do fit only if contents of bin has changed
297 if (Nm<=0)
298 return kFALSE;
299
300 // determine range (yq[0], yq[1]) of time differences
301 // where fit should be performed;
302 // require a fraction >=xq[0] of all entries to lie below yq[0]
303 // and a fraction <=xq[1] of all entries to lie below yq[1];
304 // within the range (yq[0], yq[1]) there must be no empty bin;
305 // choose pedestrian approach as long as GetQuantiles is not available
306 Double_t xq[2] = { 0.6, 0.99 };
307 Double_t yq[2];
308 h->GetQuantiles(2, yq, xq);
309
310 // Nmdel = Nm * binwidth, with Nm = number of observed events
311 const Double_t Nmdel = h->Integral("width");
312
313 //
314 // Setup Poisson function for the fit:
315 // lambda [Hz], N0 = ideal no of evts, del = bin width of dt
316 //
317 // parameter 0 = lambda
318 // parameter 1 = N0*del
319 //
320 TF1 func("Poisson", " [1]*[2] * [0] * exp(-[0] *x)");
321 //func.SetParNames("lambda", "N0", "del");
322
323 func.SetParameter(0, 200); // Hz
324 func.SetParameter(1, Nm);
325 func.FixParameter(2, Nmdel/Nm);
326
327 // options : N do not store the function, do not draw
328 // I use integral of function in bin rather than value at bin center
329 // R use the range specified in the function range
330 // Q quiet mode
331 h->Fit(&func, "NIQ", "", yq[0], yq[1]);
332
333 const Double_t chi2 = func.GetChisquare();
334 const Int_t NDF = func.GetNDF();
335
336 // was fit successful ?
337 const Bool_t ok = NDF>0 && chi2<3*NDF;
338
339 if (paint)
340 {
341 func.SetLineWidth(2);
342 func.SetLineColor(ok ? kGreen : kRed);
343 func.Paint("same");
344 }
345
346 const Double_t lambda = func.GetParameter(0);
347 //const Double_t N0 = func.GetParameter(1);
348 const Double_t prob = func.GetProb();
349
350 /*
351 *fLog << all << "Nm/lambda=" << Nm/lambda << " chi2/NDF=";
352 *fLog << (NDF ? chi2/NDF : 0.0) << " lambda=";
353 *fLog << lambda << " N0=" << N0 << endl;
354 */
355
356 Double_t emat[2][2];
357 gMinuit->mnemat((Double_t*)emat, 2);
358
359 const Double_t dldl = emat[0][0];
360 //const Double_t dN0dN0 = emat[1][1];
361
362 const Double_t teff = Nm/lambda;
363 const Double_t dteff = teff * TMath::Sqrt(dldl/(lambda*lambda) + 1.0/Nm);
364 const Double_t dl = TMath::Sqrt(dldl);
365
366 //const Double_t kappa = Nm/N0;
367 //const Double_t Rdead = 1.0 - kappa;
368 //const Double_t dRdead = kappa * TMath::Sqrt(dN0dN0/(N0*N0) + 1.0/Nm);
369
370 // the effective on time is Nm/lambda
371 res[0] = teff;
372 res[1] = dteff;
373
374 // plot chi2-probability of fit
375 res[2] = prob*100;
376
377 // lambda of fit
378 res[3] = lambda;
379 res[4] = dl;
380
381 // NDoF of fit
382 res[5] = NDF;
383
384 // Chi2
385 res[6] = chi2;
386
387 // Rdead (from fit) is the fraction from real time lost by the dead time
388 //fHRdead.SetBinContent(i, Rdead);
389 //fHRdead.SetBinError (i,dRdead);
390
391 return ok;
392}
393
394// --------------------------------------------------------------------------
395//
396// Fit a all bins of the distribution in theta. Store the result in the
397// Theta-Histograms
398//
399void MHEffectiveOnTime::FitThetaBins()
400{
401 fHThetaEffOn.Reset();
402 fHThetaProb.Reset();
403 fHThetaLambda.Reset();
404 fHThetaNDF.Reset();
405
406 const TString name = Form("CalcTheta%d", (UInt_t)gRandom->Uniform(999999999));
407
408 // nbins = number of Theta bins
409 const Int_t nbins = fH2DeltaT.GetNbinsY();
410
411 TH1D *h=0;
412 for (int i=1; i<=nbins; i++)
413 {
414 // TH1D &h = *hist->ProjectionX("Calc-theta", i, i);
415 h = fH2DeltaT.ProjectionX(name, i, i, "E");
416
417 Double_t res[7];
418 if (!FitH(h, res))
419 continue;
420
421 // the effective on time is Nm/lambda
422 fHThetaEffOn.SetBinContent(i, res[0]);
423 fHThetaEffOn.SetBinError (i, res[1]);
424
425 // plot chi2-probability of fit
426 fHThetaProb.SetBinContent(i, res[2]);
427
428 // plot chi2/NDF of fit
429 //fHChi2.SetBinContent(i, res[3]);
430
431 // lambda of fit
432 fHThetaLambda.SetBinContent(i, res[3]);
433 fHThetaLambda.SetBinError (i, res[4]);
434
435 // NDoF of fit
436 fHThetaNDF.SetBinContent(i, res[5]);
437
438 // Rdead (from fit) is the fraction from real time lost by the dead time
439 //fHRdead.SetBinContent(i, Rdead);
440 //fHRdead.SetBinError (i,dRdead);
441 }
442
443 // Histogram is reused via gROOT->FindObject()
444 // Need to be deleted only once
445 if (h)
446 delete h;
447}
448
449// --------------------------------------------------------------------------
450//
451// Fit the single-time-bin histogram. Store the result in the
452// Time-Histograms
453//
454void MHEffectiveOnTime::FitTimeBin()
455{
456 //
457 // Fit histogram
458 //
459 Double_t res[7];
460 if (!FitH(&fH1DeltaT, res))
461 return;
462
463 // Reset Histogram
464 fH1DeltaT.Reset();
465
466 //
467 // Prepare Histogram
468 //
469
470 // Get number of bins
471 const Int_t n = fHTimeEffOn.GetNbinsX();
472
473 // Enhance binning
474 MBinning bins;
475 bins.SetEdges(fHTimeEffOn, 'x');
476 bins.AddEdge(fLastTime.GetAxisTime());
477 bins.Apply(fHTimeEffOn);
478 bins.Apply(fHTimeProb);
479 bins.Apply(fHTimeLambda);
480 //bins.Apply(fHTimeNDF);
481
482 //
483 // Fill histogram
484 //
485 fHTimeEffOn.SetBinContent(n, res[0]);
486 fHTimeEffOn.SetBinError(n, res[1]);
487
488 fHTimeProb.SetBinContent(n, res[2]);
489
490 fHTimeLambda.SetBinContent(n, res[3]);
491 fHTimeLambda.SetBinError(n, res[4]);
492
493 //fHTimeNDF.SetBinContent(n, res[5]);
494
495 //
496 // Now prepare output
497 //
498 fParam->SetVal(res[0], res[1]);
499 fParam->SetReadyToSave();
500
501 *fTime = fLastTime;
502
503 // Include the current event
504 fTime->Plus1ns();
505
506 *fLog << fLastTime << ": Val=" << res[0] << " Err=" << res[1] << endl;
507}
508
509// --------------------------------------------------------------------------
510//
511// Fill the histogram
512//
513Bool_t MHEffectiveOnTime::Fill(const MParContainer *par, const Stat_t w)
514{
515 const MTime *time = dynamic_cast<const MTime*>(par);
516 if (!time)
517 {
518 *fLog << err << "ERROR - MHEffectiveOnTime::Fill without argument or container doesn't inherit from MTime... abort." << endl;
519 return kFALSE;
520 }
521
522 //
523 // If this is the first call we have to initialize the time-histogram
524 //
525 if (fLastTime==MTime())
526 {
527 MBinning bins;
528 bins.SetEdges(1, time->GetAxisTime()-fNumEvents/200, time->GetAxisTime());
529 bins.Apply(fHTimeEffOn);
530 bins.Apply(fHTimeProb);
531 bins.Apply(fHTimeLambda);
532 //bins.Apply(fHTimeNDF);
533
534 fParam->SetVal(0, 0);
535 fParam->SetReadyToSave();
536
537 *fTime = *time;
538
539 // Make this 1ns before the first event!
540 fTime->Minus1ns();
541 }
542
543 //
544 // Fill time difference into the histograms
545 //
546 const Double_t dt = *time-fLastTime;
547 fLastTime = *time;
548
549 fH2DeltaT.Fill(dt, fPointPos->GetZd(), w);
550 fH1DeltaT.Fill(dt, w);
551
552 //
553 // If we reached the event number limit for the time-bins fit the
554 // histogram - if it fails try again when 1.6% more events available
555 //
556 const Int_t n = (Int_t)fH1DeltaT.GetEntries();
557 if (n>=fNumEvents && n%(fNumEvents/60)==0)
558 FitTimeBin();
559
560 return kTRUE;
561}
562
563// --------------------------------------------------------------------------
564//
565// Fit the theta projections of the 2D histogram and the 1D Delta-T
566// distribution
567//
568Bool_t MHEffectiveOnTime::Finalize()
569{
570 FitThetaBins();
571 FitTimeBin();
572 MH::RemoveFirstBin(fHTimeEffOn);
573 MH::RemoveFirstBin(fHTimeProb);
574 MH::RemoveFirstBin(fHTimeLambda);
575 //MH::RemoveFirstBin(fHTimeNDF);
576
577 fIsFinalized = kTRUE;
578
579 return kTRUE;
580}
581
582// --------------------------------------------------------------------------
583//
584// Paint the integral and the error on top of the histogram
585//
586void MHEffectiveOnTime::PaintText(Double_t val, Double_t error) const
587{
588 TLatex text(0.45, 0.94, Form("T_{eff} = %.1fs \\pm %.1fs", val, error));
589 text.SetBit(TLatex::kTextNDC);
590 text.SetTextSize(0.04);
591 text.Paint();
592}
593
594void MHEffectiveOnTime::PaintText(Double_t *res) const
595{
596 TLatex text(0.27, 0.94, Form("T_{eff}=%.1fs\\pm%.1fs \\lambda=%.1f\\pm%.1fHz p=%.1f%% \\chi^{2}/%d=%.1f",
597 res[0], res[1], res[3], res[4], res[2], (int)res[5], res[6]/res[5]));
598 text.SetBit(TLatex::kTextNDC);
599 text.SetTextSize(0.04);
600 text.Paint();
601}
602
603void MHEffectiveOnTime::PaintProb(TH1 &h) const
604{
605 Double_t sum = 0;
606 Int_t n = 0;
607 for (int i=0; i<h.GetNbinsX(); i++)
608 if (h.GetBinContent(i+1)>0)
609 {
610 sum += h.GetBinContent(i+1);
611 n++;
612 }
613
614 if (n==0)
615 return;
616
617 TLatex text(0.47, 0.94, Form("\\bar{p} = %.1f%%", sum/n));
618 text.SetBit(TLatex::kTextNDC);
619 text.SetTextSize(0.04);
620 text.Paint();
621}
622
623void MHEffectiveOnTime::UpdateRightAxis(TH1 &h)
624{
625 const Double_t max = h.GetMaximum()*1.1;
626 if (max==0)
627 return;
628
629 h.SetNormFactor(h.Integral()*gPad->GetUymax()/max);
630
631 TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
632 if (!axis)
633 return;
634
635 axis->SetX1(gPad->GetUxmax());
636 axis->SetX2(gPad->GetUxmax());
637 axis->SetY1(gPad->GetUymin());
638 axis->SetY2(gPad->GetUymax());
639 axis->SetWmax(max);
640}
641
642// --------------------------------------------------------------------------
643//
644// Prepare painting the histograms
645//
646void MHEffectiveOnTime::Paint(Option_t *opt)
647{
648 TH1D *h=0;
649 TPaveStats *st=0;
650
651 TString o(opt);
652 if (o==(TString)"fit")
653 {
654 TVirtualPad *pad = gPad;
655
656 for (int x=0; x<2; x++)
657 for (int y=0; y<3; y++)
658 {
659 TVirtualPad *p=gPad->GetPad(x+1)->GetPad(y+1);
660 if (!(st = (TPaveStats*)p->GetPrimitive("stats")))
661 continue;
662
663 if (st->GetOptStat()==11)
664 continue;
665
666 const Double_t y1 = st->GetY1NDC();
667 const Double_t y2 = st->GetY2NDC();
668 const Double_t x1 = st->GetX1NDC();
669 const Double_t x2 = st->GetX2NDC();
670
671 st->SetY1NDC((y2-y1)/3+y1);
672 st->SetX1NDC((x2-x1)/3+x1);
673 st->SetOptStat(11);
674 }
675
676 pad->GetPad(1)->cd(1);
677 if ((h = (TH1D*)gPad->FindObject(fNameProjDeltaT)))
678 {
679 h = fH2DeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
680 if (h->GetEntries()>0)
681 gPad->SetLogy();
682 }
683
684 pad->GetPad(2)->cd(1);
685 if ((h = (TH1D*)gPad->FindObject(fNameProjTheta)))
686 fH2DeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
687
688 if (!fIsFinalized)
689 FitThetaBins();
690 return;
691 }
692 if (o==(TString)"paint")
693 {
694 if ((h = (TH1D*)gPad->FindObject(fNameProjDeltaT)))
695 {
696 Double_t res[7];
697 FitH(h, res, kTRUE);
698 PaintText(res);
699 }
700 return;
701 }
702
703 if (o==(TString)"timendf")
704 {
705 // UpdateRightAxis(fHTimeNDF);
706 // FIXME: first bin?
707 PaintProb(fHTimeProb);
708 }
709
710 if (o==(TString)"thetandf")
711 {
712 UpdateRightAxis(fHThetaNDF);
713 // FIXME: first bin?
714 PaintProb(fHThetaProb);
715 }
716
717 h=0;
718 if (o==(TString)"theta")
719 {
720 h = &fHThetaEffOn;
721 UpdateRightAxis(fHThetaLambda);
722 }
723 if (o==(TString)"time")
724 {
725 h = &fHTimeEffOn;
726 UpdateRightAxis(fHTimeLambda);
727 }
728
729 if (!h)
730 return;
731
732 Double_t error = 0;
733 for (int i=0; i<h->GetXaxis()->GetNbins(); i++)
734 error += h->GetBinError(i);
735
736 PaintText(h->Integral(), error);
737}
738
739void MHEffectiveOnTime::DrawRightAxis(const char *title)
740{
741 TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
742 gPad->GetUxmax(), gPad->GetUymax(),
743 0, 1, 510, "+L");
744 axis->SetName("RightAxis");
745 axis->SetTitle(title);
746 axis->SetTitleOffset(0.9);
747 axis->SetTextColor(kGreen);
748 axis->CenterTitle();
749 axis->SetBit(kCanDelete);
750 axis->Draw();
751}
752
753// --------------------------------------------------------------------------
754//
755// Draw the histogram
756//
757void MHEffectiveOnTime::Draw(Option_t *opt)
758{
759 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
760 pad->SetBorderMode(0);
761
762 AppendPad("fit");
763
764 pad->Divide(2, 1, 0, 0);
765
766 TH1 *h;
767
768 pad->cd(1);
769 gPad->SetBorderMode(0);
770 gPad->Divide(1, 3, 0, 0);
771 pad->GetPad(1)->cd(1);
772 gPad->SetBorderMode(0);
773 h = fH2DeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
774 h->SetTitle("Distribution of \\Delta t [s]");
775 h->SetXTitle("\\Delta t [s]");
776 h->SetYTitle("Counts");
777 h->SetDirectory(NULL);
778 h->SetMarkerStyle(kFullDotMedium);
779 h->SetBit(kCanDelete);
780 h->Draw();
781 AppendPad("paint");
782
783 pad->GetPad(1)->cd(2);
784 gPad->SetBorderMode(0);
785 fHTimeProb.Draw();
786 AppendPad("timendf");
787 //fHTimeNDF.Draw("same");
788 //DrawRightAxis("NDF");
789
790 pad->GetPad(1)->cd(3);
791 gPad->SetBorderMode(0);
792 fHTimeEffOn.Draw();
793 AppendPad("time");
794 fHTimeLambda.Draw("same");
795 DrawRightAxis("\\lambda [s^{-1}]");
796
797 pad->cd(2);
798 gPad->SetBorderMode(0);
799 gPad->Divide(1, 3, 0, 0);
800
801 pad->GetPad(2)->cd(1);
802 gPad->SetBorderMode(0);
803 h = fH2DeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
804 h->SetTitle("Distribution of \\Theta [\\circ]");
805 h->SetXTitle("\\Theta [\\circ]");
806 h->SetYTitle("Counts");
807 h->SetDirectory(NULL);
808 h->SetMarkerStyle(kFullDotMedium);
809 h->SetBit(kCanDelete);
810 h->GetYaxis()->SetTitleOffset(1.1);
811 h->Draw();
812
813 pad->GetPad(2)->cd(2);
814 gPad->SetBorderMode(0);
815 fHThetaProb.Draw();
816 AppendPad("thetandf");
817 fHThetaNDF.Draw("same");
818 DrawRightAxis("NDF");
819
820 pad->GetPad(2)->cd(3);
821 gPad->SetBorderMode(0);
822 fHThetaEffOn.Draw();
823 AppendPad("theta");
824 fHThetaLambda.Draw("same");
825 DrawRightAxis("\\lambda [s^{-1}]");
826}
Note: See TracBrowser for help on using the repository browser.