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