Issue with ROOT tree compression in a MakeSelector framework

Dear experts,

I am using a make-selector based analysis code to read into nanoAOD files, pick a subset of events, and store the event-level variables in a new root file, inside a tree called “Events”.

This is how I am declaring the TFile and the TTree.

TFile *_TreeFile = new TFile(_TreeFileName,"recreate", "", 9); //using compression
TTree *mytree = new TTree("Events", "Events");

I am filling the tree with event-level variables as shown:
In an event loop,

Float_t lep0_pt  = (Float_t);
mytree->Branch("lep0_pt",  &lep0_pt);

I only have ~2000 events and 25 branches containing floats in the output. However, it is consuming ~250 MB. If I clone the input nanaAOD tree and don’t fill it up with any extra branch as shown above, the file size is below 100 KB. That means, my custom branches are consuming a lot of space. Is there any way to compress those? I expected the output files (including my custom branches) to be ~100KB.


ROOT Version: 6.12/07
Platform: Not Provided
Compiler: Not Provided

Hi @phazarik!

This doesn’t look like a compression problem. Even uncompressed, 2k events, 25 branches of floats would be only about 200 kB in total. So if you have 1000 times larger files, it seems more that you accidentally write more into the file than you intend. Have you expected the output tree and file carefully?

Since you don’t share that much of your code, I can’t really diagnose what is wrong. But two ideas: I would not call the output tree “Events”. This is already the name of the input NanoAOD tree, right? Often, ROOT expects unique names for all objects, and things get messed up if this is not the case. Then, have you tried a newer ROOT version, like 6.30.00? The 6.12/07 version is very old. Maybe your problem is related to a bug that was fixed in the meantime?


Dear @jonas ,

Thank you for your response!

I have figured out the mistake. Previously I was creating the branches inside the event loop. Now, I have made the variables global, and declared the branches outside the loop.

This is the corrected version.

//Declaring the variables globally
Float_t lep0pt;
//Declaring the branches globally
mytree->Branch("lep0_pt",  &lep0_pt);
//inside the event loop:
    //Assigning values to the variables:
    lep0_pt  = (Float_t);
    //Filling up the tree for each event.

Now the output file is ~200 KB.

With regards,