Multiply TH1F by double from .root files

Hello,

I have a couple of .root files generated by GEANT4, and I need to normalize the histograms. The normalization factor is a double, which I defined on my code (Simulation_Factor). The question is, what is the easiest way to multiply my histograms so I can have my data normalized? I’m sure this is a trivial question, but sorry to say I’m stuck with it.

This is my code to call the histograms from the .root files:

void Fluorescent_Screens(){

double Simulation_Factor = 6.2e12;

TFile *YAG = new TFile(“build-SIRIUS-Desktop-Default/SIRIUS_YAG_20160120.root”);
TFile *Al2O3 = new TFile(“build-SIRIUS-Desktop-Default/SIRIUS_Cr_Alumina_20160120.root”);

TTree tree1 = (TTree)YAG->Get(“Mirror_Fluence_tuple_fluence_gamma”);
TTree tree2 = (TTree)Al2O3->Get(“Mirror_Fluence_tuple_fluence_gamma”);

tree1->Draw(“kine>>hist1”);
tree2->Draw(“kine>>hist2”);

TH1F *hist1 = gDirectory->Get(“hist1”);
TH1F *hist2 = gDirectory->Get(“hist2”);

TCanvas *c1 = new TCanvas(“c1”);
c1->SetFillColor(10);
c1->SetGrid();
c1->SetLogx();
c1->SetLogy();

hist1->SetTitle(“Fluorescent Screens Comparison”);
hist1->GetXaxis()->SetTitle(“Photon Energy[MeV]”);
hist1->GetYaxis()->SetTitle(“Photon Count”);

hist1->SetLineColor(4);
hist1->SetLineWidth(2);
hist1->Draw();

hist2->SetLineColor(2);
hist2->SetLineWidth(2);
hist2->Draw(“Same”);

leg = new TLegend(0.1,0.7,0.3,0.9);
leg->SetFillColor(0);
leg->AddEntry(hist1,“Ce doped YAG”,“l”);
leg->AddEntry(hist2,“Cr doped Al2O3”,“l”);
leg->Draw();
}

Thanks a lot!
Leonardo.

Ok,

I found it myself, and should have searched more before posting the question. :confused:

On the code, after:

TH1F *hist1 = gDirectory->Get(“hist1”);
TH1F *hist2 = gDirectory->Get(“hist2”);

I just added the following lines:

hist1->Scale(Simulation_Factor);
hist2->Scale(Simulation_Factor);

And the results are now normalized.

Thank you anyway!

Best Regards.
Leonardo

Dear Leonardo,

TH1 provides Multiply and Divide methods. For example, if I have understood your problem correctly, this may be what you are looking for:

root.cern.ch/doc/master/classTH … 3c944a4dd2

G Ganis