The tree in the file not filled but the branch is added and filled properly

Hi All, I am a beginner and am learning ROOT. I was trying to make a ROOT file using these commands :
TFile *outfile = new TFile(“ht.root”,“RECREATE”);
TTree *newtree= new TTree(“newtree”,“test”);
TH1F *rc = new TH1F(“rc”,“rc”,500,10,4000);
newtree->Branch(“rc”,“TH1F”,&rc,32000,0);

Where, rc will be added as a branch in the tree ‘newtree’.
But the branch is not added to the tree rather it is separately added as a branch. What should I do to get a branch in the tree?

Hi. Look at the examples in TTree class documentation. AFAIK, you cannot attach a histogram to a branch.

Thanks for your reply. I don’t want to attach a branch to a histogram. I want to have a tree and within that I want to have a branch. But for some reason, it’s not filling the tree. Rather it is attaching a branch in the file. I think I exactly followed the example that you sent !

Alo see the related tutorials:
root.cern.ch/doc/master/group__ … _tree.html