How to delete a projection

Dear rooters,

I want to make a loop which creates several histograms in each step.
I want to use the feature of the automatic binning of Draw. It is more convenient for me to use the same names for the histograms each time, so at the end of each loop I delete them by “histo=0” (I also tried “delete histo” and “histo.Delete()” but I got a segmentation fault)

So the thing is that it almost work with “histo=0”. For all the first three histograms is OK, but for the fourth one, which is the projection of the third one, it keeps the same range in all the loops.

Any idea? Thanks,

nugen_numu.000159.000006.root (706 KB)
correlations.C (2.02 KB)

here is how I do it:

Th2D* 2dhist = a 2D histo;
for () {
TH1D* histPtr1 = 2dhist->ProjectionY(name1,i,i);

// do some stuff

delete histPtr1;

The problem is that the range of the histrogram changes from one iteration in the loop to another, so I cannot just to it with:

Th2D* 2dhist = a 2D histo;



I dont quite understand how range should matter.
function Projection() return pointer to a new histogram ( projection) say PTR.
You work with projection, and then use the pointer to delete it:

delete PTR;

thats all there is to it… isn’t it ? :open_mouth:

of course, you should not delete projection untill you are completely done with it.