Generate random points inside a TCutG

I have made a TCutG using a TH2 and am now looking to randomly generate and points that are inside of it.

Is there a quick way to do this?

I could generate many x,y values and just ask ‘isinside’ , but that feels very brute force.

Can ROOT ONLY generate random points that exist inside of the polygon I have drawn?

Yes IsInside() is the way:

for (int i = 0; 1<npoints ; i++) {
    generate_random_point(x,y);
    if (cutg->IsInside(x,y)) {
       keep the point...
    } else {
       reject the point...
    } 
}
1 Like