Error running Macro

Can you try to make your arrays x and y std::vectors instead of double[100000], please?

Unrelated but still problematic, you are doing several floating point to integer conversion, where your result is basically “random”, e.g. g1->SetPoint(i*4, i, sum); with i being a double: it might store your intended 0.25 as 0.249999998 and that *4 and converted to int might give 0, not 1!

I don’t see anything obviously wrong, so either allow us to reproduce this by sharing the required files, or consider running valgrind (if you’re on Linux) on it to see what’s broken. See Valgrind and ROOT