Matching histograms

Hello,

I have to match two histograms, i.e. compress/stretch (by rebinning) and rescale the second histogram such that it matches to the first one in a certain bin range. This is a pretty standard task, for example when you want to normalize an MC simulation to an experimental distribution. Unfortunately, I did not find a ‘ready-made’ solution for that in ROOT, like for fitting functions to histograms. However, I am a novice …

I would be glad for any hints.

Cheers

Ralf

Hello Ralf,
There are methods Rebin and Scale from the TH1 class.

Please Sir, I need your help.
I am a beginner in programming and I have a problem in ROOT:

I want to build a histogram from a text file containing the following data:

-----> 3 columns and 1000 lines: 1st column = x of voxel
2nd column = y of voxel
3rd column = voxel energy

I constructed a 2D histogram with binning: 100 in x and 100 in y,

We want to find the voxels contained in each bin of the histo and that it is the total energy of this bin

Here is my code: I was able to know the number of voxels in each bin with GetBinContent, but the energy either

Please help me calculate this resulting energy

part of my code:
TH2F* h1 = new TH2F(“h1”, “z en fct de x”, 100, -262, 262, 100, -250, 250);
ifstream fichier(“RESULTAT.ascii”);
for (int j = 0; j < 1000; j++)

 {

fichier >> x[j];
fichier >> z[j];
fichier >> E[j];

h1->Fill(z[j],x[j]);

}
int A ;

for (int i=1 ;i<=100;i++) {
for (int j=1 ;j<=100;j++ )

  {    

A=h1->GetBinContent (i,j);
cout << A<< endl;
std::ofstream file(" bin.txt",std::ios_base::out | std::ios_base::app);
file << “i “<< i<< " j “<< j<<” A “<< A <<” E(”<<i<<”,"<<j<<")="<<E[i,j]<<endl;

}

}
gStyle->SetPalette(55);//:niveau de gris=52
h1->Draw(“colz”);

h1->Fill(z[j], x[j], E[j]);