TTree,axis labels and other cosmethics

Hi again you all.

Sorry to bother.

I try to draw a TTree and then add to it marker style, labels, line between points.

i use this:

[code]#include <TFile.h>
#include <TObjArray.h>
#include <TGraph.h>
#include <TObject.h>
#include <TCint.h>
#include <TGraphErrors.h>
#include <TMultiGraph.h>
#include <TMarker.h>
#include <TTree.h>
#include <TBranch.h>
#include <TFolder.h>
#include <TString.h>
#include <TH1.h>
#include <TH2.h>
#include <TCanvas.h>
#include
#include
#include

using namespace std;

void fsigma()
{
string title =“TotRunHistos.root”;
const Char_t *direction =“theta0”;

TFile *myfile =TFile::Open(title.c_str());
TTree t1=(TTree)myfile->Get(direction);

/* Float_t maxX =(Float_t)t1->GetMaximum(“energytree”)+0.5e+10;
Float_t maxY =(Float_t)t1->GetMaximum(“sigma”)+7;*/

TCanvas *c2 =new TCanvas();

t1->Draw(“sigma:energy>>histo”,"",“lp”);
TH2D *histo =(TH2D *)myfile->Get(“histo”);//data are double
ostringstream histotitle;

histotitle<<“mu “<<direction<<” su faccia superiore (compresi eventi con 0 fotoelettroni)”;
histo->SetTitle(histotitle.str().c_str());

histo->GetXaxis()->SetTitle(“Energia[eV]”);
histo->GetYaxis()->SetTitle("#sigma_{npe}");

histo->SetMarkerColor(2);
histo->SetMarkerStyle(20);
histo->SetMarkerSize(0.4);

histo->Draw(“lsame”);

c2->SetGrid();
c2->Modified();

/delete c2;
delete histo;
delete myfile;
/
}
[/code]

compiled under root with and then launched with

 .L AmirSigma.cc+
 fsigma()

why i get this histo and not what i desire (labels,grid, red points joined with a line)?

Thank you very much
Amir
AmirSigma.tar.gz (20 KB)

You can choose one of teh two solutions below

Solution1

[code]void fsigma()
{
string title =“TotRunHistos.root”;
const Char_t *direction =“theta0”;

TFile *myfile =TFile::Open(title.c_str());
TTree t1=(TTree)myfile->Get(direction);

TCanvas *c2 =new TCanvas();
c2->SetGrid();

t1->Draw(“sigma:energy>>histo”,"",“goff”);
TH2D *histo =(TH2D *)myfile->Get(“histo”);
ostringstream histotitle;

histotitle<<“mu “<<direction<<” su faccia superiore (compresi eventi con 0 fotoelettroni)”;
histo->SetTitle(histotitle.str().c_str());
histo->GetXaxis()->SetTitle(“Energia[eV]”);
histo->GetYaxis()->SetTitle("#sigma_{npe}");
histo->SetMarkerColor(2);
histo->SetMarkerStyle(20);
histo->SetMarkerSize(0.4);

t1->Draw(“sigma:energy>>histo”,"",“lp”);
t1->Draw(“sigma:energy>>histo”,"",“l same”);
} [/code]

Solution 2

[code]void fsigma()
{
string title =“TotRunHistos.root”;
const Char_t *direction =“theta0”;

TFile *myfile =TFile::Open(title.c_str());
TTree t1=(TTree)myfile->Get(direction);

TCanvas *c2 =new TCanvas();
c2->SetGrid();

ostringstream histotitle;
histotitle<<“mu “<<direction<<” su faccia superiore (compresi eventi con 0 fotoelettroni)”;
TH2F *histo = new TH2F(“histo”,histotitle.str().c_str(),20,0,1e10,20,12,34);
histo->GetXaxis()->SetTitle(“Energia[eV]”);
histo->GetYaxis()->SetTitle("#sigma_{npe}");
histo->SetMarkerColor(2);
histo->SetMarkerStyle(20);
histo->SetMarkerSize(0.4);
t1->Draw(“sigma:energy>>histo”,"",“p”);
t1->Draw(“sigma:energy>>histo”,"",“l same”);
} [/code]

Rene

Thank you Rene for the quick reply.

I tryed to use both your solutions, but i get strange histos.

c1.jpg i used solution 1
c2.jpg i used solution 2

they are almost the same. what is strange is the fact that while the line shows the right points, the red markers are misplaced.

Do you know why this happens? i ran the script with ROOT 3.10 and also with ROOT 5.02 with the same results.

Amir



Solved. :smiley:

i ran this under ROOT 5.02

void fsigma()
{
string title ="TotRunHistos.root";
const Char_t *direction ="theta0";

  TFile *myfile =TFile::Open(title.c_str());
  TTree *t1=(TTree*)myfile->Get(direction);
      
      TCanvas *c1 =new TCanvas();
      
   Float_t maxX =(Float_t)t1->GetMaximum("energytree")+0.5e+10;
   Float_t maxY =(Float_t)t1->GetMaximum("sigma")+7;

   TH1 *htemp = new TH2F("htemp","mu theta0 (compresi eventi con 0 fotoelettroni)",40,0,maxX,40,0,maxY);
   htemp->SetDirectory(0);
   htemp->SetStats(0);
   htemp->GetXaxis()->SetTitle("Energia[eV]");
   htemp->GetYaxis()->SetTitle("#sigma_{npe}");
   htemp->Draw("");
   
   t1->SetMarkerColor(2);
   t1->SetMarkerStyle(20);
   t1->SetMarkerSize(0.4); 
   
   t1->Draw("sigma:energy>>htemp","","lpsame");
     
   c1->SetGrid();
   c1->Modified();
}   

Amir