void showGraph(double canvasSizeX, double canvasSizeY,
	       TGraph* graph, 
	       bool useLogScaleX, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset,
	       bool useLogScaleY, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset,
	       const std::string& outputFileName)
{
  TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY);
  canvas->SetFillColor(10);
  canvas->SetBorderSize(2); 
  canvas->SetTopMargin(0.05);
  canvas->SetLeftMargin(0.19);
  canvas->SetBottomMargin(0.19);
  canvas->SetRightMargin(0.05);
  canvas->SetLogx(useLogScaleX);
  canvas->SetLogy(useLogScaleY);

  TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", 10, xMin, xMax);
  dummyHistogram->SetTitle("");
  dummyHistogram->SetStats(false);
  dummyHistogram->SetMinimum(yMin);
  dummyHistogram->SetMaximum(yMax);
  dummyHistogram->Draw("axis");

  TAxis* xAxis = dummyHistogram->GetXaxis();
  xAxis->SetTitle(xAxisTitle.data());
  xAxis->SetTitleOffset(xAxisOffset);
  xAxis->SetTitleSize(0.065);
  xAxis->SetLabelSize(0.055);
  xAxis->SetLabelOffset(0.01);
  xAxis->SetTickLength(0.055);
  xAxis->SetNdivisions(505);

  TAxis* yAxis = dummyHistogram->GetYaxis();
  yAxis->SetTitle(yAxisTitle.data());
  yAxis->SetTitleOffset(yAxisOffset);
  yAxis->SetTitleSize(0.070);
  yAxis->SetLabelSize(0.055);
  yAxis->SetLabelOffset(0.01);
  yAxis->SetTickLength(0.055);
  yAxis->SetNdivisions(505);

  graph->SetMarkerColor(1);
  graph->SetLineColor(1);
  graph->Draw("p");

  canvas->Update();
  size_t idx = outputFileName.find_last_of('.');
  std::string outputFileName_plot = std::string(outputFileName, 0, idx);
  if ( useLogScaleY ) outputFileName_plot.append("_log");
  else outputFileName_plot.append("_linear");
  if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
  canvas->Print(std::string(outputFileName_plot).append(".png").data());
  //canvas->Print(std::string(outputFileName_plot).append(".pdf").data());
  //canvas->Print(std::string(outputFileName_plot).append(".root").data());
  
  delete dummyHistogram;
  delete canvas;  
}
Esempio n. 2
0
/*
   double residual_error( double error_data, double pdf )
   {
   double chi2 = 0.;

   if ( pdf > 0 )
   chi2 += 2. * ( pdf - error_data );

   if ( error_data > 0 && pdf > 0 )
   chi2=(error_data/pdf);
//chi2 += 2. * error_data * log( error_data / error_pdf );

// return ( ( error_data >= pdf ) ? sqrt( chi2 ) : -sqrt( chi2 ) );
// return ( ( error_data >= pdf ) ? chi2 :  chi2 );
return ( chi2 );
}
 */
