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