Changeset 4928
- Timestamp:
- 09/10/04 16:48:25 (20 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r4924 r4928 60 60 * mhist/Makefile, mhist/HistLinkDef.h: 61 61 - added MHEffectiveOnTime 62 63 * mhbase/MH3.cc: 64 - fixed a bug in SetupFill which was introduced when I allowed 65 set the axis titles from the object title 62 66 63 67 -
trunk/MagicSoft/Mars/mhbase/MH3.cc
r4891 r4928 103 103 // 104 104 MH3::MH3(const unsigned int dim) 105 : fDimension(dim>3?3:dim), fHist(NULL) 105 : fDimension(dim>3?3:dim), fHist(NULL), 106 fNameProfX(Form("ProfX_%p", this)), 107 fNameProfY(Form("ProfY_%p", this)) 106 108 { 107 109 switch (fDimension) … … 171 173 // 172 174 MH3::MH3(const char *memberx, const char *membery) 173 : fDimension(2) 175 : fDimension(2), fNameProfX(Form("ProjX_%p", this)), fNameProfY(Form("ProjY_%p", this)) 174 176 { 175 177 fHist = new TH2F; … … 313 315 return kFALSE; 314 316 } 315 316 317 } 317 318 if (fData[0] && !fData[0]->PreProcess(plist)) … … 325 326 } 326 327 327 fHist->SetName(fName);328 fHist->SetDirectory(0);329 330 if (fTitle!=gsDefTitle)331 {332 fHist->SetTitle(fTitle);333 return kTRUE;334 }335 336 328 TString title("Histogram for "); 337 329 title += fName; 338 339 switch (fDimension) 340 { 341 case 1: 342 fHist->SetTitle(title+" (1D)"); 330 title += Form(" (%dD)", fDimension); 331 332 fHist->SetName(fName); 333 fHist->SetTitle(fTitle==gsDefTitle ? title : fTitle); 334 fHist->SetDirectory(0); 335 336 switch (fDimension) 337 { 338 case 1: 343 339 SetBinning(fHist, binsx); 344 340 return kTRUE; 345 341 case 2: 346 fHist->SetTitle(title+" (2D)");347 342 SetBinning((TH2*)fHist, binsx, binsy); 348 343 return kTRUE; 349 344 case 3: 350 fHist->SetTitle(title+" (3D)");351 345 SetBinning((TH3*)fHist, binsx, binsy, binsz); 352 346 return kTRUE; … … 479 473 } 480 474 481 // -------------------------------------------------------------------------- 482 // 483 // Draw clone of histogram. So that the object can be deleted 475 void MH3::Paint(Option_t *o) 476 { 477 TString str(o); 478 479 // FIXME: Do it in Paint() 480 if (str.Contains("COL", TString::kIgnoreCase)) 481 SetColors(); 482 483 if (fHist->TestBit(kIsLogx) && fHist->GetEntries()>0) gPad->SetLogx(); 484 if (fHist->TestBit(kIsLogy) && fHist->GetEntries()>0) gPad->SetLogy(); 485 if (fHist->TestBit(kIsLogz) && fHist->GetEntries()>0) gPad->SetLogz(); 486 487 // Set pretty color palette 488 gStyle->SetPalette(1, 0); 489 490 TVirtualPad *padsave = gPad; 491 492 TProfile* h0; 493 if ((h0 = (TProfile*)gPad->FindObject(fNameProfX))) 494 { 495 // Get projection for range 496 TProfile *p = ((TH2*)fHist)->ProfileX(fNameProfX, -1, 9999, "s"); 497 498 // Move contents from projection to h3 499 h0->Reset(); 500 h0->Add(p); 501 delete p; 502 503 // Set Minimum as minimum value Greater Than 0 504 //h0->SetMinimum(GetMinimumGT(*h0)); 505 } 506 if ((h0 = (TProfile*)gPad->FindObject(fNameProfY))) 507 { 508 // Get projection for range 509 TProfile *p = ((TH2*)fHist)->ProfileY(fNameProfY, -1, 9999, "s"); 510 511 // Move contents from projection to h3 512 h0->Reset(); 513 h0->Add(p); 514 delete p; 515 516 // Set Minimum as minimum value Greater Than 0 517 //h0->SetMinimum(GetMinimumGT(*h0)); 518 } 519 520 gPad = padsave; 521 } 522 523 // -------------------------------------------------------------------------- 524 // 525 // Creates a new canvas and draws the histogram into it. 484 526 // 485 527 // Possible options are: … … 491 533 // eg this is set when applying a logarithmic MBinning 492 534 // 493 // and the histogram is still visible in the canvas. 494 // The cloned object are deleted together with the canvas if the canvas is 495 // destroyed. If you want to handle destroying the canvas you can get a 496 // pointer to it from this function 497 // 498 /* 499 TObject *MH3::DrawClone(Option_t *opt) const 500 { 535 // Be careful: The histogram belongs to this object and won't get deleted 536 // together with the canvas. 537 // 538 void MH3::Draw(Option_t *opt) 539 { 540 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fHist); 541 pad->SetBorderMode(0); 542 543 fHist->SetFillStyle(4000); 544 501 545 TString str(opt); 502 503 TVirtualPad *c = gPad; 504 if (!str.Contains("nonew", TString::kIgnoreCase)) 505 { 506 c = MH::MakeDefCanvas(fHist); 507 508 // 509 // This is necessary to get the expected bahviour of DrawClone 510 // 511 gROOT->SetSelectedPad(NULL); 512 } 513 514 if (str.Contains("COL", TString::kIgnoreCase)) 515 SetColors(); 546 str = str.Strip(TString::kBoth); 516 547 517 548 Bool_t only = str.Contains("ONLY", TString::kIgnoreCase) && fDimension==2; 549 // FIXME: We may have to remove all our own options from str! 518 550 if (!only) 519 fHist->Draw Copy(opt);551 fHist->Draw(str); 520 552 521 553 if (str.Contains("PROFX", TString::kIgnoreCase) && fDimension==2) 522 554 { 523 TProfile *p = ((TH2*)fHist)->ProfileX( "_pfx", -1, 9999, "s");555 TProfile *p = ((TH2*)fHist)->ProfileX(fNameProfX, -1, 9999, "s"); 524 556 p->SetLineColor(kBlue); 525 557 p->Draw(only?"":"same"); … … 529 561 if (str.Contains("PROFY", TString::kIgnoreCase) && fDimension==2) 530 562 { 531 TProfile *p = ((TH2*)fHist)->ProfileY("_pfy", -1, 9999, "s"); 532 p->SetLineColor(kBlue); 533 p->Draw(only?"":"same"); 534 p->SetBit(kCanDelete); 535 p->SetDirectory(NULL); 536 } 537 538 if (fHist->TestBit(kIsLogx)) c->SetLogx(); 539 if (fHist->TestBit(kIsLogy)) c->SetLogy(); 540 if (fHist->TestBit(kIsLogz)) c->SetLogz(); 541 542 c->Modified(); 543 c->Update(); 544 545 return c; 546 } 547 */ 548 549 /* 550 void MH3::Paint(Option_t *opt) 551 { 552 if (fHist->TestBit(kIsLogx)) pad->SetLogx(); 553 if (fHist->TestBit(kIsLogy)) pad->SetLogy(); 554 if (fHist->TestBit(kIsLogz)) pad->SetLogz(); 555 } 556 */ 557 558 void MH3::Paint(Option_t *o) 559 { 560 TString str(o); 561 562 // FIXME: Do it in Paint() 563 if (str.Contains("COL", TString::kIgnoreCase)) 564 SetColors(); 565 566 if (fHist->TestBit(kIsLogx) && fHist->GetEntries()>0) gPad->SetLogx(); 567 if (fHist->TestBit(kIsLogy) && fHist->GetEntries()>0) gPad->SetLogy(); 568 if (fHist->TestBit(kIsLogz) && fHist->GetEntries()>0) gPad->SetLogz(); 569 570 // Set pretty color palette 571 gStyle->SetPalette(1, 0); 572 573 TVirtualPad *padsave = gPad; 574 575 TProfile* h0; 576 if ((h0 = (TProfile*)gPad->FindObject("_pfx"))) 577 { 578 // Get projection for range 579 TProfile *p = ((TH2*)fHist)->ProfileX("_pfx", -1, 9999, "s"); 580 581 // Move contents from projection to h3 582 h0->Reset(); 583 h0->Add(p); 584 delete p; 585 586 // Set Minimum as minimum value Greater Than 0 587 //h0->SetMinimum(GetMinimumGT(*h0)); 588 } 589 if ((h0 = (TProfile*)gPad->FindObject("_pfy"))) 590 { 591 // Get projection for range 592 TProfile *p = ((TH2*)fHist)->ProfileY("_pfy", -1, 9999, "s"); 593 594 // Move contents from projection to h3 595 h0->Reset(); 596 h0->Add(p); 597 delete p; 598 599 // Set Minimum as minimum value Greater Than 0 600 //h0->SetMinimum(GetMinimumGT(*h0)); 601 } 602 603 gPad = padsave; 604 } 605 606 // -------------------------------------------------------------------------- 607 // 608 // Creates a new canvas and draws the histogram into it. 609 // 610 // Possible options are: 611 // PROFX: Draw a x-profile into the histogram (for 2D histograms only) 612 // PROFY: Draw a y-profile into the histogram (for 2D histograms only) 613 // ONLY: Draw the profile histogram only (for 2D histograms only) 614 // 615 // If the kIsLog?-Bit is set the axis is displayed lkogarithmically. 616 // eg this is set when applying a logarithmic MBinning 617 // 618 // Be careful: The histogram belongs to this object and won't get deleted 619 // together with the canvas. 620 // 621 void MH3::Draw(Option_t *opt) 622 { 623 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fHist); 624 pad->SetBorderMode(0); 625 626 fHist->SetFillStyle(4000); 627 628 TString str(opt); 629 str = str.Strip(TString::kBoth); 630 631 632 Bool_t only = str.Contains("ONLY", TString::kIgnoreCase) && fDimension==2; 633 // FIXME: We may have to remove all our own options from str! 634 if (!only) 635 fHist->Draw(str); 636 637 if (str.Contains("PROFX", TString::kIgnoreCase) && fDimension==2) 638 { 639 TProfile *p = ((TH2*)fHist)->ProfileX("_pfx", -1, 9999, "s"); 640 p->SetLineColor(kBlue); 641 p->Draw(only?"":"same"); 642 p->SetBit(kCanDelete); 643 p->SetDirectory(NULL); 644 } 645 if (str.Contains("PROFY", TString::kIgnoreCase) && fDimension==2) 646 { 647 TProfile *p = ((TH2*)fHist)->ProfileY("_pfy", -1, 9999, "s"); 563 TProfile *p = ((TH2*)fHist)->ProfileY(fNameProfY, -1, 9999, "s"); 648 564 p->SetLineColor(kBlue); 649 565 p->Draw(only?"":"same");
Note:
See TracChangeset
for help on using the changeset viewer.