PDA

View Full Version : help needed with plotting a graph (cern ROOT)


lavster
Nov5-10, 10:42 AM
ive been plotting 2D histograms (x vs y). when plotting using Draw->("surf"). it gives a 3D plot, showing the varying number of "hits" in each bin. I want to draw a TGraph which represents this so when drawing x vs y using Tgraph it gives a continous line instead of a bunch of dots. Ive got very confused reading the documentation on this. Does anyone have any ideas?

my first thought was:

define the histogram and TGraph (or perhaps TGraph2D ????)

write some code, perhaps something like:

double currIntegral= 0;//defining new variable "currIntegral" to be zero
int graphPointNumber=0;//where we are
for(int i=hxpre->GetNbinsX(); i>=1;i++)//for loop; adding from left.i=0 is an underflow bin
{ currIntegral=currIntegral+h->GetBinContent(i);//integration
g->SetPoint(graphPointNumber,h->GetBinCenter(i),currIntegral/number);
graphPointNumber++;//keeping track of the where we are
}

define the canvas and draw like you do with hist but with g->Draw("ACP") instead of g->Draw();

Apart from giving me mulitple errors, this only involves the x variable; all values of y variable are ignored. Im also very doubtful this is going to plot what i want it to plot :(

Am i going about it the right way? and how do you go from using just x variable to using the y variable also?

any ideas will be very useful!!

Thanks

lavster
Nov5-10, 07:02 PM
im going to try and do it a different way - this way confuses me!!