Beispiel #1
0
void efficiencyL0_01(std::string fullPath, bool doOverview = true)
{
    const std::string outpdf("efficiencyL0_01plot");
    const int fVerbose(0);
    setTDRStyle();
    gStyle->SetOptStat(112211);
    gStyle->SetPalette(1);
    // Canvas
    if (doOverview)
	c = new TCanvas("c1","c1",1400,1200);
    else
	c = new TCanvas("c1","c1",600,600);
    const unsigned int nPadX = doOverview ? 3 : 1;
    const unsigned int nPadY = doOverview ? 2 : 1;
    c->Divide(nPadX,nPadY);
    const unsigned int nPads=nPadX*nPadY;
    // Open file
    TFile *f = TFile::Open(fullPath.c_str());
    if (f==0)
    {
	cout << "File " << fullPath << " not found -- exiting" << endl;
	return;
    }
    if(fVerbose>0)
	cout << "Succesfully opened file " << fullPath << endl;
    // Get TTrees
    TTree* tree = (TTree*) f->Get("events");
    if (tree==0)
    {
	cout << "Tree events not found -- exiting" << endl;
	return;
    }
    if(fVerbose>0) cout << "Got TTree evemts with " << tree->GetEntries() << " entries" << endl;

    // General cuts
    std::string cutacc = "genL0vtxR>1&&genL0vtxR<35&&TMath::Abs(genL0vtxZ)<100";

    // Do plots
    int canvasCdCounter(0), canvasPageCounter(0);
    const int nbinseta(5);
    const int nbinspt(5);
    const double etamax(2.6);
    const double ptmax(40.);
    //const double ptbins[] = {0,1,3,5,10,15,40};
    const double ptbins[] = {0,0.5,1,1.5,2,2.5,3,3.5,4,5,6,8,10,40};
    const int ptbins_size = (sizeof(ptbins)/sizeof(double));
    std::vector<double> ptbinvec(ptbins,ptbins+ptbins_size);
    //const double etabins[] = {0.0,0.5,1.0,1.4,1.8,2.2};
    const double etabins[] = {0.0,0.5,1.0,1.5,2.0,2.5,3.0};
    const int etabins_size = (sizeof(etabins)/sizeof(double));
    std::vector<double> etabinvec(etabins,etabins+etabins_size);
    //const int nbinseta(2);
    //const double etamax(2.4);
    //const int nbinspt(1);
    const bool etabetrag(true);

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    doPlot2d((TPad*)c->cd(canvasCdCounter),tree,"h1", "genL0pt:TMath::Abs(genL0eta)", cutacc.c_str(), etabinvec, ptbinvec,"Generated #Lambda","|#eta(#Lambda)|","p_{T}(#Lambda)","","GeV/c");
    setTH2params((TPad*)c->cd(canvasCdCounter),(TH2F*)gDirectory->GetList()->FindObject("h1"),true);

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    doPlot2d((TPad*)c->cd(canvasCdCounter),tree,"h2", "genL0pt:TMath::Abs(genL0eta)", (cutacc+(cutacc.size()>0?"&&":"")+"L0matched==1").c_str(), etabinvec, ptbinvec,"Generated #Lambda, found in reco","|#eta(#Lambda)|","p_{T}(#Lambda)","","GeV/c");
    setTH2params((TPad*)c->cd(canvasCdCounter),(TH2F*)gDirectory->GetList()->FindObject("h2"),true);

#ifdef DOPIDTABLE
    // now we make a pidTable out of this
    PidTable *pid = new PidTable(1);
    pid->readFromHist(gDirectory, "h2", "h1");
    pid->dumpToFile("pid_lambda0.dat");
#endif

    // make a clone for the ratio
    {
	TH2F *hratio = (TH2F*)gDirectory->GetList()->FindObject("h2")->Clone("h2Dratio");
    }
    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    doPlotRatio2d((TPad*)c->cd(canvasCdCounter),"#Lambda reco efficiency","h1","h2Dratio");

    // Now we do a 1D histo for each x-bin
    //plot1Dfrom2DforeachXbin((TH2F*)gDirectory->GetList()->FindObject("h1"));
    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    plot1Dfrom2DforeachXbin((TPad*)c->cd(canvasCdCounter),"h2Dratio");

    // 1D ratio plots
    const double ptbinsratio[] = {0,0.5,1,1.5,2,2.5,3,3.5,4,5,6,8,12,16,40};
    const int ptbinsratio_size = (sizeof(ptbinsratio)/sizeof(double));
    std::vector<double> ptbinratiovec(ptbinsratio,ptbinsratio+ptbinsratio_size);
    const double etabinsratio[] = {0,0.2};
    const int etabinsratio_size = (sizeof(etabinsratio)/sizeof(double));
    std::vector<double> etabinratiovec(etabinsratio,etabinsratio+etabinsratio_size);

    std::string cutaccEta = (cutacc.size()>0?cutacc+"&&":"")+ "TMath::Abs(genL0eta)<2.5";
    std::string cutaccPt = (cutacc.size()>0?cutacc+"&&":"")+ "genL0pt>2&&genL0pt<40";

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    doRatioPlot((TPad*)c->cd(canvasCdCounter),tree,tree,"hpt","genL0pt","genL0pt",cutaccEta.c_str(), (cutaccEta+(cutaccEta.size()>0?"&&":"")+"L0matched==1").c_str(),ptbinratiovec,"#Lambda reco efficiency for |#eta|<2.5","p_{T}","GeV/c");
    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    doRatioPlot((TPad*)c->cd(canvasCdCounter),tree,tree,"heta","TMath::Abs(genL0eta)","TMath::Abs(genL0eta)",cutaccPt.c_str(), (cutaccPt+(cutaccPt.size()>0?"&&":"")+"L0matched==1").c_str(),25,0,2.5,"#Lambda reco efficiency for 2<p_{T}<40","|#eta|","");

    // finalize current page
    c->SaveAs((outpdf + toString(canvasPageCounter) + ".pdf").c_str());
}
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("../L1Tree_Latest_MuTau_2012CD.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", 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("e");
    h1->Clone()->Draw("hist same");
    
    h1->Fit("g1");
   
    h2->SetLineColor(4);
    h2->Draw("esame");
    h2->Clone()->Draw("hist same");
    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("Stage 1 #sigma") + TString(sigma1);
    
    TString stage2Leg = TString("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_tau_reso_" << skim << "_" << var << "_" << xMin << "_" << xMax << "_dcm_" << k << "_" << regionCode << ".eps";
    canvas->SaveAs( saveAs.str().c_str() );
    
    saveAs.str("");
    saveAs << path << "/pdf/rlx_tau_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; 


}
Beispiel #3
0
void plot(char* h, bool norm2data, TString prefix, TString RR) {

    TFile f1(prefix+"DATA"+RR+"CP.root", "read");
    TH1D* hdata = (TH1D*)f1.Get(h);
    hdata->SetDirectory(0);
    
    TFile f2(prefix+"DYM_CP.root", "read");
    TH1D* hsignal = (TH1D*)f2.Get(TString(h));
    hsignal->SetDirectory(0);
    
    TFile f3(prefix+"QCD_CP_dd.root", "read");
    TH1D* hqcd = (TH1D*)f3.Get("hqcd");
    hqcd->SetDirectory(0);

    TFile f3_mc(prefix+"QCD_CP.root", "read");
    TH1D* hqcd_mc = (TH1D*)f3_mc.Get(h);
    hqcd_mc->SetDirectory(0);

    //FIXME    
    cout << "See the implementation in 2D case!" << endl;
    TFile f4(prefix+"TT_CP.root", "read");
    TH1D* httbar = (TH1D*)f4.Get(h); //"httbar");
    httbar->SetDirectory(0);

    TFile f4_mc(prefix+"TT_CP.root", "read");
    TH1D* httbar_mc = (TH1D*)f4_mc.Get(h);
    httbar_mc->SetDirectory(0);

    TFile f5(prefix+"TAU_CP.root", "read");
    TH1D* hZtautau = (TH1D*)f5.Get(h);
    hZtautau->SetDirectory(0);
    
    TFile f6(prefix+"EWK_CP.root", "read");
    TH1D* hWleptonnu = (TH1D*)f6.Get(h);
    hWleptonnu->SetDirectory(0);
    
    TFile f7(prefix+"DIBOSON_CP.root", "read");
    TH1D* hDibosons = (TH1D*)f7.Get(h);
    hDibosons->SetDirectory(0);
    
    gStyle->SetOptStat(0);
    gStyle->SetPalette(1);
    gROOT->ProcessLine(".L ../tools/setTDRStyle.C");
    setTDRStyle();
    gROOT->SetStyle("tdrStyle");
    gROOT->ForceStyle(true);
    
    // signal
    hsignal->SetLineColor(kOrange);
    hsignal->SetFillColor(kOrange);
    
    // qcd
    hqcd->SetLineColor(9);
    hqcd->SetFillColor(9);

    // tt
    httbar->SetLineColor(kRed+2);
    httbar->SetFillColor(kRed+2);

    // tau
    hZtautau->SetLineColor(kGreen);
    hZtautau->SetFillColor(kGreen);

    // EWK
    hWleptonnu->SetLineColor(38);
    hWleptonnu->SetFillColor(38);

    //hupsilon->SetLineColor(51);
    //hupsilon->SetFillColor(51);

    // diboson
    hDibosons->SetLineColor(40);
    hDibosons->SetFillColor(40);

    //
    //The histograms come properly weighted with priors
    //This would normalize to number of events in data
    //

    if (norm2data) {
	    const double ttbarNorm = httbar->Integral();
	    const double WleptonnuNorm = hWleptonnu->Integral();
	    const double ZtautauNorm = hZtautau->Integral();
	    const double qcdNorm = hqcd_mc->Integral();
 	    const double dibosonNorm = hDibosons->Integral();
	    const double signalNorm = hsignal->Integral();
 	    const double fullMCintegral = ttbarNorm+WleptonnuNorm+ZtautauNorm+qcdNorm+dibosonNorm+signalNorm;

	    httbar->Scale(hdata->Integral()/fullMCintegral);
	    hWleptonnu->Scale(hdata->Integral()/fullMCintegral);
	    hZtautau->Scale(hdata->Integral()/fullMCintegral);
	    hqcd_mc->Scale(hdata->Integral()/fullMCintegral);
	    hsignal->Scale(hdata->Integral()/fullMCintegral);
	    hDibosons->Scale(hdata->Integral()/fullMCintegral);
            normalizeToPeak(httbar, hWleptonnu, hqcd_mc, hZtautau, hsignal, hDibosons, hdata);

    } else {
           //Just do not normalize, for utility purposes, not for the analysis 
    }

    // mc
    TH1D* hmc = (TH1D*)hsignal->Clone();
    hmc->Add(hqcd_mc);
    //hmc->Add(hupsilon);
    hmc->Add(httbar);
    hmc->Add(hZtautau);
    hmc->Add(hWleptonnu);
    hmc->Add(hDibosons);

    //set up ratio check
    TH1D* hratio = (TH1D*)httbar->Clone();
    FindRatio(hratio,hdata,hmc);

    THStack* hstack = new THStack("hstack", "hstack");
    //hstack->Add(hupsilon);
    hstack->Add(hWleptonnu);
    hstack->Add(hDibosons);
    hstack->Add(httbar);
    hstack->Add(hZtautau);
    hstack->Add(hqcd_mc);
    hstack->Add(hsignal);

    std::ostringstream pprint;

    //add to stack
    TH1D* hstack4fit = (TH1D*)hsignal->Clone();
    //hstack->Add(hupsilon);
    hstack4fit->Add(hWleptonnu);
    hstack4fit->Add(hDibosons);
    hstack4fit->Add(httbar);
    hstack4fit->Add(hZtautau);
    hstack4fit->Add(hqcd_mc);

//save important histograms
    TFile* f = new TFile(prefix+"stack4fit_analyse"+TString(h)+RR+"CP.root","recreate");
    f->cd();
    //resetHisto(hstack4fit);
    hmc->SetName("hmc");
    hmc->Write();
    hstack4fit->SetName("stack4fit");
    hstack4fit->Write();
    //resetHisto(hsignal);
    hsignal->SetName("hsig_fewz");
    hsignal->SetTitle("hsig_fewz");
    hsignal->Write();
    //resetHisto(hqcd);
    hqcd->SetName("hqcd");
    hqcd->SetTitle("hqcd_dd");
    hqcd->Write();
    //resetHisto(hqcd_mc);
    hqcd_mc->SetName("hqcd_mc");
    hqcd_mc->SetTitle("hqcd_mc");
    hqcd_mc->Write();
    //resetHisto(hZtautau);
    hZtautau->SetName("hDYtautau");
    hZtautau->SetTitle("hDYtautau");
    hZtautau->Write();
    //resetHisto(hWleptonnu);
    cout << "hWleptonnu norm " << hWleptonnu->Integral() << endl;
    hWleptonnu->SetName("hWlepton");
    hWleptonnu->SetTitle("hWlepton");
    hWleptonnu->Write();
    //resetHisto(hDibosons);
    hDibosons->SetName("hdiboson");
    hDibosons->SetTitle("hdiboson");
    hDibosons->Write();
    //resetHisto(httbar);
    httbar->SetName("httbar");
    httbar->SetTitle("httbar_dd");
    httbar->Write();
    //resetHisto(httbar_mc);
    httbar_mc->SetName("httbar_mc");
    httbar_mc->SetTitle("httbar_mc");
    httbar_mc->Write();
    //resetHisto(hdata);
    hdata->SetName("hdata");
    hdata->SetTitle("hdata");
    hdata->Write();
    f->Close();
}
Beispiel #4
0
void plotLimit(string outputDir="./", TString inputs="", TString inputs_blinded="", TString inputXSec="", bool strengthLimit=true, bool blind=false, double energy=7, double luminosity=5.035, TString legendName="ee and #mu#mu channels")
{
   setTDRStyle();  
   gStyle->SetPadTopMargin   (0.05);
   gStyle->SetPadBottomMargin(0.12);
   gStyle->SetPadRightMargin (0.16);
   gStyle->SetPadLeftMargin  (0.14);
   gStyle->SetTitleSize(0.04, "XYZ");
   gStyle->SetTitleXOffset(1.1);
   gStyle->SetTitleYOffset(1.45);
   gStyle->SetPalette(1);
   gStyle->SetNdivisions(505);
  
  //get the limits from the tree
  TFile* file = TFile::Open(inputs);
  printf("Looping on %s\n",inputs.Data());
  if(!file) return;
  if(file->IsZombie()) return;
  TFile* file_blinded = TFile::Open(inputs_blinded);
  printf("Looping on %s\n",inputs_blinded.Data());
  if(!file_blinded) return;
  if(file_blinded->IsZombie()) return;
  TTree* tree_blinded = (TTree*)file_blinded->Get("limit");
  tree_blinded->GetBranch("mh"              )->SetAddress(&Tmh      );
  tree_blinded->GetBranch("limit"           )->SetAddress(&Tlimit   );
  tree_blinded->GetBranch("limitErr"        )->SetAddress(&TlimitErr);
  tree_blinded->GetBranch("quantileExpected")->SetAddress(&TquantExp);
  TGraph* ExpLimitm2 = getLimitGraph(tree_blinded,0.025);
  TGraph* ExpLimitm1 = getLimitGraph(tree_blinded,0.160);
  TGraph* ExpLimit   = getLimitGraph(tree_blinded,0.500);
  TGraph* ExpLimitp1 = getLimitGraph(tree_blinded,0.840);
  TGraph* ExpLimitp2 = getLimitGraph(tree_blinded,0.975);
  file_blinded->Close(); 
  TTree* tree = (TTree*)file->Get("limit");
  tree->GetBranch("mh"              )->SetAddress(&Tmh      );
  tree->GetBranch("limit"           )->SetAddress(&Tlimit   );
  tree->GetBranch("limitErr"        )->SetAddress(&TlimitErr);
  tree->GetBranch("quantileExpected")->SetAddress(&TquantExp);
  TGraph* ObsLimit   = getLimitGraph(tree,-1   ); 
  file->Close(); 

  FILE* pFileSStrenght = fopen((outputDir+"SignalStrenght").c_str(),"w");
  std::cout << "Printing Signal Strenght" << std::endl;
  for(int i=0;i<ExpLimit->GetN();i++){
     double M = ExpLimit->GetX()[i];
     std::cout << "Mass: " << M << "; ExpLimit: " << ExpLimit->Eval(M) << std::endl; 
     printf("$%8.6E$ & $%8.6E$ & $[%8.6E,%8.6E]$ & $[%8.6E,%8.6E]$ \\\\\\hline\n",M, ExpLimit->Eval(M), ExpLimitm1->Eval(M), ExpLimitp1->Eval(M), ExpLimitm2->Eval(M),  ExpLimitp2->Eval(M));
     fprintf(pFileSStrenght, "$%8.6E$ & $%8.6E$ & $[%8.6E,%8.6E]$ & $[%8.6E,%8.6E]$ & $%8.6E$ \\\\\\hline\n",M, ExpLimit->Eval(M), ExpLimitm1->Eval(M), ExpLimitp1->Eval(M), ExpLimitm2->Eval(M),  ExpLimitp2->Eval(M), ObsLimit->Eval(M));
    if(int(ExpLimit->GetX()[i])%50!=0)continue; //printf("%f ",ObsLimit->Eval(M));
  }printf("\n");
  fclose(pFileSStrenght); 
 

  //get the pValue
  inputs = inputs.ReplaceAll("/LimitTree", "/PValueTree");
  file = TFile::Open(inputs);
  
  printf("Looping on %s\n",inputs.Data());
  if(!file) return;
  if(file->IsZombie()) return;
  
  tree = (TTree*)file->Get("limit");
  
  tree->GetBranch("limit"           )->SetAddress(&Tlimit   );
  
  TGraph* pValue     = getLimitGraph(tree,-1);
  
  file->Close();

  
  //make TH Cross-sections
   string suffix = outputDir;
   TGraph* THXSec   = Hxswg::utils::getXSec(outputDir); 
   scaleGraph(THXSec, 1000);  //convert cross-section to fb
   double cprime=1.0; double  brnew=0.0;
   double XSecScaleFactor = 1.0;
   if(suffix.find("_cp")!=string::npos){
     sscanf(suffix.c_str()+suffix.find("_cp"), "_cp%lf_brn%lf", &cprime, &brnew);
     XSecScaleFactor = pow(cprime,2) * (1-brnew);
   }
  //XSecScaleFactor = 0.001; //pb to fb
  scaleGraph(THXSec, XSecScaleFactor);


  string prod = "pp_SM";
  if(outputDir.find("ggH")!=std::string::npos)prod="gg";
  if(outputDir.find("qqH")!=std::string::npos)prod="qq";
  if(outputDir.find("ppH")!=std::string::npos)prod="pp";

  
  strengthLimit = false;
  if(prod=="pp_SM")strengthLimit=true;
 
  //TGraph *XSecMELA = Hxswg::utils::getXSecMELA(cprime);

  //Hxswg::utils::multiplyGraph(   ObsLimit, XSecMELA);
  //Hxswg::utils::multiplyGraph( ExpLimitm2, XSecMELA);
  //Hxswg::utils::multiplyGraph( ExpLimitm1, XSecMELA);
  //Hxswg::utils::multiplyGraph(   ExpLimit, XSecMELA);
  //Hxswg::utils::multiplyGraph( ExpLimitp1, XSecMELA);
  //Hxswg::utils::multiplyGraph( ExpLimitp2, XSecMELA);
 
  //Scale exclusion XSec in fb
  scaleGraph(ObsLimit  , 0.001); //pb to fb
  scaleGraph(ExpLimitm2, 0.001); //pb to fb
  scaleGraph(ExpLimitm1, 0.001); //pb to fb
  scaleGraph(ExpLimit  , 0.001); //pb to fb
  scaleGraph(ExpLimitp1, 0.001); //pb to fb
  scaleGraph(ExpLimitp2, 0.001); //pb to fb

  //scal eTH cross-section and limits according to scale factor 
  //this only apply to NarrowResonnance case
  if(strengthLimit){
     Hxswg::utils::divideGraph(ObsLimit   , THXSec);
     Hxswg::utils::divideGraph(ExpLimitm2 , THXSec);
     Hxswg::utils::divideGraph(ExpLimitm1 , THXSec);
     Hxswg::utils::divideGraph(ExpLimit   , THXSec);
     Hxswg::utils::divideGraph(ExpLimitp1 , THXSec);
     Hxswg::utils::divideGraph(ExpLimitp2 , THXSec);
     Hxswg::utils::divideGraph(THXSec     , THXSec);
  }


  //limits in terms of signal strength
  TCanvas* c = new TCanvas("c", "c",800,800);
  c->SetGridx();
  c->SetGridy();
  TH1F* framework = new TH1F("Graph","Graph",1,strengthLimit?199:199,2500); //3000);
  framework->SetStats(false);
  framework->SetTitle("");
  framework->GetXaxis()->SetTitle("M_{H} [GeV]");
  framework->GetYaxis()->SetTitleOffset(1.70);
  if(strengthLimit){
  framework->GetYaxis()->SetTitle("#mu = #sigma_{95%} / #sigma_{th}");
  framework->GetYaxis()->SetRangeUser(1E-4,1E3);
  c->SetLogy(true);
  }else{
  framework->GetYaxis()->SetTitle((string("#sigma_{95%} (") + prod +" #rightarrow H #rightarrow ZZ) (pb)").c_str());
  framework->GetYaxis()->SetRangeUser(1E-3,1E3);
  c->SetLogy(true);
  }
  framework->GetXaxis()->SetLabelOffset(0.007);
  framework->GetXaxis()->SetLabelSize(0.03);
  framework->GetXaxis()->SetTitleOffset(1.0);
  framework->GetXaxis()->SetTitleFont(42);
  framework->GetXaxis()->SetTitleSize(0.035);
  framework->GetYaxis()->SetLabelFont(42);
  framework->GetYaxis()->SetLabelOffset(0.007);
  framework->GetYaxis()->SetLabelSize(0.03);
  framework->GetYaxis()->SetTitleOffset(1.3);
  framework->GetYaxis()->SetTitleFont(42);
  framework->GetYaxis()->SetTitleSize(0.035);
  framework->Draw();

  
  TGraph* TGObsLimit   = ObsLimit;  TGObsLimit->SetLineWidth(2);
  TGraph* TGExpLimit   = ExpLimit;  TGExpLimit->SetLineWidth(2); TGExpLimit->SetLineStyle(2);
  TCutG* TGExpLimit1S  = GetErrorBand("1S", ExpLimitm1, ExpLimitp1);  
  TCutG* TGExpLimit2S  = GetErrorBand("2S", ExpLimitm2, ExpLimitp2);  TGExpLimit2S->SetFillColor(5);
  THXSec->SetLineWidth(2); THXSec->SetLineStyle(1); THXSec->SetLineColor(4);

  TGExpLimit->SetLineColor(1);  TGExpLimit->SetLineStyle(2);
  TGObsLimit->SetLineWidth(2);  TGObsLimit->SetMarkerStyle(20);
  TGExpLimit2S->Draw("fc same");
  TGExpLimit1S->Draw("fc same");
  if(!blind) TGObsLimit->Draw("same P");
  TGExpLimit->Draw("same c");

  
  /*if(strengthLimit){
     TLine* SMLine = new TLine(framework->GetXaxis()->GetXmin(),1.0,framework->GetXaxis()->GetXmax(),1.0);
     SMLine->SetLineWidth(2); SMLine->SetLineStyle(1); SMLine->SetLineColor(4);      
     SMLine->Draw("same C");
  }else{
     THXSec->Draw("same C");
  }*/

  utils::root::DrawPreliminary(luminosity, energy, c);

  
  TLegend* LEG = new TLegend(0.55,0.75,0.85,0.95);
  LEG->SetHeader("");
  LEG->SetFillColor(0);
  LEG->SetFillStyle(0);
  LEG->SetTextFont(42);
  LEG->SetBorderSize(0);
  //LEG->AddEntry(THXSec  , "Th prediction"  ,"L");
  LEG->AddEntry(TGExpLimit  , "median expected"  ,"L");
  LEG->AddEntry(TGExpLimit1S  , "expected #pm 1#sigma"  ,"F");
  LEG->AddEntry(TGExpLimit2S  , "expected #pm 2#sigma"  ,"F");
  if(!blind) LEG->AddEntry(TGObsLimit  , "observed"  ,"LP");
  LEG->Draw();
  c->RedrawAxis();
  c->SaveAs((outputDir+"Limit.png").c_str());
  c->SaveAs((outputDir+"Limit.C").c_str());
  c->SaveAs((outputDir+"Limit.pdf").c_str()); 

  
  //save a summary of the limits
  FILE* pFileSum = fopen((outputDir+"LimitSummary").c_str(),"w");
  for(int i=0;i<TGExpLimit->GetN();i++){
     double M = ExpLimit->GetX()[i];
     fprintf(pFileSum, "$%8.6E$ & $%8.6E$ & $[%8.6E,%8.6E]$ & $[%8.6E,%8.6E]$ & $%8.6E$ & Th=$%8.6E$ & pValue=$%8.6E$\\\\\\hline\n",M, ExpLimit->Eval(M), ExpLimitm1->Eval(M), ExpLimitp1->Eval(M), ExpLimitm2->Eval(M),  ExpLimitp2->Eval(M), ObsLimit->Eval(M), (THXSec!=NULL)?THXSec->Eval(M):-1, pValue->Eval(M));
    if(int(ExpLimit->GetX()[i])%50!=0)continue; printf("%f ",ObsLimit->Eval(M));
  }printf("\n");
  fclose(pFileSum);

  pFileSum = fopen((outputDir+"LimitRange").c_str(),"w");
  fprintf(pFileSum, "EXPECTED LIMIT --> ");                   printLimits(pFileSum,TGExpLimit, TGExpLimit->GetX()[0], TGExpLimit->GetX()[TGExpLimit->GetN()-1]);
  if(!blind) fprintf(pFileSum, "OBSERVED LIMIT --> ");        printLimits(pFileSum,TGObsLimit, TGObsLimit->GetX()[0], TGObsLimit->GetX()[TGObsLimit->GetN()-1]);
  fprintf(pFileSum, "Exp Limits for Model are: ");              for(int i=0;i<TGExpLimit->GetN();i++){if(int(TGExpLimit->GetX()[i])%50==0) fprintf(pFileSum, "%f+-%f ",TGExpLimit->GetY()[i], (ExpLimitp1->GetY()[i]-ExpLimitm1->GetY()[i])/2.0);}fprintf(pFileSum,"\n");
  if(!blind) { fprintf(pFileSum, "Obs Limits for Model are: "); for(int i=0;i<TGObsLimit->GetN();i++){if(int(TGObsLimit->GetX()[i])%50==0) fprintf(pFileSum, "%f ",TGObsLimit->GetY()[i]);}fprintf(pFileSum,"\n"); }
  fclose(pFileSum); 
}
void DrawResponsePlot( Float_t genMean[], Float_t genSigma[], 
		       Float_t recoMean[], Float_t recoSigma[]) {


  gROOT->ProcessLine(".L mystyle.C");
  setTDRStyle();
  tdrStyle->SetErrorX(0.5);
  tdrStyle->SetPadLeftMargin(0.2);
  tdrStyle->SetPadRightMargin(0.10);
  tdrStyle->SetLegendBorderSize(0);
  tdrStyle->SetTitleYOffset(1.3);

  // plot full spectrum
  TGraphErrors *ptbalanceGen  = new TGraphErrors(nZPtBins, pt, genMean, 
						 errpt, genSigma);
  TGraphErrors *ptbalanceReco = new TGraphErrors(nZPtBins, pt, recoMean, 
						 errpt, recoSigma);
  // plot Zmumu values
  Float_t ptmm[9] = { 40.0, 60.0, 100.0, 140.0, 200.0, 250.0, 
		      330.0, 400.0, 520.0 };
  Float_t balancemm[9] = { 0.496, 0.568, 0.66, 0.71, 0.75, 0.765, 
			   0.775, 0.79, 0.81 }; 
  TGraph *ptbalancemm = new TGraph( 9, ptmm, balancemm);


  ptbalanceGen->GetXaxis()->SetTitle("p_{T}^{Z} (GeV/c)");
  ptbalanceGen->GetYaxis()->SetTitle("p_{T}^{jet} / p_{T}^{Z}");
  ptbalanceGen->SetMarkerStyle(22);
  ptbalanceGen->SetMarkerSize(1.2);
  ptbalanceGen->SetTitle("");
  ptbalanceGen->SetMinimum(0.3);
  ptbalanceReco->SetMarkerColor(2);
  ptbalanceReco->SetLineColor(2);
  ptbalanceReco->SetMarkerStyle(22);
  ptbalanceReco->SetMarkerSize(1.2);
  ptbalanceReco->SetMinimum(0.3);
  ptbalancemm->SetMarkerStyle(24);
  ptbalancemm->SetMarkerSize(1.2);
  ptbalancemm->SetMinimum(0.3);
  ptbalancemm->SetMarkerColor(4);
  ptbalancemm->SetLineColor(4);

  TCanvas c1("c1","",500,500);
  ptbalanceGen->Draw("APL");
  ptbalanceReco->Draw("PL");
  ptbalancemm->Draw("PL");
  leg_hist = new TLegend(0.6,0.7,0.89,0.89);
  leg_hist->AddEntry( ptbalanceGen, "Generator level", "l");
  leg_hist->AddEntry( ptbalanceReco,"Calorimeter level","l");
  leg_hist->AddEntry( ptbalancemm,"Z#rightarrow#mu#mu","l");
  leg_hist->SetFillColor(0);
  leg_hist->Draw();
  c1.SaveAs("PtBalanceVsPt.eps");
  c1.SaveAs("PtBalanceVsPt.gif");
  c1.SaveAs("PtBalanceVsPt.root");
  c1.Close();
  delete leg_hist;
  delete ptbalanceGen;
  delete ptbalanceReco;
  delete ptbalancemm;
}
Beispiel #6
0
void PlotEffGen(TString fileName = "DYJetsEff",
		// TString numName = "TPPassed",
		// TString denName = "TPAll",
		//		TString numName = "RecoPassedTag",
		//		TString denName = "RecoAllTag",
		TString numName = "RecoPassed",
		TString denName = "RecoAll",
		bool posTag = true,
		bool isMuId = true,
		bool isPrompt = true) {


  setTDRStyle();

  TString name("ElectronPt_");
  if (isMuId)
    name = "MuonPt_";

  TString LepQ("Neg");
  if (posTag)
    LepQ = "Pos";

  TString Type("NonPrompt");
  if (isPrompt)
    Type = "Prompt";

  int nEtaBins = 3;
  TString EtaBinName[3] = {"0To0p8",
			   "0p8To1p5",
			   "1p5To2p3"};
  TFile * file = new TFile(fileName+".root");

  int nPtBins = 7;
  float ptBins[8] = {10,15,20,30,40,50,70,100};

  TH1F * histos[3][2];
  for (int iEta=0; iEta<3; ++iEta) {
    TH1F * histNum = (TH1F*)file->Get(name+LepQ+Type+numName+EtaBinName[iEta]);
    histos[iEta][0] = TH1toTH1(histNum,nPtBins,ptBins,true,"_new");
    TH1F * histDen = (TH1F*)file->Get(name+LepQ+Type+denName+EtaBinName[iEta]);
    histos[iEta][1] = TH1toTH1(histDen,nPtBins,ptBins,true,"_new");
    
  }

  int color[3] = {1,2,4};
  int symbol[3] = {20,21,22};

  TGraphAsymmErrors * eff[3];
  for (int iEta=0; iEta<3; ++iEta) {
    eff[iEta] = new TGraphAsymmErrors();
    eff[iEta]->SetLineColor(color[iEta]);
    eff[iEta]->SetMarkerColor(color[iEta]);
    eff[iEta]->SetLineWidth(2);
    eff[iEta]->SetMarkerSize(1.6);
    eff[iEta]->SetMarkerStyle(symbol[iEta]);
    eff[iEta]->Divide(histos[iEta][0],histos[iEta][1],"Pois");
  }  

 
  TH2F * frame = new TH2F("frame","",2,0,100,2,0,1);
  TCanvas * canv = new TCanvas("canv","",700,700);
  frame->Draw();
  eff[0]->Draw("PS");
  eff[1]->Draw("PS");
  eff[2]->Draw("PS");
  canv->Update();

}
Beispiel #7
0
bool                                          // returns true if success
processStyleSection(FILE *fp,string& theline, bool& new_section)
{
  vector<string> v_tokens;

  string *sid      = NULL;
  TStyle *thestyle = NULL;

  if (gl_verbose)
    cout << "Processing style section" << endl;

  new_section=false;

  while (getLine(fp,theline,"style")) {
    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome

    if (theline[0] == '[') {
      new_section=true;
      return true;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    if (key == "id") {
      if (sid != NULL) {
	cerr << "no more than one id per style section allowed " << value << endl;
	break;
      }

      sid = new string(value);
      thestyle = new TStyle(*gStyle); // Assume current attributes, let user override specifics
      thestyle->SetNameTitle(sid->c_str(),sid->c_str());
      glmap_id2style.insert(pair<string,TStyle*>(*sid,thestyle));
      continue;
    }
    else if (!sid) {
      // assume the style is the global style
      thestyle = gStyle;
      sid = new string("using global"); // so as to pass this check the next time
      cerr << "No style ID defined, assuming global style" << endl;
      continue;
    }

    if (key == "style") {
      if (value == "TDR")
	setTDRStyle();
      else if (value == "Plain")
	gROOT->SetStyle("Plain");
      else 
	cerr << "unknown style name " << value << endl;
    }
    else if (key == "optstat")  {
      if (gl_verbose) cout << "OptStat = " << thestyle->GetOptStat() << endl;
      thestyle->SetOptStat(value.c_str());
      if (gl_verbose) cout << "OptStat = " << thestyle->GetOptStat() << endl;
    }
    else if (key == "opttitle")  thestyle->SetOptTitle(str2int(value));

    else if (key == "padrightmargin")  thestyle->SetPadRightMargin (str2flt(value));
    else if (key == "padleftmargin")   thestyle->SetPadLeftMargin  (str2flt(value));
    else if (key == "padtopmargin")    thestyle->SetPadTopMargin   (str2flt(value));
    else if (key == "padbottommargin") thestyle->SetPadBottomMargin(str2flt(value));
    else if (key == "padgridx")        thestyle->SetPadGridX       (str2int(value));
    else if (key == "padgridy")        thestyle->SetPadGridY       (str2int(value));

    // Set the position/size of the title box

    else if (key == "titlexndc")    thestyle->SetTitleX(str2flt(value));
    else if (key == "titleyndc")    thestyle->SetTitleY(str2flt(value));
    else if (key == "titlewndc")    thestyle->SetTitleW(str2flt(value));
    else if (key == "titlehndc")    thestyle->SetTitleH(str2flt(value));
    else if (key == "titlefont")    thestyle->SetTitleFont(str2int(value));
    else if (key == "titlebordersize") thestyle->SetTitleBorderSize(str2int(value));

    else if (key == "markercolor")  thestyle->SetMarkerColor(str2int(value));
    else if (key == "markerstyle")  thestyle->SetMarkerStyle(str2int(value));
    else if (key == "markersize")   thestyle->SetMarkerSize(str2int(value));
    else if (key == "linecolor")    thestyle->SetLineColor(str2int(value));
    else if (key == "linestyle")    thestyle->SetLineStyle(str2int(value));
    else if (key == "linewidth")    thestyle->SetLineWidth(str2int(value));
    else if (key == "fillcolor")    thestyle->SetFillColor(str2int(value));
    else if (key == "fillstyle")    thestyle->SetFillStyle(str2int(value));

    // axes
    else if (key == "xtitlesize")   thestyle->SetTitleSize(str2flt(value),"X");
    else if (key == "ytitlesize")   thestyle->SetTitleSize(str2flt(value),"Y");
    else if (key == "ztitlesize")   thestyle->SetTitleSize(str2flt(value),"Z");
    else if (key == "xtitleoffset") thestyle->SetTitleOffset(str2flt(value),"X");
    else if (key == "ytitleoffset") thestyle->SetTitleOffset(str2flt(value),"Y");
    else if (key == "ztitleoffset") thestyle->SetTitleOffset(str2flt(value),"Z");
    else if (key == "xlabeloffset") thestyle->SetLabelOffset(str2flt(value),"X");
    else if (key == "ylabeloffset") thestyle->SetLabelOffset(str2flt(value),"Y");
    else if (key == "zlabeloffset") thestyle->SetLabelOffset(str2flt(value),"Z");
    else if (key == "xtitlefont")   thestyle->SetTitleFont(str2int(value),"X");
    else if (key == "ytitlefont")   thestyle->SetTitleFont(str2int(value),"Y");
    else if (key == "ztitlefont")   thestyle->SetTitleFont(str2int(value),"Z");
    else if (key == "xlabelsize")   thestyle->SetLabelSize(str2flt(value),"X");
    else if (key == "ylabelsize")   thestyle->SetLabelSize(str2flt(value),"Y");
    else if (key == "zlabelsize")   thestyle->SetLabelSize(str2flt(value),"Z");
    else if (key == "xlabelfont")   thestyle->SetLabelFont(str2int(value),"X");
    else if (key == "ylabelfont")   thestyle->SetLabelFont(str2int(value),"Y");
    else if (key == "zlabelfont")   thestyle->SetLabelFont(str2int(value),"Z");
    else if (key == "xndiv")        thestyle->SetNdivisions(str2int(value),"X");
    else if (key == "yndiv")        thestyle->SetNdivisions(str2int(value),"Y");
    else if (key == "zndiv")        thestyle->SetNdivisions(str2int(value),"Z");

    // Set the position of the statbox
    else if (key == "statx2ndc")    thestyle->SetStatX(str2flt(value));
    else if (key == "staty2ndc")    thestyle->SetStatY(str2flt(value));
    else if (key == "statwndc")     thestyle->SetStatW(str2flt(value));
    else if (key == "stathndc")     thestyle->SetStatH(str2flt(value));

    else if (key == "statfont")     thestyle->SetStatFont    (str2int(value));
    else if (key == "statfontsize") thestyle->SetStatFontSize(str2flt(value));
    else if (key == "statformat")   thestyle->SetStatFormat  (value.c_str());
    else if (key == "statstyle")    thestyle->SetStatStyle   (str2int(value.c_str()));

    else if (key == "fitformat")    thestyle->SetFitFormat   (value.c_str());

    else if (key == "painttextfmt") thestyle->SetPaintTextFormat(value.c_str());
    else if (key == "markersize")   thestyle->SetMarkerSize(str2flt(value));
    else {
      cerr << "Unknown key " << key << endl;
    }

  } // while loop

  return true;
}                                                 // processStyleSection
Beispiel #8
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;



}
Beispiel #9
0
void plotMC(){//main  
TFile *file[6];

file[0]= TFile::Open("../data/plot_T5Wg_mGl-800to1000.root");  
file[1]= TFile::Open("../data/plot_T5Wg_mGl-1050to1100.root");
file[2]= TFile::Open("../data/plot_T5Wg_mGl-1250to1300.root");
file[3]= TFile::Open("../data/plot_T5Wg_mGl-1350to1400.root");
file[4]= TFile::Open("../data/plot_T5Wg_mGl-1450to1500.root");
file[5]= TFile::Open("../data/plot_T5Wg_mGl-1550.root");

TH2F *p_SUSYMass[6];
TH1F *p_mcphotonET[6];
TH1F *p_mceleET[6];
TH1F *p_phoEBR9_true[6]; 
TH1F *p_phoEER9_true[6];
TH1F *p_phoEBHoverE_true[6];
TH1F *p_phoEEHoverE_true[6];
TH1F *p_phoEBsigma_true[6];
TH1F *p_phoEEsigma_true[6];
TH1F *p_phoEBChIso_true[6];
TH1F *p_phoEEChIso_true[6];
TH1F *p_phoEBNeuIso_true[6];
TH1F *p_phoEENeuIso_true[6];
TH1F *p_phoEBPhoIso_true[6];
TH1F *p_phoEEPhoIso_true[6];

TH1F *p_eleEBR9_true[6];
TH1F *p_eleEER9_true[6];

TH1F *p_eleEBR9_idselect[6];
TH1F *p_eleEER9_idselect[6];

TH1F *p_Mt[6];
TH1F *p_PhoELeDeltaR[6];
TH1F *p_PhoEleMass[6];
TH1F *p_selectPhoEleMass[6];

for(unsigned iF(0); iF < 6; iF++){
  p_SUSYMass[iF] = (TH2F*)file[iF]->Get("Mass");

  p_mcphotonET[iF] = (TH1F*)file[iF]->Get("photonET");
  p_mceleET[iF] = (TH1F*)file[iF]->Get("eleET");

  p_phoEBR9_true[iF] = (TH1F*)file[iF]->Get("p_phoEBR9");
  p_phoEBR9_true[iF]->GetXaxis()->SetRangeUser(0.5,1);
  p_phoEER9_true[iF] = (TH1F*)file[iF]->Get("p_phoEER9");
  p_phoEER9_true[iF]->GetXaxis()->SetRangeUser(0.5,1);
  p_phoEBHoverE_true[iF] = (TH1F*)file[iF]->Get("p_phoEBHoverE");
  p_phoEEHoverE_true[iF] = (TH1F*)file[iF]->Get("p_phoEEHoverE");
  p_phoEBsigma_true[iF] = (TH1F*)file[iF]->Get("p_phoEBsigma");
  p_phoEEsigma_true[iF] = (TH1F*)file[iF]->Get("p_phoEEsigma");
  p_phoEBChIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEBChIso");
  p_phoEEChIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEEChIso");
  p_phoEBNeuIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEBNeuIso");
  p_phoEENeuIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEENeuIso");
  p_phoEBPhoIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEBPhoIso");
  p_phoEEPhoIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEEPhoIso");

  p_eleEBR9_true[iF] = (TH1F*)file[iF]->Get("p_eleEBR9");
  p_eleEBR9_true[iF]->GetXaxis()->SetRangeUser(0.5,1);
  p_eleEER9_true[iF] = (TH1F*)file[iF]->Get("p_eleEER9");
  p_eleEER9_true[iF]->GetXaxis()->SetRangeUser(0.5,1);

  p_eleEBR9_idselect[iF] = (TH1F*)file[iF]->Get("p_eleEBR9_idselect");
  p_eleEBR9_idselect[iF]->GetXaxis()->SetRangeUser(0.5,1);
  p_eleEER9_idselect[iF] = (TH1F*)file[iF]->Get("p_eleEER9_idselect");
  p_eleEER9_idselect[iF]->GetXaxis()->SetRangeUser(0.5,1);

  p_Mt[iF] = (TH1F*)file[iF]->Get("Mt");
  p_PhoELeDeltaR[iF] = (TH1F*)file[iF]->Get("p_PhoELeDeltaR");
  p_PhoEleMass[iF] = (TH1F*)file[iF]->Get("p_PhoEleMass");
  p_selectPhoEleMass[iF] = (TH1F*)file[iF]->Get("p_selectPhoEleMass");
}

p_SUSYMass[0]->Add(p_SUSYMass[1]); 
p_SUSYMass[0]->Add(p_SUSYMass[2]);
p_SUSYMass[0]->Add(p_SUSYMass[3]);
p_SUSYMass[0]->Add(p_SUSYMass[4]);
p_SUSYMass[0]->Add(p_SUSYMass[5]);

setTDRStyle();    
TCanvas *hist_MC[6][19];
std::ostringstream canvas; 

for(unsigned iF(0); iF<6; iF++){
  for(unsigned iC(0); iC<19; iC++){
    canvas.str("");
    canvas << "energy" << iF << "_canvas" << iC;
    hist_MC[iF][iC] = new TCanvas(canvas.str().c_str(),canvas.str().c_str(),600,600);
  }
}

TCanvas *canMass = new TCanvas("SUSY Mass","SUSY Mass",600,600);
TCanvas *canEt = new TCanvas("Photon Et","Photon Et",600,600);
canEt->cd();
int norm(1);
int LineColor[] = {1,2,3,4,6,41};
string FileList[] = {"M_{#tilde{g}}=800 to 1000","M_{#tilde{g}}=1050 to 1100", "M_{#tilde{g}}=1250 to 1300","M_{#tilde{g}}=1350 to 1400","M_{#tilde{g}}=1450 to 1500","M_{#tilde{g}}=1550"};
TLegend *legEt =  new TLegend(0.4,0.55,0.86,0.85);
std::ostringstream histname;
for(unsigned ii(0); ii<6; ii++){
  histname.str("");
  histname << FileList[ii];
  norm = p_mcphotonET[ii]->GetEntries();
  p_mcphotonET[ii]->Scale(1.0/norm);
  p_mcphotonET[ii]->SetLineColor(LineColor[ii]);
  legEt->AddEntry(p_mcphotonET[ii],histname.str().c_str());
  if(ii==0)p_mcphotonET[ii]->Draw();
  else p_mcphotonET[ii]->Draw("same");
}
legEt->Draw("same");

canMass->cd();
Int_t PaletteColors[] = {kBlue+1, kBlue, kBlue-7, kCyan,kGreen, kGreen-6}; // #colors >= #levels - 1
TLine *MassGridX[32];
TLine *MassGridY[16];
for(unsigned ix(0); ix < 32; ix++)MassGridX[ix]= new TLine(ix*50,800,ix*50,1600);
for(unsigned iy(0); iy < 16; iy++)MassGridY[iy]= new TLine(0,iy*50+800,1600,iy*50+800);
gStyle->SetPalette((sizeof(PaletteColors)/sizeof(Int_t)), PaletteColors);
p_SUSYMass[0]->GetYaxis()->SetTitleOffset(1.7);
p_SUSYMass[0]->Draw("colz");
for(unsigned ix(0); ix < 32; ix++)MassGridX[ix]->Draw("same");
for(unsigned iy(0); iy < 16; iy++)MassGridY[iy]->Draw("same");

TCanvas *canPt = new TCanvas("Electron Pt","Electron Pt",600,600);
canPt->cd();
for(unsigned ii(0); ii<6; ii++){
  norm = p_mceleET[ii]->GetEntries();
  p_mceleET[ii]->Scale(1.0/norm);
  p_mceleET[ii]->SetLineColor(LineColor[ii]);
  if(ii==0)p_mceleET[ii]->Draw();
  else p_mceleET[ii]->Draw("same");
}
legEt->Draw("same");


TCanvas *canMT = new TCanvas("MT","MT",600,600);
canMT->cd();
for(unsigned ii(0); ii<6; ii++){
  norm = p_Mt[ii]->GetEntries();
  p_Mt[ii]->Scale(1.0/norm);
  p_Mt[ii]->SetLineColor(LineColor[ii]);
  if(ii==0)p_Mt[ii]->Draw();
  else p_Mt[ii]->Draw("same");
}
legEt->Draw("same");


for(unsigned iF(0); iF<6; iF++){
  TAxis *axis = p_selectPhoEleMass[iF]->GetXaxis();
  Int_t bmin = axis->FindBin(0.0); 
  Int_t bmax = axis->FindBin(95.0); 
  double integral = p_selectPhoEleMass[iF]->Integral(bmin,bmax);
  std::cout << integral << " events less then 95GeV out of " << p_selectPhoEleMass[iF]->GetEntries() << std::endl;

  hist_MC[iF][0]->cd();
  p_selectPhoEleMass[iF]->Draw();
  TLine *masscut = new TLine(95,0,95,1000);
  masscut->SetLineColor(kRed);
  masscut->Draw("same");

  hist_MC[iF][1]->cd();
  p_mceleET[iF]->Draw();
  hist_MC[iF][2]->cd();
  p_phoEBR9_true[iF]->Draw();
  hist_MC[iF][3]->cd();
  p_phoEER9_true[iF]->Draw();
  hist_MC[iF][4]->cd();
  gPad->SetLogy();
  p_phoEBHoverE_true[iF]->Draw();
  hist_MC[iF][5]->cd();
  gPad->SetLogy();
  p_phoEEHoverE_true[iF]->Draw();
  hist_MC[iF][6]->cd();
  p_phoEBsigma_true[iF]->Draw();
  hist_MC[iF][7]->cd();
  p_phoEEsigma_true[iF]->Draw();
  hist_MC[iF][8]->cd();
  gPad->SetLogy();
  p_phoEBChIso_true[iF]->Draw();
  hist_MC[iF][9]->cd();
  gPad->SetLogy();
  p_phoEEChIso_true[iF]->Draw();
  hist_MC[iF][10]->cd();
  gPad->SetLogy();
  p_phoEBNeuIso_true[iF]->Draw();
  hist_MC[iF][11]->cd();
  gPad->SetLogy();
  p_phoEENeuIso_true[iF]->Draw();
  hist_MC[iF][12]->cd();
  gPad->SetLogy();
  p_phoEBPhoIso_true[iF]->Draw();
  hist_MC[iF][13]->cd();
  gPad->SetLogy();
  p_phoEEPhoIso_true[iF]->Draw();
  hist_MC[iF][14]->cd();
  p_eleEBR9_true[iF]->SetLineColor(kBlue);
  p_eleEBR9_idselect[iF]->SetLineColor(kRed);
  TLegend *legEBR9 =  new TLegend(0.4,0.65,0.86,0.85);
  legEBR9->AddEntry(p_eleEBR9_true[iF],"all e#pm R9");
  legEBR9->AddEntry(p_eleEBR9_idselect[iF],"pt>25GeV,medium WP e#pm,R9"); 
  p_eleEBR9_true[iF]->Draw();
  p_eleEBR9_idselect[iF]->Draw("same");
  legEBR9->Draw("same");

  hist_MC[iF][15]->cd();
  p_eleEER9_true[iF]->SetLineColor(kBlue);
  p_eleEER9_idselect[iF]->SetLineColor(kRed);
  TLegend *legEER9 =  new TLegend(0.4,0.65,0.86,0.85);
  legEER9->AddEntry(p_eleEER9_true[iF],"all e#pm R9");
  legEER9->AddEntry(p_eleEER9_idselect[iF],"pt>25GeV,medium WP e#pm, R9"); 
  p_eleEER9_true[iF]->Draw();
  p_eleEER9_idselect[iF]->Draw("same");
  legEER9->Draw("same");

  hist_MC[iF][16]->cd();
  p_Mt[iF]->Draw();
  hist_MC[iF][17]->cd();
  p_PhoELeDeltaR[iF]->Draw();
  hist_MC[iF][18]->cd();
  p_PhoEleMass[iF]->Draw();
}


for(unsigned iF(0); iF<6; iF++){
  for(unsigned iC(0); iC<19; iC++){
    canvas.str("");
    canvas << "energy" << iF << "_canvas" << iC << ".pdf";
    hist_MC[iF][iC]->SaveAs(canvas.str().c_str());
  }
}

canEt->SaveAs("MC_photonEt.pdf");
canMass->SaveAs("SUSY_Mass.pdf");
canPt->SaveAs("MC_elePt.pdf");
canMT->SaveAs("MC_MT.pdf");
}
Beispiel #10
0
// .x PlotEffPt.C("DYJets","RecoPassedTag","RecoAllTag","RecoPassedTag","RecoAllTag",1,"NonPrompt","Prompt",2,0.4,1.0,"Id+Iso efficiency")
void PlotEffPt(TString fileName = "DYJets_TP",
	       TString numName0 = "RecoPassedTag",
	       TString denName0 = "RecoAllTag",
	       TString numName1 = "RecoPassedTag",
	       TString denName1 = "RecoAllTag",
	       bool isMuId = true,
	       TString namePrompt0 = "NonPrompt",
	       TString namePrompt1 = "Prompt",
	       int EtaBin = 2,
	       float yMin = 0.4,
	       float yMax = 1.0,
	       TString yTitle="Id+Iso efficiency") {
  // inputs
  // fileName - the name of the RooT file produced by AnalysisMacroEff (without .root extension)
  // numName0 - name of the numerator histogram for non-prompt leptons
  // denName0 - name of the denominator histogram for non-prompt leptons
  // numName1 - name of the numerator histogram for prompt leptons
  // denName1 - name of the denominator histogram for prompt leptons
  // isMuId - false : electron , true : muon
  // namePrompt0 - name of the histogram for prompt leptons
  // namePrompt1 - name of the histogram for non-prompt leptons
  // EtaBin - eta bin  0 : 0-0.8,  1 : 0.8-1.5, 2 : 1.5-2.4
  // yMin, yMax - ranges of the y axis (efficiency)
  // yTitle : title of y axis

  setTDRStyle();

  int lepSign = 0;

  TString name("ElectronPt_");
  if (isMuId)
    name = "MuonPt_";

  TString LepQ("Neg");
  if (lepSign>0)
    LepQ = "Pos";

  TString Type[2];
  Type[0] = namePrompt0;
  Type[1] = namePrompt1;


  int nEtaBins = 3;
  TString EtaBinName[3] = {"0To0p8",
			   "0p8To1p5",
			   "1p5To2p3"};

  TString EtaLeg[3] = {"#eta = [0,0.8]","#eta = [0.8,1.5]","#eta = [1.5,2.5]"};
  if (isMuId)
    EtaLeg[2] = "#eta = [1.5,2.4]";

  TFile * file = new TFile(fileName+".root");

  int nPtBins = 7;
  float ptBins[8] = {10,15,20,30,40,50,70,100};
  TString numName[2];
  TString denName[2];
  numName[0] = numName0;
  numName[1] = numName1;
  denName[0] = denName0;
  denName[1] = denName1;  

  TH1F * histos[3][2][2];
  for (int iEta=0; iEta<3; ++iEta) {
    for (int iType=0; iType<2; ++iType) {
      TH1F * histNum = (TH1F*)file->Get(name+LepQ+Type[iType]+numName[iType]+EtaBinName[iEta]);
      if (lepSign==0) {
	TH1F * histNumX = (TH1F*)file->Get(name+"Pos"+Type[iType]+numName[iType]+EtaBinName[iEta]);
	histNum->Add(histNum,histNumX);
      }
      histos[iEta][iType][0] = TH1toTH1(histNum,nPtBins,ptBins,false,"_new");
      TH1F * histDen = (TH1F*)file->Get(name+LepQ+Type[iType]+denName[iType]+EtaBinName[iEta]);
      if (lepSign==0) {
	TH1F * histDenX = (TH1F*)file->Get(name+"Pos"+Type[iType]+denName[iType]+EtaBinName[iEta]);
	histDen->Add(histDen,histDenX);
      }
      histos[iEta][iType][1] = TH1toTH1(histDen,nPtBins,ptBins,false,"_new");
    }
  }

  int color[3] = {1,2,4};
  int symbol[3] = {20,21,22};

  TGraphAsymmErrors * eff[3][2];
  for (int iEta=0; iEta<3; ++iEta) {
    for (int iType=0; iType<2; ++iType) {
      eff[iEta][iType] = new TGraphAsymmErrors();
      eff[iEta][iType]->SetLineColor(color[iEta]);
      eff[iEta][iType]->SetMarkerColor(color[iEta]);
      eff[iEta][iType]->SetLineWidth(2);
      eff[iEta][iType]->SetMarkerSize(2.5);
      eff[iEta][iType]->SetMarkerStyle(symbol[iEta]);
      if (iType==1)
	eff[iEta][iType]->SetMarkerStyle(symbol[iEta]+4);
      eff[iEta][iType]->Divide(histos[iEta][iType][0],histos[iEta][iType][1]);
    }
  }  
 
  // **************
  // Tag-and-Probe
  // **************

  TString mass("massEEId_");
  if (isMuId) 
    mass = "massMuMuId_";

  TString TagQ("Pos");

  int nPtBins = 7;
  float ptBins[8] = {10,15,20,30,40,50,70,100};
  TString PtBinName[7] = {"pt10to15",
			  "pt15to20",
			  "pt20to30",
			  "pt30to40",
			  "pt40to50",
			  "pt50to70",
			  "pt70to100"};
  
  TString passName[2] = {"Pass","Fail"};

  TH1F * histosTP[3][2];
  for (int iEta=0; iEta<3; ++iEta) {
    for (int iPass=0; iPass<2; ++iPass) {
      histosTP[iEta][iPass] = new TH1F(passName[iPass]+EtaBinName[iEta],"",nPtBins,ptBins);
      for (int iPt=0; iPt<nPtBins; ++iPt) {
	TH1F * hist = (TH1F*)file->Get(mass+TagQ+EtaBinName[iEta]+PtBinName[iPt]+passName[iPass]);
	float yield = hist->GetSum();
	histosTP[iEta][iPass]->SetBinContent(iPt+1,yield);
      }
    }
  }
  
  TGraphAsymmErrors * effTP[3];
  for (int iEta=0; iEta<3; ++iEta) {
    effTP[iEta] = new TGraphAsymmErrors();
    effTP[iEta]->SetLineColor(color[iEta]);
    effTP[iEta]->SetMarkerColor(color[iEta]);
    effTP[iEta]->SetLineWidth(2);
    effTP[iEta]->SetMarkerSize(3);
    effTP[iEta]->SetMarkerStyle(28);
    histosTP[iEta][1]->Add(histosTP[iEta][0],histosTP[iEta][1]);
    effTP[iEta]->Divide(histosTP[iEta][0],histosTP[iEta][1]);
  }  

  TH2F * frame = new TH2F("frame","",2,10,50,2,yMin,yMax);
  frame->GetYaxis()->SetTitle(yTitle);
  frame->GetXaxis()->SetTitle("electron p_{T} [GeV/c]");
  //  frame->GetYaxis()->SetNdivisions(505);
  TString LegName("Z#rightarrowee");
  if (isMuId) {
    frame->GetXaxis()->SetTitle("muon p_{T} [GeV/c]");
    LegName = "Z#rightarrow#mu#mu";
  }
  TCanvas * canv = new TCanvas("canv","",900,700);
  frame->Draw();
  eff[EtaBin][0]->Draw("EPS");
  eff[EtaBin][1]->Draw("EPS");
  //  effTP[EtaBin]->Draw("EPS");

  TLegend * leg = new TLegend(0.6,0.2,0.9,0.5);
  leg->SetFillColor(0);
  leg->SetHeader(EtaLeg[EtaBin]);
  leg->AddEntry(eff[EtaBin][0],"Z#rightarrow#tau#tau#rightarrowe+#mu","lp");
  leg->AddEntry(eff[EtaBin][1],LegName,"lp");
  //  leg->AddEntry(effTP[EtaBin] ,LegName+" (T&P)","lp");
  leg->Draw();
  canv->Update();
  canv->Print(fileName+"_"+name+numName0+"_"+denName0+"_"+EtaBinName[EtaBin]+".gif");

}
void CheckDataFakes_CR_Bjet(){
  
  TH1::SetDefaultSumw2(true);
  setTDRStyle();
  
  TString param = "BJetCR_fakeparam_";

  TH1F* data_presel_hist = new TH1F("mcclosure","mcclosure", 10,0.,10.);
  data_presel_hist->GetYaxis()->SetTitle("Event");
  float ymax = 250.;
  data_presel_hist->GetYaxis()->SetRangeUser(0., ymax);
  data_presel_hist->GetXaxis()->SetTitle("");
  data_presel_hist->GetXaxis()->SetBinLabel(1,"PtvsEta");
  data_presel_hist->GetXaxis()->SetBinLabel(2,"HtvsEta");
  data_presel_hist->GetXaxis()->SetBinLabel(3,"PtvsEta_nbjet");
  data_presel_hist->GetXaxis()->SetBinLabel(4,"HtvsEta_X");
  data_presel_hist->GetXaxis()->SetBinLabel(5,"PtvsEta_X");
  data_presel_hist->GetXaxis()->SetBinLabel(6,"PtvsEta_nbjet_X");
  data_presel_hist->GetXaxis()->SetBinLabel(7,"PtvsEta_HT_nbjet_X");
  data_presel_hist->GetXaxis()->SetBinLabel(8,"PtvsEta_HT_X");
  data_presel_hist->GetXaxis()->SetBinLabel(9,"PtvsEta_HT");
  
  
  TString path_data= "/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_data_5_3_14.root";
  TFile * fdata = new TFile(path_data);
  
  TH1F* h_data_presel= (TH1F*)fdata->Get(param + "20");
  double error_up_data = GetError(h_data_presel , true);
  double error_down_data = GetError(h_data_presel , false);
  
  
  
  TCanvas* c1 = new TCanvas(("Plot"), "Plot", 1600, 1200);
  c1->cd();

  data_presel_hist->GetYaxis()->SetTitle("Event");
  data_presel_hist->Draw();

  
  vector<TString> jetpt;
  jetpt.push_back("20");
  jetpt.push_back("30");
  jetpt.push_back("40");
  jetpt.push_back("60");

  
  TString path_mc= "/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_mc_5_3_14.root";
  TFile * fmc = new TFile(path_mc);


  TString path_cf= "/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_SKchargeflip_dilep_5_3_14.root";
  TFile * fcf = new TFile(path_cf);


  TString path_np= "/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/NP/REG2/HNDiElectron_SKnonprompt_dilep_5_3_14.root";
  TFile * fnp = new TFile(path_np);

  TLegend* legendH = new TLegend(0.6,0.6, 0.9,0.9);
  legendH->SetFillColor(kWhite);
  legendH->SetTextFont(42);
  
  //h_data_presel->Draw("histsame");

  double jx[9], jxerr[9];
  double jy[9], jyerrup[9], jyerrdown[9];
  float offset = 0.1; 
  for(unsigned int bin = 0; bin < h_data_presel->GetNbinsX(); bin++){
    
    jx[bin] = bin+ offset;  jxerr[bin] = 0.;
    jy[bin] = h_data_presel->GetBinContent(bin+1);
    jyerrup[bin] = error_up_data;
    jyerrdown[bin] = error_down_data;
  }

  TGraphAsymmErrors * gd = new TGraphAsymmErrors(9, jx, jy, jxerr, jxerr,  jyerrup,jyerrdown);
  gd->SetLineWidth(2.0);
  gd->SetMarkerSize(2.);

  gd->Draw( "9sameP" );
  

  TLine *line = new TLine( data_presel_hist->GetBinLowEdge(data_presel_hist->GetXaxis()->GetFirst()),h_data_presel->GetBinContent(1),data_presel_hist->GetBinLowEdge(data_presel_hist->GetXaxis()->GetLast()+1),h_data_presel->GetBinContent(1));

  line->SetLineColor(kBlack);
  line->SetLineWidth(2);
  line->Draw();
  
  float ymaxlb = ymax * 0.6;
  float ymaxhb = ymax ;
  for(unsigned int b = 1; b < data_presel_hist->GetNbinsX(); b++){
    //Bin dividers
    if( b < 4) ymax = ymaxlb;
    else ymax = ymaxhb;
    TLine *lineb = new TLine( float(b), 0., float(b), ymax);
    lineb->SetLineColor(kRed);
    lineb->SetLineWidth(2);
    lineb->Draw();
  }

  

  legendH->AddEntry(gd, "Observed" , "pl");
  for(unsigned int j= 0 ; j < jetpt.size() ; j++){
    TH1F* h_mc_presel= (TH1F*)fmc->Get(param+jetpt.at(j));
    TH1F* h_np_presel= (TH1F*)fnp->Get(param+jetpt.at(j));
    TH1F* h_cf_presel= (TH1F*)fcf->Get(param+jetpt.at(j));
    
    if(j == 0){
      h_mc_presel->SetLineColor(kOrange);
    }
    if(j ==1){
      h_mc_presel->SetFillColor(870);
    }
    if(j == 2){
      h_mc_presel->SetFillColor(391);
    }
    if(j==3){
      h_mc_presel->SetFillColor(kBlue-2);
    }
    
    for(unsigned int i=1; i < h_mc_presel->GetNbinsX()+1 ; i++){
      float binerror = sqrt( (h_mc_presel->GetBinError(i)*h_mc_presel->GetBinError(i)) + ((h_mc_presel->GetBinContent(i)*0.2)*(h_mc_presel->GetBinContent(i)*0.2)));
      h_mc_presel->SetBinError(i , binerror);
    }
    for(unsigned int i=1 ;i < h_cf_presel->GetNbinsX()+1 ; i++){
      float binerror = sqrt( (h_cf_presel->GetBinError(i)*h_cf_presel->GetBinError(i)) + ((h_cf_presel->GetBinContent(i)*0.2)*(h_cf_presel->GetBinContent(i)*0.2)));
      h_cf_presel->SetBinError(i , binerror);
    }
    for(unsigned int i=1 ;i < h_np_presel->GetNbinsX()+1 ; i++){
      float binerror = sqrt( (h_np_presel->GetBinError(i)*h_np_presel->GetBinError(i)) + ((h_np_presel->GetBinContent(i)*0.4)*(h_np_presel->GetBinContent(i)*0.4)));
      h_np_presel->SetBinError(i , binerror);
    }
    
    h_mc_presel->Add(h_np_presel);
    h_mc_presel->Add(h_cf_presel);
    
    double jx[9], jxerr[9];
    double jy[9], jyerr[9];
    for(unsigned int i=0 ;i < h_mc_presel->GetNbinsX() ; i++){
      jx[i] = i + 0.4 + (0.1*float(j));
      jy[i] = h_mc_presel->GetBinContent(i+1);
      jyerr[i] =  h_mc_presel->GetBinError(i+1);
      jxerr[i] = 0.;
    }
    
    
    TGraphAsymmErrors * g = new TGraphAsymmErrors(9, jx, jy, jxerr, jxerr, jyerr, jyerr);

    if(j ==0){
      g->SetLineColor(kOrange);
      g->SetMarkerColor(kOrange);
      g->SetMarkerStyle(21.);
    }
    if(j ==1){
      g->SetLineColor(870);
      g->SetMarkerColor(870);
      g->SetMarkerStyle(22.);
    }
    if(j ==2){
      g->SetLineColor(kCyan);
      g->SetMarkerColor(kCyan);
      g->SetMarkerStyle(23.);
    }
    if(j ==3){
      g->SetLineColor(kBlue-2);
      g->SetMarkerColor(kBlue-2);
      g->SetMarkerStyle(23.);
    }
   
    g->SetLineWidth(2.);
    g->SetMarkerSize(2.);

    g->Draw( "9sameP" );
    

    legendH->AddEntry(g , "Awayjet pt > " + jetpt.at(j) , "lp");
  }
  legendH->Draw();
  
  CMS_lumi( c1, 2, 11 );
  c1->Update();
  c1->RedrawAxis();

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

  latex.SetTextFont(42);
  //  latex.SetTextAlign(31);
  float t = c1->GetTopMargin();
  latex.SetTextSize(lumiTextSize*t);

  TString label = "#bf{Preselection}";
  TString label2 = "#bf{2 Electrons + 2 Jets; Zveto }"; 
  float l = c1->GetLeftMargin()+0.05;
  latex.DrawLatex(l, 0.75 ,label);
  latex.DrawLatex(l, 0.7 ,label2);

  c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/DataFakes/Preselection" + param + "_looseregion2.pdf"));
    
}
void controlPlots(string strigger="Jet30"){

  gStyle->SetOptStat(0);
  gROOT->ProcessLine(".L ~/tdrstyle.C");
  setTDRStyle();
  //style modifications:
  gStyle->SetErrorX(0.5);
  gStyle->SetPadTopMargin(0.08);//.005
  gStyle->SetPadBottomMargin(0.10);//0.13
  gStyle->SetMarkerStyle(1);

  TCanvas *c = new TCanvas(("ptCutComp"+strigger).c_str(),("pt cut comparison (8 vs. 10 GeV), "+strigger).c_str(),100,300,500,500);
  TCanvas *cr = new TCanvas(("ptCutCompRat"+strigger).c_str(),("pt cut comparison (8 vs. 10 GeV) Ratio, "+strigger).c_str(),500,300,500,500);
  c->cd(); 

  //string strigger="jet30"; 
  double rebin= 5.0; 
  string file1 = "PT8vsPT10/ptcut8/histo-Data-HLT_" + strigger + "U-BBCorr_HadrJetMatchPt_OpenHLT-total.root"; 
  string file2 = "PT8vsPT10/ptcut10/histo-Data-HLT_" + strigger + "U-BBCorr_HadrJetMatchPt_OpenHLT-total.root";
  string plot="Vert_dR_2b_CORR";
  string label1 = "p_{T} > 8 GeV";   
  string label2 = "p_{T} > 10 GeV";   
  //string plot="Vert_dR_2b";  

  TFile *f1 = TFile::Open(file1.c_str(),"READ");
  TFile *f2 = TFile::Open(file2.c_str(),"READ");
  
  TH1F *hp1; f1->GetObject((plot).c_str(),hp1);
  TH1F *hp2; f2->GetObject((plot).c_str(),hp2);

  hp1->Rebin(rebin);
  hp2->Rebin(rebin);
  
  hp1->SetLineColor(1);
  hp1->SetMarkerColor(1);
  hp1->SetMarkerStyle(4);
  hp2->SetLineColor(2);
  hp2->SetMarkerColor(2);
  hp2->SetMarkerStyle(20);
  hp2->SetMarkerSize(1.13);
  

  bool hp1first = false;
  if(hp1->GetMaximum()>hp2->GetMaximum()) hp1first=true;
  double max; 
  if(hp1first){
    hp1->GetXaxis()->SetTitle("#Delta R"); 
    hp1->GetYaxis()->SetTitle("d#sigma /d#Delta R"); 
    hp1->GetYaxis()->SetTitleOffset(1.9); 
    hp1->GetXaxis()->SetRangeUser(0,3.9); 
    hp1->DrawCopy("PE");
    hp2->DrawCopy("PEsames");
    hp1->DrawCopy("PEsames");
    max = hp1->GetMaximum(); 
  }
  else{
    hp2->DrawCopy("PE");
    hp2->GetXaxis()->SetTitle("#Delta R"); 
    hp2->GetYaxis()->SetTitle("d#sigma /d#Delta R"); 
    hp2->GetYaxis()->SetTitleOffset(1.9); 
    hp2->GetXaxis()->SetRangeUser(0,3.9); 
    hp1->DrawCopy("PEsames");
    max = hp2->GetMaximum(); 
  }

  TLegend *leg = new TLegend(0.6,0.65,0.89,0.84);
  leg->SetHeader(("HLT_"+strigger+"U").c_str());
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->AddEntry(hp1,label1.c_str(),"PE");
  leg->AddEntry(hp2,label2.c_str(),"PE");
  leg->Draw();

  TLatex *   tex; 
  if(strigger=="Jet15") tex = new TLatex(0,max*1.26,"CMS    #sqrt{s} = 7 TeV, L = 3.1 pb^{-1}");
  else if(strigger=="Jet30") tex = new TLatex(0,max*1.17,"CMS    #sqrt{s} = 7 TeV, L = 3.1 pb^{-1}");
  else if(strigger=="Jet50") tex = new TLatex(0,max*1.13,"CMS    #sqrt{s} = 7 TeV, L = 3.1 pb^{-1}");
  tex->SetTextSize(0.040); //0.044
  tex->SetLineWidth(2);
  tex->Draw();

  gPad->RedrawAxis(); 

  cr->cd(); 
  hp2->Rebin(2); 
  hp1->Rebin(2); 
  TH1F *hrat = hp2->Clone(); 
  hrat->Divide(hp2,hp1,1,1);
  hrat->GetXaxis()->SetRangeUser(0,3.9); 
  hrat->GetXaxis()->SetTitle("#Delta R"); 
  hrat->GetYaxis()->SetTitle("ratio"); 
  hrat->GetYaxis()->SetTitleOffset(1.7); 
  hrat->SetLineColor(1);
  hrat->SetMarkerColor(1);  
  hrat->Draw(); 
  TLatex *tex2; 
  if(strigger=="Jet15") tex2 = new TLatex(0,1.53,"CMS    #sqrt{s} = 7 TeV, L = 3.1 pb^{-1}");
  else if(strigger=="Jet30") tex2 = new TLatex(0,1.187,"CMS    #sqrt{s} = 7 TeV, L = 3.1 pb^{-1}");
  else if(strigger=="Jet50") tex2 = new TLatex(0,1.143,"CMS    #sqrt{s} = 7 TeV, L = 3.1 pb^{-1}");
  tex2->SetTextSize(0.040); //0.044
  tex2->SetLineWidth(2);
  tex2->Draw();

}
Beispiel #13
0
void macroPlot( TString name, TString nameGen, const TString & nameFile1, const TString & nameFile2, const TString & title,
                const TString & resonanceType, const int rebinX, const int rebinY, const int fitType,
                const TString & outputFileName, const bool genMass) {

  gROOT->SetBatch(true);

  //Save the graphs in a file
  TFile *outputFile = new TFile(outputFileName,"RECREATE");

  setTDRStyle();

  TGraphErrors *grM_1 = fit2DProj(name, nameFile1, 100, rebinX, rebinY, fitType, outputFile, resonanceType, 0, "_1");
  TGraphErrors *grM_2 = fit2DProj(name, nameFile2, 100, rebinX, rebinY, fitType, outputFile, resonanceType, 0, "_2");
  TGraphErrors *grM_Gen = fit2DProj(nameGen, nameFile2, 100, rebinX, rebinY, fitType, outputFile, resonanceType, 0, "");

  TCanvas *c = new TCanvas(name+"_Z",name+"_Z");
  c->SetGridx();
  c->SetGridy();
    
  grM_1->SetMarkerColor(1);
  grM_2->SetMarkerColor(2);
  if(genMass)
    grM_Gen->SetMarkerColor(4);
 
  TString xAxisTitle;

  double x[2],y[2];

  if( name.Contains("Eta") ) {
    x[0]=-3; x[1]=3;       //<------useful for reso VS eta
    xAxisTitle = "muon #eta";
  }
  else if( name.Contains("PhiPlus") || name.Contains("PhiMinus") ) {
    x[0] = -3.2; x[1] = 3.2;
    xAxisTitle = "muon #phi(rad)";
  }
  else {
    x[0] = 0.; x[1] = 200;
    xAxisTitle = "muon pt(GeV)";
  }
  if( resonanceType == "JPsi" || resonanceType == "Psi2S" ) { y[0]=0.; y[1]=6.; }
  else if( resonanceType.Contains("Upsilon") ) { y[0]=8.; y[1]=12.; }
  else if( resonanceType == "Z" ) { y[0]=80; y[1]=100; }

  // This is used to have a canvas containing both histogram points
  TGraph *gr = new TGraph(2,x,y);
  gr->SetMarkerStyle(8);
  gr->SetMarkerColor(108);
  gr->GetYaxis()->SetTitle("Res Mass(GeV)   ");
  gr->GetYaxis()->SetTitleOffset(1);
  gr->GetXaxis()->SetTitle(xAxisTitle);
  gr->SetTitle(title);

  // Text for the fits
  TPaveText * paveText1 = new TPaveText(0.20,0.15,0.49,0.28,"NDC");
  paveText1->SetFillColor(0);
  paveText1->SetTextColor(1);
  paveText1->SetTextSize(0.02);
  paveText1->SetBorderSize(1);
  TPaveText * paveText2 = new TPaveText(0.59,0.15,0.88,0.28,"NDC");
  paveText2->SetFillColor(0);
  paveText2->SetTextColor(2);
  paveText2->SetTextSize(0.02);
  paveText2->SetBorderSize(1);

  TPaveText * paveText3 = new TPaveText(0.59,0.32,0.88,0.45,"NDC");
  paveText3->SetFillColor(0);
  paveText3->SetTextColor(4);
  paveText3->SetTextSize(0.02);
  paveText3->SetBorderSize(1);
  
  /*****************PARABOLIC FIT (ETA)********************/
  if( name.Contains("Eta") ) {
    std::cout << "Fitting eta" << std::endl;
    TF1 *fit1 = new TF1("fit1",onlyParabolic,-3.2,3.2,2);
    fit1->SetLineWidth(2);
    fit1->SetLineColor(1);
    if( grM_1->GetN() > 0 ) grM_1->Fit("fit1","", "", -3, 3);
    setTPaveText(fit1, paveText1);

    TF1 *fit2 = new TF1("fit2","pol0",-3.2,3.2);
    // TF1 *fit2 = new TF1("fit2",onlyParabolic,-3.2,3.2,2);
    fit2->SetLineWidth(2);
    fit2->SetLineColor(2);
    if( grM_2->GetN() > 0 ) grM_2->Fit("fit2","", "", -3, 3);
    // grM_2->Fit("fit2","R");
    setTPaveText(fit2, paveText2);
    if(genMass){
      TF1 *fit3 = new TF1("fit3",onlyParabolic,-3.2,3.2,2);
      fit3->SetLineWidth(2);
      fit3->SetLineColor(4);
      if( grM_Gen->GetN() > 0 ) grM_Gen->Fit("fit3","", "", -3, 3);
      // grM_2->Fit("fit2","R");
      setTPaveText(fit3, paveText3);
    }
  }
  /*****************SINUSOIDAL FIT (PHI)********************/
//   if( name.Contains("Phi") ) {
//     std::cout << "Fitting phi" << std::endl;
//     TF1 *fit1 = new TF1("fit1",sinusoidal,-3.2,3.2,3);
//     fit1->SetParameters(9.45,1,1);
//     fit1->SetParNames("offset","amplitude","phase");
//     fit1->SetLineWidth(2);
//     fit1->SetLineColor(1);
//     fit1->SetParLimits(2,-3.14,3.14);
//     if( grM_1->GetN() > 0 ) grM_1->Fit("fit1","","",-3,3);
//     setTPaveText(fit1, paveText1);

//     TF1 *fit2 = new TF1("fit2",sinusoidal,-3.2,3.2,3);
//     fit2->SetParameters(9.45,1,1);
//     fit2->SetParNames("offset","amplitude","phase");
//     fit2->SetLineWidth(2);
//     fit2->SetLineColor(2);
//     fit2->SetParLimits(2,-3.14,3.14);
//     if( grM_2->GetN() > 0 ) grM_2->Fit("fit2","","",-3,3);
//     setTPaveText(fit2, paveText2);

//     if(genMass){
//       TF1 *fit3 = new TF1("fit3",sinusoidal,-3.2,3.2,3);
//       fit3->SetParameters(9.45,1,1);
//       fit3->SetParNames("offset","amplitude","phase");
//       fit3->SetLineWidth(2);
//       fit3->SetLineColor(4);
//       fit3->SetParLimits(2,-3.14,3.14);
//       if( grM_Gen->GetN() > 0 ) grM_Gen->Fit("fit3","","",-3,3);
//       setTPaveText(fit3, paveText3);
//     }
//   }
  /*****************************************/ 
  if( name.Contains("Pt") ) {
    std::cout << "Fitting pt" << std::endl;
    // TF1 * fit1 = new TF1("fit1", linear, 0., 150., 2);
    TF1 * fit1 = new TF1("fit1", "[0]", 0., 150.);
    fit1->SetParameters(0., 1.);
    fit1->SetParNames("scale","pt coefficient");
    fit1->SetLineWidth(2);
    fit1->SetLineColor(1);
    if( grM_1->GetN() > 0 ) {
      if( name.Contains("Z") ) grM_1->Fit("fit1","","",0.,150.);
      else grM_1->Fit("fit1","","",0.,27.);
    }
    setTPaveText(fit1, paveText1);

    // TF1 * fit2 = new TF1("fit2", linear, 0., 150., 2);
    TF1 * fit2 = new TF1("fit2", "[0]", 0., 150.);
    fit2->SetParameters(0., 1.);
    fit2->SetParNames("scale","pt coefficient");
    fit2->SetLineWidth(2);
    fit2->SetLineColor(2);
    if( grM_2->GetN() > 0 ) {
      if( name.Contains("Z") ) grM_2->Fit("fit2","","",0.,150.);
      grM_2->Fit("fit2","","",0.,27.);
    }
    setTPaveText(fit2, paveText2);

    if(genMass){
      TF1 * fit3 = new TF1("fit3", "[0]", 0., 150.);
      fit3->SetParameters(0., 1.);
      fit3->SetParNames("scale","pt coefficient");
      fit3->SetLineWidth(2);
      fit3->SetLineColor(4);
      if( grM_Gen->GetN() > 0 ) {
	if( name.Contains("Z") ) grM_Gen->Fit("fit3","","",0.,150.);
	grM_Gen->Fit("fit3","","",0.,27.);
      }
      setTPaveText(fit3, paveText3);
    }
  }

  c->cd();
  gr->Draw("AP");
  grM_1->Draw("P");
  grM_2->Draw("P");
  if(genMass)
    grM_Gen->Draw("P");

  paveText1->Draw("same");
  paveText2->Draw("same");
  if(genMass)
    paveText3->Draw("same");

  TLegend *leg = new TLegend(0.65,0.85,1,1);
  leg->SetFillColor(0);
  leg->AddEntry(grM_1,"before calibration","P");
  leg->AddEntry(grM_2,"after calibration","P");
  if(genMass)
    leg->AddEntry(grM_Gen, "generated mass", "P");
  leg->Draw("same");

  outputFile->cd();
  c->Write();
  outputFile->Close();
}
Beispiel #14
0
void Opt_mT(){
  
  
  setTDRStyle();
  //gStyle->SetPalette(1);
  
  
  TLegend *legend = new TLegend(.7, 0.7, .9, 0.9);
  legend->SetFillColor(10);
  legend->SetBorderSize(0);
  legend->SetTextSize(0.04);

  
  TFile * fnp = new TFile("/home/jalmond/Analysis/LQanalyzer/data/output/ElectronOpt/HNLowMedHighMassOptimisation_SKnonprompt_dilep_5_3_14.root");
  TFile * fcf = new TFile("/home/jalmond/Analysis/LQanalyzer/data/output/ElectronOpt/HNLowMedHighMassOptimisation_SKchargeflip_dilep_5_3_14.root");
  TFile * fmc = new TFile("/home/jalmond/Analysis/LQanalyzer/data/output/ElectronOpt/HNLowMedHighMassOptimisation_mc_5_3_14.root");
  TFile * fdata = new TFile("/home/jalmond/Analysis/LQanalyzer/data/output/ElectronOpt/HNLowMedHighMassOptimisation_data_5_3_14.root");

  TH1F* h_npcutflow= (TH1F*)fnp->Get(("HighMassOptimise"));
  TH1F* h_cfcutflow= (TH1F*)fcf->Get(("HighMassOptimise"));
  TH1F* h_mccutflow= (TH1F*)fmc->Get(("HighMassOptimise"));
  TH1F* h_datacutflow= (TH1F*)fdata->Get(("HighMassOptimise"));
  
  std::vector<TString> masses;
  masses.push_back("40");
  masses.push_back("50");
  masses.push_back("60");
  masses.push_back("70");
  masses.push_back("80");
  masses.push_back("90");
  masses.push_back("100");
  masses.push_back("125");
  masses.push_back("150");
  masses.push_back("175");
  masses.push_back("200");
  masses.push_back("225");
  masses.push_back("250");
  masses.push_back("275");
  masses.push_back("300");
  masses.push_back("325");
  masses.push_back("350");
  masses.push_back("375");
  masses.push_back("400");
  masses.push_back("500");
  masses.push_back("600");
  masses.push_back("700");

  std::map<TString, TH1*> histmap;
  std::map<TString, int> nsigmap;
  for(unsigned int imass=0; imass < masses.size(); imass++){
    TFile * fsig = new TFile(("/home/jalmond/Analysis/LQanalyzer/data/output/ElectronOpt/HNLowMedHighMassOptimisation_SKHNee" + masses.at(imass) + "_nocut_5_3_14.root").Data());

    TH1* hsig =  (TH1F*)fsig->Get(("HighMassOptimise_sig"));
    histmap[masses.at(imass)] =  hsig;

    TH1* hnsig =   (TH1F*)fsig->Get(("eventcutflow"));
    nsigmap[masses.at(imass)] = hnsig->GetBinContent(1);
    cout << masses.at(imass) << " has nsig = " << hnsig->GetBinContent(1) << endl;
  }
  
  
  int i2=0;
  for(std::map<TString, TH1*>::iterator it = histmap.begin(); it != histmap.end(); it++, i2++){
    TCanvas* c1 = new TCanvas(("Plot"+masses.at(i2)).Data(), "Plot", 800, 600);
    TH1* h_mass_mtopt = (TH1*) h_mccutflow->Clone(("A"+masses.at(i2)).Data());
  

    float nsig=50000.;
    if(it->first.Contains("40")) nsig = 100000;
    if(it->first.Contains("60")) nsig = 100000;
    if(it->first.Contains("80")) nsig = 100000;

    for(int i=1; i <   h_npcutflow->GetNbinsX(); i++){
      float sig_cut = it->second->GetBinContent(i);
      
      float tot_bkg =  h_npcutflow->GetBinContent(i) + h_cfcutflow->GetBinContent(i)  + h_mccutflow->GetBinContent(i);
      
      float sig_eff = sig_cut/nsig;
      float bkgtmp = tot_bkg + (0.28*h_npcutflow->GetBinContent(i))* (0.28*h_npcutflow->GetBinContent(i));
      float denom= 1. + sqrt(bkgtmp);
      
      
      float punzi = 0.;
      if(bkgtmp > 0.) {
	if(denom != 0.) punzi= sig_eff/denom;
      }
      //if(bkgtmp > 25.)  punzi=0.;
      //if(sig_eff < 0.0004) punzi=0.;
      if(h_npcutflow->GetBinContent(i) < 1.)  punzi=0.;
      //cout << i << " " << punzi << endl;
      h_mass_mtopt->SetBinContent(i,punzi);
      
      //if(tot_bkg > 1) cout << "bin = " << i << ": tot_bkg = " << tot_bkg << " and data  = " << h_datacutflow->GetBinContent(i)  << " signal eff = " << 100.* sig_eff<< endl;
      //cout << i << ": h_npcutflow->GetBinContent(i) = " <<  h_npcutflow->GetBinContent(i) << " h_cfcutflow->GetBinContent(i) = " << h_cfcutflow->GetBinContent(i) << " h_mccutflow->GetBinContent(i) = " << h_mccutflow->GetBinContent(i)  << " ...   data = " << h_datacutflow->GetBinContent(i) << endl;
    } 

    h_mass_mtopt->GetYaxis()->SetTitle("Punzi"); 
    h_mass_mtopt->GetXaxis()->SetTitle("cut");
    
    h_mass_mtopt->SetLineWidth(3.);
    
    //h_mass_d0opt->GetYaxis()->SetRangeUser(0.001, 0.005);
    h_mass_mtopt->GetYaxis()->SetTitleSize(0.05);
    h_mass_mtopt->GetYaxis()->SetTitleOffset(1.5);
    h_mass_mtopt->GetYaxis()->SetLabelSize(0.04);
    h_mass_mtopt->Draw("hist");
    
    int binmax=0;
    float max=0.;

    for(unsigned int ibin =1 ; ibin <h_mass_mtopt->GetNbinsX()+1; ibin++){
      
      if(h_mass_mtopt->GetBinContent(ibin) > max) {
	max = h_mass_mtopt->GetBinContent(ibin);
	binmax=ibin;
      }
    }
    cout << "Signal efficiency for max punzi = "<< it->second->GetBinContent(binmax) / nsig << endl;
    cout << "Total fakes = " << h_npcutflow->GetBinContent(binmax)<< endl;
    cout << "Total prompt = " << h_mccutflow->GetBinContent(binmax)<< endl;
    cout << "Total cf = " << h_cfcutflow->GetBinContent(binmax)<< endl;
    cout << "Total bkg = " << h_npcutflow->GetBinContent(binmax) + h_mccutflow->GetBinContent(binmax) + h_cfcutflow->GetBinContent(binmax) << endl;
    cout << "Total data = " <<  h_datacutflow->GetBinContent(binmax)  << endl;
    cout << "punzi = " << h_mass_mtopt->GetBinContent(binmax)  << endl;
    
    std::vector<TString> isocut;
    isocut.push_back("09_09");
    isocut.push_back("09_05");
    std::vector<TString> ptmin;
    ptmin.push_back("25");
    ptmin.push_back("30");
    ptmin.push_back("35");
    ptmin.push_back("40");
    ptmin.push_back("45");
    std::vector<TString> ptmax;
    ptmax.push_back("40");
    ptmax.push_back("50");
    ptmax.push_back("60");
    ptmax.push_back("70");
    ptmax.push_back("80");
    ptmax.push_back("90");
    ptmax.push_back("100");
    std::vector<TString> eemin;
    eemin.push_back("15");
    std::vector<TString> eemax;
    eemax.push_back("1000");
    std::vector<TString> jjmin;
    jjmin.push_back("50");
    jjmin.push_back("60");
    std::vector<TString> jjmax;
    jjmax.push_back("110");
    jjmax.push_back("120");
    std::vector<TString> eejjmin;
    eejjmin.push_back("180");
    eejjmin.push_back("200");
    eejjmin.push_back("225");
    eejjmin.push_back("250");
    eejjmin.push_back("275");
    eejjmin.push_back("300");
    std::vector<TString> eejjmax;
    eejjmax.push_back("300");
    eejjmax.push_back("400");
    eejjmax.push_back("500");
    eejjmax.push_back("600");
    eejjmax.push_back("10000");
    std::vector<TString> e1jjmin;
    e1jjmin.push_back("0.");
    std::vector<TString> e1jjmax;
    e1jjmax.push_back("1000.");
    std::vector<TString> e2jjmin;
    e2jjmin.push_back("0.");
    std::vector<TString> e2jjmax;
    //e2jjmax.push_back("125.");
    //e2jjmax.push_back("150.");
    //e2jjmax.push_back("175.");
    //e2jjmax.push_back("200.");
    e2jjmax.push_back("1000.");
    std::vector<TString> metmax;
    metmax.push_back("35.");
    metmax.push_back("40.");
    metmax.push_back("50.");
    std::vector<TString> mtmax;
    mtmax.push_back("1000.");
    std::vector<TString> stmin;
    stmin.push_back("0.");
    stmin.push_back("150.");
    stmin.push_back("200.");

    std::vector<TString> stmax;
    stmax.push_back("500.");
    stmax.push_back("750.");
    stmax.push_back("1000.");
    stmax.push_back("10000.");

    std::vector<TString> removeZ;
    removeZ.push_back("true");
    removeZ.push_back("false");
    
    std::vector<TString> removedrej;
    //removedrej.push_back("true");
    removedrej.push_back("false");


    int icut=0;
    for(unsigned int iiso = 0; iiso<  isocut.size() ; iiso++){
      for(unsigned int ipt = 0; ipt <  ptmin.size() ; ipt++){
	for(unsigned int ipt2 = 0; ipt2 <  ptmax.size() ; ipt2++){
	  for(unsigned int iee = 0; iee <  eemin.size() ; iee++){
	    for(unsigned int iee2 = 0; iee2 <  eemax.size() ; iee2++){
	      for(unsigned int ijj = 0; ijj <  jjmin.size() ; ijj++){
		for(unsigned int ijj2 = 0; ijj2 <  jjmax.size() ; ijj2++){
		  for(unsigned int ieejj = 0; ieejj <  eejjmin.size() ; ieejj++){
		    for(unsigned int ieejj2 = 0; ieejj2 <  eejjmax.size() ; ieejj2++){
		      for(unsigned int ie1jj = 0; ie1jj <  e1jjmin.size() ; ie1jj++){
			for(unsigned int ie1jj2 = 0; ie1jj2 <  e1jjmax.size() ; ie1jj2++){
			  for(unsigned int ie2jj = 0; ie2jj <  e2jjmin.size() ; ie2jj++){
			    for(unsigned int ie2jj2 = 0; ie2jj2 <  e2jjmax.size() ; ie2jj2++){
			      for(unsigned int imet = 0; imet <  metmax.size() ; imet++){
				for(unsigned int imt = 0; imt <  mtmax.size() ; imt++){
				  for(unsigned int istmin = 0; istmin <  stmin.size() ; istmin++){
				    for(unsigned int istmax = 0; istmax <  stmax.size() ; istmax++){
				      for(unsigned int iZ =0; iZ< removeZ.size(); iZ++){
					for(unsigned int iej =0; iej< removedrej.size(); iej++){
					  
					  TString cut= "iso_ec = " + isocut.at(iiso) + " ptmin = " + ptmin.at(ipt)+ " ptmax = " + ptmax.at(ipt2)+ " eemin= "  +  eemin.at(iee)+ " eemax = " +  eemax.at(iee2)+  " jjmin= " + jjmin.at(ijj)+ "jjmax = " +  jjmax.at(ijj2)+ " eejjmin= " + eejjmin.at(ieejj)+ " eejjmax = " + eejjmax.at(ieejj2)+  "e1jjmin = " + e1jjmin.at(ie1jj)+ " e1jjmax = " + e1jjmax.at(ie1jj2)+ " e2jjmin = " + e2jjmin.at(ie2jj)+ " e2jjmax = " + e2jjmax.at(ie2jj2)+ " metmax = " +  metmax.at(imet)+ " mtmax = " +  mtmax.at(imt)+ " stmin = " + stmin.at(istmin) +  " stmax = " + stmax.at(istmax) + " removeZ peak = " + removeZ.at(iZ) + " remove dRej > 2. = " +  removedrej.at(iej) ;
					  icut++;
					  if(icut == binmax) cout << "Max punzi has cut = " << cut  << endl;
					}
				      }
				    }
				  }
				}
			      }
			    }
			  }
			}
		      }
		    }
		  }
		}
	      }
	    }
	  }
	}
      }
    }    
    
    
    ///legend->AddEntry(h_mass_d0opt,("m_{N}= "+ masses.at(im)).Data(),"l");
    
    it->second->Scale(0.01);
    it->second->SetLineColor(kRed);
    it->second->Draw("histsame");
    
    //legend->Draw("same");
    c1->SaveAs(("/home/jalmond/WebPlots/Opt/HighMassoptimise_" + it->first + ".pdf").Data());

  }
}
Beispiel #15
0
void plotLimit(int signal = 0){
//signal: 0 = ZPN, 1 = ZPW, 2 = ZPXW, 3 = RSG  

setTDRStyle();

//gROOT->SetStyle("Plain");
gStyle->SetOptStat(0000000000); //this clears all the boxes and crap
gStyle->SetLegendBorderSize(1);

TGraph * limit_obs = new TGraph(3);
TGraph * limit_exp = new TGraph(3);
TGraphAsymmErrors * band_exp1 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2 = new TGraphAsymmErrors();

TGraph * limit_obs_2 = new TGraph(3);
TGraph * limit_exp_2 = new TGraph(3);
TGraphAsymmErrors * band_exp1_2 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2_2 = new TGraphAsymmErrors();
TGraph * limit_obs_3 = new TGraph(3);
TGraph * limit_exp_3 = new TGraph(3);
TGraphAsymmErrors * band_exp1_3 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2_3 = new TGraphAsymmErrors();
TGraph * limit_obs_4 = new TGraph(3);
TGraph * limit_exp_4 = new TGraph(3);
TGraphAsymmErrors * band_exp1_4 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2_4 = new TGraphAsymmErrors();
TGraph *theory = new TGraph(3);
TGraph *theory2 = new TGraph(3);
TGraph *theory3 = new TGraph(3);
TGraph *theory4 = new TGraph(3);

   theory->SetPoint(0,  0.01, 4.24671);

   theory->SetPoint(1,  0.1, 42.24246);

   theory->SetPoint(2,  0.3, 122.17487);
   theory2->SetPoint(0,  0.01, 0.17980);
   theory2->SetPoint(1,  0.1, 2.00723);
   theory2->SetPoint(2,  0.3, 6.99950);
   theory3->SetPoint(0, 0.01, 0.01659*0.1);
   theory3->SetPoint(1,  0.1, 0.23030*0.1);
   theory3->SetPoint(2,  0.3, 1.03387*0.1);
   theory4->SetPoint(0, 0.01, 0.00203*0.01);
   theory4->SetPoint(1, 0.1, 0.04254*0.01);
   theory4->SetPoint(2, 0.3, 0.25352*0.01); 

 string filename = "Limits/comb_width_1TeV.txt";
 if (signal == 1) filename= "Limits/comb_width_2TeV.txt";
 if (signal == 2) filename= "Limits/comb_width_3TeV.txt";
 if (signal == 3) filename= "Limits/comb_width_4TeV.txt";

ifstream infile(filename);

double mass, exp, obs, up1, up2, dn1, dn2;
int point = 0;

while (!infile.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 1.0;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs->SetPoint(point, mass, obs*sf);
  limit_exp->SetPoint(point, mass, exp*sf);
  band_exp1->SetPoint(point, mass, exp*sf);
  band_exp2->SetPoint(point, mass, exp*sf);
  
  band_exp1->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}

ifstream infile2 ("Limits/comb_width_2TeV.txt");
point = 0;
while (!infile2.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile2 >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 1.0;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs_2->SetPoint(point, mass, obs*sf);
  limit_exp_2->SetPoint(point, mass, exp*sf);
  band_exp1_2->SetPoint(point, mass, exp*sf);
  band_exp2_2->SetPoint(point, mass, exp*sf);
  
  band_exp1_2->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1_2->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2_2->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2_2->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}

ifstream infile3 ("Limits/comb_width_3TeV.txt");
point = 0;

while (!infile3.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile3 >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 0.1;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs_3->SetPoint(point, mass, obs*sf);
  limit_exp_3->SetPoint(point, mass, exp*sf);
  band_exp1_3->SetPoint(point, mass, exp*sf);
  band_exp2_3->SetPoint(point, mass, exp*sf);

  band_exp1_3->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1_3->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2_3->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2_3->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}

ifstream infile4 ("Limits/comb_width_4TeV.txt");
point = 0;

while (!infile4.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile4 >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 0.01;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs_4->SetPoint(point, mass, obs*sf);
  limit_exp_4->SetPoint(point, mass, exp*sf);
  band_exp1_4->SetPoint(point, mass, exp*sf);
  band_exp2_4->SetPoint(point, mass, exp*sf);
  band_exp1_4->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1_4->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2_4->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2_4->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}





double max = 200000.0; //band_exp2->GetHistogram()->GetMaximum()*50;

  TCanvas *canvas = new TCanvas("limit set ZPN","limit set ZPN", 500,500);

  limit_exp->SetMinimum(0.00001);
  limit_exp->GetXaxis()->SetLabelSize(0.05);
  limit_exp->GetYaxis()->SetLabelSize(0.05);
  limit_exp->Draw("AL");
  if (signal == 0){
    limit_exp->GetXaxis()->SetTitle("#Gamma_{Z'} / M_{Z'}");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]");
  }
  else if (signal == 1){
    limit_exp->GetXaxis()->SetTitle("M_{Z'} [GeV]");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]");
  }
  else if (signal == 2){
    limit_exp->GetXaxis()->SetTitle("M_{Z'} [GeV]");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]");
  }
  else if (signal == 3){
    limit_exp->GetXaxis()->SetTitle("M_{g_{KK}} [GeV]");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{g_{KK}} #times B(g_{KK}#rightarrowt#bar{t}) [pb]");
  }
  //limit_exp->GetYaxis()->SetTitleOffset(1.2);
  limit_exp->GetYaxis()->SetRangeUser(0.00001,2000);


  band_exp2->SetFillColor(5);
  band_exp2->SetLineColor(0);
  //band_exp2->SetFillStyle(4000);
  band_exp2->Draw("3same");

  band_exp1->SetFillColor(3);
  band_exp1->SetLineColor(0);
  //band_exp1->SetFillStyle(4000);
  band_exp1->Draw("3same");

  limit_obs->Draw("Lsame");
  limit_obs->SetLineWidth(2);
  limit_obs->SetMarkerSize(1.0);
  limit_obs->SetMarkerStyle(20);
   
  limit_exp->Draw("Lsame");
  limit_exp->SetLineStyle(2);
  limit_exp->SetLineWidth(2);
  limit_exp->SetMarkerSize(1.0);
  limit_exp->SetMaximum(max);
  limit_exp->SetMinimum(0.000001);
  limit_exp->SetMarkerStyle(20);
  

  band_exp2_2->SetFillColor(5);
  band_exp2_2->SetLineColor(0);
  band_exp1_2->SetFillColor(3);
  band_exp1_2->SetLineColor(0);
  band_exp2_3->SetFillColor(5);
  band_exp2_3->SetLineColor(0);
  band_exp1_3->SetFillColor(3);
  band_exp1_3->SetLineColor(0);
  band_exp2_4->SetFillColor(5);
  band_exp2_4->SetLineColor(0);
  band_exp1_4->SetFillColor(3);
  band_exp1_4->SetLineColor(0);
  band_exp2_2->Draw("3same");
  band_exp1_2->Draw("3same");
  limit_obs_2->Draw("Lsame");
  limit_obs_2->SetLineWidth(2);
  limit_obs_2->SetMarkerSize(1.0);
  limit_obs_2->SetMarkerStyle(20);
  band_exp2_3->Draw("3same");
  band_exp1_3->Draw("3same");
  limit_obs_3->Draw("Lsame");
  limit_obs_3->SetLineWidth(2);
  limit_obs_3->SetMarkerSize(1.0);
  limit_obs_3->SetMarkerStyle(20);
  band_exp2_4->Draw("3same");
  band_exp1_4->Draw("3same");
  limit_obs_4->Draw("Lsame");
  limit_obs_4->SetLineWidth(2);
  limit_obs_4->SetMarkerSize(1.0);
  limit_obs_4->SetMarkerStyle(20);

  limit_exp_2->Draw("L same");
  limit_exp_2->SetLineStyle(2);
  limit_exp_2->SetLineWidth(2);
  limit_exp_2->SetMarkerSize(1.0);
  limit_exp_3->Draw("L same");
  limit_exp_3->SetLineStyle(2);
  limit_exp_3->SetLineWidth(2);
  limit_exp_3->SetMarkerSize(1.0);
  limit_exp_4->Draw("L same");
  limit_exp_4->SetLineStyle(2);
  limit_exp_4->SetLineWidth(2);
  limit_exp_4->SetMarkerSize(1.0);








    canvas->RedrawAxis();

  double x1 = 595; 
  double y1 = 1.0;
  double x2 = 905;
  double y2 = 1.0;
  TLine * line = new TLine(x1, y1, x2, y2);
  theory->SetLineColor(2);
  theory->SetLineWidth(2);
  theory->Draw("same");
	theory2->SetLineColor(kBlue);
	theory2->SetLineWidth(2);
	theory2->Draw("same");
	theory3->SetLineColor(kMagenta);
	theory3->SetLineWidth(2);
	theory3->Draw("same");
	theory4->SetLineColor(kCyan);
	theory4->SetLineWidth(2);
	theory4->Draw("same");

  CMS_lumi(canvas, 4, 10);

  float t = canvas->GetTopMargin();
  float r = canvas->GetRightMargin();

  //Legend
  TLegend *l = new TLegend(0.51,0.63,0.99-r,0.99-t);
  l->AddEntry(limit_obs,"Observed", "L");
  l->AddEntry(limit_exp,"Expected", "L");
  l->AddEntry(band_exp1,"#pm1 #sigma Exp.", "F");
  l->AddEntry(band_exp2,"#pm2 #sigma Exp.", "F");
    l->AddEntry(theory, "Z' 1 TeV (NLO)", "L");
    l->AddEntry(theory2, "Z' 2 TeV (NLO)", "L");
    l->AddEntry(theory3, "Z' 3 TeV (NLO x 0.1)", "L");
    l->AddEntry(theory4, "Z' 4 TeV (NLO x 0.01)", "L");
  l->SetFillColor(0);
  l->SetLineColor(0);
  l->SetTextSize(0.04);
  l->SetTextFont(42);
  l->Draw();

  //TLatex * label = new TLatex();
  //label->SetNDC();
  //label->DrawLatex(0.2,0.86,"CMS Preliminary, 19.7 fb^{-1}");
  //label->DrawLatex(0.2,0.80,"#sqrt{s} = 8 TeV");
  //label->DrawLatex(0.6,0.80, Form("BR(b'#rightarrow %s) = 1", channel.Data()));
  //label->DrawLatex(0.55,0.80, "BR(b'#rightarrow tW) = 0.5");
  //label->DrawLatex(0.55,0.74, "BR(b'#rightarrow bH) = 0.25");
  //label->DrawLatex(0.55,0.68, "BR(b'#rightarrow bZ) = 0.25");
  //label->DrawLatex(0.2,0.74, lepton.Data());

  canvas->SetLogy(1);
  canvas->SetLogx(1);
  canvas->SetTickx(1);
  canvas->SetTicky(1);


  if (signal == 0){
    canvas->Print("Limits/comb_ZPN_limit.pdf");
    canvas->Print("Limits/comb_ZPN_limit.root");
  }
  else if (signal == 1){
    canvas->Print("Limits/comb_ZPW_limit.pdf");
    canvas->Print("Limits/comb_ZPW_limit.root");
  }
  else if (signal == 2){
    canvas->Print("Limits/comb_ZPXW_limit.pdf");
    canvas->Print("Limits/comb_ZPXW_limit.root");
  }
  else if (signal == 3){
    canvas->Print("Limits/comb_RSG_limit.pdf");
    canvas->Print("Limits/comb_RSG_limit.root");
  }
}
Beispiel #16
0
void drawCtauFrom2DPlot(RooWorkspace& myws,   // Local workspace
                        string outputDir,     // Output directory
                        struct InputOpt opt,  // Variable with run information (kept for legacy purpose)
                        struct KinCuts cut,   // Variable with current kinematic cuts
                        map<string, string>  parIni,   // Variable containing all initial parameters
                        string plotLabel,     // The label used to define the output file name
                        // Select the type of datasets to fit
                        string DSTAG,         // Specifies the type of datasets: i.e, DATA, MCJPSINP, ...
                        bool isPbPb,          // Define if it is PbPb (True) or PP (False)
                        // Select the type of object to fit
                        bool incJpsi,         // Includes Jpsi model
                        bool incPsi2S,        // Includes Psi(2S) model
                        bool incBkg,          // Includes Background model     
                        // Select the fitting options
                        // Select the drawing options
                        bool setLogScale,     // Draw plot with log scale
                        bool incSS,           // Include Same Sign data
                        double binWidth       // Bin width
                        ) 
{

  RooMsgService::instance().getStream(0).removeTopic(Caching);  
  RooMsgService::instance().getStream(1).removeTopic(Caching);
  RooMsgService::instance().getStream(0).removeTopic(Plotting);
  RooMsgService::instance().getStream(1).removeTopic(Plotting);
  RooMsgService::instance().getStream(0).removeTopic(Integration);
  RooMsgService::instance().getStream(1).removeTopic(Integration);
  RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING) ;

  if (DSTAG.find("_")!=std::string::npos) DSTAG.erase(DSTAG.find("_"));

  string pdfTotName  = Form("pdfCTAUMASS_Tot_%s", (isPbPb?"PbPb":"PP"));
  string dsOSName = Form("dOS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP"));
  string dsOSNameCut = dsOSName+"_CTAUCUT";
  string hOSName = Form("dhCTAUERRTot_Tot_%s", (isPbPb?"PbPb":"PP"));
  string hOSNameBkg  = Form("dhCTAUERR_Bkg_%s", (isPbPb?"PbPb":"PP"));
  string hOSNameJpsi = Form("dhCTAUERR_Jpsi_%s", (isPbPb?"PbPb":"PP"));
  string hOSNamePsi2S = Form("dhCTAUERR_Psi2S_%s", (isPbPb?"PbPb":"PP"));
  string dsSSName = Form("dSS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP"));

  bool isWeighted = myws.data(dsOSName.c_str())->isWeighted();
  vector<double> range; range.push_back(cut.dMuon.ctau.Min); range.push_back(cut.dMuon.ctau.Max);

  double minRange = -4.0;
  double maxRange = 7.0;
  Double_t outTot = myws.data(dsOSName.c_str())->numEntries();
  Double_t outErr = myws.data(dsOSName.c_str())->reduce(Form("(ctau>%.6f || ctau<%.6f)", range[1], range[0]))->numEntries();
  int nBins = min(int( round((maxRange - minRange)/binWidth) ), 1000);

  double normDSTot   = 1.0;  if (myws.data(dsOSNameCut.c_str()))  { normDSTot   = myws.data(dsOSName.c_str())->sumEntries()/myws.data(dsOSNameCut.c_str())->sumEntries();  }
  double normJpsi  = 1.0;  if (myws.data(hOSNameJpsi.c_str()))  { normJpsi  = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSNameJpsi.c_str())->sumEntries();  }
  double normPsi2S = 1.0;  if (myws.data(hOSNamePsi2S.c_str())) { normPsi2S = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSNamePsi2S.c_str())->sumEntries(); }
  double normBkg   = 1.0;  if (myws.data(hOSNameBkg.c_str()))   { normBkg   = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSNameBkg.c_str())->sumEntries();   }
  double normTot   = 1.0;  if (myws.data(hOSName.c_str()))  { normTot   = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSName.c_str())->sumEntries();  }

  // Create the main plot of the fit
  RooPlot*   frame     = myws.var("ctau")->frame(Bins(nBins), Range(minRange, maxRange));
  frame->updateNormVars(RooArgSet(*myws.var("invMass"), *myws.var("ctau"), *myws.var("ctauErr"))) ;
  myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2));
  
  myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PDF"),
                                       ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSNameCut.c_str()), kTRUE),
                                       Normalization(normDSTot, RooAbsReal::NumEvent),
                                       FillStyle(1001), FillColor(kViolet+6), VLines(), DrawOption("LF"), NumCPU(32), LineColor(kBlack)
                                       );
  myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("BKG"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_Bkg_%s", (isPbPb?"PbPb":"PP"))) )),
                                       ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                       Normalization(normDSTot, RooAbsReal::NumEvent),
                                       FillStyle(1001), FillColor(kAzure-9), VLines(), DrawOption("LF"), NumCPU(32)
                                       );
  if (incJpsi) {
    myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSIPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_JpsiPR_%s", (isPbPb?"PbPb":"PP"))) )),
                                         ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                         Normalization(normDSTot, RooAbsReal::NumEvent),
                                         LineColor(kRed+3), Precision(1e-5), NumCPU(32)
                                         );
    myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSINOPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_JpsiNoPR_%s", (isPbPb?"PbPb":"PP"))) )),
                                         ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                         Normalization(normDSTot, RooAbsReal::NumEvent),
                                         LineColor(kGreen+3), Precision(1e-5), NumCPU(32)
                                         );
  }
  if (incPsi2S) {
    myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_Psi2SPR_%s", (isPbPb?"PbPb":"PP"))) )),
                                         ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                         Normalization(normDSTot, RooAbsReal::NumEvent),
                                         LineColor(kRed+3), Precision(1e-5), NumCPU(32)
                                         );
    myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SNOPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_Psi2SNo_%s", (isPbPb?"PbPb":"PP"))) )),
                                         ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                         Normalization(normDSTot, RooAbsReal::NumEvent),
                                         LineColor(kGreen+3), Precision(1e-5), NumCPU(32)
                                         );
  }  
  if (incSS) { 
    myws.data(dsSSName.c_str())->plotOn(frame, Name("dSS"), MarkerColor(kRed), LineColor(kRed), MarkerSize(1.2)); 
  }
  myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2));
  myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PDFLINE"),
                                       ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSNameCut.c_str()), kTRUE),
                                       Normalization(normDSTot, RooAbsReal::NumEvent), 
                                       LineColor(kBlack), NumCPU(32)
                                       );
  
  
  // set the CMS style
  setTDRStyle();

  // Create the pull distribution of the fit 
  RooHist *hpull = frame->pullHist(0, "PDF", true);
  hpull->SetName("hpull");
  RooPlot* frame2 = myws.var("ctau")->frame(Title("Pull Distribution"), Bins(nBins), Range(minRange, maxRange));
  frame2->addPlotable(hpull, "PX"); 
  
  // Create the main canvas
  TCanvas *cFig  = new TCanvas(Form("cCtauFig_%s", (isPbPb?"PbPb":"PP")), "cCtauFig",800,800);
  TPad    *pad1  = new TPad(Form("pad1_%s", (isPbPb?"PbPb":"PP")),"",0,0.23,1,1);
  TPad    *pad2  = new TPad(Form("pad2_%s", (isPbPb?"PbPb":"PP")),"",0,0,1,.228);
  TLine   *pline = new TLine(minRange, 0.0, maxRange, 0.0);
  
  TPad *pad4 = new TPad("pad4","This is pad4",0.55,0.46,0.97,0.87);
  pad4->SetFillStyle(0);
  pad4->SetLeftMargin(0.28);
  pad4->SetRightMargin(0.10);
  pad4->SetBottomMargin(0.21);
  pad4->SetTopMargin(0.072);

  frame->SetTitle("");
  frame->GetXaxis()->SetTitle("");
  frame->GetXaxis()->CenterTitle(kTRUE);
  frame->GetXaxis()->SetTitleSize(0.045);
  frame->GetXaxis()->SetTitleFont(42);
  frame->GetXaxis()->SetTitleOffset(3);
  frame->GetXaxis()->SetLabelOffset(3);
  frame->GetYaxis()->SetLabelSize(0.04);
  frame->GetYaxis()->SetTitleSize(0.04);
  frame->GetYaxis()->SetTitleOffset(1.7);
  frame->GetYaxis()->SetTitleFont(42);
  setCtauFrom2DRange(myws, frame, dsOSNameCut, setLogScale, range, outErr);
 
  cFig->cd();
  pad2->SetTopMargin(0.02);
  pad2->SetBottomMargin(0.4);
  pad2->SetFillStyle(4000); 
  pad2->SetFrameFillStyle(4000); 
  pad1->SetBottomMargin(0.015); 
  //plot fit
  pad1->Draw();
  pad1->cd(); 
  frame->Draw();

  printCtauFrom2DParameters(myws, pad1, isPbPb, pdfTotName, isWeighted);
  pad1->SetLogy(setLogScale);

  // Drawing the text in the plot
  TLatex *t = new TLatex(); t->SetNDC(); t->SetTextSize(0.032);
  float dy = 0; 
  
  t->SetTextSize(0.03);
  t->DrawLatex(0.21, 0.86-dy, "2015 HI Soft Muon ID"); dy+=0.045;
  if (isPbPb) {
    t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045;
  } else {
    t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045;
  } 
  t->DrawLatex(0.21, 0.86-dy, Form("%.1f #leq p_{T}^{#mu#mu} < %.1f GeV/c",cut.dMuon.Pt.Min,cut.dMuon.Pt.Max)); dy+=0.045;
  t->DrawLatex(0.21, 0.86-dy, Form("%.1f #leq |y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Min,cut.dMuon.AbsRap.Max)); dy+=0.045;
  if (isPbPb) {t->DrawLatex(0.21, 0.86-dy, Form("Cent. %d-%d%%", (int)(cut.Centrality.Start/2), (int)(cut.Centrality.End/2))); dy+=0.045;}
  if (outErr>0.0) {
    t->DrawLatex(0.21, 0.86-dy, Form("Excl: (%.4f%%) %.0f evts", (outErr*100.0/outTot), outErr)); dy+=1.5*0.045;
  }

  // Drawing the Legend
  double ymin = 0.7602;
  if (incPsi2S && incJpsi && incSS)  { ymin = 0.7202; } 
  if (incPsi2S && incJpsi && !incSS) { ymin = 0.7452; }
  TLegend* leg = new TLegend(0.5175, ymin, 0.7180, 0.8809); leg->SetTextSize(0.03);
  leg->AddEntry(frame->findObject("dOS"), (incSS?"Opposite Charge":"Data"),"pe");
  if (incSS) { leg->AddEntry(frame->findObject("dSS"),"Same Charge","pe"); }
  if(frame->findObject("PDF")) { leg->AddEntry(frame->findObject("PDF"),"Total fit","fl"); }
  if((incBkg && (incJpsi || incPsi2S)) && frame->findObject("BKG")) { leg->AddEntry(frame->findObject("BKG"),"Background","fl");  }
  if(incBkg && incJpsi && frame->findObject("JPSIPR")) { leg->AddEntry(frame->findObject("JPSIPR"),"J/#psi Prompt","l"); }
  if(incBkg && incJpsi && frame->findObject("JPSINOPR")) { leg->AddEntry(frame->findObject("JPSINOPR"),"J/#psi Non-Prompt","l"); }
  if(incBkg && incPsi2S && frame->findObject("PSI2SPR")) { leg->AddEntry(frame->findObject("PSI2SPR"),"#psi(2S) Prompt","l"); }
  if(incBkg && incPsi2S && frame->findObject("PSI2SNOPR")) { leg->AddEntry(frame->findObject("PSI2SNOPR"),"#psi(2S) Non-Prompt","l"); }
  leg->Draw("same");

  //Drawing the title
  TString label;
  if (isPbPb) {
    if (opt.PbPb.RunNb.Start==opt.PbPb.RunNb.End){
      label = Form("PbPb Run %d", opt.PbPb.RunNb.Start);
    } else {
      label = Form("%s [%s %d-%d]", "PbPb", "HIOniaL1DoubleMu0", opt.PbPb.RunNb.Start, opt.PbPb.RunNb.End);
    }
  } else {
    if (opt.pp.RunNb.Start==opt.pp.RunNb.End){
      label = Form("PP Run %d", opt.pp.RunNb.Start);
    } else {
      label = Form("%s [%s %d-%d]", "PP", "DoubleMu0", opt.pp.RunNb.Start, opt.pp.RunNb.End);
    }
  }
  
  //CMS_lumi(pad1, isPbPb ? 105 : 104, 33, label);
  CMS_lumi(pad1, isPbPb ? 108 : 107, 33, "");
  gStyle->SetTitleFontSize(0.05);
  
  pad1->Update();
  cFig->cd(); 

  //---plot pull
  pad2->Draw();
  pad2->cd();
    
  frame2->SetTitle("");
  frame2->GetYaxis()->CenterTitle(kTRUE);
  frame2->GetYaxis()->SetTitleOffset(0.4);
  frame2->GetYaxis()->SetTitleSize(0.1);
  frame2->GetYaxis()->SetLabelSize(0.1);
  frame2->GetYaxis()->SetTitle("Pull");
  frame2->GetXaxis()->CenterTitle(kTRUE);
  frame2->GetXaxis()->SetTitleOffset(1);
  frame2->GetXaxis()->SetTitleSize(0.12);
  frame2->GetXaxis()->SetLabelSize(0.1);
  frame2->GetXaxis()->SetTitle("#font[12]{l}_{J/#psi} (mm)");
  frame2->GetYaxis()->SetRangeUser(-7.0, 7.0);

  frame2->Draw(); 
  
  // *** Print chi2/ndof 
  printChi2(myws, pad2, frame, "ctau", dsOSName.c_str(), pdfTotName.c_str(), nBins, false);
  
  pline->Draw("same");
  pad2->Update();
  
  // Save the plot in different formats
  gSystem->mkdir(Form("%sctauMass/%s/plot/root/", outputDir.c_str(), DSTAG.c_str()), kTRUE); 
  cFig->SaveAs(Form("%sctauMass/%s/plot/root/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), "CTAU", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End));
  gSystem->mkdir(Form("%sctauMass/%s/plot/png/", outputDir.c_str(), DSTAG.c_str()), kTRUE);
  cFig->SaveAs(Form("%sctauMass/%s/plot/png/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.png", outputDir.c_str(), DSTAG.c_str(), "CTAU", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End));
  gSystem->mkdir(Form("%sctauMass/%s/plot/pdf/", outputDir.c_str(), DSTAG.c_str()), kTRUE);
  cFig->SaveAs(Form("%sctauMass/%s/plot/pdf/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.pdf", outputDir.c_str(), DSTAG.c_str(), "CTAU", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End));
  

  cFig->Clear();
  cFig->Close();

}
Beispiel #17
0
void Draw()
{
    
  setTDRStyle(0,1,0);

  // Type 1 MET. Signal area
  TCanvas* c1 = new TCanvas("X","Y",1);

  TLegend *leg = new TLegend(0.20,0.80,0.50,0.90,NULL,"brNDC");

  // data in signal region
  TFile* file = new TFile("VBFHinvisQCDAnalysisMy_Type1MET.root");

  TH1F * hPfMetDphiJJSDataClone = (TH1F*)hPfMetDphiJJSData->Clone();
  hPfMetDphiJJSDataClone->Sumw2();

  TH1F *hrD = (TH1F*)hPfMetDphiJJSData->Clone();
  TH1F *hD_EW_S = (TH1F*)hPfMetDphiJJSData->Clone();
  TH1F *hD_EW_B = (TH1F*)hPfMetDphiJJSData->Clone();
  TH1F *hrD_EW = (TH1F*)hPfMetDphiJJSData->Clone();


  hPfMetDphiJJSData->GetXaxis()->SetTitle("E_{T}^{miss}, GeV");
  hPfMetDphiJJSData->GetYaxis()->SetTitle("Nev");
  hPfMetDphiJJSData->SetMinimum(1.);
  hPfMetDphiJJSData->SetMaximum(10000.);
  hPfMetDphiJJSData->SetMarkerStyle(20);
  hPfMetDphiJJSData->Draw("E1P");
  leg->SetFillColor(10);
  leg->AddEntry(hPfMetDphiJJSData,"Data","PL");

  // EW MC in signal region
  TFile* file = new TFile("AnneMarieEWK_METType1_My.root");

  TH1F *metRangeTotal_DPhiSIGNALClone = (TH1F*)metRangeTotal_DPhiSIGNAL->Clone();
  metRangeTotal_DPhiSIGNALClone->Sumw2();

  metRangeTotal_DPhiSIGNAL->SetLineWidth(2);
  metRangeTotal_DPhiSIGNAL->SetLineStyle(1);
  metRangeTotal_DPhiSIGNAL->Draw("SAMEE1");
  leg->AddEntry(metRangeTotal_DPhiSIGNAL,"EW MC","PL");
  leg->Draw();

  TLatex *t = new TLatex();
  t->SetTextSize(0.042);
  t->DrawLatex(80.,10.,"#Delta#phi_{jj} < 1.0");
  t->DrawLatex(80.,4.,"Type 1 MET");
  t->DrawLatex(60.,2.,"tag.jets with no #mu's");

  c1->SaveAs("met_type1_s_my.gif");

  // Type 1 MET. Bkg area
  TCanvas* c2 = new TCanvas("X","Y",1);

  TLegend *leg = new TLegend(0.60,0.40,0.90,0.50,NULL,"brNDC");

  // data in Bkg region
  TFile* file = new TFile("VBFHinvisQCDAnalysisMy_Type1MET.root");

  TH1F * hPfMetDphiJJBDataClone = (TH1F*)hPfMetDphiJJBData->Clone();
  hPfMetDphiJJBDataClone->Sumw2();

  hPfMetDphiJJBData->GetXaxis()->SetTitle("E_{T}^{miss}, GeV");
  hPfMetDphiJJBData->GetYaxis()->SetTitle("Nev");
  hPfMetDphiJJBData->SetMinimum(1.);
  //  hPfMetDphiJJBData->SetMaximum(100000.);
  hPfMetDphiJJBData->SetMarkerStyle(20);
  hPfMetDphiJJBData->Draw("E1P");
  leg->SetFillColor(10);
  leg->AddEntry(hPfMetDphiJJBData,"Data","PL");

  // EW MC in signal region
  TFile* file = new TFile("AnneMarieEWK_METType1_My.root");

  TH1F *metRangeTotal_DPhiQCDClone = (TH1F*)metRangeTotal_DPhiQCD->Clone();
  metRangeTotal_DPhiQCDClone->Sumw2();

  metRangeTotal_DPhiQCD->SetLineWidth(2);
  metRangeTotal_DPhiQCD->SetLineStyle(1);
  metRangeTotal_DPhiQCD->Draw("SAMEE1");
  leg->AddEntry(metRangeTotal_DPhiQCD,"EW MC","PL");
  leg->Draw();

  TLatex *t = new TLatex();
  t->SetTextSize(0.042);
  t->DrawLatex(80.,10.,"#Delta#phi_{jj} > 2.6");
  t->DrawLatex(80.,4.,"Type 1 MET");
  t->DrawLatex(60.,2.,"tag.jets with no #mu's");

  c2->SaveAs("met_type1_b_my.gif");

  setTDRStyle(0,0,0);

  TCanvas* c3 = new TCanvas("X","Y",1);

  TLegend *leg = new TLegend(0.20,0.80,0.80,0.90,NULL,"brNDC");

  hrD->GetXaxis()->SetTitle("E_{T}^{miss}, GeV");
  hrD->GetYaxis()->SetTitle("multijet extrapolation factor r");
  hrD->Divide(hPfMetDphiJJSDataClone,hPfMetDphiJJBDataClone,1.,1.,"");
  hrD->SetMinimum(0.);
  hrD->SetMaximum(0.07);
  hrD->SetMarkerStyle(24);
  hrD->SetAxisRange(20.,120.,"X");
  hrD->SetTitleOffset(1.5, "Y");
  hrD->Draw("EP");

  hD_EW_S->Add(hPfMetDphiJJSDataClone,metRangeTotal_DPhiSIGNALClone,1.,-1.); 
  hD_EW_B->Add(hPfMetDphiJJBDataClone,metRangeTotal_DPhiQCDClone,1.,-1.);
  hrD_EW->Divide(hD_EW_S,hD_EW_B,1.,1.,"");
  hrD_EW->SetMarkerStyle(20);
  hrD_EW->Draw("SAMEEP");

  leg->AddEntry(hrD,"Data with no EW subtraction","PL");
  leg->AddEntry(hrD_EW,"Data with MC EW subtraction","PL");
  leg->Draw();

  TLatex *t = new TLatex();
  t->SetTextSize(0.042);
  t->DrawLatex(80.,0.015,"Type 1 MET");
  t->DrawLatex(60.,0.010,"tag.jets with no #mu's");


  c3->SaveAs("rD_type1_my.gif");

}
Beispiel #18
0
void forPaperZEE(
      		 std::string datavar="h_ystar",
		 float xmin=-9999.0, float xmax=-9999.0,
		 bool logScale=false,
		 std::string datafile="darko_root/corrected_electron.root",
		 std::string mcfile1="darko_root/bare_exclusive1Jet_zPt40_electron_dressed_DYToLL_M-50_1jEnh2_2jEnh35_3jEnh40_4jEnh50_7TeV-sherpa.root", 
		 std::string mcfile2="darko_root/bare_exclusive1Jet_zPt40_electron_dressed_DYJetsToLL_TuneZ2_M-50_7TeV-madgraph-tauola.root", 
		 std::string mcfile3="unified_angular_distributions/rebinnings/zpt40/Z_1jet_tota_cteq66_1___1___ex_m34.root",
		 std::string var1="", std::string var2="", 
		 std::string headertitle="Z(#rightarrow ee)+1 jet",
		 std::string dataName="Data",
		 std::string mcName1="Sherpa",
		 std::string mcName2="Madgraph",
		 std::string mcName3="MCFM"
		 )
{
  
  setTDRStyle();
  gStyle->SetOptStat(0);

  const int NHISTOS=4;
  TH1F* h[NHISTOS];

  char tempName[300];
  if(var1 ==  "" )var1=datavar;
  if(var2 ==  "" )var2=datavar;

  std::string xtitle;
  std::string output;
  std::string var3;

  if(datavar=="h_ystar")
    {
      var3  = "id4";
      xtitle = "0.5|Y_{Z}-Y_{jet}|";
      output = "DifYEle";
    }
  else if(datavar=="h_yB")
    {
      var3 = "id3";
      xtitle = "0.5|Y_{Z}+Y_{jet}|";
      output = "SumYEle";
    }
  else if(datavar=="h_jety")
    {
      var3 = "id1";
      xtitle = "|Y_{jet}|";
      output = "YJetEle";
    }
  else if(datavar=="h_zy")
    {
      var3 = "id2";
      xtitle = "|Y_{Z}|";
      output = "YZedEle";
    }

  
  // first get the histogram files
  TFile *fdata  = TFile::Open(datafile.data());
  TFile *fmc1   = TFile::Open(mcfile1.data());
  TFile *fmc2   = TFile::Open(mcfile2.data());
  TFile *fmc3   = TFile::Open(mcfile3.data());

  cout << "Opening " << fdata->GetName() << endl;
  cout << "Opening " << fmc1->GetName() << endl;
  cout << "Opening " << fmc2->GetName() << endl;
  cout << "Opening " << fmc3->GetName() << endl;

  h[0] = (TH1F*)(fdata->Get(datavar.data()));
  h[1]    = (TH1F*)(fmc1->Get(var1.data()));
  h[2]    = (TH1F*)(fmc2->Get(var2.data()));
  h[3]    = (TH1F*)(fmc3->Get(var3.data()));

  TH1D* hscale[NHISTOS];

  int COLOR[NHISTOS]={1,4,2,kOrange-1};
  int MARKERSTYLE[NHISTOS]={8,24,21,29};

  for(int i=0; i < NHISTOS; i++){

    hscale[i]   =(TH1D*) h[0]->Clone(Form("hscale%02i",i));
    hscale[i]   ->SetYTitle(Form("Ratio to %s",mcName3.data()));
    hscale[i]   ->SetXTitle(xtitle.data());
//     hscale[i]   ->GetXaxis()->SetNdivisions(5);
    hscale[i]   ->GetXaxis()->SetDecimals();
    hscale[i]   ->GetYaxis()->SetDecimals();

    hscale[i]->SetLineColor(COLOR[i]);
    hscale[i]->SetMarkerColor(COLOR[i]);
    hscale[i]->SetMarkerStyle(MARKERSTYLE[i]);

    hscale[i]->SetTitle("");
    hscale[i]->SetMaximum(1.65);
    hscale[i]->SetMinimum(0.5);
    hscale[i]->SetTitleOffset(1.2,"X");
    hscale[i]->SetTitleOffset(1.2,"Y");

    h[i]->SetTitle("");
//     h[i]->GetXaxis()->SetNdivisions(5);
    h[i]->GetXaxis()->SetDecimals();
    h[i]->GetYaxis()->SetDecimals();

    h[i]->SetLineColor(COLOR[i]);
    h[i]->SetMarkerColor(COLOR[i]);
    h[i]->SetMarkerSize(1);
    h[i]->SetMarkerStyle(MARKERSTYLE[i]);
    h[i]->SetTitleOffset(1.2,"Y");

  }

  // if normalizing to the same area, set the scale 

  int binLo = -1;
  int binHi = -1;
  int nbins = h[0]->GetNbinsX();
  if(xmin>-9999.0 && xmax>-9999.0)
    {

      binLo = h[0]->FindBin(xmin);
      binHi = h[0]->FindBin(xmax)-1;

    }

  else
    {
      binLo = 1;
      binHi = nbins;
      xmin = h[0]->GetBinLowEdge(1);
      xmax = h[0]->GetBinLowEdge(nbins+1);
    }


  float scaleFactor[NHISTOS]={1};

  for(int ih=0; ih < NHISTOS; ih++){
    
    float integral = h[ih]->Integral(binLo,binHi);
//     scaleFactor[ih] = integral > 0? (float)h[0]->Integral(binLo,binHi)/integral: 1;
    scaleFactor[ih] = integral > 0? 1.0/integral: 1;
    h[ih]->Sumw2();
    h[ih]->Scale(scaleFactor[ih]);

  }

  for(int ih=0; ih < NHISTOS; ih++)
    cout << "histogram " << ih << " integral = " << h[ih]->Integral() << endl;


  // get the ratio

  for(int ih=0; ih < NHISTOS-1; ih++){
    cout << "===================================================" << endl;
    cout << "For histogram " << ih << endl;
    hscale[ih]->Divide(h[ih], h[NHISTOS-1]);
    hscale[ih]->SetMaximum(1.65);
    hscale[ih]->SetMinimum(0.5);

//     for(int ib=1;ib<= nbins;ib++){

//       double nref    =h[NHISTOS-1]->GetBinContent(ib);
//       double nreferr =h[NHISTOS-1]->GetBinError(ib);

//       double ncomp   =h[ih]->GetBinContent(ib); 
//       double ncomperr=h[ih]->GetBinError(ib); 

//       double ratio = -9999;
//       double err   = 1e-4;

//       hscale[ih]->SetBinContent(ib,ratio);
//       hscale[ih]->SetBinError(ib,err);
    
//       if(ncomp<=0 || nref<=0)continue;    
    
//       if(ncomperr<=0 || nreferr<=0)
// 	continue;
      
//       // now calculate the ratio 1
//       ratio = ncomp/nref;
//       err =
// 	(ratio)*sqrt(pow(nreferr/nref,2)+pow(ncomperr/ncomp,2));

//       hscale[ih]->SetBinContent(ib,ratio);
//       hscale[ih]->SetBinError(ib,err);

//       cout << "Bin " << ib << " ratio = " << ratio << " +- " << err << endl;

//       cout << "===================================================" << endl;
//     } // end of loop over bins
  } // end of loop over histograms

  vector<float> maxArray;
  maxArray.clear();

  for(int ih=0; ih < NHISTOS; ih++){

    h[ih]->GetXaxis()->SetRangeUser(xmin,xmax);
    hscale[ih]->GetXaxis()->SetRangeUser(xmin,xmax);
    float max_this  = h[ih]->GetBinError(h[ih]->GetMaximumBin()) + h[ih]->GetMaximum();
    maxArray.push_back(max_this);

  }


  float max = *max_element(maxArray.begin(),maxArray.end());
  cout << "Max = " << max << endl;

  for(int ih=0; ih < NHISTOS; ih++){

    h[ih]->SetMaximum(1.1*max);
    if(!logScale)
      h[ih]->SetMinimum(-0.015);
    else
      h[ih]->SetMinimum(5e-6);
  }

  cout << "here" << endl;
  TCanvas* c1 = new TCanvas("c1","",700,1000);  
  c1->Divide(1,2,0.01,0);
  c1->cd(1);
  if(logScale)
    gPad->SetLogy(1);
  gPad->SetTopMargin(0.01);
  gPad->SetBottomMargin(0);
  gPad->SetRightMargin(0.04);

  
  cout << "here1" << endl;
  h[0]->SetYTitle("Arbitrary Unit");
  h[0]->Draw("e");
  for(int ih=0; ih < NHISTOS-1; ih++)
    h[ih]->Draw("esame");

  cout << "here2" << endl;

  h[NHISTOS-1]->Draw("hesame");

  cout << "here3" << endl;

  float x1NDC = 0.711567;
  float y1NDC = 0.653719;
  float x2NDC = 0.930511;
  float y2NDC = 0.965385;

  TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC);
  
  leg->SetFillColor(0);
  leg->SetFillStyle(0);
  leg->SetTextSize(0.05);
  leg->SetBorderSize(0);
  leg->SetHeader(headertitle.data());
  leg->AddEntry(h[0], dataName.data());
  leg->AddEntry(h[1], mcName1.data());
  leg->AddEntry(h[2], mcName2.data());
  leg->AddEntry(h[3], mcName3.data());
  leg->Draw("same");

  TLatex *lar = new TLatex(0.30, 0.91, "CMS   #sqrt{s} = 7 TeV, L_{int} = 4.9 fb^{-1}");
  lar->SetNDC(kTRUE);
  lar->SetTextSize(0.045);
  lar->Draw();

  c1->cd(2);
  gStyle->SetStatW       (0.3);
  gStyle->SetStatH       (0.3);
  gStyle->SetStatX       (0.879447);
  gStyle->SetStatY       (0.939033);
  gStyle->SetStatFontSize(0.05);
  gStyle->SetStatBorderSize(0);
  gPad->SetRightMargin(0.04);
  gPad->SetTopMargin(0);
  gPad->SetBottomMargin(0.2);
  gPad->SetTickx();
  gStyle->SetOptFit(1);

  cout << "here4" << endl;

  hscale[0]->Draw("e1");
  for(int ih=0; ih < NHISTOS-1; ih++){
    hscale[ih]->Draw("e1same");
  }

  cout << "here5" << endl;
  TLine* l2 = new TLine(xmin,1.,xmax,1.);
  l2->SetLineColor(kOrange-1);
  l2->SetLineStyle(1);
  l2->Draw("same");


  string dirName = "forPaper";
  gSystem->mkdir(dirName.data());

  std::string filename;
  std::string psname = dirName+ "/" + output;
  filename = psname + ".eps";
  c1->Print(filename.data());
  filename = psname + ".gif";
  c1->Print(filename.data());
  filename = psname + ".pdf";
  c1->Print(filename.data());
  //   c1->Close();
}
void v2ExpClose_pt(bool bSavePlots     = true,
                   float rangeYAxis    = 0.6,
                   float rangeXAxis    = 30,
                   bool  bDrawCh       = true,
                   const char* inputDir      = "../macro_v2/outRoot", // the place where the input root files, with the histograms are
                   const char* figNamePrefix="v2ExpClose_pt")
{
    gSystem->mkdir(Form("./figs/png"), kTRUE);
    gSystem->mkdir(Form("./figs/pdf"), kTRUE);
    setTDRStyle();

    // read CMS graphs
    TFile *pfV2Cms_cent   = new TFile(Form("%s/Prp_v2_pt_plotter.root",inputDir));

    TGraphAsymmErrors *pgV2Low  = (TGraphAsymmErrors *)pfV2Cms_cent->Get("pgV2_low");
    TGraphErrors *pgV2LowSyst   = (TGraphErrors *)pfV2Cms_cent->Get("pgV2_low_sys");
    TGraphErrors *pgV2LowP      = (TGraphErrors *)pfV2Cms_cent->Get("pgV2_low_cont");

    TGraphAsymmErrors *pgV2High = (TGraphAsymmErrors *)pfV2Cms_cent->Get("pgV2");
    TGraphErrors *pgV2HighSyst  = (TGraphErrors *)pfV2Cms_cent->Get("pgV2_sys");
    TGraphErrors *pgV2HighP     = (TGraphErrors *)pfV2Cms_cent->Get("pgV2_cont");

    pgV2Low->SetName("pgV2Low");
    pgV2LowSyst->SetFillColorAlpha(kViolet-9,0.5);
    pgV2High->SetName("pgV2High");
    pgV2HighSyst->SetFillColorAlpha(kRed-9,0.5);

    // -----------------------------------------------------------------------------------------
    // ----- charged hadrons
    TGraphErrors *gChar    = new TGraphErrors(19, pTChar, v2Char, chxerr, v2CharSt);
    TGraphErrors *gChar2   = new TGraphErrors(19, pTChar, v2Char, chxerr, v2CharSt2);
    TGraphErrors *gCharSys = new TGraphErrors(19, pTChar, v2Char, chxerr2, v2CharSys);

    gChar->SetName("gChar");
    gChar->SetMarkerStyle(20);
    gChar->SetMarkerColor(kTeal+3);
    gChar->SetLineColor(kTeal+3);
    gChar->SetMarkerSize(1.3);
    gChar2->SetMarkerStyle(24);
    gChar2->SetMarkerColor(kTeal+4);
    gChar2->SetLineColor(kTeal+4);
    gChar2->SetMarkerSize(1.3);

    gCharSys->SetFillColor(kTeal-9);

    //----------- D from ALICE
    TGraphErrors *pgAlice          = new TGraphErrors(6, v2AliceX_pt, v2Alice_pt, v2AliceXl, v2AliceStat_pt);
    TGraphErrors *pgAliceSys       = new TGraphErrors(6, v2AliceX_pt, v2Alice_pt, v2AliceXl, v2AliceSyst_pt);
    TGraphAsymmErrors *pgAliceSysB = new TGraphAsymmErrors(6, v2AliceX_pt, v2Alice_pt, v2AliceXl2, v2AliceXl2, v2AliceSystBLow_pt, v2AliceSystBHigh_pt);


    pgAlice->SetName("pgAlice");
    pgAlice->SetMarkerStyle(kOpenSquare);
    pgAlice->SetMarkerColor(kGray+2);
    pgAlice->SetLineColor(kGray+2);
    pgAlice->SetMarkerSize(1.0);

    pgAliceSys->SetFillStyle(0);
    pgAliceSys->SetMarkerColor(kGray+2);
    pgAliceSys->SetLineColor(kGray+2);
    pgAliceSys->SetMarkerSize(1.7);

    pgAliceSysB->SetFillColor(kGray);

    // drawing
    //------------------------------------------------------------------------
    // put everything on one plot
    TH1D *phAxis_v2 = new TH1D("phAxis_v2",";p_{T} (GeV/c);v_{2}",1,0,rangeXAxis);
    phAxis_v2->SetDirectory(0);
    phAxis_v2->GetXaxis()->CenterTitle(true);
    phAxis_v2->GetXaxis()->LabelsOption("h");
    phAxis_v2->GetYaxis()->SetRangeUser(0,rangeYAxis);
    phAxis_v2->GetYaxis()->SetTitleOffset(1.25);

    TCanvas *pcCombi = new TCanvas("pcCombi","pcCombi");
    phAxis_v2->Draw();
    CMS_lumi(pcCombi,12001000,0);

    pgAliceSysB->Draw("2");
    pgAliceSys->Draw("2");
    pgAlice->Draw("pz");

    if (bDrawCh) {
        gCharSys->Draw("2");
        gChar->Draw("pz");
        gChar2->Draw("p");
    }

    pgV2LowSyst->Draw("2");
    pgV2Low->Draw("PZ");
    pgV2LowP->Draw("P");

    pgV2HighSyst->Draw("2");
    pgV2High->Draw("PZ");
    pgV2HighP->Draw("P");

    // --------- legends ----
    TLegend *leg = new TLegend(0.2,0.77,0.7,0.89,NULL,"brNDC"); // at top center
    leg->SetBorderSize(0);
    leg->SetTextFont(132);
    leg->SetTextSize(0.03);
    leg->SetLineColor(1);
    leg->SetLineStyle(1);
    leg->SetLineWidth(1);
    leg->SetFillColor(19);
    leg->SetFillStyle(0);

    TLegendEntry *entry, *entry11;
    entry=leg->AddEntry("cmspr","Hidden charm: prompt J/#psi","");
    entry->SetTextFont(132);
    entry->SetTextSize(ltxSetTextSize3);

    entry=leg->AddEntry("pgV2Low", "1.6 < |y| < 2.4","p");
    entry->SetTextFont(42);
    entry->SetTextSize(entrySize);

    entry=leg->AddEntry("pgV2High", "|y| < 2.4","P");
    entry->SetTextFont(42);
    entry->SetTextSize(entrySize);

    TLegend *leg1 = new TLegend(0.2,0.685,0.7,0.765,NULL,"brNDC");
    leg1->SetBorderSize(0);
    leg1->SetTextFont(132);
    leg1->SetTextSize(ltxSetTextSize3);

    if (bDrawCh) {
        TLegendEntry *entry1;
        entry1=leg1->AddEntry("hpm","Charged hadron","");
        entry1->SetTextFont(132);
        entry1->SetTextSize(ltxSetTextSize3);
        entry1=leg1->AddEntry("gChar","|#eta| < 0.8","P");
        entry1->SetTextFont(42);
        entry1->SetTextSize(entrySize);
    }

    //---------------------------
    TLegend *leg_alice;
    if (bDrawCh) {
        leg_alice = new TLegend(0.2,0.60,0.7,0.68,NULL,"brNDC");
    } else {
        leg_alice = new TLegend(0.2,0.685,0.7,0.765,NULL,"brNDC");
    }
    leg_alice->SetBorderSize(0);
    leg_alice->SetTextFont(132);
    leg_alice->SetLineColor(1);
    leg_alice->SetLineStyle(1);
    leg_alice->SetLineWidth(1);
    leg_alice->SetFillColor(19);
    leg_alice->SetFillStyle(0);

    TLegendEntry *entry_alice=leg_alice->AddEntry("pgAlice","Open charm: prompt D (ALICE)","");
    entry_alice->SetTextFont(132);
    entry_alice->SetTextSize(ltxSetTextSize3);
    entry_alice=leg_alice->AddEntry("pgAlice","|y| < 0.8, Cent. 30-50\%","P");
    entry_alice->SetTextFont(42);
    entry_alice->SetTextSize(entrySize);

    TLatex *lat = new TLatex();
    lat->SetNDC();
    lat->SetTextFont(42);
    lat->SetTextSize(ltxSetTextSize2);
    if (bDrawCh) lat->DrawLatex(0.63,0.52,"Cent. 10-60%");
    else lat->DrawLatex(0.63,0.58,"Cent. 10-60%");

    leg->Draw();
    if (bDrawCh) leg1->Draw();
    leg_alice->Draw();

    gPad->RedrawAxis();

    if(bSavePlots)
    {
        pcCombi->SaveAs(Form("figs/pdf/%s_RaaCh%d.pdf",figNamePrefix,bDrawCh));
        pcCombi->SaveAs(Form("figs/png/%s_RaaCh%d.png",figNamePrefix,bDrawCh));
    }


    return;
}
Beispiel #20
0
// draw the same thing but after reco
void genPlots02(std::string fullPath, int nOverlay = 500, bool custBinning = false)
{
    const int fVerbose(1);
    setTDRStyle();
    gStyle->SetOptStat(112211);
    gStyle->SetPalette(1);
    // Canvas
    c = new TCanvas("c2","c2",1000,600);
    const unsigned int nPadX = 1;
    const unsigned int nPadY = 1;
    c->Divide(nPadX,nPadY);
    const unsigned int nPads=nPadX*nPadY;
    for(unsigned int i=1; i<=nPads; i++)
    {
	TPad* pad= (TPad*)c->cd(i);
	pad->SetTopMargin(0.10);
	pad->SetRightMargin(0.20);
	pad->SetLeftMargin(0.15);
    }
    // Open file
    TFile *f = TFile::Open(fullPath.c_str());
    if (f==0)
    {
	cout << "File " << fullPath << " not found -- exiting" << endl;
	return;
    }
    if(fVerbose>0)
	cout << "Succesfully opened file " << fullPath << endl;
    // Get TTree
    TTree* t = (TTree*) f->Get("events");
    if(fVerbose>0) cout << "Got TTree with " << t->GetEntries() << " entries" << endl;
    // Do a cut, if needed
    //t->Draw(">>lst","chi2lb>.1&&mlb>5.61&&mlb<5.63");
    //t->Draw(">>lst","chi2lb>.1&&isSig==1");
    t->Draw(">>lst","(rid1m&4)==4&&(rid2m&4)==4&&mjp>2.895&&mjp<3.295&&prob1m>0.1&&prob2m>0.1&&ptjp>2&&probjp>0.005&&ml0>1.101&&ml0<1.129&&probpr>0.02&&probpi>0.02&&rptpr>rptpi&&ptl0>3&&rptpr>1&&rptpi>0.5&&probl0>0.02&&alphal0<0.3&&d3l0>1&&d3l0/d3El0>10&&problb>0.001&&alphalb<0.3");
    TEventList *lst;
    lst = (TEventList*)gDirectory->Get("lst");
    t->SetEventList(lst);
    if(fVerbose>0) cout << "Got TTree with " << t->GetEntries() << " entries" << endl;

    // Do plots
    c->cd(1);
    //doPlot2d(t,"hrzL0vtx", "vrl0:TMath::Abs(vzl0)",30,0,300,30,0,120,"Tit","|z|","r","cm","cm");
    if (custBinning)
    {
	double newbinsX[]={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50};
	const int newbinsX_size = sizeof(newbinsX)/sizeof(double);
	std::vector<double> binvecX(newbinsX,newbinsX+newbinsX_size);
	//double newbinsY[]={0,1,2,3,4,5,6,7,8,9,10};
	double newbinsY[]={0,0.5,1,2,4,8,16,32};
	const int newbinsY_size = sizeof(newbinsY)/sizeof(double);
	std::vector<double> binvecY(newbinsY,newbinsY+newbinsY_size);
	doPlot2d(t,"hrzL0vtxreco", "vrl0:TMath::Abs(vzl0)",binvecX, binvecY,"#Lambda vertices","|z|","r","cm","cm");
    }
    else
    {
	doPlot2d(t,"hrzL0vtxreco", "vrl0:TMath::Abs(vzl0)",30,0,50,30,0,30,"#Lambda vertices","|z|","r","cm","cm");
    }

    // add tracker
    TPad* pad;
    pad = (TPad*)c->cd(1);
    pad->Modified();
    pad->Update();
    repositionPalette("hrzL0vtxreco");
    pad->Update();
    pad->SetLogz();
    drawTracker(pad);

    if (nOverlay<=0) return;
    int maxN = nOverlay;
    if (maxN > t->GetEntries()) maxN = t->GetEntries();
    double vrl0,vzl0,ppr,ppi,etapr,etapi;
    t->SetBranchAddress("vrl0",&vrl0);
    t->SetBranchAddress("vzl0",&vzl0);
    t->SetBranchAddress("ppr",&ppr);
    t->SetBranchAddress("etapr",&etapr);
    t->SetBranchAddress("ppi",&ppi);
    t->SetBranchAddress("etapi",&etapi);
    double scalepr = 4;
    double scalepi = 8;

    { // reference indicator
	const double x1pr = 0; const double y1pr = -3;
	const double x2pr = scalepr; const double y2pr = y1pr;
	const double versatz = 14;
	const double x1pi = x1pr+versatz; const double y1pi = -3;
	const double x2pi = x2pr+versatz+scalepi; const double y2pi = y1pi;
	TArrow *a;
	a = new TArrow(x1pr,y1pr,x2pr,y2pr,.01,">");
	a->SetLineColor(24);
	a->Draw();
	TLatex tl;
	tl.SetTextSize(20);
	tl.SetTextFont(4);
	tl.DrawLatex(x1pr,y2pr-1.2,"p(p) / 1 GeV");
	a = new TArrow(x1pi,y1pi,x2pi,y2pi,.01,">");
	a->SetLineColor(20);
	a->Draw();
	tl.SetTextSize(20);
	tl.SetTextFont(4);
	tl.DrawLatex(x1pi,y2pi-1.2,"p(#pi) / 1 GeV");
    }
    for (int i = 0; i!=maxN; i++)
    {
	t->GetEntry(i);
	const double thetapr = 2*TMath::ATan(TMath::Exp(-TMath::Abs(etapr)));
	const double thetapi = 2*TMath::ATan(TMath::Exp(-TMath::Abs(etapi)));
	const double x1=TMath::Abs(vzl0);
	const double y1=vrl0;
	const double x2pr=x1+scalepr*ppr*TMath::Cos(thetapr);
	const double y2pr=y1+scalepr*ppr*TMath::Sin(thetapr);
	const double x2pi=x1+scalepi*ppi*TMath::Cos(thetapi);
	const double y2pi=y1+scalepi*ppi*TMath::Sin(thetapi);
	TArrow *a;
        a = new TArrow(x1,y1,x2pr,y2pr,.01,">");
	a->SetLineColor(24);
	a->Draw();
        a = new TArrow(x1,y1,x2pi,y2pi,.01,">");
	a->SetLineColor(20);
	a->Draw();
	TMarker *m = new TMarker(x1,y1,7);
	m->SetMarkerColor(28);
	m->Draw();
    }
}
Beispiel #21
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");
        }  

}
Beispiel #22
0
void MakeNPunziLowMass_id(){
  
  setTDRStyle();
  gStyle->SetPalette(1);

  TH1F* tight_anal1 = makehist("PreSelection_lowmass");
  TH1F* tight_anal2 = makehist("PreSelection_medium_lowmass");
  TH1F* tight_anal3 = makehist("PreSelection_tight_lowmass");
  TH1F* tight_anal4 = makehist("PreSelection_iso_b10_e10_lowmass");


  TLegend* legendH = new TLegend(0.6, 0.7, 0.9, 0.9);
  legendH->SetFillColor(kWhite);
  legendH->SetTextSize(0.03);

  
  tight_anal1->GetXaxis()->SetTitle("m_{N} GeV");
  tight_anal1->GetYaxis()->SetTitle("ID efficiency");
 
  tight_anal1->SetMarkerColor(kBlue);
  tight_anal1->SetMarkerStyle(20.);
  tight_anal2->SetMarkerColor(kRed);
  tight_anal2->SetMarkerStyle(21.);
  tight_anal3->SetMarkerColor(kRed);
  tight_anal3->SetMarkerStyle(22.);



  tight_anal4->SetMarkerColor(kRed);
  tight_anal4->SetMarkerStyle(23.);
  tight_anal2->SetMarkerColor(kRed);




  legendH->AddEntry(tight_anal1, "Analysis", "p");
  legendH->AddEntry(tight_anal2, "Medium POG", "p");
  legendH->AddEntry(tight_anal3, "Tight POG", "p");
  legendH->AddEntry(tight_anal4, "Tight POG + IP", "p");

  tight_anal4->GetYaxis()->SetRangeUser(0., 0.001);
  tight_anal4->Draw("p");
  tight_anal2->Draw("psame");
  tight_anal3->Draw("psame");
  tight_anal1->Draw("psame");


  legendH->Draw();

  TGraphAsymmErrors * g = new TGraphAsymmErrors(heff);
  g->SetLineWidth(2.0);
  g->SetMarkerSize(2.);
  //  g->Draw( "9pXsame" );
  
  
  CMS_lumi( c1, 2, 11 );
  c1->Update();
  c1->RedrawAxis();
  
  
  c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/SignalPlots/Punzi_presel_id_lowmass.pdf" ));
  return;
  
}
int Efficiency_v2(TTree* tree, int narray, int* leptonId, int* mother_Id, TString* sel_den , TString* sel_num, TString* par_x, double* cut_den, double* cut_num){

setTDRStyle();

Long64_t n = tree->GetEntries();

//Path for input and output file. Written in FitDataPath.txt
ifstream file("EfficiencyPath.txt");
string str;
getline(file,str);
TString _path = str;

//Histogram parameter
int nbins[narray];
double par_low[narray];
double par_upp[narray];

//Declaration of histogram
//
//efficiency of the isolation cut
TH1D **histo_num= new TH1D*[narray];
TH1D **histo_den= new TH1D*[narray];
//efficiency of the selection
TH1D **eff = new TH1D*[narray];

//Name for storing and final plots
//
TString* pname = new TString[narray];
TString* _pname = new TString[narray];
TString* treename = new TString[narray];
TString* _par = new TString[narray];
TString* _sel_num = new TString[narray];
TString* _sel_den = new TString[narray];
TString* _cut_num = new TString[narray];
TString* _cut_den = new TString[narray];
TString* _mother_Id = new TString[narray];

//Name of the output
TString _output; 
_output = _path+"eff.root";
TFile* output = new TFile(_output,"recreate");


for(int i =0; i < narray; ++i){

//Set parameter range
if(par_x[i] == "Pt"){nbins[i] = 10;par_low[i] = 0;par_upp[i] = 250;}
else if(par_x[i] == "eta"){nbins[i] = 20;par_low[i] = -3;par_upp[i] = 3;}
else if(par_x[i] == "phi"){nbins[i] = 10;par_low[i] = -3.5;par_upp[i] = 3.5;}


//Writing string
if(mother_Id[i] == 23){_mother_Id[i] = "Z";}
else if(mother_Id[i] == 24){_mother_Id[i] = "W";}
if (leptonId[i] == 11) {pname[i] = "e";_pname[i] = "e";}
else if (leptonId[i] == 13){pname[i] = " #mu";_pname[i] = "mu";}
if (mother_Id[i] == 23){treename[i] = "from Z";}
else if (mother_Id[i] == 24){treename[i] = "from W";}
if(par_x[i] == "Pt"){_par[i] = "P_{t}";}
else if(par_x[i] == "eta"){_par[i] = "#eta";}
else if(par_x[i] == "phi"){_par[i] = "#phi";}
else{cout<<"ERROR: wrong parameter name !";return 1;}
if(sel_num[i] == ""){_sel_num[i] = "unsel";}
	else if(sel_num[i] == "tightId"){_sel_num[i] = "tightId";}
	else if(sel_num[i] == "dz"){_sel_num[i] = Form("IP dz < %0.3lf ",cut_num[i]);}
	else if(sel_num[i] == "dxy"){_sel_num[i] = Form("IP dxy < %0.3lf ", cut_num[i]) ;}
	else{cout<<"ERROR: wrong numeretor selection name !";return 1;}
	if(sel_den[i] == ""){_sel_den[i] = "unsel";}
	else if(sel_den[i] == "tightId"){_sel_den[i] = "tight";}
	else{cout<<"ERROR: wrong denominator selection name !";return 1;}
	if(cut_den[i] == 0.){_cut_den[i] = "";}
	else{_cut_den[i] = Form("%0.3lf",cut_den[i]);}
	if(cut_num[i] == 0.){_cut_num[i] = "";}
	else{_cut_num[i] = Form("%0.3lf",cut_num[i]);}

	//Assigning histo
	histo_num[i] = new TH1D("histo_num","Pt",nbins[i],par_low[i],par_upp[i]);
	histo_den[i] = new TH1D("histo_den","Pt",nbins[i],par_low[i],par_upp[i]);
	eff[i] = new TH1D("histo_eff","Pt",nbins[i],par_low[i],par_upp[i]);


	}


	//Event variables
	//
	//Generated
	Float_t gen_phi[200];
	Float_t gen_eta[200];
	Float_t Pt[200];
	Float_t m[200];
	Int_t Id[200];
	Int_t Mo[200];
	Float_t charge[200];
	Int_t status[200];
	Int_t GrMa[200];
	Int_t ngenPart;
	Int_t source[200];
	Int_t pile_up;
	//Reconstructed
	//Electrons
	Int_t nrecel;
	Int_t receltightid[200];
	Float_t recelPt[200];
	Float_t recelm[200];
	Float_t recel_eta[200];
	Float_t recel_phi[200];
	Int_t recelcharge[200];
	Float_t receliso03[200];
	Float_t receliso04[200];
	Float_t receldz[200];
	Float_t receldxy[200];
	//Muons
	Int_t nrecmu;
	Int_t recmutightid[200];
	Float_t recmuPt[200];
	Float_t recmum[200];
	Float_t recmu_eta[200];
	Float_t recmu_phi[200];
	Int_t recmucharge[200];
	Float_t recmuiso03[200];
	Float_t recmuiso04[200];
	Float_t recmudz[200];
	Float_t recmudxy[200];

	//Assigne branches
	//generated
	tree->SetBranchAddress("ngenLep", &ngenPart);
	tree->SetBranchAddress("genLep_pdgId", &Id);
	tree->SetBranchAddress("genLep_sourceId", &source);
	tree->SetBranchAddress("genLep_eta", &gen_eta);
	tree->SetBranchAddress("genLep_phi", &gen_phi);
	tree->SetBranchAddress("genLep_pt", &Pt);
	tree->SetBranchAddress("genLep_mass", &m);
	tree->SetBranchAddress("genLep_charge", &charge);
	tree->SetBranchAddress("genLep_status", &status);
	tree->SetBranchAddress("nTrueInt",&pile_up);
	//reconstructed
	//electron
	tree->SetBranchAddress("nel", &nrecel);
	tree->SetBranchAddress("el_tightId", &receltightid);
	tree->SetBranchAddress("el_pt", &recelPt);
	tree->SetBranchAddress("el_mass", &recelm);
	tree->SetBranchAddress("el_eta", &recel_eta);
	tree->SetBranchAddress("el_phi", &recel_phi);
	tree->SetBranchAddress("el_charge", &recelcharge);
	tree->SetBranchAddress("el_relIso03", &receliso03);
	tree->SetBranchAddress("el_relIso04", &receliso04);
	tree->SetBranchAddress("el_chargedHadRelIso03", &receliso03);
	tree->SetBranchAddress("el_chargedHadRelIso04", &receliso04);
	tree->SetBranchAddress("el_dz",&receldz);
	tree->SetBranchAddress("el_dxy",&receldxy);
	
	//muons
	tree->SetBranchAddress("nmu", &nrecmu);
	tree->SetBranchAddress("mu_tightId", &recmutightid);
	tree->SetBranchAddress("mu_pt", &recmuPt);
	tree->SetBranchAddress("mu_mass", &recmum);
	tree->SetBranchAddress("mu_eta", &recmu_eta);
	tree->SetBranchAddress("mu_phi", &recmu_phi);
	tree->SetBranchAddress("mu_charge", &recmucharge);
	tree->SetBranchAddress("mu_relIso03", &recmuiso03);
	tree->SetBranchAddress("mu_relIso04", &recmuiso04);
	tree->SetBranchAddress("mu_chargedHadRelIso03", &recmuiso03);
	tree->SetBranchAddress("mu_chargedHadRelIso04", &recmuiso04);
	tree->SetBranchAddress("mu_dz",&recmudz);
	tree->SetBranchAddress("mu_dxy",&recmudxy);
	
	int counter = 1;
	//Start loop over all events
	for (int k = 0; k < n; ++k) {

		tree->GetEntry(k);

		for(int ii = 0; ii <narray; ++ii){  

		if(k%n > counter*100000){cout<<100.*k/n<<" completed"<<endl;++counter;}

		if(leptonId[ii] == 11){
			for(int j=0; j<nrecel;++j){
				//Cut on the denominator
				if((sel_den[ii] != "tightId")||((sel_den[ii] == "tightId")&&(receltightid[j] == 1 ))){
					//Veto the EE-EB gape
					if(((abs(recel_eta[j]) < 1.479)||(abs(recel_eta[j]) > 1.653))){

					//Variable for matching
					double R = 999;
					double delta_P = 999;
					double delta_charge = 999;

					//Parameter on the xaxis

					double par;

					//if(abs(recel_eta[j]) < 2.4){ 
						//loop over all generated particles to do the matching
						for (int i = 0; i < ngenPart; ++i) {
							if((abs(Id[i]) == leptonId[ii])&&(status[i]== 1)&&(abs(gen_eta[i]) < 2.4)&&(abs(source[i]) == mother_Id[ii])){ 

								//Electrons selection
								double R2 = DeltaR(gen_eta[i],recel_eta[j],gen_phi[i],recel_phi[j] );

								//Minimise DeltaR and Fill the other variables
								if (R > R2) {

									R = R2;
									delta_P = abs(recelPt[j]-Pt[i])/Pt[i];
									delta_charge = abs(recelcharge[j] - charge[i]);
								}
							}
						}
					//}			

					//Choose the parameter to be filled for the eff.
					if(par_x[ii] == "Pt"){par = recelPt[j];}
					else if(par_x[ii] == "eta"){par = recel_eta[j];}
					else if(par_x[ii] == "phi"){par = recel_phi[j];}

					//Fill Pt only for matched events
					if((R<0.1)&&(delta_P < 0.2)&&(delta_charge < 0.5)){
						//Filling the den
						histo_den[ii]->Fill(par);

						//Additional cut on the numerator
						if((sel_num[ii] != "tightId")||((sel_num[ii] == "tightId")&&(receltightid[j] == 1 ))){
							if((sel_num[ii] != "dxy")||((sel_num[ii] == "dxy")&&(abs(receldxy[j]) < cut_num[ii] ))){
								if((sel_num[ii] != "dz")||((sel_num[ii] == "dz")&&(abs(receldz[j]) < cut_num[ii] ))){
									histo_num[ii]->Fill(par);
								}
							}
						}
					}
					}
				}
			}
		}

		if(leptonId[ii] == 13){
			for(int j=0; j<nrecmu;++j){
				//Cut on the denominator
				if((sel_den[ii] != "tightId")||((sel_den[ii] == "tightId")&&(recmutightid[j] == 1 ))){
					//Veto the EE-EB gape
					if(((abs(recmu_eta[j]) < 1.479)||(abs(recmu_eta[j]) > 1.653))){

					//Variable for matching
					double R = 999;
					double delta_P = 999;
					double delta_charge = 999;

					//Parameter on the xaxis

					double par;

					//if(abs(recmu_eta[j]) < 2.4){ 
						//loop over all generated particles to do the matching
						for (int i = 0; i < ngenPart; ++i) {
							if((abs(Id[i]) == leptonId[ii])&&(status[i]== 1)&&(abs(gen_eta[i]) < 2.4)&&(abs(source[i]) == mother_Id[ii])){ 

								//Electrons selection
								double R2 = DeltaR(gen_eta[i],recmu_eta[j],gen_phi[i],recmu_phi[j] );

								//Minimise DeltaR and Fill the other variables
								if (R > R2) {

									R = R2;
									delta_P = abs(recmuPt[j]-Pt[i])/Pt[i];
									delta_charge = abs(recmucharge[j] - charge[i]);
								}
							}
						}
					//}			

					//Choose the parameter to be filled for the eff.
					if(par_x[ii] == "Pt"){par = recmuPt[j];}
					else if(par_x[ii] == "eta"){par = recmu_eta[j];}
					else if(par_x[ii] == "phi"){par = recmu_phi[j];}

					//Fill Pt only for matched events
					if((R<0.1)&&(delta_P < 0.2)&&(delta_charge < 0.5)){
						//Filling the den
						histo_den[ii]->Fill(par);

						//Additional cut on the numerator
						if((sel_num[ii] != "tightId")||((sel_num[ii] == "tightId")&&(recmutightid[j] == 1 ))){
							if((sel_num[ii] != "dxy")||((sel_num[ii] == "dxy")&&(abs(recmudxy[j]) < cut_num[ii] ))){
								if((sel_num[ii] != "dz")||((sel_num[ii] == "dz")&&(abs(recmudz[j]) < cut_num[ii] ))){
									histo_num[ii]->Fill(par);
								}
							}
						}
					}
					}
				}
			}
		}
		}
		
	}
	for(int ii = 0; ii < narray;++ii){


	histo_num[ii]->Sumw2();
	histo_den[ii]->Sumw2();

	//Divide histograms to get the efficiency
	eff[ii]->Divide(histo_num[ii],histo_den[ii],1,1,"B"); 

	//Efficiency of the iso cut.
	TCanvas* c1 = new TCanvas("c1","c1");
	eff[ii]->Draw();
	eff[ii]->GetYaxis()->SetRangeUser(0,1.1);
	eff[ii]->GetYaxis()->SetTitle("#epsilon");
	eff[ii]->GetXaxis()->SetTitle(_par[ii]);
	eff[ii]->SetMarkerStyle(20);
	eff[ii]->SetMarkerSize(1);
	eff[ii]->SetMarkerColor(4);
	eff[ii]->SetLineColor(4);
	eff[ii]->SetTitle(_sel_num[ii]+" for "+_sel_den[ii]+" "+pname[ii]+" "+treename[ii]);
	
	//Define the name of the canvas
	TString cname = (TString)"eff_"+_pname[ii]+"_"+treename[ii]+"_den_"+_sel_den[ii]+"_num_"+_sel_num[ii]+"_"+par_x[ii];
	
	c1->SaveAs(_path+"/PDF/"+cname+".pdf");
	output->cd();
	c1->Write(cname);
	}

	output->Close();
}
Beispiel #24
0
void drawBias () {
    
    setTDRStyle();
    gStyle->SetOptStat(1);
    gStyle->SetOptTitle(1);
    gStyle->SetFitFormat("2.2g");
    gStyle->SetPadBottomMargin(0.2);
    
    
    const int nDirs = 6;
    
    Color_t cols[nDirs] = {kBlack, kRed+1, kOrange-3, kGreen+1, kAzure+7 , kMagenta};
    
    
    TString dirNames[nDirs] = {"exp1","expow2","pow1","lau1","atlas1","vvdijet1"};
    
    
    const int nPoints = 26;//46;
    TCanvas* c1[nDirs][nPoints];
    TFile * f[nDirs][nPoints];
    TTree* tree_fit_sb[nDirs][nPoints];
    
    TH1D* hists[nDirs][nPoints];
    
    TGraphErrors* biasG[nDirs];
    TGraphErrors* biasG2[nDirs];
    
    TCanvas* c2 = new TCanvas("p2","p2",700,700);
    TH1F *hr = c2->DrawFrame(500,-1,3100,1);
    hr->SetXTitle("m_{X} (GeV)");
    hr->SetYTitle("mean");

    TCanvas* c2a = new TCanvas("c2a","c2a",700,700);
    TH1F *hra = c2a->DrawFrame(500,-1,3100,1);
    hra->SetXTitle("m_{X} (GeV)");
    hra->SetYTitle("medians");
    
    TLegend* leg = new TLegend(0.75,1.0,1.0,0.75,"pull mean","NDC");
    leg->SetTextFont(42);
    TLegend* leg2 = new TLegend(0.65,0.35,0.9,0.1,"medians","NDC");
    leg2->SetTextFont(42);
    
    for (int dd=0; dd!=6; ++dd) {
        biasG[dd] = new TGraphErrors(nPoints);
        biasG2[dd] = new TGraphErrors(nPoints);
        biasG[dd]->SetMarkerColor(cols[dd]);
        biasG[dd]->SetLineColor(cols[dd]);
        biasG2[dd]->SetMarkerColor(cols[dd]);
        biasG2[dd]->SetLineColor(cols[dd]);
        
        
        leg->AddEntry(biasG[dd],dirNames[dd],"p");
        leg2->AddEntry(biasG2[dd],dirNames[dd],"p");
        
        Double_t quantile,prob;
        prob = 0.5;
        
        for (int i=0; i!=nPoints; ++i) {
            if (650+i*100 == 1750) continue;
            TString nameF = dirNames[dd]+Form("/mlfitoutput%d.root",650+i*100);
            if (gSystem->AccessPathName(nameF)) continue;
            c1[dd][i] = new TCanvas(Form("c_%d_%d",dd,i),Form("c_%d_%d",dd,i), 700, 700);
            f[dd][i] = new TFile(nameF);
            if(!f[dd][i]) continue;
            
            tree_fit_sb[dd][i] = static_cast<TTree*>(f[dd][i]->Get("tree_fit_sb"));
            
            TString name = Form("bias_%d_GeV-",650+i*100)+dirNames[dd];
            TString title = Form("bias at %d GeV for ",650+i*100)+dirNames[dd];
            hists[dd][i] = new TH1D(name,title+";#frac{#mu_{fit}-0.0}{#sigma_{fit}};entries/0.25",10000,-10,10);
            
            tree_fit_sb[dd][i]->Draw("(mu-0)/muHiErr>>"+name,"fit_status >= 0","pe");
            hists[dd][i]->Fit("gaus","LM","",-2,2);
            hists[dd][i]->GetXaxis()->SetTitleOffset(1.2);
            c1[dd][i]->SaveAs(dirNames[dd]+Form("_%d.pdf",650+i*100));
            
            
            biasG[dd]->SetPoint(i,650+i*100,hists[dd][i]->GetFunction("gaus")->GetParameter(1));
            biasG[dd]->SetPointError(i,0,hists[dd][i]->GetFunction("gaus")->GetParError(1));
            
            hists[dd][i]->GetQuantiles(1,&quantile,&prob);
            biasG2[dd]->SetPoint(i,650+i*100,quantile); // //GetMean
            //biasG2[dd]->SetPoint(i,650+i*100,hists[dd][i]->GetMean()); // //GetMean
            biasG2[dd]->SetPointError(i,0,hists[dd][i]->GetRMS()/sqrt(hists[dd][i]->GetEntries()));
            
            
        }
        c2->cd();
        biasG[dd]->Draw("pe same");
        c2a->cd();
        biasG2[dd]->Draw("pe same");
    }

    c2->cd();
    leg->Draw("same");
    c2a->cd();
    leg2->Draw("same");
    
}
void doControlPlotsMuons(){
setTDRStyle();

//loop over variables
for(int i = 0; i<N; i++){
//double MinX = MinXs[i];
//double MaxX = MaxXs[i];
RebinFact = RebinFacts[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("DoubleMu", 1, Obj, Next, Variable, RebinFact, Systematic);

std::cout << data->Integral() << std::endl;

//MC
TH1D* tt = getSample("TTJet", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* wjets = getSample("WJetsToLNu", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* DY1 = getSample("DYJetsToLL_M-10To50", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* DY2 = getSample("DYJetsToLL_M-50", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* T_tW = getSample("T_tW-channel", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* Tbar_tW = getSample("Tbar_tW-channel",1, Obj, Next, Variable, RebinFact, Systematic);

THStack *hs = new THStack("hs","test");

  hs->Add(wjets);
  hs->Add(DY1);
  hs->Add(DY2);
  hs->Add(T_tW); 
  hs->Add(Tbar_tW);
  hs->Add(tt); 
  
  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);
		
  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3);

  hs->Draw();
  data->Draw("E same");
  data->SetMarkerStyle(20);
  
//  hs->GetXaxis()->SetLimits(MinX, MaxX);
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
   
   
  if(logPlot == true){
  c1->SetLogy();
  }	
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.6,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t}", "lf");
	tleg2->AddEntry(T_tW, "single-t", "lf");
	tleg2->AddEntry(Tbar_tW, "single-#bar{t}", "lf");	
	tleg2->AddEntry(DY1 , "DYJetsToLL-10To50", "lf");
	tleg2->AddEntry(DY2 , "DYJetsToLL-50", "lf");
	tleg2->AddEntry(wjets , "W+jets", "lf");
	
 	tleg2->Draw("same");	

  TString plotName("plots/Control/PassesCutsUpTo1Btag/Muons/");
  
  if(logPlot == true){
    plotName += Variable+"Log.pdf";
//    plotName += Nbtags+".pdf";
    
  }else{
    plotName += Variable+".pdf";  
//    plotName += Nbtags+".pdf";
  }
 
  TText* textPrelim = doPrelim(0.16,0.96); 
  textPrelim->Draw();
  
  c1->SaveAs(plotName);
  delete c1;
  
  }
  	
}
void plot_TauTemplate(string Elog="Elog431_",int icomp=0){

  //
  // icomp=0: only show own results
  //       1: show also Koushik's results
  //
  
  //
  ///////////////////////////////////////////////////////////////////////////////////////////
  ////Some cosmetic work for official documents. 
  gROOT->LoadMacro("tdrstyle.C");
  setTDRStyle();
  gStyle->SetPalette(1) ; // for better color output
  gROOT->LoadMacro("CMS_lumi.C");
 writeExtraText = true;       // if extra text
  extraText  = "         Supplementary";  // default extra text is "Preliminary"
  lumi_8TeV  = "19.1 fb^{-1}"; // default is "19.7 fb^{-1}"
  lumi_7TeV  = "4.9 fb^{-1}";  // default is "5.1 fb^{-1}"
  lumi_sqrtS = "13 TeV";       // used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string)

  int iPeriod = 0;    // 1=7TeV, 2=8TeV, 3=7+8TeV, 7=7+8+13TeV, 0=free form (uses lumi_sqrtS)
  // second parameter in example_plot is iPos, which drives the position of the CMS logo in the plot
  // 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)
  int iPos =0;
  
  
  
  char tempname[200];
  char tempname2[200];
  int W = 600;
  int H = 600;
  int H_ref = 600;
  int W_ref = 800;
  float T = 0.08*H_ref;
  float B = 0.12*H_ref;
  float L = 0.12*W_ref;
  float R = 0.04*W_ref;

  TCanvas* c1 = new TCanvas("name","name",10,10,W,H);
  c1->SetFillColor(0);
  c1->SetBorderMode(0);
  c1->SetFrameFillStyle(0);
  c1->SetFrameBorderMode(0);
  c1->SetLeftMargin( L/W );
  c1->SetRightMargin( R/W );
  c1->SetTopMargin( T/H );
  c1->SetBottomMargin( B/H );
  c1->SetTickx(0);
  c1->SetTicky(0);

  gStyle->SetOptStat(000000);
  
  Float_t legendX1 = .60; //.50;
  Float_t legendX2 = .90; //.70;
  Float_t legendY1 = .60; //.65;
  Float_t legendY2 = .90;
  TLegend* catLeg1 = new TLegend(legendX1,legendY1,legendX2,legendY2);
  catLeg1->SetTextSize(0.042);
  catLeg1->SetTextFont(42);
  catLeg1->SetFillColor(0);
  catLeg1->SetLineColor(0);
  catLeg1->SetBorderSize(0);

  //
  sprintf(tempname,"TauHad/Stack/%sHadTau_TauResponseTemplates_stacked.root",Elog.c_str());
  TFile *file_13TeV         = new TFile(tempname,"R"); 
  //TFile *file_13TeV_Koushik = new TFile("HadTau_TauResponseTemplates_PHYS14_13TeV.root","R"); 
  TFile *file_TauGan        = new TFile("TauHad/HadTau_TauResponseTemplates_GenTau_Matching04.root","R"); 

  TH1D * thist;
  catLeg1->SetHeader("p_{T}(#tau^{tau})");

  for(int i=0;i<4;i++){
    sprintf(tempname,"hTauResp_%d",i);
    thist = (TH1D*)file_13TeV->Get(tempname)->Clone();
    sprintf(tempname2,"hTauResp_%d_AB",i);
    thist->SetName(tempname2);
	thist->SetFillColor(0);
    thist->SetLineColor(i+1);
    thist->SetLineWidth(3);
    thist->SetStats(kFALSE);
    thist->SetMaximum(1.5);
    
    if(i==0){
      thist->SetMaximum(1.4);
      thist->GetXaxis()->SetLabelFont(42);
      thist->GetXaxis()->SetLabelOffset(0.007);
      thist->GetXaxis()->SetLabelSize(0.04);
      thist->GetXaxis()->SetTitleSize(0.05);
      thist->GetXaxis()->SetTitleOffset(0.9);
      thist->GetXaxis()->SetTitleFont(42);
      thist->GetYaxis()->SetLabelFont(42);
      thist->GetYaxis()->SetLabelOffset(0.007);
      thist->GetYaxis()->SetLabelSize(0.04);
      thist->GetYaxis()->SetTitleSize(0.05);
      thist->GetYaxis()->SetTitleOffset(1.25);
      thist->GetYaxis()->SetTitleFont(42);
    }

    //KH if (i==0){
    thist->GetYaxis()->SetTitle("Arbitrary unit");
    thist->DrawNormalized("same,hist");
    /*
    if(i==0)sprintf(tempname,"20 - 30: t#bar{t}");
    if(i==1)sprintf(tempname,"30 - 50: t#bar{t}");
    if(i==2)sprintf(tempname,"50 - 100: t#bar{t}");
    if(i==3)sprintf(tempname,">100: t#bar{t}");
    */
    if(i==0)sprintf(tempname,"20 - 30 GeV");
    if(i==1)sprintf(tempname,"30 - 50 GeV");
    if(i==2)sprintf(tempname,"50 - 100 GeV");
    if(i==3)sprintf(tempname,">100 GeV");
    catLeg1->AddEntry(thist,tempname,"l");
    //KH}
    
    }
  catLeg1->Draw();
  /*
   TLatex *   tex = new TLatex(1.5,0.03,"arXiv:1602.06581");
   tex->SetTextColor(4);
   tex->SetTextFont(61);
   tex->SetTextSize(0.0375);
   tex->SetLineColor(4);
   tex->SetLineWidth(2);
   //tex->Draw();
*/  
  TH1D * thist_km;
  if (icomp==1){
  for(int i=0;i<4;i++){
    sprintf(tempname,"hTauResp_%d",i);
    thist_km = (TH1D*)file_TauGan->Get(tempname)->Clone();
    sprintf(tempname2,"hTauResp_%d_KM",i);
    thist_km->SetName(tempname2);
    thist_km->SetLineColor(i+1);
    thist_km->SetLineWidth(3);
    thist_km->SetLineStyle(3);

    if (i==0) {
    thist_km->DrawNormalized("same,hist");
    if(i==0)sprintf(tempname,"20 - 30: TauGan");
    if(i==1)sprintf(tempname,"30 - 50: TauGan");
    if(i==2)sprintf(tempname,"50 - 100: TauGan");
    if(i==3)sprintf(tempname,">100: TauGan");
    catLeg1->AddEntry(thist_km,tempname,"l");
    }
  }
  }
  {
    CMS_lumi( c1, iPeriod, iPos );   // writing the lumi information and the CMS "logo"
  }
  c1->Update();
  c1->RedrawAxis();
  catLeg1->Draw();  

  c1->Print("Plot_TauTemplate_TTbar_Wjets.pdf");
  c1->Print("Plot_TauTemplate_TTbar_Wjets.png");

}
Beispiel #27
0
void plotAcc(TFile* f, const char* var="Z0_Y") {
  setTDRStyle();
  TDirectory* basedir=f->Get("mcEff");

  TH1* base=((TDirectory*)basedir->Get("All"))->Get(var);

  //  TDirectory* zdir=basedir->Get("Tight-ECAL-Loose-ECAL");
  // TDirectory* zdir2=basedir->Get("Tight-ECAL-HF");

  TCanvas* c1=new TCanvas("c1","c1",700,600);
  
  TLegend* tl;
  tl=new TLegend(0.35,0.15,0.75,0.40,"POWHEG + Tune Z2 + CT10");

  c1->SetTopMargin(0.05);
  c1->SetRightMargin(0.05);

  TH1* final=0;

  int n=0;
  TH1* stage1=((TDirectory*)basedir->Get("All"))->Get("ECAL-ECAL");
  TH1* stage2=((TDirectory*)basedir->Get("All"))->Get("ECAL-HF");
	       
  TH1* work=stage1->Clone();
  work->Add(stage2);
  TH1* work2=base->Clone();

  double w2f=0;
  int w2fn=0;
  for (int iii=-3; iii<=4; iii++) {
    w2f+=work2->GetBinContent(work2->GetNbinsX()/2+iii);
    w2fn++;
  }
  w2f/=w2fn;

  work2->Scale(1.0/w2f);
  //  work->Divide(work,base);
  for (int iii=1; iii<=100; iii++)
    work->SetBinContent(iii+5,work->GetBinContent(iii+5)/base->GetBinContent(iii));

  work->SetLineColor(colorFor(n));
  work->SetLineWidth(2);
  work->GetXaxis()->SetTitle(y_xaxis_label);
  work->GetYaxis()->SetTitle("Geometrical Acceptance");
  work->GetYaxis()->SetTitleOffset(1.2);
  work->SetTitle(0);
  work->SetStats(false);
  work->SetMaximum(1.02);
  work->SetMinimum(0.0);

  if (strstr(var,"Y")!=0) {
    work->GetXaxis()->SetRangeUser(-4.5,4.5);
  } else {
    work->GetXaxis()->SetRangeUser(0.0,120.0);
  }
  work->GetXaxis()->CenterTitle(true);
  work->GetYaxis()->CenterTitle(true);
  work->Draw("HIST");

  work2->SetLineWidth(2);
  work2->SetLineStyle(2);
  work2->SetLineColor(4);
  work2->Draw("SAMEHIST");

  tl->AddEntry(work,"Acceptance");
  tl->AddEntry(work2,"Normalized d#sigma/dY");

  tl->SetFillColor(0);
  tl->Draw("SAME");


  zrap_Prelim(0.80,0.90);

  char stuff[1024];
  //  sprintf(stuff,"acc_%s.png",var);
  // c1->Print(stuff);
  sprintf(stuff,"acc_%s.eps",var);
  c1->Print(stuff);

  /*
  sprintf(stuff,"effacc_%s.txt",zdef);
  FILE* stats=fopen(stuff,"wt");

  fprintf(stats," Y_min Y_max Eff*Acc\n");

  for (int i=1; i<=final->GetNbinsX(); i++) {
    fprintf(stats," %5.2f %5.2f %.5f\n",final->GetBinLowEdge(i),final->GetBinWidth(i)+final->GetBinLowEdge(i),final->GetBinContent(i)); 
  }
  fclose(stats);
  */
}
Beispiel #28
0
void forPaper_approval_2(std::string var1="h_ystar", 
			 bool logScale=false,
			 std::string datafile="darko_root/goldenWithMCerror_withJESCorr_bigmatrix_corr.root",
			 std::string mcfile1="darko_root/bare_exclusive1Jet_zPt40_both_dressed_DYToLL_M-50_1jEnh2_2jEnh35_3jEnh40_4jEnh50_7TeV-sherpa.root", 
			 std::string mcfile2="darko_root/bare_exclusive1Jet_zPt40_both_dressed_DYJetsToLL_TuneZ2_M-50_7TeV-madgraph-tauola.root", 
			 std::string mcfile3="unified_angular_distributions/rebinnings/zpt40/Z_1jet_tota_cteq66_1___1___ex_m34.root",
			 std::string var2="", 
			 std::string headertitle="Z#rightarrow ll + 1 jet",
			 std::string dataName="Data",
			 std::string mcName1="Sherpa",
			 std::string mcName2="Madgraph",
			 std::string mcName3="MCFM"
			 )
{
  
  setTDRStyle();
  gStyle->SetOptStat(0);

  const double LABELSIZE = 20.0;
  const int LINEWIDTH=3;
  const int NHISTOS=4;
  TH1F* h[NHISTOS];

  char tempName[300];
  if(var2 ==  "" )var2=var1;

  std::string xtitle;
  std::string output;
  std::string datavar;
  std::string var3;
  std::string theoryName;

  std::string remword3  ="h_";
  std::string corrName = var1;
  size_t pos3  = corrName.find(remword3);
  if(pos3!= std::string::npos)
    corrName.replace(pos3,remword3.length(),"");

  datavar = "h_combine_" + corrName;

  double ymax=1.22;
  double ymin=0.78;

  double xmax=3.0;
  double xmin=0.0;

  if(var1=="h_ystar")
    {
      var3  = "id4";
      xtitle = "Y_{dif} = |Y_{Z}-Y_{jet}| / 2";
      output = "DifYAll";
      theoryName = "Ydif";
      ymax = 1.45;
      ymin = 0.55; 
      xmax = 1.7999;
    }
  else if(var1=="h_yB")
    {
      var3 = "id3";
      xtitle = "Y_{sum} = |Y_{Z}+Y_{jet}| / 2";
      output = "SumYAll";
      theoryName = "Ysum";
      ymax = 1.45;
      ymin = 0.55;
      xmax = 2.1999;
    }
  else if(var1=="h_jety")
    {
      var3 = "id1";
      xtitle = "|Y_{jet}|";
      output = "YJetAll";
      datafile = "darko_root/goldenWithMCerror_withJESCorr_jety_bigmatrix.root";
      theoryName = "Yjet";
      xmax = 2.3999;

    }
  else if(var1=="h_zy")
    {
      var3 = "id2";
      xtitle = "|Y_{Z}|";
      output = "YZedAll";
      theoryName = "Yzed";
      xmax = 2.1999;
    }

  

  // first get the histogram files
  TFile *fdata  = TFile::Open(datafile.data());
  cout << "Opening " << fdata->GetName() << endl;

  TFile *fmc1   = TFile::Open(mcfile1.data());
  cout << "Opening " << fmc1->GetName() << endl;

  TFile *fmc2   = TFile::Open(mcfile2.data());
  cout << "Opening " << fmc2->GetName() << endl;

  TFile *fmc3   = TFile::Open(mcfile3.data());
  cout << "Opening " << fmc3->GetName() << endl;

  h[0] = (TH1F*)(fdata->Get(datavar.data()));
  h[1] = (TH1F*)(fmc1->Get(var1.data()));
  h[2] = (TH1F*)(fmc2->Get(var2.data()));
  h[3] = (TH1F*)(fmc3->Get(var3.data()));

  if(var1=="h_jety")
    {
      double value = h[3]->GetBinContent(12);
      value *= 0.9;
      h[3]->SetBinContent(12,value);
    }


  TH1D* hscale[NHISTOS];

  int COLOR[NHISTOS]={1,4,2,kOrange-1};
  int MARKERSTYLE[NHISTOS]={8,24,21,29};
  int MARKERSIZE[NHISTOS]={1,0,0,0};
  int LINESTYLE[NHISTOS]={1,1,2,6};
  int FILLSTYLE[NHISTOS]={1,3345,3436,1};

  for(int i=0; i < NHISTOS; i++){

    hscale[i]   =(TH1D*) h[0]->Clone(Form("hscale%02i",i));
    hscale[i]   ->SetYTitle(Form("Ratio to %s",mcName3.data()));
    hscale[i]   ->SetXTitle(xtitle.data());
    hscale[i]   ->GetXaxis()->SetDecimals();
    hscale[i]   ->GetYaxis()->SetDecimals();

    hscale[i]->SetLineColor(COLOR[i]);
    hscale[i]->SetLineWidth(LINEWIDTH);
    hscale[i]->SetLineStyle(1);
    hscale[i]->SetMarkerColor(COLOR[i]);
    hscale[i]->SetMarkerStyle(MARKERSTYLE[i]);
    hscale[i]->SetMarkerSize(MARKERSIZE[i]);
    hscale[i]->SetFillColor(COLOR[i]);
    hscale[i]->SetFillStyle(FILLSTYLE[i]);

    hscale[i]->SetTitle("");
    hscale[i]->SetMaximum(ymax);
    hscale[i]->SetMinimum(ymin);

    hscale[i]->SetTitleOffset(1.2,"X");
    hscale[i]->SetTitleOffset(1.2,"Y");

    h[i]->SetTitle("");
    h[i]->SetLineStyle(LINESTYLE[i]);
    h[i]->GetXaxis()->SetDecimals();
    h[i]->GetYaxis()->SetDecimals();
    h[i]->SetMarkerSize(1);
    h[i]->SetLineColor(COLOR[i]);
    h[i]->SetLineWidth(LINEWIDTH);
    h[i]->SetMarkerColor(COLOR[i]);
    h[i]->SetMarkerStyle(MARKERSTYLE[i]);
    h[i]->SetTitleOffset(1.2,"Y");

  }
  h[0]->SetLineWidth(1);
  hscale[0]->SetLineWidth(1);

  // if normalizing to the same area, set the scale 

  int binLo = -1;
  int binHi = -1;
  int nbins = h[0]->GetNbinsX();
  binLo = 1;
  binHi = nbins;

  double scaleFactor[NHISTOS]={1};

  for(int ih=0; ih < NHISTOS; ih++){
    
    double integral = h[ih]->Integral(binLo,binHi);
    scaleFactor[ih] = integral > 0? 1.0/integral: 1;
    h[ih]->Sumw2();
    h[ih]->Scale(scaleFactor[ih]);

  }

  for(int ih=0; ih < NHISTOS; ih++)
    cout << "histogram " << ih << " integral = " << h[ih]->Integral() << endl;


  // get the ratio

  for(int ih=0; ih < NHISTOS-1; ih++){
    cout << "===================================================" << endl;
    cout << "For histogram " << ih << endl;
    hscale[ih]->Divide(h[ih], h[NHISTOS-1]);
    hscale[ih]->SetMaximum(ymax);
    hscale[ih]->SetMinimum(ymin);

  } // end of loop over histograms

  vector<double> maxArray;
  maxArray.clear();
  
  for(int ih=0; ih < NHISTOS; ih++){

    h[ih]->GetXaxis()->SetRangeUser(xmin,xmax);
    hscale[ih]->GetXaxis()->SetRangeUser(xmin,xmax);
    double max_this  = h[ih]->GetBinError(h[ih]->GetMaximumBin()) + h[ih]->GetMaximum();
    maxArray.push_back(max_this);

  }


  double max = *(std::max_element(maxArray.begin(),maxArray.end()));
  cout << "Max = " << max << endl;

  for(int ih=0; ih < NHISTOS; ih++){

    h[ih]->SetMaximum(1.1*max);
    if(!logScale)
      h[ih]->SetMinimum(-0.015);
    else
      h[ih]->SetMinimum(5e-6);
  }


  //////////////////////////////////////////////////////////////////////////
  /// 
  ///   Making final figures and save the canvas in files
  ///
  //////////////////////////////////////////////////////////////////////////

  TCanvas* c1 = new TCanvas("c1","",700,1000);  
  c1->Divide(1,2,0.01,0);
  c1->cd(1);
  if(logScale)
    gPad->SetLogy(1);
  gPad->SetTopMargin(0.01);
  gPad->SetBottomMargin(0);
  gPad->SetRightMargin(0.04);
  gStyle->SetStatFontSize(0.05);

  // pad 1 and pad 2 have different sizes, need to rescale to 
  // make the label size the same
  double temp1_pad = gPad->GetWh()*gPad->GetAbsHNDC();
  cout << "pad 1 size in pixels = " << temp1_pad << endl;
  double label1_size = LABELSIZE/temp1_pad;
  for(int ih=0; ih < NHISTOS; ih++)
    {
      h[ih]->GetYaxis()->SetLabelSize(label1_size);
      h[ih]->GetXaxis()->SetLabelSize(label1_size);
    }

  h[0]->SetYTitle("1/#sigma d#sigma/dY");
  h[0]->Draw("9e1");
  for(int ih=1; ih < NHISTOS; ih++)
    h[ih]->Draw("9histsame");
  h[0]->Draw("9e1same");


  double x1NDC = 0.729812;
  double y1NDC = 0.560219;
  double x2NDC = 0.939633;
  double y2NDC = 0.871885;

  TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC);
  
  leg->SetFillColor(0);
  leg->SetFillStyle(0);
  leg->SetTextSize(0.045);
  leg->SetBorderSize(0);
  leg->SetHeader(headertitle.data());
  leg->AddEntry(h[0], dataName.data());
  leg->AddEntry(h[1], mcName1.data(),"l");
  leg->AddEntry(h[2], mcName2.data(),"l");
  leg->AddEntry(h[3], mcName3.data(),"l");
  leg->Draw("same");

  TLatex *lar = new TLatex(0.33, 0.91, "CMS Preliminary,  #sqrt{s} = 7 TeV, L_{int} = 5 fb^{-1}");
  lar->SetNDC(kTRUE);
  lar->SetTextSize(0.05);
  lar->Draw();


  TPaveText *pavetex = new TPaveText(0.17029, 
				     0.0495665, 
				     0.478939, 
				     0.483501,"NDCBR");
  pavetex->SetBorderSize(0);
  pavetex->SetFillColor(0);
  pavetex->SetFillStyle(0);
  pavetex->SetLineWidth(3);
  pavetex->SetTextAlign(12);
  pavetex->SetTextSize(0.04);
  pavetex->AddText("76 < M_{ll} < 106 GeV");
  pavetex->AddText("p_{T}^{ll} > 40 GeV"); 
  pavetex->AddText("p_{T}^{l} > 20 GeV, |#eta^{l}| < 2.1");
  pavetex->AddText("N_{jet}=1, p_{T}^{jet} > 30 GeV, |#eta^{jet}| < 2.4");
  pavetex->AddText("#Delta R(l,jet)>0.5");
  pavetex->Draw();

  cout << "pad 1 label size = " << h[0]->GetYaxis()->GetLabelSize() << endl;

  //////////////////////////////////////////////////////////////////////  

  c1->cd(2);
  gPad->SetRightMargin(0.04);
  gPad->SetTopMargin(0);
  gPad->SetBottomMargin(0.2);
  gPad->SetTickx();

  // pad 1 and pad 2 have different sizes, need to rescale to 
  // make the label size the same
  double temp2_pad = gPad->GetWh()*gPad->GetAbsHNDC();
  cout << "pad 2 size in pixels = " << temp2_pad << endl;
  double label2_size = LABELSIZE/temp2_pad;
  for(int ih=0; ih < NHISTOS; ih++)
    {
      hscale[ih]->GetYaxis()->SetLabelSize(label2_size);
      hscale[ih]->GetXaxis()->SetLabelSize(label2_size);
    }


  hscale[0]->Draw("9e1");
  for(int ih=1; ih < NHISTOS-1; ih++){
    hscale[ih]->Draw("9e3same");
  }
  hscale[0]->Draw("9e1same");

  TLine* l2 = new TLine(xmin,1.,xmax,1.);
  l2->SetLineColor(kOrange-1);
  l2->SetLineStyle(1);
  l2->Draw("same");


  TLegend* leg2 = new TLegend(0.17333,0.244648,0.392274,0.476857);
  
  leg2->SetFillColor(0);
  leg2->SetFillStyle(0);
  leg2->SetTextSize(0.04);
  leg2->SetBorderSize(0);
  leg2->AddEntry(hscale[1], "Sherpa stat. uncertainty","f");
  leg2->AddEntry(hscale[2], "Madgraph stat. uncertainty","f");
  leg2->Draw("same");


  gROOT->ProcessLine(".L ~/scripts/theoryErrorZed.c");
  theoryErrorZed(theoryName.data());

  hscale[0]->Draw("9e1same");
  for(int ih=1; ih < NHISTOS-1; ih++){
    hscale[ih]->Draw("9e3same");
  }
  hscale[0]->Draw("9e1same");
  l2->Draw("same");

  cout << "pad 2 label size = " << hscale[0]->GetYaxis()->GetLabelSize() << endl;
  
  string dirName = "forPaper";
  gSystem->mkdir(dirName.data());

  std::string filename;
  std::string psname = dirName + "/" + output;
  filename = psname + ".eps";
  c1->Print(filename.data());
  filename = psname + ".gif";
  c1->Print(filename.data());
  filename = psname + ".pdf";
  c1->Print(filename.data());
  //   c1->Close();
}
void Plotter(TString plots="2btag", bool LogScale=false, TString cat = "ttbb", TString nSyst = "btagcfI"){
 
  TString files  = "../" + dirnameIn + fl;

  /****************
        Style
  ****************/
  setTDRStyle();
  gROOT->SetStyle("Plain");
  gStyle->SetOptFit(1000);
  gStyle->SetOptStat("emruo");
  gStyle->SetOptStat(kFALSE);
  gStyle->SetPadTickY(1);
  gStyle->SetPadTickX(1);
  
  int col_Nom  = 1;
  int col_Up   = 2;
  int col_Down = 4;
  
  /****************
       Channel
  ****************/
  TString channel[3];
  channel[0] = "mujets";
  channel[1] = "ejets";  
  channel[2] = "lepjet"; 
 
  /****************
    ttbar Signal
  ****************/ 
  std::vector<histos> ttbar_Nom;
  std::vector<histos> ttbar_Up;
  std::vector<histos> ttbar_Down;

  ttbar_Nom  = loadhistogramsSys(plots, files + "_ttbar_LepJetsPowhegPythia" + cat,"central");
  ttbar_Up   = loadhistogramsSys(plots, files + "_ttbar_LepJetsPowhegPythia" + cat, nSyst + "Up");
  ttbar_Down = loadhistogramsSys(plots, files + "_ttbar_LepJetsPowhegPythia" + cat, nSyst + "Down");
  setuphistograms(ttbar_Nom,  col_Nom,   1);
  setuphistograms(ttbar_Up,   col_Up,    2);
  setuphistograms(ttbar_Down, col_Down,  3);

  
  /****************
     Draw Histos
  ****************/ 
  TCanvas *histocanvas;
  histocanvas = new TCanvas("plots", "Plots");

  for(unsigned int h=0; h<ttbar_Nom.size(); h++){
    for(int ch=0; ch<3; ch++){
      
      histocanvas->cd();
      if(LogScale) histocanvas->cd()->SetLogy();

      ttbar_Nom[h].hist[ch]->GetXaxis()->SetRange(ttbar_Nom[h].hist[ch]->GetXaxis()->GetFirst(), 
  						ttbar_Nom[h].hist[ch]->GetXaxis()->GetLast());
      //ttbar_Nom[h].hist[ch]->GetYaxis()->SetTitle("Events");
      ttbar_Nom[h].hist[ch]->GetYaxis()->SetTitleOffset(1.2);
      ttbar_Nom[h].hist[ch]->GetYaxis()->SetTitleSize(0.07);
      ttbar_Nom[h].hist[ch]->GetYaxis()->SetLabelSize(0.055);
      ttbar_Nom[h].hist[ch]->GetYaxis()->SetNdivisions(607);
      //ttbar_Nom[h].hist[ch]->GetYaxis()->SetLabelSize(0.05);
      TGaxis *hYaxis = (TGaxis*)ttbar_Nom[h].hist[ch]->GetYaxis();
      //hYaxis->SetMaxDigits(3);
      //ttbar_Nom[h].hist[ch]->GetXaxis()->SetLabelSize(0.0);
      //ttbar_Nom[h].hist[ch]->GetXaxis()->SetTitle("");
      ttbar_Nom[h].hist[ch]->GetXaxis()->SetNdivisions(509); //(402)
      ttbar_Nom[h].hist[ch]->GetXaxis()->SetTitleOffset(1.1);

      // Produce enough vertical space for the legend 
      float MaxHisto;
      if(LogScale) MaxHisto = 8.0;
      else MaxHisto = 1.4;
            float maxh;
  	    maxh = ttbar_Nom[h].hist[ch]->GetMaximum();
  	    if (maxh < ttbar_Up[h].hist[ch]->GetMaximum()) maxh = ttbar_Up[h].hist[ch]->GetMaximum();
  	    if (maxh < ttbar_Down[h].hist[ch]->GetMaximum()) maxh = ttbar_Down[h].hist[ch]->GetMaximum();
	    
      ttbar_Nom[h].hist[ch]->SetMaximum(MaxHisto*maxh);
      
      //ttbar_Nom[h].hist[ch]->SetMinimum(0.1);
      
      ttbar_Nom[h].hist[ch]->Draw("hist");
      ttbar_Up[h].hist[ch]->Draw("histSAME");
      ttbar_Down[h].hist[ch]->Draw("histSAME");
      

      //ttbar_1[h].hist[ch]->Draw("histoSAME");

      /***********************
             Legends
      ***********************/
      TLegend *leg;
      float legx1=0.70;
      float legy1=0.75;
      float legx2=0.93;
      float legy2=0.93;
      leg = new TLegend(legx1,legy1,legx2,legy2);
      leg->SetFillColor(0);
      leg->SetLineColor(1);
      leg->SetTextFont(62);
      leg->SetTextSize(0.03);

      leg->AddEntry((TObject*)0, cat + ": " + nSyst,"");
      leg->AddEntry((TObject*)0,"","");
      leg->AddEntry(ttbar_Nom[h].hist[ch],"Nom","l");
      leg->AddEntry(ttbar_Up[h].hist[ch],"Up","l");
      leg->AddEntry(ttbar_Down[h].hist[ch],"Down","l");
      //leg->AddEntry((TObject*)0,"","");
      leg->Draw("SAME");

      //-------------------------------------------------------
      // CMS Legend
      //-------------------------------------------------------
      TString htitleCMSChannel[3];
      htitleCMSChannel[0] = "#mu^{#pm}+jets channel";
      htitleCMSChannel[1] = "e^{#pm}+jets channel";
      htitleCMSChannel[2] = "l^{#pm}+jets channel";
      
      TLatex *titlePr;
      titlePr  = new TLatex(-20.,50.,"Preliminary");
      titlePr->SetNDC();
      titlePr->SetTextAlign(12);
      titlePr->SetX(0.25);
      titlePr->SetY(0.97);
      titlePr->SetTextColor(2);
      titlePr->SetTextFont(42);
      titlePr->SetTextSize(0.05);
      titlePr->SetTextSizePixels(24);
      titlePr->Draw("SAME");

      TLatex *title;
      title  = new TLatex(-20.,50.,"CMS #sqrt{s} = 13TeV, L = 36.5 fb^{-1}");
      title->SetNDC();
      title->SetTextAlign(12);
      title->SetX(0.20);
      title->SetY(0.80);
      title->SetTextFont(42);
      title->SetTextSize(0.03);
      title->SetTextSizePixels(24);
      title->Draw("SAME");
      
      TLatex *chtitle;
      chtitle  = new TLatex(-20.,50.,htitleCMSChannel[ch]);
      chtitle->SetNDC();
      chtitle->SetTextAlign(12);
      chtitle->SetX(0.20);
      chtitle->SetY(0.86);
      chtitle->SetTextFont(42);
      chtitle->SetTextSize(0.03);
      chtitle->SetTextSizePixels(24);
      chtitle->Draw("SAME");

            
      /***********************
            Save Histos
      ***********************/    
      TString dirfigname_log;
      if(LogScale) dirfigname_log = "_log";
      else dirfigname_log = "";
      TString dirfigname_pdf;
      TString dirfigname_png;
      dirfigname_pdf = "../" + dirnameIn + "figuresNomUpDown_" + fl + "/ttbbNomUpDown_" + cat + "/pdf" + dirfigname_log + "/";
      //dirfigname_png = dirnameIn + "figuresSystComp_" + fl + "/ttbb/png" + dirfigname_log + "/";
      // make a dir if it does not exist!!
      gSystem->mkdir(dirfigname_pdf,       kTRUE);
      histocanvas->SaveAs(dirfigname_pdf + nSyst + "_" + ttbar_Nom[h].hist[ch]->GetName() + ".pdf");
      //gSystem->mkdir(dirfigname_png,       kTRUE);
      //histocanvas->SaveAs(dirfigname_png + WJets[h].hist[ch]->GetName() + ".png");
      
      // clear Canvas
      histocanvas->Clear();    

    }
  }
  
} //end Plots.C
Beispiel #30
0
void Opt_ee(){
  
  
  setTDRStyle();
  //gStyle->SetPalette(1);
  
  
  TLegend *legend = new TLegend(.7, 0.7, .9, 0.9);
  legend->SetFillColor(10);
  legend->SetBorderSize(0);
  legend->SetTextSize(0.04);

  
  TFile * fnp = new TFile("/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_SKnonprompt_dilep_5_3_14.root");
  TFile * fcf = new TFile("/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_SKchargeflip_dilep_5_3_14.root");
  TFile * fmc = new TFile("/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_mc_5_3_14.root");

  TH1F* h_npcutflow= (TH1F*)fnp->Get(("SSee_DiJet/h_e1jjmass_SSee_DiJet"));
  TH1F* h_cfcutflow= (TH1F*)fcf->Get(("SSee_DiJet/h_e1jjmass_SSee_DiJet"));
  TH1F* h_mccutflow= (TH1F*)fmc->Get(("SSee_DiJet/h_e1jjmass_SSee_DiJet"));
  
  std::vector<TString> masses;
  masses.push_back("40");
  masses.push_back("50");
  masses.push_back("60");
  masses.push_back("70");
  masses.push_back("80");
  masses.push_back("90");
  masses.push_back("100");
  masses.push_back("125");
  masses.push_back("150");
  masses.push_back("175");
  masses.push_back("200");
  masses.push_back("225");
  masses.push_back("250");
  masses.push_back("275");
  masses.push_back("300");
  masses.push_back("325");
  masses.push_back("350");
  masses.push_back("375");
  masses.push_back("400");
  masses.push_back("500");
  masses.push_back("600");
  masses.push_back("700");




  std::map<TString, TH1*> histmap;
  for(unsigned int imass=0; imass < masses.size(); imass++){
    TFile * fsig = new TFile(("/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_SKHNee" + masses.at(imass) + "_nocut_5_3_14.root").Data());
    TH1* hsig =  (TH1F*)fsig->Get(("SSee_DiJet/h_e1jjmass_SSee_DiJet"));
    histmap[masses.at(imass)] =  hsig;
  }
  
  
  int i2=0;
  for(std::map<TString, TH1*>::iterator it = histmap.begin(); it != histmap.end(); it++, i2++){
    float total_sig  = it->second->Integral();
    
    float opt_sig=0.;
    float opt=0.;
    float optbkg=0.;
    int iopt=0;
    int jopt=0;    
      
    for(int i= 1; i <  h_npcutflow->GetNbinsX()+1; i++){
      for(int j=  h_npcutflow->GetNbinsX(); j > 0 ;j--){
	if( i >= j ) continue;
	float sig_cut = it->second->Integral(i, j);

	
	float tot_bkg =  h_npcutflow->Integral(i, j) + h_mccutflow->Integral(i, j); 
	//h_cfcutflow->Integral(i,  j)  + h_mccutflow->Integral(i, j);
	
	float sig_eff = sig_cut/ total_sig;

	float bkgtmp = tot_bkg + (0.28*h_npcutflow->Integral(i,  j))* (0.28*h_npcutflow->Integral(i, j));
	float denom= 1. + sqrt(bkgtmp);
	
	if(sig_eff < 0.7) continue; 
	float punzi = sig_eff/denom;
	if(punzi > opt) {
	  opt =  punzi;
	  iopt= i;
	  jopt=j;
	  opt_sig= sig_eff;
	  optbkg = tot_bkg;
	}
      } 
    }

    cout << it->first << "  cut = " << h_npcutflow->GetBinLowEdge(iopt) << " -  "  <<  h_npcutflow->GetBinLowEdge(jopt+1) << "  sigeff = " << opt_sig <<  " bkg = " << optbkg << endl;
  }
}