Exemplo n.º 1
0
        void Draw(const int &rebin=1) {

	  Color_t _sampleColor[nSamples];
            //_sampleColor[iHWW  ] = kRed+1;
            //_sampleColor[iWW   ] = kAzure-9;
            //_sampleColor[iZJets] = kGreen+2;
            //_sampleColor[iZTau]  = kGreen+2;
            //_sampleColor[iTop  ] = kYellow;
            //_sampleColor[iWZ   ] = kAzure-2;
            //_sampleColor[iWJets] = kGray+1;
            //_sampleColor[iWJets] = kViolet-9;
            //_sampleColor[iWJets] = kCyan;

	    _sampleColor[itH   ] = kRed;
            _sampleColor[iWZ   ] = kAzure-9;
            _sampleColor[iZZ   ] = kAzure-5;
            _sampleColor[iWW   ] = kAzure-1;
            _sampleColor[itt   ] = kGray;
            _sampleColor[ittw  ] = kOrange+7;
            _sampleColor[ittz  ] = kOrange+1;
            _sampleColor[iwww  ] = kSpring+9;
            _sampleColor[iwwz  ] = kSpring+3;
            _sampleColor[iwzz  ] = kSpring-7;
            _sampleColor[idyl  ] = kViolet-1;
            _sampleColor[idy   ] = kViolet-1;
	    
            //setUpStyle();
            if(!gPad) new TCanvas();

            THStack* hstack = new THStack();
            for (int i=0; i<nSamples; i++) {

                // in case the user doesn't set it
                if( !_hist[i] ) continue;

                _hist[i]->Rebin(rebin);
                _hist[i]->SetLineColor(_sampleColor[i]);

                // signal gets overlaid
                if (i == itH) continue;

                _hist[i]->SetFillColor(_sampleColor[i]);
                _hist[i]->SetFillStyle(1001);

                hstack->Add(_hist[i]);
            }

            if(_hist[itH]) _hist[itH]->SetLineWidth(3);
            if(_data) _data->Rebin(rebin);
            if(_data) _data->SetLineColor  (kBlack);
            if(_data) _data->SetMarkerStyle(kFullCircle);

            if(_nostack) {
              for(int ihist=0;ihist<(int)_hist.size();ihist++) {
                _hist[ihist]->SetFillStyle(0);
                _hist[ihist]->SetLineWidth(2);
              }
              hstack->Draw("hist,nostack");
              if(_hist[itH]) _hist[itH]->Draw("hist,same");
              if(_data) _data->Draw("ep,same");
            } else {
              hstack->Draw("hist");
              if(_hist[itH]) _hist[itH]->Draw("hist,same");
              if(_data) _data->Draw("ep,same");
            }
            //hstack->SetTitle("CMS preliminary");

            Float_t theMax = hstack->GetMaximum();
            Float_t theMin = hstack->GetMinimum();

	    theMax = 1.0;
            //Float_t theMin = hstack->GetMinimum();

            if (_hist[itH]) {
                if (_hist[itH]->GetMaximum() > theMax) theMax = _hist[itH]->GetMaximum();
                if (_hist[itH]->GetMinimum() < theMin) theMin = _hist[itH]->GetMinimum();
            }

            if (_data) {

                Float_t dataMax = GetMaximumIncludingErrors(_data);

                if (dataMax > theMax) theMax = dataMax;
            }

            if (gPad->GetLogy()) {
                hstack->SetMaximum(500 * theMax);
                hstack->SetMinimum(0.05);
            } else {
                hstack->SetMaximum(1.55 * theMax);
            }

            if(_breakdown) {
                THStackAxisFonts(hstack, "y", "entries");
                hstack->GetHistogram()->LabelsOption("v");
            } else {
                THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
                if(_units.Sizeof() == 1) {
                    THStackAxisFonts(hstack, "x", _xLabel.Data());
                    THStackAxisFonts(hstack, "y", "entries");
                } else {
                    THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
                    THStackAxisFonts(hstack, "y", TString::Format("entries / %.0f %s", _hist[iWZ]->GetBinWidth(0),_units.Data()));
                }
            }

            // total mess to get it nice, should be redone
            size_t j=0;
            TString higgsLabel = " tH x 100";
            //if(_mass != 0) higgsLabel.Form(" m_{H}=%d",_mass);

	    
            if(_data        ) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _data,         " data",    "lp"); j++; }
            if(_hist[itH   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itH   ], higgsLabel, "l" ); j++; }
            if(_hist[iWZ   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWZ   ], " WZ",      "f" ); j++; }
            if(_hist[iZZ   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iZZ   ], " ZZ",      "f" ); j++; }
            if(_hist[iWW   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWW   ], " WW",      "f" ); j++; }
            if(_hist[itt   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itt   ], " tt",      "f" ); j++; }
            if(_hist[ittw  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittw  ], " ttW",     "f" ); j++; }
            if(_hist[ittz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittz  ], " ttZ",     "f" ); j++; }
            if(_hist[iwww  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwww  ], " WWW",     "f" ); j++; }
            if(_hist[iwwz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwwz  ], " WWZ",     "f" ); j++; }
            if(_hist[iwzz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwzz  ], " WZZ",     "f" ); j++; }
            if(_hist[idy   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[idy   ], " Drell-Yan","f" ); j++; }
	    

            //TLatex* luminosity = new TLatex(0.9, 0.815, TString::Format("L = %.1f fb^{-1}",_lumi));
            TLatex* luminosity = new TLatex(0.9, 0.95, TString::Format("CMS Preliminary \\sqrt{s} = 8 TeV, L = %.1f fb^{-1}",_lumi));
            luminosity->SetNDC();
            luminosity->SetTextAlign(32);
            luminosity->SetTextFont(42);
            luminosity->SetTextSize(_tsize);
            luminosity->Draw("same");
            // if(_extraLabel) _extraLabel->Draw("same");
            // return hstack->GetHistogram();
        }
