EventList selecting subset of tree;problem "This error is s"

Hi,
I want to select a subset of events based on a selection given as a text string and store the results into a separate tree with the same structure as the original.

I have a little function:

TTree* makeSelectedTree(TTree* origtree,string selection){

cerr<<“applying selection: “<<selection<<” to tree: “
<GetName()<<”\n”;
TEventList* evlist=new TEventList(“cursel”);
origtree->Draw(">>cursel",
selection.c_str());
cerr<<“number of entries in the event list: “<GetN()<<”\n”;

TTree* t_clone=origtree->CloneTree(0);
//t_clone->SetName(Form("%s_%s",origtree->GetName(),selection.c_str()));
//TEventlist* evlist=(*TEventList)gDirectory->Get(selectionname.c_str());

for(int iev=0;ievGetN();iev++){
cerr<<“iev: “<<iev<<”\t-> “;
origtree->GetEntry(evlist->GetEntry(iev));
cerr<<” got entry; filling\t”;
t_clone->Fill();
cerr<<" filled\n";
}
delete evlist;

cerr<<“number of entries in the return tree: “<<t_clone->GetEntries()<<”\n”;

return t_clone;
}

origtree is read from a file. I am doing in for several files and trees in my program. On one of the trees this happens:

applying selection: TMath::Abs(tracketa)>=0.000&&TMath::Abs(tracketa)<5.000&&trackp>=0.000&&trackp<1000000000.000 to tree: t_fitdata_per_ele_IsEM_CustomMediumPID_fake
number of entries in the event list: 6167

iev: 3982 -> got entry; filling filled
iev: 3983 -> got entry; filling filled
iev: 3984 -> got entry; filling Error in TTree::Fill: Failed filling branch:t_fitdata_per_ele_IsEM_CustomMediumPID_fake.trtfrac, nbytes=-1
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(…)
Error in TTree::Fill: Failed filling branch:t_fitdata_per_ele_IsEM_CustomMediumPID_fake.nblhits, nbytes=-1
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(…)
Error in TTree::Fill: Failed filling branch:t_fitdata_per_ele_IsEM_CustomMediumPID_fake.EoverP, nbytes=-1
Error in TTree::Fill: Failed filling branch:t_fitdata_per_ele_IsEM_CustomMediumPID_fake.tracketa, nbytes=-1
Error in TTree::Fill: Failed filling branch:t_fitdata_per_ele_IsEM_CustomMediumPID_fake.trackp, nbytes=-1
filled
iev: 3985 -> got entry; filling Error in TTree::Fill: Failed filling branch:t_fitdata_per_ele_IsEM_CustomMediumPID_fake.f1, nbytes=-1
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(…)
Error in TTree::Fill: Failed filling branch:t_fitdata_per_ele_IsEM_CustomMediumPID_fake.Et, nbytes=-1
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(…)
filled
iev: 3986 -> got entry; filling filled
iev: 3987 -> got entry; filling filled
iev: 3988 -> got entry; filling filled

iev: 6165 -> got entry; filling filled
iev: 6166 -> got entry; filling filled
number of entries in the return tree: 6167

What is going on???
I tried adding line:
t_clone->SetDirectory(origtree->GetDirectory());
after the CloneTree line but this didn’t help.
Thank you for any help…

Wojtek

[quote]I tried adding line:
t_clone->SetDirectory(origtree->GetDirectory());
after the CloneTree line but this didn’t help[/quote] And it usually should not. This tell the TTree to store itself into your input file (this would work only if you opened the file in ‘update’ mode).

Most likely you just need to do:TFile *output = TFile::Open("output.root","RECREATE"); TTree* t_clone=origtree->CloneTree(0);

Cheers,
Philippe.

Hi,
That didn’t work either.
w

Hi,

It should of.

Did you check whether you ran out of disk space? If there is not such problem, then I will need a complete running example reproducing the problem.

Cheers,
Philippe.

Actually I spoke too soon - still had the previous line inside with setting the directories…
It does work,
but I don’t understand why must I have a file open - I intend the cloned tree to be only used internally in the program and don’t need it saved…

  • thanks for the hint on the workaround.
    w

Hi,

[quote]but I don’t understand why must I have a file open - I intend the cloned tree to be only used internally in the program and don’t need it saved…[/quote]Ah :slight_smile:. In this case (assuming you have enough ram to fit all the data in memory), you need:TTree* t_clone=origtree->CloneTree(0); t_clone->SetDirectory(0);

Cheers,
Philippe.