Logo ROOT  
Reference Guide
TAxis.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 12/12/94
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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 "TAxis.h"
13#include "TVirtualPad.h"
14#include "TStyle.h"
15#include "TError.h"
16#include "THashList.h"
17#include "TList.h"
18#include "TAxisModLab.h"
19#include "TH1.h"
20#include "TObjString.h"
21#include "TDatime.h"
22#include "TTimeStamp.h"
23#include "TBuffer.h"
24#include "TMath.h"
25#include "THLimitsFinder.h"
26#include "strlcpy.h"
27#include "snprintf.h"
28
29#include <iostream>
30#include <ctime>
31#include <cassert>
32
34
35////////////////////////////////////////////////////////////////////////////////
36/** \class TAxis
37 \ingroup Histograms
38 \brief Class to manage histogram axis
39
40This class manages histogram axis. It is referenced by TH1 and TGraph.
41To make a graphical representation of an histogram axis, this class
42references the TGaxis class. TAxis supports axis with fixed or variable bin sizes.
43Labels may be associated to individual bins.
44See examples of various axis representations drawn by class TGaxis.
45*///////////////////////////////////////////////////////////////////////////////
46
47////////////////////////////////////////////////////////////////////////////////
48/// Default constructor.
49
51{
52 fNbins = 1;
53 fXmin = 0;
54 fXmax = 1;
55 fFirst = 0;
56 fLast = 0;
57 fParent = 0;
58 fLabels = 0;
59 fModLabs = 0;
60 fBits2 = 0;
61 fTimeDisplay = 0;
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Axis constructor for axis with fix bin size
66
68{
69 fParent = 0;
70 fLabels = 0;
71 fModLabs = 0;
72 Set(nbins,xlow,xup);
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Axis constructor for variable bin size
77
79{
80 fParent = 0;
81 fLabels = 0;
82 fModLabs = 0;
83 Set(nbins,xbins);
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Destructor.
88
90{
91 if (fLabels) {
92 fLabels->Delete();
93 delete fLabels;
94 fLabels = 0;
95 }
96 if (fModLabs) {
98 delete fModLabs;
99 fModLabs = 0;
100 }
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Copy constructor.
105
106TAxis::TAxis(const TAxis &axis) : TNamed(axis), TAttAxis(axis), fLabels(0), fModLabs(0)
107{
108 axis.Copy(*this);
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Assignment operator.
113
115{
116 orig.Copy( *this );
117 return *this;
118}
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Choose a reasonable time format from the coordinates in the active pad
123/// and the number of divisions in this axis
124/// If orientation = "X", the horizontal axis of the pad will be used for ref.
125/// If orientation = "Y", the vertical axis of the pad will be used for ref.
126
127const char *TAxis::ChooseTimeFormat(Double_t axislength)
128{
129 const char *formatstr = nullptr;
130 Int_t reasformat = 0;
131 Int_t ndiv,nx1,nx2,n;
132 Double_t awidth;
134
135 if (!axislength) {
136 length = gPad->GetUxmax() - gPad->GetUxmin();
137 } else {
138 length = axislength;
139 }
140
141 ndiv = GetNdivisions();
142 if (ndiv > 1000) {
143 nx2 = ndiv/100;
144 nx1 = TMath::Max(1, ndiv%100);
145 ndiv = 100*nx2 + Int_t(Double_t(nx1)*gPad->GetAbsWNDC());
146 }
147 ndiv = TMath::Abs(ndiv);
148 n = ndiv - (ndiv/100)*100;
149 awidth = length/n;
150
151// width in seconds ?
152 if (awidth>=.5) {
153 reasformat = 1;
154// width in minutes ?
155 if (awidth>=30) {
156 awidth /= 60; reasformat = 2;
157// width in hours ?
158 if (awidth>=30) {
159 awidth /=60; reasformat = 3;
160// width in days ?
161 if (awidth>=12) {
162 awidth /= 24; reasformat = 4;
163// width in months ?
164 if (awidth>=15.218425) {
165 awidth /= 30.43685; reasformat = 5;
166// width in years ?
167 if (awidth>=6) {
168 awidth /= 12; reasformat = 6;
169 if (awidth>=2) {
170 awidth /= 12; reasformat = 7;
171 }
172 }
173 }
174 }
175 }
176 }
177 }
178// set reasonable format
179 switch (reasformat) {
180 case 0:
181 formatstr = "%S";
182 break;
183 case 1:
184 formatstr = "%Mm%S";
185 break;
186 case 2:
187 formatstr = "%Hh%M";
188 break;
189 case 3:
190 formatstr = "%d-%Hh";
191 break;
192 case 4:
193 formatstr = "%d/%m";
194 break;
195 case 5:
196 formatstr = "%d/%m/%y";
197 break;
198 case 6:
199 formatstr = "%d/%m/%y";
200 break;
201 case 7:
202 formatstr = "%m/%y";
203 break;
204 }
205 return formatstr;
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Copy axis structure to another axis
210
211void TAxis::Copy(TObject &obj) const
212{
213 TNamed::Copy(obj);
214 TAttAxis::Copy(((TAxis&)obj));
215 TAxis &axis( ((TAxis&)obj) );
216 axis.fNbins = fNbins;
217 axis.fXmin = fXmin;
218 axis.fXmax = fXmax;
219 axis.fFirst = fFirst;
220 axis.fLast = fLast;
221 axis.fBits2 = fBits2;
222 fXbins.Copy(axis.fXbins);
225 axis.fParent = fParent;
226 if (axis.fLabels) {
227 axis.fLabels->Delete();
228 delete axis.fLabels;
229 axis.fLabels = 0;
230 }
231 if (fLabels) {
232 //Properly handle case where not all bins have labels
233 TIter next(fLabels);
234 TObjString *label;
235 if(! axis.fLabels) {
236 axis.fLabels = new THashList(axis.fNbins, 3);
237 }
238 while( (label=(TObjString*)next()) ) {
239 TObjString *copyLabel = new TObjString(*label);
240 axis.fLabels->Add(copyLabel);
241 copyLabel->SetUniqueID(label->GetUniqueID());
242 }
243 }
244 if (axis.fModLabs) {
245 axis.fModLabs->Delete();
246 delete axis.fModLabs;
247 axis.fModLabs = 0;
248 }
249 if (fModLabs) {
250 TIter next(fModLabs);
251 TAxisModLab *modlabel;
252 if(! axis.fModLabs) {
253 axis.fModLabs = new TList();
254 }
255 while( (modlabel=(TAxisModLab*)next()) ) {
256 TAxisModLab *copyModLabel = new TAxisModLab(*modlabel);
257 axis.fModLabs->Add(copyModLabel);
258 copyModLabel->SetUniqueID(modlabel->GetUniqueID());
259 }
260 }
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Compute distance from point px,py to an axis
265
267{
268 return 9999;
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Execute action corresponding to one event
273///
274/// This member function is called when an axis is clicked with the locator.
275/// The axis range is set between the position where the mouse is pressed
276/// and the position where it is released.
277/// If the mouse position is outside the current axis range when it is released
278/// the axis is unzoomed with the corresponding proportions.
279/// Note that the mouse does not need to be in the pad or even canvas
280/// when it is released.
281
283{
284 if (!gPad) return;
285 gPad->ExecuteEventAxis(event,px,py,this);
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Find bin number corresponding to abscissa x. NOTE: this method does not work with alphanumeric bins !!!
290///
291/// If x is underflow or overflow, attempt to extend the axis if TAxis::kCanExtend is true.
292/// Otherwise, return 0 or fNbins+1.
293
295{
296 Int_t bin;
297 // NOTE: This should not be allowed for Alphanumeric histograms,
298 // but it is heavily used (legacy) in the TTreePlayer to fill alphanumeric histograms.
299 // but in case of alphanumeric do-not extend the axis. It makes no sense
300 if (IsAlphanumeric() && gDebug) Info("FindBin","Numeric query on alphanumeric axis - Sorting the bins or extending the axes / rebinning can alter the correspondence between the label and the bin interval.");
301 if (x < fXmin) { //*-* underflow
302 bin = 0;
303 if (fParent == 0) return bin;
304 if (!CanExtend() || IsAlphanumeric() ) return bin;
305 ((TH1*)fParent)->ExtendAxis(x,this);
306 return FindFixBin(x);
307 } else if ( !(x < fXmax)) { //*-* overflow (note the way to catch NaN)
308 bin = fNbins+1;
309 if (fParent == 0) return bin;
310 if (!CanExtend() || IsAlphanumeric() ) return bin;
311 ((TH1*)fParent)->ExtendAxis(x,this);
312 return FindFixBin(x);
313 } else {
314 if (!fXbins.fN) { //*-* fix bins
315 bin = 1 + int (fNbins*(x-fXmin)/(fXmax-fXmin) );
316 } else { //*-* variable bin sizes
317 //for (bin =1; x >= fXbins.fArray[bin]; bin++);
319 }
320 }
321 return bin;
322}
323
324////////////////////////////////////////////////////////////////////////////////
325/// Find bin number with label.
326/// If the List of labels does not exist create it and make the axis alphanumeric
327/// If one wants just to add a single label- just call TAxis::SetBinLabel
328/// If label is not in the list of labels do the following depending on the
329/// bit TAxis::kCanExtend; of the axis.
330/// - if the bit is set add the new label and if the number of labels exceeds
331/// the number of bins, double the number of bins via TH1::LabelsInflate
332/// - if the bit is not set and the histogram has labels in each bin
333/// set the bit automatically and consider the histogram as alphanumeric
334/// if histogram has only some bins with labels then the histogram is not
335/// consider alphanumeric and return -1
336///
337/// -1 is returned only when the Axis has no parent histogram
338
339Int_t TAxis::FindBin(const char *label)
340{
341 //create list of labels if it does not exist yet
342 if (!fLabels) {
343 if (!fParent) return -1;
344 fLabels = new THashList(fNbins,3);
345 // we set the axis alphanumeric
346 // when list of labels does not exist
347 // do we want to do this also when histogram is not empty ?????
348 if (CanBeAlphanumeric() ) {
351 if (fXmax <= fXmin) {
352 //L.M. Dec 2010 in case of no min and max specified use 0 ->NBINS
353 fXmin = 0;
354 fXmax = fNbins;
355 }
356 }
357 }
358
359 // search for label in the existing list and return it if it exists
360 TObjString *obj = (TObjString*)fLabels->FindObject(label);
361 if (obj) return (Int_t)obj->GetUniqueID();
362
363 // if labels is not in the list and we have already labels
364 if (!IsAlphanumeric()) {
365 // if bins without labels exist or if the axis cannot be set to alphanumeric
367 Info("FindBin","Label %s is not in the list and the axis is not alphanumeric - ignore it",label);
368 return -1;
369 }
370 else {
371 Info("FindBin","Label %s not in the list. It will be added to the histogram",label);
374 }
375 }
376
377 //Not yet in the list. Can we extend the axis ?
378 assert ( CanExtend() && IsAlphanumeric() );
379 // {
380 // if (gDebug>0)
381 // Info("FindBin","Label %s is not in the list and the axis cannot be extended - the entry will be added in the underflow bin",label);
382 // return 0;
383 // }
384
386
387 //may be we have to resize the histogram (doubling number of channels)
388 if (n >= fNbins) ((TH1*)fParent)->LabelsInflate(GetName());
389
390 //add new label to the list: assign bin number
391 obj = new TObjString(label);
392 fLabels->Add(obj);
393 obj->SetUniqueID(n+1);
394 return n+1;
395}
396
397////////////////////////////////////////////////////////////////////////////////
398/// Find bin number with label.
399/// If the List of labels does not exist or the label does not exist just return -1 .
400/// Do not attempt to modify the axis. This is different than FindBin
401
402Int_t TAxis::FindFixBin(const char *label) const
403{
404 //create list of labels if it does not exist yet
405 if (!fLabels) return -1;
406
407 // search for label in the existing list and return it if it exists
408 TObjString *obj = (TObjString*)fLabels->FindObject(label);
409 if (obj) return (Int_t)obj->GetUniqueID();
410 return -1;
411}
412
413
414////////////////////////////////////////////////////////////////////////////////
415/// Find bin number corresponding to abscissa x
416///
417/// Identical to TAxis::FindBin except that if x is an underflow/overflow
418/// no attempt is made to extend the axis.
419
421{
422 Int_t bin;
423 if (x < fXmin) { //*-* underflow
424 bin = 0;
425 } else if ( !(x < fXmax)) { //*-* overflow (note the way to catch NaN
426 bin = fNbins+1;
427 } else {
428 if (!fXbins.fN) { //*-* fix bins
429 bin = 1 + int (fNbins*(x-fXmin)/(fXmax-fXmin) );
430 } else { //*-* variable bin sizes
431// for (bin =1; x >= fXbins.fArray[bin]; bin++);
433 }
434 }
435 return bin;
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// Return label for bin
440
441const char *TAxis::GetBinLabel(Int_t bin) const
442{
443 if (!fLabels) return "";
444 if (bin <= 0 || bin > fNbins) return "";
445 TIter next(fLabels);
446 TObjString *obj;
447 while ((obj=(TObjString*)next())) {
448 Int_t binid = (Int_t)obj->GetUniqueID();
449 if (binid == bin) return obj->GetName();
450 }
451 return "";
452}
453
454////////////////////////////////////////////////////////////////////////////////
455/// Return first bin on the axis
456/// i.e. 1 if no range defined
457/// NOTE: in some cases a zero is returned (see TAxis::SetRange)
458
460{
461 if (!TestBit(kAxisRange)) return 1;
462 return fFirst;
463}
464
465////////////////////////////////////////////////////////////////////////////////
466/// Return last bin on the axis
467/// i.e. fNbins if no range defined
468/// NOTE: in some cases a zero is returned (see TAxis::SetRange)
469
471{
472 if (!TestBit(kAxisRange)) return fNbins;
473 return fLast;
474}
475
476////////////////////////////////////////////////////////////////////////////////
477/// Return center of bin
478
480{
481 Double_t binwidth;
482 if (!fXbins.fN || bin<1 || bin>fNbins) {
483 binwidth = (fXmax - fXmin) / Double_t(fNbins);
484 return fXmin + (bin-1) * binwidth + 0.5*binwidth;
485 } else {
486 binwidth = fXbins.fArray[bin] - fXbins.fArray[bin-1];
487 return fXbins.fArray[bin-1] + 0.5*binwidth;
488 }
489}
490
491////////////////////////////////////////////////////////////////////////////////
492/// Return center of bin in log
493/// With a log-equidistant binning for a bin with low and up edges, the mean is :
494/// 0.5*(ln low + ln up) i.e. sqrt(low*up) in logx (e.g. sqrt(10^0*10^2) = 10).
495/// Imagine a bin with low=1 and up=100 :
496/// - the center in lin is (100-1)/2=50.5
497/// - the center in log would be sqrt(1*100)=10 (!=log(50.5))
498///
499/// NB: if the low edge of the bin is negative, the function returns the bin center
500/// as computed by TAxis::GetBinCenter
501
503{
504 Double_t low,up;
505 if (!fXbins.fN || bin<1 || bin>fNbins) {
506 Double_t binwidth = (fXmax - fXmin) / Double_t(fNbins);
507 low = fXmin + (bin-1) * binwidth;
508 up = low+binwidth;
509 } else {
510 low = fXbins.fArray[bin-1];
511 up = fXbins.fArray[bin];
512 }
513 if (low <=0 ) return GetBinCenter(bin);
514 return TMath::Sqrt(low*up);
515}
516////////////////////////////////////////////////////////////////////////////////
517/// Return low edge of bin
518
520{
521 if (fXbins.fN && bin > 0 && bin <=fNbins) return fXbins.fArray[bin-1];
522 Double_t binwidth = (fXmax - fXmin) / Double_t(fNbins);
523 return fXmin + (bin-1) * binwidth;
524}
525
526////////////////////////////////////////////////////////////////////////////////
527/// Return up edge of bin
528
530{
531 if (!fXbins.fN || bin < 1 || bin>fNbins) {
532 Double_t binwidth = (fXmax - fXmin) / Double_t(fNbins);
533 return fXmin + bin*binwidth;
534 }
535 return fXbins.fArray[bin];
536}
537
538////////////////////////////////////////////////////////////////////////////////
539/// Return bin width
540
542{
543 if (fNbins <= 0) return 0;
544 if (fXbins.fN <= 0) return (fXmax - fXmin) / Double_t(fNbins);
545 if (bin >fNbins) bin = fNbins;
546 if (bin <1 ) bin = 1;
547 return fXbins.fArray[bin] - fXbins.fArray[bin-1];
548}
549
550
551////////////////////////////////////////////////////////////////////////////////
552/// Return an array with the center of all bins
553
554void TAxis::GetCenter(Double_t *center) const
555{
556 Int_t bin;
557 for (bin=1; bin<=fNbins; bin++) *(center + bin-1) = GetBinCenter(bin);
558}
559
560////////////////////////////////////////////////////////////////////////////////
561/// Return an array with the low edge of all bins
562
564{
565 Int_t bin;
566 for (bin=1; bin<=fNbins; bin++) *(edge + bin-1) = GetBinLowEdge(bin);
567}
568
569////////////////////////////////////////////////////////////////////////////////
570/// Return the number of axis labels.
571///
572/// It is sometimes useful to know the number of labels on an axis. For instance
573/// when changing the labels with TAxis::ChangeLabel. The number of labels is equal
574/// to `the_number_of_divisions + 1`. By default the number of divisions is
575/// optimised to show a coherent labelling of the main tick marks. After optimisation the
576/// real number of divisions will be smaller or equal to number of divisions requested.
577/// In order to turn off the labelling optimization, it is enough to give a negative
578/// number of divisions to TAttAxis::SetNdivisions. The absolute value of this number will be use as
579/// the exact number of divisions. This method takes the two cases (optimised or not) into
580/// account.
581
583{
584 if (fNdivisions>0) {
585 Int_t divxo = 0;
586 Double_t x1o = 0.;
587 Double_t x2o = 0.;
588 Double_t bwx = 0.;
589 THLimitsFinder::Optimize(fXmin, fXmax,fNdivisions%100,x1o,x2o,divxo,bwx,"");
590 return divxo+1;
591 } else {
592 Int_t divx = -fNdivisions;
593 return divx%100+1;
594 }
595}
596
597////////////////////////////////////////////////////////////////////////////////
598/// Return *only* the time format from the string fTimeFormat
599
600const char *TAxis::GetTimeFormatOnly() const
601{
602 static TString timeformat;
603 Int_t idF = fTimeFormat.Index("%F");
604 if (idF>=0) {
605 timeformat = fTimeFormat(0,idF);
606 } else {
607 timeformat = fTimeFormat;
608 }
609 return timeformat.Data();
610}
611
612////////////////////////////////////////////////////////////////////////////////
613/// Return the ticks option (see SetTicks)
614
615const char *TAxis::GetTicks() const
616{
617 if (TestBit(kTickPlus) && TestBit(kTickMinus)) return "+-";
618 if (TestBit(kTickMinus)) return "-";
619 return "+";
620}
621
622////////////////////////////////////////////////////////////////////////////////
623/// This helper function checks if there is a bin without a label
624/// if all bins have labels, the axis can / will become alphanumeric
625
627{
628 return fLabels->GetSize() != fNbins;
629}
630
631////////////////////////////////////////////////////////////////////////////////
632/// Set option(s) to draw axis with labels
633/// option can be:
634/// - "a" sort by alphabetic order
635/// - ">" sort by decreasing values
636/// - "<" sort by increasing values
637/// - "h" draw labels horizontal
638/// - "v" draw labels vertical
639/// - "u" draw labels up (end of label right adjusted)
640/// - "d" draw labels down (start of label left adjusted)
641
643{
644 if (!fLabels) {
645 Warning("Sort","Cannot sort. No labels");
646 return;
647 }
648 TH1 *h = (TH1*)GetParent();
649 if (!h) {
650 Error("Sort","Axis has no parent");
651 return;
652 }
653
654 h->LabelsOption(option,GetName());
655}
656
657////////////////////////////////////////////////////////////////////////////////
658/// Copy axis attributes to this
659
661{
662 SetTitle(axis->GetTitle());
664 SetAxisColor(axis->GetAxisColor());
666 SetLabelFont(axis->GetLabelFont());
668 SetLabelSize(axis->GetLabelSize());
671 SetTitleSize(axis->GetTitleSize());
673 SetTitleFont(axis->GetTitleFont());
683}
684
685
686
687////////////////////////////////////////////////////////////////////////////////
688/// Save axis attributes as C++ statement(s) on output stream out
689
690void TAxis::SaveAttributes(std::ostream &out, const char *name, const char *subname)
691{
692 char quote = '"';
693 if (strlen(GetTitle())) {
694 TString t(GetTitle());
695 t.ReplaceAll("\\","\\\\");
696 out<<" "<<name<<subname<<"->SetTitle("<<quote<<t.Data()<<quote<<");"<<std::endl;
697 }
698 if (fTimeDisplay) {
699 out<<" "<<name<<subname<<"->SetTimeDisplay(1);"<<std::endl;
700 out<<" "<<name<<subname<<"->SetTimeFormat("<<quote<<GetTimeFormat()<<quote<<");"<<std::endl;
701 }
702 if (fLabels) {
703 TIter next(fLabels);
704 TObjString *obj;
705 while ((obj=(TObjString*)next())) {
706 out<<" "<<name<<subname<<"->SetBinLabel("<<obj->GetUniqueID()<<","<<quote<<obj->GetName()<<quote<<");"<<std::endl;
707 }
708 }
709
710 if (fFirst || fLast) {
711 out<<" "<<name<<subname<<"->SetRange("<<fFirst<<","<<fLast<<");"<<std::endl;
712 }
713
714 if (TestBit(kLabelsHori)) {
715 out<<" "<<name<<subname<<"->SetBit(TAxis::kLabelsHori);"<<std::endl;
716 }
717
718 if (TestBit(kLabelsVert)) {
719 out<<" "<<name<<subname<<"->SetBit(TAxis::kLabelsVert);"<<std::endl;
720 }
721
722 if (TestBit(kLabelsDown)) {
723 out<<" "<<name<<subname<<"->SetBit(TAxis::kLabelsDown);"<<std::endl;
724 }
725
726 if (TestBit(kLabelsUp)) {
727 out<<" "<<name<<subname<<"->SetBit(TAxis::kLabelsUp);"<<std::endl;
728 }
729
730 if (TestBit(kCenterLabels)) {
731 out<<" "<<name<<subname<<"->CenterLabels(true);"<<std::endl;
732 }
733
734 if (TestBit(kCenterTitle)) {
735 out<<" "<<name<<subname<<"->CenterTitle(true);"<<std::endl;
736 }
737
738 if (TestBit(kRotateTitle)) {
739 out<<" "<<name<<subname<<"->RotateTitle(true);"<<std::endl;
740 }
741
742 if (TestBit(kDecimals)) {
743 out<<" "<<name<<subname<<"->SetDecimals();"<<std::endl;
744 }
745
746 if (TestBit(kMoreLogLabels)) {
747 out<<" "<<name<<subname<<"->SetMoreLogLabels();"<<std::endl;
748 }
749
750 if (TestBit(kNoExponent)) {
751 out<<" "<<name<<subname<<"->SetNoExponent();"<<std::endl;
752 }
753
754 TAttAxis::SaveAttributes(out,name,subname);
755}
756
757////////////////////////////////////////////////////////////////////////////////
758/// Initialize axis with fix bins
759
760void TAxis::Set(Int_t nbins, Double_t xlow, Double_t xup)
761{
762 fNbins = nbins;
763 fXmin = xlow;
764 fXmax = xup;
765 if (!fParent) SetDefaults();
766 if (fXbins.fN > 0) fXbins.Set(0);
767}
768
769////////////////////////////////////////////////////////////////////////////////
770/// Initialize axis with variable bins
771
772void TAxis::Set(Int_t nbins, const Float_t *xbins)
773{
774 Int_t bin;
775 fNbins = nbins;
776 fXbins.Set(fNbins+1);
777 for (bin=0; bin<= fNbins; bin++)
778 fXbins.fArray[bin] = xbins[bin];
779 for (bin=1; bin<= fNbins; bin++)
780 if (fXbins.fArray[bin] < fXbins.fArray[bin-1])
781 Error("TAxis::Set", "bins must be in increasing order");
782 fXmin = fXbins.fArray[0];
784 if (!fParent) SetDefaults();
785}
786
787////////////////////////////////////////////////////////////////////////////////
788/// Initialize axis with variable bins
789
790void TAxis::Set(Int_t nbins, const Double_t *xbins)
791{
792 Int_t bin;
793 fNbins = nbins;
794 fXbins.Set(fNbins+1);
795 for (bin=0; bin<= fNbins; bin++)
796 fXbins.fArray[bin] = xbins[bin];
797 for (bin=1; bin<= fNbins; bin++)
798 if (fXbins.fArray[bin] < fXbins.fArray[bin-1])
799 Error("TAxis::Set", "bins must be in increasing order");
800 fXmin = fXbins.fArray[0];
802 if (!fParent) SetDefaults();
803}
804
805////////////////////////////////////////////////////////////////////////////////
806/// Set axis alphanumeric
807
809{
810 if (alphanumeric) fBits2 |= kAlphanumeric;
811 else fBits2 &= ~kAlphanumeric;
812
813 // clear underflow and overflow (in an alphanumeric situation they do not make sense)
814 // NOTE: using AddBinContent instead of SetBinContent in order to not change
815 // the number of entries
816 //((TH1 *)fParent)->ClearUnderflowAndOverflow();
817 // L.M. 26.1.15 Keep underflow and overflows (see ROOT-7034)
818 if (gDebug && fParent) {
819 TH1 * h = dynamic_cast<TH1*>( fParent);
820 if (!h) return;
821 double s[TH1::kNstat];
822 h->GetStats(s);
823 if (s[0] != 0. && gDebug > 0)
824 Info("SetAlphanumeric","Cannot switch axis %s of histogram %s to alphanumeric: it has non-zero content",GetName(),h->GetName());
825 }
826}
827
828
829////////////////////////////////////////////////////////////////////////////////
830/// Set axis default values (from TStyle)
831
833{
834 fFirst = 0;
835 fLast = 0;
836 fBits2 = 0;
837 char name[2];
838 strlcpy(name,GetName(),2);
839 name[1] = 0;
841 fTimeDisplay = 0;
843}
844
845////////////////////////////////////////////////////////////////////////////////
846/// Set label for bin.
847/// If no label list exists, it is created. If all the bins have labels, the
848/// axis becomes alphanumeric and extendable.
849/// New labels will not be added with the Fill method but will end-up in the
850/// underflow bin. See documentation of TAxis::FindBin(const char*)
851
852void TAxis::SetBinLabel(Int_t bin, const char *label)
853{
854 if (!fLabels) fLabels = new THashList(fNbins,3);
855
856 if (bin <= 0 || bin > fNbins) {
857 Error("SetBinLabel","Illegal bin number: %d",bin);
858 return;
859 }
860
861 // Check whether this bin already has a label.
862 TIter next(fLabels);
863 TObjString *obj;
864 while ((obj=(TObjString*)next())) {
865 if ( obj->GetUniqueID()==(UInt_t)bin ) {
866 // It does. Overwrite it.
867 obj->SetString(label);
868 // LM need to rehash the labels list (see ROOT-5025)
870 return;
871 }
872 }
873 // It doesn't. Add this new label.
874 obj = new TObjString(label);
875 fLabels->Add(obj);
876 obj->SetUniqueID((UInt_t)bin);
877
878 // check for Alphanumeric case (labels for each bin)
879 if (CanBeAlphanumeric() && fLabels->GetSize() == fNbins) {
882 }
883}
884
885////////////////////////////////////////////////////////////////////////////////
886/// Define new text attributes for the label number "labNum". It allows to do a
887/// fine tuning of the labels. All the attributes can be changed, even the
888/// label text itself.
889///
890/// \param[in] labNum Number of the label to be changed, negative numbers start from the end
891/// \param[in] labAngle New angle value
892/// \param[in] labSize New size (0 erase the label)
893/// \param[in] labAlign New alignment value
894/// \param[in] labColor New label color
895/// \param[in] labFont New label font
896/// \param[in] labText New label text
897///
898/// #### Notes:
899///
900/// - If an attribute should not be changed just give the value "-1".
901/// - If labnum=0 the list of modified labels is reset.
902/// - To erase a label set labSize to 0.
903/// - If labText is not specified or is an empty string, the text label is not changed.
904/// - To retrieve the number of axis labels use TAxis::GetNlabels.
905
906void TAxis::ChangeLabel(Int_t labNum, Double_t labAngle, Double_t labSize,
907 Int_t labAlign, Int_t labColor, Int_t labFont,
908 TString labText)
909{
910 if (!fModLabs) fModLabs = new TList();
911
912 // Reset the list of modified labels.
913 if (labNum == 0) {
914 delete fModLabs;
915 fModLabs = 0;
916 return;
917 }
918
919 TAxisModLab *ml = new TAxisModLab();
920 ml->SetLabNum(labNum);
921 ml->SetAngle(labAngle);
922 ml->SetSize(labSize);
923 ml->SetAlign(labAlign);
924 ml->SetColor(labColor);
925 ml->SetFont(labFont);
926 ml->SetText(labText);
927
928 fModLabs->Add((TObject*)ml);
929}
930
931
932////////////////////////////////////////////////////////////////////////////////
933/// Set the viewing range for the axis using bin numbers.
934///
935/// \param first First bin of the range.
936/// \param last Last bin of the range.
937/// To set a range using the axis coordinates, use TAxis::SetRangeUser.
938///
939/// If `first == last == 0` or if `first > last` or if the range specified does
940/// not intersect at all with the maximum available range `[0, fNbins + 1]`,
941/// then the viewing range is reset by removing the bit TAxis::kAxisRange. In this
942/// case, the functions TAxis::GetFirst() and TAxis::GetLast() will return 1
943/// and fNbins.
944///
945/// If the range specified partially intersects with `[0, fNbins + 1]`, then the
946/// intersection range is accepted. For instance, if `first == -2` and `last == fNbins`,
947/// the accepted range will be `[0, fNbins]` (`fFirst = 0` and `fLast = fNbins`).
948///
949/// \note For historical reasons, SetRange(0,0) resets the range even though bin 0 is
950/// technically reserved for the underflow; in order to set the range of the axis
951/// so that it only includes the underflow, use `SetRange(-1,0)`.
952
954{
955
956 Int_t nCells = fNbins + 1; // bins + overflow
957
958 // special reset range cases
959 if (last < first || (first < 0 && last < 0) ||
960 (first > nCells && last > nCells) || (first == 0 && last == 0)
961 ) {
962 fFirst = 1;
963 fLast = fNbins;
964 SetBit(kAxisRange, 0);
965 } else {
966 fFirst = std::max(first, 0);
967 fLast = std::min(last, nCells);
968 SetBit(kAxisRange, 1);
969 }
970
971}
972
973
974////////////////////////////////////////////////////////////////////////////////
975/// Set the viewing range for the axis from ufirst to ulast (in user coordinates,
976/// that is, the "natural" axis coordinates).
977/// To set a range using the axis bin numbers, use TAxis::SetRange.
978
980{
981 if (!strstr(GetName(),"xaxis")) {
982 TH1 *hobj = (TH1*)GetParent();
983 if (hobj &&
984 ((hobj->GetDimension() == 2 && strstr(GetName(),"zaxis"))
985 || (hobj->GetDimension() == 1 && strstr(GetName(),"yaxis")))) {
986 hobj->SetMinimum(ufirst);
987 hobj->SetMaximum(ulast);
988 return;
989 }
990 }
991 Int_t ifirst = FindFixBin(ufirst);
992 Int_t ilast = FindFixBin(ulast);
993 // fixes for numerical error and for https://savannah.cern.ch/bugs/index.php?99777
994 if (GetBinUpEdge(ifirst) <= ufirst ) ifirst += 1;
995 if (GetBinLowEdge(ilast) >= ulast ) ilast -= 1;
996 SetRange(ifirst, ilast);
997}
998
999////////////////////////////////////////////////////////////////////////////////
1000/// Set ticks orientation.
1001/// option = "+" ticks drawn on the "positive side" (default)
1002/// option = "-" ticks drawn on the "negative side"
1003/// option = "+-" ticks drawn on both sides
1004
1006{
1009 if (strchr(option,'+')) SetBit(kTickPlus);
1010 if (strchr(option,'-')) SetBit(kTickMinus);
1011}
1012
1013////////////////////////////////////////////////////////////////////////////////
1014/// Change the format used for time plotting
1015///
1016/// The format string for date and time use the same options as the one used
1017/// in the standard strftime C function, i.e. :
1018/// for date :
1019///
1020/// %a abbreviated weekday name
1021/// %b abbreviated month name
1022/// %d day of the month (01-31)
1023/// %m month (01-12)
1024/// %y year without century
1025///
1026/// for time :
1027///
1028/// %H hour (24-hour clock)
1029/// %I hour (12-hour clock)
1030/// %p local equivalent of AM or PM
1031/// %M minute (00-59)
1032/// %S seconds (00-61)
1033/// %% %
1034///
1035/// This function allows also to define the time offset. It is done via %F
1036/// which should be appended at the end of the format string. The time
1037/// offset has the following format: 'yyyy-mm-dd hh:mm:ss'
1038/// Example:
1039///
1040/// h = new TH1F("Test","h",3000,0.,200000.);
1041/// h->GetXaxis()->SetTimeDisplay(1);
1042/// h->GetXaxis()->SetTimeFormat("%d\/%m\/%y%F2000-02-28 13:00:01");
1043///
1044/// This defines the time format being "dd/mm/yy" and the time offset as the
1045/// February 28th 2003 at 13:00:01
1046///
1047/// If %F is not specified, the time offset used will be the one defined by:
1048/// gStyle->SetTimeOffset. For example like that:
1049///
1050/// TDatime da(2003,02,28,12,00,00);
1051/// gStyle->SetTimeOffset(da.Convert());
1052
1053void TAxis::SetTimeFormat(const char *tformat)
1054{
1055 TString timeformat = tformat;
1056
1057 if (timeformat.Index("%F")>=0 || timeformat.IsNull()) {
1058 fTimeFormat = timeformat;
1059 return;
1060 }
1061
1062 Int_t idF = fTimeFormat.Index("%F");
1063 if (idF>=0) {
1064 Int_t lnF = fTimeFormat.Length();
1065 TString stringtimeoffset = fTimeFormat(idF,lnF);
1066 fTimeFormat = tformat;
1067 fTimeFormat.Append(stringtimeoffset);
1068 } else {
1069 fTimeFormat = tformat;
1071 }
1072}
1073
1074
1075////////////////////////////////////////////////////////////////////////////////
1076/// Change the time offset
1077/// If option = "gmt", set display mode to GMT.
1078
1080{
1081 TString opt = option;
1082 opt.ToLower();
1083
1084 char tmp[20];
1085 time_t timeoff;
1086 struct tm* utctis;
1087 Int_t idF = fTimeFormat.Index("%F");
1088 if (idF>=0) fTimeFormat.Remove(idF);
1089 fTimeFormat.Append("%F");
1090
1091 timeoff = (time_t)((Long_t)(toffset));
1092 // offset is always saved in GMT to allow file transport
1093 // to different time zones
1094 utctis = gmtime(&timeoff);
1095
1096 strftime(tmp,20,"%Y-%m-%d %H:%M:%S",utctis);
1097 fTimeFormat.Append(tmp);
1098
1099 // append the decimal part of the time offset
1100 Double_t ds = toffset-(Int_t)toffset;
1101 snprintf(tmp,20,"s%g",ds);
1102 fTimeFormat.Append(tmp);
1103
1104 // add GMT/local option
1105 if (opt.Contains("gmt")) fTimeFormat.Append(" GMT");
1106}
1107
1108
1109////////////////////////////////////////////////////////////////////////////////
1110/// Stream an object of class TAxis.
1111
1113{
1114 if (R__b.IsReading()) {
1115 UInt_t R__s, R__c;
1116 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1117 if (R__v > 5) {
1118 R__b.ReadClassBuffer(TAxis::Class(), this, R__v, R__s, R__c);
1119 return;
1120 }
1121 //====process old versions before automatic schema evolution
1122 TNamed::Streamer(R__b);
1123 TAttAxis::Streamer(R__b);
1124 R__b >> fNbins;
1125 if (R__v < 5) {
1127 R__b >> xmin; fXmin = xmin;
1128 R__b >> xmax; fXmax = xmax;
1129 Float_t *xbins = 0;
1130 Int_t n = R__b.ReadArray(xbins);
1131 fXbins.Set(n);
1132 for (Int_t i=0;i<n;i++) fXbins.fArray[i] = xbins[i];
1133 delete [] xbins;
1134 } else {
1135 R__b >> fXmin;
1136 R__b >> fXmax;
1137 fXbins.Streamer(R__b);
1138 }
1139 if (R__v > 2) {
1140 R__b >> fFirst;
1141 R__b >> fLast;
1142 // following lines required to repair for a bug in Root version 1.03
1143 if (fFirst < 0 || fFirst > fNbins) fFirst = 0;
1144 if (fLast < 0 || fLast > fNbins) fLast = 0;
1145 if (fLast < fFirst) { fFirst = 0; fLast = 0;}
1146 if (fFirst ==0 && fLast == 0) SetBit(kAxisRange,0);
1147 }
1148 if (R__v > 3) {
1149 R__b >> fTimeDisplay;
1150 fTimeFormat.Streamer(R__b);
1151 } else {
1152 SetTimeFormat();
1153 }
1154 R__b.CheckByteCount(R__s, R__c, TAxis::IsA());
1155 //====end of old versions
1156
1157 } else {
1158 R__b.WriteClassBuffer(TAxis::Class(),this);
1159 }
1160}
1161
1162////////////////////////////////////////////////////////////////////////////////
1163/// Reset first & last bin to the full range
1164
1166{
1167 if (!gPad) {
1168 Warning("TAxis::UnZoom","Cannot UnZoom if gPad does not exist. Did you mean to draw the TAxis first?");
1169 return;
1170 }
1171 gPad->SetView();
1172
1173 //unzoom object owning this axis
1174 SetRange(0,0);
1175 TH1 *hobj1 = (TH1*)GetParent();
1176 if (!strstr(GetName(),"xaxis")) {
1177 if (!hobj1) return;
1178 if (hobj1->GetDimension() == 2) {
1179 if (strstr(GetName(),"zaxis")) {
1180 hobj1->SetMinimum();
1181 hobj1->SetMaximum();
1182 hobj1->ResetBit(TH1::kIsZoomed);
1183 }
1184 return;
1185 }
1186 if (strcmp(hobj1->GetName(),"hframe") == 0 ) {
1187 hobj1->SetMinimum(fXmin);
1188 hobj1->SetMaximum(fXmax);
1189 } else {
1190 if (fXmin==hobj1->GetMinimum() && fXmax==hobj1->GetMaximum()) {
1191 hobj1->SetMinimum(fXmin);
1192 hobj1->SetMaximum(fXmax);
1193 } else {
1194 hobj1->SetMinimum();
1195 hobj1->SetMaximum();
1196 }
1197 hobj1->ResetBit(TH1::kIsZoomed);
1198 }
1199 }
1200 //must unzoom all histograms in the pad
1201 TIter next(gPad->GetListOfPrimitives());
1202 TObject *obj;
1203 while ((obj= next())) {
1204 if (!obj->InheritsFrom(TH1::Class())) continue;
1205 TH1 *hobj = (TH1*)obj;
1206 if (hobj == hobj1) continue;
1207 if (!strstr(GetName(),"xaxis")) {
1208 if (hobj->GetDimension() == 2) {
1209 if (strstr(GetName(),"zaxis")) {
1210 hobj->SetMinimum();
1211 hobj->SetMaximum();
1212 hobj->ResetBit(TH1::kIsZoomed);
1213 } else {
1214 hobj->GetYaxis()->SetRange(0,0);
1215 }
1216 return;
1217 }
1218 if (strcmp(hobj->GetName(),"hframe") == 0 ) {
1219 hobj->SetMinimum(fXmin);
1220 hobj->SetMaximum(fXmax);
1221 } else {
1222 hobj->SetMinimum();
1223 hobj->SetMaximum();
1224 hobj->ResetBit(TH1::kIsZoomed);
1225 }
1226 } else {
1227 hobj->GetXaxis()->SetRange(0,0);
1228 }
1229 }
1230
1231 gPad->UnZoomed();
1232}
1233
1234////////////////////////////////////////////////////////////////////////////////
1235/// Zoom out by a factor of 'factor' (default =2)
1236/// uses previous zoom factor by default
1237/// Keep center defined by 'offset' fixed
1238/// ie. -1 at left of current range, 0 in center, +1 at right
1239
1241{
1242
1243 if (factor <= 0) factor = 2;
1244 Double_t center = (GetFirst()*(1-offset) + GetLast()*(1+offset))/2.;
1245 Int_t first = int(TMath::Floor(center+(GetFirst()-center)*factor + 0.4999999));
1246 Int_t last = int(TMath::Floor(center+(GetLast() -center)*factor + 0.5000001));
1247 if (first==GetFirst() && last==GetLast()) { first--; last++; }
1248 SetRange(first,last);
1249}
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:45
short Version_t
Definition: RtypesCore.h:65
long Long_t
Definition: RtypesCore.h:54
float Float_t
Definition: RtypesCore.h:57
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:375
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
char name[80]
Definition: TGX11.cxx:110
float xmin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
Int_t gDebug
Definition: TROOT.cxx:585
R__EXTERN TStyle * gStyle
Definition: TStyle.h:414
#define gPad
Definition: TVirtualPad.h:288
#define snprintf
Definition: civetweb.c:1540
Double_t * fArray
Definition: TArrayD.h:30
void Streamer(TBuffer &) override
Stream a TArrayD object.
Definition: TArrayD.cxx:149
void Copy(TArrayD &array) const
Definition: TArrayD.h:42
void Set(Int_t n) override
Set size of this array to n doubles.
Definition: TArrayD.cxx:106
Int_t fN
Definition: TArray.h:38
Manages histogram axis attributes.
Definition: TAttAxis.h:18
virtual Color_t GetTitleColor() const
Definition: TAttAxis.h:46
virtual Color_t GetLabelColor() const
Definition: TAttAxis.h:38
Int_t fNdivisions
Number of divisions(10000*n3 + 100*n2 + n1)
Definition: TAttAxis.h:20
virtual Int_t GetNdivisions() const
Definition: TAttAxis.h:36
virtual Color_t GetAxisColor() const
Definition: TAttAxis.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:301
virtual Style_t GetTitleFont() const
Definition: TAttAxis.h:47
virtual Float_t GetLabelOffset() const
Definition: TAttAxis.h:40
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition: TAttAxis.cxx:163
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition: TAttAxis.cxx:206
virtual Style_t GetLabelFont() const
Definition: TAttAxis.h:39
virtual void SetTitleFont(Style_t font=62)
Set the title font.
Definition: TAttAxis.cxx:330
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition: TAttAxis.cxx:194
virtual void SetLabelFont(Style_t font=62)
Set labels' font.
Definition: TAttAxis.cxx:183
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
Definition: TAttAxis.cxx:312
virtual void SaveAttributes(std::ostream &out, const char *name, const char *subname)
Save axis attributes as C++ statement(s) on output stream out.
Definition: TAttAxis.cxx:111
virtual void SetTitleColor(Color_t color=1)
Set color of axis title.
Definition: TAttAxis.cxx:321
virtual Float_t GetTitleSize() const
Definition: TAttAxis.h:44
virtual void Streamer(TBuffer &)
Stream an object of class TAttAxis.
Definition: TAttAxis.cxx:339
virtual Float_t GetLabelSize() const
Definition: TAttAxis.h:41
virtual Float_t GetTickLength() const
Definition: TAttAxis.h:45
virtual void ResetAttAxis(Option_t *option="")
Reset axis attributes.
Definition: TAttAxis.cxx:79
virtual Float_t GetTitleOffset() const
Definition: TAttAxis.h:43
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length.
Definition: TAttAxis.cxx:287
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:236
void Copy(TAttAxis &attaxis) const
Copy of the object.
Definition: TAttAxis.cxx:61
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Set color of labels.
Definition: TAttAxis.cxx:173
TAxis helper class used to store the modified labels.
Definition: TAxisModLab.h:21
void SetColor(Int_t c=-1)
Set modified label color.
Definition: TAxisModLab.cxx:68
void SetSize(Double_t s=-1.)
Set modified label size.
Definition: TAxisModLab.cxx:54
void SetFont(Int_t f=-1)
Set modified label font.
Definition: TAxisModLab.cxx:75
void SetText(TString t="")
Set modified label text.
Definition: TAxisModLab.cxx:82
void SetAlign(Int_t a=-1)
Set modified label alignment.
Definition: TAxisModLab.cxx:61
void SetLabNum(Int_t n=0)
Set modified label number.
Definition: TAxisModLab.cxx:40
void SetAngle(Double_t a=-1.)
Set modified label angle.
Definition: TAxisModLab.cxx:47
Class to manage histogram axis.
Definition: TAxis.h:30
virtual void GetCenter(Double_t *center) const
Return an array with the center of all bins.
Definition: TAxis.cxx:554
virtual void SetTimeOffset(Double_t toffset, Option_t *option="local")
Change the time offset If option = "gmt", set display mode to GMT.
Definition: TAxis.cxx:1079
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
Definition: TAxis.cxx:642
virtual void SetDefaults()
Set axis default values (from TStyle)
Definition: TAxis.cxx:832
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:852
Int_t fLast
Last bin to display.
Definition: TAxis.h:38
static TClass * Class()
Bool_t IsAlphanumeric() const
Definition: TAxis.h:84
virtual void ZoomOut(Double_t factor=0, Double_t offset=0)
Zoom out by a factor of 'factor' (default =2) uses previous zoom factor by default Keep center define...
Definition: TAxis.cxx:1240
const char * GetTitle() const override
Returns title of object.
Definition: TAxis.h:130
Int_t GetNlabels() const
Return the number of axis labels.
Definition: TAxis.cxx:582
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:479
TObject * fParent
! Object owning this axis
Definition: TAxis.h:42
Double_t fXmax
Upper edge of last bin.
Definition: TAxis.h:35
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to an axis.
Definition: TAxis.cxx:266
Bool_t CanExtend() const
Definition: TAxis.h:82
TArrayD fXbins
Bin edges array in X.
Definition: TAxis.h:36
TAxis()
Default constructor.
Definition: TAxis.cxx:50
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition: TAxis.cxx:282
virtual void UnZoom()
Reset first & last bin to the full range.
Definition: TAxis.cxx:1165
THashList * fLabels
List of labels.
Definition: TAxis.h:43
void SetCanExtend(Bool_t canExtend)
Definition: TAxis.h:86
void Copy(TObject &axis) const override
Copy axis structure to another axis.
Definition: TAxis.cxx:211
virtual void SetTicks(Option_t *option="+")
Set ticks orientation.
Definition: TAxis.cxx:1005
@ kTickMinus
Definition: TAxis.h:60
@ kLabelsUp
Definition: TAxis.h:70
@ kCenterTitle
Definition: TAxis.h:62
@ kRotateTitle
Definition: TAxis.h:64
@ kNoExponent
Definition: TAxis.h:66
@ kMoreLogLabels
Definition: TAxis.h:72
@ kTickPlus
Definition: TAxis.h:59
@ kLabelsDown
Definition: TAxis.h:69
@ kLabelsHori
Definition: TAxis.h:67
@ kAxisRange
Definition: TAxis.h:61
@ kDecimals
Definition: TAxis.h:58
@ kCenterLabels
Bit 13 is used by TObject.
Definition: TAxis.h:63
@ kLabelsVert
Definition: TAxis.h:68
Bool_t fTimeDisplay
On/off displaying time values instead of numerics.
Definition: TAxis.h:40
TList * fModLabs
List of modified labels.
Definition: TAxis.h:44
const char * GetBinLabel(Int_t bin) const
Return label for bin.
Definition: TAxis.cxx:441
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:294
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:519
Int_t fNbins
Number of bins.
Definition: TAxis.h:33
@ kAlphanumeric
Axis is alphanumeric.
Definition: TAxis.h:48
Double_t fXmin
Low edge of first bin.
Definition: TAxis.h:34
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition: TAxis.cxx:760
Bool_t HasBinWithoutLabel() const
This helper function checks if there is a bin without a label if all bins have labels,...
Definition: TAxis.cxx:626
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:420
const char * ChooseTimeFormat(Double_t axislength=0)
Choose a reasonable time format from the coordinates in the active pad and the number of divisions in...
Definition: TAxis.cxx:127
void SaveAttributes(std::ostream &out, const char *name, const char *subname) override
Save axis attributes as C++ statement(s) on output stream out.
Definition: TAxis.cxx:690
TClass * IsA() const override
Definition: TAxis.h:168
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:470
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition: TAxis.cxx:660
virtual const char * GetTimeFormatOnly() const
Return only the time format from the string fTimeFormat.
Definition: TAxis.cxx:600
virtual Double_t GetBinCenterLog(Int_t bin) const
Return center of bin in log With a log-equidistant binning for a bin with low and up edges,...
Definition: TAxis.cxx:502
void SetAlphanumeric(Bool_t alphanumeric=kTRUE)
Set axis alphanumeric.
Definition: TAxis.cxx:808
void Streamer(TBuffer &) override
Stream an object of class TAxis.
Definition: TAxis.cxx:1112
TAxis & operator=(const TAxis &)
Assignment operator.
Definition: TAxis.cxx:114
~TAxis() override
Destructor.
Definition: TAxis.cxx:89
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates, that is,...
Definition: TAxis.cxx:979
virtual const char * GetTimeFormat() const
Definition: TAxis.h:128
virtual void GetLowEdge(Double_t *edge) const
Return an array with the low edge of all bins.
Definition: TAxis.cxx:563
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition: TAxis.cxx:1053
Bool_t CanBeAlphanumeric()
Definition: TAxis.h:83
TString fTimeFormat
Date&time format, ex: 09/12/99 12:34:00.
Definition: TAxis.h:41
virtual TObject * GetParent() const
Definition: TAxis.h:124
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition: TAxis.cxx:953
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition: TAxis.cxx:541
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:529
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:459
virtual const char * GetTicks() const
Return the ticks option (see SetTicks)
Definition: TAxis.cxx:615
UShort_t fBits2
Second bit status word.
Definition: TAxis.h:39
Int_t fFirst
First bin to display.
Definition: TAxis.h:37
void ChangeLabel(Int_t labNum=0, Double_t labAngle=-1., Double_t labSize=-1., Int_t labAlign=-1, Int_t labColor=-1, Int_t labFont=-1, TString labText="")
Define new text attributes for the label number "labNum".
Definition: TAxis.cxx:906
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual Int_t ReadArray(Bool_t *&b)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
Bool_t IsReading() const
Definition: TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual Int_t GetEntries() const
Definition: TCollection.h:179
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:184
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
static TClass * Class()
virtual Int_t GetDimension() const
Definition: TH1.h:281
@ kIsZoomed
Bit set when zooming on Y axis.
Definition: TH1.h:167
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:319
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition: TH1.cxx:8420
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:397
TAxis * GetYaxis()
Definition: TH1.h:320
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:398
@ kNstat
Size of statistics data (up to TProfile3D)
Definition: TH1.h:182
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
Definition: TH1.cxx:8510
static void Optimize(Double_t A1, Double_t A2, Int_t nold, Double_t &BinLow, Double_t &BinHigh, Int_t &nbins, Double_t &BWID, Option_t *option="")
Static function to compute reasonable axis limits.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition: THashList.cxx:207
void Rehash(Int_t newCapacity)
Rehash the hashlist.
Definition: THashList.cxx:368
TObject * FindObject(const char *name) const override
Find object using its name.
Definition: THashList.cxx:262
A doubly linked list.
Definition: TList.h:38
void Add(TObject *obj) override
Definition: TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
void Copy(TObject &named) const override
Copy this to obj.
Definition: TNamed.cxx:94
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
void Streamer(TBuffer &) override
Stream an object of class TObject.
Collectable string class.
Definition: TObjString.h:28
void SetString(const char *s)
Definition: TObjString.h:45
const char * GetName() const override
Returns name of object.
Definition: TObjString.h:38
Mother of all ROOT objects.
Definition: TObject.h:37
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:377
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:879
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:707
void ResetBit(UInt_t f)
Definition: TObject.h:186
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:867
Basic string class.
Definition: TString.h:136
Ssiz_t Length() const
Definition: TString.h:410
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1150
const char * Data() const
Definition: TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
Bool_t IsNull() const
Definition: TString.h:407
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
virtual void Streamer(TBuffer &)
Stream a string object.
Definition: TString.cxx:1370
TString & Append(const char *cs)
Definition: TString.h:564
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:639
Double_t GetTimeOffset() const
Definition: TStyle.h:261
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
for(Int_t i=0;i< n;i++)
Definition: legend1.C:18
static constexpr double s
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition: TMathBase.h:250
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Definition: TMath.h:677
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition: TMath.h:659
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Definition: TMathBase.h:347
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition: TMathBase.h:123
Definition: first.py:1
const double xbins[xbins_n]