//------------------------------------------------------------------------ void DrawWalk() { Int_t npeaks = 20; Int_t sigma=3.; Bool_t down = false; Int_t index[20]; Char_t buf1[10], buf2[10]; TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951); gStyle->SetOptStat(0); c1->Divide(4,3); for (Int_t i=0; i<12; i++) { c1->cd(i+1); sprintf(buf1,"T0_C_%i_CFD",i+1); sprintf(buf2,"CFDvsQTC%i",i+1); cout<<buf1<<" "<<buf2<<endl; TH2F *qtc_cfd = (TH2F*) gFile->Get(buf2); TH1F *cfd = (TH1F*) gFile->Get(buf1); // cfd->Draw(); TSpectrum *s = new TSpectrum(2*npeaks,1); Int_t nfound = s->Search(cfd,sigma," ",0.05); cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;; if(nfound!=0){ Float_t *xpeak = s->GetPositionX(); TMath::Sort(nfound, xpeak, index,down); Float_t xp = xpeak[index[0]]; Int_t xbin = cfd->GetXaxis()->FindBin(xp); Float_t yp = cfd->GetBinContent(xbin); cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[1]<<"\typeak = "<<yp<<endl; Float_t hmax = xp+10*sigma; Float_t hmin = xp-10*sigma; cout<<hmin<< " "<<hmax<<endl; // cfd->GetXaxis()->SetRange(hmin,hmax); // TF1 *g1 = new TF1("g1", "gaus", hmin, hmax); // cfd->Fit("g1","R"); Int_t hminbin= qtc_cfd->GetXaxis()->GetFirst(); Int_t hmaxbin= qtc_cfd->GetXaxis()->GetLast(); Int_t nbins= qtc_cfd->GetXaxis()->GetNbins(); cout<<" qtc_cfd "<<hminbin<<" "<<hmaxbin<<" "<<nbins<<endl; // qtc_cfd->Draw(); TProfile *pr_y = qtc_cfd->ProfileX(); Float_t maxHr=pr_y->GetBinCenter(hmaxbin); pr_y->SetMaximum(hmax); pr_y->SetMinimum(hmin); Int_t np=nbins/20; Double_t *xx = new Double_t[np]; Double_t *yy = new Double_t[np]; Int_t ng=0; Double_t yg=0; for (Int_t ip=1; ip<nbins; ip++) { if(ip%20 != 0 ) { if (pr_y->GetBinContent(ip) !=0) yg +=pr_y->GetBinContent(ip); // cout<<ng<<" "<<pr_y->GetBinContent(ip)<<" "<<yg<<endl; ng++;} else { xx[ip/20] = Float_t (pr_y->GetBinCenter(ip)); yy[ip/20] = yg/ng; yg=0; ng=0; cout<<ip<<" "<<ip/20<<" "<< xx[ip/20]<<" "<< yy[ip/20]<<endl; } } TH2F *hr = new TH2F("hr"," ",np,0,maxHr, np, hmin, hmax); hr->Draw(); TGraph *gr = new TGraph(np,xx,yy); gr->SetMinimum(hmin); gr->SetMaximum(hmax); gr->SetMarkerStyle(20); gr->Draw("P"); // delete [] xx; // delete [] yy; // pr_y->Rebin(10); // pr_y->Draw(); } } }
Int_t DrawPerformanceZDCQAMatch(TString inFile="trending.root"){ // Draw control histograms and generate output pictures gSystem->Load("libSTAT"); gSystem->Load("libANALYSIS"); gSystem->Load("libANALYSISalice"); gSystem->Load("libANALYSIScalib"); gSystem->Load("libCORRFW"); gSystem->Load("libANALYSISalice"); gSystem->Load("libANALYSIScalib"); gSystem->Load("libTender"); gSystem->Load("libPWGPP"); gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetOptStat(0); gStyle->SetTitleSize(0.025); TH1::AddDirectory(kFALSE); TFile * fin = TFile::Open(inFile.Data()); if (!fin){ Printf("File not found !!!"); return -1; } TTree * ttree = (TTree*) fin->Get("trending"); //in TTree * tree = new TTree("tree","tree"); //out (to be summed) if (!ttree){ Printf("Invalid trending tree!!!!!!!!!!!!!!"); return -2; } Int_t nRuns = ttree->GetEntries(); TList list; printf(" nRuns %d\n", nRuns); /*set graphic style*/ gStyle->SetCanvasColor(kWhite); gStyle->SetFrameFillColor(kWhite); gStyle->SetFrameBorderMode(0); gStyle->SetCanvasBorderMode(0); gStyle->SetTitleFillColor(kWhite); gStyle->SetTitleBorderSize(0); gStyle->SetTitleFont(42); gStyle->SetTitleX(0.5); gStyle->SetTitleAlign(23); gStyle->SetTextFont(42); gStyle->SetStatColor(kWhite); gStyle->SetStatBorderSize(1); gStyle->SetOptStat(0); gStyle->SetTickLength(0.02,"y"); gStyle->SetLabelSize(0.02,"xyz"); gStyle->SetLabelOffset(0.03,"xyz"); TString plotDir("."); TLegend *legend = new TLegend(0.9,0.1,1.0,0.9); legend->SetFillColor(kWhite); Int_t runNumber=0; Double_t ZNC_mean=0; Double_t ZNA_mean=0; Double_t ZPA_mean=0; Double_t ZPC_mean=0; Double_t ZNCuncalib_mean=0; Double_t ZNAuncalib_mean=0; Double_t ZPAuncalib_mean=0; Double_t ZPCuncalib_mean=0; Double_t ZEM1_mean=0; Double_t ZEM2_mean=0; Double_t ZNC_XCent=0; Double_t ZNC_YCent=0; Double_t ZNA_XCent=0; Double_t ZNA_YCent=0; Double_t ZNC_XCent_err=0; Double_t ZNC_YCent_err=0; Double_t ZNA_XCent_err=0; Double_t ZNA_YCent_err=0; Double_t ZN_TDC_Sum=0; Double_t ZN_TDC_Diff=0; Double_t ZN_TDC_Sum_err=0; Double_t ZN_TDC_Diff_err=0; Double_t ZNC_TDC=0; Double_t ZNA_TDC=0; TH1F *hZNCpmcUncalib = new TH1F("hZNCpmcUncalib","hZNCpmcUncalib",200.,0.,2000.); TH1F *hZNApmcUncalib = new TH1F("hZNApmcUncalib","hZNApmcUncalib",200.,0.,2000.); TH1F *hZPCpmcUncalib = new TH1F("hZPCpmcUncalib","hZPCpmcUncalib",200.,0.,2000.); TH1F *hZPApmcUncalib = new TH1F("hZPApmcUncalib","hZPApmcUncalib",200.,0.,2000.); TH1F *hZEM1 = new TH1F("hZEM1","hZEM1",200.,0.,2000.); TH1F *hZEM2 = new TH1F("hZEM2","hZEM2",200.,0.,2000.); ttree->SetBranchAddress("run",&runNumber); ttree->SetBranchAddress("ZNC_mean_value",&ZNC_mean); ttree->SetBranchAddress("ZNA_mean_value",&ZNA_mean); ttree->SetBranchAddress("ZPC_mean_value",&ZPC_mean); ttree->SetBranchAddress("ZPA_mean_value",&ZPA_mean); ttree->SetBranchAddress("ZNCuncalib_mean",&ZNCuncalib_mean); ttree->SetBranchAddress("ZNAuncalib_mean",&ZNAuncalib_mean); ttree->SetBranchAddress("ZPCuncalib_mean",&ZPCuncalib_mean); ttree->SetBranchAddress("ZPAuncalib_mean",&ZPAuncalib_mean); ttree->SetBranchAddress("ZEM1_mean_value",&ZEM1_mean); ttree->SetBranchAddress("ZEM2_mean_value",&ZEM2_mean); ttree->SetBranchAddress("ZNC_X_Centroid",&ZNC_XCent); ttree->SetBranchAddress("ZNC_Y_Centroid",&ZNC_YCent); ttree->SetBranchAddress("ZNA_X_Centroid",&ZNA_XCent); ttree->SetBranchAddress("ZNA_Y_Centroid",&ZNA_YCent); ttree->SetBranchAddress("ZNC_X_Centroid_Err",&ZNC_XCent_err); ttree->SetBranchAddress("ZNC_Y_Centroid_Err",&ZNC_YCent_err); ttree->SetBranchAddress("ZNA_X_Centroid_Err",&ZNA_XCent_err); ttree->SetBranchAddress("ZNA_Y_Centroid_Err",&ZNA_YCent_err); ttree->SetBranchAddress("ZN_TDC_Sum",&ZN_TDC_Sum); ttree->SetBranchAddress("ZN_TDC_Diff",&ZN_TDC_Diff); ttree->SetBranchAddress("ZN_TDC_Sum_Err",&ZN_TDC_Sum_err); ttree->SetBranchAddress("ZN_TDC_Diff_Err",&ZN_TDC_Diff_err); //ttree->SetBranchAddress("ZNC_TDC",&ZNC_TDC); //ttree->SetBranchAddress("ZNA_TDC",&ZNA_TDC); printf(" branch addresses set\n"); TH1F *hznc = new TH1F("hznc","ZNC average signal",3,-1,1); hznc->GetXaxis()->SetRangeUser(-1.,1.); hznc->SetDrawOption("EP"); hznc->SetMarkerStyle(20); hznc->SetMarkerColor(kRed); hznc->SetLineColor(kRed); TH1F *hzna = new TH1F("hzna","ZNA average signal",3,-1,1); hzna->GetXaxis()->SetRangeUser(-1.,1.); hzna->SetDrawOption("EP"); hzna->SetMarkerStyle(20); hzna->SetMarkerColor(kRed); hzna->SetLineColor(kRed); TH1F *hzpc = new TH1F("hzpc","ZPC average signal",3,-1,1); hzpc->GetXaxis()->SetRangeUser(-1.,1.); hzpc->SetDrawOption("EP"); hzpc->SetMarkerStyle(20); hzpc->SetMarkerColor(kRed); hzpc->SetLineColor(kRed); TH1F *hzpa = new TH1F("hzpa","ZPA average signal",3,-1,1); hzpa->GetXaxis()->SetRangeUser(-1.,1.); hzpa->SetDrawOption("EP"); hzpa->SetMarkerStyle(20); hzpa->SetMarkerColor(kRed); hzpa->SetLineColor(kRed); TH1F *hzncUncalib = new TH1F("hzncUncalib","ZNC uncalibrated average signal",3,-1,1); hzncUncalib->GetXaxis()->SetRangeUser(-1.,1.); hzncUncalib->SetDrawOption("EP"); hzncUncalib->SetMarkerStyle(20); hzncUncalib->SetMarkerColor(kAzure+10); hzncUncalib->SetLineColor(kAzure+10); TH1F *hznaUncalib = new TH1F("hznaUncalib","ZNA uncalibrated average signal",3,-1,1); hznaUncalib->GetXaxis()->SetRangeUser(-1.,1.); hznaUncalib->SetDrawOption("EP"); hznaUncalib->SetMarkerStyle(20); hznaUncalib->SetMarkerColor(kAzure+10); hznaUncalib->SetLineColor(kAzure+10); TH1F *hzpcUncalib = new TH1F("hzpcUncalib","ZPC uncalibrated average signal",3,-1,1); hzpcUncalib->GetXaxis()->SetRangeUser(-1.,1.); hzpcUncalib->SetDrawOption("EP"); hzpcUncalib->SetMarkerStyle(20); hzpcUncalib->SetMarkerColor(kAzure+10); hzpcUncalib->SetLineColor(kAzure+10); TH1F *hzpaUncalib = new TH1F("hzpaUncalib","ZPA uncalibrated average signal",3,-1,1); hzpaUncalib->GetXaxis()->SetRangeUser(-1.,1.); hzpaUncalib->SetDrawOption("EP"); hzpaUncalib->SetMarkerStyle(20); hzpaUncalib->SetMarkerColor(kAzure+10); hzpaUncalib->SetLineColor(kAzure+10); TH1F *hzem1 = new TH1F("hzem1","ZEM1 average signal",3,-1,1); hzem1->GetXaxis()->SetRangeUser(-1.,1.); hzem1->SetDrawOption("EP"); hzem1->SetMarkerStyle(20); hzem1->SetMarkerColor(kRed); hzem1->SetLineColor(kRed); TH1F *hzem2 = new TH1F("hzem2","ZEM2 average signal",3,-1,1); hzem2->GetXaxis()->SetRangeUser(-1.,1.); hzem2->SetDrawOption("EP"); hzem2->SetMarkerStyle(20); hzem2->SetMarkerColor(kRed); hzem2->SetLineColor(kRed); TH1F *hzna_Xcentroid = new TH1F("hzna_Xcentroid","ZNA X centroid",3,-1,1); hzna_Xcentroid->GetXaxis()->SetRangeUser(-1.,1.); hzna_Xcentroid->SetDrawOption("EP"); hzna_Xcentroid->SetMarkerStyle(20); hzna_Xcentroid->SetMarkerColor(kRed); hzna_Xcentroid->SetLineColor(kRed); TH1F *hzna_Ycentroid = new TH1F("hzna_Ycentroid","ZNA Y centroid",3,-1,1); hzna_Ycentroid->GetXaxis()->SetRangeUser(-1.,1.); hzna_Ycentroid->SetDrawOption("EP"); hzna_Ycentroid->SetMarkerStyle(20); hzna_Ycentroid->SetMarkerColor(kRed); hzna_Ycentroid->SetLineColor(kRed); TH1F *hznc_Xcentroid = new TH1F("hznc_Xcentroid","ZNC X centroid",3,-1,1); hznc_Xcentroid->GetXaxis()->SetRangeUser(-1.,1.); hznc_Xcentroid->SetDrawOption("EP"); hznc_Xcentroid->SetMarkerStyle(20); hznc_Xcentroid->SetMarkerColor(kRed); hznc_Xcentroid->SetLineColor(kRed); TH1F *hznc_Ycentroid = new TH1F("hznc_Ycentroid","ZNC Y centroid",3,-1,1); hznc_Ycentroid->GetXaxis()->SetRangeUser(-1.,1.); hznc_Ycentroid->SetDrawOption("EP"); hznc_Ycentroid->SetMarkerStyle(20); hznc_Ycentroid->SetMarkerColor(kRed); hznc_Ycentroid->SetLineColor(kRed); TH1F *hzn_TDC_Sum = new TH1F("hzn_TDC_Sum","ZNC TDC + ZNA TDC",3,-1,1); hzn_TDC_Sum->GetXaxis()->SetRangeUser(-1.,1.); hzn_TDC_Sum->SetDrawOption("EP"); hzn_TDC_Sum->SetMarkerStyle(20); hzn_TDC_Sum->SetMarkerColor(kRed); hzn_TDC_Sum->SetLineColor(kRed); TH1F *hzn_TDC_Diff = new TH1F("hzn_TDC_Diff","ZNC TDC - ZNA TDC",3,-1,1); hzn_TDC_Diff->GetXaxis()->SetRangeUser(-1.,1.); hzn_TDC_Diff->SetDrawOption("EP"); hzn_TDC_Diff->SetMarkerStyle(20); hzn_TDC_Diff->SetMarkerColor(kRed); hzn_TDC_Diff->SetLineColor(kRed); TH1F *hznc_TDC = new TH1F("hznc_TDC","ZNC TDC",3,-1,1); hznc_TDC->GetXaxis()->SetRangeUser(-1.,1.); hznc_TDC->SetDrawOption("EP"); hznc_TDC->SetMarkerStyle(20); hznc_TDC->SetMarkerColor(kRed); hznc_TDC->SetLineColor(kRed); TH1F *hzna_TDC = new TH1F("hzna_TDC","ZNA TDC",3,-1,1); hzna_TDC->GetXaxis()->SetRangeUser(-1.,1.); hzna_TDC->SetDrawOption("EP"); hzna_TDC->SetMarkerStyle(20); hzna_TDC->SetMarkerColor(kRed); hzna_TDC->SetLineColor(kRed); char runlabel[40]; for (Int_t irun=0;irun<nRuns;irun++){ ttree->GetEntry(irun); } sprintf(runlabel,"%i",runNumber); //---------------------------------------------------------------------- //spectrum vs run //---------------------------------------------------------------------- hZNCpmcUncalib = dynamic_cast<TH1F*> (fin->Get("fhZNCpmcUncalib")); if(hZNCpmcUncalib){ if(hZNCpmcUncalib->GetEntries()>0. ) hZNCpmcUncalib->Scale(1./hZNCpmcUncalib->GetEntries()); hZNCpmcUncalib->SetLineColor(kRed); hZNCpmcUncalib->SetLineWidth(2); hZNCpmcUncalib->SetTitle("ZNC spectrum"); hZNCpmcUncalib->SetXTitle("ZNC signal "); } hZNApmcUncalib = dynamic_cast<TH1F*> (fin->Get("fhZNApmcUncalib")); if(hZNApmcUncalib){ if(hZNApmcUncalib->GetEntries()>0. ) hZNApmcUncalib->Scale(1./hZNApmcUncalib->GetEntries()); hZNApmcUncalib->SetLineColor(kRed); hZNApmcUncalib->SetLineWidth(2); hZNApmcUncalib->SetTitle("ZNA spectrum"); hZNApmcUncalib->SetXTitle("ZNA signal "); } hZPCpmcUncalib = dynamic_cast<TH1F*> (fin->Get("fhZPCpmcUncalib")); if(hZPCpmcUncalib){ if(hZPCpmcUncalib->GetEntries()>0. ) hZPCpmcUncalib->Scale(1./hZPCpmcUncalib->GetEntries()); hZPCpmcUncalib->SetLineColor(kRed); hZPCpmcUncalib->SetLineWidth(2); hZPCpmcUncalib->SetTitle("ZPC spectrum"); hZPCpmcUncalib->SetXTitle("ZPC signal "); } hZPApmcUncalib = dynamic_cast<TH1F*> (fin->Get("fhZPApmcUncalib")); if(hZPApmcUncalib){ if(hZPApmcUncalib->GetEntries()>0. ) hZPApmcUncalib->Scale(1./hZPApmcUncalib->GetEntries()); hZPApmcUncalib->SetLineColor(kRed); hZPApmcUncalib->SetLineWidth(2); hZPApmcUncalib->SetTitle("ZPA spectrum"); hZPApmcUncalib->SetXTitle("ZPA signal "); } hZEM1 = dynamic_cast<TH1F*> (fin->Get("fhZEM1Spectrum")); if(hZEM1){ if(hZEM1->GetEntries()>0.) hZEM1->Scale(1./hZEM1->GetEntries()); hZEM1->SetLineColor(kRed); hZEM1->SetLineWidth(2); hZEM1->SetTitle("ZEM1 spectrum"); hZEM1->SetXTitle("ZEM1 signal (ADC ch.)"); } hZEM2 = dynamic_cast<TH1F*> (fin->Get("fhZEM2Spectrum")); if(hZEM2){ if(hZEM2->GetEntries()>0.) hZEM2->Scale(1./hZEM2->GetEntries()); hZEM2->SetLineColor(kRed); hZEM2->SetLineWidth(2); hZEM2->SetTitle("ZEM2 spectrum"); hZEM2->SetXTitle("ZEM2 signal (ADC ch.)"); } //---------------------------------------------------------------------- //variables vs run //---------------------------------------------------------------------- hzna->SetBinContent(2,ZNA_mean); hzna->GetXaxis()->SetBinLabel(2,runlabel); hzna->GetXaxis()->SetLabelSize(0.05); hzpc->SetBinContent(2,ZPC_mean); hzpc->GetXaxis()->SetBinLabel(2,runlabel); hzpc->GetXaxis()->SetLabelSize(0.05); hznc->SetBinContent(2,ZNC_mean); hznc->GetXaxis()->SetBinLabel(2,runlabel); hznc->GetXaxis()->SetLabelSize(0.05); hzpa->SetBinContent(2,ZPA_mean); hzpa->GetXaxis()->SetBinLabel(2,runlabel); hzpa->GetXaxis()->SetLabelSize(0.05); hznaUncalib->SetBinContent(2,ZNAuncalib_mean); hznaUncalib->GetXaxis()->SetBinLabel(2,runlabel); hznaUncalib->GetXaxis()->SetLabelSize(0.05); hzpcUncalib->SetBinContent(2,ZPCuncalib_mean); hzpcUncalib->GetXaxis()->SetBinLabel(2,runlabel); hzpcUncalib->GetXaxis()->SetLabelSize(0.05); hzncUncalib->SetBinContent(2,ZNCuncalib_mean); hzncUncalib->GetXaxis()->SetBinLabel(2,runlabel); hzncUncalib->GetXaxis()->SetLabelSize(0.05); hzpaUncalib->SetBinContent(2,ZPAuncalib_mean); hzpaUncalib->GetXaxis()->SetBinLabel(2,runlabel); hzpaUncalib->GetXaxis()->SetLabelSize(0.05); hzem1->SetBinContent(2,ZEM1_mean); hzem1->GetXaxis()->SetBinLabel(2,runlabel); hzem1->GetXaxis()->SetLabelSize(0.05); hzem2->SetBinContent(2,ZEM2_mean); hzem2->GetXaxis()->SetBinLabel(2,runlabel); hzem2->GetXaxis()->SetLabelSize(0.05); hzna_Xcentroid->SetBinContent(2,ZNA_XCent); hzna_Xcentroid->SetBinError(2,ZNA_XCent_err); hzna_Xcentroid->GetXaxis()->SetBinLabel(2,runlabel); hzna_Xcentroid->GetXaxis()->SetLabelSize(0.05); hzna_Xcentroid->GetYaxis()->SetTitle("(cm)"); hzna_Ycentroid->SetBinContent(2,ZNA_YCent); hzna_Ycentroid->SetBinError(2,ZNA_YCent_err); hzna_Ycentroid->GetXaxis()->SetBinLabel(2,runlabel); hzna_Ycentroid->GetXaxis()->SetLabelSize(0.05); hzna_Ycentroid->GetYaxis()->SetTitle("(cm)"); hznc_Xcentroid->SetBinContent(2,ZNC_XCent); hznc_Xcentroid->SetBinError(2,ZNC_XCent_err); hznc_Xcentroid->GetXaxis()->SetBinLabel(2,runlabel); hznc_Xcentroid->GetXaxis()->SetLabelSize(0.05); hznc_Xcentroid->GetYaxis()->SetTitle("(cm)"); hznc_Ycentroid->SetBinContent(2,ZNC_YCent); hznc_Ycentroid->SetBinError(2,ZNC_YCent_err); hznc_Ycentroid->GetXaxis()->SetBinLabel(2,runlabel); hznc_Ycentroid->GetXaxis()->SetLabelSize(0.05); hznc_Ycentroid->GetYaxis()->SetTitle("(cm)"); hzn_TDC_Sum->SetBinContent(2,ZN_TDC_Sum); hzn_TDC_Sum->SetBinError(2,ZN_TDC_Sum_err); hzn_TDC_Sum->GetXaxis()->SetBinLabel(2,runlabel); hzn_TDC_Sum->GetXaxis()->SetLabelSize(0.05); hzn_TDC_Sum->GetYaxis()->SetTitle("(ns)"); hzn_TDC_Diff->SetBinContent(2,ZN_TDC_Diff); hzn_TDC_Diff->SetBinError(2,ZN_TDC_Diff_err); hzn_TDC_Diff->GetXaxis()->SetBinLabel(2,runlabel); hzn_TDC_Diff->GetXaxis()->SetLabelSize(0.05); hzn_TDC_Diff->GetYaxis()->SetTitle("(ns)"); hznc_TDC->SetBinContent(2,ZNC_TDC); //hznc_TDC->SetBinError(2,ZNC_TDC_err); hznc_TDC->GetXaxis()->SetBinLabel(2,runlabel); hznc_TDC->GetXaxis()->SetLabelSize(0.05); hznc_TDC->GetYaxis()->SetTitle("(ns)"); hzna_TDC->SetBinContent(2,ZNA_TDC); //hzna_TDC->SetBinError(2,ZNA_TDC_err); hzna_TDC->GetXaxis()->SetBinLabel(2,runlabel); hzna_TDC->GetXaxis()->SetLabelSize(0.05); hzna_TDC->GetYaxis()->SetTitle("(ns)"); //---------------------------------------------------------------------- //spectra //---------------------------------------------------------------------- TCanvas* cZNC_Spectra_Uncal = new TCanvas("cZNC_Spectra_Uncal","cZNC_Spectra_Uncal",0,0,1200,900); if(hZNCpmcUncalib){ gPad->SetLogy(); hZNCpmcUncalib->Draw(); cZNC_Spectra_Uncal->Print(Form("%s/cZNC_Spectra_Uncal.png",plotDir.Data())); } TCanvas* cZNA_Spectra_Uncal = new TCanvas("cZNA_Spectra_Uncal","cZNA_Spectra_Uncal",0,0,1200,900); if(hZNApmcUncalib){ gPad->SetLogy(); hZNApmcUncalib->Draw(); cZNA_Spectra_Uncal->Print(Form("%s/cZNA_Spectra_Uncal.png",plotDir.Data())); } TCanvas* cZPC_Spectra_Uncal = new TCanvas("cZPC_Spectra_Uncal","cZPC_Spectra_Uncal",0,0,1200,900); if(hZPCpmcUncalib){ gPad->SetLogy(); hZPCpmcUncalib->Draw(); cZPC_Spectra_Uncal->Print(Form("%s/cZPC_Spectra_Uncal.png",plotDir.Data())); } TCanvas* cZPA_Spectra_Uncal = new TCanvas("cZPA_Spectra_Uncal","cZPA_Spectra_Uncal",0,0,1200,900); if(hZPApmcUncalib){ gPad->SetLogy(); hZPApmcUncalib->Draw(); cZPA_Spectra_Uncal->Print(Form("%s/cZPA_Spectra_Uncal.png",plotDir.Data())); } TCanvas* cZEM1_Spectra = new TCanvas("cZEM1_Spectra","cZEM1_Spectra",0,0,1200,900); if(hZEM1){ gPad->SetLogy(); hZEM1->Draw(); cZEM1_Spectra->Print(Form("%s/cZEM1_Spectra.png",plotDir.Data())); } TCanvas* cZEM2_Spectra = new TCanvas("cZEM2_Spectra","cZEM2_Spectra",0,0,1200,900); if(hZEM2){ gPad->SetLogy(); hZEM2->Draw(); cZEM2_Spectra->Print(Form("%s/cZEM2_Spectra.png",plotDir.Data())); } //--------------------------------------------------------------------------------------------------- //means //--------------------------------------------------------------------------------------------------- TCanvas* cZNC_Mean_Values = new TCanvas("cZNC_Mean_Values","cZNC_Mean_Values", 0,0,750,900); hznc->Draw("ep"); cZNC_Mean_Values->Print(Form("%s/cZNC_Mean_Values.png",plotDir.Data())); TCanvas* cZNA_Mean_Values = new TCanvas("cZNA_Mean_Values","cZNA_Mean_Values", 0,0,750,900); hzna->Draw("ep"); cZNA_Mean_Values->Print(Form("%s/cZNA_Mean_Values.png",plotDir.Data())); TCanvas* cZPC_Mean_Values = new TCanvas("cZPC_Mean_Values","cZPC_Mean_Values", 0,0,750,900); hzpc->Draw("ep"); cZPC_Mean_Values->Print(Form("%s/cZPC_Mean_Values.png",plotDir.Data())); TCanvas* cZPA_Mean_Values = new TCanvas("cZPA_Mean_Values","cZPA_Mean_Values", 0,0,750,900); hzpa->Draw("ep"); cZPA_Mean_Values->Print(Form("%s/cZPA_Mean_Values.png",plotDir.Data())); TCanvas* cZNC_Mean_Uncalib = new TCanvas("cZNC_Mean_Uncalib","cZNC_Mean_Uncalib", 0,0,750,900); hzncUncalib->Draw("ep"); cZNC_Mean_Uncalib->Print(Form("%s/cZNC_Mean_Uncalib.png",plotDir.Data())); TCanvas* cZNA_Mean_Uncalib = new TCanvas("cZNA_Mean_Uncalib","cZNA_Mean_Uncalib", 0,0,750,900); hznaUncalib->Draw("ep"); cZNA_Mean_Uncalib->Print(Form("%s/cZNA_Mean_Uncalib.png",plotDir.Data())); TCanvas* cZPC_Mean_Uncalib = new TCanvas("cZPC_Mean_Uncalib","cZPC_Mean_Uncalib", 0,0,750,900); hzpcUncalib->Draw("ep"); cZPC_Mean_Uncalib->Print(Form("%s/cZPC_Mean_Uncalib.png",plotDir.Data())); TCanvas* cZPA_Mean_Uncalib = new TCanvas("cZPA_Mean_Uncalib","cZPA_Mean_Uncalib", 0,0,750,900); hzpaUncalib->Draw("ep"); cZPA_Mean_Uncalib->Print(Form("%s/cZPA_Mean_Uncalib.png",plotDir.Data())); TCanvas* cZEM1_Mean_Values = new TCanvas("cZEM1_Mean_Values","cZEM1_Mean_Values", 0,0,750,900); hzem1->Draw("ep"); cZEM1_Mean_Values->Print(Form("%s/cZEM1_Mean_Values.png",plotDir.Data())); TCanvas* cZEM2_Mean_Values = new TCanvas("cZEM2_Mean_Values","cZEM2_Mean_Values", 0,0,750,900); hzem2->Draw("ep"); cZEM2_Mean_Values->Print(Form("%s/cZEM2_Mean_Values.png",plotDir.Data())); //--------------------------------------------------------------------------------------------------- //centroids //--------------------------------------------------------------------------------------------------- TCanvas* cZNA_X_centroid = new TCanvas("cZNA_X_centroid","cZNA_X_centroid", 0,0,750,900); hzna_Xcentroid->Draw(); cZNA_X_centroid->Print(Form("%s/cZNA_X_centroid.png",plotDir.Data())); TCanvas* cZNA_Y_centroid = new TCanvas("cZNA_Y_centroid","cZNA_Y_centroid", 0,0,750,900); hzna_Ycentroid->Draw(); cZNA_Y_centroid->Print(Form("%s/cZNA_Y_centroid.png",plotDir.Data())); TCanvas* cZNC_X_centroid = new TCanvas("cZNC_X_centroid","cZNC_X_centroid", 0,0,750,900); hznc_Xcentroid->Draw(); cZNC_X_centroid->Print(Form("%s/cZNC_X_centroid.png",plotDir.Data())); TCanvas* cZNC_Y_centroid = new TCanvas("cZNC_Y_centroid","cZNC_Y_centroid", 0,0,750,900); hznc_Ycentroid->Draw(); cZNC_Y_centroid->Print(Form("%s/cZNC_Y_centroid.png",plotDir.Data())); //--------------------------------------------------------------------------------- //timing //--------------------------------------------------------------------------------- TCanvas* cTimingSum = new TCanvas("cTimingSum","cTimingSum",0,0,750,900); hzn_TDC_Sum->Draw(); cTimingSum->Print(Form("%s/cTimingSum.png",plotDir.Data())); TCanvas* cTimingDiff = new TCanvas("cTimingDiff","cTimingDiff",0,0,750,900); hzn_TDC_Diff->Draw(); cTimingDiff->Print(Form("%s/cTimingDiff.png",plotDir.Data())); //---------------------------------------------------------------------- //out //---------------------------------------------------------------------- printf(" preparing output tree\n"); tree->Branch("run",&runNumber,"runNumber/I"); tree->Branch("ZNC_mean_value",&ZNC_mean,"ZNC_mean/D"); tree->Branch("ZNA_mean_value",&ZNA_mean,"ZNA_mean/D"); tree->Branch("ZPC_mean_value",&ZPC_mean,"ZPC_mean/D"); tree->Branch("ZPA_mean_value",&ZPA_mean,"ZPA_mean/D"); tree->Branch("ZNC_mean_uncalib",&ZNCuncalib_mean,"ZNCuncalib_mean/D"); tree->Branch("ZNA_mean_uncalib",&ZNAuncalib_mean,"ZNAuncalib_mean/D"); tree->Branch("ZPC_mean_uncalib",&ZPCuncalib_mean,"ZPCuncalib_mean/D"); tree->Branch("ZPA_mean_uncalib",&ZPAuncalib_mean,"ZPAuncalib_mean/D"); tree->Branch("ZEM1_mean_value",&ZEM1_mean,"ZEM1_mean/D"); tree->Branch("ZEM2_mean_value",&ZEM2_mean,"ZEM2_mean/D"); tree->Branch("ZNC_X_Centroid",&ZNC_XCent,"ZNC_XCent/D"); tree->Branch("ZNC_Y_Centroid",&ZNC_YCent,"ZNC_YCent/D"); tree->Branch("ZNA_X_Centroid",&ZNA_XCent,"ZNA_XCent/D"); tree->Branch("ZNA_Y_Centroid",&ZNA_YCent,"ZNA_YCent/D"); tree->Branch("ZNC_X_Centroid_Err",&ZNC_XCent_err,"ZNC_XCent_err/D"); tree->Branch("ZNC_Y_Centroid_Err",&ZNC_YCent_err,"ZNC_YCent_err/D"); tree->Branch("ZNA_X_Centroid_Err",&ZNA_XCent_err,"ZNA_XCent_err/D"); tree->Branch("ZNA_Y_Centroid_Err",&ZNA_YCent_err,"ZNA_YCent_err/D"); tree->Branch("ZN_TDC_Sum",&ZN_TDC_Sum,"ZN_TDC_Sum/D"); tree->Branch("ZN_TDC_Diff",&ZN_TDC_Diff,"ZN_TDC_Diff/D"); tree->Branch("ZN_TDC_Sum_Err",&ZN_TDC_Sum_err,"ZN_TDC_Sum_err/D"); tree->Branch("ZN_TDC_Diff_Err",&ZN_TDC_Diff_err,"ZN_TDC_Diff_err/D"); tree->Fill(); if(hZNCpmcUncalib) list.Add(cZNC_Spectra_Uncal); if(hZNApmcUncalib) list.Add(cZNA_Spectra_Uncal); if(hZPCpmcUncalib) list.Add(cZPC_Spectra_Uncal); if(hZPApmcUncalib) list.Add(cZPA_Spectra_Uncal); list.Add(cZEM1_Spectra); list.Add(cZEM2_Spectra); list.Add(cTimingSum); list.Add(cTimingDiff); list.Add(cZNA_X_centroid); list.Add(cZNA_Y_centroid); list.Add(cZNC_X_centroid); list.Add(cZNC_Y_centroid); TFile *fout; fout = TFile::Open("prodQAhistos.root", "update"); if(!fout) fout = new TFile("prodQAhistos.root"); fout->cd(); list.Write(); tree->Write(); fout->Close(); return 0; }
void Getvn2D(bool usingCNTEP=0){ TString str; TFile *fin; int nrun = GetTotalRun(); std::cout<<"Totally we have "<<nrun<<" runs/segments!"<<std::endl; FillGoodRun(); std::cout<<"Filling Good run finished!"<<std::endl; if(nrun<0) exit(1); ofstream fout, foutraw, fout1, fout2; int iharE=0; if(nhar==1||nhar==2) iharE=1; for(int icent=0;icent<ncent;icent++){ for(int ihar=0;ihar<nhar;ihar++){ if(icent!=0) continue; for(int isub=0;isub<nsub;isub++){ int n = ihar+1.0+iharE; str = choosesub(isub); TString UseCNTEP; if(str=="ABORT") continue; if(usingCNTEP) UseCNTEP = "UseCNTEP"; else UseCNTEP = "NoUseCNTEP"; std::cout<<UseCNTEP<<std::endl; std::cout<<"starting doing "<<str<<" v"<<n<<" analysis!"<<std::endl; cout<<Form("Result/%s/res%d_%d_%s.dat",UseCNTEP.Data(),n,icent,str.Data())<<endl; fout1.open(Form("Result/%s/res%d_%d_%s.dat",UseCNTEP.Data(),n,icent,str.Data())); //using str as event plane detector fout2.open(Form("Result/%s/psi%d_%d_%s.dat",UseCNTEP.Data(),n,icent,str.Data())); //using str as event plane detector float reso = GetReso(icent,ihar,isub,usingCNTEP); fout1<<reso<<std::endl; if(reso<0) {std::cout<<"resolution is wrong!"<<std::endl; reso = -9999;} for(int irun=0;irun<nrun;irun++){ fout2<<GetRun(irun)<<" "<<GoodRunFit[icent][ihar][isub][irun]<<std::endl; } TH2F* hvobsall = new TH2F(Form("hvobs_%d_%d_%d",icent,ihar,isub),Form("hvobs_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); // TH2F* hvobsallsq = new TH2F(Form("hvobssq_%d_%d_%d",icent,ihar,isub),Form("hvobssq_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); for(int iphi=0;iphi<nphi+1;iphi++){ TH2F* hvobs = new TH2F(Form("hvobs_%d_%d_%d_%d",icent,ihar,isub,iphi),Form("hvobs_%d_%d_%d_%d",icent,ihar,isub,iphi),60,0,6,220,-1.1,1.1); // TH2F* hvobssq = new TH2F(Form("hvobssq_%d_%d_%d_%d",icent,ihar,isub,iphi),Form("hvobssq_%d_%d_%d_%d",icent,ihar,isub,iphi),60,0,6,220,-1.1,1.1); string phistr = (iphi==0)?"_east":"_west"; if(iphi==nphi) phistr = ""; cout<<"open v2 file"<<endl; fout.open(Form("Result/%s/v%d_%d%s_%s.dat",UseCNTEP.Data(),n,icent,phistr.c_str(),str.Data())); //using str as event plane detector cout<<"open v2raw file"<<endl; foutraw.open(Form("Result/%s/v%draw_%d%s_%s.dat",UseCNTEP.Data(),n,icent,phistr.c_str(),str.Data())); //using str as event plane detector if(iphi<nphi){ for(int irun=0;irun<nrun;irun++){ //std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<irun<<" "<<phistr<<std::endl; //fin = TFile::Open(Form("/phenix/plhf/xuq/taxi/%s%s/%d/data/%s.root",dataset.Data(),pro.Data(),taxi,GetRun(irun).Data())); //fin = TFile::Open(Form("/gpfs/mnt/gpfs02/phenix/plhf/plhf1/xuq/phenix/flow/Run16dAu/work/39GeV/output/%s",GetRun(irun).Data())); fin = TFile::Open(Form("/gpfs/mnt/gpfs02/phenix/plhf/plhf1/xuq/phenix/flow/Run16dAu/work/39GeV/treeout/%s",GetRun(irun).Data())); if(!(GoodRunFit[icent][ihar][isub][irun]>0.2 && GoodRunFit[icent][ihar][isub][irun]<3.0)){ std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<GetRun(irun)<<" is bad run!"<<std::endl; fin->Close(); continue; } TH2F* hvobstemp = (TH2F*)fin->Get(Form("vobs%s_0_0_%d_%d_%d",str.Data(),icent,ihar,iphi)); //TH2F* hvobssqtemp = (TH2F*)fin->Get(Form("vobs%ssq_%d_%d_%d",str.Data(),icent,ihar,iphi)); hvobs->Add(hvobstemp); //hvobssq->Add(hvobssqtemp); fin->Close(); } } hvobsall->Add(hvobs); //hvobsallsq->Add(hvobssq); if(iphi==nphi){ hvobs = hvobsall; //hvobssq = hvobsallsq; } TH1F* ptProj = (TH1F*)hvobs->ProjectionX(Form("hptProj"),0,-1); for(int ipt=0;ipt<npt-1;ipt++){ int xbinmin = hvobs->GetXaxis()->FindBin(ptbin[ipt]+eps); int xbinmax = hvobs->GetXaxis()->FindBin(ptbin[ipt+1]-eps); // std::cout<<xbinmin<<" "<<xbinmax<<std::endl; // std::cout<<ptbin[ipt]<<" "<<ptbin[ipt+1]<<std::endl; TH1F* hvobsProj = (TH1F*)hvobs->ProjectionY(Form("hvobsProj_%d",ipt),xbinmin,xbinmax); // TH1F* hvobssqProj = (TH1F*)hvobssq->ProjectionY(Form("hvobssqProj_%d",ipt),xbinmin,xbinmax); float vobs = hvobsProj->GetMean(); float Ntracks = hvobsProj->Integral(); // float vobssq = hvobssqProj->GetMean(); float v = vobs/reso; if(Ntracks>0) float verr = hvobsProj->GetRMS()/reso/sqrt(Ntracks); else verr = -9999; // float verr = sqrt(vobssq/reso/reso-(v*v))/sqrt(Ntracks); ptProj->GetXaxis()->SetRangeUser(ptbin[ipt]+eps,ptbin[ipt+1]-eps); float pt = ptProj->GetMean(); fout<<pt<<" "<<v<<" "<<verr<<" "<<std::endl; foutraw<<pt<<" "<<vobs<<" "<<verr*reso<<" "<<std::endl; } fout.close(); foutraw.close(); } fout1.close(); fout2.close(); } } } }
void readTree_background() { Char_t *filename = "Background.root"; // Retrieve the TTree TFile* myFile = TFile::Open(filename); TTree* tree = (TTree*)(myFile->Get("tree")); Double_t Et1, eta1, phi1, Et2, eta2, phi2; tree->SetBranchAddress("Et1" ,&Et1 ); tree->SetBranchAddress("eta1",&eta1); tree->SetBranchAddress("phi1",&phi1); tree->SetBranchAddress("Et2" ,&Et2 ); tree->SetBranchAddress("eta2",&eta2); tree->SetBranchAddress("phi2",&phi2); // Book histograms TH1F* hmass = new TH1F("hmass","m_{#gamma#gamma}",60,100.,160.); hmass->GetXaxis()->SetTitle("Invariant mass [GeV]"); hmass->GetYaxis()->SetTitle("Events"); // Loop over the events Long64_t events = tree->GetEntries(); for (int i=0; i<events; i++) { tree->GetEntry(i); TLorentzVector g1,g2; g1.SetPtEtaPhiM(Et1,eta1,phi1,0.); g2.SetPtEtaPhiM(Et2,eta2,phi2,0.); TLorentzVector gg=g1+g2; hmass->Fill( gg.M() ); } // Test of different background options hmass->DrawClone("e"); TCanvas* myCanvas = new TCanvas("myCanvas","Background fits",800,800); myCanvas->Divide(2,2); // Linear background TF1* myBack1 = new TF1("myBack1","[0]+[1]*x",100.,160.); myBack1->SetParameter(0,events); myBack1->SetParameter(1,-100.); myCanvas->cd(1); hmass->Fit(myBack1); hmass->DrawClone("e"); EvaluatePvalue(myBack1); // Quadratic background TF1* myBack2 = new TF1("myBack2","[0]+[1]*x+[2]*x**2",100.,160.); myBack2->SetParameter(0,events); myBack2->SetParameter(1,-100.); myBack2->SetParameter(1,0.); myCanvas->cd(2); hmass->Fit(myBack2); hmass->DrawClone("e"); EvaluatePvalue(myBack2); // Exponential background TF1* myBack3 = new TF1("myBack3","[0]*exp(-x/[1])",100.,160.); myBack3->SetParameter(0,events); myBack3->SetParameter(1,100.); myCanvas->cd(3); hmass->Fit(myBack3); hmass->DrawClone("e"); EvaluatePvalue(myBack3); // Cubic background TF1* myBack4 = new TF1("myBack4","[0]+[1]*x+[2]*x**2+[3]*x**3",100.,160.); myBack4->SetParameter(0,0.); myBack4->SetParameter(1,0.); myBack4->SetParameter(2,0.); myBack4->SetParameter(3,0.); myCanvas->cd(4); TFitResultPtr fit4 = hmass->Fit(myBack4,"S"); hmass->DrawClone("e"); EvaluatePvalue(myBack4); }
void fake() { gROOT->SetBatch(); gROOT->SetStyle("Plain"); gStyle->SetOptStat(0); SetStyle(); TCanvas *c1 = new TCanvas("c1","c1",0,0,600,500); c1->Draw(); c1->cd(); TPad *c1_1; gStyle->SetHistTopMargin(0); TLegend *leg = new TLegend(0.65,0.90,0.90,0.70); leg->SetFillColor(253); leg->SetBorderSize(0); std::string fpath = "histTEST_MERGED/QCD_Pt_170to300_TuneCUETP8M1_13TeV_pythia8/data.root"; // std::string histnameFake = "h_muFake_pt"; // std::string histnameReal = "h_muReal_pt"; // std::string histnameFake = "h_muFake_trackerLayersWithMeasurement"; // std::string histnameReal = "h_muReal_trackerLayersWithMeasurement"; // std::string histnameFake = "h_muFake_numberOfValidMuonHits"; // std::string histnameReal = "h_muReal_numberOfValidMuonHits"; // std::string histnameFake = "h_muFake_numberOfMatches"; // std::string histnameReal = "h_muReal_numberOfMatches"; // std::string histnameFake = "h_muFake_numberOfMatchedStations"; // std::string histnameReal = "h_muReal_numberOfMatchedStations"; // std::string histnameFake = "h_muFake_numberOfValidHits"; // std::string histnameReal = "h_muReal_numberOfValidHits"; // std::string histnameFake = "h_muFake_numberOfValidPixelHits"; // std::string histnameReal = "h_muReal_numberOfValidPixelHits"; std::string histnameFake = "h_muFake_numberOfHits"; std::string histnameReal = "h_muReal_numberOfHits"; // std::string histnameFake = "h_muFake_normalizedChi2GlobalTrack"; // std::string histnameReal = "h_muReal_normalizedChi2GlobalTrack"; // std::string histnameFake = "h_muFake_normalizedChi2InnerTrack"; // std::string histnameReal = "h_muReal_normalizedChi2InnerTrack"; TFile *f; TH1D *hFake; TH1D *hReal; f = TFile::Open(fpath.c_str()); { TH1D *hFake_c = (TH1D*)f->Get(histnameFake.c_str()); hFake_c->SetMarkerSize(0.0); TH1D *hReal_c = (TH1D*)f->Get(histnameReal.c_str()); hReal_c->SetMarkerSize(0.0); hFake = (TH1D*)hFake_c->Clone("hFake"); hReal = (TH1D*)hReal_c->Clone("hReal"); } addbin(hFake); addbin(hReal); std::cout << hReal->Integral() << std::endl; std::cout << hFake->Integral() << std::endl; double iFake = hFake->Integral(); double iReal = hReal->Integral(); // double iAll = iFake+iReal; // hFake->Scale(1./iAll); // hReal->Scale(1./iAll); hFake->SetLineColor(9); hFake->SetFillColor(9); hReal->SetLineColor(46); hReal->SetFillColor(46); THStack *hst = new THStack(); hst->Add(hReal); hst->Add(hFake); hst->Draw("hist e1"); float max = hst->GetMaximum(); hst->SetMaximum(1.3*max); hst->SetMinimum(0.); if( histnameFake == "h_muFake_pt" ) hst->GetXaxis()->SetTitle("p_{T} [GeV]"); hst->GetYaxis()->SetTitle("Number of muons"); leg->AddEntry(hFake,"Fake","f"); leg->AddEntry(hReal,"Real","f"); leg->Draw(); c1->Print("pics/fake.eps"); c1->Clear(); TH1F *hRealScaled = (TH1F*)hReal->Clone("hRealScaled"); hRealScaled->Scale(1./iReal); TH1F *hFakeScaled = (TH1F*)hFake->Clone("hFakeScaled"); hFakeScaled->Scale(1./iFake); hFakeScaled->SetLineColor(9); hFakeScaled->SetFillColor(0); hRealScaled->SetLineColor(46); hRealScaled->SetFillColor(0); hRealScaled->Draw("hist e1"); hFakeScaled->Draw("hist e1 same"); float max1 = hRealScaled->GetMaximum(); float max2 = hFakeScaled->GetMaximum(); max = (max1 > max2) ? max1 : max2; hRealScaled->SetMaximum(1.3*max); hRealScaled->SetMinimum(0.); if( histnameFake == "h_muFake_pt" ) hRealScaled->GetXaxis()->SetTitle("p_{T} [GeV]"); if( histnameFake == "h_muFake_trackerLayersWithMeasurement" ) hRealScaled->GetXaxis()->SetTitle("trackerLayersWithMeasurement"); if( histnameFake == "h_muFake_numberOfValidMuonHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidMuonHits"); if( histnameFake == "h_muFake_numberOfMatches" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatches"); if( histnameFake == "h_muFake_numberOfMatchedStations" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatchedStations"); if( histnameFake == "h_muFake_numberOfValidHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidHits"); if( histnameFake == "h_muFake_numberOfValidPixelHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidPixelHits"); if( histnameFake == "h_muFake_numberOfHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfHits"); if( histnameFake == "h_muFake_normalizedChi2GlobalTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2GlobalTrack"); if( histnameFake == "h_muFake_normalizedChi2InnerTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2InnerTrack"); hRealScaled->GetYaxis()->SetTitle("Normalized to unity"); leg->Draw(); c1->Print("pics/fakeComp.eps"); c1->Clear(); gApplication->Terminate(); }
void plotFit(TString filename = "fp-d", TString pltmd = "tph") { // CHECK FOR RIGHT INPUT //////////////////////////////////////////////// string strpltmd = pltmd; if( strpltmd.compare("tph") != 0 && strpltmd.compare("s2b") != 0 && strpltmd.compare("mmp") != 0 ) {error(4);}; // OPEN THE ROOT FILE ////////////////////////////////////////////////// gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetTitleBorderSize(0); gStyle->SetPalette(1); TCanvas *MyC = new TCanvas("MyC","Plot of the GAPP fit",200,10,700,500); // Still to do: Automate the frame boundaries. string strfile = filename, rootname = strfile + ".root"; TFile *rootfile = TFile::Open(rootname.c_str()); if(rootfile == NULL) error(1); TTree *tree = (TTree*)rootfile->Get(strfile.c_str()); if(tree == NULL) error(2); TBranch *fits2bbranch = (TBranch*)tree->GetBranch("fits2b"); TBranch *fittphbranch = (TBranch*)tree->GetBranch("fittph"); TBranch *fitxbranch = (TBranch*)tree->GetBranch("fitx"); if( (fits2bbranch == NULL) || (fittphbranch == NULL) || (fitxbranch == NULL) ) error(3); Float_t fits2b, fittph, fitx; tree->SetBranchAddress("fits2b",&fits2b); tree->SetBranchAddress("fittph",&fittph); tree->SetBranchAddress("fitx", &fitx); // GET GRID ///////////////////////////////////////////////////////////// Int_t Npoints = (Int_t)tree->GetEntries(); Int_t point, zSteps = 0, ySteps = 0; Float_t fitxMin = 100000, fitxMax = -1.0, s2bMin = 100000, tphMin = 100000; Float_t s2bMax = -1.0, tphMax = -1.0; for(point=0; point<Npoints; point++) { tree->GetEntry(point); if( fits2b > s2bMax ) {zSteps++; s2bMax = fits2b;} if( fittph > tphMax ) {ySteps++; tphMax = fittph;} }; const int s2bSteps = zSteps, tphSteps = ySteps, mmpSteps = Npoints; Float_t s2bValues[s2bSteps], tphValues[tphSteps]; s2bMax = -1.0, tphMax = -1.0; int s2bStep = 0, tphStep = 0; for(point=0; point<Npoints; point++) { tree->GetEntry(point); if( fits2b > s2bMax ) {s2bValues[s2bStep] = fits2b; s2bStep++; s2bMax = fits2b;} if( fittph > tphMax ) {tphValues[tphStep] = fittph; tphStep++; tphMax = fittph;} }; // PREPARE PLOT ///////////////////////////////////////////////////////// string plottitle = "Model: " + strfile + " | Plot: "; if( strpltmd.compare("tph") == 0 ) { plottitle += "tan^{2}(#phi) over x for fixed sin^{2}(2#beta)"; } if( strpltmd.compare("s2b") == 0 ) { plottitle += "sin^{2}(2#beta) over x for fixed tan^{2}(#phi)"; } if( strpltmd.compare("mmp") == 0 ) { plottitle += "Masses of the new heavy gauge bosons"; } // PLOT DATA /////////////////////////////////////////////////////////// if (strpltmd.compare("tph") == 0) { tphMax = -1.0; // TGraph *tphplots[s2bSteps]; TGraph *tphplots[s2bSteps-30]; // for(s2bStep=0; s2bStep<s2bSteps; s2bStep++) { for(s2bStep=0; s2bStep<s2bSteps-30; s2bStep++) { Float_t tphArray[tphSteps], fitxArray[tphSteps]; tphStep = 0; for(point=0; point<Npoints; point++) { tree->GetEntry(point); if(fits2b == s2bValues[s2bStep]) { // tphArray[tphStep] = fittph; tphArray[tphStep] = sqrt(1.0/(1.0+fittph)); if (fittph < tphMin) tphMin = fittph; if (fittph > tphMax) tphMax = fittph; fitxArray[tphStep] = fitx; if (fitx < fitxMin) fitxMin = fitx; if (fitx > fitxMax) fitxMax = fitx; tphStep++; TMarker *m = new TMarker(fitxArray[tphStep],tphArray[tphStep],20); m->SetMarkerSize(2); m->SetMarkerColor(31+tphStep); m->Draw(); } } if (s2bStep == 0) { TH1F* frame = MyC->DrawFrame(0.0,0.0,1.1*fitxMax,1.1); // TH1F* frame = MyC->DrawFrame(0.7*fitxMin,0.7*tphMin,1.1*fitxMax,1.1*tphMax); TAxis *xaxis = frame->GetXaxis(); TAxis *yaxis = frame->GetYaxis(); xaxis->SetTitle("x = u^{2}/v^{2}"); xaxis->CenterTitle(); xaxis->SetTitleOffset(1.); xaxis->SetDecimals(); xaxis->SetLabelSize(0.03); xaxis->SetLabelOffset(0.01); yaxis->SetTitle("tan^{2}(#phi)"); yaxis->CenterTitle(); yaxis->SetTitleOffset(1.); yaxis->SetDecimals(); yaxis->SetLabelSize(0.03); yaxis->SetLabelOffset(0.01); frame->SetTitle(plottitle.c_str()); } tphplots[s2bStep] = new TGraph(tphSteps,fitxArray,tphArray); tphplots[s2bStep]->SetMarkerStyle(20); tphplots[s2bStep]->SetMarkerSize(0.4); tphplots[s2bStep]->Draw("CP"); } } else if (strpltmd.compare("s2b") == 0) { s2bMax = -1.0; TGraph *s2bplots[tphSteps-100]; for(tphStep=0; tphStep<tphSteps-100; tphStep++) { Float_t s2bArray[s2bSteps], fitxArray[s2bSteps]; s2bStep = 0; for(point=0; point<Npoints; point++) { tree->GetEntry(point); if(fittph == tphValues[tphStep+20]) { s2bArray[s2bStep] = fits2b; if (fits2b < s2bMin) s2bMin = fits2b; if (fits2b > s2bMax) s2bMax = fits2b; fitxArray[s2bStep] = fitx; if (fitx < fitxMin) fitxMin = fitx; if (fitx > fitxMax) fitxMax = fitx; s2bStep++; } } if (tphStep == 0) { TH1F* frame = MyC->DrawFrame(0.8*fitxMin,0.95*s2bMin,1.2*fitxMax,1.05*s2bMax); TAxis *xaxis = frame->GetXaxis(); TAxis *yaxis = frame->GetYaxis(); xaxis->SetTitle("x = u^{2}/v^{2}"); xaxis->CenterTitle(); xaxis->SetTitleOffset(1.); xaxis->SetDecimals(); xaxis->SetLabelSize(0.03); xaxis->SetLabelOffset(0.01); yaxis->SetTitle("sin^{2}(2#beta)"); yaxis->CenterTitle(); yaxis->SetTitleOffset(1.25); yaxis->SetDecimals(); yaxis->SetLabelSize(0.03); yaxis->SetLabelOffset(0.01); frame->SetTitle(plottitle.c_str()); } s2bplots[tphStep] = new TGraph(s2bSteps,fitxArray,s2bArray); s2bplots[tphStep]->SetMarkerStyle(20); s2bplots[tphStep]->SetMarkerSize(0.4); s2bplots[tphStep]->Draw("C"); } } else if (strpltmd.compare("mmp") == 0) { Float_t mzpArray[mmpSteps], mwpArray[mmpSteps]; Float_t mzpMin = 100000, mzpMax = -1.0, mwpMin = 100000, mwpMax = -1.0; Float_t fitsph, fitcph; Float_t Cz1, Cz2, Cz3, Cw1, Cw2, Cw3, Cw4, C1, C2; string mdl(strfile,0,2); if ( (mdl.compare("lr") == 0) || (mdl.compare("lp") == 0) || (mdl.compare("hp") == 0) || (mdl.compare("fp") == 0) ) { string Higgs(strfile,3,1); if (Higgs.compare("d") == 0) { Cz1 = 11.95349795785275; Cz2 = 30.63269990028513; Cz3 = 42.58619785813789; Cw1 = 21.29309892906894; Cw2 = 9.339600971216193; Cw3 = 30.63269990028513; Cw4 = 42.58619785813789; } else if (Higgs.compare("t") == 0) { Cz1 = 5.976748978926375; Cz2 = 30.63269990028513; Cz3 = 85.17239571627579; Cw1 = 15.05649464522066; Cw2 = 3.302047590161717; Cw3 = 21.66058982554409; Cw4 = 60.22597858088265; } else {error(6);} for(point=0; point<Npoints; point++) { tree->GetEntry(point); fitsph = fittph / (1.0 + fittph); fitcph = 1.0 - fitsph; if (fitsph != 0.0) { mzpArray[point] = (0.001/sqrt(fitsph*fitcph*fitx)) * (Cz1*fitcph*fitcph + Cz2*fits2b + Cz3*fitx); if (mzpArray[point] < mzpMin) mzpMin = mzpArray[point]; if (mzpArray[point] > mzpMax) mzpMax = mzpArray[point]; mwpArray[point] = (0.001/sqrt(fitsph*fitx)) * (Cw1 - Cw2*fitcph*fitcph + Cw3*fits2b + Cw4*fitx); if (mwpArray[point] < mwpMin) mwpMin = mwpArray[point]; if (mwpArray[point] > mwpMax) mwpMax = mwpArray[point]; } else { mzpArray[point] = 0.0; mwpArray[point] = 0.0; } } } else if ( (mdl.compare("uu") == 0) || (mdl.compare("nu") == 0) ) { C1 = 94.0397928463607 C2 = 77.1253849720165 for(point=0; point<Npoints; point++) { tree->GetEntry(point); fitsph = fittph / (1.0+fittph); fitcph = 1.0 - fitsph; if (fitsph != 0.0) { mzpArray[point] = (0.001/sqrt(fitsph*fitcph*fitx)) * (C1*fitsph*fitsph + C2*fitx); if (mzpArray[point] < mzpMin) mzpMin = mzpArray[point]; if (mzpArray[point] > mzpMax) mzpMax = mzpArray[point]; mwpArray[point] = (0.001/sqrt(fitsph*fitcph*fitx)) * (C1*fitsph*fitsph + C2*fitx); if (mwpArray[point] < mwpMin) mwpMin = mwpArray[point]; if (mwpArray[point] > mwpMax) mwpMax = mwpArray[point]; } else { mzpArray[point] = 0.0; mwpArray[point] = 0.0; } } }
void DoEvolutions( const TString &sim, Int_t time, Int_t Nbins=1, const TString &options="") { #ifdef __CINT__ gSystem->Load("libptools.so"); #endif PGlobals::Initialize(); // Palettes! gROOT->Macro("PPalettes.C"); TString opt = options; // cout << "options = " << opt << endl; // Load PData PData *pData = PData::Get(sim.Data()); pData->LoadFileNames(time); if(!pData->IsInit()) return; Bool_t CYL = kFALSE; if(sim.Contains("cyl")) { CYL = kTRUE; opt += "cyl"; } Bool_t ThreeD = kFALSE; if(sim.Contains("3D")) ThreeD = kTRUE; // Some plasma constants Double_t n0 = pData->GetPlasmaDensity(); Double_t kp = pData->GetPlasmaK(); Double_t skindepth = 1.0; if(kp!=0.0) skindepth = 1/kp; Double_t E0 = pData->GetPlasmaE0(); // Some initial beam properties: Float_t Ebeam = pData->GetBeamEnergy() * PUnits::MeV; Float_t gamma = pData->GetBeamGamma(); Float_t vbeam = pData->GetBeamVelocity(); Double_t rms0 = pData->GetBeamRmsY() * kp; if(CYL) rms0 = pData->GetBeamRmsR() * kp; // Time in OU Float_t Time = pData->GetRealTime(); // z start of the plasma in normalized units. Float_t zStartPlasma = pData->GetPlasmaStart() * kp; // z start of the beam in normalized units. Float_t zStartBeam = pData->GetBeamStart() * kp; if(opt.Contains("center")) { Time -= zStartPlasma; if(opt.Contains("comov")) // Centers on the head of the beam. Time += zStartBeam; } // Beam charge 2D and 1D histogram (on-axis) // ------------------------------------------------------------------ TH2F *hDen2D = NULL; if(pData->GetChargeFileName(1)) { char hName[24]; sprintf(hName,"hDen2D"); hDen2D = (TH2F*) gROOT->FindObject(hName); if(hDen2D) { delete hDen2D; hDen2D = NULL; } if(!ThreeD) hDen2D = pData->GetCharge(1,opt); else hDen2D = pData->GetCharge2DSliceZY(1,-1,1,opt+"avg"); hDen2D->SetName(hName); hDen2D->GetXaxis()->CenterTitle(); hDen2D->GetYaxis()->CenterTitle(); hDen2D->GetZaxis()->CenterTitle(); if(opt.Contains("comov")) hDen2D->GetXaxis()->SetTitle("k_{p}#zeta"); else hDen2D->GetXaxis()->SetTitle("k_{p}z"); if(CYL) hDen2D->GetYaxis()->SetTitle("k_{p}r"); else hDen2D->GetYaxis()->SetTitle("k_{p}y"); hDen2D->GetZaxis()->SetTitle("n_{b}/n_{0}"); } // Define ranges from the charge 2D histogram: // Binning for 2D histograms: // We get this values from the 2D density histogram. Int_t x1Nbin = hDen2D->GetNbinsX(); Float_t x1Range = (hDen2D->GetXaxis()->GetXmax() - hDen2D->GetXaxis()->GetXmin()); Float_t x1Mid = (hDen2D->GetXaxis()->GetXmax() + hDen2D->GetXaxis()->GetXmin())/2.; Float_t x1Min = hDen2D->GetXaxis()->GetXmin(); Float_t x1Max = hDen2D->GetXaxis()->GetXmax(); Int_t x2Nbin = hDen2D->GetNbinsY(); Float_t x2Range = (hDen2D->GetYaxis()->GetXmax() - hDen2D->GetYaxis()->GetXmin()); Float_t x2Mid = (hDen2D->GetYaxis()->GetXmax() + hDen2D->GetYaxis()->GetXmin())/2.; Float_t x2Min = x2Mid - x2Range/2; Float_t x2Max = x2Mid + x2Range/2; if(Nbins==0) { Nbins = TMath::Nint(rms0 / hDen2D->GetYaxis()->GetBinWidth(1)) ; // cout << Form(" Rms0 = %6.2f Dx = %6.2f Nbins = %4i .", // rms0, hDen2D->GetYaxis()->GetBinWidth(1), Nbins) << endl; } // Slice width limits. Int_t FirstyBin = 0; Int_t LastyBin = 0; if(!CYL) { FirstyBin = hDen2D->GetNbinsY()/2 + 1 - Nbins; LastyBin = hDen2D->GetNbinsY()/2 + Nbins; } else { FirstyBin = 1; LastyBin = Nbins; } // OUTPUT ROOT FILE WITH THE PLOTS: TString filename = Form("./%s/Plots/Evolutions/Evolutions-%s.root",sim.Data(),sim.Data()); TFile * ifile = (TFile*) gROOT->GetListOfFiles()->FindObject(filename); // if doesn't exist the directory should be created if (!ifile) { TString f = filename; TString dir2 = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) ); TString dir1 = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) ); gSystem->mkdir( dir1 ); gSystem->mkdir( dir2 ); ifile = new TFile(filename,"UPDATE"); } // Charge 1D histogram on axis TH1F *hDen1D = NULL; if(pData->GetChargeFileName(1)) { TString opth1 = opt; opth1 += "avg"; char hName[24]; sprintf(hName,"hDen1D"); hDen1D = (TH1F*) gROOT->FindObject(hName); if(hDen1D) delete hDen1D; if(ThreeD) { hDen1D = pData->GetH1SliceZ3D(pData->GetChargeFileName(1)->c_str(),"charge",-1,Nbins,-1,Nbins,opth1.Data()); } else if(CYL) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0). hDen1D = pData->GetH1SliceZ(pData->GetChargeFileName(1)->c_str(),"charge",1,Nbins,opth1.Data()); } else { // 2D cartesian hDen1D = pData->GetH1SliceZ(pData->GetChargeFileName(1)->c_str(),"charge",-1,Nbins,opth1.Data()); } hDen1D->SetName(hName); if(opt.Contains("comov")) hDen1D->GetXaxis()->SetTitle("k_{p}#zeta"); else hDen1D->GetXaxis()->SetTitle("k_{p}z"); hDen1D->GetYaxis()->SetTitle("n_{b}/n_{0}"); } // On-axis beam density vs \zeta vs time! _________________________________ TH2F *hDen1DvsTime = NULL; if(hDen1D) { char hName[24]; sprintf(hName,"hDen1DvsTime"); TH2F *hDen1DvsTimeOld = (TH2F*) ifile->Get(hName); Int_t nBins = 1; Float_t edge0 = Time-0.5; Float_t edge1 = Time+0.5; if(hDen1DvsTimeOld!=NULL) { nBins = hDen1DvsTimeOld->GetNbinsX()+1; Float_t binwidth = (Time - hDen1DvsTimeOld->GetXaxis()->GetBinCenter(1))/(nBins-1); edge0 = hDen1DvsTimeOld->GetXaxis()->GetBinCenter(1) - binwidth/2.; edge1 = Time + binwidth/2.; } hDen1DvsTime = new TH2F("temp","",nBins,edge0,edge1, hDen1D->GetNbinsX(), hDen1D->GetBinLowEdge(1), hDen1D->GetBinLowEdge(hDen1D->GetNbinsX()+1)); for(Int_t ix=1;ix<hDen1DvsTime->GetNbinsX();ix++) { for(Int_t iy=1;iy<hDen1DvsTime->GetNbinsY();iy++) { hDen1DvsTime->SetBinContent(ix,iy,hDen1DvsTimeOld->GetBinContent(ix,iy)); } } delete hDen1DvsTimeOld; // Fill last bin with the newest values. for(Int_t iy=1;iy<=hDen1D->GetNbinsX();iy++) { hDen1DvsTime->SetBinContent(nBins,iy,hDen1D->GetBinContent(iy)); } hDen1DvsTime->GetZaxis()->SetTitle("n_{b}/n_{0}"); hDen1DvsTime->GetYaxis()->SetTitle("k_{p}#zeta"); hDen1DvsTime->GetXaxis()->SetTitle("k_{p}z"); hDen1DvsTime->GetZaxis()->CenterTitle(); hDen1DvsTime->GetYaxis()->CenterTitle(); hDen1DvsTime->GetXaxis()->CenterTitle(); hDen1DvsTime->SetName(hName); // Change the range of z axis Float_t Denmax = hDen1DvsTime->GetMaximum(); hDen1DvsTime->GetZaxis()->SetRangeUser(0,Denmax); hDen1DvsTime->Write(hName,TObject::kOverwrite); } // RMS (vs z) of the beam's charge distribution: TProfile *hDen2Dprof = NULL; TH1F *hRms = NULL; Double_t axisPos = x2Mid; if(hDen2D) { TString pname = hDen2D->GetName(); pname += "_pfx"; hDen2Dprof = (TProfile*) gROOT->FindObject(pname.Data()); if(hDen2Dprof) { delete hDen2Dprof; hDen2Dprof = NULL; } hDen2Dprof = hDen2D->ProfileX("_pfx",1,-1,"s"); hRms = (TH1F*) gROOT->FindObject("hRms"); if(hRms) delete hRms; hRms = new TH1F("hRms","",x1Nbin,x1Min,x1Max); if(CYL) axisPos = 0.0; for(Int_t j=0;j<hRms->GetNbinsX();j++) { Double_t rms = 0; Double_t total = 0; for(Int_t k=1;k<=x2Nbin;k++) { Double_t value = hDen2D->GetBinContent(j,k); Double_t radius = hDen2D->GetYaxis()->GetBinCenter(k) - axisPos; if(CYL) { rms += radius*radius*radius*value; total += radius*value; } else { rms += radius*radius*value; total += value; } // cout << Form(" (%i,%i) -> radius = %7.4f , density = %7.4f",j,k,radius,value) << endl; } rms /= total; rms = sqrt(rms); hRms->SetBinContent(j,rms); } hRms->GetXaxis()->SetTitle("k_{p}z"); if(opt.Contains("comov")) hRms->GetXaxis()->SetTitle("k_{p}#zeta"); hRms->GetYaxis()->SetTitle("k_{p}#LTr#GT_{rms}"); } // Transverse charge RMS vs \zeta vs time! _________________________________ TH2F *hRmsvsTime = NULL; if(hRms) { char hName[24]; sprintf(hName,"hRmsvsTime"); TH2F *hRmsvsTimeOld = (TH2F*) ifile->Get(hName); Int_t nBins = 1; Float_t edge0 = Time-0.5; Float_t edge1 = Time+0.5; if(hRmsvsTimeOld!=NULL) { nBins = hRmsvsTimeOld->GetNbinsX()+1; Float_t binwidth = (Time - hRmsvsTimeOld->GetXaxis()->GetBinCenter(1))/(nBins-1); edge0 = hRmsvsTimeOld->GetXaxis()->GetBinCenter(1) - binwidth/2.; edge1 = Time + binwidth/2.; } hRmsvsTime = new TH2F("temp","",nBins,edge0,edge1, hRms->GetNbinsX(), hRms->GetBinLowEdge(1), hRms->GetBinLowEdge(hRms->GetNbinsX()+1)); for(Int_t ix=1;ix<hRmsvsTime->GetNbinsX();ix++) { for(Int_t iy=1;iy<hRmsvsTime->GetNbinsY();iy++) { hRmsvsTime->SetBinContent(ix,iy,hRmsvsTimeOld->GetBinContent(ix,iy)); } } delete hRmsvsTimeOld; // Fill last bin with the newest values. for(Int_t iy=1;iy<=hRms->GetNbinsX();iy++) { hRmsvsTime->SetBinContent(nBins,iy,hRms->GetBinContent(iy)); } hRmsvsTime->GetZaxis()->SetTitle("#LTr#GT_{rms}"); hRmsvsTime->GetYaxis()->SetTitle("k_{p}#zeta"); hRmsvsTime->GetXaxis()->SetTitle("k_{p}z"); hRmsvsTime->GetZaxis()->CenterTitle(); hRmsvsTime->GetYaxis()->CenterTitle(); hRmsvsTime->GetXaxis()->CenterTitle(); hRmsvsTime->SetName(hName); // Change the range of z axis Float_t Rmsmax = hRmsvsTime->GetMaximum(); hRmsvsTime->GetZaxis()->SetRangeUser(0,Rmsmax); hRmsvsTime->Write(hName,TObject::kOverwrite); } // INTEGRATED Beam's Charge: // Total charge vs time : TGraph *gQvsTime = NULL; if(hDen2D) { Double_t Q = 0; for(Int_t i=1;i<=x1Nbin;i++) { for(Int_t j=1;j<=x2Nbin;j++) { Double_t value = hDen2D->GetBinContent(i,j); if(CYL) { Double_t radius = hDen2D->GetYaxis()->GetBinCenter(j); Q += radius * value; // cout << Form(" (%i,%i) -> radius = %7.4f , value = %7.4f",i,j,radius,value) << endl; } else { Q += value; } } } Double_t xbinsize = hDen2D->GetXaxis()->GetBinWidth(1); Double_t ybinsize = hDen2D->GetYaxis()->GetBinWidth(1); Q *= xbinsize * ybinsize; if(!CYL && !ThreeD) { Q *= TMath::Sqrt(2*TMath::Pi()) * rms0; } else if(CYL) { Q *= 2*TMath::Pi(); } if(opt.Contains("units")) { Double_t dV = skindepth * skindepth * skindepth; Q *= n0 * dV; Q *= (PConst::ElectronCharge/PUnits::picocoulomb); cout << Form(" Integrated charge = %8i pC", TMath::Nint(Q)) << endl; } else { cout << Form(" Integrated charge = %8.4f n0 * kp^-3",Q) << endl; } Int_t nPoints = 0; char gName[32]; sprintf(gName,"gQvsTime"); gQvsTime = (TGraph*) ifile->Get(gName); if(gQvsTime==NULL) { gQvsTime = new TGraph(); gQvsTime->SetName(gName); nPoints = 0; // Some cosmetics at creation time: gQvsTime->SetLineWidth(3); gQvsTime->SetLineColor(PGlobals::fieldLine); gQvsTime->SetMarkerStyle(20); gQvsTime->SetMarkerSize(0.4); gQvsTime->SetMarkerColor(PGlobals::fieldLine); gQvsTime->GetYaxis()->SetTitle("charge [n_{0}/k_{p}^{3}]"); gQvsTime->GetXaxis()->SetTitle("k_{p}z"); } else { nPoints = gQvsTime->GetN(); } gQvsTime->Set(nPoints+1); gQvsTime->SetPoint(nPoints,Time,Q); gQvsTime->Write(gName,TObject::kOverwrite); } // ------------------------------------------------------------------------------------ // Longitudinal phasespace Int_t gNbin = 100; // Float_t gMin = 80; // Float_t gMax = 120; Float_t gMin = 43.07 - 1.2; Float_t gMax = 43.07 + 1.2; TH2F *hGvsZ = NULL; if(pData->GetRawFileName(1)) { char hName[24]; sprintf(hName,"hGvsZ"); hGvsZ = (TH2F*) gROOT->FindObject(hName); if(hGvsZ) { delete hGvsZ; hGvsZ = NULL; } hGvsZ = new TH2F(hName,"",x1Nbin,x1Min,x1Max,gNbin,gMin,gMax); pData->GetH2Raw(pData->GetRawFileName(1)->c_str(),"x1","gamma",hGvsZ,opt); hGvsZ->GetXaxis()->CenterTitle(); hGvsZ->GetYaxis()->CenterTitle(); hGvsZ->GetZaxis()->CenterTitle(); hGvsZ->GetYaxis()->SetTitle("#gamma"); if(opt.Contains("comov")) { hGvsZ->GetXaxis()->SetTitle("k_{p}#zeta"); hGvsZ->GetZaxis()->SetTitle("dN/d#zetad#gamma [a.u.]"); } else { hGvsZ->GetXaxis()->SetTitle("k_{p}z"); hGvsZ->GetZaxis()->SetTitle("dN/dzd#gamma [a.u.]"); } } else { cout << Form("--> No RAW data file is present for species 1") << endl; } TH2F *hGvsTime = NULL; TProfile *hGvsZprof = NULL; TGraphErrors *gGvsZ = NULL; if(hGvsZ) { TString pname = hGvsZ->GetName(); pname += "_pfx"; hGvsZprof = (TProfile*) gROOT->FindObject(pname.Data()); if(hGvsZprof) delete hGvsZprof; hGvsZprof = hGvsZ->ProfileX("_pfx",1,-1,"s"); gGvsZ = (TGraphErrors*) gROOT->FindObject("gGvsZ"); if(gGvsZ) delete gGvsZ; Int_t Npoints = hGvsZprof->GetNbinsX(); Double_t *x = new Double_t[Npoints]; Double_t *y = new Double_t[Npoints]; Double_t *ex = new Double_t[Npoints]; Double_t *ey = new Double_t[Npoints]; for(Int_t j=0;j<Npoints;j++) { x[j] = hGvsZprof->GetBinCenter(j); y[j] = hGvsZprof->GetBinContent(j); ex[j] = 0; ey[j] = hGvsZprof->GetBinError(j); } gGvsZ = new TGraphErrors(Npoints,x,y,ex,ey); gGvsZ->SetName("gGvsZ"); // PGlobals::SetH1Style((TH1*)gGvsZ,1); PGlobals::SetGraphStyle(gGvsZ,1); if(opt.Contains("comov")) gGvsZ->GetXaxis()->SetTitle("k_{p}#zeta"); else gGvsZ->GetXaxis()->SetTitle("k_{p}z"); gGvsZ->GetYaxis()->SetTitle("#LT#gamma#GT [MeV]"); char hName[24]; sprintf(hName,"hGvsTime"); TH2F *hGvsTimeOld = (TH2F*) ifile->Get(hName); Int_t nBins = 1; Float_t edge0 = Time-0.5; Float_t edge1 = Time+0.5; if(hGvsTimeOld!=NULL) { nBins = hGvsTimeOld->GetNbinsX()+1; Float_t binwidth = (Time - hGvsTimeOld->GetXaxis()->GetBinCenter(1))/(nBins-1); edge0 = hGvsTimeOld->GetXaxis()->GetBinCenter(1) - binwidth/2.; edge1 = Time + binwidth/2.; } hGvsTime = new TH2F("temp","",nBins,edge0,edge1, hGvsZprof->GetNbinsX(), hGvsZprof->GetBinLowEdge(1), hGvsZprof->GetBinLowEdge(hGvsZprof->GetNbinsX()+1)); for(Int_t ix=1;ix<hGvsTime->GetNbinsX();ix++) { for(Int_t iy=1;iy<hGvsTime->GetNbinsY();iy++) { hGvsTime->SetBinContent(ix,iy,hGvsTimeOld->GetBinContent(ix,iy)); } } delete hGvsTimeOld; // Fill last bin with the newest values. for(Int_t iy=1;iy<=hGvsZprof->GetNbinsX();iy++) { hGvsTime->SetBinContent(nBins,iy,hGvsZprof->GetBinContent(iy)); } hGvsTime->GetZaxis()->SetTitle("#LT#gamma#GT"); hGvsTime->GetYaxis()->SetTitle("k_{p}#zeta"); hGvsTime->GetXaxis()->SetTitle("k_{p}z"); hGvsTime->GetZaxis()->CenterTitle(); hGvsTime->GetYaxis()->CenterTitle(); hGvsTime->GetXaxis()->CenterTitle(); hGvsTime->SetName(hName); // Change the range of z axis Float_t Gmax = hGvsTime->GetMaximum(); Float_t Gmin = hGvsTime->GetMinimum(); hGvsTime->GetZaxis()->SetRangeUser(Gmin,Gmax); hGvsTime->Write(hName,TObject::kOverwrite); } // --------------------------------------------------------------------------------- // EM fields on - axis : TString opth1 = opt; opth1 += "avg"; // Get electric fields const Int_t Nfields = 2; TH1F **hE1D = new TH1F*[Nfields]; for(Int_t i=0;i<Nfields;i++) { hE1D[i] = NULL; if(!pData->GetEfieldFileName(i)) continue; char nam[3]; sprintf(nam,"e%i",i+1); if(ThreeD) { if(i==0) hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,-1,Nbins,opth1.Data()); else hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,-Nbins,Nbins,opth1.Data()); } else if(CYL) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0). if(i==0) hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data()); else hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data()); } else { // 2D cartesian if(i==0) hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,opth1.Data()); else hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,opth1.Data()); } char hName[24]; sprintf(hName,"hE_%i_%i",i,time); hE1D[i]->SetName(hName); if(opt.Contains("comov")) hE1D[i]->GetXaxis()->SetTitle("k_{p}#zeta"); else hE1D[i]->GetXaxis()->SetTitle("k_{p}z"); if(i==0) hE1D[i]->GetYaxis()->SetTitle("E_{z}/E_{0}"); else if(i==1) hE1D[i]->GetYaxis()->SetTitle("E_{y}/E_{0}"); else if(i==2) hE1D[i]->GetYaxis()->SetTitle("E_{x}/E_{0}"); hE1D[i]->GetYaxis()->CenterTitle(); hE1D[i]->GetXaxis()->CenterTitle(); } // Calculate wave positions: // ---------------------------------------------------------------- // Calculate the crossings and the extremes of the Electric fields Float_t Ecross[Nfields][100] = {{0.0}}; Float_t Eextr[Nfields][100] = {{0.0}}; Int_t Ncross[Nfields] = {0}; for(Int_t i=0;i<Nfields;i++) { Ncross[i] = 0; if(!hE1D[i]) continue; // Only smooths the focusing if flag activated.. if(i>0 && opt.Contains("smooth")) { // cout << " Smoothing fields on axis..." << endl; hE1D[i]->Smooth(10); } Float_t maxZeta = zStartBeam; if(opt.Contains("center")) maxZeta -= zStartBeam; for(Int_t ip=hE1D[i]->GetNbinsX();ip>1;ip--) { Float_t Z2 = hE1D[i]->GetBinCenter(ip-1); if(Z2 > maxZeta) continue; Float_t E1 = hE1D[i]->GetBinContent(ip); Float_t E2 = hE1D[i]->GetBinContent(ip-1); Float_t Z1 = hE1D[i]->GetBinCenter(ip); // cout << Form("Z1 = %6.4f Z2 = %6.4f E1 = %6.4f E2 = %6.4f", Z1, Z2, E1, E2) << endl; if(E1*E2 >= 0) { // No change of sign means we are in a side of the zero axis. if(fabs(E2)>fabs(Eextr[i][Ncross[i]])) { Eextr[i][Ncross[i]] = E2; } } if(E1*E2 < 0) { // change of sign means a crossing! // The next crossing has to be far enough from the previous one: Float_t zcross = -E1 * ( (Z2-Z1)/(E2-E1) ) + Z1; if(Ncross[i]>0 && fabs(Ecross[i][Ncross[i]-1]-zcross)<TMath::PiOver2() ) continue; // cout << " CROSS! " << endl; // add the point Ecross[i][Ncross[i]] = zcross; Ncross[i]++; } } cout << " -> Number of crossings for field " << i << " : " << Ncross[i] << endl; for(Int_t ic=0;ic<Ncross[i];ic++) { // cout << Form(" %2i: zeta = %6.4f E = %6.4f", ic, Ecross[i][ic], Eextr[i][ic]) << endl; } hE1D[i]->SetLineColor(kRed); hE1D[i]->Write(hE1D[i]->GetName(),TObject::kOverwrite); } // Get the Graphs and histos from file Int_t nPoints = 0; TGraph ***gEcross = new TGraph**[Nfields]; TGraph ***gEextr = new TGraph**[Nfields]; TH2F **hEvsTime = new TH2F*[Nfields]; for(Int_t i=0;i<Nfields;i++) { char hName[24]; sprintf(hName,"hEvsTime_%i",i); TH2F *hEvsTimeOld = (TH2F*) ifile->Get(hName); Int_t nBins = 1; Float_t edge0 = Time-0.5; Float_t edge1 = Time+0.5; if(hEvsTimeOld!=NULL) { nBins = hEvsTimeOld->GetNbinsX()+1; Float_t binwidth = (Time - hEvsTimeOld->GetXaxis()->GetBinCenter(1))/(nBins-1); edge0 = hEvsTimeOld->GetXaxis()->GetBinCenter(1) - binwidth/2.; edge1 = Time + binwidth/2.; } hEvsTime[i] = new TH2F("temp","",nBins,edge0,edge1, hE1D[i]->GetNbinsX(), hE1D[i]->GetBinLowEdge(1), hE1D[i]->GetBinLowEdge(hE1D[i]->GetNbinsX()+1)); for(Int_t ix=1;ix<hEvsTime[i]->GetNbinsX();ix++) { for(Int_t iy=1;iy<hEvsTime[i]->GetNbinsY();iy++) { hEvsTime[i]->SetBinContent(ix,iy,hEvsTimeOld->GetBinContent(ix,iy)); } } delete hEvsTimeOld; // Fill last bin with the newest values. for(Int_t iy=1;iy<=hE1D[i]->GetNbinsX();iy++) { hEvsTime[i]->SetBinContent(nBins,iy,hE1D[i]->GetBinContent(iy)); } if(i==0) hEvsTime[i]->GetZaxis()->SetTitle("E_{z}/E_{0}"); else if(i==1) hEvsTime[i]->GetZaxis()->SetTitle("E_{y}/E_{0}"); else if(i==2) hEvsTime[i]->GetZaxis()->SetTitle("E_{x}/E_{0}"); hEvsTime[i]->GetYaxis()->SetTitle("k_{p}#zeta"); hEvsTime[i]->GetXaxis()->SetTitle("k_{p}z"); hEvsTime[i]->GetZaxis()->CenterTitle(); hEvsTime[i]->GetYaxis()->CenterTitle(); hEvsTime[i]->GetXaxis()->CenterTitle(); hEvsTime[i]->SetName(hName); // Change the range of z axis for the fields to be symmetric. Float_t Emax = hEvsTime[i]->GetMaximum(); Float_t Emin = hEvsTime[i]->GetMinimum(); if(Emax > TMath::Abs(Emin)) Emin = -Emax; else Emax = -Emin; hEvsTime[i]->GetZaxis()->SetRangeUser(Emin,Emax); hEvsTime[i]->Write(hName,TObject::kOverwrite); // --- gEcross[i] = new TGraph*[Ncross[i]]; gEextr[i] = new TGraph*[Ncross[i]]; char gName[24]; Int_t ifail = 0; for(Int_t ic=0;ic<Ncross[i];ic++) { sprintf(gName,"gEcross_%i_%i",i,ic); gEcross[i][ic] = (TGraph*) ifile->Get(gName); if(gEcross[i][ic]==NULL) { gEcross[i][ic] = new TGraph(); gEcross[i][ic]->SetName(gName); nPoints = 0; // Some cosmetics at creation time: if(i==1) gEcross[i][ic]->SetLineStyle(2); else gEcross[i][ic]->SetLineStyle(1); gEcross[i][ic]->SetLineWidth(1); gEcross[i][ic]->SetLineColor(kGray+1); gEcross[i][ic]->SetMarkerStyle(20); gEcross[i][ic]->SetMarkerSize(0.4); gEcross[i][ic]->SetMarkerColor(kGray+1); gEcross[i][ic]->GetYaxis()->SetTitle("k_{p}#zeta]"); gEcross[i][ic]->GetXaxis()->SetTitle("k_{p}z"); } else { nPoints = gEcross[i][ic]->GetN(); } // Check the new crossings respect the previous ones: // Double_t t,zeta; // if(nPoints>0) { // gEcross[i][ic]->GetPoint(nPoints-1,t,zeta); // if(fabs(zeta-Ecross[i][ic+ifail])>TMath::Pi()) { // ic--; // ifail++; // continue; // } // } gEcross[i][ic]->Set(nPoints+1); gEcross[i][ic]->SetPoint(nPoints,Time,Ecross[i][ic+ifail]); gEcross[i][ic]->Write(gName,TObject::kOverwrite); // if(ic==Ncross[i]-1) continue; sprintf(gName,"gEextr_%i_%i",i,ic); gEextr[i][ic] = (TGraph*) ifile->Get(gName); if(gEextr[i][ic]==NULL) { gEextr[i][ic] = new TGraph(); gEextr[i][ic]->SetName(gName); nPoints = 0; // Some cosmetics at creation time: if(i==0) { gEextr[i][ic]->SetLineWidth(3); gEextr[i][ic]->SetLineColor(PGlobals::fieldLine); gEextr[i][ic]->SetMarkerStyle(20); gEextr[i][ic]->SetMarkerSize(0.4); gEextr[i][ic]->SetMarkerColor(PGlobals::fieldLine); gEextr[i][ic]->GetYaxis()->SetTitle("E_{z}/E_{0}"); gEextr[i][ic]->GetXaxis()->SetTitle("k_{p}z"); } else if(i==1) { gEextr[i][ic]->SetLineWidth(1); gEextr[i][ic]->SetLineColor(kGray+2); gEextr[i][ic]->SetMarkerStyle(20); gEextr[i][ic]->SetMarkerSize(0.4); gEextr[i][ic]->SetMarkerColor(kGray+2); gEextr[i][ic]->GetYaxis()->SetTitle("E_{y}/E_{0}"); gEextr[i][ic]->GetXaxis()->SetTitle("k_{p}z"); } } else { nPoints = gEextr[i][ic]->GetN(); } gEextr[i][ic]->Set(nPoints+1); gEextr[i][ic]->SetPoint(nPoints,Time,Eextr[i][ic]); gEextr[i][ic]->Write(gName,TObject::kOverwrite); } } ifile->Close(); }
void PlotShapeSystematics() { TFile *file = 0; TH1F *DefaultShape = 0; TH1F *UpShape = 0; TH1F *DownShape = 0; TCanvas *cv = 0; TLegend *legend = 0; //********************************************************* //0 Jet Bin - OF //********************************************************* file = new TFile("/data/smurf/sixie/data/Thesis/cards/130/hwwof_0j.input.root","READ"); DefaultShape = (TH1F*)file->Get("histo_qqWW"); UpShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWNLOBounding_hwwUp"); DownShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWNLOBounding_hwwDown"); assert(DefaultShape); assert(UpShape); assert(DownShape); NormalizeHist(DefaultShape); NormalizeHist(UpShape); NormalizeHist(DownShape); cv = new TCanvas("cv","cv",800,600); legend = new TLegend(0.2, 0.6, 0.5, 0.9); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetFillColor(kWhite); legend->AddEntry(DefaultShape, "Default Shape", "L"); legend->AddEntry(UpShape, "Bounding Shape (Up)", "L"); legend->AddEntry(DownShape, "Bounding Shape (Down)", "L"); DefaultShape->SetLineColor(kBlack); UpShape->SetLineColor(kBlue); DownShape->SetLineColor(kRed); DefaultShape->SetLineWidth(2); UpShape->SetLineWidth(2); DownShape->SetLineWidth(2); DefaultShape->SetTitle(""); DefaultShape->GetXaxis()->SetTitle("MVA discriminator"); DefaultShape->GetYaxis()->SetTitle("Fraction of Events"); DefaultShape->GetYaxis()->SetTitleOffset(1.4); DefaultShape->GetXaxis()->SetRangeUser(-1.0,1.0); DefaultShape->GetYaxis()->SetRangeUser(0.0,0.25); DefaultShape->Draw("hist"); UpShape->Draw("same,hist"); DownShape->Draw("same,hist"); legend->Draw(); cv->SaveAs("WWBkgShapeVariation_MCAtNLOScaleVariation_OF0Jet.png"); cv->SaveAs("WWBkgShapeVariation_MCAtNLOScaleVariation_OF0Jet.eps"); //********************************************************* //0 Jet Bin - SF //********************************************************* file = new TFile("/data/smurf/sixie/data/Thesis/cards/130/hwwsf_0j.input.root","READ"); DefaultShape = (TH1F*)file->Get("histo_qqWW"); UpShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWNLOBounding_hwwUp"); DownShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWNLOBounding_hwwDown"); assert(DefaultShape); assert(UpShape); assert(DownShape); NormalizeHist(DefaultShape); NormalizeHist(UpShape); NormalizeHist(DownShape); cv = new TCanvas("cv","cv",800,600); legend = new TLegend(0.2, 0.6, 0.5, 0.9); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetFillColor(kWhite); legend->AddEntry(DefaultShape, "Default Shape", "L"); legend->AddEntry(UpShape, "Bounding Shape (Up)", "L"); legend->AddEntry(DownShape, "Bounding Shape (Down)", "L"); DefaultShape->SetLineColor(kBlack); UpShape->SetLineColor(kBlue); DownShape->SetLineColor(kRed); DefaultShape->SetLineWidth(2); UpShape->SetLineWidth(2); DownShape->SetLineWidth(2); DefaultShape->SetTitle(""); DefaultShape->GetXaxis()->SetTitle("MVA discriminator"); DefaultShape->GetYaxis()->SetTitle("Fraction of Events"); DefaultShape->GetYaxis()->SetTitleOffset(1.4); DefaultShape->GetXaxis()->SetRangeUser(-1.0,1.0); DefaultShape->GetYaxis()->SetRangeUser(0.0,0.25); DefaultShape->Draw("hist"); UpShape->Draw("same,hist"); DownShape->Draw("same,hist"); legend->Draw(); cv->SaveAs("WWBkgShapeVariation_MCAtNLOScaleVariation_SF0Jet.png"); cv->SaveAs("WWBkgShapeVariation_MCAtNLOScaleVariation_SF0Jet.eps"); //********************************************************* //1 Jet Bin - OF //********************************************************* file = new TFile("/data/smurf/sixie/data/Thesis/cards/130/hwwof_1j.input.root","READ"); DefaultShape = (TH1F*)file->Get("histo_qqWW"); UpShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWNLOBounding_hwwUp"); DownShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWNLOBounding_hwwDown"); assert(DefaultShape); assert(UpShape); assert(DownShape); NormalizeHist(DefaultShape); NormalizeHist(UpShape); NormalizeHist(DownShape); cv = new TCanvas("cv","cv",800,600); legend = new TLegend(0.2, 0.6, 0.5, 0.9); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetFillColor(kWhite); legend->AddEntry(DefaultShape, "Default Shape", "L"); legend->AddEntry(UpShape, "Bounding Shape (Up)", "L"); legend->AddEntry(DownShape, "Bounding Shape (Down)", "L"); DefaultShape->SetLineColor(kBlack); UpShape->SetLineColor(kBlue); DownShape->SetLineColor(kRed); DefaultShape->SetLineWidth(2); UpShape->SetLineWidth(2); DownShape->SetLineWidth(2); DefaultShape->SetTitle(""); DefaultShape->GetXaxis()->SetTitle("MVA discriminator"); DefaultShape->GetYaxis()->SetTitle("Fraction of Events"); DefaultShape->GetYaxis()->SetTitleOffset(1.4); DefaultShape->GetXaxis()->SetRangeUser(-1.0,1.0); DefaultShape->GetYaxis()->SetRangeUser(0.0,0.4); DefaultShape->Draw("hist"); UpShape->Draw("same,hist"); DownShape->Draw("same,hist"); legend->Draw(); cv->SaveAs("WWBkgShapeVariation_MCAtNLOScaleVariation_OF1Jet.png"); cv->SaveAs("WWBkgShapeVariation_MCAtNLOScaleVariation_OF1Jet.eps"); //********************************************************* //1 Jet Bin - SF //********************************************************* file = new TFile("/data/smurf/sixie/data/Thesis/cards/130/hwwsf_1j.input.root","READ"); DefaultShape = (TH1F*)file->Get("histo_qqWW"); UpShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWNLOBounding_hwwUp"); DownShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWNLOBounding_hwwDown"); assert(DefaultShape); assert(UpShape); assert(DownShape); NormalizeHist(DefaultShape); NormalizeHist(UpShape); NormalizeHist(DownShape); cv = new TCanvas("cv","cv",800,600); legend = new TLegend(0.2, 0.6, 0.5, 0.9); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetFillColor(kWhite); legend->AddEntry(DefaultShape, "Default Shape", "L"); legend->AddEntry(UpShape, "Bounding Shape (Up)", "L"); legend->AddEntry(DownShape, "Bounding Shape (Down)", "L"); DefaultShape->SetLineColor(kBlack); UpShape->SetLineColor(kBlue); DownShape->SetLineColor(kRed); DefaultShape->SetLineWidth(2); UpShape->SetLineWidth(2); DownShape->SetLineWidth(2); DefaultShape->SetTitle(""); DefaultShape->GetXaxis()->SetTitle("MVA discriminator"); DefaultShape->GetYaxis()->SetTitle("Fraction of Events"); DefaultShape->GetYaxis()->SetTitleOffset(1.4); DefaultShape->GetXaxis()->SetRangeUser(-1.0,1.0); DefaultShape->GetYaxis()->SetRangeUser(0.0,0.4); DefaultShape->Draw("hist"); UpShape->Draw("same,hist"); DownShape->Draw("same,hist"); legend->Draw(); cv->SaveAs("WWBkgShapeVariation_MCAtNLOScaleVariation_SF1Jet.png"); cv->SaveAs("WWBkgShapeVariation_MCAtNLOScaleVariation_SF1Jet.eps"); //********************************************************* //0 Jet Bin - OF //********************************************************* file = new TFile("/data/smurf/sixie/data/Thesis/cards/130/hwwof_0j.input.root","READ"); DefaultShape = (TH1F*)file->Get("histo_qqWW"); UpShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWBounding_hwwUp"); DownShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWBounding_hwwDown"); assert(DefaultShape); assert(UpShape); assert(DownShape); NormalizeHist(DefaultShape); NormalizeHist(UpShape); NormalizeHist(DownShape); cv = new TCanvas("cv","cv",800,600); legend = new TLegend(0.2, 0.6, 0.5, 0.9); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetFillColor(kWhite); legend->AddEntry(DefaultShape, "Default Shape", "L"); legend->AddEntry(UpShape, "Bounding Shape (Up)", "L"); legend->AddEntry(DownShape, "Bounding Shape (Down)", "L"); DefaultShape->SetLineColor(kBlack); UpShape->SetLineColor(kBlue); DownShape->SetLineColor(kRed); DefaultShape->SetLineWidth(2); UpShape->SetLineWidth(2); DownShape->SetLineWidth(2); DefaultShape->SetTitle(""); DefaultShape->GetXaxis()->SetTitle("MVA discriminator"); DefaultShape->GetYaxis()->SetTitle("Fraction of Events"); DefaultShape->GetYaxis()->SetTitleOffset(1.4); DefaultShape->GetXaxis()->SetRangeUser(-1.0,1.0); DefaultShape->GetYaxis()->SetRangeUser(0.0,0.25); DefaultShape->Draw("hist"); UpShape->Draw("same,hist"); DownShape->Draw("same,hist"); legend->Draw(); cv->SaveAs("WWBkgShapeVariation_MadgraphVsMCAtNLO_OF0Jet.png"); cv->SaveAs("WWBkgShapeVariation_MadgraphVsMCAtNLO_OF0Jet.eps"); //********************************************************* //0 Jet Bin - SF //********************************************************* file = new TFile("/data/smurf/sixie/data/Thesis/cards/130/hwwsf_0j.input.root","READ"); DefaultShape = (TH1F*)file->Get("histo_qqWW"); UpShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWBounding_hwwUp"); DownShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWBounding_hwwDown"); assert(DefaultShape); assert(UpShape); assert(DownShape); NormalizeHist(DefaultShape); NormalizeHist(UpShape); NormalizeHist(DownShape); cv = new TCanvas("cv","cv",800,600); legend = new TLegend(0.2, 0.6, 0.5, 0.9); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetFillColor(kWhite); legend->AddEntry(DefaultShape, "Default Shape", "L"); legend->AddEntry(UpShape, "Bounding Shape (Up)", "L"); legend->AddEntry(DownShape, "Bounding Shape (Down)", "L"); DefaultShape->SetLineColor(kBlack); UpShape->SetLineColor(kBlue); DownShape->SetLineColor(kRed); DefaultShape->SetLineWidth(2); UpShape->SetLineWidth(2); DownShape->SetLineWidth(2); DefaultShape->SetTitle(""); DefaultShape->GetXaxis()->SetTitle("MVA discriminator"); DefaultShape->GetYaxis()->SetTitle("Fraction of Events"); DefaultShape->GetYaxis()->SetTitleOffset(1.4); DefaultShape->GetXaxis()->SetRangeUser(-1.0,1.0); DefaultShape->GetYaxis()->SetRangeUser(0.0,0.25); DefaultShape->Draw("hist"); UpShape->Draw("same,hist"); DownShape->Draw("same,hist"); legend->Draw(); cv->SaveAs("WWBkgShapeVariation_MadgraphVsMCAtNLO_SF0Jet.png"); cv->SaveAs("WWBkgShapeVariation_MadgraphVsMCAtNLO_SF0Jet.eps"); //********************************************************* //1 Jet Bin - OF //********************************************************* file = new TFile("/data/smurf/sixie/data/Thesis/cards/130/hwwof_1j.input.root","READ"); DefaultShape = (TH1F*)file->Get("histo_qqWW"); UpShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWBounding_hwwUp"); DownShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWBounding_hwwDown"); assert(DefaultShape); assert(UpShape); assert(DownShape); NormalizeHist(DefaultShape); NormalizeHist(UpShape); NormalizeHist(DownShape); cv = new TCanvas("cv","cv",800,600); legend = new TLegend(0.2, 0.6, 0.5, 0.9); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetFillColor(kWhite); legend->AddEntry(DefaultShape, "Default Shape", "L"); legend->AddEntry(UpShape, "Bounding Shape (Up)", "L"); legend->AddEntry(DownShape, "Bounding Shape (Down)", "L"); DefaultShape->SetLineColor(kBlack); UpShape->SetLineColor(kBlue); DownShape->SetLineColor(kRed); DefaultShape->SetLineWidth(2); UpShape->SetLineWidth(2); DownShape->SetLineWidth(2); DefaultShape->SetTitle(""); DefaultShape->GetXaxis()->SetTitle("MVA discriminator"); DefaultShape->GetYaxis()->SetTitle("Fraction of Events"); DefaultShape->GetYaxis()->SetTitleOffset(1.4); DefaultShape->GetXaxis()->SetRangeUser(-1.0,1.0); DefaultShape->GetYaxis()->SetRangeUser(0.0,0.4); DefaultShape->Draw("hist"); UpShape->Draw("same,hist"); DownShape->Draw("same,hist"); legend->Draw(); cv->SaveAs("WWBkgShapeVariation_MadgraphVsMCAtNLO_OF1Jet.png"); cv->SaveAs("WWBkgShapeVariation_MadgraphVsMCAtNLO_OF1Jet.eps"); //********************************************************* //1 Jet Bin - SF //********************************************************* file = new TFile("/data/smurf/sixie/data/Thesis/cards/130/hwwsf_1j.input.root","READ"); DefaultShape = (TH1F*)file->Get("histo_qqWW"); UpShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWBounding_hwwUp"); DownShape = (TH1F*)file->Get("histo_qqWW_CMS_MVAWWBounding_hwwDown"); assert(DefaultShape); assert(UpShape); assert(DownShape); NormalizeHist(DefaultShape); NormalizeHist(UpShape); NormalizeHist(DownShape); cv = new TCanvas("cv","cv",800,600); legend = new TLegend(0.2, 0.6, 0.5, 0.9); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetFillColor(kWhite); legend->AddEntry(DefaultShape, "Default Shape", "L"); legend->AddEntry(UpShape, "Bounding Shape (Up)", "L"); legend->AddEntry(DownShape, "Bounding Shape (Down)", "L"); DefaultShape->SetLineColor(kBlack); UpShape->SetLineColor(kBlue); DownShape->SetLineColor(kRed); DefaultShape->SetLineWidth(2); UpShape->SetLineWidth(2); DownShape->SetLineWidth(2); DefaultShape->SetTitle(""); DefaultShape->GetXaxis()->SetTitle("MVA discriminator"); DefaultShape->GetYaxis()->SetTitle("Fraction of Events"); DefaultShape->GetYaxis()->SetTitleOffset(1.4); DefaultShape->GetXaxis()->SetRangeUser(-1.0,1.0); DefaultShape->GetYaxis()->SetRangeUser(0.0,0.4); DefaultShape->Draw("hist"); UpShape->Draw("same,hist"); DownShape->Draw("same,hist"); legend->Draw(); cv->SaveAs("WWBkgShapeVariation_MadgraphVsMCAtNLO_SF1Jet.png"); cv->SaveAs("WWBkgShapeVariation_MadgraphVsMCAtNLO_SF1Jet.eps"); }
void gyieldsp() { //=========Macro generated from canvas: c1/c1 //========= (Fri Jul 31 19:31:43 2015) by ROOT version6.05/01 TCanvas *c1 = new TCanvas("c1", "c1",0,23,600,600); gStyle->SetOptFit(1); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); c1->Range(0,0,1,1); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetBorderSize(2); c1->SetTickx(1); c1->SetTicky(1); c1->SetLeftMargin(0.16); c1->SetRightMargin(0.04); c1->SetTopMargin(0.08); c1->SetBottomMargin(0.12); c1->SetFrameFillStyle(0); c1->SetFrameBorderMode(0); // ------------>Primitives in pad: pad1 TPad *pad1 = new TPad("pad1", "pad1",0,0.26,1,1); pad1->Draw(); pad1->cd(); pad1->Range(-3.5,-6.621622,2.75,158.9189); pad1->SetFillColor(0); pad1->SetBorderMode(0); pad1->SetBorderSize(2); pad1->SetTickx(1); pad1->SetTicky(1); pad1->SetLeftMargin(0.16); pad1->SetRightMargin(0.04); pad1->SetTopMargin(0.1142857); pad1->SetBottomMargin(0.04); pad1->SetFrameFillStyle(0); pad1->SetFrameBorderMode(0); pad1->SetFrameFillStyle(0); pad1->SetFrameBorderMode(0); Double_t Graph0_fx3021[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph0_fy3021[10] = { 103.56, 105.744, 103.4081, 100.0093, 97.03688, 94.36609, 90.5471, 82.43278, 65.82142, 43.43165}; Double_t Graph0_felx3021[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph0_fely3021[10] = { 7.299733, 7.206486, 6.824632, 6.594841, 6.406375, 6.079494, 5.746822, 5.225105, 4.165823, 2.787035}; Double_t Graph0_fehx3021[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph0_fehy3021[10] = { 5.988963, 6.218694, 6.307709, 6.368316, 5.847823, 5.655323, 5.083818, 4.561256, 3.722445, 2.542957}; TGraphAsymmErrors *grae = new TGraphAsymmErrors(10,Graph0_fx3021,Graph0_fy3021,Graph0_felx3021,Graph0_fehx3021,Graph0_fely3021,Graph0_fehy3021); grae->SetName("Graph0"); grae->SetTitle("Graph"); Int_t ci; // for color index setting TColor *color; // for color definition with alpha ci = TColor::GetColor("#ffff00"); grae->SetFillColor(ci); ci = TColor::GetColor("#ff0000"); grae->SetLineColor(ci); grae->SetLineWidth(4); grae->SetMarkerStyle(20); grae->SetMarkerSize(0); TH1F *Graph_Graph3021 = new TH1F("Graph_Graph3021","Graph",100,-2.5,2.5); Graph_Graph3021->SetMinimum(0); Graph_Graph3021->SetMaximum(140); Graph_Graph3021->SetDirectory(0); Graph_Graph3021->SetStats(0); Graph_Graph3021->SetLineStyle(0); Graph_Graph3021->SetMarkerStyle(20); Graph_Graph3021->GetXaxis()->SetNdivisions(505); Graph_Graph3021->GetXaxis()->SetLabelFont(42); Graph_Graph3021->GetXaxis()->SetLabelOffset(0.007); Graph_Graph3021->GetXaxis()->SetLabelSize(0); Graph_Graph3021->GetXaxis()->SetTitleSize(0.07142857); Graph_Graph3021->GetXaxis()->SetTitleOffset(1.1); Graph_Graph3021->GetXaxis()->SetTitleFont(42); Graph_Graph3021->GetYaxis()->SetTitle("d#sigma (W^{+}#rightarrow#font[12]{l}^{+}#nu) / d#eta_{lab} [nb]"); Graph_Graph3021->GetYaxis()->SetLabelFont(42); Graph_Graph3021->GetYaxis()->SetLabelOffset(0.007); Graph_Graph3021->GetYaxis()->SetLabelSize(0.07142857); Graph_Graph3021->GetYaxis()->SetTitleSize(0.07142857); Graph_Graph3021->GetYaxis()->SetTitleOffset(1.05); Graph_Graph3021->GetYaxis()->SetTitleFont(42); Graph_Graph3021->GetZaxis()->SetLabelFont(42); Graph_Graph3021->GetZaxis()->SetLabelOffset(0.007); Graph_Graph3021->GetZaxis()->SetLabelSize(0.05); Graph_Graph3021->GetZaxis()->SetTitleSize(0.06); Graph_Graph3021->GetZaxis()->SetTitleFont(42); grae->SetHistogram(Graph_Graph3021); grae->Draw("a2"); Double_t Graph1_fx3022[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph1_fy3022[10] = { 103.56, 105.744, 103.4081, 100.0093, 97.03688, 94.36609, 90.5471, 82.43278, 65.82142, 43.43165}; Double_t Graph1_felx3022[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph1_fely3022[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Double_t Graph1_fehx3022[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph1_fehy3022[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; grae = new TGraphAsymmErrors(10,Graph1_fx3022,Graph1_fy3022,Graph1_felx3022,Graph1_fehx3022,Graph1_fely3022,Graph1_fehy3022); grae->SetName("Graph1"); grae->SetTitle("Graph"); ci = TColor::GetColor("#ffff00"); grae->SetFillColor(ci); ci = TColor::GetColor("#ff0000"); grae->SetLineColor(ci); grae->SetLineWidth(4); grae->SetMarkerStyle(20); grae->SetMarkerSize(0); grae->Draw("z"); Double_t Graph2_fx3023[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph2_fy3023[10] = { 91.59545, 95.26883, 95.65156, 95.47892, 95.94693, 96.02597, 93.3635, 84.56484, 65.95871, 42.11706}; Double_t Graph2_felx3023[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph2_fely3023[10] = { 8.336985, 8.261181, 7.634488, 6.438496, 6.661149, 6.164321, 6.1019, 4.954787, 4.773841, 2.599375}; Double_t Graph2_fehx3023[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph2_fehy3023[10] = { 8.262572, 7.14746, 6.62492, 6.725295, 5.946212, 5.838684, 5.077774, 5.257491, 3.443198, 2.602454}; grae = new TGraphAsymmErrors(10,Graph2_fx3023,Graph2_fy3023,Graph2_felx3023,Graph2_fehx3023,Graph2_fely3023,Graph2_fehy3023); grae->SetName("Graph2"); grae->SetTitle("Graph"); ci = TColor::GetColor("#009900"); grae->SetFillColor(ci); grae->SetFillStyle(3375); ci = TColor::GetColor("#009900"); grae->SetLineColor(ci); grae->SetLineStyle(7); grae->SetLineWidth(4); grae->SetMarkerStyle(20); TH1F *Graph_Graph3023 = new TH1F("Graph_Graph3023","Graph",100,-2.88,2.88); Graph_Graph3023->SetMinimum(33.22782); Graph_Graph3023->SetMaximum(108.7062); Graph_Graph3023->SetDirectory(0); Graph_Graph3023->SetStats(0); Graph_Graph3023->SetLineStyle(0); Graph_Graph3023->SetMarkerStyle(20); Graph_Graph3023->GetXaxis()->SetLabelFont(42); Graph_Graph3023->GetXaxis()->SetLabelOffset(0.007); Graph_Graph3023->GetXaxis()->SetLabelSize(0.05); Graph_Graph3023->GetXaxis()->SetTitleSize(0.06); Graph_Graph3023->GetXaxis()->SetTitleOffset(1.1); Graph_Graph3023->GetXaxis()->SetTitleFont(42); Graph_Graph3023->GetYaxis()->SetLabelFont(42); Graph_Graph3023->GetYaxis()->SetLabelOffset(0.007); Graph_Graph3023->GetYaxis()->SetLabelSize(0.05); Graph_Graph3023->GetYaxis()->SetTitleSize(0.06); Graph_Graph3023->GetYaxis()->SetTitleOffset(1.5); Graph_Graph3023->GetYaxis()->SetTitleFont(42); Graph_Graph3023->GetZaxis()->SetLabelFont(42); Graph_Graph3023->GetZaxis()->SetLabelOffset(0.007); Graph_Graph3023->GetZaxis()->SetLabelSize(0.05); Graph_Graph3023->GetZaxis()->SetTitleSize(0.06); Graph_Graph3023->GetZaxis()->SetTitleFont(42); grae->SetHistogram(Graph_Graph3023); grae->Draw("2"); Double_t Graph3_fx3024[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph3_fy3024[10] = { 91.59545, 95.26883, 95.65156, 95.47892, 95.94693, 96.02597, 93.3635, 84.56484, 65.95871, 42.11706}; Double_t Graph3_felx3024[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph3_fely3024[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Double_t Graph3_fehx3024[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph3_fehy3024[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; grae = new TGraphAsymmErrors(10,Graph3_fx3024,Graph3_fy3024,Graph3_felx3024,Graph3_fehx3024,Graph3_fely3024,Graph3_fehy3024); grae->SetName("Graph3"); grae->SetTitle("Graph"); ci = TColor::GetColor("#009900"); grae->SetFillColor(ci); grae->SetFillStyle(3375); ci = TColor::GetColor("#009900"); grae->SetLineColor(ci); grae->SetLineStyle(7); grae->SetLineWidth(4); grae->SetMarkerStyle(20); grae->Draw("z"); Double_t Graph4_fx1011[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph4_fy1011[10] = { 108.0732, 102.2597, 100.2246, 101.796, 105.3416, 99.73788, 98.62062, 85.94448, 62.90271, 44.47931}; Double_t Graph4_fex1011[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Double_t Graph4_fey1011[10] = { 6.667786, 4.792637, 3.765295, 3.224798, 3.479167, 3.377478, 3.07273, 3.40604, 2.800731, 2.87761}; TGraphErrors *gre = new TGraphErrors(10,Graph4_fx1011,Graph4_fy1011,Graph4_fex1011,Graph4_fey1011); gre->SetName("Graph4"); gre->SetTitle("Graph"); gre->SetFillColor(1); gre->SetFillStyle(0); gre->SetLineWidth(2); gre->SetMarkerStyle(20); gre->Draw("||"); Double_t gyieldsp_exp_statonly_1_fx1012[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t gyieldsp_exp_statonly_1_fy1012[10] = { 108.0732, 102.2597, 100.2246, 101.796, 105.3416, 99.73788, 98.62062, 85.94448, 62.90271, 44.47931}; Double_t gyieldsp_exp_statonly_1_fex1012[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Double_t gyieldsp_exp_statonly_1_fey1012[10] = { 2.814265, 2.293805, 2.181326, 2.056934, 2.054972, 2.059018, 2.050204, 2.01317, 1.754638, 1.667829}; gre = new TGraphErrors(10,gyieldsp_exp_statonly_1_fx1012,gyieldsp_exp_statonly_1_fy1012,gyieldsp_exp_statonly_1_fex1012,gyieldsp_exp_statonly_1_fey1012); gre->SetName("gyieldsp_exp_statonly_1"); gre->SetTitle("Graph"); gre->SetFillColor(1); gre->SetLineWidth(2); gre->SetMarkerStyle(20); gre->SetMarkerSize(1.2); TH1F *Graph_gyieldsp_exp_statonly_11012 = new TH1F("Graph_gyieldsp_exp_statonly_11012","Graph",100,-2.64,2.64); Graph_gyieldsp_exp_statonly_11012->SetMinimum(36.00388); Graph_gyieldsp_exp_statonly_11012->SetMaximum(117.6951); Graph_gyieldsp_exp_statonly_11012->SetDirectory(0); Graph_gyieldsp_exp_statonly_11012->SetStats(0); Graph_gyieldsp_exp_statonly_11012->SetLineStyle(0); Graph_gyieldsp_exp_statonly_11012->SetMarkerStyle(20); Graph_gyieldsp_exp_statonly_11012->GetXaxis()->SetLabelFont(42); Graph_gyieldsp_exp_statonly_11012->GetXaxis()->SetLabelOffset(0.007); Graph_gyieldsp_exp_statonly_11012->GetXaxis()->SetLabelSize(0.05); Graph_gyieldsp_exp_statonly_11012->GetXaxis()->SetTitleSize(0.06); Graph_gyieldsp_exp_statonly_11012->GetXaxis()->SetTitleOffset(1.1); Graph_gyieldsp_exp_statonly_11012->GetXaxis()->SetTitleFont(42); Graph_gyieldsp_exp_statonly_11012->GetYaxis()->SetLabelFont(42); Graph_gyieldsp_exp_statonly_11012->GetYaxis()->SetLabelOffset(0.007); Graph_gyieldsp_exp_statonly_11012->GetYaxis()->SetLabelSize(0.05); Graph_gyieldsp_exp_statonly_11012->GetYaxis()->SetTitleSize(0.06); Graph_gyieldsp_exp_statonly_11012->GetYaxis()->SetTitleOffset(1.5); Graph_gyieldsp_exp_statonly_11012->GetYaxis()->SetTitleFont(42); Graph_gyieldsp_exp_statonly_11012->GetZaxis()->SetLabelFont(42); Graph_gyieldsp_exp_statonly_11012->GetZaxis()->SetLabelOffset(0.007); Graph_gyieldsp_exp_statonly_11012->GetZaxis()->SetLabelSize(0.05); Graph_gyieldsp_exp_statonly_11012->GetZaxis()->SetTitleSize(0.06); Graph_gyieldsp_exp_statonly_11012->GetZaxis()->SetTitleFont(42); gre->SetHistogram(Graph_gyieldsp_exp_statonly_11012); gre->Draw("pz"); TLegend *leg = new TLegend(0.6,0.1,0.9,0.3142857,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.05714286); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(1001); TLegendEntry *entry=leg->AddEntry("Graph4","Data","p"); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(20); entry->SetMarkerSize(1); entry->SetTextFont(42); entry=leg->AddEntry("Graph0","CT10","lf"); ci = TColor::GetColor("#ffff00"); entry->SetFillColor(ci); entry->SetFillStyle(1001); ci = TColor::GetColor("#ff0000"); entry->SetLineColor(ci); entry->SetLineStyle(1); entry->SetLineWidth(4); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(42); entry=leg->AddEntry("Graph2","CT10+EPS09","lf"); ci = TColor::GetColor("#009900"); entry->SetFillColor(ci); entry->SetFillStyle(3375); ci = TColor::GetColor("#009900"); entry->SetLineColor(ci); entry->SetLineStyle(7); entry->SetLineWidth(4); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(42); leg->Draw(); TPaveText *pt = new TPaveText(-2.35,125,-0.35,140,"br"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetFillStyle(0); pt->SetTextAlign(13); pt->SetTextFont(42); pt->SetTextSize(0.05714286); TText *AText = pt->AddText("Luminosity uncertainty: 3.5%"); pt->Draw(); pt = new TPaveText(0.27,0.2,0.5,0.3428571,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetFillStyle(0); pt->SetTextAlign(13); pt->SetTextFont(42); pt->SetTextSize(0.05714286); AText = pt->AddText("W^{+} #rightarrow #font[12]{l}^{+} + #nu"); AText = pt->AddText("p_{T}^{#font[12]{l}} > 25 GeV/c"); pt->Draw(); tex = new TLatex(0.96,0.9177143," #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(31); tex->SetTextFont(42); tex->SetTextSize(0.05714286); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.16,0.9177143,"pPb 34.6 nb^{-1}"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.05714286); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.924,0.8476571,"CMS"); tex->SetNDC(); tex->SetTextAlign(33); tex->SetTextFont(61); tex->SetTextSize(0.06857143); tex->SetLineWidth(2); tex->Draw(); TH1F *Graph_copy = new TH1F("Graph_copy","Graph",100,-2.5,2.5); Graph_copy->SetMinimum(0); Graph_copy->SetMaximum(140); Graph_copy->SetDirectory(0); Graph_copy->SetStats(0); Graph_copy->SetLineStyle(0); Graph_copy->SetMarkerStyle(20); Graph_copy->GetXaxis()->SetNdivisions(505); Graph_copy->GetXaxis()->SetLabelFont(42); Graph_copy->GetXaxis()->SetLabelOffset(0.007); Graph_copy->GetXaxis()->SetLabelSize(0); Graph_copy->GetXaxis()->SetTitleSize(0.07142857); Graph_copy->GetXaxis()->SetTitleOffset(1.1); Graph_copy->GetXaxis()->SetTitleFont(42); Graph_copy->GetYaxis()->SetTitle("d#sigma (W^{+}#rightarrow#font[12]{l}^{+}#nu) / d#eta_{lab} [nb]"); Graph_copy->GetYaxis()->SetLabelFont(42); Graph_copy->GetYaxis()->SetLabelOffset(0.007); Graph_copy->GetYaxis()->SetLabelSize(0.07142857); Graph_copy->GetYaxis()->SetTitleSize(0.07142857); Graph_copy->GetYaxis()->SetTitleOffset(1.05); Graph_copy->GetYaxis()->SetTitleFont(42); Graph_copy->GetZaxis()->SetLabelFont(42); Graph_copy->GetZaxis()->SetLabelOffset(0.007); Graph_copy->GetZaxis()->SetLabelSize(0.05); Graph_copy->GetZaxis()->SetTitleSize(0.06); Graph_copy->GetZaxis()->SetTitleFont(42); Graph_copy->Draw("sameaxis"); pad1->Modified(); c1->cd(); // ------------>Primitives in pad: pad2 TPad *pad2 = new TPad("pad2", "pad2",0,0,1,0.288); pad2->Draw(); pad2->cd(); pad2->Range(-3.5,0.35,2.75,1.35); pad2->SetFillColor(0); pad2->SetFillStyle(4000); pad2->SetBorderMode(0); pad2->SetBorderSize(2); pad2->SetTickx(1); pad2->SetTicky(1); pad2->SetLeftMargin(0.16); pad2->SetRightMargin(0.04); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.4); pad2->SetFrameFillStyle(4000); pad2->SetFrameBorderMode(0); pad2->SetFrameFillStyle(4000); pad2->SetFrameBorderMode(0); TH1F *Graph = new TH1F("Graph","Graph",100,-2.5,2.5); Graph->SetMinimum(0.75); Graph->SetMaximum(1.35); Graph->SetDirectory(0); Graph->SetStats(0); Graph->SetLineStyle(0); Graph->SetMarkerStyle(20); Graph->GetXaxis()->SetTitle("#eta_{lab}"); Graph->GetXaxis()->SetNdivisions(505); Graph->GetXaxis()->SetLabelFont(42); Graph->GetXaxis()->SetLabelOffset(0.007); Graph->GetXaxis()->SetLabelSize(0.1666667); Graph->GetXaxis()->SetTitleSize(0.1666667); Graph->GetXaxis()->SetTitleOffset(1.1); Graph->GetXaxis()->SetTitleFont(42); Graph->GetYaxis()->SetTitle("Ratio "); Graph->GetYaxis()->SetNdivisions(503); Graph->GetYaxis()->SetLabelFont(42); Graph->GetYaxis()->SetLabelOffset(0.007); Graph->GetYaxis()->SetLabelSize(0.1666667); Graph->GetYaxis()->SetTitleSize(0.1666667); Graph->GetYaxis()->SetTitleOffset(0.45); Graph->GetYaxis()->SetTitleFont(42); Graph->GetZaxis()->SetLabelFont(42); Graph->GetZaxis()->SetLabelOffset(0.007); Graph->GetZaxis()->SetLabelSize(0.05); Graph->GetZaxis()->SetTitleSize(0.06); Graph->GetZaxis()->SetTitleFont(42); Graph->Draw(""); Double_t Graph0_fx1013[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph0_fy1013[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; Double_t Graph0_fex1013[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph0_fey1013[10] = { 0.0644708, 0.06365122, 0.06354681, 0.06481966, 0.06320752, 0.0622177, 0.05991862, 0.05949606, 0.06001632, 0.06142499}; gre = new TGraphErrors(10,Graph0_fx1013,Graph0_fy1013,Graph0_fex1013,Graph0_fey1013); gre->SetName("Graph0"); gre->SetTitle("Graph"); ci = TColor::GetColor("#ffff00"); gre->SetFillColor(ci); ci = TColor::GetColor("#ff0000"); gre->SetLineColor(ci); gre->SetLineWidth(4); gre->SetMarkerStyle(20); gre->SetMarkerSize(0); TH1F *Graph_Graph1013 = new TH1F("Graph_Graph1013","Graph",100,-2.88,2.88); Graph_Graph1013->SetMinimum(0.9222164); Graph_Graph1013->SetMaximum(1.077784); Graph_Graph1013->SetDirectory(0); Graph_Graph1013->SetStats(0); Graph_Graph1013->SetLineStyle(0); Graph_Graph1013->SetMarkerStyle(20); Graph_Graph1013->GetXaxis()->SetLabelFont(42); Graph_Graph1013->GetXaxis()->SetLabelOffset(0.007); Graph_Graph1013->GetXaxis()->SetLabelSize(0.05); Graph_Graph1013->GetXaxis()->SetTitleSize(0.06); Graph_Graph1013->GetXaxis()->SetTitleOffset(1.1); Graph_Graph1013->GetXaxis()->SetTitleFont(42); Graph_Graph1013->GetYaxis()->SetLabelFont(42); Graph_Graph1013->GetYaxis()->SetLabelOffset(0.007); Graph_Graph1013->GetYaxis()->SetLabelSize(0.05); Graph_Graph1013->GetYaxis()->SetTitleSize(0.06); Graph_Graph1013->GetYaxis()->SetTitleOffset(1.5); Graph_Graph1013->GetYaxis()->SetTitleFont(42); Graph_Graph1013->GetZaxis()->SetLabelFont(42); Graph_Graph1013->GetZaxis()->SetLabelOffset(0.007); Graph_Graph1013->GetZaxis()->SetLabelSize(0.05); Graph_Graph1013->GetZaxis()->SetTitleSize(0.06); Graph_Graph1013->GetZaxis()->SetTitleFont(42); gre->SetHistogram(Graph_Graph1013); gre->Draw("2"); Double_t Graph1_fx1014[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph1_fy1014[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; Double_t Graph1_fex1014[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph1_fey1014[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; gre = new TGraphErrors(10,Graph1_fx1014,Graph1_fy1014,Graph1_fex1014,Graph1_fey1014); gre->SetName("Graph1"); gre->SetTitle("Graph"); ci = TColor::GetColor("#ffff00"); gre->SetFillColor(ci); ci = TColor::GetColor("#ff0000"); gre->SetLineColor(ci); gre->SetLineWidth(4); gre->SetMarkerStyle(20); gre->SetMarkerSize(0); gre->Draw("z"); Double_t Graph2_fx1015[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph2_fy1015[10] = { 0.8844678, 0.9009383, 0.9249909, 0.9547005, 0.9887677, 1.01759, 1.031104, 1.025864, 1.002086, 0.9697318}; Double_t Graph2_fex1015[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph2_fey1015[10] = { 0.05296218, 0.042007, 0.03326947, 0.02116912, 0.0170915, 0.01890429, 0.01672622, 0.01681633, 0.01541551, 0.01597539}; gre = new TGraphErrors(10,Graph2_fx1015,Graph2_fy1015,Graph2_fex1015,Graph2_fey1015); gre->SetName("Graph2"); gre->SetTitle("Graph"); ci = TColor::GetColor("#009900"); gre->SetFillColor(ci); gre->SetFillStyle(3375); ci = TColor::GetColor("#009900"); gre->SetLineColor(ci); gre->SetLineStyle(7); gre->SetLineWidth(4); gre->SetMarkerStyle(20); TH1F *Graph_Graph1015 = new TH1F("Graph_Graph1015","Graph",100,-2.88,2.88); Graph_Graph1015->SetMinimum(0.8098732); Graph_Graph1015->SetMaximum(1.069463); Graph_Graph1015->SetDirectory(0); Graph_Graph1015->SetStats(0); Graph_Graph1015->SetLineStyle(0); Graph_Graph1015->SetMarkerStyle(20); Graph_Graph1015->GetXaxis()->SetLabelFont(42); Graph_Graph1015->GetXaxis()->SetLabelOffset(0.007); Graph_Graph1015->GetXaxis()->SetLabelSize(0.05); Graph_Graph1015->GetXaxis()->SetTitleSize(0.06); Graph_Graph1015->GetXaxis()->SetTitleOffset(1.1); Graph_Graph1015->GetXaxis()->SetTitleFont(42); Graph_Graph1015->GetYaxis()->SetLabelFont(42); Graph_Graph1015->GetYaxis()->SetLabelOffset(0.007); Graph_Graph1015->GetYaxis()->SetLabelSize(0.05); Graph_Graph1015->GetYaxis()->SetTitleSize(0.06); Graph_Graph1015->GetYaxis()->SetTitleOffset(1.5); Graph_Graph1015->GetYaxis()->SetTitleFont(42); Graph_Graph1015->GetZaxis()->SetLabelFont(42); Graph_Graph1015->GetZaxis()->SetLabelOffset(0.007); Graph_Graph1015->GetZaxis()->SetLabelSize(0.05); Graph_Graph1015->GetZaxis()->SetTitleSize(0.06); Graph_Graph1015->GetZaxis()->SetTitleFont(42); gre->SetHistogram(Graph_Graph1015); gre->Draw("2"); Double_t Graph3_fx1016[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph3_fy1016[10] = { 0.8844678, 0.9009383, 0.9249909, 0.9547005, 0.9887677, 1.01759, 1.031104, 1.025864, 1.002086, 0.9697318}; Double_t Graph3_fex1016[10] = { 0.2, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2}; Double_t Graph3_fey1016[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; gre = new TGraphErrors(10,Graph3_fx1016,Graph3_fy1016,Graph3_fex1016,Graph3_fey1016); gre->SetName("Graph3"); gre->SetTitle("Graph"); ci = TColor::GetColor("#009900"); gre->SetFillColor(ci); gre->SetFillStyle(3375); ci = TColor::GetColor("#009900"); gre->SetLineColor(ci); gre->SetLineStyle(7); gre->SetLineWidth(4); gre->SetMarkerStyle(20); gre->Draw("z"); Double_t Graph4_fx1017[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph4_fy1017[10] = { 1.043581, 0.9670498, 0.9692137, 1.017865, 1.085583, 1.056925, 1.089164, 1.042601, 0.9556571, 1.024122}; Double_t Graph4_fex1017[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Double_t Graph4_fey1017[10] = { 0.06438575, 0.04532301, 0.03641199, 0.03224499, 0.03585407, 0.03579123, 0.03393516, 0.041319, 0.04255045, 0.06625605}; gre = new TGraphErrors(10,Graph4_fx1017,Graph4_fy1017,Graph4_fex1017,Graph4_fey1017); gre->SetName("Graph4"); gre->SetTitle("Graph"); gre->SetFillColor(1); gre->SetFillStyle(0); gre->SetLineWidth(2); gre->SetMarkerStyle(20); gre->Draw("||"); Double_t Graph5_fx1018[10] = { 2.2, 1.75, 1.25, 0.75, 0.25, -0.25, -0.75, -1.25, -1.75, -2.2}; Double_t Graph5_fy1018[10] = { 1.043581, 0.9670498, 0.9692137, 1.017865, 1.085583, 1.056925, 1.089164, 1.042601, 0.9556571, 1.024122}; Double_t Graph5_fex1018[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Double_t Graph5_fey1018[10] = { 0.02717523, 0.02169205, 0.02109434, 0.02056743, 0.02117723, 0.02181947, 0.02264241, 0.02442196, 0.02665755, 0.03840124}; gre = new TGraphErrors(10,Graph5_fx1018,Graph5_fy1018,Graph5_fex1018,Graph5_fey1018); gre->SetName("Graph5"); gre->SetTitle("Graph"); gre->SetFillColor(1); gre->SetLineWidth(2); gre->SetMarkerStyle(20); TH1F *Graph_Graph1018 = new TH1F("Graph_Graph1018","Graph",100,-2.64,2.64); Graph_Graph1018->SetMinimum(0.9107189); Graph_Graph1018->SetMaximum(1.130087); Graph_Graph1018->SetDirectory(0); Graph_Graph1018->SetStats(0); Graph_Graph1018->SetLineStyle(0); Graph_Graph1018->SetMarkerStyle(20); Graph_Graph1018->GetXaxis()->SetLabelFont(42); Graph_Graph1018->GetXaxis()->SetLabelOffset(0.007); Graph_Graph1018->GetXaxis()->SetLabelSize(0.05); Graph_Graph1018->GetXaxis()->SetTitleSize(0.06); Graph_Graph1018->GetXaxis()->SetTitleOffset(1.1); Graph_Graph1018->GetXaxis()->SetTitleFont(42); Graph_Graph1018->GetYaxis()->SetLabelFont(42); Graph_Graph1018->GetYaxis()->SetLabelOffset(0.007); Graph_Graph1018->GetYaxis()->SetLabelSize(0.05); Graph_Graph1018->GetYaxis()->SetTitleSize(0.06); Graph_Graph1018->GetYaxis()->SetTitleOffset(1.5); Graph_Graph1018->GetYaxis()->SetTitleFont(42); Graph_Graph1018->GetZaxis()->SetLabelFont(42); Graph_Graph1018->GetZaxis()->SetLabelOffset(0.007); Graph_Graph1018->GetZaxis()->SetLabelSize(0.05); Graph_Graph1018->GetZaxis()->SetTitleSize(0.06); Graph_Graph1018->GetZaxis()->SetTitleFont(42); gre->SetHistogram(Graph_Graph1018); gre->Draw("pz"); TH1F *Graph_copy = new TH1F("Graph_copy","Graph",100,-2.5,2.5); Graph_copy->SetMinimum(0.75); Graph_copy->SetMaximum(1.35); Graph_copy->SetDirectory(0); Graph_copy->SetStats(0); Graph_copy->SetLineStyle(0); Graph_copy->SetMarkerStyle(20); Graph_copy->GetXaxis()->SetTitle("#eta_{lab}"); Graph_copy->GetXaxis()->SetNdivisions(505); Graph_copy->GetXaxis()->SetLabelFont(42); Graph_copy->GetXaxis()->SetLabelOffset(0.007); Graph_copy->GetXaxis()->SetLabelSize(0.1666667); Graph_copy->GetXaxis()->SetTitleSize(0.1666667); Graph_copy->GetXaxis()->SetTitleOffset(1.1); Graph_copy->GetXaxis()->SetTitleFont(42); Graph_copy->GetYaxis()->SetTitle("Ratio "); Graph_copy->GetYaxis()->SetNdivisions(503); Graph_copy->GetYaxis()->SetLabelFont(42); Graph_copy->GetYaxis()->SetLabelOffset(0.007); Graph_copy->GetYaxis()->SetLabelSize(0.1666667); Graph_copy->GetYaxis()->SetTitleSize(0.1666667); Graph_copy->GetYaxis()->SetTitleOffset(0.45); Graph_copy->GetYaxis()->SetTitleFont(42); Graph_copy->GetZaxis()->SetLabelFont(42); Graph_copy->GetZaxis()->SetLabelOffset(0.007); Graph_copy->GetZaxis()->SetLabelSize(0.05); Graph_copy->GetZaxis()->SetTitleSize(0.06); Graph_copy->GetZaxis()->SetTitleFont(42); Graph_copy->Draw("sameaxis"); pad2->Modified(); c1->cd(); c1->Modified(); c1->cd(); c1->SetSelected(c1); }
//------------------------------------------------------------------------------ //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 plot(int mass) { double myQCDRelUncert = 0.038; double myEWKRelUncert = 0.131; double myFakesRelUncert = 0.238; double delta = 1.4; double br = 0.05; bool debug = false; bool log = false; double ymin = 0.001; double ymax = 48; static bool bMessage = false; if (!bMessage) { cout << "Values used as relative uncertainty (please check):" << endl; cout << " QCD: " << myQCDRelUncert << endl; cout << " EWK genuine tau: " << myEWKRelUncert << endl; cout << " EWK fake tau: " << myFakesRelUncert << endl << endl; bMessage = true; } cout << "Processing mass point: " << mass << " GeV/c2" << endl; gStyle->SetOptFit(1); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetTitleFont(43, "xyz"); gStyle->SetTitleSize(33, "xyz"); gStyle->SetLabelFont(43, "xyz"); gStyle->SetLabelSize(27, "xyz"); //std::string infile = "EPS_data_nodeltaphi/hplus_100.root"; //std::string infile = "EPS_data_deltaphi160/hplus_100.root"; std::stringstream s; s << "lands_histograms_hplushadronic_m" << mass << ".root"; std::string infile = s.str(); // Canvas TCanvas *myCanvas = new TCanvas("myCanvas", "",0,0,600,600); myCanvas->SetHighLightColor(2); myCanvas->Range(0,0,1,1); myCanvas->SetFillColor(0); myCanvas->SetBorderMode(0); myCanvas->SetBorderSize(2); if (log) myCanvas->SetLogy(); myCanvas->SetTickx(1); myCanvas->SetTicky(1); myCanvas->SetLeftMargin(0.16); myCanvas->SetRightMargin(0.05); myCanvas->SetTopMargin(0.05); myCanvas->SetBottomMargin(0.08); myCanvas->SetFrameFillStyle(0); myCanvas->SetFrameBorderMode(0); myCanvas->SetFrameFillStyle(0); myCanvas->SetFrameBorderMode(0); myCanvas->cd(); Int_t ci; TFile* f = TFile::Open(infile.c_str()); s.str(""); s << "HW" << mass << "_1"; TH1* hw = (TH1*)f->Get(s.str().c_str()); s.str(""); s << "HH" << mass << "_1"; TH1* hh = (TH1*)f->Get(s.str().c_str()); TH1* data = (TH1*)f->Get("data_obs"); data->SetLineWidth(2); data->SetMarkerStyle(20); data->SetMarkerSize(1.2); TH1* ewktau = (TH1*)f->Get("EWK_Tau"); ci = TColor::GetColor("#993399"); ewktau->SetFillColor(ci); ewktau->SetLineWidth(0); TH1* ewkDY = (TH1*)f->Get("EWK_DYx"); TH1* ewkVV = (TH1*)f->Get("EWK_VVx"); ewktau->Add(ewkDY); ewktau->Add(ewkVV); //TH1* qcd = (TH1*)f->Get("QCDInv"); TH1* qcd = (TH1*)f->Get("QCD"); ci = TColor::GetColor("#ffcc33"); qcd->SetFillColor(ci); qcd->SetLineWidth(0); TH1* fakett = (TH1*)f->Get("fake_tt"); ci = TColor::GetColor("#669900"); fakett->SetFillColor(ci); fakett->SetLineWidth(0); TH1* fakeW = (TH1*)f->Get("fake_W"); ci = TColor::GetColor("#cc3300"); fakeW->SetFillColor(ci); fakeW->SetLineWidth(0); TH1* faket = (TH1*)f->Get("fake_t"); TH1F *hFrame = new TH1F("hFrame","",20,0,400); hFrame->SetMinimum(ymin); if (log) hFrame->SetMaximum(ymax*1.5); else hFrame->SetMaximum(ymax); hFrame->SetDirectory(0); hFrame->SetStats(0); hFrame->SetLineStyle(0); hFrame->SetMarkerStyle(20); hFrame->SetXTitle("Transverse mass (#tau jet, E_{T}^{miss}), (GeV/c^{2})"); if (paperStatus) hFrame->SetXTitle("Transverse mass (#tau_{h}, E_{T}^{miss}), (GeV/c^{2})"); hFrame->SetYTitle("Events / 20 GeV/c^{2}"); hFrame->GetXaxis()->SetTitleSize(0); hFrame->GetXaxis()->SetLabelSize(0); hFrame->GetYaxis()->SetTitleFont(43); hFrame->GetYaxis()->SetTitleSize(27); hFrame->GetYaxis()->SetTitleOffset(1.3); // signal hh->Scale(br*br); hw->Scale(2*br*(1.0-br)); TH1* signal = (TH1*)hh->Clone(); signal->Add(hw); ci = TColor::GetColor("#ff3399"); signal->SetLineColor(ci); signal->SetLineStyle(2); signal->SetLineWidth(2); // Fakes TH1* fakes = (TH1*)(fakett->Clone()); fakes->Add(fakeW); fakes->Add(faket); // stacked backgrounds THStack *exp = new THStack(); exp->SetName("exp"); exp->SetTitle("exp"); exp->Add(fakes); exp->Add(ewktau); exp->Add(qcd); exp->Add(signal); TH1* hExpBkg = (TH1*)fakes->Clone(); hExpBkg->Add(ewktau); hExpBkg->Add(qcd); // uncertainty TH1* uncert = (TH1*)fakeW->Clone(); uncert->Add(fakett); uncert->Add(ewktau); uncert->Add(qcd); uncert->SetFillColor(1); uncert->SetFillStyle(3344); uncert->SetLineColor(0); uncert->SetLineStyle(0); uncert->SetLineWidth(0); TH1* hExpBkgTotalUncert = (TH1*)uncert->Clone(); hExpBkgTotalUncert->SetFillStyle(3354); TH1* hAgreement = (TH1*)data->Clone(); hAgreement->Divide(hExpBkg); TGraphErrors* hAgreementRelUncert = new TGraphErrors(hAgreement->GetNbinsX()); hAgreementRelUncert->SetLineWidth(2); hAgreementRelUncert->SetLineColor(kBlack); for (int i = 1; i <= hFrame->GetNbinsX(); ++i) { double myQCDTotalUncert = TMath::Power(qcd->GetBinError(i), 2) + TMath::Power(qcd->GetBinContent(i)*myQCDRelUncert, 2); double myEWKTotalUncert = TMath::Power(ewktau->GetBinError(i), 2) + TMath::Power(ewktau->GetBinContent(i)*myEWKRelUncert, 2); double myFakesTotalUncert = TMath::Power(fakes->GetBinError(i), 2) + TMath::Power(fakes->GetBinContent(i)*myFakesRelUncert, 2); hExpBkgTotalUncert->SetBinError(i, TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert)); if (hExpBkg->GetBinContent(i) > 0) { hAgreementRelUncert->SetPoint(i-1, hExpBkg->GetBinCenter(i), data->GetBinContent(i) / hExpBkg->GetBinContent(i)); double myUncertData = 0; if (data->GetBinContent(i) > 0) myUncertData = TMath::Power(data->GetBinError(i) / data->GetBinContent(i), 2); double myUncertBkg = (myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) / TMath::Power(hExpBkg->GetBinContent(i), 2); hAgreementRelUncert->SetPointError(i-1, 0, data->GetBinContent(i) / hExpBkg->GetBinContent(i) * TMath::Sqrt(myUncertData + myUncertBkg)); } else { hAgreementRelUncert->SetPoint(i-1, hExpBkg->GetBinCenter(i), 0); hAgreementRelUncert->SetPointError(i-1, 0, 0); } if (debug) { cout << "Point: " << hAgreementRelUncert->GetX()[i-1]-10 << "-" << hAgreementRelUncert->GetX()[i-1]+10 << " GeV/c2, agreement: " << hAgreementRelUncert->GetY()[i-1] << ", uncert: " << hAgreement->GetBinError(i) << ", " << hAgreementRelUncert->GetErrorY(i-1) << endl; cout << " bkg. stat. uncert. " << hExpBkg->GetBinError(i) << " (i.e. " << hExpBkg->GetBinError(i) / hExpBkg->GetBinContent(i) * 100.0 << " %)" << ", stat+syst uncert. " << TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) << " (i.e. " << TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) / hExpBkg->GetBinContent(i) * 100.0 << " %)" << endl; } } // Agreement pad TPad* pad = new TPad("ratiopad","ratiopad",0.,0.,1.,.3); pad->Draw(); pad->cd(); pad->Range(0,0,1,1); pad->SetFillColor(0); pad->SetFillStyle(4000); pad->SetBorderMode(0); pad->SetBorderSize(2); pad->SetTickx(1); pad->SetTicky(1); pad->SetLeftMargin(0.16); pad->SetRightMargin(0.05); pad->SetTopMargin(0); pad->SetBottomMargin(0.34); pad->SetFrameFillStyle(0); pad->SetFrameBorderMode(0); // Plot here ratio if (1.0-delta > 0) hAgreement->SetMinimum(1.0-delta); else hAgreement->SetMinimum(0.); hAgreement->SetMaximum(1.0+delta); hAgreement->GetXaxis()->SetLabelOffset(0.007); hAgreement->GetXaxis()->SetLabelFont(43); hAgreement->GetXaxis()->SetLabelSize(27); hAgreement->GetYaxis()->SetLabelFont(43); hAgreement->GetYaxis()->SetLabelSize(27); hAgreement->GetYaxis()->SetLabelOffset(0.007); hAgreement->GetYaxis()->SetNdivisions(505); hAgreement->GetXaxis()->SetTitleFont(43); hAgreement->GetYaxis()->SetTitleFont(43); hAgreement->GetXaxis()->SetTitleSize(33); hAgreement->GetYaxis()->SetTitleSize(33); hAgreement->SetTitleSize(27, "xyz"); hAgreement->GetXaxis()->SetTitleOffset(3.2); hAgreement->GetYaxis()->SetTitleOffset(1.3); hAgreement->SetXTitle(hFrame->GetXaxis()->GetTitle()); hAgreement->SetYTitle("Data/#Sigmabkg"); hAgreement->Draw("e2"); // Plot line at zero TH1* hAgreementLine = dynamic_cast<TH1*>(hAgreement->Clone()); for (int i = 1; i <= hAgreementLine->GetNbinsX(); ++i) { hAgreementLine->SetBinContent(i,1.0); hAgreementLine->SetBinError(i,0.0); } hAgreementLine->SetLineColor(kRed); hAgreementLine->SetLineWidth(2); hAgreementLine->SetLineStyle(3); hAgreementLine->Draw("hist same"); hAgreement->Draw("same"); hAgreementRelUncert->Draw("[]"); pad->RedrawAxis(); myCanvas->cd(); TPad* plotpad = new TPad("plotpad", "plotpad",0,0.3,1.,1.); plotpad->Draw(); plotpad->cd(); plotpad->Range(0,0,1,1); plotpad->SetFillColor(0); plotpad->SetFillStyle(4000); plotpad->SetBorderMode(0); plotpad->SetBorderSize(2); //if (logy) // plotpad->SetLogy(); plotpad->SetTickx(1); plotpad->SetTicky(1); plotpad->SetLeftMargin(0.16); plotpad->SetRightMargin(0.05); plotpad->SetTopMargin(0.065); plotpad->SetBottomMargin(0.0); plotpad->SetFrameFillStyle(0); plotpad->SetFrameBorderMode(0); hFrame->GetXaxis()->SetTitleSize(0); hFrame->GetXaxis()->SetLabelSize(0); hFrame->GetYaxis()->SetTitleFont(43); hFrame->GetYaxis()->SetTitleSize(33); hFrame->GetYaxis()->SetTitleOffset(1.3); // Draw objects hFrame->Draw(); exp->Draw("hist same"); uncert->Draw("E2 same"); hExpBkgTotalUncert->Draw("E2 same"); // Data data->Draw("same"); //signal->Draw("same"); TLegend *leg = new TLegend(0.53,0.6,0.87,0.91,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextFont(63); leg->SetTextSize(18); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(kWhite); //leg->SetFillStyle(4000); // enabling this will cause the plot to be erased from the pad TLegendEntry* entry = leg->AddEntry(data, "Data", "P"); s.str(""); s << "with H^{#pm}#rightarrow#tau^{#pm}#nu"; entry = leg->AddEntry(signal, s.str().c_str(), "L"); entry = leg->AddEntry(qcd, "QCD (meas.)", "F"); entry = leg->AddEntry(ewktau, "EWK genuine #tau (meas.)", "F"); entry = leg->AddEntry(fakes, "EWK fake #tau (MC)", "F"); entry = leg->AddEntry(uncert, "stat. uncert.", "F"); entry = leg->AddEntry(hExpBkgTotalUncert, "stat. #oplus syst. uncert.", "F"); leg->Draw(); string myTitle = "CMS Preliminary"; if (paperStatus) myTitle = "CMS"; TLatex *tex = new TLatex(0.62,0.945,myTitle.c_str()); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.2,0.945,"#sqrt{s} = 7 TeV"); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.43,0.945,"2.2 fb^{-1}"); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); s.str(""); s << "m_{H^{#pm}} = " << mass << " GeV/c^{2}"; tex = new TLatex(0.28,0.865,s.str().c_str()); tex->SetNDC(); tex->SetTextFont(63); tex->SetTextSize(20); tex->SetLineWidth(2); tex->Draw(); s.str(""); s << "BR(t#rightarrowbH^{#pm})=" << setprecision(2) << br; tex = new TLatex(0.28,0.805,s.str().c_str()); tex->SetNDC(); tex->SetTextFont(63); tex->SetTextSize(20); tex->SetLineWidth(2); tex->Draw(); plotpad->RedrawAxis(); plotpad->Modified(); s.str(""); s << "mT_datadriven_m" << mass << ".png"; myCanvas->Print(s.str().c_str()); s.str(""); s << "mT_datadriven_m" << mass << ".C"; myCanvas->Print(s.str().c_str()); s.str(""); s << "mT_datadriven_m" << mass << ".eps"; myCanvas->Print(s.str().c_str()); }
//------------------------------------------------------------------------------ // DrawHistogram //------------------------------------------------------------------------------ void DrawHistogram(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, 550, 720); TCanvas* canvas = new TCanvas(hname, hname, 800, 800); TPad* pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0); TPad* pad2 = new TPad("pad2", "pad2", 0, 0.0, 1, 0.3); pad1->SetTopMargin (0.08); pad1->SetBottomMargin(0.02); pad1->Draw(); pad2->SetTopMargin (0.08); pad2->SetBottomMargin(0.35); pad2->Draw(); //---------------------------------------------------------------------------- // pad1 //---------------------------------------------------------------------------- pad1->cd(); pad1->SetLogy(_setLogy); THStack* hstack = new THStack(hname, hname); TH1F* hist[nProcesses]; TH1F* hist_0[nProcesses]; // 0-jet TH1F* hist_1[nProcesses]; // 1-jet for (UInt_t ip=0; ip<nProcesses; ip++) { if( _njet == 10 ){ hist_0[ip] = (TH1F*)input_0[ip]->Get(hname); hist_1[ip] = (TH1F*)input_1[ip]->Get(hname); }else{ //hist[ip] = (TH1F*)input[ip]->Get(hname); //hist[ip]->SetName(hname + process[ip]); } if (moveOverflow){ if(_njet ==10){ MoveOverflowBins (hist_0[ip], xmin, xmax); MoveOverflowBins (hist_1[ip], xmin, xmax); }else{ //MoveOverflowBins (hist[ip], xmin, xmax); } }else{ if(_njet == 10){ ZeroOutOfRangeBins(hist_0[ip], xmin, xmax); ZeroOutOfRangeBins(hist_1[ip], xmin, xmax); }else{ //ZeroOutOfRangeBins(hist[ip], xmin, xmax); } } if (ngroup > 0){ if(_njet == 10){ hist_0[ip]->Rebin(ngroup); hist_1[ip]->Rebin(ngroup); }else{ //hist[ip]->Rebin(ngroup); } } // Add 0, 1 jet if (ip == iData) { if(_njet == 10 ){ hist[ip] = (TH1F*)hist_0[ip]->Clone(hname+process[ip]); hist[ip]->Add(hist_1[ip]); hist[ip]->SetMarkerStyle(kFullCircle); }else{ //hist[ip]->SetMarkerStyle(kFullCircle); } } else { if(_njet == 10){ if (_dataDriven && ip == itt) hist_0[ip]->Scale(ttScale[0]); if (_dataDriven && ip == itW) hist_0[ip]->Scale(tWScale[0]); if (_dataDriven && ip == iWW) hist_0[ip]->Scale(WWScale[0]); if (_dataDriven && ip == iDY) hist_0[ip]->Scale(ZjScale[0]); if (_dataDriven && ip == iDYtau) hist_0[ip]->Scale(ZjScale[0]); if (_dataDriven && ip == itt) hist_1[ip]->Scale(ttScale[1]); if (_dataDriven && ip == itW) hist_1[ip]->Scale(tWScale[1]); if (_dataDriven && ip == iWW) hist_1[ip]->Scale(WWScale[1]); if (_dataDriven && ip == iDY) hist_1[ip]->Scale(ZjScale[1]); if (_dataDriven && ip == iDYtau) hist_1[ip]->Scale(ZjScale[1]); hist[ip] = (TH1F*)hist_0[ip]->Clone(hname+process[ip]); hist[ip]->Add(hist_1[ip]); hist[ip]->SetFillColor(color[ip]); hist[ip]->SetFillStyle(1001); hist[ip]->SetLineColor(color[ip]); }else{ //hist[ip]->SetFillColor(color[ip]); //hist[ip]->SetFillStyle(1001); //hist[ip]->SetLineColor(color[ip]); //if (_dataDriven && ip == itt) hist[ip]->Scale(ttScale[_njet]); //if (_dataDriven && ip == itW) hist[ip]->Scale(tWScale[_njet]); //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]); } hstack->Add(hist[ip]); } } //========================================================= //Save histograms to root file to draw paper style plots //========================================================= //TFile* outfile; //TString fname = Form("files/%s_%djet.root", hname.Data(),_njet); //TString fname = "files/0jet_"+hname+".root"; //if(_njet==1) fname = "files/1jet_"+hname+".root"; //if(_njet==10) fname = "files/10jet_"+hname+".root"; //outfile = new TFile(fname, "create"); //if(ip == iData) TH1F* data = (TH1F*)hist[iData]->Clone("Data"); //data -> Sumw2(); //if(ip == itt) TH1F* top = (TH1F*)hist[itt]->Clone("top"); //top -> Sumw2(); //if(ip == itW) TH1F* tW = (TH1F*)hist[itW]->Clone("tW"); //tW -> Sumw2(); //if(ip == iWW) TH1F* WW = (TH1F*)hist[iWW]->Clone("WW"); //WW -> Sumw2(); //if(ip == iWZ) TH1F* VVandVVV = (TH1F*)hist[iWZ]->Clone("VVandVVV"); //VV -> Sumw2(); //if(ip == iZZ) TH1F* ZZ = (TH1F*)hist[iZZ]->Clone("ZZ"); //ZZ -> Sumw2(); //if(ip == iWg) TH1F* Wg = (TH1F*)hist[iWg]->Clone("Wg"); //Wg -> Sumw2(); //if(ip == iWj) TH1F* Wjets = (TH1F*)hist[iWj]->Clone("W+jets"); //Wjets -> Sumw2(); //if(ip == iDY) TH1F* Zjets = (TH1F*)hist[iDY]->Clone("Z+jets"); //Zjets -> Sumw2(); //if(ip == iDYtau) TH1F* DYtau = (TH1F*)hist[iDYtau]->Clone("DYtau"); //DYtau -> Sumw2(); //if(ip == iZgamma) TH1F* Zgamma = (TH1F*)hist[iZgamma]->Clone("Zgamma"); //Zgamma -> Sumw2(); //if(ip == iH125) TH1F* ggH = (TH1F*)hist[iH125]->Clone("ggH"); //ggH -> Sumw2(); // //top -> Add(tW); //VVandVVV -> Add(ZZ); //VVandVVV -> Add(Wg); //Zjets -> Add(DYtau); //Zjets -> Add(Zgamma); // //data -> Write(); //top -> Write(); //WW -> Write(); //VVandVVV -> Write(); //Wjets -> Write(); //Zjets -> Write(); //ggH -> Write(); // //outfile -> Close(); // //========================================================= //Draw paper style plots //========================================================= //Use LatinoPlotTools. //As input root file, use above saved root file "outfile" //Run the following executable file: //https://github.com/latinos/LatinoPlotTools/blob/master/WWRunI/scripts/doHWidth_Top_control.sh // All MC //---------------------------------------------------------------------------- TH1F* allmc = (TH1F*)hist[iData]->Clone("allmc"); allmc->SetFillColor (kGray+2); allmc->SetFillStyle ( 3345); allmc->SetLineColor (kGray+2); allmc->SetMarkerColor(kGray+2); allmc->SetMarkerSize ( 0); for (UInt_t ibin=1; ibin<=allmc->GetNbinsX(); ibin++) { Double_t binValue = 0; Double_t binError = 0; for (UInt_t ip=0; ip<nProcesses; ip++) { if (ip == iData) continue; Double_t binContent = hist[ip]->GetBinContent(ibin); binValue += binContent; binError += (hist[ip]->GetBinError(ibin) * hist[ip]->GetBinError(ibin)); //We need to calculate systematic uncertainty for ggH case // if (_dataDriven) // binError += (systError[ip]*binContent * systError[ip]*binContent); } binError = sqrt(binError); allmc->SetBinContent(ibin, binValue); allmc->SetBinError (ibin, binError); } // Axis labels //---------------------------------------------------------------------------- TAxis* xaxis = hist[iData]->GetXaxis(); TAxis* yaxis = hist[iData]->GetYaxis(); TString ytitle = Form("entries / %s.%df", "%", precision); xaxis->SetTitle(xtitle); yaxis->SetTitle(Form(ytitle.Data(), hist[iData]->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); hist[iData]->Draw("ep"); hstack ->Draw("hist,same"); allmc ->Draw("e2,same"); hist[iData]->Draw("ep,same"); // Adjust scale //---------------------------------------------------------------------------- Float_t theMax = GetMaximumIncludingErrors(hist[iData], xmin, xmax); Float_t theMaxMC = GetMaximumIncludingErrors(allmc, xmin, xmax); if (theMaxMC > theMax) theMax = theMaxMC; if (pad1->GetLogy()) { theMax = TMath::Power(10, TMath::Log10(theMax) + 2.7); hist[iData]->SetMinimum(0.05); } else theMax *= 1.55; hist[iData]->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; Double_t YieldTop = Yield(hist[itt]) + Yield(hist[itW]); Double_t YieldVV = Yield(hist[iWZ]) + Yield(hist[iZZ]) + Yield(hist[iWg]); //Double_t YieldZJets = Yield(hist[iDY]) + Yield(hist[iDYtau]); Double_t YieldZJets = Yield(hist[iDY]) + Yield(hist[iDYtau]) + Yield(hist[iZgamma]); DrawLegend(x0 - 0.49, y0 - ndelta, hist[iData], Form(" data (%.0f)", Yield(hist[iData])), "lp", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, allmc, Form(" all (%.0f)", Yield(allmc)), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWW], Form(" WW (%.0f)", Yield(hist[iWW])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWZ], Form(" VV (%.0f)", YieldVV), "f", 0.03, 0.2, yoffset); ndelta += delta; ndelta = 0; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iDY], Form(" Z+jets (%.0f)", YieldZJets), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iWj], Form(" W+jets (%.0f)", Yield(hist[iWj])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[itt], Form(" top (%.0f)", YieldTop), "f", 0.03, 0.2, yoffset); ndelta += delta; //DrawLegend(x0 - 0.23, y0 - ndelta, hist[iH125], Form(" Higgs (%.0f)", Yield(hist[iH125])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iH125], Form(" ggH (%.0f)", Yield(hist[iH125])), "f", 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"; if( _njet != 10) channelLabel += Form(" %d", _njet); if (_njet == 0) channelLabel += "-jets"; if (_njet == 1) channelLabel += "-jet"; if (_njet >= 2 && _njet!= 10) channelLabel += "-jets"; if ( _njet== 10) channelLabel += "SS 0+1 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)); //---------------------------------------------------------------------------- // pad2 //---------------------------------------------------------------------------- pad2->cd(); TH1F* ratio = hist[iData]->Clone("ratio"); TH1F* uncertainty = allmc->Clone("uncertainty"); for (UInt_t ibin=1; ibin<=ratio->GetNbinsX(); ibin++) { Double_t mcValue = allmc->GetBinContent(ibin); Double_t mcError = allmc->GetBinError (ibin); Double_t dtValue = ratio->GetBinContent(ibin); Double_t dtError = ratio->GetBinError (ibin); Double_t ratioValue = (mcValue > 0) ? dtValue/mcValue : 0.0; Double_t ratioError = (mcValue > 0) ? dtError/mcValue : 0.0; Double_t uncertaintyError = (mcValue > 0) ? mcError/mcValue : 0.0; ratio->SetBinContent(ibin, ratioValue); ratio->SetBinError (ibin, ratioError); uncertainty->SetBinContent(ibin, 1.0); uncertainty->SetBinError (ibin, uncertaintyError); } TAxis* uaxis = (TAxis*)uncertainty->GetXaxis(); uaxis->SetRangeUser(xmin, xmax); uncertainty->Draw("e2"); ratio ->Draw("ep,same"); uncertainty->GetYaxis()->SetRangeUser(0, 2.5); // Save //---------------------------------------------------------------------------- pad2->cd(); SetAxis(uncertainty, hist[iData]->GetXaxis()->GetTitle(), "data / prediction", 0.10, 0.8); pad1->cd(); SetAxis(hist[iData], "", hist[iData]->GetYaxis()->GetTitle(), 0.05, 1.6); canvas->cd(); TString suffixLogy = (_setLogy) ? "_Log" : "_Lin"; canvas->SaveAs(Form("%s/%s%s.%s", _output.Data(), hname.Data(), suffixLogy.Data(), _format.Data())); }
//------------------------------------------------------------------------ void DrawCFD() { Int_t npeaks = 20; Int_t sigma=3.; Bool_t down=false; Int_t index[20]; TCanvas *c1 = new TCanvas("c1", "CFD C side",0,48,1280,951); c1->Divide(4,3); gStyle->SetOptFit(1111); //c1->Divide(2,2); Char_t buf1[10]; for (Int_t i=0; i<12; i++) { c1->cd(i+1); sprintf(buf1,"T0_C_%i_CFD",i+1); TH1F *cfd = (TH1F*) gFile->Get(buf1); // cfd->Draw(); TSpectrum *s = new TSpectrum(2*npeaks,1); Int_t nfound = s->Search(cfd,sigma," ",0.05); cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;; if(nfound!=0){ Float_t *xpeak = s->GetPositionX(); TMath::Sort(nfound, xpeak, index,down); Float_t xp = xpeak[index[0]]; cout<<" index[0] "<<index[0]<<endl; // Float_t xp = xpeak[1]; Int_t xbin = cfd->GetXaxis()->FindBin(xp); Float_t yp = cfd->GetBinContent(xbin); cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[1]<<"\typeak = "<<yp<<endl; Float_t hmax = xp+3*sigma; Float_t hmin = xp-3*sigma; cout<<hmin<< " "<<hmax<<endl; cfd->GetXaxis()->SetRange(hmin-10,hmax+10); cout<<" cfd range "<<hmin-10<<" "<<hmax+10<<endl; cfd->GetXaxis()->SetLabelSize(0.03); TF1 *g1 = new TF1("g1", "gaus", hmin, hmax); cfd->Fit("g1","R"); // cfd->Draw(); } } TCanvas *c2 = new TCanvas("c2", "CFD A side",0,48,1280,951); c2->Divide(4,3); gStyle->SetOptFit(1111); //c1->Divide(2,2); Char_t buf1[10]; for (Int_t i=0; i<12; i++) { c2->cd(i+1); sprintf(buf1,"T0_A_%i_CFD",i+1); TH1F *cfd = (TH1F*) gFile->Get(buf1); // cfd->Draw(); TSpectrum *s = new TSpectrum(2*npeaks,1); Int_t nfound = s->Search(cfd,sigma," ",0.05); cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;; if(nfound!=0){ Float_t *xpeak = s->GetPositionX(); TMath::Sort(nfound, xpeak, index,down); Float_t xp = xpeak[index[0]]; cout<<" index[0] "<<index[0]<<endl; // Float_t xp = xpeak[1]; Int_t xbin = cfd->GetXaxis()->FindBin(xp); Float_t yp = cfd->GetBinContent(xbin); cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[1]<<"\typeak = "<<yp<<endl; Float_t hmax = xp+3*sigma; Float_t hmin = xp-3*sigma; cout<<hmin<< " "<<hmax<<endl; cfd->GetXaxis()->SetRange(hmin-10,hmax+10); cout<<" cfd range "<<hmin-10<<" "<<hmax+10<<endl; cfd->GetXaxis()->SetLabelSize(0.03); TF1 *g1 = new TF1("g1", "gaus", hmin, hmax); cfd->Fit("g1","R"); // cfd->Draw(); } } }
//------------------------------------------------------------------------ void DrawCFDvsLED() { Int_t runNumber=1098; Int_t npeaks = 20; Int_t sigma=2.; Char_t buf1[10], buf2[10]; TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951); gStyle->SetOptStat(0); c1->Divide(4,3); for (Int_t i=0; i<12; i++) { c1->cd(i+1); sprintf(buf1,"T0_C_%i_CFD",i+1); sprintf(buf2,"CFDvsLED%i",i+1); TH2F *qtc_cfd = (TH2F*) gFile->Get(buf2); //qtc_cfd->Draw(); TH1F *cfd = (TH1F*) gFile->Get(buf1); // cfd->Draw(); TSpectrum *s = new TSpectrum(2*npeaks,1); Int_t nfound = s->Search(cfd,sigma," ",0.05); cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;; if(nfound!=0){ Double_t max=0.0; Double_t tabmax[2] = {0.0, 0.0}; Float_t *xpeak = s->GetPositionX(); for(Int_t k=0; k<1 ;k++) { Float_t xp = xpeak[k]; Int_t xbin = cfd->GetXaxis()->FindBin(xp); Float_t yp = cfd->GetBinContent(xbin); cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[k]<<"\typeak = "<<yp<<endl; } Float_t hmin=xp-10*sigma; Float_t hmax =xp+10*sigma; cout<<hmin<< " "<<hmax<<endl; // cfd->GetXaxis()->SetRange(hmin,hmax); // TF1 *g1 = new TF1("g1", "gaus", hmin, hmax); // cfd->Fit("g1","R"); Int_t hminbin= qtc_cfd->GetXaxis()->GetFirst(); Int_t hmaxbin= qtc_cfd->GetXaxis()->GetLast(); Int_t nbins= qtc_cfd->GetXaxis()->GetNbins(); cout<<" qtc_cfd "<<hminbin<<" "<<hmaxbin<<" "<<nbins<<endl; qtc_cfd->Draw(); /*TProfile *pr_y = qtc_cfd->ProfileX(); pr_y->SetMaximum(hmax); pr_y->SetMinimum(hmin); Int_t np=nbins/20; Double_t *xx = new Double_t[np]; Double_t *yy = new Double_t[np]; Int_t ng=0; Double_t yg=0; for (Int_t ip=1; ip<nbins; ip++) { if(ip%20 != 0 ) { if (pr_y->GetBinContent(ip) !=0) yg +=pr_y->GetBinContent(ip); // cout<<ng<<" "<<pr_y->GetBinContent(ip)<<" "<<yg<<endl; ng++;} else { xx[ip/20] = Float_t (ip); yy[ip/20] = yg/ng; yg=0; ng=0; cout<<ip<<" "<<ip/20<<" "<< xx[ip/20]<<" "<< yy[ip/20]<<endl; } } TH2F *hr = new TH2F("hr"," ",np,0,nbins, np, hmin, hmax); hr->Draw(); TGraph *gr = new TGraph(np,xx,yy); gr->SetMinimum(hmin); gr->SetMaximum(hmax); gr->Draw("P"); delete [] xx; delete [] yy; // pr_y->Rebin(10); // pr_y->Draw(); */ } } }
void plotDistribution( TChain* data , TChain *mc , TCut sel , TCut vtxweight , char* var , int nbins , float xmin , float xmax , char* xtitle , char* plottitle = "" , bool printplot = false , bool residual = false , bool log = false ){ //-------------------------------------- // define histograms and TGraphs //-------------------------------------- TH1F* hdata = new TH1F(Form("hdata_%i" , iplot),Form("hdata_%i" , iplot),nbins,xmin,xmax); TH1F* hmc = new TH1F(Form("hmc_%i" , iplot),Form("hmc_%i" , iplot),nbins,xmin,xmax); TH1F* hmc_novtx = new TH1F(Form("hmc_novtx_%i" , iplot),Form("hmc_novtx%i" , iplot),nbins,xmin,xmax); hdata->Sumw2(); hmc->Sumw2(); TGraphAsymmErrors* grdata = new TGraphAsymmErrors(); TGraphAsymmErrors* grmc = new TGraphAsymmErrors(); TH1F* hdata_denom = new TH1F(Form("hdata_denom_%i",iplot),"",nbins,xmin,xmax); TH1F* hmc_denom = new TH1F(Form("hmc_denom_%i" ,iplot),"",nbins,xmin,xmax); //-------------------------------------- // set up canvas and pads //-------------------------------------- TCanvas *can = new TCanvas(Form("can_%i",iplot),Form("can_%i",iplot),600,600); can->cd(); if( log ) gPad->SetLogy(); TPad *mainpad = new TPad("mainpad","mainpad",0.0,0.0,1.0,0.8); if( residual ){ mainpad->Draw(); mainpad->cd(); if( log ) mainpad->SetLogy(); } //-------------------------------------- // fill histos and TGraphs //-------------------------------------- data->Draw(Form("min(%s,%f)>>hdata_%i" , var,xmax-0.0001,iplot),sel); mc ->Draw(Form("min(%s,%f)>>hmc_%i" , var,xmax-0.0001,iplot),sel*vtxweight); mc ->Draw(Form("min(%s,%f)>>hmc_novtx_%i" , var,xmax-0.0001,iplot),sel); for( int ibin = 1 ; ibin <= nbins ; ibin++ ){ hdata_denom->SetBinContent(ibin,hdata->Integral()); hmc_denom->SetBinContent(ibin,hmc->Integral()); } grdata->BayesDivide(hdata,hdata_denom); grmc->BayesDivide(hmc_novtx,hmc_denom); //-------------------------------------- // get efficiencies and errors //-------------------------------------- /* float ndata1 = (float) hdata->GetBinContent(1); float ndata = (float) hdata->Integral(); float effdata = 1-ndata1 / ndata; // TGraphAsymmErrors* grdata_temp = new TGraphAsymmErrors(); // TH1F* hdata_num_temp = new TH1F(Form("hdata_num_temp_%i",iplot),"",1,0,1); // TH1F* hdata_den_temp = new TH1F(Form("hdata_den_temp_%i",iplot),"",1,0,1); // hdata_num_temp->SetBinContent(1,ndata-ndata1); // hdata_den_temp->SetBinContent(1,ndata); // grdata_temp->BayesDivide(hdata_num_temp,hdata_den_temp); //float effdataerr = sqrt(ndata1) / ndata; float effdataerr = 0.5 * ( grdata->GetErrorYlow(0) + grdata->GetErrorYhigh(0) ); //float effdataerr = 0.5 * ( grdata_temp->GetErrorYlow(0) + grdata_temp->GetErrorYhigh(0) ); float nmc1 = (float) hmc->GetBinContent(1); float nmc = (float) hmc->Integral(); float effmc = 1-nmc1 / nmc; //float effmcerr = hmc->GetBinError(1) / nmc; float effmcerr = 0.5 * ( grmc->GetErrorYlow(0) + grmc->GetErrorYhigh(0) ); float datatot = hdata->Integral(); float mctot = hmc->Integral(); cout << endl; cout << plottitle << endl; cout << "Data eff " << Form("%.2f +/- %.3f",effdata,effdataerr) << endl; cout << "MC eff " << Form("%.2f +/- %.3f",effmc ,effmcerr) << endl; cout << "Data/MC " << Form("%.2f +/- %.2f",ratio ,ratioerr) << endl; */ float ndata = hdata->Integral(); float ndata1 = hdata->Integral(2,20); float ndata2 = hdata->Integral(3,20); float ndata3 = hdata->Integral(4,20); float ndata4 = hdata->Integral(5,20); float ndata5 = hdata->Integral(6,20); float nmc = hmc->Integral(); float nmc1 = hmc->Integral(2,20); float nmc2 = hmc->Integral(3,20); float nmc3 = hmc->Integral(4,20); float nmc4 = hmc->Integral(5,20); float nmc5 = hmc->Integral(6,20); float effdata1 = ndata1/ndata; float effdata2 = ndata2/ndata; float effdata3 = ndata3/ndata; float effdata4 = ndata4/ndata; float effdata5 = ndata5/ndata; float effmc1 = nmc1/nmc; float effmc2 = nmc2/nmc; float effmc3 = nmc3/nmc; float effmc4 = nmc4/nmc; float effmc5 = nmc5/nmc; float effdata1err = getBinomialError(ndata1,ndata); float effdata2err = getBinomialError(ndata2,ndata); float effdata3err = getBinomialError(ndata3,ndata); float effdata4err = getBinomialError(ndata4,ndata); float effdata5err = getBinomialError(ndata5,ndata); float effmc1err = getBinomialError(nmc1,nmc); float effmc2err = getBinomialError(nmc2,nmc); float effmc3err = getBinomialError(nmc3,nmc); float effmc4err = getBinomialError(nmc4,nmc); float effmc5err = getBinomialError(nmc5,nmc); float ratio1 = effdata1/effmc1; float ratio2 = effdata2/effmc2; float ratio3 = effdata3/effmc3; float ratio4 = effdata4/effmc4; float ratio5 = effdata5/effmc5; float ratio1err = ratio1 * sqrt(pow(effdata1err/effdata1,2)+pow(effmc1err/effmc1,2)); float ratio2err = ratio2 * sqrt(pow(effdata2err/effdata2,2)+pow(effmc2err/effmc2,2)); float ratio3err = ratio3 * sqrt(pow(effdata3err/effdata3,2)+pow(effmc3err/effmc3,2)); float ratio4err = ratio4 * sqrt(pow(effdata4err/effdata4,2)+pow(effmc4err/effmc4,2)); float ratio5err = ratio5 * sqrt(pow(effdata5err/effdata5,2)+pow(effmc5err/effmc5,2)); cout << endl << endl << plottitle << endl; int left = 20; // char* delimstart = "|"; // char* delim = "|"; // char* delimend = "|"; // char* pm = "+/-"; char* delimstart = ""; char* delim = "&"; char* delimend = "\\\\"; char* pm = "$\\pm$"; cout << delimstart << setw(10) << "" << setw(4) << delim << setw(left) << "$>$ 1 GeV" << setw(4) << delim << setw(left) << "$>$ 2 GeV" << setw(4) << delim << setw(left) << "$>$ 3 GeV" << setw(4) << delim << setw(left) << "$>$ 4 GeV" << setw(4) << delim << setw(left) << "$>$ 5 GeV" << setw(4) << delimend << endl; cout << delimstart << setw(10) << "data" << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata1,pm,effdata1err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata2,pm,effdata2err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata3,pm,effdata3err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata4,pm,effdata4err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata5,pm,effdata5err) << setw(4) << delimend << endl; cout << delimstart << setw(10) << "mc" << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc1,pm,effmc1err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc2,pm,effmc2err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc3,pm,effmc3err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc4,pm,effmc4err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc5,pm,effmc5err) << setw(4) << delimend << endl; cout << delimstart << setw(10) << "data/mc" << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio1,pm,ratio1err) << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio2,pm,ratio2err) << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio3,pm,ratio3err) << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio4,pm,ratio4err) << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio5,pm,ratio5err) << setw(4) << delimend << endl; //-------------------------------------- // draw stuff //-------------------------------------- hdata->Scale(1.0/hdata->Integral()); hmc->Scale(1.0/hmc->Integral()); if( log ) hmc->GetYaxis()->SetRangeUser(0.0001,5); else hmc->GetYaxis()->SetRangeUser(0.0,1); hmc->GetXaxis()->SetTitle(xtitle); hmc->SetLineColor(2); hmc->SetMarkerColor(2); hmc->DrawNormalized("hist"); hmc->DrawNormalized("sameE1"); hdata->SetLineColor(4); hdata->SetMarkerColor(4); hdata->Draw("sameE1"); grdata->SetLineColor(6); grmc->SetLineColor(7); //grdata->Draw("sameP"); //grmc->Draw("sameP"); TLegend *leg = new TLegend(0.6,0.7,0.8,0.9); leg->AddEntry(hdata , "data" , "lp"); leg->AddEntry(hmc , "MC" , "lp"); leg->SetBorderSize(0); leg->SetFillColor(0); leg->Draw(); TLatex *t = new TLatex(); t->SetNDC(); if( TString(plottitle).Contains("el") ) t->DrawLatex(0.6,0.6,"electrons"); if( TString(plottitle).Contains("mu") ) t->DrawLatex(0.6,0.6,"muons"); if( TString(plottitle).Contains("0j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 0"); if( TString(plottitle).Contains("1j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 1"); if( TString(plottitle).Contains("2j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 2"); if( TString(plottitle).Contains("3j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 3"); if( TString(plottitle).Contains("4j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 4"); //-------------------------------------- // draw residual plots //-------------------------------------- if( residual ){ can->cd(); TPad *respad = new TPad("respad","respad",0.0,0.8,1.0,1.0); respad->Draw(); respad->cd(); respad->SetGridy(); TH1F* hratio = (TH1F*) hdata->Clone(Form("hratio_%i",iplot)); hratio->Divide(hmc); hratio->SetMarkerColor(1); hratio->SetLineColor(1); hratio->Draw(); hratio->GetYaxis()->SetRangeUser(0.5,1.5); hratio->GetYaxis()->SetNdivisions(5); hratio->GetYaxis()->SetLabelSize(0.2); hratio->GetXaxis()->SetLabelSize(0.0); TLine line; line.DrawLine(xmin,1.0,xmax,1.0); } //data->Scan("run:lumi:event:probe->pt():probe->eta():tkisonew:met:mt:njets:nbl:nbm",sel+"tkisonew>20"); //data->Scan("run:lumi:event:probe->pt():probe->eta():tkisonew:met:mt:njets:nbl:nbm",sel); if( printplot ) can->Print(Form("plots/%s.pdf",plottitle)); iplot++; // TCanvas *c2 = new TCanvas(); // c2->cd(); // grdata->Draw("AP"); }
void dileptonMassFit(const char* pInFileName="PanchoSkim4JanAll.root", // "PromtRecoV2V3V3H_DiMuonPlot_TightSTACutsAll15Dec.root", // "Z0_DataMixPt50_PatDiMuonPlots_NewCutAll14Dec.root", const char* pHistNameOpCh="diMuonsGlobalInvMassVsPt",//diMuonsGlobalInvMassVsPtW", const char* pHistNameSameCh="diMuonsGlobalSameChargeInvMassVsPt", const char* pSpectra="pt", // pt, y, centr bool doMc=false, int nFitFunction = 3, int getYield = 1) { gROOT->Macro("setStyle.C+"); //gROOT->Macro("/Users/eusmartass/Software/utilities/setStyle.C+"); char szBuf[256]; //////// definitions of Switches /////////// // nFitFunction = 1 RBW + Pol2 // nFitFunction = 2 Gaus + Pol2 // nFitFunction = 3 RBWGaus + Pol2 // getYield = 1 Bin counting // getYield = 2 Integral //////////////////////////////////////////////////////////// // make some choices float MassZ0 = 91.1876; float WidthZ0 = 2.4952; float massFit_low = 60; float massFit_high = 120; // Fit ranges float massDraw_low = 30.0; // 0. float massDraw_high = 130.0; // 200/ int nrebin = 80; bool isLog = 0; bool isFit = 1; // draw ranges float massCount_low = 60.0; //78.0 float massCount_high = 120.0; //102.0 //___________________________________________________________________________________ // ------- Open input file sprintf(szBuf,"%s",pInFileName); TString inFileName(szBuf); TFile *pfInFile = new TFile(inFileName); // ------- get histograms: sprintf(szBuf,"%s",pHistNameOpCh); TH2D *phDimuMass_1 = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1"); sprintf(szBuf,"%s",pHistNameSameCh); TH2D *phDimuMass_1S = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1S"); phDimuMass_1->SetDirectory(0); phDimuMass_1S->SetDirectory(0); // Open pp data file TFile *ppFile = new TFile("Zmumu_40-200_35pb.root"); TH1F *Zmumu = (TH1F*)ppFile->Get("hdata"); //___________________________________________________________________________________ // bins definition: const char* Xname[] = {" ", "p_{T}^{Dimuon} (GeV/c)", "rapidity", "centrality"}; bool doPt = false; bool doY = false; bool doCent = false; int GenRange, nBins; double binEdge[10]; char* label; sprintf(szBuf,"%s",pSpectra); TString wichSpectra(szBuf); if ( wichSpectra.CompareTo("pt") == 0) { doPt = true; label = (char*)Xname[1]; GenRange = 20; nBins = 1; binEdge[0] = 0.0; binEdge[1]= 100.0; // double binEdge[10] = {0.0, 10., 20., 100.0}; if(doMc) { nBins = 1; binEdge[0] = 0.0; binEdge[1]= 50.0; // nBins = 7; // binEdge[0] = 0.0; binEdge[1] = 2.0; binEdge[2] = 4.0; binEdge[3] = 8.0; //binEdge[4] = 12.0; binEdge[5] = 16.0; binEdge[6] = 22.0; binEdge[7] = 50.0; } } else { if ( wichSpectra.CompareTo("y") == 0) { doY = true; label = (char*)Xname[2]; nBins = 3; GenRange = 4.8; binEdge[0] = -2.4; binEdge[1] = -0.8; binEdge[2] = 0.8; binEdge[3] = 2.4; } else { if ( wichSpectra.CompareTo("cent") == 0) { doCent = true; label = (char*)Xname[3]; nBins = 4; GenRange = 40; binEdge[0] = 0.; binEdge[1] = 4; binEdge[2] = 8.; binEdge[3] = 16; binEdge[4] = 40; } else { cout<<"Don't know what you want to do!!!!"<<endl; return; } } } double PT[10], DelPT[10], mom_err[100]; for (Int_t ih = 0; ih < nBins; ih++) { PT[ih] = (binEdge[ih] + binEdge[ih+1])/2.0; DelPT[ih] = binEdge[ih+1] - binEdge[ih]; mom_err[ih] = DelPT[ih]/2.0; } //___________________________________________________________________________________ double gen_pt[10]; double egen_pt[10]; TCanvas *pcPt_1 = new TCanvas("pcPt_1"," Z0 Yield Vs. Pt ", 40,40,600,600); if(doMc) { pcPt_1->Divide(nBins,2); //TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPt"); TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPtW"); TH1D *ptaxis = (TH1D*)genMass_1->ProjectionY("ptaxis"); for (Int_t ih = 0; ih < nBins; ih++) { pcPt_1->cd(ih+nBins+1); int bin1 = ptaxis->FindBin(binEdge[ih]+0.0000001); int bin2 = ptaxis->FindBin(binEdge[ih+1]+0.0000001); TH1D * genMassVsPt = (TH1D*)genMass_1->ProjectionX("genMassVsPt", bin1, bin2-1); genMassVsPt->Draw("EPL"); pcPt_1->Update(); TAxis *axs = genMassVsPt->GetXaxis(); int binlow = axs->FindBin(massCount_low); int binhi = axs->FindBin(massCount_high); double int_sig_gen; double int_sig_gen_sqr; for(Int_t bin = binlow; bin<=binhi; bin++) { // cout << " int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sigpow_gen <<"+="<< "bin" << bin << " content"<<genMassVsPt->GetBinContent(bin)<<endl; int_sig_gen += genMassVsPt->GetBinContent(bin); int_sig_gen_sqr += pow(genMassVsPt->GetBinContent(bin),2); } gen_pt[ih] = int_sig_gen;//genMassVsPt->GetEntries(); cout<<" gen entries : "<< gen_pt[ih]<<endl; egen_pt[ih] =int_sig_gen_sqr; } } else { if (nBins == 2) pcPt_1->Divide(2,1); if (nBins == 3 || nBins == 4) pcPt_1->Divide(2,2); if (nBins == 5 || nBins == 6) pcPt_1->Divide(3,2); } //___________________________________________________________________________________ // Fit Function // const char *name_fit[] = {" ", "RBWPol1", "GausPol1", "RBWGausPol2"}; int nParam[] = {0,6,6,7}; int nFitParam = nParam[nFitFunction]; TF1 *RBWPOL=0; if(nFitFunction == 1) RBWPOL = new TF1("RBWPOL", RBWPol2, 0, 200, nFitParam); if(nFitFunction == 2) RBWPOL = new TF1("RBWPOL", GausPol2, 0, 200, nFitParam); if(nFitFunction == 3) RBWPOL = new TF1("RBWPOL", RBWGausPol2, 0, 200, nFitParam); TF1 *EXP = new TF1("EXP", Exp, 0, 200, 2); RBWPOL->SetLineWidth(1); RBWPOL->SetParameter(1, MassZ0); RBWPOL->SetParameter(2, WidthZ0); RBWPOL->SetParLimits(1, 0.9*MassZ0, 1.1*MassZ0); RBWPOL->SetParLimits(2, 0.1*WidthZ0, 5.0*WidthZ0); if(nFitFunction == 1 || nFitFunction == 2) RBWPOL->FixParameter(5, 0); if(nFitFunction == 3 || nFitFunction == 4) { RBWPOL->SetParameter(3, WidthZ0); RBWPOL->SetParLimits(3, 0.1, 20); RBWPOL->FixParameter(2, WidthZ0); RBWPOL->FixParameter(4, 0); // for no bkg RBWPOL->FixParameter(5, 0); // for no bkg RBWPOL->FixParameter(6, 0); } //___________________________________________________________________________________ // Efficiency double yld_cat_1[10], cyld_cat_1[10], eyld_cat_1[10], ceyld_cat_1[10]; double Eff_cat_1[10], errEff_cat_1[10]; ///// Write the spectra sprintf(szBuf,"fileSpecta%d.root", getYield); // TFile *fileSpectra = new TFile(szBuf, "recreate"); //___________________________________________________________________________________ // Drawing // Category _1 TLegend *pLegCategory = new TLegend(.66, .74, .92, .94); // pLegCategory = new TLegend(.1, .82, .50, .93); pLegCategory->SetBorderSize(0); pLegCategory->SetFillStyle(0); pLegCategory->SetFillColor(0); pLegCategory->SetTextSize(0.03); // pLegCategory->AddEntry(RBWPOL," CMS Preliminary", " "); pLegCategory->AddEntry(RBWPOL," CMS Pb+Pb ", " "); pLegCategory->AddEntry(RBWPOL," #sqrt{s_{NN}} = 2.76 TeV ", " "); pLegCategory->AddEntry(RBWPOL," #int Ldt = 6.6 #mub^{-1} ", " "); // pLegCategory->AddEntry(RBWPOL," Global-Global ", ""); //pLegCategory->AddEntry(RBWPOL," |y| < 2.4 ", "P"); //pLegCategory->AddEntry(RBWPOL," Run# 150431-151027 ", "P"); TLegend *legend_1[12]; for(int i=0; i<12; i++) { if(isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94); if(!isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94 ); // legend_1[i] = new TLegend(.68, .62, .91, 0.93 ); legend_1[i]->SetBorderSize(0); legend_1[i]->SetFillStyle(0); legend_1[i]->SetFillColor(0); legend_1[i]->SetTextSize(0.028); } int bin_bound[100]; TH1D *dimuonsGlobalInvMassVsPt[10]; TH1D *dimuonsGlobalInvMassVsPtS[10]; TH1D *service = (TH1D*)phDimuMass_1->ProjectionY("service"); // cout << endl << label << " Yield Mass (GeV) Width (GeV) GauWidth chi2/ndf " << endl << endl; for (Int_t ih = 0; ih < nBins; ih++) { pcPt_1->cd(ih+1); gPad->SetTickx(); gPad->SetTicky(); // Project 1 D bin_bound[ih] = service->FindBin(binEdge[ih]+0.0000001); bin_bound[ih+1] = service->FindBin(binEdge[ih+1]+0.0000001); sprintf(szBuf,"Z0_1_pt_%d",ih); dimuonsGlobalInvMassVsPt[ih] = (TH1D*)phDimuMass_1->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1, "e"); sprintf(szBuf,"Z0_1S_pt_%d",ih); dimuonsGlobalInvMassVsPtS[ih] = (TH1D*)phDimuMass_1S->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1); cout << "reco entries" << dimuonsGlobalInvMassVsPt[ih]->GetEntries() <<endl; if(doPt || doY) { sprintf(szBuf," %s [%.1f, %.1f]", label, service->GetBinLowEdge(bin_bound[ih]), service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1])); } if(doCent) { sprintf(szBuf," %s [%.1f, %.1f] %s", label, 2.5*service->GetBinLowEdge(bin_bound[ih]), 2.5*(service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1])), "%"); } dimuonsGlobalInvMassVsPt[ih]->Rebin(nrebin); dimuonsGlobalInvMassVsPtS[ih]->Rebin(nrebin); // -------- Fit Function + Bkg Function double part[20]; dimuonsGlobalInvMassVsPt[ih]->Fit("EXP","LEQ", "", 34, 60); EXP->GetParameters(part); if(nFitFunction == 4) { RBWPOL->FixParameter(4, part[0]); RBWPOL->FixParameter(5, part[1]); } if(isFit) { //dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQ", "", massFit_low, massFit_high); //TFitResultPtr r = dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQS0","", massFit_low, massFit_high); // if(r->IsValid()) r->Print(); //else cout<<"Fit not valid!!!\n"<<endl; } //------ get fit parameters double par[20]; RBWPOL->GetParameters(par); float GGphDimuMass = RBWPOL->GetParameter(1); float GGZ0Width = RBWPOL->GetParameter(2); float GauWidth =0; if(nFitFunction == 3 || nFitFunction == 4) GauWidth = RBWPOL->GetParameter(3); double chisq = RBWPOL->GetChisquare(); int ndf = RBWPOL->GetNDF(); double chisqdf =1000; if(ndf!=0) chisqdf=chisq/ndf; // +++ set backgroudn fit sprintf(szBuf,"pt_1B_%d",ih); TF1 *bkgFit_1 = new TF1(szBuf, Pol2, massFit_low, massFit_high, 3); // if(nFitFunction == 4) bkgFit_1 = new TF1(namePt_1B, Exp, massFit_low, massFit_high, 2); bkgFit_1->SetParameters(&par[3]); if(nFitFunction == 3 || nFitFunction == 4) bkgFit_1->SetParameters(&par[4]); // ---------- Integrated Yield // float massCount_low =GGphDimuMass-(4.0*GGZ0Width); // float massCount_high =GGphDimuMass+(4.0*GGZ0Width); TAxis *axs = dimuonsGlobalInvMassVsPt[ih]->GetXaxis(); int binlow = axs->FindBin(massCount_low); int binhi = axs->FindBin(massCount_high); Double_t bin_size = (1.0*dimuonsGlobalInvMassVsPt[ih]->GetNbinsX())/(axs->GetXmax() - axs->GetXmin()); Float_t int_sig = 0.0; Float_t int_sig_sqr = 0.0; for(Int_t bin = binlow; bin<=binhi; bin++) { // cout << " int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sig <<"+="<< "bin" << bin << " content"<<dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin)<<endl; int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin); int_sig_sqr += pow(dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin),2); } if(getYield == 2) { int_sig = RBWPOL->Integral(massCount_low, massCount_high)*bin_size; yld_cat_1[ih] = int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high); eyld_cat_1[ih] = TMath::Sqrt(int_sig + bin_size*bkgFit_1->Integral(massCount_low, massCount_high) ); } else { yld_cat_1[ih] = int_sig ; eyld_cat_1[ih] = int_sig_sqr; } cout << "int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high);" << int_sig<< " -"<< bin_size<<"*"<<bkgFit_1->Integral(massCount_low, massCount_high)<< " with low"<< massCount_low<<" high "<< massCount_high<<endl; //// Printing ///// cout << PT[ih] << " " << yld_cat_1[ih] << " +- " << eyld_cat_1[ih] <<" " << GGphDimuMass << " " << GGZ0Width << " " << GauWidth <<" "<< chisq << "/" << ndf << endl; // -------------- Draw // dimuonsGlobalInvMassVsPt[ih]->SetMinimum(-.05*dimuonsGlobalInvMassVsPt[ih]->GetMaximum()); if(isLog) gPad->SetLogy(1); TColor *pal = new TColor(); Int_t kblue = pal->GetColor(9,0,200); // Int_t korange = pal->GetColor(101, 42, 0); // +++ opposite charge dimuonsGlobalInvMassVsPt[ih]->SetMarkerStyle(21); dimuonsGlobalInvMassVsPt[ih]->SetMarkerColor(kblue); dimuonsGlobalInvMassVsPt[ih]->SetLineColor(kblue); dimuonsGlobalInvMassVsPt[ih]->SetMarkerSize(1.1); dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetTitle("Dimuon mass (GeV/c^{2})"); dimuonsGlobalInvMassVsPt[ih]->GetYaxis()->SetTitle("dN/dM (2 GeV/c^{2})^{-1}"); dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetRangeUser(massDraw_low,massDraw_high); // dimuonsGlobalInvMassVsPt[ih]->Add(dimuonsGlobalInvMassVsPtS[ih], -1); pcPt_1->cd(ih+1); dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame"); // pp data TAxis *axs1 = Zmumu->GetXaxis(); int ll = axs1->FindBin(massCount_low); int hh = axs1->FindBin(massCount_high); double scalefactor = yld_cat_1[ih]/Zmumu->Integral(ll, hh); cout << Zmumu->Integral(ll, hh) << endl; Zmumu->Scale(scalefactor); Zmumu->SetFillColor(19); Zmumu->Draw("same"); dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame"); // dimuonsGlobalInvMassVsPt[ih]->Draw("B"); // +++ same charge dimuonsGlobalInvMassVsPtS[ih]->SetMarkerStyle(8); dimuonsGlobalInvMassVsPtS[ih]->SetMarkerColor(46); dimuonsGlobalInvMassVsPtS[ih]->SetLineColor(46); dimuonsGlobalInvMassVsPtS[ih]->SetMarkerSize(1.1); dimuonsGlobalInvMassVsPtS[ih]->DrawCopy("EPsame"); // background // RBWPOL->SetLineColor(kblue); bkgFit_1->SetLineColor(46); bkgFit_1->SetLineWidth(1); // if(isFit) bkgFit_1->Draw("same"); // ++++ legend pLegCategory->Draw("same"); // legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Global-Global", " "); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," |#eta^{#mu}| < 2.4, p_{T}^{#mu} > 10 GeV/c ", ""); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Unlike Sign ", "LP"); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPtS[ih]," Like Sign ", "LP"); legend_1[ih]->AddEntry(Zmumu," pp Data ", "L"); // legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], text, ""); sprintf(szBuf, "N=%1.0f #pm %1.1f ", yld_cat_1[ih], sqrt(yld_cat_1[ih]) ); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, ""); // sprintf(label_1, "N_{Z^{0}} = 27"); sprintf(szBuf, "mass = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(1), RBWPOL->GetParError(1)); // if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih],szBuf, ""); sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(2), RBWPOL->GetParError(2)); if(nFitFunction ==3 || nFitFunction == 4) sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(3), RBWPOL->GetParError(3)); // if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, ""); sprintf(szBuf, "#chi^{2}/ndf = %1.2f / %d", chisq, ndf); // if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], label_4, ""); legend_1[ih]->Draw("same"); pcPt_1->Update(); } cout << endl << endl; TGraphErrors *Z0pt_cat_1 = new TGraphErrors(nBins, PT, yld_cat_1, mom_err, eyld_cat_1); Z0pt_cat_1->SetMarkerStyle(20); Z0pt_cat_1->SetMarkerColor(2); Z0pt_cat_1->GetXaxis()->SetTitle(label); Z0pt_cat_1->GetYaxis()->SetTitle("counts"); TCanvas *pc2 = new TCanvas("pc2","pc2"); Z0pt_cat_1->SetMinimum(0.0); Z0pt_cat_1->SetName("Z0pt_cat_1"); Z0pt_cat_1->Draw("AP"); TGraphErrors *Z0ptC_cat_1_gen = new TGraphErrors(nBins, PT, gen_pt, mom_err, egen_pt); // Z0ptC_cat_1_gen->SetMarkerStyle(23); //Z0ptC_cat_1_gen->SetMarkerColor(3); //Z0ptC_cat_1_gen->Draw("AP"); pLegCategory->Draw("same"); Z0pt_cat_1->Write(); pLegCategory->Write(); // gPad->Print("Pt_Z0YieldCat_1.png"); pcPt_1->Print("Pt_Z0YieldCat_1.png"); cout << endl << endl; ////////////////////////////////////////////////////////////////////////////// // Efficiency correction if(doMc) { ofstream fileout("correction.txt"); cout << label << " Eff_cat_1 " << endl; for (Int_t ih = 0; ih < nBins; ih++) { Eff_cat_1[ih] = yld_cat_1[ih]/gen_pt[ih]; errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih] +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*( yld_cat_1[ih]-gen_pt[ih]/ yld_cat_1[ih])); // errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih] // +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*event failing); // fileout << PT[ih] <<" "<< Eff_cat_1[ih] << " " << Eff_cat_2[ih] <<" " << Eff_cat_3[ih] << endl; // cout <<" " << PT[ih] <<" "<< Eff_cat_1[ih] << " " << Eff_cat_2[ih] << " " << Eff_cat_3[ih] << endl; fileout << PT[ih] <<" "<< Eff_cat_1[ih] << " " << errEff_cat_1[ih] << endl; cout <<" " << PT[ih] <<" "<< Eff_cat_1[ih] << " +- " << errEff_cat_1[ih] << endl; cyld_cat_1[ih] = Eff_cat_1[ih]; ceyld_cat_1[ih] = errEff_cat_1[ih]; } } else { ifstream filein("correction.txt"); cout << label << " yld_cat_1 " << " efficiency " << " corr. yld_cat_1 " << endl; for (Int_t ih = 0; ih < nBins; ih++) { // filein >> PT[ih] >> Eff_cat_1[ih] >> Eff_cat_2[ih] >> Eff_cat_3[ih] ; // cout << " " << PT[ih] << " "<< yld_cat_1[ih] << " " << yld_cat_2[ih] <<" " << yld_cat_3[ih] << endl; filein >> PT[ih] >> Eff_cat_1[ih] >> errEff_cat_1[ih]; cout << " " << PT[ih] << " " << yld_cat_1[ih] << " " << Eff_cat_1[ih] << " " << yld_cat_1[ih]/Eff_cat_1[ih] << endl; cyld_cat_1[ih] = yld_cat_1[ih]/Eff_cat_1[ih]; ceyld_cat_1[ih] = eyld_cat_1[ih]/Eff_cat_1[ih]; } } // TF1 *EXPA = new TF1("EXPA", Exp, 0, 100, 2); TGraphErrors *Z0ptC_cat_1 = new TGraphErrors(nBins, PT, cyld_cat_1, mom_err, ceyld_cat_1); Z0ptC_cat_1->SetMarkerStyle(20); Z0ptC_cat_1->SetMarkerColor(2); Z0ptC_cat_1->GetXaxis()->SetTitle(label); Z0ptC_cat_1->GetYaxis()->SetTitle("Acc x Eff"); // if(part == 2) Z0ptC_cat_1->Fit("EXPA","LEQ", "", 7, 16); new TCanvas; Z0ptC_cat_1->SetMinimum(0.0); Z0ptC_cat_1->SetMaximum(0.8); Z0ptC_cat_1->SetName("Z0ptC_cat_1"); Z0ptC_cat_1->Draw("AP"); pLegCategory->Draw("same"); cout << endl << endl; Z0ptC_cat_1->Write(); }
void q4gep_jan2009() { gROOT->SetStyle("HALLA"); TCanvas *cn = new TCanvas("cn"); cn->Draw(); TH1F *frm = new TH1F("frm","",100,0.,15.); #ifndef DIFF_LAB frm->GetXaxis()->SetTitle("Q^{2} [GeV^{2}]"); #endif #ifdef DIFF_LAB frm->GetXaxis()->SetTitle("Q^{2} in GeV^{2}"); #endif frm->GetXaxis()->CenterTitle(); #ifndef DIFF_LAB frm->GetYaxis()->SetTitle("Q^{4} G_{E}^{p}"); #endif #ifdef DIFF_LAB frm->GetYaxis()->SetTitle("#muG_{Ep}/G_{Mp}"); #endif frm->GetYaxis()->CenterTitle(); frm->SetMinimum(-0.1); frm->SetMaximum(0.4); frm->UseCurrentStyle(); frm->Draw(); TF1 *ff = new TF1("ff",fff,1.,10.,1.); ff->SetLineColor(2); ff->SetLineStyle(2); ff->SetParameter(0,1.); ff->SetParameter(1,.3); // match to Gayou point at 5.54 GeV^2 ff->SetParameter(0,.1035); TMultiGraph* mgrDta = new TMultiGraph("Data","#frac{#mu_{p}G_{E}^{p}}{G_{M}^{p}}"); //TLegend *legDta = new TLegend(.58,.565,.875,.9,"","brNDC"); TLegend *legDta = new TLegend(.648,.682,.945,.900,"","brNDC"); TMultiGraph* wgr = mgrDta; TLegend *wlg = legDta; // the data legDta->SetBorderSize(0); // turn off border legDta->SetFillStyle(0); datafile_t *f = datafiles; TGraph* gr=0; TGraph* ogr=0; while ( f && f->filename ) { ogr=OneGraph(f); if (ogr) { gr = fromGEpGMptoQ4GEp(ogr); gr->SetLineWidth(2); if (f->lnpt) { mgrDta->Add(gr,f->lnpt); legDta->AddEntry(gr,f->label,f->lnpt); } else if (gr->GetMarkerStyle()>=20) { mgrDta->Add(gr,"p"); legDta->AddEntry(gr,f->label,"p"); } else { mgrDta->Add(gr,"l"); legDta->AddEntry(gr,f->label,"l"); } } f++; } mgrDta->Draw("p"); legDta->Draw();// don't draw the data legend TMultiGraph* mgrThry = new TMultiGraph("Theory","#frac{#mu_{p}G_{E}^{p}}{G_{M}^{p}}"); // TLegend *legThry = new TLegend(.585,.6,.9,.9,"","brNDC"); TLegend *legThry = new TLegend(.335,.689,.649,.911,"","brNDC"); wgr = mgrThry; wlg = legThry; // the theory wlg->SetBorderSize(0); // turn off border wlg->SetFillStyle(0); f = theoryfiles1; ogr=0; while ( f && f->filename ) { ogr=OneGraph(f); if (ogr) { gr = fromGEpGMptoQ4GEp(ogr); TGraphAsymmErrors *egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetEYhigh() && egr->GetEYhigh()[0]>0) { gr = toerror_band(egr); gr->SetFillStyle(3000+f->style); } gr->SetLineWidth(2); if (f->lnpt) { wgr->Add(gr,f->lnpt); if( f->label[0] != 'x' ){ wlg->AddEntry(gr,f->label,f->lnpt); } } else if (gr->GetMarkerStyle()>=20) { wgr->Add(gr,"p"); if( f->label[0] != 'x' ){ wlg->AddEntry(gr,f->label,"p"); } } else { wgr->Add(gr,"l"); if( f->label[0] != 'x' ){ wlg->AddEntry(gr,f->label,"l"); } } } f++; } mgrThry->Draw("c"); #ifdef PQCD ff->Draw("same"); legThry->AddEntry(ff,"F2/F1 #propto ln^{2}(Q^{2}/#Lambda^{2})/Q^{2}","l"); #endif// PQCD legThry->Draw(); cn->Modified(); cn->Update(); TFrame* frame = gPad->GetFrame(); // draw a line at 1 TLine *line1 = new TLine(frame->GetX1(),1.,frame->GetX2(),1.); line1->SetLineStyle(1); line1->Draw(); return; cn->Update(); cn->SaveAs(Form("%s.eps",psfile)); cn->SaveAs(Form("%s.root",psfile)); gSystem->Exec(Form("./replace_symbols.pl %s.eps",psfile)); // now an overlay, hopefully matching dimensions // remove everything except the frame cn->Update(); TList *clist = cn->GetListOfPrimitives(); frame = cn->GetFrame(); for (int i=0; i<clist->GetSize(); ) { if (clist->At(i) != frame) { clist->RemoveAt(i); } else i++; } // draw markers in the corners TMarker *mkr = new TMarker(frame->GetX1(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX1(),frame->GetY2(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY2(),2); mkr->Draw(); frame->SetLineColor(10); { datafile_t goeckeler = { "figure_input/Goeckeler/goeckeler.dat","Goeckeler", "[0]","[1]","[1]-[2]","[3]-[1]",0,0,1,4,"F" }; gr = OneGraph(&goeckeler); TGraphAsymmErrors *egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetEYhigh() && egr->GetEYhigh()[egr->GetN()/2]>0) { gr = toerror_band(egr); gr->SetLineStyle(1); gr->SetFillColor(gr->GetLineColor()); gr->SetFillStyle(3000+goeckeler.style); } gr->Draw("F"); cn->Update(); cn->SaveAs("mup_gep_gmp_goeckeler_Overlay.eps"); cn->SaveAs("mup_gep_gmp_goeckeler_Overlay.root"); // remove Goeckeler curve from plot clist->Remove(gr); } { datafile_t miller = { "figure_input/Miller/lattice.GEp_GMp.rtf","Miller", "[0]","[1]","[1]-[3]","[2]-[1]",0,0,1,3,"F" }; gr = OneGraph(&miller); TGraphAsymmErrors* egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetEYhigh() && egr->GetEYhigh()[egr->GetN()/2]>0) { gr = toerror_band(egr); gr->SetLineStyle(1); gr->SetFillColor(gr->GetLineColor()); gr->SetFillStyle(3000+miller.style); } gr->Draw("F"); cn->Update(); cn->SaveAs("mup_gep_gmp_Miller_Overlay.eps"); cn->SaveAs("mup_gep_gmp_Miller_Overlay.root"); clist->Remove(gr); } { datafile_t zanotti = { "figure_input/Zanotti/zanotti_gepgmp.dat","Zanotti", "[0]","[1]","[1]-[2]","[3]-[1]",0,0,1,6,"F" }; gr = OneGraph(&zanotti); TGraphAsymmErrors* egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetEYhigh() && egr->GetEYhigh()[egr->GetN()/2]>0) { gr = toerror_band(egr); gr->SetLineStyle(1); gr->SetFillColor(gr->GetLineColor()); gr->SetFillStyle(3000+zanotti.style); } gr->Draw("F"); cn->Update(); cn->SaveAs("mup_gep_gmp_Zanotti_Overlay.eps"); cn->SaveAs("mup_gep_gmp_Zanotti_Overlay.root"); clist->Remove(gr); } }
void PlotAlignmentValidation::plotDMR(const std::string variable, Int_t minHits ) { setNiceStyle(); gStyle->SetOptStat(0); // TList treeList=getTreeList(); TCanvas *c = new TCanvas("canv", "canv", 600, 600); setCanvasStyle( *c ); //loop over sub-detectors for (int i=1;i<7;++i){ int histo_Counter=1; TLegend *leg_hist = new TLegend(0.17,0.8,0.85,0.88); setLegendStyle(*leg_hist); //loop over file list //TTree *tree= (TTree*)treeList.First(); //binning int nbinsX=100; double xmin=0; double xmax=0; float maxY=0; bool isHisto = false; std::string plotVar=variable; THStack *hstack=new THStack("hstack","hstack"); for(std::vector<TkOfflineVariables*>::iterator it = sourceList.begin(); it != sourceList.end(); ++it){ //while ( tree ){ plotVar=variable; TString subdet = "entries>="; subdet+=minHits; subdet+=" && subDetId=="; subdet+=i; char binning [50]=""; sprintf (binning, ">>myhisto(%d, %f , %f)", nbinsX, xmin, xmax); TH1F *h = 0; if (histo_Counter==1&&plotVar=="meanX")(*it)->getTree()->Draw( (plotVar+=">>myhisto(50,-0.001,0.001)").c_str(),subdet,"goff"); else if (histo_Counter==1&&plotVar=="meanY")(*it)->getTree()->Draw( (plotVar+=">>myhisto(50,-0.005,0.005)").c_str(),subdet,"goff"); else if (histo_Counter==1&&plotVar=="medianX")(*it)->getTree()->Draw( (plotVar+=">>myhisto(50,-0.005,0.005)").c_str(),subdet,"goff"); else if (histo_Counter==1&&plotVar=="medianY")(*it)->getTree()->Draw( (plotVar+=">>myhisto(50,-0.005,0.005)").c_str(),subdet,"goff"); else if (histo_Counter==1&&plotVar=="meanNormX")(*it)->getTree()->Draw( (plotVar+=">>myhisto(100,-2,2)").c_str(),subdet,"goff"); else if (histo_Counter==1&&plotVar=="rmsX")(*it)->getTree()->Draw( (plotVar+=">>myhisto(100,0.,0.1)").c_str(),subdet,"goff"); else if (histo_Counter!=1)(*it)->getTree()->Draw( (plotVar+=binning).c_str(),subdet,"goff"); if (gDirectory) gDirectory->GetObject("myhisto", h); std::pair<float,float> fitResults(9999., 9999.); if (h){ if (h->GetEntries()>0) { isHisto = true; h->SetDirectory(0); //general draw options h->SetLineWidth(2); //first histo only, setting optStat... if (histo_Counter==1) setHistStyle(*h,plotVar.c_str() ,"#modules", 1 ); //set color later h->SetLineColor( (*it)->getLineColor() ); h->SetLineStyle( (*it)->getLineStyle() ); //h->SetMarkerStyle(20+file_Counter); //draw options if (maxY<h->GetMaximum()){ maxY=h->GetMaximum(); } //fit histogram for median and mean if (variable=="medianX"||variable =="meanX")fitResults=fitGauss(h, (*it)->getLineColor() ); if (histo_Counter==1){ //get mean and sigma from fit: gauss for 2sigma range hstack->Add(h); nbinsX=h->GetXaxis()->GetNbins(); xmin=h->GetXaxis()->GetXmin(); xmax=h->GetXaxis()->GetXmax(); }else if (histo_Counter!=1 && h->GetEntries()>0)hstack->Add(h); char legend [50]=""; std::string legEntry = (*it)->getName(); if ( (variable=="medianX"||variable =="meanX") && useFit_) sprintf (legend, "%s: #mu = %4.2f#mum, #sigma = %4.2f#mum ",legEntry.c_str(),fitResults.first ,fitResults.second); if ( (variable=="medianX"||variable =="meanX"||variable=="medianY"||variable =="meanY" )&&useFit_ == false) sprintf (legend, "%s: #mu = %4.2f#mum, rms = %4.2f#mum ",legEntry.c_str(),h->GetMean(1)*10000 ,h->GetRMS(1)*10000); else sprintf (legend, "%s ",legEntry.c_str()); if(h) leg_hist->AddEntry(h,legend,"l"); else std::cerr<< "histogram did not exist!"; } } // tree= (TTree*)treeList.After( tree ); // file_Counter++; histo_Counter++; } if (isHisto){ hstack->Draw("nostack"); hstack->SetMaximum(maxY*1.3); setTitleStyle(*hstack,plotVar.c_str() ,"#modules",i); setHistStyle(*hstack->GetHistogram(),plotVar.c_str() ,"#modules", 1 ); leg_hist->Draw(); std::string histName="D"; if (variable=="medianX") histName+="medianR_"; else if (variable=="medianY") histName+="medianYR_"; else if (variable=="meanX") histName+="meanR_"; else if (variable=="meanY") histName+="meanYR_"; else if (variable=="rmsX") histName+="rmsR_"; std::string subDetector =""; switch (i){ case 1 : subDetector+="TPB";break; case 2 : subDetector+="TPE";break; case 3 : subDetector+="TIB";break; case 4 : subDetector+="TID";break; case 5 : subDetector+="TOB";break; case 6 : subDetector+="TEC";break; } char PlotName[100]; sprintf( PlotName, "%s/%s%s.eps",outputDir.c_str(), histName.c_str(), subDetector.c_str() ); c->Update(); c->Print(PlotName); //c->Update(); //c->Close(); } delete hstack; hstack=0; } delete c; c=0; }
int main(int argc, char** argv) { // Set style options setTDRStyle(); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetOptTitle(0); gStyle->SetOptStat(1110); gStyle->SetOptFit(1); // Set fitting options TVirtualFitter::SetDefaultFitter("Fumili2"); //----------------- // Input parameters std::cout << "\n***************************************************************************************************************************" << std::endl; std::cout << "arcg: " << argc << std::endl; char* EBEE = argv[1]; int evtsPerPoint = atoi(argv[2]); int useRegression = atoi(argv[3]); std::string dayMin = ""; std::string dayMax = ""; std::string dayMinLabel = ""; std::string dayMaxLabel = ""; float absEtaMin = -1.; float absEtaMax = -1.; int IetaMin = -1; int IetaMax = -1; int IphiMin = -1; int IphiMax = -1; if(argc >= 5) { dayMin = std::string(argv[4])+" "+std::string(argv[5])+" "+std::string(argv[6]); dayMax = std::string(argv[7])+" "+std::string(argv[8])+" "+std::string(argv[9]); dayMinLabel = std::string(argv[4])+"_"+std::string(argv[5])+"_"+std::string(argv[6]); dayMaxLabel = std::string(argv[7])+"_"+std::string(argv[8])+"_"+std::string(argv[9]); t1 = dateToInt(dayMin); t2 = dateToInt(dayMax); } if(argc >= 11) { yMIN = atof(argv[10]); yMAX = atof(argv[11]); } if(argc >= 13) { absEtaMin = atof(argv[12]); absEtaMax = atof(argv[13]); } if(argc >= 15) { IetaMin = atoi(argv[14]); IetaMax = atoi(argv[15]); IphiMin = atoi(argv[16]); IphiMax = atoi(argv[17]); } std::cout << "EBEE: " << EBEE << std::endl; std::cout << "evtsPerPoint: " << evtsPerPoint << std::endl; std::cout << "useRegression: " << useRegression << std::endl; std::cout << "dayMin: " << dayMin << std::endl; std::cout << "dayMax: " << dayMax << std::endl; std::cout << "yMin: " << yMIN << std::endl; std::cout << "yMax: " << yMAX << std::endl; std::cout << "absEtaMin: " << absEtaMin << std::endl; std::cout << "absEtaMax: " << absEtaMax << std::endl; std::cout << "IetaMin: " << IetaMin << std::endl; std::cout << "IetaMax: " << IetaMax << std::endl; std::cout << "IphiMin: " << IphiMin << std::endl; std::cout << "IphiMax: " << IphiMax << std::endl; //------------------- // Define in/outfiles std::string folderName = std::string(EBEE) + "_" + dayMinLabel + "_" + dayMaxLabel; if( (absEtaMin != -1.) && (absEtaMax != -1.) ) { char absEtaBuffer[50]; sprintf(absEtaBuffer,"_%.2f-%.2f",absEtaMin,absEtaMax); folderName += std::string(absEtaBuffer); } if( (IetaMin != -1.) && (IetaMax != -1.) && (IphiMin != -1.) && (IphiMax != -1.) ) { char absEtaBuffer[50]; sprintf(absEtaBuffer,"_Ieta_%d-%d_Iphi_%d-%d",IetaMin,IetaMax,IphiMin,IphiMax); folderName += std::string(absEtaBuffer); } gSystem->mkdir(folderName.c_str()); TFile* o = new TFile((folderName+"/"+folderName+"_histos.root").c_str(),"RECREATE"); // Get trees std::cout << std::endl; TChain* ntu_DA = new TChain("simpleNtupleEoverP/SimpleNtupleEoverP"); FillChain(ntu_DA,"inputDATA.txt"); std::cout << " DATA: " << std::setw(8) << ntu_DA->GetEntries() << " entries" << std::endl; TChain* ntu_MC = new TChain("simpleNtupleEoverP/SimpleNtupleEoverP"); FillChain(ntu_MC,"inputMC.txt"); std::cout << "REFERENCE: " << std::setw(8) << ntu_MC->GetEntries() << " entries" << std::endl; if (ntu_DA->GetEntries() == 0 || ntu_MC->GetEntries() == 0 ) { std::cout << "Error: At least one file is empty" << std::endl; return -1; } // Set branch addresses int runId; int timeStampHigh; int PV_n; float scLaserCorr, seedLaserAlpha, EoP, scEta, scPhi, scE, ES, P; int seedIeta, seedIphi, seedIx, seedIy, seedZside; ntu_DA->SetBranchStatus("*",0); ntu_DA->SetBranchStatus("runId",1); ntu_DA->SetBranchStatus("timeStampHigh",1); ntu_DA->SetBranchStatus("PV_n",1); ntu_DA->SetBranchStatus("ele1_scLaserCorr",1); ntu_DA->SetBranchStatus("ele1_seedLaserAlpha",1); ntu_DA->SetBranchStatus("ele1_EOverP",1); ntu_DA->SetBranchStatus("ele1_scEta",1); ntu_DA->SetBranchStatus("ele1_scPhi",1); ntu_DA->SetBranchStatus("ele1_scE",1); ntu_DA->SetBranchStatus("ele1_scE_regression",1); ntu_DA->SetBranchStatus("ele1_scE",1); ntu_DA->SetBranchStatus("ele1_es",1); ntu_DA->SetBranchStatus("ele1_tkP",1); ntu_DA->SetBranchStatus("ele1_seedIeta",1); ntu_DA->SetBranchStatus("ele1_seedIphi",1); ntu_DA->SetBranchStatus("ele1_seedIx",1); ntu_DA->SetBranchStatus("ele1_seedIy",1); ntu_DA->SetBranchStatus("ele1_seedZside",1); ntu_DA->SetBranchAddress("runId", &runId); ntu_DA->SetBranchAddress("timeStampHigh", &timeStampHigh); ntu_DA->SetBranchAddress("PV_n", &PV_n); ntu_DA->SetBranchAddress("ele1_scLaserCorr", &scLaserCorr); ntu_DA->SetBranchAddress("ele1_seedLaserAlpha", &seedLaserAlpha); ntu_DA->SetBranchAddress("ele1_EOverP", &EoP); ntu_DA->SetBranchAddress("ele1_scEta", &scEta); ntu_DA->SetBranchAddress("ele1_scPhi", &scPhi); if( useRegression < 1 ) ntu_DA->SetBranchAddress("ele1_scE", &scE); else ntu_DA->SetBranchAddress("ele1_scE_regression", &scE); ntu_DA->SetBranchAddress("ele1_scE", &scE); ntu_DA->SetBranchAddress("ele1_es", &ES); ntu_DA->SetBranchAddress("ele1_tkP", &P); ntu_DA->SetBranchAddress("ele1_seedIeta", &seedIeta); ntu_DA->SetBranchAddress("ele1_seedIphi", &seedIphi); ntu_DA->SetBranchAddress("ele1_seedIx", &seedIx); ntu_DA->SetBranchAddress("ele1_seedIy", &seedIy); ntu_DA->SetBranchAddress("ele1_seedZside", &seedZside); ntu_MC->SetBranchStatus("*",0); ntu_MC->SetBranchStatus("runId",1); ntu_MC->SetBranchStatus("PV_n",1); ntu_MC->SetBranchStatus("ele1_scEta",1); ntu_MC->SetBranchStatus("ele1_EOverP",1); ntu_MC->SetBranchStatus("ele1_scE",1); ntu_MC->SetBranchStatus("ele1_scE_regression",1); ntu_MC->SetBranchStatus("ele1_es",1); ntu_MC->SetBranchStatus("ele1_tkP",1); ntu_MC->SetBranchStatus("ele1_seedIeta",1); ntu_MC->SetBranchStatus("ele1_seedIphi",1); ntu_MC->SetBranchStatus("ele1_seedIx",1); ntu_MC->SetBranchStatus("ele1_seedIy",1); ntu_MC->SetBranchStatus("ele1_seedZside",1); ntu_MC->SetBranchAddress("runId", &runId); ntu_MC->SetBranchAddress("PV_n", &PV_n); ntu_MC->SetBranchAddress("ele1_scEta", &scEta); ntu_MC->SetBranchAddress("ele1_EOverP", &EoP); if( useRegression < 1 ) ntu_MC->SetBranchAddress("ele1_scE", &scE); else ntu_MC->SetBranchAddress("ele1_scE_regression", &scE); ntu_MC->SetBranchAddress("ele1_es", &ES); ntu_MC->SetBranchAddress("ele1_tkP", &P); ntu_MC->SetBranchAddress("ele1_seedIeta", &seedIeta); ntu_MC->SetBranchAddress("ele1_seedIphi", &seedIphi); ntu_MC->SetBranchAddress("ele1_seedIx", &seedIx); ntu_MC->SetBranchAddress("ele1_seedIy", &seedIy); ntu_MC->SetBranchAddress("ele1_seedZside", &seedZside); //-------------------------------------------------------- // Define PU correction (to be used if useRegression == 0) // corr = p0 + p1 * PV_n float p0_EB; float p1_EB; float p0_EE; float p1_EE; if( useRegression == 0 ) { //2012 EB p0_EB = 0.9991; p1_EB = 0.0001635; //2012 EE p0_EE = 0.9968; p1_EE = 0.001046; } else { //2012 EB p0_EB = 1.001; p1_EB = -0.000143; //2012 EE p0_EE = 1.00327; p1_EE = -0.000432; } float p0 = -1.; float p1 = -1.; if( strcmp(EBEE,"EB") == 0 ) { p0 = p0_EB; p1 = p1_EB; } else { p0 = p0_EE; p1 = p1_EE; } //--------------------------------- // Build the reference distribution std::cout << std::endl; std::cout << "***** Build reference for " << EBEE << " *****" << std::endl; TH1F* h_template = new TH1F("template", "", 2000, 0., 5.); for(int ientry = 0; ientry < ntu_MC->GetEntries(); ++ientry) { if( (ientry%100000 == 0) ) std::cout << "reading MC entry " << ientry << "\r" << std::flush; ntu_MC->GetEntry(ientry); // selections if( (strcmp(EBEE,"EB") == 0) && (fabs(scEta) > 1.45) ) continue; // barrel if( (strcmp(EBEE,"EE") == 0) && (fabs(scEta) < 1.47 || fabs(scEta)>2.7) ) continue; // endcap if( (absEtaMin != -1.) && (absEtaMax != -1.) ) { if( (fabs(scEta) < absEtaMin) || (fabs(scEta) > absEtaMax) ) continue; } if( (IetaMin != -1.) && (IetaMax != -1.) && (IphiMin != -1.) && (IphiMax != -1.) ) { if( (seedIeta < IetaMin) || (seedIeta > IetaMax) ) continue; if( (seedIphi < IphiMin) || (seedIphi > IphiMax) ) continue; } // PU correction float PUCorr = (p0 + p1*PV_n); //std::cout << "p0: " << p0 << " p1: " << p1 << " PV_n: " << PV_n << std::endl; // fill the template histogram h_template -> Fill( (scE-ES)/(P-ES) / PUCorr ); } std::cout << "Reference built for " << EBEE << " - " << h_template->GetEntries() << " events" << std::endl; //--------------------- // Loop and sort events std::cout << std::endl; std::cout << "***** Sort events and define bins *****" << std::endl; int nEntries = ntu_DA -> GetEntriesFast(); int nSavePts = 0; std::vector<bool> isSavedEntries(nEntries); std::vector<Sorter> sortedEntries; std::vector<int> timeStampFirst; for(int ientry = 0; ientry < nEntries; ++ientry) { ntu_DA -> GetEntry(ientry); isSavedEntries.at(ientry) = false; // selections if( (strcmp(EBEE,"EB") == 0) && (fabs(scEta) > 1.45) ) continue; // barrel if( (strcmp(EBEE,"EE") == 0) && (fabs(scEta) < 1.47 || fabs(scEta)>2.7) ) continue; // endcap if( (absEtaMin != -1.) && (absEtaMax != -1.) ) { if( (fabs(scEta) < absEtaMin) || (fabs(scEta) > absEtaMax) ) continue; } if( (IetaMin != -1.) && (IetaMax != -1.) && (IphiMin != -1.) && (IphiMax != -1.) ) { if( (seedIeta < IetaMin) || (seedIeta > IetaMax) ) continue; if( (seedIphi < IphiMin) || (seedIphi > IphiMax) ) continue; } if( timeStampHigh < t1 ) continue; if( timeStampHigh > t2 ) continue; if( scLaserCorr <= 0. ) continue; isSavedEntries.at(ientry) = true; // fill sorter Sorter dummy; dummy.time = timeStampHigh; dummy.entry = ientry; sortedEntries.push_back(dummy); ++nSavePts; } // sort events std::sort(sortedEntries.begin(),sortedEntries.end(),Sorter()); std::cout << "Data sorted in " << EBEE << " - " << nSavePts << " events" << std::endl; std::map<int,int> antiMap; for(unsigned int iSaved = 0; iSaved < sortedEntries.size(); ++iSaved) antiMap[sortedEntries.at(iSaved).entry] = iSaved; //--------------------- // Loop and define bins // "wide" bins - find events with time separation bigger than 1 day int nWideBins = 1; std::vector<int> wideBinEntryMax; int timeStampOld = -1; wideBinEntryMax.push_back(0); for(int iSaved = 0; iSaved < nSavePts; ++iSaved) { if( iSaved%100000 == 0 ) std::cout << "reading saved entry " << iSaved << "\r" << std::flush; ntu_DA->GetEntry(sortedEntries[iSaved].entry); if( iSaved == 0 ) { timeStampOld = timeStampHigh; continue; } if( (timeStampHigh-timeStampOld)/3600. > timeLapse ) { ++nWideBins; wideBinEntryMax.push_back(iSaved-1); } timeStampOld = timeStampHigh; } std::cout << std::endl; wideBinEntryMax.push_back(nSavePts); // bins with approximatively evtsPerPoint events per bin int nBins = 0; std::vector<int> binEntryMax; binEntryMax.push_back(0); for(int wideBin = 0; wideBin < nWideBins; ++wideBin) { int nTempBins = std::max(1,int( (wideBinEntryMax.at(wideBin+1)-wideBinEntryMax.at(wideBin))/evtsPerPoint )); int nTempBinEntries = int( (wideBinEntryMax.at(wideBin+1)-wideBinEntryMax.at(wideBin))/nTempBins ); for(int tempBin = 0; tempBin < nTempBins; ++tempBin) { ++nBins; if( tempBin < nTempBins - 1 ) binEntryMax.push_back( wideBinEntryMax.at(wideBin) + (tempBin+1)*nTempBinEntries ); else binEntryMax.push_back( wideBinEntryMax.at(wideBin+1) ); } } std::cout << "nBins = " << nBins << std::endl; //for(int bin = 0; bin < nBins; ++bin) // std::cout << "bin: " << bin // << " entry min: " << setw(6) << binEntryMax.at(bin) // << " entry max: " << setw(6) << binEntryMax.at(bin+1) // << " events: " << setw(6) << binEntryMax.at(bin+1)-binEntryMax.at(bin) // << std::endl; //--------------------- // histogram definition TH1F* h_scOccupancy_eta = new TH1F("h_scOccupancy_eta","", 298, -2.6, 2.6); TH1F* h_scOccupancy_phi = new TH1F("h_scOccupancy_phi","", 363, -3.1765, 3.159); SetHistoStyle(h_scOccupancy_eta); SetHistoStyle(h_scOccupancy_phi); TH2F* h_seedOccupancy_EB = new TH2F("h_seedOccupancy_EB","", 171, -85., 86., 361, 0.,361.); TH2F* h_seedOccupancy_EEp = new TH2F("h_seedOccupancy_EEp","", 101, 0.,101., 100, 0.,101.); TH2F* h_seedOccupancy_EEm = new TH2F("h_seedOccupancy_EEm","", 101, 0.,101., 100, 0.,101.); SetHistoStyle(h_seedOccupancy_EB); SetHistoStyle(h_seedOccupancy_EEp); SetHistoStyle(h_seedOccupancy_EEm); TH1F* h_EoP_spread = new TH1F("h_EoP_spread","",100,yMIN,yMAX); TH1F* h_EoC_spread = new TH1F("h_EoC_spread","",100,yMIN,yMAX); TH1F* h_EoP_spread_run = new TH1F("h_EoP_spread_run","",100,yMIN,yMAX); TH1F* h_EoC_spread_run = new TH1F("h_EoC_spread_run","",100,yMIN,yMAX); SetHistoStyle(h_EoP_spread,"EoP"); SetHistoStyle(h_EoC_spread,"EoC"); SetHistoStyle(h_EoP_spread_run,"EoP"); SetHistoStyle(h_EoC_spread_run,"EoC"); TH1F* h_EoP_chi2 = new TH1F("h_EoP_chi2","",50,0.,5.); TH1F* h_EoC_chi2 = new TH1F("h_EoC_chi2","",50,0.,5.); SetHistoStyle(h_EoP_chi2,"EoP"); SetHistoStyle(h_EoC_chi2,"EoC"); TH1F** h_EoP = new TH1F*[nBins]; TH1F** h_EoC = new TH1F*[nBins]; TH1F** h_Las = new TH1F*[nBins]; TH1F** h_Tsp = new TH1F*[nBins]; TH1F** h_Cvl = new TH1F*[nBins]; for(int i = 0; i < nBins; ++i) { char histoName[80]; sprintf(histoName, "EoP_%d", i); h_EoP[i] = new TH1F(histoName, histoName, 2000, 0., 5.); SetHistoStyle(h_EoP[i],"EoP"); sprintf(histoName, "EoC_%d", i); h_EoC[i] = new TH1F(histoName, histoName, 2000, 0., 5.); SetHistoStyle(h_EoC[i],"EoC"); sprintf(histoName, "Las_%d", i); h_Las[i] = new TH1F(histoName, histoName, 500, 0.5, 1.5); sprintf(histoName, "Tsp_%d", i); h_Tsp[i] = new TH1F(histoName, histoName, 500, 0.5, 1.5); } // function definition TF1** f_EoP = new TF1*[nBins]; TF1** f_EoC = new TF1*[nBins]; // graphs definition TGraphAsymmErrors* g_fit = new TGraphAsymmErrors(); TGraphAsymmErrors* g_c_fit = new TGraphAsymmErrors(); TGraphAsymmErrors* g_fit_run = new TGraphAsymmErrors(); TGraphAsymmErrors* g_c_fit_run = new TGraphAsymmErrors(); TGraph* g_las = new TGraph(); TGraphErrors* g_LT = new TGraphErrors(); g_fit->GetXaxis()->SetTimeFormat("%d/%m%F1970-01-01 00:00:00"); g_fit->GetXaxis()->SetTimeDisplay(1); g_c_fit->GetXaxis()->SetTimeFormat("%d/%m%F1970-01-01 00:00:00"); g_c_fit->GetXaxis()->SetTimeDisplay(1); g_las->GetXaxis()->SetTimeFormat("%d/%m%F1970-01-01 00:00:00"); g_las->GetXaxis()->SetTimeDisplay(1); g_LT->GetXaxis()->SetTimeFormat("%d/%m%F1970-01-01 00:00:00"); g_LT->GetXaxis()->SetTimeDisplay(1); //------------------------------------ // loop on the saved and sorted events std::cout << std::endl; std::cout << "***** Fill and fit histograms *****" << std::endl; std::vector<int> Entries(nBins); std::vector<double> AveTime(nBins); std::vector<int> MinTime(nBins); std::vector<int> MaxTime(nBins); std::vector<double> AveRun(nBins); std::vector<int> MinRun(nBins); std::vector<int> MaxRun(nBins); std::vector<double> AveLT(nBins); std::vector<double> AveLT2(nBins); int iSaved = -1; for(int ientry = 0; ientry < nEntries; ++ientry) { if( (ientry%100000 == 0) ) std::cout << "reading entry " << ientry << "\r" << std::flush; if( isSavedEntries.at(ientry) == false ) continue; ++iSaved; int iSaved = antiMap[ientry]; int bin = -1; for(bin = 0; bin < nBins; ++bin) if( iSaved >= binEntryMax.at(bin) && iSaved < binEntryMax.at(bin+1) ) break; //std::cout << "bin = " << bin << " iSaved = "<< iSaved << std::endl; ntu_DA->GetEntry(ientry); Entries[bin] += 1; if( iSaved == binEntryMax.at(bin)+1 ) MinTime[bin] = timeStampHigh; if( iSaved == binEntryMax.at(bin+1)-1 ) MaxTime[bin] = timeStampHigh; AveTime[bin] += timeStampHigh; if( iSaved == binEntryMax.at(bin)+1 ) MinRun[bin] = runId; if( iSaved == binEntryMax.at(bin+1)-1 ) MaxRun[bin] = runId; AveRun[bin] += runId; float LT = (-1. / seedLaserAlpha * log(scLaserCorr)); AveLT[bin] += LT; AveLT2[bin] += LT*LT; // PU correction float PUCorr = (p0 + p1*PV_n); // fill the histograms (h_EoP[bin]) -> Fill( (scE-ES)/(P-ES) / scLaserCorr / PUCorr); (h_EoC[bin]) -> Fill( (scE-ES)/(P-ES) / PUCorr ); (h_Las[bin]) -> Fill(scLaserCorr); (h_Tsp[bin]) -> Fill(1./scLaserCorr); h_scOccupancy_eta -> Fill(scEta); h_scOccupancy_phi -> Fill(scPhi); if(seedZside == 0) h_seedOccupancy_EB -> Fill(seedIeta,seedIphi); if(seedZside > 0) h_seedOccupancy_EEp -> Fill(seedIx,seedIy); if(seedZside < 0) h_seedOccupancy_EEm -> Fill(seedIx,seedIy); } for(int bin = 0; bin < nBins; ++bin) { AveTime[bin] = 1. * AveTime[bin] / (binEntryMax.at(bin+1)-binEntryMax.at(bin)); AveRun[bin] = 1. * AveRun[bin] / (binEntryMax.at(bin+1)-binEntryMax.at(bin)); AveLT[bin] = 1. * AveLT[bin] / (binEntryMax.at(bin+1)-binEntryMax.at(bin)); AveLT2[bin] = 1. * AveLT2[bin] / (binEntryMax.at(bin+1)-binEntryMax.at(bin)); //std::cout << date << " " << AveTime[i] << " " << MinTime[i] << " " << MaxTime[i] << std::endl; } int rebin = 2; if( strcmp(EBEE,"EE") == 0 ) rebin *= 2; h_template -> Rebin(rebin); float EoP_scale = 0.; float EoP_err = 0.; int EoP_nActiveBins = 0; float EoC_scale = 0.; float EoC_err = 0.; int EoC_nActiveBins = 0; float LCInv_scale = 0; std::vector<int> validBins; for(int i = 0; i < nBins; ++i) { bool isValid = true; h_EoP[i] -> Rebin(rebin); h_EoC[i] -> Rebin(rebin); //------------------------------------ // Fill the graph for uncorrected data // define the fitting function // N.B. [0] * ( [1] * f( [1]*(x-[2]) ) ) //o -> cd(); char convolutionName[50]; sprintf(convolutionName,"h_convolution_%d",i); //h_Cvl[i] = ConvoluteTemplate(std::string(convolutionName),h_template,h_Las[i],32768,-5.,5.); h_Cvl[i] = MellinConvolution(std::string(convolutionName),h_template,h_Tsp[i]); histoFunc* templateHistoFunc = new histoFunc(h_template); histoFunc* templateConvolutedHistoFunc = new histoFunc(h_Cvl[i]); char funcName[50]; sprintf(funcName,"f_EoP_%d",i); if( strcmp(EBEE,"EB") == 0 ) f_EoP[i] = new TF1(funcName, templateConvolutedHistoFunc, 0.8*(h_Tsp[i]->GetMean()), 1.4*(h_Tsp[i]->GetMean()), 3, "histoFunc"); else f_EoP[i] = new TF1(funcName, templateConvolutedHistoFunc, 0.75*(h_Tsp[i]->GetMean()), 1.5*(h_Tsp[i]->GetMean()), 3, "histoFunc"); f_EoP[i] -> SetParName(0,"Norm"); f_EoP[i] -> SetParName(1,"Scale factor"); f_EoP[i] -> SetLineWidth(1); f_EoP[i] -> SetNpx(10000); double xNorm = h_EoP[i]->GetEntries()/h_template->GetEntries() * h_EoP[i]->GetBinWidth(1)/h_template->GetBinWidth(1); f_EoP[i] -> FixParameter(0, xNorm); f_EoP[i] -> SetParameter(1, 1.); f_EoP[i] -> FixParameter(2, 0.); f_EoP[i] -> SetLineColor(kRed+2); int fStatus = 0; int nTrials = 0; TFitResultPtr rp; rp = h_EoP[i] -> Fit(funcName, "QERLS+"); while( (fStatus != 0) && (nTrials < 10) ) { rp = h_EoP[i] -> Fit(funcName, "QERLS+"); fStatus = rp; if(fStatus == 0) break; ++nTrials; } // fill the graph double eee = f_EoP[i]->GetParError(1); //float k = f_EoP[i]->GetParameter(1); float k = f_EoP[i]->GetParameter(1) / h_Tsp[i]->GetMean(); //needed when using mellin's convolution if( (h_EoP[i]->GetEntries() > 3) && (fStatus == 0) && (eee > 0.05*h_template->GetRMS()/sqrt(evtsPerPoint)) ) { float date = (float)AveTime[i]; float dLow = (float)(AveTime[i]-MinTime[i]); float dHig = (float)(MaxTime[i]-AveTime[i]); float run = (float)AveRun[i]; float rLow = (float)(AveRun[i]-MinRun[i]); float rHig = (float)(MaxRun[i]-AveRun[i]); g_fit -> SetPoint(i, date , 1./k); g_fit -> SetPointError(i, dLow , dHig, eee/k/k, eee/k/k); g_fit_run -> SetPoint(i, run , 1./k); g_fit_run -> SetPointError(i, rLow , rHig, eee/k/k, eee/k/k); h_EoP_chi2 -> Fill(f_EoP[i]->GetChisquare()/f_EoP[i]->GetNDF()); EoP_scale += 1./k; EoP_err += eee/k/k; ++EoP_nActiveBins; } else { std::cout << "Fitting uncorrected time bin: " << i << " Fail status: " << fStatus << " sigma: " << eee << std::endl; isValid = false; } //---------------------------------- // Fill the graph for corrected data // define the fitting function // N.B. [0] * ( [1] * f( [1]*(x-[2]) ) ) sprintf(funcName,"f_EoC_%d",i); if( strcmp(EBEE,"EB") == 0 ) f_EoC[i] = new TF1(funcName, templateHistoFunc, 0.8, 1.4, 3, "histoFunc"); else f_EoC[i] = new TF1(funcName, templateHistoFunc, 0.75, 1.5, 3, "histoFunc"); f_EoC[i] -> SetParName(0,"Norm"); f_EoC[i] -> SetParName(1,"Scale factor"); f_EoC[i] -> SetLineWidth(1); f_EoC[i] -> SetNpx(10000); xNorm = h_EoC[i]->GetEntries()/h_template->GetEntries() * h_EoC[i]->GetBinWidth(1)/h_template->GetBinWidth(1); f_EoC[i] -> FixParameter(0, xNorm); f_EoC[i] -> SetParameter(1, 0.99); f_EoC[i] -> FixParameter(2, 0.); f_EoC[i] -> SetLineColor(kGreen+2); rp = h_EoC[i] -> Fit(funcName, "QERLS+"); fStatus = rp; nTrials = 0; while( (fStatus != 0) && (nTrials < 10) ) { rp = h_EoC[i] -> Fit(funcName, "QERLS+"); fStatus = rp; if(fStatus == 0) break; ++nTrials; } // fill the graph k = f_EoC[i]->GetParameter(1); eee = f_EoC[i]->GetParError(1); if( (h_EoC[i]->GetEntries() > 10) && (fStatus == 0) && (eee > 0.05*h_template->GetRMS()/sqrt(evtsPerPoint)) ) { float date = (float)AveTime[i]; float dLow = (float)(AveTime[i]-MinTime[i]); float dHig = (float)(MaxTime[i]-AveTime[i]); float run = (float)AveRun[i]; float rLow = (float)(AveRun[i]-MinRun[i]); float rHig = (float)(MaxRun[i]-AveRun[i]); g_c_fit -> SetPoint(i, date , 1./k); g_c_fit -> SetPointError(i, dLow , dHig , eee/k/k, eee/k/k); g_c_fit_run -> SetPoint(i, run , 1./k); g_c_fit_run -> SetPointError(i, rLow , rHig, eee/k/k, eee/k/k); h_EoC_chi2 -> Fill(f_EoC[i]->GetChisquare()/f_EoP[i]->GetNDF()); EoC_scale += 1./k; EoC_err += eee/k/k; ++EoC_nActiveBins; } else { std::cout << "Fitting corrected time bin: " << i << " Fail status: " << fStatus << " sigma: " << eee << std::endl; isValid = false; } if( isValid == true ) validBins.push_back(i); } EoP_scale /= EoP_nActiveBins; EoP_err /= EoP_nActiveBins; EoC_scale /= EoC_nActiveBins; EoC_err /= EoC_nActiveBins; //---------------------------------------- // Fill the graph for avg laser correction //fede for(unsigned int itr = 0; itr < validBins.size(); ++itr) { int i = validBins.at(itr); g_las -> SetPoint(itr, (float)AveTime[i], h_Tsp[i]->GetMean() ); g_LT -> SetPoint(itr, (float)AveTime[i], AveLT[i] ); g_LT -> SetPointError(itr, 0., sqrt(AveLT2[i]-AveLT[i]*AveLT[i]) / sqrt(Entries[i]) ); LCInv_scale += h_Tsp[i]->GetMean(); } LCInv_scale /= validBins.size(); //--------------- // Rescale graphs float yscale = 1.; //float yscale = 1./EoC_scale; for(unsigned int itr = 0; itr < validBins.size(); ++itr) { double x,y; g_fit -> GetPoint(itr,x,y); g_fit -> SetPoint(itr,x,y*yscale); if ( (x > t1) && (x < t2) ) h_EoP_spread -> Fill(y*yscale); g_c_fit -> GetPoint(itr,x,y); g_c_fit -> SetPoint(itr,x,y*yscale); if ( (x > t1) && (x < t2) ) h_EoC_spread -> Fill(y*yscale); g_fit_run -> GetPoint(itr,x,y); g_fit_run -> SetPoint(itr,x,y*yscale); if ( (x > t1) && (x < t2) ) h_EoP_spread_run -> Fill(y*yscale); g_c_fit_run -> GetPoint(itr,x,y); g_c_fit_run -> SetPoint(itr,x,y*yscale); if ( (x > t1) && (x < t2) ) h_EoC_spread_run -> Fill(y*yscale); g_las -> GetPoint(itr,x,y); g_las -> SetPoint(itr,x,y*yscale*EoP_scale/LCInv_scale); } TF1 EoC_pol0("EoC_pol0","pol0",t1,t2); EoC_pol0.SetLineColor(kGreen+2); EoC_pol0.SetLineWidth(2); EoC_pol0.SetLineStyle(2); g_c_fit -> Fit("EoC_pol0","QNR"); //---------------------------- // Print out global quantities std::cout << std::endl; std::cout << "***** Mean scales and errors *****" << std::endl; std::cout << std::fixed; std::cout << std::setprecision(4); std::cout << "Mean EoP scale: " << std::setw(6) << EoP_scale << " mean EoP error: " << std::setw(8) << EoP_err << std::endl; std::cout << "Mean EoC scale: " << std::setw(6) << EoC_scale << " mean EoC error: " << std::setw(8) << EoC_err << std::endl; std::cout << "Mean 1/LC scale: " << std::setw(6) << LCInv_scale << std::endl; //----------------- // Occupancy plots //----------------- TCanvas* c_scOccupancy = new TCanvas("c_scOccupancy","SC occupancy",0,0,1000,500); c_scOccupancy -> Divide(2,1); c_scOccupancy -> cd(1); h_scOccupancy_eta -> GetXaxis() -> SetTitle("sc #eta"); h_scOccupancy_eta -> GetYaxis() -> SetTitle("events"); h_scOccupancy_eta -> Draw(); c_scOccupancy -> cd(2); h_scOccupancy_phi -> GetXaxis() -> SetTitle("sc #phi"); h_scOccupancy_phi -> GetYaxis() -> SetTitle("events"); h_scOccupancy_phi -> Draw(); TCanvas* c_seedOccupancy = new TCanvas("c_seedOccupancy","seed occupancy",0,0,1500,500); c_seedOccupancy -> Divide(3,1); c_seedOccupancy -> cd(1); h_seedOccupancy_EB -> GetXaxis() -> SetTitle("seed i#eta"); h_seedOccupancy_EB -> GetYaxis() -> SetTitle("seed i#phi"); h_seedOccupancy_EB -> Draw("COLZ"); c_seedOccupancy -> cd(2); h_seedOccupancy_EEp -> GetXaxis() -> SetTitle("seed ix"); h_seedOccupancy_EEp -> GetYaxis() -> SetTitle("seed iy"); h_seedOccupancy_EEp -> Draw("COLZ"); c_seedOccupancy -> cd(3); h_seedOccupancy_EEm -> GetXaxis() -> SetTitle("seed ix"); h_seedOccupancy_EEm -> GetYaxis() -> SetTitle("seed iy"); h_seedOccupancy_EEm -> Draw("COLZ"); //----------- // Chi2 plots //----------- TCanvas* c_chi2 = new TCanvas("c_chi2","fit chi2",0,0,500,500); c_chi2 -> cd(); h_EoC_chi2 -> GetXaxis() -> SetTitle("#chi^{2}/N_{dof}"); h_EoC_chi2 -> Draw(""); gPad -> Update(); TPaveStats* s_EoC = new TPaveStats; s_EoC = (TPaveStats*)(h_EoC_chi2->GetListOfFunctions()->FindObject("stats")); s_EoC -> SetStatFormat("1.4g"); s_EoC -> SetTextColor(kGreen+2); s_EoC->SetY1NDC(0.59); s_EoC->SetY2NDC(0.79); s_EoC -> Draw("sames"); gPad -> Update(); h_EoP_chi2 -> GetXaxis() -> SetTitle("#chi^{2}/N_{dof}"); h_EoP_chi2 -> Draw("sames"); gPad -> Update(); TPaveStats* s_EoP = new TPaveStats; s_EoP = (TPaveStats*)(h_EoP_chi2->GetListOfFunctions()->FindObject("stats")); s_EoP -> SetStatFormat("1.4g"); s_EoP -> SetTextColor(kRed+2); s_EoP->SetY1NDC(0.79); s_EoP->SetY2NDC(0.99); s_EoP -> Draw("sames"); gPad -> Update(); //------------------- // Final plot vs date //------------------- TCanvas* cplot = new TCanvas("cplot", "history plot vs date",100,100,1000,500); cplot->cd(); TPad *cLeft = new TPad("pad_0","pad_0",0.00,0.00,0.75,1.00); TPad *cRight = new TPad("pad_1","pad_1",0.75,0.00,1.00,1.00); cLeft->SetLeftMargin(0.15); cLeft->SetRightMargin(0.025); cRight->SetLeftMargin(0.025); cLeft->Draw(); cRight->Draw(); float tYoffset = 1.0; float labSize = 0.05; float labSize2 = 0.06; cLeft->cd(); cLeft->SetGridx(); cLeft->SetGridy(); TH1F *hPad = (TH1F*)gPad->DrawFrame(t1,0.9,t2,1.05); hPad->GetXaxis()->SetTimeFormat("%d/%m%F1970-01-01 00:00:00"); hPad->GetXaxis()->SetTimeDisplay(1); hPad->GetXaxis() -> SetRangeUser(MinTime[0]-43200,MaxTime[nBins-1]+43200); hPad->GetXaxis()->SetTitle("date (day/month)"); if( strcmp(EBEE,"EB") == 0 ) hPad->GetYaxis()->SetTitle("Relative E/p scale"); else hPad->GetYaxis()->SetTitle("Relative E/p scale"); hPad->GetYaxis()->SetTitleOffset(tYoffset); hPad->GetXaxis()->SetLabelSize(labSize); hPad->GetXaxis()->SetTitleSize(labSize2); hPad->GetYaxis()->SetLabelSize(labSize); hPad->GetYaxis()->SetTitleSize(labSize2); hPad -> SetMinimum(yMIN); hPad -> SetMaximum(yMAX); // draw history plot g_fit -> SetMarkerStyle(24); g_fit -> SetMarkerSize(0.7); g_fit -> SetMarkerColor(kRed+2); g_fit -> SetLineColor(kRed+2); g_fit -> Draw("P"); g_c_fit -> SetMarkerStyle(20); g_c_fit -> SetMarkerColor(kGreen+2); g_c_fit -> SetLineColor(kGreen+2); g_c_fit -> SetMarkerSize(0.7); g_c_fit -> Draw("P,same"); g_las -> SetLineColor(kAzure-2); g_las -> SetLineWidth(2); g_las -> Draw("L,same"); TLegend* legend = new TLegend(0.60,0.78,0.90,0.94); legend -> SetLineColor(kWhite); legend -> SetLineWidth(0); legend -> SetFillColor(kWhite); legend -> SetFillStyle(0); legend -> SetTextFont(42); legend -> SetTextSize(0.04); legend -> AddEntry(g_c_fit,"with LM correction","PL"); legend -> AddEntry(g_fit, "without LM correction","PL"); legend -> AddEntry(g_las, "1 / LM correction","L"); legend -> Draw("same"); char latexBuffer[250]; sprintf(latexBuffer,"CMS 2012 Preliminary"); TLatex* latex = new TLatex(0.18,0.89,latexBuffer); latex -> SetNDC(); latex -> SetTextFont(62); latex -> SetTextSize(0.05); latex -> Draw("same"); //sprintf(latexBuffer,"#sqrt{s} = 8 TeV L = 3.95 fb^{-1}"); sprintf(latexBuffer,"#sqrt{s} = 8 TeV"); TLatex* latex2 = new TLatex(0.18,0.84,latexBuffer); latex2 -> SetNDC(); latex2 -> SetTextFont(42); latex2 -> SetTextSize(0.05); latex2 -> Draw("same"); if( strcmp(EBEE,"EB") == 0 ) sprintf(latexBuffer,"ECAL Barrel"); else sprintf(latexBuffer,"ECAL Endcap"); TLatex* latex3 = new TLatex(0.18,0.19,latexBuffer); latex3 -> SetNDC(); latex3 -> SetTextFont(42); latex3 -> SetTextSize(0.05); latex3 -> Draw("same"); //sprintf(latexBuffer,"%.2E events",1.*nSavePts); //TLatex* latex4 = new TLatex(0.18,0.24,latexBuffer); //latex4 -> SetNDC(); //latex4 -> SetTextFont(42); //latex4 -> SetTextSize(0.04); //latex4 -> Draw("same"); // //sprintf(latexBuffer,"%d events/bin - %d bins",evtsPerPoint,nBins); //TLatex* latex5 = new TLatex(0.18,0.19,latexBuffer); //latex5 -> SetNDC(); //latex5 -> SetTextFont(42); //latex5 -> SetTextSize(0.04); //latex5 -> Draw("same"); cRight -> cd(); TPaveStats* s_EoP_spread = new TPaveStats(); TPaveStats* s_EoC_spread = new TPaveStats(); h_EoC_spread -> SetFillStyle(3001); h_EoC_spread -> SetFillColor(kGreen+2); h_EoC_spread->GetYaxis()->SetLabelSize(0.09); h_EoC_spread->GetYaxis()->SetLabelOffset(-0.03); h_EoC_spread->GetYaxis()->SetTitleSize(0.08); h_EoC_spread->GetYaxis()->SetNdivisions(505); h_EoC_spread->GetXaxis()->SetLabelOffset(1000); h_EoC_spread -> Draw("hbar"); gPad -> Update(); s_EoC_spread = (TPaveStats*)(h_EoC_spread->GetListOfFunctions()->FindObject("stats")); s_EoC_spread -> SetStatFormat("1.4g"); s_EoC_spread->SetX1NDC(0.06); //new x start position s_EoC_spread->SetX2NDC(0.71); //new x end position s_EoC_spread->SetY1NDC(0.93); //new x start position s_EoC_spread->SetY2NDC(0.84); //new x end position s_EoC_spread -> SetOptStat(1100); s_EoC_spread ->SetTextColor(kGreen+2); s_EoC_spread ->SetTextSize(0.08); s_EoC_spread -> Draw("sames"); h_EoP_spread -> SetFillStyle(3001); h_EoP_spread -> SetFillColor(kRed+2); h_EoP_spread -> Draw("hbarsames"); gPad -> Update(); s_EoP_spread = (TPaveStats*)(h_EoP_spread->GetListOfFunctions()->FindObject("stats")); s_EoP_spread -> SetStatFormat("1.4g"); s_EoP_spread->SetX1NDC(0.06); //new x start position s_EoP_spread->SetX2NDC(0.71); //new x end position s_EoP_spread->SetY1NDC(0.83); //new x start position s_EoP_spread->SetY2NDC(0.74); //new x end position s_EoP_spread ->SetOptStat(1100); s_EoP_spread ->SetTextColor(kRed+2); s_EoP_spread ->SetTextSize(0.08); s_EoP_spread -> Draw("sames"); /* h_EoP_spread -> SetFillStyle(3001); h_EoP_spread -> SetFillColor(kRed+2); h_EoP_spread -> Draw("hbarsame"); gPad -> Update(); */ //------------------ // Final plot vs run //------------------ TCanvas* cplot_run = new TCanvas("cplot_run", "history plot vs run",100,100,1000,500); cplot_run->cd(); cLeft = new TPad("pad_0_run","pad_0_run",0.00,0.00,0.75,1.00); cRight = new TPad("pad_1_run","pad_1_run",0.75,0.00,1.00,1.00); cLeft->SetLeftMargin(0.15); cLeft->SetRightMargin(0.025); cRight->SetLeftMargin(0.025); cLeft->Draw(); cRight->Draw(); tYoffset = 1.5; labSize = 0.04; labSize2 = 0.07; cLeft->cd(); cLeft->SetGridx(); cLeft->SetGridy(); hPad = (TH1F*)gPad->DrawFrame(MinRun[0]-1000,0.9,MaxRun[nBins-1]+1000,1.05); hPad->GetXaxis()->SetTitle("run"); if( strcmp(EBEE,"EB") == 0 ) hPad->GetYaxis()->SetTitle("Relative E/p scale"); else hPad->GetYaxis()->SetTitle("Relative E/p scale"); hPad->GetYaxis()->SetTitleOffset(tYoffset); hPad->GetXaxis()->SetLabelSize(labSize); hPad->GetXaxis()->SetTitleSize(labSize); hPad->GetYaxis()->SetLabelSize(labSize); hPad->GetYaxis()->SetTitleSize(labSize); hPad -> SetMinimum(yMIN); hPad -> SetMaximum(yMAX); // draw history plot g_fit_run -> SetMarkerStyle(20); g_fit_run -> SetMarkerSize(0.7); g_fit_run -> SetMarkerColor(kRed+2); g_fit_run -> SetLineColor(kRed+2); g_fit_run -> Draw("P"); g_c_fit_run -> SetMarkerStyle(20); g_c_fit_run -> SetMarkerColor(kGreen+2); g_c_fit_run -> SetLineColor(kGreen+2); g_c_fit_run -> SetMarkerSize(0.7); g_c_fit_run -> Draw("P,same"); cRight -> cd(); s_EoP_spread = new TPaveStats(); s_EoC_spread = new TPaveStats(); h_EoC_spread_run -> SetFillStyle(3001); h_EoC_spread_run -> SetFillColor(kGreen+2); h_EoC_spread_run->GetYaxis()->SetLabelSize(labSize2); h_EoC_spread_run->GetYaxis()->SetTitleSize(labSize2); h_EoC_spread_run->GetYaxis()->SetNdivisions(505); h_EoC_spread_run->GetYaxis()->SetLabelOffset(-0.02); h_EoC_spread_run->GetXaxis()->SetLabelOffset(1000); h_EoC_spread_run -> Draw("hbar"); gPad -> Update(); s_EoC_spread = (TPaveStats*)(h_EoC_spread_run->GetListOfFunctions()->FindObject("stats")); s_EoC_spread ->SetTextColor(kGreen+2); s_EoC_spread ->SetTextSize(0.06); s_EoC_spread->SetX1NDC(0.49); //new x start position s_EoC_spread->SetX2NDC(0.99); //new x end position s_EoC_spread->SetY1NDC(0.875); //new x start position s_EoC_spread->SetY2NDC(0.990); //new x end position s_EoC_spread -> SetOptStat(1100); s_EoC_spread -> Draw("sames"); h_EoP_spread_run -> SetFillStyle(3001); h_EoP_spread_run -> SetFillColor(kRed+2); h_EoP_spread_run -> Draw("hbarsames"); gPad -> Update(); s_EoP_spread = (TPaveStats*)(h_EoP_spread_run->GetListOfFunctions()->FindObject("stats")); s_EoP_spread->SetX1NDC(0.49); //new x start position s_EoP_spread->SetX2NDC(0.99); //new x end position s_EoP_spread->SetY1NDC(0.750); //new x start position s_EoP_spread->SetY2NDC(0.875); //new x end position s_EoP_spread ->SetOptStat(1100); s_EoP_spread ->SetTextColor(kRed+2); s_EoP_spread ->SetTextSize(0.06); s_EoP_spread -> Draw("sames"); c_chi2 -> Print((folderName+"/"+folderName+"_fitChi2.png").c_str(),"png"); c_scOccupancy -> Print((folderName+"/"+folderName+"_scOccupancy.png").c_str(),"png"); c_seedOccupancy -> Print((folderName+"/"+folderName+"_seedOccupancy.png").c_str(),"png"); cplot -> Print((folderName+"/"+folderName+"_history_vsTime.png").c_str(),"png"); cplot_run -> Print((folderName+"/"+folderName+"_history_vsRun.png").c_str(),"png"); c_chi2 -> Print((folderName+"/"+folderName+"_fitChi2.pdf").c_str(),"pdf"); c_scOccupancy -> Print((folderName+"/"+folderName+"_scOccupancy.pdf").c_str(),"pdf"); c_seedOccupancy -> Print((folderName+"/"+folderName+"_seedOccupancy.pdf").c_str(),"pdf"); cplot -> Print((folderName+"/"+folderName+"_history_vsTime.pdf").c_str(),"pdf"); cplot_run -> Print((folderName+"/"+folderName+"_history_vsRun.pdf").c_str(),"pdf"); cplot -> SaveAs((folderName+"/"+folderName+"_history_vsTime.C").c_str()); cplot_run -> SaveAs((folderName+"/"+folderName+"_history_vsRun.C").c_str()); o -> cd(); h_template -> Write(); h_scOccupancy_eta -> Write(); h_scOccupancy_phi -> Write(); h_seedOccupancy_EB -> Write(); h_seedOccupancy_EEp -> Write(); h_seedOccupancy_EEm -> Write(); g_fit -> Write("g_fit"); g_c_fit -> Write("g_c_fit"); g_fit_run -> Write("g_fit_run"); g_c_fit_run -> Write("g_c_fit_run"); g_las -> Write("g_las"); g_LT -> Write("g_LT"); h_EoP_chi2 -> Write(); h_EoC_chi2 -> Write(); //for(int i = 0; i < nBins; ++i) //{ // h_EoP[i] -> GetXaxis() -> SetTitle("E/p"); // h_EoP[i] -> Write(); // // h_EoC[i] -> GetXaxis() -> SetTitle("E/p"); // h_EoC[i] -> Write(); // // h_Tsp[i] -> Write(); // // h_Cvl[i] -> Write(); //} o -> Close(); }
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 GammaFun() { gSystem->Load("libMathCore"); gStyle->SetPalette(1); gStyle->SetOptStat(0); TF1 *f1a = new TF1("Gamma(x)","ROOT::Math::tgamma(x)",-2,5); TF1 *f2a = new TF1("f2a","ROOT::Math::lgamma(x)",0,10); TF2 *f3a = new TF2("Beta(x)","ROOT::Math::beta(x, y)",0,0.1, 0, 0.1); TF1 *f4a = new TF1("erf(x)","ROOT::Math::erf(x)",0,5); TF1 *f4b = new TF1("erfc(x)","ROOT::Math::erfc(x)",0,5); TCanvas *c1 = new TCanvas("c1", "Gamma and related functions",1000,750); c1->SetFillColor(17); c1->Divide(2,2); c1->cd(1); gPad->SetGrid(); gPad->SetFrameFillColor(19); //setting the title in a label style TPaveLabel *p1 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"ROOT::Math::tgamma(x)", "NDC"); p1->SetFillColor(0); p1->SetTextFont(22); p1->SetTextColor(kBlack); //setting graph // draw axis first (use TH1 to draw the frame) TH1F * h = new TH1F("htmp","",500,-2,5); h->SetMinimum(-20); h->SetMaximum(20); h->GetXaxis()->SetTitleSize(0.06); h->GetXaxis()->SetTitleOffset(.7); h->GetXaxis()->SetTitle("x"); h->Draw(); // draw the functions 3 times in the separate ranges to avoid singularities f1a->SetLineWidth(2); f1a->SetLineColor(kBlue); f1a->SetRange(-2,-1); f1a->DrawCopy("same"); f1a->SetRange(-1,0); f1a->DrawCopy("same"); f1a->SetRange(0,5); f1a->DrawCopy("same"); p1->Draw(); c1->cd(2); gPad->SetGrid(); gPad->SetFrameFillColor(19); TPaveLabel *p2 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"ROOT::Math::lgamma(x)", "NDC"); p2->SetFillColor(0); p2->SetTextFont(22); p2->SetTextColor(kBlack); f2a->SetLineColor(kBlue); f2a->SetLineWidth(2); f2a->GetXaxis()->SetTitle("x"); f2a->GetXaxis()->SetTitleSize(0.06); f2a->GetXaxis()->SetTitleOffset(.7); f2a->SetTitle(""); f2a->Draw(); p2->Draw(); c1->cd(3); gPad->SetGrid(); gPad->SetFrameFillColor(19); TPaveLabel *p3 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"ROOT::Math::beta(x, y)", "NDC"); p3->SetFillColor(0); p3->SetTextFont(22); p3->SetTextColor(kBlack); f3a->SetLineWidth(2); f3a->GetXaxis()->SetTitle("x"); f3a->GetXaxis()->SetTitleOffset(1.2); f3a->GetXaxis()->SetTitleSize(0.06); f3a->GetYaxis()->SetTitle("y"); f3a->GetYaxis()->SetTitleSize(0.06); f3a->GetYaxis()->SetTitleOffset(1.5); f3a->SetTitle(""); f3a->Draw("surf1");//option for a 3-dim plot p3->Draw(); c1->cd(4); gPad->SetGrid(); gPad->SetFrameFillColor(19); TPaveLabel *p4 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"erf(x) and erfc(x)", "NDC"); p4->SetFillColor(0); p4->SetTextFont(22); p4->SetTextColor(kBlack); f4a->SetTitle("erf(x) and erfc(x)"); f4a->SetLineWidth(2); f4b->SetLineWidth(2); f4a->SetLineColor(kBlue); f4b->SetLineColor(kRed); f4a->GetXaxis()->SetTitleSize(.06); f4a->GetXaxis()->SetTitleOffset(.7); f4a->GetXaxis()->SetTitle("x"); f4a->Draw(); f4b->Draw("same");//option for a multiple graph plot f4a->SetTitle(""); p4->Draw(); c1->Update(); c1->cd(); }
void Be9_xs() { TCanvas * c5 = new TCanvas("heyo","heyo",800,600); int k=181; ifstream file1("../Programs/AngCorr/elas_xsection.plot"); //apparently you need to write out the whole thing for ROOT ifstream file2("../Programs/AngCorr/inel_xsection.plot"); ifstream file3("../Programs/AngCorr/inel1_xsection.plot"); if(!file1.is_open())cout << "file1 not open" << endl; if(!file2.is_open())cout << "file2 not open" << endl; float * angle = new float[k]; float * elas = new float[k]; float * inel = new float[k]; float * inel1 = new float[k]; float elasTOT=0; float SCALER = 384205.; SCALER = 7261; //run 61 with Be SCALER = 1.; // don't have FC data for first mult=1 runs SCALER = 0.00009736; // taking into account target thickness and beam current should give results in millibarns //*3 depending on definition of what's written down... also could vary beam current slightly to fit //WTF their right on top of each other, am I drunk or is that physics? 9/21/2016 //also remember you made a scaler that multiplies //find the calculation on your desk and comment that shit in here bro! for(int i=0;i<k;i++) { file1 >> angle[i] >> elas[i]; file2 >> angle[i] >> inel[i]; file3 >> angle[i] >> inel1[k]; elas[i] = elas[i]+inel1[k]; elas[i] = elas[i]; inel[i] = inel[i]; //cout << elas[i] << endl; //cout << inel[i] << endl; } TGraph * E = new TGraph(k,angle,elas); TGraph * I = new TGraph(k,angle,inel); TH1F * eff1D = (TH1F*)sim->Get("theta_reactionCM_R")->Clone("26"); TH1F * really = (TH1F*)sim->Get("theta_reactionCM_P")->Clone("me"); eff1D->Divide(really); eff1D->Draw(); TH1F * Be1D = (TH1F*)data->Get("/corr/Li7/Li7_theta_reactCoM_9Be")->Clone("27"); Be1D->Divide(eff1D); float binW; binW = Be1D->GetXaxis()->GetBinWidth(23)*3.14159/180.; for(int i=1;i<=125;i++) { float solidAng; float thetaC; thetaC = Be1D->GetBinCenter(i)*3.14159/180.; solidAng = 2*3.14159*(cos(thetaC-binW/2.) - cos(thetaC+binW/2.)); float content = Be1D->GetBinContent(i); content = content/solidAng;//sin(Be1D->GetBinCenter(i)*3.14159/180.); //-->I've had the sin(theta) in there all along --> this is only an approximation of the solid angle (works because of binning) Be1D->SetBinContent(i,content*SCALER); if(Be1D->GetBinCenter(i)>24)Be1D->SetBinContent(i,0.); } Be1D->SetMarkerStyle(20); Be1D->Draw("P"); I->SetMarkerStyle(3); I->Draw("same"); Be1D->GetXaxis()->SetRangeUser(0,25); Be1D->GetXaxis()->SetTitle("#theta_{CM}"); //Be1D->GetYaxis()->SetTitle("#frac{d#sigma(mb)}{d#Omega}"); TLatex title; title.DrawLatex(-5,20,"#frac{d#sigma(mb)}{d#Omega}"); Be1D->SetTitle("^{7}Li(7.2-) #sigma_{inel}"); c5->SetLogy(); TFile * sim2 = new TFile("~/elasSim/sim9Be/sim.root"); TCanvas * c6 = new TCanvas("r","r",800,600); TH1F * effEl = (TH1F*)sim2->Get("theta_reactionCM_R")->Clone("65"); TH1F * really2 = (TH1F*)sim2->Get("theta_reactionCM_P")->Clone("56"); effEl->Divide(really2); TH1F * BeElas = (TH1F*)data->Get("/corr/Li7/7Li_elas_9Be")->Clone("45"); BeElas->Divide(effEl); binW = BeElas->GetXaxis()->GetBinWidth(23)*3.14159/180.; for(int i=1;i<=125;i++) { float solidAng; float thetaC; thetaC = BeElas->GetBinCenter(i)*3.14159/180.; solidAng = 2*3.14159*(cos(thetaC-binW/2.) - cos(thetaC+binW/2.)); float content = BeElas->GetBinContent(i); //cout << content << endl; content = content/solidAng;//sin(BeElas->GetBinCenter(i)*3.14159/180.); BeElas->SetBinContent(i,content*SCALER); if(BeElas->GetBinCenter(i)>7.5 && BeElas->GetBinCenter(i)<11) BeElas->SetBinContent(i,0.); if(BeElas->GetBinCenter(i) < 3.5) BeElas->SetBinContent(i,0.); } BeElas->SetMarkerStyle(20); BeElas->Draw("P"); BeElas->GetYaxis()->SetRangeUser(1.,100000); I->SetLineColor(2); E->SetMarkerStyle(3); E->Draw("same"); I->Draw("same"); Be1D->SetMarkerColor(2); Be1D->Draw("sameP"); BeElas->GetXaxis()->SetRangeUser(0,25); BeElas->GetXaxis()->SetTitle("#theta_{CM}"); title.DrawLatex(-5,200,"#frac{d#sigma(mb)}{d#Omega}"); BeElas->SetTitle("^{7}Li(7.2-) #sigma_{el}"); c6->SetLogy(); TCanvas * c7 = new TCanvas("b","b",800,600); TH1F * relative = (TH1F*)data->Get("/corr/Li7/Li7_theta_reactCoM_9Be")->Clone("73"); relative->Divide(eff1D); relative->Divide(BeElas); relative->SetMarkerStyle(20); relative->Draw("P"); c7->SetLogy(); relative->GetXaxis()->SetRangeUser(0,25); }
void InclusiveJets_2010(){ //general root settings gROOT->SetStyle("Plain"); gStyle->SetOptStat(0); //get rid of statistics box TH1::SetDefaultSumw2() ; //Ranges for plots Float_t xmin=17.5 , ymin = 0.00001, xmax = 1684.0, ymax = 10000000000000000.; //for the linecolor and linestyle Int_t icol[8]={8,kViolet,7,4,12,46,6,7}; Int_t isty[8]={1,1,1,1,1,1,1,1}; Int_t imark[5] = {21,22,25,26,3}; //get the root files TFile *f[3]; // POWHEG + Pythia TFile *g[1]; //Herwig TFile *p[1]; //Pythia f[0] = new TFile("out_aida_40times900kevents_errorcut50/Z2MPIHADONbornkt5ktsupp250_errorcut.root"); f[1] = new TFile("out_aida_40times900kevents_errorcut50/Z2MPIHADOFFbornkt5ktsupp250_errorcut.root"); f[2] = new TFile("out_aida_40times900kevents_errorcut50/NOTUNEbornkt5ktsupp250_errorcut.root"); g[0] = new TFile("out_aida_40times900kevents_errorcut50/HERWIGMPIHADONbornkt5ktsupp250_1.root"); // from POWHEG and HERWIG //files from Paolo ---- only Pythia Z2 p[0] = new TFile("FromPaolo/2010PYTHIA.root"); //get the Tgraph and convert into histo TH1F _histotmp[6][3]; TH1F _histotmp_pyth[6][1]; TH1F _histotmp_herw[6][1]; _histotmp_herw[0][0] = Gr2Hi((TGraph*) g[0]->Get("d01_x01_y01;1")); // |y| < 0.5 _histotmp_herw[1][0] = Gr2Hi((TGraph*) g[0]->Get("d02_x01_y01;1")); // 0.5 < |y| < 1.0 _histotmp_herw[2][0] = Gr2Hi((TGraph*) g[0]->Get("d03_x01_y01;1")); // 1.0 < |y| < 1.5 _histotmp_herw[3][0] = Gr2Hi((TGraph*) g[0]->Get("d04_x01_y01;1")); // 1.5 < |y| < 2.0 _histotmp_herw[4][0] = Gr2Hi((TGraph*) g[0]->Get("d05_x01_y01;1")); // 2.0 < |y| < 2.5 _histotmp_herw[5][0] = Gr2Hi((TGraph*) g[0]->Get("d06_x01_y01;1")); // 2.5 < |y| < 3.0 _histotmp_pyth[0][0] = Gr2Hi((TGraph*) p[0]->Get("d01_x01_y01;1")); // |y| < 0.5 _histotmp_pyth[1][0] = Gr2Hi((TGraph*) p[0]->Get("d02_x01_y01;1")); // 0.5 < |y| < 1.0 _histotmp_pyth[2][0] = Gr2Hi((TGraph*) p[0]->Get("d03_x01_y01;1")); // 1.0 < |y| < 1.5 _histotmp_pyth[3][0] = Gr2Hi((TGraph*) p[0]->Get("d04_x01_y01;1")); // 1.5 < |y| < 2.0 _histotmp_pyth[4][0] = Gr2Hi((TGraph*) p[0]->Get("d05_x01_y01;1")); // 2.0 < |y| < 2.5 _histotmp_pyth[5][0] = Gr2Hi((TGraph*) p[0]->Get("d06_x01_y01;1")); // 2.5 < |y| < 3.0 Int_t n = 3; //number of files Int_t nh = 6; // number of histograms = number of y bins for(const int ifile = 0; ifile < n; ifile++){ _histotmp[0][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d01_x01_y01;1")); // |y| <0.5 _histotmp[1][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d02_x01_y01;2")); // 0.5 < |y| < 1.0 _histotmp[2][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d03_x01_y01;2")); // 1.0 < |y| < 1.5 _histotmp[3][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d04_x01_y01;2")); // 1.5 < |y| < 2.0 _histotmp[4][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d05_x01_y01;1")); // 2.0 < |y| < 2.5 _histotmp[5][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d06_x01_y01;1")); // 2.5 < |y| < 3.0 /* _histotmp[0][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d01_x01_y01;1")); // |y| <0.5 _histotmp[1][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d02_x01_y01;1")); // 0.5 < |y| < 1.0 _histotmp[2][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d03_x01_y01;1")); // 1.0 < |y| < 1.5 _histotmp[3][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d04_x01_y01;1")); // 1.5 < |y| < 2.0 _histotmp[4][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d05_x01_y01;1")); // 2.0 < |y| < 2.5 _histotmp[5][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d06_x01_y01;1")); // 2.5 < |y| < 3.0 */ for(const int ihisto = 0; ihisto < nh; ihisto++){ _histotmp_herw[ihisto][0].SetName(""); _histotmp_pyth[ihisto][0].SetName(""); _histotmp[ihisto][ifile].SetName(""); } } //change the histo so that I can plot it and do the ratio TH1F *_histo[6][3]; TH1F *_histo_herw[6][1]; TH1F *_histo_pyth[6][1]; for(const int ifile = 0; ifile < n; ifile++){ for(const int ihisto = 0; ihisto < nh; ihisto++){ TH1F *_histo[ihisto][ifile]= (TH1F*)_histotmp[ihisto][ifile].Clone(""); /* _histo[ihisto][ifile]->Divide((TH1*)_histo[ihisto][1]); //histo 0 / hsito 1 TH1F *_ratio1[ihisto]= (TH1F*)_ratiotmp1[ihisto]->Clone(""); _ratiotmp2[ihisto]->Divide((TH1*)_histo[ihisto][2]); //histo 0 / hsito 2 TH1F *_ratio2[ihisto]= (TH1F*)_ratiotmp2[ihisto]->Clone(""); */ _histo[ihisto][ifile]->SetLineWidth(2); _histo[ihisto][ifile]->SetLineColor(icol[ihisto]); _histo[ihisto][ifile]->SetMarkerStyle(2); _histo[ihisto][ifile]->SetMarkerColor(icol[ihisto]); TH1F *_histo_herw[ihisto][0] = (TH1F*) _histotmp_herw[ihisto][0].Clone(""); _histo_herw[ihisto][0]->SetLineWidth(2); _histo_herw[ihisto][0]->SetLineColor(1); _histo_herw[ihisto][0]->SetMarkerStyle(2); _histo_herw[ihisto][0]->SetMarkerColor(1); TH1F *_histo_pyth[ihisto][0] = (TH1F*) _histotmp_pyth[ihisto][0].Clone(""); _histo_pyth[ihisto][0]->SetLineWidth(2); _histo_pyth[ihisto][0]->SetLineStyle(3); _histo_pyth[ihisto][0]->SetLineColor(icol[ihisto]); _histo_pyth[ihisto][0]->SetMarkerStyle(2); _histo_pyth[ihisto][0]->SetMarkerColor(icol[ihisto]); } //scale the histos that it fits in one histogram _histo[0][ifile]->Scale(10000); _histo[1][ifile]->Scale(1000); _histo[2][ifile]->Scale(100); _histo[3][ifile]->Scale(10); _histo[4][ifile]->Scale(1); } _histo_herw[0][0]->Scale(10000); _histo_herw[1][0]->Scale(1000); _histo_herw[2][0]->Scale(100); _histo_herw[3][0]->Scale(10); _histo_herw[4][0]->Scale(1); _histo_pyth[0][0]->Scale(10000); _histo_pyth[1][0]->Scale(1000); _histo_pyth[2][0]->Scale(100); _histo_pyth[3][0]->Scale(10); _histo_pyth[4][0]->Scale(1); //get the data 2010 //data = new TFile("out_aida/CMS_2011_S9086218.root"); //TH1F _histodata1 = Gr2Hi((TGraph*)data->Get("d01_x01_y01;1")); // |y| <0.5 //TH1F _histodata2 = Gr2Hi((TGraph*)data->Get("d02_x01_y01;1")); // 0.5 < |y| < 1.0 //TH1F _histodata3 = Gr2Hi((TGraph*)data->Get("d03_x01_y01;1")); // 1.0 < |y| < 1.5 //TH1F _histodata4 = Gr2Hi((TGraph*)data->Get("d04_x01_y01;1")); // 1.5 < |y| < 2.0 //TH1F _histodata5 = Gr2Hi((TGraph*)data->Get("d05_x01_y01;1")); // 2.0 < |y| < 2.5 //TH1F _histodata6 = Gr2Hi((TGraph*)data->Get("d06_x01_y01;1")); // 2.5 < |y| < 3.0 Double_t xAxis1[35] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468, 507, 548, 592, 638, 686, 737, 846, 1684}; TH1F *d01_x01_y01_histo = new TH1F("d01_x01_y01_histo","d01_x01_y01_histo",34, xAxis1); d01_x01_y01_histo->SetBinContent(1,1.97e+11); d01_x01_y01_histo->SetBinContent(2,1.02e+11); d01_x01_y01_histo->SetBinContent(3,5.14e+10); d01_x01_y01_histo->SetBinContent(4,2.66e+10); d01_x01_y01_histo->SetBinContent(5,1.38e+10); d01_x01_y01_histo->SetBinContent(6,6.53e+09); d01_x01_y01_histo->SetBinContent(7,3.35e+09); d01_x01_y01_histo->SetBinContent(8,1.8e+09); d01_x01_y01_histo->SetBinContent(9,9.2e+08); d01_x01_y01_histo->SetBinContent(10,4.66e+08); d01_x01_y01_histo->SetBinContent(11,2.37e+08); d01_x01_y01_histo->SetBinContent(12,1.18e+08); d01_x01_y01_histo->SetBinContent(13,5.43e+07); d01_x01_y01_histo->SetBinContent(14,2.39e+07); d01_x01_y01_histo->SetBinContent(15,1.08e+07); d01_x01_y01_histo->SetBinContent(16,5240000); d01_x01_y01_histo->SetBinContent(17,2610000); d01_x01_y01_histo->SetBinContent(18,1360000); d01_x01_y01_histo->SetBinContent(19,716000); d01_x01_y01_histo->SetBinContent(20,381000); d01_x01_y01_histo->SetBinContent(21,207000); d01_x01_y01_histo->SetBinContent(22,117000); d01_x01_y01_histo->SetBinContent(23,66800); d01_x01_y01_histo->SetBinContent(24,37900); d01_x01_y01_histo->SetBinContent(25,22000); d01_x01_y01_histo->SetBinContent(26,12900); d01_x01_y01_histo->SetBinContent(27,7540); d01_x01_y01_histo->SetBinContent(28,4410); d01_x01_y01_histo->SetBinContent(29,2770); d01_x01_y01_histo->SetBinContent(30,1450); d01_x01_y01_histo->SetBinContent(31,846); d01_x01_y01_histo->SetBinContent(32,499); d01_x01_y01_histo->SetBinContent(33,205); d01_x01_y01_histo->SetBinContent(34,20.2); d01_x01_y01_histo->SetBinError(1,2.547782e+10); d01_x01_y01_histo->SetBinError(2,1.24325e+10); d01_x01_y01_histo->SetBinError(3,6.016764e+09); d01_x01_y01_histo->SetBinError(4,3.005329e+09); d01_x01_y01_histo->SetBinError(5,1.530463e+09); d01_x01_y01_histo->SetBinError(6,7.056178e+08); d01_x01_y01_histo->SetBinError(7,3.617535e+08); d01_x01_y01_histo->SetBinError(8,1.96072e+08); d01_x01_y01_histo->SetBinError(9,9.919588e+07); d01_x01_y01_histo->SetBinError(10,5.102008e+07); d01_x01_y01_histo->SetBinError(11,2.639067e+07); d01_x01_y01_histo->SetBinError(12,1.335539e+07); d01_x01_y01_histo->SetBinError(13,6258885); d01_x01_y01_histo->SetBinError(14,2836105); d01_x01_y01_histo->SetBinError(15,1319900); d01_x01_y01_histo->SetBinError(16,663920.6); d01_x01_y01_histo->SetBinError(17,342646.4); d01_x01_y01_histo->SetBinError(18,184642.2); d01_x01_y01_histo->SetBinError(19,100845.5); d01_x01_y01_histo->SetBinError(20,55764.14); d01_x01_y01_histo->SetBinError(21,31565.29); d01_x01_y01_histo->SetBinError(22,18614.95); d01_x01_y01_histo->SetBinError(23,11075.51); d01_x01_y01_histo->SetBinError(24,6579.499); d01_x01_y01_histo->SetBinError(25,4015.708); d01_x01_y01_histo->SetBinError(26,2479.083); d01_x01_y01_histo->SetBinError(27,1527.99); d01_x01_y01_histo->SetBinError(28,943.6936); d01_x01_y01_histo->SetBinError(29,627.92); d01_x01_y01_histo->SetBinError(30,350.3168); d01_x01_y01_histo->SetBinError(31,219.1467); d01_x01_y01_histo->SetBinError(32,139.7467); d01_x01_y01_histo->SetBinError(33,62.02427); d01_x01_y01_histo->SetBinError(34,7.233998); d01_x01_y01_histo->SetEntries(34); d01_x01_y01_histo->SetStats(0); //d01_x01_y01_histo->Scale(10000); d01_x01_y01_histo->SetLineWidth(2); d01_x01_y01_histo->SetMarkerStyle(21); d01_x01_y01_histo->SetMarkerSize(0.7); d01_x01_y01_histo->SetFillColor(kGray); Double_t xAxis2[34] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468, 507, 548, 592, 638, 686, 790, 1684}; TH1F *d02_x01_y01_histo = new TH1F("d02_x01_y01_histo","d02_x01_y01_histo",33, xAxis2); d02_x01_y01_histo->SetBinContent(1,1.89e+10); d02_x01_y01_histo->SetBinContent(2,9.74e+09); d02_x01_y01_histo->SetBinContent(3,4.99e+09); d02_x01_y01_histo->SetBinContent(4,2.49e+09); d02_x01_y01_histo->SetBinContent(5,1.31e+09); d02_x01_y01_histo->SetBinContent(6,6.28e+08); d02_x01_y01_histo->SetBinContent(7,3.23e+08); d02_x01_y01_histo->SetBinContent(8,1.71e+08); d02_x01_y01_histo->SetBinContent(9,8.84e+07); d02_x01_y01_histo->SetBinContent(10,4.42e+07); d02_x01_y01_histo->SetBinContent(11,2.22e+07); d02_x01_y01_histo->SetBinContent(12,1.13e+07); d02_x01_y01_histo->SetBinContent(13,5130000); d02_x01_y01_histo->SetBinContent(14,2230000); d02_x01_y01_histo->SetBinContent(15,1010000); d02_x01_y01_histo->SetBinContent(16,482000); d02_x01_y01_histo->SetBinContent(17,238000); d02_x01_y01_histo->SetBinContent(18,122000); d02_x01_y01_histo->SetBinContent(19,64200); d02_x01_y01_histo->SetBinContent(20,34100); d02_x01_y01_histo->SetBinContent(21,18700); d02_x01_y01_histo->SetBinContent(22,10100); d02_x01_y01_histo->SetBinContent(23,5720); d02_x01_y01_histo->SetBinContent(24,3420); d02_x01_y01_histo->SetBinContent(25,1890); d02_x01_y01_histo->SetBinContent(26,1130); d02_x01_y01_histo->SetBinContent(27,590); d02_x01_y01_histo->SetBinContent(28,376); d02_x01_y01_histo->SetBinContent(29,196); d02_x01_y01_histo->SetBinContent(30,130); d02_x01_y01_histo->SetBinContent(31,62.4); d02_x01_y01_histo->SetBinContent(32,30.1); d02_x01_y01_histo->SetBinContent(33,2.14); d02_x01_y01_histo->SetBinError(1,2.47211e+09); d02_x01_y01_histo->SetBinError(2,1.196891e+09); d02_x01_y01_histo->SetBinError(3,5.890842e+08); d02_x01_y01_histo->SetBinError(4,2.837945e+08); d02_x01_y01_histo->SetBinError(5,1.465766e+08); d02_x01_y01_histo->SetBinError(6,6.848512e+07); d02_x01_y01_histo->SetBinError(7,3.536592e+07); d02_x01_y01_histo->SetBinError(8,1.879562e+07); d02_x01_y01_histo->SetBinError(9,9619569); d02_x01_y01_histo->SetBinError(10,4860292); d02_x01_y01_histo->SetBinError(11,2483524); d02_x01_y01_histo->SetBinError(12,1278948); d02_x01_y01_histo->SetBinError(13,596427.3); d02_x01_y01_histo->SetBinError(14,266851); d02_x01_y01_histo->SetBinError(15,124973); d02_x01_y01_histo->SetBinError(16,61551.8); d02_x01_y01_histo->SetBinError(17,31482.64); d02_x01_y01_histo->SetBinError(18,16749.58); d02_x01_y01_histo->SetBinError(19,9172.852); d02_x01_y01_histo->SetBinError(20,5077.065); d02_x01_y01_histo->SetBinError(21,2898.771); d02_x01_y01_histo->SetBinError(22,1633.017); d02_x01_y01_histo->SetBinError(23,965.8504); d02_x01_y01_histo->SetBinError(24,606.0352); d02_x01_y01_histo->SetBinError(25,351.8168); d02_x01_y01_histo->SetBinError(26,221.2594); d02_x01_y01_histo->SetBinError(27,122.0002); d02_x01_y01_histo->SetBinError(28,82.34314); d02_x01_y01_histo->SetBinError(29,45.69701); d02_x01_y01_histo->SetBinError(30,32.27314); d02_x01_y01_histo->SetBinError(31,16.82748); d02_x01_y01_histo->SetBinError(32,8.687436); d02_x01_y01_histo->SetBinError(33,0.745178); d02_x01_y01_histo->SetEntries(33); d02_x01_y01_histo->SetStats(0); d02_x01_y01_histo->SetLineStyle(0); d02_x01_y01_histo->SetLineWidth(2); d02_x01_y01_histo->SetMarkerStyle(22); d02_x01_y01_histo->SetMarkerSize(0.7); d02_x01_y01_histo->SetFillColor(kGray); Double_t xAxis3[33] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468, 507, 548, 592, 638, 686, 1410}; TH1F *d03_x01_y01_histo = new TH1F("d03_x01_y01_histo","d03_x01_y01_histo",32, xAxis3); d03_x01_y01_histo->SetBinContent(1,1.84e+09); d03_x01_y01_histo->SetBinContent(2,9.24e+08); d03_x01_y01_histo->SetBinContent(3,4.64e+08); d03_x01_y01_histo->SetBinContent(4,2.34e+08); d03_x01_y01_histo->SetBinContent(5,1.19e+08); d03_x01_y01_histo->SetBinContent(6,5.88e+07); d03_x01_y01_histo->SetBinContent(7,2.92e+07); d03_x01_y01_histo->SetBinContent(8,1.57e+07); d03_x01_y01_histo->SetBinContent(9,8090000); d03_x01_y01_histo->SetBinContent(10,4090000); d03_x01_y01_histo->SetBinContent(11,2050000); d03_x01_y01_histo->SetBinContent(12,994000); d03_x01_y01_histo->SetBinContent(13,452000); d03_x01_y01_histo->SetBinContent(14,192000); d03_x01_y01_histo->SetBinContent(15,86200); d03_x01_y01_histo->SetBinContent(16,40500); d03_x01_y01_histo->SetBinContent(17,20100); d03_x01_y01_histo->SetBinContent(18,10000); d03_x01_y01_histo->SetBinContent(19,5210); d03_x01_y01_histo->SetBinContent(20,2720); d03_x01_y01_histo->SetBinContent(21,1470); d03_x01_y01_histo->SetBinContent(22,803); d03_x01_y01_histo->SetBinContent(23,435); d03_x01_y01_histo->SetBinContent(24,252); d03_x01_y01_histo->SetBinContent(25,138); d03_x01_y01_histo->SetBinContent(26,75.7); d03_x01_y01_histo->SetBinContent(27,43.1); d03_x01_y01_histo->SetBinContent(28,23.5); d03_x01_y01_histo->SetBinContent(29,13.1); d03_x01_y01_histo->SetBinContent(30,6.96); d03_x01_y01_histo->SetBinContent(31,3.31); d03_x01_y01_histo->SetBinContent(32,0.263); d03_x01_y01_histo->SetBinError(1,3.267438e+08); d03_x01_y01_histo->SetBinError(2,1.460402e+08); d03_x01_y01_histo->SetBinError(3,6.756898e+07); d03_x01_y01_histo->SetBinError(4,3.169167e+07); d03_x01_y01_histo->SetBinError(5,1.534246e+07); d03_x01_y01_histo->SetBinError(6,7206299); d03_x01_y01_histo->SetBinError(7,3487964); d03_x01_y01_histo->SetBinError(8,1852766); d03_x01_y01_histo->SetBinError(9,937690); d03_x01_y01_histo->SetBinError(10,474695.6); d03_x01_y01_histo->SetBinError(11,239744.8); d03_x01_y01_histo->SetBinError(12,117028.5); d03_x01_y01_histo->SetBinError(13,54375.43); d03_x01_y01_histo->SetBinError(14,23751.81); d03_x01_y01_histo->SetBinError(15,11010.17); d03_x01_y01_histo->SetBinError(16,5355.962); d03_x01_y01_histo->SetBinError(17,2760.221); d03_x01_y01_histo->SetBinError(18,1428.408); d03_x01_y01_histo->SetBinError(19,775.8965); d03_x01_y01_histo->SetBinError(20,422.7916); d03_x01_y01_histo->SetBinError(21,238.9779); d03_x01_y01_histo->SetBinError(22,137.1344); d03_x01_y01_histo->SetBinError(23,78.10703); d03_x01_y01_histo->SetBinError(24,47.62767); d03_x01_y01_histo->SetBinError(25,27.54976); d03_x01_y01_histo->SetBinError(26,16.01829); d03_x01_y01_histo->SetBinError(27,9.722084); d03_x01_y01_histo->SetBinError(28,5.653863); d03_x01_y01_histo->SetBinError(29,3.37332); d03_x01_y01_histo->SetBinError(30,1.948179); d03_x01_y01_histo->SetBinError(31,1.026618); d03_x01_y01_histo->SetBinError(32,0.09205037); d03_x01_y01_histo->SetEntries(32); d03_x01_y01_histo->SetStats(0); d03_x01_y01_histo->SetLineStyle(0); d03_x01_y01_histo->SetLineWidth(2); d03_x01_y01_histo->SetMarkerStyle(25); d03_x01_y01_histo->SetMarkerSize(0.7); d03_x01_y01_histo->SetFillColor(kGray); Double_t xAxis4[30] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468, 507, 548, 1032}; TH1F *d04_x01_y01_histo = new TH1F("d04_x01_y01_histo","d04_x01_y01_histo",29, xAxis4); d04_x01_y01_histo->SetBinContent(1,1.44e+08); d04_x01_y01_histo->SetBinContent(2,7.35e+07); d04_x01_y01_histo->SetBinContent(3,3.8e+07); d04_x01_y01_histo->SetBinContent(4,1.89e+07); d04_x01_y01_histo->SetBinContent(5,9700000); d04_x01_y01_histo->SetBinContent(6,4670000); d04_x01_y01_histo->SetBinContent(7,2280000); d04_x01_y01_histo->SetBinContent(8,1220000); d04_x01_y01_histo->SetBinContent(9,629000); d04_x01_y01_histo->SetBinContent(10,305000); d04_x01_y01_histo->SetBinContent(11,151000); d04_x01_y01_histo->SetBinContent(12,73400); d04_x01_y01_histo->SetBinContent(13,32900); d04_x01_y01_histo->SetBinContent(14,13900); d04_x01_y01_histo->SetBinContent(15,6160); d04_x01_y01_histo->SetBinContent(16,2860); d04_x01_y01_histo->SetBinContent(17,1400); d04_x01_y01_histo->SetBinContent(18,711); d04_x01_y01_histo->SetBinContent(19,356); d04_x01_y01_histo->SetBinContent(20,186); d04_x01_y01_histo->SetBinContent(21,94.5); d04_x01_y01_histo->SetBinContent(22,50.9); d04_x01_y01_histo->SetBinContent(23,25.6); d04_x01_y01_histo->SetBinContent(24,13.3); d04_x01_y01_histo->SetBinContent(25,7); d04_x01_y01_histo->SetBinContent(26,3.45); d04_x01_y01_histo->SetBinContent(27,1.73); d04_x01_y01_histo->SetBinContent(28,0.796); d04_x01_y01_histo->SetBinContent(29,0.066); d04_x01_y01_histo->SetBinError(1,3.637846e+07); d04_x01_y01_histo->SetBinError(2,1.67099e+07); d04_x01_y01_histo->SetBinError(3,7851714); d04_x01_y01_histo->SetBinError(4,3568673); d04_x01_y01_histo->SetBinError(5,1703586); d04_x01_y01_histo->SetBinError(6,750723.4); d04_x01_y01_histo->SetBinError(7,343490.2); d04_x01_y01_histo->SetBinError(8,173448.2); d04_x01_y01_histo->SetBinError(9,84294.21); d04_x01_y01_histo->SetBinError(10,39082.27); d04_x01_y01_histo->SetBinError(11,18979.5); d04_x01_y01_histo->SetBinError(12,9119.636); d04_x01_y01_histo->SetBinError(13,4140.893); d04_x01_y01_histo->SetBinError(14,1810.098); d04_x01_y01_histo->SetBinError(15,830.3785); d04_x01_y01_histo->SetBinError(16,399.9657); d04_x01_y01_histo->SetBinError(17,204.9602); d04_x01_y01_histo->SetBinError(18,109.8075); d04_x01_y01_histo->SetBinError(19,59.1287); d04_x01_y01_histo->SetBinError(20,33.42105); d04_x01_y01_histo->SetBinError(21,18.47046); d04_x01_y01_histo->SetBinError(22,10.88183); d04_x01_y01_histo->SetBinError(23,6.000047); d04_x01_y01_histo->SetBinError(24,3.41489); d04_x01_y01_histo->SetBinError(25,1.994767); d04_x01_y01_histo->SetBinError(26,1.086542); d04_x01_y01_histo->SetBinError(27,0.610451); d04_x01_y01_histo->SetBinError(28,0.3130872); d04_x01_y01_histo->SetBinError(29,0.03211142); d04_x01_y01_histo->SetEntries(29); d04_x01_y01_histo->SetStats(0); d04_x01_y01_histo->SetLineStyle(0); d04_x01_y01_histo->SetLineWidth(2); d04_x01_y01_histo->SetMarkerStyle(26); d04_x01_y01_histo->SetMarkerSize(0.7); d04_x01_y01_histo->SetFillColor(kGray); Double_t xAxis5[27] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 737}; TH1F *d05_x01_y01_histo = new TH1F("d05_x01_y01_histo","d05_x01_y01_histo",26, xAxis5); d05_x01_y01_histo->SetBinContent(1,1.05e+07); d05_x01_y01_histo->SetBinContent(2,5520000); d05_x01_y01_histo->SetBinContent(3,2720000); d05_x01_y01_histo->SetBinContent(4,1440000); d05_x01_y01_histo->SetBinContent(5,738000); d05_x01_y01_histo->SetBinContent(6,348000); d05_x01_y01_histo->SetBinContent(7,168000); d05_x01_y01_histo->SetBinContent(8,89800); d05_x01_y01_histo->SetBinContent(9,43800); d05_x01_y01_histo->SetBinContent(10,21800); d05_x01_y01_histo->SetBinContent(11,10300); d05_x01_y01_histo->SetBinContent(12,5030); d05_x01_y01_histo->SetBinContent(13,2180); d05_x01_y01_histo->SetBinContent(14,896); d05_x01_y01_histo->SetBinContent(15,384); d05_x01_y01_histo->SetBinContent(16,170); d05_x01_y01_histo->SetBinContent(17,78.5); d05_x01_y01_histo->SetBinContent(18,35.8); d05_x01_y01_histo->SetBinContent(19,16.5); d05_x01_y01_histo->SetBinContent(20,7.25); d05_x01_y01_histo->SetBinContent(21,3.27); d05_x01_y01_histo->SetBinContent(22,1.38); d05_x01_y01_histo->SetBinContent(23,0.579); d05_x01_y01_histo->SetBinContent(24,0.22); d05_x01_y01_histo->SetBinContent(25,0.0808); d05_x01_y01_histo->SetBinContent(26,0.00548); d05_x01_y01_histo->SetBinError(1,1978672); d05_x01_y01_histo->SetBinError(2,935188); d05_x01_y01_histo->SetBinError(3,421635.1); d05_x01_y01_histo->SetBinError(4,206618.7); d05_x01_y01_histo->SetBinError(5,100557.7); d05_x01_y01_histo->SetBinError(6,44514.08); d05_x01_y01_histo->SetBinError(7,20942.13); d05_x01_y01_histo->SetBinError(8,11048.87); d05_x01_y01_histo->SetBinError(9,5260.105); d05_x01_y01_histo->SetBinError(10,2634.555); d05_x01_y01_histo->SetBinError(11,1278.591); d05_x01_y01_histo->SetBinError(12,627.8137); d05_x01_y01_histo->SetBinError(13,282.1732); d05_x01_y01_histo->SetBinError(14,121.6466); d05_x01_y01_histo->SetBinError(15,55.24865); d05_x01_y01_histo->SetBinError(16,25.82574); d05_x01_y01_histo->SetBinError(17,12.76174); d05_x01_y01_histo->SetBinError(18,6.253124); d05_x01_y01_histo->SetBinError(19,3.142438); d05_x01_y01_histo->SetBinError(20,1.508923); d05_x01_y01_histo->SetBinError(21,0.7510828); d05_x01_y01_histo->SetBinError(22,0.3514478); d05_x01_y01_histo->SetBinError(23,0.1646418); d05_x01_y01_histo->SetBinError(24,0.071108); d05_x01_y01_histo->SetBinError(25,0.02988224); d05_x01_y01_histo->SetBinError(26,0.002567773); d05_x01_y01_histo->SetEntries(26); d05_x01_y01_histo->SetStats(0); d05_x01_y01_histo->SetLineStyle(0); d05_x01_y01_histo->SetLineWidth(2); d05_x01_y01_histo->SetMarkerStyle(3); d05_x01_y01_histo->SetMarkerSize(0.7); d05_x01_y01_histo->SetFillColor(kGray); // MC / Data TH1F *_ratio[6][3]; TH1F *_ratio_pyth[6][1]; for(const int ifile = 0; ifile < n; ifile++){ for(const int ihisto = 0; ihisto < nh; ihisto++){ TH1F *_ratio[ihisto][ifile]= (TH1F*)_histo[ihisto][ifile]->Clone(""); TH1F *_ratio_pyth[ihisto][0]= (TH1F*)_histo_pyth[ihisto][0]->Clone(""); _ratio[ihisto][ifile]->SetLineWidth(1); _ratio[ihisto][ifile]->SetLineColor(icol[ihisto]); _ratio[ihisto][ifile]->SetMarkerStyle(imark[ihisto]); _ratio[ihisto][ifile]->SetMarkerSize(0.5); _ratio[ihisto][ifile]->SetMarkerColor(icol[ihisto]); _ratio_pyth[ihisto][0]->SetLineWidth(1); _ratio_pyth[ihisto][0]->SetLineColor(icol[ihisto]); _ratio_pyth[ihisto][0]->SetLineStyle(3); _ratio_pyth[ihisto][0]->SetMarkerStyle(imark[ihisto]); _ratio_pyth[ihisto][0]->SetMarkerSize(0.5); _ratio_pyth[ihisto][0]->SetMarkerColor(icol[ihisto]); } _ratio[0][ifile]->Divide((TH1*)d01_x01_y01_histo); _ratio[1][ifile]->Divide((TH1*)d02_x01_y01_histo); _ratio[2][ifile]->Divide((TH1*)d03_x01_y01_histo); _ratio[3][ifile]->Divide((TH1*)d04_x01_y01_histo); _ratio[4][ifile]->Divide((TH1*)d05_x01_y01_histo); // TH1F *_ratio[ihisto]= (TH1F*)_ratiotmp1[ihisto]->Clone(""); // _ratiotmp2[ihisto]->Divide((TH1*)_histo[ihisto][2]); //histo 0 / hsito 2 // TH1F *_ratio2[ihisto]= (TH1F*)_ratiotmp2[ihisto]->Clone(""); } _ratio_pyth[0][0]->Divide((TH1*)d01_x01_y01_histo); _ratio_pyth[1][0]->Divide((TH1*)d02_x01_y01_histo); _ratio_pyth[2][0]->Divide((TH1*)d03_x01_y01_histo); _ratio_pyth[3][0]->Divide((TH1*)d04_x01_y01_histo); _ratio_pyth[4][0]->Divide((TH1*)d05_x01_y01_histo); // Data / MC TH1F *_ratio_datamc[6][3]; TH1F *_ratio_pyth_datamc[6][1]; TH1F *_ratio_pyth_datamc[0][0]= (TH1F*)d01_x01_y01_histo->Clone(""); TH1F *_ratio_pyth_datamc[1][0]= (TH1F*)d02_x01_y01_histo->Clone(""); TH1F *_ratio_pyth_datamc[2][0]= (TH1F*)d03_x01_y01_histo->Clone(""); TH1F *_ratio_pyth_datamc[3][0]= (TH1F*)d04_x01_y01_histo->Clone(""); TH1F *_ratio_pyth_datamc[4][0]= (TH1F*)d05_x01_y01_histo->Clone(""); for(const int ifile = 0; ifile < n; ifile++){ TH1F *_ratio_datamc[0][ifile]= (TH1F*)d01_x01_y01_histo->Clone(""); TH1F *_ratio_datamc[1][ifile]= (TH1F*)d02_x01_y01_histo->Clone(""); TH1F *_ratio_datamc[2][ifile]= (TH1F*)d03_x01_y01_histo->Clone(""); TH1F *_ratio_datamc[3][ifile]= (TH1F*)d04_x01_y01_histo->Clone(""); TH1F *_ratio_datamc[4][ifile]= (TH1F*)d05_x01_y01_histo->Clone(""); for(const int ihisto = 0; ihisto < 5; ihisto++){ _ratio_datamc[ihisto][ifile]->Divide((TH1F*)_histo[ihisto][ifile]); _ratio_datamc[ihisto][ifile]->SetLineWidth(1); _ratio_datamc[ihisto][ifile]->SetLineColor(icol[ihisto]); _ratio_datamc[ihisto][ifile]->SetMarkerStyle(imark[ihisto]); _ratio_datamc[ihisto][ifile]->SetMarkerSize(0.5); _ratio_datamc[ihisto][ifile]->SetMarkerColor(icol[ihisto]); _ratio_datamc[ihisto][ifile]->SetFillColor(0); _ratio_pyth_datamc[ihisto][0]->Divide((TH1F*)_histo_pyth[ihisto][0]); _ratio_pyth_datamc[ihisto][0]->SetLineWidth(1); _ratio_pyth_datamc[ihisto][0]->SetLineColor(icol[ihisto]); _ratio_pyth_datamc[ihisto][0]->SetLineStyle(3); _ratio_pyth_datamc[ihisto][0]->SetMarkerStyle(imark[ihisto]); _ratio_pyth_datamc[ihisto][0]->SetMarkerSize(0.5); _ratio_pyth_datamc[ihisto][0]->SetMarkerColor(icol[ihisto]); _ratio_pyth_datamc[ihisto][0]->SetFillColor(0); } } //create a canvas to draw TGraph and TH1F TCanvas *c1 = new TCanvas("c1", "c1",369,0,680,550); //pads (inclusive jet cross section, MC / data ) Pad_inclJet = new TPad("Pad_inclJet","xs",0.01,0.01,1.0,1.0); Pad_inclJet->Draw(); // first pad style Pad_inclJet->cd(); gStyle->SetOptStat(0); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLogy(); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.03); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); //empty histo for border and style TH1F *shape = new TH1F("","",1, xmin, xmax); shape->SetMinimum(ymin); shape->SetMaximum(ymax); shape->GetXaxis()->SetTitle("Jet p_{T} (GeV/c)"); shape->GetXaxis()->SetLabelSize(0.03); shape->GetXaxis()->SetTitleSize(0.03); shape->GetXaxis()->SetNdivisions(508); shape->GetXaxis()->SetTitleOffset(1.3); shape->GetXaxis()->SetMoreLogLabels(); shape->GetYaxis()->SetTitle("#frac{d^{2}#sigma}{dp_{T}d|y|} (pb/GeV)"); shape->GetYaxis()->SetLabelSize(0.03); shape->GetYaxis()->SetTitleSize(0.03); shape->GetYaxis()->SetTitleOffset(1.6); shape->Draw("e"); gPad->SetLogy(); gPad->SetLogx(); //data d01_x01_y01_histo->Draw("E2same"); d02_x01_y01_histo->Draw("E2same"); d03_x01_y01_histo->Draw("E2same"); d04_x01_y01_histo->Draw("E2same"); d05_x01_y01_histo->Draw("E2same"); _histo[0][0]->Draw("E1same"); _histo[1][0]->Draw("E1same"); _histo[2][0]->Draw("E1same"); _histo[3][0]->Draw("E1same"); _histo[4][0]->Draw("E1same"); // _histo_herw[0][0]->Draw("E1same"); // _histo_herw[1][0]->Draw("E1same"); // _histo_herw[2][0]->Draw("E1same"); // _histo_herw[3][0]->Draw("E1same"); // _histo_herw[4][0]->Draw("E1same"); _histo_pyth[0][0]->Draw("E1same"); _histo_pyth[1][0]->Draw("E1same"); _histo_pyth[2][0]->Draw("E1same"); _histo_pyth[3][0]->Draw("E1same"); _histo_pyth[4][0]->Draw("E1same"); TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.17,0.79,0.37,0.95,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.03); text = pt->AddText("CMS 2010"); text = pt->AddText("#sqrt{s} = 7 TeV"); text = pt->AddText("anti-k_{T} R = 0.5"); pt->Draw(); TLegend *leg = new TLegend(0.68,0.70,0.83,0.928); leg->SetBorderSize(1); leg->SetTextSize(0.025); leg->SetLineColor(0); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(1001); leg->AddEntry((TH1F*)_histo[0][0],"POWHEG & Pythia6 Z2","pfl"); leg->AddEntry((TH1F*)_histo_pyth[0][0]," Pythia6 Z2","pfl"); leg->AddEntry((TH1F*) d01_x01_y01_histo, "|y| <0.5 (x 10^{4})","pfl"); leg->AddEntry((TH1F*) d02_x01_y01_histo, "0.5 < |y| < 1.0 (x 10^{3})","pfl"); leg->AddEntry((TH1F*) d03_x01_y01_histo, "1.0 < |y| < 1.5 (x 10^{2})","pfl"); leg->AddEntry((TH1F*) d04_x01_y01_histo, "1.5 < |y| < 2.0 (x 10^{1})","pfl"); leg->AddEntry((TH1F*) d05_x01_y01_histo, "2.0 < |y| < 2.5 (x 10^{0})","pfl"); leg->Draw(); //write in png file mysubpad1 =(TPad*)c1->GetPad(0); mysubpad1->Print("pics/InclusiveJets_xs_10.png"); mysubpad1->Print("~/DESY/ANALYSIS_NOTES/JetCrossSectionsWithPOWHEG/notes/AN-12-236/trunk/plots/InclusiveJets_xs_10.pdf"); // MC / Data //create a canvas to draw TGraph and TH1F TCanvas *c2 = new TCanvas("c2", "c2",369,0,680,550); Pad_MCdata1 = new TPad("Pad_MCdata1","ratio",0.01,0.78,1.0,0.95); Pad_MCdata1->Draw(); Pad_MCdata2 = new TPad("Pad_MCdata2","ratio",0.01,0.60,1.0,0.76); Pad_MCdata2->Draw(); Pad_MCdata3 = new TPad("Pad_MCdata3","ratio",0.01,0.42,1.0,0.58); Pad_MCdata3->Draw(); Pad_MCdata4 = new TPad("Pad_MCdata4","ratio",0.01,0.24,1.0,0.40); Pad_MCdata4->Draw(); Pad_MCdata5 = new TPad("Pad_MCdata5","ratio",0.01,0.06,1.0,0.22); Pad_MCdata5->Draw(); Pad_MCdata1->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); //AK Empty histo for style and borders TH1F *shape_MCdata = new TH1F("","",1, xmin, xmax); shape_MCdata->SetMinimum(0.5); shape_MCdata->SetMaximum(2.0); shape_MCdata->GetXaxis()->SetTitle("Jet p_{T} (GeV/c)"); shape_MCdata->GetXaxis()->SetLabelSize(0.1); shape_MCdata->GetXaxis()->SetTitleSize(0.1); shape_MCdata->GetXaxis()->SetTitleOffset(0.6); shape_MCdata->GetXaxis()->SetMoreLogLabels(); shape_MCdata->GetYaxis()->SetTitle("MC/Data"); shape_MCdata->GetYaxis()->SetLabelSize(0.1); shape_MCdata->GetYaxis()->SetTitleSize(0.15); shape_MCdata->GetYaxis()->SetTitleOffset(0.2); shape_MCdata->GetYaxis()->SetNdivisions(108, kTRUE); shape_MCdata->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.89,0.7,0.94,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("|y| <0.5"); pt->Draw(); _ratio[0][0]->Draw("EhistSame"); _ratio_pyth[0][0]->Draw("EhistSame"); Pad_MCdata2->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); shape_MCdata->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("0.5 < |y| < 1.0"); pt->Draw(); _ratio[1][0]->Draw("EhistSame"); _ratio_pyth[1][0]->Draw("EhistSame"); Pad_MCdata3->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); shape_MCdata->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("1.0 < |y| < 1.5"); pt->Draw(); _ratio[2][0]->Draw("EhistSame"); _ratio_pyth[2][0]->Draw("EhistSame"); Pad_MCdata4->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); shape_MCdata->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("1.5 < |y| < 2.0"); pt->Draw(); _ratio[3][0]->Draw("EhistSame"); _ratio_pyth[3][0]->Draw("EhistSame"); Pad_MCdata5->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); shape_MCdata->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("2.0 < |y| < 2.5"); pt->Draw(); _ratio[4][0]->Draw("EhistSame"); _ratio_pyth[4][0]->Draw("EhistSame"); //write in png file mysubpad2 =(TPad*)c2->GetPad(0); mysubpad2->Print("pics/InclusiveJets_mcdataRatio_10.png"); mysubpad2->Print("~/DESY/ANALYSIS_NOTES/JetCrossSectionsWithPOWHEG/notes/AN-12-236/trunk/plots/InclusiveJets_mcdataRatio_10.pdf"); // Data / MC //create a canvas to draw TGraph and TH1F TCanvas *c3 = new TCanvas("c3", "c3",369,0,680,550); Pad_DataMC1 = new TPad("Pad_DataMC1","ratio",0.01,0.78,1.0,0.95); Pad_DataMC1->Draw(); Pad_DataMC2 = new TPad("Pad_DataMC2","ratio",0.01,0.60,1.0,0.76); Pad_DataMC2->Draw(); Pad_DataMC3 = new TPad("Pad_DataMC3","ratio",0.01,0.42,1.0,0.58); Pad_DataMC3->Draw(); Pad_DataMC4 = new TPad("Pad_DataMC4","ratio",0.01,0.24,1.0,0.40); Pad_DataMC4->Draw(); Pad_DataMC5 = new TPad("Pad_DataMC5","ratio",0.01,0.06,1.0,0.22); Pad_DataMC5->Draw(); Pad_DataMC1->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); //AK Empty histo for style and borders TH1F *shape_DataMC = new TH1F("","",1, xmin, xmax); shape_DataMC->SetMinimum(0.5); shape_DataMC->SetMaximum(2.0); shape_DataMC->GetXaxis()->SetTitle("Jet p_{T} (GeV/c)"); shape_DataMC->GetXaxis()->SetLabelSize(0.1); shape_DataMC->GetXaxis()->SetTitleSize(0.1); shape_DataMC->GetXaxis()->SetTitleOffset(0.6); shape_DataMC->GetXaxis()->SetMoreLogLabels(); shape_DataMC->GetYaxis()->SetTitle("Data/MC"); shape_DataMC->GetYaxis()->SetLabelSize(0.1); shape_DataMC->GetYaxis()->SetTitleSize(0.15); shape_DataMC->GetYaxis()->SetTitleOffset(0.2); shape_DataMC->GetYaxis()->SetNdivisions(108, kTRUE); shape_DataMC->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.89,0.7,0.94,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("|y| <0.5"); pt->Draw(); _ratio_datamc[0][0]->Draw("EhistSame"); _ratio_pyth_datamc[0][0]->Draw("EhistSame"); Pad_DataMC2->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); shape_DataMC->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("0.5 < |y| < 1.0"); pt->Draw(); _ratio_datamc[1][0]->Draw("EhistSame"); _ratio_pyth_datamc[1][0]->Draw("EhistSame"); Pad_DataMC3->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); shape_DataMC->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("1.0 < |y| < 1.5"); pt->Draw(); _ratio_datamc[2][0]->Draw("EhistSame"); _ratio_pyth_datamc[2][0]->Draw("EhistSame"); Pad_DataMC4->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); shape_DataMC->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("1.5 < |y| < 2.0"); pt->Draw(); _ratio_datamc[3][0]->Draw("EhistSame"); _ratio_pyth_datamc[3][0]->Draw("EhistSame"); Pad_DataMC5->cd(); gPad->SetFillColor(0); gPad->SetBorderMode(0); gPad->SetBorderSize(2); gPad->SetLeftMargin(0.14); gPad->SetRightMargin(0.03); gPad->SetTopMargin(0.0); gPad->SetFrameBorderMode(0); gPad->SetFrameBorderMode(0); gPad->SetLogx(); shape_DataMC->Draw("e"); // horizontal line at y = 1 TLine *line = new TLine(xmin,1,xmax,1); line->SetLineStyle(2); line->Draw(); TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetTextAlign(12); pt->SetTextSize(0.15); text = pt->AddText("2.0 < |y| < 2.5"); pt->Draw(); _ratio_datamc[4][0]->Draw("EhistSame"); _ratio_pyth_datamc[4][0]->Draw("EhistSame"); //write in png file mysubpad3 =(TPad*)c3->GetPad(0); mysubpad3->Print("pics/InclusiveJets_DataMCRatio_10.png"); mysubpad3->Print("~/DESY/ANALYSIS_NOTES/JetCrossSectionsWithPOWHEG/notes/AN-12-236/trunk/plots/InclusiveJets_DataMCRatio_10.pdf"); c1->Print("InclusiveJets_2010.pdf("); c2->Print("InclusiveJets_2010.pdf"); c3->Print("InclusiveJets_2010.pdf)"); }
void postfit(const char* inputfile, const char* analysis = "SM", const char* dataset = "2011+2012", const char* extra="", const char* extra2="", float min=0.1, float max=-1., bool log=true) { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // switch for MSSM/SM bool MSSM = std::string(analysis) == std::string("MSSM"); // determine label if (std::string(dataset) == std::string("2011" )){ dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV"; } if (std::string(dataset) == std::string("2012" )){ if (std::string(extra) == std::string("#mu#mu") ) dataset = "MS Preliminary, H#rightarrow#tau#tau, 18.7 fb^{-1} at 8 TeV"; else dataset = "MS Preliminary, H#rightarrow#tau#tau, 19.4 fb^{-1} at 8 TeV"; } if (std::string(dataset) == std::string("2011+2012")){ if (std::string(extra) == std::string("#mu#mu") ) dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV, 18.6 fb^{-1} at 8 TeV"; else dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV, 19.4 fb^{-1} at 8 TeV"; if (MSSM) dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV, 12.1 fb^{-1} at 8 TeV"; } // determine category tag const char* category_extra = ""; if(std::string(extra2) == std::string("0jet_low" )){ category_extra = "0 jet, low p_{T}"; } if(std::string(extra2) == std::string("0jet_high" )){ category_extra = "0 jet, high p_{T}"; } if(std::string(extra2) == std::string("0jet" )){ category_extra = "0 jet"; } if(std::string(extra2) == std::string("boost_low" )){ category_extra = "1 jet, low p_{T}"; } if(std::string(extra2) == std::string("boost_high")){ category_extra = "1 jet, high p_{T}"; } if(std::string(extra2) == std::string("boost" )){ category_extra = "1 jet"; } if(std::string(extra2) == std::string("vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(extra2) == std::string("nobtag" )){ category_extra = "No B-Tag"; } if(std::string(extra2) == std::string("btag" )){ category_extra = "B-Tag"; } TFile* input = new TFile(inputfile); TH1F* Fakes = refill((TH1F*)input->Get("Fakes" ), "Fakes/QCD"); TH1F* EWK = refill((TH1F*)input->Get("EWK" ), "EWK" ); TH1F* ttbar = refill((TH1F*)input->Get("ttbar" ), "ttbar" ); TH1F* Ztt = refill((TH1F*)input->Get("Ztt" ), "Ztt" ); TH1F* Zmm = refill((TH1F*)input->Get("Zmm" ), "Zmm" ); TH1F* ggH = refill((TH1F*)input->Get("ggH" ), "ggH" ); TH1F* data = (TH1F*)input->Get("data_obs"); // determine channel for etau Z->ee (EWK) will be shown separated from the rest (EWK1) TH1F* EWK1 = 0; if(std::string(extra) == std::string("e#tau_{h}")){ EWK1 = refill((TH1F*)input->Get("EWK1"), "EWK1"); } TH1F* errorBand = (TH1F*)input->Get("errorBand"); /* mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); if(log) canv->SetLogy(1); // reduce the axis range if necessary for linea plots and SM if(MSSM && !log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(490)); }; if(!MSSM){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } data->SetNdivisions(505); data->SetMinimum(min); if(Zmm){ data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(EWK, log))); } else{ data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log))); } data->Draw("e"); if(log){ if(Zmm){ EWK ->Draw("same"); ttbar->Draw("same"); Fakes->Draw("same"); Zmm ->Draw("same"); Ztt ->Draw("same"); } else{ Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); if(EWK1){ EWK1->Draw("same"); } if(Fakes){ Fakes->Draw("same"); } } if(ggH) ggH ->Draw("histsame"); } else{ if(ggH) ggH ->Draw("histsame"); if(Zmm){ EWK->Draw("same"); Fakes->Draw("same"); ttbar->Draw("same"); Zmm->Draw("same"); Ztt->Draw("same"); } else{ Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); if(EWK1){ EWK1->Draw("same"); } if(Fakes){ Fakes->Draw("same"); } } } if(errorBand){ errorBand->Draw("e2same"); } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, extra, 0.17, 0.835); CMSPrelim(dataset, "", 0.18, 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(extra); 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(); if(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(); } float lower_bound = EWK1 ? 0.60 : 0.65; TLegend* leg = new TLegend(MSSM ? 0.45 : 0.50, lower_bound, 0.93, 0.90); SetLegendStyle(leg); if(MSSM){ leg->AddEntry(ggH , "#phi#rightarrow#tau#tau", "L" ); } else{ if(ggH){ 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" ); } } } leg->AddEntry(data , "observed" , "LP"); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); if(Zmm){ leg->AddEntry(Zmm , "Z#rightarrow#mu#mu" , "F" ); } if(EWK1){ leg->AddEntry(EWK , "Z#rightarrow ee" , "F" ); leg->AddEntry(EWK1 , "electroweak" , "F" ); } else{ leg->AddEntry(EWK , "electroweak" , "F" ); } leg->AddEntry(ttbar, "t#bar{t}" , "F" ); if(Fakes){ leg->AddEntry(Fakes, "QCD" , "F" ); } if(errorBand){ leg->AddEntry(errorBand, "bkg. uncertainty" , "F" ); } leg->Draw(); /* TPaveText* ext0 = new TPaveText(0.50, lower_bound-0.08, 0.70, lower_bound-0.03, "NDC"); ext0->SetBorderSize( 0 ); ext0->SetFillStyle( 0 ); ext0->SetTextAlign( 12 ); ext0->SetTextSize ( 0.035 ); ext0->SetTextColor( 1 ); ext0->SetTextFont ( 42 ); ext0->AddText("CMS Preliminary"); ext0->Draw(); TPaveText* ext1 = new TPaveText(0.50, lower_bound-0.13, 0.70, lower_bound-0.08, "NDC"); ext1->SetBorderSize( 0 ); ext1->SetFillStyle( 0 ); ext1->SetTextAlign( 12 ); ext1->SetTextSize ( 0.035 ); ext1->SetTextColor( 1 ); ext1->SetTextFont ( 42 ); ext1->AddText("#sqrt{s} = 7 TeV, L = 4.9 fb^{-1}"); ext1->Draw(); TPaveText* ext2 = new TPaveText(0.50, lower_bound-0.18, 0.70, lower_bound-0.13, "NDC"); ext2->SetBorderSize( 0 ); ext2->SetFillStyle( 0 ); ext2->SetTextAlign( 12 ); ext2->SetTextSize ( 0.035 ); ext2->SetTextColor( 1 ); ext2->SetTextFont ( 42 ); ext2->AddText("#sqrt{s} = 8 TeV, L = 19.4 fb^{-1}"); ext2->Draw(); TPaveText* ext3 = new TPaveText(0.50, lower_bound-0.23, 0.70, lower_bound-0.18, "NDC"); ext3->SetBorderSize( 0 ); ext3->SetFillStyle( 0 ); ext3->SetTextAlign( 12 ); ext3->SetTextSize ( 0.035 ); ext3->SetTextColor( 1 ); ext3->SetTextFont ( 42 ); ext3->AddText("H#rightarrow#tau#tau"); ext3->Draw(); */ /* prepare output */ std::string newName = std::string(inputfile).substr(0, std::string(inputfile).find(".root")); //canv->Print(TString::Format("%s%s.png", newName.c_str(), log ? "_LOG" : "")); //canv->Print(TString::Format("%s%s.pdf", newName.c_str(), log ? "_LOG" : "")); //canv->Print(TString::Format("%s%s.eps", newName.c_str(), log ? "_LOG" : "")); canv->Print(TString::Format("%s.png", newName.c_str())); canv->Print(TString::Format("%s.pdf", newName.c_str())); canv->Print(TString::Format("%s.eps", newName.c_str())); }
void SPEFit(char * fname, int run, int LED_amp, double cutmax = 250.0) { //set plotting styles gStyle->SetCanvasColor(0); gStyle->SetPadColor(0); gStyle->SetCanvasBorderMode(0); gStyle->SetFrameBorderMode(0); gStyle->SetStatColor(0); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); //set file names stringstream out_fname; stringstream out_fname1; out_fname<<"SPEconstants_Run_"<<run<<".txt"; out_fname1<<"SPEspec_Run_"<<run<<".txt"; ofstream constants_file(out_fname.str().c_str(),ios_base::trunc); ofstream constants_file1(out_fname1.str().c_str(),ios_base::trunc); constants_file<<"Run "<<run<<endl; constants_file<<"type SPE"<<endl; constants_file<<"LED_amplitude "<<LED_amp<<endl<<endl; //constants_file<<endl<<"LED_amplitude HV Spigot Channel Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl; constants_file<<endl<<"LED_amplitude HV Spigot Channel Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag Polya_shape Polya_shape_err Polya_mode"<<endl; out_fname.str(""); out_fname<<"SPEdistributions_Run_"<<run<<".txt"; out_fname.str(""); out_fname<<"SPEextra_Run_"<<run<<".txt"; //ofstream extra_file(out_fname.str().c_str(),ios_base::trunc); //extra_file<<endl<<"LED_amplitude HV Spigot Channel PedSubtracted_mean Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl; double scale = 1.0; scale = 2.6; //Need to scale up HF charge double fC2electrons = 6240.; //convert fC to #electrons char spename[128], pedname[128], spehistname[128]; bool drawflag; TFile *tf = new TFile(fname); TCanvas *c1 = new TCanvas("c1","c1",1200,700); c1->Divide(6,4); c1->SetBorderMode(0); c1->SetBorderSize(0); TCanvas *c2 = new TCanvas("c2","c2",1200,700); c2->Divide(6,4); c2->SetBorderMode(0); c2->SetBorderSize(0); TCanvas *c3 = new TCanvas("c3","c3",1200,700); c3->Divide(6,4); c3->SetBorderMode(0); c3->SetBorderSize(0); const int NnewBins = 106; double binsX[NnewBins] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,180,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500}; TH1F* hspe = new TH1F("hspe","hspe",NnewBins-1,binsX); int Npoints; TH2D *tmp; for(Npoints=0;Npoints<10;Npoints++){ sprintf(spename,"spetest/spigot_%d/bb_%d/LED_HVset_%d_sp_%d_BB_%d",0,1,Npoints,0,1); tmp=(TH2D *)tf->Get(spename); if(tmp==0) break; } TH2D *LED[3][3][20]; TH2D *PED[3][3]; for(int iSpig = 0; iSpig < 3; iSpig++)for(int bb = 1; bb < 4; bb++){ for(int ii=0; ii<Npoints; ii++){ sprintf(spename,"spetest/spigot_%d/bb_%d/LED_HVset_%d_sp_%d_BB_%d",iSpig,bb,ii,iSpig,bb); LED[iSpig][bb-1][ii]=(TH2D *)tf->Get(spename); } sprintf(spename,"spetest/spigot_%d/bb_%d/PED_sp_%d_BB_%d",iSpig,bb,iSpig,bb); PED[iSpig][bb-1]=(TH2D *)tf->Get(spename); } for(int ii=0; ii<Npoints; ii++) { drawflag=false; int HV=0; for (int iSpig = 0; iSpig < 3; iSpig++) { for(int i = 0; i < 24; i++) { int bb=BB_MAP[i]; int pmt=PMT_MAP[i]; sprintf(spehistname,"led %d %d %d",ii,iSpig,i); TH1D *hspe_temp = (TH1D *)LED[iSpig][bb-1][ii]->ProjectionX(spehistname,pmt,pmt,"")->Clone(); sprintf(spehistname,"ped %d %d %d",ii,iSpig,i); TH1D *hped = (TH1D *)PED[iSpig][bb-1]->ProjectionX(spehistname,pmt,pmt,"")->Clone(); sscanf(&hspe_temp->GetTitle()[7],"%d",&HV); hspe->Reset(); sprintf (spehistname, "SumLED%d_sp_%d_ch_%d", HV, iSpig, i); hspe->SetTitle(spehistname); //combine bins of original SPE histogram for(int ib=1; ib<=hspe_temp->GetNbinsX(); ib++) { double bin_center = hspe_temp->GetBinCenter(ib); if(bin_center>hspe->GetXaxis()->GetXmax()) continue; int newbin = hspe->FindBin(bin_center); double new_content = hspe->GetBinContent(newbin) + hspe_temp->GetBinContent(ib); double new_error = sqrt(pow(hspe->GetBinError(newbin),2)+pow(hspe_temp->GetBinError(ib),2)); hspe->SetBinContent(newbin,new_content); hspe->SetBinError(newbin,new_error); } TH1F* hspe_unscaled = (TH1F*)hspe->Clone("hspe_unscaled"); //renormalize bins of new SPE histogram for(int ib=1; ib<=hspe->GetNbinsX(); ib++) { double new_content = hspe->GetBinContent(ib)/hspe->GetXaxis()->GetBinWidth(ib)*hspe_temp->GetXaxis()->GetBinWidth(1); double new_error = hspe->GetBinError(ib)/hspe->GetXaxis()->GetBinWidth(ib)*hspe_temp->GetXaxis()->GetBinWidth(1); hspe->SetBinContent(ib,new_content); hspe->SetBinError(ib,new_error); } if(hspe_temp->Integral()==0) continue; else drawflag=true; Nev = hspe_temp->Integral()*hspe_temp->GetXaxis()->GetBinWidth(1); TF1 *fped = new TF1("fped","gaus",0, 80); hped->Fit(fped,"NQR"); double pploc = fped->GetParameter(1), ppwidth = fped->GetParameter(2); //cout<<"Ped only: ped mean "<<fped->GetParameter(1)<<", ped width "<<fped->GetParameter(2)<<" normalization "<<fped->GetParameter(0)<<endl; hspe->Fit(fped, "NQ", "", pploc - 3*ppwidth, pploc + ppwidth); //cout<<"SPE distribution: ped mean "<<fped->GetParameter(1)<<", ped width "<<fped->GetParameter(2)<<" normalization "<<fped->GetParameter(0)<<endl; //estimate SPE peak location int max_SPE_bin, maxbin, Nbins; double max_SPE_height=0, minheight, max_SPE_location; bool minflag = false; maxbin=hspe->FindBin(fped->GetParameter(1)); //location of pedestal peak minheight=hspe->GetBinContent(maxbin); //initialize minheight /* int maxped_bin = hspe->GetMaximumBin(); int maxped_binheight = hspe->GetBinContent(maxped_bin); minheight = maxped_binheight; */ Nbins = hspe->GetNbinsX(); for(int j=/*maxped_bin*/maxbin+1; j<Nbins-1; j++) { //start from pedestal peak and loop through bins if(hspe->GetBinContent(j) > minheight && !minflag) minflag=true; //only look for SPE peak when minflag=true if(hspe->GetBinContent(j) < minheight ) minheight = hspe->GetBinContent(j); if(minflag && hspe->GetBinContent(j) > max_SPE_height){ max_SPE_bin = j; max_SPE_location = hspe->GetBinCenter(max_SPE_bin); max_SPE_height = hspe->GetBinContent(j); } } //start from pedestal peak and loop through bins //find minimum bin between pedestal and SPE peaks hspe->GetXaxis()->SetRange(maxbin,max_SPE_bin); int minbin = hspe->GetMinimumBin(); double minbin_location = hspe->GetBinCenter(minbin); hspe->GetXaxis()->SetRange(1,Nbins); TF1 *fit = new TF1("fit", FitFun, 0, 500, 5); double mu = - log(fped->Integral(0,100)/Nev); if(mu<0) mu=0.01; double gain_est = max_SPE_location-1.0*fped->GetParameter(1); if(max_SPE_bin > (minbin+1)) fit->SetParameters(mu, 20, 1, gain_est, 3.0); else fit->SetParameters(mu, 20, 1, 2.1*fped->GetParameter(2), 3.0); //case of no clear minimum; start looking for SPE peak at 2sigma away from pedestal peak fit->SetParLimits(0, 0, 10); fit->FixParameter(1, fped->GetParameter(1)); fit->FixParameter(2, fped->GetParameter(2)); fit->SetParLimits(3, fped->GetParameter(2)*2, 350); fit->SetParLimits(4, 1.01, 100.); double maxfitrange = 500.; double minfitrange = 0.; hspe->Fit(fit, "MNQL", "", minfitrange, maxfitrange); double rms_estimate = fit->GetParameter(3)/sqrt(fit->GetParameter(4)); maxfitrange = fped->GetParameter(1)+4*fit->GetParameter(3)+rms_estimate; // cout<<"estimate of gain "<<gain_est<<", fit "<<fit->GetParameter(3)<<endl; // cout<<"Shape Parameter "<<fit->GetParameter(4)<<endl; // cout<<"SPE width "<<rms_estimate<<endl; // cout<<"maxfitrange "<<maxfitrange<<endl; if(500<maxfitrange) maxfitrange = 500; hspe->Fit(fit, "MNQL", "", minfitrange, maxfitrange); //calculate NDOF of fit excluding bins with 0 entries int myNDOF=-3; //three free parameters for(int j=hspe->FindBin(minfitrange); j<=hspe->FindBin(maxfitrange); j++) { //loop through fitted spe bins if(hspe->GetBinContent(j)) myNDOF++; } //loop through fitted spe bins // cout<<"estimate of gain "<<gain_est<<", fit "<<fit->GetParameter(3)<<endl; // cout<<"Shape Parameter "<<fit->GetParameter(4)<<endl; // double SPE_rms = fit->GetParameter(3)/sqrt(fit->GetParameter(4)); // cout<<"SPE width "<<SPE_rms<<endl; //cout<<"SPE width "<<fit->GetParameter(4)<<endl; //cout<<"Fit normalization constant: estimate "<<mu<<" fit "<<fit->GetParameter(0)<<endl; //cout<<spename<<endl; //calculate means and integrals of the fit and data double fint, fint_error, hint, favg, havg; int temp_lowbin, temp_highbin; temp_lowbin = hspe->FindBin(minfitrange); temp_highbin = hspe->FindBin(maxfitrange); hspe_unscaled->GetXaxis()->SetRangeUser(minfitrange, maxfitrange); havg = hspe_unscaled->GetMean(); hint = hspe->Integral(temp_lowbin,temp_highbin,"width"); double min_frange = hspe->GetBinLowEdge(temp_lowbin); favg = fit->Mean(min_frange, maxfitrange); fint = fit->Integral(min_frange, maxfitrange); //fint_error = fit->IntegralError(min_frange, maxfitrange); double PE5int = 0; //integral of events with >=5 PE double PE5loc = fped->GetParameter(1)+ 5*fit->GetParameter(3); if(PE5loc>500) PE5int = 0; else { int PE5bin = hspe_temp->FindBin(PE5loc); temp_highbin = hspe_temp->FindBin(maxfitrange)-1; PE5int = hspe_temp->Integral(PE5bin,temp_highbin,"width"); } int PE5flag = 0; if(PE5int/hint>0.05) PE5flag = 1; //set flag if more than 5% of events in the fit correspond to >=5PE //========================================= for(int i1=1;i1<hspe->GetNbinsX();i1++){ constants_file1<<HV<<"\t"<<iSpig<<"\t"<<i<<"\t"<<2.6*hspe->GetBinCenter(i1)<<"\t"<<hspe->GetBinContent(i1)<<"\t"<<fit->Eval(hspe->GetBinCenter(i1))<<"\n"; } //========================================= //output calibrations constants //constants_file<<endl<<"LED_amplitude HV Spigot Channel Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag Polya_shape Polya_shape_err Polya_mode"<<endl; constants_file<<LED_amp<<" "<<HV<<" "<<iSpig<<" "<<(bb-1)*8+pmt<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParError(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fped->GetParError(2)<<" "<<scale*fit->GetParameter(3)/sqrt(fit->GetParameter(4))<<" "<<0<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<scale*fit->GetParError(3)*fC2electrons<<" "<<fit->GetChisquare()/myNDOF/*fit->GetNDF()*/<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<" "<<fit->GetParameter(4)<<" "<<fit->GetParError(4)<<" "<<scale*(fit->GetParameter(4)-1.0)/fit->GetParameter(4)*fit->GetParameter(3)*fC2electrons<<endl; // cout<<LED_amp<<" "<<HV<<" "<<iSpig<<" "<<QIECh[i]<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParError(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fped->GetParError(2)<<" "<<scale*fit->GetParameter(4)<<" "<<scale*fit->GetParError(4)<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<scale*fit->GetParError(3)*fC2electrons<<" "<<fit->GetChisquare()/fit->GetNDF()<<" "<<fit->GetChisquare()<<" "<<fit->GetNDF()<<" "<<myNDOF<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<endl; //extra_file<<endl<<"LED_amplitude HV Spigot Channel SignalAvg_inFitRange FitAvg_inFitRange SignalInt_inFitRange FitInt_inFitRange PEge5Int Gain(fC) Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl; //extra_file<<LED_amp<<" "<<HV<<" "<<iSpig<<" "<<QIECh[i]<<" "<<scale*havg<<" "<<scale*favg<<" "<<hint<<" "<<fint<<" "<<PE5int<<" "<<scale*fit->GetParameter(3)<<" "<<scale*fit->GetParError(3)<<" "<<fit->GetChisquare()/myNDOF<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<endl; //cout<<"# Spigot Channel Ped_mean Ped_RMS SPE_PeakRMS Gain Normalized_Chi2 Avg_PE"<<endl; //cout<<iSpig<<" "<<i<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fit->GetParameter(4)<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<fit->GetChisquare()/fit->GetNDF()<<" "<<fit->GetParameter(0)<<endl<<endl; if(iSpig==0) c1->cd(i+1); else if(iSpig==1) c2->cd(i+1); else if(iSpig==2) c3->cd(i+1); gPad->SetBorderMode(0); gPad->SetBorderSize(0); gPad->SetRightMargin(0.01); gPad->SetBottomMargin(0.1); gPad->SetLogy(true); hspe->GetXaxis()->SetRangeUser(0, /*300*/508); hspe->SetLineColor(kBlue); hspe->DrawClone("hist"); fit->SetLineWidth(2); fit->Draw("same"); } } if(drawflag) { //draw plots of fit if data for the HV is present stringstream plot_name; //plot_name<<"Plots/SPEFits_Spigot0_Run_"<<run<<"_HV"<<HV<<".pdf"; plot_name<<"Plots/SPEFits_Spigot0_Run_"<<run<<"_HV"<<HV<<"_config"<<ii<<".pdf"; c1->SaveAs(plot_name.str().c_str()); plot_name.str( std::string() ); //plot_name<<"Plots/SPEFits_Spigot1_Run_"<<run<<"_HV"<<HV<<".pdf"; plot_name<<"Plots/SPEFits_Spigot1_Run_"<<run<<"_HV"<<HV<<"_config"<<ii<<".pdf"; c2->SaveAs(plot_name.str().c_str()); plot_name.str( std::string() ); //plot_name<<"Plots/SPEFits_Spigot2_Run_"<<run<<"_HV"<<HV<<".pdf"; plot_name<<"Plots/SPEFits_Spigot2_Run_"<<run<<"_HV"<<HV<<"_config"<<ii<<".pdf"; c3->SaveAs(plot_name.str().c_str()); } } //HV loop constants_file.close(); constants_file1.close(); }
void plotGlauberCenVars(Float_t eff=1., const Char_t* file="ZNA_ntuple_195483.root") { TFile *f = TFile::Open(file); TNtuple* ntuple = dynamic_cast<TNtuple*> (f->Get("gnt")); TGraphErrors *gNpart=new TGraphErrors(0); gNpart->SetName("gNpart"); TGraphErrors *gNcoll=new TGraphErrors(0); gNcoll->SetName("gNcoll"); TGraphErrors *gtAA=new TGraphErrors(0); gtAA->SetName("gtAA"); /*TFile *ffd = TFile::Open("hZNAcalibRUN195483.root"); TH1F * hd = dynamic_cast<TH1F*> (ffd->Get(("hZNA"))); hd->Sumw2();*/ // TFile *ff = TFile::Open("ZNA_fit_195483.root"); TH1F * hd = dynamic_cast<TH1F*> (ff->Get(("hZNA"))); hd->Sumw2(); TH1F * hg = dynamic_cast<TH1F*> (ff->Get(("hZNA_GLAU"))); hd->SetMarkerColor(kBlue+3); hd->SetMarkerSize(1.); hd->SetLineColor(kBlue+3); hd->SetLineWidth(2); hd->SetMarkerStyle(20); hd->SetLineWidth(2); // hg->Scale(1./hd->GetEntries()); // hd->Scale(1./hd->GetEntries()); hd->SetMinimum(1.e-01); hd->SetXTitle("E_{ZNA} (TeV)"); hg->SetLineColor(kPink-2); hg->SetLineWidth(2); TH1F* hist = (TH1F*) hg->Clone("hist"); //--------------------------------------------------- getCentrality(hist, eff); //--------------------------------------------------- TCanvas* canvas = new TCanvas("canvas","Multiplicity",200,200,600,600); canvas->cd(); canvas->SetLogy(); hd->Draw("pe"); //hd->GetXaxis()->SetRangeUser(0.,130.); hd->SetMinimum(0.01); hg->Draw("SAME"); float low = 0; float high = hist->GetNbinsX(); for(int i=0; i<binUp->GetSize(); i++){ low = binUp->At(i); hist->GetXaxis()->SetRange(low+1, high); hist->SetFillColor((i%2==0)?0:kAzure+6); hist->SetLineColor((i%2==0)?0:kAzure+6); printf(" bin %d low %f high %f\n",i,low,high); hist->DrawCopy("h same"); high=low; } hd->Draw("esame"); hg->Draw("SAME"); canvas->Print("plotGlauber.gif"); TCanvas* canvas2 = new TCanvas("canvas2","NPart"); canvas2->cd(); canvas2->SetLogy(); TH1F *hist2 = new TH1F("hist2","N_{part}",35,0.,35); ntuple->Project("hist2","fNpart"); //hist2->SetStats(0); hist2->SetTitle(""); hist2->GetXaxis()->SetTitle("NPart"); hist2->GetXaxis()->SetTitleSize(0.05); hist2->GetXaxis()->SetLabelSize(0.04); hist2->GetXaxis()->SetTitleOffset(1.2); hist2->GetYaxis()->SetTitle(""); hist2->GetYaxis()->SetTitleOffset(1.3); hist2->GetYaxis()->SetTitleSize(0.05); hist2->GetYaxis()->SetLabelSize(0.04); hist2->DrawCopy(); float lownp=0; float highnp=5000; TH1F *htemp10[nbins]; printf("\n ***** N_part \n"); for(int i=0; i<Multbin->GetSize(); i++){ lownp = Multbin->At(i); char cuts[120]; char histname[20]; sprintf(cuts,"Etot>%f && Etot<=%f",lownp,highnp); sprintf(histname,"htemp10[%i]",i); htemp10[i] = new TH1F(histname,"N_{part}",35,0.,35); //printf(" cut: %s\n", cuts); ntuple->Project(histname,"fNpart",cuts); htemp10[i]->SetLineColor(i+1); htemp10[i]->Draw("same"); cout << i << " | " << lownp << " | " << highnp << " | " << setprecision(3) << htemp10[i]->GetMean() << " | " << htemp10[i]->GetRMS() << " | " << endl; gNpart->SetPoint(i,Float_t(i),htemp10[i]->GetMean()); gNpart->SetPointError(i,0,htemp10[i]->GetRMS()); highnp = lownp; } cout << endl; TCanvas* canvas3 = new TCanvas("canvas3","NColl"); canvas3->SetLogy(); TH1F *hist3 = new TH1F("hist3","N_{coll}",35,0.,35); ntuple->Project("hist3","fNcoll"); //hist3->SetStats(0); hist3->SetTitle(""); hist3->GetXaxis()->SetTitle("NColl"); hist3->GetXaxis()->SetTitleSize(0.05); hist3->GetXaxis()->SetLabelSize(0.04); hist3->GetXaxis()->SetTitleOffset(1.2); hist3->GetXaxis()->SetTitle(""); hist3->GetXaxis()->SetTitleOffset(1.3); hist3->GetXaxis()->SetTitleSize(0.05); hist3->GetXaxis()->SetLabelSize(0.04); hist3->DrawCopy(); float lownc = 0; float highnc = 5000; TH1F *htemp11[nbins]; printf("\n ***** N_coll \n"); for(int i=0; i<Multbin->GetSize(); i++){ lownc = Multbin->At(i); char cuts[120]; char histname[20]; sprintf(cuts,"Etot>%f && Etot<=%f",lownc,highnc); sprintf(histname,"htemp11[%i]",i); htemp11[i] = new TH1F(histname,"N_{coll}",35,0.,35.); ntuple->Project(histname,"fNcoll",cuts); htemp11[i]->SetLineColor(i+1); htemp11[i]->Draw("same"); cout << setprecision(3) << htemp11[i]->GetMean() << " | " << htemp11[i]->GetRMS() << " | " << endl; gNcoll->SetPoint(i,Float_t(i),htemp11[i]->GetMean()); gNcoll->SetPointError(i,0,htemp11[i]->GetRMS()); highnc = lownc; } cout << endl; TCanvas* canvas4 = new TCanvas("canvas4","Impact Parameter"); canvas4->cd(); TH1F *hist4 = new TH1F("hist4","b",100,0.,16.); ntuple->Project("hist4","fB"); //hist4->SetStats(0); hist4->SetTitle(""); hist4->GetXaxis()->SetTitle("b"); hist4->GetXaxis()->SetTitleSize(0.05); hist4->GetXaxis()->SetLabelSize(0.04); hist4->GetXaxis()->SetTitleOffset(1.2); hist4->GetYaxis()->SetTitle(""); hist4->GetYaxis()->SetTitleOffset(1.3); hist4->GetYaxis()->SetTitleSize(0.05); hist4->GetYaxis()->SetLabelSize(0.04); hist4->DrawCopy(); float lowb = 0; float highb = 5000; TH1F *htemp12[nbins]; printf("\n ***** b \n"); for(int i=0; i<Multbin->GetSize(); i++){ lowb = Multbin->At(i); char cuts[100]; char histname[25]; sprintf(cuts,"Etot>%f && Etot<=%f",lowb,highb); sprintf(histname,"htemp12[%i]",i); htemp12[i] = new TH1F(histname,"b",100,0.,16.); //printf(" cut: %s\n", cuts); ntuple->Project(histname,"fB",cuts); htemp12[i]->SetLineColor(i+1); htemp12[i]->DrawCopy("same"); cout << i << " | " << lowb << " | " << highb << " | " << setprecision(3) << htemp12[i]->GetMean() << " | " << htemp12[i]->GetRMS() << " | " << endl; highb = lowb; } TCanvas* canvas5 = new TCanvas("canvas5","Taa"); canvas5->SetLogy(); TH1F *hist5 = new TH1F("hist5","T_{AA}",100,0.,0.5); ntuple->Project("hist5","fTaa"); //hist5->SetStats(0); hist5->SetTitle(""); hist5->GetXaxis()->SetTitle("tAA"); hist5->GetXaxis()->SetTitleSize(0.05); hist5->GetXaxis()->SetLabelSize(0.04); hist5->GetXaxis()->SetTitleOffset(1.2); hist5->GetYaxis()->SetTitle(""); hist5->GetYaxis()->SetTitleOffset(1.3); hist5->GetYaxis()->SetTitleSize(0.05); hist5->GetYaxis()->SetLabelSize(0.04); hist5->DrawCopy(); float lowtaa = 0; float hightaa = 5000; TH1F *htemp13[nbins]; printf("\n ***** T_AA \n"); for (int i=0; i<Multbin->GetSize(); i++){ lowtaa = Multbin->At(i); char cuts[100]; char histname[100]; sprintf(cuts,"Etot>%f && Etot<%f",lowtaa,hightaa); //printf(" cut: %s\n", cuts); sprintf(histname,"htemp13[%i]",i); htemp13[i] = new TH1F(histname,"b",100,0.,0.5); ntuple->Project(histname,"fTaa",cuts); htemp13[i]->SetLineColor(i+1); htemp13[i]->DrawCopy("same"); cout << setprecision(3) << htemp13[i]->GetMean() << " | " << htemp13[i]->GetRMS() << " | " << endl; gtAA->SetPoint(i,Float_t(i),htemp13[i]->GetMean()); gtAA->SetPointError(i,0,htemp13[i]->GetRMS()); hightaa = lowtaa; } /*TCanvas* canvas6 = new TCanvas("canvas6","Mean Mult"); canvas6->SetLogy(); //ntuple->Draw("ntot/Npart/23.867>>hmultperanc"); ntuple->Draw("Etot/(0.801*Npart+(1-0.801)*Ncoll)/3.9>>hmultperanc"); TH1F* hmultperanc = (TH1F*)gPad->GetPrimitive("hmultperanc"); TH1F* hist6 = (TH1F*)hmultperanc->Clone(); hist6->SetStats(0); hist6->SetTitle(""); hist6->GetXaxis()->SetTitle("Mult/NPart"); hist6->GetXaxis()->SetTitleSize(0.05); hist6->GetXaxis()->SetLabelSize(0.04); hist6->GetXaxis()->SetTitleOffset(1.); hist6->GetYaxis()->SetTitle(""); hist6->GetYaxis()->SetTitleOffset(1.); hist6->GetYaxis()->SetTitleSize(0.05); hist6->GetYaxis()->SetLabelSize(0.04); hist6->DrawCopy(); low=0; high=50000; for (int i=0; i<Multbin->GetSize(); i++) { low=Multbin->At(i); char cuts[100]; char histtitle1[100]; char histtitle[100]; sprintf(cuts,"Etot>%i && Etot<%i",low,high); //sprintf(histtitle,"ntot/Npart/23.867>>htemp%i(100)",80+i); sprintf(histtitle,"Etot/(0.801*Npart+(1-0.801)*Ncoll)/3.9>>htemp%i(100)",80+i); sprintf(histtitle1,"htemp%i",80+i); ntuple->Draw(histtitle,cuts,"same"); TH1F* htemp14 = (TH1F*)gPad->GetPrimitive(histtitle1); htemp14 = (TH1F*)gPad->GetPrimitive(histtitle1); htemp14->SetFillColor(i+1); htemp14->DrawCopy("same"); //cout << i << " | " << low << " | " << high << " | " << setprecision(3) << htemp14->GetMean() << " | " << htemp14->GetRMS() << " | " << endl; high=low; h->SetBinContent(i+1,htemp14->GetMean()); h->SetBinError(i+1,0.01*htemp14->GetRMS()); } TCanvas* c7 = new TCanvas("c7","c7"); c7->cd(); h->Draw(); */ //TFile *outrootfile = new TFile("OutGlauber_Hijing.root","RECREATE"); TFile *outrootfile = new TFile("test.root","RECREATE"); outrootfile->cd(); //h->Write(); gNpart->Write(); gNcoll->Write(); gtAA->Write(); hd->Write(); outrootfile->Close(); }
void printHisto( TCanvas *can , TChain *data , TChain *mc , TCut num , TCut denom , char* var , int nbins , float xmin , float xmax , char* xtitle , char* ytitle){ can->cd(); TPad *plotpad = new TPad("plotpad","plotpad",0.0,0.0,1.0,0.8); plotpad->Draw(); plotpad->cd(); // float ptbin[] = {30., 40., 60. , 80. , 100. , 120. , 150. , 200 , 300 }; // int nptbin = 8; float ptbin[] = { 20., 30. , 40. , 50. , 60. , 80.0 , 100.0 , 150.0 , 200.0 , 300.0 , 350.0 }; int nptbin = 10; // float ptbin[] = { 20., 30. , 40. , 50. , 60. , 80.0 , 100.0 , 150.0 , 200.0 , 300.0 , 500.0 , 1000.0 , 1100.0 }; // int nptbin = 12; xmax=ptbin[nptbin]; cout << "Using xmax " << xmax << endl; //TH1F* hpass = new TH1F(Form("hpass_%i",iplot),Form("hpass_%i",iplot),nptbin,ptbin); //TH1F* hall = new TH1F(Form("hall_%i" ,iplot),Form("hall_%i" ,iplot),nptbin,ptbin); // TH1F* hpass_data = new TH1F(Form("hpass_data_%i",iplot),Form("hpass_data_%i",iplot),nbins,xmin,xmax); // TH1F* hall_data = new TH1F(Form("hall_data_%i" ,iplot),Form("hall_data_%i" ,iplot),nbins,xmin,xmax); // TH1F* hpass_mc = new TH1F(Form("hpass_mc_%i" ,iplot),Form("hpass_mc_%i" ,iplot),nbins,xmin,xmax); // TH1F* hall_mc = new TH1F(Form("hall_mc_%i" ,iplot),Form("hall_mc_%i" ,iplot),nbins,xmin,xmax); TH1F* hpass_data = new TH1F(Form("hpass_data_%i" ,iplot),Form("hpass_data_%i" ,iplot),nptbin,ptbin); TH1F* hall_data = new TH1F(Form("hall_data_%i" ,iplot),Form("hall_data_%i" ,iplot),nptbin,ptbin); TH1F* hratio_data = new TH1F(Form("hratio_data_%i" ,iplot),Form("hratio_data_%i" ,iplot),nptbin,ptbin); TH1F* hpass_mc = new TH1F(Form("hpass_mc_%i" ,iplot),Form("hpass_mc_%i" ,iplot),nptbin,ptbin); TH1F* hall_mc = new TH1F(Form("hall_mc_%i" ,iplot),Form("hall_mc_%i" ,iplot),nptbin,ptbin); TH1F* hratio_mc = new TH1F(Form("hratio_mc_%i" ,iplot),Form("hratio_mc_%i" ,iplot),nptbin,ptbin); TH1F* hsf = new TH1F(Form("hsf_%i" ,iplot),Form("hsf_%i" ,iplot),nptbin,ptbin); hpass_data->Sumw2(); hall_data->Sumw2(); hratio_data->Sumw2(); hpass_mc->Sumw2(); hall_mc->Sumw2(); hratio_mc->Sumw2(); hsf->Sumw2(); //TCanvas *can = new TCanvas(Form("can_%i",iplot),Form("can_%i",iplot),600,600); //can->cd(); data->Draw(Form("min(%s,%f)>>hpass_data_%i" , var,xmax-0.0001,iplot),denom+num); data->Draw(Form("min(%s,%f)>>hall_data_%i" , var,xmax-0.0001,iplot),denom); mc->Draw (Form("min(%s,%f)>>hpass_mc_%i" , var,xmax-0.0001,iplot),denom+num); mc->Draw (Form("min(%s,%f)>>hall_mc_%i" , var,xmax-0.0001,iplot),denom); TGraphAsymmErrors *grdata = new TGraphAsymmErrors(); grdata->BayesDivide(hpass_data,hall_data); TGraphAsymmErrors *grmc = new TGraphAsymmErrors(); grmc->BayesDivide(hpass_mc,hall_mc); cout << "data all " << hall_data->GetBinContent(2) << endl; cout << "data pass " << hpass_data->GetBinContent(2) << endl; cout << "data eff " << hpass_data->GetBinContent(2) / hall_data->GetBinContent(2) << endl; Double_t x; Double_t y; grdata->GetPoint(1,x,y); cout << "data eff2 " << y << endl; cout << "MC all " << hall_mc->GetBinContent(2) << endl; cout << "MC pass " << hpass_mc->GetBinContent(2) << endl; cout << "MC eff " << hpass_mc->GetBinContent(2) / hall_mc->GetBinContent(2) << endl; Double_t xmc; Double_t ymc; grmc->GetPoint(1,xmc,ymc); cout << "MC eff2 " << ymc << endl; gPad->SetGridx(); gPad->SetGridy(); grdata->SetMarkerColor(2); grdata->SetLineColor(2); grmc->SetMarkerColor(4); grmc->SetLineColor(4); grmc->SetMarkerStyle(25); grdata->GetXaxis()->SetRangeUser(20,350); if( TString(ytitle).Contains("iso") ) grdata->GetYaxis()->SetRangeUser(0.8,1.0); if( TString(ytitle).Contains("ID") ) grdata->GetYaxis()->SetRangeUser(0.5,1.0); grdata->GetXaxis()->SetTitle(xtitle); grdata->GetYaxis()->SetTitle(ytitle); grdata->Draw("AP"); grmc->Draw("sameP"); TLegend *leg = new TLegend(0.6,0.15,0.75,0.3); leg->AddEntry(grdata ,"data","lp"); leg->AddEntry(grmc ,"mc" ,"lp"); leg->SetBorderSize(1); leg->SetFillColor(0); leg->Draw(); TLatex *t = new TLatex(); t->SetNDC(); if( TString(denom.GetTitle()).Contains("njets>=0") ) t->DrawLatex(0.2,0.2,"n_{jets} #geq 0"); if( TString(denom.GetTitle()).Contains("njets>=1") ) t->DrawLatex(0.2,0.2,"n_{jets} #geq 1"); if( TString(denom.GetTitle()).Contains("njets>=2") ) t->DrawLatex(0.2,0.2,"n_{jets} #geq 2"); if( TString(denom.GetTitle()).Contains("njets>=3") ) t->DrawLatex(0.2,0.2,"n_{jets} #geq 3"); if( TString(denom.GetTitle()).Contains("njets>=4") ) t->DrawLatex(0.2,0.2,"n_{jets} #geq 4"); can->cd(); TPad *respad = new TPad("respad","respad",0.0,0.8,1.0,1.0); respad->Draw(); respad->cd(); respad->SetGridy(); // TGraphAsymmErrors* gr_ratio = (TGraphAsymmErrors*) grdata->Clone("gr_ratio"); // gr_ratio->Divide(grmc); // gr_ratio->Draw(); hratio_data->Divide(hpass_data,hall_data,1,1,"B"); hratio_mc ->Divide(hpass_mc ,hall_mc,1,1,"B"); hsf ->Divide(hratio_data,hratio_mc,1,1); if( TString(ytitle).Contains("iso") ) hsf->GetYaxis()->SetRangeUser(0.9,1.1); if( TString(ytitle).Contains("ID") ) hsf->GetYaxis()->SetRangeUser(0.6,1.1); hsf->GetXaxis()->SetRangeUser(20,350); hsf->GetYaxis()->SetNdivisions(3); hsf->GetYaxis()->SetLabelSize(0.2); hsf->GetXaxis()->SetLabelSize(0.0); hsf->Draw("E1"); iplot ++; }
//-------------------------------------- //function to calculate sampling factors std::pair<Double_t,Double_t> g4_sample(int snum, Double_t energy, bool do_pion, bool do_show, bool do_print=false, bool set_val=true){ Sample* sp = sample_map[snum]; if(!sp) { std::cout << "Sample " << snum << " is not loaded." << std::endl; return std::pair<Double_t,Double_t>(0.,0.); } //select correct file std::string fpre = sp->fpre; if(do_pion) fpre += "_pion"; else fpre += "_elec"; //make filenames std::stringstream drawname, fname, piname; fname << sp->dir << "/" << fpre << "_" << energy << "gev_10k.root"; if(do_pion) piname << "#pi^{-} " << energy << " GeV"; else piname << "e^{-} " << energy << " GeV"; //open file and tree TFile* _file; _file = TFile::Open((fname.str()).c_str()); TTree* totalTree = (TTree*)_file->Get("Total"); //get histo from tree (no display) //define mip as sam_ecal*ecal < 1 gev = 1000 mev (for pions in HCAL) if(sp->det==Hcal) drawname << "(hcal+" << sp->zeroWt << "*zero)/1000>>hsam(200)"; else drawname << "(ecal)/1000>>hsam(200)"; totalTree->Draw((drawname.str()).c_str(),"","hist goff"); TH1F* hsam = (TH1F*)gDirectory->Get("hsam"); //use parameters from histo to start fit TSpectrum* spec = new TSpectrum(5); spec->Search(hsam,5,"nodraw goff"); Float_t* xpos = spec->GetPositionX(); Float_t* ypos = spec->GetPositionY(); Double_t m = xpos[0]; Double_t me = hsam->GetMeanError(); Double_t N = hsam->GetEntries(); std::stringstream s_mean; s_mean.precision(3); Double_t f = energy/m; Double_t f_err = energy*(me/(m*m)); s_mean << f << " #pm " << f_err; TPolyMarker* pm = new TPolyMarker(1, xpos, ypos); hsam->GetListOfFunctions()->Add(pm); pm->SetMarkerStyle(23); pm->SetMarkerColor(kRed); pm->SetMarkerSize(1.3); std::cout.precision(6); std::cout << "f_" << (do_pion ? "pion" : "elec") << " = " << f << " +/- " << f_err << std::endl; //plotting and printing if (do_show){ TCanvas* can = new TCanvas("sample","sample",700,500); can->cd(); TPad* pad = new TPad("graph","",0,0,1,1); pad->SetMargin(0.12,0.05,0.15,0.05); pad->Draw(); pad->cd(); //formatting hsam->SetTitle(""); hsam->GetXaxis()->SetTitle("Energy [GeV]"); //hsam->SetStats(kTRUE); //gStyle->SetOptStat("mr"); hsam->SetLineWidth(2); hsam->SetLineColor(kBlack); hsam->GetYaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC())); hsam->GetYaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC())); hsam->GetXaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC())); hsam->GetXaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC())); hsam->GetYaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC())); hsam->GetXaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC())); hsam->Draw(); std::stringstream Nname; Nname << "N = " << N; //determine placing of pave Double_t xmin; if (m/((hsam->GetXaxis()->GetXmax() + hsam->GetXaxis()->GetXmin())/2) < 1) xmin = 0.65; else xmin = 0.2; //legend TPaveText *pave = new TPaveText(xmin,0.65,xmin+0.2,0.85,"NDC"); pave->AddText((piname.str()).c_str()); pave->AddText((Nname.str()).c_str()); pave->AddText("Peak sampling factor:"); pave->AddText((s_mean.str()).c_str()); pave->SetFillColor(0); pave->SetBorderSize(0); pave->SetTextFont(42); pave->SetTextSize(0.05); pave->Draw("same"); if(do_print) { std::stringstream oname; oname << pdir << "/" << fpre << "_sample_" << energy << "gev_peak.png"; can->Print((oname.str()).c_str(),"png"); } } else _file->Close(); //store value in sample if(set_val){ if(do_pion) sp->sam_pion = f; else sp->sam_elec = f; } return std::pair<Double_t,Double_t>(f,f_err); }
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; } }
//------------------------------------------------------------------------ void DrawLEDminCFD() { Int_t npeaks = 10; Int_t sigma=10.; Bool_t down=false; Int_t index[20]; TCanvas *c1 = new TCanvas("c1", " LED-CFD C side",0,48,1280,951); c1->Divide(4,3); Char_t buf1[20]; for (Int_t i=0; i<12; i++) { c1->cd(i+1); sprintf(buf1,"LEDminCFD%i",i+1); TH1F *cfd = (TH1F*) gFile->Get(buf1); cfd->Draw(); TSpectrum *s = new TSpectrum(2*npeaks,1); Int_t nfound = s->Search(cfd,sigma," ",0.2); cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;; if(nfound!=0) { Float_t *xpeak = s->GetPositionX(); TMath::Sort(nfound, xpeak, index,down); Float_t xp = xpeak[index[0]]; Int_t xbin = cfd->GetXaxis()->FindBin(xp); Float_t yp = cfd->GetBinContent(xbin); cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[index[0]]<<"\typeak = "<<yp<<endl; Float_t hmin=xp-3*sigma; Float_t hmax =xp+3*sigma; cfd->GetXaxis()->SetRange(hmin,hmax); TF1 *g1 = new TF1("g1", "gaus", hmin, hmax); cfd->Fit("g1","RQ"); } } TCanvas *c2 = new TCanvas("c2", "LED-CFD A side",0,48,1280,951); c2->Divide(4,3); Char_t buf1[20]; for (Int_t i=12; i<24; i++) { c2->cd(i+1-12); sprintf(buf1,"LEDminCFD%i",i+1); TH1F *cfd = (TH1F*) gFile->Get(buf1); cfd->Draw(); TSpectrum *s = new TSpectrum(2*npeaks,1); Int_t nfound = s->Search(cfd,sigma," ",0.2); cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;; if(nfound!=0) { Float_t *xpeak = s->GetPositionX(); TMath::Sort(nfound, xpeak, index,down); Float_t xp = xpeak[index[0]]; Int_t xbin = cfd->GetXaxis()->FindBin(xp); Float_t yp = cfd->GetBinContent(xbin); cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[index[0]]<<"\typeak = "<<yp<<endl; Float_t hmin=xp-3*sigma; Float_t hmax =xp+3*sigma; cfd->GetXaxis()->SetRange(hmin,hmax); TF1 *g1 = new TF1("g1", "gaus", hmin, hmax); cfd->Fit("g1","RQ"); } } /* TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951); c1->Divide(2,2); Char_t buf1[10]; for (Int_t i=0; i<4; i++) { c1->cd(i+1); sprintf(buf1,"LED-CFD%i",i+1); TH1F *cfd = (TH1F*) file->Get(buf1); // cout<<buf1<<" "<<cfd<<endl; // cfd->Draw(); // cfd->GetXaxis()->SetRange(0,100); Float_t mean = cfd->GetMean(); Float_t rms = cfd->GetRMS(); Float_t hmin=mean - 3*rms; Float_t hmax =mean + 3*rms; cfd->GetXaxis()->SetRange(hmin-10,hmax+10); cout<<" cfd range "<<mean<<" rms "<<rms<<" "<<hmin<<" "<<hmax<<endl; // TF1 *g1 = new TF1("g1", "gaus", hmin, hmax); // cfd->Fit("g1","RQ"); cfd->Draw(); } */ }