Extracting the sum of the points ploted by TGraph

Hello, I am using TH1 as the base and the plot the line using TGraph.

Since I used TGraph to draw the line, I cannot use h-> GetSum() like this.

Is there any way to extract the data point and get the sum value automatically?

I enclose the portion of the code

double Norm = 23.14;
ifstream infile(“lead.data”);
for (int i=0; i<455; i++){
infile >> E1box1 >> E2box1 >> Ybox1 >> EYbox1;
EnergyBox1[i] = (E2box1+E1box1)/2;
eEnergyBox1[i] = 0;
FluenceBox1[i] = Norm
eFluenceBox1[i] = Norm0.01EYbox1Ybox1(E2box1-E1box1);
eFluenceBox1[i] << endl;

TGraph* lead = new TGraph(455,EnergyBox1,FluenceBox1);

You can use

Double *x = lead->GetX();
Double *y = lead->GetY();

Thank you. Is there anyway to get the sum value automatically? Like get sum from TH1

I do not think so. But once you get the y array, you just have to loop on it to calculate the sum.

std::cout << "lead sum X = " << lead->GetMean(1) * lead->GetN() << std::endl;
std::cout << "lead sum Y = " << lead->GetMean(2) * lead->GetN() << std::endl;
1 Like

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