Hi, I've been using the very useful feature of root to save C macros of canvases but have run into some problems. I'm using root_4_01_02 compiled from source on suse linux. I attach 2 files: 1.) mProf.C (code I wrote to make canvas "cTest") 2.) cTest.C (root produced code when saving "cTest.C") These are the problems: 1.) Changing the label size of TPaletteAxis does not get propagated to the canvas automatically - I have to draw again. 2.) The palette label size does not get stored in cTest.C when I click on the item under "save" in the "File" menu. 3.) Changing the Ndivisions on the palette doesn't work using: palette3->GetAxis()->SetNdivisions(3); 4.) When I save cTest.C I get "ClassName()" instead of "TProfile2D" as the type of my profile histograms - hence macro wont run! 5.) The TLegend I created does not have its FillColor saved in cTest.C. Is there anyway for root to propagate the "gStyle->SetPalette" that was in use when the C macro was saved - I always have to go in and change it by hand. Thanks for your help, Jeff. -- ******************************************** Jeffrey Hartnell, Oxford/RAL DPhil student. Phone numbers, addresses, etc on website: http://www-pnp.physics.ox.ac.uk/~hartnell/ ******************************************** { //=========Macro generated from canvas: cTest/cTest //========= (Thu Nov 25 22:23:43 2004) by ROOT version4.01/02 TCanvas *cTest = new TCanvas("cTest", "cTest",4,22,800,600); cTest->Range(0,0,1,1); cTest->SetFillColor(0); cTest->SetBorderSize(2); // ------------>Primitives in pad: cTest_1 TPad *cTest_1 = new TPad("cTest_1", "cTest_1",0.01,0.51,0.49,0.99); cTest_1->Draw(); cTest_1->cd(); cTest_1->Range(-10,-6.75,70,30.75); cTest_1->SetFillColor(0); cTest_1->SetBorderSize(2); ClassName() *pStVsPlWin = new TProfile2D("pStVsPlWin","I was redrawn to get big label on palette",64,-2,62,30,-3,27,0,0); pStVsPlWin->SetBinEntries(1272,1); pStVsPlWin->SetBinEntries(1597,1); pStVsPlWin->SetBinContent(1272,200); pStVsPlWin->SetBinContent(1597,100); pStVsPlWin->SetBinError(1272,200); pStVsPlWin->SetBinError(1597,100); pStVsPlWin->SetEntries(2); pStVsPlWin->SetContour(20); pStVsPlWin->SetContourLevel(0,0); pStVsPlWin->SetContourLevel(1,10); pStVsPlWin->SetContourLevel(2,20); pStVsPlWin->SetContourLevel(3,30); pStVsPlWin->SetContourLevel(4,40); pStVsPlWin->SetContourLevel(5,50); pStVsPlWin->SetContourLevel(6,60); pStVsPlWin->SetContourLevel(7,70); pStVsPlWin->SetContourLevel(8,80); pStVsPlWin->SetContourLevel(9,90); pStVsPlWin->SetContourLevel(10,100); pStVsPlWin->SetContourLevel(11,110); pStVsPlWin->SetContourLevel(12,120); pStVsPlWin->SetContourLevel(13,130); pStVsPlWin->SetContourLevel(14,140); pStVsPlWin->SetContourLevel(15,150); pStVsPlWin->SetContourLevel(16,160); pStVsPlWin->SetContourLevel(17,170); pStVsPlWin->SetContourLevel(18,180); pStVsPlWin->SetContourLevel(19,190); TPaveStats *ptstats = new TPaveStats(0.78,0.755,0.98,0.995,"brNDC"); ptstats->SetName("stats"); ptstats->SetBorderSize(2); ptstats->SetFillColor(19); ptstats->SetTextAlign(12); TText *text = ptstats->AddText("pStVsPlWin"); text->SetTextSize(0.0368); text = ptstats->AddText("Entries = 2 "); text = ptstats->AddText("Mean x = 13"); text = ptstats->AddText("Mean y = 18"); text = ptstats->AddText("RMS x = 2.5"); text = ptstats->AddText("RMS y = 2.5"); ptstats->Draw(); pStVsPlWin->GetListOfFunctions()->Add(ptstats); ptstats->SetParent(pStVsPlWin->GetListOfFunctions()); pStVsPlWin->GetXaxis()->SetTitle("Plane"); pStVsPlWin->GetXaxis()->CenterTitle(true); pStVsPlWin->GetYaxis()->SetTitle("Strip"); pStVsPlWin->GetYaxis()->CenterTitle(true); pStVsPlWin->Draw("colz"); TPaveText *pt = new TPaveText(0.01,0.938182,0.673844,0.995,"blNDC"); pt->SetName("title"); pt->SetBorderSize(2); pt->SetFillColor(19); text = pt->AddText("I was redrawn to get big label on palette"); pt->Draw(); cTest_1->Modified(); cTest->cd(); // ------------>Primitives in pad: cTest_2 cTest_2 = new TPad("cTest_2", "cTest_2",0.51,0.51,0.99,0.99); cTest_2->Draw(); cTest_2->cd(); cTest_2->Range(-10,-6.75,70,30.75); cTest_2->SetFillColor(0); cTest_2->SetBorderSize(2); ClassName() *pStVsPlWin2 = new TProfile2D("pStVsPlWin2","You have to click on me to make my palette label size increase",64,-2,62,30,-3,27,0,0); pStVsPlWin2->SetBinEntries(1272,1); pStVsPlWin2->SetBinEntries(1597,1); pStVsPlWin2->SetBinContent(1272,200); pStVsPlWin2->SetBinContent(1597,100); pStVsPlWin2->SetBinError(1272,200); pStVsPlWin2->SetBinError(1597,100); pStVsPlWin2->SetEntries(2); pStVsPlWin2->SetContour(20); pStVsPlWin2->SetContourLevel(0,0); pStVsPlWin2->SetContourLevel(1,10); pStVsPlWin2->SetContourLevel(2,20); pStVsPlWin2->SetContourLevel(3,30); pStVsPlWin2->SetContourLevel(4,40); pStVsPlWin2->SetContourLevel(5,50); pStVsPlWin2->SetContourLevel(6,60); pStVsPlWin2->SetContourLevel(7,70); pStVsPlWin2->SetContourLevel(8,80); pStVsPlWin2->SetContourLevel(9,90); pStVsPlWin2->SetContourLevel(10,100); pStVsPlWin2->SetContourLevel(11,110); pStVsPlWin2->SetContourLevel(12,120); pStVsPlWin2->SetContourLevel(13,130); pStVsPlWin2->SetContourLevel(14,140); pStVsPlWin2->SetContourLevel(15,150); pStVsPlWin2->SetContourLevel(16,160); pStVsPlWin2->SetContourLevel(17,170); pStVsPlWin2->SetContourLevel(18,180); pStVsPlWin2->SetContourLevel(19,190); ptstats = new TPaveStats(0.78,0.755,0.98,0.995,"brNDC"); ptstats->SetName("stats"); ptstats->SetBorderSize(2); ptstats->SetFillColor(19); ptstats->SetTextAlign(12); text = ptstats->AddText("pStVsPlWin2"); text->SetTextSize(0.0368); text = ptstats->AddText("Entries = 2 "); text = ptstats->AddText("Mean x = 13"); text = ptstats->AddText("Mean y = 18"); text = ptstats->AddText("RMS x = 2.5"); text = ptstats->AddText("RMS y = 2.5"); ptstats->Draw(); pStVsPlWin2->GetListOfFunctions()->Add(ptstats); ptstats->SetParent(pStVsPlWin2->GetListOfFunctions()); pStVsPlWin2->GetXaxis()->SetTitle("Plane"); pStVsPlWin2->GetXaxis()->CenterTitle(true); pStVsPlWin2->GetYaxis()->SetTitle("Strip"); pStVsPlWin2->GetYaxis()->CenterTitle(true); pStVsPlWin2->Draw("colz"); pt = new TPaveText(0.01,0.938182,0.71,0.995,"blNDC"); pt->SetName("title"); pt->SetBorderSize(2); pt->SetFillColor(19); text = pt->AddText("You have to click on me to make my palette label size increase"); pt->Draw(); cTest_2->Modified(); cTest->cd(); // ------------>Primitives in pad: cTest_3 cTest_3 = new TPad("cTest_3", "cTest_3",0.01,0.01,0.49,0.49); cTest_3->Draw(); cTest_3->cd(); cTest_3->Range(-10,-6.75,70,30.75); cTest_3->SetFillColor(0); cTest_3->SetBorderSize(2); ClassName() *pStVsPlWin3 = new TProfile2D("pStVsPlWin3","I don't have 3 divisions on my palette",64,-2,62,30,-3,27,0,0); pStVsPlWin3->SetBinEntries(1272,1); pStVsPlWin3->SetBinEntries(1597,1); pStVsPlWin3->SetBinContent(1272,200); pStVsPlWin3->SetBinContent(1597,100); pStVsPlWin3->SetBinError(1272,200); pStVsPlWin3->SetBinError(1597,100); pStVsPlWin3->SetEntries(2); pStVsPlWin3->SetContour(20); pStVsPlWin3->SetContourLevel(0,0); pStVsPlWin3->SetContourLevel(1,10); pStVsPlWin3->SetContourLevel(2,20); pStVsPlWin3->SetContourLevel(3,30); pStVsPlWin3->SetContourLevel(4,40); pStVsPlWin3->SetContourLevel(5,50); pStVsPlWin3->SetContourLevel(6,60); pStVsPlWin3->SetContourLevel(7,70); pStVsPlWin3->SetContourLevel(8,80); pStVsPlWin3->SetContourLevel(9,90); pStVsPlWin3->SetContourLevel(10,100); pStVsPlWin3->SetContourLevel(11,110); pStVsPlWin3->SetContourLevel(12,120); pStVsPlWin3->SetContourLevel(13,130); pStVsPlWin3->SetContourLevel(14,140); pStVsPlWin3->SetContourLevel(15,150); pStVsPlWin3->SetContourLevel(16,160); pStVsPlWin3->SetContourLevel(17,170); pStVsPlWin3->SetContourLevel(18,180); pStVsPlWin3->SetContourLevel(19,190); ptstats = new TPaveStats(0.78,0.755,0.98,0.995,"brNDC"); ptstats->SetName("stats"); ptstats->SetBorderSize(2); ptstats->SetFillColor(19); ptstats->SetTextAlign(12); text = ptstats->AddText("pStVsPlWin3"); text->SetTextSize(0.0368); text = ptstats->AddText("Entries = 2 "); text = ptstats->AddText("Mean x = 13"); text = ptstats->AddText("Mean y = 18"); text = ptstats->AddText("RMS x = 2.5"); text = ptstats->AddText("RMS y = 2.5"); ptstats->Draw(); pStVsPlWin3->GetListOfFunctions()->Add(ptstats); ptstats->SetParent(pStVsPlWin3->GetListOfFunctions()); pStVsPlWin3->GetXaxis()->SetTitle("Plane"); pStVsPlWin3->GetXaxis()->CenterTitle(true); pStVsPlWin3->GetYaxis()->SetTitle("Strip"); pStVsPlWin3->GetYaxis()->CenterTitle(true); pStVsPlWin3->Draw("colz"); pt = new TPaveText(0.01,0.938182,0.631968,0.995,"blNDC"); pt->SetName("title"); pt->SetBorderSize(2); pt->SetFillColor(19); text = pt->AddText("I don't have 3 divisions on my palette"); pt->Draw(); TLegend *leg = new TLegend(0.65,0.83,1,1,NULL,"brNDC"); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillStyle(1001); TLegendEntry *entry=leg->AddEntry("pStVsPlWin3","Am I fill colour 0?","l"); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextAlign(12); entry->SetTextColor(1); leg->Draw(); cTest_3->Modified(); cTest->cd(); // ------------>Primitives in pad: cTest_4 cTest_4 = new TPad("cTest_4", "cTest_4",0.51,0.01,0.99,0.49); cTest_4->Draw(); cTest_4->cd(); cTest_4->Range(-10,-6.75,70,30.75); cTest_4->SetFillColor(0); cTest_4->SetBorderSize(2); ClassName() *pStVsPlWin4 = new TProfile2D("pStVsPlWin4","I have 3 divisions on my palette",64,-2,62,30,-3,27,0,0); pStVsPlWin4->SetBinEntries(1272,1); pStVsPlWin4->SetBinEntries(1597,1); pStVsPlWin4->SetBinContent(1272,200); pStVsPlWin4->SetBinContent(1597,100); pStVsPlWin4->SetBinError(1272,200); pStVsPlWin4->SetBinError(1597,100); pStVsPlWin4->SetEntries(2); pStVsPlWin4->SetContour(20); pStVsPlWin4->SetContourLevel(0,0); pStVsPlWin4->SetContourLevel(1,10); pStVsPlWin4->SetContourLevel(2,20); pStVsPlWin4->SetContourLevel(3,30); pStVsPlWin4->SetContourLevel(4,40); pStVsPlWin4->SetContourLevel(5,50); pStVsPlWin4->SetContourLevel(6,60); pStVsPlWin4->SetContourLevel(7,70); pStVsPlWin4->SetContourLevel(8,80); pStVsPlWin4->SetContourLevel(9,90); pStVsPlWin4->SetContourLevel(10,100); pStVsPlWin4->SetContourLevel(11,110); pStVsPlWin4->SetContourLevel(12,120); pStVsPlWin4->SetContourLevel(13,130); pStVsPlWin4->SetContourLevel(14,140); pStVsPlWin4->SetContourLevel(15,150); pStVsPlWin4->SetContourLevel(16,160); pStVsPlWin4->SetContourLevel(17,170); pStVsPlWin4->SetContourLevel(18,180); pStVsPlWin4->SetContourLevel(19,190); ptstats = new TPaveStats(0.78,0.755,0.98,0.995,"brNDC"); ptstats->SetName("stats"); ptstats->SetBorderSize(2); ptstats->SetFillColor(19); ptstats->SetTextAlign(12); text = ptstats->AddText("pStVsPlWin4"); text->SetTextSize(0.0368); text = ptstats->AddText("Entries = 2 "); text = ptstats->AddText("Mean x = 13"); text = ptstats->AddText("Mean y = 18"); text = ptstats->AddText("RMS x = 2.5"); text = ptstats->AddText("RMS y = 2.5"); ptstats->Draw(); pStVsPlWin4->GetListOfFunctions()->Add(ptstats); ptstats->SetParent(pStVsPlWin4->GetListOfFunctions()); pStVsPlWin4->GetXaxis()->SetTitle("Plane"); pStVsPlWin4->GetXaxis()->CenterTitle(true); pStVsPlWin4->GetYaxis()->SetTitle("Strip"); pStVsPlWin4->GetYaxis()->CenterTitle(true); pStVsPlWin4->GetZaxis()->SetNdivisions(3); pStVsPlWin4->Draw("colz"); pt = new TPaveText(0.01,0.938182,0.540364,0.995,"blNDC"); pt->SetName("title"); pt->SetBorderSize(2); pt->SetFillColor(19); text = pt->AddText("I have 3 divisions on my palette"); pt->Draw(); cTest_4->Modified(); cTest->cd(); cTest->Modified(); cTest->cd(); cTest->SetSelected(cTest); } void mProf() { TCanvas* cTest=new TCanvas("cTest","cTest",0,0,800,600); cTest->SetFillColor(0); cTest->Divide(2,2); TProfile2D* pStVsPlWin=new TProfile2D("pStVsPlWin","I was redrawn to get big label on palette", 64,-2,62,30,-3,27); pStVsPlWin->GetXaxis()->SetTitle("Plane"); pStVsPlWin->GetXaxis()->CenterTitle(); pStVsPlWin->GetYaxis()->SetTitle("Strip"); pStVsPlWin->GetYaxis()->CenterTitle(); pStVsPlWin->SetFillColor(0); pStVsPlWin->Fill(10,20,100); pStVsPlWin->Fill(15,15,200); //draw the first prof cTest->cd(1); pStVsPlWin->Draw("colz"); cTest->Update(); TPaletteAxis* palette= (TPaletteAxis*)pStVsPlWin->GetListOfFunctions()-> FindObject("palette"); palette->SetLabelSize(0.1);//this doesn't actually draw, you have to click on the canvas //have to redraw the TProfile2D to make the TPaletteAxis font size actually change gPad->Clear(); pStVsPlWin->Draw("colz"); TProfile2D* pStVsPlWin2=new TProfile2D("pStVsPlWin2","You have to click on me to make my palette label size increase", 64,-2,62,30,-3,27); pStVsPlWin2->GetXaxis()->SetTitle("Plane"); pStVsPlWin2->GetXaxis()->CenterTitle(); pStVsPlWin2->GetYaxis()->SetTitle("Strip"); pStVsPlWin2->GetYaxis()->CenterTitle(); pStVsPlWin2->SetFillColor(0); pStVsPlWin2->Fill(10,20,100); pStVsPlWin2->Fill(15,15,200); cTest->cd(2); pStVsPlWin2->Draw("colz"); cTest->Update(); TPaletteAxis* palette2= (TPaletteAxis*)pStVsPlWin2->GetListOfFunctions()-> FindObject("palette"); palette2->SetLabelSize(0.1); TProfile2D* pStVsPlWin3=new TProfile2D("pStVsPlWin3","I don't have 3 divisions on my palette", 64,-2,62,30,-3,27); pStVsPlWin3->GetXaxis()->SetTitle("Plane"); pStVsPlWin3->GetXaxis()->CenterTitle(); pStVsPlWin3->GetYaxis()->SetTitle("Strip"); pStVsPlWin3->GetYaxis()->CenterTitle(); pStVsPlWin3->SetFillColor(0); pStVsPlWin3->Fill(10,20,100); pStVsPlWin3->Fill(15,15,200); cTest->cd(3); pStVsPlWin3->Draw("colz"); cTest->Update(); TPaletteAxis* palette3= (TPaletteAxis*)pStVsPlWin3->GetListOfFunctions()-> FindObject("palette"); palette3->GetAxis()->SetNdivisions(3);//this doesn't do anything! TLegend *lElec=new TLegend(0.65,0.83, 1,1); lElec->SetFillColor(0); lElec->AddEntry(pStVsPlWin3,"Am I fill colour 0?","l"); lElec->Draw();//legend is colour 0 when drawn from here but if you save cTest.C then draw again the fill color goes back to default. TProfile2D* pStVsPlWin4=new TProfile2D("pStVsPlWin4","I have 3 divisions on my palette", 64,-2,62,30,-3,27); pStVsPlWin4->GetXaxis()->SetTitle("Plane"); pStVsPlWin4->GetXaxis()->CenterTitle(); pStVsPlWin4->GetYaxis()->SetTitle("Strip"); pStVsPlWin4->GetYaxis()->CenterTitle(); pStVsPlWin4->SetFillColor(0); pStVsPlWin4->Fill(10,20,100); pStVsPlWin4->Fill(15,15,200); cTest->cd(4); pStVsPlWin4->Draw("colz"); pStVsPlWin4->GetZaxis()->SetNdivisions(3);//this works }
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET