void vertex_distribution_dataMC() {

  bool print = false;

  TFile *file0 = TFile::Open("results/RecoRoutines_W-selection_WJetsMGZ238PU.root");
  TFile *file1 = TFile::Open("results/RecoRoutines_W-selection_dataskimnov4rereco_newJetColl.root");

  TCanvas * canvas = makeCanvas("vertexDistribution_dataMC");
  TH1D * mc = (TH1D*)file0->Get("RECO_PolPlots_50toinf/RECO_NumVerticesPerEvent");
  TH1D * data = (TH1D*)file1->Get("RECO_PolPlots_50toinf/RECO_NumVerticesPerEvent");

  mc->GetXaxis()->SetTitle("Vertex Multiplicity");
  mc->GetXaxis()->SetTitleSize(0.06);
  mc->GetXaxis()->SetLabelOffset(0.015);
  mc->GetXaxis()->SetTitleOffset(1.2);
  mc->GetXaxis()->SetRangeUser(0,10);
  mc->GetYaxis()->SetRangeUser(0,0.35);

  mc->GetYaxis()->SetTitle("Normalised");
  mc->GetYaxis()->SetTitleSize(0.06);
  mc->GetYaxis()->SetTitleOffset(0.85);

  mc->SetLineColor(kRed);
  data->SetLineColor(kBlack);

  mc->SetLineWidth(4);
  mc->SetLineStyle(2);
  data->SetLineWidth(4);
  data->SetLineStyle(1);

  leg = new TLegend(0.6426174,0.8074324,0.9010067,0.9273649,NULL,"brNDC");
  leg->AddEntry(mc,"MC","l");
  leg->AddEntry(data,"Data","l");
  leg->SetFillColor(kWhite);
  leg->SetBorderSize(0);
  leg->SetTextFont(62);

  canvas->cd();
  mc->DrawNormalized("h");
  data->DrawNormalized("sameh");
  leg->DrawClone();

  if(print) {
    canvas->Write();
  }

  file1->Close();
  file0->Close();
  return;
}
示例#2
0
// -----------------------------------------------------------------------------
//
TCanvas* createPlot( TString path, 
		     TString canvas_name, 
		     TString name, 
		     TString dirmame, 
		     int rebin, 
		     bool norm, 
		     bool log,
		     TDirectory* file )
{

  // SetSomeStyles();

  float lumi = 250.0;// 15.04;//10.9;//6.8;
 
  // Create legend
  TLegend* legend = new TLegend(0.75, 0.6, 0.99, 0.99, "", "brNDC" );
  legend->SetFillColor(0);
  legend->SetLineColor(0); 
  legend->SetShadowColor(0);
  TLatex* prelim = new TLatex(0.6,0.54,"#scale[0.8]{CMS preliminary 2010}");
  prelim->SetNDC();
  TLatex* alumi = new TLatex(0.6,.45,"#scale[0.8]{#int L dt = 35 pb^{-1}, #sqrt{s} = 7 TeV}");
  alumi->SetNDC();

  // Create canvas 
  TCanvas* aCanvas = createCanvas( canvas_name, file, log );

  // Create histogram
  TString aname("nAll");
  // TH1D* data1    = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",aname,rebin);
  // TH1D* data    = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",dirmame,rebin);
 
  TH1D* data    = getHisto( path+"", name, "tt.root", dirmame, rebin );
  TH1D* qcd     = getHisto( path+"", name, "lm1.root", dirmame, rebin );
  TH1D* w_jets  = getHisto( path+"", name, "w.root", dirmame, rebin );
  TH1D* tt_jets = getHisto( path+"", name, "tt.root", dirmame, rebin );
  TH1D* z_jets  = getHisto( path+"", name, "z.root", dirmame, rebin );
  TH1D* lm3     = getHisto( path+"", name, "lm3.root", dirmame, rebin );
  TH1D* lm1     = getHisto( path+"", name, "lm1.root", dirmame, rebin );
  TH1D* lm6     = getHisto( path+"", name, "data.root", dirmame, rebin );
  TH1D* wm     = getHisto( path+"", name, "w.root", dirmame, rebin );
  data->Scale(lumi/100.);
  qcd->Scale(lumi/100.);
  tt_jets->Scale(lumi/100);
  w_jets->Scale(lumi/100);
  //  w_jets->Scale(10);
  //  z_inv->Scale(lumi/100);
  //  lm6->Scale(lumi/100);
  lm1->Scale(lumi/100);
  lm3->Scale(lumi/100);
  z_jets->Scale(lumi/100);
  wm->Scale(lumi/100);
  // Combine Z+jets and Z->inv
  // TH1D* z_all = z_inv->Clone(); 
  //  z_all->Add(z_jets,1);
  //z_jets->Add(z_inv,1);
  TH1D* total = tt_jets->Clone();
  total->Add(w_jets);
  total->Add(z_jets);

  // total->
 
  Int_t binMax =   total->GetNbinsX();
  Double_t& err = new Double_t(0.);
  total->IntegralAndError(10,binMax ,err);
  Double_t& errW = new Double_t(0.);
  w_jets->IntegralAndError(10,binMax ,errW);
  Double_t& errtt = new Double_t(0.);
  tt_jets->IntegralAndError(10,binMax ,errtt);
  Double_t& errZ = new Double_t(0.);
  z_jets->IntegralAndError(10,binMax ,errZ);
  Double_t& errQCD = new Double_t(0.);
  qcd->IntegralAndError(10,binMax ,errQCD );


  cout  <<endl;
  //  cout << "MC:" <<  total->IntegralAndError(11,binMax ,err) <<" && " <<  w_jets->Integral(11,binMax)<<" && "<<tt_jets->Integral(11,binMax) << "&&  "<<z_jets->Integral(11,binMax)<<" && "<< "\/\ /\hline"<<endl;
  //  cout << total->IntegralAndError(0,binMax ,err) <<" & " << lm1->Integral(0,binMax) <<" & " << lm3->Integral(0,binMax)<<" & " << lm6->Integral(0,binMax)   <<"\\\\ \\hline"<<endl;
  //  cout <<"270: " <<  total->IntegralAndError(27,binMax ,err) <<" & " << lm1->Integral(27,binMax) <<" & " << lm3->Integral(27,binMax)<<" & " << lm6->Integral(27,binMax)   <<"\\\\ \\hline"<<endl;


  cout <<"250& " <<  total->IntegralAndError(6,binMax ,err) <<" & " << lm1->Integral(6,binMax) <<" & " << lm3->Integral(6,binMax)<<" & " << lm6->Integral(6,binMax)   <<"\\\\ \\hline"<<endl;
 
  // cout << "300: " <<  total->IntegralAndError(7,binMax ,err) <<" & " << lm1->Integral(7,binMax) <<" & " << lm3->Integral(7,binMax)<<" &" << lm6->Integral(7,binMax)   <<"\\\\ \\hline"<<endl;

  cout <<"350& " <<  total->IntegralAndError(8,binMax ,err) <<" & " << lm1->Integral(8,binMax) <<" & " << lm3->Integral(8,binMax)<<" & " << lm6->Integral(8,binMax)    <<"\\\\ \\hline"<<endl;

  //   cout << "400: " <<  total->IntegralAndError(9,binMax ,err) <<" & " << lm1->Integral(9,binMax) <<" & " << lm3->Integral(9,binMax)<<" & " << lm6->Integral(9,binMax)    <<"\\\\ \\hline"<<endl;

cout << "450& " <<  total->IntegralAndError(10,binMax ,err) <<" & " << lm1->Integral(10,binMax) <<" & " << lm3->Integral(10,binMax)<<" & " << lm6->Integral(10,binMax)    <<"\\\\ \\hline"<<endl;

//cout << "500: " <<   total->IntegralAndError(11,binMax ,err) <<" & " << lm1->Integral(11,binMax) <<" & " << lm3->Integral(11,binMax)<<" & " << lm6->Integral(11,binMax)    <<"\\\\ \\hline"<<endl;

  cout <<"550& " <<  total->IntegralAndError(12,binMax ,err) <<" & " << lm1->Integral(12,binMax) <<" & " << lm3->Integral(12,binMax)<<" & " << lm6->Integral(12,binMax)    <<"\\\\ \\hline"<<endl;
  /*
 cout << "MC:" <<  total->IntegralAndError(7,binMax ,err) <<" && " << lm1->Integral(7,binMax) <<" && " << lm3->Integral(7,binMax)<<" && " << lm6->Integral(6,binMax)   <<"/\/\ /\hline"<<endl;
  cout << "MC:" <<  total->IntegralAndError(8,binMax ,err) <<" && " << lm1->Integral(8,binMax) <<" && " << lm3->Integral(8,binMax)<<" && " << lm6->Integral(7,binMax)   <<"/\/\ /\hline"<<endl;
  cout << "MC:" <<  total->IntegralAndError(10,binMax ,err) <<" && " << lm1->Integral(10,binMax) <<" && " << lm3->Integral(10,binMax)<<" && " << lm6->Integral(10,binMax)   <<"/\/\ /\hline"<<endl;
 cout << "MC:" <<  total->IntegralAndError(11,binMax ,err) <<" && " << lm1->Integral(11,binMax) <<" && " << lm3->Integral(11,binMax)<<" && " << lm6->Integral(11,binMax)   <<"/\/\ /\hline"<<endl;
 cout << "MC:" <<  total->IntegralAndError(12,binMax ,err) <<" && " << lm1->Integral(12,binMax) <<" && " << lm3->Integral(12,binMax)<<" && " << lm6->Integral(12,binMax)   <<"/\/\ /\hline"<<endl;
  // cout << "MC:" << err  <<", W: " << errW<<", tt: "<<errtt << ", Z: "<<errZ<<", QCD: "<<  errQCD<< endl;
  */

  //  cout << "data:" << data->Integral() << endl;


  TH1D* hcen = total->Clone();
  TH1D* herr = total->Clone();
  
  herr->SetLineColor(kTeal+3);
  herr->SetMarkerColor(kAzure+6);
  herr->SetFillColor(kAzure+6);
  herr->SetLineWidth(3);
  
  total->SetLineWidth(3);
  total->SetFillColor(kAzure+2);
  total->SetLineColor(kAzure+2);
  total->SetFillStyle(3245);
 
  hcen->SetFillStyle(0);
  hcen->SetMarkerColor(kTeal+3);
  hcen->SetLineColor(kTeal+3);
  hcen->SetLineWidth(3);

  // Merge Z+jets and Z->inv
  bool combine = false;
  
  // Line colour and fill
  qcd->SetLineColor(kPink+4);
  qcd->SetLineWidth(3);
  tt_jets->SetLineColor(kBlue+1);
  tt_jets->SetLineWidth(3);
  
  w_jets->SetLineColor(kPink+7);
  w_jets->SetLineWidth(3);

  z_jets->SetLineWidth(3);
  z_jets->SetLineColor(kTeal-7);
  
  if ( combine ) {
    z_all->SetLineColor(kBlack);
    z_all->SetLineStyle(3);
    z_all->SetLineWidth(1);
  } else {
    data->SetLineColor(1);
    data->SetLineStyle(1);
    data->SetLineWidth(3);
    data->SetMarkerStyle(20);
    data->SetFillColor(0);
  }
  //  lm0->SetLineColor(kRed);
  //  lm0->SetLineWidth(3);
  // lm1->SetLineColor(kRed+3);
  // lm1->SetLineWidth(3);

  // Populate legend
  // legend->AddEntry( data, "tt fully leptonic/", "LP" );
   legend->AddEntry( herr, "full SM", "LP" );
    legend->AddEntry( z_jets, " Z+jets ", "LP" );
    legend->AddEntry( w_jets, " W+jets", "LP" );
    legend->AddEntry( tt_jets, " t#bar{t}", "LP" );
    //  legend->AddEntry( lm3, " SUSY LM3", "LP" );
    //   legend->AddEntry( lm1, " SUSY LM1", "LP" );
    legend->AddEntry( lm6, " data", "LP" );
    // legend->AddEntry(wm,"W Mad","lp");
    
  // Calc maximum number of entries
  double aMax = 0.;
  if( data->GetMaximum()     > aMax ) { aMax = data->GetMaximum()+data->GetBinError(data->GetMaximumBin()); }
  if ( qcd->GetMaximum()     > aMax ) { aMax = qcd->GetMaximum(); }
  //  if ( lm0->GetMaximum()     > aMax ) { aMax = lm0->GetMaximum(); }
  //  if ( lm1->GetMaximum()     > aMax ) { aMax = lm1->GetMaximum(); }
  if ( tt_jets->GetMaximum() > aMax ) { aMax = tt_jets->GetMaximum(); }  
  if ( w_jets->GetMaximum()  > aMax ) { aMax = w_jets->GetMaximum(); }  
  if ( combine ) {
    if ( z_all->GetMaximum()  > aMax ) { aMax = z_all->GetMaximum(); }  
  } else {
    //   if ( data->GetMaximum()   > aMax ) { aMax = z_inv->GetMaximum(); }  
    if ( z_jets->GetMaximum()  > aMax ) { aMax = z_jets->GetMaximum(); }  
  }

  // Calc minimum number of entries
  double aMin = 1.e12;
  if ( qcd->GetMinimum(1.e-12)     < aMin ) { aMin = qcd->GetMinimum(1.e-12); }
  //  if ( lm0->GetMinimum(1.e-12)     < aMin ) { aMin = lm0->GetMinimum(1.e-12); }
  //  if ( lm1->GetMinimum(1.e-12)     < aMin ) { aMin = lm1->GetMinimum(1.e-12); }
  if ( tt_jets->GetMinimum(1.e-12) < aMin ) { aMin = tt_jets->GetMinimum(1.e-12); }  
  if ( w_jets->GetMinimum(1.e-12)  < aMin ) { aMin = w_jets->GetMinimum(1.e-12); }  
  if ( combine ) {
    if ( z_all->GetMinimum(1.e-12)   < aMin ) { aMin = z_all->GetMinimum(1.e-12); }  
  } else {
    // if ( data->GetMinimum(1.e-12)   < aMin ) { aMin = z_inv->GetMinimum(1.e-12); }  
    if ( z_jets->GetMinimum(1.e-12)  < aMin ) { aMin = z_jets->GetMinimum(1.e-12); }  
  }

  if ( qcd ) qcd->GetYaxis()->SetTitleOffset(1.43);
  if ( qcd ) qcd->GetYaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleOffset(0.9);

 
  if ( log ) {
    if ( qcd ) herr->SetMaximum( aMax * 10. );
    //   if ( qcd ) herr->SetMinimum( aMin * 0.1 );
    if ( qcd ) herr->SetMinimum( 0.005);
  } else {
    if ( qcd ) herr->SetMaximum( aMax * 1.1 );
    //   if ( qcd ) herr->SetMinimum( aMin * 0.9 );
  if ( qcd ) herr->SetMinimum( 0.005);

  }

  /*  TPad* mainPad = new TPad("","",0.01,0.25,0.99,0.99);
  mainPad->SetNumber(1);
  mainPad->SetFillColor(0);
  // mainPad->Range(-288.2483,-2.138147,1344.235,6.918939);
  mainPad->SetFillColor(0);
  mainPad->SetBorderMode(0);
  mainPad->SetBorderSize(2);
  if ( log == true)mainPad->SetLogy();
   mainPad->SetLeftMargin(0.1765705);
  mainPad->SetRightMargin(0.05772496);
  mainPad->SetTopMargin(0.04778761);
  mainPad->SetBottomMargin(0.1256637);
  mainPad->SetFrameFillStyle(0);
  mainPad->SetFrameLineWidth(2);
  mainPad->SetFrameBorderMode(0);
  mainPad->SetFrameFillStyle(0);
  mainPad->SetFrameLineWidth(2);
  mainPad->SetFrameBorderMode(0);
  if ( log == true)mainPad->SetLogy();
  mainPad->Draw();
  TPad*  ratioPad = new TPad("","",0.01,0.01,0.99,0.25);
  ratioPad->SetNumber(2);
  ratioPad->SetFillColor(0);
  ratioPad->SetFillColor(0);
  ratioPad->SetBorderMode(0);
  ratioPad->SetBorderSize(2);
  // if ( log == true)ratioPad->SetLogy();
   ratioPad->SetLeftMargin(0.1765705);
  ratioPad->SetRightMargin(0.05772496);
  ratioPad->SetTopMargin(0.04778761);
  ratioPad->SetBottomMargin(0.1256637);
  ratioPad->SetFrameFillStyle(0);
  ratioPad->SetFrameLineWidth(2);
  ratioPad->SetFrameBorderMode(0);
  ratioPad->SetFrameFillStyle(0);
  ratioPad->SetFrameLineWidth(2);
  ratioPad->SetFrameBorderMode(0);
  //  if ( log == true)ratioPad->SetLogy();
  ratioPad->Draw();
 

  aCanvas->cd(1);
  */

  herr->GetYaxis()->SetTitle("events");


  if ( norm ) {
    if ( qcd ) qcd->DrawNormalized("Ehist");
    // if ( lm0->GetEntries() > 0. )     { lm0->DrawNormalized("hsame"); }
    if ( lm1->GetEntries() > 0. )     { lm1->DrawNormalized("hsame"); }
    if ( tt_jets->GetEntries() > 0. ) { tt_jets->DrawNormalized("hsame"); }
    if ( w_jets->GetEntries() > 0. )  { w_jets->DrawNormalized("hsame"); }
    if ( combine ) {
      if ( z_all->GetEntries() > 0. )   { z_all->DrawNormalized("hsame"); }
    } else {
      if ( data->GetEntries() > 0. )   { z_inv->DrawNormalized("hsame"); }
      if ( z_jets->GetEntries() > 0. )  { z_jets->DrawNormalized("hsame"); }
    }
  } else {
     herr->Draw("hist");
   
   
     // qcd->SetFillStyle(3240);
     // qcd->SetFillColor(kPink+4);
    // qcd->Draw("hist");
    w_jets->Draw("hSameh");
    z_jets->Draw("9Sameh");
    w_jets->Draw("9Sameh");
    tt_jets->Draw("9SAMEh");
    //data1->Draw("9SAMEh");
     //lm0->Draw("9SAMEh");
     lm1->SetLineColor(12);
     lm1->SetLineStyle(2);
     lm1->SetLineWidth(2);
     //     lm1->Draw("9SAMEh");
     lm3->SetLineColor(14);
     lm3->SetLineStyle(2);
     lm3->SetLineWidth(2);
     //  lm3->Draw("9SAMEh");
     lm6->Draw("9SAMEh");
     wm->SetLineStyle(2);
     wm->SetLineColor(kPink+7);
     // wm->Draw("9Sameh");

     // total->DrawNormalized("9E2same");
     //      data->Draw("SAMEh");
    //  tt_jets->Divide(data);
    //  tt_jets->Draw("h");
  //  data->SetLineColor(kRed);
  //  data->Draw("sameh");
     //     data1->SetLineColor(kRed);
     //  data1->Draw("9SAMEP");
  }
  
    legend->Draw();
  // prelim->Draw();
  // alumi->Draw();



  /*  TH1D* ratioBottom = total->Clone();
  TH1D* ratioTop = data->Clone();
  ratioTop->GetYaxis()->SetTitle("data / sim");
  ratioTop->Divide(ratioBottom);
  
  aCanvas->cd(1)->Update();
 
  aCanvas->cd(2);

  ratioTop->SetTitleSize(0.1, "XYZ");
  ratioTop->SetTitleOffset(0.55, "X");
  ratioTop->SetTitleOffset(0.3, "Y");
  ratioTop->SetLabelSize(0.06,"XY");
    
  // ratioTop->GetXaxis().SetRangeUser(MinX,MaxX);
  ratioTop->GetYaxis()->SetRangeUser(0.,2.0);
  ratioTop->Draw();*/
  /* TBox* unity = TBox(ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetFirst()), 0.89,ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetLast()), 1.11);
  unity->SetLineWidth(2);
   
  unity->SetLineColor(2);
  unity->SetFillColor(2);
  unity->SetFillStyle(3002);
  unity->Draw();

  */
  file->cd();
 
  aCanvas->SaveAs( std::string(canvas_name+".pdf").c_str() );
  aCanvas->Write();



  //   aCanvas->Print(".png");
 return aCanvas;

}
示例#3
0
// -----------------------------------------------------------------------------
//
TCanvas* aDrawBkgdPlots( TString path, 
			 TString canvas_name, 
			 TString name, 
			 TString dirmame, 
			 int rebin, 
			 bool norm, 
			 bool log,
			 TDirectory* file )
{

  // SetSomeStyles();

  // Create legend
  TLegend* legend = new TLegend( 0.75, 0.65, 0.92, 0.92, NULL, "brNDC" );
  legend->SetFillColor(0);
  legend->SetLineColor(0); 
  
  // Create canvas
  TCanvas* aCanvas = getaCanvas( canvas_name, file, log );
  
  // Create histograms
  TH1D* qcd     = readHist( path, name, "IC5Calo_QCD_Pythia_Merged.root", dirmame, rebin );
  TH1D* tt_jets = readHist( path, name, "IC5Calo_TTbarJets.root", dirmame, rebin );
  TH1D* w_jets  = readHist( path, name, "IC5Calo_WJets.root", dirmame, rebin );
  TH1D* z_inv   = readHist( path, name, "IC5Calo_Zinv.root", dirmame, rebin );
  TH1D* z_jets  = readHist( path, name, "IC5Calo_ZJets.root", dirmame, rebin );
  TH1D* lm0     = readHist( path, name, "IC5Calo_LM0.root", dirmame, rebin );
  TH1D* lm1     = readHist( path, name, "IC5Calo_LM1.root", dirmame, rebin );

  // Combine Z+jets and Z->inv
  TH1D* z_all = z_inv->Clone(); 
  z_all->Add(z_jets,1);

//   TH1D* z_all = 0;
//   if ( z_inv && z_jets ) { 
//     z_all = z_inv->Clone(); 
//     z_all->Add(z_jets,1);
//   } else if ( z_inv ) { 
//     z_all = z_inv->Clone(); 
//   } else if ( z_jets ) { 
//     z_all = z_jets->Clone(); 
//   }
  
  // Select Z+jets and Z->inv separate or not
  bool combine = true;
  
  // Line colour and fill
  if ( qcd ) qcd->SetLineColor(kGreen+2);
  if ( qcd ) qcd->SetFillColor(kGreen+2);
  if ( qcd ) qcd->SetFillStyle(3003);
  if ( tt_jets ) tt_jets->SetLineColor(kBlue);
  if ( tt_jets ) tt_jets->SetLineStyle(1);
  if ( tt_jets ) tt_jets->SetLineWidth(1);
  w_jets->SetLineColor(kBlue);
  w_jets->SetLineStyle(3);
  w_jets->SetLineWidth(1);
  if ( combine ) {
    z_all->SetLineColor(kBlack);
    z_all->SetLineStyle(3);
    z_all->SetLineWidth(1);
  } else {
    z_inv->SetLineColor(kBlack);
    z_inv->SetLineStyle(1);
    z_inv->SetLineWidth(1);
    z_jets->SetLineColor(kBlack);
    z_jets->SetLineStyle(3);
    z_jets->SetLineWidth(1);
  }
  lm0->SetLineColor(kRed);
  lm0->SetLineStyle(1);
  lm0->SetLineWidth(2);
  lm1->SetLineColor(kRed);
  lm1->SetLineStyle(3);
  lm1->SetLineWidth(2);

  // Populate legend
  legend->AddEntry( qcd, " QCD", "f" );
  legend->AddEntry( lm0, " SUSY LM0", "L" );
  legend->AddEntry( lm1, " SUSY LM1", "L" );
  legend->AddEntry( tt_jets, " t#bar{t}+jets", "L" );
  legend->AddEntry( w_jets, " W+jets", "L" );
  if ( combine ) {
    legend->AddEntry( z_all, " Z", "L" );
  } else {
    legend->AddEntry( z_jets, " Z+jets", "L" );
    legend->AddEntry( z_inv, " Z#rightarrow#nu#nu", "L" );
  }

  // Calc maximum number of entries
  double aMax = 0.;
  if ( qcd->GetMaximum()     > aMax ) { aMax = qcd->GetMaximum(); }
  if ( lm0->GetMaximum()     > aMax ) { aMax = lm0->GetMaximum(); }
  if ( lm1->GetMaximum()     > aMax ) { aMax = lm1->GetMaximum(); }
  if ( tt_jets->GetMaximum() > aMax ) { aMax = tt_jets->GetMaximum(); }  
  if ( w_jets->GetMaximum()  > aMax ) { aMax = w_jets->GetMaximum(); }  
  if ( combine ) {
    if ( z_all->GetMaximum()  > aMax ) { aMax = z_all->GetMaximum(); }  
  } else {
    if ( z_inv->GetMaximum()   > aMax ) { aMax = z_inv->GetMaximum(); }  
    if ( z_jets->GetMaximum()  > aMax ) { aMax = z_jets->GetMaximum(); }  
  }

  // Calc minimum number of entries
  double aMin = 1.e12;
  if ( qcd->GetMinimum(1.e-12)     < aMin ) { aMin = qcd->GetMinimum(1.e-12); }
  if ( lm0->GetMinimum(1.e-12)     < aMin ) { aMin = lm0->GetMinimum(1.e-12); }
  if ( lm1->GetMinimum(1.e-12)     < aMin ) { aMin = lm1->GetMinimum(1.e-12); }
  if ( tt_jets->GetMinimum(1.e-12) < aMin ) { aMin = tt_jets->GetMinimum(1.e-12); }  
  if ( w_jets->GetMinimum(1.e-12)  < aMin ) { aMin = w_jets->GetMinimum(1.e-12); }  
  if ( combine ) {
    if ( z_all->GetMinimum(1.e-12)   < aMin ) { aMin = z_all->GetMinimum(1.e-12); }  
  } else {
    if ( z_inv->GetMinimum(1.e-12)   < aMin ) { aMin = z_inv->GetMinimum(1.e-12); }  
    if ( z_jets->GetMinimum(1.e-12)  < aMin ) { aMin = z_jets->GetMinimum(1.e-12); }  
  }

  if ( qcd ) qcd->GetYaxis()->SetTitleOffset(1.43);
  if ( qcd ) qcd->GetYaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleOffset(0.9);

  if ( log ) {
    if ( qcd ) qcd->SetMaximum( aMax * 10. );
    if ( qcd ) qcd->SetMinimum( aMin * 0.1 );
  } else {
    if ( qcd ) qcd->SetMaximum( aMax * 1.1 );
    if ( qcd ) qcd->SetMinimum( aMin * 0.9 );
  }

  if ( norm ) {
    if ( qcd ) qcd->DrawNormalized("Ehist");
    if ( lm0->GetEntries() > 0. )     { lm0->DrawNormalized("hsame"); }
    if ( lm1->GetEntries() > 0. )     { lm1->DrawNormalized("hsame"); }
    if ( tt_jets->GetEntries() > 0. ) { tt_jets->DrawNormalized("hsame"); }
    if ( w_jets->GetEntries() > 0. )  { w_jets->DrawNormalized("hsame"); }
    if ( combine ) {
      if ( z_all->GetEntries() > 0. )   { z_all->DrawNormalized("hsame"); }
    } else {
      if ( z_inv->GetEntries() > 0. )   { z_inv->DrawNormalized("hsame"); }
      if ( z_jets->GetEntries() > 0. )  { z_jets->DrawNormalized("hsame"); }
    }
  } else {
    if ( qcd ) qcd->Draw("h");
    lm0->Draw("sameH");
    lm1->Draw("sameH");
    if ( tt_jets ) tt_jets->Draw("sameh");
    w_jets->Draw("sameH");
    if ( combine ) {
      z_all->Draw("sameH");
    } else {
      z_inv->Draw("sameH");
      z_jets->Draw("sameH");
    }
  }
  
  file->cd();
  legend->Draw("same");
  aCanvas->Write();
  return aCanvas;

}
示例#4
0
文件: GenVBoson.C 项目: CMSRA1/bryn
GenVBosonPlot(TString name, int rebin,float min = -1,float max =0, bool log=false){

  //  TCanvas* aCan = new TCanvas(name,name,0.6,0.6,0.8,0.8);

  TCanvas* aCan = new TCanvas(name);
  aCan->Divide(2,1);
  aCan->cd(1);
  if(log) aCan->SetLogy();
  // int rebin= 10;
  TFile* W = new TFile("results5/IC5Calo_WJets_madgraph.root");
  //W->ls();
  TDirectory* Wdir = ( TDirectory*) W->Get("GenVBoson200");
  Wdir->ls();
  TH1D* Wh = (TH1D*) Wdir->Get(name);
  Wh->Rebin(rebin);
  Wh->SetLineWidth(2);
  Wh->SetLineStyle(2);
  //  Wh->
  if(min>-.2)  Wh->GetXaxis()->SetRangeUser(min,max);
 
  Wh->DrawNormalized();
  //cout << Wh->GetMaximum() <<endl;
  Wh->GetXaxis()->SetRangeUser(0.00001,1);

  //  Wh->SetMaximum( Wh->GetMaximum()*1.75);


  TFile* Z = new TFile("results5/IC5Calo_Zinvisible_jets.root");
  //Z->ls();
  TDirectory* Zdir = ( TDirectory*) Z->Get("GenVBoson200");
  //  Zdir->ls();
  TH1D* Zh = (TH1D*) Zdir->Get(name);
  Zh->SetLineColor(kRed);
  Zh->SetLineWidth(2);
  Zh->SetLineStyle(2);

  Zh->Rebin(rebin);
  Zh->DrawNormalized("same");

  TFile* Ph = new TFile("results5/photon.root");
  Ph->ls();
  TDirectory* Phdir = ( TDirectory*) Ph->Get("GenVBoson200");
  // Phdir->ls();
  TH1D* Phh = (TH1D*) Phdir->Get(name);
  Phh->SetLineColor(kBlue);
  Phh->SetLineWidth(2);
  Phh->Rebin(rebin);
  Phh->DrawNormalized("same"); 

  TLegend* leg = new TLegend(0.5,0.5,0.7,0.7);
  leg->AddEntry(Zh,"Z","l" );
  leg->AddEntry(Wh,"W","l" );
  leg->AddEntry(Phh,"#gamma","l" );
  leg->Draw("same");

  aCan->cd(1);

  TH1D*  DivPhh = Phh->Clone();
  DivPhh->Divide(Zh);
  TH1D*  DivWh = Wh->Clone();
  DivWh->Divide(Zh);
  DivPhh->Draw();
DivWh->Draw("same");

}
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");

}
示例#6
0
void plot_TauTemplate(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();
  gROOT->LoadMacro("CMS_lumi_v2.C");

  
  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);

  //
  
  TFile *file_08TeV         = new TFile("tauTemplatesRes_8TeV.root","R"); 
  TFile *file_13TeV         = new TFile("HadTau_TauResponseTemplates_TTbar_.root","R"); 
  //TFile *file_13TeV_Koushik = new TFile("HadTau_TauResponseTemplates_PHYS14_13TeV.root","R"); 
  TFile *file_TauGan        = new TFile("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->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();

  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");
    }
  }
  }

  catLeg1->Draw();  

  c1->Print("Plot_TauTemplate_TTbar.pdf");

}
示例#7
0
void PurityFit::fit(){
    string signame   ="ChargedHiggsQCDPurity/Vars/Uperp_pt%.0f_%.0f_IsoInv_Data";
    string bkgname   ="ChargedHiggsQCDPurity/Vars/Uperp_pt%.0f_%.0f_%s";
    string bkgnameInv="ChargedHiggsQCDPurity/Vars/Uperp_pt%.0f_%.0f_IsoInv_%s";
    string targetname="ChargedHiggsQCDPurity/Vars/Uperp_pt%.0f_%.0f_Data";

    vector<string> bkglabels;
        bkglabels.push_back("WJets");
        //bkglabels.push_back("TTJets");
        bkglabels.push_back("WW");
        bkglabels.push_back("WZ");
        bkglabels.push_back("ZZ");
        bkglabels.push_back("DY");

    // reset output file
    TFile *fOut= TFile::Open(outname.c_str(),"RECREATE");
    fOut->Close();

    ofstream  fw;
    fw.open("R.txt");
    fw <<"# QCD R-factor computed by PurityFit"<<endl;

    for (size_t iBin=0;iBin+1<PtBins.size() ;++iBin)
    {
        TCanvas *cEWK= new TCanvas(Form("EWK_control_pt%.0f_%.0f",PtBins[iBin],PtBins[iBin+1] ));
        TCanvas *cQCD= new TCanvas(Form("QCD_control_pt%.0f_%.0f",PtBins[iBin],PtBins[iBin+1] ));

        if (verbose_ >0 ) cout <<"[PurityFit]::[fit]::[INFO] Getting histogram: '"<< Form(targetname.c_str(),PtBins[iBin],PtBins[iBin+1])<<"'" <<endl;
        TH1D *h   = (TH1D*) fIn_ -> Get( Form(targetname.c_str(), PtBins[iBin],PtBins[iBin+1])  ) -> Clone();  // EWK
        if (verbose_ >0 ) cout <<"[PurityFit]::[fit]::[INFO] Getting histogram: '"<< Form(signame.c_str(),PtBins[iBin],PtBins[iBin+1])<<"'" <<endl;
        TH1D *sig = (TH1D*) fIn_ -> Get( Form(signame.c_str(), PtBins[iBin],PtBins[iBin+1]) ) -> Clone();// QCD
       
        if ( h != NULL and sig != NULL and h->Integral() >0 and sig->Integral() >0)  // control plots QCD
        {
            cQCD->cd();

            sig->DrawNormalized("P");

            if (verbose_ >0 ) cout <<"[PurityFit]::[fit]::[INFO] Getting histogram: '"<<Form(bkgname.c_str(),PtBins[iBin],PtBins[iBin+1],"QCD")<<"'" <<endl;
            TH1D * qcd = (TH1D*)  fIn_ ->Get( Form( bkgname.c_str() , PtBins[iBin],PtBins[iBin+1],"QCD") );
            if (verbose_ >0 ) cout <<"[PurityFit]::[fit]::[INFO] Getting histogram: '"<<Form(bkgnameInv.c_str(),PtBins[iBin],PtBins[iBin+1],"QCD")<<"'" <<endl;
            TH1D * qcdInv = (TH1D*)  fIn_ ->Get( Form( bkgnameInv.c_str() , PtBins[iBin],PtBins[iBin+1],"QCD") ) ;
            sig->SetMarkerStyle(20);
            qcd->SetLineColor(kRed+2);
            qcdInv->SetMarkerColor(kRed);
            qcdInv->SetLineColor(kRed);
            qcdInv->SetMarkerStyle(21);
            
            if (qcd->Integral() >0 ) qcd->DrawNormalized("HIST SAME");
            if (qcdInv->Integral() > 0 ) qcdInv->DrawNormalized("P SAME");
            TLegend *l = new TLegend(0.6,.6,.9,.9);
            l->SetFillStyle(0);
            l->SetBorderSize(0);
            l->AddEntry(sig,"Data InvIso");
            l->AddEntry(qcd,"QCD DirectIso");
            l->AddEntry(qcdInv,"QCD InvIso");
            l->Draw();
            cQCD->Update();

            // Open and close. Don't leave files open, otherwise root will write stuff inside
            fOut = TFile::Open(outname.c_str(),"UPDATE");
            fOut->cd();
            cQCD->Write();
            fOut->Close();

            delete cQCD;
        }
        //else { cout << "NO QCD Control plots"<<endl; }  //DEBUG

        cEWK->cd() ;
        TLegend *l =new TLegend(0.6,.6,.9,.9);
        l->SetFillStyle(0);
        l->SetBorderSize(0);

        ///-----
        //NegativeWeightInterpolator n;
        //n.print();
        // ----

        TH1D *bkg= NULL;
        for (string& s : bkglabels)
        {
            TH1D *bkg_tmp = (TH1D*)  fIn_ ->Get( Form( bkgname.c_str() , PtBins[iBin],PtBins[iBin+1],s.c_str()) );
            TH1D *bkg_binned = NULL;
            //if ( s== "WJets" or s=="DY" )
            //{
            //    bkg_binned = bkg_tmp;
            //    TH1D*pos = static_cast<TH1D*>(fIn_ ->Get( Form( (bkgname+ "_wPlus").c_str() , PtBins[iBin],PtBins[iBin+1],s.c_str()) ));
            //    TH1D*neg = static_cast<TH1D*>(fIn_ ->Get( Form( (bkgname+ "_wMinus").c_str() , PtBins[iBin],PtBins[iBin+1],s.c_str()) ));
            //    bkg_tmp = static_cast<TH1D*>(n.add(pos,neg));
            //}

            if ( bkg_tmp == NULL )  cout <<"[PurityFit]::[fit]::[ERROR] histo "<<  Form( bkgname.c_str() , PtBins[iBin],PtBins[iBin+1],s.c_str()) << " is NULL"<<endl;

            bool first = false;
            if (bkg==NULL) {
                bkg = (TH1D*) bkg_tmp->Clone( Form( bkgname.c_str(), PtBins[iBin],PtBins[iBin+1], "EWK") );
                first = true;
                }
            else bkg->Add(bkg_tmp);
      
            // control plots EWK
            if (s == "DY") { bkg_tmp->SetLineColor(kCyan);}// bkg_binned->SetLineColor(kCyan); } 
            else if (s == "TTJets") bkg_tmp->SetLineColor(kMagenta+2);
            else if (s == "WJets" ) { bkg_tmp->SetLineColor(kGreen+2);}// bkg_binned -> SetLineColor(kGreen+2);}
            else if (s == "WW"  )  bkg_tmp->SetLineColor(kRed);
            else if (s == "WZ"  )  bkg_tmp->SetLineColor(kRed+2);
            else if (s == "ZZ"  )  bkg_tmp->SetLineColor(kRed-4);
            else                   bkg_tmp->SetLineColor(kGray);
            l->AddEntry(bkg_tmp,s.c_str());

            if (first) bkg_tmp->Draw("HIST");
            else bkg_tmp->Draw("HIST SAME");

            if (bkg_binned) bkg_binned -> Draw("HIST SAME");

        } // labels loop
        
        l->Draw();
        cEWK->Update();
        fOut = TFile::Open(outname.c_str(),"UPDATE"); // don't leave them open. Root will try to use them.
        fOut->cd();
        cEWK->Write();
        fOut->Close(); // close for the fit_specific

        delete cEWK;
    
        map<string,float> pars; 

        float hI= h->Integral();
        float sI= sig->Integral();

        float f = fit_specific( h, sig, bkg, Form("fit_pt%.0f_%.0f",PtBins[iBin],PtBins[iBin+1] ), outname, &pars);

        // propagate the fraction to the yields
        float R = f * hI / sI;
        float Rhi = pars["fracErrorHigh"] * hI / sI;
        float Rlo = pars["fracErrorLow"] * hI / sI;

        //  INFO
        cout <<"pt "<<PtBins[iBin]<<" "<<PtBins[iBin+1]
            << " frac "<<f <<" +"<<pars["fracErrorHigh"]<< " -"<< pars["fracErrorLow"]
            << " R "<< R <<" +"<<Rhi<<" -"<<Rlo
            <<endl;
        //  for SF DB
        fw <<"tauinviso pteta "<<PtBins[iBin]<<" "<<PtBins[iBin+1]<< " -2.1 2.1 "<<R<<" "<< (Rhi + Rlo)/2.0<<endl;

    } // bin loop

}
int main(int argc, char** argv){

  TString chfile;
  TString chfileref;
  TString DirectoryLast;
  TString labelData;
  TString labelRef;


  int ntrueargs = 0;
  bool logyFlag = true;
  bool normalize = false;

  for (int i=1; i<argc; ++i) {
      if (argv[i][0] == '-') {
            if (argv[i][1]=='l') logyFlag = false;
            else if (argv[i][1]=='b') gROOT->SetBatch();
            else if (argv[i][1]=='h') return printUsage();
            else if (argv[i][1]=='n') normalize=true;
            else if (argv[i][1]=='D') labelData = argv[i+1];
            else if (argv[i][1]=='R') labelRef= argv[i+1];

      } else {
            ntrueargs += 1;
            if (ntrueargs==1) chfile = argv[i];
            else if (ntrueargs==2) chfileref = argv[i];
            else if (ntrueargs==3) DirectoryLast = argv[i];
      }
  }

  if (ntrueargs<3) return printUsage();

  TRint* app = new TRint("CMS Root Application", 0, 0);

  TString cmssw_version = gSystem->Getenv("CMSSW_VERSION");
  TString chsample = "EWKMu";
  TString chtitle = chsample + " validation for " + cmssw_version;




  //TCanvas* c1 = new TCanvas("c1",chtitle.Data());
  TCanvas* c1 = new TCanvas("c1",chtitle.Data(),0,0,1024,768);
  c1->SetFillColor(0);
  TPaveLabel* paveTitle = new TPaveLabel(0.1,0.93,0.9,0.99, chtitle.Data());
  paveTitle->Draw();
  paveTitle->SetFillColor(0);
  gStyle->SetOptLogy(logyFlag);
  gStyle->SetPadGridX(true);
  gStyle->SetPadGridY(true);
  gStyle->SetOptStat(0);
//  gStyle->SetFillColor(0);

  TPad* pad[4];
  pad[0] = new TPad("pad_tl","The top-left pad",0.01,0.48,0.49,0.92);
  pad[0]->SetFillColor(0); 
  pad[1] = new TPad("pad_tr","The top-right pad",0.51,0.48,0.99,0.92); 
  pad[1]->SetFillColor(0);
  pad[2] = new TPad("pad_bl","The bottom-left pad",0.01,0.01,0.49,0.46); 
  pad[2]->SetFillColor(0);
  pad[3] = new TPad("pad_br","The bottom-right pad",0.51,0.01,0.99,0.46); 
  pad[3]->SetFillColor(0);

  for (unsigned int i=0; i<4; ++i) pad[i]->Draw();
                                                                                
  TLegend* leg = new TLegend(0.6041667,0.7487715,0.9861111,0.9576167);
  leg->SetFillColor(0);
  TFile* input_file = new TFile(chfile.Data(),"READONLY");
  TFile* input_fileref = new TFile(chfileref.Data(),"READONLY");
  bool first_plots_done = false;

  TString directory = DirectoryLast + "/BeforeCuts";

  TDirectory* dir_before = input_file->GetDirectory(directory);
  TDirectory* dirref_before = input_fileref->GetDirectory(directory);
  TList* list_before = dir_before->GetListOfKeys();
  list_before->Print();

  unsigned int list_before_size = list_before->GetSize();
  TString auxTitle = chtitle + ": BEFORE CUTS";
  for (unsigned int i=0; i<list_before_size; i+=4) {
      if (first_plots_done==true) c1->DrawClone();
      paveTitle->SetLabel(auxTitle.Data());
      for (unsigned int j=0; j<4; ++j) {
            pad[j]->cd(); 
            pad[j]->Clear(); 
            if ((i+j)>=list_before_size) continue;

            TH1D* h1 = (TH1D*)dir_before->Get(list_before->At(i+j)->GetName()); 
//            h1->SetLineColor(kBlue);
//            h1->SetMarkerColor(kBlue);
            h1->SetMarkerStyle(21);
            h1->SetLineStyle(1);
            h1->SetLineWidth(3);
            h1->SetTitleSize(0.05,"X");
            h1->SetTitleSize(0.05,"Y");
            TString title=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetTitle();
            TString name=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetName(); 
            TString nameD =name+"_MC";
            h1->SetXTitle(title);
            h1->SetName(nameD);

            h1->SetYTitle("");
            h1->SetTitle(""); 
            h1->SetTitleOffset(0.85,"X");

            TH1D* hr = (TH1D*)dirref_before->Get(list_before->At(i+j)->GetName()); 
            hr->SetLineColor(kPink-4);
//            hr->SetLineStyle(2);
            hr->SetLineWidth(3);
            hr->SetTitleSize(0.05,"X");
            hr->SetTitleSize(0.05,"Y");
            hr->SetFillColor(kPink-4);
            hr->SetFillStyle(3001);
            hr->SetXTitle(title);
            TString nameMC =name+"_Data";
            h1->SetName(nameMC);

            hr->SetYTitle("");
            hr->SetTitle("");
            hr->SetTitleOffset(0.85,"X");



            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
            else{hr->Draw("hist");}
            h1->Draw("sames,p,E");
            
            int max1=h1->GetMaximum();
            int maxr=hr->GetMaximum();
            if(!normalize){
            if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);}
            else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);}
            }
            else if (normalize){
            hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2);
            }


            leg->Clear();
            leg->AddEntry(h1,labelData.Data(),"Lp");
            leg->AddEntry(hr,labelRef.Data() ,"f");

            leg->Draw();




      }
      first_plots_done = true;
      c1->Modified();
      c1->Update();
      char chplot[80];
      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
  }

  TString directory2 = DirectoryLast + "/LastCut";

  TDirectory* dir_lastcut = input_file->GetDirectory(directory2);
  TDirectory* dirref_lastcut = input_fileref->GetDirectory(directory2);
  TList* list_lastcut = dir_lastcut->GetListOfKeys();
  list_lastcut->Print();

  unsigned int list_lastcut_size = list_lastcut->GetSize();
  auxTitle = chtitle + ": AFTER N-1 CUTS";
  for (unsigned int i=0; i<list_lastcut_size; i+=4) {
      if (first_plots_done==true) c1->DrawClone();
      paveTitle->SetLabel(auxTitle.Data());
      for (unsigned int j=0; j<4; ++j) {
            pad[j]->cd(); 
            pad[j]->Clear(); 
            if ((i+j)>=list_lastcut_size) continue;

            TH1D* h1 = (TH1D*)dir_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
//            h1->SetLineColor(kBlue);
//            h1->SetMarkerColor(kBlue);
            h1->SetMarkerStyle(21);
            h1->SetLineWidth(3);
            h1->SetTitleSize(0.05,"X");
            h1->SetTitleSize(0.05,"Y");
            TString name=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetName();
            TString title=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetTitle();
            TString nameD=name+"_Data";
            h1->SetXTitle(title); 
            h1->SetName(nameD);
            h1->SetYTitle("");
            h1->SetTitle(""); 
            h1->SetTitleOffset(0.85,"X");

            TH1D* hr = (TH1D*)dirref_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
            hr->SetLineColor(kAzure+5);
//            hr->SetLineStyle(2);
            hr->SetLineWidth(3);
            hr->SetTitleSize(0.05,"X");
            hr->SetTitleSize(0.05,"Y");
            hr->SetFillColor(kAzure+5);
            hr->SetFillStyle(3001);
            hr->SetXTitle(title);
            TString nameMC=name+"_Data";
            h1->SetName(nameMC);
            hr->SetYTitle("");
            hr->SetTitle("");
            hr->SetTitleOffset(0.85,"X");


            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
            else{hr->Draw("hist");}
            h1->Draw("sames,p,E");

            int max1=h1->GetMaximum();
            int maxr=hr->GetMaximum();
            if(!normalize){
            if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);}
            else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);}
            }
            else if (normalize){
            hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2);
            }
            

            leg->Clear();
            leg->AddEntry(h1,labelData.Data(),"lp");
            leg->AddEntry(hr,labelRef.Data(),"f");
            leg->Draw();
      }
      first_plots_done = true;
      c1->Modified();
      c1->Update();
      char chplot[80];
      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
  }

  if (!gROOT->IsBatch()) app->Run();

  return 0;
}
示例#9
0
void massSubtraction(){



  //TFile* opFile = new TFile("./pairQA/qa_9_9_invMass.root");
  TFile* opFile = new TFile("~/Desktop/Research/2012IFF/rootFiles/qa_9_9_invMass.root");
  
  TH1D* hOpMass = (TH1D*)opFile->Get("invarM");
  
//  double opInt = hOpMass->GetIntegral();
    double opInt = hOpMass->GetEntries();
  
  cout << hOpMass->GetEntries() << "  " << hOpMass->GetIntegral() << endl;
  
  
  //TFile* sameFile = new TFile("./pairQA/sameSign_4_14_InvarMassRad03.root");
  TFile* sameFile = new TFile("~/Desktop/Research/2012IFF/rootFiles/sameSign_4_14_InvarMassRad03.root");

  TH1D* hSameMass = (TH1D*)sameFile->Get("invarM");

//  double sameInt = hSameMass->GetIntegral();
    double sameInt = hSameMass->GetEntries();
  
  cout << hSameMass->GetEntries() << "  " << hSameMass->GetIntegral() << endl;
  
  
  /*
  hOpMass->DrawNormalized();
  hSameMass->DrawNormalized("Same");
  hSameMass->SetLineColor(kRed);
  //*/
  
  
  TH1D* hdiff = new TH1D("hdiff","hdiff",800,0,5);

  //hdiff->Add(hSameMass, hOpMass, -1/sameInt, 1/opInt);
  //hdiff->Add(hSameMass, -1/sameInt);
  hdiff->Add(hOpMass, 1/opInt);
  hdiff->Add(hSameMass, -1/sameInt);

  //hOpMass->Add(hSameMass, -1*opInt/sameInt);
  
  //hOpMass->Draw();
  hdiff->Draw();

  TCanvas* c2 = new TCanvas();
  hOpMass->SetLineColor(1);
  hOpMass->DrawNormalized();
  hSameMass->SetLineColor(2);
  hSameMass->DrawNormalized("same");
  
  


  
  
  
  
  
  
  
  
  
  
  
  

}