Ignore:
Timestamp:
08/16/02 11:47:30 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r1484 r1504  
    5454#include <TGaxis.h>
    5555#include <TCanvas.h>
     56#include <TLegend.h>
     57#include <TPaveStats.h>
    5658
    5759#include "MLog.h"
     
    133135}
    134136
     137// --------------------------------------------------------------------------
     138//
     139// Applies a given binning to a 1D-histogram
     140//
    135141void MH::SetBinning(TH1 *h, const MBinning *binsx)
    136142{
     
    161167}
    162168
     169// --------------------------------------------------------------------------
     170//
     171// Applies given binnings to the two axis of a 2D-histogram
     172//
    163173void MH::SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy)
    164174{
     
    194204}
    195205
     206// --------------------------------------------------------------------------
     207//
     208// Applies given binnings to the three axis of a 3D-histogram
     209//
    196210void MH::SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz)
    197211{
     
    232246}
    233247
     248// --------------------------------------------------------------------------
     249//
     250// Applies given binning (the n+1 edges)  to the axis of a 1D-histogram
     251//
    234252void MH::SetBinning(TH1 *h, const TArrayD &binsx)
    235253{
     
    239257}
    240258
     259// --------------------------------------------------------------------------
     260//
     261// Applies given binning (the n+1 edges) to the two axis of a
     262// 2D-histogram
     263//
    241264void MH::SetBinning(TH2 *h, const TArrayD &binsx, const TArrayD &binsy)
    242265{
     
    248271}
    249272
     273// --------------------------------------------------------------------------
     274//
     275// Applies given binning (the n+1 edges) to the three axis of a
     276// 3D-histogram
     277//
    250278void MH::SetBinning(TH3 *h, const TArrayD &binsx, const TArrayD &binsy, const TArrayD &binsz)
    251279{
     
    259287}
    260288
     289// --------------------------------------------------------------------------
     290//
     291// Applies the binning of a TAxis (eg from a root histogram) to the axis
     292// of a 1D-histogram
     293//
    261294void MH::SetBinning(TH1 *h, const TAxis *binsx)
    262295{
     
    270303}
    271304
     305// --------------------------------------------------------------------------
     306//
     307// Applies the binnings of the TAxis' (eg from a root histogram) to the
     308// two axis' of a 2D-histogram
     309//
    272310void MH::SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy)
    273311{
     
    285323}
    286324
     325// --------------------------------------------------------------------------
     326//
     327// Applies the binnings of the TAxis' (eg from a root histogram) to the
     328// three axis' of a 3D-histogram
     329//
    287330void MH::SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz)
    288331{
     
    304347}
    305348
     349// --------------------------------------------------------------------------
     350//
     351// Applies the binnings of one root-histogram x to another one h
     352// Both histograms must be of the same type: TH1, TH2 or TH3
     353//
    306354void MH::SetBinning(TH1 *h, TH1 *x)
    307355{
     
    311359        return;
    312360    }
     361    if (h->InheritsFrom(TH3::Class()) || x->InheritsFrom(TH3::Class()))
     362        return;
    313363    if (h->InheritsFrom(TH2::Class()) && x->InheritsFrom(TH2::Class()))
    314364    {
     
    316366        return;
    317367    }
     368    if (h->InheritsFrom(TH2::Class()) || x->InheritsFrom(TH2::Class()))
     369        return;
    318370    if (h->InheritsFrom(TH1::Class()) && x->InheritsFrom(TH1::Class()))
    319371    {
     
    323375}
    324376
     377// --------------------------------------------------------------------------
     378//
     379// Multiplies all entries in a TArrayD by a float f
     380//
    325381void MH::ScaleArray(TArrayD &bins, Double_t f)
    326382{
     
    329385}
    330386
     387// --------------------------------------------------------------------------
     388//
     389// Scales the binning of a TAxis by a float f
     390//
    331391TArrayD MH::ScaleAxis(TAxis &axe, Double_t f)
    332392{
     
    341401}
    342402
     403// --------------------------------------------------------------------------
     404//
     405// Scales the binning of one, two or three axis of a histogram by a float f
     406//
    343407void MH::ScaleAxis(TH1 *h, Double_t fx, Double_t fy, Double_t fz)
    344408{
     
    364428}
    365429
     430// --------------------------------------------------------------------------
     431//
     432// Tries to find a MBinning container with the name "Binning"+name
     433// in the given parameter list. If it was found it is applied to the
     434// given histogram. This is only valid for 1D-histograms
     435//
    366436Bool_t MH::ApplyBinning(const MParList &plist, TString name, TH1 *h)
    367437{
     
    442512}
    443513
     514// --------------------------------------------------------------------------
     515//
     516//  Returns the lowest entry in a histogram which is greater than gt (eg >0)
     517//
    444518Double_t MH::GetMinimumGT(const TH1 &h, Double_t gt)
    445519{
     
    456530    return min;
    457531}
     532
     533// --------------------------------------------------------------------------
     534//
     535// Draws a copy of the two given histograms. Uses title as the pad title.
     536// Also layout the two statistic boxes and a legend.
     537//
     538void MH::DrawCopy(const TH1 &hist1, const TH1 &hist2, const TString title)
     539{
     540    //
     541    // Draw first histogram
     542    //
     543    TH1 *h1 = (TH1*)((TH1&)hist1).DrawCopy();
     544    gPad->Update();
     545
     546    //
     547    // Rename first statistics box
     548    //
     549    TPaveStats &s1 = *(TPaveStats*)gPad->FindObject("stats");
     550    s1.SetX1NDC(s1.GetX1NDC()-0.01);
     551    s1.SetName((TString)"Stat"+hist1.GetTitle());
     552
     553    //
     554    // Draw second histogram
     555    //
     556    TH1 *h2 = (TH1*)((TH1&)hist2).DrawCopy("sames");
     557
     558    gPad->Update();
     559
     560    //
     561    // Set new position of second statistics box
     562    //
     563    TPaveStats &s2 = *(TPaveStats*)gPad->FindObject("stats");
     564    s2.SetX1NDC(s1.GetX1NDC()-(s2.GetX2NDC()-s2.GetX1NDC())-0.01);
     565    s2.SetX2NDC(s1.GetX1NDC()-0.01);
     566
     567    //
     568    // Draw Legend
     569    //
     570    TLegend &l = *new TLegend(s1.GetX1NDC(),
     571                              s1.GetY1NDC()-0.015-(s1.GetY2NDC()-s1.GetY1NDC())/2,
     572                              s1.GetX2NDC(),
     573                              s1.GetY1NDC()-0.01
     574                            );
     575    l.AddEntry(h1, h1->GetTitle());
     576    l.AddEntry(h2, h2->GetTitle());
     577    l.SetTextSize(s2.GetTextSize());
     578    l.SetTextFont(s2.GetTextFont());
     579    l.SetBorderSize(s2.GetBorderSize());
     580    l.SetBit(kCanDelete);
     581
     582    // FIXME: Don't change the hist title. Change TPaveText::title
     583    h1->SetTitle(" "+title+" ");
     584
     585    l.Draw();
     586}
     587
     588// --------------------------------------------------------------------------
     589//
     590// Draws the two given histograms. Uses title as the pad title.
     591// Also layout the two statistic boxes and a legend.
     592//
     593void MH::Draw(TH1 &hist1, TH1 &hist2, const TString title)
     594{
     595    //
     596    // Draw first histogram
     597    //
     598    hist1.Draw();
     599    // FIXME: Don't change the hist title. Change TPaveText::title
     600    //h1->SetTitle(" "+title+" ");
     601
     602    gPad->Update();
     603
     604    //
     605    // Rename first statistics box
     606    //
     607    TPaveStats &s1 = *(TPaveStats*)gPad->FindObject("stats");
     608    s1.SetX1NDC(s1.GetX1NDC()-0.01);
     609    s1.SetName((TString)"Stat"+hist1.GetTitle());
     610
     611    //
     612    // Draw second histogram
     613    //
     614    hist2.Draw("sames");
     615
     616    gPad->Update();
     617
     618    //
     619    // Set new position of second statistics box
     620    //
     621    TPaveStats &s2 = *(TPaveStats*)gPad->FindObject("stats");
     622    s2.SetX1NDC(s1.GetX1NDC()-(s2.GetX2NDC()-s2.GetX1NDC())-0.01);
     623    s2.SetX2NDC(s1.GetX1NDC()-0.01);
     624
     625    //
     626    // Draw Legend
     627    //
     628    TLegend &l = *new TLegend(s1.GetX1NDC(),
     629                              s1.GetY1NDC()-0.015-(s1.GetY2NDC()-s1.GetY1NDC())/2,
     630                              s1.GetX2NDC(),
     631                              s1.GetY1NDC()-0.01
     632                             );
     633    l.AddEntry(&hist1, hist1.GetTitle());
     634    l.AddEntry(&hist2, hist2.GetTitle());
     635    l.SetTextSize(s2.GetTextSize());
     636    l.SetTextFont(s2.GetTextFont());
     637    l.SetBorderSize(s2.GetBorderSize());
     638    l.SetBit(kCanDelete);
     639    l.Draw();
     640}
Note: See TracChangeset for help on using the changeset viewer.