In the loop of my program, when the loop variable bin=8, I have this error:
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad
and the program stops.
Here is a part of my code:
In the part of the code that you posted, nothing points to a problem with ROOT.
If you think that this is the case, could you please provide a complete reproducer inside the ROOT shell?
Please, specify also the version of your ROOT installation.
Both your Ubuntu version and ROOT version are old and now unsupported. You should try to upgrade asap.
The error that you get indicates a memory leak. Your code is too complex to understand where it happens,
but you are calling things in loops (for example Analysis) and you have to make sure that all objects created with ānewā are properly deleted. I do not see any ādeleteā call in the code.
Well, in C++, objects created with new need to be deleted with delete when not required anymore, otherwise they continue to use memory and eventually prevent proper running.
For example, in histo() you create new histograms:
If it is not the unbalanced new/deletes, my best guess would be that you are writing out of bounds somewhere.
What makes it hard to reason about your program:
There are way too many global variables. Your goal should be 0, zero, none at all; you have already more than I can count!
Way too many hardcoded numbers in your code, you never know if the arrays have the correct size
There is no checking for the number of lines in the input files you are reading. You are assuming that your array is large enough.
in C++ use constants, not #defines
all your functions are way too long. Keep then short (goal: max 1x screen height). Otherwise you canāt see what the code is doing.
keep the scope of your variables as short as possible
Given all these general comments, my recommendation would be to rewrite the code. Thatās probably not what you want, so three different suggestions that might help on the short run:
a) use a static analyzer like cppcheck or clang-tidy to spot bugs (I canāt do it without the pdbreakup.h file)
b) compile this program using a ārealā compiler (you need to add some missing headers) and use the built-in runtime checks like -fsanitize=address (or memory/undefined).
c) comment out some parts of the script and check if the problem still exists. Repeat until you find the bug.