TCutG IsInside never tests true

I am attempting to gate on a TCutG but I can’t get it to ever test true when I use the IsInside method. Please let me know if more information is needed other than what is below…

TCutG cut1(cutName.Data(),fNPoints,fX,fY);
if(cut1.IsInside(csIFast,csISlow)) printf(“cut1=in\n”);

I also tried if(cut1.IsInside(csIFast,csISlow)==1) but that also never tested true.

I double checked that the x and y values had indeed been filled into the TCutG using the GetPoint method and they all appear fine.

what am i missing?!

Can you send a small running example reproducing your problem ?

i’m not sure how to as it is part of a large and inextricably linked set of classes…created not by me. :frowning: I can try to show more of the code?

  TString cutName;
  Int_t fN[1];
  Double_t fZ[1],fA[1],fX[100],fY[100];
  Int_t detNum=73;
  cutName=Form("det%d",detNum);
  LoadPoints(detNum,fN,fZ,fA,fX,fY);
  Int_t fNPoints=fN[0];
  printf("points:%d\n",fNPoints);
  TCutG cut1(cutName.Data(),fNPoints,fX,fY);

Load points reads in the picked points of the polygon from a file given the detector number.

The program then scrolls through a large event file, event by event, and uses the cut.

if(csIFast>5 && csISlow>5 && siFront>5 && cut1.IsInside(csIFast,csISlow)) { printf("cut 1 passed\n"); hCsITestSlowVsFastFull[csIId-1]->Fill(csIFast,csISlow); fSiCounter[siId]++; }
I don’t know if this makes it any more clear…?

That does not really help as we cannot see what the cut points are. I suspect you are outside the cut. Can you draw the cut and save it in a “.C” file from the File/SaveAs menu ?

in any kind of just world this is the C file you asked for…
cut.C (1.77 KB)

Thanks. It works for me. After:

   cutg->Draw("alp");

I have added:

   Int_t i;
   i = cutg->IsInside(3000.,2000.);
   printf("%d\n",i);                         
   i = cutg->IsInside(2000.,3000.);
   printf("%d\n",i);

And, as expected, the 1st printf gives me 1 and the 2nd 0. Can you try yourself ?

It does work with how you showed it. I even got it to go through a scatter plot and only pick out the points that are inside the cut. I still can’t get it to work in my other program- but at least now I know I’m using TCutG correctly. Thanks!

I noticed in the above “C file” that the first and last points in the cut are the same. I had been trying to add points to TCutG objects and when I drew them they would never complete the polygon. That is until i added the last line in my code example below

  if(z1cut!=NULL) {delete z1cut; z1cut=NULL;};
  z1cut = new TCutG("z1cut",nz+1);
  z1cut->SetVarX("");
  z1cut->SetVarY("");
  for(Int_t i=0;i<nz+1;i++) {
	z1cut->SetPoint(i,cpntsz[0][i],cpntsz[1][i]);
  }
  z1cut->SetPoint(nz+1,cpntsz[0][0],cpntsz[1][0]);

For clarity the cpntsz array is two dimensional, one for each x-y coordinate. The last line sets the final point of the TCutG equal to the first. This apparently signifies closeure as the IsInside() function doesn’t work properly without this!

As indicated in the documentation of TCutG, it must be a closed polygon.
This remark should be probably repeated in several places.

Rene