Ignore:
Timestamp:
05/19/08 15:04:36 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mhbase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhbase/MH.cc

    r8709 r8892  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.36 2007-08-25 15:30:24 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.37 2008-05-19 14:04:12 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    212212// --------------------------------------------------------------------------
    213213//
    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//
     219MBinning 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//
     234void 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.
    215250//
    216251void MH::SetBinning(TH1 *h, const MBinning *binsx)
     
    225260#endif
    226261
     262#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
    227263    // All this is reset by TAxis::Set
    228264    const TAttAxis att(x);
     
    247283    x.SetTimeDisplay(tm);
    248284    x.SetTimeFormat(tf);
     285#else
     286    if (!x.GetLabels())
     287        h->SetBins(binsx->GetNumBins(), binsx->GetEdges());
     288#endif
     289
    249290
    250291#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
     
    255296// --------------------------------------------------------------------------
    256297//
    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.
    258301//
    259302void MH::SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy)
     
    261304    TAxis &x = *h->GetXaxis();
    262305    TAxis &y = *h->GetYaxis();
     306
     307    const MBinning bx(GetBinningForLabels(x, binsx));
     308    const MBinning by(GetBinningForLabels(y, binsy));
    263309
    264310    //
     
    270316#endif
    271317
     318#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
    272319    // All this is reset by TAxis::Set
    273320    const TAttAxis attx(x);
     
    283330    // TH1D::fNcells must be set correctly.
    284331    //
    285     h->SetBins(binsx->GetNumBins(), 0, 1,
    286                binsy->GetNumBins(), 0, 1);
     332    h->SetBins(bx.GetNumBins(), 0, 1,
     333               by.GetNumBins(), 0, 1);
    287334
    288335    //
     
    290337    // in one of the two given histograms
    291338    //
    292     x.Set(binsx->GetNumBins(), binsx->GetEdges());
    293     y.Set(binsy->GetNumBins(), binsy->GetEdges());
     339    x.Set(bx.GetNumBins(), bx.GetEdges());
     340    y.Set(by.GetNumBins(), by.GetEdges());
    294341
    295342    // All this is reset by TAxis::Set
     
    300347    x.SetTimeFormat(tfx);
    301348    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);
    302356
    303357#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
     
    310364//
    311365// 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.
    312368//
    313369void MH::SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz)
     
    319375    TAxis &y = *h->GetYaxis();
    320376    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));
    321381
    322382#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
     
    326386#endif
    327387
     388#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
    328389    // All this is reset by TAxis::Set
    329390    const TAttAxis attx(x);
     
    336397    const TString  tfy(y.GetTimeFormat());
    337398    const TString  tfz(z.GetTimeFormat());
     399#endif
    338400
    339401    //
     
    342404    // TH1D::fNcells must be set correctly.
    343405    //
    344     h->SetBins(binsx->GetNumBins(), 0, 1,
    345                binsy->GetNumBins(), 0, 1,
    346                binsz->GetNumBins(), 0, 1);
     406    h->SetBins(bx.GetNumBins(), 0, 1,
     407               by.GetNumBins(), 0, 1,
     408               bz.GetNumBins(), 0, 1);
    347409
    348410    //
     
    350412    // in one of the two given histograms
    351413    //
    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)
    356423    // All this is reset by TAxis::Set
    357424    attx.Copy(x);
     
    364431    y.SetTimeFormat(tfy);
    365432    z.SetTimeFormat(tfz);
     433#endif
    366434
    367435#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
  • trunk/MagicSoft/Mars/mhbase/MH.h

    r8696 r8892  
    2626    Byte_t fSerialNumber;   // Serial number (eg of telecope)
    2727    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);
    2831
    2932public:
Note: See TracChangeset for help on using the changeset viewer.