Exemplo n.º 2
0
void plotsNoFitETau(bool mine=false,TString name="collMass",TString file="LFV_vbf_collMass_fakeRate_zjetsEmbed_newSignal.root", TString dir="preselectionMetFix_Nov2", TString dirInternal="vbfmutau",double blindA=100, double blindB=160, bool blind=false, TString Xaxis="M_{#mu,#tau}_{coll} [GeV]", TString Yaxis="Events / 20 GeV", TString Tex="#mu#tau_{h} 0 Jet", double xmin=0, double xmax=300, int rebinning=1, bool setLogY=false, double legx1=0.6, double legy1=0.9, double legx2=0.9, double legy2=0.5, double MAX=-1, double MIN=-1, double CORRFR=1., double scaleSignal=1.0, double ymin=-0.95, double ymax=0.95){

  //gROOT->LoadMacro("tdrstyle.C");
  setTDRStyle();
  //gROOT->LoadMacro("CMS_lumi.C");
  writeExtraText = false; 
  int iPeriod = 2; 
  // second parameter in example_plot is iPos, which drives the position of the CMS logo in the plot
  int iPos=11;// : top-left, left-aligned
  // iPos=33 : top-right, right-aligned
  // iPos=22 : center, centered
  // mode generally : 
  //   iPos = 10*(alignement 1/2/3) + position (1/2/3 = left/center/right)
  //  example_plot( iPeriod, 11 );  // left-aligned
  //  example_plot( iPeriod, 33 );  // right-aligned
  //  example_plot( iPeriod, 0 );   // out of frame (in exceptional cases)
  //  example_plot( iPeriod, 11 );  // default: left-aligned
  //  example_plot( iPeriod, 22 );  // centered
  //  example_plot( iPeriod, 33 );  // right-aligned  



  double kForPlotting=1;
  double branchingratioTauTau=0.063;
  double branchingratioTauMu=0.1;
  double Lumi=19717;

 // Get Plots

 // Get Plots

        TFile *_file0= new TFile(dir+"/"+file);
	TString find="DYrightarrowlljets";
	if(!mine) find="zjetsother";
        TH1F *hDY=_file0->Get(dirInternal+find); hDY->SetName("DY");
	find="Diboson";
	if(!mine) find="ww";
        TH1F *hWW=_file0->Get(dirInternal+find); hWW->SetName("WW");
	find="SingleTop";
	if(!mine) find="singlet";
        TH1F *hTOP=_file0->Get(dirInternal+find); hTOP->SetName("TOP");
	find="tbart";
	if(!mine) find="ttbar";
        TH1F *hTT=_file0->Get(dirInternal+find); hTT->SetName("TT");
	find="Zrightarrowtautauembedded";
	if(!mine) find="ztautau";
        TH1F *hZTauTau=_file0->Get(dirInternal+find); hZTauTau->SetName("ZTauTau");
	find="Fakes";
	if(!mine) find="fakes";
        TH1F *hFAKES=_file0->Get(dirInternal+find); hFAKES->SetName("fakes");
                hFAKES->Scale(CORRFR);
        TH1F *hLFVVBF126=_file0->Get(dirInternal+"LFVvbfHiggsBR=1"); hLFVVBF126->SetName("LFVVBF126");
        TH1F *hSMVBF126=_file0->Get(dirInternal+"SMvbfHiggs"); hSMVBF126->SetName("SMVBF126");
        TH1F *hLFVGG126=_file0->Get(dirInternal+"LFVggHiggsBR=1"); hLFVGG126->SetName("LFVGG126");
        TH1F *hSMGG126=_file0->Get(dirInternal+"SMHiggs"); hSMGG126->SetName("SMGG126");

	find="Observed";
	if(!mine) find="data_obs";
        TH1F* hdata_obsNoErrFix=_file0->Get(dirInternal+find);
        TH1F* hdata_obs = hdata_obsNoErrFix->Clone();
        std::cout << hdata_obsNoErrFix->GetEntries() << std::endl;
        for (i = 1; i <= hdata_obs->GetNbinsX(); i++){
                if (hdata_obs->GetBinContent(i) == 0){
                        hdata_obs->SetBinContent(i,0.0);
                        hdata_obs->SetBinError(i,1.8);
                }
        }

	hdata_obs->SetName("data_obs");


        TH1F* hSMHIGGS=hSMGG126->Clone(); hSMHIGGS->SetName("HIGGSSM");
        hSMHIGGS->Add(hSMVBF126);

        // For the Control plots only we want signal to be scaled to 100% Br
        hLFVVBF126->Scale(scaleSignal);
        hLFVGG126->Scale(scaleSignal);

// From the fit
/*	hDY->Scale(1.122280);
	hWW->Scale(1.254172);
	hTOP->Scale(1.348162);
	hTT->Scale(1.082784);
	hZTauTau->Scale(1.157596);
	hFAKES->Scale(0.901000);
*/
	
 // Daniel's Colors
/*
WGammaStar=kCyan
ZTauTauEmbedded=kOrange-4
ZLL_residual=kAzure+3
TTBar=40
SingleTop=kGreen-2
EWKDiBoson=kRed+2
WJets/QCD Multijets=kMagenta-10
SMHToTauTau=kMagenta
*/
        hFAKES->SetFillColor(kMagenta-10); hFAKES->SetLineColor(kMagenta+4); hFAKES->SetLineWidth(1);
        hZTauTau->SetFillColor(kOrange-4); hZTauTau->SetLineColor(kOrange+4); hZTauTau->SetLineWidth(1);

        hDY->SetFillColor(kAzure+3); hDY->SetLineColor(kAzure+4); hDY->SetLineWidth(1);
        hWW->SetFillColor(kAzure+3); hWW->SetLineColor(kAzure+3); hWW->SetLineWidth(1);

        hTOP->SetFillColor(kGreen-2); hTOP->SetLineColor(kGreen+4); hTOP->SetLineWidth(1);
        hTT->SetFillColor(kGreen-2); hTT->SetLineColor(kGreen-2); hTT->SetLineWidth(1);

        hLFVGG126->SetLineColor(kBlue+1);  hLFVGG126->SetLineWidth(3);
        hLFVVBF126->SetLineColor(kBlue+1); hLFVVBF126->SetLineWidth(3); hLFVVBF126->SetLineStyle(kDashed);
        hSMVBF126->SetLineColor(kMagenta); hSMVBF126->SetLineWidth(3); hSMVBF126->SetLineStyle(kDashed); 
        hSMGG126->SetLineColor(kMagenta); hSMGG126->SetLineWidth(3); 
        hSMHIGGS->SetFillColor(kMagenta); hSMHIGGS->SetLineColor(kMagenta+1); hSMHIGGS->SetLineWidth(1);



	hdata_obs->SetMarkerSize(1); // Closer to Daniel's

 // Rebin

	hFAKES->Rebin(rebinning);
	hZTauTau->Rebin(rebinning);
        hDY->Rebin(rebinning);
        hTOP->Rebin(rebinning);
	hTT->Rebin(rebinning);
	hWW->Rebin(rebinning);
	hLFVGG126->Rebin(rebinning);
	hLFVVBF126->Rebin(rebinning);
	hSMVBF126->Rebin(rebinning);
        hSMGG126->Rebin(rebinning);
	hdata_obs->Rebin(rebinning);
	hSMHIGGS->Rebin(rebinning);

// PLOT

        TCanvas *c1 = new TCanvas("canvas_"+name);
        TPad *Pad1= new TPad("pad1","",0,0.2,1,1); Pad1->Draw(); Pad1->cd();;
        Pad1->SetLeftMargin(0.2147651);
        Pad1->SetRightMargin(0.06543624);
        Pad1->SetTopMargin(0.07);
        Pad1->SetBottomMargin(0.04);


        for (int i=0; i<hFAKES->GetNbinsX()+1; i++){
                double content=hFAKES->GetBinContent(i);
                double contentErr=0;//sqrt(content);//hFAKES->GetBinError(i);
		double err=sqrt(0.3*0.3*content*content+contentErr*contentErr);
                hFAKES->SetBinError(i,err);
        }

        TH1F* fullMC2=hZTauTau->Clone();  fullMC2->Add(hFAKES); fullMC2->Add(hTT); fullMC2->Add(hWW);
        fullMC2->Add(hDY); fullMC2->Add(hTOP);
        fullMC2->SetFillColorAlpha(kGray+2, 0.35); 
        //fullMC2->SetFillStyle(3002); 
        fullMC2->SetMarkerSize(0);
	fullMC2->Draw("hist");

        fullMC2->GetXaxis()->SetTitle("");
        fullMC2->GetYaxis()->SetTitle(Yaxis);
        fullMC2->GetXaxis()->SetRangeUser(xmin,xmax);
        fullMC2->GetYaxis()->SetTitleOffset(1.2);
        fullMC2->GetYaxis()->SetTitleSize(0.05);
        fullMC2->GetXaxis()->SetNdivisions(505);
        fullMC2->GetYaxis()->SetLabelSize(0.04);
	fullMC2->GetXaxis()->SetLabelSize(0);

	THStack* stack = new THStack("stack","");
        stack->Add(hFAKES);
        stack->Add(hWW);
        stack->Add(hDY);
        stack->Add(hTT);
        stack->Add(hTOP);
        stack->Add(hZTauTau);
        stack->Add(hSMHIGGS);

	cout<<"Yields"<<endl;
	cout<<"VV " <<hWW->Integral()<<endl;
        cout<<"TOP " <<hTOP->Integral()<<endl;
        cout<<"TT " <<hTT->Integral()<<endl;
        cout<<"DY " <<hDY->Integral()<<endl;
        cout<<"ZTauTau " <<hZTauTau->Integral()<<endl;
        cout<<"FAKES " <<hFAKES->Integral()<<endl;
        cout<<"LFVGG126 " <<hLFVGG126->Integral()<<endl;
        cout<<"LFVVBF126 " <<hLFVVBF126->Integral()<<endl;

	stack->Draw("samehist");
	fullMC2->Draw("sames,E2");

        hLFVVBF126->Draw("sameshist");
        hLFVGG126->Draw("sameshist");

        double maxData=hdata_obs->GetMaximum();
        double maxMC=stack->GetMaximum()*1.2;
	double maxLFV=hLFVGG126->GetMaximum();
        double maxLFV2=hLFVVBF126->GetMaximum();
        double minMC=stack->GetMinimum();

        if(maxData>maxMC) {maxMC=1.2*maxData;}
	if(maxLFV>maxMC) {maxMC=1.2*maxLFV;}
        if(maxLFV2>maxMC) {maxMC=1.2*maxLFV2;}
	if(MAX!=-1) {maxMC=MAX;}

	stack->SetMaximum(maxMC);
	stack->GetYaxis()->SetRangeUser(minMC,maxMC);
        fullMC2->SetMaximum(maxMC);
        fullMC2->GetYaxis()->SetRangeUser(minMC,maxMC);

	if(setLogY){fullMC2->SetMinimum(0.1); fullMC2->GetYaxis()->SetRangeUser(1,maxMC*1000);}

        TH1F* histoDataUnblindedV4=hdata_obs->Clone(); histoDataUnblindedV4->SetName("data_unblinded");

        if(!blind) hdata_obs->Draw("sames");
        else {
                int findBinA=hdata_obs->FindBin(blindA);
                int findBinB=hdata_obs->FindBin(blindB);
                for (int i=findBinA; i<findBinB; i++) hdata_obs->SetBinContent(i,-1000);
                hdata_obs->Draw("sames");
                 TPave *pave = new TPave(blindA,minMC,blindB,maxMC,4,"br");
                   //pave->SetFillColorAlpha(kGray+3,0.35);
		   pave->SetFillColor(1);
                   pave->SetFillStyle(3003);
                   pave->SetDrawOption(0);
                   pave->SetBorderSize(0);
                   pave->Draw();

        }


   TLegend *leg = new TLegend(legx1,legy1,legx2,legy2,NULL,"brNDC");
   leg->SetFillColor(0);
   leg->SetBorderSize(0);
   leg->SetFillStyle(0);
   TLegendEntry *entry;
   entry=leg->AddEntry(hdata_obs,"Data, e#tau_{h}","p");
   entry=leg->AddEntry(fullMC2,"Bkgd. uncertainty","f");
   entry=leg->AddEntry(hSMHIGGS,"SM Higgs","f");
   eblindBy=leg->AddEntry(hZTauTau,"Z#rightarrow#tau#tau","f");
        entry=leg->AddEntry(hTOP,"t#bar{t}, t, #bar{t}","f");
        entry=leg->AddEntry(hDY,"Other","f");
   entry=leg->AddEntry(hFAKES,"MisID'd #tau","f");
   entry=leg->AddEntry(hLFVGG126,"LFV GG Higgs (B=100%)","l");
   entry=leg->AddEntry(hLFVVBF126,"LFV VBF Higgs (B=100%)","l");
   


   leg->Draw();


    CMS_lumi( Pad1, iPeriod, iPos );

    TLatex latex;
    latex.SetNDC();
    latex.SetTextAngle(0);
    latex.SetTextColor(kBlack);

    latex.SetTextFont(42);
    latex.SetTextAlign(31);
    latex.SetTextSize(.05);
    latex.DrawLatex(0.39,0.8,Tex);

   //cmsPrelim(Lumi);
	
        Pad1->SetLogy(setLogY);
	gPad->RedrawAxis();

        c1->cd(); TPad *Pad2= new TPad("pad2","",0,0,1,0.23); Pad2->Draw(); Pad2->cd();  Pad2->SetGridy();
        Pad2->SetLeftMargin(0.2147651);
        Pad2->SetRightMargin(0.06543624);
        Pad2->SetTopMargin(0.0);
        Pad2->SetBottomMargin(0.37);
        Pad2->SetFillStyle(0);



        TH1F * Ratio=fullMC2->Clone(); Ratio->SetName("Ratio");
	Ratio->Scale(-1);
	Ratio->Add(hdata_obs,1);
	Ratio->Divide(fullMC2);
	Ratio->SetLineColor(kBlack);

        Ratio->GetXaxis()->SetLabelFont(42);
        Ratio->GetXaxis()->SetTitleFont(42);
        Ratio->GetYaxis()->SetNdivisions(505);
        Ratio->GetYaxis()->SetLabelFont(42);
        Ratio->GetYaxis()->SetLabelSize(0.122);
        Ratio->GetYaxis()->SetRangeUser(ymin,ymax);
        Ratio->GetXaxis()->SetRangeUser(xmin,xmax);
        Ratio->GetXaxis()->SetLabelSize(0.12);
        Ratio->GetXaxis()->SetLabelFont(42);
        Ratio->SetYTitle("#frac{Data-Bkgd}{Bkgd}");
        Ratio->SetXTitle(Xaxis);
        Ratio->GetXaxis()->SetNdivisions(505);
        Ratio->GetYaxis()->CenterTitle(true);
        Ratio->GetYaxis()->SetTitleOffset(0.4);
        Ratio->GetYaxis()->SetTitleSize(0.11);
        Ratio->GetXaxis()->SetTitleOffset(0.75);
        Ratio->GetXaxis()->SetTitleSize(0.20);
        Ratio->SetMarkerSize(1.);


        TH1F* RatioError = Ratio->Clone(); RatioError->SetName("RatioError");

        for (int i=0; i<RatioError->GetNbinsX()+1; i++){
                        double error=fullMC2->GetBinError(i)*hdata_obs->GetBinContent(i)/fullMC2->GetBinContent(i)/fullMC2->GetBinContent(i);
                        RatioError->SetBinContent(i,0);
                        RatioError->SetBinError(i,error);
        }
        //RatioError->SetFillStyle(3002); 
        RatioError->SetFillColorAlpha(kGray+2,0.35); RatioError->SetMarkerSize(0);  
        RatioError->Draw("E2");
	//Ratio->Draw("samesE0"); //errorbarswithoutdatapoints
        Ratio->Draw("sames");

        if(!blind) Ratio->Draw("sames");
        else {
                int findBinA=Ratio->FindBin(blindA);
                int findBinB=Ratio->FindBin(blindB);
                for (int i=findBinA; i<findBinB; i++) Ratio->SetBinContent(i,-100);
                Ratio->Draw("sames");

                   TPave *pave = new TPave(blindA,-1.0,blindB,1.0,4,"br");
                   pave->SetFillColor(1);
                   pave->SetFillStyle(3003);
		   //pave->SetFillColorAlpha(kGray+3,0.35);
                   pave->SetDrawOption(0);
                   pave->SetBorderSize(0);
                   pave->Draw();
        }

       if(!setLogY){	
       	//	c1->SaveAs(name+"ErrorBarsWithoutDataPoints.png");
       	//	c1->SaveAs(name+"ErrorBarsWithoutDataPoints.pdf");
              c1->SaveAs(name+".png");
              c1->SaveAs(name+".pdf");

	}
	else {
       		c1->SaveAs(name+"_log.png");
       		c1->SaveAs(name+"_log.pdf");
        }  

}
Exemplo n.º 3
0
void Draw(TString name, TString histotitle, bool log, int move_legend)

