本文整理汇总了C++中TAxis::SetTitle方法的典型用法代码示例。如果您正苦于以下问题:C++ TAxis::SetTitle方法的具体用法?C++ TAxis::SetTitle怎么用?C++ TAxis::SetTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TAxis
的用法示例。
在下文中一共展示了TAxis::SetTitle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetAxis
//------------------------------------------------------------------------------
// SetAxis
//------------------------------------------------------------------------------
void SetAxis(TH1* hist,
TString xtitle,
TString ytitle,
Float_t size,
Float_t offset)
{
TAxis* xaxis = (TAxis*)hist->GetXaxis();
TAxis* yaxis = (TAxis*)hist->GetYaxis();
xaxis->SetLabelFont(42);
yaxis->SetLabelFont(42);
xaxis->SetTitleFont(42);
yaxis->SetTitleFont(42);
xaxis->SetLabelOffset(0.025);
yaxis->SetLabelOffset(0.025);
xaxis->SetTitleOffset(1.4);
yaxis->SetTitleOffset(offset);
xaxis->SetLabelSize(size);
yaxis->SetLabelSize(size);
xaxis->SetTitleSize(size);
yaxis->SetTitleSize(size);
xaxis->SetTitle(xtitle);
yaxis->SetTitle(ytitle);
xaxis->SetNdivisions(505);
yaxis->SetNdivisions(505);
yaxis->CenterTitle();
gPad->GetFrame()->DrawClone();
gPad->RedrawAxis();
}
示例2:
TH2* RootWriter::CreateTH2(Histogram2D* h)
{
const Axis& xax = h->GetAxisX(), yax = h->GetAxisY();
const int xchannels = xax.GetBinCount();
const int ychannels = yax.GetBinCount();
TH2* mat = new TH2F( h->GetName().c_str(), h->GetTitle().c_str(),
xchannels, xax.GetLeft(), xax.GetRight(),
ychannels, yax.GetLeft(), yax.GetRight() );
mat->SetOption( "colz" );
mat->SetContour( 64 );
TAxis* rxax = mat->GetXaxis();
rxax->SetTitle(xax.GetTitle().c_str());
rxax->SetTitleSize(0.03);
rxax->SetLabelSize(0.03);
TAxis* ryax = mat->GetYaxis();
ryax->SetTitle(yax.GetTitle().c_str());
ryax->SetTitleSize(0.03);
ryax->SetLabelSize(0.03);
ryax->SetTitleOffset(1.3);
TAxis* zax = mat->GetZaxis();
zax->SetLabelSize(0.025);
for(int iy=0; iy<ychannels+2; ++iy)
for(int ix=0; ix<xchannels+2; ++ix)
mat->SetBinContent(ix, iy, h->GetBinContent(ix, iy));
mat->SetEntries( h->GetEntries() );
return mat;
}
示例3: PlotRatevsDAC
bool TMRCScanner::PlotRatevsDAC(int xmin,int xmax,int ymax)
{
int channel = 0;
// Read channel range from configuration
ffile = new TFile(foutfile);
if (ffile->IsOpen()){
ftree = (TTree*) ffile->Get("T");
//ftree->SetMarkerStyle(23);
//ftree->SetLineColor(kRed);
ftree->Draw("(HITEntries[0]/Duration):DAC>>hDAC(1024,0,1023,2001,0,2000)","HITEntries!=0","L");
TH2F *h = (TH2F*)gPad->GetPrimitive("hDAC");
TAxis *xaxis = h->GetXaxis();
xaxis->SetTitle("Threshold [DAC unit]");
xaxis->SetRange(xmin,xmax);
TAxis *yaxis = h->GetYaxis();
yaxis->SetTitle("Rate [Hz]");
yaxis->SetRange(0,ymax);
h->SetTitle("Pulse Amplitude Integral Distribution");
for (int i = 2048; i<(2048+128); i++) {
ftree->Draw(Form("(HITEntries[%d]/Duration):DAC",channel+i),"HITEntries!=0","SAME,L");
printf("%d\n",i);
}
ftree->SetLineColor(kRed);
ftree->Draw("Rate:DAC","","SAME,L");
}else {
printf("File %s not opened \n",foutfile);
return false;
}
delete ffile;
return true;
}
示例4: showGraph
void showGraph(double canvasSizeX, double canvasSizeY,
TGraph* graph,
bool useLogScaleX, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset,
bool useLogScaleY, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset,
const std::string& outputFileName)
{
TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY);
canvas->SetFillColor(10);
canvas->SetBorderSize(2);
canvas->SetTopMargin(0.05);
canvas->SetLeftMargin(0.19);
canvas->SetBottomMargin(0.19);
canvas->SetRightMargin(0.05);
canvas->SetLogx(useLogScaleX);
canvas->SetLogy(useLogScaleY);
TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", 10, xMin, xMax);
dummyHistogram->SetTitle("");
dummyHistogram->SetStats(false);
dummyHistogram->SetMinimum(yMin);
dummyHistogram->SetMaximum(yMax);
dummyHistogram->Draw("axis");
TAxis* xAxis = dummyHistogram->GetXaxis();
xAxis->SetTitle(xAxisTitle.data());
xAxis->SetTitleOffset(xAxisOffset);
xAxis->SetTitleSize(0.065);
xAxis->SetLabelSize(0.055);
xAxis->SetLabelOffset(0.01);
xAxis->SetTickLength(0.055);
xAxis->SetNdivisions(505);
TAxis* yAxis = dummyHistogram->GetYaxis();
yAxis->SetTitle(yAxisTitle.data());
yAxis->SetTitleOffset(yAxisOffset);
yAxis->SetTitleSize(0.070);
yAxis->SetLabelSize(0.055);
yAxis->SetLabelOffset(0.01);
yAxis->SetTickLength(0.055);
yAxis->SetNdivisions(505);
graph->SetMarkerColor(1);
graph->SetLineColor(1);
graph->Draw("p");
canvas->Update();
size_t idx = outputFileName.find_last_of('.');
std::string outputFileName_plot = std::string(outputFileName, 0, idx);
if ( useLogScaleY ) outputFileName_plot.append("_log");
else outputFileName_plot.append("_linear");
if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
canvas->Print(std::string(outputFileName_plot).append(".png").data());
//canvas->Print(std::string(outputFileName_plot).append(".pdf").data());
//canvas->Print(std::string(outputFileName_plot).append(".root").data());
delete dummyHistogram;
delete canvas;
}
示例5: showHistograms
void showHistograms(double canvasSizeX, double canvasSizeY,
TH1* histogram,
double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset,
bool useLogScale, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset,
const std::string& outputFileName)
{
TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY);
canvas->SetFillColor(10);
canvas->SetBorderSize(2);
canvas->SetLeftMargin(0.15);
canvas->SetBottomMargin(0.15);
canvas->SetLogy(useLogScale);
histogram->SetTitle("");
histogram->SetStats(true);
histogram->SetMinimum(yMin);
histogram->SetMaximum(yMax);
histogram->SetLineColor(1);
histogram->SetLineWidth(2);
histogram->SetMarkerColor(1);
histogram->SetMarkerStyle(20);
histogram->SetMarkerSize(1.5);
histogram->Draw("hist");
TAxis* xAxis = histogram->GetXaxis();
xAxis->SetRangeUser(xMin, xMax);
xAxis->SetTitle(xAxisTitle.data());
xAxis->SetTitleSize(0.060);
xAxis->SetTitleOffset(xAxisOffset);
xAxis->SetLabelSize(0.050);
xAxis->SetNdivisions(505);
TAxis* yAxis = histogram->GetYaxis();
yAxis->SetTitle(yAxisTitle.data());
yAxis->SetTitleSize(0.060);
yAxis->SetTitleOffset(yAxisOffset);
yAxis->SetLabelSize(0.050);
yAxis->SetNdivisions(505);
canvas->Update();
size_t idx = outputFileName.find_last_of('.');
std::string outputFileName_plot = std::string(outputFileName, 0, idx);
if ( useLogScale ) outputFileName_plot.append("_log");
else outputFileName_plot.append("_linear");
if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
//canvas->Print(std::string(outputFileName_plot).append(".png").data());
canvas->Print(std::string(outputFileName_plot).append(".pdf").data());
//canvas->Print(std::string(outputFileName_plot).append(".root").data());
delete canvas;
}
示例6: setup_TGraph
void setup_TGraph(TGraph* graph, std::string xtitle, std::string ytitle, int lcolor){
graph->SetLineColor(lcolor);
graph->SetLineWidth(LINE_WIDTH);
// graph->Draw();
TAxis *xaxis = graph->GetXaxis();
TAxis *yaxis = graph->GetYaxis();
xaxis->SetTitle(xtitle.c_str());
yaxis->SetTitle(ytitle.c_str());
xaxis->SetTitleOffset(1.1);
yaxis->SetTitleOffset(1.1);
}
示例7: macro4
// Create, Draw and fit a TGraph2DErrors
void macro4(){
gStyle->SetPalette(57);
const double e = 0.3;
const int nd = 500;
TRandom3 my_random_generator;
TF2 f2("f2",
"1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+200",
-6,6,-6,6);
f2.SetParameters(1,1);
TGraph2DErrors dte(nd);
// Fill the 2D graph
double rnd, x, y, z, ex, ey, ez;
for (Int_t i=0; i<nd; i++) {
f2.GetRandom2(x,y);
// A random number in [-e,e]
rnd = my_random_generator.Uniform(-e,e);
z = f2.Eval(x,y)*(1+rnd);
dte.SetPoint(i,x,y,z);
ex = 0.05*my_random_generator.Uniform();
ey = 0.05*my_random_generator.Uniform();
ez = fabs(z*rnd);
dte.SetPointError(i,ex,ey,ez);
}
// Fit function to generated data
f2.SetParameters(0.7,1.5); // set initial values for fit
f2.SetTitle("Fitted 2D function");
dte.Fit(&f2);
// Plot the result
auto c1 = new TCanvas();
f2.SetLineWidth(1);
f2.SetLineColor(kBlue-5);
TF2 *f2c = (TF2*)f2.DrawClone("Surf1");
TAxis *Xaxis = f2c->GetXaxis();
TAxis *Yaxis = f2c->GetYaxis();
TAxis *Zaxis = f2c->GetZaxis();
Xaxis->SetTitle("X Title"); Xaxis->SetTitleOffset(1.5);
Yaxis->SetTitle("Y Title"); Yaxis->SetTitleOffset(1.5);
Zaxis->SetTitle("Z Title"); Zaxis->SetTitleOffset(1.5);
dte.DrawClone("P0 Same");
// Make the x and y projections
auto c_p= new TCanvas("ProjCan",
"The Projections",1000,400);
c_p->Divide(2,1);
c_p->cd(1);
dte.Project("x")->Draw();
c_p->cd(2);
dte.Project("y")->Draw();
}
示例8: showHistogram1d
void showHistogram1d(TH1* histogram,
const std::string& xAxisTitle,
Float_t* genX,
const std::string& outputFileName)
{
TCanvas* canvas = new TCanvas("canvas", "canvas", 800, 600);
canvas->SetFillColor(10);
canvas->SetBorderSize(2);
canvas->SetTopMargin(0.10);
canvas->SetLeftMargin(0.16);
canvas->SetRightMargin(0.14);
canvas->SetBottomMargin(0.12);
TAxis* xAxis = histogram->GetXaxis();
xAxis->SetTitle(xAxisTitle.data());
xAxis->SetTitleOffset(1.15);
TAxis* yAxis = histogram->GetYaxis();
yAxis->SetTitle("Sampling Points");
yAxis->SetTitleOffset(1.60);
histogram->SetLineColor(1);
histogram->SetLineWidth(2);
histogram->SetMarkerColor(1);
histogram->SetMarkerStyle(20);
histogram->Draw("e1p");
TMarker* genMarker = 0;
if ( genX ) {
genMarker = new TMarker(*genX, 0.10, 34);
genMarker->SetMarkerColor(1);
genMarker->SetMarkerSize(2);
genMarker->Draw();
}
canvas->Update();
size_t idx = outputFileName.find_last_of('.');
std::string outputFileName_plot = std::string(outputFileName, 0, idx);
if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
canvas->Print(std::string(outputFileName_plot).append(".png").data());
canvas->Print(std::string(outputFileName_plot).append(".pdf").data());
canvas->Print(std::string(outputFileName_plot).append(".root").data());
delete genMarker;
delete canvas;
}
示例9: residual_error
/*
double residual_error( double error_data, double pdf )
{
double chi2 = 0.;
if ( pdf > 0 )
chi2 += 2. * ( pdf - error_data );
if ( error_data > 0 && pdf > 0 )
chi2=(error_data/pdf);
//chi2 += 2. * error_data * log( error_data / error_pdf );
// return ( ( error_data >= pdf ) ? sqrt( chi2 ) : -sqrt( chi2 ) );
// return ( ( error_data >= pdf ) ? chi2 : chi2 );
return ( chi2 );
}
*/
TH1D* residualHist( const RooHist* rhist, const RooCurve* curve )
{
double r = 0.2;
double sr = 1. / r;
// Grab info from the histogram.
int n = rhist->GetN();
double* x = rhist->GetX();
double* y = rhist->GetY();
//rhist->Sumw2();
// double e;
// Create residual histogram.
double xMin = x[ 0 ];
double xMax = x[ n - 1 ];
TH1D* residuals_temp = new TH1D( "r", "", n, xMin, xMax );
double datum = 0.;
double pdf = 0.;
double error_data = 0.;
// Fill the histogram.
if ( curve )
for ( int bin = 0; bin < n; bin++ )
{
datum = y[ bin ];
pdf = curve->Eval( x[ bin ] );
error_data = rhist->GetErrorY(bin);
// error_pdf = curve->Eval( x[ bin ] );
residuals_temp->SetBinContent( bin + 1, residual( datum, pdf ) );
// residuals_temp->SetBinError ( bin + 1, residual_error( error_data, pdf ) );
residuals_temp->SetBinError ( bin + 1, error_data / pdf );
}
residuals_temp->SetMinimum ( -2. );
residuals_temp->SetMaximum ( 2. );
residuals_temp->SetStats ( false );
residuals_temp->SetMarkerStyle( 8 );
residuals_temp->SetMarkerSize ( .8 );
TAxis* xAxis = residuals_temp->GetXaxis();
xAxis->SetTickLength ( sr * xAxis->GetTickLength() );
xAxis->SetLabelSize ( sr * xAxis->GetLabelSize() );
xAxis->SetTitleSize ( sr * xAxis->GetTitleSize() );
xAxis->SetLabelOffset( sr * xAxis->GetLabelOffset() );
TAxis* yAxis = residuals_temp->GetYaxis();
//yAxis->SetNdivisions ( 500 );
//yAxis->SetLabelSize ( 10*sr * yAxis->GetLabelSize() );
yAxis->SetLabelSize ( 2.5 * yAxis->GetLabelSize() );
yAxis->SetTitle(" (DATA - FIT) / FIT");
yAxis->SetTitleSize ( 0.09 );
yAxis->SetTitleOffset( 0.35 );
return residuals_temp;
}
示例10: PlotLightYieldGraph
TGraphErrors* PlotLightYieldGraph()
{
string filename;
vector<double> x,y,ex,ey;
while(1){
cout<<"\n\nEnter next file to process; <enter> to finish."<<endl;
getline(cin, filename);
if(filename=="")
break;
//load the tree
TTree* Events = GetEventsTree(filename.c_str());
if(!Events)
continue;
gROOT->ProcessLine(".x analysis/Aliases.C");
double start = Events->GetMinimum("timestamp");
double end = Events->GetMaximum("timestamp");
double error = 0;
TString title = TString("Na22 Spectrum, ") +
TString(filename)(TRegexp("Run......"));
TH1F* hist = new TH1F("Na22Spec",title,200,1000,2500);
Events->Draw("sumspec >> Na22Spec","min > 0","e");
double yield = Fit511Photopeak(hist,&error);
x.push_back((start+end)/2.);
ex.push_back((end-start)/2.);
y.push_back(yield);
ey.push_back(error);
}
if(x.size() == 0){
cerr<<"No valid points found!"<<endl;
return 0;
}
TGraphErrors* graph = new TGraphErrors(x.size(),&x[0],&y[0],&ex[0],&ey[0]);
graph->Draw("ape");
TAxis* xax = graph->GetXaxis();
xax->SetTitle("Run Time");
xax->SetTimeDisplay(1);
xax->SetTimeFormat("%Y/%m/%d");
xax->SetTimeOffset(1,"gmt");
TAxis* yax = graph->GetYaxis();
yax->SetTitle("511 keV Light Yield [pe/keV]");
graph->Draw("ape");
return graph;
}
示例11: drawEmptyHisto
void drawEmptyHisto ( float Xmin, float Xmax, TString xTitle, float Ymin, float Ymax, TString yTitle, TString name )
{
printf ( "Setting empty histo: X: %.2f-%.2f\tY: %.2f-%.2f\n",Xmin,Xmax,Ymin,Ymax );
printf("Total luminosity to be plotted: %.3f\n",Xmax);
printf("Luminosity scale used: %.2f\n",lumiScale);
Xmax*=1.02; // Increasing max lumi to have free space
gStyle->SetOptStat ( 0 );
// TGaxis::SetMaxDigits ( 4 );
TH1F *histo = new TH1F ( name, xTitle, 1, Xmin, Xmax );
TAxis *xAx = histo->GetXaxis();
TAxis *yAx = histo->GetYaxis();
xAx->SetTitle ( xTitle );
// xAx->SetTitleOffset ( 1.1 );
// xAx->SetNdivisions ( 510 );
yAx->SetTitle ( yTitle );
// yAx->SetTitleOffset ( 1.15 );
// yAx->SetNdivisions ( 510 );
histo->SetMinimum ( Ymin );
histo->SetMaximum ( Ymax );
histo->Draw ( "AXIS" );
}
示例12: SetAxisLabels
void SetAxisLabels(TH1& hist, char* xtitle, char* ytitle="",
double xoffset=1.1, double yoffset=1.4) {
TAxis* x = hist.GetXaxis();
TAxis* y = hist.GetYaxis();
x->SetTitle(xtitle);
x->SetTitleSize(0.06);
x->SetLabelSize(0.05);
x->SetTitleOffset(xoffset);
x->SetNdivisions(505);
y->SetTitle(ytitle);
y->SetTitleSize(0.06);
y->SetLabelSize(0.05);
y->SetTitleOffset(yoffset);
y->SetNoExponent();
hist.SetLineWidth(2);
hist.SetMarkerStyle(20);
std::stringstream str;
str << "Events / " << (int) lumi << " pb^{-1} ";
std::string defYtitle = str.str();
if(ytitle=="") y->SetTitle( defYtitle.c_str() );
}
示例13: SetAxis
//------------------------------------------------------------------------------
// SetAxis
//------------------------------------------------------------------------------
void SetAxis(TH1* hist,
TString xtitle,
TString ytitle,
Float_t xoffset,
Float_t yoffset)
{
gPad->cd();
gPad->Update();
// See https://root.cern.ch/doc/master/classTAttText.html#T4
Float_t padw = gPad->XtoPixel(gPad->GetX2());
Float_t padh = gPad->YtoPixel(gPad->GetY1());
Float_t size = (padw < padh) ? padw : padh;
size = 20. / size; // Like this label size is always 20 pixels
TAxis* xaxis = (TAxis*)hist->GetXaxis();
TAxis* yaxis = (TAxis*)hist->GetYaxis();
xaxis->SetTitleOffset(xoffset);
yaxis->SetTitleOffset(yoffset);
xaxis->SetLabelSize(size);
yaxis->SetLabelSize(size);
xaxis->SetTitleSize(size);
yaxis->SetTitleSize(size);
xaxis->SetTitle(xtitle);
yaxis->SetTitle(ytitle);
yaxis->CenterTitle();
gPad->GetFrame()->DrawClone();
gPad->RedrawAxis();
}
示例14: drawBeamSpotPdfs
void drawBeamSpotPdfs (TDirectory* directory, const char* coord,
const char* fname)
{
TH3* obsHisto = directory->Get("PVobs");
TH3* estHisto = directory->Get("PVest");
if ( obsHisto==0 || estHisto==0 ) return;
std::string fullName("PV");
fullName += coord;
if ( fname ) fullName += fname;
else fullName += directory->GetName();
TCanvas* c = new TCanvas(fullName.c_str(),fullName.c_str());
c->SetLogy(true);
TH1* obsHisto1D = obsHisto->Project3D(coord);
TH1* estHisto1D = estHisto->Project3D(coord);
TAxis* xaxis = obsHisto1D->GetXaxis();
string atitle("Primary vertex ");
atitle += coord;
atitle += " [cm]";
xaxis->SetTitle(atitle.c_str());
if ( c->GetLogy() ) obsHisto1D->SetMinimum(0.5);
obsHisto1D->SetMarkerStyle(21);
// obsHisto1D->SetLineColor(2);
// obsHisto1D->SetMarkerColor(2);
obsHisto1D->Draw("E0");
estHisto1D->SetLineColor(2);
estHisto1D->SetLineWidth(2);
estHisto1D->Draw("hist same c");
if ( strcmp(coord,"x") || strcmp(coord,"y") ) xaxis->SetNdivisions(508);
string epsName = fullName + ".eps";
c->SaveAs(epsName.c_str());
string pngName = fullName + ".png";
c->SaveAs(pngName.c_str());
}
示例15: setHist
void LEPStyle::setHist()
{
_hist = new TH1F( "bidon", "bidon", 100, _xmin, _xmax );
_ax = _hist->GetXaxis();
_ay = _hist->GetYaxis();
_ax->SetTitle(_title);
_ax->SetNdivisions(_ndivx);
if( _logX )
{
_ax->SetMoreLogLabels();
}
_ax->SetLabelSize(_scale*0.060);
// _ax->SetLabelOffset(_scale*0.007);
_ax->SetTitleSize(_scale*0.070);
_ax->SetTitleOffset(0.9);
_ax->CenterTitle( _centerTitle );
_ay->SetNdivisions(0);
}