It’s a bit tricky. independent_variables (and dependent_variables) contains four dictionaries, one for each cut of invariant mass of a l+l- system. This dictionaries contain the cross-section for different Wilson coefficients for a given invariant mass. So for a given dict, when I do dict[key] I get all the values of the cross-section as one Wilson coefficient varies for a given invariant mass cut. The idea is to represent this cross-sections variations for each invariant mass cut, putting one graph next to the other.
So, for a given key (a given Wilson coefficient), the z runs over the number of cuts in invariant mass, it goes from 0 to 3 and I extract the values of the cross-sections. Because of the TCanvas.cd starts at 1, I need z+1 to get the right pad.
If I put the c1.cd(z+1) where you say, nothing changes.
I mean without the necessity of storing all the graph in an array (your solution) or in a dict (my solution). I think that this would be inefficient if we work with many many graphs and more complicated.
In C++ you can also avoid using an array of TGraph. The pointer to the graphs 0, 1 and 3 are lost at the end of the loop. But the graphs still exist in memory and are properly drawn. The memory comsomption is the same:
void acgc99() {
TGraph *g;
Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
Double_t y[10] = {1,2,3,4,5,5,4,3,2,1};
auto C = new TCanvas();
C->Divide(4,1);
for (int i=0; i<4; i++) {
g = new TGraph(10, x, y);
g->SetTitle(Form("GRAPH %d",i));
C->cd(i+1);
g->Draw("AL");
}
}
It is not the graphs which were stored in memory in my previous example. It was the pointers to the graphs … so, nothing … The graphs are in memory in both example. That’s what uses memory.