Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TProfile.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 29/09/95
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 "TProfile.h"
13#include "TBuffer.h"
14#include "TMath.h"
15#include "TF1.h"
16#include "THLimitsFinder.h"
17#include <iostream>
18#include "TError.h"
19#include "TClass.h"
20#include "TObjString.h"
21
22#include "TProfileHelper.h"
23
25
27
28/** \class TProfile
29 \ingroup Histograms
30 Profile Histogram.
31 Profile histograms are used to display the mean
32 value of Y and its error for each bin in X. The displayed error is by default the
33 standard error on the mean (i.e. the standard deviation divided by the sqrt(n) ).
34 Profile histograms are in many cases an
35 elegant replacement of two-dimensional histograms. The inter-relation of two
36 measured quantities X and Y can always be visualized by a two-dimensional
37 histogram or scatter plot, but if Y is an unknown (but single-valued)
38 approximate function of X, this function is displayed by a profile histogram with
39 much better precision than by a scatter plot.
40
41 The following formulae show the cumulated contents (capital letters) and the values
42 displayed by the printing or plotting routines (small letters) of the elements for bin j.
43 \f[
44 \begin{align}
45 H(j) &= \sum w \cdot Y \\
46 E(j) &= \sum w \cdot Y^2 \\
47 W(j) &= \sum w & &\text{if weights different from 1, the number of bin effective entries is used} \\
48 h(j) &= H(j) / W(j) & &\text{mean of Y,} \\
49 s(j) &= \sqrt{E(j)/W(j)- h(j)^2} & &\text{standard deviation of Y} \\
50 e(j) &= s(j)/\sqrt{W(j)} & &\text{standard error on the mean} \\
51 \end{align}
52 \f]
53 The bin content is always the mean of the Y values, but errors change depending on options:
54 \f[
55 \begin{align}
56 \text{GetBinContent}(j) &= h(j) \\
57 \text{GetBinError}(j) &=
58 \begin{cases}
59 e(j) &\text{if option="" (default). Error of the mean of all y values.} \\
60 s(j) &\text{if option="s". Standard deviation of all y values.} \\
61 \begin{cases} e(j) &\text{if } h(j) \ne 0 \\ 1/\sqrt{12 N} &\text{if } h(j)=0 \end{cases} &\text{if option="i". This is useful for storing integers such as ADC counts.} \\
62 1/\sqrt{W(j)} &\text{if option="g". Error of a weighted mean for combining measurements with variances of } w. \\
63 \end{cases}
64 \end{align}
65 \f]
66 In the special case where s(j) is zero (eg, case of 1 entry only in one bin)
67 the bin error e(j) is computed from the average of the s(j) for all bins if
68 the static function TProfile::Approximate() has been called.
69 This simple/crude approximation was suggested in order to keep the bin
70 during a fit operation. But note that this approximation is not the default behaviour.
71 See also TProfile::BuildOptions for more on error options.
72
73 ### Creating and drawing a profile histogram
74~~~{.cpp}
75{
76 auto c1 = new TCanvas("c1","Profile histogram example",200,10,700,500);
77 auto hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
78 Float_t px, py, pz;
79 for ( Int_t i=0; i<25000; i++) {
80 gRandom->Rannor(px,py);
81 pz = px*px + py*py;
82 hprof->Fill(px,pz,1);
83 }
84 hprof->Draw();
85}
86~~~
87*/
88
89////////////////////////////////////////////////////////////////////////////////
90/// Default constructor for Profile histograms
91
93{
94 BuildOptions(0,0,"");
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Default destructor for Profile histograms
99
101{
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Normal Constructor for Profile histograms.
106///
107/// The first five parameters are similar to TH1D::TH1D.
108/// All values of y are accepted at filling time.
109/// To fill a profile histogram, one must use TProfile::Fill function.
110///
111/// Note that when filling the profile histogram the function Fill
112/// checks if the variable y is between fYmin and fYmax.
113/// If a minimum or maximum value is set for the Y scale before filling,
114/// then all values below ymin or above ymax will be discarded.
115/// Setting the minimum or maximum value for the Y scale before filling
116/// has the same effect as calling the special TProfile constructor below
117/// where ymin and ymax are specified.
118///
119/// H(j) is printed as the channel contents. The errors displayed are s(j) if `option`='S'
120/// (spread option), or e(j) if `CHOPT`='' (error on mean).
121///
122/// See TProfile::BuildOptions() for explanation of parameters
123///
124/// see also comments in the TH1 base class constructors
125
126TProfile::TProfile(const char *name,const char *title,Int_t nbins,Double_t xlow,Double_t xup,Option_t *option)
127: TH1D(name,title,nbins,xlow,xup)
128{
129 BuildOptions(0,0,option);
130}
131
132////////////////////////////////////////////////////////////////////////////////
133/// Constructor for Profile histograms with variable bin size.
134///
135/// See TProfile::BuildOptions() for more explanations on errors
136/// see also comments in the TH1 base class constructors
137
138TProfile::TProfile(const char *name,const char *title,Int_t nbins,const Float_t *xbins,Option_t *option)
139: TH1D(name,title,nbins,xbins)
140{
141 BuildOptions(0,0,option);
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Constructor for Profile histograms with variable bin size.
146///
147/// See TProfile::BuildOptions for more explanations on errors
148/// see also comments in the TH1 base class constructors
149
150TProfile::TProfile(const char *name,const char *title,Int_t nbins,const Double_t *xbins,Option_t *option)
151: TH1D(name,title,nbins,xbins)
152{
153 BuildOptions(0,0,option);
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// Constructor for Profile histograms with variable bin size.
158/// See TProfile::BuildOptions for more explanations on errors
159///
160/// see also comments in the TH1 base class constructors
161
162TProfile::TProfile(const char *name,const char *title,Int_t nbins,const Double_t *xbins,Double_t ylow,Double_t yup,Option_t *option)
163: TH1D(name,title,nbins,xbins)
164{
165 BuildOptions(ylow,yup,option);
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Constructor for Profile histograms with range in y.
170///
171/// The first five parameters are similar to TH1D::TH1D.
172/// Only the values of Y between ylow and yup will be considered at filling time.
173/// ylow and yup will also be the maximum and minimum values
174/// on the y scale when drawing the profile.
175///
176/// See TProfile::BuildOptions for more explanations on errors
177///
178/// see also comments in the TH1 base class constructors
179
180TProfile::TProfile(const char *name,const char *title,Int_t nbins,Double_t xlow,Double_t xup,Double_t ylow,Double_t yup,Option_t *option)
181: TH1D(name,title,nbins,xlow,xup)
182{
183 BuildOptions(ylow,yup,option);
184}
185
186
187////////////////////////////////////////////////////////////////////////////////
188/// Set Profile histogram structure and options.
189///
190/// \param[in] ymin minimum value allowed for y
191/// \param[in] ymax maximum value allowed for y
192/// if (ymin = ymax = 0) there are no limits on the allowed y values (ymin = -inf, ymax = +inf)
193/// \param[in] option this is the option for the computation of the y error of the profile ( TProfile::GetBinError )
194/// possible values for the options are:
195/// - ' ' (Default) the bin errors are the standard error on the mean of Y = S(Y)/SQRT(N)
196/// where S(Y) is the standard deviation (RMS) of the Y data in the bin
197/// and N is the number of bin entries (from TProfile::GetBinEntries(ibin) )
198/// (i.e the errors are the standard error on the bin content of the profile)
199/// - 's' Errors are the standard deviation of Y, S(Y)
200/// - 'i' Errors are S(Y)/SQRT(N) (standard error on the mean as in the default)
201/// The only difference is only when the standard deviation in Y is zero.
202/// In this case the error a standard deviation = 1/SQRT(12) is assumed and the error is
203/// 1./SQRT(12*N).
204/// This approximation assumes that the Y values are integer (e.g. ADC counts)
205/// and have an implicit uncertainty of y +/- 0.5. With the assumption that the probability that y
206/// takes any value between y-0.5 and y+0.5 is uniform, its standard error is 1/SQRT(12)
207/// - 'g' Errors are 1./SQRT(W) where W is the sum of the weights for the bin j
208/// W is obtained as from TProfile::GetBinEntries(ibin)
209/// This errors corresponds to the standard deviation of weighted mean where each
210/// measurement Y is uncorrelated and has an error sigma, which is expressed in the
211/// weight used to fill the Profile: w = 1/sigma^2
212/// The resulting error in TProfile is then 1./SQRT( Sum(1./sigma^2) )
213///
214/// In the case of Profile filled weights and with TProfile::Sumw2() called,
215/// STD(Y) is the standard deviation of the weighted sample Y and N is in this case the
216/// number of effective entries (TProfile::GetBinEffectiveEntries(ibin) )
217///
218/// If a bin has N data points all with the same value Y (especially
219/// possible when dealing with integers), the spread in Y for that bin
220/// is zero, and the uncertainty assigned is also zero, and the bin is
221/// ignored in making subsequent fits.
222/// To avoid this problem one can use an approximation for the standard deviation S(Y),
223/// by using the average of all the S(Y) of the other Profile bins. To use this approximation
224/// one must call before TProfile::Approximate
225/// This approximation applies only for the default and the 's' options
226
228{
230
231 // create extra profile data structure (bin entries/ y^2 and sum of weight square)
233
234 fYmin = ymin;
235 fYmax = ymax;
237 fTsumwy = fTsumwy2 = 0;
238
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Copy constructor.
243
245{
246 profile.TProfile::Copy(*this);
247}
248
250{
251 if (this != &profile)
252 profile.TProfile::Copy(*this);
253 return *this;
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Performs the operation: this = this + c1*f1
258
260{
261 Error("Add","Function not implemented for TProfile");
262 return kFALSE;
263}
264
265
266////////////////////////////////////////////////////////////////////////////////
267/// Performs the operation: this = this + c1*h1
268
270{
271 if (!h1) {
272 Error("Add","Attempt to add a non-existing profile");
273 return kFALSE;
274 }
276 Error("Add","Attempt to add a non-profile object");
277 return kFALSE;
278 }
279
280 return TProfileHelper::Add(this, this, h1, 1, c1);
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Replace contents of this profile by the addition of h1 and h2.
285///
286/// `this = c1*h1 + c2*h2`
287///
288/// c1 and c2 are considered as weights applied to the two summed profiles.
289/// The operation acts therefore like merging the two profiles with a weight c1 and c2
290
292{
293 if (!h1 || !h2) {
294 Error("Add","Attempt to add a non-existing profile");
295 return kFALSE;
296 }
298 Error("Add","Attempt to add a non-profile object");
299 return kFALSE;
300 }
301 if (!h2->InheritsFrom(TProfile::Class())) {
302 Error("Add","Attempt to add a non-profile object");
303 return kFALSE;
304 }
305 Bool_t ret = TProfileHelper::Add(this, h1, h2, c1, c2);
306 if (c1 < 0 || c2 < 0)
307 ResetStats();
308 return ret;
309}
310
311
312////////////////////////////////////////////////////////////////////////////////
313/// Static function to set the fgApproximate flag.
314///
315///When the flag is true, the function GetBinError
316/// will approximate the bin error with the average profile error on all bins
317/// in the following situation only
318///
319/// - the number of bins in the profile is less than 1002
320/// - the bin number of entries is small ( <5)
321/// - the estimated bin error is extremely small compared to the bin content
322/// (see TProfile::GetBinError)
323
325{
326 fgApproximate = approx;
327}
328
329////////////////////////////////////////////////////////////////////////////////
330/// Fill histogram with all entries in the buffer.
331///
332/// - action = -1 histogram is reset and refilled from the buffer (called by THistPainter::Paint)
333/// - action = 0 histogram is filled from the buffer
334/// - action = 1 histogram is filled and buffer is deleted
335/// The buffer is automatically deleted when the number of entries
336/// in the buffer is greater than the number of entries in the histogram
337
339{
340 // do we need to compute the bin size?
341 if (!fBuffer) return 0;
342 Int_t nbentries = (Int_t)fBuffer[0];
343 if (!nbentries) return 0;
344 Double_t *buffer = fBuffer;
345 if (nbentries < 0) {
346 if (action == 0) return 0;
347 nbentries = -nbentries;
348 fBuffer=nullptr;
349 Reset("ICES"); // reset without deleting the functions
350 fBuffer = buffer;
351 }
352 if (CanExtendAllAxes() || fXaxis.GetXmax() <= fXaxis.GetXmin()) {
353 //find min, max of entries in buffer
354 Double_t xmin = fBuffer[2];
356 for (Int_t i=1;i<nbentries;i++) {
357 Double_t x = fBuffer[3*i+2];
358 if (x < xmin) xmin = x;
359 if (x > xmax) xmax = x;
360 }
361 if (fXaxis.GetXmax() <= fXaxis.GetXmin()) {
363 } else {
364 fBuffer = nullptr;
365 Int_t keep = fBufferSize; fBufferSize = 0;
368 fBuffer = buffer;
369 fBufferSize = keep;
370 }
371 }
372
373 fBuffer = nullptr;
374
375 for (Int_t i=0;i<nbentries;i++) {
376 Fill(buffer[3*i+2],buffer[3*i+3],buffer[3*i+1]);
377 }
378 fBuffer = buffer;
379
380 if (action > 0) { delete [] fBuffer; fBuffer = nullptr; fBufferSize = 0;}
381 else {
382 if (nbentries == (Int_t)fEntries) fBuffer[0] = -nbentries;
383 else fBuffer[0] = 0;
384 }
385 return nbentries;
386}
387
388////////////////////////////////////////////////////////////////////////////////
389/// accumulate arguments in buffer. When buffer is full, empty the buffer.
390///
391/// - fBuffer[0] = number of entries in buffer
392/// - fBuffer[1] = w of first entry
393/// - fBuffer[2] = x of first entry
394/// - fBuffer[3] = y of first entry
395
397{
398 if (!fBuffer) return -2;
399 Int_t nbentries = (Int_t)fBuffer[0];
400 if (nbentries < 0) {
401 nbentries = -nbentries;
402 fBuffer[0] = nbentries;
403 if (fEntries > 0) {
404 Double_t *buffer = fBuffer; fBuffer=nullptr;
405 Reset("ICES"); // reset without deleting the functions
406 fBuffer = buffer;
407 }
408 }
409 if (3*nbentries+3 >= fBufferSize) {
410 BufferEmpty(1);
411 return Fill(x,y,w);
412 }
413 fBuffer[3*nbentries+1] = w;
414 fBuffer[3*nbentries+2] = x;
415 fBuffer[3*nbentries+3] = y;
416 fBuffer[0] += 1;
417 return -2;
418}
419
420////////////////////////////////////////////////////////////////////////////////
421/// Copy a Profile histogram to a new profile histogram.
422
423void TProfile::Copy(TObject &obj) const
424{
425 try {
426 TProfile &pobj = dynamic_cast<TProfile&>(obj);
427 TH1D::Copy(pobj);
430 for (int bin=0;bin<fNcells;bin++) {
431 pobj.fArray[bin] = fArray[bin];
432 pobj.fSumw2.fArray[bin] = fSumw2.fArray[bin];
433 }
434
435 pobj.fYmin = fYmin;
436 pobj.fYmax = fYmax;
437 pobj.fScaling = fScaling;
438 pobj.fErrorMode = fErrorMode;
439 pobj.fTsumwy = fTsumwy;
440 pobj.fTsumwy2 = fTsumwy2;
441
442 } catch(...) {
443 Fatal("Copy","Cannot copy a TProfile in a %s",obj.IsA()->GetName());
444 }
445
446}
447
448////////////////////////////////////////////////////////////////////////////////
449/// Performs the operation: `this = this/(c1*f1)`.
450///
451/// This function is not implemented for the TProfile
452
454{
455 Error("Divide","Function not implemented for TProfile");
456 return kFALSE;
457}
458
459////////////////////////////////////////////////////////////////////////////////
460/// Divide this profile by h1.
461///
462/// `this = this/h1`
463///
464/// This function accepts to divide a TProfile by a histogram
465///
466/// The function return kFALSE if the divide operation failed
467
469{
470 if (!h1) {
471 Error("Divide","Attempt to divide a non-existing profile");
472 return kFALSE;
473 }
474 if (!h1->InheritsFrom(TH1::Class())) {
475 Error("Divide","Attempt to divide by a non-profile or non-histogram object");
476 return kFALSE;
477 }
478 TProfile *p1 = (TProfile*)h1;
479
480 // delete buffer if it is there since it will become invalid
481 if (fBuffer) BufferEmpty(1);
482
483
484 Int_t nbinsx = GetNbinsX();
485 //- Check profile compatibility
486 if (nbinsx != p1->GetNbinsX()) {
487 Error("Divide","Attempt to divide profiles with different number of bins");
488 return kFALSE;
489 }
490
491 //- Reset statistics
493
494 //- Loop on bins (including underflows/overflows)
495 Int_t bin;
496 Double_t *cu1=nullptr, *er1=nullptr, *en1=nullptr;
497 Double_t e0,e1,c12;
499 cu1 = p1->GetW();
500 er1 = p1->GetW2();
501 en1 = p1->GetB();
502 }
503 Double_t c0,c1,w,z,x;
504 for (bin=0;bin<=nbinsx+1;bin++) {
505 c0 = fArray[bin];
506 if (cu1) c1 = cu1[bin];
507 else c1 = h1->GetBinContent(bin);
508 if (c1) w = c0/c1;
509 else w = 0;
510 fArray[bin] = w;
511 z = TMath::Abs(w);
512 x = fXaxis.GetBinCenter(bin);
513 fEntries++;
514 fTsumw += z;
515 fTsumw2 += z*z;
516 fTsumwx += z*x;
517 fTsumwx2 += z*x*x;
518 fTsumwy += z*c1;
519 fTsumwx2 += z*c1*c1;
520 e0 = fSumw2.fArray[bin];
521 if (er1) e1 = er1[bin];
522 else {e1 = h1->GetBinError(bin); e1*=e1;}
523 c12= c1*c1;
524 if (!c1) fSumw2.fArray[bin] = 0;
525 else fSumw2.fArray[bin] = (e0*c1*c1 + e1*c0*c0)/(c12*c12);
526 if (!en1) continue;
527 if (!en1[bin]) fBinEntries.fArray[bin] = 0;
528 else fBinEntries.fArray[bin] /= en1[bin];
529 }
530 // maintaining the correct sum of weights square is not supported when dividing
531 // bin error resulting from division of profile needs to be checked
532 if (fBinSumw2.fN) {
533 Warning("Divide","Cannot preserve during the division of profiles the sum of bin weight square");
534 fBinSumw2 = TArrayD();
535 }
536
537 return kTRUE;
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Replace contents of this profile by the division of h1 by h2.
542///
543/// `this = c1*h1/(c2*h2)`
544///
545/// The function return kFALSE if the divide operation failed
546
548{
549 TString opt = option;
550 opt.ToLower();
551 Bool_t binomial = kFALSE;
552 if (opt.Contains("b")) binomial = kTRUE;
553 if (!h1 || !h2) {
554 Error("Divide","Attempt to divide a non-existing profile");
555 return kFALSE;
556 }
558 Error("Divide","Attempt to divide a non-profile object");
559 return kFALSE;
560 }
561 TProfile *p1 = (TProfile*)h1;
562 if (!h2->InheritsFrom(TProfile::Class())) {
563 Error("Divide","Attempt to divide by a non-profile object");
564 return kFALSE;
565 }
566 TProfile *p2 = (TProfile*)h2;
567
568 // delete buffer if it is there since it will become invalid
569 if (fBuffer) BufferEmpty(1);
570
571 Int_t nbinsx = GetNbinsX();
572 //- Check histogram compatibility
573 if (nbinsx != p1->GetNbinsX() || nbinsx != p2->GetNbinsX()) {
574 Error("Divide","Attempt to divide profiles with different number of bins");
575 return kFALSE;
576 }
577 if (!c2) {
578 Error("Divide","Coefficient of dividing profile cannot be zero");
579 return kFALSE;
580 }
581
582 //THE ALGORITHM COMPUTING THE ERRORS IS WRONG. HELP REQUIRED
583 printf("WARNING!!: The algorithm in TProfile::Divide computing the errors is not accurate\n");
584 printf(" Instead of Divide(TProfile *h1, TProfile *h2), do:\n");
585 printf(" TH1D *p1 = h1->ProjectionX();\n");
586 printf(" TH1D *p2 = h2->ProjectionX();\n");
587 printf(" p1->Divide(p2);\n");
588
589 //- Reset statistics
591
592 //- Loop on bins (including underflows/overflows)
593 Int_t bin;
594 Double_t *cu1 = p1->GetW();
595 Double_t *cu2 = p2->GetW();
596 Double_t *er1 = p1->GetW2();
597 Double_t *er2 = p2->GetW2();
598 Double_t *en1 = p1->GetB();
599 Double_t *en2 = p2->GetB();
600 Double_t b1,b2,w,z,x,ac1,ac2;
601 //d1 = c1*c1;
602 //d2 = c2*c2;
603 ac1 = TMath::Abs(c1);
604 ac2 = TMath::Abs(c2);
605 for (bin=0;bin<=nbinsx+1;bin++) {
606 b1 = cu1[bin];
607 b2 = cu2[bin];
608 if (b2) w = c1*b1/(c2*b2);
609 else w = 0;
610 fArray[bin] = w;
611 z = TMath::Abs(w);
612 x = fXaxis.GetBinCenter(bin);
613 fEntries++;
614 fTsumw += z;
615 fTsumw2 += z*z;
616 fTsumwx += z*x;
617 fTsumwx2 += z*x*x;
618 //fTsumwy += z*x;
619 //fTsumwy2 += z*x*x;
620 Double_t e1 = er1[bin];
621 Double_t e2 = er2[bin];
622 //Double_t b22= b2*b2*d2;
623 Double_t b22= b2*b2*TMath::Abs(c2);
624 if (!b2) fSumw2.fArray[bin] = 0;
625 else {
626 if (binomial) {
627 fSumw2.fArray[bin] = TMath::Abs(w*(1-w)/b2);
628 } else {
629 //fSumw2.fArray[bin] = d1*d2*(e1*b2*b2 + e2*b1*b1)/(b22*b22);
630 fSumw2.fArray[bin] = ac1*ac2*(e1*b2*b2 + e2*b1*b1)/(b22*b22);
631 }
632 }
633 if (en2[bin]) fBinEntries.fArray[bin] = en1[bin]/en2[bin];
634 else fBinEntries.fArray[bin] = 0;
635 }
636
637 // maintaining the correct sum of weights square is not supported when dividing
638 // bin error resulting from division of profile needs to be checked
639 if (fBinSumw2.fN) {
640 Warning("Divide","Cannot preserve during the division of profiles the sum of bin weight square");
641 fBinSumw2 = TArrayD();
642 }
643
644 return kTRUE;
645}
646
647////////////////////////////////////////////////////////////////////////////////
648/// Fill a Profile histogram (no weights).
649
651{
652 if (fBuffer) return BufferFill(x,y,1);
653
654 Int_t bin;
655 if (fYmin != fYmax) {
656 if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
657 }
658
659 fEntries++;
660 bin =fXaxis.FindBin(x);
661 AddBinContent(bin, y);
662 fSumw2.fArray[bin] += (Double_t)y*y;
663 fBinEntries.fArray[bin] += 1;
664 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += 1;
665 if (bin == 0 || bin > fXaxis.GetNbins()) {
666 if (!GetStatOverflowsBehaviour()) return -1;
667 }
668 fTsumw++;
669 fTsumw2++;
670 fTsumwx += x;
671 fTsumwx2 += x*x;
672 fTsumwy += y;
673 fTsumwy2 += y*y;
674 return bin;
675}
676
677////////////////////////////////////////////////////////////////////////////////
678/// Fill a Profile histogram (no weights).
679
680Int_t TProfile::Fill(const char *namex, Double_t y)
681{
682 Int_t bin;
683 if (fYmin != fYmax) {
684 if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
685 }
686
687 fEntries++;
688 bin =fXaxis.FindBin(namex);
689 AddBinContent(bin, y);
690 fSumw2.fArray[bin] += (Double_t)y*y;
691 fBinEntries.fArray[bin] += 1;
692 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += 1;
693 if (bin == 0 || bin > fXaxis.GetNbins()) {
694 if (!GetStatOverflowsBehaviour()) return -1;
695 }
696 fTsumw++;
697 fTsumw2++;
698 fTsumwy += y;
699 fTsumwy2 += y * y;
700 if (!fXaxis.CanExtend() || !fXaxis.IsAlphanumeric()) {
702 fTsumwx += x;
703 fTsumwx2 += x * x;
704 }
705 return bin;
706}
707////////////////////////////////////////////////////////////////////////////////
708/// Fill a Profile histogram with weights.
709
711{
712 if (fBuffer) return BufferFill(x,y,w);
713
714 Int_t bin;
715 if (fYmin != fYmax) {
716 if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
717 }
718
719 Double_t u= w;
720 fEntries++;
721 bin =fXaxis.FindBin(x);
722 AddBinContent(bin, u*y);
723 fSumw2.fArray[bin] += u*y*y;
724 if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
725 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
726 fBinEntries.fArray[bin] += u;
727 if (bin == 0 || bin > fXaxis.GetNbins()) {
728 if (!GetStatOverflowsBehaviour()) return -1;
729 }
730 fTsumw += u;
731 fTsumw2 += u*u;
732 fTsumwx += u*x;
733 fTsumwx2 += u*x*x;
734 fTsumwy += u*y;
735 fTsumwy2 += u*y*y;
736 return bin;
737}
738
739////////////////////////////////////////////////////////////////////////////////
740/// Fill a Profile histogram with weights.
741
743{
744 Int_t bin;
745
746 if (fYmin != fYmax) {
747 if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
748 }
749
750 Double_t u= w; // (w > 0 ? w : -w);
751 fEntries++;
752 bin =fXaxis.FindBin(namex);
753 AddBinContent(bin, u*y);
754 fSumw2.fArray[bin] += u*y*y;
755 if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
756 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
757 fBinEntries.fArray[bin] += u;
758 if (bin == 0 || bin > fXaxis.GetNbins()) {
759 if (!GetStatOverflowsBehaviour()) return -1;
760 }
761 fTsumw += u;
762 fTsumw2 += u*u;
763 if (!fXaxis.CanExtend() || !fXaxis.IsAlphanumeric()) {
765 fTsumwx += u*x;
766 fTsumwx2 += u*x*x;
767 }
768 fTsumwy += u*y;
769 fTsumwy2 += u*y*y;
770 return bin;
771}
772
773////////////////////////////////////////////////////////////////////////////////
774/// Fill a Profile histogram with weights.
775
776void TProfile::FillN(Int_t ntimes, const Double_t *x, const Double_t *y, const Double_t *w, Int_t stride)
777{
778 Int_t bin,i;
779 ntimes *= stride;
780 Int_t ifirst = 0;
781 //If a buffer is activated, fill buffer
782 // (note that this function must not be called from TH2::BufferEmpty)
783 if (fBuffer) {
784 for (i=0;i<ntimes;i+=stride) {
785 if (!fBuffer) break; // buffer can be deleted in BufferFill when is empty
786 if (w) BufferFill(x[i],y[i],w[i]);
787 else BufferFill(x[i], y[i], 1.);
788 }
789 // fill the remaining entries if the buffer has been deleted
790 if (i < ntimes && fBuffer==nullptr)
791 ifirst = i; // start from i
792 else
793 return;
794 }
795
796 for (i=ifirst;i<ntimes;i+=stride) {
797 if (fYmin != fYmax) {
798 if (y[i] <fYmin || y[i]> fYmax || TMath::IsNaN(y[i])) continue;
799 }
800
801 Double_t u = (w) ? w[i] : 1; // (w[i] > 0 ? w[i] : -w[i]);
802 fEntries++;
803 bin =fXaxis.FindBin(x[i]);
804 AddBinContent(bin, u*y[i]);
805 fSumw2.fArray[bin] += u*y[i]*y[i];
806 if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
807 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
808 fBinEntries.fArray[bin] += u;
809 if (bin == 0 || bin > fXaxis.GetNbins()) {
810 if (!GetStatOverflowsBehaviour()) continue;
811 }
812 fTsumw += u;
813 fTsumw2 += u*u;
814 fTsumwx += u*x[i];
815 fTsumwx2 += u*x[i]*x[i];
816 fTsumwy += u*y[i];
817 fTsumwy2 += u*y[i]*y[i];
818 }
819}
820
821////////////////////////////////////////////////////////////////////////////////
822/// Return bin content of a Profile histogram.
823
825{
826 if (fBuffer) ((TProfile*)this)->BufferEmpty();
827
828 if (bin < 0 || bin >= fNcells) return 0;
829 if (fBinEntries.fArray[bin] == 0) return 0;
830 if (!fArray) return 0;
831 return fArray[bin]/fBinEntries.fArray[bin];
832}
833
834////////////////////////////////////////////////////////////////////////////////
835/// Return bin entries of a Profile histogram.
836
838{
839 if (fBuffer) ((TProfile*)this)->BufferEmpty();
840
841 if (bin < 0 || bin >= fNcells) return 0;
842 return fBinEntries.fArray[bin];
843}
844
845////////////////////////////////////////////////////////////////////////////////
846/// Return bin effective entries for a weighted filled Profile histogram.
847/// In case of an unweighted profile, it is equivalent to the number of entries per bin
848/// The effective entries is defined as the square of the sum of the weights divided by the
849/// sum of the weights square.
850/// TProfile::Sumw2() must be called before filling the profile with weights.
851/// Only by calling this method the sum of the square of the weights per bin is stored.
852
854{
856}
857
858////////////////////////////////////////////////////////////////////////////////
859/// Return bin error of a Profile histogram
860///
861/// Computing errors: A moving field
862///
863/// The computation of errors for a TProfile has evolved with the versions
864/// of ROOT. The difficulty is in computing errors for bins with low statistics.
865///
866/// - prior to version 3.00, we had no special treatment of low statistic bins.
867/// As a result, these bins had huge errors. The reason is that the
868/// expression eprim2 is very close to 0 (rounding problems) or 0.
869/// - in version 3.00 (18 Dec 2000), the algorithm is protected for values of
870/// eprim2 very small and the bin errors set to the average bin errors, following
871/// recommendations from a group of users.
872/// - in version 3.01 (19 Apr 2001), it is realized that the algorithm above
873/// should be applied only to low statistic bins.
874/// - in version 3.02 (26 Sep 2001), the same group of users recommend instead
875/// to take two times the average error on all bins for these low
876/// statistics bins giving a very small value for eprim2.
877/// - in version 3.04 (Nov 2002), the algorithm is modified/protected for the case
878/// when a TProfile is projected (ProjectionX). The previous algorithm
879/// generated a N^2 problem when projecting a TProfile with a large number of
880/// bins (eg 100000).
881/// - in version 3.05/06, a new static function TProfile::Approximate
882/// is introduced to enable or disable (default) the approximation.
883///
884/// Ideas for improvements of this algorithm are welcome. No suggestions
885/// received since our call for advice to roottalk in Jul 2002.
886/// see for instance: http://root.cern/root/roottalk/roottalk02/2916.html
887
889{
890 return TProfileHelper::GetBinError((TProfile*)this, bin);
891}
892
893////////////////////////////////////////////////////////////////////////////////
894/// Return option to compute profile errors
895
897{
898 if (fErrorMode == kERRORSPREAD) return "s";
899 if (fErrorMode == kERRORSPREADI) return "i";
900 if (fErrorMode == kERRORSPREADG) return "g";
901 return "";
902}
903
904////////////////////////////////////////////////////////////////////////////////
905/// fill the array stats from the contents of this profile.
906///
907/// The array stats must be correctly dimensioned in the calling program.
908///
909/// - stats[0] = sumw
910/// - stats[1] = sumw2
911/// - stats[2] = sumwx
912/// - stats[3] = sumwx2
913/// - stats[4] = sumwy
914/// - stats[5] = sumwy2
915///
916/// If no axis-subrange is specified (via TAxis::SetRange), the array stats
917/// is simply a copy of the statistics quantities computed at filling time.
918/// If a sub-range is specified, the function recomputes these quantities
919/// from the bin contents in the current axis range.
920
921void TProfile::GetStats(Double_t *stats) const
922{
923 if (fBuffer) ((TProfile*)this)->BufferEmpty();
924
925 // Loop on bins
926 Int_t bin, binx;
927 // identify the case of labels with extension of axis range
928 // in this case the statistics in x does not make any sense
929 Bool_t labelHist = ((const_cast<TAxis&>(fXaxis)).GetLabels() && fXaxis.CanExtend() );
930
931 if ( (fTsumw == 0 /* && fEntries > 0 */) || fXaxis.TestBit(TAxis::kAxisRange) ) {
932 for (bin=0;bin<6;bin++) stats[bin] = 0;
933 if (!fBinEntries.fArray) return;
934 Int_t firstBinX = fXaxis.GetFirst();
935 Int_t lastBinX = fXaxis.GetLast();
936 // include underflow/overflow if TH1::StatOverflows(kTRUE) in case no range is set on the axis
938 if (firstBinX == 1) firstBinX = 0;
939 if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1;
940 }
941 for (binx = firstBinX; binx <= lastBinX; binx++) {
943 Double_t w2 = (fBinSumw2.fN ? fBinSumw2.fArray[binx] : w);
944 Double_t x = (!labelHist) ? fXaxis.GetBinCenter(binx) : 0;
945 stats[0] += w;
946 stats[1] += w2;
947 stats[2] += w*x;
948 stats[3] += w*x*x;
949 stats[4] += fArray[binx];
950 stats[5] += fSumw2.fArray[binx];
951 }
952 } else {
953 if (fTsumwy == 0 && fTsumwy2 == 0) {
954 //this case may happen when processing TProfiles with version <=3
955 TProfile *p = (TProfile*)this; // cheating with const
956 for (binx=fXaxis.GetFirst();binx<=fXaxis.GetLast();binx++) {
957 p->fTsumwy += fArray[binx];
958 p->fTsumwy2 += fSumw2.fArray[binx];
959 }
960 }
961 stats[0] = fTsumw;
962 stats[1] = fTsumw2;
963 stats[2] = fTsumwx;
964 stats[3] = fTsumwx2;
965 stats[4] = fTsumwy;
966 stats[5] = fTsumwy2;
967 }
968}
969
970////////////////////////////////////////////////////////////////////////////////
971/// Reduce the number of bins for this axis to the number of bins having a label.
972
974{
976}
977
978////////////////////////////////////////////////////////////////////////////////
979/// Double the number of bins for axis.
980/// Refill histogram
981/// This function is called by TAxis::FindBin(const char *label)
982
984{
985 TProfileHelper::LabelsInflate(this, options);
986}
987
988////////////////////////////////////////////////////////////////////////////////
989/// Set option(s) to draw axis with labels.
990///
991/// option might have the following values:
992///
993/// - "a" sort by alphabetic order
994/// - ">" sort by decreasing values
995/// - "<" sort by increasing values
996/// - "h" draw labels horizontal
997/// - "v" draw labels vertical
998/// - "u" draw labels up (end of label right adjusted)
999/// - "d" draw labels down (start of label left adjusted)
1000
1002{
1003 THashList *labels = fXaxis.GetLabels();
1004 if (!labels) {
1005 Warning("LabelsOption","Cannot sort. No labels");
1006 return;
1007 }
1008 TString opt = option;
1009 opt.ToLower();
1010 if (opt.Contains("h")) {
1015 }
1016 if (opt.Contains("v")) {
1021 }
1022 if (opt.Contains("u")) {
1027 }
1028 if (opt.Contains("d")) {
1033 }
1034 Int_t sort = -1;
1035 if (opt.Contains("a")) sort = 0;
1036 if (opt.Contains(">")) sort = 1;
1037 if (opt.Contains("<")) sort = 2;
1038 if (sort < 0) return;
1039
1040 // support only cases when first n bins have labels
1041 Int_t n = labels->GetSize();
1042 TAxis *axis = &fXaxis;
1043 if (n != axis->GetNbins()) {
1044 // check if labels are all consecutive and starts from the first bin
1045 // in that case the current code will work fine
1046 Int_t firstLabelBin = axis->GetNbins() + 1;
1047 Int_t lastLabelBin = -1;
1048 for (Int_t i = 0; i < n; ++i) {
1049 Int_t bin = labels->At(i)->GetUniqueID();
1050 if (bin < firstLabelBin)
1051 firstLabelBin = bin;
1052 if (bin > lastLabelBin)
1053 lastLabelBin = bin;
1054 }
1055 if (firstLabelBin != 1 || lastLabelBin - firstLabelBin + 1 != n) {
1056 Error("LabelsOption",
1057 "%s of TProfile %s contains bins without labels. Sorting will not work correctly - return",
1058 axis->GetName(), GetName());
1059 return;
1060 }
1061 // case where label bins are consecutive starting from first bin will work
1062 Warning(
1063 "LabelsOption",
1064 "axis %s of TProfile %s has extra following bins without labels. Sorting will work only for first label bins",
1065 axis->GetName(), GetName());
1066 }
1067 std::vector<Int_t> a(n);
1068 Int_t i;
1069 std::vector<Double_t> cont(n);
1070 std::vector<Double_t> sumw(n);
1071 std::vector<Double_t> errors(n);
1072 std::vector<Double_t> ent(n);
1073 std::vector<Double_t> binsw2;
1074 if (fBinSumw2.fN) binsw2.resize(n);
1075
1076 // delete buffer if it is there since bins will be reordered.
1077 if (fBuffer)
1078 BufferEmpty(1);
1079
1080 // make a labelold list but ordered with bins
1081 // (re-ordered original label list)
1082 std::vector<TObject *> labold(n);
1083 for (i = 0; i < n; i++)
1084 labold[i] = nullptr;
1085 TIter nextold(labels);
1086 TObject *obj;
1087 while ((obj=nextold())) {
1088 Int_t bin = obj->GetUniqueID();
1089 R__ASSERT(bin <= n);
1090 labold[bin - 1] = obj;
1091 }
1092 // order now labold according to bin content
1093
1094 labels->Clear();
1095 if (sort > 0) {
1096 //---sort by values of bins
1097 for (i=1;i<=n;i++) {
1098 a[i-1] = i-1;
1099 sumw[i-1] = fArray[i];
1100 errors[i-1] = fSumw2.fArray[i];
1101 ent[i-1] = fBinEntries.fArray[i];
1102 if (fBinSumw2.fN) binsw2[i - 1] = fBinSumw2.fArray[i];
1103 if (fBinEntries.fArray[i] == 0) cont[i-1] = 0;
1104 else cont[i-1] = fArray[i]/fBinEntries.fArray[i];
1105 }
1106 if (sort ==1)
1107 TMath::Sort(n,cont.data(),a.data(),kTRUE); //sort by decreasing values
1108 else
1109 TMath::Sort(n,cont.data(),a.data(),kFALSE); //sort by increasing values
1110 for (i=1;i<=n;i++) {
1111 fArray[i] = sumw[a[i-1]];
1112 fSumw2.fArray[i] = errors[a[i-1]];
1113 fBinEntries.fArray[i] = ent[a[i-1]];
1114 if (fBinSumw2.fN)
1115 fBinSumw2.fArray[i] = binsw2[a[i-1]];
1116 }
1117 for (i=0 ;i < n; i++) {
1118 obj = labold[a[i]];
1119 labels->Add(obj);
1120 obj->SetUniqueID(i+1);
1121 }
1122 } else {
1123
1124 //---alphabetic sort
1125 // sort labels using vector of strings and TMath::Sort
1126 // I need to array because labels order in list is not necessary that of the bins
1127 std::vector<std::string> vecLabels(n);
1128 for (i = 0; i < n; i++) {
1129 vecLabels[i] = labold[i]->GetName();
1130 a[i] = i;
1131 sumw[i] = fArray[i+1];
1132 errors[i] = fSumw2.fArray[i+1];
1133 ent[i] = fBinEntries.fArray[i+1];
1134 if (fBinSumw2.fN)
1135 binsw2[i] = fBinSumw2.fArray[i+1];
1136 }
1137 // sort in ascending order for strings
1138 TMath::Sort(n, vecLabels.data(), a.data(), kFALSE);
1139 // set the new labels
1140 for (i = 0; i < n; i++) {
1141 TObject *labelObj = labold[a[i]];
1142 labels->Add(labelObj);
1143 // set the corresponding bin. NB bin starts from 1
1144 labelObj->SetUniqueID(i + 1);
1145 if (gDebug)
1146 std::cout << "bin " << i + 1 << " setting new labels for axis " << labold.at(a[i])->GetName() << " from "
1147 << a[i] << std::endl;
1148 }
1149
1150 for (i=0; i < n; i++) {
1151 fArray[i+1] = sumw[a[i]];
1152 fSumw2.fArray[i+1] = errors[a[i]];
1153 fBinEntries.fArray[i+1] = ent[a[i]];
1154 if (fBinSumw2.fN)
1155 fBinSumw2.fArray[i+1] = binsw2[a[i]];
1156 }
1157 }
1158 // need to set to zero the statistics if axis has been sorted
1159 // see for example TH3::PutStats for definition of s vector
1160 bool labelsAreSorted = kFALSE;
1161 for (i = 0; i < n; ++i) {
1162 if (a[i] != i) {
1163 labelsAreSorted = kTRUE;
1164 break;
1165 }
1166 }
1167 if (labelsAreSorted) {
1168 double s[TH1::kNstat];
1169 GetStats(s);
1170 // if (iaxis == 1) {
1171 s[2] = 0; // fTsumwx
1172 s[3] = 0; // fTsumwx2
1173 PutStats(s);
1174 }
1175}
1176
1177////////////////////////////////////////////////////////////////////////////////
1178///Merge all histograms in the collection in this histogram.
1179///
1180/// This function computes the min/max for the x axis,
1181/// compute a new number of bins, if necessary,
1182/// add bin contents, errors and statistics.
1183/// If overflows are present and limits are different the function will fail.
1184/// The function returns the total number of entries in the result histogram
1185/// if the merge is successful, -1 otherwise.
1186///
1187/// IMPORTANT remark. The axis x may have different number
1188/// of bins and different limits, BUT the largest bin width must be
1189/// a multiple of the smallest bin width and the upper limit must also
1190/// be a multiple of the bin width.
1191
1193{
1194 return TProfileHelper::Merge(this, li);
1195}
1196
1197////////////////////////////////////////////////////////////////////////////////
1198/// Performs the operation: this = this*c1*f1
1199///
1200/// The function return kFALSE if the Multiply operation failed
1201
1203{
1204
1205 if (!f1) {
1206 Error("Multiply","Attempt to multiply by a null function");
1207 return kFALSE;
1208 }
1209
1210 Int_t nbinsx = GetNbinsX();
1211
1212 //- Add statistics
1213 Double_t xx[1], cf1, ac1 = TMath::Abs(c1);
1214 Double_t s1[10];
1215 Int_t i;
1216 for (i=0;i<10;i++) {s1[i] = 0;}
1217 PutStats(s1);
1218
1219 SetMinimum();
1220 SetMaximum();
1221
1222 //- Loop on bins (including underflows/overflows)
1223 Int_t bin;
1224 for (bin=0;bin<=nbinsx+1;bin++) {
1225 xx[0] = fXaxis.GetBinCenter(bin);
1226 if (!f1->IsInside(xx)) continue;
1228 cf1 = f1->EvalPar(xx);
1229 if (TF1::RejectedPoint()) continue;
1230 fArray[bin] *= c1*cf1;
1231 //see http://savannah.cern.ch/bugs/?func=detailitem&item_id=14851
1232 //fSumw2.fArray[bin] *= c1*c1*cf1*cf1;
1233 fSumw2.fArray[bin] *= ac1*cf1*cf1;
1234 //fBinEntries.fArray[bin] *= ac1*TMath::Abs(cf1);
1235 }
1236 return kTRUE;
1237}
1238
1239////////////////////////////////////////////////////////////////////////////////
1240/// Multiply this profile by h1.
1241///
1242/// `this = this*h1`
1243
1245{
1246 Error("Multiply","Multiplication of profile histograms not implemented");
1247 return kFALSE;
1248}
1249
1250
1251////////////////////////////////////////////////////////////////////////////////
1252/// Replace contents of this profile by multiplication of h1 by h2.
1253///
1254/// `this = (c1*h1)*(c2*h2)`
1255
1257{
1258 Error("Multiply","Multiplication of profile histograms not implemented");
1259 return kFALSE;
1260}
1261
1262////////////////////////////////////////////////////////////////////////////////
1263/// Project this profile into a 1-D histogram along X
1264///
1265/// The projection is always of the type TH1D.
1266///
1267/// - if option "E" is specified the errors of the projected histogram are computed and set
1268/// to be equal to the errors of the profile.
1269/// Option "E" is defined as the default one in the header file.
1270/// - if option "" is specified the histogram errors are simply the sqrt of its content
1271/// - if option "B" is specified, the content of bin of the returned histogram
1272/// will be equal to the GetBinEntries(bin) of the profile,
1273/// otherwise (default) it will be equal to GetBinContent(bin)
1274/// - if option "C=E" the bin contents of the projection are set to the
1275/// bin errors of the profile
1276/// - if option "W" is specified the bin content of the projected histogram is set to the
1277/// product of the bin content of the profile and the entries.
1278/// With this option the returned histogram will be equivalent to the one obtained by
1279/// filling directly a TH1D using the 2-nd value as a weight.
1280/// This makes sense only for profile filled with weights =1. If not, the error of the
1281/// projected histogram obtained with this option will not be correct.
1282
1284{
1285
1286 TString opt = option;
1287 opt.ToLower();
1288 Int_t nx = fXaxis.GetNbins();
1289
1290 // Create the projection histogram
1291 TString pname = name;
1292 if (pname == "_px") {
1293 pname = GetName();
1294 pname.Append("_px");
1295 }
1296 TH1D *h1;
1297 const TArrayD *bins = fXaxis.GetXbins();
1298 if (bins->fN == 0) {
1299 h1 = new TH1D(pname,GetTitle(),nx,fXaxis.GetXmin(),fXaxis.GetXmax());
1300 } else {
1301 h1 = new TH1D(pname,GetTitle(),nx,bins->fArray);
1302 }
1303 Bool_t computeErrors = kFALSE;
1304 Bool_t cequalErrors = kFALSE;
1305 Bool_t binEntries = kFALSE;
1306 Bool_t binWeight = kFALSE;
1307 if (opt.Contains("b")) binEntries = kTRUE;
1308 if (opt.Contains("e")) computeErrors = kTRUE;
1309 if (opt.Contains("w")) binWeight = kTRUE;
1310 if (opt.Contains("c=e")) {cequalErrors = kTRUE; computeErrors=kFALSE;}
1311 if (computeErrors || binWeight || (binEntries && fBinSumw2.fN) ) h1->Sumw2();
1312
1313 // Fill the projected histogram
1314 Double_t cont;
1315 for (Int_t bin =0;bin<=nx+1;bin++) {
1316
1317 if (binEntries) cont = GetBinEntries(bin);
1318 else if (cequalErrors) cont = GetBinError(bin);
1319 else if (binWeight) cont = fArray[bin]; // bin content * bin entries
1320 else cont = GetBinContent(bin); // default case
1321
1322 h1->SetBinContent(bin ,cont);
1323
1324 // if option E projected histogram errors are same as profile
1325 if (computeErrors ) h1->SetBinError(bin , GetBinError(bin) );
1326 // in case of option W bin error is deduced from bin sum of z**2 values of profile
1327 // this is correct only if the profile is filled with weights =1
1328 if (binWeight) h1->GetSumw2()->fArray[bin] = fSumw2.fArray[bin];
1329 // in case of bin entries and profile is weighted, we need to set also the bin error
1330 if (binEntries && fBinSumw2.fN ) {
1331 R__ASSERT( h1->GetSumw2() );
1332 h1->GetSumw2()->fArray[bin] = fBinSumw2.fArray[bin];
1333 }
1334
1335 }
1336
1337 // Copy the axis attributes and the axis labels if needed.
1338 h1->GetXaxis()->ImportAttributes(this->GetXaxis());
1339 h1->GetYaxis()->ImportAttributes(this->GetYaxis());
1340 THashList* labels=this->GetXaxis()->GetLabels();
1341 if (labels) {
1342 TIter iL(labels);
1343 TObjString* lb;
1344 Int_t i = 1;
1345 while ((lb=(TObjString*)iL())) {
1346 h1->GetXaxis()->SetBinLabel(i,lb->String().Data());
1347 i++;
1348 }
1349 }
1350
1352 return h1;
1353}
1354
1355////////////////////////////////////////////////////////////////////////////////
1356/// Replace current statistics with the values in array stats.
1357
1359{
1360 fTsumw = stats[0];
1361 fTsumw2 = stats[1];
1362 fTsumwx = stats[2];
1363 fTsumwx2 = stats[3];
1364 fTsumwy = stats[4];
1365 fTsumwy2 = stats[5];
1366}
1367
1368////////////////////////////////////////////////////////////////////////////////
1369/// Rebin this profile grouping ngroup bins together.
1370///
1371/// ## case 1 xbins=0
1372/// if newname is not blank a new temporary profile hnew is created.
1373/// else the current profile is modified (default)
1374/// The parameter ngroup indicates how many bins of this have to me merged
1375/// into one bin of hnew
1376/// If the original profile has errors stored (via Sumw2), the resulting
1377/// profile has new errors correctly calculated.
1378///
1379/// examples: if hp is an existing TProfile histogram with 100 bins
1380///
1381/// ~~~ {.cpp}
1382/// hp->Rebin(); //merges two bins in one in hp: previous contents of hp are lost
1383/// hp->Rebin(5); //merges five bins in one in hp
1384/// TProfile *hnew = hp->Rebin(5,"hnew"); // creates a new profile hnew
1385/// //merging 5 bins of hp in one bin
1386/// ~~~
1387///
1388/// NOTE: If ngroup is not an exact divider of the number of bins,
1389/// the top limit of the rebinned profile is changed
1390/// to the upper edge of the bin=newbins*ngroup and the corresponding
1391/// bins are added to the overflow bin.
1392/// Statistics will be recomputed from the new bin contents.
1393///
1394/// ## case 2 xbins!=0
1395/// a new profile is created (you should specify newname).
1396/// The parameter ngroup is the number of variable size bins in the created profile
1397/// The array xbins must contain ngroup+1 elements that represent the low-edge
1398/// of the bins.
1399/// The data of the old bins are added to the new bin which contains the bin center
1400/// of the old bins. It is possible that information from the old binning are attached
1401/// to the under-/overflow bins of the new binning.
1402///
1403/// examples: if hp is an existing TProfile with 100 bins
1404///
1405/// ~~~ {.cpp}
1406/// Double_t xbins[25] = {...} array of low-edges (xbins[25] is the upper edge of last bin
1407/// hp->Rebin(24,"hpnew",xbins); //creates a new variable bin size profile hpnew
1408/// ~~~
1409
1410TH1 *TProfile::Rebin(Int_t ngroup, const char*newname, const Double_t *xbins)
1411{
1412 Int_t nbins = fXaxis.GetNbins();
1415 if ((ngroup <= 0) || (ngroup > nbins)) {
1416 Error("Rebin", "Illegal value of ngroup=%d",ngroup);
1417 return nullptr;
1418 }
1419 if (!newname && xbins) {
1420 Error("Rebin","if xbins is specified, newname must be given");
1421 return nullptr;
1422 }
1423
1424 Int_t newbins = nbins/ngroup;
1425 if (!xbins) {
1426 Int_t nbg = nbins/ngroup;
1427 if (nbg*ngroup != nbins) {
1428 Warning("Rebin", "ngroup=%d must be an exact divider of nbins=%d",ngroup,nbins);
1429 }
1430 }
1431 else {
1432 // in the case of xbins given (rebinning in variable bins) ngroup is the new number of bins.
1433 // and number of grouped bins is not constant.
1434 // when looping for setting the contents for the new histogram we
1435 // need to loop on all bins of original histogram. Set then ngroup=nbins
1436 newbins = ngroup;
1437 ngroup = nbins;
1438 }
1439
1440 // Save old bin contents into a new array
1441 Double_t *oldBins = new Double_t[nbins+2];
1442 Double_t *oldCount = new Double_t[nbins+2];
1443 Double_t *oldErrors = new Double_t[nbins+2];
1444 Double_t *oldBinw2 = (fBinSumw2.fN ? new Double_t[nbins+2] : nullptr );
1445 Int_t bin, i;
1446 Double_t *cu1 = GetW();
1447 Double_t *er1 = GetW2();
1448 Double_t *en1 = GetB();
1449 Double_t *ew1 = GetB2();
1450
1451 for (bin=0;bin<=nbins+1;bin++) {
1452 oldBins[bin] = cu1[bin];
1453 oldCount[bin] = en1[bin];
1454 oldErrors[bin] = er1[bin];
1455 if (ew1 && fBinSumw2.fN) oldBinw2[bin] = ew1[bin];
1456 }
1457
1458 // create a clone of the old histogram if newname is specified
1459 TProfile *hnew = this;
1460 if ((newname && strlen(newname) > 0) || xbins) {
1461 hnew = (TProfile*)Clone(newname);
1462 }
1463
1464 // in case of ngroup not an excat divider of nbins,
1465 // top limit is changed (see NOTE in method comment)
1466 if(!xbins && (newbins*ngroup != nbins)) {
1467 xmax = fXaxis.GetBinUpEdge(newbins*ngroup);
1468 hnew->fTsumw = 0; //stats must be reset because top bins will be moved to overflow bin
1469 }
1470
1471 // set correctly the axis and resizes the bin arrays
1472 if(!xbins && (fXaxis.GetXbins()->GetSize() > 0)){
1473 // for rebinning of variable bins in a constant group
1474 Double_t *bins = new Double_t[newbins+1];
1475 for(i = 0; i <= newbins; ++i) bins[i] = fXaxis.GetBinLowEdge(1+i*ngroup);
1476 hnew->SetBins(newbins,bins); //this also changes the bin array's
1477 delete [] bins;
1478 } else if (xbins) {
1479 // when rebinning in variable bins
1480 hnew->SetBins(newbins,xbins);
1481 } else {
1482 hnew->SetBins(newbins,xmin,xmax);
1483 }
1484
1485 // merge bin contents ignoring now underflow/overflows
1486 if (fBinSumw2.fN) hnew->Sumw2();
1487
1488 // Start merging only once the new lowest edge is reached
1489 Int_t startbin = 1;
1490 const Double_t newxmin = hnew->GetXaxis()->GetBinLowEdge(1);
1491 while( fXaxis.GetBinCenter(startbin) < newxmin && startbin <= nbins ) {
1492 startbin++;
1493 }
1494
1495 Double_t *cu2 = hnew->GetW();
1496 Double_t *er2 = hnew->GetW2();
1497 Double_t *en2 = hnew->GetB();
1498 Double_t *ew2 = hnew->GetB2();
1499 Int_t oldbin = startbin;
1500 Double_t binContent, binCount, binError, binSumw2;
1501 for (bin = 1;bin<=newbins;bin++) {
1502 binContent = 0;
1503 binCount = 0;
1504 binError = 0;
1505 binSumw2 = 0;
1506
1507 //for xbins != 0: ngroup == nbins
1508 Int_t imax = ngroup;
1509 Double_t xbinmax = hnew->GetXaxis()->GetBinUpEdge(bin);
1510 for (i=0;i<ngroup;i++) {
1511 if((hnew == this && (oldbin+i > nbins)) ||
1512 (hnew != this && (fXaxis.GetBinCenter(oldbin+i) > xbinmax)))
1513 {
1514 imax = i;
1515 break;
1516 }
1517
1518 binContent += oldBins[oldbin+i];
1519 binCount += oldCount[oldbin+i];
1520 binError += oldErrors[oldbin+i];
1521 if (fBinSumw2.fN) binSumw2 += oldBinw2[oldbin+i];
1522 }
1523
1524 cu2[bin] = binContent;
1525 er2[bin] = binError;
1526 en2[bin] = binCount;
1527 if (fBinSumw2.fN) ew2[bin] = binSumw2;
1528 oldbin += imax;
1529 }
1530 // set bin statistics for underflow bin
1531 binContent = 0;
1532 binCount = 0;
1533 binError = 0;
1534 binSumw2 = 0;
1535 for(i=0;i<startbin;i++)
1536 {
1537 binContent += oldBins[i];
1538 binCount += oldCount[i];
1539 binError += oldErrors[i];
1540 if (fBinSumw2.fN) binSumw2 += oldBinw2[i];
1541 }
1542 hnew->fArray[0] = binContent;
1543 hnew->fBinEntries[0] = binCount;
1544 hnew->fSumw2[0] = binError;
1545 if ( fBinSumw2.fN ) hnew->fBinSumw2[0] = binSumw2;
1546
1547 // set bin statistics for overflow bin
1548 binContent = 0;
1549 binCount = 0;
1550 binError = 0;
1551 binSumw2 = 0;
1552 for(i=oldbin;i<=nbins+1;i++)
1553 {
1554 binContent += oldBins[i];
1555 binCount += oldCount[i];
1556 binError += oldErrors[i];
1557 if (fBinSumw2.fN) binSumw2 += oldBinw2[i];
1558 }
1559 hnew->fArray[newbins+1] = binContent;
1560 hnew->fBinEntries[newbins+1] = binCount;
1561 hnew->fSumw2[newbins+1] = binError;
1562 if ( fBinSumw2.fN ) hnew->fBinSumw2[newbins+1] = binSumw2;
1563
1564
1565 delete [] oldBins;
1566 delete [] oldCount;
1567 delete [] oldErrors;
1568 if (oldBinw2) delete [] oldBinw2;
1569 return hnew;
1570}
1571
1572////////////////////////////////////////////////////////////////////////////////
1573/// Profile histogram is resized along x axis such that x is in the axis range.
1574/// The new axis limits are recomputed by doubling iteratively
1575/// the current axis range until the specified value x is within the limits.
1576/// The algorithm makes a copy of the histogram, then loops on all bins
1577/// of the old histogram to fill the extended histogram.
1578/// Takes into account errors (Sumw2) if any.
1579/// The axis must be extendable before invoking this function.
1580///
1581/// Ex: `h->GetXaxis()->SetCanExtend(kTRUE)`
1582
1584{
1585 TProfile* hold = TProfileHelper::ExtendAxis(this, x, axis);
1586 if ( hold ) {
1587 fTsumwy = hold->fTsumwy;
1588 fTsumwy2 = hold->fTsumwy2;
1589
1590 delete hold;
1591 }
1592}
1593
1594////////////////////////////////////////////////////////////////////////////////
1595/// Reset contents of a Profile histogram.
1596
1598{
1601 fBinSumw2.Reset();
1602 TString opt = option;
1603 opt.ToUpper();
1604 if (opt.Contains("ICE") && !opt.Contains("S")) return;
1605 fTsumwy = 0;
1606 fTsumwy2 = 0;
1607}
1608
1609////////////////////////////////////////////////////////////////////////////////
1610/// Save primitive as a C++ statement(s) on output stream out.
1611
1612void TProfile::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1613{
1614 //Note the following restrictions in the code generated:
1615 // - variable bin size not implemented
1616 // - SetErrorOption not implemented
1617
1618 Bool_t nonEqiX = kFALSE;
1619 Int_t i;
1620 // Check if the profile has equidistant X bins or not. If not, we
1621 // create an array holding the bins.
1622 if (GetXaxis()->GetXbins()->fN && GetXaxis()->GetXbins()->fArray) {
1623 nonEqiX = kTRUE;
1624 out << " Double_t xAxis[" << GetXaxis()->GetXbins()->fN
1625 << "] = {";
1626 for (i = 0; i < GetXaxis()->GetXbins()->fN; i++) {
1627 if (i != 0) out << ", ";
1628 out << GetXaxis()->GetXbins()->fArray[i];
1629 }
1630 out << "}; " << std::endl;
1631 }
1632
1633 char quote = '"';
1634 out<<" "<<std::endl;
1635 out<<" "<<ClassName()<<" *";
1636
1637 //histogram pointer has by default the histogram name.
1638 //however, in case histogram has no directory, it is safer to add a incremental suffix
1639 static Int_t hcounter = 0;
1640 TString histName = gInterpreter->MapCppName(GetName());
1641 if (!fDirectory) {
1642 hcounter++;
1643 histName += "__";
1644 histName += hcounter;
1645 }
1646 const char *hname = histName.Data();
1647
1648 out << hname << " = new " << ClassName() << "(" << quote << hname << quote << "," << quote << GetTitle() << quote
1649 << "," << GetXaxis()->GetNbins();
1650 if (nonEqiX)
1651 out << ", xAxis";
1652 else
1653 out << "," << GetXaxis()->GetXmin()
1654 << "," << GetXaxis()->GetXmax()
1655 <<","<<quote<<GetErrorOption()<<quote<<");"<<std::endl;
1656
1657 // save bin entries
1658 Int_t bin;
1659 for (bin=0;bin<fNcells;bin++) {
1660 Double_t bi = GetBinEntries(bin);
1661 if (bi) {
1662 out<<" "<<hname<<"->SetBinEntries("<<bin<<","<<bi<<");"<<std::endl;
1663 }
1664 }
1665 //save bin contents
1666 for (bin=0;bin<fNcells;bin++) {
1667 Double_t bc = fArray[bin];
1668 if (bc) {
1669 out<<" "<<hname<<"->SetBinContent("<<bin<<","<<bc<<");"<<std::endl;
1670 }
1671 }
1672 // save bin errors
1673 if (fSumw2.fN) {
1674 for (bin=0;bin<fNcells;bin++) {
1675 Double_t be = TMath::Sqrt(fSumw2.fArray[bin]);
1676 if (be) {
1677 out<<" "<<hname<<"->SetBinError("<<bin<<","<<be<<");"<<std::endl;
1678 }
1679 }
1680 }
1681
1682 TH1::SavePrimitiveHelp(out, hname, option);
1683}
1684
1685////////////////////////////////////////////////////////////////////////////////
1686/// Multiply this profile by a constant c1.
1687///
1688/// `this = c1*this`
1689///
1690/// This function uses the services of TProfile::Add
1691
1693{
1695}
1696
1697////////////////////////////////////////////////////////////////////////////////
1698/// Set the number of entries in bin.
1699
1701{
1702 TProfileHelper::SetBinEntries(this, bin, w);
1703}
1704
1705////////////////////////////////////////////////////////////////////////////////
1706/// Redefine x axis parameters.
1707
1709{
1710 fXaxis.Set(nx,xmin,xmax);
1711 fNcells = nx+2;
1713}
1714
1715////////////////////////////////////////////////////////////////////////////////
1716/// Redefine x axis parameters.
1717
1718void TProfile::SetBins(Int_t nx, const Double_t *xbins)
1719{
1720 fXaxis.Set(nx,xbins);
1721 fNcells = nx+2;
1723}
1724
1725////////////////////////////////////////////////////////////////////////////////
1726/// Set total number of bins including under/overflow.
1727/// Reallocate bin contents array
1728
1730{
1733}
1734
1735////////////////////////////////////////////////////////////////////////////////
1736/// Set the buffer size in units of 8 bytes (double).
1737
1739{
1740 if (fBuffer) {
1741 BufferEmpty();
1742 delete [] fBuffer;
1743 fBuffer = nullptr;
1744 }
1745 if (buffersize <= 0) {
1746 fBufferSize = 0;
1747 return;
1748 }
1749 if (buffersize < 100) buffersize = 100;
1750 fBufferSize = 1 + 3*buffersize;
1752 memset(fBuffer,0,sizeof(Double_t)*fBufferSize);
1753}
1754
1755////////////////////////////////////////////////////////////////////////////////
1756/// Set option to compute profile errors.
1757///
1758/// The computation of the bin errors is based on the parameter option:
1759///
1760/// -' ' (Default) The bin errors are the standard error on the mean of the bin profiled values (Y),
1761/// i.e. the standard error of the bin contents.
1762/// Note that if TProfile::Approximate() is called, an approximation is used when
1763/// the spread in Y is 0 and the number of bin entries is > 0
1764/// -'s' The bin errors are the standard deviations of the Y bin values
1765/// Note that if TProfile::Approximate() is called, an approximation is used when
1766/// the spread in Y is 0 and the number of bin entries is > 0
1767/// -'i' Errors are as in default case (standard errors of the bin contents)
1768/// The only difference is for the case when the spread in Y is zero.
1769/// In this case for N > 0 the error is 1./SQRT(12.*N)
1770/// -'g' Errors are 1./SQRT(W) for W not equal to 0 and 0 for W = 0.
1771/// W is the sum in the bin of the weights of the profile.
1772/// This option is for combining measurements y +/- dy,
1773/// and the profile is filled with values y and weights w = 1/dy**2
1774///
1775/// See TProfile::BuildOptions for a detailed explanation of all options
1776
1778{
1780}
1781
1782////////////////////////////////////////////////////////////////////////////////
1783/// Stream an object of class TProfile.
1784
1786{
1787 if (R__b.IsReading()) {
1788 UInt_t R__s, R__c;
1789 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1790 if (R__v > 2) {
1791 R__b.ReadClassBuffer(TProfile::Class(), this, R__v, R__s, R__c);
1792 return;
1793 }
1794 //====process old versions before automatic schema evolution
1795 TH1D::Streamer(R__b);
1796 fBinEntries.Streamer(R__b);
1797 Int_t errorMode;
1798 R__b >> errorMode;
1799 fErrorMode = (EErrorType)errorMode;
1800 if (R__v < 2) {
1802 R__b >> ymin; fYmin = ymin;
1803 R__b >> ymax; fYmax = ymax;
1804 } else {
1805 R__b >> fYmin;
1806 R__b >> fYmax;
1807 }
1808 R__b.CheckByteCount(R__s, R__c, TProfile::IsA());
1809 //====end of old versions
1810
1811 } else {
1812 R__b.WriteClassBuffer(TProfile::Class(),this);
1813 }
1814}
1815////////////////////////////////////////////////////////////////////////////////
1816/// Create/delete structure to store sum of squares of weights per bin.
1817///
1818/// This is needed to compute the correct statistical quantities
1819/// of a profile filled with weights
1820///
1821/// This function is automatically called when the histogram is created
1822/// if the static function TH1::SetDefaultSumw2 has been called before.
1823/// If flag is false the structure is deleted
1824
1826{
1827 TProfileHelper::Sumw2(this, flag);
1828}
#define a(i)
Definition RSha256.hxx:99
#define s1(x)
Definition RSha256.hxx:91
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
short Version_t
Definition RtypesCore.h:65
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:69
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
#define gInterpreter
EErrorType
Definition TProfile.h:28
@ kERRORSPREAD
Definition TProfile.h:28
@ kERRORSPREADG
Definition TProfile.h:28
@ kERRORSPREADI
Definition TProfile.h:28
Int_t gDebug
Definition TROOT.cxx:597
Array of doubles (64 bits per element).
Definition TArrayD.h:27
Double_t * fArray
Definition TArrayD.h:30
void Streamer(TBuffer &) override
Stream a TArrayD object.
Definition TArrayD.cxx:149
void Copy(TArrayD &array) const
Definition TArrayD.h:42
TArrayD()
Default TArrayD ctor.
Definition TArrayD.cxx:26
void Reset()
Definition TArrayD.h:47
Int_t fN
Definition TArray.h:38
Int_t GetSize() const
Definition TArray.h:47
Class to manage histogram axis.
Definition TAxis.h:31
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition TAxis.cxx:887
Bool_t IsAlphanumeric() const
Definition TAxis.h:88
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
@ kLabelsUp
Definition TAxis.h:74
@ kLabelsDown
Definition TAxis.h:73
@ kLabelsHori
Definition TAxis.h:71
@ kAxisRange
Definition TAxis.h:65
@ kLabelsVert
Definition TAxis.h:72
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
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition TAxis.cxx:795
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:469
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition TAxis.cxx:681
Double_t GetXmin() const
Definition TAxis.h:139
Int_t GetNbins() const
Definition TAxis.h:125
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
THashList * GetLabels() const
Definition TAxis.h:121
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Collection abstract base class.
Definition TCollection.h:65
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
1-Dim function class
Definition TF1.h:233
static void RejectPoint(Bool_t reject=kTRUE)
Static function to set the global flag to reject points the fgRejectPoint global flag is tested by al...
Definition TF1.cxx:3683
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=nullptr)
Evaluate function with given coordinates and parameters.
Definition TF1.cxx:1468
static Bool_t RejectedPoint()
See TF1::RejectPoint above.
Definition TF1.cxx:3692
virtual Bool_t IsInside(const Double_t *x) const
return kTRUE if the point is inside the function range
Definition TF1.h:626
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:671
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow Reallocate bin contents array.
Definition TH1.cxx:10534
void Copy(TObject &hnew) const override
Copy this to newth1.
Definition TH1.cxx:10516
void Streamer(TBuffer &) override
Stream a class object.
TH1D()
Constructor.
Definition TH1.cxx:10435
void AddBinContent(Int_t bin) override
Increment bin content by 1.
Definition TH1.h:685
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
Double_t * fBuffer
[fBufferSize] entry buffer
Definition TH1.h:108
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
static TClass * Class()
Double_t fTsumwx2
Total Sum of weight*X*X.
Definition TH1.h:99
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition TH1.cxx:9096
@ 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:6665
TDirectory * fDirectory
! Pointer to directory holding this histogram
Definition TH1.h:109
TAxis * GetXaxis()
Definition TH1.h:325
virtual Int_t GetNbinsX() const
Definition TH1.h:298
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:405
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:9239
TAxis * GetYaxis()
Definition TH1.h:326
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:7412
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:406
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:9255
virtual void ResetStats()
Reset the statistics including the number of entries and replace with values calculated from bin cont...
Definition TH1.cxx:7935
@ kNstat
Size of statistics data (up to TProfile3D)
Definition TH1.h:184
Double_t fEntries
Number of entries.
Definition TH1.h:95
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5090
virtual TArrayD * GetSumw2()
Definition TH1.h:314
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
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH1.cxx:2754
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:9053
virtual void SetEntries(Double_t n)
Definition TH1.h:392
Double_t fTsumwx
Total Sum of weight*X.
Definition TH1.h:98
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.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
void Clear(Option_t *option="") override
Remove all objects from the list.
void Add(TObject *obj) override
Definition TList.h:81
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:355
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
Collectable string class.
Definition TObjString.h:28
TString & String()
Definition TObjString.h:48
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition TObject.cxx:474
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:225
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:991
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:798
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:542
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1005
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1033
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:809
virtual TClass * IsA() const
Definition TObject.h:243
void ResetBit(UInt_t f)
Definition TObject.h:198
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 *)
Profile Histogram.
Definition TProfile.h:32
Double_t GetBinContent(Int_t bin) const override
Return bin content of a Profile histogram.
Definition TProfile.cxx:824
virtual Double_t GetBinEffectiveEntries(Int_t bin) const
Return bin effective entries for a weighted filled Profile histogram.
Definition TProfile.cxx:853
Bool_t Divide(TF1 *h1, Double_t c1=1) override
Performs the operation: this = this/(c1*f1).
Definition TProfile.cxx:453
TH1 * Rebin(Int_t ngroup=2, const char *newname="", const Double_t *xbins=nullptr) override
Rebin this profile grouping ngroup bins together.
static Bool_t fgApproximate
bin error approximation option
Definition TProfile.h:48
void ExtendAxis(Double_t x, TAxis *axis) override
Profile histogram is resized along x axis such that x is in the axis range.
void PutStats(Double_t *stats) override
Replace current statistics with the values in array stats.
void BuildOptions(Double_t ymin, Double_t ymax, Option_t *option)
Set Profile histogram structure and options.
Definition TProfile.cxx:227
EErrorType fErrorMode
Option to compute errors.
Definition TProfile.h:40
Long64_t Merge(TCollection *list) override
Merge all histograms in the collection in this histogram.
void Copy(TObject &hnew) const override
Copy a Profile histogram to a new profile histogram.
Definition TProfile.cxx:423
Double_t fYmax
Upper limit in Y (if set)
Definition TProfile.h:42
virtual void SetBinEntries(Int_t bin, Double_t w)
Set the number of entries in bin.
TH1D * ProjectionX(const char *name="_px", Option_t *option="e") const
Project this profile into a 1-D histogram along X.
virtual void SetErrorOption(Option_t *option="")
Set option to compute profile errors.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
virtual Double_t GetBinEntries(Int_t bin) const
Return bin entries of a Profile histogram.
Definition TProfile.cxx:837
static TClass * Class()
void LabelsDeflate(Option_t *axis="X") override
Reduce the number of bins for this axis to the number of bins having a label.
Definition TProfile.cxx:973
Double_t * GetB2()
Definition TProfile.h:65
void Streamer(TBuffer &) override
Stream an object of class TProfile.
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow.
void Scale(Double_t c1=1, Option_t *option="") override
Multiply this profile by a constant c1.
TProfile()
Default constructor for Profile histograms.
Definition TProfile.cxx:92
Int_t BufferEmpty(Int_t action=0) override
Fill histogram with all entries in the buffer.
Definition TProfile.cxx:338
void SetBuffer(Int_t buffersize, Option_t *option="") override
Set the buffer size in units of 8 bytes (double).
void FillN(Int_t, const Double_t *, const Double_t *, Int_t) override
Fill this histogram with an array x and weights w.
Definition TProfile.h:63
TProfile & operator=(const TProfile &profile)
Definition TProfile.cxx:249
void Sumw2(Bool_t flag=kTRUE) override
Create/delete structure to store sum of squares of weights per bin.
void LabelsInflate(Option_t *axis="X") override
Double the number of bins for axis.
Definition TProfile.cxx:983
Double_t fTsumwy2
Total Sum of weight*Y*Y.
Definition TProfile.h:45
Bool_t Multiply(TF1 *h1, Double_t c1=1) override
Performs the operation: this = this*c1*f1.
TArrayD fBinSumw2
Array of sum of squares of weights per bin.
Definition TProfile.h:46
Double_t GetBinError(Int_t bin) const override
Return bin error of a Profile histogram.
Definition TProfile.cxx:888
Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="") override
Performs the operation: this = this + c1*f1.
Definition TProfile.cxx:259
Int_t Fill(const Double_t *v)
Definition TProfile.h:55
Double_t fTsumwy
Total Sum of weight*Y.
Definition TProfile.h:44
Int_t BufferFill(Double_t, Double_t) override
accumulate arguments in buffer.
Definition TProfile.h:50
Double_t * GetB()
Definition TProfile.h:64
~TProfile() override
Default destructor for Profile histograms.
Definition TProfile.cxx:100
void SetBins(const Int_t *nbins, const Double_t *range)
Definition TProfile.h:54
Double_t fYmin
Lower limit in Y (if set)
Definition TProfile.h:41
TArrayD fBinEntries
number of entries per bin
Definition TProfile.h:39
Double_t * GetW()
Definition TProfile.h:66
static void Approximate(Bool_t approx=kTRUE)
Static function to set the fgApproximate flag.
Definition TProfile.cxx:324
Bool_t fScaling
! True when TProfile::Scale is called
Definition TProfile.h:43
void GetStats(Double_t *stats) const override
fill the array stats from the contents of this profile.
Definition TProfile.cxx:921
TClass * IsA() const override
Definition TProfile.h:138
Option_t * GetErrorOption() const
Return option to compute profile errors.
Definition TProfile.cxx:896
void LabelsOption(Option_t *option="h", Option_t *axis="X") override
Set option(s) to draw axis with labels.
Double_t * GetW2()
Definition TProfile.h:67
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
const char * Data() const
Definition TString.h:376
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
TF1 * f1
Definition legend1.C:11
return c2
Definition legend2.C:14
Bool_t IsNaN(Double_t x)
Definition TMath.h:896
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:666
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Sort the n elements of the array a of generic templated type Element.
Definition TMathBase.h:431
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123