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