Changeset 1449 for trunk/MagicSoft


Ignore:
Timestamp:
07/29/02 09:10:23 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mhist
Files:
2 edited

Legend:

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

    r1446 r1449  
    5252#include <TH2.h>
    5353#include <TH3.h>
     54#include <TGaxis.h>
    5455#include <TCanvas.h>
    5556
     
    335336        ScaleAxis(*h->GetXaxis()->GetXbins(), fx);
    336337}
     338
     339void MH::FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger)
     340{
     341//*-*-*-*-*-*-*-*-*Find reasonable bin values*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
     342//*-*              ==========================
     343
     344    Double_t dx = 0.1*(xmax-xmin);
     345    Double_t umin = xmin - dx;
     346    Double_t umax = xmax + dx;
     347
     348    if (umin < 0 && xmin >= 0)
     349        umin = 0;
     350
     351    if (umax > 0 && xmax <= 0)
     352        umax = 0;
     353
     354    Int_t n=0;
     355    Double_t binlow  =0;
     356    Double_t binhigh =0;
     357    Double_t binwidth=0;
     358    TGaxis::Optimize(umin, umax, nbins, binlow, binhigh, n, binwidth, "");
     359
     360    if (binwidth <= 0 || binwidth > 1.e+39)
     361    {
     362        xmin = -1;
     363        xmax = 1;
     364    }
     365    else
     366    {
     367        xmin = binlow;
     368        xmax = binhigh;
     369    }
     370
     371    if (isInteger)
     372    {
     373        Int_t ixmin = (Int_t)xmin;
     374        Int_t ixmax = (Int_t)xmax;
     375        Double_t dxmin = (Double_t)ixmin;
     376        Double_t dxmax = (Double_t)ixmax;
     377
     378        xmin = xmin<0 && xmin!=dxmin ? dxmin - 1 : dxmin;
     379        xmax = xmax>0 && xmax!=dxmax ? dxmax + 1 : dxmax;
     380
     381        if (xmin>=xmax)
     382            xmax = xmin+1;
     383
     384        Int_t bw = 1 + (Int_t)((xmax-xmin)/nbins);
     385
     386        nbins = (Int_t)((xmax-xmin)/bw);
     387
     388        if (xmin+nbins*bw < xmax)
     389        {
     390            nbins++;
     391            xmax = xmin +nbins*bw;
     392        }
     393    }
     394
     395    newbins = nbins;
     396}
     397
     398Double_t MH::GetMinimumGT(const TH1 &h, Double_t gt)
     399{
     400    Double_t min = FLT_MAX;
     401
     402    const TAxis &axe = *((TH1&)h).GetXaxis();
     403
     404    for (int i=1; i<=axe.GetNbins(); i++)
     405    {
     406        Double_t x = h.GetBinContent(i);
     407        if (gt<x && x<min)
     408            min = x;
     409    }
     410    return min;
     411}
  • trunk/MagicSoft/Mars/mhist/MH.h

    r1441 r1449  
    4747    static void ScaleAxis(TH1 *bins, Double_t fx=1, Double_t fy=1, Double_t fz=1);
    4848
     49    static void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger);
     50    static Double_t GetMinimumGT(const TH1 &h, Double_t gt=0);
     51
    4952    ClassDef(MH, 1) //A histogram base class for Mars histograms
    5053};
Note: See TracChangeset for help on using the changeset viewer.