One out of four TCanvas missing

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.24/02
Platform: Ubuntu
Compiler: Not Provided

I wish to create 4 different TCanvas and draw histograms on each of them separately. However, it seems like the position of canvas-> cd() matters which I have no idea why. The code and data are attached below:
analysis.C (2.7 KB)
pedestal2_2022022.root (1.6 MB)

When I run my code, C3 shows nothing but other canvases have the histogram drawn. However, once I moved all the canvas->cd() to the end of the code, everything works.
Why does this happen?

With histogram->Fit, the fit is drawn on the current canvas; in you case, you are still in c3 when you do the fits that later are used on c4, and you delete those fits, so c3 is left empty.
Either put c4->cd() right after drawing on c3, or add the option “0” when using ‘fit2’ on tmp, so that the fits don’t draw anything on c3: