How to save an existing histogram into TTree

I have some histograms stored in a TDirectoryFile in a root file. I am trying to save some of those histograms into a TTree in a new root file. I tried the following but I am unable to write the histograms to the tree:

file = 'DYJetsToLL_M-50_TuneCP5_13TeV-amcatnloFXFX-pythia8_v14-v1.root'
f = TFile("DYJetsToLL.root","RECREATE")
t = TTree('TreeS', 'Test')
MuTaufile = TFile(file)
lfv_histo = MuTaufile.Get('TightOS')
hlist = lfv_histo.GetListOfKeys()
iter = TIter(hlist)
for i in iter:
    histo = MuTaufile.Get('TightOS/'+i.GetName())

What should I do?

I am trying to save some of those histograms into a TTree in a new root file.

What is the end purpose of this transformation? (knowning that might influence what needs to be done).


So, in the TDirectoryFile I have the following variables filled: mPt, tPt, mtCollinearMass, mtVisibleMass. I am trying to save them in a tree because I want to input the tree into a BDT in TMVA for some classification of signal and background. I know that I can run the analyzer to fill the TTree instead of saving the histograms in a TDirectoryFile but the analyzer takes atleast several hours to run. So, I though there will be a workaround for this.


A histogram is aggregate data and does not save data points for each individual event, as such it’s unsuitable to use as input to TMVA and I’m afraid you’ll have to re-run the generation.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.