- Timestamp:
- 11/18/03 12:13:51 (21 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 20 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/MH.cc
r2416 r2525 882 882 } 883 883 884 // -------------------------------------------------------------------------- 885 // 886 // Cuts the bins containing only zeros at the edges. 887 // 888 // A new number of bins can be defined with nbins != 0 889 // In the case of nbins == 0, no rebinning will take place 890 // 891 // Returns the new (real) number of bins 892 // 893 Int_t MH::CutEdges(TH1 *h, Int_t nbins) 894 { 895 896 TAxis* axe = h->GetXaxis(); 897 898 Int_t min1 = axe->GetFirst(); 899 Int_t max1 = axe->GetLast(); 900 Int_t range1 = max1-min1; 901 902 // 903 // Check for useless zeros 904 // 905 if (range1 == 0) 906 return 0; 907 908 Int_t min2 = 0; 909 Int_t max2 = 0; 910 911 for (int i=min1; i<=max1; i++) 912 { 913 Double_t x = h->GetBinContent(i); 914 if (x != 0.) 915 { 916 min2 = i; 917 break; 918 } 919 } 920 921 // 922 // If the histogram consists of zeros only 923 // 924 if (min2 == max1) 925 return 0; 926 927 for (int i=max1; i>=min2; i--) 928 { 929 Double_t x = h->GetBinContent(i); 930 if (x != 0.) 931 { 932 max2 = i; 933 break; 934 } 935 } 936 937 // 938 // Check for rebinning 939 // 940 if (nbins < 1) 941 { 942 axe->SetRange(min2,max2); 943 return axe->GetLast()-axe->GetFirst(); 944 } 945 946 // 947 // Appying TAxis->SetRange before ReBin does not work ... 948 // But this workaround helps quite fine 949 // 950 Axis_t min = h->GetBinLowEdge(min2); 951 Axis_t max = h->GetBinLowEdge(max2)+h->GetBinWidth(max2); 952 953 Int_t ngroup = (int)((max2-min2)*h->GetNbinsX()/nbins/(max1-min1)); 954 955 if (ngroup > 1) 956 h->Rebin(ngroup); 957 958 axe->SetRangeUser(min,max); 959 960 return axe->GetLast()-axe->GetFirst(); 961 } 962 884 963 void MH::ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin, Int_t lastybin) 885 964 { -
trunk/MagicSoft/Mars/mhist/MH.h
r2516 r2525 88 88 static void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger); 89 89 static Double_t GetMinimumGT(const TH1 &h, Double_t gt=0); 90 90 static Int_t CutEdges(TH1 *h, Int_t nbins); 91 91 92 static void ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin=-1, Int_t lastybin=9999); 92 93 static void ProjectionY(TH1D &dest, const TH2 &src, Int_t firstxbin=-1, Int_t lastxbin=9999);
Note:
See TracChangeset
for help on using the changeset viewer.