Help needed with plotting a graph (cern ROOT)

Click For Summary
SUMMARY

The discussion focuses on plotting 2D histograms using CERN ROOT, specifically transitioning from a 3D surface plot to a continuous line representation with TGraph. The user attempts to define a histogram and TGraph, implementing a loop to integrate bin contents but encounters multiple errors and confusion regarding the inclusion of the y variable. The proposed solution involves using g->Draw("ACP") for rendering, but the user expresses doubt about achieving the desired output. Clarification on integrating both x and y variables in the graphing process is sought.

PREREQUISITES
  • CERN ROOT framework for data analysis
  • Understanding of 2D histograms and TGraphs
  • Basic programming skills in C++
  • Knowledge of histogram binning and integration techniques
NEXT STEPS
  • Explore CERN ROOT documentation on TGraph and TGraph2D
  • Learn about integrating multiple variables in histogram plotting
  • Study examples of using g->Draw() with different options in ROOT
  • Investigate error handling in C++ for ROOT applications
USEFUL FOR

This discussion is beneficial for data analysts, physicists, and software developers working with CERN ROOT who need to visualize multidimensional data effectively.

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!
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
22
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K