I’m working on a script that attempts to select events from a tree using TTree->Draw() and a TCutG object. I do this by using TCutG->IsInside(x,y). I should then be able to plot 2D histograms (TH2F in my case) that show only data points that fall within the cut (as in the example here) along with, once that is working, other data associated with those selected events.
However, I am running into an issue using the IsInside function, as seen here:
tree->Draw(Form(Branch.CoordY:Branch.CoordX>>histo%d(2048,0,8192,2048,0,8192)", p), Form(“Branch.blah == %d” && (mycut->IsInside(Branch.CoordX, Branch.CoordY))", p), “goff”);
(Variable names shortened for clarity; the actual ones are pretty long).
Branch.CoordX and Branch.CoordY are floating-point numbers while mycut is a TCutG object created by a loop that loads coordinates from a file and then uses mycut->SetPoint() to turn those coordinates into a cut. The TCutG creation loop works fine in another script I have that draws it on the screen, so as far as I know the cut itself is fine.
However, this function results in a bad numerical expression/failure to compile, so I am assuming that I am likely not calling IsInside correctly. I am able to create a 2D histogram successfully if I only do the check on the value of the ‘blah’ variable.
I call goff because this code exists inside a loop that creates a bunch of histograms based on the value of another variable (hence the use of Form() in the second argument of Draw()) and then later on in the script they are written to disk, but I’m pretty sure that the presence of the goff option is not the problem. I include it here just in case.
Have I made a simple typo somewhere or have I misunderstood the proper use of the IsInside() function? What is the best way to go about doing this?
I got the idea to do the test this way from this old mailing list post.