I am experiencing some weird behaviour from TEventLists.
I apply a selection to a TChain using a TEntryList, this works fine, and I output a TTree of only the selected events. Then I add some more variables to the TTree which I also wish to make cuts on. I use a TEventList to apply the second set of cuts to this TTree.
I find that if I give the TEventList the same name as the previous TEntryList then there is no seg fault but I get this error:
Error in TSelectorDraw::Begin: An object of type ‘TEntryList’ has the same name as the requested event list (elist)
And the selection does not work as it should.
When I change the name of the TEventList this causes a seg fault.
Any help with this would be greatly appreciated.
Thanks,
Ed.
P.S. I attach the stack trace, and my code with the line that causes the fault (line 212) clearly marked. stack_trace.txt (838 Bytes) TCuts.cpp (7.79 KB)
In coshel_and_Bdcosptng the address of local variable are associated with the TTree and are not reset at the end, resulting in the TTree continuing to use them eventhough their are invalid … resulting in random behavior.
The problem should be fixed by adding tree->ResetBranchAddresses(); at the very end of coshel_and_Bdcosptng.
Thanks for your quick reply, it worked great! I have another problem that I think lies in the same function coshel_and_Bdcosptng…
I have a vector of TCuts that I want to apply to a TTree one at a time. The following loop works for accessing the TCuts one at a time and applying them:
uint index;
for(index=0; index<cuts.size()-4; index++)
{
stringstream nn;
nn << index;
t->Draw((">>elist"+nn.str()).c_str(),cuts.at(index),“entrylist”);
elist = (TEntryList*)gDirectory->Get((“elist”+nn.str()).c_str());
t->SetEntryList(elist);
temp.push_back(elist->GetN());
}
//cuts is a vector of TCuts.
//temp is a vector of the sizes of the eventlists after each cut,
//this is for use outside of the function and irrelevant to this issue.
//t is the TTree being analysed.
However, when I try and access the TCuts with an iterator (preferred), then the variables that are added with the function coshel_and_Bdcosptng() are not recognised I get error messages like this:
vector::iterator iter = cuts.begin();
for(; iter<cuts.end()-4; ++iter)
{
stringstream nn;
nn << distance(cuts.begin(),iter);
t->Draw((">>elist"+nn.str()).c_str(),iter,“entrylist”);
elist = (TEntryList)gDirectory->Get((“elist”+nn.str()).c_str());
t->SetEntryList(elist);
temp.push_back(elist->GetN());
}
TCuts on variables that were already in the TTree work when they are accessed by an iterator.
Is there something else wrong in coshel_and_Bdcosptng() that could be causing this error? Or is this more of a general C++ point I am missing? Is there a better way of adding variables to a TTree?
Then I have no idea what the problem could be. The 2 piece code seems to be doing essentially the same thing.
Did you double check that the TCut prints/contain the same things (using std::cout) in both case? Did you try running the example using valgrind?
std::cout prints the same thing in both cases. I have just run it with valgrind (just did "valgrind ./myprogram.exe), but I am unsure how to interpret the output since I haven’t used this before. In any case, the same error is present.
I have also made all the code available on lxplus. It is in /afs/cern.ch/user/e/edsmith/public/prototype_selection_v1.1. If you want to look at all of it…
Just go there and do:
source compile_TCuts_test.csh
./TCuts_test.exe
The offending loop is in the function apply_selection in the file TCuts.cpp, and cosptng_and_coshel is in lib/coshel_cosptng.h
I have thought of a less than optimal workaround so there is no urgent problem, but I am very grateful for any help you can give me with this.
The error I saw was:Bdcosptng>0.99995
Error in <TTreeFormula::Compile>: Bad numerical expression : "Bdcosptng"which sounded like the tree was missing the branch and indeed when replacing: t->Draw((">>elist"+nn.str()).c_str(),*iter,"entrylist");with small->Draw((">>elist"+nn.str()).c_str(),*iter,"entrylist");the problem went away (since the branch is only present in the cloned tree).