Error on root6: error: use of undeclared identifier

Hello,

I’m reading a rootfile that has several histograms and I was working with root 5.34 and this was working perfectly but recently I started to work with root 6.06 and suddenly when I open my file to obtain the graph of a histogram like this:

rootfile_example->cd();

   histo_tst1->Draw("histosame");

I obtain an error from root 6 that is:

error: use of undeclared identifier ‘histo_tst1’

I wiil be very happy if you help me with this error,

Thank you very much.

Norman

Hi Norman,

I cannot reproduce this. Could you provide us with a script (that we can run, i.e. with the necessary data files) that shows this behavior?

Cheers, Axel.

1 Like

Hi Axel, this forum doesn’t allow me attach archives yet, because I’m a new user, but this is the macro that I was working with:

  TFile *file1 = TFile::Open("fig_histograms_my_input0.root");
  TFile *file2 = TFile::Open("root5_rho_1_my_input0.root");
  TFile *file3 = TFile::Open("root6_rho_1_my_input0.root");     
  TFile *file4 = TFile::Open("root6_rho_2_my_input0.root");
  
   cout<<" -->Running: myEfficiency"<<endl;
   TCanvas *g[30];
   Int_t n;
   TLine *line[5];
   TLegend *leg[5];
    string myTitle,myTitle2;
   
   gROOT->SetStyle("Plain");
   gStyle->SetOptStat(111111);
   
   gStyle->SetStatW(0.25),  gStyle->SetStatH(0.3);
   gStyle->SetTitleH(0.10), gStyle->SetTitleW(0.50);	

   myTitle  = ".pdf";
   myTitle2 = "graphs/";
   
   n=0; g[n] = new TCanvas(Form("all%d",n),"Compare number of tracks"), g[n]->Divide(2,3); 
   
   file2->cd();     

        g[n]->cd(1);  tst20->Draw("histosame");
                      tst20->SetTitle("ntracks for root5_larsoft_v05_14_01");                                                    
	
   file3->cd();     

        g[n]->cd(2);  tst20->Draw("histosame");
                      tst20->SetTitle("ntracks root6_larsoft_v05_14_01");

   file4->cd();     

        g[n]->cd(3);  tst20->Draw("histosame");
                      tst20->SetTitle("ntracks_pmtrack root6_larsoft_v06_19_00"); 

        g[n]->cd(4);  tst37->Draw("histosame");
                      tst37->SetTitle("ntracks_pmtracktc root6_larsoft_v06_19_00"); 

        g[n]->cd(5);  tst38->Draw("histosame");
                      tst38->SetTitle("ntracks_pandora root6_larsoft_v06_19_00"); 

        g[n]->cd(6);  tst39->Draw("histosame");
                      tst39->SetTitle("ntracks_pmtrajfit root6_larsoft_v06_19_00"); 

                      g[n]->SaveAs((myTitle2+"ntracks"+myTitle).c_str());   

The thing is that this macro run with root 5 perfectly, but with root 6 don’t.

Thank you very much .

Norman

In ROOT 6, you must create histogram pointers and then retrieve your histograms manually. So, for each histogram, you should have something like: TH1F *h; SomeRootFile->GetObject("SomeHistoName", h);
Note also that, you should not use the “same” drawing option, if nothing has been drawn yet (in the current pad).

1 Like

Note that if the current canvas in empty the option “same” will be ignored. But in principle you are right.

1 Like

Hi,

I’ll give some background in case anyone cares / reads this :slight_smile: We went back and forth with this in ROOT 6; what you observe is likely the long lasting result:

It’s easy to misspell variables. I do it all the time. To make sure that we know what we’re talking about, we decided to stop doing magic variables in named macros (anything that has a function inside). We had cases - also in ROOT tutorials - where broken code was hidden because of these magic variables, giving wrong results.

We also like the fact that code that looks like code is now much closer to what the compiler would accept (except for #includes) making it less confusing for novices why “sometimes” something is okay and sometimes it’s not.

:white_check_mark: Note that these magic variables continue to work on the prompt: opening a ROOT file with a histogram called histo will still allow you to simply issue a histo->Draw().

Cheers, Axel.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.