Please read tips for efficient and successful posting and posting code
ROOT Version: root_v6.19.02.macosx64-10.15-clang110.tar.gz
Platform: Mac OS
Compiler: XCode
Hi I am running through a root tutorial for my lab. I tried making a C++ script to open a file and make histograms as well as a .root file.
Can anyone let me know what I did wrong in my code.
First here is my script.
oot_v6.19.02.macosx64-10.15-clang110.tar.gz
#include "/Users/conor/root/macros/exo_j2.C"
#include "Riostream.h"
#include "TFile.h"
#include "TH1.h"
#include "TNtuple.h"
void exo_j2(const Char_t* fdata="exo_j2.data", const Char_t* froot="exo_j2.root")
{
ifstream in;
open(fdata, ios::in);
Float_t x,y,z,e;
Int_t nlines = 0;
TFile *f = new TFile(froot,"exo_j2.root");
TH1F *hz = new TH1F("hz","z distribution",100,-10,10);
TH2F *hy_hx = new TH2F("hy_hx","Y vs X",100,-25,25,100,-25,25);
TH2F *hz_hx = new TH2F("hz_hx","Z vs X)",100,-10,10,100,-25,25);
TH2F *hz_hy = new TH2F("hz_hy","Z vs X)",100,-10,10,100,-25,25);
//TProfile *hxprof = new TProfile("profx","<e> vs X",100,-25,25);
//TProfile *hyprof = new TProfile("profx","<e> vs X",100,-25,25);
TH3F *hx_hy_hz = new TH3F("hx_hy_hz","Z vs Y vs X",100,-25,25,100,-25,25,100,-10,10);
TNtuple *ntuple = new TNtuple("ntuple","data from ascii file","x:y:z:e");
while (in.good())
{
in >> x >> y >> z >> e;
if (in.good())
{
if (nlines < 5)
{
cout << "X = " << x << ", Y = " << y ;
cout << ",Z = " << z << ",E = " << e << endl;
}
hz->Fill(z);
hy_hx->Fill(x,y);
hz_hx->Fill(x,z);
hz_hy->Fill(y,z);
//hxprof->Fill(x,e,1);
//hyprof->Fill(y,e,1);
ntuple->Fill(x,y,z,e);
nlines++;
}
};
in.close();
f->Write();
delete f;
}
Here are the errors I received after running the script.
**/Users/conor/root/macros/exo_j2.C:23:4:** **error:** **unknown type name 'TFile'**
TFile *f = new TFile(froot,"exo_j2.root");
**^**
**/Users/conor/root/macros/exo_j2.C:23:19:** **error:** **unknown type name 'TFile'**
TFile *f = new TFile(froot,"exo_j2.root");
**^**
**/Users/conor/root/macros/exo_j2.C:25:5:** **error:** **unknown type name 'TH1F'**
TH1F *hz = new TH1F("hz","z distribution",100,-10,10);
**^**
**/Users/conor/root/macros/exo_j2.C:25:20:** **error:** **unknown type name 'TH1F'**
TH1F *hz = new TH1F("hz","z distribution",100,-10,10);
**^**
**/Users/conor/root/macros/exo_j2.C:26:5:** **error:** **unknown type name 'TH2F'**
TH2F *hy_hx = new TH2F("hy_hx","Y vs X",100,-25,25,100,-25,25);
**^**
**/Users/conor/root/macros/exo_j2.C:26:23:** **error:** **unknown type name 'TH2F'**
TH2F *hy_hx = new TH2F("hy_hx","Y vs X",100,-25,25,100,-25,25);
**^**
**/Users/conor/root/macros/exo_j2.C:27:5:** **error:** **unknown type name 'TH2F'**
TH2F *hz_hx = new TH2F("hz_hx","Z vs X)",100,-10,10,100,-25,25);
**^**
**/Users/conor/root/macros/exo_j2.C:27:23:** **error:** **unknown type name 'TH2F'**
TH2F *hz_hx = new TH2F("hz_hx","Z vs X)",100,-10,10,100,-25,25);
**^**
**/Users/conor/root/macros/exo_j2.C:28:5:** **error:** **unknown type name 'TH2F'**
TH2F *hz_hy = new TH2F("hz_hy","Z vs X)",100,-10,10,100,-25,25);
**^**
**/Users/conor/root/macros/exo_j2.C:28:23:** **error:** **unknown type name 'TH2F'**
TH2F *hz_hy = new TH2F("hz_hy","Z vs X)",100,-10,10,100,-25,25);
**^**
**/Users/conor/root/macros/exo_j2.C:31:5:** **error:** **unknown type name 'TH3F'**
TH3F *hx_hy_hz = new TH3F("hx_hy_hz","Z vs Y vs X",100,-25,25,100,-25,2...
**^**
**/Users/conor/root/macros/exo_j2.C:31:26:** **error:** **unknown type name 'TH3F'**
TH3F *hx_hy_hz = new TH3F("hx_hy_hz","Z vs Y vs X",100,-25,25,100,-25,2...
It seems to be not recognizing the TH3F types. Unsure how to fix this issue.