Changeset 1504 for trunk/MagicSoft/Mars/mhist/MH.cc
- Timestamp:
- 08/16/02 11:47:30 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/MH.cc
r1484 r1504 54 54 #include <TGaxis.h> 55 55 #include <TCanvas.h> 56 #include <TLegend.h> 57 #include <TPaveStats.h> 56 58 57 59 #include "MLog.h" … … 133 135 } 134 136 137 // -------------------------------------------------------------------------- 138 // 139 // Applies a given binning to a 1D-histogram 140 // 135 141 void MH::SetBinning(TH1 *h, const MBinning *binsx) 136 142 { … … 161 167 } 162 168 169 // -------------------------------------------------------------------------- 170 // 171 // Applies given binnings to the two axis of a 2D-histogram 172 // 163 173 void MH::SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy) 164 174 { … … 194 204 } 195 205 206 // -------------------------------------------------------------------------- 207 // 208 // Applies given binnings to the three axis of a 3D-histogram 209 // 196 210 void MH::SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz) 197 211 { … … 232 246 } 233 247 248 // -------------------------------------------------------------------------- 249 // 250 // Applies given binning (the n+1 edges) to the axis of a 1D-histogram 251 // 234 252 void MH::SetBinning(TH1 *h, const TArrayD &binsx) 235 253 { … … 239 257 } 240 258 259 // -------------------------------------------------------------------------- 260 // 261 // Applies given binning (the n+1 edges) to the two axis of a 262 // 2D-histogram 263 // 241 264 void MH::SetBinning(TH2 *h, const TArrayD &binsx, const TArrayD &binsy) 242 265 { … … 248 271 } 249 272 273 // -------------------------------------------------------------------------- 274 // 275 // Applies given binning (the n+1 edges) to the three axis of a 276 // 3D-histogram 277 // 250 278 void MH::SetBinning(TH3 *h, const TArrayD &binsx, const TArrayD &binsy, const TArrayD &binsz) 251 279 { … … 259 287 } 260 288 289 // -------------------------------------------------------------------------- 290 // 291 // Applies the binning of a TAxis (eg from a root histogram) to the axis 292 // of a 1D-histogram 293 // 261 294 void MH::SetBinning(TH1 *h, const TAxis *binsx) 262 295 { … … 270 303 } 271 304 305 // -------------------------------------------------------------------------- 306 // 307 // Applies the binnings of the TAxis' (eg from a root histogram) to the 308 // two axis' of a 2D-histogram 309 // 272 310 void MH::SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy) 273 311 { … … 285 323 } 286 324 325 // -------------------------------------------------------------------------- 326 // 327 // Applies the binnings of the TAxis' (eg from a root histogram) to the 328 // three axis' of a 3D-histogram 329 // 287 330 void MH::SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz) 288 331 { … … 304 347 } 305 348 349 // -------------------------------------------------------------------------- 350 // 351 // Applies the binnings of one root-histogram x to another one h 352 // Both histograms must be of the same type: TH1, TH2 or TH3 353 // 306 354 void MH::SetBinning(TH1 *h, TH1 *x) 307 355 { … … 311 359 return; 312 360 } 361 if (h->InheritsFrom(TH3::Class()) || x->InheritsFrom(TH3::Class())) 362 return; 313 363 if (h->InheritsFrom(TH2::Class()) && x->InheritsFrom(TH2::Class())) 314 364 { … … 316 366 return; 317 367 } 368 if (h->InheritsFrom(TH2::Class()) || x->InheritsFrom(TH2::Class())) 369 return; 318 370 if (h->InheritsFrom(TH1::Class()) && x->InheritsFrom(TH1::Class())) 319 371 { … … 323 375 } 324 376 377 // -------------------------------------------------------------------------- 378 // 379 // Multiplies all entries in a TArrayD by a float f 380 // 325 381 void MH::ScaleArray(TArrayD &bins, Double_t f) 326 382 { … … 329 385 } 330 386 387 // -------------------------------------------------------------------------- 388 // 389 // Scales the binning of a TAxis by a float f 390 // 331 391 TArrayD MH::ScaleAxis(TAxis &axe, Double_t f) 332 392 { … … 341 401 } 342 402 403 // -------------------------------------------------------------------------- 404 // 405 // Scales the binning of one, two or three axis of a histogram by a float f 406 // 343 407 void MH::ScaleAxis(TH1 *h, Double_t fx, Double_t fy, Double_t fz) 344 408 { … … 364 428 } 365 429 430 // -------------------------------------------------------------------------- 431 // 432 // Tries to find a MBinning container with the name "Binning"+name 433 // in the given parameter list. If it was found it is applied to the 434 // given histogram. This is only valid for 1D-histograms 435 // 366 436 Bool_t MH::ApplyBinning(const MParList &plist, TString name, TH1 *h) 367 437 { … … 442 512 } 443 513 514 // -------------------------------------------------------------------------- 515 // 516 // Returns the lowest entry in a histogram which is greater than gt (eg >0) 517 // 444 518 Double_t MH::GetMinimumGT(const TH1 &h, Double_t gt) 445 519 { … … 456 530 return min; 457 531 } 532 533 // -------------------------------------------------------------------------- 534 // 535 // Draws a copy of the two given histograms. Uses title as the pad title. 536 // Also layout the two statistic boxes and a legend. 537 // 538 void MH::DrawCopy(const TH1 &hist1, const TH1 &hist2, const TString title) 539 { 540 // 541 // Draw first histogram 542 // 543 TH1 *h1 = (TH1*)((TH1&)hist1).DrawCopy(); 544 gPad->Update(); 545 546 // 547 // Rename first statistics box 548 // 549 TPaveStats &s1 = *(TPaveStats*)gPad->FindObject("stats"); 550 s1.SetX1NDC(s1.GetX1NDC()-0.01); 551 s1.SetName((TString)"Stat"+hist1.GetTitle()); 552 553 // 554 // Draw second histogram 555 // 556 TH1 *h2 = (TH1*)((TH1&)hist2).DrawCopy("sames"); 557 558 gPad->Update(); 559 560 // 561 // Set new position of second statistics box 562 // 563 TPaveStats &s2 = *(TPaveStats*)gPad->FindObject("stats"); 564 s2.SetX1NDC(s1.GetX1NDC()-(s2.GetX2NDC()-s2.GetX1NDC())-0.01); 565 s2.SetX2NDC(s1.GetX1NDC()-0.01); 566 567 // 568 // Draw Legend 569 // 570 TLegend &l = *new TLegend(s1.GetX1NDC(), 571 s1.GetY1NDC()-0.015-(s1.GetY2NDC()-s1.GetY1NDC())/2, 572 s1.GetX2NDC(), 573 s1.GetY1NDC()-0.01 574 ); 575 l.AddEntry(h1, h1->GetTitle()); 576 l.AddEntry(h2, h2->GetTitle()); 577 l.SetTextSize(s2.GetTextSize()); 578 l.SetTextFont(s2.GetTextFont()); 579 l.SetBorderSize(s2.GetBorderSize()); 580 l.SetBit(kCanDelete); 581 582 // FIXME: Don't change the hist title. Change TPaveText::title 583 h1->SetTitle(" "+title+" "); 584 585 l.Draw(); 586 } 587 588 // -------------------------------------------------------------------------- 589 // 590 // Draws the two given histograms. Uses title as the pad title. 591 // Also layout the two statistic boxes and a legend. 592 // 593 void MH::Draw(TH1 &hist1, TH1 &hist2, const TString title) 594 { 595 // 596 // Draw first histogram 597 // 598 hist1.Draw(); 599 // FIXME: Don't change the hist title. Change TPaveText::title 600 //h1->SetTitle(" "+title+" "); 601 602 gPad->Update(); 603 604 // 605 // Rename first statistics box 606 // 607 TPaveStats &s1 = *(TPaveStats*)gPad->FindObject("stats"); 608 s1.SetX1NDC(s1.GetX1NDC()-0.01); 609 s1.SetName((TString)"Stat"+hist1.GetTitle()); 610 611 // 612 // Draw second histogram 613 // 614 hist2.Draw("sames"); 615 616 gPad->Update(); 617 618 // 619 // Set new position of second statistics box 620 // 621 TPaveStats &s2 = *(TPaveStats*)gPad->FindObject("stats"); 622 s2.SetX1NDC(s1.GetX1NDC()-(s2.GetX2NDC()-s2.GetX1NDC())-0.01); 623 s2.SetX2NDC(s1.GetX1NDC()-0.01); 624 625 // 626 // Draw Legend 627 // 628 TLegend &l = *new TLegend(s1.GetX1NDC(), 629 s1.GetY1NDC()-0.015-(s1.GetY2NDC()-s1.GetY1NDC())/2, 630 s1.GetX2NDC(), 631 s1.GetY1NDC()-0.01 632 ); 633 l.AddEntry(&hist1, hist1.GetTitle()); 634 l.AddEntry(&hist2, hist2.GetTitle()); 635 l.SetTextSize(s2.GetTextSize()); 636 l.SetTextFont(s2.GetTextFont()); 637 l.SetBorderSize(s2.GetBorderSize()); 638 l.SetBit(kCanDelete); 639 l.Draw(); 640 }
Note:
See TracChangeset
for help on using the changeset viewer.