Esempio n. 1
0
TF1* fit(Double_t ptmin, Double_t ptmax)
{
  TCanvas* c = new TCanvas(Form("c_%.0f_%.0f",ptmin,ptmax),"",600,600);
  TFile* infile = new TFile(Form("%s_%s_%.0f_%.0f.root",infname.Data(),collisionsystem.Data(),ptmin,ptmax));
  TH1D* h = (TH1D*)infile->Get("h");                    h->SetName(Form("h_%.0f_%.0f",ptmin,ptmax));
  TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal");    hMCSignal->SetName(Form("hMCSignal_%.0f_%.0f",ptmin,ptmax));
  TH1D* hMCSwapped = (TH1D*)infile->Get("hMCSwapped");  hMCSwapped->SetName(Form("hMCSwapped_%.0f_%.0f",ptmin,ptmax));
  TF1* f = new TF1(Form("f_%.0f_%.0f",ptmin,ptmax),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]*exp([4]*x)", 1.7, 2.0);

  f->SetParLimits(10,0.001,0.05);
  f->SetParLimits(2,0.01,0.1);
  f->SetParLimits(8,0.02,0.2);
  f->SetParLimits(7,0,1);
  f->SetParLimits(9,0,1);
  
  f->SetParameter(0,setparam0);
  f->SetParameter(1,setparam1);
  f->SetParameter(2,setparam2);
  f->SetParameter(10,setparam10);
  f->SetParameter(9,setparam9);

  f->FixParameter(8,setparam8);
  f->FixParameter(7,1);
  f->FixParameter(1,fixparam1);
  f->FixParameter(3,0);
  f->FixParameter(4,0);
  h->GetEntries();
  
  hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto);
  f->ReleaseParameter(1);
  hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto);
  
  f->FixParameter(1,f->GetParameter(1));
  f->FixParameter(2,f->GetParameter(2));
  f->FixParameter(10,f->GetParameter(10));
  f->FixParameter(9,f->GetParameter(9));
  f->FixParameter(7,0);
  f->ReleaseParameter(8);
  f->SetParameter(8,setparam8);
  
  hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto);
  hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto);
  hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto);
  hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto);
  
  f->SetParLimits(0,0,1.e+6);
  f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000)));
  f->FixParameter(8,f->GetParameter(8));
  f->ReleaseParameter(3);
  f->ReleaseParameter(4);
  f->SetParLimits(3,0,1.e+10);
  f->SetParameter(3,1.e+3);

  f->SetLineColor(kRed);
  
  h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto);
  h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto);
  f->ReleaseParameter(1);
  f->SetParLimits(1,1.85,1.90);
  //f->ReleaseParameter(2);                                     // you need to release these two parameters if you want to perform studies on the sigma shape
  //f->ReleaseParameter(10);                                   // you need to release these two parameters if you want to perform studies on the sigma shape
  h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto);
  h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto);
  h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto);
  h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto);
  
  TF1* background = new TF1(Form("background_%.0f_%.0f",ptmin,ptmax),"[0]*exp([1]*x)");
  background->SetParameter(0,f->GetParameter(3));
  background->SetParameter(1,f->GetParameter(4));
  background->SetLineColor(4);
  background->SetRange(minhisto,maxhisto);
  background->SetLineStyle(2);
  
  TF1* mass = new TF1(Form("fmass_%.0f_%.0f",ptmin,ptmax),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))");
  mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10));
  mass->SetParError(0,f->GetParError(0));
  mass->SetParError(1,f->GetParError(1));
  mass->SetParError(2,f->GetParError(2));
  mass->SetParError(3,f->GetParError(7));
  mass->SetParError(4,f->GetParError(9));
  mass->SetParError(5,f->GetParError(10));
  mass->SetFillColor(kOrange-3);
  mass->SetFillStyle(3002);
  mass->SetLineColor(kOrange-3);
  mass->SetLineWidth(3);
  mass->SetLineStyle(2);
  
  TF1* massSwap = new TF1(Form("fmassSwap_%.0f_%.0f",ptmin,ptmax),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])");
  massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8));
  massSwap->SetParError(0,f->GetParError(0));
  massSwap->SetParError(1,f->GetParError(1));
  massSwap->SetParError(2,f->GetParError(7));
  massSwap->SetParError(3,f->GetParError(8));
  massSwap->SetFillColor(kGreen+4);
  massSwap->SetFillStyle(3005);
  massSwap->SetLineColor(kGreen+4);
  massSwap->SetLineWidth(3);
  massSwap->SetLineStyle(1);
  
  h->SetXTitle("m_{#piK} (GeV/c^{2})");
  h->SetYTitle("Entries / (5 MeV/c^{2})");
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y");
  h->GetXaxis()->SetTitleOffset(1.3);
  h->GetYaxis()->SetTitleOffset(1.8);
  h->GetXaxis()->SetLabelOffset(0.007);
  h->GetYaxis()->SetLabelOffset(0.007);
  h->GetXaxis()->SetTitleSize(0.045);
  h->GetYaxis()->SetTitleSize(0.045);
  h->GetXaxis()->SetTitleFont(42);
  h->GetYaxis()->SetTitleFont(42);
  h->GetXaxis()->SetLabelFont(42);
  h->GetYaxis()->SetLabelFont(42);
  h->GetXaxis()->SetLabelSize(0.04);
  h->GetYaxis()->SetLabelSize(0.04);
  h->SetMarkerSize(0.8);
  h->SetMarkerStyle(20);
  h->SetStats(0);
  h->Draw("e");

  background->Draw("same");   
  mass->SetRange(minhisto,maxhisto);	
  mass->Draw("same");
  massSwap->SetRange(minhisto,maxhisto);
  massSwap->Draw("same");
  f->Draw("same");
  
  Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass;
  Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0);
  
  std::cout<<"YIELD="<<yield<<std::endl;

  TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f");
  leg->AddEntry(massSwap,"K-#pi swapped","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
  texCms->SetNDC();
  texCms->SetTextAlign(12);
  texCms->SetTextSize(0.04);
  texCms->SetTextFont(42);
  texCms->Draw();

  TLatex* texCol = new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data()));
  texCol->SetNDC();
  texCol->SetTextAlign(32);
  texCol->SetTextSize(0.04);
  texCol->SetTextFont(42);
  texCol->Draw();

  TLatex* texPt = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
  texPt->SetNDC();
  texPt->SetTextFont(42);
  texPt->SetTextSize(0.04);
  texPt->SetLineWidth(2);
  texPt->Draw();

  TLatex* texY = new TLatex(0.22,0.83,"|y| < 1.0");
  texY->SetNDC();
  texY->SetTextFont(42);
  texY->SetTextSize(0.04);
  texY->SetLineWidth(2);
  texY->Draw();

  TLatex* texYield = new TLatex(0.22,0.73,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr));
  texYield->SetNDC();
  texYield->SetTextFont(42);
  texYield->SetTextSize(0.04);
  texYield->SetLineWidth(2);
  texYield->Draw();

  c->SaveAs(Form("plotFits/DMass_expo_%s_%.0f_%.0f.pdf",collisionsystem.Data(),ptmin,ptmax));
  
  TCanvas* cPull = new TCanvas(Form("cPull_%.0f_%.0f",ptmin,ptmax),"",600,700);
  TH1D* hPull = (TH1D*)h->Clone("hPull");
  for(int i=0;i<h->GetNbinsX();i++)
    {
      Double_t nfit = f->Integral(h->GetBinLowEdge(i+1),h->GetBinLowEdge(i+1)+h->GetBinWidth(i+1))/h->GetBinWidth(i+1);
      if(h->GetBinError(i+1)==0)
        {
          hPull->SetBinContent(i+1,0.);
        }
      else hPull->SetBinContent(i+1,(h->GetBinContent(i+1)-nfit)/h->GetBinError(i+1));
      hPull->SetBinError(i+1,0);
    }
  hPull->SetMinimum(-4.);
  hPull->SetMaximum(4.);
  hPull->SetYTitle("Pull");
  hPull->GetXaxis()->SetTitleOffset(1.);
  hPull->GetYaxis()->SetTitleOffset(0.65);
  hPull->GetXaxis()->SetLabelOffset(0.007);
  hPull->GetYaxis()->SetLabelOffset(0.007);
  hPull->GetXaxis()->SetTitleSize(0.12);
  hPull->GetYaxis()->SetTitleSize(0.12);
  hPull->GetXaxis()->SetLabelSize(0.1);
  hPull->GetYaxis()->SetLabelSize(0.1);
  hPull->GetYaxis()->SetNdivisions(504);
  TLine* lPull = new TLine(1.7, 0, 2., 0);
  lPull->SetLineWidth(1);
  lPull->SetLineStyle(7);
  lPull->SetLineColor(1);
  TPad* pFit = new TPad("pFit","",0,0.3,1,1);
  pFit->SetBottomMargin(0);
  pFit->Draw();
  pFit->cd();
  h->Draw("e");
  background->Draw("same");
  mass->Draw("same");
  massSwap->Draw("same");
  f->Draw("same");
  leg->Draw("same");
  texCms->Draw();
  texCol->Draw();
  texPt->Draw();
  texY->Draw();
  texYield->Draw();
  cPull->cd();
  TPad* pPull = new TPad("pPull","",0,0,1,0.3);
  pPull->SetTopMargin(0);
  pPull->SetBottomMargin(0.3);
  pPull->Draw();
  pPull->cd();
  hPull->Draw("p");
  lPull->Draw();
  cPull->cd();
  cPull->SaveAs(Form("plotFits/DMass_expo_%s_%.0f_%.0f_Pull.pdf",collisionsystem.Data(),ptmin,ptmax));

  return mass;
}
Esempio n. 2
0
TF1 *fit(TTree *nt, TTree *ntMC, Double_t ptmin, Double_t ptmax, int isMC,bool isPbPb,TF1* &total,Float_t centmin, Float_t centmax)
{
	//cout<<cut.Data()<<endl;
	static Int_t count=0;
	count++;
	TCanvas* c= new TCanvas(Form("c%d",count),"",600,600);
	TH1D* h = new TH1D(Form("h%d",count),"",nbinsmasshisto,minhisto,maxhisto);

	//   TF1* f = new TF1(Form("f%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [6]*Gaus(x,[7],[8])/(sqrt(2*3.14159)*[8]) + [9]+[10]*x ");
	//   TF1* f = new TF1(Form("f%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [9]+[10]*x ");
	TF1* f = new TF1(Form("f%d",count),"[0]*TMath::Erf((x-[1])/[2]) + [0] + [9]+[10]*x ");

	if(isMC==1) nt->Project(Form("h%d",count),"Bmass",Form("%s*(%s&&Bpt>%f&&Bpt<%f)","1",seldata.Data(),ptmin,ptmax));   
	else nt->Project(Form("h%d",count),"Bmass",Form("(%s&&Bpt>%f&&Bpt<%f)",seldata.Data(),ptmin,ptmax));   

	clean0(h);

	h->Draw();
	f->SetParLimits(0, 1e-2, 1e4);
	f->SetParLimits(1, 5.02, 5.06);
	f->SetParLimits(2, 0.001, 0.1);

	f->SetParLimits(3, 1e-2, 1e4);
	f->SetParLimits(4, 5.06, 5.10);
	f->SetParLimits(5, 0.001, 0.1);

	f->SetParLimits(6, 0, 1e4);
	f->SetParLimits(7, 5.3, 5.4);
	f->SetParLimits(8, 0.001, 0.5);

	f->SetParLimits(9, 0, 1e5);
	f->SetParLimits(10, -500,  100);

	f->SetParameter(0,1e2);
	f->SetParameter(1,5.03);
	f->SetParameter(2,0.05);

	f->SetParameter(0,1e2);
	f->SetParameter(1,5.03);
	f->SetParameter(2,0.05);

	f->SetParameter(3,1e2);
	f->SetParameter(4,5.07);
	f->SetParameter(5,0.05);

	f->SetParameter(6,1e2);
	f->SetParameter(7,5.35);
	f->SetParameter(8,0.05);

	f->SetParameter(9,1e3);
	f->SetParameter(10,-1);

	//error fn
	f->SetParLimits(0, 1e1, 1e3);
	f->SetParLimits(1, 5., 5.3);
	f->SetParLimits(2, -10, 0);
	f->SetParameter(0,100);
	f->SetParameter(1,5.1);
	f->SetParameter(2,0);

	h->GetEntries();

	h->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
	h->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
	h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
	h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
	h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
	h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto);
	h->SetMarkerSize(0.8);
	h->SetMarkerStyle(20);

	TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x");
	background->SetParameter(0,f->GetParameter(9));
	background->SetParameter(1,f->GetParameter(10));
	background->SetLineColor(4);
	background->SetRange(minhisto,maxhisto);
	background->SetLineStyle(2);

	//   TF1 *mass = new TF1(Form("fmass%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [6]*Gaus(x,[7],[8])/(sqrt(2*3.14159)*[8])");
	//   mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(3),f->GetParameter(4),f->GetParameter(5),f->GetParameter(6),f->GetParameter(7),f->GetParameter(8));
	//TF1 *mass = new TF1(Form("fmass%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5])");
	//mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(3),f->GetParameter(4),f->GetParameter(5));
	TF1 *mass = new TF1(Form("fmass%d",count),"[0]*TMath::Erf((x-[1])/[2]) + [0]");
	mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2));
	//mass->SetParError(0,f->GetParError(0));
	//mass->SetParError(1,f->GetParError(1));
	//mass->SetParError(2,f->GetParError(2));
	mass->SetLineColor(2);

	h->SetXTitle("m_{#mu#muK} (GeV/c^{2})");
	h->SetYTitle("Entries / (5 MeV/c^{2})");
	h->GetXaxis()->CenterTitle();
	h->GetYaxis()->CenterTitle();
	h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y");
	h->GetXaxis()->SetTitleOffset(1.3);
	h->GetYaxis()->SetTitleOffset(1.8);
	h->GetXaxis()->SetLabelOffset(0.007);
	h->GetYaxis()->SetLabelOffset(0.007);
	h->GetXaxis()->SetTitleSize(0.045);
	h->GetYaxis()->SetTitleSize(0.045);
	h->GetXaxis()->SetTitleFont(42);
	h->GetYaxis()->SetTitleFont(42);
	h->GetXaxis()->SetLabelFont(42);
	h->GetYaxis()->SetLabelFont(42);
	h->GetXaxis()->SetLabelSize(0.04);
	h->GetYaxis()->SetLabelSize(0.04);
	h->SetMarkerSize(0.8);
	h->SetMarkerStyle(20);
	h->SetStats(0);
	h->Draw("e");
	background->Draw("same");   
	mass->SetRange(minhisto,maxhisto);
	mass->Draw("same");
	mass->SetLineStyle(2);
	mass->SetFillStyle(3004);
	mass->SetFillColor(2);
	f->Draw("same");

	Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass;
	Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0);

	TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC");
	leg->SetBorderSize(0);
	leg->SetTextSize(0.04);
	leg->SetTextFont(42);
	leg->SetFillStyle(0);
	leg->AddEntry(h,"Data","pl");
	leg->AddEntry(f,"Fit","l");
	leg->AddEntry(mass,"Peaking BG","f");
	leg->AddEntry(background,"Combinatorial","l");
	leg->Draw("same");

	TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
	texCms->SetNDC();
	texCms->SetTextAlign(12);
	texCms->SetTextSize(0.04);
	texCms->SetTextFont(42);
	texCms->Draw();

	TLatex* texCol;
	if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","pp"));
	else texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","PbPb"));
	texCol->SetNDC();
	texCol->SetTextAlign(32);
	texCol->SetTextSize(0.04);
	texCol->SetTextFont(42);
	texCol->Draw();

	TLatex* tex;

	tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetTextSize(0.04);
	tex->SetLineWidth(2);
	tex->Draw();

	if(centMax>0){
		TString texper="%";
		tex = new TLatex(0.22,0.71,Form("Centrality %.0f-%.0f%s",centMin,centMax,texper.Data()));//0.2612903,0.8425793
		tex->SetNDC();
		tex->SetTextColor(1);
		tex->SetTextFont(42);
		tex->SetTextSize(0.045);
		tex->SetLineWidth(2);
		tex->Draw();
	}

	tex = new TLatex(0.22,0.83,"|y| < 2.4");
	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetTextSize(0.04);
	tex->SetLineWidth(2);
	tex->Draw();

	total=f;

	h->Write();
	f->Write();
	if(!isPbPb) c->SaveAs(Form("plotNP/BMass%s_%d.pdf",collisionsystem.Data(),count));
	else c->SaveAs(Form("plotNP/BMass%s_%.0f_%.0f_%d.pdf",collisionsystem.Data(),centMin,centMax,count));
	return mass;
}
Esempio n. 3
0
int main(int argc, char** argv){

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


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

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

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

  if (ntrueargs<3) return printUsage();

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

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




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

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

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

  TString directory = DirectoryLast + "/BeforeCuts";

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

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

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

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

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

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



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


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

            leg->Draw();




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

  TString directory2 = DirectoryLast + "/LastCut";

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

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

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

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


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

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

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

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

  return 0;
}
Esempio n. 4
0
void triggerEfficiency() {
   
   TCut trigCut;
   trigCut = "yhlt.HLT_HISinglePhoton40_v2";
   //   trigCut = "yhlt.HLT_HISinglePhoton30_v2";
   //trigCut = "yhlt.L1_SingleEG5_BptxAND";
   //   trigCut = "yhlt.HLT_HISinglePhoton30_v2  ";
   //  trigCut = "yhlt.L1_SingleEG5_BptxAND";// || yhlt.HLT_HIJet80_v1";
   // || yhlt.HLT_HIJet80_v1";
   
   TCut goodL1Cut = "yhlt.Run > 181675 && !(yhlt.Run==181912 || yhlt.Run==181910 || yhlt.Run==182089 || yhlt.Run==182098 || yhlt.Run==182099 || yhlt.Run==182124)";
   TCut goodHLTCut = "!(yhlt.Run==182123 || yhlt.Run==182133 || yhlt.Run==181946)  && yhlt.Run<=182134  ";
   TCut goodRunCut = goodL1Cut && goodHLTCut;
   
   const int nPtBin = 10;
   double ptBin[nPtBin+1] = {0,10,15,20,25,30,33,41,50,70,120};
   TH1D* heff         = new TH1D("heff",";Leading Photon E_{T} (GeV);",nPtBin, ptBin);
   TGraphAsymmErrors* geff = new TGraphAsymmErrors();

   TCanvas* c1  = new TCanvas("c2","",610,522);
   c1->Divide(2,1);
   c1->cd(1);
  
   getEff(heff,geff,trigCut,ptMode, goodRunCut);
   handsomeTH1(heff,1);
   handsomeTGraph(geff,1);
   geff->SetMarkerStyle(20);
   heff->SetMarkerSize(0.1);
   for ( int i=0;i<= heff->GetNbinsX() ; i++)
      heff->SetBinError(i,0);
   heff->Draw(0);
   //   heff->DrawCopy("pl");
   geff->Draw("p");
   drawText("HLT_HISinglePhoton40",0.4,0.3,1,18);
   
   c1->cd(2);
   TH1D* heffr         = new TH1D("heffr",";Run number;",182400.5 - 181500.5,181500.5,182400.5);
   TGraphAsymmErrors* geffr = new TGraphAsymmErrors();
   getEff(heffr,geffr,trigCut, runByRunMode, "pt>50" && goodRunCut);
   handsomeTH1(heffr,1);
   heffr->SetNdivisions(505);
   handsomeTGraph(geffr,1);
   geffr->SetMarkerStyle(20);
   heffr->Reset();
   heffr->DrawCopy();
   geffr->Draw("p");
   
   TCanvas* c3  = new TCanvas("c3","",700,500);
   heff->SetYTitle("Efficiency");
   heff->SetFillColor(kGray);
   heff->SetFillStyle(3001);
   heff->SetAxisRange(0,1.2,"Y");
   heff->DrawCopy("hist ");
   geff->Draw("p same");
   drawCMS3(0.5,0.5,84,17);
   drawText("HLT_HISinglePhoton40",0.5,0.3,1,18);
   
      c3->SaveAs("plot_triggerEfficiencyPhoton30.eps");
     c3->SaveAs("plot_triggerEfficiencyPhoton30.gif");

}
Esempio n. 5
0
void ZuuRate(void){

	
	//--------------------------------------//
	// ATLAS STYLE				//
	//--------------------------------------//

	gROOT->LoadMacro("~/Root/atlasstyle-00-03-01/AtlasStyle.C");
  	gROOT->LoadMacro("~/Root/atlasstyle-00-03-01/AtlasLabels.C");
  	AtlasStyle();
  	TStyle* atlasStyle = AtlasStyle();
  	gROOT->SetStyle("ATLAS");
  	gROOT->ForceStyle();
	//gStyle->SetOptStat("enmriou");
	gStyle->SetPalette(1);

	Int_t mc_RunNumber[] = {107650,107651,107652,107653,107654,107655,               //Zee + light jets
				107660,107661,107662,107663,107664,107665, 		 //Zuu + light jets
				116950,116951,116952,116953,116960,116961,116962,116963, //Zeebb 4LepM + bgdVeto4LepM
				116955,116956,116957,116958,116965,116966,116967,116968,  //Zuubb 4LepM + bgdVeto4LepM
				128971,							 //PythiaWZ_inclusive
				105200,							 //T1_McAtNlo_Jimmy
				116601,116602,116603,126859,126860,126861,126862,126863,126864//ZZ
				};

	TFile *file0 = new TFile("../output/Zuu_DATA.root");
	TH1D *hData = (TH1D *) file0->Get("Zuu_rate");

	TH1D *hZjets = new TH1D("", "", 11, 0, 11);
	for(int i =  0; i <  12 ; i++){  //Z + light jets bgd
		TFile *file = new TFile(Form("../output/Zuu_MC_%d.root",mc_RunNumber[i]));
		TH1D *h = (TH1D *) file->Get("Zuu_rate");
		hZjets->Add(h);
		delete h;
		delete file;
	}

	TH1D *hZbbjets = new TH1D("", "", 11, 0, 11);
	for(int i = 12; i < 28 ; i++){  //Zbb 4LepM + bgdVeto4LepM
		TFile *file = new TFile(Form("../output/Zuu_MC_%d.root",mc_RunNumber[i]));
		TH1D *h = (TH1D *) file->Get("Zuu_rate");
		hZbbjets->Add(h);
		delete h;
		delete file;
	}

	TH1D *hWZ = new TH1D("", "", 11, 0, 11);
	for(int i = 28; i < 29 ; i++){  //PythiaWZ_inclusive
		TFile *file = new TFile(Form("../output/Zuu_MC_%d.root",mc_RunNumber[i]));
		TH1D *h = (TH1D *) file->Get("Zuu_rate");
		hWZ->Add(h);
		delete h;
		delete file;
	}

	TH1D *httbar = new TH1D("", "", 11, 0, 11);
	for(int i = 29; i < 30 ; i++){  //T1_McAtNlo_Jimmy
		TFile *file = new TFile(Form("../output/Zuu_MC_%d.root",mc_RunNumber[i]));
		TH1D *h = (TH1D *) file->Get("Zuu_rate");
		httbar->Add(h);
		delete h;
		delete file;
	}

	TH1D *hZZ = new TH1D("", "", 11, 0, 11);
	for(int i = 30; i < 39 ; i++){  //ZZ
		TFile *file = new TFile(Form("../output/Zuu_MC_%d.root",mc_RunNumber[i]));
		TH1D *h = (TH1D *) file->Get("Zuu_rate");
		hZZ->Add(h);
		delete h;
		delete file;
	}
	/*-----------------------------------------------------------------*/
/*	hData->Sumw2();
	hZjets->Sumw2();
	hZbbjets->Sumw2();
	hWZ->Sumw2();
	httbar->Sumw2();
	hZZ->Sumw2();
*/
	/*-----------------------------------------------------------------*/

	const Float_t LumiPeriod[] = {
		11.74, 166.77,
		48.70, 142.56, 537.54, 259.46,
		386.23, 226.46, 600.07,
		1401.87, 1025.62
	};

	const Float_t LumiPeriodMC[] = {
		LumiPeriod[0] + LumiPeriod[1],
		LumiPeriod[2] + LumiPeriod[3] + LumiPeriod[4] + LumiPeriod[5],
		LumiPeriod[6] + LumiPeriod[7] + LumiPeriod[8],
		LumiPeriod[9] + LumiPeriod[10]
	};

	/*-----------------------------------------------------------------*/

	if(1)
	{
		// MC : Z+jets //
		hZjets->TH1::SetBinContent(1,  hZjets->TH1::GetBinContent(1)  / (float)LumiPeriodMC[0]);
		hZjets->TH1::SetBinContent(2,  hZjets->TH1::GetBinContent(2)  / (float)LumiPeriodMC[0]);

		hZjets->TH1::SetBinContent(3,  hZjets->TH1::GetBinContent(3)  / (float)LumiPeriodMC[1]);
		hZjets->TH1::SetBinContent(4,  hZjets->TH1::GetBinContent(4)  / (float)LumiPeriodMC[1]);
		hZjets->TH1::SetBinContent(5,  hZjets->TH1::GetBinContent(5)  / (float)LumiPeriodMC[1]);
		hZjets->TH1::SetBinContent(6,  hZjets->TH1::GetBinContent(6)  / (float)LumiPeriodMC[1]);

		hZjets->TH1::SetBinContent(7,  hZjets->TH1::GetBinContent(7)  / (float)LumiPeriodMC[2]);
		hZjets->TH1::SetBinContent(8,  hZjets->TH1::GetBinContent(8)  / (float)LumiPeriodMC[2]);
		hZjets->TH1::SetBinContent(9,  hZjets->TH1::GetBinContent(9)  / (float)LumiPeriodMC[2]);

		hZjets->TH1::SetBinContent(10, hZjets->TH1::GetBinContent(10) / (float)LumiPeriodMC[3]);
		hZjets->TH1::SetBinContent(11, hZjets->TH1::GetBinContent(11) / (float)LumiPeriodMC[3]);

		// MC : Zbb+jets //
		hZbbjets->TH1::SetBinContent(1,  hZbbjets->TH1::GetBinContent(1)  / (float)LumiPeriodMC[0]);
		hZbbjets->TH1::SetBinContent(2,  hZbbjets->TH1::GetBinContent(2)  / (float)LumiPeriodMC[0]);

		hZbbjets->TH1::SetBinContent(3,  hZbbjets->TH1::GetBinContent(3)  / (float)LumiPeriodMC[1]);
		hZbbjets->TH1::SetBinContent(4,  hZbbjets->TH1::GetBinContent(4)  / (float)LumiPeriodMC[1]);
		hZbbjets->TH1::SetBinContent(5,  hZbbjets->TH1::GetBinContent(5)  / (float)LumiPeriodMC[1]);
		hZbbjets->TH1::SetBinContent(6,  hZbbjets->TH1::GetBinContent(6)  / (float)LumiPeriodMC[1]);

		hZbbjets->TH1::SetBinContent(7,  hZbbjets->TH1::GetBinContent(7)  / (float)LumiPeriodMC[2]);
		hZbbjets->TH1::SetBinContent(8,  hZbbjets->TH1::GetBinContent(8)  / (float)LumiPeriodMC[2]);
		hZbbjets->TH1::SetBinContent(9,  hZbbjets->TH1::GetBinContent(9)  / (float)LumiPeriodMC[2]);

		hZbbjets->TH1::SetBinContent(10, hZbbjets->TH1::GetBinContent(10) / (float)LumiPeriodMC[3]);
		hZbbjets->TH1::SetBinContent(11, hZbbjets->TH1::GetBinContent(11) / (float)LumiPeriodMC[3]);

		// MC : WZ //
		hWZ->TH1::SetBinContent(1,  hWZ->TH1::GetBinContent(1)  / (float)LumiPeriodMC[0]);
		hWZ->TH1::SetBinContent(2,  hWZ->TH1::GetBinContent(2)  / (float)LumiPeriodMC[0]);

		hWZ->TH1::SetBinContent(3,  hWZ->TH1::GetBinContent(3)  / (float)LumiPeriodMC[1]);
		hWZ->TH1::SetBinContent(4,  hWZ->TH1::GetBinContent(4)  / (float)LumiPeriodMC[1]);
		hWZ->TH1::SetBinContent(5,  hWZ->TH1::GetBinContent(5)  / (float)LumiPeriodMC[1]);
		hWZ->TH1::SetBinContent(6,  hWZ->TH1::GetBinContent(6)  / (float)LumiPeriodMC[1]);

		hWZ->TH1::SetBinContent(7,  hWZ->TH1::GetBinContent(7)  / (float)LumiPeriodMC[2]);
		hWZ->TH1::SetBinContent(8,  hWZ->TH1::GetBinContent(8)  / (float)LumiPeriodMC[2]);
		hWZ->TH1::SetBinContent(9,  hWZ->TH1::GetBinContent(9)  / (float)LumiPeriodMC[2]);

		hWZ->TH1::SetBinContent(10, hWZ->TH1::GetBinContent(10) / (float)LumiPeriodMC[3]);
		hWZ->TH1::SetBinContent(11, hWZ->TH1::GetBinContent(11) / (float)LumiPeriodMC[3]);

		// MC : ttbar //
		httbar->TH1::SetBinContent(1,  httbar->TH1::GetBinContent(1)  / (float)LumiPeriodMC[0]);
		httbar->TH1::SetBinContent(2,  httbar->TH1::GetBinContent(2)  / (float)LumiPeriodMC[0]);

		httbar->TH1::SetBinContent(3,  httbar->TH1::GetBinContent(3)  / (float)LumiPeriodMC[1]);
		httbar->TH1::SetBinContent(4,  httbar->TH1::GetBinContent(4)  / (float)LumiPeriodMC[1]);
		httbar->TH1::SetBinContent(5,  httbar->TH1::GetBinContent(5)  / (float)LumiPeriodMC[1]);
		httbar->TH1::SetBinContent(6,  httbar->TH1::GetBinContent(6)  / (float)LumiPeriodMC[1]);

		httbar->TH1::SetBinContent(7,  httbar->TH1::GetBinContent(7)  / (float)LumiPeriodMC[2]);
		httbar->TH1::SetBinContent(8,  httbar->TH1::GetBinContent(8)  / (float)LumiPeriodMC[2]);
		httbar->TH1::SetBinContent(9,  httbar->TH1::GetBinContent(9)  / (float)LumiPeriodMC[2]);

		httbar->TH1::SetBinContent(10, httbar->TH1::GetBinContent(10) / (float)LumiPeriodMC[3]);
		httbar->TH1::SetBinContent(11, httbar->TH1::GetBinContent(11) / (float)LumiPeriodMC[3]);

		// MC : ZZ //
		hZZ->TH1::SetBinContent(1,  hZZ->TH1::GetBinContent(1)  / (float)LumiPeriodMC[0]);
		hZZ->TH1::SetBinContent(2,  hZZ->TH1::GetBinContent(2)  / (float)LumiPeriodMC[0]);

		hZZ->TH1::SetBinContent(3,  hZZ->TH1::GetBinContent(3)  / (float)LumiPeriodMC[1]);
		hZZ->TH1::SetBinContent(4,  hZZ->TH1::GetBinContent(4)  / (float)LumiPeriodMC[1]);
		hZZ->TH1::SetBinContent(5,  hZZ->TH1::GetBinContent(5)  / (float)LumiPeriodMC[1]);
		hZZ->TH1::SetBinContent(6,  hZZ->TH1::GetBinContent(6)  / (float)LumiPeriodMC[1]);

		hZZ->TH1::SetBinContent(7,  hZZ->TH1::GetBinContent(7)  / (float)LumiPeriodMC[2]);
		hZZ->TH1::SetBinContent(8,  hZZ->TH1::GetBinContent(8)  / (float)LumiPeriodMC[2]);
		hZZ->TH1::SetBinContent(9,  hZZ->TH1::GetBinContent(9)  / (float)LumiPeriodMC[2]);

		hZZ->TH1::SetBinContent(10, hZZ->TH1::GetBinContent(10) / (float)LumiPeriodMC[3]);
		hZZ->TH1::SetBinContent(11, hZZ->TH1::GetBinContent(11) / (float)LumiPeriodMC[3]);

		// DATA //

		Int_t DataNb_B = hData->TH1::GetBinContent(1);
		Int_t DataNb_D = hData->TH1::GetBinContent(2);
		Int_t DataNb_E = hData->TH1::GetBinContent(3);
		Int_t DataNb_F = hData->TH1::GetBinContent(4);
		Int_t DataNb_G = hData->TH1::GetBinContent(5);
		Int_t DataNb_H = hData->TH1::GetBinContent(6);
		Int_t DataNb_I = hData->TH1::GetBinContent(7);
		Int_t DataNb_J = hData->TH1::GetBinContent(8);
		Int_t DataNb_K = hData->TH1::GetBinContent(9);
		Int_t DataNb_L = hData->TH1::GetBinContent(10);
		Int_t DataNb_M = hData->TH1::GetBinContent(11);

		hData->TH1::SetBinContent(1,  (float)DataNb_B / (float)LumiPeriod[0]);
		hData->TH1::SetBinContent(2,  (float)DataNb_D / (float)LumiPeriod[1]);

		hData->TH1::SetBinContent(3,  (float)DataNb_E / (float)LumiPeriod[2]);
		hData->TH1::SetBinContent(4,  (float)DataNb_F / (float)LumiPeriod[3]);
		hData->TH1::SetBinContent(5,  (float)DataNb_G / (float)LumiPeriod[4]);
		hData->TH1::SetBinContent(6,  (float)DataNb_H / (float)LumiPeriod[5]);

		hData->TH1::SetBinContent(7,  (float)DataNb_I / (float)LumiPeriod[6]);
		hData->TH1::SetBinContent(8,  (float)DataNb_J / (float)LumiPeriod[7]);
		hData->TH1::SetBinContent(9,  (float)DataNb_K / (float)LumiPeriod[8]);

		hData->TH1::SetBinContent(10, (float)DataNb_L / (float)LumiPeriod[9]);
		hData->TH1::SetBinContent(11, (float)DataNb_M / (float)LumiPeriod[10]);
	}


	hData->SetMarkerStyle(20);
	hZjets->SetFillColor(kBlue);
	hZbbjets->SetFillColor(kRed);
	hWZ->SetFillColor(kYellow);
	httbar->SetFillColor(kGreen);
	hZZ->SetFillColor(kCyan - 7);

	const char *names[] = {
			"B", "D",
			"E", "F", "G", "H",
			"I", "J", "K",
			"L", "M"
		};
	TAxis *axis1 = hData->GetXaxis();

	for(int i = 1; i < 12; i++)
	{
		axis1->SetBinLabel(i - 0, names[i - 1]);
	}
	hData->SetXTitle("2011 Periods");
	hData->SetYTitle("Z#rightarrow #mu#mu candidats / Luminosity [pb]");
	THStack* hresult = new THStack("hresults","hresult");

	hresult->Add(hZZ);
	hresult->Add(hWZ); 
	hresult->Add(httbar);
	hresult->Add(hZbbjets);
	hresult->Add(hZjets);

	TCanvas *c = new TCanvas("c","c");
	c->SetLogy();
	hData->TH1::SetMinimum(0.01);
	hData->TH1::SetMaximum(100000);
	hData->Draw("EP");
	hresult->Draw("SAME");

	TLegend*leg1=new TLegend(0.25,0.75,0.50,0.9);
	leg1->SetFillColor(0);
	leg1->SetShadowColor(0);
	leg1->SetBorderSize(0);
	leg1->AddEntry(httbar,"t#bar{t}","f");
	leg1->AddEntry(hWZ,"WZ","f");
	leg1->AddEntry(hZZ,"ZZ","f");
	leg1->Draw();

	TLegend*leg2=new TLegend(0.40,0.75,0.60,0.9);
	leg2->SetFillColor(0);
	leg2->SetShadowColor(0);
	leg2->SetBorderSize(0);
	leg2->AddEntry(hData,"Data","ep");
	leg2->AddEntry(hZjets,"Z light jets","f");
	leg2->AddEntry(hZbbjets,"Zbb","f");
	leg2->Draw();

	TLatex l2;
	l2.SetNDC();
	l2.DrawLatex(0.65, 0.8, "#int L dt  #approx 4.8 fb^{-1}");

	c->SaveAs("2011_ZuuRate.png");


}
Esempio n. 6
0
TF1 *fit(TTree *nt, TTree *ntMC, double ptmin,double ptmax)
{   
   //cout<<cut.Data()<<endl;
   static int count=0;
   count++;
   TCanvas *c= new TCanvas(Form("c%d",count),"",600,600);
   TH1D *h = new TH1D(Form("h%d",count),"",30,5.03,5.93);
//   TH1D *hBck = new TH1D(Form("hBck%d",count),"",40,5,6);
   
   TH1D *hMC = new TH1D(Form("hMC%d",count),"",30,5.03,5.93);
   // Fit function
   //QM2014
   //TString iNP="6.71675e+00*Gaus(x,5.30142e+00,8.42680e-02)/(sqrt(2*3.14159)*8.42680e-02)+4.06744e+01*Gaus(x,5.00954e+00,8.11305e-02)/(sqrt(2*3.14159)*8.11305e-02)+5.99974e-01*(2.376716*Gaus(x,5.640619,0.095530)/(sqrt(2*3.14159)*0.095530)+3.702342*Gaus(x,5.501706,0.046222)/(sqrt(2*3.14159)*0.046222))+1.31767e-01*(61.195688*Gaus(x,5.127566,0.087439)/(sqrt(2*3.14159)*0.087439)+58.943919*Gaus(x,5.246471,0.041983)/(sqrt(2*3.14159)*0.041983))";
   TString iNP="2.28629e1*Gaus(x,5.02606,6.84e-2)/(sqrt(2*3.14159)*(6.84e-2))+3.85695*Gaus(x,5.27701,0.04305)/(sqrt(2*3.14159)*(0.04305))";


   TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[6]*("+iNP+")");

   nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax));   
   ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax));   
