Some (stupid) ROOT file questions

Hi,

I know that my questions have already been answered tons of times, however I’m just stuck again and I don’t know why…

  1. I’m reading in some histograms from a root tuple, transform them into TGraphAsymmErrors and I want to write them back out into a new ROOT file. My code basically looks like:

[code]TCanvas *c1 = new TCanvas(“c1”,“c1”,700,400);

TFile *input = new TFile(“presel3.root”);
TPostScript *hist = new TPostScript(“turnon.ps”);
TFile *target = TFile::Open( “turnon.root”, “RECREATE” );
for(int k=0;k<20;++k) {
TGraphAsymmErrors *gr = new TGraphAsymmErrors(nbins,x,y,exl,exh,eyl,eyh);
…do some stuff…
gr->Draw(“AP z”);
c1->Update();
gr->Write();
hist->NewPage();
}
target->Close();
hist->Write();
hist->Close();[/code]

Unfortunately the new root file (“turnon.root”) just contains objects like Graph1, Graph2, etc. which are all empty (execpt for the statistics box). What do I have to change to make it work?

  1. I’m trying to set the name of the above already mentioned TGraphAsymmErrors correctly, however I just doesn’t seem to work:
TGraphAsymmErrors *gr = new TGraphAsymmErrors(nbins,x,y,exl,exh,eyl,eyh);
TString *name = new TString(sht20_seta->GetTitle());
cout << *name<<endl;
gr->SetTitle(*name);

In the for loop the name goes like “A_0”, “A_1”, “A_2” etc. This is verified by the cout statement. However in the generated PS file the name is just “A_0”. Why doesn’t SetTitle doesn’t set the title correctly?

Cheers,
Carsten

Hi Carsten,

Can you send the complete code that actually set. The interlacing of loops, assignment and drawing is important?

Philippe.

Hi Philippe,

thanks for taking your time and looking into this. Attached you’ll find the whole cpp code I’m using and the input file “presel.root”.
To compile do:
[ul]gzip -d effic_cn.tar.gz[/ul]

The program is started with:
[ul]exec[/ul]

The relevant source code with the main function is in “calceff.cpp”.

Cheers,
Carsten
effic_cn.tar (539 KB)

Hi,

I can’t built or execute you example (missing SoftRelTools and different version of ROOT) and I can not find the code you mentioned.

All I found was:

which should simply be

Philippe.

Hi Philippe,

Sorry I forgot to mention that the compilation is done by:
[ul]make -f Makefile[/ul]
Then you shouldn’t get any warnings/error messages.

I’ve tried to and replaced gr->GetHistogram()->SetTitle(sht20_seta->GetTitle());
by gr->SetTitle(sht20_seta->GetTitle());
However that doesn’t change anything. I guess that something with the drawing order (and how the TGraphs are written out to the file(s)) is wrong…

Cheers,
Carsten

Hi Carsten,
works for me. After running the binary I open turnon.root, and run Graph.Draw(“al”) - and I can see your graph. I get the error msg
Error in TPostScript::Write: No file open
when running your binary, though - but that’s a different issue.
Axel.

Hi Carsten,

In your file calceff.cpp you can
-either give a different key name when you write your graphs with
gr->Write(“gr1”);
-or better give a name to your graphs after the constructor, call eg
gr->SetName(Form(“gr%d”,k));
This will give names (in the loop) like gr0, gr1, gr2

Rene

Hi Rene,

I did as you suggested and gave a name to the graphs right after the constructor:

The resulting root file contains 3 graphs in the form gr0, gr1, gr2. However drawing them just shows the statistics box and not the fitted graph. Since the fitted graph is shown correctly in the eps file I’m wondering what’s going wrong.

Cheers,
Carsten

Hi Axel,

I have trouble reproducing you suggestions. Sometimes it works, sometimes it doesn’t. Anyway I want to have all graphs accessible (exactly as they appear in the eps file) via TBrowser.

Cheers,
Carsten

Hi Carsten,
the point is: you have to name the graphs, but you can’t just call TGraph::Draw. You’ll have to call it with an option (“AL”). Only then you’ll see the graphs with axes. You can check that your (properly named, see Rene’s posting) graphs are really non-empty by calling TGraph::Print() (e.g. gr1->Print()).
Axel.

Hi Alex,

thanks for pointing that out, that was indeed the culprit. I wasn’t aware that I should have done gr0->Draw(“AP z”) and not just double clicking on the name within TBrowser. For some reason I’ve assumned that it works like histograms. The only remaing “feature” is that the background is not set to “Plain”, but I guess I have to do that in the root session.

Cheers,
Carsten

Hi Carsten,

You can set options like “ap” , “apl”, “ac”, etc your default when browsing
by adding the following line in your $ROOTSYS/etc/system.rootrc file

TGraph.BrowseOption : ap

Rene