Copying histogram to new TTree

Hi all,

I’m trying to copy a histogram from one file to a new tree in a new file, and can’t seem to get the syntax right. So far I can create the new file & tree without any problems, but I’m not able to copy a histogram to the tree. What I have so far is:

TFile* nfile = new TFile("histos_A.root"); TFile hfile("output_file.root","RECREATE"); TTree *TreeB = new TTree("TreeB","TreeB"); TreeB->Branch("pt","pt/F"); ... TreeB->Fill(); TreeB->Print(); hfile.Write(); hfile.Close();

Where I’ve removed the incorrect attempts to copy the histogram across (they were in place of ‘…’). I think that creating the branch with pt given as a float is incorrect, but I leave this here as I don’t have the correct syntax.

Any advice would be greatly appreciated!


In your example there is no trace from the histogram and thus I have no clue what you might mean (usually histogram are produced from the content of a TTree, you may have meant to copy the content the input TTree or you may have tried to copy an histogram into a TTree … which is not a well defined operation (i.e. could mean many things).