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