ROOT   Reference Guide
Searching...
No Matches
TProfile3D.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 17/05/2006
3
4/*************************************************************************
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. * 9 * For the list of contributors see$ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TProfile3D.h"
13#include "TProfile2D.h"
14#include "THashList.h"
15#include "TMath.h"
16#include "THLimitsFinder.h"
17#include <iostream>
18#include "TError.h"
19#include "TClass.h"
20
21#include "TProfileHelper.h"
22
24
26
27/** \class TProfile3D
28 \ingroup Hist
29 Profile3D histograms are used to display the mean
30 value of T and its RMS for each cell in X,Y,Z.
31 Profile3D histograms are in many cases an
32 The inter-relation of three measured quantities X, Y, Z and T can always
33 be visualized by a four-dimensional histogram or scatter-plot;
34 its representation on the line-printer is not particularly
35 satisfactory, except for sparse data. If T is an unknown (but single-valued)
36 approximate function of X,Y,Z this function is displayed by a profile3D histogram with
37 much better precision than by a scatter-plot.
38
39 The following formulae show the cumulated contents (capital letters) and the values
40 displayed by the printing or plotting routines (small letters) of the elements for cell I, J.
41
42 2
43 H(I,J,K) = sum T E(I,J,K) = sum T
44 l(I,J,K) = sum l L(I,J,K) = sum l
45 h(I,J,K) = H(I,J,K)/L(I,J,K) s(I,J,K) = sqrt(E(I,J,K)/L(I,J,K)- h(I,J,K)**2)
46 e(I,J,K) = s(I,J,K)/sqrt(L(I,J,K))
47
48 In the special case where s(I,J,K) is zero (eg, case of 1 entry only in one cell)
49 e(I,J,K) is computed from the average of the s(I,J,K) for all cells,
50 if the static function TProfile3D::Approximate has been called.
51 This simple/crude approximation was suggested in order to keep the cell
52 during a fit operation. But note that this approximation is not the default behaviour.
53
54 Example of a profile3D histogram
55~~~~{.cpp}
56{
57 auto c1 = new TCanvas("c1","Profile histogram example",200,10,700,500);
58 auto hprof3d = new TProfile3D("hprof3d","Profile of pt versus px, py and pz",40,-4,4,40,-4,4,40,0,20);
59 Double_t px, py, pz, pt;
60 TRandom3 r(0);
61 for ( Int_t i=0; i<25000; i++) {
62 r.Rannor(px,py);
63 pz = px*px + py*py;
64 pt = r.Landau(0,1);
65 hprof3d->Fill(px,py,pz,pt,1);
66 }
67 hprof3d->Draw();
68}
69~~~~
70 NOTE: A TProfile3D is drawn as it was a simple TH3
71*/
72
73////////////////////////////////////////////////////////////////////////////////
74/// Default constructor for Profile3D histograms.
75
77{
78 fTsumwt = fTsumwt2 = 0;
80 BuildOptions(0,0,"");
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Default destructor for Profile3D histograms.
85
87{
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Normal Constructor for Profile histograms.
92///
93/// The first eleven parameters are similar to TH3D::TH3D.
94/// All values of t are accepted at filling time.
95/// To fill a profile3D histogram, one must use TProfile3D::Fill function.
96///
97/// Note that when filling the profile histogram the function Fill
98/// checks if the variable t is between fTmin and fTmax.
99/// If a minimum or maximum value is set for the T scale before filling,
100/// then all values below tmin or above tmax will be discarded.
101/// Setting the minimum or maximum value for the T scale before filling
102/// has the same effect as calling the special TProfile3D constructor below
103/// where tmin and tmax are specified.
104///
105/// H(I,J,K) is printed as the cell contents. The errors computed are s(I,J,K) if CHOPT='S'
106/// (spread option), or e(I,J,K) if CHOPT=' ' (error on mean).
107///
108/// See TProfile3D::BuildOptions for explanation of parameters
109///
110/// see other constructors below with all possible combinations of
111/// fix and variable bin size like in TH3D.
112
113TProfile3D::TProfile3D(const char *name,const char *title,Int_t nx,Double_t xlow,Double_t xup,Int_t ny,Double_t ylow,Double_t yup,Int_t nz, Double_t zlow,Double_t zup,Option_t *option)
114 : TH3D(name,title,nx,xlow,xup,ny,ylow,yup,nz,zlow,zup)
115{
116 BuildOptions(0,0,option);
117 if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Create a 3-D Profile with variable bins in X , Y and Z.
122
123TProfile3D::TProfile3D(const char *name,const char *title,Int_t nx,const Double_t *xbins,Int_t ny,const Double_t *ybins,Int_t nz,const Double_t *zbins,Option_t *option)
124 : TH3D(name,title,nx,xbins,ny,ybins,nz,zbins)
125{
126 BuildOptions(0,0,option);
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Set Profile3D histogram structure and options.
131///
132/// - tmin: minimum value allowed for t
133/// - tmax: maximum value allowed for t
134/// if (tmin = tmax = 0) there are no limits on the allowed t values (tmin = -inf, tmax = +inf)
135///
136/// - option: this is the option for the computation of the t error of the profile ( TProfile3D::GetBinError )
137/// possible values for the options are documented in TProfile3D::SetErrorOption
138///
140
142{
143 SetErrorOption(option);
144
145 // create extra profile data structure (bin entries/ y^2 and sum of weight square)
147
148 fTmin = tmin;
149 fTmax = tmax;
151 fTsumwt = fTsumwt2 = 0;
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Copy constructor.
156
158{
159 ((TProfile3D&)profile).Copy(*this);
160}
161
163{
164 ((TProfile3D &)profile).Copy(*this);
165 return *this;
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Performs the operation: this = this + c1*f1 .
170
172{
173 Error("Add","Function not implemented for TProfile3D");
174 return kFALSE;
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Performs the operation: this = this + c1*h1 .
179
181{
182 if (!h1) {
184 return kFALSE;
185 }
186 if (!h1->InheritsFrom(TProfile3D::Class())) {
188 return kFALSE;
189 }
190
191 return TProfileHelper::Add(this, this, h1, 1, c1);
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Replace contents of this profile3D by the addition of h1 and h2.
196///
197/// this = c1*h1 + c2*h2
198
200{
201 if (!h1 || !h2) {
203 return kFALSE;
204 }
205 if (!h1->InheritsFrom(TProfile3D::Class())) {
207 return kFALSE;
208 }
209 if (!h2->InheritsFrom(TProfile3D::Class())) {
211 return kFALSE;
212 }
213
214 return TProfileHelper::Add(this, h1, h2, c1, c2);
215}
216
217
218////////////////////////////////////////////////////////////////////////////////
219/// Set the fgApproximate flag.
220///
221/// When the flag is true, the function GetBinError
222/// will approximate the bin error with the average profile error on all bins
223/// in the following situation only
224///
225/// - the number of bins in the profile3D is less than 10404 (eg 100x100x100)
226/// - the bin number of entries is small ( <5)
227/// - the estimated bin error is extremely small compared to the bin content
228/// (see TProfile3D::GetBinError)
229
231{
232 fgApproximate = approx;
233}
234
235
236////////////////////////////////////////////////////////////////////////////////
237/// Fill histogram with all entries in the buffer.
238///
239/// - action = -1 histogram is reset and refilled from the buffer (called by THistPainter::Paint)
240/// - action = 0 histogram is filled from the buffer
241/// - action = 1 histogram is filled and buffer is deleted
242/// The buffer is automatically deleted when the number of entries
243/// in the buffer is greater than the number of entries in the histogram
244
246{
247 // do we need to compute the bin size?
248 if (!fBuffer) return 0;
249 Int_t nbentries = (Int_t)fBuffer[0];
250 if (!nbentries) return 0;
251 Double_t *buffer = fBuffer;
252 if (nbentries < 0) {
253 if (action == 0) return 0;
254 nbentries = -nbentries;
255 fBuffer=0;
256 Reset("ICES"); // reset without deleting the functions
257 fBuffer = buffer;
258 }
260 //find min, max of entries in buffer
261 Double_t xmin = fBuffer[2];
263 Double_t ymin = fBuffer[3];
265 Double_t zmin = fBuffer[4];
266 Double_t zmax = zmin;
267 for (Int_t i=1;i<nbentries;i++) {
268 Double_t x = fBuffer[5*i+2];
269 if (x < xmin) xmin = x;
270 if (x > xmax) xmax = x;
271 Double_t y = fBuffer[5*i+3];
272 if (y < ymin) ymin = y;
273 if (y > ymax) ymax = y;
274 Double_t z = fBuffer[5*i+4];
275 if (z < zmin) zmin = z;
276 if (z > zmax) zmax = z;
277 }
280 } else {
281 fBuffer = 0;
282 Int_t keep = fBufferSize; fBufferSize = 0;
287 if (zmin < fZaxis.GetXmin()) ExtendAxis(zmin,&fZaxis);
288 if (zmax >= fZaxis.GetXmax()) ExtendAxis(zmax,&fZaxis);
289 fBuffer = buffer;
290 fBufferSize = keep;
291 }
292 }
293
294 fBuffer = 0;
295 for (Int_t i=0;i<nbentries;i++) {
296 Fill(buffer[5*i+2],buffer[5*i+3],buffer[5*i+4],buffer[5*i+5],buffer[5*i+1]);
297 }
298 fBuffer = buffer;
299
300 if (action > 0) { delete [] fBuffer; fBuffer = 0; fBufferSize = 0;}
301 else {
302 if (nbentries == (Int_t)fEntries) fBuffer[0] = -nbentries;
303 else fBuffer[0] = 0;
304 }
305 return nbentries;
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Accumulate arguments in buffer.
310///
311/// When buffer is full, empty the buffer
312///
313/// - fBuffer[0] = number of entries in buffer
314/// - fBuffer[1] = w of first entry
315/// - fBuffer[2] = x of first entry
316/// - fBuffer[3] = y of first entry
317/// - fBuffer[4] = z of first entry
318/// - fBuffer[5] = t of first entry
319
321{
322 if (!fBuffer) return -3;
323 Int_t nbentries = (Int_t)fBuffer[0];
324 if (nbentries < 0) {
325 nbentries = -nbentries;
326 fBuffer[0] = nbentries;
327 if (fEntries > 0) {
328 Double_t *buffer = fBuffer; fBuffer=0;
329 Reset("ICES"); // reset without deleting the functions
330 fBuffer = buffer;
331 }
332 }
333 if (5*nbentries+5 >= fBufferSize) {
334 BufferEmpty(1);
335 return Fill(x,y,z,t,w);
336 }
337 fBuffer[5*nbentries+1] = w;
338 fBuffer[5*nbentries+2] = x;
339 fBuffer[5*nbentries+3] = y;
340 fBuffer[5*nbentries+4] = z;
341 fBuffer[5*nbentries+5] = t;
342 fBuffer[0] += 1;
343 return -2;
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// Copy a Profile3D histogram to a new profile2D histogram.
348
349void TProfile3D::Copy(TObject &obj) const
350{
351 try {
352 TProfile3D & pobj = dynamic_cast<TProfile3D&>(obj);
353
354 TH3D::Copy(pobj);
357 for (int bin=0;bin<fNcells;bin++) {
358 pobj.fArray[bin] = fArray[bin];
359 pobj.fSumw2.fArray[bin] = fSumw2.fArray[bin];
360 }
361 pobj.fTmin = fTmin;
362 pobj.fTmax = fTmax;
363 pobj.fScaling = fScaling;
364 pobj.fErrorMode = fErrorMode;
365 pobj.fTsumwt = fTsumwt;
366 pobj.fTsumwt2 = fTsumwt2;
367
368 } catch(...) {
369 Fatal("Copy","Cannot copy a TProfile3D in a %s",obj.IsA()->GetName());
370 }
371}
372
373////////////////////////////////////////////////////////////////////////////////
374/// Performs the operation: this = this/(c1*f1) .
375///
376/// This function is not implemented
377
379{
380 Error("Divide","Function not implemented for TProfile3D");
381 return kFALSE;
382}
383
384////////////////////////////////////////////////////////////////////////////////
385/// Divide this profile2D by h1.
386///
387/// this = this/h1
388///
389/// This function return kFALSE if the divide operation failed
390
392{
393 if (!h1) {
394 Error("Divide","Attempt to divide a non-existing profile2D");
395 return kFALSE;
396 }
397 if (!h1->InheritsFrom(TProfile3D::Class())) {
398 Error("Divide","Attempt to divide a non-profile3D object");
399 return kFALSE;
400 }
401 TProfile3D *p1 = (TProfile3D*)h1;
402
403 // delete buffer if it is there since it will become invalid
404 if (fBuffer) BufferEmpty(1);
405
406// Check profile compatibility
407 Int_t nx = GetNbinsX();
408 if (nx != p1->GetNbinsX()) {
409 Error("Divide","Attempt to divide profiles with different number of bins");
410 return kFALSE;
411 }
412 Int_t ny = GetNbinsY();
413 if (ny != p1->GetNbinsY()) {
414 Error("Divide","Attempt to divide profiles with different number of bins");
415 return kFALSE;
416 }
417 Int_t nz = GetNbinsZ();
418 if (nz != p1->GetNbinsZ()) {
419 Error("Divide","Attempt to divide profiles with different number of bins");
420 return kFALSE;
421 }
422
423// Reset statistics
425
426// Loop on bins (including underflows/overflows)
427 Int_t bin,binx,biny,binz;
428 Double_t *cu1 = p1->GetW();
429 Double_t *er1 = p1->GetW2();
430 Double_t *en1 = p1->GetB();
431 Double_t c0,c1,w,u,x,y,z;
432 for (binx =0;binx<=nx+1;binx++) {
433 for (biny =0;biny<=ny+1;biny++) {
434 for (binz =0;binz<=nz+1;binz++) {
435 bin = GetBin(binx,biny,binz);
436 c0 = fArray[bin];
437 c1 = cu1[bin];
438 if (c1) w = c0/c1;
439 else w = 0;
440 fArray[bin] = w;
441 u = TMath::Abs(w);
442 x = fXaxis.GetBinCenter(binx);
443 y = fYaxis.GetBinCenter(biny);
444 z = fZaxis.GetBinCenter(binz);
445 fEntries++;
446 fTsumw += u;
447 fTsumw2 += u*u;
448 fTsumwx += u*x;
449 fTsumwx2 += u*x*x;
450 fTsumwy += u*y;
451 fTsumwy2 += u*y*y;
452 fTsumwxy += u*x*y;
453 fTsumwz += u;
454 fTsumwz2 += u*z;
455 fTsumwxz += u*x*z;
456 fTsumwyz += u*y*z;
457 fTsumwt += u;
458 fTsumwt2 += u*u;
459 Double_t e0 = fSumw2.fArray[bin];
460 Double_t e1 = er1[bin];
461 Double_t c12= c1*c1;
462 if (!c1) fSumw2.fArray[bin] = 0;
463 else fSumw2.fArray[bin] = (e0*c1*c1 + e1*c0*c0)/(c12*c12);
464 if (!en1[bin]) fBinEntries.fArray[bin] = 0;
465 else fBinEntries.fArray[bin] /= en1[bin];
466 }
467 }
468 }
469 // maintaining the correct sum of weights square is not supported when dividing
470 // bin error resulting from division of profile needs to be checked
471 if (fBinSumw2.fN) {
472 Warning("Divide","Cannot preserve during the division of profiles the sum of bin weight square");
473 fBinSumw2 = TArrayD();
474 }
475 return kTRUE;
476}
477
478////////////////////////////////////////////////////////////////////////////////
479/// Replace contents of this profile2D by the division of h1 by h2.
480///
481/// this = c1*h1/(c2*h2)
482///
483/// This function return kFALSE if the divide operation failed
484
486{
487 TString opt = option;
488 opt.ToLower();
489 Bool_t binomial = kFALSE;
490 if (opt.Contains("b")) binomial = kTRUE;
491 if (!h1 || !h2) {
492 Error("Divide","Attempt to divide a non-existing profile2D");
493 return kFALSE;
494 }
495 if (!h1->InheritsFrom(TProfile3D::Class())) {
496 Error("Divide","Attempt to divide a non-profile2D object");
497 return kFALSE;
498 }
499 TProfile3D *p1 = (TProfile3D*)h1;
500 if (!h2->InheritsFrom(TProfile3D::Class())) {
501 Error("Divide","Attempt to divide a non-profile2D object");
502 return kFALSE;
503 }
504 TProfile3D *p2 = (TProfile3D*)h2;
505
506// Check histogram compatibility
507 Int_t nx = GetNbinsX();
508 if (nx != p1->GetNbinsX() || nx != p2->GetNbinsX()) {
509 Error("Divide","Attempt to divide profiles with different number of bins");
510 return kFALSE;
511 }
512 Int_t ny = GetNbinsY();
513 if (ny != p1->GetNbinsY() || ny != p2->GetNbinsY()) {
514 Error("Divide","Attempt to divide profiles with different number of bins");
515 return kFALSE;
516 }
517 Int_t nz = GetNbinsZ();
518 if (nz != p1->GetNbinsZ() || nz != p2->GetNbinsZ()) {
519 Error("Divide","Attempt to divide profiles with different number of bins");
520 return kFALSE;
521 }
522 if (!c2) {
523 Error("Divide","Coefficient of dividing profile cannot be zero");
524 return kFALSE;
525 }
526
527// Reset statistics
529
530// Loop on bins (including underflows/overflows)
531 Int_t bin,binx,biny,binz;
532 Double_t *cu1 = p1->GetW();
533 Double_t *cu2 = p2->GetW();
534 Double_t *er1 = p1->GetW2();
535 Double_t *er2 = p2->GetW2();
536 Double_t *en1 = p1->GetB();
537 Double_t *en2 = p2->GetB();
538 Double_t b1,b2,w,u,x,y,z,ac1,ac2;
539 ac1 = TMath::Abs(c1);
540 ac2 = TMath::Abs(c2);
541 for (binx =0;binx<=nx+1;binx++) {
542 for (biny =0;biny<=ny+1;biny++) {
543 for (binz =0;binz<=nz+1;binz++) {
544 bin = GetBin(binx,biny,binz);
545 b1 = cu1[bin];
546 b2 = cu2[bin];
547 if (b2) w = c1*b1/(c2*b2);
548 else w = 0;
549 fArray[bin] = w;
550 u = TMath::Abs(w);
551 x = fXaxis.GetBinCenter(binx);
552 y = fYaxis.GetBinCenter(biny);
553 z = fZaxis.GetBinCenter(biny);
554 fEntries++;
555 fTsumw += u;
556 fTsumw2 += u*u;
557 fTsumwx += u*x;
558 fTsumwx2 += u*x*x;
559 fTsumwy += u*y;
560 fTsumwy2 += u*y*y;
561 fTsumwxy += u*x*y;
562 fTsumwz += u*z;
563 fTsumwz2 += u*z*z;
564 fTsumwxz += u*x*z;
565 fTsumwyz += u*y*z;
566 fTsumwt += u;
567 fTsumwt2 += u*u;
568 Double_t e1 = er1[bin];
569 Double_t e2 = er2[bin];
570 //Double_t b22= b2*b2*d2;
571 Double_t b22= b2*b2*TMath::Abs(c2);
572 if (!b2) fSumw2.fArray[bin] = 0;
573 else {
574 if (binomial) {
575 fSumw2.fArray[bin] = TMath::Abs(w*(1-w)/(c2*b2));
576 } else {
577 fSumw2.fArray[bin] = ac1*ac2*(e1*b2*b2 + e2*b1*b1)/(b22*b22);
578 }
579 }
580 if (!en2[bin]) fBinEntries.fArray[bin] = 0;
581 else fBinEntries.fArray[bin] = en1[bin]/en2[bin];
582 }
583 }
584 }
585 return kTRUE;
586}
587
588////////////////////////////////////////////////////////////////////////////////
589/// Fill a Profile3D histogram (no weights).
590
592{
593 if (fBuffer) return BufferFill(x,y,z,t,1);
594
595 Int_t bin,binx,biny,binz;
596
597 if (fTmin != fTmax) {
598 if (t <fTmin || t> fTmax || TMath::IsNaN(t) ) return -1;
599 }
600
601 fEntries++;
602 binx =fXaxis.FindBin(x);
603 biny =fYaxis.FindBin(y);
604 binz =fZaxis.FindBin(z);
605 if (binx <0 || biny <0 || binz<0) return -1;
606 bin = GetBin(binx,biny,binz);
608 fSumw2.fArray[bin] += (Double_t)t*t;
609 fBinEntries.fArray[bin] += 1;
610 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += 1;
611 if (binx == 0 || binx > fXaxis.GetNbins()) {
612 if (!GetStatOverflowsBehaviour()) return -1;
613 }
614 if (biny == 0 || biny > fYaxis.GetNbins()) {
615 if (!GetStatOverflowsBehaviour()) return -1;
616 }
617 if (binz == 0 || binz > fZaxis.GetNbins()) {
618 if (!GetStatOverflowsBehaviour()) return -1;
619 }
620//printf("x=%g, y=%g, z=%g, t=%g, binx=%d, biny=%d, binz=%d, bin=%d\n",x,y,z,t,binx,biny,binz,bin);
621 ++fTsumw;
622 ++fTsumw2;
623 fTsumwx += x;
624 fTsumwx2 += x*x;
625 fTsumwy += y;
626 fTsumwy2 += y*y;
627 fTsumwxy += x*y;
628 fTsumwz += z;
629 fTsumwz2 += z*z;
630 fTsumwxz += x*z;
631 fTsumwyz += y*z;
632 fTsumwt += t;
633 fTsumwt2 += t*t;
634 return bin;
635}
636
637////////////////////////////////////////////////////////////////////////////////
638/// Fill a Profile3D histogram with weights.
639
641{
642 if (fBuffer) return BufferFill(x,y,z,t,w);
643
644 Int_t bin,binx,biny,binz;
645
646 if (fTmin != fTmax) {
647 if (t <fTmin || t> fTmax || TMath::IsNaN(t) ) return -1;
648 }
649
650 Double_t u= w; // (w > 0 ? w : -w);
651 fEntries++;
652 binx =fXaxis.FindBin(x);
653 biny =fYaxis.FindBin(y);
654 binz =fZaxis.FindBin(z);
655 if (binx <0 || biny <0 || binz<0) return -1;
656 bin = GetBin(binx,biny,binz);
658 fSumw2.fArray[bin] += u*t*t;
659 if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
660 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
661 fBinEntries.fArray[bin] += u;
662 if (binx == 0 || binx > fXaxis.GetNbins()) {
663 if (!GetStatOverflowsBehaviour()) return -1;
664 }
665 if (biny == 0 || biny > fYaxis.GetNbins()) {
666 if (!GetStatOverflowsBehaviour()) return -1;
667 }
668 if (binz == 0 || binz > fZaxis.GetNbins()) {
669 if (!GetStatOverflowsBehaviour()) return -1;
670 }
671 fTsumw += u;
672 fTsumw2 += u*u;
673 fTsumwx += u*x;
674 fTsumwx2 += u*x*x;
675 fTsumwy += u*y;
676 fTsumwy2 += u*y*y;
677 fTsumwxy += u*x*y;
678 fTsumwz += u*z;
679 fTsumwz2 += u*z*z;
680 fTsumwxz += u*x*z;
681 fTsumwyz += u*y*z;
682 fTsumwt += u*t;
683 fTsumwt2 += u*t*t;
684 return bin;
685}
686
687////////////////////////////////////////////////////////////////////////////////
688/// Return bin content of a Profile3D histogram.
689
691{
692 if (fBuffer) ((TProfile3D*)this)->BufferEmpty();
693
694 if (bin < 0 || bin >= fNcells) return 0;
695 if (fBinEntries.fArray[bin] == 0) return 0;
696 if (!fArray) return 0;
697 return fArray[bin]/fBinEntries.fArray[bin];
698}
699
700////////////////////////////////////////////////////////////////////////////////
701/// Return bin entries of a Profile3D histogram.
702
704{
705 if (fBuffer) ((TProfile3D*)this)->BufferEmpty();
706
707 if (bin < 0 || bin >= fNcells) return 0;
708 return fBinEntries.fArray[bin];
709}
710
711////////////////////////////////////////////////////////////////////////////////
712/// Return bin effective entries for a weighted filled Profile histogram.
713///
714/// In case of an unweighted profile, it is equivalent to the number of entries per bin
715/// The effective entries is defined as the square of the sum of the weights divided by the
716/// sum of the weights square.
717/// TProfile::Sumw2() must be called before filling the profile with weights.
718/// Only by calling this method the sum of the square of the weights per bin is stored.
719
721{
723}
724
725////////////////////////////////////////////////////////////////////////////////
726/// Return bin error of a Profile3D histogram.
727///
728/// ### Computing errors: A moving field
729///
730/// The computation of errors for a TProfile3D has evolved with the versions
731/// of ROOT. The difficulty is in computing errors for bins with low statistics.
732///
733/// - prior to version 3.10, we had no special treatment of low statistic bins.
734/// As a result, these bins had huge errors. The reason is that the
735/// expression eprim2 is very close to 0 (rounding problems) or 0.
736/// - The algorithm is modified/protected for the case
737/// when a TProfile3D is projected (ProjectionX). The previous algorithm
738/// generated a N^2 problem when projecting a TProfile3D with a large number of
739/// bins (eg 100000).
740/// - in version 3.10/02, a new static function TProfile::Approximate
741/// is introduced to enable or disable (default) the approximation.
743
745{
746 return TProfileHelper::GetBinError((TProfile3D*)this, bin);
747}
748
749////////////////////////////////////////////////////////////////////////////////
750/// Return option to compute profile2D errors.
751
753{
754 if (fErrorMode == kERRORSPREAD) return "s";
755 if (fErrorMode == kERRORSPREADI) return "i";
756 if (fErrorMode == kERRORSPREADG) return "g";
757 return "";
758}
759
760////////////////////////////////////////////////////////////////////////////////
761/// fill the array stats from the contents of this profile.
762///
763/// The array stats must be correctly dimensionned in the calling program.
764///
765/// - stats[0] = sumw
766/// - stats[1] = sumw2
767/// - stats[2] = sumwx
768/// - stats[3] = sumwx2
769/// - stats[4] = sumwy
770/// - stats[5] = sumwy2
771/// - stats[6] = sumwxy
772/// - stats[7] = sumwz
773/// - stats[8] = sumwz2
774/// - stats[9] = sumwxz
775/// - stats[10]= sumwyz
776/// - stats[11]= sumwt
777/// - stats[12]= sumwt2
778///
779/// If no axis-subrange is specified (via TAxis::SetRange), the array stats
780/// is simply a copy of the statistics quantities computed at filling time.
781/// If a sub-range is specified, the function recomputes these quantities
782/// from the bin contents in the current axis range.
783
785{
786 if (fBuffer) ((TProfile3D*)this)->BufferEmpty();
787
788 // Loop on bins
789 if ( (fTsumw == 0 /* && fEntries > 0 */) || fXaxis.TestBit(TAxis::kAxisRange) || fYaxis.TestBit(TAxis::kAxisRange)) {
790
791 // check for labels axis . In that case corresponsing statistics do not make sense and it is set to zero
792 Bool_t labelXaxis = ((const_cast<TAxis &>(fXaxis)).GetLabels() && fXaxis.CanExtend());
793 Bool_t labelYaxis = ((const_cast<TAxis &>(fYaxis)).GetLabels() && fYaxis.CanExtend());
794 Bool_t labelZaxis = ((const_cast<TAxis &>(fZaxis)).GetLabels() && fZaxis.CanExtend());
795
796 Int_t bin, binx, biny,binz;
797 Double_t w, w2;
798 Double_t x,y,z;
799 for (bin=0;bin<kNstat;bin++) stats[bin] = 0;
800 if (!fBinEntries.fArray) return;
801 for (binz=fZaxis.GetFirst();binz<=fZaxis.GetLast();binz++) {
802 z = (!labelZaxis) ? fZaxis.GetBinCenter(binz) : 0;
803 for (biny=fYaxis.GetFirst();biny<=fYaxis.GetLast();biny++) {
804 y = (!labelYaxis) ? fYaxis.GetBinCenter(biny) : 0;
805 for (binx=fXaxis.GetFirst();binx<=fXaxis.GetLast();binx++) {
806 bin = GetBin(binx,biny,binz);
807 w = fBinEntries.fArray[bin];
808 w2 = (fBinSumw2.fN ? fBinSumw2.fArray[bin] : w );
809 x = (!labelXaxis) ? fXaxis.GetBinCenter(binx) : 0;
810 stats[0] += w;
811 stats[1] += w2;
812 stats[2] += w*x;
813 stats[3] += w*x*x;
814 stats[4] += w*y;
815 stats[5] += w*y*y;
816 stats[6] += w*x*y;
817 stats[7] += w*z;
818 stats[8] += w*z*z;
819 stats[9] += w*x*z;
820 stats[10] += w*y*z;
821 stats[11] += fArray[bin];
822 stats[12] += fSumw2.fArray[bin];
823 }
824 }
825 }
826 } else {
827 stats[0] = fTsumw;
828 stats[1] = fTsumw2;
829 stats[2] = fTsumwx;
830 stats[3] = fTsumwx2;
831 stats[4] = fTsumwy;
832 stats[5] = fTsumwy2;
833 stats[6] = fTsumwxy;
834 stats[7] = fTsumwz;
835 stats[8] = fTsumwz2;
836 stats[9] = fTsumwxz;
837 stats[10] = fTsumwyz;
838 stats[11] = fTsumwt;
839 stats[12] = fTsumwt2;
840 }
841}
842
843////////////////////////////////////////////////////////////////////////////////
844/// Reduce the number of bins for this axis to the number of bins having a label.
845
847{
849}
850
851////////////////////////////////////////////////////////////////////////////////
852/// Double the number of bins for axis.
853/// Refill histogram
854/// This function is called by TAxis::FindBin(const char *label)
855
857{
859}
860
861////////////////////////////////////////////////////////////////////////////////
862/// Set option(s) to draw axis with labels.
863///
864/// option might have the following values:
865///
866/// - "a" sort by alphabetic order
867/// - ">" sort by decreasing values
868/// - "<" sort by increasing values
869/// - "h" draw labels horizontal
870/// - "v" draw labels vertical
871/// - "u" draw labels up (end of label right adjusted)
872/// - "d" draw labels down (start of label left adjusted)
873
874void TProfile3D::LabelsOption(Option_t * /* option */, Option_t * /* ax */)
875{
876 Error("LabelsOption","Labels option function is not implemented for a TProfile3D");
877}
878////////////////////////////////////////////////////////////////////////////////
879/// Merge all histograms in the collection in this histogram.
880///
881/// This function computes the min/max for the axes,
882/// compute a new number of bins, if necessary,
883/// add bin contents, errors and statistics.
884/// If overflows are present and limits are different the function will fail.
885/// The function returns the total number of entries in the result histogram
886/// if the merge is successful, -1 otherwise.
887///
888/// IMPORTANT remark. The 2 axis x and y may have different number
889/// of bins and different limits, BUT the largest bin width must be
890/// a multiple of the smallest bin width and the upper limit must also
891/// be a multiple of the bin width.
892
894{
895 return TProfileHelper::Merge(this, li);
896}
897
898////////////////////////////////////////////////////////////////////////////////
899/// Performs the operation: this = this*c1*f1 .
900
902{
903 Error("Multiply","Function not implemented for TProfile3D");
904 return kFALSE;
905}
906
907////////////////////////////////////////////////////////////////////////////////
908/// Multiply this profile2D by h1.
909///
910/// this = this*h1
911
913{
914 Error("Multiply","Multiplication of profile2D histograms not implemented");
915 return kFALSE;
916}
917
918////////////////////////////////////////////////////////////////////////////////
919/// Replace contents of this profile2D by multiplication of h1 by h2.
920///
921/// this = (c1*h1)*(c2*h2)
922
924{
925 Error("Multiply","Multiplication of profile2D histograms not implemented");
926 return kFALSE;
927}
928
929////////////////////////////////////////////////////////////////////////////////
930/// Project this profile3D into a 3-D histogram along X,Y,Z.
931///
932/// The projection is always of the type TH3D.
933///
934/// - if option "E" is specified, the errors are computed. (default)
935/// - if option "B" is specified, the content of bin of the returned histogram
936/// will be equal to the GetBinEntries(bin) of the profile,
937/// - if option "C=E" the bin contents of the projection are set to the
938/// bin errors of the profile
939/// - if option "E" is specified the errors of the projected histogram are computed and set
940/// to be equal to the errors of the profile.
941/// Option "E" is defined as the default one in the header file.
942/// - if option "" is specified the histogram errors are simply the sqrt of its content
943/// - if option "B" is specified, the content of bin of the returned histogram
944/// will be equal to the GetBinEntries(bin) of the profile,
945/// - if option "C=E" the bin contents of the projection are set to the
946/// bin errors of the profile
947/// - if option "W" is specified the bin content of the projected histogram is set to the
948/// product of the bin content of the profile and the entries.
949/// With this option the returned histogram will be equivalent to the one obtained by
950/// filling directly a TH2D using the 3-rd value as a weight.
951/// This option makes sense only for profile filled with all weights =1.
952/// When the profile is weighted (filled with weights different than 1) the
953/// bin error of the projected histogram (obtained using this option "W") cannot be
954/// correctly computed from the information stored in the profile. In that case the
955/// obtained histogram contains as bin error square the weighted sum of the square of the
956/// profiled observable (TProfile2D::fSumw2[bin] )
957///
958/// Note that the axis range is not considered when doing the projection
959
960TH3D *TProfile3D::ProjectionXYZ(const char *name, Option_t *option) const
961{
962
963 TString opt = option;
964 opt.ToLower();
965 Int_t nx = fXaxis.GetNbins();
966 Int_t ny = fYaxis.GetNbins();
967 Int_t nz = fZaxis.GetNbins();
968 const TArrayD *xbins = fXaxis.GetXbins();
969 const TArrayD *ybins = fYaxis.GetXbins();
970 const TArrayD *zbins = fZaxis.GetXbins();
971
972 // Create the projection histogram
973 TString pname = name;
974 if (pname == "_px") {
975 pname = GetName(); pname.Append("_pxyz");
976 }
977 TH3D *h1 = 0 ;
978 if (xbins->fN == 0 && ybins->fN == 0 && zbins->fN == 0)
980 else if ( xbins->fN != 0 && ybins->fN != 0 && zbins->fN != 0)
981 h1 = new TH3D(pname,GetTitle(),nx,xbins->GetArray(),ny,ybins->GetArray(), nz,zbins->GetArray() );
982 else {
983 Error("ProjectionXYZ","Histogram has an axis with variable bins and an axis with fixed bins. This case is not supported - return a null pointer");
984 return 0;
985 }
986
987
988 Bool_t computeErrors = kFALSE;
989 Bool_t cequalErrors = kFALSE;
990 Bool_t binEntries = kFALSE;
991 Bool_t binWeight = kFALSE;
992
993 if (opt.Contains("b")) binEntries = kTRUE;
994 if (opt.Contains("e")) computeErrors = kTRUE;
995 if (opt.Contains("w")) binWeight = kTRUE;
996 if (opt.Contains("c=e")) {cequalErrors = kTRUE; computeErrors=kFALSE;}
997 if (computeErrors || binWeight || (binEntries && fBinSumw2.fN) ) h1->Sumw2();
998
999 // Fill the projected histogram
1000 Int_t bin,binx,biny,binz;
1001 Double_t cont;
1002 for (binx =0;binx<=nx+1;binx++) {
1003 for (biny =0;biny<=ny+1;biny++) {
1004 for (binz =0;binz<=nz+1;binz++) {
1005 bin = GetBin(binx,biny,binz);
1006
1007 if (binEntries) cont = GetBinEntries(bin);
1008 else if (cequalErrors) cont = GetBinError(bin);
1009 else if (binWeight) cont = GetBinContent(bin) * GetBinEntries(bin);
1010 else cont = GetBinContent(bin); // default case
1011
1012 h1->SetBinContent(bin ,cont);
1013
1014 // if option E projected histogram errors are same as profile
1015 if (computeErrors ) h1->SetBinError(bin , GetBinError(bin) );
1016 // in case of option W bin error is deduced from bin sum of z**2 values of profile
1017 // this is correct only if the profile is unweighted
1018 if (binWeight) h1->GetSumw2()->fArray[bin] = fSumw2.fArray[bin];
1019 // in case of bin entries and profile is weighted, we need to set also the bin error
1020 if (binEntries && fBinSumw2.fN ) {
1021 R__ASSERT( h1->GetSumw2() );
1022 h1->GetSumw2()->fArray[bin] = fBinSumw2.fArray[bin];
1023 }
1024 }
1025 }
1026 }
1028 return h1;
1029}
1030////////////////////////////////////////////////////////////////////////////////
1031/// Project a 3-D profile into a 2D-profile histogram depending on the option parameter.
1032///
1033/// option may contain a combination of the characters x,y,z:
1034///
1035/// - option = "xy" return the x versus y projection into a TProfile2D histogram
1036/// - option = "yx" return the y versus x projection into a TProfile2D histogram
1037/// - option = "xz" return the x versus z projection into a TProfile2D histogram
1038/// - option = "zx" return the z versus x projection into a TProfile2D histogram
1039/// - option = "yz" return the y versus z projection into a TProfile2D histogram
1040/// - option = "zy" return the z versus y projection into a TProfile2D histogram
1041///
1042/// NB: the notation "a vs b" means "a" vertical and "b" horizontal along X
1043///
1044/// The resulting profile contains the combination of all the considered bins along X
1045/// By default, all bins are included considering also underflow/overflows
1046///
1047/// The option can also be used to specify the projected profile error type.
1048/// Values which can be used are 's', 'i', or 'g'. See TProfile::BuildOptions for details
1049///
1050/// To select a bin range along an axis, use TAxis::SetRange, eg
1051/// h3.GetYaxis()->SetRange(23,56);
1052
1054{
1055 // can call TH3 method which will call the virtual method :DoProjectProfile2D re-implemented below
1056 // but need to add underflow/overflow
1057 TString opt(option);
1058 opt.Append(" UF OF");
1059 return TH3::Project3DProfile(opt);
1060}
1061
1062////////////////////////////////////////////////////////////////////////////////
1063/// Internal method to project to a 2D Profile.
1064///
1065/// Called from TH3::Project3DProfile but re-implemented in case of the TPRofile3D
1066/// since what is done is different.
1067
1068TProfile2D *TProfile3D::DoProjectProfile2D(const char* name, const char * title, const TAxis* projX, const TAxis* projY,
1069 bool originalRange, bool useUF, bool useOF) const
1070{
1071 // Get the ranges where we will work.
1072 Int_t ixmin = projX->GetFirst();
1073 Int_t ixmax = projX->GetLast();
1074 Int_t iymin = projY->GetFirst();
1075 Int_t iymax = projY->GetLast();
1076 if (ixmin == 0 && ixmax == 0) { ixmin = 1; ixmax = projX->GetNbins(); }
1077 if (iymin == 0 && iymax == 0) { iymin = 1; iymax = projY->GetNbins(); }
1078 Int_t nx = ixmax-ixmin+1;
1079 Int_t ny = iymax-iymin+1;
1080
1081 // Create the projected profiles
1082 TProfile2D *p2 = 0;
1083 // Create always a new TProfile2D (not as in the case of TH3 projection)
1084
1085 const TArrayD *xbins = projX->GetXbins();
1086 const TArrayD *ybins = projY->GetXbins();
1087 // assume all axis have variable bins or have fixed bins
1088 if ( originalRange ) {
1089 if (xbins->fN == 0 && ybins->fN == 0) {
1090 p2 = new TProfile2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1091 ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1092 } else {
1093 p2 = new TProfile2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1],projX->GetNbins(),&xbins->fArray[ixmin-1]);
1094 }
1095 } else {
1096 if (xbins->fN == 0 && ybins->fN == 0) {
1097 p2 = new TProfile2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1098 ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1099 } else {
1100 p2 = new TProfile2D(name,title,ny,&ybins->fArray[iymin-1],nx,&xbins->fArray[ixmin-1]);
1101 }
1102 }
1103
1104 // weights
1105 bool useWeights = (fBinSumw2.fN != 0);
1106 if (useWeights) p2->Sumw2();
1107
1108 // make projection in a 3D first
1109 TH3D * h3dW = ProjectionXYZ("h3temp-W","W");
1110 TH3D * h3dN = ProjectionXYZ("h3temp-N","B");
1111
1112 h3dW->SetDirectory(0); h3dN->SetDirectory(0);
1113
1114 // Since no axis range is considered when doing the projection TProfile3D->TH3D
1115 // the resulting histogram will have the same axis as the parent one
1116 // we need afterwards to set the range in the 3D histogram to considered it later
1117 // when doing the projection in a Profile2D
1121 }
1125 }
1129 }
1130
1131 // note that h3dW is always a weighted histogram - so we need to compute error in the projection
1132 TAxis * projX_hW = h3dW->GetXaxis();
1133 TAxis * projX_hN = h3dN->GetXaxis();
1134 if (projX == GetYaxis() ) { projX_hW = h3dW->GetYaxis(); projX_hN = h3dN->GetYaxis(); }
1135 if (projX == GetZaxis() ) { projX_hW = h3dW->GetZaxis(); projX_hN = h3dN->GetZaxis(); }
1136 TAxis * projY_hW = h3dW->GetYaxis();
1137 TAxis * projY_hN = h3dN->GetYaxis();
1138 if (projY == GetXaxis() ) { projY_hW = h3dW->GetXaxis(); projY_hN = h3dN->GetXaxis(); }
1139 if (projY == GetZaxis() ) { projY_hW = h3dW->GetZaxis(); projY_hN = h3dN->GetZaxis(); }
1140
1141 TH2D * h2W = TH3::DoProject2D(*h3dW,"htemp-W","",projX_hW, projY_hW, true, originalRange, useUF, useOF);
1142 TH2D * h2N = TH3::DoProject2D(*h3dN,"htemp-N","",projX_hN, projY_hN, useWeights, originalRange, useUF, useOF);
1143 h2W->SetDirectory(0); h2N->SetDirectory(0);
1144
1145
1146 // fill the bin content
1147 R__ASSERT( h2W->fN == p2->fN );
1148 R__ASSERT( h2N->fN == p2->fN );
1149 R__ASSERT( h2W->GetSumw2()->fN != 0); // h2W should always be a weighted histogram since h3dW is weighted
1150 for (int i = 0; i < p2->fN ; ++i) {
1151 //std::cout << " proj bin " << i << " " << h2W->fArray[i] << " " << h2N->fArray[i] << std::endl;
1152 p2->fArray[i] = h2W->fArray[i]; // array of profile is sum of all values
1153 p2->GetSumw2()->fArray[i] = h2W->GetSumw2()->fArray[i]; // array of content square of profile is weight square of the W projected histogram
1154 p2->SetBinEntries(i, h2N->fArray[i] );
1155 if (useWeights) p2->GetBinSumw2()->fArray[i] = h2N->GetSumw2()->fArray[i]; // sum of weight squares are stored to compute errors in h1N histogram
1156 }
1157 // delete the created histograms
1158 delete h3dW;
1159 delete h3dN;
1160 delete h2W;
1161 delete h2N;
1162
1163 // Also we need to set the entries since they have not been correctly calculated during the projection
1164 // we can only set them to the effective entries
1165 p2->SetEntries( p2->GetEffectiveEntries() );
1166
1167 return p2;
1168
1169}
1170
1171////////////////////////////////////////////////////////////////////////////////
1172/// Replace current statistics with the values in array stats.
1173
1175{
1176 TH3::PutStats(stats);
1177 fTsumwt = stats[11];
1178 fTsumwt2 = stats[12];
1179}
1180
1181////////////////////////////////////////////////////////////////////////////////
1182/// Reset contents of a Profile3D histogram.
1183
1185{
1186 TH3D::Reset(option);
1187 fBinSumw2.Reset();
1189 TString opt = option;
1190 opt.ToUpper();
1191 if (opt.Contains("ICE") && !opt.Contains("S")) return;
1192 fTsumwt = fTsumwt2 = 0;
1193}
1194
1195////////////////////////////////////////////////////////////////////////////////
1196/// Profile histogram is resized along axis such that x is in the axis range.
1197/// The new axis limits are recomputed by doubling iteratively
1198/// the current axis range until the specified value x is within the limits.
1199/// The algorithm makes a copy of the histogram, then loops on all bins
1200/// of the old histogram to fill the rebinned histogram.
1201/// Takes into account errors (Sumw2) if any.
1202/// The axis must be rebinnable before invoking this function.
1203/// Ex: h->GetXaxis()->SetCanExtend(kTRUE)
1204
1206{
1207 TProfile3D* hold = TProfileHelper::ExtendAxis(this, x, axis);
1208 if ( hold ) {
1209 fTsumwt = hold->fTsumwt;
1210 fTsumwt2 = hold->fTsumwt2;
1211 delete hold;
1212 }
1213}
1214
1215////////////////////////////////////////////////////////////////////////////////
1216/// Save primitive as a C++ statement(s) on output stream out.
1217///
1218/// Note the following restrictions in the code generated:
1219/// - variable bin size not implemented
1220/// - SetErrorOption not implemented
1221
1222void TProfile3D::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1223{
1224 char quote = '"';
1225 out <<" "<<std::endl;
1226 out <<" "<<ClassName()<<" *";
1227
1228 out << GetName() << " = new " << ClassName() << "(" << quote
1229 << GetName() << quote << "," << quote<< GetTitle() << quote
1230 << "," << GetXaxis()->GetNbins();
1231 out << "," << GetXaxis()->GetXmin()
1232 << "," << GetXaxis()->GetXmax();
1233 out << "," << GetYaxis()->GetNbins();
1234 out << "," << GetYaxis()->GetXmin()
1235 << "," << GetYaxis()->GetXmax();
1236 out << "," << GetZaxis()->GetNbins();
1237 out << "," << GetZaxis()->GetXmin()
1238 << "," << GetZaxis()->GetXmax();
1239 out << "," << fTmin
1240 << "," << fTmax;
1241 out << ");" << std::endl;
1242
1243
1244 // save bin entries
1245 Int_t bin;
1246 for (bin=0;bin<fNcells;bin++) {
1247 Double_t bi = GetBinEntries(bin);
1248 if (bi) {
1249 out<<" "<<GetName()<<"->SetBinEntries("<<bin<<","<<bi<<");"<<std::endl;
1250 }
1251 }
1252 //save bin contents
1253 for (bin=0;bin<fNcells;bin++) {
1254 Double_t bc = fArray[bin];
1255 if (bc) {
1256 out<<" "<<GetName()<<"->SetBinContent("<<bin<<","<<bc<<");"<<std::endl;
1257 }
1258 }
1259 // save bin errors
1260 if (fSumw2.fN) {
1261 for (bin=0;bin<fNcells;bin++) {
1262 Double_t be = TMath::Sqrt(fSumw2.fArray[bin]);
1263 if (be) {
1264 out<<" "<<GetName()<<"->SetBinError("<<bin<<","<<be<<");"<<std::endl;
1265 }
1266 }
1267 }
1268
1269 TH1::SavePrimitiveHelp(out, GetName(), option);
1270}
1271
1272////////////////////////////////////////////////////////////////////////////////
1273/// Multiply this profile2D by a constant c1.
1274///
1275/// this = c1*this
1276///
1277/// This function uses the services of TProfile3D::Add
1278
1280{
1281 TProfileHelper::Scale(this, c1, option);
1282}
1283
1284////////////////////////////////////////////////////////////////////////////////
1285///Set the number of entries in bin.
1286
1288{
1289 TProfileHelper::SetBinEntries(this, bin, w);
1290}
1291
1292////////////////////////////////////////////////////////////////////////////////
1293/// Redefine x, y and z axis parameters.
1294
1296{
1297 TH1::SetBins(nx, xmin, xmax, ny, ymin, ymax, nz, zmin, zmax);
1300}
1301
1302////////////////////////////////////////////////////////////////////////////////
1303/// Redefine x, y and z axis parameters with variable bin sizes
1304
1305void TProfile3D::SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t *yBins, Int_t nz, const Double_t *zBins)
1306{
1307 TH1::SetBins(nx,xBins,ny,yBins,nz,zBins);
1310}
1311
1312////////////////////////////////////////////////////////////////////////////////
1313/// Set total number of bins including under/overflow.
1314///
1315/// Reallocate bin contents array
1316
1318{
1321}
1322
1323////////////////////////////////////////////////////////////////////////////////
1324/// Set the buffer size in units of 8 bytes (double).
1325
1327{
1328 if (fBuffer) {
1329 BufferEmpty();
1330 delete [] fBuffer;
1331 fBuffer = 0;
1332 }
1333 if (buffersize <= 0) {
1334 fBufferSize = 0;
1335 return;
1336 }
1337 if (buffersize < 100) buffersize = 100;
1338 fBufferSize = 1 + 5*buffersize;
1340 memset(fBuffer,0,sizeof(Double_t)*fBufferSize);
1341}
1342
1343////////////////////////////////////////////////////////////////////////////////
1344/// Set option to compute profile3D errors.
1345///
1346/// The computation of the bin errors is based on the parameter option:
1347/// - ' ' (Default) The bin errors are the standard error on the mean of the bin profiled values (T),
1348/// i.e. the standard error of the bin contents.
1349/// Note that if TProfile3D::Approximate() is called, an approximation is used when
1350/// the spread in T is 0 and the number of bin entries is > 0
1351/// - 's' The bin errors are the standard deviations of the T bin values
1352/// Note that if TProfile3D::Approximate() is called, an approximation is used when
1353/// the spread in T is 0 and the number of bin entries is > 0
1354/// - 'i' Errors are as in default case (standard errors of the bin contents)
1355/// The only difference is for the case when the spread in T is zero.
1356/// In this case for N > 0 the error is 1./SQRT(12.*N)
1357/// - 'g' Errors are 1./SQRT(W) for W not equal to 0 and 0 for W = 0.
1358/// W is the sum in the bin of the weights of the profile.
1359/// This option is for combining measurements t +/- dt,
1360/// and the profile is filled with values t and weights w = 1/dt**2
1361///
1362/// See TProfile::BuildOptions for explanation of all options
1363
1365{
1366 TProfileHelper::SetErrorOption(this, option);
1367}
1368
1369////////////////////////////////////////////////////////////////////////////////
1370/// Create/Delete structure to store sum of squares of weights per bin
1371/// This is needed to compute the correct statistical quantities
1372/// of a profile filled with weights
1373///
1374/// This function is automatically called when the histogram is created
1375/// if the static function TH1::SetDefaultSumw2 has been called before.
1376/// If flag = false the structure is deleted
1377
1379{
1380 TProfileHelper::Sumw2(this, flag);
1381}
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:92
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:73
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
#define R__ASSERT(e)
Definition TError.h:120
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:231
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition TError.cxx:245
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
Definition TProfile.h:28
Definition TProfile.h:28
Definition TProfile.h:28
Array of doubles (64 bits per element).
Definition TArrayD.h:27
Double_t * fArray
Definition TArrayD.h:30
void Copy(TArrayD &array) const
Definition TArrayD.h:42
void Set(Int_t n)
Set size of this array to n doubles.
Definition TArrayD.cxx:106
TArrayD()
Default TArrayD ctor.
Definition TArrayD.cxx:26
const Double_t * GetArray() const
Definition TArrayD.h:43
void Reset()
Definition TArrayD.h:47
Int_t fN
Definition TArray.h:38
Class to manage histogram axis.
Definition TAxis.h:30
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition TAxis.cxx:478
Bool_t CanExtend() const
Definition TAxis.h:82
const TArrayD * GetXbins() const
Definition TAxis.h:130
Double_t GetXmax() const
Definition TAxis.h:134
@ kAxisRange
Definition TAxis.h:61
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition TAxis.cxx:293
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition TAxis.cxx:518
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:469
Double_t GetXmin() const
Definition TAxis.h:133
Int_t GetNbins() const
Definition TAxis.h:121
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:920
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition TAxis.cxx:528
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition TAxis.cxx:458
Collection abstract base class.
Definition TCollection.h:63
1-Dim function class
Definition TF1.h:213
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8777
Double_t * fBuffer
[fBufferSize] entry buffer
Definition TH1.h:107
virtual Double_t GetEffectiveEntries() const
Number of effective entries of the histogram.
Definition TH1.cxx:4411
TAxis * GetZaxis()
Definition TH1.h:322
Int_t fNcells
number of bins(1D), cells (2D) +U/Overflows
Definition TH1.h:88
Double_t fTsumw
Total Sum of weights.
Definition TH1.h:95
Double_t fTsumw2
Total Sum of squares of weights.
Definition TH1.h:96
Double_t fTsumwx2
Total Sum of weight*X*X.
Definition TH1.h:98
virtual Int_t GetNbinsY() const
Definition TH1.h:297
virtual Int_t GetNbinsZ() const
Definition TH1.h:298
@ kIsNotW
Histogram is forced to be not weighted even when the histogram is filled with weighted different than...
Definition TH1.h:171
virtual Bool_t CanExtendAllAxes() const
Returns true if all axes are extendable.
Definition TH1.cxx:6596
TAxis * GetXaxis()
Definition TH1.h:320
virtual Int_t GetNbinsX() const
Definition TH1.h:296
Int_t fBufferSize
fBuffer size
Definition TH1.h:106
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
Definition TH1.cxx:9046
static Int_t fgBufferSize
!default buffer size for automatic histograms
Definition TH1.h:114
TAxis * GetYaxis()
Definition TH1.h:321
virtual void SavePrimitiveHelp(std::ostream &out, const char *hname, Option_t *option="")
Helper function for the SavePrimitive functions from TH1 or classes derived from TH1,...
Definition TH1.cxx:7264
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition TH1.cxx:9062
@ kNstat
Definition TH1.h:183
Double_t fEntries
Number of entries.
Definition TH1.h:94
TAxis fZaxis
Z axis descriptor.
Definition TH1.h:91
virtual TArrayD * GetSumw2()
Definition TH1.h:312
TAxis fXaxis
X axis descriptor.
Definition TH1.h:89
TArrayD fSumw2
Array of sum of squares of weights.
Definition TH1.h:103
Bool_t GetStatOverflowsBehaviour() const
Definition TH1.h:152
TAxis fYaxis
Y axis descriptor.
Definition TH1.h:90
virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax)
Redefine x axis parameters.
Definition TH1.cxx:8607
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:8860
virtual void SetEntries(Double_t n)
Definition TH1.h:385
Double_t fTsumwx
Total Sum of weight*X.
Definition TH1.h:97
2-D histogram with a double per channel (see TH1 documentation)}
Definition TH2.h:292
3-D histogram with a double per channel (see TH1 documentation)}
Definition TH3.h:305
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition TH3.cxx:4376
TH3D()
Constructor.
Definition TH3.cxx:4287
Increment bin content by 1.
Definition TH3.h:319
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition TH3.cxx:4355
Double_t fTsumwy
Definition TH3.h:34
Double_t fTsumwy2
Definition TH3.h:35
virtual TH2D * DoProject2D(const char *name, const char *title, const TAxis *projX, const TAxis *projY, bool computeErrors, bool originalRange, bool useUF, bool useOF) const
internal method performing the projection to a 2D histogram called from TH3::Project3D
Definition TH3.cxx:2011
Double_t fTsumwxz
Definition TH3.h:39
virtual Int_t GetBin(Int_t binx, Int_t biny, Int_t binz) const
Definition TH3.cxx:1026
virtual TProfile2D * Project3DProfile(Option_t *option="xy") const
Project a 3-d histogram into a 2-d profile histograms depending on the option parameter option may co...
Definition TH3.cxx:2677
Double_t fTsumwz2
Definition TH3.h:38
Double_t fTsumwxy
Definition TH3.h:36
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
Definition TH3.cxx:2760
Double_t fTsumwz
Definition TH3.h:37
Double_t fTsumwyz
Definition TH3.h:40
static THLimitsFinder * GetLimitsFinder()
Return pointer to the current finder.
virtual Int_t FindGoodLimits(TH1 *h, Double_t xmin, Double_t xmax)
Compute the best axis limits for the X axis.
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:187
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:130
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
Profile2D histograms are used to display the mean value of Z and its error for each cell in X,...
Definition TProfile2D.h:27
virtual void SetBinEntries(Int_t bin, Double_t w)
Set the number of entries in bin.
virtual void Sumw2(Bool_t flag=kTRUE)
Create/Delete structure to store sum of squares of weights per bin.
virtual TArrayD * GetBinSumw2()
Definition TProfile2D.h:116
Profile3D histograms are used to display the mean value of T and its RMS for each cell in X,...
Definition TProfile3D.h:27
TProfile3D & operator=(const TProfile3D &profile)
virtual TProfile2D * DoProjectProfile2D(const char *name, const char *title, const TAxis *projX, const TAxis *projY, bool originalRange, bool useUF, bool useOF) const
Internal method to project to a 2D Profile.
Double_t * GetW()
Definition TProfile3D.h:75
virtual void Sumw2(Bool_t flag=kTRUE)
Create/Delete structure to store sum of squares of weights per bin This is needed to compute the corr...
virtual void ExtendAxis(Double_t x, TAxis *axis)
Profile histogram is resized along axis such that x is in the axis range.
static Bool_t fgApproximate
Definition TProfile3D.h:42
virtual void LabelsDeflate(Option_t *axis="X")
Reduce the number of bins for this axis to the number of bins having a label.
virtual void SetBuffer(Int_t buffersize, Option_t *opt="")
Set the buffer size in units of 8 bytes (double).
virtual Int_t BufferEmpty(Int_t action=0)
Fill histogram with all entries in the buffer.
virtual Long64_t Merge(TCollection *list)
Merge all histograms in the collection in this histogram.
Option_t * GetErrorOption() const
Return option to compute profile2D errors.
Bool_t fScaling
Definition TProfile3D.h:38
void SetBins(const Int_t *nbins, const Double_t *range)
Definition TProfile3D.h:50
virtual Double_t GetBinError(Int_t bin) const
Return bin error of a Profile3D histogram.
Double_t fTsumwt2
Definition TProfile3D.h:40
virtual Double_t GetBinEffectiveEntries(Int_t bin)
Return bin effective entries for a weighted filled Profile histogram.
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 .
virtual void GetStats(Double_t *stats) const
fill the array stats from the contents of this profile.
TProfile3D()
Default constructor for Profile3D histograms.
TArrayD fBinEntries
Definition TProfile3D.h:34
virtual Double_t GetBinContent(Int_t bin) const
Return bin content of a Profile3D histogram.
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this profile2D by a constant c1.
virtual Bool_t Multiply(TF1 *h1, Double_t c1=1)
Performs the operation: this = this*c1*f1 .
Double_t fTmin
Definition TProfile3D.h:36
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
virtual TProfile2D * Project3DProfile(Option_t *option="xy") const
Project a 3-D profile into a 2D-profile histogram depending on the option parameter.
virtual void SetBinEntries(Int_t bin, Double_t w)
Set the number of entries in bin.
virtual void Copy(TObject &hnew) const
Copy a Profile3D histogram to a new profile2D histogram.
void BuildOptions(Double_t tmin, Double_t tmax, Option_t *option)
Set Profile3D histogram structure and options.
Int_t Fill(const Double_t *v)
Definition TProfile3D.h:53
TArrayD fBinSumw2
Definition TProfile3D.h:41
Double_t * GetB()
Definition TProfile3D.h:73
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
virtual void SetErrorOption(Option_t *option="")
Set option to compute profile3D errors.
virtual Bool_t Divide(TF1 *h1, Double_t c1=1)
Performs the operation: this = this/(c1*f1) .
virtual ~TProfile3D()
Default destructor for Profile3D histograms.
virtual TH3D * ProjectionXYZ(const char *name="_pxyz", Option_t *option="e") const
Project this profile3D into a 3-D histogram along X,Y,Z.
virtual void LabelsInflate(Option_t *axis="X")
Double the number of bins for axis.
EErrorType fErrorMode
Definition TProfile3D.h:35
virtual Int_t BufferFill(Double_t, Double_t)
accumulate arguments in buffer.
Definition TProfile3D.h:44
virtual Double_t GetBinEntries(Int_t bin) const
Return bin entries of a Profile3D histogram.
Double_t * GetW2()
Definition TProfile3D.h:76
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow.
Double_t fTsumwt
True when TProfile3D::Scale is called.
Definition TProfile3D.h:39
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Set option(s) to draw axis with labels.
static void Approximate(Bool_t approx=kTRUE)
Set the fgApproximate flag.
Double_t fTmax
Definition TProfile3D.h:37
static void LabelsInflate(T *p, Option_t *)
static Double_t GetBinError(T *p, Int_t bin)
static T * ExtendAxis(T *p, Double_t x, TAxis *axis)
static void Sumw2(T *p, Bool_t flag)
static void SetBinEntries(T *p, Int_t bin, Double_t w)
static void Scale(T *p, Double_t c1, Option_t *option)
static void SetErrorOption(T *p, Option_t *opt)
static Long64_t Merge(T *p, TCollection *list)
static void BuildArray(T *p)
static Bool_t Add(T *p, const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2=1)
static Double_t GetBinEffectiveEntries(T *p, Int_t bin)
static void LabelsDeflate(T *p, Option_t *)
Basic string class.
Definition TString.h:136
void ToLower()
Change string to lower-case.
Definition TString.cxx:1145
void ToUpper()
Change string to upper case.
Definition TString.cxx:1158
TString & Append(const char *cs)
Definition TString.h:564
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
return c1
Definition legend1.C:41
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TH1F * h1
Definition legend1.C:5
return c2
Definition legend2.C:14
Bool_t IsNaN(Double_t x)
Definition TMath.h:892
Double_t Sqrt(Double_t x)
Definition TMath.h:691
Short_t Abs(Short_t d)
Definition TMathBase.h:120