Help needed with plotting a graph (cern ROOT)

AI Thread Summary
The discussion centers on the challenge of plotting a continuous line representation of a 2D histogram using TGraph in a programming context. The user is attempting to create a TGraph that reflects the cumulative distribution of hits in each bin of a histogram, which is currently being visualized as a 3D plot through the "surf" option. They express confusion over the documentation and seek guidance on integrating both x and y variables in their plot. Initial thoughts include defining a histogram and TGraph (or TGraph2D) and writing a loop to calculate cumulative values for the x variable. However, the user encounters multiple errors and realizes that their current approach only considers the x variable, neglecting the y variable entirely. They express doubt about whether this method will yield the desired plot and are open to alternative suggestions, indicating a willingness to explore different approaches due to the confusion experienced with the current method.
lavster
Messages
213
Reaction score
0
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 continuous line instead of a bunch of dots. I've 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. I am 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
 
Technology news on Phys.org
im going to try and do it a different way - this way confuses me!
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Back
Top