Example #1
0
void banner4Plot (){
  TPaveText* pt ;
  pt = new TPaveText(.14,0.91,.25,.94,"NDC");
  pt->AddText("Preliminary");
  pt->SetFillColor(0);
  pt->SetTextSize(0.035);
  pt->SetFillStyle(0);
  pt->SetLineColor(0);
  pt->SetLineWidth(0);
  pt->SetMargin(0);
  pt->SetShadowColor(0);
  pt->Draw();
}
Example #2
0
void plottingmacro_IVF()
{


  double fa = 0.46502;
  double fb = 0.53498;
  bool debug_ = true;

  //  std::string path("Nov10thFall11Plots/");
  //  std::string path("Nov10Fall1160MTopSlimPlots/");
  std::string path("Nov10Fall1160MTopIVFPlots_b/");

  if(debug_)
    std::cout << "Init the style form setTDRStyle" << std::endl;
  setTDRStyle();
  gStyle->SetErrorX(0.5);
  gROOT->ForceStyle();
  initOptions();
  

  if(debug_)
    std::cout << "Init the sample" << std::endl;
  //  std::vector<Sample> s = Nov10thDiJetPtUpdatedSlimHistos();
  //std::vector<Sample> s = Nov10Fall1160MTopSlimHistos();
  std::vector<Sample> s = Nov10Fall1160MTopIVFHistos();

  Sample data(1,"fake data","S1.root",0,true,1000);

  if(debug_)
    std::cout << "Init the data sample" << std::endl;
  for(size_t i=0;i< s.size();i++) if(s[i].data) {data=s[i];break;}

  if(debug_)
    std::cout << "Ls data sample" << std::endl;
  data.file()->ls(); 

  if(debug_)
    std::cout << "Init the mc sample" << std::endl;
  for(size_t i=0;i< s.size();i++) s[i].dump(1,fa,fb);

  std::vector<std::string> names;

  if(debug_)
    std::cout << "Get List of Keys" << std::endl;
  TList * subs = data.file()->GetListOfKeys();
  for(size_t i=0;i< subs->GetSize();i++)
    {
      TString nn = subs->At(i)->GetName();
      if( nn.Contains(TRegexp("Count*")) )
	continue;
      if(debug_)
	std::cout << "Get List of Keys in subdirs" << std::endl;
      TList * objs = ((TDirectoryFile *)data.file()->Get(subs->At(i)->GetName()))->GetListOfKeys();
      for(size_t j=0;j< objs->GetSize();j++)
	{
	  if(debug_)
	    std::cout << "Name = " << subs->At(i)->GetName()+std::string("/")  + objs->At(j)->GetName() << std::endl;
	  names.push_back(subs->At(i)->GetName()+std::string("/")  + objs->At(j)->GetName());
	  //      std::cout << subs->At(i)->GetName() << "/"  << objs->At(j)->GetName() << std::endl;
	  //TODO: select plots via regexp
	}
    }


  if(debug_)
    std::cout << "Starting plotting" << std::endl;

  std::string process;

  for(size_t i = 0 ; i < names.size() ; i++) 
    {
      
      std::map<std::string,TH1F *> grouped;
      TString n=names[i];
      //      if(!n.Contains(TRegexp("VlightRegionHZee/HiggsPtVlightRegionHZee"))) continue;
      //      if(!n.Contains(TRegexp("VlightRegionHZee/ZPtVlightRegionHZee"))) continue;
      //      if(!n.Contains(TRegexp("VlightRegionHZee"))) continue;
      //      if(!n.Contains(TRegexp("ZSVRegionZmmSV"))) continue;
      //      if(!n.Contains(TRegexp("ZSVRegionZeeSV"))) continue;
      //      if(!n.Contains(TRegexp("ZSVRegionZcombSV"))) continue;
      //      if(!n.Contains(TRegexp("ZSVPureRegionZcombSV"))) continue;
      //      if(!n.Contains(TRegexp("ZSVTTbarPureRegionZcombSV"))) continue;
      if(!n.Contains(TRegexp("TTbarRegionZeeSVJets"))) continue;

      if(n.Contains(TRegexp("RegionHZcomb")))
	process = "Z(l^{+}l^{-})H(b#bar{b})";
      if(n.Contains(TRegexp("RegionHZmm")))
	process = "Z(#mu^{+}#mu^{-})H(b#bar{b})";
      if(n.Contains(TRegexp("RegionHZee")))
	process = "Z(e^{+}e^{-})H(b#bar{b})";

      if(debug_)
	std::cout << "Creating the Canvas" << std::endl;

      TCanvas *c = new TCanvas();
      c->SetLogy(false);
      c->SetTitle(names[i].c_str());

      if(debug_)
	std::cout << "Creating histograms" << std::endl;
  
      TH1F *hd = ((TH1F*)data.file()->Get(names[i].c_str()));
      hd->Sumw2();
      Options o=options[names[i]];
      //      hd->Rebin(o.rebin);
      hd->SetMarkerStyle(20);
      hd->GetXaxis()->SetLabelOffset(99);
      hd->SetYTitle(o.yaxis.c_str());
      double nbin = hd->GetNbinsX();
      double min_bin = hd->GetXaxis()->GetXmin();
      double max_bin = hd->GetXaxis()->GetXmax();
      TH1F *hmc = new TH1F("hmc","hmc", nbin, min_bin, max_bin);
      hmc->SetFillColor(kWhite);
      hmc->Sumw2();
      //      hmc->Rebin(o.rebin);

      if(debug_)
	std::cout << "Creating the THStack and Legend" << std::endl;
      THStack * sta = new THStack("sta",hd->GetTitle());
      TLegend * l = new TLegend(o.legendx1,o.legendy1,o.legendx2,o.legendy2); //0.7,0.1,0.9,0.6);
      l->SetFillColor(kWhite);
      l->SetBorderSize(0);
      l->SetTextFont(62);
      l->SetTextSize(0.03);
      if(debug_)
	std::cout << "Adding data to the legend" << std::endl;  
      l->AddEntry(hd, "Data","P");
      if(debug_)
	std::cout << "Adding MC to the THStack" << std::endl;  

      //with the proper trigger eff
      //      double SF[] = {1.01,1.03,1.00};
      //      double SF[] = {1.03,1.054,1.032};
      double SF[] = {1.0,1.0,1.0};

      if(debug_){
	for(int i = 0; i< 3; ++i)
	  std::cout << "SF [" << i << "] = " << SF[i] << std::endl;
      }

      double mcIntegral=0;
      for(size_t j=0;j< s.size() ;j++) 
	{ 
	  if(!s[j].data) 
	    {
	      if(debug_)
		std::cout << "Creating TH1F from file " << s[j].name << std::endl;  
	      TH1F * h = ((TH1F*)s[j].file()->Get(names[i].c_str()));
	      h->Sumw2();
	      if(debug_){
		std::cout << "TH1F created from file " << s[j].name << std::endl;  
		std::cout << "Scaling : " << s[j].scale(data.lumi(),fa,fb) << std::endl;  
		std::cout << "Scaling with SF : " << s[j].scale(data.lumi(),fa,fb,SF) << std::endl;  
		std::cout << "Histo integral before scaling = " << h->Integral() << std::endl;
	      }
	      h->Scale(s[j].scale(data.lumi(),fa,fb,SF));
	      if(debug_){
		std::cout << "Histo integral after scaling = " << h->Integral() << std::endl;
		std::cout << "Managing style... " << std::endl;  
	      }
	      h->SetLineWidth(1.);
	      h->SetFillColor(s[j].color);
	      h->SetLineColor(s[j].color);
	      //	      h->Rebin(options[names[i]].rebin);
	      if(debug_)
		std::cout << "Cloning and update legend " << std::endl;  
	      if(grouped.find(s[j].name) == grouped.end()){
		l->AddEntry(h,s[j].name.c_str(),"F");
	      }
	      std::cout << "Sample : " << s[j].name << " - Integral for plot " << names[i] << " = " << h->Integral(-10000,10000) << std::endl;
	      mcIntegral += h->Integral();
	      sta->Add(h);
	      hmc->Add(h);	      
	      //TO FIX grouped map
	      // sovrascrive histo con lo stesso nome tipo VV o ST etc...
	      grouped[s[j].name]=(TH1F *)h->Clone(("_"+names[i]).c_str());
	    }
	}

      if(debug_){
	std::cout << "Data total = " << hd->Integral() << std::endl;
	std::cout << "MC = " << mcIntegral << std::endl;
	std::cout << "Data/MC = " << hd->Integral()/mcIntegral << std::endl;
      }

      TPad * TopPad = new TPad("TopPad","Top Pad",0.,0.3,1.,1. ) ;
      TPad * BtmPad = new TPad("BtmPad","Bottom Pad",0.,0.,1.,0.313 ) ;
      TopPad->SetBottomMargin(0.02);
      BtmPad->SetTopMargin(0.0);
      BtmPad->SetFillStyle(4000);
      TopPad->SetFillStyle(4000);
      BtmPad->SetFillColor(0);
      BtmPad->SetBottomMargin(0.35);
      TopPad->Draw() ;
      BtmPad->Draw() ;
      std::cout << "hd maximum = " << hd->GetMaximum() << "  sta maximum = " << sta->GetMaximum() << std::endl;
      double maxY;
      if(hd->GetMaximum() > sta->GetMaximum()) maxY = (hd->GetMaximum())*1.5;
      else maxY = (sta->GetMaximum())*1.5;
      TopPad->cd();
      hd->Draw("E1X0");
      sta->Draw("sameHIST");
      hmc->Draw("sameE2");
      hmc->SetFillColor(2);
      hmc->SetMarkerSize(0);
      hmc->SetFillStyle(3013);
      hd->Draw("E1X0same");
      l->Draw("same");
      std::cout << "Set Maximum to = " << maxY << std::endl;
      hd->GetYaxis()->SetRangeUser(0.,maxY);
      hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max);

      BtmPad->cd();
      std::cout << "Division" << std::endl;

      TH1D * divisionErrorBand = (TH1D*)(hmc)->Clone("divisionErrorBand");
      divisionErrorBand->Sumw2();
      divisionErrorBand->Divide(hmc);
      divisionErrorBand->Draw("E2");      
      divisionErrorBand->SetMaximum(2.49);
      divisionErrorBand->SetMinimum(0);
      divisionErrorBand->SetMarkerStyle(20);
      divisionErrorBand->SetMarkerSize(0.55);
      divisionErrorBand->GetXaxis()->SetTitleOffset(1.12);
      divisionErrorBand->GetXaxis()->SetLabelSize(0.12);
      divisionErrorBand->GetXaxis()->SetTitleSize(0.5);
      divisionErrorBand->GetYaxis()->SetTitle("Data/MC");
      divisionErrorBand->GetYaxis()->SetLabelSize(0.12);
      divisionErrorBand->GetYaxis()->SetTitleSize(0.12);
      divisionErrorBand->GetYaxis()->SetTitleOffset(0.40);
      divisionErrorBand->GetYaxis()->SetNdivisions(505);
      //divisionErrorBand->UseCurrentStyle();
      divisionErrorBand->SetFillColor(2);
      divisionErrorBand->SetFillStyle(3001);
      divisionErrorBand->SetMarkerSize(0.);

      TH1D * division = (TH1D*)(hd)->Clone("division");
      division->Sumw2();
      division->Divide(hmc);
//       division->SetMaximum(2.5);
//       division->SetMinimum(0);
//       division->SetMarkerStyle(20);
//       division->SetMarkerSize(0.55);
//       division->GetXaxis()->SetLabelSize(0.12);
//       division->GetXaxis()->SetTitleSize(0.14);
//       division->GetYaxis()->SetLabelSize(0.10);
//       division->GetYaxis()->SetTitleSize(0.10);
//      division->GetYaxis()->SetTitle("Data/MC");
      Double_t min = division->GetXaxis()->GetXmin();
      Double_t max = division->GetXaxis()->GetXmax();
      division->Draw("E1X0same");

      TLine *line = new TLine(min, 1.0, max, 1.0);
      line->SetLineColor(kRed);
      line->Draw("same");
      
      TLegend * leg3 =new TLegend(0.50,0.86,0.69,0.96);
      leg3->AddEntry(divisionErrorBand,"MC uncert. (stat.)","f");
      leg3->SetFillColor(0);
      leg3->SetLineColor(0);
      leg3->SetShadowColor(0);
      leg3->SetTextFont(62);
      leg3->SetTextSize(0.06);
      leg3->Draw();

      TPaveText *pave = new TPaveText(0.15,0.85,0.32,0.96,"brNDC");
      pave->SetTextAlign(12);
      pave->SetLineColor(0);
      pave->SetFillColor(0);
      pave->SetShadowColor(0);
      //TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",histDt->Chi2Test(histCopyMC5,"UWCHI2/NDF"),histDt->KolmogorovTest(histCopyMC5))); // stat + sys
      TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",hd->Chi2Test(hmc,"UWCHI2/NDF"),hd->KolmogorovTest(hmc))); // stat only
      text->SetTextFont(62);
      text->SetTextSize(0.08);
      pave->Draw();

      TopPad->cd();
      TLatex latex;
      latex.SetNDC();
      latex.SetTextAlign(12);
      latex.SetTextSize(0.052);
      latex.DrawLatex(0.17,0.89,"CMS Preliminary");
      latex.SetTextSize(0.04);
      latex.DrawLatex(0.17,0.84,"#sqrt{s} = 7 TeV, L = 4.7 fb^{-1}");
      //      latex.DrawLatex(0.17,0.79,"Z(e^{+}e^{-})H(b#bar{b})");
      latex.DrawLatex(0.17,0.79,process.c_str());
      c->Update();
      std::string cName= hd->GetName();
      cName += "_bare.pdf";
      cName = path+cName;
      c->Print(cName.c_str(),"pdf");

//       std::cout << names[i] << " d: " <<  hd->Integral() << " ";
//       THStack * sta2 = new THStack("sta2",hd->GetTitle());
//       float tot=0;
//       float toterr2=0;

//       if(debug_)
// 	std::cout << "Putting the iterator in the for loop" << std::endl;
//       for(std::map<std::string,TH1F *>::reverse_iterator it=grouped.rbegin(); it!=grouped.rend();++it)
//  	{
// 	  if(debug_)
// 	    std::cout << "Using the iterator" << std::endl;
// 	  std::cout << (*it).first << " " << (*it).second->Integral() << " | " << std::endl ;
// 	  if((*it).second->GetEntries() > 0) {
// 	    float er=1.*sqrt((*it).second->GetEntries())/(*it).second->GetEntries()*(*it).second->Integral();
// 	    toterr2+=er*er;
// 	  }
// 	  tot+=(*it).second->Integral();
// 	  sta2->Add(it->second);
//  	}
//       std::cout << " Tot: " << tot << "+-" << sqrt(toterr2) <<  " SF: " << hd->Integral()/tot << std::endl;
//       TCanvas *c2 = new TCanvas();
//       c2->SetTitle(names[i].c_str());
//       std::cout << "hd maximum = " << hd->GetMaximum() << "  sta2 maximum = " << sta2->GetMaximum() << std::endl;
//       if(hd->GetMaximum() > sta2->GetMaximum()) maxY =  hd->GetBinContent(hd->GetMaximumBin()) * 1.5;
//       else maxY = ( sta2->GetMaximum())*1.5;
//       //      hd->Draw("E1"); 
//       sta2->Draw("PADSHIST");
//       //    hd->Draw("E1same");
//       //      l->Draw("same");
//       std::cout << "Set Maximum to = " << maxY << std::endl;
//       hd->GetYaxis()->SetRangeUser(0.,maxY);
//       hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max);
//       c2->Update();

//       std::string c2Name = hd->GetName();
//       c2Name = path+c2Name;
//       c2Name += "_norm.pdf";
//       c2->Print(c2Name.c_str(),"pdf");  

    }

}
Example #3
0
File: csv2.C Project: rgoldouz/tqA
void csv2() 
{   
  TString sysname ="CSV.root";
  TFile *sysinput(0);
  sysinput = TFile::Open( sysname ); // if not: download from ROOT server
  std::vector<string> variables_;
  TString name;
  variables_.push_back("BDT__zjethist");
//  variables_.push_back("BDT__phjethist");
  variables_.push_back("BDT__tbartchhist");
  variables_.push_back("BDT__tt3hist");
  variables_.push_back("BDT__ttphhist");
  variables_.push_back("BDT__wwphhist");
  variables_.push_back("BDT__zzhist");
  variables_.push_back("BDT__zgammahist");
  variables_.push_back("BDT__singleantitopphotonhist");

std::vector<TH1F*> addhists;
std::vector<TH1F*> wjetandwphjet;

wjetandwphjet.push_back((TH1F*) sysinput->Get((std::string("BDT__wjet").c_str())));
wjetandwphjet.push_back((TH1F*) sysinput->Get((std::string("BDT__wphjethist").c_str())));

std::vector<TH1F*> jesuphists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__JES__plus";
jesuphists.push_back((TH1F*) sysinput->Get(name));
}
//jesuphists.push_back((TH1F*) sysinput->Get((std::string("BDT__wjet").c_str())));
//jesuphists.push_back((TH1F*) sysinput->Get((std::string("BDT__wphjethist").c_str())));
for(unsigned int idx=1; idx<variables_.size(); ++idx){
jesuphists[idx]->Add(jesuphists[idx-1]);
}
addhists.push_back(jesuphists[variables_.size()-1]);

std::vector<TH1F*> jesdownhists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__JES__minus";
jesdownhists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
jesdownhists[idx]->Add(jesdownhists[idx-1]);}
addhists.push_back(jesdownhists[variables_.size()-1]);

std::vector<TH1F*> jeruphists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__JER__plus";
jeruphists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
jeruphists[idx]->Add(jeruphists[idx-1]);}
addhists.push_back(jeruphists[variables_.size()-1]);

std::vector<TH1F*> jerdownhists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__JER__minus";
jerdownhists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
jerdownhists[idx]->Add(jerdownhists[idx-1]);}
addhists.push_back(jerdownhists[variables_.size()-1]);

std::vector<TH1F*> phesuphists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__PhES__plus";
phesuphists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
phesuphists[idx]->Add(phesuphists[idx-1]);}
addhists.push_back(phesuphists[variables_.size()-1]);

std::vector<TH1F*> phesdownhists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__PhES__minus";
phesdownhists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
phesdownhists[idx]->Add(phesdownhists[idx-1]);}
addhists.push_back(phesdownhists[variables_.size()-1]);

std::vector<TH1F*> puuphists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__PU__plus";
puuphists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
puuphists[idx]->Add(puuphists[idx-1]);}
addhists.push_back(puuphists[variables_.size()-1]);

std::vector<TH1F*> pudownhists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__PU__minus";
pudownhists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
pudownhists[idx]->Add(pudownhists[idx-1]);}
addhists.push_back(pudownhists[variables_.size()-1]);

std::vector<TH1F*> triguphists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__TRIG__plus";
triguphists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
triguphists[idx]->Add(triguphists[idx-1]);}
addhists.push_back(triguphists[variables_.size()-1]);

std::vector<TH1F*> trigdownhists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__TRIG__minus";
trigdownhists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
trigdownhists[idx]->Add(trigdownhists[idx-1]);}
addhists.push_back(trigdownhists[variables_.size()-1]);

std::vector<TH1F*> btaguphists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__BTAG__plus";
btaguphists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
btaguphists[idx]->Add(btaguphists[idx-1]);}
addhists.push_back(btaguphists[variables_.size()-1]);

std::vector<TH1F*> btagdownhists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__BTAG__minus";
btagdownhists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
btagdownhists[idx]->Add(btagdownhists[idx-1]);}
addhists.push_back(btagdownhists[variables_.size()-1]);

std::vector<TH1F*> misstaguphists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__MISSTAG__plus";
misstaguphists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
misstaguphists[idx]->Add(misstaguphists[idx-1]);}
addhists.push_back(misstaguphists[variables_.size()-1]);

std::vector<TH1F*> misstagdownhists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__MISSTAG__minus";
misstagdownhists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
misstagdownhists[idx]->Add(misstagdownhists[idx-1]);}
addhists.push_back(misstagdownhists[variables_.size()-1]);

std::vector<TH1F*> muonuphists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__MUON__plus";
muonuphists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
muonuphists[idx]->Add(muonuphists[idx-1]);}
addhists.push_back(muonuphists[variables_.size()-1]);

std::vector<TH1F*> muondownhists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__MUON__minus";
muondownhists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
muondownhists[idx]->Add(muondownhists[idx-1]);}
addhists.push_back(muondownhists[variables_.size()-1]);

std::vector<TH1F*> photonuphists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__PHOTON__plus";
photonuphists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
photonuphists[idx]->Add(photonuphists[idx-1]);}
addhists.push_back(photonuphists[variables_.size()-1]);

std::vector<TH1F*> photondownhists;
for(unsigned int i=0; i<variables_.size(); ++i){
name=variables_[i]+"__PHOTON__minus";
photondownhists.push_back((TH1F*) sysinput->Get(name));}
for(unsigned int idx=1; idx<variables_.size(); ++idx){
photondownhists[idx]->Add(photondownhists[idx-1]);}
addhists.push_back(photondownhists[variables_.size()-1]);

std::vector<std::vector<double_t> > vec(photondownhists[0]->GetNbinsX(), vector<double>(18));
  for(int p = 0; p <photondownhists[0]->GetNbinsX(); p++){ //loop over bins
    for(int m = 0; m < 18; m++){ //loop over systematics
vec[p][m]=addhists[m]->GetBinContent(p+1)+wjetandwphjet[0]->GetBinContent(p+1)+wjetandwphjet[1]->GetBinContent(p+1);
cout<<vec[p][m]<<endl;
}}


   // Book output histograms
   UInt_t nbin = 20;
   double min=0;
   double max=1;

   // Prepare input tree (this must be replaced by your data source)
   // in this example, there is a toy tree with signal and one with background events
   // we'll later on use only the "signal" events for the test in this example.
   //   
   TFile *input(0);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::vector<string> samples_;
std::vector<string> datasamples_;
std::vector<TH1F*> hists;
std::vector<TH1F*> datahists;
std::vector<TH1F*> revDATAhists;

float scales[] = {0.628,0.0978,34.01,6.133,1.04,0.32,0.02,0.002,0.0961,0.0253,0.0224,0.0145,0.0125,0.0160,0.0158,0.0341,0.0341,0.0341,0.020,0.0017,0.0055,0.0032,0.00084,0.02,0.01139,0.01139,0.049094905/19.145};
samples_.push_back("WJET.root");
samples_.push_back("ZJET.root");
samples_.push_back("G_Pt_50to80.root");
samples_.push_back("G_Pt_80to120.root");
samples_.push_back("G_Pt_120to170.root");
samples_.push_back("G_Pt_170to300.root");
samples_.push_back("G_Pt_300to470.root");
samples_.push_back("G_Pt_470to800.root");
samples_.push_back("WPHJET.root");
samples_.push_back("T-W-CH.root");
samples_.push_back("TBAR-W-CH.root");
samples_.push_back("T-S-CH.root");
samples_.push_back("TBAR-S-CH.root");
samples_.push_back("T-T-CH.root");
samples_.push_back("TBAR-T-CH.root");
samples_.push_back("TTBAR1.root");
samples_.push_back("TTBAR2.root");
samples_.push_back("TTBAR3.root");
samples_.push_back("TTG.root");
samples_.push_back("WWG.root");
samples_.push_back("WW.root");
samples_.push_back("WZ.root");
samples_.push_back("ZZ.root");
samples_.push_back("ZGAMMA.root");
samples_.push_back("SINGLE-TOP-PH.root");
samples_.push_back("SINGLE-ANTITOP-PH.root");
samples_.push_back("SIGNALtGu.root");
datasamples_.push_back("REALDATA1.root");
datasamples_.push_back("REALDATA2.root");
datasamples_.push_back("REALDATA3.root");

