TH1Manipulator.cxx
Go to the documentation of this file.
1 // TH1Manipulator.cxx
2 
3 #include "TH1Manipulator.h"
4 #include "TH1.h"
5 #include "TPad.h"
6 #include "TAxis.h"
7 #include "TGaxis.h"
8 #include "TList.h"
9 #include "TStyle.h"
10 
11 using std::string;
12 
13 //**********************************************************************
14 
16  addaxistop(ph);
17  return addaxisright(ph);
18 }
19 
20 //**********************************************************************
21 
23  double ticksize = 0;
24  int ndiv = 0;
25  if ( ph != 0 ) {
26  TAxis* paxold = ph->GetXaxis();
27  if ( paxold != 0 ) {
28  ticksize = paxold->GetTickLength();
29  ndiv = paxold->GetNdivisions();
30  }
31  }
32  return addaxistop(ticksize, ndiv);
33 }
34 
35 //**********************************************************************
36 
37 int TH1Manipulator::addaxistop(double ticksize, int ndiv) {
38  double xmin = 0.0;
39  double xmax = 0.0;
40  double ymin = 0.0;
41  double ymax = 0.0;
42  if ( gPad == 0 ) return 3;
43  gPad->Update();
44  gPad->GetRangeAxis(xmin, ymin, xmax, ymax);
45  double xax1 = gPad->GetUxmin();
46  double xax2 = gPad->GetUxmax();
47  double yax = gPad->GetUymax();
48  string sopt = "-US";
49  if ( gPad->GetLogx() ) {
50  xax1 = pow(10.0, xax1);
51  xax2 = pow(10.0, xax2);
52  xmin = pow(10.0, xmin);
53  xmax = pow(10.0, xmax);
54  sopt += "G";
55  }
56  if ( gPad->GetLogy() ) {
57  yax = pow(10.0, yax);
58  }
59  TGaxis* paxnew = new TGaxis(xax1, yax, xax2, yax,
60  xmin, xmax, 510, sopt.c_str());
61  if ( ticksize > 0 ) paxnew->SetTickSize(ticksize);
62  if ( ndiv > 0 ) paxnew->SetNdivisions(ndiv);
63  string name = "TopAxis";
64  paxnew->SetName(name.c_str());
65  TList* pobjs = gPad->GetListOfPrimitives();
66  for ( int iobj=0; iobj<pobjs->GetEntries(); ++iobj ) {
67  TGaxis* paxold = dynamic_cast<TGaxis*>(pobjs->At(iobj));
68  if ( paxold != 0 ) {
69 
70  if ( paxold->GetName() == name ) {
71  pobjs->RemoveAt(iobj);
72  break;
73  }
74  }
75  }
76  paxnew->Draw();
77  return 0;
78 }
79 
80 //**********************************************************************
81 
83  double ticksize = 0;
84  int ndiv = 0;
85  if ( ph != 0 ) {
86  TAxis* paxold = ph->GetYaxis();
87  if ( paxold != 0 ) {
88  ticksize = paxold->GetTickLength();
89  ndiv = paxold->GetNdivisions();
90  }
91  }
92  return addaxisright(ticksize, ndiv);
93 }
94 
95 //**********************************************************************
96 
97 int TH1Manipulator::addaxisright(double ticksize, int ndiv) {
98  double xmin = 0.0;
99  double xmax = 0.0;
100  double ymin = 0.0;
101  double ymax = 0.0;
102  if ( gPad == 0 ) return 3;
103  gPad->Update();
104  gPad->GetRangeAxis(xmin, ymin, xmax, ymax);
105  double xax = gPad->GetUxmax();
106  double yax1 = gPad->GetUymin();
107  double yax2 = gPad->GetUymax();
108  string sopt = "+US";
109  if ( gPad->GetLogx() ) {
110  xax = pow(10.0, xax);
111  }
112  if ( gPad->GetLogy() ) {
113  yax1 = pow(10.0, yax1);
114  yax2 = pow(10.0, yax2);
115  ymin = pow(10.0, ymin);
116  ymax = pow(10.0, ymax);
117  sopt += "G";
118  }
119  if ( gPad->GetLogy() ) sopt += "G";
120  TGaxis* paxnew = new TGaxis(xax, yax1, xax, yax2,
121  ymin, ymax, 510, sopt.c_str());
122  if ( ticksize > 0 ) paxnew->SetTickLength(ticksize);
123  if ( ndiv > 0 ) paxnew->SetNdivisions(ndiv);
124  string name = "RightAxis";
125  paxnew->SetName(name.c_str());
126  TList* pobjs = gPad->GetListOfPrimitives();
127  for ( int iobj=0; iobj<pobjs->GetEntries(); ++iobj ) {
128  TGaxis* paxold = dynamic_cast<TGaxis*>(pobjs->At(iobj));
129  if ( paxold != 0 ) {
130  if ( paxold->GetName() == name ) {
131  pobjs->RemoveAt(iobj);
132  break;
133  }
134  }
135  }
136  paxnew->Draw("");
137  return 0;
138 }
139 
140 //**********************************************************************
141 
143  if ( gPad == nullptr ) return 1;
144  if ( gStyle == nullptr ) return 2;
145  gPad->SetFrameFillColor(gStyle->GetColorPalette(0));
146  return 0;
147 }
148 
149 //**********************************************************************
150 //**********************************************************************
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
constexpr T pow(T x)
Definition: pow.h:72
static int addaxistop(TH1 *ph=0)
static int fixFrameFillColor()
static int addaxis(TH1 *ph=0)
static int addaxisright(TH1 *ph=0)