Ignore:
Timestamp:
08/22/07 19:18:35 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mhbase
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhbase/HBaseLinkDef.h

    r6915 r8695  
    99#pragma link C++ class MH+;
    1010#pragma link C++ class MH3+;
     11#pragma link C++ class MHn+;
    1112#pragma link C++ class MHArray+;
    1213#pragma link C++ class MHMatrix+;
  • trunk/MagicSoft/Mars/mhbase/MH3.cc

    r8669 r8695  
    5454// If the binning should have a different name than the histogram name
    5555// the binning name can be added to the name, eg.:
    56 //    SetName("MyHistName;MyBinning")
     56//    SetName("MyHistName;MyXBins;MyYBins")
    5757// Instead of BinningMyHistName[XYZ] the parameter list will be searched
    58 // for BinningMyBinning[XYZ].
     58// for BinningMyXBinning, BinningMyYBins and BinningMyHistNameZ
    5959//
    6060//
     
    8686//   + MData      *fData[3];        // Object from which the data is filled
    8787//
     88// Class Version 3:
     89// ----------------
     90//   - Byte_t fStyleBits
    8891//
    8992/////////////////////////////////////////////////////////////////////////////
     
    9396#include <fstream>
    9497
    95 #include <TPad.h>
     98//#include <TPad.h>
    9699#include <TStyle.h>
    97100#include <TCanvas.h>
     
    121124//
    122125MH3::MH3(const unsigned int dim)
    123     : fDimension(dim>3?3:dim), fHist(NULL)
     126    : fDimension(dim>3?3:dim), fHist(NULL), fStyleBits(0)
    124127
    125128    switch (fDimension)
     
    162165//
    163166MH3::MH3(const char *memberx)
    164     : fDimension(1)
     167    : fDimension(1), fStyleBits(0)
    165168{
    166169    fHist = new TH1D;
     
    182185}
    183186
    184 MH3::MH3(const TH1 &h1) : fDimension(1)
     187MH3::MH3(const TH1 &h1)
     188    : fDimension(1), fStyleBits(0)
    185189{
    186190    if (h1.InheritsFrom(TH3::Class()))
     
    221225//
    222226MH3::MH3(const char *memberx, const char *membery)
    223     : fDimension(2)
     227    : fDimension(2), fStyleBits(0)
    224228{
    225229    fHist = new TH2D;
     
    248252//
    249253MH3::MH3(const char *memberx, const char *membery, const char *memberz)
    250     : fDimension(3)
     254    : fDimension(3), fStyleBits(0)
    251255{
    252256    fHist = new TH3D;
     
    312316    fHist->Reset();
    313317
    314     const Int_t split = fName.First(';');
    315 
    316     const TString name = split<0 ? fName : fName(0, split);
    317     const TString bins = split<0 ? fName : fName(split+1, fName.Length());
    318 
    319     TString bname("Binning");
    320     bname += bins;
     318    // Tokenize name into name and binnings names
     319    TObjArray *tok = fName.Tokenize(";");
     320
     321    const TString name = (*tok)[0] ? (*tok)[0]->GetName() : fName.Data();
     322
     323    TString bx = (*tok)[1] ? (*tok)[1]->GetName() : Form("%sX", name.Data());
     324    TString by = (*tok)[2] ? (*tok)[2]->GetName() : Form("%sY", name.Data());
     325    TString bz = (*tok)[3] ? (*tok)[3]->GetName() : Form("%sZ", name.Data());
     326
     327    bx.Prepend("Binning");
     328    by.Prepend("Binning");
     329    bz.Prepend("Binning");
     330
     331    delete tok;
     332
    321333
    322334    MBinning *binsx = NULL;
     
    327339    {
    328340    case 3:
    329         binsz = (MBinning*)plist->FindObject(bname+"Z", "MBinning");
     341        binsz = (MBinning*)plist->FindObject(bz, "MBinning");
    330342        if (!binsz)
    331343        {
    332             *fLog << err << dbginf << "MBinning '" << bname << "X' not found... aborting." << endl;
     344            *fLog << err << dbginf << "MBinning '" << bz << "' not found... aborting." << endl;
    333345            return kFALSE;
    334346        }
     
    342354            fHist->SetBit(kIsLogz);
    343355    case 2:
    344         binsy = (MBinning*)plist->FindObject(bname+"Y", "MBinning");
     356        binsy = (MBinning*)plist->FindObject(by, "MBinning");
    345357        if (!binsy)
    346358        {
    347             *fLog << err << dbginf << "MBinning '" << bname << "Y' not found... aborting." << endl;
     359            *fLog << err << dbginf << "MBinning '" << by << "' not found... aborting." << endl;
    348360            return kFALSE;
    349361        }
     
    357369            fHist->SetBit(kIsLogy);
    358370    case 1:
    359         binsx = (MBinning*)plist->FindObject(bname+"X", "MBinning");
     371        binsx = (MBinning*)plist->FindObject(bx, "MBinning");
    360372        if (!binsx)
    361373        {
    362374            if (fDimension==1)
    363                 binsx = (MBinning*)plist->FindObject(bname, "MBinning");
     375                binsx = (MBinning*)plist->FindObject("Binning"+fName, "MBinning");
    364376
    365377            if (!binsx)
    366378            {
    367                 *fLog << err << dbginf << "Neither MBinning '" << bname << "X' nor '" << bname << "' found... aborting." << endl;
     379                *fLog << err << dbginf << "Neither '" << bx << "' nor '" << binsx << fName << "' found... aborting." << endl;
    368380                return kFALSE;
    369381            }
     
    477489    return kFALSE;
    478490}
    479 /*
    480 // --------------------------------------------------------------------------
    481 //
    482 // Set the palette you wanna use:
    483 //  - you could set the root "Pretty Palette Violet->Red" by
    484 //    gStyle->SetPalette(1, 0), but in some cases this may look
    485 //    confusing
    486 //  - The maximum colors root allowes us to set by ourself
    487 //    is 50 (idx: 51-100). This colors are set to a grayscaled
    488 //    palette
    489 //  - the number of contours must be two less than the number
    490 //    of palette entries
    491 //
    492 void MHStarMap::PrepareDrawing() const
    493 {
    494     const Int_t numg = 32; // number of gray scaled colors
    495     const Int_t numw = 32; // number of white
    496 
    497     Int_t palette[numg+numw];
    498 
    499     //
    500     // The first half of the colors are white.
    501     // This is some kind of optical background supression
    502     //
    503     gROOT->GetColor(51)->SetRGB(1, 1, 1);
    504 
    505     Int_t i;
    506     for (i=0; i<numw; i++)
    507         palette[i] = 51;
    508 
    509     //
    510     // now the (gray) scaled part is coming
    511     //
    512     for (;i<numw+numg; i++)
    513     {
    514         const Float_t gray = 1.0-(float)(i-numw)/(numg-1.0);
    515 
    516         gROOT->GetColor(52+i)->SetRGB(gray, gray, gray);
    517         palette[i] = 52+i;
    518     }
    519 
    520     //
    521     // Set the palette and the number of contour levels
    522     //
    523     gStyle->SetPalette(numg+numw, palette);
    524     fStarMap->SetContour(numg+numw-2);
    525 }
    526 */
     491
     492// --------------------------------------------------------------------------
     493//
     494// If an auto range bit is set the histogram range of the corresponding
     495// axis is set to show only the non-empty bins (with a single empty bin
     496// on both sides)
     497//
     498Bool_t MH3::Finalize()
     499{
     500    Bool_t autorangex=TESTBIT(fStyleBits, 0);
     501    Bool_t autorangey=TESTBIT(fStyleBits, 1);
     502    //Bool_t autorangez=TESTBIT(fStyleBits, 2);
     503
     504    Int_t lo, hi;
     505
     506    if (autorangex)
     507    {
     508        GetRangeX(*fHist, lo, hi);
     509        cout << "====> " << GetName() << " " << fHist->GetName() << ": " << lo << " " << hi <<" " << fHist->GetNbinsX() <<  endl;
     510        fHist->GetXaxis()->SetRange(lo-2, hi+1);
     511    }
     512    if (autorangey)
     513    {
     514        GetRangeY(*fHist, lo, hi);
     515        fHist->GetYaxis()->SetRange(lo-2, hi+1);
     516    }
     517    /*
     518    if (autorangez)
     519    {
     520        GetRangeZ(*fHist, lo, hi);
     521        fHist->GetZaxis()->SetRange(lo-2, hi+1);
     522    }
     523    */
     524    return kTRUE;
     525}
     526
    527527// --------------------------------------------------------------------------
    528528//
     
    547547    {
    548548        Int_t col = p->GetLineColor();
    549         p = ((TH2*)fHist)->ProfileX(pfx, -1, 9999, "s");
     549        p = ((TH2*)fHist)->ProfileX(pfx, -1, -1, "s");
    550550        p->SetLineColor(col);
    551551    }
     
    555555    {
    556556        Int_t col = p->GetLineColor();
    557         p = ((TH2*)fHist)->ProfileY(pfy, -1, 9999, "s");
     557        p = ((TH2*)fHist)->ProfileY(pfy, -1, -1, "s");
    558558        p->SetLineColor(col);
    559559    }
    560 
     560/*
    561561    if (fHist->TestBit(kIsLogx) && fHist->GetEntries()>0) gPad->SetLogx();
    562562    if (fHist->TestBit(kIsLogy) && fHist->GetEntries()>0) gPad->SetLogy();
    563563    if (fHist->TestBit(kIsLogz) && fHist->GetEntries()>0) gPad->SetLogz();
     564    */
    564565}
    565566
     
    587588    pad->SetGridy();
    588589
     590    if (fHist->TestBit(kIsLogx)) pad->SetLogx();
     591    if (fHist->TestBit(kIsLogy)) pad->SetLogy();
     592    if (fHist->TestBit(kIsLogz)) pad->SetLogz();
     593
    589594    fHist->SetFillStyle(4000);
    590595
     
    624629            *fLog << warn << "TProfile " << pfx << " already in pad." << endl;
    625630
    626         p = ((TH2*)fHist)->ProfileX(pfx, -1, 9999, "s");
     631        p = ((TH2*)fHist)->ProfileX(pfx, -1, -1, "s");
    627632        p->UseCurrentStyle();
    628633        p->SetLineColor(blue ? kBlue : fHist->GetLineColor());
     
    640645            *fLog << warn << "TProfile " << pfy << " already in pad." << endl;
    641646
    642         p = ((TH2*)fHist)->ProfileY(pfy, -1, 9999, "s");
     647        p = ((TH2*)fHist)->ProfileY(pfy, -1, -1, "s");
    643648        p->UseCurrentStyle();
    644649        p->SetLineColor(blue ? kBlue : fHist->GetLineColor());
  • trunk/MagicSoft/Mars/mhbase/MH3.h

    r8082 r8695  
    1010
    1111class TH1;
    12 class TMethodCall;
    1312class MData;
    1413
     
    2524    MData      *fData[3];        // Object from which the data is filled
    2625    Double_t    fScale[3];       // Scale for the three axis (eg unit)
     26    Byte_t      fStyleBits;      // Set the range of a histogram automatically in Finalize
    2727
    2828    void StreamPrimitive(ostream &out) const;
     
    4646    void SetScaleY(Double_t scale) { fScale[1] = scale; }
    4747    void SetScaleZ(Double_t scale) { fScale[2] = scale; }
     48    void SetScale(Double_t x, Double_t y=1, Double_t z=2) { SetScaleX(x); SetScaleY(y); SetScaleZ(z); }
    4849
    4950    void SetLogx(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogx) : fHist->ResetBit(kIsLogx); }
    5051    void SetLogy(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogy) : fHist->ResetBit(kIsLogy); }
    5152    void SetLogz(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogz) : fHist->ResetBit(kIsLogz); }
     53    void SetLog(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetLogx(x); SetLogy(y); SetLogz(z); }
     54
     55    void SetAutoRangeX(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 0) : CLRBIT(fStyleBits, 0); }
     56    void SetAutoRangeY(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 1) : CLRBIT(fStyleBits, 1); }
     57    void SetAutoRangeZ(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 2) : CLRBIT(fStyleBits, 2); }
     58    void SetAutoRange(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetAutoRangeX(x); SetAutoRangeY(y); SetAutoRangeZ(z); }
    5259
    5360    void Sumw2() const { if (fHist) fHist->Sumw2(); }
     
    6774    Bool_t SetupFill(const MParList *pList);
    6875    Bool_t Fill(const MParContainer *par, const Stat_t w=1);
     76    Bool_t Finalize();
    6977
    7078    TH1 *GetHistByName(const TString name="") const { return fHist; }
     
    8694    void Paint(Option_t *opt="");
    8795
    88     ClassDef(MH3, 2) // Generalized 1/2/3D-histogram for Mars variables
     96    ClassDef(MH3, 3) // Generalized 1/2/3D-histogram for Mars variables
    8997};
    9098
  • trunk/MagicSoft/Mars/mhbase/Makefile

    r6915 r8695  
    2525           MH.cc \
    2626           MH3.cc \
     27           MHn.cc \
    2728           MHArray.cc \
    2829           MHMatrix.cc
Note: See TracChangeset for help on using the changeset viewer.