Changeset 1504 for trunk/MagicSoft


Ignore:
Timestamp:
08/16/02 11:47:30 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r1503 r1504  
    77
    88   * mhist/MHHillas.cc, mhist/MHHillasExt.cc:
    9      - added legends. (still work to be done with the stat boxes)
     9     - use the new MH::Draw[Copy] function
     10     - added names to the histograms in MHHillasExt
    1011
    1112   * manalysis/MCerPhotPix.h:
     
    1516     - added comment
    1617
     18   * mhist/MH.[h,cc]:
     19     - added function to draw two histograms in one pad with
     20       a layout of two stat boxes and a legend: Draw[Copy]
     21     - added comments
     22     - added another sanity check in SetBinning(TH1*,TH1*)
    1723
    1824
  • 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}
  • trunk/MagicSoft/Mars/mhist/MH.h

    r1463 r1504  
    5050    static void    ScaleAxis(TH1 *bins, Double_t fx=1, Double_t fy=1, Double_t fz=1);
    5151
     52    static void DrawCopy(const TH1 &hist1, const TH1 &hist2, const TString title);
     53    static void Draw(TH1 &hist1, TH1 &hist2, const TString title);
     54
    5255    static void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger);
    5356    static Double_t GetMinimumGT(const TH1 &h, Double_t gt=0);
  • trunk/MagicSoft/Mars/mhist/MHHillas.cc

    r1502 r1504  
    4141#include <TStyle.h>
    4242#include <TCanvas.h>
    43 #include <TLegend.h>
    4443
    4544#include "MLog.h"
     
    295294
    296295    c->cd(1);
    297 
    298     TObject *obj;
    299     TLegend *l = new TLegend(0.75, 0.8, 0.9, 0.9);
    300     obj = fWidth->DrawCopy();
    301     ((TH1*)obj)->SetTitle(" Width / Length ");
    302     l->AddEntry(obj, "Width");
    303     obj = fLength->DrawCopy("same");
    304     l->AddEntry(obj,  "Length");
    305     l->SetBit(kCanDelete);
    306     l->Draw();
     296    DrawCopy(*fWidth, *fLength, "Width / Length");
    307297
    308298    c->cd(2);
     
    311301
    312302    c->cd(3);
    313     l = new TLegend(0.70, 0.8, 0.9, 0.9);
    314     obj = fCorePix->DrawCopy();
    315     ((TH1*)obj)->SetTitle(" Number of core/used Pixels ");
    316     l->AddEntry(obj, "# Core Pixels");
    317     obj = fUsedPix->DrawCopy("same");
    318     l->AddEntry(obj,  "# Used Pixels");
    319     l->SetBit(kCanDelete);
    320     l->Draw();
     303    DrawCopy(*fCorePix, *fUsedPix, "Number of core/used Pixels");
    321304
    322305    c->cd(4);
     
    350333
    351334    gPad->cd(1);
    352     fWidth->Draw();
    353     fLength->Draw("same");
     335    MH::Draw(*fWidth, *fLength, "Width / Length");
    354336
    355337    gPad->cd(2);
     
    358340
    359341    gPad->cd(3);
    360     fCorePix->Draw();
    361     fUsedPix->Draw("same");
     342    MH::Draw(*fCorePix, *fUsedPix, "Number of core/used Pixels");
    362343
    363344    gPad->cd(4);
  • trunk/MagicSoft/Mars/mhist/MHHillasExt.cc

    r1502 r1504  
    8080    fHM3Trans.SetDirectory(NULL);
    8181
     82    fHConc.SetName("Conc2");
     83    fHConc1.SetName("Conc1");
     84    fHAsym.SetName("Asymmetry");
     85    fHM3Long.SetName("3rd Mom Long");
     86    fHM3Trans.SetName("3rd Mom Trans");
     87
    8288    fHConc.SetTitle("Ratio: Conc");
    8389    fHConc1.SetTitle("Ratio: Conc1");
     
    261267
    262268    c.cd(1);
    263     TObject *obj;
    264     TLegend *l = new TLegend(0.75, 0.8, 0.9, 0.9);
    265     obj = ((TH1F)fHConc1).DrawCopy();
    266     ((TH1*)obj)->SetTitle(" Concentrations ");
    267     l->AddEntry(obj, "Conc1");
    268     obj = ((TH1F)fHConc).DrawCopy("same");
    269     l->AddEntry(obj,  "Conc2");
    270     l->SetBit(kCanDelete);
    271     l->Draw();
     269    DrawCopy(fHConc1, fHConc, "Concentrations");
    272270
    273271    c.cd(2);
    274     ((TH1F)fHAsym).DrawCopy();
     272    ((TH1&)fHAsym).DrawCopy();
    275273
    276274    c.cd(3);
    277     ((TH1F)fHM3Long).DrawCopy();
     275    ((TH1&)fHM3Long).DrawCopy();
    278276
    279277    c.cd(4);
    280     ((TH1F)fHM3Trans).DrawCopy();
     278    ((TH1&)fHM3Trans).DrawCopy();
    281279
    282280    c.Modified();
     
    300298
    301299    gPad->cd(1);
    302     fHConc1.Draw();
    303     fHConc.Draw("same");
    304 
    305     TLegend *l = new TLegend(0.75, 0.8, 0.9, 0.9);
    306     l->AddEntry((TH1*)&fHConc1, "Conc 1");
    307     l->AddEntry((TH1*)&fHConc,  "Conc");
    308     l->SetBit(kCanDelete);
    309     l->Draw();
     300    MH::Draw(fHConc1, fHConc, "Concentrations");
    310301
    311302    gPad->cd(2);
Note: See TracChangeset for help on using the changeset viewer.