Subtraction of TH1D incorrect - clone issue?

Note that the TH2::ProfileX method returns a TProfile, not a TH1D.

The two histograms (“Electron” and “Pion”) differ by an order of magnitude:

for(int i=0; i<1000; i++){
// ...
for(int i=0; i<10000; i++){

BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).