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")) {
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 = kFALSE;
503 if (opt.Contains("e")) lerr = kTRUE;
504 Double_t them = 0, themax = -std::numeric_limits<Double_t>::max(), c1, e1;
505 if (!fHists) return 0;
506 Int_t nhists = fHists->GetSize();
507 TH1 *h;
508 Int_t first,last;
509
510 if (!opt.Contains("nostack")) {
511 BuildStack();
512 h = (TH1*)fStack->At(nhists-1);
513 if (fHistogram) h->GetXaxis()->SetRange(fHistogram->GetXaxis()->GetFirst(),
515 themax = h->GetMaximum(maxval);
516 } else {
517 for (Int_t i=0;i<nhists;i++) {
518 h = (TH1*)fHists->At(i);
519 if (fHistogram) h->GetXaxis()->SetRange(fHistogram->GetXaxis()->GetFirst(),
521 them = h->GetMaximum(maxval);
522 if (fHistogram) h->GetXaxis()->SetRange(0,0);
523 if (them > themax) themax = them;
524 }
525 }
526
527 if (lerr) {
528 for (Int_t i=0;i<nhists;i++) {
529 h = (TH1*)fHists->At(i);
530 first = h->GetXaxis()->GetFirst();
531 last = h->GetXaxis()->GetLast();
532 for (Int_t j=first; j<=last;j++) {
533 e1 = h->GetBinError(j);
534 c1 = h->GetBinContent(j);
535 themax = TMath::Max(themax,c1+e1);
536 }
537 }
538 }
539
540 return themax;
541}
542
543////////////////////////////////////////////////////////////////////////////////
544/// Returns the minimum of all added histograms larger than minval.
545/// Returns the minimum of all histograms, larger than minval, if option "nostack".
546
548{
549 TString opt = option;
550 opt.ToLower();
551 Bool_t lerr = kFALSE;
552 if (opt.Contains("e")) lerr = kTRUE;
553 Double_t them = 0, themin = std::numeric_limits<Double_t>::max(), c1, e1;
554 if (!fHists) return 0;
555 Int_t nhists = fHists->GetSize();
556 Int_t first,last;
557 TH1 *h;
558
559 if (!opt.Contains("nostack")) {
560 BuildStack();
561 h = (TH1*)fStack->At(nhists-1);
562 themin = h->GetMinimum(minval);
563 } else {
564 for (Int_t i=0;i<nhists;i++) {
565 h = (TH1*)fHists->At(i);
566 them = h->GetMinimum(minval);
567 if (them <= 0 && gPad && gPad->GetLogy()) them = h->GetMinimum(0);
568 if (them < themin) themin = them;
569 }
570 }
571
572 if (lerr) {
573 for (Int_t i=0;i<nhists;i++) {
574 h = (TH1*)fHists->At(i);
575 first = h->GetXaxis()->GetFirst();
576 last = h->GetXaxis()->GetLast();
577 for (Int_t j=first; j<=last;j++) {
578 e1 = h->GetBinError(j);
579 c1 = h->GetBinContent(j);
580 themin = TMath::Min(themin,c1-e1);
581 }
582 }
583 }
584
585 return themin;
586}
587
588////////////////////////////////////////////////////////////////////////////////
589/// Return the number of histograms in the stack
590
592{
593 if (fHists) return fHists->GetSize();
594 return 0;
595}
596
597////////////////////////////////////////////////////////////////////////////////
598/// Return pointer to Stack. Build it if not yet done.
599
601{
602 BuildStack();
603 return fStack;
604}
605
606////////////////////////////////////////////////////////////////////////////////
607/// Get the x-axis of the histogram used to draw the stack.
608///
609/// IMPORTANT NOTE
610/// You must call Draw before calling this function. The returned histogram
611/// depends on the selected Draw options.
612
614{
615 TH1 *h = GetHistogram();
616 return h ? h->GetXaxis() : nullptr;
617}
618
619////////////////////////////////////////////////////////////////////////////////
620/// Get the y-axis of the histogram used to draw the stack.
621///
622/// IMPORTANT NOTE
623/// You must call Draw before calling this function. The returned histogram
624/// depends on the selected Draw options.
625
627{
628 TH1 *h = GetHistogram();
629 return h ? h->GetYaxis() : nullptr;
630}
631
632////////////////////////////////////////////////////////////////////////////////
633/// Get the z-axis of the histogram used to draw the stack.
634///
635/// IMPORTANT NOTE
636/// You must call Draw before calling this function. The returned histogram
637/// depends on the selected Draw options.
638
640{
641 TH1 *h = GetHistogram();
642 if (!h) return nullptr;
643 if (h->GetDimension() == 1)
644 Warning("GetZaxis","1D Histograms don't have a Z axis");
645 return h->GetZaxis();
646}
647
648////////////////////////////////////////////////////////////////////////////////
649/// List histograms in the stack.
650
652{
654 std::cout <<IsA()->GetName()
655 <<" Name= "<<GetName()<<" Title= "<<GetTitle()<<" Option="<<option<<std::endl;
657 if (fHists) fHists->ls(option);
659}
660////////////////////////////////////////////////////////////////////////////////
661/// Merge the THStack in the TList into this stack.
662/// Returns the total number of histograms in the result or -1 in case of an error.
663
665{
666 if (li==nullptr || li->GetEntries()==0) {
667 return fHists->GetEntries();
668 }
669 TIter next(li);
670 TList histLists;
671 while (TObject* o = next()) {
672 THStack *stack = dynamic_cast<THStack*> (o);
673 if (!stack) {
674 Error("Merge",
675 "Cannot merge - an object which doesn't inherit from THStack found in the list");
676 return -1;
677 }
678 histLists.Add(stack->GetHists());
679 }
680 fHists->Merge(&histLists);
681 return fHists->GetEntries();
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// Note: this method invalidates the sum of histograms.
686
688{
689 if (!fStack) return;
690 fStack->Delete();
691 delete fStack;
692 fStack = nullptr;
693 delete fHistogram;
694 fHistogram = nullptr;
695}
696
697////////////////////////////////////////////////////////////////////////////////
698/// [Paint the list of histograms.](#HS00)
699
701{
702 BuildAndPaint(chopt, kTRUE);
703}
704
705////////////////////////////////////////////////////////////////////////////////
706/// Create all additional objects and stack (if specified).
707
709{
710 if (!fHists) return;
711 if (!fHists->GetSize()) return;
712
713 char option[128];
714 strlcpy(option,choptin,128);
715
716 // Automatic color
717 char *l1 = strstr(option,"pfc"); // Automatic Fill Color
718 char *l2 = strstr(option,"plc"); // Automatic Line Color
719 char *l3 = strstr(option,"pmc"); // Automatic Marker Color
720 if (l1 || l2 || l3) {
721 TString opt1 = option;
722 if (l1) memcpy(l1," ",3);
723 if (l2) memcpy(l2," ",3);
724 if (l3) memcpy(l3," ",3);
725 TString ws = option;
726 if (ws.IsWhitespace()) strncpy(option,"\0",1);
727 Int_t nhists = fHists->GetSize();
728 gPad->IncrementPaletteColor(nhists, opt1);
729 for (Int_t i = 0; i < nhists; i++) {
730 auto ic = gPad->NextPaletteColor();
731 auto hAti = static_cast<TH1 *>(fHists->At(i));
732 if (l1) hAti->SetFillColor(ic);
733 if (l2) hAti->SetLineColor(ic);
734 if (l3) hAti->SetMarkerColor(ic);
735 if (fStack) {
736 auto hsAti = static_cast<TH1 *>(fStack->At(i));
737 if (l1) hsAti->SetFillColor(ic);
738 if (l2) hsAti->SetLineColor(ic);
739 if (l3) hsAti->SetMarkerColor(ic);
740 }
741 }
742 }
743
744 TString opt = option;
745 opt.ToLower();
746 opt.ReplaceAll(" ","");
747 Bool_t lsame = kFALSE;
748 if (opt.Contains("same")) {
749 lsame = kTRUE;
750 opt.ReplaceAll("same","");
751 }
752 Bool_t lclear = kTRUE;
753 if (opt.Contains("noclear")) {
754 lclear = kFALSE;
755 opt.ReplaceAll("noclear","");
756 }
757 if (opt.Contains("pads")) {
758 Int_t npads = fHists->GetSize();
759 TVirtualPad *padsav = gPad;
760 //if pad is not already divided into subpads, divide it
761 Int_t nps = 0;
762 TIter nextp(padsav->GetListOfPrimitives());
763 while (auto obj = nextp()) {
764 if (obj->InheritsFrom(TVirtualPad::Class())) nps++;
765 }
766 if (nps < npads) {
767 padsav->Clear();
768 Int_t nx = (Int_t)TMath::Sqrt((Double_t)npads);
769 if (nx*nx < npads) nx++;
770 Int_t ny = nx;
771 if (((nx*ny)-nx) >= npads) ny--;
772 padsav->Divide(nx,ny);
773
774 Int_t i = 0;
775 auto lnk = fHists->FirstLink();
776 while (lnk) {
777 i++;
778 padsav->cd(i);
779 lnk->GetObject()->Draw(lnk->GetOption());
780 lnk = lnk->Next();
781 }
782 padsav->cd();
783 }
784 return;
785 }
786
787 // compute the min/max of each axis
788 TH1 *h;
789 TIter next(fHists);
790 Double_t xmin = 1e100;
791 Double_t xmax = -xmin;
792 Double_t ymin = 1e100;
793 Double_t ymax = -xmin;
794 while ((h=(TH1*)next())) {
795 // in case of automatic binning
796 if (h->GetBuffer()) h->BufferEmpty(-1);
797 if (h->GetXaxis()->GetXmin() < xmin) xmin = h->GetXaxis()->GetXmin();
798 if (h->GetXaxis()->GetXmax() > xmax) xmax = h->GetXaxis()->GetXmax();
799 if (h->GetYaxis()->GetXmin() < ymin) ymin = h->GetYaxis()->GetXmin();
800 if (h->GetYaxis()->GetXmax() > ymax) ymax = h->GetYaxis()->GetXmax();
801 }
802
803 TString loption = opt;
804 Bool_t nostack = loption.Contains("nostack");
805 Bool_t nostackb = loption.Contains("nostackb");
806 Bool_t candle = loption.Contains("candle");
807 Bool_t violin = loption.Contains("violin");
808
809 // do not delete the stack. Another pad may contain the same object
810 // drawn in stack mode!
811 //if (nostack && fStack) {fStack->Delete(); delete fStack; fStack = 0;}
812
813 if (!nostack && !candle && !violin) BuildStack();
814
815 Double_t themax,themin;
816 if (fMaximum == -1111) themax = GetMaximum(option);
817 else themax = fMaximum;
818 if (fMinimum == -1111) {
819 themin = GetMinimum(option);
820 if (gPad->GetLogy()){
821 if (themin>0) themin *= .9;
822 else themin = themax*1.e-3;
823 }
824 else if (themin > 0)
825 themin = 0;
826 }
827 else themin = fMinimum;
828 if (!fHistogram) {
831 h = (TH1*)fHists->At(0);
832 TAxis *xaxis = h->GetXaxis();
833 TAxis *yaxis = h->GetYaxis();
834 const TArrayD *xbins = xaxis->GetXbins();
835 if (h->GetDimension() > 1) {
836 if (loption.IsNull()) loption = "lego1";
837 const TArrayD *ybins = yaxis->GetXbins();
838 if (xbins->fN != 0 && ybins->fN != 0) {
840 xaxis->GetNbins(), xbins->GetArray(),
841 yaxis->GetNbins(), ybins->GetArray());
842 } else if (xbins->fN != 0 && ybins->fN == 0) {
844 xaxis->GetNbins(), xbins->GetArray(),
845 yaxis->GetNbins(), ymin, ymax);
846 } else if (xbins->fN == 0 && ybins->fN != 0) {
848 xaxis->GetNbins(), xmin, xmax,
849 yaxis->GetNbins(), ybins->GetArray());
850 } else {
852 xaxis->GetNbins(), xmin, xmax,
853 yaxis->GetNbins(), ymin, ymax);
854 }
855 } else {
856 if (xbins->fN != 0) {
858 xaxis->GetNbins(), xbins->GetArray());
859 } else {
860 fHistogram = new TH1F(GetName(),GetTitle(),xaxis->GetNbins(),xmin, xmax);
861 }
862 }
863 fHistogram->SetStats(false);
865 } else {
867 }
868
869 if (nostackb) {
870 loption.ReplaceAll("nostackb","");
871 } else {
872 if (nostack) loption.ReplaceAll("nostack","");
874 }
875
877 if (nostack && fMaximum != -1111) fHistogram->SetMaximum(fMaximum);
878 else {
879 if (gPad->GetLogy()) fHistogram->SetMaximum(themax*(1+0.2*TMath::Log10(themax/themin)));
880 else {
881 if (fMaximum != -1111) fHistogram->SetMaximum(themax);
882 else fHistogram->SetMaximum((1+gStyle->GetHistTopMargin())*themax);
883 }
884 }
885 if (nostack && fMinimum != -1111) fHistogram->SetMinimum(fMinimum);
886 else {
887 if (gPad->GetLogy()) fHistogram->SetMinimum(themin/(1+0.5*TMath::Log10(themax/themin)));
888 else fHistogram->SetMinimum(themin);
889 }
890 }
891
892 // Copy the axis labels if needed.
893 TH1 *hfirst = (TH1*)fHists->First();
894 THashList* labels = hfirst->GetXaxis()->GetLabels();
895 if (labels) {
896 TIter iL(labels);
897 Int_t ilab = 1;
898 while (auto lb=(TObjString*)iL()) {
899 fHistogram->GetXaxis()->SetBinLabel(ilab,lb->String().Data());
900 ilab++;
901 }
902 }
903
904 // Set fHistogram attributes and paint it.
905 if (!lsame) {
907 if (paint)
908 fHistogram->Paint(loption.Data());
909 }
910
911 if (fHistogram->GetDimension() > 1)
912 SetDrawOption(loption.Data());
913 if (loption.Index("lego")>=0)
914 return;
915
916 char noption[32];
917 strlcpy(noption,loption.Data(),32);
918 Int_t nhists = fHists->GetSize();
919 if (nostack || candle || violin) {
920 auto lnk = fHists->FirstLink();
921 Double_t bo = 0.03;
922 Double_t bw = (1.-(2*bo))/nhists;
923 for (Int_t i=0;i<nhists;i++) {
924 if (strstr(lnk->GetOption(),"same")) {
925 if (nostackb) loption.Form("%s%s b",noption,lnk->GetOption());
926 else loption.Form("%s%s",noption,lnk->GetOption());
927 } else {
928 TString indivOpt = lnk->GetOption();
929 indivOpt.ToLower();
930 if (nostackb) loption.Form("%ssame%s b",noption,lnk->GetOption());
931 else if (candle && (indivOpt.Contains("candle") || indivOpt.Contains("violin"))) loption.Form("%ssame",lnk->GetOption());
932 else loption.Form("%ssame%s",noption,lnk->GetOption());
933 }
934 TH1* hAti = (TH1*) fHists->At(i);
935 if (nostackb) {
936 hAti->SetBarWidth(bw);
937 hAti->SetBarOffset(bo);
938 bo += bw;
939 }
940 if (candle || violin) {
941 float candleSpace = 1./(nhists*2);
942 float candleOffset = - 1./2 + candleSpace + 2*candleSpace*i;
943 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
944 hAti->SetBarWidth(candleSpace);
945 hAti->SetBarOffset(candleOffset);
946 }
947 if (paint)
948 hAti->Paint(loption.Data());
949 lnk = lnk->Next();
950 }
951 } else {
952 auto lnk = fHists->LastLink();
953 Int_t h1col, h1fill;
954 for (Int_t i=0;i<nhists;i++) {
955 if (strstr(lnk->GetOption(),"same")) {
956 loption.Form("%s%s",noption,lnk->GetOption());
957 } else {
958 loption.Form("%ssame%s",noption,lnk->GetOption());
959 }
960 TH1 *h1 = (TH1*) fStack->At(nhists-i-1);
961 if ((i > 0) && lclear && paint) {
962 // Erase before drawing the histogram
963 h1col = h1->GetFillColor();
964 h1fill = h1->GetFillStyle();
965 h1->SetFillColor(10);
966 h1->SetFillStyle(1001);
967 h1->Paint(loption.Data());
968 static TClassRef clTFrame = TClass::GetClass("TFrame", kFALSE);
969 TAttFill *frameFill = (TAttFill*)clTFrame->DynamicCast(TAttFill::Class(),gPad->GetFrame());
970 if (frameFill) {
971 h1->SetFillColor(frameFill->GetFillColor());
972 h1->SetFillStyle(frameFill->GetFillStyle());
973 }
974 h1->Paint(loption.Data());
975 h1->SetFillColor(h1col);
976 h1->SetFillStyle(h1fill);
977 }
978 if (paint)
979 h1->Paint(loption.Data());
980 lnk = lnk->Prev();
981 }
982 }
983
984 opt.ReplaceAll("nostack","");
985 opt.ReplaceAll("candle","");
986 if (!lsame && !opt.Contains("a") && paint)
987 fHistogram->Paint("axissame");
988}
989
990////////////////////////////////////////////////////////////////////////////////
991/// Print the list of histograms
992
994{
995 TIter next(fHists);
996 while (auto h = next())
997 h->Print(option);
998}
999
1000////////////////////////////////////////////////////////////////////////////////
1001/// Recursively remove the object `obj` from the list of histograms.
1002
1004{
1005 if (!fHists) return;
1006 fHists->RecursiveRemove(obj);
1007 while (fHists->IndexOf(obj) >= 0) fHists->Remove(obj);
1008}
1009
1010////////////////////////////////////////////////////////////////////////////////
1011/// Save primitive as a C++ statement(s) on output stream out.
1012
1013void THStack::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1014{
1015 char quote = '"';
1016 out<<" "<<std::endl;
1017 if (gROOT->ClassSaved(THStack::Class())) {
1018 out<<" ";
1019 } else {
1020 out<<" THStack *";
1021 }
1022 out<<GetName()<<" = new THStack();"<<std::endl;
1023 out<<" "<<GetName()<<"->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
1024 out<<" "<<GetName()<<"->SetTitle("<<quote<<GetTitle()<<quote<<");"<<std::endl;
1025
1026 if (fMinimum != -1111) {
1027 out<<" "<<GetName()<<"->SetMinimum("<<fMinimum<<");"<<std::endl;
1028 }
1029 if (fMaximum != -1111) {
1030 out<<" "<<GetName()<<"->SetMaximum("<<fMaximum<<");"<<std::endl;
1031 }
1032
1033 static Int_t frameNumber = 0;
1034 if (fHistogram) {
1035 frameNumber++;
1036 TString hname = fHistogram->GetName();
1037 fHistogram->SetName(TString::Format("%s_stack_%d", hname.Data(), frameNumber).Data());
1038 fHistogram->SavePrimitive(out,"nodraw");
1039 out<<" "<<GetName()<<"->SetHistogram("<<fHistogram->GetName()<<");"<<std::endl;
1040 out<<" "<<std::endl;
1041 fHistogram->SetName(hname.Data()); // restore histogram name
1042 }
1043
1044 if (fHists) {
1045 auto lnk = fHists->FirstLink();
1046 Int_t hcount = 0;
1047 while (lnk) {
1048 auto h = (TH1 *) lnk->GetObject();
1049 TString hname = h->GetName();
1050 h->SetName(TString::Format("%s_stack_%d", hname.Data(), ++hcount).Data());
1051 h->SavePrimitive(out,"nodraw");
1052 out<<" "<<GetName()<<"->Add("<<h->GetName()<<","<<quote<<lnk->GetOption()<<quote<<");"<<std::endl;
1053 lnk = lnk->Next();
1054 h->SetName(hname.Data()); // restore histogram name
1055 }
1056 }
1057 out<<" "<<GetName()<<"->Draw("<<quote<<option<<quote<<");"<<std::endl;
1058}
1059
1060////////////////////////////////////////////////////////////////////////////////
1061/// Set maximum.
1062
1064{
1065 fMaximum = maximum;
1066 if (fHistogram) fHistogram->SetMaximum(maximum);
1067}
1068
1069////////////////////////////////////////////////////////////////////////////////
1070/// Set minimum.
1071
1073{
1074 fMinimum = minimum;
1075 if (fHistogram) fHistogram->SetMinimum(minimum);
1076}
1077
1078
1079////////////////////////////////////////////////////////////////////////////////
1080/// Get an iterator over internal hists list.
1082{
1083 return TIter(fHists);
1084}
@ 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:101
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:124
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
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:407
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:2412
The Histogram stack class.
Definition THStack.h:40
TIter begin() const
Get an iterator over internal hists list.
Definition THStack.cxx:1081
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:547
void ls(Option_t *option="") const override
List histograms in the stack.
Definition THStack.cxx:651
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:708
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:626
virtual Long64_t Merge(TCollection *li, TFileMergeInfo *info)
Merge the THStack in the TList into this stack.
Definition THStack.cxx:664
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:1003
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:993
TObjArray * GetStack()
Return pointer to Stack. Build it if not yet done.
Definition THStack.cxx:600
Int_t GetNhists() const
Return the number of histograms in the stack.
Definition THStack.cxx:591
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:700
TList * fHists
Pointer to array of TH1.
Definition THStack.h:45
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum.
Definition THStack.cxx:1063
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:639
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition THStack.cxx:1013
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:687
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum.
Definition THStack.cxx:1072
TAxis * GetXaxis() const
Get the x-axis of the histogram used to draw the stack.
Definition THStack.cxx:613
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:2869
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2877
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
void Draw(Option_t *option="") override=0
Default Draw method for all objects.
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()