Info lost after cloning

Dear experts,

I am writing a vector, TVectorD(2), with some information to a ROOT file. The vector (called PScuts) does not appear as a branch (attached is the ROOT file for reference). When I clone the tree in order to turn off some branches I lose the vector and the information in it.
Is there a way to keep this vector after cloning the tree?

Thank you,
Amin
B-4p-0-1-v1510_14TEV_NoPileUp_288175522.PS.root (66.4 KB)

Hi again,

Any ideas on how to solve this issue?

Thanks a lot,
Amin

I suspect that is then a data member of an object that is not split. In order to keep it, you must keep the branch that contains the non-split object that contains this vector.

Cheers,
Philippe.

Hi Philippe,

I can’t quite follow what you exactly mean. It does not seem that this vector belong to a branch.
I tried treating it like one

oldtree->SetBranchStatus("PScuts*",1);

but it didn’t work.
If it helps, I wrote this vector to the tree using this script:

TVectorD *PScuts;
PScuts = new TVectorD(2);

for (Long64_t i=0; i<nentries; ++i) {
    chain.GetEntry(i);
    LHEFEvent *event = (LHEFEvent*) branchEvent->At(0);
    (*PScuts)(0) = (*PScuts)(0)+event->Weight;
    MissingET *met = (MissingET*) branchMissingET->At(0);
    if(met->MET<70) {continue;}
    (*PScuts)(1) = (*PScuts)(1)+event->Weight;
    newtree[0]->Fill(); }
newfile[0] = new TFile(outroot[0].c_str(),"recreate");
PScuts->Write("PScuts");
newtree[0]->Write();
newfile[0]->Close();

Thank you in advance,
Amin

Humm … How is newtree ‘created’?

PScuts->Write("PScuts");

ask for the TVectorD to be written ‘once’, ‘outside’ the TTree. This is unlikely to be what you meant. Nonetheless to retrieve it you would do:

TVectorD *PScuts = nullptr;
file->GetObject("PScuts", PScuts);

However it is more likely you meant to store it as part of the newtree.

Also

newfile[0] = new TFile(outroot[0].c_str(),"recreate");
...
newtree[0]->Write();

means that unless the ‘newtree’ was created as an in-memory TTree, the file will only contains the TTree meta-data and none of the data. [And if it was created as an in-memory, you may be more efficient, in run-time and memory usage, to attached it to the outputfile before filling it]

So you may have meant to do:

TVectorD *PScuts;
PScuts = new TVectorD(2);

newfile[0] = new TFile(outroot[0].c_str(),"recreate");

newtree[0] = ..... way you created the tree ... maybe ... oldtree->CloneTree(0);

newtree->Branch("PScuts",&PScuts);

for (Long64_t i=0; i<nentries; ++i) {
    chain.GetEntry(i);
    LHEFEvent *event = (LHEFEvent*) branchEvent->At(0);
    (*PScuts)(0) = (*PScuts)(0)+event->Weight;
    MissingET *met = (MissingET*) branchMissingET->At(0);
    if(met->MET<70) {continue;}
    (*PScuts)(1) = (*PScuts)(1)+event->Weight;
    newtree[0]->Fill(); 
}
newtree[0]->Write();
newfile[0]->Close();

Cheers,
Philippe.

Thank you @pcanal
I did mean to write the vector outside the tree. But now it seems to me that it has to be a branch and part of the tree to successfully clone it.
Yes, I created newtree the way you mentioned.
Thanks again for the help.

Best,
Amin

Sorry to open this up again. The branch PScuts has a lot of components which I am not familiar with (attached screenshot). In this case, how can one access the two entries of the vector?

Thank you,
Amin
branch

Try double clicking on fElements (towards the bottom of the list).

Cheers,
Philippe.

PS. Also see https://root.cern.ch/doc/master/classTVectorT.html

The histogram I see has values that do not make sense. I suppose I need to access fElements with the help of the link you provided. Maybe then I can make sense of the stored values.
Thank you again.

Best,
Amin

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