Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-8807

Save a TCanvas as a *C file with a name starting with a number makes unrunable macro

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: 6.08/06
    • Fix Version/s: 6.10/00
    • Component/s: Graphics
    • Labels:
      None
    • Environment:

      Linux 64-bits

      Description

      This code shows the problem

      #include <TCanvas.h>
      #include <TH1D.h>
       
      void test() {
        TCanvas *c = new TCanvas();
        TH1D *h = new TH1D("h","h",500,-5,5);
        h->FillRandom("gaus",10);
        h->Draw();
        c->SaveAs("1D_spectrum.C");
      }

      At the end I have a file named 1D_spectrum.C with the following code

      void 1D_spectrum()
      {
      //=========Macro generated from canvas: c1/c1
      //=========  (Mon May 29 20:50:13 2017) by ROOT version6.08/02
         TCanvas *c1 = new TCanvas("c1", "c1",13,33,700,500);
         gStyle->SetOptFit(1);
         gStyle->SetOptStat(0);
         c1->Range(0,0,1,1);
         c1->SetFillColor(10);
         c1->SetBorderMode(0);
         c1->SetBorderSize(2);
         c1->SetTickx(1);
         c1->SetTicky(1);
         c1->SetLeftMargin(0.17);
         c1->SetRightMargin(0.08);
         c1->SetTopMargin(0.08);
         c1->SetBottomMargin(0.18);
         c1->SetFrameLineWidth(2);
         c1->SetFrameBorderMode(0);
         
         TH1D *h__1 = new TH1D("h__1","h",500,-5,5);
         h__1->SetBinContent(201,1);
         h__1->SetBinContent(214,1);
         h__1->SetBinContent(222,1);
         h__1->SetBinContent(249,1);
         h__1->SetBinContent(256,1);
         h__1->SetBinContent(283,2);
         h__1->SetBinContent(331,1);
         h__1->SetBinContent(337,1);
         h__1->SetBinContent(424,1);
         h__1->SetEntries(10);
         h__1->SetLineWidth(2);
         h__1->SetMarkerStyle(20);
         h__1->SetMarkerSize(0.7);
         h__1->GetXaxis()->SetNdivisions(506);
         h__1->GetXaxis()->SetLabelFont(42);
         h__1->GetXaxis()->SetLabelOffset(0.015);
         h__1->GetXaxis()->SetLabelSize(0.06);
         h__1->GetXaxis()->SetTitleSize(0.07);
         h__1->GetXaxis()->SetTitleFont(42);
         h__1->GetYaxis()->SetNdivisions(506);
         h__1->GetYaxis()->SetLabelFont(42);
         h__1->GetYaxis()->SetLabelOffset(0.015);
         h__1->GetYaxis()->SetLabelSize(0.06);
         h__1->GetYaxis()->SetTitleSize(0.07);
         h__1->GetYaxis()->SetTitleOffset(1.1);
         h__1->GetYaxis()->SetTitleFont(42);
         h__1->GetZaxis()->SetLabelFont(42);
         h__1->GetZaxis()->SetLabelOffset(0.015);
         h__1->GetZaxis()->SetLabelSize(0.06);
         h__1->GetZaxis()->SetTitleSize(0.07);
         h__1->GetZaxis()->SetTitleOffset(1.1);
         h__1->GetZaxis()->SetTitleFont(42);
         h__1->Draw("");
         c1->Modified();
         c1->cd();
         c1->SetSelected(c1);
      }

      The problem with the named macro is I cannot simply plot my spectrum by doing ".x 1D_spectrum.C". If I do so I get

      root [1] .x 1D_spectrum.C 
      In file included from input_line_72:1:
      /home/olivier/1D_spectrum.C:1:6: error: expected unqualified-id
      void 1D_spectrum()
           ^

      Is there any reason to use a named macro instead of simply

      {
      //=========Macro generated from canvas: c1/c1
      //=========  (Mon May 29 20:50:13 2017) by ROOT version6.08/02
         TCanvas *c1 = new TCanvas("c1", "c1",13,33,700,500);
         gStyle->SetOptFit(1);
      ......
       
         c1->Modified();
         c1->cd();
         c1->SetSelected(c1);
      }

        Attachments

          Activity

            People

            • Assignee:
              couet Olivier Couet
              Reporter:
              4aa1957e0394b6104dd6 Olivier Delaune
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Actual End: