You anyhow go through an “intermediate” histogram so maybe use its integral.
Otherwisse, you would need to create a TF2 from your 2D graph and integrate this new function.
An example of a TF1 created from a 1D graph can be found in: “Integral of TGraph”
In the following macro, is there any problem? I am getting empty histogram with non-zero entries with TH1D range 1,0,1. But, if I make it 10,0,1, it is plotting, which I do not want. I know that the bin widths are not exactly same. I want to have range 0 to 1 only. And I do not want to use TGraph as there is problem of normalising it. Any idea?
FILE *f1;
double col1[22],col2[22],col3[22];
f1=fopen("data.txt","r");
for (int i = 0; i < 22; ++i )
{
fscanf(f1,"%lf %lf %lf",&col1[i],&col2[i],&col3[i]);
}
auto hist0=new TH1D("hist0","hist0",1,0,1);
for (int k=0; k<=22; k++) {
hist0->Fill(col1[k],col2[k]);
int bin = hist0->GetXaxis()->FindBin(col1[k]);
hist0->SetBinError(bin,col3[k]);
}
hist0->Draw("E1");
gPad->Update();
fclose(f1);
But, The problem with it is, it changes the bin centers. I want the points to be exactly at where the data are. And if I want to keep the bin width to be same as is in original data.
What to do then?
I was trying to be closer to the original macro. Of course I know your suggestion. But lets imagine @Sandy wants to manipulate the vectors before filling the graph then the way I did it is better. At least the two solutions are on the table now. Thanks for your input.
In the case of histograms the errors bars are drawn at the bin center. So it will never be the exact position. Graph are doing that. If you create the histogram with many bins it should be close though (try 1000).
Also, as you have the vectors, you can “normalise” them as you wish before putting them in the TGraph.