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?
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.
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();
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.
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?
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.