I’m afraid I’m even more confused than you … try the attached “w2b.C” macro …
With ROOT 5 I get: [code]TH2F hold histogram exists in advance -> 0x2bc33b0
gPad -> 0x2bc33b0 -> TH1.Print Name = hold, Entries= 20, Total sum= 20
gROOT -> 0x2bc33b0 -> TH1.Print Name = hold, Entries= 20, Total sum= 20
TH2F hnew histogram DOES NOT exist in advance
gPad -> 0x2d096b0 -> TH1.Print Name = hnew, Entries= 0, Total sum= 0
gROOT -> 0x2c61c90 -> TH1.Print Name = hnew, Entries= 20, Total sum= 20[/code] So, in case “hold” existed, ROOT 5 (re)uses it in both, the “gPad” and the “gROOT”.
However, in case “hnew” did not exist, ROOT 5 creates TWO different histograms with the same name “hnew”. One histogram in “gPad” and this “hnew” histogram is NOT filled, and another one in “gROOT” and this “hnew” histogram is filled.
With ROOT 6 I get: [code]TH2F hold histogram exists in advance -> 0x3779ed0
gPad -> 0x3779ed0 -> TH1.Print Name = hold, Entries= 20, Total sum= 20
gROOT -> 0x3779ed0 -> TH1.Print Name = hold, Entries= 20, Total sum= 20
TH2F hnew histogram DOES NOT exist in advance
gPad -> 0 -> hnew
gROOT -> 0x31eab70 -> TH1.Print Name = hnew, Entries= 0, Total sum= 0
gPad -> 0x31ecd10 -> TH1.Print Name = hnew_copy, Entries= 0, Total sum= 0
gROOT -> 0x31ecd10 -> TH1.Print Name = hnew_copy, Entries= 0, Total sum= 0[/code] Again, in case “hold” existed, ROOT 6 (re)uses it in both, the “gPad” and the “gROOT”.
However, in case “hnew” did not exist, ROOT 6 creates TWO different histograms with two different names. The “gROOT” sees both, “hnew” and “hnew_copy”, while “gPad” sees only “hnew_copy”. Neither of these two new histograms is filled.
I vote for the following modifications.
- In case “hold” existed and had appropriate dimensions and binning, ROOT simply resets and fills it if “>>hold[(…)]” or continues filling without resetting (appends data) if “>>+hold[(…)]”.
- in case “hold” existed but it did not have appropriate dimensions and/or binning, it is replaced with an appropriate new “hold” histogram and then everything goes as in point 1. above.
- In case “hnew” did not exist, ROOT creates it and registers in the “gPad” (current pad) and “gDirectory” (current directory). This newly created “hnew” histogram should be filled (for both, “>>hnew[(…)]” and “>>+hnew[(…)]”).
- What concerns graphic output (i.e. what’s drawn in the canvas) -> both above cases (i.e. point 1. and 3.) should behave in EXACTLY the same way. So, either in BOTH above cases the newly filled histogram is drawn, or in BOTH above cases an additionally created TGraph / TPolyMarker3D is drawn (so that every pad will have its own TGraph / TPolyMarker3D, too).
- The above rules should work for all dimensions and any graphics options.
BTW. in one of your previous posts you write that “… the histogram can be used to define the range …”. I believe that the whole purpose of the “>>[+]hnew” feature is to get the “hnew” histogram filled. If the user wants to “define the range”, he can simply call TPad::DrawFrame in advance (note that in this case, the histogram’s range does NOT need to be the same as the pad’s range).
w2b.C (1.5 KB)