Changeset 6988 for trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
- Timestamp:
- 05/02/05 10:17:41 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
r6977 r6988 18 18 ! Author(s): Thomas Bretz, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 420 ! Copyright: MAGIC Software Development, 2000-2005 21 21 ! 22 22 ! … … 81 81 // 82 82 MHAlpha::MHAlpha(const char *name, const char *title) 83 : fOffData(0), fResult(0), /*fExcess(0),*/ fEnergy(0), fHillas(0), 83 : fNameParameter("MHillasSrc"), fParameter(0), 84 fOffData(0), fResult(0), /*fExcess(0),*/ fEnergy(0), fHillas(0), 84 85 fPointPos(0), fTimeEffOn(0), fTime(0), 85 86 fSkipHistTime(kFALSE), fSkipHistTheta(kFALSE), fSkipHistEnergy(kFALSE), … … 93 94 fTitle = title ? title : "Alpha plot"; 94 95 95 fH Alpha.SetName("Alpha");96 fH Alpha.SetTitle("Alpha");97 fH Alpha.SetXTitle("\\Theta [deg]");98 //fH Alpha.SetYTitle("E_{est} [GeV]");99 fH Alpha.SetZTitle("|\\alpha| [\\circ]");100 fH Alpha.SetDirectory(NULL);101 fH Alpha.UseCurrentStyle();96 fHist.SetName("Alpha"); 97 fHist.SetTitle("Alpha"); 98 fHist.SetXTitle("\\Theta [deg]"); 99 //fHist.SetYTitle("E_{est} [GeV]"); 100 fHist.SetZTitle("|\\alpha| [\\circ]"); 101 fHist.SetDirectory(NULL); 102 fHist.UseCurrentStyle(); 102 103 103 104 // Main histogram 104 fH AlphaTime.SetName("Alpha");105 fH AlphaTime.SetXTitle("|\\alpha| [\\circ]");106 fH AlphaTime.SetYTitle("Counts");107 fH AlphaTime.UseCurrentStyle();108 fH AlphaTime.SetDirectory(NULL);105 fHistTime.SetName("Alpha"); 106 fHistTime.SetXTitle("|\\alpha| [\\circ]"); 107 fHistTime.SetYTitle("Counts"); 108 fHistTime.UseCurrentStyle(); 109 fHistTime.SetDirectory(NULL); 109 110 110 111 … … 142 143 binse.Apply(fHEnergy); 143 144 binst.Apply(fHTheta); 144 binsa.Apply(fHAlphaTime); 145 146 MH::SetBinning(&fHAlpha, &binst, &binse, &binsa); 147 } 148 149 void MHAlpha::FitEnergySpec(Bool_t paint) 150 { 151 /* 152 TF1 f("Spectrum", "pow(x, [0])*exp(-x/[1])*[2]*x");// 153 f.SetParameter(0, -2.1); 154 f.SetParameter(1, 1400); // 50 155 f.SetParameter(2, fHEnergy.Integral()); // 50 156 f.SetLineWidth(2); 157 158 fHEnergy.Fit(&f, "0QI", "", 100, 2400); // Integral? 90, 2800 159 160 const Double_t chi2 = f.GetChisquare(); 161 const Int_t NDF = f.GetNDF(); 162 163 // was fit successful ? 164 const Bool_t ok = NDF>0 && chi2<2.5*NDF; 165 f.SetLineColor(ok ? kGreen : kRed); 166 167 if (paint) 168 { 169 f.Paint("same"); 170 171 if (ok) 172 { 173 TString s; 174 s += Form("\\alpha=%.1f ", f.GetParameter(0)); 175 s += Form("E_{c}=%.1f TeV ", f.GetParameter(1)/1000); 176 s += Form("N=%.1e", f.GetParameter(2)); 177 178 TLatex text(0.25, 0.94, s.Data()); 179 text.SetBit(TLatex::kTextNDC); 180 text.SetTextSize(0.04); 181 text.Paint(); 182 } 183 }*/ 145 binsa.Apply(fHistTime); 146 147 MH::SetBinning(&fHist, &binst, &binse, &binsa); 148 } 149 150 Double_t MHAlpha::GetVal() const 151 { 152 return static_cast<const MHillasSrc*>(fParameter)->GetAlpha(); 184 153 } 185 154 … … 189 158 MAlphaFitter fit(fFit); 190 159 191 const Int_t n = fH Alpha.GetNbinsY();160 const Int_t n = fHist.GetNbinsY(); 192 161 193 162 fHEnergy.SetEntries(0); … … 197 166 for (int i=1; i<=n; i++) 198 167 { 199 if (fit.FitEnergy(fH Alpha, fOffData, i))168 if (fit.FitEnergy(fHist, fOffData, i)) 200 169 { 201 170 fHEnergy.SetBinContent(i, fit.GetEventsExcess()); … … 220 189 MAlphaFitter fit(fFit); 221 190 222 const Int_t n = fH Alpha.GetNbinsX();191 const Int_t n = fHist.GetNbinsX(); 223 192 224 193 fHTheta.SetEntries(0); … … 226 195 for (int i=1; i<=n; i++) 227 196 { 228 if (fit.FitTheta(fH Alpha, fOffData, i))197 if (fit.FitTheta(fHist, fOffData, i)) 229 198 { 230 199 fHTheta.SetBinContent(i, fit.GetEventsExcess()); … … 237 206 } 238 207 208 Bool_t MHAlpha::GetParameter(const MParList &pl) 209 { 210 fParameter = (MParContainer*)pl.FindObject(fNameParameter, "MHillasSrc"); 211 if (fParameter) 212 return kTRUE; 213 214 *fLog << err << fNameParameter << " [MHillasSrc] not found... abort." << endl; 215 return kFALSE; 216 } 217 239 218 Bool_t MHAlpha::SetupFill(const MParList *pl) 240 219 { 241 fH Alpha.Reset();220 fHist.Reset(); 242 221 fHEnergy.Reset(); 243 222 fHTheta.Reset(); 244 223 fHTime.Reset(); 245 224 246 if (fName!=(TString)"MHAlphaOff" && fOffData==NULL) 247 { 248 MHAlpha *hoff = (MHAlpha*)pl->FindObject("MHAlphaOff", "MHAlpha"); 225 const TString off(Form("%sOff", ClassName())); 226 if (fName!=off && fOffData==NULL) 227 { 228 const TString desc(Form("%s [%s] found... using ", off.Data(), ClassName())); 229 MHAlpha *hoff = (MHAlpha*)pl->FindObject(off, ClassName()); 249 230 if (!hoff) 250 *fLog << inf << "No MHAlphaOff [MHAlpha] found... usingcurrent data only!" << endl;231 *fLog << inf << "No " << desc << "current data only!" << endl; 251 232 else 252 233 { 253 *fLog << inf << "MHAlphaOff [MHAlpha] found... usingon-off mode!" << endl;234 *fLog << inf << desc << "on-off mode!" << endl; 254 235 SetOffData(*hoff); 255 236 } 256 237 } 238 239 if (!GetParameter(*pl)) 240 return kFALSE; 257 241 258 242 fHillas = 0; … … 271 255 fHEnergy.SetTitle(" N_{exc} vs. Size "); 272 256 fHEnergy.SetXTitle("Size [phe]"); 273 fH Alpha.SetYTitle("Size [phe]");257 fHist.SetYTitle("Size [phe]"); 274 258 } 275 259 else … … 277 261 fHEnergy.SetTitle(" N_{exc} vs. E_{est} "); 278 262 fHEnergy.SetXTitle("E_{est} [GeV]"); 279 fH Alpha.SetYTitle("E_{est} [GeV]");263 fHist.SetYTitle("E_{est} [GeV]"); 280 264 } 281 265 … … 306 290 307 291 MBinning binst, binse, binsa; 308 binst.SetEdges(fOffData ? *fOffData : fH Alpha, 'x');309 binse.SetEdges(fOffData ? *fOffData : fH Alpha, 'y');310 binsa.SetEdges(fOffData ? *fOffData : fH Alpha, 'z');292 binst.SetEdges(fOffData ? *fOffData : fHist, 'x'); 293 binse.SetEdges(fOffData ? *fOffData : fHist, 'y'); 294 binsa.SetEdges(fOffData ? *fOffData : fHist, 'z'); 311 295 if (!fOffData) 312 296 { … … 324 308 binse.SetEdges(*pl, "BinningSize"); 325 309 326 binsa.SetEdges(*pl, "BinningAlpha");310 binsa.SetEdges(*pl, Form("Binning%s", ClassName()+2)); 327 311 } 328 312 else … … 330 314 fHEnergy.SetTitle(fOffData->GetTitle()); 331 315 fHEnergy.SetXTitle(fOffData->GetYaxis()->GetTitle()); 332 fH Alpha.SetYTitle(fOffData->GetYaxis()->GetTitle());316 fHist.SetYTitle(fOffData->GetYaxis()->GetTitle()); 333 317 } 334 318 335 319 binse.Apply(fHEnergy); 336 320 binst.Apply(fHTheta); 337 binsa.Apply(fH AlphaTime);338 MH::SetBinning(&fH Alpha, &binst, &binse, &binsa);321 binsa.Apply(fHistTime); 322 MH::SetBinning(&fHist, &binst, &binse, &binsa); 339 323 340 324 MAlphaFitter *fit = (MAlphaFitter*)pl->FindObject("MAlphaFitter"); … … 402 386 403 387 TH1D *h = fOffData ? fOffData->ProjectionZ("ProjTimeTemp", -1, 9999, -1, 9999, "E") : 0; 404 const Bool_t rc = fit.ScaleAndFit(fH AlphaTime, h);388 const Bool_t rc = fit.ScaleAndFit(fHistTime, h); 405 389 if (h) 406 390 delete h; … … 410 394 411 395 // Reset Histogram 412 fH AlphaTime.Reset();413 fH AlphaTime.SetEntries(0);396 fHistTime.Reset(); 397 fHistTime.SetEntries(0); 414 398 415 399 // … … 469 453 else 470 454 { 471 const MHillasSrc *hil = dynamic_cast<const MHillasSrc*>(par); 472 if (!par) 473 { 474 *fLog << err << dbginf << "MHillasSrc not found... abort." << endl; 475 return kFALSE; 476 } 477 478 alpha = hil->GetAlpha(); 455 alpha = GetVal(); 479 456 480 457 if (fHillas) … … 491 468 492 469 // Fill histograms 493 fH Alpha.Fill(theta, energy, TMath::Abs(alpha), w);470 fHist.Fill(theta, energy, TMath::Abs(alpha), w); 494 471 495 472 // Check cuts … … 503 480 504 481 if (!fSkipHistTime) 505 fH AlphaTime.Fill(TMath::Abs(alpha), w);482 fHistTime.Fill(TMath::Abs(alpha), w); 506 483 507 484 return kTRUE; … … 557 534 558 535 padsave->cd(1); 559 TH1D *hon = fH Alpha.ProjectionZ("ProjAlpha");536 TH1D *hon = fHist.ProjectionZ("Proj"); 560 537 if (fOffData) 561 538 { 562 TH1D *hoff = fOffData->ProjectionZ("Proj AlphaOff");539 TH1D *hoff = fOffData->ProjectionZ("ProjOff"); 563 540 const Double_t alpha = fFit.Scale(*hoff, *hon); 564 541 … … 569 546 hoff->SetMaximum(alpha); 570 547 571 if ((h0=(TH1D*)gPad->FindObject("Proj AlphaOnOff")))548 if ((h0=(TH1D*)gPad->FindObject("ProjOnOff"))) 572 549 { 573 550 h0->Reset(); … … 583 560 } 584 561 585 if (o==(TString)" alpha")586 if ((h0 = (TH1D*)gPad->FindObject("Proj Alpha")))562 if (o==(TString)"variable") 563 if ((h0 = (TH1D*)gPad->FindObject("Proj"))) 587 564 { 588 565 // Check whether we are dealing with on-off analysis 589 TH1D *hoff = (TH1D*)gPad->FindObject("Proj AlphaOff");566 TH1D *hoff = (TH1D*)gPad->FindObject("ProjOff"); 590 567 591 568 // BE CARFEULL: This is a really weird workaround! … … 603 580 if (o==(TString)"theta") 604 581 { 605 TH1 *h = (TH1*)gPad->FindObject( "Alpha_x");582 TH1 *h = (TH1*)gPad->FindObject(Form("%s_x", fHist.GetName())); 606 583 if (h) 607 584 { 608 TH1D *h2 = (TH1D*)fH Alpha.Project3D("dum_x");585 TH1D *h2 = (TH1D*)fHist.Project3D("dum_x"); 609 586 h2->SetDirectory(0); 610 587 h2->Scale(fHTheta.Integral()/h2->Integral()); … … 618 595 if (o==(TString)"energy") 619 596 { 620 TH1 *h = (TH1*)gPad->FindObject( "Alpha_y");597 TH1 *h = (TH1*)gPad->FindObject(Form("%s_y", fHist.GetName())); 621 598 if (h) 622 599 { 623 TH1D *h2 = (TH1D*)fH Alpha.Project3D("dum_y");600 TH1D *h2 = (TH1D*)fHist.Project3D("dum_y"); 624 601 h2->SetDirectory(0); 625 602 h2->Scale(fHEnergy.Integral()/h2->Integral()); … … 634 611 gPad->SetLogy(); 635 612 } 636 FitEnergySpec(kTRUE);637 613 } 638 614 … … 660 636 gPad->SetBorderMode(0); 661 637 662 h = fH Alpha.ProjectionZ("ProjAlpha", -1, 9999, -1, 9999, "E");638 h = fHist.ProjectionZ("Proj", -1, 9999, -1, 9999, "E"); 663 639 h->SetBit(TH1::kNoTitle); 664 640 h->SetStats(kTRUE); 665 h->SetXTitle( "\\alpha [\\circ]");641 h->SetXTitle(fHist.GetZaxis()->GetTitle()); 666 642 h->SetYTitle("Counts"); 667 643 h->SetDirectory(NULL); … … 674 650 h->SetMarkerColor(kGreen); 675 651 676 h = fOffData->ProjectionZ("Proj AlphaOff", -1, 9999, -1, 9999, "E");652 h = fOffData->ProjectionZ("ProjOff", -1, 9999, -1, 9999, "E"); 677 653 h->SetBit(TH1::kNoTitle); 678 h->SetXTitle( "\\alpha [\\circ]");654 h->SetXTitle(fHist.GetZaxis()->GetTitle()); 679 655 h->SetYTitle("Counts"); 680 656 h->SetDirectory(NULL); … … 684 660 h->Draw("same"); 685 661 686 h = (TH1D*)h->Clone("Proj AlphaOnOff");662 h = (TH1D*)h->Clone("ProjOnOff"); 687 663 h->SetBit(TH1::kNoTitle); 688 h->SetXTitle( "\\alpha [\\circ]");664 h->SetXTitle(fHist.GetZaxis()->GetTitle()); 689 665 h->SetYTitle("Counts"); 690 666 h->SetDirectory(NULL); … … 696 672 TLine lin; 697 673 lin.SetLineStyle(kDashed); 698 lin.DrawLine( 0, 0, 90, 0);674 lin.DrawLine(h->GetXaxis()->GetXmin(), 0, h->GetXaxis()->GetXmax(), 0); 699 675 } 700 676 701 677 // After the Alpha-projection has been drawn. Fit the histogram 702 678 // and paint the result into this pad 703 AppendPad(" alpha");679 AppendPad("variable"); 704 680 705 681 if (fHEnergy.GetNbinsX()>1) … … 713 689 AppendPad("energy"); 714 690 715 h = (TH1D*)fH Alpha.Project3D("y");691 h = (TH1D*)fHist.Project3D("y"); 716 692 h->SetBit(TH1::kNoTitle|TH1::kNoStats); 717 693 h->SetXTitle("E [GeV]"); … … 749 725 AppendPad("theta"); 750 726 751 h = (TH1D*)fH Alpha.Project3D("x");727 h = (TH1D*)fHist.Project3D("x"); 752 728 h->SetBit(TH1::kNoTitle|TH1::kNoStats); 753 729 h->SetXTitle("\\theta [\\circ]"); … … 768 744 // FIXME: Do in Paint if special option given! 769 745 TCanvas *c = new TCanvas; 770 Int_t n = fH Alpha.GetNbinsY();746 Int_t n = fHist.GetNbinsY(); 771 747 Int_t nc = (Int_t)(TMath::Sqrt((Float_t)n-1)+1); 772 748 c->Divide(nc, nc, 1e-10, 1e-10); … … 775 751 MAlphaFitter fit(fFit); 776 752 777 for (int i=1; i<=fH Alpha.GetNbinsY(); i++)753 for (int i=1; i<=fHist.GetNbinsY(); i++) 778 754 { 779 755 c->cd(i); 780 756 781 TH1D *hon = fH Alpha.ProjectionZ("ProjAlpha", -1, 9999, i, i, "E");757 TH1D *hon = fHist.ProjectionZ("Proj", -1, 9999, i, i, "E"); 782 758 hon->SetBit(TH1::kNoTitle); 783 759 hon->SetStats(kTRUE); 784 hon->SetXTitle( "\\alpha [\\circ]");760 hon->SetXTitle(fHist.GetZaxis()->GetTitle()); 785 761 hon->SetYTitle("Counts"); 786 762 hon->SetDirectory(NULL); … … 796 772 hon->SetMarkerColor(kGreen); 797 773 798 hof = fOffData->ProjectionZ("Proj AlphaOff", -1, 9999, i, i, "E");774 hof = fOffData->ProjectionZ("ProjOff", -1, 9999, i, i, "E"); 799 775 hof->SetBit(TH1::kNoTitle|TH1::kNoStats); 800 hof->SetXTitle( "\\alpha [\\circ]");776 hof->SetXTitle(fHist.GetZaxis()->GetTitle()); 801 777 hof->SetYTitle("Counts"); 802 778 hof->SetDirectory(NULL); … … 814 790 diff->Add(hof, -1); 815 791 diff->SetBit(TH1::kNoTitle); 816 diff->SetXTitle( "\\alpha [\\circ]");792 diff->SetXTitle(fHist.GetZaxis()->GetTitle()); 817 793 diff->SetYTitle("Counts"); 818 794 diff->SetDirectory(NULL); … … 824 800 TLine lin; 825 801 lin.SetLineStyle(kDashed); 826 lin.DrawLine( 0, 0, 90, 0);802 lin.DrawLine(diff->GetXaxis()->GetXmin(), 0, diff->GetXaxis()->GetXmax(), 0); 827 803 828 804 const Float_t min = diff->GetMinimum()*1.05; … … 833 809 *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << endl; 834 810 /* 835 if (fit.FitEnergy(fH Alpha, fOffData, i, kTRUE))811 if (fit.FitEnergy(fHist, fOffData, i, kTRUE)) 836 812 { 837 813 fHEnergy.SetBinContent(i, fit.GetEventsExcess()); … … 845 821 Bool_t MHAlpha::Finalize() 846 822 { 847 //TH1D *h = fH Alpha.ProjectionZ("AlphaExc_px", -1, 9999, -1, 9999, "E");823 //TH1D *h = fHist.ProjectionZ("AlphaExc_px", -1, 9999, -1, 9999, "E"); 848 824 //h->SetDirectory(0); 849 825 //Bool_t rc = fFit.Fit(*h); 850 826 //delete h; 851 827 852 if (!fFit.FitAlpha(fH Alpha, fOffData))828 if (!fFit.FitAlpha(fHist, fOffData)) 853 829 { 854 830 *fLog << warn << "MAlphaFitter - Fit failed..." << endl; … … 900 876 fMatrix = mat; 901 877 902 fMap[0] = fMatrix->AddColumn( "MHillasSrc.fAlpha");878 fMap[0] = fMatrix->AddColumn(GetParameterRule()); 903 879 fMap[1] = -1; 904 880 fMap[2] = -1;
Note:
See TracChangeset
for help on using the changeset viewer.