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