{

 
 TH1F* hist_b;
 TH1F* hist_c;
 TH1F* hist_gsplit;
 TH1F* hist_l;
 TH1F* hist_data;
 
 
 TFile *myFile     = new TFile(filename);
 
 myFile->cd();
 hist_b         = (TH1F*)gROOT->FindObject(name+"_b");
 hist_c         = (TH1F*)gROOT->FindObject(name+"_c");
 hist_gsplit    = (TH1F*)gROOT->FindObject(name+"_bfromg");
 hist_l         = (TH1F*)gROOT->FindObject(name+"_l");
 hist_data      = (TH1F*)gROOT->FindObject(name+"_data");
 

 if (bOverflow && name!="SSV" && name!="SSVHP") {
  OverFlowBinFix(hist_b);
  OverFlowBinFix(hist_c);
  OverFlowBinFix(hist_gsplit);
  OverFlowBinFix(hist_l);
  OverFlowBinFix(hist_data);
 }



 TH1F* histo_tot = (TH1F*) hist_b->Clone();
 histo_tot->Sumw2();
 histo_tot ->Add(hist_c);
 histo_tot ->Add(hist_gsplit);
 histo_tot ->Add(hist_l);  

 

 float scale_f = (hist_data->Integral())/(hist_b->Integral() + hist_c ->Integral()+ hist_gsplit->Integral() + hist_l->Integral());

 hist_b       ->Scale(scale_f);
 hist_c       ->Scale(scale_f);
 hist_gsplit  ->Scale(scale_f);
 hist_l       ->Scale(scale_f);
 histo_tot    ->Scale(scale_f);
  
 double titleoffsety=0.2;
 double titlesizex=0.17;
 double titlesizey=0.2;
 double labelsizex=0.14;
 double labelsizey=0.12; 
  
   
 hist_data  ->GetYaxis()->SetLabelSize(labelsizey);
 hist_data  ->GetYaxis()->SetTitleSize(titlesizey);
 hist_data  ->GetYaxis()->SetTitleOffset(titleoffsety);
  
 hist_b     ->GetYaxis()->SetLabelSize(labelsizey);
 hist_b     ->GetYaxis()->SetTitleSize(titlesizey);
 hist_b     ->GetYaxis()->SetTitleOffset(titleoffsety);
  
 TH1F* histo_ratio;
 histo_ratio = (TH1F*) hist_data->Clone();
 histo_ratio->SetName("histo_ratio");
 histo_ratio->SetTitle("");
  
 histo_ratio->Divide(histo_tot);
  
 hist_data  ->SetLineWidth(2);
 hist_data  ->SetMarkerStyle(20);  
 hist_data  ->SetMarkerSize(0.75); 

 hist_c     ->SetFillColor(8);
 hist_b     ->SetFillColor(2);
 hist_gsplit->SetFillColor(7);
 hist_l     ->SetFillColor(4);
  
 histo_tot  ->SetLineColor(2);
  

 THStack *stack = new THStack("stack","stack");
  
 if (b_ordering){
  stack      ->Add(hist_b);
  stack      ->Add(hist_gsplit);
  stack      ->Add(hist_c);
  stack      ->Add(hist_l);
 }
 else {
  stack      ->Add(hist_l);
  stack      ->Add(hist_c);
  stack      ->Add(hist_gsplit);
  stack      ->Add(hist_b);
 }


 gStyle->SetOptTitle(0);
 gStyle->SetOptStat(0);  
 //gStyle->SetLogy(log);
  
 TCanvas *c1 = new TCanvas("c1", "c1",10,32,782,552);
 c1->SetFillColor(10);
 c1->  cd();   
  

 TPad* canvas_1 = new TPad("canvas_1", "canvas_1",0,0.25,1.0,0.98);
 canvas_1 ->Draw();
 canvas_1 ->cd();
 
 canvas_1->SetLogy(log);
 
 if (hist_data->GetMaximum() > stack->GetMaximum() ) stack->SetMaximum( hist_data->GetMaximum()*1.1) ;

 float xmov=1;
 if (move_legend==2) {
    if (log)  xmov=5;
    else xmov=1.1;
    stack->SetMaximum( xmov*stack->GetMaximum() ) ;
 }
 
 if (stack->GetMinimum()> hist_l->GetMinimum()) {
   if (log && hist_l->GetMinimum()>0.) stack->SetMinimum(hist_l->GetMinimum());
   else if (!log) stack->SetMinimum(hist_l->GetMinimum());
 }

 stack    ->Draw("hist");  
  
 stack    ->GetHistogram()->GetXaxis()->SetTitle(name);
 stack    ->GetHistogram()->GetYaxis()->SetTitle("entries");

 stack    ->GetHistogram()->SetTitleSize(0.08,"Y");
 stack    ->GetHistogram()->SetTitleOffset(0.65,"Y"); 

 hist_data->Draw("same e");

// TLegend* qw =  new TLegend(0.54,0.63,0.88,0.9);
 TLegend* qw;
 if (move_legend==1) {
   qw =  new TLegend(0.35,0.15,0.70,0.42);
 }
 else if (move_legend==3) {
  qw =  new TLegend(0.35,0.63,0.70,0.90);
 }
 else qw =  new TLegend(0.6,0.73,0.95,1.);
  
  //Legend
 qw->AddEntry(hist_data,     "e#mu ttbar data",                       "p");
 qw->AddEntry(hist_b,        "b quark"           ,         "f");
 qw->AddEntry(hist_gsplit,   "b from gluon splitting"     ,"f");
 qw->AddEntry(hist_c,        "c quark"           ,         "f");
 qw->AddEntry(hist_l,        "uds quark or gluon"     ,    "f");

 
 qw->SetFillColor(0);
 qw->Draw();
  
  
 TLatex *latex = new TLatex();
 latex->SetNDC();
 latex->SetTextSize(0.055);
 latex->SetTextFont(42); //22

 latex->SetTextAlign(13);
 latex->DrawLatex(0.08, 0.96, title);


 c1->cd();  
  
 TPad* canvas_2 = new TPad("canvas_2", "canvas_2",0,0.,1.0,0.32);
 canvas_2->Draw();
 canvas_2->cd();
 gPad->SetBottomMargin(0.375);
 gPad->SetGridy();
  
 histo_ratio->SetMarkerStyle(20);
 histo_ratio->SetMarkerSize(0.75);
 histo_ratio->SetLineWidth(2);
 
 histo_ratio->GetYaxis()->SetTitle("Data/MC");
 histo_ratio->GetXaxis()->SetTitle(histotitle);
 histo_ratio->GetYaxis()->SetNdivisions( 505 );

 histo_ratio->GetXaxis()->SetLabelSize( labelsizex);
 histo_ratio->GetXaxis()->SetTitleSize( titlesizex );

 histo_ratio->SetMinimum(0.4);
 histo_ratio->SetMaximum(1.6);
 histo_ratio->Draw("E1X0");

 c1->cd();  
  
 TString name_plot=name+"_Linear"+format; 
 if(log) name_plot=name+"_Log"+format;
 c1->SaveAs("Commissioning_plots/"+name_plot);

 if (log && web) {  // save also _Linear for web
 canvas_1 ->cd();
 canvas_1->SetLogy(false);
 if (xmov==5) {
    stack->SetMaximum( 1.1*stack->GetMaximum() ) ;
 }
 c1->cd();  
 c1->SaveAs("Commissioning_plots/"+name+"_Linear"+format);
   
 }

}
Exemplo n.º 4
0
// *************************************** //
// this is a function that takes a set of  //
// histograms and draws them on a canvas   //
// in a stack, returning the canvas.       //
// It also plots the signal as a dashed    //
// line and the data with a ratio at the   //
// the bottom of data/allBackgrounds       //
// *************************************** //
TCanvas* drawPlots::plotAll(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, TH1D* signal, TH1D* data, TH1D* errDown, TH1D* errUp, bool isSignalRegion, bool doLogAxis){
         
   const unsigned int MAINPLOT_WIDTH  = 800;
   const unsigned int MAINPLOT_HEIGHT = 500;
   const unsigned int RATIOPLOT_HEIGHT = 125;
   const unsigned int OFFSET = 10;
   
  //LUKE: Title offset and title size are proportional in 
  //root, so you have to change them together, 
  //this makes me a sad panda 
   const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.4;
   const double RATIOPLOT_YAXIS_TITLE_SIZE   = 0.14;
   const double RATIOPLOT_YAXIS_TICK_LENGTH  = 0.01;
   const double RATIOPLOT_YAXIS_LABEL_SIZE   = 0.15;
  
   const double RATIOPLOT_XAXIS_TITLE_OFFSET = 0.9;
   const double RATIOPLOT_XAXIS_TITLE_SIZE   = 0.2;
   const double RATIOPLOT_XAXIS_TICK_LENGTH  = 0.05;
   const double RATIOPLOT_XAXIS_LABEL_SIZE   = 0.2;
   
   const double CANVAS_HEIGHT = MAINPLOT_HEIGHT+RATIOPLOT_HEIGHT+OFFSET;
   
   TCanvas* canvas = new TCanvas("canvas","canvas",0,0,MAINPLOT_WIDTH,CANVAS_HEIGHT);
   
   canvas->SetMargin(0.,0.,0.,0.);
   canvas->Clear();
   canvas->cd();
   
   // create main pad
   const double mainPad_ylow  = (CANVAS_HEIGHT - MAINPLOT_HEIGHT)/CANVAS_HEIGHT;
   const double mainPad_yhigh = 1.;
  
   const double pad_margin_left = 0.15;
   const double pad_margin_right  = 0.05;
   
   double main_y_max = -99;
   double main_y_min = -99;
   double main_x_max = -99;
   double main_x_min = -99;
   for(int a=0; a<histos.size(); a++){
     if(histos[a]){
       if(histos[a]->GetEntries()> 0.){
	 GetAxisLimits(histos[a], main_x_min, main_x_max, main_y_min, main_y_max);
       }
     }
   }
   
   if(data){
     int maxBinData = data->GetMaximumBin();
     double dataYmax = data->GetBinContent(maxBinData);
     if(dataYmax > main_y_max) main_y_max = dataYmax;
   }

   // create main pad
   TPad* mainPad = new TPad("main","main",0.,mainPad_ylow,1.,mainPad_yhigh);
   mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top
   mainPad->Draw();
   mainPad->cd();

   SetAtlasStyle();

   if(doLogAxis)mainPad->SetLogy();

   // clone signal or data because one should exist for each plot
   TH1D* allBackgrounds;
   bool gotSomething=false;
   if(signal)
     allBackgrounds = (TH1D*)signal->Clone("all_backgrounds");
   else if(data)
     allBackgrounds = (TH1D*)data->Clone("all_backgrounds");
   else{
     for(int b=0; b<histos.size(); b++){
       if(histos[b] && !gotSomething){
	 allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds");
	 gotSomething=true;
       }
     }  
   }

   // set all bins to zero so that you can add all histograms to it
   for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++)
      allBackgrounds->SetBinContent(i,0);
   
   THStack* Stack = new THStack();
   std::string title = std::string(";") + axisName + ";Events";
   Stack->SetTitle(title.c_str());
   
   for(int b=0; b<histos.size(); b++){
     if(histos[b]){
       if(histos[b]->GetEntries() > 0.){
	 histos[b]->SetLineColor(1);
	 histos[b]->SetFillColor(tools::setColor(names[b]));
	 Stack->Add(histos[b]);
	 for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){
	   double binContent=allBackgrounds->GetBinContent(j)+histos[b]->GetBinContent(j);
	   allBackgrounds->SetBinContent(j,binContent);
	 }
       }
     }
   }

   TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio");
   
   if(doLogAxis){ 
     main_y_max = main_y_max*10;
     if(Stack->GetMinimum()>.1) Stack->SetMinimum(.1);
   }
   else main_y_max = main_y_max*1.4;
   Stack->SetMaximum(main_y_max);
   Stack->Draw("hist");
   errDown->Draw("E2same");
   errUp->Draw("E2Same");
   
   // make error histograms for the ratio plot
   TH1D* ratioErrDown = (TH1D*) errDown->Clone("ratio_error_down");
   TH1D* ratioErrUp = (TH1D*) errUp->Clone("ratio_error_up");

   ratioErrDown->Divide(backgroundsForRatio);
   ratioErrUp->Divide(backgroundsForRatio);

   if(!isSignalRegion && data)
      data->Draw("e same");

   if(signal){
     signal->SetLineStyle(2);
     signal->SetLineColor(kRed);
     signal->SetLineWidth(5);
     signal->Draw("hist same");
   }

   TLegend* leg = new TLegend(0.8,0.65,0.95,0.9);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   
   if(signal)
     leg->AddEntry(signal, "Signal", "l");
   if(!isSignalRegion)
     leg->AddEntry(data, "Data");
   for(int q=0; q<histos.size(); q++){
     if(histos[q]){
       if(histos[q]->GetEntries() > 0.)
	 leg->AddEntry(histos[q], names[q].c_str(), "f");
     }
   }
   leg->Draw("lpe");
   
   ATLAS_LABEL(0.2,0.85,1);
   char text[]="#sqrt{s}=8 TeV";
   myText(0.6,0.75,1,.04, text);
   char text_L[]="#int L dt = 20.3 fb^{-1}";
   myText(0.6, 0.85,1, .04, text_L);
   char inText[100];
   int t;
   if(signal)
     t=sprintf(inText, "N_{Signal} = %.1f", signal->Integral(0,signal->GetNbinsX()+1));
   else
     t=sprintf(inText, "N_{Signal} = %.1f", 0.);
   myText(0.2, 0.75, 1, .04, inText);
   double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1);
   if(back_int > 10000.)
     t=sprintf(inText, "N_{Bkgd} = %.3e", back_int);
   else
     t=sprintf(inText, "N_{Bkgd} = %.1f", back_int);
   myText(0.2, 0.7, 1, .04, inText);
   if(!isSignalRegion){
     if(data)
       t=sprintf(inText, "N_{Data} = %.0f", data->Integral(0,data->GetNbinsX()+1));
     else
       t=sprintf(inText, "N_{Data} = %.0f", 0.);
     myText(0.2, 0.65, 1, .04, inText);
   }
   
   canvas->cd();
   
   // Draw Ratio plot
   double ratio_max = 1.6;
   double ratio_min = 0.4;
  
   const double x_axis_size = 0.4;
   const double ratio_pad_height = RATIOPLOT_HEIGHT/CANVAS_HEIGHT;
   
   double pad_xlow = 0.,pad_xhigh = 1.;
   double pad_ylow = OFFSET/CANVAS_HEIGHT,pad_yhigh = ratio_pad_height;
   
   const char* pad_name = "pad";
   TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh);
   
   pad4ratio->SetMargin(pad_margin_left,pad_margin_right,x_axis_size,0.);
   pad4ratio->Draw();
   pad4ratio->cd();

   TH1D* ratioPlot;
   if(data) ratioPlot = (TH1D*)data->Clone("ratio");
   else if(signal) ratioPlot = (TH1D*)signal->Clone("ratio"); // if there is no data then use signal for axis 
   ratioPlot->SetTitle("");
   ratioPlot->GetYaxis()->SetTitle("Data/MC");
   ratioPlot->GetXaxis()->SetTitle(axisName.c_str());
   if(data){
     ratioPlot->Divide(allBackgrounds);
     // here change ratio_min and ratio_max if the ratio plot is quite flat
     double maxDeviation=0;
     double tempDev=0;
     for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){
       tempDev = std::abs(ratioPlot->GetBinContent(ibin)-1.);
       if(tempDev > maxDeviation) maxDeviation = tempDev;
     }
     if(maxDeviation < 0.1){
       ratio_max = 1.12;
       ratio_min = 0.88;
     }
     else if(maxDeviation < 0.2){
       ratio_max = 1.25;
       ratio_min = .75;
     }
     ratioPlot->SetMinimum(ratio_min);
     ratioPlot->SetMaximum(ratio_max);
   }
   ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE);
   ratioPlot->GetXaxis()->SetTickLength(RATIOPLOT_XAXIS_TICK_LENGTH);
   ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE);
   ratioPlot->GetYaxis()->SetTickLength(RATIOPLOT_YAXIS_TICK_LENGTH);
   ratioPlot->GetYaxis()->SetNdivisions(3);
   ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE);
   ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET);
   ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE);
   ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET);
   
   if(!isSignalRegion && data){
     ratioPlot->Draw();
     // plot horizontal line at y=1
     TF1* horizontal = new TF1("horizontal","pol1",-10000,10000);
     horizontal->SetParameter(0,1.);
     horizontal->SetParameter(1,0.);
     horizontal->SetLineColor(kBlack);
     horizontal->SetLineStyle(2);
     horizontal->SetLineWidth(1);
     horizontal->Draw("same");
     ratioErrDown->Draw("E2same");
     ratioErrUp->Draw("E2same");
   }else if(isSignalRegion){
     ratioPlot->Draw("axis");
     char text[]="DATA IS BLINDED HERE";
     myText(0.4,0.6,1,.2,text);
   }else{ // in this case it is not the signal region but there is no data
     ratioPlot->Draw("axis");
     char text[]="NO DATA";
     myText(0.4,0.6,1,.2,text);
     }
   
   return canvas;
}
Exemplo n.º 5
0
THStack* BasePlot::GetStack(bool isLog)  {
    THStack* hstack = new THStack();

    float binWidth = 0;
    for (int i=0; i<nSamples; i++) if( _hist[i] && i != iHWW) {

        _hist[i]->SetLineColor(sampleColor[i]);
        _hist[i]->SetFillColor(sampleColor[i]);
        _hist[i]->SetFillStyle(1001);
        binWidth = _hist[i]->GetBinWidth(1);

        hstack->Add(_hist[i]);
    }

    for (size_t i=0; i<_autreHists.size(); i++) {

        _autreHists[i].second->SetLineColor(autreColors[i]);
        _autreHists[i].second->SetFillColor(autreColors[i]);
        _autreHists[i].second->SetFillStyle(1001);

        hstack->Add(_autreHists[i].second);
    }


    hstack->Draw("GOFF");
    if(_prelim) hstack->SetTitle("CMS preliminary");
    else        hstack->SetTitle("CMS, #sqrt{s} = 7 TeV");

    Float_t theMax = hstack->GetMaximum();
    Float_t theMin = hstack->GetMinimum();

    if (_hist[iHWW]) {
        if (_hist[iHWW]->GetMaximum() > theMax) theMax = _hist[iHWW]->GetMaximum();
        if (_hist[iHWW]->GetMinimum() < theMin) theMin = _hist[iHWW]->GetMinimum();
    }

    if (_data) {
        Float_t dataMax = GetMaximumIncludingErrors(_data);
        if (dataMax > theMax) theMax = dataMax;
    }

    int sampCount = GetSampCount();
    float scaleBy = 1.35 + 0.2*(sampCount>6) + 0.2*(sampCount>10) + 0.2*(sampCount>14);

    // Min --- only need to change if log
    theMin = theMin==0?0.1:theMin/10;
    if(isLog) hstack->SetMinimum(theMin);

    // Max
    if (_myMax != -1) {
        hstack->SetMaximum(_myMax);
    } else if (isLog) {
        hstack->SetMaximum(pow(10,(log(theMax)/log(10)-log(theMin)/log(10)+1)*scaleBy+log(theMin)/log(10)-1));
    } else {
        hstack->SetMaximum(scaleBy * theMax);
    }


    if(_breakdown) {
        THStackAxisFonts(hstack, "y", "entries");
        hstack->GetHistogram()->LabelsOption("v");
    } else {
        THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
        THStackAxisFonts(hstack, "y", TString::Format("entries / %.1f %s", binWidth,_units.Data()));
        if(_units.Sizeof() == 1) {
            THStackAxisFonts(hstack, "x", _xLabel.Data());
//            THStackAxisFonts(hstack, "y", "entries");
        }
    }
    return hstack;
}
void postFitPlotsCOMBINEINSERT(TString name="collMass",TString fileDataMuHad0Jet="asdf", TString fileDataMuHad1Jet = "asdf", TString fileDataMuHad2Jet = "asdf", TString fileDataMuEle0Jet = "asdf", TString fileDataMuEle1Jet = "asdf", TString fileDataMuEle2Jet = "asdf", TString file="fit2_signalV5_collMass_type1.root", TString dirInternal="filesBoosted", TString Xaxis="M_{#mu,#tau}_{coll} [GeV]", TString Yaxis="Events / 20 GeV", double xmin=200, double xmax=300, double ymin=-2, double ymax=2, bool setLogY=false, double legx1=0.6, double legy1=0.9, double legx2=0.9, double legy2=0.5, double MAX=-1, double MIN=-1, bool mutau0=true, bool mutau1=true, bool mutau2=true, bool muele0=true, bool muele1=true, bool muele2=true, bool REBIN=true, bool weightSOverSB=true,TString channelName="#mu#tau", double minsubs=-1, double maxsubs=-1){


	gROOT->LoadMacro("tdrstyle.C");
	setTDRStyle();
	double kForPlotting=1;
	double branchingratioTauTau=0.063;
	double branchingratioTauMu=0.1;
	double Lumi=19717;

	gROOT->LoadMacro("CMS_lumi.C");
	writeExtraText = false;
	int iPeriod = 2;
	// second parameter in example_plot is iPos, which drives the position of the CMS logo in the plot
	int iPos=11;// : top-left, left-aligned
	// iPos=33 : top-right, right-aligned
	// iPos=22 : center, centered
	// mode generally :
	//   iPos = 10*(alignement 1/2/3) + position (1/2/3 = left/center/right)
	//  example_plot( iPeriod, 11 );  // left-aligned
	//  example_plot( iPeriod, 33 );  // right-aligned
	//  example_plot( iPeriod, 0 );   // out of frame (in exceptional cases)
	//  example_plot( iPeriod, 11 );  // default: left-aligned
	//  example_plot( iPeriod, 22 );  // centered
	//  example_plot( iPeriod, 33 );  // right-aligned


	bool muonchannels[3]={mutau0,mutau1,mutau2};
	bool elechannels[3]={muele0,muele1,muele2};

	int NBins=30; 
	if(mutau2 || muele2 || REBIN) { REBIN=true; NBins=15;}

	TFile *_fileMC= new TFile("CombinedPlots20PAS/"+file);
	TFile *_fileDataMuHad0Jet= new TFile("CombinedPlots20PAS/"+fileDataMuHad0Jet);
        TFile *_fileDataMuHad1Jet= new TFile("CombinedPlots20PAS/"+fileDataMuHad1Jet);
        TFile *_fileDataMuHad2Jet= new TFile("CombinedPlots20PAS/"+fileDataMuHad2Jet);
        TFile *_fileDataMuEle0Jet= new TFile("CombinedPlots20PAS/"+fileDataMuEle0Jet);
        TFile *_fileDataMuEle1Jet= new TFile("CombinedPlots20PAS/"+fileDataMuEle1Jet);
        TFile *_fileDataMuEle2Jet= new TFile("CombinedPlots20PAS/"+fileDataMuEle2Jet);


	//TString dirInternalAllMU[3]={dirInternal+"/datacard_gg0_pfMetFixOldjesNewFakeShape",dirInternal+"/datacard_gg1_pfMetFixOldjesNewFakeShape", dirInternal+"/datacard_vbf20_pfMetFixOldjesNewFakeShape"};
        TString dirInternalAllMU[3]={dirInternal+"/datacard_MuTau_0Jet_new",dirInternal+"/datacard_MuTau_1Jet_new", dirInternal+"/datacard_vbf_PAS20"};
	TString dirInternalAllELE[3]={dirInternal+"/datacard_MuEle_0Jet",dirInternal+"/datacard_MuEle_1Jet", dirInternal+"/datacard_MuEle_2Jet"};

	TString dirInternalSignal="shapes_prefit";

	TH1F* hdata_obs = new TH1F("hdata_obs","",NBins,0,300);
	TH1F* hFAKES = new TH1F("hFAKES","",NBins,0,300);
	TH1F* hFAKESLEPTON = new TH1F("hFAKESLEPTON","",NBins,0,300);
	TH1F* hDY = new TH1F("hDY","",NBins,0,300);
	TH1F* hWW = new TH1F("hWW","",NBins,0,300);
	TH1F* hTOP = new TH1F("hTOP","",NBins,0,300);
	TH1F* hTT = new TH1F("hTT","",NBins,0,300);
	TH1F* hZTauTau = new TH1F("hZTauTau","",NBins,0,300);
	TH1F* hLFVVBF126 = new TH1F("hLFVVBF126","",NBins,0,300);
	TH1F* hSMVBF126 = new TH1F("hSMVBF126","",NBins,0,300);
	TH1F* hSMHWWVBF126 = new TH1F("hSMHWWVBF126","",NBins,0,300);
	TH1F* hLFVGG126 = new TH1F("hLFVGG126","",NBins,0,300);
	TH1F* hSMGG126 = new TH1F("hSMGG126","",NBins,0,300);
	TH1F* hSMHWWGG126 = new TH1F("hSMHWWGG126","",NBins,0,300);
	TH1F* hWGamma = new TH1F("hWGamma","",NBins,0,300);
	TH1F* hWGammaStar = new TH1F("hWGammaStar","",NBins,0,300);

	double weightMuTau[3]={1,1,1};
	double weightMuEle[3]={1,1,1};

	int binA=hdata_obs->FindBin(100);
	int binB=hdata_obs->FindBin(150);

	for (int i=0; i<3; i++){
		cout << "starting" << i <<endl;
		if(muonchannels[i]!=true) continue;
		TH1F *hFAKES_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/fakes");hFAKES_2->SetName("fakesHisto");
		TString Extra="/zjetsother";
		if(i==2) Extra="/fakes"; // in the postfit directory the DY for VBF is not saved, since it has 0 events
		TH1F *hDY_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+Extra); hDY_2->SetName("dyHisto");
		TH1F *hWW_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/ww");
		TH1F *hTOP_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/singlet");
		TH1F *hTT_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/ttbar");
		TH1F *hZTauTau_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/ztautau");
		TH1F *hLFVVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/LFVVBF");
		TH1F *hLFVGG126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/LFVGG");
		TH1F *hSMGG126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/SMGG126");
		TH1F *hSMVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/SMVBF126");
		Extra="/fakes";
		if(i!=0) Extra="/WWGG126";
		TH1F *hSMHWWGG126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+Extra); hSMHWWGG126_2->SetName("smwwgg");
		if(i==0) hSMHWWGG126_2->Scale(0);
		TH1F *hSMHWWVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/WWVBF126"); hSMHWWVBF126_2->SetName("wwsm");
		cout << "got histos" << endl;
		if(i!=2 && (REBIN)) {
			hFAKES_2->Rebin(2); hDY_2->Rebin(2); hWW_2->Rebin(2); hTOP_2->Rebin(2); hTT_2->Rebin(2); hZTauTau_2->Rebin(2);
			hLFVVBF126_2->Rebin(2); hLFVGG126_2->Rebin(2); hSMGG126_2->Rebin(2); hSMVBF126_2->Rebin(2);
			hSMHWWVBF126_2->Rebin(2);
			if(i!=0) hSMHWWGG126_2->Rebin(2);
		}

		// WEIGHT	
		double bckg=hWW_2->Integral(binA,binB)+hFAKES_2->Integral(binA,binB) + hTOP_2->Integral(binA,binB) + hTT_2->Integral(binA,binB) + hZTauTau_2->Integral(binA,binB);
		bckg+=hSMVBF126_2->Integral(binA,binB)+hSMGG126_2->Integral(binA,binB)+hSMHWWVBF126_2->Integral(binA,binB);
		if(i!=2) bckg+=hDY_2->Integral(binA,binB);
		else hDY_2->Scale(0);
		if(i!=0) bckg+=hSMHWWGG126_2->Integral(binA,binB);
		else hSMHWWGG126_2->Scale(0);

		double signal=hLFVGG126_2->Integral(binA,binB)+hLFVVBF126_2->Integral(binA,binB);

		weightMuTau[i]=signal/(signal+bckg);
		cout<<"Weighting MuTau Channel  "<<i<<" --> "<<weightMuTau[i]<<endl;

		if(weightSOverSB){
			hFAKES_2->Scale(weightMuTau[i]);
			hDY_2->Scale(weightMuTau[i]);
			hWW_2->Scale(weightMuTau[i]);
			hTOP_2->Scale(weightMuTau[i]);
			hTT_2->Scale(weightMuTau[i]);
			hZTauTau_2->Scale(weightMuTau[i]);
			hLFVVBF126_2->Scale(weightMuTau[i]);
			hLFVGG126_2->Scale(weightMuTau[i]);
			hSMVBF126_2->Scale(weightMuTau[i]);
			hSMGG126_2->Scale(weightMuTau[i]);
			hSMHWWVBF126_2->Scale(weightMuTau[i]);
			hSMHWWGG126_2->Scale(weightMuTau[i]);
		}

		// MERGE

		fillNewHisto(hFAKES,hFAKES_2);
		if(i!=2) fillNewHisto(hDY,hDY_2);
		fillNewHisto(hWW,hWW_2);
		fillNewHisto(hTOP,hTOP_2);
		fillNewHisto(hTT,hTT_2);
		fillNewHisto(hZTauTau,hZTauTau_2);
		fillNewHisto(hLFVVBF126,hLFVVBF126_2);
		fillNewHisto(hLFVGG126,hLFVGG126_2);
		fillNewHisto(hSMVBF126,hSMVBF126_2);
		fillNewHisto(hSMGG126,hSMGG126_2);
		fillNewHisto(hSMHWWVBF126,hSMHWWVBF126_2);
		if(i!=0) fillNewHisto(hSMHWWGG126,hSMHWWGG126_2);

	}

	for (int i=0; i<3; i++){
		if(elechannels[i]!=true) continue;

		TH1F *hFAKESLEPTON_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/Fakes"); hFAKESLEPTON_2->SetName("hFAKESLEPTON_2");
		TString Extra="/DYnoTauTau";
		if(i==2) Extra="/Fakes"; // in the postfit directory the DY for VBF is not saved, since it has 0 events
		TH1F *hDY_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+Extra);
		TH1F *hWW_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/WW");
		Extra="/WG";
		if(i!=1) Extra="/Fakes";
		TH1F *hWGamma_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+Extra); hWGamma_2->SetName("hWGamma_2");
		Extra="/WGStar";
		if(i==2) Extra="/Fakes";
		TH1F *hWGammaStar_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+Extra); hWGammaStar_2->SetName("hWGammaStar_2");
		TH1F *hTOP_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/TOP");
		TH1F *hTT_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/TT");
		TH1F *hZTauTau_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/ZTauTau");
		TH1F *hLFVVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/LFVVBF");
		TH1F *hLFVGG126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/LFVGG");
		TH1F *hSMGG126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/ggHTauTau");
		TH1F *hSMVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/vbfHTauTau");
		TH1F *hSMHWWGG126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/ggHWW");
		TH1F *hSMHWWVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/vbfHWW");

		if(i!=2 && (REBIN)) {
			hFAKESLEPTON_2->Rebin(2); hDY_2->Rebin(2); hWW_2->Rebin(2); hTOP_2->Rebin(2); hTT_2->Rebin(2); hZTauTau_2->Rebin(2);
			hLFVVBF126_2->Rebin(2); hLFVGG126_2->Rebin(2); hSMGG126_2->Rebin(2); hSMVBF126_2->Rebin(2);
			hSMHWWGG126_2->Rebin(2); hSMHWWVBF126_2->Rebin(2);
			hWGamma_2->Rebin(2); hWGammaStar_2->Rebin(2);
		}


		// WEIGHT       
		double bckg=hWW_2->Integral(binA,binB)+hFAKESLEPTON_2->Integral(binA,binB) + hTOP_2->Integral(binA,binB) + hTT_2->Integral(binA,binB) + hZTauTau_2->Integral(binA,binB);
		bckg+=hSMVBF126_2->Integral(binA,binB)+hSMGG126_2->Integral(binA,binB)+hSMHWWVBF126_2->Integral(binA,binB)+hSMHWWGG126_2->Integral(binA,binB);
		if(i!=2) {bckg+=hDY_2->Integral(binA,binB)+hWGammaStar_2->Integral(binA,binB);}
		else {hDY_2->Scale(0); hWGammaStar_2->Scale(0);}
		if (i==1) bckg+=hWGamma_2->Integral();
		else hWGamma_2->Scale(0);

		double signal=hLFVGG126_2->Integral()+hLFVVBF126_2->Integral();

		weightMuEle[i]=signal/(signal+bckg);
		cout<<"Weighting MuEle Channel  "<<i<<" --> "<<weightMuEle[i]<<endl;

		if(weightSOverSB){
			hFAKESLEPTON_2->Scale(weightMuEle[i]);
			hDY_2->Scale(weightMuEle[i]);
			hWW_2->Scale(weightMuEle[i]);
			hTOP_2->Scale(weightMuEle[i]);
			hTT_2->Scale(weightMuEle[i]);
			hZTauTau_2->Scale(weightMuEle[i]);
			hWGamma_2->Scale(weightMuEle[i]);
			hWGammaStar_2->Scale(weightMuEle[i]);
			hLFVVBF126_2->Scale(weightMuEle[i]);
			hLFVGG126_2->Scale(weightMuEle[i]);
			hSMVBF126_2->Scale(weightMuEle[i]);
			hSMGG126_2->Scale(weightMuEle[i]);
			hSMHWWVBF126_2->Scale(weightMuEle[i]);
			hSMHWWGG126_2->Scale(weightMuEle[i]);
		}

		fillNewHisto(hFAKESLEPTON,hFAKESLEPTON_2);
		if(i!=2) fillNewHisto(hDY,hDY_2);
		fillNewHisto(hWW,hWW_2);
		if(i!=2) fillNewHisto(hWGammaStar,hWGammaStar_2);
		if(i==1) fillNewHisto(hWGamma,hWGamma_2);
		fillNewHisto(hTOP,hTOP_2);
		fillNewHisto(hTT,hTT_2);
		fillNewHisto(hZTauTau,hZTauTau_2);
		fillNewHisto(hLFVVBF126,hLFVVBF126_2);
		fillNewHisto(hLFVGG126,hLFVGG126_2);
		fillNewHisto(hSMVBF126,hSMVBF126_2);
		fillNewHisto(hSMGG126,hSMGG126_2);
		fillNewHisto(hSMHWWVBF126,hSMHWWVBF126_2);
		fillNewHisto(hSMHWWGG126,hSMHWWGG126_2);



	}



	TString dirInternalDataAllMU[3]={"gg0mutau","boostmutau","vbfmutau"};

	for (int i=0; i<3; i++){
		cout << "starting data" <<endl;
		if(muonchannels[i]!=true) continue;
		if(i == 0){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuHad0Jet->Get(dirInternalDataAllMU[i]+"/data_obs");
		}
		else if (i  == 1){
		  TH1F *hdata_obs_2=(TH1F*)_fileDataMuHad1Jet->Get(dirInternalDataAllMU[i]+"/data_obs");
		}
		else if (i == 2){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuHad2Jet->Get(dirInternalDataAllMU[i]+"/data_obs");
                }
		cout << "declared histos" << endl;
		//TH1F *hdata_obs_2=(TH1F*)_fileData->Get(dirInternalDataAllMU[i]+"/data_obs");
		hdata_obs_2->SetName("hdata_obs_2");
		if(weightSOverSB) hdata_obs_2->Scale(weightMuTau[i]);
		if(i!=2 && (REBIN)) hdata_obs_2->Rebin(2);
		cout << "filling data histo" << endl;
		fillNewHisto(hdata_obs,hdata_obs_2);
	}

	TString dirInternalDataAllELE[3]={"GGF","Boost","VBF"};

	for (int i=0; i<3; i++){
		if(elechannels[i]!=true) continue;
                if(i == 0){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuEle0Jet->Get(dirInternalDataAllELE[i]+"/data_obs");
                }
                else if (i  == 1){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuEle1Jet->Get(dirInternalDataAllELE[i]+"/data_obs");
                }
                else if (i == 2){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuEle2Jet->Get(dirInternalDataAllELE[i]+"/data_obs");
                }

		//TH1F *hdata_obs_2=(TH1F*)_fileData->Get(dirInternalDataAllELE[i]+"/data_obs");
		hdata_obs_2->SetName("hdata_obs_2");
		if(weightSOverSB) hdata_obs_2->Scale(weightMuEle[i]);
		if(i!=2 && (REBIN) ) hdata_obs_2->Rebin(2);
		fillNewHisto(hdata_obs,hdata_obs_2);
	}



	TH1F *hSMHIGGS=(TH1F*) hSMVBF126->Clone();hSMHIGGS->SetName("hSMHIGGS");
	hSMHIGGS->Add(hSMGG126);
	TH1F *hSMHWWHIGGS=(TH1F*) hSMHWWVBF126->Clone();hSMHWWHIGGS->SetName("hSMHWWHIGGS");
	hSMHWWHIGGS->Add(hSMHWWGG126);

	hWGamma->Add(hWGammaStar);

	hFAKES->Add(hFAKESLEPTON);
	hFAKES->SetFillColor(kMagenta-10); hFAKES->SetLineColor(kMagenta+3); hFAKES->SetLineWidth(1);
	hFAKESLEPTON->SetFillColor(kMagenta-9); hFAKESLEPTON->SetLineColor(kMagenta+4); hFAKESLEPTON->SetLineWidth(1);

	hZTauTau->SetFillColor(kOrange-4); hZTauTau->SetLineColor(kOrange+4); hZTauTau->SetLineWidth(1);

        hDY->SetFillColor(kAzure+3); hDY->SetLineColor(kAzure+4); hDY->SetLineWidth(1);
        hWW->SetFillColor(kAzure+3); hWW->SetLineColor(kAzure+3); hWW->SetLineWidth(1);
        hWGamma->SetFillColor(kAzure+3); hWGamma->SetLineColor(kAzure+3); hWGamma->SetLineWidth(1);

        hTOP->SetFillColor(kGreen-2); hTOP->SetLineColor(kGreen+4); hTOP->SetLineWidth(1);
        hTT->SetFillColor(kGreen-2); hTT->SetLineColor(kGreen-2); hTT->SetLineWidth(1);



	hSMHIGGS->SetFillColor(kMagenta); hSMHIGGS->SetLineColor(kMagenta+1); hSMHIGGS->SetLineWidth(1);
	hSMHWWHIGGS->SetFillColor(kMagenta); hSMHWWHIGGS->SetLineColor(kMagenta+1); hSMHWWHIGGS->SetLineWidth(1);

	hLFVGG126->SetLineColor(kBlue);  hLFVGG126->SetLineWidth(3);
	hLFVVBF126->SetLineColor(kBlue); hLFVVBF126->SetLineWidth(3); hLFVVBF126->SetLineStyle(kDashed);
	hSMHIGGS->SetLineColor(kMagenta); hSMHIGGS->SetLineWidth(3);
	hSMHWWHIGGS->SetLineColor(kMagenta); hSMHWWHIGGS->SetLineWidth(3);



	hdata_obs->SetMarkerSize(1); // Closer to Daniel's

	// PLOT

	TCanvas *c1 = new TCanvas("canvas_"+name);
	TPad *Pad1= new TPad("pad1","",0,0.2,1,1); Pad1->Draw(); Pad1->cd();;
	Pad1->SetLeftMargin(0.2147651);
	Pad1->SetRightMargin(0.06543624);
	Pad1->SetTopMargin(0.07);
	Pad1->SetBottomMargin(0.04);

	TH1F* fullMC2=hFAKES->Clone();  fullMC2->Add(hZTauTau); fullMC2->Add(hTT); fullMC2->Add(hWW); fullMC2->Add(hWGamma);
	fullMC2->Add(hDY); fullMC2->Add(hTOP); fullMC2->Add(hSMHIGGS);  fullMC2->Add(hSMHWWHIGGS);
	fullMC2->SetFillColor(kGray+2); fullMC2->SetFillStyle(3002); fullMC2->SetMarkerSize(0); fullMC2->SetLineWidth(2);
	fullMC2->Draw("hist");

	fullMC2->GetXaxis()->SetTitle("");
	fullMC2->GetYaxis()->SetTitle(Yaxis);
	fullMC2->GetXaxis()->SetRangeUser(xmin,xmax);
	fullMC2->GetYaxis()->SetTitleOffset(1.2);
	fullMC2->GetYaxis()->SetTitleSize(0.05);
	fullMC2->GetXaxis()->SetNdivisions(0);
	fullMC2->GetYaxis()->SetLabelSize(0.04);


	TH1F* hSignal=hLFVGG126->Clone(); hSignal->SetName("hSignal");
	hSignal->Add(hLFVVBF126);

        hSignal->SetLineColor(kBlue);  hSignal->SetLineWidth(3);
	hSignal->SetLineStyle(2);

	THStack* stack = new THStack("stack","");
	stack->Add(hFAKES);
	stack->Add(hWW);
	stack->Add(hWGamma);
        stack->Add(hDY);
	stack->Add(hTT);
	stack->Add(hTOP);
	stack->Add(hZTauTau);
	stack->Add(hSMHIGGS);;
	stack->Add(hSMHWWHIGGS);
	stack->Add(hSignal);

	int bins=hdata_obs->GetNbinsX()+1;

	/*
	   cout<<"Yields  "<<endl;
	   cout<<"DATA	    \t" <<hdata_obs->Integral()+hdata_obs->GetBinContent(bins)<<endl;
	   cout<<"VV           \t" <<hWW->Integral()+hWW->GetBinContent(bins)<<endl;
	   cout<<"TOP          \t" <<hTOP->Integral()+hTOP->GetBinContent(bins)<<endl;
	   cout<<"TT           \t" <<hTT->Integral()+hTT->GetBinContent(bins)<<endl;
	   cout<<"DY           \t" <<hDY->Integral()+hDY->GetBinContent(bins)<<endl;
	   cout<<"ZTauTau      \t" <<hZTauTau->Integral()+hZTauTau->GetBinContent(bins)<<endl;
	   cout<<"FAKES        \t" <<hFAKES->Integral()+hFAKES->GetBinContent(bins)<<endl;
	   cout<<"hFAKESLEPTON \t" <<hFAKESLEPTON->Integral()+hFAKESLEPTON->GetBinContent(bins)<<endl;
	   cout<<"hSMHIGGS     \t" <<hSMHIGGS->Integral()+hSMHWWHIGGS->Integral()+hSMHIGGS->GetBinContent(bins)+hSMHWWHIGGS->GetBinContent(bins)<<endl;
	   cout<<"LFVGG126     \t" <<hLFVGG126->Integral()+hLFVGG126->GetBinContent(bins)<<endl;
	   cout<<"LFVVBF126    \t" <<hLFVVBF126->Integral()+hLFVVBF126->GetBinContent(bins)<<endl;
	 */
	stack->Draw("samehist");
	fullMC2->Draw("sames,E2");

