void plotMuFromToys(std::string inputFile, std::string selectString="fit_status==0"){ // Some Global preferences gROOT->SetStyle("Plain"); gSystem->Load("$CMSSW_BASE/lib/$SCRAM_ARCH/libHiggsAnalysisCombinedLimit.so"); gStyle->SetOptFit(1111); gStyle->SetOptStat(1111); gStyle->SetPalette(1,0); TFile *fi_ = TFile::Open(inputFile.c_str()); TTree *tree_sb = (TTree*) fi_->Get("tree_fit_sb"); TH1F *mures = new TH1F("mures","",25,-2.,2.); mures->SetLineColor(kBlue+3); mures->SetMarkerStyle(kOpenCircle); mures->SetLineWidth(2); mures->GetXaxis()->SetTitle("#mu - 1"); mures->GetYaxis()->SetTitle(Form("no toys (%d total)",int(tree_sb->GetEntries()))); mures->GetYaxis()->SetTitleOffset(1.05); mures->GetXaxis()->SetTitleOffset(0.9); mures->GetYaxis()->SetTitleSize(0.05); mures->GetXaxis()->SetTitleSize(0.05); TCanvas *c = new TCanvas("c","",960,800); tree_sb->Draw("mu>>mures",selectString.c_str()); mures->Fit("gaus"); mures->GetFunction("gaus")->SetLineColor(kCyan+3); mures->Draw("pe1"); c->SaveAs("mlfit/mu_residual.pdf"); }
void Difference(TH1* iH0,TH1 *iH1) { std::string lName = std::string(iH0->GetName()); //TH1F *lHDiff = new TH1F((lName+"Diff").c_str(),(lName+"Diff").c_str(),50,0,300); lHDiff->Sumw2(); TH1F *lHDiff = new TH1F((lName+"Diff").c_str(),(lName+"Diff").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); lHDiff->Sumw2(); lHDiff->SetFillColor(kViolet); lHDiff->SetFillStyle(1001); lHDiff->SetLineWidth(1); TH1F *lXHDiff1 = new TH1F((lName+"XDiff1").c_str(),(lName+"XDiff1").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); int i1 = 0; lXHDiff1->SetLineStyle(2); lXHDiff1->SetLineWidth(2); lXHDiff1->SetLineColor(kRed); lHDiff->GetYaxis()->SetRangeUser(0,2); lHDiff->GetYaxis()->SetTitleOffset(0.6); lHDiff->GetYaxis()->SetTitleSize(0.08); lHDiff->GetYaxis()->SetLabelSize(0.08); lHDiff->GetYaxis()->CenterTitle(); lHDiff->GetXaxis()->SetTitleOffset(1.2); lHDiff->GetXaxis()->SetTitleSize(0.10); lHDiff->GetXaxis()->SetLabelSize(0.08); lHDiff->GetXaxis()->SetTitle("#slash{E}_{T} [GeV]"); //lHDiff->GetXaxis()->CenterTitle(); //lHDiff->GetYaxis()->SetTitle(YLabel); for(int i0 = 0; i0 < lHDiff->GetNbinsX()+1; i0++) { double lXCenter = lHDiff->GetBinCenter(i0); double lXVal = iH0 ->GetBinContent(i0); lXHDiff1->SetBinContent(i0, 1.0); while(iH1->GetBinCenter(i1) < lXCenter) {i1++;} if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinContent(i0,(lXVal-iH1->GetBinContent(i0))/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinError (i0,iH0->GetBinError(i0)/(iH1->GetBinContent(i0))); } lHDiff->SetMarkerStyle(kFullCircle); lHDiff->SetLineColor(kBlack); lHDiff->SetMarkerColor(kBlack); lHDiff->Draw("E1"); lXHDiff1->Draw("hist sames"); }
//Difference plotting void drawDifference(TH1* iH0,TH1 *iH1,TH1 *iHH=0,TH1 *iHL=0,TH1 *iHH1=0,TH1 *iHL1=0) { std::string lName = std::string(iH0->GetName()); TH1F *lHDiff = (TH1F*) iH0->Clone("Diff"); TH1F *lHDiffH = (TH1F*) iH0->Clone("DiffH"); TH1F *lHDiffL = (TH1F*) iH0->Clone("DiffL"); TH1F *lHDiffH1 = (TH1F*) iH0->Clone("DiffH1"); TH1F *lHDiffL1 = (TH1F*) iH0->Clone("DiffL1"); lHDiff ->SetFillColor(kViolet); lHDiff->SetFillStyle(1001); lHDiff->SetLineWidth(1); lHDiffL ->SetLineWidth(1); lHDiffL ->SetLineColor(iHL ->GetLineColor()); lHDiffH ->SetLineWidth(1); lHDiffH ->SetLineColor(iHH ->GetLineColor()); lHDiffL1->SetLineWidth(1); lHDiffL1->SetLineColor(iHL1->GetLineColor()); lHDiffH1->SetLineWidth(1); lHDiffH1->SetLineColor(iHH1->GetLineColor()); TH1F *lXHDiff1 = new TH1F((lName+"XDiff1").c_str(),(lName+"XDiff1").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); TH1F *lXHDiff2 = new TH1F((lName+"XDiff2").c_str(),(lName+"XDiff2").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); int i1 = 0; lXHDiff1->SetLineWidth(2); lXHDiff1->SetLineColor(kRed); lXHDiff2->SetLineWidth(2); lXHDiff2->SetLineColor(kRed); lXHDiff1->GetYaxis()->SetTitle("Ratio"); lXHDiff1->GetYaxis()->SetRangeUser(0.2,1.8); lXHDiff1->GetYaxis()->SetTitleOffset(0.4); lXHDiff1->GetYaxis()->SetTitleSize(0.2); lXHDiff1->GetYaxis()->SetLabelSize(0.11); for(int i0 = 0; i0 < lHDiff->GetNbinsX()+1; i0++) { double lXCenter = lHDiff->GetBinCenter(i0); double lXVal = iH0 ->GetBinContent(i0); double lXValH = iHH ->GetBinContent(i0); double lXValL = iHL ->GetBinContent(i0); double lXValH1 = iHH1 ->GetBinContent(i0); double lXValL1 = iHL1 ->GetBinContent(i0); lXHDiff1->SetBinContent(i0, 1.0); lXHDiff2->SetBinContent(i0, 1.0); while(iH1->GetBinCenter(i1) < lXCenter) {i1++;} if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinContent(i0,lXVal /(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinError (i0,sqrt(lXVal)/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiffL->SetBinContent(i0,lXValL/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiffH->SetBinContent(i0,lXValH/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiffL1->SetBinContent(i0,lXValL1/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiffH1->SetBinContent(i0,lXValH1/(iH1->GetBinContent(i0))); //if(iH1->GetBinContent(i0) > 0) cout << "unc" << lXVal << " -- " << sqrt(lXVal)/(iH1->GetBinContent(i0)) << endl; } lHDiff->SetMarkerStyle(kFullCircle); //lHDiff->Draw("EP"); lXHDiff1->SetStats(0); lXHDiff2->SetStats(0); lHDiff->SetStats(0); lHDiffH->SetStats(0); lHDiffL->SetStats(0); lHDiffH1->SetStats(0); lHDiffL1->SetStats(0); lXHDiff1->Draw("hist"); lXHDiff2->Draw("hist sames"); lHDiff->Draw("EP sames"); lHDiffH ->Draw("hist sames"); lHDiffL ->Draw("hist sames"); lHDiffH1->Draw("hist sames"); lHDiffL1->Draw("hist sames"); }
void plotEvtSelEff() { gStyle->SetOptStat(0); TFile *f = new TFile("../test/ROOTupleMC_HighPurity.root"); TH1F *hNSD = (TH1F*) f->Get("preTrgAna/hGenMultNSD"); TH1F *hNSDtrg = (TH1F*) f->Get("postTrgAna/hGenMultNSD"); TH1F *hNSDevt = (TH1F*) f->Get("postEvtSelAna/hGenMultNSD"); TH1F *hNSDvtx = (TH1F*) f->Get("postVtxAna/hGenMultNSD"); TH1F *hNSDtrkvtx = (TH1F*) f->Get("postTrkVtxAna/hGenMultNSD"); TGraphAsymmErrors *gNSDtrg = new TGraphAsymmErrors(); TGraphAsymmErrors *gNSDevt = new TGraphAsymmErrors(); TGraphAsymmErrors *gNSDvtx = new TGraphAsymmErrors(); TGraphAsymmErrors *gNSDtrkvtx = new TGraphAsymmErrors(); gNSDtrg->BayesDivide(hNSDtrg,hNSD); gNSDevt->BayesDivide(hNSDevt,hNSD); gNSDvtx->BayesDivide(hNSDvtx,hNSD); gNSDtrkvtx->BayesDivide(hNSDtrkvtx,hNSD); TH1F *dum1 = new TH1F("dum1",";Charged-particle multiplicity;Fraction of events",100,0,100); dum1->SetMaximum(0.05); dum1->GetYaxis()->SetTitleOffset(1.8); TH1F *dum2 = new TH1F("dum2",";Charged-particle multiplicity;Selection efficiency",100,0,60); TCanvas *c1 = new TCanvas("c1","Event Selection",900,500); c1->Divide(2,1); c1->cd(1); dum1->Draw(); hNSDtrkvtx->Sumw2(); hNSDtrkvtx->Scale(1./hNSDtrkvtx->GetEntries()); hNSDtrkvtx->SetMarkerStyle(24); hNSDtrkvtx->Draw("pzsame"); hNSDvtx->Sumw2(); hNSDvtx->Scale(1./hNSDvtx->GetEntries()); hNSDvtx->SetMarkerStyle(20); hNSDvtx->Draw("pzsame"); c1->cd(2); dum2->Draw(); gNSDtrkvtx->SetMarkerStyle(24); gNSDtrkvtx->Draw("pzsame"); gNSDvtx->SetMarkerStyle(20); gNSDvtx->Draw("pzsame"); }
void plotBkgModel(TList* HistList, std::string name){ gROOT->SetBatch(); system("mkdir -p plots/ada/bkgMod"); system("mkdir -p plots/grad/bkgMod"); std::string bdt; TString str = HistList->At(0)->GetName(); if (str.Contains("ada")) bdt="ada"; else if (str.Contains("grad")) bdt="grad"; else std::cout << "Error find BDT type" << std::endl; assert (str.Contains("ada") || str.Contains("grad")); gStyle->SetOptStat(0); gROOT->SetStyle("Plain"); gROOT->ForceStyle(); int color[6] = {kGreen+4,kGreen-1,kGreen,kRed,kRed-2,kRed+4}; TCanvas *canv = new TCanvas(); TLegend *leg = new TLegend(0.45,0.6,0.85,0.85); leg->SetLineColor(0); leg->SetFillColor(0); TPaveText *txt = new TPaveText(0.2,0.1,0.4,0.35,"NDC"); txt->SetFillColor(0); txt->SetLineColor(0); txt->AddText("#int L = 4.76 fb^{-1}"); for (int i=1; i<HistList->GetEntries(); i++){ //if (((TH1F*)HistList->At(i))->GetNbinsX()!=((TH1F*)HistList->At(0))->GetNbinsX()) std::cout << "Plot problem: calling plot for histograms with different number of bins" << std::endl; //assert (((TH1F*)HistList->At(i))->GetNbinsX()==((TH1F*)HistList->At(0))->GetNbinsX()); TH1F *temp = linearBin((TH1F*)HistList->At(i)); temp->Scale(((TH1F*)HistList->At(0))->Integral()/temp->Integral()); temp->SetLineColor(color[i-1]); temp->SetMarkerStyle(20); temp->SetMarkerColor(color[i-1]); temp->SetTitle(Form("Data in sidebands %s %s",bdt.c_str(),name.c_str())); temp->GetXaxis()->SetTitle(""); temp->GetYaxis()->SetRangeUser(1.0,2.*(((TH1F*)HistList->At(0))->GetMaximum())); if (i==1) temp->Draw("p"); else temp->Draw("same p"); if (i==1) leg->AddEntry(temp,"Low 3 sideband","lep"); if (i==2) leg->AddEntry(temp,"Low 2 sideband","lep"); if (i==3) leg->AddEntry(temp,"Low 1 sideband","lep"); if (i==4) leg->AddEntry(temp,"High 1 sideband","lep"); if (i==5) leg->AddEntry(temp,"High 2 sideband","lep"); if (i==6) leg->AddEntry(temp,"High 3 sideband","lep"); } leg->Draw("same"); txt->Draw("same"); canv->SetLogy(); canv->Print(("plots/"+bdt+"/bkgMod/"+name+".png").c_str(),"png"); delete canv; delete txt; delete leg; bkgCalls++; }
CheckEnabledChannels(const Char_t *runlist) { ifstream is(runlist); Char_t buf[4096]; Int_t run[1024]; Int_t nrun = 0; while(!is.eof()) { is.getline(buf, 4096); if (is.eof()) break; run[nrun] = atoi(buf); printf("added run number %d\n", run[nrun]); nrun++; } printf("%d runs added\n", nrun); is.close(); TH1F *hActive = new TH1F("hActive", "active channels;run;fraction", nrun, 0, nrun); TH1F *hReadout = new TH1F("hReadout", "good readout;run;fraction", nrun, 0, nrun); for (Int_t irun = 0; irun < nrun; irun++) { hr = CheckEnabledChannels(run[irun], kTRUE); ha = CheckEnabledChannels(run[irun], kFALSE); hReadout->SetBinContent(irun + 1, hr->Integral()); hActive->SetBinContent(irun + 1, ha->Integral()); hReadout->GetXaxis()->SetBinLabel(irun + 1, Form("%d", run[irun])); delete hr; delete ha; } hReadout->SetMarkerStyle(20); hReadout->SetMarkerColor(4); hActive->SetMarkerStyle(25); hActive->SetMarkerColor(2); hReadout->Sumw2(); hActive->Sumw2(); hReadout->Divide(hReadout, hActive, 1., 1., "B"); hActive->Scale(1. / 152928.); hReadout->SetMinimum(0.); hReadout->SetMaximum(1.); hReadout->Draw("E"); hActive->Draw("E, same"); TLegend *l = gPad->BuildLegend(); l->SetFillStyle(0); }
void draw_ratio(std::vector<TH1F*> h, TString name, TString xTitle, double xmin, double xmax, TString legHeader = "", bool legRIGHT = true, bool legTOP = true, bool logX = false, bool stat = false, int rebin = -1, int orbin = -1, TString option = "", int nclus = 99) { //double ymin_ratio, double ymax_ratio, TCanvas* can = new TCanvas(name+"_ratio",name+"_ratio",900,450); can->cd(); double legxmin = (legRIGHT ? 0.55 : 0.18); double legxmax = legxmin+0.25; double legymin = (legTOP ? 0.70 : 0.15); double legymax = legymin+0.15; TLegend* leg = new TLegend(legxmin,legymin,legxmax,legymax); if (legHeader!="") leg->SetHeader(legHeader); leg->SetTextSize(0.04); leg->SetFillColor(0); leg->SetLineColor(0); TString options = (option=="" ? "pe" : option); if (rebin>0) h[h.size()-1]->Rebin(rebin); //to rebin benchmark before divide for (size_t i=0; i<h.size(); i++) { //if(h[i]->GetNbinsX() != orbin) cout << "WARNING: orbin for " << h[i]->GetName() << " are " << h[i]->GetNbinsX() << endl; //debug - shift of h[][] wrt clu[][] if (rebin>0 && i<(h.size()-1)) h[i]->Rebin(rebin); TH1F* ratio = (TH1F*)h[i]->Clone("ratio_"+name); ratio->Sumw2(); ratio->Divide(h[h.size()-1]); //benchmark is at the end. if (logX) gPad->SetLogx(); ratio->SetMarkerStyle(20+i); ratio->SetMarkerSize(1.0); //1.2 ratio->GetXaxis()->SetRangeUser(xmin,xmax); ratio->SetMinimum(-0.1); ratio->SetMaximum(4); if (i==0){ //just for the first one ratio->GetXaxis()->SetLabelSize(0.05); ratio->GetXaxis()->SetTitle(xTitle); ratio->GetXaxis()->SetTitleOffset(1); ratio->GetXaxis()->SetTitleSize(0.06); ratio->GetYaxis()->SetTitle("ratio"); ratio->GetYaxis()->SetTitleSize(0.06); ratio->GetYaxis()->SetTitleOffset(0.7); ratio->GetYaxis()->SetLabelSize(0.05); } string nam = ""; nam = translate(clu[nclus][0].c_str()); if(i==(h.size()-1)) leg->AddEntry(h[i],nam.c_str(),"l"); //to print only benchmark (first in the list) if (i==1) options = options + (stat ? "sames" : "same"); //once is enought ratio->Draw(options); } leg->Draw("same"); drawPrivate(0.04); can->Update(); can->SaveAs(Outfolder+name+"_ratio.png"); }
void SetDataStyle(TH1F & ele) { ele.SetMarkerColor(1); ele.SetLineColor(1); ele.SetFillColor(1); ele.SetFillStyle(0); ele.SetLineWidth(2); ele.SetMarkerStyle(20); ele.SetMarkerSize(1.1); return; }
TH1F* CreateHisto(const char* name, const char* title, Int_t nBins, Double_t xMin, Double_t xMax, const char* xLabel = NULL, const char* yLabel = NULL) { // create a histogram TH1F* result = new TH1F(name, title, nBins, xMin, xMax); result->SetOption("E"); if (xLabel) result->GetXaxis()->SetTitle(xLabel); if (yLabel) result->GetYaxis()->SetTitle(yLabel); result->SetMarkerStyle(kFullCircle); return result; }
/// /// Make a plot out of a 1D histogram holding a 1-CL curve. /// This is a fall back function that does no fancy stuff. /// /// \param s The scanner to plot. /// \param first Set this to true for the first plotted scanner. /// void OneMinusClPlot::scan1dPlotSimple(MethodAbsScan* s, bool first, int CLsType) { if ( arg->debug ){ cout << "OneMinusClPlot::scan1dPlotSimple() : plotting "; cout << s->getName() << " (" << s->getMethodName() << ")" << endl; } m_mainCanvas->cd(); TH1F *hCL = (TH1F*)s->getHCL()->Clone(getUniqueRootName()); if (CLsType==1) hCL = (TH1F*)s->getHCLs()->Clone(getUniqueRootName()); else if (CLsType==2) hCL = (TH1F*)s->getHCLsFreq()->Clone(getUniqueRootName()); // get rid of nan and inf for ( int i=1; i<=hCL->GetNbinsX(); i++ ){ if ( hCL->GetBinContent(i)!=hCL->GetBinContent(i) || std::isinf(hCL->GetBinContent(i)) ) hCL->SetBinContent(i, 0.0); } int color = s->getLineColor(); if(CLsType==1) color = color + 2 ; hCL->SetStats(0); hCL->SetLineColor(color); hCL->SetMarkerColor(color); hCL->SetLineWidth(2); hCL->SetLineStyle(s->getLineStyle()); hCL->SetMarkerColor(color); hCL->SetMarkerStyle(8); hCL->SetMarkerSize(0.6); hCL->GetYaxis()->SetNdivisions(407, true); hCL->GetXaxis()->SetTitle(s->getScanVar1()->GetTitle()); hCL->GetYaxis()->SetTitle("1-CL"); hCL->GetXaxis()->SetLabelFont(font); hCL->GetYaxis()->SetLabelFont(font); hCL->GetXaxis()->SetTitleFont(font); hCL->GetYaxis()->SetTitleFont(font); hCL->GetXaxis()->SetTitleOffset(0.9); hCL->GetYaxis()->SetTitleOffset(0.85); hCL->GetXaxis()->SetLabelSize(labelsize); hCL->GetYaxis()->SetLabelSize(labelsize); hCL->GetXaxis()->SetTitleSize(titlesize); hCL->GetYaxis()->SetTitleSize(titlesize); if ( plotLegend && !arg->isQuickhack(22) ){ if ( arg->plotlog ) hCL->GetYaxis()->SetRangeUser(1e-3,10); else hCL->GetYaxis()->SetRangeUser(0.0,1.3); } else{ if ( arg->plotlog ) hCL->GetYaxis()->SetRangeUser(1e-3,1); else hCL->GetYaxis()->SetRangeUser(0.0,1.0); } hCL->Draw(first?"":"same"); }
void PlotParsDistr(TFile* f, TTree* tr, TString strMillepedeRes, TString strOutdir) { for (int isubd=PXB; isubd<=TEC; isubd++){ TString canvName="c_"; canvName+=strMillepedeRes; canvName+="_"; canvName+=StrPlotType(PARS); canvName+="_"; canvName+=subdLabels[isubd]; canvName.ReplaceAll(".res",""); f->cd(); TCanvas* canv = new TCanvas(canvName,canvName,600,600); canv->Divide(3,3); for (int parInd=1; parInd<=9; parInd++){ canv->cd(parInd); TString strCut="((label%20-1)%9+1)=="; strCut+=parInd; strCut+=" && label<700000 && "; strCut+=StrCutSubd(isubd); TString hName="hPars_"; hName+=subdLabels[isubd]; hName+="_"; hName+= StrPar(parInd); TTree* trCut = tr->CopyTree(strCut); float up = trCut->GetMaximum("parVal"); float low = trCut->GetMinimum("parVal"); std::cout<<"low="<<low<<", up="<<up<<", nent="<<trCut->GetEntries()<<std::endl; TH1F* h = new TH1F(hName,hName,100,10000*low,10000*up); TString strDraw="10000*parVal>>"; strDraw+=hName; trCut->Draw(strDraw,strCut,"goff"); h->SetMarkerStyle(2); h->Draw("EP"); }// end of loop over parInd canvName+=".png"; TString saveName=strOutdir+canvName; canv->SaveAs(saveName); saveName.ReplaceAll(".png",".pdf"); canv->SaveAs(saveName); }//end of loop over isubd }// end of PlotParsDistr
TH1F* newDumHistForLegend(const Plot_t* hist) { // caller is responsible for deleting the hist TH1F* h = 0; if (hist!=0) { TString hn(Form("%s_leg%s",hist->GetName(), (gPad!=0) ? gPad->GetName() : "")); h = new TH1F(hn.Data(), "", 1, 0, 1); h->SetFillColor(hist->GetLineColor()); h->SetLineColor(kWhite); h->SetMarkerColor(kWhite); h->SetMarkerStyle(hist->GetMarkerStyle()); h->SetMarkerSize(1); h->SetBit(TObject::kCanDelete); } return h; }
void binomialEfficiency1D(TH1F * numerator,TH1F * denominator){ TH1F * efficiency = numerator->Clone("efficiency"); efficiency->SetXTitle(numerator->GetXaxis()->GetTitle()); efficiency->SetYTitle("#epsilon"); for(int j=0;j<=numerator->GetXaxis()->GetNbins() ;j++){ if(denominator->GetBinContent(j)!=0){ float eff = numerator->GetBinContent(j)/denominator->GetBinContent(j); float err = sqrt(eff*(1-eff)/denominator->GetBinContent(j)); efficiency->SetBinContent(j,eff); efficiency->SetBinError(j,err); cout<<"1Deff "<<j<<" "<<eff<<" +/- "<<err<<endl; } } efficiency->Draw("E"); efficiency->SetMarkerColor(kRed); efficiency->SetMarkerStyle(23); efficiency->SetMarkerSize(2); }
//------------------------------------------------------------// // Get histogram //------------------------------------------------------------// TH1F* getHist(TFile* file, TString pname, TString xtitle, TString ytitle, int color, int marker) { TH1F* hist = (TH1F*) (file->Get(pname.Data())->Clone(Form("%s_%i",pname.Data(),color))); hist->GetXaxis()->SetTitle(xtitle.Data()); hist->GetYaxis()->SetTitle(ytitle.Data()); hist->SetMarkerStyle(marker); hist->SetMarkerColor(color); hist->SetMarkerSize(0.5); hist->SetLineColor(color); hist->SetTitle(""); hist->SetStats(0); hist->GetYaxis()->SetTitleOffset(1.5); hist->SetLineWidth(2); return hist; }
void closureTesterFSR(void) { TString REGIME = ""; //_corr //2D case TFile* g = new TFile("../Inputs/unfold/unfoldData_HLT_Double_2D_NoTRM.root"); g->cd(); TH1F* unfolded = (TH1F*)gDirectory->Get("hunfolded"); //FSR correction TFile* gg = new TFile("../Inputs/FSR/BinByBin.root"); gg->cd(); TH1F* FSRcorr_num = (TH1F*)gDirectory->Get("hpostFSR2"); TH1F* FSRcorr_den = (TH1F*)gDirectory->Get("hpreFSR2"); TH1F* FSRcorr = (TH1F*)FSRcorr_num->Clone(); FSRcorr->Divide(FSRcorr_num,FSRcorr_den); for (int i = 0; i < 132; i++) { unfolded->SetBinContent(i+1,unfolded->GetBinContent(i+1)*FSRcorr->GetBinContent(i+1)); } unfolded->SetMarkerStyle(22); unfolded->GetXaxis()->SetTitle("Bin number"); unfolded->GetYaxis()->SetTitle("Events"); unfolded->Draw("hist"); TH1D* other = (TH1D*)unfolded->Clone(); other->SetMarkerStyle(22); other->SetMarkerColor(kRed); other->SetLineColor(kRed); other->Draw("Psame"); TCanvas* c = new TCanvas(); c->cd(); TH1D* ratio = (TH1D*)unfolded->Clone(); ratio->Divide(other,unfolded); ratio->SetMarkerStyle(22); ratio->GetXaxis()->SetTitle("N_{unfolded}/N_{preunfolded}"); ratio->GetXaxis()->SetTitle("Bin number"); ratio->Draw("P"); }
void sigHist(TChain & EventsVBF, TChain & EventsGF, string variable, string title, int nBins, float min, float max, float GF, float VBF ){ TCanvas c(""); TH1F *hVBF = new TH1F("hVBF","hVBF", nBins, min, max); TH1F *hGF = new TH1F("hGF","hGF", nBins, min, max); EventsVBF.Project("hVBF",variable.c_str() ); EventsGF.Project("hGF",variable.c_str() ); //hVBF->Draw(); EventsVBF.Draw("h.mass()"); TH1F * h = new TH1F(title.c_str(),title.c_str(), nBins, min,max); h->Add(hVBF,hGF,VBF,GF); h->SetLineColor(kBlue+1); h->SetFillColor(kAzure+7); //h->SetLineColor(kMagenta+3); //h->SetFillColor(kMagenta-3); // h->SetLineColor(kTeal+3); // h->SetFillColor(kTeal+2); // h->SetLineColor(kOrange+7); // h->SetFillColor(kYellow-9); h->SetMarkerStyle(0); h->SetTitle( ("H350, "+title).c_str() ); h->SetXTitle("m_{H} (GeV/c^{2})"); //h->hGF->GetXaxis()->SeXmin(); //h->Scale(1/h->GetEntries()); h->Draw("HIST"); h->Write(); //c.SaveAs( (title+".eps").c_str() ); delete hVBF; delete hGF; delete h; }
float GoodRun(int icent, int ihar, int isub, int irun){ float pi = acos(-1); TF1 *fun = new TF1("fun","pol0",-pi,pi); TString str; TFile *fin; ofstream fout; if(isub==1){ str = "FVTX1S"; } else if(isub==2){ str = "FVTX2S"; } else return -9999; fin = TFile::Open(Form("Run15pAu200MinBias/output_fvtxwithcntEP_%d.root",GetRun(irun))); TH1F* hpsi = new TH1F("psi","psi",100,-pi,pi); for(int ibbcz=0;ibbcz<nbbcz;ibbcz++){ hpsitemp = (TH1F*)fin->Get(Form("psi_%d_%d_%d_%d",icent,ibbcz,ihar,isub)); hpsi->Add(hpsitemp); } if(hpsi->GetEntries()>10000){ hpsi->SetMarkerStyle(20); hpsi->SetMarkerSize(0.6); hpsi->SetMarkerColor(4); hpsi->SetMinimum(10); hpsi->Fit("fun","QR0"); float par=fun->GetParameter(0); hpsi->SetMaximum(1.5*par); //hpsi->Draw(); fin->Close(); return fun->GetChisquare()/fun->GetNDF(); } else{ fin->Close(); return -9999; } }
void plotRegrVsNoRegr(int channel, int massBin) { stringstream filenom, filenoregr; filenom << "m4lplots/nominal/fitM" << massBin << "_channel" << channel << ".root"; filenoregr << "m4lplots/noregr/fitM" << massBin << "_channel" << channel << ".root"; int col; if(channel==0) col=kOrange+7; if(channel==1) col=kAzure+2; if(channel==2) col=kGreen+3; TCanvas *c1 = new TCanvas("c1","c1",750,750); TFile *tfilenom = TFile::Open(filenom.str().c_str()); RooPlot *plotnom = (RooPlot*)tfilenom->Get("m4lplot"); plotnom->SetMarkerStyle(kOpenSquare); plotnom->Draw(); TPaveText *pavenom = (TPaveText*)tfilenom->Get("TPave"); pavenom->SetTextColor(col); pavenom->Draw("same"); TFile *tfilenoregr = TFile::Open(filenoregr.str().c_str()); RooPlot *plotnoregr = (RooPlot*)tfilenoregr->Get("m4lplot"); plotnoregr->Draw("same"); TPaveText *pavenoregr = (TPaveText*)tfilenoregr->Get("TPave"); pavenoregr->Draw("same"); // cosmetics TLegend *legend = new TLegend(0.20,0.45,0.45,0.60,NULL,"brNDC"); legend->SetBorderSize( 0); legend->SetFillColor ( 0); legend->SetTextAlign ( 12); legend->SetTextFont ( 42); legend->SetTextSize (0.03); TH1F *dummyPointsNom = new TH1F("dummyPNom","dummyPNom",1,0,1); TH1F *dummyPointsNoRegr = new TH1F("dummyPNoregr","dummyPNoregr",1,0,1); TH1F *dummyLine = new TH1F("dummyL","dummyL",1,0,1); dummyPointsNoRegr->SetMarkerStyle(kFullCircle); dummyPointsNoRegr->SetMarkerSize(1.1); dummyPointsNom->SetMarkerStyle(kFullSquare); dummyPointsNom->SetMarkerColor(col); dummyPointsNom->SetLineColor(col); dummyPointsNom->SetMarkerSize(1.1); dummyLine->SetLineColor(col); legend->AddEntry(dummyPointsNoRegr, "Simulation (E_{std}-p comb.)", "pel"); legend->AddEntry(dummyPointsNom, "Simulation (E_{regr}-p comb.)", "pel"); legend->Draw(); TPaveText *text = new TPaveText(0.15,0.90,0.77,0.98,"brNDC"); text->AddText("CMS Simulation"); text->SetBorderSize(0); text->SetFillStyle(0); text->SetTextAlign(12); text->SetTextFont(42); text->SetTextSize(0.03); text->Draw(); stringstream frameTitle; if(channel==0){frameTitle << "4#mu, m_{H} = ";} if(channel==1){frameTitle << "4e, m_{H} = ";} if(channel==2){frameTitle << "2e2#mu, m_{H} = ";} frameTitle << massBin << " GeV"; TPaveText *titlet = new TPaveText(0.15,0.80,0.60,0.85,"brNDC"); titlet->AddText(frameTitle.str().c_str()); titlet->SetBorderSize(0); titlet->SetFillStyle(0); titlet->SetTextAlign(12); titlet->SetTextFont(132); titlet->SetTextSize(0.045); titlet->Draw(); c1->SaveAs("comp.pdf"); }
void fitSignalShapeW(int massBin,int id, int channels,int categ, int sample, /* float lumi, bool doSfLepton, */double rangeLow, double rangeHigh, double bwSigma, double fitValues[9], double fitErrors[9], double covQual[1]){ // ------ root settings --------- gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPadGridX(kFALSE); gStyle->SetPadGridY(kFALSE); //gStyle->SetOptStat("kKsSiourRmMen"); gStyle->SetOptStat("iourme"); //gStyle->SetOptStat("rme"); //gStyle->SetOptStat(""); gStyle->SetOptFit(11); gStyle->SetPadLeftMargin(0.14); gStyle->SetPadRightMargin(0.06); // ------------------------------ ROOT::Math::MinimizerOptions::SetDefaultTolerance( 1.E-7); stringstream FileName; //Insert the file here if(sample==1) FileName <<"root://lxcms03//data3/Higgs/150915/ZH125/ZZ4lAnalysis.root" ; else if(sample==2) FileName << "root://lxcms03//data3/Higgs/150915/WplusH125/ZZ4lAnalysis.root"; else if(sample==3) FileName << "root://lxcms03//data3/Higgs/150915/WminusH125/ZZ4lAnalysis.root"; else if(sample==4) FileName << "root://lxcms03//data3/Higgs/150915/ttH125/ZZ4lAnalysis.root"; else { cout << "Wrong sample." << endl; return; } cout << "Using " << FileName.str() << endl; TFile* ggFile = TFile::Open(FileName.str().c_str()); TTree* ggTree = (TTree*) ggFile->Get("ZZTree/candTree"); float m4l; Short_t z1flav, z2flav; float weight; Short_t nExtraLeptons; float ZZPt; Short_t nJets; Short_t nBTaggedJets; std::vector<float> * jetpt = 0; std::vector<float> * jeteta = 0; std::vector<float> * jetphi = 0; std::vector<float> * jetmass = 0; float jet30pt[10]; float jet30eta[10]; float jet30phi[10]; float jet30mass[10]; float Fisher; int nentries = ggTree->GetEntries(); //--- ggTree part ggTree->SetBranchAddress("ZZMass",&m4l); ggTree->SetBranchAddress("Z1Flav",&z1flav); ggTree->SetBranchAddress("Z2Flav",&z2flav); ggTree->SetBranchAddress("genHEPMCweight",&weight); ggTree->SetBranchAddress("nExtraLep",&nExtraLeptons); ggTree->SetBranchAddress("nCleanedJets",&nJets); ggTree->SetBranchAddress("nCleanedJetsPt30BTagged",&nBTaggedJets); ggTree->SetBranchAddress("DiJetFisher",&Fisher); ggTree->SetBranchAddress("JetPt",&jetpt); ggTree->SetBranchAddress("JetEta",&jeteta); ggTree->SetBranchAddress("JetPhi",&jetphi); ggTree->SetBranchAddress("JetMass",&jetmass); ggTree->SetBranchAddress("ZZPt",&ZZPt); //--- rooFit part double xMin,xMax,xInit; xInit = (double) massBin; xMin = rangeLow; xMax = rangeHigh ; cout << "Fit range: [" << xMin << " , " << xMax << "]. Init value = " << xInit << endl; TH1F *hmass = new TH1F("hmass","hmass",200,xMin,xMax); //--------- RooRealVar x("mass","m_{4l}",xInit,xMin,xMax,"GeV"); RooRealVar w("myW","myW",1.0,0.,1000.); RooArgSet ntupleVarSet(x,w); RooDataSet dataset("mass4l","mass4l",ntupleVarSet,WeightVar("myW")); for(int k=0; k<nentries; k++){ ggTree->GetEvent(k); int njet30 = 0; for (unsigned int ijet = 0; ijet < jetpt->size(); ijet++) { if ( (*jetpt)[ijet] > 30. ) { jet30pt[njet30] = (*jetpt)[ijet]; jet30eta[njet30] = (*jeteta)[ijet]; jet30phi[njet30] = (*jetphi)[ijet]; jet30mass[njet30] = (*jetmass)[ijet]; njet30++; } } int Cat = category(nExtraLeptons, ZZPt, m4l, njet30, nBTaggedJets, jet30pt, jet30eta, jet30phi,jet30mass, Fisher); if (categ >= 0 && categ != Cat ) continue; if(channels==0 && z1flav*z2flav != 28561) continue; if(channels==1 && z1flav*z2flav != 14641) continue; if (weight <= 0 ) cout << "Warning! Negative weight events" << endl; if(channels==2 && z1flav*z2flav != 20449) continue; ntupleVarSet.setRealValue("mass",m4l); ntupleVarSet.setRealValue("myW",weight); if(x.getVal()>xMin && x.getVal()<xMax) dataset.add(ntupleVarSet, weight); hmass->Fill(m4l); } //--------- cout << "dataset n entries: " << dataset.sumEntries() << endl; TCanvas *c1 = new TCanvas("c1","c1",725,725); c1->cd(); TPad *pad1 = new TPad("pad1","This is pad1",0.05,0.35,0.95,0.97); pad1->Draw(); TPad *pad2 = new TPad("pad2","This is pad2",0.05,0.02,0.95,0.35); pad2->Draw(); //--- double CrystalBall RooRealVar mean("bias","mean of gaussian",0,-5.,5.) ; RooRealVar sigma("sigma","width of gaussian",1.5,0.,30.); RooRealVar a1("a1","a1",1.46,0.5,5.); RooRealVar n1("n1","n1",1.92,0.,10.); RooRealVar a2("a2","a2",1.46,1.,10.); RooRealVar n2("n2","n2",20,1.,50.); RooDoubleCB DCBall("DCBall","Double Crystal ball",x,mean,sigma,a1,n1,a2,n2); if (channels== 1) mean.setVal(-1.); //--- Breit-Wigner float bwSigmaMax,bwSigmaMin; if(massBin<400) bwSigmaMin=bwSigmaMax=bwSigma; else { bwSigmaMin=bwSigma-20.; bwSigmaMax=bwSigma+20.; } RooRealVar mean3("mean3","mean3",xInit) ; RooRealVar sigma3("sigma3","width3",bwSigma,bwSigmaMin,bwSigmaMax); RooRealVar scale3("scale3","scale3 ",1.); RooRelBWUFParam bw("bw","bw",x,mean3,scale3); //Chebyshev-Polynomial RooRealVar A1("A1","A1",-1,-3,3.); RooRealVar A2("A2","A2",0.5,-3.,3.); RooChebychev BkgPDF("BkgPDF","BkgPDF",x ,RooArgList(A1,A2)); //Fraction RooRealVar frac("frac","Fraction for PDF",0.5,0.,1.); x.setBins(10000,"fft"); RooFFTConvPdf model("model","model",x,bw,DCBall); RooAddPdf totPDF("totPDF","Total PDF ",RooArgList(model,BkgPDF),RooArgList(frac)); RooArgSet* params = totPDF.getParameters(x); if(sample!=1 && categ!=0 && id!=125){ if(channels==0 ){params->readFromFile("Ch0_Cat0_paraT.txt");}// Read the Parameter for the Resonance + Bkg(ChebyChev) if(channels==1 ){params->readFromFile("Ch1_Cat0_paraT.txt");}// Read the Parameter for the Resonance + Bkg(ChebyChev) if(channels==2 ){params->readFromFile("Ch2_Cat0_paraT.txt");}// Read the Parameter for the Resonance + Bkg(ChebyChev) } RooFitResult *fitres = (RooFitResult*)totPDF.fitTo(dataset,SumW2Error(1),Range(xMin,xMax),Strategy(2),NumCPU(8),Save(true)); if (sample==1 && categ==0 && id==125){ mean.setConstant(kTRUE); sigma.setConstant(kTRUE); a1.setConstant(kTRUE); n1.setConstant(kTRUE); a2.setConstant(kTRUE); n2.setConstant(kTRUE); mean3.setConstant(kTRUE); sigma3.setConstant(kTRUE); scale3.setConstant(kTRUE); A1.setConstant(kTRUE); A2.setConstant(kTRUE); frac.setConstant(kTRUE); if(channels==0 ){ params->readFromFile("Ch0_Cat0_para.txt"); // Read the Parameter for the Resonance as ggH sample params->writeToFile("Ch0_Cat0_paraT.txt");} // Writing the Parameter for Full PDF including the Chebyshev-Polynomial if(channels==1 ) {params->readFromFile("Ch1_Cat0_para.txt"); // Read the Parameter for the Resonance as in ggH sample params->writeToFile("Ch1_Cat0_paraT.txt");}// Writing the Parameter for Full PDF including the Chebyshev-Polynomial if(channels==2 ){ params->readFromFile("Ch2_Cat0_para.txt"); // Read the Parameter for the Resonance as ggH sample params->writeToFile("Ch2_Cat0_paraT.txt");}// Writing the Parameter for Full PDF including the Chebyshev-Polynomial } stringstream frameTitle; if(channels==0){frameTitle << "4#mu, m_{H} = "; } if(channels==1){frameTitle << "4e, m_{H} = ";} if(channels==2){frameTitle << "2e2#mu, m_{H} = ";} frameTitle << massBin << " GeV"; stringstream nameFileRoot; nameFileRoot << "fitM" << massBin << ".root"; TFile *fileplot = TFile::Open(nameFileRoot.str().c_str(), "recreate"); RooPlot* xframe = x.frame() ; xframe->SetTitle(""); xframe->SetName("m4lplot"); dataset.plotOn(xframe,DataError(RooAbsData::SumW2), MarkerStyle(kOpenCircle), MarkerSize(1.1) ); int col; if(channels==0) col=kOrange+7; if(channels==1) col=kAzure+2; if(channels==2) col=kGreen+3; totPDF.plotOn(xframe,LineColor(col)); RooHist* hpull = xframe->pullHist(); RooPlot* frame3 = x.frame(Title("Pull Distribution")) ; frame3->addPlotable(hpull,"P"); // cosmetics TLegend *legend = new TLegend(0.20,0.45,0.45,0.60,NULL,"brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); legend->SetTextAlign(12); legend->SetTextFont (42); legend->SetTextSize (0.03); TH1F *dummyPoints = new TH1F("dummyP","dummyP",1,0,1); TH1F *dummyLine = new TH1F("dummyL","dummyL",1,0,1); dummyPoints->SetMarkerStyle(kOpenCircle); dummyPoints->SetMarkerSize(1.1); dummyLine->SetLineColor(col); legend->AddEntry(dummyPoints, "Simulation", "pe"); legend->AddEntry(dummyLine, "Parametric Model", "l"); TPaveText *text = new TPaveText(0.15,0.90,0.77,0.98,"brNDC"); text->AddText("CMS Simulation"); text->SetBorderSize(0); text->SetFillStyle(0); text->SetTextAlign(12); text->SetTextFont(42); text->SetTextSize(0.03); TPaveText *titlet = new TPaveText(0.15,0.80,0.60,0.85,"brNDC"); titlet->AddText(frameTitle.str().c_str()); titlet->SetBorderSize(0); titlet->SetFillStyle(0); titlet->SetTextAlign(12); titlet->SetTextFont(132); titlet->SetTextSize(0.045); TPaveText *sigmat = new TPaveText(0.15,0.65,0.77,0.78,"brNDC"); stringstream sigmaval0, sigmaval1, sigmaval2; sigmaval0 << fixed; sigmaval0 << setprecision(1); sigmaval0 << "m_{dCB} = " << mean.getVal() + massBin << " GeV"; sigmaval1 << fixed; sigmaval1 << setprecision(1); sigmaval1 << "#sigma_{dCB} = " << sigma.getVal() << " GeV"; sigmaval2 << fixed; sigmaval2 << setprecision(1); sigmaval2 << "RMS_{eff} = " << effSigma(hmass) << " GeV"; sigmat->AddText(sigmaval1.str().c_str()); sigmat->AddText(sigmaval2.str().c_str()); sigmat->SetBorderSize(0); sigmat->SetFillStyle(0); sigmat->SetTextAlign(12); sigmat->SetTextFont(132); sigmat->SetTextSize(0.04); xframe->GetYaxis()->SetTitleOffset(1.5); cout << "EFF RMS = " << effSigma(hmass) << " RMS = " << hmass->GetRMS() << endl; pad1->cd(); stringstream nameFile, nameFileC, nameFilePng; nameFile << "fitM" << massBin << "_channel" << channels<< "_category"<< categ << ".pdf"; nameFileC << "fitM" << massBin << "_channel" << channels << "_category"<< categ << ".C"; nameFilePng << "fitM" << massBin << "_channel" << channels << "_category"<< categ << ".png"; xframe->Draw(); gPad->Update(); legend->Draw(); text->Draw(); sigmat->Draw(); titlet->Draw(); pad2->cd() ; frame3->Draw() ; frame3->SetMinimum(-3); frame3->SetMaximum(3); TLine *line1 = new TLine(105,0,140,0); line1->SetLineColor(kRed); line1->Draw(); c1->Print(nameFile.str().c_str()); c1->SaveAs(nameFileC.str().c_str()); c1->SaveAs(nameFilePng.str().c_str()); fileplot->cd(); xframe->Write(); sigmat->Write(); hmass->Write(); fileplot->Close(); if(fitValues!=0){ fitValues[0] = a1.getVal(); fitValues[1] = a2.getVal(); fitValues[2] = mean.getVal(); fitValues[3] = mean3.getVal(); fitValues[4] = n1.getVal(); fitValues[5] = n2.getVal(); fitValues[6] = sigma.getVal(); fitValues[7] = A1.getVal(); fitValues[8] = A2.getVal(); } if(fitErrors!=0){ fitErrors[0] = a1.getError(); fitErrors[1] = a2.getError(); fitErrors[2] = mean.getError(); fitErrors[3] = mean3.getError(); fitErrors[4] = n1.getError(); fitErrors[5] = n2.getError(); fitErrors[6] = sigma.getError(); fitErrors[7] = A1.getError(); fitErrors[8] = A2.getError(); } covQual[0] = fitres->covQual(); }
//___________________________________________________________________________ Double_t* Ifit(int shift, Double_t& dataResult, Double_t& dataErr, std::string dataFile, TH1D* hsig, TH1D* hbkg, TH1D* hEGdata, Double_t* FitPar, int ptbin=30, char EBEE[10]="EB", int fit_data=2) { printf(" *** calling Ifit for %s , ptbin %d *** \n\n", EBEE,ptbin); cout << "The number of bins are: " << endl; cout << "hdata nbins = " << hEGdata->GetNbinsX() << endl; cout << "hsig nbins = " << hsig->GetNbinsX() << endl; cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl; TCanvas *c1 = new TCanvas("HF1", "Histos1", 0, 0, 600, 600); gStyle->SetOptFit(0); if(fit_data != 3) dataColl.clear(); sigColl.clear(); bkgColl.clear(); totalColl.clear(); ctauColl.clear(); Para.clear(); Para_err.clear(); info.clear(); info_err.clear(); float ptmax=0.; if(ptbin== 21) ptmax= 23; if(ptbin== 23) ptmax= 26; if(ptbin== 26) ptmax= 30; if(ptbin== 30) ptmax= 35; if(ptbin== 35) ptmax= 40; if(ptbin== 40) ptmax= 45; if(ptbin== 45) ptmax= 50; if(ptbin== 50) ptmax= 60; if(ptbin== 60) ptmax= 85; if(ptbin== 85) ptmax= 120; if(ptbin== 120) ptmax= 300; if(ptbin== 300) ptmax= 500; Double_t* fitted = new Double_t[6]; fitted[0] = 0.; fitted[1] = 0.; fitted[2] = 0.; fitted[3] = 0.; fitted[4] = 0.; fitted[5] = 0.; char hname[30]; hsig->SetLineColor(1); hbkg->SetLineColor(1); hsig->SetNdivisions(505,"XY"); hbkg->SetNdivisions(505,"XY"); hsig->SetTitle(""); hbkg->SetTitle(""); hsig->SetXTitle("combined ISO (GeV)"); hbkg->SetXTitle("combined ISO (GeV)"); TH1F *hsum = (TH1F*)hsig->Clone(); hsum->Add(hbkg,1); float ntemplate = 1.; if (hsum->Integral()>1.) ntemplate = hsum->Integral(); float sigfrac = hsig->Integral()/ntemplate*0.8; TH1F *hsum_norm = (TH1F*)hsum->Clone(); hsum_norm->Scale(1./hsum->Integral()); TH1F *hdata = new TH1F(); int ndata=0; if ( fit_data==1 ) { hdata = (TH1F*)hEGdata->Clone(); ndata = (int)hdata->Integral(); for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){ for(int ipoint=0; ipoint<hdata->GetBinContent(ibin); ipoint++) { dataColl.push_back(hdata->GetBinCenter(ibin)); } } ndata = dataColl.size(); }else if (fit_data==2 ){ hdata = (TH1F*)hEGdata->Clone(); hdata -> Reset(); dataColl.clear(); FILE *infile = fopen(dataFile.data(),"r"); float xdata, xdata1, xdata2; // combined isolation, pt, eta int flag = 1; while (flag!=-1){ flag =fscanf(infile,"%f %f %f",&xdata, &xdata1, &xdata2); if( xdata1 >= ptbin && xdata1 < ptmax && xdata<20.) { if((strcmp(EBEE,"EB")==0 && TMath::Abs(xdata2)<1.45) || (strcmp(EBEE,"EE")==0 && TMath::Abs(xdata2)<2.5 && TMath::Abs(xdata2)>1.7) ) { dataColl.push_back(xdata); hdata->Fill(xdata); } } }// keep reading files as long as text exists ndata = dataColl.size(); printf("test print data 2 %2.3f \n", dataColl[2]); // cout << "ndata in dataColl = " << ndata << endl; if ( ndata == 0 ) { printf(" no data to fit \n"); return fitted; } } if(ndata==0) { printf(" --- no events in the fit \n"); return fitted; } //test fit the template and get PDFs TCanvas *c10 = new TCanvas("c10","c10",1000,500); c10->Divide(2,1); c10->cd(1); double par[20] = {hsig->GetMaximum(), 1., 0.6, 0.3, hbkg->GetMaximum(), -.45, -0.05, 0.03, 1., 1., 1., 1.}; if(strcmp(EBEE,"EE")==0) { par[2]=-0.1, par[3]=0.2; par[6]=-0.15; par[7]=0.02; }; int fit_status; TF1 *f1 = new TF1("f1", exp_conv, -1., 20., 11); TF1 *fmcsigfit = new TF1("fmcsigfit", exp_conv, -1., 20., 11); fmcsigfit->SetLineColor(4); fmcsigfit->SetLineWidth(2); f1->SetNpx(10000); f1->SetParameters(par); f1->SetLineWidth(2); c10->cd(1); fit_status = hsig->Fit(f1,"","",-1., 5.); hsig->Draw(); f1->Draw("same"); if ( fit_status > 0 ) { printf("fit signal template failed. QUIT \n"); return fitted; } if(para_index>0 && para_index<4){ double tmppar = f1->GetParameter(para_index); f1->SetParameter(para_index, tmppar+para_sigma*f1->GetParError(para_index)); } TF1 *fmcsig = (TF1*)f1->Clone(); TF1 *fmcsigcorr = (TF1*)f1->Clone(); fmcsig->SetNpx(10000); fmcsigcorr->SetNpx(10000); fmcsigfit->SetNpx(10000); TCanvas *c101 = new TCanvas("c101","c101",1000,500); c101->Divide(2,1); c101->cd(1); fmcsig->SetLineColor(1); // fmcsig->Draw(); // f1->Draw("same"); TH1F *htmp1 = (TH1F*)fmcsig->GetHistogram(); // TH1F *htmp2 = (TH1F*)fmcsigcorr->GetHistogram(); TH2F *htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25); htmp2->SetNdivisions(505,"XY"); htmp2->SetXTitle("Iso"); htmp2->SetYTitle("A.U."); htmp2->SetLineColor(1); // htmp2->Draw(); // htmp1->Draw("same"); // htmp2->Add(htmp1,-1); // htmp2->Divide(htmp1); htmp2->GetXaxis()->SetRangeUser(-1., 10.); htmp2->SetMinimum(-1.); //htmp2->SetMaximum(1.5); htmp2->Draw(); fmcsig->Draw("same"); // fmcsigcorr->Draw("same"); TLegend *tleg1 = new TLegend(0.5, 0.7, 0.93, 0.92); tleg1->SetHeader(""); tleg1->SetFillColor(0); tleg1->SetShadowColor(0); tleg1->SetBorderSize(0); tleg1->AddEntry(fmcsig,"Zee data","l"); //tleg1->AddEntry(fmcsigcorr,"corrected shape","l"); tleg1->AddEntry(fmcsigfit,"shape from data","l"); tleg1->Draw(); //return fitted; SigPDFnorm = f1->Integral(-1.,20.); printf("status %d, sig area %3.3f \n", fit_status,f1->Integral(-1., 20.)); f1->SetParameter(2,f1->GetParameter(2)+0.2); f1->SetParameter(3,f1->GetParameter(3)+0.1); Para.push_back(f1->GetParameter(0)); Para.push_back(f1->GetParameter(1)); Para.push_back(f1->GetParameter(2)); Para.push_back(f1->GetParameter(3)); Para_err.push_back(f1->GetParError(0)); Para_err.push_back(f1->GetParError(1)); Para_err.push_back(f1->GetParError(2)); Para_err.push_back(f1->GetParError(3)); c10->cd(2); TF1 *fbkgfit = new TF1("fbkgfit", expinv_power, -1., 20., 11); TF1 *f3 = new TF1("f3", expinv_power, -1., 20., 11); fbkgfit->SetNpx(10000); fbkgfit->SetLineColor(4); fbkgfit->SetLineWidth(2); f3->SetNpx(10000); f3->SetLineWidth(2); f3->SetParameters(f1->GetParameters()); f3->SetParLimits(5,-5.,0.); f3->SetParLimits(6,-0.5,0.); f3->SetParLimits(7,0.001,0.2); f3->SetParLimits(8,0.5,5.); if ( strcmp(EBEE,"EB")==0 ){ // f3->FixParameter(8,1.); // f3->FixParameter(6,-0.1); f3->SetParLimits(8,1.,1.5); } float bkg_bend_power = 1.; if ( ptbin==21 ) bkg_bend_power = 4.5; if ( ptbin==23 ) bkg_bend_power = 4.; if ( ptbin==26 ) bkg_bend_power = 3.5; if ( ptbin==30 ) bkg_bend_power = 2.6; if ( ptbin==35 ) bkg_bend_power = 2.2; if ( ptbin==40 ) bkg_bend_power = 2.; if ( ptbin==45 ) bkg_bend_power = 2.; if ( ptbin==50 ) bkg_bend_power = 1.8; if ( ptbin==60 ) bkg_bend_power = 1.5; if ( ptbin==85 ) bkg_bend_power = 1.; if ( ptbin==120 ) bkg_bend_power = 1.; if ( strcmp(EBEE,"EE")==0 ){ f3->SetParameter(8,bkg_bend_power); f3->SetParLimits(8,bkg_bend_power-1., bkg_bend_power+1.); } f3->FixParameter(0,f3->GetParameter(0)); f3->FixParameter(1,f3->GetParameter(1)); f3->FixParameter(2,f3->GetParameter(2)); f3->FixParameter(3,f3->GetParameter(3)); hbkg->SetMaximum(hbkg->GetMaximum()*3.); fit_status = hbkg->Fit(f3,"b","",-1., 20.); hbkg->Draw(); if ( fit_status > 0 ) { printf("fit background template failed. QUIT \n"); return fitted; }else { f3->Draw("same"); } TF1 *fmcbkg = (TF1*)f3->Clone(); fmcbkg->SetLineColor(1); c101->cd(2); htmp1 = (TH1F*)fmcbkg->GetHistogram(); htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25); htmp2->SetNdivisions(505,"XY"); htmp2->SetXTitle("Iso"); htmp2->SetYTitle("A.U."); htmp2->SetLineColor(1); htmp2->GetXaxis()->SetRangeUser(-1., 20.); htmp2->SetMinimum(-1.); htmp2->SetMaximum(1.5); htmp2->Draw(); fmcbkg->Draw("same"); TLegend *tleg2 = new TLegend(0.25, 0.2, 0.6, 0.42); tleg2->SetHeader(""); tleg2->SetFillColor(0); tleg2->SetShadowColor(0); tleg2->SetBorderSize(0); if ( strcmp(EBEE,"EB")==0 ){ tleg2->AddEntry(fmcbkg,"MC shape","l"); }else { tleg2->AddEntry(fmcbkg,"Data SB shape","l"); } tleg2->AddEntry(fbkgfit,"shape from data","l"); tleg2->Draw(); if(para_index>4){ double tmppar = f3->GetParameter(para_index); f3->SetParameter(para_index, tmppar+para_sigma*f3->GetParError(para_index)); } // f3->SetParameter(5,-0.5); // f3->SetParameter(6,-0.05); // f3->SetParameter(7,0.02); // f3->SetParameter(8,1.); Para.push_back(f3->GetParameter(4)); Para.push_back(f3->GetParameter(5)); Para.push_back(f3->GetParameter(6)); Para.push_back(f3->GetParameter(7)); Para.push_back(f3->GetParameter(8)); Para_err.push_back(f3->GetParError(4)); Para_err.push_back(f3->GetParError(5)); Para_err.push_back(f3->GetParError(6)); Para_err.push_back(f3->GetParError(7)); Para_err.push_back(f3->GetParError(8)); BkgPDFnorm = f3->Integral(-1., 20.); printf("status %d, bkg area %3.3f \n", fit_status,f3->Integral(-1., 20.)/hdata->GetBinWidth(2)); //test PDFs TCanvas *c11 = new TCanvas("c11","c11",1000,500); c11->Divide(2,1); c11->cd(1); TF1 *f11 = new TF1("f11",exp_conv_norm, -1., 20., 11); f11->SetNpx(10000); f11->SetParameters(f3->GetParameters()); f11->Draw(); printf(" SIG PDF area %2.3f \n", f11->Integral(-1., 20.)); c11->cd(2); TF1 *f12 = new TF1("f12",expinv_power_norm, -1., 20., 11); f12->SetNpx(10000); f12->SetParameters(f3->GetParameters()); f12->Draw(); printf(" BKG PDF area %2.3f \n", f12->Integral(-1., 20.)); //c1->cd(); printf(" --------- before the fit ------------- \n"); printf("Nsig %2.3f, Nbg %2.3f, Ntemplate %3.3f \n", hsig->Integral(), hbkg->Integral(), ntemplate); printf("Purity %2.3f, init size %4.3f, fit sample size %4d\n", hsig->Integral()/hsum->Integral(), hsum->Integral(), ndata); printf(" -------------------------------------- \n"); printf( " ----- Got %d, %d, %d events for fit ----- \n ", dataColl.size(), sigColl.size(), bkgColl.size() ); //-------------------------------------------------- //init parameters for fit Double_t vstart[11] = {1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.}; vstart[0] = sigfrac*ndata; vstart[1] = (1-sigfrac)*ndata; for (int ii=0; ii<9; ii++) { vstart[ii+2] = Para[ii]; //8 shape parameters } TMinuit *gMinuit = new TMinuit(NPAR); gMinuit->Command("SET STR 1"); gMinuit->SetFCN(fcn); Double_t arglist[11]; Int_t ierflg = 0; arglist[0] = 1; gMinuit->mnexcm("SET ERR", arglist ,1,ierflg); arglist[0] = 1; gMinuit->mnexcm("SET PRINT", arglist ,1,ierflg); Double_t step[] = { 1.,1.,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,}; for ( int ii=0; ii<9; ii++){ printf(" para %d, %.5f, err %.5f \n", ii, Para[ii], Para_err[ii]); } float sigma = 3.; gMinuit->mnparm(0, "Signal yield" , vstart[0], step[0], 0., ndata*2. , ierflg); gMinuit->mnparm(1, "background yield" , vstart[1], step[1], 0., ndata*2. , ierflg); // gMinuit->mnparm(2, "constant" , Para[0], 0.00, Para[0], Para[0] , ierflg); // gMinuit->mnparm(3, "exp tail" , Para[1], 0.01, Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); // gMinuit->mnparm(4, "exg mean" , Para[2], 0.01, Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg); // gMinuit->mnparm(5, "exg width" , Para[3], 0.01, Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg); // gMinuit->mnparm(6, "constant" , Para[4], 0.00, Para[4] , Para[4] , ierflg); // gMinuit->mnparm(7, "bg exp turnon", Para[5], 0.01, Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg); // gMinuit->mnparm(8, "bg x offset ", Para[6], 0.01, Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg); // gMinuit->mnparm(9, "bg bend slope", Para[7], 0.01, 0.001 , 0.1 , ierflg); // // gMinuit->mnparm(10, "bg bend power", Para[8], 0.01, Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg); // gMinuit->mnparm(10, "bg bend power", Para[8], 0.01, 0.5 , 5. , ierflg); // gMinuit->mnparm(2, "constant" , Para[0], TMath::Abs(Para[0]*0.0) , Para[0], Para[0], ierflg); // gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.01) , Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); // // gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.1) , 0.8 , 1.3 , ierflg); // gMinuit->mnparm(4, "exg mean" , Para[2], TMath::Abs(Para[2]*0.1) , 0.5 , 1.0 , ierflg); // gMinuit->mnparm(5, "exg width" , Para[3], TMath::Abs(Para[3]*0.1) , 0.25 , 0.5 , ierflg); // gMinuit->mnparm(6, "constant" , Para[4], TMath::Abs(Para[4]*0.0) , Para[4], Para[4], ierflg); // gMinuit->mnparm(7, "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.1) , -0.7 , -0.3 , ierflg); // gMinuit->mnparm(8, "bg x offset ", Para[6], TMath::Abs(Para[6]*0.0) , -0.15 , -0.05 , ierflg); // gMinuit->mnparm(9, "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) , 0.01 , 0.05 , ierflg); // gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) , 0.5 , 1.5 , ierflg); gMinuit->mnparm(2, "constant" , Para[0], 0.00, Para[0], Para[0] , ierflg); gMinuit->mnparm(3, "exp tail" , Para[1], 0.00, Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); gMinuit->mnparm(4, "exg mean" , Para[2], 0.00, Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg); gMinuit->mnparm(5, "exg width" , Para[3], 0.00, Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg); gMinuit->mnparm(6, "constant" , Para[4], 0.00, Para[4] , Para[4] , ierflg); gMinuit->mnparm(7, "bg exp turnon", Para[5], 0.00, Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg); gMinuit->mnparm(8, "bg x offset ", Para[6], 0.00, Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg); gMinuit->mnparm(9, "bg bend slope", Para[7], 0.00, 0.001 , 0.1 , ierflg); gMinuit->mnparm(10, "bg bend power", Para[8], 0.00, Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg); printf(" --------------------------------------------------------- \n"); printf(" Now ready for minimization step \n --------------------------------------------------------- \n"); arglist[0] = 500; // number of iteration gMinuit->mnexcm("MIGRAD", arglist,1,ierflg); //can do scan // arglist[0] = 0; // gMinuit->mnexcm("SCAN", arglist,1,ierflg); printf (" -------------------------------------------- \n"); printf("Finished. ierr = %d \n", ierflg); double para[NPAR+1],errpara[NPAR+1]; double tmp_errpara[NPAR+1]; for(int j=0; j<=NPAR-1;j++) { tmp_errpara[j]=0.1; } for(int j=2; j<=NPAR-1;j++) { if(Para_err[j-2]!=0.) tmp_errpara[j]=TMath::Abs(Para_err[j-2]); } int ni=6; if ( strcmp(EBEE,"EE")==0 ) { ni=6; }//if(ptbin==21) ni=0;} if ( ierflg == 0 ) { for(int i=0; i<ni; i++) { float istep[10] = {0.,0.,0.,0.,0.,0.,0.}; if (i<(ni-1)) { istep[i] = 0.001; }else { for (int j=0; j<ni-1; j++) {istep[j] = 0.001;} } for(int j=0; j<=NPAR-1;j++) { gMinuit->GetParameter(j, para[j], errpara[j]); if (errpara[j] != 0. ) { tmp_errpara[j] = TMath::Abs(errpara[j]); } } if ( strcmp(EBEE,"EB")==0 ) { sigma = 10.; if ( i==(ni-1) ) { sigma=5.;istep[1]=istep[4]=0.; } if ( ptbin==21 && i==1 ){ sigma=3.; } if ( ptbin==21 && i==(ni-1) ){ sigma=20.; } if ( ptbin==23 && i==0 ){ para[7]=-0.5; } if ( ptbin==23 && i==1 ){ istep[1]=0.; istep[3]=0.01; } if ( ptbin==23 && i==3 ){ istep[1]=0.01; istep[3]=0.0; } if ( ptbin==23 && i==(ni-1) ){ sigma=20.; } if ( ptbin==26 && i==1 ){ sigma=5.; } if ( ptbin==26 && i==(ni-1) ){ sigma=20.; } if ( ptbin==30 && i==(ni-1) ){ sigma=3.; } if ( ptbin==35 && i==(ni-1) ) { sigma=10.; } if ( ptbin==40 && i==(ni-1) ) { sigma=5.; istep[4]=0.01; } if ( ptbin==45 && i==(ni-1) ) { sigma=10.; } if ( ptbin==60 && i==0 ) { para[3]=1.; para[4]=0.6; para[5]=0.32; para[7]=-0.45; para[9]=0.025; para[10] = 1.;} if ( ptbin==60 && i==(ni-1) ) { sigma=5.; istep[4]=0.01;} if ( ptbin>=85 && i==(ni-1) ){ sigma=3.; } if ( ptbin==300 ) { istep[2]=istep[3]=istep[4]=0.; }// para[7] = -5.11907e-02; istep[1]=0.; } float tmp8=0.; // if( i!= (ni-1) ) { gMinuit->mnparm(0, "Signal yield" , para[0], 1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg); gMinuit->mnparm(1, "background yield", para[1], 1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg); gMinuit->mnparm(2, "constant" , para[2], 0., para[2]-100.*tmp_errpara[2], para[2]+100.*tmp_errpara[2], ierflg); gMinuit->mnparm(6, "constant" , para[6], 0., para[6]-100.*tmp_errpara[6], para[6]+100.*tmp_errpara[6], ierflg); gMinuit->mnparm(3, "exp tail" , para[3], istep[4], para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg); gMinuit->mnparm(4, "exg mean" , para[4], istep[3], para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg); gMinuit->mnparm(5, "exg width" , para[5], istep[2], para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg); gMinuit->mnparm(7, "bg exp turnon", para[7], istep[1], para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg); gMinuit->mnparm(8, "bg x offset ", para[8], tmp8 , para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg); gMinuit->mnparm(9, "bg bend slope", para[9], istep[0], para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg); float sigma10=5.; if ( para[10]-sigma10*tmp_errpara[10] < 1. )// && i!=(ni-1)) gMinuit->mnparm(10, "bg bend power", para[10], istep[0], 1., para[10]+sigma10*tmp_errpara[10], ierflg); else gMinuit->mnparm(10, "bg bend power", para[10], istep[0], para[10]-sigma10*tmp_errpara[10], para[10]+sigma10*tmp_errpara[10], ierflg); // }else { // gMinuit->mnparm(2, "constant" , Para[0], TMath::Abs(Para[0]*0.0) , Para[0], Para[0], ierflg); // //gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.01) , Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); // gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.0) , 0.8 , 1.3 , ierflg); // gMinuit->mnparm(4, "exg mean" , Para[2], TMath::Abs(Para[2]*0.1) , 0.5 , 1.0 , ierflg); // gMinuit->mnparm(5, "exg width" , Para[3], TMath::Abs(Para[3]*0.1) , 0.25 , 0.5 , ierflg); // gMinuit->mnparm(6, "constant" , Para[4], TMath::Abs(Para[4]*0.0) , Para[4], Para[4], ierflg); // gMinuit->mnparm(7, "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.0) , -0.7 , -0.3 , ierflg); // gMinuit->mnparm(8, "bg x offset ", Para[6], TMath::Abs(Para[6]*0.0) , -0.15 , -0.05 , ierflg); // gMinuit->mnparm(9, "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) , 0.01 , 0.05 , ierflg); // gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) , 0.5 , 1.5 , ierflg); // } if( ptbin >=300 ) { gMinuit->mnparm(3, "exp tail" , 1.257281, 0.0, para[1]-3.*tmp_errpara[1], para[1]+3.*tmp_errpara[1], ierflg); gMinuit->mnparm(4, "exg mean" , 0.856906, 0.0, para[2]-3.*tmp_errpara[2], para[2]+3.*tmp_errpara[2], ierflg); gMinuit->mnparm(5, "exg width" , 0.320847, 0.0, para[3]-3.*tmp_errpara[3], para[3]+3.*tmp_errpara[3], ierflg); } }else{ sigma=10.; if ( i==0 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 0.3; } if ( i==(ni-1) ) { sigma=3.;istep[1]=istep[4]=0.; } //test of not changing signal template if ( i==(ni-1) ) { istep[4]=0.;} if ( ptbin==21 && i==(ni-1) ) { sigma=20.;} if ( ptbin==23 && i==0 ) { sigma=5.;} if ( ptbin==23 && i==(ni-1) ) { sigma=10.;} if ( ptbin<30 && ptbin>21 && i==1 ){ istep[1]=0.; istep[3]=0.01; } if ( ptbin<30 && ptbin>21 && i==3 ){ istep[1]=0.01; istep[3]=0.0; } if ( ptbin==26 && i==1 ) { para[7] = -0.8; } if ( ptbin==26 && i==(ni-1) ) { sigma=10.; } if ( ptbin==30 && i==(ni-1) ) { sigma=10.; } if ( ptbin==35) {para[7] = -0.75;} if ( ptbin==40 && i==0) {para[7] = -0.65; para[10] = 2.;} if ( ptbin==45 && i==(ni-1) ) {sigma=5.;} if ( ptbin==85 && i==(ni-1) ) {sigma=10.; istep[4]=0.01;} if (ptbin >= 85 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 1.; } if ( ptbin==120 ) { para[7] = -0.615255; istep[1]=0.;} // if ( ptbin==120 && i==0 ) { // para[3] = 1.446454; para[4]=-0.016373; para[5]=0.163238; // istep[2]=istep[3]=istep[4]=0.; sigma=5.; tmp_errpara[10]=0.2; // } // if ( ptbin==120 && i==(ni-1) ) { istep[2]=istep[3]=istep[4]=0.; sigma=5.;} gMinuit->mnparm(0, "Signal yield" , para[0], 1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg); gMinuit->mnparm(1, "background yield", para[1], 1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg); gMinuit->mnparm(2, "constant" , para[2], 0., para[2], para[2] , ierflg); gMinuit->mnparm(6, "constant" , para[6], 0., para[6], para[6], ierflg); gMinuit->mnparm(3, "exp tail" , para[3], istep[4], para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg); gMinuit->mnparm(4, "exg mean" , para[4], istep[3], para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg); gMinuit->mnparm(5, "exg width" , para[5], istep[2], para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg); gMinuit->mnparm(7, "bg exp turnon", para[7], istep[1], para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg); gMinuit->mnparm(8, "bg x offset ", para[8], 0.00, para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg); gMinuit->mnparm(9, "bg bend slope", para[9], istep[0], para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg); float minerr=1.; //if ( tmp_errpara[10] > 0.5) tmp_errpara[10] = 0.5; float sigma10=5.; if ( para[10]-sigma10*tmp_errpara[10] < 1. ) gMinuit->mnparm(10, "bg bend power", para[10], istep[0], minerr, para[10]+sigma10*tmp_errpara[10], ierflg); else gMinuit->mnparm(10, "bg bend power", para[10], istep[0], para[10]-sigma10*tmp_errpara[10], para[10]+sigma10*tmp_errpara[10], ierflg); } printf(" ************ \n"); printf(" do %d th fit \n", i); if(i==5 && dataFile.find("toy") != std::string::npos) { cout << "dataResult = " << dataResult << "\t dataErr = " << dataErr << endl; // fixed turn on at +- 1 sigma gMinuit->mnparm(7, "bg exp turnon", dataResult-(float)shift*dataErr, 0.00, para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg); } else if(dataFile.find("toy") == std::string::npos) { dataResult = para[7]; dataErr = tmp_errpara[7]; } arglist[0] = 500; // number of iteration gMinuit->mnexcm("MIGRAD", arglist ,1,ierflg); if ( ierflg != 0 ) { printf("fit failed at %d iteration \n", i); c1->cd(); c1->Draw(); hdata->Draw("phe"); return fitted; } } } Double_t amin,edm,errdef; if ( ierflg == 0 ) { for(int j=0; j<=NPAR-1;j++) { gMinuit->GetParameter(j, para[j],errpara[j]); info.push_back(para[j]); info_err.push_back(errpara[j]); printf("Parameter %d = %f +- %f\n",j,para[j],errpara[j]); } para[NPAR] = dataColl.size(); printf(" fitted yield %2.3f \n", (para[0]+para[1])/ndata ); info.push_back(sigColl.size()); for(int j=0; j<=NPAR-1;j++) { tmp_errpara[j] = errpara[j]; if( tmp_errpara[j] == 0. ) tmp_errpara[j] = par[j]*.1; } //do minos if fit sucessed. } if (ierflg != 0 ) { printf(" *********** Fit failed! ************\n"); gMinuit->GetParameter(0, para[0],errpara[0]); gMinuit->GetParameter(1, para[1],errpara[1]); para[0]=0.; errpara[0]=0.; c1->cd(); c1->Draw(); //gPad->SetLogy(); hdata->SetNdivisions(505,"XY"); hdata->SetXTitle("comb. ISO (GeV)"); hdata->SetYTitle("Entries"); hdata->SetTitle(""); hdata->SetMarkerStyle(8); hdata->SetMinimum(0.); if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.); else hdata->SetMaximum(hdata->GetMaximum()*1.25); if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.25); hdata->Draw("phe"); return fitted; } // Print results // Double_t amin,edm,errdef; Int_t nvpar,nparx,icstat; gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat); gMinuit->mnprin(1,amin); gMinuit->mnmatu(1); printf(" ========= happy ending !? =========================== \n"); printf("FCN = %3.3f \n", amin); //use new PDF form double tmppar[12]; for(int ii=0; ii<9; ii++){ tmppar[ii] = para[ii+2]; fmcsigfit->SetParameter(ii,tmppar[ii]); fbkgfit->SetParameter(ii,tmppar[ii]); } c101->cd(1); //fmcsigfit->SetParameters(tmppar); //fmcsigfit->SetParameter(2,0.1); //fmcsigfit->SetLineStyle(2); fmcsigfit->Draw("same"); c101->cd(2); fbkgfit->SetParameter(4,fbkgfit->GetParameter(4)*fmcbkg->Integral(-1., 20.)/fbkgfit->Integral(-1., 20.)); fbkgfit->Draw("same"); char fname[100]; sprintf(fname,"plots/template_Ifit%s_%d.pdf",EBEE,ptbin); c101->SaveAs(fname); f11->SetParameters(tmppar); SigPDFnorm = f11->Integral(-1., 20.); f12->SetParameters(tmppar); BkgPDFnorm = f12->Integral(-1., 20.); // plot c1->cd(); c1->Draw(); //gPad->SetLogy(); hdata->SetNdivisions(505,"XY"); hdata->SetXTitle("comb. ISO (GeV)"); hdata->SetYTitle("Entries"); hdata->SetTitle(""); hdata->SetMarkerStyle(8); hdata->SetMinimum(0.); if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.); else hdata->SetMaximum(hdata->GetMaximum()*1.5); if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.2); hdata->Draw("p e "); f11->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2)); // f11->SetFillColor(5); f11->SetLineColor(4); //f11->SetFillColor(603); f11->SetLineWidth(2); // f11->SetFillStyle(3001); f11->Draw("same"); f12->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2)); // f12->SetFillColor(8); f12->SetLineColor(2); //f12->SetFillColor(603); f12->SetLineWidth(2); // f12->SetFillStyle(3013); f12->Draw("same"); TF1 *f13 = new TF1("f13",sum_norm, -1., 20 ,11); f13->SetNpx(10000); f13->SetParameters(f12->GetParameters()); f13->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2)); f13->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2)); f13->SetLineWidth(2); f13->SetLineColor(1); f13->Draw("same"); f11->Draw("same"); hdata->Draw("pe same"); // cout << "The number of bins are: " << endl; // cout << "hdata nbins = " << hdata->GetNbinsX() << endl; // cout << "hsig nbins = " << hsig->GetNbinsX() << endl; // cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl; // get chi2/NDF double chi2ForThisBin=0; int nbinForThisBin=0; chi2Nbins(f13, hdata, chi2ForThisBin, nbinForThisBin); for(int epar=0; epar < 11; epar++) { // cout << "f11 parameter " << epar << " = " << // f11->GetParameter(epar) << endl; FitPar[epar] = f11->GetParameter(epar); } for(int epar=0; epar < 11; epar++) { // cout << "f12 parameter " << epar << " = " << // f12->GetParameter(epar) << endl; FitPar[epar+11] = f12->GetParameter(epar); } for(int epar=0; epar < 11; epar++) { // cout << "f13 parameter " << epar << " = " << // f13->GetParameter(epar) << endl; FitPar[epar+22] = f13->GetParameter(epar); } // cout << "hdata integral = " << hdata->Integral() << endl; // cout << endl; // printf("fit area %3.2f; sig area %3.2f; bg area %3.2f\n", f13->Integral(-1., 20.)/hdata->GetBinWidth(2), f11->Integral(-1., 20.)/hdata->GetBinWidth(2),f12->Integral(-1., 20.)/hdata->GetBinWidth(2)); // for(int i=0; i<12; i++){ // printf(" fit para %d = %4.3f \n", i, f13->GetParameter(i)); // } TLegend *tleg = new TLegend(0.5, 0.7, 0.93, 0.92); char text[50]; sprintf(text,"%s Pt %d ~ %.0f GeV",EBEE, ptbin, ptmax); tleg->SetHeader(text); tleg->SetFillColor(0); tleg->SetShadowColor(0); tleg->SetBorderSize(0); sprintf(text,"#chi^{2}/NDF = %.1f/%d",chi2ForThisBin,nbinForThisBin); tleg->AddEntry(hdata,text,""); sprintf(text,"Data %.1f events",hdata->Integral()); tleg->AddEntry(hdata,text,"pl"); sprintf(text,"Fitted %.1f events",para[0]+para[1]);//f13->Integral(-1., 20.)/hdata->GetBinWidth(2)); tleg->AddEntry(f13,text,"l"); sprintf(text,"SIG %.1f #pm %.1f events",para[0], errpara[0]); tleg->AddEntry(f11,text,"f"); sprintf(text,"BKG %.1f #pm %.1f events",para[1], errpara[1]); tleg->AddEntry(f12,text,"f"); tleg->Draw(); gPad->RedrawAxis(); printf("%s, ptbin %d, Data %.1f events \n",EBEE, ptbin, hdata->Integral()); printf("Fitted %.1f (in 5GeV) %.1f events \n",para[0]+para[1],f13->Integral(-1.,5.)); printf("SIG %.1f #pm %.1f events \n",para[0], errpara[0]); printf("SIG (in 5GeV) %.1f #pm %.1f events \n",f11->Integral(-1.,5.)/hdata->GetBinWidth(2), f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2)); printf("BKG %.1f #pm %.1f events \n",para[1], errpara[1]); printf("BKG (in 5GeV) %.1f #pm %.1f events \n",f12->Integral(-1.,5.)/hdata->GetBinWidth(2), f12->Integral(-1.,5.)*errpara[1]/para[1]/hdata->GetBinWidth(2)); float purity = f11->Integral(-1.,5.)/hdata->GetBinWidth(2)/(f11->Integral(-1.,5.)/hdata->GetBinWidth(2)+f12->Integral(-1.,5.)/hdata->GetBinWidth(2)); float purity_err = purity*errpara[0]/para[0]; printf("Purity (in 5GeV) %.3f #pm %.3f \n", purity, purity_err); // hsig->Scale(para[0]/hsig->Integral()); // hbkg->Scale(para[1]/hbkg->Integral()); // hbkg->Add(hsig); // hsig->SetLineColor(1); // hsig->SetFillColor(5); // hsig->SetFillStyle(3001); // hbkg->SetLineWidth(2); // hsig->Draw("same"); // hbkg->Draw("same"); sprintf(fname,"plots/unbinned_free_Ifit%s_%d.pdf",EBEE,ptbin); if (para_index>0) sprintf(fname,"plots/unbinned_Ifit%s_%d_para%d_sigma%1.0f.pdf",EBEE,ptbin,para_index,para_sigma); if(Opt_SavePDF == 1) { c1->SaveAs(fname); } else { c1->Close(); c10->Close(); c101->Close(); c11->Close(); } printf("----- fit results with signal projection ----------- \n"); fitted[0] = para[0]; fitted[1] = errpara[0]; fitted[2] = para[1]; fitted[3] = errpara[1]; fitted[4] = f11->Integral(-1.,5.)/hdata->GetBinWidth(2); fitted[5] = f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2); return fitted; }
void merge_pbpb_pp_HLT(){ TH1::SetDefaultSumw2(); //TFile *fpbpb1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet80_v2.root"); //TFile *fpbpb2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet65_v2.root"); //TFile *fpbpb3 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet55_v2.root"); //TFile *fpp1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet80.root"); //TFile *fpp2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet40.root"); TFile *fpp1_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet80_v2.root"); TFile *fpp2_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet40_v2.root"); /* TTree *jetpbpb1_v2 = (TTree*)fpbpb1->Get("jetR3"); TTree *jetpbpb2_v2 = (TTree*)fpbpb2->Get("jetR3"); TTree *jetpbpb3_v2 = (TTree*)fpbpb3->Get("jetR3"); TTree *evtpbpb1_v2 = (TTree*)fpbpb1->Get("evt"); TTree *evtpbpb2_v2 = (TTree*)fpbpb2->Get("evt"); TTree *evtpbpb3_v2 = (TTree*)fpbpb3->Get("evt"); jetpbpb1_v2->AddFriend(evtpbpb1_v2); jetpbpb2_v2->AddFriend(evtpbpb2_v2); jetpbpb3_v2->AddFriend(evtpbpb3_v2); */ //TTree *jetpp1 = (TTree*)fpp1->Get("ntjet"); // TTree *jetpp2 = (TTree*)fpp2->Get("ntjet"); TTree *jetpp1_v2 = (TTree*)fpp1_v2->Get("jetR3"); TTree *jetpp2_v2 = (TTree*)fpp2_v2->Get("jetR3"); TTree *evtpp1_v2 = (TTree*)fpp1_v2->Get("evt"); TTree *evtpp2_v2 = (TTree*)fpp2_v2->Get("evt"); jetpp1_v2->AddFriend(evtpp1_v2); jetpp2_v2->AddFriend(evtpp2_v2); //TCut pbpb3 = "abs(eta)<2&&jet55&&!jet65&&!jet80&&chMax/pt>0.01"; TCut pp3 = "abs(eta)<2&&jet40&&!jet60&&!jet80&&chMax/pt>0.01"; //TH1F *hpbpb1 = new TH1F("hpbpb1","",30,0,300); //TH1F *hpbpb2 = new TH1F("hpbpb2","",30,0,300); //TH1F *hpbpb3 = new TH1F("hpbpb3","",30,0,300); //TH1F *hpbpbComb = new TH1F("hpbpbComb","",30,0,300); TH1F *hpp1 = new TH1F("hpp1","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hpp2 = new TH1F("hpp2","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hpp3 = new TH1F("hpp3","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hppComb = new TH1F("hppComb","",nbins_jetPtBin,boundaries_jetPtBin); //get the prescl factor information. //Float_t presclpbpb3 = (Float_t)jetpbpb1_v2->GetEntries("jet80")/jetpbpb1_v2->GetEntries("jet55&&jet80"); //cout<<"pbpb prescl3 = "<<presclpbpb3<<endl;//1.99871 Float_t presclpp3 = (Float_t)jetpp1_v2->GetEntries("jet80")/jetpp1_v2->GetEntries("jet40&&jet80"); cout<<"pp prescl3 = "<<presclpp3<<endl; //9.24968 /* jetpbpb1_v2->Project("hpbpb1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01"); hpbpb1->Print("base"); divideBinWidth(hpbpb1); jetpbpb2_v2->Project("hpbpb2","pt","abs(eta)<2&&jet65&&!jet80&&chMax/pt>0.01"); hpbpb2->Print("base"); divideBinWidth(hpbpb2); jetpbpb3_v2->Project("hpbpb3","pt","1.9987"*pbpb3); hpbpb3->Print("base"); divideBinWidth(hpbpb3); */ jetpp1_v2->Project("hpp1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01"); hpp1->Print("base"); //divideBinWidth(hpp1); //hpp1->Scale(1./3.083e11); //hpp1->Scale(1./4); jetpp2_v2->Project("hpp2","pt","abs(eta)<2&&jet60&&!jet80&&chMax/pt>0.01"); hpp2->Print("base"); //divideBinWidth(hpp2); //hpp2->Scale(1./3.083e11); //hpp2->Scale(1./4); jetpp2_v2->Project("hpp3","pt","9.25038"*pp3); //9.25038 - ak5 //9.24955 - ak4 //9.24968 - ak3 hpp3->Print("base"); //divideBinWidth(hpp3); //hpp3->Scale(1./3.083e11); //hpp3->Scale(1./4); //scale the PbPb histograms before adding them //we have to scale them according to the lumi of the Jet80 file. // HLT file | Lumi // HLT_80 | 150 mub-1 // HLT_65 | 12.1 mub-1 // HLT_55 | 0.38 mub-1 // // therefore scale for HLT_55 = 150/0.38 = 394.73684 // scale for HLT_65 = 150/12.1 = 12.3967 //hpbpb2->Scale(12.3867); //hpbpb3->Scale(394.7368); //add the histograms /* hpbpbComb->Add(hpbpb1,1); hpbpbComb->Add(hpbpb2,1); hpbpbComb->Add(hpbpb3,1); hpbpbComb->Print("base"); */ hppComb->Add(hpp1,1); hppComb->Add(hpp2,1); hppComb->Add(hpp3,1); hppComb->Print("base"); /* TCanvas *c1 = new TCanvas("c1","",800,600); c1->SetLogy(); hpbpbComb->SetMarkerStyle(29); //hpbpbComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}"); hpbpbComb->SetYTitle("counts"); hpbpbComb->SetXTitle("Jet p_{T} GeV/c"); TF1 *fPowerLaw = new TF1("fPowerLaw","[0]*pow(x+[1],[2])"); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Draw(); hpbpb3->SetMarkerStyle(24); hpbpb3->SetMarkerColor(kRed); hpbpb3->Draw("same"); hpbpb2->SetMarkerStyle(25); hpbpb2->SetMarkerColor(kBlue); hpbpb2->Draw("same"); hpbpb1->SetMarkerStyle(26); hpbpb1->SetMarkerColor(kGreen); hpbpb1->Draw("same"); TLegend *title = myLegend(0.54,0.65,0.85,0.9); title->AddEntry(hpbpbComb,"PbPb Merged","pl"); title->AddEntry(hpbpb3,"w_{3} * (HLT_55 && !HLT_65 && !HLT_80)","pl"); title->AddEntry(hpbpb2,"HLT_65 && !HLT_80","pl"); title->AddEntry(hpbpb1,"HLT_80","pl"); title->SetTextSize(0.03); title->Draw(); drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20); drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20); c1->SaveAs("pbpb_2013_pt_combined.gif","RECREATE"); */ //plot the statistical uncertainty here //statistical error/meanvalue as a function of pt for the combined spectra. /* TCanvas *c2 = new TCanvas("c2","",800,600); //TH1F* hPbPb_Uncert = (TH1F*)hpbpbComb->Clone("hPbPb_Uncert"); TH1F* hPbPb_Uncert = new TH1F("hPbPb_Uncert","",30,0,300); for(int i = 1;i<=hpbpbComb->GetNbinsX();i++){ double val = hpbpbComb->GetBinContent(i); double valErr = hpbpbComb->GetBinError(i); double uncert = (double)valErr/val; cout<<"uncert = "<<uncert<<endl; hPbPb_Uncert->SetBinContent(i,uncert); hPbPb_Uncert->SetBinError(i,0); } hPbPb_Uncert->SetYTitle("uncertainty"); hPbPb_Uncert->SetXTitle("p_{T} GeV/c"); hPbPb_Uncert->Draw(); drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20); drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20); c2->SaveAs("pbpb_2013_hlt_merge_scaled_uncert.gif","RECREATE"); */ TCanvas *c2 = new TCanvas("c2","",800,600); c2->SetLogy(); TH1F* hPPComb = (TH1F*)hppComb->Clone("hPPComb"); //TH1F* hPPComb_bins = rebin_yaxian(hppComb,"hPPComb_bins"); hPPComb->Scale(1./3.083e11); hPPComb->Print("base"); hPPComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}"); hPPComb->SetXTitle("Jet p_{T} GeV/c"); //hPPComb_bins->Scale(1./3.083e11); //hPPComb_bins->Print("base"); //hPPComb_bins->Scale(1./4); //divideBinWidth(hPPComb_bins); hPPComb->Scale(1./4); divideBinWidth(hPPComb); TF1 *fPowerLaw = new TF1("fPowerLaw","[0]/pow(x,[1])"); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->SetMarkerColor(kBlue); hPPComb->SetMarkerStyle(26); hPPComb->SetTitle("PP2013 ak3PF"); hPPComb->Draw(); //hPPComb_bins->SetMarkerColor(kRed); //hPPComb_bins->SetMarkerStyle(23); //hPPComb_bins->Draw("same"); c2->SaveAs("pp_2013_ak3_pt_evt_frac_merged.gif","RECREATE"); TCanvas *c5 = new TCanvas("c5","",800,600); TH1F* hppFunc = (TH1F*)functionHist(fPowerLaw,hppComb,"Fit Function p_{T} spectra PP 2013 merged"); TH1F* hPPRatio = (TH1F*)hppComb->Clone("hPPRatio"); hPPRatio->Divide(hppFunc); hPPRatio->SetTitle("Spectra to Fit Ratio"); hPPRatio->SetXTitle("Jet p_{T} GeV/c"); hPPRatio->SetYTitle("Measured data/Fit"); hPPRatio->SetMarkerStyle(8); hPPRatio->SetMarkerColor(4); hPPRatio->Draw(); c5->SaveAs("pp_2013_merged_spectra_fit_comp.gif","RECREATE"); TFile *fpbpbunfo = TFile::Open("result-2013-akPu3PF-cent-6-isFineBin-0/pbpb_pp_merged_chmx_pt_Unfo_2013_akPu3PF_cent_6_isFineBin_0.root"); TH1F* hppUnfo = (TH1F*)fpbpbunfo->Get("Unfolded_cent6"); TH1F* hPPGen = (TH1F*)fpbpbunfo->Get("hGen_cent6"); hppUnfo->Print("base"); hPPGen->Print("base"); hPPGen->Scale(1./4); divideBinWidth(hPPGen); hppUnfo->Scale(1./3.083e11); hppUnfo->Scale(1./4); divideBinWidth(hppUnfo); hppUnfo->Divide(hPPGen); TCanvas *c6 = new TCanvas("c6","",800,600); hppUnfo->SetMarkerStyle(21); hppUnfo->SetMarkerColor(kRed); hPPGen->SetMarkerStyle(21); hPPGen->SetMarkerColor(kBlue); hppUnfo->Draw(); // hPPGen->Draw("same"); c6->SaveAs("pp_2760GeV_unfold_vs_mc.gif","RECREATE"); /* TCanvas *c7 = new TCanvas("c7","",800,600); c7->SetLogy(); hPPComb->Draw(); hPPComb->SetYTitle(""); hPPComb->SetXTitle("p_{T} GeV/c"); //hppComb->SetTitle("PP 2013 2.76 TeV ak4PF measured vs unfolded"); hPPComb->SetMarkerStyle(23); hPPComb->SetMarkerColor(kBlue); //hppUnfo->SetAxisRange(10,500,"X"); //hppUnfo->SetMarkerStyle(24); //hppUnfo->SetMarkerColor(kRed); //hppUnfo->Draw("same"); TLegend *title5 = myLegend(0.54,0.65,0.85,0.9); title5->AddEntry(hppComb,"Measured","pl"); title5->AddEntry(hppUnfo,"Bayesian iter = 4","pl"); title5->SetTextSize(0.06); title5->Draw(); gStyle->SetOptStat(0); c7->SaveAs("PP2013_measured_vs_unfolded.gif","RECREATE"); //TCanvas */ //Create output file and save them. TFile f("merge_pp_ak3_HLT_V2.root","RECREATE"); //hpbpb1->Write(); //hpbpb2->Write(); //hpbpb3->Write(); //hPPComb_bins->Write(); hpp1->Write(); hpp2->Write(); hpp3->Write(); //hpbpbComb->Write(); hppComb->Write(); //hPPComb->Write(); //hPbPb_Uncert->Write(); hPPComb->Write(); hPPGen->Write(); f.Close(); }
void plottingmacro_IVF() { double fa = 0.46502; double fb = 0.53498; bool debug_ = true; // std::string path("Nov10thFall11Plots/"); // std::string path("Nov10Fall1160MTopSlimPlots/"); std::string path("Nov10Fall1160MTopIVFPlots_b/"); if(debug_) std::cout << "Init the style form setTDRStyle" << std::endl; setTDRStyle(); gStyle->SetErrorX(0.5); gROOT->ForceStyle(); initOptions(); if(debug_) std::cout << "Init the sample" << std::endl; // std::vector<Sample> s = Nov10thDiJetPtUpdatedSlimHistos(); //std::vector<Sample> s = Nov10Fall1160MTopSlimHistos(); std::vector<Sample> s = Nov10Fall1160MTopIVFHistos(); Sample data(1,"fake data","S1.root",0,true,1000); if(debug_) std::cout << "Init the data sample" << std::endl; for(size_t i=0;i< s.size();i++) if(s[i].data) {data=s[i];break;} if(debug_) std::cout << "Ls data sample" << std::endl; data.file()->ls(); if(debug_) std::cout << "Init the mc sample" << std::endl; for(size_t i=0;i< s.size();i++) s[i].dump(1,fa,fb); std::vector<std::string> names; if(debug_) std::cout << "Get List of Keys" << std::endl; TList * subs = data.file()->GetListOfKeys(); for(size_t i=0;i< subs->GetSize();i++) { TString nn = subs->At(i)->GetName(); if( nn.Contains(TRegexp("Count*")) ) continue; if(debug_) std::cout << "Get List of Keys in subdirs" << std::endl; TList * objs = ((TDirectoryFile *)data.file()->Get(subs->At(i)->GetName()))->GetListOfKeys(); for(size_t j=0;j< objs->GetSize();j++) { if(debug_) std::cout << "Name = " << subs->At(i)->GetName()+std::string("/") + objs->At(j)->GetName() << std::endl; names.push_back(subs->At(i)->GetName()+std::string("/") + objs->At(j)->GetName()); // std::cout << subs->At(i)->GetName() << "/" << objs->At(j)->GetName() << std::endl; //TODO: select plots via regexp } } if(debug_) std::cout << "Starting plotting" << std::endl; std::string process; for(size_t i = 0 ; i < names.size() ; i++) { std::map<std::string,TH1F *> grouped; TString n=names[i]; // if(!n.Contains(TRegexp("VlightRegionHZee/HiggsPtVlightRegionHZee"))) continue; // if(!n.Contains(TRegexp("VlightRegionHZee/ZPtVlightRegionHZee"))) continue; // if(!n.Contains(TRegexp("VlightRegionHZee"))) continue; // if(!n.Contains(TRegexp("ZSVRegionZmmSV"))) continue; // if(!n.Contains(TRegexp("ZSVRegionZeeSV"))) continue; // if(!n.Contains(TRegexp("ZSVRegionZcombSV"))) continue; // if(!n.Contains(TRegexp("ZSVPureRegionZcombSV"))) continue; // if(!n.Contains(TRegexp("ZSVTTbarPureRegionZcombSV"))) continue; if(!n.Contains(TRegexp("TTbarRegionZeeSVJets"))) continue; if(n.Contains(TRegexp("RegionHZcomb"))) process = "Z(l^{+}l^{-})H(b#bar{b})"; if(n.Contains(TRegexp("RegionHZmm"))) process = "Z(#mu^{+}#mu^{-})H(b#bar{b})"; if(n.Contains(TRegexp("RegionHZee"))) process = "Z(e^{+}e^{-})H(b#bar{b})"; if(debug_) std::cout << "Creating the Canvas" << std::endl; TCanvas *c = new TCanvas(); c->SetLogy(false); c->SetTitle(names[i].c_str()); if(debug_) std::cout << "Creating histograms" << std::endl; TH1F *hd = ((TH1F*)data.file()->Get(names[i].c_str())); hd->Sumw2(); Options o=options[names[i]]; // hd->Rebin(o.rebin); hd->SetMarkerStyle(20); hd->GetXaxis()->SetLabelOffset(99); hd->SetYTitle(o.yaxis.c_str()); double nbin = hd->GetNbinsX(); double min_bin = hd->GetXaxis()->GetXmin(); double max_bin = hd->GetXaxis()->GetXmax(); TH1F *hmc = new TH1F("hmc","hmc", nbin, min_bin, max_bin); hmc->SetFillColor(kWhite); hmc->Sumw2(); // hmc->Rebin(o.rebin); if(debug_) std::cout << "Creating the THStack and Legend" << std::endl; THStack * sta = new THStack("sta",hd->GetTitle()); TLegend * l = new TLegend(o.legendx1,o.legendy1,o.legendx2,o.legendy2); //0.7,0.1,0.9,0.6); l->SetFillColor(kWhite); l->SetBorderSize(0); l->SetTextFont(62); l->SetTextSize(0.03); if(debug_) std::cout << "Adding data to the legend" << std::endl; l->AddEntry(hd, "Data","P"); if(debug_) std::cout << "Adding MC to the THStack" << std::endl; //with the proper trigger eff // double SF[] = {1.01,1.03,1.00}; // double SF[] = {1.03,1.054,1.032}; double SF[] = {1.0,1.0,1.0}; if(debug_){ for(int i = 0; i< 3; ++i) std::cout << "SF [" << i << "] = " << SF[i] << std::endl; } double mcIntegral=0; for(size_t j=0;j< s.size() ;j++) { if(!s[j].data) { if(debug_) std::cout << "Creating TH1F from file " << s[j].name << std::endl; TH1F * h = ((TH1F*)s[j].file()->Get(names[i].c_str())); h->Sumw2(); if(debug_){ std::cout << "TH1F created from file " << s[j].name << std::endl; std::cout << "Scaling : " << s[j].scale(data.lumi(),fa,fb) << std::endl; std::cout << "Scaling with SF : " << s[j].scale(data.lumi(),fa,fb,SF) << std::endl; std::cout << "Histo integral before scaling = " << h->Integral() << std::endl; } h->Scale(s[j].scale(data.lumi(),fa,fb,SF)); if(debug_){ std::cout << "Histo integral after scaling = " << h->Integral() << std::endl; std::cout << "Managing style... " << std::endl; } h->SetLineWidth(1.); h->SetFillColor(s[j].color); h->SetLineColor(s[j].color); // h->Rebin(options[names[i]].rebin); if(debug_) std::cout << "Cloning and update legend " << std::endl; if(grouped.find(s[j].name) == grouped.end()){ l->AddEntry(h,s[j].name.c_str(),"F"); } std::cout << "Sample : " << s[j].name << " - Integral for plot " << names[i] << " = " << h->Integral(-10000,10000) << std::endl; mcIntegral += h->Integral(); sta->Add(h); hmc->Add(h); //TO FIX grouped map // sovrascrive histo con lo stesso nome tipo VV o ST etc... grouped[s[j].name]=(TH1F *)h->Clone(("_"+names[i]).c_str()); } } if(debug_){ std::cout << "Data total = " << hd->Integral() << std::endl; std::cout << "MC = " << mcIntegral << std::endl; std::cout << "Data/MC = " << hd->Integral()/mcIntegral << std::endl; } TPad * TopPad = new TPad("TopPad","Top Pad",0.,0.3,1.,1. ) ; TPad * BtmPad = new TPad("BtmPad","Bottom Pad",0.,0.,1.,0.313 ) ; TopPad->SetBottomMargin(0.02); BtmPad->SetTopMargin(0.0); BtmPad->SetFillStyle(4000); TopPad->SetFillStyle(4000); BtmPad->SetFillColor(0); BtmPad->SetBottomMargin(0.35); TopPad->Draw() ; BtmPad->Draw() ; std::cout << "hd maximum = " << hd->GetMaximum() << " sta maximum = " << sta->GetMaximum() << std::endl; double maxY; if(hd->GetMaximum() > sta->GetMaximum()) maxY = (hd->GetMaximum())*1.5; else maxY = (sta->GetMaximum())*1.5; TopPad->cd(); hd->Draw("E1X0"); sta->Draw("sameHIST"); hmc->Draw("sameE2"); hmc->SetFillColor(2); hmc->SetMarkerSize(0); hmc->SetFillStyle(3013); hd->Draw("E1X0same"); l->Draw("same"); std::cout << "Set Maximum to = " << maxY << std::endl; hd->GetYaxis()->SetRangeUser(0.,maxY); hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max); BtmPad->cd(); std::cout << "Division" << std::endl; TH1D * divisionErrorBand = (TH1D*)(hmc)->Clone("divisionErrorBand"); divisionErrorBand->Sumw2(); divisionErrorBand->Divide(hmc); divisionErrorBand->Draw("E2"); divisionErrorBand->SetMaximum(2.49); divisionErrorBand->SetMinimum(0); divisionErrorBand->SetMarkerStyle(20); divisionErrorBand->SetMarkerSize(0.55); divisionErrorBand->GetXaxis()->SetTitleOffset(1.12); divisionErrorBand->GetXaxis()->SetLabelSize(0.12); divisionErrorBand->GetXaxis()->SetTitleSize(0.5); divisionErrorBand->GetYaxis()->SetTitle("Data/MC"); divisionErrorBand->GetYaxis()->SetLabelSize(0.12); divisionErrorBand->GetYaxis()->SetTitleSize(0.12); divisionErrorBand->GetYaxis()->SetTitleOffset(0.40); divisionErrorBand->GetYaxis()->SetNdivisions(505); //divisionErrorBand->UseCurrentStyle(); divisionErrorBand->SetFillColor(2); divisionErrorBand->SetFillStyle(3001); divisionErrorBand->SetMarkerSize(0.); TH1D * division = (TH1D*)(hd)->Clone("division"); division->Sumw2(); division->Divide(hmc); // division->SetMaximum(2.5); // division->SetMinimum(0); // division->SetMarkerStyle(20); // division->SetMarkerSize(0.55); // division->GetXaxis()->SetLabelSize(0.12); // division->GetXaxis()->SetTitleSize(0.14); // division->GetYaxis()->SetLabelSize(0.10); // division->GetYaxis()->SetTitleSize(0.10); // division->GetYaxis()->SetTitle("Data/MC"); Double_t min = division->GetXaxis()->GetXmin(); Double_t max = division->GetXaxis()->GetXmax(); division->Draw("E1X0same"); TLine *line = new TLine(min, 1.0, max, 1.0); line->SetLineColor(kRed); line->Draw("same"); TLegend * leg3 =new TLegend(0.50,0.86,0.69,0.96); leg3->AddEntry(divisionErrorBand,"MC uncert. (stat.)","f"); leg3->SetFillColor(0); leg3->SetLineColor(0); leg3->SetShadowColor(0); leg3->SetTextFont(62); leg3->SetTextSize(0.06); leg3->Draw(); TPaveText *pave = new TPaveText(0.15,0.85,0.32,0.96,"brNDC"); pave->SetTextAlign(12); pave->SetLineColor(0); pave->SetFillColor(0); pave->SetShadowColor(0); //TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",histDt->Chi2Test(histCopyMC5,"UWCHI2/NDF"),histDt->KolmogorovTest(histCopyMC5))); // stat + sys TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",hd->Chi2Test(hmc,"UWCHI2/NDF"),hd->KolmogorovTest(hmc))); // stat only text->SetTextFont(62); text->SetTextSize(0.08); pave->Draw(); TopPad->cd(); TLatex latex; latex.SetNDC(); latex.SetTextAlign(12); latex.SetTextSize(0.052); latex.DrawLatex(0.17,0.89,"CMS Preliminary"); latex.SetTextSize(0.04); latex.DrawLatex(0.17,0.84,"#sqrt{s} = 7 TeV, L = 4.7 fb^{-1}"); // latex.DrawLatex(0.17,0.79,"Z(e^{+}e^{-})H(b#bar{b})"); latex.DrawLatex(0.17,0.79,process.c_str()); c->Update(); std::string cName= hd->GetName(); cName += "_bare.pdf"; cName = path+cName; c->Print(cName.c_str(),"pdf"); // std::cout << names[i] << " d: " << hd->Integral() << " "; // THStack * sta2 = new THStack("sta2",hd->GetTitle()); // float tot=0; // float toterr2=0; // if(debug_) // std::cout << "Putting the iterator in the for loop" << std::endl; // for(std::map<std::string,TH1F *>::reverse_iterator it=grouped.rbegin(); it!=grouped.rend();++it) // { // if(debug_) // std::cout << "Using the iterator" << std::endl; // std::cout << (*it).first << " " << (*it).second->Integral() << " | " << std::endl ; // if((*it).second->GetEntries() > 0) { // float er=1.*sqrt((*it).second->GetEntries())/(*it).second->GetEntries()*(*it).second->Integral(); // toterr2+=er*er; // } // tot+=(*it).second->Integral(); // sta2->Add(it->second); // } // std::cout << " Tot: " << tot << "+-" << sqrt(toterr2) << " SF: " << hd->Integral()/tot << std::endl; // TCanvas *c2 = new TCanvas(); // c2->SetTitle(names[i].c_str()); // std::cout << "hd maximum = " << hd->GetMaximum() << " sta2 maximum = " << sta2->GetMaximum() << std::endl; // if(hd->GetMaximum() > sta2->GetMaximum()) maxY = hd->GetBinContent(hd->GetMaximumBin()) * 1.5; // else maxY = ( sta2->GetMaximum())*1.5; // // hd->Draw("E1"); // sta2->Draw("PADSHIST"); // // hd->Draw("E1same"); // // l->Draw("same"); // std::cout << "Set Maximum to = " << maxY << std::endl; // hd->GetYaxis()->SetRangeUser(0.,maxY); // hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max); // c2->Update(); // std::string c2Name = hd->GetName(); // c2Name = path+c2Name; // c2Name += "_norm.pdf"; // c2->Print(c2Name.c_str(),"pdf"); } }
TCanvas* example_plot( int iPeriod, int iPos ) { // if( iPos==0 ) relPosX = 0.12; int W = 800; int H = 600; // // Simple example of macro: plot with CMS name and lumi text // (this script does not pretend to work in all configurations) // iPeriod = 1*(0/1 7 TeV) + 2*(0/1 8 TeV) + 4*(0/1 13 TeV) // For instance: // iPeriod = 3 means: 7 TeV + 8 TeV // iPeriod = 7 means: 7 TeV + 8 TeV + 13 TeV // Initiated by: Gautier Hamel de Monchenault (Saclay) // Updated by: Dinko Ferencek (Rutgers) // int H_ref = 600; int W_ref = 800; // references for T, B, L, R float T = 0.08*H_ref; float B = 0.12*H_ref; float L = 0.12*W_ref; float R = 0.04*W_ref; TString canvName = "FigExample_"; canvName += W; canvName += "-"; canvName += H; canvName += "_"; canvName += iPeriod; if( writeExtraText ) canvName += "-prelim"; if( iPos%10==0 ) canvName += "-out"; else if( iPos%10==1 ) canvName += "-left"; else if( iPos%10==2 ) canvName += "-center"; else if( iPos%10==3 ) canvName += "-right"; TCanvas* canv = new TCanvas(canvName,canvName,50,50,W,H); canv->SetFillColor(0); canv->SetBorderMode(0); canv->SetFrameFillStyle(0); canv->SetFrameBorderMode(0); canv->SetLeftMargin( L/W ); canv->SetRightMargin( R/W ); canv->SetTopMargin( T/H ); canv->SetBottomMargin( B/H ); canv->SetTickx(0); canv->SetTicky(0); TH1* h = new TH1F("h","h",40,70,110); h->GetXaxis()->SetNdivisions(6,5,0); h->GetXaxis()->SetTitle("m_{e^{+}e^{-}} (GeV)"); h->GetYaxis()->SetNdivisions(6,5,0); h->GetYaxis()->SetTitleOffset(1); h->GetYaxis()->SetTitle("Events / 0.5 GeV"); h->SetMaximum( 260 ); if( iPos==1 ) h->SetMaximum( 300 ); h->Draw(); int histLineColor = kOrange+7; int histFillColor = kOrange-2; float markerSize = 1.0; { TLatex latex; int n_ = 2; float x1_l = 0.92; float y1_l = 0.60; float dx_l = 0.30; float dy_l = 0.18; float x0_l = x1_l-dx_l; float y0_l = y1_l-dy_l; TPad* legend = new TPad("legend_0","legend_0",x0_l,y0_l,x1_l, y1_l ); // legend->SetFillColor( kGray ); legend->Draw(); legend->cd(); float ar_l = dy_l/dx_l; float x_l[1]; float ex_l[1]; float y_l[1]; float ey_l[1]; // float gap_ = 0.09/ar_l; float gap_ = 1./(n_+1); float bwx_ = 0.12; float bwy_ = gap_/1.5; x_l[0] = 1.2*bwx_; // y_l[0] = 1-(1-0.10)/ar_l; y_l[0] = 1-gap_; ex_l[0] = 0; ey_l[0] = 0.04/ar_l; TGraph* gr_l = new TGraphErrors(1, x_l, y_l, ex_l, ey_l ); gStyle->SetEndErrorSize(0); gr_l->SetMarkerSize(0.9); gr_l->Draw("0P"); latex.SetTextFont(42); latex.SetTextAngle(0); latex.SetTextColor(kBlack); latex.SetTextSize(0.25); latex.SetTextAlign(12); TLine line_; TBox box_; float xx_ = x_l[0]; float yy_ = y_l[0]; latex.DrawLatex(xx_+1.*bwx_,yy_,"Data"); yy_ -= gap_; box_.SetLineStyle( kSolid ); box_.SetLineWidth( 1 ); // box_.SetLineColor( kBlack ); box_.SetLineColor( histLineColor ); box_.SetFillColor( histFillColor ); box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 ); box_.SetFillStyle(0); box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 ); latex.DrawLatex(xx_+1.*bwx_,yy_,"Z #rightarrow e^{+}e^{-} (MC)"); canv->cd(); } { // Observed data TFile file_("histo.root","READ"); TH1F *data = static_cast<TH1F*>(file_.Get("data")->Clone()); data->SetDirectory(0); data->SetMarkerStyle(20); data->SetMarkerSize(markerSize); TH1F *MC = static_cast<TH1F*>(file_.Get("MC")->Clone()); MC->SetDirectory(0); MC->SetLineColor(histLineColor); MC->SetFillColor(histFillColor); MC->Draw("histsame"); data->Draw("esamex0"); file_.Close(); } // writing the lumi information and the CMS "logo" CMS_lumi( canv, iPeriod, iPos ); canv->Update(); canv->RedrawAxis(); canv->GetFrame()->Draw(); canv->Print(canvName+".pdf",".pdf"); canv->Print(canvName+".png",".png"); return canv; }
void plotv2(){ gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gStyle->SetStripDecimals(0); float pt[24]; float ept[24]; float v2pAu[24], ev2pAu[24]; float v2mpcs[24], ev2mpcs[24]; float v3mpcs[24], ev3mpcs[24]; float v2bbcs[24], ev2bbcs[24]; float v3bbcs[24], ev3bbcs[24]; float v2fvtxs[24], ev2fvtxs[24]; float v3fvtxs[24], ev3fvtxs[24]; ifstream fin2mpcs("run15pAu_mpcs_hadron_v2_0_5.txt"); ifstream fin2bbcs("run15pAu_bbcs_hadron_v2_0_5.txt"); ifstream fin2fvtxs("run15pAu_fvtx0s_hadron_v2_0_5.txt"); ifstream fin2fvtxs_RES("../../final05/vn/run15pAu_fvtx0s_hadron_v2_0_5.txt"); ifstream fin2pAu("v2_pt_pAu_00_05_sys.dat"); /* ifstream fin3mpcs("run15pAu_mpcs_hadron_v3_0_5.txt"); ifstream fin3bbcs("run15pAu_bbcs_hadron_v3_0_5.txt"); ifstream fin3fvtxs("../../final06/vn/run15pAu_fvtx0s_hadron_v2_0_5.txt"); */ float tmp; for(int i=0; i<13; i++){ ept[i]=0; fin2pAu>>pt[i]>>v2pAu[i]>>ev2pAu[i]>>tmp; } TGraphErrors *grpAu2 = new TGraphErrors(13, pt, v2pAu, ept, ev2pAu); for(int i=0; i<14; i++){ ept[i]=0; fin2mpcs>>pt[i]>>v2mpcs[i]>>ev2mpcs[i]; //fin3mpcs>>pt[i]>>v3mpcs[i]>>ev3mpcs[i]; fin2bbcs>>pt[i]>>v2bbcs[i]>>ev2bbcs[i]; //fin3bbcs>>pt[i]>>v3bbcs[i]>>ev3bbcs[i]; fin2fvtxs>>pt[i]>>v2fvtxs[i]>>ev2fvtxs[i]; //fin3fvtxs>>pt[i]>>v3fvtxs[i]>>ev3fvtxs[i]; } fin2bbcs.close(); fin2mpcs.close(); fin2fvtxs.close(); //fin3bbcs.close(); //fin3mpcs.close(); //fin3fvtxs.close(); TGraphErrors *grmpcs2 = new TGraphErrors(14, pt, v2mpcs, ept, ev2mpcs); TGraphErrors *grbbcs2 = new TGraphErrors(14, pt, v2bbcs, ept, ev2bbcs); TGraphErrors *grfvtxs2 = new TGraphErrors(14, pt, v2fvtxs, ept, ev2fvtxs); TGraphErrors *grmpcs3 = new TGraphErrors(14, pt, v3mpcs, ept, ev3mpcs); TGraphErrors *grbbcs3 = new TGraphErrors(14, pt, v3bbcs, ept, ev3bbcs); TGraphErrors *grfvtxs3 = new TGraphErrors(14, pt, v3fvtxs, ept, ev3fvtxs); c1=new TCanvas("c1","c1"); c1->SetFillColor(10); c1->cd(); TH1F *h = new TH1F("h", "h", 50, 0, 5.0); h->SetMinimum(0.002); h->SetMaximum(0.312); h->SetMarkerStyle(20); h->SetMarkerSize(1.2); h->Draw(); h->GetYaxis()->SetTitleOffset(0.9); h->GetYaxis()->SetTitleSize(0.05); h->GetYaxis()->SetTitle("v_{2}"); h->GetXaxis()->SetTitle("p_{T} (GeV/c)"); h->GetXaxis()->SetTitleSize(0.04); h->GetYaxis()->CenterTitle(kTRUE); h->GetXaxis()->CenterTitle(kTRUE); grmpcs2->SetMarkerStyle(20); grmpcs2->SetMarkerSize(1.2); grmpcs2->SetMarkerColor(2); //grmpcs2->Draw("P"); grbbcs2->SetMarkerStyle(24); grbbcs2->SetMarkerSize(1.2); grbbcs2->SetMarkerColor(4); grbbcs2->Draw("P"); grfvtxs2->SetMarkerStyle(21); grfvtxs2->SetMarkerSize(1.2); grfvtxs2->SetMarkerColor(6); grfvtxs2->Draw("P"); grpAu2->SetMarkerStyle(21); grpAu2->SetMarkerSize(1.2); grpAu2->SetMarkerColor(4); //grpAu2->Draw("P"); grmpcs3->SetMarkerStyle(22); grmpcs3->SetMarkerSize(1.2); grmpcs3->SetMarkerColor(6); //grmpcs3->Draw("P"); grbbcs3->SetMarkerStyle(23); grbbcs3->SetMarkerSize(1.2); grbbcs3->SetMarkerColor(9); //grbbcs3->Draw("P"); grfvtxs3->SetMarkerStyle(25); grfvtxs3->SetMarkerSize(1.2); grfvtxs3->SetMarkerColor(4); //fvtxs3->Draw("P"); TLegend *leg1 = new TLegend(0.20,0.60,0.60,0.88); leg1->SetFillColor(10); leg1->SetLineStyle(4000); leg1->SetLineColor(10); leg1->SetLineWidth(0.); leg1->SetTextSize(0.05); leg1->SetBorderSize(0); leg1->AddEntry(grmpcs2,"0~5%",""); //leg1->AddEntry(grmpcs2,"v_{2}(pAu, MPCs)","P"); leg1->AddEntry(grbbcs2,"v_{2}(pAu, BBCs)","P"); leg1->AddEntry(grfvtxs2,"v_{2}(pAu, FVTXs)","P"); //leg1->AddEntry(grpAu2,"v_{2}(pAu,MPCs)","P"); //leg1->AddEntry(grmpcs3,"v_{3}(#Psi_{3}^{MPCs}, -4.0<#eta<-4.0)","P"); //leg1->AddEntry(grbbcs3,"v_{3}(#Psi_{3}^{BBCs}, -4.0<#eta<-4.0)","P"); //leg1->AddEntry(grfvtxs3,"v_{3}(#Psi_{2}^{FVTXs}, -3.0<#eta<-1.0)","P"); leg1->Draw(); c1->Print("v2_pAu.pdf"); }
void Draw() { /* TLatex *t = new TLatex(); t->SetTextSize(0.042); t->DrawLatex(1.5,0.80,"CMSSW_1_6_12, |#eta|< 1.3"); t->DrawLatex(1.5,0.75,"no ZSP in HCAL"); t->DrawLatex(1.5,0.70,"no SR in ECAL"); */ /* setTDRStyle(0,1); TCanvas* c0 = new TCanvas("X","Y",1); // data TFile* file = new TFile("DYDataA_29Feb.root"); hnvtx0->GetXaxis()->SetTitle("N reco vertices"); hnvtx0->GetYaxis()->SetTitle(""); hnvtx0->SetLineStyle(1); hnvtx0->SetLineWidth(3); hnvtx0->SetMarkerStyle(24); hnvtx0->SetMarkerSize(1.0); hnvtx0->SetMaximum(200000.); hnvtx0->SetMinimum(0.5); hnvtx0->Draw("PE"); TLegend *leg = new TLegend(0.35,0.75,0.9,0.85,NULL,"brNDC"); leg->SetFillColor(10); leg->AddEntry(hnvtx0,"data: p_{T}^{#mu}> 20 GeV, |#eta|<2.4","P"); // MC TFile* file = new TFile("DYMC18novPUW.root"); hnvtx0->SetLineStyle(1); hnvtx0->SetLineWidth(3); hnvtx0->Draw("same"); leg->AddEntry(hnvtx0,"MC, DY#rightarrowll","L"); leg->Draw(); c0->SaveAs("nvtx0.png"); */ // normalization // Double_t xsection=3048.; Double_t luminosity=5061; Double_t nmcevents=15000000.; Double_t datamcratio=2925.44; Double_t normalization=(xsection*luminosity)/(nmcevents*datamcratio); setTDRStyle(0,1); // data TFile* file = new TFile("DataAB.root"); cout <<" ============= Data =============================" << endl; cout <<" ===> Zmumu = " << hZY->Integral() << endl; cout <<" ===> 2jets = " << hZY2J->Integral() << endl; cout <<" ===> y* = " << hZY2JY->Integral() << endl; cout <<" ===> Mjj = " << hZY2JYMjj->Integral() << endl; TCanvas* c1 = new TCanvas("X","Y",1); TH1F *hNjetsData = (TH1F*)hNjets->Clone(); // MC events TFile* file = new TFile("DYMCAB.root"); cout <<" ============= MC =============================" << endl; cout <<" ===> Zmumu = " << hZY->Integral()*normalization << endl; cout <<" ===> 2jets = " << hZY2J->Integral()*normalization << endl; cout <<" ===> y* = " << hZY2JY->Integral()*normalization << endl; cout <<" ===> Mjj = " << hZY2JYMjj->Integral()*normalization << endl; TH1F *hNjetsMC = (TH1F*)hNjets->Clone(); TH1F *hNjetsRatio = (TH1F*)hNjets->Clone(); TH1F *hNjetsRatio_JESUP = (TH1F*)hNjets->Clone(); TH1F *hNjetsRatio_JESDN = (TH1F*)hNjets->Clone(); // // MC events JESUP TFile* file = new TFile("DYMCAB_JESUP.root"); TH1F *hNjetsMC_JESUP = (TH1F*)hNjets->Clone(); // MC events JESDN TFile* file = new TFile("DYMCAB_JESDN.root"); TH1F *hNjetsMC_JESDN = (TH1F*)hNjets->Clone(); // hNjetsData->GetXaxis()->SetTitle("N jets"); hNjetsData->GetYaxis()->SetTitle("N events"); hNjetsData->SetMaximum(5000000.); hNjetsData->SetMinimum(100.); hNjetsData->SetLineStyle(1.); hNjetsData->SetLineWidth(2); hNjetsData->SetMarkerStyle(24); hNjetsData->SetMarkerSize(0.7); hNjetsData->Draw("PE"); // Double_t mcevents= hNjetsMC->Integral(); // Double_t dataevents=hNjetsData->Integral(); // Double_t expected=mcevents*normalization; hNjetsMC->Scale(normalization); hNjetsMC_JESUP->Scale(normalization); hNjetsMC_JESDN->Scale(normalization); hNjetsMC->SetLineStyle(1); hNjetsMC->SetLineWidth(2); hNjetsMC->Draw("same"); TLegend *leg = new TLegend(0.5,0.8,0.9,0.9,NULL,"brNDC"); leg->SetFillColor(10); leg->AddEntry(hNjetsData,"Data 2011, L=5.06 fb^{-1} ","P"); leg->AddEntry(hNjetsMC,"Z+jets MC","L"); leg->Draw(); TLatex *t = new TLatex(); t->SetTextSize(0.042); t->DrawLatex(3.0,200000,"Z#rightarrow#mu#mu + jets"); t->DrawLatex(3.0,80000,"p_{T}^{j}>50 GeV, |#eta|<2.5"); c1->SaveAs("dy_njets.png"); setTDRStyle(0,0); TCanvas* c2 = new TCanvas("X","Y",1); hNjetsData->Sumw2(); Int_t nbins = hNjetsMC->GetNbinsX(); for (Int_t ib = 1; ib <= nbins; ib++) { hNjetsMC->SetBinError(ib,0.1); hNjetsMC->SetBinError(ib,0.1); } hNjetsRatio->Divide(hNjetsData,hNjetsMC,1.,1.,""); hNjetsRatio->GetXaxis()->SetTitle("N jets"); hNjetsRatio->GetYaxis()->SetTitle("Data / MC"); hNjetsRatio->SetMaximum(1.3); hNjetsRatio->SetMinimum(0.7); hNjetsRatio->SetLineStyle(1.); hNjetsRatio->SetLineWidth(2); hNjetsRatio->SetMarkerStyle(24); hNjetsRatio->SetMarkerSize(1.0); hNjetsRatio->SetAxisRange(0,3,"X"); hNjetsRatio->Draw("PE"); hNjetsRatio_JESUP->Divide(hNjetsMC_JESUP,hNjetsMC,1.,1.,""); hNjetsRatio_JESUP->SetLineStyle(2); hNjetsRatio_JESUP->SetLineWidth(2); hNjetsRatio_JESUP->Draw("histsame"); hNjetsRatio_JESDN->Divide(hNjetsMC_JESDN,hNjetsMC,1.,1.,""); hNjetsRatio_JESDN->SetLineStyle(3); hNjetsRatio_JESDN->SetLineWidth(2); hNjetsRatio_JESDN->Draw("histsame"); TLatex *t = new TLatex(); t->SetTextSize(0.042); t->DrawLatex(1.0,1.20,"Z#rightarrow#mu#mu + jets"); t->DrawLatex(1.0,1.14,"p_{T}^{j}>50 GeV, |#eta|<2.5"); TLegend *leg = new TLegend(0.2,0.2,0.6,0.35,NULL,"brNDC"); leg->SetFillColor(10); leg->AddEntry(hNjetsRatio,"Data 2011, L=5.06 fb^{-1} ","P"); leg->AddEntry(hNjetsRatio_JESUP,"Z+jets MC, JES +1#sigma","L"); leg->AddEntry(hNjetsRatio_JESDN,"Z+jets MC, JES -1#sigma","L"); leg->Draw(); c2->SaveAs("dy_ratio_njets_jes.png"); }
/* void formatCanvas(TCanvas *c){ c->Divide(1,2,0.01,0.01); c->cd(1); c->GetPad(1)->SetLogy(); c->GetPad(1)->SetPad(0.,0.425,1.,1.); c->GetPad(2)->SetPad(0.,0.0,1.,0.425); c->GetPad(2)->SetBottomMargin(0.3); c->GetPad(2)->SetGridy(1); } // divide by bin width void divideBinWidth(TH1 *h) { h->Sumw2(); for (int i=0;i<=h->GetNbinsX();i++) { Float_t val = h->GetBinContent(i); Float_t valErr = h->GetBinError(i); val/=h->GetBinWidth(i); valErr/=h->GetBinWidth(i); h->SetBinContent(i,val); h->SetBinError(i,valErr); } h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); } void cleanup(TH1F *h) { for (int i=1;i<=h->GetNbinsX();i++) { double val1 = h->GetBinContent(i); double valErr1 = h->GetBinError(i); if (valErr1>=val1) { h->SetBinContent(i,0); h->SetBinError(i,0); } } } // rebin the spectra TH1F *rebin(TH1F *h, char *histName) { TH1F *hRebin = new TH1F(Form("%s_rebin",h->GetName()),Form("rebin %s",h->GetTitle()),nbins_recrebin,boundaries_recrebin); for (int i=1;i<=h->GetNbinsX();i++) { double val=h->GetBinContent(i); double valErr=h->GetBinError(i); int binNum = hRebin->FindBin(h->GetBinCenter(i)); double val1 = hRebin->GetBinContent(binNum); double valErr1 = hRebin->GetBinError(binNum); hRebin->SetBinContent(binNum,val+val1); hRebin->SetBinError(binNum,sqrt(valErr1*valErr1+valErr*valErr)); } cleanup(hRebin); hRebin->SetName(histName); return hRebin; } TH1F *rebin2(TH1F *h, char *histName) { TH1F *hRebin = new TH1F(Form("%s_rebin",h->GetName()),Form("rebin %s",h->GetTitle()),nbins_recrebin_2,boundaries_recrebin_2); for (int i=1;i<=h->GetNbinsX();i++) { double val=h->GetBinContent(i); double valErr=h->GetBinError(i); int binNum = hRebin->FindBin(h->GetBinCenter(i)); double val1 = hRebin->GetBinContent(binNum); double valErr1 = hRebin->GetBinError(binNum); hRebin->SetBinContent(binNum,val+val1); hRebin->SetBinError(binNum,sqrt(valErr1*valErr1+valErr*valErr)); } cleanup(hRebin); hRebin->SetName(histName); return hRebin; } void drawText(const char *text, float xp, float yp, int size){ TLatex *tex = new TLatex(xp,yp,text); tex->SetTextFont(63); tex->SetTextSize(size); tex->SetTextColor(kBlack); tex->SetLineWidth(1); //tex->SetTextFont(42); tex->SetNDC(); tex->Draw(); } void putCMSPrel(double x, double y, double size){ TLatex *tex=0; tex = new TLatex(x,y,"CMS Preliminary"); tex->SetTextSize(size); tex->SetLineWidth(2); tex->SetNDC(); tex->Draw(); } void putCMSSim(double x, double y, double size){ TLatex *tex=0; tex = new TLatex(x,y,"CMS Simulation"); tex->SetTextSize(size); tex->SetLineWidth(2); tex->SetNDC(); tex->Draw(); } TLegend *myLegend(double x1,double y1,double x2, double y2) { TLegend *leg = new TLegend(x1,y1,x2,y2); leg->SetBorderSize(0); leg->SetFillStyle(0); return leg; } */ void nlo_comp_macro(int radius = 3){ TH1::SetDefaultSumw2(); gStyle->SetOptStat(0); TFile *fPP = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/result-2013-akVs3PF-cent-1-isFineBin-0/pbpb_pp_merged_chmx_pt_isMC_0_Unfo_2013_akVs3PF_cent_1_isFineBin_0.root"); //TFile *fNLO_err = TFile::Open("fnl4350a_cteq"); TFile *fNLO_nnpdf = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_nnpdf21-nlo_aspdf_new.root"); TFile *fNLO_cteq = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_cteq66-nlo_aspdf_all_new.root"); TFile *fNLO_ct10n = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_ct10n-nlo_aspdf_new.root"); TFile *fNLO_hera = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_hera15all-nlo_aspdf_new.root"); //alright lets get the unfolded data here: remember we need it for eta range -2 to +2 //TFile* fPP_unfo_R3 = TFile::Open("pp_2013_2760_abs_eta_2_mc_ak3PF.root"); TFile* fPP_unfo_R4 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/pp_2013_2760_abs_eta_2_mc_ak4PF.root"); TFile* fPP_unfo_R5 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/pp_2013_2760_abs_eta_2_mc_ak5PF.root"); //TFile *f_unfold_R2 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/PbPb_pp_unfold_marguerite_jet80_chMaxjtpt_norawptcut_test_65GeVCut_akPu2PF_20150205_test.root"); TFile *f_unfold_R3 = TFile::Open(Form("Pawan_ntuple_PbPb_pp_calopfpt_ppNoJetidcut_nlobins_R0p%d_without80FakeRemoval_unfold_mcclosure_oppside_trgMC_noSmear_20_eta_20_%dGeVCut_akPF_20150522.root",3,40)); //TFile *f_unfold_R4 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/PbPb_pp_unfold_marguerite_jet80_chMaxjtpt_norawptcut_test_65GeVCut_akPu4PF_20150205_test.root"); TH1F* hPP_data_R_3 = (TH1F*)f_unfold_R3->Get("PP_bayesian_unfolded_spectra"); hPP_data_R_3->Print("base"); hPP_data_R_3 = (TH1F*)hPP_data_R_3->Rebin(nbins_yaxian, "PP_bayesian_unfolded_spectra", boundaries_yaxian); divideBinWidth(hPP_data_R_3); hPP_data_R_3->Print("base"); //PP_measured[0] = (TH1F*)f_unfold_R2->Get("PP_measured_unfolded_spectra"); //PP_binbybin[0] = (TH1F*)f_unfold_R2->Get("PP_binbybin_unfolded_spectra"); //TH1F* PP_bayesian[1] = (TH1F*)f_unfold_R4->Get("PP_bayesian_unfolded_spectra"); //PP_measured[1] = (TH1F*)f_unfold_R3->Get("PP_measured_unfolded_spectra"); //PP_binbybin[1] = (TH1F*)f_unfold_R3->Get("PP_binbybin_unfolded_spectra"); TFile fout("pp_2760GeV_nlo_histos.root","RECREATE"); fout.cd(); TH1F* hPP_nnpdf_NLO = (TH1F*)fNLO_nnpdf->Get(Form("h100%d00",radius-1)); TH1F* hPP_cteq_NLO = (TH1F*)fNLO_cteq->Get(Form("h100%d00",radius-1)); TH1F* hPP_ct10n_NLO = (TH1F*)fNLO_ct10n->Get(Form("h100%d00",radius-1)); TH1F* hPP_hera_NLO = (TH1F*)fNLO_hera->Get(Form("h100%d00",radius-1)); //TH1F* hPP_data_R_3 = (TH1F*)fPP_unfo_R3->Get("Unfolded_cent1"); TH1F* hPP_data_R_4 = (TH1F*)fPP_unfo_R4->Get("Unfolded_cent1"); TH1F* hPP_data_R_5 = (TH1F*)fPP_unfo_R5->Get("Unfolded_cent1"); hPP_data_R_3->Scale(5.3*1e3); hPP_data_R_3->Scale(1./5300e6); //hPP_data_R_3->Scale(1./4); //divideBinWidth(hPP_data_R_3); hPP_data_R_4->Scale(1./5300e6); hPP_data_R_4->Scale(1./4); divideBinWidth(hPP_data_R_4); hPP_data_R_5->Scale(1./5300e6); hPP_data_R_5->Scale(1./4); divideBinWidth(hPP_data_R_5); // NLO histograms without any R# at the end correspond to R=0.3 the standard. others are named accordingly TH1F* hPP_nnpdf_NLO_R4 = (TH1F*)fNLO_nnpdf->Get("h100300"); TH1F* hPP_nnpdf_NLO_R2 = (TH1F*)fNLO_nnpdf->Get("h100100"); TH1F* hPP_cteq_NLO_R4 = (TH1F*)fNLO_cteq->Get("h100300"); TH1F* hPP_ct10n_NLO_R4 = (TH1F*)fNLO_ct10n->Get("h100300"); TH1F* hPP_hera_NLO_R4 = (TH1F*)fNLO_hera->Get("h100300"); TH1F* hPP_cteq_NLO_R2 = (TH1F*)fNLO_cteq->Get("h100100"); TH1F* hPP_ct10n_NLO_R2 = (TH1F*)fNLO_ct10n->Get("h100100"); TH1F* hPP_hera_NLO_R2 = (TH1F*)fNLO_hera->Get("h100100"); TH1F* hPP_err = (TH1F*)fNLO_cteq->Get("h100203"); TH1F* hPP_err_R4 = (TH1F*)fNLO_cteq->Get("h100303"); TH1F* hPP_err_R2 = (TH1F*)fNLO_cteq->Get("h100103"); for(int i = 0;i<hPP_nnpdf_NLO->GetNbinsX();i++){ Float_t valErr = hPP_err->GetBinError(i); hPP_nnpdf_NLO->SetBinError(i,valErr); hPP_cteq_NLO->SetBinError(i,valErr); hPP_hera_NLO->SetBinError(i,valErr); hPP_ct10n_NLO->SetBinError(i,valErr); Float_t valErr_R4 = hPP_err_R4->GetBinError(i); hPP_nnpdf_NLO_R4->SetBinError(i,valErr_R4); hPP_cteq_NLO_R4->SetBinError(i,valErr_R4); hPP_ct10n_NLO_R4->SetBinError(i,valErr_R4); hPP_hera_NLO_R4->SetBinError(i,valErr_R4); Float_t valErr_R2 = hPP_err_R2->GetBinError(i); hPP_nnpdf_NLO_R2->SetBinError(i,valErr_R2); hPP_cteq_NLO_R2->SetBinError(i,valErr_R2); hPP_ct10n_NLO_R2->SetBinError(i,valErr_R2); hPP_hera_NLO_R2->SetBinError(i,valErr_R2); } //add the NPC factors char etaWidth[dir][256] = { "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15", "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10", "p10_eta_p15","p15_eta_p20", "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15", "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10", "p10_eta_p15","p15_eta_p20", "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15", "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10", "p10_eta_p15","p15_eta_p20", "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15", "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10", "p10_eta_p15","p15_eta_p20", "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15", "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10", "p10_eta_p15","p15_eta_p20" }; char radius_lable[dir][256] = { "R2","R2","R2","R2","R2","R2","R2","R2","R2","R2", "R3","R3","R3","R3","R3","R3","R3","R3","R3","R3", "R4","R4","R4","R4","R4","R4","R4","R4","R4","R4", "R5","R5","R5","R5","R5","R5","R5","R5","R5","R5", "R7","R7","R7","R7","R7","R7","R7","R7","R7","R7" }; ifstream fin_txt[dir]; int energy = 2760; for(int i = 0;i<dir;i++){ //ostringstream filename; //filename<<"/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_8_HI_patch2/src/Macros/RAA/nlo_files/input_np_txtfiles/NPC_ak_"<<radius_lable[i]<<etaWidth[i]<<"_energy"<<energy<<".txt"; fin_txt[i].open(Form("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_8_HI_patch2_old/src/Macros/RAA/nlo_files/input_np_txtfiles/NPC_ak_%s_%s_energy%d.txt",radius_lable[i],etaWidth[i],energy)); } //apply the correction factors to the NLO histograms Float_t npc = 0; Float_t bin = 0; //before applying the corrections, lets get a clone of the uncorrected histogram. TH1F* hPP_nnpdf_NLO_noNPC = (TH1F*)hPP_nnpdf_NLO->Clone("hPP_nnpdf_NLO_noNPC"); int counter = 0; while(1){ fin_txt[11]>>bin>>npc; cout<<bin<<" "<<npc<<endl; if(!fin_txt[11].good())break; int bin_no = hPP_nnpdf_NLO->FindBin(bin); //cout<<"bin no = "<<bin_no<<endl; //cout<<"boundaries_pt of bin no"<<boundaries_yaxian_large[bin_no]<<endl; cout<<"value before applying = "<<hPP_nnpdf_NLO->GetBinContent(bin_no)<<endl; hPP_nnpdf_NLO->SetBinContent(bin_no,npc*hPP_nnpdf_NLO->GetBinContent(bin_no)); cout<<"value after applying = "<<hPP_nnpdf_NLO->GetBinContent(bin_no)<<endl; hPP_cteq_NLO->SetBinContent(bin_no,npc*hPP_cteq_NLO->GetBinContent(bin_no)); hPP_ct10n_NLO->SetBinContent(bin_no,npc*hPP_ct10n_NLO->GetBinContent(bin_no)); hPP_hera_NLO->SetBinContent(bin_no,npc*hPP_hera_NLO->GetBinContent(bin_no)); fin_txt[1]>>bin>>npc; if(!fin_txt[1].good())break; bin_no = hPP_nnpdf_NLO_R2->FindBin(bin); hPP_nnpdf_NLO_R2->SetBinContent(bin_no,npc*hPP_nnpdf_NLO_R2->GetBinContent(bin_no)); hPP_cteq_NLO_R2->SetBinContent(bin_no,npc*hPP_cteq_NLO_R2->GetBinContent(bin_no)); hPP_ct10n_NLO_R2->SetBinContent(bin_no,npc*hPP_ct10n_NLO_R2->GetBinContent(bin_no)); hPP_hera_NLO_R2->SetBinContent(bin_no,npc*hPP_hera_NLO_R2->GetBinContent(bin_no)); fin_txt[21]>>bin>>npc; if(!fin_txt[21].good())break; bin_no = hPP_nnpdf_NLO_R4->FindBin(bin); hPP_nnpdf_NLO_R4->SetBinContent(bin_no,npc*hPP_nnpdf_NLO_R4->GetBinContent(bin_no)); hPP_cteq_NLO_R4->SetBinContent(bin_no,npc*hPP_cteq_NLO_R4->GetBinContent(bin_no)); hPP_ct10n_NLO_R4->SetBinContent(bin_no,npc*hPP_ct10n_NLO_R4->GetBinContent(bin_no)); hPP_hera_NLO_R4->SetBinContent(bin_no,npc*hPP_hera_NLO_R4->GetBinContent(bin_no)); counter++; } cout<<"counter = "<<counter<<endl; //get a clone after applying the corrections, TH1F* hPP_nnpdf_NLO_NPC = (TH1F*)hPP_nnpdf_NLO->Clone("hPP_nnpdf_NLO_NPC"); TH1F* hPP_NPC_ratio = (TH1F*)hPP_nnpdf_NLO_NPC->Clone("hPP_NPC_ratio"); hPP_NPC_ratio->Divide(hPP_nnpdf_NLO_noNPC); /* TCanvas *cnpc = new TCanvas("cnpc","",800,600); //cnpc->SetLogy(); hPP_NPC_ratio->SetTitle("NPC 2.76 TeV R=0.3"); hPP_NPC_ratio->SetXTitle("Jet p_{T} (GeV/c)"); hPP_NPC_ratio->SetYTitle("NP factors"); hPP_NPC_ratio->SetAxisRange(0.7,1.3,"Y"); hPP_NPC_ratio->Draw(); cnpc->SaveAs("pp_2760_npc_R3.pdf","RECREATE"); */ hPP_nnpdf_NLO->SetName("hPP_nnpdf_NLO"); hPP_cteq_NLO->SetName("hPP_cteq_NLO"); hPP_ct10n_NLO->SetName("hPP_ct10n_NLO"); hPP_hera_NLO->SetName("hPP_hera_NLO"); hPP_nnpdf_NLO_R2->SetName("hPP_nnpdf_NLO_R2"); hPP_nnpdf_NLO_R2->Print("base"); hPP_cteq_NLO_R2->SetName("hPP_cteq_NLO_R2"); hPP_cteq_NLO_R2->Print("base"); hPP_ct10n_NLO_R2->SetName("hPP_ct10n_NLO_R2"); hPP_ct10n_NLO_R2->Print("base"); hPP_hera_NLO_R2->SetName("hPP_hera_NLO_R2"); hPP_nnpdf_NLO_R4->SetName("hPP_nnpdf_NLO_R4"); hPP_cteq_NLO_R4->SetName("hPP_cteq_NLO_R4"); hPP_ct10n_NLO_R4->SetName("hPP_ct10n_NLO_R4"); hPP_hera_NLO_R4->SetName("hPP_hera_NLO_R4"); hPP_nnpdf_NLO->Write(); hPP_cteq_NLO->Write(); hPP_ct10n_NLO->Write(); hPP_hera_NLO->Write(); hPP_nnpdf_NLO_R2->Write(); hPP_cteq_NLO_R2->Write(); hPP_ct10n_NLO_R2->Write(); hPP_hera_NLO_R2->Write(); hPP_nnpdf_NLO_R4->Write(); hPP_cteq_NLO_R4->Write(); hPP_ct10n_NLO_R4->Write(); hPP_hera_NLO_R4->Write(); TH1F* hPPrebin = (TH1F*)hPP_data_R_3->Clone("hPPrebin"); //TH1F* hPPrebin_test = (TH1F*)faditya->Get("Corrected Jet Spectrum Aditya"); //TH1F* hPPrebin = (TH1F*)hPPrebin_test->Rebin(nbins_yaxian_large,"hPPrebin",boundaries_yaxian_large); //TH1F* hPPunfo = (TH1F*)fPP->Get("Unfolded_cent6"); TH1F* hPPgen = (TH1F*)fPP->Get("hGen_cent1"); //hPPrebin->Scale(64);//remove the sigma scaling from the previous macros //dont need this now since we are taking it from a dedicated macro which gives us diff cross section hPP_data_R_3->Scale(1e9); hPP_data_R_4->Scale(1e9); hPP_data_R_5->Scale(1e9); //hPP_nnpdf_NLO->Scale(1./4); //hPP_cteq_NLO->Scale(1./4); //hPP_hera_NLO->Scale(1./4); hPPrebin->Scale(1e9); //hPPrebin->Scale(1./5300e6); //hPPrebin->Scale(1./4); //divideBinWidth(hPPrebin); hPPgen->Scale(1./4); hPPgen->Scale(1e9); fout.Write(); hPP_nnpdf_NLO = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"nnpdf_pp", boundaries_yaxian); hPP_nnpdf_NLO->Print("base"); hPP_cteq_NLO = (TH1F*)hPP_cteq_NLO->Rebin(nbins_yaxian,"cteq_pp", boundaries_yaxian); hPP_cteq_NLO->Print("base"); hPP_hera_NLO = (TH1F*)hPP_hera_NLO->Rebin(nbins_yaxian,"hera_pp", boundaries_yaxian); hPP_hera_NLO->Print("base"); hPP_ct10n_NLO = (TH1F*)hPP_ct10n_NLO->Rebin(nbins_yaxian,"ct10n_pp", boundaries_yaxian); hPP_ct10n_NLO->Print("base"); TH1F* hRatio_nnpdf_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_nnpdf_mc",boundaries_yaxian); hRatio_nnpdf_mc->Divide(hPP_nnpdf_NLO); TH1F* hRatio_cteq_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_cteq_mc",boundaries_yaxian); hRatio_cteq_mc->Divide(hPP_cteq_NLO); TH1F* hRatio_hera_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_hera_mc",boundaries_yaxian); hRatio_hera_mc->Divide(hPP_hera_NLO); TH1F* hRatio_ct10n_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_ct10n_mc",boundaries_yaxian); hRatio_ct10n_mc->Divide(hPP_ct10n_NLO); TH1F* hRatio_nnpdf = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"hRatio_nnpdf",boundaries_yaxian); hRatio_nnpdf->Divide(hPPrebin); TH1F* hRatio_cteq = (TH1F*)hPP_cteq_NLO->Rebin(nbins_yaxian,"hRatio_cteq",boundaries_yaxian); hRatio_cteq->Divide(hPPrebin); TH1F* hRatio_ct10n = (TH1F*)hPP_ct10n_NLO->Rebin(nbins_yaxian,"hRatio_ct10n",boundaries_yaxian); hRatio_ct10n->Divide(hPPrebin); TH1F* hRatio_hera = (TH1F*)hPP_hera_NLO->Rebin(nbins_yaxian,"hRatio_hera",boundaries_yaxian); hRatio_hera->Divide(hPPrebin); TH1F* hRatio_ppgen = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_ppgen",boundaries_yaxian); hRatio_ppgen->Divide(hPPrebin); TH1F* hRatio_nnpdf_R_2_4 = (TH1F*)hPP_nnpdf_NLO_R2->Rebin(nbins_yaxian,"hRatio_nnpdf_R_2_4",boundaries_yaxian); hRatio_nnpdf_R_2_4->Divide(hPP_nnpdf_NLO_R4); TH1F* hRatio_nnpdf_R_3_4 = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"hRatio_nnpdf_R_3_4",boundaries_yaxian); hRatio_nnpdf_R_3_4->Divide(hPP_nnpdf_NLO_R4); TH1F* hRatio_cteq_R_2_4 = (TH1F*)hPP_cteq_NLO_R2->Rebin(nbins_yaxian,"hRatio_cteq_R_2_4",boundaries_yaxian); hRatio_cteq_R_2_4->Divide(hPP_cteq_NLO_R4); TH1F* hRatio_cteq_R_3_4 = (TH1F*)hPP_cteq_NLO->Rebin(nbins_yaxian,"hRatio_cteq_R_3_4",boundaries_yaxian); hRatio_cteq_R_3_4->Divide(hPP_cteq_NLO_R4); TH1F* hRatio_ct10n_R_2_4 = (TH1F*)hPP_ct10n_NLO_R2->Rebin(nbins_yaxian,"hRatio_ct10n_R_2_4",boundaries_yaxian); hRatio_ct10n_R_2_4->Divide(hPP_ct10n_NLO_R4); TH1F* hRatio_ct10n_R_3_4 = (TH1F*)hPP_ct10n_NLO->Rebin(nbins_yaxian,"hRatio_ct10n_R_3_4",boundaries_yaxian); hRatio_ct10n_R_3_4->Divide(hPP_ct10n_NLO_R4); TH1F* hRatio_hera_R_2_4 = (TH1F*)hPP_hera_NLO_R2->Rebin(nbins_yaxian,"hRatio_hera_R_2_4",boundaries_yaxian); hRatio_hera_R_2_4->Divide(hPP_hera_NLO_R4); TH1F* hRatio_hera_R_3_4 = (TH1F*)hPP_hera_NLO->Rebin(nbins_yaxian,"hRatio_hera_R_3_4",boundaries_yaxian); hRatio_hera_R_3_4->Divide(hPP_hera_NLO_R4); TH1F* hRatio_data_nnpdf_R_3 = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"hRatio_data_nnpdf_R_3",boundaries_yaxian); hRatio_data_nnpdf_R_3->Divide(hPP_data_R_3); TH1F* hRatio_data_nnpdf_R_4 = (TH1F*)hPP_nnpdf_NLO_R4->Rebin(nbins_yaxian,"hRatio_data_nnpdf_R_4",boundaries_yaxian); hRatio_data_nnpdf_R_4->Divide(hPP_data_R_4); TH1F* hRatio_data_R_3_4 = (TH1F*)hPP_data_R_3->Clone("hRatio_data_R_3_4"); hRatio_data_R_3_4->Divide(hPP_data_R_4); TH1F* hRatio_data_R_3_5 = (TH1F*)hPP_data_R_3->Clone("hRatio_data_R_3_5"); hRatio_data_R_3_5->Divide(hPP_data_R_5); TH1F* hRatio_data_R_4_5 = (TH1F*)hPP_data_R_4->Clone("hRatio_data_R_4_5"); hRatio_data_R_4_5->Divide(hPP_data_R_5); /* TCanvas *cnlo_mc = new TCanvas("cnlo_mc","",800,600); hRatio_nnpdf_mc->SetMarkerColor(kRed); hRatio_nnpdf_mc->SetMarkerStyle(20); hRatio_nnpdf_mc->SetXTitle("Jet p_{T} (GeV/c)"); hRatio_nnpdf_mc->SetYTitle("MC/NLO"); hRatio_nnpdf_mc->SetTitle(" "); hRatio_nnpdf_mc->SetAxisRange(0,1.5,"Y"); hRatio_nnpdf_mc->Draw(); hRatio_cteq_mc->SetMarkerColor(kBlue); hRatio_cteq_mc->SetMarkerStyle(20); hRatio_cteq_mc->Draw("same"); hRatio_ct10n_mc->SetMarkerColor(9); hRatio_ct10n_mc->SetMarkerStyle(20); hRatio_ct10n_mc->Draw("same"); hRatio_hera_mc->SetMarkerColor(kGreen); hRatio_hera_mc->SetMarkerStyle(20); hRatio_hera_mc->Draw("same"); TLegend *titlenlomc = myLegend(0.10,0.10,0.30,0.30); titlenlomc->AddEntry(hRatio_nnpdf_mc,"nnpdf","pl"); titlenlomc->AddEntry(hRatio_cteq_mc,"cteq","pl"); titlenlomc->AddEntry(hRatio_ct10n_mc,"ct10n","pl"); titlenlomc->AddEntry(hRatio_hera_mc,"hera","pl"); titlenlomc->SetTextSize(0.04); titlenlomc->Draw(); putCMSSim(0.1,0.92,0.06); drawText("pp #sqrt{s}=2.76(TeV)",0.65,0.92,16); drawText(Form("anti k_{T} R = 0.%d, NP corrections added to NLO",radius),0.15,0.83,16); cnlo_mc->SaveAs(Form("Ratio_mc_with_nlo_with_np_R%d.pdf",radius),"RECREATE"); */ TCanvas *c1 = new TCanvas("c1","",800,600); formatCanvas(c1); c1->cd(1); c1->cd(1)->SetLogy(); hPP_nnpdf_NLO->SetMarkerColor(kRed); hPP_nnpdf_NLO->SetMarkerStyle(33); hPP_cteq_NLO->SetMarkerColor(kBlue); hPP_cteq_NLO->SetMarkerStyle(33); hPP_ct10n_NLO->SetMarkerColor(9);//purple hPP_ct10n_NLO->SetMarkerStyle(33); hPP_hera_NLO->SetMarkerColor(kGreen); hPP_hera_NLO->SetMarkerStyle(33); hPPrebin->SetMarkerColor(kBlack); hPPrebin->SetMarkerStyle(8); hPPgen->SetMarkerColor(kOrange); hPPgen->SetMarkerStyle(8); //hPPgen->SetMarkerColor(kRed); //hPPgen->SetMarkerStyle(8); makeHistTitle(hPP_nnpdf_NLO,"","p_{T} (GeV/c)","#frac{d^{2} #sigma}{d p_{T} d #eta} (pb#frac{GeV}{c})"); //hPP_nnpdf_NLO->SetYTitle("#frac{d^{2} #sigma}{d p_{T} d #eta} (pb#frac{GeV}{c})"); //hPP_nnpdf_NLO->SetXTitle("p_{T} (GeV/c)"); hPP_nnpdf_NLO->SetAxisRange(22,500,"X"); hPP_nnpdf_NLO->SetTitle(" "); hPP_nnpdf_NLO->Draw("p"); hPP_cteq_NLO->Draw("same p"); hPP_ct10n_NLO->Draw("same p"); hPP_hera_NLO->Draw("same p"); hPPrebin->Draw("same p"); //hPPgen->Draw("same p"); TLegend * title = myLegend(0.47, 0.50,0.67, 0.8); title->AddEntry(hPP_nnpdf_NLO,"NLO nnpdf","pl"); title->AddEntry(hPP_cteq_NLO,"NLO cteq","pl"); title->AddEntry(hPP_ct10n_NLO,"NLO ct10n","pl"); title->AddEntry(hPP_hera_NLO,"NLO hera","pl"); //title->AddEntry(hPPgen,"pp MC spectra","pl"); title->AddEntry(hPPrebin,"pp unfolded 2013 data","pl"); title->SetTextSize(0.04); title->Draw(); putCMSPrel(0.1,0.92,0.06); drawText("pp 2013, #sqrt{s}=2.76(TeV), #int L dt = 5.3 (pb)^{-1}",0.35,0.92,16); drawText(Form("anti k_{T} R = 0.3, NP corrections added to NLO",radius),0.35,0.83,16); c1->cd(2); makeHistTitle(hRatio_nnpdf,"","p_{T} (GeV/c)","NLO / pp data"); //hRatio_nnpdf->SetYTitle(" X / pp data"); //hRatio_nnpdf->SetXTitle("p_{T} (GeV/c)"); hRatio_nnpdf->SetTitle(" "); hRatio_nnpdf->SetAxisRange(0.8,2,"Y"); hRatio_nnpdf->SetMarkerColor(kRed); hRatio_nnpdf->SetMarkerStyle(33); hRatio_hera->SetMarkerColor(kGreen); hRatio_hera->SetMarkerStyle(33); hRatio_cteq->SetMarkerColor(kBlue); hRatio_cteq->SetMarkerStyle(33); hRatio_ct10n->SetMarkerColor(9); hRatio_ct10n->SetMarkerStyle(33); hRatio_ppgen->SetMarkerColor(kOrange); hRatio_ppgen->SetMarkerStyle(33); hRatio_nnpdf->Draw("p"); hRatio_nnpdf->SetAxisRange(22,500,"X"); hRatio_hera->Draw("same p"); hRatio_cteq->Draw("same p"); hRatio_ct10n->Draw("same p"); //hRatio_ppgen->Draw("same p"); c1->SaveAs(Form("May22/pp_2760GeV_NLO_NPadded_ak%dPF_spectra.pdf",radius),"RECREATE"); /* //get the information from the ratio per bins - to use to scale down the NLO in 5.02 TeV. ofstream R_nnpdf,R_hera,R_cteq; R_nnpdf.open(Form("ratio_nnpdf_vs_pp_data_2760_ak%d.txt",radius)); R_hera.open(Form("ratio_hera_vs_pp_data_2760_ak%d.txt",radius)); R_cteq.open(Form("ratio_cteq_vs_pp_data_2760_ak%d.txt",radius)); for(int i = 0;i<hRatio_nnpdf->GetNbinsX();i++){ R_nnpdf<<i<<"\t"<<hRatio_nnpdf->GetBinContent(i)<<endl; R_hera<<i<<"\t"<<hRatio_hera->GetBinContent(i)<<endl; R_cteq<<i<<"\t"<<hRatio_cteq->GetBinContent(i)<<endl; } R_nnpdf.close(); R_hera.close(); R_cteq.close(); //draw the results for NLO comparison within different radius at the same energy TCanvas *c2 = new TCanvas("c2","",800,600); formatCanvas(c2); c2->cd(1); hPP_nnpdf_NLO->SetMarkerStyle(22); hPP_nnpdf_NLO->SetMarkerColor(3); hPP_nnpdf_NLO->Draw("p"); hPP_nnpdf_NLO_R2->SetMarkerStyle(22); hPP_nnpdf_NLO_R2->SetMarkerColor(2); hPP_nnpdf_NLO_R2->Draw("same p"); hPP_nnpdf_NLO_R4->SetMarkerStyle(22); hPP_nnpdf_NLO_R4->SetMarkerColor(4); hPP_nnpdf_NLO_R4->Draw("same p"); hPP_data_R_4->SetMarkerStyle(23); hPP_data_R_4->SetMarkerColor(4); hPP_data_R_4->Draw("same p"); hPP_data_R_3->SetMarkerStyle(23); hPP_data_R_3->SetMarkerColor(3); hPP_data_R_3->Draw("same p"); hPP_data_R_5->SetMarkerStyle(23); hPP_data_R_5->SetMarkerColor(9); hPP_data_R_5->Draw("same p"); TLegend * title2 = myLegend(0.47, 0.50,0.67, 0.8); title2->AddEntry(hPP_nnpdf_NLO_R2,"NNPDF21 R=0.2","pl"); title2->AddEntry(hPP_nnpdf_NLO,"NNPDF21 R=0.3","pl"); title2->AddEntry(hPP_nnpdf_NLO_R4,"NNPDF21 R=0.4","pl"); title2->AddEntry(hPP_data_R_3,"Data R=0.3","pl"); title2->AddEntry(hPP_data_R_4,"Data R=0.4","pl"); title2->AddEntry(hPP_data_R_5,"Data R=0.5","pl"); title2->SetTextSize(0.04); title2->Draw(); putCMSPrel(0.1,0.92,0.06); drawText("pp 2013, #sqrt{s}=2.76(TeV), #int L dt = 5.3 (pb)^{-1}",0.35,0.92,16); drawText(Form("anti k_{T}, Data vs Theory",radius),0.47,0.83,16); c2->cd(2); hRatio_nnpdf_R_2_4->SetMarkerStyle(29); hRatio_nnpdf_R_2_4->SetMarkerColor(2); hRatio_nnpdf_R_2_4->SetAxisRange(0.6,1.6,"Y"); hRatio_nnpdf_R_2_4->SetAxisRange(22,500,"X"); hRatio_nnpdf_R_2_4->SetTitle(" "); hRatio_nnpdf_R_2_4->SetYTitle("Ratios"); hRatio_nnpdf_R_2_4->SetXTitle("p_{T}(GeV/c)"); hRatio_nnpdf_R_2_4->Draw("p"); hRatio_nnpdf_R_3_4->SetMarkerStyle(29); hRatio_nnpdf_R_3_4->SetMarkerColor(3); hRatio_nnpdf_R_3_4->Draw("same p"); hRatio_data_nnpdf_R_3->SetMarkerStyle(33); hRatio_data_nnpdf_R_3->SetMarkerColor(4); hRatio_data_nnpdf_R_3->Draw("same p"); hRatio_data_nnpdf_R_4->SetMarkerStyle(33); hRatio_data_nnpdf_R_4->SetMarkerColor(7); hRatio_data_nnpdf_R_4->Draw("same p"); hRatio_data_R_3_4->SetMarkerStyle(34); hRatio_data_R_3_4->SetMarkerColor(6); hRatio_data_R_3_4->Draw("same p"); hRatio_data_R_3_5->SetMarkerStyle(34); hRatio_data_R_3_5->SetMarkerColor(7); hRatio_data_R_3_5->Draw("same p"); hRatio_data_R_4_5->SetMarkerStyle(34); hRatio_data_R_4_5->SetMarkerColor(8); hRatio_data_R_4_5->Draw("same p"); c2->cd(1); TLegend * title3 = myLegend(0.67, 0.40,0.77, 0.8); title3->AddEntry(hRatio_nnpdf_R_2_4,"NLO R=0.2/R=0.4","pl"); title3->AddEntry(hRatio_nnpdf_R_3_4,"NLO R=0.3/R=0.4","pl"); title3->AddEntry(hRatio_data_nnpdf_R_3,"R=0.3 NNPDF21/Data","pl"); title3->AddEntry(hRatio_data_nnpdf_R_4,"R=0.4 NNPDF21/Data","pl"); title3->AddEntry(hRatio_data_R_3_4,"Data R=0.3/R=0.4","pl"); title3->AddEntry(hRatio_data_R_3_5,"Data R=0.3/R=0.5","pl"); title3->AddEntry(hRatio_data_R_4_5,"Data R=0.4/R=0.5","pl"); title3->SetTextSize(0.04); title3->Draw(); c2->SaveAs("pp_2760GeV_data_NLO_NPCadded_radius_comparison.pdf","RECREATE"); fout.Write(); fout.Close(); */ /* TCanvas *c2 = new TCanvas("c2","",1000,800); c2->Divide(2,1); c2->cd(1); c2->cd(1)->SetLogy(); hPPunfo->SetTitle("PP 2013 2.76 TeV Merged, Unfolded p_{T} Spectra"); hPPunfo->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}"); hPPunfo->GetYaxis()->SetTitleOffset(1.4); hPPunfo->SetXTitle("Jet p_{T} GeV/c"); hPPunfo->GetXaxis()->SetRangeUser(50,500); hPPunfo->Draw(); hPPmeas->GetXaxis()->SetRangeUser(50,500); hPPmeas->SetMarkerStyle(22); hPPmeas->SetMarkerColor(kBlack); hPPmeas->Draw("same"); TLegend *titl = myLegend(0.54,0.65,0.85,0.9); titl->AddEntry(hPPmeas,"PP2013 Meas ak3PF","pl"); titl->AddEntry(hPPunfo,"PP2013 Unfo Bayesian","pl"); titl->SetTextSize(0.03); titl->Draw(); drawText("Anti-k_{T}PF R = 0.3",0.43,0.6,22); drawText("|#eta|<2, |vz|<15",0.47,0.5,22); c2->cd(2); TH1F* hPPRatio = (TH1F*)hPPmeas->Clone("hPPRatio"); hPPRatio->Divide(hPPunfo); hPPRatio->SetXTitle("Jet p_{T} GeV/c"); hPPRatio->SetYTitle("Ratio Measured/Unfolded"); hPPRatio->SetTitle("PP2013 ak3PF merged"); hPPRatio->GetYaxis()->SetRangeUser(0,2); hPPRatio->Draw(); c2->SaveAs("pp_2013_ak3_merged_unfolded_pt.pdf","RECREATE"); */ /* TH1F *hNLO_err = (TH1F*)fNLO->Get("h100203"); for(int i = 0;i<hNLO_err->GetNbinsX();i++){ Float_T valErr = hNLO_Err->GetBinError(i); hNLO->SetBinError(i,valErr); } */ /* //h100300 - ak4PF, h100200 - ak3PF TH1F* hNLO_2 = (TH1F*)hNLO->Clone("hNLO_2"); hNLO->Print("base"); TCanvas *cComp = new TCanvas("cComp","",800,600); cComp->Divide(2,1); cComp->cd(1); cComp->cd(1)->SetLogy(); hPPrebin->SetMarkerStyle(22); hPPrebin->SetMarkerColor(kRed); hNLO->SetMarkerStyle(20); hNLO->SetMarkerColor(kBlack); hNLO->SetTitle("PP 2.76 TeV"); hNLO->SetYTitle("#sigma pb"); hNLO->SetXTitle("Jet p_{T} GeV/c"); hNLO->Draw("pl"); hPPMCrebin->SetMarkerStyle(21); hPPMCrebin->SetMarkerColor(kBlue); hPPMCrebin->Draw("same"); hPPrebin->Draw("same"); TLegend *title = myLegend(0.34,0.65,0.54,0.75); title->AddEntry(hNLO,"NLO nnpdf21","pl"); title->AddEntry(hPPrebin,"PP ak3PF unfo","pl"); title->AddEntry(hPPMCrebin,"PP ak3PF MC Gen","pl"); title->SetTextSize(0.06); title->Draw(); cComp->cd(2); TH1F *hPP = (TH1F*)hPPrebin->Clone("hPP"); TH1F* hPPMC_v2 = (TH1F*)hPPMCrebin->Clone("hPPMC_v2"); hPP->Print("base"); hPPMC_v2->Print("base"); hPP->Divide(hNLO); hPPMC_v2->Divide(hNLO); hPP->SetTitle("Ratio of PP ak3PF unfolded and MC Gen to NLO"); //hPP->SetTitle("Ratio of PP ak4PF measured to NLO"); hPP->SetYTitle("#frac{#sigma_{PP}}{#sigma_{NLO}}"); hPP->SetXTitle("Jet p_{T} GeV/c"); hPP->Draw(); hPPMC_v2->Draw("same"); cComp->SaveAs("fastNLO_comparison/ratio_pp_ak3_merged_NLO_nnpdf21nlo.pdf","RECREATE"); TCanvas c1; c1.SetLogy(); hPPrebin->SetAxisRange(50,500,"X"); hPPrebin->SetYTitle("#sigma (pb)"); hPPrebin->SetXTitle("Jet p_{T} GeV/c"); hPPrebin->SetTitle("PP ak3PF unfolded"); hPPrebin->Draw(); c1.SaveAs("fastNLO_comparison/PP_2013_ak3_merged_Unfolded_crosssection.pdf","RECREATE"); c1.SaveAs("fastNLO_comparison/PP_2013_ak3_merged_Unfolded_crosssection.C","RECREATE"); TCanvas *c3 = new TCanvas("c3","",800,600); c3->SetGrid(); c3->SetLogy(); //TGraphErrors graph_Expected("./fastNLO_comparison/files/s2760_R0.3fine.tex","%lg %lg"); //graph_Expected.SetTitle("Non Perturbative corrections (extrapolation from Atlas) s2760;p_{T} GeV/c;#sigma nb"); //graph_Expected.DrawClone("E3AL"); TFile *fNPC = TFile::Open("fastNLO_comparison/files/npc_extrapolation_ivan.root"); TH1F* hNPC = (TH1F*)fNPC->Get("hNPC"); hNPC->Scale(1000);// 1000 for the pb from nb //hNPC->Print("base"); //TH1F* hNPC_rebin1 = rebin2(hNPC,"hNPC_rebin1"); //divideBinWidth(hNPC_rebin1); hNPC->SetTitle("Non Perturbative corrections (extrapolation from Atlas) s2760"); hNPC->SetXTitle("p_{T} GeV/c"); hNPC->SetYTitle("#sigma (pb)"); hNPC->Draw(); hPPrebin->Draw("same"); c3->SaveAs("fastNLO_comparison/NPC_atlas_ak3.pdf","RECREATE"); TCanvas *c4 = new TCanvas("c4","",800,600); c4->SetLogy(); //TH1F* hNPC_rebin = (TH1F*)hNPC->Clone("hNPC_rebin"); TH1F* hNPC_rebin = rebin2(hNPC,"hNPC_rebin"); divideBinWidth(hNPC_rebin); hPPrebin_2->SetTitle("PP Cross sections Data and Theory comparisons"); hPPrebin_2->SetYTitle("#sigma (pb)"); hPPrebin_2->SetXTitle("p_{T} GeV/c"); //hNPC_rebin->SetAxisRange(1e4,1e-2,"Y"); hPPrebin_2->SetMarkerStyle(23); hPPrebin_2->SetMarkerColor(kBlack); hPPrebin_2->SetAxisRange(50,450,"X"); hPPrebin_2->Draw("E"); //hPPrebin_2->SetAxisRange(50,450,"X"); hNPC_rebin->SetMarkerStyle(21); hNPC_rebin->SetMarkerColor(kRed); hNPC_rebin->Draw("same"); hNLO_2->SetMarkerStyle(25); hNLO_2->SetMarkerColor(kBlue); hNLO_2->Draw("same"); TLegend *title2 = myLegend(0.54,0.65,0.85,0.9); title2->AddEntry(hNPC_rebin,"Ivan NPC - Atlas R=0.3","pl"); title2->AddEntry(hPPrebin_2,"PP2013 ak3PF unfolded","pl"); title2->AddEntry(hNLO_2,"CMS NLO nnpdf21 R=0.3","l"); title2->SetTextSize(0.04); title2->Draw(); gStyle->SetOptStat(0); c4->SaveAs("fastNLO_comparison/pp_ak3_nlo_overlay_hist.pdf","RECREATE"); TCanvas *c6 = new TCanvas("c6","",800,600); TH1F* hPPratio = (TH1F*)hPPrebin_2->Clone("hPPratio"); //add the error bars directly before dividing them and then set that as the error. //FLoat_t delta_PP = 0; //Float_t delta_NPC = 0; //Float_t delta hPPratio->Divide(hNPC_rebin); hPPratio->SetTitle("Ratio of PP 2013 ak3 unfolded w/ Ivan's NPC Atlas"); hPPratio->SetYTitle(" "); hPPratio->SetXTitle("p_{T} GeV/c"); hPPratio->Draw(); c6->SaveAs("pp_ak3_npc_ratio.pdf","RECREATE"); TCanvas *c5 = new TCanvas("c5","",800,600); hNPC->Draw(); hNPC_rebin->Draw("same"); c5->SetLogy(); c5->SaveAs("Ivan_plot_rebin_ak3.pdf","RECREATE"); */ }
void CheckSDDInESD(TString filename="AliESDs.root", Int_t optTracks=kAll){ TFile* esdFile = TFile::Open(filename.Data()); if (!esdFile || !esdFile->IsOpen()) { printf("Error in opening ESD file"); return; } AliESDEvent * esd = new AliESDEvent; TTree* tree = (TTree*) esdFile->Get("esdTree"); if (!tree) { printf("Error: no ESD tree found"); return; } esd->ReadFromTree(tree); TH1F* hpt=new TH1F("hpt","",100,0.,10.); TH1F* hphi=new TH1F("hphi","",100,-1,1); TH1F* hlam=new TH1F("hlam","",100,-2.,2.); TH1F* halpha=new TH1F("halpha","",100,-7,7); TH1F* hitscl=new TH1F("hitscl","",7,-0.5,6.5); TH1F* htpccl=new TH1F("htpccl","",200,-0.5,199.5); TH1F* hitsmap=new TH1F("hitsmap","",64,-0.5,63.5); TH1F* hclulay=new TH1F("hclulay","",7,-1.5,5.5); TH1F* hvx=new TH1F("hvx","",100,-1.,1.); TH1F* hvy=new TH1F("hvy","",100,-1.,1.); TH1F* hvz=new TH1F("hvz","",100,-20.,20.); TH1F* hdedx3=new TH1F("hdedx3","",100,0.,300.); TH1F* hdedx4=new TH1F("hdedx4","",100,0.,300.); TH1F* hdedx5=new TH1F("hdedx5","",100,0.,300.); TH1F* hdedx6=new TH1F("hdedx6","",100,0.,300.); TH1F* hStatus=new TH1F("hStatus","",11,-1.5,9.5); // -- Local coordinates // -- Module histos TH1F* hAllPMod = new TH1F("hAllPmod","Crossing Tracks vs. Module",260,239.5,499.5); TH1F* hGoodPMod = new TH1F("hGoodPmod","PointsAssocToTrack per Module",260,239.5,499.5); TH1F* hBadRegMod = new TH1F("hBadRegmod","Tracks in BadRegion per Module",260,239.5,499.5); TH1F* hMissPMod = new TH1F("hMissPmod","Missing Points per Module",260,239.5,499.5); TH1F* hSkippedMod = new TH1F("hSkippedmod","Tracks in Skipped Module",260,239.5,499.5); TH1F* hOutAccMod = new TH1F("hOutAccmod","Tracks outside zAcc per Module",260,239.5,499.5); TH1F* hNoRefitMod = new TH1F("hNoRefitmod","Points rejected in refit per Module",260,239.5,499.5); TH1F* hAllPXloc = new TH1F("hAllPxloc","Crossing Tracks vs. Xloc",75, -3.75, 3.75); TH1F* hGoodPXloc = new TH1F("hGoodPxloc","PointsAssocToTrack vs. Xloc",75, -3.75, 3.75); TH1F* hBadRegXloc = new TH1F("hBadRegxloc","Tracks in BadRegion vs. Xloc",75, -3.75, 3.75); TH1F* hMissPXloc = new TH1F("hMissPxloc","Missing Points vs. Xloc",75, -3.75, 3.75); TH1F* hAllPZloc = new TH1F("hAllPzloc","Crossing Tracks vs. Zloc",77, -3.85, 3.85); TH1F* hGoodPZloc = new TH1F("hGoodPzloc","PointsAssocToTrack vs. Zloc",77, -3.85, 3.85); TH1F* hBadRegZloc = new TH1F("hBadRegzloc","Tracks in BadRegion vs. Zloc",77, -3.85, 3.85); TH1F* hMissPZloc = new TH1F("hMissPzloc","Missing Points vs. Zloc",77, -3.85, 3.85); TH2F* hdEdxVsMod=new TH2F("hdEdxVsMod","dE/dx vs. mod",260,239.5,499.5,100,0.,500.); gStyle->SetPalette(1); for (Int_t iEvent = 0; iEvent < tree->GetEntries(); iEvent++) { tree->GetEvent(iEvent); if (!esd) { printf("Error: no ESD object found for event %d", iEvent); return; } cout<<"-------- Event "<<iEvent<<endl; printf(" Tracks # = %d\n",esd->GetNumberOfTracks()); const AliESDVertex *spdv=esd->GetVertex(); printf(" SPD Primary Vertex in %f %f %f with %d contributors\n",spdv->GetX(),spdv->GetY(),spdv->GetZ(),spdv->GetNContributors()); const AliESDVertex *trkv=esd->GetPrimaryVertex(); printf(" Track Primary Vertex with %d contributors\n",trkv->GetNContributors()); if(spdv->IsFromVertexer3D()){ hvx->Fill(spdv->GetX()); hvy->Fill(spdv->GetY()); hvz->Fill(spdv->GetZ()); } Double_t itss[4]; for (Int_t iTrack = 0; iTrack < esd->GetNumberOfTracks(); iTrack++) { AliESDtrack* track = esd->GetTrack(iTrack); Int_t nITSclus=track->GetNcls(0); UChar_t clumap=track->GetITSClusterMap(); Int_t nPointsForPid=0; for(Int_t i=2; i<6; i++){ if(clumap&(1<<i)) ++nPointsForPid; } // track->PropagateTo(4.,5.); htpccl->Fill(track->GetNcls(1)); ULong64_t status=track->GetStatus(); Bool_t tpcin=0; hStatus->Fill(-1.); if(status & AliESDtrack::kTPCin){ tpcin=1; hStatus->Fill(0.); } if(status & AliESDtrack::kTPCout){ hStatus->Fill(1.); } if(status & AliESDtrack::kTPCrefit){ hStatus->Fill(2.); } Bool_t itsin=0; if(status & AliESDtrack::kITSin){ itsin=1; hStatus->Fill(3.); } if(status & AliESDtrack::kITSout){ hStatus->Fill(4.); } if(status & AliESDtrack::kITSrefit){ hStatus->Fill(5.); } if(!tpcin && itsin){ hStatus->Fill(6.); } if(status & AliESDtrack::kITSpureSA){ hStatus->Fill(7.); } if(status & AliESDtrack::kITSrefit){ if((optTracks==kTPCITS) && !(status & AliESDtrack::kTPCin)) continue; if((optTracks==kITSsa) && (status & AliESDtrack::kTPCin)) continue; if((optTracks==kITSsa) && (status & AliESDtrack::kITSpureSA)) continue; if((optTracks==kITSpureSA) && (status & AliESDtrack::kITSpureSA)) continue; track->GetITSdEdxSamples(itss); // printf("Track %d (label %d) in ITS with %d clusters clumap %d pointspid= %d\n",iTrack,track->GetLabel(),nITSclus,clumap,nPointsForPid); //printf(" dedx=%f %f %f %f\n",itss[0],itss[1],itss[2],itss[3]); hitscl->Fill(nITSclus); hdedx3->Fill(itss[0]); hdedx4->Fill(itss[1]); hdedx5->Fill(itss[2]); hdedx6->Fill(itss[3]); hitsmap->Fill(clumap); hclulay->Fill(-1.); for(Int_t iLay=0;iLay<6;iLay++){ if(clumap&1<<iLay) hclulay->Fill(iLay); } hpt->Fill(track->Pt()); hphi->Fill(TMath::ASin(track->GetSnp())); hlam->Fill(TMath::ATan(track->GetTgl())); halpha->Fill(track->GetAlpha()); Int_t iMod,status; Float_t xloc,zloc; for(Int_t iLay=2; iLay<=3; iLay++){ Bool_t ok=track->GetITSModuleIndexInfo(iLay,iMod,status,xloc,zloc); if(ok){ iMod+=240; hAllPMod->Fill(iMod); hAllPXloc->Fill(xloc); hAllPZloc->Fill(zloc); if(status==1){ hGoodPMod->Fill(iMod); hGoodPXloc->Fill(xloc); hGoodPZloc->Fill(zloc); if(track->Pt()>1.) hdEdxVsMod->Fill(iMod,itss[iLay-2]); } else if(status==2){ hBadRegMod->Fill(iMod); hBadRegXloc->Fill(xloc); hBadRegZloc->Fill(zloc); } else if(status==3) hSkippedMod->Fill(iMod); else if(status==4) hOutAccMod->Fill(iMod); else if(status==5){ hMissPMod->Fill(iMod); hMissPXloc->Fill(xloc); hMissPZloc->Fill(zloc); } else if(status==6) hNoRefitMod->Fill(iMod); } } } } } Float_t norm=hclulay->GetBinContent(1); if(norm<1.) norm=1.; hclulay->Scale(1./norm); gStyle->SetLineWidth(2); TCanvas* c1=new TCanvas("c1","Track quantities",900,900); c1->Divide(2,2); c1->cd(1); htpccl->Draw(); htpccl->GetXaxis()->SetTitle("Clusters in TPC "); c1->cd(2); hitscl->Draw(); hitscl->GetXaxis()->SetTitle("Clusters in ITS "); c1->cd(3); hclulay->Draw(); hclulay->GetXaxis()->SetRange(2,7); hclulay->GetXaxis()->SetTitle("# ITS Layer"); hclulay->GetYaxis()->SetTitle("Fraction of tracks with point in Layer x"); c1->cd(4); TCanvas* c2=new TCanvas("c2","dedx per Layer",900,900); c2->Divide(2,2); c2->cd(1); hdedx3->Draw(); hdedx3->GetXaxis()->SetTitle("dE/dx Lay3"); c2->cd(2); hdedx4->Draw(); hdedx4->GetXaxis()->SetTitle("dE/dx Lay4"); c2->cd(3); hdedx5->Draw(); hdedx5->GetXaxis()->SetTitle("dE/dx Lay5"); c2->cd(4); hdedx6->Draw(); hdedx6->GetXaxis()->SetTitle("dE/dx Lay6"); hdEdxVsMod->SetStats(0); TCanvas* cdedx=new TCanvas("cdedx","dedx SDD",1400,600); cdedx->SetLogz(); hdEdxVsMod->Draw("col"); hdEdxVsMod->GetXaxis()->SetTitle("SDD Module Id"); hdEdxVsMod->GetYaxis()->SetTitle("dE/dx (keV/300 #mum)"); hdEdxVsMod->GetYaxis()->SetTitleOffset(1.25); TCanvas* cv=new TCanvas("cv","Vertex",600,900); cv->Divide(1,3); cv->cd(1); hvx->Draw(); hvx->GetXaxis()->SetTitle("Xv (cm)"); cv->cd(2); hvy->Draw(); hvy->GetXaxis()->SetTitle("Yv (cm)"); cv->cd(3); hvz->Draw(); hvz->GetXaxis()->SetTitle("Xv (cm)"); hGoodPMod->SetStats(0); hGoodPMod->SetTitle(""); TCanvas* ceff0=new TCanvas("ceff0","ModuleIndexInfo",1000,600); hGoodPMod->Draw("e"); hGoodPMod->GetXaxis()->SetTitle("SDD Module Id"); hGoodPMod->GetYaxis()->SetTitle("Number of tracks"); hMissPMod->SetLineColor(2); hMissPMod->SetMarkerColor(2); hMissPMod->SetMarkerStyle(22); hMissPMod->SetMarkerSize(0.5); hMissPMod->Draw("psame"); hBadRegMod->SetLineColor(kGreen+1); hBadRegMod->SetMarkerColor(kGreen+1); hBadRegMod->SetMarkerStyle(20); hBadRegMod->SetMarkerSize(0.5); hBadRegMod->Draw("esame"); hSkippedMod->SetLineColor(kYellow); hSkippedMod->Draw("esame"); hOutAccMod->SetLineColor(4); hOutAccMod->Draw("esame"); hNoRefitMod->SetLineColor(6); hNoRefitMod->Draw("esame"); TLatex* t1=new TLatex(0.7,0.85,"Good Point"); t1->SetNDC(); t1->SetTextColor(1); t1->Draw(); TLatex* t2=new TLatex(0.7,0.8,"Missing Point"); t2->SetNDC(); t2->SetTextColor(2); t2->Draw(); TLatex* t3=new TLatex(0.7,0.75,"Bad Region"); t3->SetNDC(); t3->SetTextColor(kGreen+1); t3->Draw(); ceff0->Update(); TH1F* heff=new TH1F("heff","",260,239.5,499.5); for(Int_t imod=0; imod<260;imod++){ Float_t numer=hGoodPMod->GetBinContent(imod+1)+hBadRegMod->GetBinContent(imod+1)+hOutAccMod->GetBinContent(imod+1)+hNoRefitMod->GetBinContent(imod+1); Float_t denom=hAllPMod->GetBinContent(imod+1); Float_t eff=0.; Float_t erreff=0.; if(denom>0){ eff=numer/denom; erreff=TMath::Sqrt(eff*(1-eff)/denom); } heff->SetBinContent(imod+1,eff); heff->SetBinError(imod+1,erreff); } printf("---- Modules with efficiency < 90%% ----\n"); heff->SetStats(0); TCanvas* ceff1=new TCanvas("ceff1","Efficiency",1000,600); heff->Draw(); heff->GetXaxis()->SetTitle("SDD Module Id"); heff->GetYaxis()->SetTitle("Fraction of tracks with point in good region"); for(Int_t ibin=1; ibin<=heff->GetNbinsX(); ibin++){ Float_t e=heff->GetBinContent(ibin); if(e<0.9){ Int_t iMod=(Int_t)heff->GetBinCenter(ibin); Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(iMod,lay,lad,det); printf("Module %d - Layer %d Ladder %2d Det %d - Eff. %.3f\n",iMod,lay,lad,det,heff->GetBinContent(ibin)); } } ceff1->Update(); hGoodPXloc->SetTitle(""); hGoodPZloc->SetTitle(""); hGoodPXloc->SetStats(0); hGoodPZloc->SetStats(0); hGoodPXloc->SetMinimum(0); hGoodPZloc->SetMinimum(0); TCanvas* ceff2=new TCanvas("ceff2","LocalCoord",1000,600); ceff2->Divide(2,1); ceff2->cd(1); hGoodPXloc->Draw("e"); hGoodPXloc->GetXaxis()->SetTitle("Xlocal (cm)"); hGoodPXloc->GetYaxis()->SetTitle("Number of tracks"); hMissPXloc->SetLineColor(2); hMissPXloc->SetMarkerColor(2); hMissPXloc->SetMarkerStyle(22); hMissPXloc->SetMarkerSize(0.5); hMissPXloc->Draw("psame"); hBadRegXloc->SetLineColor(kGreen+1); hBadRegXloc->SetMarkerColor(kGreen+1); hBadRegXloc->SetMarkerStyle(20); hBadRegXloc->SetMarkerSize(0.5); hBadRegXloc->Draw("psame"); t1->Draw(); t2->Draw(); t3->Draw(); ceff2->cd(2); hGoodPZloc->Draw("e"); hGoodPZloc->GetXaxis()->SetTitle("Zlocal (cm)"); hGoodPZloc->GetYaxis()->SetTitle("Number of tracks"); hMissPZloc->SetLineColor(2); hMissPZloc->SetMarkerColor(2); hMissPZloc->SetMarkerStyle(22); hMissPZloc->SetMarkerSize(0.5); hMissPZloc->Draw("psame"); hBadRegZloc->SetLineColor(kGreen+1); hBadRegZloc->SetMarkerColor(kGreen+1); hBadRegZloc->SetMarkerStyle(20); hBadRegZloc->SetMarkerSize(0.5); hBadRegZloc->Draw("psame"); t1->Draw(); t2->Draw(); t3->Draw(); ceff2->Update(); }
void unfoldPt(int mode=0) { // Matched Tracklets TFile *inf = new TFile("match-10TeV-12.root"); TNtuple *nt = (TNtuple*)inf->FindObjectAny("nt"); // Test sample TFile *infTest = new TFile("./TrackletTree-Run123596.root"); TNtuple *ntTest = (TNtuple*)infTest->FindObjectAny("TrackletTree12"); TFile *pdfFile; if (mode==0) pdfFile = new TFile("pdf.root","recreate"); else pdfFile = new TFile("pdf.root"); double nPtBin=15; double minPt=log(0.05); double maxPt=log(10); double nDphiBin=600; double maxDphi=0.4; char* mycut = Form("abs(eta)<2&&log(pt)>%f&&log(pt)<%f",minPt,maxPt); char* mycut1=Form("abs(eta)<2&&log(pt)>%f&&log(pt)<%f&&abs(eta-eta1)<0.01&&abs(deta)<0.01",minPt,maxPt); TH2F *h; TH1F *hdphi = new TH1F("hdphi","",nDphiBin,0,maxDphi); TH1F *hdphi2; TH1F *hpt; TH1F *hptH = new TH1F("hptH","",nPtBin,minPt,maxPt); TH1F *hptUnfold = new TH1F("hptUnfold","",nPtBin,minPt,maxPt); TH1F *hptMC = new TH1F("hptMC","",nPtBin,minPt,maxPt); TH1F *hptTemp = new TH1F("hptTemp","",nPtBin,minPt,maxPt); // Delta phi as a function of matched genparticle transverse momentum TCanvas *c = new TCanvas("c","",600,600); if (mode == 0) { h = new TH2F("h","",nPtBin,minPt,maxPt,nDphiBin,0,maxDphi); hdphi2 = new TH1F("hdphiMC","",nDphiBin,0,maxDphi); hpt = new TH1F("hpt","",nPtBin,minPt,maxPt); h->SetXTitle("ln(P_{T}) GeV/c"); h->SetYTitle("|#Delta#phi|"); nt->Draw("abs(dphi):log(pt)>>h",mycut1,"col"); // used to generate pdf nt->Draw("abs(dphi)>>hdphiMC",mycut,""); nt->Draw("log(pt)>>hpt",mycut,""); h->Write(); hpt->Write(); hdphi2->Write(); } else { h = (TH2F*) pdfFile->FindObjectAny("h"); hdphi2 = (TH1F*) pdfFile->FindObjectAny("hdphiMC"); hpt = (TH1F*) pdfFile->FindObjectAny("hpt"); } // Delta phi fit TCanvas *c2 = new TCanvas("c2","",600,600); c2->SetLogy(); c2->SetLogx(); // dphi for unfolding and MC truth: ntTest->Draw("abs(dphi)>>hdphi","abs(eta1)<2&&abs(deta)<0.1","",200000); ntTest->Draw("log(pt)>>hptH",mycut,"",200000); histFunction2D *myfun = new histFunction2D(h); TF1 *test = new TF1("histFun",myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1); TF1 *test2 = new TF1("histFunMC",myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1); for (int i=0;i<nPtBin+1;i++) { test->SetParameter(i,1); } hdphi2->SetXTitle("|#Delta#phi|"); hdphi2->SetYTitle("Arbitrary Normalization"); hdphi2->Fit("histFunMC","M"); hdphi->SetXTitle("|#Delta#phi|"); hdphi->SetYTitle("Arbitrary Normalization"); hdphi->Fit("histFun","M"); hdphi->SetStats(0); hdphi->Draw(); for (int i=0;i<nPtBin+1;i++) { TF1 *testPlot = new TF1(Form("histFun%d",i),myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1); testPlot->SetParameter(i,test->GetParameter(i)); testPlot->SetLineColor(i+2); testPlot->Draw("same"); } int total=0,totalMC=0; for (int i=0;i<nPtBin;i++){ if (test->GetParameter(i)==0) continue; hptUnfold->SetBinContent(i+1,fabs(test->GetParameter(i))); hptUnfold->SetBinError(i+1,test->GetParError(i)); hptMC->SetBinContent(i+1,fabs(test2->GetParameter(i))); hptMC->SetBinError(i+1,test2->GetParError(i)); total+=fabs(test->GetParameter(i)); totalMC+=fabs(test2->GetParameter(i)); } hptUnfold->SetEntries(total); hptMC->SetEntries(totalMC); TCanvas *c3 = new TCanvas("c3","",600,600); hpt->Sumw2(); hptH->Sumw2(); //hptMC->Sumw2(); double normMC=0; double norm=0; double normTruth=0; hptUnfold->SetMarkerColor(2); hptUnfold->SetMarkerStyle(4); // hptUnfold->Scale(1./hptUnfold->GetEntries()); TH1F *hptCorrected = (TH1F*)hptUnfold->Clone(); hptCorrected->SetName("hptCorrected"); hptMC->Divide(hpt); hptCorrected->Divide(hptMC); for (int i=0;i<nPtBin;i++){ if (hptMC->GetBinContent(i)<=0.001)hptCorrected->SetBinContent(i,0); } hptCorrected->Scale(1./(hptCorrected->GetSum())); hptCorrected->SetMarkerStyle(20); hpt->Scale(1./hpt->GetEntries()); if (hptH->GetEntries())hptH->Scale(1./hptH->GetEntries()); hptTemp->SetXTitle("ln(P_{T}) GeV/c"); hptTemp->SetYTitle("Arbitrary Normalization"); hptTemp->Draw(); hptH->SetXTitle("ln(P_{T}) GeV/c"); hptH->SetYTitle("Arbitrary Normalization"); hptH->Draw("hist"); hptH->SetLineColor(4); hpt->Draw("hist same "); hptCorrected->Draw("same"); TH1F *hptUnfoldRatio = (TH1F*)hptUnfold->Clone(); hptUnfoldRatio->SetName("hptUnfoldRatio"); hptUnfoldRatio->Scale(1./hptUnfoldRatio->GetSum()); //hptUnfoldRatio->Divide(hptH); TH1F *hptCorrectedRatio = (TH1F*)hptCorrected->Clone(); hptCorrectedRatio->SetName("hptCorrectedRatio"); hptCorrectedRatio->SetMarkerColor(2); //hptCorrectedRatio->Divide(hptH); TCanvas *c4 = new TCanvas("c4","",600,600); TLine *l = new TLine(-2.5,1,2.5,1); hptUnfoldRatio->Draw(); hptMC->Draw("same"); hptCorrectedRatio->Draw("same"); l->Draw("same"); }
/*#include <TSystem.h> // interface to OS #include <TStyle.h> // class to handle ROOT plotting styles#include <TFile.h> // file handle class #include <TTree.h> // class to access ntuples #include <TBenchmark.h> // class to track macro running statistics #include <TH1D.h> // histogram class #include <vector> // STL vector class #include <iostream> // standard I/O #include <iomanip> // functions to format standard I/O #include <fstream> // functions for file I/O #include <string> // C++ string class #include <sstream> // class for parsing strings #include <TRandom3.h> #include <TGaxis.h> #include "Math/LorentzVector.h" // 4-vector class #include "../Utils/MyTools.hh" // various helper functions #include "../Utils/CPlot.hh" // helper class for plots #include "../Utils/MitStyleRemix.hh" // style settings for drawing #include "../Utils/WModels.hh" // definitions of PDFs for fitting #include "../Utils/RecoilCorrector.hh" // class to handle recoil corrections for MET */ void W_MET_Ratio() { TCanvas *c = new TCanvas("c","c",800,800); c->Divide(1,2,0,0); c->cd(1)->SetPad(0,0.3,1.0,1.0); c->cd(1)->SetTopMargin(0.1); c->cd(1)->SetBottomMargin(0.01); c->cd(1)->SetLeftMargin(0.15); c->cd(1)->SetRightMargin(0.07); c->cd(1)->SetTickx(1); c->cd(1)->SetTicky(1); c->cd(2)->SetPad(0,0,1.0,0.3); c->cd(2)->SetTopMargin(0.05); c->cd(2)->SetBottomMargin(0.45); c->cd(2)->SetLeftMargin(0.15); c->cd(2)->SetRightMargin(0.07); c->cd(2)->SetTickx(1); c->cd(2)->SetTicky(1); c->cd(2)->SetGridy(); TLegend * lgc = new TLegend(0.59, 0.67, 0.89, 0.89); lgc->SetTextSize(0.03); lgc->SetBorderSize(0); lgc->SetFillColor(0); // TFile *file = new TFile("../ElectronHighPU/Ele_RD_HighPU_A_Analysis.root"); TFile *file = new TFile("./ElectronHighPU_N/Ele_WToENu_S10_Analysis.root"); ///////////////Original Plot//////////////////////// c->cd(1); lgc->AddEntry(h1_W_Neut_pt1,"UnCorrected"); h1_W_Neut_pt1->SetYTitle("Events"); h1_W_Neut_pt1->SetFillColor(kWhite); h1_W_Neut_pt1->SetMarkerColor(kBlack); h1_W_Neut_pt1->SetMarkerStyle(1); h1_W_Neut_pt1->SetLineWidth(2); h1_W_Neut_pt1->Draw(); lgc->AddEntry(h1_W_Neut_pt_Corr,"Corrected"); h1_W_Neut_pt_Corr->SetLineColor(kRed); h1_W_Neut_pt_Corr->SetFillColor(kWhite); h1_W_Neut_pt_Corr->SetMarkerColor(kRed); h1_W_Neut_pt_Corr->SetMarkerStyle(1); h1_W_Neut_pt_Corr->SetLineWidth(2); h1_W_Neut_pt_Corr->Draw("same"); lgc->Draw(); /////////////////////////////////////////////////////// c->cd(2); TH1F * h1_Ori = (TH1F*)file->Get("h1_W_Neut_pt1"); TH1F * h1_Corr = (TH1F*)file->Get("h1_W_Neut_pt_Corr"); int Nbins = h1_Ori->GetNbinsX(); TH1F * ratio = new TH1F("ratio","", Nbins, h1_Ori->GetXaxis()->GetXmin(), h1_Ori->GetXaxis()->GetXmax()); ratio->Divide(h1_Ori, h1_Corr); ratio->SetXTitle("N_vtx"); ratio->SetMaximum(2); ratio->SetMinimum(0); ratio->SetNdivisions(10,"X"); ratio->SetNdivisions(4,"Y"); ratio->SetLabelSize(0.09,"XY"); ratio->SetTitleSize(0.12,"X"); ratio->SetMarkerStyle(20); ratio->SetMarkerSize(0.7); ratio->SetMarkerColor(kBlue); ratio->Draw("P"); // c->SaveAs("W_MET_Ratio_RD.png"); c->SaveAs("W_MET_Ratio_MC.png"); }
void ootpu_fit(TString files, TString comments="") { TChain* chain = new TChain("reduced_tree"); chain->Add(files); TH1::SetDefaultSumw2(); TH1F* hrelIso = new TH1F("hrelIso","", 30, 0, 0.5); TH1F* hOOTPU = new TH1F("hOOTPU","", 75, 0, 75); TH1F* hOOTPUvsIso = new TH1F("hOOTPUvsIso",";Out-of-time ints.;Isolation cut efficiency", 15, 0, 75); hrelIso->StatOverflows(true); int n1(0), n2(0); if (files.Contains("20bx25")) { n1=15; n2=75; } else if (files.Contains("S14")) { n1=0; n2=120; } else { // default: 8 TeV scenario n1=0; n2=70; } TString mu("num_gen_muons==1&&muon_reco_match>=0"); int low = 15; for (int bin(1); bin<hOOTPUvsIso->GetNbinsX()+1; bin++) { if (bin<4) continue; if (bin>4) low=low+5; if (low>hOOTPUvsIso->GetBinLowEdge(hOOTPUvsIso->GetNbinsX())) break; TString cuts = Form("(%s)&&(oot_pu>=%d&&oot_pu<%d)",mu.Data(),low,low+4); cout << "Cuts: " << cuts.Data() << endl; chain->Project(hrelIso->GetName(), "muon_relIso", cuts); chain->Project(hOOTPU->GetName(), "oot_pu", cuts); hrelIso->Scale(1/hrelIso->GetEntries()); Double_t left(0.), lerror(0.), right(0.), rerror(0.); left = hrelIso->IntegralAndError(1,12,lerror); right = hrelIso->IntegralAndError(13,31,rerror); float rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right))); printf("bin1: %3.2f +/- %3.3f\n", left/(left+right),rat_error); hOOTPUvsIso->SetBinContent(bin,left/(left+right)); hOOTPUvsIso->SetBinError(bin,rat_error); } hOOTPUvsIso->SetLineColor(1); hOOTPUvsIso->SetMarkerColor(1); hOOTPUvsIso->SetMarkerStyle(20); TCanvas* c1 = new TCanvas(); hOOTPUvsIso->Draw("e1"); // do a linear fit TF1 *flin = new TF1("flin", "1 ++ x", 15, 75); hOOTPUvsIso->Fit(flin); flin=hOOTPUvsIso->GetFunction("flin"); flin->SetLineColor(kBlue); flin->SetLineWidth(2); TString plotTitle ="OOTPU_fit"+comments+".pdf"; c1->Print(plotTitle); // cout << "Rejection rates" << endl; // Double_t left(0.), lerror(0.), right(0.), rerror(0.); // left = hA->IntegralAndError(1,12,lerror); // right = hA->IntegralAndError(13,31,rerror); // float rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right))); // printf("bin1: %3.2f +/- %3.3f\n", left/(left+right),rat_error); // left = hB->IntegralAndError(1,12,lerror); // right = hB->IntegralAndError(13,31,rerror); // rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right))); // printf("bin2: %3.2f +/- %3.3f\n", left/(left+right),rat_error); // left = hC->IntegralAndError(1,12,lerror); // right = hC->IntegralAndError(13,31,rerror); // rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right))); // printf("bin3: %3.2f +/- %3.3f\n", left/(left+right),rat_error); // left = hD->IntegralAndError(1,12,lerror); // right = hD->IntegralAndError(13,31,rerror); // rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right))); // printf("bin4: %3.2f +/- %3.3f\n", left/(left+right),rat_error); }