How to write tree to file by degrees

Hello, I’m struggling with saving a tree into a file.
What I’m trying to do is :
Read a tree file and get values from leaves, then calculate a physical quantity from those values, and fill it in another(new) tree, for each entry. And save the new tree into a file.
Please find the attached file.

When the first tree file is not too large (number of entries < 106), my program work. But when the
number of enties exceeds ~5x10
6, my program abort when writing the file.

I tried to use TTree::AutoSave(), but this function only save the the tree header, and I cannot read the content later.[/list]
mkEnergyTree.C (2.33 KB)

In your code move the two lines
TTree *energyTree = new TTree(“energyTree”, “tree for energy”);
energyTree->Branch(“energy”, energy, “energy[64]/F”);

after the line
TFile *outfile = new TFile(energyTreeFile, “recreate”);

Rene

Nice to meet you, Brun. And A Happy New Year.
Thank you very much for your help. Now, my program works as I want.
By the way, I have one more question related to the program and the tree.

The original tree contains 5 branches, whose types are Int_t, Int_t, array of Short_t (64), array of Double_t (64), array of Double_t (2), respectively. The file size is 618588698. (See below.)
On the other hands, the new tree contains only 1 branch, whose type is array of Float_t (64). The file size is 1238224876, which is twice as large as the original one. (See below.)

I would like to know about the file size. Why the file size of new tree get so large? Are there any way to control the compression factor when making this tree?

Thank you.

titoh

— “original” tree —
root [1] TFile *f = new TFile(“041231_na_m20_4us_clon_tree.root”)
root [2] TTree tr = (TTree)f->Get(“tree”)
root [3] tr->Print()


*Tree :tree : tree for data *
*Entries : 5174246 : Total = 3445009597 bytes File Size = 618588698 *

  •    :          : Tree compression factor =   5.57                       *
    

*Br 0 :i_cycles : i_cycles/I *
*Entries : 5174246 : Total Size= 20759000 bytes File Size = 176505 *
*Baskets : 648 : Basket Size= 32000 bytes Compression= 117.48 *

*Br 1 :event_seq_no : event_sq_no/I *
*Entries : 5174246 : Total Size= 20761613 bytes File Size = 7196270 *
*Baskets : 648 : Basket Size= 32000 bytes Compression= 2.88 *

*Br 2 :adc : adc[64]/S *
*Entries : 5174246 : Total Size= 664174118 bytes File Size = 452773501 *
*Baskets : 20780 : Basket Size= 32000 bytes Compression= 1.47 *

*Br 3 :ped : ped[64]/D *
*Entries : 5174246 : Total Size=2.65673e+09 bytes File Size = 77583766 *
*Baskets : 83455 : Basket Size= 32000 bytes Compression= 34.22 *

*Br 4 :cmn : cmn[2]/D *
*Entries : 5174246 : Total Size= 83021746 bytes File Size = 80132781 *
*Baskets : 2593 : Basket Size= 32000 bytes Compression= 1.04 *

— “new” tree —
root [4] TFile *fe = new TFile(“041231_na_m20_4us_clon_energyTree.root”)
root [5] TTree tre = (TTree)fe->Get(“energyTree”)
root [6] tre->Print()


*Tree :energyTree: tree for energy *
*Entries : 5174246 : Total = 1328571807 bytes File Size = 1238224876 *

  •    :          : Tree compression factor =   1.07                       *
    

*Br 0 :energy : energy[64]/F *
*Entries : 5174246 : Total Size= 1328738413 bytes File Size = 1237881980 *
*Baskets : 41727 : Basket Size= 32000 bytes Compression= 1.07 *

This is the expected behaviour.
Your branch with shorts take in average 1.4 bytes per element while your float branch takes around 3.8 bytes.

Rene

Thank you for your kind cooperation, Brun.

Best regards,
titoh