Re: The need for a TPlotViewer?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Feb 17 2000 - 09:11:05 MET


Hi Mark,
I agree with your view that a "PlotViewer" is missing. We have all the
tools
in the GUI to create a nice viewer. However, these tools are only
available now on Unix and I am hesitating to implement something that
will be available on Unix systems only. We desperately try to find a
solution to get the GUI ported on NT. This item was discussed at the
Root workshop.
It is a top priority, otherwise we will diverge between Unix and NT
and the system will become unmaintainable.
Looking at your macro, you seem to ignore the TStyle class.
I have simplified your macro using TStyle. See the new version below:

Rene Brun

//macro to plot 30,60 and 90deg missing energy spectra
{
  gROOT->Reset();

  //set some standard pad parameters via TStyle
  gStyle->SetPadLeftMargin(0.25);
  gStyle->SetTitleH(0.06);
  gStyle->SetTitleW(0.5);
  gStyle->SetNdivisions(505,"X");
  gStyle->SetLabelSize(0.08,"X");
  gStyle->SetLabelOffset(-0.04,"X");
  gStyle->SetTitleSize(0.08,"X");
  gStyle->SetTitleOffset(0.5,"X");
  gStyle->SetLabelSize(0.08,"Y");
  gStyle->SetLabelOffset(0.02,"Y");
  gStyle->SetTitleSize(0.08,"Y");
  gStyle->SetTitleOffset(1.2,"Y");
  gStyle->SetOptStat(0);

  TCanvas *canvas = new TCanvas("canvas","Missing Energy 30,60,90",1);
  canvas->Divide(3,1);

  TH1F *hemissfg30 = new TH1F("hemissfg30","random 30",50,0,5);
  TH1F *hemissfg60 = new TH1F("hemissfg60","random 60",50,0,5);
  TH1F *hemissfg90 = new TH1F("hemissfg90","random 90",50,0,5);

  hemissfg30->FillRandom("gaus",1000);
  hemissfg60->FillRandom("gaus",1000);
  hemissfg90->FillRandom("gaus",1000);
    

  hemissfg30->SetXTitle("Missing Energy (MeV)");
  hemissfg60->SetXTitle("Missing Energy (MeV)");
  hemissfg90->SetXTitle("Missing Energy (MeV)");

  hemissfg30->SetYTitle("Counts");
  hemissfg60->SetYTitle("Counts");
  hemissfg90->SetYTitle("Counts");

  //now draw on the divided canvas
  TLine line;
  line.SetLineStyle(2);
  canvas->cd(1);
  hemissfg30->Draw();
  line.DrawLine(0,20,5,20);

  canvas->cd(2);
  hemissfg60->Draw();
  line.DrawLine(0,20,5,20);

  canvas->cd(3);
  hemissfg90->Draw();
  line.DrawLine(0,20,5,20);
  //------------end drawing on canvas
}
Mark James Boland wrote:
> 
> Hi ROOT users,
> 
> I am plotting histograms using a macro and have found the ways of setting
> attributes varied and inconsistent (naturally this could lie in the way I
> think about ROOT). Since this is such a fundamental part of using ROOT
> (displaying the results of ones physics analysis) maybe there need to be
> an easy way to simply plot things. Judging from the kinds of questions on
> this dicussion list I think other people might find something like that
> useful too. I am thinking here of an analagous tool to the TBrowser or
> TTreeViewer, a "one stop" GUI to set the layout of the canvas, axis titles
> etc. I don't have the C++/GUI programing skills to implement this myself
> but maybe someone is interested. I guess this issue relates to the
> philosophy of "Get ROOT working first, idiot proof later".
> 
> As an "idiot" I find ROOT very good for analysing my data but spent all
> day today chasing inheritances and member functions just to display three
> plots with legible axis and titles. Titles are set one way, labels
> another, Rebin() resets all the X-axis properties and not the Y so the
> order in which you SetXXX() things is important etc. This leads me, after
> a long preamble to my real questions:
> 
> In the following macro I set the Y-axis title to "Counts" and also set the
> size and the offset of the title. The values I use move the "Counts" title
> off the left edge of the pad and so I have to manually grab the TFrame
> with the mouse pointer and move it to the right for all three plot for the
> title to appear.
> 
> 1. Is there a way to automate this resizing of the TFrame based on NDC or
> pad size or whatever?
> 2. How can you set the size of the text in the TH1F title in the TPaveText
> object that appears above the histogram using a macro?
> 
> (sorry for the length of this example)
> 
> //macro to plot 30,60 and 90deg missing energy spectra
> {
>   gROOT->Reset();
> 
>   TCanvas *canvas = new TCanvas("canvas","Missing Energy 30,60,90",1);
>   canvas->Divide(3,1);
> 
>   TH1F *hemissfg30 = new TH1F("hemissfg30","random 30",100,-10,10);
>   TH1F *hemissfg60 = new TH1F("hemissfg60","random 60",100,-10,10);
>   TH1F *hemissfg90 = new TH1F("hemissfg90","random 90",100,-10,10);
> 
>   hemissfg30->FillRandom("gaus",1000);
>   hemissfg60->FillRandom("gaus",1000);
>   hemissfg90->FillRandom("gaus",1000);
> 
>   //must rebin first otherwise axis is reset and all SetXXXX are undone!!!
>   hemissfg30->Rebin(2);
>   hemissfg60->Rebin(2);
>   hemissfg90->Rebin(2);
> 
>   //Set axes properties
>   TAxis *Xaxis30 = hemissfg30->GetXaxis();
>   TAxis *Xaxis60 = hemissfg60->GetXaxis();
>   TAxis *Xaxis90 = hemissfg90->GetXaxis();
> 
>   Xaxis30->SetLabelSize(0.08);
>   Xaxis60->SetLabelSize(0.08);
>   Xaxis90->SetLabelSize(0.08);
> 
>   Xaxis30->SetLabelOffset(-0.04);
>   Xaxis60->SetLabelOffset(-0.04);
>   Xaxis90->SetLabelOffset(-0.04);
> 
>   Xaxis30->SetTitleSize(0.08);
>   Xaxis60->SetTitleSize(0.08);
>   Xaxis90->SetTitleSize(0.08);
> 
>   Xaxis30->SetTitleOffset(0.5);
>   Xaxis60->SetTitleOffset(0.5);
>   Xaxis90->SetTitleOffset(0.5);
> 
>   TAxis *Yaxis30 = hemissfg30->GetYaxis();
>   TAxis *Yaxis60 = hemissfg60->GetYaxis();
>   TAxis *Yaxis90 = hemissfg90->GetYaxis();
> 
>   Yaxis30->SetLabelSize(0.08);
>   Yaxis60->SetLabelSize(0.08);
>   Yaxis90->SetLabelSize(0.08);
> 
>   Yaxis30->SetLabelOffset(0.02);
>   Yaxis60->SetLabelOffset(0.02);
>   Yaxis90->SetLabelOffset(0.02);
> 
>   Yaxis30->SetTitleSize(0.08);
>   Yaxis60->SetTitleSize(0.08);
>   Yaxis90->SetTitleSize(0.08);
> 
>   Yaxis30->SetTitleOffset(1.2);
>   Yaxis60->SetTitleOffset(1.2);
>   Yaxis90->SetTitleOffset(1.2);
> 
>   //now set all the properties of the histograms
>   hemissfg30->SetStats(0);
>   hemissfg60->SetStats(0);
>   hemissfg90->SetStats(0);
> 
>   hemissfg30->SetAxisRange(0,5);
>   hemissfg60->SetAxisRange(0,5);
>   hemissfg90->SetAxisRange(0,5);
> 
>   hemissfg30->SetXTitle("Missing Energy (MeV)");
>   hemissfg60->SetXTitle("Missing Energy (MeV)");
>   hemissfg90->SetXTitle("Missing Energy (MeV)");
> 
>   hemissfg30->SetYTitle("Counts");
>   hemissfg60->SetYTitle("Counts");
>   hemissfg90->SetYTitle("Counts");
>   //----------------end of properties--------
> 
>   //create a zero line for each histo
>   TLine *line30 = new TLine(0,20,5,20);
>   TLine *line60 = new TLine(0,20,5,20);
>   TLine *line90 = new TLine(0,20,5,20);
> 
>   line30->SetLineStyle(2);
>   line60->SetLineStyle(2);
>   line90->SetLineStyle(2);
> 
>   line30->SetLineWidth(1);
>   line60->SetLineWidth(1);
>   line90->SetLineWidth(1);
>   //-----------end line stuff
> 
>   //now draw on the divided canvas
>   canvas->cd(1);
>   hemissfg30->Draw();
>   line30->Draw();
> 
>   canvas->cd(2);
>   hemissfg60->Draw();
>   line60->Draw();
> 
>   canvas->cd(3);
>   hemissfg90->Draw();
>   line90->Draw();
>   //------------end drawing on canvas
> }
> //EOF
> 
> Thanks in advance and keep up the good ROOT development work.
> 
> Regards,
> Mark
> 
> ___________________________________________________________________
> Mark Boland                           markjb@physics.unimelb.edu.au
> School of Physics                     PhD Student
> The University of Melbourne           Photonuclear Group
> Fax: +61 3 9347 4783                  Ph: +61 3 8344 5426



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:19 MET