Changeset 9821
- Timestamp:
- 08/10/10 12:27:00 (14 years ago)
- Location:
- trunk/Mars
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/Changelog
r9820 r9821 25 25 from float to int) 26 26 27 * mhbase/MHn.[h,cc]: 28 - added SetConversion to allow for setting a conversion function 29 30 * mhbase/MH3.[h,cc]: 31 - added conversion function for displaying the histogram 32 - added new data member fConversion 33 - added new member functions Convert and SetConversion 34 - implemented conversion before displaying 35 27 36 28 37 -
trunk/Mars/mhbase/MH3.cc
r9576 r9821 18 18 ! Author(s): Thomas Bretz 2002 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-20 0820 ! Copyright: MAGIC Software Development, 2000-2010 21 21 ! 22 22 ! … … 143 143 // + MBinning fBins[3] 144 144 // 145 // Class Version 5: 146 // ---------------- 147 // + TFormula *fConversion 148 // 145 149 ///////////////////////////////////////////////////////////////////////////// 146 150 #include "MH3.h" … … 151 155 152 156 #include <TMath.h> 157 #include <TFormula.h> 153 158 154 159 #include <THashList.h> … … 200 205 fScale[2] = 1; 201 206 207 fConversion = NULL; 208 202 209 fName = gsDefName; 203 210 fTitle = gsDefTitle; … … 239 246 fHist = new TProfile; 240 247 fHist->SetYTitle("Average"); 248 static_cast<TProfile*>(fHist)->SetErrorOption("s"); 241 249 break; 242 250 case 2: … … 247 255 fHist = new TProfile2D; 248 256 fHist->SetZTitle("Average"); 257 static_cast<TProfile2D*>(fHist)->SetErrorOption("s"); 249 258 break; 250 259 case 3: … … 331 340 case -1: 332 341 fHist = static_cast<TH1*>(new TProfile); 342 static_cast<TProfile*>(fHist)->SetErrorOption("s"); 343 333 344 break; 334 345 } … … 352 363 : fDimension(type==kHistogram?3:-2) 353 364 { 354 fHist = type&kProfile ? static_cast<TH1*>(new TProfile2D) : static_cast<TH1*>(new TH3D); 365 if (type&kProfile) 366 { 367 fHist = static_cast<TH1*>(new TProfile2D); 368 static_cast<TProfile2D*>(fHist)->SetErrorOption("s"); 369 } 370 else 371 fHist = static_cast<TH1*>(new TH3D); 372 355 373 356 374 fData[0] = new MDataPhrase(memberx); … … 370 388 delete fHist; 371 389 390 if (fConversion) 391 delete fConversion; 392 372 393 for (int i=0; i<4; i++) 373 394 if (fData[i]) … … 390 411 delete fData[3]; 391 412 fData[3] = new MDataPhrase(phrase); 413 } 414 415 // -------------------------------------------------------------------------- 416 // 417 // Set a function which is applied to the histogram before it is displayed. 418 // Note, that it only effects the displayed histogram. 419 // 420 // e.g. SetConversion("sqrt(x)"); 421 // 422 Bool_t MH3::SetConversion(const char *func) 423 { 424 if (TString(func).IsNull()) 425 { 426 delete fConversion; 427 fConversion = 0; 428 return kTRUE; 429 } 430 431 fConversion = new TFormula; 432 433 // Must have a name otherwise all axis labels disappear like a miracle 434 fConversion->SetName("ConversionFunction"); 435 if (fConversion->Compile(func)) 436 { 437 *fLog << err << dbginf << "Syntax Error: TFormula::Compile failed for " << func << endl; 438 delete fConversion; 439 fConversion = 0; 440 return kFALSE; 441 } 442 443 gROOT->GetListOfFunctions()->Remove(fConversion); 444 445 return kTRUE; 392 446 } 393 447 … … 845 899 // -------------------------------------------------------------------------- 846 900 // 901 // Apply the conversion function to the contents stored in fHist and 902 // store the result in h. 903 // 904 void MH3::Convert(TH1 &h) const 905 { 906 for (Int_t z=0; z<=h.GetNbinsZ()+1; z++) 907 for (Int_t y=0; y<=h.GetNbinsY()+1; y++) 908 for (Int_t x=0; x<=h.GetNbinsX()+1; x++) 909 { 910 h.SetBinContent(x, y, z, fConversion->Eval(fHist->GetBinContent(x, y, z))); 911 h.SetBinError( x, y, z, fConversion->Eval(fHist->GetBinError( x, y, z))); 912 } 913 914 if (h.InheritsFrom(TProfile::Class())) 915 for (Int_t x=0; x<=h.GetNbinsX()+1; x++) 916 static_cast<TProfile&>(h).SetBinEntries(x, 1); 917 918 if (h.InheritsFrom(TProfile2D::Class())) 919 for (Int_t x=0; x<=h.GetNbinsX()+1; x++) 920 static_cast<TProfile2D&>(h).SetBinEntries(x, 1); 921 } 922 923 // -------------------------------------------------------------------------- 924 // 847 925 // FIXME 848 926 // … … 853 931 if (TMath::Abs(fDimension)==2) 854 932 MH::SetPalette("pretty"); 933 934 if (fConversion) 935 { 936 TH1 *h = 0; 937 if ((h=dynamic_cast<TH1*>(gPad->FindObject(fHist->GetName())))) 938 Convert(*h); 939 } 855 940 856 941 const TString pfx(MString::Format("%sProfX", fHist->GetName())); … … 963 1048 } 964 1049 1050 1051 TH1 *h = fHist; 1052 1053 if (fConversion) 1054 { 1055 h = static_cast<TH1*>(fHist->Clone()); 1056 h->SetDirectory(0); 1057 h->SetBit(kCanDelete); 1058 1059 Convert(*h); 1060 } 1061 965 1062 // FIXME: We may have to remove all our own options from str! 966 1063 if (!only) 967 fHist->Draw(str);1064 h->Draw(str); 968 1065 969 1066 AppendPad(); … … 972 1069 if (profx) 973 1070 { 974 const TString pfx(MString::Format("%sProfX", fHist->GetName()));1071 const TString pfx(MString::Format("%sProfX", h->GetName())); 975 1072 976 1073 if (same && (p=dynamic_cast<TProfile*>(gPad->FindObject(pfx)))) 977 1074 *fLog << warn << "TProfile " << pfx << " already in pad." << endl; 978 1075 979 p = ((TH2*) fHist)->ProfileX(pfx, -1, -1, "s");1076 p = ((TH2*)h)->ProfileX(pfx, -1, -1, "s"); 980 1077 p->UseCurrentStyle(); 981 p->SetLineColor(blue ? kBlue : fHist->GetLineColor());1078 p->SetLineColor(blue ? kBlue : h->GetLineColor()); 982 1079 p->SetBit(kCanDelete); 983 1080 p->SetDirectory(NULL); 984 p->SetXTitle( fHist->GetXaxis()->GetTitle());985 p->SetYTitle( fHist->GetYaxis()->GetTitle());1081 p->SetXTitle(h->GetXaxis()->GetTitle()); 1082 p->SetYTitle(h->GetYaxis()->GetTitle()); 986 1083 p->Draw(only&&!same?"":"same"); 987 1084 } 988 1085 if (profy) 989 1086 { 990 const TString pfy(MString::Format("%sProfY", fHist->GetName()));1087 const TString pfy(MString::Format("%sProfY", h->GetName())); 991 1088 992 1089 if (same && (p=dynamic_cast<TProfile*>(gPad->FindObject(pfy)))) 993 1090 *fLog << warn << "TProfile " << pfy << " already in pad." << endl; 994 1091 995 p = ((TH2*) fHist)->ProfileY(pfy, -1, -1, "s");1092 p = ((TH2*)h)->ProfileY(pfy, -1, -1, "s"); 996 1093 p->UseCurrentStyle(); 997 p->SetLineColor(blue ? kBlue : fHist->GetLineColor());1094 p->SetLineColor(blue ? kBlue : h->GetLineColor()); 998 1095 p->SetBit(kCanDelete); 999 1096 p->SetDirectory(NULL); 1000 p->SetYTitle( fHist->GetXaxis()->GetTitle());1001 p->SetXTitle( fHist->GetYaxis()->GetTitle());1097 p->SetYTitle(h->GetXaxis()->GetTitle()); 1098 p->SetXTitle(h->GetYaxis()->GetTitle()); 1002 1099 p->Draw(only&&!same?"":"same"); 1003 1100 } -
trunk/Mars/mhbase/MH3.h
r9302 r9821 15 15 class MData; 16 16 class MBinning; 17 class TFormula; 17 18 18 19 class MH3 : public MH … … 55 56 Byte_t fStyleBits; // Set the range of a histogram automatically in Finalize 56 57 57 // TH1 *fHistDraw; //! 58 TFormula *fConversion; // Conversion function for displaying the histogram 58 59 59 60 void HandleLogAxis(TAxis &axe) const; 61 void Convert(TH1 &h) const; 60 62 61 63 void StreamPrimitive(ostream &out) const; 64 62 65 63 66 enum { … … 122 125 void SetWeight(const char *phrase); 123 126 127 Bool_t SetConversion(const char *func=""); 128 124 129 // Getter 125 130 Int_t GetDimension() const { return TMath::Abs(fDimension); } … … 160 165 void RecursiveRemove(TObject *obj); 161 166 162 ClassDef(MH3, 4) // Generalized 1/2/3D-histogram for Mars variables167 ClassDef(MH3, 5) // Generalized 1/2/3D-histogram for Mars variables 163 168 }; 164 169 -
trunk/Mars/mhbase/MHn.cc
r9576 r9821 18 18 ! Author(s): Thomas Bretz 2002 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-20 0720 ! Copyright: MAGIC Software Development, 2000-2010 21 21 ! 22 22 ! … … 485 485 // -------------------------------------------------------------------------- 486 486 // 487 // call MH3::SetConversion for the current histogram 488 // 489 void MHn::SetConversion(const char *func) 490 { 491 if (fHist[fNum-1]) 492 fHist[fNum-1]->SetConversion(func); 493 } 494 495 // -------------------------------------------------------------------------- 496 // 487 497 // Call SetupFill for all initialized histograms 488 498 // -
trunk/Mars/mhbase/MHn.h
r9518 r9821 65 65 void SetWeight(const char *phrase); 66 66 67 // Set a conversion function for displaying the histogram 68 void SetConversion(const char *func=""); 69 67 70 // MH 68 71 Bool_t SetupFill(const MParList *pList);
Note:
See TracChangeset
for help on using the changeset viewer.