Changeset 8888 for trunk/MagicSoft/Mars/mhbase
- Timestamp:
- 05/14/08 12:03:25 (17 years ago)
- Location:
- trunk/MagicSoft/Mars/mhbase
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhbase/MH3.cc
r8709 r8888 124 124 // Default constructor. 125 125 // 126 MH3::MH3(const unsigned int dim) 127 : fDimension(dim>3?3:dim), fHist(NULL), fStyleBits(0) 128 { 126 MH3::MH3(const Int_t dim, Type_t type) 127 : fDimension(dim), fHist(NULL), fStyleBits(0) 128 { 129 switch (type) 130 { 131 case kHistogram: 132 if (fDimension>3) 133 fDimension=3; 134 break; 135 case kProfile: 136 fDimension = -TMath::Abs(fDimension); 137 if (fDimension<-2) 138 fDimension = -2; 139 break; 140 } 141 129 142 switch (fDimension) 130 143 { … … 132 145 fHist = new TH1D; 133 146 fHist->SetYTitle("Counts"); 147 break; 148 case -1: 149 fHist = new TProfile; 150 fHist->SetYTitle("Average"); 134 151 break; 135 152 case 2: … … 137 154 fHist->SetZTitle("Counts"); 138 155 break; 156 case -2: 157 fHist = new TProfile2D; 158 fHist->SetZTitle("Average"); 159 break; 139 160 case 3: 140 161 fHist = new TH3D; … … 194 215 } 195 216 217 // -------------------------------------------------------------------------- 218 // 219 // Adapt a given histogram 220 // 196 221 MH3::MH3(const TH1 &h1) 197 222 : fDimension(1), fStyleBits(0) … … 237 262 // description above. 238 263 // 239 MH3::MH3(const char *memberx, const char *membery )240 : fDimension( 2), fStyleBits(0)241 { 242 fHist = new TH2D;264 MH3::MH3(const char *memberx, const char *membery, Type_t type) 265 : fDimension(type==kHistogram?2:-1), fStyleBits(0) 266 { 267 fHist = type==kHistogram ? static_cast<TH1*>(new TH2D) : static_cast<TH1*>(new TProfile); //new TH2D; 243 268 244 269 fData[0] = new MDataPhrase(memberx); … … 255 280 fHist->UseCurrentStyle(); 256 281 fHist->SetDirectory(NULL); 257 fHist->SetZTitle( "Counts");282 fHist->SetZTitle(fDimension>0?"Counts":"Average"); 258 283 259 284 fScale[0] = 1; … … 268 293 // description see the class description above. 269 294 // 270 MH3::MH3(const char *memberx, const char *membery, const char *memberz )271 : fDimension( 3), fStyleBits(0)272 { 273 fHist = new TH3D;295 MH3::MH3(const char *memberx, const char *membery, const char *memberz, Type_t type) 296 : fDimension(type==kHistogram?3:-2), fStyleBits(0) 297 { 298 fHist = type==kHistogram ? static_cast<TH1*>(new TH3D) : static_cast<TH1*>(new TProfile2D); //new TH2D; 274 299 275 300 fData[0] = new MDataPhrase(memberx); … … 357 382 MBinning *binsz = NULL; 358 383 359 switch ( fDimension)384 switch (TMath::Abs(fDimension)) 360 385 { 361 386 case 3: … … 366 391 return kFALSE; 367 392 } 368 if (fData[2] && !fData[2]->PreProcess(plist))369 return kFALSE;370 393 if (fData[2]) 371 394 fHist->SetZTitle(fData[2]->GetTitle()); … … 381 404 return kFALSE; 382 405 } 383 if (fData[1] && !fData[1]->PreProcess(plist))384 return kFALSE;385 406 if (fData[1]) 386 407 fHist->SetYTitle(fData[1]->GetTitle()); … … 402 423 } 403 424 } 404 if (fData[0] && !fData[0]->PreProcess(plist))405 return kFALSE;406 425 if (fData[0]!=NULL) 407 426 fHist->SetXTitle(fData[0]->GetTitle()); … … 412 431 } 413 432 414 TString title("Histogram for "); 433 // PreProcess existing fData members 434 for (int i=0; i<3; i++) 435 if (fData[i] && !fData[i]->PreProcess(plist)) 436 return kFALSE; 437 438 TString title(fDimension>0?"Histogram":"Profile"); 439 title += " for "; 415 440 title += name; 416 title += Form(" (%dD)", fDimension);441 title += Form(" (%dD)", TMath::Abs(fDimension)); 417 442 418 443 fHist->SetName(name); … … 420 445 fHist->SetDirectory(0); 421 446 422 switch ( fDimension)447 switch (TMath::Abs(fDimension)) 423 448 { 424 449 case 1: … … 433 458 } 434 459 435 *fLog << err << "ERROR - MH3 has " << fDimension<< " dimensions!" << endl;460 *fLog << err << "ERROR - MH3 has " << TMath::Abs(fDimension) << " dimensions!" << endl; 436 461 return kFALSE; 437 462 } … … 487 512 switch (fDimension) 488 513 { 489 case 3: 514 case -2: 515 case 3: 490 516 z = fData[2]->GetValue()*fScale[2]; 491 case 2: 517 case -1: 518 case 2: 492 519 y = fData[1]->GetValue()*fScale[1]; 493 case 1:520 case 1: 494 521 x = fData[0]->GetValue()*fScale[0]; 495 522 } … … 497 524 switch (fDimension) 498 525 { 499 case 3:500 ((TH3*)fHist)->Fill(x, y, z, w);526 case 3: 527 static_cast<TH3*>(fHist)->Fill(x, y, z, w); 501 528 return kTRUE; 502 case 2:503 ((TH2*)fHist)->Fill(x, y, w);529 case 2: 530 static_cast<TH2*>(fHist)->Fill(x, y, w); 504 531 return kTRUE; 505 532 case 1: 506 533 fHist->Fill(x, w); 507 534 return kTRUE; 535 case -1: 536 static_cast<TProfile*>(fHist)->Fill(x, y, w); 537 return kTRUE; 538 case -2: 539 static_cast<TProfile2D*>(fHist)->Fill(x, y, z, w); 540 return kTRUE; 508 541 } 509 542 … … 549 582 TProfile *p=0; 550 583 551 if ( fDimension==2)584 if (TMath::Abs(fDimension)==2) 552 585 MH::SetPalette("pretty"); 553 586 … … 629 662 str.ToLower(); 630 663 631 const Bool_t only = str.Contains("only") && fDimension==2;632 const Bool_t same = str.Contains("same") && fDimension<3;633 const Bool_t blue = str.Contains("blue") && fDimension==2;634 const Bool_t profx = str.Contains("profx") && fDimension==2;635 const Bool_t profy = str.Contains("profy") && fDimension==2;664 const Bool_t only = str.Contains("only") && TMath::Abs(fDimension)==2; 665 const Bool_t same = str.Contains("same") && TMath::Abs(fDimension)<3; 666 const Bool_t blue = str.Contains("blue") && TMath::Abs(fDimension)==2; 667 const Bool_t profx = str.Contains("profx") && TMath::Abs(fDimension)==2; 668 const Bool_t profy = str.Contains("profy") && TMath::Abs(fDimension)==2; 636 669 637 670 str.ReplaceAll("only", ""); … … 641 674 str.ReplaceAll(" ", ""); 642 675 643 if (same && fDimension==1)676 if (same && TMath::Abs(fDimension)==1) 644 677 { 645 678 fHist->SetLineColor(kBlue); … … 702 735 out << " MH3 " << name << "(\""; 703 736 out << fData[0]->GetRule() << "\""; 704 if (fDimension>1 )737 if (fDimension>1 || fDimension<0) 705 738 out << ", \"" << fData[1]->GetRule() << "\""; 706 if (fDimension>2 )739 if (fDimension>2 || fDimension<-1) 707 740 out << ", \"" << fData[2]->GetRule() << "\""; 708 741 … … 717 750 switch (fDimension) 718 751 { 752 case -2: 719 753 case 3: 720 754 if (fScale[2]!=1) 721 755 out << " " << name << ".SetScaleZ(" << fScale[2] << ");" << endl; 756 case -1: 722 757 case 2: 723 758 if (fScale[1]!=1) … … 749 784 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule()); 750 785 break; 786 case -1: 787 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), MH3::kProfile); 788 break; 751 789 case 3: 752 790 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule()); 753 791 break; 792 case -2: 793 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule(), MH3::kProfile); 794 break; 754 795 } 755 796 switch (fDimension) 756 797 { 798 case -2: 757 799 case 3: 758 800 h->SetScaleZ(fScale[2]); 759 801 case 2: 802 case -1: 760 803 h->SetScaleY(fScale[1]); 761 804 case 1: … … 789 832 Int_t num = 1; 790 833 791 switch ( fDimension)834 switch (TMath::Abs(fDimension)) 792 835 { 793 836 case 3: … … 820 863 { 821 864 case 3: 865 case -2: 822 866 binz = axez.FindFixBin(z); 823 867 if (binz>axez.GetLast() || binz<axez.GetFirst()) 824 868 return -1; 825 869 case 2: 870 case -1: 826 871 biny = axey.FindFixBin(y); 827 872 if (biny>axey.GetLast() || biny<axey.GetFirst()) -
trunk/MagicSoft/Mars/mhbase/MH3.h
r8709 r8888 28 28 Byte_t fStyleBits; // Set the range of a histogram automatically in Finalize 29 29 30 // TH1 *fHistDraw; //! 31 30 32 void HandleLogAxis(TAxis &axe) const; 31 33 … … 39 41 40 42 public: 41 MH3(const unsigned int dim=0); 43 enum Type_t { 44 kHistogram, 45 kProfile 46 }; 47 48 MH3(const Int_t dim=0, Type_t type=MH3::kHistogram); 42 49 MH3(const TH1 &h1); 43 50 MH3(const char *memberx); 44 MH3(const char *memberx, const char *membery );45 MH3(const char *memberx, const char *membery, const char *memberz );51 MH3(const char *memberx, const char *membery, Type_t type=MH3::kHistogram); 52 MH3(const char *memberx, const char *membery, const char *memberz, Type_t type=MH3::kHistogram); 46 53 ~MH3(); 47 54 … … 70 77 71 78 // Getter 72 Int_t GetDimension() const { return fDimension; }79 Int_t GetDimension() const { return TMath::Abs(fDimension); } 73 80 Int_t GetNbins() const; 74 81 Int_t FindFixBin(Double_t x, Double_t y=0, Double_t z=0) const; -
trunk/MagicSoft/Mars/mhbase/MHn.cc
r8719 r8888 213 213 // e.g. AddHist("MHillas.fLength", "MHillas.fSize") 214 214 // 215 Bool_t MHn::AddHist(const char *memberx, const char *membery )215 Bool_t MHn::AddHist(const char *memberx, const char *membery, MH3::Type_t type) 216 216 { 217 217 if (fNum==8) … … 221 221 } 222 222 223 fHist[fNum] = new MH3(memberx, membery );223 fHist[fNum] = new MH3(memberx, membery, type); 224 224 225 225 InitHist(); … … 236 236 // e.g. AddHist("MHillas.fWidth", "MHillas.fLength", "MHillas.fSize") 237 237 // 238 Bool_t MHn::AddHist(const char *memberx, const char *membery, const char *memberz )238 Bool_t MHn::AddHist(const char *memberx, const char *membery, const char *memberz, MH3::Type_t type) 239 239 { 240 240 if (fNum==8) … … 244 244 } 245 245 246 fHist[fNum] = new MH3(memberx, membery, memberz );246 fHist[fNum] = new MH3(memberx, membery, memberz, type); 247 247 248 248 InitHist(); -
trunk/MagicSoft/Mars/mhbase/MHn.h
r8700 r8888 2 2 #define MARS_MHn 3 3 4 #ifndef ROOT_TH15 #include <TH1.h>4 #ifndef MARS_MH3 5 #include "MH3.h" 6 6 #endif 7 #ifndef MARS_MH8 #include "MH.h"9 #endif10 11 class MH3;12 7 13 8 class MHn : public MH … … 39 34 40 35 Bool_t AddHist(const char *memberx); 41 Bool_t AddHist(const char *memberx, const char *membery );42 Bool_t AddHist(const char *memberx, const char *membery, const char *memberz );36 Bool_t AddHist(const char *memberx, const char *membery, MH3::Type_t type=MH3::kHistogram); 37 Bool_t AddHist(const char *memberx, const char *membery, const char *memberz, MH3::Type_t type=MH3::kHistogram); 43 38 44 39 void InitName(const char *n)
Note:
See TracChangeset
for help on using the changeset viewer.