_ROOT Version: 6.08 Platform: Not Provided Compiler: Not Provided
Hi Experts,
I want to write a histogram to a branch of a tree in PyROOT.
// Opens input file
f =ROOT.TFile.Open(“~/Sharma/TuningMC/RootFiles/MC_pidfix/BIN1/performanceHisto.root”)
//Get NDim Histo
nHis1=f.Get(“RAAhisTPC_NcrossedRows_v_qPt_tgl_phi”)
//Create Output file
fileOut=ROOT.TFile.Open(“fileOut.root”,“RECREATE”)
//Create TTree
tree = ROOT.TTree( ‘tree’, ‘tree’ )
//extract TH1D histo
h1=nHis1.Projection(0)
//Writing as a branch
tree.Branch(“h1”,“TH1D”,hex(id(h1))) // Here I am giving the address, but I am no getting histogrm
tree.Write()
Is there anything I am doing wrong?
Could you please help in this?
This should create a branch called h1 associated with the h1 histogram, and when you run tree.Write() it will write an entry in the tree for that branch.
Thanks!
It works. There is a branch in the tree with a lot of information.
I correct myself, I need a single leaf which contains the histogram (h1) inside the tree.
Right Now we have this –
tree->Branch (h1)-> … … several leaves and plenty of information ***but NOT the h1 distribution
I expect —
tree->leaf (h1) ***** No extra Info, just h1 distribution
Please note that the tree is (sort of) a table, so if you write the histogram as a branch (column), you will have N copies of that histogram stored in the tree (where N is the number of rows, called entries in the tree).