void Draw(const int &rebin=1) { Color_t _sampleColor[nSamples]; //_sampleColor[iHWW ] = kRed+1; //_sampleColor[iWW ] = kAzure-9; //_sampleColor[iZJets] = kGreen+2; //_sampleColor[iZTau] = kGreen+2; //_sampleColor[iTop ] = kYellow; //_sampleColor[iWZ ] = kAzure-2; //_sampleColor[iWJets] = kGray+1; //_sampleColor[iWJets] = kViolet-9; //_sampleColor[iWJets] = kCyan; _sampleColor[itH ] = kRed; _sampleColor[iWZ ] = kAzure-9; _sampleColor[iZZ ] = kAzure-5; _sampleColor[iWW ] = kAzure-1; _sampleColor[itt ] = kGray; _sampleColor[ittw ] = kOrange+7; _sampleColor[ittz ] = kOrange+1; _sampleColor[iwww ] = kSpring+9; _sampleColor[iwwz ] = kSpring+3; _sampleColor[iwzz ] = kSpring-7; _sampleColor[idyl ] = kViolet-1; _sampleColor[idy ] = kViolet-1; //setUpStyle(); if(!gPad) new TCanvas(); THStack* hstack = new THStack(); for (int i=0; i<nSamples; i++) { // in case the user doesn't set it if( !_hist[i] ) continue; _hist[i]->Rebin(rebin); _hist[i]->SetLineColor(_sampleColor[i]); // signal gets overlaid if (i == itH) continue; _hist[i]->SetFillColor(_sampleColor[i]); _hist[i]->SetFillStyle(1001); hstack->Add(_hist[i]); } if(_hist[itH]) _hist[itH]->SetLineWidth(3); if(_data) _data->Rebin(rebin); if(_data) _data->SetLineColor (kBlack); if(_data) _data->SetMarkerStyle(kFullCircle); if(_nostack) { for(int ihist=0;ihist<(int)_hist.size();ihist++) { _hist[ihist]->SetFillStyle(0); _hist[ihist]->SetLineWidth(2); } hstack->Draw("hist,nostack"); if(_hist[itH]) _hist[itH]->Draw("hist,same"); if(_data) _data->Draw("ep,same"); } else { hstack->Draw("hist"); if(_hist[itH]) _hist[itH]->Draw("hist,same"); if(_data) _data->Draw("ep,same"); } //hstack->SetTitle("CMS preliminary"); Float_t theMax = hstack->GetMaximum(); Float_t theMin = hstack->GetMinimum(); theMax = 1.0; //Float_t theMin = hstack->GetMinimum(); if (_hist[itH]) { if (_hist[itH]->GetMaximum() > theMax) theMax = _hist[itH]->GetMaximum(); if (_hist[itH]->GetMinimum() < theMin) theMin = _hist[itH]->GetMinimum(); } if (_data) { Float_t dataMax = GetMaximumIncludingErrors(_data); if (dataMax > theMax) theMax = dataMax; } if (gPad->GetLogy()) { hstack->SetMaximum(500 * theMax); hstack->SetMinimum(0.05); } else { hstack->SetMaximum(1.55 * theMax); } if(_breakdown) { THStackAxisFonts(hstack, "y", "entries"); hstack->GetHistogram()->LabelsOption("v"); } else { THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data())); if(_units.Sizeof() == 1) { THStackAxisFonts(hstack, "x", _xLabel.Data()); THStackAxisFonts(hstack, "y", "entries"); } else { THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data())); THStackAxisFonts(hstack, "y", TString::Format("entries / %.0f %s", _hist[iWZ]->GetBinWidth(0),_units.Data())); } } // total mess to get it nice, should be redone size_t j=0; TString higgsLabel = " tH x 100"; //if(_mass != 0) higgsLabel.Form(" m_{H}=%d",_mass); if(_data ) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _data, " data", "lp"); j++; } if(_hist[itH ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itH ], higgsLabel, "l" ); j++; } if(_hist[iWZ ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWZ ], " WZ", "f" ); j++; } if(_hist[iZZ ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iZZ ], " ZZ", "f" ); j++; } if(_hist[iWW ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWW ], " WW", "f" ); j++; } if(_hist[itt ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itt ], " tt", "f" ); j++; } if(_hist[ittw ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittw ], " ttW", "f" ); j++; } if(_hist[ittz ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittz ], " ttZ", "f" ); j++; } if(_hist[iwww ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwww ], " WWW", "f" ); j++; } if(_hist[iwwz ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwwz ], " WWZ", "f" ); j++; } if(_hist[iwzz ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwzz ], " WZZ", "f" ); j++; } if(_hist[idy ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[idy ], " Drell-Yan","f" ); j++; } //TLatex* luminosity = new TLatex(0.9, 0.815, TString::Format("L = %.1f fb^{-1}",_lumi)); TLatex* luminosity = new TLatex(0.9, 0.95, TString::Format("CMS Preliminary \\sqrt{s} = 8 TeV, L = %.1f fb^{-1}",_lumi)); luminosity->SetNDC(); luminosity->SetTextAlign(32); luminosity->SetTextFont(42); luminosity->SetTextSize(_tsize); luminosity->Draw("same"); // if(_extraLabel) _extraLabel->Draw("same"); // return hstack->GetHistogram(); }
void makePlots_csvSF_13TeV( TString inputFileName = "infile.root", bool isHF = true, bool isCSV = true, TString dirPostFix = "", bool compareIterations = false ) { compareIterations = true; TString taggerName = "CSVv2"; if(!isCSV) taggerName = "cMVAv2"; TH1::SetDefaultSumw2(); TFile *histFile = TFile::Open(inputFileName); if( compareIterations ) dirPostFix = dirPostFix + "Comparison"; TString dirprefix = taggerName +"_SFPlots_2016_7_8_13TeV" + dirPostFix + "/"; struct stat st; if( stat(dirprefix.Data(),&st) != 0 ) mkdir(dirprefix.Data(),0777); // single jet specific plots int nPt = 5;//6; int nEta = 1; TString flavor = "HF"; if ( !isHF ){ nPt = 4; nEta = 3; flavor = "LF"; } ////// TH1D* h_Data_jet_csv[nPt][nEta]; TH1D* h_MC_b_jet_csv[nPt][nEta]; TH1D* h_MC_nonb_jet_csv[nPt][nEta]; ///// // int nCSVBins = 18; //Number of bins // // double xBins_hf[19] = {-0.04, 0.0, 0.122, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.7228, 0.7666, 0.8104, 0.8542, 0.898, 0.9184, 0.9388, 0.9592, 0.9796, 1.01}; // double xBins_hf[19] = {-0.04, 0.0, 0.3025, 0.605, 0.662, 0.719, 0.776, 0.833, 0.890, 0.906, 0.922, 0.938, 0.954, 0.970, 0.976, 0.982, 0.988, 0.994, 1.01}; int nCSVBins = 22; //Number of bins // double xBins_hf[19] = {-10.0, 0.0, 0.122, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.7228, 0.7666, 0.8104, 0.8542, 0.898, 0.9184, 0.9388, 0.9592, 0.9796, 1.01}; double xBins_hf[23] = {-0.04, 0.0, 0.101, 0.202, 0.303, 0.404, 0.505, 0.605, 0.662, 0.719, 0.776, 0.833, 0.890, 0.906, 0.922, 0.938, 0.954, 0.970, 0.976, 0.982, 0.988, 0.994, 1.01}; double xBins_hf_cMVA[23] = {-1.01, -0.9525, -0.905, -0.8575, -0.81, -0.7625, -0.715, -0.565, -0.415, -0.265, -0.115, 0.035, 0.185, 0.323, 0.461, 0.599, 0.737, 0.875, 0.902, 0.929, 0.956, 0.983, 1.01}; if(!isHF) nCSVBins = 21; // double xBins_lf[22] = {-0.04, 0.0, 0.04, 0.08, 0.12, 0.16, 0.2, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.752, 0.825, 0.898, 0.915, 0.932, 0.949, 0.966, 0.983, 1.01}; double xBins_lf[22] = {-0.04, 0.0, 0.101, 0.202, 0.303, 0.404, 0.505, 0.605, 0.662, 0.719, 0.776, 0.833, 0.890, 0.917, 0.944, 0.970, 0.975, 0.980, 0.985, 0.990, 0.995, 1.01}; double xBins_lf_cMVA[22] = {-1.01, -0.9525, -0.905, -0.8575, -0.81, -0.7625, -0.715, -0.565, -0.415, -0.265, -0.115, 0.035, 0.185, 0.415, 0.645, 0.875, 0.8975, 0.92, 0.9425, 0.965, 0.9875, 1.01}; //TCanvas* c1 = new TCanvas("c1","c1",600,500); TCanvas* c1 = new TCanvas("c1","c1"); c1->SetTopMargin(0.08); c1->SetRightMargin(0.08); // gPad->SetTickx(1); // gPad->SetTicky(1); TString flavor_file = flavor; flavor_file.ToLower(); /// TString lumiinfo = "2.6 fb^{-1} (13 TeV, 25ns)"; TLatex LumiInfoLatex(0.65, 0.93, lumiinfo); LumiInfoLatex.SetNDC(); LumiInfoLatex.SetTextFont(42); LumiInfoLatex.SetTextSize(0.04); //TString cmsinfo = "CMS Preliminary"; TString cmsinfo = "CMS"; // TLatex CMSInfoLatex(0.155, 0.93, cmsinfo); TLatex CMSInfoLatex(0.155, 0.85, cmsinfo); CMSInfoLatex.SetNDC(); CMSInfoLatex.SetTextFont(42); CMSInfoLatex.SetTextFont(61); CMSInfoLatex.SetTextSize(0.055); //SBOUTLE std::string publishinfo = "Preliminary"; //DPUIGH // TLatex PublishInfoLatex(0.25, 0.93, publishinfo.c_str()); //SBOUTLE TLatex PublishInfoLatex(0.155, 0.80, publishinfo.c_str()); //SBOUTLE PublishInfoLatex.SetNDC(); PublishInfoLatex.SetTextFont(52); PublishInfoLatex.SetTextSize(0.045); //SBOUTLE /// std::vector<TString> label_ptbin; std::vector<TString> label_etabin; TString plotName; int iHist = -1; int minPt = 1; for ( int iPt=minPt; iPt<nPt; iPt++){ for ( int iEta=0; iEta<nEta; iEta++){ iHist++; if(isHF){ if( iPt==0 ) label_ptbin.push_back("20 < p_{T} < 30 GeV"); else if( iPt==1 ) label_ptbin.push_back("30 < p_{T} < 40 GeV"); else if( iPt==2 ) label_ptbin.push_back("40 < p_{T} < 60 GeV"); else if( iPt==3 ) label_ptbin.push_back("60 < p_{T} < 100 GeV"); else if( iPt==4 ) label_ptbin.push_back("p_{T} > 100 GeV"); label_etabin.push_back("|#eta| < 2.4"); } else{ if( iPt==0 ) label_ptbin.push_back("20 < p_{T} < 30 GeV"); else if( iPt==1 ) label_ptbin.push_back("30 < p_{T} < 40 GeV"); else if( iPt==2 ) label_ptbin.push_back("40 < p_{T} < 60 GeV"); else if( iPt==3 ) label_ptbin.push_back("p_{T} > 60 GeV"); if( iEta==0 ) label_etabin.push_back("|#eta| < 0.8"); else if( iEta==1 ) label_etabin.push_back("0.8 < |#eta| < 1.6"); else if( iEta==2 ) label_etabin.push_back("1.6 < |#eta| < 2.4"); } if(!compareIterations){ TString h_Data_Name = Form("h_csv_Data_Pt%i_Eta%i",iPt,iEta); TString h_b_Name = Form("h_csv_MC_bjets_Pt%i_Eta%i",iPt,iEta); TString h_nonb_Name = Form("h_csv_MC_nonbjets_Pt%i_Eta%i",iPt,iEta); h_Data_jet_csv[iPt][iEta] = (TH1D*)histFile->Get(h_Data_Name.Data()); h_MC_b_jet_csv[iPt][iEta] = (TH1D*)histFile->Get(h_b_Name.Data()); h_MC_nonb_jet_csv[iPt][iEta] = (TH1D*)histFile->Get(h_nonb_Name.Data()); // rebin TH1D* h_csv_data = NULL; TH1D* h_csv_mc_b = NULL; TH1D* h_csv_mc_nonb = NULL; h_csv_data = (TH1D*)h_Data_jet_csv[iPt][iEta]; h_csv_mc_b = (TH1D*)h_MC_b_jet_csv[iPt][iEta]; h_csv_mc_nonb = (TH1D*)h_MC_nonb_jet_csv[iPt][iEta]; // if( isHF ){ // h_csv_data = (TH1D*)h_Data_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_hf ); // h_csv_mc_b = (TH1D*)h_MC_b_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_hf ); // h_csv_mc_nonb = (TH1D*)h_MC_nonb_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_hf ); // } // else{ // h_csv_data = (TH1D*)h_Data_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_lf ); // h_csv_mc_b = (TH1D*)h_MC_b_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_lf ); // h_csv_mc_nonb = (TH1D*)h_MC_nonb_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_lf ); // } // //// first and last bin; underflow/overflow // h_csv_data->SetBinContent(1,h_Data_jet_csv[iPt][iEta]->GetBinContent(1)); // h_csv_data->SetBinError(1,h_Data_jet_csv[iPt][iEta]->GetBinError(1)); // h_csv_mc_b->SetBinContent(1,h_MC_b_jet_csv[iPt][iEta]->GetBinContent(1)); // h_csv_mc_b->SetBinError(1,h_MC_b_jet_csv[iPt][iEta]->GetBinError(1)); // h_csv_mc_nonb->SetBinContent(1,h_MC_nonb_jet_csv[iPt][iEta]->GetBinContent(1)); // h_csv_mc_nonb->SetBinError(1,h_MC_nonb_jet_csv[iPt][iEta]->GetBinError(1)); // h_csv_data->SetBinContent(nCSVBins,h_Data_jet_csv[iPt][iEta]->GetBinContent(nCSVBins) + h_Data_jet_csv[iPt][iEta]->GetBinContent(nCSVBins+1)); // h_csv_data->SetBinError(nCSVBins,sqrt(pow(h_Data_jet_csv[iPt][iEta]->GetBinError(nCSVBins),2) + pow(h_Data_jet_csv[iPt][iEta]->GetBinError(nCSVBins+1),2))); // h_csv_mc_b->SetBinContent(nCSVBins,h_MC_b_jet_csv[iPt][iEta]->GetBinContent(nCSVBins) + h_MC_b_jet_csv[iPt][iEta]->GetBinContent(nCSVBins+1)); // h_csv_mc_b->SetBinError(nCSVBins,sqrt(pow(h_MC_b_jet_csv[iPt][iEta]->GetBinError(nCSVBins),2) + pow(h_MC_b_jet_csv[iPt][iEta]->GetBinError(nCSVBins+1),2))); // h_csv_mc_nonb->SetBinContent(nCSVBins,h_MC_nonb_jet_csv[iPt][iEta]->GetBinContent(nCSVBins) + h_MC_nonb_jet_csv[iPt][iEta]->GetBinContent(nCSVBins+1)); // h_csv_mc_nonb->SetBinError(nCSVBins,sqrt(pow(h_MC_nonb_jet_csv[iPt][iEta]->GetBinError(nCSVBins),2) + pow(h_MC_nonb_jet_csv[iPt][iEta]->GetBinError(nCSVBins+1),2))); // //// normalize MC to data // double norm_mc_b = h_csv_mc_b->Integral(); // double norm_mc_nonb = h_csv_mc_nonb->Integral(); // h_csv_mc_b->Scale(h_csv_data->Integral() / (norm_mc_b + norm_mc_nonb)); // h_csv_mc_nonb->Scale(h_csv_data->Integral() / (norm_mc_b + norm_mc_nonb)); //// h_csv_data->SetStats(0); //h_csv_data->GetXaxis()->SetRangeUser(0.0001, 1.001); h_csv_data->SetTitle(";"+taggerName+" Discriminator;Jets / bin"); // h_csv_data->SetTitle(";"+taggerName); h_csv_data->SetMarkerStyle(20); h_csv_mc_b->SetFillColor(kRed); h_csv_mc_nonb->SetFillColor(kBlue); // h_csv_mc_nonb->SetFillColor(kGreen+1); h_csv_mc_b->SetLineColor(kRed); h_csv_mc_nonb->SetLineColor(kBlue); // h_csv_mc_nonb->SetLineColor(kGreen+1); h_csv_data->SetLineWidth(2); h_csv_mc_b->SetLineWidth(2); h_csv_mc_nonb->SetLineWidth(2); /// TString ptselectioninfo = label_ptbin[iHist]; TLatex PTSELECTIONInfoLatex(0.57, 0.85, ptselectioninfo); PTSELECTIONInfoLatex.SetNDC(); PTSELECTIONInfoLatex.SetTextFont(42); PTSELECTIONInfoLatex.SetTextSize(0.04); TString etaselectioninfo = label_etabin[iHist]; TLatex ETASELECTIONInfoLatex(0.57, 0.8, etaselectioninfo); ETASELECTIONInfoLatex.SetNDC(); ETASELECTIONInfoLatex.SetTextFont(42); ETASELECTIONInfoLatex.SetTextSize(0.04); /// // TLegend *legend = new TLegend(0.14,0.85,0.9,0.9); TLegend *legend = new TLegend(0.57,0.57,0.87,0.77); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); legend->SetShadowColor(kWhite); legend->SetTextFont(42); legend->SetTextSize(0.05); legend->SetNColumns(1); legend->AddEntry(h_csv_data," Data","pe"); if( isHF ){ legend->AddEntry(h_csv_mc_b," b","f"); legend->AddEntry(h_csv_mc_nonb," udsg + c","f"); } else{ legend->AddEntry(h_csv_mc_b," b + c","f"); legend->AddEntry(h_csv_mc_nonb," udsg","f"); } TH1D* h_diff = (TH1D*) h_csv_data->Clone( Form("csv_diff_Pt%i_Eta%i",iPt,iEta) ); THStack *hs = new THStack("hs",""); if( isHF ){ hs->Add(h_csv_mc_b); hs->Add(h_csv_mc_nonb); h_diff->Add(h_csv_mc_nonb,-1); } else{ hs->Add(h_csv_mc_nonb); hs->Add(h_csv_mc_b); h_diff->Add(h_csv_mc_b,-1); } TH1D* h_ratio = (TH1D*) h_diff->Clone( Form("csv_ratio_Pt%i_Eta%i",iPt,iEta) ); if( isHF ) h_ratio->Divide( h_csv_mc_b ); else h_ratio->Divide( h_csv_mc_nonb ); TString title = Form("%s SF Pt%i Eta%i",flavor.Data(),iPt,iEta); TLatex BinInfoLatex(0.6, 0.81, title.Data());//(0.6, 0.86, title.Data()); BinInfoLatex.SetNDC(); BinInfoLatex.SetTextFont(42); BinInfoLatex.SetTextSize(0.04); h_csv_data->GetYaxis()->SetTitleOffset(1.2); // h_csv_data->GetXaxis()->SetRangeUser(-0.041,0.9489); h_csv_data->SetMaximum(1.3*TMath::Max(h_csv_data->GetMaximum(), hs->GetMaximum())); h_csv_data->Draw("pe1"); hs->Draw("histsame"); h_csv_data->Draw("pe1same"); legend->Draw(); // BinInfoLatex.Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); ETASELECTIONInfoLatex.Draw(); PTSELECTIONInfoLatex.Draw(); c1->RedrawAxis(); plotName = dirprefix + Form("%s_%s_SF_Pt%i_Eta%i_astack",taggerName.Data(),flavor.Data(),iPt,iEta) + ".pdf"; c1->Print(plotName.Data()); // TLegend *legend_diff = new TLegend(0.14,0.85,0.9,0.9);//new TLegend(0.14,0.93,0.9,0.98); TLegend *legend_diff = new TLegend(0.57,0.57,0.87,0.77); legend_diff->SetFillColor(kWhite); legend_diff->SetLineColor(kWhite); legend_diff->SetShadowColor(kWhite); legend_diff->SetTextFont(42); legend_diff->SetTextSize(0.05); legend_diff->SetNColumns(1); if( isHF ){ legend_diff->AddEntry(h_diff,"(Data - c, udsg)","pe"); legend_diff->AddEntry(h_csv_mc_b,"b","l"); h_diff->SetMaximum(1.3*TMath::Max(h_diff->GetMaximum(), h_csv_mc_b->GetMaximum())); } else{ legend_diff->AddEntry(h_diff,"(Data - b, c)","pe"); legend_diff->AddEntry(h_csv_mc_nonb,"udsg","l"); h_diff->SetMaximum(1.3*TMath::Max(h_diff->GetMaximum(), h_csv_mc_nonb->GetMaximum())); } h_diff->GetYaxis()->SetTitleOffset(1.2); // h_diff->GetXaxis()->SetRangeUser(-0.041,0.9489); h_diff->Draw("pe1"); if( isHF ) h_csv_mc_b->Draw("pe1same"); else h_csv_mc_nonb->Draw("pe1same"); h_diff->Draw("pe1same"); legend_diff->Draw(); // BinInfoLatex.Draw(); c1->RedrawAxis(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); ETASELECTIONInfoLatex.Draw(); PTSELECTIONInfoLatex.Draw(); plotName = dirprefix + Form("%s_%s_SF_Pt%i_Eta%i_bdiff",taggerName.Data(),flavor.Data(),iPt,iEta) + ".pdf"; c1->Print(plotName.Data()); h_ratio->GetYaxis()->SetRangeUser(0.,2.); h_ratio->SetTitle(";"+taggerName+" Discriminator;Data/MC SF"); h_ratio->Draw("pe1"); // BinInfoLatex.Draw(); c1->RedrawAxis(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); ETASELECTIONInfoLatex.Draw(); PTSELECTIONInfoLatex.Draw(); plotName = dirprefix + Form("%s_%s_SF_Pt%i_Eta%i_cratio",taggerName.Data(),flavor.Data(),iPt,iEta) + ".png"; c1->Print(plotName.Data()); } if( compareIterations ){ TFile *fitFile_iter0 = TFile::Open("../data/csvSFs/csv_rwt_fit_" + flavor_file + "_v2.root"); TFile *fitFile_iter1 = TFile::Open("../data/csv_rwt_fit_" + flavor_file + "_v2.root"); TFile *fitFile_iter2 = TFile::Open("../data/csvSFs/csv_rwt_fit_" + flavor_file + "_v2.root"); TString h_iter_Data_Name = Form("h_csv_Data_Pt%i_Eta%i",iPt,iEta); TString h_iter_b_Name = Form("h_csv_MC_bjets_Pt%i_Eta%i",iPt,iEta); TString h_iter_nonb_Name = Form("h_csv_MC_nonbjets_Pt%i_Eta%i",iPt,iEta); TString h_iter_csv_ratio_Name = Form("temp_csv_ratio_Pt%i_Eta%i",iPt,iEta); TH1D* h_iter_Data_jet_csv_iter0 = (TH1D*)fitFile_iter0->Get(h_iter_Data_Name.Data())->Clone(h_iter_Data_Name+"v0"); TH1D* h_iter_MC_b_jet_csv_iter0 = (TH1D*)fitFile_iter0->Get(h_iter_b_Name.Data())->Clone(h_iter_b_Name+"v0"); TH1D* h_iter_MC_nonb_jet_csv_iter0 = (TH1D*)fitFile_iter0->Get(h_iter_nonb_Name.Data())->Clone(h_iter_nonb_Name+"v0"); TH1D* h_iter_Data_jet_csv_iter1 = (TH1D*)fitFile_iter1->Get(h_iter_Data_Name.Data())->Clone(h_iter_Data_Name+"v1"); TH1D* h_iter_MC_b_jet_csv_iter1 = (TH1D*)fitFile_iter1->Get(h_iter_b_Name.Data())->Clone(h_iter_b_Name+"v1"); TH1D* h_iter_MC_nonb_jet_csv_iter1 = (TH1D*)fitFile_iter1->Get(h_iter_nonb_Name.Data())->Clone(h_iter_nonb_Name+"v1"); TH1D* h_iter_Data_jet_csv_iter2 = (TH1D*)fitFile_iter2->Get(h_iter_Data_Name.Data())->Clone(h_iter_Data_Name+"v2"); TH1D* h_iter_MC_b_jet_csv_iter2 = (TH1D*)fitFile_iter2->Get(h_iter_b_Name.Data())->Clone(h_iter_b_Name+"v2"); TH1D* h_iter_MC_nonb_jet_csv_iter2 = (TH1D*)fitFile_iter2->Get(h_iter_nonb_Name.Data())->Clone(h_iter_nonb_Name+"v2"); TH1D* h_iter0 = (TH1D*)h_iter_Data_jet_csv_iter0->Clone(h_iter_csv_ratio_Name+"v0"); TH1D* h_iter1 = (TH1D*)h_iter_Data_jet_csv_iter1->Clone(h_iter_csv_ratio_Name+"v1"); TH1D* h_iter2 = (TH1D*)h_iter_Data_jet_csv_iter2->Clone(h_iter_csv_ratio_Name+"v2"); if( isHF ){ h_iter0->Add(h_iter_MC_nonb_jet_csv_iter0, -1); h_iter0->Divide(h_iter_MC_b_jet_csv_iter0); h_iter1->Add(h_iter_MC_nonb_jet_csv_iter1, -1); h_iter1->Divide(h_iter_MC_b_jet_csv_iter1); h_iter2->Add(h_iter_MC_nonb_jet_csv_iter2, -1); h_iter2->Divide(h_iter_MC_b_jet_csv_iter2); } else { h_iter0->Add(h_iter_MC_b_jet_csv_iter0, -1); h_iter0->Divide(h_iter_MC_nonb_jet_csv_iter0); h_iter1->Add(h_iter_MC_b_jet_csv_iter1, -1); h_iter1->Divide(h_iter_MC_nonb_jet_csv_iter1); h_iter2->Add(h_iter_MC_b_jet_csv_iter2, -1); h_iter2->Divide(h_iter_MC_nonb_jet_csv_iter2); } TString iter_fit_histo_name = Form("csv_ratio_Pt%d_Eta%d_final",iPt,iEta); //TString iter_histo_name = Form("h_csv_ratio_%d",iHist); TH1D* h_fit_iter0 = (TH1D*)fitFile_iter0->Get(iter_fit_histo_name)->Clone(iter_fit_histo_name+"v0"); TH1D* h_fit_iter1 = (TH1D*)fitFile_iter1->Get(iter_fit_histo_name)->Clone(iter_fit_histo_name+"v1"); TH1D* h_fit_iter2 = (TH1D*)fitFile_iter2->Get(iter_fit_histo_name)->Clone(iter_fit_histo_name+"v2"); h_fit_iter0->SetLineColor(kRed); h_fit_iter1->SetLineColor(kGreen+1); h_fit_iter2->SetLineColor(kBlue); h_fit_iter0->SetLineWidth(2); h_fit_iter1->SetLineWidth(2); h_fit_iter2->SetLineWidth(2); h_iter0->SetLineColor(kRed); h_iter1->SetLineColor(kGreen+1); h_iter2->SetLineColor(kBlue); h_iter0->SetLineWidth(2); h_iter1->SetLineWidth(2); h_iter2->SetLineWidth(2); h_fit_iter0->SetStats(0); h_fit_iter0->GetYaxis()->SetRangeUser(0.,2.); h_fit_iter0->GetXaxis()->SetRangeUser(-0.04,1.01); /// change HF range // h_fit_iter0->GetXaxis()->SetRangeUser(0.890,1.01); /// change HF range h_fit_iter0->SetTitle(";"+taggerName+";Data/MC SF"); h_fit_iter0->Draw("hist"); h_iter0->Draw("pe1same"); h_fit_iter1->Draw("histsame"); h_iter1->Draw("pe1same"); // h_fit_iter2->Draw("histsame"); // h_iter2->Draw("pe1same"); c1->RedrawAxis(); ///------- TString title = Form("%s SF Pt%i Eta%i",flavor.Data(),iPt,iEta); TLatex BinInfoLatex(0.6, 0.86, title.Data()); BinInfoLatex.SetNDC(); BinInfoLatex.SetTextFont(42); BinInfoLatex.SetTextSize(0.04); ///------- TLegend *legend_iter = new TLegend(0.14,0.93,0.9,0.98); legend_iter->SetFillColor(kWhite); legend_iter->SetLineColor(kWhite); legend_iter->SetShadowColor(kWhite); legend_iter->SetTextFont(42); legend_iter->SetTextSize(0.05); legend_iter->SetNColumns(3); legend_iter->AddEntry(h_iter0,"jetPt20","f"); legend_iter->AddEntry(h_iter1,"jetPt30","f"); // legend_iter->AddEntry(h_iter2,"mumu","f"); // legend_iter->AddEntry(h_iter0,"Iter0","f"); // legend_iter->AddEntry(h_iter1,"Iter1","f"); // legend_iter->AddEntry(h_iter2,"Iter2","f"); legend_iter->Draw(); BinInfoLatex.Draw(); c1->RedrawAxis(); plotName = dirprefix + Form("%s_%s_SF_Pt%i_Eta%i_diters",taggerName.Data(),flavor.Data(),iPt,iEta) + ".png"; c1->Print(plotName.Data()); } } } std::cout << "Done." << std::endl; }
int shape() { vector<variable> vvariable; variable LepPt("LepPt","LepPt",20,0,35,"p_{T} (l) [GeV]"); variable LepEta("LepEta","LepEta",20,-3,3,"#eta (l)"); variable Njet("Njet","Njet",11,-0.5,10.5,"Njet"); variable Jet1Pt("Jet1Pt","Jet1Pt",20,100,500,"p_{T} (Jet1) [GeV]"); variable Jet1Eta("Jet1Eta","Jet1Eta",20,-3,3,"Eta (Jet1)"); variable Met("Met","Met",20,300,600,"Met [GeV]",1); variable CosDPhi("CosDeltaPhi","CosDeltaPhi",20,-1.2,1.2,"Cos(#Delta #Phi)"); variable DrJet1Lep("DrJet1Lep","DrJet1Lep",10,0,6,"Dr Jet1 Lep"); variable DrJet2Lep("DrJet2Lep","DrJet2Lep",10,0,6,"Dr Jet2 Lep"); variable Jet2Pt("Jet2Pt","Jet2Pt",20,0,400,"p_{T} (Jet2) [GeV]",1); variable mt("mt","mt",15,0,150,"mt [GeV]"); variable HT20("HT20","HT20",20,0,1400,"HT20 [GeV]"); variable HT30("HT30","HT30",20,0,1400,"HT30 [GeV]"); variable Q80("Q80","Q80",20,-2,1,"Q80 [GeV]"); variable JetLepMass("JetLepMass","JetLepMass",20,0,250,"M_{Jet+Lep}"); variable JetHBPt("JetHBpt","JetHBpt",20,0,200,"p_{T} (JetHB)"); // vvariable.push_back(LepPt); // vvariable.push_back(LepEta); // vvariable.push_back(Njet); // vvariable.push_back(Jet1Pt); // vvariable.push_back(Jet2Pt); // vvariable.push_back(Jet1Eta); vvariable.push_back(Met); vvariable.push_back(CosDPhi); // vvariable.push_back(DrJet1Lep); // vvariable.push_back(DrJet2Lep); vvariable.push_back(mt); // vvariable.push_back(HT20); vvariable.push_back(Q80); // vvariable.push_back(HT30); // vvariable.push_back(JetLepMass); // vvariable.push_back(JetHBPt); // Open input file(s) string basedirectory = "/lstore/cms/cbeiraod/Stop4Body/LepFix/"; TFile* ttbarFile = new TFile((basedirectory + "TTJets_LO_bdt.root").c_str(), "READ"); TFile* stopFile = new TFile((basedirectory + "T2DegStop_300_270_bdt.root").c_str(), "READ"); TChain* wjetsTree = new TChain("bdttree"); //creates a chain to process a Tree called "bdttree" wjetsTree->Add((basedirectory + "Wjets_100to200_bdt.root").c_str()); wjetsTree->Add((basedirectory + "Wjets_200to400_bdt.root").c_str()); wjetsTree->Add((basedirectory + "Wjets_400to600_bdt.root").c_str()); wjetsTree->Add((basedirectory + "Wjets_600toInf_bdt.root").c_str()); // Get ttree(s) from input file(s) TTree* ttbarTree = static_cast<TTree*>(ttbarFile->Get("bdttree")); TTree* stopTree = static_cast<TTree*>(stopFile->Get("bdttree")); // Create canvas TCanvas * c1 = new TCanvas("Stop","Stop", 800, 600); if(vvariable.size()!=1) { if(vvariable.size()==2) c1->Divide(2,1); else { if(vvariable.size()%2==0) c1->Divide(vvariable.size()/2,2); else c1->Divide((vvariable.size()+1)/2,2); } } vector<TH1D*> ttbarH; vector<TH1D*> wjetsH; vector<TH1D*> stopH; vector<TH1D*> backgroundH; // Plots for(int i=0;i<int(vvariable.size());i++) { TCanvas * c2 = new TCanvas("variable","variable", 800, 600); string sttbarH = "ttbarH"+std::to_string(i); string swjetsH = "wjetsH"+std::to_string(i); string sstopH = "stopH"+std::to_string(i); string sbackgroundH = "background"+std::to_string(i); // Create histogram(s) ttbarH.push_back(new TH1D(sttbarH.c_str(), "ttbar", vvariable[i].GetBins(), vvariable[i].GetXMin(), vvariable[i].GetXMax())); wjetsH.push_back(new TH1D(swjetsH.c_str(), "wjets", vvariable[i].GetBins(), vvariable[i].GetXMin(), vvariable[i].GetXMax())); stopH.push_back(new TH1D(sstopH.c_str(), "Signal", vvariable[i].GetBins(), vvariable[i].GetXMin(), vvariable[i].GetXMax())); backgroundH.push_back(new TH1D(sbackgroundH.c_str(), "Background", vvariable[i].GetBins(), vvariable[i].GetXMin(), vvariable[i].GetXMax())); ttbarH[i]->SetFillColor(kGreen-7); ttbarH[i]->SetLineColor(kGreen-7); wjetsH[i]->SetFillColor(kAzure+5); wjetsH[i]->SetLineColor(kAzure+5); //stopH->SetFillColor(kRed); stopH[i]->SetLineColor(kRed); if(vvariable.size()!=1) c1->cd(i+1); else c1->cd(); //Create TCuts TCut muon = "(abs(LepID)==13)&&(LepIso03<0.2)"; TCut electron = "(abs(LepID)==11)&&(LepIso03<0.2)"; TCut emu = muon||electron; TCut ISRjet = "Jet1Pt > 110"; TCut met = "Met > 300"; TCut jetLepMass = "JetLepMass < 100"; //TCut njets = "Njet > 1"; TCut lepPt = "LepPt < 17"; //TCut ht30 = "HT30 > 300"; //TCut ht20 = "HT20 > 450"; //TCut mt = "mt < 70"; TCut jethbpt = "JetHBpt < 80"; TCut selection = emu && ISRjet && met; // Fill histogram(s) signal & BACKGROUND & DATA ttbarTree->Draw((vvariable[i].GetExpression()+">>"+sttbarH).c_str(),"XS*5000/Nevt"*(selection),"goff"); wjetsTree->Draw((vvariable[i].GetExpression()+">>"+swjetsH).c_str(),"XS*5000/Nevt"*(selection),"goff"); stopTree->Draw((vvariable[i].GetExpression()+">>"+sstopH).c_str(),"XS*5000/Nevt"*(selection),"goff"); //MULTIPLICAR O SINAL // Normalize double BGIntegral = ttbarH[i]->Integral(0,ttbarH[i]->GetNbinsX()+2) + wjetsH[i]->Integral(0,wjetsH[i]->GetNbinsX()+2); double stopIntegral = stopH[i]->Integral(0,stopH[i]->GetNbinsX()+2); for(int j=0; j < stopH[i]->GetNbinsX()+2; j++) { stopH[i]->SetBinContent(j, stopH[i]->GetBinContent(j)/stopIntegral); ttbarH[i]->SetBinContent(j, ttbarH[i]->GetBinContent(j)/BGIntegral); wjetsH[i]->SetBinContent(j, wjetsH[i]->GetBinContent(j)/BGIntegral); } THStack *Stack = new THStack(vvariable[i].GetName().c_str(), (vvariable[i].GetName()+";"+vvariable[i].GetLeg().c_str()+";AU").c_str()); Stack->Add(ttbarH[i]); Stack->Add(wjetsH[i]); gPad->SetLogy(vvariable[i].GetLogy()); // Draw plots gStyle->SetOptStat(0); Stack->Draw("HIST"); stopH[i]->Draw("HIST same"); if(Stack->GetMaximum() > stopH[i]->GetMaximum()) { Stack->SetMaximum(Stack->GetMaximum()*1.05); } else { Stack->SetMaximum(stopH[i]->GetMaximum()*1.05); } //TLegend * legenda = gPad->BuildLegend(0.895,0.69,0.65,0.89,"NDC"); // Draw in Canvas c2 - Pad1 c2->cd(); gPad->SetLogy(vvariable[i].GetLogy()); Stack->Draw("HIST goff"); stopH[i]->Draw("HIST same goff"); //TLegend * legenda2 = gPad->BuildLegend(0.8,0.69,0.65,0.89,"NDC"); // Save individual plots as .pdf and .C //c2->SaveAs(("plots/"+vvariable[i].GetName()+".pdf").c_str()); //c2->SaveAs(("plots/"+vvariable[i].GetName()+".C").c_str()); delete c2; } //delete the vectors //Save file with all the plots c1->SaveAs("plots/shape.png"); c1->SaveAs("plots/shape.C"); return 0; }
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"); } }
void postFitPlotsCOMBINEINSERT(TString name="collMass",TString fileDataMuHad0Jet="asdf", TString fileDataMuHad1Jet = "asdf", TString fileDataMuHad2Jet = "asdf", TString fileDataMuEle0Jet = "asdf", TString fileDataMuEle1Jet = "asdf", TString fileDataMuEle2Jet = "asdf", TString file="fit2_signalV5_collMass_type1.root", TString dirInternal="filesBoosted", TString Xaxis="M_{#mu,#tau}_{coll} [GeV]", TString Yaxis="Events / 20 GeV", double xmin=200, double xmax=300, double ymin=-2, double ymax=2, bool setLogY=false, double legx1=0.6, double legy1=0.9, double legx2=0.9, double legy2=0.5, double MAX=-1, double MIN=-1, bool mutau0=true, bool mutau1=true, bool mutau2=true, bool muele0=true, bool muele1=true, bool muele2=true, bool REBIN=true, bool weightSOverSB=true,TString channelName="#mu#tau", double minsubs=-1, double maxsubs=-1){ gROOT->LoadMacro("tdrstyle.C"); setTDRStyle(); double kForPlotting=1; double branchingratioTauTau=0.063; double branchingratioTauMu=0.1; double Lumi=19717; gROOT->LoadMacro("CMS_lumi.C"); writeExtraText = false; int iPeriod = 2; // second parameter in example_plot is iPos, which drives the position of the CMS logo in the plot int iPos=11;// : top-left, left-aligned // iPos=33 : top-right, right-aligned // iPos=22 : center, centered // mode generally : // iPos = 10*(alignement 1/2/3) + position (1/2/3 = left/center/right) // example_plot( iPeriod, 11 ); // left-aligned // example_plot( iPeriod, 33 ); // right-aligned // example_plot( iPeriod, 0 ); // out of frame (in exceptional cases) // example_plot( iPeriod, 11 ); // default: left-aligned // example_plot( iPeriod, 22 ); // centered // example_plot( iPeriod, 33 ); // right-aligned bool muonchannels[3]={mutau0,mutau1,mutau2}; bool elechannels[3]={muele0,muele1,muele2}; int NBins=30; if(mutau2 || muele2 || REBIN) { REBIN=true; NBins=15;} TFile *_fileMC= new TFile("CombinedPlots20PAS/"+file); TFile *_fileDataMuHad0Jet= new TFile("CombinedPlots20PAS/"+fileDataMuHad0Jet); TFile *_fileDataMuHad1Jet= new TFile("CombinedPlots20PAS/"+fileDataMuHad1Jet); TFile *_fileDataMuHad2Jet= new TFile("CombinedPlots20PAS/"+fileDataMuHad2Jet); TFile *_fileDataMuEle0Jet= new TFile("CombinedPlots20PAS/"+fileDataMuEle0Jet); TFile *_fileDataMuEle1Jet= new TFile("CombinedPlots20PAS/"+fileDataMuEle1Jet); TFile *_fileDataMuEle2Jet= new TFile("CombinedPlots20PAS/"+fileDataMuEle2Jet); //TString dirInternalAllMU[3]={dirInternal+"/datacard_gg0_pfMetFixOldjesNewFakeShape",dirInternal+"/datacard_gg1_pfMetFixOldjesNewFakeShape", dirInternal+"/datacard_vbf20_pfMetFixOldjesNewFakeShape"}; TString dirInternalAllMU[3]={dirInternal+"/datacard_MuTau_0Jet_new",dirInternal+"/datacard_MuTau_1Jet_new", dirInternal+"/datacard_vbf_PAS20"}; TString dirInternalAllELE[3]={dirInternal+"/datacard_MuEle_0Jet",dirInternal+"/datacard_MuEle_1Jet", dirInternal+"/datacard_MuEle_2Jet"}; TString dirInternalSignal="shapes_prefit"; TH1F* hdata_obs = new TH1F("hdata_obs","",NBins,0,300); TH1F* hFAKES = new TH1F("hFAKES","",NBins,0,300); TH1F* hFAKESLEPTON = new TH1F("hFAKESLEPTON","",NBins,0,300); TH1F* hDY = new TH1F("hDY","",NBins,0,300); TH1F* hWW = new TH1F("hWW","",NBins,0,300); TH1F* hTOP = new TH1F("hTOP","",NBins,0,300); TH1F* hTT = new TH1F("hTT","",NBins,0,300); TH1F* hZTauTau = new TH1F("hZTauTau","",NBins,0,300); TH1F* hLFVVBF126 = new TH1F("hLFVVBF126","",NBins,0,300); TH1F* hSMVBF126 = new TH1F("hSMVBF126","",NBins,0,300); TH1F* hSMHWWVBF126 = new TH1F("hSMHWWVBF126","",NBins,0,300); TH1F* hLFVGG126 = new TH1F("hLFVGG126","",NBins,0,300); TH1F* hSMGG126 = new TH1F("hSMGG126","",NBins,0,300); TH1F* hSMHWWGG126 = new TH1F("hSMHWWGG126","",NBins,0,300); TH1F* hWGamma = new TH1F("hWGamma","",NBins,0,300); TH1F* hWGammaStar = new TH1F("hWGammaStar","",NBins,0,300); double weightMuTau[3]={1,1,1}; double weightMuEle[3]={1,1,1}; int binA=hdata_obs->FindBin(100); int binB=hdata_obs->FindBin(150); for (int i=0; i<3; i++){ cout << "starting" << i <<endl; if(muonchannels[i]!=true) continue; TH1F *hFAKES_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/fakes");hFAKES_2->SetName("fakesHisto"); TString Extra="/zjetsother"; if(i==2) Extra="/fakes"; // in the postfit directory the DY for VBF is not saved, since it has 0 events TH1F *hDY_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+Extra); hDY_2->SetName("dyHisto"); TH1F *hWW_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/ww"); TH1F *hTOP_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/singlet"); TH1F *hTT_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/ttbar"); TH1F *hZTauTau_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/ztautau"); TH1F *hLFVVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/LFVVBF"); TH1F *hLFVGG126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/LFVGG"); TH1F *hSMGG126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/SMGG126"); TH1F *hSMVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/SMVBF126"); Extra="/fakes"; if(i!=0) Extra="/WWGG126"; TH1F *hSMHWWGG126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+Extra); hSMHWWGG126_2->SetName("smwwgg"); if(i==0) hSMHWWGG126_2->Scale(0); TH1F *hSMHWWVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/WWVBF126"); hSMHWWVBF126_2->SetName("wwsm"); cout << "got histos" << endl; if(i!=2 && (REBIN)) { hFAKES_2->Rebin(2); hDY_2->Rebin(2); hWW_2->Rebin(2); hTOP_2->Rebin(2); hTT_2->Rebin(2); hZTauTau_2->Rebin(2); hLFVVBF126_2->Rebin(2); hLFVGG126_2->Rebin(2); hSMGG126_2->Rebin(2); hSMVBF126_2->Rebin(2); hSMHWWVBF126_2->Rebin(2); if(i!=0) hSMHWWGG126_2->Rebin(2); } // WEIGHT double bckg=hWW_2->Integral(binA,binB)+hFAKES_2->Integral(binA,binB) + hTOP_2->Integral(binA,binB) + hTT_2->Integral(binA,binB) + hZTauTau_2->Integral(binA,binB); bckg+=hSMVBF126_2->Integral(binA,binB)+hSMGG126_2->Integral(binA,binB)+hSMHWWVBF126_2->Integral(binA,binB); if(i!=2) bckg+=hDY_2->Integral(binA,binB); else hDY_2->Scale(0); if(i!=0) bckg+=hSMHWWGG126_2->Integral(binA,binB); else hSMHWWGG126_2->Scale(0); double signal=hLFVGG126_2->Integral(binA,binB)+hLFVVBF126_2->Integral(binA,binB); weightMuTau[i]=signal/(signal+bckg); cout<<"Weighting MuTau Channel "<<i<<" --> "<<weightMuTau[i]<<endl; if(weightSOverSB){ hFAKES_2->Scale(weightMuTau[i]); hDY_2->Scale(weightMuTau[i]); hWW_2->Scale(weightMuTau[i]); hTOP_2->Scale(weightMuTau[i]); hTT_2->Scale(weightMuTau[i]); hZTauTau_2->Scale(weightMuTau[i]); hLFVVBF126_2->Scale(weightMuTau[i]); hLFVGG126_2->Scale(weightMuTau[i]); hSMVBF126_2->Scale(weightMuTau[i]); hSMGG126_2->Scale(weightMuTau[i]); hSMHWWVBF126_2->Scale(weightMuTau[i]); hSMHWWGG126_2->Scale(weightMuTau[i]); } // MERGE fillNewHisto(hFAKES,hFAKES_2); if(i!=2) fillNewHisto(hDY,hDY_2); fillNewHisto(hWW,hWW_2); fillNewHisto(hTOP,hTOP_2); fillNewHisto(hTT,hTT_2); fillNewHisto(hZTauTau,hZTauTau_2); fillNewHisto(hLFVVBF126,hLFVVBF126_2); fillNewHisto(hLFVGG126,hLFVGG126_2); fillNewHisto(hSMVBF126,hSMVBF126_2); fillNewHisto(hSMGG126,hSMGG126_2); fillNewHisto(hSMHWWVBF126,hSMHWWVBF126_2); if(i!=0) fillNewHisto(hSMHWWGG126,hSMHWWGG126_2); } for (int i=0; i<3; i++){ if(elechannels[i]!=true) continue; TH1F *hFAKESLEPTON_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/Fakes"); hFAKESLEPTON_2->SetName("hFAKESLEPTON_2"); TString Extra="/DYnoTauTau"; if(i==2) Extra="/Fakes"; // in the postfit directory the DY for VBF is not saved, since it has 0 events TH1F *hDY_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+Extra); TH1F *hWW_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/WW"); Extra="/WG"; if(i!=1) Extra="/Fakes"; TH1F *hWGamma_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+Extra); hWGamma_2->SetName("hWGamma_2"); Extra="/WGStar"; if(i==2) Extra="/Fakes"; TH1F *hWGammaStar_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+Extra); hWGammaStar_2->SetName("hWGammaStar_2"); TH1F *hTOP_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/TOP"); TH1F *hTT_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/TT"); TH1F *hZTauTau_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/ZTauTau"); TH1F *hLFVVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/LFVVBF"); TH1F *hLFVGG126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/LFVGG"); TH1F *hSMGG126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/ggHTauTau"); TH1F *hSMVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/vbfHTauTau"); TH1F *hSMHWWGG126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/ggHWW"); TH1F *hSMHWWVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/vbfHWW"); if(i!=2 && (REBIN)) { hFAKESLEPTON_2->Rebin(2); hDY_2->Rebin(2); hWW_2->Rebin(2); hTOP_2->Rebin(2); hTT_2->Rebin(2); hZTauTau_2->Rebin(2); hLFVVBF126_2->Rebin(2); hLFVGG126_2->Rebin(2); hSMGG126_2->Rebin(2); hSMVBF126_2->Rebin(2); hSMHWWGG126_2->Rebin(2); hSMHWWVBF126_2->Rebin(2); hWGamma_2->Rebin(2); hWGammaStar_2->Rebin(2); } // WEIGHT double bckg=hWW_2->Integral(binA,binB)+hFAKESLEPTON_2->Integral(binA,binB) + hTOP_2->Integral(binA,binB) + hTT_2->Integral(binA,binB) + hZTauTau_2->Integral(binA,binB); bckg+=hSMVBF126_2->Integral(binA,binB)+hSMGG126_2->Integral(binA,binB)+hSMHWWVBF126_2->Integral(binA,binB)+hSMHWWGG126_2->Integral(binA,binB); if(i!=2) {bckg+=hDY_2->Integral(binA,binB)+hWGammaStar_2->Integral(binA,binB);} else {hDY_2->Scale(0); hWGammaStar_2->Scale(0);} if (i==1) bckg+=hWGamma_2->Integral(); else hWGamma_2->Scale(0); double signal=hLFVGG126_2->Integral()+hLFVVBF126_2->Integral(); weightMuEle[i]=signal/(signal+bckg); cout<<"Weighting MuEle Channel "<<i<<" --> "<<weightMuEle[i]<<endl; if(weightSOverSB){ hFAKESLEPTON_2->Scale(weightMuEle[i]); hDY_2->Scale(weightMuEle[i]); hWW_2->Scale(weightMuEle[i]); hTOP_2->Scale(weightMuEle[i]); hTT_2->Scale(weightMuEle[i]); hZTauTau_2->Scale(weightMuEle[i]); hWGamma_2->Scale(weightMuEle[i]); hWGammaStar_2->Scale(weightMuEle[i]); hLFVVBF126_2->Scale(weightMuEle[i]); hLFVGG126_2->Scale(weightMuEle[i]); hSMVBF126_2->Scale(weightMuEle[i]); hSMGG126_2->Scale(weightMuEle[i]); hSMHWWVBF126_2->Scale(weightMuEle[i]); hSMHWWGG126_2->Scale(weightMuEle[i]); } fillNewHisto(hFAKESLEPTON,hFAKESLEPTON_2); if(i!=2) fillNewHisto(hDY,hDY_2); fillNewHisto(hWW,hWW_2); if(i!=2) fillNewHisto(hWGammaStar,hWGammaStar_2); if(i==1) fillNewHisto(hWGamma,hWGamma_2); fillNewHisto(hTOP,hTOP_2); fillNewHisto(hTT,hTT_2); fillNewHisto(hZTauTau,hZTauTau_2); fillNewHisto(hLFVVBF126,hLFVVBF126_2); fillNewHisto(hLFVGG126,hLFVGG126_2); fillNewHisto(hSMVBF126,hSMVBF126_2); fillNewHisto(hSMGG126,hSMGG126_2); fillNewHisto(hSMHWWVBF126,hSMHWWVBF126_2); fillNewHisto(hSMHWWGG126,hSMHWWGG126_2); } TString dirInternalDataAllMU[3]={"gg0mutau","boostmutau","vbfmutau"}; for (int i=0; i<3; i++){ cout << "starting data" <<endl; if(muonchannels[i]!=true) continue; if(i == 0){ TH1F *hdata_obs_2=(TH1F*)_fileDataMuHad0Jet->Get(dirInternalDataAllMU[i]+"/data_obs"); } else if (i == 1){ TH1F *hdata_obs_2=(TH1F*)_fileDataMuHad1Jet->Get(dirInternalDataAllMU[i]+"/data_obs"); } else if (i == 2){ TH1F *hdata_obs_2=(TH1F*)_fileDataMuHad2Jet->Get(dirInternalDataAllMU[i]+"/data_obs"); } cout << "declared histos" << endl; //TH1F *hdata_obs_2=(TH1F*)_fileData->Get(dirInternalDataAllMU[i]+"/data_obs"); hdata_obs_2->SetName("hdata_obs_2"); if(weightSOverSB) hdata_obs_2->Scale(weightMuTau[i]); if(i!=2 && (REBIN)) hdata_obs_2->Rebin(2); cout << "filling data histo" << endl; fillNewHisto(hdata_obs,hdata_obs_2); } TString dirInternalDataAllELE[3]={"GGF","Boost","VBF"}; for (int i=0; i<3; i++){ if(elechannels[i]!=true) continue; if(i == 0){ TH1F *hdata_obs_2=(TH1F*)_fileDataMuEle0Jet->Get(dirInternalDataAllELE[i]+"/data_obs"); } else if (i == 1){ TH1F *hdata_obs_2=(TH1F*)_fileDataMuEle1Jet->Get(dirInternalDataAllELE[i]+"/data_obs"); } else if (i == 2){ TH1F *hdata_obs_2=(TH1F*)_fileDataMuEle2Jet->Get(dirInternalDataAllELE[i]+"/data_obs"); } //TH1F *hdata_obs_2=(TH1F*)_fileData->Get(dirInternalDataAllELE[i]+"/data_obs"); hdata_obs_2->SetName("hdata_obs_2"); if(weightSOverSB) hdata_obs_2->Scale(weightMuEle[i]); if(i!=2 && (REBIN) ) hdata_obs_2->Rebin(2); fillNewHisto(hdata_obs,hdata_obs_2); } TH1F *hSMHIGGS=(TH1F*) hSMVBF126->Clone();hSMHIGGS->SetName("hSMHIGGS"); hSMHIGGS->Add(hSMGG126); TH1F *hSMHWWHIGGS=(TH1F*) hSMHWWVBF126->Clone();hSMHWWHIGGS->SetName("hSMHWWHIGGS"); hSMHWWHIGGS->Add(hSMHWWGG126); hWGamma->Add(hWGammaStar); hFAKES->Add(hFAKESLEPTON); hFAKES->SetFillColor(kMagenta-10); hFAKES->SetLineColor(kMagenta+3); hFAKES->SetLineWidth(1); hFAKESLEPTON->SetFillColor(kMagenta-9); hFAKESLEPTON->SetLineColor(kMagenta+4); hFAKESLEPTON->SetLineWidth(1); hZTauTau->SetFillColor(kOrange-4); hZTauTau->SetLineColor(kOrange+4); hZTauTau->SetLineWidth(1); hDY->SetFillColor(kAzure+3); hDY->SetLineColor(kAzure+4); hDY->SetLineWidth(1); hWW->SetFillColor(kAzure+3); hWW->SetLineColor(kAzure+3); hWW->SetLineWidth(1); hWGamma->SetFillColor(kAzure+3); hWGamma->SetLineColor(kAzure+3); hWGamma->SetLineWidth(1); hTOP->SetFillColor(kGreen-2); hTOP->SetLineColor(kGreen+4); hTOP->SetLineWidth(1); hTT->SetFillColor(kGreen-2); hTT->SetLineColor(kGreen-2); hTT->SetLineWidth(1); hSMHIGGS->SetFillColor(kMagenta); hSMHIGGS->SetLineColor(kMagenta+1); hSMHIGGS->SetLineWidth(1); hSMHWWHIGGS->SetFillColor(kMagenta); hSMHWWHIGGS->SetLineColor(kMagenta+1); hSMHWWHIGGS->SetLineWidth(1); hLFVGG126->SetLineColor(kBlue); hLFVGG126->SetLineWidth(3); hLFVVBF126->SetLineColor(kBlue); hLFVVBF126->SetLineWidth(3); hLFVVBF126->SetLineStyle(kDashed); hSMHIGGS->SetLineColor(kMagenta); hSMHIGGS->SetLineWidth(3); hSMHWWHIGGS->SetLineColor(kMagenta); hSMHWWHIGGS->SetLineWidth(3); hdata_obs->SetMarkerSize(1); // Closer to Daniel's // PLOT TCanvas *c1 = new TCanvas("canvas_"+name); TPad *Pad1= new TPad("pad1","",0,0.2,1,1); Pad1->Draw(); Pad1->cd();; Pad1->SetLeftMargin(0.2147651); Pad1->SetRightMargin(0.06543624); Pad1->SetTopMargin(0.07); Pad1->SetBottomMargin(0.04); TH1F* fullMC2=hFAKES->Clone(); fullMC2->Add(hZTauTau); fullMC2->Add(hTT); fullMC2->Add(hWW); fullMC2->Add(hWGamma); fullMC2->Add(hDY); fullMC2->Add(hTOP); fullMC2->Add(hSMHIGGS); fullMC2->Add(hSMHWWHIGGS); fullMC2->SetFillColor(kGray+2); fullMC2->SetFillStyle(3002); fullMC2->SetMarkerSize(0); fullMC2->SetLineWidth(2); fullMC2->Draw("hist"); fullMC2->GetXaxis()->SetTitle(""); fullMC2->GetYaxis()->SetTitle(Yaxis); fullMC2->GetXaxis()->SetRangeUser(xmin,xmax); fullMC2->GetYaxis()->SetTitleOffset(1.2); fullMC2->GetYaxis()->SetTitleSize(0.05); fullMC2->GetXaxis()->SetNdivisions(0); fullMC2->GetYaxis()->SetLabelSize(0.04); TH1F* hSignal=hLFVGG126->Clone(); hSignal->SetName("hSignal"); hSignal->Add(hLFVVBF126); hSignal->SetLineColor(kBlue); hSignal->SetLineWidth(3); hSignal->SetLineStyle(2); THStack* stack = new THStack("stack",""); stack->Add(hFAKES); stack->Add(hWW); stack->Add(hWGamma); stack->Add(hDY); stack->Add(hTT); stack->Add(hTOP); stack->Add(hZTauTau); stack->Add(hSMHIGGS);; stack->Add(hSMHWWHIGGS); stack->Add(hSignal); int bins=hdata_obs->GetNbinsX()+1; /* cout<<"Yields "<<endl; cout<<"DATA \t" <<hdata_obs->Integral()+hdata_obs->GetBinContent(bins)<<endl; cout<<"VV \t" <<hWW->Integral()+hWW->GetBinContent(bins)<<endl; cout<<"TOP \t" <<hTOP->Integral()+hTOP->GetBinContent(bins)<<endl; cout<<"TT \t" <<hTT->Integral()+hTT->GetBinContent(bins)<<endl; cout<<"DY \t" <<hDY->Integral()+hDY->GetBinContent(bins)<<endl; cout<<"ZTauTau \t" <<hZTauTau->Integral()+hZTauTau->GetBinContent(bins)<<endl; cout<<"FAKES \t" <<hFAKES->Integral()+hFAKES->GetBinContent(bins)<<endl; cout<<"hFAKESLEPTON \t" <<hFAKESLEPTON->Integral()+hFAKESLEPTON->GetBinContent(bins)<<endl; cout<<"hSMHIGGS \t" <<hSMHIGGS->Integral()+hSMHWWHIGGS->Integral()+hSMHIGGS->GetBinContent(bins)+hSMHWWHIGGS->GetBinContent(bins)<<endl; cout<<"LFVGG126 \t" <<hLFVGG126->Integral()+hLFVGG126->GetBinContent(bins)<<endl; cout<<"LFVVBF126 \t" <<hLFVVBF126->Integral()+hLFVVBF126->GetBinContent(bins)<<endl; */ stack->Draw("samehist"); fullMC2->Draw("sames,E2"); // hSignal->Draw("sameshist"); double maxData=hdata_obs->GetMaximum(); double maxMC=stack->GetMaximum()*1.2; double maxLFV=hSignal->GetMaximum(); double minMC=stack->GetMinimum(); if(maxData>maxMC) {maxMC=1.2*maxData;} if(maxLFV>maxMC) {maxMC=1.2*maxLFV;} if(MAX!=-1) {maxMC=MAX;} if(minMC<1) minMC=0; stack->SetMaximum(maxMC); stack->GetYaxis()->SetRangeUser(minMC,maxMC); fullMC2->SetMaximum(maxMC); fullMC2->GetYaxis()->SetRangeUser(minMC,maxMC); hdata_obs->Draw("sames"); TLegend *leg = new TLegend(legx1,legy1,legx2,legy2,NULL,"brNDC"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetFillStyle(0); TLegendEntry *entry; entry=leg->AddEntry(hdata_obs,"Data","p"); entry=leg->AddEntry(fullMC2,"Bkgd. uncertainty","f"); //entry=leg->AddEntry(hSMHWWHIGGS,"SM HWW","f"); entry=leg->AddEntry(hSMHIGGS,"SM H","f"); entry=leg->AddEntry(hZTauTau,"Z#rightarrow#tau#tau","f"); entry=leg->AddEntry(hDY,"Other","f"); entry=leg->AddEntry(hTOP,"t#bar{t}, t, #bar{t}","f"); entry=leg->AddEntry(hFAKES,"MisID'd #tau, e, #mu","f"); entry=leg->AddEntry(hSignal,"LFV Higgs, (B=0.9%)","l"); // entry=leg->AddEntry("NULL","Br(h#rightarrow#mu#tau)=1%",""); // entry=leg->AddEntry("NULL","Br(h#rightarrow#tau#tau)=6%",""); leg->Draw(); /* TLegend *leg = new TLegend(legx1,legy1,legx2,legy2,NULL,"brNDC"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetFillStyle(0); TLegendEntry *entry; entry=leg->AddEntry(hdata_obs,"observed","p"); entry=leg->AddEntry(fullMC2,"bckg. uncertainty","fl"); //entry=leg->AddEntry(hSMHWWHIGGS,"SM HWW","f"); entry=leg->AddEntry(hSMHIGGS,"SM H","f"); eblindBy=leg->AddEntry(hZTauTau,"Z+#tau#tau (embedd.)","f"); eblindBy=leg->AddEntry(hDY,"EWK","f"); entry=leg->AddEntry(hFAKES,"Fakes","f"); entry=leg->AddEntry(hSignal,"LFV Higgs, (B=0.9%)","l"); // entry=leg->AddEntry("NULL","Br(h#rightarrow#mu#tau)=1%",""); // entry=leg->AddEntry("NULL","Br(h#rightarrow#tau#tau)=6%",""); */ leg->Draw(); CMS_lumi( Pad1, iPeriod, iPos ); //cmsPrelim(Lumi); Pad1->SetLogy(setLogY); c1->cd(); TPad *Pad2= new TPad("pad2","",0,0,1,0.23); Pad2->Draw(); Pad2->cd(); Pad2->SetGridy(); Pad2->SetLeftMargin(0.2147651); Pad2->SetRightMargin(0.06543624); Pad2->SetTopMargin(0.0); Pad2->SetBottomMargin(0.38); Pad2->SetFillStyle(0); TH1F * Ratio=hdata_obs->Clone(); Ratio->SetName("Ratio"); Ratio->Add(fullMC2,-1); double dataRatio[16]; double mcRatio[16]; double errordataUpRatio[16]; double errordataDownRatio[16]; double xbinsRatio[16]; double xerrorbinsRatio[16]; Ratio->Divide(fullMC2); TH1F* RatioError = Ratio->Clone(); RatioError->SetName("RatioError"); for (int i=0; i<RatioError->GetNbinsX()+1; i++){ double error=fullMC2->GetBinError(i)*hdata_obs->GetBinContent(i)/fullMC2->GetBinContent(i)/fullMC2->GetBinContent(i); //double error=fullMC2->GetBinError(i)/fullMC2->GetBinContent(i); RatioError->SetBinContent(i,0); RatioError->SetBinError(i,error); } for (int j=0; j<16; j++){ xbinsRatio[j]=300./15*(j-1)+10; xerrorbinsRatio[j]=10; dataRatio[j]=hdata_obs->GetBinContent(j); errordataUpRatio[j]=hdata_obs->GetBinError(j); errordataDownRatio[j]=hdata_obs->GetBinError(j); if(dataRatio[j]==0) {errordataUpRatio[j]=1.7; errordataDownRatio[j]=0;} mcRatio[j]=fullMC2->GetBinContent(j); dataRatio[j]-=mcRatio[j]; if(mcRatio[j]!=0) { dataRatio[j]=dataRatio[j]/mcRatio[j]; errordataUpRatio[j]=errordataUpRatio[j]/mcRatio[j]; errordataDownRatio[j]=errordataDownRatio[j]/mcRatio[j]; }else{ dataRatio[j]=0; errordataUpRatio[j]=0; errordataDownRatio[j]=0; } double error=0; if(fullMC2->GetBinContent(j)!=0) error=fullMC2->GetBinError(j)*hdata_obs->GetBinContent(j)/fullMC2->GetBinContent(j)/fullMC2->GetBinContent(j); cout<<hdata_obs->GetBinContent(j)<<" "<<mcRatio[j]<<" "<<hdata_obs->GetBinError(j)<<" "<<fullMC2->GetBinError(j)<<" "<<dataRatio[j]<<" "<<errordataUpRatio[j]<<" "<<error<<" "<<Ratio->GetBinError(j)<<" "<<sqrt(error*error+errordataUpRatio[j]*errordataUpRatio[j])<<endl; } TGraphAsymmErrors* dataGraphRatio=new TGraphAsymmErrors(16, xbinsRatio, dataRatio,xerrorbinsRatio,xerrorbinsRatio,errordataDownRatio,errordataUpRatio); Ratio->Draw(""); Ratio->GetXaxis()->SetLabelFont(42); Ratio->GetXaxis()->SetTitleFont(42); Ratio->GetYaxis()->SetNdivisions(505); Ratio->GetYaxis()->SetLabelFont(42); Ratio->GetYaxis()->SetLabelSize(0.122); Ratio->GetYaxis()->SetRangeUser(ymin,ymax); Ratio->GetXaxis()->SetRangeUser(xmin,xmax); Ratio->GetXaxis()->SetLabelSize(0.12); Ratio->GetXaxis()->SetLabelFont(42); Ratio->SetYTitle("#frac{Data-Bkgd (fit) }{Bkgd (fit)}"); Ratio->SetXTitle(Xaxis); Ratio->GetXaxis()->SetNdivisions(505); Ratio->GetYaxis()->CenterTitle(true); Ratio->GetYaxis()->SetTitleOffset(0.4); Ratio->GetYaxis()->SetTitleSize(0.11); Ratio->GetXaxis()->SetTitleOffset(0.8); Ratio->GetXaxis()->SetTitleSize(0.20); Ratio->SetMarkerSize(1.); RatioError->Draw("sames,E2"); RatioError->SetFillStyle(3002); RatioError->SetFillColor(kGray+2); RatioError->SetMarkerSize(0); // dataGraphRatio->Draw("sames,p"); TCanvas *c2 = new TCanvas("canvas_"+name+"_2","canvas_"+name+"_2"); TH1F* SUBTRACTEDMCERROR=fullMC2->Clone(); SUBTRACTEDMCERROR->SetName("SUBTRACTEDMCERROR"); for (int i=0; i<SUBTRACTEDMCERROR->GetNbinsX()+1; i++) SUBTRACTEDMCERROR->SetBinContent(i,0); SUBTRACTEDMCERROR->SetFillColor(kYellow+4); SUBTRACTEDMCERROR->SetFillStyle(3004); SUBTRACTEDMCERROR->SetLineWidth(2); TH1F* SUBTRACTED=hdata_obs->Clone(); SUBTRACTED->SetName("SUBTRACTED"); // const int entriesD=(const)SUBTRACTEDMCERROR->GetNbinsX(); double data[16]; double mc[16]; double errordataUp[16]; double errordataDown[16]; double xbins[16]; double xerrorbins[16]; for (int j=0; j<16; j++){ xbins[j]=300./15*(j-1)+10; xerrorbins[j]=10; data[j]=SUBTRACTED->GetBinContent(j); errordataUp[j]=SUBTRACTED->GetBinError(j); errordataDown[j]=SUBTRACTED->GetBinError(j); if(data[j]==0) {errordataUp[j]=1.7; errordataDown[j]=0;} mc[j]=fullMC2->GetBinContent(j); data[j]-=mc[j]; } TGraphAsymmErrors* dataGraph=new TGraphAsymmErrors(16, xbins, data,xerrorbins,xerrorbins,errordataDown,errordataUp); //dataGraph->SetMarkerColor(kRed); SUBTRACTED->Add(fullMC2,-1); for (int i=0; i<SUBTRACTED->GetNbinsX()+1; i++) SUBTRACTED->SetBinError(i,hdata_obs->GetBinError(i)); TH1F *hSignalFill=hSignal->Clone(); hSignalFill->SetName("hSignalFill"); hSignalFill->SetFillColor(kBlue-10); hSignalFill->SetFillStyle(1001); hSignalFill->SetLineWidth(2); hSignalFill->Draw("hist"); hSignalFill->SetLineStyle(1); hSignalFill->SetXTitle(Xaxis); SUBTRACTED->SetXTitle(Xaxis); SUBTRACTED->SetYTitle(Yaxis); hSignalFill->SetYTitle(Yaxis); hSignalFill->GetXaxis()->SetRangeUser(xmin,xmax); SUBTRACTED->GetXaxis()->SetRangeUser(xmin,xmax); SUBTRACTEDMCERROR->GetXaxis()->SetRangeUser(xmin,xmax); SUBTRACTEDMCERROR->SetXTitle(Xaxis); SUBTRACTEDMCERROR->SetYTitle(Yaxis); //hSignalFill->SetYTitle(Yaxis); SUBTRACTEDMCERROR->Draw("sames,E2"); //SUBTRACTED->Draw("sames"); dataGraph->Draw("sames,p"); SUBTRACTEDMCERROR->GetXaxis()->SetNdivisions(505); SUBTRACTED->GetXaxis()->SetNdivisions(505); hSignalFill->GetXaxis()->SetNdivisions(505); SUBTRACTEDMCERROR->GetXaxis()->SetLabelSize(0.04); SUBTRACTED->GetXaxis()->SetLabelSize(0.04); hSignalFill->GetXaxis()->SetLabelSize(0.04); SUBTRACTEDMCERROR->GetYaxis()->SetLabelSize(0.04); SUBTRACTED->GetYaxis()->SetLabelSize(0.04); hSignalFill->GetYaxis()->SetLabelSize(0.04); SUBTRACTEDMCERROR->GetYaxis()->SetTitleSize(0.05); SUBTRACTED->GetYaxis()->SetTitleSize(0.05); hSignalFill->GetYaxis()->SetTitleSize(0.05); if(minsubs==-1) minsubs=TMath::Min(hSignalFill->GetMinimum(),SUBTRACTED->GetMinimum())*2.5; if(maxsubs==-1) maxsubs=TMath::Max(hSignalFill->GetMaximum(),SUBTRACTED->GetMaximum())*1.2; hSignalFill->SetMaximum(maxsubs); hSignalFill->SetMinimum(minsubs); if(minsubs==-1) minsubs=TMath::Min(SUBTRACTEDMCERROR->GetMinimum(),SUBTRACTED->GetMinimum())*2.5; if(maxsubs==-1) maxsubs=TMath::Max(SUBTRACTEDMCERROR->GetMaximum(),SUBTRACTED->GetMaximum())*1.2; SUBTRACTEDMCERROR->SetMaximum(maxsubs); SUBTRACTEDMCERROR->SetMinimum(minsubs); SUBTRACTED->SetMaximum(maxsubs); SUBTRACTED->SetMinimum(minsubs); TLegend *leg2 = new TLegend(0.55,0.93,0.99,0.7,NULL,"brNDC"); leg2->SetFillColor(0); leg2->SetBorderSize(0); leg2->SetFillStyle(0); TLegendEntry *entry; // entry=leg2->AddEntry("NULL",channelName,""); entry=leg2->AddEntry(hSignalFill,"LFV H#rightarrow#mu#tau signal (B=0.9%)","f"); entry=leg2->AddEntry(SUBTRACTEDMCERROR,"Bkgd. uncertainty","f"); entry=leg2->AddEntry(SUBTRACTED,"Data-Bkgd","pl"); leg2->Draw(); CMS_lumi( c2, iPeriod, iPos ); c2->SaveAs(name+"_Subtracted.png"); c2->SaveAs(name+"_Subtracted.pdf"); if(!setLogY){ c1->SaveAs(name+".png"); c1->SaveAs(name+".pdf"); } else { c1->SaveAs(name+"_log.png"); c1->SaveAs(name+"_log.pdf"); } }
void compareDataStackMC(std::string histoName, std::string inputFile="inputFile.txt", bool update=false, double xmin=-9999.0, double xmax=-9999.0,int rebin=1) { //--------------------------------------------------------------------------- // read in the MC root files //--------------------------------------------------------------------------- std::string mcName[]= { "Dimuon Data", "DY+jets", "t#bar{t} +jets", "WW", "WZ" }; std::string leptonName="test"; double lumi =5000; if(inputFile.find("electron")!= std::string::npos) { leptonName="electron"; lumi = 5200.7; mcName[0]="DiElectron Data"; } else if(inputFile.find("muon")!= std::string::npos) { leptonName="muon"; lumi = 5204.7; } cout << "Data luminosity = " << lumi << endl; std::vector<MCFile> myMCFiles; std::string dataFile; FILE *fTable = fopen(inputFile.data(),"r"); int flag=1; while (flag!=-1) { // first reading input file char filename[500]; flag=fscanf(fTable,"%s",filename); char tmp[1000]; // read in x-section flag=fscanf(fTable,"%s",tmp); double cross=atof(tmp); // read in number of events flag=fscanf(fTable,"%s",tmp); double nevt=atof(tmp); double scale =lumi*cross/nevt; MCFile tempMCfile; tempMCfile.filename = filename; tempMCfile.scaleFactor = scale; if(flag!=-1 && cross>1e-6) { myMCFiles.push_back(tempMCfile); cout << tempMCfile.filename << "\t" << tempMCfile.scaleFactor << endl; } else if(flag!=-1) // is data { dataFile = filename; } } const unsigned int nfiles = myMCFiles.size(); cout << "Data file = " << dataFile << endl; cout << "Reading " << nfiles << " files" << endl; if(nfiles==0) { cout << "There is no file for me to process!" << endl; return; } //------------------------------------------------------------------------------- // Declaring histograms to be used //------------------------------------------------------------------------------- // local histograms THStack *hs = new THStack(Form("%s_stack",histoName.data()),""); // for local debugging TH1D* h_deno[nfiles]; int COLORCODE[]= { kRed-7, kRed-10, kRed-6, kMagenta-2, kMagenta-6, kBlue-7, kBlue-9 }; cout << "opening " << myMCFiles[0].filename << endl; TFile *f1 = TFile::Open(myMCFiles[0].filename.data()); TH1D* h_template = (TH1D*)(f1->Get(Form("%s",histoName.data()))); h_template->Reset(); TH1D* h_all = (TH1D*)h_template->Clone(Form("%s_all",histoName.data())); h_all -> Reset(); TFile *fdata = TFile::Open(dataFile.data()); TH1D* h_data= (TH1D*)(fdata->Get(Form("%s",histoName.data()))); h_data-> SetName(Form("%s_data",histoName.data())); h_data->Draw(); //------------------------------------------------------------------------------- // combine //------------------------------------------------------------------------------- for(int ifile=nfiles-1; ifile>=0; ifile--) { cout << "File " << ifile << endl; TFile *f_temp = TFile::Open(myMCFiles[ifile].filename.data()); cout << "opening " << myMCFiles[ifile].filename << endl; h_deno[ifile] = (TH1D*)(f_temp->Get(Form("%s",histoName.data()))); h_deno[ifile] -> SetName(Form("h_deno_%d",ifile)); h_deno[ifile] -> SetTitle(f_temp->GetName()); h_deno[ifile] -> Rebin(rebin); h_deno[ifile] -> SetLineColor(COLORCODE[ifile]); h_deno[ifile] -> SetFillColor(COLORCODE[ifile]); h_deno[ifile] -> SetFillStyle(1001); h_deno[ifile] -> SetMarkerColor(COLORCODE[ifile]); h_deno[ifile] -> Sumw2(); double weight = myMCFiles[ifile].scaleFactor; h_deno[ifile] -> Scale(weight); if(ifile==nfiles-1) { h_all -> Rebin(rebin); h_all -> Sumw2(); } h_all -> Add(h_deno[ifile]); hs -> Add(h_deno[ifile]); // to be used with TEfficiency methods cout << h_deno[ifile]->GetEntries() << endl; } // end of loop over files float x1NDC = 0.620968; float y1NDC = 0.684322; float x2NDC = 0.762097; float y2NDC = 0.898305; TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextSize(0.04); leg->SetBorderSize(0); leg->AddEntry(h_data,mcName[0].data()); for(int i=0; i < nfiles; i++) leg->AddEntry(h_deno[i], mcName[i+1].data()); int maxBin = h_data->GetMaximumBin(); double max = h_data->GetMaximum()+h_data->GetBinError(maxBin); double maxmc = hs->GetMaximum(); if(maxmc>max)max=maxmc; h_data->SetMaximum(1.1*max); TCanvas* c1 = new TCanvas("c1",inputFile.data(),0,0,500,500); h_data->SetMarkerSize(1); h_data->SetMarkerStyle(24); h_data->SetTitle(""); h_data->Draw("e"); if(xmin>-9999 && xmax>-9999) { h_data->GetXaxis()->SetRangeUser(xmin,xmax); } cout << "Data integral = " << h_data->Integral() << endl; hs->Draw("histsame"); h_data->Draw("esame"); leg->Draw("same"); std::string dirName = "compareDataMC_" + leptonName; gSystem->mkdir(dirName.data()); std::string filename; std::string psname ; psname = dirName+ "/overlay_" + histoName; filename = psname + ".eps"; c1->Print(filename.data()); filename = psname + ".gif"; c1->Print(filename.data()); filename = psname + ".pdf"; c1->Print(filename.data()); // study the ratios TCanvas* c2 = new TCanvas("c2","",700,0,700,1000); c2->Divide(1,2,0.01,0); c2->cd(1); gPad->SetTopMargin(0.01); gPad->SetBottomMargin(0); gPad->SetRightMargin(0.04); h_data->Draw("e"); if(xmin>-9999 && xmax>-9999) { h_data->GetXaxis()->SetRangeUser(xmin,xmax); } cout << h_data->GetName() << " integral = " << h_data->Integral() << endl; hs->Draw("histsame"); h_data->Draw("esame"); leg->Draw("same"); c2->cd(2); gStyle->SetStatW (0.3); gStyle->SetStatH (0.3); gStyle->SetStatX (0.879447); gStyle->SetStatY (0.939033); gStyle->SetStatFontSize(0.05); gStyle->SetStatBorderSize(0); gPad->SetRightMargin(0.04); gPad->SetTopMargin(0); gPad->SetBottomMargin(0.2); gPad->SetTickx(); gStyle->SetOptFit(1); TH1D* hratio = (TH1D*)h_data->Clone("hratio"); hratio->Reset(); hratio->Divide(h_data,h_all,1.0,1.0); hratio->SetTitle(""); hratio->SetMaximum(1.5); hratio->SetMinimum(0.5); hratio->SetTitleOffset(1.2,"Y"); hratio->GetXaxis()->SetTitle(h_data->GetXaxis()->GetTitle()); hratio->Draw("e1"); cout << "( " << h_data->GetBinContent(maxBin) << "+-" << h_data->GetBinError(maxBin) << " )/(" << h_all->GetBinContent(maxBin) << "+-" << h_all->GetBinError(maxBin) << ")= " << hratio->GetBinContent(maxBin) << "+-" << hratio->GetBinError(maxBin) << endl; psname = dirName+ "/ratio_" + histoName; filename = psname + ".eps"; c2->Print(filename.data()); filename = psname + ".gif"; c2->Print(filename.data()); filename = psname + ".pdf"; c2->Print(filename.data()); std::string remword =".txt"; size_t pos = inputFile.find(remword); if(pos!= std::string::npos) inputFile.replace(pos,remword.length(),""); std::string command = "recreate"; if(update)command ="update"; TFile* outFile = new TFile(Form("combined_%s.root",inputFile.data()),command.data()); h_all->Write(); hs->Write(); h_data->Write(); outFile->Close(); }
//=============================== void DrawFit(Double_t nSigma, Int_t iRapBin, Int_t iPTBin){ Char_t name[100]; //prepare the drawing of the individual components: fBG->SetFillColor(colour[BG]); fBG->SetLineColor(colour[BG]); fBG->SetFillStyle(1001); fBG->SetNpx(1000); TH1 *hBG = fBG->GetHistogram(); fUps1S->SetNpx(1000); fUps1S->SetFillColor(colour[UPS1S]); fUps1S->SetLineColor(colour[UPS1S]); fUps1S->SetFillStyle(1001); fUps2S->SetNpx(1000); fUps2S->SetFillColor(colour[UPS2S]); fUps2S->SetLineColor(colour[UPS2S]); fUps2S->SetFillStyle(1001); fUps3S->SetNpx(1000); fUps3S->SetFillColor(colour[UPS3S]); fUps3S->SetLineColor(colour[UPS3S]); fUps3S->SetFillStyle(1001); TH1 *hUps1S = fUps1S->GetHistogram(); TH1 *hUps2S = fUps2S->GetHistogram(); TH1 *hUps3S = fUps3S->GetHistogram(); THStack *hStack = new THStack("hMass_Stack", ""); hStack->Add(hBG); hStack->Add(hUps3S); hStack->Add(hUps2S); hStack->Add(hUps1S); hStack->Draw("same"); hMass->Draw("same"); fRECO->Draw("same"); TLine *line[3]; Double_t max[3] = {0.5, 0.5, 0.3}; for(int iL = 0; iL < 3; iL++){ line[iL]= new TLine(massMin[iL], 0.1, massMin[iL], max[iL]*hUps1S->GetMaximum()); line[iL]->SetLineStyle(2); line[iL]->SetLineColor(colour[iL]); line[iL]->SetLineWidth(2); line[iL]->Draw(); line[iL]->DrawLine(massMax[iL], 0.1, massMax[iL], max[iL]*hUps1S->GetMaximum()); } if(iRapBin == 0) sprintf(name, "|y| < %1.1f", onia::rapYPS); else if(iRapBin == 1) sprintf(name, "|y| < %1.1f", onia::rapForPTRange[iRapBin]); else if(iRapBin > 1) sprintf(name, "%1.1f < |y| < %1.1f", onia::rapForPTRange[iRapBin-1], onia::rapForPTRange[iRapBin]); TLatex *tex = new TLatex(8.5, hStack->GetMaximum(), name); tex->SetTextSize(0.04); tex->Draw(); if(iPTBin == 0) sprintf(name, "all p_{T}"); // else if(iPTBin == 1) sprintf(name, "p_{T} < %1.1f GeV", onia::pTRange[iRapBin][iPTBin]); else sprintf(name, "%1.1f < p_{T} < %1.1f", onia::pTRange[iRapBin][iPTBin-1], onia::pTRange[iRapBin][iPTBin]); tex->DrawLatex(8.5, 0.94*hStack->GetMaximum(), name); sprintf(name, "frac(BG) in #pm %1.1f#sigma:", nSigma); tex->DrawLatex(8.5, 0.86*hStack->GetMaximum(), name); sprintf(name, "%1.2f, %1.2f, %1.2f", fracBG[0], fracBG[1], fracBG[2]); tex->DrawLatex(8.5, 0.80*hStack->GetMaximum(), name); sprintf(name, "Figures/massFit_rap%d_pT%d.pdf", iRapBin, iPTBin); gPad->Print(name); }
void Draw(TString name, TString histotitle, bool log, int move_legend) { TH1F* hist_b; TH1F* hist_c; TH1F* hist_gsplit; TH1F* hist_l; TH1F* hist_data; TFile *myFile = new TFile(filename); myFile->cd(); hist_b = (TH1F*)gROOT->FindObject(name+"_b"); hist_c = (TH1F*)gROOT->FindObject(name+"_c"); hist_gsplit = (TH1F*)gROOT->FindObject(name+"_bfromg"); hist_l = (TH1F*)gROOT->FindObject(name+"_l"); hist_data = (TH1F*)gROOT->FindObject(name+"_data"); if (bOverflow && name!="SSV" && name!="SSVHP") { OverFlowBinFix(hist_b); OverFlowBinFix(hist_c); OverFlowBinFix(hist_gsplit); OverFlowBinFix(hist_l); OverFlowBinFix(hist_data); } TH1F* histo_tot = (TH1F*) hist_b->Clone(); histo_tot->Sumw2(); histo_tot ->Add(hist_c); histo_tot ->Add(hist_gsplit); histo_tot ->Add(hist_l); float scale_f = (hist_data->Integral())/(hist_b->Integral() + hist_c ->Integral()+ hist_gsplit->Integral() + hist_l->Integral()); hist_b ->Scale(scale_f); hist_c ->Scale(scale_f); hist_gsplit ->Scale(scale_f); hist_l ->Scale(scale_f); histo_tot ->Scale(scale_f); double titleoffsety=0.2; double titlesizex=0.17; double titlesizey=0.2; double labelsizex=0.14; double labelsizey=0.12; hist_data ->GetYaxis()->SetLabelSize(labelsizey); hist_data ->GetYaxis()->SetTitleSize(titlesizey); hist_data ->GetYaxis()->SetTitleOffset(titleoffsety); hist_b ->GetYaxis()->SetLabelSize(labelsizey); hist_b ->GetYaxis()->SetTitleSize(titlesizey); hist_b ->GetYaxis()->SetTitleOffset(titleoffsety); TH1F* histo_ratio; histo_ratio = (TH1F*) hist_data->Clone(); histo_ratio->SetName("histo_ratio"); histo_ratio->SetTitle(""); histo_ratio->Divide(histo_tot); hist_data ->SetLineWidth(2); hist_data ->SetMarkerStyle(20); hist_data ->SetMarkerSize(0.75); hist_c ->SetFillColor(8); hist_b ->SetFillColor(2); hist_gsplit->SetFillColor(7); hist_l ->SetFillColor(4); histo_tot ->SetLineColor(2); THStack *stack = new THStack("stack","stack"); if (b_ordering){ stack ->Add(hist_b); stack ->Add(hist_gsplit); stack ->Add(hist_c); stack ->Add(hist_l); } else { stack ->Add(hist_l); stack ->Add(hist_c); stack ->Add(hist_gsplit); stack ->Add(hist_b); } gStyle->SetOptTitle(0); gStyle->SetOptStat(0); //gStyle->SetLogy(log); TCanvas *c1 = new TCanvas("c1", "c1",10,32,782,552); c1->SetFillColor(10); c1-> cd(); TPad* canvas_1 = new TPad("canvas_1", "canvas_1",0,0.25,1.0,0.98); canvas_1 ->Draw(); canvas_1 ->cd(); canvas_1->SetLogy(log); if (hist_data->GetMaximum() > stack->GetMaximum() ) stack->SetMaximum( hist_data->GetMaximum()*1.1) ; float xmov=1; if (move_legend==2) { if (log) xmov=5; else xmov=1.1; stack->SetMaximum( xmov*stack->GetMaximum() ) ; } if (stack->GetMinimum()> hist_l->GetMinimum()) { if (log && hist_l->GetMinimum()>0.) stack->SetMinimum(hist_l->GetMinimum()); else if (!log) stack->SetMinimum(hist_l->GetMinimum()); } stack ->Draw("hist"); stack ->GetHistogram()->GetXaxis()->SetTitle(name); stack ->GetHistogram()->GetYaxis()->SetTitle("entries"); stack ->GetHistogram()->SetTitleSize(0.08,"Y"); stack ->GetHistogram()->SetTitleOffset(0.65,"Y"); hist_data->Draw("same e"); // TLegend* qw = new TLegend(0.54,0.63,0.88,0.9); TLegend* qw; if (move_legend==1) { qw = new TLegend(0.35,0.15,0.70,0.42); } else if (move_legend==3) { qw = new TLegend(0.35,0.63,0.70,0.90); } else qw = new TLegend(0.6,0.73,0.95,1.); //Legend qw->AddEntry(hist_data, "e#mu ttbar data", "p"); qw->AddEntry(hist_b, "b quark" , "f"); qw->AddEntry(hist_gsplit, "b from gluon splitting" ,"f"); qw->AddEntry(hist_c, "c quark" , "f"); qw->AddEntry(hist_l, "uds quark or gluon" , "f"); qw->SetFillColor(0); qw->Draw(); TLatex *latex = new TLatex(); latex->SetNDC(); latex->SetTextSize(0.055); latex->SetTextFont(42); //22 latex->SetTextAlign(13); latex->DrawLatex(0.08, 0.96, title); c1->cd(); TPad* canvas_2 = new TPad("canvas_2", "canvas_2",0,0.,1.0,0.32); canvas_2->Draw(); canvas_2->cd(); gPad->SetBottomMargin(0.375); gPad->SetGridy(); histo_ratio->SetMarkerStyle(20); histo_ratio->SetMarkerSize(0.75); histo_ratio->SetLineWidth(2); histo_ratio->GetYaxis()->SetTitle("Data/MC"); histo_ratio->GetXaxis()->SetTitle(histotitle); histo_ratio->GetYaxis()->SetNdivisions( 505 ); histo_ratio->GetXaxis()->SetLabelSize( labelsizex); histo_ratio->GetXaxis()->SetTitleSize( titlesizex ); histo_ratio->SetMinimum(0.4); histo_ratio->SetMaximum(1.6); histo_ratio->Draw("E1X0"); c1->cd(); TString name_plot=name+"_Linear"+format; if(log) name_plot=name+"_Log"+format; c1->SaveAs("Commissioning_plots/"+name_plot); if (log && web) { // save also _Linear for web canvas_1 ->cd(); canvas_1->SetLogy(false); if (xmov==5) { stack->SetMaximum( 1.1*stack->GetMaximum() ) ; } c1->cd(); c1->SaveAs("Commissioning_plots/"+name+"_Linear"+format); } }
void DrawTTbar(TString name, TString histotitle, bool log, int move_legend) { TH1F* hist_ttbar; TH1F* hist_dy; TH1F* hist_st; TH1F* hist_data; TFile *myFile = new TFile(filename); myFile->cd(); hist_ttbar = (TH1F*)gROOT->FindObject(name+"_ttbar"); hist_dy = (TH1F*)gROOT->FindObject(name+"_dy"); hist_st = (TH1F*)gROOT->FindObject(name+"_st"); hist_data = (TH1F*)gROOT->FindObject(name+"_data"); if (bOverflow) { OverFlowBinFix(hist_ttbar); OverFlowBinFix(hist_dy); OverFlowBinFix(hist_st); OverFlowBinFix(hist_data); } TH1F* histo_tot = (TH1F*) hist_ttbar->Clone(); histo_tot->Sumw2(); histo_tot ->Add(hist_dy); histo_tot ->Add(hist_st); /* float scale_f = (hist_data->Integral())/(hist_tot->Integral()); hist_ttbar ->Scale(scale_f); hist_dy ->Scale(scale_f); hist_st ->Scale(scale_f); histo_tot ->Scale(scale_f); */ double titleoffsety=0.2; double titlesizex=0.17; double titlesizey=0.2; double labelsizex=0.14; double labelsizey=0.12; hist_data ->GetYaxis()->SetLabelSize(labelsizey); hist_data ->GetYaxis()->SetTitleSize(titlesizey); hist_data ->GetYaxis()->SetTitleOffset(titleoffsety); hist_ttbar ->GetYaxis()->SetLabelSize(labelsizey); hist_ttbar ->GetYaxis()->SetTitleSize(titlesizey); hist_ttbar ->GetYaxis()->SetTitleOffset(titleoffsety); TH1F* histo_ratio; histo_ratio = (TH1F*) hist_data->Clone(); histo_ratio->SetName("histo_ratio"); histo_ratio->SetTitle(""); histo_ratio->Divide(histo_tot); hist_data ->SetLineWidth(2); hist_data ->SetMarkerStyle(20); hist_data ->SetMarkerSize(0.75); hist_dy ->SetFillColor(kAzure-2); hist_ttbar ->SetFillColor(kRed+1); hist_st ->SetFillColor(kMagenta); THStack *stack = new THStack("stack","stack"); stack ->Add(hist_ttbar); stack ->Add(hist_st); stack ->Add(hist_dy); gStyle->SetOptTitle(0); gStyle->SetOptStat(0); //gStyle->SetLogy(log); TCanvas *c1 = new TCanvas("c1", "c1",10,32,782,552); c1->SetFillColor(10); c1-> cd(); TPad* canvas_1 = new TPad("canvas_1", "canvas_1",0,0.25,1.0,0.98); canvas_1 ->Draw(); canvas_1 ->cd(); canvas_1->SetLogy(log); if (hist_data->GetMaximum() > stack->GetMaximum() ) stack->SetMaximum( hist_data->GetMaximum()*1.1) ; if (move_legend==2) { if (log) stack->SetMaximum( 5.*stack->GetMaximum() ) ; else stack->SetMaximum( 1.1*stack->GetMaximum() ) ; } stack ->Draw("hist"); stack ->GetHistogram()->GetXaxis()->SetTitle(name); stack ->GetHistogram()->GetYaxis()->SetTitle("entries"); stack ->GetHistogram()->SetTitleSize(0.08,"Y"); stack ->GetHistogram()->SetTitleOffset(0.65,"Y"); hist_data->Draw("same e"); // TLegend* qw = new TLegend(0.54,0.63,0.88,0.9); TLegend* qw; if (move_legend==1) { qw = new TLegend(0.35,0.15,0.70,0.42); } else if (move_legend==3) { qw = new TLegend(0.35,0.63,0.70,0.90); } else qw = new TLegend(0.6,0.73,0.95,1.); //Legend qw->AddEntry(hist_data, "e#mu data", "p"); qw->AddEntry(hist_ttbar, "t#bar{t}" , "f"); qw->AddEntry(hist_dy, "DY" ,"f"); qw->AddEntry(hist_st, "tW" , "f"); qw->SetFillColor(0); qw->Draw(); TLatex *latex = new TLatex(); latex->SetNDC(); latex->SetTextSize(0.055); latex->SetTextFont(42); //22 latex->SetTextAlign(13); latex->DrawLatex(0.08, 0.96, title); c1->cd(); TPad* canvas_2 = new TPad("canvas_2", "canvas_2",0,0.,1.0,0.32); canvas_2->Draw(); canvas_2->cd(); gPad->SetBottomMargin(0.375); gPad->SetGridy(); histo_ratio->SetMarkerStyle(20); histo_ratio->SetMarkerSize(0.75); histo_ratio->SetLineWidth(2); histo_ratio->GetYaxis()->SetTitle("Data/MC"); histo_ratio->GetXaxis()->SetTitle(histotitle); histo_ratio->GetYaxis()->SetNdivisions( 505 ); histo_ratio->GetXaxis()->SetLabelSize( labelsizex); histo_ratio->GetXaxis()->SetTitleSize( titlesizex ); histo_ratio->SetMinimum(0.4); histo_ratio->SetMaximum(1.6); histo_ratio->Draw("E1X0"); c1->cd(); TString name_plot="ttbar_"+name+"_Linear"+format; if(log) name_plot="ttbar_"+name+"_Log"+format; c1->SaveAs("Commissioning_plots/"+name_plot); }
void Draw(string filename, bool norm, bool logy, bool eff, bool cum, TLine* line){ if(debug) printf(" Draw (norm is %i) %s\n",norm, filename.c_str()); TCanvas c1; if(logy) c1.SetLogy(); string title; if(Data.size()){ title = Data[0].hist->GetTitle(); title += ";"; title += Data[0].hist->GetXaxis()->GetTitle(); title += ";"; title += Data[0].hist->GetYaxis()->GetTitle(); }else if(Bkg.size()){ title = Bkg[0].hist->GetTitle(); title += ";"; title += Bkg[0].hist->GetXaxis()->GetTitle(); title += ";"; title += Bkg[0].hist->GetYaxis()->GetTitle(); } TH1F* hData = NULL; for(uint i=0; i<Data.size(); i++){ if(i==0) hData = (TH1F*)Data[i].hist->Clone("hData"); else hData->Add(Data[i].hist); } hData->SetMarkerSize(5); if(!eff){ THStack* sBkg = new THStack("sBkg",title.c_str()); THStack* sSigs[Sig.size()]; for(uint i=0; i<Bkg.size(); i++){ sBkg->Add(Bkg[i].hist); } for(uint i=0; i<Sig.size(); i++){ sSigs[i] = (THStack*) sBkg->Clone(); sSigs[i]->Add(Sig[i].hist); } Double_t max = sBkg->GetMaximum(); sBkg->Draw("HIST"); for(unsigned int i=0; i<Sig.size(); i++){ max = TMath::Max(max, sSigs[i]->GetMaximum()); sSigs[i]->Draw("HIST SAME"); } if(hData){ max = TMath::Max(max, hData->GetMaximum()); hData->Draw("E1 SAME"); } sBkg->SetMaximum(1.1*max); }else{ THStack* hs = new THStack("hs",title.c_str()); hs->Add(hData); for(unsigned int i=0; i<Bkg.size(); ++i){ hs->Add(Bkg[i].hist); } for(unsigned int i=0; i<Sig.size(); ++i){ hs->Add(Sig[i].hist); } hs->Draw("nostack HIST"); } if(debug) cout<<"Title: "<<title<<endl; if(debug) cout<<"Creating Legend\n"; TLegend *legend = new TLegend(0.65,0.50,0.88,0.89,""); if(Data.size()) legend->AddEntry(hData, "Data", "PLE"); for(unsigned int i=0; i<Bkg.size(); ++i){ legend->AddEntry(Bkg[i].hist,SampleNames[Bkg[i].name].c_str(), "L"); } for(unsigned int i=0; i<Sig.size(); ++i){ legend->AddEntry(Sig[i].hist,SampleNames[Sig[i].name].c_str(), "L"); } if(norm){//???? //TAxis* axis = samples[0]->at(0).hist->GetXaxis(); //int first = axis->GetFirst(); //int last = axis->GetLast(); //float sum = hists[i]->Integral(first,last); //hists[i]->Scale(1./sum); //axis->SetRange(first,last); } //hs->GetXaxis()->SetNdivisions(10); if(debug) printf("Setting title\n"); legend->SetTextSize(0.03); legend->SetBorderSize(0); legend->SetFillStyle(0); legend->Draw(); if(line) line->Draw(); c1.SaveAs(filename.c_str()); c1.Print("Summary.pdf","pdf"); }
//======================= void PlotHistos(Char_t *enLabel, Char_t *fileNameIn) { Bool_t plotBG = kTRUE; gStyle->SetOptStat(kFALSE); // gStyle->SetOptFit(kTRUE); Char_t name[100]; //plot the mass histograms: TCanvas *c1Mass[kNbCath+2]; TLatex *texMass[kNbCath+2]; for(int iCat = 0; iCat < kNbCath+2; iCat++) { if(iCat > 2 && iCat < kNbCath) continue; sprintf(name, "c1Mass_%d", iCat); c1Mass[iCat] = new TCanvas(name, "mass"); // if(iCat == 2 && plotBG) // hReco_mass[0][iCat]->SetMaximum(5.); if(iCat == kNbCath+1 && plotBG) hReco_mass[0][iCat]->SetMaximum(12.); hReco_mass[0][iCat]->Draw(); hReco_mass[0][iCat]->Fit("gaus", "", "", 3.05, 3.15); // (hReco_mass[0][iCat]->GetFunction("gaus"))->SetLineWidth(1); if(iCat < kNbCath) (hReco_mass[0][iCat]->GetFunction("gaus"))->SetLineColor(colour[iCat]); texMass[iCat] = new TLatex(3.7, 0.65*hReco_mass[0][iCat]->GetMaximum(), enLabel); texMass[iCat]->SetTextSize(0.04); texMass[iCat]->Draw(); texMass[iCat]->DrawLatex(2.1, 0.6*hReco_mass[0][iCat]->GetMaximum(), catNames[iCat]); // sprintf(name, "#J/#psi per L_{int}=1 nb^{-1}: %1.0f #pm %1.0f", // integral[iCat], errPossonian[iCat]); // sprintf(name, "#J/#psi per L_{int}=1 nb^{-1}: %1.0f", integral[iCat]); sprintf(name, "#J/#psi per nb^{-1}: %1.0f", integral[iCat]); texMass[iCat]->DrawLatex(2.1, 0.5*hReco_mass[0][iCat]->GetMaximum(), name); if(plotBG) hRecoBG_mass[0][iCat]->Draw("same"); if(iCat < kNbCath) { sprintf(name, "Figures/%s_mass_%s.gif", fileNameIn, oniaCatName[iCat]); c1Mass[iCat]->Print(name); sprintf(name, "Figures/%s_mass_%s.pdf", fileNameIn, oniaCatName[iCat]); c1Mass[iCat]->Print(name); } else if(iCat == kNbCath) { sprintf(name, "Figures/%s_mass_GGandGT.gif", fileNameIn); c1Mass[iCat]->Print(name); sprintf(name, "Figures/%s_mass_GGandGT.pdf", fileNameIn); c1Mass[iCat]->Print(name); } else if(iCat == kNbCath+1) { sprintf(name, "Figures/%s_mass_all.gif", fileNameIn); c1Mass[iCat]->Print(name); sprintf(name, "Figures/%s_mass_all.pdf", fileNameIn); c1Mass[iCat]->Print(name); } } //plot the GG and GT combination with its BG AND //the GG with its BG overlayed: //plot the mass histograms: TCanvas *c1Massa[kNbCath+2]; TLatex *texMassa[kNbCath+2]; for(int iCat = kNbCath+1; iCat < kNbCath+2; iCat++) { sprintf(name, "c1Massa_%d", iCat); c1Massa[iCat] = new TCanvas(name, "mass special"); //gl-gl and gl-tr and tr-tr hReco_mass[0][iCat]->SetLineColor(4); (hReco_mass[0][iCat]->GetFunction("gaus"))->SetLineColor(4); hReco_mass[0][iCat]->Draw(); //gl-gl and gl-tr hReco_mass[0][kNbCath]->SetLineColor(2); (hReco_mass[0][kNbCath]->GetFunction("gaus"))->SetLineColor(2); hReco_mass[0][kNbCath]->Draw("same"); //gl-gl // hReco_mass[0][0]->SetLineColor(4); // (hReco_mass[0][0]->GetFunction("gaus"))->SetLineColor(4); hReco_mass[0][0]->Draw("same"); // hReco_mass[0][iCat]->Fit("gaus", "", "", 3.05, 3.15); // hReco_mass[0][iCat]->SetLineWidth(1); texMassa[iCat] = new TLatex(3.6, 0.65*hReco_mass[0][iCat]->GetMaximum(), enLabel); texMassa[iCat]->SetTextSize(0.04); texMassa[iCat]->Draw(); texMassa[iCat]->DrawLatex(2.45, 11., catNames[iCat]); // sprintf(name, "#J/#psi per L_{int}=1 nb^{-1}: %1.0f #pm %1.0f", // integral[iCat], errPossonian[iCat]); // sprintf(name, "#J/#psi per L_{int}=1 nb^{-1}: %1.0f", integral[iCat]); sprintf(name, "#J/#psi per nb^{-1}: %1.0f", integral[iCat]); texMassa[iCat]->DrawLatex(2.45, 9.8, name); if(plotBG) { //gl-gl and gl-tr and tr-tr hRecoBG_mass[0][iCat]->SetLineColor(4); hRecoBG_mass[0][iCat]->Draw("same"); //gl-gl and gl-tr hRecoBG_mass[0][kNbCath]->SetLineColor(2); hRecoBG_mass[0][kNbCath]->Draw("same"); //gl-gl hRecoBG_mass[0][0]->SetLineColor(1); hRecoBG_mass[0][0]->Draw("same"); } sprintf(name, "Figures/%s_mass_GGandGT_withGG.gif", fileNameIn); c1Massa[iCat]->Print(name); sprintf(name, "Figures/%s_mass_GGandGT_withGG.pdf", fileNameIn); c1Massa[iCat]->Print(name); TLatex *tex; if(iCat == kNbCath+1) { tex = new TLatex(3.231686,11.05442,"CMS simulation 2009"); tex->Draw(); tex = new TLatex(3.625803,6.712477,"per nb^{-1}"); tex->SetLineWidth(2); tex->Draw(); // tex = new TLatex(2.331331,10.70125,"global-global"); // tex->SetTextColor(4); // tex->SetTextSize(0.035); // tex->SetLineWidth(2); // tex->Draw(); // tex = new TLatex(2.368704,9.966102,"plus global-tracker"); // tex->SetTextColor(4); // tex->SetTextSize(0.035); // tex->SetLineWidth(2); // tex->Draw(); tex = new TLatex(2.399282,8.320604,"plus tracker-tracker"); tex->SetTextSize(0.04); tex->SetTextColor(4); tex->SetLineWidth(2); tex->Draw(); // tex = new TLatex(2.05273,4.08495,"global-global"); // tex->SetTextSize(0.035); // tex->SetTextColor(2); // tex->SetLineWidth(2); // tex->Draw(); tex = new TLatex(2.02555,3.946498,"plus global-tracker"); tex->SetTextSize(0.04); tex->SetTextColor(2); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(2.035742,0.5930161,"global-global"); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); } } //plot the pT histograms: TCanvas *c1Pt; TLatex *texPt; TH1F *hFramePt; sprintf(name, "c1Pt"); c1Pt = new TCanvas(name, "pt"); hFramePt = gPad->DrawFrame(0., 0., 8., 1.2*hReco_pT[0][1]->GetMaximum()); hFramePt->SetXTitle(hReco_pT[0][1]->GetXaxis()->GetTitle()); hFramePt->SetYTitle(hReco_pT[0][1]->GetYaxis()->GetTitle()); // hFramePt->SetYTitle("dN/dp_{T} [per 400 MeV/c]"); TLegend *legPt = new TLegend(0.72,0.684322,0.9899425,0.9618644, enLabel); for(int iCat = 0; iCat < 3; iCat++) { hReco_pT[0][iCat]->SetLineWidth(2); hReco_pT[0][iCat]->SetLineColor(colour[iCat]); hReco_pT[0][iCat]->Draw("same"); legPt->AddEntry(hReco_pT[0][iCat], catNames[iCat], "l"); } legPt->SetTextSize(0.04); legPt->SetFillColor(0); legPt->Draw(); sprintf(name, "Figures/%s_pT.gif", fileNameIn); c1Pt->Print(name); sprintf(name, "Figures/%s_pT.pdf", fileNameIn); c1Pt->Print(name); //get one stacked histogram: THStack *hStackPT = new THStack("hStackPT", ""); hReco_pT[0][0]->SetFillColor(1); hStackPT->Add(hReco_pT[0][0]); hReco_pT[0][1]->SetFillColor(2); hStackPT->Add(hReco_pT[0][1]); hReco_pT[0][2]->SetFillColor(4); hStackPT->Add(hReco_pT[0][2]); TCanvas *c1PTStack = new TCanvas("c1PTStack", "pT stacked"); TH1F *hFramePT = gPad->DrawFrame(0., 0., 8., 1.1*hStackPT->GetMaximum()); hFramePT->SetXTitle("p_{T} (J/#psi) [GeV/c]"); // hFramePT->SetYTitle("dN/dp_{T}"); hFramePT->SetYTitle(hReco_pT[0][1]->GetYaxis()->GetTitle()); hStackPT->Draw("histsame"); TLegend *legPTSt = new TLegend(0.72,0.684322,0.9899425,0.9618644, enLabel); for(int iCat = 2; iCat >= 0; iCat--) legPTSt->AddEntry(hReco_pT[0][iCat], catNames[iCat], "f"); legPTSt->SetTextSize(0.04); legPTSt->SetFillColor(0); legPTSt->Draw(); sprintf(name, "Figures/%s_pTStacked.gif", fileNameIn); c1PTStack->Print(name); sprintf(name, "Figures/%s_pTStacked.pdf", fileNameIn); c1PTStack->Print(name); //plot the rap histograms: TCanvas *c1Rap; TLatex *texRap; TH1F *hFrameRap; sprintf(name, "c1Rap"); c1Rap = new TCanvas(name, "rap"); hFrameRap = gPad->DrawFrame(-2.5, 0., 2.5, 1.2*hReco_rap[0][1]->GetMaximum()); hFrameRap->SetXTitle(hReco_rap[0][1]->GetXaxis()->GetTitle()); hFrameRap->SetYTitle(hReco_rap[0][1]->GetYaxis()->GetTitle()); // hFrameRap->SetYTitle("dN/dy"); TLegend *legRap = new TLegend(0.5474138,0.6567797,0.8175287,0.93432, enLabel); for(int iCat = 0; iCat < 3; iCat++) { hReco_rap[0][iCat]->SetLineWidth(2); hReco_rap[0][iCat]->SetLineColor(colour[iCat]); hReco_rap[0][iCat]->Draw("same"); legRap->AddEntry(hReco_rap[0][iCat], catNames[iCat], "l"); } legRap->SetTextSize(0.04); legRap->SetFillColor(0); legRap->Draw(); sprintf(name, "Figures/%s_rap.gif", fileNameIn); c1Rap->Print(name); sprintf(name, "Figures/%s_rap.pdf", fileNameIn); c1Rap->Print(name); //get one stacked histogram: THStack *hStack = new THStack("hStack", ""); hReco_rap[0][0]->SetFillColor(1); hStack->Add(hReco_rap[0][0]); hReco_rap[0][1]->SetFillColor(2); hStack->Add(hReco_rap[0][1]); hReco_rap[0][2]->SetFillColor(4); hStack->Add(hReco_rap[0][2]); TCanvas *c1RapStack = new TCanvas("c1RapStack", "rap stacked"); TH1F *hFrame = gPad->DrawFrame(-2.5, 0., 2.5, 1.1*hStack->GetMaximum()); hFrame->SetXTitle("y(J/#psi)"); hFrame->SetYTitle("dN/dy"); hStack->Draw("histsame"); TLegend *legRapSt = new TLegend(0.5474138,0.6567797,0.8175287,0.93432, enLabel); for(int iCat = 2; iCat >= 0; iCat--) legRapSt->AddEntry(hReco_rap[0][iCat], catNames[iCat], "f"); legRapSt->SetTextSize(0.04); legRapSt->SetFillColor(0); legRapSt->Draw(); sprintf(name, "Figures/%s_rapStacked.gif", fileNameIn); c1RapStack->Print(name); sprintf(name, "Figures/%s_rapStacked.pdf", fileNameIn); c1RapStack->Print(name); }
void fake() { gROOT->SetBatch(); gROOT->SetStyle("Plain"); gStyle->SetOptStat(0); SetStyle(); TCanvas *c1 = new TCanvas("c1","c1",0,0,600,500); c1->Draw(); c1->cd(); TPad *c1_1; gStyle->SetHistTopMargin(0); TLegend *leg = new TLegend(0.65,0.90,0.90,0.70); leg->SetFillColor(253); leg->SetBorderSize(0); std::string fpath = "histTEST_MERGED/QCD_Pt_170to300_TuneCUETP8M1_13TeV_pythia8/data.root"; // std::string histnameFake = "h_muFake_pt"; // std::string histnameReal = "h_muReal_pt"; // std::string histnameFake = "h_muFake_trackerLayersWithMeasurement"; // std::string histnameReal = "h_muReal_trackerLayersWithMeasurement"; // std::string histnameFake = "h_muFake_numberOfValidMuonHits"; // std::string histnameReal = "h_muReal_numberOfValidMuonHits"; // std::string histnameFake = "h_muFake_numberOfMatches"; // std::string histnameReal = "h_muReal_numberOfMatches"; // std::string histnameFake = "h_muFake_numberOfMatchedStations"; // std::string histnameReal = "h_muReal_numberOfMatchedStations"; // std::string histnameFake = "h_muFake_numberOfValidHits"; // std::string histnameReal = "h_muReal_numberOfValidHits"; // std::string histnameFake = "h_muFake_numberOfValidPixelHits"; // std::string histnameReal = "h_muReal_numberOfValidPixelHits"; std::string histnameFake = "h_muFake_numberOfHits"; std::string histnameReal = "h_muReal_numberOfHits"; // std::string histnameFake = "h_muFake_normalizedChi2GlobalTrack"; // std::string histnameReal = "h_muReal_normalizedChi2GlobalTrack"; // std::string histnameFake = "h_muFake_normalizedChi2InnerTrack"; // std::string histnameReal = "h_muReal_normalizedChi2InnerTrack"; TFile *f; TH1D *hFake; TH1D *hReal; f = TFile::Open(fpath.c_str()); { TH1D *hFake_c = (TH1D*)f->Get(histnameFake.c_str()); hFake_c->SetMarkerSize(0.0); TH1D *hReal_c = (TH1D*)f->Get(histnameReal.c_str()); hReal_c->SetMarkerSize(0.0); hFake = (TH1D*)hFake_c->Clone("hFake"); hReal = (TH1D*)hReal_c->Clone("hReal"); } addbin(hFake); addbin(hReal); std::cout << hReal->Integral() << std::endl; std::cout << hFake->Integral() << std::endl; double iFake = hFake->Integral(); double iReal = hReal->Integral(); // double iAll = iFake+iReal; // hFake->Scale(1./iAll); // hReal->Scale(1./iAll); hFake->SetLineColor(9); hFake->SetFillColor(9); hReal->SetLineColor(46); hReal->SetFillColor(46); THStack *hst = new THStack(); hst->Add(hReal); hst->Add(hFake); hst->Draw("hist e1"); float max = hst->GetMaximum(); hst->SetMaximum(1.3*max); hst->SetMinimum(0.); if( histnameFake == "h_muFake_pt" ) hst->GetXaxis()->SetTitle("p_{T} [GeV]"); hst->GetYaxis()->SetTitle("Number of muons"); leg->AddEntry(hFake,"Fake","f"); leg->AddEntry(hReal,"Real","f"); leg->Draw(); c1->Print("pics/fake.eps"); c1->Clear(); TH1F *hRealScaled = (TH1F*)hReal->Clone("hRealScaled"); hRealScaled->Scale(1./iReal); TH1F *hFakeScaled = (TH1F*)hFake->Clone("hFakeScaled"); hFakeScaled->Scale(1./iFake); hFakeScaled->SetLineColor(9); hFakeScaled->SetFillColor(0); hRealScaled->SetLineColor(46); hRealScaled->SetFillColor(0); hRealScaled->Draw("hist e1"); hFakeScaled->Draw("hist e1 same"); float max1 = hRealScaled->GetMaximum(); float max2 = hFakeScaled->GetMaximum(); max = (max1 > max2) ? max1 : max2; hRealScaled->SetMaximum(1.3*max); hRealScaled->SetMinimum(0.); if( histnameFake == "h_muFake_pt" ) hRealScaled->GetXaxis()->SetTitle("p_{T} [GeV]"); if( histnameFake == "h_muFake_trackerLayersWithMeasurement" ) hRealScaled->GetXaxis()->SetTitle("trackerLayersWithMeasurement"); if( histnameFake == "h_muFake_numberOfValidMuonHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidMuonHits"); if( histnameFake == "h_muFake_numberOfMatches" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatches"); if( histnameFake == "h_muFake_numberOfMatchedStations" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatchedStations"); if( histnameFake == "h_muFake_numberOfValidHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidHits"); if( histnameFake == "h_muFake_numberOfValidPixelHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidPixelHits"); if( histnameFake == "h_muFake_numberOfHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfHits"); if( histnameFake == "h_muFake_normalizedChi2GlobalTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2GlobalTrack"); if( histnameFake == "h_muFake_normalizedChi2InnerTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2InnerTrack"); hRealScaled->GetYaxis()->SetTitle("Normalized to unity"); leg->Draw(); c1->Print("pics/fakeComp.eps"); c1->Clear(); gApplication->Terminate(); }
THStack* BasePlot::GetStack(bool isLog) { THStack* hstack = new THStack(); float binWidth = 0; for (int i=0; i<nSamples; i++) if( _hist[i] && i != iHWW) { _hist[i]->SetLineColor(sampleColor[i]); _hist[i]->SetFillColor(sampleColor[i]); _hist[i]->SetFillStyle(1001); binWidth = _hist[i]->GetBinWidth(1); hstack->Add(_hist[i]); } for (size_t i=0; i<_autreHists.size(); i++) { _autreHists[i].second->SetLineColor(autreColors[i]); _autreHists[i].second->SetFillColor(autreColors[i]); _autreHists[i].second->SetFillStyle(1001); hstack->Add(_autreHists[i].second); } hstack->Draw("GOFF"); if(_prelim) hstack->SetTitle("CMS preliminary"); else hstack->SetTitle("CMS, #sqrt{s} = 7 TeV"); Float_t theMax = hstack->GetMaximum(); Float_t theMin = hstack->GetMinimum(); if (_hist[iHWW]) { if (_hist[iHWW]->GetMaximum() > theMax) theMax = _hist[iHWW]->GetMaximum(); if (_hist[iHWW]->GetMinimum() < theMin) theMin = _hist[iHWW]->GetMinimum(); } if (_data) { Float_t dataMax = GetMaximumIncludingErrors(_data); if (dataMax > theMax) theMax = dataMax; } int sampCount = GetSampCount(); float scaleBy = 1.35 + 0.2*(sampCount>6) + 0.2*(sampCount>10) + 0.2*(sampCount>14); // Min --- only need to change if log theMin = theMin==0?0.1:theMin/10; if(isLog) hstack->SetMinimum(theMin); // Max if (_myMax != -1) { hstack->SetMaximum(_myMax); } else if (isLog) { hstack->SetMaximum(pow(10,(log(theMax)/log(10)-log(theMin)/log(10)+1)*scaleBy+log(theMin)/log(10)-1)); } else { hstack->SetMaximum(scaleBy * theMax); } if(_breakdown) { THStackAxisFonts(hstack, "y", "entries"); hstack->GetHistogram()->LabelsOption("v"); } else { THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data())); THStackAxisFonts(hstack, "y", TString::Format("entries / %.1f %s", binWidth,_units.Data())); if(_units.Sizeof() == 1) { THStackAxisFonts(hstack, "x", _xLabel.Data()); // THStackAxisFonts(hstack, "y", "entries"); } } return hstack; }
void drawChannelYieldPlot( DrawBase* db, const std::string& selType, const std::string& bTaggerType, float lumi_fb, const std::string& saveName, std::string additionalCuts ) { if( additionalCuts!="" ) additionalCuts += " && "; // and now lepton channel definitions: std::string sel_mmm = "eventWeight*( " + additionalCuts + " isMZllSignalRegion && leptType==0 && leptType3==0)"; std::string sel_mme = "eventWeight*( " + additionalCuts + " isMZllSignalRegion && leptType==0 && leptType3==1)"; std::string sel_eem = "eventWeight*( " + additionalCuts + " isMZllSignalRegion && leptType==1 && leptType3==0)"; std::string sel_eee = "eventWeight*( " + additionalCuts + " isMZllSignalRegion && leptType==1 && leptType3==1)"; TLegend* legend = new TLegend( 0.6, 0.57, 0.92, 0.9 ); legend->SetFillColor(0); legend->SetTextSize(0.042); THStack* stackMC = new THStack(); std::vector<TH1D*> vh1_yields_mc; std::string yieldsFileName = "yields_"+selType; if( saveName!= "" ) yieldsFileName = yieldsFileName + "_" + saveName; yieldsFileName = yieldsFileName +"_"+bTaggerType+".txt"; ofstream yieldsFile(yieldsFileName.c_str()); yieldsFile << "------------------------" << std::endl; yieldsFile << "Yields @ " << lumi_fb << " fb-1" << std::endl; yieldsFile << "------------------------" << std::endl; yieldsFile << std::endl; yieldsFile << " (mm)m \t(mm)e \t(ee)m \t(ee)e \tTotal" << std::endl << std::endl; float s_mmm = 0.; float s_mme = 0.; float s_eem = 0.; float s_eee = 0.; float s = 0.; float b_mmm = 0.; float b_mme = 0.; float b_eem = 0.; float b_eee = 0.; float b = 0.; for( unsigned i=0; i<db->get_mcFiles().size(); ++i) { // reverse order: int iMC = db->get_mcFiles().size()-i-1; TTree* tree_mc = (TTree*)(db->get_mcFile(iMC).file->Get("tree_passedEvents")); TH1D* h1_mc_mmm = new TH1D("mc_mmm", "", 100, 0., 10000.); TH1D* h1_mc_mme = new TH1D("mc_mme", "", 100, 0., 10000.); TH1D* h1_mc_eem = new TH1D("mc_eem", "", 100, 0., 10000.); TH1D* h1_mc_eee = new TH1D("mc_eee", "", 100, 0., 10000.); tree_mc->Project("mc_mmm", "ptZll", sel_mmm.c_str()); tree_mc->Project("mc_mme", "ptZll", sel_mme.c_str()); tree_mc->Project("mc_eem", "ptZll", sel_eem.c_str()); tree_mc->Project("mc_eee", "ptZll", sel_eee.c_str()); float mmm = lumi_fb*1000.*h1_mc_mmm->Integral(); float mme = lumi_fb*1000.*h1_mc_mme->Integral(); float eem = lumi_fb*1000.*h1_mc_eem->Integral(); float eee = lumi_fb*1000.*h1_mc_eee->Integral(); float total = mmm + mme + eem + eee; char hname[100]; sprintf( hname, "yields_mc_%d", iMC); TH1D* h1_yields_mc = new TH1D(hname, "", 4, 0., 4.); h1_yields_mc->SetBinContent( 1, mmm ); h1_yields_mc->SetBinContent( 2, mme ); h1_yields_mc->SetBinContent( 3, eem ); h1_yields_mc->SetBinContent( 4, eee ); h1_yields_mc->SetFillColor( db->get_mcFile(iMC).fillColor ); vh1_yields_mc.push_back( (TH1D*)h1_yields_mc ); stackMC->Add(h1_yields_mc, "HISTO"); if( db->get_mcFiles()[iMC].legendName=="t#bar{t} + Z" ) { s_mmm += mmm; s_mme += mme; s_eem += eem; s_eee += eee; s += total; } else { yieldsFile << db->get_mcFiles()[iMC].legendName; for( unsigned ichar=0; ichar<20-db->get_mcFiles()[iMC].legendName.size(); ++ichar ) yieldsFile << " "; yieldsFile << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", mmm, mme, eem, eee, total) << std::endl; b_mmm += mmm; b_mme += mme; b_eem += eem; b_eee += eee; b += total; } delete h1_mc_mmm; delete h1_mc_mme; delete h1_mc_eem; delete h1_mc_eee; } yieldsFile << "Total BG " << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", b_mmm, b_mme, b_eem, b_eee, b) << std::endl; yieldsFile << std::endl; yieldsFile << "Signal " << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", s_mmm, s_mme, s_eem, s_eee, s) << std::endl; yieldsFile << "s / b " << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", s_mmm/b_mmm, s_mme/b_mme, s_eem/b_eem, s_eee/b_eee, s/b) << std::endl; yieldsFile << "s / sqrt(b) " << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", s_mmm/sqrt(b_mmm), s_mme/sqrt(b_mme), s_eem/sqrt(b_eem), s_eee/sqrt(b_eee), s/sqrt(b)) << std::endl; yieldsFile.close(); for( unsigned i=0; i<db->get_mcFiles().size(); ++i) { int inverseIndex = db->get_mcFiles().size()-i-1; if( vh1_yields_mc[inverseIndex]->Integral()>0 ) legend->AddEntry( vh1_yields_mc[inverseIndex], db->get_mcFile(i).legendName.c_str(), "F" ); } float yMax = stackMC->GetMaximum(); yMax *= 2.2; TH2D* h2_axes = new TH2D("axes", "", 4, 0., 4., 10, 0., yMax); h2_axes->GetXaxis()->SetLabelSize(0.085); h2_axes->GetXaxis()->SetBinLabel(1, "(#mu#mu)#mu"); h2_axes->GetXaxis()->SetBinLabel(2, "(#mu#mu)e"); h2_axes->GetXaxis()->SetBinLabel(3, "(ee)#mu"); h2_axes->GetXaxis()->SetBinLabel(4, "(ee)e"); h2_axes->SetYTitle("Events"); TPaveText* label_sqrt = db->get_labelSqrt(); TCanvas* c1 = new TCanvas("c1", "", 600, 600); c1->cd(); h2_axes->Draw(); stackMC->Draw("histo same"); legend->Draw("same"); label_sqrt->Draw("same"); gPad->RedrawAxis(); char canvasName[500]; if( saveName!="" ) sprintf( canvasName, "%s/channelYields_%s.eps", db->get_outputdir().c_str(), saveName.c_str() ); else sprintf( canvasName, "%s/channelYields.eps", db->get_outputdir().c_str() ); c1->SaveAs(canvasName); delete c1; delete h2_axes; for( unsigned i=0; i<vh1_yields_mc.size(); ++i ) delete vh1_yields_mc[vh1_yields_mc.size()-i-1]; }
void HistogramPlotter::makePlot(std::map<std::string, TH1F*> plotMap, std::string plotName, std::string subLabel, std::vector<std::string> xAxisLabels){ std::cerr << "Making a plot called: " << plotName << std::endl; //Make the legend. This is clearly the first thing I should do. TLegend legend_ = TLegend(0.7,0.7,0.94,0.94); legend_.SetFillStyle(1001); legend_.SetBorderSize(1); legend_.SetFillColor(kWhite); for (std::vector<std::string>::iterator leg_iter = legOrder_.begin(); leg_iter != legOrder_.end(); leg_iter++){ legend_.AddEntry(plotMap[*leg_iter], dsetMap_[*leg_iter].legLabel.c_str(), dsetMap_[*leg_iter].legType.c_str()); } //Initialise the stack THStack mcStack = THStack(plotName.c_str(),plotName.c_str()); //Do a few colour changing things and add MC to the stack. for (std::vector<std::string>::reverse_iterator plot_iter = plotOrder_.rbegin(); plot_iter != plotOrder_.rend(); plot_iter++){ plotMap[*plot_iter]->SetFillColor(dsetMap_[*plot_iter].colour); plotMap[*plot_iter]->SetLineColor(kBlack); plotMap[*plot_iter]->SetLineWidth(1); if( *plot_iter == "data"){ plotMap["data"]->SetMarkerStyle(20); plotMap["data"]->SetMarkerSize(1.2); plotMap["data"]->SetMarkerColor(kBlack); continue; } mcStack.Add(plotMap[*plot_iter]); } TCanvas * canvy = new TCanvas((plotName + subLabel + postfix_).c_str(), (plotName + subLabel + postfix_).c_str()); canvy->cd(); mcStack.Draw(""); if (xAxisLabels.size() > 0){ for (unsigned int i = 1; i <= xAxisLabels.size(); i++){ mcStack.GetXaxis()->SetBinLabel(i,xAxisLabels[i-1].c_str()); } } setLabelThree(subLabel); //labelThree_->Draw(); // labelTwo_->Draw(); // labelOne_->Draw(); float max = mcStack.GetMaximum(); if (plotMap.find("data") != plotMap.end()){ max = TMath::Max(mcStack.GetMaximum(),plotMap["data"]->GetMaximum()); plotMap["data"]->Draw("e x0, same"); } mcStack.SetMaximum(max*1.3); legend_.Draw(); // Save the plots. for (unsigned int ext_it = 0; ext_it < extensions_.size(); ext_it++){ canvy->SaveAs((outputFolder_ + plotName + subLabel + postfix_ + extensions_[ext_it]).c_str()); } //Make log plots canvy->SetLogy(); mcStack.SetMaximum(max*10); //Save the log plots for (unsigned int ext_it = 0; ext_it < extensions_.size(); ext_it++){ canvy->SaveAs((outputFolder_ + plotName + subLabel + postfix_ + "_log" + extensions_[ext_it]).c_str()); } delete canvy; }
void browseStacks( bool makePictures=false, bool wait=true , bool addHistName = false, Double_t maxYScaleF = 1., bool logScale = false, bool setMinZero = true) { gStyle->SetOptTitle(0); bool keep2D=false; //fix the hNJet histos TList *list = gDirectory->GetList(); TIterator *iter = list->MakeIterator(); TObject *obj = 0; while(obj = iter->Next()) { if(TString(obj->GetName()).Contains("hnJet") && obj->InheritsFrom(TH1::Class())) { int nbins = ((TH1F*)obj)->GetNbinsX(); float overflow = ((TH1F*)obj)->GetBinContent(nbins+1); float lastbinval = ((TH1F*)obj)->GetBinContent(nbins); ((TH1F*)obj)->SetBinContent(nbins, overflow+lastbinval); ((TH1F*)obj)->GetXaxis()->SetBinLabel(nbins, "#geq4"); } } // Find out what the names of the existing histograms are // The histogram names are XX_YY_ZZ, where XX is the sample, // eg, "tt", YY is the actual name, ZZ is the final state, eg, "ee" TObjArray* myNames = getMyHistosNames("ttdil","ee",keep2D); // Now loop over histograms, and make stacks TCanvas *c = new TCanvas(); c->Divide(2,2); char* suffix[4]; suffix[0] = "ee"; suffix[1] = "mm"; suffix[2] = "em"; suffix[3] = "all"; if (makePictures) c->Print("out/stacks.ps["); for (int i=0; i<myNames->GetEntries(); i++) { for (int sample=0; sample<4; sample++) { hist::stack(Form("st_%s_%s",myNames->At(i)->GetName(),suffix[sample]), Form("%s_%s$",myNames->At(i)->GetName(), suffix[sample])); THStack* thisStack = (THStack*) gROOT->FindObjectAny( Form("st_%s_%s", myNames->At(i)->GetName(), suffix[sample])); thisStack->SetMaximum(thisStack->GetMaximum()*maxYScaleF); if(TString(myNames->At(i)->GetName()).Contains("hnJet")) { TList* histolist = thisStack->GetHists(); int hatchcount = 0; // for(int j = 0; j<histolist->GetSize();j++) { // if(TString(histolist->At(j)->GetName()).Contains("tt") || // TString(histolist->At(j)->GetName()).Contains("tautau") || // TString(histolist->At(j)->GetName()).Contains("ww") ) continue; // hatch(histolist->At(j)->GetName(), FavoriteHatches[hatchcount]); // hatchcount++; // } } TLegend* thisLeg = hist::legend(thisStack, "lpf", 0, 0, 0.75, 0.65, 0.99, 0.99); c->cd(sample+1); if (logScale) gPad->SetLogy(); else gPad->SetLogy(0); double stackMax = ((TH1*)thisStack->GetHists()->At(0))->GetMaximum(); double stackMin = ((TH1*)thisStack->GetHists()->At(0))->GetMinimum(); thisStack->SetMinimum(stackMin); if (setMinZero) thisStack->SetMinimum(0); if (logScale && stackMin <=0) thisStack->SetMinimum(1e-2*stackMax); if (logScale && stackMax == 0) thisStack->SetMinimum(1e-12); thisStack->Draw("hist"); string xtitle( ((TH1*)gROOT->FindObjectAny(Form("ttdil_%s_%s", myNames->At(i)->GetName(), suffix[sample])))->GetXaxis()->GetTitle()); string ytitle( ((TH1*)gROOT->FindObjectAny(Form("ttdil_%s_%s", myNames->At(i)->GetName(), suffix[sample])))->GetYaxis()->GetTitle()); thisStack->GetXaxis()->SetTitle(xtitle.c_str()); thisStack->GetYaxis()->SetTitle(ytitle.c_str()); TString hname = thisStack->GetName(); if(hname.Contains("hnJet")) { thisStack->GetXaxis()->SetLabelSize(0.075); thisStack->GetYaxis()->SetLabelSize(0.05); thisStack->GetXaxis()->SetTitle("N_{jets}"); } thisLeg->Draw(); TPaveText *pt1 = new TPaveText(0.1, 0.95, 0.4, 0.999, "brNDC"); pt1->SetName("pt1name"); pt1->SetBorderSize(0); pt1->SetFillStyle(0); TText *blah; if (addHistName) blah = pt1->AddText(hname); else blah = pt1->AddText("CMS Preliminary"); blah->SetTextSize(0.05); pt1->Draw(); c->Modified(); c->Update(); } if (makePictures) { c->Print("out/stacks.ps"); // c->Print(Form("out/stacks_%d.png",i+1)); //c->Print(Form("out/stacks_%s.png",myNames->At(i)->GetName())); c->Print(Form("out/stacks_%s.eps",myNames->At(i)->GetName())); } if (wait) { cout << "Enter carriage return for the next set of plots....q to quit" << endl; char in = getchar(); if (in == 'q') break; } } if (makePictures) c->Print("out/stacks.ps]"); }
void AllInOne_combineLepton(const std::string& dataset,int btag=0, double timesX=1, bool useNewShape=false){ std::string useNewShapeText = (useNewShape) ? "_newshape" : ""; char wsFileName[700]; sprintf(wsFileName,"datacards/400/hzz2l2q_ee%db.input.root",btag); //sprintf(wsFileName,"PROVA/datacards_%s%s/hzz2l2q_ee%db.input.root",dataset.c_str(), useNewShapeText.c_str(),btag); gSystem->Load("libRooFit"); gSystem->Load("libFFTW"); string histoName[3]; histoName[0]="mZZ_kinfit_hiMass_0btag"; histoName[1]="mZZ_kinfit_hiMass_1btag"; histoName[2]="mZZ_kinfit_hiMass_2btag"; string btagName[3]={"0b","1b","2b"}; double LumiScale=0.; if( dataset=="Run2011A_FULL" ) LumiScale = 2100.; else if( dataset=="LP11" ) LumiScale = 1600.; else { std::cout << "Unknown dataset '" << dataset << "'. Exiting." << std::endl; } RooDataSet *data_bkg; RooDataSet *data_temp; TFile *file; string cutString[3]; cutString[0]="nBTags==0 && (mZjj>75 && mZjj<105) && mZZ>183"; cutString[1]="nBTags==1 && (mZjj>75 && mZjj<105) && mZZ>183"; cutString[2]="nBTags==2 && (mZjj>75 && mZjj<105) && mZZ>183"; int binWidth=20; int highBin=750; int lowBin=150; //double muonEff[3]={.576,.548,.489}; //double expSig[3]; //expSig[0]=5.65*LumiScale ; //expSig[1]=4.89*LumiScale ; //expSig[2]=2.37*LumiScale ; char alphaFileName[200]; sprintf( alphaFileName, "alphaFile_%s_%dbtag_ALL.root", dataset.c_str(), btag); TFile* alphaFile = TFile::Open(alphaFileName); TTree* treeSidebandsDATA_alphaCorr = (TTree*)alphaFile->Get("sidebandsDATA_alpha"); TH1D* h1_mZZ_sidebands_alpha = new TH1D("mZZ_sidebands_alpha", "", 65, 150., 800.); char sidebandsCut_alpha[500]; sprintf(sidebandsCut_alpha, "eventWeight_alpha*(isSidebands && nBTags==%d)", btag); treeSidebandsDATA_alphaCorr->Project("mZZ_sidebands_alpha", "mZZ", sidebandsCut_alpha); float expBkg = h1_mZZ_sidebands_alpha->Integral(); std::cout << "++++ expBkg: " << expBkg << std::endl; stringstream convert; // --------------------- measurable (ZZ invariant mass) ---------------- string temp; temp="m_{ZZ}"; RooRealVar mZZ("mZZ",temp.c_str(),lowBin,highBin); RooRealVar nBTags("nBTags","nBTags",-1.,3.); RooRealVar leptType("leptType","leptType",0,1); RooRealVar mZjj("mZjj","mZjj",0,200.); // ----------------- get parameters from data cards! ----------------- TFile *wsFile = new TFile(wsFileName); RooWorkspace *ws = (RooWorkspace*) wsFile->Get("w"); // ==================== defining bkg PDF ========================== // ------------------------ fermi ------------------------------ RooRealVar cutOff("cutOff","position of fermi",ws->var("cutOff_BKG")->getVal()); cutOff.setConstant(kTRUE); RooRealVar beta("beta","width of fermi",ws->var("beta_BKG")->getVal()); beta.setConstant(kTRUE); RooFermi fermi("fermi","fermi function",mZZ,cutOff,beta); // -------------------- double gauss --------------------------- temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p1"; RooRealVar m("m","m",ws->var(temp.c_str())->getVal()); m.setConstant(kTRUE); temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p2"; RooRealVar wdth("wdth","wdth",ws->var(temp.c_str())->getVal()); wdth.setConstant(kTRUE); temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p3"; RooRealVar n("n","n",ws->var(temp.c_str())->getVal()); n.setConstant(kTRUE); temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p4"; RooRealVar alpha("alpha","alpha",ws->var(temp.c_str())->getVal()); alpha.setConstant(kTRUE); temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p5"; RooRealVar theta("theta","theta",ws->var(temp.c_str())->getVal()); theta.setConstant(kTRUE); RooCB CB("CB","Crystal ball",mZZ,m,wdth,alpha,n,theta); RooProdPdf background("background","background",RooArgSet(fermi,CB)); // ------------------ get data -------------------------- // for reading sideband extrapolated data... std::string fileName = "HZZlljjRM_DATA_" + dataset + "_optLD_looseBTags_v2_ALL.root"; file = new TFile(fileName.c_str()); //file = new TFile("../HZZlljjRM_DATA_Run2011A_FULL_optLD_looseBTags_v2_ALL.root"); TTree* t=(TTree*)file->Get("tree_passedEvents"); data_bkg=new RooDataSet("data_bkg","data_bkg",t, RooArgSet(mZZ,leptType,nBTags,mZjj), cutString[btag].c_str()); // --------- draw MC data ------------------- RooPlot *plot_MCbkg = mZZ.frame(lowBin,highBin,(int)(highBin-lowBin)/binWidth); //----------------------------------------------------------------------- TCanvas *c2 = new TCanvas("c2","c2",600,600); TPaveText* cmslabel = new TPaveText( 0.145, 0.953, 0.6, 0.975, "brNDC" ); cmslabel->SetFillColor(kWhite); cmslabel->SetTextSize(0.038); cmslabel->SetTextAlign(11); cmslabel->SetTextFont(62); cmslabel->SetBorderSize(0); char lumilabel[500]; sprintf( lumilabel, "CMS Preliminary 2011, %.1f fb^{-1}", LumiScale/1000.); cmslabel->AddText(lumilabel); TPaveText* label_sqrt = new TPaveText(0.7,0.953,0.96,0.975, "brNDC"); label_sqrt->SetFillColor(kWhite); label_sqrt->SetTextSize(0.038); label_sqrt->SetTextFont(42); label_sqrt->SetTextAlign(31); // align right label_sqrt->SetBorderSize(0); label_sqrt->AddText("#sqrt{s} = 7 TeV"); //----------------------------------------------------------------------- background.plotOn(plot_MCbkg,Normalization(expBkg)); data_bkg->plotOn(plot_MCbkg,Binning((int)(highBin-lowBin)/binWidth)); // -------------------- get histograms ----------------- TFile *ZjetsFile = new TFile("HZZlljjRM_DYJetsToLL_TuneZ2_M-50_7TeV-madgraph-tauola_Summer11-PU_S4_START42_V11-v1_optLD_looseBTags_v2_ALL.root"); TFile *TTFile = new TFile("HZZlljjRM_TT_TW_TuneZ2_7TeV-powheg-tauola_Summer11-PU_S4_START42_V11-v1_optLD_looseBTags_v2_ALL.root"); TFile *VVFile = new TFile("HZZlljjRM_VV_TuneZ2_7TeV-pythia6-tauola_Summer11-PU_S4_START42_V11-v1_optLD_looseBTags_v2_ALL.root"); TFile *H400File = new TFile("HZZlljjRM_GluGluToHToZZTo2L2Q_M-400_7TeV-powheg-pythia6_Summer11-PU_S4_START42_V11-v1_optLD_looseBTags_v2_ALL.root"); TH1F *hZjets =(TH1F*)ZjetsFile->Get(histoName[btag].c_str()); hZjets->SetName("hZjets"); hZjets->Scale(LumiScale); hZjets->Rebin(binWidth); hZjets->SetFillColor(30); TH1F *hTT =(TH1F*)TTFile->Get(histoName[btag].c_str()); hTT->SetName("hTT"); convert << binWidth; temp=";m_{ZZ} [GeV]; Events / "+convert.str()+" GeV"; hTT->SetTitle(temp.c_str()); hTT->Scale(LumiScale); hTT->Rebin(binWidth); hTT->SetFillColor(39); gStyle->SetOptStat(0); //if(btag==0) // hTT->GetYaxis()->SetRangeUser(0.0001,245); //if(btag==1) // hTT->GetYaxis()->SetRangeUser(0.0001,245); //if(btag==2) // hTT->GetYaxis()->SetRangeUser(0.0001,25); //hTT->Draw(); TH1F *hVV =(TH1F*)VVFile->Get(histoName[btag].c_str()); hVV->SetName("hVV"); hVV->Scale(LumiScale); hVV->Rebin(binWidth); hVV->SetFillColor(38); TH1F* hH400 = (TH1F*)H400File->Get(histoName[btag].c_str()); hH400->SetName("hH400"); hH400->Scale(LumiScale*timesX); cout << "SIGNAL NORMALIZATION: " << hH400->Integral() << endl; hH400->Rebin(binWidth); hH400->SetFillColor(kYellow);//kRed+3); temp = ";m_{ZZ} [GeV];Events / "+convert.str()+" GeV"; THStack *hBkg = new THStack("hBkg",temp.c_str()); convert.str(""); hBkg->Add(hVV); hBkg->Add(hTT); hBkg->Add(hZjets); hBkg->Add(hH400); float xMin = 150.; float xMax = 750.; float yMin = 0.; float yMax = 1.3*hBkg->GetMaximum(); char yAxisName[500]; sprintf( yAxisName, "Events / %.0f GeV", hVV->GetXaxis()->GetBinWidth(1) ); //std::string yAxisName = "Events / "+convert.str()+" GeV"; convert.str(""); //char xAxisName[400]; //sprintf( xAxisName, "m_{%s%sjj} [GeV]", leptType_forLegend.c_str(), leptType_forLegend.c_str() ); TH2D* h2_axes = new TH2D("axes", "", 10, xMin, xMax, 10, yMin, yMax); h2_axes->SetXTitle("m_{lljj} [GeV]"); h2_axes->SetYTitle(yAxisName); h2_axes->Draw(); hBkg->Draw("SAMEHIST"); plot_MCbkg->Draw("SAME"); cmslabel->Draw(); label_sqrt->Draw(); // ---------------legend --------------------------- TLegend *leg = new TLegend(.4,.5,.8,.9); leg->SetTextSize(0.036); leg->SetFillColor(0); leg->SetBorderSize(0); convert.str(""); convert << LumiScale/1000; temp="CMS Preliminary #sqrt{s}=7 TeV "+convert.str()+" fb^{-1}"; //leg->SetHeader(temp.c_str()); leg->AddEntry("background_Norm[mZZ]","Sideband Extrapolated Fit","l"); //leg->AddEntry("model_Norm[mZZ]","Background+10#timesSignal","l"); if(btag==0) temp="0 b-tag 2l2q data"; if(btag==1) temp="1 b-tag 2l2q data"; if(btag==2) temp="2 b-tag 2l2q data"; leg->AddEntry("h_data_bkg",temp.c_str(),"p"); leg->AddEntry("hZjets","Z + Jets","f"); leg->AddEntry("hTT","tt/tW","f"); leg->AddEntry("hVV","ZZ/WZ/WW","f"); convert.str(""); convert << timesX; temp="400 GeV SM Higgs#times"+convert.str(); leg->AddEntry("hH400",temp.c_str(),"f"); leg->Draw(); string saveFileName="AllInOne_"+dataset + "_"+btagName[btag]+"tag_ll_LIMIT" + useNewShapeText + ".eps"; c2->SaveAs(saveFileName.c_str()); }
//void VHPlotter(string title="", int plot=0) { void VHPlotter(string title="", int plot=0, TCanvas* c1=0 ) { string subdir="0"; string postfix=""; string dirbSel=""; double norm11 = ((Lumi2016_ele * Xsec_dy_amc1) / Ngen_dy_amc1); double norm12 = ((Lumi2016_ele * Xsec_dy_amc2) / Ngen_dy_amc2); double norm13 = ((Lumi2016_ele * Xsec_dy_amc3) / Ngen_dy_amc3); double norm14 = ((Lumi2016_ele * Xsec_dy_amc4) / Ngen_dy_amc4); double norm2 = ((Lumi2016_ele * Xsec_tt) / Ngen_tt); double norm3 = ((Lumi2016_ele * Xsec_zz) / Ngen_zz); double norm4 = ((Lumi2016_ele * Xsec_wz) / Ngen_wz); double norm6 = ((Lumi2016_ele * Xsec_ww) / Ngen_ww); double norm7 = ((Lumi2016_ele * Xsec_zhm) / Ngen_zhm); double norm8 = ((Lumi2016_ele * Xsec_zhp) / Ngen_zhp); //if (ilepton==1) Lumi2016 = Lumi2016_ele; /*double enorm1 = ((Lumi2012 * eXsec_dy) / Ngen_dy); double enorm1_amc = ((Lumi2012 * eXsec_dy_amc) / Ngen_dy_amc); double enorm1_1 = ((Lumi2012 * eXsec_dy_1) / Ngen_dy_1); double enorm1_2=0; double enorm2 = ((Lumi2012 * eXsec_tt) / Ngen_tt); double enorm4 = ((Lumi2012 * eXsec_wz) / Ngen_wz); double enorm5 = ((Lumi2012 * eXsec_qcd) / Ngen_qcd); double enorm6 = ((Lumi2012 * eXsec_ww) / Ngen_ww); double enorm7 = ((Lumi2012 * eXsec_wj) / Ngen_wj); double enorm8 = ((Lumi2012 * eXsec_tS) / Ngen_tS); double enorm9 = ((Lumi2012 * eXsec_tT) / Ngen_tT); double enorm10 = ((Lumi2012 * eXsec_tW) / Ngen_tW); double enorm11 = ((Lumi2012 * eXsec_tSb) / Ngen_tSb); double enorm12 = ((Lumi2012 * eXsec_tTb) / Ngen_tTb); double enorm13 = ((Lumi2012 * eXsec_tWb) / Ngen_tWb); */ TFile* mc11 = TFile::Open((path + "DYJetsToLL_M-50_HT-100to200_13TeV.root").c_str()); TH1F* h_mc11 = (TH1F*)gDirectory->Get(title.c_str()); TFile* mc12 = TFile::Open((path + "DYJetsToLL_M-50_HT-200to400_13TeV.root").c_str()); TH1F* h_mc12 = (TH1F*)gDirectory->Get(title.c_str()); TFile* mc13 = TFile::Open((path + "DYJetsToLL_M-50_HT-400to600_13TeV.root").c_str()); TH1F* h_mc13 = (TH1F*)gDirectory->Get(title.c_str()); TFile* mc14 = TFile::Open((path + "DYJetsToLL_M-50_HT-600toInf_13TeV.root").c_str()); TH1F* h_mc14 = (TH1F*)gDirectory->Get(title.c_str()); TFile* mc2 = TFile::Open((path + "TT_TuneCUETP8M1_13TeV.root").c_str()); TH1F* h_mc2 = (TH1F*)gDirectory->Get(title.c_str()); TFile* mc3 = TFile::Open((path + "ZZ_TuneCUETP8M1_13TeV.root").c_str()); TH1F* h_mc3 = (TH1F*)gDirectory->Get(title.c_str()); TFile* mc4 = TFile::Open((path + "WZ_TuneCUETP8M1_13TeV.root").c_str()); TH1F* h_mc4 = (TH1F*)gDirectory->Get(title.c_str()); TFile* mc6 = TFile::Open((path + "WW_TuneCUETP8M1_13TeV.root").c_str()); TH1F* h_mc6 = (TH1F*)gDirectory->Get(title.c_str()); TFile* mc7 = TFile::Open((path + "ZH_HToBB_ZToLL_M125_13TeV_amcatnlo.root").c_str()); TH1F* h_mc7 = (TH1F*)gDirectory->Get(title.c_str()); TFile* mc8 = TFile::Open((path + "ZH_HToBB_ZToLL_M125_13TeV_powheg.root").c_str()); TH1F* h_mc8 = (TH1F*)gDirectory->Get(title.c_str()); //TFile* data = TFile::Open((path + "SingleElectron-Run2016B-v2.root").c_str());; //TH1F* h_data = (TH1F*)gDirectory->Get(title.c_str()); TFile* data_runB = TFile::Open((path + "SingleElectron-Run2016B-v2.root").c_str()); TH1F* h_data_runB = (TH1F*)gDirectory->Get(title.c_str()); TFile* data_runC = TFile::Open((path + "SingleElectron-Run2016C-v2.root").c_str()); TH1F* h_data_runC = (TH1F*)gDirectory->Get(title.c_str()); TFile* data_runD = TFile::Open((path + "SingleElectron-Run2016D-v2.root").c_str()); TH1F* h_data_runD = (TH1F*)gDirectory->Get(title.c_str()); TH1F* h_data = (TH1F*)h_data_runB ->Clone("h_data"); h_data->Reset(); h_data->Add( h_data_runB ); h_data->Add( h_data_runC ); h_data->Add( h_data_runD ); h_mc2 -> SetLineColor(kBlack); h_mc2 -> SetFillColor(kBlue); //h_mc2 -> SetFillStyle(3004); h_mc3 -> SetLineColor(kBlack); h_mc3 -> SetFillColor(kGray+2); //h_mc3 -> SetFillStyle(3004); //h_mc4 -> SetLineColor(kBlack); //h_mc4 -> SetFillColor(kGray+3); //h_mc4 -> SetFillStyle(3004); //h_mc6 -> SetLineColor(kBlack); //h_mc6 -> SetFillColor(kRed+2); //h_mc6 -> SetFillStyle(3004); h_mc7 -> SetLineColor(kBlack); h_mc7 -> SetFillColor(kMagenta); //h_mc7 -> SetFillStyle(3004); h_mc8 -> SetLineColor(kGreen); //h_mc8 -> SetLineColor(kBlack); //h_mc8 -> SetFillColor(kPink); //h_mc8 -> SetFillStyle(3004); h_mc8 ->SetLineWidth(3); h_mc11->Scale(norm11); h_mc12->Scale(norm12); h_mc13->Scale(norm13); h_mc14->Scale(norm14); h_mc2->Scale(norm2); h_mc3->Scale(norm3); h_mc4->Scale(norm4); h_mc6->Scale(norm6); h_mc7->Scale(norm7); h_mc8->Scale(norm8); TH1F* h_mcDY = (TH1F*)h_mc11->Clone("h_mcDY"); h_mcDY->Reset(); h_mcDY->Add(h_mc14); h_mcDY->Add(h_mc13); h_mcDY->Add(h_mc12); h_mcDY->Add(h_mc11); h_mcDY -> SetLineColor(kBlack); h_mcDY -> SetFillColor(kYellow-4); //h_mcDY -> SetFillStyle(3004); TH1F* h_mcDiboson = (TH1F*)h_mc3->Clone("h_mcDiboson"); h_mcDiboson->Reset(); h_mcDiboson->Add(h_mc3); h_mcDiboson->Add(h_mc4); h_mcDiboson->Add(h_mc6); TH1F *ht = (TH1F*)h_mcDY->Clone("ht"); ht->Reset(); //ht->Add(h_mc8); ht->Add(h_mc7); //ht->Add(h_mc6); //ht->Add(h_mc4); //ht->Add(h_mc3); ht->Add(h_mcDiboson); ht->Add(h_mc2); ht->Add(h_mcDY); THStack *hs = new THStack("hs",""); //hs->Add(h_mc8); // ZH powheg hs->Add(h_mc7); // ZH madgraph //hs->Add(h_mc6); //hs->Add(h_mc4); //hs->Add(h_mc3); hs->Add(h_mcDiboson); hs->Add(h_mc2); hs->Add(h_mcDY); //TCanvas* c1 = 0; //c1 = new TCanvas("c","c",10,10,800,600); c1->cd(); TPad *pad1 = new TPad("pad1","pad1",0.0,0.3,1.0,1.0); pad1->SetBottomMargin(0.001); pad1->Draw(); pad1->cd(); if( title=="FATjetSDmass" || title=="FATjetSDmassCorr" || title=="FATjetPRmass" || title=="FATjetPRmassCorr" || title=="FATnSubjet" || title=="ZHmass" ) { pad1->SetLogy(); } hs->Draw("HIST"); hs->GetYaxis()->SetTitle("Events"); hs->GetYaxis()->SetTitleSize(0.05); hs->GetYaxis()->SetLabelSize(0.045); hs->GetYaxis()->SetTitleOffset(1.0);// 0.7 //hs->SetMinimum(8); hs->SetMinimum(0.1); hs->SetMaximum(1.2*hs->GetMaximum()); if (title=="ZHmass") { hs->GetXaxis()->SetRangeUser(0, 3000); } h_mc8->Draw("same hist"); h_data->Draw("EPX0SAMES"); h_data->SetMarkerColor(kBlack); h_data->SetMarkerStyle(20); h_data->SetMarkerSize (1.0); h_data->SetStats(0); TLegend *leg; if (title=="FATjetTau2dvTau1") { leg = new TLegend(0.15, 0.547, 0.41, 0.88); } else { leg = new TLegend(0.65, 0.547, 0.91, 0.88); } //leg = new TLegend(0.65, 0.547, 0.91, 0.88); leg->SetBorderSize(0); leg->SetEntrySeparation(0.01); leg->SetFillColor(0); leg->SetFillStyle(0); leg->AddEntry(h_data,"Data","p"); leg->AddEntry(h_mcDY,"DY","f"); leg->AddEntry(h_mc2,"t#bar{t}","f"); //leg->AddEntry(h_mc3,"ZZ","f"); //leg->AddEntry(h_mc4,"WZ","f"); //leg->AddEntry(h_mc6,"WW","f"); leg->AddEntry(h_mcDiboson,"Diboson","f"); leg->AddEntry(h_mc7,"ZH madgraph","f"); leg->AddEntry(h_mc8,"ZH powheg (not in stack)","f"); leg->Draw(); TLatex *lar = new TLatex(); lar->SetNDC(kTRUE); lar->SetTextSize(0.04); lar->SetLineWidth(5); lar->DrawLatex(0.14, 0.94, "CMS #it{#bf{2016}}"); lar->DrawLatex(0.60, 0.94, "L = 12.7 fb^{-1} at #sqrt{s} = 13 TeV"); pad1->Update(); c1->Update(); c1->cd(); TH1F *h_ratio = (TH1F*)h_data->Clone("h_ratio"); TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);// 0.3 pad2->SetTopMargin(0); pad2->SetBottomMargin(0.3); pad2->Draw(); pad2->cd(); h_ratio->SetTitle(""); h_ratio->SetStats(0); if (title=="Zpt") { h_ratio->GetXaxis ()->SetTitle("p_{T}(Z) [GeV/c]"); } else if (title=="Zmass") { h_ratio->GetXaxis ()->SetTitle("M(Z) [GeV/c^{2}]");// } else if (title=="ZRapidity") { h_ratio->GetXaxis ()->SetTitle("y(Z)"); } else if (title=="Zeta") { h_ratio->GetXaxis ()->SetTitle("#eta(Z)"); } else if (title=="nVtx") { h_ratio->GetXaxis ()->SetTitle("Number of Vertices"); } else if (title=="leadElePt") { h_ratio->GetXaxis ()->SetTitle("Leading Electron p_{T} [GeV/c]"); } else if (title=="subleadElePt") { h_ratio->GetXaxis ()->SetTitle("Sub-Leading Electron p_{T} [GeV/c]"); } else if (title=="leadEleEta") { h_ratio->GetXaxis ()->SetTitle("Leading Electron #eta"); } else if (title=="subleadEleEta") { h_ratio->GetXaxis ()->SetTitle("Sub-Leading Electron #eta"); } else if (title=="FATjetPt") { h_ratio->GetXaxis ()->SetTitle("FAT Jet p_{T} [GeV/c]"); } else if (title=="FATjetEta") { h_ratio->GetXaxis ()->SetTitle("FAT Jet #eta"); } else if (title=="FATjetCISVV2") { h_ratio->GetXaxis ()->SetTitle("FAT Jet CSVv2"); } else if (title=="FATjetSDmass") { h_ratio->GetXaxis ()->SetTitle("FAT Jet Soft Drop Mass [GeV/c^{2}]"); } else if (title=="FATjetSDmassCorr") { h_ratio->GetXaxis ()->SetTitle("FAT Jet Corrected Soft Drop Mass [GeV/c^{2}]"); } else if (title=="FATjetPRmass") { h_ratio->GetXaxis ()->SetTitle("FAT Jet Pruned Mass [GeV/c^{2}]"); } else if (title=="FATjetPRmassCorr") { h_ratio->GetXaxis ()->SetTitle("FAT Jet L2L3 Corrected Pruned Mass [GeV/c^{2}]"); } else if (title=="FATjetTau1") { h_ratio->GetXaxis ()->SetTitle("FAT Jet #tau_{1}"); } else if (title=="FATjetTau2") { h_ratio->GetXaxis ()->SetTitle("FAT Jet #tau_{2}"); } else if (title=="FATjetTau2dvTau1") { h_ratio->GetXaxis ()->SetTitle("FAT Jet #tau_{21}"); } else if (title=="FATnSubjet") { h_ratio->GetXaxis ()->SetTitle("Number of Subjets"); } else if (title=="FATsubjetLeadingPt") { h_ratio->GetXaxis ()->SetTitle("Leading SubJet p_{T} [GeV/c]"); } else if (title=="FATsubjetLeadingEta") { h_ratio->GetXaxis ()->SetTitle("Leading SubJet #eta"); } else if (title=="FATsubjetLeadingSDCSV") { h_ratio->GetXaxis ()->SetTitle("Leading SubJet Soft Drop CSV"); } else if (title=="FATsubjetSubLeadingPt") { h_ratio->GetXaxis ()->SetTitle("Sub-Leading SubJet p_{T} [GeV/c]"); } else if (title=="FATsubjetSubLeadingEta") { h_ratio->GetXaxis ()->SetTitle("Sub-Leading SubJet #eta"); } else if (title=="FATsubjetSubLeadingSDCSV") { h_ratio->GetXaxis ()->SetTitle("Sub-Leading SubJet Soft Drop CSV"); } else if (title=="ADDjet_DoubleSV") { h_ratio->GetXaxis ()->SetTitle("ADDjet double b-tagger discriminator"); } else if (title=="ZHmass") { h_ratio->GetXaxis ()->SetTitle("ZH invariant mass [GeV/c^{2}]"); } if (title=="ZHmass") { h_ratio->GetXaxis()->SetRangeUser(0, 3000); } h_ratio->GetXaxis()->SetTitleSize(0.11); h_ratio->GetXaxis()->SetLabelFont(42); h_ratio->GetXaxis()->SetLabelSize(0.10); h_ratio->GetXaxis()->SetTitleFont(42); h_ratio->GetYaxis()->SetTitle("Data/MC"); h_ratio->GetYaxis()->SetNdivisions(505); h_ratio->GetYaxis()->SetTitleSize(0.11); h_ratio->GetYaxis()->SetLabelSize(0.10); h_ratio->GetYaxis()->SetRangeUser(0.2, 2); h_ratio->GetYaxis()->SetTitleOffset(0.33); h_ratio->Divide(ht); h_ratio->SetMarkerStyle(20); h_ratio->Draw("E0PX0"); TLine *OLine = new TLine(h_ratio->GetXaxis()->GetXmin(),1.,h_ratio->GetXaxis()->GetXmax(),1.); OLine->SetLineColor(kRed); OLine->SetLineWidth(2); OLine->Draw(); /* TLatex *lar = new TLatex(); lar->SetNDC(kTRUE); lar->SetTextSize(0.04); lar->SetLineWidth(5); lar->DrawLatex(0.14, 0.94, "CMS #it{#bf{2016}}"); lar->DrawLatex(0.60, 0.94, "L = 4.327 fb^{-1} at #sqrt{s} = 13 TeV"); */ c1->cd(); //c1->SaveAs((path + title + ".pdf").c_str()); }
void CCProtonPi0_SideBandTool::Plot(int ind, std::string sb_name, std::string var_name, MnvH1D* data, MnvH1D* mc_total, MnvH1D* signal, MnvH1D* WithPi0, MnvH1D* QELike, MnvH1D* SinglePiPlus, MnvH1D* Other) { std::string type; if (ind == 0) type = "Nominal"; else type = "Fitted"; std::string norm = "POT"; std::string plot_title = "Side Band: " + sb_name + " " + type + " " + norm + " Normalized"; // Get Histograms -- Use new Histograms not to change originals ColorHists(data, signal, WithPi0, QELike, SinglePiPlus, Other); TH1D* h_data = new TH1D(data->GetBinNormalizedCopy().GetCVHistoWithError()); TH1D* h_signal = new TH1D(signal->GetBinNormalizedCopy().GetCVHistoWithError()); TH1D* h_WithPi0 = new TH1D(WithPi0->GetBinNormalizedCopy().GetCVHistoWithError()); TH1D* h_QELike = new TH1D(QELike->GetBinNormalizedCopy().GetCVHistoWithError()); TH1D* h_SinglePiPlus = new TH1D(SinglePiPlus->GetBinNormalizedCopy().GetCVHistoWithError()); TH1D* h_Other = new TH1D(Other->GetBinNormalizedCopy().GetCVHistoWithError()); // MC Total depend on the Modification // If Raws - take the mc_total directly // If Modified - Add all mc models; TH1D* h_mc_total; if (ind == 0){ h_mc_total = new TH1D(mc_total->GetBinNormalizedCopy().GetCVHistoWithError()); }else{ h_mc_total = new TH1D(*h_signal); h_mc_total->Add(h_WithPi0); h_mc_total->Add(h_QELike); h_mc_total->Add(h_SinglePiPlus); h_mc_total->Add(h_Other); } // Scale Histograms double mc_ratio = POT_ratio; h_mc_total->Scale(mc_ratio); h_signal->Scale(mc_ratio); h_WithPi0->Scale(mc_ratio); h_QELike->Scale(mc_ratio); h_SinglePiPlus->Scale(mc_ratio); h_Other->Scale(mc_ratio); // ------------------------------------------------------------------------ // Unique Plot for Single Error Band, Single Universe // Comment this section out // ------------------------------------------------------------------------ //std::string err_band = "GENIE_MaRES"; //int hist_ind = 1; //TH1D* h_data = new TH1D(*(data->GetVertErrorBand(err_band)->GetHist(hist_ind))); //TH1D* h_signal = new TH1D(*(signal->GetVertErrorBand(err_band)->GetHist(hist_ind))); //TH1D* h_WithPi0 = new TH1D(*(WithPi0->GetVertErrorBand(err_band)->GetHist(hist_ind))); //TH1D* h_QELike = new TH1D(*(QELike->GetVertErrorBand(err_band)->GetHist(hist_ind))); //TH1D* h_SinglePiPlus = new TH1D(*(SinglePiPlus->GetVertErrorBand(err_band)->GetHist(hist_ind))); //TH1D* h_Other = new TH1D(*(Other->GetVertErrorBand(err_band)->GetHist(hist_ind))); //TH1D* h_mc_total; //if (ind == 0){ // h_mc_total = new TH1D(*(mc_total->GetVertErrorBand(err_band)->GetHist(hist_ind))); //}else{ // h_mc_total = new TH1D(*h_signal); // h_mc_total->Add(h_WithPi0); // h_mc_total->Add(h_QELike); // h_mc_total->Add(h_SinglePiPlus); // h_mc_total->Add(h_Other); //} //ColorHists(h_data, h_signal, h_WithPi0, h_QELike, h_SinglePiPlus, h_Other); //// Scale Histograms //h_data->Scale(1,"width"); //double mc_ratio = POT_ratio; //h_mc_total->Scale(mc_ratio,"width"); //h_signal->Scale(mc_ratio,"width"); //h_WithPi0->Scale(mc_ratio,"width"); //h_QELike->Scale(mc_ratio,"width"); //h_SinglePiPlus->Scale(mc_ratio,"width"); //h_Other->Scale(mc_ratio,"width"); // ------------------------------------------------------------------------ // Create Canvas and Divide it into two TCanvas* c = new TCanvas("c","c",1280,1280); // Upper Pad is the Data vs MC TPad *pad1 = new TPad("pad1", "pad1", 0.05, 0.3, 1, 1.0); pad1->SetBottomMargin(0); // Top and Bottom Plots attached pad1->Draw(); pad1->cd(); // pad1 is the current pad // Plot MC Models as THStack THStack* hs = new THStack("hs",plot_title.c_str()); hs->Add(h_WithPi0); hs->Add(h_QELike); hs->Add(h_SinglePiPlus); hs->Add(h_Other); hs->Add(h_signal); hs->Draw("HIST"); // Styling gStyle->SetOptTitle(0); gStyle->SetOptStat(0); hs->GetYaxis()->SetTitle("N(Events)"); hs->GetYaxis()->SetTitleFont(62); hs->GetYaxis()->SetTitleSize(0.06); //hs->GetYaxis()->CenterTitle(); //hs->GetYaxis()->SetTitleOffset(1.2); hs->GetYaxis()->SetLabelFont(42); hs->GetYaxis()->SetLabelSize(0.05); double hist_max = hs->GetMaximum(); hs->SetMaximum(hist_max * 1.5); // Add Data Plot h_data->GetXaxis()->SetTitle(""); h_data->Draw("SAME E1 X0"); // Add Legend TLegend *legend = new TLegend(0.6,0.65,0.9,0.9); legend->AddEntry(h_data, "Data"); legend->AddEntry(h_signal, "Signal", "f"); legend->AddEntry(h_Other, "Bckg: Other", "f"); legend->AddEntry(h_SinglePiPlus, "Bckg: 1 #pi^{+}", "f"); legend->AddEntry(h_QELike, "Bckg: QE Like", "f"); legend->AddEntry(h_WithPi0, "Bckg: #pi^{0} + X", "f"); legend->SetTextSize(0.04); legend->SetTextFont(42); legend->Draw(); // // Add Pi0 InvMass Lines // TLine line; // line.SetLineWidth(3); // line.SetLineColor(kBlack); // // TArrow arrow; // arrow.SetLineWidth(4); // arrow.SetLineStyle(1); // arrow.SetLineColor(1); // // // Low Inv Mass Region // line.DrawLine(60.0,0,60.0,hist_max); // arrow.DrawArrow(60.0,hist_max,60-20,hist_max,0.01,">"); // // // High Inv Mass Region // line.DrawLine(200.0,0,200.0,hist_max); // arrow.DrawArrow(200.0,hist_max,200+20,hist_max,0.01,">"); // Add Weights as Text to Modified Plot if (ind != 0){ int nPars = 3; int nPoints = 136; TLatex* text = new TLatex; text->SetTextSize(0.03); text->SetNDC(); text->DrawLatex(0.55, 0.60, Form("Fit Results with %d points, %d pars", nPoints, nPars)); text->DrawLatex(0.55, 0.57, Form("Before Fit #chi^{2} = %3.2f", ChiSq_before_fit[0])); text->DrawLatex(0.55, 0.54, Form("Before Fit #chi^{2}/dof = %3.2f", ChiSq_before_fit[0]/(nPoints-nPars))); text->DrawLatex(0.55, 0.51, Form("After Fit #chi^{2} = %3.2f", ChiSq_after_fit[0])); text->DrawLatex(0.55, 0.48, Form("After Fit #chi^{2}/dof = %3.2f", ChiSq_after_fit[0]/(nPoints-nPars))); text->DrawLatex(0.55, 0.45, Form("#color[4]{wgt(ChargedPion) = %3.2f#pm %3.2f}", wgt_SinglePiPlus[0], err_SinglePiPlus[0])); text->DrawLatex(0.55, 0.42, Form("wgt(QELike) = %3.2f#pm %3.2f", wgt_QELike[0], err_QELike[0])); text->DrawLatex(0.55, 0.39, Form("#color[2]{wgt(WithPi0) = %3.2f#pm %3.2f}", wgt_WithPi0[0], err_WithPi0[0])); delete text; } // Add Plot-ChiSq TLatex* text = new TLatex; text->SetNDC(); text->SetTextSize(0.04); text->SetTextColor(kBlue); //double plot_chisq = calc_ChiSq(data, signal, WithPi0, QELike, SinglePiPlus, Other); double plot_chisq = calc_ChiSq(h_data, h_signal, h_WithPi0, h_QELike, h_SinglePiPlus, h_Other); double nPoints = h_data->GetNbinsX()-1; //text->DrawLatex(0.15, 0.85, Form("Plot #chi^{2} = %3.2f", plot_chisq)); text->DrawLatex(0.15, 0.85, Form("Plot #chi^{2}/dof = %3.2f", plot_chisq/nPoints)); delete text; // Plot Lower Plot: Data vs MC Ratio c->cd(); // Go back to default Canvas before creating 2nd Pad TPad *pad2 = new TPad("pad2", "pad2", 0.05, 0.05, 1, 0.3); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.2); pad2->Draw(); pad2->cd(); // Calculate the Ratio TH1D* h_data_mc_ratio = new TH1D(*(h_data)); h_data_mc_ratio->Divide(h_mc_total); // Style Ratio Plot h_data_mc_ratio->SetTitle(""); h_data_mc_ratio->SetLineColor(kRed); h_data_mc_ratio->SetLineWidth(3); h_data_mc_ratio->SetFillColor(kWhite); h_data_mc_ratio->SetMinimum(0.5); h_data_mc_ratio->SetMaximum(1.5); // X axis ratio plot settings //h_data_mc_ratio->GetXaxis()->SetTitle(data->GetXaxis()->GetTitle()); h_data_mc_ratio->GetXaxis()->SetTitle("#gamma#gamma Invariant Mass [MeV]"); h_data_mc_ratio->GetXaxis()->SetNdivisions(408); h_data_mc_ratio->GetXaxis()->CenterTitle(); h_data_mc_ratio->GetXaxis()->SetTitleFont(62); h_data_mc_ratio->GetXaxis()->SetTitleSize(0.18); //h_data_mc_ratio->GetXaxis()->SetTitleOffset(1.2); h_data_mc_ratio->GetXaxis()->SetLabelFont(42); // Absolute font size in pixel (precision 3) h_data_mc_ratio->GetXaxis()->SetLabelSize(0.12); // Y axis ratio plot settings h_data_mc_ratio->GetYaxis()->CenterTitle(); h_data_mc_ratio->GetYaxis()->SetNdivisions(408); h_data_mc_ratio->GetYaxis()->SetTitle("Data/MC"); h_data_mc_ratio->GetYaxis()->SetTitleFont(62); h_data_mc_ratio->GetYaxis()->SetTitleSize(0.18); h_data_mc_ratio->GetYaxis()->SetTitleOffset(0.35); h_data_mc_ratio->GetYaxis()->SetLabelFont(42); // Absolute font size in pixel (precision 3) h_data_mc_ratio->GetYaxis()->SetLabelSize(0.12); // Add Ratio Plot h_data_mc_ratio->Draw("HIST"); // Add Ratio = 1 Line TLine ratio_1; ratio_1.SetLineWidth(2); ratio_1.SetLineStyle(7); ratio_1.SetLineColor(kBlue); double line_min = h_data->GetBinLowEdge(1); double line_max = h_data->GetBinLowEdge(h_data->GetNbinsX()+1); ratio_1.DrawLine(line_min,1,line_max,1); // Plot Output c->Update(); std::string plotDir = Folder_List::plotDir_SideBand; std::string out_name; out_name = plotDir + var_name + "_" + sb_name + "_" + type + "_" + norm + ".png"; c->Print(out_name.c_str(),"png"); delete legend; delete hs; delete pad1; delete pad2; delete c; }
void plotOne(TString what) { SetPlotStyle(); bool logscale = false; TFile* f1 = new TFile("ttbar_max700.root"); TFile* f2 = new TFile("ttbar_700to1000.root"); TFile* f3 = new TFile("ttbar_1000toInf.root"); TH1F* h1 = (TH1F*) f1->Get(what); TH1F* h2 = (TH1F*) f2->Get(what); TH1F* h3 = (TH1F*) f3->Get(what); h1->Sumw2(); h2->Sumw2(); h3->Sumw2(); float ttbar_xs = 245.8; float lumi = 19.7*1000; float n_ttbar1 = 21675970.; float n_ttbar2 = 3082812.; float n_ttbar3 = 1249111.; float eff_ttbar1 = 1.0; float eff_ttbar2 = 0.074; float eff_ttbar3 = 0.015; h1->Scale(ttbar_xs*lumi*eff_ttbar1/n_ttbar1); h2->Scale(ttbar_xs*lumi*eff_ttbar2/n_ttbar2); h3->Scale(ttbar_xs*lumi*eff_ttbar3/n_ttbar3); h1->SetFillColor(kYellow-9); h2->SetFillColor(kRed); h3->SetFillColor(kMagenta+3); TH1F* h_dummy = (TH1F*) h1->Clone("dummy"); h_dummy->SetLineColor(0); h_dummy->SetFillColor(0); h_dummy->SetMarkerColor(0); h_dummy->GetYaxis()->SetTitleOffset(1.1); if (what.Contains("ttbar_mass")) { h_dummy->GetXaxis()->SetTitle("Mass(t#bar{t}) [GeV]"); h_dummy->GetYaxis()->SetTitle("Events / 10 GeV"); } else if (what.Contains("ttbar_pt")) { h_dummy->GetXaxis()->SetTitle("p_{T}(t#bar{t}) [GeV]"); h_dummy->GetYaxis()->SetTitle("Events / 5 GeV"); } else if (what.Contains("hadtop_mass")) { h_dummy->GetXaxis()->SetTitle("Mass(hadronic top) [GeV]"); h_dummy->GetYaxis()->SetTitle("Events / 1 GeV"); h_dummy->SetAxisRange(50,300,"X"); logscale = true; } else if (what.Contains("hadtop_pt")) { h_dummy->GetXaxis()->SetTitle("p_{T}(hadronic top) [GeV]"); h_dummy->GetYaxis()->SetTitle("Events / 5 GeV"); } else if (what.Contains("leptop_mass")) { h_dummy->GetXaxis()->SetTitle("Mass(leptonic top) [GeV]"); h_dummy->GetYaxis()->SetTitle("Events / 1 GeV"); h_dummy->SetAxisRange(50,300,"X"); logscale = true; } else if (what.Contains("leptop_pt")) { h_dummy->GetXaxis()->SetTitle("p_{T}(leptonic top) [GeV]"); h_dummy->GetYaxis()->SetTitle("Events / 5 GeV"); } THStack* hs = new THStack(); hs->Add(h1); hs->Add(h2); hs->Add(h3); float max = hs->GetMaximum(); if (logscale) h_dummy->SetAxisRange(1,max*1.5,"Y"); else h_dummy->SetAxisRange(0,max*1.05,"Y"); TCanvas c; if (logscale) gPad->SetLogy(); h_dummy->Draw("hist"); hs->Draw("hist,same"); h_dummy->Draw("same,axis"); TLegend* l = new TLegend(0.6,0.65,0.85,0.9); l->SetFillStyle(0); l->SetBorderSize(0); l->SetFillColor(0); l->SetTextSize(0.04); l->AddEntry(h1,"m(t#bar{t}) < 700 GeV","f"); l->AddEntry(h2,"700 < m(t#bar{t}) < 1000 GeV","f"); l->AddEntry(h3,"m(t#bar{t}) > 1000 GeV","f"); l->SetTextFont(42); l->Draw(); c.SaveAs("truth_"+what+".png"); }
void draw_from_trees(TString var, TCut other_cuts, TString weights, TString title, int nbinsx, double xlow, double xup, TString options="plotSig:plotLog:plotData", double cut_low=-1, double cut_high=-1, TString plot_title="default") { bool plotSig = options.Contains("plotSig") && (!options.Contains("!plotSig")); bool plotLog = options.Contains("plotLog") && (!options.Contains("!plotLog")); bool plotData = options.Contains("plotData") && (!options.Contains("!plotData")); bool sigStack = options.Contains("sigStack") && (!options.Contains("!sigStack")); // Book histograms TH1D * httbar = new TH1D("ttbar" , title, nbinsx, xlow, xup); TH1D * hqcd = new TH1D("qcd" , title, nbinsx, xlow, xup); TH1D * hznn = new TH1D("znn" , title, nbinsx, xlow, xup); TH1D * hwjets = new TH1D("wjets" , title, nbinsx, xlow, xup); TH1D * hother = new TH1D("other" , title, nbinsx, xlow, xup); TH1D * hmc_exp = new TH1D("mc_exp" , title, nbinsx, xlow, xup); TH1D * hsingle_top = new TH1D("single_top" , title, nbinsx, xlow, xup); TH1D * ht1bbbb_1500_100 = new TH1D("t1bbbb_1500_100" , title, nbinsx, xlow, xup); TH1D * ht1bbbb_1000_900 = new TH1D("t1bbbb_1000_900" , title, nbinsx, xlow, xup); TH1D * ht1tttt_1500_100 = new TH1D("t1tttt_1500_100" , title, nbinsx, xlow, xup); TH1D * ht1tttt_1200_800 = new TH1D("t1tttt_1200_800" , title, nbinsx, xlow, xup); TH1D * ht1qqqq_1400_100 = new TH1D("t1qqqq_1400_100" , title, nbinsx, xlow, xup); TH1D * ht1qqqq_1000_800 = new TH1D("t1qqqq_1000_800" , title, nbinsx, xlow, xup); // Format cuts TCut cut(other_cuts); // TCut ttbar_weight("(weightppb*4000)/top_pt_weight_official"); TCut ttbar_weight("(3.17760399999999981e-05*4000)"); cout << "Filling histograms for " << var.Data() << endl; ttbar_ch->Project("ttbar",var,(cut)*ttbar_weight); qcd_ch->Project("qcd",var,cut*weights); znn_ch->Project("znn",var,cut*weights); wjets_ch->Project("wjets",var,(cut)*weights); other_ch->Project("other",var,cut*weights); single_top_ch->Project("single_top",var,cut*weights); t1bbbb_1500_100_ch->Project("t1bbbb_1500_100",var,(cut)*weights); t1bbbb_1000_900_ch->Project("t1bbbb_1000_900",var,(cut)*weights); t1tttt_1500_100_ch->Project("t1tttt_1500_100",var,(cut)*weights); t1tttt_1200_800_ch->Project("t1tttt_1200_800",var,(cut)*weights); t1qqqq_1400_100_ch->Project("t1qqqq_1400_100",var,(cut)*weights); t1qqqq_1000_800_ch->Project("t1qqqq_1000_800",var,(cut)*weights); bool addOverflow(true); Double_t e_overflow(0.), i_overflow(0.); if (addOverflow) { i_overflow=httbar->IntegralAndError(nbinsx,nbinsx+1,e_overflow); httbar->SetBinContent(nbinsx, i_overflow); httbar->SetBinError(nbinsx, e_overflow); i_overflow=hqcd->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hqcd->SetBinContent(nbinsx, i_overflow); hqcd->SetBinError(nbinsx, e_overflow); i_overflow=hznn->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hznn->SetBinContent(nbinsx, i_overflow); hznn->SetBinError(nbinsx, e_overflow); i_overflow=hwjets->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hwjets->SetBinContent(nbinsx, i_overflow); hwjets->SetBinError(nbinsx, e_overflow); i_overflow=hsingle_top->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hsingle_top->SetBinContent(nbinsx, i_overflow); hsingle_top->SetBinError(nbinsx, e_overflow); i_overflow=hother->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hother->SetBinContent(nbinsx, i_overflow); hother->SetBinError(nbinsx, e_overflow); i_overflow=ht1bbbb_1500_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow); ht1bbbb_1500_100->SetBinContent(nbinsx, i_overflow); ht1bbbb_1500_100->SetBinError(nbinsx, e_overflow); i_overflow=ht1bbbb_1000_900->IntegralAndError(nbinsx,nbinsx+1,e_overflow); ht1bbbb_1000_900->SetBinContent(nbinsx, i_overflow); ht1bbbb_1000_900->SetBinError(nbinsx, e_overflow); i_overflow=ht1tttt_1500_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow); ht1tttt_1500_100->SetBinContent(nbinsx, i_overflow); ht1tttt_1500_100->SetBinError(nbinsx, e_overflow); i_overflow=ht1tttt_1200_800->IntegralAndError(nbinsx,nbinsx+1,e_overflow); ht1tttt_1200_800->SetBinContent(nbinsx, i_overflow); ht1tttt_1200_800->SetBinError(nbinsx, e_overflow); i_overflow=ht1qqqq_1400_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow); ht1qqqq_1400_100->SetBinContent(nbinsx, i_overflow); ht1qqqq_1400_100->SetBinError(nbinsx, e_overflow); i_overflow=ht1qqqq_1000_800->IntegralAndError(nbinsx,nbinsx+1,e_overflow); ht1qqqq_1000_800->SetBinContent(nbinsx, i_overflow); ht1qqqq_1000_800->SetBinError(nbinsx, e_overflow); } // Add up MC histograms hmc_exp->Add(httbar); hmc_exp->Add(hqcd); hmc_exp->Add(hznn); hmc_exp->Add(hwjets); hmc_exp->Add(hsingle_top); hmc_exp->Add(hother); double binwidth = (xup - xlow) / nbinsx; TString ytitle = Form("Events / %.3f", binwidth); hmc_exp->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle()); hmc_exp->GetYaxis()->SetTitle(ytitle); cout << "... DONE: add all backgrounds to mc_exp." << endl; Double_t ttbar_e(0.), qcd_e(0.), znn_e(0.), wjets_e(0.), other_e(0.), single_top_e(0.), bg_tot_e(0.), t1tttt_1500_100_e(0.); double ttbar_n(httbar->IntegralAndError(0,nbinsx+1, ttbar_e)); double qcd_n(hqcd->IntegralAndError(0,nbinsx+1, qcd_e)); double znn_n(hznn->IntegralAndError(0,nbinsx+1, znn_e)); double wjets_n(hwjets->IntegralAndError(0,nbinsx+1, wjets_e)); double other_n(hother->IntegralAndError(0,nbinsx+1, other_e)); double single_top_n(hsingle_top->IntegralAndError(0,nbinsx+1, single_top_e)); double bg_tot(hmc_exp->IntegralAndError(0,nbinsx+1, bg_tot_e)); double t1tttt_1500_100_n(ht1tttt_1500_100->IntegralAndError(0,nbinsx+1, t1tttt_1500_100_e)); printf("Counts before cut: %s\n",var.Data()); printf("&ttbar&qcd&znn&wjets&single top&other&t1bbbb_1500_100\\\\ \n"); printf("%s & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f \\\\\n", var.Data(), ttbar_n,ttbar_e, qcd_n,qcd_e, znn_n,znn_e, wjets_n,wjets_e, single_top_n,single_top_e, other_n,other_e, // hmc_exp->GetBinContent(1), hmc_exp->GetBinError(1), bg_tot,bg_tot_e, t1tttt_1500_100_n,t1tttt_1500_100_e); cout << "... DONE: filled histograms." << endl; if (sigStack) { for (int bin(0); bin<nbinsx; bin++) { ht1bbbb_1500_100->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1)); ht1bbbb_1000_900->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1)); ht1tttt_1500_100->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1)); ht1tttt_1200_800->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1)); } } THStack * hs = new THStack("hs", ""); hs->Add(hother); hs->Add(hsingle_top); hs->Add(hwjets); hs->Add(hznn); if (httbar->Integral()>hqcd->Integral()) { hs->Add(hqcd); hs->Add(httbar); } else { hs->Add(httbar); hs->Add(hqcd); } //hs->GetYaxis()->SetTitle("Events / 5 fb^{-1}"); //hs->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle()); // Setup histogram styles set_style(httbar, "ttbar"); set_style(hqcd, "qcd"); set_style(hznn, "znn"); set_style(hwjets, "wjets"); set_style(hother, "other"); set_style(hsingle_top, "single_top"); // Setup auxiliary histograms (ratios, errors, etc) TH1D * staterr = (TH1D *) hmc_exp->Clone("staterr"); staterr->Sumw2(); //staterr->SetFillColor(kRed); staterr->SetFillColor(kGray+3); staterr->SetMarkerSize(0); staterr->SetFillStyle(3013); // Setup legends TLegend * leg1 = new TLegend(0.48, 0.6, 0.72, 0.92); set_style(leg1,0.025); if (plotData) leg1->AddEntry(hsingle_top, "Data", "pel"); if (plotSig) { leg1->AddEntry(ht1bbbb_1500_100, "#splitline{T1bbbb}{(1500,100) GeV}", "l"); leg1->AddEntry(ht1bbbb_1000_900, "#splitline{T1bbbb}{(1000,900) GeV}", "l"); leg1->AddEntry(ht1tttt_1500_100, "#splitline{T1tttt}{(1500,100) GeV}", "l"); leg1->AddEntry(ht1tttt_1200_800, "#splitline{T1tttt}{(1200,800) GeV}", "l"); leg1->AddEntry(ht1qqqq_1400_100, "#splitline{T1qqqq}{(1400,100) GeV}", "l"); leg1->AddEntry(ht1qqqq_1000_800, "#splitline{T1qqqq}{(1000,800) GeV}", "l"); } TLegend * leg2 = new TLegend(0.72, 0.6, 0.94, 0.92); set_style(leg2,0.025); if (httbar->Integral()>hqcd->Integral()) { leg2->AddEntry(httbar, "t#bar{t}", "f"); leg2->AddEntry(hqcd, "QCD", "f"); } else { leg2->AddEntry(hqcd, "QCD", "f"); leg2->AddEntry(httbar, "t#bar{t}", "f"); } leg2->AddEntry(hznn, "Z+jets", "f"); leg2->AddEntry(hwjets, "W+jets", "f"); leg2->AddEntry(hsingle_top, "Single Top", "f"); leg2->AddEntry(hother, "Other", "f"); leg2->AddEntry(staterr, "MC uncert.", "f"); double ymax = hs->GetMaximum(); if (ht1tttt_1500_100->GetMaximum()>ymax) ymax=ht1tttt_1500_100->GetMaximum(); if (ht1bbbb_1500_100->GetMaximum()>ymax) ymax=ht1bbbb_1500_100->GetMaximum(); if (ht1qqqq_1400_100->GetMaximum()>ymax) ymax=ht1qqqq_1400_100->GetMaximum(); if(plotLog) { hs->SetMaximum(200*ymax); hs->SetMinimum(0.1); } else { hs->SetMaximum(2*ymax); if (plot_title.Contains("baseline")) hs->SetMaximum(1.3*ymax); } // Vertical lines for cuts TLine* line_low = new TLine(cut_low,0,cut_low,1.5*ymax); TLine* line_high = new TLine(cut_high,0,cut_high,1.5*ymax); set_style(line_low); set_style(line_high); // Setup canvas and pads TCanvas * c1 = new TCanvas("c1", "c1", 700, 700); TPad * pad1 = new TPad("pad1", "top pad" , 0.0, 0.3, 1.0, 1.0); TPad * pad2 = new TPad("pad2", "bottom pad", 0.0, 0.0, 1.0, 0.3); if(plotData) { pad1->SetBottomMargin(0.0); pad1->Draw(); pad2->SetTopMargin(0.0); pad2->SetBottomMargin(0.35); pad2->Draw(); pad1->cd(); pad1->SetLogy(plotLog); } else { c1->cd(); c1->SetLogy(plotLog); } // Draw hists hs->Draw("hist"); hs->SetTitle(hmc_exp->GetTitle()); hs->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle()); hs->GetYaxis()->SetTitle(ytitle); hs->GetXaxis()->SetLabelSize(0.03); hs->GetYaxis()->SetLabelSize(0.03); if (plotData) { // hsingle_top->Draw("e1 same"); hs->GetXaxis()->SetLabelSize(0); } staterr->Draw("e2 same"); if (plotSig) { ht1bbbb_1500_100->SetLineColor(2); ht1bbbb_1500_100->SetLineWidth(4); ht1bbbb_1500_100->SetFillColor(0); ht1bbbb_1000_900->SetLineColor(2); ht1bbbb_1000_900->SetLineWidth(4); ht1bbbb_1000_900->SetLineStyle(7); ht1bbbb_1000_900->SetFillColor(0); ht1tttt_1500_100->SetLineColor(kGreen); ht1tttt_1500_100->SetLineWidth(4); ht1tttt_1500_100->SetFillColor(0); ht1tttt_1200_800->SetLineColor(kGreen); ht1tttt_1200_800->SetLineStyle(7); ht1tttt_1200_800->SetLineWidth(4); ht1tttt_1200_800->SetFillColor(0); ht1qqqq_1400_100->SetLineColor(1006); ht1qqqq_1400_100->SetLineWidth(4); ht1qqqq_1400_100->SetFillColor(0); ht1qqqq_1000_800->SetLineColor(1006); ht1qqqq_1000_800->SetLineWidth(4); ht1qqqq_1000_800->SetLineStyle(7); ht1qqqq_1000_800->SetFillColor(0); ht1bbbb_1500_100->Draw("hist same"); ht1bbbb_1000_900->Draw("hist same"); ht1tttt_1500_100->Draw("hist same"); ht1tttt_1200_800->Draw("hist same"); ht1qqqq_1400_100->Draw("hist same"); ht1qqqq_1000_800->Draw("hist same"); } if (cut_low>0) line_low->Draw("same"); if (cut_high>0) line_high->Draw("same"); // Draw legends leg1->Draw(); leg2->Draw(); TLatex * latex = new TLatex(); latex->SetNDC(); latex->SetTextAlign(12); latex->SetTextFont(62); latex->SetTextSize(0.042); latex->DrawLatex(0.19, 0.89, "CMS Simulation"); latex->SetTextSize(0.03); latex->DrawLatex(0.19, 0.84, "#sqrt{s} = 13 TeV, L = 4 fb^{-1}"); // Print cout << "MakePlots(): Printing..." << endl; c1->cd(); if (plot_title.EqualTo("default")) plot_title=plotdir+var; gPad->Print(plotdir+plot_title+".pdf"); // Clean up delete staterr; delete leg1; delete leg2; delete latex; // delete pave; delete hs; delete pad1; delete pad2; delete c1; delete httbar; delete hqcd; delete hznn; delete hwjets; delete hsingle_top; delete hother; delete hmc_exp; delete ht1bbbb_1500_100; delete ht1bbbb_1000_900; delete ht1tttt_1500_100; delete ht1tttt_1200_800; delete ht1qqqq_1400_100; delete ht1qqqq_1000_800; cout << "MakePlots(): DONE!" << endl; return; }
void plotsNoFitETau(bool mine=false,TString name="collMass",TString file="LFV_vbf_collMass_fakeRate_zjetsEmbed_newSignal.root", TString dir="preselectionMetFix_Nov2", TString dirInternal="vbfmutau",double blindA=100, double blindB=160, bool blind=false, TString Xaxis="M_{#mu,#tau}_{coll} [GeV]", TString Yaxis="Events / 20 GeV", TString Tex="#mu#tau_{h} 0 Jet", double xmin=0, double xmax=300, int rebinning=1, bool setLogY=false, double legx1=0.6, double legy1=0.9, double legx2=0.9, double legy2=0.5, double MAX=-1, double MIN=-1, double CORRFR=1., double scaleSignal=1.0, double ymin=-0.95, double ymax=0.95){ //gROOT->LoadMacro("tdrstyle.C"); setTDRStyle(); //gROOT->LoadMacro("CMS_lumi.C"); writeExtraText = false; int iPeriod = 2; // second parameter in example_plot is iPos, which drives the position of the CMS logo in the plot int iPos=11;// : top-left, left-aligned // iPos=33 : top-right, right-aligned // iPos=22 : center, centered // mode generally : // iPos = 10*(alignement 1/2/3) + position (1/2/3 = left/center/right) // example_plot( iPeriod, 11 ); // left-aligned // example_plot( iPeriod, 33 ); // right-aligned // example_plot( iPeriod, 0 ); // out of frame (in exceptional cases) // example_plot( iPeriod, 11 ); // default: left-aligned // example_plot( iPeriod, 22 ); // centered // example_plot( iPeriod, 33 ); // right-aligned double kForPlotting=1; double branchingratioTauTau=0.063; double branchingratioTauMu=0.1; double Lumi=19717; // Get Plots // Get Plots TFile *_file0= new TFile(dir+"/"+file); TString find="DYrightarrowlljets"; if(!mine) find="zjetsother"; TH1F *hDY=_file0->Get(dirInternal+find); hDY->SetName("DY"); find="Diboson"; if(!mine) find="ww"; TH1F *hWW=_file0->Get(dirInternal+find); hWW->SetName("WW"); find="SingleTop"; if(!mine) find="singlet"; TH1F *hTOP=_file0->Get(dirInternal+find); hTOP->SetName("TOP"); find="tbart"; if(!mine) find="ttbar"; TH1F *hTT=_file0->Get(dirInternal+find); hTT->SetName("TT"); find="Zrightarrowtautauembedded"; if(!mine) find="ztautau"; TH1F *hZTauTau=_file0->Get(dirInternal+find); hZTauTau->SetName("ZTauTau"); find="Fakes"; if(!mine) find="fakes"; TH1F *hFAKES=_file0->Get(dirInternal+find); hFAKES->SetName("fakes"); hFAKES->Scale(CORRFR); TH1F *hLFVVBF126=_file0->Get(dirInternal+"LFVvbfHiggsBR=1"); hLFVVBF126->SetName("LFVVBF126"); TH1F *hSMVBF126=_file0->Get(dirInternal+"SMvbfHiggs"); hSMVBF126->SetName("SMVBF126"); TH1F *hLFVGG126=_file0->Get(dirInternal+"LFVggHiggsBR=1"); hLFVGG126->SetName("LFVGG126"); TH1F *hSMGG126=_file0->Get(dirInternal+"SMHiggs"); hSMGG126->SetName("SMGG126"); find="Observed"; if(!mine) find="data_obs"; TH1F* hdata_obsNoErrFix=_file0->Get(dirInternal+find); TH1F* hdata_obs = hdata_obsNoErrFix->Clone(); std::cout << hdata_obsNoErrFix->GetEntries() << std::endl; for (i = 1; i <= hdata_obs->GetNbinsX(); i++){ if (hdata_obs->GetBinContent(i) == 0){ hdata_obs->SetBinContent(i,0.0); hdata_obs->SetBinError(i,1.8); } } hdata_obs->SetName("data_obs"); TH1F* hSMHIGGS=hSMGG126->Clone(); hSMHIGGS->SetName("HIGGSSM"); hSMHIGGS->Add(hSMVBF126); // For the Control plots only we want signal to be scaled to 100% Br hLFVVBF126->Scale(scaleSignal); hLFVGG126->Scale(scaleSignal); // From the fit /* hDY->Scale(1.122280); hWW->Scale(1.254172); hTOP->Scale(1.348162); hTT->Scale(1.082784); hZTauTau->Scale(1.157596); hFAKES->Scale(0.901000); */ // Daniel's Colors /* WGammaStar=kCyan ZTauTauEmbedded=kOrange-4 ZLL_residual=kAzure+3 TTBar=40 SingleTop=kGreen-2 EWKDiBoson=kRed+2 WJets/QCD Multijets=kMagenta-10 SMHToTauTau=kMagenta */ hFAKES->SetFillColor(kMagenta-10); hFAKES->SetLineColor(kMagenta+4); hFAKES->SetLineWidth(1); hZTauTau->SetFillColor(kOrange-4); hZTauTau->SetLineColor(kOrange+4); hZTauTau->SetLineWidth(1); hDY->SetFillColor(kAzure+3); hDY->SetLineColor(kAzure+4); hDY->SetLineWidth(1); hWW->SetFillColor(kAzure+3); hWW->SetLineColor(kAzure+3); hWW->SetLineWidth(1); hTOP->SetFillColor(kGreen-2); hTOP->SetLineColor(kGreen+4); hTOP->SetLineWidth(1); hTT->SetFillColor(kGreen-2); hTT->SetLineColor(kGreen-2); hTT->SetLineWidth(1); hLFVGG126->SetLineColor(kBlue+1); hLFVGG126->SetLineWidth(3); hLFVVBF126->SetLineColor(kBlue+1); hLFVVBF126->SetLineWidth(3); hLFVVBF126->SetLineStyle(kDashed); hSMVBF126->SetLineColor(kMagenta); hSMVBF126->SetLineWidth(3); hSMVBF126->SetLineStyle(kDashed); hSMGG126->SetLineColor(kMagenta); hSMGG126->SetLineWidth(3); hSMHIGGS->SetFillColor(kMagenta); hSMHIGGS->SetLineColor(kMagenta+1); hSMHIGGS->SetLineWidth(1); hdata_obs->SetMarkerSize(1); // Closer to Daniel's // Rebin hFAKES->Rebin(rebinning); hZTauTau->Rebin(rebinning); hDY->Rebin(rebinning); hTOP->Rebin(rebinning); hTT->Rebin(rebinning); hWW->Rebin(rebinning); hLFVGG126->Rebin(rebinning); hLFVVBF126->Rebin(rebinning); hSMVBF126->Rebin(rebinning); hSMGG126->Rebin(rebinning); hdata_obs->Rebin(rebinning); hSMHIGGS->Rebin(rebinning); // PLOT TCanvas *c1 = new TCanvas("canvas_"+name); TPad *Pad1= new TPad("pad1","",0,0.2,1,1); Pad1->Draw(); Pad1->cd();; Pad1->SetLeftMargin(0.2147651); Pad1->SetRightMargin(0.06543624); Pad1->SetTopMargin(0.07); Pad1->SetBottomMargin(0.04); for (int i=0; i<hFAKES->GetNbinsX()+1; i++){ double content=hFAKES->GetBinContent(i); double contentErr=0;//sqrt(content);//hFAKES->GetBinError(i); double err=sqrt(0.3*0.3*content*content+contentErr*contentErr); hFAKES->SetBinError(i,err); } TH1F* fullMC2=hZTauTau->Clone(); fullMC2->Add(hFAKES); fullMC2->Add(hTT); fullMC2->Add(hWW); fullMC2->Add(hDY); fullMC2->Add(hTOP); fullMC2->SetFillColorAlpha(kGray+2, 0.35); //fullMC2->SetFillStyle(3002); fullMC2->SetMarkerSize(0); fullMC2->Draw("hist"); fullMC2->GetXaxis()->SetTitle(""); fullMC2->GetYaxis()->SetTitle(Yaxis); fullMC2->GetXaxis()->SetRangeUser(xmin,xmax); fullMC2->GetYaxis()->SetTitleOffset(1.2); fullMC2->GetYaxis()->SetTitleSize(0.05); fullMC2->GetXaxis()->SetNdivisions(505); fullMC2->GetYaxis()->SetLabelSize(0.04); fullMC2->GetXaxis()->SetLabelSize(0); THStack* stack = new THStack("stack",""); stack->Add(hFAKES); stack->Add(hWW); stack->Add(hDY); stack->Add(hTT); stack->Add(hTOP); stack->Add(hZTauTau); stack->Add(hSMHIGGS); cout<<"Yields"<<endl; cout<<"VV " <<hWW->Integral()<<endl; cout<<"TOP " <<hTOP->Integral()<<endl; cout<<"TT " <<hTT->Integral()<<endl; cout<<"DY " <<hDY->Integral()<<endl; cout<<"ZTauTau " <<hZTauTau->Integral()<<endl; cout<<"FAKES " <<hFAKES->Integral()<<endl; cout<<"LFVGG126 " <<hLFVGG126->Integral()<<endl; cout<<"LFVVBF126 " <<hLFVVBF126->Integral()<<endl; stack->Draw("samehist"); fullMC2->Draw("sames,E2"); hLFVVBF126->Draw("sameshist"); hLFVGG126->Draw("sameshist"); double maxData=hdata_obs->GetMaximum(); double maxMC=stack->GetMaximum()*1.2; double maxLFV=hLFVGG126->GetMaximum(); double maxLFV2=hLFVVBF126->GetMaximum(); double minMC=stack->GetMinimum(); if(maxData>maxMC) {maxMC=1.2*maxData;} if(maxLFV>maxMC) {maxMC=1.2*maxLFV;} if(maxLFV2>maxMC) {maxMC=1.2*maxLFV2;} if(MAX!=-1) {maxMC=MAX;} stack->SetMaximum(maxMC); stack->GetYaxis()->SetRangeUser(minMC,maxMC); fullMC2->SetMaximum(maxMC); fullMC2->GetYaxis()->SetRangeUser(minMC,maxMC); if(setLogY){fullMC2->SetMinimum(0.1); fullMC2->GetYaxis()->SetRangeUser(1,maxMC*1000);} TH1F* histoDataUnblindedV4=hdata_obs->Clone(); histoDataUnblindedV4->SetName("data_unblinded"); if(!blind) hdata_obs->Draw("sames"); else { int findBinA=hdata_obs->FindBin(blindA); int findBinB=hdata_obs->FindBin(blindB); for (int i=findBinA; i<findBinB; i++) hdata_obs->SetBinContent(i,-1000); hdata_obs->Draw("sames"); TPave *pave = new TPave(blindA,minMC,blindB,maxMC,4,"br"); //pave->SetFillColorAlpha(kGray+3,0.35); pave->SetFillColor(1); pave->SetFillStyle(3003); pave->SetDrawOption(0); pave->SetBorderSize(0); pave->Draw(); } TLegend *leg = new TLegend(legx1,legy1,legx2,legy2,NULL,"brNDC"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetFillStyle(0); TLegendEntry *entry; entry=leg->AddEntry(hdata_obs,"Data, e#tau_{h}","p"); entry=leg->AddEntry(fullMC2,"Bkgd. uncertainty","f"); entry=leg->AddEntry(hSMHIGGS,"SM Higgs","f"); eblindBy=leg->AddEntry(hZTauTau,"Z#rightarrow#tau#tau","f"); entry=leg->AddEntry(hTOP,"t#bar{t}, t, #bar{t}","f"); entry=leg->AddEntry(hDY,"Other","f"); entry=leg->AddEntry(hFAKES,"MisID'd #tau","f"); entry=leg->AddEntry(hLFVGG126,"LFV GG Higgs (B=100%)","l"); entry=leg->AddEntry(hLFVVBF126,"LFV VBF Higgs (B=100%)","l"); leg->Draw(); CMS_lumi( Pad1, iPeriod, iPos ); TLatex latex; latex.SetNDC(); latex.SetTextAngle(0); latex.SetTextColor(kBlack); latex.SetTextFont(42); latex.SetTextAlign(31); latex.SetTextSize(.05); latex.DrawLatex(0.39,0.8,Tex); //cmsPrelim(Lumi); Pad1->SetLogy(setLogY); gPad->RedrawAxis(); c1->cd(); TPad *Pad2= new TPad("pad2","",0,0,1,0.23); Pad2->Draw(); Pad2->cd(); Pad2->SetGridy(); Pad2->SetLeftMargin(0.2147651); Pad2->SetRightMargin(0.06543624); Pad2->SetTopMargin(0.0); Pad2->SetBottomMargin(0.37); Pad2->SetFillStyle(0); TH1F * Ratio=fullMC2->Clone(); Ratio->SetName("Ratio"); Ratio->Scale(-1); Ratio->Add(hdata_obs,1); Ratio->Divide(fullMC2); Ratio->SetLineColor(kBlack); Ratio->GetXaxis()->SetLabelFont(42); Ratio->GetXaxis()->SetTitleFont(42); Ratio->GetYaxis()->SetNdivisions(505); Ratio->GetYaxis()->SetLabelFont(42); Ratio->GetYaxis()->SetLabelSize(0.122); Ratio->GetYaxis()->SetRangeUser(ymin,ymax); Ratio->GetXaxis()->SetRangeUser(xmin,xmax); Ratio->GetXaxis()->SetLabelSize(0.12); Ratio->GetXaxis()->SetLabelFont(42); Ratio->SetYTitle("#frac{Data-Bkgd}{Bkgd}"); Ratio->SetXTitle(Xaxis); Ratio->GetXaxis()->SetNdivisions(505); Ratio->GetYaxis()->CenterTitle(true); Ratio->GetYaxis()->SetTitleOffset(0.4); Ratio->GetYaxis()->SetTitleSize(0.11); Ratio->GetXaxis()->SetTitleOffset(0.75); Ratio->GetXaxis()->SetTitleSize(0.20); Ratio->SetMarkerSize(1.); TH1F* RatioError = Ratio->Clone(); RatioError->SetName("RatioError"); for (int i=0; i<RatioError->GetNbinsX()+1; i++){ double error=fullMC2->GetBinError(i)*hdata_obs->GetBinContent(i)/fullMC2->GetBinContent(i)/fullMC2->GetBinContent(i); RatioError->SetBinContent(i,0); RatioError->SetBinError(i,error); } //RatioError->SetFillStyle(3002); RatioError->SetFillColorAlpha(kGray+2,0.35); RatioError->SetMarkerSize(0); RatioError->Draw("E2"); //Ratio->Draw("samesE0"); //errorbarswithoutdatapoints Ratio->Draw("sames"); if(!blind) Ratio->Draw("sames"); else { int findBinA=Ratio->FindBin(blindA); int findBinB=Ratio->FindBin(blindB); for (int i=findBinA; i<findBinB; i++) Ratio->SetBinContent(i,-100); Ratio->Draw("sames"); TPave *pave = new TPave(blindA,-1.0,blindB,1.0,4,"br"); pave->SetFillColor(1); pave->SetFillStyle(3003); //pave->SetFillColorAlpha(kGray+3,0.35); pave->SetDrawOption(0); pave->SetBorderSize(0); pave->Draw(); } if(!setLogY){ // c1->SaveAs(name+"ErrorBarsWithoutDataPoints.png"); // c1->SaveAs(name+"ErrorBarsWithoutDataPoints.pdf"); c1->SaveAs(name+".png"); c1->SaveAs(name+".pdf"); } else { c1->SaveAs(name+"_log.png"); c1->SaveAs(name+"_log.pdf"); } }
//=============================== void DrawFit(Double_t nSigma, Int_t iRapBin, Int_t iPTBin){ gStyle->SetFillColor(0); Char_t name[100]; gStyle->SetFrameBorderMode(0); //prepare the drawing of the individual components: fBG->SetFillColor(colour[BG]); fBG->SetLineColor(colour[BG]); fBG->SetFillStyle(1001); fBG->SetNpx(1000); TH1 *hBG = fBG->GetHistogram(); fUps1S->SetNpx(1000); fUps1S->SetFillColor(colour[UPS1S]); fUps1S->SetLineColor(colour[UPS1S]); fUps1S->SetFillStyle(1001); fUps2S->SetNpx(1000); fUps2S->SetFillColor(colour[UPS2S]); fUps2S->SetLineColor(colour[UPS2S]); fUps2S->SetFillStyle(1001); fUps3S->SetNpx(1000); fUps3S->SetFillColor(colour[UPS3S]); fUps3S->SetLineColor(colour[UPS3S]); fUps3S->SetFillStyle(1001); TH1 *hUps1S = fUps1S->GetHistogram(); TH1 *hUps2S = fUps2S->GetHistogram(); TH1 *hUps3S = fUps3S->GetHistogram(); THStack *hStack = new THStack("hMass_Stack", ""); hStack->Add(hBG); hStack->Add(hUps3S); hStack->Add(hUps2S); hStack->Add(hUps1S); if(!PlotSimplistic) hStack->Draw("same"); hMass->Draw("same"); if(!PlotSimplistic) fRECO->Draw("same"); TLine *line[3]; Double_t max[3] = {1., 0.5, 0.3}; for(int iL = 0; iL < 3; iL++){ line[iL]= new TLine(massMin[iL], 0.1, massMin[iL], max[iL]*hUps1S->GetMaximum()); line[iL]->SetLineStyle(2); line[iL]->SetLineColor(colour[iL]); line[iL]->SetLineWidth(2); if(!PlotSimplistic) line[iL]->Draw(); if(!PlotSimplistic) line[iL]->DrawLine(massMax[iL], 0.1, massMax[iL], max[iL]*hUps1S->GetMaximum()); } /* double MassScan[13]={8.6,8.95,9.3,9.45,9.6,9.85,10.0125,10.175,10.3425,10.51,10.8,11.1,11.4}; TLine *line[13]; for(int iL = 0; iL < 13; iL++){ line[iL]= new TLine(MassScan[iL], 0.1, MassScan[iL], 1.1*hUps1S->GetMaximum()); line[iL]->SetLineStyle(2); line[iL]->SetLineColor(kWhite); line[iL]->SetLineWidth(2); line[iL]->Draw(); } TLatex *texMassScan[13]; char MassScanName[200]; for(int iL = 0; iL < 13; iL++){ sprintf(MassScanName,"%d",iL+1); texMassScan[iL] = new TLatex((MassScan[iL]+MassScan[iL+1])/2., 0.015*hStack->GetMaximum(), MassScanName); texMassScan[iL]->SetTextSize(0.03); texMassScan[iL]->SetTextColor(kWhite); texMassScan[iL]->Draw(); } */ if(iRapBin == 0) sprintf(name, "|y| < %1.1f", onia::rapYPS); else if(iRapBin == 1) sprintf(name, "|y| < %1.1f", onia::rapForPTRange[iRapBin]); else if(iRapBin > 1) sprintf(name, "%1.1f < |y| < %1.1f", onia::rapForPTRange[iRapBin-1], onia::rapForPTRange[iRapBin]); double xText=10.25; TLatex *tex = new TLatex(xText, hStack->GetMaximum(), name); tex->SetTextSize(0.04); if(!PlotSimplistic) tex->Draw(); if(iPTBin == 0) sprintf(name, "all p_{T}"); // else if(iPTBin == 1) sprintf(name, "p_{T} < %1.1f GeV", onia::pTRange[iRapBin][iPTBin]); else sprintf(name, "%1.1f < p_{T} < %1.1f", onia::pTRange[iRapBin][iPTBin-1], onia::pTRange[iRapBin][iPTBin]); if(!PlotSimplistic) tex->DrawLatex(xText, 0.94*hStack->GetMaximum(), name); sprintf(name, "frac(BG) in #pm %1.1f#sigma:", nSigma); if(!PlotSimplistic) tex->DrawLatex(xText, 0.86*hStack->GetMaximum(), name); sprintf(name, "%1.2f, %1.2f, %1.2f", fracBG[0], fracBG[1], fracBG[2]); if(!PlotSimplistic) tex->DrawLatex(xText, 0.80*hStack->GetMaximum(), name); sprintf(name, "Figures/massFit_rap%d_pT%d.pdf", iRapBin, iPTBin); // gPad->SetLogy(kTRUE); gPad->Print(name); if(iPTBin>-1&&iRapBin>-10){ /// produce pedagogical plot cout<<"Plot pedagogical"<<endl; double mean1S_draw = fUps1S->GetParameter(1); double sigma1S_draw = fUps1S->GetParameter(2); double nSigmaMin=0; double nSigmaMax=2.5; int nIntegrals=100; double nSigmaCenter[nIntegrals]; double lSig[nIntegrals]; double lBkg[nIntegrals]; double lSig_[nIntegrals]; double lBkg_[nIntegrals]; double lSigOVERBkg[nIntegrals]; double maxSig=2.5; int whichBinIsAtOne=1/(nSigmaMax-nSigmaMin)*nIntegrals; cout<<"whichBinIsAtOne "<<whichBinIsAtOne<<endl; for(int nIter=0;nIter<nIntegrals;nIter++){ nSigmaCenter[nIter]= (nSigmaMax-nSigmaMin)/double(nIntegrals)*double(nIter+1); lSig_[nIter]= fUps1S->Integral(mean1S_draw-nSigmaCenter[nIter]*sigma1S_draw, mean1S_draw+nSigmaCenter[nIter]*sigma1S_draw); lBkg_[nIter]= fBG->Integral(mean1S_draw-nSigmaCenter[nIter]*sigma1S_draw, mean1S_draw+nSigmaCenter[nIter]*sigma1S_draw); } for(int nIter=0;nIter<nIntegrals;nIter++){ nSigmaCenter[nIter]= (nSigmaMax-nSigmaMin)/double(nIntegrals)*double(nIter+1); lSig[nIter]= fUps1S->Integral(mean1S_draw-nSigmaCenter[nIter]*sigma1S_draw, mean1S_draw+nSigmaCenter[nIter]*sigma1S_draw)/lSig_[whichBinIsAtOne-1]; lBkg[nIter]= fBG->Integral(mean1S_draw-nSigmaCenter[nIter]*sigma1S_draw, mean1S_draw+nSigmaCenter[nIter]*sigma1S_draw)/lBkg_[whichBinIsAtOne-1]; } for(int nIter=0;nIter<nIntegrals;nIter++){ lSigOVERBkg[nIter]= lSig[nIter]/lBkg[nIter]; cout<<"lSigOVERBkg[nIter] "<<lSigOVERBkg[nIter]<<endl; } TGraphErrors *nSigma_Sig = new TGraphErrors(nIntegrals,nSigmaCenter,lSig,0,0); TGraphErrors *nSigma_Bkg = new TGraphErrors(nIntegrals,nSigmaCenter,lBkg,0,0); TGraphErrors *nSigma_SigOVERBkg = new TGraphErrors(nIntegrals,nSigmaCenter,lSigOVERBkg,0,0); TCanvas *SystCanvas = new TCanvas("SystCanvas","SystCanvas",1000,800); // gStyle->SetPalette(1); // gPad->SetFillColor(kWhite); // gPad->SetLeftMargin(0.15); SystCanvas->SetFillColor(kWhite); SystCanvas->SetGrid(); SystCanvas->GetFrame()->SetFillColor(kWhite); SystCanvas->GetFrame()->SetBorderSize(0); SystCanvas->SetRightMargin(0.05) ; TLegend* plotLegend=new TLegend(0.1,0.7,0.45,0.9); plotLegend->SetFillColor(kWhite); plotLegend->SetTextFont(72); plotLegend->SetTextSize(0.03); plotLegend->SetBorderSize(1); char legendentry[200]; double lineWidth=3; char drawGraphStyle[200]; sprintf(drawGraphStyle,"LX"); TH1F *SystHisto = new TH1F; SystHisto = SystCanvas->DrawFrame(nSigmaMin,0,nSigmaMax,maxSig); SystHisto->SetXTitle("n_{#sigma}"); SystHisto->GetYaxis()->SetTitleOffset(1.5); nSigma_Sig->SetLineColor(kGreen-2); nSigma_Sig->SetLineWidth(lineWidth); nSigma_Sig->Draw(drawGraphStyle); sprintf(legendentry,"Signal yield"); plotLegend->AddEntry(nSigma_Sig,legendentry,"l"); nSigma_Bkg->SetLineColor(kBlue); nSigma_Bkg->SetLineWidth(lineWidth); nSigma_Bkg->Draw(drawGraphStyle); sprintf(legendentry,"Background yield"); plotLegend->AddEntry(nSigma_Bkg,legendentry,"l"); nSigma_SigOVERBkg->SetLineColor(kRed); nSigma_SigOVERBkg->SetLineWidth(lineWidth); nSigma_SigOVERBkg->Draw(drawGraphStyle); sprintf(legendentry,"S/B ratio"); plotLegend->AddEntry(nSigma_SigOVERBkg,legendentry,"l"); plotLegend->Draw(); sprintf(name,"Figures/pedagogical_rap%d_pT%d.pdf",iRapBin,iPTBin); SystCanvas->SaveAs(name); } }
void controlplots(int mode = 0){ gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetErrorX(0); setTDRStyle(); gROOT->SetBatch(1); labelcms = new TPaveText(0.12,0.88,0.5,0.94,"NDCBR"); labelcms->SetTextAlign(12); labelcms->SetTextSize(0.045); labelcms->SetFillColor(kWhite); labelcms->AddText("CMS Preliminary, #sqrt{s} = 7 TeV"); labelcms->SetBorderSize(0); labelcms2 = new TPaveText(0.12,0.85,0.5,0.88,"NDCBR"); labelcms2->SetTextAlign(12); labelcms2->SetTextSize(0.045); labelcms2->SetFillColor(kWhite); if (mode == 0) labelcms2->AddText("4.9 fb^{-1}, e#mu channel "); if (mode == 1) labelcms2->AddText("4.9 fb^{-1}, #mu#mu channel "); if (mode == 2) labelcms2->AddText("4.9 fb^{-1}, ee channel "); labelcms2->SetBorderSize(0); gStyle->SetOptStat(0); gStyle->SetPalette(1); gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite); gStyle->SetCanvasDefH(600); gStyle->SetCanvasDefW(600); gStyle->SetLabelFont(18,""); gStyle->SetTitleXOffset(1.2);//1.5 gStyle->SetTitleYOffset(1.2);//1.7 char myRootFile[300]; double lumi = 0; if (mode == 0 ) lumi = 4904.338; else if ( mode == 1) lumi = 4919.924; else if ( mode == 2) lumi = 4895.249; sprintf(myRootFile,"results/sf_an_%dpb_%d.root", lumi, mode); TFile *_file0 = TFile::Open(myRootFile); cout << myRootFile << endl; const int nProcess = 8; TString processName[nProcess] = { "twdr", "st", "tt","di", "zjets", "wjets", "qcd_mu", "data"}; TString processTitle[nProcess] = { "tW", "t/s-channel", "t#bar{t}", "WW/WZ/ZZ", "Z/#gamma*+jets", "W+jets", "QCD", "data"}; Color_t color[nProcess] = {kWhite, kMagenta-10, kRed+1, kYellow-10, kAzure-2, kGreen-3, 40, kBlack}; TString modeString[3] = {"0", "1", "2"}; TString cutLabel = "R"; TH1F* h [nProcess]; TH1F* histo[nProcess]; THStack* hStack; leg = new TLegend(0.7,0.7,0.94,0.94); leg ->SetFillStyle(1); leg ->SetFillColor(kWhite); leg ->SetBorderSize(1); leg ->SetTextSize(0.03); hStack = new THStack(); hStack2 = new THStack(); for (int iProcess = 0; iProcess < 8; iProcess++){ h[iProcess] = (TH1F*) _file0->Get("R_" + processName[iProcess]); h[iProcess]->SetFillColor(color[iProcess]); h[iProcess]->SetLineColor(kBlack); histo[iProcess] = new TH1F("histo"+processName[iProcess], "", 3, 0, 3); histo[iProcess]->SetLineColor(kBlack); histo[iProcess]->SetLineWidth(1); histo[iProcess]->SetFillColor(color[iProcess]); histo[iProcess]->SetBinContent(1, h[iProcess]->GetBinContent(28)); histo[iProcess]->SetBinContent(2, h[iProcess]->GetBinContent(30)); histo[iProcess]->SetBinContent(3, h[iProcess]->GetBinContent(31)); histo[iProcess]->SetBinError(1, h[iProcess]->GetBinError(28)); histo[iProcess]->SetBinError(2, h[iProcess]->GetBinError(30)); histo[iProcess]->SetBinError(3, h[iProcess]->GetBinError(31)); if (iProcess == 0){ h[iProcess]->SetLineColor(kBlack); histo[iProcess]->SetLineColor(kBlack); } } histo[5]->Add(histo[1]); histo[5]->Add(histo[3]); histo[5]->Add(histo[6]); hStack->Add(histo[5]); hStack->Add(histo[4]); hStack->Add(histo[2]); hStack->Add(histo[0]); if (mode == 0) leg->AddEntry(histo[7], processTitle[7], "p"); if (mode == 1) leg->AddEntry(histo[7], processTitle[7], "p"); if (mode == 2) leg->AddEntry(histo[7], processTitle[7], "p"); leg->AddEntry(histo[0], processTitle[0], "f"); leg->AddEntry(histo[2], processTitle[2], "f"); leg->AddEntry(histo[4], processTitle[4], "f"); leg->AddEntry(histo[5], "Other", "f"); histo[7]->SetMarkerStyle(20); histo[7]->SetMarkerSize(1.2); histo[7]->SetMarkerColor(kBlack); histo[7]->SetLineColor(kBlack); histo[7]->SetLineWidth(1); double max = TMath::Max(hStack->GetMaximum(), histo[7]->GetMaximum()); TCanvas *c1 = new TCanvas(); hStack->Draw("histo"); hStack->SetMaximum(max * 1.25); hStack->SetMinimum(1); hStack->GetYaxis()->SetTitle("events / 4.9 fb^{-1}"); hStack->GetYaxis()->SetTitleOffset(1.4); hStack->GetYaxis()->CenterTitle(); hStack->GetYaxis()->SetTitleOffset(1.4); hStack->GetYaxis()->CenterTitle(); hStack->GetXaxis()->SetBinLabel(1,"1 jet 1 tag"); hStack->GetXaxis()->SetBinLabel(2,"2 jet 1 tag"); hStack->GetXaxis()->SetBinLabel(3,"2 jet 2 tag"); histo[7]->Draw("e, sames"); leg->Draw(); labelcms->Draw(); labelcms2->Draw(); c1->SaveAs("plots/sf_control_summer_tt_" + modeString[mode] + "_" + cutLabel + ".png"); c1->SaveAs("plots/pdf/sf_control_summer_tt_" + modeString[mode] + "_" + cutLabel + ".pdf"); c1->SetLogy(); hStack->SetMaximum(max * 10); c1->SaveAs("plots/sf_control_summer_tt_" + modeString[mode] + "_" + cutLabel + "_log.png"); c1->SaveAs("plots/pdf/sf_control_summer_tt_" + modeString[mode] + "_" + cutLabel + "_log.pdf"); }