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