&& vs * in TTree->Draw

Hello,

I was wondering if anyone can explain why the psudocode below would print two different values instead of the same values. Please note, this is rewritten psudo-code to illustrait my confusion, and would not work if ran.

TFile* Data_File = TFile::Open( "Example ");
TTree* Data_Tree = (TTree*)Data_File->Get("MyTree");

// First Version
TH1D *h1 = new TH1D("h1","h1", 50, -1, 1 );
Data_Tree -> Draw("my_Var>>h1", "(criteria1==1)&&(criteria2>=5) * weight" ,"goff");
cout<<h1->GetSumOfWeights()<<endl;

// Second version
TH1D *h2 = new TH1D("h2","h2", 50, -1, 1 );
Data_Tree -> Draw("my_Var>>h2", "(criteria1==1)*(criteria2>=5) * weight" ,"goff");
cout<<h2->GetSumOfWeights()<<endl;

delete h1; delete h2;

Noting that the difference is in the weights and criteria string, where i put && in the first and * in the second. When i call this for my application, i get two different results.

Thank you in advance!

Matt

Try: "((criteria1==1)&&(criteria2>=5)) * weight"

Yup, that solves the discrepancy, thank you! i’m however still not sure why the brackets are needed, could you perhaps explain?

I guess, your original selection would be interpreted as: "(criteria1==1) && ((criteria2>=5) * weight)"

Ah, ok. So to perhaps clarify if i understand correctly,

in the first example, i was asking:

(true/false) and ( (true/false) * weight)

which in a “pass” test case could give

(1) and (1*weight) = (1) and (not false) = 1  

instead of the desired

(1 and 1)*weight = weight

true” = “1.”, “false” = “0.
(true / false) * value” = “(1. / 0.) * value” (i.e., = “value” or “0.”)
(true / false) && value” = “(true / false) && (value != 0.)” (i.e., = “1.” or “0.”)

Thanks!