# && vs \* in TTree-\>Draw

**URL:** <https://root-forum.cern.ch/t/vs-in-ttree-draw/50628>\
**Category:** Newbie\
**Created:** [July 1, 2022, 3:29pm UTC](https://root-forum.cern.ch/t/vs-in-ttree-draw/50628 "2022-07-01T15:29:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smitmatt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/smitmatt/32/26905_2.png) [@smitmatt](https://root-forum.cern.ch/u/smitmatt)\
**Post date:** [July 1, 2022, 3:29pm UTC](https://root-forum.cern.ch/t/vs-in-ttree-draw/50628/1 "2022-07-01T15:29:43Z")

</div>

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.

```auto
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

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 1, 2022, 3:34pm UTC](https://root-forum.cern.ch/t/vs-in-ttree-draw/50628/2 "2022-07-01T15:34:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![smitmatt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/smitmatt/32/26905_2.png) [@smitmatt](https://root-forum.cern.ch/u/smitmatt)\
**Post date:** [July 1, 2022, 3:38pm UTC](https://root-forum.cern.ch/t/vs-in-ttree-draw/50628/3 "2022-07-01T15:38:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 1, 2022, 3:43pm UTC](https://root-forum.cern.ch/t/vs-in-ttree-draw/50628/4 "2022-07-01T15:43:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![smitmatt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/smitmatt/32/26905_2.png) [@smitmatt](https://root-forum.cern.ch/u/smitmatt)\
**Post date:** [July 1, 2022, 3:52pm UTC](https://root-forum.cern.ch/t/vs-in-ttree-draw/50628/5 "2022-07-01T15:52:58Z")

</div>

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

in the first example, i was asking:

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

```

which in a “pass” test case could give

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

```

instead of the desired

```auto
(1 and 1)*weight = weight

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 1, 2022, 3:59pm UTC](https://root-forum.cern.ch/t/vs-in-ttree-draw/50628/6 "2022-07-01T15:59:29Z")

</div>

“`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.`”)

---

<div class="post-metadata">

**Author:** ![smitmatt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/smitmatt/32/26905_2.png) [@smitmatt](https://root-forum.cern.ch/u/smitmatt)\
**Post date:** [July 1, 2022, 4:19pm UTC](https://root-forum.cern.ch/t/vs-in-ttree-draw/50628/7 "2022-07-01T16:19:47Z")

</div>

Thanks!
