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