//	hSignal->Draw("sameshist");

	double maxData=hdata_obs->GetMaximum();
	double maxMC=stack->GetMaximum()*1.2;
	double maxLFV=hSignal->GetMaximum();
	double minMC=stack->GetMinimum();

	if(maxData>maxMC) {maxMC=1.2*maxData;}
	if(maxLFV>maxMC) {maxMC=1.2*maxLFV;}
	if(MAX!=-1) {maxMC=MAX;}
	if(minMC<1) minMC=0;

	stack->SetMaximum(maxMC);
	stack->GetYaxis()->SetRangeUser(minMC,maxMC);
	fullMC2->SetMaximum(maxMC);
	fullMC2->GetYaxis()->SetRangeUser(minMC,maxMC);

	hdata_obs->Draw("sames");


	TLegend *leg = new TLegend(legx1,legy1,legx2,legy2,NULL,"brNDC");
	leg->SetFillColor(0);
	leg->SetBorderSize(0);
	leg->SetFillStyle(0);
	TLegendEntry *entry;
	entry=leg->AddEntry(hdata_obs,"Data","p");
	entry=leg->AddEntry(fullMC2,"Bkgd. uncertainty","f");
	//entry=leg->AddEntry(hSMHWWHIGGS,"SM HWW","f");
	entry=leg->AddEntry(hSMHIGGS,"SM H","f");
	entry=leg->AddEntry(hZTauTau,"Z#rightarrow#tau#tau","f");
        entry=leg->AddEntry(hDY,"Other","f");
        entry=leg->AddEntry(hTOP,"t#bar{t}, t, #bar{t}","f");
	entry=leg->AddEntry(hFAKES,"MisID'd #tau, e, #mu","f");
	entry=leg->AddEntry(hSignal,"LFV Higgs, (B=0.9%)","l");
	//        entry=leg->AddEntry("NULL","Br(h#rightarrow#mu#tau)=1%","");
	//        entry=leg->AddEntry("NULL","Br(h#rightarrow#tau#tau)=6%","");
	leg->Draw();


	/*
	   TLegend *leg = new TLegend(legx1,legy1,legx2,legy2,NULL,"brNDC");
	   leg->SetFillColor(0);
	   leg->SetBorderSize(0);
	   leg->SetFillStyle(0);
	   TLegendEntry *entry;
	   entry=leg->AddEntry(hdata_obs,"observed","p");
	   entry=leg->AddEntry(fullMC2,"bckg. uncertainty","fl");
	//entry=leg->AddEntry(hSMHWWHIGGS,"SM HWW","f");
	entry=leg->AddEntry(hSMHIGGS,"SM H","f");
	eblindBy=leg->AddEntry(hZTauTau,"Z+#tau#tau (embedd.)","f");
	eblindBy=leg->AddEntry(hDY,"EWK","f");
	entry=leg->AddEntry(hFAKES,"Fakes","f");
	entry=leg->AddEntry(hSignal,"LFV Higgs, (B=0.9%)","l");
	//        entry=leg->AddEntry("NULL","Br(h#rightarrow#mu#tau)=1%","");
	//        entry=leg->AddEntry("NULL","Br(h#rightarrow#tau#tau)=6%","");
	 */


	leg->Draw();

	CMS_lumi( Pad1, iPeriod, iPos );
	//cmsPrelim(Lumi);

	Pad1->SetLogy(setLogY);



	c1->cd(); TPad *Pad2= new TPad("pad2","",0,0,1,0.23); Pad2->Draw(); Pad2->cd();  Pad2->SetGridy();
	Pad2->SetLeftMargin(0.2147651);
	Pad2->SetRightMargin(0.06543624);
	Pad2->SetTopMargin(0.0);
	Pad2->SetBottomMargin(0.38);
	Pad2->SetFillStyle(0);

	TH1F * Ratio=hdata_obs->Clone(); Ratio->SetName("Ratio");
	Ratio->Add(fullMC2,-1);
	double dataRatio[16];
	double mcRatio[16];
	double errordataUpRatio[16];
	double errordataDownRatio[16];
	double xbinsRatio[16];
	double xerrorbinsRatio[16];
	Ratio->Divide(fullMC2);

	TH1F* RatioError = Ratio->Clone(); RatioError->SetName("RatioError");

	for (int i=0; i<RatioError->GetNbinsX()+1; i++){
		double error=fullMC2->GetBinError(i)*hdata_obs->GetBinContent(i)/fullMC2->GetBinContent(i)/fullMC2->GetBinContent(i);
		//double error=fullMC2->GetBinError(i)/fullMC2->GetBinContent(i);
		RatioError->SetBinContent(i,0);
		RatioError->SetBinError(i,error);
	}


	for (int j=0; j<16; j++){
		xbinsRatio[j]=300./15*(j-1)+10;
		xerrorbinsRatio[j]=10;
		dataRatio[j]=hdata_obs->GetBinContent(j);
		errordataUpRatio[j]=hdata_obs->GetBinError(j);
		errordataDownRatio[j]=hdata_obs->GetBinError(j);
		if(dataRatio[j]==0) {errordataUpRatio[j]=1.7; errordataDownRatio[j]=0;}
		mcRatio[j]=fullMC2->GetBinContent(j);
		dataRatio[j]-=mcRatio[j];
		if(mcRatio[j]!=0) {
			dataRatio[j]=dataRatio[j]/mcRatio[j];
			errordataUpRatio[j]=errordataUpRatio[j]/mcRatio[j];
			errordataDownRatio[j]=errordataDownRatio[j]/mcRatio[j];
		}else{
			dataRatio[j]=0;
			errordataUpRatio[j]=0;
			errordataDownRatio[j]=0;
		}
		double error=0;
		if(fullMC2->GetBinContent(j)!=0) error=fullMC2->GetBinError(j)*hdata_obs->GetBinContent(j)/fullMC2->GetBinContent(j)/fullMC2->GetBinContent(j);

		cout<<hdata_obs->GetBinContent(j)<<" "<<mcRatio[j]<<"  "<<hdata_obs->GetBinError(j)<<" "<<fullMC2->GetBinError(j)<<"  "<<dataRatio[j]<<"  "<<errordataUpRatio[j]<<"  "<<error<<"  "<<Ratio->GetBinError(j)<<"   "<<sqrt(error*error+errordataUpRatio[j]*errordataUpRatio[j])<<endl;

	}

	TGraphAsymmErrors* dataGraphRatio=new TGraphAsymmErrors(16, xbinsRatio, dataRatio,xerrorbinsRatio,xerrorbinsRatio,errordataDownRatio,errordataUpRatio);

	Ratio->Draw("");

	Ratio->GetXaxis()->SetLabelFont(42);
	Ratio->GetXaxis()->SetTitleFont(42);
	Ratio->GetYaxis()->SetNdivisions(505);
	Ratio->GetYaxis()->SetLabelFont(42);
	Ratio->GetYaxis()->SetLabelSize(0.122);
	Ratio->GetYaxis()->SetRangeUser(ymin,ymax);
	Ratio->GetXaxis()->SetRangeUser(xmin,xmax);
	Ratio->GetXaxis()->SetLabelSize(0.12);
	Ratio->GetXaxis()->SetLabelFont(42);
	Ratio->SetYTitle("#frac{Data-Bkgd (fit)  }{Bkgd (fit)}");
	Ratio->SetXTitle(Xaxis);
	Ratio->GetXaxis()->SetNdivisions(505);
	Ratio->GetYaxis()->CenterTitle(true);
	Ratio->GetYaxis()->SetTitleOffset(0.4);
	Ratio->GetYaxis()->SetTitleSize(0.11);
	Ratio->GetXaxis()->SetTitleOffset(0.8);
	Ratio->GetXaxis()->SetTitleSize(0.20);
	Ratio->SetMarkerSize(1.);


	RatioError->Draw("sames,E2"); RatioError->SetFillStyle(3002); RatioError->SetFillColor(kGray+2); RatioError->SetMarkerSize(0);

	//	dataGraphRatio->Draw("sames,p");

	TCanvas *c2 = new TCanvas("canvas_"+name+"_2","canvas_"+name+"_2");
	TH1F* SUBTRACTEDMCERROR=fullMC2->Clone(); SUBTRACTEDMCERROR->SetName("SUBTRACTEDMCERROR");
	for (int i=0; i<SUBTRACTEDMCERROR->GetNbinsX()+1; i++) SUBTRACTEDMCERROR->SetBinContent(i,0);
	SUBTRACTEDMCERROR->SetFillColor(kYellow+4);
	SUBTRACTEDMCERROR->SetFillStyle(3004);
	SUBTRACTEDMCERROR->SetLineWidth(2);
	TH1F* SUBTRACTED=hdata_obs->Clone(); SUBTRACTED->SetName("SUBTRACTED");

	//	const int entriesD=(const)SUBTRACTEDMCERROR->GetNbinsX();
	double data[16];
	double mc[16];
	double errordataUp[16];
	double errordataDown[16];
	double xbins[16];
	double xerrorbins[16];

	for (int j=0; j<16; j++){
		xbins[j]=300./15*(j-1)+10;
		xerrorbins[j]=10;
		data[j]=SUBTRACTED->GetBinContent(j);
		errordataUp[j]=SUBTRACTED->GetBinError(j);
		errordataDown[j]=SUBTRACTED->GetBinError(j);
		if(data[j]==0) {errordataUp[j]=1.7; errordataDown[j]=0;}
		mc[j]=fullMC2->GetBinContent(j);
		data[j]-=mc[j];
	}

	TGraphAsymmErrors* dataGraph=new TGraphAsymmErrors(16, xbins, data,xerrorbins,xerrorbins,errordataDown,errordataUp);
	//dataGraph->SetMarkerColor(kRed);	

	SUBTRACTED->Add(fullMC2,-1);
	for (int i=0; i<SUBTRACTED->GetNbinsX()+1; i++) SUBTRACTED->SetBinError(i,hdata_obs->GetBinError(i));
	TH1F *hSignalFill=hSignal->Clone(); hSignalFill->SetName("hSignalFill");
	hSignalFill->SetFillColor(kBlue-10);
	hSignalFill->SetFillStyle(1001);
	hSignalFill->SetLineWidth(2);
	hSignalFill->Draw("hist");
        hSignalFill->SetLineStyle(1);

	hSignalFill->SetXTitle(Xaxis);
	SUBTRACTED->SetXTitle(Xaxis);
	SUBTRACTED->SetYTitle(Yaxis);
	hSignalFill->SetYTitle(Yaxis);

	hSignalFill->GetXaxis()->SetRangeUser(xmin,xmax);
	SUBTRACTED->GetXaxis()->SetRangeUser(xmin,xmax);
	SUBTRACTEDMCERROR->GetXaxis()->SetRangeUser(xmin,xmax);
	SUBTRACTEDMCERROR->SetXTitle(Xaxis);
	SUBTRACTEDMCERROR->SetYTitle(Yaxis);
	//hSignalFill->SetYTitle(Yaxis);
	SUBTRACTEDMCERROR->Draw("sames,E2");
	//SUBTRACTED->Draw("sames");
	dataGraph->Draw("sames,p");
	SUBTRACTEDMCERROR->GetXaxis()->SetNdivisions(505);
	SUBTRACTED->GetXaxis()->SetNdivisions(505);
	hSignalFill->GetXaxis()->SetNdivisions(505);
	SUBTRACTEDMCERROR->GetXaxis()->SetLabelSize(0.04);
	SUBTRACTED->GetXaxis()->SetLabelSize(0.04);
	hSignalFill->GetXaxis()->SetLabelSize(0.04);
	SUBTRACTEDMCERROR->GetYaxis()->SetLabelSize(0.04);
	SUBTRACTED->GetYaxis()->SetLabelSize(0.04);
	hSignalFill->GetYaxis()->SetLabelSize(0.04);
	SUBTRACTEDMCERROR->GetYaxis()->SetTitleSize(0.05);
	SUBTRACTED->GetYaxis()->SetTitleSize(0.05);
	hSignalFill->GetYaxis()->SetTitleSize(0.05);

	if(minsubs==-1)
		minsubs=TMath::Min(hSignalFill->GetMinimum(),SUBTRACTED->GetMinimum())*2.5;
	if(maxsubs==-1)
		maxsubs=TMath::Max(hSignalFill->GetMaximum(),SUBTRACTED->GetMaximum())*1.2;
	hSignalFill->SetMaximum(maxsubs);
	hSignalFill->SetMinimum(minsubs);

	if(minsubs==-1)
		minsubs=TMath::Min(SUBTRACTEDMCERROR->GetMinimum(),SUBTRACTED->GetMinimum())*2.5;
	if(maxsubs==-1)
		maxsubs=TMath::Max(SUBTRACTEDMCERROR->GetMaximum(),SUBTRACTED->GetMaximum())*1.2;
	SUBTRACTEDMCERROR->SetMaximum(maxsubs);
	SUBTRACTEDMCERROR->SetMinimum(minsubs);
	SUBTRACTED->SetMaximum(maxsubs);
	SUBTRACTED->SetMinimum(minsubs);




	TLegend *leg2 = new TLegend(0.55,0.93,0.99,0.7,NULL,"brNDC");
	leg2->SetFillColor(0);
	leg2->SetBorderSize(0);
	leg2->SetFillStyle(0);
	TLegendEntry *entry;
	//	entry=leg2->AddEntry("NULL",channelName,"");
	entry=leg2->AddEntry(hSignalFill,"LFV H#rightarrow#mu#tau signal (B=0.9%)","f");
	entry=leg2->AddEntry(SUBTRACTEDMCERROR,"Bkgd. uncertainty","f");
	entry=leg2->AddEntry(SUBTRACTED,"Data-Bkgd","pl");

	leg2->Draw();

        CMS_lumi( c2, iPeriod, iPos );

	c2->SaveAs(name+"_Subtracted.png");
	c2->SaveAs(name+"_Subtracted.pdf");

	if(!setLogY){
		c1->SaveAs(name+".png");
		c1->SaveAs(name+".pdf");
	}
	else {
		c1->SaveAs(name+"_log.png");
		c1->SaveAs(name+"_log.pdf");
	}

}