@@ -744,6 +744,54 @@ Bool_t TH1::AddDirectoryStatus()
744
744
return fgAddDirectory;
745
745
}
746
746
747
+ // //////////////////////////////////////////////////////////////////////////////
748
+ // / Autozoom histogram in all their axes
749
+ // / \see TAxis::AutoZoom
750
+
751
+ void TH1::AutoZoom ()
752
+ {
753
+ const auto ndims = GetDimension ();
754
+ if (ndims < 1 || ndims > 3 )
755
+ return ;
756
+ // First apply autozoom in pure coordinate axis
757
+ if (ndims >= 1 )
758
+ GetXaxis ()->AutoZoom ();
759
+ if (ndims >= 2 )
760
+ GetYaxis ()->AutoZoom ();
761
+ if (ndims >= 3 )
762
+ GetZaxis ()->AutoZoom ();
763
+ // Now apply autozoom in the bin content axis if it's a TH1 or TH2
764
+ if (ndims == 1 )
765
+ GetYaxis ()->AutoZoom ();
766
+ else if (ndims == 2 )
767
+ GetZaxis ()->AutoZoom ();
768
+ // For 3D, there is no UnZoom or AutoZoom implemented for TPaletteAxis
769
+ }
770
+
771
+ // //////////////////////////////////////////////////////////////////////////////
772
+ // / Unzoom histogram in all their axes
773
+ // / \see TAxis::UnZoom
774
+
775
+ void TH1::UnZoom ()
776
+ {
777
+ const auto ndims = GetDimension ();
778
+ if (ndims < 1 || ndims > 3 )
779
+ return ;
780
+ // First apply Unzoom in pure coordinate axis
781
+ if (ndims >= 1 )
782
+ GetXaxis ()->UnZoom ();
783
+ if (ndims >= 2 )
784
+ GetYaxis ()->UnZoom ();
785
+ if (ndims >= 3 )
786
+ GetZaxis ()->UnZoom ();
787
+ // Now apply unzoom in the bin content axis if it's a TH1 or TH2
788
+ if (ndims == 1 )
789
+ GetYaxis ()->UnZoom ();
790
+ else if (ndims == 2 )
791
+ GetZaxis ()->UnZoom ();
792
+ // For 3D, there is no UnZoom or AutoZoom implemented for TPaletteAxis
793
+ }
794
+
747
795
// //////////////////////////////////////////////////////////////////////////////
748
796
// / Browse the Histogram object.
749
797
@@ -7904,19 +7952,143 @@ void TH1::ResetStats()
7904
7952
if (fSumw2 .fN > 0 && fTsumw > 0 && stats[1 ] > 0 ) fEntries = stats[0 ]*stats[0 ]/ stats[1 ];
7905
7953
}
7906
7954
7955
+ void TH1::GetRangeOfFilledWeights (const Int_t dim, Int_t& first, Int_t& last, const bool includeUnderOverflow) const
7956
+ {
7957
+ if (fBuffer ) const_cast <TH1*>(this )->BufferEmpty ();
7958
+
7959
+ const Int_t start = (includeUnderOverflow ? 0 : 1 );
7960
+ const Int_t lastX = fXaxis .GetNbins () + (includeUnderOverflow ? 1 : 0 );
7961
+ const Int_t lastY = fYaxis .GetNbins () + (includeUnderOverflow ? 1 : 0 );
7962
+ const Int_t lastZ = fZaxis .GetNbins () + (includeUnderOverflow ? 1 : 0 );
7963
+
7964
+ const auto ndims = GetDimension ();
7965
+ R__ASSERT (dim == 0 || dim == 1 || dim == 2 );
7966
+ if (ndims == 1 ) {
7967
+ R__ASSERT (dim == 0 );
7968
+ } else if (ndims == 2 ) {
7969
+ R__ASSERT (dim == 0 || dim == 1 );
7970
+ } else if (ndims == 3 ) {
7971
+ R__ASSERT (dim == 0 || dim == 1 || dim == 2 );
7972
+ }
7973
+
7974
+ if (dim == 0 ) {
7975
+ first = start;
7976
+ for (Int_t binx = start; binx <= lastX; binx++) {
7977
+ for (auto biny = start; biny <= lastY; biny++) {
7978
+ for (auto binz = start; binz <= lastZ; binz++) {
7979
+ auto bin = GetBin (binx, biny, binz);
7980
+ if (RetrieveBinContent (bin) != 0 || GetBinError (bin) != 0 )
7981
+ {
7982
+ first = binx;
7983
+ // Break:
7984
+ binx = lastX;
7985
+ biny = lastY;
7986
+ binz = lastZ;
7987
+ }
7988
+ }
7989
+ }
7990
+ }
7991
+ last = lastX;
7992
+ for (Int_t binx = lastX; binx >= start; binx--) {
7993
+ for (auto biny = start; biny <= lastY; biny++) {
7994
+ for (auto binz = start; binz <= lastZ; binz++) {
7995
+ auto bin = GetBin (binx, biny, binz);
7996
+ if (RetrieveBinContent (bin) != 0 || GetBinError (bin) != 0 )
7997
+ {
7998
+ last = binx;
7999
+ // Break:
8000
+ binx = start;
8001
+ biny = lastY;
8002
+ binz = lastZ;
8003
+ }
8004
+ }
8005
+ }
8006
+ }
8007
+ return ;
8008
+ } else if (dim == 1 ) {
8009
+ first = start;
8010
+ for (auto biny = start; biny <= lastY; biny++) {
8011
+ for (Int_t binx = start; binx <= lastX; binx++) {
8012
+ for (auto binz = start; binz <= lastZ; binz++) {
8013
+ auto bin = GetBin (binx, biny, binz);
8014
+ if (RetrieveBinContent (bin) != 0 || GetBinError (bin) != 0 )
8015
+ {
8016
+ first = biny;
8017
+ // Break:
8018
+ binx = lastX;
8019
+ biny = lastY;
8020
+ binz = lastZ;
8021
+ }
8022
+ }
8023
+ }
8024
+ }
8025
+ last = lastY;
8026
+ for (Int_t biny = lastY; biny >= start; biny--) {
8027
+ for (auto binx = start; binx <= lastX; binx++) {
8028
+ for (auto binz = start; binz <= lastZ; binz++) {
8029
+ auto bin = GetBin (binx, biny, binz);
8030
+ if (RetrieveBinContent (bin) != 0 || GetBinError (bin) != 0 )
8031
+ {
8032
+ last = biny;
8033
+ // Break:
8034
+ binx = lastX;
8035
+ biny = start;
8036
+ binz = lastZ;
8037
+ }
8038
+ }
8039
+ }
8040
+ }
8041
+ return ;
8042
+ } else if (dim == 2 ) {
8043
+ first = start;
8044
+ for (auto binz = start; binz <= lastZ; binz++) {
8045
+ for (Int_t binx = start; binx <= lastX; binx++) {
8046
+ for (auto biny = start; biny <= lastY; biny++) {
8047
+ auto bin = GetBin (binx, biny, binz);
8048
+ if (RetrieveBinContent (bin) != 0 || GetBinError (bin) != 0 )
8049
+ {
8050
+ first = biny;
8051
+ // Break:
8052
+ binx = lastX;
8053
+ biny = lastY;
8054
+ binz = lastZ;
8055
+ }
8056
+ }
8057
+ }
8058
+ }
8059
+ last = lastZ;
8060
+ for (Int_t binz = lastZ; binz >= start; binz--) {
8061
+ for (auto binx = start; binx <= lastX; binx++) {
8062
+ for (auto biny = start; biny <= lastY; biny++) {
8063
+ auto bin = GetBin (binx, biny, binz);
8064
+ if (RetrieveBinContent (bin) != 0 || GetBinError (bin) != 0 )
8065
+ {
8066
+ last = binz;
8067
+ // Break:
8068
+ binx = lastX;
8069
+ biny = lastY;
8070
+ binz = start;
8071
+ }
8072
+ }
8073
+ }
8074
+ }
8075
+ return ;
8076
+ }
8077
+ }
8078
+
7907
8079
// //////////////////////////////////////////////////////////////////////////////
7908
8080
// / Return the sum of all weights
7909
8081
// / \param includeOverflow true to include under/overflows bins, false to exclude those.
7910
8082
// / \note Different from TH1::GetSumOfWeights, that always excludes those
7911
8083
7912
- Double_t TH1::GetSumOfAllWeights (const bool includeOverflow ) const
8084
+ Double_t TH1::GetSumOfAllWeights (const bool includeUnderOverflow ) const
7913
8085
{
7914
8086
if (fBuffer ) const_cast <TH1*>(this )->BufferEmpty ();
7915
8087
7916
- const Int_t start = (includeOverflow ? 0 : 1 );
7917
- const Int_t lastX = fXaxis .GetNbins () + (includeOverflow ? 1 : 0 );
7918
- const Int_t lastY = fYaxis .GetNbins () + (includeOverflow ? 1 : 0 );
7919
- const Int_t lastZ = fZaxis .GetNbins () + (includeOverflow ? 1 : 0 );
8088
+ const Int_t start = (includeUnderOverflow ? 0 : 1 );
8089
+ const Int_t lastX = fXaxis .GetNbins () + (includeUnderOverflow ? 1 : 0 );
8090
+ const Int_t lastY = fYaxis .GetNbins () + (includeUnderOverflow ? 1 : 0 );
8091
+ const Int_t lastZ = fZaxis .GetNbins () + (includeUnderOverflow ? 1 : 0 );
7920
8092
Double_t sum =0 ;
7921
8093
for (auto binz = start; binz <= lastZ; binz++) {
7922
8094
for (auto biny = start; biny <= lastY; biny++) {
0 commit comments