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 <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 
126 TProfile::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 
138 TProfile::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 
150 TProfile::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 
162 TProfile::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 
180 TProfile::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;
236  fScaling = kFALSE;
237  fTsumwy = fTsumwy2 = 0;
238 
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Copy constructor.
243 
244 TProfile::TProfile(const TProfile &profile) : TH1D()
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];
351  Double_t xmax = xmin;
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;
363  if (xmax >= fXaxis.GetXmax()) ExtendAxis(xmax,&fXaxis);
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 
419 void TProfile::Copy(TObject &obj) const
420 {
421  try {
422  TProfile & pobj = dynamic_cast<TProfile&>(obj);
423  TH1D::Copy(pobj);
425  fBinSumw2.Copy(pobj.fBinSumw2);
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
586  fEntries = fTsumw = fTsumw2 = fTsumwx = fTsumwx2 = 0;
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 
676 Int_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  Double_t x = fXaxis.GetBinCenter(bin);
693  fTsumw++;
694  fTsumw2++;
695  fTsumwx += x;
696  fTsumwx2 += x*x;
697  fTsumwy += y;
698  fTsumwy2 += y*y;
699  return bin;
700 }
701 
702 ////////////////////////////////////////////////////////////////////////////////
703 /// Fill a Profile histogram with weights.
704 
706 {
707  if (fBuffer) return BufferFill(x,y,w);
708 
709  Int_t bin;
710  if (fYmin != fYmax) {
711  if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
712  }
713 
714  Double_t u= w;
715  fEntries++;
716  bin =fXaxis.FindBin(x);
717  AddBinContent(bin, u*y);
718  fSumw2.fArray[bin] += u*y*y;
719  if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
720  if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
721  fBinEntries.fArray[bin] += u;
722  if (bin == 0 || bin > fXaxis.GetNbins()) {
723  if (!GetStatOverflowsBehaviour()) return -1;
724  }
725  fTsumw += u;
726  fTsumw2 += u*u;
727  fTsumwx += u*x;
728  fTsumwx2 += u*x*x;
729  fTsumwy += u*y;
730  fTsumwy2 += u*y*y;
731  return bin;
732 }
733 
734 ////////////////////////////////////////////////////////////////////////////////
735 /// Fill a Profile histogram with weights.
736 
737 Int_t TProfile::Fill(const char *namex, Double_t y, Double_t w)
738 {
739  Int_t bin;
740 
741  if (fYmin != fYmax) {
742  if (y <fYmin || y> fYmax || TMath::IsNaN(y) ) return -1;
743  }
744 
745  Double_t u= w; // (w > 0 ? w : -w);
746  fEntries++;
747  bin =fXaxis.FindBin(namex);
748  AddBinContent(bin, u*y);
749  fSumw2.fArray[bin] += u*y*y;
750  if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
751  if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
752  fBinEntries.fArray[bin] += u;
753  if (bin == 0 || bin > fXaxis.GetNbins()) {
754  if (!GetStatOverflowsBehaviour()) return -1;
755  }
756  Double_t x = fXaxis.GetBinCenter(bin);
757  fTsumw += u;
758  fTsumw2 += u*u;
759  fTsumwx += u*x;
760  fTsumwx2 += u*x*x;
761  fTsumwy += u*y;
762  fTsumwy2 += u*y*y;
763  return bin;
764 }
765 
766 ////////////////////////////////////////////////////////////////////////////////
767 /// Fill a Profile histogram with weights.
768 
769 void TProfile::FillN(Int_t ntimes, const Double_t *x, const Double_t *y, const Double_t *w, Int_t stride)
770 {
771  Int_t bin,i;
772  ntimes *= stride;
773  Int_t ifirst = 0;
774  //If a buffer is activated, fill buffer
775  // (note that this function must not be called from TH2::BufferEmpty)
776  if (fBuffer) {
777  for (i=0;i<ntimes;i+=stride) {
778  if (!fBuffer) break; // buffer can be deleted in BufferFill when is empty
779  if (w) BufferFill(x[i],y[i],w[i]);
780  else BufferFill(x[i], y[i], 1.);
781  }
782  // fill the remaining entries if the buffer has been deleted
783  if (i < ntimes && fBuffer==0)
784  ifirst = i; // start from i
785  else
786  return;
787  }
788 
789  for (i=ifirst;i<ntimes;i+=stride) {
790  if (fYmin != fYmax) {
791  if (y[i] <fYmin || y[i]> fYmax || TMath::IsNaN(y[i])) continue;
792  }
793 
794  Double_t u = (w) ? w[i] : 1; // (w[i] > 0 ? w[i] : -w[i]);
795  fEntries++;
796  bin =fXaxis.FindBin(x[i]);
797  AddBinContent(bin, u*y[i]);
798  fSumw2.fArray[bin] += u*y[i]*y[i];
799  if (!fBinSumw2.fN && u != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before accumulating the entries
800  if (fBinSumw2.fN) fBinSumw2.fArray[bin] += u*u;
801  fBinEntries.fArray[bin] += u;
802  if (bin == 0 || bin > fXaxis.GetNbins()) {
803  if (!GetStatOverflowsBehaviour()) continue;
804  }
805  fTsumw += u;
806  fTsumw2 += u*u;
807  fTsumwx += u*x[i];
808  fTsumwx2 += u*x[i]*x[i];
809  fTsumwy += u*y[i];
810  fTsumwy2 += u*y[i]*y[i];
811  }
812 }
813 
814 ////////////////////////////////////////////////////////////////////////////////
815 /// Return bin content of a Profile histogram.
816 
818 {
819  if (fBuffer) ((TProfile*)this)->BufferEmpty();
820 
821  if (bin < 0 || bin >= fNcells) return 0;
822  if (fBinEntries.fArray[bin] == 0) return 0;
823  if (!fArray) return 0;
824  return fArray[bin]/fBinEntries.fArray[bin];
825 }
826 
827 ////////////////////////////////////////////////////////////////////////////////
828 /// Return bin entries of a Profile histogram.
829 
831 {
832  if (fBuffer) ((TProfile*)this)->BufferEmpty();
833 
834  if (bin < 0 || bin >= fNcells) return 0;
835  return fBinEntries.fArray[bin];
836 }
837 
838 ////////////////////////////////////////////////////////////////////////////////
839 /// Return bin effective entries for a weighted filled Profile histogram.
840 /// In case of an unweighted profile, it is equivalent to the number of entries per bin
841 /// The effective entries is defined as the square of the sum of the weights divided by the
842 /// sum of the weights square.
843 /// TProfile::Sumw2() must be called before filling the profile with weights.
844 /// Only by calling this method the sum of the square of the weights per bin is stored.
845 
847 {
849 }
850 
851 ////////////////////////////////////////////////////////////////////////////////
852 /// Return bin error of a Profile histogram
853 ///
854 /// Computing errors: A moving field
855 ///
856 /// The computation of errors for a TProfile has evolved with the versions
857 /// of ROOT. The difficulty is in computing errors for bins with low statistics.
858 ///
859 /// - prior to version 3.00, we had no special treatment of low statistic bins.
860 /// As a result, these bins had huge errors. The reason is that the
861 /// expression eprim2 is very close to 0 (rounding problems) or 0.
862 /// - in version 3.00 (18 Dec 2000), the algorithm is protected for values of
863 /// eprim2 very small and the bin errors set to the average bin errors, following
864 /// recommendations from a group of users.
865 /// - in version 3.01 (19 Apr 2001), it is realized that the algorithm above
866 /// should be applied only to low statistic bins.
867 /// - in version 3.02 (26 Sep 2001), the same group of users recommend instead
868 /// to take two times the average error on all bins for these low
869 /// statistics bins giving a very small value for eprim2.
870 /// - in version 3.04 (Nov 2002), the algorithm is modified/protected for the case
871 /// when a TProfile is projected (ProjectionX). The previous algorithm
872 /// generated a N^2 problem when projecting a TProfile with a large number of
873 /// bins (eg 100000).
874 /// - in version 3.05/06, a new static function TProfile::Approximate
875 /// is introduced to enable or disable (default) the approximation.
876 ///
877 /// Ideas for improvements of this algorithm are welcome. No suggestions
878 /// received since our call for advice to roottalk in Jul 2002.
879 /// see for instance: http://root.cern.ch/root/roottalk/roottalk02/2916.html
880 
882 {
883  return TProfileHelper::GetBinError((TProfile*)this, bin);
884 }
885 
886 ////////////////////////////////////////////////////////////////////////////////
887 /// Return option to compute profile errors
888 
890 {
891  if (fErrorMode == kERRORSPREAD) return "s";
892  if (fErrorMode == kERRORSPREADI) return "i";
893  if (fErrorMode == kERRORSPREADG) return "g";
894  return "";
895 }
896 
897 ////////////////////////////////////////////////////////////////////////////////
898 /// fill the array stats from the contents of this profile.
899 ///
900 /// The array stats must be correctly dimensioned in the calling program.
901 ///
902 /// - stats[0] = sumw
903 /// - stats[1] = sumw2
904 /// - stats[2] = sumwx
905 /// - stats[3] = sumwx2
906 /// - stats[4] = sumwy
907 /// - stats[5] = sumwy2
908 ///
909 /// If no axis-subrange is specified (via TAxis::SetRange), the array stats
910 /// is simply a copy of the statistics quantities computed at filling time.
911 /// If a sub-range is specified, the function recomputes these quantities
912 /// from the bin contents in the current axis range.
913 
914 void TProfile::GetStats(Double_t *stats) const
915 {
916  if (fBuffer) ((TProfile*)this)->BufferEmpty();
917 
918  // Loop on bins
919  Int_t bin, binx;
920  if (fTsumw == 0 || fXaxis.TestBit(TAxis::kAxisRange)) {
921  for (bin=0;bin<6;bin++) stats[bin] = 0;
922  if (!fBinEntries.fArray) return;
923  Int_t firstBinX = fXaxis.GetFirst();
924  Int_t lastBinX = fXaxis.GetLast();
925  // include underflow/overflow if TH1::StatOverflows(kTRUE) in case no range is set on the axis
927  if (firstBinX == 1) firstBinX = 0;
928  if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1;
929  }
930  for (binx = firstBinX; binx <= lastBinX; binx++) {
931  Double_t w = fBinEntries.fArray[binx];
932  Double_t w2 = (fBinSumw2.fN ? fBinSumw2.fArray[binx] : w);
933  Double_t x = fXaxis.GetBinCenter(binx);
934  stats[0] += w;
935  stats[1] += w2;
936  stats[2] += w*x;
937  stats[3] += w*x*x;
938  stats[4] += fArray[binx];
939  stats[5] += fSumw2.fArray[binx];
940  }
941  } else {
942  if (fTsumwy == 0 && fTsumwy2 == 0) {
943  //this case may happen when processing TProfiles with version <=3
944  TProfile *p = (TProfile*)this; // cheating with const
945  for (binx=fXaxis.GetFirst();binx<=fXaxis.GetLast();binx++) {
946  p->fTsumwy += fArray[binx];
947  p->fTsumwy2 += fSumw2.fArray[binx];
948  }
949  }
950  stats[0] = fTsumw;
951  stats[1] = fTsumw2;
952  stats[2] = fTsumwx;
953  stats[3] = fTsumwx2;
954  stats[4] = fTsumwy;
955  stats[5] = fTsumwy2;
956  }
957 }
958 
959 ////////////////////////////////////////////////////////////////////////////////
960 /// Reduce the number of bins for this axis to the number of bins having a label.
961 
963 {
964  TProfileHelper::LabelsDeflate(this, option);
965 }
966 
967 ////////////////////////////////////////////////////////////////////////////////
968 /// Double the number of bins for axis.
969 /// Refill histogram
970 /// This function is called by TAxis::FindBin(const char *label)
971 
973 {
974  TProfileHelper::LabelsInflate(this, options);
975 }
976 
977 ////////////////////////////////////////////////////////////////////////////////
978 /// Set option(s) to draw axis with labels.
979 ///
980 /// option might have the following values:
981 ///
982 /// - "a" sort by alphabetic order
983 /// - ">" sort by decreasing values
984 /// - "<" sort by increasing values
985 /// - "h" draw labels horizontal
986 /// - "v" draw labels vertical
987 /// - "u" draw labels up (end of label right adjusted)
988 /// - "d" draw labels down (start of label left adjusted)
989 
990 void TProfile::LabelsOption(Option_t *option, Option_t * /*ax */)
991 {
992  THashList *labels = fXaxis.GetLabels();
993  if (!labels) {
994  Warning("LabelsOption","Cannot sort. No labels");
995  return;
996  }
997  TString opt = option;
998  opt.ToLower();
999  if (opt.Contains("h")) {
1004  }
1005  if (opt.Contains("v")) {
1010  }
1011  if (opt.Contains("u")) {
1016  }
1017  if (opt.Contains("d")) {
1022  }
1023  Int_t sort = -1;
1024  if (opt.Contains("a")) sort = 0;
1025  if (opt.Contains(">")) sort = 1;
1026  if (opt.Contains("<")) sort = 2;
1027  if (sort < 0) return;
1028 
1029  Int_t n = TMath::Min(fXaxis.GetNbins(), labels->GetSize());
1030  Int_t *a = new Int_t[n+2];
1031  Int_t i,j;
1032  Double_t *cont = new Double_t[n+2];
1033  Double_t *sumw = new Double_t[n+2];
1034  Double_t *errors = new Double_t[n+2];
1035  Double_t *ent = new Double_t[n+2];
1036  THashList *labold = new THashList(labels->GetSize(),1);
1037  TIter nextold(labels);
1038  TObject *obj;
1039  while ((obj=nextold())) {
1040  labold->Add(obj);
1041  }
1042  labels->Clear();
1043  if (sort > 0) {
1044  //---sort by values of bins
1045  for (i=1;i<=n;i++) {
1046  sumw[i-1] = fArray[i];
1047  errors[i-1] = fSumw2.fArray[i];
1048  ent[i-1] = fBinEntries.fArray[i];
1049  if (fBinEntries.fArray[i] == 0) cont[i-1] = 0;
1050  else cont[i-1] = fArray[i]/fBinEntries.fArray[i];
1051  }
1052  if (sort ==1) TMath::Sort(n,cont,a,kTRUE); //sort by decreasing values
1053  else TMath::Sort(n,cont,a,kFALSE); //sort by increasing values
1054  for (i=1;i<=n;i++) {
1055  fArray[i] = sumw[a[i-1]];
1056  fSumw2.fArray[i] = errors[a[i-1]];
1057  fBinEntries.fArray[i] = ent[a[i-1]];
1058  }
1059  for (i=1;i<=n;i++) {
1060  obj = labold->At(a[i-1]);
1061  labels->Add(obj);
1062  obj->SetUniqueID(i);
1063  }
1064  } else {
1065  //---alphabetic sort
1066  const UInt_t kUsed = 1<<18;
1067  TObject *objk=0;
1068  a[0] = 0;
1069  a[n+1] = n+1;
1070  for (i=1;i<=n;i++) {
1071  const char *label = "zzzzzzzzzzzz";
1072  for (j=1;j<=n;j++) {
1073  obj = labold->At(j-1);
1074  if (!obj) continue;
1075  if (obj->TestBit(kUsed)) continue;
1076  //use strcasecmp for case non-sensitive sort (may be an option)
1077  if (strcmp(label,obj->GetName()) < 0) continue;
1078  objk = obj;
1079  a[i] = j;
1080  label = obj->GetName();
1081  }
1082  if (objk) {
1083  objk->SetUniqueID(i);
1084  labels->Add(objk);
1085  objk->SetBit(kUsed);
1086  }
1087  }
1088  for (i=1;i<=n;i++) {
1089  obj = labels->At(i-1);
1090  if (!obj) continue;
1091  obj->ResetBit(kUsed);
1092  }
1093 
1094  for (i=1;i<=n;i++) {
1095  sumw[i] = fArray[a[i]];
1096  errors[i] = fSumw2.fArray[a[i]];
1097  ent[i] = fBinEntries.fArray[a[i]];
1098  }
1099  for (i=1;i<=n;i++) {
1100  fArray[i] = sumw[i];
1101  fSumw2.fArray[i] = errors[i];
1102  fBinEntries.fArray[i] = ent[i];
1103  }
1104  }
1105  delete labold;
1106  if (a) delete [] a;
1107  if (sumw) delete [] sumw;
1108  if (cont) delete [] cont;
1109  if (errors) delete [] errors;
1110  if (ent) delete [] ent;
1111 }
1112 
1113 ////////////////////////////////////////////////////////////////////////////////
1114 ///Merge all histograms in the collection in this histogram.
1115 ///
1116 /// This function computes the min/max for the x axis,
1117 /// compute a new number of bins, if necessary,
1118 /// add bin contents, errors and statistics.
1119 /// If overflows are present and limits are different the function will fail.
1120 /// The function returns the total number of entries in the result histogram
1121 /// if the merge is successfull, -1 otherwise.
1122 ///
1123 /// IMPORTANT remark. The axis x may have different number
1124 /// of bins and different limits, BUT the largest bin width must be
1125 /// a multiple of the smallest bin width and the upper limit must also
1126 /// be a multiple of the bin width.
1127 
1129 {
1130  return TProfileHelper::Merge(this, li);
1131 }
1132 
1133 ////////////////////////////////////////////////////////////////////////////////
1134 /// Performs the operation: this = this*c1*f1
1135 ///
1136 /// The function return kFALSE if the Multiply operation failed
1137 
1139 {
1140 
1141  if (!f1) {
1142  Error("Multiply","Attempt to multiply by a null function");
1143  return kFALSE;
1144  }
1145 
1146  Int_t nbinsx = GetNbinsX();
1147 
1148  //- Add statistics
1149  Double_t xx[1], cf1, ac1 = TMath::Abs(c1);
1150  Double_t s1[10];
1151  Int_t i;
1152  for (i=0;i<10;i++) {s1[i] = 0;}
1153  PutStats(s1);
1154 
1155  SetMinimum();
1156  SetMaximum();
1157 
1158  //- Loop on bins (including underflows/overflows)
1159  Int_t bin;
1160  for (bin=0;bin<=nbinsx+1;bin++) {
1161  xx[0] = fXaxis.GetBinCenter(bin);
1162  if (!f1->IsInside(xx)) continue;
1164  cf1 = f1->EvalPar(xx);
1165  if (TF1::RejectedPoint()) continue;
1166  fArray[bin] *= c1*cf1;
1167  //see http://savannah.cern.ch/bugs/?func=detailitem&item_id=14851
1168  //fSumw2.fArray[bin] *= c1*c1*cf1*cf1;
1169  fSumw2.fArray[bin] *= ac1*cf1*cf1;
1170  //fBinEntries.fArray[bin] *= ac1*TMath::Abs(cf1);
1171  }
1172  return kTRUE;
1173 }
1174 
1175 ////////////////////////////////////////////////////////////////////////////////
1176 /// Multiply this profile by h1.
1177 ///
1178 /// `this = this*h1`
1179 
1181 {
1182  Error("Multiply","Multiplication of profile histograms not implemented");
1183  return kFALSE;
1184 }
1185 
1186 
1187 ////////////////////////////////////////////////////////////////////////////////
1188 /// Replace contents of this profile by multiplication of h1 by h2.
1189 ///
1190 /// `this = (c1*h1)*(c2*h2)`
1191 
1193 {
1194  Error("Multiply","Multiplication of profile histograms not implemented");
1195  return kFALSE;
1196 }
1197 
1198 ////////////////////////////////////////////////////////////////////////////////
1199 /// Project this profile into a 1-D histogram along X
1200 ///
1201 /// The projection is always of the type TH1D.
1202 ///
1203 /// - if option "E" is specified the errors of the projected histogram are computed and set
1204 /// to be equal to the errors of the profile.
1205 /// Option "E" is defined as the default one in the header file.
1206 /// - if option "" is specified the histogram errors are simply the sqrt of its content
1207 /// - if option "B" is specified, the content of bin of the returned histogram
1208 /// will be equal to the GetBinEntries(bin) of the profile,
1209 /// otherwise (default) it will be equal to GetBinContent(bin)
1210 /// - if option "C=E" the bin contents of the projection are set to the
1211 /// bin errors of the profile
1212 /// - if option "W" is specified the bin content of the projected histogram is set to the
1213 /// product of the bin content of the profile and the entries.
1214 /// With this option the returned histogram will be equivalent to the one obtained by
1215 /// filling directly a TH1D using the 2-nd value as a weight.
1216 /// This makes sense only for profile filled with weights =1. If not, the error of the
1217 /// projected histogram obtained with this option will not be correct.
1218 
1219 TH1D *TProfile::ProjectionX(const char *name, Option_t *option) const
1220 {
1221 
1222  TString opt = option;
1223  opt.ToLower();
1224  Int_t nx = fXaxis.GetNbins();
1225 
1226  // Create the projection histogram
1227  TString pname = name;
1228  if (pname == "_px") {
1229  pname = GetName();
1230  pname.Append("_px");
1231  }
1232  TH1D *h1;
1233  const TArrayD *bins = fXaxis.GetXbins();
1234  if (bins->fN == 0) {
1235  h1 = new TH1D(pname,GetTitle(),nx,fXaxis.GetXmin(),fXaxis.GetXmax());
1236  } else {
1237  h1 = new TH1D(pname,GetTitle(),nx,bins->fArray);
1238  }
1239  Bool_t computeErrors = kFALSE;
1240  Bool_t cequalErrors = kFALSE;
1241  Bool_t binEntries = kFALSE;
1242  Bool_t binWeight = kFALSE;
1243  if (opt.Contains("b")) binEntries = kTRUE;
1244  if (opt.Contains("e")) computeErrors = kTRUE;
1245  if (opt.Contains("w")) binWeight = kTRUE;
1246  if (opt.Contains("c=e")) {cequalErrors = kTRUE; computeErrors=kFALSE;}
1247  if (computeErrors || binWeight || (binEntries && fBinSumw2.fN) ) h1->Sumw2();
1248 
1249  // Fill the projected histogram
1250  Double_t cont;
1251  for (Int_t bin =0;bin<=nx+1;bin++) {
1252 
1253  if (binEntries) cont = GetBinEntries(bin);
1254  else if (cequalErrors) cont = GetBinError(bin);
1255  else if (binWeight) cont = fArray[bin]; // bin content * bin entries
1256  else cont = GetBinContent(bin); // default case
1257 
1258  h1->SetBinContent(bin ,cont);
1259 
1260  // if option E projected histogram errors are same as profile
1261  if (computeErrors ) h1->SetBinError(bin , GetBinError(bin) );
1262  // in case of option W bin error is deduced from bin sum of z**2 values of profile
1263  // this is correct only if the profile is filled with weights =1
1264  if (binWeight) h1->GetSumw2()->fArray[bin] = fSumw2.fArray[bin];
1265  // in case of bin entries and profile is weighted, we need to set also the bin error
1266  if (binEntries && fBinSumw2.fN ) {
1267  R__ASSERT( h1->GetSumw2() );
1268  h1->GetSumw2()->fArray[bin] = fBinSumw2.fArray[bin];
1269  }
1270 
1271  }
1272 
1273  // Copy the axis attributes and the axis labels if needed.
1274  h1->GetXaxis()->ImportAttributes(this->GetXaxis());
1275  h1->GetYaxis()->ImportAttributes(this->GetYaxis());
1276  THashList* labels=this->GetXaxis()->GetLabels();
1277  if (labels) {
1278  TIter iL(labels);
1279  TObjString* lb;
1280  Int_t i = 1;
1281  while ((lb=(TObjString*)iL())) {
1282  h1->GetXaxis()->SetBinLabel(i,lb->String().Data());
1283  i++;
1284  }
1285  }
1286 
1288  return h1;
1289 }
1290 
1291 ////////////////////////////////////////////////////////////////////////////////
1292 /// Replace current statistics with the values in array stats.
1293 
1295 {
1296  fTsumw = stats[0];
1297  fTsumw2 = stats[1];
1298  fTsumwx = stats[2];
1299  fTsumwx2 = stats[3];
1300  fTsumwy = stats[4];
1301  fTsumwy2 = stats[5];
1302 }
1303 
1304 ////////////////////////////////////////////////////////////////////////////////
1305 /// Rebin this profile grouping ngroup bins together.
1306 ///
1307 /// ## case 1 xbins=0
1308 /// if newname is not blank a new temporary profile hnew is created.
1309 /// else the current profile is modified (default)
1310 /// The parameter ngroup indicates how many bins of this have to me merged
1311 /// into one bin of hnew
1312 /// If the original profile has errors stored (via Sumw2), the resulting
1313 /// profile has new errors correctly calculated.
1314 ///
1315 /// examples: if hp is an existing TProfile histogram with 100 bins
1316 ///
1317 /// ~~~ {.cpp}
1318 /// hp->Rebin(); //merges two bins in one in hp: previous contents of hp are lost
1319 /// hp->Rebin(5); //merges five bins in one in hp
1320 /// TProfile *hnew = hp->Rebin(5,"hnew"); // creates a new profile hnew
1321 /// //merging 5 bins of hp in one bin
1322 /// ~~~
1323 ///
1324 /// NOTE: If ngroup is not an exact divider of the number of bins,
1325 /// the top limit of the rebinned profile is changed
1326 /// to the upper edge of the bin=newbins*ngroup and the corresponding
1327 /// bins are added to the overflow bin.
1328 /// Statistics will be recomputed from the new bin contents.
1329 ///
1330 /// ## case 2 xbins!=0
1331 /// a new profile is created (you should specify newname).
1332 /// The parameter ngroup is the number of variable size bins in the created profile
1333 /// The array xbins must contain ngroup+1 elements that represent the low-edge
1334 /// of the bins.
1335 /// The data of the old bins are added to the new bin which contains the bin center
1336 /// of the old bins. It is possible that information from the old binning are attached
1337 /// to the under-/overflow bins of the new binning.
1338 ///
1339 /// examples: if hp is an existing TProfile with 100 bins
1340 ///
1341 /// ~~~ {.cpp}
1342 /// Double_t xbins[25] = {...} array of low-edges (xbins[25] is the upper edge of last bin
1343 /// hp->Rebin(24,"hpnew",xbins); //creates a new variable bin size profile hpnew
1344 /// ~~~
1345 
1346 TH1 *TProfile::Rebin(Int_t ngroup, const char*newname, const Double_t *xbins)
1347 {
1348  Int_t nbins = fXaxis.GetNbins();
1351  if ((ngroup <= 0) || (ngroup > nbins)) {
1352  Error("Rebin", "Illegal value of ngroup=%d",ngroup);
1353  return 0;
1354  }
1355  if (!newname && xbins) {
1356  Error("Rebin","if xbins is specified, newname must be given");
1357  return 0;
1358  }
1359 
1360  Int_t newbins = nbins/ngroup;
1361  if (!xbins) {
1362  Int_t nbg = nbins/ngroup;
1363  if (nbg*ngroup != nbins) {
1364  Warning("Rebin", "ngroup=%d must be an exact divider of nbins=%d",ngroup,nbins);
1365  }
1366  }
1367  else {
1368  // in the case of xbins given (rebinning in variable bins) ngroup is the new number of bins.
1369  // and number of grouped bins is not constant.
1370  // when looping for setting the contents for the new histogram we
1371  // need to loop on all bins of original histogram. Set then ngroup=nbins
1372  newbins = ngroup;
1373  ngroup = nbins;
1374  }
1375 
1376  // Save old bin contents into a new array
1377  Double_t *oldBins = new Double_t[nbins+2];
1378  Double_t *oldCount = new Double_t[nbins+2];
1379  Double_t *oldErrors = new Double_t[nbins+2];
1380  Double_t *oldBinw2 = (fBinSumw2.fN ? new Double_t[nbins+2] : 0 );
1381  Int_t bin, i;
1382  Double_t *cu1 = GetW();
1383  Double_t *er1 = GetW2();
1384  Double_t *en1 = GetB();
1385  Double_t *ew1 = GetB2();
1386 
1387  for (bin=0;bin<=nbins+1;bin++) {
1388  oldBins[bin] = cu1[bin];
1389  oldCount[bin] = en1[bin];
1390  oldErrors[bin] = er1[bin];
1391  if (ew1 && fBinSumw2.fN) oldBinw2[bin] = ew1[bin];
1392  }
1393 
1394  // create a clone of the old histogram if newname is specified
1395  TProfile *hnew = this;
1396  if ((newname && strlen(newname) > 0) || xbins) {
1397  hnew = (TProfile*)Clone(newname);
1398  }
1399 
1400  // in case of ngroup not an excat divider of nbins,
1401  // top limit is changed (see NOTE in method comment)
1402  if(!xbins && (newbins*ngroup != nbins)) {
1403  xmax = fXaxis.GetBinUpEdge(newbins*ngroup);
1404  hnew->fTsumw = 0; //stats must be reset because top bins will be moved to overflow bin
1405  }
1406 
1407  // set correctly the axis and resizes the bin arrays
1408  if(!xbins && (fXaxis.GetXbins()->GetSize() > 0)){
1409  // for rebinning of variable bins in a constant group
1410  Double_t *bins = new Double_t[newbins+1];
1411  for(i = 0; i <= newbins; ++i) bins[i] = fXaxis.GetBinLowEdge(1+i*ngroup);
1412  hnew->SetBins(newbins,bins); //this also changes the bin array's
1413  delete [] bins;
1414  } else if (xbins) {
1415  // when rebinning in variable bins
1416  hnew->SetBins(newbins,xbins);
1417  } else {
1418  hnew->SetBins(newbins,xmin,xmax);
1419  }
1420 
1421  // merge bin contents ignoring now underflow/overflows
1422  if (fBinSumw2.fN) hnew->Sumw2();
1423 
1424  // Start merging only once the new lowest edge is reached
1425  Int_t startbin = 1;
1426  const Double_t newxmin = hnew->GetXaxis()->GetBinLowEdge(1);
1427  while( fXaxis.GetBinCenter(startbin) < newxmin && startbin <= nbins ) {
1428  startbin++;
1429  }
1430 
1431  Double_t *cu2 = hnew->GetW();
1432  Double_t *er2 = hnew->GetW2();
1433  Double_t *en2 = hnew->GetB();
1434  Double_t *ew2 = hnew->GetB2();
1435  Int_t oldbin = startbin;
1436  Double_t binContent, binCount, binError, binSumw2;
1437  for (bin = 1;bin<=newbins;bin++) {
1438  binContent = 0;
1439  binCount = 0;
1440  binError = 0;
1441  binSumw2 = 0;
1442 
1443  //for xbins != 0: ngroup == nbins
1444  Int_t imax = ngroup;
1445  Double_t xbinmax = hnew->GetXaxis()->GetBinUpEdge(bin);
1446  for (i=0;i<ngroup;i++) {
1447  if((hnew == this && (oldbin+i > nbins)) ||
1448  (hnew != this && (fXaxis.GetBinCenter(oldbin+i) > xbinmax)))
1449  {
1450  imax = i;
1451  break;
1452  }
1453 
1454  binContent += oldBins[oldbin+i];
1455  binCount += oldCount[oldbin+i];
1456  binError += oldErrors[oldbin+i];
1457  if (fBinSumw2.fN) binSumw2 += oldBinw2[oldbin+i];
1458  }
1459 
1460  cu2[bin] = binContent;
1461  er2[bin] = binError;
1462  en2[bin] = binCount;
1463  if (fBinSumw2.fN) ew2[bin] = binSumw2;
1464  oldbin += imax;
1465  }
1466  // set bin statistics for underflow bin
1467  binContent = 0;
1468  binCount = 0;
1469  binError = 0;
1470  binSumw2 = 0;
1471  for(i=0;i<startbin;i++)
1472  {
1473  binContent += oldBins[i];
1474  binCount += oldCount[i];
1475  binError += oldErrors[i];
1476  if (fBinSumw2.fN) binSumw2 += oldBinw2[i];
1477  }
1478  hnew->fArray[0] = binContent;
1479  hnew->fBinEntries[0] = binCount;
1480  hnew->fSumw2[0] = binError;
1481  if ( fBinSumw2.fN ) hnew->fBinSumw2[0] = binSumw2;
1482 
1483  // set bin statistics for overflow bin
1484  binContent = 0;
1485  binCount = 0;
1486  binError = 0;
1487  binSumw2 = 0;
1488  for(i=oldbin;i<=nbins+1;i++)
1489  {
1490  binContent += oldBins[i];
1491  binCount += oldCount[i];
1492  binError += oldErrors[i];
1493  if (fBinSumw2.fN) binSumw2 += oldBinw2[i];
1494  }
1495  hnew->fArray[newbins+1] = binContent;
1496  hnew->fBinEntries[newbins+1] = binCount;
1497  hnew->fSumw2[newbins+1] = binError;
1498  if ( fBinSumw2.fN ) hnew->fBinSumw2[newbins+1] = binSumw2;
1499 
1500 
1501  delete [] oldBins;
1502  delete [] oldCount;
1503  delete [] oldErrors;
1504  if (oldBinw2) delete [] oldBinw2;
1505  return hnew;
1506 }
1507 
1508 ////////////////////////////////////////////////////////////////////////////////
1509 /// Profile histogram is resized along x axis such that x is in the axis range.
1510 /// The new axis limits are recomputed by doubling iteratively
1511 /// the current axis range until the specified value x is within the limits.
1512 /// The algorithm makes a copy of the histogram, then loops on all bins
1513 /// of the old histogram to fill the extended histogram.
1514 /// Takes into account errors (Sumw2) if any.
1515 /// The axis must be extendable before invoking this function.
1516 ///
1517 /// Ex: `h->GetXaxis()->SetCanExtend(kTRUE)`
1518 
1520 {
1521  TProfile* hold = TProfileHelper::ExtendAxis(this, x, axis);
1522  if ( hold ) {
1523  fTsumwy = hold->fTsumwy;
1524  fTsumwy2 = hold->fTsumwy2;
1525 
1526  delete hold;
1527  }
1528 }
1529 
1530 ////////////////////////////////////////////////////////////////////////////////
1531 /// Reset contents of a Profile histogram.
1532 
1534 {
1535  TH1D::Reset(option);
1536  fBinEntries.Reset();
1537  fBinSumw2.Reset();
1538  TString opt = option;
1539  opt.ToUpper();
1540  if (opt.Contains("ICE") && !opt.Contains("S")) return;
1541  fTsumwy = 0;
1542  fTsumwy2 = 0;
1543 }
1544 
1545 ////////////////////////////////////////////////////////////////////////////////
1546 /// Save primitive as a C++ statement(s) on output stream out.
1547 
1548 void TProfile::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1549 {
1550  //Note the following restrictions in the code generated:
1551  // - variable bin size not implemented
1552  // - SetErrorOption not implemented
1553 
1554  Bool_t nonEqiX = kFALSE;
1555  Int_t i;
1556  // Check if the profile has equidistant X bins or not. If not, we
1557  // create an array holding the bins.
1558  if (GetXaxis()->GetXbins()->fN && GetXaxis()->GetXbins()->fArray) {
1559  nonEqiX = kTRUE;
1560  out << " Double_t xAxis[" << GetXaxis()->GetXbins()->fN
1561  << "] = {";
1562  for (i = 0; i < GetXaxis()->GetXbins()->fN; i++) {
1563  if (i != 0) out << ", ";
1564  out << GetXaxis()->GetXbins()->fArray[i];
1565  }
1566  out << "}; " << std::endl;
1567  }
1568 
1569  char quote = '"';
1570  out<<" "<<std::endl;
1571  out<<" "<<ClassName()<<" *";
1572 
1573  //histogram pointer has by default teh histogram name.
1574  //however, in case histogram has no directory, it is safer to add a incremental suffix
1575  static Int_t hcounter = 0;
1576  TString histName = GetName();
1577  if (!fDirectory) {
1578  hcounter++;
1579  histName += "__";
1580  histName += hcounter;
1581  }
1582  const char *hname = histName.Data();
1583 
1584  out<<hname<<" = new "<<ClassName()<<"("<<quote<<GetName()<<quote<<","<<quote<<GetTitle()<<quote
1585  <<","<<GetXaxis()->GetNbins();
1586  if (nonEqiX)
1587  out << ", xAxis";
1588  else
1589  out << "," << GetXaxis()->GetXmin()
1590  << "," << GetXaxis()->GetXmax()
1591  <<","<<quote<<GetErrorOption()<<quote<<");"<<std::endl;
1592 
1593  // save bin entries
1594  Int_t bin;
1595  for (bin=0;bin<fNcells;bin++) {
1596  Double_t bi = GetBinEntries(bin);
1597  if (bi) {
1598  out<<" "<<hname<<"->SetBinEntries("<<bin<<","<<bi<<");"<<std::endl;
1599  }
1600  }
1601  //save bin contents
1602  for (bin=0;bin<fNcells;bin++) {
1603  Double_t bc = fArray[bin];
1604  if (bc) {
1605  out<<" "<<hname<<"->SetBinContent("<<bin<<","<<bc<<");"<<std::endl;
1606  }
1607  }
1608  // save bin errors
1609  if (fSumw2.fN) {
1610  for (bin=0;bin<fNcells;bin++) {
1611  Double_t be = TMath::Sqrt(fSumw2.fArray[bin]);
1612  if (be) {
1613  out<<" "<<hname<<"->SetBinError("<<bin<<","<<be<<");"<<std::endl;
1614  }
1615  }
1616  }
1617 
1618  TH1::SavePrimitiveHelp(out, hname, option);
1619 }
1620 
1621 ////////////////////////////////////////////////////////////////////////////////
1622 /// Multiply this profile by a constant c1.
1623 ///
1624 /// `this = c1*this`
1625 ///
1626 /// This function uses the services of TProfile::Add
1627 
1629 {
1630  TProfileHelper::Scale(this, c1, option);
1631 }
1632 
1633 ////////////////////////////////////////////////////////////////////////////////
1634 /// Set the number of entries in bin.
1635 
1637 {
1638  TProfileHelper::SetBinEntries(this, bin, w);
1639 }
1640 
1641 ////////////////////////////////////////////////////////////////////////////////
1642 /// Redefine x axis parameters.
1643 
1645 {
1646  fXaxis.Set(nx,xmin,xmax);
1647  fNcells = nx+2;
1649 }
1650 
1651 ////////////////////////////////////////////////////////////////////////////////
1652 /// Redefine x axis parameters.
1653 
1654 void TProfile::SetBins(Int_t nx, const Double_t *xbins)
1655 {
1656  fXaxis.Set(nx,xbins);
1657  fNcells = nx+2;
1659 }
1660 
1661 ////////////////////////////////////////////////////////////////////////////////
1662 /// Set total number of bins including under/overflow.
1663 /// Reallocate bin contents array
1664 
1666 {
1669 }
1670 
1671 ////////////////////////////////////////////////////////////////////////////////
1672 /// Set the buffer size in units of 8 bytes (double).
1673 
1675 {
1676  if (fBuffer) {
1677  BufferEmpty();
1678  delete [] fBuffer;
1679  fBuffer = 0;
1680  }
1681  if (buffersize <= 0) {
1682  fBufferSize = 0;
1683  return;
1684  }
1685  if (buffersize < 100) buffersize = 100;
1686  fBufferSize = 1 + 3*buffersize;
1687  fBuffer = new Double_t[fBufferSize];
1688  memset(fBuffer,0,sizeof(Double_t)*fBufferSize);
1689 }
1690 
1691 ////////////////////////////////////////////////////////////////////////////////
1692 /// Set option to compute profile errors.
1693 ///
1694 /// The computation of the bin errors is based on the parameter option:
1695 ///
1696 /// -' ' (Default) The bin errors are the standard error on the mean of the bin profiled values (Y),
1697 /// i.e. the standard error of the bin contents.
1698 /// Note that if TProfile::Approximate() is called, an approximation is used when
1699 /// the spread in Y is 0 and the number of bin entries is > 0
1700 /// -'s' The bin errors are the standard deviations of the Y bin values
1701 /// Note that if TProfile::Approximate() is called, an approximation is used when
1702 /// the spread in Y is 0 and the number of bin entries is > 0
1703 /// -'i' Errors are as in default case (standard errors of the bin contents)
1704 /// The only difference is for the case when the spread in Y is zero.
1705 /// In this case for N > 0 the error is 1./SQRT(12.*N)
1706 /// -'g' Errors are 1./SQRT(W) for W not equal to 0 and 0 for W = 0.
1707 /// W is the sum in the bin of the weights of the profile.
1708 /// This option is for combining measurements y +/- dy,
1709 /// and the profile is filled with values y and weights w = 1/dy**2
1710 ///
1711 /// See TProfile::BuildOptions for a detailed explanation of all options
1712 
1714 {
1715  TProfileHelper::SetErrorOption(this, option);
1716 }
1717 
1718 ////////////////////////////////////////////////////////////////////////////////
1719 /// Stream an object of class TProfile.
1720 
1721 void TProfile::Streamer(TBuffer &R__b)
1722 {
1723  if (R__b.IsReading()) {
1724  UInt_t R__s, R__c;
1725  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1726  if (R__v > 2) {
1727  R__b.ReadClassBuffer(TProfile::Class(), this, R__v, R__s, R__c);
1728  return;
1729  }
1730  //====process old versions before automatic schema evolution
1731  TH1D::Streamer(R__b);
1732  fBinEntries.Streamer(R__b);
1733  Int_t errorMode;
1734  R__b >> errorMode;
1735  fErrorMode = (EErrorType)errorMode;
1736  if (R__v < 2) {
1737  Float_t ymin,ymax;
1738  R__b >> ymin; fYmin = ymin;
1739  R__b >> ymax; fYmax = ymax;
1740  } else {
1741  R__b >> fYmin;
1742  R__b >> fYmax;
1743  }
1744  R__b.CheckByteCount(R__s, R__c, TProfile::IsA());
1745  //====end of old versions
1746 
1747  } else {
1748  R__b.WriteClassBuffer(TProfile::Class(),this);
1749  }
1750 }
1751 ////////////////////////////////////////////////////////////////////////////////
1752 /// Create/delete structure to store sum of squares of weights per bin.
1753 ///
1754 /// This is needed to compute the correct statistical quantities
1755 /// of a profile filled with weights
1756 ///
1757 /// This function is automatically called when the histogram is created
1758 /// if the static function TH1::SetDefaultSumw2 has been called before.
1759 /// If flag is false the structure is deleted
1760 
1762 {
1763  TProfileHelper::Sumw2(this, flag);
1764 }
THLimitsFinder::FindGoodLimits
virtual Int_t FindGoodLimits(TH1 *h, Double_t xmin, Double_t xmax)
Compute the best axis limits for the X axis.
Definition: THLimitsFinder.cxx:53
TProfileHelper::Scale
static void Scale(T *p, Double_t c1, Option_t *option)
Definition: TProfileHelper.h:481
TProfileHelper::Merge
static Long64_t Merge(T *p, TCollection *list)
Definition: TProfileHelper.h:166
TProfileHelper::SetErrorOption
static void SetErrorOption(T *p, Option_t *opt)
Definition: TProfileHelper.h:650
n
const Int_t n
Definition: legend1.C:16
TAxis
Class to manage histogram axis.
Definition: TAxis.h:30
TProfileHelper::SetBinEntries
static void SetBinEntries(T *p, Int_t bin, Double_t w)
Definition: TProfileHelper.h:725
TProfile::GetBinEntries
virtual Double_t GetBinEntries(Int_t bin) const
Return bin entries of a Profile histogram.
Definition: TProfile.cxx:830
TProfile::SetBinEntries
virtual void SetBinEntries(Int_t bin, Double_t w)
Set the number of entries in bin.
Definition: TProfile.cxx:1636
ymax
float ymax
Definition: THbookFile.cxx:95
TF1::RejectPoint
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:3668
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TProfileHelper::BuildArray
static void BuildArray(T *p)
Definition: TProfileHelper.h:129
TObject::TestBit
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
TProfile::TProfile
TProfile()
Default constructor for Profile histograms.
Definition: TProfile.cxx:92
TAxis::GetBinLowEdge
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:518
Version_t
short Version_t
Definition: RtypesCore.h:65
TAxis::Set
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition: TAxis.cxx:731
Option_t
const char Option_t
Definition: RtypesCore.h:66
TProfile::operator=
TProfile & operator=(const TProfile &profile)
Definition: TProfile.cxx:249
TProfile::GetBinError
virtual Double_t GetBinError(Int_t bin) const
Return bin error of a Profile histogram.
Definition: TProfile.cxx:881
TProfile::Rebin
TH1 * Rebin(Int_t ngroup=2, const char *newname="", const Double_t *xbins=0)
Rebin this profile grouping ngroup bins together.
Definition: TProfile.cxx:1346
TProfile::Merge
virtual Long64_t Merge(TCollection *list)
Merge all histograms in the collection in this histogram.
Definition: TProfile.cxx:1128
TProfile::GetBinEffectiveEntries
virtual Double_t GetBinEffectiveEntries(Int_t bin) const
Return bin effective entries for a weighted filled Profile histogram.
Definition: TProfile.cxx:846
TH1::SetMinimum
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:397
TProfile::LabelsDeflate
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:962
TH1::fEntries
Double_t fEntries
Number of entries.
Definition: TH1.h:94
TString::Data
const char * Data() const
Definition: TString.h:369
TProfile::LabelsInflate
virtual void LabelsInflate(Option_t *axis="X")
Double the number of bins for axis.
Definition: TProfile.cxx:972
TProfile::~TProfile
virtual ~TProfile()
Default destructor for Profile histograms.
Definition: TProfile.cxx:100
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
TProfileHelper::GetBinError
static Double_t GetBinError(T *p, Int_t bin)
Definition: TProfileHelper.h:661
TObjString.h
TProfile::BufferEmpty
virtual Int_t BufferEmpty(Int_t action=0)
Fill histogram with all entries in the buffer.
Definition: TProfile.cxx:334
TBuffer::ReadClassBuffer
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
TH1::fTsumw
Double_t fTsumw
Total Sum of weights.
Definition: TH1.h:95
xmax
float xmax
Definition: THbookFile.cxx:95
TProfile::Add
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1.
Definition: TProfile.cxx:258
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TH1::fBufferSize
Int_t fBufferSize
fBuffer size
Definition: TH1.h:106
TMath::Sqrt
Double_t Sqrt(Double_t x)
Definition: TMath.h:691
TProfile::ExtendAxis
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:1519
TH1D
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:616
TH1::kIsNotW
@ kIsNotW
Histogram is forced to be not weighted even when the histogram is filled with weighted different than...
Definition: TH1.h:169
TAxis::GetFirst
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:458
Float_t
float Float_t
Definition: RtypesCore.h:57
TProfileHelper::LabelsInflate
static void LabelsInflate(T *p, Option_t *)
Definition: TProfileHelper.h:595
TObject::Fatal
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:918
Int_t
int Int_t
Definition: RtypesCore.h:45
TAxis::GetBinCenter
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:478
TH1::GetBinError
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8738
TH1::fDirectory
TDirectory * fDirectory
!Pointer to directory holding this histogram
Definition: TH1.h:108
TProfileHelper::Sumw2
static void Sumw2(T *p, Bool_t flag)
Definition: TProfileHelper.h:498
TH1::fBuffer
Double_t * fBuffer
[fBufferSize] entry buffer
Definition: TH1.h:107
TArrayD::TArrayD
TArrayD()
Default TArrayD ctor.
Definition: TArrayD.cxx:26
TAxis::GetBinUpEdge
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:528
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
TH1::SetBinContent
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:8897
x
Double_t x[n]
Definition: legend1.C:17
TClass.h
TProfile::Sumw2
virtual void Sumw2(Bool_t flag=kTRUE)
Create/delete structure to store sum of squares of weights per bin.
Definition: TProfile.cxx:1761
TMath::Abs
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
TBuffer
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
TF1::IsInside
virtual Bool_t IsInside(const Double_t *x) const
return kTRUE if the point is inside the function range
Definition: TF1.h:597
TH1::fNcells
Int_t fNcells
number of bins(1D), cells (2D) +U/Overflows
Definition: TH1.h:88
TArray::fN
Int_t fN
Definition: TArray.h:38
TMath::Sort
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition: TMathBase.h:362
TProfile.h
TProfileHelper::Add
static Bool_t Add(T *p, const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2=1)
Definition: TProfileHelper.h:70
TBuffer::CheckByteCount
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
TProfile::Divide
virtual Bool_t Divide(TF1 *h1, Double_t c1=1)
Performs the operation: this = this/(c1*f1).
Definition: TProfile.cxx:449
TString
Basic string class.
Definition: TString.h:136
TAxis::ImportAttributes
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition: TAxis.cxx:631
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
TProfile::fYmax
Double_t fYmax
Definition: TProfile.h:41
h1
TH1F * h1
Definition: legend1.C:5
bool
TProfile::GetB2
Double_t * GetB2()
Definition: TProfile.h:64
THLimitsFinder.h
TH1::fTsumw2
Double_t fTsumw2
Total Sum of squares of weights.
Definition: TH1.h:96
TObjString::String
TString & String()
Definition: TObjString.h:48
TProfile::fTsumwy
Double_t fTsumwy
True when TProfile::Scale is called.
Definition: TProfile.h:43
TH1::Clone
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
Definition: TH1.cxx:2717
TString::ToUpper
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1138
TProfile::PutStats
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
Definition: TProfile.cxx:1294
TObjString
Collectable string class.
Definition: TObjString.h:28
TProfile::LabelsOption
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Set option(s) to draw axis with labels.
Definition: TProfile.cxx:990
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
TProfile::fTsumwy2
Double_t fTsumwy2
Definition: TProfile.h:44
TAxis::GetLabels
THashList * GetLabels() const
Definition: TAxis.h:117
TList::At
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
TProfile::FillN
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
TProfile::GetW2
Double_t * GetW2()
Definition: TProfile.h:66
TProfile::SetBuffer
virtual void SetBuffer(Int_t buffersize, Option_t *option="")
Set the buffer size in units of 8 bytes (double).
Definition: TProfile.cxx:1674
TProfileHelper::ExtendAxis
static T * ExtendAxis(T *p, Double_t x, TAxis *axis)
Definition: TProfileHelper.h:420
TH1::SavePrimitiveHelp
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:7150
TProfile::GetW
Double_t * GetW()
Definition: TProfile.h:65
TH1::GetBinContent
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4970
TBuffer.h
TH1D::SetBinsLength
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH1.cxx:9970
TProfile::Approximate
static void Approximate(Bool_t approx=kTRUE)
Static function to set the fgApproximate flag.
Definition: TProfile.cxx:320
TAxis::GetXmin
Double_t GetXmin() const
Definition: TAxis.h:133
TObject::ResetBit
void ResetBit(UInt_t f)
Definition: TObject.h:171
TAxis::kLabelsHori
@ kLabelsHori
Definition: TAxis.h:67
TH1::GetYaxis
TAxis * GetYaxis()
Definition: TH1.h:319
xmin
float xmin
Definition: THbookFile.cxx:95
TH1::GetSumw2
virtual TArrayD * GetSumw2()
Definition: TH1.h:310
THashList
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TAxis::kLabelsUp
@ kLabelsUp
Definition: TAxis.h:70
TAxis::kAxisRange
@ kAxisRange
Definition: TAxis.h:61
TMath::IsNaN
Bool_t IsNaN(Double_t x)
Definition: TMath.h:892
TH1::SetEntries
virtual void SetEntries(Double_t n)
Definition: TH1.h:383
TH1D::TH1D
TH1D()
Constructor.
Definition: TH1.cxx:9872
a
auto * a
Definition: textangle.C:12
THLimitsFinder::GetLimitsFinder
static THLimitsFinder * GetLimitsFinder()
Return pointer to the current finder.
Definition: THLimitsFinder.cxx:153
TBuffer::WriteClassBuffer
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
TProfileHelper::LabelsDeflate
static void LabelsDeflate(T *p, Option_t *)
Definition: TProfileHelper.h:529
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TProfile::Fill
Int_t Fill(const Double_t *v)
Definition: TProfile.h:54
TArrayD::Copy
void Copy(TArrayD &array) const
Definition: TArrayD.h:42
s1
#define s1(x)
Definition: RSha256.hxx:91
TH1D::Copy
virtual void Copy(TObject &hnew) const
Copy this to newth1.
Definition: TH1.cxx:9952
TH1::SetMaximum
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:396
TAxis::GetLast
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:469
TProfile::GetStats
virtual void GetStats(Double_t *stats) const
fill the array stats from the contents of this profile.
Definition: TProfile.cxx:914
TProfile::BufferFill
virtual Int_t BufferFill(Double_t, Double_t)
accumulate arguments in buffer.
Definition: TProfile.h:49
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
y
Double_t y[n]
Definition: legend1.C:17
TH1::GetStatOverflowsBehaviour
Bool_t GetStatOverflowsBehaviour() const
Definition: TH1.h:150
TProfile::Copy
virtual void Copy(TObject &hnew) const
Copy a Profile histogram to a new profile histogram.
Definition: TProfile.cxx:419
kERRORSPREADI
@ kERRORSPREADI
Definition: TProfile.h:28
TProfileHelper::GetBinEffectiveEntries
static Double_t GetBinEffectiveEntries(T *p, Int_t bin)
Definition: TProfileHelper.h:142
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
TAxis::kLabelsDown
@ kLabelsDown
Definition: TAxis.h:69
TH1::CanExtendAllAxes
virtual Bool_t CanExtendAllAxes() const
Returns true if all axes are extendable.
Definition: TH1.cxx:6497
TBuffer::ReadVersion
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
TProfile::SetErrorOption
virtual void SetErrorOption(Option_t *option="")
Set option to compute profile errors.
Definition: TProfile.cxx:1713
TMath::Min
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
unsigned int
TF1::EvalPar
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.
Definition: TF1.cxx:1479
TProfile::GetErrorOption
Option_t * GetErrorOption() const
Return option to compute profile errors.
Definition: TProfile.cxx:889
ymin
float ymin
Definition: THbookFile.cxx:95
TProfile
Profile Histogram.
Definition: TProfile.h:32
TArrayD::Reset
void Reset()
Definition: TArrayD.h:47
TArrayD::fArray
Double_t * fArray
Definition: TArrayD.h:30
TAxis::SetBinLabel
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:823
TBuffer::IsReading
Bool_t IsReading() const
Definition: TBuffer.h:86
TProfileHelper.h
f1
TF1 * f1
Definition: legend1.C:11
Double_t
double Double_t
Definition: RtypesCore.h:59
TAxis::kLabelsVert
@ kLabelsVert
Definition: TAxis.h:68
TProfile::BuildOptions
void BuildOptions(Double_t ymin, Double_t ymax, Option_t *option)
Set Profile histogram structure and options.
Definition: TProfile.cxx:227
R__ASSERT
#define R__ASSERT(e)
Definition: TError.h:120
TF1.h
TH1::SetBinError
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:8881
TF1::RejectedPoint
static Bool_t RejectedPoint()
See TF1::RejectPoint above.
Definition: TF1.cxx:3677
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TProfile::GetB
Double_t * GetB()
Definition: TProfile.h:63
TProfile::fgApproximate
static Bool_t fgApproximate
Definition: TProfile.h:47
EErrorType
EErrorType
Definition: TProfile.h:28
THashList::Clear
void Clear(Option_t *option="")
Remove all objects from the list.
Definition: THashList.cxx:189
TH1::fSumw2
TArrayD fSumw2
Array of sum of squares of weights.
Definition: TH1.h:103
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TH1::Sumw2
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition: TH1.cxx:8695
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TH1::fTsumwx2
Double_t fTsumwx2
Total Sum of weight*X*X.
Definition: TH1.h:98
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition: TH1.h:58
name
char name[80]
Definition: TGX11.cxx:110
TH1::fXaxis
TAxis fXaxis
X axis descriptor.
Definition: TH1.h:89
TAxis::FindBin
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:293
TH1D::AddBinContent
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition: TH1.h:628
c2
return c2
Definition: legend2.C:14
kERRORSPREADG
@ kERRORSPREADG
Definition: TProfile.h:28
TIter
Definition: TCollection.h:233
TProfile::fBinEntries
TArrayD fBinEntries
Definition: TProfile.h:38
TCollection
Collection abstract base class.
Definition: TCollection.h:63
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
TAxis::GetXmax
Double_t GetXmax() const
Definition: TAxis.h:134
TProfile::SetBinsLength
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow.
Definition: TProfile.cxx:1665
TF1
1-Dim function class
Definition: TF1.h:213
TProfile::fScaling
Bool_t fScaling
Definition: TProfile.h:42
TArrayD
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
Class
void Class()
Definition: Class.C:29
TString::ToLower
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:318
TProfile::fYmin
Double_t fYmin
Definition: TProfile.h:40
TH1::fTsumwx
Double_t fTsumwx
Total Sum of weight*X.
Definition: TH1.h:97
kERRORSPREAD
@ kERRORSPREAD
Definition: TProfile.h:28
TAxis::GetXbins
const TArrayD * GetXbins() const
Definition: TAxis.h:130
TObject::ClassName
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
TProfile::GetBinContent
virtual Double_t GetBinContent(Int_t bin) const
Return bin content of a Profile histogram.
Definition: TProfile.cxx:817
TProfile::SetBins
void SetBins(const Int_t *nbins, const Double_t *range)
Definition: TProfile.h:53
TProfile::Multiply
virtual Bool_t Multiply(TF1 *h1, Double_t c1=1)
Performs the operation: this = this*c1*f1.
Definition: TProfile.cxx:1138
TProfile::Scale
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this profile by a constant c1.
Definition: TProfile.cxx:1628
TAxis::GetNbins
Int_t GetNbins() const
Definition: TAxis.h:121
TProfile::fErrorMode
EErrorType fErrorMode
Definition: TProfile.h:39
TArray::GetSize
Int_t GetSize() const
Definition: TArray.h:47
TMath.h
TObject::SetUniqueID
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:707
TH1::GetNbinsX
virtual Int_t GetNbinsX() const
Definition: TH1.h:294
TProfile::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TProfile.cxx:1548
int
TError.h
c1
return c1
Definition: legend1.C:41
TProfile::fBinSumw2
TArrayD fBinSumw2
Definition: TProfile.h:45
TProfile::ProjectionX
TH1D * ProjectionX(const char *name="_px", Option_t *option="e") const
Project this profile into a 1-D histogram along X.
Definition: TProfile.cxx:1219