void GetFWHM(TF1* floo, double& mean, double& fwhm) { TF1* fgt = (TF1*) gROOT->FindObject("fgt"); if (fgt != 0) delete fgt; fgt = new TF1("fgt", gaustail, 0, 6000, 5); for (int i=0;i<5;i++) fgt->SetParameter(i,floo->GetParameter(i)); double mean = fgt->GetMaximumX(); double max = fgt->GetMaximum(); double left = fgt->GetX(max/2.,0,mean); double right = fgt->GetX(max/2.,mean,6000); fwhm = right - left; cout << "Found " << mean << " " << fwhm << endl; }
double acceptance2(double accrecoil, double n, double fbeta=0.27, double frecoil=0.71) { TF1* f = (TF1*)(gROOT->GetFunction("acc")); if(!f) f = new TF1("acc","acceptance([0],[1],x)",0,1); f->SetParameters(n,frecoil); double fcut = f->GetX(accrecoil); return acceptance(n,fbeta,fcut); }
Double_t beta2_for_5sigma(const Int_t fNPts, const Double_t fRangeMin, const Double_t fRangeMax, const Double_t fN_sig_100, const Double_t fN_bkg_100, const Double_t fSigma_N_bkg, const string& fTitle) { Double_t x[fNPts], y[fNPts]; Double_t step = (fRangeMax - fRangeMin)/(fNPts-1); for (Int_t i = 0; i < fNPts; i++) { x[i] = fRangeMin + step*i; y[i] = ScP(x[i], fN_sig_100, fN_bkg_100, fSigma_N_bkg); } TCanvas *c_temp = new TCanvas("c_temp","",1120,800); c_temp->cd(); string title = fTitle + ";#beta^{2};S_{cP}"; TH2F *bg_temp = new TH2F("bg_temp",title.c_str(), 100, fRangeMin, fRangeMax, 100, 0.8*y[0], 1.2*y[fNPts-1]); bg_temp->SetStats(kFALSE); bg_temp->SetTitleOffset(1.,"X"); bg_temp->SetTitleOffset(1.,"Y"); bg_temp->Draw(); TGraph *scP = new TGraph(fNPts, x, y); scP->SetMarkerSize(1.); scP->SetMarkerStyle(24); scP->SetMarkerColor(kRed); scP->Draw("P"); scP->Fit("pol2"); TF1 *fit = (TF1*)scP->GetFunction("pol2"); Double_t beta2 = fit->GetX(5); Double_t N_sig = beta2*fN_sig_100; Double_t N_s_b = N_sig + fN_bkg_100; cout<<">> beta2 for 5 sigma discovery for "<<fTitle<<" = "<<beta2<<"\n"; cout<<">> ** N_sig = "<<N_sig<<"\n"; cout<<">> ** N_bkg = "<<fN_bkg_100<<"\n"; cout<<">> ** N_s_b = "<<N_s_b<<"\n"; if(fSigma_N_bkg != 0) c_temp->SaveAs((fTitle + "_significance_beta_sys.png").c_str()); else c_temp->SaveAs((fTitle + "_significance_beta.png").c_str()); delete scP; delete bg_temp; delete c_temp; return beta2; }
void analyzeInclusivejet(){ float cutEtaJet = 2; float cutPtJet =100; // Tree variables //Trigger trigger; float jtpt_ic5[1000]; float jteta_ic5[1000]; float jtphi_ic5[1000]; int njets_ic5; float jtpt_ak3[1000]; float jteta_ak3[1000]; float jtphi_ak3[1000]; int njets_ak3; int run; int evt; int bin; const int NBINS=15; Double_t BOUNDARIES[NBINS] = {60,65,72,80,90,100,120,140,160,180,200,220,240,280,350}; TH1F* hak3pujet_cut = new TH1F("hak3pujet_cut","AK3PU Jet Spectra with cut;p_{T}; # of Events",NBINS-1,BOUNDARIES); TH1F* hak3pujet = new TH1F("hak3pujet","AK3PU Jet Spectra;p_{T}; # of Events",NBINS-1,BOUNDARIES); hak3pujet_cut->Sumw2(); hak3pujet->Sumw2(); TString inname="merged.root"; TFile* inf = new TFile(inname,"read"); TTree* ic5t = (TTree*)inf->Get("icPu5JetAnalyzer/t"); TTree* t = (TTree*)inf->Get("hltanalysis/HltTree"); ic5t->SetBranchAddress("jtpt",jtpt_ic5); ic5t->SetBranchAddress("jteta",jteta_ic5); ic5t->SetBranchAddress("jtphi",jtphi_ic5); ic5t->SetBranchAddress("nref",&njets_ic5); TTree* ak3t = (TTree*)inf->Get("akPu3PFJetAnalyzer/t"); ak3t->SetBranchAddress("jtpt",jtpt_ak3); ak3t->SetBranchAddress("jteta",jteta_ak3); ak3t->SetBranchAddress("jtphi",jtphi_ak3); ak3t->SetBranchAddress("nref",&njets_ak3); t->SetBranchAddress("Run",&run); t->SetBranchAddress("Event",&evt); t->SetBranchAddress("hiBin",&bin); TString outname = "JetSkimTree.root"; int Nevents = t->GetEntries(); for(int iev = 0; iev < Nevents; ++iev){ t->GetEntry(iev); ic5t->GetEntry(iev); ak3t->GetEntry(iev); for(int i = 0; i < njets_ak3; ++i){ //if(jtpt_ak3[i] < cutPtJet) continue; if(fabs(jteta_ak3[i]) > cutEtaJet) continue; hak3pujet->Fill(jtpt_ak3[i]); }//1st for loop int id=0; for(int i = 0; i < njets_ak3; ++i){ if(fabs(jteta_ic5[i]) < cutEtaJet) id =1; }// 2nd for loop if(id == 1){ for(int i = 0; i < njets_ak3; ++i){ if(jtpt_ic5[i] < cutPtJet) continue; //if(jtpt_ak3[i] < cutPtJet) continue; if(fabs(jteta_ak3[i]) > cutEtaJet) continue; hak3pujet_cut->Fill(jtpt_ak3[i]); } }// if loop }//evt loop TCanvas *c1 = new TCanvas("c1", "",46,477,700,509); c1->Range(-125,-11.1492,1125,3.24528); c1->SetBorderSize(0); c1->SetBorderMode(0); c1->SetLeftMargin(0.16); c1->SetTopMargin(0.06); c1->SetBottomMargin(0.17); c1->SetTicks(1,1); gROOT->LoadMacro("erf.C"); TGraphAsymmErrors *dividedthingy= new TGraphAsymmErrors; dividedthingy->BayesDivide(hak3pujet_cut,hak3pujet); float xstart=20.0; float xend=300.0; TF1 *fitfcn = new TF1("fitfcn",erf,xstart,xend,2); //<============ fitfcn->SetParameter(0,40); //<============= TFitResultPtr results =dividedthingy->Fit("fitfcn","VSR"); cout << "Chi2: " << results->Chi2() << " / " << results->Ndf() << " NDF" << endl; float turnon=fitfcn->GetX(0.99,10,300); cout << "99% at: " << turnon << endl; char turnontext[50]=""; sprintf(turnontext," ak5pu at %4.1f",turnon); dividedthingy->GetFunction("fitfcn")->SetLineColor(3); dividedthingy->SetLineColor(1); dividedthingy->Draw("Ap"); TText *t2 = new TText(95,0.08,turnontext); t2->SetTextSize(0.055); t2->SetTextColor(1); t2->Draw(); }
void theoryBin(TDirectory *din, TDirectory *dth, TDirectory *dout) { float etamin, etamax; assert(sscanf(din->GetName(),"Eta_%f-%f",&etamin,&etamax)==2); sscanf(din->GetName(),"Eta_%f-%f",&etamin,&etamax); int ieta = int((0.5*(etamin+etamax))/0.5); int jeta = (_jp_algo=="AK7" ? min(4,ieta) : ieta); // inclusive jets TH1D *hpt = (TH1D*)din->Get("hpt"); assert(hpt); // theory curves // http://www-ekp.physik.uni-karlsruhe.de/~rabbertz/fastNLO_LHC/InclusiveJets/ // -> fnl2342_cteq66_aspdf_full.root // Numbering scheme explained in // https://twiki.cern.ch/twiki/bin/view/CMS/CMSfastNLO // 2-point to 6-point theory uncertainty: // h200X00->h300X09, h400X00->h300X08 TH1D *hnlo(0);//, *hpdfup(0), *hpdfdw(0), *hscup(0), *hscdw(0);//, *herr(0); cout << din->GetName() << " ieta="<<ieta<< " jeta="<<jeta << endl; TH1D *hmc = (TH1D*)dth->Get("hpt_g0tw"); assert(hmc); /* int S = (_jp_algo=="AK7" ? 1 : 3); TH1D *hnlo_cteq = (TH1D*)dnlo0->Get(Form("h%d00%d00",S,jeta+1)); assert(hnlo_cteq); hnlo_cteq->Scale(1000.); // CTEQ10 TH1D *hnlo_ct10 = (TH1D*)dnlo1->Get(Form("h300%d00",jeta+1)); TH1D *hpdfup_ct10 = (TH1D*)dnlo1->Get(Form("h300%d02",jeta+1)); TH1D *hpdfdw_ct10 = (TH1D*)dnlo1->Get(Form("h300%d01",jeta+1)); TH1D *hscup_ct10 = (TH1D*)dnlo1->Get(Form("h300%d09",jeta+1)); TH1D *hscdw_ct10 = (TH1D*)dnlo1->Get(Form("h300%d08",jeta+1)); assert(hnlo_ct10); assert(hpdfup_ct10); assert(hpdfdw_ct10); assert(hscup_ct10); assert(hscdw_ct10); hnlo_ct10->Scale(1000.); hpdfup_ct10->Scale(1./1.65); hpdfdw_ct10->Scale(1./1.65); // MSTW2008 TH1D *hnlo_mstw = (TH1D*)dnlo2->Get(Form("h%d00%d00",S,jeta+1)); assert(hnlo_mstw); hnlo_mstw->Scale(1000.); // NNPDF2010 TH1D *hnlo_nnpdf = (TH1D*)dnlo3->Get(Form("h%d00%d00",S,jeta+1)); assert(hnlo_nnpdf); hnlo_nnpdf->Scale(1000.); // HERA10 TH1D *hnlo_hera = (TH1D*)dnlo4->Get(Form("h%d00%d00",S,jeta+1)); TH1D *hpdfup_hera = (TH1D*)dnlo4->Get(Form("h%d00%d02",S,jeta+1)); TH1D *hpdfdw_hera = (TH1D*)dnlo4->Get(Form("h%d00%d01",S,jeta+1)); assert(hnlo_hera); assert(hpdfup_hera); assert(hpdfdw_hera); hnlo_hera->Scale(1000.); // alpha-S TH1D *hasup = (TH1D*)das->Get(Form("h300%d02",ieta+1)); TH1D *hasdw = (TH1D*)das->Get(Form("h300%d01",ieta+1)); assert(hasup); assert(hasdw); TH1D *hnp = (TH1D*)dnp->Get(Form("corr%d",min(int(etamin/0.5+0.5),5))); if (!hnp) cout << "eta: " << etamin << " " << etamax << endl; assert(hnp); */ // make sure new histograms get created in the output file dout->cd(); /* TH1D *hnpup(0), *hnpdw(0), *hsysup(0), *hsysdw(0); { // Move CTEQ6.6 hnlo_cteq = (TH1D*)hnlo_cteq->Clone("hnlo0_ct10k"); hnlo_ct10 = (TH1D*)hnlo_ct10->Clone("hnlo0_ct10"); hnlo_mstw = (TH1D*)hnlo_mstw->Clone("hnlo0_mstw"); hnlo_nnpdf = (TH1D*)hnlo_nnpdf->Clone("hnlo0_nnpdf"); hnlo_hera = (TH1D*)hnlo_hera->Clone("hnlo0_hera"); // Determine PDF4LHC from CT10, MSTW08, NNPDF10 hnlo = (TH1D*)hnlo_ct10->Clone("hnlo0"); // central PDF again later hpdfup = (TH1D*)hpdfup_ct10->Clone("hpdfup"); // central PDF hpdfdw = (TH1D*)hpdfdw_ct10->Clone("hpdfdw"); // central PDF for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { // Sanity checks assert(hpdfup_ct10->GetBinContent(i)>=0); assert(hpdfdw_ct10->GetBinContent(i)<=0); } hscup = (TH1D*)hscup_ct10->Clone("hscup"); // central PDF hscdw = (TH1D*)hscdw_ct10->Clone("hscdw"); // central PDF hasup = (TH1D*)hasup->Clone("hasup"); hasdw = (TH1D*)hasdw->Clone("hasdw"); hnp = (TH1D*)hnp->Clone("hnpcorr"); hnpup = (TH1D*)hnlo->Clone("hnpup"); hnpdw = (TH1D*)hnlo->Clone("hnpdw"); hsysup = (TH1D*)hnlo->Clone("hsysup"); hsysdw = (TH1D*)hnlo->Clone("hsysdw"); } */ /* // Patch up the hnp to adapt the wrong binning at low pT if (true) { // patch hnp TH1D *hnp_tmp = (TH1D*)hnlo->Clone("hnp_tmp"); for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { double x = hnlo->GetBinCenter(i); int j1 = hnp->FindBin(x); double x1 = hnp->GetBinCenter(j1); double y1 = hnp->GetBinContent(j1); double ey1 = hnp->GetBinError(j1); int j2 = (x>x1? j1+1 : j1-1); double x2 = hnp->GetBinCenter(j2); double y2 = hnp->GetBinContent(j2); double ey2 = hnp->GetBinError(j2); double y = y1 + (y2-y1) / (x2-x1) * (x-x1); double ey = ey1 + (ey2-ey1) / (x2-x1) * (x-x1); hnp_tmp->SetBinContent(i, y); hnp_tmp->SetBinError(i, ey); } // for i delete hnp; hnp = hnp_tmp; hnp->SetName("hnpcorr"); } // patch hnp */ /* // Turn NP uncertainty into uncertainty histogram for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { int j = hnp->FindBin(hnlo->GetBinCenter(i)); hnpup->SetBinContent(i, +hnp->GetBinError(j)/hnp->GetBinContent(j)); hnpup->SetBinError(i, 0.); hnpdw->SetBinContent(i, -hnp->GetBinError(j)/hnp->GetBinContent(j)); hnpdw->SetBinError(i, 0.); if (!(hnp->GetBinLowEdge(j)>=hnlo->GetBinLowEdge(i)) || !(hnp->GetBinLowEdge(j+1)<=hnlo->GetBinLowEdge(i+1))) { cout << Form("hnlo = [%1.0f,%1.0f]; hnp = [%1.0f,%1.0f]", hnlo->GetBinLowEdge(i), hnlo->GetBinLowEdge(i+1), hnp->GetBinLowEdge(j), hnp->GetBinLowEdge(j+1)) << endl; if (hnlo->GetBinLowEdge(i)>100 && hnlo->GetBinLowEdge(i)<2500.) { assert(hnp->GetBinLowEdge(j)>=hnlo->GetBinLowEdge(i)); assert(hnp->GetBinLowEdge(j+1)<=hnlo->GetBinLowEdge(i+1)); } } } // for i */ /* for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { double x = hnlo->GetBinCenter(i); int i1 = hnpup->FindBin(x); double y1a = hnpup->GetBinContent(i1); double y1b = hnpdw->GetBinContent(i1); int i2 = hscup->FindBin(x); double y2a = hscup->GetBinContent(i2); double y2b = hscdw->GetBinContent(i2); int i3 = hpdfup->FindBin(x); double y3a = hpdfup->GetBinContent(i3); double y3b = hpdfdw->GetBinContent(i3); int i4 = hasup->FindBin(x); double y4a = hasup->GetBinContent(i4); double y4b = hasdw->GetBinContent(i4); double errup = sqrt(pow(max3(y1a,y1b,0),2) + pow(max3(y2a,y2b,0),2) + pow(max3(y3a,y3b,0),2) + pow(max3(y4a,y4b,0),2)); double errdw = sqrt(pow(min3(y1a,y1b,0),2) + pow(min3(y2a,y2b,0),2) + pow(min3(y3a,y3b,0),2) + pow(min3(y4a,y4b,0),2)); hsysup->SetBinContent(i, errup); hsysup->SetBinError(i, 0.); hpdfup->SetBinError(i, 0.); hscup->SetBinError(i, 0.); hasup->SetBinError(i, 0); hsysdw->SetBinContent(i, -errdw); hsysdw->SetBinError(i, 0.); hpdfdw->SetBinError(i, 0.); hscdw->SetBinError(i, 0.); hasdw->SetBinError(i, 0); } // for i */ /* for (int i = 1; i != hnlo_ct10->GetNbinsX()+1; ++i) { double x = hnlo_ct10->GetBinCenter(i); int jnp = hnp->FindBin(x); double np = hnp->GetBinContent(jnp); int j = hnlo_ct10->FindBin(x); hnlo->SetBinContent(j, 1e-3*hnlo->GetBinContent(j)*np); int jc = hnlo_ct10->FindBin(x); hnlo_ct10->SetBinContent(jc, 1e-3*hnlo_ct10->GetBinContent(jc)*np); int jk = hnlo_cteq->FindBin(x); hnlo_cteq->SetBinContent(jk, 1e-3*hnlo_cteq->GetBinContent(jk)*np); int jm = hnlo_mstw->FindBin(x); hnlo_mstw->SetBinContent(jm, 1e-3*hnlo_mstw->GetBinContent(jm)*np); int jn = hnlo_nnpdf->FindBin(x); hnlo_nnpdf->SetBinContent(jn, 1e-3*hnlo_nnpdf->GetBinContent(jn)*np); int jh = hnlo_hera->FindBin(x); hnlo_hera->SetBinContent(jh, 1e-3*hnlo_hera->GetBinContent(jh)*np); // hnlo->SetBinError(j, 0.); hnlo_ct10->SetBinError(jc, 0.); hnlo_cteq->SetBinError(jk, 0.); hnlo_mstw->SetBinError(jm, 0.); hnlo_nnpdf->SetBinError(jn, 0.); hnlo_hera->SetBinError(jh, 0.); } */ // initial fit of the NLO curve TF1 *fnlo = new TF1("fnlo", "[0]*exp([1]/x)*pow(x,[2])" "*pow(1-x*cosh([4])/3500.,[3])", 10., 1000.); fnlo->SetParameters(2e14,-18,-5.2,8.9,0.5*ieta); fnlo->FixParameter(4,0.5*ieta); hnlo = hmc; hnlo->Fit(fnlo,"QRN"); // Graph of theory points with centered bins const double minerr = 0.02; TGraphErrors *gnlo = new TGraphErrors(0); TGraphErrors *gnlo2 = new TGraphErrors(0); // above + minerr TGraphErrors *gnlocut = new TGraphErrors(0); // only up to expected pT gnlo->SetName("gnlo"); gnlo2->SetName("gnlo2"); gnlocut->SetName("gnlocut"); for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { double y = hnlo->GetBinContent(i); double dy = hnlo->GetBinError(i); double ptmin = hnlo->GetBinLowEdge(i); double ptmax = hnlo->GetBinLowEdge(i+1); double y0 = fnlo->Integral(ptmin, ptmax) / (ptmax - ptmin); double x = fnlo->GetX(y0, ptmin, ptmax); int n = gnlo->GetN(); tools::SetPoint(gnlo, n, x, y, 0, dy); tools::SetPoint(gnlo2, n, x, y, 0, tools::oplus(dy, minerr*y)); if (y*(ptmax-ptmin) > 0.0001) { // for 10/fb int m = gnlocut->GetN(); tools::SetPoint(gnlocut, m, x, y, 0, 0); } } gnlo2->Fit(fnlo,"QRN"); // Divide graph with fit to check stability TGraphErrors *gnlofit = new TGraphErrors(0); gnlofit->SetName("gnlofit"); for (int i = 0; i != gnlo->GetN(); ++i) { double x, y, ex, ey; tools::GetPoint(gnlo, i, x, y, ex, ey); double f = fnlo->Eval(x); tools::SetPoint(gnlofit, i, x, y/f, ex, ey/f); } // Rebin theory to match data bins TH1D *hnlo0 = hnlo; hnlo0->SetName("hnlo0"); hnlo = tools::Rebin(hnlo0, hpt); hnlo->SetName("hnlo"); // Same for earlier 2010 and 2011 studies to get a matching theory set // (moved from PDF4LHC to CT10 since 2010) if (false) { // Match this to drawSummary.C inputs TDirectory *curdir = gDirectory; TFile *fin2010 = new TFile("../pfjet/output-DATA-4c.root","READ"); assert(fin2010 && !fin2010->IsZombie()); assert(fin2010->cd("Standard")); fin2010->cd("Standard"); assert(gDirectory->cd(din->GetName())); gDirectory->cd(din->GetName()); TDirectory *din2010 = gDirectory; TH1D *hpt2010 = (TH1D*)din2010->Get("hpt"); curdir->cd(); TH1D *hnlo2010 = tools::Rebin(hnlo0, hpt2010); hnlo2010->SetName("hnlo2010"); hnlo2010->Write(); } if (false) { // Match this to drawSummary.C inputs TDirectory *curdir = gDirectory; TFile *fin2011 = new TFile("backup/oct26/output-DATA-4c.root","READ"); assert(fin2011 && !fin2011->IsZombie()); assert(fin2011->cd("Standard")); fin2011->cd("Standard"); assert(gDirectory->cd(din->GetName())); gDirectory->cd(din->GetName()); TDirectory *din2011 = gDirectory; TH1D *hpt2011 = (TH1D*)din2011->Get("hpt"); curdir->cd(); TH1D *hnlo2011 = tools::Rebin(hnlo0, hpt2011); hnlo2011->SetName("hnlo2011"); hnlo2011->Write(); } /* { TH1D *hnlo0_cteq = hnlo_cteq; hnlo0_cteq->SetName("hnlo0_ct10k"); hnlo_cteq = tools::Rebin(hnlo0_cteq, hpt); hnlo_cteq->SetName("hnlo_ct10k"); // TH1D *hnlo0_ct10 = hnlo_ct10; hnlo0_ct10->SetName("hnlo0_ct10"); hnlo_ct10 = tools::Rebin(hnlo0_ct10, hpt); hnlo_ct10->SetName("hnlo_ct10"); // TH1D *hnlo0_mstw = hnlo_mstw; hnlo0_mstw->SetName("hnlo0_mstw"); hnlo_mstw = tools::Rebin(hnlo0_mstw, hpt); hnlo_mstw->SetName("hnlo_mstw"); // TH1D *hnlo0_nnpdf = hnlo_nnpdf; hnlo0_nnpdf->SetName("hnlo0_nnpdf"); hnlo_nnpdf = tools::Rebin(hnlo0_nnpdf, hpt); hnlo_nnpdf->SetName("hnlo_nnpdf"); // TH1D *hnlo0_hera = hnlo_hera; hnlo0_hera->SetName("hnlo0_hera"); hnlo_hera = tools::Rebin(hnlo0_hera, hpt); hnlo_hera->SetName("hnlo_hera"); } */ dout->cd(); gnlo->Write(); gnlocut->Write(); gnlofit->Write(); fnlo->Write(); din->cd(); } // theoryBin
void fitTF1(TCanvas *canvas, TH1F h, double XMIN_, double XMAX_, double dX_, double params[], Color_t LC_=kBlack) { //double& FWHM_, double& x0_, double& x1_, double& x2_, double& y0_, double& y1_, double& INT_, double& YIELD_) { //TCanvas* fitTF1(TH1F h, double HSCALE_, double XMIN_, double XMAX_) { //TF1* fitTF1(TH1F h, double HSCALE_, double XMIN_, double XMAX_) { gROOT->ForceStyle(); RooMsgService::instance().setSilentMode(kTRUE); for(int i=0;i<2;i++) RooMsgService::instance().setStreamStatus(i,kFALSE); //TCanvas *canvas = new TCanvas(TString::Format("canvas_%s",h.GetName()),TString::Format("canvas_%s",h.GetName()),1800,1200); RooDataHist *RooHistFit = 0; RooAddPdf *model = 0; RooWorkspace w = RooWorkspace("w","workspace"); RooRealVar x("mbbReg","mbbReg",XMIN_,XMAX_); RooRealVar kJES("CMS_scale_j","CMS_scale_j",1,0.9,1.1); RooRealVar kJER("CMS_res_j","CMS_res_j",1,0.8,1.2); kJES.setConstant(kTRUE); kJER.setConstant(kTRUE); TString hname = h.GetName(); RooHistFit = new RooDataHist("fit_"+hname,"fit_"+hname,x,&h); RooRealVar YieldVBF = RooRealVar("yield_"+hname,"yield_"+hname,h.Integral()); RooRealVar m("mean_"+hname,"mean_"+hname,125,100,150); RooRealVar s("sigma_"+hname,"sigma_"+hname,12,3,30); RooFormulaVar mShift("mShift_"+hname,"@0*@1",RooArgList(m,kJES)); RooFormulaVar sShift("sShift_"+hname,"@0*@1",RooArgList(m,kJER)); RooRealVar a("alpha_"+hname,"alpha_"+hname,1,-10,10); RooRealVar n("exp_"+hname,"exp_"+hname,1,0,100); RooRealVar b0("b0_"+hname,"b0_"+hname,0.5,0.,1.); RooRealVar b1("b1_"+hname,"b1_"+hname,0.5,0.,1.); RooRealVar b2("b2_"+hname,"b2_"+hname,0.5,0.,1.); RooRealVar b3("b3_"+hname,"b3_"+hname,0.5,0.,1.); RooBernstein bkg("signal_bkg_"+hname,"signal_bkg_"+hname,x,RooArgSet(b0,b1,b2)); RooRealVar fsig("fsig_"+hname,"fsig_"+hname,0.7,0.0,1.0); RooCBShape sig("signal_gauss_"+hname,"signal_gauss_"+hname,x,mShift,sShift,a,n); model = new RooAddPdf("signal_model_"+hname,"signal_model_"+hname,RooArgList(sig,bkg),fsig); //RooFitResult *res = model->fitTo(*RooHistFit,RooFit::Save(),RooFit::SumW2Error(kFALSE),"q"); model->fitTo(*RooHistFit,RooFit::Save(),RooFit::SumW2Error(kFALSE),"q"); //res->Print(); //model->Print(); canvas->cd(); canvas->SetTopMargin(0.1); RooPlot *frame = x.frame(); // no scale RooHistFit->plotOn(frame); model->plotOn(frame,RooFit::LineColor(LC_),RooFit::LineWidth(2));//,RooFit::LineStyle(kDotted)); model->plotOn(frame,RooFit::Components(bkg),RooFit::LineColor(LC_),RooFit::LineWidth(2),RooFit::LineStyle(kDashed)); // with scale // RooHistFit->plotOn(frame,RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent)); // model->plotOn(frame,RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent),RooFit::LineWidth(1)); // model->plotOn(frame,RooFit::Components(bkg),RooFit::LineColor(kBlue),RooFit::LineWidth(1),RooFit::LineStyle(kDashed),RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent)); frame->GetXaxis()->SetLimits(50,200); frame->GetXaxis()->SetNdivisions(505); frame->GetXaxis()->SetTitle("M_{b#bar{b}} (GeV)"); frame->GetYaxis()->SetTitle("Events"); frame->Draw(); h.SetFillColor(kGray); h.Draw("hist,same"); frame->Draw("same"); gPad->RedrawAxis(); TF1 *tmp = model->asTF(x,fsig,x); //tmp->Print(); double y0_ = tmp->GetMaximum(); double x0_ = tmp->GetMaximumX(); double x1_ = tmp->GetX(y0_/2.,XMIN_,x0_); double x2_ = tmp->GetX(y0_/2.,x0_,XMAX_); double FWHM_ = x2_-x1_; double INT_ = tmp->Integral(XMIN_,XMAX_); double YIELD_= YieldVBF.getVal(); double y1_ = dX_*0.5*y0_*(YieldVBF.getVal()/tmp->Integral(XMIN_,XMAX_)); params[0] = x0_; params[1] = x1_; params[2] = x2_; params[3] = y0_; params[4] = y1_; params[5] = FWHM_; params[6] = INT_; params[7] = YIELD_; //cout<<"Int = "<<tmp->Integral(XMIN_,XMAX_)<<", Yield = "<<YieldVBF.getVal()<<", y0 = "<<y0_<<", y1 = "<<y1_ <<", x0 = "<< x0_ << ", x1 = "<<x1_<<", x2 = "<<x2_<<", FWHM = "<<FWHM_<<endl; TLine ln = TLine(x1_,y1_,x2_,y1_); ln.SetLineColor(kMagenta+3); ln.SetLineStyle(7); ln.SetLineWidth(2); ln.Draw(); canvas->Update(); canvas->SaveAs("testC.png"); // tmp->Delete(); // frame->Delete(); // res->Delete(); // TF1 *f1 = model->asTF(x,fsig,x); // return f1; ////tmp->Delete(); ////ln->Delete(); ////model->Delete(); ////RooHistFit->Delete(); ////w->Delete(); ////YieldVBF->Delete(); ////frame->Delete(); ////res->Delete(); //delete tmp; //delete ln; //delete model; //delete RooHistFit; //delete w; //delete YieldVBF; //delete frame; //delete res; // return canvas; }
//--------------------------------------------------------------- double *treat(TString fileData, double lumi, TString decay, vector<double> mtop, vector<double> xlim, int binned, TString date, TString version) //--------------------------------------------------------------- { //TString indir = date+"/v"+version+"/"; TString indir = date+"/"+version+"/"; TString outdir = indir; TString channel = " + Jets channel"; if (fileData.Contains("ElectronHad")) { outdir += "CalibEl/"; indir += "MyAnaEl/"; if (decay.Contains("semi", TString::kIgnoreCase)) channel = "e"+channel; if (decay.Contains("di", TString::kIgnoreCase)) channel = "ee/e#mu"+channel; if (decay.Contains("all", TString::kIgnoreCase)) channel = "e/ee/e#mu"+channel; } if (fileData.Contains("MuHad")) { outdir += "CalibMu/"; indir += "MyAnaMu/"; if (decay.Contains("semi", TString::kIgnoreCase)) channel = "#mu"+channel; if (decay.Contains("di", TString::kIgnoreCase)) channel = "#mu#mu/#mue"+channel; if (decay.Contains("all", TString::kIgnoreCase)) channel = "#mu/#mu#mu/#mue"+channel; } if (fileData.Contains("Run2012")) { outdir += "CalibAll/"; indir += "MyAnaAll/"; if (decay.Contains("semi", TString::kIgnoreCase)) channel = "e/#mu"+channel; if (decay.Contains("di", TString::kIgnoreCase)) channel = "ee/#mu#mu/e#mu"+channel; if (decay.Contains("all", TString::kIgnoreCase)) channel = "e/#mu/ee/#mu#mu/e#mu"+channel; } gROOT->ProcessLine(".! mkdir "+outdir); TLatex* channel_tex = new TLatex(0.22, 0.9, channel); channel_tex->SetNDC(true); channel_tex->SetTextFont(43); channel_tex->SetTextSize(TITLE_FONTSIZE - 6); const unsigned int numberOfPoints = mtop.size(); double x[numberOfPoints], ex[numberOfPoints]; double y[numberOfPoints], ey[numberOfPoints]; for (unsigned int itop = 0; itop < numberOfPoints; itop++) { TString fileMC = TString::Format("All_%d_5.root", (int)mtop[itop]); //TString fileMC = TString::Format("TTJets_MSDecays_JpsiFilter_%d_5.root", (int)mtop[itop]); double *mean_err = new double[2]; if (binned < 2) mean_err = unbinnedFit(indir+fileMC, xlim, mtop[itop], channel_tex, outdir, lumi); if (binned == 2) mean_err = binnedFit(indir+fileMC, xlim, mtop[itop], channel_tex, outdir, lumi); y[itop] = mean_err[0]; ey[itop] = mean_err[1]; x[itop] = mtop[itop]+0.5; ex[itop] = 0.; } TGraphErrors *gr = new TGraphErrors(numberOfPoints, x, y, ex, ey); TFitResultPtr fitptr = gr->Fit("pol1", "FSQ", ""); TF1 *fit = gr->GetFunction("pol1"); double yinte = fitptr->Parameter(0); double errYinte = fitptr->ParError(0); double slope = fitptr->Parameter(1); double errSlope = fitptr->ParError(1); double chi2 = fitptr->Chi2(); double ndf = fitptr->Ndf(); double err_up[numberOfPoints]; double err_down[numberOfPoints]; double err_val[numberOfPoints]; fitptr->GetConfidenceIntervals(numberOfPoints, 1, 1, x, err_val, 0.68); for(unsigned int itop = 0; itop < numberOfPoints; itop++) { double error = err_val[itop]; err_up[itop] = fit->Eval(x[itop]) + error; err_down[itop] = fit->Eval(x[itop]) - error; } TGraph *gr_up = new TGraph(numberOfPoints,x,err_up); gr_up->Fit("pol2","FQ",""); TF1 *fit_up = gr_up->GetFunction("pol2"); TGraph *gr_down = new TGraph(numberOfPoints,x,err_down); gr_down->Fit("pol2","FQ",""); TF1 *fit_down = gr_down->GetFunction("pol2"); TLegend *leg_calib = new TLegend(0.2,0.75,0.65,0.83,NULL,"brNDC"); leg_calib->SetTextSize(0.04); leg_calib->AddEntry(gr,TString::Format("Slope of %.2f #pm %.2f", slope, errSlope),"lp"); leg_calib->SetHeader("Calibration curve"); // Blinded analysis TCanvas *cn_calib = new TCanvas("cn_calib", "cn_calib", 800, 800); cn_calib->cd(); grapherrors_myStyle(gr,"gr",2,30,1,30,1001,-1111,-1111,510,510,21,36,1.,"M_{t} (GeV)","M_{J/#psi+l} (GeV)"); gr->Draw("AP"); cn_calib->Update(); fit->SetLineColor(30); fit_up->SetLineColor(29); fit_up->SetLineStyle(2); fit_up->SetLineWidth(2); fit_up->Draw("same"); fit_down->SetLineColor(29); fit_down->SetLineStyle(2); fit_down->SetLineWidth(2); fit_down->Draw("same"); leg_myStyle(leg_calib); leg_calib->SetTextAlign(22); leg_calib->Draw(); channel_tex->Draw("same"); cms_myStyle(lumi, false); TString outBlind = outdir; if (binned < 2) outBlind += "BlindedUnbinnedCalibration"; if (binned == 2) outBlind += "BlindedBinnedCalibration"; cn_calib->SaveAs(outBlind+".pdf"); cn_calib->SaveAs(outBlind+".C"); cn_calib->SaveAs(outBlind+".jpg"); cn_calib->SaveAs(outBlind+".eps"); // Unblinded analysis double *data_fit = new double[2]; if (binned == 0) data_fit = unbinnedFit(indir+fileData, xlim, 0., channel_tex, outdir, lumi); if (binned > 0) data_fit = binnedFit(indir+fileData, xlim, 0., channel_tex, outdir, lumi); double mean_gaus = data_fit[0]; double err_gaus = data_fit[1]; TString mjpsil_res = TString::Format("M_{J/#psi+l} = (%3.1f #pm %3.1f) GeV", mean_gaus, err_gaus); double x_horiz[4]={gr->GetXaxis()->GetXmin(),fit->GetX(mean_gaus+err_gaus,0,250),fit->GetX(mean_gaus-err_gaus,0,250),gr->GetXaxis()->GetXmin()}; double y_horiz[4]={mean_gaus+err_gaus,mean_gaus+err_gaus,mean_gaus-err_gaus,mean_gaus-err_gaus}; TPolyLine *horiz = new TPolyLine(4,x_horiz,y_horiz); TLine *horiz_sup = new TLine(x_horiz[0], y_horiz[0], x_horiz[1], y_horiz[1]); TLine *horiz_med = new TLine(gr->GetXaxis()->GetXmin(), mean_gaus, fit->GetX(mean_gaus,0,250), mean_gaus); TLine *horiz_inf = new TLine(x_horiz[2], y_horiz[2], x_horiz[3], y_horiz[3]); double x_vert_min[4]={fit_up->GetX(mean_gaus-err_gaus,0,250),fit_up->GetX(mean_gaus-err_gaus,0,250),x_horiz[2],x_horiz[2]}; double y_vert_min[4]={gr->GetYaxis()->GetXmin(),mean_gaus-err_gaus,mean_gaus-err_gaus,gr->GetYaxis()->GetXmin()}; TPolyLine *vert_min = new TPolyLine(4,x_vert_min,y_vert_min); double x_vert_mean[4]={x_horiz[2],x_horiz[2],x_horiz[1],x_horiz[1]}; double y_vert_mean[4]={gr->GetYaxis()->GetXmin(),y_horiz[2],y_horiz[1],gr->GetYaxis()->GetXmin()}; TPolyLine *vert_mean = new TPolyLine(4,x_vert_mean,y_vert_mean); double x_vert_max[4]={x_horiz[1],x_horiz[1],fit_down->GetX(mean_gaus+err_gaus,0,250),fit_down->GetX(mean_gaus+err_gaus,0,250)}; double y_vert_max[4]={gr->GetYaxis()->GetXmin(),mean_gaus+err_gaus,mean_gaus+err_gaus,gr->GetYaxis()->GetXmin()}; TPolyLine *vert_max = new TPolyLine(4,x_vert_max,y_vert_max); TLine *vert1 = new TLine(x_vert_min[0],y_vert_min[0],x_vert_min[1],y_vert_min[1]); TLine *vert2 = new TLine(x_vert_mean[0],y_vert_mean[0],x_vert_mean[1],y_vert_mean[1]); TLine *vert3 = new TLine(fit->GetX(mean_gaus,0,250),y_vert_mean[0],fit->GetX(mean_gaus,0,250),mean_gaus); TLine *vert4 = new TLine(x_vert_mean[3],y_vert_mean[3],x_vert_mean[2],y_vert_mean[2]); TLine *vert5 = new TLine(x_vert_max[3],y_vert_max[3],x_vert_max[2],y_vert_max[2]); TString mt_res; double pm_fit = (x_vert_mean[3]-x_vert_mean[0])/2.; double p_fit = x_vert_max[3]-x_vert_mean[3]; double m_fit = x_vert_mean[0]-x_vert_min[0]; if (fabs(p_fit-m_fit)<0.1) mt_res= TString::Format("M_{t} = (%0.1f #pm %0.1f #pm %0.1f) GeV", fit->GetX(mean_gaus,0,250), pm_fit, fabs(m_fit)); else mt_res= TString::Format("M_{t} = (%0.1f #pm %0.1f #splitline{_{+ %0.1f}}{_{- %0.1f}}) GeV", fit->GetX(mean_gaus,0,250),pm_fit, fabs(p_fit), fabs(m_fit)); double *mtop_res = new double[2]; mtop_res[0] = fit->GetX(mean_gaus,0,250); mtop_res[1] = pm_fit + max(fabs(p_fit), fabs(m_fit)); TLegend *leg_res = new TLegend(0.2,0.75,0.65,0.87,NULL,"brNDC"); leg_res->SetTextSize(0.04); leg_res->AddEntry(gr,TString::Format("Slope of %.2f #pm %.2f", slope, errSlope),"lp"); leg_res->AddEntry((TObject*)0, mjpsil_res, ""); leg_res->AddEntry((TObject*)0, mt_res, ""); TCanvas *cn_res = new TCanvas("cn_res", "cn_res", 800, 800); cn_res->cd(); grapherrors_myStyle(gr,"gr",2,30,1,30,1001,-1111,-1111,510,510,21,36,1.,"M_{t} (GeV)","M_{J/#psi+l} (GeV)"); gr->Draw("AP"); cn_res->Update(); fit->SetLineColor(30); fit_up->SetLineColor(29); fit_up->SetLineStyle(2); fit_up->SetLineWidth(2); fit_up->Draw("same"); fit_down->SetLineColor(29); fit_down->SetLineStyle(2); fit_down->SetLineWidth(2); fit_down->Draw("same"); poly_myStyle(horiz,0,30,1,9,3002); horiz->Draw("f"); horiz->Draw("same"); line_myStyle(horiz_sup,2,9,2); horiz_sup->Draw("same"); line_myStyle(horiz_med,2,4,1); horiz_med->Draw("same"); line_myStyle(horiz_inf,2,9,2); horiz_inf->Draw("same"); poly_myStyle(vert_min,0,9,2,38,3003); vert_min->Draw("f"); vert_min->Draw("same"); poly_myStyle(vert_mean,0,30,1,9,3002); vert_mean->Draw("f"); vert_mean->Draw("same"); poly_myStyle(vert_max,2,38,2,38,3003); vert_max->Draw("f"); vert_max->Draw("same"); line_myStyle(vert1,2,38,2); vert1->Draw("same"); line_myStyle(vert2,2,9,2); vert2->Draw("same"); line_myStyle(vert3,2,4,1); vert3->Draw("same"); line_myStyle(vert4,2,9,2); vert4->Draw("same"); line_myStyle(vert5,2,38,2); vert5->Draw("same"); leg_myStyle(leg_res); leg_res->SetTextAlign(22); leg_res->Draw(); channel_tex->Draw("same"); cms_myStyle(lumi, true); TString outUnblind = outdir; if (binned == 0) outUnblind += "UnblindedUnbinnedCalibration"; if (binned == 1) outUnblind += "UnblindedMixedCalibration"; if (binned == 2) outUnblind += "UnblindedBinnedCalibration"; cn_res->SaveAs(outUnblind+".pdf"); cn_res->SaveAs(outUnblind+".C"); cn_res->SaveAs(outUnblind+".jpg"); cn_res->SaveAs(outUnblind+".eps"); cout << "\n=============== " << channel <<" =================\n" <<endl; for (unsigned int itop = 0; itop < numberOfPoints; itop++) cout << "M_{top} = "<< x[itop] << " GeV, #tilde{M}_{J/#psi+l} = (" << y[itop] << " +/- "<< ey[itop] << ") GeV" << endl; cout << "\nCalibration:" << endl; cout << "#chi^{2}/Ndof = " << chi2/ndf << endl; cout << "slope = " << slope << " +/- " << errSlope << endl; cout << "y-intercept = " << yinte << " +/- " << errYinte << endl; if (binned == 0) cout << "\nUnbinned fit:" << endl; if (binned == 1) cout << "\nMixed fit:" << endl; if (binned == 2) cout << "\nBinned fit:" << endl; cout << mjpsil_res << endl; cout << mt_res << endl; cout << "\nFigures saved in " << outdir << endl; return mtop_res; }