TH1D* residualHist( const RooHist* rhist, const RooCurve* curve )
{
    double r = 0.2;
    double sr = 1. / r;

    // Grab info from the histogram.
    int     n = rhist->GetN();
    double* x = rhist->GetX();
    double* y = rhist->GetY();
    //rhist->Sumw2();
    //   double e;

    // Create residual histogram.
    double xMin = x[ 0     ];
    double xMax = x[ n - 1 ];
    TH1D* residuals_temp = new TH1D( "r", "", n, xMin, xMax );

    double datum = 0.;
    double pdf   = 0.;
    double error_data = 0.;

    // Fill the histogram.
    if ( curve )
        for ( int bin = 0; bin < n; bin++ )
        {
            datum = y[ bin ];
            pdf   = curve->Eval( x[ bin ] );
            error_data = rhist->GetErrorY(bin); 

            //            error_pdf = curve->Eval( x[ bin ] );

            residuals_temp->SetBinContent( bin + 1, residual( datum, pdf ) );
            //          residuals_temp->SetBinError  ( bin + 1, residual_error( error_data, pdf ) );
            residuals_temp->SetBinError  ( bin + 1, error_data / pdf );
        }

    residuals_temp->SetMinimum    ( -2.   );
    residuals_temp->SetMaximum    (  2.   );
    residuals_temp->SetStats      ( false );
    residuals_temp->SetMarkerStyle( 8     );
    residuals_temp->SetMarkerSize ( .8    );

    TAxis* xAxis = residuals_temp->GetXaxis();
    xAxis->SetTickLength ( sr * xAxis->GetTickLength()  );
    xAxis->SetLabelSize  ( sr * xAxis->GetLabelSize()   );
    xAxis->SetTitleSize  ( sr * xAxis->GetTitleSize()   );
    xAxis->SetLabelOffset( sr * xAxis->GetLabelOffset() );

    TAxis* yAxis = residuals_temp->GetYaxis();
    //yAxis->SetNdivisions ( 500                          );
    //yAxis->SetLabelSize  ( 10*sr * yAxis->GetLabelSize()   );
    yAxis->SetLabelSize  ( 2.5 * yAxis->GetLabelSize()   );

    yAxis->SetTitle("  (DATA - FIT) / FIT");
    yAxis->SetTitleSize  ( 0.09  );
    yAxis->SetTitleOffset( 0.35  );

    return residuals_temp;
}
void makePlot(const std::string& inputFilePath, const std::string& canvasName, const std::string& sample, int massPoint, const std::string& channel, double k, 
	      const std::string& inputFileName, const std::string& outputFilePath, const std::string& outputFileName)
{
  std::string inputFileName_full = Form("%s%s", inputFilePath.data(), inputFileName.data());
  TFile* inputFile = new TFile(inputFileName_full.data());
  if ( !inputFile ) {
    std::cerr << "Failed to open input file = " << inputFileName_full << " !!" << std::endl;
    assert(0);
  }

  inputFile->ls();

  TCanvas* canvas = dynamic_cast<TCanvas*>(inputFile->Get(canvasName.data()));
  if ( !canvas ) {
    std::cerr << "Failed to load canvas = " << canvasName << " !!" << std::endl;
    assert(0);
  }

  int idxPad = -1;
  if ( massPoint ==  90 ) idxPad = 1;
  if ( massPoint == 125 ) idxPad = 2;
  if ( massPoint == 200 ) idxPad = 3;
  if ( massPoint == 300 ) idxPad = 4;
  if ( massPoint == 500 ) idxPad = 5;
  if ( massPoint == 800 ) idxPad = 6;  
  if ( !(idxPad >= 1 && idxPad <= 6) ) {
    std::cerr << "Invalid sample = " << sample << " !!" << std::endl;
    assert(0);
  }
  TVirtualPad* pad = canvas->GetPad(idxPad);
  std::cout << "pad = " << pad << ": ClassName = " << pad->ClassName() << std::endl;

  TCanvas* canvas_new = new TCanvas("canvas_new", "canvas_new", 900, 800);
  canvas_new->SetFillColor(10);
  canvas_new->SetBorderSize(2);
  canvas_new->SetTopMargin(0.065);
  canvas_new->SetLeftMargin(0.17);
  canvas_new->SetBottomMargin(0.165);
  canvas_new->SetRightMargin(0.015);
  canvas_new->SetLogx(true);
  canvas_new->SetLogy(true);
  canvas_new->Draw();
  canvas_new->cd();

  //TList* pad_primitives = canvas->GetListOfPrimitives();
  TList* pad_primitives = pad->GetListOfPrimitives();

  TH1* histogramCA            = 0;
  TH1* histogramSVfit         = 0;
  TH1* histogramSVfitMEMkEq0  = 0;
  TH1* histogramSVfitMEMkNeq0 = 0;

  TIter pad_nextObj(pad_primitives);
  while ( TObject* obj = pad_nextObj() ) {
    std::string objName = "";
    if ( dynamic_cast<TNamed*>(obj) ) objName = (dynamic_cast<TNamed*>(obj))->GetName();    
    std::cout << "obj = " << obj << ": name = " << objName << ", type = " << obj->ClassName() << std::endl;

    TH1* tmpHistogram = dynamic_cast<TH1*>(obj);
    if ( tmpHistogram ) {
      std::cout << "tmpHistogram:" 
		<< " fillColor = " << tmpHistogram->GetFillColor() << ", fillStyle = " << tmpHistogram->GetFillStyle() << ","
		<< " lineColor = " << tmpHistogram->GetLineColor() << ", lineStyle = " << tmpHistogram->GetLineStyle() << ", lineWidth = " << tmpHistogram->GetLineWidth() << ","
		<< " markerColor = " << tmpHistogram->GetMarkerColor() << ", markerStyle = " << tmpHistogram->GetMarkerStyle() << ", markerSize = " << tmpHistogram->GetMarkerSize() << ","
		<< " integral = " << tmpHistogram->Integral() << std::endl;
      std::cout << "(mean = " << tmpHistogram->GetMean() << ", rms = " << tmpHistogram->GetRMS() << ": rms/mean = " << (tmpHistogram->GetRMS()/tmpHistogram->GetMean()) << ")" << std::endl;
      if ( tmpHistogram->GetLineColor() == 416 ) histogramCA            = tmpHistogram;
      if ( tmpHistogram->GetLineColor() == 600 ) histogramSVfit         = tmpHistogram;
      if ( tmpHistogram->GetLineColor() == 616 ) histogramSVfitMEMkEq0  = tmpHistogram;
      if ( tmpHistogram->GetLineColor() == 632 ) histogramSVfitMEMkNeq0 = tmpHistogram;
    }
  }

  if ( !(histogramCA && histogramSVfit && histogramSVfitMEMkEq0 && histogramSVfitMEMkNeq0) ) {
    std::cerr << "Failed to load histograms !!" << std::endl;
    assert(0);
  }

  //gStyle->SetLineStyleString(2,"40 10 10 10 10 10 10 10");
  //gStyle->SetLineStyleString(3,"25 15");
  //gStyle->SetLineStyleString(4,"60 25");

  //int colors[4] = { kBlack, kGreen - 6, kBlue - 7, kMagenta - 7  };
  int colors[4] = { 28, kGreen - 6, kBlue - 7, kBlack };
  //int lineStyles[4] = { 2, 3, 4, 1 };
  int lineStyles[4] = { 7, 1, 1, 1 };
  //int lineWidths[4] = { 3, 3, 4, 3 };
  int lineWidths[4] = { 3, 3, 1, 1 };
  int markerStyles[4] = { 20, 25, 21, 24 };
  int markerSizes[4] = { 2, 2, 2, 2 };

  histogramCA->SetFillColor(0);
  histogramCA->SetFillStyle(0);
  histogramCA->SetLineColor(colors[0]);
  histogramCA->SetLineStyle(lineStyles[0]);
  histogramCA->SetLineWidth(lineWidths[0]);
  histogramCA->SetMarkerColor(colors[0]);
  histogramCA->SetMarkerStyle(markerStyles[0]);
  histogramCA->SetMarkerSize(markerSizes[0]);

  histogramSVfit->SetFillColor(0);
  histogramSVfit->SetFillStyle(0);
  histogramSVfit->SetLineColor(colors[1]);
  histogramSVfit->SetLineStyle(lineStyles[1]);
  histogramSVfit->SetLineWidth(lineWidths[1]);
  histogramSVfit->SetMarkerColor(colors[1]);
  histogramSVfit->SetMarkerStyle(markerStyles[1]);
  histogramSVfit->SetMarkerSize(markerSizes[1]);

  histogramSVfitMEMkEq0->SetFillColor(0);
  histogramSVfitMEMkEq0->SetFillStyle(0);
  histogramSVfitMEMkEq0->SetLineColor(colors[2]);
  histogramSVfitMEMkEq0->SetLineStyle(lineStyles[2]);
  histogramSVfitMEMkEq0->SetLineWidth(lineWidths[2]);
  histogramSVfitMEMkEq0->SetMarkerColor(colors[2]);
  histogramSVfitMEMkEq0->SetMarkerStyle(markerStyles[2]);
  histogramSVfitMEMkEq0->SetMarkerSize(markerSizes[2]);
  // CV: fix pathological bins at high mass for which dN/dm increases
  int numBins = histogramSVfitMEMkEq0->GetNbinsX();
  for ( int idxBin = 1; idxBin <= numBins; ++idxBin ) {
    double binCenter = histogramSVfitMEMkEq0->GetBinCenter(idxBin);
    if ( (channel == "#tau_{h}#tau_{h}" && massPoint == 500 && binCenter > 1500.) ||
	 (channel == "#tau_{h}#tau_{h}" && massPoint == 800 && binCenter > 2000.) ||
	 (channel == "#mu#tau_{h}"      && massPoint == 500 && binCenter > 1500.) ||
	 (channel == "#mu#tau_{h}"      && massPoint == 800 && binCenter > 2500.) ) {
      histogramSVfitMEMkEq0->SetBinContent(idxBin, 0.);
    }
  }

  histogramSVfitMEMkNeq0->SetFillColor(0);
  histogramSVfitMEMkNeq0->SetFillStyle(0);
  histogramSVfitMEMkNeq0->SetLineColor(colors[3]);
  histogramSVfitMEMkNeq0->SetLineStyle(lineStyles[3]);
  histogramSVfitMEMkNeq0->SetLineWidth(lineWidths[3]);
  histogramSVfitMEMkNeq0->SetMarkerColor(colors[3]);
  histogramSVfitMEMkNeq0->SetMarkerStyle(markerStyles[3]);
  histogramSVfitMEMkNeq0->SetMarkerSize(markerSizes[3]);

  TAxis* xAxis = histogramCA->GetXaxis();
  xAxis->SetTitle("m_{#tau#tau} [GeV]");
  xAxis->SetTitleOffset(1.15);
  xAxis->SetTitleSize(0.070);
  xAxis->SetTitleFont(42);
  xAxis->SetLabelOffset(0.010);
  xAxis->SetLabelSize(0.055);
  xAxis->SetLabelFont(42);
  xAxis->SetTickLength(0.040);
  xAxis->SetNdivisions(510);

  //double xMin = 20.;
  //double xMax = xAxis->GetXmax();
  //xAxis->SetRangeUser(xMin, xMax);

  TAxis* yAxis = histogramCA->GetYaxis();
  yAxis->SetTitle("dN/dm_{#tau#tau} [1/GeV]");
  yAxis->SetTitleOffset(1.20);
  yAxis->SetTitleSize(0.070);
  yAxis->SetTitleFont(42);
  yAxis->SetLabelOffset(0.010);
  yAxis->SetLabelSize(0.055);
  yAxis->SetLabelFont(42);
  yAxis->SetTickLength(0.040);  
  yAxis->SetNdivisions(505);

  double massPoint_double = 0.;
  if ( massPoint == 90 ) massPoint_double = 91.2;
  else massPoint_double = massPoint;
  double dLog = (TMath::Log(5.*massPoint_double) - TMath::Log(50.))/25.; // xMin = 50, xMax = 5*massPoint, numBins = 25
  double binWidth = TMath::Exp(TMath::Log(massPoint_double) + 0.5*dLog) - TMath::Exp(TMath::Log(massPoint_double) - 0.5*dLog);
  double sf_binWidth = 1./binWidth;
  std::cout << "massPoint = " << massPoint << ": sf_binWidth = " << sf_binWidth << std::endl;

  histogramCA->SetTitle("");
  histogramCA->SetStats(false);
  histogramCA->SetMaximum(sf_binWidth*0.79);
  histogramCA->SetMinimum(sf_binWidth*1.1e-4);
  histogramCA->Draw("hist");
  histogramSVfit->Draw("histsame");
  //histogramSVfitMEMkEq0->Draw("histsame");
  histogramSVfitMEMkEq0->Draw("epsame");
  //histogramSVfitMEMkNeq0->Draw("histsame");
  histogramSVfitMEMkNeq0->Draw("epsame");
  histogramCA->Draw("axissame");

  //TPaveText* label_sample = new TPaveText(0.21, 0.86, 0.46, 0.94, "NDC");
  TPaveText* label_sample = new TPaveText(0.1700, 0.9475, 0.4600, 1.0375, "NDC");
  label_sample->SetFillStyle(0);
  label_sample->SetBorderSize(0);
  label_sample->AddText(sample.data());
  label_sample->SetTextFont(42);
  label_sample->SetTextSize(0.055);
  label_sample->SetTextColor(1);
  label_sample->SetTextAlign(13);
  label_sample->Draw();

  //TLegend* legend_new = new TLegend(0.225, 0.52, 0.41, 0.82, NULL, "brNDC");
  TLegend* legend_new = new TLegend(0.30, 0.30, 0.80, 0.80, NULL, "brNDC");
  legend_new->SetFillColor(10);
  legend_new->SetFillStyle(0);
  legend_new->SetBorderSize(0);
  legend_new->SetTextFont(42);
  legend_new->SetTextSize(0.055);
  legend_new->SetTextColor(1);
  legend_new->SetMargin(0.20);
  legend_new->AddEntry(histogramCA, "CA", "l");
  legend_new->AddEntry(histogramSVfit, "SVfit", "l");
  //legend_new->AddEntry(histogramSVfitMEMkEq0, "SVfitMEM (k=0)", "l");
  legend_new->AddEntry(histogramSVfitMEMkEq0, "SVfitMEM (k=0)", "p");
  //legend_new->AddEntry(histogramSVfitMEMkNeq0, Form("SVfitMEM(k=%1.0f)", k), "l");
  legend_new->AddEntry(histogramSVfitMEMkNeq0, Form("SVfitMEM (k=%1.0f)", k), "p");
  //legend_new->Draw();

  double label_channel_y0;
  if      ( channel == "e#mu"             ) label_channel_y0 = 0.9275;
  else if ( channel == "#mu#tau_{h}"      ) label_channel_y0 = 0.9400;
  else if ( channel == "#tau_{h}#tau_{h}" ) label_channel_y0 = 0.9350;
  else {
    std::cerr << "Invalid channel = " << channel << " !!" << std::endl;
    assert(0);
  }
  TPaveText* label_channel = new TPaveText(0.895, label_channel_y0, 0.975, label_channel_y0 + 0.055, "NDC");
  label_channel->SetFillStyle(0);
  label_channel->SetBorderSize(0);
  label_channel->AddText(channel.data());
  label_channel->SetTextFont(62);
  label_channel->SetTextSize(0.055);
  label_channel->SetTextColor(1);
  label_channel->SetTextAlign(31);
  label_channel->Draw();

  canvas_new->Update();

  std::string outputFileName_full = Form("%s%s", outputFilePath.data(), outputFileName.data());
  size_t idx = outputFileName_full.find_last_of('.');
  std::string outputFileName_plot = std::string(outputFileName_full, 0, idx);
  canvas_new->Print(std::string(outputFileName_plot).append(".pdf").data());
  canvas_new->Print(std::string(outputFileName_plot).append(".root").data());

  std::string channel_string;
  if      ( channel == "e#mu"             ) channel_string = "emu";
  else if ( channel == "#mu#tau_{h}"      ) channel_string = "muhad";
  else if ( channel == "#tau_{h}#tau_{h}" ) channel_string = "hadhad";
  else {
    std::cerr << "Invalid channel = " << channel << " !!" << std::endl;
    assert(0);
  }
  std::string outputFileName_legend = Form("makeSVfitMEM_PerformancePlots_legend_%s.pdf", channel_string.data());
  makePlot_legend(legend_new, outputFilePath, outputFileName_legend);

  delete label_sample;
  delete legend_new;
  delete label_channel;
  delete canvas_new;

  delete inputFile;
}
void draw() {

  gROOT->Reset();

// first make a canvas and a 2D histogram for the axes

  TCanvas* canvas = new TCanvas("canvas", "canvas", 10, 10, 500, 500);
  canvas->SetFillColor(0);
  canvas->SetBorderMode(0);  
  canvas->SetFrameBorderMode(0);   // need this to turn off red hist frame!

  gROOT->SetStyle("Plain");
  canvas->UseCurrentStyle();

  gPad->SetLeftMargin(0.15);
  gPad->SetRightMargin(0.05);
  gPad->SetTopMargin(0.07);
  gPad->SetBottomMargin(0.17);

  gStyle->SetOptStat(0);
  gStyle->SetTitleBorderSize(0);
  gStyle->SetTitleSize(0.04);

  gStyle->SetTextFont(42);
  gStyle->SetTextSize(0.04);
  gStyle->SetTitleFont(42, "hxy");    // for histogram and axis title
  gStyle->SetLabelFont(42, "xyz");    // for axis labels (values)

  gStyle->SetTitleOffset(0.8, "h");        // what does this do?
  gStyle->SetTitleX(0.15);
  gStyle->SetTitleY(0.99);

  gROOT->ForceStyle();

  // can make histogram or alternatively use the histograms automatically
  // connected to the TF1 or TGraph objects

  double xMin = 0.1;
  double xMax = 100.;
  // double yMin = 0.1;
  // double yMax = 10.;
  double yMin = 0.;
  double yMax = 8.;
  TH2F* axhist = new TH2F("axhist", "title", 10, xMin, xMax, 10, yMin, yMax);
  axhist->SetTitle("");
  axhist->SetXTitle("b");
  axhist->SetYTitle("med[Z|s]");
  gPad->SetLogx(1);
  gPad->SetLogy(0);

  double u[20];
  double x[20][500];

  // Read in data from file and insert in TTree

  TString fileName;
  // cout << "Enter file name: ";
  // cin >> fileName;
  fileName = "medsig_s5_rel_bi.txt";

  ifstream inFile;
  inFile.open(fileName);
  if (inFile.fail()) { 
    cout << "Couldn't open file!" << endl;
    exit(1); 
  }

  bool readLine = true;
  int lineNum = 0;
  int ncol;
  while ( readLine ){

    TString line;
    stringstream ss;
    line.ReadLine(inFile);
    readLine = inFile.good();

    if ( readLine ) {

      TString firstChar = line(0,1);
      bool useLine = firstChar != "#";

      if ( useLine ){

        int i = 0;
        stringstream ss;
        ss << line;              // put whole line into ss
        TString token;
        bool getToken = true;

        while ( getToken ) {
          ss >> token;           // extracts one token
          if ( token.Length() > 0 ) {
            u[i] = token.Atof();
            i++;
          } 
          else {
            getToken = false;
          }
        }             // getToken
        ncol = i;  

        for (int i=0; i<ncol; i++){
          x[i][lineNum] = u[i];
        }
        lineNum++;

      }               // useLine

    }         // readLine

  }           // readLine

  int n = lineNum;
  inFile.close();

  //  for (int i=0; i<n; i++){
  //  cout << i << "  " << x[0][i] << "  " << x[3][i] << "  " 
  //	 << x[4][i] << endl;
  //  }

  TGraph* tg1 = new TGraph(n, x[0], x[1]);
  TGraph* tg2 = new TGraph(n, x[0], x[2]);
  TGraph* tg3 = new TGraph(n, x[0], x[3]);
  TGraph* tg4 = new TGraph(n, x[0], x[4]);
  TGraph* tg5 = new TGraph(n, x[0], x[5]);
  TGraph* tg6 = new TGraph(n, x[0], x[6]);
  TGraph* tg7 = new TGraph(n, x[0], x[7]);
  TGraph* tg8 = new TGraph(n, x[0], x[8]);
  TGraph* tg9 = new TGraph(n, x[0], x[9]);
  TGraph* tg10 = new TGraph(n, x[0], x[10]);
  TGraph* tg11 = new TGraph(n, x[0], x[11]);
  TGraph* tg12 = new TGraph(n, x[0], x[12]);
  TGraph* tg13 = new TGraph(n, x[0], x[13]);
  TGraph* tg14 = new TGraph(n, x[0], x[14]);
  TGraph* tg15 = new TGraph(n, x[0], x[15]);

  TAxis* xa = axhist->GetXaxis();
  TAxis* ya = axhist->GetYaxis();

  xa->SetTitleOffset(1.2);    //  factor multiplies default offset
  ya->SetTitleOffset(1.1);

  xa->SetLabelOffset(0.005);
  ya->SetLabelOffset(0.005);

  xa->SetTickLength(0.015);  // default  = 0.03
  ya->SetTickLength(0.015);  // default  = 0.03

  xa->SetTitleSize(0.05);
  ya->SetTitleSize(0.05);

  //  gPad->SetLogx(1);
  //  xa->SetLimits(90., 700.);

  xa->SetNdivisions(-5); // negative value should force number of divisions?
  ya->SetNdivisions(-4);

  xa->SetLabelSize(0.05);
  ya->SetLabelSize(0.05);

  // Draw axes and then add stuff

  // kDot=1, kPlus, kStar, kCircle=4, kMultiply=5,
  // kFullDotSmall=6, kFullDotMedium=7, kFullDotLarge=8,
  // kFullCircle=20, kFullSquare=21, kFullTriangleUp=22,
  // kFullTriangleDown=23, kOpenCircle=24, kOpenSquare=25,
  // kOpenTriangleUp=26, kOpenDiamond=27, kOpenCross=28,
  // kFullStar=29, kOpenStar=30

  axhist->Draw();

  tg1->SetLineColor(kRed);
  tg1->SetLineWidth(2);
  tg1->SetLineStyle(2);
  tg1->SetMarkerColor(kRed);
  tg1->SetMarkerSize(0.8);
  tg1->SetMarkerStyle(20);
  tg1->Draw("L,same");              // or P for points

  tg2->SetLineColor(kRed);
  tg2->SetLineWidth(2);
  tg2->SetLineStyle(2);
  tg2->SetMarkerColor(kRed);
  tg2->SetMarkerSize(0.8);
  tg2->SetMarkerStyle(20);
  tg2->Draw("L,same");              // or P for points

  tg3->SetLineColor(kRed);
  tg3->SetLineWidth(2);
  tg3->SetLineStyle(2);
  tg3->SetMarkerColor(kRed);
  tg3->SetMarkerSize(0.8);
  tg3->SetMarkerStyle(20);
  // tg3->Draw("L,same");              // or P for points

  tg4->SetLineColor(kBlue);
  tg4->SetLineWidth(2);
  tg4->SetLineStyle(1);
  tg4->SetMarkerColor(kBlue);
  tg4->SetMarkerSize(0.8);
  tg4->SetMarkerStyle(20);
  tg4->Draw("L,same");              // or P for points

  tg5->SetLineColor(kBlue);
  tg5->SetLineWidth(2);
  tg5->SetLineStyle(1);
  tg5->SetMarkerColor(kBlue);
  tg5->SetMarkerSize(0.8);
  tg5->SetMarkerStyle(20);
  tg5->Draw("L,same");              // or P for points

  tg6->SetLineColor(kBlue);
  tg6->SetLineWidth(2);
  tg6->SetLineStyle(1);
  tg6->SetMarkerColor(kBlue);
  tg6->SetMarkerSize(0.8);
  tg6->SetMarkerStyle(20);
  // tg6->Draw("L,same");              // or P for points

  tg7->SetLineColor(kRed);
  tg7->SetLineWidth(2);
  tg7->SetLineStyle(1);
  tg7->SetMarkerColor(kRed);
  tg7->SetMarkerSize(0.8);
  tg7->SetMarkerStyle(21);
  // tg7->Draw("P,same");              // or P for points

  tg8->SetLineColor(kRed);
  tg8->SetLineWidth(2);
  tg8->SetLineStyle(1);
  tg8->SetMarkerColor(kRed);
  tg8->SetMarkerSize(0.8);
  tg8->SetMarkerStyle(21);
  // tg8->Draw("P,same");              // or P for points

  tg9->SetLineColor(kRed);
  tg9->SetLineWidth(2);
  tg9->SetLineStyle(2);
  tg9->SetMarkerColor(kRed);
  tg9->SetMarkerSize(0.8);
  tg9->SetMarkerStyle(21);
  // tg9->Draw("P,same");              // or P for points

  tg10->SetLineColor(kBlack);
  tg10->SetLineWidth(2);
  tg10->SetLineStyle(2);
  tg10->SetMarkerColor(kBlack);
  tg10->SetMarkerSize(0.8);
  tg10->SetMarkerStyle(20);
  tg10->Draw("P,same");              // or P for points

  tg11->SetLineColor(kBlack);
  tg11->SetLineWidth(2);
  tg11->SetLineStyle(2);
  tg11->SetMarkerColor(kBlack);
  tg11->SetMarkerSize(0.8);
  tg11->SetMarkerStyle(20);
  tg11->Draw("P,same");              // or P for points

  tg12->SetLineColor(kBlack);
  tg12->SetLineWidth(2);
  tg12->SetLineStyle(2);
  tg12->SetMarkerColor(kBlack);
  tg12->SetMarkerSize(0.8);
  tg12->SetMarkerStyle(20);
  // tg12->Draw("P,same");              // or P for points

  tg13->SetLineColor(kBlack);
  tg13->SetLineWidth(2);
  tg13->SetLineStyle(3);
  tg13->SetMarkerColor(kBlack);
  tg13->SetMarkerSize(0.8);
  tg13->SetMarkerStyle(20);
  // tg13->Draw("L,same");              // or P for points

  tg14->SetLineColor(kBlack);
  tg14->SetLineWidth(2);
  tg14->SetLineStyle(3);
  tg14->SetMarkerColor(kBlack);
  tg14->SetMarkerSize(0.8);
  tg14->SetMarkerStyle(20);
  // tg14->Draw("L,same");              // or P for points

  tg15->SetLineColor(kBlack);
  tg15->SetLineWidth(2);
  tg15->SetLineStyle(3);
  tg15->SetMarkerColor(kBlack);
  tg15->SetMarkerSize(0.8);
  tg15->SetMarkerStyle(20);
  // tg15->Draw("L,same");              // or P for points


  TLegend* leg = new TLegend(0.53, 0.48, 0.95, .73); // x1, y1, x2, y2
  leg->SetTextSize(0.05);
  leg->SetTextFont(42);
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->AddEntry(tg1, " s / #sqrt{b + #sigma_{b}^{2}}", "l");
  leg->AddEntry(tg4, "  Z_{A}", "l");
  // leg->AddEntry(tg7, " #sqrt{q0}, MC median", "p");
  leg->AddEntry(tg10, " Monte Carlo", "p");
  // leg->AddEntry(tg13, " Z_{bi}" , "l");
  // leg->AddEntry(tg4, "s = 0.03", "l");
  leg->Draw();

  TLatex* tl = new TLatex();
  tl->SetTextAlign(11);
  tl->SetTextSize(0.05);
  tl->SetTextFont(42);
  tl->SetNDC();
  // tl->DrawLatex(.76, 0.33, "s = 2");  
  // tl->DrawLatex(.76, 0.465, "s = 5");  
  // tl->DrawLatex(.76, 0.6, "s = 10");  
  //   tl->DrawLatex(.76, 0.73, "s = 20");  

  // tl->DrawLatex(.5, .77, "#sigma_{b}/b = 0.2, 0.5, 1");
  tl->DrawLatex(.5, .77, "#sigma_{b}/b = 0.2, 0.5");
  tl->DrawLatex(.5, .85, "s = 5");

  // Fix idiotic problem with frame

  TLine* tli = new TLine();
  tli->SetLineStyle(1);
  tli->SetLineWidth(1);
  tli->DrawLine(xMin, yMin, xMax, yMin);
  tli->DrawLine(xMax, yMin, xMax, yMax);
  tli->DrawLine(xMin, yMax, xMax, yMax);
  tli->DrawLine(xMin, yMin, xMin, yMax);

  TPostScript psfile("medsig_s5_rel_bi.eps", 113);     // 113 makes eps
  canvas->Draw();
  psfile.Close();
  // canvas->Print("plot.gif", "gif");

}
void makePlot(const std::string& inputFilePath, const std::string& canvasName, const std::string& histogram, const std::string& channel, const std::string& xAxisTitle, const std::string& yAxisTitle,
	      const std::string& inputFileName, const std::string& outputFilePath, const std::string& outputFileName)
{
  std::string inputFileName_full = Form("%s%s", inputFilePath.data(), inputFileName.data());
  TFile* inputFile = new TFile(inputFileName_full.data());
  if ( !inputFile ) {
    std::cerr << "Failed to open input file = " << inputFileName_full << " !!" << std::endl;
    assert(0);
  }

  inputFile->ls();

  TCanvas* canvas = dynamic_cast<TCanvas*>(inputFile->Get(canvasName.data()));
  if ( !canvas ) {
    std::cerr << "Failed to load canvas = " << canvasName << " !!" << std::endl;
    assert(0);
  }

  int idxPad = -1;
  if ( histogram == "mVis"    ) idxPad = 1;
  if ( histogram == "mTauTau" ) idxPad = 2;
  if ( !(idxPad >= 1 && idxPad <= 2) ) {
    std::cerr << "Invalid histogram = " << histogram << " !!" << std::endl;
    assert(0);
  }
  TVirtualPad* pad = canvas->GetPad(idxPad);
  std::cout << "pad = " << pad << ": ClassName = " << pad->ClassName() << std::endl;

  TCanvas* canvas_new = new TCanvas("canvas_new", "canvas_new", 900, 850);
  canvas_new->SetFillColor(10);
  canvas_new->SetBorderSize(2);
  canvas_new->SetTopMargin(0.065);
  canvas_new->SetLeftMargin(0.17);
  canvas_new->SetBottomMargin(0.155);
  canvas_new->SetRightMargin(0.045);
  canvas_new->SetLogx(false);
  canvas_new->SetLogy(false);
  canvas_new->Draw();
  canvas_new->cd();

  //TList* pad_primitives = canvas->GetListOfPrimitives();
  TList* pad_primitives = pad->GetListOfPrimitives();

  TH1* histogramDYJets   = 0;
  TH1* histogramHiggs125 = 0;
  TH1* histogramHiggs200 = 0;
  TH1* histogramHiggs300 = 0;

  TIter pad_nextObj(pad_primitives);
  while ( TObject* obj = pad_nextObj() ) {
    std::string objName = "";
    if ( dynamic_cast<TNamed*>(obj) ) objName = (dynamic_cast<TNamed*>(obj))->GetName();    
    std::cout << "obj = " << obj << ": name = " << objName << ", type = " << obj->ClassName() << std::endl;

    TH1* tmpHistogram = dynamic_cast<TH1*>(obj);
    if ( tmpHistogram ) {
      std::cout << "tmpHistogram:" 
		<< " fillColor = " << tmpHistogram->GetFillColor() << ", fillStyle = " << tmpHistogram->GetFillStyle() << ","
		<< " lineColor = " << tmpHistogram->GetLineColor() << ", lineStyle = " << tmpHistogram->GetLineStyle() << ", lineWidth = " << tmpHistogram->GetLineWidth() << ","
		<< " markerColor = " << tmpHistogram->GetMarkerColor() << ", markerStyle = " << tmpHistogram->GetMarkerStyle() << ", markerSize = " << tmpHistogram->GetMarkerSize() << ","
		<< " integral = " << tmpHistogram->Integral() << std::endl;
      if ( tmpHistogram->GetFillColor() ==   0 ) histogramDYJets   = tmpHistogram;
      if ( tmpHistogram->GetFillColor() == 632 ) histogramHiggs125 = tmpHistogram;
      if ( tmpHistogram->GetFillColor() == 616 ) histogramHiggs200 = tmpHistogram;
      if ( tmpHistogram->GetFillColor() == 600 ) histogramHiggs300 = tmpHistogram;
    }
  }

  if ( !(histogramDYJets && histogramHiggs125 && histogramHiggs200 && histogramHiggs300) ) {
    std::cerr << "Failed to load histograms !!" << std::endl;
    assert(0);
  }

  int lineColors[4] = { 1, 2, 6, 4 };
  int lineStyles[4] = { 1, 1, 1, 1 };
  int lineWidths[4] = { 2, 2, 2, 2 };
  int fillColors[4] = { 10, 2, 6, 4 };
  int fillStyles[4] = { 0, 3002, 3004, 3005 };

  histogramDYJets->SetFillColor(fillColors[0]);
  histogramDYJets->SetFillStyle(fillStyles[0]);
  histogramDYJets->SetLineColor(lineColors[0]);
  histogramDYJets->SetLineStyle(lineStyles[0]);
  histogramDYJets->SetLineWidth(lineWidths[0]);

  histogramHiggs125->SetFillColor(fillColors[1]);
  histogramHiggs125->SetFillStyle(fillStyles[1]);
  histogramHiggs125->SetLineColor(lineColors[1]);
  histogramHiggs125->SetLineStyle(lineStyles[1]);
  histogramHiggs125->SetLineWidth(lineWidths[1]);

  histogramHiggs200->SetFillColor(fillColors[2]);
  histogramHiggs200->SetFillStyle(fillStyles[2]);
  histogramHiggs200->SetLineColor(lineColors[2]);
  histogramHiggs200->SetLineStyle(lineStyles[2]);
  histogramHiggs200->SetLineWidth(lineWidths[2]);

  histogramHiggs300->SetFillColor(fillColors[3]);
  histogramHiggs300->SetFillStyle(fillStyles[3]);
  histogramHiggs300->SetLineColor(lineColors[3]);
  histogramHiggs300->SetLineStyle(lineStyles[3]);
  histogramHiggs300->SetLineWidth(lineWidths[3]);

  TAxis* xAxis = histogramHiggs300->GetXaxis();
  if ( histogram == "mVis"    ) xAxis->SetRangeUser(0,350);
  else xAxis->SetRangeUser(0,450);
  xAxis->SetTitle(xAxisTitle.data());
  xAxis->SetTitleOffset(1.00);
  xAxis->SetTitleSize(0.070);
  xAxis->SetTitleFont(42);
  xAxis->SetLabelOffset(0.010);
  xAxis->SetLabelSize(0.050);
  xAxis->SetLabelFont(42);
  xAxis->SetTickLength(0.040);
  xAxis->SetNdivisions(505);

  //double xMin = 20.;
  //double xMax = xAxis->GetXmax();
  //xAxis->SetRangeUser(xMin, xMax);

  TAxis* yAxis = histogramHiggs300->GetYaxis();
  yAxis->SetTitle(yAxisTitle.data());
  yAxis->SetTitleOffset(1.20);
  yAxis->SetTitleSize(0.070);
  yAxis->SetTitleFont(42);
  yAxis->SetLabelOffset(0.010);
  yAxis->SetLabelSize(0.055);
  yAxis->SetLabelFont(42);
  yAxis->SetTickLength(0.040);  
  yAxis->SetNdivisions(505);

  histogramHiggs300->SetTitle("");
  histogramHiggs300->SetStats(false);
  histogramHiggs300->SetMaximum(1.2*histogramDYJets->GetMaximum());
  histogramHiggs300->SetMinimum(0.);
  histogramHiggs300->Draw("hist");
  histogramHiggs200->Draw("histsame");
  histogramHiggs125->Draw("histsame");
  histogramDYJets->Draw("histsame");
  histogramHiggs300->Draw("axissame");

  TLegend* legend_new = new TLegend(0.50, 0.62, 0.87, 0.92, NULL, "brNDC");
  legend_new->SetFillColor(10);
  legend_new->SetFillStyle(0);
  legend_new->SetBorderSize(0);
  legend_new->SetTextFont(42);
  legend_new->SetTextSize(0.055);
  legend_new->SetTextColor(1);
  legend_new->SetMargin(0.20);
  legend_new->AddEntry(histogramDYJets, "Z/#gamma* #rightarrow #tau#tau", "f");
  legend_new->AddEntry(histogramHiggs125, "H(125 GeV) #rightarrow #tau#tau", "f");
  legend_new->AddEntry(histogramHiggs200, "H(200 GeV) #rightarrow #tau#tau", "f");
  legend_new->AddEntry(histogramHiggs300, "H(300 GeV) #rightarrow #tau#tau", "f");
  legend_new->Draw();

  double label_channel_y0;
  if      ( channel == "e#mu"             ) label_channel_y0 = 0.9275;
  else if ( channel == "#mu#tau_{h}"      ) label_channel_y0 = 0.9400;
  else if ( channel == "#tau_{h}#tau_{h}" ) label_channel_y0 = 0.9350;
  else {
    std::cerr << "Invalid channel = " << channel << " !!" << std::endl;
    assert(0);
  }
  TPaveText* label_channel = new TPaveText(0.855, label_channel_y0, 0.945, label_channel_y0 + 0.055, "NDC");
  label_channel->SetFillStyle(0);
  label_channel->SetBorderSize(0);
  label_channel->AddText(channel.data());
  label_channel->SetTextFont(62);
  label_channel->SetTextSize(0.055);
  label_channel->SetTextColor(1);
  label_channel->SetTextAlign(31);
  label_channel->Draw();

  canvas_new->Update();

  std::string outputFileName_full = Form("%s%s", outputFilePath.data(), outputFileName.data());
  size_t idx = outputFileName_full.find_last_of('.');
  std::string outputFileName_plot = std::string(outputFileName_full, 0, idx);
  canvas_new->Print(std::string(outputFileName_plot).append(".pdf").data());
  //canvas_new->Print(std::string(outputFileName_plot).append(".root").data());

  delete legend_new;
  delete label_channel;
  delete canvas_new;

  delete inputFile;
}
Esempio n. 6
0
void plot_Comb(void) {

    gROOT->ProcessLine(".L ../tools/plottools.C");
    gStyle->SetPadGridX(kFALSE);
    gStyle->SetPadGridY(kFALSE);

    //SET UP FINE THEORY
    ifstream in_xsec_massNNLO4("../style/DY/root/Plain/NNLO/8TeV_CTEQ12NNLO_41.txt",ios::in);
    const int nbins4  = 339+179+25;
    double mass_xbin4[nbins4] = {0.};
    double initial = 14.0;
    for( int i = 0; i < nbins4; i++ ) {
        if( i >= 0 && i < 11 ) {
            initial += 1.0;
        }
        else if( i >= 11 && i < 18 ) {
            initial += 5.0;
        }
        else if( i >= 18 && i < 118 ) {
            initial += 1.0;
        }
        else if( i >= 118 && i < 338 ) {
            initial += 2.0;
        }
        else if (i >= 338 && i < 542-24) {
            initial += 5.0;
        } else {
            initial += 20.0;
        }
        mass_xbin4[i] = initial;
    }
    TH1D* h_theory4  = new TH1D("xsec4_NNLO","xsec4_NNLO",nbins4-1,mass_xbin4);
    TH1D* h_theory4_band  = new TH1D("xsec4_bandNNLO","xsec4_bandNNLO",nbins4-1,mass_xbin4);
    double xsec_mass4[nbins4-1];
    double xsec_err_mass4[nbins4-1];

    for( int i = 0; i < nbins4-1; i++ ) {
        double dm_ = mass_xbin4[i+1]-mass_xbin4[i];

        //NNLO
        in_xsec_massNNLO4 >> xsec_mass4[i] >>  xsec_err_mass4[i] ;
        //FIXME fix the kink at high mass, artificially
        xsec_mass4[i] *= weightProducer(mass_xbin4[i+1]);

        double peak = 1137.2;
        if (IS_RSHAPE) {
            h_theory4_band->SetBinContent(i+1,xsec_mass4[i]/dm_/peak);
            //controls error band
            h_theory4_band->SetBinError(i+1,0.1*h_theory4_band->GetBinContent(i+1));///peak);
            h_theory4->SetBinContent(i+1,xsec_mass4[i]/dm_/peak);
            h_theory4->SetBinError(i+1,0.0);//sqrt(pow(xsec_mass4[i]*10./peak_val_theory/peak_val_theory,2)));
        } else {
            h_theory4_band->SetBinContent(i+1,xsec_mass4[i]/dm_);
            h_theory4_band->SetBinError(i+1,0.1*h_theory4_band->GetBinContent(i+1));
            h_theory4->SetBinContent(i+1,xsec_mass4[i]/dm_);
            h_theory4->SetBinError(i+1,0.0);//sqrt(pow(xsec_mass4[i]*10./peak_val_theory/peak_val_theory,2)));
        }
    }
    average(h_theory4_band);
    average(h_theory4);

    //ACCESS VALUES
    TFile* f;
    if (IS_7TEV) f = new TFile("../Inputs/Theory/1Dabsxsec_NNLO_CTEQ12NNLO_7TeV.root");
    else f = new TFile("../Inputs/Theory/1Dabsxsec_NNLO_CTEQ12NNLO"+has41+".root");
    f->cd();
    TH1D* theory = (TH1D*)gDirectory->Get("invm_FEWZ"+has41);
    double peak_th = theory->Integral(10,22);
    for (int i = 0; i < 41; i++) {
        theory->SetBinContent(i+1,theory->GetBinContent(i+1)/theory->GetBinWidth(i+1));
    }
    TH1D* rshape_theory = (TH1D*)theory->Clone();
    for (int i = 0; i < 41; i++) {
        rshape_theory->SetBinContent(i+1,theory->GetBinContent(i+1)/peak_th);
        rshape_theory->SetBinError(i+1,theory->GetBinError(i+1)/peak_th);
    }
    if (IS_RSHAPE) theory = rshape_theory;

    TFile* g;
    if (!IS_RSHAPE) {
        if (IS_7TEV)  g = new TFile("/group/cms/users/asvyatko/CMSSW_4_2_8/src/DYPackage/Outputs/absex_full2011.root");
        else g = new TFile("../Outputs/absex_full_comb_PI_Bayesian.root");
    } else {
        if (IS_7TEV) g = new TFile("/group/cms/users/asvyatko/CMSSW_4_2_8/src/DYPackage/Outputs/rshape_full_mumuCurrentMarch.root");
        else g = new TFile("../Outputs/absex_full_comb_PI_Bayesian.root");
    }
    g->cd();
    TH1D* data = (TH1D*)hxsec->Clone();
    double peak = 0;
    double peak_err = 0.01; //1% approx, for the plot only
    for (int i = 9; i < 22; i++) {
        peak += data->GetBinContent(i+1)*data->GetBinWidth(i+1);
    }
    cout << "Peak comb data: " << peak<< endl;
    TH1D* rshape_data = (TH1D*)hxsec->Clone();
    for (int i = 0; i < 41; i++) {
        //Note: it is already pre-divided by the bin width
        rshape_data->SetBinContent(i+1,data->GetBinContent(i+1)/peak);
        rshape_data->SetBinError(i+1,sqrt(pow(data->GetBinError(i+1)/peak,2)+pow(peak_err*rshape_data->GetBinContent(i+1),2)));
    }
    if (IS_RSHAPE && !IS_7TEV) data = rshape_data;

    TGraphAsymmErrors* gdata = new TGraphAsymmErrors(nbin-1);
    for( size_t ii=0; ii<nbin; ii++ )
    {
        double x_ = fake_par[ii];
        double y_ = data->GetBinContent(ii+1);
        double exl_ = fake_par[ii]-mass_xbin[ii];
        double exh_ = mass_xbin[ii+1]-fake_par[ii];
        double eyl_ = data->GetBinError(ii+1);
        double eyh_ = eyl_;
        gdata->SetPoint(ii,x_,y_);
        gdata->SetPointError(ii,exl_,exh_,eyl_,eyh_);
    }

//FIXME need ratio plots
    TCanvas *c1 = new TCanvas("CrossSect1D","CrossSect1D",600,600);
    c1->Draw();
    c1->cd();
    TPad *p1 = new TPad("p1", "",0.0,0.25,1.0,0.98,0,0,0);
    p1->Draw();
    p1->cd();
    //p1->SetTickx(kFALSE);

    //TAxis *xaxis = h_theory4->GetXaxis();
    //xaxis->SetMoreLogLabels();
    //xaxis->SetNoExponent();

    TAxis *axis = h_theory4->GetYaxis();
    axis->SetTickLength(axis->GetTickLength()/1.35);
    //axis->SetNdivisions(506);


    p1->SetRightMargin(0.055);
    p1->SetBottomMargin(0.01);
    p1->SetTopMargin(0.1);
    p1->SetLogy();
    p1->SetLogx();
    h_theory4->GetXaxis()->SetMoreLogLabels();
    if (IS_RSHAPE) h_theory4->GetYaxis()->SetTitle("1/#sigma_{Z}d#sigma/dm [GeV^{-1}]");
    else h_theory4->GetYaxis()->SetTitle("d#sigma/dm [pb/GeV]");
    h_theory4->GetXaxis()->SetTitle("m_{#mu#mu} [GeV]");
    h_theory4->SetLineColor(kBlue);
    h_theory4->SetLineWidth(0.1);
    h_theory4->SetMarkerSize(0);
    //h_theory4->SetMaximum(h_theory4->GetMaximum()*100.);
    h_theory4->GetYaxis()->SetRangeUser(h_theory4->GetMinimum()/10.,h_theory4->GetMaximum()*10.);
    h_theory4->SetMinimum(1.5*10E-9);
    h_theory4->Draw("L");

    TH1D* h_theory4_clone = (TH1D*)h_theory4->Clone();
    h_theory4_clone->SetLineWidth(1.5);
    //h_theory4_clone->GetXaxis()->SetRangeUser(40,180);
    h_theory4_clone->Draw("Lsame");
    h_theory4_band->SetLineColor(kBlue);
    h_theory4_band->SetLineWidth(3);
    h_theory4_band->SetMarkerSize(0);
    h_theory4_band->SetFillColor(kBlue);
    h_theory4_band->Draw("E3same");
    //data->Draw("Psame");

    gdata->SetMarkerStyle(20);
    gdata->SetMarkerSize(0.7);
    gdata->Draw("Psame");

    double yminl_ = h_theory4->GetMinimum();
    double ymaxl_ = h_theory4->GetMaximum();
    //draw_bin_grid2( yminl_, 1.7*yminl_ );
    //draw_bin_grid( yminl_, 1.2*yminl_ );
    //draw_bin_grid2( ymaxl_/1.7, ymaxl_ );
    //draw_bin_grid( ymaxl_/1.2, ymaxl_ );

    // text2
    size_t ntxt = 3;
    TString txt[3];
    float txtSize[3];
    float txtX[3];
    float txtY[3];
    int   txtAlign[3];
    int   txtFont[3];

    txt[0] = "CMS"; // Preliminary";
    txtSize[0] = 0.072;
    txtX[0] = 0.27;
    txtY[0] = 0.82;
    txtAlign[0] = 21;
    txtFont[0] = 61;

    //txt[1] = "19.7 fb^{-1} at #sqrt{s} = 8 TeV";
    txt[1] = "19.7 fb^{-1} ee and #mu#mu (8 TeV)";
    txtSize[1] = 0.042;
    txtX[1] = 0.79;
    txtY[1] = 0.91;
    txtAlign[1] = 21;
    txtFont[1] = 42;

    txt[2] = "#gamma*/Z #rightarrow e^{+}e^{-}, #mu^{+}#mu^{-}";
    //txt[2] = "#gamma*/Z #rightarrow #font[11]{l#lower[-0.72]{^{#font[122]{+}}}l^{#font[122]{-}}}");
    txtSize[2] = 0.05;
    txtX[2] = 0.80;
    txtY[2] = 0.82;
    txtAlign[2] = 21;
    txtFont[2] = 42;

    TLatex latex;
    latex.SetNDC();
    for( size_t ii=0; ii<ntxt; ii++ ) {
        latex.SetTextFont(txtFont[ii]);
        latex.SetTextSize(txtSize[ii]);
        latex.SetTextAlign(txtAlign[ii]);
        latex.DrawLatex(txtX[ii],txtY[ii],txt[ii]);
    }

    TLegend *leg= new TLegend(0.21,0.10,0.51,0.30);
    leg->SetTextFont(42);
    leg->SetTextSize(0.055);
    //leg->SetTextAlign(31);
    leg->SetBorderSize(0);
    leg->SetFillColor(0);
    leg->AddEntry(gdata,"data","lp");
    leg->AddEntry(h_theory4_band,"FEWZ, NNLO CT10","f");
    leg->Draw("same");

    TH1D* ratio = (TH1D*)theory->Clone();
    ratio->Divide(data,theory);

    //cout << "XX " << ratio->GetNbinsX() << " " << theory->GetNbinsX() << endl;
    //for (int i = 0; i < ratio->GetNbinsX(); i++) {
    //   cout << i+1 << ratio->GetBinContent(i+1) << endl;
    //}

    //ratio should be a graph
    TGraphAsymmErrors* gratio = new TGraphAsymmErrors(nbin-1);
    for( size_t ii=0; ii<nbin; ii++ )
    {
        double x_ = fake_par[ii];
        double y_ = ratio->GetBinContent(ii+1);
        double exl_ = fake_par[ii]-mass_xbin[ii];
        double exh_ = mass_xbin[ii+1]-fake_par[ii];
        double eyl_ = ratio->GetBinError(ii+1);
        double eyh_ = eyl_;
        gratio->SetPoint(ii,x_,y_);
        gratio->SetPointError(ii,exl_,exh_,eyl_,eyh_);
    }

    gStyle->SetOptTitle(0);
    TPad *p2 = new TPad("p2", "",0.0,0.01,1.0,0.249,0,0,0);
    c1->cd();
    p2->Draw();
    p2->cd();
    p2->SetLogx();
    p2->SetTopMargin(0.007);
    p2->SetBottomMargin(0.32);
    p2->SetRightMargin(0.055);
    //p2->SetTickx(kFALSE);
    TAxis* ay_ = ratio->GetYaxis();

    //ax_->SetNdivisions(0);
    //ax_->SetTitleOffset(1.15);
    //ax_->SetLabelOffset(99);

//ay_->SetTitle(ytitle);
    //  ay_->CenterTitle();
    ay_->SetNdivisions(506); //506);
    ay_->SetLabelOffset(0.019);

    ratio->GetYaxis()->SetTitle("Data/theory");
    ratio->GetXaxis()->SetTitle("m [GeV]");
    ratio->SetStats(kFALSE);
    ratio->GetYaxis()->SetTitleOffset(0.41);
    ratio->GetXaxis()->SetMoreLogLabels();
    ratio->GetYaxis()->SetTitleSize(0.15);
    ratio->GetXaxis()->SetTitleSize(0.155);
    ratio->GetYaxis()->SetLabelSize(0.15);
    ratio->GetXaxis()->SetLabelSize(0);//0.15);
    ratio->GetXaxis()->SetTickLength(0.08);
    ratio->GetXaxis()->SetNoExponent(kTRUE);

    ratio->SetMarkerSize(0);
    ratio->SetMaximum(1.7);  //1.48); //1.75); //1.52);
    ratio->SetMinimum(0.3); ////0.52); //0.25);//0.4);
    ratio->SetLineColor(kBlack);
    ratio->Draw("hist");
    //draw_bin_grid(ratio->GetMinimum(),ratio->GetMaximum());
    yminl_ = ratio->GetMinimum();
    ymaxl_ = ratio->GetMaximum();
    //draw_bin_grid2( yminl_, 1.5*yminl_ );
    //draw_bin_grid( yminl_, 1.2*yminl_ );
    //draw_bin_grid2( ymaxl_/1.07, ymaxl_ );
    //draw_bin_grid( ymaxl_/1.03, ymaxl_ );
    float r0_ = 1.;
    float dr_ = 0.75;
    //draw_axis_labels(r0_-1.09*dr_,0.15);
    draw_axis_labels(r0_-1.0*dr_,0.15);
    gratio->SetMarkerColor(kViolet);
    gratio->SetMarkerSize(0.9);
    gratio->SetLineColor(kBlack);
    gratio->SetMarkerStyle(20);
    gratio->Draw("epsame");
    p2->Update();
    TLine *line=new TLine();
    line->SetLineColor(kBlue);
    line->SetLineWidth(2);
    line->DrawLine(15,1,2000,1);
    //c1->SaveAs(etaclass+run+".pdf"); //_DR53X_HCP2012.png");

    double chisquared = 0.;

    for (int i =0; i < data->GetNbinsX(); i++) {
        chisquared+=pow((data->GetBinContent(i+1)-theory->GetBinContent(i+1)),2)/(data->GetBinError(i+1)*data->GetBinError(i+1));
        //std::cout << data->GetBinError(i+1) << " " << theory->GetBinError(i+1) << std::endl;
        //chisquared+=(ee8->GetBinContent(i+1)-mumu8->GetBinContent(i+1))/sqrt(ee8->GetBinError(i+1)*mumu8->GetBinError(i+1));
    }
    cout << "Full chi2 " << chisquared/double(data->GetNbinsX()) << " " << TMath::Prob(chisquared,data->GetNbinsX())<< endl;

}