Filling a 2D vector branch in a TTree using makefile

Please provide the following information:

Hi,

I have made a makefile using a TTree of ttbar MC samples. I now want to make another TTree in a different TFile and then make a new branch in it and fill it with a 2D vector of jet_pt of the MC data itself. (In the MC sample, in each event, there are more than one Jet and thus want a 2D vector). Thus, what I want is to have same branch contents in both the TTree as latter, if this works, I wish to put some selection cut and then fill the new branch. However, I am getting the error

Error in TFile::ReadBuffer: error reading all requested bytes from file delete.root, got 218 of 300
Error in TFile::Init: delete.root failed to read the file type data.

Could someone please check the code I wrote and see where am I going wrong.

tree.C (2.6 KB)

Hi,

It seems that the file is corrupted: can you check?

Cheers,
D

Hi,

another detail. I see that you reopen the file for every entry and for example never reset the container you are filling. Perhaps a simpler approach to create a column and re-persistify the dataset might help. Did you have a look to TDataFrame?

Cheers,
D

1 Like

Hi,

The file isn’t corrupted. The “delete.root” is the new root file I wish to create while tree.root was the original file. Earlier when I was using
TFile *nfile = TFile::Open(“nfile.root”,“recreate”);
TTree *tree = fChain->CloneTree(0);
instead of creating a new TTree, I was getting an error:

Error in <TBranchElement::Fill>: Failed filling branch:jet_pt, nbytes=-1
Error in <TTree::Fill>: Failed filling branch:ntree.jet_pt, nbytes=-1, entry=18063
 This error is symptomatic of a Tree created as a memory-resident Tree
 Instead of doing:
    TTree *T = new TTree(...)
    TFile *f = new TFile(...)
 you should do:
    TFile *f = new TFile(...)
    TTree *T = new TTree(...)


Do you feel the code I wrote can make  a new TBranch of 2D vector whose each row denotes new event while each column defines number of jets in each event?
`

Thank you!

Hi made a proposal to greatly simplify the task.

D

Hi,

TDataFrame is available in the rootv6.13.

While I am using v6.06/01. So it is still supported on this version.

root [1] using namespace std;
root [2] using namespace ROOT::Experimental;
ROOT_prompt_2:1:23: error: expected namespace name
using namespace ROOT::Experimental;
                ~~~~~~^

Thank you and best regards,

Hi,

Also, regarding the previous file, I modified the code and now it is working apart from the factor you mention about resetting the container. Could you please explain this.

The jet_pt present in original sample is

While the one which I obtained by filling the 2d vector is

where we see the values are getting repeated inspite of initialing the column vector to zero.

I guess I making some mistake in filling the TBranch as the final 2d vector jet_pt matrix is correct (as I see in the output) but the filling of TTree is a issue…

tree_newc.C (3.0 KB)

Hi,

TDataFrame is in ROOT since version 6.12 - in your first post you say ROOT 6.12, so are you using 6.06?

D

Hi,

I guess those statements got attached to the post by default. But anyways, I am using 6.06 version of ROOT. Also, could you help me figure out the error in the previous post…

Thank you!

Hi,

Incase someone gets stuck,<a class=“attachment”

Also, what I stated in my first post required only 1D vector and not 2D.

Thanks!

tree_correct1D.C (3.1 KB)

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