Draw plots a wrong histogram


So I made a script that creates some histograms in a loop, and I have a hitmap (TH2F) that I create before the loop and then reset it before every iteration in the loop. After creating the hitmap, I have an if statement to save e.g. the histograms with >100 entries, like shown below. Now the problem is, even when I know there is for sure only 1 histogram with Np>100, the script saves the correct histogram (with Np>100), the cout shows the correct number of entries (which is > 100), but the Draw function does not draw the correct histogram, but instead it draws the last one created in the loop (even though that histogram has <100 entries). Why is this the case? I don’t use the Draw function anywhere else in the code.

 if (Np>100) {
                                    cout<<"The number of entries is  "<<hitmap1->GetEntries()<<endl;

_ROOT Version: 6.12/04
_Platform: MacOS 10.12.6,
_Compiler: clang 9.0

may be try to add the two following lines after the Draw:


I added them in the IF statement, nope, nothing changes.

Ok in that case we would need some code reproducing the problem in order to debug it.

I got so scared that I will have to post my extremely messy code, that I found the issue :stuck_out_tongue:
Because I was doing some fitting before, I had gStyle->SetOptFit(1111); somewhere in the code. After removing this line it works fine now. Thanks!


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