Help needed with plotting a graph (cern ROOT)

In summary, the conversation discusses plotting 2D histograms using Draw->("surf") and the desire to draw a TGraph that represents the same data as a continuous line instead of a scatter plot. The conversation also includes a suggested code for achieving this and a doubt about how to incorporate the y variable into the plot. The conversation concludes with the individual deciding to try a different approach to achieve their desired result.
  • #1
lavster
217
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
  • #2
im going to try and do it a different way - this way confuses me!
 

1. How do I plot a graph using CERN ROOT?

To plot a graph using CERN ROOT, you will need to use the TGraph class. First, create an instance of the TGraph class and specify the number of points you want to plot. Then, use the SetPoint() function to set the x and y values for each point. Finally, use the Draw() function to draw the graph on a canvas.

2. Can I customize the appearance of my graph in CERN ROOT?

Yes, you can customize the appearance of your graph in CERN ROOT. You can use the SetLineColor(), SetLineWidth(), SetLineStyle(), and SetMarkerStyle() functions to change the color, width, and style of the lines and markers in your graph. Additionally, you can use the SetTitle() function to add a title to your graph and the SetAxisRange() function to specify the range of values to be displayed on the x and y axes.

3. How can I save my graph as an image in CERN ROOT?

To save your graph as an image in CERN ROOT, you can use the SaveAs() function. This function allows you to save your graph in various formats such as PNG, JPG, and PDF. You can also specify the file name and directory where you want to save the image.

4. Is it possible to plot multiple graphs in the same canvas using CERN ROOT?

Yes, it is possible to plot multiple graphs in the same canvas using CERN ROOT. You can use the TMultiGraph class to create a canvas that can hold multiple graphs. Then, you can use the Add() function to add each graph to the TMultiGraph canvas. This will allow you to display all the graphs in the same canvas.

5. How do I add error bars to my graph in CERN ROOT?

To add error bars to your graph in CERN ROOT, you can use the SetPointError() function. This function takes three arguments: the index of the point, the error on the x-axis, and the error on the y-axis. You can also customize the appearance of the error bars using the SetErrorX(), SetErrorY(), and SetMarkerSize() functions.

Similar threads

  • Programming and Computer Science
Replies
1
Views
11K
  • Programming and Computer Science
Replies
22
Views
3K
  • General Math
Replies
7
Views
1K
Replies
1
Views
1K
  • Precalculus Mathematics Homework Help
Replies
11
Views
2K
  • Programming and Computer Science
Replies
1
Views
846
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Advanced Physics Homework Help
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top