Elliptical cut on a TH2F

How can I make an elliptical cut in a TH2F programmatically (e.g. in my script, I want to make a cut where I know all of the parameters of the ellipse)? I figure that there’s some way to do it with TEllipse and TCutG, but I can’t figure it out.

Jesse

If you have your TEllipse object, create a TCutg named “mycut”, fill
it via SetPoint (get some inspiration from TEllipse::PaintEllipse)

root.cern.ch/root/htmldoc/src/TE … tml#kYc2mE

and draw your TH2F with
h.Draw("[mycut]");

Rene

Okay, great. Now, the harder question. Is there a way to use a TCutG when drawing from a tree? I would imaging something like…

TCutG myCut;
myCut.SetPoint(0,15.,32.);

TH2F *h = new TH2F(“h”,“h”,100,0,10,100,0,10);
myTree->Draw(“a:b>>h”,"[myCut]");

I’m trying to draw “a:b” into a 2D histogam from a tree, but only have the elements that exist in the ellipse defined by my TCutG be entered into the histogram.

Incidentally, I just realized that I could just run through a and b entry by entry, and if they are inside an ellipse of my definition, I can just fill a histo… e.g. in pseudo programming language:

val = ((a-a0)/s1)^2 + ((b-b0)/s2)^2
if val < c then fill histo

I was just hoping there was a cool way of doing this with TEllipse somehow.

see documentation of class TCutG at:
root.cern.ch/root/htmldoc/TCutG.html

in short, if you have a TCutG named “mycut”, you can do
tree.Draw(“var”,“mycut”);

see also an example of TCutG in case you implement the event loop yourself in tutorial fit2d.C

Rene