Changeset 5776 for trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc
- Timestamp:
- 01/10/05 17:55:11 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc
r5301 r5776 147 147 using namespace std; 148 148 149 class MHillasExt;149 //class MHillasExt; 150 150 151 151 // -------------------------------------------------------------------------- … … 155 155 MHFalseSource::MHFalseSource(const char *name, const char *title) 156 156 : fTime(0), fPointPos(0), fObservatory(0), fMm2Deg(-1), fAlphaCut(12.5), 157 fBgMean(55), fMinDist(-1), fMaxDist(-1), fMinDW(-1), fMaxDW(-1) 157 fBgMean(55), fMinDist(-1), fMaxDist(-1), fMinDW(-1), fMaxDW(-1), 158 fHistOff(0) 158 159 { 159 160 // … … 174 175 void MHFalseSource::MakeSymmetric(TH1 *h) 175 176 { 177 h->SetMinimum(); 178 h->SetMaximum(); 179 176 180 const Float_t min = TMath::Abs(h->GetMinimum()); 177 181 const Float_t max = TMath::Abs(h->GetMaximum()); … … 248 252 // Also search for MTime, MObservatory and MPointingPos 249 253 // 250 MHillasExt *ext=0;254 //MHillasExt *ext=0; 251 255 Bool_t MHFalseSource::SetupFill(const MParList *plist) 252 256 { … … 257 261 return kFALSE; 258 262 } 263 /* 259 264 ext = (MHillasExt*)plist->FindObject("MHillasExt"); 260 265 if (!ext) … … 263 268 return kFALSE; 264 269 } 265 270 */ 266 271 fMm2Deg = geom->GetConvMm2Deg(); 267 272 268 MBinning binsa; 269 binsa.SetEdges(18, 0, 90); 270 271 const MBinning *bins = (MBinning*)plist->FindObject("BinningFalseSource"); 272 if (!bins) 273 if (fName!=(TString)"MHFalseSourceOff" && fHistOff==NULL) 273 274 { 274 const Float_t r = (geom ? geom->GetMaxRadius()/3 : 200)*fMm2Deg; 275 276 MBinning b; 277 b.SetEdges(20, -r, r); 278 SetBinning(&fHist, &b, &b, &binsa); 275 MHFalseSource *hoff = (MHFalseSource*)plist->FindObject("MHFalseSourceOff", "MHFalseSource"); 276 if (!hoff) 277 *fLog << inf << "No MHFalseSourceOff [MHFalseSource] found... using current data only!" << endl; 278 else 279 { 280 *fLog << inf << "MHFalseSource [MHFalseSource] found... using on-off mode!" << endl; 281 SetOffData(*hoff); 282 } 279 283 } 284 285 if (fHistOff) 286 MH::SetBinning(&fHist, fHistOff); 280 287 else 281 SetBinning(&fHist, bins, bins, &binsa); 288 { 289 MBinning binsa; 290 binsa.SetEdges(18, 0, 90); 291 292 const MBinning *bins = (MBinning*)plist->FindObject("BinningFalseSource"); 293 if (!bins) 294 { 295 const Float_t r = (geom ? geom->GetMaxRadius()/3 : 200)*fMm2Deg; 296 297 MBinning b; 298 b.SetEdges(20, -r, r); 299 SetBinning(&fHist, &b, &b, &binsa); 300 } 301 else 302 SetBinning(&fHist, bins, bins, &binsa); 303 } 282 304 283 305 fPointPos = (MPointingPos*)plist->FindObject(AddSerialNumber("MPointingPos")); … … 399 421 // the same number of bins than for on-data 400 422 // 401 void MHFalseSource::ProjectOff( TH2D *h2, TH2D *all)402 { 403 TAxis &axe = * fHist.GetZaxis();423 void MHFalseSource::ProjectOff(const TH3D &src, TH2D *h2, TH2D *all) 424 { 425 TAxis &axe = *src.GetZaxis(); 404 426 405 427 // Find range to cut (left edge and width) … … 413 435 414 436 // Get projection for range 415 TH2D *p = (TH2D*) fHist.Project3D("yx_off");437 TH2D *p = (TH2D*)src.Project3D("yx_off"); 416 438 417 439 // Reset range … … 435 457 // range (0, fAlphaCut) 436 458 // 437 void MHFalseSource::ProjectOn( TH2D *h3, TH2D *all)438 { 439 TAxis &axe = * fHist.GetZaxis();459 void MHFalseSource::ProjectOn(const TH3D &src, TH2D *h3, TH2D *all) 460 { 461 TAxis &axe = *src.GetZaxis(); 440 462 441 463 // Find range to cut … … 445 467 446 468 // Get projection for range 447 TH2D *p = (TH2D*) fHist.Project3D("yx_on");469 TH2D *p = (TH2D*)src.Project3D("yx_on"); 448 470 449 471 // Reset range … … 482 504 // Set Minimum as minimum value Greater Than 0 483 505 h3->SetMinimum(GetMinimumGT(*h3)); 506 } 507 508 void MHFalseSource::ProjectOnOff(TH2D *h2, TH2D *h0) 509 { 510 ProjectOn(*fHistOff, h2, h0); 511 512 TH2D h; 513 MH::SetBinning(&h, h2); 514 515 // Divide by number of entries in off region (of off-data) 516 ProjectOff(*fHistOff, &h, h0); 517 h2->Divide(&h); 518 519 // Multiply by number of entries in off region (of on-data) 520 ProjectOff(fHist, &h, h0); 521 h2->Multiply(&h); 522 523 // Recalculate Minimum 524 h2->SetMinimum(GetMinimumGT(*h2)); 484 525 } 485 526 … … 518 559 padsave->GetPad(1)->cd(1); 519 560 if ((h3 = (TH2D*)gPad->FindObject("Alpha_yx_on"))) 520 ProjectOn( h3, h0);561 ProjectOn(fHist, h3, h0); 521 562 522 563 // Update projection of off-events 523 564 padsave->GetPad(1)->cd(3); 524 565 if ((h2 = (TH2D*)gPad->FindObject("Alpha_yx_off"))) 525 ProjectOff(h2, h0); 566 { 567 if (!fHistOff) 568 ProjectOff(fHist, h2, h0); 569 else 570 ProjectOnOff(h2, h0); 571 } 526 572 527 573 padsave->GetPad(2)->cd(2); … … 579 625 TH1 *h = fHist.ProjectionZ("Alpha_z", maxx, maxx, maxy, maxy); 580 626 h->SetTitle(Form("Distribution of \\alpha for x=%.2f y=%.2f (\\sigma_{max}=%.1f)", x, y, s)); 627 628 TH1D *h0=0; 629 if ((h0 = (TH1D*)gPad->FindObject("AlphaOff_z"))) 630 { 631 fHistOff->ProjectionZ("AlphaOff_z", maxx, maxx, maxy, maxy); 632 633 const Int_t f = h0->GetXaxis()->FindFixBin(fBgMean-fAlphaCut/2); 634 const Int_t l = h0->GetXaxis()->FindFixBin(fAlphaCut)+f-1; 635 h0->Scale(h1->Integral(f, l)/h0->Integral(f, l)); 636 //h0->Scale(h1->GetEntries()/h0->GetEntries()); 637 638 } 581 639 } 582 640 } … … 620 678 pad->Divide(1, 2, 0, 0.03); 621 679 622 TObject *catalog = GetCatalog();680 // TObject *catalog = GetCatalog(); 623 681 624 682 // Initialize upper part 625 683 pad->cd(1); 626 684 // Make sure that the catalog is deleted only once 627 gROOT->GetListOfCleanups()->Add(gPad); 685 // Normally this is not done by root, because it is not necessary... 686 // but in this case it is necessary, because the catalog is 687 // deleted by the first pad and the second one tries to do the same! 688 // gROOT->GetListOfCleanups()->Add(gPad); 628 689 gPad->SetBorderMode(0); 629 690 gPad->Divide(3, 1); … … 640 701 h3->Draw("colz"); 641 702 h3->SetBit(kCanDelete); 642 catalog->Draw("mirror same *");703 // catalog->Draw("mirror same *"); 643 704 644 705 // PAD #2 … … 654 715 h4->Draw("colz"); 655 716 h4->SetBit(kCanDelete); 656 catalog->Draw("mirror same *");717 // catalog->Draw("mirror same *"); 657 718 658 719 // PAD #3 659 720 pad->GetPad(1)->cd(3); 660 721 gPad->SetBorderMode(0); 661 fHist.GetZaxis()->SetRangeUser(fBgMean-fAlphaCut/2, fBgMean+fAlphaCut/2); 662 TH1 *h2 = fHist.Project3D("yx_off"); 722 TH1 *h2 = 0; 723 if (fHistOff) 724 { 725 fHistOff->GetZaxis()->SetRangeUser(0,fAlphaCut); 726 h2 = fHistOff->Project3D("yx_off"); 727 fHistOff->GetZaxis()->SetRange(0,9999); 728 } 729 else 730 { 731 fHist.GetZaxis()->SetRangeUser(fBgMean-fAlphaCut/2, fBgMean+fAlphaCut/2); 732 h2 = fHist.Project3D("yx_off"); 733 fHist.GetZaxis()->SetRange(0,9999); 734 } 663 735 h2->SetDirectory(NULL); 664 736 h2->SetXTitle(fHist.GetXaxis()->GetTitle()); … … 666 738 h2->Draw("colz"); 667 739 h2->SetBit(kCanDelete); 668 catalog->Draw("mirror same *");740 // catalog->Draw("mirror same *"); 669 741 670 742 // Initialize lower part 671 743 pad->cd(2); 672 744 // Make sure that the catalog is deleted only once 673 gROOT->GetListOfCleanups()->Add(gPad);745 // gROOT->GetListOfCleanups()->Add(gPad); 674 746 gPad->SetBorderMode(0); 675 747 gPad->Divide(3, 1); … … 685 757 h1->Draw(); 686 758 h1->SetBit(kCanDelete); 759 if (fHistOff) 760 { 761 h1->SetLineColor(kGreen); 762 763 h1 = fHistOff->ProjectionZ("AlphaOff_z"); 764 h1->SetDirectory(NULL); 765 h1->SetTitle("Distribution of \\alpha"); 766 h1->SetXTitle(fHistOff->GetZaxis()->GetTitle()); 767 h1->SetYTitle("Counts"); 768 h1->Draw("same"); 769 h1->SetBit(kCanDelete); 770 h1->SetLineColor(kRed); 771 } 687 772 688 773 // PAD #5 … … 695 780 h5->Draw("colz"); 696 781 h5->SetBit(kCanDelete); 697 catalog->Draw("mirror same *");782 // catalog->Draw("mirror same *"); 698 783 699 784 // PAD #6 … … 706 791 h0->Draw("colz"); 707 792 h0->SetBit(kCanDelete); 708 catalog->Draw("mirror same *");793 // catalog->Draw("mirror same *"); 709 794 } 710 795 … … 785 870 void MHFalseSource::FitSignificance(Float_t sigint, Float_t sigmax, Float_t bgmin, Float_t bgmax, Byte_t polynom) 786 871 { 787 TObject *catalog = GetCatalog();872 // TObject *catalog = GetCatalog(); 788 873 789 874 TH1D h0a("A", "", 50, 0, 4000); … … 868 953 fit.SetPolynomOrder(polynom); 869 954 870 TH1D *h=0 ;955 TH1D *h=0, *hoff=0; 871 956 for (int ix=1; ix<=nx; ix++) 872 957 for (int iy=1; iy<=ny; iy++) … … 879 964 continue; 880 965 881 882 966 h->Scale(entries/h->GetEntries()); 883 967 884 if (!fit.Fit(*h)) 968 if (fHistOff) 969 { 970 hoff = fHistOff->ProjectionZ("AlphaFitOff", ix, ix, iy, iy); 971 hoff->Scale(entries/hoff->GetEntries()); 972 } 973 974 if (!fit.Fit(*h, hoff)) 885 975 continue; 886 976 … … 894 984 h1.Fill(fit.GetGausMu()); // mu 895 985 h2.Fill(fit.GetGausSigma()); // sigma-gaus 896 if (polynom>1 )986 if (polynom>1 && !fHistOff) 897 987 h3.Fill(fit.GetCoefficient(5)); 898 988 h4b.Fill(fit.GetChiSqSignal()); … … 945 1035 hists->Draw("colz"); 946 1036 hists->SetBit(kCanDelete); 947 catalog->Draw("mirror same *");1037 // catalog->Draw("mirror same *"); 948 1038 c->cd(2); 949 1039 gPad->SetBorderMode(0); … … 976 1066 977 1067 978 catalog->Draw("mirror same *");1068 // catalog->Draw("mirror same *"); 979 1069 c->cd(3); 980 1070 gPad->SetBorderMode(0); 981 1071 histb->Draw("colz"); 982 1072 histb->SetBit(kCanDelete); 983 catalog->Draw("mirror same *");1073 // catalog->Draw("mirror same *"); 984 1074 c->cd(4); 985 1075 gPad->Divide(1,3, 0, 0); … … 1018 1108 hist->GetYaxis()->GetBinCenter(maxy), maxs); 1019 1109 1020 TH1 *result = fHist.ProjectionZ("AlphaFit", maxx, maxx, maxy, maxy); 1021 result->Scale(entries/h->GetEntries()); 1022 1023 result->SetDirectory(NULL); 1024 result->SetNameTitle("Result \\alpha", title); 1025 result->SetBit(kCanDelete); 1026 result->SetXTitle("\\alpha [\\circ]"); 1027 result->SetYTitle("Counts"); 1028 result->Draw(); 1029 1030 TF1 f1("f1", Form("gaus(0) + pol%d(3)", polynom), 0, 90); 1031 TF1 f2("f2", Form("gaus(0) + pol%d(3)", polynom), 0, 90); 1110 h = fHist.ProjectionZ("AlphaFit", maxx, maxx, maxy, maxy); 1111 h->Scale(entries/h->GetEntries()); 1112 1113 h->SetDirectory(NULL); 1114 h->SetNameTitle("Result \\alpha", title); 1115 h->SetBit(kCanDelete); 1116 h->SetXTitle("\\alpha [\\circ]"); 1117 h->SetYTitle("Counts"); 1118 h->Draw(); 1119 1120 if (fHistOff) 1121 { 1122 h->SetLineColor(kGreen); 1123 1124 TH1D *hof=fHistOff->ProjectionZ("AlphaFitOff", maxx, maxx, maxy, maxy); 1125 hof->Scale(entries/hof->GetEntries()); 1126 1127 fit.Scale(*(TH1D*)hof, *(TH1D*)h); 1128 1129 hof->SetLineColor(kRed); 1130 hof->SetDirectory(NULL); 1131 hof->SetNameTitle("Result \\alpha", title); 1132 hof->SetBit(kCanDelete); 1133 hof->SetXTitle("\\alpha [\\circ]"); 1134 hof->SetYTitle("Counts"); 1135 hof->Draw("same"); 1136 1137 TH1D *diff = (TH1D*)h->Clone("AlphaFitOnOff"); 1138 diff->Add(hof, -1); 1139 diff->SetLineColor(kBlue); 1140 diff->SetNameTitle("Result On-Off \\alpha", title); 1141 diff->SetBit(kCanDelete); 1142 diff->SetXTitle("\\alpha [\\circ]"); 1143 diff->SetYTitle("Counts"); 1144 diff->Draw("same"); 1145 1146 h->SetMinimum(diff->GetMinimum()<0 ? diff->GetMinimum()*1.2 : 0); 1147 1148 TLine l; 1149 l.DrawLine(0, 0, 90, 0); 1150 } 1151 1152 TF1 f1("f1", Form("gaus(0) + pol%d(3)", fHistOff ? 0 : polynom), 0, 90); 1153 TF1 f2("f2", Form("gaus(0) + pol%d(3)", fHistOff ? 0 : polynom), 0, 90); 1032 1154 f1.SetParameters(maxpar.GetArray()); 1033 1155 f2.SetParameters(maxpar.GetArray()); … … 1053 1175 leg->AddText(0.60, 0.34, Form("b=%.2f (fix)", maxpar[4]))->SetTextAlign(11); 1054 1176 if (polynom>1) 1055 leg->AddText(0.60, 0.14, Form("c=%.2f", maxpar[5]))->SetTextAlign(11);1177 leg->AddText(0.60, 0.14, Form("c=%.2f", !fHistOff?maxpar[5]:0))->SetTextAlign(11); 1056 1178 leg->SetBit(kCanDelete); 1057 1179 leg->Draw();
Note:
See TracChangeset
for help on using the changeset viewer.