void
draw2DLimitContours(map<string,TList *>& m_contours,
		    const TString& par1,
		    const TString& par2,
		    const TString& plotprefix,
		    TLegend *legend,
		    float par1_bestfit,
		    float par2_bestfit)
{

  //from here we build the two-dimensional aTGC limit

  TCanvas *finalPlot = new TCanvas("final","limits",500,500);
  finalPlot->cd();

  cout << "Drawing expected 68%" << endl;

  TList *contLevel = m_contours["exp68"];
  TGraph *curv;

  std::cout << "m_contours.size() = " << m_contours.size() << std::endl;

  for (map<string,TList *>::const_iterator iter = m_contours.begin(); iter != m_contours.end(); iter++ ){
    std::cout << "iter->first = " << iter->first << std::endl;
    std::cout << "iter->second = " << iter->second << std::endl;
  }

  std::cout << "contLevel = " << contLevel << std::endl;

  assert(contLevel);

  curv = (TGraph*)(contLevel->First());

  curv->GetXaxis()->SetLimits(parmin(par1),parmax(par1));
  curv->GetYaxis()->SetRangeUser(parmin(par2),parmax(par2));

  curv->SetTitle();
  curv->GetXaxis()->SetTitle(par2latex(par1));
  curv->GetXaxis()->SetTitleFont(42);
  curv->GetYaxis()->SetTitle(par2latex(par2));
  curv->GetYaxis()->SetTitleFont(42);
  curv->GetYaxis()->SetTitleOffset(1.20);

  legend->SetNColumns(2);

  for (int i=0; i<contLevel->GetSize(); i++) {
    assert(curv);
    curv->SetLineColor(kBlue);
    curv->SetLineWidth(2);
    curv->SetLineStyle(9);
    if (!i) {
      curv->Draw("AC");
      legend->AddEntry(curv,"Expected 68% C.L.","L");
    } else 
      curv->Draw("SAME C");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing expected 95%" << endl;
  
  contLevel = m_contours["exp95"];

  curv = (TGraph*)(contLevel->First());

  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kGreen);
    curv->SetLineWidth(2);
    curv->SetLineStyle(9);
    curv->Draw("SAME C");
    if (!i) legend->AddEntry(curv,"Expected 95% C.L.","L");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing expected 99%" << endl;

  contLevel = m_contours["exp99"];
  curv = (TGraph*)(contLevel->First());
  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kRed);
    curv->SetLineWidth(2);
    curv->SetLineStyle(9);
    curv->Draw("SAME C");
    if (!i) legend->AddEntry(curv,"Expected 99% C.L.","L");
    curv=(TGraph *)(contLevel->After(curv));
  }

  
  contLevel = m_contours["obs95"];

  if (contLevel) {
    cout << "Drawing obs95" << endl;

    curv = (TGraph*)(contLevel->First());

    for (int i=0; i<contLevel->GetSize(); i++) {
      curv->Draw("SAME C");
      curv->SetLineWidth(3);
      if (!i) legend->AddEntry(curv,"Observed 95% C.L.","L");
      curv=(TGraph *)(contLevel->After(curv));
    }
  }

  
  TGraph *SMpoint = new TGraph(1);
  SMpoint->SetPoint(1,0,0);
  SMpoint->Draw("SAME P");
  legend->AddEntry(SMpoint,"SM","P");
  TGraph *bestfit = new TGraph(1);
  bestfit->SetPoint(1,par1_bestfit,par2_bestfit);
  bestfit->Draw("SAME *");
  legend->AddEntry(bestfit,"Best fit value","P");
  
  //smLabel = TPaveText(0,
  //                    m_contours["-2s"]->GetYaxis()->GetXmax()/8,
  //                    m_contours["-2s"]->GetXaxis()->GetXmax()/3->5,
  //                    -m_contours["-2s"]->GetYaxis()->GetXmax()/8);
  //smLabel->SetFillStyle(0);
  //smLabel->SetBorderSize(0);
  //smLabel->AddText(" SM");
  //smLabel->Draw();

  legend->Draw();

  TPaveText *text = new TPaveText(0.566,0.89,0.965,1.13,"NDC");
  text->SetFillStyle(0);
  text->SetBorderSize(0);
  text->SetTextFont(42);
  text->SetTextSize(0.05);
  //text->AddText(Form("95%% CL Limit on %s and %s",par2latex(par1).Data(),par2latex(par2).Data()));
  text->AddText(0,0.35,Form("2.3 fb^{-1} (%d TeV)",beamcometev));
  text->Draw();

  // text2 = TPaveText(0.155,0.199,0.974,0.244,"NDC");
  // text2->SetFillStyle(0);
  // text2->SetBorderSize(0);
  // text2->AddText("Values outside contour excluded");
  // text2->Draw();

  //text3 = TPaveText(0.506,0.699,0.905,0.758,"NDC");
  //text3->SetFillStyle(0);
  //text3->SetBorderSize(0);
  //text3->AddText(options.flavorText);
  //text3->Draw();    
  
  gPad->SetGrid(1,1);

  finalPlot->RedrawAxis();
  finalPlot->ResetAttPad();
  finalPlot->Update();

  finalPlot->Draw();
  finalPlot->Update();
  finalPlot->Modified();
  finalPlot->Update();
  finalPlot->Print(Form("%s.pdf",plotprefix.Data()));
  finalPlot->Print(Form("%s.eps",plotprefix.Data()));
  //finalPlot->Print(Form("%s.png",plotprefix.Data()));

}                                                 // draw2DlimitContours
void
draw2DLimitBFstyle(map<string,TList *>& m_contours,
		     const TString& par1,
		     const TString& par2,
		     const TString& plotprefix,
		     TLegend *legend)
{

  //from here we build the two-dimensional aTGC limit

  TCanvas *finalPlot = new TCanvas("final","limits",500,500);
  finalPlot->cd();

  cout << "Drawing +2s" << endl;

  TList *contLevel = m_contours["+2s"];
  TGraph *curv;

  assert(contLevel);

  curv = (TGraph*)(contLevel->First());

  //curv->GetYaxis()->SetRangeUser(-1.25*curv->GetYaxis()->GetXmax(),
	  			   //+2.0*curv->GetYaxis()->GetXmax());
  //curv->GetYaxis()->SetRangeUser(-0.1,0.15);
  curv->GetYaxis()->SetRangeUser(parmin(par2),parmax(par2));

  curv->SetTitle();
  curv->GetXaxis()->SetTitle(par2latex(par1));
  curv->GetXaxis()->SetTitleFont(42);
  curv->GetYaxis()->SetTitle(par2latex(par2));
  curv->GetYaxis()->SetTitleFont(42);
  curv->GetYaxis()->SetTitleOffset(1.20);

  for (int i=0; i<contLevel->GetSize(); i++) {
    assert(curv);
    curv->SetLineColor(kYellow);
    curv->SetFillColor(kYellow);
    curv->GetXaxis()->SetLimits(parmin(par1),parmax(par1));
    if (!i) {
      curv->Draw("ACF");
      legend->AddEntry(curv,"#pm 2#sigma","F");
    } else 
      curv->Draw("SAME CF");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing +1s" << endl;
  
  contLevel = m_contours["+1s"];

  curv = (TGraph*)(contLevel->First());

  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kGreen);
    curv->SetFillColor(kGreen);
    curv->Draw("SAME CF");
    if (!i) legend->AddEntry(curv,"#pm 1#sigma","F");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing -1s" << endl;

  contLevel = m_contours["-1s"];
  curv = (TGraph*)(contLevel->First());
  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kYellow);
    curv->SetFillColor(kYellow);
    curv->Draw("SAME CF");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing -2s" << endl;
  
  contLevel = m_contours["-2s"];

  if (!contLevel)
    //  this can happen more often for this contour if there is insufficient
    // sensitivity close to the SM
    cerr << "No contour level for +2s, have to fill in the central region" << endl;
  else {
    curv = (TGraph*)(contLevel->First());
    for (int i=0; i<contLevel->GetSize(); i++) {
      curv->SetFillColor(kWhite);
      curv->SetLineColor(kYellow);
      curv->Draw("SAME CF");
      curv=(TGraph *)(contLevel->After(curv));
    }
  }
  cout << "Drawing median" << endl;
  
  curv = (TGraph*)(m_contours["median"]->First());
  curv->SetLineColor(kBlack);
  curv->SetLineWidth(2);
  curv->SetLineStyle(2);
  curv->Draw("SAME C");

  legend->AddEntry(curv,"Expected","L");
  
  cout << "Drawing obs" << endl;

  contLevel = m_contours["obs"];
  curv = (TGraph*)(contLevel->First());
  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kBlack);
    curv->SetLineWidth(2);
    curv->Draw("SAME C");
    if (!i) legend->AddEntry(curv,"Observed","L");
    curv=(TGraph *)(contLevel->After(curv));
  }

  
  TGraph *SMpoint = new TGraph(1);
  SMpoint->SetPoint(1,0,0);
  SMpoint->Draw("SAME Po");
  
  // smLabel = TPaveText(0,
  //                     m_contours["-2s"]->GetYaxis()->GetXmax()/8,
  //                     m_contours["-2s"]->GetXaxis()->GetXmax()/3->5,
  //                     -m_contours["-2s"]->GetYaxis()->GetXmax()/8);
  // smLabel->SetFillStyle(0);
  // smLabel->SetBorderSize(0);
  // smLabel->AddText(" SM");
  // smLabel->Draw();

  legend->Draw();

  TPaveText *text = new TPaveText(0.566,0.87,0.965,1.101,"NDC");
  text->SetFillStyle(0);
  text->SetBorderSize(0);
  text->AddText(Form("95%% CL Limit on %s and %s",par2latex(par1).Data(),par2latex(par2).Data()));
  text->AddText(0,0.35,Form("#intL dt= %.1f fb^{-1}, #sqrt{s} = %d TeV",intlumifbinv,beamcometev));
  text->Draw();

  // text2 = TPaveText(0.155,0.199,0.974,0.244,"NDC");
  // text2->SetFillStyle(0);
  // text2->SetBorderSize(0);
  // text2->AddText("Values outside contour excluded");
  // text2->Draw();

  //text3 = TPaveText(0.506,0.699,0.905,0.758,"NDC");
  //text3->SetFillStyle(0);
  //text3->SetBorderSize(0);
  //text3->AddText(options.flavorText);
  //text3->Draw();    
  
  finalPlot->RedrawAxis();
  finalPlot->ResetAttPad();
  finalPlot->Update();

  finalPlot->Draw();
  finalPlot->Update();
  finalPlot->Modified();
  finalPlot->Update();
  finalPlot->Print(Form("%s.pdf",plotprefix.Data()));
  finalPlot->Print(Form("%s.eps",plotprefix.Data()));
  finalPlot->Print(Form("%s.png",plotprefix.Data()));

}                                                  // draw2DlimitBFstyle