Ignore:
Timestamp:
09/13/04 08:57:58 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mhbase
Files:
4 edited

Legend:

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

    r4920 r4966  
    1818!   Author(s): Thomas Bretz, 01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2003
     20!   Copyright: MAGIC Software Development, 2000-2004
    2121!
    2222!
     
    2424
    2525//////////////////////////////////////////////////////////////////////////////
    26 //                                                                          //
    27 //  MBinning                                                                //
    28 //                                                                          //
     26//
     27//  MBinning
     28//
     29// This is a MParCOntainer storing a binning for a histogram. Doing this
     30// you are able to distribute a single binning to several histograms
     31// in your parameter list.
     32//
     33// In some classes the title of the container is used to set the
     34// axis-title of the corresponding axis in your histogram.
     35//
     36// For all the features supported see the function descriptions in
     37//  MBinning and MH
     38//
    2939//////////////////////////////////////////////////////////////////////////////
    3040#include "MBinning.h"
     
    6474}
    6575
     76// --------------------------------------------------------------------------
     77//
     78// Instantiate MBinning with nbins number of bins between lo (lower edge)
     79// and hi (upper edge), name name and title title.
     80//
    6681MBinning::MBinning(Int_t nbins, Axis_t lo, Axis_t hi, const char *name, const char *opt, const char *title)
    6782{
     
    7085
    7186    SetEdges(nbins, lo, hi, opt);
    72 
    73 }
    74 
     87}
     88
     89// --------------------------------------------------------------------------
     90//
     91// Setup the edges stored in MBinning from the TAxis axe
     92//
    7593void MBinning::SetEdges(const TAxis &axe)
    7694{
     
    85103}
    86104
     105// --------------------------------------------------------------------------
     106//
     107// Add a new upper edge to the edges stored in MBinning. The new upper
     108// edge must be greater than the current greatest. Using this you can
     109// enhance a histogram bin-by-bin, eg:
     110//   TH1F h("", "", 2, 0, 1);
     111//   MBinning b;
     112//   b.SetEdges(h);
     113//   b.AddEdge(2);
     114//   b.Apply(h);
     115//   b.AddEdge(3);
     116//   b.Apply(h);
     117//   [...]
     118//
    87119void MBinning::AddEdge(Axis_t up)
    88120{
     
    101133}
    102134
     135void MBinning::RemoveFirstEdge()
     136{
     137    const Int_t n = fEdges.GetSize();
     138    for (int i=0; i<n-1; i++)
     139        fEdges[i] = fEdges[i+1];
     140    fEdges.Set(n-1);
     141}
     142
     143void MBinning::RemoveLastEdge()
     144{
     145    fEdges.Set(fEdges.GetSize()-1);
     146}
     147
     148// --------------------------------------------------------------------------
     149//
     150// Set the edges in MBinning from a histogram-axis. Which axis is
     151// specified by axis ('x', 'y', 'z')
     152//
    103153void MBinning::SetEdges(const TH1 &h, const Char_t axis)
    104154{
    105     TH1 &hist = (TH1&)h; // get rid of const qualifier
    106155    switch (tolower(axis))
    107156    {
    108157    case 'x':
    109         SetEdges(*hist.GetXaxis());
     158        SetEdges(*h.GetXaxis());
    110159        return;
    111160    case 'y':
    112         SetEdges(*hist.GetYaxis());
     161        SetEdges(*h.GetYaxis());
    113162        return;
    114163    case 'z':
    115         SetEdges(*hist.GetZaxis());
     164        SetEdges(*h.GetZaxis());
    116165        return;
    117166    default:
    118167        *fLog << warn << "MBinning::SetEdges: Axis '" << axis << "' unknown... using x." << endl;
    119         SetEdges(*hist.GetXaxis());
     168        SetEdges(*h.GetXaxis());
    120169    }
    121170}
  • trunk/MagicSoft/Mars/mhbase/MBinning.h

    r4920 r4966  
    4646
    4747    void SetEdges(const TAxis &axe);
     48    void SetEdges(const MBinning &bins) { SetEdges(fEdges); }
    4849    void SetEdges(const TH1 &h, const Char_t axis='x');
    4950    void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
     
    5960        for (int i=1; i<fEdges.GetSize(); i++)
    6061        {
    61             if (((TArrayD)fEdges)[i] >= val)
     62            if (fEdges[i] >= val)
    6263                return i-1;
    6364        }
     
    7071    }
    7172
    72     // FIXME: ROOT workaround: "operator[] const" missing
    73     Double_t GetEdgeLo() const { return ((TArrayD)fEdges)[0]; }
    74     Double_t GetEdgeHi() const { return ((TArrayD)fEdges)[fEdges.GetSize()-1]; }
     73    Double_t GetEdgeLo() const { return fEdges[0]; }
     74    Double_t GetEdgeHi() const { return fEdges[fEdges.GetSize()-1]; }
    7575
    76     Int_t GetNumEdges() const { return fEdges.GetSize(); }
    77     Int_t GetNumBins() const { return fEdges.GetSize()-1; }
     76    Int_t GetNumEdges() const  { return fEdges.GetSize(); }
     77    Int_t GetNumBins() const   { return fEdges.GetSize()-1; }
    7878
    7979    Double_t *GetEdges() const { return (Double_t*)fEdges.GetArray(); }
     80    const TArrayD &GetEdgesD() const { return fEdges; }
    8081
    8182    void AddEdge(Axis_t up);
     83    void RemoveFirstEdge();
     84    void RemoveLastEdge();
    8285
    83     Bool_t IsLinear() const { return fType==kIsLinear; }
     86    Bool_t IsLinear() const      { return fType==kIsLinear; }
    8487    Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
    85     Bool_t IsCosinic() const { return fType==kIsCosinic; }
    86     Bool_t IsDefault() const { return fType==kIsDefault; }
    87     Bool_t IsUserArray() const { return fType==kIsUserArray; }
     88    Bool_t IsCosinic() const     { return fType==kIsCosinic; }
     89    Bool_t IsDefault() const     { return fType==kIsDefault; }
     90    Bool_t IsUserArray() const   { return fType==kIsUserArray; }
    8891
    89     Bool_t HasTitle() const { return gsDefTitle!=fTitle; }
     92    Bool_t HasTitle() const      { return gsDefTitle!=fTitle; }
    9093
    9194    void Apply(TH1 &) const;
     
    9598
    9699#endif
    97 
  • trunk/MagicSoft/Mars/mhbase/MH.cc

    r4956 r4966  
    478478}
    479479
     480void MH::RemoveFirstBin(TH1 &h)
     481{
     482    if (h.InheritsFrom(TH2::Class()) || h.InheritsFrom(TH3::Class()))
     483        return;
     484
     485    const Int_t n0 = h.GetNbinsX();
     486    if (n0<2)
     487        return;
     488
     489    TArrayD val(n0-1);
     490    TArrayD err(n0-1);
     491    for (int i=1; i<n0; i++)
     492    {
     493        val[i-1] = h.GetBinContent(i+1);
     494        err[i-1] = h.GetBinError(i+1);
     495    }
     496
     497    MBinning bins;
     498    bins.SetEdges(h, 'x');
     499    bins.RemoveFirstEdge();
     500    bins.Apply(h);
     501
     502    h.Reset();
     503
     504    for (int i=1; i<n0; i++)
     505    {
     506        h.SetBinContent(i, val[i-1]);
     507        h.SetBinError(i, err[i-1]);
     508    }
     509}
     510
    480511// --------------------------------------------------------------------------
    481512//
  • trunk/MagicSoft/Mars/mhbase/MH.h

    r4956 r4966  
    6969    static void SetBinning(TH1 *h, const TH1 *x);
    7070
     71    static void RemoveFirstBin(TH1 &h);
     72
    7173    static Bool_t ApplyBinning(const MParList &plist, TString name, TH1 *h);
    7274
Note: See TracChangeset for help on using the changeset viewer.