Logo ROOT   6.12/07
Reference Guide
THStack.cxx
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Rene Brun 10/12/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, 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 "TROOT.h"
13 #include "TClassRef.h"
14 #include "THStack.h"
15 #include "TVirtualPad.h"
16 #include "TVirtualHistPainter.h"
17 #include "THashList.h"
18 #include "TH2.h"
19 #include "TH3.h"
20 #include "TList.h"
21 #include "TStyle.h"
22 #include "Riostream.h"
23 #include "TBrowser.h"
24 #include "TMath.h"
25 #include "TObjString.h"
26 #include "TVirtualMutex.h"
27 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 
32 /** \class THStack
33  \ingroup Hist
34 The Histogram stack class
35 
36 A THStack is a collection of TH1 or TH2 histograms.
37 Using THStack::Draw() the histogram collection is drawn in one go according
38 to the drawing option.
39 
40 THStack::Add() allows to add a new histogram to the list.
41 The THStack does not own the objects in the list.
42 
43 By default (if no option drawing option is specified), histograms will be paint
44 stacked on top of each other. TH2 are stacked as lego plots.
45 
46 If option "nostack" is specified the histograms are not drawn on top
47 of each other but as they would if drawn using the option "same".
48 
49 If option "nostackb" is specified the histograms are drawn next to
50 each other as bar charts.
51 
52 In all cases The axis range is computed automatically along the X and Y axis in
53 order to show the complete histogram collection.
54 
55 Example;
56 
57 Begin_Macro(source)
58 {
59  THStack *hs = new THStack("hs","");
60  TH1F *h1 = new TH1F("h1","test hstack",10,-4,4);
61  h1->FillRandom("gaus",20000);
62  h1->SetFillColor(kRed);
63  hs->Add(h1);
64  TH1F *h2 = new TH1F("h2","test hstack",10,-4,4);
65  h2->FillRandom("gaus",15000);
66  h2->SetFillColor(kBlue);
67  hs->Add(h2);
68  TH1F *h3 = new TH1F("h3","test hstack",10,-4,4);
69  h3->FillRandom("gaus",10000);
70  h3->SetFillColor(kGreen);
71  hs->Add(h3);
72  TCanvas *cs = new TCanvas("cs","cs",10,10,700,900);
73  TText T; T.SetTextFont(42); T.SetTextAlign(21);
74  cs->Divide(2,2);
75  cs->cd(1); hs->Draw(); T.DrawTextNDC(.5,.95,"Default drawing option");
76  cs->cd(2); hs->Draw("nostack"); T.DrawTextNDC(.5,.95,"Option \"nostack\"");
77  cs->cd(3); hs->Draw("nostackb"); T.DrawTextNDC(.5,.95,"Option \"nostackb\"");
78  cs->cd(4); hs->Draw("lego1"); T.DrawTextNDC(.5,.95,"Option \"lego1\"");
79  return cs;
80 }
81 End_Macro
82 
83 A more complex example:
84 
85 Begin_Macro(source)
86 ../../../tutorials/hist/hstack.C
87 End_Macro
88 
89 Note that picking is supported for all drawing modes.
90 
91 \since **ROOT version 6.07/07:**
92 Stacks of 2D histograms can also be painted as candle plots:
93 \since **ROOT version 6.09/02:**
94 Stacks of 2D histograms can also be painted as violin plots, combinations of candle and
95 violin plots are possible as well:
96 
97 Begin_Macro(source)
98 ../../../tutorials/hist/candleplotstack.C
99 End_Macro
100 
101 Automatic coloring according to the current palette is available as shown in the
102 following example:
103 
104 Begin_Macro(source)
105 ../../../tutorials/hist/thstackpalettecolor.C
106 End_Macro
107 */
108 
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// THStack default constructor
112 
114 {
115  fHists = 0;
116  fStack = 0;
117  fHistogram = 0;
118  fMaximum = -1111;
119  fMinimum = -1111;
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// constructor with name and title
124 
125 THStack::THStack(const char *name, const char *title)
126  : TNamed(name,title)
127 {
128  fHists = 0;
129  fStack = 0;
130  fHistogram = 0;
131  fMaximum = -1111;
132  fMinimum = -1111;
134  gROOT->GetListOfCleanups()->Add(this);
135 }
136 
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Creates a new THStack from a TH2 or TH3
140 /// It is filled with the 1D histograms from GetProjectionX or GetProjectionY
141 /// for each bin of the histogram. It illustrates the differences and total
142 /// sum along an axis.
143 ///
144 /// Parameters:
145 /// - hist: the histogram used for the projections. Can be an object deriving
146 /// from TH2 or TH3.
147 /// - axis: for TH2: "x" for ProjectionX, "y" for ProjectionY.
148 /// for TH3: see TH3::Project3D.
149 /// - name: fName is set to name if given, otherwise to histo's name with
150 /// "_stack_<axis>" appended, where <axis> is the value of the
151 /// parameter axis.
152 /// - title: fTitle is set to title if given, otherwise to histo's title
153 /// with ", stack of <axis> projections" appended.
154 /// - firstbin, lastbin:
155 /// for each bin within [firstbin,lastbin] a stack entry is created.
156 /// See TH2::ProjectionX/Y for use overflow bins.
157 /// Defaults to "all bins but under- / overflow"
158 /// - firstbin2, lastbin2:
159 /// Other axis range for TH3::Project3D, defaults to "all bins but
160 /// under- / overflow". Ignored for TH2s
161 /// - proj_option:
162 /// option passed to TH2::ProjectionX/Y and TH3::Project3D (along
163 /// with axis)
164 /// - draw_option:
165 /// option passed to THStack::Add.
166 
167 THStack::THStack(TH1* hist, Option_t *axis /*="x"*/,
168  const char *name /*=0*/, const char *title /*=0*/,
169  Int_t firstbin /*=1*/, Int_t lastbin /*=-1*/,
170  Int_t firstbin2 /*=1*/, Int_t lastbin2 /*=-1*/,
171  Option_t* proj_option /*=""*/, Option_t* draw_option /*=""*/): TNamed(name, title) {
172  fHists = 0;
173  fStack = 0;
174  fHistogram = 0;
175  fMaximum = -1111;
176  fMinimum = -1111;
177  {
179  gROOT->GetListOfCleanups()->Add(this);
180  }
181  if (!axis) {
182  Warning("THStack", "Need an axis.");
183  return;
184  }
185  if (!hist) {
186  Warning("THStack", "Need a histogram.");
187  return;
188  }
189  Bool_t isTH2=hist->IsA()->InheritsFrom(TH2::Class());
190  Bool_t isTH3=hist->IsA()->InheritsFrom(TH3::Class());
191  if (!isTH2 && !isTH3) {
192  Warning("THStack", "Need a histogram deriving from TH2 or TH3.");
193  return;
194  }
195 
196  if (!fName.Length())
197  fName=Form("%s_stack%s", hist->GetName(), axis);
198  if (!fTitle.Length()) {
199  if (hist->GetTitle() && strlen(hist->GetTitle()))
200  fTitle=Form("%s, stack of %s projections", hist->GetTitle(), axis);
201  else
202  fTitle=Form("stack of %s projections", axis);
203  }
204 
205  if (isTH2) {
206  TH2* hist2=(TH2*) hist;
207  Bool_t useX=(strchr(axis,'x')) || (strchr(axis,'X'));
208  Bool_t useY=(strchr(axis,'y')) || (strchr(axis,'Y'));
209  if ((!useX && !useY) || (useX && useY)) {
210  Warning("THStack", "Need parameter axis=\"x\" or \"y\" for a TH2, not none or both.");
211  return;
212  }
213  TAxis* haxis= useX ? hist->GetYaxis() : hist->GetXaxis();
214  if (!haxis) {
215  Warning("HStack","Histogram axis is NULL");
216  return;
217  }
218  Int_t nbins = haxis->GetNbins();
219  if (firstbin < 0) firstbin = 1;
220  if (lastbin < 0) lastbin = nbins;
221  if (lastbin > nbins+1) lastbin = nbins;
222  for (Int_t iBin=firstbin; iBin<=lastbin; iBin++) {
223  TH1* hProj=0;
224  if (useX) hProj=hist2->ProjectionX(Form("%s_px%d",hist2->GetName(), iBin),
225  iBin, iBin, proj_option);
226  else hProj=hist2->ProjectionY(Form("%s_py%d",hist2->GetName(), iBin),
227  iBin, iBin, proj_option);
228  Add(hProj, draw_option);
229  }
230  } else {
231  // hist is a TH3
232  TH3* hist3=(TH3*) hist;
233  TString sAxis(axis);
234  sAxis.ToLower();
235  Int_t dim=3-sAxis.Length();
236  if (dim<1 || dim>2) {
237  Warning("THStack", "Invalid length for parameter axis.");
238  return;
239  }
240 
241  if (dim==1) {
242  TAxis* haxis = 0;
243  // look for the haxis _not_ in axis
244  if (sAxis.First('x')==kNPOS)
245  haxis=hist->GetXaxis();
246  else if (sAxis.First('y')==kNPOS)
247  haxis=hist->GetYaxis();
248  else if (sAxis.First('z')==kNPOS)
249  haxis=hist->GetZaxis();
250  if (!haxis) {
251  Warning("HStack","Histogram axis is NULL");
252  return;
253  }
254 
255  Int_t nbins = haxis->GetNbins();
256  if (firstbin < 0) firstbin = 1;
257  if (lastbin < 0) lastbin = nbins;
258  if (lastbin > nbins+1) lastbin = nbins;
259  Int_t iFirstOld=haxis->GetFirst();
260  Int_t iLastOld=haxis->GetLast();
261  for (Int_t iBin=firstbin; iBin<=lastbin; iBin++) {
262  haxis->SetRange(iBin, iBin);
263  // build projection named axis_iBin (passed through "option")
264  TH1* hProj=hist3->Project3D(Form("%s_%s%s_%d", hist3->GetName(),
265  axis, proj_option, iBin));
266  Add(hProj, draw_option);
267  }
268  haxis->SetRange(iFirstOld, iLastOld);
269  } else {
270  // if dim==2
271  TAxis* haxis1 = 0;
272  TAxis* haxis2 = 0;
273  // look for the haxis _not_ in axis
274  if (sAxis.First('x')!=kNPOS) {
275  haxis1=hist->GetYaxis();
276  haxis2=hist->GetZaxis();
277  } else if (sAxis.First('y')!=kNPOS) {
278  haxis1=hist->GetXaxis();
279  haxis2=hist->GetZaxis();
280  } else if (sAxis.First('z')!=kNPOS) {
281  haxis1=hist->GetXaxis();
282  haxis2=hist->GetYaxis();
283  }
284  if (!haxis1 || !haxis2) {
285  Warning("HStack","Histogram axis is NULL");
286  return;
287  }
288 
289  Int_t nbins1 = haxis1->GetNbins();
290  Int_t nbins2 = haxis2->GetNbins();
291  if (firstbin < 0) firstbin = 1;
292  if (lastbin < 0) lastbin = nbins1;
293  if (lastbin > nbins1+1) lastbin = nbins1;
294  if (firstbin2 < 0) firstbin2 = 1;
295  if (lastbin2 < 0) lastbin2 = nbins2;
296  if (lastbin2 > nbins2+1) lastbin2 = nbins2;
297  Int_t iFirstOld1=haxis1->GetFirst();
298  Int_t iLastOld1=haxis1->GetLast();
299  Int_t iFirstOld2=haxis2->GetFirst();
300  Int_t iLastOld2=haxis2->GetLast();
301  for (Int_t iBin=firstbin; iBin<=lastbin; iBin++) {
302  haxis1->SetRange(iBin, iBin);
303  for (Int_t jBin=firstbin2; jBin<=lastbin2; jBin++) {
304  haxis2->SetRange(jBin, jBin);
305  // build projection named axis_iBin (passed through "option")
306  TH1* hProj=hist3->Project3D(Form("%s_%s%s_%d", hist3->GetName(),
307  axis, proj_option, iBin));
308  Add(hProj, draw_option);
309  }
310  }
311  haxis1->SetRange(iFirstOld1, iLastOld1);
312  haxis2->SetRange(iFirstOld2, iLastOld2);
313  }
314  } // if hist is TH2 or TH3
315 }
316 
317 ////////////////////////////////////////////////////////////////////////////////
318 /// THStack destructor
319 
321 {
322 
323  {
325  gROOT->GetListOfCleanups()->Remove(this);
326  }
327  if (!fHists) return;
328  fHists->Clear("nodelete");
329  delete fHists;
330  fHists = 0;
331  if (fStack) {fStack->Delete(); delete fStack;}
332  delete fHistogram;
333  fHistogram = 0;
334 }
335 
336 ////////////////////////////////////////////////////////////////////////////////
337 /// THStack copy constructor
338 
339 THStack::THStack(const THStack &hstack) :
340  TNamed(hstack),
341  fHists(0),
342  fStack(0),
343  fHistogram(0),
344  fMaximum(hstack.fMaximum),
345  fMinimum(hstack.fMinimum)
346 {
347  if (hstack.GetHists()) {
348  TIter next(hstack.GetHists());
349  TH1 *h;
350  while ((h=(TH1*)next())) Add(h);
351  }
352 }
353 
354 ////////////////////////////////////////////////////////////////////////////////
355 /// add a new histogram to the list
356 /// Only 1-d and 2-d histograms currently supported.
357 /// A drawing option may be specified
358 
359 void THStack::Add(TH1 *h1, Option_t *option)
360 {
361  if (!h1) return;
362  if (h1->GetDimension() > 2) {
363  Error("Add","THStack supports only 1-d and 2-d histograms");
364  return;
365  }
366  if (!fHists) fHists = new TList();
367  fHists->Add(h1,option);
368  Modified(); //invalidate stack
369 }
370 
371 ////////////////////////////////////////////////////////////////////////////////
372 /// Browse.
373 
375 {
376  Draw(b ? b->GetDrawOption() : "");
377  gPad->Update();
378 }
379 
380 ////////////////////////////////////////////////////////////////////////////////
381 /// build sum of all histograms
382 /// Build a separate list fStack containing the running sum of all histograms
383 
384 void THStack::BuildStack()
385 {
386  if (fStack) return;
387  if (!fHists) return;
388  Int_t nhists = fHists->GetSize();
389  if (!nhists) return;
390  fStack = new TObjArray(nhists);
393  TH1 *h = (TH1*)fHists->At(0)->Clone();
394  fStack->Add(h);
395  for (Int_t i=1;i<nhists;i++) {
396  h = (TH1*)fHists->At(i)->Clone();
397  h->Add((TH1*)fStack->At(i-1));
398  fStack->AddAt(h,i);
399  }
400  TH1::AddDirectory(add);
401 }
402 
403 ////////////////////////////////////////////////////////////////////////////////
404 /// Compute distance from point px,py to each graph
405 ///
406 
408 {
409  //*-*- Are we on the axis?
410  const Int_t kMaxDiff = 10;
411  Int_t distance = 9999;
412  if (fHistogram) {
413  distance = fHistogram->DistancetoPrimitive(px,py);
414  if (distance <= 0) {return distance;}
415  if (distance <= 1) {gPad->SetSelected(fHistogram);return distance;}
416  }
417 
418 
419  //*-*- Loop on the list of histograms
420  if (!fHists) return distance;
421  TH1 *h = 0;
422  const char *doption = GetDrawOption();
423  Int_t nhists = fHists->GetSize();
424  for (Int_t i=0;i<nhists;i++) {
425  h = (TH1*)fHists->At(i);
426  if (fStack && !strstr(doption,"nostack")) h = (TH1*)fStack->At(i);
427  Int_t dist = h->DistancetoPrimitive(px,py);
428  if (dist <= 0) return 0;
429  if (dist < kMaxDiff) {
430  gPad->SetSelected(fHists->At(i));
431  gPad->SetCursor(kPointer);
432  return dist;
433  }
434  }
435  return distance;
436 }
437 
438 ////////////////////////////////////////////////////////////////////////////////
439 /// Draw this multihist with its current attributes.
440 ///
441 /// Options to draw histograms are described in THistPainter::Paint
442 /// By default (if option "nostack" is not specified), histograms will be paint
443 /// stacked on top of each other.
444 
445 void THStack::Draw(Option_t *option)
446 {
447  TString opt = option;
448  opt.ToLower();
449  if (gPad) {
450  if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
451  if (!opt.Contains("same")) {
452  //the following statement is necessary in case one attempts to draw
453  //a temporary histogram already in the current pad
454  if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
455  gPad->Clear();
456  }
457  }
458  AppendPad(opt.Data());
459 }
460 
461 ////////////////////////////////////////////////////////////////////////////////
462 /// Returns a pointer to the histogram used to draw the axis
463 /// Takes into account the two following cases.
464 /// 1- option 'A' was specified in THStack::Draw. Return fHistogram
465 /// 2- user had called TPad::DrawFrame. return pointer to hframe histogram
466 ///
467 /// IMPORTANT NOTES
468 /// - You must call Draw before calling this function. The returned histogram
469 /// depends on the selected Draw options.
470 /// - This function returns a pointer to an intermediate fixed bin size
471 /// histogram used to set the range and for picking.
472 /// You cannot use this histogram to return the bin information.
473 /// You must get a pointer to one of the histograms in the stack,
474 /// the first one, for example.
475 
476 TH1 *THStack::GetHistogram() const
477 {
478  if (fHistogram) return fHistogram;
479  if (!gPad) return 0;
480  gPad->Modified();
481  gPad->Update();
482  if (fHistogram) return fHistogram;
483  TH1 *h1 = (TH1*)gPad->FindObject("hframe");
484  return h1;
485 }
486 
487 ////////////////////////////////////////////////////////////////////////////////
488 /// returns the maximum of all added histograms
489 /// returns the maximum of all histograms if option "nostack".
490 
492 {
493  TString opt = option;
494  opt.ToLower();
495  Bool_t lerr = kFALSE;
496  if (opt.Contains("e")) lerr = kTRUE;
497  Double_t them=0, themax = -1e300, c1, e1;
498  if (!fHists) return 0;
499  Int_t nhists = fHists->GetSize();
500  TH1 *h;
501  Int_t first,last;
502 
503  if (!opt.Contains("nostack")) {
504  BuildStack();
505  h = (TH1*)fStack->At(nhists-1);
506  themax = h->GetMaximum();
507  } else {
508  for (Int_t i=0;i<nhists;i++) {
509  h = (TH1*)fHists->At(i);
510  them = h->GetMaximum();
511  if (them > themax) themax = them;
512  }
513  }
514 
515  if (lerr) {
516  for (Int_t i=0;i<nhists;i++) {
517  h = (TH1*)fHists->At(i);
518  first = h->GetXaxis()->GetFirst();
519  last = h->GetXaxis()->GetLast();
520  for (Int_t j=first; j<=last;j++) {
521  e1 = h->GetBinError(j);
522  c1 = h->GetBinContent(j);
523  themax = TMath::Max(themax,c1+e1);
524  }
525  }
526  }
527 
528  return themax;
529 }
530 
531 ////////////////////////////////////////////////////////////////////////////////
532 /// returns the minimum of all added histograms
533 /// returns the minimum of all histograms if option "nostack".
534 
536 {
537  TString opt = option;
538  opt.ToLower();
539  Bool_t lerr = kFALSE;
540  if (opt.Contains("e")) lerr = kTRUE;
541  Double_t them=0, themin = 1e300, c1, e1;
542  if (!fHists) return 0;
543  Int_t nhists = fHists->GetSize();
544  Int_t first,last;
545  TH1 *h;
546 
547  if (!opt.Contains("nostack")) {
548  BuildStack();
549  h = (TH1*)fStack->At(nhists-1);
550  themin = h->GetMinimum();
551  } else {
552  for (Int_t i=0;i<nhists;i++) {
553  h = (TH1*)fHists->At(i);
554  them = h->GetMinimum();
555  if (them <= 0 && gPad && gPad->GetLogy()) them = h->GetMinimum(0);
556  if (them < themin) themin = them;
557  }
558  }
559 
560  if (lerr) {
561  for (Int_t i=0;i<nhists;i++) {
562  h = (TH1*)fHists->At(i);
563  first = h->GetXaxis()->GetFirst();
564  last = h->GetXaxis()->GetLast();
565  for (Int_t j=first; j<=last;j++) {
566  e1 = h->GetBinError(j);
567  c1 = h->GetBinContent(j);
568  themin = TMath::Min(themin,c1-e1);
569  }
570  }
571  }
572 
573  return themin;
574 }
575 
576 ////////////////////////////////////////////////////////////////////////////////
577 /// Return the number of histograms in the stack
578 
580 {
581  if (fHists) return fHists->GetSize();
582  return 0;
583 }
584 
585 ////////////////////////////////////////////////////////////////////////////////
586 /// Return pointer to Stack. Build it if not yet done
587 
589 {
590  BuildStack();
591  return fStack;
592 }
593 
594 ////////////////////////////////////////////////////////////////////////////////
595 /// Get x axis of the histogram used to draw the stack.
596 ///
597 /// IMPORTANT NOTE
598 /// You must call Draw before calling this function. The returned histogram
599 /// depends on the selected Draw options.
600 
601 TAxis *THStack::GetXaxis() const
602 {
603  if (!gPad) return 0;
605  if (!h) return 0;
606  return h->GetXaxis();
607 }
608 
609 ////////////////////////////////////////////////////////////////////////////////
610 /// Get x axis of the histogram used to draw the stack.
611 ///
612 /// IMPORTANT NOTE
613 /// You must call Draw before calling this function. The returned histogram
614 /// depends on the selected Draw options.
615 
616 TAxis *THStack::GetYaxis() const
617 {
618  if (!gPad) return 0;
620  if (!h) return 0;
621  return h->GetYaxis();
622 }
623 
624 ////////////////////////////////////////////////////////////////////////////////
625 /// List histograms in the stack
626 
627 void THStack::ls(Option_t *option) const
628 {
630  std::cout <<IsA()->GetName()
631  <<" Name= "<<GetName()<<" Title= "<<GetTitle()<<" Option="<<option<<std::endl;
633  if (fHists) fHists->ls(option);
635 }
636 ////////////////////////////////////////////////////////////////////////////////
637 /// Merge the THStack in the TList into this stack.
638 /// Returns the total number of histograms in the result or -1 in case of an error.
639 
641 {
642  if (li==0 || li->GetEntries()==0) {
643  return fHists->GetEntries();
644  }
645  TIter next(li);
646  TList histLists;
647  while (TObject* o = next()) {
648  THStack *stack = dynamic_cast<THStack*> (o);
649  if (!stack) {
650  Error("Merge",
651  "Cannot merge - an object which doesn't inherit from THStack found in the list");
652  return -1;
653  }
654  histLists.Add(stack->GetHists());
655  }
656  fHists->Merge(&histLists);
657  return fHists->GetEntries();
658 }
659 
660 ////////////////////////////////////////////////////////////////////////////////
661 /// invalidate sum of histograms
662 
663 void THStack::Modified()
664 {
665  if (!fStack) return;
667  delete fStack;
668  fStack = 0;
669  delete fHistogram;
670  fHistogram = 0;
671 }
672 
673 ////////////////////////////////////////////////////////////////////////////////
674 /// Paint the list of histograms.
675 /// By default, histograms are shown stacked.
676 /// - the first histogram is paint
677 /// - then the sum of the first and second, etc
678 ///
679 /// If option "nostack" is specified, histograms are all paint in the same pad
680 /// as if the option "same" had been specified.
681 ///
682 /// If the option nostackb is specified histograms are all paint in the same pad
683 /// next to each other as bar plots.
684 ///
685 /// if option "pads" is specified, the current pad/canvas is subdivided into
686 /// a number of pads equal to the number of histograms and each histogram
687 /// is paint into a separate pad.
688 ///
689 /// By default the background of the histograms is erased before drawing the
690 /// histograms. The option "noclear" avoid this behaviour. This is useful
691 /// when drawing a THStack on top of an other plot. If the patterns used to
692 /// draw the histograms in the stack are transparents, then the plot behind
693 /// will be visible.
694 ///
695 /// See THistPainter::Paint for a list of valid options.
696 
697 void THStack::Paint(Option_t *choptin)
698 {
699  if (!fHists) return;
700  if (!fHists->GetSize()) return;
701 
702  char option[128];
703  strlcpy(option,choptin,128);
704 
705  // Automatic color
706  char *l1 = strstr(option,"pfc"); // Automatic Fill Color
707  char *l2 = strstr(option,"plc"); // Automatic Line Color
708  char *l3 = strstr(option,"pmc"); // Automatic Marker Color
709  if (l1 || l2 || l3) {
710  TString opt1 = option;
711  if (l1) strncpy(l1," ",3);
712  if (l2) strncpy(l2," ",3);
713  if (l3) strncpy(l3," ",3);
714  TString ws = option;
715  if (ws.IsWhitespace()) strncpy(option,"\0",1);
717  TH1* hAti;
718  Int_t nhists = fHists->GetSize();
719  Int_t ic;
720  gPad->IncrementPaletteColor(nhists, opt1);
721  for (Int_t i=0;i<nhists;i++) {
722  ic = gPad->NextPaletteColor();
723  hAti = (TH1F*)(fHists->At(i));
724  if (l1) hAti->SetFillColor(ic);
725  if (l2) hAti->SetLineColor(ic);
726  if (l3) hAti->SetMarkerColor(ic);
727  lnk = (TObjOptLink*)lnk->Next();
728  }
729  }
730 
731  TString opt = option;
732  opt.ToLower();
733  opt.ReplaceAll(" ","");
734  Bool_t lsame = kFALSE;
735  if (opt.Contains("same")) {
736  lsame = kTRUE;
737  opt.ReplaceAll("same","");
738  }
739  Bool_t lclear = kTRUE;
740  if (opt.Contains("noclear")) {
741  lclear = kFALSE;
742  opt.ReplaceAll("noclear","");
743  }
744  if (opt.Contains("pads")) {
745  Int_t npads = fHists->GetSize();
746  TVirtualPad *padsav = gPad;
747  //if pad is not already divided into subpads, divide it
748  Int_t nps = 0;
749  TObject *obj;
750  TIter nextp(padsav->GetListOfPrimitives());
751  while ((obj = nextp())) {
752  if (obj->InheritsFrom(TVirtualPad::Class())) nps++;
753  }
754  if (nps < npads) {
755  padsav->Clear();
756  Int_t nx = (Int_t)TMath::Sqrt((Double_t)npads);
757  if (nx*nx < npads) nx++;
758  Int_t ny = nx;
759  if (((nx*ny)-nx) >= npads) ny--;
760  padsav->Divide(nx,ny);
761  }
762  TH1 *h;
763  Int_t i = 0;
765  while (lnk) {
766  i++;
767  padsav->cd(i);
768  h = (TH1*)lnk->GetObject();
769  h->Draw(lnk->GetOption());
770  lnk = (TObjOptLink*)lnk->Next();
771  }
772  padsav->cd();
773  return;
774  }
775 
776  // compute the min/max of each axis
777  TH1 *h;
778  TIter next(fHists);
779  Double_t xmin = 1e100;
780  Double_t xmax = -xmin;
781  Double_t ymin = 1e100;
782  Double_t ymax = -xmin;
783  while ((h=(TH1*)next())) {
784  // in case of automatic binning
785  if (h->GetBuffer()) h->BufferEmpty(-1);
786  if (h->GetXaxis()->GetXmin() < xmin) xmin = h->GetXaxis()->GetXmin();
787  if (h->GetXaxis()->GetXmax() > xmax) xmax = h->GetXaxis()->GetXmax();
788  if (h->GetYaxis()->GetXmin() < ymin) ymin = h->GetYaxis()->GetXmin();
789  if (h->GetYaxis()->GetXmax() > ymax) ymax = h->GetYaxis()->GetXmax();
790  }
791 
792  char loption[32];
793  snprintf(loption,31,"%s",opt.Data());
794  char *nostack = strstr(loption,"nostack");
795  char *nostackb = strstr(loption,"nostackb");
796  char *candle = strstr(loption,"candle");
797  char *violin = strstr(loption,"violin");
798 
799  // do not delete the stack. Another pad may contain the same object
800  // drawn in stack mode!
801  //if (nostack && fStack) {fStack->Delete(); delete fStack; fStack = 0;}
802 
803  if (!opt.Contains("nostack") && (!opt.Contains("candle")) && (!opt.Contains("violin"))) BuildStack();
804 
805  Double_t themax,themin;
806  if (fMaximum == -1111) themax = GetMaximum(option);
807  else themax = fMaximum;
808  if (fMinimum == -1111) {
809  themin = GetMinimum(option);
810  if (gPad->GetLogy()){
811  if (themin>0) themin *= .9;
812  else themin = themax*1.e-3;
813  }
814  else if (themin > 0)
815  themin = 0;
816  }
817  else themin = fMinimum;
818  if (!fHistogram) {
821  h = (TH1*)fHists->At(0);
822  TAxis *xaxis = h->GetXaxis();
823  TAxis *yaxis = h->GetYaxis();
824  const TArrayD *xbins = xaxis->GetXbins();
825  if (h->GetDimension() > 1) {
826  if (!option[0]) strlcpy(loption,"lego1",32);
827  const TArrayD *ybins = yaxis->GetXbins();
828  if (xbins->fN != 0 && ybins->fN != 0) {
829  fHistogram = new TH2F(GetName(),GetTitle(),
830  xaxis->GetNbins(), xbins->GetArray(),
831  yaxis->GetNbins(), ybins->GetArray());
832  } else if (xbins->fN != 0 && ybins->fN == 0) {
833  fHistogram = new TH2F(GetName(),GetTitle(),
834  xaxis->GetNbins(), xbins->GetArray(),
835  yaxis->GetNbins(), ymin, ymax);
836  } else if (xbins->fN == 0 && ybins->fN != 0) {
837  fHistogram = new TH2F(GetName(),GetTitle(),
838  xaxis->GetNbins(), xmin, xmax,
839  yaxis->GetNbins(), ybins->GetArray());
840  } else {
841  fHistogram = new TH2F(GetName(),GetTitle(),
842  xaxis->GetNbins(), xmin, xmax,
843  yaxis->GetNbins(), ymin, ymax);
844  }
845  } else {
846  if (xbins->fN != 0) {
847  fHistogram = new TH1F(GetName(),GetTitle(),
848  xaxis->GetNbins(), xbins->GetArray());
849  } else {
850  fHistogram = new TH1F(GetName(),GetTitle(),xaxis->GetNbins(),xmin, xmax);
851  }
852  }
853  fHistogram->SetStats(0);
854  TH1::AddDirectory(add);
855  } else {
857  }
858 
859  if (nostack) {*nostack = 0; strncat(nostack,nostack+7,7);}
860  if (nostackb) {*nostackb = 0; strncat(nostackb,nostackb+8,8);}
862 
864  if (nostack && fMaximum != -1111) fHistogram->SetMaximum(fMaximum);
865  else {
866  if (gPad->GetLogy()) fHistogram->SetMaximum(themax*(1+0.2*TMath::Log10(themax/themin)));
867  else fHistogram->SetMaximum((1+gStyle->GetHistTopMargin())*themax);
868  }
869  if (nostack && fMinimum != -1111) fHistogram->SetMinimum(fMinimum);
870  else {
871  if (gPad->GetLogy()) fHistogram->SetMinimum(themin/(1+0.5*TMath::Log10(themax/themin)));
872  else fHistogram->SetMinimum(themin);
873  }
874  }
875 
876  // Copy the axis labels if needed.
877  TH1 *hfirst;
879  hfirst = (TH1*)lnk->GetObject();
880  THashList* labels = hfirst->GetXaxis()->GetLabels();
881  if (labels) {
882  TIter iL(labels);
883  TObjString* lb;
884  Int_t ilab = 1;
885  while ((lb=(TObjString*)iL())) {
886  fHistogram->GetXaxis()->SetBinLabel(ilab,lb->String().Data());
887  ilab++;
888  }
889  }
890 
891  if (!lsame) fHistogram->Paint(loption);
892 
893  if (fHistogram->GetDimension() > 1) SetDrawOption(loption);
894  if (strstr(loption,"lego")) return;
895 
896  char noption[32];
897  strlcpy(noption,loption,32);
898  Int_t nhists = fHists->GetSize();
899  if (nostack || candle || violin) {
900  lnk = (TObjOptLink*)fHists->FirstLink();
901  TH1* hAti;
902  Double_t bo=0.03;
903  Double_t bw = (1.-(2*bo))/nhists;
904  for (Int_t i=0;i<nhists;i++) {
905  if (strstr(lnk->GetOption(),"same")) {
906  if (nostackb) snprintf(loption,31,"%s%s b",noption,lnk->GetOption());
907  else snprintf(loption,31,"%s%s",noption,lnk->GetOption());
908  } else {
909  TString indivOpt = lnk->GetOption();
910  indivOpt.ToLower();
911  if (nostackb) snprintf(loption,31,"%ssame%s b",noption,lnk->GetOption());
912  else if (candle && (indivOpt.Contains("candle") || indivOpt.Contains("violin"))) snprintf(loption,31,"%ssame",lnk->GetOption());
913  else snprintf(loption,31,"%ssame%s",noption,lnk->GetOption());
914  }
915  hAti = (TH1F*)(fHists->At(i));
916  if (nostackb) {
917  hAti->SetBarWidth(bw);
918  hAti->SetBarOffset(bo);
919  bo += bw;
920  }
921  if (candle || violin) {
922  float candleSpace = 1./(nhists*2);
923  float candleOffset = - 1./2 + candleSpace + 2*candleSpace*i;
924  candleSpace *= 1.66; //width of the candle per bin: 1.0 means space is as great as the candle, 2.0 means there is no space
925  hAti->SetBarWidth(candleSpace);
926  hAti->SetBarOffset(candleOffset);
927  }
928  hAti->Paint(loption);
929  lnk = (TObjOptLink*)lnk->Next();
930  }
931  } else {
932  lnk = (TObjOptLink*)fHists->LastLink();
933  TH1 *h1;
934  Int_t h1col, h1fill;
935  for (Int_t i=0;i<nhists;i++) {
936  if (strstr(lnk->GetOption(),"same")) {
937  snprintf(loption,31,"%s%s",noption,lnk->GetOption());
938  } else {
939  snprintf(loption,31,"%ssame%s",noption,lnk->GetOption());
940  }
941  h1 = (TH1*)fStack->At(nhists-i-1);
942  if (i>0 && lclear) {
943  // Erase before drawing the histogram
944  h1col = h1->GetFillColor();
945  h1fill = h1->GetFillStyle();
946  h1->SetFillColor(10);
947  h1->SetFillStyle(1001);
948  h1->Paint(loption);
949  static TClassRef clTFrame = TClass::GetClass("TFrame",kFALSE);
950  TAttFill *frameFill = (TAttFill*)clTFrame->DynamicCast(TAttFill::Class(),gPad->GetFrame());
951  if (frameFill) {
952  h1->SetFillColor(frameFill->GetFillColor());
953  h1->SetFillStyle(frameFill->GetFillStyle());
954  }
955  h1->Paint(loption);
956  h1->SetFillColor(h1col);
957  h1->SetFillStyle(h1fill);
958  }
959  h1->Paint(loption);
960  lnk = (TObjOptLink*)lnk->Prev();
961  }
962  }
963 
964  opt.ReplaceAll("nostack","");
965  opt.ReplaceAll("candle","");
966  if (!lsame && !opt.Contains("a")) fHistogram->Paint("axissame");
967 }
968 
969 ////////////////////////////////////////////////////////////////////////////////
970 /// Print the list of histograms
971 
972 void THStack::Print(Option_t *option) const
973 {
974  TH1 *h;
975  if (fHists) {
976  TIter next(fHists);
977  while ((h = (TH1*) next())) {
978  h->Print(option);
979  }
980  }
981 }
982 
983 ////////////////////////////////////////////////////////////////////////////////
984 /// Recursively remove object from the list of histograms
985 
987 {
988  if (!fHists) return;
990  while (fHists->IndexOf(obj) >= 0) fHists->Remove(obj);
991 }
992 
993 ////////////////////////////////////////////////////////////////////////////////
994 /// Save primitive as a C++ statement(s) on output stream out
995 
996 void THStack::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
997 {
998  char quote = '"';
999  out<<" "<<std::endl;
1000  if (gROOT->ClassSaved(THStack::Class())) {
1001  out<<" ";
1002  } else {
1003  out<<" THStack *";
1004  }
1005  out<<GetName()<<" = new THStack();"<<std::endl;
1006  out<<" "<<GetName()<<"->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
1007  out<<" "<<GetName()<<"->SetTitle("<<quote<<GetTitle()<<quote<<");"<<std::endl;
1008 
1009  if (fMinimum != -1111) {
1010  out<<" "<<GetName()<<"->SetMinimum("<<fMinimum<<");"<<std::endl;
1011  }
1012  if (fMaximum != -1111) {
1013  out<<" "<<GetName()<<"->SetMaximum("<<fMaximum<<");"<<std::endl;
1014  }
1015 
1016  static Int_t frameNumber = 0;
1017  if (fHistogram) {
1018  frameNumber++;
1019  TString hname = fHistogram->GetName();
1020  hname += "_stack_";
1021  hname += frameNumber;
1022  fHistogram->SetName(hname.Data());
1023  fHistogram->SavePrimitive(out,"nodraw");
1024  out<<" "<<GetName()<<"->SetHistogram("<<fHistogram->GetName()<<");"<<std::endl;
1025  out<<" "<<std::endl;
1026  }
1027 
1028  TH1 *h;
1029  if (fHists) {
1031  Int_t hcount = 0;
1032  while (lnk) {
1033  h = (TH1*)lnk->GetObject();
1034  TString hname = h->GetName();
1035  hname += Form("_stack_%d",++hcount);
1036  h->SetName(hname);
1037  h->SavePrimitive(out,"nodraw");
1038  out<<" "<<GetName()<<"->Add("<<h->GetName()<<","<<quote<<lnk->GetOption()<<quote<<");"<<std::endl;
1039  lnk = (TObjOptLink*)lnk->Next();
1040  }
1041  }
1042  out<<" "<<GetName()<<"->Draw("
1043  <<quote<<option<<quote<<");"<<std::endl;
1044 }
1045 
1046 ////////////////////////////////////////////////////////////////////////////////
1047 /// Set maximum.
1048 
1049 void THStack::SetMaximum(Double_t maximum)
1050 {
1051  fMaximum = maximum;
1053 }
1054 
1055 ////////////////////////////////////////////////////////////////////////////////
1056 /// Set minimum.
1057 
1058 void THStack::SetMinimum(Double_t minimum)
1059 {
1060  fMinimum = minimum;
1062 }
1063 
1064 
1065 ////////////////////////////////////////////////////////////////////////////////
1066 /// Get iterator over internal hists list.
1067 TIter THStack::begin() const
1068 {
1069  return TIter(fHists);
TString fTitle
Definition: TNamed.h:33
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TH1.cxx:6598
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void Print(Option_t *option="") const
Print some global quantities for this histogram.
Definition: TH1.cxx:6451
virtual void Print(Option_t *chopt="") const
Print the list of histograms.
Definition: THStack.cxx:975
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition: TH1.cxx:7807
virtual void RecursiveRemove(TObject *obj)
Recursively remove object from the list of histograms.
Definition: THStack.cxx:989
virtual void Paint(Option_t *option="")
Control routine to paint any kind of histograms.
Definition: TH1.cxx:5663
An array of TObjects.
Definition: TObjArray.h:37
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition: TROOT.cxx:2683
float xmin
Definition: THbookFile.cxx:93
Double_t fMinimum
Definition: THStack.h:40
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:444
long long Long64_t
Definition: RtypesCore.h:69
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:390
TH1 * GetHistogram() const
Returns a pointer to the histogram used to draw the axis Takes into account the two following cases...
Definition: THStack.cxx:479
The Histogram stack class.
Definition: THStack.h:31
virtual TH1 * Project3D(Option_t *option="x") const
Project a 3-d histogram into 1 or 2-d histograms depending on the option parameter, which may contain a combination of the characters x,y,z,e.
Definition: TH3.cxx:2201
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition: TH1.cxx:4224
Collectable string class.
Definition: TObjString.h:28
void ws()
Definition: ws.C:62
const char Option_t
Definition: RtypesCore.h:62
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:355
return c1
Definition: legend1.C:41
float ymin
Definition: THbookFile.cxx:93
const Ssiz_t kNPOS
Definition: RtypesCore.h:111
Double_t GetHistTopMargin() const
Definition: TStyle.h:223
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:638
TH1D * ProjectionY(const char *name="_py", Int_t firstxbin=0, Int_t lastxbin=-1, Option_t *option="") const
Project a 2-D histogram into a 1-D histogram along Y.
Definition: TH2.cxx:2328
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
const Double_t * GetArray() const
Definition: TArrayD.h:43
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:285
TH1 * h
Definition: legend2.C:5
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4763
TAxis * GetXaxis() const
Get x axis of the histogram used to draw the stack.
Definition: THStack.cxx:604
virtual Int_t GetEntries() const
Definition: TCollection.h:177
TH1D * ProjectionX(const char *name="_px", Int_t firstybin=0, Int_t lastybin=-1, Option_t *option="") const
Project a 2-D histogram into a 1-D histogram along X.
Definition: TH2.cxx:2288
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:391
#define gROOT
Definition: TROOT.h:402
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
Basic string class.
Definition: TString.h:125
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Definition: TH1.cxx:705
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:567
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: THStack.cxx:999
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:168
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1099
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Long64_t Merge(TCollection *li, TFileMergeInfo *info)
Merge the THStack in the TList into this stack.
Definition: THStack.cxx:643
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:57
TObject * At(Int_t idx) const
Definition: TObjArray.h:165
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:448
bit set when zooming on Y axis
Definition: TH1.h:164
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition: TH1.cxx:1225
if object in a list can be deleted
Definition: TObject.h:58
virtual void SetBarWidth(Float_t width=0.5)
Definition: TH1.h:353
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:105
virtual Int_t GetDimension() const
Definition: TH1.h:277
Double_t GetXmin() const
Definition: TAxis.h:133
Fill Area Attributes class.
Definition: TAttFill.h:19
Double_t fMaximum
Definition: THStack.h:39
virtual void Paint(Option_t *chopt="")
Paint the list of histograms.
Definition: THStack.cxx:700
void Class()
Definition: Class.C:29
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
virtual Double_t GetMaximum(Option_t *option="")
returns the maximum of all added histograms returns the maximum of all histograms if option "nostack"...
Definition: THStack.cxx:494
TObjArray * GetStack()
Return pointer to Stack. Build it if not yet done.
Definition: THStack.cxx:591
const Double_t * GetBuffer() const
Definition: TH1.h:233
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
THashList * GetLabels() const
Definition: TAxis.h:117
Double_t Log10(Double_t x)
Definition: TMath.h:651
virtual void ls(Option_t *option="") const
List histograms in the stack.
Definition: THStack.cxx:630
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
virtual void Modified()
invalidate sum of histograms
Definition: THStack.cxx:666
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:477
TList * fHists
Definition: THStack.h:36
TH1F * h1
Definition: legend1.C:5
virtual ~THStack()
THStack destructor.
Definition: THStack.cxx:323
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:49
The 3-D histogram classes derived from the 1-D histogram classes.
Definition: TH3.h:31
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to each graph.
Definition: THStack.cxx:410
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:341
A doubly linked list.
Definition: TList.h:44
void BuildStack()
build sum of all histograms Build a separate list fStack containing the running sum of all histograms...
Definition: THStack.cxx:387
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a line.
Definition: TH1.cxx:2707
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Int_t fN
Definition: TArray.h:38
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum.
Definition: THStack.cxx:1061
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis from bin first to last.
Definition: TAxis.cxx:903
float ymax
Definition: THbookFile.cxx:93
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:455
Service class for 2-Dim histogram classes.
Definition: TH2.h:30
Class to manage histogram axis.
Definition: TAxis.h:30
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2969
TList * GetHists() const
Definition: THStack.h:60
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
TObjArray * fStack
Definition: THStack.h:37
TIter begin() const
Get iterator over internal hists list.
Definition: THStack.cxx:1070
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
Collection abstract base class.
Definition: TCollection.h:63
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
char * Form(const char *fmt,...)
Ssiz_t Length() const
Definition: TString.h:386
virtual void Clear(Option_t *option="")=0
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2746
virtual void SetStack(TList *stack)=0
TAxis * GetYaxis()
Definition: TH1.h:316
THStack()
THStack default constructor.
Definition: THStack.cxx:116
virtual TList * GetListOfPrimitives() const =0
float xmax
Definition: THbookFile.cxx:93
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:354
TString fName
Definition: TNamed.h:32
TString & String()
Definition: TObjString.h:49
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TObjArray.cxx:253
virtual TObjLink * FirstLink() const
Definition: TList.h:108
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
Definition: TH1.cxx:7892
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual void SetName(const char *name)
Change the name of this histogram.
Definition: TH1.cxx:8217
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Definition: TObject.cxx:519
virtual void Browse(TBrowser *b)
Browse.
Definition: THStack.cxx:377
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
virtual void ls(Option_t *option="") const
List (ls) all objects in this collection.
TNamed()
Definition: TNamed.h:36
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
Definition: THStack.cxx:362
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:570
The TH1 histogram class.
Definition: TH1.h:56
#define R__LOCKGUARD(mutex)
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:809
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2887
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:399
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 if errors are defined (see TH1::Sumw2), errors are also recalculated.
Definition: TH1.cxx:777
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)=0
TAxis * GetZaxis()
Definition: TH1.h:317
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:144
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:29
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition: TROOT.cxx:2738
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition: TList.cxx:760
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
TAxis * GetYaxis() const
Get x axis of the histogram used to draw the stack.
Definition: THStack.cxx:619
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
#define snprintf
Definition: civetweb.c:822
#define gPad
Definition: TVirtualPad.h:285
virtual Int_t BufferEmpty(Int_t action=0)
Fill histogram with all entries in the buffer.
Definition: TH1.cxx:1346
virtual TObjLink * LastLink() const
Definition: TList.h:111
void Add(TObject *obj)
Definition: TObjArray.h:73
Int_t GetNhists() const
Return the number of histograms in the stack.
Definition: THStack.cxx:582
void * DynamicCast(const TClass *base, void *obj, Bool_t up=kTRUE)
Cast obj of this class type up to baseclass cl if up is true.
Definition: TClass.cxx:4729
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6154
Definition: first.py:1
Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TBrowser.h:104
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:31
Double_t Sqrt(Double_t x)
Definition: TMath.h:590
Int_t GetNbins() const
Definition: TAxis.h:121
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition: TObject.cxx:677
virtual Int_t GetSize() const
Definition: TCollection.h:180
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:291
Bool_t IsWhitespace() const
Definition: TString.h:384
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum.
Definition: THStack.cxx:1052
const Bool_t kTRUE
Definition: RtypesCore.h:87
Double_t GetXmax() const
Definition: TAxis.h:134
virtual Double_t GetMinimum(Option_t *option="")
returns the minimum of all added histograms returns the minimum of all histograms if option "nostack"...
Definition: THStack.cxx:538
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8247
char name[80]
Definition: TGX11.cxx:109
const TArrayD * GetXbins() const
Definition: TAxis.h:130
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315
Long64_t Merge(TCollection *list)
Merge this collection with all collections coming in the input list.
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8319
virtual Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
const char * Data() const
Definition: TString.h:345
TH1 * fHistogram
Pointer to array of sums of TH1.
Definition: THStack.h:38