//   nt->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax));   
//   nt2->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax));   

//   cout <<"nsig = "<<hBck->GetEntries();
   clean0(h);
   h->Draw();
   f->SetParLimits(4,-1000,0);
   f->SetParLimits(2,0.01,0.08);
   f->SetParLimits(8,0.01,0.1);
   f->SetParLimits(7,0,1);
   f->SetParLimits(6,0,1000);

   f->SetParameter(0,setparam0);
   f->SetParameter(1,setparam1);
   f->SetParameter(2,setparam2);
   f->SetParameter(8,setparam3);
   f->FixParameter(1,fixparam1);
   f->FixParameter(6,0);
   h->GetEntries();

   hMC->Fit(Form("f%d",count),"q","",5,6);
   hMC->Fit(Form("f%d",count),"q","",5,6);
   f->ReleaseParameter(1);
   hMC->Fit(Form("f%d",count),"L q","",5,6);
   hMC->Fit(Form("f%d",count),"L q","",5,6);
   hMC->Fit(Form("f%d",count),"L q","",5,6);
   hMC->Fit(Form("f%d",count),"L m","",5,6);

   f->FixParameter(1,f->GetParameter(1));
   f->FixParameter(2,f->GetParameter(2));
   f->FixParameter(7,f->GetParameter(7));
   f->FixParameter(8,f->GetParameter(8));
   f->ReleaseParameter(6);
   
   h->Fit(Form("f%d",count),"q","",5,6);
   h->Fit(Form("f%d",count),"q","",5,6);
   f->ReleaseParameter(1);
   h->Fit(Form("f%d",count),"L q","",5,6);
   h->Fit(Form("f%d",count),"L q","",5,6);
   h->Fit(Form("f%d",count),"L q","",5,6);
   h->Fit(Form("f%d",count),"L m","",5,6);
   h->SetMarkerSize(0.8);
   h->SetMarkerStyle(20);
   cout <<h->GetEntries()<<endl;

   cout<<"======= chi2 ======="<<endl;
   cout<<f->GetChisquare()<<endl;
   cout<<"===== chi2 end ====="<<endl;

   // function for background shape plotting. take the fit result from f
   TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x");
   background->SetParameter(0,f->GetParameter(3));
   background->SetParameter(1,f->GetParameter(4));
   background->SetLineColor(4);
   background->SetRange(5,6);
   background->SetLineStyle(2);
   
   // function for signal shape plotting. take the fit result from f
   TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*("+iNP+")");
   Bkpi->SetParameter(0,f->GetParameter(6));
   Bkpi->SetLineColor(kGreen+1);
   Bkpi->SetFillColor(kGreen+1);
   Bkpi->SetRange(5.00,6.00);
   Bkpi->SetLineStyle(1);
   Bkpi->SetFillStyle(3005);

   // function for signal shape plotting. take the fit result from f
   TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))");
   mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8));
   mass->SetParError(0,f->GetParError(0));
   mass->SetParError(1,f->GetParError(1));
   mass->SetParError(2,f->GetParError(2));
   mass->SetParError(7,f->GetParError(7));
   mass->SetParError(8,f->GetParError(8));
   mass->SetLineColor(2);
   mass->SetLineStyle(2);

