Help needed with plotting a graph (cern ROOT)

Click For 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!
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 0 ·
Replies
0
Views
626
  • · Replies 0 ·
Replies
0
Views
656
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 1 ·
Replies
1
Views
2K
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