137 gROOT->GetListOfCleanups()->Add(
this);
171 const char *
name ,
const char *title ,
178 gROOT->GetListOfCleanups()->Add(
this);
181 Warning(
"THStack",
"Need an axis.");
185 Warning(
"THStack",
"Need a histogram.");
190 if (!isTH2 && !isTH3) {
191 Warning(
"THStack",
"Need a histogram deriving from TH2 or TH3.");
196 fName.Form(
"%s_stack%s", hist->
GetName(), axis);
197 if (!fTitle.Length()) {
198 if (hist->GetTitle() && strlen(hist->GetTitle()))
199 fTitle.Form(
"%s, stack of %s projections", hist->GetTitle(), axis);
201 fTitle.Form(
"stack of %s projections", axis);
206 Bool_t useX = (strchr(axis,
'x')) || (strchr(axis,
'X'));
207 Bool_t useY = (strchr(axis,
'y')) || (strchr(axis,
'Y'));
208 if ((!useX && !useY) || (useX && useY)) {
209 Warning(
"THStack",
"Need parameter axis=\"x\" or \"y\" for a TH2, not none or both.");
214 Warning(
"THStack",
"Histogram axis is NULL");
218 if (firstbin < 0) firstbin = 1;
219 if (lastbin < 0) lastbin = nbins;
220 if (lastbin > nbins+1) lastbin = nbins;
221 for (
Int_t iBin=firstbin; iBin<=lastbin; iBin++) {
222 TH1* hProj =
nullptr;
225 iBin, iBin, proj_option);
228 iBin, iBin, proj_option);
229 Add(hProj, draw_option);
237 if (dim<1 || dim>2) {
238 Warning(
"THStack",
"Invalid length for parameter axis.");
243 TAxis* haxis =
nullptr;
245 if (sAxis.First(
'x')==
kNPOS)
247 else if (sAxis.First(
'y')==
kNPOS)
249 else if (sAxis.First(
'z')==
kNPOS)
252 Warning(
"THStack",
"Histogram axis is NULL");
257 if (firstbin < 0) firstbin = 1;
258 if (lastbin < 0) lastbin = nbins;
259 if (lastbin > nbins+1) lastbin = nbins;
262 for (
Int_t iBin=firstbin; iBin<=lastbin; iBin++) {
266 axis, proj_option, iBin).Data());
267 Add(hProj, draw_option);
269 haxis->
SetRange(iFirstOld, iLastOld);
272 TAxis* haxis1 =
nullptr;
273 TAxis* haxis2 =
nullptr;
275 if (sAxis.First(
'x')!=
kNPOS) {
278 }
else if (sAxis.First(
'y')!=
kNPOS) {
281 }
else if (sAxis.First(
'z')!=
kNPOS) {
285 if (!haxis1 || !haxis2) {
286 Warning(
"THStack",
"Histogram axis is NULL");
292 if (firstbin < 0) firstbin = 1;
293 if (lastbin < 0) lastbin = nbins1;
294 if (lastbin > nbins1+1) lastbin = nbins1;
295 if (firstbin2 < 0) firstbin2 = 1;
296 if (lastbin2 < 0) lastbin2 = nbins2;
297 if (lastbin2 > nbins2+1) lastbin2 = nbins2;
302 for (
Int_t iBin=firstbin; iBin<=lastbin; iBin++) {
304 for (
Int_t jBin=firstbin2; jBin<=lastbin2; jBin++) {
308 axis, proj_option, iBin).Data());
309 Add(hProj, draw_option);
312 haxis1->
SetRange(iFirstOld1, iLastOld1);
313 haxis2->
SetRange(iFirstOld2, iLastOld2);
325 gROOT->GetListOfCleanups()->Remove(
this);
328 fHists->Clear(
"nodelete");
346 fMaximum(hstack.fMaximum),
347 fMinimum(hstack.fMinimum)
351 gROOT->GetListOfCleanups()->Add(
this);
355 while (
auto h =
static_cast<TH1 *
>(next()))
368 Error(
"Add",
"THStack supports only 1-d and 2-d histograms");
382 Draw(
b ?
b->GetDrawOption() :
"");
396 fStack =
new TObjArray(nhists);
399 TH1 *
h = (TH1*)
fHists->At(0)->Clone();
401 for (
Int_t i=1;i<nhists;i++) {
402 h = (TH1*)
fHists->At(i)->Clone();
403 if (
h->GetMinimum() < 0.) {
404 Warning(
"BuildStack",
"Histograms with a negative minimum may produce wrong plots");
417 const Int_t kMaxDiff = 10;
418 Int_t distance = 9999;
420 distance =
fHistogram->DistancetoPrimitive(px,py);
421 if (distance <= 0) {
return distance;}
422 if (distance <= 1) {
gPad->SetSelected(
fHistogram);
return distance;}
427 if (!
fHists)
return distance;
430 for (
Int_t i=0;i<nhists;i++) {
432 if (
fStack && !strstr(doption,
"nostack"))
h = (TH1*)
fStack->At(i);
434 if (dist <= 0)
return 0;
435 if (dist < kMaxDiff) {
453 TString opt = option;
456 if (!
gPad->IsEditable())
gROOT->MakeDefCanvas();
485 if (!
gPad)
return nullptr;
489 return (TH1*)
gPad->FindObject(
"hframe");
498 TString opt = option;
501 Double_t themax = -std::numeric_limits<Double_t>::max();
505 auto check_error = [&themax](TH1 *
h) {
506 Int_t first =
h->GetXaxis()->GetFirst();
507 Int_t last =
h->GetXaxis()->GetLast();
508 for (
Int_t j = first; j <= last; j++) {
517 auto h = (TH1 *)
fStack->At(nhists - 1);
519 h->GetXaxis()->SetRange(
fHistogram->GetXaxis()->GetFirst(),
521 themax =
h->GetMaximum(maxval);
525 for (
Int_t i = 0; i < nhists; i++) {
528 h->GetXaxis()->SetRange(
fHistogram->GetXaxis()->GetFirst(),
536 h->GetXaxis()->SetRange(0,0);
551 TString opt = option;
555 Double_t themin = std::numeric_limits<Double_t>::max();
558 auto check_error = [logy, &themin](TH1 *
h) {
559 Int_t first =
h->GetXaxis()->GetFirst();
560 Int_t last =
h->GetXaxis()->GetLast();
561 for (
Int_t j = first; j <= last; j++) {
564 if (!logy || (
c1 - e1 > 0))
571 auto h = (TH1*)
fStack->At(nhists-1);
572 themin =
h->GetMinimum(minval);
573 if (themin <= 0 && logy)
574 themin =
h->GetMinimum(0);
578 for (
Int_t i = 0; i < nhists; i++) {
581 if (them <= 0 && logy)
582 them =
h->GetMinimum(0);
621 return h ?
h->GetXaxis() :
nullptr;
634 return h ?
h->GetYaxis() :
nullptr;
647 if (!
h)
return nullptr;
648 if (
h->GetDimension() == 1)
649 Warning(
"GetZaxis",
"1D Histograms don't have a Z axis");
650 return h->GetZaxis();
660 <<
" Name= "<<
GetName()<<
" Title= "<<
GetTitle()<<
" Option="<<option<<std::endl;
672 return fHists->GetEntries();
680 "Cannot merge - an object which doesn't inherit from THStack found in the list");
685 fHists->Merge(&histLists);
686 return fHists->GetEntries();
716 if (!
fHists->GetSize())
return;
719 strlcpy(option,choptin,128);
722 char *l1 = strstr(option,
"pfc");
723 char *l2 = strstr(option,
"plc");
724 char *l3 = strstr(option,
"pmc");
725 if (l1 || l2 || l3) {
726 TString opt1 = option;
727 if (l1) memcpy(l1,
" ",3);
728 if (l2) memcpy(l2,
" ",3);
729 if (l3) memcpy(l3,
" ",3);
733 gPad->IncrementPaletteColor(nhists, opt1);
734 for (
Int_t i = 0; i < nhists; i++) {
735 auto ic =
gPad->NextPaletteColor();
736 auto hAti =
static_cast<TH1 *
>(
fHists->At(i));
737 if (l1) hAti->SetFillColor(ic);
738 if (l2) hAti->SetLineColor(ic);
739 if (l3) hAti->SetMarkerColor(ic);
741 auto hsAti =
static_cast<TH1 *
>(
fStack->At(i));
742 if (l1) hsAti->SetFillColor(ic);
743 if (l2) hsAti->SetLineColor(ic);
744 if (l3) hsAti->SetMarkerColor(ic);
749 TString opt = option;
762 auto l = strstr(opt.
Data(),
"pads");
768 if (sscanf(&
l[4],
"%d", &fnx) > 0) {
775 TVirtualPad *padsav =
gPad;
779 while (
auto obj = nextp()) {
790 if (((nx * ny) - nx) >= npads)
795 if (fnx * ny < npads)
802 auto lnk =
fHists->FirstLink();
804 auto subpad = padsav->
GetPad(i++);
807 if (!subpad->FindObject(lnk->GetObject())) {
809 subpad->Add(lnk->GetObject(), lnk->GetOption());
825 while ((
h=(TH1*)next())) {
827 if (
h->GetBuffer())
h->BufferEmpty(-1);
828 if (
h->GetXaxis()->GetXmin() <
xmin)
xmin =
h->GetXaxis()->GetXmin();
829 if (
h->GetXaxis()->GetXmax() >
xmax)
xmax =
h->GetXaxis()->GetXmax();
830 if (
h->GetYaxis()->GetXmin() <
ymin)
ymin =
h->GetYaxis()->GetXmin();
831 if (
h->GetYaxis()->GetXmax() >
ymax)
ymax =
h->GetYaxis()->GetXmax();
834 TString loption = opt;
841 if (!nostack && !candle && !violin) {
844 if (rebuild_stack &&
fStack) {
857 if (
gPad->GetLogy()){
858 if (themin>0) themin *= .9;
859 else themin = themax*1.e-3;
868 TAxis *xaxis =
h->GetXaxis();
869 TAxis *yaxis =
h->GetYaxis();
871 if (
h->GetDimension() > 1) {
872 if (loption.
IsNull()) loption =
"lego1";
873 const TArrayD *ybins = yaxis->
GetXbins();
874 if (
xbins->fN != 0 && ybins->
fN != 0) {
878 }
else if (
xbins->fN != 0 && ybins->
fN == 0) {
882 }
else if (
xbins->fN == 0 && ybins->
fN != 0) {
892 if (
xbins->fN != 0) {
908 if (nostack) loption.
ReplaceAll(
"nostack",
"");
929 TH1 *hfirst = (TH1*)
fHists->First();
934 while (
auto lb=(TObjString*)iL()) {
935 fHistogram->GetXaxis()->SetBinLabel(ilab,lb->String().Data());
949 if (loption.
Index(
"lego")>=0)
953 strlcpy(noption,loption.
Data(),32);
955 if (nostack || candle || violin) {
956 auto lnk =
fHists->FirstLink();
959 for (
Int_t i=0;i<nhists;i++) {
960 if (strstr(lnk->GetOption(),
"same")) {
961 if (nostackb) loption.
Form(
"%s%s b",noption,lnk->GetOption());
962 else loption.
Form(
"%s%s",noption,lnk->GetOption());
964 TString indivOpt = lnk->GetOption();
966 if (nostackb) loption.
Form(
"%ssame%s b",noption,lnk->GetOption());
967 else if (candle && (indivOpt.
Contains(
"candle") || indivOpt.
Contains(
"violin"))) loption.
Form(
"%ssame",lnk->GetOption());
968 else loption.
Form(
"%ssame%s",noption,lnk->GetOption());
970 TH1* hAti = (TH1*)
fHists->At(i);
976 if (candle || violin) {
977 float candleSpace = 1./(nhists*2);
978 float candleOffset = - 1./2 + candleSpace + 2*candleSpace*i;
988 auto lnk =
fHists->LastLink();
990 for (
Int_t i=0;i<nhists;i++) {
991 if (strstr(lnk->GetOption(),
"same")) {
992 loption.
Form(
"%s%s",noption,lnk->GetOption());
994 loption.
Form(
"%ssame%s",noption,lnk->GetOption());
996 TH1 *
h1 = (TH1*)
fStack->At(nhists-i-1);
997 if ((i > 0) && lclear && paint) {
1022 if (!lsame && !opt.
Contains(
"a") && paint)
1032 while (
auto h = next())
1042 fHists->RecursiveRemove(obj);
1060 out <<
" " <<
name <<
"->SetMinimum(" <<
fMinimum <<
");\n";
1062 out <<
" " <<
name <<
"->SetMaximum(" <<
fMaximum <<
");\n";
1064 thread_local Int_t hcount = 0;
1069 out <<
" " <<
name <<
"->SetHistogram(" <<
fHistogram->GetName() <<
");\n";
1075 auto lnk =
fHists->FirstLink();
1077 auto h =
static_cast<TH1 *
>(lnk->GetObject());
1078 TString hname =
h->GetName();
1080 h->SavePrimitive(out,
"nodraw");
1081 out <<
" " <<
name <<
"->Add(" <<
h->GetName() <<
", \""
1082 << TString(lnk->GetOption()).ReplaceSpecialCppChars() <<
"\");\n";
1083 h->SetName(hname.
Data());
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
long long Long64_t
Portable signed long integer 8 bytes.
const char Option_t
Option string (const char).
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
externTVirtualMutex * gROOTMutex
#define R__LOCKGUARD(mutex)
const Double_t * GetArray() const
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.
Class to manage histogram axis.
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.
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.
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.
virtual Int_t GetEntries() const
A class to pass information from the TFileMerger to the objects being merged.
TH1 is the base class of all histogram classes in ROOT.
virtual Int_t GetDimension() const
@ kIsZoomed
Bit set when zooming on Y axis.
virtual void SetBarWidth(Float_t width=0.5)
Set the width of bars as fraction of the bin width for drawing mode "B".
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
virtual void SetBarOffset(Float_t offset=0.25)
Set the bar offset as fraction of the bin width for drawing mode "B".
TClass * IsA() const override
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 (integration along X).
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 (integration along Y).
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,...
TClass * IsA() const override
virtual Double_t GetMinimum(Option_t *option="", Double_t minval=-std::numeric_limits< Double_t >::max())
void BuildAndPaint(Option_t *chopt, Bool_t paint, Bool_t rebuild_stack=kFALSE)
void ls(Option_t *option="") const override
The ls function lists the contents of a class on stdout.
TObjArray * fStack
! Pointer to array of sums of TH1
Double_t fMinimum
Minimum value for plotting along y.
TH1 * GetHistogram() const
void RecursiveRemove(TObject *obj) override
Recursively remove this object from a list.
void Print(Option_t *chopt="") const override
This method must be overridden when a class wants to print itself.
virtual Double_t GetMaximum(Option_t *option="", Double_t maxval=std::numeric_limits< Double_t >::max())
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
void Paint(Option_t *chopt="") override
This method must be overridden if a class wants to paint itself.
TList * fHists
Pointer to array of TH1.
virtual Long64_t Merge(TCollection *li, TFileMergeInfo *info)
TH1 * fHistogram
Pointer to histogram used for drawing axis.
virtual void SetMinimum(Double_t minimum=-1111)
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
void Browse(TBrowser *b) override
Browse object. May be overridden for another default action.
virtual void SetMaximum(Double_t maximum=-1111)
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Computes distance from point (px,py) to the object.
virtual void Add(TH1 *h, Option_t *option="")
Double_t fMaximum
Maximum value for plotting along y.
void Add(TObject *obj) override
The TNamed class is the base class for all named ROOT classes.
void SavePrimitiveNameTitle(std::ostream &out, const char *variable_name)
Save object name and title into the output stream "out".
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Mother of all ROOT objects.
Bool_t TestBit(UInt_t f) const
virtual const char * ClassName() const
Returns name of class to which the object belongs.
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.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
TObject()
TObject constructor.
@ kCanDelete
if object in a list can be deleted
@ kMustCleanup
if object destructor must call RecursiveRemove()
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().
void ToLower()
Change string to lower-case.
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
virtual TList * GetListOfPrimitives() const =0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual TVirtualPad * GetPad(Int_t subpadnumber) const =0
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
double dist(Rotation3D const &r1, Rotation3D const &r2)
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.
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
const double xbins[xbins_n]