Changeset 1504 for trunk/MagicSoft
- Timestamp:
- 08/16/02 11:47:30 (22 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r1503 r1504 7 7 8 8 * mhist/MHHillas.cc, mhist/MHHillasExt.cc: 9 - added legends. (still work to be done with the stat boxes) 9 - use the new MH::Draw[Copy] function 10 - added names to the histograms in MHHillasExt 10 11 11 12 * manalysis/MCerPhotPix.h: … … 15 16 - added comment 16 17 18 * mhist/MH.[h,cc]: 19 - added function to draw two histograms in one pad with 20 a layout of two stat boxes and a legend: Draw[Copy] 21 - added comments 22 - added another sanity check in SetBinning(TH1*,TH1*) 17 23 18 24 -
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 } -
trunk/MagicSoft/Mars/mhist/MH.h
r1463 r1504 50 50 static void ScaleAxis(TH1 *bins, Double_t fx=1, Double_t fy=1, Double_t fz=1); 51 51 52 static void DrawCopy(const TH1 &hist1, const TH1 &hist2, const TString title); 53 static void Draw(TH1 &hist1, TH1 &hist2, const TString title); 54 52 55 static void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger); 53 56 static Double_t GetMinimumGT(const TH1 &h, Double_t gt=0); -
trunk/MagicSoft/Mars/mhist/MHHillas.cc
r1502 r1504 41 41 #include <TStyle.h> 42 42 #include <TCanvas.h> 43 #include <TLegend.h>44 43 45 44 #include "MLog.h" … … 295 294 296 295 c->cd(1); 297 298 TObject *obj; 299 TLegend *l = new TLegend(0.75, 0.8, 0.9, 0.9); 300 obj = fWidth->DrawCopy(); 301 ((TH1*)obj)->SetTitle(" Width / Length "); 302 l->AddEntry(obj, "Width"); 303 obj = fLength->DrawCopy("same"); 304 l->AddEntry(obj, "Length"); 305 l->SetBit(kCanDelete); 306 l->Draw(); 296 DrawCopy(*fWidth, *fLength, "Width / Length"); 307 297 308 298 c->cd(2); … … 311 301 312 302 c->cd(3); 313 l = new TLegend(0.70, 0.8, 0.9, 0.9); 314 obj = fCorePix->DrawCopy(); 315 ((TH1*)obj)->SetTitle(" Number of core/used Pixels "); 316 l->AddEntry(obj, "# Core Pixels"); 317 obj = fUsedPix->DrawCopy("same"); 318 l->AddEntry(obj, "# Used Pixels"); 319 l->SetBit(kCanDelete); 320 l->Draw(); 303 DrawCopy(*fCorePix, *fUsedPix, "Number of core/used Pixels"); 321 304 322 305 c->cd(4); … … 350 333 351 334 gPad->cd(1); 352 fWidth->Draw(); 353 fLength->Draw("same"); 335 MH::Draw(*fWidth, *fLength, "Width / Length"); 354 336 355 337 gPad->cd(2); … … 358 340 359 341 gPad->cd(3); 360 fCorePix->Draw(); 361 fUsedPix->Draw("same"); 342 MH::Draw(*fCorePix, *fUsedPix, "Number of core/used Pixels"); 362 343 363 344 gPad->cd(4); -
trunk/MagicSoft/Mars/mhist/MHHillasExt.cc
r1502 r1504 80 80 fHM3Trans.SetDirectory(NULL); 81 81 82 fHConc.SetName("Conc2"); 83 fHConc1.SetName("Conc1"); 84 fHAsym.SetName("Asymmetry"); 85 fHM3Long.SetName("3rd Mom Long"); 86 fHM3Trans.SetName("3rd Mom Trans"); 87 82 88 fHConc.SetTitle("Ratio: Conc"); 83 89 fHConc1.SetTitle("Ratio: Conc1"); … … 261 267 262 268 c.cd(1); 263 TObject *obj; 264 TLegend *l = new TLegend(0.75, 0.8, 0.9, 0.9); 265 obj = ((TH1F)fHConc1).DrawCopy(); 266 ((TH1*)obj)->SetTitle(" Concentrations "); 267 l->AddEntry(obj, "Conc1"); 268 obj = ((TH1F)fHConc).DrawCopy("same"); 269 l->AddEntry(obj, "Conc2"); 270 l->SetBit(kCanDelete); 271 l->Draw(); 269 DrawCopy(fHConc1, fHConc, "Concentrations"); 272 270 273 271 c.cd(2); 274 ((TH1 F)fHAsym).DrawCopy();272 ((TH1&)fHAsym).DrawCopy(); 275 273 276 274 c.cd(3); 277 ((TH1 F)fHM3Long).DrawCopy();275 ((TH1&)fHM3Long).DrawCopy(); 278 276 279 277 c.cd(4); 280 ((TH1 F)fHM3Trans).DrawCopy();278 ((TH1&)fHM3Trans).DrawCopy(); 281 279 282 280 c.Modified(); … … 300 298 301 299 gPad->cd(1); 302 fHConc1.Draw(); 303 fHConc.Draw("same"); 304 305 TLegend *l = new TLegend(0.75, 0.8, 0.9, 0.9); 306 l->AddEntry((TH1*)&fHConc1, "Conc 1"); 307 l->AddEntry((TH1*)&fHConc, "Conc"); 308 l->SetBit(kCanDelete); 309 l->Draw(); 300 MH::Draw(fHConc1, fHConc, "Concentrations"); 310 301 311 302 gPad->cd(2);
Note:
See TracChangeset
for help on using the changeset viewer.