std::vector<string> datasamplesreverse_;
datasamplesreverse_.push_back("etarev/REALDATA1.root");
datasamplesreverse_.push_back("etarev/REALDATA2.root");
datasamplesreverse_.push_back("etarev/REALDATA3.root");

TH1F   *wphjethist(0), *zjethist(0) , *phjethist(0), *wjethist(0), *twchhist(0), *tbarwhist(0),  *tschhist(0), *tbarschhist(0), *ttchhist(0), *tbartchhist(0), *tt1hist(0) ,*tt2hist(0), *tt3hist(0), *ttphhist(0), *wwphhist(0), *wwhist(0), *wzhist(0), *zzhist(0), *zgammahist(0),*singletopphotonhist(0), *singleantitopphotonhist(0), *signalhist(0), *G_Pt_50to80(0),*G_Pt_80to120(0), *G_Pt_120to170(0), *G_Pt_170to300(0) ,*G_Pt_300to470(0),*G_Pt_470to800(0)  ;

TH1F   *wphjethistSB(0), *zjethistSB(0) , *phjethistSB(0), *wjethistSB(0), *twchhistSB(0), *tbarwhistSB(0),  *tschhistSB(0), *tbarschhistSB(0), *ttchhistSB(0), *tbartchhistSB(0), *tt1histSB(0) ,*tt2histSB(0), *tt3histSB(0), *ttphhistSB(0), *wwphhistSB(0), *wwhistSB(0), *wzhistSB(0), *zzhistSB(0), *zgammahistSB(0),*singletopphotonhistSB(0), *singleantitopphotonhistSB(0), *signalhistSB(0), *G_Pt_50to80SB(0),*G_Pt_80to120SB(0), *G_Pt_120to170SB(0), *G_Pt_170to300SB(0) ,*G_Pt_300to470SB(0),*G_Pt_470to800SB(0)  ;

TH1F *data1hist(0), *data2hist(0) ,*data3hist(0) ,*datahistsideband(0);
TH1F *data1histrev(0), *data2histrev(0) ,*data3histrev(0), *datahistrevsideband(0);

wphjethist = new TH1F( "mu_BDT__wphjethist",           "mu_BDT__wphjethist",           nbin, min, max );
zjethist = new TH1F( "mu_BDT__zjethist",           "mu_BDT__zjethist",           nbin, min, max );
G_Pt_50to80= new TH1F( "mu_BDT__G_Pt_50to80",           "mu_BDT__G_Pt_50to80",           nbin, min, max );
G_Pt_80to120= new TH1F( "mu_BDT__G_Pt_80to120",           "mu_BDT__G_Pt_80to120",           nbin, min, max );
G_Pt_120to170= new TH1F( "mu_BDT__G_Pt_120to170",           "mu_BDT__G_Pt_120to170",           nbin, min, max );
G_Pt_170to300= new TH1F( "mu_BDT__G_Pt_170to300",           "mu_BDT__G_Pt_170to300",           nbin, min, max );
G_Pt_300to470= new TH1F( "mu_BDT__G_Pt_300to470",           "mu_BDT__G_Pt_300to470",           nbin, min, max );
G_Pt_470to800= new TH1F( "mu_BDT__G_Pt_470to800",           "mu_BDT__G_Pt_470to800",           nbin, min, max );
wjethist = new TH1F( "mu_BDT__wjethist",           "mu_BDT__wjethist",           nbin, min, max);
twchhist = new TH1F( "mu_BDT__twchhist",           "mu_BDT__twchhist",           nbin, min, max );
tbarwhist = new TH1F( "mu_BDT__tbarwhist",           "mu_BDT__tbarwhist",           nbin, min, max );
tschhist = new TH1F( "mu_BDT__tschhist",           "mu_BDT__tschhist",           nbin, min, max );
tbarschhist = new TH1F( "mu_BDT__tbarschhist",           "mu_BDT__tbarschhist",           nbin, min, max );
ttchhist = new TH1F( "mu_BDT__ttchhist",           "mu_BDT__ttchhist",           nbin, min, max );
tbartchhist = new TH1F( "mu_BDT__tbartchhist",           "mu_BDT__tbartchhist",           nbin, min, max);
tt1hist = new TH1F( "mu_BDT__tt1hist",           "mu_BDT__tt1hist",           nbin,min, max );
tt2hist = new TH1F( "mu_BDT__tt2hist",           "mu_BDT__tt2hist",           nbin, min, max);
tt3hist = new TH1F( "mu_BDT__tt3hist",           "mu_BDT__tt3hist",           nbin, min, max);
ttphhist = new TH1F( "mu_BDT__ttphhist",           "mu_BDT__ttphhist",           nbin, min, max);
wwphhist = new TH1F( "mu_BDT__wwphhist",           "BDT__wwphhist",           nbin,min, max );
wwhist = new TH1F( "mu_BDT__wwhist",           "mu_BDT__wwhist",           nbin,min, max );
wzhist = new TH1F( "mu_BDT__wzhist",           "mu_BDT__wzhist",           nbin, min, max );
zzhist = new TH1F( "mu_BDT__zzhist",           "mu_BDT__zzhist",           nbin, min, max );
zgammahist = new TH1F( "mu_BDT__zgammahist",           "mu_BDT__zgammahist",           nbin,min, max );
singletopphotonhist = new TH1F( "mu_BDT__singletopphotonhist",           "mu_BDT__singletopphotonhist",           nbin, min, max);
singleantitopphotonhist = new TH1F( "mu_BDT__singleantitopphotonhist",           "mu_BDT__singleantitopphotonhist",           nbin,min, max );
signalhist = new TH1F( "mu_BDT__signal100",           "mu_BDT__signal100",           nbin, min, max );


data1hist = new TH1F( "mu_BDT__data1hist",           "mu_BDT__data1hist",           nbin, min, max );
data2hist = new TH1F( "mu_BDT__data2hist",           "mu_BDT__data2hist",           nbin, min, max );
data3hist = new TH1F( "mu_BDT__DATA",           "mu_BDT__DATA",           nbin, min, max );
datahistsideband = new TH1F( "mu_BDT__DATA_sideband",           "mu_BDT__DATA_sideband",           nbin, min, max);


data1histrev = new TH1F( "mu_BDT__data1histrev",           "mu_BDT__data1histrev",           nbin, min, max );
data2histrev = new TH1F( "mu_BDT__data2histrev",           "mu_BDT__data2histrev",           nbin,min, max );
data3histrev = new TH1F( "mu_BDT__DATArev",           "mu_BDT__DATArev",           nbin, min, max );
datahistrevsideband = new TH1F( "mu_BDT__DATArevsideband",           "mu_BDT__DATArevsideband",           nbin, min, max );

wphjethistSB = new TH1F( "mu_BDT__wphjethist__JES__SB",           "mu_BDT__wphjethist__JES__SB",           nbin,min, max );
zjethistSB = new TH1F( "mu_BDT__zjethist__JES__SB",           "mu_BDT__zjethist__JES__SB",           nbin, min, max );
G_Pt_50to80SB= new TH1F( "mu_BDT__G_Pt_50to80SB",           "mu_BDT__G_Pt_50to80SB",           nbin, min, max );
G_Pt_80to120SB= new TH1F( "mu_BDT__G_Pt_80to120SB",           "mu_BDT__G_Pt_80to120SB",           nbin, min, max );
G_Pt_120to170SB= new TH1F( "mu_BDT__G_Pt_120to170SB",           "mu_BDT__G_Pt_120to170SB",           nbin, min, max );
G_Pt_170to300SB= new TH1F( "mu_BDT__G_Pt_170to300SB",           "mu_BDT__G_Pt_170to300SB",           nbin, min, max );
G_Pt_300to470SB= new TH1F( "mu_BDT__G_Pt_300to470SB",           "mu_BDT__G_Pt_300to470SB",           nbin, min, max );
G_Pt_470to800SB= new TH1F( "mu_BDT__G_Pt_470to800SB",           "mu_BDT__G_Pt_470to800SB",           nbin, min, max );
wjethistSB = new TH1F( "mu_BDT__wjethist__JES__SB",           "mu_BDT__wjethist__JES__SB",           nbin, min, max );
twchhistSB = new TH1F( "mu_BDT__twchhist__JES__SB",           "mu_BDT__twchhist__JES__SB",           nbin,min, max);
tbarwhistSB = new TH1F( "mu_BDT__tbarwhist__JES__SB",           "mu_BDT__tbarwhist__JES__SB",           nbin,min, max );
tschhistSB = new TH1F( "mu_BDT__tschhist__JES__SB",           "mu_BDT__tschhist__JES__SB",           nbin, min, max );
tbarschhistSB = new TH1F( "mu_BDT__tbarschhist__JES__SB",           "mu_BDT__tbarschhist__JES__SB",           nbin, min, max );
ttchhistSB = new TH1F( "mu_BDT__ttchhist__JES__SB",           "mu_BDT__ttchhist__JES__SB",           nbin, min, max );
tbartchhistSB = new TH1F( "mu_BDT__tbartchhist__JES__SB",           "mu_BDT__tbartchhist__JES__SB",           nbin, min, max);
tt1histSB = new TH1F( "mu_BDT__tt1hist__JES__SB",           "mu_BDT__tt1hist__JES__SB",           nbin, min, max );
tt2histSB = new TH1F( "mu_BDT__tt2hist__JES__SB",           "mu_BDT__tt2hist__JES__SB",           nbin, min, max );
tt3histSB = new TH1F( "mu_BDT__tt3hist__JES__SB",           "mu_BDT__tt3hist__JES__SB",           nbin, min, max );
ttphhistSB = new TH1F( "mu_BDT__ttphhist__JES__SB",           "mu_BDT__ttphhist__JES__SB",           nbin,min, max );
wwphhistSB = new TH1F( "mu_BDT__wwphhist__JES__SB",           "BDT__wwphhist__JES__SB",           nbin,min, max );
wwhistSB = new TH1F( "mu_BDT__wwhist__JES__SB",           "mu_BDT__wwhist__JES__SB",           nbin, min, max );
wzhistSB = new TH1F( "mu_BDT__wzhist__JES__SB",           "mu_BDT__wzhist__JES__SB",           nbin, min, max );
zzhistSB = new TH1F( "mu_BDT__zzhist__JES__SB",           "mu_BDT__zzhist__JES__SB",           nbin, min, max);
zgammahistSB = new TH1F( "mu_BDT__zgammahist__JES__SB",           "mu_BDT__zgammahist__JES__SB",           nbin, min, max );
singletopphotonhistSB = new TH1F( "mu_BDT__singletopphotonhistSB",           "mu_BDT__singletopphotonhistSB",           nbin,min, max );
singleantitopphotonhistSB = new TH1F( "mu_BDT__singleantitopphotonhistSB",           "mu_BDT__singleantitopphotonhistSB",           nbin, min, max);
signalhistSB = new TH1F( "mu_BDT__signal100__JES__SB",           "mu_BDT__signal100__JES__SB",           nbin,min, max );

std::vector<TH1F*> SBhists;
SBhists.push_back(wjethistSB);
SBhists.push_back(zjethistSB);
SBhists.push_back(G_Pt_50to80SB);
SBhists.push_back(G_Pt_80to120SB);
SBhists.push_back(G_Pt_120to170SB);
SBhists.push_back(G_Pt_170to300SB);
SBhists.push_back(G_Pt_300to470SB);
SBhists.push_back(G_Pt_470to800SB);
SBhists.push_back(wphjethistSB);
SBhists.push_back(twchhistSB);
SBhists.push_back(tbarwhistSB);
SBhists.push_back(tschhistSB);
SBhists.push_back(tbarschhistSB);
SBhists.push_back(ttchhistSB);
SBhists.push_back(tbartchhistSB);
SBhists.push_back(tt1histSB);
SBhists.push_back(tt2histSB);
SBhists.push_back(tt3histSB);
SBhists.push_back(ttphhistSB);
SBhists.push_back(wwphhistSB);
SBhists.push_back(wwhistSB);
SBhists.push_back(wzhistSB);
SBhists.push_back(zzhistSB);
SBhists.push_back(zgammahistSB);
SBhists.push_back(singletopphotonhistSB);
SBhists.push_back(singleantitopphotonhistSB);
SBhists.push_back(signalhistSB);

hists.push_back(wjethist);
hists.push_back(zjethist);
hists.push_back(G_Pt_50to80);
hists.push_back(G_Pt_80to120);
hists.push_back(G_Pt_120to170);
hists.push_back(G_Pt_170to300);
hists.push_back(G_Pt_300to470);
hists.push_back(G_Pt_470to800);
hists.push_back(wphjethist);
hists.push_back(twchhist);
hists.push_back(tbarwhist);
hists.push_back(tschhist);
hists.push_back(tbarschhist);
hists.push_back(ttchhist);
hists.push_back(tbartchhist);
hists.push_back(tt1hist);
hists.push_back(tt2hist);
hists.push_back(tt3hist);
hists.push_back(ttphhist);
hists.push_back(wwphhist);
hists.push_back(wwhist);
hists.push_back(wzhist);
hists.push_back(zzhist);
hists.push_back(zgammahist);
hists.push_back(singletopphotonhist);
hists.push_back(singleantitopphotonhist);
hists.push_back(signalhist);

for(unsigned int idx=0; idx<samples_.size(); ++idx){
hists[idx]->Sumw2();}

datahists.push_back(data1hist);
datahists.push_back(data2hist);
datahists.push_back(data3hist);
datahists.push_back(datahistsideband);
for(unsigned int idx=0; idx<datasamples_.size(); ++idx){
datahists[idx]->Sumw2();}

revDATAhists.push_back(data1histrev);
revDATAhists.push_back(data2histrev);
revDATAhists.push_back(data3histrev);
revDATAhists.push_back(datahistrevsideband);

