- #1
lavster
- 217
- 0
Homework Statement
i have drawn a graph in C++/root which is a bunch of points (in an array) joined together ie it is not a function. it looks kind of like a gauss, but isn't ie its a peak. i want to find out the x distance between the points of 90% and 20% of the maximum. i am having difficulty finding how from knowing the value of y to obtain the corresponding x value of eg the 90% level. I can do it from clicking on the graph but i want to write some code to find it and print it on screen using the cout thingy
Homework Equations
The Attempt at a Solution
my array is called Es[]. to find the maximum value i have made a for loop;
Code:
float max = 0;
max=Es[0];
for(int n=0; n<40; n++)
{
if(Es[n]>max)
max=Es[n];
}
cout << "max value of energy deposited =" << max << "MeV" <<endl;
so i know what the y value is. I have no idea how to get the corresponding x value.
by graph is defined as so:
Code:
TGraph *g =new TGraph(h->GetNbinsX());//defining a graph
g->SetTitle("hi");
cout << "hello" << endl;
float graphPointNumber=0;//where we are
cout << "salut" << endl;
for(int m=1; m<=h->GetNbinsX();m++)
{
cout << "hi" << endl;
cout << "m="<< m << endl;
g->SetPoint(graphPointNumber,h->GetBinCenter(m),Es[m]);
graphPointNumber++;
cout << "value =" << Es[m] << "MeV" << endl;
}
can anyone tell me how to do this please?
thanks