int makePlots(float mass) { const int makeGraphs = 0; double rate_data = 104; // ritva double rate_hh; double rate_hw; double rate_qcd = 7.5; // alexandros double rate_ewk = 71.2; // matti // Check that these numbers correspond to // the rates in the datacard if (mass==120) { rate_hh = 608.872; // ritva rate_hw = 303.188; // ritva } else if (mass==100) { rate_hh = 568.476; rate_hw = 208.439; } else if (mass==160) { rate_hh = 233.449 ; rate_hw = 441.343 ; } else { cout<< "Illegal data point!" << endl; exit(-1); } char tmp[200]; int rebin = 1; // EWK from Matti TFile *file1 = new TFile("mt_ewk_lands.root","read"); TH1F *histo1 = (TH1F *) file1->Get("mt_ewk"); // from Ritva TFile *file2 = new TFile("mt_lands_ritva3.root","read"); TH1F *histo21 = (TH1F *) file2->Get("mt_data"); // now HW and HH from Matti's new file TFile *fileMatti = new TFile("mt_matti.root","read"); sprintf(tmp,"mt_hw_%.0f",mass); cout << "getting histo " << tmp << endl; TH1F *histo22 = (TH1F *) fileMatti->Get(tmp); sprintf(tmp,"mt_hh_%.0f",mass); TH1F *histo23 = (TH1F *) fileMatti->Get(tmp); // from Alexandros TFile *file3 = new TFile("fromAlexandros.root"); TH1F * histo3 = (TH1F *) file3->Get("Data_met_AfterBigBox"); // empty dummy histos TH1F * histoD1; TH1F * histoD2; histoD1 = new TH1F("T2_tt","T2_tt",40/rebin,0,400); histoD2 = new TH1F("res.","res.",40/rebin,0,400); histo1 ->Scale( rate_ewk /histo1->Integral() ); histo21->Scale( rate_data/histo21->Integral() ); histo22->Scale( rate_hw /histo22->Integral() ); histo23->Scale( rate_hh /histo23->Integral() ); histo3-> Scale( rate_qcd /histo3->Integral() ); histo1->Rebin( rebin ); histo21->Rebin( rebin ); histo22->Rebin( rebin ); histo23->Rebin( rebin ); histo3->Rebin( rebin ); histoD1->Rebin( rebin ); histoD2->Rebin( rebin ); if (makeGraphs) { int bgColor = kBlue-9; int sigColor= kRed-9; TCanvas * tc = new TCanvas(); tc->Divide(3,2); int index=1; tc->cd(index++); histo1->Draw(); // black histo21->SetMarkerColor(kBlue); histo21->SetFillColor(kBlue); histo21->SetFillStyle(kBlue); tc->cd(index++);histo21->Draw();// blue tc->cd(index++);histo22->Draw();//red tc->cd(index++);histo23->Draw();//brown histo3->SetMarkerColor(kGreen); tc->cd(index++);histo3 ->Draw();//green histoD1->SetMarkerColor(kOrange); tc->cd(index++);histoD1 ->Draw();//orange tc->SaveAs("hplus_test.png"); TH1F * sumBG = new TH1F("sumBg","sumBg",40/rebin,0,400); TH1F * sumSig = new TH1F("sumSig","sumSig",40/rebin,0,400); TH1F * sumData; TCanvas * tu = new TCanvas(); sumBG->Add(histo1); sumBG->Add(histo3); // sumBG->SetMarkerColor(kBlue); // sumBG->SetFillColor(kBlue); sumBG->SetFillColor(bgColor); // sumBG->SetFillStyle(1001); // sumBG->SetMarkerStyle(2); // sumBG->Draw("hist"); const double f=0.1; sumSig->Add(histo23,f*f); sumSig->Add(histo22,2.0*(1.0-f)*f); // sumSig->SetMarkerColor(kRed); sumSig->SetFillColor(sigColor); // sumSig->SetMarkerStyle(2); // sumSig->Draw("same"); sumData = (TH1F * ) histo21->Clone("sumData"); sumData->SetMarkerColor(kBlack); // sumData->Draw("same"); THStack * st = new THStack(); st->Add(sumBG); st->Add(sumSig); st->Draw("histe"); THStack * st2 = st->Clone(); sumData->Draw("same"); st2->Draw("same E"); TLatex text; text.SetTextAlign(12); text.SetTextSize(0.04); text.SetNDC(); // char tmpLabel[30]; // sprintf(tmpLabel,"Peak at %.3f", // myhi->GetBinCenter(myhi->GetMaximumBin())); text.SetTextColor(bgColor); text.DrawLatex(0.4,0.85,"background (ewk+qcd)"); text.SetTextColor(sigColor); text.DrawLatex(0.4,0.75,"bg + signal (HW+HH, br_{t#rightarrowH^{+}b}=0.1) "); text.SetTextColor(kBlack); text.DrawLatex(0.4,0.65,"data"); tu->SaveAs("hplus_test_db.png"); } histo1 ->SetName("Type1"); histo21->SetName("data_obs"); histo22->SetName("HW_1"); histo23->SetName("HH_1"); histo3 ->SetName("QCD"); sprintf(tmp,"hplus_%.0f.root",mass); TFile * fileOut = new TFile(tmp,"recreate"); histo1->Write(); histo21->Write(); histo22->Write(); histo23->Write(); histo3->Write(); histoD1->Write(); histoD2->Write(); fileOut->Close(); return 0; }
void oneDlinearcombination(TH1F* first, int firsttype, TH1F* second, int secondtype, TH1F* input, int inputtype, TH1F* finaloutput, int outputtype, TH1F* finaloutput2, int output2type){ TH1F* output = (TH1F*) input->Clone(); TH1F* output2 = (TH1F*) output->Clone(); if(outputtype==kIntHist || outputtype==kSigHist){ if(inputtype==kBSI25Hist && firsttype==kSigHist && secondtype==kBkgHist){ output->Add(first, -25.0); output->Add(second, -1.0); output->Scale(0.2); if (outputtype == kSigHist){ delete output; output = (TH1F*) first->Clone(); } output2->Add(first, -25.0); output2->Add(second, -1.0); output2->Scale(0.2); if (output2type == kSigHist){ delete output2; output2 = (TH1F*) first->Clone(); } } if(inputtype==kBSI25Hist && firsttype==kBSIHist && secondtype==kBkgHist){ for (int binx = 1; binx <= output->GetNbinsX(); binx++){ double bsi = first->GetBinContent(binx); double bkg = second->GetBinContent(binx); double bsi25 = output->GetBinContent(binx); double weight=doLinearCombination(bsi25,25,bsi,1,bkg,outputtype); output->SetBinContent(binx,weight); if (finaloutput2 != 0){ double weight2 = doLinearCombination(bsi25, 25, bsi, 1, bkg, output2type); output2->SetBinContent(binx, weight2); } } } if(inputtype==kBSI25Hist && firsttype==kBSI10Hist && secondtype==kBkgHist){ for (int binx = 1; binx <= output->GetNbinsX(); binx++){ double bsi10 = first->GetBinContent(binx); double bkg = second->GetBinContent(binx); double bsi25 = output->GetBinContent(binx); double weight=doLinearCombination(bsi25,25,bsi10,10,bkg,outputtype); output->SetBinContent(binx,weight); if (finaloutput2 != 0){ double weight2 = doLinearCombination(bsi25, 25, bsi10, 10, bkg, output2type); output2->SetBinContent(binx, weight2); } } } if(inputtype==kBSI10Hist && firsttype==kBSIHist && secondtype==kBkgHist){ for (int binx = 1; binx <= output->GetNbinsX(); binx++){ double bsi = first->GetBinContent(binx); double bkg = second->GetBinContent(binx); double bsi10 = output->GetBinContent(binx); double weight=doLinearCombination(bsi10,10,bsi,1,bkg,outputtype); output->SetBinContent(binx,weight); if (finaloutput2 != 0){ double weight2 = doLinearCombination(bsi10, 10, bsi, 1, bkg, output2type); output2->SetBinContent(binx, weight2); } } } for (int binx = 1; binx <= output->GetNbinsX(); binx++){ finaloutput->SetBinContent(binx,output->GetBinContent(binx)); if (finaloutput2 != 0) finaloutput2->SetBinContent(binx,output2->GetBinContent(binx)); } } else{cout<<"Option not yet supported. Exiting..."<<endl; assert(0);}; delete output; delete output2; }
void ReactorNuAnalysis() { // -------- VARIABLE DEFINITIONS and SETUP -------- // Style settings gStyle->SetOptStat(""); // Constants Double_t NuSpectrumMinE = 0.0; // [MeV] Double_t NuSpectrumMaxE = 10.0; // [MeV] Int_t seed = 43534; const Double_t Gfermi = 1.16637e-11; // [MeV^-2] const Double_t Sin2ThetaW = 0.2387; const Double_t InverseMeVtoCm = 1.97e-11; const Double_t elementaryCharge = 1.602176565e-19; // Spectrum files (these are just samples for now) const char ReactorNeutronBackgroundFile[] = "SampleData.txt"; // Define constants relevant for this run Double_t OnOffTimeRatio = 1.0/1.0; Double_t time = 100 * 24.0*3600.0; // [sec] Double_t detMass = 5000.0; // [g] Double_t distance = 200.0; // [cm] Double_t activity = 6.0/200.0/elementaryCharge; // [sec^-1] const Int_t nNeutrons = 14; const Int_t nProtons = 14; const Double_t Qweak = nNeutrons - (1 - 4*Sin2ThetaW) * nProtons; const Double_t NucleonMass = (nNeutrons * 939.565) + (nProtons * 938.272); // [MeV] // Define the histograms TH1F* RecoilEvtHistogram = new TH1F("RecoilEvtHistogram","^{28}Si recoil energy spectrum;Energy [eV];Events / 10 eV",50,0.0,500.0); TH1F* NeutrinoEvtHistogram = new TH1F("NeutrinoEvtHistogram","#bar{#nu}_{e} energy spectrum;Energy [MeV];Events / 0.5 MeV",50,0.0,20); TH1F* TheoryRecoilEvtHistogram = new TH1F("TheoryRecoilEvtHistogram","High-statistics (\"theoretical\") Coherent Recoil Spectrum;Energy [eV];Events / 10 eV",50,0.0,500.0); TH1F* TheoryNeutrinoEvtHistogram = new TH1F("TheoryNeutrinoEvtHistogram","High-statistics (\"theoretical\") Neutrino Energy Spectrum;Energy [MeV] / 0.5 MeV;Events",50,0.0,20); TH1F* TheoryRecoilEvtHistogramFit = new TH1F("TheoryRecoilEvtHistogram","MC Fit;Events",50,0.0,0.002); TH1F* EMNoLukeBackground = new TH1F("EMNoLukeBackground","Background from EM recoils (before Luke Effect amplification;Energy [MeV];Events)",50,0.0,0.002); TH1F* ReactorNeutronBackground = new TH1F("ReactorNeutronBackground","Background from reactor neutrons;Energy [MeV];Events",50,0.0,0.002); TH1F* ReactorOnCosmoNeutronBackground = new TH1F("ReactorOnCosmoNeutronBackground","Reactor-on background from muon-induced neutrons;Energy [MeV];Events)",50,0.0,0.002); TH1F* ReactorOffCosmoNeutronBackground = new TH1F("ReactorOffCosmoNeutronBackground","Reactor-off background from muon-induced neutrons;Energy [MeV];Events)",50,0.0,0.002); TH1F* ReactorOnHisto = new TH1F("ReactorOnHisto","Recoil Spectrum for Reactor-On Data;Energy [MeV];Events",50,0.0,0.002); TH1F* ReactorOffHisto = new TH1F("ReactorOffHisto","Recoil Spectrum for Reactor-Off Data;Energy [MeV];Events",50,0.0,0.002); TH1F* BackgroundSubtractedSignal = new TH1F("BackgroundSubtractedSignal","Recoil Spectrum for Reactor-Off Data;Energy [MeV];Events",50,0.0,0.002); // Energy spectra // (Spectral parameterizations from arXiv:1101.2663v3) TF1* NeutrinoEnergySpectrum = new TF1("NeutrinoSpectrum", "TMath::Exp([0] + [1]*x + [2]*TMath::Power(x,2) + [3]*TMath::Power(x,3) + [4]*TMath::Power(x,4) + [5]*TMath::Power(x,5))", NuSpectrumMinE, NuSpectrumMaxE); NeutrinoEnergySpectrum->SetParameters(3.217, -3.111, 1.395, -0.369, 0.04445, -0.002053); TF1* IntegratedRecoilSpectrum = new TF1("IntegratedRecoilSpectrum", "TMath::Power([0]*[1]*[3],2)/(4*TMath::Pi()) * [2] * (x/(1 + [2]/(2*x))) * (1 - ([2]/(4*x*x)) * (x/(1 + [2]/(2*x))))", NuSpectrumMinE, NuSpectrumMaxE); IntegratedRecoilSpectrum->SetParameters(Gfermi, Qweak, NucleonMass, InverseMeVtoCm); TF1* RecoilSpectrum = new TF1("RecoilSpectrum","IntegratedRecoilSpectrum * NeutrinoSpectrum", 0.0, 10.0); TF1* DiffRecoilSpectrumAtConstE = new TF1("DiffRecoilSpectrumAtConstE", "(x<[4])*TMath::Power([0]*[1],2)/(4*TMath::Pi()) * [2] * (1 - ([2] * x)/(2 * TMath::Power([3],2))) + (x>[4])*0", NuSpectrumMinE, 0.01); DiffRecoilSpectrumAtConstE->SetParameters(Gfermi, Qweak, NucleonMass); // -------- HISTOGRAM FILLING -------- // Fill "experimental" histograms Int_t nEvt = GenerateNumOfNuRecoils(time, detMass, distance, activity, nNeutrons, nProtons, RecoilSpectrum, NuSpectrumMinE, NuSpectrumMaxE, seed); FillNuRecoilSpectrum(RecoilEvtHistogram, NeutrinoEvtHistogram, nEvt, nNeutrons, nProtons, RecoilSpectrum, DiffRecoilSpectrumAtConstE, NuSpectrumMinE, NuSpectrumMaxE, seed+4); FillRecoilSpectrumFromFile(ReactorNeutronBackground, 100.0, 10.0, ReactorNeutronBackgroundFile, seed+1); // Testing purposes only. CHANGE ME!! FillRecoilSpectrumFromFile(ReactorOnCosmoNeutronBackground, 50.0, 10.0, ReactorNeutronBackgroundFile, seed+2); // Testing purposes only. CHANGE ME!! FillRecoilSpectrumFromFile(ReactorOffCosmoNeutronBackground, 50.0, 10.0, ReactorNeutronBackgroundFile, seed+3); // Testing purposes only. CHANGE ME!! cout << "nEvt: " << nEvt << endl; // Fill high-statistics "theoretical" histograms FillNuRecoilSpectrum(TheoryRecoilEvtHistogram, TheoryNeutrinoEvtHistogram, 10000, nNeutrons, nProtons, RecoilSpectrum, DiffRecoilSpectrumAtConstE, NuSpectrumMinE, NuSpectrumMaxE, seed+5); TheoryNeutrinoEvtHistogram->Scale(nEvt/TheoryNeutrinoEvtHistogram->GetEntries()); TheoryRecoilEvtHistogram->Scale(nEvt/TheoryNeutrinoEvtHistogram->GetEntries()); // Combine the histograms into total ReactorOnHisto->Add(RecoilEvtHistogram); ReactorOnHisto->Add(ReactorNeutronBackground); ReactorOnHisto->Add(ReactorOnCosmoNeutronBackground); ReactorOffHisto->Add(ReactorOffCosmoNeutronBackground); // -------- HYPOTHESIS TESTING -------- cout << "p-value between Reactor-On and Reactor-Off Data: " << ReactorOnHisto->Chi2Test(ReactorOffHisto) << endl; cout << "p-value between the simulated data and the Monte Carlo histogram: " << RecoilEvtHistogram->Chi2Test(TheoryRecoilEvtHistogram) << endl; // -------- BACKGROUND SUBTRACTION and FITTING -------- // Normalize reactor-off data to reactor-on data by exposure BackgroundSubtractedSignal->Add(ReactorOnHisto, ReactorOffHisto, 1.0, -1.0*OnOffTimeRatio); // Use TFractionFitter to do fitting TObjArray *FractionFitData = new TObjArray(2); FractionFitData->Add(TheoryRecoilEvtHistogram); FractionFitData->Add(ReactorOffHisto); TFractionFitter* ffit = new TFractionFitter(ReactorOnHisto, FractionFitData); ffit->Constrain(0,0.1,10.0); ffit->Constrain(1,1.0,1.0); Int_t status = ffit->Fit(); TH1F* result = (TH1F*) ffit->GetPlot(); // Build a stacked histogram for plotting Double_t param, error; THStack *ReactorOnStackedFit = new THStack("ReactorOnStackedFit","Signal fits for Reactor-On data"); ffit->GetResult(0,param,error); TheoryRecoilEvtHistogramFit->Add(TheoryRecoilEvtHistogram,param); ReactorOnStackedFit->Add(TheoryRecoilEvtHistogramFit); ReactorOnStackedFit->Add(ReactorOffHisto); // -------- MAKE PLOTS -------- // Set drawing settings RecoilEvtHistogram->SetLineColor(1); NeutrinoEvtHistogram->SetLineColor(1); TheoryRecoilEvtHistogram->SetLineColor(2); TheoryNeutrinoEvtHistogram->SetLineColor(2); ReactorOnHisto->SetLineColor(1); result->SetLineColor(2); // Draw everything TCanvas* c1 = new TCanvas("c1"); RecoilEvtHistogram->Draw("E1"); TheoryRecoilEvtHistogram->Draw("same"); legend1 = new TLegend(0.6,0.7,0.89,0.89); legend1->AddEntry(RecoilEvtHistogram,"Data","lep"); legend1->AddEntry(TheoryRecoilEvtHistogram,"Monte Carlo","l"); legend1->SetFillColor(0); legend1->Draw(); TCanvas* c2 = new TCanvas("c2"); NeutrinoEvtHistogram->Draw("E1"); TheoryNeutrinoEvtHistogram->Draw("same"); legend2 = new TLegend(0.6,0.7,0.89,0.89); legend2->AddEntry(RecoilEvtHistogram,"Data","lep"); legend2->AddEntry(TheoryRecoilEvtHistogram,"Monte Carlo","l"); legend2->SetFillColor(0); legend2->Draw(); TCanvas* c3 = new TCanvas("c3"); ReactorOnHisto->Draw("E1"); ReactorOffHisto->Draw("E1,same"); legend3 = new TLegend(0.6,0.7,0.89,0.89); legend3->AddEntry(ReactorOnHisto,"Reactor On","lep"); legend3->AddEntry(ReactorOffHisto,"Reactor Off","lep"); legend3->SetFillColor(0); legend3->Draw(); TCanvas* c4 = new TCanvas("c4"); ReactorNeutronBackground->Draw("E1"); //This plot is broken: THStack is not being used correctly /*TCanvas* c5 = new TCanvas("c5"); ReactorOnHisto->Draw("E1"); TheoryRecoilEvtHistogramFit->SetFillColor(kRed); TheoryRecoilEvtHistogramFit->SetMarkerStyle(1); TheoryRecoilEvtHistogramFit->SetMarkerColor(kRed); ReactorOffHisto->SetFillColor(kBlue); ReactorOffHisto->SetMarkerStyle(1); ReactorOffHisto->SetMarkerColor(kBlue); ReactorOnStackedFit->Draw("same"); legend5 = new TLegend(0.6,0.7,0.89,0.89); legend5->AddEntry(ReactorOnHisto,"Reactor On","lep"); legend5->AddEntry(ReactorOffHisto,"Reactor Off"); legend5->AddEntry(TheoryRecoilEvtHistogramFit,"Coherent Scattering"); legend5->SetFillColor(0); legend5->Draw();*/ WriteHistogramToFile(RecoilEvtHistogram, "histogramOutput.txt"); WriteNuRecoilEvents("MonoenergeticEvents.txt", 0.811, nEvt, nNeutrons, nProtons, RecoilSpectrum, DiffRecoilSpectrumAtConstE, NuSpectrumMinE, NuSpectrumMaxE, seed+5); }
void createNNLOplot(TString theory="ahrens") { // theory="ahrens", "kidonakis" TString outputRootFile="test.root"; // NB: add new datset name here if(theory.Contains("ahrens") ){ outputRootFile="AhrensNLONNLL"; //if(theory.Contains("mtt") ) outputRootFile+="mttbar" ; //else if(theory.Contains("pt")) outputRootFile+="pTttbar"; outputRootFile+=".root"; } else if(theory=="kidonakis") outputRootFile="KidonakisAproxNNLO.root"; // general options gStyle->SetOptStat(0); bool usequad=true; bool divideByBinwidth=true; // list of variables std::vector<TString> xSecVariables_, xSecLabel_; // NB: add variables for new datset name here TString xSecVariablesUsedAhrens[] ={"ttbarMass", "ttbarPt"}; TString xSecVariablesUsedKidonakis[] ={"topPt" , "topY" }; if( theory.Contains("ahrens") ) xSecVariables_ .insert( xSecVariables_.begin(), xSecVariablesUsedAhrens , xSecVariablesUsedAhrens + sizeof(xSecVariablesUsedAhrens )/sizeof(TString) ); else if(theory=="kidonakis") xSecVariables_ .insert( xSecVariables_.begin(), xSecVariablesUsedKidonakis, xSecVariablesUsedKidonakis + sizeof(xSecVariablesUsedKidonakis)/sizeof(TString) ); // get variable binning used for final cross sections std::map<TString, std::vector<double> > bins_=makeVariableBinning(); //std::vector<double> tempbins_; //double ttbarMassBins[]={345,445,545,745, 1045}; //tempbins_.insert( tempbins_.begin(), ttbarMassBins, ttbarMassBins + sizeof(ttbarMassBins)/sizeof(double) ); //bins_["ttbarMass"]=tempbins_; // loop all variables for(unsigned var=0; var<xSecVariables_.size(); ++var){ TString variable=xSecVariables_[var]; std::cout << "----------" << std::endl; std::cout << theory << ": " << variable << std::endl; // get bin boundaries double low =bins_[variable][0]; double high=bins_[variable][bins_[variable].size()-1]; // -------------------------- // get raw nnlo theory points // -------------------------- // NB: add new datset file names here TGraph * rawHist; TString predictionfolder="/afs/naf.desy.de/group/cms/scratch/tophh/CommonFiles/"; if(theory=="ahrens" ){ if(variable.Contains("ttbarMass")) rawHist= new TGraph(predictionfolder+"AhrensTheory_Mttbar_8000_172.5_NLONNLL_norm.dat");//AhrensTheory_Mtt_7000_172.5_Mtt_fin.dat if(variable.Contains("ttbarPt" )) rawHist= new TGraph(predictionfolder+"AhrensTheory_pTttbar_8000_172.5_NLONNLL_abs.dat");//AhrensTheory_pTttbar_7000_172.5_NLONNLL_abs.dat } else if(theory=="kidonakis"){ if(variable.Contains("topPt")) rawHist= new TGraph(predictionfolder+"pttopnnloapprox8lhc173m.dat");//"ptnormalNNLO7lhc173m.dat" //"pttopnnloapprox8lhc173m.dat" if(variable.Contains("topY" )) rawHist= new TGraph(predictionfolder+"ytopnnloapprox8lhc173m.dat" );//"ynormalNNLO7lhc173m.dat" //"ytopnnloapprox8lhc173m.dat" } // NB: say if points should be interpreted as single points with // nothing in between or as integrated value over the range bool points=true; if(theory.Contains("ahrens")) points=false; else if(theory=="kidonakis") points=true; std::cout << "input: " << rawHist->GetTitle() << std::endl; std::cout << "interprete values as points?: " << points << std::endl; // -------------------- // convertion to TH1F* // -------------------- double *Xvalues = rawHist->GetX(); int Nbins=rawHist->GetN(); //double *Yvalues = rawHist->GetY(); // not working double xmax=-1; double xmin=-1; double binwidth=-1; // TH1F* hist; // NB: add additional binning for new theory here // NB: if loaded data should be interpreted as points with // nothing in between (like kidonakis), make suree you // choose a binning that is fine enough for the // data points loaded if(theory=="ahrens"){ if(variable.Contains("ttbarMass")){ xmin= 345.; xmax=2720.; binwidth=25.;// 5 for 8TeV, 25 for 7TeV if(TString(rawHist->GetTitle()).Contains("8000")) binwidth=5.; } else if(variable.Contains("ttbarPt")){ xmin= 0.; xmax=1300.; binwidth=5.; } } else if(theory=="kidonakis"){ if(variable.Contains("topPt")){ xmin= 0.; xmax=1500.; binwidth=1.; } else if(variable.Contains("topY")){ xmin=-3.8; xmax= 3.8; binwidth=0.01; } } // fill data in binned TH1F hist= new TH1F ( variable, variable, (int)((xmax-xmin)/binwidth), xmin, xmax); TH1F* ori=(TH1F*)hist->Clone("original points"); std::cout << "fine binned theory prediction has " << hist->GetNbinsX() << " bins" << std::endl; std::cout << "loaded values from .dat file: " << std::endl; // list all data values loaded and the corresponding bin for(int bin=1; bin<=Nbins; ++bin){ double x=-999; double y=-999; // NB: choose if loaded data is interpreted as points with nothing // between (like kidonakis) or as integrated over the bin range (like ahrens) if(points){ // check if you are still inside the array //std::cout << "data point " << bin-1 << "/" << sizeof(Xvalues)/sizeof(double) << std::endl; if(rawHist->GetPoint(bin-1, x, y)!=-1){ //x=Xvalues[bin-1]; // get value from data points x+=0.5*binwidth; // add half the binwidth to get the center of the bin } } else{ x=hist->GetBinCenter(bin); // get bin center y=rawHist->GetY()[bin-1]; } if(x!=-999){ std::cout << "data point: " << bin; std::cout << "(<x>=" << x << ")-> bin"; // get bin in target (fine binned) plot int bin2=bin; if(points) bin2=hist->FindBin(x); //double y=Yvalues[bin2-1]; std::cout << bin2 << " ("; std::cout << hist->GetBinLowEdge(bin2) << ".." << hist->GetBinLowEdge(bin2+1); std::cout << "): " << y << std::endl; // fill target (fine binned) plot if(!points) hist->SetBinContent(bin2, y); // mark bins coming from the original prediction ori->SetBinContent(bin2, 1.); // ------------------------------- // fit range without data entries // ------------------------------- // NB: needed if loaded data is interpreted as points with nothing // between (like kidonakis) if(points){ // perform a linear fit wrt previous point // get the two points (this bin and the previous one) int binPrev= (bin==1&&variable=="topPt") ? 0 : hist->FindBin(Xvalues[bin-2]+0.5*binwidth); double x2=-1; double x1= 0; double y2=-1; double y1= 0.; rawHist->GetPoint(bin-1, x2, y2); x2+=0.5*binwidth; if(bin==1&&variable=="topPt"){ y1=0; x1=0; } else{ rawHist->GetPoint(bin-2, x1, y1); x1+=0.5*binwidth; } // calculate linear funtion double a=(y2-y1)/(x2-x1); double b=y1-a*x1; TF1* linInterpol=new TF1("linInterpol"+getTStringFromInt(bin), "[0]*x+[1]", x1, x2); linInterpol->SetParameter(0,a); linInterpol->SetParameter(1,b); double xlow = (bin==1&&variable=="topPt") ? 0. : hist->GetBinLowEdge(binPrev+1); double xhigh = hist->GetBinLowEdge(bin2+1); std::cout << " lin. interpolation [ (" << x1 << "," << y1 << ") .. (" << x2 << "," << y2 << ") ]: " << a << "*x+" << b << std::endl; linInterpol->SetRange(xlow, xhigh); hist->Add(linInterpol); } } } // check theory curve std::cout << std::endl << "analyze theory curve:" << std::endl; double integralRawTheory=hist->Integral(0.,hist->GetNbinsX()+1); std::cout << "Integral: " << integralRawTheory << std::endl; if(integralRawTheory==0.){ std::cout << "ERROR: Integral can not be 0!" << std::endl; exit(0); } std::cout << "binwidth: " << binwidth << std::endl; std::cout << "Integral*binwidth: " << integralRawTheory*binwidth << std::endl; std::cout << "binRange: " << xmin << ".." << xmax << std::endl; std::cout << " -> reco range: " << low << ".." << high << std::endl; std::vector<double> recoBins_=bins_[variable]; for(unsigned int i=0; i<recoBins_.size(); ++i){ i==0 ? std::cout << "(" : std::cout << ", "; std::cout << recoBins_[i]; if(i==recoBins_.size()-1) std::cout << ")" << std::endl; } // check if you need to divide by binwidth if(std::abs(1.-integralRawTheory)<0.03){ std::cout << "Integral is approx. 1 -> need to divide by binwidth!" << std::endl; hist->Scale(1./binwidth); } else if(std::abs(1-integralRawTheory*binwidth)<0.03){ std::cout << "Integral*binwidth is approx. 1 -> no scaling needed!" << std::endl; } else{ std::cout << "need to normalize and divide by binwidth"; hist->Scale(1./(binwidth*integralRawTheory)); } // styling hist->GetXaxis()->SetRangeUser(low,high); hist->SetMarkerColor(kMagenta); hist->SetLineColor( kMagenta); hist->SetMarkerStyle(24); // create canvas std::cout << std::endl << "create canvas " << std::endl; TCanvas *canv = new TCanvas(variable,variable,800,600); canv->cd(); std::cout << "draw original theory curve " << std::endl; //temp->Draw("axis"); hist->Draw("p"); //hist->Draw("hist same"); // draw original points if(points){ for(int bin=1; bin<ori->GetNbinsX(); ++bin){ // create copy of original data points with the normalized values if(ori->GetBinContent(bin)!=0) ori->SetBinContent(bin, hist->GetBinContent(bin)); ori->SetMarkerColor(kBlack); ori->SetMarkerStyle(29); ori->SetMarkerSize(1); ori->Draw("p same"); } } // -------------------- // create rebinned plot // -------------------- std::cout << std::endl << "create rebinned curve:" << std::endl; TString name=""; // NB: add name for dataset here name=variable; if( theory=="kidonakis") name+="approxnnlo"; else if(theory=="ahrens" ) name+="nlonnll" ; TH1F* binnedPlot=new TH1F(name, name, bins_[variable].size()-1, &bins_[variable][0]); for(int bin=1; bin<=hist->GetNbinsX(); ++bin){ double y=hist->GetBinContent(bin)*hist->GetBinWidth(bin); double xlow =hist->GetBinLowEdge(bin); double xhigh=hist->GetBinLowEdge(bin+1); // search corresponding bin in rebinned curve bool found=false; //std::cout << "xlow: " << xlow << ", xhigh: " << xhigh << std::endl; // FIXME for(int binRebinned=0; binRebinned<=binnedPlot->GetNbinsX()+1; ++binRebinned){ if(binnedPlot->GetBinLowEdge(binRebinned)<=xlow&&binnedPlot->GetBinLowEdge(binRebinned+1)>=xhigh){ found=true; binnedPlot->SetBinContent(binRebinned, binnedPlot->GetBinContent(binRebinned)+y); break; } //else{ // std::cout << "not in: " << binnedPlot->GetBinLowEdge(binRebinned) << ".." << binnedPlot->GetBinLowEdge(binRebinned+1)<< std::endl; //} } // -------------------- // use linear interpolation for edge bins // -------------------- if(hist->GetBinCenter(bin)<high&&!found){ std::cout << "need interpolation for bin" << bin << "(<x>=" << hist->GetBinCenter(bin) << ")!"<< std::endl; // search for the two bins involved double binLow=0; double binHigh=0; for(int binRebinned=1; binRebinned<=binnedPlot->GetNbinsX(); ++binRebinned){ // search for bin in binned histo where upper border of is close to lower border of unbinned histo if(std::abs(binnedPlot->GetBinLowEdge(binRebinned+1)-xlow)<binwidth){ binLow =binRebinned; binHigh=binRebinned+1; break; } } std::cout << "theory bin " << xlow << ".." << xhigh << "-> reco bins "; std::cout << binnedPlot->GetBinLowEdge(binLow) << ".." << binnedPlot->GetBinLowEdge(binLow+1) << " & "; std::cout << binnedPlot->GetBinLowEdge(binHigh) << ".." << binnedPlot->GetBinLowEdge(binHigh+1) << std::endl; // get the two points (this bin and the previous one) double x2=hist->GetBinCenter (bin ); double x1=hist->GetBinCenter (bin-1); double x3=hist->GetBinCenter (bin+1); double y2=hist->GetBinContent(bin ); double y1=hist->GetBinContent(bin-1); double y3=hist->GetBinContent(bin+1); // calculate linear funtion double a=(y2-y1)/(x2-x1); double b=y1-a*x1; TF1* linInterpol=new TF1("linInterpol"+getTStringFromInt(bin), "[0]*x+[1]", x1, x2); linInterpol->SetParameter(0,a); linInterpol->SetParameter(1,b); // calculate the corresponding area of linear function to binned curve double contributionLowerBin=linInterpol->Integral(xlow,binnedPlot->GetBinLowEdge(binHigh)); double contributionUpperBin=linInterpol->Integral(binnedPlot->GetBinLowEdge(binHigh),xhigh); // draw interpolation function for checking linInterpol->SetRange(xlow,xhigh); linInterpol->SetLineColor(kMagenta); linInterpol->DrawClone("same"); // eventually use quadratic interpolation for the first harens m(ttbar) bin if(theory=="ahrens"&&variable.Contains("ttbarMass")&&usequad&&x2<450){ // calculate quadratic funtion double a2=(y2-((y3-y1))*(x2-x1)/(x3-x1))/(x2*x2-x1*x1-(x2-x1)*(x3*x3+x1*x1)/(x3-x1)); double b2=((y3-y1)-a2*(x3*x3-x1*x1))/(x3-x1); double c2=y1-a2*x1*x1-b*x1; TF1* quadInterpol=new TF1("quadInterpol"+getTStringFromInt(bin), "[0]*x*x+[1]*x+[2]", x1, x2); quadInterpol->SetParameter(0,a2); quadInterpol->SetParameter(1,b2); quadInterpol->SetParameter(2,c2); // draw quad interpolation function for checking quadInterpol->SetRange(xlow,xhigh); quadInterpol->SetLineColor(kGreen); quadInterpol->SetLineStyle(2); hist->Fit(quadInterpol, "", "same", x1, x3); // calculate the corresponding area of linear function to binned curve quadInterpol->DrawClone("same"); double areaLow =quadInterpol->Integral(xlow,binnedPlot->GetBinLowEdge(binHigh) ); double areaHigh=quadInterpol->Integral(binnedPlot->GetBinLowEdge(binHigh),xhigh); std::cout << "ratio(high/low) linear/quadratic: " << contributionUpperBin/contributionLowerBin << "/"<< areaHigh/areaLow << std::endl; contributionLowerBin=y2*binwidth*areaLow /(areaLow+areaHigh); contributionUpperBin=y2*binwidth*areaHigh/(areaLow+areaHigh); } // add fitted result binnedPlot->SetBinContent(binLow , binnedPlot->GetBinContent(binLow )+contributionLowerBin); binnedPlot->SetBinContent(binHigh, binnedPlot->GetBinContent(binHigh)+contributionUpperBin); } } // ensure over/underflow is 0 binnedPlot->SetBinContent(0, 0.); binnedPlot->SetBinContent(binnedPlot->GetNbinsX()+1, 0.); // ensure normalization binnedPlot->Scale(1./(binnedPlot->Integral(0.,binnedPlot->GetNbinsX()+1))); // divide by binwidth if(divideByBinwidth){ for(int bin=1; bin<=binnedPlot->GetNbinsX(); ++bin){ binnedPlot->SetBinContent(bin, binnedPlot->GetBinContent(bin)/binnedPlot->GetBinWidth(bin)); } } std::cout << "-------------------------------------------" << std::endl; std::cout << "result: binned output histo" << std::endl; for(int bin=1; bin<=binnedPlot->GetNbinsX(); ++bin){ std::cout << "content bin " << bin << " (" << binnedPlot->GetBinLowEdge(bin) << ".." << binnedPlot->GetBinLowEdge(bin+1) << ")= " << binnedPlot->GetBinContent(bin) << std::endl; } // styling binnedPlot->SetLineColor(kBlue); binnedPlot->SetLineWidth(2); std::cout << "draw rebinned theory curve " << std::endl; binnedPlot->Draw("hist same"); // draw bin boundaries std::cout << "draw bin boundaries " << std::endl; int binColor=kRed; int binWidth=2; int binStyle=6; for(int bin=0; bin<(int)bins_.size(); ++bin){ if(!variable.Contains("ttbarMass")||bins_[variable][bin]>=345.) drawLine(bins_[variable][bin], 0, bins_[variable][bin], hist->GetMaximum(), binColor, binWidth, binStyle); } TH1F* line=(TH1F*)hist->Clone("line"); line->SetLineColor(binColor); line->SetLineWidth(binWidth); line->SetLineStyle(binStyle); // legend TLegend *leg = new TLegend(0.7, 0.6, 0.95, 0.9); legendStyle(*leg,theory); if(points) leg ->AddEntry(ori, "original data points","P"); leg ->AddEntry(hist , "theory prediction" ,"P"); leg ->AddEntry(line , "reco binning" ,"L"); leg ->AddEntry(hist , "linear interpolation" ,"L"); leg ->AddEntry(binnedPlot, "rebinned curve" ,"L"); leg->Draw("same"); std::cout << "done" << std::endl; // save in png and rootfile std::cout << std::endl << "do saving..." << std::endl; canv->SaveAs(variable+"Norm_Theory.png"); TH1F* out=(TH1F*)binnedPlot->Clone(); out->SetTitle(variable); out->SetName (variable); out->GetXaxis()->SetTitle(xSecLabelName(variable)); TString yTile="#frac{1}{#sigma} #frac{d#sigma}{d"; if(variable=="ttbarMass") yTile+="m^{t#bar{t}}} [GeV^{-1}]"; if(variable=="ttbarPt") yTile+="p_{T}^{t#bar{t}}} [GeV^{-1}]"; if(variable=="topPt") yTile+="p_{T}^{t}} [GeV^{-1}]"; if(variable=="topY" ) yTile+="y^{t}}"; out->GetYaxis()->SetTitle(yTile); out->SetLineColor(kOrange+2); out->SetLineStyle(2); std::cout << std::endl << "draw final result " << std::endl; TCanvas *canv2 = new TCanvas(variable+"Rebinned",variable+"Rebinned",800,600); canv2->cd(); out->Draw(); saveToRootFile(outputRootFile, out , true, 0,"" ); saveToRootFile(outputRootFile, rawHist, true, 0,"graph" ); saveToRootFile(outputRootFile, canv , true, 0,"detail"); std::cout << "done!" << std::endl; } }
/************************************************************************************* * createMFOutfile: moves the MLB distributions into an output file for use in * R. Nally's MassFit.C code. * input: the main() arguments array * output: writes to an output file the histograms, in a MassFit.C-readable format * * Structure-wise: can be implemented into class easily. ***********************************/ void createMFOutfile(const char* argv[]) { TFile *f = new TFile(argv[2]); //create the output file we'd like to write histograms to TFile *output = new TFile(outfileName, "RECREATE"); //get the filesystem information from the file f->cd(); TList *alokDirs = (TList*) f->GetListOfKeys(); //create a list of "All" histograms and initialize (TODO) TList *allHists = new TList; //loop through the directories in the input file for(int idir=0; alokDirs->At(idir-1) != alokDirs->Last(); idir++) { //if it's not mlb, we don't care if(!TString(alokDirs->At(idir)->GetName()).Contains("_Mlb")) continue; //get the file directory information, its histograms TDirectory *cDir = (TDirectory*) f->Get(alokDirs->At(idir)->GetName()); TList *alokHistos = (TList*) cDir->GetListOfKeys(); //loop through the histograms in the current directory for(int ihisto=0; alokHistos->At(ihisto-1) != alokHistos->Last(); ihisto++) { // don't consider the graph objects if(TString(alokHistos->At(ihisto)->GetName()).Contains("Graph_")) continue; // clone the histogram, give it a new name TString cloneName = formatName(alokHistos->At(ihisto)->GetName(),nominalWidth); TH1F *thisto = (TH1F*) cDir->Get(alokHistos->At(ihisto)->GetName()); TH1F *tclone = (TH1F*) thisto->Clone(cloneName); // open the outfile and write the histo in output->cd(); TList *outkeys = (TList*) output->GetListOfKeys(); // if the histogram already exists, add thisto to the existing one // messy, but removes the need for magic for(int iout=0; outkeys->At(iout-1) != outkeys->Last(); iout++) { if(outkeys->At(iout)->GetName() == cloneName) { cout<<" - found another histogram in output with name "<<cloneName<<endl; TH1F *theHisto = (TH1F*) output->Get(cloneName); cout<<" - got the same histogram from the output file"<<endl; TH1F *tHclone = (TH1F*) theHisto->Clone(cloneName); cout<<" - cloned the histogram"<<endl; cout<<" - adding in clone"<<endl; tclone->Add(tHclone); cout<<" - deleting the original histogram from the output file"<<endl; output->Delete(cloneName + TString(";1")); cout<<" - deleted thing from output file"<<endl; cout<<" - tclone looks like "<<tclone<<endl; } } cout<<" - writing the tclone to file"<<endl; tclone->Write(); // reopen the input root file and clean up f->cd(); delete thisto; delete tclone; } } f->Close(); output->cd(); output->Close(); // if we want to interpolate, start making more histograms if(interpolate) { // Have to reopen the outfile because ROOT is odd TFile *output2 = new TFile(outfileName, "UPDATE"); output2->cd(); std::pair<double,TString> maxPair = *moreFiles.begin(); double maxWidth = maxPair.first; // check that it makes sense to interpolate with our settings if(maxWidth <= nominalWidth) { cout<<"\n\nERROR: Max width is less than or equal to the nominal width! Exiting."<<endl; exit(EXIT_FAILURE); } // open the input file and loop through the relevant directories TFile *maxFile = new TFile(maxPair.second); for(int i=0; i<lepsSize; i++) { // change directory and get the name of the folder we want to access maxFile->cd(); char a[128]; sprintf(a, "mlbwa_%s_Mlb", leps[i]); TDirectory *tDir = (TDirectory*) maxFile->Get(a); TList *alok = tDir->GetListOfKeys(); // get the maxWidth histogram in this folder, clone and rename it TString maxHName = alok->First()->GetName(); TString maxCloneName = formatName(maxHName, maxWidth); TH1F *maxHisto = (TH1F*) tDir->Get(maxHName); TH1F *maxClone = (TH1F*) maxHisto->Clone(maxCloneName); // write this max histogram to the outfile output2->cd(); maxClone->Write(); // get the corresponding nominal histogram from the outfile TH1F *nomHisto = (TH1F*) output2->Get(formatName(maxHName,nominalWidth)); TCanvas *c = new TCanvas(""); nomHisto->Draw(); c->SaveAs(formatName(maxHName,nominalWidth)+TString(".pdf")); // for each interpolation, create a morphed histogram and write to outfile for(int i=interpolations; i>0; i--) { double tWidth = nominalWidth + i*(maxWidth - nominalWidth)/(interpolations+1); TString interpName = formatName(maxHName, tWidth); TH1F *interpHisto = (TH1F*) th1fmorph(interpName, interpName,nomHisto,maxHisto, nominalWidth,maxWidth,tWidth,nomHisto->Integral(),1); interpHisto->Write(); } } maxFile->cd(); maxFile->Close(); output2->cd(); output2->Close(); // Otherwise, we want to collect signal histograms of different weights } else { // Have to reopen the outfile because ROOT is odd TFile *output2 = new TFile(outfileName, "UPDATE"); output2->cd(); // Loop through the additional files for(std::vector<std::pair<double, TString> >::const_iterator pf=moreFiles.begin(); pf!=moreFiles.end(); pf++) { // This is the current file and width TFile *curFile = new TFile(pf->second, "READ"); double curWid = pf->first; // Loop through lepton final states for(int i=0; i<lepsSize; i++) { curFile->cd(); // Get the desired directory char dirName[128]; sprintf(dirName, "mlbwa_%s_Mlb", leps[i]); TDirectory *curDir = (TDirectory*) curFile->Get(dirName); // Get the names of the first histogram in the directory // (we don't want more than one additional signal histo per extra file) // Format it with the usual method TString histName = TString(curDir->GetListOfKeys()->First()->GetName()); TString cloneName = formatName(histName,curWid); // Get the mlb histo TH1D *curHisto = (TH1D*) curDir->Get(histName)->Clone(cloneName); // Write to the outfile output2->cd(); curHisto->Write(); } curFile->Close(); } output2->cd(); output2->Close(); } }
void DeltaEta_norm(){ TLegend* leg = new TLegend(0.70,0.55,0.89,0.89); TFile *data = TFile::Open("./50ns_betaV4/DoubleEG.root","READ"); TFile *sig_M1 = TFile::Open("./50ns_betaV4/NewWeightDMHtoGG_M1.root","READ"); TFile *sig_M10 = TFile::Open("./50ns_betaV4/NewWeightDMHtoGG_M10.root","READ"); TFile *sig_M100 = TFile::Open("./50ns_betaV4/NewWeightDMHtoGG_M100.root","READ"); TFile *sig_M1000 = TFile::Open("./50ns_betaV4/NewWeightDMHtoGG_M1000.root","READ"); TFile *bkg1 = TFile::Open("./50ns_betaV4/NewWeightDiPhoton.root","READ"); TFile *bkg2 = TFile::Open("./50ns_betaV4/NewWeightDYJetsToLL.root","READ"); TFile *bkg3 = TFile::Open("./50ns_betaV4/NewWeightGJets.root","READ"); TFile *bkg4 = TFile::Open("./50ns_betaV4/NewWeightGluGluHToGG.root","READ"); TFile *bkg5 = TFile::Open("./50ns_betaV4/NewWeightQCD.root","READ"); TFile *bkg6 = TFile::Open("./50ns_betaV4/NewWeightVH.root","READ"); TTree *tree_data = (TTree*) data->Get("DiPhotonTree"); TTree *tree_sig_M1 = (TTree*) sig_M1->Get("WeightDiPhotonTree"); TTree *tree_sig_M10 = (TTree*) sig_M10->Get("WeightDiPhotonTree"); TTree *tree_sig_M100 = (TTree*) sig_M100->Get("WeightDiPhotonTree"); TTree *tree_sig_M1000 = (TTree*) sig_M1000->Get("WeightDiPhotonTree"); TTree *tree_bkg1 = (TTree*) bkg1->Get("WeightDiPhotonTree"); TTree *tree_bkg2 = (TTree*) bkg2->Get("WeightDiPhotonTree"); TTree *tree_bkg3 = (TTree*) bkg3->Get("WeightDiPhotonTree"); TTree *tree_bkg4 = (TTree*) bkg4->Get("WeightDiPhotonTree"); TTree *tree_bkg5 = (TTree*) bkg5->Get("WeightDiPhotonTree"); TTree *tree_bkg6 = (TTree*) bkg6->Get("WeightDiPhotonTree"); TCanvas *c1n = new TCanvas("c1n","",1200,400); c1n->Divide(2,1); c1n->cd(1); gPad->SetLogy(); tree_data->Draw("(fabs(eta1-eta2))>>hdata(30,0,3)"); TH1F *hdata =(TH1F*)gPad->GetPrimitive("hdata"); tree_sig_M1->Draw("(fabs(eta1-eta2))>>h1(30,0,3)","weightNew"); TH1F *h1 =(TH1F*)gPad->GetPrimitive("h1"); tree_sig_M10->Draw("(fabs(eta1-eta2))>>h2(30,0,3)","weightNew"); TH1F *h2 =(TH1F*)gPad->GetPrimitive("h2"); tree_sig_M100->Draw("(fabs(eta1-eta2))>>h3(30,0,3)","weightNew"); TH1F *h3 =(TH1F*)gPad->GetPrimitive("h3"); tree_sig_M1000->Draw("(fabs(eta1-eta2))>>h4(30,0,3)","weightNew"); TH1F *h4 =(TH1F*)gPad->GetPrimitive("h4"); tree_bkg1->Draw("(fabs(eta1-eta2))>>hbkg1(30,0,3)","weight*weightNew"); TH1F *hbkg1 =(TH1F*)gPad->GetPrimitive("hbkg1"); tree_bkg2->Draw("(fabs(eta1-eta2))>>hbkg2(30,0,3)","weight*weightNew"); TH1F *hbkg2 =(TH1F*)gPad->GetPrimitive("hbkg2"); tree_bkg3->Draw("(fabs(eta1-eta2))>>hbkg3(30,0,3)","weight*weightNew"); TH1F *hbkg3 =(TH1F*)gPad->GetPrimitive("hbkg3"); tree_bkg4->Draw("(fabs(eta1-eta2))>>hbkg4(30,0,3)","weight*weightNew"); TH1F *hbkg4 =(TH1F*)gPad->GetPrimitive("hbkg4"); tree_bkg5->Draw("(fabs(eta1-eta2))>>hbkg5(30,0,3)","weight*weightNew"); TH1F *hbkg5 =(TH1F*)gPad->GetPrimitive("hbkg5"); tree_bkg6->Draw("(fabs(eta1-eta2))>>hbkg6(30,0,3)","weight*weightNew"); TH1F *hbkg6 =(TH1F*)gPad->GetPrimitive("hbkg6"); h1->SetLineColor(kRed-4); h2->SetLineColor(kRed+2); h3->SetLineColor(kPink+2); h4->SetLineColor(kPink+4); h1->SetLineWidth(2); h2->SetLineWidth(2); h3->SetLineWidth(2); h4->SetLineWidth(2); THStack *hs= new THStack("hs",""); hbkg6->SetFillColor(kGreen+3); hbkg4->SetFillColor(kGreen+4); hbkg1->SetFillColor(kBlue); hbkg2->SetFillColor(kBlue+2); hbkg3->SetFillColor(kMagenta+4); hbkg5->SetFillColor(kMagenta+2); hbkg1->SetLineColor(kBlack); hbkg2->SetLineColor(kBlack); hbkg3->SetLineColor(kBlack); hbkg4->SetLineColor(kBlack); hbkg5->SetLineColor(kBlack); hbkg6->SetLineColor(kBlack); hs->Add(hbkg6); hs->Add(hbkg4); hs->Add(hbkg1); hs->Add(hbkg2); hs->Add(hbkg3); hs->Add(hbkg5); TH1F *hsum = (TH1F*)hbkg1->Clone("hsum"); hsum->Add(hbkg2); hsum->Add(hbkg3); hsum->Add(hbkg4); hsum->Add(hbkg5); hsum->Add(hbkg6); h4->SetTitle(""); h4->Draw("HIST"); hsum->SetMarkerStyle(1); hsum->SetFillColor(kGray+3); hsum->SetFillStyle(3001); hsum->Draw("same e2"); hs->Draw("same hist"); h2->Draw("same HIST"); h3->Draw("same HIST"); h4->Draw("same HIST"); h1->Draw("same HIST"); hdata->Draw("same E1"); h4->GetXaxis()->SetTitle("#Delta#eta(#gamma,#gamma)"); h4->GetYaxis()->SetTitle("Events/0.1"); gPad->Modified(); leg->AddEntry(hdata,"Data","lp"); leg->AddEntry(h1,"m_{#chi} = 1 GeV","l"); leg->AddEntry(h2,"m_{#chi} = 10 GeV","l"); leg->AddEntry(h3,"m_{#chi} = 100 GeV","l"); leg->AddEntry(h4,"m_{#chi} = 1000 GeV","l"); leg->AddEntry(hbkg1,"#gamma #gamma","f"); leg->AddEntry(hbkg2,"Drell Yann","f"); leg->AddEntry(hbkg3,"#gamma + Jets","f"); leg->AddEntry(hbkg4,"ggH","f"); leg->AddEntry(hbkg5,"QCD","f"); leg->AddEntry(hbkg6,"VH","f"); leg->Draw("same"); c1n->cd(2); gPad->SetLogy(); TH1F *h1_norm = (TH1F*)h1->Clone("h1_norm"); TH1F *h2_norm = (TH1F*)h2->Clone("h2_norm"); TH1F *h3_norm = (TH1F*)h3->Clone("h3_norm"); TH1F *h4_norm = (TH1F*)h4->Clone("h4_norm"); TH1F *hbkg1_norm = (TH1F*)hbkg1->Clone("hbkg1_norm"); TH1F *hbkg2_norm = (TH1F*)hbkg2->Clone("hbkg2_norm"); TH1F *hbkg3_norm = (TH1F*)hbkg3->Clone("hbkg3_norm"); TH1F *hbkg4_norm = (TH1F*)hbkg4->Clone("hbkg4_norm"); TH1F *hbkg5_norm = (TH1F*)hbkg5->Clone("hbkg5_norm"); TH1F *hbkg6_norm = (TH1F*)hbkg6->Clone("hbkg6_norm"); double norm = 1./h1->Integral(); h1_norm->Scale(norm); norm = 1./h2->Integral(); h2_norm->Scale(norm); norm = 1./h3->Integral(); h3_norm->Scale(norm); norm = 1./h4->Integral(); h4_norm->Scale(norm); norm = 1./hbkg1->Integral(); hbkg1_norm->Scale(norm); norm = 1./hbkg2->Integral(); hbkg2_norm->Scale(norm); norm = 1./hbkg3->Integral(); hbkg3_norm->Scale(norm); norm = 1./hbkg4->Integral(); hbkg4_norm->Scale(norm); norm = 1./hbkg5->Integral(); hbkg5_norm->Scale(norm); norm = 1./hbkg6->Integral(); hbkg6_norm->Scale(norm); hbkg1_norm->SetFillStyle(0); hbkg2_norm->SetFillStyle(0); hbkg3_norm->SetFillStyle(0); hbkg4_norm->SetFillStyle(0); hbkg5_norm->SetFillStyle(0); hbkg6_norm->SetFillStyle(0); h4_norm->SetTitle(""); h4_norm->Draw("HIST"); hbkg1_norm->Draw("same hist"); hbkg2_norm->Draw("same hist"); hbkg3_norm->Draw("same hist"); hbkg4_norm->Draw("same hist"); hbkg5_norm->Draw("same hist"); hbkg6_norm->Draw("same hist"); h2_norm->Draw("same hist"); h3_norm->Draw("same hist"); h1_norm->Draw("same hist"); h4_norm->GetXaxis()->SetTitle("#Delta#eta(#gamma,#gamma)"); h4_norm->GetYaxis()->SetTitle("1/0.1"); gPad->Modified(); TLegend* leg_norm = new TLegend(0.70,0.55,0.89,0.89); leg_norm->AddEntry(hdata,"Data","lp"); leg_norm->AddEntry(h1_norm,"m_{#chi} = 1 GeV","l"); leg_norm->AddEntry(h2_norm,"m_{#chi} = 10 GeV","l"); leg_norm->AddEntry(h3_norm,"m_{#chi} = 100 GeV","l"); leg_norm->AddEntry(h4_norm,"m_{#chi} = 1000 GeV","l"); leg_norm->AddEntry(hbkg1_norm,"#gamma #gamma","l"); leg_norm->AddEntry(hbkg2_norm,"Drell Yann","l"); leg_norm->AddEntry(hbkg3_norm,"#gamma + Jets","l"); leg_norm->AddEntry(hbkg4_norm,"ggH","l"); leg_norm->AddEntry(hbkg5_norm,"QCD","l"); leg_norm->AddEntry(hbkg6_norm,"VH","l"); leg_norm->Draw("same"); gStyle->SetOptStat(0); c1n->SaveAs("DeltaEta_norm.png"); }
void //HHH_TT_X_1or2tag(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="tauTau_$CATEGORY") HHH_TT_X_1or2tag(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="tauTau_$CATEGORY") { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category = ""; const char* category_extra = ""; const char* category_extra2 = ""; if(std::string(directory) == std::string("tauTau_2jet0tag")){ category = "#tau_{h}#tau_{h}"; } if(std::string(directory) == std::string("tauTau_2jet0tag")){ category_extra= "2-jet 0 b-tag"; } if(std::string(directory) == std::string("tauTau_2jet1tag" )){ category = "#tau_{h}#tau_{h}"; } if(std::string(directory) == std::string("tauTau_2jet1tag" )){ category_extra= "2-jet 1 b-tag"; } if(std::string(directory) == std::string("tauTau_2jet2tag" )){ category = "#tau_{h}#tau_{h}"; } if(std::string(directory) == std::string("tauTau_2jet2tag" )){ category_extra = "2-jet 2 b-tag"; } const char* dataset; #ifdef MSSM if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 4.9 fb^{-1} (7 TeV)";} if(std::string(inputfile).find("8TeV")!=std::string::npos){ if(std::string(directory).find("btag")!=std::string::npos){ dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 18.3 fb^{-1} (8 TeV)"; } else{ dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 19.7 fb^{-1} (8 TeV)"; } } #else if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS, 19.7 fb^{-1} at 8 TeV";} #endif // open example histogram file TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MH_$TANB").c_str()); #endif TH1F* Fakes = refill((TH1F*)input->Get(TString::Format("%s/QCD" , directory)), "QCD"); InitHist(Fakes, "", "", TColor::GetColor(250,202,255), 1001); // TH1F* EWK1 = refill((TH1F*)input->Get(TString::Format("%s/W" , directory)), "W" ); InitHist(EWK1 , "", "", TColor::GetColor(222,90,106), 1001); TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZLL" , directory)), "ZLL" ); InitHist(EWK2 , "", "", TColor::GetColor(222,90,106), 1001); //TH1F* EWK3 = refill((TH1F*)input->Get(TString::Format("%s/ZL" , directory)), "ZL" ); InitHist(EWK3 , "", "", TColor::GetColor(222,90,106), 1001); TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/VV" , directory)), "VV" ); InitHist(EWK , "", "", TColor::GetColor(222,90,106), 1001); TH1F* ttbar = refill((TH1F*)input->Get(TString::Format("%s/TT" , directory)), "TT" ); InitHist(ttbar, "", "", TColor::GetColor(155,152,204), 1001); TH1F* Ztt = refill((TH1F*)input->Get(TString::Format("%s/ZTT" , directory)), "ZTT"); InitHist(Ztt , "", "", TColor::GetColor(248,206,104), 1001); #ifdef MSSM TH1F* ggHTohhTo2Tau2B = refill((TH1F*)input2->Get(TString::Format("%s/ggHTohhTo2Tau2B$MH" , directory)), "ggHTohhTo2Tau2B"); InitSignal(ggHTohhTo2Tau2B); ggHTohhTo2Tau2B->Scale($TANB*SIGNAL_SCALE); /* if(std::string(directory)=="tauTau_2jet1tag") ggHTohhTo2Tau2B->Scale(0.5); if(std::string(directory)=="tauTau_2jet2tag") ggHTohhTo2Tau2B->Scale(0.3); TH1F* ggH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/ggH_SM125",directory)),"ggH_SM125");InitSignal(ggH_SM125);ggH_SM125->Scale(SIGNAL_SCALE); TH1F* qqH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/qqH_SM125",directory)),"qqH_SM125");InitSignal(qqH_SM125);qqH_SM125->Scale(SIGNAL_SCALE); TH1F* VH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/VH_SM125",directory)),"VH_SM125");InitSignal(VH_SM125);VH_SM125->Scale(SIGNAL_SCALE); // TH1F* WHToBB_SM125 = refill((TH1F*)input->Get(TString::Format("%s/WHToBB_SM125",directory)),"WHToBB_SM125");InitSignal(WHToBB_SM125);WHToBB_SM125->Scale(SIGNAL_SCALE); TH1F* ZHToBB_SM125 = refill((TH1F*)input->Get(TString::Format("%s/ZHToBB_SM125",directory)),"ZHToBB_SM125");InitSignal(ZHToBB_SM125);ZHToBB_SM125->Scale(SIGNAL_SCALE); */ /* TH1F* ggAToZhToLLTauTau = refill((TH1F*)input2->Get(TString::Format("%s/ggAToZhToLLTauTau$MH",directory)),"ggAToZhToLLTauTau"); InitSignal(ggAToZhToLLTauTau); TH1F* ggAToZhToLLBB = refill((TH1F*)input2->Get(TString::Format("%s/ggAToZhToLLBB$MH",directory)),"ggAToZhToLLBB"); InitSignal(ggAToZhToLLBB); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MH" , directory)), "bbH"); InitSignal(bbH); */ #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data",true); #endif InitHist(data, "#bf{m_{H} [GeV]}", "#bf{dN/dm_{H} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Fakes->Clone("ref"); // ref->Add(EWK1 ); ref->Add(EWK2 ); //ref->Add(EWK3 ); ref->Add(EWK ); ref->Add(ttbar); ref->Add(Ztt ); double unscaled[8]; unscaled[0] = Fakes->Integral(); unscaled[1] = EWK ->Integral(); // unscaled[1]+= EWK1 ->Integral(); unscaled[1]+= EWK2 ->Integral(); //unscaled[1]+= EWK3 ->Integral(); unscaled[2] = ttbar->Integral(); unscaled[3] = Ztt ->Integral(); #ifdef MSSM unscaled[4] = ggHTohhTo2Tau2B ->Integral(); /*unscaled[5] = ggH_SM125->Integral(); unscaled[5]+= qqH_SM125->Integral(); unscaled[5]+= VH_SM125->Integral(); */ /* unscaled[5] = ggAToZhToLLTauTau->Integral(); unscaled[6] = ggAToZhToLLBB->Integral(); unscaled[7] = bbH ->Integral(); */ #endif if(scaled){ /* Fakes = refill(shape_histos(Fakes, datacard, "QCD"), "QCD"); EWK1 = refill(shape_histos(EWK1, datacard, "W"), "W"); EWK2 = refill(shape_histos(EWK2, datacard, "ZJ"), "ZJ"); EWK = refill(shape_histos(EWK, datacard, "VV"), "VV"); ttbar = refill(shape_histos(ttbar, datacard, "TT"), "TT"); Ztt = refill(shape_histos(Ztt, datacard, "ZTT"), "ZTT"); #ifdef MSSM ggH = refill(shape_histos(ggH, datacard, "ggH$MH"), "ggH$MH"); bbH = refill(shape_histos(bbH, datacard, "bbH$MH"), "bbH$MH"); #else ggH = refill(shape_histos(ggH, datacard, "ggH"), "ggH"); qqH = refill(shape_histos(qqH, datacard, "qqH"), "qqH"); VH = refill(shape_histos(VH, datacard, "VH"), "VH"); #endif */ rescale(Fakes, 7); //rescale(EWK1 , 3); rescale(EWK2 , 4); //rescale(EWK3 , 5); rescale(EWK , 6); rescale(ttbar, 2); rescale(Ztt , 1); #ifdef MSSM rescale(ggHTohhTo2Tau2B , 8); /* rescale(ggAToZhToLLTauTau,9); rescale(ggAToZhToLLBB,10); rescale(bbH , 11); */ #endif } TH1F* scales[8]; scales[0] = new TH1F("scales-Fakes", "", 8, 0, 8); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-EWK" , "", 8, 0, 8); scales[1]->SetBinContent(2, unscaled[1]>0 ? ((EWK ->Integral() //+EWK1 ->Integral() +EWK2 ->Integral() //+EWK3 ->Integral() )/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-ttbar", "", 8, 0, 8); scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-Ztt" , "", 8, 0, 8); scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt ->Integral()/unscaled[3]-1.) : 0.); #ifdef MSSM scales[4] = new TH1F("scales-ggHTohhTo2Tau2B" , "", 8, 0, 8); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggHTohhTo2Tau2B ->Integral()/unscaled[4]-1.) : 0.); /* scales[5] = new TH1F("scales-ggAToZhToLLTauTau" , "", 8, 0, 8); scales[5]->SetBinContent(6, unscaled[5]>0 ? (ggAToZhToLLTauTau ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-ggAToZhToLLBB" , "", 8, 0, 8); scales[6]->SetBinContent(7, unscaled[6]>0 ? (ggAToZhToLLBB ->Integral()/unscaled[6]-1.) : 0.); scales[7] = new TH1F("scales-bbH" , "", 8, 0, 8); scales[7]->SetBinContent(8, unscaled[7]>0 ? (bbH ->Integral()/unscaled[7]-1.) : 0.); */ #endif //#ifdef MSSM // qqH_SM125->Add(ggH_SM125); // VH_SM125->Add(qqH_SM125); // Fakes->Add(VH_SM125); //#endif Fakes->Add(ttbar); // EWK1 ->Add(Fakes); EWK2 ->Add(Fakes ); //EWK3 ->Add(EWK2 ); //EWK ->Add(EWK3 ); EWK ->Add(EWK2 ); // ttbar->Add(EWK ); Ztt ->Add(EWK); /*ggH_SM125->Add(qqH_SM125); ggH_SM125->Add(VH_SM125); ggH_SM125->Add(ZHToBB_SM125); */ // ggH_SM125->Add(WHToBB_SM125); //if(log){ //#ifdef MSSM // ggH->Add(bbH); //#else // qqH->Add(VH ); // ggH->Add(qqH); //#endif // } //else{ //#ifdef MSSM // bbH->Add(Ztt); // ggH->Add(bbH); //#else // VH ->Add(Ztt); // qqH->Add(VH ); // ggH->Add(qqH); //#endif // } /* Mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(200, data->FindBin(UPPER_EDGE)); } else{ data->GetXaxis()->SetRange(200, data->FindBin(UPPER_EDGE)); }; #else data->GetXaxis()->SetRange(200, data->FindBin(UPPER_EDGE)); #endif data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max>0 ? max : std::max(std::max(maximum(data, log), maximum(Ztt, log)), maximum(ggHTohhTo2Tau2B, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)Ztt ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(13); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ Ztt ->Draw("histsame"); // ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); ttbar->Draw("histsame"); //#ifdef MSSM // VH_SM125->Draw("histsame"); //#endif $DRAW_ERROR ggHTohhTo2Tau2B ->Draw("histsame"); /*ggH_SM125->SetLineColor(kRed); ggH_SM125->Draw("histsame"); */ } else{ Ztt ->Draw("histsame"); // ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); ttbar->Draw("histsame"); #ifdef MSSM //VH_SM125->Draw("histsame"); #endif $DRAW_ERROR ggHTohhTo2Tau2B ->Draw("histsame"); /* ggH_SM125->SetLineColor(kRed); ggH_SM125->Draw("histsame"); */ } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{h}#tau_{h}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); #if defined MSSM TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "tlbrNDC"); if (strcmp(category_extra2,"")!=0) chan = new TPaveText(0.20, 0.69+0.061, 0.32, 0.74+0.161, "tlbrNDC"); #else TPaveText* chan = new TPaveText(0.52, 0.35, 0.91, 0.55, "tlbrNDC"); #endif chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->AddText(category_extra); #if defined MSSM if (strcmp(category_extra2,"")!=0) chan->AddText(category_extra2); #else chan->AddText(category_extra2); #endif chan->Draw(); /* TPaveText* cat = new TPaveText(0.20, 0.71+0.061, 0.32, 0.71+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); TPaveText* cat2 = new TPaveText(0.20, 0.66+0.061, 0.32, 0.66+0.161, "NDC"); cat2->SetBorderSize( 0 ); cat2->SetFillStyle( 0 ); cat2->SetTextAlign( 12 ); cat2->SetTextSize ( 0.05 ); cat2->SetTextColor( 1 ); cat2->SetTextFont ( 62 ); cat2->AddText(category_extra2); cat2->Draw(); */ #ifdef MSSM TPaveText* massA = new TPaveText(0.53, 0.44+0.061, 0.95, 0.44+0.151, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("MSSM m^{h}_{mod+} scenario"); massA->AddText("m_{H}=$MH GeV, tan#beta=$TANB"); massA->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.53, 0.60, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggHTohhTo2Tau2B , TString::Format("%0.f #times H#rightarrowhh#rightarrow#tau#taubb", SIGNAL_SCALE) , "L" ); // leg->AddEntry(ggH_SM125, TString::Format("%0.f #times SM H (125 GeV) #rightarrow #tau#tau/bb", SIGNAL_SCALE), "L"); #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + H(125)" , "LP"); #else leg->AddEntry(data , "Observed" , "LP"); #endif leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(EWK , "Electroweak" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); /*#ifdef MSSM leg->AddEntry(VH_SM125, "SM H(125 GeV) #rightarrow #tau#tau", "F" ); #endif */ $ERROR_LEGEND leg->Draw(); /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* model = (TH1F*)Ztt ->Clone("model"); TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); model->SetBinError (ibin+1, CONSERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob=0.; double chi2ndof=0.; double ksprob=0.; double ksprobpe=0.; if(!BLIND_DATA){ chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; } std::vector<double> edges; TH1F* zero = (TH1F*)ref->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/Ztt->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? Ztt ->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if(edges.size()>1){ if (edges[edges.size()-2]>0.1) { range = 0.2; } else if (edges[edges.size()-2]>0.2) { range = 0.5; } else if (edges[edges.size()-2]>0.5) { range = 1.0; } else if (edges[edges.size()-2]>1.0) { range = 1.5; } else if (edges[edges.size()-2]>1.5) { range = 2.0; } } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{H} [GeV]}"); rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv0->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); if(!BLIND_DATA){ stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); } //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); stat1->Draw(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); edges.clear(); TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ rat2->SetBinContent(ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinContent(ibin+1)/ref->GetBinContent(ibin+1) : 0); rat2->SetBinError (ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinError (ibin+1)/ref->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat2->GetBinContent(ibin+1)-1.)+TMath::Abs(rat2->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } range = 0.1; std::sort(edges.begin(), edges.end()); if(edges.size()>1){ if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } } #if defined MSSM if(!log){ rat2->GetXaxis()->SetRange(200, rat2->FindBin(UPPER_EDGE)); } else{ rat2->GetXaxis()->SetRange(200, rat2->FindBin(UPPER_EDGE)); }; #else rat2->GetXaxis()->SetRange(200, rat2->FindBin(UPPER_EDGE)); #endif rat2->SetNdivisions(505); rat2->SetLineColor(kRed+ 3); rat2->SetMarkerColor(kRed+3); rat2->SetMarkerSize(1.1); rat2->SetMaximum(+range); rat2->SetMinimum(-range); rat2->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{H} [GeV]}"); rat2->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->Draw("e2histsame"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", TColor::GetColor(250,202,255), 1001); InitHist (scales[1], "", "", TColor::GetColor(222,90,106), 1001); InitHist (scales[2], "", "", TColor::GetColor(155,152,204), 1001); InitHist (scales[3], "", "", TColor::GetColor(248,206,104), 1001); InitHist(scales[4],"","",kGreen+2,1001); /* InitHist(scales[5],"","",kGreen+2,1001); InitHist(scales[6],"","",kGreen+2,1001); InitHist(scales[7],"","",kGreen+2,1001); */ scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggHTohhTo2tau2B}" ); /* scales[0]->GetXaxis()->SetBinLabel(6, "#bf{ggAToZhToLLTauTau}"); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{ggAToZhToLLBB}"); scales[0]->GetXaxis()->SetBinLabel(8, "#bf{bbH}" ); */ #endif scales[0]->SetMaximum(+0.5); scales[0]->SetMinimum(-0.5); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); scales[4]->Draw("same"); /* scales[5]->Draw("same"); scales[6]->Draw("same"); */ TH1F* zero_samples = (TH1F*)scales[0]->Clone("zero_samples"); zero_samples->Clear(); zero_samples->SetBinContent(1,0.); zero_samples->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); if(!log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } if((!log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"), "update"); output->cd(); data ->Write("data_obs"); Fakes->Write("Fakes" ); EWK ->Write("EWK" ); ttbar->Write("ttbar" ); Ztt ->Write("Ztt" ); #ifdef MSSM ggHTohhTo2Tau2B ->Write("ggHTohhTo2Tau2B" ); /* ggAToZhToLLTauTau->Write("ggAToZhToLLTauTau"); ggAToZhToLLBB->Write("ggAToZhToLLBB"); bbH ->Write("bbH" ); */ #endif output->Close(); delete errorBand; delete model; delete test1; delete zero; delete rat1; delete rat2; delete zero_samples; delete ref; }
void quickLifetimeFit(string filename, bool isB0) { setTDRStyle(); TFile *_file0 = TFile::Open(filename.c_str()); TTree *tree = (TTree*)gDirectory->Get("fittree"); TCanvas *c = new TCanvas("c","c",600,800); c->Divide(2,3); int canvasctr(0); string strSigWindow, strBgrWindow; double SoverSB; if (isB0) { strSigWindow = "mass>5.25&&mass<5.31"; strBgrWindow = "mass>5.35&&mass<5.55"; SoverSB = 0.90; // from another fit } else { strSigWindow = "mass>5.60&&mass<5.64"; strBgrWindow = "mass>5.75&&mass<6.30"; SoverSB = 0.60; // from another fit } c->cd(++canvasctr); tree->Draw("mass>>hmsigwindow", strSigWindow.c_str()); TH1F *hmsigwindow = (TH1F*)gDirectory->GetList()->FindObject("hmsigwindow"); const int nSigWindow = hmsigwindow->GetEntries(); c->cd(++canvasctr); tree->Draw("mass>>hbgrwindow", strBgrWindow.c_str()); TH1F *hbgrwindow = (TH1F*)gDirectory->GetList()->FindObject("hbgrwindow"); const int nBgrWindow = hbgrwindow->GetEntries(); const double nSig = nSigWindow * SoverSB; const double nBgr = nSigWindow * (1.-SoverSB); const double scale = (double)nBgr / (double)nBgrWindow; c->cd(++canvasctr); tree->Draw("t>>hsigt(34,-2e-12,15e-12)", strSigWindow.c_str()); TH1F *hsigt = (TH1F*)gDirectory->GetList()->FindObject("hsigt"); gPad->SetLogy(); c->cd(++canvasctr); tree->Draw("t>>hbgrt(34,-2e-12,15e-12)", strBgrWindow.c_str()); TH1F *hbgrt = (TH1F*)gDirectory->GetList()->FindObject("hbgrt"); hbgrt->Scale(scale); gPad->SetLogy(); c->cd(++canvasctr); hsigt->Draw(); hsigt->SetLineColor(4); hbgrt->Draw("same"); hbgrt->SetLineColor(2); gPad->SetLogy(); c->cd(++canvasctr); TH1F *hdiff = new TH1F("hdiff","hdiff",34,-2e-12,15e-12); hdiff->Add(hsigt,hbgrt,1,-1); hdiff->Draw(); gPad->SetLogy(); c->SaveAs("quickFit.pdf"); TCanvas *c2 = new TCanvas("c2","c2",1000,800); hdiff->Draw(); gPad->SetLogy(); }
void macro_MakeQcdClosureTest() { // parameters ////////////////////////////////////////////////////////////// //TFile input("./emuSpec_19619pb-1.root", "open"); TFile input("test_19619pb-1.root", "open"); input.cd(); TParameter<float> *lumi = (TParameter<float> *)input.Get("lumi"); const int nBins = 75; const bool usePu = 1; const bool useWeight = 1; const int qcdEst = 1; // estimation method of QCD contribution. none(0), from SS spectrum(1), from fake rate(2) int eRegion = 2; // electron region EB(0), EE(1), EB+EE(2) bool plotSign[3]; plotSign[0] = 1; // all plotSign[1] = 1; // SS same sign plotSign[2] = 1; // OS opposite sign bool plotType[2]; plotType[0] = 1; // emu spectrum plotType[1] = 1; // cumulative emu spectrum const bool plotPull = 0; // plot (data-bkg)/bkg const bool plotPullBelowSpec = 0; // plot (data-bkg)/bkg below spectrum const bool logPlotX = 0; const bool logPlotY = 1; const bool prelim = 1; const bool groupedPlot = 0; const bool overflowBin = 1; float xRangeMin = 60.; float xRangeMax = 1200.; //float xRangeMin = 0.; //float xRangeMax = 1500.; float yRangeMin[6] = {0.002, 0.002, 0.002, 0.4, 0.4, 0.4}; float yRangeMax[6] = {30, 10, 30, 3000, 1000, 3000}; float yRangeMinRatio[3] = {-0.7, -0.7, -0.7}; float yRangeMaxRatio[3] = {0.7, 0.7, 0.7}; float fitMin = xRangeMin; float fitMax = 1100.; // set to highest bin with a data point float xRangeMinRatio = fitMin; float xRangeMaxRatio = fitMax; // output file formats const bool savePull = 0; const bool saveSpec = 0; const bool saveCumSpec = 0; const bool saveAsPdf = 0; const bool saveAsPng = 1; const bool saveAsRoot = 0; const char *fileNameExtra = ""; //const char *fileNameExtra = "madgraphTTbar_"; const char *plotDir = "./plottemp/"; // plot style int wjetColour= TColor::GetColor("#ffd324"); int jetBkgColour = TColor::GetColor("#ffff66"); int font = 42; //62 //////////////////////////////////////////////////////////////////////////// // systematic errors float systErrLumi = ((TParameter<float> *)input.Get("systErrLumi"))->GetVal(); systErrLumi = 0.; // since we normalize to the Z peak float systErrEff = ((TParameter<float> *)input.Get("systErrEff"))->GetVal(); // muon err & ele err THashList *systErrMCs = (THashList *)input.Get("systErrMCs"); vector<float> systErrMC; systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcTtbar"))->GetVal()); // NNLO ttbar //systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcTtbar700to1000"))->GetVal()); // NLO ttbar700to1000 //systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcTtbar1000up"))->GetVal()); // NLO ttbar1000up systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcDyTauTau"))->GetVal()); //z->tt systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcWW"))->GetVal()); //WW systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcWZ"))->GetVal()); //WZ systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcZZ"))->GetVal()); //ZZ systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcTW"))->GetVal()); //tW systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcDyMuMu"))->GetVal()); //Z->mm systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcDyEE"))->GetVal()); //Z->ee if (qcdEst == 2) systErrMC.push_back(0.4); // qcd error else systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcWJets"))->GetVal()); //WJets // to keep the histogram when the file is closed TH1::AddDirectory(kFALSE); TH1::SetDefaultSumw2(kTRUE); TString histoSign[3] = {"", "SS_", "OS_"}; TString xAxisTitle[3] = {"m(e#mu)", "m(e^{#pm}#mu^{#pm})", "m(e^{#pm}#mu^{#mp})"}; TString nameSuffix[2] = {"", "cumul"}; TString titleSuffix[2] = {"", " - Cumulative"}; vector<TH1F *> emuMass_wjets; vector<TH1F *> emuMass_qcd; vector<TH1F *> emuMass_qcdFromFake; // define the binning vector<float> binning; if (logPlotX) { //for (float bin = 0.; bin < 100.; bin += 5.) // binning.push_back(bin); for (float bin = 0.; bin < 200.; bin += 10.) binning.push_back(bin); for (float bin = 200.; bin < 400.; bin += 20.) binning.push_back(bin); for (float bin = 400.; bin < 500.; bin += 25.) binning.push_back(bin); for (float bin = 500.; bin <= 620.; bin += 40.) binning.push_back(bin); binning.push_back(670.); binning.push_back(720.); binning.push_back(780.); binning.push_back(840.); binning.push_back(920.); binning.push_back(1000.); binning.push_back(1100.); binning.push_back(1220.); binning.push_back(1380.); binning.push_back(1500.); } else { //for (float bin = 0.; bin <= 1500.; bin += 20.) // binning.push_back(bin); for (float bin = 0.; bin < 200.; bin += 20.) binning.push_back(bin); for (float bin = 200.; bin < 400.; bin += 40.) binning.push_back(bin); for (float bin = 400.; bin < 700.; bin += 50.) binning.push_back(bin); for (float bin = 700.; bin < 1000.; bin += 75.) binning.push_back(bin); for (float bin = 1000.; bin < 1200.; bin += 100.) binning.push_back(bin); for (float bin = 1200.; bin <= 1500.; bin += 150.) binning.push_back(bin); } THashList *mcWeights = (THashList *)input.Get("mcWeights"); TParameter<float> *mcWeight = (TParameter<float> *)mcWeights->FindObject("ttbar"); TParameter<float> *mcWeight700to1000 = (TParameter<float> *)mcWeights->FindObject("ttbar700to1000"); TParameter<float> *mcWeight1000up = (TParameter<float> *)mcWeights->FindObject("ttbar1000up"); float totMcWeight = 1.; // determine qcd contribution TH1F *qcdContrib; TH1F *ssData = MakeHistoFromBranch(&input, "emuTree_data", "mass", SS, eRegion, "", 0., 0., binning, 0x100); TH1F *ssBg = MakeHistoFromBranch(&input, "emuTree_ttbar", "mass", SS, eRegion, "genMTtbar", 0., 700., binning, 0x1DF); totMcWeight = 1. / (1 / mcWeight->GetVal() + 1 / mcWeight700to1000->GetVal()); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ttbar", "mass", SS, eRegion, "genMTtbar", 700., 1000., binning, 0x19F), totMcWeight); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ttbar700to1000", "mass", SS, eRegion, "genMTtbar", 700., 1000., binning, 0x19F), totMcWeight); totMcWeight = 1. / (1 / mcWeight->GetVal() + 1 / mcWeight1000up->GetVal()); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ttbar", "mass", SS, eRegion, "genMTtbar", 1000., 1000000000., binning, 0x19F), totMcWeight); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ttbar1000up", "mass", SS, eRegion, "genMTtbar", 1000., 1000000000., binning, 0x19F), totMcWeight); //TH1F *ssBg = MakeHistoFromBranch(&input, "emuTree_ttbar", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF); //TH1F *ssBg = MakeHistoFromBranch(&input, "emuTree_ttbarto2l", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ztautau", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF)); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ww", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF)); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_wz", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF)); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_zz", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF)); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_tw", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF)); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_zmumu", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF)); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_zee", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF)); ssBg->Add(MakeHistoFromBranch(&input, "emuTree_wjets", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF)); qcdContrib = (TH1F *)ssData->Clone("qcdContrib_SS"); qcdContrib->Add(ssBg, -1); for (int i = 0; i < qcdContrib->GetNbinsX() + 2; ++i) { if (qcdContrib->GetBinContent(i) < 0) qcdContrib->SetBinContent(i, 0.); } cout << "expected SS QCD events: " << ssData->Integral() - ssBg->Integral() << endl; cout << "derived SS QCD events: " << qcdContrib->Integral() << endl; cout << "scale factor: " << (ssData->Integral() - ssBg->Integral()) / qcdContrib->Integral()<< endl; qcdContrib->Scale((ssData->Integral() - ssBg->Integral()) / qcdContrib->Integral()); // loop over full spectrum, SS and OS for (int k = 0; k < 3; ++k) { // loop to get normal and cumulated spectrum for (unsigned int j = 0; j < 2; ++j) { input.cd(); bool normToBin = true; if (j > 0) normToBin = false; if (k == 2) k = -1; // make the histograms emuMass_wjets.push_back(MakeHistoFromBranch(&input, "emuTree_wjets", "mass", k, eRegion, "", 0., 0., binning, 0x1DF, normToBin)); if (k == -1) k = 2; emuMass_wjets.back()->SetName("emuMass_" + histoSign[k] + "wjets" + nameSuffix[j]); // qcd contribution if (k == 2) k = -1; emuMass_qcdFromFake.push_back((TH1F *)MakeHistoFromBranch(&input, "frEmuTree_data", "mass", k, eRegion, "", 0., 0., binning, 0x300)); emuMass_qcd.push_back((TH1F *)qcdContrib->Clone("emuMass_" + histoSign[k] + "qcd")); if (k == ALL) emuMass_qcd.back()->Scale(2.); // normalize to bin width if (j < 1) { for (int i = 1; i < emuMass_qcd.back()->GetNbinsX() + 1; ++i) { emuMass_qcd.back()->SetBinContent(i, emuMass_qcd.back()->GetBinContent(i) / emuMass_qcd.back()->GetBinWidth(i)); emuMass_qcd.back()->SetBinError(i, emuMass_qcd.back()->GetBinError(i) / emuMass_qcd.back()->GetBinWidth(i)); emuMass_qcdFromFake.back()->SetBinContent(i, emuMass_qcdFromFake.back()->GetBinContent(i) / emuMass_qcdFromFake.back()->GetBinWidth(i)); emuMass_qcdFromFake.back()->SetBinError(i, emuMass_qcdFromFake.back()->GetBinError(i) / emuMass_qcdFromFake.back()->GetBinWidth(i)); } } if (k == -1) k = 2; // add overflow in last bin if (j == 0 && overflowBin) { emuMass_wjets.back()->SetBinContent(emuMass_wjets.back()->GetNbinsX(), emuMass_wjets.back()->GetBinContent(emuMass_wjets.back()->GetNbinsX()) + emuMass_wjets.back()->GetBinContent(emuMass_wjets.back()->GetNbinsX() + 1)); emuMass_qcd.back()->SetBinContent(emuMass_qcd.back()->GetNbinsX(), emuMass_qcd.back()->GetBinContent(emuMass_qcd.back()->GetNbinsX()) + emuMass_qcd.back()->GetBinContent(emuMass_qcd.back()->GetNbinsX() + 1)); emuMass_qcdFromFake.back()->SetBinContent(emuMass_qcdFromFake.back()->GetNbinsX(), emuMass_qcdFromFake.back()->GetBinContent(emuMass_qcdFromFake.back()->GetNbinsX()) + emuMass_qcdFromFake.back()->GetBinContent(emuMass_qcdFromFake.back()->GetNbinsX() + 1)); } // integrate from the right side if (j == 1) { // loop over bins double error; for (int i = 1; i < nBins + 1; ++i) { emuMass_wjets.back()->SetBinContent(i, emuMass_wjets.back()->IntegralAndError(i, nBins, error)); emuMass_wjets.back()->SetBinError(i, error); emuMass_qcd.back()->SetBinContent(i, emuMass_qcd.back()->IntegralAndError(i, nBins, error)); emuMass_qcd.back()->SetBinError(i, error); emuMass_qcdFromFake.back()->SetBinContent(i, emuMass_qcdFromFake.back()->IntegralAndError(i, nBins, error)); emuMass_qcdFromFake.back()->SetBinError(i, error); } } if (!plotSign[k]) continue; if (!plotType[j]) continue; TCanvas *emuPlot; TPad *specPad; if (plotPullBelowSpec && j == 0) { emuPlot = new TCanvas("emuPlot" + histoSign[k] + nameSuffix[j], "emu Spectrum" + titleSuffix[j], 100, 100, 900, 900); specPad = new TPad("specPad" + histoSign[k] + nameSuffix[j], "emu Spectrum" + titleSuffix[j], 0., 0.33, 1., 1.); specPad->SetBottomMargin(0.06); } else { emuPlot = new TCanvas("emuPlot" + histoSign[k] + nameSuffix[j], "emu Spectrum" + titleSuffix[j], 100, 100, 900, 600); specPad = new TPad("specPad" + histoSign[k] + nameSuffix[j], "emu Spectrum" + titleSuffix[j], 0., 0., 1., 1.); specPad->SetBottomMargin(0.12); } specPad->SetBorderMode(0); specPad->SetBorderSize(2); specPad->SetFrameBorderMode(0); specPad->SetFillColor(0); specPad->SetFrameFillColor(0); if (logPlotX) specPad->SetLogx(); if (logPlotY) specPad->SetLogy(); specPad->SetLeftMargin(0.11); specPad->SetRightMargin(0.09); specPad->SetTopMargin(0.08); specPad->SetTickx(1); specPad->SetTicky(1); specPad->Draw(); specPad->cd(); gStyle->SetTitleFont(font); gStyle->SetLabelFont(font); gStyle->SetLegendFont(font); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetTitleXOffset(1.); gStyle->SetTitleYOffset(1.3); gPad->SetTicks(1, 1); // make a histogram stack with the bg THStack *bgStack = new THStack("bgStack" + histoSign[k] + nameSuffix[j], "Invariant Mass" + titleSuffix[j]); bgStack->Add(emuMass_qcd.back()); bgStack->Add(emuMass_wjets.back()); // plot spectrum emuMass_wjets.back()->SetFillColor(wjetColour); emuMass_wjets.back()->SetMarkerColor(wjetColour); emuMass_wjets.back()->SetLineColor(kBlack); emuMass_wjets.back()->SetLineWidth(2); //emuMass_wjets.back()->Draw("HISTsames"); emuMass_qcd.back()->SetFillColor(jetBkgColour); emuMass_qcd.back()->SetMarkerColor(jetBkgColour); emuMass_qcd.back()->SetLineColor(kBlack); emuMass_qcd.back()->SetLineWidth(2); //emuMass_qcd.back()->Draw("HISTsames"); bgStack->Draw("hist"); emuMass_qcdFromFake.back()->SetLineColor(kRed); emuMass_qcdFromFake.back()->SetLineWidth(2); emuMass_qcdFromFake.back()->Draw("esame"); if (plotPullBelowSpec && j == 0) { bgStack->GetXaxis()->SetTitle(""); } else { bgStack->GetXaxis()->SetTitle(xAxisTitle[k] + " [GeV]"); } bgStack->GetXaxis()->SetTitleFont(font); bgStack->GetXaxis()->SetTitleSize(0.047); bgStack->GetXaxis()->SetTitleOffset(0.9); bgStack->GetXaxis()->SetLabelFont(font); bgStack->GetXaxis()->SetLabelSize(0.05); bgStack->GetXaxis()->SetMoreLogLabels(); bgStack->GetXaxis()->SetNoExponent(); //bgStack->GetXaxis()->SetRangeUser(xRangeMin, xRangeMax); bgStack->GetXaxis()->SetLimits(xRangeMin, xRangeMax); if (j == 1) bgStack->GetYaxis()->SetTitle("Events #geq " + xAxisTitle[k]); else bgStack->GetYaxis()->SetTitle("Events / GeV"); bgStack->GetYaxis()->SetTitleFont(font); bgStack->GetYaxis()->SetTitleSize(0.047); bgStack->GetYaxis()->SetTitleOffset(1.1); bgStack->GetYaxis()->SetLabelFont(font); bgStack->GetYaxis()->SetLabelSize(0.05); bgStack->SetMinimum(yRangeMin[k + j * 3]); bgStack->SetMaximum(yRangeMax[k + j * 3]); // redraw axis emuMass_qcd.back()->Draw("sameaxis"); // legend and labels TLegend legend(0.710, 0.646, 0.901, 0.885); legend.SetTextFont(font); legend.SetTextSize(0.03); legend.SetBorderSize(0); legend.SetLineColor(1); legend.SetLineStyle(1); legend.SetLineWidth(1); legend.SetFillColor(19); legend.SetFillStyle(0); legend.AddEntry(emuMass_wjets.back(), "W+jets (MC)" ,"F"); legend.AddEntry(emuMass_qcd.back(), "jets (SS data)" ,"F"); legend.AddEntry(emuMass_qcdFromFake.back(), "jets (Fake Rate)" ,"le"); legend.DrawClone("sames"); TLatex *tex = new TLatex(); tex->SetNDC(); tex->SetTextFont(font); tex->SetLineWidth(2); tex->SetTextSize(0.042); if (prelim) tex->DrawLatex(0.325, 0.853, "CMS Preliminary, 8 TeV, 19.6 fb^{-1}"); else tex->DrawLatex(0.405, 0.853, "CMS, 8 TeV, 19.6 fb^{-1}"); if (eRegion == 0) tex->DrawLatex(0.325, 0.775, "e in barrel"); if (eRegion == 1) tex->DrawLatex(0.325, 0.775, "e in endcap"); // safe in various file formats stringstream sStream; if (!plotPullBelowSpec || j > 0) { sStream << plotDir << "qcdClosureTestSpec"; if (k == 0) sStream << "_"; sStream << histoSign[k]; if (eRegion == 0) sStream << "EB_"; if (eRegion == 1) sStream << "EE_"; sStream << fileNameExtra << nameSuffix[j]; if (j > 0) sStream << "_"; if (groupedPlot) sStream << "grouped_"; if (!logPlotY) sStream << "lin_"; sStream << lumi->GetVal() << "pb-1"; TString saveFileName = sStream.str(); if ((j == 0 && saveSpec) || (j > 0 && saveCumSpec)) { if (saveAsPdf) emuPlot->Print(saveFileName + ".pdf", "pdf"); if (saveAsPng) emuPlot->Print(saveFileName + ".png", "png"); if (saveAsRoot) emuPlot->Print(saveFileName + ".root", "root"); } } } // end loop over normal or cumulated } // end loop over full, SS and OS // generate one object containing everything vector<vector<TH1F *> > emuMasses; emuMasses.push_back(emuMass_wjets); emuMasses.push_back(emuMass_qcd); // // define groups of MC samples // vector<bool> ttLikeSamples(6, true); // vector<bool> contamSamples(6, false); // contamSamples.push_back(true); // Zmm // contamSamples.push_back(true); // Zee // contamSamples.push_back(true); // WJets or QCD // vector<bool> contamSamplesNoQcd(contamSamples); // vector<bool> allSamples(9, true); // vector<bool> onlyQCD(emuMasses.size() - 1, false); // if (qcdEst > 0) { // onlyQCD.back() = true; // if (qcdEst != 2) { // allSamples.push_back(true); // contamSamples.push_back(true); // contamSamplesNoQcd.push_back(false); // systErrMC.push_back(0.); // QCD error will be calculated later // } else { // contamSamplesNoQcd.back() = false; // } // } // vector<bool> allSamplesNoQcd(allSamples); // if (qcdEst > 0) allSamplesNoQcd.back() = false; // unsigned int qcdInd = onlyQCD.size(); // unsigned int qcdErrInd = qcdInd - 1; // // // calculate rate of syst errors // float systErrLuEff = sqrt(systErrLumi*systErrLumi + systErrEff*systErrEff); // vector<float> systErrMCLuEff; // for (unsigned int it = 0; it < systErrMC.size(); ++it) // systErrMCLuEff.push_back(sqrt(systErrMC[it]*systErrMC[it] + systErrLuEff*systErrLuEff)); // // bool calcQcdErr = false; // if (qcdEst == 1) calcQcdErr = true; // // //cout << "qcdInd " << qcdInd << ", emuMasses.size() " << emuMasses.size() << ", systErrMC.size() " << systErrMC.size() // // << ", systErrMCLuEff.size() " << systErrMCLuEff.size() << ", allSamples.size() " << allSamples.size() // // << ", allSamplesNoQcd.size() " << allSamplesNoQcd.size() << ", contamSamplesNoQcd.size() " << contamSamplesNoQcd.size() // // << ", contamSamples.size() " << contamSamples.size() << ", onlyQCD.size() " << onlyQCD.size() << endl; // //for (unsigned int sIt = 0; sIt < emuMasses.size() - 1; ++sIt) { // // cout << "allSamples " << allSamples[sIt] << ", allSamplesNoQcd " << allSamplesNoQcd[sIt] // // << ", contamSamples " << contamSamples[sIt] << ", contamSamplesNoQcd " << contamSamplesNoQcd[sIt] // // << ", onlyQCD " << onlyQCD[sIt] << ", systErrMC " << systErrMC[sIt] << ", systErrMCLuEff " << systErrMCLuEff[sIt] << endl; // //} // // // define special bins corresponding to specific masses // int bin60 = emuMass_data.at(ALL)->FindBin(60.); // int bin120 = emuMass_data.at(ALL)->FindBin(120.); // int bin200 = emuMass_data.at(ALL)->FindBin(200.); // int bin400 = emuMass_data.at(ALL)->FindBin(400.); // int bin500 = emuMass_data.at(ALL)->FindBin(500.); // // vector<const char *> sampleNames; // sampleNames.push_back("data "); // sampleNames.push_back("ttbar "); // sampleNames.push_back("Ztautau"); // sampleNames.push_back("WW "); // sampleNames.push_back("WZ "); // sampleNames.push_back("ZZ "); // sampleNames.push_back("tW "); // sampleNames.push_back("Zmumu "); // sampleNames.push_back("Zee "); // if (qcdEst != 2) sampleNames.push_back("WJets "); // if (qcdEst > 0) sampleNames.push_back("QCD "); // // // write numbers // cout << endl; // cout << "-----------------------------------------------------------------------------------------------------------" << endl; // cout << "HEEP - TIGHT MU Lumi = " << lumi->GetVal() << "pb-1" << endl; // //cout << " e pT EB > " << bar_et << "GeV/c" << endl; // //cout << " e pT EE > " << end_et << "GeV/c" << endl; // //cout << " mu pT > " << muon_et << "GeV/c" << endl; // //cout << " mu |eta| < " << muon_etaMax << endl; // cout << endl; // cout << "Systematic errors" << endl; // cout << " Luminosity: " << systErrLumi * 100 << "%" << endl; // cout << " Efficiency: " << systErrEff * 100 << "%" << endl; // cout << " ttbar: " << systErrMC[TTBAR-1] * 100 << "%" << endl; // cout << " Z->tautau: " << systErrMC[ZTT-1] * 100 << "%" << endl; // cout << " WW: " << systErrMC[WW-1] * 100 << "%" << endl; // cout << " WZ: " << systErrMC[WZ-1] * 100 << "%" << endl; // cout << " ZZ: " << systErrMC[ZZ-1] * 100 << "%" << endl; // cout << " tW, tbarW: " << systErrMC[TW-1] * 100 << "%" << endl; // cout << " Z->mumu: " << systErrMC[ZMM-1] * 100 << "%" << endl; // cout << " Z->ee: " << systErrMC[ZEE-1] * 100 << "%" << endl; // if (qcdEst != 2) cout << " W+Jets: " << systErrMC[WJET-1] * 100 << "%" << endl; // else cout << " QCD: " << systErrMC.back() * 100 << "%" << endl; // cout << "-----------------------------------------------------------------------------------------------------------" << endl; // for (unsigned int signIt = 1; signIt < 6; signIt += 2) { // if (signIt == 3) cout << "-SS--------------------------------------------------------------------------------------------------------" << endl; // if (signIt == 5) cout << "-OS--------------------------------------------------------------------------------------------------------" << endl; // cout << "-----------------------------------------------------------------------------------------------------------------------------------------" << endl; // cout << "M_emu | > 60GeV/c^2 | > 120GeV/c^2 | > 200GeV/c^2 | > 400GeV/c^2 |" << endl; // cout << "-----------------------------------------------------------------------------------------------------------------------------------------" << endl; // // printf("nb data | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) |\n", // emuMass_data.at(signIt)->GetBinContent(bin60), sqrt(emuMass_data.at(signIt)->GetBinContent(bin60)), // emuMass_data.at(signIt)->GetBinContent(bin120), sqrt(emuMass_data.at(signIt)->GetBinContent(bin120)), // emuMass_data.at(signIt)->GetBinContent(bin200), sqrt(emuMass_data.at(signIt)->GetBinContent(bin200)), // emuMass_data.at(signIt)->GetBinContent(bin400), sqrt(emuMass_data.at(signIt)->GetBinContent(bin400))); // cout << "----------------------------------------------------------------------------------------------------------------------------------------" << endl; // for (unsigned int sampleIt = 1; sampleIt < sampleNames.size(); ++sampleIt) { // if (sampleIt == 7) cout << "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" << endl; // if (qcdEst == 1 && sampleIt == sampleNames.size() - 1) { // printf("nb %7s | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", sampleNames[sampleIt], // emuMass_qcd.at(signIt)->GetBinContent(bin60), emuMass_qcd.at(signIt)->GetBinContent(bin60) * CalcSSQcdErr(emuMasses, systErrMCLuEff, bin60), // emuMass_qcd.at(signIt)->GetBinContent(bin120), emuMass_qcd.at(signIt)->GetBinContent(bin120) * CalcSSQcdErr(emuMasses, systErrMCLuEff, bin120), // emuMass_qcd.at(signIt)->GetBinContent(bin200), emuMass_qcd.at(signIt)->GetBinContent(bin200) * CalcSSQcdErr(emuMasses, systErrMCLuEff, bin200), // emuMass_qcd.at(signIt)->GetBinContent(bin400), emuMass_qcd.at(signIt)->GetBinContent(bin400) * CalcSSQcdErr(emuMasses, systErrMCLuEff, bin400)); // } else { // printf("nb %7s | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", sampleNames[sampleIt], // emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin60), emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin60) * systErrMCLuEff[sampleIt-1], // emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin120), emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin120) * systErrMCLuEff[sampleIt-1], // emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin200), emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin200) * systErrMCLuEff[sampleIt-1], // emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin400), emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin400) * systErrMCLuEff[sampleIt-1]); // } // } // cout << endl; // cout << "----------------------------------------------------------------------------------------------------------------------------------------" << endl; // printf("TOT ttlike | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", // CalcBgSum(emuMasses, ttLikeSamples, signIt, bin60), CalcSystErr(emuMasses, systErrMCLuEff, ttLikeSamples, signIt, bin60), // CalcBgSum(emuMasses, ttLikeSamples, signIt, bin120), CalcSystErr(emuMasses, systErrMCLuEff, ttLikeSamples, signIt, bin120), // CalcBgSum(emuMasses, ttLikeSamples, signIt, bin200), CalcSystErr(emuMasses, systErrMCLuEff, ttLikeSamples, signIt, bin200), // CalcBgSum(emuMasses, ttLikeSamples, signIt, bin400), CalcSystErr(emuMasses, systErrMCLuEff, ttLikeSamples, signIt, bin400)); // printf("TOT contam | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", // CalcBgSum(emuMasses, contamSamples, signIt, bin60), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, contamSamples, signIt, bin60, -1, calcQcdErr), // CalcBgSum(emuMasses, contamSamples, signIt, bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, contamSamples, signIt, bin120, -1, calcQcdErr), // CalcBgSum(emuMasses, contamSamples, signIt, bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, contamSamples, signIt, bin200, -1, calcQcdErr), // CalcBgSum(emuMasses, contamSamples, signIt, bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, contamSamples, signIt, bin400, -1, calcQcdErr)); // cout << "----------------------------------------------------------------------------------------------------------------------------------------" << endl; // // printf("TOT Bkg | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", // CalcBgSum(emuMasses, allSamples, signIt, bin60), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin60, -1, calcQcdErr), // CalcBgSum(emuMasses, allSamples, signIt, bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin120, -1, calcQcdErr), // CalcBgSum(emuMasses, allSamples, signIt, bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin200, -1, calcQcdErr), // CalcBgSum(emuMasses, allSamples, signIt, bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin400, -1, calcQcdErr)); // cout << "----------------------------------------------------------------------------------------------------------------------------------------" << endl; // cout << endl << endl; // } // cout << endl; // // cout << "--Without adding QCD contribution:--------------------------------------------------------------------------------------------------------" << endl; // cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl; // cout << "M_emu | > 60GeV/c^2 | > 120GeV/c^2 | > 200GeV/c^2 | > 400GeV/c^2 |" << endl; // cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl; // for (unsigned int signIt = 1; signIt < 6; signIt += 2) { // if (signIt == 3) cout << "-SS-------------------------------------------------------------------------------------------------------------------------------------" << endl; // if (signIt == 5) cout << "-OS-------------------------------------------------------------------------------------------------------------------------------------" << endl; // printf("nb data | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) |\n", // emuMasses.at(DATA).at(signIt)->GetBinContent(bin60), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin60)), // emuMasses.at(DATA).at(signIt)->GetBinContent(bin120), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin120)), // emuMasses.at(DATA).at(signIt)->GetBinContent(bin200), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin200)), // emuMasses.at(DATA).at(signIt)->GetBinContent(bin400), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin400))); // printf("nb MC | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", // CalcBgSum(emuMasses, allSamplesNoQcd, signIt, bin60), CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, signIt, bin60), // CalcBgSum(emuMasses, allSamplesNoQcd, signIt, bin120), CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, signIt, bin120), // CalcBgSum(emuMasses, allSamplesNoQcd, signIt, bin200), CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, signIt, bin200), // CalcBgSum(emuMasses, allSamplesNoQcd, signIt, bin400), CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, signIt, bin400)); // } // cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl; // // if (qcdEst == 1) { // //systErrMC.back() = 2 * sqrt(emuMasses.at(DATA).at(SS)->Integral() + pow(CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, SS, 1), 2)) / emuMasses.at(qcdInd).at(ALL)->Integral(); // //systErrMC.back() = CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, SSCUM, 1) / emuMass_qcd.at(SSCUM)->GetBinContent(1); // //systErrMCLuEff.back() = systErrMC[qcdErrInd]; // // cout << endl; // cout << "---QCD events from SS spectrum:----------------------------------------------------------------------------------------------------------------------------------" << endl; // cout << "-----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl; // printf("nb QCD SS+OS | %9.3f +- %8.3f (%.1f%%) (syst) | %9.3f +- %8.3f (%.1f%%) (syst) | %9.3f +- %8.3f (%.1f%%) (syst) | %9.3f +- %8.3f (%.1f%%) (syst) |\n", // emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin60), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin60, -1, calcQcdErr), // 100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin60, -1, calcQcdErr) / emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin60), // emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin120, -1, calcQcdErr), // 100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin120, -1, calcQcdErr) / emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin120), // emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin200, -1, calcQcdErr), // 100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin200, -1, calcQcdErr) / emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin200), // emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin400, -1, calcQcdErr), // 100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin400, -1, calcQcdErr) / emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin400)); // printf("%% of total MC | %7.3f%% +- %7.3f%% (syst) | %7.3f%% +- %7.3f%% (syst) | %7.3f%% +- %7.3f%% (syst) | %7.3f%% +- %7.3f%% (syst) |\n", // 100 * emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin60) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin60), // 100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin60, -1, calcQcdErr) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin60), // 100 * emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin120) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin120), // 100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin120, -1, calcQcdErr) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin120), // 100 * emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin200) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin200), // 100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin200, -1, calcQcdErr) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin200), // 100 * emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin400) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin400), // 100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin400, -1, calcQcdErr) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin400)); // cout << "-----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl; // } // // // top up bg contribution with qcd // if (qcdEst > 0) { // cout << endl; // cout << "--After adding QCD contribution:----------------------------------------------------------------------------------------------------------" << endl; // cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl; // cout << "M_emu | > 60GeV/c^2 | > 120GeV/c^2 | > 200GeV/c^2 | > 400GeV/c^2 |" << endl; // cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl; // for (unsigned int signIt = 1; signIt < 6; signIt += 2) { // if (signIt == 3) cout << "-SS-------------------------------------------------------------------------------------------------------------------------------------" << endl; // if (signIt == 5) cout << "-OS-------------------------------------------------------------------------------------------------------------------------------------" << endl; // printf("nb data | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) |\n", // emuMasses.at(DATA).at(signIt)->GetBinContent(bin60), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin60)), // emuMasses.at(DATA).at(signIt)->GetBinContent(bin120), sqrt((emuMasses.at(DATA).at(signIt))->GetBinContent(bin120)), // emuMasses.at(DATA).at(signIt)->GetBinContent(bin200), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin200)), // emuMasses.at(DATA).at(signIt)->GetBinContent(bin400), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin400))); // printf("nb MC | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", // CalcBgSum(emuMasses, allSamples, signIt, bin60), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin60, -1, calcQcdErr), // CalcBgSum(emuMasses, allSamples, signIt, bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin120, -1, calcQcdErr), // CalcBgSum(emuMasses, allSamples, signIt, bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin200, -1, calcQcdErr), // CalcBgSum(emuMasses, allSamples, signIt, bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin400, -1, calcQcdErr)); // } // cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl; // } // // cout << endl; // cout << "-----------------------------------------------------------------------------------------------------------" << endl; // cout << "M_emu | 60 - 120GeV/c^2 | 120 - 200GeV/c^2 | 200 - 400GeV/c^2 |" << endl; // cout << "-----------------------------------------------------------------------------------------------------------" << endl; // for (unsigned int signIt = 1; signIt < 6; signIt += 2) { // printf("nb data | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) | %5.0f +- %-.3f (stat) |\n", // emuMasses.at(DATA).at(signIt)->GetBinContent(bin60) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin120), // sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin60) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin120)), // emuMasses.at(DATA).at(signIt)->GetBinContent(bin120) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin200), // sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin120) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin200)), // emuMasses.at(DATA).at(signIt)->GetBinContent(bin200) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin400), // sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin200) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin400))); // printf("nb MC | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", // CalcBgSum(emuMasses, allSamples, signIt, bin60, bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin60, bin120, calcQcdErr), // CalcBgSum(emuMasses, allSamples, signIt, bin120, bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin120, bin200, calcQcdErr), // CalcBgSum(emuMasses, allSamples, signIt, bin200, bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin200, bin400, calcQcdErr)); // cout << "-----------------------------------------------------------------------------------------------------------" << endl; // } }
void shapehist() { bool makeplot = true; double bins[] = {250., 266, 285., 305., 330., 360., 400., 450., 500., 550., 1000.}; int nbins = 10; TH1F* hisdt = new TH1F("data_obs" , "", nbins, bins); TH1F* hisdm = new TH1F("DM" , "", nbins, bins); TH1F* hiszj = new TH1F("ZJets" , "", nbins, bins); TH1F* hisdi = new TH1F("Dibosons" , "", nbins, bins); TH1F* histt = new TH1F("ttbar" , "", nbins, bins); TH1F* hisst = new TH1F("singletop" , "", nbins, bins); TH1F* hisqc = new TH1F("QCD" , "", nbins, bins); TH1F* hiswj = new TH1F("WJets" , "", nbins, bins); TH1F* hiszn = new TH1F("Znunu" , "", nbins, bins); TH1F* hist1 = new TH1F("hist1" , "", nbins, bins); TH1F* hist2 = new TH1F("hist2" , "", nbins, bins); TH1F* hiswu = new TH1F("WJets_Stat_WJETSUp" , "", nbins, bins); TH1F* hiswd = new TH1F("WJets_Stat_WJETSDown" , "", nbins, bins); TH1F* hiszu = new TH1F("Znunu_Stat_ZNUNUUp" , "", nbins, bins); TH1F* hiszd = new TH1F("Znunu_Stat_ZNUNUDown" , "", nbins, bins); hisdt->Sumw2(); hisdm->Sumw2(); hiszn->Sumw2(); hiswj->Sumw2(); hiszj->Sumw2(); hisdi->Sumw2(); histt->Sumw2(); hisst->Sumw2(); hisqc->Sumw2(); hiszu->Sumw2(); hiszd->Sumw2(); hiswu->Sumw2(); hiswd->Sumw2(); hist1->Sumw2(); hist2->Sumw2(); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/met/ztree.root", "tree/tree", 1, 1.0 , hiszn); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/bkgz/ztree.root", "tree/tree", 1, 19.7, hist1); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/bkgnowz/ztree.root","tree/tree", 1, 19.7, hist1); hiszn->Add(hist1, -1.0); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/met/wtree.root", "tree/tree", 2, 1.0 , hiswj); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/bkgw/wtree.root", "tree/tree", 2, 19.7, hist2); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/bkgnowz/wtree.root","tree/tree", 2, 19.7, hist2); hiswj->Add(hist2, -1.0); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/dmVM100/reducedtree.root" , "tree/tree", 0, 19.7 , hisdm); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/met/reducedtree.root" , "tree/tree", 0, 1.0 , hisdt); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/zjets/reducedtree.root" , "tree/tree", 0, 19.7 , hiszj); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/dibosons/reducedtree.root" , "tree/tree", 0, 19.7 , hisdi); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/ttbar/reducedtree.root" , "tree/tree", 0, 19.7 , histt); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/singletop/reducedtree.root", "tree/tree", 0, 19.7 , hisst); fillhist("/home/avartak/CMS/MonoX/CMSSW_5_3_12/src/MonoXAnalysis/AnalysisStep/trees/qcd/reducedtree.root" , "tree/tree", 0, 19.7*1.3 , hisqc); for (int i = 1; i <= nbins; i++) { hiszu->SetBinContent(i, hiszn->GetBinContent(i) + hiszn->GetBinError(i)); hiszd->SetBinContent(i, hiszn->GetBinContent(i) - hiszn->GetBinError(i)); hiswu->SetBinContent(i, hiswj->GetBinContent(i) + hiswj->GetBinError(i)); hiswd->SetBinContent(i, hiswj->GetBinContent(i) - hiswj->GetBinError(i)); } for (int i = 1; i <= nbins; i++) { if (hiszj->GetBinContent(i) == 0) hiszj->SetBinContent(i, 0.001); if (hisdi->GetBinContent(i) == 0) hisdi->SetBinContent(i, 0.001); if (histt->GetBinContent(i) == 0) histt->SetBinContent(i, 0.001); if (hisst->GetBinContent(i) == 0) hisst->SetBinContent(i, 0.001); if (hisqc->GetBinContent(i) == 0) hisqc->SetBinContent(i, 0.001); hiszj->SetBinError(i, 0.5*hiszj->GetBinContent(i)); hisdi->SetBinError(i, 0.5*hisdi->GetBinContent(i)); histt->SetBinError(i, 0.5*histt->GetBinContent(i)); hisst->SetBinError(i, 0.5*hisst->GetBinContent(i)); hisqc->SetBinError(i, 0.5*hisqc->GetBinContent(i)); } std::cout << "data_obs : " << hisdt->Integral() << std::endl; std::cout << "DM : " << hisdm->Integral() << std::endl; std::cout << "Znunu : " << hiszn->Integral() << std::endl; std::cout << "WJets : " << hiswj->Integral() << std::endl; std::cout << "ZJets : " << hiszj->Integral() << std::endl; std::cout << "Dibosons : " << hisdi->Integral() << std::endl; std::cout << "ttbar : " << histt->Integral() << std::endl; std::cout << "singletop : " << hisst->Integral() << std::endl; std::cout << "QCD : " << hisqc->Integral() << std::endl; if (makeplot) { hiszj->Add(hisdi); hiszj->Add(histt); hiszj->Add(hisst); hiszj->Add(hisqc); hiswj->Add(hiszj); hiszn->Add(hiswj); hiszu->Add(hiswj); hiszd->Add(hiswj); hiszj->SetLineColor(kGreen+2); hiswj->SetLineColor(kRed); hiszn->SetLineColor(kBlue); hiszj->SetLineWidth(2); hiswj->SetLineWidth(2); hiszn->SetLineWidth(2); hiszu->SetMarkerSize(0); hiszu->SetMarkerColor(0); hiszu->SetLineColor(kOrange); hiszu->SetFillColor(kOrange); hiszd->SetMarkerSize(0); hiszd->SetMarkerColor(0); hiszd->SetLineColor(10); hiszd->SetFillColor(10); hiszj->SetMarkerSize(0); hiswj->SetMarkerSize(0); hiszn->SetMarkerSize(0); hisdm->SetMarkerSize(0); hisdm->SetLineStyle(7); hisdm->SetLineWidth(2); TCanvas* canvas = new TCanvas("canvas", "canvas", 500, 500); canvas->SetRightMargin(0.075); canvas->SetTopMargin(0.075); TH1* frame = canvas->DrawFrame(250., 2.0, 1000., 100000.0, ""); frame->GetXaxis()->SetTitle("E_{T}^{miss} [GeV]"); frame->GetXaxis()->SetLabelSize(0.9*frame->GetXaxis()->GetLabelSize()); frame->GetYaxis()->SetLabelSize(0.9*frame->GetYaxis()->GetLabelSize()); canvas->SetLogy(); frame->Draw(); hiszu->Draw("HIST SAME"); hiszd->Draw("HIST SAME"); hiszn->Draw("HIST SAME"); hiswj->Draw("HIST SAME"); hiszj->Draw("HIST SAME"); hisdm->Draw("HIST SAME"); hisdt->Draw("PE SAME"); canvas->RedrawAxis(); } else { TFile* outfile = new TFile("monojet_8TeV_shape_histogram.root", "RECREATE"); hisdt->Write(); hisdm->Write(); hiszn->Write(); hiswj->Write(); hiszj->Write(); hisdi->Write(); histt->Write(); hisst->Write(); hisqc->Write(); hiszu->Write(); hiszd->Write(); hiswu->Write(); hiswd->Write(); outfile->Close(); } }
void bbtt_upg_mt(std::string var,int nbins, double xmin, double xmax,std::string xtitle, std::string ytitle, double sigscale=1,int hist=1) { double massLEdges[14] = {-0.5,-0.45,-0.4,-0.35,-0.3,-0.25,-0.2,-0.15,-0.1,-0.05,0.0,0.05,0.1,0.2}; TFile *outDC = new TFile("hh_mt_inputs.root","RECREATE"); //SetStyle(); gStyle->SetLineStyleString(11,"20 10"); setTDRStyle(); TH1::SetDefaultSumw2(1); std::string dir = "/data/blue/Bacon/029a/Upgrade/sep-2-bbtt/"; std::stringstream scale; scale << sigscale; //Cut definitions double luminosity = 3000; std::stringstream lumi; lumi << luminosity; std::string objcut = "(tauCat1==1 && tauCat2==3 && ptTau1>30 && ptTau2>30 && (bTag1==2||bTag1==3||bTag1==6||bTag1==7) && (bTag2==2||bTag2==3||bTag2==6||bTag2==7) && ptB1>30 && ptB2>30)*(abs(etaB1)<2.5 && abs(etaB2)<2.5 && abs(etaTau1)<2.1 && abs(etaTau2)<2.5 && ptTrk1>0)";//*(tauIso2<0.15)"; std::string jetcut = objcut+"*(m_svpileup>100 && m_svpileup<150 && mBB1>90 && mBB1<130 && mt2pileup>100)"; //std::string jetcut = objcut+"*(m_svpileup>100 && m_svpileup<150 && mBB1>90 && mBB1<130)"; //std::string jetcut = objcut+"*(1.0)"; //signal region std::string mccut = jetcut+"*eventWeight*"+lumi.str(); std::string sigcut = jetcut+"*eventWeight*"+lumi.str(); std::string zjetcut = jetcut+"*eventWeight*(eventType!=3&&eventType!=1)*"+lumi.str(); std::string wjetcut = jetcut+"*eventWeight*(eventType==3&&eventType!=1)*"+lumi.str(); std::string ewkcut = jetcut+"*eventWeight*(eventType!=1)*"+lumi.str(); std::string vbfcut = jetcut+"*eventWeight*49470*0.0632*"+lumi.str(); //-------------------------------------------------------------------------- //Get the trees TTree *hhtree = load(dir+"gFHHTobbtautau.root"); TTree *hhtree_m1 = load(dir+"gFHHTobbtautaulam1m.root"); TTree *hhtree_m5 = load(dir+"gFHHTobbtautaulam5m.root"); TTree *hhtree_0 = load(dir+"gFHHTobbtautaulam0.root"); TTree *hhtree_p5 = load(dir+"gFHHTobbtautaulam5p.root"); TTree *hhtree_vbf = load("/data/blue/Bacon/029a/Upgrade/sep-10-bbtt/vbfHHTobbtautau.root"); TTree *tttree = load(dir+"tt.root"); TTree *vbfhtree = load(dir+"VBFHToTauTau.root"); TTree *gfhtree = load(dir+"ggFHToTauTau.root"); TTree *assohtree = load(dir+"vH_ttH.root"); TTree *vjettree = load(dir+"Bjets.root"); TTree *ewktree = load(dir+"ewk.root"); //------------------------------------------------------------------------- //Get histograms TCanvas *canv0 = MakeCanvas("canv", "histograms", 600, 600); canv0->cd(); std::string vardraw; TH1F *Ztt; if(hist) Ztt = new TH1F("DY","",nbins,xmin,xmax); else Ztt = new TH1F("DY","",13, massLEdges); vardraw = var+">>"+"DY"; vjettree->Draw(vardraw.c_str(),zjetcut.c_str()); InitHist(Ztt , xtitle.c_str(), ytitle.c_str(), TColor::GetColor(248,206,104), 1001); TH1F *ttbar; if(hist) ttbar = new TH1F("TTbar","",nbins,xmin,xmax); else ttbar = new TH1F("TTbar","",13, massLEdges); vardraw = var+">>"+"TTbar"; tttree->Draw(vardraw.c_str(),mccut.c_str()); InitHist(ttbar, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(155,152,204), 1001); TH1F *wjets; if(hist) wjets= new TH1F("Wjets","",nbins,xmin,xmax); else wjets = new TH1F("Wjets","",13, massLEdges); vardraw = var+">>"+"Wjets"; vjettree->Draw(vardraw.c_str(),wjetcut.c_str()); InitHist(wjets, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(222,90,106), 1001); TH1F *ewk; if(hist) ewk = new TH1F("Ewk","",nbins,xmin,xmax); else ewk = new TH1F("Ewk","",13,massLEdges); vardraw = var+">>"+"Ewk"; ewktree->Draw(vardraw.c_str(),ewkcut.c_str()); InitHist(ewk, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(222,90,106), 1001); TH1F *vbfh; if(hist) vbfh = new TH1F("VBFH","",nbins,xmin,xmax); else vbfh = new TH1F("VBFH","",13,massLEdges); vardraw = var+">>"+"VBFH"; vbfhtree->Draw(vardraw.c_str(),vbfcut.c_str()); InitHist(vbfh, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(250,202,255), 1001); TH1F *ggh; if(hist) ggh = new TH1F("GGH","",nbins,xmin,xmax); else ggh = new TH1F("GGH","",13,massLEdges); vardraw = var+">>"+"GGH"; gfhtree->Draw(vardraw.c_str(),mccut.c_str()); InitHist(ggh, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(250,202,255), 1001); TH1F *assoh; if(hist) assoh = new TH1F("AH","",nbins,xmin,xmax); else assoh = new TH1F("AH","",13,massLEdges); vardraw = var+">>"+"AH"; assohtree->Draw(vardraw.c_str(),mccut.c_str()); InitHist(assoh, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(250,202,255), 1001); TH1F *smhh; if(hist) smhh= new TH1F("SMhh","",nbins,xmin,xmax); else smhh= new TH1F("SMhh","",13,massLEdges); vardraw = var+">>"+"SMhh"; hhtree->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(smhh); smhh->SetLineColor(kBlack); TH1F *hh_0 = new TH1F("hh_0","",nbins,xmin,xmax); vardraw = var+">>"+"hh_0"; hhtree_0->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_0); hh_0->SetLineColor(kBlack); TH1F *hh_m1; if(hist) hh_m1 = new TH1F("hh_m1","",nbins,xmin,xmax); else hh_m1 = new TH1F("hh_m1","",13,massLEdges); vardraw = var+">>"+"hh_m1"; hhtree_m1->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_m1); hh_m1->SetLineColor(kBlack); TH1F *hh_m5; if(hist) hh_m5 = new TH1F("hh_m5","",nbins,xmin,xmax); else hh_m5 = new TH1F("hh_m5","",13,massLEdges); vardraw = var+">>"+"hh_m5"; hhtree_m5->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_m5); hh_m5->SetLineColor(kBlack); TH1F *hh_p5; if(hist) hh_p5= new TH1F("hh_p5","",nbins,xmin,xmax); else hh_p5= new TH1F("hh_p5","",13,massLEdges); vardraw = var+">>"+"hh_p5"; hhtree_p5->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_p5); hh_p5->SetLineColor(kBlack); TH1F *hh_vbf; if(hist) hh_vbf= new TH1F("hh_vbf","",nbins,xmin,xmax); else hh_vbf= new TH1F("hh_vbf","",13,massLEdges); vardraw = var+">>"+"hh_vbf"; hhtree_vbf->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_vbf); hh_vbf->SetLineColor(kBlue); delete canv0; //for(int i0 = 0; i0 < ewk->GetNbinsX()+1; i0++) // if(ewk->GetBinContent(i0) == 0) // ewk->SetBinError(i0,2.8); //--------------------------------------------------------------------------- //Print out the yields Double_t error=999; Double_t sigN=0; Double_t sigSig=0; Double_t bgdN=0; Double_t bgdSig=0; //ofstream outfile; //outfile.open("yields.txt"); //outfile << "Yields for the signal region." << std::endl; cout << jetcut << endl; cout << "SM hh " << smhh->IntegralAndError(0,smhh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; cout << " VBF HH " << hh_vbf->IntegralAndError(0,hh_vbf->GetNbinsX(),error) << "+/-"; sigN+=smhh->IntegralAndError(0,smhh->GetNbinsX(),error); sigSig+=error; cout << error << endl; error=999; cout << "ttbar " << ttbar->IntegralAndError(0,ttbar->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=ttbar->IntegralAndError(0,ttbar->GetNbinsX(),error);bgdSig+=error*error; cout << "Ztt " << Ztt->IntegralAndError(0,Ztt->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=Ztt->IntegralAndError(0,Ztt->GetNbinsX(),error);bgdSig+=error*error; cout << "ewk " << ewk->IntegralAndError(0,ewk->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=ewk->IntegralAndError(0,ewk->GetNbinsX(),error);bgdSig+=error*error; cout << "wjets " << wjets->IntegralAndError(0,wjets->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=wjets->IntegralAndError(0,wjets->GetNbinsX(),error);bgdSig+=error*error; cout << "ggH " << ggh->IntegralAndError(0,ggh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=ggh->IntegralAndError(0,ggh->GetNbinsX(),error);bgdSig+=error*error; cout << "vbfH " << vbfh->IntegralAndError(0,vbfh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=vbfh->IntegralAndError(0,vbfh->GetNbinsX(),error);bgdSig+=error*error; cout << "vH/ttH " << assoh->IntegralAndError(0,assoh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=assoh->IntegralAndError(0,assoh->GetNbinsX(),error); bgdSig+=error*error; cout << "S = " << sigN << "+/-" << sigSig << endl; cout << "B = " << bgdN << "+/-" << TMath::Sqrt(bgdSig) << endl; cout << "S/sqrt(B) = " << sigN/TMath::Sqrt(bgdN) << endl; //-------------------------------------------------------------------------- //outfile.close(); outDC->cd(); TDirectory* lTD = outDC->mkdir("mutau"); outDC->cd(lTD->GetPath()); ttbar->SetName("data_obs"); ttbar->SetTitle("data_obs"); ttbar->Write(); Ztt->SetName("ZTT"); Ztt->SetTitle("ZTT"); Ztt->Write(); ttbar->SetName("TT"); ttbar->SetTitle("TT"); ttbar->Write(); wjets->SetName("W"); wjets->SetTitle("W"); wjets->Write(); ewk->SetName("VV"); ewk->SetTitle("VV"); ewk->Write(); vbfh->SetName("qqH"); vbfh->SetTitle("qqH"); vbfh->Write(); ggh->SetName("ggH"); ggh->SetTitle("ggH"); ggh->Write(); assoh->SetName("assoH"); assoh->SetTitle("assoH"); assoh->Write(); smhh->SetName("ggHH"); smhh->SetTitle("ggHH"); smhh->Write(); hh_0->SetName("lam0"); hh_0->SetTitle("lam0"); hh_0->Write(); hh_m5->SetName("lamm5"); hh_m5->SetTitle("lamm5"); hh_m5->Write(); hh_m1->SetName("lamm1"); hh_m1->SetTitle("lamm1"); hh_m1->Write(); hh_p5->SetName("lamp5"); hh_p5->SetTitle("lamp5"); hh_p5->Write(); hh_vbf->SetName("qqHH"); hh_vbf->SetTitle("qqHH"); hh_vbf->Write(); outDC->Close(); //stack some histtograms together vbfh->Add(ggh); vbfh->Add(assoh); cout << "Single H " << vbfh->IntegralAndError(0,vbfh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; wjets->Add(ewk); cout << "Total Electroweak " << wjets->IntegralAndError(0,wjets->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; //----------------------------------------------------------------------- smhh->Scale(sigscale); //Draw the histograms TCanvas *canv = MakeCanvas("canv", "histograms", 800, 600); canv->cd(); wjets->Add(ttbar); Ztt->Add(wjets); vbfh->Add(Ztt); //Error band stat TH1F* errorBand = (TH1F*)vbfh->Clone("errorBand"); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(13); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); // for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ // if(errorBand->GetBinContent(idx)>0){ // std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; // break; // } //} vbfh->SetMaximum(1.0*std::max(maximum(vbfh, 0), maximum(smhh, 0))); //blind(data,75,150); //data->Draw("e"); vbfh->Draw("hist"); Ztt->Draw("histsame"); wjets->Draw("histsame"); //ggh->Draw("histsame"); ttbar->Draw("histsame"); //qcd->Draw("histsame"); //data->Draw("esame"); errorBand->Draw("e2same"); smhh->Draw("histsame"); canv->RedrawAxis(); //canv->SetLogy(1); //--------------------------------------------------------------------------- //Adding a legend TLegend* leg = new TLegend(0.65, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(smhh , TString::Format("%.0f#timeshh#rightarrow#tau#tau bb", sigscale) , "L" ); leg->AddEntry(vbfh , "SM H#rightarrow#tau#tau" , "F" ); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(wjets , "Electroweak" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(errorBand,"bkg. uncertainty","F"); leg->Draw(); //--------------------------------------------------------------------------- //CMS_lumi_v2( canv, 14, 11 ); //CMS preliminary //const char* dataset = "CMS Simulation, 3000 fb^{-1} at 14 TeV"; const char* category = ""; //CMSPrelim(dataset, "#tau_{#mu}#tau_{h}", 0.17, 0.835); //CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.52, 0.35, 0.91, 0.55, "tlbrNDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); //chan->Draw(); //------------------------------------------------------------------------- //Save histograms canv->Print((var+"_mt.png").c_str()); /* Ratio Data over MC */ /* TCanvas *canv1 = MakeCanvas("canv0", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); TH1F* model = (TH1F*)Ztt ->Clone("model"); TH1F* test1 = (TH1F*)vbfh->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); //model->SetBinError (ibin+1, CONVERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); model->SetBinError (ibin+1, 0); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; double chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; double ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; double ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; std::vector<double> edges; TH1F* zero = (TH1F*)ttbar->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)vbfh->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, Ztt->GetBinContent(ibin+1)>0 ? vbfh->GetBinContent(ibin+1)/Ztt->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? vbfh->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? Ztt ->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv1->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); //stat1->Draw(); canv1->Print((var+"_ratio.png").c_str()); */ }
void DrawQCDClosure(TString VAR,TString XTITLE) { gROOT->ForceStyle(); TString FileName[7] = {"QCD_HT200to300","QCD_HT300to500","QCD_HT500to700","QCD_HT700to1000","QCD_HT1000to1500","QCD_HT1500to2000","QCD_HT2000toInf"}; float XSEC[7] = {1.74e+6,3.67e+5,2.94e+4,6.524e+03,1.064e+03,121.5,2.542e+01}; TFile *inf[7]; TH1F *h[7],*h1[7]; TCanvas *can = new TCanvas("can_QCDClosure_"+VAR,"can_QCDClosure_"+VAR,900,600); can->cd(1); can->SetBottomMargin(0.3); can->SetRightMargin(0.15); for(int i=0;i<7;i++) { inf[i] = TFile::Open("Histo_"+FileName[i]+".root"); TH1F *hTriggerPass = (TH1F*)inf[i]->Get("hadtopL/TriggerPass"); h[i] = (TH1F*)inf[i]->Get("hadtopL/h_"+VAR); h1[i] = (TH1F*)inf[i]->Get("hadtop/h_"+VAR); h[i]->Sumw2(); h1[i]->Sumw2(); h[i]->Rebin(5); h1[i]->Rebin(5); h[i]->Scale(XSEC[i]/hTriggerPass->GetBinContent(1)); h1[i]->Scale(XSEC[i]/hTriggerPass->GetBinContent(1)); cout<<hTriggerPass->GetBinContent(1)<<endl; } TH1F *hQCD = (TH1F*)h[0]->Clone("hQCD"); TH1F *hQCD1 = (TH1F*)h1[0]->Clone("hQCD1"); for(int i=0;i<7;i++) { hQCD->Add(h[i]); hQCD1->Add(h1[i]); } hQCD->SetFillColor(kGray); hQCD->Scale(1./hQCD->Integral()); hQCD1->Scale(1./hQCD1->Integral()); hQCD->GetXaxis()->SetLabelSize(0.0); double max = 1.1*TMath::Max(hQCD->GetBinContent(hQCD->GetMaximumBin()),hQCD1->GetBinContent(hQCD1->GetMaximumBin())); hQCD->SetMinimum(1e-5); hQCD->SetMaximum(max); hQCD->Draw("hist"); hQCD1->Draw("sameE"); gPad->RedrawAxis(); TLegend *leg = new TLegend(0.86,0.65,0.99,0.9); leg->SetFillColor(0); leg->SetTextFont(42); leg->SetTextSize(0.03); leg->AddEntry(hQCD,"Control","F"); leg->AddEntry(hQCD1,"Signal","LP"); leg->Draw(); TH1F *hRatio = (TH1F*)hQCD1->Clone("Ratio"); hRatio->Divide(hQCD); TPad* pad = new TPad("pad", "pad", 0., 0., 1., 1.); pad->SetTopMargin(0.7); pad->SetRightMargin(0.15); pad->SetFillColor(0); pad->SetFillStyle(0); pad->Draw(); pad->cd(0); gPad->SetGridy(); hRatio->GetXaxis()->SetTitle(XTITLE); hRatio->GetYaxis()->SetNdivisions(505); hRatio->GetYaxis()->SetRangeUser(0,2); hRatio->GetYaxis()->SetLabelSize(0.04); hRatio->Draw(); }
void drawVBFSpec(TTree **iTree,TH1F **iH,TH1F **iHSS,TH1F **iHMT,TH1F **iHLIS,TH1F **iHTIS,TH1F **iHNMT,TH1F **iHMTSS,TH1F **iHTemp,int iN,std::string iVar,std::string iCut,bool is2012,TFile * iFile = 0,std::string iDirName="",bool *iUseScale,TH1F** iHHigh,TH1F** iHLow) { std::string lVBF = "*(njetingap == 0 && mjj > 500 && jdeta > 3.5)";// && nbtag == 0)"; for(int i0 = 0; i0 < iN; i0++) { //iHNMT [i0] = draw(iVar,iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 > -10)*(iso_1 < 0.1 && iso_2 > 0.795) "+lVBF," nm_{T}"); //iHMTSS[i0] = draw(iVar,iTree[i0],i0,iCut+"*(q_1*q_2 > 0)*(mtMVA_1 > -10)*(iso_1 < 0.3 && iso_2 > -0.50 ) "+lVBF," nm_{T} SS"); iH [i0] = draw(iVar,iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 < 20)*(iso_1 < 0.1 && "+fIso+" ) "+lVBF," Main"); iHSS [i0] = draw(iVar,iTree[i0],i0,iCut+"*(q_1*q_2 > 0)*(mtMVA_1 < 20)*(iso_1 < 0.3 && "+fIso+" && iso_1 > 0.1 )"+lVBF," Same Sign"); iHMT [i0] = draw(iVar,iTree[i0],i0,iCut+"* (mtMVA_1 > 70 && mtMVA_1 < 120)*(iso_1 < 0.1 && "+fIso+" && m_sv < 145)"+lVBF," m_{T} > 70 GeV"); iHNMT [i0] = draw(iVar,iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 > 0) *(iso_1 < 0.3 && "+fIso+" )"+lVBF," No m"); iHMTSS[i0] = draw(iVar,iTree[i0],i0,iCut+"*(q_1*q_2 > 0)*(mtMVA_1 > 70 && mtMVA_1 < 120)*(iso_1 < 0.1 && "+fIso+" )"+lVBF," XNomSS"); iHTemp[i0] = draw(iVar,iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*"+fFreeWeights[i0] ," XFree"); iHLIS [i0] = draw(iVar,iTree[i0],i0,iCut+"*(q_1*q_2 > 0)*(mtMVA_1 < 20)*(iso_1 < 0.3 && "+fIso+" & iso_1 > 0.1)" ," X2 Jet Loose Iso SS Cut"); iHTIS [i0] = draw(iVar,iTree[i0],i0,iCut+"*(q_1*q_2 > 0)*(mtMVA_1 < 20)*(iso_1 < 0.1 && "+fIso+" )" ," Y2 Jet Tight Iso SS Cut"); cout << " +===> " << iHLIS[i0]->Integral() << " -- " << iHTIS[i0]->Integral() << endl; if(iFile == 0 ) continue; iHHigh[i0] = 0; iHLow[i0] = 0; if(!iUseScale[i0]) continue; iHHigh[i0] = draw(iVar+"High",iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 < 20)"," Main High"); iHLow [i0] = draw(iVar+"Low" ,iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 < 20)"," Main Low"); } //Comput MT Scale Factor TH1F *lMTMC = (TH1F*) iHMT [0]->Clone("mTTmp"); clear(lMTMC); TH1F *lMTMCS = (TH1F*) iHMTSS[0]->Clone("mTTmpS"); clear(lMTMCS); for(int i0 = 0; i0 < iN-1; i0++) { if(i0 == fWId || i0 == fQCDId) continue; lMTMC ->Add(iHMT[i0]); lMTMCS->Add(iHMTSS[i0]); } double lDataInt = iHMT[iN-1] ->Integral(-1,1000) - lMTMC ->Integral(-1,1000); double lDataSSInt = iHMTSS[iN-1]->Integral(-1,1000) - lMTMCS->Integral(-1,1000); double lWSF = float(iHMT [fWId]->Integral(-1,1000))/lDataInt; double lWSFSS = float(iHMTSS[fWId]->Integral(-1,1000))/lDataSSInt; cout << "===> W Boson Scale Factor : " << lWSF << " -W- " << lWSFSS << " -Data- "<< lDataInt << " - " << iHMT[iN-1]->Integral(-1,1000) << " MC- " << lMTMC->Integral(-1,1000) << endl; if(lWSF == 0) lWSF = 1.; if(lWSFSS == 0) lWSFSS = 1.; iH [fWId]->Scale(1./lWSF); iHSS [fWId]->Scale(1./lWSF); iHMT [fWId]->Scale(1./lWSF); iHMTSS[fWId]->Scale(1./lWSF); //!!!!! Do we need to do this //iHLIS [fWId]->Scale(1./lWSF); //iHTIS [fWId]->Scale(1./lWSF); //Compute QCD Shape TH1F *lSS = (TH1F*) iHSS [0]->Clone("SSTmp0"); clear(lSS); TH1F *lSSL = (TH1F*) iHLIS [0]->Clone("SSTmp1"); clear(lSSL); TH1F *lSST = (TH1F*) iHTIS [0]->Clone("SSTmp2"); clear(lSST); TH1F *lSSMT = (TH1F*) iHMTSS[0]->Clone("SSTmp3"); clear(lSSMT); for(int i0 = 0; i0 < iN-1; i0++) { if(i0 == fQCDId) continue; lSS ->Add(iHSS [i0]); lSSL ->Add(iHLIS [i0]); lSST ->Add(iHTIS [i0]); lSSMT->Add(iHMTSS[i0]); } iHSS [fQCDId]->Add(lSS ,-1); iHMTSS[fQCDId]->Add(lSSMT ,-1); iHLIS [fQCDId]->Add(lSSL ,-1); iHTIS [fQCDId]->Add(lSST ,-1); clear(iHMT[fQCDId]); for(int i0 = 0; i0 < iHSS [fQCDId]->GetNbinsX()+1; i0++) if(iHSS [fQCDId]->GetBinContent(i0) < 0) iHSS [fQCDId]->SetBinContent(i0,0); for(int i0 = 0; i0 < iHMTSS[fQCDId]->GetNbinsX()+1; i0++) if(iHMTSS[fQCDId]->GetBinContent(i0) < 0) iHMTSS[fQCDId]->SetBinContent(i0,0); for(int i0 = 0; i0 < iHLIS [fQCDId]->GetNbinsX()+1; i0++) if(iHLIS [fQCDId]->GetBinContent(i0) < 0) iHLIS [fQCDId]->SetBinContent(i0,0); for(int i0 = 0; i0 < iHTIS [fQCDId]->GetNbinsX()+1; i0++) if(iHTIS [fQCDId]->GetBinContent(i0) < 0) iHTIS [fQCDId]->SetBinContent(i0,0); iHTIS[fQCDId]->Scale(1.06); double lTightLooseRatio = iHTIS[fQCDId]->Integral()/iHLIS[fQCDId]->Integral(); cout << "===> Tight/Loose QCD Ratio " << lTightLooseRatio << endl; iHSS [fQCDId]->Scale(lTightLooseRatio); iHTIS [fQCDId]->Scale(iHSS[fQCDId]->Integral()/iHTIS[fQCDId]->Integral()); iH [fQCDId] = iHSS [fQCDId]; //Generic Template Definition for the loose cuts for(int i0 = 0; i0 < iN-1; i0++) { if(i0 == fQCDId || i0 == 0) continue; //Keep full selection for Z and QCD double pInt = iH[i0]->Integral(); iH[i0] = iHTemp[i0]; iH[i0]->Scale(pInt/iH[i0]->Integral()); } //Make Data card if(iFile !=0) makeDataCard(iFile,iH,iHHigh,iHLow,iN,iDirName,fString); //Additional Crap //iHNMT [fWId]->Scale(1./lWSF); //iHMTSS [fQCDId]->Scale(lTightLooseRatio); //iHNMT [fQCDId] = iHMTSS[fQCDId]; //Blind //for(int i0 = 0; i0 < iH[iN-1]->GetNbinsX()+1; i0++) if(iH[iN-1]->GetXaxis()->GetBinCenter(i0) > 60 && iH[iN-1]->GetXaxis()->GetBinCenter(i0) < 130) iH[iN-1]->SetBinContent(i0,0); //Draw the plot draw(iH ,iN,iVar+"VBFA",iVar); draw(iHSS ,iN,iVar+"VBFB",iVar); draw(iHMT ,iN,iVar+"VBFC",iVar); //draw(iHLIS ,iN,iVar+"VBFD",iVar); //draw(iHTIS ,iN,iVar+"VBFE",iVar); //draw(iHMTSS,iN,iVar+"VBFF",iVar); //draw(iHNMT ,iN,iVar+"VBFG",iVar); }
void drawSpec(TTree **iTree,TH1F **iH,TH1F **iHSS,TH1F **iHMT,TH1F **iHNMT,TH1F **iHSSMT,TH1F **iHMTS,int iN,std::string iVar,std::string iCut,std::string iName,TFile * iFile = 0,std::string iDirName="",bool *iUseScale,TH1F** iHHigh,TH1F** iHLow) { std::string lVar = iVar; TH1F *lQCDShape = 0; for(int i0 = 0; i0 < iN; i0++) { lVar = iVar; iH [i0] = draw(lVar,iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 < 20)"," Main"); iHSS [i0] = draw(lVar,iTree[i0],i0,iCut+"*(q_1*q_2 > 0)*(mtMVA_1 < 20)"," Same Sign"); iHMT [i0] = draw(lVar,iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 > 70)"," OS m_{T} > 70 GeV"); iHMTS[i0] = draw(lVar,iTree[i0],i0,iCut+"*(q_1*q_2 > 0)*(mtMVA_1 > 70)"," SS m_{T} > 70 GeV"); cout << "====> " << fString[i0] << " -- " << iH[i0]->Integral() << " -- " << fWId << " -- " << fQCDId << endl; if(i0 == fQCDId && iName.find("A") == std::string::npos) lQCDShape = draw(lVar,iTree[i0],iN,iCut+"*(q_1*q_2 > 0)*(mtMVA_1 < 20)"," Same Sign Shape"); //Additional Useless plots //iHNMT[i0] = draw(lVar,iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 > 0)"," No m_{T} Cut"); //iHSSMT[i0] = draw(lVar,iTree[i0],i0,iCut+"*(q_1*q_2 > 0)*(mtMVA_1 > 0)"," Same Sign"); //Dealing with datacards if(iFile == 0 ) continue; iHHigh[i0] = 0; iHLow[i0] = 0; if(!iUseScale[i0]) continue; iHHigh[i0] = draw(iVar+"High",iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 < 20)"," Main High"); iHLow [i0] = draw(iVar+"Low" ,iTree[i0],i0,iCut+"*(q_1*q_2 < 0)*(mtMVA_1 < 20)"," Main Low"); } //Comput MT Scale Factor => separately for SS and OS TH1F *lMTMC = (TH1F*) iHMT [0]->Clone("mTTmp"); clear(lMTMC); TH1F *lMTMCS = (TH1F*) iHMTS[0]->Clone("mTTmpS"); clear(lMTMCS); for(int i0 = 0; i0 < iN-1; i0++) { if(i0 == fWId || i0 == fQCDId) continue; lMTMC ->Add(iHMT [i0]); lMTMCS->Add(iHMTS[i0]); } double lDataInt = iHMT [iN-1]->Integral(-1,1000) - lMTMC ->Integral(-1,1000); double lWSF = float(iHMT[fWId]->Integral(-1,1000))/lDataInt; double lDataSSInt = iHMTS[iN-1]->Integral(-1,1000) - lMTMCS->Integral(-1,1000); double lWSFSS = float(iHMTS[fWId]->Integral(-1,1000))/lDataSSInt; cout << "===> W Boson Scale Factor : " << lWSF << " -W- " << iHMT[fWId]->Integral(-1,1000) << " -- " << iH[fWId]->Integral(-1,1000) << endl; cout << "===> W Boson SS Scale Factor : " << lWSFSS << " -W- " << iHMT[fWId]->Integral(-1,1000) << endl; if(lWSF == 0) lWSF = 1.; if(lWSFSS == 0) lWSFSS = 1.; iH [fWId]->Scale(1./lWSF); iHSS [fWId]->Scale(1./lWSFSS); iHMT [fWId]->Scale(1./lWSF);//No ss iHMTS [fWId]->Scale(1./lWSFSS); //Compute QCD Yield TH1F *lSS = (TH1F*) iHSS[0]->Clone("SSTmp"); clear(lSS); for(int i0 = 0; i0 < iN-1; i0++) {if(i0 == fQCDId) continue; lSS ->Add(iHSS [i0]); } iHSS [fQCDId]->Add(lSS ,-1); //Scale the Shape if(lQCDShape != 0) lQCDShape->Scale(iHSS[fQCDId]->Integral()/lQCDShape->Integral()); if(lQCDShape != 0) iHSS [fQCDId] = lQCDShape; for(int i0 = 0; i0 < iHSS [fQCDId]->GetNbinsX()+1; i0++) if(iHSS [fQCDId]->GetBinContent(i0) < 0) iHSS [fQCDId]->SetBinContent(i0,0); TH1F *lXSS = (TH1F*) iHSS[fQCDId]->Clone("SSF"); lXSS->Scale(1.06); iH [fQCDId] = lXSS;//iHSS[fQCDId]; //Dealing with Addtional Plots //iHNMT [fWId]->Scale(1./lWSF); //No ss //iHSSMT[fWId]->Scale(1./lWSFSS); //TH1F *lSSMT = (TH1F*) iHSS[0]->Clone("SSTmpmT"); clear(lSSMT); //for(int i0 = 0; i0 < iN-1; i0++) {if(i0 == fQCDId) continue; lSSMT->Add(iHSSMT[i0]); } //iHSSMT[fQCDId]->Add(lSSMT,-1); clear(iHMT [fQCDId]); //clear(iHNMT[fQCDId]); //for(int i0 = 0; i0 < iHSSMT[fQCDId]->GetNbinsX()+1; i0++) if(iHSSMT[fQCDId]->GetBinContent(i0) < 0) iHSSMT[fQCDId]->SetBinContent(i0,0); //iHSSMT[fQCDId]->Scale(1.06); //iHNMT[fQCDId] = iHSSMT[fQCDId]; //Make DataCards ==> If Asked if(iFile !=0) makeDataCard(iFile,iH,iHHigh,iHLow,iN,iDirName,fString); //Blind //for(int i0 = 0; i0 < iH[iN-1]->GetNbinsX()+1; i0++) if(iH[iN-1]->GetXaxis()->GetBinCenter(i0) > 100 && iH[iN-1]->GetXaxis()->GetBinCenter(i0) < 150) iH[iN-1]->SetBinContent(i0,0); //Draw the plot draw(iH ,iN,iVar+"A"+iName,iVar); draw(iHSS ,iN,iVar+"B"+iName,iVar); draw(iHMT ,iN,iVar+"C"+iName,iVar); //draw(iHNMT,iN,iVar+"D"+iName,iVar); //draw(iHMTS,iN,iVar+"E"+iName,iVar); }
void HTT_EM_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., TString datacard="htt_em_0_7TeV", string inputfile="root/$HISTFILE", const char* directory="emu_$CATEGORY") { // define common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category = ""; const char* category_extra = ""; const char* category_extra2 = ""; if(std::string(directory) == std::string("emu_0jet_low" )){ category = "e#mu, 0 jet"; } if(std::string(directory) == std::string("emu_0jet_low" )){ category_extra = "p_{T}(lep1) low"; } if(std::string(directory) == std::string("emu_0jet_high" )){ category = "e#mu, 0 jet"; } if(std::string(directory) == std::string("emu_0jet_high" )){ category_extra = "p_{T}(lep1) high"; } if(std::string(directory) == std::string("emu_1jet_low" )){ category = "e#mu, 1 jet"; } if(std::string(directory) == std::string("emu_1jet_low" )){ category_extra = "p_{T}(lep1) low"; } if(std::string(directory) == std::string("emu_1jet_high" )){ category = "e#mu, 1 jet"; } if(std::string(directory) == std::string("emu_1jet_high" )){ category_extra = "p_{T}(lep1) high"; } if(std::string(directory) == std::string("emu_vbf_loose" )){ category = "e#mu, 2 jet"; } if(std::string(directory) == std::string("emu_vbf_loose" )){ category_extra = "VBF, loose"; } if(std::string(directory) == std::string("emu_vbf_tight" )){ category = "e#mu, 2 jet"; } if(std::string(directory) == std::string("emu_vbf_tight" )){ category_extra = "VBF, tight"; } if(std::string(directory) == std::string("emu_nobtag" )){ category = "e#mu"; } if(std::string(directory) == std::string("emu_nobtag" )){ category_extra = "No B-Tag"; } if(std::string(directory) == std::string("emu_btag" )){ category = "e#mu"; } if(std::string(directory) == std::string("emu_btag" )){ category_extra = "B-Tag"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 19.7 fb^{-1} at 8 TeV";} TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MA_$TANB").c_str()); #endif TH1F* Fakes = refill((TH1F*)input->Get(TString::Format("%s/Fakes" , directory)), "Fakes" ); InitHist(Fakes, "", "", kMagenta-10, 1001); TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/EWK" , directory)), "EWK" ); InitHist(EWK , "", "", kRed + 2, 1001); TH1F* ttbar = refill((TH1F*)input->Get(TString::Format("%s/ttbar" , directory)), "ttbar" ); InitHist(ttbar, "", "", kBlue - 8, 1001); TH1F* Ztt = refill((TH1F*)input->Get(TString::Format("%s/Ztt" , directory)), "Ztt" ); InitHist(Ztt , "", "", kOrange - 4, 1001); #ifdef MSSM TH1F* ggH = refill((TH1F*)input2->Get(TString::Format("%s/ggH$MA" , directory)), "ggH" ); InitSignal(ggH ); ggH ->Scale($TANB); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MA" , directory)), "bbH" ); InitSignal(bbH ); bbH ->Scale($TANB); #else #ifdef HWW_BG TH1F* ggH_hww= refill((TH1F*)input->Get(TString::Format("%s/ggH_hww125", directory)), "ggH_hww"); InitHist(ggH_hww , "", "", kGreen + 2, 1001); ggH_hww->Scale(SIGNAL_SCALE); TH1F* qqH_hww= refill((TH1F*)input->Get(TString::Format("%s/qqH_hww125", directory)), "qqH_hww"); InitHist(qqH_hww , "", "", kGreen + 2, 1001); qqH_hww->Scale(SIGNAL_SCALE); #else TH1F* ggH_hww= refill((TH1F*)input->Get(TString::Format("%s/ggH_hww125", directory)), "ggH_hww"); InitSignal(ggH_hww); ggH_hww->Scale(SIGNAL_SCALE); TH1F* qqH_hww= refill((TH1F*)input->Get(TString::Format("%s/qqH_hww125", directory)), "qqH_hww"); InitSignal(qqH_hww); qqH_hww->Scale(SIGNAL_SCALE); #endif #ifndef DROP_SIGNAL TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH125" , directory)), "ggH" ); InitSignal(ggH ); ggH ->Scale(SIGNAL_SCALE); TH1F* qqH = refill((TH1F*)input->Get(TString::Format("%s/qqH125" , directory)), "qqH" ); InitSignal(qqH ); qqH ->Scale(SIGNAL_SCALE); TH1F* VH = refill((TH1F*)input->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH ->Scale(SIGNAL_SCALE); #ifndef HWW_BG ggH->Add(ggH_hww); qqH->Add(qqH_hww); #endif #endif #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); #endif InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Fakes->Clone("ref"); ref->Add(EWK ); ref->Add(ttbar); ref->Add(Ztt ); #ifdef HWW_BG ref->Add(qqH_hww); ref->Add(ggH_hww); #endif #ifdef HWW_BG const int numhistos = 9; const int offset = 2; #else const int numhistos = 7; const int offset = 0; #endif double unscaled[numhistos]; unscaled[0] = Fakes->Integral(); unscaled[1] = EWK ->Integral(); unscaled[2] = ttbar->Integral(); unscaled[3] = Ztt ->Integral(); #ifdef MSSM unscaled[4] = ggH ->Integral(); unscaled[5] = bbH ->Integral(); unscaled[6] = 0; #else #ifdef HWW_BG unscaled[4] = ggH_hww ->Integral(); unscaled[5] = qqH_hww ->Integral(); #endif #ifndef DROP_SIGNAL unscaled[4+offset] = ggH ->Integral(); unscaled[5+offset] = qqH ->Integral(); unscaled[6+offset] = VH ->Integral(); #endif #endif if(scaled){ Fakes = refill(shape_histos(Fakes, datacard, "Fakes"), "Fakes"); EWK = refill(shape_histos(EWK, datacard, "EWK"), "EWK"); ttbar = refill(shape_histos(ttbar, datacard, "ttbar"), "ttbar"); Ztt = refill(shape_histos(Ztt, datacard, "Ztt"), "Ztt"); #ifdef MSSM ggH = refill(shape_histos(ggH, datacard, "ggH$MA"), "ggH$MA"); bbH = refill(shape_histos(bbH, datacard, "bbH$MA"), "bbH$MA"); #else #ifndef DROP_SIGNAL ggH = refill(shape_histos(ggH, datacard, "ggH"), "ggH"); qqH = refill(shape_histos(qqH, datacard, "qqH"), "qqH"); VH = refill(shape_histos(VH, datacard, "VH"), "VH"); #endif #endif #ifdef HWW_BG ggH_hww = refill(shape_histos(ggH_hww, datacard, "ggH_hww125"), "ggH_hww125"); qqH_hww = refill(shape_histos(qqH_hww, datacard, "qqH_hww125"), "qqH_hww125"); #endif rescale(Fakes, 4); rescale(EWK, 3); rescale(ttbar, 2); rescale(Ztt, 1); #ifdef MSSM rescale(ggH, 5); rescale(bbH, 6); #else #ifdef HWW_BG rescale(qqH_hww, 8); rescale(qqH_hww, 9); #endif #ifndef DROP_SIGNAL rescale(ggH, 5); rescale(qqH, 6); rescale(VH, 7); #endif #endif } TH1F* scales[numhistos]; scales[0] = new TH1F("scales-Fakes", "", numhistos, 0, numhistos); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-EWK" , "", numhistos, 0, numhistos); scales[1]->SetBinContent(2, unscaled[1]>0 ? (EWK ->Integral()/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-ttbar", "", numhistos, 0, numhistos); scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-Ztt" , "", numhistos, 0, numhistos); scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt ->Integral()/unscaled[3]-1.) : 0.); #ifdef MSSM scales[4] = new TH1F("scales-ggH" , "", numhistos, 0, numhistos); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-qqH" , "", numhistos, 0, numhistos); scales[5]->SetBinContent(6, unscaled[5]>0 ? (bbH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-NONE" , "", numhistos, 0, numhistos); scales[6]->SetBinContent(numhistos, 0.); #else #ifdef HWW_BG scales[4] = new TH1F("scales-ggH_hww" , "", numhistos, 0, numhistos); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH_hww ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-qqH_hww" , "", numhistos, 0, numhistos); scales[5]->SetBinContent(6, unscaled[5]>0 ? (qqH_hww ->Integral()/unscaled[5]-1.) : 0.); #endif #ifndef DROP_SIGNAL scales[4+offset] = new TH1F("scales-ggH" , "", numhistos, 0, numhistos); scales[4+offset]->SetBinContent(5+offset, unscaled[4+offset]>0 ? (ggH ->Integral()/unscaled[4+offset]-1.) : 0.); scales[5+offset] = new TH1F("scales-qqH" , "", numhistos, 0, numhistos); scales[5+offset]->SetBinContent(6+offset, unscaled[5+offset]>0 ? (qqH ->Integral()/unscaled[5+offset]-1.) : 0.); scales[6+offset] = new TH1F("scales-VH" , "", numhistos, 0, numhistos); scales[6+offset]->SetBinContent(7+offset, unscaled[6+offset]>0 ? (VH ->Integral()/unscaled[6+offset]-1.) : 0.); #endif #endif EWK ->Add(Fakes); ttbar->Add(EWK ); Ztt ->Add(ttbar); #ifdef HWW_BG qqH_hww->Add(Ztt); ggH_hww->Add(qqH_hww); #endif if(log){ #ifdef MSSM ggH ->Add(bbH); #else #ifndef DROP_SIGNAL qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } else{ #ifdef MSSM bbH ->Add(Ztt); ggH ->Add(bbH); #else #ifndef DROP_SIGNAL #ifdef HWW_BG VH ->Add(qqH_hww); #else VH ->Add(Ztt); #endif qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } /* mass plot before and after fit */ TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(345)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(UPPER_EDGE)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(345)); #endif data->SetNdivisions(505); data->SetMinimum(min); #ifndef DROP_SIGNAL data->SetMaximum(max>0 ? max : std::max(std::max(maximum(data, log), maximum(Ztt, log)), maximum(ggH, log))); #else data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log))); #endif data->Draw("e"); #ifdef HWW_BG TH1F* errorBand = (TH1F*)ggH_hww ->Clone("errorBand"); #else TH1F* errorBand = (TH1F*)Ztt ->Clone("errorBand"); #endif errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ #ifdef HWW_BG ggH_hww->Draw("histsame"); #endif Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif #ifdef HWW_BG ggH_hww->Draw("histsame"); #endif Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{e}#tau_{#mu}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.20, (category_extra2 && category_extra2[0]=='\0') ? 0.65+0.061 : 0.65+0.061, 0.32, 0.75+0.161, "tlbrNDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->AddText(category_extra); chan->AddText(category_extra2); chan->Draw(); /* TPaveText* cat = new TPaveText(0.20, 0.71+0.061, 0.32, 0.71+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); #ifdef MSSM TPaveText* massA = new TPaveText(0.53, 0.50+0.061, 0.95, 0.50+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m^{h}_{max} (m_{A}=$MA GeV, tan#beta=$TANB)"); massA->Draw(); #endif */ #ifdef MSSM TLegend* leg = new TLegend(0.53, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggH , "#phi#rightarrow#tau#tau" , "L" ); #else TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90); SetLegendStyle(leg); #ifndef DROP_SIGNAL if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ #ifdef HWW_BG leg->AddEntry(ggH , "H(125 GeV)#rightarrow#tau#tau" , "L" ); #else leg->AddEntry(ggH , "#splitline{H(125 GeV)#rightarrow#tau#tau}{H(125 GeV)#rightarrowWW}" , "L" ); leg->AddEntry((TObject*)0, "", ""); #endif } #endif #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + H(125)" , "LP"); #else leg->AddEntry(data , "observed" , "LP"); #endif #ifdef HWW_BG leg->AddEntry(ggH_hww , "H(125 GeV)#rightarrowWW" , "F" ); #endif leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(EWK , "electroweak" , "F" ); leg->AddEntry(Fakes, "Fakes" , "F" ); $ERROR_LEGEND leg->Draw(); /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); #ifdef HWW_BG TH1F* model = (TH1F*)ggH_hww ->Clone("model"); #else TH1F* model = (TH1F*)Ztt ->Clone("model"); #endif TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); model->SetBinError (ibin+1, CONVERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; double chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; double ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; double ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; std::vector<double> edges; TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/Ztt->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? Ztt ->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv0->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); stat1->Draw(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); edges.clear(); #ifdef HWW_BG TH1F* rat2 = (TH1F*) ggH_hww->Clone("rat2"); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ rat2->SetBinContent(ibin+1, ref->GetBinContent(ibin+1)>0 ? ggH_hww->GetBinContent(ibin+1)/ref->GetBinContent(ibin+1) : 0); rat2->SetBinError (ibin+1, ref->GetBinContent(ibin+1)>0 ? ggH_hww->GetBinError (ibin+1)/ref->GetBinContent(ibin+1) : 0); } #else TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ rat2->SetBinContent(ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinContent(ibin+1)/ref->GetBinContent(ibin+1) : 0); rat2->SetBinError (ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinError (ibin+1)/ref->GetBinContent(ibin+1) : 0); } #endif for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat2->GetBinContent(ibin+1)-1.)+TMath::Abs(rat2->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } #if defined MSSM if(!log){ rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); } else{ rat2->GetXaxis()->SetRange(0, rat2->FindBin(UPPER_EDGE)); }; #else rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); #endif rat2->SetNdivisions(505); rat2->SetLineColor(kRed+ 3); rat2->SetMarkerColor(kRed+3); rat2->SetMarkerSize(1.1); rat2->SetMaximum(+range); rat2->SetMinimum(-range); rat2->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat2->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->Draw("e2histsame"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", kMagenta-10, 1001); InitHist (scales[1], "", "", kRed + 2, 1001); InitHist (scales[2], "", "", kBlue - 8, 1001); InitHist (scales[3], "", "", kOrange - 4, 1001); #ifdef HWW_BG InitHist(scales[4], "", "", kGreen + 2, 1001); InitHist(scales[5], "", "", kGreen + 2, 1001); #endif #ifndef DROP_SIGNAL InitSignal(scales[4+offset]); InitSignal(scales[5+offset]); InitSignal(scales[6+offset]); #endif scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{NONE}" ); #else #ifdef HWW_BG scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH_hww}"); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH_hww}"); #endif scales[0]->GetXaxis()->SetBinLabel(5+offset, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6+offset, "#bf{qqH}" ); scales[0]->GetXaxis()->SetBinLabel(7+offset, "#bf{VH}" ); #endif scales[0]->SetMaximum(+0.5); scales[0]->SetMinimum(-0.5); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); #ifdef HWW_BG scales[4]->Draw("same"); scales[5]->Draw("same"); #endif #ifndef DROP_SIGNAL scales[4+offset]->Draw("same"); scales[5+offset]->Draw("same"); scales[6+offset]->Draw("same"); #endif TH1F* zero_samples = (TH1F*)scales[0]->Clone("zero_samples"); zero_samples->Clear(); zero_samples->SetBinContent(1,0.); zero_samples->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); if(!log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } if((!log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"), "update"); output->cd(); data ->Write("data_obs"); Fakes->Write("Fakes" ); EWK ->Write("EWK" ); ttbar->Write("ttbar" ); Ztt ->Write("Ztt" ); #ifdef MSSM ggH ->Write("ggH" ); bbH ->Write("bbH" ); #else #ifdef HWW_BG ggH_hww ->Write("ggH_hww" ); #endif #ifndef DROP_SIGNAL ggH ->Write("ggH" ); qqH ->Write("qqH" ); VH ->Write("VH" ); #endif #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); delete errorBand; delete model; delete test1; delete zero; delete rat1; delete rat2; delete zero_samples; delete ref; }
void met_cuts(double pt1min, double pt2min, double METmin, int jets, int DataFlag){ TLegend* leg = new TLegend(0.5,0.72,0.89,0.89); leg->SetNColumns(2); TCanvas *canvas = new TCanvas("c1n","",500,500); gPad->SetLogy(); TCut mggmax = "mgg<200"; TCut mggmin = "mgg>100"; TCut pt1Cut = Form("pt1>%lf",pt1min); TCut pt2Cut = Form("pt2>%lf",pt2min); TCut METCut = Form("t1pfmet>%lf",METmin); TCut eveto1 = "eleveto1 == 1"; TCut eveto2 = "eleveto2 == 1"; TCut eveto = eveto1 && eveto2; TCut genmatch = "((genmatch1==1 && genmatch2==0)||(genmatch1==0 && genmatch2==1)||(genmatch1==0 && genmatch2==0))"; TCut metF = "((metF_GV==1) && (metF_HBHENoise==1) && (metF_HBHENoiseIso==1) && (metF_CSC==1) && (metF_eeBadSC==1))"; TCut Cut_Jets = Form("nJets<%d",jets); /* TFile *M1 = TFile::Open("./50ns_betaV4/NewWeightDMHtoGG_M1.root","READ"); TFile *M10 = TFile::Open("./50ns_betaV4/NewWeightDMHtoGG_M10.root","READ"); TFile *M100 = TFile::Open("./50ns_betaV4/NewWeightDMHtoGG_M100.root","READ"); TFile *M1000 = TFile::Open("./50ns_betaV4/NewWeightDMHtoGG_M1000.root","READ"); */ TFile *data = TFile::Open("./25ns_2246inv/DoubleEG.root","READ"); TFile *sig1 = TFile::Open("./25ns_2246inv/2HDM_mZP600.root","READ"); TFile *sig2 = TFile::Open("./25ns_2246inv/2HDM_mZP800.root","READ"); TFile *sig3 = TFile::Open("./25ns_2246inv/2HDM_mZP1000.root","READ"); TFile *sig4 = TFile::Open("./25ns_2246inv/2HDM_mZP1200.root","READ"); TFile *sig5 = TFile::Open("./25ns_2246inv/2HDM_mZP1400.root","READ"); /* TFile *bkg1 = TFile::Open("./50ns_betaV4/DiPhoton.root","READ"); TFile *bkg2 = TFile::Open("./50ns_betaV4/DYJetsToLL.root","READ"); TFile *bkg3 = TFile::Open("./50ns_betaV4/GJets.root","READ"); TFile *bkg4 = TFile::Open("./50ns_betaV4/GluGluHToGG.root","READ"); TFile *bkg5 = TFile::Open("./50ns_betaV4/QCD.root","READ"); TFile *bkg6 = TFile::Open("./50ns_betaV4/VH.root","READ"); */ TFile *bkg1 = TFile::Open("./25ns_2246inv/DiPhoton.root","READ"); TFile *bkg2 = TFile::Open("./25ns_2246inv/DYJetsToLL.root","READ"); TFile *bkg3 = TFile::Open("./25ns_2246inv/GJets.root","READ"); TFile *bkg4 = TFile::Open("./25ns_2246inv/GluGluHToGG.root","READ"); TFile *bkg5 = TFile::Open("./25ns_2246inv/QCD.root","READ"); TFile *bkg6 = TFile::Open("./25ns_2246inv/VH.root","READ"); /* TTree *tree_M1 = (TTree*) M1->Get("DiPhotonTree"); TTree *tree_M10 = (TTree*) M10->Get("DiPhotonTree"); TTree *tree_M100 = (TTree*) M100->Get("DiPhotonTree"); TTree *tree_M1000 = (TTree*) M1000->Get("DiPhotonTree"); */ TTree *tree_data = (TTree*) data->Get("DiPhotonTree"); TTree *tree_sig1 = (TTree*) sig1->Get("DiPhotonTree"); TTree *tree_sig2 = (TTree*) sig2->Get("DiPhotonTree"); TTree *tree_sig3 = (TTree*) sig3->Get("DiPhotonTree"); TTree *tree_sig4 = (TTree*) sig4->Get("DiPhotonTree"); TTree *tree_sig5 = (TTree*) sig5->Get("DiPhotonTree"); TTree *tree_bkg1 = (TTree*) bkg1->Get("DiPhotonTree"); TTree *tree_bkg2 = (TTree*) bkg2->Get("DiPhotonTree"); TTree *tree_bkg3 = (TTree*) bkg3->Get("DiPhotonTree"); TTree *tree_bkg4 = (TTree*) bkg4->Get("DiPhotonTree"); TTree *tree_bkg5 = (TTree*) bkg5->Get("DiPhotonTree"); TTree *tree_bkg6 = (TTree*) bkg6->Get("DiPhotonTree"); /* tree_M1->Draw("(t1pfmet)>>h1(30,100,200)","weight*10"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *h1 =(TH1F*)gPad->GetPrimitive("h1"); tree_M10->Draw("(t1pfmet)>>h2(30,100,200)","weight*10"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *h2 =(TH1F*)gPad->GetPrimitive("h2"); tree_M100->Draw("(t1pfmet)>>h3(30,100,200)","weight*10"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *h3 =(TH1F*)gPad->GetPrimitive("h3"); tree_M1000->Draw("(t1pfmet)>>h4(30,100,200)","weight*10"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *h4 =(TH1F*)gPad->GetPrimitive("h4"); */ tree_data->Draw("(t1pfmet)>>hdata(60,0,900)",(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets && metF)); TH1F *hdata =(TH1F*)gPad->GetPrimitive("hdata"); tree_sig1->Draw("(t1pfmet)>>h1(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *h1 =(TH1F*)gPad->GetPrimitive("h1"); tree_sig2->Draw("(t1pfmet)>>h2(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *h2 =(TH1F*)gPad->GetPrimitive("h2"); tree_sig3->Draw("(t1pfmet)>>h3(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *h3 =(TH1F*)gPad->GetPrimitive("h3"); tree_sig4->Draw("(t1pfmet)>>h4(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *h4 =(TH1F*)gPad->GetPrimitive("h4"); tree_sig5->Draw("(t1pfmet)>>h5(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *h5 =(TH1F*)gPad->GetPrimitive("h5"); h1->Scale(0.00009338); h2->Scale(0.00010348); h3->Scale(0.00008394); h4->Scale(0.00006352); h5->Scale(0.00004712); tree_bkg1->Draw("(t1pfmet)>>hbkg1(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *hbkg1 =(TH1F*)gPad->GetPrimitive("hbkg1"); tree_bkg2->Draw("(t1pfmet)>>hbkg2(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); TH1F *hbkg2 =(TH1F*)gPad->GetPrimitive("hbkg2"); tree_bkg3->Draw("(t1pfmet)>>hbkg3(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets && genmatch)); TH1F *hbkg3 =(TH1F*)gPad->GetPrimitive("hbkg3"); tree_bkg4->Draw("(t1pfmet)>>hbkg4(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); //weight also on BR = 0.002 if using 50ns samples TH1F *hbkg4 =(TH1F*)gPad->GetPrimitive("hbkg4"); tree_bkg5->Draw("(t1pfmet)>>hbkg5(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets && genmatch)); TH1F *hbkg5 =(TH1F*)gPad->GetPrimitive("hbkg5"); tree_bkg6->Draw("(t1pfmet)>>hbkg6(60,0,900)","weight"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets)); //weight also on BR = 0.002 if using 50ns samples TH1F *hbkg6 =(TH1F*)gPad->GetPrimitive("hbkg6"); double DeltaN = 0; double DeltaS1 = 0; double DeltaS2 = 0; double DeltaS3 = 0; double DeltaS4 = 0; double DeltaS5 = 0; double DeltaF1 = 0; double DeltaF2 = 0; double DeltaF3 = 0; double DeltaF4 = 0; double DeltaF5 = 0; double DeltaF6 = 0; double DeltaNi = 0; double DeltaS1i= 0; double DeltaS2i= 0; double DeltaS3i= 0; double DeltaS4i= 0; double DeltaS5i= 0; double DeltaF1i= 0; double DeltaF2i= 0; double DeltaF3i = 0; double DeltaF4i = 0; double DeltaF5i = 0; double DeltaF6i = 0; for(i=0; i<60; i++){ DeltaNi=hdata->GetBinError(i); DeltaS1i=h1->GetBinError(i); DeltaS2i=h2->GetBinError(i); DeltaS3i=h3->GetBinError(i); DeltaS4i=h4->GetBinError(i); DeltaS5i=h5->GetBinError(i); DeltaF1i=hbkg1->GetBinError(i); DeltaF2i= hbkg2->GetBinError(i); DeltaF3i= hbkg3->GetBinError(i); DeltaF4i= hbkg4->GetBinError(i); DeltaF5i= hbkg5->GetBinError(i); DeltaF6i= hbkg6->GetBinError(i); DeltaN += pow(DeltaNi,2); DeltaS1 += pow(DeltaS1i,2); DeltaS2 += pow(DeltaS2i,2); DeltaS3 += pow(DeltaS3i,2); DeltaS4 += pow(DeltaS4i,2); DeltaS5 += pow(DeltaS5i,2); DeltaF1 += pow(DeltaF1i,2); DeltaF2 += pow(DeltaF2i,2); DeltaF3 += pow(DeltaF3i,2); DeltaF4 += pow(DeltaF4i,2); DeltaF5 += pow(DeltaF5i,2); DeltaF6 += pow(DeltaF6i,2); } DeltaN = sqrt(DeltaN); DeltaS1 = sqrt(DeltaS1); DeltaS2 = sqrt(DeltaS2); DeltaS3 = sqrt(DeltaS3); DeltaS4 = sqrt(DeltaS4); DeltaS5 = sqrt(DeltaS5); DeltaF1 = sqrt(DeltaF1); DeltaF2 = sqrt(DeltaF2); DeltaF3 = sqrt(DeltaF3); DeltaF4 = sqrt(DeltaF4); DeltaF5 = sqrt(DeltaF5); DeltaF6 = sqrt(DeltaF6); double Ndata= hdata->Integral(); cout<<"Ndata= "<<Ndata<<" +/- "<<DeltaN<<endl; double S1= h1->Integral(); double S2= h2->Integral(); double S3= h3->Integral(); double S4= h4->Integral(); double S5= h5->Integral(); cout<<"S1= "<<S1<<" +/- "<<DeltaS1<<endl; cout<<"S2= "<<S2<<" +/- "<<DeltaS2<<endl; cout<<"S3= "<<S3<<" +/- "<<DeltaS3<<endl; cout<<"S4= "<<S4<<" +/- "<<DeltaS4<<endl; cout<<"S5= "<<S5<<" +/- "<<DeltaS5<<endl; double DiPho = hbkg1->Integral(); cout<<"diphoton = "<<DiPho<<" +/- "<<DeltaF1<<endl; double DY = hbkg2->Integral(); cout<<"DY = "<<DY<<" +/- "<<DeltaF2<<endl; double GJ = hbkg3->Integral(); cout<<"GJ = "<<GJ<<" +/- "<<DeltaF3<<endl; double GluGlu = hbkg4->Integral(); cout<<"GluGlu = "<<GluGlu<<" +/- "<<DeltaF4<<endl; double QCD = hbkg5->Integral(); cout<<"QCD = "<<QCD<<" +/- "<<DeltaF5<<endl; double VHiggs = hbkg6->Integral(); cout<<"VH = "<<VHiggs<<" +/- "<<DeltaF6<<endl; h1->SetLineColor(kRed-4); h2->SetLineColor(kRed+2); h3->SetLineColor(kPink+2); h4->SetLineColor(kPink+4); h5->SetLineColor(kMagenta+2); //only for 25ns samples h1->SetLineWidth(2); h2->SetLineWidth(2); h3->SetLineWidth(2); h4->SetLineWidth(2); h5->SetLineWidth(2); //only for 25ns samples THStack *hs=new THStack("hs",""); hbkg6->SetFillColor(kGreen+3); hbkg4->SetFillColor(kGreen+4); hbkg1->SetFillColor(kBlue); hbkg2->SetFillColor(kBlue+2); hbkg3->SetFillColor(kMagenta+4); hbkg5->SetFillColor(kMagenta+2); hbkg1->SetLineColor(kBlack); hbkg2->SetLineColor(kBlack); hbkg3->SetLineColor(kBlack); hbkg4->SetLineColor(kBlack); hbkg5->SetLineColor(kBlack); hbkg6->SetLineColor(kBlack); hs->Add(hbkg6); hs->Add(hbkg4); hs->Add(hbkg1); hs->Add(hbkg2); hs->Add(hbkg3); hs->Add(hbkg5); TH1F *hsum = (TH1F*)hbkg1->Clone("hsum"); hsum->Add(hbkg2); hsum->Add(hbkg3); hsum->Add(hbkg4); hsum->Add(hbkg5); hsum->Add(hbkg6); hs->SetMinimum(0.001); hs->SetMaximum(5000); hs->SetTitle(""); hs->Draw("HIST"); hsum->SetMarkerStyle(1); hsum->SetFillColor(kGray+3); hsum->SetFillStyle(3001); hsum->Draw("same e2"); h2->Draw("same hist"); h3->Draw("same hist"); h4->Draw("same hist"); h1->Draw("same hist"); h5->Draw("same hist"); //only for 25ns samples if(DataFlag==1){ hdata->Draw("same E1"); } hs->GetXaxis()->SetTitle("MET [GeV]"); hs->GetYaxis()->SetTitleOffset(1.2); hs->GetYaxis()->SetTitle("Events/15 GeV"); gPad->Modified(); /*leg->AddEntry(h1,"m_{#chi} = 1 GeV","l"); leg->AddEntry(h2,"m_{#chi} = 10 GeV","l"); leg->AddEntry(h3,"m_{#chi} = 100 GeV","l"); leg->AddEntry(h4,"m_{#chi} = 1000 GeV","l");*/ leg->AddEntry(h1,"m_{Z'} = 600 GeV","l"); leg->AddEntry(hbkg1,"#gamma #gamma","f"); leg->AddEntry(h2,"m_{Z'} = 800 GeV","l"); leg->AddEntry(hbkg2,"Drell Yann","f"); leg->AddEntry(h3,"m_{Z'} = 1000 GeV","l"); leg->AddEntry(hbkg3,"#gamma + Jets","f"); leg->AddEntry(h4,"m_{Z'} = 1200 GeV","l"); leg->AddEntry(hbkg4,"ggH","f"); leg->AddEntry(h5,"m_{Z'} = 1400 GeV","l"); //only for 25ns samples leg->AddEntry(hbkg5,"QCD","f"); leg->AddEntry(hbkg6,"VH","f"); leg->Draw("same"); gStyle->SetOptStat(0); /* if(jets<3){ canvas->SaveAs(Form("met_cuts_M%d_%djets.pdf",sigMass,(jets-1))); canvas->SaveAs(Form("met_cuts_M%d_%djets.png",sigMass,(jets-1))); }else{ canvas->SaveAs(Form("met_cuts_M%d_noJetsCut.pdf",sigMass)); canvas->SaveAs(Form("met_cuts_M%d_noJetsCut.png",sigMass)); }*/ }
//------------------------------------------------------------------------------ //Subtraction //------------------------------------------------------------------------------ void Subtraction(TString hname, TString xtitle, Int_t ngroup = -1, Int_t precision = 1, TString units = "NULL", Double_t xmin = -999, Double_t xmax = 999, Bool_t moveOverflow = true) { TCanvas* canvas = new TCanvas(hname, hname, 800, 800); TPad* pad1 = new TPad("pad1", "pad1", 0, 0.0, 1, 1.0); pad1->SetTopMargin (0.08); //pad1->SetBottomMargin(0.02); pad1->Draw(); //---------------------------------------------------------------------------- // pad1 //---------------------------------------------------------------------------- pad1->cd(); pad1->SetLogy(_setLogy); TH1F* hist[nProcesses]; for (UInt_t ip=0; ip<nProcesses; ip++) { hist[ip] = (TH1F*)input[ip]->Get(hname); hist[ip]->SetName(hname + process[ip]); if (moveOverflow) MoveOverflowBins (hist[ip], xmin, xmax); else ZeroOutOfRangeBins(hist[ip], xmin, xmax); if (ngroup > 0) hist[ip]->Rebin(ngroup); if (_dataDriven && ip == iWW) hist[ip]->Scale(WWScale[_njet]); if (_dataDriven && ip == iDY) hist[ip]->Scale(ZjScale[_njet]); if (_dataDriven && ip == iDYtau) hist[ip]->Scale(ZjScale[_njet]); } // Data subtraction for Top background estimation //---------------------------------------------------------------------------- TH1F* subData = (TH1F*)hist[iData]->Clone("subData"); for (UInt_t ip=0; ip<nProcesses; ip++) { if (ip == itt) continue; if (ip == itW) continue; if (ip == iData ) continue; subData->Add(hist[ip],-1); } subData->SetLineColor(kRed+1); Double_t subData_Yield = subData->Integral(); //subData->SetLineColor(); // Top background //---------------------------------------------------------------------------- TH1F* Top = (TH1F*)hist[itt]->Clone("Top"); Top->Add(hist[itW]); Top->SetLineColor(kBlue+1); Double_t Top_Yield = Top->Integral(); // Axis labels //---------------------------------------------------------------------------- TAxis* xaxis = subData->GetXaxis(); TAxis* yaxis = subData->GetYaxis(); TString ytitle = Form("entries / %s.%df", "%", precision); xaxis->SetTitle(xtitle); yaxis->SetTitle(Form(ytitle.Data(), subData->GetBinWidth(0))); yaxis->SetTitleOffset(1.6); if (!units.Contains("NULL")) { xaxis->SetTitle(Form("%s [%s]", xaxis->GetTitle(), units.Data())); yaxis->SetTitle(Form("%s %s", yaxis->GetTitle(), units.Data())); } // Draw //---------------------------------------------------------------------------- xaxis->SetRangeUser(xmin, xmax); subData->Draw("hist"); Top->Draw("hist same"); // Adjust scale //---------------------------------------------------------------------------- subData->SetMinimum(0.0); Float_t theMax = GetMaximumIncludingErrors(subData, xmin, xmax); Float_t theMaxMC = GetMaximumIncludingErrors(Top, xmin, xmax); if (theMaxMC > theMax) theMax = theMaxMC; if (pad1->GetLogy()) { theMax = TMath::Power(10, TMath::Log10(theMax) + 2.7); subData->SetMinimum(0.05); } else theMax *= 1.55; subData->SetMaximum(theMax); // Legend //---------------------------------------------------------------------------- Double_t x0 = 0.720; Double_t y0 = 0.834; Double_t yoffset = 0.048; Double_t delta = yoffset + 0.001; Double_t ndelta = 0; DrawLegend(x0 - 0.49, y0 - ndelta, subData, Form(" Data Subtraction (MC without Top) (%.0f)", Yield(subData)), "l", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, Top, Form(" Top (%.0f)", Yield(Top)), "l", 0.03, 0.2, yoffset); ndelta += delta; // Additional titles //---------------------------------------------------------------------------- //TString channelLabel = "ee/#mu#mu/e#mu/#mue"; TString channelLabel = ""; //if (_channel == "EE") channelLabel = "ee"; //if (_channel == "MuMu") channelLabel = "#mu#mu"; //if (_channel == "EMu") channelLabel = "e#mu"; //if (_channel == "MuE") channelLabel = "#mue"; //if (_channel == "SF") channelLabel = "ee/#mu#mu"; //if (_channel == "OF") channelLabel = "e#mu/#mue"; channelLabel += Form(" %d", _njet); if (_njet == 0) channelLabel += "-jets"; if (_njet == 1) channelLabel += "-jet"; if (_njet >= 2) channelLabel += "-jets"; DrawTLatex(0.185, 0.975, 0.05, 13, channelLabel.Data()); DrawTLatex(0.940, 0.983, 0.05, 33, Form("L = %.1f fb^{-1}", _luminosity/1e3)); if (Top_Yield!=0){ cout << "subData_Yield = "<<subData_Yield<<", Top_Yield = "<<Top_Yield<<", Ratio = "<< subData_Yield/Top_Yield <<endl; TLatex *tex3 = new TLatex(0.250, 0.75, "Scale Factor"); tex3->SetNDC(); tex3->SetTextSize(0.035); tex3->Draw(); TLatex *tex4 = new TLatex(0.250, 0.7, Form("%.0f / %.0f = %3.3f",subData_Yield ,Top_Yield ,subData_Yield/Top_Yield)); tex4->SetNDC(); tex4->SetTextSize(0.035); tex4->Draw(); } // Save //---------------------------------------------------------------------------- pad1->cd(); //SetAxis(subData, "", subData->GetYaxis()->GetTitle(), 0.05, 1.6); canvas->cd(); TString suffixLogy = (_setLogy) ? "_Log" : "_Lin"; canvas->SaveAs(Form("%s/%s%s_sub.%s", _output.Data(), hname.Data(), suffixLogy.Data(), _format.Data())); }
void printYields( vector<TChain*> chmc , vector<char*> labels , TChain* chdata , TCut sel , TCut weight , bool latex ){ initSymbols( latex ); TCanvas *ctemp = new TCanvas(); printLine(latex); printHeader(); printLine(latex); TH1F* hyield = new TH1F("hyield","yield",4,0,4); TH1F* hmctot = new TH1F("hmctot","hmctot",4,0,4); hyield->Sumw2(); hmctot->Sumw2(); //---------------------- // print SM MC samples //---------------------- for(unsigned int imc = 0 ; imc < chmc.size() ; imc++){ bool correlatedError = false; if( TString(labels[imc]).Contains("T2") ) continue; // data-driven DY estimate if( strcmp(labels[imc],"DYdata") == 0 ){ //hyield = doDYestimate( chmc[imc] , sel ); doDYestimate( chmc[imc] , sel , hyield ); } // fake estimate else if( strcmp(labels[imc],"single fakes") == 0 || strcmp(labels[imc],"double fakes") == 0){ //correlatedError = true; TString weightstring(weight.GetTitle()); weightstring.ReplaceAll("ndavtxweight","1"); TCut newweight = TCut(weightstring); chmc[imc]->Draw("leptype>>hyield",sel*newweight); // SF --> SF - 2 X DF if( strcmp(labels[imc],"single fakes") == 0 ){ TH1F *hyielddf = new TH1F("hyielddf","hyielddf",4,0,4); chmc[imc+1]->Draw("leptype>>hyielddf",sel*newweight); hyield->Add(hyielddf,-2); } hyield->SetBinError(1,0.5*hyield->GetBinContent(1)); hyield->SetBinError(2,0.5*hyield->GetBinContent(2)); } //vanilla MC else{ chmc[imc]->Draw("leptype>>hyield",sel*weight); //do efficiency correction //hyield->SetBinContent ( 2 , hyield->GetBinContent(2) * 0.90); //hyield->SetBinContent ( 3 , hyield->GetBinContent(3) * 0.95); //hyield->SetBinError ( 2 , hyield->GetBinError(2) * 0.90); //hyield->SetBinError ( 3 , hyield->GetBinError(3) * 0.95); } if( imc == 0 ) hmctot = (TH1F*) hyield->Clone(); else hmctot->Add(hyield); print( hyield , labels[imc] , correlatedError ); //hyield->Reset(); } printLine(latex); //------------------------------- // print sum of SM MC samples //------------------------------- print( hmctot , "total SM MC" ); printLine(latex); chdata->Draw("leptype>>hyield",sel); print( hyield , "data" ); printLine(latex); //---------------------- // print T2tt MC samples //---------------------- for(unsigned int imc = 0 ; imc < chmc.size() ; imc++){ if( !TString(labels[imc]).Contains("T2") ) continue; chmc[imc]->Draw("leptype>>hyield",sel*weight); if( TString(labels[imc]).Contains("X5") ) hyield->Scale(5); if( TString(labels[imc]).Contains("X6") ) hyield->Scale(6); if( TString(labels[imc]).Contains("X10") ) hyield->Scale(10); //do efficiency correction //hyield->SetBinContent ( 2 , hyield->GetBinContent(2) * 0.90); //hyield->SetBinContent ( 3 , hyield->GetBinContent(3) * 0.95); //hyield->SetBinError ( 2 , hyield->GetBinError(2) * 0.90); //hyield->SetBinError ( 3 , hyield->GetBinError(3) * 0.95); print( hyield , labels[imc] ); } printLine(latex); delete ctemp; }
void makePlot( vector<TChain*> samples , vector<string> names , char* var , char* xtitle , TCut sel , TCut weight , int nbin , float xmin , float xmax , bool printplot = false , bool logplot = true , bool stacksig = false) { const unsigned int n = samples.size(); TH1F* h[n]; TCanvas* can = new TCanvas(Form("%s_can",var),Form("%s_can",var),800,600); can->cd(); int colors[] = {kBlue-10,kGreen+2,kRed+3}; int linecolors[] = {1,2,4}; THStack* t = new THStack(Form("%s_stack",var),Form("%s_stack",var)); TH1F* bkgtot = new TH1F(); int nbkg = 0; float ymax = 0; //TLegend* leg = new TLegend(0.5,0.75,0.85,0.9); TLegend* leg = new TLegend(0.5,0.45,0.85,0.6); leg->SetFillColor(0); leg->SetBorderSize(0); //TCut nj2("njets==2"); //TCut nj2(""); char* legentry = ""; for( unsigned int i = 0 ; i < n ; i++ ){ if( TString(names.at(i)).Contains("sig") ) continue; h[i] = new TH1F(Form("hist_%s_%s",names.at(i).c_str(),var),"",nbin,xmin,xmax); //h[i]->Sumw2(); //samples.at(i)->Draw(Form("min(%s,%f)>>hist_%s_%s",var,xmax-0.0001,names.at(i).c_str(),var),(sel+nj2)*weight); samples.at(i)->Draw(Form("min(%s,%f)>>hist_%s_%s",var,xmax-0.0001,names.at(i).c_str(),var),(sel)*weight); h[i]->SetFillColor(colors[i]); cout << "Intregal " << names.at(i) << " " << h[i]->Integral() << endl; //cout << "Bin3 " << names.at(i) << " " << h[i]->GetBinContent(3) << " +/- " << h[i]->GetBinError(3) << endl; t->Add(h[i]); nbkg++; ymax += h[i]->GetMaximum(); if( TString(names.at(i)).Contains("ttbar") ) legentry = "t#bar{t}"; if( TString(names.at(i)).Contains("Vjets") ) legentry = "V+jets"; leg->AddEntry(h[i],legentry,"f"); if( i==0 ) bkgtot = (TH1F*) h[i]->Clone("bkgtot"); else bkgtot->Add(h[i]); } for( unsigned int i = 0 ; i < n ; i++ ){ if( !TString(names.at(i)).Contains("sig") ) continue; h[i] = new TH1F(Form("hist_%s_%s",names.at(i).c_str(),var),"",nbin,xmin,xmax); //h[i]->Sumw2(); samples.at(i)->Draw(Form("min(%s,%f)>>hist_%s_%s",var,xmax-0.0001,names.at(i).c_str(),var),sel*weight); cout << "Intregal " << names.at(i) << " " << h[i]->Integral() << endl; //cout << "Bin3 " << names.at(i) << " " << h[i]->GetBinContent(3) << " +/- " << h[i]->GetBinError(3) << endl; if( TString(names.at(i)).Contains("WH500GeV_sig") ) legentry = "WH signal (500,100)"; if( TString(names.at(i)).Contains("WH1TeV_sig") ) legentry = "WH signal (1000,100)"; if( TString(names.at(i)).Contains("WH2TeV_sig") ) legentry = "WH signal (2000,100)"; if( TString(names.at(i)).Contains("WH3TeV_sig") ) legentry = "WH signal (3000,100)"; leg->AddEntry(h[i],legentry,"l"); if( stacksig ) h[i]->Add(bkgtot); } if( logplot ) ymax*=10; else ymax*=1.1; TH2F* hdummy = new TH2F("hdummy","",nbin,xmin,xmax,100,1,ymax); if( logplot ) gPad->SetLogy(); hdummy->GetXaxis()->SetTitle(xtitle); hdummy->Draw(); t->Draw("same"); for( unsigned int isig = nbkg ; isig < n ; isig++ ){ //h[isig]->Scale(10); h[isig]->SetLineColor(linecolors[isig-nbkg]); h[isig]->SetLineWidth(2); h[isig]->Draw("samehist"); } //leg->Draw(); hdummy->Draw("axissame"); if( printplot ) can->Print(Form("plots/%s.pdf",var)); }
void compareDataMC( vector<TChain*> chmc , vector<char*> labels , TChain* chdata , char* var , TCut sel , TCut weight , int nbins , float xmin , float xmax , char* xtitle , bool overlayData , bool residual , bool drawLegend , bool log , char* flavor ){ TPad* fullpad = new TPad(); TPad* plotpad = new TPad(); TPad* respad = new TPad(); if( residual ){ fullpad = new TPad("fullpad","fullpad",0,0,1,1); fullpad->Draw(); fullpad->cd(); plotpad = new TPad("plotpad","plotpad",0,0,1,0.8); plotpad->Draw(); plotpad->cd(); if( log ) plotpad->SetLogy(); } else{ if( log ) gPad->SetLogy(); } TString tvar(var); tvar.ReplaceAll("()",""); tvar.ReplaceAll(".",""); const char* myvar = tvar; cout << "Plotting var " << myvar << " flavor " << flavor << endl; int colors[]={6,2,7,4,5,8,9,15,12}; int sigcolors[]={4,1,7,4,5,8,9,15,12}; int isigmc = 0; assert( chmc.size() == labels.size() ); const unsigned int nmc = chmc.size(); THStack* mcstack = new THStack("mcstack","mcstack"); TH1F* mctothist = new TH1F(); TH1F* smtothist = new TH1F(); TH1F* mchist[nmc]; TH1F* datahist = new TH1F(Form("%s_datahist_%s",myvar,flavor),Form("%s_datahist_%s",myvar,flavor),nbins,xmin,xmax); vector<TH1F*> sighist; float trigeff = 1.0; //if ( TString(flavor).Contains("ee") ) trigeff = 1.00; //else if( TString(flavor).Contains("mm") ) trigeff = 0.90; //else if( TString(flavor).Contains("em") ) trigeff = 0.95; //else if( TString(flavor).Contains("all") ) trigeff = 0.95; TCut trigweight(Form("%.2f",trigeff)); for( unsigned int imc = 0 ; imc < nmc ; imc++ ){ //for( int imc = nmc-1 ; imc > -1 ; imc-- ){ bool isSignal = TString( labels.at(imc) ).Contains("T2"); mchist[imc] = new TH1F(Form("%s_mc_%i_%s",myvar,imc,flavor),Form("%s_mc_%i_%s",myvar,imc,flavor),nbins,xmin,xmax); mchist[imc]->Sumw2(); chmc.at(imc)->Draw(Form("TMath::Min(%s,%f)>>%s_mc_%i_%s",var,xmax-0.01,myvar,imc,flavor),sel*weight*trigweight); if( isSignal ){ mchist[imc]->SetFillColor( 0 ); //mchist[imc]->SetLineStyle(2); mchist[imc]->SetLineWidth(2); mchist[imc]->SetLineColor( sigcolors[isigmc++] ); if( TString( labels.at(imc) ).Contains("X5") ){ mchist[imc]->Scale(5); cout << "Scaling signal MC by 5" << endl; } if( TString( labels.at(imc) ).Contains("X6") ){ mchist[imc]->Scale(6); cout << "Scaling signal MC by 6" << endl; } if( TString( labels.at(imc) ).Contains("X10") ){ mchist[imc]->Scale(10); cout << "Scaling signal MC by 10" << endl; } }else{ mchist[imc]->SetLineWidth(1); mchist[imc]->SetFillColor( colors[imc] ); mchist[imc]->SetLineColor( 1 ); } //mcstack->Add( mchist[imc] ); if( !isSignal ){ mcstack->Add( mchist[imc] ); if( imc == 0 ){ mctothist = (TH1F*) mchist[imc]->Clone(); smtothist = (TH1F*) mchist[imc]->Clone(); } else{ mctothist->Add(mchist[imc]); smtothist->Add(mchist[imc]); } } else{ mctothist->Add(mchist[imc]); sighist.push_back( mchist[imc] ); } cout << "MC yield " << labels[imc] << " " << Form("%.2f",mchist[imc]->Integral()) << endl; } chdata->Draw(Form("TMath::Min(%s,%f)>>%s_datahist_%s",var,xmax-0.01,myvar,flavor),sel); if( overlayData ){ float max = datahist->GetMaximum() + datahist->GetBinError(datahist->GetMaximumBin()); if( mctothist->GetMaximum() > max ) max = mctothist->GetMaximum(); if( log ) datahist->SetMaximum( 15 * max ); else datahist->SetMaximum( 1.4 * max ); datahist->GetXaxis()->SetTitle(xtitle); datahist->Draw("E1"); mcstack->Draw("samehist"); for( unsigned int isig = 0 ; isig < sighist.size() ; isig++ ){ sighist.at(isig)->Add(smtothist); sighist.at(isig)->Draw("samehist"); } datahist->Draw("sameE1"); datahist->Draw("sameaxis"); if(!log) datahist->GetYaxis()->SetRangeUser(0.,1.4*max); } else{ float max = mctothist->GetMaximum(); if( log ) mctothist->SetMaximum( 15 * max ); else mctothist->SetMaximum( 1.4 * max ); mctothist->SetLineColor(0); mctothist->SetFillColor(0); mctothist->GetXaxis()->SetTitle(xtitle); mctothist->Draw("hist"); mcstack->Draw("samehist"); for( unsigned int isig = 0 ; isig < sighist.size() ; isig++ ){ sighist.at(isig)->Add(smtothist); sighist.at(isig)->Draw("samehist"); } mctothist->Draw("sameaxis"); } if( drawLegend ){ TLegend* myleg = getLegend( chmc , labels , overlayData ); myleg->Draw(); } TLatex *text = new TLatex(); text->SetNDC(); text->SetTextSize(0.04); text->DrawLatex(0.2,0.88,"CMS Preliminary"); //text->DrawLatex(0.2,0.83,"0.98 fb^{-1} at #sqrt{s} = 7 TeV"); text->DrawLatex(0.2,0.83,"#sqrt{s} = 7 TeV, #scale[0.6]{#int}Ldt = 1.0 fb^{-1}"); if ( TString(flavor).Contains("e") ) text->DrawLatex(0.2,0.78,"e-channel"); else if( TString(flavor).Contains("m") ) text->DrawLatex(0.2,0.78,"#mu-channel"); else if( TString(flavor).Contains("all") ) text->DrawLatex(0.2,0.78,"e/#mu-channel"); if( residual ){ fullpad->cd(); respad = new TPad("respad","respad",0,0.8,1,1); respad->Draw(); respad->cd(); //gPad->SetGridy(); TH1F* ratio = (TH1F*) datahist->Clone(Form("%s_ratio",datahist->GetName())); ratio->Divide(smtothist); ratio->GetYaxis()->SetTitleOffset(0.3); ratio->GetYaxis()->SetTitleSize(0.2); ratio->GetYaxis()->SetNdivisions(5); ratio->GetYaxis()->SetLabelSize(0.2); ratio->GetYaxis()->SetRangeUser(0.5,1.5); ratio->GetYaxis()->SetTitle("data/SM "); ratio->GetXaxis()->SetLabelSize(0); ratio->GetXaxis()->SetTitleSize(0); ratio->SetMarkerSize(1); ratio->Draw(); TLine line; line.SetLineWidth(1); line.DrawLine(datahist->GetXaxis()->GetXmin(),1,datahist->GetXaxis()->GetXmax(),1); } }
int main (int argc, char** argv) { // check number of inpt parameters if (argc < 2) { cerr << "Forgot to put the cfg file --> exit " << endl ; return 1 ; } if (gConfigParser) return 1 ; gConfigParser = new ConfigParser () ; TString config ; config.Form ("%s",argv[1]) ; if (! (gConfigParser->init (config))) { cout << ">>> parseConfigFile::Could not open configuration file " << config << endl ; return -1 ; } float lumi = gConfigParser->readFloatOption ("general::lumi") ; cout << "READING lumi " << lumi << endl ; int maxEvtsMC = -1; if (gConfigParser->isDefined ("general::maxEvtsMC")) maxEvtsMC = gConfigParser -> readIntOption ("general::maxEvtsMC"); // get the samples to be analised // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- // isolated samples // .... .... .... .... .... .... .... .... .... .... .... .... vector<string> sigSamplesList = gConfigParser->readStringListOption ("general::signals") ; vector<sample> sigSamples ; readSamples (sigSamples, sigSamplesList) ; vector<float> signalScales ; for (unsigned int i = 0 ; i < sigSamplesList.size () ; ++i) { string name = string ("samples::") + sigSamplesList.at (i) + string ("FACT") ; float scale = gConfigParser->readFloatOption (name.c_str ()) ; signalScales.push_back (scale) ; } vector<string> bkgSamplesList = gConfigParser->readStringListOption ("general::backgrounds") ; vector<sample> bkgSamples ; readSamples (bkgSamples, bkgSamplesList) ; vector<string> DATASamplesList = gConfigParser->readStringListOption ("general::data") ; vector<sample> DATASamples ; readSamples (DATASamples, DATASamplesList) ; /* // NOT isolated samples // not needed anymore from Skims_7_NI because we don't ask isolation during the skim // .... .... .... .... .... .... .... .... .... .... .... .... vector<string> NI_sigSamplesList = gConfigParser->readStringListOption ("general::NIsignals") ; vector<sample> NI_sigSamples ; readSamples (NI_sigSamples, NI_sigSamplesList) ; vector<string> NI_bkgSamplesList = gConfigParser->readStringListOption ("general::NIbackgrounds") ; vector<sample> NI_bkgSamples ; readSamples (NI_bkgSamples, NI_bkgSamplesList) ; vector<string> NI_DATASamplesList = gConfigParser->readStringListOption ("general::NIdata") ; vector<sample> NI_DATASamples ; readSamples (NI_DATASamples, NI_DATASamplesList) ; */ // get the selections to be applied // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- vector<string> activeSelections = gConfigParser->readStringListOption ("computeQCDratio::list") ; vector<pair <TString, TCut> > selections = readCutsFile ( activeSelections, gConfigParser->readStringOption ("selections::selectionsFile") ) ; cout << "\n-====-====-====-====-====-====-====-====-====-====-====-====-====-\n\n" ; cout << "selections sequence: \n" ; for (unsigned int i = 0 ; i < selections.size () ; ++i) cout << selections.at (i).first << " : " << selections.at (i).second << endl ; // read thresholds for non iso WPs std::vector<float> dau1iso_thrLow = gConfigParser->readFloatListOption ("computeQCDratio::dau1isothrLow"); std::vector<float> dau2iso_thrLow = gConfigParser->readFloatListOption ("computeQCDratio::dau2isothrLow"); // iso > thrLow vector <vector<pair <TString, TCut> > > vec_allselections_SS; vector <vector<pair <TString, TCut> > > vec_allselections_OS; // create SS and OS selections for (unsigned int ithr = 0; ithr < dau1iso_thrLow.size(); ithr++) { // OS vector<pair <TString, TCut> > this_selections_OS = selections ; for (unsigned int i = 0 ; i < this_selections_OS.size () ; ++i) { this_selections_OS.at (i).first = TString (Form("OSaiso_%f_%f_", dau1iso_thrLow.at(ithr), dau2iso_thrLow.at(ithr))) + this_selections_OS.at (i).first ; TString cut = Form("dau1_iso > %f && dau2_iso > %f && isOS != 0", dau1iso_thrLow.at(ithr), dau2iso_thrLow.at(ithr)); cout << "OS anti-iso selecton: " << cut << endl; this_selections_OS.at (i).second = this_selections_OS.at (i).second && TCut(cut) ; } vec_allselections_OS.push_back(this_selections_OS); // SS vector<pair <TString, TCut> > this_selections_SS = selections ; for (unsigned int i = 0 ; i < this_selections_SS.size () ; ++i) { this_selections_SS.at (i).first = TString (Form("SSaiso_%f_%f_", dau1iso_thrLow.at(ithr), dau2iso_thrLow.at(ithr))) + this_selections_SS.at (i).first ; TString cut = Form("dau1_iso > %f && dau2_iso > %f && isOS == 0", dau1iso_thrLow.at(ithr), dau2iso_thrLow.at(ithr)); cout << "SS anti-iso selecton: " << cut << endl; this_selections_SS.at (i).second = this_selections_SS.at (i).second && TCut(cut) ; } vec_allselections_SS.push_back(this_selections_SS); } // now merge all selections for different iso thresholds into a single one to be faster vector<pair <TString, TCut> > selections_OS; for (unsigned int iv = 0; iv < vec_allselections_OS.size(); iv++) { for (unsigned int isel = 0; isel < vec_allselections_OS.at(iv).size(); isel++) { pair <TString, TCut> thisPair = vec_allselections_OS.at(iv).at(isel); selections_OS.push_back (thisPair); } } vector<pair <TString, TCut> > selections_SS; for (unsigned int iv = 0; iv < vec_allselections_SS.size(); iv++) { for (unsigned int isel = 0; isel < vec_allselections_SS.at(iv).size(); isel++) { pair <TString, TCut> thisPair = vec_allselections_SS.at(iv).at(isel); selections_SS.push_back (thisPair); } } // check that everything is fine: for (unsigned int isel = 0; isel < selections_OS.size(); isel++) cout << selections_OS.at(isel).first << endl; for (unsigned int isel = 0; isel < selections_SS.size(); isel++) cout << selections_SS.at(isel).first << endl; // get the variables to be plotted -- will make OS / SS plot ratio for each // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- vector<string> variablesList = gConfigParser->readStringListOption ("general::variables") ; vector<string> Buf_variables2DList(0); if (gConfigParser->isDefined ("general::2Dvariables")) Buf_variables2DList = gConfigParser->readStringListOption ("general::2Dvariables") ; vector<pair<string,string> > variables2DList(0); for (unsigned int i = 0 ; i < Buf_variables2DList.size () ; ++i) { vector<string> dummy = split (Buf_variables2DList.at (i), ':') ; //cout << dummy.at (0) << " " << dummy.at (1) << " " << dummy.size () << endl ; variables2DList.push_back (make_pair(dummy.at (0), dummy.at (1)) ) ; } // calculate the QCD in the SS region as data - other_bkg // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- cout << "--- MAIN reading DATA and filling SS histos" << endl ; // get the same-sign distributions from data plotContainer SS_DATA_plots ("SS_DATA", variablesList, variables2DList, selections_SS, DATASamplesList, 2) ; counters SS_DATACount = fillHistos (DATASamples, SS_DATA_plots, variablesList, variables2DList, selections_SS, lumi, vector<float> (0), true, false) ; // SS_DATA_plots.AddOverAndUnderFlow () ; cout << "--- MAIN reading bkg and filling SS histos" << endl ; // get the same-sign distributions from bkg plotContainer SS_bkg_plots ("SS_bkg", variablesList, variables2DList, selections_SS, bkgSamplesList, 0) ; counters SS_bkgCount = fillHistos (bkgSamples, SS_bkg_plots, variablesList, variables2DList, selections_SS, lumi, vector<float> (0), false, false, maxEvtsMC) ; // SS_bkg_plots.AddOverAndUnderFlow () ; cout << "--- MAIN preparing to loop on variables and selections to calc SS QCD" << endl ; // the index in the stack is based on variable ID (iv) and selection ID (isel): // iHisto = iv + nVars * isel vector<string> QCDsample ; QCDsample.push_back ("QCD") ; plotContainer SS_QCD ("SS_QCD", variablesList, variables2DList, selections_SS, QCDsample, 0) ; // vector <TH1F *> SS_QCD ; for (unsigned int ivar = 0 ; ivar < variablesList.size () ; ++ivar) { for (unsigned int icut = 0 ; icut < selections_SS.size () ; ++icut) { THStack * D_stack = SS_DATA_plots.makeStack (variablesList.at (ivar), selections_SS.at (icut).first.Data ()) ; TH1F * tempo = (TH1F *) D_stack->GetStack ()->Last () ; TString name = tempo->GetName () ; name = TString ("DDQCD_") + name ; TH1F * dummy = (TH1F *) tempo->Clone (name) ; THStack * b_stack = SS_bkg_plots.makeStack (variablesList.at (ivar), selections_SS.at (icut).first.Data ()) ; TH1F * h_bkg = (TH1F *) b_stack->GetStack ()->Last () ; dummy->Add (h_bkg, -1) ; SS_QCD.m_histos[variablesList.at (ivar)][selections_SS.at (icut).first.Data ()]["QCD"] = dummy ; } } // calculate the QCD in the OS region as data - other_bkg // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- cout << "--- MAIN reading DATA and filling OS histos" << endl ; // get the same-sign distributions from data plotContainer OS_DATA_plots ("OS_DATA", variablesList, variables2DList, selections_OS, DATASamplesList, 2) ; counters OS_DATACount = fillHistos (DATASamples, OS_DATA_plots, variablesList, variables2DList, selections_OS, lumi, vector<float> (0), true, false) ; // OS_DATA_plots.AddOverAndUnderFlow () ; cout << "--- MAIN reading bkg and filling OS histos" << endl ; // get the same-sign distributions from bkg plotContainer OS_bkg_plots ("OS_bkg", variablesList, variables2DList, selections_OS, bkgSamplesList, 0) ; counters OS_bkgCount = fillHistos (bkgSamples, OS_bkg_plots, variablesList, variables2DList, selections_OS, lumi, vector<float> (0), false, false, maxEvtsMC) ; // OS_bkg_plots.AddOverAndUnderFlow () ; cout << "--- MAIN preparing to loop on variables and selections to calc OS QCD" << endl ; // the index in the stack is based on variable ID (iv) and selection ID (isel): // iHisto = iv + nVars * isel //vector<string> QCDsample ; //QCDsample.push_back ("QCD") ; plotContainer OS_QCD ("OS_QCD", variablesList, variables2DList, selections_OS, QCDsample, 0) ; // vector <TH1F *> OS_QCD ; for (unsigned int ivar = 0 ; ivar < variablesList.size () ; ++ivar) { for (unsigned int icut = 0 ; icut < selections_OS.size () ; ++icut) { THStack * D_stack = OS_DATA_plots.makeStack (variablesList.at (ivar), selections_OS.at (icut).first.Data ()) ; TH1F * tempo = (TH1F *) D_stack->GetStack ()->Last () ; TString name = tempo->GetName () ; name = TString ("DDQCD_") + name ; TH1F * dummy = (TH1F *) tempo->Clone (name) ; THStack * b_stack = OS_bkg_plots.makeStack (variablesList.at (ivar), selections_OS.at (icut).first.Data ()) ; TH1F * h_bkg = (TH1F *) b_stack->GetStack ()->Last () ; dummy->Add (h_bkg, -1) ; OS_QCD.m_histos[variablesList.at (ivar)][selections_OS.at (icut).first.Data ()]["QCD"] = dummy ; } } // calculate the QCD in the OS region as data - other_bkg // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- cout << "--- MAIN calculating ratios OS / SS" << endl ; //gStyle->SetOptStat(0); TString outFolderNameBase = gConfigParser->readStringOption ("general::outputFolderName") ; outFolderNameBase += "/" ; system (TString ("mkdir -p ") + outFolderNameBase) ; outFolderNameBase += gConfigParser->readStringOption ("computeQCDratio::outputFolderName") ; outFolderNameBase += "/" ; system (TString ("mkdir -p ") + outFolderNameBase) ; system (TString ("mkdir -p ") + outFolderNameBase + TString("ratioplots/")) ; system (TString ("mkdir -p ") + outFolderNameBase + TString("num_denom_plots/")) ; system (TString ("mkdir -p ") + outFolderNameBase + TString("num_denom_plots_log/")) ; system (TString ("mkdir -p ") + outFolderNameBase + TString("events/")) ; system (TString ("mkdir -p ") + outFolderNameBase + TString("events_log/")) ; TFile* fOut = new TFile (outFolderNameBase + "ratioPlots.root", "RECREATE"); fOut->cd(); TCanvas* c1 = new TCanvas; gStyle->SetOptFit(1111); TF1* f = new TF1 ("f", "[0] + [1]*x"); f->SetParameters (1.06, -0.0002); //for (unsigned int isample = 0; isample < samples.size(); isample++) for (unsigned int ivar = 0; ivar < variablesList.size(); ivar++) { for (unsigned int isel = 0; isel < selections.size(); isel++) { for (unsigned int ithr = 0; ithr < dau1iso_thrLow.size(); ithr++) { TH1F* thisRatio = makeRatio (OS_QCD, SS_QCD, selections.at(isel), variablesList.at(ivar), QCDsample.at(0), // "QCD" dau1iso_thrLow.at(ithr), dau2iso_thrLow.at(ithr) ); thisRatio -> SetMarkerStyle(8); thisRatio -> SetMarkerSize(1); thisRatio -> SetMarkerColor(kBlack); c1->SetLogy(false); thisRatio -> Draw(); //thisRatio -> Fit("pol1"); thisRatio -> Fit("f", "", "", 200, 1000); TString newName = outFolderNameBase + "ratioplots/ratio_" + variablesList.at(ivar) + "_" + selections.at(isel).first + Form("_%f_%f.pdf", dau1iso_thrLow.at(ithr), dau2iso_thrLow.at(ithr)) ; c1->Print (newName, "pdf"); thisRatio -> Write(); // now draw together SS and OS for this selection and draw plot pair <TH1F*, TH1F*> res = getPlotPair (OS_QCD, SS_QCD, selections.at(isel), variablesList.at(ivar), QCDsample.at(0), // "QCD" dau1iso_thrLow.at(ithr), dau2iso_thrLow.at(ithr) ); TH1F* hOS = res.first; TH1F* hSS = res.second; hOS->SetStats(false); hSS->SetStats(false); hOS->SetLineColor (kRed); hSS->SetLineColor (kBlue); hOS->SetMarkerColor (kRed); hSS->SetMarkerColor (kBlue); hOS->SetMarkerStyle (4); hSS->SetMarkerStyle (5); if (hSS->GetMaximum() > hOS->GetMaximum()) hOS->SetMaximum(hSS->GetMaximum()); hOS->SetMaximum(1.2*hOS->GetMaximum()); TLegend leg (0.41, 0.79, 0.89, 0.89); leg.SetNColumns(2); leg.SetFillColor(kWhite); leg.SetLineWidth(0); leg.SetBorderSize(0); leg.AddEntry(hOS, "OS", "lp"); leg.AddEntry(hSS, "SS", "lp"); hOS->Draw(); hSS->Draw("same"); leg.Draw(); newName = outFolderNameBase + "num_denom_plots/ratio_" + variablesList.at(ivar) + "_" + selections.at(isel).first + Form("_%f_%f.pdf", dau1iso_thrLow.at(ithr), dau2iso_thrLow.at(ithr)) ; c1->Print (newName, "pdf"); // ------- log ---- c1->SetLogy(true); hOS->Draw(); hSS->Draw("same"); //leg.Draw(); newName = outFolderNameBase + "num_denom_plots_log/ratio_" + variablesList.at(ivar) + "_" + selections.at(isel).first + Form("_%f_%f_log.pdf", dau1iso_thrLow.at(ithr), dau2iso_thrLow.at(ithr)) ; c1->Print (newName, "pdf"); c1->SetLogy(false); } } } // ------------------------------------------------------------------ cout << "--- MAIN printing event plots" << endl ; for (unsigned int ivar = 0 ; ivar < variablesList.size () ; ++ivar) { for (unsigned int icut = 0 ; icut < selections_OS.size () ; ++icut) { THStack * D_stack = OS_DATA_plots.makeStack (variablesList.at (ivar), selections_OS.at (icut).first.Data ()) ; TH1F * D_histo = (TH1F *) D_stack->GetStack ()->Last () ; D_histo -> Sumw2(false); D_histo -> SetBinErrorOption(TH1::kPoisson); D_histo -> SetMarkerStyle (8); D_histo -> SetMarkerSize (1); D_histo -> SetMarkerColor (kBlack); D_histo->SetMinimum(1.); THStack * b_stack = OS_bkg_plots.makeStack (variablesList.at (ivar), selections_OS.at (icut).first.Data ()) ; //TH1F * h_bkg = (TH1F *) b_stack->GetStack ()->Last () ; D_histo->SetStats(false); D_histo->Draw("E"); // data surely above bkg as it is QCD dominated b_stack->Draw("hist same"); // data surely above bkg as it is QCD dominated TString newName = outFolderNameBase + "events/plot_" + variablesList.at(ivar) + "_" + selections_OS.at (icut).first + "_OS.pdf" ; c1->Print (newName, "pdf"); c1->SetLogy(true); newName = outFolderNameBase + "events_log/plot_" + variablesList.at(ivar) + "_" + selections_OS.at (icut).first + "_log_OS.pdf" ; c1->Print (newName, "pdf"); c1->SetLogy(false); } } for (unsigned int ivar = 0 ; ivar < variablesList.size () ; ++ivar) { for (unsigned int icut = 0 ; icut < selections_SS.size () ; ++icut) { THStack * D_stack = SS_DATA_plots.makeStack (variablesList.at (ivar), selections_SS.at (icut).first.Data ()) ; TH1F * D_histo = (TH1F *) D_stack->GetStack ()->Last () ; D_histo -> Sumw2(false); D_histo -> SetBinErrorOption(TH1::kPoisson); D_histo -> SetMarkerStyle (8); D_histo -> SetMarkerSize (1); D_histo -> SetMarkerColor (kBlack); D_histo->SetMinimum(1.); THStack * b_stack = SS_bkg_plots.makeStack (variablesList.at (ivar), selections_SS.at (icut).first.Data ()) ; //TH1F * h_bkg = (TH1F *) b_stack->GetStack ()->Last () ; D_histo->SetStats(false); D_histo->Draw("E"); // data surely above bkg as it is QCD dominated b_stack->Draw("hist same"); // data surely above bkg as it is QCD dominated TString newName = outFolderNameBase + "events/plot_" + variablesList.at(ivar) + "_" + selections_SS.at (icut).first + "_SS.pdf" ; c1->Print (newName, "pdf"); c1->SetLogy(true); newName = outFolderNameBase + "events_log/plot_" + variablesList.at(ivar) + "_" + selections_OS.at (icut).first + "_log_SS.pdf" ; c1->Print (newName, "pdf"); c1->SetLogy(false); } } // /* NB if it has to be subtracted, it cannot be scaled! */ // // get the SS-to-OS scale factor and scale the QCD distributions // // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- // float SStoOS_scaleFactor = 1.06 ; // to be calculated here at a certain moment!! // SS_QCD.scale (SStoOS_scaleFactor) ; // int QCDcolor = gConfigParser->readIntOption ("colors::QCD") ; // SS_QCD.setHistosProperties (0, QCDcolor) ; // // insert the QCD in the OS region // // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- // cout << "--- MAIN reading DATA and filling OS histos" << endl ; // // get the opposite-sign distributions from data // plotContainer OS_DATA_plots ("OS_DATA", variablesList, variables2DList, selections_OS, DATASamplesList, 2) ; // counters OS_DATACount = fillHistos (DATASamples, OS_DATA_plots, // variablesList, variables2DList, // selections_OS, // lumi, // vector<float> (0), // true, false) ; // OS_DATA_plots.AddOverAndUnderFlow () ; // cout << "--- MAIN reading bkg and filling OS histos" << endl ; // // get the opposite-sign distributions from bkg // plotContainer OS_bkg_plots ("OS_bkg", variablesList, variables2DList, selections_OS, bkgSamplesList, 0) ; // counters OS_bkgCount = fillHistos (bkgSamples, OS_bkg_plots, // variablesList, variables2DList, // selections_OS, // lumi, // vector<float> (0), // false, false, maxEvtsMC) ; // OS_bkg_plots.AddOverAndUnderFlow () ; // OS_bkg_plots.addSample ("QCD", SS_QCD) ; // cout << "--- MAIN reading sig and filling OS histos" << endl ; // // get the opposite-sign distributions from sig // plotContainer OS_sig_plots ("OS_sig", variablesList, variables2DList, selections_OS, sigSamplesList, 1) ; // counters OS_sigCount = fillHistos (sigSamples, OS_sig_plots, // variablesList, variables2DList, // selections_OS, // lumi, // vector<float> (0), // false, true) ; // OS_sig_plots.AddOverAndUnderFlow () ; // // Save the histograms // // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- // cout << "--- MAIN before saving" << endl ; // TString outFolderNameBase = gConfigParser->readStringOption ("general::outputFolderName") ; // outFolderNameBase += "/" ; // system (TString ("mkdir -p ") + outFolderNameBase) ; // outFolderNameBase += gConfigParser->readStringOption ("evalQCD::outputFolderName") ; // outFolderNameBase += "/" ; // system (TString ("mkdir -p ") + outFolderNameBase) ; // TString outString ; // outString.Form (outFolderNameBase + "outPlotter.root") ; // TFile * fOut = new TFile (outString.Data (), "RECREATE") ; // SS_DATA_plots.save (fOut) ; // SS_bkg_plots.save (fOut) ; // OS_DATA_plots.save (fOut) ; // OS_bkg_plots.save (fOut) ; // OS_sig_plots.save (fOut) ; // SS_QCD.save (fOut); // this is the estimated QCD after scaling to OS region 1.06 // fOut->Close () ; // // Plot the histograms // // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- // system (TString ("mkdir -p ") + outFolderNameBase + TString ("/events/")) ; // system (TString ("mkdir -p ") + outFolderNameBase + TString ("/shapes/")) ; // TCanvas * c = new TCanvas () ; // cout << "--- MAIN before plotting" << endl ; // // loop on selections // for (unsigned int isel = 0 ; isel < selections.size () ; ++isel) // { // // loop on variables // for (unsigned int iv = 0 ; iv < variablesList.size () ; ++iv) // { // c->cd () ; // TString outputName ; // outputName.Form ("plot_%s_%s", // variablesList.at (iv).c_str (), selections.at (isel).first.Data ()) ; // TString outFolderName = outFolderNameBase + TString ("/events/") ; // // get the extremes for the plot // THStack * sig_stack = OS_sig_plots.makeStack ( variablesList.at (iv), // selections_OS.at (isel).first.Data ()) ; // THStack * bkg_stack = OS_bkg_plots.makeStack ( variablesList.at (iv), // selections_OS.at (isel).first.Data ()) ; // THStack * DATA_stack = OS_DATA_plots.makeStack ( variablesList.at (iv), // selections_OS.at (isel).first.Data ()) ; // vector<float> extremes_bkg = getExtremes (bkg_stack) ; // vector<float> extremes_sig = getExtremes (sig_stack) ; // vector<float> extremes_DATA = getExtremes (DATA_stack) ; // TH1F * bkg = c->DrawFrame ( // extremes_bkg.at (0) , // 0.9 * min3 (extremes_bkg.at (1), extremes_sig.at (1), // extremes_DATA.at (1)) , // extremes_bkg.at (2) , // 1.3 * max3 (extremes_bkg.at (3), extremes_sig.at (3), // extremes_DATA.at (3) + sqrt (extremes_DATA.at (3))) // ) ; // copyTitles (bkg, bkg_stack) ; // bkg->Draw () ; // bkg_stack->Draw ("hist same") ; // sig_stack->Draw ("nostack hist same") ; // TH1F * h_data = (TH1F *) DATA_stack->GetStack ()->Last () ; // // FIXME probably the data uncertainties need to be fixed // h_data->Draw ("same") ; // TString coutputName ; // coutputName.Form ("%s.pdf", (outFolderName + outputName).Data ()) ; // c->SaveAs (coutputName.Data ()) ; // c->SetLogy (1) ; // bkg->Draw () ; // bkg_stack->Draw ("hist same") ; // sig_stack->Draw ("nostack hist same") ; // h_data->Draw ("same") ; // coutputName.Form ("%s_log.pdf", (outFolderName + outputName).Data ()) ; // c->SaveAs (coutputName.Data ()) ; // c->SetLogy (0) ; // // plotting shapes // // ---- ---- ---- ---- ---- ---- ---- ---- ---- // outFolderName = outFolderNameBase + TString ("/shapes/") ; // TString basename ; // basename.Form ("shape_%s_%s", // variablesList.at (iv).c_str (), // selections.at (isel).first.Data () // ) ; // THStack * hstack_bkg_norm = normaliseStack (bkg_stack) ; // TH1F * shape_bkg = (TH1F *) hstack_bkg_norm->GetStack ()->Last () ; // THStack * hstack_sig_norm = normaliseStack (sig_stack) ; // TH1F * shape_sig = (TH1F *) hstack_sig_norm->GetStack ()->Last () ; // if (shape_sig->GetMaximum () > shape_bkg->GetMaximum ()) // hstack_sig_norm->Draw ("hist") ; // else // hstack_bkg_norm->Draw ("hist") ; // hstack_bkg_norm->Draw ("hist same") ; // hstack_sig_norm->Draw ("hist same") ; // TString name = basename + "_norm" ; // coutputName.Form ("%s.pdf", (outFolderName + basename).Data ()) ; // c->SaveAs (coutputName.Data ()) ; // /* // // plotting 2D histos, one per sample as it is hard to superimpose them // // ---- ---- ---- ---- ---- ---- ---- ---- ---- // outFolderName = outFolderNameBase + TString ("/plots2D/") ; // OS_sig_plots. // */ // delete hstack_bkg_norm; // delete hstack_sig_norm; // delete sig_stack; // delete bkg_stack; // delete DATA_stack; // } // loop on variables // } // loop on selections // delete c ; // // print yields // // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- // TString yieldsFileName = outFolderNameBase + "/yields.txt"; // std::ofstream yieldsFile (yieldsFileName.Data()); // unsigned int NSpacesColZero = 16; // unsigned int NSpacesColumns = 10; // cout << "\n-====-====-====-====-====-====-====-====-====-====-====-====-====-\n\n" ; // cout << " EXPECTED NUMBER OF SIG EVENTS\n\n" ; // yieldsFile << "\n-====-====-====-====-====-====-====-====-====-====-====-====-====-\n\n" ; // yieldsFile << " EXPECTED NUMBER OF SIG EVENTS\n\n" ; // printTableTitle (std::cout, sigSamples) ; // printTableTitle (yieldsFile, sigSamples) ; // printTableBody (std::cout, selections, OS_sigCount, sigSamples) ; // printTableBody (yieldsFile, selections, OS_sigCount, sigSamples) ; // vector<string> DataDriven_names (1, string("QCD")); // vector <vector<float>> DataDriven_yields; // vector<float> QCD_yields; // // QCD -- prepare yields // for (unsigned int iSel = 0 ; iSel < selections.size () ; ++iSel) // { // int nQCD = SS_QCD.getHisto (variablesList.at(0), string(selections_SS.at(iSel).first.Data()), QCDsample.at(0)) -> Integral(); // QCD_yields.push_back (nQCD); // } // DataDriven_yields.push_back (QCD_yields); // cout << "\n-====-====-====-====-====-====-====-====-====-====-====-====-====-\n\n" ; // cout << " EXPECTED NUMBER OF BKG EVENTS\n\n" ; // yieldsFile << "\n-====-====-====-====-====-====-====-====-====-====-====-====-====-\n\n" ; // yieldsFile << " EXPECTED NUMBER OF BKG EVENTS\n\n" ; // printTableTitle (std::cout, bkgSamples, DataDriven_names) ; // printTableTitle (yieldsFile, bkgSamples, DataDriven_names) ; // printTableBody (std::cout, selections, OS_bkgCount, bkgSamples, DataDriven_yields) ; // printTableBody (yieldsFile, selections, OS_bkgCount, bkgSamples, DataDriven_yields) ; // // mini debug to cjeck that each var has the same QCD yield // /* // // QCD // for (unsigned int iSel = 0 ; iSel < selections.size () ; ++iSel) // { // for (int ivar = 0 ; ivar < variablesList.size(); ivar++) // { // int nQCD = SS_QCD.getHisto (variablesList.at(ivar), string(selections_SS.at(iSel).first.Data()), QCDsample.at(0)) -> Integral(); // cout << nQCD << " "; // } // cout << " --- " << endl; // } // */ // cout << "\n-====-====-====-====-====-====-====-====-====-====-====-====-====-\n\n" ; // cout << " OBSERVED NUMBER OF EVENTS\n\n" ; // yieldsFile << "\n-====-====-====-====-====-====-====-====-====-====-====-====-====-\n\n" ; // yieldsFile << " OBSERVED NUMBER OF EVENTS\n\n" ; // printTableTitle (std::cout, DATASamples) ; // printTableTitle (yieldsFile, DATASamples) ; // printTableBody (std::cout, selections, OS_DATACount, DATASamples) ; // printTableBody (yieldsFile, selections, OS_DATACount, DATASamples) ; // cout << "\n-====-====-====-====-====-====-====-====-====-====-====-====-====-\n\n" ; // cout << " TOTALS\n\n" ; // yieldsFile << "\n-====-====-====-====-====-====-====-====-====-====-====-====-====-\n\n" ; // yieldsFile << " TOTALS\n\n" ; // vector<float> DATAtotal = OS_DATACount.getTotalCountsPerCut () ; // vector<float> bkgtotal = OS_bkgCount.getTotalCountsPerCut () ; // vector<string> titles ; titles.push_back ("DATA") ; titles.push_back ("bkg") ; // printTableTitle (std::cout, titles) ; // printTableTitle (yieldsFile, titles) ; // for (unsigned int iSel = 0 ; iSel < selections.size () ; ++iSel) // { // cout << selections.at (iSel).first ; // yieldsFile << selections.at (iSel).first ; // unsigned int nspacetojump = (NSpacesColZero > string(selections.at (iSel).first.Data ()).size () ? NSpacesColZero - string(selections.at (iSel).first.Data ()).size () : 0); // for (unsigned int i = 0 ; i < nspacetojump; ++i){ // cout << " " ; // yieldsFile << " " ; // } // cout << "|" ; // yieldsFile << "|" ; // float evtnum = DATAtotal.at (iSel+1) ; // int subtractspace = 0 ; // if (evtnum > 0) subtractspace = int (log10 (evtnum)) ; // for (unsigned int i = 0 ; i < NSpacesColumns - subtractspace ; ++i) // { // cout << " " ; // yieldsFile << " " ; // } // cout << setprecision (0) << fixed << evtnum // << " |" ; // yieldsFile << setprecision (0) << fixed << evtnum // << " |" ; // evtnum = bkgtotal.at (iSel+1); // for (unsigned int iDD = 0; iDD < DataDriven_yields.size(); iDD++) evtnum += DataDriven_yields.at(iDD).at(iSel); // subtractspace = 0 ; // if (evtnum > 0) subtractspace = int (log10 (evtnum)) ; // for (unsigned int i = 0 ; i < NSpacesColumns - subtractspace ; ++i) // { // cout << " " ; // yieldsFile << " " ; // } // cout << setprecision (0) << fixed << evtnum // << " |\n" ; // yieldsFile << setprecision (0) << fixed << evtnum // << " |\n" ; // } // /* // cout << " ============ MINI DEBUG ON QCD YIELDS ============ " << endl; // for (unsigned int isel = 0 ; isel < selections.size () ; ++isel) // { // // loop on variables // for (unsigned int iv = 0 ; iv < variablesList.size () ; ++iv) // } // */ // // save on root file for debug // //TFile* fRootOut = new TFile (outFolderNameBase + "/" + "SS_QCD_histos.root", "recreate"); // //fRootOut->Close(); return 0 ; }
void HTT_MM_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="mumu_$CATEGORY") { // define common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category = ""; const char* category_extra = ""; const char* category_extra2 = ""; if(std::string(directory) == std::string("mumu_0jet_low" )){ category = "#mu#mu"; } if(std::string(directory) == std::string("mumu_0jet_low" )){ category_extra = "0-jet low p_{T}^{#mu}"; } if(std::string(directory) == std::string("mumu_0jet_high" )){ category = "#mu#mu"; } if(std::string(directory) == std::string("mumu_0jet_high" )){ category_extra = "0-jet high p_{T}^{#mu}"; } if(std::string(directory) == std::string("mumu_1jet_low" )){ category = "#mu#mu"; } if(std::string(directory) == std::string("mumu_1jet_low" )){ category_extra = "1-jet low p_{T}^{#mu}"; } if(std::string(directory) == std::string("mumu_1jet_high" )){ category = "#mu#mu"; } if(std::string(directory) == std::string("mumu_1jet_high" )){ category_extra = "1-jet high p_{T}^{#mu}"; } if(std::string(directory) == std::string("mumu_vbf" )){ category = "#mu#mu"; } if(std::string(directory) == std::string("mumu_vbf" )){ category_extra = "2-jet"; } if(std::string(directory) == std::string("mumu_nobtag" )){ category = "#mu#mu"; } if(std::string(directory) == std::string("mumu_nobtag" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("mumu_btag" )){ category = "#mu#mu"; } if(std::string(directory) == std::string("mumu_btag" )){ category_extra = "b-tag"; } const char* dataset; #ifdef MSSM if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 4.9 fb^{-1} (7 TeV)";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 19.7 fb^{-1} (8 TeV)";} #else if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS, 19.7 fb^{-1} at 8 TeV";} #endif TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MA_$TANB").c_str()); #endif TH1F* ZTT = refill((TH1F*)input ->Get(TString::Format("%s/ZTT" , directory)), "ZTT" ); InitHist(ZTT , "", "", TColor::GetColor(248,206,104), 1001); TH1F* ZMM = refill((TH1F*)input ->Get(TString::Format("%s/ZMM" , directory)), "ZMM" ); InitHist(ZMM , "", "", TColor::GetColor(100,182,232), 1001); TH1F* TTJ = refill((TH1F*)input ->Get(TString::Format("%s/TTJ" , directory)), "TTJ" ); InitHist(TTJ , "", "", TColor::GetColor(155,152,204), 1001); TH1F* QCD = refill((TH1F*)input ->Get(TString::Format("%s/QCD" , directory)), "QCD" ); InitHist(QCD , "", "", TColor::GetColor(250,202,255), 1001); TH1F* Dibosons = refill((TH1F*)input ->Get(TString::Format("%s/Dibosons", directory)), "Dibosons"); InitHist(Dibosons, "", "", TColor::GetColor(222,90,106), 1001); TH1F* WJets = 0; if(!(std::string("mumu_nobtag") == std::string(directory))){ // template has been removed from nobtag categories WJets = refill((TH1F*)input ->Get(TString::Format("%s/WJets" , directory)), "WJets" ); InitHist(WJets , "", "", kGreen -4 , 1001); } #ifdef MSSM TH1F* ggH = refill((TH1F*)input2->Get(TString::Format("%s/ggH$MA" , directory)), "ggH" ); InitSignal(ggH); ggH->Scale($TANB); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MA" , directory)), "bbH" ); InitSignal(bbH); bbH->Scale($TANB); #else #ifndef DROP_SIGNAL TH1F* ggH = refill((TH1F*)input ->Get(TString::Format("%s/ggH125" , directory)), "ggH" ); InitSignal(ggH); ggH->Scale(SIGNAL_SCALE); TH1F* qqH = refill((TH1F*)input ->Get(TString::Format("%s/qqH125" , directory)), "qqH" ); InitSignal(qqH); qqH->Scale(SIGNAL_SCALE); TH1F* VH = refill((TH1F*)input ->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH ->Scale(SIGNAL_SCALE); #endif #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); #endif #ifdef MSSM InitHist(data, "#bf{m_{#tau#tau} [GeV]}" , "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); #else InitHist(data, "#bf{D}", "#bf{dN/dD}" ); InitData(data); #endif TH1F* ref=(TH1F*)ZTT->Clone("ref"); ref->Add(ZMM); ref->Add(TTJ); ref->Add(QCD); ref->Add(Dibosons); if(WJets){ ref->Add(WJets); } double unscaled[9]; unscaled[0] = ZTT->Integral(); unscaled[1] = ZMM->Integral(); unscaled[2] = TTJ->Integral(); unscaled[3] = QCD->Integral(); unscaled[4] = Dibosons->Integral(); unscaled[5] = 0; if(WJets){ unscaled[5] = WJets->Integral(); } #ifdef MSSM unscaled[6] = ggH->Integral(); unscaled[7] = bbH->Integral(); unscaled[8] = 0; #else #ifndef DROP_SIGNAL unscaled[6] = ggH->Integral(); unscaled[7] = qqH->Integral(); unscaled[8] = VH ->Integral(); #endif #endif if(scaled){ rescale(ZTT, 1); rescale(ZMM, 2); rescale(TTJ, 3); rescale(QCD, 4); rescale(Dibosons, 5); if(WJets){ rescale(WJets, 6); } #ifdef MSSM rescale(ggH, 7); rescale(bbH, 8); #else #ifndef DROP_SIGNAL rescale(ggH, 7); rescale(qqH, 8); rescale(VH, 9); #endif #endif } TH1F* scales[9]; scales[0] = new TH1F("scales-ZTT", "", 9, 0, 9); scales[0]->SetBinContent(1, unscaled[0]>0 ? (ZTT->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-ZMM" , "", 9, 0, 9); scales[1]->SetBinContent(2, unscaled[1]>0 ? (ZMM->Integral()/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-TTJ", "", 9, 0, 9); scales[2]->SetBinContent(3, unscaled[2]>0 ? (TTJ->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-QCD" , "", 9, 0, 9); scales[3]->SetBinContent(4, unscaled[3]>0 ? (QCD->Integral()/unscaled[3]-1.) : 0.); scales[4] = new TH1F("scales-Dibosons", "", 9, 0, 9); scales[4]->SetBinContent(5, unscaled[4]>0 ? (Dibosons->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-WJets" , "", 9, 0, 9); scales[5]->SetBinContent(6, 0.); if(WJets){ scales[5]->SetBinContent(6, unscaled[5]>0 ? (WJets->Integral()/unscaled[5]-1.) : 0.); } #ifdef MSSM scales[6] = new TH1F("scales-ggH" , "", 9, 0, 9); scales[6]->SetBinContent(7, unscaled[6]>0 ? (ggH->Integral()/unscaled[6]-1.) : 0.); scales[7] = new TH1F("scales-bbH" , "", 9, 0, 9); scales[7]->SetBinContent(8, unscaled[7]>0 ? (bbH->Integral()/unscaled[7]-1.) : 0.); scales[8] = new TH1F("scales-NONE" , "", 9, 0, 9); scales[8]->SetBinContent(9, 0.); #else #ifndef DROP_SIGNAL scales[6] = new TH1F("scales-ggH" , "", 9, 0, 9); scales[6]->SetBinContent(7, unscaled[6]>0 ? (ggH->Integral()/unscaled[6]-1.) : 0.); scales[7] = new TH1F("scales-qqH" , "", 9, 0, 9); scales[7]->SetBinContent(8, unscaled[7]>0 ? (qqH->Integral()/unscaled[7]-1.) : 0.); scales[8] = new TH1F("scales-VH" , "", 9, 0, 9); scales[8]->SetBinContent(9, unscaled[8]>0 ? (VH ->Integral()/unscaled[8]-1.) : 0.); #endif #endif if(WJets){ Dibosons->Add(WJets); } QCD->Add(Dibosons); TTJ->Add(QCD); ZTT->Add(TTJ); ZMM->Add(ZTT); if(log){ #ifdef MSSM ggH ->Add(bbH); #else #ifndef DROP_SIGNAL qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } else{ #ifdef MSSM bbH ->Add(ZMM); ggH ->Add(bbH); #else #ifndef DROP_SIGNAL VH ->Add(ZMM); qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } /* mass plot before and after fit */ TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(345)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(UPPER_EDGE)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(345)); #endif data->SetNdivisions(505); data->SetMinimum(min); #ifndef DROP_SIGNAL data->SetMaximum(max>0 ? max : std::max(std::max(maximum(data, log), maximum(ZMM, log)), maximum(ggH, log))); #else data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(ZMM, log))); #endif data->Draw("e"); TH1F* errorBand = (TH1F*)ZMM->Clone("errorBand"); errorBand->SetMarkerSize(0); errorBand->SetFillColor(13); errorBand->SetFillStyle(3013); errorBand->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ ZMM->Draw("histsame"); ZTT->Draw("histsame"); TTJ->Draw("histsame"); QCD->Draw("histsame"); Dibosons->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ggH->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif ZMM->Draw("histsame"); ZTT->Draw("histsame"); TTJ->Draw("histsame"); QCD->Draw("histsame"); Dibosons->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{#mu}#tau_{#mu}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); #if defined MSSM TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "tlbrNDC"); #else TPaveText* chan = new TPaveText(0.22, (category_extra2 && category_extra2[0]=='\0') ? 0.65+0.061 : 0.65+0.061, 0.34, 0.75+0.161, "tlbrNDC"); #endif chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->AddText(category_extra); #if defined MSSM #else chan->AddText(category_extra2); #endif chan->Draw(); /* TPaveText* cat = new TPaveText(0.20, 0.71+0.061, 0.32, 0.71+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); */ #ifdef MSSM TPaveText* massA = new TPaveText(0.53, 0.44+0.061, 0.95, 0.44+0.151, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("MSSM m^{h}_{max} scenario"); massA->AddText("m_{A}=$MA GeV, tan#beta=$TANB"); massA->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.53, 0.60, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggH , "h,H,A#rightarrow#tau#tau" , "L" ); #else TLegend* leg = new TLegend(0.52, 0.58, 0.92, 0.89); SetLegendStyle(leg); #ifndef DROP_SIGNAL if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ leg->AddEntry(ggH , "SM H(125 GeV)#rightarrow#tau#tau" , "L" ); } #endif #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + H(125)" , "LP"); #else leg->AddEntry(data , "Observed" , "LP"); #endif leg->AddEntry(ZMM , "Z#rightarrow#mu#mu" , "F" ); leg->AddEntry(ZTT , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(TTJ , "t#bar{t}" , "F" ); leg->AddEntry(QCD , "QCD" , "F" ); leg->AddEntry(Dibosons, "Electroweak" , "F" ); $ERROR_LEGEND leg->Draw(); /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* model = (TH1F*)ZMM ->Clone("model"); TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); model->SetBinError (ibin+1, CONVERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; double chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; double ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; double ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; std::vector<double> edges; TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat1"); rat1->Reset("ICES"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(data->GetBinContent(ibin+1) > 0){ rat1->SetBinContent(ibin+1, ZMM->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/ZMM->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, ZMM->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/ZMM->GetBinContent(ibin+1) : 0); } zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, ZMM->GetBinContent(ibin+1)>0 ? ZMM ->GetBinError (ibin+1)/ZMM->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); #ifdef MSSM rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); #else rat1->GetXaxis()->SetTitle("#bf{D}"); #endif rat1->Draw("E0"); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv0->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); stat1->Draw(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); edges.clear(); TH1F* rat2 = (TH1F*) ZMM->Clone("rat2"); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ rat2->SetBinContent(ibin+1, ref->GetBinContent(ibin+1)>0 ? ZMM->GetBinContent(ibin+1)/ref->GetBinContent(ibin+1) : 0); rat2->SetBinError (ibin+1, ref->GetBinContent(ibin+1)>0 ? ZMM->GetBinError (ibin+1)/ref->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat2->GetBinContent(ibin+1)-1.)+TMath::Abs(rat2->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } #if defined MSSM if(!log){ rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); } else{ rat2->GetXaxis()->SetRange(0, rat2->FindBin(UPPER_EDGE)); }; #else rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); #endif rat2->SetNdivisions(505); rat2->SetLineColor(kRed+3); rat2->SetMarkerColor(kRed+3); rat2->SetMarkerSize(1.1); rat2->SetMaximum(+range); rat2->SetMinimum(-range); rat2->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); #if defined MSSM rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); #else rat2->GetXaxis()->SetTitle("#bf{D}"); #endif rat2->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->Draw("e2histsame"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", TColor::GetColor(248,206,104), 1001); InitHist (scales[1], "", "", TColor::GetColor(100,182,232), 1001); InitHist (scales[2], "", "", TColor::GetColor(155,152,204), 1001); InitHist (scales[3], "", "", TColor::GetColor(250,202,255), 1001); InitHist (scales[4], "", "", TColor::GetColor(222,90,106), 1001); InitHist (scales[5], "", "", kGreen - 4, 1001); #ifndef DROP_SIGNAL InitSignal(scales[6]); InitSignal(scales[7]); InitSignal(scales[8]); #endif scales[0]->GetXaxis()->SetBinLabel(1, "#bf{ZTT}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{ZMM}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{TTJ}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{QCD}" ); scales[0]->GetXaxis()->SetBinLabel(5, "#bf{Dibosons}"); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{WJets}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(7, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(8, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(9, "#bf{NONE}" ); #else scales[0]->GetXaxis()->SetBinLabel(7, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(8, "#bf{qqH}" ); scales[0]->GetXaxis()->SetBinLabel(9, "#bf{VH}" ); #endif scales[0]->SetMaximum(+0.5); scales[0]->SetMinimum(-0.5); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); scales[0]->Draw(); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); scales[4]->Draw("same"); scales[5]->Draw("same"); #ifndef DROP_SIGNAL scales[6]->Draw("same"); scales[7]->Draw("same"); scales[8]->Draw("same"); #endif TH1F* zero_samples = (TH1F*)scales[0]->Clone("zero_samples"); zero_samples->Clear(); zero_samples->SetBinContent(1,0.); zero_samples->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); if(log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } if((log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"), "update"); output->cd(); data ->Write("data_obs"); ZTT->Write("Ztt" ); ZMM->Write("Zmm" ); TTJ->Write("ttbar"); QCD->Write("Fakes"); Dibosons->Write("EWK"); if(WJets){ WJets->Write("WJets"); } #ifdef MSSM ggH ->Write("ggH"); bbH ->Write("bbH"); #else #ifndef DROP_SIGNAL ggH ->Write("ggH"); qqH ->Write("qqH"); VH ->Write("VH" ); #endif #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); delete errorBand; delete model; delete test1; delete zero; delete rat1; delete rat2; delete zero_samples; delete ref; }
void overlayParamPlots_report(string paramFilename1, bool isData1, string paramFilename2, bool isData2, string paramToPlot, int rebin=1, double yaxis_min=1e-2, double yaxis_max=10, Short_t col2=kRed, bool doNormalizedArea=true) { cout <<"file1 (black) : " << paramFilename1 <<endl; cout <<"file2 ("<< col2 <<"): "<< paramFilename2 <<endl; TFile *rfin1 = new TFile( paramFilename1.c_str(), "read"); TFile *rfin2 = new TFile( paramFilename2.c_str(), "read"); //plot single parameters char title[200]; string runType1, runType2; if( isData1 ) runType1="Data"; else runType1="Sim"; if( isData2 ) runType2="Data"; else runType2="Sim"; int reportTypeId=2; bool showerParameter = false; int paramIdToPlot = -9; for(int i=0; i<NofShowerParams; i++){ if( paramToPlot.compare( NameOfParams[i]) == 0 ){ showerParameter = true; paramIdToPlot = i; for(int j=0; j<NofEbins; j++){ sprintf( title, "h1%s_%s_Ebin%d_%s", NameOfParams[i].c_str(), runType1.c_str(), j, NameOfType[reportTypeId].c_str()); h1Params1[i][j][reportTypeId] = (TH1F*)rfin1->Get( title ); h1Params1[i][j][reportTypeId]->SetLineColor(kBlack); sprintf( title, "h1%s_%s_Ebin%d_%s", NameOfParams[i].c_str(), runType2.c_str(), j, NameOfType[reportTypeId].c_str()); h1Params2[i][j][reportTypeId] = (TH1F*)rfin2->Get( title ); h1Params2[i][j][reportTypeId]->SetMarkerStyle(24); h1Params2[i][j][reportTypeId]->SetMarkerColor(col2); h1Params2[i][j][reportTypeId]->SetLineColor(col2); if( rebin > 1 ){ h1Params1[i][j][reportTypeId]->Rebin( rebin ); h1Params2[i][j][reportTypeId]->Rebin( rebin ); } } } } if( !showerParameter ){ for(int i=0; i<NofTelParams; i++){ if( paramToPlot.compare(NameOfParamsTel[i]) == 0 ){ paramIdToPlot = i; for(int j=0; j<NofEbins; j++){ for(int ntel=0; ntel<kMaxTels; ntel++){ sprintf( title, "h1%s_%s_Ebin%d_tel%d_%s", NameOfParamsTel[i].c_str(), runType1.c_str(), j, ntel+1, NameOfType[reportTypeId].c_str()); h1ParamsPerTel1[i][j][ntel][reportTypeId] = (TH1F*)rfin1->Get( title ); h1ParamsPerTel1[i][j][ntel][reportTypeId]->SetLineColor(kBlack); if( j == 0 ){ sprintf( title, "h1%s_%s_tel%d_%s", NameOfParamsTel[i].c_str(), runType1.c_str(), ntel+1, NameOfType[reportTypeId].c_str()); h1ParamsPerTelCombined1[i][ntel][reportTypeId] = (TH1F*)h1ParamsPerTel1[i][j][ntel][reportTypeId]->Clone(title); } else { h1ParamsPerTelCombined1[i][ntel][reportTypeId]->Add( h1ParamsPerTel1[i][j][ntel][reportTypeId], 1 ); } sprintf( title, "h1%s_%s_Ebin%d_tel%d_%s", NameOfParamsTel[i].c_str(), runType2.c_str(), j, ntel+1, NameOfType[reportTypeId].c_str()); h1ParamsPerTel2[i][j][ntel][reportTypeId] = (TH1F*)rfin2->Get( title ); h1ParamsPerTel2[i][j][ntel][reportTypeId]->SetMarkerStyle(25); h1ParamsPerTel2[i][j][ntel][reportTypeId]->SetMarkerColor(col2); h1ParamsPerTel2[i][j][ntel][reportTypeId]->SetLineColor(col2); if( j == 0 ){ sprintf( title, "h1%s_%s_tel%d_%s", NameOfParamsTel[i].c_str(), runType2.c_str(), ntel+1, NameOfType[reportTypeId].c_str()); h1ParamsPerTelCombined2[i][ntel][reportTypeId] = (TH1F*)h1ParamsPerTel2[i][j][ntel][reportTypeId]->Clone(title); } else { h1ParamsPerTelCombined2[i][ntel][reportTypeId]->Add( h1ParamsPerTel2[i][j][ntel][reportTypeId], 1 ); } if( rebin > 1 ){ h1ParamsPerTel1[i][j][ntel][reportTypeId]->Rebin( rebin ); h1ParamsPerTel2[i][j][ntel][reportTypeId]->Rebin( rebin ); if( j == 0 ){ h1ParamsPerTel1[i][j][ntel][reportTypeId]->Rebin( rebin ); h1ParamsPerTel2[i][j][ntel][reportTypeId]->Rebin( rebin ); } } } } } } } if( paramIdToPlot == - 9 ){ cout <<"couldn't find the parameter " << paramToPlot << endl; return ; } double norm1, norm2; double value; for(int i=0; i<NofEbins; i++){ norm1 = 0; norm2 = 0; if( showerParameter ){ if( doNormalizedArea ){ for(int n=1; n<=h1Params1[paramIdToPlot][i][reportTypeId]->GetNbinsX(); n++) norm1 += h1Params1[paramIdToPlot][i][reportTypeId]-> GetBinContent(n); for(int n=1; n<=h1Params2[paramIdToPlot][i][reportTypeId]->GetNbinsX(); n++) norm2 += h1Params2[paramIdToPlot][i][reportTypeId]-> GetBinContent(n); } else { norm1 = h1Params1[paramIdToPlot][i][reportTypeId]->GetMaximum(); norm2 = h1Params2[paramIdToPlot][i][reportTypeId]->GetMaximum(); } cout <<norm1 <<" " << norm2 <<endl; for(int n=1; n<=h1Params1[paramIdToPlot][i][reportTypeId]->GetNbinsX(); n++){ if( norm1 > 0 ){ h1Params1[paramIdToPlot][i][reportTypeId]->SetBinContent(n, h1Params1[paramIdToPlot][i][reportTypeId]->GetBinContent(n)/(norm1)); if( h1Params1[paramIdToPlot][i][reportTypeId]->GetBinError(n)/(norm1) > 1e-4 ) h1Params1[paramIdToPlot][i][reportTypeId]->SetBinError(n, h1Params1[paramIdToPlot][i][reportTypeId]->GetBinError(n)/(norm1)); } } for(int n=1; n<=h1Params2[paramIdToPlot][i][reportTypeId]->GetNbinsX(); n++){ if( norm2 > 0 ){ h1Params2[paramIdToPlot][i][reportTypeId]->SetBinContent(n, h1Params2[paramIdToPlot][i][reportTypeId]->GetBinContent(n)/(norm2)); if( h1Params2[paramIdToPlot][i][reportTypeId]->GetBinError(n)/(norm1)>1e-4 ) h1Params2[paramIdToPlot][i][reportTypeId]->SetBinError(n, h1Params2[paramIdToPlot][i][reportTypeId]->GetBinError(n)/(norm2)); } } } else { for(int ntel=0; ntel<kMaxTels; ntel ++){ norm1 = 0; if( doNormalizedArea ){ for(int n=1; n<=h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->GetNbinsX(); n++) norm1 += h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->GetBinContent(n); } else { } for(int n=1; n<h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->GetNbinsX(); n++){ if( norm1 > 0 ){ h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId] ->SetBinContent(n, h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->GetBinContent(n)/(norm1)); if( h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->GetBinError(n)/(norm1) > 1e-4 ){ h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId] ->SetBinError(n, h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->GetBinError(n)/(norm1)); } } } if( i == 0 ){ norm1 = 0; for(int n=1; n<=h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId]->GetNbinsX(); n++) norm1 += h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId]->GetBinContent(n); for(int n=1; n<h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId]->GetNbinsX(); n++){ if( norm1 > 0 ){ h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId] ->SetBinContent(n, h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId]->GetBinContent(n)/(norm1)); if( h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId]->GetBinError(n)/(norm1) > 1e-4 ){ h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId] ->SetBinError(n, h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId]->GetBinError(n)/(norm1)); } } } norm2 = 0; for(int n=1; n<=h1ParamsPerTelCombined2[paramIdToPlot][ntel][reportTypeId]->GetNbinsX(); n++) norm2 += h1ParamsPerTelCombined2[paramIdToPlot][ntel][reportTypeId]->GetBinContent(n); for(int n=1; n<h1ParamsPerTelCombined2[paramIdToPlot][ntel][reportTypeId]->GetNbinsX(); n++){ if( norm2 > 0 ){ h1ParamsPerTelCombined2[paramIdToPlot][ntel][reportTypeId] ->SetBinContent(n, h1ParamsPerTelCombined2[paramIdToPlot][ntel][reportTypeId]->GetBinContent(n)/(norm2)); if( h1ParamsPerTelCombined2[paramIdToPlot][ntel][reportTypeId]->GetBinError(n)/(norm2) > 1e-4 ){ h1ParamsPerTelCombined2[paramIdToPlot][ntel][reportTypeId] ->SetBinError(n, h1ParamsPerTelCombined2[paramIdToPlot][ntel][reportTypeId]->GetBinError(n)/(norm2)); } } } } norm2 = 0; if( doNormalizedArea ){ for(int n=1; n<=h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId]->GetNbinsX(); n++) norm2 += h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId]->GetBinContent(n); } else { norm2 = h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId]->GetMaximum(); } for(int n=1; n<h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId]->GetNbinsX(); n++){ if(norm2 > 0 ){ h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId] ->SetBinContent(n, h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId]->GetBinContent(n)/(norm2)); if( h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId]->GetBinError(n)/(norm2) > 1 ) h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId] ->SetBinError(n, h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId]->GetBinError(n)/(norm2)); } } } } } TCanvas *can[kMaxTels]; TCanvas *canResFrac[kMaxTels]; TBox *box = new TBox(); box->SetFillColor(col2); box->SetFillStyle(3002); int maxVBin; if( showerParameter ) { can[0] = new TCanvas("can0","can0", 1200, 800); can[0]->SetFillColor(10); can[0]->Divide(3,2); canResFrac[0] = new TCanvas("canResFrac0","canResFrac0", 1200, 800); canResFrac[0]->SetFillColor(10); canResFrac[0]->Divide(3,2); for(int i=0; i<NofEbins; i++){ can[0]->cd(i+1); gPad->SetGrid(); h1Params1[paramIdToPlot][i][reportTypeId]->Draw("p"); h1Params1[paramIdToPlot][i][reportTypeId]->GetYaxis()->SetRangeUser(yaxis_min, yaxis_max); h1Params2[paramIdToPlot][i][reportTypeId]->Draw("psames"); canResFrac[0]->cd(i+1); gPad->SetGrid(); sprintf( title, "h1%s_%s_Ebin%d_%s_ResFrac", NameOfParams[paramIdToPlot].c_str(), runType1.c_str(), i, NameOfType[reportTypeId].c_str() ); TH1F *tmp = (TH1F*)h1Params1[paramIdToPlot][i][reportTypeId]->Clone( title ); tmp->Add( h1Params1[paramIdToPlot][i][reportTypeId], h1Params2[paramIdToPlot][i][reportTypeId], -1, 1 ); tmp->Divide( h1Params1[paramIdToPlot][i][reportTypeId] ); sprintf( title, "%s (%s-%s)/%s, Ebin%d", NameOfParams[paramIdToPlot].c_str(), runType2.c_str(), runType1.c_str(), runType1.c_str(), i); tmp->SetTitle( title ); tmp->Draw("p"); tmp->GetYaxis()->SetRangeUser(-2,2); maxVBin = h1Params1[paramIdToPlot][i][reportTypeId]->GetMaximumBin(); box->DrawBox( tmp->GetBinCenter(maxVBin-3), -1, tmp->GetBinCenter(maxVBin+3) , 1); gPad->Modified(); gPad->Update(); } } else { for(int ntel=0; ntel<kMaxTels; ntel++){ sprintf( title, "can%d", ntel+1); can[ntel] = new TCanvas( title, title, 0, 0, 1200, 800); can[ntel]->SetFillColor(10); can[ntel]->Divide(3,2); sprintf( title, "canResFrac%d", ntel+1); canResFrac[ntel] = new TCanvas( title, title, 0, 0, 1200, 800); canResFrac[ntel]->SetFillColor(10); canResFrac[ntel]->Divide(3,2); for(int i=0; i<NofEbins; i++){ can[ntel]->cd(i+1); gPad->SetGrid(); if( paramToPlot.compare("SizeFracLo") == 0 || paramToPlot.compare("Size") == 0 || paramToPlot.compare("NTube") == 0 || paramToPlot.compare("Max3") == 0 ){ h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->GetYaxis()->SetRangeUser(yaxis_min, yaxis_max); gPad->SetLogy(); } h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->Draw("p"); if( paramToPlot.compare("ImpactDist") == 0 || paramToPlot.compare("Width") == 0 || paramToPlot.compare("Length") == 0 ){ h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->GetYaxis()->SetRangeUser(yaxis_min, yaxis_max); } h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId]->Draw("psames"); maxVBin = h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->GetMaximumBin(); canResFrac[ntel]->cd(i+1); gPad->SetGrid(); sprintf( title, "h1%s_%s_Ebin%d_tel%d_%s_ResFrac", NameOfParamsTel[paramIdToPlot].c_str(), runType1.c_str(), i, ntel+1, NameOfType[reportTypeId].c_str() ); TH1F *tmp = (TH1F*)h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId]->Clone( title ); tmp->Add( h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId], h1ParamsPerTel2[paramIdToPlot][i][ntel][reportTypeId], -1, 1 ); tmp->Divide( h1ParamsPerTel1[paramIdToPlot][i][ntel][reportTypeId] ); sprintf( title, "%s (%s-%s)/%s, Ebin%d Tel%d", NameOfParamsTel[paramIdToPlot].c_str(), runType2.c_str(), runType1.c_str(), runType1.c_str(), i, ntel+1 ); tmp->SetTitle( title ); tmp->Draw("p"); tmp->GetYaxis()->SetRangeUser(-2,2); box->DrawBox( tmp->GetBinCenter(maxVBin-3), -1, tmp->GetBinCenter(maxVBin+3) , 1); gPad->Modified(); gPad->Update(); } } TCanvas *c2 = new TCanvas("c2","c2",800,800); c2->Divide(2,2); for(int ntel = 0; ntel<kMaxTels; ntel++){ c2->cd(ntel+1); gPad->SetGrid(); if( paramToPlot.compare("SizeFracLo") == 0 || paramToPlot.compare("Size") == 0 || paramToPlot.compare("NTube") == 0 || paramToPlot.compare("Max3") == 0 ){ h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId]->GetYaxis()->SetRangeUser(yaxis_min, yaxis_max); gPad->Modified(); gPad->SetLogy(); } h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId]->Draw("p"); if( paramToPlot.compare("ImpactDist") == 0 || paramToPlot.compare("Width") == 0 || paramToPlot.compare("Length") == 0 ){ h1ParamsPerTelCombined1[paramIdToPlot][ntel][reportTypeId]->GetYaxis()->SetRangeUser(yaxis_min, yaxis_max); } h1ParamsPerTelCombined2[paramIdToPlot][ntel][reportTypeId]->Draw("psames"); } } }
int main() { Int_t nbins = 800, count = 0; Double_t integral; TFile *input = new TFile("FilterRMSComparison.root"); TFile *templatefile = new TFile("/home/marko/Desktop/H4Analysis/ntuples/Templates_APDs.old.root"); TTree *MyTree = (TTree*) input->Get("RMS"); TCanvas *can1 = new TCanvas("can1", "canvas", 1200,900); TCanvas *can2 = new TCanvas("can2", "canvas", 1200,1200); TCanvas *can3 = new TCanvas("can3", "canvas", 1200,1200); can1->Divide(1,3); can2->Divide(1,2); can3->Divide(1,2); MyTree->SetEntryList(0); TString listcut = "abs(unfilteredbslope)<6 && unfilteredampfit>700"; MyTree->Draw(">>myList", listcut, "entrylist"); TEntryList *myList = (TEntryList*) gDirectory->Get("myList"); MyTree->SetEntryList(myList); Int_t nevents = myList->GetN(); MyTree->Draw("unfilteredevent", "abs(unfilteredbslope)<6 && unfilteredampfit>700", "goff"); Double_t *vTemp = MyTree->GetV1(); Int_t *vEvent = new Int_t[nevents]; for (int iEntry = 0; iEntry<nevents; iEntry++) { vEvent[iEntry] = vTemp[iEntry]; } TString plot, plot2, cut; char name[50]; TH1F *histoave = new TH1F("histoave","Wave Pulse Average", nbins, -40, 120); TH1F *histoavefft = new TH1F("histoavefft","Wave Pulse Average FFT", nbins, 0, 5); TH1F *histoaveph = new TH1F("histoaveph","Wave Pulse Average Phase", nbins, 0, 800); TH1F *originaltemplate = (TH1F*) templatefile->Get("APD2_E50_G50_prof"); originaltemplate->Rebin(16); TH1F *templatehisto = new TH1F("templatehisto", "Template = Green, Average = Red", nbins, -40, 120); TH1F *difference = new TH1F("difference","Template vs. Average Difference", nbins, -40, 120); TH1F *percentdifference = new TH1F("percentdifference","Template vs. Average Percent Difference", nbins, -40, 120); for (Int_t i=0;i<nbins;i++) { templatehisto->SetBinContent(i+1, originaltemplate->GetBinContent(i+1)); } templatehisto->SetLineColor(kGreen+3); templatehisto->SetLineWidth(4); can2->cd(2); histoave->GetYaxis()->SetRangeUser(-.120,1.2); //templatehisto->Draw(); histoave->SetStats(0); histoave->Draw(); for (Int_t i=0;i<nevents;i++) { //for (Int_t i=0;i<10;i++) { if (vEvent[i]==513) continue; //event for which electronics die out for a bit halfway through TString histoname = "TempHisto_"; histoname += i; TString histoname2 = "TempHisto2_"; histoname2 += i; TH2F* TempHisto = new TH2F (histoname, "Temp Histo", nbins, -40, 120, 1000, -120, 800); //nanoseconds TH2F* TempHisto2 = new TH2F (histoname2, "Temp Histo", nbins, -40, 120, 1000, -120, 800); //nanoseconds TString h1name = "h1001_"; h1name += i; TString h1name2 = "h1002_"; h1name2 += i; TString h1name2fft = "h1002fft_"; h1name2 += i; TString h1name2ph = "h1002ph_"; h1name2 += i; TString h1name3 = "h1003_"; h1name3 += i; TString h1name4 = "h1004_"; h1name4 += i; TH1F *h1001 = new TH1F(h1name,"Red = Unfiltered, Blue = Filtered", nbins, -40, 120); TH1F *h1002 = new TH1F(h1name2,"h1002", nbins, -40, 120); TH1F *h1002fft = new TH1F(h1name2fft,"h1002fft", nbins, 0, 5); TH1F *h1002ph = new TH1F(h1name2ph,"h1002ph", nbins, 0, 800); TH1F *h1003 = new TH1F(h1name3,"Filtered WF - Unfiltered WF", nbins, -40, 120); TH1F *h1004 = new TH1F(h1name4,"Percent Change in Filtered WF - Unfiltered WF", nbins, -40, 120); plot = "unfilteredwfval:(unfilteredwftime-unfilteredtimeref)>>"; plot += histoname; plot2 = "filteredwfval:(filteredwftime-filteredtimeref)>>"; plot2 += histoname2; cut = "abs(unfilteredbslope)<6 && unfilteredampfit>700 && unfilteredevent=="; cut += vEvent[i]; MyTree->Draw(plot, cut, "goff"); TempHisto = (TH2F*) gDirectory->Get(histoname); h1001 = transform2Dto1D(TempHisto); MyTree->Draw(plot2, cut, "goff"); TempHisto2 = (TH2F*) gDirectory->Get(histoname2); h1002 = transform2Dto1D(TempHisto2); if (h1002->GetBinCenter(h1002->GetMaximumBin()) < 30) continue; sprintf(name, "Good Events/Event%d", vEvent[i]); strcat(name, ".png"); h1001->SetLineColor(kRed); h1002->SetLineColor(kBlue); h1001->SetStats(0); h1002->SetStats(0); //can1->cd(1); can1->cd(); h1001->GetXaxis()->SetTitle("Time (ns)"); h1001->GetYaxis()->SetTitle("Amplitude"); h1001->Draw(); h1002->Draw("same"); //for (Int_t i=0;i<nbins;i++) { // h1003->SetBinContent(i+1, (h1002->GetBinContent(i+1))-(h1001->GetBinContent(i+1))); // if (h1001->GetBinContent(i+1) != 0) h1004->SetBinContent(i+1, ((h1002->GetBinContent(i+1))-(h1001->GetBinContent(i+1)))/(h1001->GetBinContent(i+1))); // else h1004->SetBinContent(i+1, 0); //} //can1->cd(2); //h1003->Draw(); //can1->cd(3); //h1004->Draw(); //h1004->GetYaxis()->SetRangeUser(-0.1,0.1); //gPad->SetGrid(); can1->SaveAs(name); //h1002->FFT(h1002fft, "MAG"); //h1002->FFT(h1002ph, "PH"); //histoavefft->Add(histoavefft, h1002fft); //histoaveph->Add(histoaveph, h1002ph); histoave->Add(histoave, h1002); can2->cd(2); h1002->Scale(1./(h1002->GetMaximum())); h1002->Draw("same"); count++; delete TempHisto, TempHisto2, h1001, h1002, h1003, h1004, histoname, histoname2, h1name, h1name2, h1name3, h1name4; gDirectory->Clear(); } can2->cd(1); //histoavefft->Scale(1./count); //histoaveph->Scale(1./count); histoave->Scale(1./count); //Double_t *re_full = new Double_t[nbins]; //Double_t *im_full = new Double_t[nbins]; //TH1 *Throwaway = 0; //TH1F *invhistoave = new TH1F(invhistoave, "Average Pulse", nbins, -40, 120); //TVirtualFFT *invFFT = TVirtualFFT::FFT(1, &nbins, "C2R M K"); //for (Int_t n=0; n<nbins; n++) { // (re_full)[n]=(histoavefft->GetBinContent(n+1)*cos(histoaveph->GetBinContent(n+1))); // (im_full)[n]=(histoavefft->GetBinContent(n+1)*sin(histoaveph->GetBinContent(n+1))); //} //invFFT->SetPointsComplex(re_full, im_full); //invFFT->Transform(); //Throwaway = TH1::TransformHisto(invFFT, Throwaway, "Re"); //for (Int_t p=0; p<nbins; p++) { // histoave->SetBinContent(p+1, Throwaway->GetBinContent(p+1)/nbins); //} histoave->Scale(1./(histoave->GetMaximum())); histoave->SetLineColor(kRed); histoave->SetLineWidth(4); integral = templatehisto->Integral(); templatehisto->Scale(1./integral); templatehisto->SetStats(0); templatehisto->Draw(); integral = histoave->Integral(); histoave->Scale(1./integral); histoave->DrawClone("same"); histoave->Scale(integral); can2->cd(2); histoave->GetXaxis()->SetTitle("Time (ns)"); histoave->GetYaxis()->SetTitle("Normalized Amplitude"); histoave->DrawClone("same"); can2->SaveAs("AmpSpread.png"); can2->SaveAs("AmpSpreadRoot.root"); TFile *output = new TFile("Alignment.root", "recreate"); output->cd(); originaltemplate->Write(); histoave->Write(); templatehisto->Write(); output->Close(); can3->cd(1); histoave->Scale(1./integral); for (int i=0;i<nbins;i++) { difference->SetBinContent(i+1, histoave->GetBinContent(i+1) - templatehisto->GetBinContent(i+1)); if (templatehisto->GetBinContent(i+1) != 0) percentdifference->SetBinContent(i+1, (histoave->GetBinContent(i+1) - templatehisto->GetBinContent(i+1))/templatehisto->GetBinContent(i+1)); else percentdifference->SetBinContent(i+1, 0); } difference->GetXaxis()->SetTitle("Time (ns)"); difference->GetYaxis()->SetTitle("Average - Template"); difference->SetStats(0); difference->Draw(); can3->cd(2); percentdifference->GetXaxis()->SetTitle("Time (ns)"); percentdifference->GetYaxis()->SetTitle("Percent Difference Average - Template"); percentdifference->SetStats(0); percentdifference->Draw(); percentdifference->GetYaxis()->SetRangeUser(-0.1,0.1); gPad->SetGrid(); can3->SaveAs("Difference.png"); can3->SaveAs("Difference.root"); }
void HPhiWeight(const char* FileName="test") { // Set Style parameters for this macro gStyle->SetOptTitle(1); // Show Title (off by default for cleanliness) // Open ROOT File char name[1000]; sprintf(name,"/Users/zach/Research/rootFiles/july2015/%s.root",FileName); TFile *f = new TFile(name,"READ"); if (f->IsOpen()==kFALSE) { std::cout << "!!! File Not Found !!!" << std::endl; exit(1); } // f->ls(); // - DEBUG by printing all objects in ROOT file TH1F * LSIM[20]; TH1F * USIM[20]; TH1F * INCL[20]; TCanvas * c[4]; TCanvas * IN[4]; for(Int_t trig = 0; trig < 4; trig++){ // Create and Segment Canvas c[trig] = new TCanvas(Form("c%i",trig),"Photonic Hists",0,0,900,500); IN[trig]= new TCanvas(Form("IN%i",trig),"Inclusive Hists",0,0,900,500); c[trig] -> Divide(3,2); IN[trig]-> Divide(3,2); c[trig] -> Update(); IN[trig]-> Update(); for(Int_t ptbin = 0; ptbin < 5; ptbin++){ Int_t counter = 5*trig+ptbin; c[trig]->cd(ptbin+1); // Grab Histograms for manipulation (can draw without Get, must Get for manip) LSIM[counter] = (TH1F*)f->Get(Form("projDelPhiPhotLS_%i_%i",ptbin,trig)); // Like Sign Delta Phi (Photonic Electrons) USIM[counter] = (TH1F*)f->Get(Form("projDelPhiPhotUS_%i_%i",ptbin,trig)); // Unlike Sign Delta Phi (Photonic Electrons) INCL[counter] = (TH1F*)f->Get(Form("projDelPhiIncl_%i_%i",ptbin,trig)); // Inclusive Delta Phi eh // Actually manipulate histos and plot USIM[counter]->SetLineColor(kRed); USIM[counter]->SetLineWidth(1); USIM[counter]->GetXaxis()->SetTitle("#Delta#phi_{eh}"); USIM[counter]->GetXaxis()->SetRangeUser(0,4); if(ptbin == 0) USIM[counter]->SetTitle("Photonic Electron Reconstruction"); else if (ptbin == 1 && trig !=3) USIM[counter]->SetTitle(Form("HT%i",trig)); else if (trig == 3 && ptbin == 1) USIM[counter]->SetTitle("MB"); else USIM[counter]->SetTitle(""); USIM[counter]->Draw("hist"); LSIM[counter]->SetLineColor(kBlack); LSIM[counter]->SetLineWidth(1); LSIM[counter]->Draw("hist same"); // Subtraction of (US-LS) TH1F *SUB = (TH1F*)USIM[counter]->Clone(); // SUB->SetName("Subtraction"); // Create SUB as a clone of USIM SUB->Add(LSIM[counter],-1); SUB->SetLineColor(kBlue); SUB->SetLineWidth(1); SUB->SetFillStyle(3001); SUB->SetFillColor(kBlue); SUB->Draw("hist same"); TLegend* leg = new TLegend(0.7,0.7,0.85,0.85); leg->AddEntry(USIM[counter],"Unlike Sign","l"); leg->AddEntry(LSIM[counter],"Like Sign", "l"); leg->AddEntry(SUB,"Unlike - Like", "f"); leg->Draw(); c[trig]->Update(); // Handle Inclusive Hists IN[trig]->cd(ptbin+1); INCL[counter]->SetLineColor(kBlue); INCL[counter]->SetLineWidth(1); INCL[counter]->GetXaxis()->SetTitle("#Delta#phi_{eh}"); INCL[counter]->GetXaxis()->SetRangeUser(0,4); if(ptbin == 0) INCL[counter]->SetTitle("Semi-Inclusive Electrons"); else if (ptbin == 1 && trig !=3) INCL[counter]->SetTitle(Form("HT%i",trig)); else if (trig == 3 && ptbin == 1) INCL[counter]->SetTitle("MB"); else INCL[counter]->SetTitle(""); INCL[counter]->Draw("hist"); IN[trig]->Update(); } } // Close ROOT File //f->Close(); //delete f; // Make PDF if Desired //c1->Print("c1.pdf","pdf"); }
void HTT_MM_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="mumu_$CATEGORY") { // define common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category_extra = ""; if(std::string(directory) == std::string("mumu_0jet_low" )){ category_extra = "0 jet, low p_{T}"; } if(std::string(directory) == std::string("mumu_0jet_high" )){ category_extra = "0 jet, high p_{T}"; } if(std::string(directory) == std::string("mumu_boost_low" )){ category_extra = "1 jet, low p_{T}"; } if(std::string(directory) == std::string("mumu_boost_high")){ category_extra = "1 jet, high p_{T}"; } if(std::string(directory) == std::string("mumu_vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(directory) == std::string("mumu_nobtag" )){ category_extra = "No B-Tag"; } if(std::string(directory) == std::string("mumu_btag" )){ category_extra = "B-Tag"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 18.7 fb^{-1} at 8 TeV";} #ifdef MSSM if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 12.1 fb^{-1} at 8 TeV";} #endif TFile* input = new TFile(inputfile); TH1F* ZTT = refill((TH1F*)input->Get(TString::Format("%s/ZTT" , directory)), "ZTT"); InitHist(ZTT, "", "", kOrange-4, 1001); TH1F* ZMM = refill((TH1F*)input->Get(TString::Format("%s/ZMM" , directory)), "ZMM"); InitHist(ZMM , "", "", kAzure+2, 1001); TH1F* TTJ = refill((TH1F*)input->Get(TString::Format("%s/TTJ" , directory)), "TTJ"); InitHist(TTJ, "", "", kBlue-8, 1001); TH1F* QCD = refill((TH1F*)input->Get(TString::Format("%s/QCD" , directory)), "QCD"); InitHist(QCD , "", "", kMagenta - 10, 1001); TH1F* Dibosons = refill((TH1F*)input->Get(TString::Format("%s/Dibosons" , directory)), "Dibosons"); InitHist(Dibosons, "", "", kGreen - 4, 1001); TH1F* WJets = refill((TH1F*)input->Get(TString::Format("%s/WJets" , directory)), "WJets"); InitHist(WJets , "", "", kRed + 2, 1001); #ifdef MSSM float ggHScale = 1., bbHScale = 1.; ggHScale = ($MSSM_SIGNAL_ggH_xseff_A + $MSSM_SIGNAL_ggH_xseff_hH); bbHScale = ($MSSM_SIGNAL_bbH_xseff_A + $MSSM_SIGNAL_bbH_xseff_hH); // float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=20, A + H for the time being // if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = (9157.49*0.119 + 10180.7*0.120)/1000.; // bbHScale = (23314.3*0.119 + 21999.3*0.120)/1000.; } // if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (11815.3*0.119 + 13124.9*0.120)/1000.; // bbHScale = (31087.9*0.119 + 29317.8*0.120)/1000.; } // float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=10, A + H for the time being // if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = (2111.4*0.11 + 4022.9*0.11)/1000.; // bbHScale = (6211.6*0.11 + 5147.0*0.11)/1000.; } // if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (2729.9*0.11 + 5193.2*0.11)/1000.; // bbHScale = (8282.7*0.11 + 6867.8*0.11)/1000.; } TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH160" , directory)), "ggH" ); InitSignal(ggH); ggH->Scale(ggHScale); TH1F* bbH = refill((TH1F*)input->Get(TString::Format("%s/bbH160" , directory)), "bbH" ); InitSignal(bbH); bbH->Scale(bbHScale); #else #ifndef DROP_SIGNAL TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH125" , directory)), "ggH" ); InitSignal(ggH); ggH->Scale(SIGNAL_SCALE); TH1F* qqH = refill((TH1F*)input->Get(TString::Format("%s/qqH125" , directory)), "qqH" ); InitSignal(qqH); qqH->Scale(SIGNAL_SCALE); TH1F* VH = refill((TH1F*)input->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH ->Scale(SIGNAL_SCALE); #endif #endif TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)ZTT->Clone("ref"); ref->Add(ZMM ); ref->Add(TTJ); ref->Add(QCD ); ref->Add(Dibosons); ref->Add(WJets ); double unscaled[9]; unscaled[0] = ZTT->Integral(); unscaled[1] = ZMM ->Integral(); unscaled[2] = TTJ->Integral(); unscaled[3] = QCD ->Integral(); unscaled[4] = Dibosons ->Integral(); unscaled[5] = WJets ->Integral(); #ifdef MSSM unscaled[6] = ggH ->Integral(); unscaled[7] = bbH ->Integral(); unscaled[8] = 0; #else #ifndef DROP_SIGNAL unscaled[6] = ggH ->Integral(); unscaled[7] = qqH ->Integral(); unscaled[8] = VH ->Integral(); #endif #endif if(scaled){ rescale(ZTT, 1); rescale(ZMM, 2); rescale(TTJ, 3); rescale(QCD, 4); rescale(Dibosons, 5); rescale(WJets, 6); #ifdef MSSM rescale(ggH, 7); rescale(bbH, 8); #else #ifndef DROP_SIGNAL rescale(ggH, 7); rescale(qqH, 8); rescale(VH, 9); #endif #endif } TH1F* scales[9]; scales[0] = new TH1F("scales-ZTT", "", 9, 0, 9); scales[0]->SetBinContent(1, unscaled[0]>0 ? (ZTT->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-ZMM" , "", 9, 0, 9); scales[1]->SetBinContent(2, unscaled[1]>0 ? (ZMM ->Integral()/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-TTJ", "", 9, 0, 9); scales[2]->SetBinContent(3, unscaled[2]>0 ? (TTJ->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-QCD" , "", 9, 0, 9); scales[3]->SetBinContent(4, unscaled[3]>0 ? (QCD ->Integral()/unscaled[3]-1.) : 0.); scales[4] = new TH1F("scales-Dibosons", "", 9, 0, 9); scales[4]->SetBinContent(5, unscaled[4]>0 ? (Dibosons->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-WJets" , "", 9, 0, 9); scales[5]->SetBinContent(6, unscaled[5]>0 ? (WJets ->Integral()/unscaled[5]-1.) : 0.); #ifdef MSSM scales[6] = new TH1F("scales-ggH" , "", 9, 0, 9); scales[6]->SetBinContent(7, unscaled[6]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[7] = new TH1F("scales-bbH" , "", 9, 0, 9); scales[7]->SetBinContent(8, unscaled[7]>0 ? (bbH ->Integral()/unscaled[5]-1.) : 0.); scales[8] = new TH1F("scales-NONE" , "", 9, 0, 9); scales[8]->SetBinContent(9, 0.); #else #ifndef DROP_SIGNAL scales[6] = new TH1F("scales-ggH" , "", 9, 0, 9); scales[6]->SetBinContent(7, unscaled[6]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[7] = new TH1F("scales-qqH" , "", 9, 0, 9); scales[7]->SetBinContent(8, unscaled[7]>0 ? (qqH ->Integral()/unscaled[5]-1.) : 0.); scales[8] = new TH1F("scales-VH" , "", 9, 0, 9); scales[8]->SetBinContent(9, unscaled[8]>0 ? (VH ->Integral()/unscaled[6]-1.) : 0.); #endif #endif ZMM->Add(ZTT); QCD->Add(ZMM); TTJ->Add(QCD); Dibosons->Add(TTJ); WJets->Add(Dibosons); if(log){ #ifdef MSSM ggH ->Add(bbH); #else #ifndef DROP_SIGNAL qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } else{ #ifdef MSSM bbH ->Add(WJets); ggH ->Add(bbH); #else #ifndef DROP_SIGNAL VH ->Add(WJets); qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } /* mass plot before and after fit */ TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(350)); #endif data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(WJets, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)WJets ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ WJets->Draw("histsame"); //Dibosons->Draw("histsame"); TTJ->Draw("histsame"); QCD->Draw("histsame"); ZMM->Draw("histsame"); ZTT->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ggH->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif WJets->Draw("histsame"); //Dibosons->Draw("histsame"); TTJ->Draw("histsame"); QCD->Draw("histsame"); ZMM->Draw("histsame"); ZTT->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{#mu}#tau_{#mu}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText("#mu#mu"); chan->Draw(); TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); #ifdef MSSM TPaveText* massA = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m_{A}=160GeV"); massA->Draw(); TPaveText* tanb = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC"); tanb->SetBorderSize( 0 ); tanb->SetFillStyle( 0 ); tanb->SetTextAlign( 12 ); tanb->SetTextSize ( 0.03 ); tanb->SetTextColor( 1 ); tanb->SetTextFont ( 62 ); tanb->AddText("tan#beta=20"); tanb->Draw(); TPaveText* scen = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC"); scen->SetBorderSize( 0 ); scen->SetFillStyle( 0 ); scen->SetTextAlign( 12 ); scen->SetTextSize ( 0.03 ); scen->SetTextColor( 1 ); scen->SetTextFont ( 62 ); scen->AddText("mhmax"); scen->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.45, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggH , "#phi#rightarrow#tau#tau" , "L" ); #else TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90); SetLegendStyle(leg); #ifndef DROP_SIGNAL if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ leg->AddEntry(ggH , "H(125 GeV)#rightarrow#tau#tau" , "L" ); } #endif #endif leg->AddEntry(data , "observed" , "LP"); leg->AddEntry(ZTT , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ZMM , "Z#rightarrow#mu#mu" , "F" ); leg->AddEntry(TTJ , "t#bar{t}" , "F" ); leg->AddEntry(QCD , "QCD" , "F" ); //leg->AddEntry(Dibosons , "Dibosons" , "F" ); leg->AddEntry(WJets, "electroweak" , "F" ); $ERROR_LEGEND leg->Draw(); //#ifdef MSSM // TPaveText* mssm = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("(m_{A}=120, tan#beta=10)"); // mssm->Draw(); //#else // TPaveText* mssm = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("m_{H}=125"); // mssm->Draw(); //#endif /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat"); rat1->Divide(WJets); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } zero->SetBinContent(ibin+1, 0.); } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+0.5); rat1->SetMinimum(-0.5); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat1->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv0->RedrawAxis(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); TH1F* rat2 = (TH1F*) WJets->Clone("rat2"); rat2->Divide(ref); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } rat2->SetLineColor(kRed+ 3); rat2->SetFillColor(kRed-10); rat2->SetMaximum(+0.3); rat2->SetMinimum(-0.3); rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat2->GetXaxis()->SetRange(0, 28); rat2->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", kGreen - 4, 1001); InitHist (scales[1], "", "", kYellow - 4, 1001); InitHist (scales[2], "", "", kMagenta-10, 1001); InitHist (scales[3], "", "", kRed + 2, 1001); InitHist (scales[4], "", "", kBlue - 8, 1001); InitHist (scales[5], "", "", kOrange - 4, 1001); #ifndef DROP_SIGNAL InitSignal(scales[6]); InitSignal(scales[7]); InitSignal(scales[8]); #endif scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{ZTT}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{ZMM}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{TTJ}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{QCD}" ); scales[0]->GetXaxis()->SetBinLabel(5, "#bf{Dibosons}"); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{WJets}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(7, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(8, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(9, "#bf{NONE}" ); #else scales[0]->GetXaxis()->SetBinLabel(7, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(8, "#bf{qqH}" ); scales[0]->GetXaxis()->SetBinLabel(9, "#bf{VH}" ); #endif scales[0]->SetMaximum(+1.5); scales[0]->SetMinimum(-1.5); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); scales[4]->Draw("same"); scales[5]->Draw("same"); #ifndef DROP_SIGNAL scales[6]->Draw("same"); scales[7]->Draw("same"); scales[8]->Draw("same"); #endif zero->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sscaled_%s_%s.png" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.pdf" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.eps" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); TFile* output = new TFile(TString::Format("%s_%sscaled_%s_%s.root", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update"); output->cd(); data ->Write("data_obs"); ZTT->Write("Ztt" ); ZMM->Write("Zmm" ); TTJ->Write("ttbar" ); QCD->Write("Fakes" ); Dibosons->Write("Dibosons" ); WJets->Write("EWK" ); #ifdef MSSM ggH ->Write("ggH" ); bbH ->Write("bbH" ); #else #ifndef DROP_SIGNAL ggH ->Write("ggH" ); qqH ->Write("qqH" ); VH ->Write("VH" ); #endif #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); }
void ppb_merge(){ TStopwatch timer; timer.Start(); //Float_t N_mb = Lumi_ppb*sigma_inelastic*1000; //Float_t Lumi_ppb = 30.9;// inverse micro barns //Float_t sigma_inelastic = 70.0;//milli barns TH1::SetDefaultSumw2(); TString inname1 = "root://eoscms//eos/cms/store/group/phys_heavyions/yjlee/pPb2013/promptReco/PA2013_HiForest_PromptReco_JSonPPb_forestv77.root"; TString inname2 = "root://eoscms//eos/cms/store/group/phys_heavyions/krajczar/inbound/mnt/hadoop/cms/store/user/krajczar/pPb_Jet40Jet60_Full_v1/mergedJet40Jet60_KK.root"; TFile *f1 = TFile::Open(inname1); TFile *f2 = TFile::Open(inname2); cout<<" File for HLT_100 HLT_80 = "<<inname1<<endl; cout<<" File for HLT_60 HLT_40 = "<<inname2<<endl; TFile *outfile = new TFile("pPbmerged_output.root","RECREATE"); TTree* jet_80 = (TTree*)f1->Get("akPu3PFJetAnalyzer/t"); TTree* jet_80_hlt = (TTree*)f1->Get("hltanalysis/HltTree"); TTree* jet_80_skim = (TTree*)f1->Get("skimanalysis/HltTree"); TTree* jet_80_evt = (TTree*)f1->Get("hiEvtAnalyzer/HiTree"); jet_80->AddFriend(jet_80_hlt); jet_80->AddFriend(jet_80_skim); jet_80->AddFriend(jet_80_evt); TTree* jet_60 = (TTree*)f2->Get("akPu3PFJetAnalyzer/t"); TTree* jet_60_hlt = (TTree*)f2->Get("hltanalysis/HltTree"); TTree* jet_60_skim = (TTree*)f2->Get("skimanalysis/HltTree"); TTree* jet_60_evt = (TTree*)f2->Get("hiEvtAnalyzer/HiTree"); jet_60->AddFriend(jet_60_hlt); jet_60->AddFriend(jet_60_skim); jet_60->AddFriend(jet_60_evt); TCut Sel = "abs(vz)<15&&pHBHENoiseFilter&&pPAcollisionEventSelectionPA"; TCut Trig_100 = "HLT_PAJet100_NoJetID_v1"; TCut Trig_80 = "HLT_PAJet80_NoJetID_v1"; TCut Trig_60 = "HLT_PAJet60_NoJetID_v1"; TCut eta = "abs(jteta)<1"; Float_t N_mb = 7.71e13; Float_t prescl3 = (Float_t)jet_80->GetEntries()/jet_80->GetEntries(Trig_60); Float_t prescl3_test = (Float_t)jet_80->GetEntries(Sel&&eta&&Trig_100)/jet_80->GetEntries(Sel&&eta&&Trig_60); const Int_t nbins = 16; const Double_t bound[nbins+1] = {30., 40., 50., 60., 70., 80., 90., 100., 110., 120., 140., 150., 160., 200., 220., 260., 300.}; TH1F *hMeas_100 = new TH1F("hMeas_100","PPb HLT_100 Measured histo",nbins,bound); TH1F *hMeas_80 = new TH1F("hMeas_80","PPb HLT_80 Measured histo",nbins,bound); TH1F *hMeas_60 = new TH1F("hMeas_60","PPb HLT_60 Measured histo",nbins,bound); TH1F *hCombined = new TH1F("hCombined","PPb Combined spectra",nbins,bound); hMeas_100->Sumw2(); hMeas_60->Sumw2(); hMeas_80->Sumw2(); jet_80->Draw("jtpt>>hMeas_100",Sel&&Trig_100&&eta); jet_80->Draw("jtpt>>hMeas_80",Sel&&!Trig_100&&Trig_80&&eta); jet_60->Draw("jtpt>>hMeas_60","1.58606"*Sel&&eta&&Trig_60&&!Trig_80&&!Trig_100); divideBinWidth(hMeas_100); divideBinWidth(hMeas_80); divideBinWidth(hMeas_60); hMeas_100->Scale(1./2); //scaling by d eta - from -1 to +1 is 2. hMeas_80->Scale(1./2); hMeas_60->Scale(1./2); hCombined->Add(hMeas_100,1); hCombined->Add(hMeas_80,1); hCombined->Add(hMeas_60,1); hCombined->Scale(1./N_mb); hMeas_100->Scale(1./N_mb); hMeas_80->Scale(1./N_mb); hMeas_60->Scale(1./N_mb); TCanvas *cMerged = new TCanvas("cMerged","Merged PPb spectra",800,600); cMerged->SetLogy(); hCombined->SetXTitle("Jet p_{T} [GeV/c]"); hCombined->SetYTitle("1/N_mb d^2N/dp_t d eta"); hCombined->SetMarkerColor(kBlack); hCombined->SetMarkerStyle(20); hCombined->SetAxisRange(30,300,"X"); hCombined->Draw(); hMeas_100->SetMarkerColor(kRed); hMeas_100->SetMarkerStyle(21); hMeas_100->Draw("same"); hMeas_80->SetMarkerColor(kBlue); hMeas_80->SetMarkerStyle(22); hMeas_80->Draw("same"); hMeas_60->SetMarkerColor(kGreen); hMeas_60->SetMarkerStyle(23); hMeas_60->Draw("same"); TLegend *leg_PPb = myLegend(0.6,0.65,0.95,0.9); leg_PPb->SetTextSize(0.05); leg_PPb->AddEntry(hCombined,"Merged PPb spectra ","pl"); leg_PPb->AddEntry(hMeas_100,"HLT_100 spectra","pl"); leg_PPb->AddEntry(hMeas_80,"HLT_80 spectra","pl"); leg_PPb->AddEntry(hMeas_60,"HLT_60 spectra","pl"); leg_PPb->Draw(); putCMSPrel(0.2,0.83,0.06); drawText("PPb AKPu3PF |eta|<1 |vz|<15",0.2,0.23,20); cMerged->SaveAs("pPb_merged.pdf","RECREATE"); hMeas_100->Write(); hCombined->Write(); hMeas_80->Write(); hMeas_60->Write(); TFile *fYaxian = TFile::Open("AkPu3PFJetRpA.root"); TH1F *Yaxian = (TH1F*)fYaxian->Get("DataJetWideBin;3"); TH1F *test = (TH1F*)Yaxian->Clone("test"); cout<<"hi"<<endl; //outfile->cd(); Yaxian->Print("base"); test->Print("base"); Yaxian->Divide(hCombined); TCanvas *yaxian = new TCanvas("yaxian","",800,600); yaxian->Divide(2,1); yaxian->cd(1); Yaxian->SetTitle("ratio of Yaxian's measured pPb spectra to Mine"); Yaxian->SetXTitle("Jet p_{T} [GeV/c]"); Yaxian->SetMarkerColor(kBlack); Yaxian->SetMarkerStyle(23); Yaxian->Draw(); yaxian->cd(2); yaxian->cd(2)->SetLogy(); test->SetMarkerStyle(22); test->SetMarkerColor(kBlack); test->SetXTitle("Jet p_{T} [GeV/c]"); test->SetYTitle("1/N_mb d^2N/dp_t d eta"); test->Draw(); hCombined->Draw("same"); TLegend *leg = myLegend(0.6,0.65,0.95,0.9); leg->SetTextSize(0.05); leg->AddEntry(hCombined,"Merged PPb spectra ","pl"); leg->AddEntry(test,"Yaxian's spectra","pl"); leg->Draw(); putCMSPrel(0.2,0.83,0.06); drawText("PPb AKPu3PF |eta|<1 |vz|<15",0.2,0.23,20); yaxian->SaveAs("Yaxian_Comparison_pPb_pt_spectra.root","RECREATE"); outfile->cd(); Yaxian->Write(); test->Write(); outfile->Write(); outfile->Close(); timer.Stop(); float rtime = timer.RealTime(); float ctime = timer.CpuTime(); std::cout<<"\t"<<std::endl; std::cout<<Form("RealTime=%f seconds, CpuTime=%f seconds",rtime,ctime)<<std::endl; std::cout<<"\t"<<std::endl; std::cout<<"Good bye : " <<"\t"<<std::endl; //define the required histograms //static const Int_t nbins = 22; //static const Double_t bound[nbins+1] = {30.,40.,50.,60.,70.,80.,90.,100.,110.,120.,130.,140.,150.,160.,180.,200.,220.,260.,300.,350.,400.,450.,500.}; }
void fakeStudyMu( TCut Cuts_ = "ptL1>0", TString variable_ = "MtLeg1", TString XTitle_ = "M_{T}(#mu,MET)", TString Unities_ = "GeV", Int_t nBins_ = 12, Float_t xMin_=0, Float_t xMax_=120, Float_t magnifySgn_ = 10, Float_t hltEff_ = 1.0, Int_t enableHLTmatching_ = 1, Int_t logy_ = 0 ) { float Lumi = 24.86+159.15; TCanvas *c1 = new TCanvas("c1","",5,30,650,600); c1->SetGrid(0,0); c1->SetFillStyle(4000); c1->SetFillColor(10); c1->SetTicky(); c1->SetObjectStat(0); c1->SetLogy(logy_); TLegend* leg = new TLegend(0.60,0.50,0.85,0.85,NULL,"brNDC"); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetFillColor(10); leg->SetTextSize(0.04); leg->SetHeader("#mu+#tau_{had}"); THStack* aStack = new THStack("aStack",Form("CMS Preliminary 2011 #sqrt{s}=7 TeV L=%.0f pb^{-1}", Lumi )); TH1F* hSiml = new TH1F(); TH1F* hSgn = new TH1F(); TH1F* hSgn1 = new TH1F(); TH1F* hSgn2 = new TH1F(); TH1F* hData = new TH1F(); // OpenNTuples TString fDataName = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleRun2011-Mu_Open_MuTauStream.root"; TString fSignalNameVBF = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleVBFH115-Mu-powheg-PUS1_Open_MuTauStream.root"; TString fSignalNameGGH = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleGGFH115-Mu-powheg-PUS1_Open_MuTauStream.root"; TString fBackgroundNameDYTauTau = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleDYJets-Mu-50-madgraph-PUS1_Open_MuTauStream.root"; TString fBackgroundNameDYMuMu = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleDYJets-Mu-50-madgraph-PUS1_Open_MuTauStream.root"; TString fBackgroundNameWJets = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleWJets-Mu-madgraph-PUS1_Open_MuTauStream.root"; TString fBackgroundNameQCD = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleQCDmu_Open_MuTauStream.root"; TString fBackgroundNameTTbar = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleTTJets-Mu-madgraph-PUS1_Open_MuTauStream.root"; TString fBackgroundNameSingleTop = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleSingleTop-Mu_Open_MuTauStream.root"; TString fBackgroundNameDiBoson = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleDiBoson-Mu_Open_MuTauStream.root"; TFile *fData(0); TFile *fSignalVBF(0); TFile *fSignalGGH(0); TFile *fBackgroundDYTauTau(0); TFile *fBackgroundDYMuMu(0); TFile *fBackgroundWJets(0); TFile *fBackgroundQCD(0); TFile *fBackgroundTTbar(0); TFile *fBackgroundSingleTop(0); TFile *fBackgroundDiBoson(0); fData = TFile::Open( fDataName ); fSignalVBF = TFile::Open( fSignalNameVBF ); fSignalGGH = TFile::Open( fSignalNameGGH ); fBackgroundDYTauTau = TFile::Open( fBackgroundNameDYTauTau ); fBackgroundDYMuMu = TFile::Open( fBackgroundNameDYMuMu ); fBackgroundWJets = TFile::Open( fBackgroundNameWJets ); fBackgroundQCD = TFile::Open( fBackgroundNameQCD ); fBackgroundTTbar = TFile::Open( fBackgroundNameTTbar ); fBackgroundSingleTop= TFile::Open( fBackgroundNameSingleTop ); fBackgroundDiBoson = TFile::Open( fBackgroundNameDiBoson ); if(!fSignalVBF || !fBackgroundDYTauTau || !fBackgroundWJets || !fBackgroundQCD || !fBackgroundTTbar || !fBackgroundSingleTop || !fSignalGGH || !fBackgroundDYMuMu || !fBackgroundDiBoson || !fData){ std::cout << "ERROR: could not open files" << std::endl; exit(1); } TString tree = "outTreePtOrd"; TTree *data = (TTree*)fData->Get(tree); TTree *signalVBF = (TTree*)fSignalVBF->Get(tree); TTree *signalGGH = (TTree*)fSignalGGH->Get(tree); TFile* dummy1 = new TFile("dummy1.root","RECREATE"); TTree *backgroundDYTauTau = ((TTree*)fBackgroundDYTauTau->Get(tree))->CopyTree("isTauLegMatched>0.5"); TTree *backgroundDYMuMu = ((TTree*)fBackgroundDYMuMu->Get(tree))->CopyTree("isTauLegMatched<0.5"); cout <<backgroundDYTauTau->GetEntries() << " -- " << backgroundDYMuMu->GetEntries() << endl; TTree *backgroundWJets = (TTree*)fBackgroundWJets->Get(tree); TTree *backgroundQCD = (TTree*)fBackgroundQCD->Get(tree); TTree *backgroundTTbar = (TTree*)fBackgroundTTbar->Get(tree); TTree *backgroundSingleTop = (TTree*)fBackgroundSingleTop->Get(tree); TTree *backgroundDiBoson = (TTree*)fBackgroundDiBoson->Get(tree); // here I choose the order in the stack std::vector<string> samples; samples.push_back("ggH115"); samples.push_back("qqH115"); samples.push_back("DiBoson"); samples.push_back("SingleTop"); samples.push_back("TTbar"); samples.push_back("Wjets"); samples.push_back("QCD"); samples.push_back("ZfakeTau"); samples.push_back("Ztautau"); samples.push_back("Data"); // here I define the map between a sample name and its tree std::map<std::string,TTree*> tMap; tMap["Data"]=data; tMap["ggH115"]=signalGGH; tMap["qqH115"]=signalVBF; tMap["Ztautau"]=backgroundDYTauTau; tMap["ZfakeTau"]=backgroundDYMuMu; tMap["Wjets"]=backgroundWJets; tMap["QCD"]=backgroundQCD; tMap["TTbar"]=backgroundTTbar; tMap["SingleTop"]=backgroundSingleTop; tMap["DiBoson"]=backgroundDiBoson; Float_t pt1, pt2, Deta, Mjj, eta1, eta2; Float_t diTauSVFitPt,diTauVisPt,diTauVisEta,diTauSVFitEta,diTauVisMass,diTauSVFitMass,ptL1,ptL2,etaL1,etaL2,diTauCharge,MtLeg1,numPV,combRelIsoLeg1DBeta,combRelIsoLeg1,pZetaCutVar, MEt, ptVeto, leadTrackPt, jetsBtagHE1, jetsBtagHE2; Float_t sampleWeight,puWeight; std::map<TString,Float_t> vMap; for( unsigned iter=0; iter<samples.size(); iter++){ std::map<std::string,TTree*>::iterator it = tMap.find(samples[iter]); TString h1Name = "h1_"+it->first; TH1F* h1 = new TH1F( h1Name ,Form("CMS Preliminary 2011 #sqrt{s}=7 TeV L=%.0f pb^{-1}", Lumi) , nBins_ ,xMin_ , xMax_); TFile* dummy = new TFile("dummy.root","RECREATE"); TCut Cuts = Cuts_; TCut hlt = enableHLTmatching_ ? "( ((HLTmatch==2 && run<=163261) || (HLTmatch==1 && run>163261)) && ((HLTmu==1 && run<=163261) || (HLTx==1 && run>163261)) )" : "( ((HLTmu==1 && run<=163261) || (HLTx==1 && run>163261)) )"; if((it->first).find("Data")!=string::npos) Cuts = Cuts_ && hlt; TTree* currentTree = (TTree*)(it->second)->CopyTree(Cuts); Int_t counter = 0; currentTree->SetBranchAddress( "pt1", &pt1 ); currentTree->SetBranchAddress( "pt2", &pt2 ); currentTree->SetBranchAddress( "Deta",&Deta ); currentTree->SetBranchAddress( "Mjj", &Mjj ); currentTree->SetBranchAddress( "diTauSVFitPt",&diTauSVFitPt); currentTree->SetBranchAddress( "diTauSVFitEta",&diTauSVFitEta); currentTree->SetBranchAddress( "diTauSVFitMass",&diTauSVFitMass); currentTree->SetBranchAddress( "diTauVisPt",&diTauVisPt); currentTree->SetBranchAddress( "diTauVisEta",&diTauVisEta); currentTree->SetBranchAddress( "diTauVisMass",&diTauVisMass); currentTree->SetBranchAddress( "ptL1", &ptL1 ); currentTree->SetBranchAddress( "ptL2", &ptL2 ); currentTree->SetBranchAddress( "etaL1", &etaL1 ); currentTree->SetBranchAddress( "etaL2", &etaL2 ); currentTree->SetBranchAddress( "combRelIsoLeg1DBeta",&combRelIsoLeg1DBeta); currentTree->SetBranchAddress( "combRelIsoLeg1",&combRelIsoLeg1); currentTree->SetBranchAddress( "diTauCharge",&diTauCharge); currentTree->SetBranchAddress( "MtLeg1",&MtLeg1); currentTree->SetBranchAddress( "pZetaCutVar",&pZetaCutVar); currentTree->SetBranchAddress( "numPV",&numPV); currentTree->SetBranchAddress( "sampleWeight",&sampleWeight); currentTree->SetBranchAddress( "puWeight",&puWeight); currentTree->SetBranchAddress( "ptVeto",&ptVeto); currentTree->SetBranchAddress( "MEt",&MEt); currentTree->SetBranchAddress( "leadTrackPt",&leadTrackPt); currentTree->SetBranchAddress( "jetsBtagHE1",&jetsBtagHE1); currentTree->SetBranchAddress( "jetsBtagHE2",&jetsBtagHE2); for (Long64_t ievt=0; ievt<currentTree->GetEntries();ievt++) { currentTree->GetEntry(ievt); if (ievt%10000 == 0){ std::cout << (it->first) << " ---> processing event: " << ievt << " ..." <<std::endl; } vMap["diTauSVFitPt"] = diTauSVFitPt; vMap["diTauSVFitEta"] = diTauSVFitEta; vMap["diTauSVFitMass"]= diTauSVFitMass; vMap["diTauVisPt"] = diTauVisPt; vMap["diTauVisEta"] = diTauVisEta; vMap["diTauVisMass"] = diTauVisMass; vMap["ptL1"] = ptL1; vMap["ptL2"] = ptL2; vMap["etaL1"] = etaL1; vMap["etaL2"] = etaL2; vMap["diTauCharge"]= Float_t(diTauCharge); vMap["MtLeg1"]= MtLeg1; vMap["pZetaCutVar"] = pZetaCutVar; vMap["numPV"]= numPV; vMap["combRelIsoLeg1"]= combRelIsoLeg1; vMap["combRelIsoLeg1DBeta"]= combRelIsoLeg1DBeta; vMap["sampleWeight"]= sampleWeight; vMap["puWeight"]= puWeight; vMap["puWeight"]= puWeight; vMap["jetsBtagHE1"]= jetsBtagHE1; vMap["jetsBtagHE2"]= jetsBtagHE2; vMap["leadTrackPt"]= leadTrackPt; vMap["pt1"]= pt1; vMap["pt2"]= pt2; vMap["Deta"]= Deta; vMap["Mjj"]= Mjj; vMap["ptVeto"]= ptVeto; if((it->first).find("Data")==string::npos) sampleWeight*=(Lumi/1000*hltEff_*puWeight); counter++; h1->Fill( vMap[variable_], sampleWeight); }// end loop if( (it->first).find("ZfakeTau")!=string::npos ) { h1->SetFillColor(7); leg->AddEntry(h1,"Z+jets, fake-#tau","F"); } if( (it->first).find("Ztautau")!=string::npos ) { h1->SetFillColor(kRed); leg->AddEntry(h1,"Z+jets, genuine-#tau","F"); } if( (it->first).find("TTbar")!=string::npos ) { h1->SetFillColor(kBlue); leg->AddEntry(h1,"t#bar{t}+jets","F"); } if( (it->first).find("SingleTop")!=string::npos ) { h1->SetFillColor(29); leg->AddEntry(h1,"single-t","F"); } if( (it->first).find("Wjets")!=string::npos ) { h1->SetFillColor(kGreen); leg->AddEntry(h1,"W+jets","F"); } if( (it->first).find("DiBoson")!=string::npos ) { h1->SetFillColor(38); leg->AddEntry(h1,"Di-Boson","F"); } if( (it->first).find("QCD")!=string::npos ) { h1->SetFillColor(42); leg->AddEntry(h1,"QCD-multijets","F"); } if((it->first).find("qqH115")!=string::npos){ hSgn1 = (TH1F*)h1->Clone("hSgn1"); hSgn1->Scale(magnifySgn_); hSgn1->SetLineWidth(2); h1->SetFillColor(kBlack); h1->SetFillStyle(3004); h1->SetLineColor(kBlack); leg->AddEntry(h1,Form("VBF H(115) X %.0f",magnifySgn_),"F"); } if((it->first).find("ggH115")!=string::npos){ hSgn2 = (TH1F*)h1->Clone("hSgn2"); hSgn2->Scale(magnifySgn_); hSgn2->SetLineWidth(2); h1->SetFillColor(kBlack); h1->SetFillStyle(3005); h1->SetLineColor(kBlack); leg->AddEntry(h1,Form("GGF H(115) X %.0f",magnifySgn_),"F"); } if((it->first).find("Data")!=string::npos){ hData = (TH1F*)h1->Clone("hData"); hData->Sumw2(); hData->SetMarkerStyle(20); hData->SetMarkerSize(1.2); hData->SetMarkerColor(kBlack); hData->SetLineColor(kBlack); hData->SetXTitle(XTitle_+" ("+Unities_+")"); hData->SetYTitle(Form(" Events/(%.0f %s)", hData->GetBinWidth(1), Unities_.Data() ) ); hData->SetTitleSize(0.04,"X"); hData->SetTitleSize(0.05,"Y"); hData->SetTitleOffset(0.95,"Y"); leg->AddEntry(hData,"DATA","P"); } if(iter==0) hSiml=(TH1F*)h1->Clone("hSiml"); else if((it->first).find("Data")==string::npos) hSiml->Add(h1); if((it->first).find("Data")==string::npos) aStack->Add(h1); if(VERBOSE) cout<<(it->first) << " ==> " << h1->Integral() << " +/- " << TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries()) << endl; } // all signal summed together: hSgn = (TH1F*)hSgn1->Clone("hSgn"); hSgn->Add(hSgn1,hSgn2,1,1); if(VERBOSE) cout<< "S/sqrt(B) ==> " << hSgn->Integral()/ TMath::Sqrt(hSiml->Integral()) << " +/- " << (1./2)*TMath::Sqrt(hSiml->GetEntries())*(hSiml->GetSumOfWeights())/hSiml->Integral()*( hSgn->Integral()/ TMath::Sqrt(hSiml->Integral()) ) << endl; hData->SetXTitle(XTitle_+" ("+Unities_+")"); hData->SetYTitle(Form(" Events/(%.1f %s)", hData->GetBinWidth(1), Unities_.Data() ) ); hData->SetTitleSize(0.04,"X"); hData->SetTitleSize(0.05,"Y"); hData->SetTitleOffset(0.95,"Y"); hData->Draw("P"); aStack->Draw("HISTSAME"); hData->Draw("PSAME"); //hSgn1->Draw("HISTSAME"); //hSgn2->Draw("HISTSAME"); TH1F* hStack = (TH1F*)aStack->GetHistogram(); hStack->SetXTitle(XTitle_+" ("+Unities_+")"); hStack->SetYTitle(Form(" Events/(%.0f %s)", hStack->GetBinWidth(1), Unities_.Data() ) ); hStack->SetTitleSize(0.04,"X"); hStack->SetTitleSize(0.05,"Y"); hStack->SetTitleOffset(0.95,"Y"); //aStack->GetYaxis()->SetRangeUser(0.0,std::max(hData->GetMaximum(),hStack->GetMaximum())*1.1); leg->Draw(); }
// option = 1 (muon-pt), option = 2 (transverse mass) void doPlots(int option) { //gStyle->SetFillColor(1); // interested in plot made after all cuts have been applied string final_histo_desc; if(analysis_channel == 1) final_histo_desc = mumet_cuts_desc_short[Num_mumet_cuts-1]; else if(analysis_channel == 2) final_histo_desc = elmet_cuts_desc_short[Num_elmet_cuts-1]; string prefix = ""; if(option == 1 && analysis_channel == 1) prefix = "hPT"; if(option == 1 && analysis_channel == 2) prefix = "hET"; else if(option == 2) prefix = "hTM"; TH1F ** bgdSamples = 0; const string * bgdNames = 0; unsigned NbgdSamples = 0; if(analysis_channel == 1) { bgdSamples = &bgdMuMET[0]; bgdNames = &bgdNamesMuMET[0]; NbgdSamples = NbgdSamplesMuMET; } else if(analysis_channel == 2) { bgdSamples = &bgdElMET[0]; bgdNames = &bgdNamesElMET[0]; NbgdSamples = NbgdSamplesElMET; } string histo = prefix + algo + "_" + final_histo_desc; for(unsigned i = 0; i != NbgdSamples; ++i) { string histo_i = bgdNames[i] + "/" + histo; bgdSamples[i] = (TH1F* ) _file0->Get(histo_i.c_str()); if(badHisto(bgdSamples[i], histo_i)) return; } string mass = "1.5";//W' mass string histo_wp = "wprime" + mass + "/" + histo; TH1F * wp = (TH1F* )_file0->Get(histo_wp.c_str()); if(badHisto(wp, "wprime" + mass)) return; string histo_wp_noint = "wprime" + mass + "_noint/" + histo; TH1F * wp_noint = (TH1F* )_file0->Get(histo_wp_noint.c_str()); if(badHisto(wp_noint, "wprime" + mass + "_noint")) return; string histo_wp_oppsign = "wprime" + mass + "_oppsign/" + histo; TH1F * wp_oppsign = (TH1F* )_file0->Get(histo_wp_oppsign.c_str()); if(badHisto(wp_oppsign, "wprime" + mass + "_oppsign")) return; string histo_wp_samesign = "wprime" + mass + "_samesign/" + histo; TH1F * wp_samesign = (TH1F* )_file0->Get(histo_wp_samesign.c_str()); if(badHisto(wp_samesign, "wprime" + mass + "_samesign")) return; string hname = "tot_bgd"; double xmin = -1; double xmax = -1; double xmax_ratio = -1; double xmax_cumu = -1; string title = "INVALID"; string var_plotted = "INVALID2"; char data_ipb[1024]; sprintf(data_ipb, " data (%4.1f pb^{-1})", Lumi_ipb); char lumi_value[1024]; sprintf(lumi_value, "%4.1fipb", Lumi_ipb); char lumi_value2[1024]; sprintf(lumi_value2, "%4.1f pb^{-1}", Lumi_ipb); string cms_prelim = "CMS Preliminary 2011"; char lumi_sqrts_[1024]; sprintf(lumi_sqrts_, "L_{int} = %4.1f pb^{-1}, #sqrt{s} = 7 TeV", Lumi_ipb); string lumi_sqrts = lumi_sqrts_; float x_offset = 0; int Nbins = bgdSamples[0]->GetNbinsX(); if(option == 1) { hname += "_mupt"; desc = " p_{T} distribution"; xmin = 150; xmax = 1200; title = "Muon p_{T} (GeV/c)"; var_plotted = "MuPt"; x_offset = -100; } else if(option == 2) { hname += "_TM"; string desc0 = ""; if(analysis_channel == 1) desc0 = "#mu"; else if(analysis_channel == 2) desc0 = "e"; desc = desc0 + "&ME_{T} transverse mass: 2011 data (" + string(lumi_value2) + ")"; xmin = 200; xmax = 2000; title = "M_{T} (GeV/c^{2})"; var_plotted = "TM"; } string file = var_plotted + "_" + lumi_value + ".gif"; // ============== CREATE DISTRIBUTIONS HERE ====================== // this is the total background distribution (W + QCD + top + Z/DY) TH1F * bgd = new TH1F(hname.c_str(), desc.c_str(), Nbins, bgdSamples[0]->GetXaxis()->GetXmin(), bgdSamples[0]->GetXaxis()->GetXmax()); TH1F * bgd_output = new TH1F("MT_bgd","MT_bgd",nbins_output,xmin_output,xmax_output); THStack *hsbgd =new THStack(hname.c_str(),desc.c_str());//+++++++++ for(unsigned i = 0; i != NbgdSamples; ++i){ //for(int i = NbgdSamples - 1; i != -1; i--){ if(analysis_channel == 2){ // 1, 2-4, 5-7, 8-10,11-12,13-15,16- if(i<1){bgdClr=bgdColorElMET[0];} else if(i>1 && i<5){bgdClr=bgdColorElMET[1];} else if(4<i && i<8){bgdClr=bgdColorElMET[2];} else if(7<i && i<11){bgdClr=bgdColorElMET[3];} else if(10<i && i<13){bgdClr=bgdColorElMET[4];} else if(12<i && i<16){bgdClr=bgdColorElMET[5];} else if(i>15){bgdClr=bgdColorElMET[6];} bgdSamples[i]->SetLineColor(bgdClr);bgdSamples[i]->SetFillColor(bgdClr); hsbgd->Add(bgdSamples[i]);//+++++++++ } bgd->Add(bgdSamples[i]); bgd_output->Add(bgdSamples[i]); } const int fill_style_sig = 3001; const int fill_style_bgd = 3001; bgd->SetLineColor(kAzure+1); bgd->SetFillColor(kAzure+1); bgd->SetFillStyle(fill_style_bgd); // =============== PLOT DISTRIBUTIONS HERE ======================== TCanvas * c1 = new TCanvas(); c1->SetLogy(); if(wClr && analysis_channel == 2)hsbgd->Draw("e"); else bgd->Draw("e"); wp->SetLineColor(kRed); wp_noint->SetLineColor(kRed+1); wp_oppsign->SetLineColor(kRed+2); wp_samesign->SetLineColor(kRed+3); wp->SetFillColor(kRed); wp_noint->SetFillColor(kRed+1); wp_oppsign->SetFillColor(kRed+2); wp_samesign->SetFillColor(kRed+3); wp->SetFillStyle(fill_style_sig); wp_noint->SetFillStyle(fill_style_sig); wp_oppsign->SetFillStyle(fill_style_sig); wp_samesign->SetFillStyle(fill_style_sig); wp->Draw("same"); wp_noint->Draw("same"); wp_oppsign->Draw("same"); wp_samesign->Draw("same"); TLegend * lg = new TLegend(0.52, 0.67, 0.82, 0.89); lg->SetTextSize(0.03); lg->SetBorderSize(0); lg->SetFillColor(0); lg->AddEntry(bgd, "Total bgd", "F"); string histo_entry_title = "W ' (" + mass + " TeV)"; lg->AddEntry(wp, histo_entry_title.c_str(), "F"); histo_entry_title = "W ' (" + mass + " TeV), no interference"; lg->AddEntry(wp_noint, histo_entry_title.c_str(), "F"); histo_entry_title = "W ' (" + mass + " TeV), negative interference"; lg->AddEntry(wp_oppsign, histo_entry_title.c_str(), "F"); histo_entry_title = "W ' (" + mass + " TeV), positive interference"; lg->AddEntry(wp_samesign, histo_entry_title.c_str(), "F"); lg->Draw(); c1->SaveAs(file.c_str()); TFile *bgd_output_file = new TFile("Wprime_bgd_mu.root","recreate"); bgd_output->Write(); bgd_output_file->Close(); }
void templatefit1() { std::vector<string> samples_; float scales[] = {0.0961,0.0978,1.491,0.0253,0.0224,0.0145,0.0125,0.0160,0.0158,0.0341,0.0341,0.0341,0.020,0.0017,0.0055,0.0032,0.00084,0.02}; samples_.push_back("WPHJET.root"); samples_.push_back("ZJET.root"); samples_.push_back("PHJET200400.root"); //samples_.push_back("WJET.root"); samples_.push_back("T-W-CH.root"); samples_.push_back("TBAR-W-CH.root"); samples_.push_back("T-S-CH.root"); samples_.push_back("TBAR-S-CH.root"); samples_.push_back("T-T-CH.root"); samples_.push_back("TBAR-T-CH.root"); samples_.push_back("TTBAR1.root"); samples_.push_back("TTBAR2.root"); samples_.push_back("TTBAR3.root"); samples_.push_back("TTG.root"); samples_.push_back("WWG.root"); samples_.push_back("WW.root"); samples_.push_back("WZ.root"); samples_.push_back("ZZ.root"); samples_.push_back("ZGAMMA.root"); //samples_.push_back("SIGNAL.root"); //samples_.push_back("REALDATA.root"); std::vector<string> samplesreverse_; samplesreverse_.push_back("etarev/WPHJET.root"); samplesreverse_.push_back("etarev/ZJET.root"); samplesreverse_.push_back("etarev/PHJET200400.root"); samplesreverse_.push_back("etarev/T-W-CH.root"); samplesreverse_.push_back("etarev/TBAR-W-CH.root"); samplesreverse_.push_back("etarev/T-S-CH.root"); samplesreverse_.push_back("etarev/TBAR-S-CH.root"); samplesreverse_.push_back("etarev/T-T-CH.root"); samplesreverse_.push_back("etarev/TBAR-T-CH.root"); samplesreverse_.push_back("etarev/TTBAR1.root"); samplesreverse_.push_back("etarev/TTBAR2.root"); samplesreverse_.push_back("etarev/TTBAR3.root"); samplesreverse_.push_back("etarev/TTG.root"); samplesreverse_.push_back("etarev/WWG.root"); samplesreverse_.push_back("etarev/WW.root"); samplesreverse_.push_back("etarev/WZ.root"); samplesreverse_.push_back("etarev/ZZ.root"); samplesreverse_.push_back("etarev/ZGAMMA.root"); //open files std::vector<TFile*> files; for(unsigned int idx=0; idx<samples_.size(); ++idx){ files.push_back(new TFile(samples_[idx].c_str())); } std::vector<TFile*> reversefiles; for(unsigned int idx=0; idx<samplesreverse_.size(); ++idx){ reversefiles.push_back(new TFile(samplesreverse_[idx].c_str())); } TFile* data = new TFile("REALDATA.root"); TFile* datarev=new TFile("etarev/REALDATA.root"); ///////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// std::vector<string> variables2_; variables2_.push_back("photon_Pt"); // variables2_.push_back("photon_Eta"); // variables2_.push_back("muon_Pt"); // variables2_.push_back("muon_Eta"); // variables2_.push_back("Jet_Pt"); // variables2_.push_back("Jet_Eta"); // variables2_.push_back("Jet_Multiplicity"); // variables2_.push_back("topmass"); // variables2_.push_back("WTmass"); // variables2_.push_back("Cosmuonjet"); // variables2_.push_back("Cosmuonphoton"); // variables2_.push_back("Cosphotonjet"); // variables2_.push_back("Deltaphiphotonjet"); // variables2_.push_back("Deltaphiphotonmuon"); // variables2_.push_back("Deltaphimuonjet"); // variables2_.push_back("DeltaRphotonmuon"); // variables2_.push_back("DeltaRphotonjet"); // variables2_.push_back("DeltaRmuonjet"); // variables2_.push_back("HT"); // variables2_.push_back("Photonmuonmass"); // variables2_.push_back("Costopphoton"); // variables2_.push_back("sigmaetaetaendcap"); // variables2_.push_back("sigmaetaetabarrel"); // load histograms std::vector<TH1F*> BGhists; for(unsigned int idx=0; idx<files.size(); ++idx){ BGhists.push_back((TH1F*)files[idx]->Get((std::string("analyzestep2/").append(variables2_[0]).c_str()))); } std::vector<TH1F*> revBGhists; for(unsigned int idx=0; idx<reversefiles.size(); ++idx){ revBGhists.push_back((TH1F*)reversefiles[idx]->Get((std::string("analyzestep2/").append(variables2_[0]).c_str()))); } TH1F* DATAhists; DATAhists = (TH1F*)data->Get((std::string("analyzestep2/").append(variables2_[0]).c_str())); TH1F* SIGhists; TH1F* revDATAhists; revDATAhists = (TH1F*)datarev->Get((std::string("analyzestep2/").append(variables2_[0]).c_str())); float lumi = 5.319; for(unsigned int idx=0; idx<samples_.size(); ++idx){ BGhists[idx]->Scale(lumi*scales[idx]); } for(unsigned int idx=0; idx<samplesreverse_.size(); ++idx){ revBGhists[idx]->Scale(lumi*scales[idx]); } for(unsigned int idx=1; idx<samples_.size(); ++idx){ BGhists[idx]->Add(BGhists[idx-1]); } for(unsigned int idx=1; idx<samplesreverse_.size(); ++idx){ revBGhists[idx]->Add(revBGhists[idx-1]); } SIGhists=revDATAhists; SIGhists->Add(revBGhists[samples_.size()-1],-1); //TCanvas* conv = new TCanvas("BGBG", "BG" , 600, 600); //conv->cd(0); //DATAhists->Draw(); //revBGhists[samples_.size()-1]->Draw("same"); //TCanvas* nv = new TCanvas("data", "data" , 600, 600); //nv->cd(0); //SIGhists->Draw(); int norm=1; double scalesig =norm/SIGhists->Integral(); SIGhists->Scale(scalesig); //double scaledata =norm/DATAhists->Integral(); //DATAhists->Scale(scaledata); double scalebg =norm/BGhists[samples_.size()-1]->Integral(); BGhists[samples_.size()-1]->Scale(scalebg); //TCanvas* conv = new TCanvas("signal", "signal" , 600, 600); //conv->cd(0); //SIGhists->Draw(); //TCanvas* nv = new TCanvas("data", "data" , 600, 600); //nv->cd(0); //DATAhists->Draw(); //TCanvas* con = new TCanvas("BG", "BG" , 600, 600); //con->cd(0); //BGhists[samples_.size()-1]->Draw(); //conv->cd(0); ////Ghists->Draw(); RooRealVar x("x", "x", 50.,500.); // RooRealVar x("x", "x", -3,3); // RooRealVar x("x", "x", 26.,500.); // RooRealVar x("x", "x", 25.,150.); // RooRealVar x("x", "x", 0.,400.); RooDataHist* template1 = new RooDataHist("template1", "template1", RooArgList(x), SIGhists); RooHistPdf modelTemplate1("modelTemplate1", "modelTemplate1", RooArgSet(x), *template1); RooDataHist* template2 = new RooDataHist("template2", "template2", RooArgList(x), BGhists[samples_.size()-1]); RooHistPdf modelTemplate2("modelTemplate2", "modelTemplate2", RooArgSet(x), *template2); RooDataHist* sumData = new RooDataHist("sumData", "sumData", RooArgList(x), DATAhists); std::cout << " executing fit..." << std::endl; RooRealVar coeffTemplate1("coeffTemplate1", "coeffTemplate1", 0, 2000); RooRealVar coeffTemplate2("coeffTemplate2", "coeffTemplate2", 0, 2000); RooAddPdf sumTemplate("sumTemplate", "coeff*modelTemplate1 + (1 - coeff)*modelTemplate2",RooArgList(modelTemplate1, modelTemplate2),RooArgList(coeffTemplate1,coeffTemplate2)); sumTemplate.fitTo(*sumData); std::cout << "--> coeffTemplate1 = " << coeffTemplate1.getVal() << std::endl; std::cout << "--> coeffTemplate2 = " << coeffTemplate2.getVal() << std::endl; RooPlot* frame = x.frame() ; sumData->plotOn(frame,LineStyle(kDashed)) ; sumTemplate.plotOn(frame) ; //modelTemplate2.plotOn(frame) ; frame->Draw() ; }