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