Home | News | Documentation | Download

Saving Histograms from tree based Root file into a new root file

i have tree based root file i want to extract histogram from it and want to save them into a new root file form tree based root file one by one. please any hint?

Please read tips for efficient and successful posting and posting code

ROOT Version: 5.34
Platform: Not Provided
Compiler: Not Provided


ROOT comes with command lines tools: rootls, rootcp, rootmv… etc that might be an easy solution for your problem.

thanks for help but How can i use these command lines?

These commands lines are installed when ROOT is installed.
They should be available at the shell prompt.
for instance type rootls at the shell prompt.

@couet In the first post, please note ROOT Version: 5.34

Ah yes, … it is not available with 5.34,

So you will have to open the files in ROOT using TFile. Get the histograms you need in memory, then create a new TFile and save the histograms you got in memory in it.

Well, @sbinet could maybe give you a link to some simple standalone tools written in Go.

sure thing:

and look for the root-cp command for your OS/architecture (e.g. root-cp-windows-amd64.exe for a Windows 64bits machine)

then:

$> root-cp -help
Usage: root-cp [options] file1.root[:REGEXP] [file2.root[:REGEXP] [...]] out.root

ex:
 $> root-cp f.root out.root
 $> root-cp f1.root f2.root f3.root out.root
 $> root-cp f1.root:hist.* f2.root:h2 out.root

options:

ex:

$> root-ls ./h1.root
=== [./h1.root] ===
version: 60806
TH1D    h1d     h1d     (cycle=1)
TH1F    h1f     h1f     (cycle=1)
TH1F    h1d-var h1d-var (cycle=1)
TH1F    h1f-var h1f-var (cycle=1)

$> root-cp ./h1.root:h1d$ o.root
root-cp: copying "./h1.root:h1d$"...
$> root-ls ./o.root
=== [./o.root] ===
version: 61800
TH1D    h1d     h1d     (cycle=1)

$> root-cp ./h1.root:h1d o.root
root-cp: copying "./h1.root:h1d"...
$> root-ls ./o.root
=== [./o.root] ===
version: 61800
TH1D    h1d     h1d     (cycle=1)
TH1F    h1d-var h1d-var (cycle=1)

hth,
-s

Thanks a lot for help @sbinet , @Wile_E_Coyote and @couet

I don’t see what go has to do with any of this?

root [] tree->Draw("whatever >> hist");
root [] new TFile("output.root", "RECREATE");
root [] hist->Write();
root [] .q

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