void plot_rms(void) { // // plot sigma of rms distribution. // // #include #include gROOT->Reset(); //TTree *Bfield = (TTree *) gROOT->FindObject("Bfield"); gStyle->SetPalette(1,0); gStyle->SetOptStat(kFALSE); // gStyle->SetOptFit(kTRUE); // gStyle->SetOptFit(1111); gStyle->SetPadRightMargin(0.15); gStyle->SetPadLeftMargin(0.15); gStyle->SetPadBottomMargin(0.15); gStyle->SetFillColor(0); // char string[256]; char filename[80]; Int_t j,jj; #define npts 100; # define nbins 100; // define parameters // define limits Double_t mean=5; Double_t N=npts; Double_t xmin=0; Double_t xmax=1; sprintf (string,"Rms: mean=%f\n",mean); printf ("plot_rms: %s",string); TF1 *rms = new TF1("rms",rms,xmin,xmax,1); rms->SetParameter(0,N); TCanvas *c1 = new TCanvas("c1","c1 Plot rms",200,10,700,400); c1->SetBorderMode(0); c1->SetFillColor(0); c1->SetGridx(); c1->SetGridy(); // c1->SetLogy(); Double_t ymin = 0; Double_t ymax = 7; rms->GetXaxis()->SetRangeUser(xmin,xmax); rms->GetYaxis()->SetRangeUser(ymin,ymax); rms->GetXaxis()->SetTitleSize(0.07); rms->GetYaxis()->SetTitleSize(0.07); rms->GetYaxis()->SetTitleOffset(0.5); rms->GetXaxis()->SetTitle("probability p"); rms->GetYaxis()->SetTitle("root-mean-square (#sigma)"); rms->GetXaxis()->SetNdivisions(5); // rms->SetMarkerColor(1); // rms->SetMarkerStyle(21); rms->SetTitle(""); rms->SetLineColor(2); rms->Draw(""); sprintf(string,"Number of trials= %.0f\n",N); t1 = new TLatex(0.2,0.8,string); t1->SetTextColor(1); t1->SetTextSize(0.07); t1->SetNDC(); t1->Draw(); // sprintf(string,"#sigma = %.1f\n",sigma); t1 = new TLatex(0.2,0.80,string); t1->SetTextColor(1); t1->SetNDC(); // t1->Draw(); TLine *lmean = new TLine(mean,ymin,mean,ymax); // lmean->Draw(); // // TCanvas *c3 = new TCanvas("c3","c3 Plot PDFs",200,10,700,700); // c3->SetBorderMode(0); // c3->SetFillColor(0); //c3->SetGridx(); //c3->SetGridy(); //c3->SetLogy(); TH1F *pdf = new TH1F("pdf","random generation",nbins,xmin,xmax); for (j=0;jGetRandom(); // pdf->Fill(rand); } // pdf->Fit("func","","",xmin,xmax); pdf->SetTitle(""); // pdf->GetXaxis()->SetRangeUser(1.0,2.5); // pdf->GetYaxis()->SetRangeUser(ymin,ymax); pdf->GetXaxis()->SetTitleSize(0.05); pdf->GetYaxis()->SetTitleSize(0.05); pdf->GetYaxis()->SetTitleOffset(1.5); pdf->GetYaxis()->SetTitle("events per bin"); pdf->GetXaxis()->SetTitle("random variable x"); pdf->GetXaxis()->SetNdivisions(505); pdf->SetMarkerColor(2); pdf->SetMarkerStyle(21); // pdf->Draw(); sprintf(string,"Entries = %.0f nbins = %.0f #Delta x = %.1f\n",pdf->GetEntries(),(Float_t )nbins,(xmax-xmin)/nbins); t1 = new TLatex(0.15,0.92,string); t1->SetTextColor(1); t1->SetNDC(); // t1->Draw(); c1->SaveAs("plot_rms_c1.png"); // c3->SaveAs("plot_rms_c3.png"); } Double_t rms(Double_t *x, Double_t *par) { // function to be plotted Double_t N=par[0]; Double_t p=x[0]; char string[256]; Double_t pi=3.14159; Double_t distr = sqrt(N*p*(1-p)); sprintf(string,"N=%f, p=%f, distr=%f\n",N,p,distr); // printf ("rms: %s",string); return distr; }