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.
39Using THStack::Draw() the histogram collection is drawn in one go according
40to the drawing option.
41
42THStack::Add() allows to add a new histogram to the list.
43The THStack does not own the objects in the list.
44
45\anchor HS00
46### Stack painting
47
48By default, histograms are shown stacked.
49 - the first histogram is paint
50 - then the sum of the first and second, etc
51
52The axis ranges are computed automatically along the X and Y axis in
53order to show the complete histogram collection.
54
55### Stack's drawing options
56
57The specific stack's drawing options are:
58
59 - **NOSTACK** If option "nostack" is specified, histograms are all painted in the same pad
60 as if the option "same" had been specified.
61
62 - **NOSTACKB** If the option "nostackb" is specified histograms are all painted in the same pad
63 next to each other as bar plots.
64
65 - **PADS** if option "pads" is specified, the current pad/canvas is subdivided into
66 a number of pads equal to the number of histograms and each histogram
67 is painted into a separate pad.
68
69 - **NOCLEAR** By default the background of the histograms is erased before drawing the
70 histograms. The option "noclear" avoid this behaviour. This is useful
71 when drawing a THStack on top of an other plot. If the patterns used to
72 draw the histograms in the stack are transparents, then the plot behind
73 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
326 {
328 gROOT->GetListOfCleanups()->Remove(this);
329 }
330 if (!fHists) return;
331
332 fHists->Clear("nodelete");
333 delete fHists;
334 fHists = nullptr;
335 if (fStack) {
336 fStack->Delete();
337 delete fStack;
338 fStack = nullptr;
339 }
340 delete fHistogram;
341 fHistogram = nullptr;
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// THStack copy constructor
346
347THStack::THStack(const THStack &hstack) :
348 TNamed(hstack),
349 fMaximum(hstack.fMaximum),
350 fMinimum(hstack.fMinimum)
351{
352 if (hstack.GetHists()) {
353 TIter next(hstack.GetHists());
354 TH1 *h;
355 while ((h=(TH1*)next())) Add(h);
356 }
357}
358
359////////////////////////////////////////////////////////////////////////////////
360/// add a new histogram to the list
361/// Only 1-d and 2-d histograms currently supported.
362/// A drawing option may be specified
363
365{
366 if (!h1) return;
367 if (h1->GetDimension() > 2) {
368 Error("Add","THStack supports only 1-d and 2-d histograms");
369 return;
370 }
371 if (!fHists) fHists = new TList();
373 Modified(); //invalidate stack
374}
375
376////////////////////////////////////////////////////////////////////////////////
377/// Browse.
378
380{
381 Draw(b ? b->GetDrawOption() : "");
382 gPad->Update();
383}
384
385////////////////////////////////////////////////////////////////////////////////
386/// build sum of all histograms
387/// Build a separate list fStack containing the running sum of all histograms
388
390{
391 if (fStack) return;
392 if (!fHists) return;
393 Int_t nhists = fHists->GetSize();
394 if (!nhists) return;
395 fStack = new TObjArray(nhists);
398 TH1 *h = (TH1*)fHists->At(0)->Clone();
399 fStack->Add(h);
400 for (Int_t i=1;i<nhists;i++) {
401 h = (TH1*)fHists->At(i)->Clone();
402 h->Add((TH1*)fStack->At(i-1));
403 fStack->AddAt(h,i);
404 }
406}
407
408////////////////////////////////////////////////////////////////////////////////
409/// Compute distance from point px,py to each graph
410///
411
413{
414 //*-*- Are we on the axis?
415 const Int_t kMaxDiff = 10;
416 Int_t distance = 9999;
417 if (fHistogram) {
418 distance = fHistogram->DistancetoPrimitive(px,py);
419 if (distance <= 0) {return distance;}
420 if (distance <= 1) {gPad->SetSelected(fHistogram);return distance;}
421 }
422
423
424 //*-*- Loop on the list of histograms
425 if (!fHists) return distance;
426 const char *doption = GetDrawOption();
427 Int_t nhists = fHists->GetSize();
428 for (Int_t i=0;i<nhists;i++) {
429 TH1 *h = (TH1*)fHists->At(i);
430 if (fStack && !strstr(doption,"nostack")) h = (TH1*)fStack->At(i);
431 Int_t dist = h->DistancetoPrimitive(px,py);
432 if (dist <= 0) return 0;
433 if (dist < kMaxDiff) {
434 gPad->SetSelected(fHists->At(i));
435 gPad->SetCursor(kPointer);
436 return dist;
437 }
438 }
439 return distance;
440}
441
442////////////////////////////////////////////////////////////////////////////////
443/// Draw this multihist with its current attributes.
444///
445/// Options to draw histograms are described in THistPainter::Paint
446/// By default (if option "nostack" is not specified), histograms will be paint
447/// stacked on top of each other.
448
450{
451 TString opt = option;
452 opt.ToLower();
453 if (gPad) {
454 if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
455 if (!opt.Contains("same")) {
456 //the following statement is necessary in case one attempts to draw
457 //a temporary histogram already in the current pad
458 if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
459 gPad->Clear();
460 }
461 }
462 AppendPad(opt.Data());
463}
464
465////////////////////////////////////////////////////////////////////////////////
466/// Returns a pointer to the histogram used to draw the axis
467/// Takes into account the two following cases.
468/// 1- option 'A' was specified in THStack::Draw. Return fHistogram
469/// 2- user had called TPad::DrawFrame. return pointer to hframe histogram
470///
471/// IMPORTANT NOTES
472/// - You must call Draw before calling this function. The returned histogram
473/// depends on the selected Draw options.
474/// - This function returns a pointer to an intermediate fixed bin size
475/// histogram used to set the range and for picking.
476/// You cannot use this histogram to return the bin information.
477/// You must get a pointer to one of the histograms in the stack,
478/// the first one, for example.
479
481{
482 if (fHistogram) return fHistogram;
483 if (!gPad) return nullptr;
484 gPad->Modified();
485 gPad->Update();
486 if (fHistogram) return fHistogram;
487 return (TH1*)gPad->FindObject("hframe");
488}
489
490////////////////////////////////////////////////////////////////////////////////
491/// returns the maximum of all added histograms
492/// returns the maximum of all histograms if option "nostack".
493
495{
496 TString opt = option;
497 opt.ToLower();
498 Bool_t lerr = kFALSE;
499 if (opt.Contains("e")) lerr = kTRUE;
500 Double_t them=0, themax = -1e300, c1, e1;
501 if (!fHists) return 0;
502 Int_t nhists = fHists->GetSize();
503 TH1 *h;
504 Int_t first,last;
505
506 if (!opt.Contains("nostack")) {
507 BuildStack();
508 h = (TH1*)fStack->At(nhists-1);
509 if (fHistogram) h->GetXaxis()->SetRange(fHistogram->GetXaxis()->GetFirst(),
511 themax = h->GetMaximum();
512 } else {
513 for (Int_t i=0;i<nhists;i++) {
514 h = (TH1*)fHists->At(i);
515 if (fHistogram) h->GetXaxis()->SetRange(fHistogram->GetXaxis()->GetFirst(),
517 them = h->GetMaximum();
518 if (fHistogram) h->GetXaxis()->SetRange(0,0);
519 if (them > themax) themax = them;
520 }
521 }
522
523 if (lerr) {
524 for (Int_t i=0;i<nhists;i++) {
525 h = (TH1*)fHists->At(i);
526 first = h->GetXaxis()->GetFirst();
527 last = h->GetXaxis()->GetLast();
528 for (Int_t j=first; j<=last;j++) {
529 e1 = h->GetBinError(j);
530 c1 = h->GetBinContent(j);
531 themax = TMath::Max(themax,c1+e1);
532 }
533 }
534 }
535
536 return themax;
537}
538
539////////////////////////////////////////////////////////////////////////////////
540/// returns the minimum of all added histograms
541/// returns the minimum of all histograms if option "nostack".
542
544{
545 TString opt = option;
546 opt.ToLower();
547 Bool_t lerr = kFALSE;
548 if (opt.Contains("e")) lerr = kTRUE;
549 Double_t them=0, themin = 1e300, c1, e1;
550 if (!fHists) return 0;
551 Int_t nhists = fHists->GetSize();
552 Int_t first,last;
553 TH1 *h;
554
555 if (!opt.Contains("nostack")) {
556 BuildStack();
557 h = (TH1*)fStack->At(nhists-1);
558 themin = h->GetMinimum();
559 } else {
560 for (Int_t i=0;i<nhists;i++) {
561 h = (TH1*)fHists->At(i);
562 them = h->GetMinimum();
563 if (them <= 0 && gPad && gPad->GetLogy()) them = h->GetMinimum(0);
564 if (them < themin) themin = them;
565 }
566 }
567
568 if (lerr) {
569 for (Int_t i=0;i<nhists;i++) {
570 h = (TH1*)fHists->At(i);
571 first = h->GetXaxis()->GetFirst();
572 last = h->GetXaxis()->GetLast();
573 for (Int_t j=first; j<=last;j++) {
574 e1 = h->GetBinError(j);
575 c1 = h->GetBinContent(j);
576 themin = TMath::Min(themin,c1-e1);
577 }
578 }
579 }
580
581 return themin;
582}
583
584////////////////////////////////////////////////////////////////////////////////
585/// Return the number of histograms in the stack
586
588{
589 if (fHists) return fHists->GetSize();
590 return 0;
591}
592
593////////////////////////////////////////////////////////////////////////////////
594/// Return pointer to Stack. Build it if not yet done
595
597{
598 BuildStack();
599 return fStack;
600}
601
602////////////////////////////////////////////////////////////////////////////////
603/// Get x axis of the histogram used to draw the stack.
604///
605/// IMPORTANT NOTE
606/// You must call Draw before calling this function. The returned histogram
607/// depends on the selected Draw options.
608
610{
611 if (!gPad) return nullptr;
612 TH1 *h = GetHistogram();
613 if (!h) return nullptr;
614 return h->GetXaxis();
615}
616
617////////////////////////////////////////////////////////////////////////////////
618/// Get y axis of the histogram used to draw the stack.
619///
620/// IMPORTANT NOTE
621/// You must call Draw before calling this function. The returned histogram
622/// depends on the selected Draw options.
623
625{
626 if (!gPad) return nullptr;
627 TH1 *h = GetHistogram();
628 if (!h) return nullptr;
629 return h->GetYaxis();
630}
631
632////////////////////////////////////////////////////////////////////////////////
633/// Get 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 if (!gPad) return nullptr;
642 TH1 *h = GetHistogram();
643 if (!h->IsA()->InheritsFrom(TH2::Class())) Warning("THStack","1D Histograms don't have a Z axis");
644 if (!h) return nullptr;
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==0 || 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/// invalidate 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 TH1* hAti;
728 TH1* hsAti;
729 Int_t nhists = fHists->GetSize();
730 Int_t ic;
731 gPad->IncrementPaletteColor(nhists, opt1);
732 for (Int_t i=0;i<nhists;i++) {
733 ic = gPad->NextPaletteColor();
734 hAti = (TH1F*)(fHists->At(i));
735 if (l1) hAti->SetFillColor(ic);
736 if (l2) hAti->SetLineColor(ic);
737 if (l3) hAti->SetMarkerColor(ic);
738 if (fStack) {
739 hsAti = (TH1*)fStack->At(i);
740 if (l1) hsAti->SetFillColor(ic);
741 if (l2) hsAti->SetLineColor(ic);
742 if (l3) hsAti->SetMarkerColor(ic);
743 }
744 }
745 }
746
747 TString opt = option;
748 opt.ToLower();
749 opt.ReplaceAll(" ","");
750 Bool_t lsame = kFALSE;
751 if (opt.Contains("same")) {
752 lsame = kTRUE;
753 opt.ReplaceAll("same","");
754 }
755 Bool_t lclear = kTRUE;
756 if (opt.Contains("noclear")) {
757 lclear = kFALSE;
758 opt.ReplaceAll("noclear","");
759 }
760 if (opt.Contains("pads")) {
761 Int_t npads = fHists->GetSize();
762 TVirtualPad *padsav = gPad;
763 //if pad is not already divided into subpads, divide it
764 Int_t nps = 0;
765 TObject *obj;
766 TIter nextp(padsav->GetListOfPrimitives());
767 while ((obj = nextp())) {
768 if (obj->InheritsFrom(TVirtualPad::Class())) nps++;
769 }
770 if (nps < npads) {
771 padsav->Clear();
772 Int_t nx = (Int_t)TMath::Sqrt((Double_t)npads);
773 if (nx*nx < npads) nx++;
774 Int_t ny = nx;
775 if (((nx*ny)-nx) >= npads) ny--;
776 padsav->Divide(nx,ny);
777
778 Int_t i = 0;
779 auto lnk = fHists->FirstLink();
780 while (lnk) {
781 i++;
782 padsav->cd(i);
783 lnk->GetObject()->Draw(lnk->GetOption());
784 lnk = lnk->Next();
785 }
786 padsav->cd();
787 }
788 return;
789 }
790
791 // compute the min/max of each axis
792 TH1 *h;
793 TIter next(fHists);
794 Double_t xmin = 1e100;
795 Double_t xmax = -xmin;
796 Double_t ymin = 1e100;
797 Double_t ymax = -xmin;
798 while ((h=(TH1*)next())) {
799 // in case of automatic binning
800 if (h->GetBuffer()) h->BufferEmpty(-1);
801 if (h->GetXaxis()->GetXmin() < xmin) xmin = h->GetXaxis()->GetXmin();
802 if (h->GetXaxis()->GetXmax() > xmax) xmax = h->GetXaxis()->GetXmax();
803 if (h->GetYaxis()->GetXmin() < ymin) ymin = h->GetYaxis()->GetXmin();
804 if (h->GetYaxis()->GetXmax() > ymax) ymax = h->GetYaxis()->GetXmax();
805 }
806
807 TString loption = opt;
808 Bool_t nostack = loption.Contains("nostack");
809 Bool_t nostackb = loption.Contains("nostackb");
810 Bool_t candle = loption.Contains("candle");
811 Bool_t violin = loption.Contains("violin");
812
813 // do not delete the stack. Another pad may contain the same object
814 // drawn in stack mode!
815 //if (nostack && fStack) {fStack->Delete(); delete fStack; fStack = 0;}
816
817 if (!nostack && !candle && !violin) BuildStack();
818
819 Double_t themax,themin;
820 if (fMaximum == -1111) themax = GetMaximum(option);
821 else themax = fMaximum;
822 if (fMinimum == -1111) {
823 themin = GetMinimum(option);
824 if (gPad->GetLogy()){
825 if (themin>0) themin *= .9;
826 else themin = themax*1.e-3;
827 }
828 else if (themin > 0)
829 themin = 0;
830 }
831 else themin = fMinimum;
832 if (!fHistogram) {
835 h = (TH1*)fHists->At(0);
836 TAxis *xaxis = h->GetXaxis();
837 TAxis *yaxis = h->GetYaxis();
838 const TArrayD *xbins = xaxis->GetXbins();
839 if (h->GetDimension() > 1) {
840 if (loption.IsNull()) loption = "lego1";
841 const TArrayD *ybins = yaxis->GetXbins();
842 if (xbins->fN != 0 && ybins->fN != 0) {
844 xaxis->GetNbins(), xbins->GetArray(),
845 yaxis->GetNbins(), ybins->GetArray());
846 } else if (xbins->fN != 0 && ybins->fN == 0) {
848 xaxis->GetNbins(), xbins->GetArray(),
849 yaxis->GetNbins(), ymin, ymax);
850 } else if (xbins->fN == 0 && ybins->fN != 0) {
852 xaxis->GetNbins(), xmin, xmax,
853 yaxis->GetNbins(), ybins->GetArray());
854 } else {
856 xaxis->GetNbins(), xmin, xmax,
857 yaxis->GetNbins(), ymin, ymax);
858 }
859 } else {
860 if (xbins->fN != 0) {
862 xaxis->GetNbins(), xbins->GetArray());
863 } else {
864 fHistogram = new TH1F(GetName(),GetTitle(),xaxis->GetNbins(),xmin, xmax);
865 }
866 }
869 } else {
871 }
872
873 if (nostackb) {
874 loption.ReplaceAll("nostackb","");
875 } else {
876 if (nostack) loption.ReplaceAll("nostack","");
878 }
879
881 if (nostack && fMaximum != -1111) fHistogram->SetMaximum(fMaximum);
882 else {
883 if (gPad->GetLogy()) fHistogram->SetMaximum(themax*(1+0.2*TMath::Log10(themax/themin)));
884 else {
885 if (fMaximum != -1111) fHistogram->SetMaximum(themax);
886 else fHistogram->SetMaximum((1+gStyle->GetHistTopMargin())*themax);
887 }
888 }
889 if (nostack && fMinimum != -1111) fHistogram->SetMinimum(fMinimum);
890 else {
891 if (gPad->GetLogy()) fHistogram->SetMinimum(themin/(1+0.5*TMath::Log10(themax/themin)));
892 else fHistogram->SetMinimum(themin);
893 }
894 }
895
896 // Copy the axis labels if needed.
897 TH1 *hfirst = (TH1*)fHists->First();
898 THashList* labels = hfirst->GetXaxis()->GetLabels();
899 if (labels) {
900 TIter iL(labels);
901 Int_t ilab = 1;
902 while (auto lb=(TObjString*)iL()) {
903 fHistogram->GetXaxis()->SetBinLabel(ilab,lb->String().Data());
904 ilab++;
905 }
906 }
907
908 // Set fHistogram attributes and paint it.
909 if (!lsame) {
911 if (paint)
912 fHistogram->Paint(loption.Data());
913 }
914
915 if (fHistogram->GetDimension() > 1)
916 SetDrawOption(loption.Data());
917 if (loption.Index("lego")>=0)
918 return;
919
920 char noption[32];
921 strlcpy(noption,loption.Data(),32);
922 Int_t nhists = fHists->GetSize();
923 if (nostack || candle || violin) {
924 auto lnk = fHists->FirstLink();
925 Double_t bo = 0.03;
926 Double_t bw = (1.-(2*bo))/nhists;
927 for (Int_t i=0;i<nhists;i++) {
928 if (strstr(lnk->GetOption(),"same")) {
929 if (nostackb) loption.Form("%s%s b",noption,lnk->GetOption());
930 else loption.Form("%s%s",noption,lnk->GetOption());
931 } else {
932 TString indivOpt = lnk->GetOption();
933 indivOpt.ToLower();
934 if (nostackb) loption.Form("%ssame%s b",noption,lnk->GetOption());
935 else if (candle && (indivOpt.Contains("candle") || indivOpt.Contains("violin"))) loption.Form("%ssame",lnk->GetOption());
936 else loption.Form("%ssame%s",noption,lnk->GetOption());
937 }
938 TH1* hAti = (TH1*) fHists->At(i);
939 if (nostackb) {
940 hAti->SetBarWidth(bw);
941 hAti->SetBarOffset(bo);
942 bo += bw;
943 }
944 if (candle || violin) {
945 float candleSpace = 1./(nhists*2);
946 float candleOffset = - 1./2 + candleSpace + 2*candleSpace*i;
947 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
948 hAti->SetBarWidth(candleSpace);
949 hAti->SetBarOffset(candleOffset);
950 }
951 if (paint)
952 hAti->Paint(loption.Data());
953 lnk = lnk->Next();
954 }
955 } else {
956 auto lnk = fHists->LastLink();
957 Int_t h1col, h1fill;
958 for (Int_t i=0;i<nhists;i++) {
959 if (strstr(lnk->GetOption(),"same")) {
960 loption.Form("%s%s",noption,lnk->GetOption());
961 } else {
962 loption.Form("%ssame%s",noption,lnk->GetOption());
963 }
964 TH1 *h1 = (TH1*) fStack->At(nhists-i-1);
965 if ((i > 0) && lclear && paint) {
966 // Erase before drawing the histogram
967 h1col = h1->GetFillColor();
968 h1fill = h1->GetFillStyle();
969 h1->SetFillColor(10);
970 h1->SetFillStyle(1001);
971 h1->Paint(loption.Data());
972 static TClassRef clTFrame = TClass::GetClass("TFrame", kFALSE);
973 TAttFill *frameFill = (TAttFill*)clTFrame->DynamicCast(TAttFill::Class(),gPad->GetFrame());
974 if (frameFill) {
975 h1->SetFillColor(frameFill->GetFillColor());
976 h1->SetFillStyle(frameFill->GetFillStyle());
977 }
978 h1->Paint(loption.Data());
979 h1->SetFillColor(h1col);
980 h1->SetFillStyle(h1fill);
981 }
982 if (paint)
983 h1->Paint(loption.Data());
984 lnk = lnk->Prev();
985 }
986 }
987
988 opt.ReplaceAll("nostack","");
989 opt.ReplaceAll("candle","");
990 if (!lsame && !opt.Contains("a") && paint)
991 fHistogram->Paint("axissame");
992}
993
994////////////////////////////////////////////////////////////////////////////////
995/// Print the list of histograms
996
998{
999 TH1 *h;
1000 if (fHists) {
1001 TIter next(fHists);
1002 while ((h = (TH1*) next())) {
1003 h->Print(option);
1004 }
1005 }
1006}
1007
1008////////////////////////////////////////////////////////////////////////////////
1009/// Recursively remove object from the list of histograms
1010
1012{
1013 if (!fHists) return;
1014 fHists->RecursiveRemove(obj);
1015 while (fHists->IndexOf(obj) >= 0) fHists->Remove(obj);
1016}
1017
1018////////////////////////////////////////////////////////////////////////////////
1019/// Save primitive as a C++ statement(s) on output stream out
1020
1021void THStack::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1022{
1023 char quote = '"';
1024 out<<" "<<std::endl;
1025 if (gROOT->ClassSaved(THStack::Class())) {
1026 out<<" ";
1027 } else {
1028 out<<" THStack *";
1029 }
1030 out<<GetName()<<" = new THStack();"<<std::endl;
1031 out<<" "<<GetName()<<"->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
1032 out<<" "<<GetName()<<"->SetTitle("<<quote<<GetTitle()<<quote<<");"<<std::endl;
1033
1034 if (fMinimum != -1111) {
1035 out<<" "<<GetName()<<"->SetMinimum("<<fMinimum<<");"<<std::endl;
1036 }
1037 if (fMaximum != -1111) {
1038 out<<" "<<GetName()<<"->SetMaximum("<<fMaximum<<");"<<std::endl;
1039 }
1040
1041 static Int_t frameNumber = 0;
1042 if (fHistogram) {
1043 frameNumber++;
1044 TString hname = fHistogram->GetName();
1045 fHistogram->SetName(TString::Format("%s_stack_%d", hname.Data(), frameNumber).Data());
1046 fHistogram->SavePrimitive(out,"nodraw");
1047 out<<" "<<GetName()<<"->SetHistogram("<<fHistogram->GetName()<<");"<<std::endl;
1048 out<<" "<<std::endl;
1049 fHistogram->SetName(hname.Data()); // restore histogram name
1050 }
1051
1052 if (fHists) {
1053 auto lnk = fHists->FirstLink();
1054 Int_t hcount = 0;
1055 while (lnk) {
1056 auto h = (TH1 *) lnk->GetObject();
1057 TString hname = h->GetName();
1058 h->SetName(TString::Format("%s_stack_%d", hname.Data(), ++hcount).Data());
1059 h->SavePrimitive(out,"nodraw");
1060 out<<" "<<GetName()<<"->Add("<<h->GetName()<<","<<quote<<lnk->GetOption()<<quote<<");"<<std::endl;
1061 lnk = lnk->Next();
1062 h->SetName(hname.Data()); // restore histogram name
1063 }
1064 }
1065 out<<" "<<GetName()<<"->Draw("<<quote<<option<<quote<<");"<<std::endl;
1066}
1067
1068////////////////////////////////////////////////////////////////////////////////
1069/// Set maximum.
1070
1072{
1073 fMaximum = maximum;
1074 if (fHistogram) fHistogram->SetMaximum(maximum);
1075}
1076
1077////////////////////////////////////////////////////////////////////////////////
1078/// Set minimum.
1079
1081{
1082 fMinimum = minimum;
1083 if (fHistogram) fHistogram->SetMinimum(minimum);
1084}
1085
1086
1087////////////////////////////////////////////////////////////////////////////////
1088/// Get iterator over internal hists list.
1090{
1091 return TIter(fHists);
1092}
@ 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:405
R__EXTERN TStyle * gStyle
Definition TStyle.h:414
#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
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
Class to manage histogram axis.
Definition TAxis.h:30
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition TAxis.cxx:851
const TArrayD * GetXbins() const
Definition TAxis.h:131
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:469
Int_t GetNbins() const
Definition TAxis.h:121
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:952
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition TAxis.cxx:458
THashList * GetLabels() const
Definition TAxis.h:117
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:577
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
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:361
TAxis * GetZaxis()
Definition TH1.h:324
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a line.
Definition TH1.cxx:2798
void SetTitle(const char *title) override
Change (i.e.
Definition TH1.cxx:6700
virtual Int_t GetDimension() const
Definition TH1.h:281
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition TH1.cxx:1267
@ kIsZoomed
Bit set when zooming on Y axis.
Definition TH1.h:167
TAxis * GetXaxis()
Definition TH1.h:322
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition TH1.cxx:4484
TObject * FindObject(const char *name) const override
Search object named name in the list of functions.
Definition TH1.cxx:3853
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:400
TAxis * GetYaxis()
Definition TH1.h:323
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:401
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TH1.cxx:7147
void SetName(const char *name) override
Change the name of this histogram.
Definition TH1.cxx:8826
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
Definition TH1.cxx:6188
TClass * IsA() const override
Definition TH1.h:440
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Definition TH1.cxx:735
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:362
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8856
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:257
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:2414
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:2374
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:2363
The Histogram stack class.
Definition THStack.h:38
TIter begin() const
Get iterator over internal hists list.
Definition THStack.cxx:1089
TClass * IsA() const override
Definition THStack.h:91
~THStack() override
THStack destructor.
Definition THStack.cxx:323
THStack()
Definition THStack.h:55
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:44
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:47
void BuildStack()
build sum of all histograms Build a separate list fStack containing the running sum of all histograms
Definition THStack.cxx:389
TList * GetHists() const
Definition THStack.h:70
TAxis * GetYaxis() const
Get y axis of the histogram used to draw the stack.
Definition THStack.cxx:624
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 Takes into account the two following cases.
Definition THStack.cxx:480
virtual Double_t GetMaximum(Option_t *option="")
returns the maximum of all added histograms returns the maximum of all histograms if option "nostack"...
Definition THStack.cxx:494
void RecursiveRemove(TObject *obj) override
Recursively remove object from the list of histograms.
Definition THStack.cxx:1011
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
Definition THStack.cxx:364
void Print(Option_t *chopt="") const override
Print the list of histograms.
Definition THStack.cxx:997
TObjArray * GetStack()
Return pointer to Stack. Build it if not yet done.
Definition THStack.cxx:596
Int_t GetNhists() const
Return the number of histograms in the stack.
Definition THStack.cxx:587
virtual Double_t GetMinimum(Option_t *option="")
returns the minimum of all added histograms returns the minimum of all histograms if option "nostack"...
Definition THStack.cxx:543
void Draw(Option_t *chopt="") override
Draw this multihist with its current attributes.
Definition THStack.cxx:449
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:43
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum.
Definition THStack.cxx:1071
TH1 * fHistogram
Pointer to histogram used for drawing axis.
Definition THStack.h:45
TAxis * GetZaxis() const
Get 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:1021
void Browse(TBrowser *b) override
Browse.
Definition THStack.cxx:379
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:412
virtual void Modified()
invalidate sum of histograms
Definition THStack.cxx:687
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum.
Definition THStack.cxx:1080
TAxis * GetXaxis() const
Get x axis of the histogram used to draw the stack.
Definition THStack.cxx:609
Double_t fMaximum
Maximum value for plotting along y.
Definition THStack.h:46
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:402
virtual TObjLink * LastLink() const
Definition TList.h:105
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition TList.cxx:764
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:822
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:659
virtual TObjLink * FirstLink() const
Definition TList.h:102
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:357
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:201
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:423
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:956
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:184
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:970
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition TObject.cxx:758
@ 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:2826
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2834
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2713
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:421
void ToLower()
Change string to lower-case.
Definition TString.cxx:1170
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:531
const char * Data() const
Definition TString.h:380
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
Bool_t IsNull() const
Definition TString.h:418
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:2356
Bool_t IsWhitespace() const
Definition TString.h:419
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2334
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
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:230
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:660
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:760
Definition first.py:1
th1 Draw()