I want to draw a histogram from a directory inside the root file


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi root experts !
I have one root file, inside it there is a directory named “noise_ADCunits”. I want to draw the histogram(noiseADC_3.1.1.V) saved inside that directory. So, tried with the following macro :

void svd()
{
TFile *f = new TFile("/home/souvik/svd/02627/beam.0003.02627.HLT2.f00000.root");
f->cd("noise_ADCunits");
f->Draw("noiseADC_3.1.1.V");
}

Code is running, but I am not getting any plot.
Please suggest me what to do.
Thanks

If your histogram is a TH1F try:

void svd()
{
TFile *f = new TFile("/home/souvik/svd/02627/beam.0003.02627.HLT2.f00000.root");
f->cd("noise_ADCunits");
TH1F *h = (TH1F*)f->Get("noiseADC_3.1.1.V");
h->Draw();
}

You can also do directly histogram_name->Draw()after the cd() but in your case the histogram name contains dots and that might not work (not valid c++)

Thanks for the reply. But this time I am getting the following error.

Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
warning: null passed to a callee that requires a non-null argument [-Wnonnull]
h->Draw();

I think the code should look like this:

void svd()
{
TFile *f = new TFile("/home/souvik/svd/02627/beam.0003.02627.HLT2.f00000.root");
f->cd("noise_ADCunits");
TH1F *h = (TH1F*)gDirectory->Get("noiseADC_3.1.1.V");
h->Draw();
}

f->cd(… doesnt modify f itself

Otto

oops sur… may be even simpler:

TFile *f = new TFile("/home/souvik/svd/02627/beam.0003.02627.HLT2.f00000.root");
TH1F *h = (TH1F*)f->Get("noise_ADCunits/noiseADC_3.1.1.V");
h->Draw();

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.