TH1F* makehist( string id, int ndf ) { int hits_count = ndf + 2; TString hist_name, cut, title; hist_name += id; hist_name += "_chisq_"; hist_name += hits_count; hist_name += "hits"; cut += id; cut += "_hits_count == "; cut += hits_count; float min_x = 0; float max_x = (ndf == 2) ? 2.0 : 0.5; TH1F *hist = new TH1F(hist_name.Data(), cut, 1000, min_x, max_x); events->Draw(Form("%s_chisq >> %s", id.c_str(), hist_name.Data()), cut); if (hits_count > 3) { TF1 *func = new TF1("func", "[0]*exp([1]*x)+[2]"); TFitResultPtr fit = hist->Fit(func, "SQ", "", 0.0, 0.5); // S - return fit result, Q - quiet std::cout << hist_name << "\tslope: " << fit->Parameter(1) << "\tadd const: " << fit->Parameter(2) << std::endl; } if (id[1] == '3') { title += "Left "; } else { title += "Right "; } title += id[2]; title += " ("; title += cut; title += ")"; hist->SetTitle(title); hist->SetLabelSize(0.04, "X"); hist->SetLabelSize(0.04, "Y"); hist->SetTitleSize(0.05, "X"); hist->SetTitleSize(0.05, "Y"); hist->SetTitleOffset(0.9, "X"); hist->SetTitleOffset(1.1, "Y"); hist->GetXaxis()->SetTitle("#chi^2, [mm]"); hist->GetYaxis()->SetTitle("N"); return hist; }
TH1F* bookHist(const char* hname, const char* htitle, int nBinsMET, int nBinsHT, int sampleIndex ) { int nbins = nBinsMET*(nBinsHT+1) + 1 ; TH1F* retVal = new TH1F( hname, htitle, nbins, 0.5+0.05*(sampleIndex-5), nbins+0.5+0.05*(sampleIndex-5) ) ; TAxis* xaxis = retVal->GetXaxis() ; for ( int mbi=0; mbi<nBinsMET; mbi++ ) { for ( int hbi=0; hbi<nBinsHT; hbi++ ) { int histbin = 1 + (nBinsHT+1)*mbi + hbi + 1 ; char binlabel[1000] ; sprintf( binlabel, "M%d_H%d", mbi+1, hbi+1 ) ; xaxis->SetBinLabel( histbin, binlabel ) ; } // hbi. } // mbi. retVal->SetLabelSize(0.055,"x") ; xaxis->LabelsOption("v") ; return retVal ; }
TH1F* bookHist(const char* hname, const char* htitle, const char* selstring, int nbjet, int nBinsMET, int nBinsHT ) { int nbins = nBinsMET*(nBinsHT+1) + 1 ; TH1F* retVal = new TH1F( hname, htitle, nbins, 0.5 + 0.1*(nbjet-2), nbins+0.5 + 0.1*(nbjet-2) ) ; TAxis* xaxis = retVal->GetXaxis() ; for ( int mbi=0; mbi<nBinsMET; mbi++ ) { for ( int hbi=0; hbi<nBinsHT; hbi++ ) { int histbin = 1 + (nBinsHT+1)*mbi + hbi + 1 ; char binlabel[1000] ; sprintf( binlabel, "%s_M%d_H%d_%db", selstring, mbi+1, hbi+1, nbjet ) ; xaxis->SetBinLabel( histbin, binlabel ) ; } // hbi. } // mbi. retVal->SetLabelSize(0.055,"x") ; xaxis->LabelsOption("v") ; return retVal ; }
void StringFloat(){ gROOT->Reset(); gStyle->SetOptStat(1111111); ifstream data; float value; // string name = "L1Eff"; //name withtout .txt string name = "JustRPCMon7TeV"; data.open((name+".txt").c_str()); string label; float eff; TH1F * histo = new TH1F("histo",name.c_str(),66,0.5,66.5); int bin = 0; while(!data.eof() && bin<66){ bin++; data >>label>>eff; cout<<label<<" "<<eff<<endl; histo->GetXaxis()->SetBinLabel(bin,label.c_str()); histo->SetBinContent(bin,eff); } TCanvas * Ca0 = new TCanvas("Ca0","Canvas",1200,800); // Ca0->SetBottomMargin(0.4); histo->Draw(); // histo->SetMaximum(100000.); // histo->SetMinimum(0.); histo->GetXaxis()->LabelsOption("v"); histo->GetYaxis()->SetTitle("Events/run"); histo->SetLabelSize(0.03); Ca0->SetLogy(); Ca0->SaveAs((name+".png").c_str()); }
/*#include <TSystem.h> // interface to OS #include <TStyle.h> // class to handle ROOT plotting styles#include <TFile.h> // file handle class #include <TTree.h> // class to access ntuples #include <TBenchmark.h> // class to track macro running statistics #include <TH1D.h> // histogram class #include <vector> // STL vector class #include <iostream> // standard I/O #include <iomanip> // functions to format standard I/O #include <fstream> // functions for file I/O #include <string> // C++ string class #include <sstream> // class for parsing strings #include <TRandom3.h> #include <TGaxis.h> #include "Math/LorentzVector.h" // 4-vector class #include "../Utils/MyTools.hh" // various helper functions #include "../Utils/CPlot.hh" // helper class for plots #include "../Utils/MitStyleRemix.hh" // style settings for drawing #include "../Utils/WModels.hh" // definitions of PDFs for fitting #include "../Utils/RecoilCorrector.hh" // class to handle recoil corrections for MET */ void W_MET_Ratio() { TCanvas *c = new TCanvas("c","c",800,800); c->Divide(1,2,0,0); c->cd(1)->SetPad(0,0.3,1.0,1.0); c->cd(1)->SetTopMargin(0.1); c->cd(1)->SetBottomMargin(0.01); c->cd(1)->SetLeftMargin(0.15); c->cd(1)->SetRightMargin(0.07); c->cd(1)->SetTickx(1); c->cd(1)->SetTicky(1); c->cd(2)->SetPad(0,0,1.0,0.3); c->cd(2)->SetTopMargin(0.05); c->cd(2)->SetBottomMargin(0.45); c->cd(2)->SetLeftMargin(0.15); c->cd(2)->SetRightMargin(0.07); c->cd(2)->SetTickx(1); c->cd(2)->SetTicky(1); c->cd(2)->SetGridy(); TLegend * lgc = new TLegend(0.59, 0.67, 0.89, 0.89); lgc->SetTextSize(0.03); lgc->SetBorderSize(0); lgc->SetFillColor(0); // TFile *file = new TFile("../ElectronHighPU/Ele_RD_HighPU_A_Analysis.root"); TFile *file = new TFile("./ElectronHighPU_N/Ele_WToENu_S10_Analysis.root"); ///////////////Original Plot//////////////////////// c->cd(1); lgc->AddEntry(h1_W_Neut_pt1,"UnCorrected"); h1_W_Neut_pt1->SetYTitle("Events"); h1_W_Neut_pt1->SetFillColor(kWhite); h1_W_Neut_pt1->SetMarkerColor(kBlack); h1_W_Neut_pt1->SetMarkerStyle(1); h1_W_Neut_pt1->SetLineWidth(2); h1_W_Neut_pt1->Draw(); lgc->AddEntry(h1_W_Neut_pt_Corr,"Corrected"); h1_W_Neut_pt_Corr->SetLineColor(kRed); h1_W_Neut_pt_Corr->SetFillColor(kWhite); h1_W_Neut_pt_Corr->SetMarkerColor(kRed); h1_W_Neut_pt_Corr->SetMarkerStyle(1); h1_W_Neut_pt_Corr->SetLineWidth(2); h1_W_Neut_pt_Corr->Draw("same"); lgc->Draw(); /////////////////////////////////////////////////////// c->cd(2); TH1F * h1_Ori = (TH1F*)file->Get("h1_W_Neut_pt1"); TH1F * h1_Corr = (TH1F*)file->Get("h1_W_Neut_pt_Corr"); int Nbins = h1_Ori->GetNbinsX(); TH1F * ratio = new TH1F("ratio","", Nbins, h1_Ori->GetXaxis()->GetXmin(), h1_Ori->GetXaxis()->GetXmax()); ratio->Divide(h1_Ori, h1_Corr); ratio->SetXTitle("N_vtx"); ratio->SetMaximum(2); ratio->SetMinimum(0); ratio->SetNdivisions(10,"X"); ratio->SetNdivisions(4,"Y"); ratio->SetLabelSize(0.09,"XY"); ratio->SetTitleSize(0.12,"X"); ratio->SetMarkerStyle(20); ratio->SetMarkerSize(0.7); ratio->SetMarkerColor(kBlue); ratio->Draw("P"); // c->SaveAs("W_MET_Ratio_RD.png"); c->SaveAs("W_MET_Ratio_MC.png"); }
int compare(){ gROOT->SetStyle("Plain"); // For the canvas: gStyle->SetCanvasColor(0); // For the Pad: gStyle->SetPadColor(0); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetPadBorderSize(2); // For the frame: gStyle->SetFrameBorderMode(0); // For the statistics box: gStyle->SetOptStat(0); // Margins: gStyle->SetPadBottomMargin(0.25); gStyle->SetPadTopMargin(0.15); gStyle->SetPadLeftMargin(0.15); gStyle->SetPadRightMargin(0.1); // For the Global title: gStyle->SetOptTitle(0); gStyle->SetTitleColor(1); gStyle->SetTitleFillColor(10); gStyle->SetTitleTextColor(1); gStyle->SetTitleFont(42); gStyle->SetTitleFontSize(0.05); gStyle->SetTitleBorderSize(0); // For the axis gStyle->SetNdivisions(510, "X"); gStyle->SetNdivisions(510, "Y"); gStyle->SetTickLength(0.03); // For the axis titles: gStyle->SetTitleOffset(1.4, "X"); gStyle->SetTitleOffset(1.2, "Y"); gStyle->SetTitleOffset(0.5, "Z"); gStyle->SetTitleSize(0.061, "XYZ"); gStyle->SetTitleFont(42, "XYZ"); // For the axis labels: gStyle->SetLabelSize(0.04, "XYZ"); gStyle->SetLabelOffset(0.01, "XYZ"); gStyle->SetLabelFont(42, "XYZ"); // For the legend gStyle->SetLegendBorderSize(0); gROOT->ForceStyle(); //////////////////////////////////////// TFile *f1 = new TFile("output_GetPrediction/prediction_histos_MyTest_data_METsoftSmeared_noAngSmear_N20_CR_v3.root", "READ", "", 0); TFile *f2 = new TFile("output_GetPrediction/bkg.root", "READ", "", 0); selection = (TH1F*) f1->FindObjectAny("VBF_MET_presel_4JV_dPhiSide_selection"); prediction = (TH1F*) f1->FindObjectAny("VBF_MET_presel_4JV_dPhiSide_prediction_px"); background2 = (TH1F*) f2->FindObjectAny("met_check_inVR_rebin"); TH1F* background = new TH1F(*prediction); background->Reset(); for (int i = 1; i <= background->GetXaxis()->GetNbins(); ++i) { float x = background->GetXaxis()->GetBinCenter(i); int j = background2->GetXaxis()->FindBin(x); float value = background2->GetBinContent(j); float error = background2->GetBinError(j); background->SetBinContent(i,value); background->SetBinError(i,error); } //double MinX = selection->GetXaxis()->GetBinLowEdge(1); //double MaxX = selection->GetXaxis()->GetBinUpEdge(selection->GetXaxis()->GetNbins()); double MinX = 150; double MaxX = 500; double BinWidth = selection->GetXaxis()->GetBinWidth(selection->GetXaxis()->GetNbins()); double MaxY = prediction->GetBinContent(prediction->GetMaximumBin()); double MaxYsel = selection->GetBinContent(selection->GetMaximumBin()); if (MaxY < MaxYsel) MaxY = MaxYsel; double YRangeMax = 2.*pow(10., int(log10(MaxY))+2); double MinY = prediction->GetBinContent(prediction->GetMinimumBin()); double MinYsel = selection->GetBinContent(selection->GetMinimumBin()); if (MinY > MinYsel) MinY = MinYsel; if (MinY < 0.001) MinY = 0.001; double YRangeMin = 0.5*pow(10., int(log10(MinY))-2); TString titlePrediction; TString titleSelection; TString titleBackground; TString RatioTitle; TString LumiTitle; TString Title; TString xTitle; TString yTitle; LumiTitle = "ATLAS internal, L = 36.1 fb^{ -1}, #sqrt{s} = 13 TeV"; Title = "3 jets, 1.8<#Delta#phi(jj)<2.7, MET>150 GeV, M(jj)>0.6 TeV, p_{T}^{3rd}<50 GeV"; xTitle = "#slash{E}_{T} (GeV)"; yTitle = "Events"; titlePrediction = "Data-driven Pred."; titleSelection = "Data"; titleBackground = "non-QCD background"; RatioTitle = "(Pred-Data)/Data"; static Int_t c_LightBrown = TColor::GetColor( "#D9D9CC" ); static Int_t c_LightGray = TColor::GetColor( "#DDDDDD" ); selection->SetAxisRange(MinX, MaxX, "X"); selection->GetYaxis()->SetRangeUser(YRangeMin, YRangeMax); selection->SetMarkerStyle(20); selection->SetMarkerSize(0.9); selection->SetMarkerColor(kBlack); selection->SetXTitle(xTitle); selection->SetYTitle(yTitle); prediction->SetAxisRange(MinX, MaxX, "X"); prediction->GetYaxis()->SetRangeUser(YRangeMin, YRangeMax); prediction->SetFillColor(c_LightGray); prediction->SetTitle(""); prediction->SetXTitle(xTitle); prediction->SetYTitle(yTitle); background->SetAxisRange(MinX, MaxX, "X"); background->GetYaxis()->SetRangeUser(YRangeMin, YRangeMax); background->SetTitle(""); background->SetLineColor(kRed); background->SetLineWidth(2); background->SetXTitle(xTitle); background->SetYTitle(yTitle); TCanvas *c = new TCanvas("ca", "Comparison and ratio of two histos", 700, 700); TPad *pad1 = new TPad("pad1a", "pad1a", 0, 0.35, 1, 1); pad1->SetLogy(); pad1->SetBottomMargin(0); pad1->Draw(); pad1->cd(); prediction->DrawCopy("hist"); selection->Draw("same"); prediction->SetFillColor(kAzure-3); prediction->SetFillStyle(3354); prediction->DrawCopy("e2same"); background->Scale(36.1/32.6); background->Draw("same"); prediction->SetFillStyle(1001); //prediction->SetFillColor(c_LightBrown); prediction->SetFillColor(c_LightGray); //TLegend* leg1 = new TLegend(0.48, 0.63, 0.95, 0.83); TLegend* leg1 = new TLegend(0.44, 0.63, 0.91, 0.83); leg1->SetFillStyle(0); leg1->SetLineStyle(1); leg1->SetTextFont(42); //leg1->SetTextSize(0.04); leg1->SetTextSize(0.045); leg1->AddEntry(prediction, titlePrediction, "lf"); leg1->AddEntry(selection, titleSelection, "lep"); leg1->AddEntry(background, titleBackground, "l"); leg1->Draw("same"); TPaveText* pt = new TPaveText(0.11, 0.98, 0.95, 0.86, "NDC"); pt->SetBorderSize(0); pt->SetFillStyle(0); pt->SetTextAlign(12); pt->SetTextSize(0.045); pt->AddText(Title); pt->AddText(LumiTitle); pt->Draw(); c->cd(); TPad *pad2 = new TPad("pad2a", "pad2a", 0, 0, 1, 0.35); pad2->SetTopMargin(0); pad2->Draw(); pad2->cd(); TH1F* r = new TH1F(*prediction); r->SetTitle(""); r->SetLabelSize(0.08, "XYZ"); r->SetLabelOffset(0.01, "XYZ"); // r->SetTitleSize(0.09, "XYZ"); r->SetTitleSize(0.125, "XYZ"); r->SetTitleOffset(0.95, "X"); r->SetTitleOffset(0.53, "Y"); // r->SetTitleOffset(0.65, "Y"); r->SetTickLength(0.05); r->SetYTitle(RatioTitle); r->SetStats(0); r->SetMarkerStyle(20); r->SetMarkerSize(0.9); r->SetMarkerColor(kBlack); r->Reset(); r->Add(prediction, 1); r->Add(background, 1); r->Add(selection, -1); r->Divide(selection); r->SetMaximum(2.2); r->SetMinimum(-2.2); r->Draw("ep"); TLine l; l.DrawLine(MinX, 0., MaxX+BinWidth, 0.); c->cd(); c->SaveAs("compare.pdf"); return 0; }
void plotCutFlowNotStaggered( FileList fileList , float Lumi_ = 30, float pt1_ = 20., float pt2_ = 15, float DEta_ = 1.0, float Mjj_ = 300. , float jetVeto_ = 15, float signalScale_ = 1.0) { for(int i = 0; i<fileList.size(); i++){ (fileList[i].first)->Close(); delete (fileList[i].first); } TFile* fVBF115 = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_VBFH115.root","READ"); TFile* fVBF135 = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_VBFH135.root","READ"); TFile* fDYJets = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_DYJets-madgraph-50-PU.root","READ"); TFile* fTT = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_TT-madgraph-PU.root","READ"); TFile* fWJets = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_WJets-madgraph-PU.root","READ"); TFile* fT = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_TToBLNu-tW-madhraph-PU.root","READ"); TFile* fQCD = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_QCD-pythia-PU.root","READ"); FileList fileList_; fileList_.push_back( make_pair(fT, make_pair("tW", 10.6 ) )); fileList_.push_back( make_pair(fTT, make_pair("ttbar", 157.5 ) )); fileList_.push_back( make_pair(fDYJets, make_pair("Zjets", 3048.0 ) )); fileList_.push_back( make_pair(fWJets, make_pair("Wjets", 31314.0 ) )); fileList_.push_back( make_pair(fQCD, make_pair("QCD", 349988.0 ) )); fileList_.push_back( make_pair(fVBF115, make_pair("qqH115", 0.1012 ) )); fileList_.push_back( make_pair(fVBF135, make_pair("qqH135", 0.05049) )); TCanvas *c1 = new TCanvas("c1CutFlowNotStaggeredMass","",5,30,650,600); c1->SetGrid(0,0); c1->SetFillStyle(4000); c1->SetFillColor(10); c1->SetTicky(); c1->SetObjectStat(0); c1->SetLogy(1); TPad* pad1 = new TPad("pad1CutFlowNotStaggeredMass","",0.05,0.27,0.96,0.97); TPad* pad2 = new TPad("pad2CutFlowNotStaggeredMass","",0.05,0.02,0.96,0.26); pad1->SetFillColor(0); pad2->SetFillColor(0); pad1->Draw(); pad2->Draw(); pad1->cd(); pad1->SetLogy(1); TLegend* leg = new TLegend(0.60,0.47,0.90,0.85,NULL,"brNDC"); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetFillColor(10); leg->SetTextSize(0.04); leg->SetHeader( "Cut Flow" ); vector<TH1F*> histos; histos.clear(); TH1F* hqqH115 = new TH1F(); TH1F* hqqH135 = new TH1F(); TH1F* hSiml = new TH1F(); vector< pair<string,string> > cutList; cutList.push_back(make_pair("vertexScarpingFilter/totalEvents","good vertex")); cutList.push_back(make_pair("oneMuonFilter/totalEvents","one gl. muon p_{T}>15 GeV")); cutList.push_back(make_pair("noElecFilter/totalEvents","electron veto")); cutList.push_back(make_pair("muonLegFilter/totalEvents","#mu cuts")); cutList.push_back(make_pair("tauLegFilter/totalEvents","#tau cuts")); cutList.push_back(make_pair("atLeastOneDiTauFilter/totalEvents","OS + m_{T} cut")); vector<float> cutFlow; float signalScale = 1; for(unsigned int i = 0 ; i < fileList_.size() ; i++){ signalScale = 1; TFile* currentFile = (TFile*)fileList_[i].first ; if( currentFile->IsZombie() ) continue; TH1F* allEvents = (TH1F*)currentFile->Get("allEventsFilter/totalEvents"); float totalEvents = allEvents->GetBinContent(1); cutFlow.clear(); for(int m = 0; m<cutList.size(); m++){ TH1F* tmph1 = (TH1F*)currentFile->Get( (cutList[m].first).c_str() ); if(tmph1!=0){ cutFlow.push_back( tmph1->GetBinContent(1) ); //cout << tmph1->GetBinContent(1) << endl; } } TTree* currentTree = (TTree*)currentFile->Get("muTauStreamAnalyzer/tree"); string h1Name = "h1_"+(fileList_[i].second).first; TH1F* h1 = new TH1F( h1Name.c_str() ,"", (int)(cutFlow.size()+3) ,0 , cutFlow.size()+3); if( ((fileList_[i].second).first).find("Zjets")!=string::npos ) { h1->SetLineColor(kRed); leg->AddEntry(h1,"MadGraph Z+jets","F"); } if( ((fileList_[i].second).first).find("ttbar")!=string::npos ) { h1->SetLineColor(kBlue); leg->AddEntry(h1,"MadGraph t#bar{t}+jets","F"); } if( ((fileList_[i].second).first).find("Wjets")!=string::npos ) { h1->SetLineColor(kGreen); leg->AddEntry(h1,"MadGraph W+jets","F"); } if( ((fileList_[i].second).first).find("tW")!=string::npos ){ h1->SetLineColor( 44 ); leg->AddEntry(h1,"MadGraph single-top","F"); } if( ((fileList_[i].second).first).find("QCD")!=string::npos ) { h1->SetLineColor(11); leg->AddEntry(h1,"Pythia QCD","F"); } if( ((fileList_[i].second).first).find("qqH115")!=string::npos ) { h1->SetLineColor(kBlack); h1->SetLineStyle(kDashed); h1->SetLineWidth(3.0); signalScale = signalScale_; leg->AddEntry(h1,Form("VBF H(115)#rightarrow#tau#tau X %.0f",signalScale),"l"); } if( ((fileList_[i].second).first).find("qqH135")!=string::npos ) { h1->SetLineColor(kBlack); h1->SetLineStyle(kDotted); h1->SetLineWidth(3.0); signalScale = signalScale_; leg->AddEntry(h1,Form("VBF H(135)#rightarrow#tau#tau X %.0f",signalScale),"l"); } h1->SetBinContent(1,totalEvents); h1->GetXaxis()->SetBinLabel(1,"#sigma*BR*#int L"); for(int m = 0; m<cutFlow.size(); m++){ h1->SetBinContent(m+2,cutFlow[m]); h1->GetXaxis()->SetBinLabel(m+2, (cutList[m].second).c_str() ); } h1->GetXaxis()->SetBinLabel(cutFlow.size()+2,"VBF 1%"); h1->GetXaxis()->SetBinLabel(cutFlow.size()+3,"CJV (15 GeV)"); int nEntries = currentTree->GetEntries() ; std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* diTauSVfit3; std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* jets; currentTree->SetBranchAddress("diTauSVfit3P4",&diTauSVfit3); currentTree->SetBranchAddress("jetsIDP4",&jets); for (int n = 0; n < nEntries ; n++) { currentTree->GetEntry(n); if( diTauSVfit3->size() < 1) continue; bool vbfCut = false; bool jetVeto = false; if( jets->size()>1 && (*jets)[0].Et()>pt1_ && (*jets)[1].Et()>pt2_ && abs((*jets)[0].Eta()-(*jets)[1].Eta())>DEta_ && ((*jets)[0]+(*jets)[1]).M()>Mjj_ ) vbfCut = true; for(unsigned k=0; k < jets->size(); k++){ if(k>1 && ( ((*jets)[k].Eta()>(*jets)[1].Eta()+0.5 && (*jets)[k].Eta()<(*jets)[0].Eta()-0.5) || ((*jets)[k].Eta()>(*jets)[0].Eta()+0.5 && (*jets)[k].Eta()<(*jets)[1].Eta()-0.5) ) && (*jets)[k].Et()>jetVeto_ ) jetVeto=true; } if(vbfCut) h1->Fill( cutFlow.size()+1.5 ) ; if(vbfCut && !jetVeto) h1->Fill( cutFlow.size()+2.5 ) ; } h1->Scale( Lumi_ / (totalEvents/((fileList_[i].second).second * signalScale)) ); if(((fileList_[i].second).first).find("qqH115")!=string::npos){ hqqH115=(TH1F*)h1->Clone("hqqH115"); hqqH115 = h1; hqqH115->Sumw2(); continue; } if(((fileList_[i].second).first).find("qqH135")!=string::npos){ hqqH135=(TH1F*)h1->Clone("hqqH135"); hqqH135 = h1; hqqH135->Sumw2(); continue; } if(i==0) hSiml=(TH1F*)h1->Clone("hSiml"); else hSiml->Add(h1); histos.push_back(h1); } //float numData = hData->GetEntries(); //float numSiml = hSiml->Integral(); //float dataToSimlRatio = numData/numSiml; //cout << "data " << numData << " --- simul " << numSiml << endl; hqqH115->SetTitle(Form("CMS Preliminary 2010 #sqrt{s}=7 TeV L=%.0f pb^{-1}",Lumi_)); hqqH115->SetXTitle(""); hqqH115->SetYTitle("Number of events"); hqqH115->SetTitleSize(0.05,"X"); hqqH115->SetTitleSize(0.05,"Y"); hqqH115->SetTitleOffset(0.75,"Y"); hqqH115->SetAxisRange(0.1,hSiml->GetMaximum()*1.2,"Y"); hqqH115->Draw("HIST"); hqqH135->Draw("HISTSAME"); for(int p = 0; p<histos.size(); p++){ histos[p]->Draw("HISTSAME"); } leg->Draw(); pad2->cd(); TH1F* hRatio = new TH1F("hRatio", " ; ; purity", hqqH115->GetNbinsX(), hqqH115->GetXaxis()->GetXmin(), hqqH115->GetXaxis()->GetXmax()); hRatio->SetLineStyle(kDashed); hRatio->SetLineWidth(1.0); hRatio->SetLabelSize(0.12,"X"); hRatio->SetLabelSize(0.10,"Y"); hRatio->SetTitleSize(0.12,"Y"); hRatio->SetTitleOffset(0.36,"Y"); TH1F* hqqH115Clone = (TH1F*)hqqH115->Clone("hqqH115Clone"); TH1F* hqqH135Clone = (TH1F*)hqqH135->Clone("hqqH135Clone"); hqqH115Clone->Divide( hqqH115 ,hSiml,1./signalScale,1.0); hqqH135Clone->Divide( hqqH135 ,hSiml,1./signalScale,1.0); hRatio->SetAxisRange(0.,0.1,"Y"); hRatio->Draw(); hqqH115Clone->Draw("HISTSAME"); hqqH135Clone->Draw("HISTSAME"); if(SAVE) c1->SaveAs("Zmm_CutFlowNotStaggeredMass.png"); }
void plotInclusiveMass( FileList fileList , float Lumi_ = 30) { for(int i = 0; i<fileList.size(); i++){ (fileList[i].first)->Close(); delete (fileList[i].first); } TFile* fVBF115 = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_VBFH115.root","READ"); TFile* fVBF135 = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_VBFH135.root","READ"); TFile* fDYJets = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_DYJets-madgraph-50-PU.root","READ"); TFile* fTT = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_TT-madgraph-PU.root","READ"); TFile* fWJets = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_WJets-madgraph-PU.root","READ"); TFile* fT = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_TToBLNu-tW-madhraph-PU.root","READ"); TFile* fQCD = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_QCD-pythia-PU.root","READ"); FileList fileList_; fileList_.push_back( make_pair(fT, make_pair("tW", 10.6 ) )); fileList_.push_back( make_pair(fQCD, make_pair("QCD", 349988.0 ) )); fileList_.push_back( make_pair(fWJets, make_pair("Wjets", 31314.0 ) )); fileList_.push_back( make_pair(fTT, make_pair("ttbar", 157.5 ) )); fileList_.push_back( make_pair(fDYJets, make_pair("Zjets", 3048.0 ) )); fileList_.push_back( make_pair(fVBF115, make_pair("qqH115", 0.1012 ) )); fileList_.push_back( make_pair(fVBF135, make_pair("qqH135", 0.05049) )); TCanvas *c1 = new TCanvas("c1InclusiveMass","",5,30,650,600); c1->SetGrid(0,0); c1->SetFillStyle(4000); c1->SetFillColor(10); c1->SetTicky(); c1->SetObjectStat(0); c1->SetLogy(1); TPad* pad1 = new TPad("pad1InclusiveMass","",0.05,0.27,0.96,0.97); TPad* pad2 = new TPad("pad2InclusiveMass","",0.05,0.02,0.96,0.26); pad1->SetFillColor(0); pad2->SetFillColor(0); pad1->Draw(); pad2->Draw(); pad1->cd(); pad1->SetLogy(1); TLegend* leg = new TLegend(0.60,0.47,0.90,0.85,NULL,"brNDC"); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetFillColor(10); leg->SetTextSize(0.04); leg->SetHeader( "#mu+#tau Inclusive" ); THStack* aStack = new THStack("aStack",Form("CMS Preliminary 2010 #sqrt{s}=7 TeV L=%.0f pb^{-1}",Lumi_)); TH1F* hqqH115 = new TH1F(); TH1F* hqqH135 = new TH1F(); TH1F* hSiml = new TH1F(); float signalScale = 1; for(unsigned int i = 0 ; i < fileList_.size() ; i++){ TFile* currentFile = (TFile*)fileList_[i].first ; if( currentFile->IsZombie() ) continue; TH1F* allEvents = (TH1F*)currentFile->Get("allEventsFilter/totalEvents"); float totalEvents = allEvents->GetBinContent(1); TTree* currentTree = (TTree*)currentFile->Get("muTauStreamAnalyzer/tree"); string h1Name = "h1_"+(fileList_[i].second).first; TH1F* h1 = new TH1F( h1Name.c_str() ,"", 28 , 20, 300); if( ((fileList_[i].second).first).find("Zjets")!=string::npos ) { h1->SetFillColor(kRed); leg->AddEntry(h1,"MadGraph Z+jets","F"); } if( ((fileList_[i].second).first).find("ttbar")!=string::npos ) { h1->SetFillColor(kBlue); leg->AddEntry(h1,"MadGraph t#bar{t}+jets","F"); } if( ((fileList_[i].second).first).find("Wjets")!=string::npos ) { h1->SetFillColor(kGreen); leg->AddEntry(h1,"MadGraph W+jets","F"); } if( ((fileList_[i].second).first).find("tW")!=string::npos ){ h1->SetFillColor( 44 ); leg->AddEntry(h1,"MadGraph single-top","F"); } if( ((fileList_[i].second).first).find("QCD")!=string::npos ) { h1->SetFillColor(11); leg->AddEntry(h1,"Pythia QCD","F"); } if( ((fileList_[i].second).first).find("qqH115")!=string::npos ) { h1->SetLineColor(kBlack); h1->SetLineStyle(kDashed); h1->SetLineWidth(3.0); leg->AddEntry(h1,"VBF H(115)#rightarrow#tau#tau X 100","l"); signalScale = 100; } if( ((fileList_[i].second).first).find("qqH135")!=string::npos ) { h1->SetLineColor(kBlack); h1->SetLineStyle(kDotted); h1->SetLineWidth(3.0); leg->AddEntry(h1,"VBF H(135)#rightarrow#tau#tau X 100","l"); signalScale = 100; } int nEntries = currentTree->GetEntries() ; std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* diTauSVfit3; currentTree->SetBranchAddress("diTauSVfit3P4",&diTauSVfit3); for (int n = 0; n < nEntries ; n++) { currentTree->GetEntry(n); if( diTauSVfit3->size() < 1) continue; h1->Fill( (*diTauSVfit3)[0].M() ) ; } h1->Scale( Lumi_ / (totalEvents/((fileList_[i].second).second * signalScale)) ); if(((fileList_[i].second).first).find("qqH115")!=string::npos){ hqqH115=(TH1F*)h1->Clone("hqqH115"); hqqH115 = h1; hqqH115->Sumw2(); continue; } if(((fileList_[i].second).first).find("qqH135")!=string::npos){ hqqH135=(TH1F*)h1->Clone("hqqH135"); hqqH135 = h1; hqqH135->Sumw2(); continue; } if(i==0) hSiml=(TH1F*)h1->Clone("hSiml"); else hSiml->Add(h1); aStack->Add(h1); } //float numData = hData->GetEntries(); //float numSiml = hSiml->Integral(); //float dataToSimlRatio = numData/numSiml; //cout << "data " << numData << " --- simul " << numSiml << endl; aStack->Draw("HIST"); hqqH115->Draw("HISTSAME"); hqqH135->Draw("HISTSAME"); TH1F* hStack = (TH1F*)aStack->GetHistogram(); hStack->SetXTitle("SVfit #tau#tau mass"); hStack->SetYTitle(Form("Number of events/%.0f GeV",hStack->GetBinWidth(1))); hStack->SetTitleSize(0.05,"X"); hStack->SetTitleSize(0.05,"Y"); hStack->SetTitleOffset(0.75,"Y"); leg->Draw(); pad2->cd(); TH1F* hRatio = new TH1F("hRatio", " ; ; purity", hStack->GetNbinsX(), hStack->GetXaxis()->GetXmin(), hStack->GetXaxis()->GetXmax()); hRatio->SetLineStyle(kDashed); hRatio->SetLineWidth(1.0); hRatio->SetLabelSize(0.12,"X"); hRatio->SetLabelSize(0.10,"Y"); hRatio->SetTitleSize(0.12,"Y"); hRatio->SetTitleOffset(0.36,"Y"); TH1F* hqqH115Clone = (TH1F*)hqqH115->Clone("hqqH115Clone"); TH1F* hqqH135Clone = (TH1F*)hqqH135->Clone("hqqH135Clone"); hqqH115Clone->Divide( hqqH115 ,hSiml,1./signalScale,1.0); hqqH135Clone->Divide( hqqH135 ,hSiml,1./signalScale,1.0); hRatio->SetAxisRange(0.,0.001,"Y"); hRatio->Draw(); hqqH115Clone->Draw("HISTSAME"); hqqH135Clone->Draw("HISTSAME"); if(SAVE) c1->SaveAs("Zmm_InclusiveMass.png"); }
void plot(){ typedef std::map<double, ROOT::Math::XYZTVector , User::moreStruct>::iterator CImap; TFile* file = new TFile("./vbfTree.root","READ"); TCanvas *c1 = new TCanvas("c1Mass","",5,30,650,600); c1->SetGrid(0,0); c1->SetFillStyle(4000); c1->SetFillColor(10); c1->SetTicky(); c1->SetObjectStat(0); c1->SetLogy(1); TPad* pad1 = new TPad("pad1","",0.05,0.27,0.96,0.97); TPad* pad2 = new TPad("pad2","",0.05,0.02,0.96,0.26); pad1->SetFillColor(0); pad2->SetFillColor(0); pad1->Draw(); pad2->Draw(); pad1->cd(); pad1->SetLogy(1); TLegend* leg = new TLegend(0.55,0.45,0.85,0.75,NULL,"brNDC"); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetFillColor(10); leg->SetTextSize(0.04); leg->SetHeader("#splitline{POWHEG+PYTHIA qqH(115)#rightarrow#tau#tau}{jets matched to tag partons}"); TTree* currentTree = (TTree*)file->Get("vbfJetAnalyzer/tree"); int nEntries = currentTree->GetEntries() ; TH1F* h_TagMult = new TH1F("h_TagMult"," ; multiplicity ; a.u. ", 6,-0.5,5.5); TH1F* h_ptTag1 = new TH1F("h_ptTag1","; p_{T} (GeV/c); a.u. ", 60,0,300); TH1F* h_ptTag2 = new TH1F("h_ptTag2","; p_{T} (GeV/c); a.u. ", 60,0,300); TH1F* h_ptTag3 = new TH1F("h_ptTag3","; p_{T} (GeV/c); a.u. ", 60,0,300); std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* jets; std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* tagjets; currentTree->SetBranchAddress("jetsP4", &jets); currentTree->SetBranchAddress("tagjetsP4",&tagjets); for (int n = 0; n < nEntries ; n++) { currentTree->GetEntry(n); std::map<double, ROOT::Math::XYZTVector , User::moreStruct> sortedTagJets; for(unsigned int i = 0; i < tagjets->size(); i++){ sortedTagJets.insert( make_pair( (*tagjets)[i].Et(),(*tagjets)[i] ) ) ; } std::map<double, ROOT::Math::XYZTVector , User::moreStruct> sortedJets; for(unsigned int i = 0; i < jets->size(); i++){ sortedJets.insert( make_pair( (*jets)[i].Et(),(*jets)[i] ) ) ; } h_TagMult->Fill(tagjets->size()); int counter=0; for(CImap it = sortedTagJets.begin(); it!=sortedTagJets.end(); it++){ if( counter==0 ) h_ptTag1->Fill( (it->second).Et() ); if( counter==1 ) h_ptTag2->Fill( (it->second).Et() ); if( counter==2 ) h_ptTag3->Fill( (it->second).Et() ); counter++; } } h_ptTag1->SetLineColor(kRed); h_ptTag1->SetLineStyle(kSolid); h_ptTag2->SetLineColor(kBlue); h_ptTag2->SetLineStyle(kDashed); h_ptTag2->SetLineColor(kMagenta); h_ptTag2->SetLineStyle(kDotted); cout << "1st jet " << h_ptTag1->GetEntries() << endl; cout << "2nd jet " << h_ptTag2->GetEntries() << endl; cout << "3rd jet " << h_ptTag3->GetEntries() << endl; h_ptTag3->Draw("HISTS"); h_ptTag1->Draw("HISTSAME"); h_ptTag2->Draw("HISTSAME"); leg->AddEntry(h_ptTag1,"1st largest-p_{T} jet","L"); leg->AddEntry(h_ptTag2,"2nd largest-p_{T} jet","L"); leg->AddEntry(h_ptTag3,"3rd largest-p_{T} jet","L"); leg->Draw(); pad2->cd(); TH1F* hLow = (TH1F*)h_TagMult->Clone(); hLow->SetLabelSize(0.12,"X"); hLow->SetLabelSize(0.10,"Y"); hLow->SetTitleSize(0.12,"Y"); hLow->SetTitleSize(0.12,"X"); hLow->SetTitleOffset(0.36,"Y"); hLow->SetTitleOffset(0.36,"X"); hLow->Draw("HIST"); }
void compareplots(){ vector<TFile*> files; files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_100/ttbar2JetLO8TeVMECut50GeVCTEQ6M-extracted.root")); files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_100/ttbarMergedMS100GeVMCCut50GeV8TeVCTEQ6M-extracted.root")); vector<TString> names; names.push_back("ttbar+2 Jets, in LO"); names.push_back("ttbar+1 Jet, FxFx-Merged"); vector<TString> titles; titles.push_back("Gen-Jet p_{T} with pos weights (GeV)"); titles.push_back("Gen-Jet p_{T} with neg weights (GeV)"); titles.push_back("Gen-Jet p_{T} (GeV)"); titles.push_back("Gen_Jet #phi with pos. weights"); titles.push_back("Gen_Jet #phi with neg. weights"); titles.push_back("Gen_Jet #phi"); titles.push_back("Gen Jet #theta with pos weights"); titles.push_back("Gen Jet #theta with neg weights"); titles.push_back("Gen Jet #theta"); titles.push_back("Gen Jet Energy with pos weights (GeV) "); titles.push_back("Gen Jet Energy with neg weights (GeV)"); titles.push_back("Gen Jet Energy (GeV)"); titles.push_back("p_{T} of hardest Gen-Jet with pos weights (GeV)"); titles.push_back("p_{T} of hardest Gen-Jet with neg weights (GeV)"); titles.push_back("p_{T} of hardest Gen-Jet (GeV)"); titles.push_back("p_{T} of 2nd hardest Gen-Jet with pos weights (GeV)"); titles.push_back("p_{T} of 2nd hardest Gen-Jet with neg weights (GeV)"); titles.push_back("p_{T} of 2nd hardest Gen-Jet (GeV)"); titles.push_back("#eta of hardest Gen-Jets with pos weights"); titles.push_back("#eta of hardest Gen-Jets with neg weights"); titles.push_back("#eta of hardest Gen-Jets"); titles.push_back("Number of Gen-Jets with pos. weights"); titles.push_back("Number of Gen-Jets with neg. weights"); titles.push_back("Number of Gen-Jets"); TFile *vergleich = new TFile("vergleich_ttbar_Fx_vs_noFx.root","RECREATE"); // Show no statistics box gStyle->SetOptStat(0); TH1::SetDefaultSumw2(); // Main program part TIter nextkey(files.at(0)->GetListOfKeys()); TKey *key; bool first=true; TCanvas* c = new TCanvas(); c->Print("plots.pdf["); // Save also as pictures int pictureNumber = 0; int run = 0; while (key = (TKey*)nextkey()) { pictureNumber++; TString pictureName = TString::Format("%d.png",pictureNumber); vector<TH1F*> histos; histos.push_back((TH1F*)key->ReadObj()); for(size_t i=1;i<files.size();i++){ histos.push_back((TH1F*)files.at(i)->Get(histos.at(0)->GetName())); } for(size_t i=0;i<histos.size();i++){ if(i == 0){ histos.at(i)->SetLineColor(kBlack); } if(i == 1){ histos.at(i)->SetLineColor(kRed); } if(i == 2){ histos.at(i)->SetLineColor(kBlue); } if(i == 3){ histos.at(i)->SetLineColor(kGreen+2); } if(i == 4){ histos.at(i)->SetLineColor(kMagenta-7); } if(i == 5){ histos.at(i)->SetLineColor(kOrange+7); } } for(size_t i=0;i<histos.size();i++){ histos.at(i)->Sumw2(); histos.at(i)->Scale(1./histos.at(i)->Integral(),"width"); } // Set axis title histos.at(0)->GetYaxis()->SetTitle("Normalized units"); std::string const histogramName = histos.at(0)->GetName(); histos.at(0)->GetXaxis()->SetLabelSize(0.06); histos.at(0)->GetXaxis()->SetLabelOffset(0.006); histos.at(0)->GetYaxis()->SetLabelSize(0.06); histos.at(0)->GetYaxis()->SetLabelOffset(0.006); histos.at(0)->GetXaxis()->SetTitleSize(0.06); histos.at(0)->GetXaxis()->SetTitleOffset(1.1); histos.at(0)->GetYaxis()->SetTitleSize(0.06); histos.at(0)->GetYaxis()->SetTitleOffset(1.08); histos.at(0)->GetXaxis()->SetTitle(titles.at(run)); run = run+1; if(run == (3*8)){ run = 0; } // If only two histograms per plot make a ratio plot if(histos.size() == 2) { //create main pad TPad *mainPad = new TPad("","",0.0,0.3,1.0,1.0); mainPad->SetNumber(1); mainPad->SetBottomMargin(0.0); mainPad->SetRightMargin(0.04); mainPad->SetLeftMargin(0.13); mainPad->Draw(); //create ratio pad TPad *ratioPad = new TPad("","",0.0,0.0,1.0,0.3); ratioPad->SetTopMargin(0.0); ratioPad->SetBottomMargin(0.4); ratioPad->SetLeftMargin(0.13); ratioPad->SetRightMargin(0.04); gStyle->SetOptTitle(0); ratioPad->SetFillColor(0); ratioPad->SetNumber(2); ratioPad->SetGridy(); ratioPad->Draw(); // Draw both histograms first c->cd(1); histos.at(0)->Draw("histo E"); histos.at(1)->Draw("histo same E"); // Show legend and statistical tests in first pad for(size_t i=0;i<histos.size()-1;i=i+2){ double ksresult = histos.at(i)->KolmogorovTest(histos.at(i+1)); ksresult=floor(ksresult*1000+0.5)/1000; double chi2result =histos.at(i)->Chi2Test(histos.at(i+1),"WW"); chi2result=floor(chi2result*1000+0.5)/1000; stringstream ss; ss << " KS: " <<std::setprecision(3) << ksresult << " chi2: " <<std::setprecision(3) << chi2result << " Private Work"; const char * ch = & ss.str().c_str();; TLatex * ks = new TLatex(0.1, 0.9-0.03*i, ch ); ks->SetTextColor(histos.at(i)->GetLineColor()); ks->SetNDC(); ks->Draw(""); } TLegend* l = new TLegend(0.55,0.9,0.69,0.99); // Options for legend l->SetBorderSize(0); l->SetLineStyle(0); l->SetTextSize(0.049); l->SetFillStyle(0); for(size_t i=0;i<names.size();i++){ l->AddEntry(histos.at(i),names.at(i),"L"); } l->Draw("same"); // Clone histograms and draw ratio plot c->cd(2); TH1F* ratioHisto = (TH1F*)histos.at(0)->Clone(); ratioHisto->Divide(histos.at(1)); ratioHisto->SetLineColor(kBlue); ratioHisto->SetStats(false); ratioHisto->GetYaxis()->SetTitle("Ratio #frac{noFxFx}{FxFx}"); // Same Size like in histogram ratioHisto->SetLabelSize(histos.at(0)->GetLabelSize() * 0.7 / 0.3); ratioHisto->SetTitleOffset((histos.at(0)->GetTitleOffset("Y") * 0.3 / 0.7), "Y"); ratioHisto->SetTitleSize((histos.at(0)->GetTitleSize("Y") * 0.7 / 0.3), "Y"); ratioHisto->SetTitleOffset((histos.at(0)->GetTitleOffset("X")), "X"); ratioHisto->SetTitleSize((histos.at(0)->GetTitleSize("X") * 0.7 / 0.3), "X"); // Use nicer range ratioHisto->GetYaxis()->SetRangeUser(0, 2.2); ratioHisto->GetYaxis()->SetNdivisions(503); ratioHisto->GetYaxis()->SetLabelSize(0.06 * 0.7 / 0.3); ratioHisto->Draw(); } else { histos.at(0)->Draw("histo E"); for(size_t i=0;i<histos.size();i++){ histos.at(i)->Draw("histo same E"); } for(size_t i=0;i<histos.size()-1;i=i+2){ double ksresult = histos.at(i)->KolmogorovTest(histos.at(i+1)); ksresult=floor(ksresult*1000+0.5)/1000; double chi2result =histos.at(i)->Chi2Test(histos.at(i+1),"WW"); chi2result=floor(chi2result*1000+0.5)/1000; stringstream ss; ss << "KS: " <<std::setprecision(3) << ksresult << " chi2: " <<std::setprecision(3) << chi2result; const char * ch = & ss.str().c_str();; TText * ks = new TText(0.1, 0.9-0.03*i, ch ); ks->SetTextColor(histos.at(i)->GetLineColor()); ks->SetNDC(); ks->Draw(""); } TLegend* l = new TLegend(0.65,0.5,0.9,0.7); l->SetBorderSize(0); l->SetLineStyle(0); // l->SetTextSize(0.039); l->SetFillStyle(0); for(size_t i=0;i<names.size();i++){ l->AddEntry(histos.at(i),names.at(i),"L"); } l->Draw("same"); } c->Print("plots.pdf"); c->SaveAs(pictureName); vergleich->WriteTObject(c); } c->Print("plots.pdf]"); }