本文整理汇总了C++中TGraph2D::SetTitle方法的典型用法代码示例。如果您正苦于以下问题:C++ TGraph2D::SetTitle方法的具体用法?C++ TGraph2D::SetTitle怎么用?C++ TGraph2D::SetTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TGraph2D
的用法示例。
在下文中一共展示了TGraph2D::SetTitle方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setGraphOptions
void setGraphOptions(TGraph2D &g)
{
g.SetTitle("");
g.SetMarkerColor(1);
g.SetMarkerStyle(24);
g.SetMarkerSize(.5);
}
示例2: w1
int w1() {
TCanvas *c = new TCanvas("c1", "", 0, 0, 700, 600);
TGraph2D *dt = new TGraph2D();
ifstream in("/opt/workspace-cpp/simulation/result_rand3.csv");
string buff;
getline(in, buff);
int meanResidenceTime;
int products;
float lastProductPrice;
float shopIncome;
int n = 0;
while (getline(in, buff)) {
for (unsigned int i = 0; i < buff.size(); i++) {
if (buff[i] == ';') {
buff[i] = ' ';
}
}
stringstream ss(buff);
ss >> meanResidenceTime;
ss >> products;
ss >> lastProductPrice;
ss >> shopIncome;
dt->SetPoint(n, products, meanResidenceTime, shopIncome);
n++;
}
gStyle->SetPalette(1);
dt->SetTitle("Zaleznosc zysku od liczby produktow oraz czasu przebywania w sklepie");
dt->GetXaxis()->SetTitle("Liczba produktow");
dt->GetYaxis()->SetTitle("Sredni czas przebywania w sklepie");
dt->GetZaxis()->SetTitle("Dochod");
dt->Draw("surf1");
}
示例3: TCanvas
TCanvas* graph2dfit()
{
gStyle->SetOptStat(0);
gStyle->SetOptFit();
TCanvas *c = new TCanvas("c","Graph2D example",0,0,600,800);
c->Divide(2,3);
Double_t rnd, x, y, z;
Double_t e = 0.3;
Int_t nd = 400;
Int_t np = 10000;
TRandom r;
Double_t fl = 6;
TF2 *f2 = new TF2("f2","1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+200",
-fl,fl,-fl,fl);
f2->SetParameters(1,1);
TGraph2D *dt = new TGraph2D();
// Fill the 2D graph
Double_t zmax = 0;
for (Int_t N=0; N<nd; N++) {
f2->GetRandom2(x,y);
// Generate a random number in [-e,e]
rnd = 2*r.Rndm()*e-e;
z = f2->Eval(x,y)*(1+rnd);
if (z>zmax) zmax = z;
dt->SetPoint(N,x,y,z);
}
Double_t hr = 350;
TH1D *h1 = new TH1D("h1",
"#splitline{Difference between Original}{#splitline{function and Function}{with noise}}",
100, -hr, hr);
TH1D *h2 = new TH1D("h2",
"#splitline{Difference between Original}{#splitline{function and Delaunay triangles}{interpolation}}",
100, -hr, hr);
TH1D *h3 = new TH1D("h3",
"#splitline{Difference between Original}{function and Minuit fit}",
500, -hr, hr);
f2->SetParameters(0.5,1.5);
dt->Fit(f2);
TF2 *fit2 = (TF2*)dt->FindObject("f2");
f2->SetParameters(1,1);
for (Int_t N=0; N<np; N++) {
f2->GetRandom2(x,y);
// Generate a random number in [-e,e]
rnd = 2*r.Rndm()*e-e;
z = f2->Eval(x,y)*(1+rnd);
h1->Fill(f2->Eval(x,y)-z);
z = dt->Interpolate(x,y);
h2->Fill(f2->Eval(x,y)-z);
z = fit2->Eval(x,y);
h3->Fill(f2->Eval(x,y)-z);
}
c->cd(1);
f2->SetTitle("Original function with Graph2D points on top");
f2->SetMaximum(zmax);
gStyle->SetHistTopMargin(0);
f2->Draw("surf1");
dt->Draw("same p0");
c->cd(3);
dt->SetMargin(0.1);
dt->SetFillColor(36);
dt->SetTitle("Histogram produced with Delaunay interpolation");
dt->Draw("surf4");
c->cd(5);
fit2->SetTitle("Minuit fit result on the Graph2D points");
fit2->Draw("surf1");
h1->SetFillColor(47);
h2->SetFillColor(38);
h3->SetFillColor(29);
c->cd(2); h1->Fit("gaus","Q") ; h1->Draw();
c->cd(4); h2->Fit("gaus","Q") ; h2->Draw();
c->cd(6); h3->Fit("gaus","Q") ; h3->Draw();
c->cd();
return c;
}
示例4: view_SMEvents_3D_from_Hits
void view_SMEvents_3D_from_Hits() {
/*** Displays an 3D occupancy plot for each SM Event. (stop mode event)
Can choose which SM event to start at. (find "CHOOSE THIS" in this script)
Input file must be a Hits file (_interpreted_Hits.root file).
***/
gROOT->Reset();
// Setting up file, treereader, histogram
TFile *f = new TFile("/home/pixel/pybar/tags/2.0.2_new/pyBAR-master/pybar/module_202_new/101_module_202_new_stop_mode_ext_trigger_scan_interpreted_Hits.root");
if (!f) { // if we cannot open the file, print an error message and return immediately
cout << "Error: cannot open the root file!\n";
//return;
}
TTreeReader *reader = new TTreeReader("Table", f);
TTreeReaderValue<UInt_t> h5_file_num(*reader, "h5_file_num");
TTreeReaderValue<Long64_t> event_number(*reader, "event_number");
TTreeReaderValue<UChar_t> tot(*reader, "tot");
TTreeReaderValue<UChar_t> relative_BCID(*reader, "relative_BCID");
TTreeReaderValue<Long64_t> SM_event_num(*reader, "SM_event_num");
TTreeReaderValue<Double_t> x(*reader, "x");
TTreeReaderValue<Double_t> y(*reader, "y");
TTreeReaderValue<Double_t> z(*reader, "z");
// Initialize the canvas and graph
TCanvas *c1 = new TCanvas("c1","3D Occupancy for Specified SM Event", 1000, 10, 900, 550);
c1->SetRightMargin(0.25);
TGraph2D *graph = new TGraph2D();
// Variables used to loop the main loop
bool endOfReader = false; // if reached end of the reader
bool quit = false; // if pressed q
int smEventNum = 1; // the current SM-event CHOOSE THIS to start at desired SM event number
// Main Loop (loops for every smEventNum)
while (!endOfReader && !quit) {
// Variables used in this main loop
int startEntryNum = 0;
int endEntryNum = 0;
string histTitle = "3D Occupancy for SM Event ";
string inString = "";
bool fitFailed = false; // true if the 3D fit failed
bool lastEvent = false;
// Declaring some important output values for the current graph and/or line fit
int numEntries = 0;
double sumSquares = 0;
// Get startEntryNum and endEntryNum
startEntryNum = getEntryNumWithSMEventNum(reader, smEventNum);
endEntryNum = getEntryNumWithSMEventNum(reader, smEventNum + 1);
if (startEntryNum == -2) { // can't find the smEventNum
cout << "Error: There should not be any SM event numbers that are missing." << "\n";
} else if (startEntryNum == -3) {
endOfReader = true;
break;
} else if (endEntryNum == -3) { // assuming no SM event nums are skipped
endEntryNum = reader->GetEntries(false);
lastEvent = true;
}
// Fill TGraph with points and set title and axes
graph = new TGraph2D(); // create a new TGraph to refresh
reader->SetEntry(startEntryNum);
for (int i = 0; i < endEntryNum - startEntryNum; i++) {
graph->SetPoint(i, (*x - 0.001), (*y + 0.001), (*z - 0.001));
endOfReader = !(reader->Next());
}
histTitle.append(to_string(smEventNum));
graph->SetTitle(histTitle.c_str());
graph->GetXaxis()->SetTitle("x (mm)");
graph->GetYaxis()->SetTitle("y (mm)");
graph->GetZaxis()->SetTitle("z (mm)");
graph->GetXaxis()->SetLimits(0, 20); // ROOT is buggy, x and y use setlimits()
graph->GetYaxis()->SetLimits(-16.8, 0); // but z uses setrangeuser()
graph->GetZaxis()->SetRangeUser(0, 40.96);
c1->SetTitle(histTitle.c_str());
// 3D Fit, display results, draw graph and line fit, only accept "good" events, get input
if (!endOfReader || lastEvent) {
// Display some results
numEntries = graph->GetN();
cout << "Current SM Event Number: " << smEventNum << "\n";
cout << "Number of entries: " << numEntries << "\n";
// Starting the fit. First, get decent starting parameters for the fit - do two 2D fits (one for x vs z, one for y vs z)
TGraph *graphZX = new TGraph();
TGraph *graphZY = new TGraph();
reader->SetEntry(startEntryNum);
for (int i = 0; i < endEntryNum - startEntryNum; i++) {
graphZX->SetPoint(i, (*z - 0.001), (*x + 0.001));
graphZY->SetPoint(i, (*z - 0.001), (*y + 0.001));
//.........这里部分代码省略.........
示例5: PlotSVMopt
void PlotSVMopt(){
// // TString FileData = "SVMoptData.dat";
// TFile *f = new TFile("SVMoptTree.root","RECREATE");
// TTree *T = new TTree("SVMoptTree","data from ascii file");
// Long64_t nlines = T->ReadFile("SVMoptData.dat","Gamma:C:ROCint:SigAt1Bkg_test:SigAt1Bkg_train");
// printf(" found %lld pointsn",nlines);
// T->Write();
// TGraph2D *grROCint = new TGraph2D();
// for(int i=0;i<nlines;i++){
// grROCint->SetPoint(i,);
// }
TGraph2D *grROCint = new TGraph2D();
TGraph2D *grSigAt1Bkg_test = new TGraph2D();
TGraph2D *grOverTrain = new TGraph2D();
TString dir = gSystem->UnixPathName(__FILE__);
dir.ReplaceAll("PlotSVMopt.C","");
dir.ReplaceAll("/./","/");
ifstream in;
// in.open(Form("%sSVMoptData.dat",dir.Data()));
in.open(Form("%sSVMoptData_NEW2.dat",dir.Data()));
Float_t Gamma,C,ROCint, SigAt1Bkg_test, SigAt1Bkg_train;
Int_t nlines = 0;
while (1) {
in >> Gamma >> C >> ROCint >> SigAt1Bkg_test >> SigAt1Bkg_train;
if (!in.good()) break;
// if (in.good()){
if (nlines < 5) printf("Gamma=%8f, C=%8f, ROCint=%8f\n",Gamma, C, ROCint);
grROCint->SetPoint(nlines,Gamma,C,ROCint);
grSigAt1Bkg_test->SetPoint(nlines,Gamma,C,SigAt1Bkg_test);
grOverTrain->SetPoint(nlines,Gamma,C,fabs(SigAt1Bkg_train-SigAt1Bkg_test));
nlines++;
// }
}
printf(" found %d points\n",nlines);
in.close();
TCanvas *cSVMopt = new TCanvas("cSVMopt","SVM model choice",600,600);
cSVMopt->Divide(2,2);
cSVMopt->cd(1);
cSVMopt_1->SetLogx();
cSVMopt_1->SetLogy();
grROCint->GetXaxis()->SetLabelSize(0.04);
grROCint->GetYaxis()->SetLabelSize(0.04);
grROCint->GetZaxis()->SetLabelSize(0.04);
grROCint->GetXaxis()->SetTitle("#gamma");
grROCint->GetYaxis()->SetTitle("C");
grROCint->GetZaxis()->SetTitle("ROC integral");
grROCint->SetTitle("ROC integral");
grROCint->SetMaximum(1.0);
grROCint->SetMinimum(0.9);
grROCint->Draw("COLZ");
cSVMopt->cd(2);
cSVMopt_2->SetLogx();
cSVMopt_2->SetLogy();
grSigAt1Bkg_test->SetTitle("Signal at 1% Bkg level (test)");
// grSigAt1Bkg_test->Draw("surf1");
grSigAt1Bkg_test->Draw("COLZ");
cSVMopt->cd(3);
cSVMopt_3->SetLogx();
cSVMopt_3->SetLogy();
grOverTrain->SetTitle("Overtraining");
grOverTrain->Draw("COLZ");
//cSVMopt->SaveAs("SVMoptC1.root");
}
示例6: main
//.........这里部分代码省略.........
std::cout << "Simpson integral: " <<s_integral <<std::endl;
integral_hist->Fill(s_integral);
cmp_int[i] = s_integral;
Int_t lines = (Int_t)intb.size();
TGraph *r_integral = new TGraph(lines, _inta, _intb);
std::cout << "ROOT integral: " << r_integral->Integral() << std::endl;
cmp_int_root[i] = r_integral->Integral();
//expanding
//expand(y, THRS_EXPAND, RATIO_EXPAND, LINES);
//Filling TGraph2D
for(Int_t j = 0; j <LINES ; j++){
if (y[j] > max){
max = y[j];
maxwl = x[j];
}
gr->SetPoint(j+i*LINES, x[j],i,y[j]);
}
in.seekg(0, std::ios::beg);
in.close();
//Plotting each spectrum
TGraph *_gr = new TGraph(LINES,x,y);
_gr->GetHistogram()->GetXaxis()->SetTitle("#lambda in nm");
_gr->GetHistogram()->GetYaxis()->SetTitle("Intensity in dB");
c1->cd(i-NUM_ARGS);
_gr->Draw("AP");
_gr->GetYaxis()->SetRangeUser(-80.,-10.);
_gr->GetXaxis()->SetRangeUser(startwl,stopwl);
_gr->SetTitle(tmp.c_str());
c1->Update();
//Calculating asymmetry
std::cout << "maximum: " << max << std::endl;
double leftlimit, rightlimit = 1;
leftlimit = findlower(x,y, max);
rightlimit = findupper(x,y, max);
if (leftlimit != 1 && rightlimit != 1){
width_ary[i] = (leftlimit +rightlimit)/2;
}else{
width_ary[i] = maxwl;
}
double calced_asy = (maxwl-leftlimit)/(rightlimit-maxwl);
asymmety_ary[i-NUM_ARGS] = calced_asy;
std::cout << "Asymmetry: " << calced_asy << std::endl;
}catch(std::exception e){
std::cout << e.what()<< std::endl;
}
}
//Setting style for 3D Plot
TCanvas *d = new TCanvas("big","big",10,10,1500,800);
示例7: FitXS
void FitXS (int nminx = 0, int nmaxx = 1509, int nmintest = 0, int nmaxtest = 1509) {
////////////////////////////////////////////////////
// ftp://root.cern.ch/root/doc/ROOTUsersGuideHTML/ch09s05.html
TStyle *defaultStyle = new TStyle("defaultStyle","Default Style");
//gStyle->SetOptStat(0);
// defaultStyle->SetOptStat(0000);
// defaultStyle->SetOptFit(000);
// defaultStyle->SetPalette(1);
////////////////////////
defaultStyle->SetOptStat(0); // remove info box
/////// pad ////////////
defaultStyle->SetPadBorderMode(0);
defaultStyle->SetPadBorderSize(3);
defaultStyle->SetPadColor(0);
defaultStyle->SetPadTopMargin(0.1);
defaultStyle->SetPadBottomMargin(0.16);
defaultStyle->SetPadRightMargin(5.5);
defaultStyle->SetPadLeftMargin(0.18);
/////// canvas /////////
defaultStyle->SetCanvasBorderMode(1);
defaultStyle->SetCanvasColor(0);
// defaultStyle->SetCanvasDefH(600);
// defaultStyle->SetCanvasDefW(600);
/////// frame //////////
//defaultStyle->SetFrameBorderMode(1);
//defaultStyle->SetFrameBorderSize(1);
defaultStyle->SetFrameFillColor(0);
defaultStyle->SetFrameLineColor(1);
/////// label //////////
// defaultStyle->SetLabelOffset(0.005,"XY");
// defaultStyle->SetLabelSize(0.05,"XY");
//defaultStyle->SetLabelFont(46,"XY");
/////// title //////////
//defaultStyle->SetTitleW(0.6);
defaultStyle->SetTitleSize(0.08, "XYZ");
defaultStyle->SetTitleBorderSize(0);
defaultStyle->SetTitleX(0.2);
// defaultStyle->SetTitleOffset(1.1,"X");
// defaultStyle->SetTitleSize(0.01,"X");
// defaultStyle->SetTitleOffset(1.25,"Y");
// defaultStyle->SetTitleSize(0.05,"Y");
//defaultStyle->SetTitleFont(42, "XYZ");
/////// various ////////
defaultStyle->SetNdivisions(303,"Y");
defaultStyle->SetTitleFillColor(0);//SetTitleFillStyle(0, "Z");
//defaultStyle->SetTitleX(0.2);
//defaultStyle->SetTitleY(0.1);
//defaultStyle->SetTitleBorderSize(-0.1); // For the axis titles:
// defaultStyle->SetTitleColor(1, "XYZ");
// defaultStyle->SetTitleFont(42, "XYZ");
// defaultStyle->SetTitleYSize(0.08);
//defaultStyle->SetTitleXOffset(0.9);
//defaultStyle->SetTitleYOffset(1.05);
defaultStyle->SetTitleOffset(1.3, "Y"); // Another way to set the Offset
//defaultStyle->SetTitleOffset(1.0, "X"); // Another way to set the Offset
// For the axis labels:
defaultStyle->SetLabelColor(1, "XYZ");
//defaultStyle->SetLabelFont(46, "XYZ");
defaultStyle->SetLabelOffset(0.03, "XYZ");
defaultStyle->SetLabelSize(0.07, "XYZ");
//defaultStyle->SetLabelY(0.06);
// For the axis:
// defaultStyle->SetAxisColor(1, "XYZ");
defaultStyle->SetStripDecimals(kTRUE);
defaultStyle->SetTickLength(0.03, "XYZ");
defaultStyle->SetNdivisions(7, "XYZ");
// defaultStyle->SetPadTickX(1); // To get tick marks on the opposite side of the frame
// defaultStyle->SetPadTickY(1);
defaultStyle->cd();
///////////////////////////////////////////
nmin=nminx;
nmax=nmaxx;
if (nmin<0) nmin=0;
if (nmax>Npoints) nmax=Npoints;
// Read in the cross section values and the parameters space points
ifstream XSvals;
XSvals.open("list_all_translation_CX.txt");//"14TeV_CX_5k_opositecgw.ascii");// "8TeV_CX_5k_opositecgw.ascii");//
for (int i=nmin; i<nmax; i++) {
XSvals >> par0[i] >> par1[i] >> par2[i] >> par3[i] >> par4[i] >> cross_section[i] >> cross_sectionerr[i];
cout << "For point i = " << i << "pars are " << par0[i] << " " << par1[i] << " " << par2[i]
<< " " << par3[i] << " " << par4[i] << " and xs is " << cross_section[i] << endl;
}
cout << "**********************************************" << endl;
// Likelihood maximization
// -----------------------
// Minuit routine
TMinuit rmin(2);
rmin.SetFCN(Likelihood);
// Main initialization member function for MINUIT
rmin.mninit(5,6,7);
// Parameters needed to be unambiguous with MINOS
int iflag=0; // You can use this for selection
double arglis[4];
//.........这里部分代码省略.........