Using TSelector derived class to fill histos

What is the preferred method of filling histograms and saving them to a file from a Tree using a TSelector derived class?

I am now trying to fill TH1 and TProfile histos by defining the histos in the TSelector class, filling them in the Process function, then back in the macro Clone’ing the histos before writing them to a file. This seems to work sometimes. When I have too many histos, the Close on the file causes seg faults. The stack track seems to indicate that destruction of a TProfile is the problem but which one (the one created in the macro or the TSelector) I don’t know.

I’ve also tried explicitly creating the histos in the macro as well and using Add to get the copy from the TSelector copies and assigning the address of the Tselector copies to a pointer in the macro. All methods fail the same way.

If I comment some of my histos out of the TSelector class, then the whole thing works ok.

Any examples would be appreciated.

We need more details from your side (including a running extract of your code).

Rene