While I fear I may be overlooking some basic concept, I have a problem with the TGraph originating from tree.Draw() - see attached code for the basic structure of what I’m trying to do. The code worked fine at first… and then, without changing anything, it started not displaying the plots.
TTree *tree = new TTree("tree","tree"); tree->Branch("branchName1",&branchName1); [...] tree->Branch("branchNameN",&branchNameN); std::ifstream file1; string input="some_file.txt"; file1.open(input.c_str(),ios::in); file1 >> branchName1 >> ... >> branchNameN; TCanvas *c1 = new TCanvas("c1","c1",700,500); tree->Draw("branchNameX:branchNameY"); // Plotting routines here are held in a dedicated plotting function, but it's a simple plotMe(double a, double b) TGraph *graph = (TGraph*)gPad->GetPrimitive("Graph"); TH2F *htemp = (TH2F*)gPad->GetPrimitive("htemp"); htemp->GetXaxis()->SetTitle("xxxxx"); htemp->GetYaxis()->SetTitle("YYYY"); graph->SetMarkerColor(kBlue); // End of plotting routine // End of main
The error that keeps appearing is related to the instructions I have inside my plotting function, which themselves relate to gPad->GetPrimitive. As far as I understand, to change the X/Y axis labels and the colors in the plot, I need to go use those functions if I’m creating the plots with TTree::Draw(). I’m guessing some kind of (memory?) problem comes from there, but I have run out of ideas on how to solve it. Here’s the actual error message:
Warning in <TCanvas::ResizePad>: c2 width changed from 0 to 10
Also, I don’t know if it’s a runaway consequence of the above, but: each time I run it afresh (it has some trivial iterative conditions to choose from different cases, but always with the same aforementioned structure - the point is I can run it more than once until I choose to exit it), it outputs before plotting: (void)1.
I tried it with ROOT v. 5.34/18 and 5.20/00.
I have seen a similar issue discussed back in 2002, and tried re-compiling ROOT. It worked (!) for a while, but now it has stopped working at all. Another way I “solved” it and then stopped working was changing the way I had defined the tree (TTree tree(“tree”,“tree”)->Gave problems; vs TTree *tree = new TTree(“tree”,“tree”)->Didn’t give problems) and calling it through tree->DoSomething instead of tree.DoSomething .
Thank you in advance for any help on this you might bring!