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 \\
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 return TProfileHelper::Add(this, h1, h2, c1, c2);
306}
307
308
309////////////////////////////////////////////////////////////////////////////////
310/// Static function to set the fgApproximate flag.
311///
312///When the flag is true, the function GetBinError
313/// will approximate the bin error with the average profile error on all bins
314/// in the following situation only
315///
316/// - the number of bins in the profile is less than 1002
317/// - the bin number of entries is small ( <5)
318/// - the estimated bin error is extremely small compared to the bin content
319/// (see TProfile::GetBinError)
320
322{
323 fgApproximate = approx;
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// Fill histogram with all entries in the buffer.
328///
329/// - action = -1 histogram is reset and refilled from the buffer (called by THistPainter::Paint)
330/// - action = 0 histogram is filled from the buffer
331/// - action = 1 histogram is filled and buffer is deleted
332/// The buffer is automatically deleted when the number of entries
333/// in the buffer is greater than the number of entries in the histogram
334
336{
337 // do we need to compute the bin size?
338 if (!fBuffer) return 0;
339 Int_t nbentries = (Int_t)fBuffer[0];
340 if (!nbentries) return 0;
341 Double_t *buffer = fBuffer;
342 if (nbentries < 0) {
343 if (action == 0) return 0;
344 nbentries = -nbentries;
345 fBuffer=nullptr;
346 Reset("ICES"); // reset without deleting the functions
347 fBuffer = buffer;
348 }
349 if (CanExtendAllAxes() || fXaxis.GetXmax() <= fXaxis.GetXmin()) {
350 //find min, max of entries in buffer
351 Double_t xmin = fBuffer[2];
353 for (Int_t i=1;i<nbentries;i++) {
354 Double_t x = fBuffer[3*i+2];
355 if (x < xmin) xmin = x;
356 if (x > xmax) xmax = x;
357 }
358 if (fXaxis.GetXmax() <= fXaxis.GetXmin()) {
360 } else {
361 fBuffer = nullptr;
362 Int_t keep = fBufferSize; fBufferSize = 0;
365 fBuffer = buffer;
366 fBufferSize = keep;
367 }
368 }
369
370 fBuffer = nullptr;
371
372 for (Int_t i=0;i<nbentries;i++) {
373 Fill(buffer[3*i+2],buffer[3*i+3],buffer[3*i+1]);
374 }
375 fBuffer = buffer;
376
377 if (action > 0) { delete [] fBuffer; fBuffer = nullptr; fBufferSize = 0;}
378 else {
379 if (nbentries == (Int_t)fEntries) fBuffer[0] = -nbentries;
380 else fBuffer[0] = 0;
381 }
382 return nbentries;
383}
384
385////////////////////////////////////////////////////////////////////////////////
386/// accumulate arguments in buffer. When buffer is full, empty the buffer.
387///
388/// - fBuffer[0] = number of entries in buffer
389/// - fBuffer[1] = w of first entry
390/// - fBuffer[2] = x of first entry
391/// - fBuffer[3] = y of first entry
392
394{
395 if (!fBuffer) return -2;
396 Int_t nbentries = (Int_t)fBuffer[0];
397 if (nbentries < 0) {
398 nbentries = -nbentries;
399 fBuffer[0] = nbentries;
400 if (fEntries > 0) {
401 Double_t *buffer = fBuffer; fBuffer=nullptr;
402 Reset("ICES"); // reset without deleting the functions
403 fBuffer = buffer;
404 }
405 }
406 if (3*nbentries+3 >= fBufferSize) {
407 BufferEmpty(1);
408 return Fill(x,y,w);
409 }
410 fBuffer[3*nbentries+1] = w;
411 fBuffer[3*nbentries+2] = x;
412 fBuffer[3*nbentries+3] = y;
413 fBuffer[0] += 1;
414 return -2;
415}
416
417////////////////////////////////////////////////////////////////////////////////
418/// Copy a Profile histogram to a new profile histogram.
419
420void TProfile::Copy(TObject &obj) const
421{
422 try {
423 TProfile &pobj = dynamic_cast<TProfile&>(obj);
424 TH1D::Copy(pobj);
427 for (int bin=0;bin<fNcells;bin++) {
428 pobj.fArray[bin] = fArray[bin];
429 pobj.fSumw2.fArray[bin] = fSumw2.fArray[bin];
430 }
431
432 pobj.fYmin = fYmin;
433 pobj.fYmax = fYmax;
434 pobj.fScaling = fScaling;
435 pobj.fErrorMode = fErrorMode;
436 pobj.fTsumwy = fTsumwy;
437 pobj.fTsumwy2 = fTsumwy2;
438
439 } catch(...) {
440 Fatal("Copy","Cannot copy a TProfile in a %s",obj.IsA()->GetName());
441 }
442
443}
444
445////////////////////////////////////////////////////////////////////////////////
446/// Performs the operation: `this = this/(c1*f1)`.
447///
448/// This function is not implemented for the TProfile
449
451{
452 Error("Divide","Function not implemented for TProfile");
453 return kFALSE;
454}
455
456////////////////////////////////////////////////////////////////////////////////
457/// Divide this profile by h1.
458///
459/// `this = this/h1`
460///
461/// This function accepts to divide a TProfile by a histogram
462///
463/// The function return kFALSE if the divide operation failed
464
466{
467 if (!h1) {
468 Error("Divide","Attempt to divide a non-existing profile");
469 return kFALSE;
470 }
471 if (!h1->InheritsFrom(TH1::Class())) {
472 Error("Divide","Attempt to divide by a non-profile or non-histogram object");
473 return kFALSE;
474 }
475 TProfile *p1 = (TProfile*)h1;
476
477 // delete buffer if it is there since it will become invalid
478 if (fBuffer) BufferEmpty(1);
479
480
481 Int_t nbinsx = GetNbinsX();
482 //- Check profile compatibility
483 if (nbinsx != p1->GetNbinsX()) {
484 Error("Divide","Attempt to divide profiles with different number of bins");
485 return kFALSE;
486 }
487
488 //- Reset statistics
490
491 //- Loop on bins (including underflows/overflows)
492 Int_t bin;
493 Double_t *cu1=nullptr, *er1=nullptr, *en1=nullptr;
494 Double_t e0,e1,c12;
496 cu1 = p1->GetW();
497 er1 = p1->GetW2();
498 en1 = p1->GetB();
499 }
500 Double_t c0,c1,w,z,x;
501 for (bin=0;bin<=nbinsx+1;bin++) {
502 c0 = fArray[bin];
503 if (cu1) c1 = cu1[bin];
504 else c1 = h1->GetBinContent(bin);
505 if (c1) w = c0/c1;
506 else w = 0;
507 fArray[bin] = w;
508 z = TMath::Abs(w);
509 x = fXaxis.GetBinCenter(bin);
510 fEntries++;
511 fTsumw += z;
512 fTsumw2 += z*z;
513 fTsumwx += z*x;
514 fTsumwx2 += z*x*x;
515 fTsumwy += z*c1;
516 fTsumwx2 += z*c1*c1;
517 e0 = fSumw2.fArray[bin];
518 if (er1) e1 = er1[bin];
519 else {e1 = h1->GetBinError(bin); e1*=e1;}
520 c12= c1*c1;
521 if (!c1) fSumw2.fArray[bin] = 0;
522 else fSumw2.fArray[bin] = (e0*c1*c1 + e1*c0*c0)/(c12*c12);
523 if (!en1) continue;
524 if (!en1[bin]) fBinEntries.fArray[bin] = 0;
525 else fBinEntries.fArray[bin] /= en1[bin];
526 }
527 // maintaining the correct sum of weights square is not supported when dividing
528 // bin error resulting from division of profile needs to be checked
529 if (fBinSumw2.fN) {
530 Warning("Divide","Cannot preserve during the division of profiles the sum of bin weight square");
531 fBinSumw2 = TArrayD();
532 }
533
534 return kTRUE;
535}
536
537////////////////////////////////////////////////////////////////////////////////
538/// Replace contents of this profile by the division of h1 by h2.
539///
540/// `this = c1*h1/(c2*h2)`
541///
542/// The function return kFALSE if the divide operation failed
543
545{
546 TString opt = option;
547 opt.ToLower();
548 Bool_t binomial = kFALSE;
549 if (opt.Contains("b")) binomial = kTRUE;
550 if (!h1 || !h2) {
551 Error("Divide","Attempt to divide a non-existing profile");
552 return kFALSE;
553 }
555 Error("Divide","Attempt to divide a non-profile object");
556 return kFALSE;
557 }
558 TProfile *p1 = (TProfile*)h1;
559 if (!h2->InheritsFrom(TProfile::Class())) {
560 Error("Divide","Attempt to divide by a non-profile object");
561 return kFALSE;
562 }
563 TProfile *p2 = (TProfile*)h2;
564
565 // delete buffer if it is there since it will become invalid
566 if (fBuffer) BufferEmpty(1);
567
568 Int_t nbinsx = GetNbinsX();
569 //- Check histogram compatibility
570 if (nbinsx != p1->GetNbinsX() || nbinsx != p2->GetNbinsX()) {
571 Error("Divide","Attempt to divide profiles with different number of bins");
572 return kFALSE;
573 }
574 if (!c2) {
575 Error("Divide","Coefficient of dividing profile cannot be zero");
576 return kFALSE;
577 }
578
579 //THE ALGORITHM COMPUTING THE ERRORS IS WRONG. HELP REQUIRED
580 printf("WARNING!!: The algorithm in TProfile::Divide computing the errors is not accurate\n");
581 printf(" Instead of Divide(TProfile *h1, TProfile *h2), do:\n");
582 printf(" TH1D *p1 = h1->ProjectionX();\n");
583 printf(" TH1D *p2 = h2->ProjectionX();\n");
584 printf(" p1->Divide(p2);\n");
585
586 //- Reset statistics
588
589 //- Loop on bins (including underflows/overflows)
590 Int_t bin;
591 Double_t *cu1 = p1->GetW();
592 Double_t *cu2 = p2->GetW();
593 Double_t *er1 = p1->GetW2();
594 Double_t *er2 = p2->GetW2();
595 Double_t *en1 = p1->GetB();
596 Double_t *en2 = p2->GetB();
597 Double_t b1,b2,w,z,x,ac1,ac2;
598 //d1 = c1*c1;
599 //d2 = c2*c2;
600 ac1 = TMath::Abs(c1);
601 ac2 = TMath::Abs(c2);
602 for (bin=0;bin<=nbinsx+1;bin++) {
603 b1 = cu1[bin];
604 b2 = cu2[bin];
605 if (b2) w = c1*b1/(c2*b2);
606 else w = 0;
607 fArray[bin] = w;
608 z = TMath::Abs(w);
609 x = fXaxis.GetBinCenter(bin);
610 fEntries++;
611 fTsumw += z;
612 fTsumw2 += z*z;
613 fTsumwx += z*x;
614 fTsumwx2 += z*x*x;
615 //fTsumwy += z*x;
616 //fTsumwy2 += z*x*x;
617 Double_t e1 = er1[bin];
618 Double_t e2 = er2[bin];
619 //Double_t b22= b2*b2*d2;
620 Double_t b22= b2*b2*TMath::Abs(c2);
621 if (!b2) fSumw2.fArray[bin] = 0;
622 else {
623 if (binomial) {
624 fSumw2.fArray[bin] = TMath::Abs(w*(1-w)/b2);
625 } else {
626 //fSumw2.fArray[bin] = d1*d2*(e1*b2*b2 + e2*b1*b1)/(b22*b22);
627 fSumw2.fArray[bin] = ac1*ac2*(e1*b2*b2 + e2*b1*b1)/(b22*b22);
628 }
629 }
630 if (en2[bin]) fBinEntries.fArray[bin] = en1[bin]/en2[bin];
631 else fBinEntries.fArray[bin] = 0;
632 }
633
634 // maintaining the correct sum of weights square is not supported when dividing
635 // bin error resulting from division of profile needs to be checked
636 if (fBinSumw2.fN) {
637 Warning("Divide","Cannot preserve during the division of profiles the sum of bin weight square");
638 fBinSumw2 = TArrayD();
639 }
640
641 return kTRUE;
642}
643
644////////////////////////////////////////////////////////////////////////////////
645/// Fill a Profile histogram (no weights).
646
648{
649 if (fBuffer) return BufferFill(x,y,1);
650
651 Int_t bin;
652 if (fYmin != fYmax) {
653 if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
654 }
655
656 fEntries++;
657 bin =fXaxis.FindBin(x);
658 AddBinContent(bin, y);
659 fSumw2.fArray[bin] += (Double_t)y*y;
660 fBinEntries.fArray[bin] += 1;
661 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += 1;
662 if (bin == 0 || bin > fXaxis.GetNbins()) {
663 if (!GetStatOverflowsBehaviour()) return -1;
664 }
665 fTsumw++;
666 fTsumw2++;
667 fTsumwx += x;
668 fTsumwx2 += x*x;
669 fTsumwy += y;
670 fTsumwy2 += y*y;
671 return bin;
672}
673
674////////////////////////////////////////////////////////////////////////////////
675/// Fill a Profile histogram (no weights).
676
677Int_t TProfile::Fill(const char *namex, Double_t y)
678{
679 Int_t bin;
680 if (fYmin != fYmax) {
681 if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
682 }
683
684 fEntries++;
685 bin =fXaxis.FindBin(namex);
686 AddBinContent(bin, y);
687 fSumw2.fArray[bin] += (Double_t)y*y;
688 fBinEntries.fArray[bin] += 1;
689 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += 1;
690 if (bin == 0 || bin > fXaxis.GetNbins()) {
691 if (!GetStatOverflowsBehaviour()) return -1;
692 }
693 fTsumw++;
694 fTsumw2++;
695 fTsumwy += y;
696 fTsumwy2 += y * y;
697 if (!fXaxis.CanExtend() || !fXaxis.IsAlphanumeric()) {
699 fTsumwx += x;
700 fTsumwx2 += x * x;
701 }
702 return bin;
703}
704////////////////////////////////////////////////////////////////////////////////
705/// Fill a Profile histogram with weights.
706
708{
709 if (fBuffer) return BufferFill(x,y,w);
710
711 Int_t bin;
712 if (fYmin != fYmax) {
713 if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
714 }
715
716 Double_t u= w;
717 fEntries++;
718 bin =fXaxis.FindBin(x);
719 AddBinContent(bin, u*y);
720 fSumw2.fArray[bin] += u*y*y;
721 if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
722 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
723 fBinEntries.fArray[bin] += u;
724 if (bin == 0 || bin > fXaxis.GetNbins()) {
725 if (!GetStatOverflowsBehaviour()) return -1;
726 }
727 fTsumw += u;
728 fTsumw2 += u*u;
729 fTsumwx += u*x;
730 fTsumwx2 += u*x*x;
731 fTsumwy += u*y;
732 fTsumwy2 += u*y*y;
733 return bin;
734}
735
736////////////////////////////////////////////////////////////////////////////////
737/// Fill a Profile histogram with weights.
738
740{
741 Int_t bin;
742
743 if (fYmin != fYmax) {
744 if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
745 }
746
747 Double_t u= w; // (w > 0 ? w : -w);
748 fEntries++;
749 bin =fXaxis.FindBin(namex);
750 AddBinContent(bin, u*y);
751 fSumw2.fArray[bin] += u*y*y;
752 if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
753 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
754 fBinEntries.fArray[bin] += u;
755 if (bin == 0 || bin > fXaxis.GetNbins()) {
756 if (!GetStatOverflowsBehaviour()) return -1;
757 }
758 fTsumw += u;
759 fTsumw2 += u*u;
760 if (!fXaxis.CanExtend() || !fXaxis.IsAlphanumeric()) {
762 fTsumwx += u*x;
763 fTsumwx2 += u*x*x;
764 }
765 fTsumwy += u*y;
766 fTsumwy2 += u*y*y;
767 return bin;
768}
769
770////////////////////////////////////////////////////////////////////////////////
771/// Fill a Profile histogram with weights.
772
773void TProfile::FillN(Int_t ntimes, const Double_t *x, const Double_t *y, const Double_t *w, Int_t stride)
774{
775 Int_t bin,i;
776 ntimes *= stride;
777 Int_t ifirst = 0;
778 //If a buffer is activated, fill buffer
779 // (note that this function must not be called from TH2::BufferEmpty)
780 if (fBuffer) {
781 for (i=0;i<ntimes;i+=stride) {
782 if (!fBuffer) break; // buffer can be deleted in BufferFill when is empty
783 if (w) BufferFill(x[i],y[i],w[i]);
784 else BufferFill(x[i], y[i], 1.);
785 }
786 // fill the remaining entries if the buffer has been deleted
787 if (i < ntimes && fBuffer==nullptr)
788 ifirst = i; // start from i
789 else
790 return;
791 }
792
793 for (i=ifirst;i<ntimes;i+=stride) {
794 if (fYmin != fYmax) {
795 if (y[i] <fYmin || y[i]> fYmax || TMath::IsNaN(y[i])) continue;
796 }
797
798 Double_t u = (w) ? w[i] : 1; // (w[i] > 0 ? w[i] : -w[i]);
799 fEntries++;
800 bin =fXaxis.FindBin(x[i]);
801 AddBinContent(bin, u*y[i]);
802 fSumw2.fArray[bin] += u*y[i]*y[i];
803 if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
804 if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
805 fBinEntries.fArray[bin] += u;
806 if (bin == 0 || bin > fXaxis.GetNbins()) {
807 if (!GetStatOverflowsBehaviour()) continue;
808 }
809 fTsumw += u;
810 fTsumw2 += u*u;
811 fTsumwx += u*x[i];
812 fTsumwx2 += u*x[i]*x[i];
813 fTsumwy += u*y[i];
814 fTsumwy2 += u*y[i]*y[i];
815 }
816}
817
818////////////////////////////////////////////////////////////////////////////////
819/// Return bin content of a Profile histogram.
820
822{
823 if (fBuffer) ((TProfile*)this)->BufferEmpty();
824
825 if (bin < 0 || bin >= fNcells) return 0;
826 if (fBinEntries.fArray[bin] == 0) return 0;
827 if (!fArray) return 0;
828 return fArray[bin]/fBinEntries.fArray[bin];
829}
830
831////////////////////////////////////////////////////////////////////////////////
832/// Return bin entries of a Profile histogram.
833
835{
836 if (fBuffer) ((TProfile*)this)->BufferEmpty();
837
838 if (bin < 0 || bin >= fNcells) return 0;
839 return fBinEntries.fArray[bin];
840}
841
842////////////////////////////////////////////////////////////////////////////////
843/// Return bin effective entries for a weighted filled Profile histogram.
844/// In case of an unweighted profile, it is equivalent to the number of entries per bin
845/// The effective entries is defined as the square of the sum of the weights divided by the
846/// sum of the weights square.
847/// TProfile::Sumw2() must be called before filling the profile with weights.
848/// Only by calling this method the sum of the square of the weights per bin is stored.
849
851{
853}
854
855////////////////////////////////////////////////////////////////////////////////
856/// Return bin error of a Profile histogram
857///
858/// Computing errors: A moving field
859///
860/// The computation of errors for a TProfile has evolved with the versions
861/// of ROOT. The difficulty is in computing errors for bins with low statistics.
862///
863/// - prior to version 3.00, we had no special treatment of low statistic bins.
864/// As a result, these bins had huge errors. The reason is that the
865/// expression eprim2 is very close to 0 (rounding problems) or 0.
866/// - in version 3.00 (18 Dec 2000), the algorithm is protected for values of
867/// eprim2 very small and the bin errors set to the average bin errors, following
868/// recommendations from a group of users.
869/// - in version 3.01 (19 Apr 2001), it is realized that the algorithm above
870/// should be applied only to low statistic bins.
871/// - in version 3.02 (26 Sep 2001), the same group of users recommend instead
872/// to take two times the average error on all bins for these low
873/// statistics bins giving a very small value for eprim2.
874/// - in version 3.04 (Nov 2002), the algorithm is modified/protected for the case
875/// when a TProfile is projected (ProjectionX). The previous algorithm
876/// generated a N^2 problem when projecting a TProfile with a large number of
877/// bins (eg 100000).
878/// - in version 3.05/06, a new static function TProfile::Approximate
879/// is introduced to enable or disable (default) the approximation.
880///
881/// Ideas for improvements of this algorithm are welcome. No suggestions
882/// received since our call for advice to roottalk in Jul 2002.
883/// see for instance: http://root.cern.ch/root/roottalk/roottalk02/2916.html
884
886{
887 return TProfileHelper::GetBinError((TProfile*)this, bin);
888}
889
890////////////////////////////////////////////////////////////////////////////////
891/// Return option to compute profile errors
892
894{
895 if (fErrorMode == kERRORSPREAD) return "s";
896 if (fErrorMode == kERRORSPREADI) return "i";
897 if (fErrorMode == kERRORSPREADG) return "g";
898 return "";
899}
900
901////////////////////////////////////////////////////////////////////////////////
902/// fill the array stats from the contents of this profile.
903///
904/// The array stats must be correctly dimensioned in the calling program.
905///
906/// - stats[0] = sumw
907/// - stats[1] = sumw2
908/// - stats[2] = sumwx
909/// - stats[3] = sumwx2
910/// - stats[4] = sumwy
911/// - stats[5] = sumwy2
912///
913/// If no axis-subrange is specified (via TAxis::SetRange), the array stats
914/// is simply a copy of the statistics quantities computed at filling time.
915/// If a sub-range is specified, the function recomputes these quantities
916/// from the bin contents in the current axis range.
917
918void TProfile::GetStats(Double_t *stats) const
919{
920 if (fBuffer) ((TProfile*)this)->BufferEmpty();
921
922 // Loop on bins
923 Int_t bin, binx;
924 // identify the case of labels with extension of axis range
925 // in this case the statistics in x does not make any sense
926 Bool_t labelHist = ((const_cast<TAxis&>(fXaxis)).GetLabels() && fXaxis.CanExtend() );
927
928 if ( (fTsumw == 0 /* && fEntries > 0 */) || fXaxis.TestBit(TAxis::kAxisRange) ) {
929 for (bin=0;bin<6;bin++) stats[bin] = 0;
930 if (!fBinEntries.fArray) return;
931 Int_t firstBinX = fXaxis.GetFirst();
932 Int_t lastBinX = fXaxis.GetLast();
933 // include underflow/overflow if TH1::StatOverflows(kTRUE) in case no range is set on the axis
935 if (firstBinX == 1) firstBinX = 0;
936 if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1;
937 }
938 for (binx = firstBinX; binx <= lastBinX; binx++) {
940 Double_t w2 = (fBinSumw2.fN ? fBinSumw2.fArray[binx] : w);
941 Double_t x = (!labelHist) ? fXaxis.GetBinCenter(binx) : 0;
942 stats[0] += w;
943 stats[1] += w2;
944 stats[2] += w*x;
945 stats[3] += w*x*x;
946 stats[4] += fArray[binx];
947 stats[5] += fSumw2.fArray[binx];
948 }
949 } else {
950 if (fTsumwy == 0 && fTsumwy2 == 0) {
951 //this case may happen when processing TProfiles with version <=3
952 TProfile *p = (TProfile*)this; // cheating with const
953 for (binx=fXaxis.GetFirst();binx<=fXaxis.GetLast();binx++) {
954 p->fTsumwy += fArray[binx];
955 p->fTsumwy2 += fSumw2.fArray[binx];
956 }
957 }
958 stats[0] = fTsumw;
959 stats[1] = fTsumw2;
960 stats[2] = fTsumwx;
961 stats[3] = fTsumwx2;
962 stats[4] = fTsumwy;
963 stats[5] = fTsumwy2;
964 }
965}
966
967////////////////////////////////////////////////////////////////////////////////
968/// Reduce the number of bins for this axis to the number of bins having a label.
969
971{
973}
974
975////////////////////////////////////////////////////////////////////////////////
976/// Double the number of bins for axis.
977/// Refill histogram
978/// This function is called by TAxis::FindBin(const char *label)
979
981{
982 TProfileHelper::LabelsInflate(this, options);
983}
984
985////////////////////////////////////////////////////////////////////////////////
986/// Set option(s) to draw axis with labels.
987///
988/// option might have the following values:
989///
990/// - "a" sort by alphabetic order
991/// - ">" sort by decreasing values
992/// - "<" sort by increasing values
993/// - "h" draw labels horizontal
994/// - "v" draw labels vertical
995/// - "u" draw labels up (end of label right adjusted)
996/// - "d" draw labels down (start of label left adjusted)
997
999{
1000 THashList *labels = fXaxis.GetLabels();
1001 if (!labels) {
1002 Warning("LabelsOption","Cannot sort. No labels");
1003 return;
1004 }
1005 TString opt = option;
1006 opt.ToLower();
1007 if (opt.Contains("h")) {
1012 }
1013 if (opt.Contains("v")) {
1018 }
1019 if (opt.Contains("u")) {
1024 }
1025 if (opt.Contains("d")) {
1030 }
1031 Int_t sort = -1;
1032 if (opt.Contains("a")) sort = 0;
1033 if (opt.Contains(">")) sort = 1;
1034 if (opt.Contains("<")) sort = 2;
1035 if (sort < 0) return;
1036
1037 // support only cases when first n bins have labels
1038 Int_t n = labels->GetSize();
1039 TAxis *axis = &fXaxis;
1040 if (n != axis->GetNbins()) {
1041 // check if labels are all consecutive and starts from the first bin
1042 // in that case the current code will work fine
1043 Int_t firstLabelBin = axis->GetNbins() + 1;
1044 Int_t lastLabelBin = -1;
1045 for (Int_t i = 0; i < n; ++i) {
1046 Int_t bin = labels->At(i)->GetUniqueID();
1047 if (bin < firstLabelBin)
1048 firstLabelBin = bin;
1049 if (bin > lastLabelBin)
1050 lastLabelBin = bin;
1051 }
1052 if (firstLabelBin != 1 || lastLabelBin - firstLabelBin + 1 != n) {
1053 Error("LabelsOption",
1054 "%s of TProfile %s contains bins without labels. Sorting will not work correctly - return",
1055 axis->GetName(), GetName());
1056 return;
1057 }
1058 // case where label bins are consecutive starting from first bin will work
1059 Warning(
1060 "LabelsOption",
1061 "axis %s of TProfile %s has extra following bins without labels. Sorting will work only for first label bins",
1062 axis->GetName(), GetName());
1063 }
1064 std::vector<Int_t> a(n);
1065 Int_t i;
1066 std::vector<Double_t> cont(n);
1067 std::vector<Double_t> sumw(n);
1068 std::vector<Double_t> errors(n);
1069 std::vector<Double_t> ent(n);
1070 std::vector<Double_t> binsw2;
1071 if (fBinSumw2.fN) binsw2.resize(n);
1072
1073 // delete buffer if it is there since bins will be reordered.
1074 if (fBuffer)
1075 BufferEmpty(1);
1076
1077 // make a labelold list but ordered with bins
1078 // (re-ordered original label list)
1079 std::vector<TObject *> labold(n);
1080 for (i = 0; i < n; i++)
1081 labold[i] = nullptr;
1082 TIter nextold(labels);
1083 TObject *obj;
1084 while ((obj=nextold())) {
1085 Int_t bin = obj->GetUniqueID();
1086 R__ASSERT(bin <= n);
1087 labold[bin - 1] = obj;
1088 }
1089 // order now labold according to bin content
1090
1091 labels->Clear();
1092 if (sort > 0) {
1093 //---sort by values of bins
1094 for (i=1;i<=n;i++) {
1095 a[i-1] = i-1;
1096 sumw[i-1] = fArray[i];
1097 errors[i-1] = fSumw2.fArray[i];
1098 ent[i-1] = fBinEntries.fArray[i];
1099 if (fBinSumw2.fN) binsw2[i - 1] = fBinSumw2.fArray[i];
1100 if (fBinEntries.fArray[i] == 0) cont[i-1] = 0;
1101 else cont[i-1] = fArray[i]/fBinEntries.fArray[i];
1102 }
1103 if (sort ==1)
1104 TMath::Sort(n,cont.data(),a.data(),kTRUE); //sort by decreasing values
1105 else
1106 TMath::Sort(n,cont.data(),a.data(),kFALSE); //sort by increasing values
1107 for (i=1;i<=n;i++) {
1108 fArray[i] = sumw[a[i-1]];
1109 fSumw2.fArray[i] = errors[a[i-1]];
1110 fBinEntries.fArray[i] = ent[a[i-1]];
1111 if (fBinSumw2.fN)
1112 fBinSumw2.fArray[i] = binsw2[a[i-1]];
1113 }
1114 for (i=0 ;i < n; i++) {
1115 obj = labold[a[i]];
1116 labels->Add(obj);
1117 obj->SetUniqueID(i+1);
1118 }
1119 } else {
1120
1121 //---alphabetic sort
1122 // sort labels using vector of strings and TMath::Sort
1123 // I need to array because labels order in list is not necessary that of the bins
1124 std::vector<std::string> vecLabels(n);
1125 for (i = 0; i < n; i++) {
1126 vecLabels[i] = labold[i]->GetName();
1127 a[i] = i;
1128 sumw[i] = fArray[i+1];
1129 errors[i] = fSumw2.fArray[i+1];
1130 ent[i] = fBinEntries.fArray[i+1];
1131 if (fBinSumw2.fN)
1132 binsw2[i] = fBinSumw2.fArray[i+1];
1133 }
1134 // sort in ascending order for strings
1135 TMath::Sort(n, vecLabels.data(), a.data(), kFALSE);
1136 // set the new labels
1137 for (i = 0; i < n; i++) {
1138 TObject *labelObj = labold[a[i]];
1139 labels->Add(labelObj);
1140 // set the corresponding bin. NB bin starts from 1
1141 labelObj->SetUniqueID(i + 1);
1142 if (gDebug)
1143 std::cout << "bin " << i + 1 << " setting new labels for axis " << labold.at(a[i])->GetName() << " from "
1144 << a[i] << std::endl;
1145 }
1146
1147 for (i=0; i < n; i++) {
1148 fArray[i+1] = sumw[a[i]];
1149 fSumw2.fArray[i+1] = errors[a[i]];
1150 fBinEntries.fArray[i+1] = ent[a[i]];
1151 if (fBinSumw2.fN)
1152 fBinSumw2.fArray[i+1] = binsw2[a[i]];
1153 }
1154 }
1155 // need to set to zero the statistics if axis has been sorted
1156 // see for example TH3::PutStats for definition of s vector
1157 bool labelsAreSorted = kFALSE;
1158 for (i = 0; i < n; ++i) {
1159 if (a[i] != i) {
1160 labelsAreSorted = kTRUE;
1161 break;
1162 }
1163 }
1164 if (labelsAreSorted) {
1165 double s[TH1::kNstat];
1166 GetStats(s);
1167 // if (iaxis == 1) {
1168 s[2] = 0; // fTsumwx
1169 s[3] = 0; // fTsumwx2
1170 PutStats(s);
1171 }
1172}
1173
1174////////////////////////////////////////////////////////////////////////////////
1175///Merge all histograms in the collection in this histogram.
1176///
1177/// This function computes the min/max for the x axis,
1178/// compute a new number of bins, if necessary,
1179/// add bin contents, errors and statistics.
1180/// If overflows are present and limits are different the function will fail.
1181/// The function returns the total number of entries in the result histogram
1182/// if the merge is successful, -1 otherwise.
1183///
1184/// IMPORTANT remark. The axis x may have different number
1185/// of bins and different limits, BUT the largest bin width must be
1186/// a multiple of the smallest bin width and the upper limit must also
1187/// be a multiple of the bin width.
1188
1190{
1191 return TProfileHelper::Merge(this, li);
1192}
1193
1194////////////////////////////////////////////////////////////////////////////////
1195/// Performs the operation: this = this*c1*f1
1196///
1197/// The function return kFALSE if the Multiply operation failed
1198
1200{
1201
1202 if (!f1) {
1203 Error("Multiply","Attempt to multiply by a null function");
1204 return kFALSE;
1205 }
1206
1207 Int_t nbinsx = GetNbinsX();
1208
1209 //- Add statistics
1210 Double_t xx[1], cf1, ac1 = TMath::Abs(c1);
1211 Double_t s1[10];
1212 Int_t i;
1213 for (i=0;i<10;i++) {s1[i] = 0;}
1214 PutStats(s1);
1215
1216 SetMinimum();
1217 SetMaximum();
1218
1219 //- Loop on bins (including underflows/overflows)
1220 Int_t bin;
1221 for (bin=0;bin<=nbinsx+1;bin++) {
1222 xx[0] = fXaxis.GetBinCenter(bin);
1223 if (!f1->IsInside(xx)) continue;
1225 cf1 = f1->EvalPar(xx);
1226 if (TF1::RejectedPoint()) continue;
1227 fArray[bin] *= c1*cf1;
1228 //see http://savannah.cern.ch/bugs/?func=detailitem&item_id=14851
1229 //fSumw2.fArray[bin] *= c1*c1*cf1*cf1;
1230 fSumw2.fArray[bin] *= ac1*cf1*cf1;
1231 //fBinEntries.fArray[bin] *= ac1*TMath::Abs(cf1);
1232 }
1233 return kTRUE;
1234}
1235
1236////////////////////////////////////////////////////////////////////////////////
1237/// Multiply this profile by h1.
1238///
1239/// `this = this*h1`
1240
1242{
1243 Error("Multiply","Multiplication of profile histograms not implemented");
1244 return kFALSE;
1245}
1246
1247
1248////////////////////////////////////////////////////////////////////////////////
1249/// Replace contents of this profile by multiplication of h1 by h2.
1250///
1251/// `this = (c1*h1)*(c2*h2)`
1252
1254{
1255 Error("Multiply","Multiplication of profile histograms not implemented");
1256 return kFALSE;
1257}
1258
1259////////////////////////////////////////////////////////////////////////////////
1260/// Project this profile into a 1-D histogram along X
1261///
1262/// The projection is always of the type TH1D.
1263///
1264/// - if option "E" is specified the errors of the projected histogram are computed and set
1265/// to be equal to the errors of the profile.
1266/// Option "E" is defined as the default one in the header file.
1267/// - if option "" is specified the histogram errors are simply the sqrt of its content
1268/// - if option "B" is specified, the content of bin of the returned histogram
1269/// will be equal to the GetBinEntries(bin) of the profile,
1270/// otherwise (default) it will be equal to GetBinContent(bin)
1271/// - if option "C=E" the bin contents of the projection are set to the
1272/// bin errors of the profile
1273/// - if option "W" is specified the bin content of the projected histogram is set to the
1274/// product of the bin content of the profile and the entries.
1275/// With this option the returned histogram will be equivalent to the one obtained by
1276/// filling directly a TH1D using the 2-nd value as a weight.
1277/// This makes sense only for profile filled with weights =1. If not, the error of the
1278/// projected histogram obtained with this option will not be correct.
1279
1281{
1282
1283 TString opt = option;
1284 opt.ToLower();
1285 Int_t nx = fXaxis.GetNbins();
1286
1287 // Create the projection histogram
1288 TString pname = name;
1289 if (pname == "_px") {
1290 pname = GetName();
1291 pname.Append("_px");
1292 }
1293 TH1D *h1;
1294 const TArrayD *bins = fXaxis.GetXbins();
1295 if (bins->fN == 0) {
1296 h1 = new TH1D(pname,GetTitle(),nx,fXaxis.GetXmin(),fXaxis.GetXmax());
1297 } else {
1298 h1 = new TH1D(pname,GetTitle(),nx,bins->fArray);
1299 }
1300 Bool_t computeErrors = kFALSE;
1301 Bool_t cequalErrors = kFALSE;
1302 Bool_t binEntries = kFALSE;
1303 Bool_t binWeight = kFALSE;
1304 if (opt.Contains("b")) binEntries = kTRUE;
1305 if (opt.Contains("e")) computeErrors = kTRUE;
1306 if (opt.Contains("w")) binWeight = kTRUE;
1307 if (opt.Contains("c=e")) {cequalErrors = kTRUE; computeErrors=kFALSE;}
1308 if (computeErrors || binWeight || (binEntries && fBinSumw2.fN) ) h1->Sumw2();
1309
1310 // Fill the projected histogram
1311 Double_t cont;
1312 for (Int_t bin =0;bin<=nx+1;bin++) {
1313
1314 if (binEntries) cont = GetBinEntries(bin);
1315 else if (cequalErrors) cont = GetBinError(bin);
1316 else if (binWeight) cont = fArray[bin]; // bin content * bin entries
1317 else cont = GetBinContent(bin); // default case
1318
1319 h1->SetBinContent(bin ,cont);
1320
1321 // if option E projected histogram errors are same as profile
1322 if (computeErrors ) h1->SetBinError(bin , GetBinError(bin) );
1323 // in case of option W bin error is deduced from bin sum of z**2 values of profile
1324 // this is correct only if the profile is filled with weights =1
1325 if (binWeight) h1->GetSumw2()->fArray[bin] = fSumw2.fArray[bin];
1326 // in case of bin entries and profile is weighted, we need to set also the bin error
1327 if (binEntries && fBinSumw2.fN ) {
1328 R__ASSERT( h1->GetSumw2() );
1329 h1->GetSumw2()->fArray[bin] = fBinSumw2.fArray[bin];
1330 }
1331
1332 }
1333
1334 // Copy the axis attributes and the axis labels if needed.
1335 h1->GetXaxis()->ImportAttributes(this->GetXaxis());
1336 h1->GetYaxis()->ImportAttributes(this->GetYaxis());
1337 THashList* labels=this->GetXaxis()->GetLabels();
1338 if (labels) {
1339 TIter iL(labels);
1340 TObjString* lb;
1341 Int_t i = 1;
1342 while ((lb=(TObjString*)iL())) {
1343 h1->GetXaxis()->SetBinLabel(i,lb->String().Data());
1344 i++;
1345 }
1346 }
1347
1349 return h1;
1350}
1351
1352////////////////////////////////////////////////////////////////////////////////
1353/// Replace current statistics with the values in array stats.
1354
1356{
1357 fTsumw = stats[0];
1358 fTsumw2 = stats[1];
1359 fTsumwx = stats[2];
1360 fTsumwx2 = stats[3];
1361 fTsumwy = stats[4];
1362 fTsumwy2 = stats[5];
1363}
1364
1365////////////////////////////////////////////////////////////////////////////////
1366/// Rebin this profile grouping ngroup bins together.
1367///
1368/// ## case 1 xbins=0
1369/// if newname is not blank a new temporary profile hnew is created.
1370/// else the current profile is modified (default)
1371/// The parameter ngroup indicates how many bins of this have to me merged
1372/// into one bin of hnew
1373/// If the original profile has errors stored (via Sumw2), the resulting
1374/// profile has new errors correctly calculated.
1375///
1376/// examples: if hp is an existing TProfile histogram with 100 bins
1377///
1378/// ~~~ {.cpp}
1379/// hp->Rebin(); //merges two bins in one in hp: previous contents of hp are lost
1380/// hp->Rebin(5); //merges five bins in one in hp
1381/// TProfile *hnew = hp->Rebin(5,"hnew"); // creates a new profile hnew
1382/// //merging 5 bins of hp in one bin
1383/// ~~~
1384///
1385/// NOTE: If ngroup is not an exact divider of the number of bins,
1386/// the top limit of the rebinned profile is changed
1387/// to the upper edge of the bin=newbins*ngroup and the corresponding
1388/// bins are added to the overflow bin.
1389/// Statistics will be recomputed from the new bin contents.
1390///
1391/// ## case 2 xbins!=0
1392/// a new profile is created (you should specify newname).
1393/// The parameter ngroup is the number of variable size bins in the created profile
1394/// The array xbins must contain ngroup+1 elements that represent the low-edge
1395/// of the bins.
1396/// The data of the old bins are added to the new bin which contains the bin center
1397/// of the old bins. It is possible that information from the old binning are attached
1398/// to the under-/overflow bins of the new binning.
1399///
1400/// examples: if hp is an existing TProfile with 100 bins
1401///
1402/// ~~~ {.cpp}
1403/// Double_t xbins[25] = {...} array of low-edges (xbins[25] is the upper edge of last bin
1404/// hp->Rebin(24,"hpnew",xbins); //creates a new variable bin size profile hpnew
1405/// ~~~
1406
1407TH1 *TProfile::Rebin(Int_t ngroup, const char*newname, const Double_t *xbins)
1408{
1409 Int_t nbins = fXaxis.GetNbins();
1412 if ((ngroup <= 0) || (ngroup > nbins)) {
1413 Error("Rebin", "Illegal value of ngroup=%d",ngroup);
1414 return nullptr;
1415 }
1416 if (!newname && xbins) {
1417 Error("Rebin","if xbins is specified, newname must be given");
1418 return nullptr;
1419 }
1420
1421 Int_t newbins = nbins/ngroup;
1422 if (!xbins) {
1423 Int_t nbg = nbins/ngroup;
1424 if (nbg*ngroup != nbins) {
1425 Warning("Rebin", "ngroup=%d must be an exact divider of nbins=%d",ngroup,nbins);
1426 }
1427 }
1428 else {
1429 // in the case of xbins given (rebinning in variable bins) ngroup is the new number of bins.
1430 // and number of grouped bins is not constant.
1431 // when looping for setting the contents for the new histogram we
1432 // need to loop on all bins of original histogram. Set then ngroup=nbins
1433 newbins = ngroup;
1434 ngroup = nbins;
1435 }
1436
1437 // Save old bin contents into a new array
1438 Double_t *oldBins = new Double_t[nbins+2];
1439 Double_t *oldCount = new Double_t[nbins+2];
1440 Double_t *oldErrors = new Double_t[nbins+2];
1441 Double_t *oldBinw2 = (fBinSumw2.fN ? new Double_t[nbins+2] : nullptr );
1442 Int_t bin, i;
1443 Double_t *cu1 = GetW();
1444 Double_t *er1 = GetW2();
1445 Double_t *en1 = GetB();
1446 Double_t *ew1 = GetB2();
1447
1448 for (bin=0;bin<=nbins+1;bin++) {
1449 oldBins[bin] = cu1[bin];
1450 oldCount[bin] = en1[bin];
1451 oldErrors[bin] = er1[bin];
1452 if (ew1 && fBinSumw2.fN) oldBinw2[bin] = ew1[bin];
1453 }
1454
1455 // create a clone of the old histogram if newname is specified
1456 TProfile *hnew = this;
1457 if ((newname && strlen(newname) > 0) || xbins) {
1458 hnew = (TProfile*)Clone(newname);
1459 }
1460
1461 // in case of ngroup not an excat divider of nbins,
1462 // top limit is changed (see NOTE in method comment)
1463 if(!xbins && (newbins*ngroup != nbins)) {
1464 xmax = fXaxis.GetBinUpEdge(newbins*ngroup);
1465 hnew->fTsumw = 0; //stats must be reset because top bins will be moved to overflow bin
1466 }
1467
1468 // set correctly the axis and resizes the bin arrays
1469 if(!xbins && (fXaxis.GetXbins()->GetSize() > 0)){
1470 // for rebinning of variable bins in a constant group
1471 Double_t *bins = new Double_t[newbins+1];
1472 for(i = 0; i <= newbins; ++i) bins[i] = fXaxis.GetBinLowEdge(1+i*ngroup);
1473 hnew->SetBins(newbins,bins); //this also changes the bin array's
1474 delete [] bins;
1475 } else if (xbins) {
1476 // when rebinning in variable bins
1477 hnew->SetBins(newbins,xbins);
1478 } else {
1479 hnew->SetBins(newbins,xmin,xmax);
1480 }
1481
1482 // merge bin contents ignoring now underflow/overflows
1483 if (fBinSumw2.fN) hnew->Sumw2();
1484
1485 // Start merging only once the new lowest edge is reached
1486 Int_t startbin = 1;
1487 const Double_t newxmin = hnew->GetXaxis()->GetBinLowEdge(1);
1488 while( fXaxis.GetBinCenter(startbin) < newxmin && startbin <= nbins ) {
1489 startbin++;
1490 }
1491
1492 Double_t *cu2 = hnew->GetW();
1493 Double_t *er2 = hnew->GetW2();
1494 Double_t *en2 = hnew->GetB();
1495 Double_t *ew2 = hnew->GetB2();
1496 Int_t oldbin = startbin;
1497 Double_t binContent, binCount, binError, binSumw2;
1498 for (bin = 1;bin<=newbins;bin++) {
1499 binContent = 0;
1500 binCount = 0;
1501 binError = 0;
1502 binSumw2 = 0;
1503
1504 //for xbins != 0: ngroup == nbins
1505 Int_t imax = ngroup;
1506 Double_t xbinmax = hnew->GetXaxis()->GetBinUpEdge(bin);
1507 for (i=0;i<ngroup;i++) {
1508 if((hnew == this && (oldbin+i > nbins)) ||
1509 (hnew != this && (fXaxis.GetBinCenter(oldbin+i) > xbinmax)))
1510 {
1511 imax = i;
1512 break;
1513 }
1514
1515 binContent += oldBins[oldbin+i];
1516 binCount += oldCount[oldbin+i];
1517 binError += oldErrors[oldbin+i];
1518 if (fBinSumw2.fN) binSumw2 += oldBinw2[oldbin+i];
1519 }
1520
1521 cu2[bin] = binContent;
1522 er2[bin] = binError;
1523 en2[bin] = binCount;
1524 if (fBinSumw2.fN) ew2[bin] = binSumw2;
1525 oldbin += imax;
1526 }
1527 // set bin statistics for underflow bin
1528 binContent = 0;
1529 binCount = 0;
1530 binError = 0;
1531 binSumw2 = 0;
1532 for(i=0;i<startbin;i++)
1533 {
1534 binContent += oldBins[i];
1535 binCount += oldCount[i];
1536 binError += oldErrors[i];
1537 if (fBinSumw2.fN) binSumw2 += oldBinw2[i];
1538 }
1539 hnew->fArray[0] = binContent;
1540 hnew->fBinEntries[0] = binCount;
1541 hnew->fSumw2[0] = binError;
1542 if ( fBinSumw2.fN ) hnew->fBinSumw2[0] = binSumw2;
1543
1544 // set bin statistics for overflow bin
1545 binContent = 0;
1546 binCount = 0;
1547 binError = 0;
1548 binSumw2 = 0;
1549 for(i=oldbin;i<=nbins+1;i++)
1550 {
1551 binContent += oldBins[i];
1552 binCount += oldCount[i];
1553 binError += oldErrors[i];
1554 if (fBinSumw2.fN) binSumw2 += oldBinw2[i];
1555 }
1556 hnew->fArray[newbins+1] = binContent;
1557 hnew->fBinEntries[newbins+1] = binCount;
1558 hnew->fSumw2[newbins+1] = binError;
1559 if ( fBinSumw2.fN ) hnew->fBinSumw2[newbins+1] = binSumw2;
1560
1561
1562 delete [] oldBins;
1563 delete [] oldCount;
1564 delete [] oldErrors;
1565 if (oldBinw2) delete [] oldBinw2;
1566 return hnew;
1567}
1568
1569////////////////////////////////////////////////////////////////////////////////
1570/// Profile histogram is resized along x axis such that x is in the axis range.
1571/// The new axis limits are recomputed by doubling iteratively
1572/// the current axis range until the specified value x is within the limits.
1573/// The algorithm makes a copy of the histogram, then loops on all bins
1574/// of the old histogram to fill the extended histogram.
1575/// Takes into account errors (Sumw2) if any.
1576/// The axis must be extendable before invoking this function.
1577///
1578/// Ex: `h->GetXaxis()->SetCanExtend(kTRUE)`
1579
1581{
1582 TProfile* hold = TProfileHelper::ExtendAxis(this, x, axis);
1583 if ( hold ) {
1584 fTsumwy = hold->fTsumwy;
1585 fTsumwy2 = hold->fTsumwy2;
1586
1587 delete hold;
1588 }
1589}
1590
1591////////////////////////////////////////////////////////////////////////////////
1592/// Reset contents of a Profile histogram.
1593
1595{
1598 fBinSumw2.Reset();
1599 TString opt = option;
1600 opt.ToUpper();
1601 if (opt.Contains("ICE") && !opt.Contains("S")) return;
1602 fTsumwy = 0;
1603 fTsumwy2 = 0;
1604}
1605
1606////////////////////////////////////////////////////////////////////////////////
1607/// Save primitive as a C++ statement(s) on output stream out.
1608
1609void TProfile::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1610{
1611 //Note the following restrictions in the code generated:
1612 // - variable bin size not implemented
1613 // - SetErrorOption not implemented
1614
1615 Bool_t nonEqiX = kFALSE;
1616 Int_t i;
1617 // Check if the profile has equidistant X bins or not. If not, we
1618 // create an array holding the bins.
1619 if (GetXaxis()->GetXbins()->fN && GetXaxis()->GetXbins()->fArray) {
1620 nonEqiX = kTRUE;
1621 out << " Double_t xAxis[" << GetXaxis()->GetXbins()->fN
1622 << "] = {";
1623 for (i = 0; i < GetXaxis()->GetXbins()->fN; i++) {
1624 if (i != 0) out << ", ";
1625 out << GetXaxis()->GetXbins()->fArray[i];
1626 }
1627 out << "}; " << std::endl;
1628 }
1629
1630 char quote = '"';
1631 out<<" "<<std::endl;
1632 out<<" "<<ClassName()<<" *";
1633
1634 //histogram pointer has by default the histogram name.
1635 //however, in case histogram has no directory, it is safer to add a incremental suffix
1636 static Int_t hcounter = 0;
1637 TString histName = GetName();
1638 if (!fDirectory) {
1639 hcounter++;
1640 histName += "__";
1641 histName += hcounter;
1642 }
1643 const char *hname = histName.Data();
1644
1645 out<<hname<<" = new "<<ClassName()<<"("<<quote<<GetName()<<quote<<","<<quote<<GetTitle()<<quote
1646 <<","<<GetXaxis()->GetNbins();
1647 if (nonEqiX)
1648 out << ", xAxis";
1649 else
1650 out << "," << GetXaxis()->GetXmin()
1651 << "," << GetXaxis()->GetXmax()
1652 <<","<<quote<<GetErrorOption()<<quote<<");"<<std::endl;
1653
1654 // save bin entries
1655 Int_t bin;
1656 for (bin=0;bin<fNcells;bin++) {
1657 Double_t bi = GetBinEntries(bin);
1658 if (bi) {
1659 out<<" "<<hname<<"->SetBinEntries("<<bin<<","<<bi<<");"<<std::endl;
1660 }
1661 }
1662 //save bin contents
1663 for (bin=0;bin<fNcells;bin++) {
1664 Double_t bc = fArray[bin];
1665 if (bc) {
1666 out<<" "<<hname<<"->SetBinContent("<<bin<<","<<bc<<");"<<std::endl;
1667 }
1668 }
1669 // save bin errors
1670 if (fSumw2.fN) {
1671 for (bin=0;bin<fNcells;bin++) {
1672 Double_t be = TMath::Sqrt(fSumw2.fArray[bin]);
1673 if (be) {
1674 out<<" "<<hname<<"->SetBinError("<<bin<<","<<be<<");"<<std::endl;
1675 }
1676 }
1677 }
1678
1679 TH1::SavePrimitiveHelp(out, hname, option);
1680}
1681
1682////////////////////////////////////////////////////////////////////////////////
1683/// Multiply this profile by a constant c1.
1684///
1685/// `this = c1*this`
1686///
1687/// This function uses the services of TProfile::Add
1688
1690{
1692}
1693
1694////////////////////////////////////////////////////////////////////////////////
1695/// Set the number of entries in bin.
1696
1698{
1699 TProfileHelper::SetBinEntries(this, bin, w);
1700}
1701
1702////////////////////////////////////////////////////////////////////////////////
1703/// Redefine x axis parameters.
1704
1706{
1707 fXaxis.Set(nx,xmin,xmax);
1708 fNcells = nx+2;
1710}
1711
1712////////////////////////////////////////////////////////////////////////////////
1713/// Redefine x axis parameters.
1714
1715void TProfile::SetBins(Int_t nx, const Double_t *xbins)
1716{
1717 fXaxis.Set(nx,xbins);
1718 fNcells = nx+2;
1720}
1721
1722////////////////////////////////////////////////////////////////////////////////
1723/// Set total number of bins including under/overflow.
1724/// Reallocate bin contents array
1725
1727{
1730}
1731
1732////////////////////////////////////////////////////////////////////////////////
1733/// Set the buffer size in units of 8 bytes (double).
1734
1736{
1737 if (fBuffer) {
1738 BufferEmpty();
1739 delete [] fBuffer;
1740 fBuffer = nullptr;
1741 }
1742 if (buffersize <= 0) {
1743 fBufferSize = 0;
1744 return;
1745 }
1746 if (buffersize < 100) buffersize = 100;
1747 fBufferSize = 1 + 3*buffersize;
1749 memset(fBuffer,0,sizeof(Double_t)*fBufferSize);
1750}
1751
1752////////////////////////////////////////////////////////////////////////////////
1753/// Set option to compute profile errors.
1754///
1755/// The computation of the bin errors is based on the parameter option:
1756///
1757/// -' ' (Default) The bin errors are the standard error on the mean of the bin profiled values (Y),
1758/// i.e. the standard error of the bin contents.
1759/// Note that if TProfile::Approximate() is called, an approximation is used when
1760/// the spread in Y is 0 and the number of bin entries is > 0
1761/// -'s' The bin errors are the standard deviations of the Y bin values
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/// -'i' Errors are as in default case (standard errors of the bin contents)
1765/// The only difference is for the case when the spread in Y is zero.
1766/// In this case for N > 0 the error is 1./SQRT(12.*N)
1767/// -'g' Errors are 1./SQRT(W) for W not equal to 0 and 0 for W = 0.
1768/// W is the sum in the bin of the weights of the profile.
1769/// This option is for combining measurements y +/- dy,
1770/// and the profile is filled with values y and weights w = 1/dy**2
1771///
1772/// See TProfile::BuildOptions for a detailed explanation of all options
1773
1775{
1777}
1778
1779////////////////////////////////////////////////////////////////////////////////
1780/// Stream an object of class TProfile.
1781
1783{
1784 if (R__b.IsReading()) {
1785 UInt_t R__s, R__c;
1786 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1787 if (R__v > 2) {
1788 R__b.ReadClassBuffer(TProfile::Class(), this, R__v, R__s, R__c);
1789 return;
1790 }
1791 //====process old versions before automatic schema evolution
1792 TH1D::Streamer(R__b);
1793 fBinEntries.Streamer(R__b);
1794 Int_t errorMode;
1795 R__b >> errorMode;
1796 fErrorMode = (EErrorType)errorMode;
1797 if (R__v < 2) {
1799 R__b >> ymin; fYmin = ymin;
1800 R__b >> ymax; fYmax = ymax;
1801 } else {
1802 R__b >> fYmin;
1803 R__b >> fYmax;
1804 }
1805 R__b.CheckByteCount(R__s, R__c, TProfile::IsA());
1806 //====end of old versions
1807
1808 } else {
1809 R__b.WriteClassBuffer(TProfile::Class(),this);
1810 }
1811}
1812////////////////////////////////////////////////////////////////////////////////
1813/// Create/delete structure to store sum of squares of weights per bin.
1814///
1815/// This is needed to compute the correct statistical quantities
1816/// of a profile filled with weights
1817///
1818/// This function is automatically called when the histogram is created
1819/// if the static function TH1::SetDefaultSumw2 has been called before.
1820/// If flag is false the structure is deleted
1821
1823{
1824 TProfileHelper::Sumw2(this, flag);
1825}
#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: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
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
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:886
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:794
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:680
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:214
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:3648
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=nullptr)
Evaluate function with given coordinates and parameters.
Definition TF1.cxx:1470
static Bool_t RejectedPoint()
See TF1::RejectPoint above.
Definition TF1.cxx:3657
virtual Bool_t IsInside(const Double_t *x) const
return kTRUE if the point is inside the function range
Definition TF1.h:604
1-D histogram with a double per channel (see TH1 documentation)}
Definition TH1.h:620
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow Reallocate bin contents array.
Definition TH1.cxx:10221
void Copy(TObject &hnew) const override
Copy this to newth1.
Definition TH1.cxx:10203
void Streamer(TBuffer &) override
Stream a class object.
TH1D()
Constructor.
Definition TH1.cxx:10122
void AddBinContent(Int_t bin) override
Increment bin content by 1.
Definition TH1.h:632
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
Double_t * fBuffer
[fBufferSize] entry buffer
Definition TH1.h:107
Int_t fNcells
Number of bins(1D), cells (2D) +U/Overflows.
Definition TH1.h:88
Double_t fTsumw
Total Sum of weights.
Definition TH1.h:95
Double_t fTsumw2
Total Sum of squares of weights.
Definition TH1.h:96
static TClass * Class()
Double_t fTsumwx2
Total Sum of weight*X*X.
Definition TH1.h:98
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition TH1.cxx:8980
@ kIsNotW
Histogram is forced to be not weighted even when the histogram is filled with weighted.
Definition TH1.h:170
virtual Bool_t CanExtendAllAxes() const
Returns true if all axes are extendable.
Definition TH1.cxx:6625
TDirectory * fDirectory
! Pointer to directory holding this histogram
Definition TH1.h:108
TAxis * GetXaxis()
Definition TH1.h:322
virtual Int_t GetNbinsX() const
Definition TH1.h:295
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:400
Int_t fBufferSize
fBuffer size
Definition TH1.h:106
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
Definition TH1.cxx:9123
TAxis * GetYaxis()
Definition TH1.h:323
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:7296
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:401
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:9139
@ kNstat
Size of statistics data (up to TProfile3D)
Definition TH1.h:182
Double_t fEntries
Number of entries.
Definition TH1.h:94
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5032
virtual TArrayD * GetSumw2()
Definition TH1.h:311
TAxis fXaxis
X axis descriptor.
Definition TH1.h:89
TArrayD fSumw2
Array of sum of squares of weights.
Definition TH1.h:103
Bool_t GetStatOverflowsBehaviour() const
Definition TH1.h:151
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH1.cxx:2734
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:8937
virtual void SetEntries(Double_t n)
Definition TH1.h:387
Double_t fTsumwx
Total Sum of weight*X.
Definition TH1.h:97
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:357
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:457
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1015
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:791
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:821
virtual Double_t GetBinEffectiveEntries(Int_t bin) const
Return bin effective entries for a weighted filled Profile histogram.
Definition TProfile.cxx:850
Bool_t Divide(TF1 *h1, Double_t c1=1) override
Performs the operation: this = this/(c1*f1).
Definition TProfile.cxx:450
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:420
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:834
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:970
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:335
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:980
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:885
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:321
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:918
TClass * IsA() const override
Definition TProfile.h:138
Option_t * GetErrorOption() const
Return option to compute profile errors.
Definition TProfile.cxx:893
void LabelsOption(Option_t *option="h", Option_t *axis="X") override
Set option(s) to draw axis with labels.
Definition TProfile.cxx:998
Double_t * GetW2()
Definition TProfile.h:67
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1170
const char * Data() const
Definition TString.h:380
void ToUpper()
Change string to upper case.
Definition TString.cxx:1183
TString & Append(const char *cs)
Definition TString.h:576
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
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:892
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
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