Same as previous comment: The functions defined here are called multiple times per recovered channel. In each case there are multiple creations and deletions of TF1*. This is costly and there is really no need to use TF1.  Please define the functions that you need and remove TF1s.