double insidewphjet=0;
double outsidewphjet=0;
double insidewjet=0;
double outsidewjet=0;
double nsignalevent=0;
double mtopup=220;
double mtopdown=130;
//bool SR=false;
//bool SB=true;
bool SR=true;
bool SB=false;
for(unsigned int idx=0; idx<samples_.size(); ++idx){
   TString fname =samples_[idx];
   if (!gSystem->AccessPathName( fname )) input = TFile::Open( fname ); // check if file in local directory exists
   else    
      input = TFile::Open( "http://root.cern.ch/files/tmva_class_example.root" ); // if not: download from ROOT server
   
   if (!input) {
      std::cout << "ERROR: could not open data file" << std::endl;
      exit(1);
   }
   std::cout << "--- TMVAClassificationApp    : Using input file: " << input->GetName() << std::endl;
   
   // --- Event loop

   // Prepare the event tree
   // - here the variable names have to corres[1]ponds to your tree
   // - you can use the same variables as above which is slightly faster,
   //   but of course you can use different ones and copy the values inside the event loop
   //
  //Double_t  myptphoton,myetaphoton,myptmuon,myetamuon,myptjet,myetajet,mymasstop,mymtw,mydeltaRphotonjet,mydeltaRphotonmuon,myht,mycostopphoton,mydeltaphiphotonmet,mycvsdiscriminant,myjetmultiplicity,mybjetmultiplicity,myleptoncharge;


std::vector<double> *myptphoton=0;
std::vector<double> *myetaphoton=0;
std::vector<double> *myptmuon=0;
std::vector<double> *myetamuon=0;
std::vector<double> *myptjet=0;
std::vector<double> *myetajet=0;
std::vector<double> *mymasstop=0;
//std::vector<double> *mymtw=0;
std::vector<double> *mydeltaRphotonjet=0;
std::vector<double> *mydeltaRphotonmuon=0;
//std::vector<double> *myht=0;
std::vector<double> *mycostopphoton=0;
std::vector<double> *mydeltaphiphotonmet=0;
std::vector<double> *mycvsdiscriminant=0;
std::vector<double> *myjetmultiplicity=0;
//std::vector<double> *mybjetmultiplicity=0;
//std::vector<double> *myleptoncharge=0;
std::vector<double> *myweight=0;
std::vector<double> *myjetmatchinginfo=0;
std::vector<double> *mycoswphoton=0;

   std::cout << "--- Select signal sample" << std::endl;
   TTree* theTree = (TTree*)input->Get("analyzestep2/atq");
//   Int_t myjetmultiplicity, mybjetmultiplicity , myleptoncharge;
//   Float_t userVar1, userVar2;

   theTree->SetBranchAddress("ptphoton", &myptphoton  );
   theTree->SetBranchAddress( "etaphoton", &myetaphoton );
   theTree->SetBranchAddress( "ptmuon", &myptmuon );
   theTree->SetBranchAddress( "etamuon", &myetamuon );
   theTree->SetBranchAddress( "ptjet", &myptjet );
   theTree->SetBranchAddress( "etajet", &myetajet );
   theTree->SetBranchAddress( "masstop", &mymasstop );
//   theTree->SetBranchAddress( "mtw", &mymtw );
   theTree->SetBranchAddress( "deltaRphotonjet", &mydeltaRphotonjet );
   theTree->SetBranchAddress( "deltaRphotonmuon", &mydeltaRphotonmuon );
//   theTree->SetBranchAddress( "ht", &myht );
   theTree->SetBranchAddress( "costopphoton", &mycostopphoton );
   theTree->SetBranchAddress( "jetmultiplicity", &myjetmultiplicity );
//   theTree->SetBranchAddress( "bjetmultiplicity", &mybjetmultiplicity );
   theTree->SetBranchAddress( "deltaphiphotonmet", &mydeltaphiphotonmet );
   theTree->SetBranchAddress( "cvsdiscriminant", &mycvsdiscriminant );
//   theTree->SetBranchAddress( "leptoncharge", &myleptoncharge );
   theTree->SetBranchAddress( "weight", &myweight);
   theTree->SetBranchAddress( "coswphoton", &mycoswphoton );
	theTree->SetBranchAddress( "jetmatchinginfo", &myjetmatchinginfo );


//   std::cout << "--- Processing: " << theTree->GetEntries() << " events" << std::endl;
   TStopwatch sw;
   sw.Start();
   for (Long64_t ievt=0; ievt<theTree->GetEntries();ievt++) {
//   std::cout << "--- ... Processing event: " << ievt << std::endl;
double finalweight;

      if (ievt%1000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl;

      theTree->GetEntry(ievt);
//for (int l=0;l<sizeof(myptphoton);l++){
//std::cout << "--- ... reza: " << myptphoton[l] <<std::endl;
//}
//std::cout << "--- ......................."<< (*mycvsdiscriminant)[0]<<std::endl;
      // --- Return the MVA outputs and fill into histograms

finalweight=(*myweight)[0];
//cout<<(*myweight)[0]<<endl;
if((*mymasstop )[0]>mtopdown && (*mymasstop )[0]<mtopup){
hists[idx] ->Fill(Bmodification((*mycvsdiscriminant)[0],(*myjetmatchinginfo)[0]),finalweight );
if (samples_[idx]=="WPHJET.root")insidewphjet=insidewphjet+finalweight;
if (samples_[idx]=="SIGNALtGu.root")nsignalevent=nsignalevent+1;
//cout<<insidewphjet<<endl;
}
else {
SBhists[idx] ->Fill( Bmodification((*mycvsdiscriminant)[0],(*myjetmatchinginfo)[0]),finalweight );
if (samples_[idx]=="WPHJET.root")outsidewphjet=outsidewphjet+finalweight;}


      // Retrieve also per-event error
}
delete myptphoton;
delete myetaphoton;
delete myptmuon;
delete myetamuon;
delete myptjet;
delete myetajet;
delete mymasstop;
//delete mymtw;
delete mydeltaRphotonjet;
delete mydeltaRphotonmuon;
//delete myht;
delete mycostopphoton;
delete mydeltaphiphotonmet;
delete mycvsdiscriminant;
delete myjetmultiplicity;
//delete mybjetmultiplicity;
//delete myleptoncharge;
//delete myplot;
}
for(unsigned int idx=0; idx<datasamples_.size(); ++idx){
   TString fname =datasamples_[idx];
   if (!gSystem->AccessPathName( fname )) input = TFile::Open( fname ); // check if file in local directory exists
   else    
      input = TFile::Open( "http://root.cern.ch/files/tmva_class_example.root" ); // if not: download from ROOT server
   
   if (!input) {
      std::cout << "ERROR: could not open data file" << std::endl;
      exit(1);
   }
   std::cout << "--- TMVAClassificationApp    : Using input file: " << input->GetName() << std::endl;
   
   // --- Event loop

   // Prepare the event tree
   // - here the variable names have to corres[1]ponds to your tree
   // - you can use the same variables as above which is slightly faster,
   //   but of course you can use different ones and copy the values inside the event loop
   //
  //Double_t  myptphoton,myetaphoton,myptmuon,myetamuon,myptjet,myetajet,mymasstop,mymtw,mydeltaRphotonjet,mydeltaRphotonmuon,myht,mycostopphoton,mydeltaphiphotonmet,mycvsdiscriminant,myjetmultiplicity,mybjetmultiplicity,myleptoncharge;


std::vector<double> *myptphoton=0;
std::vector<double> *myetaphoton=0;
std::vector<double> *myptmuon=0;
std::vector<double> *myetamuon=0;
std::vector<double> *myptjet=0;
std::vector<double> *myetajet=0;
std::vector<double> *mymasstop=0;
//std::vector<double> *mymtw=0;
std::vector<double> *mydeltaRphotonjet=0;
std::vector<double> *mydeltaRphotonmuon=0;
//std::vector<double> *myht=0;
std::vector<double> *mycostopphoton=0;
std::vector<double> *mydeltaphiphotonmet=0;
std::vector<double> *mycvsdiscriminant=0;
std::vector<double> *myjetmultiplicity=0;
//std::vector<double> *mybjetmultiplicity=0;
//std::vector<double> *myleptoncharge=0;
std::vector<double> *mycoswphoton=0;



   std::cout << "--- Select signal sample" << std::endl;
   TTree* theTree = (TTree*)input->Get("analyzestep2/atq");
//   Int_t myjetmultiplicity, mybjetmultiplicity , myleptoncharge;
//   Float_t userVar1, userVar2;

   theTree->SetBranchAddress("ptphoton", &myptphoton  );
   theTree->SetBranchAddress( "etaphoton", &myetaphoton );
   theTree->SetBranchAddress( "ptmuon", &myptmuon );
   theTree->SetBranchAddress( "etamuon", &myetamuon );
   theTree->SetBranchAddress( "ptjet", &myptjet );
   theTree->SetBranchAddress( "etajet", &myetajet );
   theTree->SetBranchAddress( "masstop", &mymasstop );
//   theTree->SetBranchAddress( "mtw", &mymtw );
   theTree->SetBranchAddress( "deltaRphotonjet", &mydeltaRphotonjet );
   theTree->SetBranchAddress( "deltaRphotonmuon", &mydeltaRphotonmuon );
//   theTree->SetBranchAddress( "ht", &myht );
   theTree->SetBranchAddress( "costopphoton", &mycostopphoton );
   theTree->SetBranchAddress( "jetmultiplicity", &myjetmultiplicity );
//   theTree->SetBranchAddress( "bjetmultiplicity", &mybjetmultiplicity );
   theTree->SetBranchAddress( "deltaphiphotonmet", &mydeltaphiphotonmet );
   theTree->SetBranchAddress( "cvsdiscriminant", &mycvsdiscriminant );
   theTree->SetBranchAddress( "coswphoton", &mycoswphoton );
//   theTree->SetBranchAddress( "leptoncharge", &myleptoncharge );


   for (Long64_t ievt=0; ievt<theTree->GetEntries();ievt++) {
//   std::cout << "--- ... Processing event: " << ievt << std::endl;
      theTree->GetEntry(ievt);
      // --- Return the MVA outputs and fill into histograms
//leptoncharge=(float)(*myleptoncharge )[0];

if((*mymasstop )[0]>mtopdown && (*mymasstop )[0]<mtopup) datahists[idx] ->Fill( (*mycvsdiscriminant)[0] );
else datahists[3]->Fill(  (*mycvsdiscriminant)[0] );
}
delete myptphoton;
delete myetaphoton;
delete myptmuon;
delete myetamuon;
delete myptjet;
delete myetajet;
delete mymasstop;
//delete mymtw;
delete mydeltaRphotonjet;
delete mydeltaRphotonmuon;
//delete myht;
delete mycostopphoton;
delete mydeltaphiphotonmet;
delete mycvsdiscriminant;
delete myjetmultiplicity;
//delete mybjetmultiplicity;
//delete myleptoncharge;
//delete myplot;

}

for(unsigned int idx=0; idx<datasamplesreverse_.size(); ++idx){
   TString fname =datasamplesreverse_[idx];
   if (!gSystem->AccessPathName( fname )) input = TFile::Open( fname ); // check if file in local directory exists
   else
      input = TFile::Open( "http://root.cern.ch/files/tmva_class_example.root" ); // if not: download from ROOT server

   if (!input) {
      std::cout << "ERROR: could not open data file" << std::endl;
      exit(1);
   }
   std::cout << "--- TMVAClassificationApp    : Using input file: " << input->GetName() << std::endl;

std::vector<double> *myptphoton=0;
std::vector<double> *myetaphoton=0;
 std::vector<double> *myptmuon=0;
 std::vector<double> *myetamuon=0;
 std::vector<double> *myptjet=0;
 std::vector<double> *myetajet=0;
 std::vector<double> *mymasstop=0;
 //std::vector<double> *mymtw=0;
 std::vector<double> *mydeltaRphotonjet=0;
std::vector<double> *mydeltaRphotonmuon=0;
 //std::vector<double> *myht=0;
 std::vector<double> *mycostopphoton=0;
 std::vector<double> *mydeltaphiphotonmet=0;
 std::vector<double> *mycvsdiscriminant=0;
 std::vector<double> *myjetmultiplicity=0;
std::vector<double> *mycoswphoton=0;
 //std::vector<double> *mybjetmultiplicity=0;
 //std::vector<double> *myleptoncharge=0;
   TTree* theTree = (TTree*)input->Get("analyzestep2/atq");
   theTree->SetBranchAddress("ptphoton", &myptphoton  );
   theTree->SetBranchAddress( "etaphoton", &myetaphoton );
   theTree->SetBranchAddress( "ptmuon", &myptmuon );
   theTree->SetBranchAddress( "etamuon", &myetamuon );
   theTree->SetBranchAddress( "ptjet", &myptjet );
   theTree->SetBranchAddress( "etajet", &myetajet );
   theTree->SetBranchAddress( "masstop", &mymasstop );
//   theTree->SetBranchAddress( "mtw", &mymtw );
   theTree->SetBranchAddress( "deltaRphotonjet", &mydeltaRphotonjet );
   theTree->SetBranchAddress( "deltaRphotonmuon", &mydeltaRphotonmuon );
         //   theTree->SetBranchAddress( "ht", &myht );
   theTree->SetBranchAddress( "costopphoton", &mycostopphoton );
   theTree->SetBranchAddress( "jetmultiplicity", &myjetmultiplicity );
               //   theTree->SetBranchAddress( "bjetmultiplicity", &mybjetmultiplicity );
   theTree->SetBranchAddress( "deltaphiphotonmet", &mydeltaphiphotonmet );
   theTree->SetBranchAddress( "cvsdiscriminant", &mycvsdiscriminant );
   theTree->SetBranchAddress( "coswphoton", &mycoswphoton );
                     //   theTree->SetBranchAddress( "leptoncharge", &myleptoncharge );
 // Efficiency calculator for cut method
 for (Long64_t ievt=0; ievt<theTree->GetEntries();ievt++) {
                       //   std::cout << "--- ... Processing event: " << ievt << std::endl;
   if (ievt%1000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl;
   theTree->GetEntry(ievt);

 

if((*mymasstop )[0]>mtopdown && (*mymasstop )[0]<mtopup) {
//revDATAhists[idx]->Fill( reader->EvaluateMVA( "BDT method"           ) );
insidewjet=insidewjet+1;
revDATAhists[idx]->Fill(  (*mycvsdiscriminant)[0]);
}
else {
//revDATAhists[3]->Fill( reader->EvaluateMVA( "BDT method"           ) );
outsidewjet=outsidewjet+1;
revDATAhists[3]->Fill( (*mycvsdiscriminant)[0]);
}


//cout<<insidewjet<<endl;
}
delete myptphoton;
delete myetaphoton;
delete myptmuon;
delete myetamuon;
delete myptjet;
delete myetajet;
delete mymasstop;
//delete mymtw;
delete mydeltaRphotonjet;
delete mydeltaRphotonmuon;
//delete myht;
delete mycostopphoton;
delete mydeltaphiphotonmet;
delete mycvsdiscriminant;
delete myjetmultiplicity;
////delete mybjetmultiplicity;
////delete myleptoncharge;
////delete myplot;
//
}

double wphjetscale;
wphjetscale=insidewphjet/(insidewphjet+outsidewphjet);
cout<<"wphjetscale=    "<<wphjetscale<<endl;
double wjetscale;
wjetscale=insidewjet/(insidewjet+outsidewjet);
cout<<"wjetscale=    "<<wjetscale<<endl;
cout<<"nsignalevent=    "<<nsignalevent<<endl;
//cout<<insidewphjet<<"insidewphjet"<<"       "<<wphjetscale<<"       "<<insidewjet/(insidewjet+outsidewjet)<<endl;
float lumi = 1;

if (SR==true){
double ff=0;
for(unsigned int idx=0; idx<samples_.size(); ++idx){
hists[idx]->Scale(lumi*scales[idx]);
if (idx !=0 && idx!=3){
ff=hists[idx]->Integral()+ff;
cout<<samples_[idx]<<"         =        "<<hists[idx]->Integral()<<"     " <<ff<<endl;}
}

for(unsigned int idx=0; idx<samples_.size(); ++idx){
SBhists[idx]->Scale(lumi*scales[idx]);}

THStack *hs1 = new THStack("hs1","BDT output");
for(unsigned int idx=1; idx<datasamplesreverse_.size(); ++idx){
revDATAhists[idx]->Add(revDATAhists[idx-1]);
}
//cout<<"*********************"<< datahists[3]->Integral()<<"       "<<wphjetscale<<endl;
//cout<<"*********************"<< revDATAhists[2]->Integral()<<"       "<<wjetscale<<endl;

revDATAhists[2]->Scale(219.373/revDATAhists[2]->Integral());
for(unsigned int idx=1; idx<revDATAhists[2]->GetNbinsX()+1; ++idx){
//revDATAhists[2]->SetBinError(idx,(revDATAhists[2]->GetBinContent(idx)/revDATAhists[2]->Integral())*74.84);
revDATAhists[2]->SetBinError(idx,0);
//if (revDATAhists[2]->GetBinError(idx)>revDATAhists[2]->GetBinContent(idx)) revDATAhists[2]->SetBinError(idx, revDATAhists[2]->GetBinContent(idx)/2); 
}
//revDATAhists[2]->Scale(wjetscale);
revDATAhists[3]->Scale(219.373/revDATAhists[3]->Integral());
revDATAhists[3]->Scale((1-wjetscale)/wjetscale);


for(unsigned int idx=1; idx<datasamples_.size(); ++idx){
datahists[idx]->Add(datahists[idx-1]);}
cout<<"     " <<datahists[2]->Integral()<<endl;

datahists[3]->Add(revDATAhists[3],-1);
datahists[3]->Add(SBhists[1],-1);
datahists[3]->Add(SBhists[2],-1);
for(unsigned int idx=9; idx<samples_.size()-1; ++idx){
datahists[3]->Add(SBhists[idx],-1);}
for(unsigned int idx=1; idx<nbin; ++idx){
if (datahists[3]->GetBinContent(idx)<0)datahists[3]->SetBinContent(idx,0);
} 
datahists[3]->Scale(1112.2/datahists[3]->Integral());
for(unsigned int idx=1; idx<datahists[3]->GetNbinsX()+1; ++idx){
//datahists[3]->SetBinError(idx,(datahists[3]->GetBinContent(idx)/datahists[3]->Integral())*139.11);}
datahists[3]->SetBinError(idx,0);}

TH1F *datatoMC(0);

//datahists[3]->Scale(wphjetscale);

//hists[1]->Add(revDATAhists[2]);
//hists[2]->Add(hists[1]);
//datahists[3]->Add(hists[2]);
//hists[4]->Add(datahists[3]);

//for(unsigned int idx=5; idx<samples_.size()-1; ++idx){
//   hists[idx]->Add(hists[idx-1]);}
//cout<<"**********real data***********"<< datahists[2]->Integral()<<"       "<<wphjetscale<<endl;
//cout<<"********** mc ***********"<< hists[18]->Integral()<<"       "<<wjetscale<<endl;
// setup the canvas and draw the histograms

TH1F *sum_h= new TH1F ( *hists[1] ) ;
sum_h->Sumw2();
for(unsigned int idx=2; idx<samples_.size()-1; ++idx){
if (idx!=8)sum_h->Add(hists[idx],1);
}
sum_h->Add(revDATAhists[2],1);
sum_h->Add(datahists[3],1);

std::vector<std::vector<double_t> > vecplus(photondownhists[0]->GetNbinsX(), vector<double>(18));
std::vector<std::vector<double_t> > vecminus(photondownhists[0]->GetNbinsX(), vector<double>(18));
 for(int p = 0; p <photondownhists[0]->GetNbinsX(); p++){ //loop over bins
    for(int m = 0; m < 18; m++){ //loop over systematics
vecplus[p][m]=0;
vecminus[p][m]=0;
if (vec[p][m]>sum_h->GetBinContent(p+1)) vecplus[p][m] = vec[p][m]-sum_h->GetBinContent(p+1);
else if (vec[p][m]<sum_h->GetBinContent(p+1)) vecminus[p][m] = sum_h->GetBinContent(p+1)-vec[p][m];

cout<<vecplus[p][m]<<endl;
}}




TCanvas *c1 = new TCanvas("c1","signal region",50,50,865,780);
c1->cd();
TPad *pad1 = new TPad("pad1","pad1",0,0.25,1,1);
pad1->SetFillStyle(0);
pad1->SetFrameFillStyle(0);
pad1->SetBottomMargin(0);
TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.25);
pad2->SetFillStyle(0);
pad2->SetFrameFillStyle(0);
pad2->SetTopMargin(0);
pad2->SetBottomMargin(0.12/0.46);
pad2->Draw();
pad1->Draw();

pad1->cd();

//W+jet
revDATAhists[2]->SetFillColor(kBlue-2);
revDATAhists[2]->SetLineColor(kBlack);
hs1->Add(revDATAhists[2]);
//Z+jet
hists[1]->SetFillColor(kOrange-4);
hists[1]->SetLineColor(kBlack);
hs1->Add(hists[1]);
//photon+jet
hists[3]->Add(hists[2]);
hists[4]->Add(hists[3]);
hists[5]->Add(hists[4]);
hists[6]->Add(hists[5]);
hists[7]->Add(hists[6]);
hists[7]->SetFillColor(19);
//hs1->Add(hists[7]);
//W+photon+jet
datahists[3]->SetFillColor(kGreen-3);
datahists[3]->SetLineColor(kBlack);
hs1->Add(datahists[3]);

//single top+singletop photon
hists[5+5]->Add(hists[4+5]);
hists[6+5]->Add(hists[5+5]);
hists[7+5]->Add(hists[6+5]);
hists[8+5]->Add(hists[7+5]);
hists[9+5]->Add(hists[8+5]);
hists[19+5]->Add(hists[9+5]);
hists[20+5]->Add(hists[19+5]);
hists[20+5]->SetFillColor(kRed+3);
hists[20+5]->SetLineColor(kBlack);
hs1->Add(hists[20+5]);
//hists[9+5]->SetFillColor(kAzure+10);
//hs1->Add(hists[9+5]);

hists[11+5]->Add(hists[10+5]);
hists[12+5]->Add(hists[11+5]);
hists[13+5]->Add(hists[12+5]);
hists[13+5]->SetFillColor(kPink+1);
hists[13+5]->SetLineColor(kBlack);
hs1->Add(hists[13+5]);
//hists[13+5]->SetFillColor(17);
//hs1->Add(hists[13+5]);
//hists[14+5]->SetFillColor(kSpring-9);
//hs1->Add(hists[14+5]);
hists[15+5]->Add(hists[14+5]);
hists[16+5]->Add(hists[15+5]);
hists[17+5]->Add(hists[16+5]);
hists[17+5]->SetFillColor(kViolet-7);
hists[17+5]->SetLineColor(kBlack);
hs1->Add(hists[17+5]);
hists[18+5]->SetFillColor(kAzure+10);
hists[18+5]->SetLineColor(kBlack);
hs1->Add(hists[18+5]);
//hists[20+5]->Add(hists[19+5]);
//hists[20+5]->SetFillColor(kYellow+3);
//hs1->Add(hists[20+5]);

hs1->Draw("hist");
hs1->SetMaximum(1.6*datahists[2]->GetMaximum());
//hs1->GetXaxis()->SetTitle("BDT output");
hs1->GetYaxis()->SetTitle("Events / 0.05");
hs1->GetYaxis()->SetTitleSize(0.045);
hs1->GetYaxis()->SetTitleFont(22);
hs1->GetYaxis()->SetTitleOffset(0.8);
hs1->GetYaxis()->SetLabelSize(0.044);

hists[21+5]->SetLineColor(kRed+3);
hists[21+5]->SetLineWidth(3);
hists[21+5]->Draw("histsame");

datahists[2]->SetLineWidth(3.);
datahists[2]->SetLineColor(kBlack);
datahists[2]->SetMarkerColor(kBlack);
datahists[2]->SetMarkerStyle(20.);
datahists[2]->SetMarkerSize(1.35);
datahists[2]->Draw("esame");
sum_h->SetLineColor(kBlack);
sum_h->SetFillColor(1);
sum_h->SetFillStyle(3001);
sum_h->Draw("e2same");


    TPaveText *pt = new TPaveText(0.1,0.95,0.4,0.95, "NDC"); // NDC sets coords
    pt->SetLineColor(10);                                              // relative to pad dimensions
    pt->SetFillColor(10); // text is black on white
    pt->SetTextSize(0.045);
    pt->SetTextAlign(12);
    pt->AddText("CMS Preliminary, 19.1 fb^{-1}, #sqrt{s} = 8 TeV");
    pt->SetShadowColor(10);
    pt->Draw("same");

std::vector<double_t> errorup(photondownhists[0]->GetNbinsX());
std::vector<double_t> errordown(photondownhists[0]->GetNbinsX());
 for(int p = 0; p <photondownhists[0]->GetNbinsX(); p++){ //loop over bins
    for(int m = 0; m < 18; m++){ //loop over systematics
if (m==0) {errorup[p]=0;
errordown[p]=0;}
errorup[p]=pow(vecplus[p][m],2)+errorup[p];
errordown[p]=pow(vecminus[p][m],2)+errordown[p];
}
errorup[p]=pow(0.024*sum_h->GetBinContent(p+1),2)+errorup[p];
errordown[p]=pow(0.024*sum_h->GetBinContent(p+1),2)+errordown[p];
errorup[p]=pow(0.4*wjetandwphjet[0]->GetBinContent(p+1),2)+errorup[p];
errordown[p]=pow(0.4*wjetandwphjet[0]->GetBinContent(p+1),2)+errordown[p];
errorup[p]=pow(0.3*wjetandwphjet[1]->GetBinContent(p+1),2)+errorup[p];
errordown[p]=pow(0.3*wjetandwphjet[1]->GetBinContent(p+1),2)+errordown[p];
errorup[p]=pow(0.3*hists[1]->GetBinContent(p+1),2)+errorup[p];
errordown[p]=pow(0.3*hists[1]->GetBinContent(p+1),2)+errordown[p];
errorup[p]=pow(0.3*hists[20+5]->GetBinContent(p+1),2)+errorup[p];
errordown[p]=pow(0.3*hists[20+5]->GetBinContent(p+1),2)+errordown[p];
errorup[p]=pow(0.3*hists[13+5]->GetBinContent(p+1),2)+errorup[p];
errordown[p]=pow(0.3*hists[13+5]->GetBinContent(p+1),2)+errordown[p];
errorup[p]=pow(0.3*hists[17+5]->GetBinContent(p+1),2)+errorup[p];
errordown[p]=pow(0.3*hists[17+5]->GetBinContent(p+1),2)+errordown[p];
errorup[p]=pow(0.3*hists[18+5]->GetBinContent(p+1),2)+errorup[p];
errordown[p]=pow(0.3*hists[18+5]->GetBinContent(p+1),2)+errordown[p];

cout<<errorup[p]<<endl;
cout<<errordown[p]<<endl;
}

 double ax[photondownhists[0]->GetNbinsX()];
 double ay[photondownhists[0]->GetNbinsX()];
 double aexl[photondownhists[0]->GetNbinsX()];
 double aexh[photondownhists[0]->GetNbinsX()];
 double aeyl[photondownhists[0]->GetNbinsX()];
 double aeyh[photondownhists[0]->GetNbinsX()];
 for(int p = 0; p <photondownhists[0]->GetNbinsX(); p++){ //loop over bins
ax[p]=min+(max-min)/(2*nbin)+p*((max-min)/nbin);
ay[p]=sum_h->GetBinContent(p+1);
aexl[p]=(max-min)/(2*nbin);
aexh[p]=(max-min)/(2*nbin);
aeyl[p]=sqrt(errordown[p]);
aeyh[p]=sqrt(errorup[p]);
}
TGraphAsymmErrors* gae = new TGraphAsymmErrors(photondownhists[0]->GetNbinsX(), ax, ay, aexl, aexh, aeyl, aeyh);
gae->SetFillColor(1);
gae->SetFillStyle(3003);

   gae->Draw("e2same");
TLegend* leg = new TLegend(0.60,0.40,0.89,0.87);
  leg->SetFillStyle ( 0);
  leg->SetFillColor ( 0);
  leg->SetBorderSize( 0);
  leg->AddEntry( datahists[2], "Data"               , "PL");
//  leg->AddEntry( hists[25], "Single top+#gamma"               , "F");
  leg->AddEntry( hists[23], "Z#gamma"               , "F");
  leg->AddEntry( hists[22], "WW,WZ,ZZ,WW#gamma "               , "F");
//  leg->AddEntry( hists[19], "WW#gamma"               , "F");
  leg->AddEntry( hists[18], "t#bar{t}, t#bar{t}#gamma"               , "F");
//  leg->AddEntry( hists[17], "t#bar{t}"               , "F");
  leg->AddEntry( hists[25], "Single top, Single top+#gamma"               , "F");
//  leg->AddEntry( hists[14], "Single top"               , "F");
  leg->AddEntry( datahists[3], "W#gamma"              , "F");
//  leg->AddEntry( hists[7], "#gamma+jets"                           , "F");
  leg->AddEntry( hists[1], "Z+jets"                           , "F");
  leg->AddEntry(revDATAhists[2], "W+jets"                           , "F");
  leg->AddEntry( hists[26], "Signal(tu#gamma) 1 pb"               , "L");
  leg->AddEntry(sum_h, "Stat uncertainty"               , "F");
  leg->AddEntry(gae, "Syst uncertainty"               , "F");

//  leg->AddEntry( datahists[2], "CMS Data 2012(19.145/fb)"               , "PL");

leg->Draw("same");
   sum_h->Draw("AXISSAMEY+");
   sum_h->Draw("AXISSAMEX+");
pad1->Draw();

TCanvas *c22 = new TCanvas("c22","signal region22",50,50,865,780);
c22->cd();
    gae->Draw("a2");
    gae->Draw("psame");

TH1F *h_ratio = (TH1F*)datahists[2]->Clone("h_copy");
h_ratio->Sumw2();	
pad2->cd();
pad2->SetGridy();
datatoMC = new TH1F( "datatoMC",           "datatoMC",           nbin, min, max );
datatoMC->Sumw2();
datatoMC->Divide(datahists[2],sum_h);
h_ratio->Divide(sum_h);
h_ratio->SetFillStyle(3004);
h_ratio->GetXaxis()->SetTitle("CSV discriminator");
h_ratio->GetYaxis()->SetTitle("DATA/MC");
  h_ratio->GetXaxis()->SetTitleSize(0.12);
  h_ratio->GetYaxis()->SetTitleSize(0.12);
  h_ratio->GetXaxis()->SetTitleFont(22);
  h_ratio->GetYaxis()->SetTitleFont(22);
  h_ratio->GetXaxis()->SetTickLength(0.05);
  h_ratio->GetYaxis()->SetTickLength(0.05);
  h_ratio->GetXaxis()->SetLabelSize(0.14);
  h_ratio->GetYaxis()->SetLabelSize(0.14);
  h_ratio->GetYaxis()->SetTitleOffset(0.25);
  h_ratio->GetYaxis()->SetNdivisions(504);
  h_ratio->SetLineWidth(2);
//h_ratio->SetStats(0);
//h_ratio->SetMarkerStyle(20);
h_ratio->SetMinimum(0);
h_ratio->SetMaximum(2);
h_ratio->Draw("E");


//datatoMC->Draw("");
TLine *l3 = new TLine(h_ratio->GetXaxis()->GetXmin(), 1.00, h_ratio->GetXaxis()->GetXmax(), 1.00);
l3->SetLineWidth(1);
//l3->SetLineStyle(7);
//l3->Draw();
  h_ratio->Draw("AXISSAMEY+");
   h_ratio->Draw("AXISSAMEX+");

 
c1->Update();

for(unsigned int idx=1; idx<nbin+1; ++idx){
cout<<"MC    "<<"nbin= "<<idx<<"  content= "<<sum_h->GetBinContent(idx)<<endl;
cout<<"signal    "<<"nbin= "<<idx<<"  content= "<<hists[21+5]->GetBinContent(idx)<<endl;
cout<<"Data    "<<"nbin= "<<idx<<"  content= "<<datahists[2]->GetBinContent(idx)<<endl;
}
cout<<"signal Integral   "<<hists[21+5]->Integral()<<endl;

}


if (SB==true){
for(unsigned int idx=0; idx<samples_.size(); ++idx){
SBhists[idx]->Scale(lumi*scales[idx]);}
revDATAhists[3]->Scale(620.32/revDATAhists[3]->Integral());
revDATAhists[3]->Scale(1-wjetscale);
SBhists[1]->Add(revDATAhists[3]);
SBhists[2]->Add(SBhists[1]);
SBhists[4]->Add(SBhists[2]);

for(unsigned int idx=5; idx<samples_.size()-1; ++idx){
   SBhists[idx]->Add(SBhists[idx-1]);}
SBhists[20]->SetMaximum(1.5*datahists[3]->GetMaximum());
SBhists[20]->SetFillColor(kMagenta+2);
SBhists[20]->Draw();
SBhists[18]->SetFillColor(kOrange+4);
SBhists[18]->Draw("same");
SBhists[17]->SetFillColor(kOrange-2);
SBhists[17]->Draw("same");

SBhists[16]->SetFillColor(kRed);
SBhists[16]->Draw("same");
SBhists[15]->SetFillColor(kViolet+1);
SBhists[15]->Draw("same");
SBhists[14]->SetFillColor(kSpring-9);
SBhists[14]->Draw("same");
SBhists[13]->SetFillColor(32);
SBhists[13]->Draw("same");
SBhists[12]->SetFillColor(6);
SBhists[12]->Draw("same");
SBhists[9]->SetFillColor(4);
SBhists[9]->Draw("same");
//hists[8]->SetFillColor(4);
//hists[8]->Draw("same");
//hists[7]->SetFillColor(3);
//hists[7]->Draw("same");
//hists[6]->SetFillColor(3);
//hists[6]->Draw("same");
//hists[5]->SetFillColor(2);
//hists[5]->Draw("same");
//hists[4]->SetFillColor(2);
//hists[4]->Draw("same");
//hists[3]->SetFillColor(5);
//hists[3]->Draw("same");
//datahists[3]->SetFillColor(5);
//datahists[3]->Draw("same");
SBhists[2]->SetFillColor(8);
SBhists[2]->Draw("same");
SBhists[1]->SetFillColor(kOrange+7);
SBhists[1]->Draw("same");
revDATAhists[3]->SetFillColor(7);
revDATAhists[3]->Draw("same");
//hists[0]->SetFillColor(7);
//hists[0]->Draw("same");
SBhists[21]->SetFillColor(1);
SBhists[21]->SetFillStyle(3004);
SBhists[21]->Draw("same");


 // plot data points
datahists[3]->SetLineWidth(3.);
datahists[3]->SetLineColor(kBlack);
datahists[3]->SetMarkerColor(kBlack);
datahists[3]->SetMarkerStyle(20.);
datahists[3]->Draw("esame");
//conv->RedrawAxis();


TLegend* leg = new TLegend(0.60,0.40,0.89,0.87);
  leg->SetFillStyle ( 0);
  leg->SetFillColor ( 0);
  leg->SetBorderSize( 0);
  leg->AddEntry( revDATAhists[2], "W JET"                           , "F");
  leg->AddEntry( SBhists[1], "Z JET"                           , "F");
  leg->AddEntry( SBhists[2], "PH JET"                           , "F");
//  leg->AddEntry( datahists[3], "W PH JET"              , "F");
//  leg->AddEntry( hists[5], "TOP-W-CH"               , "F");
//  leg->AddEntry( hists[5], "T-S-CH"               , "F");
//  leg->AddEntry( hists[7], "TOP-S-CH"               , "F");
//  leg->AddEntry( hists[7], "TTBAR-CH"               , "F");
//  leg->AddEntry( hists[8], "TBAR-W-CH"               , "F");
  leg->AddEntry( SBhists[9], "SINGLE TOP  "               , "F");
  leg->AddEntry( SBhists[12], "TTBAR"               , "F");
  leg->AddEntry( SBhists[13], "TTG"               , "F");
  leg->AddEntry( SBhists[14], "WWG"               , "F");
  leg->AddEntry( SBhists[15], "WW"               , "F");
  leg->AddEntry( SBhists[16], "WZ"               , "F");
  leg->AddEntry( SBhists[17], "ZZ"               , "F");
  leg->AddEntry( SBhists[18], "ZGAMMA"               , "F");
  leg->AddEntry( SBhists[20], "SINGLE TOP+PHOTON"               , "F");
  leg->AddEntry( SBhists[21], "SIGNAL"               , "F");
leg->AddEntry( datahists[3], "CMS Data 2012(19.145/fb)"               , "PL");

  leg->Draw("same");
}
} 
//*************************************************************
void arrangeCanvas(TCanvas *canv,TH1F* meanplots[100],TH1F* widthplots[100],Int_t nFiles, TString LegLabels[10], bool onlyBias){
//*************************************************************

  TPaveText *ali = new TPaveText(0.18,0.87,0.50,0.93,"NDC");  
  ali->SetFillColor(10);
  ali->SetTextColor(1);
  ali->SetTextFont(42);
  ali->SetMargin(0.);
  ali->SetLineColor(10);
  ali->SetShadowColor(10);
  // pt->SetTextAlign(11);
  TText *alitext = ali->AddText("Alignment: PCL"); //"Preliminary 2015 - 0T collision data");
  alitext->SetTextSize(0.04);

  TLegend *lego = new TLegend(0.18,0.80,0.78,0.92);
  lego-> SetNColumns(2);
  //TLegend *lego = new TLegend(0.18,0.77,0.50,0.86);
  lego->SetFillColor(10);
  lego->SetTextSize(0.04);
  lego->SetTextFont(42);
  lego->SetFillColor(10);
  lego->SetLineColor(10);
  lego->SetShadowColor(10);

  TPaveText *pt  = NULL;
  TPaveText *pt2 = NULL;
  TPaveText *pt3 = NULL;

  if(!onlyBias){ 
    pt =new TPaveText(0.179,0.955,0.260,0.985,"NDC");
  } else {
    pt =new TPaveText(0.179,0.955,0.260,0.985,"NDC");
  }

  pt->SetFillColor(10);
  pt->SetTextColor(1);
  pt->SetTextFont(61);
  // pt->SetTextAlign(11);
  TText *text1 = pt->AddText("CMS"); //"Preliminary 2015 - 0T collision data");
  text1->SetTextSize(0.05);
 
  float extraOverCmsTextSize  = 0.76;

  if(!onlyBias){ 
    pt2 =new TPaveText(0.3,0.95,0.503,0.98,"NDC");
  } else {
    pt2 =new TPaveText(0.3,0.95,0.503,0.98,"NDC");
  }

  pt2->SetFillColor(10);
  pt2->SetTextColor(1);
  pt2->SetTextFont(52);
  pt2->SetTextAlign(22);
  TText *text2 = pt2->AddText("work in progress");
  text2->SetTextSize(0.05*extraOverCmsTextSize);

  if(!onlyBias){ 
    pt3 =new TPaveText(0.6,0.95,0.98,0.98,"NDC");
  } else {
    pt3 =new TPaveText(0.6,0.95,0.98,0.98,"NDC");
  }

  pt3->SetFillColor(10);
  pt3->SetTextColor(1);
  pt3->SetTextFont(42);
  // pt2->SetTextAlign(11);
  TText *text3 = pt3->AddText("3.8T collision data 2015");
  text3->SetTextSize(0.05*extraOverCmsTextSize);

  canv->SetFillColor(10);  
  if(!onlyBias) {
    canv->Divide(2,1);
    
    canv->cd(1)->SetBottomMargin(0.12);
    canv->cd(1)->SetLeftMargin(0.17);
    canv->cd(1)->SetRightMargin(0.02);
    canv->cd(1)->SetTopMargin(0.06);  
    
    canv->cd(2)->SetBottomMargin(0.12);
    canv->cd(2)->SetLeftMargin(0.17);
    canv->cd(2)->SetRightMargin(0.02);
    canv->cd(2)->SetTopMargin(0.06);  
  
    canv->cd(1);
  } else {
    
    canv->cd()->SetBottomMargin(0.14);
    canv->cd()->SetLeftMargin(0.17);
    canv->cd()->SetRightMargin(0.02);
    canv->cd()->SetTopMargin(0.06);  
    canv->cd();

  }

  Double_t absmin(999.);
  Double_t absmax(-999.);

  for(Int_t i=0; i<nFiles; i++){
    if(meanplots[i]->GetMaximum()>absmax) absmax = meanplots[i]->GetMaximum();
    if(meanplots[i]->GetMinimum()<absmin) absmin = meanplots[i]->GetMinimum();
  }

  Double_t safeDelta=(absmax-absmin)/2.;
  Double_t theExtreme=std::max(absmax,TMath::Abs(absmin));

  for(Int_t i=0; i<nFiles; i++){

    TString myTitle = meanplots[i]->GetName();
    float axmin = -999;
    float axmax = 999.;
    int ndiv = 510;
    if(myTitle.Contains("eta")){
      axmin = -2.5;
      axmax = 2.5;
      ndiv = 505;
    } else if (myTitle.Contains("phi")){
      axmin = -TMath::Pi();
      axmax = TMath::Pi();
      ndiv = 510;
    } else  {
      std::cout<<"unrecongnized variable";
    }

    meanplots[i]->GetXaxis()->SetLabelOffset(999);
    meanplots[i]->GetXaxis()->SetTickLength(0);
    
    // Redraw the new axis 
    gPad->Update();
    TGaxis *newaxis =  new TGaxis(gPad->GetUxmin(),gPad->GetUymin(),
				  gPad->GetUxmax(),gPad->GetUymin(),
				  axmin,
				  axmax,
				  //meanplots[i]->GetXaxis()->GetXmin(),
				  //meanplots[i]->GetXaxis()->GetXmax(),
				  ndiv,"SDH");
    
    
    TGaxis *newaxisup =  new TGaxis(gPad->GetUxmin(),gPad->GetUymax(),
				    gPad->GetUxmax(),gPad->GetUymax(),
				    axmin,
				    axmax,
				    //meanplots[i]->GetXaxis()->GetXmin(),                                                                                                     
				    //meanplots[i]->GetXaxis()->GetXmax(),                                                                                                     
				    ndiv,"-SDH");
    
    newaxis->SetLabelOffset(0.02);
    newaxis->SetLabelFont(42);
    newaxis->SetLabelSize(.05);
    newaxis->Draw();

    newaxisup->SetLabelOffset(-0.02);
    newaxisup->SetLabelFont(42);
    newaxisup->SetLabelSize(0);
    newaxisup->Draw();
    
    if(i==0){
      //meanplots[i]->GetYaxis()->SetRangeUser(absmin-safeDelta/2.,absmax+safeDelta);
      std::cout<<"name is: "<< meanplots[i]->GetName() << " absmin:" <<absmin<<" absmax: "<<absmax<<" safeDelta: "<<safeDelta<<std::endl;
      TString theTitle = meanplots[i]->GetName();
      if( theTitle.Contains("Norm")){
	meanplots[i]->GetYaxis()->SetRangeUser(std::min(-0.48,absmin-safeDelta),std::max(0.48,absmax+safeDelta));
      } else {
	if(!onlyBias){
	  meanplots[i]->GetYaxis()->SetRangeUser(absmin-safeDelta,absmax+safeDelta);
	} else {
	  meanplots[i]->GetYaxis()->SetRangeUser(-theExtreme-(TMath::Abs(absmin)/10.),theExtreme+(TMath::Abs(absmax/10.)));
	}
	//meanplots[i]->GetYaxis()->SetRangeUser(-theExtreme,theExtreme);
      } 
      meanplots[i]->Draw("e1");

      if(onlyBias){
	Int_t nbins =  meanplots[i]->GetNbinsX();
	Double_t lowedge  = meanplots[i]->GetBinLowEdge(1);
	Double_t highedge = meanplots[i]->GetBinLowEdge(nbins+1);
	
	TH1F* hzero = DrawZero(meanplots[i],nbins,lowedge,highedge);
	hzero->Draw("PLsame");
      }

    }
    else meanplots[i]->Draw("e1sames");
    lego->AddEntry(meanplots[i],LegLabels[i]); 
  }  
  

  //ali->Draw();
  lego->Draw();
  pt->Draw("same");
  pt2->Draw("same");
  pt3->Draw("same");


  if(!onlyBias){

    canv->cd(2);
    Double_t absmax2(-999.);
    
    for(Int_t i=0; i<nFiles; i++){
      if(widthplots[i]->GetMaximum()>absmax2) absmax2 = widthplots[i]->GetMaximum();
    }
    
    Double_t safeDelta2=absmax2/3.;
    
    for(Int_t i=0; i<nFiles; i++){

      TString myTitle = widthplots[i]->GetName();
      float axmin = -999;
      float axmax = 999.;
      int ndiv = 510;
      if(myTitle.Contains("eta")){
	axmin = -2.5;
	axmax = 2.5;
	ndiv = 505;
      } else if (myTitle.Contains("phi")){
	axmin = -TMath::Pi();
	axmax = TMath::Pi();
	ndiv = 510;
      } else  {
	std::cout<<"unrecongnized variable";
      }
      
      widthplots[i]->GetXaxis()->SetLabelOffset(999);
      widthplots[i]->GetXaxis()->SetTickLength(0);
      
      // Redraw the new axis 
      gPad->Update();
      TGaxis *newaxis2 = new TGaxis(gPad->GetUxmin(),gPad->GetUymin(),
				    gPad->GetUxmax(),gPad->GetUymin(),
				    axmin,
				    axmax,
				    //widthplots[i]->GetXaxis()->GetXmin(),
				    //widthplots[i]->GetXaxis()->GetXmax(),
				    ndiv,"SDH");
      
      newaxis2->SetLabelOffset(0.02);
      newaxis2->SetLabelFont(42);
      newaxis2->SetLabelSize(.05);
      newaxis2->Draw();

      TGaxis *newaxis2up = new TGaxis(gPad->GetUxmin(),gPad->GetUymax(),
				      gPad->GetUxmax(),gPad->GetUymax(),
				      axmin,
				      axmax,
				      //widthplots[i]->GetXaxis()->GetXmin(),
				      //widthplots[i]->GetXaxis()->GetXmax(),
				      ndiv,"-SDH");
      
      newaxis2up->SetLabelOffset(-0.02);
      newaxis2up->SetLabelFont(42);
      newaxis2up->SetLabelSize(0.);
      newaxis2up->Draw();

      if(i==0) widthplots[i]->Draw("e1");
      else widthplots[i]->Draw("e1sames");
      widthplots[i]->SetMinimum(0.5);
      widthplots[i]->SetMaximum(absmax2+safeDelta2);
    }
    
    lego->Draw();
    pt->Draw("same");
    pt2->Draw("same");
    pt3->Draw("same");

  }
}
Example #5
0
void gluinoMass(double lumi=-1., double maxInstLumi=-1.) {
	
  if (lumi<0)
    lumi=877.;
  if (maxInstLumi<0)
    maxInstLumi=1300.;
  LimitPlots plots(lumi);
  
  plots.calculateCrossSections(7,4,39,9);
	
  // expected limit (1 and 2 sigma bands)
  TGraph* g_exp = plots.getExpMassLimitGluino();
  TGraphAsymmErrors* g_exp1 = plots.getExpMassLimitGluino1Sig();
  TGraphAsymmErrors* g_exp2 = plots.getExpMassLimitGluino2Sig();
  
  // three points on counting expt curve
  TGraph* g_gluino = plots.getMassLimitGluino();
  TGraph* g_stop = plots.getMassLimitStop();
  
  // one point from lifetime fit
  TGraph* g_tp = plots.getMassLimitGluinoTP();
  
  // theory prediction
  TGraph* g_thGluino = plots.getGluinoTheory();
  TGraph* g_thStop = plots.getStopTheory();
  
  TCanvas* canvas = new TCanvas("canvas");
  
  //canvas->SetGrid();
  canvas->SetLogy();
  
  TH1 * h;
  h = canvas->DrawFrame(300., .02, 1000., 1e2);
  //h->SetTitle("Beamgap Expt;m_{#tilde{g}} [GeV/c^{2}]; Stopped HSCP Cross Section #times BR [pb]");
  h->SetTitle("Beamgap Expt;m_{#tilde{g}} [GeV/c^{2}]; #sigma(pp #rightarrow #tilde{g}#tilde{g}) #times BR(#tilde{g} #rightarrow g#tilde{#chi}^{0}) [pb]");
  
  // not covered region
  TBox* nc = new TBox(100., .1, 150., 5e2);
  nc->SetFillStyle(3354);
  nc->SetFillColor(kRed-4);
  //nc->Draw();
  
  // details
  TPaveText* blurb = new TPaveText(300., 2, 550., 1e2);
  blurb->AddText("CMS Preliminary 2012");

  std::stringstream label;
  label<<"#int L dt = "<<lumi<<" fb^{-1}";
  blurb->AddText(label.str().c_str());
  label.str("");
  double peakInstLumi=maxInstLumi;
  int exponent=30;
  while (peakInstLumi>10) {
    peakInstLumi/=10.;
    ++exponent;
  }
  label<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
  blurb->AddText(label.str().c_str());
  label.str("");
  label << "#sqrt{s} = " << ENERGY << " TeV";
  blurb->AddText(label.str().c_str());
  blurb->AddText("m_{#tilde{g}} - m_{#tilde{#chi}^{0}} = 100 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{t}} - m_{#tilde{#chi}^{0}} = 200 GeV/c^{2}");	
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.032);

  
  // legend
  TBox *legbg = new TBox(600., 2., 900., 1e2);
  legbg->Draw();
  TLegend *leg = new TLegend(600., 2., 900., 1e2,"95% C.L. Limits","");
  leg->SetTextSize(0.028);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);
  leg->AddEntry(g_exp, "Expected: 10 #mus - 1000 s Counting Exp. ", "l");
  leg->AddEntry(g_exp1, "Expected #pm1#sigma: 10 #mus - 1000 s Counting Exp. ", "f");
  leg->AddEntry(g_exp2, "Expected #pm2#sigma: 10 #mus - 1000 s Counting Exp. ", "f");
  //	  leg->AddEntry(graph3, "Obs.: 10^{6} s Counting Exp.", "l");
  leg->AddEntry(g_gluino, "Obs.: 10 #mus - 1000 s Counting Exp. ", "l");
  leg->AddEntry(g_tp, "Obs.: 10 #mus Timing Profile ", "l");
  //leg->AddEntry(g_stop, "Obs.: 10 #mus - 1000 s Counting Exp. (#tilde{t})", "l");
  //leg->AddEntry(graph_em, "Obs.: 10 #mus - 1000 s Counting Exp. (EM only)", "l");
  //  leg->AddEntry(graph1, "Obs.: 570 ns Counting Exp.", "l");
  leg->Draw();
  
  
  
  // 2 sigma expected band
  g_exp2->SetLineColor(0);
  g_exp2->SetLineStyle(0);
  g_exp2->SetLineWidth(0);
  g_exp2->SetFillColor(5);
  g_exp2->SetFillStyle(1001);
  g_exp2->Draw("3");
  
  // 1 sigma expected band
  g_exp1->SetLineColor(0);
  g_exp1->SetLineStyle(0);
  g_exp1->SetLineWidth(0);
  g_exp1->SetFillColor(3);
  g_exp1->SetFillStyle(1001);
  g_exp1->Draw("3");  
  
  // expected line
  g_exp->SetLineStyle(2);
  g_exp->SetLineWidth(1);
  g_exp->Draw("l");
  
 
  // plateau limit - 1 ms
  g_gluino->SetLineColor(1);
  g_gluino->SetLineStyle(1);
  g_gluino->SetLineWidth(2);
  g_gluino->Draw("l");
  
  // stop curve
  g_stop->SetLineColor(1);
  g_stop->SetLineStyle(5);
  g_stop->SetLineWidth(2);
  //g_stop->Draw("l");
 

  // 1 mus lifetime fit limit
  g_tp->SetLineColor(kRed);
  g_tp->SetLineStyle(1);
  g_tp->SetLineWidth(2);
  g_tp->Draw("l");
  
  // theory line
  g_thGluino->SetLineColor(kBlue);
  g_thGluino->SetLineStyle(1);
  g_thGluino->SetLineWidth(2);
  g_thGluino->SetFillStyle(3001);
  g_thGluino->SetFillColor(kBlue-4);
  g_thGluino->Draw("l3");
  
  g_thStop->SetLineColor(kRed);
  g_thStop->SetLineStyle(1);
  g_thStop->SetLineWidth(2);
  g_thStop->SetFillStyle(3001);
  g_thStop->SetFillColor(kRed-4);
  //g_thStop->Draw("l3");


  // theory line label
  TLatex* th = new TLatex(600., .3, "NLO+NLL #tilde{g}");
  th->SetTextColor(kBlue);
  th->SetTextFont(42);
  th->SetTextSize(0.035);
  th->Draw();

  TLatex* ths = new TLatex(330., 2., "NLO+NLL #tilde{t}");
  ths->SetTextColor(kRed);
  ths->SetTextFont(42);
  ths->SetTextSize(0.035);
  //ths->Draw();

  // not explored label
  TText* ne = new TText(125., .2, "Not Sensitive");
  ne->SetTextColor(kRed+1);
  ne->SetTextFont(42);
  ne->SetTextAngle(90);
  ne->SetTextSize(0.035);
  //ne->Draw();

  blurb->Draw();

  canvas->RedrawAxis();

  canvas->Print("gluinoMassLimit.pdf");
  canvas->Print("gluinoMassLimit.C");

  plots.calculateIntercepts();
  
}
//void gluinostopMassLifetime(double lumi=4560., double maxInstLumi=5000.) {
void gluinostopMassLifetime(double lumi=4560.) {

  ExtraLimitPlots plots(lumi);
  //mchamp index 0 is used, corresponds to 0th mass point = 100 GeV
  plots.calculateCrossSections(7,4,3,0,39,9);

  // xsecs as extracted from nllfast http://web.physik.rwth-aachen.de/service/wiki/bin/view/Main/SquarksandGluinos
  // gluino (m_squark=m_gluino):  "nllfast gg mstw <mass> <mass>"
  // gluino (m_squark>>m_gluino): "nllfast gdcpl mstw <mass>"
  // stop: "nllfast st mstw <mass>"
  double g_mass [21] = {  
    200 ,     250 ,     300 ,     350 ,     400 ,   
    450 ,     500 ,     550 ,     600 ,     650 ,   
    700 ,     750 ,     800 ,     850 ,     900 ,   
    950 ,    1000 ,    1050 ,    1100 ,    1150 ,   
    1200 };
  double g_xsec [21] = {  
    1010,      302,     106,     42.6,     18.9,
    8.93,     4.52,    2.39,     1.31,    0.744,
    0.434,   0.259,   0.157,   0.0967,   0.0603,
    0.0381, 0.0244,  0.0157,   0.0102,  0.00667,
    0.00440
  };
  double g_xsecdcpl [21] = {  
    1010,      302,     106,     42.6,     18.9,
    8.93,     4.52,    2.39,     1.31,    0.744,
    0.434,   0.259,   0.157,   0.0967,   0.0603,
    0.0381, 0.0244,  0.0157,   0.0102,  0.00667,
    0.00440
  };
  double s_mass [21] = {  
    100 ,     150 ,     200 ,     250 ,     300 ,   
    350 ,     400 ,     450 ,     500 ,     550 ,   
    600 ,     650 ,     700 ,     750 ,     800 ,   
    850 ,     900 ,     950 ,    1000 ,    1050 ,   
    1100 
  };
  double s_xsec [21] = {  
    560,       80.3,     18.5,     5.58,     2.00,
    0.807,    0.357,    0.170,   0.0856,   0.0452,
    0.0248,  0.0140,  0.00811,  0.00480,  0.00290,
    0.00177,0.00110, 0.000687, 0.000435, 0.000278,
    0.000180 
  };
  double m_mass [10] = {  
    100 ,        200 ,     300 ,     400 ,     500 ,   
    600 ,        700 ,     800 ,     900 ,    1000 
  };
  double m_xsec [10] = {  
    1.88,      0.1402,      0.02622,   0.006968, 0.002257,
    0.0008183, 0.0003228, 0.0001333, 0.00005764, 0.0000254
  };

  //gluino xsec
  vector<double> masses;
  for (int i = 0; i < 21; ++i)  {
    masses.push_back(g_mass[i]);
    g_xsec [i] = log10 (g_xsec [i]*1e3) * 20.;
    g_xsecdcpl [i] = log10 (g_xsecdcpl [i]*1e3) * 20.;
  }
  //  Xsection gluino_xs (masses, g_xsec);
  Xsection gluino_xs (masses, g_xsecdcpl);
  
  //stop xsec
  masses.clear();
  for (int i = 0; i < 19; ++i)  {
    masses.push_back(s_mass[i]);
    s_xsec [i] = log10 (s_xsec [i]*1e3) * 20.;
  }
  Xsection stop_xs (masses, s_xsec);

  //mchamp xsec
  masses.clear();
  for (int i = 0; i < 10; ++i)  {
    masses.push_back(m_mass[i]);
    m_xsec [i] = log10 (m_xsec [i]*1e3) * 20.;
  }
  Xsection mchamp_xs (masses, m_xsec);
  
  // graphs
  TGraph* g_obs     = new TGraph (*plots.getLimitGluino());
  gluino_xs.xsec2mass (g_obs);

  TGraph* g_exp      = new TGraph (*plots.getExpLimitGluino());
  gluino_xs.xsec2mass (g_exp);
  TGraphAsymmErrors* g_exp_1sig = new TGraphAsymmErrors (*plots.getExpLimitGluino1Sig());
  gluino_xs.xsec2mass (g_exp_1sig);
  TGraphAsymmErrors* g_exp_2sig = new TGraphAsymmErrors (*plots.getExpLimitGluino2Sig());
  gluino_xs.xsec2mass (g_exp_2sig);

  TGraph* stop_obs     = new TGraph (*plots.getLimitStop());
  stop_xs.xsec2mass (stop_obs);

  TGraph* stop_exp      = new TGraph (*plots.getExpLimitStop());
  stop_xs.xsec2mass (stop_exp);
  TGraphAsymmErrors* stop_exp_1sig = new TGraphAsymmErrors (*plots.getExpLimitStop1Sig());
  stop_xs.xsec2mass (stop_exp_1sig);
  TGraphAsymmErrors* stop_exp_2sig = new TGraphAsymmErrors (*plots.getExpLimitStop2Sig());
  stop_xs.xsec2mass (stop_exp_2sig);


  TGraph* mchamp_obs     = new TGraph (*plots.getLimitMchamp());
  mchamp_xs.xsec2mass (mchamp_obs);

  TGraph* mchamp_exp      = new TGraph (*plots.getExpLimitMchamp());
  mchamp_xs.xsec2mass (mchamp_exp);
  TGraphAsymmErrors* mchamp_exp_1sig = new TGraphAsymmErrors (*plots.getExpLimitMchamp1Sig());
  mchamp_xs.xsec2mass (mchamp_exp_1sig);
  TGraphAsymmErrors* mchamp_exp_2sig = new TGraphAsymmErrors (*plots.getExpLimitMchamp2Sig());
  mchamp_xs.xsec2mass (mchamp_exp_2sig);

  
  TCanvas *canvas = new TCanvas("allMassLifetime", "allMassLifetime", 800, 600);
  
  canvas->SetLogx();
  canvas->SetGridy();

  
  TH1F* h = new TH1F ("h", "", 1,  7.5e-8, 1e6);
  h->SetStats (0);
  //h->SetMinimum (300);
  h->SetMinimum (0);
  //h->SetMaximum (1500);
  h->SetMaximum (600);
  h->SetTitle("Beamgap Expt");
  //  h->GetXaxis()->SetTitle("#tau_{#tilde{g},#tilde{t},#tilde{#tau}} [s]");
  h->GetXaxis()->SetTitle("#tau [s]");
  h->GetYaxis()->SetTitle("m [GeV]  ");
  h->Draw ("");

  
  
  // limit arrows
  double* x = g_obs->GetX();
  for (int i = 0; i < g_obs->GetN(); ++i) {
    if (x[i] > 0.5) {
      double y =  g_obs->GetY()[i];
      TArrow* arrow = new TArrow (x[i], y, h->GetXaxis()->GetXmin(), y, 0.02);
      arrow->SetLineColor (kRed);
      arrow->SetLineWidth (2);
      //arrow->Draw();
      cout << "GLUINO mass limit @ " << x[i] << "sec is found: " << y << endl;
      break;
    }
  }
  x = g_obs->GetX();
  for (int i = 0; i < stop_obs->GetN(); ++i) {
    if (x[i] > 0.5) {
      double y =  stop_obs->GetY()[i];
      TArrow* arrow = new TArrow (x[i], y, h->GetXaxis()->GetXmin(), y, 0.02);
      arrow->SetLineColor (kBlue);
      arrow->SetLineWidth (2);
      //arrow->Draw();
      cout << "STOP mass limit @ " << x[i] << "sec is found: " << y << endl;
      break;
    }
  }
  x = mchamp_obs->GetX();
  for (int i = 0; i < mchamp_obs->GetN(); ++i) {
    if (x[i] > 0.5) {
      double y =  mchamp_obs->GetY()[i];
      TArrow* arrow = new TArrow (x[i], y, h->GetXaxis()->GetXmin(), y, 0.02);
      arrow->SetLineColor (kBlack);
      arrow->SetLineWidth (2);
      arrow->Draw();
      cout << "MCHAMP mass limit @ " << x[i] << "sec is found: " << y << endl;
      break;
    }
  }
 
  // gluino  
  // 2 sigma band
  if (g_exp_2sig) {
    g_exp_2sig->SetLineColor(0);
    g_exp_2sig->SetLineStyle(0);
    g_exp_2sig->SetLineWidth(0);
    g_exp_2sig->SetFillColor(kYellow);
    g_exp_2sig->SetFillStyle(1001);
    //g_exp_2sig->Draw("3");
  }
  
  // 1 sigma band
  if (g_exp_1sig) {
    // g_exp_1sig->SetLineColor(8);
    g_exp_1sig->SetLineColor(0);
    g_exp_1sig->SetLineStyle(0);
    g_exp_1sig->SetLineWidth(0);
    // g_exp_1sig->SetFillColor(8);
    g_exp_1sig->SetFillColor(kGreen);
    g_exp_1sig->SetFillStyle(1001);
    // g_exp_1sig->SetFillStyle(3005);
    //g_exp_1sig->Draw("3");
    // g_exp_1sig->Draw("lX");
  }
  
  
  // epxected limit
  if (g_exp) {
    g_exp->SetLineColor(kRed);
    g_exp->SetLineStyle(4);
    g_exp->SetLineWidth(2);
    //g_exp->Draw("l3");
  }
  

  // observed limit
  if (g_obs) {
    g_obs->SetLineColor(kRed);
    g_obs->SetLineStyle(1);
    g_obs->SetLineWidth(2);
    //g_obs->Draw("l");
  }
  
  // stop  
  // 2 sigma band
  if (stop_exp_2sig) {
    stop_exp_2sig->SetLineColor(0);
    stop_exp_2sig->SetLineStyle(0);
    stop_exp_2sig->SetLineWidth(0);
    stop_exp_2sig->SetFillColor(kYellow);
    stop_exp_2sig->SetFillStyle(1001);
    //stop_exp_2sig->Draw("3");
  }
  
  // 1 sigma band
  if (stop_exp_1sig) {
    // stop_exp_1sig->SetLineColor(8);
    stop_exp_1sig->SetLineColor(0);
    stop_exp_1sig->SetLineStyle(0);
    stop_exp_1sig->SetLineWidth(0);
    // stop_exp_1sig->SetFillColor(8);
    stop_exp_1sig->SetFillColor(kGreen);
    stop_exp_1sig->SetFillStyle(1001);
    // stop_exp_1sig->SetFillStyle(3005);
    //stop_exp_1sig->Draw("3");
    // stop_exp_1sig->Draw("lX");
  }
  
  
  // epxected limit
  if (stop_exp) {
    stop_exp->SetLineColor(kBlue);
    stop_exp->SetLineStyle(3);
    stop_exp->SetLineWidth(2);
    //stop_exp->Draw("l3");
  }
  

  // observed limit
  if (stop_obs) {
    stop_obs->SetLineColor(kBlue);
    stop_obs->SetLineStyle(2);
    stop_obs->SetLineWidth(2);
    //stop_obs->Draw("l");
  }


  //mchamp
  // 2 sigma band
  if (mchamp_exp_2sig) {
    mchamp_exp_2sig->SetLineColor(0);
    mchamp_exp_2sig->SetLineStyle(0);
    mchamp_exp_2sig->SetLineWidth(0);
    mchamp_exp_2sig->SetFillColor(kYellow);
    mchamp_exp_2sig->SetFillStyle(1001);
    mchamp_exp_2sig->Draw("3");
  }
  
  // 1 sigma band
  if (mchamp_exp_1sig) {
    // mchamp_exp_1sig->SetLineColor(8);
    mchamp_exp_1sig->SetLineColor(0);
    mchamp_exp_1sig->SetLineStyle(0);
    mchamp_exp_1sig->SetLineWidth(0);
    // mchamp_exp_1sig->SetFillColor(8);
    mchamp_exp_1sig->SetFillColor(kGreen);
    mchamp_exp_1sig->SetFillStyle(1001);
    // mchamp_exp_1sig->SetFillStyle(3005);
    mchamp_exp_1sig->Draw("3");
    // mchamp_exp_1sig->Draw("lX");
  }
  
  
  // epxected limit
  if (mchamp_exp) {
    mchamp_exp->SetLineColor(kBlack);
    mchamp_exp->SetLineStyle(3);
    mchamp_exp->SetLineWidth(2);
    mchamp_exp->Draw("l3");
  }
  

  // observed limit
  if (mchamp_obs) {
    mchamp_obs->SetLineColor(kBlack);
    mchamp_obs->SetLineStyle(2);
    mchamp_obs->SetLineWidth(2);
    mchamp_obs->Draw("l");
  }

  
  

  TPaveText* blurb = new TPaveText(0.20, 0.63, 0.60, 0.90, "NDC");
  blurb->AddText("CMS Preliminary 2012");
  //blurb->AddText("CMS 2012");
  blurb->AddText("#int L dt = 19.7 fb^{-1}"); //,  #int L_{eff} dt = 935 pb^{-1}");
  //blurb->AddText("L^{max}_{inst} = 3.5 #times 10^{33} cm^{-2}s^{-1}");

  // std::stringstream label;
  // label<<"#int L dt = "<<lumi<<" pb^{-1}";
  // blurb->AddText(label.str().c_str());
  // double peakInstLumi=maxInstLumi;
  // int exponent=30;
  // while (peakInstLumi>10) {
  //   peakInstLumi/=10;
  //   ++exponent;
  // }
  // std::stringstream label2;
  // label2<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
//  blurb->AddText(label2.str().c_str());
  blurb->AddText("#sqrt{s} = 8 TeV");
  //blurb->AddText("E_{gluon} > 120 GeV, E_{top} > 150 GeV");
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.033);
  blurb->Draw();

  TLegend* leg = new TLegend(0.6, 0.62, 0.87, 0.90,"95% CL Limits:","NDC");
  leg->SetTextSize(0.033);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);

  //leg->AddEntry(g_obs, " #tilde{g} observed", "l");
  //leg->AddEntry(stop_obs, " #tilde{t} observed", "l");
  leg->AddEntry(mchamp_obs, "mchamp observed", "l");

  TGraph* expectedStyle1 = new TGraph (*g_exp);
  expectedStyle1->SetFillColor (g_exp_1sig->GetFillColor());
  TGraph* expectedStyle2 = new TGraph (*g_exp);
  expectedStyle2->SetFillColor (g_exp_2sig->GetFillColor());
  //leg->AddEntry(expectedStyle1, " #tilde{g} expected #pm1#sigma", "lf");
  //leg->AddEntry(expectedStyle2, " #tilde{g} expected #pm2#sigma", "lf");

  expectedStyle1 = new TGraph (*stop_exp);
  expectedStyle1->SetFillColor (stop_exp_1sig->GetFillColor());
  expectedStyle2 = new TGraph (*stop_exp);
  expectedStyle2->SetFillColor (stop_exp_2sig->GetFillColor());
  //leg->AddEntry(expectedStyle1, " #tilde{t} expected #pm1#sigma", "lf");
  //leg->AddEntry(expectedStyle2, " #tilde{t} expected #pm2#sigma", "lf");

  expectedStyle1 = new TGraph (*mchamp_exp);
  expectedStyle1->SetFillColor (mchamp_exp_1sig->GetFillColor());
  expectedStyle2 = new TGraph (*mchamp_exp);
  expectedStyle2->SetFillColor (mchamp_exp_2sig->GetFillColor());
  leg->AddEntry(expectedStyle1, "mchamp expected #pm1#sigma", "lf");
  leg->AddEntry(expectedStyle2, "mchamp expected #pm2#sigma", "lf");

  leg->Draw();

  h->Draw("sameaxis");

  canvas->Print("gluinostopmchampMassLifetime.png");
  canvas->Print("gluinostopmchampMassLifetime.pdf");
}
Example #7
0
void allInOneLifetime(double lumi=4560., double maxInstLumi=5000.) {

  ExtraLimitPlots plots(lumi);
  plots.calculateCrossSections(4,6,3,39,9);
  
  // graphs - observed
  TGraph* g_obs      = plots.getObsLimit();
  TGraph* g_exp      = plots.getExpLimit();
  TGraphAsymmErrors* g_exp_1sig = plots.getExpLimit1Sig();
  TGraphAsymmErrors* g_exp_2sig = plots.getExpLimit2Sig();

  TGraph* g_obs_gluino = plots.getLimitGluino();
  double gluino2ref    = g_obs_gluino->GetY()[0] / g_obs->GetY()[0];
  TGraph* g_obs_stop   = plots.getLimitStop();
  double stop2ref      = g_obs_stop->GetY()[0] / g_obs->GetY()[0];
  TGraph* g_obs_stau   = plots.getLimitStau();
  double stau2ref      = g_obs_stau->GetY()[0] / g_obs->GetY()[0];

  cout << "scales: " << g_obs->GetY()[0] 
       << '/' <<g_obs_gluino->GetY()[0]
       << '/' <<g_obs_stop->GetY()[0]
       << '/' <<g_obs_stau->GetY()[0]
       <<endl;

  
  TCanvas *canvas = new TCanvas("allLifetime", "allLifetime", 1000, 600);
  
  canvas->SetLogx();
  canvas->SetLogy();

  canvas->SetRightMargin(0.8*canvas->GetLeftMargin());
  canvas->SetLeftMargin(1.2*canvas->GetLeftMargin());
  canvas->SetTicks (canvas->GetTickx(), 0);
  
  TH1F* h = new TH1F ("h", "", 1, 7.5e-8, 1e6);
  h->SetStats (0);
  h->SetMinimum (.0001);
  h->SetMaximum (0.99e1);
  // TH1* h = canvas->DrawFrame(7.5e-8, .001, 1e6, 1e2, "Y+");
  h->SetTitle("Beamgap Expt");
  //  h->GetXaxis()->SetTitle("#tau_{#tilde{g},#tilde{t},#tilde{#tau}} [s]");
  h->GetXaxis()->SetTitle("#tau [s]");
  h->GetYaxis()->SetTitle("#sigma #times BF #times #varepsilon_{stopping} #times #varepsilon_{reco}   [pb]  ");
  h->Draw ("Y+");

  ExtraAxis aGluino = anotherScale (h, gluino2ref, kRed+2, "#sigma(pp #rightarrow #tilde{g}#tilde{g}) #times BF(#tilde{g} #rightarrow g#tilde{#chi}^{0})   [pb]  ", 0.0);

  ExtraAxis aStop = anotherScale (h, stop2ref, kBlue+2, "#sigma(pp #rightarrow #tilde{t}#tilde{t}) #times BF(#tilde{t} #rightarrow t#tilde{#chi}^{0})   [pb]  ", 0.2);

  ExtraAxis aStau = anotherScale (h, stau2ref, kGreen+2, "#sigma(pp #rightarrow #tilde{#tau}#tilde{#tau}) #times BF(#tilde{#tau} #rightarrow #tau#tilde{#chi}^{0})   [pb]  ", 0.4);


  
  
  TPaveText* blurb = new TPaveText(0.25, 0.57, 0.50, 0.87, "NDC");

  blurb->AddText("CMS Preliminary 2015");
  // std::stringstream label;
  // label<<"#int L dt = "<<lumi<<" pb^{-1}";
  // blurb->AddText(label.str().c_str());
  // double peakInstLumi=maxInstLumi;
  // int exponent=30;
  // while (peakInstLumi>10) {
  //   peakInstLumi/=10;
  //   ++exponent;
  // }
  // std::stringstream label2;
  // label2<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
  // blurb->AddText(label2.str().c_str());

  //blurb->AddText("CMS 2011");
  blurb->AddText("#int L dt = 2.46 fb^{-1}");//,  #int L_{eff} dt = 935 pb^{-1}");
  //blurb->AddText("L^{max}_{inst} = 3.5 #times 10^{33} cm^{-2}s^{-1}");
  blurb->AddText("#sqrt{s} = 13 TeV");
  blurb->AddText("E_{g} > 120 GeV, E_{t} > 150 GeV");
  blurb->AddText("E_{jet} > 70 GeV");
  //blurb->AddText("m_{#tilde{g}} = 300 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{#chi}^{0}} = 200 GeV/c^{2}");
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.033);
  blurb->Draw();
  
  
  // 2 sigma band
  if (g_exp_2sig) {
    g_exp_2sig->SetLineColor(0);
    g_exp_2sig->SetLineStyle(0);
    g_exp_2sig->SetLineWidth(0);
    g_exp_2sig->SetFillColor(kYellow);
    g_exp_2sig->SetFillStyle(1001);
    g_exp_2sig->Draw("3");
  }
  
  // 1 sigma band
  if (g_exp_1sig) {
    // g_exp_1sig->SetLineColor(8);
    g_exp_1sig->SetLineColor(0);
    g_exp_1sig->SetLineStyle(0);
    g_exp_1sig->SetLineWidth(0);
    // g_exp_1sig->SetFillColor(8);
    g_exp_1sig->SetFillColor(kGreen);
    g_exp_1sig->SetFillStyle(1001);
    // g_exp_1sig->SetFillStyle(3005);
    g_exp_1sig->Draw("3");
    // g_exp_1sig->Draw("lX");
  }
  
  
  // GLUINO LIMIT
  if (g_exp) {
    g_exp->SetLineColor(1);
    g_exp->SetLineStyle(4);
    g_exp->SetLineWidth(2);
    g_exp->Draw("l3");
  }
  
  TLine *l;
  l = new TLine(7.5e-8, 1.49/gluino2ref, 1e6, 1.49/gluino2ref); //600 GeV
  l->SetLineColor(kRed);
  l->SetLineWidth(2);
  l->Draw();
  
  TLatex *t1;
  t1 = new TLatex(0.1, 0.7/gluino2ref, "#sigma_{theory} (m_{#tilde{g}} = 800 GeV)");
  t1->SetTextColor(kRed);
  t1->SetTextFont(42);
  t1->SetTextSize(0.035);
  t1->Draw();

  // STOP LIMIT
  TLine *ltop = new TLine(7.5e-8, 0.028/stop2ref, 1e6, 0.028/stop2ref); //600 GeV
  ltop->SetLineColor(kBlue);
  ltop->SetLineWidth(2);
  ltop->Draw();
  
  TLatex *t1top;
  t1top = new TLatex(0.1, 0.015/stop2ref, "#sigma_{theory} (m_{#tilde{t}} = 800 GeV)");
  t1top->SetTextColor(kBlue);
  t1top->SetTextFont(42);
  t1top->SetTextSize(0.035);
  t1top->Draw();
  

  // observed limit
  if (g_obs) {
    g_obs->SetLineColor(1);
    g_obs->SetLineStyle(1);
    g_obs->SetLineWidth(2);
    g_obs->Draw("l");
  }
  
  

  TLegend* leg = new TLegend(0.67, 0.65, 0.82, 0.87,"95% CL Limits:","NDC");
  leg->SetTextSize(0.033);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);
  TGraph* expectedStyle1 = new TGraph (*g_exp);
  expectedStyle1->SetFillColor (g_exp_1sig->GetFillColor());
  TGraph* expectedStyle2 = new TGraph (*g_exp);
  expectedStyle2->SetFillColor (g_exp_2sig->GetFillColor());
  cout << "colors: " << g_exp_1sig->GetFillColor() << ':' << g_exp_2sig->GetFillColor() << endl;
  leg->AddEntry(g_obs, "Observed", "l");
  leg->AddEntry(expectedStyle1, "Expected #pm1#sigma", "lf");
  leg->AddEntry(expectedStyle2, "Expected #pm2#sigma", "lf");
  //leg->AddEntry(g_obs_stop,"Obs.: Counting Exp. (#tilde{t})", "l");
  //leg->AddEntry(g_obs_nb, "Obs.: Counting Exp. (Neutral R-Baryon)", "l");
  //leg->AddEntry(g_obs_em, "Observed: Counting Exp. (EM only)", "l");
  //leg->AddEntry(g_obs_tp, "Observed: Timing Profile", "l");
  leg->Draw();

  h->Draw("sameaxis y+");
  aGluino.Draw();
  aStop.Draw();
  //aStau.Draw();

  canvas->Print("allInOneLifetime.png");
  canvas->Print("allInOneLifetime.pdf");
}
Example #8
0
void modelIndLimit(double lumi=-1.,double maxInstLumi=-1.) 
{
  if (lumi<0)
    lumi=LUMI;
  if (maxInstLumi<0)
    maxInstLumi=MAXINSTLUMI;
  LimitPlots plots(lumi);
	
  plots.calculateCrossSections(7,4,39,9);

  // graphs - observed
  TGraph* g_gluino  = plots.getLimitGluinoBasic();
  TGraph* g_stop    = plots.getLimitStopBasic();
  
  TCanvas *canvas;
  canvas = new TCanvas("basicPlot");

  //canvas->SetGrid();
  canvas->SetLogx();
  canvas->SetLogy();

  TH1* h = canvas->DrawFrame(7.5e-8, 3e-3, 1e6, 10);
  //	h->SetTitle("Beamgap Expt;#tau_{#tilde{g}} [s]; #sigma(pp #rightarrow #tilde{g}#tilde{g}) #times BR(#tilde{g} #rightarrow g#tilde{#chi}^{0}) #times #varepsilon^{#tilde{g}#tilde{g}}_{stop} [pb]");
  h->SetTitle("Beamgap Expt;#tau_{HSCP} [s]; Model Independent Cross-section [pb]");

  TPaveText* blurb = new TPaveText(5e-7, .5, 1e-2, 7);
  blurb->AddText("CMS Preliminary 2012");

  std::stringstream label;
  label<<"#int L dt = "<<lumi<<" fb^{-1}";
  blurb->AddText(label.str().c_str());

  label.str("");
  double peakInstLumi=maxInstLumi;
  int exponent=30;
  while (peakInstLumi>10) {
    peakInstLumi/=10;
    ++exponent;
  }
  label<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
  blurb->AddText(label.str().c_str());

  //	blurb->AddText("LUMI pb^{-1}");
  //	blurb->AddText("L^{max}_{inst} = MAXLUMI 10^{33} cm^{-2}s^{-1}");
	
  label.str("");
  label << "#sqrt{s} = " << ENERGY << " TeV";
  blurb->AddText(label.str().c_str());
  //blurb->AddText("m_{HSCP} - m_{#tilde{#chi}^{0}} = 100 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{g}} = 300 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{#chi}^{0}} = 200 GeV/c^{2}");
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.033);
  blurb->Draw();


  //	TPaveText* cms = new TPaveText(1e-6, 1.5e1, 1e-2, 2e1);
  //	cms->AddText("CMS 2011");
  //	cms->SetTextFont(62);
  //	cms->SetBorderSize(0);
  //	cms->SetFillColor(0);
  //	cms->SetShadowColor(0);
  //	cms->SetTextAlign(12);
  //	cms->SetTextSize(0.040);
  //	cms->Draw();


  TLegend* leg = new TLegend(2e-2, .5, 1e2, 7,"95% C.L. Limits:","");
  leg->SetTextSize(0.030);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);
  leg->AddEntry(g_gluino, "Gluino : m_{#tilde{g}}=500 GeV/c^{2}, m_{#tilde{#chi^{0}}}=387 GeV/c^{2}", "l");
  leg->AddEntry(g_stop, "Stop  : m_{#tilde{t}}=300 GeV/c^{2}, m_{#tilde{#chi^{0}}}=109 GeV/c^{2}", "l");
  leg->Draw();

  g_gluino->SetLineColor(2);
  g_gluino->SetLineStyle(1);
  g_gluino->SetLineWidth(2);
  g_gluino->Draw("l");

  g_stop->SetLineColor(4);
  g_stop->SetLineStyle(1);
  g_stop->SetLineWidth(2);
  g_stop->Draw("l");

  canvas->Print("basicLimit.png");
  canvas->Print("basicLimit.pdf");
  canvas->Print("basicLimit.C");

  return;

}
Example #9
0
void MakeClosurePlot(TH1D* hObs, TH1D* hPred, TString name, bool logy=true) {
  set_style(hObs,"data_obs");
  set_style(hPred,"pred");

  // Setup canvas and pads
  TCanvas * c1 = new TCanvas("c1", "c1", 700, 700);
  c1->SetFillStyle(4000);
  TPad * pad1 = new TPad("pad1", "top pad" , 0.0, 0.3, 1.0, 1.0);
  pad1->SetFillStyle(4000);
  pad1->SetBottomMargin(0.0);
  pad1->Draw();
  TPad * pad2 = new TPad("pad2", "bottom pad", 0.0, 0.0, 1.0, 0.3);
  pad2->SetFillStyle(4000);
  pad2->SetTopMargin(0.0);
  pad2->SetBottomMargin(0.35);
  pad2->Draw();
  pad1->cd();
  pad1->SetLogy(logy);

  TH1D * staterr = (TH1D *) hPred->Clone("staterr");
  //  staterr->Sumw2();
  //staterr->SetFillColor(kRed);
  staterr->SetFillColor(kGray+3);
  staterr->SetMarkerSize(0);
  staterr->SetFillStyle(3013);

  //cout << "Compute ratio hist..." << endl;
  TH1D * ratio = (TH1D *) hPred->Clone("ratio");
  //ratio->Sumw2();
  ratio->SetMarkerSize(0.8);
  ratio->SetMarkerColor(1);
  //ratio->SetMarkerSize(0.5);
  ratio->Divide(hObs, hPred, 1., 1., "B");
  ratio->Print("all");
  TH1D * ratiostaterr = (TH1D *) hObs->Clone("ratiostaterr");
  //  ratiostaterr->Sumw2();
  ratiostaterr->SetStats(0);
  ratiostaterr->SetTitle(hPred->GetTitle());
  ratiostaterr->GetYaxis()->SetTitle("Obs/Pred.");
  ratiostaterr->SetMaximum(2.2);
  ratiostaterr->SetMinimum(0);
  ratiostaterr->SetMarkerSize(0);
  //ratiostaterr->SetFillColor(kRed);
  ratiostaterr->SetFillColor(kGray+3);
  ratiostaterr->SetFillStyle(3013);
  ratiostaterr->GetXaxis()->SetLabelSize(0.2);
  ratiostaterr->GetXaxis()->SetLabelOffset(0.03);
  ratiostaterr->GetXaxis()->SetTitleSize(0.14);
  ratiostaterr->GetXaxis()->SetTitleOffset(1.10);
  ratiostaterr->GetYaxis()->SetLabelSize(0.10);
  ratiostaterr->GetYaxis()->SetTitleSize(0.12);
  ratiostaterr->GetYaxis()->SetTitleOffset(0.6);
  ratiostaterr->GetYaxis()->SetNdivisions(505);
  TLine* ratiounity = new TLine(hPred->GetBinLowEdge(1),1,hPred->GetBinLowEdge(hPred->GetNbinsX()+1),1);
  ratiounity->SetLineStyle(2);
  for (Int_t i = 0; i < hPred->GetNbinsX()+2; i++) {
    // if (hObs->GetBinContent(i)>0.) ratio->SetBinError(i, hObs->GetBinError(i)/hObs->GetBinContent(i)); // just the fractional uncertainty on the observation
    ratiostaterr->SetBinContent(i, 1.0);
    if (hPred->GetBinContent(i) > 1e-6) { //< not empty
      double binerror = hPred->GetBinError(i) / hPred->GetBinContent(i);
      ratiostaterr->SetBinError(i, binerror);
    } else {
      ratiostaterr->SetBinError(i, 999.);
    }
  }
  TH1D * ratiosysterr = (TH1D *) ratiostaterr->Clone("ratiosysterr");
  //  ratiosysterr->Sumw2();
  ratiosysterr->SetMarkerSize(0);
  ratiosysterr->SetFillColor(kYellow-4);
  //ratiosysterr->SetFillStyle(3002);
  ratiosysterr->SetFillStyle(1001);
  for (Int_t i = 0; i < hPred->GetNbinsX()+2; i++) {
    if (hPred->GetBinContent(i) > 1e-6) { //< not empty
      double binerror2 = (pow(hPred->GetBinError(i), 2));
      double binerror = sqrt(binerror2);
      ratiosysterr->SetBinError(i, binerror / hPred->GetBinContent(i));
    }
  }


  double max = hObs->GetMaximum();
  if (hPred->GetMaximum() > max) max = hPred->GetMaximum();

  if (logy) {
    hPred->SetMaximum(max*10);
    hPred->SetMinimum(0.09);
  } else {
    hPred->SetMaximum(max*1.5);
    hPred->SetMinimum(0.);
  }

  hPred->GetYaxis()->SetTitle("Events / bin");
  hPred->Draw("hist");
  hObs->Draw("e1,same");
  staterr->Draw("e2 same");
  hPred->GetXaxis()->SetTitleSize(0.035);
  hPred->GetXaxis()->SetLabelSize(0.035);
  /* hObs->GetYaxis()->SetTitleSize(0.035); */
  /* hObs->GetYaxis()->SetLabelSize(0.035); */

  TLegend * leg2 = new TLegend(0.72, 0.68, 0.94, 0.92);
  set_style(leg2,0.035);
  leg2->AddEntry(hObs,"Obs.","elp");
  leg2->AddEntry(hPred,"Pred.","f");
  leg2->AddEntry(staterr, "Syst. uncert.", "f");
  leg2->Draw();
  TLatex * latex = new TLatex();
  latex->SetNDC();
  latex->SetTextAlign(12);
  latex->SetTextFont(62);
  latex->SetTextSize(0.042);
  latex->DrawLatex(0.19, 0.89, "CMS Simulation");
  latex->SetTextSize(0.03);
  TString stamp = Form("#sqrt{s} = 13 TeV, L = %3.1f fb^{-1}", int_lumi);
  latex->DrawLatex(0.19, 0.84, stamp);

  pad2->cd();
  pad2->SetGridy(0);
  ratiostaterr->GetXaxis()->SetRangeUser(0,6);
  ratiostaterr->Draw("e2");
  //ratiosysterr->Draw("e2 same");
  ratiostaterr->Draw("e2 same");
  ratiounity->Draw();
  ratio->Draw("e1 same");

  TPaveText * pave = new TPaveText(0.18, 0.86, 0.4, 0.96, "brNDC");
  pave->SetLineColor(0);
  pave->SetFillColor(kWhite);
  pave->SetShadowColor(0);
  pave->SetBorderSize(1);
  double nchisq = hObs->Chi2Test(hPred, "UWCHI2/NDF, P"); // MC uncert. (stat)
  double p_value = hObs->Chi2Test(hPred, "UW"); // MC uncert. (stat)
  // //double kolprob = hdata_obs->KolmogorovTest(hmc_pred); // MC uncert. (stat)
  TText * text = pave->AddText(Form("#chi_{#nu}^{2}/ndf = %.3f, p = %.3f", nchisq, p_value));
  // //TText * text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f", nchisq, kolprob));
  text->SetTextFont(62);
  text->SetTextSize(0.07);
  // text->SetTextSize(0.06);
  pave->Draw();
  
  /* TLegend * ratioleg = new TLegend(0.72, 0.88, 0.94, 0.96); */
  /* set_style(ratioleg); */
  /* ratioleg->SetTextSize(0.07); */
  /* ratioleg->AddEntry(ratiostaterr, "MC uncert. (stat)", "f"); */
  /* ratioleg->Draw(); */

  pad1->cd();
  gPad->RedrawAxis();
  gPad->Modified();
  gPad->Update();
  pad2->cd();
  gPad->RedrawAxis();
  gPad->Modified();
  gPad->Update();

  c1->cd();
  
  c1->Print("Closure/plots/no_dp_cut/"+name+".pdf");

  delete staterr;
  delete ratio;
  delete ratiostaterr;
  delete ratiosysterr;
  delete leg2;
  // delete ratioleg;
  delete pad1;
  delete pad2;
  delete c1;
  delete latex;
  
}
void gluinostopMassLifetime(double lumi=4560., double maxInstLumi=5000.) {

  ExtraLimitPlots plots(lumi);
  plots.calculateCrossSections(4,6,3,39,9);

  // xsecs as extracted from nllfast http://web.physik.rwth-aachen.de/service/wiki/bin/view/Main/SquarksandGluinos
  // gluino (m_squark=m_gluino):  "nllfast gg mstw <mass> <mass>"
  // gluino (m_squark>>m_gluino): "nllfast gdcpl mstw <mass>"
  // stop: "nllfast st mstw <mass>"
  // the xsec of gluino and stop are updated for 13TeV analysis, the xsecs are extracted from:
  // https://twiki.cern.ch/twiki/bin/view/LHCPhysics/SUSYCrossSections#Cross_sections_for_various_S_AN2
  double g_mass [21] = {  
    200 ,     250 ,     300 ,     350 ,     400 ,   
    450 ,     500 ,     550 ,     600 ,     650 ,   
    700 ,     750 ,     800 ,     850 ,     900 ,   
    950 ,    1000 ,    1050 ,    1100 ,    1150 ,   
    1200 };
  double g_xsec [21] = {  
    3574,      1190,     462,     202,     98.0,
    50.4,      27.4,    15.6,     9.20,    5.60,
    3.53,      2.27,     1.49,   0.996,   0.677,
    0.466,     0.325,  0.229,   0.163,  0.118,
    0.0856
  };
  double g_xsecdcpl [21] = {  
    3574,      1190,     462,     202,     98.0,
    50.4,      27.4,    15.6,     9.20,    5.60,
    3.53,      2.27,     1.49,   0.996,   0.677,
    0.466,     0.325,  0.229,   0.163,  0.118,
    0.0856
  };
  double s_mass [21] = {  
    100 ,     150 ,     200 ,     250 ,     300 ,   
    350 ,     400 ,     450 ,     500 ,     550 ,   
    600 ,     650 ,     700 ,     750 ,     800 ,   
    850 ,     900 ,     950 ,    1000 ,    1050 ,   
    1100 };
  double s_xsec [21] = {  
    1521,       249.4,     64.5,     21.6,     8.51,
    3.79,        1.84,    0.948,   0.518,   0.296,
    0.175,      0.107,  0.067,  0.0431,  0.0283,
    0.0190,    0.0129, 0.00883, 0.00615, 0.00432,
    0.00307
  };

  //gluino xsec
  vector<double> masses;
  for (int i = 0; i < 21; ++i)  {
    masses.push_back(g_mass[i]);
    g_xsec [i] = log10 (g_xsec [i]*1e3) * 20.;
    g_xsecdcpl [i] = log10 (g_xsecdcpl [i]*1e3) * 20.;
  }
  //  Xsection gluino_xs (masses, g_xsec);
  Xsection gluino_xs (masses, g_xsecdcpl);
  
  //stop xsec
  masses.clear();
  for (int i = 0; i < 19; ++i)  {
    masses.push_back(s_mass[i]);
    s_xsec [i] = log10 (s_xsec [i]*1e3) * 20.;
  }
  Xsection stop_xs (masses, s_xsec);
  
  // graphs
  TGraph* g_obs     = new TGraph (*plots.getLimitGluino());
  gluino_xs.xsec2mass (g_obs);

  TGraph* g_exp      = new TGraph (*plots.getExpLimitGluino());
  gluino_xs.xsec2mass (g_exp);
  TGraphAsymmErrors* g_exp_1sig = new TGraphAsymmErrors (*plots.getExpLimitGluino1Sig());
  gluino_xs.xsec2mass (g_exp_1sig);
  TGraphAsymmErrors* g_exp_2sig = new TGraphAsymmErrors (*plots.getExpLimitGluino2Sig());
  gluino_xs.xsec2mass (g_exp_2sig);

  TGraph* stop_obs     = new TGraph (*plots.getLimitStop());
  stop_xs.xsec2mass (stop_obs);

  TGraph* stop_exp      = new TGraph (*plots.getExpLimitStop());
  stop_xs.xsec2mass (stop_exp);
  TGraphAsymmErrors* stop_exp_1sig = new TGraphAsymmErrors (*plots.getExpLimitStop1Sig());
  stop_xs.xsec2mass (stop_exp_1sig);
  TGraphAsymmErrors* stop_exp_2sig = new TGraphAsymmErrors (*plots.getExpLimitStop2Sig());
  stop_xs.xsec2mass (stop_exp_2sig);

  
  TCanvas *canvas = new TCanvas("allMassLifetime", "allMassLifetime", 800, 600);
  
  canvas->SetLogx();
//  canvas->SetGridy();

  
  TH1F* h = new TH1F ("h", "", 1,  7.5e-8, 1e6);
  h->SetStats (0);
  h->SetMinimum (300);
  h->SetMaximum (2000);
  h->SetTitle("Beamgap Expt");
  //  h->GetXaxis()->SetTitle("#tau_{#tilde{g},#tilde{t},#tilde{#tau}} [s]");
  h->GetXaxis()->SetTitle("#tau [s]");
  h->GetYaxis()->SetTitle("m [GeV]  ");
  h->Draw ("");

  
  
  // limit arrows
  double* x = g_obs->GetX();
  for (int i = 0; i < g_obs->GetN(); ++i) {
    if (x[i] > 0.5) {
      double y =  g_obs->GetY()[i];
      TArrow* arrow = new TArrow (x[i], y, h->GetXaxis()->GetXmin(), y, 0.02);
      arrow->SetLineColor (kRed);
      arrow->SetLineWidth (2);
      //arrow->Draw();
      cout << "GLUINO mass limit @ " << x[i] << "sec is found: " << y << endl;
      break;
    }
  }
  x = g_obs->GetX();
  for (int i = 0; i < stop_obs->GetN(); ++i) {
    if (x[i] > 0.5) {
      double y =  stop_obs->GetY()[i];
      TArrow* arrow = new TArrow (x[i], y, h->GetXaxis()->GetXmin(), y, 0.02);
      arrow->SetLineColor (kBlue);
      arrow->SetLineWidth (2);
      //arrow->Draw();
      cout << "STOP mass limit @ " << x[i] << "sec is found: " << y << endl;
      break;
    }
  }
 
  // gluino  
  // 2 sigma band
  if (g_exp_2sig) {
    g_exp_2sig->SetLineColor(0);
    g_exp_2sig->SetLineStyle(0);
    g_exp_2sig->SetLineWidth(0);
    g_exp_2sig->SetFillColor(kYellow);
    g_exp_2sig->SetFillStyle(1001);
    g_exp_2sig->Draw("3");
  }
  
  // 1 sigma band
  if (g_exp_1sig) {
    // g_exp_1sig->SetLineColor(8);
    g_exp_1sig->SetLineColor(0);
    g_exp_1sig->SetLineStyle(0);
    g_exp_1sig->SetLineWidth(0);
    // g_exp_1sig->SetFillColor(8);
    g_exp_1sig->SetFillColor(kGreen);
    g_exp_1sig->SetFillStyle(1001);
    // g_exp_1sig->SetFillStyle(3005);
    g_exp_1sig->Draw("3");
    // g_exp_1sig->Draw("lX");
  }
  
  
  // epxected limit
  if (g_exp) {
    g_exp->SetLineColor(kRed);
    g_exp->SetLineStyle(4);
    g_exp->SetLineWidth(2);
    g_exp->Draw("l3");
  }
  

  // observed limit
  if (g_obs) {
    g_obs->SetLineColor(kRed);
    g_obs->SetLineStyle(1);
    g_obs->SetLineWidth(2);
    g_obs->Draw("l");
  }
  
  // stop  
  // 2 sigma band
  if (stop_exp_2sig) {
    stop_exp_2sig->SetLineColor(0);
    stop_exp_2sig->SetLineStyle(0);
    stop_exp_2sig->SetLineWidth(0);
    stop_exp_2sig->SetFillColor(kYellow);
    stop_exp_2sig->SetFillStyle(1001);
    stop_exp_2sig->Draw("3");
  }
  
  // 1 sigma band
  if (stop_exp_1sig) {
    // stop_exp_1sig->SetLineColor(8);
    stop_exp_1sig->SetLineColor(0);
    stop_exp_1sig->SetLineStyle(0);
    stop_exp_1sig->SetLineWidth(0);
    // stop_exp_1sig->SetFillColor(8);
    stop_exp_1sig->SetFillColor(kGreen);
    stop_exp_1sig->SetFillStyle(1001);
    // stop_exp_1sig->SetFillStyle(3005);
    stop_exp_1sig->Draw("3");
    // stop_exp_1sig->Draw("lX");
  }
  
  
  // epxected limit
  if (stop_exp) {
    stop_exp->SetLineColor(kBlue);
    stop_exp->SetLineStyle(3);
    stop_exp->SetLineWidth(2);
    stop_exp->Draw("l3");
  }
  

  // observed limit
  if (stop_obs) {
    stop_obs->SetLineColor(kBlue);
    stop_obs->SetLineStyle(2);
    stop_obs->SetLineWidth(2);
    stop_obs->Draw("l");
  }
  
  

  TPaveText* blurb = new TPaveText(0.20, 0.63, 0.60, 0.90, "NDC");
  blurb->AddText("CMS Preliminary 2015");
  //blurb->AddText("CMS 2012");
  blurb->AddText("#int L dt = 2.46 fb^{-1}"); //,  #int L_{eff} dt = 935 pb^{-1}");
  //blurb->AddText("L^{max}_{inst} = 3.5 #times 10^{33} cm^{-2}s^{-1}");

  // std::stringstream label;
  // label<<"#int L dt = "<<lumi<<" pb^{-1}";
  // blurb->AddText(label.str().c_str());
  // double peakInstLumi=maxInstLumi;
  // int exponent=30;
  // while (peakInstLumi>10) {
  //   peakInstLumi/=10;
  //   ++exponent;
  // }
  // std::stringstream label2;
  // label2<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
//  blurb->AddText(label2.str().c_str());
  blurb->AddText("#sqrt{s} = 13 TeV");
  blurb->AddText("E_{g} > 120 GeV, E_{t} > 150 GeV");
  blurb->AddText("E_{jet} > 70 GeV");
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.033);
  blurb->Draw();

  TLegend* leg = new TLegend(0.6, 0.62, 0.87, 0.90,"95% CL Limits:","NDC");
  leg->SetTextSize(0.033);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);

  leg->AddEntry(g_obs, " #tilde{g} observed", "l");
  leg->AddEntry(stop_obs, " #tilde{t} observed", "l");

  TGraph* expectedStyle1 = new TGraph (*g_exp);
  expectedStyle1->SetFillColor (g_exp_1sig->GetFillColor());
  TGraph* expectedStyle2 = new TGraph (*g_exp);
  expectedStyle2->SetFillColor (g_exp_2sig->GetFillColor());
  leg->AddEntry(expectedStyle1, " #tilde{g} expected #pm1#sigma", "lf");
  leg->AddEntry(expectedStyle2, " #tilde{g} expected #pm2#sigma", "lf");

  expectedStyle1 = new TGraph (*stop_exp);
  expectedStyle1->SetFillColor (stop_exp_1sig->GetFillColor());
  expectedStyle2 = new TGraph (*stop_exp);
  expectedStyle2->SetFillColor (stop_exp_2sig->GetFillColor());
  leg->AddEntry(expectedStyle1, " #tilde{t} expected #pm1#sigma", "lf");
  leg->AddEntry(expectedStyle2, " #tilde{t} expected #pm2#sigma", "lf");
  leg->Draw();

  h->Draw("sameaxis");

  canvas->Print("gluinostopMassLifetime.png");
  canvas->Print("gluinostopMassLifetime.pdf");
}
Example #11
0
void EleScaleClosureTest() {

  //--------------------------------------------------------------------------------------------------------------
  // Settings 
  //============================================================================================================== 
  
  // event category enumeration
  enum { eEleEle2HLT=1, eEleEle1HLT1L1, eEleEle1HLT, eEleEleNoSel, eEleSC };
  
  // Create output directory
  TString outputDir = "EleScaleClosureTestResults";
  TString pufname = "../Tools/pileup_weights_2015B.root";

  gSystem->mkdir(outputDir,kTRUE);
  
  vector<TString> infilenamev;
  infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zee/ntuples/data_select.root");    // data
  infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zee/ntuples/zee_select.raw.root"); // MC (raw)
  infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zee/ntuples/zee_select.raw.root"); // MC2 (corrected)

  enum { eData=0, eMC, eMC2 };

  Float_t lumi=40.0;
  
  const Int_t    NBINS     = 40;
  const Double_t MASS_LOW  = 80;
  const Double_t MASS_HIGH = 100;
  const Double_t PT_CUT    = 25;
  const Double_t ETA_CUT   = 2.5;
  const Double_t ELE_MASS  = 0.000511;  
  
  vector<pair<Double_t,Double_t> > scEta_limits;
  scEta_limits.push_back(make_pair(0.0,0.4));
  scEta_limits.push_back(make_pair(0.4,0.8));
  scEta_limits.push_back(make_pair(0.8,1.4442));
  scEta_limits.push_back(make_pair(1.566,2.5));

  CPlot::sOutDir = outputDir;
  
  const TString format("png");

  TRandom3 *rnd = new TRandom3();  
  
  //--------------------------------------------------------------------------------------------------------------
  // Main analysis code 
  //==============================================================================================================  

  TFile *pufile = new TFile(pufname); assert(pufile);
  TH1D  *puWeights = (TH1D*)pufile->Get("npv_rw");
  
  TH1D* hData_Tot = new TH1D("hData_Tot","",NBINS,MASS_LOW,MASS_HIGH); hData_Tot->Sumw2();
  TH1D* hMC_Tot   = new TH1D("hMC_Tot","",NBINS,MASS_LOW,MASS_HIGH);   hMC_Tot->Sumw2();
  TH1D* hMC2_Tot  = new TH1D("hMC2_Tot","",NBINS,MASS_LOW,MASS_HIGH);  hMC2_Tot->Sumw2();
  
  char hname[100];
  vector<TH1D*> hMCv, hDatav, hMC2v;  
  for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) {
    for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) {
      sprintf(hname,"data_%i_%i",ibin,jbin);
      hDatav.push_back(new TH1D(hname,"",NBINS,MASS_LOW,MASS_HIGH));
      hDatav.back()->Sumw2();

      sprintf(hname,"mc_%i_%i",ibin,jbin);
      hMCv.push_back(new TH1D(hname,"",NBINS,MASS_LOW,MASS_HIGH));
      hMCv.back()->Sumw2();
      
      sprintf(hname,"mc2_%i_%i",ibin,jbin);
      hMC2v.push_back(new TH1D(hname,"",NBINS,MASS_LOW,MASS_HIGH));
      hMC2v.back()->Sumw2();
    }
  }
  
  //
  // Declare output ntuple variables
  //
  UInt_t  runNum, lumiSec, evtNum;
  UInt_t  matchGen;
  UInt_t  category;
  UInt_t  npv, npu;
  Int_t   q1, q2;
  Float_t scale1fb, puWeight;
  TLorentzVector *dilep=0, *lep1=0, *lep2=0;
  ///// electron specific /////
  TLorentzVector *sc1=0, *sc2=0;
  
  for(UInt_t ifile=0; ifile<infilenamev.size(); ifile++) {
    cout << "Processing " << infilenamev[ifile] << "..." << endl;
    TFile *infile = TFile::Open(infilenamev[ifile]); assert(infile);
    TTree *intree = (TTree*)infile->Get("Events"); assert(intree);
  
    intree->SetBranchAddress("runNum",   &runNum);    // event run number
    intree->SetBranchAddress("lumiSec",  &lumiSec);   // event lumi section
    intree->SetBranchAddress("evtNum",   &evtNum);    // event number
    intree->SetBranchAddress("scale1fb", &scale1fb);  // event weight
    intree->SetBranchAddress("puWeight", &puWeight);  // pileup reweighting
    intree->SetBranchAddress("matchGen", &matchGen);  // event has both leptons matched to MC Z->ll
    intree->SetBranchAddress("category", &category);  // dilepton category
    intree->SetBranchAddress("npv",      &npv);	      // number of primary vertices
    intree->SetBranchAddress("npu",      &npu);	      // number of in-time PU events (MC)
    intree->SetBranchAddress("q1",       &q1);	      // charge of lead lepton
    intree->SetBranchAddress("q2",       &q2);	      // charge of trail lepton
    intree->SetBranchAddress("dilep",    &dilep);     // dilepton 4-vector
    intree->SetBranchAddress("lep1",     &lep1);      // lead lepton 4-vector
    intree->SetBranchAddress("lep2",     &lep2);      // trail lepton 4-vector
    intree->SetBranchAddress("sc1",      &sc1);	      // lead Supercluster 4-vector
    intree->SetBranchAddress("sc2",      &sc2);	      // trail Supercluster 4-vector 
  
    for(UInt_t ientry=0; ientry<intree->GetEntries(); ientry++) {
      intree->GetEntry(ientry);
      
      Double_t weight = 1;
      if(ifile==eMC || ifile==eMC2)
        weight=scale1fb*lumi*puWeights->GetBinContent(npv+1);
      
      if((category!=eEleEle2HLT) && (category!=eEleEle1HLT) && (category!=eEleEle1HLT1L1)) continue;
      if(q1 == q2) continue;
      if(dilep->M()	  < MASS_LOW)  continue;
      if(dilep->M()	  > MASS_HIGH) continue;
      if(sc1->Pt()	  < PT_CUT)    continue;
      if(sc2->Pt()	  < PT_CUT)    continue;
      if(fabs(sc1->Eta()) > ETA_CUT)   continue;      
      if(fabs(sc2->Eta()) > ETA_CUT)   continue;

      TLorentzVector vLep1(0,0,0,0); 
      TLorentzVector vLep2(0,0,0,0); 
      if (ifile==eData) {
	vLep1.SetPtEtaPhiM(lep1->Pt(), lep1->Eta(), lep1->Phi(), ELE_MASS);
	vLep2.SetPtEtaPhiM(lep2->Pt(), lep2->Eta(), lep2->Phi(), ELE_MASS);
      }
      else if (ifile==eMC) {
	vLep1.SetPtEtaPhiM(lep1->Pt(), lep1->Eta(), lep1->Phi(), ELE_MASS);
	vLep2.SetPtEtaPhiM(lep2->Pt(), lep2->Eta(), lep2->Phi(), ELE_MASS);
      }
      else {
	vLep1.SetPtEtaPhiM(gRandom->Gaus(lep1->Pt()*getEleScaleCorr(lep1->Eta(),0),getEleResCorr(lep1->Eta(),0)), lep1->Eta(), lep1->Phi(), ELE_MASS);
	vLep2.SetPtEtaPhiM(gRandom->Gaus(lep2->Pt()*getEleScaleCorr(lep2->Eta(),0),getEleResCorr(lep2->Eta(),0)), lep2->Eta(), lep2->Phi(), ELE_MASS);
      }
      TLorentzVector vDilep = vLep1 + vLep2;
    
      Int_t bin1=-1, bin2=-1;
      for(UInt_t i=0; i<scEta_limits.size(); i++) {
        Double_t etalow  = scEta_limits.at(i).first;
        Double_t etahigh = scEta_limits.at(i).second;
        if(fabs(sc1->Eta())>=etalow && fabs(sc1->Eta())<=etahigh) bin1=i;
        if(fabs(sc2->Eta())>=etalow && fabs(sc2->Eta())<=etahigh) bin2=i;
      }
      assert(bin1>=0);
      assert(bin2>=0);
      Int_t ibin= (bin1<=bin2) ? bin1 : bin2;
      Int_t jbin= (bin1<=bin2) ? bin2 : bin1;

      if (ifile==eData) hData_Tot->Fill(vDilep.M(),weight);
      else if (ifile==eMC) hMC_Tot->Fill(vDilep.M(),weight);
      else if (ifile==eMC2) hMC2_Tot->Fill(vDilep.M(),weight);

      UInt_t n=jbin-ibin;
      for(Int_t k=0; k<ibin; k++)
        n+=(scEta_limits.size()-k);
      
      if(ifile==eData)
	hDatav[n]->Fill(vDilep.M(),weight);
      else if(ifile==eMC)
	hMCv[n]->Fill(vDilep.M(),weight);
      else if(ifile==eMC2)
	hMC2v[n]->Fill(vDilep.M(),weight);
    }  
    delete infile;
    infile=0, intree=0;
  }

  TCanvas *c1 = MakeCanvas("c1", "", 800, 800);
  char pname[100];

  c1->Divide(1,2,0,0);
  c1->cd(1)->SetPad(0,0.3,1.0,1.0);
  c1->cd(1)->SetTopMargin(0.1);
  c1->cd(1)->SetBottomMargin(0.01); //0.01
  c1->cd(1)->SetLeftMargin(0.15);
  c1->cd(1)->SetRightMargin(0.07);
  c1->cd(1)->SetTickx(1);
  c1->cd(1)->SetTicky(1);

  c1->cd(2)->SetPad(0,0,1.0,0.3);
  c1->cd(2)->SetTopMargin(0.05);
  c1->cd(2)->SetBottomMargin(0.45);//0.25
  c1->cd(2)->SetLeftMargin(0.15);
  c1->cd(2)->SetRightMargin(0.07);
  c1->cd(2)->SetTickx(1);
  c1->cd(2)->SetTicky(0);

  TGaxis::SetMaxDigits(3);

  for (UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) {
    for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) {
      UInt_t n=jbin-ibin;
      for(UInt_t k=0; k<ibin; k++)
        n+=(scEta_limits.size()-k);

      //hMCv[n]   ->Scale(1.0/hMCv[n]->Integral());
      //hDatav[n] ->Scale(1.0/hDatav[n]->Integral());
      //hMC2v[n]->Scale(1.0/hMC2v[n]->Integral());

      c1->cd(1);

      hMCv[n]->SetLineColor(kRed);
      hMCv[n]->GetYaxis()->SetTitleOffset(1.100);
      hMCv[n]->GetYaxis()->SetTitle("Events");
      hMCv[n]->GetYaxis()->SetRangeUser(0.01, 1.3*TMath::Max(hMCv[n]->GetMaximum(),hDatav[n]->GetMaximum()));
      hMCv[n]->Draw("hist");
      hDatav[n]->Draw("EX0 same");
      hMC2v[n]->SetLineColor(kBlue);
      hMC2v[n]->Draw("histsame");

      c1->cd(2);

      TH1D* hDiffMC = returnRelDiff(hMCv[n],hDatav[n],"foo");
      TH1D* hDiffMC2 = returnRelDiff(hMC2v[n],hDatav[n],"foo2");

      hDiffMC->GetYaxis()->SetRangeUser(-1.0,1.0);
      hDiffMC->GetXaxis()->SetTitle("m_{ee} [GeV]");
      hDiffMC->GetYaxis()->SetTitle("#chi");

      hDiffMC->GetYaxis()->SetTitleOffset(0.42);
      hDiffMC->GetYaxis()->SetTitleSize(0.13);
      hDiffMC->GetXaxis()->SetTitleSize(0.13);
      hDiffMC->GetYaxis()->SetLabelSize(0.12);
      hDiffMC->GetXaxis()->SetLabelSize(0.12);
      hDiffMC->GetYaxis()->SetNdivisions(102);
      hDiffMC->GetYaxis()->CenterTitle();
      hDiffMC->GetXaxis()->SetTitleOffset(1.2);
      hDiffMC->GetXaxis()->CenterTitle();

      hDiffMC->Draw("hist");
      TLine l(80,0.0,100,0.0);
      l.Draw();
      hDiffMC->Draw("histsame");

      hDiffMC2->SetMarkerColor(kBlue);
      hDiffMC2->SetMarkerSize(1);
      hDiffMC2->SetLineColor(kBlue);
      hDiffMC2->Draw("EX0 same");

      c1->cd(1);

      TLegend *leg = new TLegend(0.65, 0.55, 0.90, 0.80);
      leg->SetShadowColor(0); leg->SetLineColor(0);
      leg->AddEntry(hMCv[n],"Raw MC","l");
      leg->AddEntry(hDatav[n],"Data","l");
      leg->AddEntry(hMC2v[n],"Corr. MC","l");
      leg->Draw();

      // CMS label
      TPaveText tb1(0.65,0.92,0.95,0.99,"NDC");
      tb1.SetFillStyle(0);
      tb1.SetBorderSize(0);
      tb1.SetTextAlign(32);
      tb1.AddText("CMS Preliminary");
      tb1.Draw();

      char buffer[200];
      // lumi label
      sprintf(buffer,"%.1f pb^{-1}  at  #sqrt{s} = 13 TeV",lumi);
      TPaveText tb2(0.55,0.82,0.90,0.90,"NDC");
      tb2.SetFillStyle(0);
      tb2.SetBorderSize(0);
      tb2.SetTextAlign(32);
      tb2.AddText(buffer);
      tb2.Draw();

      char str1[200],str2[200];
      sprintf(str1,"[%.1f, %.1f]",scEta_limits.at(ibin).first,scEta_limits.at(ibin).second);
      sprintf(str2,"[%.1f, %.1f]",scEta_limits.at(jbin).first,scEta_limits.at(jbin).second);
      TPaveText *a = new TPaveText(0.16,0.75,0.40,0.82,"NDC");
      a->SetFillColor(0); a->SetShadowColor(0); a->SetLineColor(0);
      a->AddText(str1);
      TPaveText *b = new TPaveText(0.16,0.68,0.40,0.75,"NDC");
      b->SetFillColor(0); b->SetShadowColor(0); b->SetLineColor(0);
      b->AddText(str2);

      a->Draw();
      b->Draw();

      sprintf(pname,"ele_comp_%i_%i.png",ibin,jbin); 
      c1->SaveAs(outputDir+"/"+pname);

      delete hDiffMC; delete hDiffMC2;
    }
  }

  cout << endl;
  cout << hMC_Tot->Integral() << ", " << hData_Tot->Integral() << ", " << hMC2_Tot->Integral() << endl;

  c1->cd(1);

  hMC_Tot->SetLineColor(kRed); hMC_Tot->SetMarkerColor(kRed);
  hMC_Tot->GetYaxis()->SetTitleOffset(1.100);
  hMC_Tot->GetYaxis()->SetTitle("Events");
  hMC_Tot->GetYaxis()->SetRangeUser(0.01, 1.2*hMC_Tot->GetMaximum());
  hMC_Tot->Draw("hist");
  hData_Tot->Draw("EX0 same");
  hMC2_Tot->SetLineColor(kBlue); hMC2_Tot->SetMarkerColor(kBlue);
  hMC2_Tot->Draw("hist same");

  c1->cd(2);
  
  TH1D* hDiffMC = returnRelDiff(hMC_Tot,hData_Tot,"foo");
  TH1D* hDiffMC2 = returnRelDiff(hMC2_Tot,hData_Tot,"foo2");
  
  hDiffMC->GetYaxis()->SetRangeUser(-1.0,1.0);
  hDiffMC->GetXaxis()->SetTitle("m_{ee} [GeV]");
  hDiffMC->GetYaxis()->SetTitle("#chi");

  hDiffMC->GetYaxis()->SetTitleOffset(0.42);
  hDiffMC->GetYaxis()->SetTitleSize(0.13);
  hDiffMC->GetXaxis()->SetTitleSize(0.13);
  hDiffMC->GetYaxis()->SetLabelSize(0.12);
  hDiffMC->GetXaxis()->SetLabelSize(0.12);
  hDiffMC->GetYaxis()->SetNdivisions(102);
  hDiffMC->GetYaxis()->CenterTitle();
  hDiffMC->GetXaxis()->SetTitleOffset(1.2);
  hDiffMC->GetXaxis()->CenterTitle();

  hDiffMC->SetMarkerColor(kRed);
  hDiffMC->SetMarkerSize(1);
  hDiffMC->SetLineColor(kRed);
  hDiffMC->Draw("hist");
  TLine l(80,0.0,100,0.0);
  l.Draw();
  //hDiffMC->Draw("EX0 same");

  hDiffMC2->SetMarkerColor(kBlue);
  hDiffMC2->SetMarkerSize(1);
  hDiffMC2->SetLineColor(kBlue);
  hDiffMC2->Draw("EX0 same");

  c1->cd(1);

  TLegend *leg = new TLegend(0.65, 0.55, 0.90, 0.80);
  leg->SetShadowColor(0); leg->SetLineColor(0);
  leg->AddEntry(hMC_Tot,"Raw MC","l");
  leg->AddEntry(hData_Tot,"Data","l");
  leg->AddEntry(hMC2_Tot,"Corr. MC","l");
  leg->Draw();

  // CMS label
  TPaveText tb1(0.65,0.92,0.95,0.99,"NDC");
  tb1.SetFillStyle(0);
  tb1.SetBorderSize(0);
  tb1.SetTextAlign(32);
  tb1.AddText("CMS Preliminary");
  tb1.Draw();

  char buffer[200];
  // lumi label
  sprintf(buffer,"%.1f pb^{-1}  at  #sqrt{s} = 13 TeV",lumi);
  TPaveText tb2(0.55,0.82,0.90,0.90,"NDC");
  tb2.SetFillStyle(0);
  tb2.SetBorderSize(0);
  tb2.SetTextAlign(32);
  tb2.AddText(buffer);
  tb2.Draw();

  char str1[200],str2[200];
  sprintf(str1,"[%.1f, %.1f]",scEta_limits.at(0).first,scEta_limits.at(scEta_limits.size()-1).second);
  sprintf(str2,"[%.1f, %.1f]",scEta_limits.at(0).first,scEta_limits.at(scEta_limits.size()-1).second);
  TPaveText *a = new TPaveText(0.16,0.75,0.40,0.82,"NDC");
  a->SetFillColor(0); a->SetShadowColor(0); a->SetLineColor(0);
  a->AddText(str1);
  TPaveText *b = new TPaveText(0.16,0.68,0.40,0.75,"NDC");
  b->SetFillColor(0); b->SetShadowColor(0); b->SetLineColor(0);
  b->AddText(str2);
  
  a->Draw();
  b->Draw();

  sprintf(pname,"ele_comp_tot.png");
  c1->SaveAs(outputDir+"/"+pname);


}
Example #12
0
void newBrezilianflagneventstGc(){

 TF1 *fa = new TF1("fa","7.15*x*x",0.001,0.13); 
   
  TCanvas *c1 = new TCanvas("c1","upper limit results ",200,10,700,500);
  c1->SetGrid();

const int N=2;
//double X[N]={0.001,0.13};
//double nO[N]={0.0365,0.0365 };
//double nE[N]={0.0469,0.0469};

double X[N]={0.001,0.13};
double nO[N]={0.0372,0.0372 };
double nE[N]={0.0481,0.0481};

cout<<"expected tgammac coupling"<<sqrt(nE[0]/7.15)<<endl;
cout<<"observed tgammac coupling"<<sqrt(nO[0]/7.15)<<endl;

cout<<"expected tgammac coupling including k-factor"<<sqrt(nE[0]/(1.375*7.15))<<endl;
cout<<"observed tgammac coupling including k-factor"<<sqrt(nO[0]/(1.375*7.15))<<endl;


double nE1sigmaup[N]={0.0648,0.0648};
double nE1sigmadown[N]={0.0351,0.0351};

double nE2sigmaup[N]={0.0949,0.0949};

double nE2sigmadown[N]={0.0266,0.0266};
double sigma1up[N];
double sigma1down[N];
double sigma2up[N];
double sigma2down[N];
for (int idx=0; idx<N; ++idx){
sigma1up[idx]=nE1sigmaup[idx]-nE[idx];
sigma1down[idx]=nE[idx]-nE1sigmadown[idx];
sigma2up[idx]=nE2sigmaup[idx]-nE[idx];
sigma2down[idx]=nE[idx]-nE2sigmadown[idx];
}

   TGraphAsymmErrors *grafexp1sigma=new TGraphAsymmErrors(N);
   grafexp1sigma->SetName("grafexp1sigma");
   grafexp1sigma->SetTitle("Graph");
   grafexp1sigma->SetFillColor(1);
//grafexp1sigma->SetPoint(point number ,x value,y value);
//grafexp1sigma->SetPointError(point number ,0,0,y lower error ,y upper error);
   grafexp1sigma->SetPoint(0,X[0],nE[0]);
   grafexp1sigma->SetPointError(0,0,0,sigma1down[0],sigma1up[0]);
   grafexp1sigma->SetPoint(1,X[1],nE[1]);
   grafexp1sigma->SetPointError(1,0,0,sigma1down[1],sigma1up[1]);
/*
   grafexp1sigma->SetPoint(2,X[2],nE[2]);
   grafexp1sigma->SetPointError(2,0,0,sigma1down[2],sigma1up[2]);
   grafexp1sigma->SetPoint(3,X[3],nE[3]);
   grafexp1sigma->SetPointError(3,0,0,sigma1down[3],sigma1up[3]);
   grafexp1sigma->SetPoint(4,X[4],nE[4]);
   grafexp1sigma->SetPointError(4,0,0,sigma1down[4],sigma1up[4]);
*/
   grafexp1sigma->SetFillColor(kGreen);
//   grafexp1sigma->
//   grafexp1sigma->
//   grafexp1sigma->
//   grafexp1sigma->

   TGraphAsymmErrors *grafexp2sigma=new TGraphAsymmErrors(N);
   grafexp2sigma->SetPoint(0,X[0],nE[0]);
   grafexp2sigma->SetPointError(0,0,0,sigma2down[0],sigma2up[0]);
   grafexp2sigma->SetPoint(1,X[1],nE[1]);
   grafexp2sigma->SetPointError(1,0,0,sigma2down[1],sigma2up[1]);
/*
   grafexp2sigma->SetPoint(2,X[2],nE[2]);
   grafexp2sigma->SetPointError(2,0,0,sigma2down[2],sigma2up[2]);
   grafexp2sigma->SetPoint(3,X[3],nE[3]);
   grafexp2sigma->SetPointError(3,0,0,sigma2down[3],sigma2up[3]);
   grafexp2sigma->SetPoint(4,X[4],nE[4]);
   grafexp2sigma->SetPointError(4,0,0,sigma2down[4],sigma2up[4]);
*/
   grafexp2sigma->SetFillColor(kYellow);
   grafexp2sigma->GetXaxis()->SetLabelFont(42);
 //  grafexp2sigma->SetLabel("");
   grafexp2sigma->GetXaxis()->SetLabelOffset(0.007);
   grafexp2sigma->GetXaxis()->SetLabelSize(0.034);
   grafexp2sigma->GetXaxis()->SetTitleSize(0.045);
   grafexp2sigma->GetXaxis()->SetTitleFont(22);
   grafexp2sigma->GetXaxis()->SetTitleOffset(0.90);
   grafexp2sigma->GetXaxis()->SetRangeUser(0, 0.2);
   grafexp2sigma->GetYaxis()->SetRangeUser(0, 0.16);
   grafexp2sigma->GetYaxis()->SetTitle("95% CL Limit on [#sigma_{tc#gamma} * Br(w #rightarrow l#nu)] (pb)");
   grafexp2sigma->GetYaxis()->SetLabelFont(42);
   grafexp2sigma->GetYaxis()->SetLabelOffset(0.007);
   grafexp2sigma->GetYaxis()->SetLabelSize(0.034);
   grafexp2sigma->GetYaxis()->SetTitleSize(0.045);
   grafexp2sigma->GetYaxis()->SetTitleOffset(0.9);
   grafexp2sigma->GetYaxis()->SetTitleFont(22);
   grafexp2sigma->GetXaxis()->SetTitle("#kappa_{c}");
   grafexp2sigma->SetTitle("");
 //  grafexp2sigma->SetMaximum(8);

   TGraph *Expected= new TGraph(N,X,nE);

   Expected->SetLineColor(4);
   Expected->SetLineWidth(2);
   Expected->SetMarkerColor(1);
   Expected->SetMarkerStyle(20);
   Expected->SetLineStyle(2);
   Expected->GetYaxis()->SetTitle("Cross Section [pb]");
   Expected->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   Expected->SetTitle("with ");
   Expected->SetFillColor(10);



   TGraph *Observed= new TGraph(N,X,nO);
   Observed->SetLineColor(1);
   Observed->SetLineWidth(2);
   Observed->SetMarkerColor(1);
   Observed->SetMarkerStyle(20);
//   Observed->SetLineStyle(2);
   Observed->GetYaxis()->SetTitle("Cross Section [pb]");
   Observed->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   Observed->SetTitle("with ");
   Observed->SetFillColor(10);


   grafexp2sigma->Draw("AL3");
   grafexp1sigma->Draw("L3same");
   Expected->Draw("L");
   Observed->Draw("L");

   fa->SetLineColor(2);
   fa->SetLineWidth(3);
   fa->SetMarkerColor(1);
   fa->Draw("same");
  Observed->GetHistogram()->Draw("AXISSAMEY+");
  Observed->GetHistogram()->Draw("AXISSAMEX+");

    TLegend *leg1 = new TLegend(0.2, 0.6, 0.35, 0.8);
    leg1->SetTextSize(0.03);
    leg1->SetBorderSize(0);
    leg1->SetLineColor(0);
    leg1->SetLineWidth(0);
    leg1->SetFillColor(kWhite);
    leg1->AddEntry(fa, "Predicted", "L");
    leg1->AddEntry(Observed, "95% CL Observed Limit", "L");
    leg1->AddEntry(Expected, "95% CL Expected Limit", "L");
    leg1->AddEntry(grafexp1sigma, "#pm1#sigma Exp.Limit", "F");
    leg1->AddEntry(grafexp2sigma, "#pm2#sigma Exp.Limit", "F");

    leg1->Draw();

    TLine *line1 = new TLine(5, 1, 40, 1);
    line1->SetLineColor(2);
    line1->SetLineWidth(2);
//    line1->Draw("same");
  
    TPaveText *pt = new TPaveText(0.1,0.95,0.4,0.95, "NDC"); // NDC sets coords
    pt->SetLineColor(10);                                              // relative to pad dimensions
    pt->SetFillColor(10); // text is black on white
    pt->SetTextSize(0.045);
    pt->SetTextAlign(12);
    pt->AddText("CMS Preliminary, 19.1 fb^{-1}, #sqrt{s} = 8 TeV");
    pt->SetShadowColor(10);
    pt->Draw("same");


}
Example #13
0
TCanvas* plotExpVersusMC(int numExpHists, TH1** expHists, int numMCHists, TH1** mcHists, TString titleString)
{
	gROOT->cd();
	int totalNumHists = numExpHists + numMCHists;

	if(totalNumHists < 1 || (expHists == nullptr && mcHists == nullptr))
	{
		return nullptr;
	}

	const int numColors = 11;
	const int colorList[numColors] = { kBlack, kBlue, kRed, kGreen, kCyan, kMagenta, kPink, kOrange, kViolet, kAzure, kYellow };
	const int markerList[14] = { 20, 22, 23, 25, 24, 32, 33, 3, 5, 28, 26, 30, 29 };
	//gStyle->SetTitleColor(kWhite);
	TCanvas* c2 = new TCanvas(titleString, "plotManyHistCanvas", 1600, 1200);
	c2->SetFillColor(kGray);
	c2->cd();
	c2->SetLeftMargin(.13);
	c2->SetRightMargin(.06);
	c2->SetGrid(1, 1);
	gPad->SetTickx(1);
	gPad->SetTicky(1);
	gPad->SetFillColor(kWhite);

	TLegend *theLegend;

	if(totalNumHists >= 1)
	{
		double legendSize = .1 * totalNumHists;
		if(legendSize < .15) legendSize = .15;
		theLegend = new TLegend(0.55, .8 - legendSize, 0.87, 0.8);  //Top Right
//        theLegend = new TLegend(0.2,.8-legendSize,0.47,0.8);  //Top Left
//        theLegend = new TLegend(0.55,.4-legendSize,0.87,0.4); //Bottom Right
	}

	//Prep MCHists
	for (int i = 0; i < numMCHists; i++)
	{
		mcHists[i]->SetLineColor(colorList[(i) % numColors]);
		mcHists[i]->SetMarkerColor(colorList[(i) % numColors]);
		mcHists[i]->SetLineStyle((i - numExpHists) % 5 + 1);
		mcHists[i]->SetLineWidth(2);
		mcHists[i]->GetYaxis()->SetTitleOffset(1.5);
	}

	//Prep MCHists
	for (int i = 0; i < numExpHists; i++)
	{
		expHists[i]->SetLineColor(colorList[(i + numMCHists) % numColors]);
		expHists[i]->SetMarkerColor(colorList[(i + numMCHists) % numColors]);
		expHists[i]->SetMarkerStyle(markerList[(i) % 14]);
		expHists[i]->SetLineWidth(2);
		expHists[i]->SetMarkerSize(2);
		expHists[i]->GetYaxis()->SetTitleOffset(1.5);
	}

	bool drawExpFirst = true;

	for (int i = 0; i < totalNumHists; i++)
	{
		if(drawExpFirst && numExpHists > 0)
		{
			if(i < numExpHists)
			{
				theLegend->AddEntry(expHists[i], expHists[i]->GetTitle(), "PE");
				if(i == 0)
				{
					expHists[i]->SetTitle("");
					expHists[i]->Draw("P E1 X0");
				}
				else
				{
					expHists[i]->Draw("P E1 X0 SAME");
				}
			}
			else
			{
				theLegend->AddEntry(mcHists[i - numExpHists], mcHists[i - numExpHists]->GetTitle(), "L");
				mcHists[i - numExpHists]->Draw("HIST SAME");
			}
		}
		else
		{
			if(i < numMCHists)
			{
				theLegend->AddEntry(mcHists[i], mcHists[i]->GetTitle(), "L");
				if(i == 0)
				{
					mcHists[i]->SetTitle("");
					mcHists[i]->Draw("HIST");
				}
				else
				{
					mcHists[i]->Draw("HIST SAME");
				}
			}
			else
			{
				theLegend->AddEntry(expHists[i - numMCHists], expHists[i - numMCHists]->GetTitle(), "PE");
				expHists[i - numMCHists]->Draw("P E1 X0 SAME");
			}
		}
	}

	if(totalNumHists >= 1)
	{
		theLegend->Draw();
		theLegend->SetBorderSize(1);
		theLegend->SetFillColor(kWhite);
	}

	TPaveText* textBox = new TPaveText(.14, .945, .8705314, .9825073, "NDC");
	textBox->SetTextSize(.035);
	textBox->AddText(titleString);
	textBox->SetFillColor(kWhite);
	textBox->SetLineColor(kWhite);

	textBox->SetShadowColor(kWhite);
	// textBox->SetFillStyle(4000);//transparent
	// textBox->SetLineStyle(4000);//transparent
	textBox->SetLineWidth(0);
	textBox->Draw();

	c2->Update();

	return c2;
}
Example #14
0
void tqgammaVStqz(){

TCanvas *c1 = new TCanvas("c1","upper limit results ",200,10,700,500);
c1->SetLogy(1);
c1->SetLogx(1);
c1->Range(0,0,1,1);
const int N=3;
double cdfx[4]={0,0.032,0.032,1};
double cdfy[4]={0.037,0.037,0,0};

double dzerox[4]={0.000001,0.02,0.06,1};
double dzeroy[4]={0.032,0.032,0.032,0.032};

//double cdfx[7]={0,0,1,1,0.45,0.45,0};
//double cdfy[7]={0.032,0.1,0.1,0,0,0.032,0.032};
double lepx[4]={0,0.0468,0.04681,0.0468};
double lepy[4]={0.08,0.08,0,0};
double herax[4]={0,0.0060,0.0060,0.0060};
double heray[4]={0.3,0.3,0,0};
double h1x[4]={0.0064,0.0064,0.0064,0.0064};
double h1y[4]={0.000001,0.02,0.06,1};
double cmsx[4]={0.000001,0.02,0.06,1};
double cmsy[4]={0.0005,0.0005,0.0005,0.0005};

double atlasx[4]={0.000001,0.02,0.06,1};
double atlasy[4]={0.0073,0.0073,0.0073,0.0073};

double mycmsx[4]={0.000161,0.000161,0.000161,0.000161};
double mycmsy[4]={0.000001,0.02,0.06,1};

double mycmscx[4]={0.00182,0.00182,0.00182,0.00182};
double mycmscy[4]={0.000001,0.02,0.06,1};



double cmsphux[4]={0.00001,0.000161,0.000161001,1};
double cmsphuy[4]={0,0,0,0};

double cmsphcx[4]={0.00182,0.00182,0.00182,0.00182};
double cmsphcy[4]={0,0.02,0.06,1};

   TGraph *cdf= new TGraph(4,cdfx,cdfy);
   cdf->SetLineColor(12);
   cdf->SetLineWidth(3);
   cdf->SetMarkerColor(1);
   cdf->SetMarkerStyle(20);
//   Observed->SetLineStyle(2);
   cdf->GetYaxis()->SetTitle("Cross Section [pb]");
   cdf->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   cdf->SetTitle("with ");
   cdf->SetFillColor(45);
   cdf->GetXaxis()->SetLabelOffset(0.0001);

   TGraph *dzero= new TGraph(4,dzerox,dzeroy);
   dzero->SetLineColor(3);
   dzero->SetLineWidth(3);
   dzero->SetMarkerColor(1);
   dzero->SetMarkerStyle(20);
//   Observed->SetLineStyle(2);
   dzero->GetYaxis()->SetTitle("Cross Section [pb]");
   dzero->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   dzero->SetTitle("with ");
   dzero->SetFillColor(45);
   dzero->GetXaxis()->SetLabelOffset(0.0001);

   TGraph *cms= new TGraph(4,mycmsx,mycmsy);
   cms->SetLineColor(2);
   cms->SetLineWidth(3);
   cms->SetMarkerColor(1);
   cms->SetMarkerStyle(20);
//   Observed->SetLineStyle(2);
   cms->GetYaxis()->SetTitle("Cross Section [pb]");
   cms->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   cms->SetTitle("with ");
   cms->SetFillColor(45);

  TGraph *cmsc= new TGraph(4,mycmscx,mycmscy);
   cmsc->SetLineColor(2);
   cmsc->SetLineWidth(3);
   cmsc->SetMarkerColor(1);
   cmsc->SetMarkerStyle(20);
//   Observed->SetLineStyle(2);
   cmsc->GetYaxis()->SetTitle("Cross Section [pb]");
   cmsc->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   cmsc->SetTitle("with ");
   cmsc->SetFillColor(45);

   TGraph *cmsz= new TGraph(4,cmsx,cmsy);
   cmsz->SetLineColor(1);
   cmsz->SetLineWidth(3);
   cmsz->SetMarkerColor(1);
   cmsz->SetMarkerStyle(20);
//   Observed->SetLineStyle(2);
   cmsz->GetYaxis()->SetTitle("Cross Section [pb]");
   cmsz->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   cmsz->SetTitle("with ");
   cmsz->SetFillColor(45);

   TGraph *hera= new TGraph(4,herax,heray);
   hera->SetLineColor(6);
   hera->SetLineWidth(3);
   hera->SetMarkerColor(1);
   hera->SetMarkerStyle(20);
//   hera->SetLineStyle(2);
//   hera->SetLineStyle(2);
   hera->GetYaxis()->SetTitle("Cross Section [pb]");
   hera->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   hera->SetTitle("with ");
   hera->SetFillColor(45);

   TGraph *h1= new TGraph(4,h1x,h1y);
   h1->SetLineColor(28);
   h1->SetLineWidth(3);
   h1->SetMarkerColor(1);
 //  h1->SetMarkerStyle(20);
//   hera->SetLineStyle(2);
   h1->GetYaxis()->SetTitle("Cross Section [pb]");
   h1->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
//   h1->SetLineStyle(2);
   h1->SetTitle("with ");
   h1->SetFillColor(45);

   TGraph *lep= new TGraph(4,lepx,lepy);
   lep->SetLineColor(4);
   lep->SetLineWidth(3);
   lep->SetMarkerColor(1);
   lep->SetMarkerStyle(20);
//   lep->SetLineStyle(2);
   lep->GetYaxis()->SetTitle("Cross Section [pb]");
   lep->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   lep->SetTitle("with ");
   lep->SetFillColor(39);

   TGraph *atlas= new TGraph(4,atlasx,atlasy);
   atlas->SetLineColor(46);
   atlas->SetLineWidth(3);
   atlas->SetMarkerColor(1);
   atlas->SetMarkerStyle(20);
//   lep->SetLineStyle(2);
   atlas->GetYaxis()->SetTitle("Cross Section [pb]");
   atlas->GetXaxis()->SetTitle("#Lambda_{T} [GeV]");
   atlas->SetTitle("with ");
   atlas->SetFillColor(39);

   TGraphAsymmErrors *grafphotoncms=new TGraphAsymmErrors(4);
   grafphotoncms->SetPoint(0,cmsphux[0],cmsphuy[0]);
   grafphotoncms->SetPointError(0,0,0,0,0);
   grafphotoncms->SetPoint(1,cmsphux[1],cmsphuy[1]);
   grafphotoncms->SetPointError(1,0,0,0,0);
   grafphotoncms->SetPoint(2,cmsphux[2],cmsphuy[2]);
   grafphotoncms->SetPointError(2,0,0,0,1);
   grafphotoncms->SetPoint(3,cmsphux[3],cmsphuy[3]);
   grafphotoncms->SetPointError(3,0,0,0,1);
//grafhera->SetFillColor(kYellow+3);
grafphotoncms->SetFillColor(kOrange-3);
//grafphotoncms->SetFillColor(kTeal-9);
   grafphotoncms->SetFillStyle(3004);
   grafphotoncms->GetXaxis()->SetRangeUser(0.00005, 1);
   grafphotoncms->GetYaxis()->SetRangeUser(0.00001, 1);
   grafphotoncms->GetYaxis()->SetTitle("BR(t #rightarrow qZ)");
   grafphotoncms->GetXaxis()->SetTitle("BR(t #rightarrow q#gamma)");
   grafphotoncms->GetXaxis()->SetLabelSize(0.03);
   grafphotoncms->GetYaxis()->SetLabelSize(0.03);
   grafphotoncms->GetXaxis()->SetTitleFont(62);
   grafphotoncms->GetYaxis()->SetTitleFont(62);
   grafphotoncms->GetXaxis()->SetTitleSize(0.050);
   grafphotoncms->GetYaxis()->SetTitleSize(0.050);
   grafphotoncms->GetXaxis()->SetTitleOffset(0.8);
   grafphotoncms->GetYaxis()->SetTitleOffset(0.8);

   TGraphAsymmErrors *grafphotoncms2=new TGraphAsymmErrors(4);
   grafphotoncms2->SetPoint(0,cmsx[0],cmsy[0]);
   grafphotoncms2->SetPointError(0,0,0,0,1-cmsy[0]);
   grafphotoncms2->SetPoint(1,cmsphux[2],cmsy[1]);
   grafphotoncms2->SetPointError(1,0,0,0,1-cmsy[1]);
   grafphotoncms2->SetPoint(2,cmsphux[2],cmsphuy[2]);
   grafphotoncms2->SetPointError(2,0,0,0,1);
   grafphotoncms2->SetPoint(3,cmsphux[3],cmsphuy[3]);
   grafphotoncms2->SetPointError(3,0,0,0,1);
//grafhera->SetFillColor(kYellow+3);
//grafhera->SetFillColor(kRed-8);
grafphotoncms2->SetFillColor(kYellow-9);
//   grafphotoncms2->SetFillStyle(3005);
   grafphotoncms2->GetXaxis()->SetRangeUser(0.00005, 1);
   grafphotoncms2->GetYaxis()->SetRangeUser(0.00001, 1);
   grafphotoncms2->GetYaxis()->SetTitle("BR(t #rightarrow qZ)");
   grafphotoncms2->GetXaxis()->SetTitle("BR(t #rightarrow q#gamma)");
   grafphotoncms2->GetXaxis()->SetLabelSize(0.03);
   grafphotoncms2->GetYaxis()->SetLabelSize(0.03);
   grafphotoncms2->GetXaxis()->SetTitleFont(62);
   grafphotoncms2->GetYaxis()->SetTitleFont(62);
   grafphotoncms2->GetXaxis()->SetTitleSize(0.065);
   grafphotoncms2->GetYaxis()->SetTitleSize(0.045);
   grafphotoncms2->GetXaxis()->SetLabelOffset(0.0001);
   grafphotoncms2->GetXaxis()->SetTitleOffset(0.60);


   TGraphAsymmErrors *grafcms=new TGraphAsymmErrors(4);
   grafcms->SetPoint(0,cmsx[0],cmsy[0]);
   grafcms->SetPointError(0,0,0,0,1-cmsy[0]);
   grafcms->SetPoint(1,cmsx[1],cmsy[1]);
   grafcms->SetPointError(1,0,0,0,1-cmsy[1]);
   grafcms->SetPoint(2,cmsx[2],cmsy[2]);
   grafcms->SetPointError(2,0,0,0,1-cmsy[2]);
   grafcms->SetPoint(3,cmsx[3],cmsy[3]);
   grafcms->SetPointError(3,0,0,0,1-cmsy[3]);
grafcms->SetFillColor(kGray+1);
//   grafcms->SetFillColor(kCyan-10);
//   grafcms->SetFillColor(kCyan-8);
//  grafcms->SetFillColor(kMagenta-10);
   grafcms->SetFillStyle(3005);
   grafcms->SetLineColor(1);
   grafcms->GetXaxis()->SetRangeUser(0.00005, 1);
   grafcms->GetYaxis()->SetRangeUser(0.00001, 1);
   grafcms->GetYaxis()->SetTitle("BR(t #rightarrow #gamma u)");
   grafcms->GetXaxis()->SetTitle("#kappa_{tu#gamma}");
   grafcms->GetXaxis()->SetLabelSize(0.03);
   grafcms->GetYaxis()->SetLabelSize(0.03);
   grafcms->GetXaxis()->SetTitleFont(62);
   grafcms->GetYaxis()->SetTitleFont(62);
   grafcms->GetXaxis()->SetTitleSize(0.065);
   grafcms->GetYaxis()->SetTitleSize(0.045);
   grafcms->GetXaxis()->SetLabelOffset(0.0001);
   grafcms->GetXaxis()->SetTitleOffset(0.60);

   grafphotoncms->Draw("AL3");
  grafphotoncms2->Draw("L3SAME");
   grafcms->Draw("L3SAME");
 //  grafphotoncms2->Draw("L3SAME");
  grafphotoncms->Draw("L3SAME");

//   grafphotoncms->Draw("L3SAME");
   cdf->Draw("same");
   dzero->Draw("same");
   cms->Draw("same");
   cmsc->Draw("same");
   cmsz->Draw("same");
   hera->Draw("same");
   h1->Draw("same");
   lep->Draw("same");
   atlas->Draw("same");  

  TPaveText *pt = new TPaveText(0.1,0.95,0.4,0.95, "NDC"); // NDC sets coords
    pt->SetLineColor(10);                                              // relative to pad dimensions
    pt->SetFillColor(10); // text is black on white
    pt->SetTextSize(0.045);
    pt->SetTextAlign(12);
    pt->AddText("CMS Preliminary, 19.1 fb^{-1}, #sqrt{s} = 8 TeV");
    pt->SetShadowColor(10);
 //   pt->Draw("same");


   cdf->GetHistogram()->Draw("AXISSAMEY+");
   cdf->GetHistogram()->Draw("AXISSAMEX+");
   cdf->GetHistogram()->Draw("AXISSAME");


 TLatex latex;
   latex.SetTextSize(0.035);
   latex.SetTextAlign(13);  //align at top
   latex.DrawLatex(0.000014,cdfy[0]+cdfy[0]/1.5,"#color[12]{CDF}");
   latex.DrawLatex(0.000014,dzeroy[0]-dzeroy[0]/10,"#color[3]{D0}");
   latex.DrawLatex(0.000014,lepy[0]+lepy[0]/1.5,"#color[4]{DELPHI}");
//    latex.DrawLatex(0.000014,heray[0]+heray[0]/1.5,"#color[6]{ZEUS}");
   latex.DrawLatex(0.000014,atlasy[0]+atlasy[0]/1.5,"#color[46]{ATLAS}");
   latex.DrawLatex(0.000014,cmsy[0]+cmsy[0]/1.5,"#color[1]{CMS}");

 latex.DrawLatex(mycmsx[0]+mycmsx[0]/8,0.000035,"#splitline{#color[2]{}}{#color[2]{(q=u)}}");
 latex.DrawLatex(mycmscx[0]-mycmscx[0]/1.85,0.000035,"#splitline{#color[2]{}}{#color[2]{(q=c)}}");
 latex.DrawLatex(mycmsx[0]+mycmsx[0]/2,0.0001,"#splitline{#color[2]{     CMS}}{#color[2]{Preliminary}}");


 latex.DrawLatex(0.000014,heray[0]+heray[0]/1.5,"#color[6]{ZEUS (q=u)}");
 latex.DrawLatex(h1x[0]+h1x[0]/8,0.00005,"#splitline{#color[28]{H1}}{#color[28]{(q=u)}}");
 //  latex.DrawLatex(0.03,cmsy[0]+cmsy[0]/1.5,"#color[46]{ #scale[10.2]{#rightarrow}CMS}");


   latex.DrawLatex(0.03,0.55,"#splitline{#color[1]{          95% C.L} }{#color[1]{EXCLUDED REGION}}");

TArrow ar1(0.1,0.1,1,0.1);
   ar1.Draw("same");
//  TText *th1 = new TText(0.005,cdfy[0]+0.005,"#color[2]{Left adjusted}" );
//   th1->SetTextAlign(5); 
//   th1->SetTextSize(0.05);
//   th1->Draw();
 
//   grafexp1sigma->Draw("L3same");
//   cdf->Draw("AL");
//   Observed->Draw("L");

 
//   TGaxis *axis1 = new TGaxis(-8,-0.5,8,-0.5,0.0001,0.5,510,"-");
//   axis1->SetName("axis1");
//   axis1->Draw("same");
//   c1->Update();
/*
    TLegend *leg1 = new TLegend(0.2, 0.6, 0.35, 0.8);
    leg1->SetTextSize(0.03);
    leg1->SetBorderSize(0);
    leg1->SetLineColor(0);
    leg1->SetLineWidth(0);
    leg1->SetFillColor(kWhite);
    leg1->AddEntry(cdf, "Predicted", "L");
//    leg1->AddEntry(Observed, "95% CL Observed Limit", "L");
//    leg1->AddEntry(Expected, "95% CL Expected Limit", "L");
//    leg1->AddEntry(grafexp1sigma, "#pm1#sigma Exp.Limit", "F");
//    leg1->AddEntry(grafexp2sigma, "#pm2#sigma Exp.Limit", "F");

    leg1->Draw();

    TLine *line1 = new TLine(5, 1, 40, 1);
    line1->SetLineColor(2);
    line1->SetLineWidth(2);
//    line1->Draw("same");
  
    TPaveText *pt = new TPaveText(0.15,0.80,0.4,0.87, "NDC"); // NDC sets coords
    pt->SetLineColor(10);                                              // relative to pad dimensions
    pt->SetFillColor(10); // text is black on white
    pt->SetTextSize(0.03);
    pt->SetTextAlign(12);
    pt->AddText("CMS Preliminary #sqrt{s} = 8 TeV, #int L dt= 19.145 fb^{-1}");
    pt->SetShadowColor(10);
    pt->Draw("same");

*/
}