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