TNtuple do not work

Hallo everybody,

I have the following problem. I want to use TNtuple, and for that I made the following program to test it:

#include <iostream>
#include <TTree.h>
#include <TNtuple.h>
#include <TFile.h>

using namespace std;

int main(int argc, char **argv) {
  
  TFile * outPut = new TFile("outPut.root","RECREATE"); 
  TNtuple * myTree = new TNtuple("meins", "", "a:b:c:d");

   myTree->Fill(1,2,3,4);
   myTree->Fill(1,2,5,6);
   myTree->Fill(1,2,7,8);
   myTree->Fill(1,2,9,10);
       
    outPut->Write();
    outPut->Close();
  
  }
}

the compiling works without any error, but if I try to start the program, there come the error:

Warning in <TFile::Write>: file outPut.root not opened in write mode
Warning in <TFile::Write>: file outPut.root not opened in write mode

 *** Break *** segmentation violation

what is my mistake?

cheers
Prometheus

Hi,

I can not reproduce this problem. One possibility is that you current (OS) directory is not writeable.

CHeers,
Philippe.

Hi Philippe,

thank you, you were right :slight_smile:

but now, I have the next problem: if I try to use the TNtuple in root like that:

root [0] TFile *_file0=TFile::Open("outPut.root")
root [1] TH2D* tmp = new TH2D("tmp","",100,0,100,100,0,100)
root [2] myTree->Project("tmp","a:b","")

I get this error:

Error: Symbol myTree is not defined in current scope  (tmpfile):1:
Error: Failed to evaluate myTree->Project("tmp","a:b","")
*** Interpreter error recovered ***

where is my mistake?

cheers
Prometheus

Hi,

Unless you ntuple was named ‘myTree’ (in which case CINT would have done the load of the object for you) you are missing the reading the ntuple:root [0] TFile *_file0=TFile::Open("outPut.root") root [1] TTree*myTree = 0; _file0->GetObject("meins",myTree); root [2] TH2D* tmp = new TH2D("tmp","",100,0,100,100,0,100) root [3] myTree->Project("tmp","a:b","")

Cheers,
Philippe.

yes, now it works :slight_smile:

thank you a lot of!