Changeset 3666 for trunk/MagicSoft/Mars/mhist
- Timestamp:
- 04/06/04 13:41:56 (21 years ago)
- Location:
- trunk/MagicSoft/Mars/mhist
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/MHFalseSource.cc
r3597 r3666 99 99 // also different algorithms like (Li/Ma) 100 100 // - implement fit for best alpha distribution -- online (Paint) 101 // - currently a constant pointing position is assumed in Fill() 102 // - the center of rotation need not to be the camera center 101 103 // 102 104 ////////////////////////////////////////////////////////////////////////////// … … 117 119 #include "MObservatory.h" 118 120 #include "MPointingPos.h" 121 #include "MAstroCatalog.h" 119 122 #include "MAstroSky2Local.h" 120 123 #include "MStatusDisplay.h" … … 136 139 // 137 140 MHFalseSource::MHFalseSource(const char *name, const char *title) 138 : fMm2Deg(-1), fUseMmScale(kTRUE), fAlphaCut(12.5), fBgMean(55) 141 : fTime(0), fPointPos(0), fObservatory(0), fMm2Deg(-1), 142 fAlphaCut(12.5), fBgMean(55), fDistMin(-1), fDistMax(-1) 139 143 { 140 144 // … … 186 190 // -------------------------------------------------------------------------- 187 191 // 188 // Use this function to setup your own conversion factor between degrees189 // and millimeters. The conversion factor should be the one calculated in190 // MGeomCam. Use this function with Caution: You could create wrong values191 // by setting up your own scale factor.192 //193 void MHFalseSource::SetMm2Deg(Float_t mmdeg)194 {195 if (mmdeg<0)196 {197 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;198 return;199 }200 201 if (fMm2Deg>=0)202 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;203 204 fMm2Deg = mmdeg;205 }206 207 // --------------------------------------------------------------------------208 //209 // With this function you can convert the histogram ('on the fly') between210 // degrees and millimeters.211 //212 void MHFalseSource::SetMmScale(Bool_t mmscale)213 {214 if (fUseMmScale == mmscale)215 return;216 217 if (fMm2Deg<0)218 {219 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;220 return;221 }222 223 if (fUseMmScale)224 {225 fHist.SetXTitle("x [mm]");226 fHist.SetYTitle("y [mm]");227 228 fHist.Scale(1./fMm2Deg);229 }230 else231 {232 fHist.SetXTitle("x [\\circ]");233 fHist.SetYTitle("y [\\circ]");234 235 fHist.Scale(1./fMm2Deg);236 }237 238 fUseMmScale = mmscale;239 }240 241 // --------------------------------------------------------------------------242 //243 192 // Calculate Significance as 244 193 // significance = (s-b)/sqrt(s+k*k*b) mit k=s/b … … 249 198 Double_t MHFalseSource::Significance(Double_t s, Double_t b) 250 199 { 251 return MMath::Significance (s, b);200 return MMath::SignificanceSym(s, b); 252 201 } 253 202 … … 263 212 Double_t MHFalseSource::SignificanceLiMa(Double_t s, Double_t b, Double_t alpha) 264 213 { 265 const Double_t lima = MMath::SignificanceLiMa(s, b); 266 return lima<0 ? 0 : lima; 214 return MMath::SignificanceLiMaSigned(s, b); 215 /* 216 const Double_t lima = MMath::SignificanceLiMa(s, b); 217 return lima<0 ? 0 : lima; 218 */ 267 219 } 268 220 … … 277 229 { 278 230 const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam"); 279 if ( geom)231 if (!geom) 280 232 { 281 fMm2Deg = geom->GetConvMm2Deg(); 282 fUseMmScale = kFALSE; 283 284 fHist.SetXTitle("x [\\circ]"); 285 fHist.SetYTitle("y [\\circ]"); 233 *fLog << err << "MGeomCam not found... aborting." << endl; 234 return kFALSE; 286 235 } 236 237 fMm2Deg = geom->GetConvMm2Deg(); 287 238 288 239 MBinning binsa; … … 292 243 if (!bins) 293 244 { 294 Float_t r = geom ? geom->GetMaxRadius() : 600; 295 r /= 3; 296 if (!fUseMmScale) 297 r *= fMm2Deg; 245 const Float_t r = (geom ? geom->GetMaxRadius()/3 : 200)*fMm2Deg; 298 246 299 247 MBinning b; … … 314 262 fObservatory = (MObservatory*)plist->FindObject(AddSerialNumber("MObservatory")); 315 263 if (!fObservatory) 316 *fLog << err << "MObservatory not found... no derotation." << endl; 317 264 *fLog << warn << "MObservatory not found... no derotation." << endl; 265 266 // FIXME: Because the pointing position could change we must check 267 // for the current pointing position and add a offset in the 268 // Fill function! 269 fRa = fPointPos->GetRa(); 270 fDec = fPointPos->GetDec(); 318 271 319 272 return kTRUE; … … 326 279 Bool_t MHFalseSource::Fill(const MParContainer *par, const Stat_t w) 327 280 { 328 MHillas *hil = (MHillas*)par; 329 281 const MHillas *hil = dynamic_cast<const MHillas*>(par); 282 if (!hil) 283 { 284 *fLog << err << "MHFalseSource::Fill: No container specified!" << endl; 285 return kFALSE; 286 } 287 288 // Get max radius... 330 289 const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1)); 331 290 … … 337 296 // rho = fPointPos->RotationAngle(*fObservatory); 338 297 298 // Create necessary containers for calculation 339 299 MSrcPosCam src; 340 300 MHillasSrc hsrc; 341 301 hsrc.SetSrcPos(&src); 342 302 303 // Get number of bins and bin-centers 343 304 const Int_t nx = fHist.GetNbinsX(); 344 305 const Int_t ny = fHist.GetNbinsY(); … … 352 313 for (int iy=0; iy<ny; iy++) 353 314 { 315 // check distance... to get a circle plot 354 316 if (TMath::Hypot(cx[ix], cy[iy])>maxr) 355 317 continue; 356 318 319 // rotate center of bin 320 // precalculation of sin/cos doesn't accelerate 357 321 TVector2 v(cx[ix], cy[iy]); 358 322 if (rho!=0) 359 323 v=v.Rotate(rho); 360 324 361 if (!fUseMmScale) 362 v *= 1./fMm2Deg; 363 325 // convert degrees to millimeters 326 v *= 1./fMm2Deg; 364 327 src.SetXY(v); 365 328 329 // Source dependant hillas parameters 366 330 if (!hsrc.Calc(hil)) 367 331 { … … 370 334 } 371 335 336 // FIXME: This should be replaced by an external MFilter 337 // and/or MTaskList 338 // Source dependant distance cut 339 if (fDistMin>0 && hsrc.GetDist()*fMm2Deg<fDistMin) 340 continue; 341 342 if (fDistMax>0 && hil->GetLength()>fDistMax*hsrc.GetDist()) 343 continue; 344 345 // Fill histogram 372 346 const Double_t alpha = hsrc.GetAlpha(); 373 374 347 fHist.Fill(cx[ix], cy[iy], TMath::Abs(alpha), w); 375 348 } … … 446 419 // -------------------------------------------------------------------------- 447 420 // 448 // Update the projections 421 // Create projection for all data, taking sum of bin contents of 422 // range (0, 90) - corresponding to the number of entries in this slice. 423 // 424 void MHFalseSource::ProjectAll(TH2D *h3) 425 { 426 h3->SetTitle("Number of entries"); 427 428 // Get projection for range 429 TH2D *p = (TH2D*)fHist.Project3D("yx_all"); 430 431 // Move contents from projection to h3 432 h3->Reset(); 433 h3->Add(p); 434 delete p; 435 436 // Set Minimum as minimum value Greater Than 0 437 h3->SetMinimum(GetMinimumGT(*h3)); 438 } 439 440 // -------------------------------------------------------------------------- 441 // 442 // Update the projections and paint them 449 443 // 450 444 void MHFalseSource::Paint(Option_t *opt) 451 445 { 452 // sigma = (s-b)/sqrt(s+k*k*b) mit k=s/b 453 446 // Set pretty color palette 454 447 gStyle->SetPalette(1, 0); 455 448 … … 457 450 458 451 TH1D* h1; 452 TH2D* h0; 459 453 TH2D* h2; 460 454 TH2D* h3; 461 455 TH2D* h4; 462 456 463 padsave->cd(3); 457 // Update projection of all-events 458 padsave->GetPad(1)->cd(3); 459 if ((h0 = (TH2D*)gPad->FindObject("Alpha_yx_all"))) 460 ProjectAll(h0); 461 462 // Update projection of off-events 463 padsave->GetPad(2)->cd(1); 464 if ((h2 = (TH2D*)gPad->FindObject("Alpha_yx_off"))) 465 ProjectOff(h2); 466 467 // Update projection of on-events 468 padsave->GetPad(2)->cd(2); 464 469 if ((h3 = (TH2D*)gPad->FindObject("Alpha_yx_on"))) 465 470 ProjectOn(h3); 466 471 467 padsave->cd(4); 468 if ((h2 = (TH2D*)gPad->FindObject("Alpha_yx_off"))) 469 ProjectOff(h2); 470 471 padsave->cd(2); 472 // Update projection of significance 473 padsave->GetPad(2)->cd(3); 472 474 if (h2 && h3 && (h4 = (TH2D*)gPad->FindObject("Alpha_yx_sig"))) 473 475 { 474 476 const Int_t nx = h4->GetXaxis()->GetNbins(); 475 477 const Int_t ny = h4->GetYaxis()->GetNbins(); 476 const Int_t nr = nx*nx + ny*ny;478 //const Int_t nr = nx*nx + ny*ny; 477 479 478 480 Int_t maxx=nx/2; … … 493 495 h4->SetBinContent(n, sig); 494 496 495 if (sig>h4->GetBinContent(max) && sig>0 && ix*ix+iy*iy<nr*nr/9)497 if (sig>h4->GetBinContent(max) && sig>0/* && (ix-nx/2)*(ix-nx/2)+(iy-ny/2)*(iy-ny/2)<nr*nr/9*/) 496 498 { 497 499 max = n; … … 501 503 } 502 504 503 padsave->cd(1); 505 // Update projection of 'the best alpha-plot' 506 padsave->GetPad(1)->cd(1); 504 507 if ((h1 = (TH1D*)gPad->FindObject("Alpha")) && max>0) 505 508 { … … 520 523 // -------------------------------------------------------------------------- 521 524 // 525 // Get the MAstroCatalog corresponding to fRa, fDec. The limiting magnitude 526 // is set to 9, while the fov is equal to the current fov of the false 527 // source plot. 528 // 529 TObject *MHFalseSource::GetCatalog() 530 { 531 const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1)); 532 533 // Create catalog... 534 MAstroCatalog stars; 535 stars.SetLimMag(9); 536 stars.SetGuiActive(kFALSE); 537 stars.SetRadiusFOV(maxr); 538 stars.SetRaDec(fRa*TMath::DegToRad()*15, fDec*TMath::DegToRad()); 539 stars.ReadBSC("bsc5.dat"); 540 541 TObject *o = (MAstroCatalog*)stars.Clone(); 542 o->SetBit(kCanDelete); 543 544 return o; 545 } 546 547 // -------------------------------------------------------------------------- 548 // 522 549 // Draw the histogram 523 550 // … … 529 556 AppendPad(""); 530 557 531 pad->Divide(2, 2); 558 pad->Divide(1, 2, 0, 0.03); 559 560 TObject *catalog = GetCatalog(); 532 561 533 562 // draw the 2D histogram Sigmabar versus Theta 534 563 pad->cd(1); 535 564 gPad->SetBorderMode(0); 565 gPad->Divide(3, 1); 566 delete pad->GetPad(1)->GetPad(2); 567 568 pad->GetPad(1)->cd(3); 569 gPad->SetBorderMode(0); 570 TH1 *h0 = fHist.Project3D("yx_all"); 571 h0->SetDirectory(NULL); 572 h0->SetXTitle(fHist.GetXaxis()->GetTitle()); 573 h0->SetYTitle(fHist.GetYaxis()->GetTitle()); 574 h0->Draw("colz"); 575 h0->SetBit(kCanDelete); 576 catalog->Draw("mirror same"); 577 578 pad->GetPad(1)->cd(1); 579 gPad->SetBorderMode(0); 580 536 581 TH1 *h1 = fHist.ProjectionZ("Alpha"); 537 582 h1->SetDirectory(NULL); … … 542 587 h1->SetBit(kCanDelete); 543 588 544 pad->cd(4); 589 pad->cd(2); 590 gPad->SetBorderMode(0); 591 gPad->Divide(3, 1); 592 593 pad = gPad; 594 595 pad->cd(1); 545 596 gPad->SetBorderMode(0); 546 597 fHist.GetZaxis()->SetRangeUser(fBgMean-fAlphaCut/2, fBgMean+fAlphaCut/2); … … 551 602 h2->Draw("colz"); 552 603 h2->SetBit(kCanDelete); 553 554 pad->cd(3); 604 catalog->Draw("mirror same"); 605 606 pad->cd(2); 555 607 gPad->SetBorderMode(0); 556 608 fHist.GetZaxis()->SetRangeUser(0,fAlphaCut); … … 562 614 h3->Draw("colz"); 563 615 h3->SetBit(kCanDelete); 564 565 pad->cd(2); 616 catalog->Draw("mirror same"); 617 618 pad->cd(3); 566 619 gPad->SetBorderMode(0); 567 620 fHist.GetZaxis()->SetRange(0,0); … … 574 627 h4->Draw("colz"); 575 628 h4->SetBit(kCanDelete); 629 catalog->Draw("mirror same"); 576 630 } 577 631 … … 596 650 TVirtualPad *padsave = gPad; 597 651 padsave->Modified(); 598 padsave-> cd(1);652 padsave->GetPad(1)->cd(1); 599 653 gPad->Modified(); 600 padsave-> cd(2);654 padsave->GetPad(1)->cd(3); 601 655 gPad->Modified(); 602 padsave-> cd(3);656 padsave->GetPad(2)->cd(1); 603 657 gPad->Modified(); 604 padsave->cd(4); 658 padsave->GetPad(2)->cd(2); 659 gPad->Modified(); 660 padsave->GetPad(2)->cd(3); 605 661 gPad->Modified(); 606 662 gPad->cd(); … … 639 695 void MHFalseSource::FitSignificance(Float_t sigint, Float_t sigmax, Float_t bgmin, Float_t bgmax, Byte_t polynom) 640 696 { 697 TObject *catalog = GetCatalog(); 698 641 699 TH1D h0a("A", "", 50, 0, 4000); 642 700 TH1D h4a("chisq1", "", 50, 0, 35); … … 686 744 // Implementing the function yourself is only about 5% faster 687 745 TF1 func("", Form("gaus(0) + pol%d(3)", polynom), 0, 90); 746 //TF1 func("", Form("[0]*(TMath::Gaus(x, [1], [2])+TMath::Gaus(x, -[1], [2]))+pol%d(3)", polynom), 0, 90); 688 747 TArrayD maxpar(func.GetNpar()); 689 748 690 /* 691 func.SetParName(0, "A"); 692 func.SetParName(1, "mu"); 693 func.SetParName(2, "sigma"); 694 func.SetParName(3, "a"); 695 func.SetParName(4, "b"); 696 func.SetParName(5, "c"); 749 /* func.SetParName(0, "A"); 750 * func.SetParName(1, "mu"); 751 * func.SetParName(2, "sigma"); 697 752 */ 698 753 … … 704 759 const Int_t nx = hist->GetXaxis()->GetNbins(); 705 760 const Int_t ny = hist->GetYaxis()->GetNbins(); 706 const Int_t nr = nx*nx+ny*ny;761 //const Int_t nr = nx*nx+ny*ny; 707 762 708 763 Double_t maxalpha0=0; … … 748 803 749 804 h->Fit(&func, "N0Q", "", bgmin, bgmax); 750 //*fLog << dbg << ix << "/" << iy << ": " << func.GetParameter(3) << " " << func.GetParameter(4) << endl;751 805 752 806 h4a.Fill(func.GetChisquare()); … … 774 828 775 829 h->Fit(&func, "N0Q", "", 0, sigmax); 776 //*fLog << dbg << " " << func.GetParameter(0) << " " << func.GetParameter(1) << " " << func.GetParameter(2) << endl;777 830 778 831 TArrayD p(func.GetNpar(), func.GetParameters()); … … 820 873 h6.Fill(sig); 821 874 822 if (sig>maxs && ix*ix+iy*iy<nr*nr/9)875 if (sig>maxs/* && (ix-nx/2)*(ix-nx/2)+(iy-ny/2)*(iy-ny/2)<nr*nr/9*/) 823 876 { 824 877 maxs = sig; … … 838 891 839 892 clk.Stop(); 840 clk.Print( );893 clk.Print("m"); 841 894 842 895 TCanvas *c=new TCanvas; … … 849 902 hists->Draw("colz"); 850 903 hists->SetBit(kCanDelete); 904 catalog->Draw("mirror same"); 851 905 c->cd(2); 852 906 gPad->SetBorderMode(0); 853 907 hist->Draw("colz"); 854 908 hist->SetBit(kCanDelete); 909 catalog->Draw("mirror same"); 855 910 c->cd(3); 856 911 gPad->SetBorderMode(0); 857 912 histb->Draw("colz"); 858 913 histb->SetBit(kCanDelete); 914 catalog->Draw("mirror same"); 859 915 c->cd(4); 860 916 gPad->Divide(1,3, 0, 0); … … 942 998 const Double_t b = f2.Integral(0, (float)i)/w; 943 999 944 const Double_t sig = Significance (s, b);1000 const Double_t sig = SignificanceLiMa(s, b); 945 1001 946 1002 g->SetPoint(g->GetN(), i, sig); -
trunk/MagicSoft/Mars/mhist/MHFalseSource.h
r3597 r3666 12 12 class TH2D; 13 13 14 class MHillasSrc;15 class MEnergyEst;16 14 class MParList; 17 15 class MTime; … … 22 20 { 23 21 private: 24 MTime *fTime; //! container to take the event time from25 MPointingPos *fPointPos; //! container to take pointing position from26 MObservatory *fObservatory; //! conteiner to take observatory location from22 MTime *fTime; //! container to take the event time from 23 MPointingPos *fPointPos; //! container to take pointing position from 24 MObservatory *fObservatory; //! conteiner to take observatory location from 27 25 28 Float_t fMm2Deg; // conversion factor for display in degrees 29 Bool_t fUseMmScale; // which scale to use? 26 Float_t fMm2Deg; // conversion factor for display in degrees 30 27 31 Float_t fAlphaCut; // Alpha cut32 Float_t fBgMean; // Background mean28 Float_t fAlphaCut; // Alpha cut 29 Float_t fBgMean; // Background mean 33 30 34 TH3D fHist; // Alpha vs. x and y 31 Float_t fDistMin; // Min dist 32 Float_t fDistMax; // Maximum distance in percent of dist 33 34 TH3D fHist; // Alpha vs. x and y 35 36 Double_t fRa; 37 Double_t fDec; 35 38 36 39 Int_t DistancetoPrimitive(Int_t px, Int_t py); … … 39 42 void ProjectOff(TH2D *h); 40 43 void ProjectOn(TH2D *h); 44 void ProjectAll(TH2D *h); 45 46 TObject *GetCatalog(); 41 47 42 48 public: … … 46 52 Bool_t Fill(const MParContainer *par, const Stat_t w=1); 47 53 48 void SetMmScale(Bool_t mmscale=kTRUE);49 void SetMm2Deg(Float_t mmdeg);50 51 54 TH1 *GetHistByName(const TString name) { return &fHist; } 52 55 53 56 void FitSignificance(Float_t sigint=15, Float_t sigmax=70, Float_t bgmin=40, Float_t bgmax=70, Byte_t polynom=1); //*MENU* 54 57 void FitSignificanceStd() { FitSignificance(); } //*MENU* 58 59 void SetDistMin(Float_t dist) { fDistMin = dist; } // Absolute minimum distance 60 void SetDistMax(Float_t ratio) { fDistMax = ratio; } // Maximum ratio between length/dist 55 61 56 62 void SetAlphaCut(Float_t alpha); //*MENU* -
trunk/MagicSoft/Mars/mhist/MHStarMap.cc
r3594 r3666 34 34 // For a given a shower, a series of points along its main axis are filled 35 35 // into the 2-dim histogram (x, y) of the camera plane. 36 // 36 // 37 37 // Before filling a point (x, y) into the histogram it is 38 38 // - shifted by (xSrc, ySrc) (the expected source position) 39 39 // - and rotated in order to compensate the rotation of the 40 40 // sky image in the camera 41 // 42 // 41 // 42 // To be done: 43 // - simplification of the algorithm, by doing all translation before 44 // calculation of the line 45 // - the center of rotation need not to be the camera center 46 // 43 47 ///////////////////////////////////////////////////////////////////////////// 44 48 #include "MHStarMap.h"
Note:
See TracChangeset
for help on using the changeset viewer.