本文整理汇总了C++中TF1::Draw方法的典型用法代码示例。如果您正苦于以下问题:C++ TF1::Draw方法的具体用法?C++ TF1::Draw怎么用?C++ TF1::Draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TF1
的用法示例。
在下文中一共展示了TF1::Draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: plotMttResolution
void plotMttResolution() {
setTDRStyle();
TCanvas *c = new TCanvas("c", "c", 800, 800);
TH1F *mtt = (TH1F*) _file0->Get("mtt_resolution_mva");
mtt->SetTitle("");
mtt->SetName("m_{t#bar{t}}");
mtt->GetXaxis()->SetTitle("m_{t#bar{t}} - m_{t#bar{t}}^{gen} (GeV)");
mtt->SetLineColor(TColor::GetColor("#542437"));
mtt->SetLineColor(TColor::GetColor("#8A9B0F"));
mtt->SetLineColor(TColor::GetColor("#C02942"));
mtt->SetFillColor(mtt->GetLineColor());
mtt->SetFillStyle(3004);
mtt->GetXaxis()->SetTitleOffset(1.2);
TF1 *voigt = new TF1("voigt", "gaus", -100, 100);
voigt->SetParName(0, "amp");
voigt->SetParName(2, "mean");
voigt->SetParName(1, "sigma");
voigt->SetParameter(0, mtt->GetMaximum());
voigt->SetParameter(2, 0);
voigt->SetParameter(1, 100);
mtt->Fit(voigt, "RVN");
voigt->SetLineColor(TColor::GetColor("#8A9B0F"));
voigt->SetLineWidth(2);
mtt->Draw();
voigt->Draw("same");
TLatex* latex = new TLatex();
latex->SetTextFont(42);
latex->SetTextSize(0.033);
latex->DrawLatexNDC(0.25, 0.84, TString::Format("mean = %.2f", voigt->GetParameter(1)));
latex->DrawLatexNDC(0.25, 0.8, TString::Format("#sigma = %.2f", voigt->GetParameter(2)));
gPad->Modified();
gPad->Update();
c->Print("mtt_resolution.pdf");
}
示例2: GetRandomTest
void GetRandomTest(){
double k0=1.39;
double k1 = 0.425;
double theta0 = 3.41;
double theta1 = 1.30;
int iNpart=2;
double k_=k0+k1*(iNpart-2);
double theta_=theta0+theta1*TMath::Log(iNpart-1);
TF1 *f = new TF1("f","TMath::GammaDist(x,[0],0,[1])",0,200);
f->SetParameters(k1,theta_);
cout<<"Value at 0 = "<<f->Eval(0)<<endl;
cout<<"Value at 1e-11 = "<<f->Eval(1e-11)<<endl;
cout<<"Integral 1= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl;
f->SetRange(1e-12,200);
cout<<"Integral 2= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl;
cout<<"fXmin = "<<f->GetXmin()<<"\tfXmax = "<<f->GetXmax()<<"\tfNpx = "<<f->GetNpx()<<endl;
f->SetNpx(1e5);
TCanvas *c1 = new TCanvas();
c1->SetLogy();
cout<<"f mean = "<<f->Mean(0,200)<<endl;
cout<<"math mean = "<<f->GetParameter(0)*f->GetParameter(1)<<endl;
TH1D* h = new TH1D("h","h",1000,0,200);
for(int i=0;i<1e6;i++){
double para = f->GetRandom();
h->Fill(para);
}
h->Scale(1.0/h->Integral()*1000/200);
h->GetYaxis()->SetRangeUser(1e-10,1);
h->SetMarkerStyle(24);
h->SetMarkerColor(4);
h->SetMarkerSize(1.1);
TLegend *leg = new TLegend(0.6,0.7,0.8,0.9);
leg->SetFillColor(0);
leg->SetFillStyle(0);
leg->SetBorderSize(0);
leg->SetTextFont(42);
leg->SetTextSize(0.03);
leg->AddEntry(f,"function","lp");
leg->AddEntry(h,"filled histogram","lp");
h->Draw("P");
f->Draw("same");
leg->Draw("same");
cout<<"h mean = "<<h->GetMean(1)<<endl;
c1->Print("TestGetRandom.png");
}
示例3: masses
void plotter::draw_chi2(TF1 * fit_, std::vector<double> masses_, std::vector<double> chi2_, double mass, double uncert, TString file_name){
TF1 * fit = (TF1*)fit_->Clone("fit");
TVectorD masses(masses_.size());
TVectorD chi2(chi2_.size());
for(int i=0; i<masses_.size(); i++) masses[i] = masses_[i];
for(int i=0; i<chi2_.size(); i++) chi2[i] = chi2_[i];
TGraph* chi_hist = new TGraph(masses,chi2);
TCanvas *c = new TCanvas("Chi2", "", 600, 600);
gPad->SetLeftMargin(0.15);
TGaxis::SetMaxDigits(3);
chi_hist->SetTitle(" ");
chi_hist->GetXaxis()->SetTitle("m_{top}^{MC} [GeV]");
chi_hist->GetYaxis()->SetTitle("#chi^{2}");
chi_hist->GetYaxis()->SetTitleOffset(1.1);
chi_hist->GetXaxis()->SetTitleOffset(0.9);
chi_hist->GetYaxis()->SetTitleSize(0.05);
chi_hist->GetXaxis()->SetTitleSize(0.05);
chi_hist->GetXaxis()->SetNdivisions(505);
chi_hist->GetYaxis()->SetNdivisions(505);
chi_hist->SetMarkerStyle(20);
chi_hist->SetMarkerSize(1.5);
chi_hist->SetLineColor(1);
chi_hist->Draw("AP");
fit->Draw("SAME");
// write extracted mass value into plot
TLatex text;
text.SetNDC(kTRUE);
text.SetTextFont(43);
text.SetTextSize(18);
char mass_text[32];
sprintf(mass_text, "%.5g", mass);
char uncert_text[32];
if(uncert < 1) sprintf(uncert_text, "%.3g", uncert);
else sprintf(uncert_text, "%.4g", uncert);
TString masstext = "m_{top}^{MC} = ";
masstext += mass_text;
masstext += " #pm ";
masstext += uncert_text;
text.DrawLatex(.4,.6, masstext);
c->SaveAs(directory + file_name + ".pdf");
delete c;
return;
}
示例4: quick
void quick() {
//setTDRStyle();
TCanvas *canv = MakeCanvas("canv", "histograms", 800, 600);
canv->cd();
double eff_points[10] = { 0.55, 0.57, 0.59, 0.61, 0.63, 0.65, 0.67, 0.69, 0.71, 0.73 };
double eff_points_2[10] = { 0.55, 0.57, 0.59, 0.61, 0.63, 0.65, 0.67, 0.69, 0.71, 0.73 };
double sig_up[10] = { 1.22484, 1.20737, 1.19085, 1.17521, 1.16035, 1.14622, 1.13276, 1.11993, 1.10767, 1.09593 };
TF1 *fxn = new TF1("fxn", "[0]*TMath::Sqrt([1]*x+[2])/([3]*x+[4])", 0.4, 0.9);
fxn->SetParameter(0,114.622/10.7759);
fxn->SetParameter(1,11548);
fxn->SetParameter(2,658);
fxn->SetParameter(3,12.9);
fxn->SetParameter(4,0);
for (Int_t i=0; i<10; i++) {
sig_up[i]*=100;
eff_points_2[i]/=0.65;
}
TGraph *gr = new TGraph(10, eff_points, sig_up);
//TGraphAsymmErrors gr2(10, eff_points, sig_cent, 0, 0, sig_down, sig_up);
gr->SetLineColor(kRed);
//gr->SetLineWidth(2);
fxn->SetLineColor(kBlue);
//fxn->SetLineWidth(2);
//gr2->SetFillColor(kGreen);
gr->GetXaxis()->SetTitle("Hadronic #tau Efficiency");
gr->GetYaxis()->SetTitle("Uncertainty on #sigma_{HH}");
gr->Draw("alp");
cout << fxn->Eval(0.65) << endl;
fxn->Draw("same R");
}
示例5: v
void v()
{
TF1 *signal = new TF1("DGauss", DGauss, 0, 800, 7);
signal->SetParameter(0, 50);
signal->SetParameter(1, 1);
signal->SetParameter(2, 2);
signal->SetParameter(3, 100);
signal->SetParameter(4, -20);
signal->SetParameter(5, 22.374);
signal->SetParameter(6, 5.55);
signal->SetNpx(10000);
signal->Draw();
}
示例6: langaus
void langaus() {
// Fill Histogram
Int_t data[100] = {0,0,0,0,0,0,2,6,11,18,18,55,90,141,255,323,454,563,681,
737,821,796,832,720,637,558,519,460,357,291,279,241,212,
153,164,139,106,95,91,76,80,80,59,58,51,30,49,23,35,28,23,
22,27,27,24,20,16,17,14,20,12,12,13,10,17,7,6,12,6,12,4,
9,9,10,3,4,5,2,4,1,5,5,1,7,1,6,3,3,3,4,5,4,4,2,2,7,2,4};
TH1F *hSNR = new TH1F("snr","Signal-to-noise",400,0,400);
for (Int_t i=0; i<100; i++) hSNR->Fill(i,data[i]);
// Fitting SNR histo
printf("Fitting...\n");
// Setting fit range and start values
Double_t fr[2];
Double_t sv[4], pllo[4], plhi[4], fp[4], fpe[4];
fr[0]=0.3*hSNR->GetMean();
fr[1]=3.0*hSNR->GetMean();
pllo[0]=0.5; pllo[1]=5.0; pllo[2]=1.0; pllo[3]=0.4;
plhi[0]=5.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=5.0;
sv[0]=1.8; sv[1]=20.0; sv[2]=50000.0; sv[3]=3.0;
Double_t chisqr;
Int_t ndf;
TF1 *fitsnr = langaufit(hSNR,fr,sv,pllo,plhi,fp,fpe,&chisqr,&ndf);
Double_t SNRPeak, SNRFWHM;
langaupro(fp,SNRPeak,SNRFWHM);
printf("Fitting done\nPlotting results...\n");
// Global style settings
gStyle->SetOptStat(1111);
gStyle->SetOptFit(111);
gStyle->SetLabelSize(0.03,"x");
gStyle->SetLabelSize(0.03,"y");
hSNR->GetXaxis()->SetRange(0,70);
hSNR->Draw();
fitsnr->Draw("lsame");
}
示例7: ShowErrorRange
void ShowErrorRange(TGraphErrors* graph)
{
// de = 0
TF1 *fcon = new TF1("fcon","0",0.99,1.01);
fcon->SetLineColor(3);
// fit function
TF1 *fit = graph->GetFunction("facfit");
double fac = fit->GetParameter(0);
double slo = fit->GetParameter(1);
double de = graph->GetErrorY(graph->GetN()/2);
// construct edge functions
TF1 *f2 = new TF1("f2","[1]*(x-[0])",0.99,1.01);
TF1 *f3 = new TF1("f3","[1]*(x-[0])",0.99,1.01);
f2->SetParameters(fac-de/slo,slo);
f3->SetParameters(fac+de/slo,slo);
f2->SetLineStyle(2);
f3->SetLineStyle(2);
double fmin = f2->GetX(0);
double fmax = f3->GetX(0);
TArrow *arr0 = new TArrow(fac ,-0.002,fac ,0);
TArrow *arr1 = new TArrow(fmin,-0.002,fmin,0);
TArrow *arr2 = new TArrow(fmax,-0.002,fmax,0);
arr0->SetArrowSize(0.035);
arr1->SetArrowSize(0.035);
arr2->SetArrowSize(0.035);
arr0->SetLineWidth(2);
arr1->SetLineWidth(2);
arr2->SetLineWidth(2);
graph->Draw();
f2->Draw("same");
f3->Draw("same");
fcon->Draw("same");
arr0->Draw();
arr1->Draw();
arr2->Draw();
}
示例8: draw_smearFit
void plotter::draw_smearFit(TH1D* variation, TF1* fit_, TString file_name){
TH1D* var = (TH1D*) variation->Clone();
TF1* fit = (TF1*) fit_->Clone();
TCanvas *c= new TCanvas("","",600,600);
gPad->SetLeftMargin(0.15);
double ymax = var->GetMaximum() * 1.5;
var->GetYaxis()->SetRangeUser(0., ymax);
var->GetXaxis()->SetTitle("bin content");
var->GetYaxis()->SetTitle("events");
var->GetYaxis()->SetTitleOffset(1.5);
var->GetYaxis()->SetNdivisions(505);
var->SetFillColor(kGray);
var->SetLineColor(kBlack);
var->Draw("HIST");
fit->SetLineColor(kRed);
fit->SetLineWidth(4);
fit->Draw("SAME");
gPad->RedrawAxis();
c->SaveAs(directory + file_name + ".pdf");
delete c;
}
示例9: slits
// This is the main program
void slits() {
float r,ns;
// request user input
cout << "slit width / g ? ";
scanf("%f",&r);
cout << "# of slits? ";
scanf("%f",&ns);
cout <<"interference pattern for "<< ns
<<" slits, width/distance: "<<r<<endl;
// define function and set options
TF1 *Fnslit = new TF1("Fnslit",nslit,-5.001,5.,2);
Fnslit->SetNpx(500);
// set parameters, as read in above
Fnslit->SetParameter(0,r);
Fnslit->SetParameter(1,ns);
// draw the interference pattern for a grid with n slits
Fnslit->Draw();
}
示例10: angle_correlation_daughter_particles
void angle_correlation_daughter_particles(){
TStopwatch timer;
TString inPath ="";// "/home/ikp1/puetz/panda/mysimulations/test/boxgenerator/lambda0/10000_events/";
TFile * inFile = new TFile(inPath + "output_ana.root", "READ");
TTree * lambda0 = (TTree*) inFile->Get("fntpLambda0");
gStyle->SetOptStat(0);
TF1 * f = new TF1("f", "x", -1, 1);
TH2D * h_cos_tht = new TH2D("h_cos_tht", "Correlation for tht of daughters; cos(tht_{d0});cos(tht_{d1})", 1000,-1,1, 1000,-1,1);
lambda0->Project("h_cos_tht", "cos(Lambda0_d1tht):cos(Lambda0_d0tht)", "McTruthMatch==1");
TH1D * h_tht = new TH1D("h_tht", "Correlation for tht of daughters; tht_{d0}-tht_{d1}/rad; counts", 100,-2,2);
lambda0->Project("h_tht", "cos(Lambda0_d1tht)-cos(Lambda0_d0tht)", "McTruthMatch==1 && abs(Lambda0_d1phi-Lambda0_d0phi)<0.002");
TH1D * h_phi = new TH1D("h_phi", "Correlation for phi of daughters; phi_{d0}-phi_{d1}/rad; counts", 100,-0.1,0.1);
lambda0->Project("h_phi", "Lambda0_d1phi-Lambda0_d0phi", "McTruthMatch==1 && abs(Lambda0_d1phi-Lambda0_d0phi)<0.002");
TCanvas * c_cos_tht = new TCanvas("c_cos_tht", "c_cos_tht", 0,0,800,500);
h_cos_tht->Draw("COLZ");
f->Draw("SAME");
TCanvas * c_tht = new TCanvas("c_tht", "c_tht", 0,0,800,500);
h_tht->Draw();
TCanvas * c_phi = new TCanvas("c_phi", "c_phi", 0,0,800,500);
h_phi->Draw();
}
示例11: plotMVALeadVsLeadCharg
void plotMVALeadVsLeadCharg(){
TFile* f_Ztautau = new TFile("../");
f_Ztautau->cd();
TTree* tree_Ztautau = (TTree*) gDirectory->Get("tauFakeRateAnalyzerHPS/tree");
TH2F* h2 = new TH2F("h2","",220,0,1.1,220,0,1.1);
float vxF[45];
float vyF[45];
float ZtautauAll = (float)tree_Ztautau->GetEntries("");
for(int i = 0; i<=44; i++){
float cut = 0.025*i;
float ZtautauCutLeadPi = (float) tree_Ztautau->GetEntries(Form("leadPFCandMva<=%f",-0.1+cut));
float ZtautauCutLeadCh = (float) tree_Ztautau->GetEntries(Form("leadPFChargedHadrMva<=%f",-0.1+cut));
vxF[i]=ZtautauCutLeadCh/ZtautauAll;
vyF[i]=ZtautauCutLeadPi/ZtautauAll;
}
h2->SetXTitle("efficiency of mva<X cut on lead charged");
h2->SetYTitle("efficiency of mva<X cut on lead candidate");
h2->SetAxisRange(0.95,1.02,"X");
h2->SetAxisRange(0.95,1.02,"Y");
h2->Draw();
TVectorF vx(45,vxF);
TVectorF vy(45,vyF);
TGraph* graph = new TGraph(vx,vy);
graph->SetMarkerStyle(kFullCircle);
graph->SetMarkerColor(kRed);
graph->SetMarkerSize(1.0);
graph->Draw("P");
TF1* line = new TF1("line","x",0.9,1.2);
line->Draw("SAME");
}
示例12: langaus
void langaus() {
// Fill Histogram
TFile *f=new TFile("fitInputs.root");
TH1F *hSNR = (TH1F*)f->Get("hxsobs");
// Fitting SNR histo
printf("Fitting...\n");
// Setting fit range and start values
Double_t fr[2];
Double_t sv[4], pllo[4], plhi[4], fp[4], fpe[4];
fr[0]=0.3*hSNR->GetMean();
fr[1]=3.0*hSNR->GetMean();
pllo[0]=0.5; pllo[1]=5.0; pllo[2]=1.0; pllo[3]=0.4;
plhi[0]=5.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=5.0;
sv[0]=1.8; sv[1]=20.0; sv[2]=50000.0; sv[3]=3.0;
Double_t chisqr;
Int_t ndf;
TF1 *fitsnr = langaufit(hSNR,fr,sv,pllo,plhi,fp,fpe,&chisqr,&ndf);
Double_t SNRPeak, SNRFWHM;
langaupro(fp,SNRPeak,SNRFWHM);
printf("Fitting done\nPlotting results...\n");
// Global style settings
gStyle->SetOptStat(1111);
gStyle->SetOptFit(111);
gStyle->SetLabelSize(0.03,"x");
gStyle->SetLabelSize(0.03,"y");
hSNR->GetXaxis()->SetRange(0,70);
hSNR->Draw();
fitsnr->Draw("lsame");
}
示例13: Fit
//______________________________________________________________________________
void Fit(TH1* h, Double_t* outPos, Double_t* outFWHM)
{
// Perform fit.
Char_t tmp[256];
// delete old function
TF1* func = new TF1(tmp, "pol1+gaus(2)");
func->SetLineColor(2);
// estimate peak position
Double_t fPi0Pos = h->GetBinCenter(h->GetMaximumBin());
// configure fitting function
func->SetRange(fPi0Pos - 0.8, fPi0Pos + 0.8);
func->SetLineColor(2);
func->SetParameters( 0.1, 0.1, h->GetMaximum(), 0, 0.1);
Int_t fitres = h->Fit(func, "RB0Q");
// get position and FWHM
fPi0Pos = func->GetParameter(3);
*outPos = fPi0Pos;
*outFWHM = 2.35*func->GetParameter(4);
// indicator line
TLine* line = new TLine();
line->SetX1(fPi0Pos);
line->SetX2(fPi0Pos);
line->SetY1(0);
line->SetY2(h->GetMaximum());
// draw
h->GetXaxis()->SetRangeUser(-3, 3);
h->Draw();
func->Draw("same");
line->Draw("same");
}
示例14: test_mc_rejection_method_lin
void test_mc_rejection_method_lin()
{
const int N = 500000;
const int nbins = 300;
const double ymax = 1.1;
const double xmin = 0;
const double xmax = 10;
const double dx = xmax-xmin;
TRandom rg;
TF1 * func = new TF1 ("func","1/(x+1)",0,10);
TH1D * hgen = new TH1D ("hgen","generated",nbins,xmin,xmax);
for(int i=0; i<N; i++) {
cout << "..................." << i << endl;
bool selected=false;
while(1) {
double xg = xmin + rg.Uniform() * dx;
double yg = ymax * rg.Uniform();
double yc = func->Eval(xg);
selected = (yg<yc);
if(selected) {
hgen->Fill(xg);
break;
}
}
}
double IF = func->Integral(xmin,xmax);
double IH = hgen->Integral("width");
double sc = IF/IH;
hgen->Scale(sc);
hgen->Draw();
func->Draw("same");
}
示例15: doit
//.........这里部分代码省略.........
hh1v2_cut2->Fill(-voltage1[i],-voltage2[i]);
hhSvA_cut2->Fill(tempsum,tempasym);
}
}
// --- make a canvas and draw the histogram
TCanvas *c1 = new TCanvas("c1","",800,800);
// --- rescale the histograms from volts to photoelectrons
h1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
h1->GetXaxis()->SetTitle("Number of photoelectrons");
h1->GetYaxis()->SetTitle("Counts");
// --- define Landau function and draw
// --- don't fit yet because the data have tons of ugly low voltage1 background
double height = 1049;
double mu = 23;
double sigma = 3;
//TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",newmin/peconvert,newmax/peconvert);
TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",2*newmin/peconvert,2*newmax/peconvert);
fun->SetParameter(0,height);
fun->SetParameter(1,mu);
fun->SetParameter(2,sigma);
double bgscale = 650; // guess...
c1->SetLogy(0);
c1->Clear();
hh1v2->Draw("colz");
hh1v2->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2->GetXaxis()->SetTitle("#pe SiPM1");
hh1v2->GetYaxis()->SetTitle("#pe SiPM2");
c1->SetLogz(0);
c1->Print(Form("Cosmics/%s_cosmics_1v2.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_1v2.pdf",basename));
c1->SetLogz(1);
c1->Print(Form("Cosmics/%s_cosmics_1v2_log.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_1v2_log.pdf",basename));
hhSvA->Draw("colz");
hhSvA->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert);
hhSvA->GetXaxis()->SetTitle("Sum");
hhSvA->GetYaxis()->SetTitle("Asymmetry");
c1->SetLogz(0);
c1->Print(Form("Cosmics/%s_cosmics_SvA.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_SvA.pdf",basename));
c1->SetLogz(1);
c1->Print(Form("Cosmics/%s_cosmics_SvA_log.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_SvA_log.pdf",basename));
// --- now for some cuts...
c1->SetLogz(0);
hh1v2_cut1->Draw("colz");
hh1v2_cut1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2_cut1->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2_cut1->GetXaxis()->SetTitle("#pe SiPM1");
hh1v2_cut1->GetYaxis()->SetTitle("#pe SiPM2");
TLatex *tex1 = new TLatex(0.2,0.8,"|Asymmetry|<0.4");