I want to take an existing branch in an existing tree, perform cuts, then save the now reduced branch to a new tree in a new file, and I’d prefer to do it without setting branch addresses. (I have existing code that uses TCut and I’d rather not move everything over into if statements.)
TTree::CopyTree() seems the best way to do this as it lets you specify a selection. However, the examples the documentation suggests (1) do not actually use CopyTree, (2) involve setting branch addresses, and (3) do not actually work if I just try to run them. I tried following [url]Copy tree from one file to another (no changes in between) but this results in an empty tree. I have also tried[code] TCut cmid = “[some cuts]”;
TFile *oldfile = new TFile("[path to old file]",“READ”);
cout<<“oldfile opened”<<endl;
TTree oldtree = (TTree)oldfile->Get(“Lb2JpsiLTree/mytree”);
cout<<“oldtree gotten”<<endl;
TFile *newfile = new TFile("[path]/test.root",“recreate”);
cout<<“newfile recreated”<<endl;
TTree *newtree = oldtree->CopyTree(cmid);
cout<<“newtree declared as copy of oldtree”<<endl;
newtree->GetBranch(“Bs_LOKI_MASS_JpsiConstr”)->SetFile("[path]/test_small.root");
cout<<“separate file declared for Bs_LOKI_MASS_JpsiConstr”<<endl;
newtree->CopyEntries(oldtree);
cout<<“entries copied”<<endl;
newtree->Print();
cout<<“newtree printed”<<endl;
newfile->Write();
cout<<“newfile written”<<endl;
delete oldfile;
delete newfile;
cout<<“files deleted”<<endl<<“done”<<endl;
[/code]
but test_small.root doesn’t have any trees inside, and when I trymytree->Draw("Bs_LOKI_MASS_JpsiConstr")
with test.root, I end up with an enormous error output. The beginning is included below. Advice?
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Info in TCanvas::MakeDefCanvas: created default TCanvas with name c1
Warning in TFile::Init: no StreamerInfo found in /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root therefore preventing schema evolution when reading this file.
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:0, badread=1, nerrors=1, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:1, badread=1, nerrors=2, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:2, badread=1, nerrors=3, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:3, badread=1, nerrors=4, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:4, badread=1, nerrors=5, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:5, badread=1, nerrors=6, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:6, badread=1, nerrors=7, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:7, badread=1, nerrors=8, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:8, badread=1, nerrors=9, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fNbytes is incorrect (-481200332) ; trying to recover by setting it to zero
file probably overwritten: stopping reporting error messages
Error in TBranch::GetBasket: File: /afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/test_small.root at byte:-1070189243, branch:Bs_LOKI_MASS_JpsiConstr, entry:9, badread=1, nerrors=10, basketnumber=0
Error in TBasket::Streamer: The value of fKeylen is incorrect (-30713) ; trying to recover by setting it to zero