TCutG* in macro

Hi all,

I wrote a macro to plot a TH2F from TTree with a TCUT , then I define some TCutG (cut1,cut2,…)and I want to pass the cut as parameter to another macro plotting the TTree with this cut.

void macro (…TCutG* cut…){

TCutG* gate=(TCutG*)cut->Clone();
gate->SetName(“gate”);
gate->SetVarX(“sg->senA[]”);
gate->SetVarY(“sg->gen[]”);

//gate->Print();
//cut->Print();

sg->Draw(p,“gate”); //char * p is the branch to plot

}

I get no error but if I run the macro again changing cut, it seems not to consider the new gate, and the plot is not updated. :frowning:

Thanks very much if someone can help me!

Cheers,
Valentina

Could you post the strict minimum (script + data set) such that we can reproduce your problem?

Rene

Hi,

I do not know if it is correct, but deleting the gate object the script works properly.

delete gate;
gate=NULL;

Thanks.
Valentina

Hi Valentina,

Yes this is the expected behavior. Since the TCutG is retrieved by name, the first one is always used unless you delete it explicitly.

Cheers,
Philippe