TGraph2D Format not saved to file

Hello Rooters,

I am creating a canvas with four pads, any combination of them will contain a two dimensional graph. If the macro is run live, the canvas is drawn and displays the formats that I specify. However, those formats are not saved to file using SaveAs(), nor are they saved if from the Canvas I do a menu “Save As”.

I’m using Root 5.34.

Thanks,

Rob

void main()
{
        TCanvas  *c1 = new TCanvas("c1","Radiative Acceptance",70,60,1200,900);
        c1 -> Divide(2,2);
        c1 -> cd(1);
        g1 -> Draw("surf1");
        SetupAxesg( g1, "Radiative Acceptance", "Minimum Positron Energy [MeV]","Minimum Photon Energy [MeV]","Acceptance");
        c1_1 -> SetTheta(30);
        c1_1 -> SetPhi(210);
        c1_1 -> Modified();
        c1_1 -> Update();
}
void SetupAxesg( TH2D *gr, char *mainTitle, char *xtitle,char *ytitle,char *ztitle);
{
        gPad -> Update();
        gr -> SetTitle(mainTitle);
        gr -> GetXaxis() -> SetTitle(xtitle);
        gr -> GetXaxis() -> SetTitleSize(0.03);
        gr -> GetXaxis() -> SetLabelSize(0.02);
        gr -> GetXaxis() -> SetDecimals(kTRUE);
        gr -> GetXaxis() -> CenterTitle(true);
        gr -> GetXaxis() -> SetTitleOffset(1.30);
        gr -> GetYaxis() -> SetDecimals(kTRUE);
        gr -> GetYaxis() -> SetTitle(ytitle);
        gr -> GetYaxis() -> SetTitleSize(0.03);
        gr -> GetYaxis() -> SetLabelSize(0.02);
        gr -> GetYaxis() -> CenterTitle(true);
        gr -> GetYaxis() -> SetTitleOffset(1.30);
        gr -> GetZaxis() -> SetDecimals(kTRUE);
        gr -> GetZaxis() -> SetTitle(ztitle);
        gr -> GetZaxis() -> SetTitleSize(0.03);
        gr -> GetZaxis() -> SetLabelSize(0.02);
        gr -> GetZaxis() -> CenterTitle(true);
        gr -> GetZaxis() -> SetTitleOffset(1.30);
}

It is difficult to run your macro as g1 is not defined.

Apologies. rAcc[][] is a result of a somewhat complicated summation of filtered events.

    int nn = 10;
    Float_t rAcc[nn][nn];
    Emax = 52.8304;
    TGraph2D *g1 = new TGraph2D();

    Int_t pnt = 0;
    for( i=0; i<nn; i++ )
    {
            double xx = Emax*rX0[i];
            for( j=0; j<nn; j++ )
            {
                    double yy = Emax*rY0[j];
                    g1 -> SetPoint(pnt,xx,yy,rAcc[i][j]);
                    pnt++;
            }
    }

I had to modify your macro to make it work (many errors with ROOT 6).
rob.C (1.7 KB)

But still it does not work. Some arrays are undefined:

$ root rob.C
   ------------------------------------------------------------------
  | Welcome to ROOT 6.19/01                        https://root.cern |
  | (c) 1995-2019, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on Aug 21 2019, 13:02:06                      |
  | From heads/master@v6-19-01-881-g2f5fb7eaf6                       |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] 
Processing rob.C...
In file included from input_line_12:1:
/Users/couet/roottest/rob.C:36:27: error: use of undeclared identifier 'rX0'
         double xx = Emax*rX0[i];
                          ^
/Users/couet/roottest/rob.C:39:35: error: use of undeclared identifier 'rY0'
                 double yy = Emax*rY0[j];
                                  ^
root [1] 

OK. I appreciate your patience. Here is a working example. In this instance, I removed the division into mutiple pads.

Thanks, Rob.

void main()
{
        double Emax = 52.803;
        int nn = 10;
        Float_t rAcc[10][10], rX0[10], rY0[10];

        for( int i = 0; i < nn; i++ )
        {
                rX0[i] = 1.0*i;
                rY0[i] = 1.0*i;
                for( int j = 0; j < nn; j++ )
                        rAcc[i][j] = gRandom -> Gaus(0.01,0.5);
        }

        TGraph2D *g1 = new TGraph2D();

        Int_t pnt = 0;
        for( i=0; i<nn; i++ )
        {
                double xx = Emax*rX0[i];
                for( j=0; j<nn; j++ )
                {
                        double yy = Emax*rY0[j];
                        g1 -> SetPoint(pnt,xx,yy,rAcc[i][j]);
                        pnt++;
                }
        }

        gStyle->SetNumberContours(99);
        gStyle -> SetPalette(1);

        TCanvas  *c1 = new TCanvas("c1","Radiative Acceptance",70,60,1200,900);
        c1 -> cd();
        g1 -> Draw("surf1");
        SetupAxesg( g1, "Radiative Acceptance", "Minimum Positron Energy [MeV]","Minimum Photon Energy [MeV]","Acceptance");
        c1 -> SetTheta(30);
        c1 -> SetPhi(210);
        c1 -> Modified();
        c1 -> Update();

        c1 -> SaveAs("tmp.C");
}

void SetupAxesg( TGraph2D *gr, char *mainTitle, char *xtitle, char *ytitle, char *ztitle )
{
        gPad -> Update();
        gr -> SetTitle(mainTitle);
        gr -> GetXaxis() -> SetTitle(xtitle);
        gr -> GetXaxis() -> SetTitleSize(0.03);
        gr -> GetXaxis() -> SetLabelSize(0.02);
        gr -> GetXaxis() -> SetDecimals(kTRUE);
        gr -> GetXaxis() -> CenterTitle(true);
        gr -> GetXaxis() -> SetTitleOffset(1.30);
        gr -> GetYaxis() -> SetDecimals(kTRUE);
        gr -> GetYaxis() -> SetTitle(ytitle);
        gr -> GetYaxis() -> SetTitleSize(0.03);
        gr -> GetYaxis() -> SetLabelSize(0.02);
        gr -> GetYaxis() -> CenterTitle(true);
        gr -> GetYaxis() -> SetTitleOffset(1.30);
        gr -> GetZaxis() -> SetDecimals(kTRUE);
        gr -> GetZaxis() -> SetTitle(ztitle);
        gr -> GetZaxis() -> SetTitleSize(0.03);
        gr -> GetZaxis() -> SetLabelSize(0.02);
        gr -> GetZaxis() -> CenterTitle(true);
        gr -> GetZaxis() -> SetTitleOffset(1.30);
}

I am amble to run rob.C now.
it generates the file tmp.C. I do not see anything wrong.
What should I do to see the problem ?

It you next try to call up tmp.C, you’ll see that the formatting didn’t get saved.

Ah yes when executing tmp.C I see the titles are missing.

If I execute Modified() and Update() it doesn’t help.

Yes, that’s a bug. I need to fix. Working on it now. But i am afraid it will be fixed in version 6 only.

OK. Thanks! I’ll look forward to the update.

The bug is now fixed in master, Thanks to have seen it.
But, as I said, if you are stick to 5.34 that will not help you.