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 {
326 gROOT->GetListOfCleanups()->Remove(this);
327 }
328 if (fHists) {
329 fHists->Clear("nodelete");
330 delete fHists;
331 fHists = nullptr;
332 }
333 if (fStack) {
334 fStack->Delete();
335 delete fStack;
336 fStack = nullptr;
337 }
338 delete fHistogram;
339 fHistogram = nullptr;
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// THStack copy constructor
344
345THStack::THStack(const THStack &hstack) :
346 TNamed(hstack),
347 fMaximum(hstack.fMaximum),
348 fMinimum(hstack.fMinimum)
349{
350 {
352 gROOT->GetListOfCleanups()->Add(this);
353 }
354
355 TIter next(hstack.GetHists());
356 while (auto h = static_cast<TH1 *>(next()))
357 Add(h);
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// add a new histogram to the list
362/// Only 1-d and 2-d histograms currently supported.
363/// A drawing option may be specified
364
366{
367 if (!h1) return;
368 if (h1->GetDimension() > 2) {
369 Error("Add","THStack supports only 1-d and 2-d histograms");
370 return;
371 }
372 if (!fHists) fHists = new TList();
374 Modified(); //invalidate stack
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// Browse.
379
381{
382 Draw(b ? b->GetDrawOption() : "");
383 gPad->Update();
384}
385
386////////////////////////////////////////////////////////////////////////////////
387/// build sum of all histograms
388/// Build a separate list fStack containing the running sum of all histograms
389
391{
392 if (fStack) return;
393 if (!fHists) return;
394 Int_t nhists = fHists->GetSize();
395 if (!nhists) return;
396 fStack = new TObjArray(nhists);
399 TH1 *h = (TH1*)fHists->At(0)->Clone();
400 fStack->Add(h);
401 for (Int_t i=1;i<nhists;i++) {
402 h = (TH1*)fHists->At(i)->Clone();
403 h->Add((TH1*)fStack->At(i-1));
404 fStack->AddAt(h,i);
405 }
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Compute distance from point px,py to each graph
411///
412
414{
415 //*-*- Are we on the axis?
416 const Int_t kMaxDiff = 10;
417 Int_t distance = 9999;
418 if (fHistogram) {
419 distance = fHistogram->DistancetoPrimitive(px,py);
420 if (distance <= 0) {return distance;}
421 if (distance <= 1) {gPad->SetSelected(fHistogram);return distance;}
422 }
423
424
425 //*-*- Loop on the list of histograms
426 if (!fHists) return distance;
427 const char *doption = GetDrawOption();
428 Int_t nhists = fHists->GetSize();
429 for (Int_t i=0;i<nhists;i++) {
430 TH1 *h = (TH1*)fHists->At(i);
431 if (fStack && !strstr(doption,"nostack")) h = (TH1*)fStack->At(i);
432 Int_t dist = h->DistancetoPrimitive(px,py);
433 if (dist <= 0) return 0;
434 if (dist < kMaxDiff) {
435 gPad->SetSelected(fHists->At(i));
436 gPad->SetCursor(kPointer);
437 return dist;
438 }
439 }
440 return distance;
441}
442
443////////////////////////////////////////////////////////////////////////////////
444/// Draw this multihist with its current attributes.
445///
446/// Options to draw histograms are described in THistPainter::Paint
447/// By default (if option "nostack" is not specified), histograms will be paint
448/// stacked on top of each other.
449
451{
452 TString opt = option;
453 opt.ToLower();
454 if (gPad) {
455 if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
456 if (!opt.Contains("same")) {
457 //the following statement is necessary in case one attempts to draw
458 //a temporary histogram already in the current pad
459 if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
460 gPad->Clear();
461 }
462 }
463 AppendPad(opt.Data());
464}
465
466////////////////////////////////////////////////////////////////////////////////
467/// Returns a pointer to the histogram used to draw the axis
468/// Takes into account the two following cases.
469/// 1- option 'A' was specified in THStack::Draw. Return fHistogram
470/// 2- user had called TPad::DrawFrame. return pointer to hframe histogram
471///
472/// IMPORTANT NOTES
473/// - You must call Draw before calling this function. The returned histogram
474/// depends on the selected Draw options.
475/// - This function returns a pointer to an intermediate fixed bin size
476/// histogram used to set the range and for picking.
477/// You cannot use this histogram to return the bin information.
478/// You must get a pointer to one of the histograms in the stack,
479/// the first one, for example.
480
482{
483 if (fHistogram) return fHistogram;
484 if (!gPad) return nullptr;
485 gPad->Modified();
486 gPad->Update();
487 if (fHistogram) return fHistogram;
488 return (TH1*)gPad->FindObject("hframe");
489}
490
491////////////////////////////////////////////////////////////////////////////////
492/// returns the maximum of all added histograms smaller than maxval.
493/// returns the maximum of all histograms, smaller than maxval, if option "nostack".
494
496{
497 TString opt = option;
498 opt.ToLower();
499 Bool_t lerr = kFALSE;
500 if (opt.Contains("e")) lerr = kTRUE;
501 Double_t them = 0, themax = -std::numeric_limits<Double_t>::max(), c1, e1;
502 if (!fHists) return 0;
503 Int_t nhists = fHists->GetSize();
504 TH1 *h;
505 Int_t first,last;
506
507 if (!opt.Contains("nostack")) {
508 BuildStack();
509 h = (TH1*)fStack->At(nhists-1);
510 if (fHistogram) h->GetXaxis()->SetRange(fHistogram->GetXaxis()->GetFirst(),
512 themax = h->GetMaximum(maxval);
513 } else {
514 for (Int_t i=0;i<nhists;i++) {
515 h = (TH1*)fHists->At(i);
516 if (fHistogram) h->GetXaxis()->SetRange(fHistogram->GetXaxis()->GetFirst(),
518 them = h->GetMaximum(maxval);
519 if (fHistogram) h->GetXaxis()->SetRange(0,0);
520 if (them > themax) themax = them;
521 }
522 }
523
524 if (lerr) {
525 for (Int_t i=0;i<nhists;i++) {
526 h = (TH1*)fHists->At(i);
527 first = h->GetXaxis()->GetFirst();
528 last = h->GetXaxis()->GetLast();
529 for (Int_t j=first; j<=last;j++) {
530 e1 = h->GetBinError(j);
531 c1 = h->GetBinContent(j);
532 themax = TMath::Max(themax,c1+e1);
533 }
534 }
535 }
536
537 return themax;
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Returns the minimum of all added histograms larger than minval.
542/// Returns the minimum of all histograms, larger than minval, if option "nostack".
543
545{
546 TString opt = option;
547 opt.ToLower();
548 Bool_t lerr = kFALSE;
549 if (opt.Contains("e")) lerr = kTRUE;
550 Double_t them = 0, themin = std::numeric_limits<Double_t>::max(), c1, e1;
551 if (!fHists) return 0;
552 Int_t nhists = fHists->GetSize();
553 Int_t first,last;
554 TH1 *h;
555
556 if (!opt.Contains("nostack")) {
557 BuildStack();
558 h = (TH1*)fStack->At(nhists-1);
559 themin = h->GetMinimum(minval);
560 } else {
561 for (Int_t i=0;i<nhists;i++) {
562 h = (TH1*)fHists->At(i);
563 them = h->GetMinimum(minval);
564 if (them <= 0 && gPad && gPad->GetLogy()) them = h->GetMinimum(0);
565 if (them < themin) themin = them;
566 }
567 }
568
569 if (lerr) {
570 for (Int_t i=0;i<nhists;i++) {
571 h = (TH1*)fHists->At(i);
572 first = h->GetXaxis()->GetFirst();
573 last = h->GetXaxis()->GetLast();
574 for (Int_t j=first; j<=last;j++) {
575 e1 = h->GetBinError(j);
576 c1 = h->GetBinContent(j);
577 themin = TMath::Min(themin,c1-e1);
578 }
579 }
580 }
581
582 return themin;
583}
584
585////////////////////////////////////////////////////////////////////////////////
586/// Return the number of histograms in the stack
587
589{
590 if (fHists) return fHists->GetSize();
591 return 0;
592}
593
594////////////////////////////////////////////////////////////////////////////////
595/// Return pointer to Stack. Build it if not yet done
596
598{
599 BuildStack();
600 return fStack;
601}
602
603////////////////////////////////////////////////////////////////////////////////
604/// Get x axis of the histogram used to draw the stack.
605///
606/// IMPORTANT NOTE
607/// You must call Draw before calling this function. The returned histogram
608/// depends on the selected Draw options.
609
611{
612 TH1 *h = GetHistogram();
613 return h ? h->GetXaxis() : nullptr;
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 TH1 *h = GetHistogram();
626 return h ? h->GetYaxis() : nullptr;
627}
628
629////////////////////////////////////////////////////////////////////////////////
630/// Get z axis of the histogram used to draw the stack.
631///
632/// IMPORTANT NOTE
633/// You must call Draw before calling this function. The returned histogram
634/// depends on the selected Draw options.
635
637{
638 TH1 *h = GetHistogram();
639 if (!h) return nullptr;
640 if (h->GetDimension() == 1)
641 Warning("GetZaxis","1D Histograms don't have a Z axis");
642 return h->GetZaxis();
643}
644
645////////////////////////////////////////////////////////////////////////////////
646/// List histograms in the stack
647
649{
651 std::cout <<IsA()->GetName()
652 <<" Name= "<<GetName()<<" Title= "<<GetTitle()<<" Option="<<option<<std::endl;
654 if (fHists) fHists->ls(option);
656}
657////////////////////////////////////////////////////////////////////////////////
658/// Merge the THStack in the TList into this stack.
659/// Returns the total number of histograms in the result or -1 in case of an error.
660
662{
663 if (li==nullptr || li->GetEntries()==0) {
664 return fHists->GetEntries();
665 }
666 TIter next(li);
667 TList histLists;
668 while (TObject* o = next()) {
669 THStack *stack = dynamic_cast<THStack*> (o);
670 if (!stack) {
671 Error("Merge",
672 "Cannot merge - an object which doesn't inherit from THStack found in the list");
673 return -1;
674 }
675 histLists.Add(stack->GetHists());
676 }
677 fHists->Merge(&histLists);
678 return fHists->GetEntries();
679}
680
681////////////////////////////////////////////////////////////////////////////////
682/// invalidate sum of histograms
683
685{
686 if (!fStack) return;
687 fStack->Delete();
688 delete fStack;
689 fStack = nullptr;
690 delete fHistogram;
691 fHistogram = nullptr;
692}
693
694////////////////////////////////////////////////////////////////////////////////
695/// [Paint the list of histograms.](#HS00)
696
698{
699 BuildAndPaint(chopt, kTRUE);
700}
701
702////////////////////////////////////////////////////////////////////////////////
703/// Create all additional objects and stack (if specified)
704
706{
707 if (!fHists) return;
708 if (!fHists->GetSize()) return;
709
710 char option[128];
711 strlcpy(option,choptin,128);
712
713 // Automatic color
714 char *l1 = strstr(option,"pfc"); // Automatic Fill Color
715 char *l2 = strstr(option,"plc"); // Automatic Line Color
716 char *l3 = strstr(option,"pmc"); // Automatic Marker Color
717 if (l1 || l2 || l3) {
718 TString opt1 = option;
719 if (l1) memcpy(l1," ",3);
720 if (l2) memcpy(l2," ",3);
721 if (l3) memcpy(l3," ",3);
722 TString ws = option;
723 if (ws.IsWhitespace()) strncpy(option,"\0",1);
724 Int_t nhists = fHists->GetSize();
725 gPad->IncrementPaletteColor(nhists, opt1);
726 for (Int_t i = 0; i < nhists; i++) {
727 auto ic = gPad->NextPaletteColor();
728 auto hAti = static_cast<TH1 *>(fHists->At(i));
729 if (l1) hAti->SetFillColor(ic);
730 if (l2) hAti->SetLineColor(ic);
731 if (l3) hAti->SetMarkerColor(ic);
732 if (fStack) {
733 auto hsAti = static_cast<TH1 *>(fStack->At(i));
734 if (l1) hsAti->SetFillColor(ic);
735 if (l2) hsAti->SetLineColor(ic);
736 if (l3) hsAti->SetMarkerColor(ic);
737 }
738 }
739 }
740
741 TString opt = option;
742 opt.ToLower();
743 opt.ReplaceAll(" ","");
744 Bool_t lsame = kFALSE;
745 if (opt.Contains("same")) {
746 lsame = kTRUE;
747 opt.ReplaceAll("same","");
748 }
749 Bool_t lclear = kTRUE;
750 if (opt.Contains("noclear")) {
751 lclear = kFALSE;
752 opt.ReplaceAll("noclear","");
753 }
754 if (opt.Contains("pads")) {
755 Int_t npads = fHists->GetSize();
756 TVirtualPad *padsav = gPad;
757 //if pad is not already divided into subpads, divide it
758 Int_t nps = 0;
759 TIter nextp(padsav->GetListOfPrimitives());
760 while (auto obj = nextp()) {
761 if (obj->InheritsFrom(TVirtualPad::Class())) nps++;
762 }
763 if (nps < npads) {
764 padsav->Clear();
765 Int_t nx = (Int_t)TMath::Sqrt((Double_t)npads);
766 if (nx*nx < npads) nx++;
767 Int_t ny = nx;
768 if (((nx*ny)-nx) >= npads) ny--;
769 padsav->Divide(nx,ny);
770
771 Int_t i = 0;
772 auto lnk = fHists->FirstLink();
773 while (lnk) {
774 i++;
775 padsav->cd(i);
776 lnk->GetObject()->Draw(lnk->GetOption());
777 lnk = lnk->Next();
778 }
779 padsav->cd();
780 }
781 return;
782 }
783
784 // compute the min/max of each axis
785 TH1 *h;
786 TIter next(fHists);
787 Double_t xmin = 1e100;
788 Double_t xmax = -xmin;
789 Double_t ymin = 1e100;
790 Double_t ymax = -xmin;
791 while ((h=(TH1*)next())) {
792 // in case of automatic binning
793 if (h->GetBuffer()) h->BufferEmpty(-1);
794 if (h->GetXaxis()->GetXmin() < xmin) xmin = h->GetXaxis()->GetXmin();
795 if (h->GetXaxis()->GetXmax() > xmax) xmax = h->GetXaxis()->GetXmax();
796 if (h->GetYaxis()->GetXmin() < ymin) ymin = h->GetYaxis()->GetXmin();
797 if (h->GetYaxis()->GetXmax() > ymax) ymax = h->GetYaxis()->GetXmax();
798 }
799
800 TString loption = opt;
801 Bool_t nostack = loption.Contains("nostack");
802 Bool_t nostackb = loption.Contains("nostackb");
803 Bool_t candle = loption.Contains("candle");
804 Bool_t violin = loption.Contains("violin");
805
806 // do not delete the stack. Another pad may contain the same object
807 // drawn in stack mode!
808 //if (nostack && fStack) {fStack->Delete(); delete fStack; fStack = 0;}
809
810 if (!nostack && !candle && !violin) BuildStack();
811
812 Double_t themax,themin;
813 if (fMaximum == -1111) themax = GetMaximum(option);
814 else themax = fMaximum;
815 if (fMinimum == -1111) {
816 themin = GetMinimum(option);
817 if (gPad->GetLogy()){
818 if (themin>0) themin *= .9;
819 else themin = themax*1.e-3;
820 }
821 else if (themin > 0)
822 themin = 0;
823 }
824 else themin = fMinimum;
825 if (!fHistogram) {
828 h = (TH1*)fHists->At(0);
829 TAxis *xaxis = h->GetXaxis();
830 TAxis *yaxis = h->GetYaxis();
831 const TArrayD *xbins = xaxis->GetXbins();
832 if (h->GetDimension() > 1) {
833 if (loption.IsNull()) loption = "lego1";
834 const TArrayD *ybins = yaxis->GetXbins();
835 if (xbins->fN != 0 && ybins->fN != 0) {
837 xaxis->GetNbins(), xbins->GetArray(),
838 yaxis->GetNbins(), ybins->GetArray());
839 } else if (xbins->fN != 0 && ybins->fN == 0) {
841 xaxis->GetNbins(), xbins->GetArray(),
842 yaxis->GetNbins(), ymin, ymax);
843 } else if (xbins->fN == 0 && ybins->fN != 0) {
845 xaxis->GetNbins(), xmin, xmax,
846 yaxis->GetNbins(), ybins->GetArray());
847 } else {
849 xaxis->GetNbins(), xmin, xmax,
850 yaxis->GetNbins(), ymin, ymax);
851 }
852 } else {
853 if (xbins->fN != 0) {
855 xaxis->GetNbins(), xbins->GetArray());
856 } else {
857 fHistogram = new TH1F(GetName(),GetTitle(),xaxis->GetNbins(),xmin, xmax);
858 }
859 }
860 fHistogram->SetStats(false);
862 } else {
864 }
865
866 if (nostackb) {
867 loption.ReplaceAll("nostackb","");
868 } else {
869 if (nostack) loption.ReplaceAll("nostack","");
871 }
872
874 if (nostack && fMaximum != -1111) fHistogram->SetMaximum(fMaximum);
875 else {
876 if (gPad->GetLogy()) fHistogram->SetMaximum(themax*(1+0.2*TMath::Log10(themax/themin)));
877 else {
878 if (fMaximum != -1111) fHistogram->SetMaximum(themax);
879 else fHistogram->SetMaximum((1+gStyle->GetHistTopMargin())*themax);
880 }
881 }
882 if (nostack && fMinimum != -1111) fHistogram->SetMinimum(fMinimum);
883 else {
884 if (gPad->GetLogy()) fHistogram->SetMinimum(themin/(1+0.5*TMath::Log10(themax/themin)));
885 else fHistogram->SetMinimum(themin);
886 }
887 }
888
889 // Copy the axis labels if needed.
890 TH1 *hfirst = (TH1*)fHists->First();
891 THashList* labels = hfirst->GetXaxis()->GetLabels();
892 if (labels) {
893 TIter iL(labels);
894 Int_t ilab = 1;
895 while (auto lb=(TObjString*)iL()) {
896 fHistogram->GetXaxis()->SetBinLabel(ilab,lb->String().Data());
897 ilab++;
898 }
899 }
900
901 // Set fHistogram attributes and paint it.
902 if (!lsame) {
904 if (paint)
905 fHistogram->Paint(loption.Data());
906 }
907
908 if (fHistogram->GetDimension() > 1)
909 SetDrawOption(loption.Data());
910 if (loption.Index("lego")>=0)
911 return;
912
913 char noption[32];
914 strlcpy(noption,loption.Data(),32);
915 Int_t nhists = fHists->GetSize();
916 if (nostack || candle || violin) {
917 auto lnk = fHists->FirstLink();
918 Double_t bo = 0.03;
919 Double_t bw = (1.-(2*bo))/nhists;
920 for (Int_t i=0;i<nhists;i++) {
921 if (strstr(lnk->GetOption(),"same")) {
922 if (nostackb) loption.Form("%s%s b",noption,lnk->GetOption());
923 else loption.Form("%s%s",noption,lnk->GetOption());
924 } else {
925 TString indivOpt = lnk->GetOption();
926 indivOpt.ToLower();
927 if (nostackb) loption.Form("%ssame%s b",noption,lnk->GetOption());
928 else if (candle && (indivOpt.Contains("candle") || indivOpt.Contains("violin"))) loption.Form("%ssame",lnk->GetOption());
929 else loption.Form("%ssame%s",noption,lnk->GetOption());
930 }
931 TH1* hAti = (TH1*) fHists->At(i);
932 if (nostackb) {
933 hAti->SetBarWidth(bw);
934 hAti->SetBarOffset(bo);
935 bo += bw;
936 }
937 if (candle || violin) {
938 float candleSpace = 1./(nhists*2);
939 float candleOffset = - 1./2 + candleSpace + 2*candleSpace*i;
940 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
941 hAti->SetBarWidth(candleSpace);
942 hAti->SetBarOffset(candleOffset);
943 }
944 if (paint)
945 hAti->Paint(loption.Data());
946 lnk = lnk->Next();
947 }
948 } else {
949 auto lnk = fHists->LastLink();
950 Int_t h1col, h1fill;
951 for (Int_t i=0;i<nhists;i++) {
952 if (strstr(lnk->GetOption(),"same")) {
953 loption.Form("%s%s",noption,lnk->GetOption());
954 } else {
955 loption.Form("%ssame%s",noption,lnk->GetOption());
956 }
957 TH1 *h1 = (TH1*) fStack->At(nhists-i-1);
958 if ((i > 0) && lclear && paint) {
959 // Erase before drawing the histogram
960 h1col = h1->GetFillColor();
961 h1fill = h1->GetFillStyle();
962 h1->SetFillColor(10);
963 h1->SetFillStyle(1001);
964 h1->Paint(loption.Data());
965 static TClassRef clTFrame = TClass::GetClass("TFrame", kFALSE);
966 TAttFill *frameFill = (TAttFill*)clTFrame->DynamicCast(TAttFill::Class(),gPad->GetFrame());
967 if (frameFill) {
968 h1->SetFillColor(frameFill->GetFillColor());
969 h1->SetFillStyle(frameFill->GetFillStyle());
970 }
971 h1->Paint(loption.Data());
972 h1->SetFillColor(h1col);
973 h1->SetFillStyle(h1fill);
974 }
975 if (paint)
976 h1->Paint(loption.Data());
977 lnk = lnk->Prev();
978 }
979 }
980
981 opt.ReplaceAll("nostack","");
982 opt.ReplaceAll("candle","");
983 if (!lsame && !opt.Contains("a") && paint)
984 fHistogram->Paint("axissame");
985}
986
987////////////////////////////////////////////////////////////////////////////////
988/// Print the list of histograms
989
991{
992 TIter next(fHists);
993 while (auto h = next())
994 h->Print(option);
995}
996
997////////////////////////////////////////////////////////////////////////////////
998/// Recursively remove object from the list of histograms
999
1001{
1002 if (!fHists) return;
1003 fHists->RecursiveRemove(obj);
1004 while (fHists->IndexOf(obj) >= 0) fHists->Remove(obj);
1005}
1006
1007////////////////////////////////////////////////////////////////////////////////
1008/// Save primitive as a C++ statement(s) on output stream out
1009
1010void THStack::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1011{
1012 char quote = '"';
1013 out<<" "<<std::endl;
1014 if (gROOT->ClassSaved(THStack::Class())) {
1015 out<<" ";
1016 } else {
1017 out<<" THStack *";
1018 }
1019 out<<GetName()<<" = new THStack();"<<std::endl;
1020 out<<" "<<GetName()<<"->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
1021 out<<" "<<GetName()<<"->SetTitle("<<quote<<GetTitle()<<quote<<");"<<std::endl;
1022
1023 if (fMinimum != -1111) {
1024 out<<" "<<GetName()<<"->SetMinimum("<<fMinimum<<");"<<std::endl;
1025 }
1026 if (fMaximum != -1111) {
1027 out<<" "<<GetName()<<"->SetMaximum("<<fMaximum<<");"<<std::endl;
1028 }
1029
1030 static Int_t frameNumber = 0;
1031 if (fHistogram) {
1032 frameNumber++;
1033 TString hname = fHistogram->GetName();
1034 fHistogram->SetName(TString::Format("%s_stack_%d", hname.Data(), frameNumber).Data());
1035 fHistogram->SavePrimitive(out,"nodraw");
1036 out<<" "<<GetName()<<"->SetHistogram("<<fHistogram->GetName()<<");"<<std::endl;
1037 out<<" "<<std::endl;
1038 fHistogram->SetName(hname.Data()); // restore histogram name
1039 }
1040
1041 if (fHists) {
1042 auto lnk = fHists->FirstLink();
1043 Int_t hcount = 0;
1044 while (lnk) {
1045 auto h = (TH1 *) lnk->GetObject();
1046 TString hname = h->GetName();
1047 h->SetName(TString::Format("%s_stack_%d", hname.Data(), ++hcount).Data());
1048 h->SavePrimitive(out,"nodraw");
1049 out<<" "<<GetName()<<"->Add("<<h->GetName()<<","<<quote<<lnk->GetOption()<<quote<<");"<<std::endl;
1050 lnk = lnk->Next();
1051 h->SetName(hname.Data()); // restore histogram name
1052 }
1053 }
1054 out<<" "<<GetName()<<"->Draw("<<quote<<option<<quote<<");"<<std::endl;
1055}
1056
1057////////////////////////////////////////////////////////////////////////////////
1058/// Set maximum.
1059
1061{
1062 fMaximum = maximum;
1063 if (fHistogram) fHistogram->SetMaximum(maximum);
1064}
1065
1066////////////////////////////////////////////////////////////////////////////////
1067/// Set minimum.
1068
1070{
1071 fMinimum = minimum;
1072 if (fHistogram) fHistogram->SetMinimum(minimum);
1073}
1074
1075
1076////////////////////////////////////////////////////////////////////////////////
1077/// Get iterator over internal hists list.
1079{
1080 return TIter(fHists);
1081}
@ 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
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:2823
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6686
virtual Int_t GetDimension() const
Definition TH1.h:283
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition TH1.cxx:1294
@ kIsZoomed
Bit set when zooming on Y axis.
Definition TH1.h:169
TAxis * GetXaxis()
Definition TH1.h:324
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition TH1.cxx:4488
TObject * FindObject(const char *name) const override
Search object named name in the list of functions.
Definition TH1.cxx:3857
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h: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:7205
void SetName(const char *name) override
Change the name of this histogram.
Definition TH1.cxx:8928
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
Definition TH1.cxx:6174
TClass * IsA() const override
Definition TH1.h:443
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Definition TH1.cxx:754
virtual void SetBarWidth(Float_t width=0.5)
Set the width of bars as fraction of the bin width for drawing mode "B".
Definition TH1.h:365
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8958
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
Service class for 2-D histogram classes.
Definition TH2.h:30
TH1D * ProjectionY(const char *name="_py", Int_t firstxbin=0, Int_t lastxbin=-1, Option_t *option="") const
Project a 2-D histogram into a 1-D histogram along Y.
Definition TH2.cxx:2476
TH1D * ProjectionX(const char *name="_px", Int_t firstybin=0, Int_t lastybin=-1, Option_t *option="") const
Project a 2-D histogram into a 1-D histogram along X.
Definition TH2.cxx:2436
static TClass * Class()
The 3-D histogram classes derived from the 1-D histogram classes.
Definition TH3.h:31
static TClass * Class()
virtual TH1 * Project3D(Option_t *option="x") const
Project a 3-d histogram into 1 or 2-d histograms depending on the option parameter,...
Definition TH3.cxx:2412
The Histogram stack class.
Definition THStack.h:40
TIter begin() const
Get iterator over internal hists list.
Definition THStack.cxx:1078
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:544
void ls(Option_t *option="") const override
List histograms in the stack.
Definition THStack.cxx:648
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:705
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:390
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:661
TH1 * GetHistogram() const
Returns a pointer to the histogram used to draw the axis Takes into account the two following cases.
Definition THStack.cxx:481
void RecursiveRemove(TObject *obj) override
Recursively remove object from the list of histograms.
Definition THStack.cxx:1000
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:365
void Print(Option_t *chopt="") const override
Print the list of histograms.
Definition THStack.cxx:990
TObjArray * GetStack()
Return pointer to Stack. Build it if not yet done.
Definition THStack.cxx:597
Int_t GetNhists() const
Return the number of histograms in the stack.
Definition THStack.cxx:588
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:495
void Draw(Option_t *chopt="") override
Draw this multihist with its current attributes.
Definition THStack.cxx:450
void Paint(Option_t *chopt="") override
Paint the list of histograms.
Definition THStack.cxx:697
TList * fHists
Pointer to array of TH1.
Definition THStack.h:45
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum.
Definition THStack.cxx:1060
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:636
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition THStack.cxx:1010
void Browse(TBrowser *b) override
Browse.
Definition THStack.cxx:380
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:413
virtual void Modified()
invalidate sum of histograms
Definition THStack.cxx:684
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum.
Definition THStack.cxx:1069
TAxis * GetXaxis() const
Get x axis of the histogram used to draw the stack.
Definition THStack.cxx:610
Double_t fMaximum
Maximum value for plotting along y.
Definition THStack.h:48
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
A doubly linked list.
Definition TList.h:38
void Clear(Option_t *option="") override
Remove all objects from the list.
Definition TList.cxx:400
virtual TObjLink * LastLink() const
Definition TList.h: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:762
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:820
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:657
virtual TObjLink * FirstLink() const
Definition TList.h: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:355
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
TString fTitle
Definition TNamed.h:33
TString fName
Definition TNamed.h:32
An array of TObjects.
Definition TObjArray.h:31
void AddAt(TObject *obj, Int_t idx) override
Add object at position ids.
void Delete(Option_t *option="") override
Remove all objects from the array AND delete all heap based objects.
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
void Add(TObject *obj) override
Definition TObjArray.h:68
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h: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:973
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:184
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition TObject.cxx:764
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:62
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition TROOT.cxx:2836
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2844
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2718
virtual Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
Long64_t Merge(TCollection *list)
Merge this collection with all collections coming in the input list.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:538
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
Bool_t IsNull() const
Definition TString.h:414
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Bool_t IsWhitespace() const
Definition TString.h:415
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
Double_t GetHistTopMargin() const
Definition TStyle.h: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()