Changeset 8892 for trunk/MagicSoft/Mars/mhbase
- Timestamp:
- 05/19/08 15:04:36 (17 years ago)
- Location:
- trunk/MagicSoft/Mars/mhbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhbase/MH.cc
r8709 r8892 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.3 6 2007-08-25 15:30:24tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.37 2008-05-19 14:04:12 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 212 212 // -------------------------------------------------------------------------- 213 213 // 214 // Applies a given binning to a 1D-histogram 214 // If labels are set for this axis the correct MBinning corresponding 215 // to the existing label range is returned (this is necessary to 216 // maintain the correct number of bins in the histogram) 217 // otherwise the given binning is returned. 218 // 219 MBinning MH::GetBinningForLabels(TAxis &x, const MBinning *bins) 220 { 221 if (!x.GetLabels()) 222 return *bins; 223 224 const Int_t n = TMath::Max(x.GetLabels()->GetEntries(), 1); 225 return MBinning(n, 0, n); 226 } 227 228 // -------------------------------------------------------------------------- 229 // 230 // If Labels are set this function deletes the fXbins Array from 231 // the axis (which makes the axis a variable bin-size axis) 232 // and sets the Nbins, Xmin and Xmax according to the number of labels. 233 // 234 void MH::RestoreBinningForLabels(TAxis &x) 235 { 236 if (!x.GetLabels()) 237 return; 238 239 const Int_t n = TMath::Max(x.GetLabels()->GetEntries(), 1); 240 x.Set(n, 0, n); 241 242 const_cast<TArrayD*>(x.GetXbins())->Set(0); 243 } 244 245 // -------------------------------------------------------------------------- 246 // 247 // Applies a given binning to a 1D-histogram. In case the axis has labels 248 // (e.g. GetXaxis()->GetLabels()) the binning is set according to the 249 // labels. 215 250 // 216 251 void MH::SetBinning(TH1 *h, const MBinning *binsx) … … 225 260 #endif 226 261 262 #if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00) 227 263 // All this is reset by TAxis::Set 228 264 const TAttAxis att(x); … … 247 283 x.SetTimeDisplay(tm); 248 284 x.SetTimeFormat(tf); 285 #else 286 if (!x.GetLabels()) 287 h->SetBins(binsx->GetNumBins(), binsx->GetEdges()); 288 #endif 289 249 290 250 291 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03) … … 255 296 // -------------------------------------------------------------------------- 256 297 // 257 // Applies given binnings to the two axis of a 2D-histogram 298 // Applies given binnings to the two axis of a 2D-histogram. 299 // In case the axis has labels (e.g. GetXaxis()->GetLabels()) 300 // the binning is set according to the labels. 258 301 // 259 302 void MH::SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy) … … 261 304 TAxis &x = *h->GetXaxis(); 262 305 TAxis &y = *h->GetYaxis(); 306 307 const MBinning bx(GetBinningForLabels(x, binsx)); 308 const MBinning by(GetBinningForLabels(y, binsy)); 263 309 264 310 // … … 270 316 #endif 271 317 318 #if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00) 272 319 // All this is reset by TAxis::Set 273 320 const TAttAxis attx(x); … … 283 330 // TH1D::fNcells must be set correctly. 284 331 // 285 h->SetBins(b insx->GetNumBins(), 0, 1,286 b insy->GetNumBins(), 0, 1);332 h->SetBins(bx.GetNumBins(), 0, 1, 333 by.GetNumBins(), 0, 1); 287 334 288 335 // … … 290 337 // in one of the two given histograms 291 338 // 292 x.Set(b insx->GetNumBins(), binsx->GetEdges());293 y.Set(b insy->GetNumBins(), binsy->GetEdges());339 x.Set(bx.GetNumBins(), bx.GetEdges()); 340 y.Set(by.GetNumBins(), by.GetEdges()); 294 341 295 342 // All this is reset by TAxis::Set … … 300 347 x.SetTimeFormat(tfx); 301 348 y.SetTimeFormat(tfy); 349 #else 350 h->SetBins(bx.GetNumBins(), bx.GetEdges(), 351 by.GetNumBins(), by.GetEdges()); 352 #endif 353 354 RestoreBinningForLabels(x); 355 RestoreBinningForLabels(y); 302 356 303 357 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03) … … 310 364 // 311 365 // Applies given binnings to the three axis of a 3D-histogram 366 // In case the axis has labels (e.g. GetXaxis()->GetLabels()) 367 // the binning is set according to the labels. 312 368 // 313 369 void MH::SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz) … … 319 375 TAxis &y = *h->GetYaxis(); 320 376 TAxis &z = *h->GetZaxis(); 377 378 const MBinning bx(GetBinningForLabels(x, binsx)); 379 const MBinning by(GetBinningForLabels(y, binsy)); 380 const MBinning bz(GetBinningForLabels(z, binsz)); 321 381 322 382 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03) … … 326 386 #endif 327 387 388 #if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00) 328 389 // All this is reset by TAxis::Set 329 390 const TAttAxis attx(x); … … 336 397 const TString tfy(y.GetTimeFormat()); 337 398 const TString tfz(z.GetTimeFormat()); 399 #endif 338 400 339 401 // … … 342 404 // TH1D::fNcells must be set correctly. 343 405 // 344 h->SetBins(b insx->GetNumBins(), 0, 1,345 b insy->GetNumBins(), 0, 1,346 b insz->GetNumBins(), 0, 1);406 h->SetBins(bx.GetNumBins(), 0, 1, 407 by.GetNumBins(), 0, 1, 408 bz.GetNumBins(), 0, 1); 347 409 348 410 // … … 350 412 // in one of the two given histograms 351 413 // 352 x.Set(binsx->GetNumBins(), binsx->GetEdges()); 353 y.Set(binsy->GetNumBins(), binsy->GetEdges()); 354 z.Set(binsz->GetNumBins(), binsz->GetEdges()); 355 414 x.Set(bx.GetNumBins(), bx.GetEdges()); 415 y.Set(by.GetNumBins(), by.GetEdges()); 416 z.Set(bz.GetNumBins(), bz.GetEdges()); 417 418 RestoreBinningForLabels(x); 419 RestoreBinningForLabels(y); 420 RestoreBinningForLabels(z); 421 422 #if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00) 356 423 // All this is reset by TAxis::Set 357 424 attx.Copy(x); … … 364 431 y.SetTimeFormat(tfy); 365 432 z.SetTimeFormat(tfz); 433 #endif 366 434 367 435 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03) -
trunk/MagicSoft/Mars/mhbase/MH.h
r8696 r8892 26 26 Byte_t fSerialNumber; // Serial number (eg of telecope) 27 27 UInt_t fNumExecutions; // Number of calls to Fill function 28 29 static MBinning GetBinningForLabels(TAxis &x, const MBinning *bins); 30 static void RestoreBinningForLabels(TAxis &x); 28 31 29 32 public:
Note:
See TracChangeset
for help on using the changeset viewer.