Esempio n. 1
0
void UCTRateTree::ComparePlots(TList * vRates, const char * title, const char * saveAs) {
  
  std::stringstream cc;
  cc << "L1UCTRates_" << ncanvas;
  
  m_canvas[title] = new TCanvas(cc.str().c_str(), "L1 and UCT rates", 600, 600);
  m_canvas[title]->SetLogy();
  m_canvas[title]->SetFillColor(10);
  m_canvas[title]->cd();
  
  if ( vRates->GetSize() == 0 || vRates->GetSize() < 2) {
    std::cout << "Cannot compare!" << std::endl;
    return;
  }
  
  int max = vRates->GetSize();
  
  TLegend * legend;

  std::cout << " * " << m_largeLegend << std::endl;

  if( m_largeLegend ) 
    legend = new TLegend(0.32,0.57,0.87,0.91, "", "brNDC");
  else
    legend = new TLegend(0.32,0.75,0.74,0.91, "", "brNDC");

  legend->SetFillColor(kWhite);
  legend->SetBorderSize(1);

  

  for(int k=0; k < max; ++k ) {
    
    TH1F * h1 = ((RateHisto*)vRates->At(k))->m_rate;
  
    if ( k == 0 ) {
      
      h1->SetTitle(title);
      h1->GetXaxis()->SetTitle( ((RateHisto*)vRates->At(k))->m_label.c_str() ) ;
      h1->GetYaxis()->SetTitle( "Rate ( Hz )") ;
      h1->SetMaximum(7.0E7);
      h1->SetMinimum(1000);
      legend->AddEntry(h1, ((RateHisto*)vRates->At(k))->m_legend.c_str(), "p");
      h1->Draw("ph");

    }
    else {
      legend->AddEntry(h1, ((RateHisto*)vRates->At(k))->m_legend.c_str(), "p");
      h1->Draw("phsame");
    }
    
  }
  
  legend->Draw();
  cmsPrelim();
  m_canvas[title]->SaveAs( saveAs );
  
  ++ncanvas;

}
void plotResolution( char* var, float xmin, float xmax, const char * region, const char *xbinning, const char * skim, int regionCode, 
		     std::ofstream * resultsStg1,
		     std::ofstream * resultsStg2 ) {
  
  //Log file
  
  TString log_subdir("./logs/");
  TString resolution_log = TString("resolution_PVbins_") + TString(var) + TString("_") + TString(skim) + TString(".log");

  std::ofstream * logfile = new std::ofstream( (log_subdir + resolution_log).Data(), ios_base::app );

  TDatime *d1 = new TDatime();
  (*logfile) << d1->AsString() << std::endl;

  //Output path
  TString path("./slhc-plots/resolution/Taus/noPUC/isoStudies");
  
  TString varName = TString("reco") + TString(var);  // RECO(PFTau)
  TString l1varName = TString("l1g") + TString(var); // L1 Calo Upgrade (can be Stage 1 or Stage 2)
  
  gROOT->SetStyle("Plain");
  gROOT->SetBatch(false);
  gStyle->SetOptStat(0);

  // --- Use the CMS TDR style
  gROOT->ProcessLine(".L tdrStyle.C");
  setTDRStyle();
  tdrStyle->SetErrorX(0.5);
  tdrStyle->SetPadLeftMargin(0.18);
  tdrStyle->SetPadRightMargin(0.08);
  tdrStyle->SetLegendBorderSize(0);
  tdrStyle->SetTitleYOffset(1.3);
  tdrStyle->SetOptStat(0);
  tdrStyle->SetOptFit(0);
  tdrStyle->SetTitleFontSize(0.05);
  tdrStyle->SetStatStyle(0);

  TFile * f1 = new TFile("/uscms/home/aosorio/nobackup/scratch0/SLHC_BKP/root_files/L1Tree_Htt_MC_RAWRECO_MC_VisTau.root");

  f1->cd();

  TTree * Stage1Taus = (TTree*)gDirectory->Get("rlxTauSt1Efficiency/Ntuple");

  TTree * Stage2Taus = (TTree*)gDirectory->Get("rlxTauSt2Efficiency/Ntuple");
  
  std::cout << " Ntuple ready: " << Stage1Taus << " " << Stage2Taus << std::endl;
  
  TCanvas * canvas = new TCanvas("asdf", "adsf", 800, 600);
  canvas->Draw();
  
  TList * Stage1Histos = new TList();
  TList * Stage2Histos = new TList();
  
  //this is to separate into different decay mode as in reco::PFTau::hadronicDecayMode
  // Enumerator:
  // -1 kNull
  //  0 kOneProng0PiZero
  //  1 kOneProng1PiZero
  //  2 kOneProng2PiZero
  //  ...
  // 10 kThreeProng0PiZero

  int decayMode[10] = {0};
  
  for( int k = 0 ; k < 1; ++k ) {
    
    double m1   = 0.0;
    double area = 0.0;
    double yMax = 0.0;
    
    int xMin = xmin;
    int xMax = xmax;
    
    char cuts[200];
    
    //this is to use the decayMode:
    sprintf(cuts, " ( l1Pt >= 25.0 && l1gMatch >= 1.0 )&& %s && nPVs > %d && nPVs < %d && decayMode >= %d && decayMode < 3", region, xMin, xMax, decayMode[k]);
    
    TString histoDraw = TString("(") + TString( l1varName ) + TString(" - ") + TString(varName) + TString(")/") + TString(varName) + TString(">> ");
    
    char st1HistoName[100];
    sprintf(st1HistoName, "htempSt1_%d", k);
    
    char st2HistoName[100];
    sprintf(st2HistoName, "htempSt2_%d", k);

    TH1D* h1T = new TH1D(st1HistoName, "", 50, -2, 2);
    h1T->Sumw2();

    TH1D* h2T = new TH1D(st2HistoName, "", 50, -2, 2);
    h2T->Sumw2();

    Stage1Taus->Draw( histoDraw + TString(st1HistoName), cuts, "");
    TH1F* h1 = (TH1F*)gDirectory->Get( st1HistoName )->Clone();
    area = h1->Integral();
    h1->Scale( 1.0/area );
    
    m1 = h1->GetMaximum();
    
    if ( m1 > yMax ) 
      yMax = m1;
    
    std::cout << h1 << std::endl;
    Stage1Histos->Add( h1 );
    
    Stage2Taus->Draw( histoDraw + TString(st2HistoName), cuts, "");
    TH1F* h2 = (TH1F*)gDirectory->Get( st2HistoName )->Clone();
    area = h2->Integral();
    h2->Scale( 1.0/area );
    m1 = h2->GetMaximum();
    
    if ( m1 > yMax ) 
      yMax = m1;

    std::cout << h2 << std::endl;
    Stage2Histos->Add( h2 );
    
    canvas->cd();
    
    TF1 * stg1Fit = new TF1("g1","gaus",h1->GetXaxis()->GetXmin(), h1->GetXaxis()->GetXmax() );
    TF1 * stg1Fit = new TF1("g2","gaus",h1->GetXaxis()->GetXmin(), h1->GetXaxis()->GetXmax() );
    
    h1->GetXaxis()->SetLabelFont(42);
    h1->GetXaxis()->SetTitleOffset(1.34);
    h1->GetXaxis()->SetTitleFont(42);
    h1->GetYaxis()->SetTitle("A.U.");
    h1->GetYaxis()->SetLabelFont(42);
    h1->GetYaxis()->SetTitleOffset(1.3);
    h1->GetYaxis()->SetTitleFont(42);

    h1->SetMaximum( yMax + (yMax*0.30) );
    h2->SetMaximum( yMax + (yMax*0.30) );

    h1->SetLineColor(2);
    h1->Draw("e0");
    h1->Clone()->Draw("histsame");
    
    h1->Fit("g1");
   
    h2->SetLineColor(4);
    h2->Draw("lsame");
    h2->Clone()->Draw("histsame");
    h2->Fit("g2");

    tdrStyle->SetStatStyle(0);

    TF1 * fitFun = (TF1*)h1->GetListOfFunctions()->FindObject("g1");
    fitFun->SetLineColor(2);
    fitFun->SetLineWidth(2);
    fitFun->SetLineStyle(2);
    
    (*logfile) << "Fit results h1 reg: " << regionCode << " decaymode: " << k << '\t';
    (*logfile) << fitFun->GetParameter(1) << '\t'
	       << fitFun->GetParameter(2) << '\n';

    (*resultsStg1) << xMin << '\t'
		   << fitFun->GetParameter(2) << '\t'
		   << fitFun->GetParError(2) << '\n';
    
    char sigma1[50];
    sprintf(sigma1, "= %f", fitFun->GetParameter(2) );

    fitFun = (TF1*)h2->GetListOfFunctions()->FindObject("g2");
    fitFun->SetLineColor(4);
    fitFun->SetLineWidth(2);
    fitFun->SetLineStyle(2);

    (*logfile) << "Fit results h2 reg: " << regionCode << " decaymode: " << k << '\t';
    (*logfile) << fitFun->GetParameter(1) << '\t'
	       << fitFun->GetParameter(2) << '\n';

    (*logfile) << " xmin " << xmin  << " xmax " << xmax << std::endl;

    (*resultsStg2) << xMin << '\t'
		   << fitFun->GetParameter(2) << '\t'
		   << fitFun->GetParError(2) << '\n';
    
    char sigma2[50];
    sprintf(sigma2, "= %f", fitFun->GetParameter(2) ); // get the sigma

    h1->SetMaximum( yMax + (yMax*0.30) );

    h1->Draw("same");
    h2->Draw("same");
    
    //
    TString stage1Leg = TString("MC Stage 1 #sigma") + TString(sigma1);
    
    TString stage2Leg = TString("MC Stage 2 #sigma") + TString(sigma2);
    
    
    //////////////////////////////////////////////////
    TLegend * leg = new TLegend(0.21,0.72,0.44,0.86);
    leg->AddEntry( h1, stage1Leg.Data() );
    leg->AddEntry( h2, stage2Leg.Data() );
    leg->SetBorderSize(0);
    leg->SetTextSize(0.032);
    leg->SetLineColor(1);
    leg->SetLineStyle(1);
    leg->SetLineWidth(1);
    leg->SetFillColor(0);
    leg->SetFillStyle(1001);

    leg->Draw();

    cmsPrelim();

    std::stringstream saveAs;
    
    saveAs.str("");
    saveAs << path << "/eps/rlx_mctau_reso_" << skim << "_" << var << "_" << xMin << "_" << xMax << "_dcm_" << k << "_" << regionCode << ".eps";
    canvas->SaveAs( saveAs.str().c_str() );
    
    saveAs.str("");
    saveAs << path << "/pdf/rlx_mctau_reso_" << skim << "_" << var << "_" << xMin << "_" << xMax << "_dcm_" << k << "_" << regionCode << ".pdf";
    canvas->SaveAs( saveAs.str().c_str() );
    
    //png output not working properly - fitted curve is not fully draw - removed as output (work around -> convert from pdf to png)
    
  }
  

  logfile->close();
  delete logfile; 


}
Esempio n. 3
0
void LEPStyle::draw()
{
  if( _canv==0 )
    {
      setCanvas();
      setHist();
      _canv->Draw();
      if( _ymin==0 ) _ymin = 0.2;
      //  _ymax = _n*1.5; 
      if( _ymax==0 ) _ymax = _n+_upDy;
      _hist->SetMinimum( _ymin  );
      _hist->SetMaximum( _ymax );
      
      _hist->Draw();

      if( _cmsPrelim ) cmsPrelim( _intLumi );
    }

  //  size_t n_ = _entry.size();
  _n = _entry.size();
  
  if( _extraBand )
    {
      drawExtraBand();
    }
 
  if( _band )
    {
      Double_t xx_[5] = { _bxmin, _bxmax, _bxmax, _bxmin, _bxmin };
      float eps1_ = _eps1*(_ymax-_ymin);
      float eps2_ = _eps2*(_ymax-_ymin);
      Double_t yy_[5] = { _ymin+eps1_, _ymin+eps1_, _ymax-eps2_, _ymax-eps2_, _ymin+eps1_ };
      TPolyLine* pl_ = new TPolyLine( 5, xx_, yy_ );
      pl_->SetFillStyle(_bandFillStyle);
      pl_->SetFillColor(_bandFillColor);
      pl_->SetLineWidth(3);
      pl_->SetLineColor( kOrange );
      pl_->DrawClone("FSame");
      TLine* l_ = new TLine( _bx0, _ymin+eps1_, _bx0, _ymax-eps2_  );
      l_->SetLineWidth(4);
      l_->SetLineColor( kOrange );
      l_->DrawClone();


      if( _hasLegend )
	{

	  cout << "HELLO!!!!" << endl;
	  //      _y0 = 4.0;
	  if( _y0==0 ) _y0 = _n+2*_upDy/3.;
	  if( _dy==0 ) _dy = 0.06;
	  _x0 = _xmax - 0.05*(_xmax-_xmin);
	  
	  TLatex leg1_;
	  leg1_.SetTextSize(_scale*0.05);      
	  leg1_.SetTextAlign(31); 
	  leg1_.DrawLatex( _x0, _y0+_dy, _legend );
	  
	  
	  TLatex leg2_;
	  leg2_.SetTextSize(_scale*0.05);      
	  leg2_.SetTextAlign(23); 
	  leg2_.DrawLatex( _bx0, _y0-_dy, _theory );

	}

//       TLegend* legend=new TLegend(_x0,_y0, _x0+_dx, _y0+_dy );
//       legend->SetLineColor(0);
//       legend->SetFillColor(0);
      
//       //      legend->AddEntry(pl_,_legend,"lf");
//       legend->AddEntry(pl_,_legend,"");

//       legend->Draw("same");
      

    }

  for( size_t ii=0; ii<_entry.size(); ii++ )
    {
      if( _entry[ii]==("SPACE") ) continue;
      Float_t  xval_[1];
      Float_t  yval_[1];
      Float_t    ey_[1];
      Float_t estatup_[1];
      Float_t ecombup_[1];
      Float_t etotup_[1];
      Float_t estatlo_[1];
      Float_t ecomblo_[1];
      Float_t etotlo_[1];

      float yy_ = _n-(Float_t)ii;
      xval_[0] = _val[ii];
      yval_[0] = yy_;
      ey_[0] = 0;

      estatup_[0] = _statup[ii];
      ecombup_[0] = sqrt( pow( _statup[ii],2 ) + pow( _systup[ii],2 ) );
      etotup_[0] = ecombup_[0] + _lumi[ii];

      estatlo_[0] = _statlo[ii];
      ecomblo_[0] = sqrt( pow( _statlo[ii],2 ) + pow( _systlo[ii],2 ) );      
      etotlo_[0] = ecomblo_[0] + _lumi[ii];

      TGraphAsymmErrors* gtot_  = new TGraphAsymmErrors( 1, xval_, yval_, etotlo_, etotup_, ey_, ey_ );
      gtot_->SetLineColor( kGreen );
      TGraphAsymmErrors* gcomb_ = new TGraphAsymmErrors( 1, xval_, yval_, ecomblo_, ecombup_, ey_, ey_ );
      gcomb_->SetLineColor( kRed );
      TGraphAsymmErrors* gstat_ = new TGraphAsymmErrors( 1, xval_, yval_, estatlo_, estatup_, ey_, ey_ );
      gstat_->SetLineColor( kBlack );
      gstat_->SetLineWidth( 2 );
      gstat_->SetMarkerStyle( _marker[ii] );
      gstat_->SetMarkerSize( _size[ii] );
      gstat_->SetMarkerColor( _color[ii] );

      gcomb_->SetLineWidth( 2 );

      gtot_->SetLineWidth( 2 );

      if( _lumi[ii]>0 )
	gtot_->Draw();

      gcomb_->DrawClone();
      gstat_->DrawClone("P");



      if( !_writeText ) continue;

      //   align = 10*HorizontalAlign + VerticalAlign
      // For Horizontal alignment the following convention applies:
      //   1=left adjusted, 2=centered, 3=right adjusted
      // For Vertical alignment the following convention applies:
      //   1=bottom adjusted, 2=centered, 3=top adjusted
      float xtxt_ = _xmin + 0.05*(_xmax-_xmin);
      TLatex ltx1_;

      ltx1_.SetTextSize(_scale*_size1);      
      ltx1_.SetTextAlign(_align1);
      if( _specifyPlacement )
	ltx1_.DrawLatex( _xx1, yy_+_e1, _entry[ii] );
      else
	ltx1_.DrawLatex( xtxt_, yy_+E_+e_, _entry[ii] );

      TLatex ltx2_;

      char line_[512];

      TString str_;
      TString pmstr_(" #pm ");
      TString format_("%-4.");
      format_ += _ndigit[ii];
      format_ += "f";
      TString valstr_;
      TString statstr_;
      TString syststr_;
      TString lumistr_;

      sprintf( line_, format_.Data(), _val[ii] );
      // sprintf( line_,  "%-4.3f", _val[ii] );
      valstr_ = line_;

      if( fabs( _statup[ii]-_statlo[ii] )<0.01 )
	{
	  sprintf( line_, format_.Data(), _statlo[ii] );
	}
      else
	{
	  sprintf( line_, "#scale[0.7]{#splitline{+%-4.3f}{-%-4.3f}}_{ stat.}", _statup[ii], _statlo[ii] );
	}

      statstr_ = line_;
      str_ = valstr_ + pmstr_ + statstr_;
      str_ += "_{ ";
      str_ += _firstError;
      str_ += "}";

      if( _systup[ii]>0 )
	{
	  if( fabs( _systup[ii]-_systlo[ii] )<0.01 )
	    {
	      sprintf( line_, format_.Data(), _systlo[ii] );
	    }
	  else 
	    {
	      sprintf( line_, "#scale[0.7]{#splitline{+%-4.3f}{- %-4.3f}}_", _systup[ii], _systlo[ii] );
	    }
	  syststr_ = line_;
	  str_ += pmstr_;
	  str_ += syststr_;
	  str_ += "_{ ";
	  str_ += _secondError;
	  str_ += "}";
	}
  
      if( _lumi[ii]>0 )
	{
	  sprintf( line_, format_.Data(), _lumi[ii] );
	  lumistr_ = line_;
	  lumistr_ += "_{lumi.}";
	  str_ += pmstr_ + lumistr_;
	}

      //      TString str_(line_);
      
      str_ += _unit;
      cout << str_ << endl;
 
      ltx2_.SetTextSize(_scale*_size2);      
      ltx2_.SetTextAlign(_align2);
      if( _specifyPlacement )
	ltx2_.DrawLatex( _xx2, yy_+_e2, str_ );
      else
	ltx2_.DrawLatex( xtxt_+0.02*(_xmax-_xmin), yy_+E_-e_, str_ );
    }


  _hist->Draw("Same");

  _canv->RedrawAxis();
}
Esempio n. 4
0
void L1UCTEfficiency::ComparePlots(TList * vEffs, const char * title, const char * saveAs) {
  
  std::stringstream cc;
  cc << "UCTEfficiencies_" << ncanvas;
  std::stringstream frame;
  frame << "frame_" << ncanvas;
  
  std::map<std::string,TCanvas*>::iterator it1;
  
  it1 = m_canvas.find( cc.str().c_str() );
  
  if( it1 != m_canvas.end() ) {
    cc << "_" << (ncanvas+1);
    frame << "_" << (ncanvas+1);
  }
  
  m_canvas[title] = new TCanvas(cc.str().c_str(), "L1 and UCT efficiencies", 600, 600);
  m_canvas[title]->SetFillColor(10);
  m_canvas[title]->SetFrameBorderMode(0);
  m_canvas[title]->SetGridx();
  m_canvas[title]->SetGridy();
  m_canvas[title]->cd();
  
  if ( vEffs->GetSize() == 0 || vEffs->GetSize() < 2) {
    std::cout << "Cannot compare!" << std::endl;
    return;
  }
  
  int max = vEffs->GetSize();
  
  TLegend * legend = new TLegend(0.35,0.18,0.90,0.38, "", "brNDC");
  legend->SetFillColor(kWhite);
  legend->SetBorderSize(1);
  
  for(int k=0; k < max; ++k ) {
    
    TGraphAsymmErrors * h1 = ((EffGraph*)vEffs->At(k))->m_eff;
    
    if ( k == 0 ) {
            
      m_histograms1D[frame.str().c_str()] = new TH1F(frame.str().c_str(), "frame", m_nbins, m_xmin, m_xmax );
      m_histograms1D[frame.str().c_str()]->SetMaximum(1.2);
      m_histograms1D[frame.str().c_str()]->SetTitle(title);
      m_histograms1D[frame.str().c_str()]->GetXaxis()->SetTitle( ((EffGraph*)vEffs->At(k))->m_label.c_str() );
      m_histograms1D[frame.str().c_str()]->GetYaxis()->SetTitle("Efficiency");

      m_histograms1D[frame.str().c_str()]->Draw();

      legend->AddEntry(h1, ((EffGraph*)vEffs->At(k))->m_legend.c_str(), "pe");
      h1->Draw("pe");
            
    }
    else {
      legend->AddEntry(h1, ((EffGraph*)vEffs->At(k))->m_legend.c_str(), "pe");
      h1->Draw("pe");
    }
    
  }
  
  legend->Draw();
  cmsPrelim();
  m_canvas[title]->SaveAs( saveAs );
  
  ++ncanvas;
  
}
Esempio n. 5
0
void plotEfficiency(char* var, double min, double max, int l1PtMin=0) {
  TFile*f1 =  TFile::Open("efficiency_tree_Zmumu_merged.root");
  f1->cd("muonEfficiency");
  TTree* tree1 = (TTree*) gDirectory->Get("Ntuple");

  int nBins = 100;
  if(var=="Pt") nBins = (int) ((max - min) / 5);
  if(var=="Eta") nBins = (int) ((max - min) / 0.2);



  ///// ----- Define your cuts ----------
  char l1PtMinStr[100];
  sprintf(l1PtMinStr, "l1Pt>%d", l1PtMin);
  TCut l1PtMinCut(l1PtMinStr);
  TCut cutNPV0("(nPVs>-1)");
  TCut cutNPV1("(nPVs>=0 && nPVs<15)");
  TCut cutNPV2("(nPVs>=15 && nPVs<25)");
  TCut cutNPV3("(nPVs>=25 && nPVs<200)");
  TCut l1isoCut("(abs(l1gDR)>0.2 || (l1gRegionEt/l1Pt<0.5))");


  ///// ----- Create all the histograms ----------
  TH1D* allReco = new TH1D("allReco", "", nBins, min, max);
  allReco->SetLineWidth(2);
  allReco->Sumw2();
  TH1D* allRecoNPV1 = allReco->Clone("allRecoNPV1");
  TH1D* allRecoNPV2 = allReco->Clone("allRecoNPV2");
  TH1D* allRecoNPV3 = allReco->Clone("allRecoNPV3");



  TH1D* l1iso = allReco->Clone("l1iso");
  TH1D* l1isoNPV1 = allReco->Clone("l1isoNPV1");
  TH1D* l1isoNPV2 = allReco->Clone("l1isoNPV2");
  TH1D* l1isoNPV3 = allReco->Clone("l1isoNPV3");


  l1isoNPV1->SetLineColor(4);
  l1isoNPV1->SetMarkerColor(4);
  l1isoNPV2->SetLineColor(6);
  l1isoNPV2->SetMarkerColor(6);
  l1isoNPV3->SetLineColor(2);
  l1isoNPV3->SetMarkerColor(2);

  l1iso->GetYaxis()->SetRangeUser(0.5, 1.1);
  l1iso->GetYaxis()->SetTitle("L1 Efficiency");
  char* xtitle = var;
  if(var=="Pt") xtitle = "Offline muon p_{T} (GeV)";
  if(var=="Eta") xtitle = "Offline muon #eta";
  l1iso->GetXaxis()->SetTitle(xtitle);





  ///// ----- Draw from tree ----------
  TString varName = TString("reco") + TString(var);
  tree1->Draw(varName+TString(">>allReco"),cutNPV0,"goff");
  tree1->Draw(varName+TString(">>allRecoNPV1"),cutNPV1,"goff");
  tree1->Draw(varName+TString(">>allRecoNPV2"),cutNPV2,"goff");
  tree1->Draw(varName+TString(">>allRecoNPV3"),cutNPV3,"goff");

  tree1->Draw(varName+TString(">>l1iso"),l1PtMinCut && cutNPV0 && l1isoCut,"goff");
  tree1->Draw(varName+TString(">>l1isoNPV1"),l1PtMinCut && cutNPV1 && l1isoCut,"goff");
  tree1->Draw(varName+TString(">>l1isoNPV2"),l1PtMinCut && cutNPV2 && l1isoCut,"goff");
  tree1->Draw(varName+TString(">>l1isoNPV3"),l1PtMinCut && cutNPV3 && l1isoCut,"goff");




  //// ---- Now divide by allReco histogram to obtain efficiency ----
  l1iso->Divide(allReco);
  l1isoNPV1->Divide(allRecoNPV1);
  l1isoNPV2->Divide(allRecoNPV2);
  l1isoNPV3->Divide(allRecoNPV3);


  // --- plot the efficiency histograms ------ 
  gROOT->ProcessLine(".L ~/tdrstyle.C");
  setTDRStyle();
  tdrStyle->SetErrorX(0.5);
  tdrStyle->SetPadLeftMargin(0.18);
  tdrStyle->SetPadRightMargin(0.08);
  tdrStyle->SetLegendBorderSize(0);
  tdrStyle->SetTitleYOffset(1.3);


  TCanvas* canEffIso = new TCanvas("canEffIso","",500,500);
  l1iso->SetFillColor(5);
  l1iso->Draw("e3");
  l1iso->Draw("esame");
  l1isoNPV1->Draw("psame");
  l1isoNPV2->Draw("psame");
  l1isoNPV3->Draw("psame");
  l1iso->Draw("esame");

  TLegend* legend = new TLegend(0.45,0.15,0.9,0.45);
  legend->SetFillColor(0);
  legend->AddEntry(l1iso, "All NPV", "PLE");  
  legend->AddEntry(l1isoNPV1, "NPV: 0-15", "PLE");  
  legend->AddEntry(l1isoNPV2, "NPV: 15-25", "PLE");  
  legend->AddEntry(l1isoNPV3, "NPV: 25-above", "PLE"); 
  legend->Draw();
  cmsPrelim();

  TString plotname = TString("muonEfficiency_")+TString(var);
  char tempst[100];
  sprintf(tempst, "_l1Pt_%d", l1PtMin);
  plotname += TString(tempst);
  canEffIso->SetGridy();
  canEffIso->SaveAs(plotname+TString(".png"));
  canEffIso->SaveAs(plotname+TString(".pdf"));


  //--------- Finally clean up the memory -------
  delete allReco;
  delete allRecoNPV1;
  delete allRecoNPV2;
  delete allRecoNPV3;
  delete l1iso;
  delete l1isoNPV1;
  delete l1isoNPV2;
  delete l1isoNPV3;

  delete canEffIso;
  delete legend;



}
void plotTurnonCurve(char* var, double min, double max, int NPVmin=0, int NPVmax=50) {

  TString path("./slhc-plots/turnon/EG/noPUC/isoStudies");
  float PUcut = 1.0;
  
  TFile * f1;
  
  if( 1 ) {
    
    f1 =  TFile::Open("../uct_efficiency_tree_Zee_All_BCD.root");

  } 


  TTree* tree1 = (TTree*) gDirectory->Get("rlxEGEfficiency/Ntuple");
  
  int nBins = 100;
  if(var=="Pt") nBins = (int) ((max - min) / 2);
  if(var=="Eta") nBins = (int) ((max - min) / 0.5);
  
  double RecoPtmin = 0.0;
  
  ////////////////////////////////////////////////////////////////////////////////
  // read the same selection used for the Rate/Efficiency plots
  //
  int lineWidth = 1;

  std::ifstream *m_in = new std::ifstream("config/efficiency_EG_WPs_WI_Selection.dat");
  
  if ( !m_in->is_open() ) {
    std::cout << " I could not open this file" << std::endl;
    exit(1);
  }
  
  TList * v_Selection = new TList();
  
  char line[256];
  while(1) {
    
    m_in->getline( line, 256 );
    TObjString *selection = new TObjString( line );
    v_Selection->Add( selection );
    if ( m_in->eof() ) break;
    
  }
  
  v_Selection->RemoveLast();
  
  TList * v_Labels = new TList();
  
  TObjString *label;
  label = new TObjString( "L1 Upgrade EG" );
  v_Labels->Add( label ); 
  label = new TObjString( "L1 Upgrade Iso EG" );
  v_Labels->Add( label ); 

  ////////////////////////////////////////////////////////////////////////////////
  
  //This is the standard cut based on nPVS, DR3<0.2 and recoPt minimum
  
  char cuts[100];
  sprintf(cuts, "nPVs>%d && nPVs<%d && dr03CombinedEt < 0.2 && l1gMatch && recoPt > %d ", NPVmin, NPVmax, RecoPtmin);
  
  int max_sel = v_Selection->GetEntries();

  tdrStyle->cd();
  
  int minSel = 1; // For these we only want the Isolated one (thresholds labels are for the Isolated case)

  for( int k = minSel; k < max_sel; ++k ) {
    
    TString egsel = ((TObjString*)v_Selection->At(k))->GetString();
    
    std::cout << egsel.Data() << std::endl;
    
    ///// ----- Create all the histograms ----------
    TH1D* allReco = new TH1D("allReco", "", nBins, min, max);
    allReco->SetLineWidth(lineWidth);
    allReco->Sumw2();
    
    TH1D* l1Pt20 = allReco->Clone("l1Pt20");
    if(var=="Pt") l1Pt20->GetYaxis()->SetRangeUser(0.0, 1.1);
    if(var=="Eta") l1Pt20->GetYaxis()->SetRangeUser(0.55, 1.05);
    
    l1Pt20->GetYaxis()->SetTitle("Efficiency");
    char* xtitle = var;
    if(var=="Pt") xtitle = "Offline electron p_{T} [GeV]";
    if(var=="Eta") xtitle = "Offline electron #eta";
    l1Pt20->GetXaxis()->SetTitle(xtitle);
    l1Pt20->GetXaxis()->SetTitleOffset(1.3);
    l1Pt20->SetMinimum(0.);
    l1Pt20->SetMaximum(1.2);

    TH1D* l1Pt25 = allReco->Clone("l1Pt25");
    l1Pt25->SetLineColor(6);
    l1Pt25->SetMarkerColor(6);
    
    TH1D* l1Pt30 = allReco->Clone("l1Pt30");
    l1Pt30->SetLineColor(7);
    l1Pt30->SetMarkerColor(7);
    TString varName = TString("reco") + TString(var);
    
    TH1D* l1Pt35 = allReco->Clone("l1Pt35");
    l1Pt35->SetLineColor(8);
    l1Pt35->SetMarkerColor(8);
    TString varName = TString("reco") + TString(var);
    
    TH1D* l1Pt40 = allReco->Clone("l1Pt40");
    l1Pt40->SetLineColor(2);
    l1Pt40->SetMarkerColor(2);
    TString varName = TString("reco") + TString(var);

    TH1D* l1Pt10 = allReco->Clone("l1Pt10");
    l1Pt10->SetLineColor(9);
    l1Pt10->SetMarkerColor(9);
    TString varName = TString("reco") + TString(var);
    
    
    ///// ----- Draw from tree ----------
    tree1->Draw(varName+TString(">>allReco"),cuts,"goff");
    tree1->Draw(varName+TString(">>l1Pt20"),TString(cuts)+TString(" && l1gPt>20. && ")+egsel,"goff");
    tree1->Draw(varName+TString(">>l1Pt25"),TString(cuts)+TString(" && l1gPt>25. && ")+egsel,"goff");
    tree1->Draw(varName+TString(">>l1Pt30"),TString(cuts)+TString(" && l1gPt>30. && ")+egsel,"goff");
    tree1->Draw(varName+TString(">>l1Pt35"),TString(cuts)+TString(" && l1gPt>35. && ")+egsel,"goff");
    tree1->Draw(varName+TString(">>l1Pt40"),TString(cuts)+TString(" && l1gPt>40. && ")+egsel,"goff");
    tree1->Draw(varName+TString(">>l1Pt10"),TString(cuts)+TString(" && l1gPt>10. && ")+egsel,"goff");
    
    //// ---- Now divide by allReco histogram to obtain efficiency ----
    l1Pt20->Divide(allReco);
    l1Pt25->Divide(allReco);
    l1Pt30->Divide(allReco);
    l1Pt35->Divide(allReco);
    l1Pt40->Divide(allReco);
    l1Pt10->Divide(allReco);
    
    // --- plot the efficiency histograms ------ 

    TCanvas* canEffIso = new TCanvas("canEffIso","",500,500);
    l1Pt20->Draw("e");
    l1Pt20->Draw("hist same");
    l1Pt25->Draw("esame");
    l1Pt25->Draw("hist same");
    l1Pt30->Draw("esame");
    l1Pt30->Draw("hist same");
    l1Pt35->Draw("esame");
    l1Pt35->Draw("hist same");
    l1Pt40->Draw("esame");
    l1Pt40->Draw("hist same");
    l1Pt10->Draw("esame");
    l1Pt10->Draw("hist same");
    
    TString legend_Label = ((TObjString*)v_Labels->At(k))->GetString();

    TLegend* legend = new TLegend(0.54,0.22,0.82,0.45,"95% offline thresholds:");

    legend->SetFillColor(0);
    legend->SetBorderSize(0);
    legend->SetTextFont(62);
    legend->SetTextSize(0.034);
    legend->AddEntry(l1Pt10, "20 GeV", "PLE"); 
    legend->AddEntry(l1Pt20, "29 GeV", "PLE"); 
    legend->AddEntry(l1Pt25, "34 GeV", "PLE"); 
    legend->AddEntry(l1Pt30, "38 GeV", "PLE"); 
    legend->AddEntry(l1Pt35, "43 GeV", "PLE"); 
    legend->AddEntry(l1Pt40, "47 GeV", "PLE"); 
    legend->Draw();
    cmsPrelim();
    canEffIso->SetGridx();
    canEffIso->SetGridy();

    TLatex * tex = new TLatex(15.4, 1.1, legend_Label.Data() );
    tex->SetTextFont(42);
    tex->SetLineWidth(2);
    tex->Draw();
    
    canEffIso->Modified();

    std::stringstream saveAs;
    
    saveAs.str("");
    saveAs << path << "/eps/rlx_eg_eff_trg10_WTh_" << varName << "_" << NPVmin << "_" << NPVmax << "_" << k << "_" << PUcut 
	   << "_" << lineWidth << ".eps";

    canEffIso->SaveAs( saveAs.str().c_str() );
    
    saveAs.str("");
    saveAs << path << "/eps/rlx_eg_eff_trg10_WTh_" << varName << "_" << NPVmin << "_" << NPVmax << "_" << k << "_" << PUcut 
	   << "_" << lineWidth << ".pdf";

    canEffIso->SaveAs( saveAs.str().c_str() );
    
    saveAs.str("");
    saveAs << path << "/png/rlx_eg_eff_trg10_WTh_" << varName << "_" << NPVmin << "_" << NPVmax << "_" << k << "_" << PUcut 
	   << "_" << lineWidth << ".png";

    canEffIso->SaveAs( saveAs.str().c_str() );
    
    //--------- Finally clean up the memory -------
    delete allReco;
    delete l1Pt10;
    delete l1Pt20;
    delete l1Pt25;
    delete l1Pt30;
    delete l1Pt35;
    delete l1Pt40;
    delete canEffIso;
    delete legend;
    
  }

  

  
}
void plotTurnonCurve(char* var, double min, double max, int NPVmin=0, int NPVmax=50) {
  
  TString path("./uct15-plots/turnon/Taus/noPUC/isoStudies");
  
  float PUcut = 1.0;
  
  TFile * f1;
  
  if( 1 ) {
    
    f1 =  TFile::Open("/uscms_data/d2/aosorio/scratch0/UCT2015_BKP/root_files/uct_eff_trees_mutau_BC.root");

  } 

  TTree* tree1 = (TTree*) gDirectory->Get("rlxTauEfficiency/Ntuple");
    
  int nBins = 10;
  if(var=="Pt") nBins = (int) ((max - min) / 2);
  if(var=="Eta") nBins = (int) ((max - min) / 0.5);

  nBins = 20;

  double RecoPtmin = 0.0;
  
  ////////////////////////////////////////////////////////////////////////////////
  // read the same selection used for the Rate/Efficiency plots
  //
  int lineWidth = 2;

  std::ifstream *m_in = new std::ifstream("config/efficiency_TS_WP_WI_Selection.dat");
  
  if ( !m_in->is_open() ) {
    std::cout << " I could not open this file" << std::endl;
    exit(1);
  }
  
  TList * v_Selection = new TList();
  
  char line[256];
  while(1) {
    
    m_in->getline( line, 256 );
    TObjString *selection = new TObjString( line );
    v_Selection->Add( selection );
    if ( m_in->eof() ) break;
    
  }
  
  v_Selection->RemoveLast();

  TList * v_Labels = new TList();
  
  TObjString *label;
  label = new TObjString( "L1 Upgrade Tau" );
  v_Labels->Add( label ); 
  label = new TObjString( "L1 Upgrade Iso Tau" );
  v_Labels->Add( label ); 

  ////////////////////////////////////////////////////////////////////////////////
  //This is the standard cut based on nPVS
  
  char cuts[100];
  sprintf(cuts, " l1gMatch && recoPt > %d ", NPVmin, NPVmax, RecoPtmin);
  
  int min_sel = 0; 
  int max_sel = v_Selection->GetEntries();

  max_sel = 1; //Only focus on the relaxed tau plots - they go to TDR

  for( int k = min_sel; k < max_sel; ++k ) {
    
    TString egsel = ((TObjString*)v_Selection->At(k))->GetString();
    
    std::cout << egsel.Data() << std::endl;
    
    ///// ----- Create all the histograms ----------
    TH1D* allReco = new TH1D("allReco", "", nBins, min, max);
    allReco->SetLineWidth(2);
    allReco->Sumw2();
    
    TH1D* l1Pt20 = allReco->Clone("l1Pt20");
    if(var=="Pt") l1Pt20->GetYaxis()->SetRangeUser(0.0, 1.1);
    if(var=="Eta") l1Pt20->GetYaxis()->SetRangeUser(0.55, 1.05);
    
    l1Pt20->GetYaxis()->SetTitle("Efficiency");
    char* xtitle = var;
    if(var=="Pt") xtitle = "Offline tau p_{T} [GeV]";
    if(var=="Eta") xtitle = "Offline tau #eta";
    l1Pt20->GetXaxis()->SetTitle(xtitle);
    l1Pt20->GetXaxis()->SetTitleOffset(1.3);
    l1Pt20->SetMinimum(0.);
    l1Pt20->SetMaximum(1.2);

    
    TH1D* l1Pt25 = allReco->Clone("l1Pt25");
    l1Pt25->SetLineColor(6);
    l1Pt25->SetMarkerColor(6);
    
    TH1D* l1Pt30 = allReco->Clone("l1Pt30");
    l1Pt30->SetLineColor(7);
    l1Pt30->SetMarkerColor(7);
    TString varName = TString("reco") + TString(var);
    
    TH1D* l1Pt40 = allReco->Clone("l1Pt40");
    l1Pt40->SetLineColor(8);
    l1Pt40->SetMarkerColor(8);
    TString varName = TString("reco") + TString(var);
    
    TH1D* l1Pt60 = allReco->Clone("l1Pt60");
    l1Pt60->SetLineColor(2);
    l1Pt60->SetMarkerColor(2);
    TString varName = TString("reco") + TString(var);
    
    ///// ----- Draw from tree ----------
    tree1->Draw(varName+TString(">>allReco"),cuts,"goff");
    tree1->Draw(varName+TString(">>l1Pt20"),TString(cuts)+TString(" && l1gPt>20. && ")+egsel,"goff");
    tree1->Draw(varName+TString(">>l1Pt25"),TString(cuts)+TString(" && l1gPt>25. && ")+egsel,"goff");
    tree1->Draw(varName+TString(">>l1Pt30"),TString(cuts)+TString(" && l1gPt>30. && ")+egsel,"goff");
    tree1->Draw(varName+TString(">>l1Pt40"),TString(cuts)+TString(" && l1gPt>40. && ")+egsel,"goff");
    tree1->Draw(varName+TString(">>l1Pt60"),TString(cuts)+TString(" && l1gPt>60. && ")+egsel,"goff");
    
    //// ---- Now divide by allReco histogram to obtain efficiency ----
    l1Pt20->Divide(allReco);
    l1Pt25->Divide(allReco);
    l1Pt30->Divide(allReco);
    l1Pt40->Divide(allReco);
    l1Pt60->Divide(allReco);
    
    
    
    TCanvas* canEffIso = new TCanvas("canEffIso","",500,500);
    l1Pt20->Draw("e");
    l1Pt20->Draw("hist same");
    l1Pt25->Draw("esame");
    l1Pt25->Draw("hist same");
    l1Pt30->Draw("esame");
    l1Pt30->Draw("hist same");
    l1Pt40->Draw("esame");
    l1Pt40->Draw("hist same");
    l1Pt60->Draw("esame");
    l1Pt60->Draw("hist same");
    
    TString legend_Label = ((TObjString*)v_Labels->At(k))->GetString();

    TLegend* legend = new TLegend(0.5,0.22,0.9,0.45);
    legend->SetFillColor(0);
    legend->SetBorderSize(0);
    legend->SetTextFont(62);
    legend->SetTextSize(0.034);
    legend->AddEntry(l1Pt20, "L1 p_{T} > 20 GeV", "PLE"); 
    legend->AddEntry(l1Pt25, "L1 p_{T} > 25 GeV", "PLE"); 
    legend->AddEntry(l1Pt30, "L1 p_{T} > 30 GeV", "PLE"); 
    legend->AddEntry(l1Pt40, "L1 p_{T} > 40 GeV", "PLE"); 
    legend->AddEntry(l1Pt60, "L1 p_{T} > 60 GeV", "PLE"); 
    legend->Draw();
    cmsPrelim();
    canEffIso->SetGridx();
    canEffIso->SetGridy();

    TLatex * tex = new TLatex(15.4, 1.1, legend_Label.Data() );
    tex->SetTextFont(42);
    tex->SetLineWidth(2);
    tex->Draw();

    canEffIso->Modified();

    std::stringstream saveAs;
    
    saveAs.str("");
    saveAs << path << "/eps/rlx_tau_eff_trg20_WP_" << varName << "_" << NPVmin << "_" << NPVmax << "_" << k << "_" << PUcut 
	   << "_" << lineWidth << ".eps";
    canEffIso->SaveAs( saveAs.str().c_str() );

    saveAs.str("");
    saveAs << path << "/eps/rlx_tau_eff_trg20_WP_" << varName << "_" << NPVmin << "_" << NPVmax << "_" << k << "_" << PUcut 
	   << "_" << lineWidth << ".pdf";
    canEffIso->SaveAs( saveAs.str().c_str() );
    
    saveAs.str("");
    saveAs << path << "/png/rlx_tau_eff_trg20_WP_" << varName << "_" << NPVmin << "_" << NPVmax << "_" << k << "_" << PUcut 
	   << "_" << lineWidth << ".png";
    canEffIso->SaveAs( saveAs.str().c_str() );
    
    //--------- Finally clean up the memory -------
    delete allReco;
    delete l1Pt20;
    delete l1Pt25;
    delete l1Pt30;
    delete l1Pt40;
    delete l1Pt60;
    delete canEffIso;
    delete legend;
    
  }

  

  
}