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