Changeset 2265 for trunk/MagicSoft/Mars/mhist/MHCamera.cc
- Timestamp:
- 07/06/03 21:02:56 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/MHCamera.cc
r2264 r2265 47 47 #include <TRandom.h> 48 48 #include <TPaveText.h> 49 #include <TPaveStats.h> 49 50 #include <TClonesArray.h> 51 #include <THistPainter.h> 52 53 #include "MLog.h" 54 #include "MLogManip.h" 50 55 51 56 #include "MH.h" … … 76 81 // Default Constructor. To be used by the root system ONLY. 77 82 // 78 MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fColors(kItemsLegend) 83 MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fColors(kItemsLegend), fOptStat(-1) 79 84 { 80 85 SetDirectory(NULL); … … 215 220 fTsumwx2 += z*x*x; 216 221 return bin; 222 } 223 224 Stat_t MHCamera::GetMean(Int_t axis) const 225 { 226 Stat_t mean = 0; 227 for (int i=1; i<fNcells-1; i++) 228 mean += fArray[i]; 229 230 return mean/(fNcells-2); 231 } 232 233 Stat_t MHCamera::GetRMS(Int_t axis) const 234 { 235 const Int_t n = fNcells-2; 236 237 Stat_t sum = 0; 238 Stat_t sq = 0; 239 for (int i=1; i<n+1; i++) 240 { 241 sum += fArray[i]; 242 sq += fArray[i]*fArray[i]; 243 } 244 245 sum /= n; 246 sq /= n; 247 248 return sqrt(sq-sum*sum); 217 249 } 218 250 … … 314 346 void MHCamera::SetRange() 315 347 { 316 const Float_t range = fGeomCam->GetMaxRadius() ;348 const Float_t range = fGeomCam->GetMaxRadius()*1.05; 317 349 318 350 // … … 373 405 { 374 406 if (IsUsed(i) && iscol) 407 { 408 if (TMath::IsNaN(fArray[i+1])) 409 gLog << warn << "MHCamera::Update: " << GetName() << " <" << GetTitle() << "> - Pixel Index #" << i << " contents is NaN (Not a Number)..." << endl; 410 375 411 hex.SetFillColor(GetColor(fArray[i+1], min, max, islog)); 412 } 376 413 else 377 414 hex.SetFillColor(10); … … 381 418 hex.PaintHexagon(pix.GetX(), pix.GetY(), pix.GetD()); 382 419 else 383 if (IsUsed(i) )420 if (IsUsed(i) && !TMath::IsNaN(fArray[i+1])) 384 421 { 385 422 Float_t size = pix.GetD()*(fArray[i+1]-min)/(max-min); … … 413 450 void MHCamera::PaintAxisTitle() 414 451 { 415 Float_t fRange = fGeomCam->GetMaxRadius(); 416 417 TLatex *ptitle = new TLatex(1.2*fRange, .97*fRange, GetYaxis()->GetTitle()); 418 419 ptitle->SetTextSize(0.03); 420 ptitle->SetTextAlign(33); 452 const Float_t range = fGeomCam->GetMaxRadius()*1.05; 453 const Float_t w = (1 + 1.5/sqrt((float)(fNcells-2)))*range; 454 455 TLatex *ptitle = new TLatex(w, -.90*range, GetYaxis()->GetTitle()); 456 457 ptitle->SetTextSize(0.05); 458 ptitle->SetTextAlign(21); 421 459 422 460 // box with the histogram title … … 430 468 // ------------------------------------------------------------------------ 431 469 // 432 // Paint the histogram title433 //434 void MHCamera::PaintTitle()435 {436 // *-*-*-*-*-*-*-*-*-*Draw the histogram title*-*-*-*-*-*-*-*-*-*-*-*-*437 // ========================438 //if (Hoption.Same) return;439 #if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)440 if (TestBit(kNoTitle))441 return;442 #endif443 444 const Int_t nt = strlen(GetTitle());445 446 TPaveText *title = (TPaveText*)gPad->FindObject("title");447 if (nt == 0 || gStyle->GetOptTitle() <= 0)448 {449 if (title)450 delete title;451 return;452 }453 454 Double_t ht = gStyle->GetTitleH();455 Double_t wt = gStyle->GetTitleW();456 457 if (ht <= 0)458 ht = 0.05;459 if (wt <= 0)460 {461 TLatex l;462 l.SetTextSize(ht);463 l.SetTitle(GetTitle());464 Double_t wndc = l.GetXsize()/(gPad->GetX2() - gPad->GetX1());465 wt = TMath::Min(0.7, 0.02+wndc);466 }467 if (title)468 {469 TText *t0 = (TText*)title->GetLine(0);470 if (t0)471 {472 if (!strcmp(t0->GetTitle(), GetTitle()))473 return;474 475 t0->SetTitle(GetTitle());476 if (wt > 0)477 title->SetX2NDC(title->GetX1NDC()+wt);478 }479 return;480 }481 482 TPaveText *ptitle = new TPaveText(483 gStyle->GetTitleX(),484 gStyle->GetTitleY()-ht,485 gStyle->GetTitleX()+wt,486 gStyle->GetTitleY(),"blNDC");487 488 // box with the histogram title489 #if ROOT_VERSION_CODE > ROOT_VERSION(3,05,01)490 ptitle->SetFillColor(gStyle->GetTitleFillColor());491 ptitle->SetTextFont(gStyle->GetTitleFont(""));492 if (gStyle->GetTitleFont("")%10 > 2)493 ptitle->SetTextSize(gStyle->GetTitleFontSize());494 #endif495 ptitle->SetFillStyle(gStyle->GetTitleStyle());496 ptitle->SetName("title");497 ptitle->SetBorderSize(gStyle->GetTitleBorderSize());498 ptitle->SetTextColor(gStyle->GetTitleTextColor());499 ptitle->AddText(GetTitle());500 ptitle->SetBit(kCanDelete);501 ptitle->Draw();502 ptitle->Paint();503 }504 505 // ------------------------------------------------------------------------506 //507 470 // Paints the camera. 508 471 // … … 515 478 { 516 479 opt.ReplaceAll("hist", ""); 517 518 480 Int_t mode = gStyle->GetOptStat(); 519 481 TVirtualPad *save = gPad; 520 482 gPad=NULL; 521 gStyle->SetOptStat( 1000011);483 gStyle->SetOptStat(fOptStat<0 ? mode : fOptStat); 522 484 gPad=save; 523 485 TH1D::Paint(o); … … 534 496 Bool_t iscol = isbox ? !opt.Contains("nocol") : 1; 535 497 498 THistPainter paint; 499 if (!TestBit(TH1::kNoStats)) 500 { 501 paint.SetHistogram(this); 502 paint.PaintStat(fOptStat<0?gStyle->GetOptStat():fOptStat, NULL); 503 } 504 536 505 // Update Contents of the pixels and paint legend 537 506 Update(gPad->GetLogy(), isbox, iscol); 538 507 539 508 // Paint primitives (pixels, color legend, photons, ...) 540 PaintTitle();509 paint.PaintTitle(); 541 510 PaintAxisTitle(); 542 511 } … … 619 588 const MGeomPix &h = (*fGeomCam)[i]; 620 589 TText *nt = txt.DrawText(h.GetX(), h.GetY(), num); 621 nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius() );590 nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05); 622 591 } 623 592 } … … 642 611 const MGeomPix &h = (*fGeomCam)[i]; 643 612 TText *nt = txt.DrawText(h.GetX(), h.GetY(), num); 644 nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius() );613 nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05); 645 614 } 646 615 } … … 848 817 { 849 818 if (TMath::IsNaN(val)) // FIXME: gLog! 850 { 851 cout << "MHCamera::GetColor: " << GetName() << " <" << GetTitle() << "> - Color for val=NaN (Not a Number) requested... set val=min." << endl; 852 val = min; 853 } 819 return 10; 854 820 855 821 // … … 877 843 } 878 844 845 TPaveStats *MHCamera::GetStats() 846 { 847 TObject *obj = 0; 848 849 TIter Next(fFunctions); 850 while ((obj = Next())) 851 if (obj->InheritsFrom(TPaveStats::Class())) 852 return static_cast<TPaveStats*>(obj); 853 854 return NULL; 855 } 856 879 857 // ------------------------------------------------------------------------ 880 858 // … … 883 861 void MHCamera::UpdateLegend(Float_t min, Float_t max, Bool_t islog) 884 862 { 885 const Float_t range = fGeomCam->GetMaxRadius(); 886 887 const Float_t H = 0.9*range; 863 TPaveStats *stats = GetStats(); 864 865 const Float_t hndc = 0.92 - (stats ? stats->GetY1NDC() : 1); 866 const Float_t range = fGeomCam->GetMaxRadius()*1.05; 867 const Float_t H = (0.75-hndc)*range; 868 const Float_t offset = hndc*range; 869 888 870 const Float_t h = 2./kItemsLegend; 889 const Float_t offset = 0.04*range;890 891 871 const Float_t w = range/sqrt((float)(fNcells-2)); 892 872 893 873 TBox newbox; 894 874 TText newtxt; 895 newtxt.SetTextSize(0.0 25);875 newtxt.SetTextSize(0.03); 896 876 newtxt.SetTextAlign(12); 897 877 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
Note:
See TracChangeset
for help on using the changeset viewer.