Hi there,
My root file contains several histograms.
I open the root file in the main code with:
TFile *f = TFile::Open("t0RPrelui2015all.root");
I want to call a function plotall() which should plot
all the histograms as per:
plot1d(rp_x_124,"X (cm)","0.1cm","lin","lin")
This code compiles fine in ROOT5.
However, when I try to compile it with ROOT 6.16/00
it gives the error:
[lgemedia@zabriskie manyplots]$ root mycode.C
------------------------------------------------------------
| Welcome to ROOT 6.16/00 https://root.cern |
| (c) 1995-2018, The ROOT Team |
| Built for linuxx8664gcc on Jan 23 2019, 09:06:13 |
| From tags/v6-16-00@v6-16-00 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------
root [0]
Processing mycode.C...
In file included from input_line_10:1:
/home/lgemedia/totem/manyplots/mycode.C:69:10: error: use of undeclared identifier 'rp_x_124'
plot1d(rp_x_124,"X (cm)","0.1cm","lin","lin")
^
root [1] .q
I have read and tried many things unsuccessfully.
mycode.C
-------------
#include <TPad.h>
#include <TStyle.h>
#include <TPave.h>
#include <TPaletteAxis.h>
#include <TLatex.h>
#include "TCanvas.h"
//
#include "TSystem.h"
#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"
#include <Riostream.h>
//
using namespace std;
void mycode()
{
TFile *f = TFile::Open("t0RPrelui2015all.root");
cout << " in root: " << endl;
cout << " .x makeplot.C " << endl;
}
void plot1d(TH1F* string1, TString xtitle, TString binning, TString scaley1, TString scalex1)
{
TCanvas * c1 = new TCanvas("c1","c1",1200,800);
string1->Draw();
string1->GetXaxis()->SetTitle(xtitle);
string1->GetYaxis()->SetTitle("# of Events/" + binning);
string1->GetXaxis()->CenterTitle();
string1->GetYaxis()->CenterTitle();
string1->GetXaxis()->SetTitleOffset(1.2);
string1->GetYaxis()->SetTitleOffset(1.2);
c1->Update();
if (scalex1 == "log"){
gPad->SetLogx();
}
if (scaley1 == "log"){
gPad->SetLogy();
}
c1->Modified();
TString hname1 = string1->GetName();
c1->SaveAs(hname1 + ".png");
}
void plotall()
{
//
//TString myplot="makeplot.C";
//gROOT->Macro(myplot.Data());
//
//TH1* readThis = 0;
//file->GetObject("hpx", readThis);
//
//TFile *f = TFile::Open("t0RPrelui2015all.root");
//plot1d(f->GetObject("rp_y_125",readThis),"X (cm)","0.1cm","lin","lin");
plot1d(rp_x_124,"X (cm)","0.1cm","lin","lin")
plot1d(rp_x_125,"X (cm)","0.1cm","lin","lin")
plot1d(rp_y_124,"X (cm)","0.1cm","lin","lin")
plot1d(rp_y_125,"X (cm)","0.1cm","lin","lin")
cout << " ...all set ! " << endl;
//
}
Does anyone know what is wrong with this syntax?
Thanks in advance.
Luiz Emediato
_ROOT Version: 6.16/00
_Platform: Fedora 29
_Compiler: gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2)