I would like to draw in one Canvas many graphs (lets say 15), but I don’t want to type for every graph the command
TGraph *gr1 = …
The data for each graph are held by an array[i=15][j=200]. So I would like for each i to draw a graph in the same Canvas. Is there a way to name the pointer (gr) differently for each graph using a loop??
Hello! I have the same situation. In my program I have to analyse 1000 files and access a branch from the tree and execute some code. In the end I have to represent the results in a histogram wich have to contain the data from all the 1000 files. The problem is that the program overwrites the same canvas until the last one.
Also it seems that hit is drawn in the method Paint() but it looks declared elsewhere in your code. Is it global ?
When you draw hit with the option hist it will overwrite the previous plots. If you want to have several histograms drawing on the same plot you should use the option same or use a THStack which might be better if you have 1000 histograms in order to compute the global range.
Note: I have re-formatted your post. It was impossible to see relay the code.
Very late reply here, but I’m never sure about the general practice of using new. The tool my collaboration has an event display (we generate plots for each event in the detector and iterate to the next event with a GUI so we can take a peek at each event) so for each event we need to clear the graphics.
Am I going to have an issue if I have something like what’s above in a function that iterates over each event?
Asked as a decision between two options:
If I have a function that runs for each event, should I:
I have calls to new i and inside this event-by-event function and ROOT will call do the relevant calls to ~TGraph at the end of the scope of that call to new?
Or should I have an array that holds all the TGraph*'s (or even TGraph’s) then populate them and add them to the TMultiGraph and draw it, then clear them with TGraph::Set(0)?
thanks for asking! If you add the TGraphs to the TMultiGraph via TMultiGraph::Add(), you have to create them with new but don’t delete them because the TMultiGraph will now take care of that (as explained in the linked documentation).