//--- function to divide histograms then draw--- void drawDivHist(const char* hn1, const char* hn2, const char* opt, const char* name, const char* title, const int nbin, const float min, const float max, bool log=false, const int lc=0, const int ls=0, const int lw=0) { // find input histos if (!TString(opt).Contains("same")) printf("\n"); printf("h1: %s. h2: %s. Draw: %s\n", hn1, hn2, name); TH1F * h1; TH1F * h2; if (gROOT->FindObject(hn1)) h1 = dynamic_cast<TH1F*>(gROOT->FindObject(hn1)); else { printf("%s is not found, please check the histogram name\n", hn1); return; } if (gROOT->FindObject(hn2)) h2 = dynamic_cast<TH1F*>(gROOT->FindObject(hn2)); else { printf("%s is not found, please check the histogram name\n", hn2); return; } //--- Make/set histogram --- printf("hist: %s %d %f %f\n",name,nbin,min,max); TH1F * h = createHist(name, title, nbin, min, max); setHist(h,lc,ls,lw); //--- Action --- h->Divide(h1,h2); //--- Draw --- TCanvas * c = makeCanvas(name,title,log,opt); h->Draw(opt); }
//-------------------------------------------------------------------------------------------------- // make fake rate histogram from numerator and denominators //-------------------------------------------------------------------------------------------------- TH1F* createFakeRatePtHist(vector<string> datasetFiles, vector<string> datasetNames, int faketype, string histName) { string numeratorHistName = ""; string denominatorHistName = ""; string dirName = ""; if (faketype == 11) { dirName = "ComputeElectronFakeRateMod"; numeratorHistName = "hElectronNumeratorEt"; denominatorHistName = "hElectronDenominatorEt"; } else if (faketype == 13) { dirName = "ComputeMuonFakeRateMod"; numeratorHistName = "hMuonNumeratorPt"; denominatorHistName = "hMuonDenominatorPt"; } else { cerr << "Error: faketype = " << faketype << " is not recognized." << endl; return 0; } TH1F *denominator = addAllSamples(datasetFiles, datasetNames, dirName, denominatorHistName); TH1F *numerator = addAllSamples(datasetFiles, datasetNames, dirName, numeratorHistName); //create fake rate hist from denominator binning TH1F *fakeRateHist = (TH1F*)numerator->Clone(histName.c_str()); fakeRateHist->GetYaxis()->SetTitle("Fake Rate"); //divide by the denominator to get fake rate; fakeRateHist->Divide(denominator); return fakeRateHist; }
void make_histos_syst_rawyield(TString file_syst, TString file_default, TString out_tag){ TFile *f1 = new TFile(file_syst.Data(),"read"); TFile *f2 = new TFile(file_default.Data(),"read"); TDirectoryFile *dir1 = (TDirectoryFile*)(f1->Get("effunf")); TDirectoryFile *dir2 = (TDirectoryFile*)(f2->Get("effunf")); TList *list = dir1->GetListOfKeys(); TFile *f = new TFile(Form("plots/ratiosyst_%s.root",out_tag.Data()),"recreate"); for (int i=0; i<list->GetSize(); i++){ TString name = dir1->GetListOfKeys()->At(i)->GetName(); if (!(name.Contains("hreco_"))) continue; TObject *obj1 = dir1->Get(name.Data()); assert(obj1); TObject *obj2 = dir2->Get(name.Data()); assert(obj2); TString newname = name; newname.Append("_ratiosyst"); if (name.EndsWith("_0")) newname.ReplaceAll("_0_","_EBEB_"); if (name.EndsWith("_1")) newname.ReplaceAll("_1_","_EBEE_"); if (name.EndsWith("_2")) newname.ReplaceAll("_2_","_EEEE_"); TH1F *h = (TH1F*)(((TH1F*)obj1)->Clone(newname.Data())); h->SetTitle(h->GetName()); h->Divide((TH1F*)obj2); for (int j=0; j<h->GetNbinsX(); j++) h->SetBinError(j+1,0); for (int j=0; j<h->GetNbinsX(); j++) h->SetBinContent(j+1,1+fabs(1-h->GetBinContent(j+1))); f->cd(); h->Write(); } }
static void make_plot( const char* i ) { c.cd(++pad_id); char *hist_name = Form("h%s_hit", i); TH1F *hit = new TH1F(hist_name, "", time_bins, min_time, max_time); events->Draw( Form("timestamp >> %s", hist_name), Form("(t%s_hits_count == 4) && (t%s_track_count >= 1)", i, i) ); hist_name = Form("h%s_all", i); TH1F *all = new TH1F(hist_name, "", time_bins, min_time, max_time); events->Draw( Form("timestamp >> %s", hist_name) ); hist_name = Form("h%s_eff", i); TH1F *eff = new TH1F(hist_name, "", time_bins, min_time, max_time); eff->Divide(hit, all); eff->GetYaxis()->SetRangeUser(0.0, 1.0); eff->Draw(); c.cd(++pad_id); hist_name = Form("h%s_eff_distrib", i); TH1F *eff_distrib = new TH1F(hist_name, "", 100, 0, 0.5); int nbins = eff->GetXaxis()->GetNbins(); for (int bin = 1; bin <= nbins; bin++) { eff_distrib->Fill(eff->GetBinContent(bin)); } eff_distrib->Draw(); }
void FindZ2Weight(){ NCanvas(1,1,"data"); NCanvas(1,1,"ratio"); TH1F * Pyt; TH1F * Dat; TH1F * Data; TFile *fzee = new TFile("ZDiffOutputfile.root"); Pyt = (TH1F*)fzee->Get("NoCuts_GoodVtx_Z2PY6"); Dat = (TH1F*)fzee->Get("NoCuts_GoodVtx_DATA10"); Data = (TH1F*)fzee->Get("NoCuts_GoodVtx_DATA10"); data->cd(1); Data->Draw(); Float_t scale = Pyt->Integral()/Dat->Integral(); cout << "Scaling factor to conserve MC luminosity = " << scale << endl; ratio->cd(1); Dat->Divide(Pyt); // Dat->Scale(scale); Dat->Draw(); cout << "Float_t Z2Weight[] = {" ; for (Int_t j = 1;j<=19; j++) cout << Dat->GetBinContent(j) << ", " ; cout << " 0 }; " << endl; }
void beffAnalysis(const char* input, const char* output) { // input TFile* inputFile = TFile::Open(input); TTree* btagEff = (TTree*)inputFile->Get("btagEff"); // output TFile* outputFile = TFile::Open(output,"RECREATE"); // histogram with proper binning... cloned later on Double_t binning[23] = {20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,120,140,160,180,200,1000}; TH1F* ptSpectrum = new TH1F("PtSpectrum","PtSpectrum",22,binning); ptSpectrum->Sumw2(); // produce the ratio plot for the 12 combinations of (CSVL,CSVM,CSVT),(Barrel,Endcap),(b,c,l) TClonesArray algorithms("TCut",3); new(algorithms[0]) TCut("CSVL","csv>0.244"); new(algorithms[1]) TCut("CSVM","csv>0.679"); new(algorithms[2]) TCut("CSVT","csv>0.898"); TClonesArray etaRegions("TCut",2); new(etaRegions[0]) TCut("Barrel","abs(eta)<=1.2"); new(etaRegions[1]) TCut("Endcaps","abs(eta)>1.2"); TClonesArray flavor("TCut",3); new(flavor[0]) TCut("l","abs(flavor)!=4 && abs(flavor)!=5"); new(flavor[1]) TCut("c","abs(flavor)==4"); new(flavor[2]) TCut("b","abs(flavor)==5"); for(int i=0; i< algorithms.GetEntries() ; ++i) { outputFile->mkdir(((TCut*)algorithms.At(i))->GetName()); outputFile->cd(((TCut*)algorithms.At(i))->GetName()); for(int j=0; j< etaRegions.GetEntries() ; ++j) { for(int k=0; k< flavor.GetEntries() ; ++k) { // histogram before tagging TH1F* pretag = ptSpectrum->Clone("pretag"); btagEff->Draw("pt>>pretag",((*(TCut*)etaRegions.At(j))&&(*(TCut*)flavor.At(k)))*"eventWeight"); // histogram after tagging TH1F* posttag = ptSpectrum->Clone("posttag"); btagEff->Draw("pt>>posttag",((*(TCut*)algorithms.At(i))&&(*(TCut*)etaRegions.At(j))&&(*(TCut*)flavor.At(k)))*"eventWeight"); // ratio TH1F* ratio = posttag->Clone(Form("h_eff_bTagOverGoodJet_pt%s_%s",((TCut*)flavor.At(k))->GetName(), ((TCut*)etaRegions.At(j))->GetName())); ratio->Divide(pretag); // cleanup delete pretag; delete posttag; } } } // cleanup algorithms.Delete(); etaRegions.Delete(); flavor.Delete(); ptSpectrum->SetDirectory(0); outputFile->Write(); outputFile->Close(); inputFile->Close(); }
void reweight_eta_1d(TH1F* weight_eta,TH1F* weight_etao,TH2F*weight_etan,TH2F* weight_eta2o,TH2F* weight_etanr,TH2F*weight_eta2,RooDataSet **dset, RooDataSet *dsetdestination, int numvar){ if (!(*dset)) return; TH1F *hnum = new TH1F("hnum","hnum",n_etabins_forreweighting,etabins_forreweighting); TH1F *hden = new TH1F("hden","hden",n_etabins_forreweighting,etabins_forreweighting); // TH1F *hnum = new TH1F("hnum","hnum",25,0.,2.5); // TH1F *hden = new TH1F("hden","hden",25,0.,2.5); hnum->Sumw2(); hden->Sumw2(); const char* etaname=Form("rooeta%d",numvar); for (int i=0; i<(*dset)->numEntries(); i++){ hden->Fill(fabs((*dset)->get(i)->getRealValue(etaname)),(*dset)->store()->weight(i)); } for (int i=0; i<dsetdestination->numEntries(); i++){ hnum->Fill(fabs(dsetdestination->get(i)->getRealValue(etaname)),dsetdestination->store()->weight(i)); } hnum->Scale(1.0/hnum->Integral()); hden->Scale(1.0/hden->Integral()); hnum->Divide(hden); TH1F *h = hnum; RooDataSet *newdset = new RooDataSet(**dset,Form("%s_etarew",(*dset)->GetName())); newdset->reset(); for (int i=0; i<(*dset)->numEntries(); i++){ RooArgSet args = *((*dset)->get(i)); float oldw = (*dset)->store()->weight(i); float eta = args.getRealValue(etaname); float neww = oldw*h->GetBinContent(h->FindBin(fabs(eta))); if(debug){ weight_eta->Fill(neww); weight_etao->Fill(oldw); weight_etan->Fill(h->FindBin(fabs(eta)),neww); weight_eta2o->Fill(h->FindBin(fabs(eta)),oldw); if(oldw!=0 && neww!=0)weight_etanr->Fill(h->FindBin(fabs(eta)),oldw/neww); else {weight_etanr->Fill(-10,1);} // weight_pt2->Fill(pt,neww/oldw); if(oldw!=0 && neww!=0)weight_eta2->Fill(fabs(eta),oldw/neww); else {weight_eta2->Fill(-10,1);} } newdset->add(args,neww); } newdset->SetName((*dset)->GetName()); newdset->SetTitle((*dset)->GetTitle()); delete hnum; delete hden; RooDataSet *old_dset = *dset; *dset=newdset; std::cout << "Eta 1d rew: norm from " << old_dset->sumEntries() << " to " << newdset->sumEntries() << std::endl; delete old_dset; };
void PlotMinEtFromSim(Bool_t isPhos = kFALSE){ gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gStyle->SetOptFit(0); Float_t min = 0; float max = 1; TString filename, detname; if(isPhos){ min = 0.655; max = 0.785; detname = "PHOS"; filename = "rootFiles/LHC11a10a_bis/Et.ESD.simPbPb.PHOS.LHC11a10a_bis.Run139465.root"; } else{ min = 0.58; max = 0.725; filename = "rootFiles/LHC11a10a_bis/Et.ESD.simPbPb.EMCal.LHC11a10a_bis.Run139465.root"; detname = "EMCal"; } TFile *f = TFile::Open(filename, "READ"); TList *l = dynamic_cast<TList*>(f->Get("out1")); TH1F *fHistSimulatedGammaEnergyAboveThreshold = l->FindObject("fHistSimulatedGammaEnergyAboveThreshold"); TH1F *fHistSimulatedGammaEnergy = l->FindObject("fHistSimulatedGammaEnergy"); SetStyles(fHistSimulatedGammaEnergyAboveThreshold,20,TColor::kRed); fHistSimulatedGammaEnergyAboveThreshold->Divide(fHistSimulatedGammaEnergy); TCanvas *c1 = new TCanvas("c1","Simulation",600,400); c1->SetTopMargin(0.02); c1->SetRightMargin(0.03); c1->SetLeftMargin(0.11745); c1->SetBottomMargin(0.11745); c1->SetBorderSize(0); c1->SetFillColor(0); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetFrameFillColor(0); c1->SetFrameBorderMode(0); fHistSimulatedGammaEnergyAboveThreshold->SetMaximum(max +0.1); fHistSimulatedGammaEnergyAboveThreshold->SetMinimum(min-0.1); fHistSimulatedGammaEnergyAboveThreshold->GetXaxis()->SetTitle("Centrality bin"); fHistSimulatedGammaEnergyAboveThreshold->GetYaxis()->SetTitle("f_{minEt}"); fHistSimulatedGammaEnergyAboveThreshold->GetYaxis()->SetLabelSize(0.06); fHistSimulatedGammaEnergyAboveThreshold->GetXaxis()->SetLabelSize(0.06); fHistSimulatedGammaEnergyAboveThreshold->GetYaxis()->SetTitleSize(0.06); fHistSimulatedGammaEnergyAboveThreshold->GetXaxis()->SetTitleSize(0.06); fHistSimulatedGammaEnergyAboveThreshold->Draw(); TLine *lineMin = new TLine(-0.5,min,19.5,min); lineMin->Draw(); TLine *lineMax = new TLine(-0.5,max,19.5,max); lineMax->Draw(); lineMin->SetLineColor(TColor::kBlue); lineMax->SetLineColor(TColor::kBlue); lineMin->SetLineStyle(2); lineMax->SetLineStyle(2); TString outfile = "/tmp/MinEtFromSim"+detname+".png"; c1->SaveAs(outfile.Data()); }
//-------------------------------------------------------------------------------------------------- // make fake rate histogram from numerator and denominators //-------------------------------------------------------------------------------------------------- // TGraphAsymmErrors* createFakeRatePtHist(vector<string> datasetFiles, vector<string> datasetNames, // int denominatortype, int faketype, int chargetype, // int eventType, string histName) { TH1F* createFakeRatePtHist(vector<string> datasetFiles, vector<string> datasetNames, int denominatortype, int faketype, int chargetype, int eventType, string histName) { string numeratorHistName = ""; string denominatorHistName = ""; string dirName = ""; string chargeTypeName = ""; if (chargetype == -1) chargeTypeName = "Minus"; else if (chargetype == 1) chargeTypeName = "Plus"; string eventTypeName = ""; if (eventType == -1) eventTypeName = "MinusW"; else if (eventType == 1) eventTypeName = "PlusW"; string denominatorTypeName = ""; if (denominatortype == 1) denominatorTypeName = "Track"; if (faketype == 11) { dirName = "ComputeElectronFakeRateMod"; numeratorHistName = "h" + chargeTypeName + "Electron" + eventTypeName + "NumeratorPt"; denominatorHistName = "h" + chargeTypeName + "Electron" + eventTypeName + denominatorTypeName + "DenominatorPt"; } else if (faketype == 13) { dirName = "ComputeMuonFakeRateMod"; numeratorHistName = "h" + chargeTypeName + "Muon" + eventTypeName + "NumeratorPt"; denominatorHistName = "h" + chargeTypeName + "Muon" + eventTypeName + denominatorTypeName + "DenominatorPt"; } else { cerr << "Error in createFakeRatePtHist: faketype = " << faketype << " is not recognized." << endl; assert(false); } TH1F *denominator = addAllSamples(datasetFiles, datasetNames, dirName, denominatorHistName); TH1F *numerator = addAllSamples(datasetFiles, datasetNames, dirName, numeratorHistName); //create fake rate hist from denominator binning TH1F *fakeRateHist = (TH1F*)numerator->Clone(histName.c_str()); fakeRateHist->GetYaxis()->SetTitle("Fake Rate"); //divide by the denominator to get fake rate; fakeRateHist->Divide(denominator); //TGraphAsymmErrors* fakeRate = (numerator, denominator); //for (int i=1 ; i <= fakeRateHist->GetXaxis()->GetNbins(); i++) { //cout << i << " : " << fakeRateHist->GetXaxis()->GetBinCenter(i) << " " << fakeRateHist->GetBinContent(i) << " +- " << fakeRateHist->GetBinError(i) << endl; //if (fakeRateHist->GetBinContent(i) > 0 && fakeRateHist->GetBinError(i) < 0.01) { //fakeRateHist->SetBinError(i,0.01); //} //} return fakeRateHist; }
void reweight_diphotonpt_1d(TH1F*weight_diphopt,TH1F*weight_diphopto,TH2F*weight_diphoptn,TH2F*weight_diphopt2o,TH2F*weight_diphoptnr, TH2F* weight_diphopt2,RooDataSet **dset, RooDataSet *dsetdestination){ if (!(*dset)) return; if (!(dsetdestination)) return; ///numerator and denominator TH1F *hnum = new TH1F("hnum","hnum",n_diphoptbins_forreweighting,diphoptbins_forreweighting); TH1F *hden = new TH1F("hden","hden",n_diphoptbins_forreweighting,diphoptbins_forreweighting); hnum->Sumw2(); hden->Sumw2(); // RooAbsData->get*() Load a given row of data //getRealValue Get value of a RooAbsReal stored in set with given name. If none is found, value of defVal is returned. for (int i=0; i<(*dset)->numEntries(); i++){ hden->Fill(fabs((*dset)->get(i)->getRealValue("roodiphopt")),(*dset)->store()->weight(i)); } for (int i=0; i<dsetdestination->numEntries(); i++){ hnum->Fill(fabs(dsetdestination->get(i)->getRealValue("roodiphopt")),dsetdestination->store()->weight(i)); } //normalize to one hnum->Scale(1.0/hnum->Integral()); hden->Scale(1.0/hden->Integral()); hnum->Divide(hden); TH1F *h = hnum; RooDataSet *newdset = new RooDataSet(**dset,Form("%s_diphoptrew",(*dset)->GetName())); newdset->reset(); assert(newdset); for (int i=0; i<(*dset)->numEntries(); i++){ RooArgSet args = *((*dset)->get(i)); float oldw = (*dset)->store()->weight(i); float diphopt = fabs((*dset)->get(i)->getRealValue("roodiphopt")); float neww = oldw*h->GetBinContent(h->FindBin(fabs(diphopt))); newdset->add(args,neww); if(debug){ weight_diphopt->Fill(neww); weight_diphopto->Fill(oldw); weight_diphopt2o->Fill((h->FindBin(fabs(diphopt))),oldw); weight_diphoptn->Fill((h->FindBin(fabs(diphopt))),neww); if(oldw!=0)weight_diphoptnr->Fill(h->FindBin(fabs(diphopt)),oldw/neww); else {weight_diphoptnr->Fill(-10,1);}//cout << "dipho weight old 0" << endl;} if(oldw!=0)weight_diphopt2->Fill(diphopt,oldw/neww); else {weight_diphopt2->Fill(-10,1);}//cout << "dipho weight old 0" << endl;} } } newdset->SetName((*dset)->GetName()); newdset->SetTitle((*dset)->GetTitle()); delete hnum; delete hden; RooDataSet *old_dset = *dset; *dset=newdset; std::cout << "Diphoton Pt 1d rew: norm from " << old_dset->sumEntries() << " to " << newdset->sumEntries() << std::endl; delete old_dset; };
void draw_ratio(std::vector<TH1F*> h, TString name, TString xTitle, double xmin, double xmax, TString legHeader = "", bool legRIGHT = true, bool legTOP = true, bool logX = false, bool stat = false, int rebin = -1, int orbin = -1, TString option = "", int nclus = 99) { //double ymin_ratio, double ymax_ratio, TCanvas* can = new TCanvas(name+"_ratio",name+"_ratio",900,450); can->cd(); double legxmin = (legRIGHT ? 0.55 : 0.18); double legxmax = legxmin+0.25; double legymin = (legTOP ? 0.70 : 0.15); double legymax = legymin+0.15; TLegend* leg = new TLegend(legxmin,legymin,legxmax,legymax); if (legHeader!="") leg->SetHeader(legHeader); leg->SetTextSize(0.04); leg->SetFillColor(0); leg->SetLineColor(0); TString options = (option=="" ? "pe" : option); if (rebin>0) h[h.size()-1]->Rebin(rebin); //to rebin benchmark before divide for (size_t i=0; i<h.size(); i++) { //if(h[i]->GetNbinsX() != orbin) cout << "WARNING: orbin for " << h[i]->GetName() << " are " << h[i]->GetNbinsX() << endl; //debug - shift of h[][] wrt clu[][] if (rebin>0 && i<(h.size()-1)) h[i]->Rebin(rebin); TH1F* ratio = (TH1F*)h[i]->Clone("ratio_"+name); ratio->Sumw2(); ratio->Divide(h[h.size()-1]); //benchmark is at the end. if (logX) gPad->SetLogx(); ratio->SetMarkerStyle(20+i); ratio->SetMarkerSize(1.0); //1.2 ratio->GetXaxis()->SetRangeUser(xmin,xmax); ratio->SetMinimum(-0.1); ratio->SetMaximum(4); if (i==0){ //just for the first one ratio->GetXaxis()->SetLabelSize(0.05); ratio->GetXaxis()->SetTitle(xTitle); ratio->GetXaxis()->SetTitleOffset(1); ratio->GetXaxis()->SetTitleSize(0.06); ratio->GetYaxis()->SetTitle("ratio"); ratio->GetYaxis()->SetTitleSize(0.06); ratio->GetYaxis()->SetTitleOffset(0.7); ratio->GetYaxis()->SetLabelSize(0.05); } string nam = ""; nam = translate(clu[nclus][0].c_str()); if(i==(h.size()-1)) leg->AddEntry(h[i],nam.c_str(),"l"); //to print only benchmark (first in the list) if (i==1) options = options + (stat ? "sames" : "same"); //once is enought ratio->Draw(options); } leg->Draw("same"); drawPrivate(0.04); can->Update(); can->SaveAs(Outfolder+name+"_ratio.png"); }
void findZscale(){ TFile* file1 = new TFile("DoubleEG_prompt.root"); TFile* file2 = new TFile("nob_pt_zelel_cnt_bkg.root"); TH1F* hist1 = (TH1F*)file1->Get("ana/nob_pt_zelel_cnt"); TH1F* hist2 = (TH1F*)file2->Get("total bkg"); TH1F* divided = (TH1F*)hist1->Clone(); divided->Divide(hist1, hist2); gStyle->SetOptStat(0000); divided->GetYaxis()->SetTitle("Data/MC"); divided->Draw("ep"); divided->SaveAs("ElectronFit.root"); }
void compare_Zsub_4253(){ TFile *f42 = new TFile("histo_xsec_dphi_inclusive_DPHI_SCALE_07_42.root"); TH1F *h42 = (TH1F*)(f42->Get("xsec")); TFile *f42up = new TFile("histo_xsec_dphi_inclusive_DPHI_SCALE_1_PURITY_1_42.root"); TH1F *h42up = (TH1F*)(f42up->Get("xsec")); TFile *f42unf = new TFile("histo_finalxs_fortheorycomp_dphi_42.root"); TH1F *h42unf = (TH1F*)(f42unf->Get("histo_finalxs_fortheorycomp_dphi")); h42unf->SetMarkerStyle(1); h42unf->SetLineColor(kBlack); h42unf->SetFillColor(kBlack); h42unf->SetMarkerColor(kBlack); TH1F *h42unforig = (TH1F*)(h42unf->Clone("histo_finalxs_fortheorycomp_dphi_orig")); TFile *f53unf = new TFile("histo_finalxs_fortheorycomp_dphi.root"); TH1F *h53unf = (TH1F*)(f53unf->Get("histo_finalxs_fortheorycomp_dphi")); h53unf->SetMarkerStyle(1); h53unf->SetLineColor(kRed); h53unf->SetFillColor(kRed); h53unf->SetMarkerColor(kRed); TH1F *h53unforig = (TH1F*)(h53unf->Clone("histo_finalxs_fortheorycomp_dphi_orig")); TFile *f53unc = new TFile("histo_systsummaryfinal_individual_dphi_inclusive.root"); TH1F *h53unc = (TH1F*)(f53unc->Get("systplot_zee_allcat")); TH1F *ratio = (TH1F*)(h42->Clone("ratio42")); ratio->Divide(h42up); for (int bin=0; bin<h42->GetNbinsX(); bin++){ float x = h42unf->GetBinContent(bin+1); float r = ratio->GetBinContent(bin+1); h42unf->SetBinError(bin+1,x*fabs(r-1)); cout << r << endl; } for (int bin=0; bin<h53unf->GetNbinsX(); bin++){ float x = h53unf->GetBinContent(bin+1); float e = h53unc->GetBinContent(bin+1); h53unf->SetBinError(bin+1,x*e); } h42unforig->SetFillStyle(3004); h53unforig->SetFillStyle(3005); h42unforig->Draw("E2"); h53unforig->Draw("E2 same"); h42unf->Draw("E1 same"); h53unf->Draw("E1 same"); }
void ZVXT1HF0() { NCanvas(1,1,"data"); NCanvas(1,1,"ratio"); TH1F * HDatHF0; TH1F * HDat; TFile *fzee = new TFile("ZDiffOutputfile_DataOnly_2010_2011.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NVTX1_InstLumiPerBx_DATA10"); HDatHF0 = (TH1F*)fzee->Get("HF0NVTX1_InstLumiPerBx_DATA10"); data->cd(1); HDat->Draw(); NSetTitle(HDat,"Luminosity [10^{-30} cm^{-2} s^{-1}]", "Entries"); HDat->SetTitle("Number of Z produced in events without PU"); HDatHF0->Draw("SAME HIST"); NHSetMarker(HDat,2,20,0.4); TLegend *legend = new TLegend(0.6,0.7,0.9,0.8); legend->SetTextFont(72); legend->SetTextSize(0.03); legend->SetBorderSize(0); legend->AddEntry(HDat,"All Z","p"); legend->AddEntry(HDatHF0,"Z with minE_HF=0","l"); legend->Draw(); TH1F * Hra = (TH1F * ) HDatHF0->Clone(); // Hra->GetXaxis->SetRange(0,12); NStat(Hra,0); Hra->Divide(HDat); NLogAxis(0,1); ratio->cd(1); Hra->Draw(); Hra->SetTitle("Fraction of Z with (PU=0 && E_HF=0)"); Hra->Fit("expo","","",0.,1.2); NSetTitle(Hra,"Luminosity [10^{-30} cm^{-2} s^{-1}]", "Fraction"); NLogAxis(0,1); NText(.05,0.1, "0.62"); NText(0.3,0.1, "2.47"); NText(0.7,0.1, "4.93"); NText(1.1,0.1, "7.4"); NText(1.4,0.1, "<Number of Int.>"); }
void Ef_Branch(){ gROOT->ProcessLine(" .L tdrstyle.C"); setTDRStyle(); gStyle->SetOptStat(0); TH1F *IsoPaftl = new TH1F("IsoPaftl","IsoP cut only",100,0,100); TH1F *IsoPaftlb = new TH1F("IsoPaftlb","IsoP cut only",100,0,100); //Pt dependency IsoPaftl->Divide(EffNp,EffN0,1.,1.,"B"); IsoPaftlb->Divide(EffNpb,EffN0b,1.,1.,"B"); TCanvas *c10 = new TCanvas("c10","Branch Out Cuts",900,600); c10->Divide(3,2); IsoPaftl->Draw(); IsoPaftlb->Draw("same"); IsoPaftl->SetLineColor(kRed); IsoPaftl->SetMarkerColor(kRed); IsoPaftl->SetMarkerSize(0.5); IsoPaftl->GetYaxis()->SetTitle("Only iso P Cut Efficiency"); IsoPaftl->GetXaxis()->SetTitle("Nvtx"); c10->Update(); c10->SaveAs("LCheck.png"); }
void EflowCASTOR() { NCanvas(1,2,"data"); TH1F * HDat; TH1F * HZ2; // TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root"); TFile *fzee = new TFile("ZDiffOutputfile.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_DATA"); HZ2 = (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_Z2PY6"); data->cd(1); NHSetMarker(HDat,2,20,0.8); HDat->SetMinimum(10); HDat->Draw(); NStat(HDat,0); NSetTitle(HDat,"CASTOR Modules", "Entries"); HDat->SetTitle("CASTOR Module Energy 2010"); HZ2->Draw("SAME HIST"); NHSetMarker(HDat,2,20,0.4); TLegend *legend = new TLegend(0.6,0.7,0.9,0.8); legend->SetTextFont(72); legend->SetTextSize(0.06); legend->SetBorderSize(0); legend->AddEntry(HDat,"Data2010","p"); legend->AddEntry(HZ2,"Z2","l"); legend->Draw(); TH1F * Hra = (TH1F * ) HDat->Clone(); // Hra->GetXaxis->SetRange(0,12); NStat(Hra,0); NHSetMarker(Hra,4,20,0.8); Hra->SetMinimum(1); Hra->Divide(HZ2); NLogAxis(0,0); data->cd(2); Hra->Draw(); Hra->SetTitle("Ratio DATA/MC"); Hra->Fit("pol0"); NSetTitle(Hra,"CASTOR Modules", "Ratio"); NLogAxis(0,1); }
std::pair<TH1F*,TH1F*> GetPMSyst(TH1F* trueHist, TH1F* intHist, std::string name){ TH1F *diff = (TH1F*)trueHist->Clone(); diff->Add(intHist,-1); diff->Divide(intHist); diff->Scale(3.); TH1F *up = (TH1F*)intHist->Clone(); up->Add(diff,1); up->SetName((name+"Up01_sigma").c_str()); TH1F *down = (TH1F*)intHist->Clone(); down->Add(diff,-1); down->SetName((name+"Down01_sigma").c_str()); std::pair<TH1F*,TH1F*> result(up,down); return result; }
TH1F *giveEfficiency(TString nomPlot, TString variable, float *theBins, int nbBins){ TH1F *denom = new TH1F("denom", "", nbBins, theBins); TH1F *num = new TH1F("num", "", nbBins, theBins); TString baseCut = "abs(T_Gen_Muon_PDGid)==13&&T_Gen_Muon_Pt>7&&abs(T_Gen_Muon_Eta)<2.4"; chain->Draw(variable+">>denom",baseCut); chain->Draw(variable+">>num",baseCut+"&&T_Gen_Muon_L2crudeMaching==1"); TH1F *efficiency = (TH1F*) denom->Clone(nomPlot); efficiency->Sumw2(); efficiency->Divide(num, denom, 1,1); delete denom; delete num; return efficiency; }
void ZVXT1NVTX() { NCanvas(1,1,"data"); NCanvas(1,1,"ratio"); TH1F * HDatHF0; TH1F * HDat; TFile *fzee = new TFile("ZDiffOutputfile_DataOnly_2010_2011.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NoCuts_InstLumiPerBx_DATA10"); HDatNVTX1 = (TH1F*)fzee->Get("NVTX1_InstLumiPerBx_DATA10"); data->cd(1); HDat->Draw(); NStat(HDat,0); NSetTitle(HDat,"Luminosity [10^{-30} cm^{-2} s^{-1}]", "Entries"); HDat->SetTitle("Z production luminosity"); HDatNVTX1->Draw("SAME HIST"); NHSetMarker(HDat,2,20,0.4); TLegend *legend = new TLegend(0.6,0.7,0.9,0.8); legend->SetTextFont(72); legend->SetTextSize(0.03); legend->SetBorderSize(0); legend->AddEntry(HDat,"All Z","p"); legend->AddEntry(HDatNVTX1,"Z with PU=0","l"); legend->Draw(); TH1F * Hra = (TH1F * ) HDatNVTX1->Clone(); // Hra->GetXaxis->SetRange(0,12); NStat(Hra,0); Hra->Divide(HDat); NLogAxis(0,1); ratio->cd(1); Hra->Draw(); Hra->SetTitle("Fraction of Z with PU=0"); // Hra->Fit("expo","","",0.1,1.2); NSetTitle(Hra,"Luminosity [10^{-30} cm^{-2} s^{-1}]", "Fraction"); NLogAxis(0,1); }
CheckEnabledChannels(const Char_t *runlist) { ifstream is(runlist); Char_t buf[4096]; Int_t run[1024]; Int_t nrun = 0; while(!is.eof()) { is.getline(buf, 4096); if (is.eof()) break; run[nrun] = atoi(buf); printf("added run number %d\n", run[nrun]); nrun++; } printf("%d runs added\n", nrun); is.close(); TH1F *hActive = new TH1F("hActive", "active channels;run;fraction", nrun, 0, nrun); TH1F *hReadout = new TH1F("hReadout", "good readout;run;fraction", nrun, 0, nrun); for (Int_t irun = 0; irun < nrun; irun++) { hr = CheckEnabledChannels(run[irun], kTRUE); ha = CheckEnabledChannels(run[irun], kFALSE); hReadout->SetBinContent(irun + 1, hr->Integral()); hActive->SetBinContent(irun + 1, ha->Integral()); hReadout->GetXaxis()->SetBinLabel(irun + 1, Form("%d", run[irun])); delete hr; delete ha; } hReadout->SetMarkerStyle(20); hReadout->SetMarkerColor(4); hActive->SetMarkerStyle(25); hActive->SetMarkerColor(2); hReadout->Sumw2(); hActive->Sumw2(); hReadout->Divide(hReadout, hActive, 1., 1., "B"); hActive->Scale(1. / 152928.); hReadout->SetMinimum(0.); hReadout->SetMaximum(1.); hReadout->Draw("E"); hActive->Draw("E, same"); TLegend *l = gPad->BuildLegend(); l->SetFillStyle(0); }
void EtaCharged() { NCanvas(1,2,"data"); TH1F * HDatHF0; TH1F * HDat; TFile *fzee = new TFile("ZDiffOutputfile.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NoCuts_max_eta_charged_PF_DATA"); HDatZ2 = (TH1F*)fzee->Get("NoCuts_max_eta_charged_PF_Z2PY6"); data->cd(1); HDat->Draw(); NSetTitle(HDat,"Eta", "Entries"); HDat->SetTitle("EtaMax Charged PrimaryVertex"); HDatZ2->Draw("SAME HIST"); NHSetMarker(HDat,2,20,0.4); TLegend *legend = new TLegend(0.6,0.7,0.9,0.8); legend->SetTextFont(72); legend->SetTextSize(0.06); legend->SetBorderSize(0); legend->AddEntry(HDat,"Data","p"); legend->AddEntry(HDatZ2,"PYTHIA Z2","l"); legend->Draw(); TH1F * Hra = (TH1F * ) HDatZ2->Clone(); // Hra->GetXaxis->SetRange(0,12); NStat(Hra,0); Hra->Divide(HDat); NLogAxis(0,1); data->cd(2); Hra->Draw(); Hra->SetTitle(""); NSetTitle(Hra,"Eta", "Ratio"); NLogAxis(0,0); }
void PoissonianMagic() { TFile file_PUnum("/nfs/dust/cms/user/rathjd/VBF-LS-tau/PU/DataPUFile_22Jan2013ReReco_Run2012.root", "read"); TFile file_PUden("/nfs/dust/cms/user/rathjd/VBF-LS-tau/PU/S10MC_PUFile.root", "read"); TH1F *data = (TH1F*)file_PUnum.Get("analyzeHiMassTau/NVertices_0"); data->Scale(1/data->Integral(0,-1)); TH1F *MC = (TH1F*)file_PUden.Get("analyzeHiMassTau/NVertices_0"); MC->Scale(1/MC->Integral(0,-1)); //define empty histograms for the smeared versions TH1F *num = (TH1F*)data->Clone("ratio"); for(int i=0; i<num->GetNbinsX(); i++) num->SetBinContent(i+1,0); TH1F *den = (TH1F*)data->Clone("MC"); for(int i=0; i<den->GetNbinsX(); i++) den->SetBinContent(i+1,0); //generate the poissonian distributions for(unsigned int i=0; i<data->GetNbinsX(); i++){ TF1 *Pd = new TF1("Pd", "TMath::PoissonI(x,[0])",0,100); Pd->SetParameter(0,data->GetBinLowEdge(i+1)); std::cout<<data->GetBinLowEdge(i+1)<<std::endl; TF1 *Pm = new TF1("Pm", "TMath::PoissonI(x,[0])",0,100); Pm->SetParameter(0,MC->GetBinLowEdge(i+1)); //add up the poissonians for(unsigned int j=0; j<data->GetNbinsX(); j++){ num->SetBinContent(j+1,num->GetBinContent(j+1)+Pd->Eval(j)/Pd->Integral(0,100)*data->GetBinContent(i+1)); den->SetBinContent(j+1,den->GetBinContent(j+1)+Pm->Eval(j)/Pm->Integral(0,100)*MC->GetBinContent(i+1)); } } //make the ratio and save the result num->Divide(den); TFile *f=new TFile("PUreweightHistogram.root","RECREATE"); num->Write(); den->Write(); f->Close(); file_PUnum.Close(); file_PUden.Close(); }
void closureTesterFSR(void) { TString REGIME = ""; //_corr //2D case TFile* g = new TFile("../Inputs/unfold/unfoldData_HLT_Double_2D_NoTRM.root"); g->cd(); TH1F* unfolded = (TH1F*)gDirectory->Get("hunfolded"); //FSR correction TFile* gg = new TFile("../Inputs/FSR/BinByBin.root"); gg->cd(); TH1F* FSRcorr_num = (TH1F*)gDirectory->Get("hpostFSR2"); TH1F* FSRcorr_den = (TH1F*)gDirectory->Get("hpreFSR2"); TH1F* FSRcorr = (TH1F*)FSRcorr_num->Clone(); FSRcorr->Divide(FSRcorr_num,FSRcorr_den); for (int i = 0; i < 132; i++) { unfolded->SetBinContent(i+1,unfolded->GetBinContent(i+1)*FSRcorr->GetBinContent(i+1)); } unfolded->SetMarkerStyle(22); unfolded->GetXaxis()->SetTitle("Bin number"); unfolded->GetYaxis()->SetTitle("Events"); unfolded->Draw("hist"); TH1D* other = (TH1D*)unfolded->Clone(); other->SetMarkerStyle(22); other->SetMarkerColor(kRed); other->SetLineColor(kRed); other->Draw("Psame"); TCanvas* c = new TCanvas(); c->cd(); TH1D* ratio = (TH1D*)unfolded->Clone(); ratio->Divide(other,unfolded); ratio->SetMarkerStyle(22); ratio->GetXaxis()->SetTitle("N_{unfolded}/N_{preunfolded}"); ratio->GetXaxis()->SetTitle("Bin number"); ratio->Draw("P"); }
void MakeCFPlot_pt_eta(TString path) { /// Set Plotting style setTDRStyle(); gStyle->SetPalette(1); TFile * fmc = new TFile(path); if(!fmc){ cout << "No MC file" << endl; return; } vector<TString> hists; hists.push_back("Zpeak_pt_eta1"); hists.push_back("Zpeak_pt_eta2"); for(vector<TString>::iterator it = hists.begin(); it!= hists.end(); it++){ TCanvas* c1 = new TCanvas(("Plot" +*it).Data(), "Plot", 800, 600); /// Make MTelectron_SingleTightElJet plot TH1F* hnum = (TH1F*)fmc->Get(("CFNumerator_"+*it).Data()); TH1F* hden = (TH1F*)fmc->Get(("CFDenominator_"+*it).Data()); hnum->SetLineColor(kRed); hnum->SetLineWidth(2.); hnum->Divide(hden); hnum->Draw("hist"); hnum->GetYaxis()->SetTitle("CF rate"); hnum->GetXaxis()->SetTitle("p_T GeV"); for(int ibin=1; ibin < hnum->GetNbinsX()+1; ibin++){ cout << *it << " bin " << ibin << " value = " << hnum->GetBinContent(ibin) << " error " << hnum->GetBinError(ibin) << endl; } c1->SaveAs(("/home/jalmond/WebPlots/CF/CF_MC" + *it +".pdf").Data()); } }
// Method by pointer TH1F* eff(TH1F* h1, TH1F* h2, const char* name="eff"){ // first, verify that all histograms have same binning // nx is the number of visible bins // nxtot = nx+2 includes underflow and overflow Int_t nx = h1->GetNbinsX(); if (h2->GetNbinsX() != nx) { cout << "Histograms must have same number of bins" << endl; return 0; } // get the new histogram TH1F* temp = (TH1F*) h1->Clone(name); temp->SetTitle(name); temp->Reset(); temp->Sumw2(); // Do the calculation temp->Divide(h2,h1,1.,1.,"B"); // Done return temp; }
TH1F* Ratio(TH1F* h1, TH1F* h2){ TH1F* ratio = (TH1F*) h1->Clone("ratio"); ratio->Divide(h2); int nbin = h1->GetNbinsX(); for (Int_t i = 0; i < nbin; i++){ double sigma1 = h1->GetBinError(i); double sigma2 = h2->GetBinError(i); double x1 = h1->GetBinContent(i); double x2 = h2->GetBinContent(i); double r = ratio->GetBinContent(i); double error =0. ; if (x1 !=0. && x2 !=0.){ error = r * TMath::Sqrt(TMath::Power(sigma1/x1, 2.0) + TMath::Power(sigma2/x2, 2.0)); } ratio->SetBinError(i, error); } return ratio; }//Ratio
void efficiency( TString denfile="60-120.root", TString numfile="orig.root", TString outfile="res.root" ) { gROOT ->Reset(); TFile * nume = new TFile(numfile); TFile * deno = new TFile(denfile); nume->cd("/"); deno->cd("/"); TString theName = "d02-x01-y01"; const TH1F *myNume; nume->GetObject(theName,myNume); myNume->Sumw2(); myNume->Print("all"); const TH1F *myDeno; deno->GetObject(theName,myDeno); myDeno->Sumw2(); myDeno->Print("all"); TH1F *Acce = (TH1F*)myNume->Clone("efficiency"); Acce->Reset(); Double_t f1(1.),f2(1.); Option_t* opt("b"); Acce->Divide(myNume,myDeno,f1,f2,opt); Acce->Print("all"); TFile * out = new TFile(outfile,"NEW"); Acce->Write(); out->Close(); }
TProfile* drawingEff_TnPToyStudy::simpleEff(TObjArray *anum, TObjArray *aden, bool dofixcent) { setTDRStyle(); gStyle->SetEndErrorSize(3); TProfile *tprof = newTProfile((TH1F*) anum->At(0)); for (int i=0; i<anum->GetSize(); i++) { TH1F *hnum = (TH1F*) anum->At(i); TH1F *hden = (TH1F*) aden->At(i); if (dofixcent && !ispbpb) { // set all bin contents to same as the 1st bin fixCentPp(hnum); fixCentPp(hden); } checkUnderFlow(hnum,hden); TH1F *hratio = (TH1F*) hnum->Clone("hratio"); hratio->Divide(hnum,hden,1,1,"B"); fillTProf(tprof,hratio); delete hnum; delete hden; delete hratio; } return tprof; }
/*#include <TSystem.h> // interface to OS #include <TStyle.h> // class to handle ROOT plotting styles#include <TFile.h> // file handle class #include <TTree.h> // class to access ntuples #include <TBenchmark.h> // class to track macro running statistics #include <TH1D.h> // histogram class #include <vector> // STL vector class #include <iostream> // standard I/O #include <iomanip> // functions to format standard I/O #include <fstream> // functions for file I/O #include <string> // C++ string class #include <sstream> // class for parsing strings #include <TRandom3.h> #include <TGaxis.h> #include "Math/LorentzVector.h" // 4-vector class #include "../Utils/MyTools.hh" // various helper functions #include "../Utils/CPlot.hh" // helper class for plots #include "../Utils/MitStyleRemix.hh" // style settings for drawing #include "../Utils/WModels.hh" // definitions of PDFs for fitting #include "../Utils/RecoilCorrector.hh" // class to handle recoil corrections for MET */ void W_MET_Ratio() { TCanvas *c = new TCanvas("c","c",800,800); c->Divide(1,2,0,0); c->cd(1)->SetPad(0,0.3,1.0,1.0); c->cd(1)->SetTopMargin(0.1); c->cd(1)->SetBottomMargin(0.01); c->cd(1)->SetLeftMargin(0.15); c->cd(1)->SetRightMargin(0.07); c->cd(1)->SetTickx(1); c->cd(1)->SetTicky(1); c->cd(2)->SetPad(0,0,1.0,0.3); c->cd(2)->SetTopMargin(0.05); c->cd(2)->SetBottomMargin(0.45); c->cd(2)->SetLeftMargin(0.15); c->cd(2)->SetRightMargin(0.07); c->cd(2)->SetTickx(1); c->cd(2)->SetTicky(1); c->cd(2)->SetGridy(); TLegend * lgc = new TLegend(0.59, 0.67, 0.89, 0.89); lgc->SetTextSize(0.03); lgc->SetBorderSize(0); lgc->SetFillColor(0); // TFile *file = new TFile("../ElectronHighPU/Ele_RD_HighPU_A_Analysis.root"); TFile *file = new TFile("./ElectronHighPU_N/Ele_WToENu_S10_Analysis.root"); ///////////////Original Plot//////////////////////// c->cd(1); lgc->AddEntry(h1_W_Neut_pt1,"UnCorrected"); h1_W_Neut_pt1->SetYTitle("Events"); h1_W_Neut_pt1->SetFillColor(kWhite); h1_W_Neut_pt1->SetMarkerColor(kBlack); h1_W_Neut_pt1->SetMarkerStyle(1); h1_W_Neut_pt1->SetLineWidth(2); h1_W_Neut_pt1->Draw(); lgc->AddEntry(h1_W_Neut_pt_Corr,"Corrected"); h1_W_Neut_pt_Corr->SetLineColor(kRed); h1_W_Neut_pt_Corr->SetFillColor(kWhite); h1_W_Neut_pt_Corr->SetMarkerColor(kRed); h1_W_Neut_pt_Corr->SetMarkerStyle(1); h1_W_Neut_pt_Corr->SetLineWidth(2); h1_W_Neut_pt_Corr->Draw("same"); lgc->Draw(); /////////////////////////////////////////////////////// c->cd(2); TH1F * h1_Ori = (TH1F*)file->Get("h1_W_Neut_pt1"); TH1F * h1_Corr = (TH1F*)file->Get("h1_W_Neut_pt_Corr"); int Nbins = h1_Ori->GetNbinsX(); TH1F * ratio = new TH1F("ratio","", Nbins, h1_Ori->GetXaxis()->GetXmin(), h1_Ori->GetXaxis()->GetXmax()); ratio->Divide(h1_Ori, h1_Corr); ratio->SetXTitle("N_vtx"); ratio->SetMaximum(2); ratio->SetMinimum(0); ratio->SetNdivisions(10,"X"); ratio->SetNdivisions(4,"Y"); ratio->SetLabelSize(0.09,"XY"); ratio->SetTitleSize(0.12,"X"); ratio->SetMarkerStyle(20); ratio->SetMarkerSize(0.7); ratio->SetMarkerColor(kBlue); ratio->Draw("P"); // c->SaveAs("W_MET_Ratio_RD.png"); c->SaveAs("W_MET_Ratio_MC.png"); }
void plotComparison( TH1F* h_dt , TH1F* h_mc , TH1F *h_extra, char* label, bool dolog, bool drawbkg) { TPad* fullpad = new TPad(); TPad* plotpad = new TPad(); TPad* respad = new TPad(); 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 (dolog) plotpad->SetLogy(); h_dt->GetYaxis()->SetTitle("Entries"); h_dt->GetXaxis()->SetTitle(Form("%s", label)); h_dt->GetYaxis()->SetTitleSize(0.05); h_dt->GetXaxis()->SetTitleSize(0.05); h_dt->GetYaxis()->SetTitleOffset(1.5); h_dt->GetXaxis()->SetTitleOffset(1.3); if (!dolog) h_dt->GetYaxis()->SetRangeUser(0., 1.4*h_dt->GetMaximum()); h_dt->SetLineColor(kBlack); h_dt->SetMarkerColor(kBlack); h_mc->SetLineColor(kBlue); h_mc->SetMarkerColor(kBlue); h_extra->SetLineColor(kRed); h_extra->SetLineWidth(2); h_mc->SetLineWidth(2); h_dt->Draw(); h_mc->Draw("HISTSAME"); if (drawbkg) h_extra->Draw("HISTSAME"); h_dt->Draw("ESAME"); TLegend *legComp = new TLegend( 0.653, 0.663, 0.944, 0.870); legComp->AddEntry(h_dt, "Data", "lp"); legComp->AddEntry(h_mc, "MC", "l"); if (drawbkg) legComp->AddEntry(h_extra, "MC Bkg", "l"); legComp->SetFillColor(0); legComp->SetBorderSize(0); legComp->Draw(); TLatex *text = new TLatex(); text->SetNDC(); text->SetTextSize(0.04); // float xtex = 0.65; // text->DrawLatex(xtex,0.88,"1 lepton + jets Sample"); fullpad->cd(); respad = new TPad("respad","respad",0,0.8,1,1); respad->Draw(); respad->cd(); //gPad->SetGridy(); TH1F* ratio = (TH1F*) h_dt->Clone("ratio"); ratio->Divide(h_mc); ratio->GetYaxis()->SetTitleOffset(0.3); ratio->GetYaxis()->SetTitleSize(0.2); ratio->GetYaxis()->SetNdivisions(5); ratio->GetYaxis()->SetLabelSize(0.2); if (dolog) ratio->GetYaxis()->SetRangeUser(0.5,1.5); else ratio->GetYaxis()->SetRangeUser(0.7,1.3); ratio->GetYaxis()->SetTitle("Ratio "); ratio->GetXaxis()->SetLabelSize(0); ratio->GetXaxis()->SetTitleSize(0); ratio->SetMarkerSize(1); ratio->SetLineWidth(2); ratio->SetLineColor(kBlue); ratio->SetMarkerColor(kBlue); ratio->SetFillColor(kBlue); ratio->SetFillStyle(3002); ratio->Draw("E2"); TLine line; line.SetLineWidth(2); line.DrawLine(h_dt->GetXaxis()->GetXmin(),1,h_dt->GetXaxis()->GetXmax(),1); }