138 gROOT->GetListOfCleanups()->Add(
this);
172 const char *
name ,
const char *title ,
179 gROOT->GetListOfCleanups()->Add(
this);
182 Warning(
"THStack",
"Need an axis.");
186 Warning(
"THStack",
"Need a histogram.");
191 if (!isTH2 && !isTH3) {
192 Warning(
"THStack",
"Need a histogram deriving from TH2 or TH3.");
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.");
215 Warning(
"THStack",
"Histogram axis is NULL");
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;
226 iBin, iBin, proj_option);
229 iBin, iBin, proj_option);
230 Add(hProj, draw_option);
238 if (dim<1 || dim>2) {
239 Warning(
"THStack",
"Invalid length for parameter axis.");
244 TAxis* haxis =
nullptr;
253 Warning(
"THStack",
"Histogram axis is NULL");
258 if (firstbin < 0) firstbin = 1;
259 if (lastbin < 0) lastbin = nbins;
260 if (lastbin > nbins+1) lastbin = nbins;
263 for (
Int_t iBin=firstbin; iBin<=lastbin; iBin++) {
267 axis, proj_option, iBin).
Data());
268 Add(hProj, draw_option);
270 haxis->
SetRange(iFirstOld, iLastOld);
273 TAxis* haxis1 =
nullptr;
274 TAxis* haxis2 =
nullptr;
286 if (!haxis1 || !haxis2) {
287 Warning(
"THStack",
"Histogram axis is NULL");
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;
303 for (
Int_t iBin=firstbin; iBin<=lastbin; iBin++) {
305 for (
Int_t jBin=firstbin2; jBin<=lastbin2; jBin++) {
309 axis, proj_option, iBin).
Data());
310 Add(hProj, draw_option);
313 haxis1->
SetRange(iFirstOld1, iLastOld1);
314 haxis2->
SetRange(iFirstOld2, iLastOld2);
327 gROOT->GetListOfCleanups()->Remove(
this);
348 fMaximum(hstack.fMaximum),
349 fMinimum(hstack.fMinimum)
367 Error(
"Add",
"THStack supports only 1-d and 2-d histograms");
380 Draw(
b ?
b->GetDrawOption() :
"");
399 for (
Int_t i=1;i<nhists;i++) {
414 const Int_t kMaxDiff = 10;
415 Int_t distance = 9999;
418 if (distance <= 0) {
return distance;}
419 if (distance <= 1) {
gPad->SetSelected(
fHistogram);
return distance;}
424 if (!
fHists)
return distance;
427 for (
Int_t i=0;i<nhists;i++) {
430 Int_t dist =
h->DistancetoPrimitive(px,py);
431 if (dist <= 0)
return 0;
432 if (dist < kMaxDiff) {
453 if (!
gPad->IsEditable())
gROOT->MakeDefCanvas();
482 if (!
gPad)
return nullptr;
499 Double_t them = 0, themax = -std::numeric_limits<Double_t>::max(),
c1, e1;
510 themax =
h->GetMaximum(maxval);
512 for (
Int_t i=0;i<nhists;i++) {
516 them =
h->GetMaximum(maxval);
518 if (them > themax) themax = them;
523 for (
Int_t i=0;i<nhists;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);
548 Double_t them = 0, themin = std::numeric_limits<Double_t>::max(),
c1, e1;
557 themin =
h->GetMinimum(minval);
559 for (
Int_t i=0;i<nhists;i++) {
561 them =
h->GetMinimum(minval);
562 if (them <= 0 && gPad && gPad->GetLogy()) them =
h->GetMinimum(0);
563 if (them < themin) themin = them;
568 for (
Int_t i=0;i<nhists;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);
610 if (!
gPad)
return nullptr;
612 if (!
h)
return nullptr;
613 return h->GetXaxis();
625 if (!
gPad)
return nullptr;
627 if (!
h)
return nullptr;
628 return h->GetYaxis();
640 if (!
gPad)
return nullptr;
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();
674 "Cannot merge - an object which doesn't inherit from THStack found in the list");
713 strlcpy(
option,choptin,128);
716 char *l1 = strstr(
option,
"pfc");
717 char *l2 = strstr(
option,
"plc");
718 char *l3 = strstr(
option,
"pmc");
719 if (l1 || l2 || l3) {
721 if (l1) memcpy(l1,
" ",3);
722 if (l2) memcpy(l2,
" ",3);
723 if (l3) memcpy(l3,
" ",3);
730 gPad->IncrementPaletteColor(nhists, opt1);
731 for (
Int_t i=0;i<nhists;i++) {
732 ic =
gPad->NextPaletteColor();
766 while ((obj = nextp())) {
772 if (nx*nx < npads) nx++;
774 if (((nx*ny)-nx) >= npads) ny--;
782 lnk->GetObject()->
Draw(lnk->GetOption());
797 while ((
h=(
TH1*)next())) {
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();
816 if (!nostack && !candle && !violin)
BuildStack();
823 if (
gPad->GetLogy()){
824 if (themin>0) themin *= .9;
825 else themin = themax*1.e-3;
835 TAxis *xaxis =
h->GetXaxis();
836 TAxis *yaxis =
h->GetYaxis();
838 if (
h->GetDimension() > 1) {
839 if (loption.
IsNull()) loption =
"lego1";
841 if (xbins->fN != 0 && ybins->
fN != 0) {
843 xaxis->
GetNbins(), xbins->GetArray(),
845 }
else if (xbins->fN != 0 && ybins->
fN == 0) {
847 xaxis->
GetNbins(), xbins->GetArray(),
849 }
else if (xbins->fN == 0 && ybins->
fN != 0) {
859 if (xbins->fN != 0) {
861 xaxis->
GetNbins(), xbins->GetArray());
875 if (nostack) loption.
ReplaceAll(
"nostack",
"");
916 if (loption.
Index(
"lego")>=0)
920 strlcpy(noption,loption.
Data(),32);
922 if (nostack || candle || violin) {
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());
931 TString indivOpt = lnk->GetOption();
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());
943 if (candle || violin) {
944 float candleSpace = 1./(nhists*2);
945 float candleOffset = - 1./2 + candleSpace + 2*candleSpace*i;
957 for (
Int_t i=0;i<nhists;i++) {
958 if (strstr(lnk->GetOption(),
"same")) {
959 loption.
Form(
"%s%s",noption,lnk->GetOption());
961 loption.
Form(
"%ssame%s",noption,lnk->GetOption());
964 if ((i > 0) && lclear && paint) {
989 if (!lsame && !opt.
Contains(
"a") && paint)
1001 while ((
h = (
TH1*) next())) {
1023 out<<
" "<<std::endl;
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;
1040 static Int_t frameNumber = 0;
1047 out<<
" "<<std::endl;
1055 auto h = (
TH1 *) lnk->GetObject();
1058 h->SavePrimitive(out,
"nodraw");
1059 out<<
" "<<
GetName()<<
"->Add("<<
h->GetName()<<
","<<quote<<lnk->GetOption()<<quote<<
");"<<std::endl;
1061 h->SetName(hname.
Data());
1064 out<<
" "<<
GetName()<<
"->Draw("<<quote<<
option<<quote<<
");"<<std::endl;
R__EXTERN TVirtualMutex * gROOTMutex
R__EXTERN TStyle * gStyle
#define R__LOCKGUARD(mutex)
Array of doubles (64 bits per element).
const Double_t * GetArray() const
Fill Area Attributes class.
virtual Color_t GetFillColor() const
Return the fill area color.
virtual Style_t GetFillStyle() const
Return the fill area style.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Class to manage histogram axis.
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
const TArrayD * GetXbins() const
Int_t GetLast() const
Return last bin on the axis i.e.
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Int_t GetFirst() const
Return first bin on the axis i.e.
THashList * GetLabels() const
Using a TBrowser one can browse all ROOT objects.
TClassRef is used to implement a permanent reference to a TClass object.
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.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
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.
Collection abstract base class.
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)
TH1 is the base class of all histogram classes in ROOT.
virtual void SetBarOffset(Float_t offset=0.25)
Set the bar offset as fraction of the bin width for drawing mode "B".
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a line.
void SetTitle(const char *title) override
Change/set the title.
virtual Int_t GetDimension() const
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
@ kIsZoomed
Bit set when zooming on Y axis.
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
TObject * FindObject(const char *name) const override
Search object named name in the list of functions.
virtual void SetMaximum(Double_t maximum=-1111)
virtual void SetMinimum(Double_t minimum=-1111)
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
void SetName(const char *name) override
Change the name of this histogram.
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
TClass * IsA() const override
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
virtual void SetBarWidth(Float_t width=0.5)
Set the width of bars as fraction of the bin width for drawing mode "B".
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
2-D histogram with a float per channel (see TH1 documentation)
Service class for 2-D histogram classes.
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.
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.
The 3-D histogram classes derived from the 1-D histogram classes.
virtual TH1 * Project3D(Option_t *option="x") const
Project a 3-d histogram into 1 or 2-d histograms depending on the option parameter,...
The Histogram stack class.
TIter begin() const
Get iterator over internal hists list.
TClass * IsA() const override
~THStack() override
THStack destructor.
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.
void ls(Option_t *option="") const override
List histograms in the stack.
TObjArray * fStack
! Pointer to array of sums of TH1
void BuildAndPaint(Option_t *chopt, Bool_t paint)
Create all additional objects and stack (if specified)
Double_t fMinimum
Minimum value for plotting along y.
void BuildStack()
build sum of all histograms Build a separate list fStack containing the running sum of all histograms
TAxis * GetYaxis() const
Get y axis of the histogram used to draw the stack.
virtual Long64_t Merge(TCollection *li, TFileMergeInfo *info)
Merge the THStack in the TList into this stack.
TH1 * GetHistogram() const
Returns a pointer to the histogram used to draw the axis Takes into account the two following cases.
void RecursiveRemove(TObject *obj) override
Recursively remove object from the list of histograms.
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
void Print(Option_t *chopt="") const override
Print the list of histograms.
TObjArray * GetStack()
Return pointer to Stack. Build it if not yet done.
Int_t GetNhists() const
Return the number of histograms in the stack.
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.
void Draw(Option_t *chopt="") override
Draw this multihist with its current attributes.
void Paint(Option_t *chopt="") override
Paint the list of histograms.
TList * fHists
Pointer to array of TH1.
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum.
TH1 * fHistogram
Pointer to histogram used for drawing axis.
TAxis * GetZaxis() const
Get z axis of the histogram used to draw the stack.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
void Browse(TBrowser *b) override
Browse.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to each graph.
virtual void Modified()
invalidate sum of histograms
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum.
TAxis * GetXaxis() const
Get x axis of the histogram used to draw the stack.
Double_t fMaximum
Maximum value for plotting along y.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
void Clear(Option_t *option="") override
Remove all objects from the list.
virtual TObjLink * LastLink() const
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
void Add(TObject *obj) override
TObject * Remove(TObject *obj) override
Remove object from the list.
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
virtual TObjLink * FirstLink() const
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
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
void Add(TObject *obj) override
Collectable string class.
Mother of all ROOT objects.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
@ kCanDelete
if object in a list can be deleted
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
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.
void ToLower()
Change string to lower-case.
Ssiz_t First(char c) const
Find first occurrence of a character c.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t IsWhitespace() const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Double_t GetHistTopMargin() const
virtual void SetStack(TList *stack)=0
TVirtualPad is an abstract base class for the Pad and Canvas classes.
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
void Clear(Option_t *option="") override=0
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Double_t Log10(Double_t x)
Returns the common (base-10) logarithm of x.