I am stuck at a step which I am pretty sure must have a straightforward fix. I have tried a few things and I am not sure what to do.
I have multiple graphs. I want to draw all these graphs in a single plot with an offset on Y-axis, such that every plot has a shift in Y-axis. This is what I did -
TGraph *gr2 = new TGraph ();
TCanvas *cgr2=new TCanvas(“cgr2”,“cExcitation Energy Spectrum 126”);
gr2->Draw();
…
TMultiGraph *mg = new TMultiGraph();
TCanvas *cmg=new TCanvas(“cmg”," Excitation Energy Spectrum all data stacked");
mg->Add(grdisk118);
mg->Add(grdisk126);
…
This does not work and gives me an error- error in tgraphpainter::paintgraph: illegal number of points (0).
Can anyone suggest anything as to how to approach this? I want something that looks like the attached pdf. Stacked plots-Logscale_1000bins.pdf (219.8 KB)
Please help! Thank you for your time!
ROOT Version: 6.18/04 Platform: C++ Compiler: Visual Studio Code
Hi @couet and @Wile_E_Coyote, Thank you for getting back. Here is a code that will run. I am also attaching the .root files because I am plotting .root files.
Also, I tried to plot the same plot in graph and as histogram. What I don’t understand is when I plot the histogram, everything lines up exactly (still having trouble with offset though), but when I plot as graph, there is slight shift in each data. Is that something that has to do with how THStack and multigraph works or is it some error in my code?
Can anyone please comment? Thank you for your time! Please help!
Hi @couet,
Thank you for getting back. So what I am saying is, this is stack histogram where different data sets are stacked. IN this plot, (the one you attached), all the peaks are perfectly aligned.
However, when I plot a multigraph using the same data, all the peaks are slightly shifted towards right from top to bottom(see attachment).
My question is there a reason why the histograms are aligned and graphs are shifted along x axis despite being the same data?
Do you think you can help? Any help is appreciated! Thank you for your time
P.S - Please ignore the offset in yaxis. I want to plot all the data with an offset in Y. For some reason, the offset is not getting plotted for the histogram but works for graphs.
Thank you for getting back @couet and @Wile_E_Coyote. I just had one more question. What does it mean by the histogram and graph “not calibrated”?
Could you please suggest to me where to look for how to do a calibration? Thank you so much for your time and help!
I really appreciate it!
The positions of peaks in your different graphs / histograms do not “coincide”.
Well, we assume that their “x” positions should be the same in all graphs / histograms, but maybe not, as it depends on “physics”.
So, we think that you probably need to “scale” the x-axes values of them (i.e., “calibrate” the x-axes of your graphs / histograms from “raw” numbers to “energy”).
You need to discuss it with the one who gave you this data.