//   cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl;
   h->SetMarkerStyle(24);
   h->SetStats(0);
   h->Draw("e");
   h->SetXTitle("M_{B} (GeV/c^{2})");
   h->SetYTitle("Entries / (30 MeV/c^{2})");
   h->GetXaxis()->CenterTitle();
   h->GetYaxis()->CenterTitle();
   h->SetTitleOffset(1.5,"Y");
   h->SetAxisRange(0,h->GetMaximum()*1.2,"Y");

 //  hBck->Draw("hist same");

   Bkpi->Draw("same");
   background->Draw("same");   
   mass->SetRange(5,6);
   mass->Draw("same");
   mass->SetLineStyle(2);
   mass->SetFillStyle(3004);
   mass->SetFillColor(2);
   f->Draw("same");

   cout <<"fit result:"<<f->GetParameter(0)*2.5<<" "<<f->Integral(5,6)/h->GetBinWidth(1)<<endl;

   double yield = mass->Integral(5,6)/0.03;
   double yieldErr = mass->Integral(5,6)/0.03*mass->GetParError(0)/mass->GetParameter(0);
   
   // Draw the legend:)   
   TLegend *leg = myLegend(0.50,0.5,0.86,0.89);
   leg->AddEntry(h,"CMS Preliminary","");
   leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV","");
   leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),"");
   leg->AddEntry(h,"Data","pl");
   leg->AddEntry(f,"Fit","l");
   leg->AddEntry(mass,"Signal","f");
   leg->AddEntry(background,"Combinatorial Background","l");
   leg->AddEntry(Bkpi,"Non-prompt J/#psi","f");
   leg->Draw();
   TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50);
   leg2->AddEntry(h,"B meson","");
   leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",f->GetParameter(1)*1000.,f->GetParError(1)*1000.),"");
   leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f",yield,yieldErr),"");
   leg2->Draw();

   //c->SaveAs(Form("../ResultsBzero/BMass-%d.pdf",count));
   c->SaveAs("../../../BzeroDefault.pdf");

   return mass;
}
Esempio n. 7
0
void fitX(TString infname="/data/twang/BfinderRun2/DoubleMu/BfinderData_pp_20151202_bPt0jpsiPt0tkPt0p5/finder_pp_merged.root")
{
   
   TFile *inf = new TFile(infname.Data());
   TTree *ntmix = (TTree*) inf->Get("Bfinder/ntmix");
   TH1D *h = new TH1D("h","",40,3.6,4);
   TCut cutTrk = "1";   //original YJ
   //TCut cutTrk = "Btrk1PixelHit>=2&&Btrk1StripHit>=7&&Btrk1Chi2ndf<5&&Btrk2PixelHit>=2&&Btrk2StripHit>=7&&Btrk2Chi2ndf<5";
   TCut cutTotal="Btype==7&&Bpt>10&&abs(Beta)<10&&sqrt((Bmumueta-Btrk1Eta)*(Bmumueta-Btrk1Eta)+(Bmumuphi-Btrk1Phi)*(Bmumuphi-Btrk1Phi))<9999"&&cutTrk;

   TCanvas *c = new TCanvas("c","",750,600);
    ntmix->Draw("Bmass>>h",cutTotal);

    
    TFile*output=new TFile("histoX.root","recreate");
    output->cd();
    h->Write();
    output->Close();

   h->Sumw2();
   TF1 *f = new TF1("f","[0]+[1]*x+[2]*x*x+[8]*x*x*x+[9]*x*x*x*x+[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])");
   f->SetLineColor(4);
   f->SetParameters(-2.2597e4,1.326e4,-1.727e3,50,3.686,0.00357,1,3.8725,0.0054);
   f->FixParameter(4,3.686);
   f->FixParameter(5,0.00357);
   f->FixParameter(7,3.8725);
   h->Fit("f","LL");
   h->Fit("f","");
   h->Fit("f","LL");
   h->Fit("f","LL","",3.65,3.94);
   h->Fit("f","LL","",3.65,3.94);
   f->ReleaseParameter(4);
   f->ReleaseParameter(5);
   f->ReleaseParameter(7);
   h->Fit("f","LL","",3.65,3.94);
   h->SetXTitle("m(J/#psi#pi^{+}#pi^{-}) [GeV]");
   h->SetYTitle("Entries");
   h->SetStats(0);
   h->SetAxisRange(0,h->GetMaximum()*1.3	,"Y");
   TF1 *f2 = new TF1("f2","[0]+[1]*x+[2]*x*x+0*Gaus(x,[4],[5])+0*Gaus(x,[7],[5])");
   f2->SetParameter(0,f->GetParameter(0));
   f2->SetParameter(1,f->GetParameter(1));
   f2->SetParameter(2,f->GetParameter(2));
   TF1 *f3 = new TF1("f3","[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])");
   f3->SetParameter(3,f->GetParameter(3));
   f3->SetParameter(4,f->GetParameter(4));
   f3->SetParameter(5,f->GetParameter(5));
   f3->SetParameter(6,f->GetParameter(6));
   f3->SetParameter(7,f->GetParameter(7));
   f3->SetParameter(8,f->GetParameter(8));

   f->SetLineColor(4);
   f2->SetLineColor(4);
   f3->SetRange(3.65,3.94);
   f2->SetRange(3.65,3.94);
   f2->SetLineStyle(2);
   f3->SetLineStyle(2);
   f2->Draw("same");
   f3->SetLineColor(2);
   f3->SetFillStyle(3004);
   f3->SetFillColor(2);
   f3->Draw("same");
   TLatex *l = new TLatex(3.7,70./80*h->GetMaximum(),"#psi(2S)");
   l->Draw();
   TLatex *l2 = new TLatex(3.875,50./80*h->GetMaximum(),"X(3872)");
   l2->Draw();
   TLatex *l3 = new TLatex(3.812,70./80*h->GetMaximum(),"CMS Preliminary");
   l3->Draw();
   TLatex *l4 = new TLatex(3.78,60./80*h->GetMaximum(),"pp #sqrt{s_{NN}}=5.02 TeV");
  l4->Draw();
   cout<<ntmix->GetEntries()<<endl;
   
   TH1D *hProj = (TH1D*)h->Clone("hProj");
   hProj->Clear();
   f->SetRange(3.6,4);
   for (int i=0;i<h->GetEntries()*11;i++)
   {
      hProj->Fill(f->GetRandom());
   } 
   
   TCanvas *c2 = new TCanvas("c2","",750,600);
   hProj->SetTitle("Estimated Projection");
   hProj->Draw("e");
}
void balanceMetVsAj(TString infname = "dj_HCPR-J50U-hiGoodMergedTracks_OfficialSelv2_Final0_120_50.root",
                    TCut myCut = "cent<30", TString metType = "",bool drawLegend = false,
                    bool drawSys = true
		    )
{
   // ===========================================================
   // Get Input
   // ===========================================================
   TFile *inf = new TFile(infname);
   TTree *t = (TTree*)inf->Get("ntjt");

   vector<TString> mergedPt,target;
   mergedPt.push_back("metxMergedAll"); target.push_back("(metx0+metx1+metx2+metx3+metx4+metx5)");
   mergedPt.push_back("metxMerged0"); target.push_back("(metx0)");
   mergedPt.push_back("metxMerged1"); target.push_back("(metx1)");
   mergedPt.push_back("metxMerged2"); target.push_back("(metx2)");
   mergedPt.push_back("metxMerged3"); target.push_back("(metx3)");
   mergedPt.push_back("metxMerged4"); target.push_back("(metx4+metx5)");
   for (Int_t i=0; i<mergedPt.size(); ++i) {
     if (metType!="") {
       target[i].ReplaceAll("metx",metType);
     }
     cout << "Alias: " << mergedPt[i] << " target: " << target[i] << endl;
     t->SetAlias(mergedPt[i],target[i]);
   }

   // ===========================================================
   // Analysis Setup
   // ===========================================================
   const int nBin = 5;
   double bins[nBin+1] = {0.5,1.0,2,4,8,1000};  
   
   const int nBinAj = 4;
   double ajBins[nBinAj+1] = {0.0001,0.11,0.22,0.33,0.49999};
   // Selection cut
   TCut evtCut = "nljet>120&&abs(nljetacorr)<1.6&&aljet>50&&abs(aljetacorr)<1.6&&jdphi>5./6*TMath::Pi()&&!maskEvt";

   cout << "Sel evt: " << t->GetEntries(evtCut&&myCut) << endl;

   // ===========================================================
   // Find Average Weights
   // ===========================================================
   TH1D *hw[nBinAj];
   float meanWt[nBinAj];
   for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
      hw[iaj] = new TH1D(Form("hw_aj%d",iaj),"",1000,0,100);
      TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
      t->Draw(Form("weight>>hw_aj%d",iaj), evtCut&&myCut&&ajCut);
      meanWt[iaj] = hw[iaj]->GetMean();
      cout << " <Weight>: " << meanWt[iaj] << endl;
   }

   // ===========================================================
   // Draw Weighted Averages
   // ===========================================================
   TH1D *ppos[nBin];
   TH1D *pneg[nBin];
   TH1D *pe[nBin];
   for (int i=0;i<nBin;i++)
   {
      TH1D *h1 = new TH1D(Form("h1%d",i),"",nBinAj,ajBins);
      TH1D *h2 = new TH1D(Form("h2%d",i),"",nBinAj,ajBins);
      TH1D *he[nBinAj];
      
      // =================================
      // Get Weighted Mean for each Aj bin
      // =================================
      h1->Sumw2();
      h2->Sumw2();
      t->Draw(Form("Aj>>h1%d",i), "weight"*(evtCut&&myCut));
      t->Draw(Form("Aj>>h2%d",i), Form("((-weight*metxMerged%d))",i)*(evtCut&&myCut));
      
      pe[i]=(TH1D*)h2->Clone();
      pe[i]->SetName(Form("p%d",i));     
      pe[i]->Divide(h1);
      ppos[i] = new TH1D(Form("ppos%d",i),"",nBinAj,ajBins);
      ppos[i]->SetLineColor(1);     
      ppos[i]->SetMarkerColor(colors[i]);
      ppos[i]->SetFillColor(colors[i]);
      ppos[i]->SetFillStyle(1001);
      pneg[i] = new TH1D(Form("pneg%d",i),"",nBinAj,ajBins);
      pneg[i]->SetLineColor(1);     
      pneg[i]->SetMarkerColor(colors[i]);
      pneg[i]->SetFillColor(colors[i]);
      pneg[i]->SetFillStyle(1001);

      // =================================
      // Caculated Stat Error of the Mean
      // =================================
      cout << "Stat Error for pt bin " << i << ": ";
      for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
         he[iaj] = new TH1D(Form("he%d_aj%d",i,iaj),"",100,-200,200);
         TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
         t->Draw(Form("((metxMerged%d))>>he%d_aj%d",i,i,iaj), "weight" * evtCut&&myCut&&ajCut);
         float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries()));
	 cout << theError << " ";
	 pe[i]->SetBinError(iaj+1, theError);
      }
      cout << endl;
   }

   // Stack
   for (int i=nBin-1;i>=0;i--)
   {
      for(int iaj = 0 ; iaj< nBinAj ; iaj++) {
         double posVal=0, negVal=0;
         double posValErr=0, negValErr=0;
         if (i!=nBin-1) {
            posVal = ppos[i+1]->GetBinContent(iaj+1);
            posValErr = ppos[i+1]->GetBinError(iaj+1);
            negVal = pneg[i+1]->GetBinContent(iaj+1);
            negValErr = pneg[i+1]->GetBinError(iaj+1);
         }
         if (pe[i]->GetBinContent(iaj+1)<0) {
            negVal+=pe[i]->GetBinContent(iaj+1);
            negValErr=pe[i]->GetBinError(iaj+1);
            posValErr=0;
         } else if (pe[i]->GetBinContent(iaj+1)>0) {
            posVal+=pe[i]->GetBinContent(iaj+1);
            posValErr=pe[i]->GetBinError(iaj+1);
            negValErr=0;
         } 
         ppos[i]->SetBinContent(iaj+1,posVal);
         ppos[i]->SetBinError(iaj+1,posValErr);
         pneg[i]->SetBinContent(iaj+1,negVal);
         pneg[i]->SetBinError(iaj+1,negValErr);
      }
   }
   
   TH1D *pall;
   TH1D *pallE;
   TH1D *h1 = new TH1D(Form("hAll1"),"",nBinAj,ajBins);
   TH1D *h2 = new TH1D(Form("hAll2"),"",nBinAj,ajBins);

   h1->Sumw2();
   h2->Sumw2();
   t->Draw(Form("Aj>>hAll1"), "weight"*(evtCut&&myCut));
   t->Draw(Form("Aj>>hAll2"), Form("((-weight*metxMergedAll))")*(evtCut&&myCut));
   pall=(TH1D*)h2->Clone();
   pall->SetName("pall");
   pall->Divide(h1);

   // replace the sys error from pallE to pall 
   TH1D *he[nBinAj];
   cout << "Stat Error for All pt: ";
   for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
      he[iaj] = new TH1D(Form("heAll_aj%d",iaj),"",100,-200,200);
      TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
      t->Draw(Form("((metxMergedAll))>>heAll_aj%d",iaj), "weight" * evtCut&&myCut&&ajCut);
      float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries()));
      cout << theError << " ";
      pall->SetBinError(iaj+1,  theError);
   }
   cout << endl;

   pall->SetXTitle("A_{J}");
   pall->SetYTitle("<#slash{p}_{T}^{#parallel}> (GeV/c)");
   pall->GetXaxis()->CenterTitle();
   pall->GetYaxis()->CenterTitle();
   pall->GetXaxis()->SetLabelSize(22);
   pall->GetXaxis()->SetLabelFont(43);
   pall->GetXaxis()->SetTitleSize(24);
   pall->GetXaxis()->SetTitleFont(43);
   pall->GetYaxis()->SetLabelSize(22);
   pall->GetYaxis()->SetLabelFont(43);
   pall->GetYaxis()->SetTitleSize(24);
   pall->GetYaxis()->SetTitleFont(43);
   pall->GetXaxis()->SetTitleOffset(1.8);
   pall->GetYaxis()->SetTitleOffset(2.4);
   pall->SetNdivisions(505);
   pall->SetAxisRange(-59.9,59.9,"Y");
   pall->SetMarkerSize(1);
   pall->Draw("E");
   float addSys = 0;
   if ( drawSys==1)   addSys=0; // No sys error at this moment

   // ====================
   // Finally Draw
   // ====================
   for (int i=0;i<nBin;++i) {
      ppos[i]->SetLineWidth(1);
      ppos[i]->Draw("hist same");
      pneg[i]->SetLineWidth(1);
      pneg[i]->Draw("hist same");
   }
   
   // ====================
   // Draw Statistical Error bars
   // ====================
   for (int i=0;i<nBin;++i) {
      if ( i==0 )       drawErrorShift(ppos[i],-0.016, addSys);
      if ( i==1 || i==4)       drawErrorShift(ppos[i],-0.008,addSys);
      if ( i==2 )       drawErrorShift(ppos[i],0.008,addSys);
      if ( i==3 )       drawErrorShift(ppos[i],0.016,addSys);
      if ( i==0 )       drawErrorShift(pneg[i],-0.016, addSys);
      if ( i==1 || i==4)       drawErrorShift(pneg[i],-0.008,addSys);
      if ( i==2 )       drawErrorShift(pneg[i],0.008,addSys);
      if ( i==3 )       drawErrorShift(pneg[i],0.016,addSys);
   }
   pall->Draw("E same");
   
   // ====================
   // Draw Systematic Errors
   // ====================
   if (drawSys == 1) {
      for(int i = 0; i < nBinAj; ++i){
        double x = pall->GetBinCenter(i+1);
        double y = pall->GetBinContent(i+1);
        // Quote the difference between GEN and RECO in >8 Bin (20%) before adjusting eff as systematics
        double err = fabs(pe[nBin-1]->GetBinContent(i+1)*0.2);
        DrawTick(y,err,err,x,1,0.02,1);
      }
   }

   // ====================
   // Draw Legend
   // ====================
   TLegend *leg = new TLegend(0.10,0.68,0.70,0.96);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   leg->SetTextFont(63);
   leg->SetTextSize(16);
   leg->AddEntry(pall,Form("> %.1f GeV/c",bins[0]),"pl");
   for (int i=0;i<nBin;++i) {
      if (i!=nBin-1){
         leg->AddEntry(ppos[i],Form("%.1f - %.1f GeV/c",bins[i],bins[i+1]),"f");
      } else {
         leg->AddEntry(ppos[i],Form("> %.1f GeV/c",bins[i]),"f");
      }
   }

   if (drawLegend) leg->Draw();

   TLine * l0 = new TLine(0,0,0.5,0);
   l0->SetLineStyle(2);
   l0->Draw();


   TLine * l1 = new TLine(0.0001,-10,0.0001,10);
   l1->Draw();
}
Esempio n. 9
0
void mCMSv5(){

const int nCent=11;
double npart[nCent]={381, 329, 283, 240, 204, 171, 143, 118, 86.2, 53.5, 30.5};
double cent[nCent], v44[nCent], v44Stat[nCent], v44Sys[nCent];
double cent2[nCent], v42[nCent], v42Stat[nCent], v42Sys[nCent];
double v42Overv44[nCent], v42Overv44Stat[nCent], v42Overv44Sys[nCent];
double cent3[nCent], nv44[nCent], nv44Stat[nCent], nv44Sys[nCent];
double cent4[nCent], nv42[nCent], nv42Stat[nCent], nv42Sys[nCent];
double nv42Overv44[nCent], nv42Overv44Stat[nCent], nv42Overv44Sys[nCent];
ifstream inFileV44;
inFileV44.open("v66.txt");
for(int i=0; i<nCent; i++){
inFileV44>>cent[i]; inFileV44>>v44[i]; inFileV44>>v44Stat[i]; inFileV44>>v44Sys[i];
}
ifstream inFileV42;
inFileV42.open("v62.txt");
for(int i=0; i<nCent; i++){
inFileV42>>cent[i]; inFileV42>>v42[i]; inFileV42>>v42Stat[i]; inFileV42>>v42Sys[i];
v42Overv44[i]=v42[i]/v44[i];
v42Overv44Sys[i]=v42Overv44[i]*(sqrt(v44Stat[i]*v44Stat[i]/v44[i]/v44[i] + v42Stat[i]*v42Stat[i]/v42[i]/v42[i]));
}
ifstream inFileV44n;
inFileV44n.open("newCMSv55.txt");
for(int i=0; i<nCent; i++){
inFileV44n>>cent3[i]; inFileV44n>>nv44[i]; inFileV44n>>nv44Stat[i]; 
}
ifstream inFileV42n;
inFileV42n.open("newCMSv523.txt");
for(int i=0; i<nCent; i++){
inFileV42n>>cent4[i]; inFileV42n>>nv42[i]; inFileV42n>>nv42Stat[i]; 
nv42Overv44[i]=nv42[i]/nv44[i];
nv42Overv44Sys[i]=nv42Overv44[i]*(sqrt(nv44Stat[i]*nv44Stat[i]/nv44[i]/nv44[i] + nv42Stat[i]*nv42Stat[i]/nv42[i]/nv42[i]));
}

  TCanvas *c1 = new TCanvas("c1","c1",1,1,500,500);
  c1->SetFillColor(10);
  c1->SetFrameFillColor(0);
  c1->SetFrameBorderSize(0);
  c1->SetFrameBorderMode(0);
  c1->SetLeftMargin(0.15);
  c1->SetBottomMargin(0.15);
  c1->SetTopMargin(0.02);
  c1->SetRightMargin(0.02);
  //c1->Divide(5,1,0,0);
  gStyle->SetOptStat(0);
  c1->SetTicks(-1);
c1->cd();
 TH1D* hist = new TH1D("hist","",100,0.,430);
 hist->SetXTitle("N_{part}");
 hist->SetYTitle("v_{5}{#Psi_{23}}/v_{5}{#Psi_{5}}");
 hist->SetMinimum(0);
 hist->SetMaximum(1.2);
 hist->GetXaxis()->CenterTitle(1);
 hist->GetYaxis()->CenterTitle(1);
 hist->GetYaxis()->SetTitleOffset(1.1);
 hist->GetXaxis()->SetTitleOffset(1.1);
 hist->GetXaxis()->SetTitleSize(0.055);
 hist->GetYaxis()->SetTitleSize(0.055);
 hist->GetXaxis()->SetLabelSize(0.046);
 hist->GetYaxis()->SetLabelSize(0.046);
 hist->GetXaxis()->SetLabelOffset(0.01);
 hist->GetYaxis()->SetLabelOffset(0.01);
 hist->Draw();

TGraphErrors *graph_v42Ov44 = new TGraphErrors(nCent,npart,v42Overv44,0,v42Overv44Sys);
graph_v42Ov44->SetTitle("");
graph_v42Ov44->SetMarkerSize(1.5);
graph_v42Ov44->SetMarkerColor(1);
graph_v42Ov44->SetMarkerStyle(20);
graph_v42Ov44->SetLineWidth(2);
graph_v42Ov44->SetLineStyle(1);
graph_v42Ov44->SetLineColor(1);
graph_v42Ov44->SetFillColor(1);
//graph_v42Ov44->Draw("pe");
TGraphErrors *graph_v42Ov44n = new TGraphErrors(nCent,npart,nv42Overv44,0,nv42Overv44Sys);
graph_v42Ov44n->SetTitle("");
graph_v42Ov44n->SetMarkerSize(1.5);
graph_v42Ov44n->SetMarkerColor(4);
graph_v42Ov44n->SetMarkerStyle(25);
graph_v42Ov44n->SetLineWidth(2);
graph_v42Ov44n->SetLineStyle(1);
graph_v42Ov44n->SetLineColor(4);
graph_v42Ov44n->SetFillColor(4);
//graph_v42Ov44n->Draw("pe");

//ATLAS
  // Plot: p8724_d17x1y2
  double p8724_d17x1y1_xval[] = { 400.6, 392.6, 383.2, 372.6, 361.8, 330.3, 281.9, 239.5, 202.6, 
    170.2, 141.7, 116.8, 95.0, 76.1, 59.9 };
  double p8724_d17x1y1_xerrminus[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
  double p8724_d17x1y1_xerrplus[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
  double p8724_d17x1y1_yval[] = { 0.2017, 0.2625, 0.3147, 0.3772, 0.425, 0.5601, 0.6918, 0.7679, 0.8126, 
    0.835, 0.8553, 0.8412, 0.8539, 0.8802, 0.7278 };
  double p8724_d17x1y1_yerrminus[] = { 0.023482809542301364, 0.029815615036420096, 0.034164759987449056, 0.039867220883828866, 0.04428437421935643, 0.05755706004479381, 0.07080783823843233, 0.07997933805677564, 0.08377625415951706, 
    0.08548919955760494, 0.08882806369610902, 0.08725226071569721, 0.10288193476019004, 0.09603769468286918, 0.18713500180351084 };
  double p8724_d17x1y1_yerrplus[] = { 0.023482809542301364, 0.029815615036420096, 0.034164759987449056, 0.039867220883828866, 0.04428437421935643, 0.05755706004479381, 0.07080783823843233, 0.07997933805677564, 0.08377625415951706, 
    0.08548919955760494, 0.08882806369610902, 0.08725226071569721, 0.10288193476019004, 0.09603769468286918, 0.18713500180351084 };
  double p8724_d17x1y1_ystatminus[] = { 0.005662, 0.00578, 0.005965, 0.006401, 0.00673, 0.003669, 0.004416, 0.005046, 0.005731, 
    0.006779, 0.0084, 0.01089, 0.01555, 0.02782, 0.04183 };
  double p8724_d17x1y1_ystatplus[] = { 0.005662, 0.00578, 0.005965, 0.006401, 0.00673, 0.003669, 0.004416, 0.005046, 0.005731, 
    0.006779, 0.0084, 0.01089, 0.01555, 0.02782, 0.04183 };
  int p8724_d17x1y1_numpoints = 15;
TGraphAsymmErrors *p8724_d17x1y1 = new TGraphAsymmErrors(p8724_d17x1y1_numpoints, p8724_d17x1y1_xval, p8724_d17x1y1_yval, p8724_d17x1y1_xerrminus, p8724_d17x1y1_xerrplus, p8724_d17x1y1_yerrminus, p8724_d17x1y1_yerrplus);
  //p8724_d17x1y1.SetName("/HepData/8724/d17x1y1");
  //p8724_d17x1y1.SetTitle("/HepData/8724/d17x1y1");
  p8724_d17x1y1->SetFillColor(kRed-9);
  p8724_d17x1y1->Draw("P3same");
//graph_v42Ov44->Draw("pesame");
graph_v42Ov44n->Draw("pesame");

    TLegend *leg0 = new TLegend(0.2,0.16,0.4,0.355);
    leg0->SetFillColor(10);
    leg0->SetBorderSize(0.035);
    leg0->SetTextFont(42);
    leg0->SetTextSize(0.046);
    leg0->AddEntry(p8724_d17x1y1,"ATLAS #LTcos(2#Psi_{2}+3#Psi_{3}-5#Psi_{5})#GT_{w} SP","f");
    //leg0->AddEntry(graph_v42Ov44,"CMS v_{6}{#Psi_{2}}/v_{6}{#Psi_{6}}, 11-005","pl");
    leg0->AddEntry(graph_v42Ov44n,"New CMS v_{5}{#Psi_{23}}/v_{5}{#Psi_{5}}, 2.76 TeV","pl");
    leg0->Draw();
    TLatex *tex1= new TLatex(40.5,10e-3,"Comparison");
    tex1->SetTextColor(1);
    tex1->SetTextSize(0.05);
    tex1->SetTextFont(42);
    //tex1->Draw();

c1->SaveAs("plot_v5.png");
}
Esempio n. 10
0
void dimuonLoop(float ptmin, float ptmax, float ymin, float ymax, int i)
{
  TFile *infData = new TFile(inputdata);
  TFile *infMC = new TFile(inputmc);
  TTree *ntData = (TTree*) infData->Get("ntKstar");
  TTree *ntMC = (TTree*) infMC->Get("ntKstar");

  TCanvas *c = new TCanvas(Form("c%i",i),"",600,600);
  //if (logy) c->SetLogy();
  
  TH1D* hData = new TH1D("hData","",35,0.6,1.3);
  TH1D* hMC = new TH1D("hMC","",35,0.6,1.3);

  ntData->Project("hData","tktkmass",Form("%s&&(pt>%f&&pt<%f)&&(y>%f&&y<%f)",cut.Data(),ptmin,ptmax,ymin,ymax));
  ntMC->Project("hMC","tktkmass",Form("%s&&(pt>%f&&pt<%f)&&(y>%f&&y<%f)",cut.Data(),ptmin,ptmax,ymin,ymax));

  hData->Sumw2();
  //hMC->Sumw2();

  double normData=0,normMC=0;
  normData = hData->GetEntries();
  normMC = hMC->GetEntries();
  cout<<normData<<" "<<normMC<<endl;
  
  hData->Scale(1./normData);
  hMC->Scale(1./normMC); 

  hData->Sumw2();
  //hMC->Sumw2();

  hMC->SetXTitle("tktk mass");
  hMC->SetYTitle("#Probability");
  hMC->SetTitleOffset(1.5,"Y");
  if(hData->GetMaximum()>hMC->GetMaximum()) hData->SetMaximum(hData->GetMaximum()*1.2);
  else hData->SetMaximum(hMC->GetMaximum()*1.2);

  hData->SetMarkerStyle(8);
  hData->SetStats(0);

  hMC->SetLineColor(kRed);
  hMC->SetFillStyle(3004);
  hMC->SetFillColor(kRed);
  hMC->SetLineWidth(3);
  hMC->SetStats(0);

  hMC->Draw();
  hData->Draw("same lep");

  
  TLegend *leg = new TLegend(0.11,0.75,0.50,0.9);
  leg->AddEntry(hData,"data","lep");
  leg->AddEntry(hMC,"MC","f");
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  leg->Draw("same");
  TLegend *leg1 = new TLegend(0.60,0.7,0.90,0.9);
  leg1->AddEntry((TObject*)0,Form("%s",particle.Data()),"");
  leg1->AddEntry((TObject*)0,Form("%.0f<p_{T}<%.0f GeV",ptmin,ptmax),"");
  leg1->AddEntry((TObject*)0,Form("%.1f<y_{CM}<%.1f",ymin,ymax),"");
  leg1->SetBorderSize(0);
  leg1->SetFillStyle(0);
  leg1->Draw("same");

  c->SaveAs(Form("TktkResult/Bzero_tktkmass_dataMC.pdf",i));
}
Esempio n. 11
0
File: Zlumi.C Progetto: cms-ts/Histo
void Zlumi::Loop()
{
//   In a ROOT session, you can do:
//      Root > .L Zlumi.C
//      Root > Zlumi t
//      Root > t.GetEntry(12); // Fill t data members with entry number 12
//      Root > t.Show();       // Show values of entry 12
//      Root > t.Show(16);     // Read and show values of entry 16
//      Root > t.Loop();       // Loop on all entries
//

//     This is the loop skeleton where:
//    jentry is the global entry number in the chain
//    ientry is the entry number in the current Tree
//  Note that the argument to GetEntry must be:
//    jentry for TChain::GetEntry
//    ientry for TTree::GetEntry and TBranch::GetEntry
//
//       To read only selected branches, Insert statements like:
// METHOD1:
//    fChain->SetBranchStatus("*",0);  // disable all branches
//    fChain->SetBranchStatus("branchname",1);  // activate branchname
// METHOD2: replace line
//    fChain->GetEntry(jentry);       //read all branches
//by  b_branchname->GetEntry(ientry); //read only this branch
 
 gROOT->ForceStyle();
        tdrStyle();

  if (fChain == 0) return;

int minRun=0;
int maxRun=0;
int maxLS=0;
bool forminRun=true;


//TH2I * LumiSRun = new TH2I("LumiSRun", "LS vs Run", 3000, 0., 3000., 20000, 160000., 180000.);
//TH1I * test2 = new TH1I("test2","test2", 3000,0, 3000);


Long64_t nentries = fChain->GetEntriesFast();

Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
	Long64_t ientry = LoadTree(jentry);
	if (ientry < 0) break;
	nb = fChain->GetEntry(jentry);   nbytes += nb;


	if(forminRun && (Run!=0)){minRun=Run; forminRun=false;}
	if((Run!=0) && (Run>maxRun)){maxRun=Run;}
	if((LS!=0) && (LS>maxLS)){maxLS=LS;}
	//printf("run %i ls %i \n",Run,LS);
}
cout << nentries << " nentries \n";

TH2I *LumiSRun = new TH2I("LumiSRun", "LS vs Run", maxLS, 0, maxLS, maxRun-minRun+2, minRun-1, maxRun+1);
TH1I *Runs = new TH1I("Runs","Run", maxRun-minRun+2, minRun-1, maxRun+1);
 Runs->Sumw2();
nbytes = 0; nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
	Long64_t ientry = LoadTree(jentry);
	if (ientry < 0) break;
	nb = fChain->GetEntry(jentry);   nbytes += nb;

	LumiSRun->Fill(LS,Run);
	//printf("run %i ls %i \n",Run,LS);
	Runs->Fill(Run);
	//test2->Fill(LS);
}
	printf("minRun %i maxRun %i \n",minRun,maxRun);
LumiSRun->Draw();
 for (int h=0;h<Runs->GetNbinsX();h++){
   Runs->SetBinError(h+1,sqrt(Runs->GetBinContent(h+1)) );
 }
Runs->Draw();
//test->Draw();
//test2->Draw();

TH1F *FileRuns = new TH1F("FileRuns","Run from Lumicalc", maxRun-minRun+2, minRun-1, maxRun+1);
TH1D *XsecDistro = new TH1D("XsecDistro","X sec distribution", 60, 0., 0.6);
//-------------
   const Int_t mpt = maxRun-minRun;
   int fileRun[mpt];
   double Lumi[mpt];

   int npt = 0;
   // read data file
   ifstream file;
   //file.open("./2011-run-lumi.txt");
   file.open("./LumiAeB-dav.txt");
   while (1) {

	   file >> fileRun[npt] >> Lumi[npt];
	   if ( ! file.good() ) break;
	   cout << "x = " << fileRun[npt] << " y = " << Lumi[npt] << endl;
	   
	   FileRuns->SetBinContent((fileRun[npt]-minRun+2),0.2);
	   npt++;
   }

   file.close();
   printf("found %d Runs in file \n", npt);

bool flaggg=1;
TH1D *LumiRuns = new TH1D("LumiRuns","Zyield vs Run", maxRun-minRun+2, minRun-1, maxRun+1);
 LumiRuns->Sumw2();
for(int i=0; i<npt;i++){
	for(int j=0;j<maxRun;j++){
		if(fileRun[i]==(minRun+j)){
		  cout << fileRun[i]-minRun+1 <<" "<< ((float)Runs->GetBinContent(j+1))/Lumi[i] <<" "<< Lumi[i] << " matched run \n";
		if(Lumi[i]>0.&&Runs->GetBinContent(j+2)>0.){
			LumiRuns->SetBinContent(fileRun[i]-minRun+2,(((double)Runs->GetBinContent(j+2))/Lumi[i])*1000);
			LumiRuns->SetBinError(fileRun[i]-minRun+2,((TMath::Sqrt((double)Runs->GetBinContent(j+2)))/Lumi[i])*1000);
			XsecDistro->Fill((((double)Runs->GetBinContent(j+2))/Lumi[i])*1000);
		flaggg=false;
		}
		}
		else if(fileRun[i]==(minRun+j) && (Runs->GetBinContent(j+2+1)>0. || Runs->GetBinContent(j+2-1)>0.)) cout << "Son cazzi " << fileRun[i]<<"\n";
	}
	if(flaggg) {
	//cout << " ---------------- \n";
	cout << fileRun[i] << " Run not matched! \n";
	//cout << Runs->GetBinContent(i) <<" " << Runs->GetBinContent(i+1) <<" " << Runs->GetBinContent(i+2) <<" "<< Lumi[i] << " probably not empty \n";
	//if(Lumi[i]>1.e+06) cout << "ALERT THIS ONE IS GOOD \n";
	}
	flaggg=true;
}

TCanvas * Canv = (TCanvas*)gDirectory->GetList()->FindObject("Canv");
if (Canv) delete Canv;
Canv = new TCanvas("Canv","Canv",0,0,800,600);
Canv->cd();
LumiRuns->SetXTitle("Run");
LumiRuns->SetYTitle("#sigma (nb)");
LumiRuns->SetLineColor(kBlack);
LumiRuns->Draw("E1");
Runs->SetLineColor(kRed);
//Runs->Draw("SAMES");
FileRuns->SetLineColor(kBlue);
//FileRuns->Draw("SAMES");
//LumiRuns->Draw("E1 SAMES");
Canv->Print("ratio_zlumi.eps");

TCanvas * Another = (TCanvas*)gDirectory->GetList()->FindObject("Another");
if (Another) delete Another;
Another = new TCanvas("Another","Another",0,0,800,600);
Another->cd();
XsecDistro->SetXTitle("#sigma (nb)");
XsecDistro->SetLineColor(kBlack);
XsecDistro->Draw();
Another->Print("distrib_zsigma.eps");

/*
  //-------------
  // per il momento tengo le due sezioni separate... solo per debuggare meglio...
  //-------------
   const Int_t rpt = 120000;
   int lsRun[rpt];
   float LuSec[rpt];

   npt = 0;
   // read data file
   ifstream in;
   in.open("./2011-LS.txt");
   while (1) {

	   in >> lsRun[npt] >> LuSec[npt];
	   if ( ! in.good() ) break;
	   //cout << "x = " << fileRun[npt] << " y = " << Lumi[npt] << endl;
	   npt++;
   }

   in.close();
   printf("found %d LS\n", npt);
*/
}