TTree::Draw with conditions and cuts

Hello,
is it possible to draw histogram specifying boolean conditions and cuts. I would like to do something like that
MyTree->Draw(“X:Y”,*mycut && “condition==true”,"")
But it does not work. Any idea?

Hi,

[quote]is it possible to draw histogram specifying boolean conditions and cuts[/quote]Yes (see the TTree::Draw documentation for a complete run down of what’s supported). Your example should work assuming ‘condition’ respect the TTree::Formula syntax.

Cheers,
Philippe.

Indeed it works, I do not know what was the problem before (maybe a syntax problem). Thanks for your answer.

I have still a little question. If I have this
MyTree->Draw(“X:Y”,*mycut && “condition==true”,"")
How can I apply weigth directly in my histogram?
Usually, I do something like
MyTree->Draw(“X:Y”,“condition==true/weigth”,"")
where weigth is attached in my tree. How to use this feature with cut?
Thanks.

Hi,

Use:MyTree->Draw("X:Y",*(mycut && "condition==true)*weigth","");

Cheers,
Phlippe.

Compiler dislikes with expression. When I type

.L mycode.C+

it says

Moreover how can I use this form if I use sprintf before?
For example

sprintf(text,"Z==%d",Z0); MyTree->Draw("X:Y",*(mycut && text")*weigth"),"");
I have the same problem as before; I got compiler error :S

Hi,

There was indeed several typos in my proposal. Here is another try :slight_smile::MyTree->Draw("X:Y",(*mycut && text)*"weigth","");(assuming ‘mycut’ is a pointer to a TCut).

Cheers,
Philippe.

This last solution works if I use uncompiled code. But in the case where I need to compile my code I got this error

[quote]error: no match for ‘operator&&’ in '* mycut && text’
note: candidates are: operator&&(bool, bool) [/quote]

Hi,

I can not reproduce this problem with the compiled code. The following compiles correctly with the trunk:

#include "TCut.h"
#include "Riostream.h"

void cuts()
{
TCut mycut("a>0");
mycut && "condition==true";
TCut c = mycut && "condition==true";
c.Print();
// c = mycut && "condition==true" * "weight";
c = (mycut && "condition==true") * "weight";
c.Print();
TCut *mycutp = &mycut;
c = ( *mycutp && "condition==true") * "weight";
c.Print();

}

Cheers,
Philippe.