Home | News | Documentation | Download

TMath::IsInside() always returns false

Hello everyone,

I’ve been trying to use the TMath::IsInside(Float_t px, Float_t py, Int_t np, Float_t* x, Float_t* y) function but its always returning false for me. Here is a link that references the definition of the function: TMath

I wrote my code in this file: thresholdPlots.cpp (10.0 KB) , where the TMath::IsInside() function is used on line 93.

Use this .root file to reproduce the results: https://drive.google.com/file/d/13fKs346wHK-iGr2lmsbG9NjC5wgZQiCG/view?usp=sharing (had to use a link since the file was too big to upload)

You need to change the content in the chain->Add() method in line 64 to the path where you have stored the .root file.

To run the code I just used the interpreter and ran root -l thresholdPlots.cpp

I’m using ROOT 5.34 on Ubuntu 18.04 LTS


Please read tips for efficient and successful posting and posting code

ROOT Version: 5.34
Platform: Ubuntu 18.04 LTS
Compiler: root interpreter CINT


Hi Juan,

I didn’t launch your code, but I wrote a small test based on it:

        Float_t signalBoxX[] = {3000.0, 4000.0, 4700.0, 4700.0, 3000.0, 3000.0};
        Float_t signalBoxY[] = {130.0, 130.0, 150.0, 250.0, 250.0, 130.0};

        constexpr Float_t xTest = 4200.;

        for (Float_t yTest = 120.; yTest < 151.; yTest += 5.)
                printf("Point (%.0f; %.0f) lays %s the signalBox\n", xTest, yTest, TMath::IsInside(xTest, yTest, 6, signalBoxX, signalBoxY)?"inside":"outside");

Everything looks good to me. Here is the output:

Point (4200; 120) lays outside the signalBox
Point (4200; 125) lays outside the signalBox
Point (4200; 130) lays outside the signalBox
Point (4200; 135) lays outside the signalBox
Point (4200; 140) lays inside the signalBox
Point (4200; 145) lays inside the signalBox
Point (4200; 150) lays inside the signalBox

This is exactly what I expected with these test values. Can you confirm this quick test of mine works fine for you, too (I’m on ROOT 6.14/04)?

Hello,

Apologies for the late reply, I ran your test and it passed all the test cases. Thank you for your help. I guess there is a bug in my code that I’m not seeing.

Yes, I suspect the bug is in these two lines of your code:

else if(Pi0Pt[0] > 120 && Pi0Pt[0] < 260 && Pi0RecZ[0] > 2900 && Pi0RecZ[0] < 5100){
    ...
    if(TMath::IsInside(static_cast<Float_t>(Pi0Pt[0]), static_cast<Float_t>(Pi0RecZ[0]), 6, signalBoxX, signalBoxY) == 1){
        ...

If the values are such that the else if returns true, then the following if will never return true. You have probably mixed up Pi0Pt and Pi0RecZ in either the else if or in the if condition.

Yes you are correct I did. Just switched them up in the if statement and everything is working fine now. Thank you for everything!