/*============================================================================*/ void gaus1peakfit(Char_t *s, Float_t x1, Float_t x2, Float_t x3, Float_t x4) { Double_t par[5],epar[5],x[4],y[4]; TH1 *hist; hist = (TH1 *) gROOT->FindObject(s); setcanvas(1); TCanvas *c1=(TCanvas*) gROOT->FindObject("c1"); if(c1==NULL)setcanvas(1); c1->Clear(); hist->SetAxisRange(x1-30,x4+30); hist->Draw(); //--**-- Linear background estimation --**--// x[0] = x1; x[1] = x2; x[2] = x3; x[3] = x4; Int_t bin1 = hist->FindBin(x1); y[0] = hist->GetBinContent(bin1); Int_t bin2 = hist->FindBin(x2); y[1] = hist->GetBinContent(bin2); Int_t bin3 = hist->FindBin(x3); y[2] = hist->GetBinContent(bin3); Int_t bin4 = hist->FindBin(x4); y[3] = hist->GetBinContent(bin4); TGraph *g = new TGraph(4,x,y); TF1 *fpol1 = new TF1("POL1","pol1",x1,x4); g->Fit(fpol1,"RQN"); par[3]=fpol1->GetParameter(0); par[4]=fpol1->GetParameter(1); //--**-- Gaussian Peak estimation without background --**--// TF1 *fgaus = new TF1("GAUS","gaus",x2,x3); hist->Fit(fgaus,"RQN"); fgaus->GetParameters(&par[0]); //--**-- Final Peak Fit with Background --**--// TF1 *func = new TF1("FGAUS","gaus(0)+pol1(3)",x1,x4); func->SetParameters(par); hist->Fit(func,"R+QN"); func->GetParameters(par); epar[0]=func->GetParError(0); epar[1]=func->GetParError(1); epar[2]=func->GetParError(2); Double_t fwhm = par[2]*TMath::Sqrt(8*TMath::Log(2)); Double_t efwhm = epar[2]*TMath::Sqrt(8*TMath::Log(2)); Double_t N0 = par[0]*(TMath::Sqrt(TMath::TwoPi())*par[2]); Double_t r0 = epar[0]/par[0]; Double_t r2 = epar[2]/par[2]; Double_t eN0= N0*TMath::Sqrt(r0*r0+r2*r2); printf("Peak = %f +- %f; FFHM = %f +- %f; Area = %f +- %f\n", par[1],epar[1],fwhm,efwhm,N0,eN0); //printf("%11.4f %11.4f %11.0f %11.0f\n", // par[1],epar[1],N0,eN0); func->SetLineWidth(0.5); func->SetLineStyle(1); func->SetLineColor(4); func->SetFillColor(4); func->Draw("same"); }
//________________________________________________________ void GFHistManager::ColourFuncs(GFHistArray *hists) const { // adjust colour of funcs to match hist, but only if exactly one function per hist if (!hists) return; for (Int_t iH = 0; iH < hists->GetEntriesFast(); ++iH) { TH1 *h = hists->At(iH); if (!h) continue; // look for _the_ TF1 (not > 1!) TF1 *func = NULL; TIter nextprim(h->GetListOfFunctions()); while (TObject* next = nextprim()) { if (next->InheritsFrom(TF1::Class())) { if (func) { // there is already a TF1, so... func = NULL; // remove it again... break; // ...and stop searching for more! } else { func = static_cast<TF1*>(next); } } } // if exactly 1 found, adjust line style/colour if (func) { func->SetLineColor(h->GetLineColor()); func->SetLineStyle(h->GetLineStyle()); } } }
void Draw_vn( TH1D * h_vn_pt, TString MBorDtrig = "MBtrig", TString EPorSP = "EP", TString vnname = "v2", TString Ytitle = "v_{2}", int cent_low = 0, int cent_high = 100, double ptlow = 1.0, double pthigh = 35.0, TString fitoption = "poly3bkg") { TCanvas * cfg_vn = new TCanvas(Form("cfg_%s_%s", MBorDtrig.Data(), vnname.Data())); h_vn_pt->GetXaxis()->SetRangeUser(ptlow+0.05, pthigh-0.05); h_vn_pt->GetYaxis()->SetRangeUser(-0.2, 0.4); h_vn_pt->GetXaxis()->SetTitle("D^{0} p_{T} (GeV/c)"); h_vn_pt->GetYaxis()->SetTitle(Ytitle); h_vn_pt->GetYaxis()->SetTitleSize(0.05); h_vn_pt->GetXaxis()->SetTitleSize(0.05); if( EPorSP == "EP" ) { h_vn_pt->SetMarkerColor(6.0); h_vn_pt->SetLineColor(6.0); h_vn_pt->SetMarkerStyle(22); h_vn_pt->SetMarkerSize(1.0); } else if( EPorSP == "SP" ) { h_vn_pt->SetMarkerColor(4.0); h_vn_pt->SetLineColor(4.0); h_vn_pt->SetMarkerStyle(21); h_vn_pt->SetMarkerSize(1.3); } h_vn_pt->Draw(); TLatex Tl; Tl.SetNDC(); Tl.SetTextAlign(12); Tl.SetTextSize(0.05); Tl.SetTextFont(42); Tl.DrawLatex(0.125,0.965, "#font[61]{CMS} #scale[0.8]{Preliminary}"); Tl.DrawLatex(0.57,0.965, "#scale[0.8]{PbPb #sqrt{s_{NN}} = 5.02 TeV}"); TLatex* tex; tex = new TLatex(0.20,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.20,0.78,Form("Cent. %d-%d%%", cent_low, cent_high)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); TF1 * fun = new TF1("fun", "0.0", 0, 100); fun->SetLineColor(1.0); fun->SetLineStyle(3); fun->SetLineWidth(1); fun->Draw("same"); cfg_vn->SaveAs(Form("Plots_vn/cfg_vnvsmass_%s_%s_cent%dto%d_%s.pdf", MBorDtrig.Data(), vnname.Data(), cent_low, cent_high, fitoption.Data())); }
void CreateDrawAndSaveHistogramBreitWignerFit(TH1* &histo, TString outputdir, TString outputname, bool saveoutput, bool close, double range=1){ setPandaStyle(); TString name = TString(histo->GetName()); TString title = TString(histo->GetTitle()); TCanvas * canvas = new TCanvas("c_"+name, title, 0,0,1500,1000); histo->Draw(); // canvas->Update(); TF1 * bw; bw = GetVoigtFit(histo, range); bw->SetLineColor(kRed); bw->SetLineStyle(7); bw->SetLineWidth(3); bw->Draw("SAME"); PandaSmartLabel("L"); if (saveoutput){ canvas->Print(outputdir + "root-files/" + outputname + ".root"); canvas->Print(outputdir + "png-files/" + outputname + ".png"); canvas->Print(outputdir + "pdf-files/" + outputname + ".pdf"); } if (close) canvas->Close(); }
void solveNumerically() { Double_t n0=1.35; Double_t m=-1*(1.78-1.35)/140; Double_t z0=-100; Double_t dMax=n0+m*z0; TCanvas *can = new TCanvas("can","can",600,400); // TF1 *lefty = new TF1("lefty",strangeLeft,0,dMax,5); // lefty->SetParameters(n0,m,z0,40,-30); // lefty->SetLineColor(8); // lefty->SetLineStyle(1); // lefty->SetNpx(1000); // lefty->Draw(""); // TF1 *righty = new TF1("righty",strangeRight,0,dMax,5); // righty->SetParameters(n0,m,z0,40,-30); // righty->SetLineColor(kViolet); // righty->SetLineStyle(1); // righty->SetNpx(1000); // righty->Draw("same"); TH1F*framey = can->DrawFrame(0,-50,dMax*1.1,0); TF1 *endy = new TF1("endy",strangeZ,0.02,dMax,4); endy->SetParameters(n0,m,z0,200); endy->SetLineColor(kViolet); endy->SetLineStyle(1); endy->SetNpx(1000); endy->Draw("same"); }
void problem_1() { //Declare variable for energy Float_t energy; //declare a histogram for the energy TH1D *energy_hist = new TH1D("Energy","Energy",50,100,160); //declare the canvas to display hist TCanvas *c1 = new TCanvas("c1","c1",10,10,900,900); TF1 *fitFcn = new TF1("fitFcn",fitFunction,90,180,6); //get the input file TFile *inputFile = new TFile("data.root"); //get the correct tree from the input file //depending on the tree name change "data" TTree *data_tree = (TTree*)inputFile->Get("data"); //Get the branch named E1 and put it into the varialbe energy data_tree->SetBranchAddress("E", &energy); //Get the number of events for the for loop int count = data_tree->GetEntries(); for (int i = 0; i < count; i++) { //get the current event i data_tree->GetEntry(i); //Fill the histogram energy_hist->Fill(energy); } //label the axis and draw the histogram after it's filled energy_hist->GetXaxis()->SetTitle("E (GeV)"); energy_hist->Draw(); // first try without starting values for the parameters // this defaults to 1 for each param. energy_hist->Fit("fitFcn"); // this results in an ok fit for the polynomial function however // the non-linear part (Lorentzian) does not respond well // second try: set start values for some parameters fitFcn->SetParameter(4,1.66); // width fitFcn->SetParameter(5,126.5); // peak energy_hist->Fit("fitFcn"); // improve the picture: TF1 *backFcn = new TF1("backFcn",background,100,160,3); backFcn->SetLineColor(1); backFcn->SetLineStyle(3); TF1 *signalFcn = new TF1("signalFcn",gaussian,100,160,3); signalFcn->SetLineColor(4); Double_t par[6]; // writes the fit results into the par array fitFcn->GetParameters(par); backFcn->SetParameters(par); backFcn->Draw("same"); signalFcn->SetParameters(&par[4]); signalFcn->Draw("same"); gStyle->SetOptFit(1111); }
TF1 * getDoubleFit(TH1 * hist, bool autorange, double inner, double outer, int which=1){ /** * @brief performes a double gaussian Fit */ Double_t parameters[6] = {0,0,0,0,0,0}; Double_t parameters_new[6] = {0,0,0,0,0,0}; double center = hist->GetMean(); if (autorange){ double inner = fabs(center - hist->GetXaxis()->GetXmax()) /10; double outer = fabs(center - hist->GetXaxis()->GetXmax()) /10*8; } TF1 * fit1 = new TF1("fit1", "gaus", center-inner, center+inner ); hist->Fit(fit1, "Q0R"); fit1->GetParameters(¶meters[0]); TF1 * fit2 = new TF1("fit2", "gaus", center-outer, center+outer ); hist->Fit(fit2, "Q0R"); fit2->GetParameters(¶meters[3]); TF1 * fitproper = new TF1("fitproper", "gaus(0)+gaus(3)", center-outer, center+outer); fitproper->SetParameters(parameters); fitproper->SetParName(0, "Const.(inner)"); fitproper->SetParName(1, "Mean (inner)"); fitproper->SetParName(2, "Sigma (inner)"); fitproper->SetParName(3, "Const.(outer)"); fitproper->SetParName(4, "Mean (outer)"); fitproper->SetParName(5, "Sigma (outer)"); hist->Fit(fitproper, "Q0R"); fitproper->GetParameters(¶meters_new[0]); fitproper->SetLineColor(hist->GetLineColor()); fitproper->SetLineWidth(hist->GetLineWidth()); fitproper->SetLineStyle(2); if (which==1){ TF1 * Gausinner = new TF1("Gausinner", "gaus(0)", center-inner, center+inner); Gausinner->SetParameters(parameters_new); return Gausinner; } else{ TF1 * Gausouter = new TF1("Gausouter", "gaus(3)", center-outer, center+outer); Gausouter->SetParameters(parameters_new); return Gausouter; } }
void Draw_vn(TH1D * vn_cent0to10, TH1D * vn_cent10to30, TH1D * vn_cent30to50, TH1D * vn_cent50to70, TString vnname = "v2_SP", TString Ytitle = "v_{2}{SP}") { TCanvas * cfg_vn_centrality = new TCanvas(Form("cfg_%s_centrality", vnname.Data()), Form("cfg_%s_centrality", vnname.Data())); vn_cent10to30->SetLineColor(4.0); vn_cent10to30->SetMarkerColor(4.0); vn_cent30to50->SetLineColor(2.0); vn_cent30to50->SetMarkerColor(2.0); vn_cent50to70->SetLineColor(8.0); vn_cent50to70->SetMarkerColor(8.0); vn_cent0to10->GetYaxis()->SetTitle(Ytitle); vn_cent0to10->Draw(); vn_cent10to30->Draw("same"); vn_cent30to50->Draw("same"); vn_cent50to70->Draw("same"); TF1 * fun = new TF1("fun", "0.0", 0, 100); fun->SetLineColor(1.0); fun->SetLineStyle(3); fun->SetLineWidth(1); fun->Draw("same"); TLegend * leg = new TLegend(0.45, 0.67, 0.65, 0.90); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->AddEntry( vn_cent0to10, "Cent. 0-10%"); leg->AddEntry( vn_cent10to30, "Cent. 10-30%"); leg->AddEntry( vn_cent30to50, "Cent. 30-50%"); leg->AddEntry( vn_cent50to70, "Cent. 50-70%"); leg->Draw(); TLatex Tl; Tl.SetNDC(); Tl.SetTextAlign(12); Tl.SetTextSize(0.05); Tl.SetTextFont(42); Tl.DrawLatex(0.125,0.965, "#font[61]{CMS} #scale[0.8]{Preliminary}"); Tl.DrawLatex(0.57,0.965, "#scale[0.8]{PbPb #sqrt{s_{NN}} = 5.02 TeV}"); TLatex* tex; tex = new TLatex(0.20,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); cfg_vn_centrality->SaveAs(Form("Plots_vn/cfg_%s_centrality.pdf", vnname.Data())); }
TF1* plotmax(TString tagger, TString TaggerStrength, float Etamin, float Etamax, TString opt = "" , int col = 1, float lineWidth = 1, int lineStyle = 1) { TF1* f = GetMistagmax(tagger,TaggerStrength,Etamin,Etamax); if( f != NULL ) { f->SetLineColor(col); f->SetLineWidth(lineWidth); f->SetLineStyle(lineStyle); f->Draw(opt); } //else cout << "NULL pointer returned... Function seems not to exist" << endl; return f; }
void BichselP() {// dE/dx versus momentum #if 1 if (!m_Bichsel || gClassTable->GetID("StBichsel") < 0) { gSystem->Load("libStar"); gSystem->Load("St_base"); gSystem->Load("StarClassLibrary"); gSystem->Load("StBichsel"); m_Bichsel = Bichsel::Instance(); } #endif TLegend *leg = new TLegend(0.7,0.4,0.9,0.9,"");//TLegend(0.79,0.91,0.89,0.89,""); Char_t *names[8] = { "pi", "e", "p", "mu", "K", "d", "t", "He3"}; Char_t *Names[8] = { "#pi", "e", "p", "#mu", "K", "d", "t", "He3"}; Double_t masses[8] = {0.13956995,0.51099907e-3,0.93827231,0.1056584,0.493677,0.1876E+01,0.2809E+01,0.2809E+01}; for (int l = 0; l < 5; l++) { TF1 *fbi = new TF1(Form("bi%s",names[l]),bichselZ,0.05,100.0,2); fbi->SetParameter(0,masses[l]); fbi->SetParameter(1,0); fbi->SetLineColor(l+1); fbi->SetLineStyle(1); leg->AddEntry(fbi,Names[l],"L"); fbi->Draw("same"); TF1 *fb70 = new TF1(Form("b70%s",names[l]),bichsel70,0.05,100.0,2); fb70->SetParameter(0,masses[l]); fb70->SetParameter(1,0); fb70->SetLineColor(l+1); fb70->SetLineStyle(2); leg->AddEntry(fb70,Form("%s I70",Names[l]),"L"); fb70->Draw("same"); TF1 *fsir = new TF1(Form("sir%s",names[l]),sifunc,0.05,100.0,2); fsir->SetParameter(0,masses[l]); fsir->SetParameter(1,0); fsir->SetLineColor(l+1); fsir->SetLineStyle(3); leg->AddEntry(fsir,Form("%s Sirrf",Names[l]),"L"); fsir->Draw("same"); } leg->Draw(); }
void Draw_vn_ratio( TH1D * vn_default, TH1D * vn_poly3bkg_floatwidth, TString vnname, TString method, TString MBorDtrig, int cent_low, int cent_high, float ptlow, float pthigh) { TCanvas * cfg_vn_floatwidth = new TCanvas(Form("cfg_vn_floatwidth_%s_cent%dto%d", (vnname+"_"+method+"_"+MBorDtrig).Data(), cent_low, cent_high), Form("cfg_vn_floatwidth_%s_cent%dto%d", (vnname+"_"+method+"_"+MBorDtrig).Data(), cent_low, cent_high), 400, 600); TPad *pad1 = new TPad("pad1","top pad",0.0,0.4,1.0,1.0); pad1->SetBottomMargin(0.01); pad1->Draw(); TPad *pad2 = new TPad("pad2","bottom pad",0.0,0.0,1.0,0.4); pad2->SetTopMargin(0.0); pad2->Draw(); pad1->cd(); vn_default->Draw(); vn_poly3bkg_floatwidth->SetMarkerColor(4); vn_poly3bkg_floatwidth->SetLineColor(4); vn_poly3bkg_floatwidth->Draw("same"); TF1 * fun = new TF1("fun", "0.0", 0, 100); fun->SetLineColor(1.0); fun->SetLineStyle(3); fun->SetLineWidth(1); fun->Draw("same"); TLegend * leg = new TLegend(0.45, 0.70, 0.65, 0.90); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->AddEntry( (TObject*)0, Form("Cent. %d-%d%%", cent_low, cent_high) , ""); leg->AddEntry( vn_default, "Default"); leg->AddEntry( vn_poly3bkg_floatwidth, "Float width"); leg->Draw(); pad2->cd(); TH1D * h_vn_ratio_poly3bkg_floatwidth_default = (TH1D *) vn_poly3bkg_floatwidth->Clone("h_vn_ratio_poly3bkg_floatwidth_default"); h_vn_ratio_poly3bkg_floatwidth_default->Divide( vn_poly3bkg_floatwidth, vn_default, 1.0, 1.0, "B"); h_vn_ratio_poly3bkg_floatwidth_default->GetYaxis()->SetRangeUser(0.7,1.3); h_vn_ratio_poly3bkg_floatwidth_default->GetYaxis()->SetTitle("*/Default"); h_vn_ratio_poly3bkg_floatwidth_default->Draw(); TF1 * fun1 = new TF1("fun1", "1.0", 0, 100); fun1->SetLineColor(1.0); fun1->SetLineStyle(3); fun1->SetLineWidth(1); fun1->Draw("same"); cfg_vn_floatwidth->SaveAs(Form("Plots_vn/plots_PDFvariation/cfg_vn_floatwidth_%s_cent%dto%d.pdf", (vnname+"_"+method+"_"+MBorDtrig).Data(), cent_low, cent_high)); }
void fitmmp(TH1 *hmmp, bool verbose = false) { TString options; if (verbose) options = ""; else options = "Q"; TF1 *fbg = f_pol4("fbg",0.4,2,true); hmmp->Fit(fbg,options.Data(),"",0.42,2); //printf("%s\n",gMinuit->fCstatu.Data()); if (true) { //gMinuit->fCstatu.Contains("CONVER")) { TF1 *fbg2 = f_pol4("fbg",0.4,2,false); fbg2->SetParameters(fbg->GetParameters()); //fbg2->Draw("same"); fbg2->SetParameter(5,0); fbg2->SetParameter(6,0); TH1 *htmp = (TH1*)hmmp->Clone("hmmp_bgsub"); htmp->Add(fbg2,-1); //htmp->Draw(); TF1 *fgaus = new TF1("fgaus","gaus",0.4,2); htmp->Fit(fgaus,options.Data(),"",0.74,0.85); TF1 *f = f_pol4gaus("f",0.4,2,fbg2,fgaus); f->SetNpx(500); hmmp->Fit(f,options.Data(),"",0.42,2); fgaus->SetRange(0.4,2); for (int i = 0; i < 3; i++) fgaus->SetParameter(i,f->GetParameter(i+5)); for (int i = 0; i < 5; i++) fbg2->SetParameter(i,f->GetParameter(i)); fbg2->SetLineStyle(2); fbg2->SetLineColor(kRed+1); fgaus->SetLineStyle(2); fgaus->SetLineColor(kGreen+1); hmmp->GetListOfFunctions()->Add(fbg2->Clone()); hmmp->GetListOfFunctions()->Add(fgaus->Clone()); delete fbg2; delete htmp; delete fgaus; delete f; } else hmmp->GetListOfFunctions()->Delete(); delete fbg; }
void drawSupport(){ #ifdef __CINT__ gROOT->LoadMacro("AtlasUtils.C"); #endif SetAtlasStyle(); char name[200]; //sprintf(name,"Mydecorr_0_Calib1.root"); sprintf(name,"Mydecorr_0_Calib1_1.root"); //sprintf(name,"support.root"); fin = TFile::Open(name); sprintf(name, "hcentrality"); TH1* hcent = (TH1D*)fin->Get(name); sprintf(name, "hntrk_Fcal_%d",0); hntrk_Fcal[0] = (TH2*)fin->Get(name); hntrk_Fcal[0]->Rebin2D(5,5); sprintf(name, "hntrk_Fcal_%d",1); hntrk_Fcal[1] = (TH2*)fin->Get(name); sprintf(name, "hFCalAC"); TH2* hFCalAC = (TH2*)fin->Get(name); TF1 *fa = new TF1("fa","[0] + [1]*x",0,7); double par2[] = {-1300,1125}; fa->SetLineColor(kRed); fa->SetParameters(par2); fa->SetLineWidth(2); fa->SetLineStyle(2); TF1 *fa2 = new TF1("fa2","[0] + [1]*x",0,7); double par[] = {4.1,-1}; fa2->SetLineColor(kRed); fa2->SetParameters(par); fa2->SetLineWidth(2); fa2->SetLineStyle(2); for (int ic=0; ic<NCENT; ic++) { sprintf(name,"hntrkloose_ic%d", ic); hntrkloose[ic] =(TH1D*)fin->Get(name); cout<<name<< " "<<hntrkloose[ic]->GetBinContent(3325)<< endl; sprintf(name,"hntrktight_ic%d", ic); hntrktight[ic] =(TH1D*)fin->Get(name); } for (int ic=0; ic<20; ic++) { sprintf(name,"hntrkcut_ic%d", ic); hntrkcut[ic] =(TH1D*)fin->Get(name); } sprintf(name,"sfcalAC"); can = SetCan2(name, 2,2); hFCalAC->Draw("colz"); hFCalAC->GetXaxis()->SetTitle("#Sigma E_{T}^{FCal A side} [TeV]"); hFCalAC->GetYaxis()->SetTitle("#Sigma E_{T}^{FCal C side} [TeV]"); hFCalAC->Rebin2D(10,10); hFCalAC->GetXaxis()->SetRangeUser(0,3.5); hFCalAC->GetYaxis()->SetRangeUser(0,3.5); gPad->SetLogz(); fa2->Draw("same"); sprintf(name,"%s.pdf", can->GetName()); can->SaveAs(name); sprintf(name,"sfcal"); can = SetCan2(name, 2,2); hntrk_Fcal[0]->Draw("colz"); hntrk_Fcal[0]->GetXaxis()->SetTitle("#Sigma E_{T}^{FCal} [TeV]"); hntrk_Fcal[0]->GetYaxis()->SetTitle("N_{track}^{Loose} [p_{T}>0.5GeV]"); gPad->SetLogz(); fa->Draw("same"); sprintf(name,"%s.pdf", can->GetName()); can->SaveAs(name); sprintf(name,"sCentrality"); can = SetCan2(name, 2,2); hcent->Draw(); hcent->GetXaxis()->SetTitle("Centrality %"); hcent->GetYaxis()->SetTitle("Nevents"); sprintf(name,"%s.pdf", can->GetName()); can->SaveAs(name); int Nx=5, Ny=4; sprintf(name,"sntrkLoose"); can = SetCan2D2(name,Nx, Ny); for (int ix=0; ix<Nx; ix++) { for (int iy=0; iy<Ny; iy++) { int ic = ix + iy*Nx; can->cd(ic+1); if(ic>=NCENT) continue; hntrkloose[ic] ->Rebin(10); hntrkloose[ic] ->DrawClone(); gPad->SetLogy(); gPad->Update(); } } sprintf(name,"%s.pdf", can->GetName()); can->SaveAs(name); sprintf(name,"%s.root", can->GetName()); can->SaveAs(name); sprintf(name,"sntrkCut"); can = SetCan2D2(name,Nx, Ny); for (int ix=0; ix<Nx; ix++) { for (int iy=0; iy<Ny; iy++) { int ic = ix + iy*Nx; can->cd(ic+1); hntrkcut[ic] ->Rebin(10); hntrkcut[ic] ->Draw(); gPad->SetLogy(); } } sprintf(name,"%s.pdf", can->GetName()); can->SaveAs(name); sprintf(name,"%s.root", can->GetName()); can->SaveAs(name); }
void fitMKVoight(TH1 *h33 , Double_t low, Double_t high, Double_t p0, Double_t p1, Double_t p2, Double_t p3, Double_t initialPar, Double_t width, Double_t Gamma, Double_t factor, Int_t draw_opt){ //double nEnt = h33->GetEntries(); double nEnt = h33->GetMaximum(); double in_par[8] = {100, initialPar, width , Gamma, p0, p1, p2}; //{A,mean,sigma,Gamma} TF1 *fitter = new TF1("fitter",myFuncBWG,low,high,8); fitter->SetParameters(&in_par[0]); fitter->SetParLimits(0,10,nEnt); fitter->SetParLimits(1,initialPar-width,initialPar+width); fitter->SetLineColor(kBlue); h33->Fit("fitter","REM+","same"); //h33->Draw("E"); TF1 *backFcn = new TF1("backFcn", "pol2",low,high); TF1 *signalFcn = new TF1("signalFcn", myVoight,low,high,4); signalFcn->SetLineColor(kBlue); signalFcn->SetLineWidth(2); Double_t par[8]; fitter->GetParameters(par); backFcn->SetParameters(&par[4]); backFcn->SetLineStyle(2); backFcn->SetLineColor(6); backFcn->SetLineWidth(1); signalFcn->SetParameters(par); signalFcn->SetLineStyle(2); signalFcn->SetLineColor(4); signalFcn->SetLineWidth(1); // backFcn->Draw("same"); //signalFcn->Draw("same"); //Double_t Intg = abs(signalFcn->Integral(par[1]-factor*par[2],par[1]+factor*par[2])); ROOT::Math::GSLIntegrator ig(1.E-6,1.E-6,1000); ROOT::Math::WrappedTF1 wf(*fitter); ig.SetFunction(wf); double Intg = ig.Integral(par[1]-factor*par[2],par[1]+factor*par[2]); Double_t Intb = abs(backFcn->Integral(par[1]-factor*par[2],par[1]+factor*par[2])); Double_t binw = h33->GetBinWidth(1); Int_t yield = Intg/binw; Int_t bckgd = Intb/binw; //Double_t ratio = double(yield)/TMath::Sqrt(double(bckgd)); Double_t ratio = double(yield)/double(yield+bckgd); cout << yield << "\t" << ratio << endl; TAxis *x=h33->GetXaxis(); TAxis *y=h33->GetYaxis(); Double_t startx=x->GetXmin()+0.45*(x->GetXmax()-x->GetXmin()); /* Double_t starty0=0.5*h33->GetMaximum(); Double_t starty1=0.56*h33->GetMaximum(); Double_t starty2=0.62*h33->GetMaximum(); Double_t starty3=0.68*h33->GetMaximum(); Double_t starty4=0.74*h33->GetMaximum(); Double_t starty5=0.8*h33->GetMaximum(); */ Double_t starty0=0.35*h33->GetMaximum(); Double_t starty1=0.43*h33->GetMaximum(); Double_t starty2=0.49*h33->GetMaximum(); Double_t starty3=0.56*h33->GetMaximum(); Double_t starty4=0.63*h33->GetMaximum(); Double_t starty5=0.7*h33->GetMaximum(); double meanError = fitter->GetParError(1); double sigmaError = fitter->GetParError(2); if (draw_opt ==1) { TLatex *sum = new TLatex(startx*0.93, starty5,Form("Yield: %i",yield)); TLatex *sum12 = new TLatex(startx*0.93, starty4,Form("Background: %i",bckgd)); TLatex *sum0=new TLatex(startx*0.93, starty3,Form("Range: #pm %2.1f #sigma",factor)); TLatex *sum2=new TLatex(startx*0.93, starty2,Form("Mean: %4.4f #pm %.4f GeV",par[1], meanError)); TLatex *sum3=new TLatex(startx*0.93, starty1,Form("#sigma: %5.4f #pm %.4f GeV",par[2], sigmaError)); //TLatex *ra = new TLatex(startx*0.93, starty0,Form("#frac{S}{#sqrt{B}}= %.1f", ratio)); TLatex *ra = new TLatex(startx*0.93, starty0,Form("#frac{S}{S+B} = %1.4f", ratio)); sum->SetTextSize(0.04); sum->SetTextColor(kBlue);//2 sum->Draw("same"); sum12->SetTextSize(0.04); sum12->SetTextColor(kBlue);//6 sum12->Draw("same"); ra->SetTextSize(0.04); ra->SetTextColor(kBlue);//was black before; ra->Draw("same"); sum0->SetTextSize(0.04); sum0->SetTextColor(kBlue);//2 sum0->Draw("same"); sum2->SetTextSize(0.04); sum2->SetTextColor(kBlue);//4 sum2->Draw("same"); sum3->SetTextSize(0.04); sum3->SetTextColor(kBlue);//4 sum3->Draw("same"); } }
// Function for the computation of channeling efficiency at various incoming angle Int_t AnalyseChannelingEfficiency(TTree *fTree,Float_t fChannelingMinimum = 35., Float_t fChannelingMaximum = 70.){ //**//Channeling Gaussian Fit Function TF1 *vChanneling = new TF1("vChanneling","gaus",fChannelingMinimum,fChannelingMaximum); vChanneling->SetParNames("Const","Mean","Sigma"); vChanneling->SetLineColor(4); vChanneling->SetLineStyle(2); TH2D *hChannelingPlot = new TH2D("hChannelingPlot","Deflection Angle vs. Incoming Angle;Horizontal Incoming Angle [#murad];Horizontal Deflection Angle [#murad]",21,-10.5,10.5,256,-127.5,128.5); TH1F *hChannelingEfficiency = new TH1F("hChannelingEfficiency","G4Channeling;Horizontal Incoming Angle [#murad];Efficiency [%]",21,-10.5,10.5); fTree->Draw("-(angXout-angXin):-angXin>>hChannelingPlot"); Double_t vNormalizationToAmorphous = 0.965; // Normalization for channeling efficiency, see PRSTAB 11, 063501 (2008) for(int i=2;i<=21;i++){ TH1D* h1 = hChannelingPlot->ProjectionY("h1",i,i); h1->Fit(vChanneling,"QR"); Double_t *vChannelingParameters; vChannelingParameters = vChanneling->GetParameters(); hChannelingEfficiency->SetBinContent(i,ComputeEfficiency(h1,vChannelingParameters)/vNormalizationToAmorphous); h1->Delete(); } hChannelingEfficiency->SetLineColor(3); hChannelingEfficiency->SetLineStyle(4); hChannelingEfficiency->SetMarkerColor(3); hChannelingEfficiency->SetFillStyle(0); hChannelingEfficiency->SetMarkerStyle(20); hChannelingEfficiency->Draw("PL"); TGraph* gRoughExperimentalData = new TGraph(11); gRoughExperimentalData->SetPoint( 0 , -10 , 20 ); gRoughExperimentalData->SetPoint( 1 , -8 , 38 ); gRoughExperimentalData->SetPoint( 2 , -6 , 56 ); gRoughExperimentalData->SetPoint( 3 , -4 , 72 ); gRoughExperimentalData->SetPoint( 4 , -2 , 80 ); gRoughExperimentalData->SetPoint( 5 , 0 , 84 ); gRoughExperimentalData->SetPoint( 6 , 2 , 82 ); gRoughExperimentalData->SetPoint( 7 , 4 , 78 ); gRoughExperimentalData->SetPoint( 8 , 6 , 66 ); gRoughExperimentalData->SetPoint( 9 , 8 , 52 ); gRoughExperimentalData->SetPoint( 10 , 10 , 37 ); gRoughExperimentalData->SetLineColor(4); gRoughExperimentalData->SetLineStyle(3); gRoughExperimentalData->SetFillStyle(0); gRoughExperimentalData->SetFillColor(0); gRoughExperimentalData->SetMarkerColor(4); gRoughExperimentalData->SetMarkerStyle(21); gRoughExperimentalData->SetTitle("Phys. Lett. B 680, 129"); gRoughExperimentalData->Draw("sameCP"); TLegend *aLegend = new TLegend(0.30,0.15,0.55,0.3); aLegend->AddEntry(hChannelingEfficiency); aLegend->AddEntry(gRoughExperimentalData); aLegend->SetFillStyle(0); aLegend->SetLineColor(0); aLegend->Draw(); return 0; }
TF1* fitMass(TH1D* hData, TH1D* hMCSignal, TH1D* hMCSwapped) { Double_t setparam0=100.; Double_t setparam1=1.865; Double_t setparam2=0.03; Double_t setparam10=0.005; Double_t setparam8=0.1; Double_t setparam9=0.1; Double_t fixparam1=1.865; Double_t minhisto=1.7; Double_t maxhisto=2.0; TF1* f = new TF1("fMass","[0]*([7]*([9]*Gaus(x,[1],[2]*(1+[11]))/(sqrt(2*3.1415927)*[2]*(1+[11]))+(1-[9])*Gaus(x,[1],[10]*(1+[11]))/(sqrt(2*3.1415927)*[10]*(1+[11])))+(1-[7])*Gaus(x,[1],[8]*(1+[11]))/(sqrt(2*3.1415927)*[8]*(1+[11])))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.005,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); f->FixParameter(11,0); hMCSignal->Fit("fMass","q","",minhisto,maxhisto); hMCSignal->Fit("fMass","q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit("fMass","L q","",minhisto,maxhisto); hMCSignal->Fit("fMass","L q","",minhisto,maxhisto); hMCSignal->Fit("fMass","L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); hData->Fit("fMass","q","",minhisto,maxhisto); hData->Fit("fMass","q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,1.86,1.87); f->ReleaseParameter(11); f->SetParLimits(11,-0.2,0.2); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L m","",minhisto,maxhisto); TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1("fSignal","[0]*([3]*([4]*Gaus(x,[1],[2]*(1+[6]))/(sqrt(2*3.1415927)*[2]*(1+[6]))+(1-[4])*Gaus(x,[1],[5]*(1+[6]))/(sqrt(2*3.1415927)*[5]*(1+[6]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(11)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1("fBackground","[0]*(1-[2])*Gaus(x,[1],[3]*(1+[4]))/(sqrt(2*3.1415927)*[3]*(1+[4]))"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8),f->GetParameter(11)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); hData->SetXTitle("m_{#piK} (GeV/c^{2})"); hData->SetYTitle("Entries / (5 MeV/c^{2})"); hData->SetAxisRange(0,hData->GetBinContent(hData->GetMaximumBin())*1.4*1.2,"Y"); hData->SetMarkerSize(0.3); hData->Draw("e"); cout<<"hData->GetMaximum(): "<<hData->GetMaximum()<<endl; background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/hData->GetBinWidth(1); Double_t yieldErr = mass->Integral(minhisto,maxhisto)/hData->GetBinWidth(1)*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"integral function yield: "<<yield<<" fit yield: "<<f->GetParameter(0)*f->GetParameter(7)/hData->GetBinWidth(1)<<" +- "<<f->GetParError(0)*f->GetParameter(7)/hData->GetBinWidth(1)<<std::endl; TLegend* leg = new TLegend(0.65,0.5,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.06); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(hData,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); hData->GetFunction("fMass")->Delete(); TH1D* hDataNoFitFun = (TH1D*) hData->Clone("hDataNoFitFun"); hDataNoFitFun->Draw("esame"); return f; }
//TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, float NPpar[]) TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, TString npfit) { TString tMC; if(isMC==1) tMC="MC"; else tMC="Data"; TCanvas* c = new TCanvas(Form("c_%s_%.0f",tMC.Data(),ibin),"",600,600); TFile* infile = new TFile(Form("%s_%s_%s_%s_%.0f.root",infname.Data(),collisionsystem.Data(),varname.Data(),tMC.Data(),ibin)); TH1D* h = (TH1D*)infile->Get("h"); h->SetName(Form("h_%s_%.0f",tMC.Data(),ibin)); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); hMCSignal->SetName(Form("hMCSignal_%s_%.0f",tMC.Data(),ibin)); //TString iNP=Form("TMath::Erf((x-%f)/%f)+1", NPpar[0], NPpar[1]); TString iNP = npfit; TF1* f = new TF1(Form("f_%s_%.0f",tMC.Data(),ibin),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*("+iNP+")"); f->SetParLimits(3,0,1e5); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(5,0,1000); if(isMC) { f->SetParLimits(3,0,1e2); f->SetParLimits(4,-100,0); } f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); f->FixParameter(5,0); h->GetEntries(); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(5); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); f->ReleaseParameter(1); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); TF1 *background = new TF1(Form("background_%s_%.0f",tMC.Data(),ibin),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1 *Bkpi = new TF1(Form("fBkpi_%s_%.0f",tMC.Data(),ibin),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(5)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetRange(minhisto,maxhisto); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); Bkpi->SetFillColor(kGreen+1); TF1 *mass = new TF1(Form("fmass_%s_%.0f",tMC.Data(),ibin),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); h->SetXTitle("m_{#mu#muK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"B^{+} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol; if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","pp")); else texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","PbPb")); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.04); texCol->SetTextFont(42); texCol->Draw(); TLatex* tex; if(ibin>0) { if(isLarger==1) tex = new TLatex(0.22,0.78,Form("%s > %.3f",vartex.Data(),varval)); else tex = new TLatex(0.22,0.78,Form("%s < %.3f",vartex.Data(),varval)); } else tex = new TLatex(0.22,0.78,Form("%s",_nominalcut.Data())); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 2.4"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.73,Form("N_{B} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); c->SaveAs(Form("plotFits/DMass_%s_%s_%s_%.0f.pdf",collisionsystem.Data(),varname.Data(),tMC.Data(),ibin)); return mass; }
void linfitMKDoubleGaus(TH1 *h33 , Double_t low, Double_t high, Double_t p0, Double_t p1, Double_t initialPar, Double_t width, Double_t factor, Int_t draw_opt){ double nEnt = h33->GetEntries(); TF1 *fitter = new TF1("fitter","gaus(0) + gaus(3) + [6] + [7]*x",low,high); fitter->SetParameters(100, initialPar, width, 100, initialPar, width/2., p0, p1); fitter->SetParLimits(0,10,nEnt); fitter->SetParLimits(1,initialPar-width,initialPar+width); fitter->SetParLimits(3,10,nEnt); fitter->SetParLimits(4,initialPar-width/2.,initialPar+width/2.); h33->Fit("fitter","REM","same"); //h33->Draw("E"); TF1 *backFcn = new TF1("backFcn", "[0] + [1]*x",low,high); TF1 *signalFcn = new TF1("signalFcn", "gaus(0) + gaus(3)",low,high); signalFcn->SetLineColor(2); signalFcn->SetLineWidth(2); Double_t par[8]; fitter->GetParameters(par); signalFcn->SetParameters(par); signalFcn->SetLineStyle(2); signalFcn->SetLineColor(4); signalFcn->SetLineWidth(1); backFcn->SetParameters(&par[6]); backFcn->SetLineStyle(2); backFcn->SetLineColor(6); backFcn->SetLineWidth(1); backFcn->Draw("same"); signalFcn->Draw("same"); Double_t Intg = abs(signalFcn->Integral(par[1]-factor*fabs(par[2]),par[1]+factor*fabs(par[2]))); Double_t Intb = abs(backFcn->Integral(par[1]-factor*fabs(par[2]),par[1]+factor*fabs(par[2]))); Double_t binw = h33->GetBinWidth(1); Int_t yield = Intg/binw; Int_t bckgd = Intb/binw; Double_t ratio = double(yield)/(double(yield+bckgd)); //(double(yield+bckgd) cout << yield << "\t" <<bckgd<<"\t"<< ratio << endl; TAxis *x=h33->GetXaxis(); TAxis *y=h33->GetYaxis(); Double_t startx=x->GetXmin()+0.75*(x->GetXmax()-x->GetXmin()); Double_t starty=0.65*h33->GetMaximum(); Double_t starty1=0.55*h33->GetMaximum(); Double_t starty0=0.75*h33->GetMaximum(); Double_t starty2=0.95*h33->GetMaximum(); Double_t starty3=0.85*h33->GetMaximum(); double meanError = fitter->GetParError(4); double sigmaError = fitter->GetParError(5); if (draw_opt ==1) { TLatex *sum = new TLatex(startx*0.83, starty,Form("Yield: %i",yield)); TLatex *sum12 = new TLatex(startx*0.83, starty*0.84,Form("Background: %i",bckgd)); TLatex *sum0=new TLatex(startx*0.83, starty0,Form("Range: #pm %2.1f #sigma",factor)); TLatex *sum2=new TLatex(startx*0.83, starty2,Form("Mean:%3.3f #pm %.3f",par[4], meanError)); TLatex *sum3=new TLatex(startx*0.83, starty3,Form("#sigma:%5.4f #pm %.4f GeV",par[5], sigmaError)); TLatex *ra = new TLatex(startx*0.83, starty*0.6,Form("#frac{S}{S+B}= %.3f", ratio)); sum->SetTextSize(0.04); sum->SetTextColor(2); //sum->Draw("same"); sum12->SetTextSize(0.04); sum12->SetTextColor(6); //sum12->Draw("same"); //ra->Draw("same"); sum0->SetTextSize(0.04); sum0->SetTextColor(2); //sum0->Draw("same"); sum2->SetTextSize(0.04); sum2->SetTextColor(4); sum2->Draw("same"); sum3->SetTextSize(0.04); sum3->SetTextColor(4); //sum3->Draw("same"); } // h33->GetXaxis()->SetTitle("M(e^{+}e^{-}#gamma) [GeV]"); // h33->GetYaxis()->SetTitleOffset(1.2); // // h33->GetYaxis()->SetTitle("Entries / 6 MeV"); //can1->Print("/Volumes/Mac_Storage/Physics_Papers/Annual_Review_Paper/ODU_Group_Pres/PLOTS_for_Review/New_Mass_Plots/etaprime.pdf") }
int plotEfromTree(){//main std::string baseDir = "../PLOTS/gitV00-02-04/version23/e-/"; std::string baseDirPi = "../PLOTS/gitV00-02-04/version23/pi-/"; bool isEM = baseDir.find("e-")!=baseDir.npos; TString pSuffix = ""; const bool doVsE = true; unsigned genEn[]={10,15,18,20,25,30,35,40,45,50,60,80}; const unsigned nGenEn=sizeof(genEn)/sizeof(unsigned); // unsigned nx=0,ny=0; // if (nGenEn>12) {nx=5;ny=3;} // else if (nGenEn > 10) // {nx=4;ny=3;} // else if (nGenEn > 6) // {nx=5;ny=2;} // else if (nGenEn > 4) // {nx=3;ny=2;} // else if (nGenEn > 2) // {nx=2;ny=2;} // else // {nx=nGenEn;ny=1;} // mycE->Divide(nx,ny); // std::cout << " Divide: " << nx << " " << ny << std::endl; const unsigned nLimits = 10;//5; const double pElim[nLimits] = {3,4,5,6,7,8,9,10,11,12}; const unsigned idxRef = 2; const unsigned nEPts = 2;//14; TString EnamesE[nEPts] = { "G4", //"G4mipcut", //"G4Noise12", //"G4Noise15", //"G4Noise20", //"G4XT2d5Noise", //"G4XT3d5Noise", //"G4XT5Noise", //"G4Rand1156N3Noise", //"G4Rand1156N6Noise", //"G4Rand925N3Noise", //"G4Rand925N6Noise", "G4XT2d5Rand1156N3Noise12", //"G4XT3d5Rand925N6Noise15" }; TString EnamesC[nLimits]; for (unsigned ilim(0);ilim<nLimits;++ilim){ std::ostringstream bname; bname << "Cglobal_" << static_cast<unsigned>(pElim[ilim]) << "mip"; EnamesC[ilim] = bname.str(); } unsigned nPts = nEPts+nLimits; TString Enames[nPts]; for (unsigned i(0);i<nPts;++i){ if (i<nEPts) Enames[i] = EnamesE[i]; else Enames[i] = EnamesC[i-nEPts]; } int marker[14] = {20,28,21,22,23,21,22,23,24,24,25,25,26,27}; int color[14] = {1,1,kRed-2,kRed,kRed+2,kGreen-2,kGreen,kGreen+2,kCyan,kBlue,kYellow,kYellow+2,kViolet-1,kViolet+1}; const unsigned nCanvas = nPts+6; TCanvas *myc[nCanvas]; TCanvas *mycinv[nPts]; for (unsigned iC(0);iC<nCanvas;++iC){ std::ostringstream lName; lName << "myc" << iC; myc[iC] = new TCanvas(lName.str().c_str(),lName.str().c_str(),1); lName.str(""); if (iC<nPts){ lName << "mycinv" << iC; mycinv[iC] = new TCanvas(lName.str().c_str(),lName.str().c_str(),1); } } double offsetVal[nPts]; double slopeVal[nPts]; double aVal[nPts]; double bVal[nPts]; double cVal[nPts]; for (unsigned iP(0); iP<nPts; ++iP){ offsetVal[iP] = 0; slopeVal[iP] = 1; aVal[iP] = 1; bVal[iP] = 0; cVal[iP] = 0; } for (unsigned iC(0); iC<4;++iC){//calib TLegend *leg = new TLegend(0,0,1,1); leg->SetFillColor(10); float meanE[nGenEn][nPts]; float rmsE[nGenEn][nPts]; float meanEerr[nGenEn][nPts]; float rmsEerr[nGenEn][nPts]; float meanFitE[nGenEn][nPts]; float rmsFitE[nGenEn][nPts]; float meanFitEerr[nGenEn][nPts]; float rmsFitEerr[nGenEn][nPts]; gStyle->SetOptStat(0); std::string plotDir; if (iC==1 || iC==3) plotDir = baseDir+"calib/"; else if (iC==2) { baseDir = baseDirPi; isEM = false; plotDir = baseDir; for (unsigned iP(0); iP<nEPts; ++iP){ slopeVal[iP] = slopeVal[iP]/1.19; } } else plotDir = baseDir; for (unsigned iE(0); iE<nGenEn; ++iE){ std::cout << "- Processing energy : " << genEn[iE] << std::endl; TFile *inputFile = 0; std::ostringstream linputStr; linputStr << baseDir << "validateCalice_e" << genEn[iE] << pSuffix << ".root"; inputFile = TFile::Open(linputStr.str().c_str()); if (!inputFile) { std::cout << " -- Error, input file " << linputStr.str() << " cannot be opened. Exiting..." << std::endl; return 1; } else std::cout << " -- File " << inputFile->GetName() << " successfully opened." << std::endl; TTree *tree = (TTree*)gDirectory->Get("Estudy"); if (!tree) { std::cout << " Tree not found." << std::endl; return 1; } else std::cout << " tree found." << std::endl; //extract histos extractMeanEnergy(color,marker,tree,nPts, Enames,genEn[iE], meanE[iE],rmsE[iE], meanEerr[iE],rmsEerr[iE], meanFitE[iE],rmsFitE[iE], meanFitEerr[iE],rmsFitEerr[iE], plotDir, offsetVal,slopeVal, aVal,bVal,cVal); inputFile->Close(); }//loop on energies std::ostringstream saveName; saveName.str(""); TGraphErrors *calib[nPts]; TGraphErrors *sigma[nPts]; TGraphErrors *reso[nPts]; TGraphErrors *calibinv[nPts]; TGraphErrors *calibFit[nPts]; TGraphErrors *deltaFit[nPts]; TGraphErrors *sigmaFit[nPts]; TGraphErrors *resoFit[nPts]; TGraphErrors * gr[nPts]; TGraphErrors * grDelta[nPts]; TGraphErrors *groffset = new TGraphErrors(); TGraphErrors *grslope = new TGraphErrors(); //draw all in one plot TPad *upperTot = plot_ratio(myc[nPts], true); TPad *lowerTot = plot_ratio(myc[nPts], false); if (!upperTot || !lowerTot){ std::cout << " Pb..." << upperTot << " " << lowerTot << std::endl; return 1; } //extract linearity for (unsigned iP(0); iP<nPts; ++iP){ TString lSuf = "_"; lSuf += iP; //draw calibration curves calib[iP] = new TGraphErrors(); calib[iP]->SetName("calib"+lSuf); calib[iP]->SetMarkerStyle(marker[iP]); calib[iP]->SetLineColor(color[iP]); calib[iP]->SetLineStyle(3); calib[iP]->SetMarkerColor(color[iP]); calib[iP]->SetTitle(""); sigma[iP] = (TGraphErrors *) calib[iP]->Clone("sigma"+lSuf); reso[iP] = (TGraphErrors *) calib[iP]->Clone("reso"+lSuf); calibFit[iP] = (TGraphErrors *) calib[iP]->Clone("calibFit"+lSuf); calibFit[iP]->SetMarkerStyle(marker[iP]); calibFit[iP]->SetLineStyle(1); calibFit[iP]->SetLineColor(color[iP]); calibFit[iP]->SetMarkerColor(color[iP]); calibinv[iP] = (TGraphErrors *) calibFit[iP]->Clone("calibinv"+lSuf); deltaFit[iP] = (TGraphErrors *) calibFit[iP]->Clone("deltaFit"+lSuf); sigmaFit[iP] = (TGraphErrors *) calibFit[iP]->Clone("sigmaFit"+lSuf); resoFit[iP] = (TGraphErrors *) calibFit[iP]->Clone("resoFit"+lSuf); for (unsigned iE(0); iE<nGenEn; ++iE){ Int_t np=calib[iP]->GetN(); calib[iP]->SetPoint(np,genEn[iE],meanE[iE][iP]); calib[iP]->SetPointError(np,0.0,meanEerr[iE][iP]); sigma[iP]->SetPoint(np,genEn[iE],rmsE[iE][iP]); sigma[iP]->SetPointError(np,0.0,rmsEerr[iE][iP]); reso[iP]->SetPoint(np,doVsE?genEn[iE] : 1/sqrt(genEn[iE]),rmsE[iE][iP]/meanE[iE][iP]); double err = rmsE[iE][iP]/meanE[iE][iP]*sqrt(pow(rmsEerr[iE][iP]/rmsE[iE][iP],2)+pow(meanEerr[iE][iP]/meanE[iE][iP],2)); reso[iP]->SetPointError(np,0,err); calibinv[iP]->SetPoint(np,meanFitE[iE][iP],genEn[iE]); calibinv[iP]->SetPointError(np,meanFitEerr[iE][iP],0.01*genEn[iE]); calibFit[iP]->SetPoint(np,genEn[iE],meanFitE[iE][iP]); calibFit[iP]->SetPointError(np,0.0,meanFitEerr[iE][iP]); sigmaFit[iP]->SetPoint(np,genEn[iE],rmsFitE[iE][iP]); sigmaFit[iP]->SetPointError(np,0.0,rmsFitEerr[iE][iP]); resoFit[iP]->SetPoint(np,doVsE?genEn[iE] : 1/sqrt(genEn[iE]),rmsFitE[iE][iP]/meanFitE[iE][iP]); double errFit = rmsFitE[iE][iP]/meanFitE[iE][iP]*sqrt(pow(rmsFitEerr[iE][iP]/rmsFitE[iE][iP],2)+pow(meanFitEerr[iE][iP]/meanFitE[iE][iP],2)); resoFit[iP]->SetPointError(np,0,errFit); }//loop on energies TPad *upper = plot_ratio(myc[iP], true); TPad *lower = plot_ratio(myc[iP], false); if (!upper || !lower){ std::cout << " Pb..." << upper << " " << lower << std::endl; return 1; } //draw inverted calib mycinv[iP]->cd(); gPad->SetGridx(1); gPad->SetGridy(1); gr[iP] = calibinv[iP]; //gr[iP]->GetXaxis()->SetLabelSize(0.06); //gr[iP]->GetXaxis()->SetTitleSize(0.06); //gr[iP]->GetYaxis()->SetLabelSize(0.06); //gr[iP]->GetYaxis()->SetTitleSize(0.06); //gr[iP]->GetXaxis()->SetTitleOffset(0.7); //gr[iP]->GetYaxis()->SetTitleOffset(0.8); gr[iP]->SetTitle(Enames[iP]); gr[iP]->Draw("ap"); gr[iP]->GetYaxis()->SetTitle("Beam energy [GeV]"); if (iC==0) gr[iP]->GetXaxis()->SetTitle("Corrected energy deposited [MIPs]"); else gr[iP]->GetXaxis()->SetTitle("Corrected energy deposited [GeV]"); //gr[iP]->GetXaxis()->SetTitle(doVsE?"Beam energy [GeV]" :"1/#sqrt{Beam energy} [1/#sqrt{GeV}]"); char buf[500]; //TF1 *fitFunc=new TF1("calib","[0]+[1]*x",gr->GetXaxis()->GetXmin(),gr->GetXaxis()->GetXmax()); TF1 *fitFuncinv=new TF1("calibinv","[0]*x+[1]*x*x+[2]*x*x*x",gr[iP]->GetXaxis()->GetXmin(),gr[iP]->GetXaxis()->GetXmax()); fitFuncinv->SetLineColor(1); gr[iP]->Fit(fitFuncinv,"RME"); gr[iP]->GetFunction("calibinv")->SetLineColor(color[iP]); TLatex lat; lat.SetTextColor(1); sprintf(buf,"<E> #propto E #times (a + b #times E +c #times E^{2})"); lat.DrawLatex(genEn[0],gr[iP]->GetYaxis()->GetXmax()*0.9,buf); sprintf(buf,"a = %3.3f #pm %3.3f %s",fitFuncinv->GetParameter(0),fitFuncinv->GetParError(0),iC==0?"MIPs":"GeV"); lat.DrawLatex(genEn[0],gr[iP]->GetYaxis()->GetXmax()*(0.8),buf); sprintf(buf,"b = %3.3f #pm %3.3f %s/GeV",fitFuncinv->GetParameter(1),fitFuncinv->GetParError(1),iC==0?"MIPs":"GeV"); lat.DrawLatex(genEn[0],gr[iP]->GetYaxis()->GetXmax()*(0.7),buf); sprintf(buf,"c = %3.6f #pm %3.6f %s/GeV",fitFuncinv->GetParameter(2),fitFuncinv->GetParError(2),iC==0?"MIPs":"GeV"); lat.DrawLatex(genEn[0],gr[iP]->GetYaxis()->GetXmax()*(0.6),buf); sprintf(buf,"chi2/NDF = %3.3f/%d = %3.3f",fitFuncinv->GetChisquare(),fitFuncinv->GetNDF(),fitFuncinv->GetChisquare()/fitFuncinv->GetNDF()); lat.DrawLatex(genEn[0],gr[iP]->GetYaxis()->GetXmax()*(0.5),buf); if (iP>=nEPts && iC==2) { aVal[iP] = fitFuncinv->GetParameter(0); bVal[iP] = fitFuncinv->GetParameter(1); cVal[iP] = fitFuncinv->GetParameter(2); } mycinv[iP]->Update(); saveName.str(""); saveName << plotDir << "/CalibEshower_" << Enames[iP]; mycinv[iP]->Update(); mycinv[iP]->Print((saveName.str()+".png").c_str()); mycinv[iP]->Print((saveName.str()+".pdf").c_str()); //draw calib upper->cd(); gPad->SetGridx(1); gPad->SetGridy(1); gr[iP] = calibFit[iP]; gr[iP]->GetXaxis()->SetLabelSize(0.06); gr[iP]->GetXaxis()->SetTitleSize(0.06); gr[iP]->GetYaxis()->SetLabelSize(0.06); gr[iP]->GetYaxis()->SetTitleSize(0.06); gr[iP]->GetXaxis()->SetTitleOffset(0.7); gr[iP]->GetYaxis()->SetTitleOffset(0.8); gr[iP]->SetTitle(Enames[iP]); gr[iP]->SetMaximum(std::max(calib[iP]->GetMaximum(),calibFit[iP]->GetMaximum())); gr[iP]->Draw("ap"); calib[iP]->Draw("pl"); gr[iP]->GetXaxis()->SetTitle(""); if (iC==0) gr[iP]->GetYaxis()->SetTitle("Average energy deposited [MIPs]"); else gr[iP]->GetYaxis()->SetTitle("Average energy deposited [GeV]"); //gr[iP]->GetXaxis()->SetTitle(doVsE?"Beam energy [GeV]" :"1/#sqrt{Beam energy} [1/#sqrt{GeV}]"); //TF1 *fitFunc=new TF1("calib","[0]+[1]*x",gr->GetXaxis()->GetXmin(),gr->GetXaxis()->GetXmax()); TF1 *fitFunc=new TF1("calib","[0]+[1]*x",9,51); fitFunc->SetLineColor(1); gr[iP]->Fit(fitFunc,"RME"); gr[iP]->GetFunction("calib")->SetLineColor(color[iP]); lat.SetTextColor(1); sprintf(buf,"<E> #propto a + b #times E "); lat.DrawLatex(genEn[0],gr[iP]->GetYaxis()->GetXmax()*0.9,buf); sprintf(buf,"a = %3.3f #pm %3.3f %s",fitFunc->GetParameter(0),fitFunc->GetParError(0),iC==0?"MIPs":"GeV"); lat.DrawLatex(genEn[0],gr[iP]->GetYaxis()->GetXmax()*(0.8),buf); sprintf(buf,"b = %3.3f #pm %3.3f %s/GeV",fitFunc->GetParameter(1),fitFunc->GetParError(1),iC==0?"MIPs":"GeV"); lat.DrawLatex(genEn[0],gr[iP]->GetYaxis()->GetXmax()*(0.7),buf); sprintf(buf,"chi2/NDF = %3.3f/%d = %3.3f",fitFunc->GetChisquare(),fitFunc->GetNDF(),fitFunc->GetChisquare()/fitFunc->GetNDF()); lat.DrawLatex(genEn[0],gr[iP]->GetYaxis()->GetXmax()*(0.6),buf); groffset->SetPoint(iP,iP,fitFunc->GetParameter(0)); groffset->SetPointError(iP,0.0,fitFunc->GetParError(0)); if (iC==0) offsetVal[iP] = fitFunc->GetParameter(0); if (iP>=nEPts && iC==0) offsetVal[iP] = offsetVal[1]; grslope->SetPoint(iP,iP,fitFunc->GetParameter(1)); grslope->SetPointError(iP,0.0,fitFunc->GetParError(1)); if (iC==0) slopeVal[iP] = fitFunc->GetParameter(1); if (iP>=nEPts && iC==0) slopeVal[iP] = slopeVal[1]; //groffset->GetXaxis()->SetBinLabel(iP+1,Enames[iP].Data()); //grslope->GetHistogram()->GetXaxis()->SetBinLabel(iP+1,Enames[iP].Data()); //draw deltaE/E vs E lower->cd(); gPad->SetLogx(0); gPad->SetGridx(1); gPad->SetGridy(1); for (unsigned iE(0);iE<nGenEn;++iE){ if (iC<1){ deltaFit[iP]->SetPoint(iE,genEn[iE],( ((meanFitE[iE][iP]-fitFunc->GetParameter(0))/fitFunc->GetParameter(1))-genEn[iE])/genEn[iE]); deltaFit[iP]->SetPointError(iE,0.0,meanFitEerr[iE][iP]/fitFunc->GetParameter(1)*1./genEn[iE]); } else { deltaFit[iP]->SetPoint(iE,genEn[iE],(meanFitE[iE][iP]-genEn[iE])/genEn[iE]); deltaFit[iP]->SetPointError(iE,0.0,meanFitEerr[iE][iP]/genEn[iE]); } } grDelta[iP] = deltaFit[iP]; grDelta[iP]->SetTitle(""); if (iC<2){ grDelta[iP]->SetMinimum(-0.03); grDelta[iP]->SetMaximum(0.03); } else { grDelta[iP]->SetMinimum(-0.1); grDelta[iP]->SetMaximum(0.1); } grDelta[iP]->GetXaxis()->SetLabelSize(0.15); grDelta[iP]->GetXaxis()->SetTitleSize(0.15); grDelta[iP]->GetYaxis()->SetLabelSize(0.12); grDelta[iP]->GetYaxis()->SetTitleSize(0.15); grDelta[iP]->GetXaxis()->SetTitleOffset(0.5); grDelta[iP]->GetYaxis()->SetTitleOffset(0.3); grDelta[iP]->Draw("ap"); //grDelta[iP]->GetYaxis()->SetRangeUser(0,grDelta->GetYaxis()->GetXmax()); grDelta[iP]->GetXaxis()->SetTitle("Beam energy [GeV]"); grDelta[iP]->GetYaxis()->SetTitle("(#Delta E)/E"); myc[iP]->Update(); saveName.str(""); saveName << plotDir << "/CalibE_" << Enames[iP]; myc[iP]->Update(); myc[iP]->Print((saveName.str()+".png").c_str()); myc[iP]->Print((saveName.str()+".pdf").c_str()); upperTot->cd(); gPad->SetGridx(1); gPad->SetGridy(1); if (iP==0) gr[iP]->Draw("ap"); else gr[iP]->Draw("psame"); lowerTot->cd(); gPad->SetGridx(1); gPad->SetGridy(1); if (iP==0) grDelta[iP]->Draw("ap"); else grDelta[iP]->Draw("psame"); myc[nPts+1]->cd(); gPad->SetGridx(1); gPad->SetGridy(1); sigmaFit[iP]->SetTitle(""); sigmaFit[iP]->SetMaximum(std::max(sigma[iP]->GetMaximum(),sigmaFit[iP]->GetMaximum())); if (iP==0) sigmaFit[iP]->Draw("ap"); else sigmaFit[iP]->Draw("p"); //sigma[iP]->Draw("pl"); sigmaFit[iP]->GetXaxis()->SetTitle("Beam energy [GeV]"); if (iC==0) sigmaFit[iP]->GetYaxis()->SetTitle("RMS energy deposited [MIPs]"); else sigmaFit[iP]->GetYaxis()->SetTitle("RMS energy deposited [GeV]"); leg->AddEntry(sigmaFit[iP],Enames[iP],"P"); myc[nPts+2]->cd(); gPad->SetGridx(1); gPad->SetGridy(1); resoFit[iP]->SetTitle(""); //resoFit[iP]->SetMaximum(std::max(reso[iP]->GetMaximum(),resoFit[iP]->GetMaximum())); if (iP==0) resoFit[iP]->Draw("ap"); else resoFit[iP]->Draw("p"); //reso[iP]->Draw("pl"); resoFit[iP]->GetXaxis()->SetTitle("Beam energy (GeV)"); resoFit[iP]->GetYaxis()->SetTitle("Relative energy resolution"); TF1* fitref =new TF1("reso","sqrt([0]/x+[1]+[2]/(x*x))",resoFit[iP]->GetXaxis()->GetXmin(),resoFit[iP]->GetXaxis()->GetXmax()); if (isEM) fitref->SetParameters(0.215*0.215,0.007*0.007,0.06*0.06); else { if (iP<nEPts) fitref->SetParameters(0.518*0.518,0.04*0.04,0.18*0.18); else fitref->SetParameters(0.436*0.436,0.0*0.0,0.18*0.18); } fitref->SetLineColor(4); fitref->SetLineStyle(2); fitref->Draw("same"); lat.SetTextColor(4); //sprintf(buf,"CALICE"); sprintf(buf,"CALICE s=%3.3f, c=%3.3f, n=%3.3f",sqrt(fitref->GetParameter(0)),sqrt(fitref->GetParameter(1)),sqrt(fitref->GetParameter(2))); if (iP==0) lat.DrawLatex(30,resoFit[iP]->GetYaxis()->GetXmax()*0.9,buf); myc[iP]->Clear(); myc[iP]->cd(); gPad->SetGridx(1); gPad->SetGridy(1); resoFit[iP]->SetMaximum(std::max(reso[iP]->GetMaximum(),resoFit[iP]->GetMaximum())); resoFit[iP]->GetXaxis()->SetLabelSize(0.05); resoFit[iP]->GetXaxis()->SetTitleSize(0.05); resoFit[iP]->GetYaxis()->SetLabelSize(0.05); resoFit[iP]->GetYaxis()->SetTitleSize(0.05); //resoFit[iP]->GetXaxis()->SetTitleOffset(0.7); resoFit[iP]->GetYaxis()->SetTitleOffset(1.2); resoFit[iP]->Draw("ap"); //reso[iP]->Draw("l"); bool addNoiseTerm = false; if (iP>0) addNoiseTerm = true; TF1 *fitFunc2; if (doVsE){ fitFunc2 =new TF1("reso","sqrt([0]/x+[1])",resoFit[iP]->GetXaxis()->GetXmin(),resoFit[iP]->GetXaxis()->GetXmax()); if (addNoiseTerm) fitFunc2 =new TF1("reso","sqrt([0]/x+[1]+[2]/(x*x))",resoFit[iP]->GetXaxis()->GetXmin(),resoFit[iP]->GetXaxis()->GetXmax()); } else { fitFunc2 =new TF1("reso","sqrt([0]*x*x+[1])",resoFit[iP]->GetXaxis()->GetXmin(),resoFit[iP]->GetXaxis()->GetXmax()); if (addNoiseTerm) fitFunc2 =new TF1("reso","sqrt([0]*x*x+[1]+[2]*x*x*x*x)",resoFit[iP]->GetXaxis()->GetXmin(),resoFit[iP]->GetXaxis()->GetXmax()); } fitFunc2->SetParameter(0,0.2); fitFunc2->SetParLimits(0,0,1); fitFunc2->SetParameter(1,0.01); fitFunc2->SetParLimits(1,0,1); if (addNoiseTerm) { if (!isEM) fitFunc2->SetParameter(2,0.18*0.18); else fitFunc2->SetParameter(2,0.06*0.06); fitFunc2->SetParLimits(2,0,2); if (!isEM) fitFunc2->FixParameter(2,0.18*0.18); else fitFunc2->FixParameter(2,0.06*0.06); } fitref->Draw("same"); resoFit[iP]->Fit(fitFunc2,"RME+"); resoFit[iP]->GetFunction("reso")->SetLineColor(color[iP]); fitFunc2->SetLineColor(color[iP]); fitFunc2->Draw("same"); double sigmaStoch = sqrt(fitFunc2->GetParameter(0)); double sigmaStochErr = fitFunc2->GetParError(0)/(2*sigmaStoch); double sigmaConst = sqrt(fitFunc2->GetParameter(1)); double sigmaConstErr = fitFunc2->GetParError(1)/(2*sigmaConst); double sigmaNoise = 0; double sigmaNoiseErr = 0; if (addNoiseTerm) { sigmaNoise = sqrt(fitFunc2->GetParameter(2)); sigmaNoiseErr = fitFunc2->GetParError(2)/(2*sigmaNoise); } lat.SetTextColor(1); sprintf(buf,"#frac{#sigma}{E} #propto #frac{s}{#sqrt{E}} #oplus c #oplus #frac{n}{E}"); double Emin = doVsE?50 : 1/sqrt(genEn[nGenEn-1]); lat.DrawLatex(Emin,resoFit[iP]->GetYaxis()->GetXmax()*0.94,buf); sprintf(buf,"s=%3.3f #pm %3.3f",sigmaStoch,sigmaStochErr); lat.DrawLatex(Emin,resoFit[iP]->GetYaxis()->GetXmax()*0.84,buf); sprintf(buf,"c=%3.3f #pm %3.3f",sigmaConst,sigmaConstErr); lat.DrawLatex(Emin,resoFit[iP]->GetYaxis()->GetXmax()*0.74,buf); sprintf(buf,"chi2/NDF = %3.3f/%d = %3.3f",fitFunc2->GetChisquare(),fitFunc2->GetNDF(),fitFunc2->GetChisquare()/fitFunc2->GetNDF()); //lat.DrawLatex(Emin,resoFit[iP]->GetYaxis()->GetXmax()*0.54,buf); if (addNoiseTerm) { sprintf(buf,"n=%3.2f",sigmaNoise); lat.DrawLatex(Emin,resoFit[iP]->GetYaxis()->GetXmax()*0.64,buf); } lat.SetTextColor(4); //sprintf(buf,"CALICE s=%3.3f, c=%3.3f, n=%3.3f",sqrt(fitref->GetParameter(0)),sqrt(fitref->GetParameter(1)),sqrt(fitref->GetParameter(2))); sprintf(buf,"CALICE"); lat.DrawLatex(70,resoFit[iP]->GetYaxis()->GetXmin()*1.35,buf); lat.SetTextColor(1); lat.DrawLatex(20,resoFit[iP]->GetYaxis()->GetXmax()*1.03,"Geant4 QGSP_BERT, #pi^{-} gun"); myc[iP]->Update(); saveName.str(""); saveName << plotDir << "/ResoE_" << Enames[iP]; myc[iP]->Update(); myc[iP]->Print((saveName.str()+".png").c_str()); myc[iP]->Print((saveName.str()+".pdf").c_str()); }//loop on points saveName.str(""); saveName << plotDir << "/Linearity_all";// << Enames[iP]; myc[nPts]->Update(); myc[nPts]->Print((saveName.str()+".png").c_str()); myc[nPts]->Print((saveName.str()+".pdf").c_str()); myc[nPts+1]->Update(); saveName.str(""); saveName << plotDir << "/RMSE_all";// << Enames[iP]; myc[nPts+1]->Update(); myc[nPts+1]->Print((saveName.str()+".png").c_str()); myc[nPts+1]->Print((saveName.str()+".pdf").c_str()); myc[nPts+2]->Update(); saveName.str(""); saveName << plotDir << "/Ereso_all";// << Enames[iP]; myc[nPts+2]->Update(); myc[nPts+2]->Print((saveName.str()+".png").c_str()); myc[nPts+2]->Print((saveName.str()+".pdf").c_str()); //myc[nPts+1]->Divide(1,2); myc[nPts+3]->cd(); gPad->SetGridx(1); gPad->SetGridy(1); groffset->SetTitle(""); groffset->GetXaxis()->SetTitle("Point"); groffset->GetYaxis()->SetTitle("Offset"); groffset->SetMarkerStyle(21); groffset->Draw("ap"); saveName.str(""); saveName << plotDir << "/Offset";// << Enames[iP]; myc[nPts+3]->Update(); myc[nPts+3]->Print((saveName.str()+".png").c_str()); myc[nPts+3]->Print((saveName.str()+".pdf").c_str()); myc[nPts+4]->cd(); gPad->SetGridx(1); gPad->SetGridy(1); grslope->SetTitle(""); grslope->GetXaxis()->SetTitle("Point"); grslope->GetYaxis()->SetTitle("Slope"); grslope->SetMarkerStyle(21); grslope->Draw("ap"); saveName.str(""); saveName << plotDir << "/Slope";// << Enames[iP]; myc[nPts+4]->Update(); myc[nPts+4]->Print((saveName.str()+".png").c_str()); myc[nPts+4]->Print((saveName.str()+".pdf").c_str()); myc[nPts+5]->cd(); leg->Draw(); saveName.str(""); saveName << plotDir << "/Legend";// << Enames[iP]; myc[nPts+5]->Update(); myc[nPts+5]->Print((saveName.str()+".png").c_str()); myc[nPts+5]->Print((saveName.str()+".pdf").c_str()); }//calib return 0; }
TF1 *fit(TH1D* h, TTree *ntMC, TTree *ntMC2,double ptmin,double ptmax) { static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); // Fit function TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])+(1-[7])*Gaus(x,[1],[8]))+[3]+[4]*x+[6]*(38.42*Gaus(x,5.25,0.03473)+15.04*Gaus(x,5.25,0.1121)+104.3*Gaus(x,5.026,0.0935))"); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata.Data(),ptmin,ptmax)); ntMC2->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.1); f->SetParLimits(7,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x+[3]*(38.42*Gaus(x,5.25,0.03473)+15.04*Gaus(x,5.25,0.1121)+104.3*Gaus(x,5.026,0.0935))"); // TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*(1.24e2*Gaus(x,5.107,0.02987)+1.886e2*Gaus(x,5.0116,5.546e-2))"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*(38.42*Gaus(x,5.25,0.03473)+15.04*Gaus(x,5.25,0.1121)+104.3*Gaus(x,5.026,0.0935))"); Bkpi->SetParameter(0,f->GetParameter(6)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); Bkpi->SetRange(5.00,5.45); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3005); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])+(1-[3])*Gaus(x,[1],[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.4,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); // hBck->Draw("hist same"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); cout <<"fit result:"<<f->GetParameter(0)*2.5<<" "<<f->Integral(5,6)/h->GetBinWidth(1)<<endl; double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.92); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",f->GetParameter(1)*1000.,f->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f",yield,yieldErr),""); leg2->Draw(); //c->SaveAs(Form("ResultsCheckStatErr/BMass-%d.C",count)); c->SaveAs(Form("ResultsCheckStatErr/BMass-%d.gif",count)); //c->SaveAs(Form("ResultsBzero/BMass-%d.eps",count)); return mass; }
void fitBvar(TString collsyst="PbPb", TString inputfile ="", TString npfile="ROOTfiles/NPFitPbPb.root", float centMin=0, float centMax=100, TString outputfile="outHisto") { collisionsystem = collsyst; infname = outputfile; centmin = centMin; centmax = centMax; if(collsyst != "PbPb") isPbPb = false; gStyle->SetTextSize(0.05); gStyle->SetTextFont(42); gStyle->SetPadRightMargin(0.02); gStyle->SetPadLeftMargin(0.18); gStyle->SetPadTopMargin(0.09); gStyle->SetPadBottomMargin(0.145); gStyle->SetTitleX(.0f); TF1* fit (float ptmin, float ptmax, int s, int b, int widVar); // widVar=0,1 TCanvas* c = new TCanvas("c","",600,600); TF1* bmass = new TF1("bmass","[0]",7,50); bmass->SetTitle(";B^{+} p_{T} (GeV/c);fraction of default yield"); bmass->SetMinimum(0.9); bmass->SetMaximum(1.1); if(isPbPb) { bmass->SetMinimum(0.9); bmass->SetMaximum(1.1); } bmass->SetParameter(0,1); bmass->SetLineWidth(1); bmass->SetLineColor(kRed); bmass->SetLineStyle(2); bmass->GetXaxis()->SetTitleOffset(1.3); bmass->GetYaxis()->SetTitleOffset(1.8); bmass->GetXaxis()->SetLabelOffset(0.007); bmass->GetYaxis()->SetLabelOffset(0.007); bmass->GetXaxis()->SetTitleSize(0.045); bmass->GetYaxis()->SetTitleSize(0.045); bmass->GetXaxis()->SetTitleFont(42); bmass->GetYaxis()->SetTitleFont(42); bmass->GetXaxis()->SetLabelFont(42); bmass->GetYaxis()->SetLabelFont(42); bmass->GetXaxis()->SetLabelSize(0.04); bmass->GetYaxis()->SetLabelSize(0.04); bmass->Draw(); TLatex* Title = new TLatex(0.1,0.94, Form("Fit Variation for %s",collisionsystem.Data())); Title->SetNDC(); Title->SetTextAlign(12); Title->SetTextSize(0.04); Title->SetTextFont(42); Title->Draw("Same"); TLegend* leg = new TLegend(0.2,0.67,0.4,0.87,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); getNPFnPar(npfile, NPpar); std::cout<<"NP parameter 0: "<<NPpar[0]<<std::endl; std::cout<<"NP parameter 1: "<<NPpar[1]<<std::endl; TString inputf; if(nBins == 1) inputf = Form("%s_integrated.root",inputfile.Data()); else inputf = Form("%s.root",inputfile.Data()); TFile* data = new TFile(inputf.Data()); TH1D* h_def = (TH1D*)data->Get("hPt"); TH1D* hwidvar; int cnt =0; for(int s=0;s<nsig;s++) { bkgmax[0]=sigmax[s]+2; for(int b=0;b<nbkg;b++) { if(s==0 || b==0) { TH1D* hvar = new TH1D(Form("h_%s",bkgname[b].Data()),"",nBins,ptBins); if(s==0 && b==0) hwidvar = new TH1D("h_widvar","",nBins,ptBins); for(int i=0;i<nBins;i++) { double def_y = h_def->GetBinContent(i+1); double def_err = h_def->GetBinError(i+1); TF1* f = fit(ptBins[i],ptBins[i+1],s,b,0); cout<<"YIELD / YIELDERR: "<< yield <<" "<< yieldErr << endl; cout << "DEF YIELD: "<< def_y*(ptBins[i+1]-ptBins[i]) <<endl; double y = yield/(ptBins[i+1]-ptBins[i]); double err = yieldErr/(ptBins[i+1]-ptBins[i]); double y_fr = y/def_y; cout << "YIELD FRACTION: " << y_fr << endl; double err_fr = sqrt(pow(err/def_y,2)+pow(def_err*y/(def_y*def_y),2)); hvar->SetBinContent(i+1,y_fr); hvar->SetBinError(i+1,err_fr); hvar->SetMarkerStyle(8); hvar->SetMarkerColor(4+cnt); cnt++; if(s==0 && b==0) { f = fit(ptBins[i],ptBins[i+1],0,0,1); cout<<"YIELD / YIELDERR: "<< yield <<" "<< yieldErr << endl; cout << "DEF YIELD: "<< def_y*(ptBins[i+1]-ptBins[i]) <<endl; y = yield/(ptBins[i+1]-ptBins[i]); err = yieldErr/(ptBins[i+1]-ptBins[i]); y_fr = y/def_y; cout << "YIELD FRACTION: " << y_fr << endl; err_fr = sqrt(pow(err/def_y,2)+pow(def_err*y/(def_y*def_y),2)); hwidvar->SetBinContent(i+1,y_fr); hwidvar->SetBinError(i+1,err_fr); hwidvar->SetMarkerStyle(8); hwidvar->SetMarkerColor(3); } } c->cd(); hvar->Draw("Same"); if(s==0 && b==0) hwidvar->Draw("Same"); leg->AddEntry(hvar,Form("%s and %s",signame[s].Data(),bkgname[b].Data()),"pl"); if(s==0 && b==0) leg->AddEntry(hwidvar, "Width Variation", "pl"); } } } c->cd(); leg->Draw("Same"); if(nBins == 1) c->SaveAs(Form("SystPDF/total_var_%s.pdf",collisionsystem.Data())); else c->SaveAs(Form("SystPDF/var_%s.pdf",collisionsystem.Data())); }
void long_Ay_nu_05() { gROOT->SetStyle("HALLA"); TCanvas *cn = new TCanvas("cn","cn",540,360); cn->Draw(); cn->UseCurrentStyle(); TH1F *frm = new TH1F("frm","",100,0.,10.); frm->GetXaxis()->SetTitle("#nu (GeV)"); frm->GetYaxis()->SetTitle("Ay for Q2=0.456 (GeV/c)2"); frm->SetMinimum(0); // frm->SetMinimum(0); // frm->SetMaximum(1.0); frm->SetMaximum(0.35); frm->UseCurrentStyle(); frm->Draw(); frm->SetAxisRange(0.120,0.350,"X"); // frm->SetAxisRange(0.5,1.1,"X"); // TF1* galster = new TF1("galster","x/(4.*0.938*.938)*1.91/(1.+x/.71)^2/(1.+5.6*x/(4.*.938*.938))",0.,4.); // galster->SetLineColor(6); // galster->SetLineStyle(3); // galster->SetLineWidth(2); TF1 *genf = new TF1("genf",genff,1.,10.,1); genf->SetLineColor(2); genf->SetLineStyle(2); genf->SetParameter(0,1.); // match to Madey point just below 1.5 // genf->SetParameter(0,.0411/genf->Eval(1.45)); genf->SetParameter(0,-0.558645); // TF1 *bbba05 = new TF1("BBBA05",gen_bbba05,0.,10.,0); // bbba05->SetLineColor(7); // bbba05->SetLineStyle(3); TMultiGraph* mgrDta = new TMultiGraph("Data","G_{E}^{n}"); TLegend *legDta = new TLegend(.54,.6,.875,.90,"","brNDC"); TMultiGraph* wgr = mgrDta; TLegend *wlg = legDta; // the data legDta->SetBorderSize(0); // turn off border legDta->SetFillStyle(0); datafile_t *f = datafiles; TGraph* gr=0; while ( f && f->filename ) { gr=OneGraph(f); if (gr) { if (f->lnpt) { mgrDta->Add(gr,f->lnpt); legDta->AddEntry(gr,f->label,f->lnpt); } else if (gr->GetMarkerStyle()>=20) { mgrDta->Add(gr,"p"); legDta->AddEntry(gr,f->label,"p"); } else { mgrDta->Add(gr,"l"); legDta->AddEntry(gr,f->label,"l"); } } f++; } mgrDta->Draw("p"); // legDta->Draw(); TF1 *theFit = new TF1("theFit","pol0"); gr->Fit(theFit); theFit->Draw("same"); TMultiGraph* mgrThry = new TMultiGraph("Theory","G_{E}^{n}"); TLegend *legThry = new TLegend(.54,.3,.875,.6,"","brNDC"); wgr = mgrThry; wlg = legThry; // the theory wlg->SetBorderSize(0); // turn off border wlg->SetFillStyle(0); f = theoryfiles1; gr=0; while ( f && f->filename ) { gr=OneGraph(f); if (gr) { TGraphAsymmErrors *egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetN()>1 && egr->GetEYhigh() && egr->GetEYhigh()[1]>0) { gr = toerror_band(egr); gr->SetFillStyle(3000+f->style); } if (f->lnpt) { wgr->Add(gr,f->lnpt); wlg->AddEntry(gr,f->label,f->lnpt); } else if (gr->GetMarkerStyle()>=20) { wgr->Add(gr,"p"); wlg->AddEntry(gr,f->label,"p"); } else { wgr->Add(gr,"l"); wlg->AddEntry(gr,f->label,"l"); } } f++; } // genf->Draw("same"); mgrThry->Draw("c"); // galster->Draw("same"); // bbba05->Draw("same"); // legThry->AddEntry(genf,"F_{2}/F_{1} #propto ln^{2}(Q^{2}/#Lambda^{2})/Q^{2}","l"); // legThry->AddEntry(galster,"Galster fit","l"); // legThry->AddEntry(bbba05,"BBBA05","l"); // legThry->Draw(); // legDta->Draw(); // draw a line at 1 cn->Modified(); cn->Update(); cn->SaveAs(Form("%s.eps",psfile)); cn->SaveAs(Form("%s.root",psfile)); gSystem->Exec(Form("./replace_symbols.pl %s.eps",psfile)); return; // LEAVING HERE // now an overlay, hopefully matching dimensions // remove everything but the graph cn->Update(); TList *clist = cn->GetListOfPrimitives(); TFrame* frame = cn->GetFrame(); for (int i=0; i<clist->GetSize(); ) { if (clist->At(i) != frame) { clist->RemoveAt(i); } else i++; } // draw markers in the corners TMarker *mkr = new TMarker(frame->GetX1(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX1(),frame->GetY2(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY2(),2); mkr->Draw(); frame->SetLineColor(10); cn->Update(); datafile_t miller = { "figure_input/Miller/lattice.GEn.rtf","Miller", "[0]","[1]","[1]-[3]","[2]-[1]",0,0,1,3,"F" }; gr = OneGraph(&miller); TGraphAsymmErrors* egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetEYhigh() && egr->GetEYhigh()[egr->GetN()/2]>0) { gr = toerror_band(egr); gr->SetLineStyle(1); gr->SetFillColor(gr->GetLineColor()); gr->SetFillStyle(3000+miller.style); } gr->Draw("F"); cn->Update(); cn->SaveAs("gen_Miller_Overlay.eps"); cn->SaveAs("gen_Miller_Overlay.root"); }
TF1* fitDstar5prongs(TTree* nt, Double_t ptmin, Double_t ptmax) { static int count5p=0; count5p++; TCanvas* c = new TCanvas(Form("c_5p_%d",count5p),"",600,600); TH1D* h = new TH1D(Form("h_5p_%d",count5p),"",60,0.140,0.160); TF1* f = new TF1(Form("f_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*((1-[8])*TMath::Gaus(x,[6],[7])/(sqrt(2*3.14159)*[7])+[8]*TMath::Gaus(x,[6],[9])/(sqrt(2*3.14159)*[9]))",minmass3prong,maxmass3prong); nt->Project(Form("h_5p_%d",count5p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata5p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); f->SetLineColor(4); f->SetParameters(0,0,0,0,0,2e2,1.45491e-1,9e-4,0.1,8e-4); f->FixParameter(9,15e-4); f->FixParameter(6,0.145491); f->FixParameter(7,8e-4); f->SetParLimits(8,0,1); f->SetParLimits(5,0,100000); h->Fit(Form("f_5p_%d",count5p),"LL"); h->Fit(Form("f_5p_%d",count5p),"LL"); h->Fit(Form("f_5p_%d",count5p),"LL","",minmass3prong,maxmass3prong); f->ReleaseParameter(6); f->ReleaseParameter(7); f->ReleaseParameter(9); f->SetParLimits(6,0.144,0.147); f->SetParLimits(7,1e-4,9e-4); f->SetParLimits(9,1e-4,9e-4); h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.148); h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16); TF1* background = new TF1(Form("background_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x"); background->SetParameter(0,f->GetParameter(0)); background->SetParameter(1,f->GetParameter(1)); background->SetParameter(2,f->GetParameter(2)); background->SetParameter(3,f->GetParameter(3)); background->SetParameter(4,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(minmass3prong,maxmass3prong); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_5p_%d",count5p),"[0]*((1-[3])*TMath::Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+[3]*TMath::Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(5),f->GetParameter(6),f->GetParameter(7),f->GetParameter(8),f->GetParameter(9)); mass->SetParError(0,f->GetParError(5)); mass->SetParError(1,f->GetParError(6)); mass->SetParError(2,f->GetParError(7)); mass->SetParError(3,f->GetParError(8)); mass->SetParError(4,f->GetParError(9)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})"); h->SetYTitle("Entries / (1/3 MeV/c^{2})"); h->SetStats(0); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(0.142,0.152); mass->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong; Double_t yieldErr = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong*mass->GetParError(0)/mass->GetParameter(0); TLatex* tex; TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.20,0.79,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); c->SaveAs(Form("plots/pp/DMass_%s_5prongs-%d.pdf",texData[isData].Data(),count5p)); return mass; }
int makeInvMassHistosNoBGKK(){ //Set global style stuff gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetCanvasColor(kWhite); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetTitleBorderSize(0); gStyle->SetOptStat(0); gStyle->SetOptFit(1); gStyle->SetErrorX(0); gStyle->SetTitleW(0.9); gStyle->SetTitleSize(0.05, "xyz"); gStyle->SetTitleSize(0.06, "h"); int NUM_PT_BINS = 20; int NUM_MASS_BINS = 1000; double MASS_LOW = 0.0; double MASS_HIGH = 2.0; string particles [8]; particles[0] = "K*^{+} + K*^{0}"; particles[1] = "K*^{-} + #bar{K}*^{0}"; particles[2] = "K*^{+}"; particles[3] = "K*^{-}"; particles[4] = "K*^{0}"; particles[5] = "#bar{K}*^{0}"; particles[6] = "K*^{0} + #bar{K}*^{0}"; particles[7] = "K*^{+} + K*^{-}"; //at decay point // string folder = "/Users/jtblair/Downloads/kstar_data/decayed/pt02/"; //reconstructed string folder = "/Users/jtblair/Downloads/kstar_data/reconstructed/pt02/"; string files[20]; files[0] = "invm_[0.0,0.2].dat"; files[1] = "invm_[0.2,0.4].dat"; files[2] = "invm_[0.4,0.6].dat"; files[3] = "invm_[0.6,0.8].dat"; files[4] = "invm_[0.8,1.0].dat"; files[5] = "invm_[1.0,1.2].dat"; files[6] = "invm_[1.2,1.4].dat"; files[7] = "invm_[1.4,1.6].dat"; files[8] = "invm_[1.6,1.8].dat"; files[9] = "invm_[1.8,2.0].dat"; files[10] = "invm_[2.0,2.2].dat"; files[11] = "invm_[2.2,2.4].dat"; files[12] = "invm_[2.4,2.6].dat"; files[13] = "invm_[2.6,2.8].dat"; files[14] = "invm_[2.8,3.0].dat"; files[15] = "invm_[3.0,3.2].dat"; files[16] = "invm_[3.2,3.4].dat"; files[17] = "invm_[3.4,3.6].dat"; files[18] = "invm_[3.6,3.8].dat"; files[19] = "invm_[3.8,4.0].dat"; /* string files[8]; files[0] = "invm_[0.0,0.5].dat"; files[1] = "invm_[0.5,1.0].dat"; files[2] = "invm_[1.0,1.5].dat"; files[3] = "invm_[1.5,2.0].dat"; files[4] = "invm_[2.0,2.5].dat"; files[5] = "invm_[2.5,3.0].dat"; files[6] = "invm_[3.0,3.5].dat"; files[7] = "invm_[3.5,4.0].dat"; */ Int_t PARTICLE_NUM = 5; TFile *output = new TFile("20170721_KKbarAdded2_fixedwidth42_recon_pf100_scaled_error05.root", "RECREATE"); TH1D *kstar0mass = new TH1D("kstar0mass", Form("Fit value of M*_{0} vs. p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS, 0.0, 4.0); TH1D *kstar0width = new TH1D("kstar0width", Form("#Gamma_{tot}(M=M*_{0}) vs p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS, 0.0, 4.0); TH1D *kstar0collWidth = new TH1D("kstar0collWidth", Form("Fit value of #Gamma_{coll} component vs. p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS,0.0, 4.0); TH1D *kstar0decWidth = new TH1D("kstar0decWidth", Form("#Gamma_{dec}(M=M*_{0}) component vs. p_{T} for %s;p_{T} (GeV/c);Width (GeV/c^2)", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS,0.0, 4.0); kstar0mass->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0mass->GetYaxis()->SetTitle("Mass (GeV/c^{2})"); kstar0width->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0width->GetYaxis()->SetTitle("Width (GeV/c^2)"); kstar0collWidth->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0collWidth->GetYaxis()->SetTitle("Width (GeV/c^2)"); kstar0mass->SetStats(kFALSE); kstar0width->SetStats(kFALSE); kstar0collWidth->SetStats(kFALSE); kstar0decWidth->SetStats(kFALSE); TF1 *massline = new TF1("massline", "[0]", 0.0, 4.0); massline->SetParameter(0, 0.892); massline->SetLineColor(2); massline->SetLineStyle(7); TF1 *widthline = new TF1("widthline", "[0]", 0.0, 4.0); widthline->SetParameter(0, 0.042); double mass = 0.0, width = 0.0, collWidth = 0.0, massBG=0.0; double massError = 0.0, widthError= 0.0, collWidthError = 0.0, massBGError=0.0; TCanvas *canvas[9]; TCanvas *diffCanvas[9]; TPaveStats *st; TPad *pad; //ofstream integrals; //integrals.open("kstarbar_integrals.txt"); for(int nfile = 0; nfile < NUM_PT_BINS; nfile++){ double meanPT = (double)(nfile*2+1)/10.0; string filename = folder+files[nfile]; string ptLower = filename.substr(filename.find("[")+1, 3); string ptHigher = filename.substr(filename.find(",")+1, 3); TH1D* histos[8]; TH1D* newHistos[8]; TH1D* diffHistos[8]; TH1D* bg[8]; for(int i=0; i<8; i++){ if(nfile<5){ histos[i] = new TH1D(Form("ptbin0%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), NUM_MASS_BINS, MASS_LOW, MASS_HIGH); newHistos[i] = new TH1D(Form("newptbin0%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), 250, MASS_LOW, MASS_HIGH); }else{ histos[i] = new TH1D(Form("ptbin%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), NUM_MASS_BINS, MASS_LOW, MASS_HIGH); newHistos[i] = new TH1D(Form("newptbin%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), 250, MASS_LOW, MASS_HIGH); } histos[i]->GetXaxis()->SetTitle("Invariant Mass (GeV/c^{2})"); histos[i]->GetYaxis()->SetTitle("Counts"); } ifstream input; input.open(filename.c_str()); string line = ""; if(input.good()){ getline(input, line); } double massBin=0.0; double invMass[8]; for(int i=0; i<8; i++){ invMass[i] = 0.0; } int lineNumber = 1; while(1){ input >> massBin >> invMass[0] >> invMass[1] >> invMass[2] >> invMass[3] >> invMass[4] >> invMass[5] >> invMass[6] >> invMass[7]; if(!input.good())break; for(int i =0; i<8; i++){ histos[i]->SetBinContent(lineNumber, invMass[i]/500.0); } if(lineNumber > 440 && lineNumber < 460 && nfile==6){ // printf("mass: %.12f invMass[6]: %.12f\n", massBin, invMass[6]); } lineNumber++; } printf("****** Fits for file: %s ******\n", filename.c_str()); for(int i=PARTICLE_NUM; i<PARTICLE_NUM+1; i++){ //add the K*0 distribution to the K*0bar (K*0 = 4 for decay, K*0 = 3 for reconstructed) histos[i]->Add(histos[3]); if(nfile==0){ canvas[i] = new TCanvas(Form("c%i", i),Form("c%i", i), 0,0,900,900); canvas[i]->Divide(5,4); diffCanvas[i] = new TCanvas(Form("diffC%i", i),Form("diffC%i", i), 0,0,900,900); diffCanvas[i]->Divide(5,4); } //rebin //histos[i]->Sumw2(); histos[i]->Rebin(4); //Fixing the errors to a percentage of the signal region: for(int ibin=1; ibin < histos[i]->GetNbinsX(); ibin++){ histos[i]->SetBinError(ibin, histos[i]->GetBinContent((int)(0.892*(250.0/2.0)))*0.05); newHistos[i]->SetBinContent(ibin, histos[i]->GetBinContent(ibin)); newHistos[i]->SetBinError(ibin, histos[i]->GetBinError(ibin)); } pad = (TPad*)canvas[i]->cd(nfile+1); histos[i]->SetLineColor(1); histos[i]->SetLineWidth(1); histos[i]->GetXaxis()->SetRangeUser(0.7, 1.2); histos[i]->GetYaxis()->SetRangeUser(0, 1.5*histos[i]->GetBinContent(histos[i]->GetMaximumBin())); //histos[i]->SetStats(kFALSE); //histos[i]->Draw("HIST"); printf("mean PT: %f\n", meanPT); TF1 *fit = new TF1(Form("fitPTbin%d00particle%d", nfile*2+1, i), FitFunRelBW, 0.68, 1.05, 5); //TF1 *fit = new TF1(Form("fitPTbin%d00particle%d", nfile*2+1, i), "gaus(0)", 0.86, 0.92); fit->SetParNames("BW Area", "Mass", "Width", "PT", "Temp"); fit->SetParameters(TMath::Power(10.0, (float)(nfile)/1.7), 0.89, 0.1, 0.5, 0.130); //fit->SetParNames("BW Area", "Mass", "Width"); //fit->SetParameters(100, 0.89, 0.0474); //fit->SetParLimits(0, -10, 1.5e9); Float_t max = histos[i]->GetXaxis()->GetBinCenter(histos[i]->GetMaximumBin()); //if(max < 0.91 && max > 0.892){ // fit->SetParLimits(1, max-0.001, max+0.001); //}else{ fit->SetParLimits(1, 0.82, 0.98); //} //fit->SetParLimits(2, 0.005, 0.15); fit->FixParameter(2, 0.042); fit->FixParameter(3, meanPT); //fit->SetParLimits(4, 0.05, 0.2); fit->FixParameter(4, 0.100001); fit->SetLineColor(2); printf("%s\n", fit->GetName()); histos[i]->Fit(Form("fitPTbin%d00particle%d", nfile*2+1, i), "BRIM", "SAME"); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); histos[i]->SetStats(1); histos[i]->Draw(); gPad->Update(); pad->Update(); st = (TPaveStats*)histos[i]->FindObject("stats"); st->SetX1NDC(0.524); st->SetY1NDC(0.680); st->SetX2NDC(0.884); st->SetY2NDC(0.876); //fit->Draw("SAME"); //histos[i]->Draw(); gPad->Update(); pad->Update(); printf("\n"); diffHistos[i] = (TH1D*)histos[i]->Clone(Form("diffPTbin%d00particl%d", nfile*2+1, i)); diffHistos[i]->Add(fit, -1); diffCanvas[i]->cd(nfile+1); diffHistos[i]->Draw("HIST E"); diffHistos[i]->Write(); //counting bins Float_t integral = histos[i]->Integral(1, 500)*500.0; //integrals << integral <<" \n"; histos[i]->Write(); fit->Write(); //Do mass and width vs. pT plots just for K*0 if(i==PARTICLE_NUM){ mass = fit->GetParameter(1); massError = fit->GetParError(1); collWidth = fit->GetParameter(2); collWidthError = fit->GetParError(2); width = Gamma(mass, collWidth); kstar0mass->SetBinContent(nfile+1, mass); kstar0mass->SetBinError(nfile+1, massError); kstar0width->SetBinContent(nfile+1, width); Double_t widthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1) + fitter->GetCovarianceMatrixElement(2,2) + 2.0*GammaDerivative(mass)*fitter->GetCovarianceMatrixElement(1,2)); kstar0width->SetBinError(nfile+1, widthError); kstar0collWidth->SetBinContent(nfile+1, collWidth); kstar0collWidth->SetBinError(nfile+1, collWidthError); kstar0decWidth->SetBinContent(nfile+1, width - collWidth); Double_t decWidthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1)); kstar0decWidth->SetBinError(nfile+1, decWidthError); if(nfile==4){ TCanvas *singlecanvas = new TCanvas("singlecanvas", "singlecanvas", 0,0,600,600); singlecanvas->cd(); printf("Got here! \n"); histos[i]->Draw("HIST E SAME"); fit->SetLineColor(8); fit->SetLineStyle(1); fit->Draw("SAME"); if(fitter){ printf("sig11: %f, sig12: %f, sig21: %f, sig22: %f GammaDer(0.8): %f GammaDer(0.85): %f GammaDer(0.9): %f\n", TMath::Sqrt(fitter->GetCovarianceMatrixElement(1,1)), fitter->GetCovarianceMatrixElement(2,1), fitter->GetCovarianceMatrixElement(1,2), TMath::Sqrt(fitter->GetCovarianceMatrixElement(2,2)), GammaDerivative(0.8), GammaDerivative(0.85), GammaDerivative(0.9)); } } } } printf("************************************************************\n"); } //integrals.close(); /* TH2D *gammaPlot = new TH2D("gammaPlot", "#Gamma_{tot}(M_{0}*);M_{0}*;#Gamma_{coll};#Gamma_{tot}", 100, 0.82, 0.9, 100, 0.0, 0.08); for(int im = 0; im<100; im++){ for(int ig = 0; ig < 100; ig++){ gammaPlot->SetBinContent(im+1, ig+1, Gamma(((0.9-0.82)/(100.0))*((double)(im)) + 0.82, ((0.08)/100.0)*((double)(ig)))); } } TH1D *gammaMassDpnd = gammaPlot->ProjectionX("gammaMassDpnd"); */ TCanvas *masscanvas = new TCanvas("masscanvas", "masscanvas", 50,50, 600, 600); masscanvas->cd(); kstar0mass->Draw(); massline->Draw("SAME"); masscanvas->Write(); for(int i=PARTICLE_NUM; i<PARTICLE_NUM+1; i++){ canvas[i]->Write(); } kstar0mass->Write(); kstar0collWidth->Write(); kstar0decWidth->Write(); kstar0width->Write(); // gammaPlot->Write(); // gammaMassDpnd->Write(); }
TF1* fitDstar3prongs(TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax) { static int count3p=0; count3p++; TCanvas* c = new TCanvas(Form("c_3p_%d",count3p),"",600,600); TH1D* h = new TH1D(Form("h_3p_%d",count3p),"",60,0.14,0.16); TH1D* hMCSignal = new TH1D(Form("hMCSignal_3p_%d",count3p),"",60,0.14,0.16); TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_3p_%d",count3p),"",60,0.14,0.16); TF1* f = new TF1(Form("f_3p_%d",count3p),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*([12]*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10])+(1-[12])*Gaus(x,[1],[13])/(sqrt(2*3.14159)*[13])))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x+[11]*x*x*x*x",0.14,0.16); f->SetLineColor(kRed); nt->Project(Form("h_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata3p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); ntMC->Project(Form("hMCSignal_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23333))",weight.Data(),selmc3p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); ntMC->Project(Form("hMCSwapped_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23344))",weight.Data(),selswp3p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); f->FixParameter(7,1.); f->FixParameter(1,0.145491); f->FixParameter(2,2.e-3); f->FixParameter(10,5.e-4); f->FixParameter(13,1.e-4); f->FixParameter(3,0.); f->FixParameter(4,0.); f->FixParameter(5,0.); f->FixParameter(6,0.); f->FixParameter(11,0.); f->SetParLimits(9,0,1); f->SetParLimits(12,0,1); f->SetParLimits(0,0,1000000); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL"); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL"); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.142,0.155); f->ReleaseParameter(1); f->ReleaseParameter(2); f->ReleaseParameter(10); f->ReleaseParameter(13); f->SetParLimits(1,0.144,0.147); if(isData==0||isData==2) f->SetParLimits(2,5.e-4,5.e-3); else f->SetParLimits(2,5.e-4,7.e-3); f->SetParLimits(10,1.e-4,2.e-3); if(isData==0||isData==2) f->SetParLimits(13,5.e-5,3.e-4); else if(ptmin>20) f->SetParLimits(13,5.e-5,4.e-4); else f->SetParLimits(13,5.e-5,5.e-4); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.143,0.147); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(13,f->GetParameter(13)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(12,f->GetParameter(12)); f->FixParameter(7,0); f->SetParLimits(8,2.e-4,2.e-3); hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16); hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->ReleaseParameter(11); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); f->ReleaseParameter(1); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); TF1* background = new TF1(Form("background_3p_%d",count3p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetParameter(4,f->GetParameter(11)); background->SetLineColor(4); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_3p_%d",count3p),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*([6]*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])+(1-[6])*Gaus(x,[1],[7])/(sqrt(2*3.14159)*[7]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(12),f->GetParameter(13)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetParError(6,f->GetParError(12)); mass->SetParError(7,f->GetParError(13)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); h->SetXTitle("M_{K#pi#pi}-M_{K#pi} (GeV/c^{2})"); h->SetYTitle("Entries / (1/3 MeV/c^{2})"); h->SetStats(0); h->SetAxisRange(1,h->GetMaximum()*1.3,"Y"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(0.142,0.152); mass->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(0.14,0.16)/binwidth3prong; Double_t yieldErr = mass->Integral(0.14,0.16)/binwidth3prong*mass->GetParError(0)/mass->GetParameter(0); TLatex* tex; TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry((TObject*)0,"D* D^{0}(K#pi)#pi",NULL); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.20,0.79,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); c->SaveAs(Form("plots/pp/DMass_%s_3prongs-%d.pdf",texData[isData].Data(),count3p)); return mass; }
void alicePlots(){ TFile* alice = new TFile("~/Downloads/HEPData-ins1288320-v1-root.root"); alice->cd("Table 16"); TGraph* aliceData = Graph1D_y1; TH1F* hist = Hist1D_y1; TH1F* stat = Hist1D_y1_e1; TH1F* syst = Hist1D_y1_e2; TGraphAsymmErrors* graph2 = (TGraphAsymmErrors*)aliceData->Clone("graph2"); Int_t numPts = aliceData->GetN(); Double_t x, y; for(int i = 0; i<numPts; i++){ aliceData->GetPoint(i, x, y); aliceData->SetPoint(i, x, (y - 0.89581)); graph2->SetPoint(i, x, (y- 0.89581)); hist->SetBinContent(i+1, hist->GetBinContent(i+1) - 0.89581); hist->SetBinError(i+1, stat->GetBinContent(i+1)); graph2->SetPointEXhigh(i, 0.1); graph2->SetPointEXlow(i, 0.1); } graph2->SetLineColor(kBlue-10); graph2->SetLineWidth(2); graph2->SetMarkerColor(kBlue-10); graph2->SetFillColor(kBlue-10); hist->SetLineColor(kBlue-2); hist->SetLineWidth(2); aliceData->SetTitle(""); aliceData->GetYaxis()->SetTitle("Mass - Vacuum Mass (GeV/c^{2})"); aliceData->GetYaxis()->SetTitleSize(0.06); aliceData->GetYaxis()->SetLabelSize(0.04); aliceData->GetYaxis()->SetTitleOffset(1.65); aliceData->GetYaxis()->SetTitleFont(42); aliceData->GetYaxis()->SetLabelFont(42); aliceData->GetXaxis()->SetTitle("p_{T} (GeV/c)"); aliceData->GetXaxis()->SetTitleSize(0.06); aliceData->GetXaxis()->SetLabelSize(0.05); aliceData->GetXaxis()->SetTitleFont(42); aliceData->GetXaxis()->SetLabelFont(42); aliceData->SetMarkerStyle(29); aliceData->SetMarkerSize(2.5); aliceData->SetMarkerColor(kBlue-2); aliceData->SetLineColor(kBlue-2); aliceData->GetYaxis()->SetRangeUser(-0.02, 0.015); aliceData->GetXaxis()->SetRangeUser(0, 5); TFile* phsd = new TFile("~/utaustin/resonancefits/finalplotting/20170721_KKbarAdded2_fixedwidth42_recon_pf100_scaled_error05.root"); TH1D* mass = phsd->Get("kstar0mass"); mass->SetName("mass"); mass->SetMarkerStyle(26); mass->SetMarkerSize(2.5); mass->SetMarkerColor(2); mass->SetLineColor(2); TF1* line = new TF1("line", "[0]", 0.0, 5.0); line->SetParameter(0, 0.0); line->SetLineColor(1); line->SetLineStyle(7); line->SetLineWidth(3); for(int j = 0; j<mass->GetNbinsX(); j++){ mass->SetBinContent(j+1, (mass->GetBinContent(j+1) - 0.892)); } TFile* phsd2 = new TFile("~/utaustin/resonancefits/finalplotting/20170616_KKbarAdded2_fixedwidth_recon_pf100_scaled_error05.root"); TH1D* mass2 = phsd2->Get("kstar0mass"); mass2->SetName("mass2"); mass2->SetMarkerStyle(22); mass2->SetMarkerSize(2.5); mass2->SetMarkerColor(2); mass2->SetLineColor(2); for(int j = 0; j<mass2->GetNbinsX(); j++){ mass2->SetBinContent(j+1, (mass2->GetBinContent(j+1) - 0.892)); } TExec *exec1 = new TExec("exec1", "gStyle->SetErrorX(0.1)"); TExec *exec2 = new TExec("exec2", "gStyle->SetErrorX(0.5)"); TCanvas *c = new TCanvas ("c", "c", 50, 50, 650, 600); c->cd()->SetMargin(0.1997, 0.0369, 0.1396, 0.0681); aliceData->Draw("APX"); //exec1->Draw(); graph2->Draw("SAME P2"); //exec2->Draw(); hist->Draw("SAME E1"); line->Draw("SAME"); mass2->Draw("SAME P E1"); mass->Draw("SAME P E1"); aliceData->Draw("SAME PX"); TLegend* legend = new TLegend(0.5836, 0.1815, 0.9489, 0.3438); legend->SetMargin(0.2); legend->SetTextSizePixels(20); legend->AddEntry(aliceData, "ALICE data, 0-20%", "p"); legend->AddEntry(mass2, "Fit IV to PHSD: w in-med", "p"); legend->AddEntry(mass, "Fit IV to PHSD: w/o in-med", "p"); legend->Draw("SAME"); TPaveText* text = new TPaveText(0.2554, 0.7243, 0.6006, 0.9162, "NDC"); text->AddText("(K*^{0} + #bar{K}*^{0})"); text->AddText("Pb-Pb #sqrt{s_{NN}} = 2.76 TeV"); text->GetLine(0)->SetTextSizePixels(36); text->GetLine(1)->SetTextSizePixels(24); text->SetTextFont(42); text->SetBorderSize(0); text->SetFillStyle(0); text->Draw(); }
TF1* fitDstar(TTree* nt, TTree* ntMC, Float_t ptmin, Bool_t plotgenmatch) { TCanvas* c = new TCanvas(Form("c_5p_%.0f",ptmin),"",600,600); TH1D* h = new TH1D(Form("h_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSignal = new TH1D(Form("hMCSignal_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSignalplot = new TH1D(Form("hMCSignalplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSwappedplot = new TH1D(Form("hMCSwappedplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TF1* f = new TF1(Form("f_5p_%.0f",ptmin),"[0]*([4]*([6]*([12]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[12])*Gaus(x,[1],[11])/(sqrt(2*3.14159)*[11]))+(1-[6])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5]))+(1-[4])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3]))+[10]*((1-exp((0.13957-x)/[7]))*pow(x/0.13957,[8])+[9]*(x/0.13957-1))",BINMIN,BINMAX); nt->Project(Form("h_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightdata[isData].Data(),seldata5p[isData].Data(),triggerselectiondata[isData].Data(),ptmin)); ntMC->Project(Form("hMCSignal_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selmc5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin)); ntMC->Project(Form("hMCSwapped_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selswp5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin)); for(int ibin=0;ibin<BINNUM;ibin++) hMCSignalplot->SetBinContent(ibin+1,hMCSignal->GetBinContent(ibin+1)); for(int ibin=0;ibin<BINNUM;ibin++) hMCSwappedplot->SetBinContent(ibin+1,hMCSwapped->GetBinContent(ibin+1)); f->FixParameter(4,1.); f->FixParameter(1,0.145491); f->FixParameter(10,0); f->SetParLimits(0,0,1.e+5); f->SetParLimits(6,0,1.); f->SetParLimits(12,0,1.); f->SetParLimits(2,3.e-4,1.e-3); f->SetParameter(2,5.e-4); f->SetParLimits(11,1.6e-4,3.e-4);//1.5e-4 keyong f->SetParameter(11,2.e-4); f->SetParLimits(5,1.e-3,1.6e-3); f->SetParameter(5,1.e-3); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); f->ReleaseParameter(1); f->SetParLimits(1,minmass,maxmass); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(5,f->GetParameter(5)); f->FixParameter(11,f->GetParameter(11)); f->FixParameter(6,f->GetParameter(6)); f->FixParameter(12,f->GetParameter(12)); f->FixParameter(4,0); f->SetParLimits(3,2.e-4,2.e-3); f->SetParameter(3,1.e-3); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass); f->FixParameter(4,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(3,f->GetParameter(3)); f->SetParLimits(7,5.e-4,1.e-2); f->SetParameter(7,1.6e-3); f->SetParLimits(8,0.,15.); f->SetParameter(8,0.35); f->SetParLimits(9,-2.e+1,2.e+1); f->SetParameter(9,13.); f->ReleaseParameter(10); f->SetParLimits(10,0,1.e+6); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); f->ReleaseParameter(1); f->SetParLimits(1,minmass,maxmass); f->SetParameter(1,f->GetParameter(1)); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); TF1* background = new TF1(Form("background_5p_%.0f",ptmin),"[3]*((1-exp((0.13957-x)/[0]))*pow(x/0.13957,[1])+[2]*(x/0.13957-1))"); background->SetParameters(f->GetParameter(7),f->GetParameter(8),f->GetParameter(9),f->GetParameter(10)); background->SetRange(BINMIN,BINMAX); background->SetLineColor(4); background->SetLineWidth(3); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_5p_%.0f",ptmin),"[0]*[3]*([5]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))+(1-[5])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(4),f->GetParameter(5),f->GetParameter(6),f->GetParameter(11),f->GetParameter(12)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(4)); mass->SetParError(4,f->GetParError(5)); mass->SetParError(5,f->GetParError(6)); mass->SetRange(BINMIN,BINMAX); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap_5p_%.0f",ptmin),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(4),f->GetParameter(3)); massSwap->SetRange(BINMIN,BINMAX); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})"); h->SetYTitle("Entries / (0.4 MeV/c^{2})"); h->SetStats(0); h->SetAxisRange(0,h->GetMaximum()*1.3,"Y"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); mass->Draw("same"); massSwap->Draw("same"); background->Draw("same"); f->Draw("same"); if(plotgenmatch&&(isData==MC_MB||isData==MC)) { hMCSignalplot->SetMarkerSize(0.8); hMCSignalplot->SetMarkerColor(kMagenta+2); hMCSignalplot->Draw("psame"); hMCSwappedplot->SetMarkerSize(0.8); hMCSwappedplot->SetMarkerColor(kGray+2); hMCSwappedplot->Draw("psame"); } Float_t yield = mass->Integral(BINMIN,BINMAX)/BINWID; Float_t yieldErr = mass->Integral(BINMIN,BINMAX)/BINWID*mass->GetParError(0)/mass->GetParameter(0); cout<<mass->GetParameter(0)<<" "<<mass->Integral(BINMIN,BINMAX)<<endl; TLatex* tex; TLegend* leg = new TLegend(0.60,0.57,0.85,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); tex = new TLatex(0.61,0.52,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.20,0.79,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.20,0.84,Form("p_{T} > %.1f GeV/c",ptmin)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); c->SaveAs(Form("plots/pp/fitDstar5p/DMass_%s_%.0f.pdf",texData[isData].Data(),ptmin)); return mass; }
void fitMKGaus_wPOINTERS(TH1D *h33 , Double_t low, Double_t high, Double_t p0, Double_t p1, Double_t p2, Double_t p3, Double_t initialPar, Double_t width, Double_t factor, Int_t draw_opt, Int_t *fitted_yield, Int_t *fitted_bckgrd, Double_t *fitted_mean, Double_t *fitted_meanerror, Double_t *fitted_sigma, Double_t *fitted_sigmaerror, Double_t *fitted_ratio ){//Double_t *array[8] double nEnt = h33->GetEntries(); TF1 *fitter = new TF1("fitter","gaus + [3] + [4]*x + [5]*x*x + [6]*x*x*x",low,high); fitter->SetParameters(100, initialPar, width, p0, p1, p2, p3); fitter->SetParLimits(0,10,nEnt); fitter->SetParLimits(1,initialPar-width,initialPar+width); h33->Fit("fitter","REM","same"); //h33->Draw("E"); TF1 *backFcn = new TF1("backFcn", "pol3",low,high); TF1 *signalFcn = new TF1("signalFcn", "gaus",low,high); signalFcn->SetLineColor(2); signalFcn->SetLineWidth(2); Double_t par[7]; fitter->GetParameters(par); backFcn->SetParameters(&par[3]); backFcn->SetLineStyle(2); backFcn->SetLineColor(6); backFcn->SetLineWidth(1); signalFcn->SetParameters(par); signalFcn->SetLineStyle(2); signalFcn->SetLineColor(4); signalFcn->SetLineWidth(1); backFcn->Draw("same"); signalFcn->Draw("same"); Double_t Intg = signalFcn->Integral(par[1]-factor*par[2],par[1]+factor*par[2]); Double_t Intb = backFcn->Integral(par[1]-factor*par[2],par[1]+factor*par[2]); Double_t binw = h33->GetBinWidth(1); Int_t yield = Intg/binw; Int_t bckgd = Intb/binw; Double_t ratio = double(yield)/TMath::Sqrt(double(bckgd)); cout << yield << "\t" << ratio << endl; TAxis *x=h33->GetXaxis(); TAxis *y=h33->GetYaxis(); Double_t startx=x->GetXmin()+0.75*(x->GetXmax()-x->GetXmin()); Double_t starty0=0.35*h33->GetMaximum(); Double_t starty1=0.45*h33->GetMaximum(); Double_t starty2=0.55*h33->GetMaximum(); Double_t starty3=0.65*h33->GetMaximum(); Double_t starty4=0.75*h33->GetMaximum(); Double_t starty5=0.85*h33->GetMaximum(); double meanError = fitter->GetParError(1); double sigmaError = fitter->GetParError(2); if (draw_opt ==1) { TLatex *sum = new TLatex(startx*0.93, starty5,Form("Yield: %i",yield)); TLatex *sum12 = new TLatex(startx*0.93, starty4,Form("Background: %i",bckgd)); TLatex *sum0=new TLatex(startx*0.93, starty3,Form("Range: #pm %2.1f #sigma",factor)); TLatex *sum2=new TLatex(startx*0.93, starty2,Form("Mean:%4.4f #pm %.4f GeV",par[1], meanError)); TLatex *sum3=new TLatex(startx*0.93, starty1,Form("#sigma:%5.4f #pm %.4f GeV",par[2], sigmaError)); TLatex *ra = new TLatex(startx*0.93, starty0,Form("#frac{S}{#sqrt{B}}= %.1f", ratio)); sum->SetTextSize(0.04); sum->SetTextColor(2); sum->Draw("same"); sum12->SetTextSize(0.04); sum12->SetTextColor(6); sum12->Draw("same"); ra->SetTextSize(0.04); ra->Draw("same"); sum0->SetTextSize(0.04); sum0->SetTextColor(2); sum0->Draw("same"); sum2->SetTextSize(0.04); sum2->SetTextColor(4); sum2->Draw("same"); sum3->SetTextSize(0.04); sum3->SetTextColor(4); sum3->Draw("same"); } (*fitted_yield) = yield; (*fitted_bckgrd) = bckgd; (*fitted_mean) = par[1]; (*fitted_meanerror) = meanError; (*fitted_sigma) = par[2]; (*fitted_sigmaerror) = sigmaError; (*fitted_ratio) =ratio; // (*array[0]) = yield; (*array[1]) = bckgd); (*array[2]) = factor; (*array[3]) = par[1]; (*array[4]) = meanError; // (*array[5]) = par[2]; (*array[6]) = sigmaError; (*array[7]) = ratio; // // for (Int_t cnt = 0; cnt < 7; cnt++) { // cout<<array[cnt]<<endl; // } // h33->GetXaxis()->SetTitle("M(e^{+}e^{-}#gamma) [GeV]"); // h33->GetYaxis()->SetTitleOffset(1.2); // // h33->GetYaxis()->SetTitle("Entries / 6 MeV"); //can1->Print("/Volumes/Mac_Storage/Physics_Papers/Annual_Review_Paper/ODU_Group_Pres/PLOTS_for_Review/New_Mass_Plots/etaprime.pdf") }
void massfitvn_Jpsi() { double fit_range_low = 2.6; double fit_range_high = 3.5; double JPsi_mass = 3.097; int npt = 7; TFile* file1 = TFile::Open("HM185_JpsivnHist_etagap1p5_v30_eff_extdeta.root"); TFile ofile("v2vspt_fromfit_jpsi_HM185_250_deta1p5_doubleCB_v30_eff_exp_extdeta.root","RECREATE"); //v12 double alpha_fit[14] = {4.30986,3.50841,3.03436,2.73741,2.37934,2.10685,2.03615}; double n_fit[14] = {1.88853,1.9839,2.03198,2.07295,2.11001,2.15234,2.10154}; TF1* fmasssig[9]; TF1* fmassbkg[9]; TF1* fmasstotal[9]; TF1* fvn[9]; double pt[13]; double KET_ncq[13]; double v2[13]; double v2e[13]; double v2_bkg[13]; double v2_ncq[13]; double v2e_ncq[13]; double ptbin[14] = {0.2, 1.8, 3.0, 4.5, 6.0, 8.0, 10, 20}; double a[13]; double b[13]; double sigfrac[13]; TCanvas* c[10]; for(int i=0;i<npt;i++) { c[i] = new TCanvas(Form("c_%d",i),Form("c_%d",i),800,400); c[i]->Divide(2,1); } for(int i=0;i<npt;i++) { c[i]->cd(1)->SetTopMargin(0.06); c[i]->cd(1)->SetLeftMargin(0.18); c[i]->cd(1)->SetRightMargin(0.043); c[i]->cd(1)->SetBottomMargin(0.145); c[i]->cd(2)->SetTopMargin(0.06); c[i]->cd(2)->SetLeftMargin(0.18); c[i]->cd(2)->SetRightMargin(0.043); c[i]->cd(2)->SetBottomMargin(0.145); } TCanvas* c2 = new TCanvas("c2","c2",100,100); TLatex* tex = new TLatex; tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); TLatex* texCMS = new TLatex; texCMS->SetNDC(); texCMS->SetTextFont(42); texCMS->SetTextSize(0.05); texCMS->SetTextAlign(12); TH1D* hist = new TH1D("hist","",10,2.6,3.5); hist->SetLineWidth(0); //hist->GetYaxis()->SetRangeUser(0,0.3); hist->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)"); hist->GetYaxis()->SetTitle("v_{2}^{S+B}"); hist->GetXaxis()->CenterTitle(); hist->GetYaxis()->CenterTitle(); hist->GetXaxis()->SetTitleOffset(1.3); hist->GetYaxis()->SetTitleOffset(2); hist->GetXaxis()->SetLabelOffset(0.007); hist->GetYaxis()->SetLabelOffset(0.007); hist->GetXaxis()->SetTitleSize(0.045); hist->GetYaxis()->SetTitleSize(0.045); hist->GetXaxis()->SetTitleFont(42); hist->GetYaxis()->SetTitleFont(42); hist->GetXaxis()->SetLabelFont(42); hist->GetYaxis()->SetLabelFont(42); hist->GetXaxis()->SetLabelSize(0.04); hist->GetYaxis()->SetLabelSize(0.04); hist->SetMinimum(0.01); hist->SetMaximum(0.33); c2->cd(); hist->Draw(); for(int i=0;i<npt;i++) { TH1D* h_data = (TH1D*)file1->Get(Form("massjpsi_pt%d",i)); h_data->SetMinimum(0); h_data->SetMarkerSize(0.8); h_data->SetMarkerStyle(20); h_data->SetLineWidth(1); h_data->SetOption("e"); h_data->Rebin(2); h_data->GetXaxis()->SetRangeUser(2.6,3.5); h_data->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)"); h_data->GetYaxis()->SetTitle("Entries / 10 MeV"); h_data->GetXaxis()->CenterTitle(); h_data->GetYaxis()->CenterTitle(); h_data->GetXaxis()->SetTitleOffset(1.3); h_data->GetYaxis()->SetTitleOffset(2); h_data->GetXaxis()->SetLabelOffset(0.007); h_data->GetYaxis()->SetLabelOffset(0.007); h_data->GetXaxis()->SetTitleSize(0.045); h_data->GetYaxis()->SetTitleSize(0.045); h_data->GetXaxis()->SetTitleFont(42); h_data->GetYaxis()->SetTitleFont(42); h_data->GetXaxis()->SetLabelFont(42); h_data->GetYaxis()->SetLabelFont(42); h_data->GetXaxis()->SetLabelSize(0.04); h_data->GetYaxis()->SetLabelSize(0.04); h_data->GetXaxis()->SetNoExponent(true); ((TGaxis*)h_data->GetXaxis())->SetMaxDigits(7); h_data->SetMaximum(h_data->GetMaximum()*1.5); TH1D* h_pt = (TH1D*)file1->Get(Form("Ptjpsi_eff_pt%d",i)); TH1D* h_KET = (TH1D*)file1->Get(Form("KETjpsi_eff_pt%d",i)); pt[i] = h_pt->GetMean(); KET_ncq[i] = h_KET->GetMean()/2.0; c[i]->cd(1); /*p definitions [0] CB1 yield; [1] Common mean of CB and Gaus; [2] CB1 sigma; [3] CB n; [4] CB alpha; [5] CB2 yield; [6] CB2 sigma; [7-10] poly 3; [11] v2 signal; [12-13] v2 bkg; */ TF1* f = new TF1(Form("f_%d",i), crystalball_function_total, fit_range_low, fit_range_high, 11); f->SetLineColor(2); f->SetLineWidth(1); f->SetParNames("CB1_Yield","common_mean","CB1_sigma","CB_N","CB_Alpha","CB2_Yield","CB2_Sigma","Pol0","Pol1","Pol2","Pol3"); //first fit data mass signal + bkg f->SetParameter(0,10000.); f->SetParameter(1,JPsi_mass); f->SetParameter(2,0.03); f->SetParameter(3,1.0); f->SetParameter(4,1.0); f->SetParameter(5,10000); f->SetParameter(6,0.03); f->SetParLimits(2,0.01,0.1); f->SetParLimits(6,0.01,0.1); //fix alpha & n from MC f->FixParameter(4,alpha_fit[i]); f->FixParameter(3,n_fit[i]); f->FixParameter(1,JPsi_mass); //for first few attempt fix mean of gaussian to get reasonable estimation of other pars; later open it up h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high); f->ReleaseParameter(1); //now let gaussian mean float h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"L m","",fit_range_low,fit_range_high); //draw D0 signal separately TF1* f1 = new TF1(Form("f_sig_%d",i), crystalball_function_signal, fit_range_low, fit_range_high, 7); f1->SetLineColor(kOrange-3); f1->SetLineWidth(1); f1->SetLineStyle(2); f1->SetFillColorAlpha(kOrange-3,0.3); f1->SetFillStyle(1001); f1->FixParameter(0,f->GetParameter(0)); f1->FixParameter(1,f->GetParameter(1)); f1->FixParameter(2,f->GetParameter(2)); f1->FixParameter(3,f->GetParameter(3)); f1->FixParameter(4,f->GetParameter(4)); f1->FixParameter(5,f->GetParameter(5)); f1->FixParameter(6,f->GetParameter(6)); fmasssig[i] = (TF1*)f1->Clone(); fmasssig[i]->SetName(Form("masssigfcn_pt%d",i)); fmasssig[i]->Write(); f1->Draw("LSAME"); //draw poly bkg separately TF1* f3 = new TF1(Form("f_bkg_%d",i),"[7] + [8]*x + [9]*x*x + [10]*x*x*x", fit_range_low, fit_range_high); f3->SetLineColor(4); f3->SetLineWidth(1); f3->SetLineStyle(2); f3->FixParameter(7,f->GetParameter(7)); f3->FixParameter(8,f->GetParameter(8)); f3->FixParameter(9,f->GetParameter(9)); f3->FixParameter(10,f->GetParameter(10)); fmassbkg[i] = (TF1*)f3->Clone(); fmassbkg[i]->SetName(Form("massbkgfcn_pt%d",i)); fmassbkg[i]->Write(); f3->Draw("LSAME"); tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250"); tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1])); tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94"); texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}"); //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}"); texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}"); TLegend* leg = new TLegend(0.21,0.4,0.5,0.65,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.045); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h_data,"data","p"); leg->AddEntry(f,"Fit","L"); leg->AddEntry(f1,"J/#psi Signal","f"); leg->AddEntry(f3,"Combinatorial","l"); leg->Draw("SAME"); sigfrac[i] = f1->Integral(2.94,3.24)/f->Integral(2.94,3.24); //c->Print(Form("plots/massfit_pt%d.pdf",i)); //fit vn //[9] is vn_sig //[10-11] is vn bkg, const + linear vn(pT) TGraphErrors* vn_data = (TGraphErrors*)file1->Get(Form("v2_mass_pt%d",i)); c[i]->cd(2); hist->Draw(); TF1* fmass_combinemassvnfit = new TF1(Form("fmass_combinemassvnfit_%d",i),crystalball_function_total, fit_range_low, fit_range_high, 11); TF1* fvn_combinemassvnfit = new TF1(Form("fvn_combinemassvnfit_%d",i), crystalball_function_v2, fit_range_low, fit_range_high, 15); fmass_combinemassvnfit->SetLineColor(2); fmass_combinemassvnfit->SetLineWidth(1); fvn_combinemassvnfit->SetLineColor(2); fvn_combinemassvnfit->SetLineWidth(1); ROOT::Math::WrappedMultiTF1 wfmass_combinemassvnfit(*fmass_combinemassvnfit,1); ROOT::Math::WrappedMultiTF1 wfvn_combinemassvnfit(*fvn_combinemassvnfit,1); ROOT::Fit::DataOptions opt; ROOT::Fit::DataRange range_massfit; range_massfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datamass(opt,range_massfit); ROOT::Fit::FillData(datamass, h_data); ROOT::Fit::DataRange range_vnfit; range_vnfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datavn(opt,range_vnfit); ROOT::Fit::FillData(datavn, vn_data); ROOT::Fit::Chi2Function chi2_B(datamass, wfmass_combinemassvnfit); ROOT::Fit::Chi2Function chi2_SB(datavn, wfvn_combinemassvnfit); GlobalChi2_poly3bkg_floatwidth globalChi2(chi2_B, chi2_SB); ROOT::Fit::Fitter fitter; const int Npar = 15; double par0[Npar]; for( int ipar = 0; ipar < f->GetNpar(); ipar++ ) par0[ipar] = f->GetParameter(ipar); par0[11] = 0.01; par0[12] = 0.10; par0[13] = 0.05; par0[14] = 0.01; fitter.Config().SetParamsSettings(Npar,par0); // fix parameter fitter.Config().ParSettings(0).Fix(); fitter.Config().ParSettings(1).Fix(); fitter.Config().ParSettings(2).Fix(); fitter.Config().ParSettings(3).Fix(); fitter.Config().ParSettings(4).Fix(); fitter.Config().ParSettings(5).Fix(); fitter.Config().ParSettings(6).Fix(); fitter.Config().ParSettings(7).Fix(); fitter.Config().ParSettings(8).Fix(); fitter.Config().ParSettings(9).Fix(); fitter.Config().ParSettings(10).Fix(); fitter.Config().MinimizerOptions().SetPrintLevel(0); fitter.Config().SetMinimizer("Minuit2","Migrad"); fitter.FitFCN(Npar,globalChi2,0,datamass.Size()+datavn.Size(),true); ROOT::Fit::FitResult result = fitter.Result(); result.Print(std::cout); fmass_combinemassvnfit->SetFitResult( result, iparmassfit_poly3bkg_floatwidth); fmass_combinemassvnfit->SetRange(range_massfit().first, range_massfit().second); fmass_combinemassvnfit->SetLineColor(kRed); h_data->GetListOfFunctions()->Add(fmass_combinemassvnfit); //c->cd(); //h_data->Draw(); fvn_combinemassvnfit->SetFitResult( result, iparvnfit_poly3bkg_floatwidth); fvn_combinemassvnfit->SetRange(range_vnfit().first, range_vnfit().second); fvn_combinemassvnfit->SetLineColor(2); //fvn_combinemassvnfit->SetLineStyle(2); vn_data->GetListOfFunctions()->Add(fvn_combinemassvnfit); vn_data->SetTitle(""); vn_data->SetMarkerSize(0.8); vn_data->SetLineWidth(1); //c1->cd(); vn_data->Draw("PESAME"); fvn[i] = (TF1*)fvn_combinemassvnfit->Clone(); fvn[i]->SetName(Form("vnfit_pt%d",i)); fvn[i]->Write(); fmasstotal[i] = (TF1*)fmass_combinemassvnfit->Clone(); fmasstotal[i]->SetName(Form("masstotalfcn_pt%d",i)); fmasstotal[i]->Write(); tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250"); tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1])); //tex->DrawLatex(0.22,0.74,"1.4 < |y_{cm}+0.46| < 2.4"); tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94"); //tex->DrawLatex(0.22,0.68,"|#Delta#eta| > 2"); //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}"); texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}"); texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}"); v2[i] = fvn_combinemassvnfit->GetParameter(11); v2e[i] = fvn_combinemassvnfit->GetParError(11); v2_bkg[i] = fvn_combinemassvnfit->GetParameter(12) + fvn_combinemassvnfit->GetParameter(13) * JPsi_mass; v2_ncq[i] = v2[i]/2.0; v2e_ncq[i] = v2e[i]/2.0; a[i] = fvn_combinemassvnfit->GetParameter(12); b[i] = fvn_combinemassvnfit->GetParameter(13); TF1* fvnbkg = new TF1(Form("fvnbkg_%d",1),"( [0] + [1] * x)", fit_range_low, fit_range_high); fvnbkg->FixParameter(0,fvn_combinemassvnfit->GetParameter(12)); fvnbkg->FixParameter(1,fvn_combinemassvnfit->GetParameter(13)); fvnbkg->SetName(Form("fvnbkg_fcn_pt%d",i)); fvnbkg->Write(); fvnbkg->SetLineStyle(7); //fvnbkg->Draw("LSAME"); TF1* fvnsig = new TF1(Form("fvnsig_%d",i),function_v2_sig,fit_range_low,fit_range_high,12); for(int k=0;k<12;k++) { fvnsig->FixParameter(k,fvn_combinemassvnfit->GetParameter(k)); } fvnsig->SetLineColor(kOrange-3); fvnsig->SetLineWidth(1); fvnsig->SetLineStyle(2); fvnsig->SetFillColorAlpha(kOrange-3,0.3); fvnsig->SetFillStyle(1001); //fvnsig->Draw("LSAME"); TLegend* leg1 = new TLegend(0.72,0.525,0.91,0.65,NULL,"brNDC"); leg1->SetBorderSize(0); leg1->SetTextSize(0.045); leg1->SetTextFont(42); leg1->SetFillStyle(0); leg1->AddEntry(h_data,"data","p"); leg1->AddEntry(fvn_combinemassvnfit,"Fit","l"); //leg1->AddEntry(fvnsig,"#alpha(#it{m}_{#mu#mu})v_{2}^{S}","f"); leg1->Draw("SAME"); double xmass[200]; double pullmass[200]; float Chi2=0; int ndf = (fit_range_high - fit_range_low)/0.01 - 8; for(int k=0;k<h_data->GetNbinsX();k++) { xmass[k] = h_data->GetBinCenter(k); pullmass[k] = (h_data->GetBinContent(k) - fmass_combinemassvnfit->Eval(xmass[k]))/h_data->GetBinError(k); if(fabs(pullmass[k])<5) { //cout<<pullmass[k]<<endl; Chi2 += pullmass[k]*pullmass[k]; } } c[i]->cd(1); tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.0f/%d",Chi2,ndf)); double xv2[200]; double pullv2[200]; double v2y[200]; float Chi2v2=0; int ndfv2 = 8 - 4; //Nbin - Npar for(int k=0;k<vn_data->GetN()-1;k++) { vn_data->GetPoint(k,xv2[k],v2y[k]); //xv2[k] = vn_dara->GetBinCenter(k); pullv2[k] = (v2y[k] - fvn_combinemassvnfit->Eval(xv2[k]))/vn_data->GetErrorY(k); cout<<k<<": "<<pullv2[k]<<endl; if(fabs(pullv2[k])<1000) { //cout<<pullmass[k]<<endl; Chi2v2 += pullv2[k]*pullv2[k]; } cout<<"fcn: "<<fvn_combinemassvnfit->Eval(xv2[k])<<endl; cout<<"data: "<<v2y[k]<<endl; } c[i]->cd(2); tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.1f/%d",Chi2v2,ndfv2)); } for(int i=0;i<npt;i++) { c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.pdf",i)); c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.gif",i)); } TGraphErrors* v2plot = new TGraphErrors(npt,pt,v2,0,v2e); TGraphErrors* v2ncqplot = new TGraphErrors(npt,KET_ncq,v2_ncq,0,v2e_ncq); TGraphErrors* v2bkgplot = new TGraphErrors(npt,pt,v2_bkg,0,0); v2plot->SetName("v2vspt"); v2ncqplot->SetName("v2vsKET_ncq"); v2bkgplot->SetName("v2bkgvspt"); v2plot->Write(); v2ncqplot->Write(); v2bkgplot->Write(); }
void plotResolution( char* var, float xmin, float xmax, const char * region, const char *xbinning, const char * skim, int regionCode, std::ofstream * resultsStg1, std::ofstream * resultsStg2 ) { //Log file TString log_subdir("./logs/"); TString resolution_log = TString("resolution_PVbins_") + TString(var) + TString("_") + TString(skim) + TString(".log"); std::ofstream * logfile = new std::ofstream( (log_subdir + resolution_log).Data(), ios_base::app ); TDatime *d1 = new TDatime(); (*logfile) << d1->AsString() << std::endl; //Output path TString path("./slhc-plots/resolution/Taus/noPUC/isoStudies"); TString varName = TString("reco") + TString(var); // RECO(PFTau) TString l1varName = TString("l1g") + TString(var); // L1 Calo Upgrade (can be Stage 1 or Stage 2) gROOT->SetStyle("Plain"); gROOT->SetBatch(false); gStyle->SetOptStat(0); // --- Use the CMS TDR style gROOT->ProcessLine(".L tdrStyle.C"); setTDRStyle(); tdrStyle->SetErrorX(0.5); tdrStyle->SetPadLeftMargin(0.18); tdrStyle->SetPadRightMargin(0.08); tdrStyle->SetLegendBorderSize(0); tdrStyle->SetTitleYOffset(1.3); tdrStyle->SetOptStat(0); tdrStyle->SetOptFit(0); tdrStyle->SetTitleFontSize(0.05); tdrStyle->SetStatStyle(0); TFile * f1 = new TFile("/uscms/home/aosorio/nobackup/scratch0/SLHC_BKP/root_files/L1Tree_Htt_MC_RAWRECO_MC_VisTau.root"); f1->cd(); TTree * Stage1Taus = (TTree*)gDirectory->Get("rlxTauSt1Efficiency/Ntuple"); TTree * Stage2Taus = (TTree*)gDirectory->Get("rlxTauSt2Efficiency/Ntuple"); std::cout << " Ntuple ready: " << Stage1Taus << " " << Stage2Taus << std::endl; TCanvas * canvas = new TCanvas("asdf", "adsf", 800, 600); canvas->Draw(); TList * Stage1Histos = new TList(); TList * Stage2Histos = new TList(); //this is to separate into different decay mode as in reco::PFTau::hadronicDecayMode // Enumerator: // -1 kNull // 0 kOneProng0PiZero // 1 kOneProng1PiZero // 2 kOneProng2PiZero // ... // 10 kThreeProng0PiZero int decayMode[10] = {0}; for( int k = 0 ; k < 1; ++k ) { double m1 = 0.0; double area = 0.0; double yMax = 0.0; int xMin = xmin; int xMax = xmax; char cuts[200]; //this is to use the decayMode: sprintf(cuts, " ( l1Pt >= 25.0 && l1gMatch >= 1.0 )&& %s && nPVs > %d && nPVs < %d && decayMode >= %d && decayMode < 3", region, xMin, xMax, decayMode[k]); TString histoDraw = TString("(") + TString( l1varName ) + TString(" - ") + TString(varName) + TString(")/") + TString(varName) + TString(">> "); char st1HistoName[100]; sprintf(st1HistoName, "htempSt1_%d", k); char st2HistoName[100]; sprintf(st2HistoName, "htempSt2_%d", k); TH1D* h1T = new TH1D(st1HistoName, "", 50, -2, 2); h1T->Sumw2(); TH1D* h2T = new TH1D(st2HistoName, "", 50, -2, 2); h2T->Sumw2(); Stage1Taus->Draw( histoDraw + TString(st1HistoName), cuts, ""); TH1F* h1 = (TH1F*)gDirectory->Get( st1HistoName )->Clone(); area = h1->Integral(); h1->Scale( 1.0/area ); m1 = h1->GetMaximum(); if ( m1 > yMax ) yMax = m1; std::cout << h1 << std::endl; Stage1Histos->Add( h1 ); Stage2Taus->Draw( histoDraw + TString(st2HistoName), cuts, ""); TH1F* h2 = (TH1F*)gDirectory->Get( st2HistoName )->Clone(); area = h2->Integral(); h2->Scale( 1.0/area ); m1 = h2->GetMaximum(); if ( m1 > yMax ) yMax = m1; std::cout << h2 << std::endl; Stage2Histos->Add( h2 ); canvas->cd(); TF1 * stg1Fit = new TF1("g1","gaus",h1->GetXaxis()->GetXmin(), h1->GetXaxis()->GetXmax() ); TF1 * stg1Fit = new TF1("g2","gaus",h1->GetXaxis()->GetXmin(), h1->GetXaxis()->GetXmax() ); h1->GetXaxis()->SetLabelFont(42); h1->GetXaxis()->SetTitleOffset(1.34); h1->GetXaxis()->SetTitleFont(42); h1->GetYaxis()->SetTitle("A.U."); h1->GetYaxis()->SetLabelFont(42); h1->GetYaxis()->SetTitleOffset(1.3); h1->GetYaxis()->SetTitleFont(42); h1->SetMaximum( yMax + (yMax*0.30) ); h2->SetMaximum( yMax + (yMax*0.30) ); h1->SetLineColor(2); h1->Draw("e0"); h1->Clone()->Draw("histsame"); h1->Fit("g1"); h2->SetLineColor(4); h2->Draw("lsame"); h2->Clone()->Draw("histsame"); h2->Fit("g2"); tdrStyle->SetStatStyle(0); TF1 * fitFun = (TF1*)h1->GetListOfFunctions()->FindObject("g1"); fitFun->SetLineColor(2); fitFun->SetLineWidth(2); fitFun->SetLineStyle(2); (*logfile) << "Fit results h1 reg: " << regionCode << " decaymode: " << k << '\t'; (*logfile) << fitFun->GetParameter(1) << '\t' << fitFun->GetParameter(2) << '\n'; (*resultsStg1) << xMin << '\t' << fitFun->GetParameter(2) << '\t' << fitFun->GetParError(2) << '\n'; char sigma1[50]; sprintf(sigma1, "= %f", fitFun->GetParameter(2) ); fitFun = (TF1*)h2->GetListOfFunctions()->FindObject("g2"); fitFun->SetLineColor(4); fitFun->SetLineWidth(2); fitFun->SetLineStyle(2); (*logfile) << "Fit results h2 reg: " << regionCode << " decaymode: " << k << '\t'; (*logfile) << fitFun->GetParameter(1) << '\t' << fitFun->GetParameter(2) << '\n'; (*logfile) << " xmin " << xmin << " xmax " << xmax << std::endl; (*resultsStg2) << xMin << '\t' << fitFun->GetParameter(2) << '\t' << fitFun->GetParError(2) << '\n'; char sigma2[50]; sprintf(sigma2, "= %f", fitFun->GetParameter(2) ); // get the sigma h1->SetMaximum( yMax + (yMax*0.30) ); h1->Draw("same"); h2->Draw("same"); // TString stage1Leg = TString("MC Stage 1 #sigma") + TString(sigma1); TString stage2Leg = TString("MC Stage 2 #sigma") + TString(sigma2); ////////////////////////////////////////////////// TLegend * leg = new TLegend(0.21,0.72,0.44,0.86); leg->AddEntry( h1, stage1Leg.Data() ); leg->AddEntry( h2, stage2Leg.Data() ); leg->SetBorderSize(0); leg->SetTextSize(0.032); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(1001); leg->Draw(); cmsPrelim(); std::stringstream saveAs; saveAs.str(""); saveAs << path << "/eps/rlx_mctau_reso_" << skim << "_" << var << "_" << xMin << "_" << xMax << "_dcm_" << k << "_" << regionCode << ".eps"; canvas->SaveAs( saveAs.str().c_str() ); saveAs.str(""); saveAs << path << "/pdf/rlx_mctau_reso_" << skim << "_" << var << "_" << xMin << "_" << xMax << "_dcm_" << k << "_" << regionCode << ".pdf"; canvas->SaveAs( saveAs.str().c_str() ); //png output not working properly - fitted curve is not fully draw - removed as output (work around -> convert from pdf to png) } logfile->close(); delete logfile; }