gDirectory->ls() after running a macro


I run the macro below using root macro.C+ and then do gDirectory->ls() and I don’t see intree in the output of gDirectory->ls(). Why? When I uncomment the last line and comment the second to last line, then I do see intree in the gDirectory->ls() output. Can someone explain this?

[code]#include “TFile.h”
#include “TTree.h”

void delete_macro()
TFile * weight_file = new TFile(“file.root”);

TChain *chain = new TChain(“tree_name”);
TTree *intree = chain;
//TTree *intree = new TTree(“tree_name”,“tree_name”);




Doing “new TChain” does NOT create any tree:

But even when I add

at the end I do not see the tree in the output of gDirectory->ls().

TChain is only for reading. Use CloneTree to copy the data and the meta-data (Clone only copies the meta data of TTree). You may want to take another look at the User’s Guide chapter on TTree to familiarize yourself which the recommend use of TTree and TChain.