Creating TH2F from another TH2F

Hi,

I’m working with a TH2F histogram that describes energies in KeV, and I want to new one with this information but in Grays. Already have the term that converts it, but I can not implement it.

When I run the macro a error occurs: invalid operands to binary expression (‘void’ and ‘double’)
Hg2-> SetBinContent (i, j) * 5.54267E-9;

This is the macro I created:

[code]{
gROOT -> Reset();
TFile f(“brachytherapy.root”);
TCanvas* c1 = new TCanvas(“c1”, " ");
TH2F* h20;
int nbinsx = h20 ->GetXaxis()->GetNbins();
int nbinsy = h20 ->GetYaxis()->GetNbins();
cout << “olha”<< nbinsx <<endl;
TH2F* hg2 = new TH2F(“hg2”,“Radiation Dose - Bone”,nbinsx,-100.125,100.125,nbinsy,-100.125,100.125);
for (int i=0;i <nbinsx;i++){
for (int j=0; j<=nbinsy;i++){
h20-> GetBinContent(i,j);
hg2-> SetBinContent(i,j)*5.54267E-9;
}
}

hg2 -> GetZaxis()->SetRangeUser(0.0,500);
hg2 -> GetZaxis()->SetTitle(" Dose (Gy)");

hg2 -> Draw(“colz”);
}
[/code]

Can you help me?

Hi,

if you do not have access to the entries, you can resort to this method root.cern.ch/doc/master/classTH … 56f5038e37
The idea would be to start from an empty histogram and add to it the one in KeV weighted so to have the z axis expressed in grays.

Cheers,
D

Hello,

Thanks for the answer.
I’m quite new in Root, this is my first example.
Can you tell me how “Add” works in a .C file?

Once looking at root.cern.ch/doc/master/classTH … 56f5038e37, this is a more of a c++ question.

myEmptyHisto.Add(&myFilledHistoInGeV, Gev2GrayFactor);

Cheers,
D

Change my code to:

[code]{
gROOT -> Reset();
TFile f(“brachytherapy.root”);
TCanvas* c1 = new TCanvas(“c1”, " ");
TH2F* h20;

TH2F* hg2 = new TH2F(“hg2”,“Radiation Dose - Bone”, 801 ,-100.125,100.125, 801,-100.125,100.125);
hg2 -> Add(h20,5.54267E-9);

hg2 -> GetZaxis()->SetRangeUser(0.0,500);
hg2 -> GetZaxis()->SetTitle(" Dose (Gy)");

hg2 -> Draw(“colz”);
}
[/code]

A error occours: Error in TH2F::Add: Attempt to add a non-existing histogram

When I use the instruction: h20 -> Draw(“colz”) on root , my original histogram appears.
What I’m doing wrong?

TFile f("brachytherapy.root"); TH2F *h20; f.GetObject("h20", h20); TH2F *hg2 = new TH2F(*h20); hg2->SetNameTitle("hg2", "Radiation Dose - Bone"); hg2->Sumw2(kTRUE); hg2->Scale(5.54267E-9);

Worked.

Thanks