Changeset 9829
- Timestamp:
- 08/11/10 11:56:20 (14 years ago)
- Location:
- trunk/Mars
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/Changelog
r9826 r9829 19 19 -*-*- END OF LINE -*-*- 20 20 21 2010/08/11 Thomas Bretz 22 23 * mhbase/MH3.[h,cc]: 24 - added another type to be able to setup a standard profile and 25 one which display the spread as error 26 - improved/fixed error calculation/display 27 28 29 21 30 2010/08/10 Thomas Bretz 22 31 -
trunk/Mars/mhbase/MH3.cc
r9821 r9829 231 231 break; 232 232 case kProfile: 233 case kProfileSpread: 233 234 fDimension = -TMath::Abs(fDimension); 234 235 if (fDimension<-2) … … 246 247 fHist = new TProfile; 247 248 fHist->SetYTitle("Average"); 248 static_cast<TProfile*>(fHist)->SetErrorOption("s"); 249 if (type==kProfileSpread) 250 static_cast<TProfile*>(fHist)->SetErrorOption("s"); 249 251 break; 250 252 case 2: … … 255 257 fHist = new TProfile2D; 256 258 fHist->SetZTitle("Average"); 257 static_cast<TProfile2D*>(fHist)->SetErrorOption("s"); 259 if (type==kProfileSpread) 260 static_cast<TProfile2D*>(fHist)->SetErrorOption("s"); 258 261 break; 259 262 case 3: … … 330 333 // 331 334 MH3::MH3(const char *memberx, const char *membery, Type_t type) 332 : fDimension(type &kProfile?-1:2)335 : fDimension(type==kHistogram?2:-1) 333 336 { 334 337 … … 340 343 case -1: 341 344 fHist = static_cast<TH1*>(new TProfile); 342 static_cast<TProfile*>(fHist)->SetErrorOption("s"); 345 if (type==kProfileSpread) 346 static_cast<TProfile*>(fHist)->SetErrorOption("s"); 343 347 344 348 break; … … 363 367 : fDimension(type==kHistogram?3:-2) 364 368 { 365 if (type&kProfile) 366 { 369 switch (fDimension) 370 { 371 case 3: 372 fHist = static_cast<TH1*>(new TH3D); 373 break; 374 case -2: 367 375 fHist = static_cast<TH1*>(new TProfile2D); 368 static_cast<TProfile2D*>(fHist)->SetErrorOption("s"); 369 } 370 else 371 fHist = static_cast<TH1*>(new TH3D); 372 376 if (type==kProfileSpread) 377 static_cast<TProfile2D*>(fHist)->SetErrorOption("s"); 378 } 373 379 374 380 fData[0] = new MDataPhrase(memberx); … … 902 908 // store the result in h. 903 909 // 910 // In the case of a TProfile we keep it a TProfile to keep the mean and 911 // rms in y displayed. To get the error correctly we have to reverse 912 // the calculation done in TProfile::GetBinError of course. 913 // 904 914 void MH3::Convert(TH1 &h) const 905 915 { 916 const Bool_t prof = h.InheritsFrom(TProfile::Class()) || h.InheritsFrom(TProfile2D::Class()); 917 906 918 for (Int_t z=0; z<=h.GetNbinsZ()+1; z++) 907 919 for (Int_t y=0; y<=h.GetNbinsY()+1; y++) … … 909 921 { 910 922 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))); 923 924 if (prof) 925 h.SetBinError(x, y, z, TMath::Hypot(fConversion->Eval(fHist->GetBinContent(x, y, z)), 926 fConversion->Eval(fHist->GetBinError( x, y, z)))); 927 else 928 h.SetBinError(x, y, z, fConversion->Eval(fHist->GetBinError(x, y, z))); 912 929 } 913 930 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); 931 TProfile *p1 = dynamic_cast<TProfile*>(fHist); 932 if (p1) 933 for (Int_t i=0; i<p1->GetSize(); i++) 934 static_cast<TProfile&>(h).SetBinEntries(i, p1->GetBinEntries(i)>0 ? 1 : 0); 935 936 TProfile *p2 = dynamic_cast<TProfile*>(fHist); 937 if (p2) 938 for (Int_t i=0; i<p2->GetSize(); i++) 939 static_cast<TProfile2D&>(h).SetBinEntries(i, p2->GetBinEntries(i)>0 ? 1 : 0); 921 940 } 922 941 … … 1054 1073 { 1055 1074 h = static_cast<TH1*>(fHist->Clone()); 1075 1056 1076 h->SetDirectory(0); 1057 1077 h->SetBit(kCanDelete); … … 1147 1167 } 1148 1168 1169 MH3::Type_t MH3::GetType() const 1170 { 1171 switch (fDimension) 1172 { 1173 case -1: 1174 return TString(static_cast<TProfile*>(fHist)->GetErrorOption())=="s" ? kProfileSpread : kProfile; 1175 case -2: 1176 return TString(static_cast<TProfile2D*>(fHist)->GetErrorOption())=="s" ? kProfileSpread : kProfile; 1177 } 1178 return kHistogram; 1179 } 1180 1149 1181 // -------------------------------------------------------------------------- 1150 1182 // … … 1167 1199 break; 1168 1200 case 2: 1169 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule());1170 break;1171 1201 case -1: 1172 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), MH3::kProfile);1202 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), GetType()); 1173 1203 break; 1174 1204 case 3: 1175 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule());1176 break;1177 1205 case -2: 1178 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule(), MH3::kProfile);1206 h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule(), GetType()); 1179 1207 break; 1180 1208 } -
trunk/Mars/mhbase/MH3.h
r9821 r9829 31 31 }; 32 32 33 enum Type_t { 34 kHistogram = 0, 35 kProfile = 1, 36 kProfileSpread = kProfile | 2, 37 }; 38 33 39 private: 34 40 static const TString gsDefName; … … 44 50 Labels_t GetLabels() const; 45 51 const char *GetLabel(Int_t axe, Double_t val) const; 52 53 // Get type 54 Type_t GetType() const; 55 56 // Helper for conversion 57 void Convert(TH1 &h) const; 46 58 47 59 MObjLookup fLabels[3]; //! Lookup table to conflate and name labels … … 59 71 60 72 void HandleLogAxis(TAxis &axe) const; 61 void Convert(TH1 &h) const;62 73 63 74 void StreamPrimitive(ostream &out) const; … … 71 82 72 83 public: 73 enum Type_t {74 kHistogram,75 kProfile,76 };77 78 84 MH3(const Int_t dim=0, Type_t type=MH3::kHistogram); 79 85 MH3(const TH1 &h1);
Note:
See TracChangeset
for help on using the changeset viewer.