TEventList interactive vs macro

Hi, I’m having a problem using a TEventList in my macro, but the same code works fine if I type it in to CINT one line at a time!

I’m using ROOT v 3.10/02, the following code is a file “mymacros.C” that I load using .L mymacros.C… Then I execute the routine using twotracks();

void twotracks() {
// Connect file generated by BaBar beta code
TFile f(“babar-data-4.root”);

ntp1->Draw(">>mylist",only2trks);

int nevt = mylist->GetN();
cout << “nevt = " << nevt << " with nphotons=nneutrals=0” << endl;

TEventList evlist = (TEventList)gDirectory->Get(“myList”);

ntp1->SetEventList(evlist); // now only scanning output list from cut above?

ntp1->Draw(“evt_pt_lab”);
}

The output histogram produced still has all events, without the cut!
Does anyone know why this would happen?

Well, this may be just a mistake in your example, but:

ntp1->Draw(">>mylist",only2trks);

Makes a global named ‘mylist’.

TEventList evlist = (TEventList)gDirectory->Get(“myList”);
You later access it via the name ‘myList’.

Possibly you have a global eventlist still in the interpreter from a previous operation called “myList” that contains all of the events without the cut? Also, if ‘myList’ doesn’t exist it will just return the highest cycle from the file, which is probably your full list.

-Jason Thomas.

Yes, you’re right. Just a typo. I feel so silly…