Strange behavior for TH3D projection : projectionY() delete the overflow content on X axis

Dear All,

I noticed a strange behavior for TH3D projection function.
I have a TH3D histogram which has content in overflow bin
for one axis (say x axis). I use projectionX() to get the
x projection and check the bin content for every bin surely the
overflow content is there.

But if I use projectionY() first and then take the projectionX()
and check the bin content, the content in the overflow bin is set to 0.
Why using projectionY() changes the overflow content on X axis.
Below is a macro which reproduce the problem.


#include "TH3.h"
#include "TRandom3.h"
#include <stdio.h>
#include <fstream>
#include <iostream>
void TestOverFlow(){
  TH3D  *hist_3D    = new TH3D("test3D","test3D",50,-4,4,100,-5,5,100,-3,3);
  gRandom->SetSeed();
  Float_t px,py,pz;
  for (Int_t i = 0; i < 25000; i++) {
    gRandom->Rannor(px,py);
    pz=px;
    hist_3D->Fill(px+4,py,pz);
  }

  TH1 *porjX = hist_3D->ProjectionX(Form("hist_projX%d",1), hist_3D->GetYaxis()->FindBin(-5), hist_3D->GetYaxis()->FindBin(5), hist_3D->GetZaxis()->FindBin(-3), hist_3D->GetZaxis()->FindBin(3));
  for(int j =0;j <=porjX->GetNbinsX()+1;j++){cout<<" bin "<<j<<" bin content "<<porjX->GetBinContent(j)<<endl;}
  cout<<endl<<endl;
  TH1 *porjY = hist_3D->ProjectionY(Form("hist_projY%d",1), hist_3D->GetXaxis()->FindBin(-4), hist_3D->GetXaxis()->FindBin(4), hist_3D->GetZaxis()->FindBin(-3), hist_3D->GetZaxis()->FindBin(3));
  cout<<" Taking the projection agagin "<<endl;
  TH1 *porjX2 = hist_3D->ProjectionX(Form("hist_projX2%d",1), hist_3D->GetYaxis()->FindBin(-5), hist_3D->GetYaxis()->FindBin(5), hist_3D->GetZaxis()->FindBin(-3), hist_3D->GetZaxis()->FindBin(3));
  for(int j =0;j <=porjX2->GetNbinsX()+1;j++){cout<<"2 bin "<<j<<" bin content "<<porjX2->GetBinContent(j)<<endl;}
}

I hope this behavior is for some reason which can be explained.

with regards,
Vineet

_ROOT Version:ROOT 6.14/06
_Platform:_MacOs 10.13.6
Compiler: Not Provided


@couet I think this is a bug … the problem is that each “Projection[XYZ]” method will unconditionally set axes ranges, which then remain set.

For the moment, you will need to “reset axes ranges” after each “Projection[XYZ]” method call:

  hist_3D->GetXaxis()->SetRange(); hist_3D->GetYaxis()->SetRange(); hist_3D->GetZaxis()->SetRange();

It looks like more for @moneta.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

A PR has been created to fix this problem

Thank you for reporting it

Lorenzo