Changeset 8893 for trunk/MagicSoft/Mars
- Timestamp:
- 05/19/08 15:44:32 (16 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r8892 r8893 27 27 - added MObjLookup 28 28 29 * mbase/M objLookup.[h,cc]:29 * mbase/MObjLookup.[h,cc]: 30 30 - added 31 31 … … 43 43 - improved SetBinning to correctly support axis with labels 44 44 (keeps the binning unchanged) 45 46 * mhbas/MH3.[h,cc], mhbase/MHn.[h,cc]: 47 - support for axis labels was added. 48 - a possibility to set an additional weight has been added 49 - the version number has been increased accordingly 45 50 46 51 * mjobs/MJPedestal.cc: -
trunk/MagicSoft/Mars/mhbase/MH3.cc
r8888 r8893 18 18 ! Author(s): Thomas Bretz 2002 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 720 ! Copyright: MAGIC Software Development, 2000-2008 21 21 ! 22 22 ! … … 45 45 // 46 46 // 47 // Binning name48 // ============ 47 // Binning/Binning name 48 // ===================== 49 49 // 50 50 // The axis binning is retrieved from the parameter list, too. Create a … … 57 57 // Instead of BinningMyHistName[XYZ] the parameter list will be searched 58 58 // for BinningMyXBinning, BinningMyYBins and BinningMyHistNameZ 59 // 60 // If you don't want to use a MBinning object from the parameter list 61 // you can also set one directly, for example 62 // MBinning bins(10, 0, 1); 63 // mh3.SetBinningX(&bins); 64 // You must not delete the MBinning object before the class has been 65 // PreProcessed. 59 66 // 60 67 // … … 71 78 // 72 79 // 73 // For example: 74 // MH3 myhist("MHillas.fLength"); 75 // myhist.SetName("MyHist"); 76 // myhist.SetScaleX(geomcam.GetConvMm2Deg()); //convert length to degree 77 // MBinning bins("BinningMyHistX"); 78 // bins.SetEdges(10, 0, 150); 79 // plist.AddToList(&myhist); 80 // plist.AddToList(&bins); 81 // 80 // Labels 81 // ====== 82 // 83 // To use labels at an axis you have to initialize this for the axis 84 // by either calling InitLabels(Labels_t) or setiting a DefaultLabel. 85 // For the axis for which the labels have been initialized the 86 // number returned by the given corresponding phrase is converted 87 // to int with TMath::Nint and used as a label. If you want to replace 88 // this id by a named label you can call DefineLabel to do that. 89 // Several ids can be replaced by the same label. If you define 90 // named labels for every label which was not defined the default 91 // is used, if any, otherwise an unnamed label is created. 92 // 93 // In the case of an axis with labels the axis-title cannot be 94 // set via a MBinning, because the MBinning is not evaluated. 95 // 96 // Please note that for some reason not all combinations of 97 // labels, dimensions and weights are available in the root- 98 // histogram classes. Please check the MH3::Fill function to see 99 // whether your combination is supported. 100 // 101 // 102 // Examples: 103 // ========= 104 // 105 // 1) MH3 myhist("MHillas.fLength"); 106 // myhist.SetName("MyHist"); 107 // myhist.SetScaleX(geomcam.GetConvMm2Deg()); //convert length to degree 108 // MBinning bins("BinningMyHistX", "Title for my x-axis [Hz]"); 109 // bins.SetEdges(10, 0, 150); 110 // plist.AddToList(&bins); 111 // 112 // 2) MH3 myhist("MHillas.fLength"); 113 // myhist.SetName("MyHist;MyX"); 114 // myhist.SetTitle("Histogram Title;X-Title [mm];Counts"); 115 // MBinning bins("BinningMyX"); 116 // bins.SetEdges(10, 0, 150); 117 // plist.AddToList(&bins); 118 // 119 // 3) MH3 myhist("MTriggerPatter.GetUnprescaled"); 120 // myhist.SetWeight("1./MRawRunHeader.GetRunLength"); 121 // myhist.SetTitle("Rate of the trigger pattern [Hz];Run Number;Trigger Pattern;Rate [Hz]"); 122 // myhist.InitLabels(MH3::kLabelsXY); 123 // myhist.DefaultLabelY("UNKNOWN"); // Lvl1 124 // myhist.DefineLabelY( 1, "Trig"); // Lvl1 125 // myhist.DefineLabelY( 2, "Cal"); // Cal 126 // myhist.DefineLabelY( 4, "Trig"); // Lvl2 127 // myhist.DefineLabelY( 8, "Ped"); // Ped 128 // 129 // 130 // Class Version 3: 131 // ---------------- 132 // - MData *fData[3]; 133 // + MData *fData[4]; 82 134 // 83 135 // Class Version 2: … … 97 149 #include <fstream> 98 150 151 #include <TObjString.h> 152 99 153 //#include <TPad.h> 100 154 #include <TStyle.h> … … 122 176 // -------------------------------------------------------------------------- 123 177 // 178 // Set fStyleBits to 0, Reset fBins to NULL, fScale to 1, set name and title 179 // to gsDefName and gsDefTitle and if fHist!=NULL UseCurrentStyle and 180 // SetDirectory(0) 181 // 182 void MH3::Init() 183 { 184 fStyleBits = 0; 185 186 fData[3] = NULL; 187 188 fBins[0] = NULL; 189 fBins[1] = NULL; 190 fBins[2] = NULL; 191 192 fScale[0] = 1; 193 fScale[1] = 1; 194 fScale[2] = 1; 195 196 fName = gsDefName; 197 fTitle = gsDefTitle; 198 199 if (!fHist) 200 return; 201 202 fHist->UseCurrentStyle(); 203 fHist->SetDirectory(NULL); 204 } 205 206 // -------------------------------------------------------------------------- 207 // 124 208 // Default constructor. 125 209 // 126 MH3::MH3(const Int_t dim, Type_t type) 127 : fDimension(dim), fHist(NULL), fStyleBits(0) 128 { 210 MH3::MH3(const Int_t dim, Type_t type) : fDimension(dim), fHist(NULL) 211 { 212 // FIXME? 129 213 switch (type) 130 214 { … … 167 251 fData[2] = NULL; 168 252 169 fBins[0] = NULL; 170 fBins[1] = NULL; 171 fBins[2] = NULL; 172 173 fName = gsDefName; 174 fTitle = gsDefTitle; 175 176 if (fHist) 177 { 178 fHist->SetDirectory(NULL); 179 fHist->UseCurrentStyle(); 180 } 181 182 fScale[0] = 1; 183 fScale[1] = 1; 184 fScale[2] = 1; 253 Init(); 185 254 } 186 255 … … 190 259 // description see the class description above. 191 260 // 192 MH3::MH3(const char *memberx) 193 : fDimension(1), fStyleBits(0) 261 MH3::MH3(const char *memberx, Type_t type) : fDimension(1) 194 262 { 195 263 fHist = new TH1D; 264 fHist->SetYTitle("Counts"); 196 265 197 266 fData[0] = new MDataPhrase(memberx); … … 199 268 fData[2] = NULL; 200 269 201 fBins[0] = NULL; 202 fBins[1] = NULL; 203 fBins[2] = NULL; 204 205 fName = gsDefName; 206 fTitle = gsDefTitle; 207 208 fHist->UseCurrentStyle(); 209 fHist->SetDirectory(NULL); 210 fHist->SetYTitle("Counts"); 211 212 fScale[0] = 1; 213 fScale[1] = 1; 214 fScale[2] = 1; 270 Init(); 215 271 } 216 272 … … 219 275 // Adapt a given histogram 220 276 // 221 MH3::MH3(const TH1 &h1) 222 : fDimension(1), fStyleBits(0) 277 MH3::MH3(const TH1 &h1) : fDimension(1) 223 278 { 224 279 if (h1.InheritsFrom(TH3::Class())) … … 227 282 fDimension = 2; 228 283 284 if (h1.InheritsFrom(TProfile2D::Class())) 285 fDimension = -2; 286 if (h1.InheritsFrom(TProfile::Class())) 287 fDimension = -1; 288 289 fHist = (TH1*)h1.Clone(); 290 229 291 fData[0] = NULL; 230 292 fData[1] = NULL; 231 293 fData[2] = NULL; 232 294 233 fBins[0] = NULL;234 fBins[1] = NULL;235 fBins[2] = NULL;236 237 295 switch (fDimension) 238 296 { 239 297 case 3: 298 case -2: 240 299 fData[2] = new MDataPhrase(h1.GetZaxis()->GetTitle()); 241 300 case 2: 301 case -1: 242 302 fData[1] = new MDataPhrase(h1.GetYaxis()->GetTitle()); 243 303 case 1: … … 245 305 } 246 306 247 fName = gsDefName; 248 fTitle = gsDefTitle; 249 250 fHist = (TH1*)h1.Clone(); 251 fHist->SetDirectory(NULL); 252 253 fScale[0] = 1; 254 fScale[1] = 1; 255 fScale[2] = 1; 307 Init(); // Before without SeUseCurrentStyle! 256 308 } 257 309 … … 263 315 // 264 316 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; 317 : fDimension(type&kProfile?-1:2) 318 { 319 320 switch (TMath::Abs(fDimension)) 321 { 322 case 2: 323 fHist = static_cast<TH1*>(new TH2D); 324 break; 325 case -1: 326 fHist = static_cast<TH1*>(new TProfile); 327 break; 328 } 329 330 fHist->SetZTitle(fDimension>0?"Counts":"Average"); 268 331 269 332 fData[0] = new MDataPhrase(memberx); … … 271 334 fData[2] = NULL; 272 335 273 fBins[0] = NULL; 274 fBins[1] = NULL; 275 fBins[2] = NULL; 276 277 fName = gsDefName; 278 fTitle = gsDefTitle; 279 280 fHist->UseCurrentStyle(); 281 fHist->SetDirectory(NULL); 282 fHist->SetZTitle(fDimension>0?"Counts":"Average"); 283 284 fScale[0] = 1; 285 fScale[1] = 1; 286 fScale[2] = 1; 336 Init(); 287 337 } 288 338 … … 294 344 // 295 345 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;346 : fDimension(type==kHistogram?3:-2) 347 { 348 fHist = type&kProfile ? static_cast<TH1*>(new TProfile2D) : static_cast<TH1*>(new TH3D); 299 349 300 350 fData[0] = new MDataPhrase(memberx); … … 302 352 fData[2] = new MDataPhrase(memberz); 303 353 304 fBins[0] = NULL; 305 fBins[1] = NULL; 306 fBins[2] = NULL; 307 308 fName = gsDefName; 309 fTitle = gsDefTitle; 310 311 fHist->UseCurrentStyle(); 312 fHist->SetDirectory(NULL); 313 314 fScale[0] = 1; 315 fScale[1] = 1; 316 fScale[2] = 1; 354 Init(); 317 355 } 318 356 … … 325 363 delete fHist; 326 364 327 for (int i=0; i< 3; i++)365 for (int i=0; i<4; i++) 328 366 if (fData[i]) 329 367 delete fData[i]; 368 369 for (int i=0; i<3; i++) 370 if (fLabels[i].GetDefault()) 371 delete fLabels[i].GetDefault(); 372 } 373 374 // -------------------------------------------------------------------------- 375 // 376 // You can set a weight as a phrase additionally to the one given 377 // as an argument to Fill (most likely from MFillH). The two weights 378 // are multiplied together. 379 // 380 void MH3::SetWeight(const char *phrase) 381 { 382 if (fData[3]) 383 delete fData[3]; 384 fData[3] = new MDataPhrase(phrase); 385 } 386 387 // -------------------------------------------------------------------------- 388 // 389 // The axis label is centered and the labeling of the axis is initialized. 390 // 391 // This function must not be called after any label has been created! 392 // 393 void MH3::InitLabels(TAxis &x) const 394 { 395 x.CenterTitle(); 396 x.SetBinLabel(1, ""); 397 x.LabelsOption("h"); // FIXME: Is "a" thread safe? (Paint and Fill?) 398 x.GetLabels()->Delete(); 399 } 400 401 // -------------------------------------------------------------------------- 402 // 403 // Depending on the bits set the InitLabels(TAxis&) function for 404 // the corresponding axes are called. In any case the kCanRebin bit 405 // is set. 406 // 407 // This function must not be called after any label has been created! 408 // 409 void MH3::InitLabels(Labels_t type) const 410 { 411 if (!fHist) 412 return; 413 414 if (type&kLabelsX && fHist->GetXaxis()) 415 InitLabels(*fHist->GetXaxis()); 416 417 if (type&kLabelsY && fHist->GetYaxis()) 418 InitLabels(*fHist->GetYaxis()); 419 420 if (type&kLabelsZ && fHist->GetZaxis()) 421 InitLabels(*fHist->GetZaxis()); 422 423 if (type&kLabelsXYZ) 424 fHist->SetBit(TH1::kCanRebin); 425 } 426 427 // -------------------------------------------------------------------------- 428 // 429 // Return the corresponding Labels_t describing for which axis 430 // axis-labels are switched on. 431 // 432 MH3::Labels_t MH3::GetLabels() const 433 { 434 UInt_t type = kNoLabels; 435 if (fHist->GetXaxis() && fHist->GetXaxis()->GetLabels()) 436 type |= kLabelsX; 437 if (fHist->GetYaxis() && fHist->GetYaxis()->GetLabels()) 438 type |= kLabelsY; 439 if (fHist->GetZaxis() && fHist->GetZaxis()->GetLabels()) 440 type |= kLabelsZ; 441 return (Labels_t)type; 442 } 443 444 // -------------------------------------------------------------------------- 445 // 446 // Calls the LabelsDeflate from the histogram for all axes. 447 // LabelsDeflate will just do nothing if the axis has no labels 448 // initialized. 449 // 450 void MH3::DeflateLabels() const 451 { 452 fHist->LabelsDeflate("X"); 453 fHist->LabelsDeflate("Y"); 454 fHist->LabelsDeflate("Z"); 455 } 456 457 // -------------------------------------------------------------------------- 458 // 459 // Returns the named label corresponding to the given value 460 // and the given axis. The names are defined with the 461 // DefineLabel-functions. if no name is defined the value 462 // is converted to a string with %d and TMath::Nint. 463 // If names are defined, but not for the given value, the default 464 // label is returned instead. If no default is defined the 465 // %d-converted string is returned. 466 // 467 const char *MH3::GetLabel(Int_t axe, Double_t val) const 468 { 469 const Int_t v = TMath::Nint(val); 470 471 if (fLabels[axe].GetSize()) 472 { 473 const char *l = fLabels[axe].GetObjName(v); 474 if (l) 475 return l; 476 } 477 478 return Form("%d", v); 330 479 } 331 480 … … 338 487 { 339 488 TString str=fData[0]->GetDataMember(); 340 if (fData[1]) 341 { 342 str += ";"; 343 str += fData[1]->GetDataMember(); 344 } 345 if (fData[2]) 346 { 347 str += ";"; 348 str += fData[2]->GetDataMember(); 349 } 489 490 for (int i=1; i<4; i++) 491 if (fData[i]) 492 { 493 str += ";"; 494 str += fData[i]->GetDataMember(); 495 } 496 350 497 return str; 351 498 } … … 377 524 delete tok; 378 525 379 380 526 MBinning *binsx = NULL; 381 527 MBinning *binsy = NULL; 382 528 MBinning *binsz = NULL; 383 529 530 const Labels_t labels = GetLabels(); 531 384 532 switch (TMath::Abs(fDimension)) 385 533 { 386 534 case 3: 387 binsz = fBins[2] ? fBins[2] : (MBinning*)plist->FindObject(bz, "MBinning");388 if (!binsz)389 {390 *fLog << err << dbginf << "MBinning '" << bz << "' not found... aborting." << endl;391 return kFALSE;392 }393 535 if (fData[2]) 394 536 fHist->SetZTitle(fData[2]->GetTitle()); 395 if (binsz->HasTitle()) 396 fHist->SetZTitle(binsz->GetTitle()); 397 if (binsz->IsLogarithmic()) 398 fHist->SetBit(kIsLogz); 537 if (!labels&kLabelsZ) 538 { 539 binsz = fBins[2] ? fBins[2] : (MBinning*)plist->FindObject(bz, "MBinning"); 540 if (!binsz) 541 { 542 *fLog << err << dbginf << "MBinning '" << bz << "' not found... aborting." << endl; 543 return kFALSE; 544 } 545 if (binsz->HasTitle()) 546 fHist->SetZTitle(binsz->GetTitle()); 547 if (binsz->IsLogarithmic()) 548 fHist->SetBit(kIsLogz); 549 } 399 550 case 2: 400 binsy = fBins[1] ? fBins[1] : (MBinning*)plist->FindObject(by, "MBinning");401 if (!binsy)402 {403 *fLog << err << dbginf << "MBinning '" << by << "' not found... aborting." << endl;404 return kFALSE;405 }406 551 if (fData[1]) 407 552 fHist->SetYTitle(fData[1]->GetTitle()); 408 if (binsy->HasTitle()) 409 fHist->SetYTitle(binsy->GetTitle()); 410 if (binsy->IsLogarithmic()) 411 fHist->SetBit(kIsLogy); 553 if (!labels&kLabelsY) 554 { 555 binsy = fBins[1] ? fBins[1] : (MBinning*)plist->FindObject(by, "MBinning"); 556 if (!binsy) 557 { 558 *fLog << err << dbginf << "MBinning '" << by << "' not found... aborting." << endl; 559 return kFALSE; 560 } 561 if (binsy->HasTitle()) 562 fHist->SetYTitle(binsy->GetTitle()); 563 if (binsy->IsLogarithmic()) 564 fHist->SetBit(kIsLogy); 565 } 412 566 case 1: 413 binsx = fBins[0] ? fBins[0] : (MBinning*)plist->FindObject(bx, "MBinning"); 414 if (!binsx) 567 if (fData[0]!=NULL) 568 fHist->SetXTitle(fData[0]->GetTitle()); 569 if (!labels&kLabelsX) 415 570 { 416 if (fDimension==1) 417 binsx = (MBinning*)plist->FindObject("Binning"+fName, "MBinning"); 418 571 binsx = fBins[0] ? fBins[0] : (MBinning*)plist->FindObject(bx, "MBinning"); 419 572 if (!binsx) 420 573 { 421 *fLog << err << dbginf << "Neither '" << bx << "' nor '" << binsx << fName << "' found... aborting." << endl; 422 return kFALSE; 574 if (fDimension==1) 575 binsx = (MBinning*)plist->FindObject("Binning"+fName, "MBinning"); 576 577 if (!binsx) 578 { 579 *fLog << err << dbginf << "Neither '" << bx << "' nor '" << binsx << fName << "' found... aborting." << endl; 580 return kFALSE; 581 } 423 582 } 583 if (binsx->HasTitle()) 584 fHist->SetXTitle(binsx->GetTitle()); 585 if (binsx->IsLogarithmic()) 586 fHist->SetBit(kIsLogx); 424 587 } 425 if (fData[0]!=NULL)426 fHist->SetXTitle(fData[0]->GetTitle());427 if (binsx->HasTitle())428 fHist->SetXTitle(binsx->GetTitle());429 if (binsx->IsLogarithmic())430 fHist->SetBit(kIsLogx);431 588 } 432 589 433 590 // PreProcess existing fData members 434 for (int i=0; i< 3; i++)591 for (int i=0; i<4; i++) 435 592 if (fData[i] && !fData[i]->PreProcess(plist)) 436 593 return kFALSE; … … 445 602 fHist->SetDirectory(0); 446 603 604 // This is for the case we have set lables 605 const MBinning def(1, 0, 1); 606 if (!binsx) 607 binsx = const_cast<MBinning*>(&def); 608 if (!binsy) 609 binsy = const_cast<MBinning*>(&def); 610 if (!binsz) 611 binsz = const_cast<MBinning*>(&def); 612 613 // set binning 447 614 switch (TMath::Abs(fDimension)) 448 615 { … … 451 618 return kTRUE; 452 619 case 2: 453 SetBinning( (TH2*)fHist, binsx, binsy);620 SetBinning(static_cast<TH2*>(fHist), binsx, binsy); 454 621 return kTRUE; 455 622 case 3: 456 SetBinning( (TH3*)fHist, binsx, binsy, binsz);623 SetBinning(static_cast<TH3*>(fHist), binsx, binsy, binsz); 457 624 return kTRUE; 458 625 } … … 504 671 // Fills the one, two or three data members into our histogram 505 672 // 506 Bool_t MH3::Fill(const MParContainer *par, const Stat_t w) 507 { 673 Bool_t MH3::Fill(const MParContainer *par, const Stat_t ww) 674 { 675 // Get Information about labels (UInt_t, to supress warning about 676 // unhandeled cases in switch) 677 const UInt_t type = GetLabels(); 678 679 // Get values for axis 508 680 Double_t x=0; 509 681 Double_t y=0; 510 682 Double_t z=0; 683 Double_t w=ww; 511 684 512 685 switch (fDimension) … … 522 695 } 523 696 697 if (fData[3]) 698 w *= fData[3]->GetValue(); 699 700 // If label option is set, convert value to label 701 TString labelx, labely, labelz; 702 if (type&kLabelsX) 703 labelx = GetLabel(0, x); 704 if (type&kLabelsY) 705 labely = GetLabel(1, y); 706 if (type&kLabelsZ) 707 labelz = GetLabel(2, z); 708 709 // Fill histogram 524 710 switch (fDimension) 525 711 { 526 712 case 3: 527 static_cast<TH3*>(fHist)->Fill(x, y, z, w); 528 return kTRUE; 713 switch (type) 714 { 715 case kNoLabels: 716 static_cast<TH3*>(fHist)->Fill(x, y, z, w); 717 return kTRUE; 718 case kLabelsX: 719 static_cast<TH3*>(fHist)->Fill(labelx, y, z); 720 return kTRUE; 721 case kLabelsY: 722 static_cast<TH3*>(fHist)->Fill(x, labely, z, w); 723 return kTRUE; 724 case kLabelsZ: 725 static_cast<TH3*>(fHist)->Fill(x, y, labelz, w); 726 return kTRUE; 727 case kLabelsXY: 728 static_cast<TH3*>(fHist)->Fill(labelx, labely, z, w); 729 return kTRUE; 730 case kLabelsXZ: 731 static_cast<TH3*>(fHist)->Fill(labelx, y, labelz, w); 732 return kTRUE; 733 case kLabelsYZ: 734 static_cast<TH3*>(fHist)->Fill(x, labely, labelz, w); 735 return kTRUE; 736 case kLabelsXYZ: 737 static_cast<TH3*>(fHist)->Fill(labelx, labely, labelz, w); 738 return kTRUE; 739 } 740 break; 529 741 case 2: 530 static_cast<TH2*>(fHist)->Fill(x, y, w); 531 return kTRUE; 742 switch (type) 743 { 744 case kNoLabels: 745 static_cast<TH2*>(fHist)->Fill(x, y, w); 746 return kTRUE; 747 case kLabelsX: 748 static_cast<TH2*>(fHist)->Fill(x, labely, w); 749 return kTRUE; 750 case kLabelsY: 751 static_cast<TH2*>(fHist)->Fill(labelx, y, w); 752 return kTRUE; 753 case kLabelsXY: 754 static_cast<TH2*>(fHist)->Fill(labelx, labely, w); 755 return kTRUE; 756 } 757 break; 532 758 case 1: 533 fHist->Fill(x, w); 534 return kTRUE; 759 switch (type) 760 { 761 case kNoLabels: 762 fHist->Fill(x, w); 763 return kTRUE; 764 case kLabelsX: 765 fHist->Fill(labelx, w); 766 return kTRUE; 767 } 768 break; 535 769 case -1: 536 static_cast<TProfile*>(fHist)->Fill(x, y, w); 537 return kTRUE; 770 switch (type) 771 { 772 case kNoLabels: 773 static_cast<TProfile*>(fHist)->Fill(x, y, w); 774 return kTRUE; 775 case kLabelsX: 776 static_cast<TProfile*>(fHist)->Fill(labelx, y, w); 777 return kTRUE; 778 } 779 break; 538 780 case -2: 539 static_cast<TProfile2D*>(fHist)->Fill(x, y, z, w); 540 return kTRUE; 541 } 542 543 return kFALSE; 781 switch (type) 782 { 783 case kNoLabels: 784 static_cast<TProfile2D*>(fHist)->Fill(x, y, z, w); 785 return kTRUE; 786 case kLabelsX: 787 static_cast<TProfile2D*>(fHist)->Fill(labelx, y, z); 788 return kTRUE; 789 case kLabelsY: 790 static_cast<TProfile2D*>(fHist)->Fill(x, labely, z); 791 return kTRUE; 792 case kLabelsXY: 793 static_cast<TProfile2D*>(fHist)->Fill(labelx, labely, z); 794 return kTRUE; 795 } 796 break; 797 } 798 799 *fLog << err << "MH3::Fill: ERROR - A fatal error occured." << endl; 800 return kERROR; 544 801 } 545 802 … … 552 809 Bool_t MH3::Finalize() 553 810 { 811 DeflateLabels(); 812 554 813 Bool_t autorangex=TESTBIT(fStyleBits, 0); 555 814 Bool_t autorangey=TESTBIT(fStyleBits, 1); … … 557 816 558 817 Int_t lo, hi; 559 560 818 if (autorangex) 561 819 { … … 578 836 } 579 837 838 // -------------------------------------------------------------------------- 839 // 840 // FIXME 841 // 580 842 void MH3::Paint(Option_t *o) 581 843 { … … 607 869 } 608 870 871 // -------------------------------------------------------------------------- 872 // 873 // If Xmax is < 3000*Xmin SetMoreLogLabels is called. If Xmax<5000 874 // the exponent is switched off (SetNoExponent) 875 // 609 876 void MH3::HandleLogAxis(TAxis &axe) const 610 877 { … … 661 928 TString str(opt); 662 929 str.ToLower(); 930 931 if (str.IsNull() && GetLabels() && fDimension==2) 932 str = "colz"; 663 933 664 934 const Bool_t only = str.Contains("only") && TMath::Abs(fDimension)==2; … … 747 1017 if (fTitle!=gsDefTitle) 748 1018 out << " " << name << ".SetTitle(\"" << fTitle << "\");" << endl; 1019 1020 if (fData[3]) 1021 out << " " << name << ".SetWeight(\"" << fData[3]->GetRule() << "\");" << endl; 749 1022 750 1023 switch (fDimension) … … 771 1044 MParContainer *MH3::New() const 772 1045 { 1046 // FIXME: TREAT THE NEW OPTIONS CORRECTLY (PROFILE, LABELS) 1047 773 1048 MH3 *h = NULL; 774 1049 … … 794 1069 break; 795 1070 } 1071 796 1072 switch (fDimension) 797 1073 { … … 805 1081 h->SetScaleX(fScale[0]); 806 1082 } 1083 1084 if (fData[3]) 1085 h->SetWeight(fData[3]->GetRule()); 1086 807 1087 return h; 808 1088 } 809 1089 1090 // -------------------------------------------------------------------------- 1091 // 1092 // FIXME 1093 // 810 1094 TString MH3::GetRule(const Char_t axis) const 811 1095 { … … 813 1097 { 814 1098 case 'x': 1099 case 'X': 815 1100 return fData[0] ? fData[0]->GetRule() : TString(""); 816 1101 case 'y': 1102 case 'Y': 817 1103 return fData[1] ? fData[1]->GetRule() : TString(""); 818 1104 case 'z': 1105 case 'Z': 819 1106 return fData[2] ? fData[2]->GetRule() : TString(""); 1107 case 'w': 1108 case 'W': 1109 return fData[3] ? fData[3]->GetRule() : TString(""); 820 1110 default: 821 1111 return "<n/a>"; … … 883 1173 return binx + nx*(biny +ny*binz); 884 1174 } 1175 1176 // -------------------------------------------------------------------------- 1177 // 1178 // Return the MObjLookup corresponding to the axis/character. 1179 // Note that only lower-case charecters (x, y, z) are supported. 1180 // If for the axis no labels were set, the corresponding 1181 // InitLabels is called. 1182 // 1183 MObjLookup *MH3::GetLabels(char axe) 1184 { 1185 if (!fHist) 1186 return 0; 1187 1188 TAxis *x = 0; 1189 1190 switch (axe) 1191 { 1192 case 'x': 1193 x = fHist->GetXaxis(); 1194 break; 1195 case 'y': 1196 x = fHist->GetYaxis(); 1197 break; 1198 case 'z': 1199 x = fHist->GetZaxis(); 1200 break; 1201 } 1202 1203 if (!x) 1204 return 0; 1205 1206 const Int_t idx = axe-'x'; 1207 1208 if (!x->GetLabels()) 1209 switch (idx) 1210 { 1211 case 0: 1212 InitLabels(kLabelsX); 1213 break; 1214 case 1: 1215 InitLabels(kLabelsY); 1216 break; 1217 case 2: 1218 InitLabels(kLabelsZ); 1219 break; 1220 } 1221 1222 return &fLabels[idx]; 1223 } 1224 1225 // -------------------------------------------------------------------------- 1226 // 1227 // Set a default label which is used if no other is found in the list 1228 // of labels. if a default was set already it is overwritten. If the 1229 // axis has not yet been initialized to use labels it it now. 1230 // 1231 void MH3::DefaultLabel(char axe, const char *name) 1232 { 1233 MObjLookup *arr = GetLabels(axe); 1234 if (!arr) 1235 return; 1236 1237 if (arr->GetDefault()) 1238 { 1239 delete arr->GetDefault(); 1240 arr->SetDefault(0); 1241 } 1242 1243 if (name) 1244 arr->SetDefault(new TObjString(name)); 1245 } 1246 1247 // -------------------------------------------------------------------------- 1248 // 1249 // Define a name for a label. More than one label can have the same 1250 // name. If the axis has not yet been initialized to use labels 1251 // it it now. 1252 // 1253 void MH3::DefineLabel(char axe, Int_t label, const char *name) 1254 { 1255 MObjLookup *arr = GetLabels(axe); 1256 1257 if (!arr || !name) 1258 return; 1259 1260 if (arr->GetObj(label)!=arr->GetDefault()) 1261 return; 1262 1263 arr->Add(label, name); 1264 } 1265 1266 // -------------------------------------------------------------------------- 1267 // 1268 // Define names for labels, like 1269 // 1=Trig;2=Cal;4=Ped;8=Lvl2 1270 // More than one label can have the same name. If the axis has not 1271 // yet been initialized to use labels it it now. 1272 // 1273 // A default cannot be set here. Use DefaultLabel instead. 1274 // 1275 void MH3::DefineLabels(char axe, const TString &labels) 1276 { 1277 TObjArray *arr = labels.Tokenize(';'); 1278 1279 for (int i=0; i<arr->GetEntries(); i++) 1280 { 1281 const char *s = (*arr)[0]->GetName(); 1282 const char *v = strchr(s, '='); 1283 1284 if (v) 1285 DefineLabel(axe, atoi(s), v+1); 1286 } 1287 1288 delete arr; 1289 } -
trunk/MagicSoft/Mars/mhbase/MH3.h
r8888 r8893 8 8 #include "MH.h" 9 9 #endif 10 #ifndef MARS_MObjLookup 11 #include "MObjLookup.h" 12 #endif 10 13 11 14 class TH1; … … 15 18 class MH3 : public MH 16 19 { 20 public: 21 enum Labels_t { 22 kNoLabels = 0, 23 kLabelsX = BIT(0), 24 kLabelsY = BIT(1), 25 kLabelsZ = BIT(2), 26 kLabelsXY = kLabelsX|kLabelsY, 27 kLabelsXZ = kLabelsX|kLabelsZ, 28 kLabelsYZ = kLabelsY|kLabelsZ, 29 kLabelsXYZ = kLabelsX|kLabelsY|kLabelsZ, 30 }; 31 17 32 private: 18 33 static const TString gsDefName; 19 34 static const TString gsDefTitle; 35 36 // Helper for constructor 37 void Init(); 38 39 // Helper for dealing with labeled histograms 40 MObjLookup *GetLabels(char axe); 41 void InitLabels(TAxis &x) const; 42 void DeflateLabels() const; 43 Labels_t GetLabels() const; 44 const char *GetLabel(Int_t axe, Double_t val) const; 45 46 MObjLookup fLabels[3]; //! Lookup table to conflate and name labels 20 47 21 48 protected: … … 23 50 Int_t fDimension; // Number of dimensions of histogram 24 51 TH1 *fHist; // Histogram to fill 25 MData *fData[ 3]; // Object from which the data is filled52 MData *fData[4]; // Object from which the data is filled (+additional weight) 26 53 MBinning *fBins[3]; // Binning set omitting the parlist access 27 54 Double_t fScale[3]; // Scale for the three axis (eg unit) … … 43 70 enum Type_t { 44 71 kHistogram, 45 kProfile 72 kProfile, 46 73 }; 47 74 48 75 MH3(const Int_t dim=0, Type_t type=MH3::kHistogram); 49 76 MH3(const TH1 &h1); 50 MH3(const char *memberx );77 MH3(const char *memberx, Type_t type=MH3::kHistogram); 51 78 MH3(const char *memberx, const char *membery, Type_t type=MH3::kHistogram); 52 79 MH3(const char *memberx, const char *membery, const char *memberz, Type_t type=MH3::kHistogram); … … 75 102 76 103 void Sumw2() const { if (fHist) fHist->Sumw2(); } 104 105 void InitLabels(Labels_t labels) const; 106 107 void DefaultLabel(char axe, const char *name=0); 108 void DefaultLabelX(const char *name=0) { DefaultLabel('x', name); } 109 void DefaultLabelY(const char *name=0) { DefaultLabel('y', name); } 110 void DefaultLabelZ(const char *name=0) { DefaultLabel('z', name); } 111 112 void DefineLabel(char axe, Int_t label=0, const char *name=0); 113 void DefineLabelX(Int_t label, const char *name) { DefineLabel('x', label, name); } 114 void DefineLabelY(Int_t label, const char *name) { DefineLabel('y', label, name); } 115 void DefineLabelZ(Int_t label, const char *name) { DefineLabel('z', label, name); } 116 117 void DefineLabels(char axe, const TString &labels); 118 void DefineLabelsX(const TString &labels) { DefineLabels('x', labels); } 119 void DefineLabelsY(const TString &labels) { DefineLabels('y', labels); } 120 void DefineLabelsZ(const TString &labels) { DefineLabels('z', labels); } 121 122 void SetWeight(const char *phrase); 77 123 78 124 // Getter … … 109 155 void Paint(Option_t *opt=""); 110 156 111 ClassDef(MH3, 3) // Generalized 1/2/3D-histogram for Mars variables157 ClassDef(MH3, 4) // Generalized 1/2/3D-histogram for Mars variables 112 158 }; 113 159 -
trunk/MagicSoft/Mars/mhbase/MHn.cc
r8888 r8893 374 374 // -------------------------------------------------------------------------- 375 375 // 376 // call MH3::InitLabels for the current histogram 377 // 378 void MHn::InitLabels(MH3::Labels_t labels) const 379 { 380 if (fHist[fNum-1]) 381 fHist[fNum-1]->InitLabels(labels); 382 } 383 384 // -------------------------------------------------------------------------- 385 // 386 // call MH3::DefaultLabelX for the current histogram 387 // 388 void MHn::DefaultLabelX(const char *name) 389 { 390 if (fHist[fNum-1]) 391 fHist[fNum-1]->DefaultLabelX(name); 392 } 393 394 // -------------------------------------------------------------------------- 395 // 396 // call MH3::DefaultLabelY for the current histogram 397 // 398 void MHn::DefaultLabelY(const char *name) 399 { 400 if (fHist[fNum-1]) 401 fHist[fNum-1]->DefaultLabelY(name); 402 } 403 404 // -------------------------------------------------------------------------- 405 // 406 // call MH3::DefaultLabelZ for the current histogram 407 // 408 void MHn::DefaultLabelZ(const char *name) 409 { 410 if (fHist[fNum-1]) 411 fHist[fNum-1]->DefaultLabelZ(name); 412 } 413 414 // -------------------------------------------------------------------------- 415 // 416 // call MH3::DefineLabelX for the current histogram 417 // 418 void MHn::DefineLabelX(Int_t label, const char *name) 419 { 420 if (fHist[fNum-1]) 421 fHist[fNum-1]->DefineLabelX(label, name); 422 } 423 424 // -------------------------------------------------------------------------- 425 // 426 // call MH3::DefineLabelY for the current histogram 427 // 428 void MHn::DefineLabelY(Int_t label, const char *name) 429 { 430 if (fHist[fNum-1]) 431 fHist[fNum-1]->DefineLabelY(label, name); 432 } 433 434 // -------------------------------------------------------------------------- 435 // 436 // call MH3::DefineLabelZ for the current histogram 437 // 438 void MHn::DefineLabelZ(Int_t label, const char *name) 439 { 440 if (fHist[fNum-1]) 441 fHist[fNum-1]->DefineLabelZ(label, name); 442 } 443 444 // -------------------------------------------------------------------------- 445 // 446 // call MH3::DefineLabelsX for the current histogram 447 // 448 void MHn::DefineLabelsX(const TString &labels) 449 { 450 if (fHist[fNum-1]) 451 fHist[fNum-1]->DefineLabelsX(labels); 452 } 453 454 // -------------------------------------------------------------------------- 455 // 456 // call MH3::DefineLabelsY for the current histogram 457 // 458 void MHn::DefineLabelsY(const TString &labels) 459 { 460 if (fHist[fNum-1]) 461 fHist[fNum-1]->DefineLabelsY(labels); 462 } 463 464 // -------------------------------------------------------------------------- 465 // 466 // call MH3::DefineLabelsZ for the current histogram 467 // 468 void MHn::DefineLabelsZ(const TString &labels) 469 { 470 if (fHist[fNum-1]) 471 fHist[fNum-1]->DefineLabelsZ(labels); 472 } 473 474 // -------------------------------------------------------------------------- 475 // 476 // call MH3::SetWeight for the current histogram 477 // 478 void MHn::SetWeight(const char *phrase) 479 { 480 if (fHist[fNum-1]) 481 fHist[fNum-1]->SetWeight(phrase); 482 } 483 484 // -------------------------------------------------------------------------- 485 // 376 486 // Call SetupFill for all initialized histograms 377 487 // -
trunk/MagicSoft/Mars/mhbase/MHn.h
r8888 r8893 37 37 Bool_t AddHist(const char *memberx, const char *membery, const char *memberz, MH3::Type_t type=MH3::kHistogram); 38 38 39 void InitName(const char *n) 40 { 41 InitName(fNum-1, n); 42 } 39 void InitName(const char *n) { InitName(fNum-1, n); } 40 void InitTitle(const char *t) { InitTitle(fNum-1, t); } 43 41 44 void InitTitle(const char *t) 45 { 46 InitTitle(fNum-1, t); 47 } 48 49 // Interfact to MH3 42 // General interfact to MH3 50 43 void SetScale(Double_t x, Double_t y=1, Double_t z=2) const; 51 44 void SetLog(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) const; … … 53 46 void SetBinnings(MBinning *x=0, MBinning *y=0, MBinning *z=0) const; 54 47 void Sumw2() const; 48 49 // Interface to labels of MH3 50 void InitLabels(MH3::Labels_t labels) const; 51 52 void DefaultLabelX(const char *name=0); 53 void DefaultLabelY(const char *name=0); 54 void DefaultLabelZ(const char *name=0); 55 56 void DefineLabelX(Int_t label, const char *name); 57 void DefineLabelY(Int_t label, const char *name); 58 void DefineLabelZ(Int_t label, const char *name); 59 60 void DefineLabelsX(const TString &labels); 61 void DefineLabelsY(const TString &labels); 62 void DefineLabelsZ(const TString &labels); 63 64 // Set additonal weights for MH3 65 void SetWeight(const char *phrase); 55 66 56 67 // MH
Note:
See TracChangeset
for help on using the changeset viewer.