Assuming we have a list of bin numbers corresponding to the white spaces, is there an efficient way to ‘modify’ the histogram by chopping those Y projections of the in numbers?
Or do I need to reconstruct the whole histogram by filling in the Y projections of the bins corresponding to non-zero entries? I am not sure, but I think this will be a more resource-intensive job.
Please share any suggestions or comments on how to go about this.
Thanks a lot for your reply,
I am trying to delete the projection of these white and replace it with the closest filled projection.
I am not sure how to do this shiting of bins here.
Hi I tried a new histogram, but I am seeing an empty histogram with non-zero entries in that statistics bar. Can you please suggest what is missing here? Thanks a lot
void RemoveGap()
{
TCanvas *c4=new TCanvas("c4","Original 2D Hist",0,550,500,250);
TCanvas *c5=new TCanvas("c5","Processed 2D Hist",550,550,500,250);
TH2 *His = Load2DHist();
c4->cd();
//Create a new histo
TH2* His_gm = new TH2D("his_gm", "", His->GetNbinsX(), 0., 3000., His->GetNbinsY(), 0., 4000.);
for(int X=14; X<400; X++) {
int x = 0;
int entries = His->Integral(X,X,0,-1);
if (entries < 1000) continue;
for (int Y = 0; Y < His->GetNbinsY(); Y++) {
His_gm->SetBinContent(x, Y, His->GetBinContent(X, Y) );
}
x=x+1; //increment x bin of the newhistogram by 1
}
c5->cd();
His_gm->Draw();
}
As a test case, I tried to copy the whole histogram with the white gaps by modifying the above macro (below).
However, there seems to be a mismatch between the entries(statistics) from the original histogram and the one created here. The mean, standard deviation and integral happen to be the same.
I am not sure what the problem is. If you use SetBinContent, the number of entries is lost, because this is related to the number of time you call the TH1::Fill function. You can get the effective entry number by calling TH1::ResetStats()
Very briefly, I have a 2d histogram and try to reproduce it by filling an empty histogram by looping across the x-axis bins followed by a nested loop in y-axis bins. However, the rebuilt histogram and the original histogram have a mismatch of entries. The mean, SD, and integral are the same.
Thanks for the explanation.
So effectively, to ensure that the entries of the original and copied histogram match, I need to reset the statistics for the copied histogram after using the SetBInContent(), right?
Yes, you can call ResetStats() or save the previous entries and reset afterwards after manipulating the histograms. This is because we cannot compete them automatically if you manipulate the histogram