source: trunk/MagicSoft/Mars/mhflux/MHAlpha.cc@ 5901

Last change on this file since 5901 was 5901, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 24.0 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, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MHAlpha
28//
29// Create a single Alpha-Plot. The alpha-plot is fitted online. You can
30// check the result when it is filles in the MStatusDisplay
31// For more information see MHFalseSource::FitSignificance
32//
33// For convinience (fit) the output significance is stored in a
34// container in the parlisrt
35//
36// PRELIMINARY!
37//
38//////////////////////////////////////////////////////////////////////////////
39#include "MHAlpha.h"
40
41#include <TF1.h>
42#include <TGraph.h>
43#include <TStyle.h>
44#include <TLatex.h>
45#include <TCanvas.h>
46#include <TPaveStats.h>
47#include <TStopwatch.h>
48
49#include "MGeomCam.h"
50#include "MSrcPosCam.h"
51#include "MHillasSrc.h"
52#include "MEnergyEst.h"
53#include "MTime.h"
54#include "MObservatory.h"
55#include "MPointingPos.h"
56#include "MAstroSky2Local.h"
57#include "MStatusDisplay.h"
58#include "MParameters.h"
59#include "MHMatrix.h"
60
61#include "MBinning.h"
62#include "MParList.h"
63
64#include "MLog.h"
65#include "MLogManip.h"
66
67ClassImp(MHAlpha);
68ClassImp(MAlphaFitter);
69
70using namespace std;
71
72// --------------------------------------------------------------------------
73//
74// Default Constructor
75//
76MHAlpha::MHAlpha(const char *name, const char *title)
77 : fOffData(0), fResult(0), /*fExcess(0),*/ fEnergy(0), fHillas(0),
78 fPointPos(0), fTimeEffOn(0), fTime(0),
79 fSkipHistTime(kFALSE), fSkipHistTheta(kFALSE), fSkipHistEnergy(kFALSE),
80 //fEnergyMin(-1), fEnergyMax(-1), fSizeMin(-1), fSizeMax(-1),
81 fMatrix(0)
82{
83 //
84 // set the name and title of this object
85 //
86 fName = name ? name : "MHAlpha";
87 fTitle = title ? title : "Alpha plot";
88
89 fHAlpha.SetName("Alpha");
90 fHAlpha.SetTitle("Alpha");
91 fHAlpha.SetXTitle("\\Theta [deg]");
92 fHAlpha.SetYTitle("E_{est} [GeV]");
93 fHAlpha.SetZTitle("|\\alpha| [\\circ]");
94 fHAlpha.SetDirectory(NULL);
95 fHAlpha.UseCurrentStyle();
96
97 // Main histogram
98 fHAlphaTime.SetName("Alpha");
99 fHAlphaTime.SetXTitle("|\\alpha| [\\circ]");
100 fHAlphaTime.SetYTitle("Counts");
101 fHAlphaTime.UseCurrentStyle();
102 fHAlphaTime.SetDirectory(NULL);
103
104
105 //fHEnergy.SetName("Energy");
106 //fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");
107 //fHEnergy.SetXTitle("E_{est} [GeV]");
108 fHEnergy.SetYTitle("N_{exc}");
109 fHEnergy.SetDirectory(NULL);
110 fHEnergy.UseCurrentStyle();
111
112 fHTheta.SetName("Theta");
113 fHTheta.SetTitle(" N_{exc} vs. \\Theta ");
114 fHTheta.SetXTitle("\\Theta [\\circ]");
115 fHTheta.SetYTitle("N_{exc}");
116 fHTheta.SetDirectory(NULL);
117 fHTheta.UseCurrentStyle();
118
119 // effective on time versus time
120 fHTime.SetName("Time");
121 fHTime.SetTitle(" N_{exc} vs. Time ");
122 fHTime.SetXTitle("Time");
123 fHTime.SetYTitle("N_{exc} [s]");
124 fHTime.UseCurrentStyle();
125 fHTime.SetDirectory(NULL);
126 fHTime.GetYaxis()->SetTitleOffset(1.2);
127 fHTime.GetXaxis()->SetLabelSize(0.033);
128 fHTime.GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
129 fHTime.GetXaxis()->SetTimeDisplay(1);
130 fHTime.Sumw2();
131
132 MBinning binsa, binse, binst;
133 binsa.SetEdges(18, 0, 90);
134 binse.SetEdgesLog(25, 10, 100000);
135 binst.SetEdgesCos(50, 0, 60);
136 binse.Apply(fHEnergy);
137 binst.Apply(fHTheta);
138 binsa.Apply(fHAlphaTime);
139
140 MH::SetBinning(&fHAlpha, &binst, &binse, &binsa);
141}
142
143void MHAlpha::FitEnergySpec(Bool_t paint)
144{
145 /*
146 TF1 f("Spectrum", "pow(x, [0])*exp(-x/[1])*[2]*x");//
147 f.SetParameter(0, -2.1);
148 f.SetParameter(1, 1400); // 50
149 f.SetParameter(2, fHEnergy.Integral()); // 50
150 f.SetLineWidth(2);
151
152 fHEnergy.Fit(&f, "0QI", "", 100, 2400); // Integral? 90, 2800
153
154 const Double_t chi2 = f.GetChisquare();
155 const Int_t NDF = f.GetNDF();
156
157 // was fit successful ?
158 const Bool_t ok = NDF>0 && chi2<2.5*NDF;
159 f.SetLineColor(ok ? kGreen : kRed);
160
161 if (paint)
162 {
163 f.Paint("same");
164
165 if (ok)
166 {
167 TString s;
168 s += Form("\\alpha=%.1f ", f.GetParameter(0));
169 s += Form("E_{c}=%.1f TeV ", f.GetParameter(1)/1000);
170 s += Form("N=%.1e", f.GetParameter(2));
171
172 TLatex text(0.25, 0.94, s.Data());
173 text.SetBit(TLatex::kTextNDC);
174 text.SetTextSize(0.04);
175 text.Paint();
176 }
177 }*/
178}
179
180void MHAlpha::FitEnergyBins(Bool_t paint)
181{
182 // Do not store the 'final' result in fFit
183 MAlphaFitter fit(fFit);
184
185 const Int_t n = fHAlpha.GetNbinsY();
186
187 fHEnergy.SetEntries(0);
188
189 for (int i=1; i<=n; i++)
190 {
191 if (fit.FitEnergy(fHAlpha, fOffData, i))
192 {
193 fHEnergy.SetBinContent(i, fit.GetEventsExcess());
194 fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2);
195 }
196 }
197}
198
199void MHAlpha::FitThetaBins(Bool_t paint)
200{
201 // Do not store the 'final' result in fFit
202 MAlphaFitter fit(fFit);
203
204 const Int_t n = fHAlpha.GetNbinsX();
205
206 fHTheta.SetEntries(0);
207
208 for (int i=1; i<=n; i++)
209 {
210 if (fit.FitTheta(fHAlpha, fOffData, i))
211 {
212 fHTheta.SetBinContent(i, fit.GetEventsExcess());
213 fHTheta.SetBinError(i, fit.GetEventsExcess()*0.2);
214 }
215 }
216}
217
218Bool_t MHAlpha::SetupFill(const MParList *pl)
219{
220 fHAlpha.Reset();
221 fHEnergy.Reset();
222 fHTheta.Reset();
223 fHTime.Reset();
224
225 if (fName!=(TString)"MHAlphaOff" && fOffData==NULL)
226 {
227 MHAlpha *hoff = (MHAlpha*)pl->FindObject("MHAlphaOff", "MHAlpha");
228 if (!hoff)
229 *fLog << inf << "No MHAlphaOff [MHAlpha] found... using current data only!" << endl;
230 else
231 {
232 *fLog << inf << "MHAlphaOff [MHAlpha] found... using on-off mode!" << endl;
233 SetOffData(*hoff);
234 }
235 }
236
237 fHillas = 0;
238 /*
239 if (fSizeMin>=0 || fSizeMax>=0)
240 {
241 fHillas = (MHillas*)pl->FindObject("MHillas");
242 if (!fHillas)
243 {
244 *fLog << warn << "Size cut set, but MHillas not found... abort." << endl;
245 return kFALSE;
246 }
247 }
248 */
249 fEnergy = (MEnergyEst*)pl->FindObject("MEnergyEst");
250 if (!fEnergy)
251 { /*
252 if (fEnergyMin>=0 || fEnergyMax>=0)
253 {
254 *fLog << warn << "Energy cut set, but MEnergyEst not found... abort." << endl;
255 return kFALSE;
256 } */
257
258 *fLog << warn << "MEnergyEst not found... " << flush;
259
260 if (!fHillas)
261 fHillas = (MHillas*)pl->FindObject("MHillas");
262 if (fHillas)
263 *fLog << "using SIZE instead!" << endl;
264 else
265 *fLog << "ignored." << endl;
266
267 fHEnergy.SetName("Size");
268 fHEnergy.SetTitle(" N_{exc} vs. Size ");
269 fHEnergy.SetXTitle("Size [\\gamma]");
270 }
271 else
272 {
273 fHEnergy.SetName("Energy");
274 fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");
275 fHEnergy.SetXTitle("E_{est} [GeV]");
276 }
277
278 fPointPos = (MPointingPos*)pl->FindObject("MPointingPos");
279 if (!fPointPos)
280 *fLog << warn << "MPointingPos not found... ignored." << endl;
281
282 fTimeEffOn = (MTime*)pl->FindObject("MTimeEffectiveOnTime", "MTime");
283 if (!fTimeEffOn)
284 *fLog << warn << "MTimeEffectiveOnTime [MTime] not found... ignored." << endl;
285 else
286 *fTimeEffOn = MTime(); // FIXME: How to do it different?
287
288 fTime = (MTime*)pl->FindObject("MTime");
289 if (!fTime)
290 *fLog << warn << "MTime not found... ignored." << endl;
291
292 fResult = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "MinimizationValue");
293 if (!fResult)
294 return kFALSE;
295
296 //fExcess = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "MExcess");
297 //if (!fExcess)
298 // return kFALSE;
299
300 fLastTime = MTime();
301
302 MBinning binst, binse, binsa;
303 binst.SetEdges(fOffData ? *fOffData : fHAlpha, 'x');
304 binse.SetEdges(fOffData ? *fOffData : fHAlpha, 'y');
305 binsa.SetEdges(fOffData ? *fOffData : fHAlpha, 'z');
306
307 if (!fOffData)
308 {
309 if (!fPointPos)
310 binst.SetEdges(1, 0, 60);
311 else
312 binst.SetEdges(*pl, "BinningTheta");
313
314 if (!fEnergy && !fHillas)
315 binse.SetEdges(1, 10, 100000);
316 else
317 binse.SetEdges(*pl, "BinningEnergyEst");
318
319 binsa.SetEdges(*pl, "BinningAlpha");
320 }
321
322 binse.Apply(fHEnergy);
323 binst.Apply(fHTheta);
324 binsa.Apply(fHAlphaTime);
325 MH::SetBinning(&fHAlpha, &binst, &binse, &binsa);
326
327 MAlphaFitter *fit = (MAlphaFitter*)pl->FindObject("MAlphaFitter");
328 if (!fit)
329 *fLog << warn << "MAlphaFitter not found... ignored." << endl;
330 else
331 fit->Copy(fFit);
332
333 fFit.Print();
334
335 return kTRUE;
336}
337
338void MHAlpha::InitAlphaTime(const MTime &t)
339{
340 //
341 // If this is the first call we have to initialize the time-histogram
342 //
343 MBinning bins;
344 bins.SetEdges(1, t.GetAxisTime()-60, t.GetAxisTime());
345 bins.Apply(fHTime);
346
347 fLastTime=t;
348}
349
350void MHAlpha::UpdateAlphaTime(Bool_t final)
351{
352 if (!fTimeEffOn)
353 return;
354
355 const Int_t steps = 10;
356
357 static int rebin = steps;
358
359 if (!final)
360 {
361 if (fLastTime==MTime() && *fTimeEffOn!=MTime())
362 {
363 InitAlphaTime(*fTimeEffOn);
364 return;
365 }
366
367 if (fLastTime!=*fTimeEffOn)
368 {
369 fLastTime=*fTimeEffOn;
370 rebin--;
371 }
372
373 if (rebin>0)
374 return;
375 }
376
377 // Check new 'last time'
378 MTime *time = final ? fTime : fTimeEffOn;
379
380 if (time->GetAxisTime()<=fHTime.GetXaxis()->GetXmax())
381 {
382 *fLog << warn << "WARNING - New time-stamp " << *time << " lower" << endl;
383 *fLog << "than upper edge of histogram... skipped." << endl;
384 *fLog << "This should not happen. Maybe you started you eventloop with" << endl;
385 *fLog << "an already initialized time stamp MTimeEffectiveOnTime?" << endl;
386 rebin++;
387 return;
388 }
389
390 // Fit time histogram
391 MAlphaFitter fit(fFit);
392
393 TH1D *h = fOffData ? fOffData->ProjectionZ("ProjTimeTemp", -1, 9999, -1, 9999, "E") : 0;
394 const Bool_t rc = fit.ScaleAndFit(fHAlphaTime, h);
395 if (h)
396 delete h;
397
398 if (!rc)
399 return;
400
401 // Reset Histogram
402 fHAlphaTime.Reset();
403 fHAlphaTime.SetEntries(0);
404
405 // Get number of bins
406 const Int_t n = fHTime.GetNbinsX();
407
408 //
409 // Prepare Histogram
410 //
411 if (final)
412 time->Plus1ns();
413
414 // Enhance binning
415 MBinning bins;
416 bins.SetEdges(fHTime, 'x');
417 bins.AddEdge(time->GetAxisTime());
418 bins.Apply(fHTime);
419
420 //
421 // Fill histogram
422 //
423 fHTime.SetBinContent(n+1, fit.GetEventsExcess());
424 fHTime.SetBinError(n+1, fit.GetEventsExcess()*0.1);
425
426 *fLog << all << *fTimeEffOn << ": " << fit.GetEventsExcess() << endl;
427
428 rebin = steps;
429}
430
431// --------------------------------------------------------------------------
432//
433// Fill the histogram. For details see the code or the class description
434//
435Bool_t MHAlpha::Fill(const MParContainer *par, const Stat_t w)
436{
437 Double_t alpha, energy, theta;
438 Double_t size=-1;
439
440 if (fMatrix)
441 {
442 alpha = (*fMatrix)[fMap[0]];
443 energy = fMap[1]<0 ? -1 : (*fMatrix)[fMap[1]];
444 size = fMap[2]<0 ? -1 : (*fMatrix)[fMap[2]];
445 //<0 ? 1000 : (*fMatrix)[fMap[1]];
446 theta = 0;
447
448 if (energy<0)
449 energy=size;
450 if (size<0)
451 size=energy;
452
453 if (energy<0 && size<0)
454 energy = size = 1000;
455 }
456 else
457 {
458 const MHillasSrc *hil = dynamic_cast<const MHillasSrc*>(par);
459 if (!par)
460 {
461 *fLog << err << dbginf << "MHillasSrc not found... abort." << endl;
462 return kFALSE;
463 }
464
465 alpha = hil->GetAlpha();
466 if (fHillas)
467 size = fHillas->GetSize();
468 energy = fEnergy ? fEnergy->GetEnergy() : (fHillas?fHillas->GetSize():1000);
469 theta = fPointPos ? fPointPos->GetZd() : 0;
470 }
471
472 // enhance histogram if necessary
473 UpdateAlphaTime();
474
475 // Fill histograms
476 fHAlpha.Fill(theta, energy, TMath::Abs(alpha), w);
477
478 // Check cuts
479 /*
480 if ( (fEnergyMin>=0 && energy<fEnergyMin) ||
481 (fEnergyMax>=0 && energy>fEnergyMax) ||
482 (fSizeMin>=0 && size <fSizeMin) ||
483 (fSizeMax>=0 && size >fSizeMin) )
484 return kTRUE;
485 */
486
487 if (!fSkipHistTime)
488 fHAlphaTime.Fill(TMath::Abs(alpha), w);
489
490 return kTRUE;
491}
492
493// --------------------------------------------------------------------------
494//
495// Paint the integral and the error on top of the histogram
496//
497void MHAlpha::PaintText(Double_t val, Double_t error) const
498{
499 TLatex text(0.45, 0.94, Form("N_{exc} = %.1f \\pm %.1f", val, error));
500 text.SetBit(TLatex::kTextNDC);
501 text.SetTextSize(0.04);
502 text.Paint();
503}
504
505// --------------------------------------------------------------------------
506//
507// Update the projections
508//
509void MHAlpha::Paint(Option_t *opt)
510{
511 // Note: Any object cannot be added to a pad twice!
512 // The object is searched by gROOT->FindObject only in
513 // gPad itself!
514 TVirtualPad *padsave = gPad;
515
516 TH1D *h0=0;
517
518 TString o(opt);
519 if (o==(TString)"proj")
520 {
521 TPaveStats *st=0;
522 for (int x=0; x<4; x++)
523 {
524 TVirtualPad *p=padsave->GetPad(x+1);
525 if (!p || !(st = (TPaveStats*)p->GetPrimitive("stats")))
526 continue;
527
528 if (st->GetOptStat()==11)
529 continue;
530
531 const Double_t y1 = st->GetY1NDC();
532 const Double_t y2 = st->GetY2NDC();
533 const Double_t x1 = st->GetX1NDC();
534 const Double_t x2 = st->GetX2NDC();
535
536 st->SetY1NDC((y2-y1)/3+y1);
537 st->SetX1NDC((x2-x1)/3+x1);
538 st->SetOptStat(11);
539 }
540
541 padsave->cd(1);
542 TH1D *hon = fHAlpha.ProjectionZ("ProjAlpha");
543 if (fOffData)
544 {
545 TH1D *hoff = fOffData->ProjectionZ("ProjAlphaOff");
546 const Double_t alpha = fFit.Scale(*hoff, *hon);
547
548 hon->SetMaximum();
549 hon->SetMaximum(TMath::Max(hon->GetMaximum(), hoff->GetMaximum())*1.05);
550
551 // BE CARFEULL: This is a really weird workaround!
552 hoff->SetMaximum(alpha);
553
554 if ((h0=(TH1D*)gPad->FindObject("ProjAlphaOnOff")))
555 {
556 h0->Reset();
557 h0->Add(hoff, hon, -1);
558 const Float_t min = h0->GetMinimum()*1.05;
559 hon->SetMinimum(min<0 ? min : 0);
560 }
561 }
562 FitEnergyBins();
563 FitThetaBins();
564 }
565
566 if (o==(TString)"alpha")
567 if ((h0 = (TH1D*)gPad->FindObject("ProjAlpha")))
568 {
569 // Check whether we are dealing with on-off analysis
570 TH1D *hoff = (TH1D*)gPad->FindObject("ProjAlphaOff");
571 if (hoff)
572 {
573 // Do not store the 'final' result in fFit
574 MAlphaFitter fit(fFit);
575
576 // BE CARFEULL: This is a really weird workaround!
577 const Double_t alpha = hoff->GetMaximum();
578 fit.Fit(*h0, hoff, alpha<0 ? 1: alpha, kTRUE);
579
580 fit.PaintResult();
581 }
582 }
583
584 if (o==(TString)"time")
585 PaintText(fHTime.Integral(), 0);
586
587 if (o==(TString)"theta")
588 {
589 TH1 *h = (TH1*)gPad->FindObject("Alpha_x");
590 if (h)
591 {
592 TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_x");
593 h2->SetDirectory(0);
594 h2->Scale(fHTheta.Integral()/h2->Integral());
595 h->Reset();
596 h->Add(h2);
597 delete h2;
598 }
599 PaintText(fHTheta.Integral(), 0);
600 }
601
602 if (o==(TString)"energy")
603 {
604 TH1 *h = (TH1*)gPad->FindObject("Alpha_y");
605 if (h)
606 {
607 TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_y");
608 h2->SetDirectory(0);
609 h2->Scale(fHEnergy.Integral()/h2->Integral());
610 h->Reset();
611 h->Add(h2);
612 delete h2;
613 }
614
615 if (fHEnergy.GetMaximum()>1)
616 {
617 gPad->SetLogx();
618 gPad->SetLogy();
619 }
620 FitEnergySpec(kTRUE);
621 }
622
623 gPad = padsave;
624}
625
626// --------------------------------------------------------------------------
627//
628// Draw the histogram
629//
630void MHAlpha::Draw(Option_t *opt)
631{
632 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
633
634 // Do the projection before painting the histograms into
635 // the individual pads
636 AppendPad("proj");
637
638 pad->SetBorderMode(0);
639 pad->Divide(2,2);
640
641 TH1D *h=0;
642
643 pad->cd(1);
644 gPad->SetBorderMode(0);
645
646 h = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, -1, 9999, "E");
647 h->SetBit(TH1::kNoTitle);
648 h->SetStats(kTRUE);
649 h->SetXTitle("\\alpha [\\circ]");
650 h->SetYTitle("Counts");
651 h->SetDirectory(NULL);
652 h->SetMarkerStyle(kFullDotMedium);
653 h->SetBit(kCanDelete);
654 h->Draw("");
655
656 if (fOffData)
657 {
658 h->SetMarkerColor(kGreen);
659
660 h = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, -1, 9999, "E");
661 h->SetBit(TH1::kNoTitle);
662 h->SetXTitle("\\alpha [\\circ]");
663 h->SetYTitle("Counts");
664 h->SetDirectory(NULL);
665 h->SetMarkerStyle(kFullDotMedium);
666 h->SetBit(kCanDelete);
667 h->SetMarkerColor(kRed);
668 h->Draw("same");
669
670 h = (TH1D*)h->Clone("ProjAlphaOnOff");
671 h->SetBit(TH1::kNoTitle);
672 h->SetXTitle("\\alpha [\\circ]");
673 h->SetYTitle("Counts");
674 h->SetDirectory(NULL);
675 h->SetMarkerStyle(kFullDotMedium);
676 h->SetBit(kCanDelete);
677 h->SetMarkerColor(kBlue);
678 h->Draw("same");
679
680 TLine lin;
681 lin.SetLineStyle(kDashed);
682 lin.DrawLine(0, 0, 90, 0);
683 }
684
685 // After the Alpha-projection has been drawn. Fit the histogram
686 // and paint the result into this pad
687 AppendPad("alpha");
688
689 if (fHEnergy.GetNbinsX()>1)
690 {
691 pad->cd(2);
692 gPad->SetBorderMode(0);
693 fHEnergy.Draw();
694
695 AppendPad("energy");
696
697 h = (TH1D*)fHAlpha.Project3D("y");
698 h->SetBit(TH1::kNoTitle|TH1::kNoStats);
699 h->SetXTitle("E [GeV]");
700 h->SetYTitle("Counts");
701 h->SetDirectory(NULL);
702 h->SetMarkerStyle(kFullDotMedium);
703 h->SetBit(kCanDelete);
704 h->SetMarkerColor(kCyan);
705 h->SetLineColor(kCyan);
706 h->Draw("Psame");
707 }
708 else
709 delete pad->GetPad(2);
710
711 if (fTimeEffOn && fTime || fHTime.GetNbinsX()>1)
712 {
713 pad->cd(3);
714 gPad->SetBorderMode(0);
715 fHTime.Draw();
716 AppendPad("time");
717 }
718 else
719 delete pad->GetPad(3);
720
721 if (fHTheta.GetNbinsX()>1)
722 {
723 pad->cd(4);
724 gPad->SetBorderMode(0);
725 fHTheta.Draw();
726
727 AppendPad("theta");
728
729 h = (TH1D*)fHAlpha.Project3D("x");
730 h->SetBit(TH1::kNoTitle|TH1::kNoStats);
731 h->SetXTitle("\\theta [\\circ]");
732 h->SetYTitle("Counts");
733 h->SetDirectory(NULL);
734 h->SetMarkerStyle(kFullDotMedium);
735 h->SetBit(kCanDelete);
736 h->SetMarkerColor(kCyan);
737 h->SetLineColor(kCyan);
738 h->Draw("Psame");
739 }
740 else
741 delete pad->GetPad(4);
742}
743
744void MHAlpha::DrawAll()
745{
746 // FIXME: Do in Paint if special option given!
747 TCanvas *c = new TCanvas;
748 Int_t n = fHAlpha.GetNbinsY();
749 Int_t nc = (Int_t)(TMath::Sqrt((Float_t)n-1)+1);
750 c->Divide(nc, nc, 0, 0);
751
752 // Do not store the 'final' result in fFit
753 MAlphaFitter fit(fFit);
754
755 for (int i=1; i<=fHAlpha.GetNbinsY(); i++)
756 {
757 c->cd(i);
758
759 TH1D *hon = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, i, i, "E");
760 hon->SetBit(TH1::kNoTitle);
761 hon->SetStats(kTRUE);
762 hon->SetXTitle("\\alpha [\\circ]");
763 hon->SetYTitle("Counts");
764 hon->SetDirectory(NULL);
765 hon->SetMarkerStyle(kFullDotMedium);
766 hon->SetBit(kCanDelete);
767 hon->Draw("");
768
769 TH1D *hof = 0;
770 Double_t alpha = 1;
771
772 if (fOffData)
773 {
774 hon->SetMarkerColor(kGreen);
775
776 hof = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, i, i, "E");
777 hof->SetBit(TH1::kNoTitle|TH1::kNoStats);
778 hof->SetXTitle("\\alpha [\\circ]");
779 hof->SetYTitle("Counts");
780 hof->SetDirectory(NULL);
781 hof->SetMarkerStyle(kFullDotMedium);
782 hof->SetBit(kCanDelete);
783 hof->SetMarkerColor(kRed);
784 hof->Draw("same");
785
786 alpha = fit.Scale(*hof, *hon);
787
788 hon->SetMaximum();
789 hon->SetMaximum(TMath::Max(hon->GetMaximum(), hof->GetMaximum())*1.05);
790
791 TH1D *diff = new TH1D(*hon);
792 diff->Add(hof, -1);
793 diff->SetBit(TH1::kNoTitle);
794 diff->SetXTitle("\\alpha [\\circ]");
795 diff->SetYTitle("Counts");
796 diff->SetDirectory(NULL);
797 diff->SetMarkerStyle(kFullDotMedium);
798 diff->SetBit(kCanDelete);
799 diff->SetMarkerColor(kBlue);
800 diff->Draw("same");
801
802 TLine lin;
803 lin.SetLineStyle(kDashed);
804 lin.DrawLine(0, 0, 90, 0);
805
806 const Float_t min = diff->GetMinimum()*1.05;
807 hon->SetMinimum(min<0 ? min : 0);
808 }
809
810 if (hof ? fit.Fit(*hon, *hof, alpha) : fit.Fit(*hon))
811 *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << endl;
812 /*
813 if (fit.FitEnergy(fHAlpha, fOffData, i, kTRUE))
814 {
815 fHEnergy.SetBinContent(i, fit.GetEventsExcess());
816 fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2);
817 }*/
818 }
819
820}
821
822
823Bool_t MHAlpha::Finalize()
824{
825 //TH1D *h = fHAlpha.ProjectionZ("AlphaExc_px", -1, 9999, -1, 9999, "E");
826 //h->SetDirectory(0);
827 //Bool_t rc = fFit.Fit(*h);
828 //delete h;
829 if (!fFit.FitAlpha(fHAlpha, fOffData))
830 {
831 *fLog << warn << "Histogram empty." << endl;
832 return kTRUE;
833 }
834
835 // Store the final result in fFit
836 fFit.Print("result");
837
838 fResult->SetVal(-fFit.GetSignificance());
839
840 if (!fSkipHistEnergy)
841 {
842 *fLog << inf << "Processing energy bins..." << endl;
843 FitEnergyBins();
844 }
845 if (!fSkipHistTheta)
846 {
847 *fLog << inf << "Processing theta bins..." << endl;
848 FitThetaBins();
849 }
850 if (!fSkipHistTime)
851 {
852 *fLog << inf << "Processing time bins..." << endl;
853 UpdateAlphaTime(kTRUE);
854 MH::RemoveFirstBin(fHTime);
855 }
856
857 return kTRUE;
858}
859
860// --------------------------------------------------------------------------
861//
862// You can use this function if you want to use a MHMatrix instead of
863// MMcEvt. This function adds all necessary columns to the
864// given matrix. Afterward you should fill the matrix with the corresponding
865// data (eg from a file by using MHMatrix::Fill). If you now loop
866// through the matrix (eg using MMatrixLoop) MHHadronness::Fill
867// will take the values from the matrix instead of the containers.
868//
869// It takes fSkipHist* into account!
870//
871void MHAlpha::InitMapping(MHMatrix *mat, Int_t type)
872{
873 if (fMatrix)
874 return;
875
876 fMatrix = mat;
877
878 fMap[0] = fMatrix->AddColumn("MHillasSrc.fAlpha");
879 fMap[1] = -1;
880 fMap[2] = -1;
881 fMap[3] = -1;
882 fMap[4] = -1;
883
884 if (!fSkipHistEnergy)
885 if (type==0)
886 {
887 fMap[1] = fMatrix->AddColumn("MEnergyEst.fEnergy");
888 fMap[2] = -1;
889 }
890 else
891 {
892 fMap[1] = -1;
893 fMap[2] = fMatrix->AddColumn("MHillas.fSize");
894 }
895
896 if (!fSkipHistTheta)
897 fMap[3] = fMatrix->AddColumn("MPointingPos.fZd");
898
899 // if (!fSkipHistTime)
900 // fMap[4] = fMatrix->AddColumn("MTime.GetAxisTime");
901}
902
903void MHAlpha::StopMapping()
904{
905 fMatrix = NULL;
906}
Note: See TracBrowser for help on using the repository browser.