My original code is quite long, so that reading it is boring.
Therefore to make my code clear, I would like to write various files to carry out different functions.
one is to open file to read and get TTrees and histograms inside
one is to open file to write and declare new TTrees and histograms
one is to perform the calculation using entries in TTrees and histograms
one is to close all the files
I do not want to write all of them in one file and even in a function.
Therefore I want both TTree and histogram, even TFile object, could be passed as parameters to the functions.
I find both TTree and histogram are attached to the currrent directory.
I read section Input/Output 1.2.8:
When a variable is declared on the stack in a function such as in the code below, it will be deleted when it goes out of scope.
Creating it on the heap instead of on the stack could prevent an object in a function from being deleted when it goes out of scope.
But I meet errors when I open a TFile in one file and close in main function.