66 fTsumwy = fTsumwy2 = fTsumwxy = 0;
67 fTsumwz = fTsumwz2 = fTsumwxz = fTsumwyz = 0;
74 TH3::TH3(
const char *name,
const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
75 ,Int_t nbinsy,Double_t ylow,Double_t yup
76 ,Int_t nbinsz,Double_t zlow,Double_t zup)
77 :TH1(name,title,nbinsx,xlow,xup),
82 Warning(
"TH3",
"nbinsy is <=0 - set to nbinsy = 1");
86 Warning(
"TH3",
"nbinsz is <=0 - set to nbinsz = 1");
89 fYaxis.Set(nbinsy,ylow,yup);
90 fZaxis.Set(nbinsz,zlow,zup);
91 fNcells = (nbinsx+2)*(nbinsy+2)*(nbinsz+2);
92 fTsumwy = fTsumwy2 = fTsumwxy = 0;
93 fTsumwz = fTsumwz2 = fTsumwxz = fTsumwyz = 0;
100 TH3::TH3(
const char *name,
const char *title,Int_t nbinsx,
const Float_t *xbins
101 ,Int_t nbinsy,
const Float_t *ybins
102 ,Int_t nbinsz,
const Float_t *zbins)
103 :TH1(name,title,nbinsx,xbins),
107 if (nbinsy <= 0) {Warning(
"TH3",
"nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
108 if (nbinsz <= 0) nbinsz = 1;
109 if (ybins) fYaxis.Set(nbinsy,ybins);
110 else fYaxis.Set(nbinsy,0,1);
111 if (zbins) fZaxis.Set(nbinsz,zbins);
112 else fZaxis.Set(nbinsz,0,1);
113 fNcells = (nbinsx+2)*(nbinsy+2)*(nbinsz+2);
114 fTsumwy = fTsumwy2 = fTsumwxy = 0;
115 fTsumwz = fTsumwz2 = fTsumwxz = fTsumwyz = 0;
122 TH3::TH3(
const char *name,
const char *title,Int_t nbinsx,
const Double_t *xbins
123 ,Int_t nbinsy,
const Double_t *ybins
124 ,Int_t nbinsz,
const Double_t *zbins)
125 :TH1(name,title,nbinsx,xbins),
129 if (nbinsy <= 0) {Warning(
"TH3",
"nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
130 if (nbinsz <= 0) nbinsz = 1;
131 if (ybins) fYaxis.Set(nbinsy,ybins);
132 else fYaxis.Set(nbinsy,0,1);
133 if (zbins) fZaxis.Set(nbinsz,zbins);
134 else fZaxis.Set(nbinsz,0,1);
135 fNcells = (nbinsx+2)*(nbinsy+2)*(nbinsz+2);
136 fTsumwy = fTsumwy2 = fTsumwxy = 0;
137 fTsumwz = fTsumwz2 = fTsumwxz = fTsumwyz = 0;
145 TH3::TH3(
const TH3 &h) : TH1(), TAtt3D()
147 ((TH3&)h).Copy(*
this);
162 void TH3::Copy(TObject &obj)
const
165 ((TH3&)obj).fTsumwy = fTsumwy;
166 ((TH3&)obj).fTsumwy2 = fTsumwy2;
167 ((TH3&)obj).fTsumwxy = fTsumwxy;
168 ((TH3&)obj).fTsumwz = fTsumwz;
169 ((TH3&)obj).fTsumwz2 = fTsumwz2;
170 ((TH3&)obj).fTsumwxz = fTsumwxz;
171 ((TH3&)obj).fTsumwyz = fTsumwyz;
183 Int_t TH3::BufferEmpty(Int_t action)
186 if (!fBuffer)
return 0;
187 Int_t nbentries = (Int_t)fBuffer[0];
188 if (!nbentries)
return 0;
189 Double_t *buffer = fBuffer;
191 if (action == 0)
return 0;
192 nbentries = -nbentries;
197 if (CanExtendAllAxes() || fXaxis.GetXmax() <= fXaxis.GetXmin() ||
198 fYaxis.GetXmax() <= fYaxis.GetXmin() ||
199 fZaxis.GetXmax() <= fZaxis.GetXmin()) {
201 Double_t xmin = fBuffer[2];
202 Double_t xmax = xmin;
203 Double_t ymin = fBuffer[3];
204 Double_t ymax = ymin;
205 Double_t zmin = fBuffer[4];
206 Double_t zmax = zmin;
207 for (Int_t i=1;i<nbentries;i++) {
208 Double_t x = fBuffer[4*i+2];
209 if (x < xmin) xmin = x;
210 if (x > xmax) xmax = x;
211 Double_t y = fBuffer[4*i+3];
212 if (y < ymin) ymin = y;
213 if (y > ymax) ymax = y;
214 Double_t z = fBuffer[4*i+4];
215 if (z < zmin) zmin = z;
216 if (z > zmax) zmax = z;
218 if (fXaxis.GetXmax() <= fXaxis.GetXmin() || fYaxis.GetXmax() <= fYaxis.GetXmin() || fZaxis.GetXmax() <= fZaxis.GetXmin()) {
219 THLimitsFinder::GetLimitsFinder()->FindGoodLimits(
this,xmin,xmax,ymin,ymax,zmin,zmax);
222 Int_t keep = fBufferSize; fBufferSize = 0;
223 if (xmin < fXaxis.GetXmin()) ExtendAxis(xmin,&fXaxis);
224 if (xmax >= fXaxis.GetXmax()) ExtendAxis(xmax,&fXaxis);
225 if (ymin < fYaxis.GetXmin()) ExtendAxis(ymin,&fYaxis);
226 if (ymax >= fYaxis.GetXmax()) ExtendAxis(ymax,&fYaxis);
227 if (zmin < fZaxis.GetXmin()) ExtendAxis(zmin,&fZaxis);
228 if (zmax >= fZaxis.GetXmax()) ExtendAxis(zmax,&fZaxis);
235 for (Int_t i=0;i<nbentries;i++) {
236 Fill(buffer[4*i+2],buffer[4*i+3],buffer[4*i+4],buffer[4*i+1]);
240 if (action > 0) {
delete [] fBuffer; fBuffer = 0; fBufferSize = 0;}
242 if (nbentries == (Int_t)fEntries) fBuffer[0] = -nbentries;
257 Int_t TH3::BufferFill(Double_t x, Double_t y, Double_t z, Double_t w)
259 if (!fBuffer)
return -3;
260 Int_t nbentries = (Int_t)fBuffer[0];
262 nbentries = -nbentries;
263 fBuffer[0] = nbentries;
265 Double_t *buffer = fBuffer; fBuffer=0;
270 if (4*nbentries+4 >= fBufferSize) {
272 return Fill(x,y,z,w);
274 fBuffer[4*nbentries+1] = w;
275 fBuffer[4*nbentries+2] = x;
276 fBuffer[4*nbentries+3] = y;
277 fBuffer[4*nbentries+4] = z;
286 Int_t TH3::Fill(Double_t )
288 Error(
"Fill",
"Invalid signature - do nothing");
299 Int_t TH3::Fill(Double_t x, Double_t y, Double_t z)
301 if (fBuffer)
return BufferFill(x,y,z,1);
303 Int_t binx, biny, binz, bin;
305 binx = fXaxis.FindBin(x);
306 biny = fYaxis.FindBin(y);
307 binz = fZaxis.FindBin(z);
308 if (binx <0 || biny <0 || binz<0)
return -1;
309 bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
310 if (fSumw2.fN) ++fSumw2.fArray[bin];
312 if (binx == 0 || binx > fXaxis.GetNbins()) {
313 if (!GetStatOverflowsBehaviour())
return -1;
316 if (biny == 0 || biny > fYaxis.GetNbins()) {
317 if (!GetStatOverflowsBehaviour())
return -1;
319 if (binz == 0 || binz > fZaxis.GetNbins()) {
320 if (!GetStatOverflowsBehaviour())
return -1;
347 Int_t TH3::Fill(Double_t x, Double_t y, Double_t z, Double_t w)
349 if (fBuffer)
return BufferFill(x,y,z,w);
351 Int_t binx, biny, binz, bin;
353 binx = fXaxis.FindBin(x);
354 biny = fYaxis.FindBin(y);
355 binz = fZaxis.FindBin(z);
356 if (binx <0 || biny <0 || binz<0)
return -1;
357 bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
358 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2();
359 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
360 AddBinContent(bin,w);
361 if (binx == 0 || binx > fXaxis.GetNbins()) {
362 if (!GetStatOverflowsBehaviour())
return -1;
364 if (biny == 0 || biny > fYaxis.GetNbins()) {
365 if (!GetStatOverflowsBehaviour())
return -1;
367 if (binz == 0 || binz > fZaxis.GetNbins()) {
368 if (!GetStatOverflowsBehaviour())
return -1;
394 Int_t TH3::Fill(
const char *namex,
const char *namey,
const char *namez, Double_t w)
396 Int_t binx, biny, binz, bin;
398 binx = fXaxis.FindBin(namex);
399 biny = fYaxis.FindBin(namey);
400 binz = fZaxis.FindBin(namez);
401 if (binx <0 || biny <0 || binz<0)
return -1;
402 bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
403 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2();
404 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
405 AddBinContent(bin,w);
406 if (binx == 0 || binx > fXaxis.GetNbins())
return -1;
407 if (biny == 0 || biny > fYaxis.GetNbins())
return -1;
408 if (binz == 0 || binz > fZaxis.GetNbins())
return -1;
409 Double_t x = fXaxis.GetBinCenter(binx);
410 Double_t y = fYaxis.GetBinCenter(biny);
411 Double_t z = fZaxis.GetBinCenter(binz);
437 Int_t TH3::Fill(
const char *namex, Double_t y,
const char *namez, Double_t w)
439 Int_t binx, biny, binz, bin;
441 binx = fXaxis.FindBin(namex);
442 biny = fYaxis.FindBin(y);
443 binz = fZaxis.FindBin(namez);
444 if (binx <0 || biny <0 || binz<0)
return -1;
445 bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
446 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2();
447 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
448 AddBinContent(bin,w);
449 if (binx == 0 || binx > fXaxis.GetNbins())
return -1;
450 if (biny == 0 || biny > fYaxis.GetNbins()) {
451 if (!GetStatOverflowsBehaviour())
return -1;
453 if (binz == 0 || binz > fZaxis.GetNbins())
return -1;
454 Double_t x = fXaxis.GetBinCenter(binx);
455 Double_t z = fZaxis.GetBinCenter(binz);
481 Int_t TH3::Fill(
const char *namex,
const char *namey, Double_t z, Double_t w)
483 Int_t binx, biny, binz, bin;
485 binx = fXaxis.FindBin(namex);
486 biny = fYaxis.FindBin(namey);
487 binz = fZaxis.FindBin(z);
488 if (binx <0 || biny <0 || binz<0)
return -1;
489 bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
490 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2();
491 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
492 AddBinContent(bin,w);
493 if (binx == 0 || binx > fXaxis.GetNbins())
return -1;
494 if (biny == 0 || biny > fYaxis.GetNbins())
return -1;
495 if (binz == 0 || binz > fZaxis.GetNbins()) {
496 if (!GetStatOverflowsBehaviour())
return -1;
498 Double_t x = fXaxis.GetBinCenter(binx);
499 Double_t y = fYaxis.GetBinCenter(biny);
525 Int_t TH3::Fill(Double_t x,
const char *namey,
const char *namez, Double_t w)
527 Int_t binx, biny, binz, bin;
529 binx = fXaxis.FindBin(x);
530 biny = fYaxis.FindBin(namey);
531 binz = fZaxis.FindBin(namez);
532 if (binx <0 || biny <0 || binz<0)
return -1;
533 bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
534 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2();
535 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
536 AddBinContent(bin,w);
537 if (binx == 0 || binx > fXaxis.GetNbins()) {
538 if (!GetStatOverflowsBehaviour())
return -1;
540 if (biny == 0 || biny > fYaxis.GetNbins())
return -1;
541 if (binz == 0 || binz > fZaxis.GetNbins())
return -1;
542 Double_t y = fYaxis.GetBinCenter(biny);
543 Double_t z = fZaxis.GetBinCenter(binz);
569 Int_t TH3::Fill(Double_t x,
const char *namey, Double_t z, Double_t w)
571 Int_t binx, biny, binz, bin;
573 binx = fXaxis.FindBin(x);
574 biny = fYaxis.FindBin(namey);
575 binz = fZaxis.FindBin(z);
576 if (binx <0 || biny <0 || binz<0)
return -1;
577 bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
578 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2();
579 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
580 AddBinContent(bin,w);
581 if (binx == 0 || binx > fXaxis.GetNbins()) {
582 if (!GetStatOverflowsBehaviour())
return -1;
584 if (biny == 0 || biny > fYaxis.GetNbins())
return -1;
585 if (binz == 0 || binz > fZaxis.GetNbins()) {
586 if (!GetStatOverflowsBehaviour())
return -1;
588 Double_t y = fYaxis.GetBinCenter(biny);
614 Int_t TH3::Fill(Double_t x, Double_t y,
const char *namez, Double_t w)
616 Int_t binx, biny, binz, bin;
618 binx = fXaxis.FindBin(x);
619 biny = fYaxis.FindBin(y);
620 binz = fZaxis.FindBin(namez);
621 if (binx <0 || biny <0 || binz<0)
return -1;
622 bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
623 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2();
624 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
625 AddBinContent(bin,w);
626 if (binx == 0 || binx > fXaxis.GetNbins()) {
627 if (!GetStatOverflowsBehaviour())
return -1;
629 if (biny == 0 || biny > fYaxis.GetNbins()) {
630 if (!GetStatOverflowsBehaviour())
return -1;
632 if (binz == 0 || binz > fZaxis.GetNbins())
return -1;
633 Double_t z = fZaxis.GetBinCenter(binz);
668 void TH3::FillRandom(
const char *fname, Int_t ntimes)
670 Int_t bin, binx, biny, binz, ibin, loop;
671 Double_t r1, x, y,z, xv[3];
673 TObject *fobj = gROOT->GetFunction(fname);
674 if (!fobj) { Error(
"FillRandom",
"Unknown function: %s",fname);
return; }
675 TF3 *f1 =
dynamic_cast<TF3*
>( fobj );
676 if (!f1) { Error(
"FillRandom",
"Function: %s is not a TF3, is a %s",fname,fobj->IsA()->GetName());
return; }
678 TAxis & xAxis = fXaxis;
679 TAxis & yAxis = fYaxis;
680 TAxis & zAxis = fZaxis;
683 if (fXaxis.GetXmax() <= fXaxis.GetXmin() || fYaxis.GetXmax() <= fYaxis.GetXmin() || fZaxis.GetXmax() <= fZaxis.GetXmin() ) {
684 Double_t xmin,xmax,ymin,ymax,zmin,zmax;
685 f1->GetRange(xmin,ymin,zmin,xmax,ymax,zmax);
686 Info(
"FillRandom",
"Using function axis and range ([%g,%g],[%g,%g],[%g,%g])",xmin, xmax,ymin,ymax,zmin,zmax);
687 xAxis = *(f1->GetHistogram()->GetXaxis());
688 yAxis = *(f1->GetHistogram()->GetYaxis());
689 zAxis = *(f1->GetHistogram()->GetZaxis());
693 Int_t nbinsx = xAxis.GetNbins();
694 Int_t nbinsy = yAxis.GetNbins();
695 Int_t nbinsz = zAxis.GetNbins();
696 Int_t nxy = nbinsx*nbinsy;
697 Int_t nbins = nbinsx*nbinsy*nbinsz;
699 Double_t *integral =
new Double_t[nbins+1];
703 for (binz=1;binz<=nbinsz;binz++) {
704 xv[2] = zAxis.GetBinCenter(binz);
705 for (biny=1;biny<=nbinsy;biny++) {
706 xv[1] = yAxis.GetBinCenter(biny);
707 for (binx=1;binx<=nbinsx;binx++) {
708 xv[0] = xAxis.GetBinCenter(binx);
710 Double_t fint = f1->EvalPar(xv,
nullptr);
715 integral[ibin] = integral[ibin-1] + fint;
721 if (integral[nbins] == 0 ) {
723 Error(
"FillRandom",
"Integral = zero");
return;
725 for (bin=1;bin<=nbins;bin++) integral[bin] /= integral[nbins];
728 if (fDimension < 2) nbinsy = -1;
729 if (fDimension < 3) nbinsz = -1;
730 for (loop=0;loop<ntimes;loop++) {
731 r1 = gRandom->Rndm();
732 ibin = TMath::BinarySearch(nbins,&integral[0],r1);
734 biny = (ibin - nxy*binz)/nbinsx;
735 binx = 1 + ibin - nbinsx*(biny + nbinsy*binz);
738 x = xAxis.GetBinCenter(binx);
739 y = yAxis.GetBinCenter(biny);
740 z = zAxis.GetBinCenter(binz);
759 void TH3::FillRandom(TH1 *h, Int_t ntimes)
761 if (!h) { Error(
"FillRandom",
"Null histogram");
return; }
762 if (fDimension != h->GetDimension()) {
763 Error(
"FillRandom",
"Histograms with different dimensions");
return;
766 if (h->ComputeIntegral() == 0)
return;
771 for (loop=0;loop<ntimes;loop++) {
772 h3->GetRandom3(x,y,z);
809 void TH3::FitSlicesZ(TF1 *f1, Int_t binminx, Int_t binmaxx, Int_t binminy, Int_t binmaxy, Int_t cut, Option_t *option)
811 Int_t nbinsx = fXaxis.GetNbins();
812 Int_t nbinsy = fYaxis.GetNbins();
813 Int_t nbinsz = fZaxis.GetNbins();
814 if (binminx < 1) binminx = 1;
815 if (binmaxx > nbinsx) binmaxx = nbinsx;
816 if (binmaxx < binminx) {binminx = 1; binmaxx = nbinsx;}
817 if (binminy < 1) binminy = 1;
818 if (binmaxy > nbinsy) binmaxy = nbinsy;
819 if (binmaxy < binminy) {binminy = 1; binmaxy = nbinsy;}
823 f1 = (TF1*)gROOT->GetFunction(
"gaus");
824 if (f1 == 0) f1 =
new TF1(
"gaus",
"gaus",fZaxis.GetXmin(),fZaxis.GetXmax());
825 else f1->SetRange(fZaxis.GetXmin(),fZaxis.GetXmax());
827 const char *fname = f1->GetName();
828 Int_t npar = f1->GetNpar();
829 Double_t *parsave =
new Double_t[npar];
830 f1->GetParameters(parsave);
834 char name[80], title[80];
836 const TArrayD *xbins = fXaxis.GetXbins();
837 const TArrayD *ybins = fYaxis.GetXbins();
838 for (ipar=0;ipar<npar;ipar++) {
839 snprintf(name,80,
"%s_%d",GetName(),ipar);
840 snprintf(title,80,
"Fitted value of par[%d]=%s",ipar,f1->GetParName(ipar));
841 if (xbins->fN == 0) {
842 hlist[ipar] =
new TH2D(name, title,
843 nbinsx, fXaxis.GetXmin(), fXaxis.GetXmax(),
844 nbinsy, fYaxis.GetXmin(), fYaxis.GetXmax());
846 hlist[ipar] =
new TH2D(name, title,
847 nbinsx, xbins->fArray,
848 nbinsy, ybins->fArray);
850 hlist[ipar]->GetXaxis()->SetTitle(fXaxis.GetTitle());
851 hlist[ipar]->GetYaxis()->SetTitle(fYaxis.GetTitle());
853 snprintf(name,80,
"%s_chi2",GetName());
854 TH2D *hchi2 =
new TH2D(name,
"chisquare", nbinsx, fXaxis.GetXmin(), fXaxis.GetXmax()
855 , nbinsy, fYaxis.GetXmin(), fYaxis.GetXmax());
858 TH1D *hpz =
new TH1D(
"R_temp",
"_temp",nbinsz, fZaxis.GetXmin(), fZaxis.GetXmax());
859 Int_t bin,binx,biny,binz;
860 for (biny=binminy;biny<=binmaxy;biny++) {
861 Float_t y = fYaxis.GetBinCenter(biny);
862 for (binx=binminx;binx<=binmaxx;binx++) {
863 Float_t x = fXaxis.GetBinCenter(binx);
866 for (binz=1;binz<=nbinsz;binz++) {
867 bin = GetBin(binx,biny,binz);
868 Float_t w = RetrieveBinContent(bin);
869 if (w == 0)
continue;
870 hpz->Fill(fZaxis.GetBinCenter(binz),w);
871 hpz->SetBinError(binz,GetBinError(bin));
874 if (nfill < cut)
continue;
875 f1->SetParameters(parsave);
876 hpz->Fit(fname,option);
877 Int_t npfits = f1->GetNumberFitPoints();
878 if (npfits > npar && npfits >= cut) {
879 for (ipar=0;ipar<npar;ipar++) {
880 hlist[ipar]->Fill(x,y,f1->GetParameter(ipar));
881 hlist[ipar]->SetBinError(binx,biny,f1->GetParError(ipar));
883 hchi2->SetBinContent(binx,biny,f1->GetChisquare()/(npfits-npar));
895 Int_t TH3::GetBin(Int_t binx, Int_t biny, Int_t binz)
const
897 Int_t ofy = fYaxis.GetNbins() + 1;
898 if (biny < 0) biny = 0;
899 if (biny > ofy) biny = ofy;
901 Int_t ofz = fZaxis.GetNbins() + 1;
902 if (binz < 0) binz = 0;
903 if (binz > ofz) binz = ofz;
905 return TH1::GetBin(binx) + (fXaxis.GetNbins() + 2) * (biny + (fYaxis.GetNbins() + 2) * binz);
929 Double_t TH3::GetBinWithContent3(Double_t c, Int_t &binx, Int_t &biny, Int_t &binz,
930 Int_t firstx, Int_t lastx,
931 Int_t firsty, Int_t lasty,
932 Int_t firstz, Int_t lastz,
933 Double_t maxdiff)
const
935 if (fDimension != 3) {
939 Error(
"GetBinWithContent3",
"function is only valid for 3-D histograms");
942 if (firstx <= 0) firstx = 1;
943 if (lastx < firstx) lastx = fXaxis.GetNbins();
944 if (firsty <= 0) firsty = 1;
945 if (lasty < firsty) lasty = fYaxis.GetNbins();
946 if (firstz <= 0) firstz = 1;
947 if (lastz < firstz) lastz = fZaxis.GetNbins();
948 Int_t binminx = 0, binminy=0, binminz=0;
949 Double_t diff, curmax = 1.e240;
950 for (Int_t k=firstz;k<=lastz;k++) {
951 for (Int_t j=firsty;j<=lasty;j++) {
952 for (Int_t i=firstx;i<=lastx;i++) {
953 diff = TMath::Abs(GetBinContent(i,j,k)-c);
954 if (diff <= 0) {binx = i; biny=j; binz=k;
return diff;}
955 if (diff < curmax && diff <= maxdiff) {curmax = diff, binminx=i; binminy=j;binminz=k;}
969 Double_t TH3::GetCorrelationFactor(Int_t axis1, Int_t axis2)
const
971 if (axis1 < 1 || axis2 < 1 || axis1 > 3 || axis2 > 3) {
972 Error(
"GetCorrelationFactor",
"Wrong parameters");
975 if (axis1 == axis2)
return 1;
976 Double_t stddev1 = GetStdDev(axis1);
977 if (stddev1 == 0)
return 0;
978 Double_t stddev2 = GetStdDev(axis2);
979 if (stddev2 == 0)
return 0;
980 return GetCovariance(axis1,axis2)/stddev1/stddev2;
987 Double_t TH3::GetCovariance(Int_t axis1, Int_t axis2)
const
989 if (axis1 < 1 || axis2 < 1 || axis1 > 3 || axis2 > 3) {
990 Error(
"GetCovariance",
"Wrong parameters");
993 Double_t stats[kNstat];
995 Double_t sumw = stats[0];
996 Double_t sumw2 = stats[1];
997 Double_t sumwx = stats[2];
998 Double_t sumwx2 = stats[3];
999 Double_t sumwy = stats[4];
1000 Double_t sumwy2 = stats[5];
1001 Double_t sumwxy = stats[6];
1002 Double_t sumwz = stats[7];
1003 Double_t sumwz2 = stats[8];
1004 Double_t sumwxz = stats[9];
1005 Double_t sumwyz = stats[10];
1007 if (sumw == 0)
return 0;
1008 if (axis1 == 1 && axis2 == 1) {
1009 return TMath::Abs(sumwx2/sumw - sumwx*sumwx/sumw2);
1011 if (axis1 == 2 && axis2 == 2) {
1012 return TMath::Abs(sumwy2/sumw - sumwy*sumwy/sumw2);
1014 if (axis1 == 3 && axis2 == 3) {
1015 return TMath::Abs(sumwz2/sumw - sumwz*sumwz/sumw2);
1017 if ((axis1 == 1 && axis2 == 2) || (axis1 == 2 && axis2 == 1)) {
1018 return sumwxy/sumw - sumwx/sumw*sumwy/sumw;
1020 if ((axis1 == 1 && axis2 == 3) || (axis1 == 3 && axis2 == 1)) {
1021 return sumwxz/sumw - sumwx/sumw*sumwz/sumw;
1023 if ((axis1 == 2 && axis2 == 3) || (axis1 == 3 && axis2 == 2)) {
1024 return sumwyz/sumw - sumwy/sumw*sumwz/sumw;
1034 void TH3::GetRandom3(Double_t &x, Double_t &y, Double_t &z)
1036 Int_t nbinsx = GetNbinsX();
1037 Int_t nbinsy = GetNbinsY();
1038 Int_t nbinsz = GetNbinsZ();
1039 Int_t nxy = nbinsx*nbinsy;
1040 Int_t nbins = nxy*nbinsz;
1044 if (fIntegral[nbins+1] != fEntries) integral = ComputeIntegral(
true);
1045 else integral = fIntegral[nbins];
1047 integral = ComputeIntegral(
true);
1049 if (integral == 0 ) { x = 0; y = 0; z = 0;
return;}
1051 if (integral == TMath::QuietNaN() ) { x = TMath::QuietNaN(); y = TMath::QuietNaN(); z = TMath::QuietNaN();
return;}
1053 Double_t r1 = gRandom->Rndm();
1054 Int_t ibin = TMath::BinarySearch(nbins,fIntegral,(Double_t) r1);
1055 Int_t binz = ibin/nxy;
1056 Int_t biny = (ibin - nxy*binz)/nbinsx;
1057 Int_t binx = ibin - nbinsx*(biny + nbinsy*binz);
1058 x = fXaxis.GetBinLowEdge(binx+1);
1059 if (r1 > fIntegral[ibin]) x +=
1060 fXaxis.GetBinWidth(binx+1)*(r1-fIntegral[ibin])/(fIntegral[ibin+1] - fIntegral[ibin]);
1061 y = fYaxis.GetBinLowEdge(biny+1) + fYaxis.GetBinWidth(biny+1)*gRandom->Rndm();
1062 z = fZaxis.GetBinLowEdge(binz+1) + fZaxis.GetBinWidth(binz+1)*gRandom->Rndm();
1081 void TH3::GetStats(Double_t *stats)
const
1083 if (fBuffer) ((TH3*)
this)->BufferEmpty();
1085 Int_t bin, binx, biny, binz;
1088 if ((fTsumw == 0 && fEntries > 0) || fXaxis.TestBit(TAxis::kAxisRange) || fYaxis.TestBit(TAxis::kAxisRange) || fZaxis.TestBit(TAxis::kAxisRange)) {
1089 for (bin=0;bin<11;bin++) stats[bin] = 0;
1091 Int_t firstBinX = fXaxis.GetFirst();
1092 Int_t lastBinX = fXaxis.GetLast();
1093 Int_t firstBinY = fYaxis.GetFirst();
1094 Int_t lastBinY = fYaxis.GetLast();
1095 Int_t firstBinZ = fZaxis.GetFirst();
1096 Int_t lastBinZ = fZaxis.GetLast();
1098 if (GetStatOverflowsBehaviour()) {
1099 if ( !fXaxis.TestBit(TAxis::kAxisRange) ) {
1100 if (firstBinX == 1) firstBinX = 0;
1101 if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1;
1103 if ( !fYaxis.TestBit(TAxis::kAxisRange) ) {
1104 if (firstBinY == 1) firstBinY = 0;
1105 if (lastBinY == fYaxis.GetNbins() ) lastBinY += 1;
1107 if ( !fZaxis.TestBit(TAxis::kAxisRange) ) {
1108 if (firstBinZ == 1) firstBinZ = 0;
1109 if (lastBinZ == fZaxis.GetNbins() ) lastBinZ += 1;
1112 for (binz = firstBinZ; binz <= lastBinZ; binz++) {
1113 z = fZaxis.GetBinCenter(binz);
1114 for (biny = firstBinY; biny <= lastBinY; biny++) {
1115 y = fYaxis.GetBinCenter(biny);
1116 for (binx = firstBinX; binx <= lastBinX; binx++) {
1117 bin = GetBin(binx,biny,binz);
1118 x = fXaxis.GetBinCenter(binx);
1120 w = RetrieveBinContent(bin);
1121 err = TMath::Abs(GetBinError(bin));
1123 stats[1] += err*err;
1140 stats[3] = fTsumwx2;
1142 stats[5] = fTsumwy2;
1143 stats[6] = fTsumwxy;
1145 stats[8] = fTsumwz2;
1146 stats[9] = fTsumwxz;
1147 stats[10]= fTsumwyz;
1158 Double_t TH3::Integral(Option_t *option)
const
1160 return Integral(fXaxis.GetFirst(),fXaxis.GetLast(),
1161 fYaxis.GetFirst(),fYaxis.GetLast(),
1162 fZaxis.GetFirst(),fZaxis.GetLast(),option);
1173 Double_t TH3::Integral(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2,
1174 Int_t binz1, Int_t binz2, Option_t *option)
const
1177 return DoIntegral(binx1,binx2,biny1,biny2,binz1,binz2,err,option);
1189 Double_t TH3::IntegralAndError(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2,
1190 Int_t binz1, Int_t binz2,
1191 Double_t & error, Option_t *option)
const
1193 return DoIntegral(binx1,binx2,biny1,biny2,binz1,binz2,error,option,kTRUE);
1199 Double_t TH3::Interpolate(Double_t)
const
1201 Error(
"Interpolate",
"This function must be called with 3 arguments for a TH3");
1209 Double_t TH3::Interpolate(Double_t, Double_t)
const
1211 Error(
"Interpolate",
"This function must be called with 3 arguments for a TH3");
1226 Double_t TH3::Interpolate(Double_t x, Double_t y, Double_t z)
const
1228 Int_t ubx = fXaxis.FindFixBin(x);
1229 if ( x < fXaxis.GetBinCenter(ubx) ) ubx -= 1;
1230 Int_t obx = ubx + 1;
1232 Int_t uby = fYaxis.FindFixBin(y);
1233 if ( y < fYaxis.GetBinCenter(uby) ) uby -= 1;
1234 Int_t oby = uby + 1;
1236 Int_t ubz = fZaxis.FindFixBin(z);
1237 if ( z < fZaxis.GetBinCenter(ubz) ) ubz -= 1;
1238 Int_t obz = ubz + 1;
1243 if (ubx <=0 || uby <=0 || ubz <= 0 ||
1244 obx > fXaxis.GetNbins() || oby > fYaxis.GetNbins() || obz > fZaxis.GetNbins() ) {
1245 Error(
"Interpolate",
"Cannot interpolate outside histogram domain.");
1249 Double_t xw = fXaxis.GetBinCenter(obx) - fXaxis.GetBinCenter(ubx);
1250 Double_t yw = fYaxis.GetBinCenter(oby) - fYaxis.GetBinCenter(uby);
1251 Double_t zw = fZaxis.GetBinCenter(obz) - fZaxis.GetBinCenter(ubz);
1253 Double_t xd = (x - fXaxis.GetBinCenter(ubx)) / xw;
1254 Double_t yd = (y - fYaxis.GetBinCenter(uby)) / yw;
1255 Double_t zd = (z - fZaxis.GetBinCenter(ubz)) / zw;
1258 Double_t v[] = { GetBinContent( ubx, uby, ubz ), GetBinContent( ubx, uby, obz ),
1259 GetBinContent( ubx, oby, ubz ), GetBinContent( ubx, oby, obz ),
1260 GetBinContent( obx, uby, ubz ), GetBinContent( obx, uby, obz ),
1261 GetBinContent( obx, oby, ubz ), GetBinContent( obx, oby, obz ) };
1264 Double_t i1 = v[0] * (1 - zd) + v[1] * zd;
1265 Double_t i2 = v[2] * (1 - zd) + v[3] * zd;
1266 Double_t j1 = v[4] * (1 - zd) + v[5] * zd;
1267 Double_t j2 = v[6] * (1 - zd) + v[7] * zd;
1270 Double_t w1 = i1 * (1 - yd) + i2 * yd;
1271 Double_t w2 = j1 * (1 - yd) + j2 * yd;
1274 Double_t result = w1 * (1 - xd) + w2 * xd;
1300 Double_t TH3::KolmogorovTest(
const TH1 *h2, Option_t *option)
const
1302 TString opt = option;
1306 TH1 *h1 = (TH1*)
this;
1307 if (h2 == 0)
return 0;
1308 const TAxis *xaxis1 = h1->GetXaxis();
1309 const TAxis *xaxis2 = h2->GetXaxis();
1310 const TAxis *yaxis1 = h1->GetYaxis();
1311 const TAxis *yaxis2 = h2->GetYaxis();
1312 const TAxis *zaxis1 = h1->GetZaxis();
1313 const TAxis *zaxis2 = h2->GetZaxis();
1314 Int_t ncx1 = xaxis1->GetNbins();
1315 Int_t ncx2 = xaxis2->GetNbins();
1316 Int_t ncy1 = yaxis1->GetNbins();
1317 Int_t ncy2 = yaxis2->GetNbins();
1318 Int_t ncz1 = zaxis1->GetNbins();
1319 Int_t ncz2 = zaxis2->GetNbins();
1322 if (h1->GetDimension() != 3 || h2->GetDimension() != 3) {
1323 Error(
"KolmogorovTest",
"Histograms must be 3-D\n");
1329 Error(
"KolmogorovTest",
"Number of channels in X is different, %d and %d\n",ncx1,ncx2);
1333 Error(
"KolmogorovTest",
"Number of channels in Y is different, %d and %d\n",ncy1,ncy2);
1337 Error(
"KolmogorovTest",
"Number of channels in Z is different, %d and %d\n",ncz1,ncz2);
1342 Bool_t afunc1 = kFALSE;
1343 Bool_t afunc2 = kFALSE;
1344 Double_t difprec = 1e-5;
1345 Double_t diff1 = TMath::Abs(xaxis1->GetXmin() - xaxis2->GetXmin());
1346 Double_t diff2 = TMath::Abs(xaxis1->GetXmax() - xaxis2->GetXmax());
1347 if (diff1 > difprec || diff2 > difprec) {
1348 Error(
"KolmogorovTest",
"histograms with different binning along X");
1351 diff1 = TMath::Abs(yaxis1->GetXmin() - yaxis2->GetXmin());
1352 diff2 = TMath::Abs(yaxis1->GetXmax() - yaxis2->GetXmax());
1353 if (diff1 > difprec || diff2 > difprec) {
1354 Error(
"KolmogorovTest",
"histograms with different binning along Y");
1357 diff1 = TMath::Abs(zaxis1->GetXmin() - zaxis2->GetXmin());
1358 diff2 = TMath::Abs(zaxis1->GetXmax() - zaxis2->GetXmax());
1359 if (diff1 > difprec || diff2 > difprec) {
1360 Error(
"KolmogorovTest",
"histograms with different binning along Z");
1365 Int_t ibeg = 1, jbeg = 1, kbeg = 1;
1366 Int_t iend = ncx1, jend = ncy1, kend = ncz1;
1367 if (opt.Contains(
"U")) {ibeg = 0; jbeg = 0; kbeg = 0;}
1368 if (opt.Contains(
"O")) {iend = ncx1+1; jend = ncy1+1; kend = ncz1+1;}
1375 for (i = ibeg; i <= iend; i++) {
1376 for (j = jbeg; j <= jend; j++) {
1377 for (k = kbeg; k <= kend; k++) {
1378 bin = h1->GetBin(i,j,k);
1379 sum1 += h1->GetBinContent(bin);
1380 sum2 += h2->GetBinContent(bin);
1381 Double_t ew1 = h1->GetBinError(bin);
1382 Double_t ew2 = h2->GetBinError(bin);
1392 Error(
"KolmogorovTest",
"Integral is zero for h1=%s\n",h1->GetName());
1396 Error(
"KolmogorovTest",
"Integral is zero for h2=%s\n",h2->GetName());
1402 Double_t esum1 = 0, esum2 = 0;
1404 esum1 = sum1 * sum1 / w1;
1409 esum2 = sum2 * sum2 / w2;
1413 if (afunc2 && afunc1) {
1414 Error(
"KolmogorovTest",
"Errors are zero for both histograms\n");
1420 int order[3] = {0,1,2};
1424 binbeg[0] = ibeg; binbeg[1] = jbeg; binbeg[2] = kbeg;
1425 binend[0] = iend; binend[1] = jend; binend[2] = kend;
1428 Double_t s1 = 1./(6.*sum1);
1429 Double_t s2 = 1./(6.*sum2);
1430 Double_t rsum1=0, rsum2=0;
1434 for (i = binbeg[order[0] ]; i <= binend[order[0] ]; i++) {
1435 for ( j = binbeg[order[1] ]; j <= binend[order[1] ]; j++) {
1436 for ( k = binbeg[order[2] ]; k <= binend[order[2] ]; k++) {
1437 ibin[ order[0] ] = i;
1438 ibin[ order[1] ] = j;
1439 ibin[ order[2] ] = k;
1440 bin = h1->GetBin(ibin[0],ibin[1],ibin[2]);
1441 rsum1 += s1*h1->GetBinContent(bin);
1442 rsum2 += s2*h2->GetBinContent(bin);
1443 dmax = TMath::Max(dmax, TMath::Abs(rsum1-rsum2));
1447 vdfmax[icomb] = dmax;
1449 }
while (TMath::Permute(3,order) );
1453 Double_t dfmax = TMath::Mean(6,vdfmax);
1457 if (afunc1) factnm = TMath::Sqrt(sum2);
1458 else if (afunc2) factnm = TMath::Sqrt(sum1);
1459 else factnm = TMath::Sqrt(sum1*sum2/(sum1+sum2));
1460 Double_t z = dfmax*factnm;
1462 prb = TMath::KolmogorovProb(z);
1464 Double_t prb1 = 0, prb2 = 0;
1466 if (opt.Contains(
"N") && !(afunc1 || afunc2 ) ) {
1469 Double_t d12 = esum1-esum2;
1470 Double_t chi2 = d12*d12/(esum1+esum2);
1471 prb2 = TMath::Prob(chi2,1);
1473 if (prb > 0 && prb2 > 0) prb = prb*prb2*(1-TMath::Log(prb*prb2));
1478 if (opt.Contains(
"D")) {
1479 printf(
" Kolmo Prob h1 = %s, sum1=%g\n",h1->GetName(),sum1);
1480 printf(
" Kolmo Prob h2 = %s, sum2=%g\n",h2->GetName(),sum2);
1481 printf(
" Kolmo Probabil = %f, Max Dist = %g\n",prb,dfmax);
1482 if (opt.Contains(
"N"))
1483 printf(
" Kolmo Probabil = %f for shape alone, =%f for normalisation alone\n",prb1,prb2);
1486 if (TMath::Abs(rsum1-1) > 0.002) Warning(
"KolmogorovTest",
"Numerical problems with h1=%s\n",h1->GetName());
1487 if (TMath::Abs(rsum2-1) > 0.002) Warning(
"KolmogorovTest",
"Numerical problems with h2=%s\n",h2->GetName());
1489 if (opt.Contains(
"M"))
return dfmax;
1515 TH1D *TH3::ProjectionX(
const char *name, Int_t iymin, Int_t iymax,
1516 Int_t izmin, Int_t izmax, Option_t *option)
const
1519 TString hname = name;
1520 if (hname ==
"_px") hname = TString::Format(
"%s%s", GetName(), name);
1521 TString title = TString::Format(
"%s ( Projection X )",GetTitle());
1524 return DoProject1D(hname, title, iymin, iymax, izmin, izmax, &fXaxis, &fYaxis, &fZaxis, option);
1548 TH1D *TH3::ProjectionY(
const char *name, Int_t ixmin, Int_t ixmax,
1549 Int_t izmin, Int_t izmax, Option_t *option)
const
1551 TString hname = name;
1552 if (hname ==
"_py") hname = TString::Format(
"%s%s", GetName(), name);
1553 TString title = TString::Format(
"%s ( Projection Y )",GetTitle());
1556 return DoProject1D(hname, title, ixmin, ixmax, izmin, izmax, &fYaxis, &fXaxis, &fZaxis, option);
1580 TH1D *TH3::ProjectionZ(
const char *name, Int_t ixmin, Int_t ixmax,
1581 Int_t iymin, Int_t iymax, Option_t *option)
const
1584 TString hname = name;
1585 if (hname ==
"_pz") hname = TString::Format(
"%s%s", GetName(), name);
1586 TString title = TString::Format(
"%s ( Projection Z )",GetTitle());
1589 return DoProject1D(hname, title, ixmin, ixmax, iymin, iymax, &fZaxis, &fXaxis, &fYaxis, option);
1597 TH1D *TH3::DoProject1D(
const char* name,
const char * title,
int imin1,
int imax1,
int imin2,
int imax2,
1598 const TAxis* projAxis,
const TAxis * axis1,
const TAxis * axis2, Option_t * option)
const
1601 TString opt = option;
1617 out1.SetRange(imin1, imax1);
1618 out2.SetRange(imin2, imax2);
1620 Bool_t computeErrors = GetSumw2N();
1621 if (opt.Contains(
"e") ) {
1622 computeErrors = kTRUE;
1623 opt.Remove(opt.First(
"e"),1);
1625 Bool_t originalRange = kFALSE;
1626 if (opt.Contains(
'o') ) {
1627 originalRange = kTRUE;
1628 opt.Remove(opt.First(
"o"),1);
1631 TH1D * h1 = DoProject1D(name, title, projAxis, &out1, &out2, computeErrors, originalRange,
true,
true);
1640 if (h1 && opt.Contains(
"d")) {
1641 opt.Remove(opt.First(
"d"),1);
1642 TVirtualPad *padsav = gPad;
1643 TVirtualPad *pad = gROOT->GetSelectedPad();
1645 if (!gPad || !gPad->FindObject(h1)) {
1650 if (padsav) padsav->cd();
1660 TH1D *TH3::DoProject1D(
const char* name,
const char * title,
const TAxis* projX,
1661 const TAxis * out1,
const TAxis * out2,
1662 bool computeErrors,
bool originalRange,
1663 bool useUF,
bool useOF)
const
1670 Int_t ixmin = std::max(projX->GetFirst(),1);
1671 Int_t ixmax = std::min(projX->GetLast(),projX->GetNbins());
1672 Int_t nx = ixmax-ixmin+1;
1675 TObject *h1obj = gROOT->FindObject(name);
1676 if (h1obj && h1obj->InheritsFrom(TH1::Class())) {
1677 if (h1obj->IsA() != TH1D::Class() ) {
1678 Error(
"DoProject1D",
"Histogram with name %s must be a TH1D and is a %s",name,h1obj->ClassName());
1684 const TArrayD *bins = projX->GetXbins();
1685 if ( originalRange )
1687 if (bins->fN == 0) {
1688 h1->SetBins(projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1690 h1->SetBins(projX->GetNbins(),bins->fArray);
1693 if (bins->fN == 0) {
1694 h1->SetBins(nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1696 h1->SetBins(nx,&bins->fArray[ixmin-1]);
1702 const TArrayD *bins = projX->GetXbins();
1703 if ( originalRange )
1705 if (bins->fN == 0) {
1706 h1 =
new TH1D(name,title,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1708 h1 =
new TH1D(name,title,projX->GetNbins(),bins->fArray);
1711 if (bins->fN == 0) {
1712 h1 =
new TH1D(name,title,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1714 h1 =
new TH1D(name,title,nx,&bins->fArray[ixmin-1]);
1720 h1->GetXaxis()->ImportAttributes(projX);
1721 THashList* labels = projX->GetLabels();
1726 while ((lb=(TObjString*)iL())) {
1727 h1->GetXaxis()->SetBinLabel(i,lb->String().Data());
1731 h1->SetLineColor(this->GetLineColor());
1732 h1->SetFillColor(this->GetFillColor());
1733 h1->SetMarkerColor(this->GetMarkerColor());
1734 h1->SetMarkerStyle(this->GetMarkerStyle());
1737 if ( computeErrors && (h1->GetSumw2N() != h1->GetNcells() ) ) h1->Sumw2();
1741 if (out1 ==
nullptr && out2 ==
nullptr) {
1742 if (projX == GetXaxis()) {
1745 }
else if (projX == GetYaxis()) {
1753 R__ASSERT(out1 !=
nullptr && out2 !=
nullptr);
1755 Int_t *refX = 0, *refY = 0, *refZ = 0;
1756 Int_t ixbin, out1bin, out2bin;
1757 if (projX == GetXaxis()) {
1762 if (projX == GetYaxis()) {
1767 if (projX == GetZaxis()) {
1772 R__ASSERT (refX != 0 && refY != 0 && refZ != 0);
1776 Double_t totcont = 0;
1778 Int_t out1min = out1->GetFirst();
1779 Int_t out1max = out1->GetLast();
1783 if (useUF && !out1->TestBit(TAxis::kAxisRange) ) out1min -= 1;
1784 if (useOF && !out1->TestBit(TAxis::kAxisRange) ) out1max += 1;
1785 Int_t out2min = out2->GetFirst();
1786 Int_t out2max = out2->GetLast();
1788 if (useUF && !out2->TestBit(TAxis::kAxisRange) ) out2min -= 1;
1789 if (useOF && !out2->TestBit(TAxis::kAxisRange) ) out2max += 1;
1791 for (ixbin=0;ixbin<=1+projX->GetNbins();ixbin++) {
1792 if ( projX->TestBit(TAxis::kAxisRange) && ( ixbin < ixmin || ixbin > ixmax ))
continue;
1798 for (out1bin = out1min; out1bin <= out1max; out1bin++) {
1799 for (out2bin = out2min; out2bin <= out2max; out2bin++) {
1801 Int_t bin = GetBin(*refX, *refY, *refZ);
1804 cont += RetrieveBinContent(bin);
1805 if (computeErrors) {
1806 Double_t exyz = GetBinError(bin);
1811 Int_t ix = h1->FindBin( projX->GetBinCenter(ixbin) );
1812 h1->SetBinContent(ix ,cont);
1813 if (computeErrors) h1->SetBinError(ix, TMath::Sqrt(err2) );
1823 bool resetStats =
true;
1824 double eps = 1.E-12;
1825 if (IsA() == TH3F::Class() ) eps = 1.E-6;
1826 if (fTsumw != 0 && TMath::Abs( fTsumw - totcont) < TMath::Abs(fTsumw) * eps) resetStats =
false;
1828 bool resetEntries = resetStats;
1830 resetEntries |= !useUF || !useOF;
1834 Double_t stats[kNstat];
1836 if ( projX == GetYaxis() ) {
1837 stats[2] = stats[4];
1838 stats[3] = stats[5];
1840 else if ( projX == GetZaxis() ) {
1841 stats[2] = stats[7];
1842 stats[3] = stats[8];
1844 h1->PutStats(stats);
1854 Double_t entries = TMath::Floor( totcont + 0.5);
1855 if (computeErrors) entries = h1->GetEffectiveEntries();
1856 h1->SetEntries( entries );
1859 h1->SetEntries( fEntries );
1870 TH2D *TH3::DoProject2D(
const char* name,
const char * title,
const TAxis* projX,
const TAxis* projY,
1871 bool computeErrors,
bool originalRange,
1872 bool useUF,
bool useOF)
const
1877 Int_t ixmin = std::max(projX->GetFirst(),1);
1878 Int_t ixmax = std::min(projX->GetLast(),projX->GetNbins());
1879 Int_t iymin = std::max(projY->GetFirst(),1);
1880 Int_t iymax = std::min(projY->GetLast(),projY->GetNbins());
1882 Int_t nx = ixmax-ixmin+1;
1883 Int_t ny = iymax-iymin+1;
1888 TObject *h2obj = gROOT->FindObject(name);
1889 if (h2obj && h2obj->InheritsFrom(TH1::Class())) {
1890 if ( h2obj->IsA() != TH2D::Class() ) {
1891 Error(
"DoProject2D",
"Histogram with name %s must be a TH2D and is a %s",name,h2obj->ClassName());
1897 const TArrayD *xbins = projX->GetXbins();
1898 const TArrayD *ybins = projY->GetXbins();
1899 if ( originalRange ) {
1900 h2->SetBins(projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1901 ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1904 h2->GetXaxis()->Set(projY->GetNbins(),&ybins->fArray[iymin-1]);
1906 h2->GetYaxis()->Set(projX->GetNbins(),&xbins->fArray[ixmin-1]);
1908 h2->SetBins(ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1909 ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1911 h2->GetXaxis()->Set(ny,&ybins->fArray[iymin-1]);
1913 h2->GetYaxis()->Set(nx,&xbins->fArray[ixmin-1]);
1919 const TArrayD *xbins = projX->GetXbins();
1920 const TArrayD *ybins = projY->GetXbins();
1921 if ( originalRange )
1923 if (xbins->fN == 0 && ybins->fN == 0) {
1924 h2 =
new TH2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1925 ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1926 }
else if (ybins->fN == 0) {
1927 h2 =
new TH2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1928 ,projX->GetNbins(),&xbins->fArray[ixmin-1]);
1929 }
else if (xbins->fN == 0) {
1930 h2 =
new TH2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1]
1931 ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1933 h2 =
new TH2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1],projX->GetNbins(),&xbins->fArray[ixmin-1]);
1936 if (xbins->fN == 0 && ybins->fN == 0) {
1937 h2 =
new TH2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1938 ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1939 }
else if (ybins->fN == 0) {
1940 h2 =
new TH2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1941 ,nx,&xbins->fArray[ixmin-1]);
1942 }
else if (xbins->fN == 0) {
1943 h2 =
new TH2D(name,title,ny,&ybins->fArray[iymin-1]
1944 ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1946 h2 =
new TH2D(name,title,ny,&ybins->fArray[iymin-1],nx,&xbins->fArray[ixmin-1]);
1952 THashList* labels1 = 0;
1953 THashList* labels2 = 0;
1955 h2->GetXaxis()->ImportAttributes(projY);
1956 h2->GetYaxis()->ImportAttributes(projX);
1957 labels1 = projY->GetLabels();
1958 labels2 = projX->GetLabels();
1963 while ((lb=(TObjString*)iL())) {
1964 h2->GetXaxis()->SetBinLabel(i,lb->String().Data());
1972 while ((lb=(TObjString*)iL())) {
1973 h2->GetYaxis()->SetBinLabel(i,lb->String().Data());
1977 h2->SetLineColor(this->GetLineColor());
1978 h2->SetFillColor(this->GetFillColor());
1979 h2->SetMarkerColor(this->GetMarkerColor());
1980 h2->SetMarkerStyle(this->GetMarkerStyle());
1983 if ( computeErrors && (h2->GetSumw2N() != h2->GetNcells()) ) h2->Sumw2();
1986 const TAxis* out = 0;
1987 if ( projX != GetXaxis() && projY != GetXaxis() ) {
1989 }
else if ( projX != GetYaxis() && projY != GetYaxis() ) {
1995 Int_t *refX = 0, *refY = 0, *refZ = 0;
1996 Int_t ixbin, iybin, outbin;
1997 if ( projX == GetXaxis() && projY == GetYaxis() ) { refX = &ixbin; refY = &iybin; refZ = &outbin; }
1998 if ( projX == GetYaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &ixbin; refZ = &outbin; }
1999 if ( projX == GetXaxis() && projY == GetZaxis() ) { refX = &ixbin; refY = &outbin; refZ = &iybin; }
2000 if ( projX == GetZaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &outbin; refZ = &ixbin; }
2001 if ( projX == GetYaxis() && projY == GetZaxis() ) { refX = &outbin; refY = &ixbin; refZ = &iybin; }
2002 if ( projX == GetZaxis() && projY == GetYaxis() ) { refX = &outbin; refY = &iybin; refZ = &ixbin; }
2003 R__ASSERT (refX != 0 && refY != 0 && refZ != 0);
2007 Double_t totcont = 0;
2009 Int_t outmin = out->GetFirst();
2010 Int_t outmax = out->GetLast();
2012 if (outmin == 0 && outmax == 0) { outmin = 1; outmax = out->GetNbins(); }
2014 if (useUF && !out->TestBit(TAxis::kAxisRange) ) outmin -= 1;
2015 if (useOF && !out->TestBit(TAxis::kAxisRange) ) outmax += 1;
2017 for (ixbin=0;ixbin<=1+projX->GetNbins();ixbin++) {
2018 if ( projX->TestBit(TAxis::kAxisRange) && ( ixbin < ixmin || ixbin > ixmax ))
continue;
2019 Int_t ix = h2->GetYaxis()->FindBin( projX->GetBinCenter(ixbin) );
2021 for (iybin=0;iybin<=1+projY->GetNbins();iybin++) {
2022 if ( projY->TestBit(TAxis::kAxisRange) && ( iybin < iymin || iybin > iymax ))
continue;
2023 Int_t iy = h2->GetXaxis()->FindBin( projY->GetBinCenter(iybin) );
2029 for (outbin = outmin; outbin <= outmax; outbin++) {
2031 Int_t bin = GetBin(*refX,*refY,*refZ);
2034 cont += RetrieveBinContent(bin);
2035 if (computeErrors) {
2036 Double_t exyz = GetBinError(bin);
2043 h2->SetBinContent(iy , ix, cont);
2044 if (computeErrors) h2->SetBinError(iy, ix, TMath::Sqrt(err2) );
2053 bool resetStats =
true;
2054 double eps = 1.E-12;
2055 if (IsA() == TH3F::Class() ) eps = 1.E-6;
2056 if (fTsumw != 0 && TMath::Abs( fTsumw - totcont) < TMath::Abs(fTsumw) * eps) resetStats =
false;
2058 bool resetEntries = resetStats;
2060 resetEntries |= !useUF || !useOF;
2063 Double_t stats[kNstat];
2064 Double_t oldst[kNstat];
2065 for (Int_t i = 0; i < kNstat; ++i) { oldst[i] = 0; }
2067 std::copy(oldst,oldst+kNstat,stats);
2070 if ( projY == GetXaxis() && projX == GetZaxis() ) {
2071 stats[4] = oldst[7];
2072 stats[5] = oldst[8];
2073 stats[6] = oldst[9];
2075 if ( projY == GetYaxis() ) {
2076 stats[2] = oldst[4];
2077 stats[3] = oldst[5];
2078 if ( projX == GetXaxis() ) {
2079 stats[4] = oldst[2];
2080 stats[5] = oldst[3];
2082 if ( projX == GetZaxis() ) {
2083 stats[4] = oldst[7];
2084 stats[5] = oldst[8];
2085 stats[6] = oldst[10];
2088 else if ( projY == GetZaxis() ) {
2089 stats[2] = oldst[7];
2090 stats[3] = oldst[8];
2091 if ( projX == GetXaxis() ) {
2092 stats[4] = oldst[2];
2093 stats[5] = oldst[3];
2094 stats[6] = oldst[9];
2096 if ( projX == GetYaxis() ) {
2097 stats[4] = oldst[4];
2098 stats[5] = oldst[5];
2099 stats[6] = oldst[10];
2103 h2->PutStats(stats);
2113 Double_t entries = h2->GetEffectiveEntries();
2114 if (!computeErrors) entries = TMath::Floor( entries + 0.5);
2115 h2->SetEntries( entries );
2118 h2->SetEntries( fEntries );
2172 TH1 *TH3::Project3D(Option_t *option)
const
2174 TString opt = option; opt.ToLower();
2177 if (opt.Contains(
"x")) { pcase = 1; ptype =
"x"; }
2178 if (opt.Contains(
"y")) { pcase = 2; ptype =
"y"; }
2179 if (opt.Contains(
"z")) { pcase = 3; ptype =
"z"; }
2180 if (opt.Contains(
"xy")) { pcase = 4; ptype =
"xy"; }
2181 if (opt.Contains(
"yx")) { pcase = 5; ptype =
"yx"; }
2182 if (opt.Contains(
"xz")) { pcase = 6; ptype =
"xz"; }
2183 if (opt.Contains(
"zx")) { pcase = 7; ptype =
"zx"; }
2184 if (opt.Contains(
"yz")) { pcase = 8; ptype =
"yz"; }
2185 if (opt.Contains(
"zy")) { pcase = 9; ptype =
"zy"; }
2188 Error(
"Project3D",
"No projection axis specified - return a NULL pointer");
2193 Bool_t computeErrors = GetSumw2N();
2194 if (opt.Contains(
"e") ) {
2195 computeErrors = kTRUE;
2196 opt.Remove(opt.First(
"e"),1);
2199 Bool_t useUF = kTRUE;
2200 Bool_t useOF = kTRUE;
2201 if (opt.Contains(
"nuf") ) {
2203 opt.Remove(opt.Index(
"nuf"),3);
2205 if (opt.Contains(
"nof") ) {
2207 opt.Remove(opt.Index(
"nof"),3);
2210 Bool_t originalRange = kFALSE;
2211 if (opt.Contains(
'o') ) {
2212 originalRange = kTRUE;
2213 opt.Remove(opt.First(
"o"),1);
2220 TString name = GetName();
2221 TString title = GetTitle();
2222 name +=
"_"; name += opt;
2223 title +=
" "; title += ptype; title +=
" projection";
2228 h = DoProject1D(name, title, this->GetXaxis(),
nullptr,
nullptr,
2229 computeErrors, originalRange, useUF, useOF);
2234 h = DoProject1D(name, title, this->GetYaxis(),
nullptr,
nullptr,
2235 computeErrors, originalRange, useUF, useOF);
2240 h = DoProject1D(name, title, this->GetZaxis(),
nullptr,
nullptr,
2241 computeErrors, originalRange, useUF, useOF);
2246 h = DoProject2D(name, title, this->GetXaxis(),this->GetYaxis(),
2247 computeErrors, originalRange, useUF, useOF);
2252 h = DoProject2D(name, title, this->GetYaxis(),this->GetXaxis(),
2253 computeErrors, originalRange, useUF, useOF);
2258 h = DoProject2D(name, title, this->GetXaxis(),this->GetZaxis(),
2259 computeErrors, originalRange, useUF, useOF);
2264 h = DoProject2D(name, title, this->GetZaxis(),this->GetXaxis(),
2265 computeErrors, originalRange, useUF, useOF);
2270 h = DoProject2D(name, title, this->GetYaxis(),this->GetZaxis(),
2271 computeErrors, originalRange, useUF, useOF);
2276 h = DoProject2D(name, title, this->GetZaxis(),this->GetYaxis(),
2277 computeErrors, originalRange, useUF, useOF);
2283 if (h && opt.Contains(
"d")) {
2284 opt.Remove(opt.First(
"d"),1);
2285 TVirtualPad *padsav = gPad;
2286 TVirtualPad *pad = gROOT->GetSelectedPad();
2288 if (!gPad || !gPad->FindObject(h)) {
2293 if (padsav) padsav->cd();
2304 void TH3::DoFillProfileProjection(TProfile2D * p2,
2305 const TAxis & a1,
const TAxis & a2,
const TAxis & a3,
2306 Int_t bin1, Int_t bin2, Int_t bin3,
2307 Int_t inBin, Bool_t useWeights )
const {
2308 Double_t cont = GetBinContent(inBin);
2310 TArrayD & binSumw2 = *(p2->GetBinSumw2());
2311 if (useWeights && binSumw2.fN <= 0) useWeights =
false;
2312 if (!useWeights) p2->SetBit(TH1::kIsNotW);
2314 Double_t u = a1.GetBinCenter(bin1);
2315 Double_t v = a2.GetBinCenter(bin2);
2316 Double_t w = a3.GetBinCenter(bin3);
2317 Int_t outBin = p2->FindBin(u, v);
2318 if (outBin <0)
return;
2320 if ( useWeights ) tmp = binSumw2.fArray[outBin];
2321 p2->Fill( u , v, w, cont);
2322 if (useWeights ) binSumw2.fArray[outBin] = tmp + fSumw2.fArray[inBin];
2330 TProfile2D *TH3::DoProjectProfile2D(
const char* name,
const char * title,
const TAxis* projX,
const TAxis* projY,
2331 bool originalRange,
bool useUF,
bool useOF)
const
2334 Int_t ixmin = std::max(projX->GetFirst(),1);
2335 Int_t ixmax = std::min(projX->GetLast(),projX->GetNbins());
2336 Int_t iymin = std::max(projY->GetFirst(),1);
2337 Int_t iymax = std::min(projY->GetLast(),projY->GetNbins());
2339 Int_t nx = ixmax-ixmin+1;
2340 Int_t ny = iymax-iymin+1;
2347 TObject *p2obj = gROOT->FindObject(name);
2348 if (p2obj && p2obj->InheritsFrom(TH1::Class())) {
2349 if (p2obj->IsA() != TProfile2D::Class() ) {
2350 Error(
"DoProjectProfile2D",
"Histogram with name %s must be a TProfile2D and is a %s",name,p2obj->ClassName());
2353 p2 = (TProfile2D*)p2obj;
2356 const TArrayD *xbins = projX->GetXbins();
2357 const TArrayD *ybins = projY->GetXbins();
2358 if ( originalRange ) {
2359 p2->SetBins(projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
2360 ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
2363 p2->GetXaxis()->Set(projY->GetNbins(),&ybins->fArray[iymin-1]);
2365 p2->GetYaxis()->Set(projX->GetNbins(),&xbins->fArray[ixmin-1]);
2367 p2->SetBins(ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
2368 ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
2370 p2->GetXaxis()->Set(ny,&ybins->fArray[iymin-1]);
2372 p2->GetYaxis()->Set(nx,&xbins->fArray[ixmin-1]);
2377 const TArrayD *xbins = projX->GetXbins();
2378 const TArrayD *ybins = projY->GetXbins();
2379 if ( originalRange ) {
2380 if (xbins->fN == 0 && ybins->fN == 0) {
2381 p2 =
new TProfile2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
2382 ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
2383 }
else if (ybins->fN == 0) {
2384 p2 =
new TProfile2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
2385 ,projX->GetNbins(),&xbins->fArray[ixmin-1]);
2386 }
else if (xbins->fN == 0) {
2387 p2 =
new TProfile2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1]
2388 ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
2390 p2 =
new TProfile2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1],projX->GetNbins(),&xbins->fArray[ixmin-1]);
2393 if (xbins->fN == 0 && ybins->fN == 0) {
2394 p2 =
new TProfile2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
2395 ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
2396 }
else if (ybins->fN == 0) {
2397 p2 =
new TProfile2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
2398 ,nx,&xbins->fArray[ixmin-1]);
2399 }
else if (xbins->fN == 0) {
2400 p2 =
new TProfile2D(name,title,ny,&ybins->fArray[iymin-1]
2401 ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
2403 p2 =
new TProfile2D(name,title,ny,&ybins->fArray[iymin-1],nx,&xbins->fArray[ixmin-1]);
2409 const TAxis* outAxis = 0;
2410 if ( projX != GetXaxis() && projY != GetXaxis() ) {
2411 outAxis = GetXaxis();
2412 }
else if ( projX != GetYaxis() && projY != GetYaxis() ) {
2413 outAxis = GetYaxis();
2415 outAxis = GetZaxis();
2419 bool useWeights = (GetSumw2N() > 0);
2421 if (useWeights && (p2->GetBinSumw2()->fN != p2->GetNcells() ) ) p2->Sumw2();
2424 Int_t *refX = 0, *refY = 0, *refZ = 0;
2425 Int_t ixbin, iybin, outbin;
2426 if ( projX == GetXaxis() && projY == GetYaxis() ) { refX = &ixbin; refY = &iybin; refZ = &outbin; }
2427 if ( projX == GetYaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &ixbin; refZ = &outbin; }
2428 if ( projX == GetXaxis() && projY == GetZaxis() ) { refX = &ixbin; refY = &outbin; refZ = &iybin; }
2429 if ( projX == GetZaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &outbin; refZ = &ixbin; }
2430 if ( projX == GetYaxis() && projY == GetZaxis() ) { refX = &outbin; refY = &ixbin; refZ = &iybin; }
2431 if ( projX == GetZaxis() && projY == GetYaxis() ) { refX = &outbin; refY = &iybin; refZ = &ixbin; }
2432 R__ASSERT (refX != 0 && refY != 0 && refZ != 0);
2434 Int_t outmin = outAxis->GetFirst();
2435 Int_t outmax = outAxis->GetLast();
2438 if (useUF && !outAxis->TestBit(TAxis::kAxisRange) ) outmin -= 1;
2439 if (useOF && !outAxis->TestBit(TAxis::kAxisRange) ) outmax += 1;
2441 TArrayD & binSumw2 = *(p2->GetBinSumw2());
2442 if (useWeights && binSumw2.fN <= 0) useWeights =
false;
2443 if (!useWeights) p2->SetBit(TH1::kIsNotW);
2446 for (ixbin=0;ixbin<=1+projX->GetNbins();ixbin++) {
2447 if ( (ixbin < ixmin || ixbin > ixmax) && projX->TestBit(TAxis::kAxisRange))
continue;
2448 for ( iybin=0;iybin<=1+projY->GetNbins();iybin++) {
2449 if ( (iybin < iymin || iybin > iymax) && projX->TestBit(TAxis::kAxisRange))
continue;
2452 Int_t poutBin = p2->FindBin(projY->GetBinCenter(iybin), projX->GetBinCenter(ixbin));
2453 if (poutBin <0)
continue;
2455 for (outbin = outmin; outbin <= outmax; outbin++) {
2457 Int_t bin = GetBin(*refX,*refY,*refZ);
2461 Double_t cont = RetrieveBinContent(bin);
2462 if (!cont)
continue;
2466 if ( useWeights ) tmp = binSumw2.fArray[poutBin];
2467 p2->Fill( projY->GetBinCenter(iybin) , projX->GetBinCenter(ixbin), outAxis->GetBinCenter(outbin), cont);
2468 if (useWeights ) binSumw2.fArray[poutBin] = tmp + fSumw2.fArray[bin];
2476 bool resetStats =
true;
2477 Double_t stats[kNstat];
2480 for (Int_t i=0;i<kNstat;i++) stats[i] = 0;
2482 p2->PutStats(stats);
2483 Double_t entries = fEntries;
2486 entries = p2->GetEffectiveEntries();
2487 if (!useWeights) entries = TMath::Floor( entries + 0.5);
2488 p2->SetEntries( entries );
2491 p2->SetEntries(entries);
2536 TProfile2D *TH3::Project3DProfile(Option_t *option)
const
2538 TString opt = option; opt.ToLower();
2541 if (opt.Contains(
"xy")) { pcase = 4; ptype =
"xy"; }
2542 if (opt.Contains(
"yx")) { pcase = 5; ptype =
"yx"; }
2543 if (opt.Contains(
"xz")) { pcase = 6; ptype =
"xz"; }
2544 if (opt.Contains(
"zx")) { pcase = 7; ptype =
"zx"; }
2545 if (opt.Contains(
"yz")) { pcase = 8; ptype =
"yz"; }
2546 if (opt.Contains(
"zy")) { pcase = 9; ptype =
"zy"; }
2549 Error(
"Project3D",
"No projection axis specified - return a NULL pointer");
2554 Bool_t useUF = kFALSE;
2555 if (opt.Contains(
"uf") ) {
2557 opt.Remove(opt.Index(
"uf"),2);
2559 Bool_t useOF = kFALSE;
2560 if (opt.Contains(
"of") ) {
2562 opt.Remove(opt.Index(
"of"),2);
2565 Bool_t originalRange = kFALSE;
2566 if (opt.Contains(
'o') ) {
2567 originalRange = kTRUE;
2568 opt.Remove(opt.First(
"o"),1);
2573 TString name = GetName();
2574 TString title = GetTitle();
2575 name +=
"_p"; name += opt;
2576 title +=
" profile "; title += ptype; title +=
" projection";
2582 p2 = DoProjectProfile2D(name, title, GetXaxis(), GetYaxis(), originalRange, useUF, useOF);
2587 p2 = DoProjectProfile2D(name, title, GetYaxis(), GetXaxis(), originalRange, useUF, useOF);
2592 p2 = DoProjectProfile2D(name, title, GetXaxis(), GetZaxis(), originalRange, useUF, useOF);
2597 p2 = DoProjectProfile2D(name, title, GetZaxis(), GetXaxis(), originalRange, useUF, useOF);
2602 p2 = DoProjectProfile2D(name, title, GetYaxis(), GetZaxis(), originalRange, useUF, useOF);
2607 p2 = DoProjectProfile2D(name, title, GetZaxis(), GetYaxis(), originalRange, useUF, useOF);
2619 void TH3::PutStats(Double_t *stats)
2621 TH1::PutStats(stats);
2623 fTsumwy2 = stats[5];
2624 fTsumwxy = stats[6];
2626 fTsumwz2 = stats[8];
2627 fTsumwxz = stats[9];
2628 fTsumwyz = stats[10];
2636 TH3 *TH3::RebinX(Int_t ngroup,
const char *newname)
2638 return Rebin3D(ngroup, 1, 1, newname);
2646 TH3 *TH3::RebinY(Int_t ngroup,
const char *newname)
2648 return Rebin3D(1, ngroup, 1, newname);
2656 TH3 *TH3::RebinZ(Int_t ngroup,
const char *newname)
2658 return Rebin3D(1, 1, ngroup, newname);
2687 TH3 *TH3::Rebin3D(Int_t nxgroup, Int_t nygroup, Int_t nzgroup,
const char *newname)
2689 Int_t i,j,k,xbin,ybin,zbin;
2690 Int_t nxbins = fXaxis.GetNbins();
2691 Int_t nybins = fYaxis.GetNbins();
2692 Int_t nzbins = fZaxis.GetNbins();
2693 Double_t xmin = fXaxis.GetXmin();
2694 Double_t xmax = fXaxis.GetXmax();
2695 Double_t ymin = fYaxis.GetXmin();
2696 Double_t ymax = fYaxis.GetXmax();
2697 Double_t zmin = fZaxis.GetXmin();
2698 Double_t zmax = fZaxis.GetXmax();
2699 if ((nxgroup <= 0) || (nxgroup > nxbins)) {
2700 Error(
"Rebin",
"Illegal value of nxgroup=%d",nxgroup);
2703 if ((nygroup <= 0) || (nygroup > nybins)) {
2704 Error(
"Rebin",
"Illegal value of nygroup=%d",nygroup);
2707 if ((nzgroup <= 0) || (nzgroup > nzbins)) {
2708 Error(
"Rebin",
"Illegal value of nzgroup=%d",nzgroup);
2712 Int_t newxbins = nxbins/nxgroup;
2713 Int_t newybins = nybins/nygroup;
2714 Int_t newzbins = nzbins/nzgroup;
2717 Double_t entries = fEntries;
2718 Double_t *oldBins =
new Double_t[fNcells];
2719 for (Int_t ibin = 0; ibin < fNcells; ibin++) {
2720 oldBins[ibin] = RetrieveBinContent(ibin);
2722 Double_t *oldSumw2 = 0;
2723 if (fSumw2.fN != 0) {
2724 oldSumw2 =
new Double_t[fNcells];
2725 for (Int_t ibin = 0; ibin < fNcells; ibin++) {
2726 oldSumw2[ibin] = fSumw2.fArray[ibin];
2732 if (newname && strlen(newname)) {
2733 hnew = (TH3*)Clone();
2734 hnew->SetName(newname);
2738 Double_t stat[kNstat];
2740 bool resetStat =
false;
2744 if (newxbins*nxgroup != nxbins) {
2745 xmax = fXaxis.GetBinUpEdge(newxbins*nxgroup);
2748 if (newybins*nygroup != nybins) {
2749 ymax = fYaxis.GetBinUpEdge(newybins*nygroup);
2752 if (newzbins*nzgroup != nzbins) {
2753 zmax = fZaxis.GetBinUpEdge(newzbins*nzgroup);
2757 Int_t nXdivisions = fXaxis.GetNdivisions();
2758 Color_t xAxisColor = fXaxis.GetAxisColor();
2759 Color_t xLabelColor = fXaxis.GetLabelColor();
2760 Style_t xLabelFont = fXaxis.GetLabelFont();
2761 Float_t xLabelOffset = fXaxis.GetLabelOffset();
2762 Float_t xLabelSize = fXaxis.GetLabelSize();
2763 Float_t xTickLength = fXaxis.GetTickLength();
2764 Float_t xTitleOffset = fXaxis.GetTitleOffset();
2765 Float_t xTitleSize = fXaxis.GetTitleSize();
2766 Color_t xTitleColor = fXaxis.GetTitleColor();
2767 Style_t xTitleFont = fXaxis.GetTitleFont();
2769 Int_t nYdivisions = fYaxis.GetNdivisions();
2770 Color_t yAxisColor = fYaxis.GetAxisColor();
2771 Color_t yLabelColor = fYaxis.GetLabelColor();
2772 Style_t yLabelFont = fYaxis.GetLabelFont();
2773 Float_t yLabelOffset = fYaxis.GetLabelOffset();
2774 Float_t yLabelSize = fYaxis.GetLabelSize();
2775 Float_t yTickLength = fYaxis.GetTickLength();
2776 Float_t yTitleOffset = fYaxis.GetTitleOffset();
2777 Float_t yTitleSize = fYaxis.GetTitleSize();
2778 Color_t yTitleColor = fYaxis.GetTitleColor();
2779 Style_t yTitleFont = fYaxis.GetTitleFont();
2781 Int_t nZdivisions = fZaxis.GetNdivisions();
2782 Color_t zAxisColor = fZaxis.GetAxisColor();
2783 Color_t zLabelColor = fZaxis.GetLabelColor();
2784 Style_t zLabelFont = fZaxis.GetLabelFont();
2785 Float_t zLabelOffset = fZaxis.GetLabelOffset();
2786 Float_t zLabelSize = fZaxis.GetLabelSize();
2787 Float_t zTickLength = fZaxis.GetTickLength();
2788 Float_t zTitleOffset = fZaxis.GetTitleOffset();
2789 Float_t zTitleSize = fZaxis.GetTitleSize();
2790 Color_t zTitleColor = fZaxis.GetTitleColor();
2791 Style_t zTitleFont = fZaxis.GetTitleFont();
2794 if (nxgroup != 1 || nygroup != 1 || nzgroup != 1) {
2795 if (fXaxis.GetXbins()->GetSize() > 0 || fYaxis.GetXbins()->GetSize() > 0 || fZaxis.GetXbins()->GetSize() > 0) {
2797 Double_t *xbins =
new Double_t[newxbins+1];
2798 for (i = 0; i <= newxbins; ++i) xbins[i] = fXaxis.GetBinLowEdge(1+i*nxgroup);
2799 Double_t *ybins =
new Double_t[newybins+1];
2800 for (i = 0; i <= newybins; ++i) ybins[i] = fYaxis.GetBinLowEdge(1+i*nygroup);
2801 Double_t *zbins =
new Double_t[newzbins+1];
2802 for (i = 0; i <= newzbins; ++i) zbins[i] = fZaxis.GetBinLowEdge(1+i*nzgroup);
2803 hnew->SetBins(newxbins,xbins, newybins, ybins, newzbins, zbins);
2808 hnew->SetBins(newxbins, xmin, xmax, newybins, ymin, ymax, newzbins, zmin, zmax);
2811 Double_t binContent, binSumw2;
2816 for (xbin = 1; xbin <= newxbins; xbin++) {
2819 for (ybin = 1; ybin <= newybins; ybin++) {
2821 for (zbin = 1; zbin <= newzbins; zbin++) {
2824 for (i = 0; i < nxgroup; i++) {
2825 if (oldxbin+i > nxbins)
break;
2826 for (j =0; j < nygroup; j++) {
2827 if (oldybin+j > nybins)
break;
2828 for (k =0; k < nzgroup; k++) {
2829 if (oldzbin+k > nzbins)
break;
2831 bin = oldxbin + i + (oldybin + j)*(nxbins + 2) + (oldzbin + k)*(nxbins + 2)*(nybins + 2);
2832 binContent += oldBins[bin];
2833 if (oldSumw2) binSumw2 += oldSumw2[bin];
2837 Int_t ibin = hnew->GetBin(xbin,ybin,zbin);
2838 hnew->SetBinContent(ibin, binContent);
2839 if (oldSumw2) hnew->fSumw2.fArray[ibin] = binSumw2;
2848 for (Int_t xover = 0; xover <= 1; xover++) {
2849 for (Int_t yover = 0; yover <= 1; yover++) {
2850 for (Int_t zover = 0; zover <= 1; zover++) {
2854 for (xbin = xover*oldxbin; xbin <= xover*(nxbins+1); xbin++) {
2855 for (ybin = yover*oldybin; ybin <= yover*(nybins+1); ybin++) {
2856 for (zbin = zover*oldzbin; zbin <= zover*(nzbins+1); zbin++) {
2857 bin = GetBin(xbin,ybin,zbin);
2858 binContent += oldBins[bin];
2859 if (oldSumw2) binSumw2 += oldSumw2[bin];
2863 Int_t binNew = hnew->GetBin( xover *(newxbins+1),
2864 yover*(newybins+1), zover*(newzbins+1) );
2865 hnew->SetBinContent(binNew,binContent);
2866 if (oldSumw2) hnew->fSumw2.fArray[binNew] = binSumw2;
2871 Double_t binContent0, binContent2, binContent3, binContent4;
2872 Double_t binError0, binError2, binError3, binError4;
2873 Int_t oldxbin2, oldybin2, oldzbin2;
2874 Int_t ufbin, ofbin, ofbin2, ofbin3, ofbin4;
2880 for (xbin = 1; xbin<=newxbins; xbin++) {
2882 for (zbin = 1; zbin<=newzbins; zbin++) {
2883 binContent0 = binContent2 = 0;
2884 binError0 = binError2 = 0;
2885 for (i=0; i<nxgroup; i++) {
2886 if (oldxbin2+i > nxbins)
break;
2887 for (k=0; k<nzgroup; k++) {
2888 if (oldzbin2+k > nzbins)
break;
2890 ufbin = oldxbin2 + i + (nxbins+2)*(nybins+2)*(oldzbin2+k);
2891 binContent0 += oldBins[ufbin];
2892 if (oldSumw2) binError0 += oldSumw2[ufbin];
2893 for (ybin = oldybin; ybin <= nybins + 1; ybin++) {
2895 ofbin = ufbin + ybin*(nxbins+2);
2896 binContent2 += oldBins[ofbin];
2897 if (oldSumw2) binError2 += oldSumw2[ofbin];
2901 hnew->SetBinContent(xbin,0,zbin,binContent0);
2902 hnew->SetBinContent(xbin,newybins+1,zbin,binContent2);
2904 hnew->SetBinError(xbin,0,zbin,TMath::Sqrt(binError0));
2905 hnew->SetBinError(xbin,newybins+1,zbin,TMath::Sqrt(binError2) );
2907 oldzbin2 += nzgroup;
2909 oldxbin2 += nxgroup;
2916 for (ybin = 1; ybin<=newybins; ybin++) {
2918 for (zbin = 1; zbin<=newzbins; zbin++) {
2919 binContent0 = binContent2 = 0;
2920 binError0 = binError2 = 0;
2921 for (j=0; j<nygroup; j++) {
2922 if (oldybin2+j > nybins)
break;
2923 for (k=0; k<nzgroup; k++) {
2924 if (oldzbin2+k > nzbins)
break;
2926 ufbin = (oldybin2 + j)*(nxbins+2) + (nxbins+2)*(nybins+2)*(oldzbin2+k);
2927 binContent0 += oldBins[ufbin];
2928 if (oldSumw2) binError0 += oldSumw2[ufbin];
2929 for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
2931 ofbin = ufbin + xbin;
2932 binContent2 += oldBins[ofbin];
2933 if (oldSumw2) binError2 += oldSumw2[ofbin];
2937 hnew->SetBinContent(0,ybin,zbin,binContent0);
2938 hnew->SetBinContent(newxbins+1,ybin,zbin,binContent2);
2940 hnew->SetBinError(0,ybin,zbin,TMath::Sqrt(binError0));
2941 hnew->SetBinError(newxbins+1,ybin,zbin,TMath::Sqrt(binError2) );
2943 oldzbin2 += nzgroup;
2945 oldybin2 += nygroup;
2952 for (xbin = 1; xbin<=newxbins; xbin++) {
2954 for (ybin = 1; ybin<=newybins; ybin++) {
2955 binContent0 = binContent2 = 0;
2956 binError0 = binError2 = 0;
2957 for (i=0; i<nxgroup; i++) {
2958 if (oldxbin2+i > nxbins)
break;
2959 for (j=0; j<nygroup; j++) {
2960 if (oldybin2+j > nybins)
break;
2962 ufbin = oldxbin2 + i + (nxbins+2)*(oldybin2+j);
2963 binContent0 += oldBins[ufbin];
2964 if (oldSumw2) binError0 += oldSumw2[ufbin];
2965 for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
2967 ofbin = ufbin + (nxbins+2)*(nybins+2)*zbin;
2968 binContent2 += oldBins[ofbin];
2969 if (oldSumw2) binError2 += oldSumw2[ofbin];
2973 hnew->SetBinContent(xbin,ybin,0,binContent0);
2974 hnew->SetBinContent(xbin,ybin,newzbins+1,binContent2);
2976 hnew->SetBinError(xbin,ybin,0,TMath::Sqrt(binError0));
2977 hnew->SetBinError(xbin,ybin,newzbins+1,TMath::Sqrt(binError2) );
2979 oldybin2 += nygroup;
2981 oldxbin2 += nxgroup;
2988 for (xbin = 1; xbin<=newxbins; xbin++) {
2997 for (i=0; i<nxgroup; i++) {
2998 if (oldxbin2+i > nxbins)
break;
2999 ufbin = oldxbin2 + i;
3000 binContent0 += oldBins[ufbin];
3001 if (oldSumw2) binError0 += oldSumw2[ufbin];
3002 for (ybin = oldybin; ybin <= nybins + 1; ybin++) {
3003 ofbin3 = ufbin+ybin*(nxbins+2);
3004 binContent3 += oldBins[ ofbin3 ];
3005 if (oldSumw2) binError3 += oldSumw2[ofbin3];
3006 for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3008 ofbin4 = oldxbin2 + i + ybin*(nxbins+2) + (nxbins+2)*(nybins+2)*zbin;
3009 binContent4 += oldBins[ofbin4];
3010 if (oldSumw2) binError4 += oldSumw2[ofbin4];
3013 for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3014 ofbin2 = ufbin+zbin*(nxbins+2)*(nybins+2);
3015 binContent2 += oldBins[ ofbin2 ];
3016 if (oldSumw2) binError2 += oldSumw2[ofbin2];
3019 hnew->SetBinContent(xbin,0,0,binContent0);
3020 hnew->SetBinContent(xbin,0,newzbins+1,binContent2);
3021 hnew->SetBinContent(xbin,newybins+1,0,binContent3);
3022 hnew->SetBinContent(xbin,newybins+1,newzbins+1,binContent4);
3024 hnew->SetBinError(xbin,0,0,TMath::Sqrt(binError0));
3025 hnew->SetBinError(xbin,0,newzbins+1,TMath::Sqrt(binError2) );
3026 hnew->SetBinError(xbin,newybins+1,0,TMath::Sqrt(binError3) );
3027 hnew->SetBinError(xbin,newybins+1,newzbins+1,TMath::Sqrt(binError4) );
3029 oldxbin2 += nxgroup;
3036 for (zbin = 1; zbin<=newzbins; zbin++) {
3045 for (i=0; i<nzgroup; i++) {
3046 if (oldzbin2+i > nzbins)
break;
3047 ufbin = (oldzbin2 + i)*(nxbins+2)*(nybins+2);
3048 binContent0 += oldBins[ufbin];
3049 if (oldSumw2) binError0 += oldSumw2[ufbin];
3050 for (ybin = oldybin; ybin <= nybins + 1; ybin++) {
3051 ofbin3 = ufbin+ybin*(nxbins+2);
3052 binContent3 += oldBins[ ofbin3 ];
3053 if (oldSumw2) binError3 += oldSumw2[ofbin3];
3054 for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
3056 ofbin4 = ufbin + xbin + ybin*(nxbins+2);
3057 binContent4 += oldBins[ofbin4];
3058 if (oldSumw2) binError4 += oldSumw2[ofbin4];
3061 for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
3062 ofbin2 = xbin +(oldzbin2+i)*(nxbins+2)*(nybins+2);
3063 binContent2 += oldBins[ ofbin2 ];
3064 if (oldSumw2) binError2 += oldSumw2[ofbin2];
3067 hnew->SetBinContent(0,0,zbin,binContent0);
3068 hnew->SetBinContent(0,newybins+1,zbin,binContent3);
3069 hnew->SetBinContent(newxbins+1,0,zbin,binContent2);
3070 hnew->SetBinContent(newxbins+1,newybins+1,zbin,binContent4);
3072 hnew->SetBinError(0,0,zbin,TMath::Sqrt(binError0));
3073 hnew->SetBinError(0,newybins+1,zbin,TMath::Sqrt(binError3) );
3074 hnew->SetBinError(newxbins+1,0,zbin,TMath::Sqrt(binError2) );
3075 hnew->SetBinError(newxbins+1,newybins+1,zbin,TMath::Sqrt(binError4) );
3077 oldzbin2 += nzgroup;
3084 for (ybin = 1; ybin<=newybins; ybin++) {
3093 for (i=0; i<nygroup; i++) {
3094 if (oldybin2+i > nybins)
break;
3095 ufbin = (oldybin2 + i)*(nxbins+2);
3096 binContent0 += oldBins[ufbin];
3097 if (oldSumw2) binError0 += oldSumw2[ufbin];
3098 for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
3099 ofbin3 = ufbin+xbin;
3100 binContent3 += oldBins[ ofbin3 ];
3101 if (oldSumw2) binError3 += oldSumw2[ofbin3];
3102 for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3104 ofbin4 = xbin + (nxbins+2)*(nybins+2)*zbin+(oldybin2+i)*(nxbins+2);
3105 binContent4 += oldBins[ofbin4];
3106 if (oldSumw2) binError4 += oldSumw2[ofbin4];
3109 for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3110 ofbin2 = (oldybin2+i)*(nxbins+2)+zbin*(nxbins+2)*(nybins+2);
3111 binContent2 += oldBins[ ofbin2 ];
3112 if (oldSumw2) binError2 += oldSumw2[ofbin2];
3115 hnew->SetBinContent(0,ybin,0,binContent0);
3116 hnew->SetBinContent(0,ybin,newzbins+1,binContent2);
3117 hnew->SetBinContent(newxbins+1,ybin,0,binContent3);
3118 hnew->SetBinContent(newxbins+1,ybin,newzbins+1,binContent4);
3120 hnew->SetBinError(0,ybin,0,TMath::Sqrt(binError0));
3121 hnew->SetBinError(0,ybin,newzbins+1,TMath::Sqrt(binError2) );
3122 hnew->SetBinError(newxbins+1,ybin,0,TMath::Sqrt(binError3) );
3123 hnew->SetBinError(newxbins+1,ybin,newzbins+1,TMath::Sqrt(binError4) );
3125 oldybin2 += nygroup;
3130 fXaxis.SetNdivisions(nXdivisions);
3131 fXaxis.SetAxisColor(xAxisColor);
3132 fXaxis.SetLabelColor(xLabelColor);
3133 fXaxis.SetLabelFont(xLabelFont);
3134 fXaxis.SetLabelOffset(xLabelOffset);
3135 fXaxis.SetLabelSize(xLabelSize);
3136 fXaxis.SetTickLength(xTickLength);
3137 fXaxis.SetTitleOffset(xTitleOffset);
3138 fXaxis.SetTitleSize(xTitleSize);
3139 fXaxis.SetTitleColor(xTitleColor);
3140 fXaxis.SetTitleFont(xTitleFont);
3142 fYaxis.SetNdivisions(nYdivisions);
3143 fYaxis.SetAxisColor(yAxisColor);
3144 fYaxis.SetLabelColor(yLabelColor);
3145 fYaxis.SetLabelFont(yLabelFont);
3146 fYaxis.SetLabelOffset(yLabelOffset);
3147 fYaxis.SetLabelSize(yLabelSize);
3148 fYaxis.SetTickLength(yTickLength);
3149 fYaxis.SetTitleOffset(yTitleOffset);
3150 fYaxis.SetTitleSize(yTitleSize);
3151 fYaxis.SetTitleColor(yTitleColor);
3152 fYaxis.SetTitleFont(yTitleFont);
3154 fZaxis.SetNdivisions(nZdivisions);
3155 fZaxis.SetAxisColor(zAxisColor);
3156 fZaxis.SetLabelColor(zLabelColor);
3157 fZaxis.SetLabelFont(zLabelFont);
3158 fZaxis.SetLabelOffset(zLabelOffset);
3159 fZaxis.SetLabelSize(zLabelSize);
3160 fZaxis.SetTickLength(zTickLength);
3161 fZaxis.SetTitleOffset(zTitleOffset);
3162 fZaxis.SetTitleSize(zTitleSize);
3163 fZaxis.SetTitleColor(zTitleColor);
3164 fZaxis.SetTitleFont(zTitleFont);
3167 hnew->SetEntries(entries);
3168 if (!resetStat) hnew->PutStats(stat);
3171 if (oldSumw2)
delete [] oldSumw2;
3179 void TH3::Reset(Option_t *option)
3182 TString opt = option;
3184 if (opt.Contains(
"ICE") && !opt.Contains(
"S"))
return;
3198 void TH3::SetBinContent(Int_t bin, Double_t content)
3202 if (bin < 0)
return;
3203 if (bin >= fNcells)
return;
3204 UpdateBinContent(bin, content);
3211 void TH3::Streamer(TBuffer &R__b)
3213 if (R__b.IsReading()) {
3215 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3217 R__b.ReadClassBuffer(TH3::Class(),
this, R__v, R__s, R__c);
3221 TH1::Streamer(R__b);
3222 TAtt3D::Streamer(R__b);
3223 R__b.CheckByteCount(R__s, R__c, TH3::IsA());
3227 R__b.WriteClassBuffer(TH3::Class(),
this);
3243 TH3C::TH3C(): TH3(), TArrayC()
3246 if (fgDefaultSumw2) Sumw2();
3261 TH3C::TH3C(
const char *name,
const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3262 ,Int_t nbinsy,Double_t ylow,Double_t yup
3263 ,Int_t nbinsz,Double_t zlow,Double_t zup)
3264 :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3266 TArrayC::Set(fNcells);
3267 if (fgDefaultSumw2) Sumw2();
3269 if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3276 TH3C::TH3C(
const char *name,
const char *title,Int_t nbinsx,
const Float_t *xbins
3277 ,Int_t nbinsy,
const Float_t *ybins
3278 ,Int_t nbinsz,
const Float_t *zbins)
3279 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3281 TArrayC::Set(fNcells);
3282 if (fgDefaultSumw2) Sumw2();
3289 TH3C::TH3C(
const char *name,
const char *title,Int_t nbinsx,
const Double_t *xbins
3290 ,Int_t nbinsy,
const Double_t *ybins
3291 ,Int_t nbinsz,
const Double_t *zbins)
3292 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3294 TArrayC::Set(fNcells);
3295 if (fgDefaultSumw2) Sumw2();
3302 TH3C::TH3C(
const TH3C &h3c) : TH3(), TArrayC()
3304 ((TH3C&)h3c).Copy(*
this);
3311 void TH3C::AddBinContent(Int_t bin)
3313 if (fArray[bin] < 127) fArray[bin]++;
3320 void TH3C::AddBinContent(Int_t bin, Double_t w)
3322 Int_t newval = fArray[bin] + Int_t(w);
3323 if (newval > -128 && newval < 128) {fArray[bin] = Char_t(newval);
return;}
3324 if (newval < -127) fArray[bin] = -127;
3325 if (newval > 127) fArray[bin] = 127;
3332 void TH3C::Copy(TObject &newth3)
const
3334 TH3::Copy((TH3C&)newth3);
3341 void TH3C::Reset(Option_t *option)
3353 void TH3C::SetBinsLength(Int_t n)
3355 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
3382 void TH3::SetShowProjection(
const char *option,Int_t nbins)
3386 if (fPainter) fPainter->SetShowProjection(option,nbins);
3393 void TH3C::Streamer(TBuffer &R__b)
3395 if (R__b.IsReading()) {
3397 if (R__b.GetParent() && R__b.GetVersionOwner() < 22300)
return;
3398 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3400 R__b.ReadClassBuffer(TH3C::Class(),
this, R__v, R__s, R__c);
3406 TH1::Streamer(R__b);
3407 TArrayC::Streamer(R__b);
3408 R__b.ReadVersion(&R__s, &R__c);
3409 TAtt3D::Streamer(R__b);
3411 TH3::Streamer(R__b);
3412 TArrayC::Streamer(R__b);
3413 R__b.CheckByteCount(R__s, R__c, TH3C::IsA());
3418 R__b.WriteClassBuffer(TH3C::Class(),
this);
3426 TH3C& TH3C::operator=(
const TH3C &h1)
3428 if (
this != &h1) ((TH3C&)h1).Copy(*
this);
3436 TH3C operator*(Float_t c1, TH3C &h1)
3440 hnew.SetDirectory(0);
3448 TH3C operator+(TH3C &h1, TH3C &h2)
3452 hnew.SetDirectory(0);
3460 TH3C operator-(TH3C &h1, TH3C &h2)
3464 hnew.SetDirectory(0);
3472 TH3C operator*(TH3C &h1, TH3C &h2)
3476 hnew.SetDirectory(0);
3484 TH3C operator/(TH3C &h1, TH3C &h2)
3488 hnew.SetDirectory(0);
3504 TH3S::TH3S(): TH3(), TArrayS()
3507 if (fgDefaultSumw2) Sumw2();
3522 TH3S::TH3S(
const char *name,
const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3523 ,Int_t nbinsy,Double_t ylow,Double_t yup
3524 ,Int_t nbinsz,Double_t zlow,Double_t zup)
3525 :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3528 if (fgDefaultSumw2) Sumw2();
3530 if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3537 TH3S::TH3S(
const char *name,
const char *title,Int_t nbinsx,
const Float_t *xbins
3538 ,Int_t nbinsy,
const Float_t *ybins
3539 ,Int_t nbinsz,
const Float_t *zbins)
3540 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3543 if (fgDefaultSumw2) Sumw2();
3550 TH3S::TH3S(
const char *name,
const char *title,Int_t nbinsx,
const Double_t *xbins
3551 ,Int_t nbinsy,
const Double_t *ybins
3552 ,Int_t nbinsz,
const Double_t *zbins)
3553 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3556 if (fgDefaultSumw2) Sumw2();
3563 TH3S::TH3S(
const TH3S &h3s) : TH3(), TArrayS()
3565 ((TH3S&)h3s).Copy(*
this);
3572 void TH3S::AddBinContent(Int_t bin)
3574 if (fArray[bin] < 32767) fArray[bin]++;
3581 void TH3S::AddBinContent(Int_t bin, Double_t w)
3583 Int_t newval = fArray[bin] + Int_t(w);
3584 if (newval > -32768 && newval < 32768) {fArray[bin] = Short_t(newval);
return;}
3585 if (newval < -32767) fArray[bin] = -32767;
3586 if (newval > 32767) fArray[bin] = 32767;
3593 void TH3S::Copy(TObject &newth3)
const
3595 TH3::Copy((TH3S&)newth3);
3602 void TH3S::Reset(Option_t *option)
3614 void TH3S::SetBinsLength(Int_t n)
3616 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
3625 void TH3S::Streamer(TBuffer &R__b)
3627 if (R__b.IsReading()) {
3629 if (R__b.GetParent() && R__b.GetVersionOwner() < 22300)
return;
3630 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3632 R__b.ReadClassBuffer(TH3S::Class(),
this, R__v, R__s, R__c);
3638 TH1::Streamer(R__b);
3639 TArrayS::Streamer(R__b);
3640 R__b.ReadVersion(&R__s, &R__c);
3641 TAtt3D::Streamer(R__b);
3643 TH3::Streamer(R__b);
3644 TArrayS::Streamer(R__b);
3645 R__b.CheckByteCount(R__s, R__c, TH3S::IsA());
3650 R__b.WriteClassBuffer(TH3S::Class(),
this);
3658 TH3S& TH3S::operator=(
const TH3S &h1)
3660 if (
this != &h1) ((TH3S&)h1).Copy(*
this);
3668 TH3S operator*(Float_t c1, TH3S &h1)
3672 hnew.SetDirectory(0);
3680 TH3S operator+(TH3S &h1, TH3S &h2)
3684 hnew.SetDirectory(0);
3692 TH3S operator-(TH3S &h1, TH3S &h2)
3696 hnew.SetDirectory(0);
3704 TH3S operator*(TH3S &h1, TH3S &h2)
3708 hnew.SetDirectory(0);
3716 TH3S operator/(TH3S &h1, TH3S &h2)
3720 hnew.SetDirectory(0);
3736 TH3I::TH3I(): TH3(), TArrayI()
3739 if (fgDefaultSumw2) Sumw2();
3754 TH3I::TH3I(
const char *name,
const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3755 ,Int_t nbinsy,Double_t ylow,Double_t yup
3756 ,Int_t nbinsz,Double_t zlow,Double_t zup)
3757 :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3760 if (fgDefaultSumw2) Sumw2();
3762 if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3769 TH3I::TH3I(
const char *name,
const char *title,Int_t nbinsx,
const Float_t *xbins
3770 ,Int_t nbinsy,
const Float_t *ybins
3771 ,Int_t nbinsz,
const Float_t *zbins)
3772 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3774 TArrayI::Set(fNcells);
3775 if (fgDefaultSumw2) Sumw2();
3782 TH3I::TH3I(
const char *name,
const char *title,Int_t nbinsx,
const Double_t *xbins
3783 ,Int_t nbinsy,
const Double_t *ybins
3784 ,Int_t nbinsz,
const Double_t *zbins)
3785 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3787 TArrayI::Set(fNcells);
3788 if (fgDefaultSumw2) Sumw2();
3795 TH3I::TH3I(
const TH3I &h3i) : TH3(), TArrayI()
3797 ((TH3I&)h3i).Copy(*
this);
3804 void TH3I::AddBinContent(Int_t bin)
3806 if (fArray[bin] < 2147483647) fArray[bin]++;
3813 void TH3I::AddBinContent(Int_t bin, Double_t w)
3815 Long64_t newval = fArray[bin] + Long64_t(w);
3816 if (newval > -2147483647 && newval < 2147483647) {fArray[bin] = Int_t(newval);
return;}
3817 if (newval < -2147483647) fArray[bin] = -2147483647;
3818 if (newval > 2147483647) fArray[bin] = 2147483647;
3825 void TH3I::Copy(TObject &newth3)
const
3827 TH3::Copy((TH3I&)newth3);
3834 void TH3I::Reset(Option_t *option)
3846 void TH3I::SetBinsLength(Int_t n)
3848 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
3857 TH3I& TH3I::operator=(
const TH3I &h1)
3859 if (
this != &h1) ((TH3I&)h1).Copy(*
this);
3867 TH3I operator*(Float_t c1, TH3I &h1)
3871 hnew.SetDirectory(0);
3879 TH3I operator+(TH3I &h1, TH3I &h2)
3883 hnew.SetDirectory(0);
3891 TH3I operator-(TH3I &h1, TH3I &h2)
3895 hnew.SetDirectory(0);
3903 TH3I operator*(TH3I &h1, TH3I &h2)
3907 hnew.SetDirectory(0);
3915 TH3I operator/(TH3I &h1, TH3I &h2)
3919 hnew.SetDirectory(0);
3935 TH3F::TH3F(): TH3(), TArrayF()
3938 if (fgDefaultSumw2) Sumw2();
3953 TH3F::TH3F(
const char *name,
const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3954 ,Int_t nbinsy,Double_t ylow,Double_t yup
3955 ,Int_t nbinsz,Double_t zlow,Double_t zup)
3956 :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3958 TArrayF::Set(fNcells);
3959 if (fgDefaultSumw2) Sumw2();
3961 if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3968 TH3F::TH3F(
const char *name,
const char *title,Int_t nbinsx,
const Float_t *xbins
3969 ,Int_t nbinsy,
const Float_t *ybins
3970 ,Int_t nbinsz,
const Float_t *zbins)
3971 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3973 TArrayF::Set(fNcells);
3974 if (fgDefaultSumw2) Sumw2();
3981 TH3F::TH3F(
const char *name,
const char *title,Int_t nbinsx,
const Double_t *xbins
3982 ,Int_t nbinsy,
const Double_t *ybins
3983 ,Int_t nbinsz,
const Double_t *zbins)
3984 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3986 TArrayF::Set(fNcells);
3987 if (fgDefaultSumw2) Sumw2();
3994 TH3F::TH3F(
const TH3F &h3f) : TH3(), TArrayF()
3996 ((TH3F&)h3f).Copy(*
this);
4003 void TH3F::Copy(TObject &newth3)
const
4005 TH3::Copy((TH3F&)newth3);
4012 void TH3F::Reset(Option_t *option)
4024 void TH3F::SetBinsLength(Int_t n)
4026 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
4035 void TH3F::Streamer(TBuffer &R__b)
4037 if (R__b.IsReading()) {
4039 if (R__b.GetParent() && R__b.GetVersionOwner() < 22300)
return;
4040 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
4042 R__b.ReadClassBuffer(TH3F::Class(),
this, R__v, R__s, R__c);
4048 TH1::Streamer(R__b);
4049 TArrayF::Streamer(R__b);
4050 R__b.ReadVersion(&R__s, &R__c);
4051 TAtt3D::Streamer(R__b);
4053 TH3::Streamer(R__b);
4054 TArrayF::Streamer(R__b);
4055 R__b.CheckByteCount(R__s, R__c, TH3F::IsA());
4060 R__b.WriteClassBuffer(TH3F::Class(),
this);
4068 TH3F& TH3F::operator=(
const TH3F &h1)
4070 if (
this != &h1) ((TH3F&)h1).Copy(*
this);
4078 TH3F operator*(Float_t c1, TH3F &h1)
4082 hnew.SetDirectory(0);
4090 TH3F operator+(TH3F &h1, TH3F &h2)
4094 hnew.SetDirectory(0);
4102 TH3F operator-(TH3F &h1, TH3F &h2)
4106 hnew.SetDirectory(0);
4114 TH3F operator*(TH3F &h1, TH3F &h2)
4118 hnew.SetDirectory(0);
4126 TH3F operator/(TH3F &h1, TH3F &h2)
4130 hnew.SetDirectory(0);
4146 TH3D::TH3D(): TH3(), TArrayD()
4149 if (fgDefaultSumw2) Sumw2();
4164 TH3D::TH3D(
const char *name,
const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
4165 ,Int_t nbinsy,Double_t ylow,Double_t yup
4166 ,Int_t nbinsz,Double_t zlow,Double_t zup)
4167 :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
4169 TArrayD::Set(fNcells);
4170 if (fgDefaultSumw2) Sumw2();
4172 if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
4179 TH3D::TH3D(
const char *name,
const char *title,Int_t nbinsx,
const Float_t *xbins
4180 ,Int_t nbinsy,
const Float_t *ybins
4181 ,Int_t nbinsz,
const Float_t *zbins)
4182 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4184 TArrayD::Set(fNcells);
4185 if (fgDefaultSumw2) Sumw2();
4192 TH3D::TH3D(
const char *name,
const char *title,Int_t nbinsx,
const Double_t *xbins
4193 ,Int_t nbinsy,
const Double_t *ybins
4194 ,Int_t nbinsz,
const Double_t *zbins)
4195 :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4197 TArrayD::Set(fNcells);
4198 if (fgDefaultSumw2) Sumw2();
4205 TH3D::TH3D(
const TH3D &h3d) : TH3(), TArrayD()
4207 ((TH3D&)h3d).Copy(*
this);
4214 void TH3D::Copy(TObject &newth3)
const
4216 TH3::Copy((TH3D&)newth3);
4223 void TH3D::Reset(Option_t *option)
4235 void TH3D::SetBinsLength(Int_t n)
4237 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
4246 void TH3D::Streamer(TBuffer &R__b)
4248 if (R__b.IsReading()) {
4250 if (R__b.GetParent() && R__b.GetVersionOwner() < 22300)
return;
4251 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
4253 R__b.ReadClassBuffer(TH3D::Class(),
this, R__v, R__s, R__c);
4259 TH1::Streamer(R__b);
4260 TArrayD::Streamer(R__b);
4261 R__b.ReadVersion(&R__s, &R__c);
4262 TAtt3D::Streamer(R__b);
4264 TH3::Streamer(R__b);
4265 TArrayD::Streamer(R__b);
4266 R__b.CheckByteCount(R__s, R__c, TH3D::IsA());
4271 R__b.WriteClassBuffer(TH3D::Class(),
this);
4279 TH3D& TH3D::operator=(
const TH3D &h1)
4281 if (
this != &h1) ((TH3D&)h1).Copy(*
this);
4289 TH3D operator*(Float_t c1, TH3D &h1)
4293 hnew.SetDirectory(0);
4301 TH3D operator+(TH3D &h1, TH3D &h2)
4305 hnew.SetDirectory(0);
4313 TH3D operator-(TH3D &h1, TH3D &h2)
4317 hnew.SetDirectory(0);
4325 TH3D operator*(TH3D &h1, TH3D &h2)
4329 hnew.SetDirectory(0);
4337 TH3D operator/(TH3D &h1, TH3D &h2)
4341 hnew.SetDirectory(0);