コード例 #1
0
ファイル: GetMultiJetCorrFunc.C プロジェクト: davidlw/RiceHIG
TH2D* GetJetCorrFunc2D_doublegaussian(int itrg, int jass)
{
                    TH2D* hcorr = (TH2D*)GetRawCorrFunc2D_ratio(itrg,jass);
                    TH2D* hcorr_clone = (TH2D*)hcorr->Clone(Form("corr_clone_itrg%d_jass%d",itrg,jass));
                    hcorr_clone->Reset();
		    for(int ietabin=1;ietabin<=hcorr->GetNbinsX();ietabin++)
		    {
                      TH1D* hcorrphi = (TH1D*)hcorr->ProjectionY(Form("corrphi_%d",ietabin),ietabin,ietabin,"e");  
                      float min = hcorrphi->GetMinimum();
                      hcorrphi->SetAxisRange(-1,1,"X");
                      float nearmax = hcorrphi->GetMaximum();
                      hcorrphi->SetAxisRange(PI-1,PI+1,"X");
                      float awaymax = hcorrphi->GetMaximum();

		      TF1* fitfunc = new TF1("fitfunc",doubleGaussian,-PI/2.,3.*PI/2.,5);		    
                      fitfunc->SetParameters(min,nearmax-min,0.3,awaymax-min,0.5);  
                      fitfunc->SetParLimits(0,0,100000);
                      fitfunc->SetParLimits(1,0,100000);
                      fitfunc->SetParLimits(2,0,100000);
                      fitfunc->SetParLimits(3,0,100000);
                      fitfunc->SetParLimits(4,0,100000);		    
		      for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit(Form("fitfunc_%d",ietabin),"RNO");                     
		      float level = fitfunc->GetParameter(0);

		      for(int iphibin=1;iphibin<=hcorr->GetNbinsY();iphibin++) 
                        hcorr_clone->SetBinContent(ietabin,iphibin,hcorr->GetBinContent(ietabin,iphibin)-level);                      
                      delete fitfunc;
		    }

                    float max = hcorr_clone->GetBinContent(hcorr_clone->GetMaximumBin());
                    hcorr_clone->SetAxisRange(ymin,max*1.3,"Z");
                    return hcorr_clone;
}
コード例 #2
0
ファイル: invertedMuonID.C プロジェクト: Bmm4/Bmm
// ----------------------------------------------------------------------
void plotRatioRaw(string era = "2016BF") {
  gStyle->SetOptStat(0);

  if (era == "all") {
    plotRatioRaw("2011");
    plotRatioRaw("2012");
    plotRatioRaw("2016BF");
    plotRatioRaw("2016GH");
    return;
  }


  double eps(0.00001);
  TH1D *hresult = new TH1D("hresult", Form("%s", era.c_str()), 80, 0., 0.4);
  hresult->GetXaxis()->SetTitle("BDT > ");
  hresult->SetMarkerStyle(24); hresult->SetLineColor(kRed+2); hresult->SetMarkerColor(kRed+2);
  TH1D *hsresult = new TH1D("hsresult", Form("%s", era.c_str()), 80, 0.+eps, 0.4+eps);
  hsresult->SetMarkerStyle(25); hsresult->SetLineColor(kBlue);  hsresult->SetMarkerColor(kBlue);

  TH1D *hbdtcut = new TH1D("hbdtcut", Form("%s", era.c_str()), 80, 0., 0.4);
  hbdtcut->SetMarkerColor(kRed+2);  hbdtcut->SetMarkerStyle(20);
  TH1D *hsbdtcut = new TH1D("hsbdtcut", Form("%s", era.c_str()), 80, 0.+eps, 0.4+eps);
  hsbdtcut->SetMarkerColor(kBlue);  hsbdtcut->SetMarkerStyle(21);

  invertedMuonIDRaw(era, 0.15, hresult, hsresult);
  invertedMuonIDRaw(era, 0.20, hresult, hsresult);
  invertedMuonIDRaw(era, 0.25, hresult, hsresult);
  invertedMuonIDRaw(era, 0.30, hresult, hsresult);
  invertedMuonIDRaw(era, -99., hbdtcut, hsbdtcut);

  c0->Clear();
  double ymax(50.);
  double smax = hresult->GetMaximum();
  double dmax = hsresult->GetMaximum();
  double themax = (smax>dmax? smax: dmax);
  if (themax < 50.)  ymax = 50.;
  if (themax < 20.)  ymax = 30.;
  if (themax < 5.)  ymax = 10.;
  if (themax < 0.5) ymax = 1.0;
  hresult->SetMinimum(-ymax);
  hresult->SetMaximum(ymax);
  hresult->Draw();
  hsresult->Draw("same");
  hbdtcut->Draw("same");
  hsbdtcut->Draw("same");
  pl->DrawLine(0., 0., 0.4, 0.);

  TLegend *tle = new TLegend(0.25, 0.2, 0.50, 0.5);
  tle->SetFillStyle(0);
  tle->SetBorderSize(0);
  tle->SetHeader(era.c_str());
  tle->AddEntry(hresult, "yield at B0", "p");
  tle->AddEntry(hsresult, "yield at Bs", "p");
  tle->Draw();

  c0->SaveAs(Form("invertedMuonIDRaw-%s-result.pdf", era.c_str()));
}
コード例 #3
0
ファイル: plotter.C プロジェクト: UHH2/MTopJet
void plotter::draw_output_pseudo(TH1* output_, TH1D* pseudotruth_, TH1D* mctruth_, bool norm, TString file_name){

  TH1* output = (TH1*) output_->Clone("output");
  TH1D* pseudotruth = (TH1D*) pseudotruth_->Clone("pseudotruth");
  TH1D* mctruth = (TH1D*) mctruth_->Clone("mctruth");

  double ymax_temp = 0;
  if(pseudotruth->GetMaximum() > ymax_temp) ymax_temp = pseudotruth->GetMaximum();
  if(mctruth->GetMaximum() > ymax_temp) ymax_temp = mctruth->GetMaximum();
  if(output->GetMaximum() > ymax_temp) ymax_temp = output->GetMaximum();
  double ymax = 1.5 * ymax_temp;


  pseudotruth->SetTitle(" ");
  pseudotruth->GetYaxis()->SetRangeUser(0., ymax);
  pseudotruth->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
  if(norm) pseudotruth->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]");
  else     pseudotruth->GetYaxis()->SetTitle("events");
  pseudotruth->GetYaxis()->SetTitleOffset(1.1);
  pseudotruth->GetXaxis()->SetTitleOffset(0.9);
  pseudotruth->GetYaxis()->SetTitleSize(0.05);
  pseudotruth->GetXaxis()->SetTitleSize(0.05);
  pseudotruth->GetYaxis()->SetNdivisions(505);

  pseudotruth->SetLineWidth(4);
  pseudotruth->SetLineColor(kRed);
  mctruth->SetLineWidth(3);
  mctruth->SetLineStyle(2);
  mctruth->SetLineColor(kBlue);

  output->SetLineColor(kBlack);
  output->SetMarkerColor(kBlack);
  output->SetMarkerStyle(8);
  output->SetMarkerSize(1);

  TCanvas *c= new TCanvas("Particle Level","",600,600);
  gPad->SetLeftMargin(0.15);
  TGaxis::SetMaxDigits(3);
  pseudotruth->Draw("HIST SAME");
  mctruth->Draw("HIST SAME");
  output->Draw("E1 SAME");
  TLegend *l;
  if(mctruth->GetSize() > 20) l=new TLegend(0.2,0.6,0.4,0.85);
  else                       l=new TLegend(0.55,0.6,0.85,0.85);
  l->SetBorderSize(0);
  l->SetFillStyle(0);
  l->AddEntry(output,"pseudo data","pl");
  l->AddEntry(pseudotruth,"pseudo data truth","pl");
  l->AddEntry(mctruth,"MC truth","pl");
  l->SetTextSize(0.04);

  l->Draw();
  gPad->RedrawAxis();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
コード例 #4
0
ファイル: n1_tree_hist.C プロジェクト: aandriat/MIT-FCCee
// Takes as input a given process with corresponding luminosity, as well as sample CME, cuts, directory location, and output file name - saves corresponding histogram in root file.
void processtree(TString sample, Double_t weight, TLorentzVector CME, TString filename, TString directory, TString param, TString cut, std::clock_t start, Int_t all){

    //Open File
    TFile *f = new TFile(directory);
    TTree *ttree = (TTree*)f->Get(sample);

    TString recohistname, paramhistname;
    if (all==0){
        recohistname = "_recoilmassHIST";
        paramhistname = "_parameterHIST";
    }
    if (all==1){
        recohistname = "_recoilmassHIST_all";
        paramhistname = "_parameterHIST_all";
    }

    TString histname = sample + recohistname;
    TH1D *recoilmassHIST   = new TH1D(histname,histname,CME.M()/2,0,CME.M());
    //recoilmassHIST->SetCanExtend(kAllAxes);
    ttree->Project(histname, "recoilmass", cut);

    histname = sample + paramhistname;
    TH1D *parameterHIST   = new TH1D(histname,histname,CME.M()/2,1,-1);
    //parameterHIST->SetCanExtend(kAllAxes);
    ttree->Project(histname, param, cut);

    //Normalize Hist
    recoilmassHIST->Scale(1/recoilmassHIST->GetMaximum());
    parameterHIST->Scale(1/parameterHIST->GetMaximum()) ;

    //Normalize Hist
//    recoilmassHIST->Scale(weight);
//    parameterHIST->Scale(weight) ;

    // Writes yield of each histogram for each cut to text file
    ofstream myfile;
    Double_t yield = recoilmassHIST->Integral(); 
    myfile.open ("yield.txt", ios::app);
        cout << "Yield for " << sample << " for Cut " << param << " is " << yield << endl;
        myfile << param << " " << all << " " << sample << " " << yield << "\n"; //write to file
    myfile.close();

    if (recoilmassHIST->Integral() == 0){
        recoilmassHIST->Fill(0);
    }
    if (parameterHIST->Integral() == 0){
        parameterHIST->Fill(0);
    }

    TFile g(filename, "update");
    recoilmassHIST->Write();
    parameterHIST->Write();
    g.Close();
}
コード例 #5
0
ファイル: plotter.C プロジェクト: UHH2/MTopJet
void plotter::draw_output_stat(TH1* output_, TH1* stat_, TH1D* truth_, bool norm, TString file_name){
  // std::vector<double> sys = get_sys_errors();
  // TH1* output_sys = add_error_bar(output, sys);

  TH1* output = (TH1*) output_->Clone("output");
  TH1* stat = (TH1*) stat_->Clone("stat");
  TH1D* truth = (TH1D*) truth_->Clone("truth");

  TCanvas *c = new TCanvas("c","",600,600);
  double ymax;
  gPad->SetLeftMargin(0.15);

  if(truth->GetMaximum() > output->GetMaximum()) ymax = 1.5 * truth->GetMaximum();
  else ymax = 1.5 * output->GetMaximum();
  TGaxis::SetMaxDigits(3);
  output->SetTitle(" ");
  output->GetYaxis()->SetRangeUser(0., ymax);
  output->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
  if(norm) output->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]");
  else output->GetYaxis()->SetTitle("events");
  output->GetYaxis()->SetTitleOffset(1.1);
  output->GetXaxis()->SetTitleOffset(0.9);
  output->GetYaxis()->SetTitleSize(0.05);
  output->GetXaxis()->SetTitleSize(0.05);
  output->GetYaxis()->SetNdivisions(505);
  output->SetLineColor(kBlack);
  output->SetMarkerColor(kBlack);
  output->SetMarkerStyle(8);
  output->SetMarkerSize(1);
  output->Draw("E1");
  stat->SetLineColor(kBlack);
  stat->SetMarkerColor(kBlack);
  stat->SetMarkerStyle(8);
  stat->SetMarkerSize(1);
  gStyle->SetEndErrorSize(5);
  truth->SetLineWidth(3);
  truth->SetLineColor(kRed);
  truth->SetLineStyle(2);
  truth->Draw("HIST SAME");
  stat->Draw("E1 SAME");
  output->Draw("E1 SAME");

  TLegend *l=new TLegend(0.5,0.65,0.85,0.85);
  l->SetBorderSize(0);
  l->SetFillStyle(0);
  l->AddEntry(output,"data unfolded","pl");
  l->AddEntry(truth,"MC particle level","pl");
  l->SetTextSize(0.04);
  l->Draw();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
コード例 #6
0
ファイル: plotter.C プロジェクト: UHH2/MTopJet
void plotter::draw_output_smear(std::vector<TH1*> output_, TH1D* truth_, TString file_name){
  // std::vector<double> sys = get_sys_errors();
  // TH1* output_sys = add_error_bar(output, sys);

  std::vector<TH1*> outputs;
  for(int i=0; i<output_.size(); i++){
    TH1* hist = (TH1*) output_[i]->Clone();
    outputs.push_back(hist);
  }
  TH1D* truth = (TH1D*) truth_->Clone("truth");

  TCanvas *c = new TCanvas("c","",600,600);
  double ymax;
  gPad->SetLeftMargin(0.15);

  if(truth->GetMaximum() > outputs[0]->GetMaximum()) ymax = 1.5 * truth->GetMaximum();
  else ymax = 1.5 * outputs[0]->GetMaximum();
  TGaxis::SetMaxDigits(3);
  for(auto output: outputs){
    output->SetTitle(" ");
    output->GetYaxis()->SetRangeUser(0., ymax);
    output->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
    output->GetYaxis()->SetTitle("events");
    output->GetYaxis()->SetTitleOffset(1.1);
    output->GetXaxis()->SetTitleOffset(0.9);
    output->GetYaxis()->SetTitleSize(0.05);
    output->GetXaxis()->SetTitleSize(0.05);
    output->GetYaxis()->SetNdivisions(505);
    output->SetLineColor(kBlack);
    output->SetMarkerColor(kBlack);
    output->SetMarkerStyle(8);
    output->SetMarkerSize(1);
    output->Draw("E1 SAME");
  }
  gStyle->SetEndErrorSize(5);
  truth->SetLineWidth(3);
  truth->SetLineColor(kRed);
  truth->SetLineStyle(2);
  truth->Draw("HIST SAME");
  TLegend *l;
  if(truth->GetSize() > 20) l=new TLegend(0.2,0.6,0.4,0.85);
  else                       l=new TLegend(0.5,0.6,0.85,0.85);
  l->SetBorderSize(0);
  l->SetFillStyle(0);
  l->AddEntry(outputs[0],"data unfolded","pl");
  l->AddEntry(truth,"MC particle level","pl");
  l->SetTextSize(0.04);
  l->Draw();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
コード例 #7
0
ファイル: makeSmearedTable.C プロジェクト: KiSooLee/TnP_B
//------------------------------------------------------------------------
void fitSlices(TH2* hCorr, TF1* func){

   int nBins = hCorr->GetNbinsX();

   TH1D* hMean = new TH1D(Form("%s_1",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());
   TH1D* hSigma = new TH1D(Form("%s_2",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());

   for(int i = 1; i < nBins+1; i++){
      int bin = nBins - i;
      TH1D* h = hCorr->ProjectionY(Form("%s_bin%d",hCorr->GetName(),bin),i,i);

      func->SetParameter(0,h->GetMaximum());
      func->SetParameter(1,h->GetMean());
      func->SetParameter(2,h->GetRMS());

      h->Fit(func,"Q");

      /*hMean->SetBinContent(i,func->GetParameter(1));
      hMean->SetBinError(i,func->GetParError(1));
      hSigma->SetBinContent(i,func->GetParameter(2));
      hSigma->SetBinError(i,func->GetParError(2));*/

      hMean->SetBinContent(i,h->GetMean());
      hMean->SetBinError(i,func->GetParError(1)); //errors are not use later for the actual table
      hSigma->SetBinContent(i,h->GetRMS());
      hSigma->SetBinError(i,func->GetParError(2));

   }
}
コード例 #8
0
ファイル: invertedMuonID.C プロジェクト: Bmm4/Bmm
// ----------------------------------------------------------------------
void plotRatio(string era = "2016BF") {
  gStyle->SetOptStat(0);

  if (era == "all") {
    plotRatio("2011");
    plotRatio("2012");
    plotRatio("2016BF");
    plotRatio("2016GH");
    return;
  }


  TH1D *hresult = new TH1D("hresult", Form("n(gauss(5.28))/n(gauss(5.37)) %s", era.c_str()), 40, 0., 0.4);
  hresult->GetXaxis()->SetTitle("BDT > ");
  TH1D *hbdtcut = new TH1D("hbdtcut", Form("n(gauss(5.28))/n(gauss(5.37)) %s", era.c_str()), 40, 0., 0.4);
  hbdtcut->SetMarkerColor(kBlue);
  invertedMuonID(era, 0.15, hresult);
  invertedMuonID(era, 0.20, hresult);
  invertedMuonID(era, 0.25, hresult);
  invertedMuonID(era, 0.30, hresult);
  invertedMuonID(era, -99., hbdtcut);

  c0->Clear();
  double ymax(50.);
  if (hresult->GetMaximum() < 5.)  ymax = 10.;
  if (hresult->GetMaximum() < 0.5) ymax = 1.0;
  hresult->SetMinimum(-ymax);
  hresult->SetMaximum(ymax);
  hresult->Draw();
  hbdtcut->Draw("same");
  pl->DrawLine(0., 0., 0.4, 0.);
  c0->SaveAs(Form("invertedMuonID-%s-result.pdf", era.c_str()));
}
コード例 #9
0
ファイル: makeTable.C プロジェクト: geonmo/cmg-cmssw
void fitSlices(TH2* hCorr, TF1* func){

   int nBins = hCorr->GetNbinsX();

   TH1D* hMean = new TH1D(Form("%s_1",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());
   TH1D* hSigma = new TH1D(Form("%s_2",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());

   for(int i = 1; i < nBins+1; ++i){
      int bin = nBins - i;
      TH1D* h = hCorr->ProjectionY(Form("%s_bin%d",hCorr->GetName(),bin),i,i);

      func->SetParameter(0,h->GetMaximum());
      func->SetParameter(1,h->GetMean());
      func->SetParameter(2,h->GetRMS());

      if(useFits) h->Fit(func);

      hMean->SetBinContent(i,func->GetParameter(1));
      hMean->SetBinError(i,func->GetParError(1));
      hSigma->SetBinContent(i,func->GetParameter(2));
      hSigma->SetBinError(i,func->GetParError(2));
      
      if(onlySaveTable){
	 h->Delete();
      }
   }
}
コード例 #10
0
ファイル: stat.C プロジェクト: radziej/findsusyb3
void loglikdistrib(Int_t ntrials = 10000, Bool_t print = kFALSE)
{
  // compute distribution of log likelihood value
  TH1D * hmc   = gStack[gPadNr][gOrder[gPadNr][0]];
  TH1D * hdata = gStack[gPadNr][gMaxProcess-1];
  Int_t nbins = hmc->GetNbinsX();
  Double_t loglik = loglikelihood(hmc, hdata, 1, nbins);
  TH1D * htest = new TH1D(*hdata);
  TH1D * lldistrib = new TH1D("lldistrib", "log(Likelihood) distribution", 
			      1000, loglik-200, loglik+200);
  setopt(lldistrib);
  for (Int_t n = 0; n < ntrials; n++) {
    // generate poisson around theorie
    for (Int_t i = 1; i <= nbins; i++) {
      htest->SetBinContent(i, gRandom->Poisson(hmc->GetBinContent(i)));
    }
    lldistrib->Fill(loglikelihood(hmc, htest, 1, nbins));
  }
  TCanvas * llcanvas = new TCanvas("llcanvas", "Log(Likelihood) distribution", 
				   40, 40, 800, 600);
  setopt(llcanvas);
  lldistrib->SetFillColor(kYellow);
  lldistrib->Draw();
  lldistrib->GetYaxis()->SetTitle("Anzahl Ereignisse");
  lldistrib->GetXaxis()->SetTitle("-ln L");
  // autozoom
  Int_t lowbin = 1;
  while (lldistrib->GetBinContent(lowbin) == 0)
    lowbin++;
  Int_t highbin = lldistrib->GetNbinsX();
  while (lldistrib->GetBinContent(highbin) == 0)
    highbin--;
  lldistrib->SetAxisRange(lldistrib->GetBinLowEdge(lowbin), 
			  lldistrib->GetBinLowEdge(highbin));
  TH1D * hworse = (TH1D *) lldistrib->Clone();
  for (Int_t nbin = 1; nbin < 501; nbin++) {
    hworse->SetBinContent(nbin, 0);
  }
  hworse->SetFillColor(95);
  hworse->Draw("same");
  Double_t pvalue = lldistrib->Integral(501,1000) / lldistrib->Integral();
  TLatex * tex = new TLatex(0.18, 0.96, Form("-ln L_{obs} = %5.2f", loglik));
  tex->SetNDC();
  tex->SetTextAlign(13);
  tex->Draw();
  tex = new TLatex(0.18, 0.86, Form("CL_{obs} = %.3f", pvalue));
  tex->SetNDC();
  tex->SetTextAlign(13);
  tex->Draw();
  TLine * l = new TLine(loglik, 0, loglik, lldistrib->GetMaximum());
  l->SetLineWidth(3);
  l->SetLineColor(kBlue);
  l->Draw();
  llcanvas->Modified();
  llcanvas->Update();
  if (print)
    llcanvas->Print("lldistrib.pdf");
  cd(gPadNr+1);
}
コード例 #11
0
ファイル: Example.C プロジェクト: losalamos/UCNB_Analyzer
void ReFit(int lo, int hi) {
	TF1* floo = (TF1*) gROOT->FindObject("floo");
	if (floo == 0) return;
	TH1D* hCe = (TH1D*) gROOT->FindObject("hCe");
	if (hCe == 0) return;
	hCe->GetXaxis()->SetRangeUser(lo,hi);
	double max = hCe->GetMaximum();
	int binmax = hCe->GetMaximumBin();
	double xmax = hCe->GetXaxis()->GetBinCenter(binmax);
	floo->SetParameters(max,xmax,10,max*0.1,50,20,5);
	hCe->Fit(floo,"Q","",lo,hi);
}
コード例 #12
0
ファイル: variables.C プロジェクト: boundino/Dntuple
void plotTurnOn(TTree* inttree, TString triggerpass, TString variable, TString varname, TString varlatex)
{
  if(varname=="vtxprob")
    {
      BIN_MIN = 0;
      BIN_MAX = 1;
    }
  else if(varname=="ffls3d")
    {
      BIN_MIN = 0;
      BIN_MAX = 50;
    }
  else if(varname=="cosalpha")
    {
      BIN_MIN = 0.9;
      BIN_MAX = 1;
    }
  TH1D* hAll = new TH1D(Form("h%s_%s_All",triggerpass.Data(),varname.Data()),Form(";%s;Probability",varlatex.Data()),BIN_NUM,BIN_MIN,BIN_MAX);
  inttree->Project(Form("h%s_%s_All",triggerpass.Data(),varname.Data()),variable,prefilter);
  TH1D* hMBseed = new TH1D(Form("h%s_%s_MBseed",triggerpass.Data(),varname.Data()),Form(";%s;Probability",varlatex.Data()),BIN_NUM,BIN_MIN,BIN_MAX);
  inttree->Project(Form("h%s_%s_MBseed",triggerpass.Data(),varname.Data()),variable,Form("%s&&%s",prefilter.Data(),triggerpass.Data()));
  //cout<<hAll->Integral()<<endl;
  hAll->Scale(1./hAll->Integral());
  hMBseed->Scale(1./hMBseed->Integral());
  hAll->SetStats(0);
  hMBseed->SetStats(0);
  hAll->SetMaximum(hMBseed->GetMaximum()*1.3);
  hAll->SetLineWidth(2);
  hAll->SetLineColor(kBlue-7);
  hAll->SetFillColor(kBlue-7);
  hAll->SetFillStyle(3001);
  hMBseed->SetLineWidth(2);
  hMBseed->SetLineColor(kRed);
  hMBseed->SetFillColor(kRed);
  hMBseed->SetFillStyle(3004);
  TCanvas* c = new TCanvas(Form("c%s_%s",triggerpass.Data(),varname.Data()),"",500,500);
  hAll->Draw();
  hMBseed->Draw("same");
  TLatex* tex = new TLatex(0.18,0.96,triggerpass);
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();
  TLegend* leg = new TLegend(0.60,0.82,0.92,0.93);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->AddEntry(hAll,"all","f");
  leg->AddEntry(hMBseed,"pass trigger","f");
  leg->Draw();
  c->SaveAs(Form("triggerturnonPlots/pthat%.0f/c%s_%s.pdf",pthat,triggerpass.Data(),varname.Data()));

}
コード例 #13
0
ファイル: Drawbbc.C プロジェクト: XuQiao/phenix
void Drawbbc(){
	TFile *f = new TFile("merged.root");
	TH1D* hbbcs;
	TH1D* hbbcn;
	TCanvas *c1;
	TCanvas *c2;
	TLegend *leg = new TLegend(0.5,0.7,0.7,0.85);
	leg->SetBorderSize(0);
	leg->SetFillColor(0);
	leg->SetTextSize(0.048);
	TH2F* bbcsbbcn = (TH2F*)f->Get(Form("bbcsbbcn_0"));
	for(int xcent=1; xcent < 6; xcent++){
		TH1F* bbcsbbcndis_t = (TH1F*)f->Get(Form("bbcsbbcn_%d",xcent));
		bbcsbbcn->Add(bbcsbbcndis_t);
	}
	hbbcs = (TH1D*)bbcsbbcn->ProjectionX("bbcs",0,-1);
	hbbcn = (TH1D*)bbcsbbcn->ProjectionY("bbcn",0,-1);
	hbbcs->Rebin(4);
	hbbcn->Rebin(4);
	c1= new TCanvas();
	c1->cd();
	c1->SetLogy();
	SetTitle(*hbbcs,"bbc charge","# of events","");
	SetRange(*hbbcs,0,1e-1,100,hbbcn->GetMaximum()*5);
	SetStyle(*hbbcs,1.2,1,20,0,0);
	SetStyle(*hbbcn,1.2,2,24,0,0);
	hbbcs->Draw("P");
	hbbcn->Draw("Psame");
	leg->AddEntry(hbbcs,"bbc south");
	leg->AddEntry(hbbcn,"bbc north");
	leg->Draw("same");
	c1->Print(Form("bbcdis.png"));
	c2= new TCanvas();
	c2->cd();
	c2->SetLogy();
	hbbcs_norm = (TH1D*)hbbcs->Clone("hbbcs_norm");
	hbbcn_norm = (TH1D*)hbbcn->Clone("hbbcn_norm");
	hbbcs_norm->Scale(1./hbbcs_norm->Integral());
	hbbcn_norm->Scale(1./hbbcn_norm->Integral());
	SetRange(*hbbcs_norm,0,1e-9,100,1);
	hbbcs_norm->Draw("P");
	hbbcn_norm->Draw("Psame");
	leg->Draw("same");
	c2->Print(Form("bbcdis_norm.png"));	
	c3= new TCanvas();
	c3->cd();
	c3->SetLogz();
	SetTitle(*bbcsbbcn,"bbc charge south","bbc charge north","# of events");
	SetRange(*bbcsbbcn,0,0,100,100);
	bbcsbbcn->Draw("colz");
	c3->Print("bbcsbbcn.png");
}
コード例 #14
0
ファイル: CompareBranch.cpp プロジェクト: abmorris/BsphiKK
void CompareBranch(string MCfilename, string CDfilename, string MCbranchname, string CDbranchname, string xtitle, string unit, string plotname, string MCcuts, string CDcuts, string MCweight, string CDweight, double xlow, double xup, int nbins)
{
  TH1D*  MChist = MakeBranchPlot(MCfilename,MCbranchname,MCcuts,MCweight,xlow,xup,nbins);
  TH1D*  CDhist = MakeBranchPlot(CDfilename,CDbranchname,CDcuts,CDweight,xlow,xup,nbins);
  MChist->Scale(1./MChist->Integral());
  CDhist->Scale(1./CDhist->Integral());
  MChist->SetDrawOption("B");
  MChist->SetFillColor(kOrange);
  MChist->SetLineColor(kOrange);
  MChist->SetMaximum(MChist->GetMaximum()*1.3);
  MChist->SetMinimum(0);
  // Draw everything
  plotmaker plotter(MChist);
  plotter.SetTitle(xtitle, unit);
  TCanvas* plot = plotter.Draw();
  CDhist->Draw("sameE1");
  plot->SaveAs((plotname+".pdf").c_str());
}
コード例 #15
0
ファイル: GetMultiJetCorrFunc.C プロジェクト: davidlw/RiceHIG
TH1D* GetJetCorrFunc1D_doublegaussian(int itrg, int jass)
{
                    TH1D* hcorrphi = (TH1D*)GetRawCorrFunc1D_ratio(itrg,jass);
		    TF1* fitfunc = new TF1("fitfunc",doubleGaussian,-PI/2.,3.*PI/2.,5);		    
                    fitfunc->SetParameters(hcorrphi->GetMinimum(),hcorrphi->GetMaximum()-hcorrphi->GetMinimum(),0.3,hcorrphi->GetMaximum(hcorrphi->GetMaximum())-hcorrphi->GetMinimum(),0.5);  
                    fitfunc->SetParLimits(0,0,100000);
                    fitfunc->SetParLimits(1,0,100000);
                    fitfunc->SetParLimits(2,0,100000);
                    fitfunc->SetParLimits(3,0,100000);
                    fitfunc->SetParLimits(4,0,100000);		    
		    for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit("fitfunc","RNO");                     
		    TH1D* hcorrphi_clone = (TH1D*)hcorrphi->Clone(Form("corrphi_clone_itrg%d_jass%d",itrg,jass));
		    float level = fitfunc->GetParameter(0);
		    for(int ibin=1;ibin<=hcorrphi_clone->GetNbinsX();ibin++) hcorrphi_clone->SetBinContent(ibin,hcorrphi_clone->GetBinContent(ibin)-level);
                    float max = hcorrphi_clone->GetBinContent(hcorrphi_clone->GetMaximumBin());
                    hcorrphi_clone->SetAxisRange(ymin,max*1.3,"Y");
                    delete fitfunc;
                    return hcorrphi_clone;
}
コード例 #16
0
ファイル: plotter.C プロジェクト: UHH2/MTopJet
void plotter::draw_bias(TH1* output_, TH1D* truth_, TH1* bias_, TString file_name){
  TH1D* bias = (TH1D*) bias_->Clone("bias");
  TH1D* truth = (TH1D*) truth_->Clone("truth");
  TH1D* output = (TH1D*) output_->Clone("output");

  double ymax_temp = 0;
  if(truth->GetMaximum() > ymax_temp) ymax_temp = truth->GetMaximum();
  if(bias->GetMaximum() > ymax_temp) ymax_temp = bias->GetMaximum();
  if(output->GetMaximum() > ymax_temp) ymax_temp = output->GetMaximum();
  double ymax = 1.5 * ymax_temp;

  TCanvas *c= new TCanvas("Bias Distribution","",600,600);
  TGaxis::SetMaxDigits(3);
  gPad->SetLeftMargin(0.15);
  truth->SetTitle(file_name);
  truth->GetYaxis()->SetRangeUser(0., ymax);
  truth->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
  truth->GetYaxis()->SetTitle("events");
  truth->GetYaxis()->SetTitleOffset(1.1);
  truth->GetXaxis()->SetTitleOffset(0.9);
  truth->GetYaxis()->SetTitleSize(0.05);
  truth->GetXaxis()->SetTitleSize(0.05);
  truth->GetYaxis()->SetNdivisions(505);

  truth->SetLineWidth(4);
  truth->SetLineColor(kRed);
  bias->SetLineWidth(4);
  bias->SetLineColor(kAzure+7);
  output->SetLineColor(kBlack);
  output->SetMarkerColor(kBlack);
  output->SetMarkerStyle(8);
  output->SetMarkerSize(1);

  truth->Draw("HIST SAME");
  bias->Draw("HIST SAME");
  output->Draw("E1 SAME");
  TLegend *l=new TLegend(0.55,0.6,0.85,0.85);
  l->SetBorderSize(0);
  l->SetFillStyle(0);
  l->AddEntry(output,"unfolded result","pl");
  l->AddEntry(truth,"truth","pl");
  l->AddEntry(bias,"bias distribution","pl");
  l->SetTextSize(0.04);
  l->Draw();
  gPad->RedrawAxis();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
コード例 #17
0
ファイル: plotter.C プロジェクト: UHH2/MTopJet
void plotter::draw_smearFit(TH1D* variation, TF1* fit_, TString file_name){
  TH1D* var = (TH1D*) variation->Clone();
  TF1* fit = (TF1*) fit_->Clone();
  TCanvas *c= new TCanvas("","",600,600);
  gPad->SetLeftMargin(0.15);
  double ymax = var->GetMaximum() * 1.5;
  var->GetYaxis()->SetRangeUser(0., ymax);
  var->GetXaxis()->SetTitle("bin content");
  var->GetYaxis()->SetTitle("events");
  var->GetYaxis()->SetTitleOffset(1.5);
  var->GetYaxis()->SetNdivisions(505);
  var->SetFillColor(kGray);
  var->SetLineColor(kBlack);
  var->Draw("HIST");
  fit->SetLineColor(kRed);
  fit->SetLineWidth(4);
  fit->Draw("SAME");
  gPad->RedrawAxis();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
コード例 #18
0
ファイル: fitWm.C プロジェクト: ksung25/UserCode
void fitWm(const TString  outputDir,   // output directory
           const Double_t lumi,        // integrated luminosity (/fb)
	   const Double_t nsigma=0     // vary MET corrections by n-sigmas (nsigma=0 means nominal correction)
) {
  gBenchmark->Start("fitWm");

  //--------------------------------------------------------------------------------------------------------------
  // Settings 
  //==============================================================================================================   
  
  // MET histogram binning and range
  const Int_t    NBINS   = 50;
  const Double_t METMAX  = 100;
  
  const Double_t PT_CUT  = 25;
  const Double_t ETA_CUT = 2.1;

  // file format for output plots
  const TString format("png"); 

    
  // recoil correction
  RecoilCorrector recoilCorr("../Recoil/ZmmData/fits.root");//, (!) uncomment to perform corrections to recoil from W-MC/Z-MC
                             //"../Recoil/WmpMC/fits.root",
			     //"../Recoil/WmmMC/fits.root",
			     //"../Recoil/ZmmMC/fits.root");
   
  // NNLO boson pT k-factors
  TFile nnloCorrFile("/data/blue/ksung/EWKAna/8TeV/Utils/Ratio.root");
  TH1D *hNNLOCorr = (TH1D*)nnloCorrFile.Get("RpT_B");
  
  //
  // input ntuple file names
  //
  enum { eData, eWmunu, eEWK, eAntiData, eAntiWmunu, eAntiEWK };  // data type enum
  vector<TString> fnamev;
  vector<Int_t>   typev;
  
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Wmunu/ntuples/data_select.root"); typev.push_back(eData);
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Wmunu/ntuples/wm_select.root");   typev.push_back(eWmunu);
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Wmunu/ntuples/ewk_select.root");  typev.push_back(eEWK);
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Wmunu/ntuples/top_select.root");  typev.push_back(eEWK);
  
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/AntiWmunu/ntuples/data_select.root"); typev.push_back(eAntiData);
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/AntiWmunu/ntuples/wm_select.root");   typev.push_back(eAntiWmunu);
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/AntiWmunu/ntuples/ewk_select.root");  typev.push_back(eAntiEWK);
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/AntiWmunu/ntuples/top_select.root");  typev.push_back(eAntiEWK);


  //--------------------------------------------------------------------------------------------------------------
  // Main analysis code 
  //==============================================================================================================  
  
  // Create output directory
  gSystem->mkdir(outputDir,kTRUE);
  CPlot::sOutDir = outputDir;  
  
  //
  // Declare MET histograms
  //
  TH1D *hDataMet   = new TH1D("hDataMet","",  NBINS,0,METMAX); hDataMet->Sumw2();
  TH1D *hDataMetm  = new TH1D("hDataMetm","", NBINS,0,METMAX); hDataMetm->Sumw2();  
  TH1D *hDataMetp  = new TH1D("hDataMetp","", NBINS,0,METMAX); hDataMetp->Sumw2();
  TH1D *hWmunuMet  = new TH1D("hWmunuMet","", NBINS,0,METMAX); hWmunuMet->Sumw2();
  TH1D *hWmunuMetp = new TH1D("hWmunuMetp","",NBINS,0,METMAX); hWmunuMetp->Sumw2();
  TH1D *hWmunuMetm = new TH1D("hWmunuMetm","",NBINS,0,METMAX); hWmunuMetm->Sumw2();
  TH1D *hEWKMet    = new TH1D("hEWKMet", "",  NBINS,0,METMAX); hEWKMet->Sumw2();
  TH1D *hEWKMetp   = new TH1D("hEWKMetp", "", NBINS,0,METMAX); hEWKMetp->Sumw2();
  TH1D *hEWKMetm   = new TH1D("hEWKMetm", "", NBINS,0,METMAX); hEWKMetm->Sumw2();

  TH1D *hAntiDataMet   = new TH1D("hAntiDataMet","",  NBINS,0,METMAX); hAntiDataMet->Sumw2();
  TH1D *hAntiDataMetm  = new TH1D("hAntiDataMetm","", NBINS,0,METMAX); hAntiDataMetm->Sumw2();  
  TH1D *hAntiDataMetp  = new TH1D("hAntiDataMetp","", NBINS,0,METMAX); hAntiDataMetp->Sumw2();
  TH1D *hAntiWmunuMet  = new TH1D("hAntiWmunuMet","", NBINS,0,METMAX); hAntiWmunuMet->Sumw2();
  TH1D *hAntiWmunuMetp = new TH1D("hAntiWmunuMetp","",NBINS,0,METMAX); hAntiWmunuMetp->Sumw2();
  TH1D *hAntiWmunuMetm = new TH1D("hAntiWmunuMetm","",NBINS,0,METMAX); hAntiWmunuMetm->Sumw2();
  TH1D *hAntiEWKMet    = new TH1D("hAntiEWKMet", "",  NBINS,0,METMAX); hAntiEWKMet->Sumw2();
  TH1D *hAntiEWKMetp   = new TH1D("hAntiEWKMetp", "", NBINS,0,METMAX); hAntiEWKMetp->Sumw2();
  TH1D *hAntiEWKMetm   = new TH1D("hAntiEWKMetm", "", NBINS,0,METMAX); hAntiEWKMetm->Sumw2();

  //
  // Declare variables to read in ntuple
  //
  UInt_t  runNum, lumiSec, evtNum;
  UInt_t  npv, npu;
  Float_t genVPt, genVPhi;
  Float_t scale1fb;
  Float_t met, metPhi, sumEt, mt, u1, u2;
  Int_t   q;
  LorentzVector *lep=0;
  Float_t pfChIso, pfGamIso, pfNeuIso;
    
  TFile *infile=0;
  TTree *intree=0;

  //
  // Loop over files
  //
  for(UInt_t ifile=0; ifile<fnamev.size(); ifile++) {
    
    // Read input file and get the TTrees
    cout << "Processing " << fnamev[ifile] << "..." << endl;
    infile = new TFile(fnamev[ifile]);	  assert(infile);
    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("npv",      &npv);       // number of primary vertices
    intree->SetBranchAddress("npu",      &npu);       // number of in-time PU events (MC)
    intree->SetBranchAddress("genVPt",   &genVPt);    // GEN W boson pT (signal MC)
    intree->SetBranchAddress("genVPhi",  &genVPhi);   // GEN W boson phi (signal MC)   
    intree->SetBranchAddress("scale1fb", &scale1fb);  // event weight per 1/fb (MC)
    intree->SetBranchAddress("met",      &met);       // MET
    intree->SetBranchAddress("metPhi",   &metPhi);    // phi(MET)
    intree->SetBranchAddress("sumEt",    &sumEt);     // Sum ET
    intree->SetBranchAddress("mt",       &mt);        // transverse mass
    intree->SetBranchAddress("u1",       &u1);        // parallel component of recoil
    intree->SetBranchAddress("u2",       &u2);        // perpendicular component of recoil
    intree->SetBranchAddress("q",        &q);	      // lepton charge
    intree->SetBranchAddress("lep",      &lep);       // lepton 4-vector
    intree->SetBranchAddress("pfChIso",  &pfChIso);
    intree->SetBranchAddress("pfGamIso", &pfGamIso);
    intree->SetBranchAddress("pfNeuIso", &pfNeuIso);
  
    //
    // loop over events
    //
    for(UInt_t ientry=0; ientry<intree->GetEntries(); ientry++) {
      intree->GetEntry(ientry);
      
      if(lep->Pt()        < PT_CUT)  continue;	
      if(fabs(lep->Eta()) > ETA_CUT) continue;
      
      if( (typev[ifile]==eAntiData || typev[ifile]==eAntiWmunu || typev[ifile]==eAntiEWK) &&
          (pfChIso+pfGamIso+pfNeuIso)>0.5*(lep->Pt()) ) 
	  continue;
      
      if(typev[ifile]==eData) {
        hDataMet->Fill(met);
	if(q>0) { hDataMetp->Fill(met); } 
	else    { hDataMetm->Fill(met); }
      
      } else if(typev[ifile]==eAntiData) {
        hAntiDataMet->Fill(met);
	if(q>0) { hAntiDataMetp->Fill(met); } 
	else    { hAntiDataMetm->Fill(met); }      
      
      } else {
        Double_t weight = 1;
        weight *= scale1fb*lumi;
	
	if(typev[ifile]==eWmunu) {
          Double_t corrMet=met, corrMetPhi=metPhi;
        
	  // apply recoil corrections to W MC
	  Double_t lepPt = lep->Pt();
	  //Double_t lepPt = gRandom->Gaus(lep->Pt(),0.5);  // (!) uncomment to apply scale/res corrections to MC
	  recoilCorr.Correct(corrMet,corrMetPhi,genVPt,genVPhi,lepPt,lep->Phi(),nsigma,q);
	
          Double_t nnlocorr=1;
          for(Int_t ibin=1; ibin<=hNNLOCorr->GetNbinsX(); ibin++) {
            if(genVPt >= hNNLOCorr->GetBinLowEdge(ibin) &&
               genVPt < (hNNLOCorr->GetBinLowEdge(ibin)+hNNLOCorr->GetBinWidth(ibin)))
              nnlocorr = hNNLOCorr->GetBinContent(ibin);
          }
	  //weight *= nnlocorr;  // (!) uncomment to apply NNLO corrections
	  
          hWmunuMet->Fill(corrMet,weight);
	  if(q>0) { hWmunuMetp->Fill(corrMet,weight); } 
	  else    { hWmunuMetm->Fill(corrMet,weight); }
        }
	if(typev[ifile]==eAntiWmunu) {
          Double_t corrMet=met, corrMetPhi=metPhi;
        
	  // apply recoil corrections to W MC
	  Double_t lepPt = lep->Pt();//gRandom->Gaus(lep->Pt(),0.5);
	  //Double_t lepPt = gRandom->Gaus(lep->Pt(),0.5);  // (!) uncomment to apply scale/res corrections to MC
	  recoilCorr.Correct(corrMet,corrMetPhi,genVPt,genVPhi,lepPt,lep->Phi(),nsigma,q);
          
	  Double_t nnlocorr=1;
          for(Int_t ibin=1; ibin<=hNNLOCorr->GetNbinsX(); ibin++) {
            if(genVPt >= hNNLOCorr->GetBinLowEdge(ibin) &&
               genVPt < (hNNLOCorr->GetBinLowEdge(ibin)+hNNLOCorr->GetBinWidth(ibin)))
              nnlocorr = hNNLOCorr->GetBinContent(ibin);
          }
	  //weight *= nnlocorr;  // (!) uncomment to apply NNLO corrections
          
	  hAntiWmunuMet->Fill(corrMet,weight);
	  if(q>0) { hAntiWmunuMetp->Fill(corrMet,weight); } 
	  else    { hAntiWmunuMetm->Fill(corrMet,weight); }
        }
        if(typev[ifile]==eEWK) {
          hEWKMet->Fill(met,weight);
	  if(q>0) { hEWKMetp->Fill(met,weight); }
	  else    { hEWKMetm->Fill(met,weight); }
        }
        if(typev[ifile]==eAntiEWK) {
          hAntiEWKMet->Fill(met,weight);
	  if(q>0) { hAntiEWKMetp->Fill(met,weight); }
	  else    { hAntiEWKMetm->Fill(met,weight); }
        }
      }
    }
  }  
  delete infile;
  infile=0, intree=0;   
  
  //
  // Declare fit parameters for signal and background yields
  // Note: W signal and EWK+top PDFs are constrained to the ratio described in MC
  //
  RooRealVar nSig("nSig","nSig",0.7*(hDataMet->Integral()),0,hDataMet->Integral());
  RooRealVar nQCD("nQCD","nQCD",0.3*(hDataMet->Integral()),0,hDataMet->Integral());
  RooRealVar cewk("cewk","cewk",0.1,0,5) ;
  cewk.setVal(hEWKMet->Integral()/hWmunuMet->Integral());
  cewk.setConstant(kTRUE);
  RooFormulaVar nEWK("nEWK","nEWK","cewk*nSig",RooArgList(nSig,cewk));
  RooRealVar nAntiSig("nAntiSig","nAntiSig",0.05*(hAntiDataMet->Integral()),0,hAntiDataMet->Integral());
  RooRealVar nAntiQCD("nAntiQCD","nAntiQCD",0.9*(hDataMet->Integral()),0,hDataMet->Integral());
  RooRealVar dewk("dewk","dewk",0.1,0,5) ;
  dewk.setVal(hAntiEWKMet->Integral()/hAntiWmunuMet->Integral());
  dewk.setConstant(kTRUE);
  RooFormulaVar nAntiEWK("nAntiEWK","nAntiEWK","dewk*nAntiSig",RooArgList(nAntiSig,dewk));
  
  RooRealVar nSigp("nSigp","nSigp",0.7*(hDataMetp->Integral()),0,hDataMetp->Integral());
  RooRealVar nQCDp("nQCDp","nQCDp",0.3*(hDataMetp->Integral()),0,hDataMetp->Integral());
  RooRealVar cewkp("cewkp","cewkp",0.1,0,5) ;
  cewkp.setVal(hEWKMetp->Integral()/hWmunuMetp->Integral());
  cewkp.setConstant(kTRUE);
  RooFormulaVar nEWKp("nEWKp","nEWKp","cewkp*nSigp",RooArgList(nSigp,cewkp));
  RooRealVar nAntiSigp("nAntiSigp","nAntiSigp",0.05*(hAntiDataMetp->Integral()),0,hAntiDataMetp->Integral());
  RooRealVar nAntiQCDp("nAntiQCDp","nAntiQCDp",0.9*(hAntiDataMetp->Integral()),0,hAntiDataMetp->Integral());
  RooRealVar dewkp("dewkp","dewkp",0.1,0,5) ;
  dewkp.setVal(hAntiEWKMetp->Integral()/hAntiWmunuMetp->Integral());
  dewkp.setConstant(kTRUE);
  RooFormulaVar nAntiEWKp("nAntiEWKp","nAntiEWKp","dewkp*nAntiSigp",RooArgList(nAntiSigp,dewkp));
  
  RooRealVar nSigm("nSigm","nSigm",0.7*(hDataMetm->Integral()),0,hDataMetm->Integral());
  RooRealVar nQCDm("nQCDm","nQCDm",0.3*(hDataMetm->Integral()),0,hDataMetm->Integral());
  RooRealVar cewkm("cewkm","cewkm",0.1,0,5) ;
  cewkm.setVal(hEWKMetm->Integral()/hWmunuMetm->Integral());
  cewkm.setConstant(kTRUE);
  RooFormulaVar nEWKm("nEWKm","nEWKm","cewkm*nSigm",RooArgList(nSigm,cewkm));  
  RooRealVar nAntiSigm("nAntiSigm","nAntiSigm",0.05*(hAntiDataMetm->Integral()),0,hAntiDataMetm->Integral());
  RooRealVar nAntiQCDm("nAntiQCDm","nAntiQCDm",0.9*(hAntiDataMetm->Integral()),0,hAntiDataMetm->Integral());
  RooRealVar dewkm("dewkm","dewkm",0.1,0,5) ;
  dewkm.setVal(hAntiEWKMetm->Integral()/hAntiWmunuMetm->Integral());
  dewkm.setConstant(kTRUE);
  RooFormulaVar nAntiEWKm("nAntiEWKm","nAntiEWKm","dewkm*nAntiSigm",RooArgList(nAntiSigm,dewkm));

  //
  // Construct PDFs for fitting
  //
  RooRealVar pfmet("pfmet","pfmet",0,METMAX);
  pfmet.setBins(NBINS);
   
  // Signal PDFs
  RooDataHist wmunuMet ("wmunuMET", "wmunuMET", RooArgSet(pfmet),hWmunuMet);  RooHistPdf pdfWm ("wm", "wm", pfmet,wmunuMet, 1);
  RooDataHist wmunuMetp("wmunuMETp","wmunuMETp",RooArgSet(pfmet),hWmunuMetp); RooHistPdf pdfWmp("wmp","wmp",pfmet,wmunuMetp,1);
  RooDataHist wmunuMetm("wmunuMETm","wmunuMETm",RooArgSet(pfmet),hWmunuMetm); RooHistPdf pdfWmm("wmm","wmm",pfmet,wmunuMetm,1); 
  
  // EWK+top PDFs
  RooDataHist ewkMet ("ewkMET", "ewkMET", RooArgSet(pfmet),hEWKMet);  RooHistPdf pdfEWK ("ewk", "ewk", pfmet,ewkMet, 1);
  RooDataHist ewkMetp("ewkMETp","ewkMETp",RooArgSet(pfmet),hEWKMetp); RooHistPdf pdfEWKp("ewkp","ewkp",pfmet,ewkMetp,1); 
  RooDataHist ewkMetm("ewkMETm","ewkMETm",RooArgSet(pfmet),hEWKMetm); RooHistPdf pdfEWKm("ewkm","ewkm",pfmet,ewkMetm,1); 
  
  // QCD Pdfs
  CPepeModel1 qcd("qcd",pfmet);
  CPepeModel1 qcdp("qcdp",pfmet);
  CPepeModel1 qcdm("qcdm",pfmet);
  
  // Signal + Background PDFs
  RooAddPdf pdfMet ("pdfMet", "pdfMet", RooArgList(pdfWm,pdfEWK,*(qcd.model)),   RooArgList(nSig,nEWK,nQCD));  
  RooAddPdf pdfMetp("pdfMetp","pdfMetp",RooArgList(pdfWmp,pdfEWKp,*(qcdp.model)),RooArgList(nSigp,nEWKp,nQCDp));
  RooAddPdf pdfMetm("pdfMetm","pdfMetm",RooArgList(pdfWmm,pdfEWKm,*(qcdm.model)),RooArgList(nSigm,nEWKm,nQCDm));
    
  
  // Anti-Signal PDFs
  RooDataHist awmunuMet ("awmunuMET", "awmunuMET", RooArgSet(pfmet),hAntiWmunuMet);  RooHistPdf apdfWm ("awm", "awm", pfmet,awmunuMet, 1);
  RooDataHist awmunuMetp("awmunuMETp","awmunuMETp",RooArgSet(pfmet),hAntiWmunuMetp); RooHistPdf apdfWmp("awmp","awmp",pfmet,awmunuMetp,1);
  RooDataHist awmunuMetm("awmunuMETm","awmunuMETm",RooArgSet(pfmet),hAntiWmunuMetm); RooHistPdf apdfWmm("awmm","awmm",pfmet,awmunuMetm,1); 
  
  // Anti-EWK+top PDFs
  RooDataHist aewkMet ("aewkMET", "aewkMET", RooArgSet(pfmet),hAntiEWKMet);  RooHistPdf apdfEWK ("aewk", "aewk", pfmet,aewkMet, 1);
  RooDataHist aewkMetp("aewkMETp","aewkMETp",RooArgSet(pfmet),hAntiEWKMetp); RooHistPdf apdfEWKp("aewkp","aewkp",pfmet,aewkMetp,1); 
  RooDataHist aewkMetm("aewkMETm","aewkMETm",RooArgSet(pfmet),hAntiEWKMetm); RooHistPdf apdfEWKm("aewkm","aewkm",pfmet,aewkMetm,1); 
  
  // Anti-QCD Pdfs
  CPepeModel1 aqcd("aqcd",pfmet,qcd.a1);
  CPepeModel1 aqcdp("aqcdp",pfmet,qcdp.a1);
  CPepeModel1 aqcdm("aqcdm",pfmet,qcdm.a1);
  
  // Anti-selection PDFs
  RooAddPdf apdfMet ("apdfMet", "apdfMet", RooArgList(apdfWm,apdfEWK,*(aqcd.model)),   RooArgList(nAntiSig,nAntiEWK,nAntiQCD));  
  RooAddPdf apdfMetp("apdfMetp","apdfMetp",RooArgList(apdfWmp,apdfEWKp,*(aqcdp.model)),RooArgList(nAntiSigp,nAntiEWKp,nAntiQCDp));
  RooAddPdf apdfMetm("apdfMetm","apdfMetm",RooArgList(apdfWmm,apdfEWKm,*(aqcdm.model)),RooArgList(nAntiSigm,nAntiEWKm,nAntiQCDm));
  
  // PDF for simultaneous fit
  RooCategory rooCat("rooCat","rooCat");
  rooCat.defineType("Select");
  rooCat.defineType("Anti");
  
  RooSimultaneous pdfTotal("pdfTotal","pdfTotal",rooCat);
  pdfTotal.addPdf(pdfMet, "Select");
  pdfTotal.addPdf(apdfMet,"Anti");
  
  RooSimultaneous pdfTotalp("pdfTotalp","pdfTotalp",rooCat);
  pdfTotalp.addPdf(pdfMetp, "Select");
  pdfTotalp.addPdf(apdfMetp,"Anti");
  
  RooSimultaneous pdfTotalm("pdfTotalm","pdfTotalm",rooCat);
  pdfTotalm.addPdf(pdfMetm, "Select");
  pdfTotalm.addPdf(apdfMetm,"Anti");
  
  //
  // Perform fits
  //

  RooDataHist dataMet("dataMet", "dataMet", RooArgSet(pfmet), hDataMet);
  RooDataHist antiMet("antiMet", "antiMet", RooArgSet(pfmet), hAntiDataMet);
  RooDataHist dataTotal("dataTotal","dataTotal", RooArgList(pfmet), Index(rooCat),
                        Import("Select", dataMet),
                        Import("Anti",   antiMet));
  RooFitResult *fitRes = pdfTotal.fitTo(dataTotal,Extended(),Minos(kTRUE),Save(kTRUE));
  
  RooDataHist dataMetp("dataMetp", "dataMetp", RooArgSet(pfmet), hDataMetp);
  RooDataHist antiMetp("antiMetp", "antiMetp", RooArgSet(pfmet), hAntiDataMetp);
  RooDataHist dataTotalp("dataTotalp","dataTotalp", RooArgList(pfmet), Index(rooCat),
                         Import("Select", dataMetp),
                         Import("Anti",   antiMetp));
  RooFitResult *fitResp = pdfTotalp.fitTo(dataTotalp,Extended(),Minos(kTRUE),Save(kTRUE));
  
  RooDataHist dataMetm("dataMetm", "dataMetm", RooArgSet(pfmet), hDataMetm);
  RooDataHist antiMetm("antiMetm", "antiMetm", RooArgSet(pfmet), hAntiDataMetm);
  RooDataHist dataTotalm("dataTotalm","dataTotalm", RooArgList(pfmet), Index(rooCat),
                         Import("Select", dataMetm),
                         Import("Anti",   antiMetm));
  RooFitResult *fitResm = pdfTotalm.fitTo(dataTotalm,Extended(),Minos(kTRUE),Save(kTRUE));
    
  //
  // Use histogram version of fitted PDFs to make ratio plots
  // (Will also use PDF histograms later for Chi^2 and KS tests)
  //
  TH1D *hPdfMet = (TH1D*)(pdfMet.createHistogram("hPdfMet", pfmet));
  hPdfMet->Scale((nSig.getVal()+nEWK.getVal()+nQCD.getVal())/hPdfMet->Integral());
  TH1D *hMetDiff = makeDiffHist(hDataMet,hPdfMet,"hMetDiff");
  hMetDiff->SetMarkerStyle(kFullCircle);
  hMetDiff->SetMarkerSize(0.9);
   
  TH1D *hPdfMetp = (TH1D*)(pdfMetp.createHistogram("hPdfMetp", pfmet));
  hPdfMetp->Scale((nSigp.getVal()+nEWKp.getVal()+nQCDp.getVal())/hPdfMetp->Integral());
  TH1D *hMetpDiff = makeDiffHist(hDataMetp,hPdfMetp,"hMetpDiff");
  hMetpDiff->SetMarkerStyle(kFullCircle);
  hMetpDiff->SetMarkerSize(0.9);
    
  TH1D *hPdfMetm = (TH1D*)(pdfMetm.createHistogram("hPdfMetm", pfmet));
  hPdfMetm->Scale((nSigm.getVal()+nEWKm.getVal()+nQCDm.getVal())/hPdfMetm->Integral());
  TH1D *hMetmDiff = makeDiffHist(hDataMetm,hPdfMetm,"hMetmDiff");
  hMetmDiff->SetMarkerStyle(kFullCircle); 
  hMetmDiff->SetMarkerSize(0.9);
   
  TH1D *hPdfAntiMet = (TH1D*)(apdfMet.createHistogram("hPdfAntiMet", pfmet));
  hPdfAntiMet->Scale((nAntiSig.getVal()+nAntiEWK.getVal()+nAntiQCD.getVal())/hPdfAntiMet->Integral());
  TH1D *hAntiMetDiff = makeDiffHist(hAntiDataMet,hPdfAntiMet,"hAntiMetDiff");
  hAntiMetDiff->SetMarkerStyle(kFullCircle);
  hAntiMetDiff->SetMarkerSize(0.9);
   
  TH1D *hPdfAntiMetp = (TH1D*)(apdfMetp.createHistogram("hPdfAntiMetp", pfmet));
  hPdfAntiMetp->Scale((nAntiSigp.getVal()+nAntiEWKp.getVal()+nAntiQCDp.getVal())/hPdfAntiMetp->Integral());
  TH1D *hAntiMetpDiff = makeDiffHist(hAntiDataMetp,hPdfAntiMetp,"hAntiMetpDiff");
  hAntiMetpDiff->SetMarkerStyle(kFullCircle);
  hAntiMetpDiff->SetMarkerSize(0.9);
    
  TH1D *hPdfAntiMetm = (TH1D*)(apdfMetm.createHistogram("hPdfAntiMetm", pfmet));
  hPdfAntiMetm->Scale((nAntiSigm.getVal()+nAntiEWKm.getVal()+nAntiQCDm.getVal())/hPdfAntiMetm->Integral());
  TH1D *hAntiMetmDiff = makeDiffHist(hAntiDataMetm,hPdfAntiMetm,"hAntiMetmDiff");
  hAntiMetmDiff->SetMarkerStyle(kFullCircle); 
  hAntiMetmDiff->SetMarkerSize(0.9);
   
  
  //--------------------------------------------------------------------------------------------------------------
  // Make plots 
  //==============================================================================================================  
  
  TCanvas *c = MakeCanvas("c","c",800,800);
  c->Divide(1,2,0,0);
  c->cd(1)->SetPad(0,0.3,1.0,1.0);
  c->cd(1)->SetTopMargin(0.1);
  c->cd(1)->SetBottomMargin(0.01);
  c->cd(1)->SetLeftMargin(0.15);  
  c->cd(1)->SetRightMargin(0.07);  
  c->cd(1)->SetTickx(1);
  c->cd(1)->SetTicky(1);  
  c->cd(2)->SetPad(0,0,1.0,0.3);
  c->cd(2)->SetTopMargin(0.05);
  c->cd(2)->SetBottomMargin(0.45);
  c->cd(2)->SetLeftMargin(0.15);
  c->cd(2)->SetRightMargin(0.07);
  c->cd(2)->SetTickx(1);
  c->cd(2)->SetTicky(1);
  gStyle->SetTitleOffset(1.100,"Y");
  TGaxis::SetMaxDigits(3);
  
  char ylabel[100];  // string buffer for y-axis label
  
  // label for lumi
  char lumitext[100];
  if(lumi<0.1) sprintf(lumitext,"%.1f pb^{-1}  at  #sqrt{s} = 8 TeV",lumi*1000.);
  else         sprintf(lumitext,"%.2f fb^{-1}  at  #sqrt{s} = 8 TeV",lumi);
  
  // plot colors
  Int_t linecolorW   = kOrange-3;
  Int_t fillcolorW   = kOrange-2;
  Int_t linecolorEWK = kOrange+10;
  Int_t fillcolorEWK = kOrange+7;
  Int_t linecolorQCD = kViolet+2;
  Int_t fillcolorQCD = kViolet-5;
  Int_t ratioColor   = kGray+2;
  
  //
  // Dummy histograms for TLegend
  // (I can't figure out how to properly pass RooFit objects...)
  //
  TH1D *hDummyData = new TH1D("hDummyData","",0,0,10);
  hDummyData->SetMarkerStyle(kFullCircle);
  hDummyData->SetMarkerSize(0.9);
  
  TH1D *hDummyW = new TH1D("hDummyW","",0,0,10);
  hDummyW->SetLineColor(linecolorW);
  hDummyW->SetFillColor(fillcolorW);
  hDummyW->SetFillStyle(1001);
  
  TH1D *hDummyEWK = new TH1D("hDummyEWK","",0,0,10);
  hDummyEWK->SetLineColor(linecolorEWK);
  hDummyEWK->SetFillColor(fillcolorEWK);
  hDummyEWK->SetFillStyle(1001);
  
  TH1D *hDummyQCD = new TH1D("hDummyQCD","",0,0,10);
  hDummyQCD->SetLineColor(linecolorQCD);
  hDummyQCD->SetFillColor(fillcolorQCD);
  hDummyQCD->SetFillStyle(1001);
   
  //
  // W MET plot
  //
  RooPlot *wmframe = pfmet.frame(Bins(NBINS)); 
  wmframe->GetYaxis()->SetNdivisions(505);
  dataMet.plotOn(wmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));
  pdfMet.plotOn(wmframe,FillColor(fillcolorW),DrawOption("F"));
  pdfMet.plotOn(wmframe,LineColor(linecolorW));
  pdfMet.plotOn(wmframe,Components(RooArgSet(pdfEWK,*(qcd.model))),FillColor(fillcolorEWK),DrawOption("F"));
  pdfMet.plotOn(wmframe,Components(RooArgSet(pdfEWK,*(qcd.model))),LineColor(linecolorEWK));
  pdfMet.plotOn(wmframe,Components(RooArgSet(*(qcd.model))),FillColor(fillcolorQCD),DrawOption("F"));
  pdfMet.plotOn(wmframe,Components(RooArgSet(*(qcd.model))),LineColor(linecolorQCD));
  pdfMet.plotOn(wmframe,Components(RooArgSet(pdfWm)),LineColor(linecolorW),LineStyle(2));
  dataMet.plotOn(wmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));  
  
  sprintf(ylabel,"Events / %.1f GeV",hDataMet->GetBinWidth(1));
  CPlot plotMet("fitmet",wmframe,"","",ylabel);
  plotMet.SetLegend(0.68,0.57,0.93,0.77);
  plotMet.GetLegend()->AddEntry(hDummyData,"data","PL");
  plotMet.GetLegend()->AddEntry(hDummyW,"W#rightarrow#mu#nu","F");
  plotMet.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F");
  plotMet.GetLegend()->AddEntry(hDummyQCD,"QCD","F");
  plotMet.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0);
  plotMet.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0);
  plotMet.SetYRange(0.1,1.1*(hDataMet->GetMaximum()));
  plotMet.Draw(c,kFALSE,format,1);

  CPlot plotMetDiff("fitmet","","#slash{E}_{T} [GeV]","#chi");
  plotMetDiff.AddHist1D(hMetDiff,"EX0",ratioColor);
  plotMetDiff.SetYRange(-8,8);
  plotMetDiff.AddLine(0, 0,METMAX, 0,kBlack,1);
  plotMetDiff.AddLine(0, 5,METMAX, 5,kBlack,3);
  plotMetDiff.AddLine(0,-5,METMAX,-5,kBlack,3);
  plotMetDiff.Draw(c,kTRUE,format,2);
  
  plotMet.SetName("fitmetlog");
  plotMet.SetLogy();
  plotMet.SetYRange(1e-3*(hDataMet->GetMaximum()),10*(hDataMet->GetMaximum()));
  plotMet.Draw(c,kTRUE,format,1);
    
  RooPlot *awmframe = pfmet.frame(Bins(NBINS));    
  antiMet.plotOn(awmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));
  apdfMet.plotOn(awmframe,FillColor(fillcolorW),DrawOption("F"));
  apdfMet.plotOn(awmframe,LineColor(linecolorW));
  apdfMet.plotOn(awmframe,Components(RooArgSet(apdfEWK,*(aqcd.model))),FillColor(fillcolorEWK),DrawOption("F"));
  apdfMet.plotOn(awmframe,Components(RooArgSet(apdfEWK,*(aqcd.model))),LineColor(linecolorEWK));
  apdfMet.plotOn(awmframe,Components(RooArgSet(*(aqcd.model))),FillColor(fillcolorQCD),DrawOption("F"));
  apdfMet.plotOn(awmframe,Components(RooArgSet(*(aqcd.model))),LineColor(linecolorQCD));
  apdfMet.plotOn(awmframe,Components(RooArgSet(apdfWm)),LineColor(linecolorW),LineStyle(2));
  antiMet.plotOn(awmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));  
  
  sprintf(ylabel,"Events / %.1f GeV",hAntiDataMet->GetBinWidth(1));
  CPlot plotAntiMet("fitantimet",awmframe,"","",ylabel);
  plotAntiMet.SetLegend(0.68,0.57,0.93,0.77);
  plotAntiMet.GetLegend()->AddEntry(hDummyData,"data","PL");
  plotAntiMet.GetLegend()->AddEntry(hDummyW,"W#rightarrow#mu#nu","F");
  plotAntiMet.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F");
  plotAntiMet.GetLegend()->AddEntry(hDummyQCD,"QCD","F");
  plotAntiMet.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0);
  plotAntiMet.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0);
  plotAntiMet.SetYRange(0.1,1.1*(hAntiDataMet->GetMaximum())); 
  plotAntiMet.Draw(c,kFALSE,format,1);

  CPlot plotAntiMetDiff("fitantimet","","#slash{E}_{T} [GeV]","#chi");
  plotAntiMetDiff.AddHist1D(hMetDiff,"EX0",ratioColor);
  plotAntiMetDiff.SetYRange(-8,8);
  plotAntiMetDiff.AddLine(0, 0,METMAX, 0,kBlack,1);
  plotAntiMetDiff.AddLine(0, 5,METMAX, 5,kBlack,3);
  plotAntiMetDiff.AddLine(0,-5,METMAX,-5,kBlack,3);
  plotAntiMetDiff.Draw(c,kTRUE,format,2);
  
  plotAntiMet.SetName("fitantimetlog");
  plotAntiMet.SetLogy();
  plotAntiMet.SetYRange(1e-3*(hAntiDataMet->GetMaximum()),10*(hAntiDataMet->GetMaximum()));
  plotAntiMet.Draw(c,kTRUE,format,1);
    
  //
  // W+ MET plot
  //
  RooPlot *wmpframe = pfmet.frame(Bins(NBINS));
  wmpframe->GetYaxis()->SetNdivisions(505);
  dataMetp.plotOn(wmpframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));
  pdfMetp.plotOn(wmpframe,FillColor(fillcolorW),DrawOption("F"));
  pdfMetp.plotOn(wmpframe,LineColor(linecolorW));
  pdfMetp.plotOn(wmpframe,Components(RooArgSet(pdfEWKp,*(qcdp.model))),FillColor(fillcolorEWK),DrawOption("F"));
  pdfMetp.plotOn(wmpframe,Components(RooArgSet(pdfEWKp,*(qcdp.model))),LineColor(linecolorEWK));
  pdfMetp.plotOn(wmpframe,Components(RooArgSet(*(qcdp.model))),FillColor(fillcolorQCD),DrawOption("F"));
  pdfMetp.plotOn(wmpframe,Components(RooArgSet(*(qcdp.model))),LineColor(linecolorQCD));
  pdfMetp.plotOn(wmpframe,Components(RooArgSet(pdfWmp)),LineColor(linecolorW),LineStyle(2));
  dataMetp.plotOn(wmpframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));  
  
  sprintf(ylabel,"Events / %.1f GeV",hDataMetp->GetBinWidth(1));
  CPlot plotMetp("fitmetp",wmpframe,"","",ylabel);
  plotMetp.SetLegend(0.68,0.57,0.93,0.77);
  plotMetp.GetLegend()->AddEntry(hDummyData,"data","PL");
  plotMetp.GetLegend()->AddEntry(hDummyW,"W^{+}#rightarrow#mu^{+}#nu","F");
  plotMetp.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F");
  plotMetp.GetLegend()->AddEntry(hDummyQCD,"QCD","F");
  plotMetp.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0);
  plotMetp.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0);
//  plotMetp.SetYRange(0.1,1.1*(hDataMetp->GetMaximum()));
plotMetp.SetYRange(0.1,4100);
  plotMetp.Draw(c,kFALSE,format,1);

  CPlot plotMetpDiff("fitmetp","","#slash{E}_{T} [GeV]","#chi");
  plotMetpDiff.AddHist1D(hMetpDiff,"EX0",ratioColor);
  plotMetpDiff.SetYRange(-8,8);
  plotMetpDiff.AddLine(0, 0,METMAX, 0,kBlack,1);
  plotMetpDiff.AddLine(0, 5,METMAX, 5,kBlack,3);
  plotMetpDiff.AddLine(0,-5,METMAX,-5,kBlack,3);
  plotMetpDiff.Draw(c,kTRUE,format,2);
  
  plotMetp.SetName("fitmetplog");
  plotMetp.SetLogy();
  plotMetp.SetYRange(1e-3*(hDataMetp->GetMaximum()),10*(hDataMetp->GetMaximum()));
  plotMetp.Draw(c,kTRUE,format,1);

  RooPlot *awmpframe = pfmet.frame(Bins(NBINS));    
  antiMetp.plotOn(awmpframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));
  apdfMetp.plotOn(awmpframe,FillColor(fillcolorW),DrawOption("F"));
  apdfMetp.plotOn(awmpframe,LineColor(linecolorW));
  apdfMetp.plotOn(awmpframe,Components(RooArgSet(apdfEWKp,*(aqcdp.model))),FillColor(fillcolorEWK),DrawOption("F"));
  apdfMetp.plotOn(awmpframe,Components(RooArgSet(apdfEWKp,*(aqcdp.model))),LineColor(linecolorEWK));
  apdfMetp.plotOn(awmpframe,Components(RooArgSet(*(aqcdp.model))),FillColor(fillcolorQCD),DrawOption("F"));
  apdfMetp.plotOn(awmpframe,Components(RooArgSet(*(aqcdp.model))),LineColor(linecolorQCD));
  apdfMetp.plotOn(awmpframe,Components(RooArgSet(apdfWmp)),LineColor(linecolorW),LineStyle(2));
  antiMetp.plotOn(awmpframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));  
  
  sprintf(ylabel,"Events / %.1f GeV",hAntiDataMetp->GetBinWidth(1));
  CPlot plotAntiMetp("fitantimetp",awmpframe,"","",ylabel);
  plotAntiMetp.SetLegend(0.68,0.57,0.93,0.77);
  plotAntiMetp.GetLegend()->AddEntry(hDummyData,"data","PL");
  plotAntiMetp.GetLegend()->AddEntry(hDummyW,"W^{+}#rightarrow#mu^{+}#nu","F");
  plotAntiMetp.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F");
  plotAntiMetp.GetLegend()->AddEntry(hDummyQCD,"QCD","F");
  plotAntiMetp.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0);
  plotAntiMetp.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0);
//  plotAntiMetp.SetYRange(0.1,1.1*(hAntiDataMetp->GetMaximum()));
plotAntiMetp.SetYRange(0.1,1500);
  plotAntiMetp.Draw(c,kFALSE,format,1);

  CPlot plotAntiMetpDiff("fitantimetp","","#slash{E}_{T} [GeV]","#chi");
  plotAntiMetpDiff.AddHist1D(hAntiMetpDiff,"EX0",ratioColor);
  plotAntiMetpDiff.SetYRange(-8,8);
  plotAntiMetpDiff.AddLine(0, 0,METMAX, 0,kBlack,1);
  plotAntiMetpDiff.AddLine(0, 5,METMAX, 5,kBlack,3);
  plotAntiMetpDiff.AddLine(0,-5,METMAX,-5,kBlack,3);
  plotAntiMetpDiff.Draw(c,kTRUE,format,2);
  
  plotAntiMetp.SetName("fitantimetplog");
  plotAntiMetp.SetLogy();
  plotAntiMetp.SetYRange(1e-3*(hAntiDataMetp->GetMaximum()),10*(hAntiDataMetp->GetMaximum()));
  plotAntiMetp.Draw(c,kTRUE,format,1);
  
  //
  // W- MET plot
  //
  RooPlot *wmmframe = pfmet.frame(Bins(NBINS)); 
  wmmframe->GetYaxis()->SetNdivisions(505);
  dataMetm.plotOn(wmmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));
  pdfMetm.plotOn(wmmframe,FillColor(fillcolorW),DrawOption("F"));
  pdfMetm.plotOn(wmmframe,LineColor(linecolorW));
  pdfMetm.plotOn(wmmframe,Components(RooArgSet(pdfEWKm,*(qcdm.model))),FillColor(fillcolorEWK),DrawOption("F"));
  pdfMetm.plotOn(wmmframe,Components(RooArgSet(pdfEWKm,*(qcdm.model))),LineColor(linecolorEWK));
  pdfMetm.plotOn(wmmframe,Components(RooArgSet(*(qcdm.model))),FillColor(fillcolorQCD),DrawOption("F"));
  pdfMetm.plotOn(wmmframe,Components(RooArgSet(*(qcdm.model))),LineColor(linecolorQCD));
  pdfMetm.plotOn(wmmframe,Components(RooArgSet(pdfWmm)),LineColor(linecolorW),LineStyle(2));
  dataMetm.plotOn(wmmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));
  
  sprintf(ylabel,"Events / %.1f GeV",hDataMetm->GetBinWidth(1));
  CPlot plotMetm("fitmetm",wmmframe,"","",ylabel);
  plotMetm.SetLegend(0.68,0.57,0.93,0.77);
  plotMetm.GetLegend()->AddEntry(hDummyData,"data","PL");
  plotMetm.GetLegend()->AddEntry(hDummyW,"W^{-}#rightarrow#mu^{-}#bar{#nu}","F");
  plotMetm.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F");
  plotMetm.GetLegend()->AddEntry(hDummyQCD,"QCD","F");
  plotMetm.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0);
  plotMetm.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0);
//  plotMetm.SetYRange(0.1,1.1*(hDataMetm->GetMaximum()));
plotMetm.SetYRange(0.1,4100);
  plotMetm.Draw(c,kFALSE,format,1);

  CPlot plotMetmDiff("fitmetm","","#slash{E}_{T} [GeV]","#chi");
  plotMetmDiff.AddHist1D(hMetmDiff,"EX0",ratioColor);
  plotMetmDiff.SetYRange(-8,8);
  plotMetmDiff.AddLine(0, 0,METMAX, 0,kBlack,1);
  plotMetmDiff.AddLine(0, 5,METMAX, 5,kBlack,3);
  plotMetmDiff.AddLine(0,-5,METMAX,-5,kBlack,3);
  plotMetmDiff.Draw(c,kTRUE,format,2);
  
  plotMetm.SetName("fitmetmlog");
  plotMetm.SetLogy();
  plotMetm.SetYRange(1e-3*(hDataMetm->GetMaximum()),10*(hDataMetm->GetMaximum()));
  plotMetm.Draw(c,kTRUE,format,1);

  RooPlot *awmmframe = pfmet.frame(Bins(NBINS)); 
  antiMetm.plotOn(awmmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));
  apdfMetm.plotOn(awmmframe,FillColor(fillcolorW),DrawOption("F"));
  apdfMetm.plotOn(awmmframe,LineColor(linecolorW));
  apdfMetm.plotOn(awmmframe,Components(RooArgSet(apdfEWKm,*(aqcdm.model))),FillColor(fillcolorEWK),DrawOption("F"));
  apdfMetm.plotOn(awmmframe,Components(RooArgSet(apdfEWKm,*(aqcdm.model))),LineColor(linecolorEWK));
  apdfMetm.plotOn(awmmframe,Components(RooArgSet(*(aqcdm.model))),FillColor(fillcolorQCD),DrawOption("F"));
  apdfMetm.plotOn(awmmframe,Components(RooArgSet(*(aqcdm.model))),LineColor(linecolorQCD));
  apdfMetm.plotOn(awmmframe,Components(RooArgSet(apdfWmm)),LineColor(linecolorW),LineStyle(2));
  antiMetm.plotOn(awmmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"));
  
  sprintf(ylabel,"Events / %.1f GeV",hDataMetm->GetBinWidth(1));
  CPlot plotAntiMetm("fitantimetm",awmmframe,"","",ylabel);
  plotAntiMetm.SetLegend(0.68,0.57,0.93,0.77);
  plotAntiMetm.GetLegend()->AddEntry(hDummyData,"data","PL");
  plotAntiMetm.GetLegend()->AddEntry(hDummyW,"W^{-}#rightarrow#mu^{-}#bar{#nu}","F");
  plotAntiMetm.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F");
  plotAntiMetm.GetLegend()->AddEntry(hDummyQCD,"QCD","F");
  plotAntiMetm.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0);
  plotAntiMetm.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0);
//  plotAntiMetm.SetYRange(0.1,1.1*(hAntiDataMetm->GetMaximum()));
plotAntiMetm.SetYRange(0.1,1500);
  plotAntiMetm.Draw(c,kFALSE,format,1);

  CPlot plotAntiMetmDiff("fitantimetm","","#slash{E}_{T} [GeV]","#chi");
  plotAntiMetmDiff.AddHist1D(hAntiMetmDiff,"EX0",ratioColor);
  plotAntiMetmDiff.SetYRange(-8,8);
  plotAntiMetmDiff.AddLine(0, 0,METMAX, 0,kBlack,1);
  plotAntiMetmDiff.AddLine(0, 5,METMAX, 5,kBlack,3);
  plotAntiMetmDiff.AddLine(0,-5,METMAX,-5,kBlack,3);
  plotAntiMetmDiff.Draw(c,kTRUE,format,2);
  
  plotAntiMetm.SetName("fitantimetmlog");
  plotAntiMetm.SetLogy();
  plotAntiMetm.SetYRange(1e-3*(hAntiDataMetm->GetMaximum()),10*(hAntiDataMetm->GetMaximum()));
  plotAntiMetm.Draw(c,kTRUE,format,1);

    
  //--------------------------------------------------------------------------------------------------------------
  // Output
  //==============================================================================================================
   
  cout << "*" << endl;
  cout << "* SUMMARY" << endl;
  cout << "*--------------------------------------------------" << endl;  
  
  //
  // Write fit results
  //
  ofstream txtfile;
  char txtfname[100];    
  
  ios_base::fmtflags flags;
  
  Double_t chi2prob, chi2ndf;
  Double_t ksprob, ksprobpe;
  
  chi2prob = hDataMet->Chi2Test(hPdfMet,"PUW");
  chi2ndf  = hDataMet->Chi2Test(hPdfMet,"CHI2/NDFUW");
  ksprob   = hDataMet->KolmogorovTest(hPdfMet);
  ksprobpe = hDataMet->KolmogorovTest(hPdfMet,"DX");
  sprintf(txtfname,"%s/fitresWm.txt",CPlot::sOutDir.Data());
  txtfile.open(txtfname);
  assert(txtfile.is_open());
  
  flags = txtfile.flags();
  txtfile << setprecision(10);
  txtfile << " *** Yields *** " << endl;
  txtfile << "Selected: " << hDataMet->Integral() << endl;
  txtfile << "  Signal: " << nSig.getVal() << " +/- " << nSig.getPropagatedError(*fitRes) << endl;
  txtfile << "     QCD: " << nQCD.getVal() << " +/- " << nQCD.getPropagatedError(*fitRes) << endl;
  txtfile << "   Other: " << nEWK.getVal() << " +/- " << nEWK.getPropagatedError(*fitRes) << endl;
  txtfile << endl;
  txtfile.flags(flags);
  
  fitRes->printStream(txtfile,RooPrintable::kValue,RooPrintable::kVerbose);
  txtfile << endl;
  printCorrelations(txtfile, fitRes);
  txtfile << endl;
  printChi2AndKSResults(txtfile, chi2prob, chi2ndf, ksprob, ksprobpe);
  txtfile.close();
  
  chi2prob = hDataMetp->Chi2Test(hPdfMetp,"PUW");
  chi2ndf  = hDataMetp->Chi2Test(hPdfMetp,"CHI2/NDFUW");
  ksprob   = hDataMetp->KolmogorovTest(hPdfMetp);
  ksprobpe = hDataMetp->KolmogorovTest(hPdfMetp,"DX");  
  sprintf(txtfname,"%s/fitresWmp.txt",CPlot::sOutDir.Data());
  txtfile.open(txtfname);
  assert(txtfile.is_open());
  
  flags = txtfile.flags();
  txtfile << setprecision(10);
  txtfile << " *** Yields *** " << endl;
  txtfile << "Selected: " << hDataMetp->Integral() << endl;
  txtfile << "  Signal: " << nSigp.getVal() << " +/- " << nSigp.getPropagatedError(*fitResp) << endl;
  txtfile << "     QCD: " << nQCDp.getVal() << " +/- " << nQCDp.getPropagatedError(*fitResp) << endl;
  txtfile << "   Other: " << nEWKp.getVal() << " +/- " << nEWKp.getPropagatedError(*fitResp) << endl;
  txtfile << endl; 
  txtfile.flags(flags);
  
  fitResp->printStream(txtfile,RooPrintable::kValue,RooPrintable::kVerbose);
  txtfile << endl;
  printCorrelations(txtfile, fitResp);
  txtfile << endl;
  printChi2AndKSResults(txtfile, chi2prob, chi2ndf, ksprob, ksprobpe);
  txtfile.close();

  chi2prob = hDataMetm->Chi2Test(hPdfMetm,"PUW");
  chi2ndf  = hDataMetm->Chi2Test(hPdfMetm,"CHI2/NDFUW");
  ksprob   = hDataMetm->KolmogorovTest(hPdfMetm);
  ksprobpe = hDataMetm->KolmogorovTest(hPdfMetm,"DX");  
  sprintf(txtfname,"%s/fitresWmm.txt",CPlot::sOutDir.Data());
  txtfile.open(txtfname);
  assert(txtfile.is_open());
  
  flags = txtfile.flags();
  txtfile << setprecision(10);
  txtfile << " *** Yields *** " << endl;
  txtfile << "Selected: " << hDataMetm->Integral() << endl;
  txtfile << "  Signal: " << nSigm.getVal() << " +/- " << nSigm.getPropagatedError(*fitResm) << endl;
  txtfile << "     QCD: " << nQCDm.getVal() << " +/- " << nQCDm.getPropagatedError(*fitResm) << endl;
  txtfile << "   Other: " << nEWKm.getVal() << " +/- " << nEWKm.getPropagatedError(*fitResm) << endl;
  txtfile << endl;
  txtfile.flags(flags);
  
  fitResm->printStream(txtfile,RooPrintable::kValue,RooPrintable::kVerbose);
  txtfile << endl;
  printCorrelations(txtfile, fitResm);
  txtfile << endl;
  printChi2AndKSResults(txtfile, chi2prob, chi2ndf, ksprob, ksprobpe);
  txtfile.close();

  makeHTML(outputDir);
  
  cout << endl;
  cout << "  <> Output saved in " << outputDir << "/" << endl;    
  cout << endl;     
  
  gBenchmark->Show("fitWm");
}
コード例 #19
0
ファイル: fitLOW.C プロジェクト: carlosperezlara/FitLandaus
void fitLOW(const char *run="19020_19035",
	    int arm=0, int lyr=2, int sen=21, int mpd=0,
	    bool draw=true,
	    //int old_xfit_min=12, int old_xfit_max=82,
	    int old_xfit_min=8, int old_xfit_max=62,
	    double xfit_min=2.5, double xfit_max=18.5) {
  gStyle->SetOptFit(0);
  gStyle->SetOptStat(0);
  TString inname = Form("%s/adc/LO_ARM%d_LYR%d_S%d_M%d.root",run,arm,lyr,sen,mpd);
  TString prename = Form("HI_ARM%d_LYR%d_S%d_M%d_%d_%d",arm,lyr,sen,mpd,old_xfit_min,old_xfit_max);
  TString outname = Form("LO_ARM%d_LYR%d_S%d_M%d_%.0f_%.0f",arm,lyr,sen,mpd,xfit_min,xfit_max);
  TFile *file = new TFile( inname.Data() );
  cout << inname.Data() << endl;
  cout << prename.Data() << endl;
  cout << outname.Data() << endl;

  TF1 *fitH = GetFit(run,prename.Data(),outname.Data());
  if(!fitH) return;
  if(lda<1) return;

  // data
  TH1D *out = (TH1D*) file->Get("out");
  double ymax = out->GetMaximum();
  int entries = out->Integral(xfit_min,xfit_max);
  out->Sumw2();
  out->SetLineColor(kBlack);
  out->SetMarkerStyle(20);
  out->SetTitle("");

  // fit
  TCanvas *main = new TCanvas("main","main");
  main->SetLogy(1);
  out->Draw("HE");
  out->GetYaxis()->SetRangeUser(0.5,ymax);
  out->GetXaxis()->SetRangeUser(-4.5,50.5);

  out->Fit(fitH,"QENIML","",xfit_min,xfit_max);
  TF1 *MIPH1 = GetMIP(fitH,1,kCyan-3);
  TF1 *MIPH2 = GetMIP(fitH,2,kGreen-3);
  TF1 *MIPH3 = GetMIP(fitH,3,kOrange-3);
  TF1 *MIPH4 = GetMIP(fitH,4,kMagenta-3);

  double sLDA = fitH->GetParameter(0);
  double eLDA= fitH->GetParError(0);
  double sSGM = fitH->GetParameter(1);
  double eSGM = fitH->GetParError(1);
  double ncs = fitH->GetChisquare()/fitH->GetNDF();

  double ldalow = lda*sLDA;
  double sgmlow = sgm*sSGM;

  double eldalow = TMath::Abs(ldalow)*TMath::Sqrt( elda/lda*elda/lda + eLDA/sLDA*eLDA/sLDA );
  double esgmlow = TMath::Abs(sgmlow)*TMath::Sqrt( esgm/sgm*esgm/sgm + eSGM/sSGM*eSGM/sSGM );

  ofstream outfit;
  outfit.open( Form("%s/fit/%s.dat",run,outname.Data()) );
  outfit << sLDA << " " << eLDA << endl;
  outfit << sSGM << " " << eSGM << endl;
  outfit << ldalow << endl;
  outfit << sgmlow << endl;
  outfit << ncs << endl;
  outfit.close();

  // draw
  if(!draw) return;

  MIPH1->Draw("SAME");
  MIPH2->Draw("SAME");
  MIPH3->Draw("SAME");
  MIPH4->Draw("SAME");
  fitH->SetRange(xfit_min,xfit_max);
  fitH->Draw("SAME");
  TLatex *text = new TLatex();
  text->DrawLatex(1, TMath::Exp(1.03*TMath::Log(ymax)), inname );
  text->DrawLatex(20, TMath::Exp(0.93*TMath::Log(ymax)), Form("Entries  %d",entries) );
  text->SetTextColor(kRed-3);
  text->DrawLatex(44, TMath::Exp(0.83*TMath::Log(ymax)),  Form("#chi^{2} / NDF  %.2f",ncs) );
  text->DrawLatex(20, TMath::Exp(0.83*TMath::Log(ymax)),  Form("S_{#lambda}  %.3f #pm %.3f",sLDA,eLDA) );
  text->DrawLatex(20, TMath::Exp(0.73*TMath::Log(ymax)),  Form("S_{#sigma}  %.3f #pm %.3f",sSGM,eSGM) );
  text->SetTextColor(kBlue-3);
  text->DrawLatex(20, TMath::Exp(0.60*TMath::Log(ymax)),  Form("#lambda^{H}  %.1f #pm %.1f   #rightarrow  #lambda^{L}  %.1f #pm %.1f",lda,elda,ldalow,eldalow) );
  text->DrawLatex(20, TMath::Exp(0.50*TMath::Log(ymax)),  Form("#sigma^{H}  %.1f #pm %.1f   #rightarrow  #sigma^{L}  %.1f #pm %.1f",sgm,esgm,sgmlow,esgmlow) );
  text->SetTextColor(kBlack);
  text->SetTextSize(0.04);
  main->SaveAs( Form("%s/fiteps/%s.png",run,outname.Data()), "png" );
  return;
}
コード例 #20
0
TF1* fitDstar5prongs(TTree* nt, Double_t ptmin, Double_t ptmax)
{
  static int count5p=0;
  count5p++;
  
  TCanvas* c = new TCanvas(Form("c_5p_%d",count5p),"",600,600);
  TH1D* h = new TH1D(Form("h_5p_%d",count5p),"",60,0.140,0.160);
  TF1* f = new TF1(Form("f_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*((1-[8])*TMath::Gaus(x,[6],[7])/(sqrt(2*3.14159)*[7])+[8]*TMath::Gaus(x,[6],[9])/(sqrt(2*3.14159)*[9]))",minmass3prong,maxmass3prong);
  nt->Project(Form("h_5p_%d",count5p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata5p.Data(),triggerselection[isData].Data(),ptmin,ptmax));   
    
  f->SetLineColor(4);
  f->SetParameters(0,0,0,0,0,2e2,1.45491e-1,9e-4,0.1,8e-4);
  f->FixParameter(9,15e-4);
  f->FixParameter(6,0.145491);
  f->FixParameter(7,8e-4);
  f->SetParLimits(8,0,1);
  f->SetParLimits(5,0,100000);
  h->Fit(Form("f_5p_%d",count5p),"LL");
  h->Fit(Form("f_5p_%d",count5p),"LL");
  h->Fit(Form("f_5p_%d",count5p),"LL","",minmass3prong,maxmass3prong);
  f->ReleaseParameter(6);
  f->ReleaseParameter(7);
  f->ReleaseParameter(9);
  f->SetParLimits(6,0.144,0.147);
  f->SetParLimits(7,1e-4,9e-4);
  f->SetParLimits(9,1e-4,9e-4);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.148);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16);

  TF1* background = new TF1(Form("background_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x");
  background->SetParameter(0,f->GetParameter(0));
  background->SetParameter(1,f->GetParameter(1));
  background->SetParameter(2,f->GetParameter(2));
  background->SetParameter(3,f->GetParameter(3));
  background->SetParameter(4,f->GetParameter(4));
  background->SetLineColor(4);
  background->SetRange(minmass3prong,maxmass3prong);
  background->SetLineStyle(2);
  
  TF1* mass = new TF1(Form("fmass_5p_%d",count5p),"[0]*((1-[3])*TMath::Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+[3]*TMath::Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))");
  mass->SetParameters(f->GetParameter(5),f->GetParameter(6),f->GetParameter(7),f->GetParameter(8),f->GetParameter(9));
  mass->SetParError(0,f->GetParError(5));
  mass->SetParError(1,f->GetParError(6));
  mass->SetParError(2,f->GetParError(7));
  mass->SetParError(3,f->GetParError(8));
  mass->SetParError(4,f->GetParError(9));
  mass->SetFillColor(kOrange-3);
  mass->SetFillStyle(3002);
  mass->SetLineColor(kOrange-3);
  mass->SetLineWidth(3);
  mass->SetLineStyle(2);
    
  h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})");
  h->SetYTitle("Entries / (1/3 MeV/c^{2})");
  h->SetStats(0);
  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(0.142,0.152);	
  mass->Draw("same");
  f->Draw("same");
  
  Double_t yield = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong;
  Double_t yieldErr = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong*mass->GetParError(0)/mass->GetParameter(0);

  TLatex* tex;
  TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.20,0.79,"|y| < 1.0");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();
  tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  c->SaveAs(Form("plots/pp/DMass_%s_5prongs-%d.pdf",texData[isData].Data(),count5p));
  
  return mass;
}
コード例 #21
0
TF1* fitDstar3prongs(TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax)
{
  static int count3p=0;
  count3p++;
  
  TCanvas* c = new TCanvas(Form("c_3p_%d",count3p),"",600,600);
  TH1D* h = new TH1D(Form("h_3p_%d",count3p),"",60,0.14,0.16);
  TH1D* hMCSignal = new TH1D(Form("hMCSignal_3p_%d",count3p),"",60,0.14,0.16);
  TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_3p_%d",count3p),"",60,0.14,0.16);

  TF1* f = new TF1(Form("f_3p_%d",count3p),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*([12]*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10])+(1-[12])*Gaus(x,[1],[13])/(sqrt(2*3.14159)*[13])))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x+[11]*x*x*x*x",0.14,0.16);
  f->SetLineColor(kRed);
  nt->Project(Form("h_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata3p.Data(),triggerselection[isData].Data(),ptmin,ptmax));
  ntMC->Project(Form("hMCSignal_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23333))",weight.Data(),selmc3p.Data(),triggerselection[isData].Data(),ptmin,ptmax));
  ntMC->Project(Form("hMCSwapped_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23344))",weight.Data(),selswp3p.Data(),triggerselection[isData].Data(),ptmin,ptmax));

  f->FixParameter(7,1.);
  f->FixParameter(1,0.145491);
  f->FixParameter(2,2.e-3);
  f->FixParameter(10,5.e-4);
  f->FixParameter(13,1.e-4);
  f->FixParameter(3,0.);
  f->FixParameter(4,0.);
  f->FixParameter(5,0.);
  f->FixParameter(6,0.);
  f->FixParameter(11,0.);

  f->SetParLimits(9,0,1);
  f->SetParLimits(12,0,1);
  f->SetParLimits(0,0,1000000);
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL");
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL");
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.142,0.155);
  f->ReleaseParameter(1);
  f->ReleaseParameter(2);
  f->ReleaseParameter(10);
  f->ReleaseParameter(13);
  f->SetParLimits(1,0.144,0.147);
  if(isData==0||isData==2) f->SetParLimits(2,5.e-4,5.e-3);
  else f->SetParLimits(2,5.e-4,7.e-3);
  f->SetParLimits(10,1.e-4,2.e-3);
  if(isData==0||isData==2) f->SetParLimits(13,5.e-5,3.e-4);
  else if(ptmin>20) f->SetParLimits(13,5.e-5,4.e-4);
  else f->SetParLimits(13,5.e-5,5.e-4);
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.143,0.147);
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);

  f->FixParameter(1,f->GetParameter(1));
  f->FixParameter(2,f->GetParameter(2));
  f->FixParameter(10,f->GetParameter(10));
  f->FixParameter(13,f->GetParameter(13));
  f->FixParameter(9,f->GetParameter(9));
  f->FixParameter(12,f->GetParameter(12));
  f->FixParameter(7,0);
  f->SetParLimits(8,2.e-4,2.e-3);

  hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16);
  hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16);

  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->ReleaseParameter(5);
  f->ReleaseParameter(6);
  f->ReleaseParameter(11);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  f->ReleaseParameter(1);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);

  TF1* background = new TF1(Form("background_3p_%d",count3p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x");
  background->SetParameter(0,f->GetParameter(3));
  background->SetParameter(1,f->GetParameter(4));
  background->SetParameter(2,f->GetParameter(5));
  background->SetParameter(3,f->GetParameter(6));
  background->SetParameter(4,f->GetParameter(11));
  background->SetLineColor(4);
  background->SetLineStyle(2);
  
  TF1* mass = new TF1(Form("fmass_3p_%d",count3p),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*([6]*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])+(1-[6])*Gaus(x,[1],[7])/(sqrt(2*3.14159)*[7]))))");
  mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(12),f->GetParameter(13));
  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->SetParError(6,f->GetParError(12));
  mass->SetParError(7,f->GetParError(13));
  mass->SetFillColor(kOrange-3);
  mass->SetFillStyle(3002);
  mass->SetLineColor(kOrange-3);
  mass->SetLineWidth(3);
  mass->SetLineStyle(2);
  
  h->SetXTitle("M_{K#pi#pi}-M_{K#pi} (GeV/c^{2})");
  h->SetYTitle("Entries / (1/3 MeV/c^{2})");
  h->SetStats(0);
  h->SetAxisRange(1,h->GetMaximum()*1.3,"Y");
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  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(0.142,0.152);	
  mass->Draw("same");
  f->Draw("same");

  Double_t yield = mass->Integral(0.14,0.16)/binwidth3prong;
  Double_t yieldErr = mass->Integral(0.14,0.16)/binwidth3prong*mass->GetParError(0)/mass->GetParameter(0);

  TLatex* tex;
  TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry((TObject*)0,"D* D^{0}(K#pi)#pi",NULL);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.20,0.79,"|y| < 1.0");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();
  tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  c->SaveAs(Form("plots/pp/DMass_%s_3prongs-%d.pdf",texData[isData].Data(),count3p));
  
  return mass;
}
コード例 #22
0
ファイル: plotVariables.C プロジェクト: boundino/Dntuple
void plot(TString var, TString varlatex, TString varname, Int_t nbins, Double_t vmin, Double_t vmax)
{
  cout<<"---- Processing - "<<var<<endl;
  cout<<"  -- Fill histograms"<<endl;
  TFile* ifBkg = new TFile(infnameBkg[isChannel]);
  TTree* ntBkg = (TTree*)ifBkg->Get(texNtuple[isChannel]);
  ntBkg->AddFriend("ntHlt");
  TFile* ifSgl = new TFile(infnameSgl[isChannel]);
  TTree* ntSgl = (TTree*)ifSgl->Get(texNtuple[isChannel]);
  ntSgl->AddFriend("ntHlt");
  ntSgl->AddFriend("ntHi");

  TH1D* hBkg = new TH1D(Form("hBkg_%s",varname.Data()),"",nbins,vmin,vmax);
  TH1D* hSgl = new TH1D(Form("hSgl_%s",varname.Data()),"",nbins,vmin,vmax);

  ntBkg->Project(Form("hBkg_%s",varname.Data()),var,Form("%s&&%s",selTriggerBkg[isChannel].Data(),selBkg[isChannel].Data()));
  ntSgl->Project(Form("hSgl_%s",varname.Data()),var,TCut(weight[isChannel])*Form("%s&&%s",selTriggerSgl[isChannel].Data(),selSgl[isChannel].Data()));

  cout<<"  -- Calculate normalization"<<endl;
  Double_t normBkg=0,normSgl=0;
  //normBkg = hBkg->GetEntries();
  //normSgl = hSgl->GetEntries();
  normBkg = hBkg->Integral(vmin,vmax);
  normSgl = hSgl->Integral(vmin,vmax);
  cout<<"     normBkg: "<<normBkg<<" ;   normSgl: "<<normSgl<<endl;

  cout<<"  -- Normalize histograms"<<endl;
  hBkg->Scale(1./normBkg);
  hSgl->Scale(1./normSgl); 

  cout<<"  -- Plot"<<endl;
  hBkg->SetXTitle(varlatex);
  hBkg->SetYTitle("#Probability");
  hBkg->SetTitleOffset(1.5,"Y");
  Double_t hisMax = (hBkg->GetMaximum()>hSgl->GetMaximum())?hBkg->GetMaximum():hSgl->GetMaximum();
  hBkg->SetMaximum(hisMax*1.2);

  hBkg->SetLineColor(kBlue+1);
  hBkg->SetFillStyle(1001);
  hBkg->SetFillColor(kBlue-9);
  hBkg->SetLineWidth(3);
  hBkg->SetStats(0);

  TH1D* hSglplot = new TH1D(Form("hSglplot_%s",varname.Data()),"",nbins,vmin,vmax);
  for(int ib=0;ib<nbins;ib++) hSglplot->SetBinContent(ib+1,hSgl->GetBinContent(ib+1));
  hSglplot->SetLineColor(kRed);
  hSglplot->SetFillStyle(3004);
  hSglplot->SetFillColor(kRed);
  hSglplot->SetLineWidth(3);
  hSglplot->SetStats(0);

  TCanvas* c = new TCanvas(Form("c_%s",varname.Data()),"",600,600);
  hBkg->Draw();
  hSglplot->Draw("same");

  cout<<"  -- Plot legends"<<endl;
  TLatex* tex = new TLatex(0.18,0.935,Form("5.02TeV %s",texPP[isChannel].Data()));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.055);
  tex->Draw();
  TLatex* texp;
  texp = new TLatex(0.68,0.935,texDecay[isChannel]);
  texp->SetNDC();
  texp->SetTextFont(42);
  texp->SetTextSize(0.055);
  texp->Draw();
  TLegend* leg = new TLegend(0.56,0.70,0.86,0.86);
  leg->AddEntry(hBkg,"Background","f");
  leg->AddEntry(hSglplot,"Signal","f");
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  leg->Draw("same");

  cout<<"  -- Save plots"<<endl;
  c->SaveAs(Form("plots/%s_%s/c_%s.pdf",texPP[isChannel].Data(),texNtuple[isChannel].Data(),varname.Data()));
  cout<<endl;
}
コード例 #23
0
void MCDataComparisonProject(TString inputdata="/data/dmeson2015/DataDntuple/nt_20160112_DfinderData_pp_20160111_dPt0tkPt1_D0Dstar3p5p_DCSJSON_v2.root", TString inputmc="/afs/cern.ch/work/w/wangj/public/Dmeson/ntD_20151110_DfinderMC_20151110_EvtMatching_Pythia_D0pt15p0_Pthat15_TuneZ2_5020GeV_GENSIM_75x_1015_20151110_ppGlobaTrackingPPmenuHFlowpuv11_MBseed_twang-Pythia_1107.root", TString trgselection="((HLT_DmesonPPTrackingGlobal_Dpt15_v1&&Dpt>25&&Dpt<40)||(HLT_DmesonPPTrackingGlobal_Dpt30_v1&&Dpt>40&&Dpt<60)||(HLT_DmesonPPTrackingGlobal_Dpt50_v1&&Dpt>60))",  TString cut="Dy>-1.&&Dy<1.&&(Dtrk1highPurity&&Dtrk2highPurity)&&(DsvpvDistance/DsvpvDisErr)>3.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1Pt>1.5&&Dtrk2Pt>1.5", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))", int isMC=0, Double_t luminosity=26., int doweight=0, TString collsyst="PbPb", TString outputfile="mytest.root")
{

	//inputdata="/data/yjlee/dmeson/2015/trigger/mb.root";
	
	//inputmc="/data/wangj/MC2015/Dntuple/pp/ntD_pp_Dzero_kpi/ntD_EvtBase_20160203_Dfinder_20160201_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root";
	//inputmc="/data/wangj/MC2015/Dntuple/pp/ntD_pp_Dzero_kpi_promptNnonprompt/ntD_EvtBase_20160216_Dfinder_20160201_pp_Pythia8_promptNnonprompt_D0_dPt0tkPt0p5_pthatweight.root";
	inputmc="/data/wangj/MC2015/Dntuple/pp/ntD_pp_Dzero_kpi_promptNnonprompt/ntD_EvtBase_20160216_Dfinder_20160201_pp_Pythia8_promptNnonprompt_D0_dPt0tkPt0p5_pthatweight_skim_20160224.root";
	//skim
	//inputdata="/data/dmeson2015/DataDntuple/nt_20160112_DfinderData_pp_20160111_dPt0tkPt1_D0Dstar3p5p_DCSJSON_v2.root";
	inputdata="/data/wangj/Data2015/Dntuple/pp/nt_20160112_DfinderData_pp_20160111_dPt0tkPt1_D0Dstar3p5p_DCSJSON_v2_skim_20160224.root";
	
	trgselection="((HLT_DmesonPPTrackingGlobal_Dpt15_v1&&Dpt>15&&Dpt<40)||(HLT_DmesonPPTrackingGlobal_Dpt30_v1&&Dpt>40&&Dpt<60)||(HLT_DmesonPPTrackingGlobal_Dpt50_v1&&Dpt>60))";
	//cut="Dy>-1.&&Dy<1.&&(Dtrk1highPurity&&Dtrk2highPurity)&&(DsvpvDistance/DsvpvDisErr)>3.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1Pt>1.5&&Dtrk2Pt>1.5";
//	cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)";
//	cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)&&(Dpt)>15";
	cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)&&(Dpt)>15&&(Dpt)<40";
//	cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)&&(Dpt)>30&&(Dpt)<50";
	selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))";
	isMC=0;
	luminosity=26.31;
	doweight=1;
	collsyst="PP";
	outputfile="hPtSpectrumDzeroPP.root";

	collisionsystem=collsyst;
	seldata = Form("%s&&%s",trgselection.Data(),cut.Data());
	//seldata = Form("%s",cut.Data());
	selmc = Form("%s",cut.Data());
	
	gStyle->SetTextSize(0.05);
	gStyle->SetTextFont(42);
	gStyle->SetPadRightMargin(0.043);
	gStyle->SetPadLeftMargin(0.18);
	gStyle->SetPadTopMargin(0.1);
	gStyle->SetPadBottomMargin(0.145);
	gStyle->SetTitleX(.0f);

	if(!doweight) weight="1";
	TFile* inf = new TFile(inputdata.Data());
	TFile* infMC = new TFile(inputmc.Data());
	
	TTree* nt = (TTree*) inf->Get("ntDkpi");
	TTree* HltTree = (TTree*) inf->Get("ntHlt");
	HltTree->AddFriend(nt);
	nt->AddFriend(HltTree);
	
	TTree* ntMC = (TTree*)infMC->Get("ntDkpi");
	TTree* ntGen = (TTree*)infMC->Get("ntGen");
	TTree* ntHi = (TTree*)infMC->Get("ntHi");
	ntMC->AddFriend("ntHi");
	//TTree* MCHltTree;
	//if (collisionsystem=="PP") MCHltTree= (TTree*)infMC->Get("ntHlt");
	//else MCHltTree= (TTree*)infMC->Get("HltTree");
	//MCHltTree= (TTree*)infMC->Get("ntHlt");
	//ntGen->AddFriend(ntMC);
	//MCHltTree->AddFriend(ntMC);
	
	TCanvas *c[_varSize];
	TH1D *h1[_varSize];
	TH1D *h2[_varSize];
	TH1D *h3[_varSize];
	TH1D *h4[_varSize];
	TH1D *h11[_varSize];
	TH1D *h12[_varSize];
	TH1D *h13[_varSize];
	TH1D *h14[_varSize];
	TH1D *h21[_varSize];
	TH1D *h22[_varSize];
	TH1D *h23[_varSize];
	TH1D *hRatio[_varSize];
	TH1D *ptR =  new TH1D((myVars[_Dpt].title+"Ratio").c_str(), myVars[_Dpt].title.c_str(), myVars[_Dpt].nBin, myVars[_Dpt].xMin, myVars[_Dpt].xMax);
	int nentries = 1000000000;
//	nentries = 2000000;
	float pa0 = 1;	
	float pa1 = 0;	
	float pa2 = 0;	
	TString ptWeight = Form("%f+%f*Dpt+%f*Dpt*Dpt", pa0, pa1, pa2);
	for (int i = 0 ; i < _varSize; i++){
		printf("processing %s\n", myVars[i].var.c_str());
		ptWeight = Form("%f+%f*Dpt+%f*Dpt*Dpt", pa0, pa1, pa2);
		cout<<ptWeight<<endl;
//		if(i > _Dpt) continue;
		c[i] =  new TCanvas(("c"+myVars[i].var).c_str(),"",600,600);
		h1[i] =  new TH1D((myVars[i].title+"1").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h2[i] =  new TH1D((myVars[i].title+"2").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h3[i] =  new TH1D((myVars[i].title+"3").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h4[i] =  new TH1D((myVars[i].title+"4").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h11[i] = new TH1D((myVars[i].title+"11").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h12[i] = new TH1D((myVars[i].title+"12").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h13[i] = new TH1D((myVars[i].title+"13").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h14[i] = new TH1D((myVars[i].title+"14").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h21[i] = new TH1D((myVars[i].title+"21").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h22[i] = new TH1D((myVars[i].title+"22").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h23[i] = new TH1D((myVars[i].title+"23").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		hRatio[i] = new TH1D((myVars[i].title+"_ratio").c_str(), (myVars[i].title+"_ratio").c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
	
		ntMC->Project((myVars[i].title+"1").c_str(), myVars[i].var.c_str(), TCut(weight)*TCut(ptWeight)*(TCut((selmc+"&&"+signalRegion).Data())), "", nentries);
		ntMC->Project((myVars[i].title+"2").c_str(), myVars[i].var.c_str(), TCut(weight)*TCut(ptWeight)*(TCut((selmc+"&&"+sidebandRegion).Data())), "", nentries);
		ntMC->Project((myVars[i].title+"4").c_str(), myVars[i].var.c_str(), TCut(weight)*TCut(ptWeight)*(TCut((selmc+"&&"+signalRegion).Data())&&"(Dgen==23333)"), "", nentries);

		ntMC->Project((myVars[i].title+"11").c_str(), myVars[i].var.c_str(), TCut("pthatweight")*TCut(ptWeight)*TCut(weight)*(TCut((selmc+"&&"+signalRegion).Data())), "", nentries);
		ntMC->Project((myVars[i].title+"12").c_str(), myVars[i].var.c_str(), TCut("pthatweight")*TCut(ptWeight)*TCut(weight)*(TCut((selmc+"&&"+sidebandRegion).Data())), "", nentries);
		ntMC->Project((myVars[i].title+"14").c_str(), myVars[i].var.c_str(), TCut("pthatweight")*TCut(ptWeight)*TCut(weight)*(TCut((selmc+"&&"+signalRegion).Data())&&"(Dgen==23333)"), "", nentries);

		nt->  Project((myVars[i].title+"21").c_str(), myVars[i].var.c_str(), TCut(weight)*(TCut((seldata+"&&"+signalRegion).Data())), "", nentries);
		nt->  Project((myVars[i].title+"22").c_str(), myVars[i].var.c_str(), TCut(weight)*(TCut((seldata+"&&"+sidebandRegion).Data())), "", nentries);

		h3[i] = (TH1D*)h1[i]->Clone();
		h3[i]->Add(h2[i],-wfactor);

		h13[i] = (TH1D*)h11[i]->Clone();
		h13[i]->Add(h12[i],-wfactor);

		h23[i] = (TH1D*)h21[i]->Clone();
		h23[i]->Add(h22[i],-wfactor);

		if(i == _Dpt){
		    h23[i]->Sumw2();
		    h13[i]->Sumw2();
		    h23[i]->Scale(1/h23[i]->Integral());
		    h13[i]->Scale(1/h13[i]->Integral());
			ptR = (TH1D*)h23[i]->Clone();
			ptR->Divide(h13[i]);
			TCanvas* cptR =  new TCanvas("cptR","",600,600);
  			TF1* f = new TF1(Form("f%d",i),"[0]+[1]*x+[2]*x*x", 15, 40);
			f->SetParameter(0,ptR->GetMaximum()*0.8);
			f->SetParLimits(0,0,ptR->GetMaximum());
			f->SetParameter(1,0.1);
			f->SetParLimits(1,-10,10);
			f->SetParameter(2,0.1);
			f->SetParLimits(1,-10,10);
			ptR->Fit(Form("f%d",i),"Lq","",15, 40);
			ptR->Fit(Form("f%d",i),"Lq","",15, 40);
			f->SetLineColor(kRed);
			f->SetLineWidth(3);
			ptR->Draw("p");
			f->Draw("l same ");
			cptR->SaveAs("plotsProject/ptR.pdf");
			pa0 = f->GetParameter(0);
			pa1 = f->GetParameter(1);
			pa2 = f->GetParameter(2);
			std::cout<<f->GetParameter(0)<<endl;
			std::cout<<f->GetParameter(1)<<endl;
			std::cout<<f->GetParameter(2)<<endl;
		}
		
		overlapTH1(c[i], h14[i], h13[i], h23[i], h21[i], myVars[i].xtitle, hRatio[i]);
		c[i]->SaveAs(("plotsProject/"+myVars[i].plotName+".pdf").c_str());
	}
	TH1D *hMCMass = new TH1D("MCDmass", "MCDmass", 100, 1.7, 2);
	TH1D *hMCMassGM = new TH1D("MCDmassGM", "MCDmassGM", 100, 1.7, 2);
	TH1D *hMCMassGMW = new TH1D("MCDmassGMW", "MCDmassGMW", 100, 1.7, 2);
	TH1D *hDataMass = new TH1D("DataDmass", "DataDmass", 100, 1.7, 2);
	TH1D *hMassRatio = new TH1D("DmassRatio", "DmassRatio", 100, 1.7, 2);
	TH1D *hempty = new TH1D("empty", "empty", 100, 1.7, 2);
    ntMC->Project("MCDmassGM", "Dmass", TCut(weight)*(TCut( (selmc) .Data())&&"(Dgen==23333)"), "", nentries);
    ntMC->Project("MCDmassGMW", "Dmass", TCut("pthatweight")*TCut(weight)*(TCut( (selmc) .Data())&&"(Dgen==23333)"), "", nentries);
    ntMC->Project("MCDmass", "Dmass", TCut(weight)*(TCut( (selmc) .Data())), "", nentries);
    nt->  Project("DataDmass", "Dmass", TCut(weight)*(TCut( (seldata).Data())), "", nentries);
    TCanvas* cMass =  new TCanvas("cMass","",600,600);
    overlapTH1(cMass, hMCMassGM, hMCMassGMW, hMCMass, hDataMass, "Dmass", hMassRatio, 1);
	cMass->SaveAs("plotsProject/mass.pdf");

	
}
コード例 #24
0
ファイル: fitD.C プロジェクト: boundino/BntupleRunII
//TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, float NPpar[])
TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, TString npfit)
{
  TString tMC;
  if(isMC==1) tMC="MC";
  else tMC="Data";
  TCanvas* c = new TCanvas(Form("c_%s_%.0f",tMC.Data(),ibin),"",600,600);
  TFile* infile = new TFile(Form("%s_%s_%s_%s_%.0f.root",infname.Data(),collisionsystem.Data(),varname.Data(),tMC.Data(),ibin));
  TH1D* h = (TH1D*)infile->Get("h");                    h->SetName(Form("h_%s_%.0f",tMC.Data(),ibin));
  TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal");    hMCSignal->SetName(Form("hMCSignal_%s_%.0f",tMC.Data(),ibin));

  //TString iNP=Form("TMath::Erf((x-%f)/%f)+1", NPpar[0], NPpar[1]);
  TString iNP = npfit;
  TF1* f = new TF1(Form("f_%s_%.0f",tMC.Data(),ibin),"[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+[5]*("+iNP+")");

  f->SetParLimits(3,0,1e5);
  f->SetParLimits(4,-1000,0);
  f->SetParLimits(2,0.01,0.05);
  f->SetParLimits(8,0.01,0.05);
  f->SetParLimits(7,0,1);
  f->SetParLimits(5,0,1000);
  if(isMC) {
    f->SetParLimits(3,0,1e2);
    f->SetParLimits(4,-100,0);
  }

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

  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto);
  f->ReleaseParameter(1);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto);

  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(5);
  
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto);
  f->ReleaseParameter(1);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto);
  h->SetMarkerSize(0.8);
  h->SetMarkerStyle(20);

  TF1 *background = new TF1(Form("background_%s_%.0f",tMC.Data(),ibin),"[0]+[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 *Bkpi = new TF1(Form("fBkpi_%s_%.0f",tMC.Data(),ibin),"[0]*("+iNP+")");
  Bkpi->SetParameter(0,f->GetParameter(5));
  Bkpi->SetLineColor(kGreen+1);
  Bkpi->SetRange(minhisto,maxhisto);
  Bkpi->SetLineStyle(1);
  Bkpi->SetFillStyle(3004);
  Bkpi->SetFillColor(kGreen+1);

  TF1 *mass = new TF1(Form("fmass_%s_%.0f",tMC.Data(),ibin),"[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);

  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");
  Bkpi->Draw("same");
  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);
  
  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,"B^{+} Signal","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;

  if(ibin>0)
    {
      if(isLarger==1) tex = new TLatex(0.22,0.78,Form("%s > %.3f",vartex.Data(),varval));
      else tex = new TLatex(0.22,0.78,Form("%s < %.3f",vartex.Data(),varval));
    }
  else tex = new TLatex(0.22,0.78,Form("%s",_nominalcut.Data()));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  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();

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

  c->SaveAs(Form("plotFits/DMass_%s_%s_%s_%.0f.pdf",collisionsystem.Data(),varname.Data(),tMC.Data(),ibin));
  return mass;
}
コード例 #25
0
ファイル: plotZee.C プロジェクト: ksung25/UserCode
void plotZee(const TString  outputDir,   // output directory
             const Double_t lumi         // integrated luminosity (/fb)
) {
  gBenchmark->Start("plotZee");
  gStyle->SetTitleOffset(1.100,"Y");
  
  //--------------------------------------------------------------------------------------------------------------
  // Settings 
  //==============================================================================================================   
  
  //
  // input ntuple file names
  //
  enum { eData, eZee, eEWK };  // data type enum
  vector<TString> fnamev;
  vector<Int_t>   typev;
  
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Zee/ntuples/data_select.root"); typev.push_back(eData);
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Zee/ntuples/zee_select.root");  typev.push_back(eZee);
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Zee/ntuples/ewk_select.root");  typev.push_back(eEWK);
  fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Zee/ntuples/top_select.root");  typev.push_back(eEWK);

  //
  // Fit options
  //
  const Int_t    NBINS     = 60;
  const Double_t MASS_LOW  = 60;
  const Double_t MASS_HIGH = 120;  
  const Double_t PT_CUT    = 25;
  const Double_t ETA_CUT   = 2.5;
  
  // plot output file format
  const TString format("png");
 
   
  //--------------------------------------------------------------------------------------------------------------
  // Main analysis code 
  //==============================================================================================================  

  // event category enumeration
  enum { eEleEle2HLT=1, eEleEle1HLT, eEleEleNoSel, eEleSC };
  
  // Create output directory
  gSystem->mkdir(outputDir,kTRUE);
  CPlot::sOutDir = outputDir;  
    

  // histograms for full selection (EleEle2HLT + EleEle1HLT)
  TH1D *hData = new TH1D("hData","",NBINS,MASS_LOW,MASS_HIGH); hData->Sumw2();
  TH1D *hZee  = new TH1D("hZee", "",NBINS,MASS_LOW,MASS_HIGH); hZee->Sumw2();
  TH1D *hEWK  = new TH1D("hEWK", "",NBINS,MASS_LOW,MASS_HIGH); hEWK->Sumw2();
  TH1D *hMC   = new TH1D("hMC",  "",NBINS,MASS_LOW,MASS_HIGH); hMC->Sumw2();
    
  //
  // Declare variables to read in ntuple
  //
  UInt_t  runNum, lumiSec, evtNum;
  UInt_t  matchGen;
  UInt_t  category;
  UInt_t  npv, npu;
  Float_t genVPt, genVPhi;
  Float_t scale1fb;
  Float_t met, metPhi, sumEt, u1, u2;
  Int_t   q1, q2;
  LorentzVector *dilep=0, *lep1=0, *lep2=0;
  LorentzVector *sc1=0, *sc2=0;

  TFile *infile=0;
  TTree *intree=0;

  for(UInt_t ifile=0; ifile<fnamev.size(); ifile++) {
  
    // Read input file and get the TTrees
    cout << "Processing " << fnamev[ifile] << "..." << endl;
    infile = new TFile(fnamev[ifile]);	    assert(infile);
    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("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("genVPt",   &genVPt);     // GEN Z boson pT (signal MC)
    intree->SetBranchAddress("genVPhi",  &genVPhi);    // GEN Z boson phi (signal MC)
    intree->SetBranchAddress("scale1fb", &scale1fb);   // event weight per 1/fb (MC)
    intree->SetBranchAddress("met",      &met);	       // MET
    intree->SetBranchAddress("metPhi",   &metPhi);     // phi(MET)
    intree->SetBranchAddress("sumEt",    &sumEt);      // Sum ET
    intree->SetBranchAddress("u1",       &u1);	       // parallel component of recoil
    intree->SetBranchAddress("u2",       &u2);	       // perpendicular component of recoil
    intree->SetBranchAddress("q1",       &q1);	       // charge of tag lepton
    intree->SetBranchAddress("q2",       &q2);	       // charge of probe lepton
    intree->SetBranchAddress("dilep",    &dilep);      // dilepton 4-vector
    intree->SetBranchAddress("lep1",     &lep1);       // tag lepton 4-vector
    intree->SetBranchAddress("lep2",     &lep2);       // probe lepton 4-vector
    intree->SetBranchAddress("sc1",      &sc1);        // tag Supercluster 4-vector
    intree->SetBranchAddress("sc2",      &sc2);        // probe Supercluster 4-vector 
  
    //
    // loop over events
    //
    for(UInt_t ientry=0; ientry<intree->GetEntries(); ientry++) {
      intree->GetEntry(ientry);

      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;
   
      Float_t mass = dilep->M();
      
      Double_t weight=1;
      if(typev[ifile]!=eData) {
	weight *= scale1fb*lumi;
      }
      
      // fill Z events passing selection (EleEle2HLT + EleEle1HLT)
      if((category==eEleEle2HLT) || (category==eEleEle1HLT)) {
        if(typev[ifile]==eData) { 
	  hData->Fill(mass); 
	
	} else {
          
	  LorentzVector slep1 = (*lep1);
	  slep1 *= gRandom->Gaus(slep1.E(), getResCorr(sc1->Eta()))/slep1.E();
	  
	  LorentzVector slep2 = (*lep2);
	  slep2 *= gRandom->Gaus(slep2.E(), getResCorr(sc2->Eta()))/slep2.E();
	  
	  mass = (slep1+slep2).M();	  
	  
	  hMC->Fill(mass,weight);
	  if(typev[ifile]==eZee) { hZee->Fill(mass,weight); }
	  if(typev[ifile]==eEWK) { hEWK->Fill(mass,weight); }
	}
      }
    }
    
    delete infile;
    infile=0, intree=0;
  }

  TH1D *hZeeDiff = makeDiffHist(hData,hMC,"hZeeDiff");
  hZeeDiff->SetMarkerStyle(kFullCircle); 
  hZeeDiff->SetMarkerSize(0.9);
  

  //--------------------------------------------------------------------------------------------------------------
  // Make plots 
  //==============================================================================================================  

  char ylabel[100];     // string buffer for y-axis label
  
  // label for lumi
  char lumitext[100];
  if(lumi<0.1) sprintf(lumitext,"%.1f pb^{-1}  at  #sqrt{s} = 8 TeV",lumi*1000.);
  else         sprintf(lumitext,"%.2f fb^{-1}  at  #sqrt{s} = 8 TeV",lumi);  
  
  // plot colors
  Int_t linecolorZ   = kOrange-3;
  Int_t fillcolorZ   = kOrange-2;
  Int_t linecolorEWK = kOrange+10;
  Int_t fillcolorEWK = kOrange+7;
  Int_t ratioColor   = kGray+2;
    
  TCanvas *c = MakeCanvas("c","c",800,800);
  c->Divide(1,2,0,0);
  c->cd(1)->SetPad(0,0.3,1.0,1.0);
  c->cd(1)->SetTopMargin(0.1);
  c->cd(1)->SetBottomMargin(0.01);
  c->cd(1)->SetLeftMargin(0.15);  
  c->cd(1)->SetRightMargin(0.07);  
  c->cd(1)->SetTickx(1);
  c->cd(1)->SetTicky(1);  
  c->cd(2)->SetPad(0,0,1.0,0.3);
  c->cd(2)->SetTopMargin(0.05);
  c->cd(2)->SetBottomMargin(0.45);
  c->cd(2)->SetLeftMargin(0.15);
  c->cd(2)->SetRightMargin(0.07);
  c->cd(2)->SetTickx(1);
  c->cd(2)->SetTicky(1);
  TGaxis::SetMaxDigits(3);
  
  //
  // EleEle2HLT + EleEle1HLT categories
  //   
  sprintf(ylabel,"Events / %.1f GeV/c^{2}",hData->GetBinWidth(1));
  CPlot plotZee("zee","","",ylabel);
  plotZee.AddHist1D(hData,"data","E");
  plotZee.AddToStack(hZee,"Z#rightarrowee",fillcolorZ,linecolorZ);
  plotZee.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0);
  plotZee.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0);
  plotZee.SetYRange(0.01,1.2*(hData->GetMaximum() + sqrt(hData->GetMaximum())));
  plotZee.TransLegend(-0.35,-0.15);
  plotZee.Draw(c,kFALSE,format,1);

  CPlot plotZeeDiff("zee","","M(e^{+}e^{-}) [GeV/c^{2}]","#chi");
  plotZeeDiff.AddHist1D(hZeeDiff,"EX0",ratioColor);
  plotZeeDiff.SetYRange(-8,8);
  plotZeeDiff.AddLine(MASS_LOW, 0,MASS_HIGH, 0,kBlack,1);
  plotZeeDiff.AddLine(MASS_LOW, 5,MASS_HIGH, 5,kBlack,3);
  plotZeeDiff.AddLine(MASS_LOW,-5,MASS_HIGH,-5,kBlack,3);
  plotZeeDiff.Draw(c,kTRUE,format,2);
  
  CPlot plotZee2("zeelog","","",ylabel);
  plotZee2.AddHist1D(hData,"data","E");
  plotZee2.AddToStack(hEWK,"EWK",fillcolorEWK,linecolorEWK);
  plotZee2.AddToStack(hZee,"Z#rightarrowee",fillcolorZ,linecolorZ);
  plotZee2.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0);plotZee2.SetName("zeelog");
  plotZee2.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0);
  plotZee2.SetLogy();
  plotZee2.SetYRange(1e-4*(hData->GetMaximum()),10*(hData->GetMaximum()));
  plotZee2.TransLegend(-0.35,-0.15);
  plotZee2.Draw(c,kTRUE,format,1);

    
  //--------------------------------------------------------------------------------------------------------------
  // Output
  //==============================================================================================================
   
  cout << "*" << endl;
  cout << "* SUMMARY" << endl;
  cout << "*--------------------------------------------------" << endl;  
  cout << endl;
  
  cout << endl;
  cout << "  <> Output saved in " << outputDir << "/" << endl;    
  cout << endl;     
  
  gBenchmark->Show("plotZee");
}
コード例 #26
0
ファイル: bToDRawYield.C プロジェクト: Jelov/BtoD
void bToDRawYield()
{
	gStyle->SetTextSize(0.05);
	gStyle->SetTextFont(42);
	gStyle->SetPadRightMargin(0.04);
	gStyle->SetPadLeftMargin(0.14);
	gStyle->SetPadTopMargin(0.1);
	gStyle->SetPadBottomMargin(0.14);
	gStyle->SetTitleX(.0f);
	gStyle->SetOptFit(1111);
	gStyle->SetOptStat(0);
	gStyle->SetOptTitle(0);

	TCanvas* c4 = new TCanvas("c4","",800,600);
	c4->Divide(2,2);

	TCanvas* c2 = new TCanvas("c2","",400,600);
	c2->Divide(1,2);

	TCanvas* c1 = new TCanvas();

	TCanvas* c15 = new TCanvas("c15","",810,1000);
	c15->Divide(3,5);

	TFile* fPbPb = new TFile("bFeedDownPbPb.hist.root");
	TFile* fPbPbMB = new TFile("bFeedDownPbPbMB.hist.root");
	TFile* fPbPbMC = new TFile("bFeedDownPbPbMC.hist.root");
	TFile* fPbPbMBMC = new TFile("bFeedDownPbPbMBMC.hist.root");

	TH3D* hDataPbPb = (TH3D*)fPbPb->Get("hData");
	TH3D* hSidebandPbPb = (TH3D*)fPbPb->Get("hSideband");
	TH3D* hDataPbPbMB = (TH3D*)fPbPbMB->Get("hData");
	TH3D* hSidebandPbPbMB = (TH3D*)fPbPbMB->Get("hSideband");
	TH3D* hPtMD0DcaPbPb = (TH3D*)fPbPb->Get("hPtMD0Dca");
	TH3D* hPtMD0DcaPbPbMB = (TH3D*)fPbPbMB->Get("hPtMD0Dca");

	TH3D* hMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCNPSignal");
	TH3D* hMCPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCNPSignal");
	TH3D* hPtMD0DcaMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSwapped");
	TH3D* hPtMD0DcaMCPSignalPbPbMB =(TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPbMB = (TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSwapped");

	TH3D* hData = (TH3D*)hDataPbPb->Clone("hData");
	hData->Sumw2();
	hData->Add(hDataPbPbMB);

	TH3D* hSideband = (TH3D*)hSidebandPbPb->Clone("hSideband");
	hSideband->Sumw2();
	hSideband->Add(hSidebandPbPbMB);

	TH3D* hPtMD0Dca = (TH3D*)hPtMD0DcaPbPb->Clone("hPtMD0Dca");
	hPtMD0Dca->Sumw2();
	hPtMD0Dca->Add(hPtMD0DcaPbPbMB);

	TH3D* hMCPSignal = (TH3D*)hMCPSignalPbPb->Clone("hMCPSignal");
	hMCPSignal->Sumw2();
	hMCPSignal->Add(hMCPSignalPbPbMB);

	TH3D* hMCNPSignal = (TH3D*)hMCNPSignalPbPb->Clone("hMCNPSignal");
	hMCNPSignal->Sumw2();
	hMCNPSignal->Add(hMCNPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSignal = (TH3D*)hPtMD0DcaMCPSignalPbPb->Clone("hPtMD0DcaMCPSignal");
	hPtMD0DcaMCPSignal->Sumw2();
	hPtMD0DcaMCPSignal->Add(hPtMD0DcaMCPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSwapped =(TH3D*)hPtMD0DcaMCPSwappedPbPb->Clone("hPtMD0DcaMCPSwapped");
	hPtMD0DcaMCPSwapped->Sumw2();
	hPtMD0DcaMCPSwapped->Add(hPtMD0DcaMCPSwappedPbPbMB);

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

	TLatex* texCol = new TLatex(0.96,0.93, "PbPb #sqrt{s_{NN}} = 5.02 TeV");
	texCol->SetNDC();
	texCol->SetTextAlign(32);
	texCol->SetTextSize(0.06);
	texCol->SetTextFont(42);

	const int nPtBins = 14;
	float ptBins[nPtBins+1] = {2.,3.,4.,5.,6.,8.,10.,12.5,15.0,20.,25.,30.,40.,60.,100};

	float pts[nPtBins];
	float ptErrors[nPtBins];
	float promptFraction[nPtBins];
	float totalYield[nPtBins];
	float totalYieldInvMassFit[nPtBins];
	float totalYieldInvMassFitError[nPtBins];
	float bToDYield[nPtBins];
	float bToDYieldError[nPtBins];
	float bToDYieldErrorDataOnly[nPtBins];
	float promptDYield[nPtBins];
	float promptDYieldError[nPtBins];
	float promptDYieldErrorDataOnly[nPtBins];

	const int nBinY = 14;
	Float_t binsY[nBinY+1];
	float firstBinYWidth = 0.001;
	float binYWidthRatio = 1.27;
	binsY[0]=0;
	for(int i=1; i<=nBinY; i++)
		binsY[i] = binsY[i-1]+firstBinYWidth*pow(binYWidthRatio,i-1);
	cout<<"last y bin: "<<binsY[nBinY]<<endl;

	//  for(int i=1; i<=nPtBins; i++)
	for(int i =7; i<=7; i++)
	{
		pts[i-1] = 0.5*(ptBins[i-1]+ptBins[i]);
		ptErrors[i-1] = 0.5*(ptBins[i]-ptBins[i-1]);
		float ptLow = ptBins[i-1];
		float ptHigh = ptBins[i];
		cout<<endl<<"======================================="<<endl;
		cout<<"pT range: "<<ptLow<<" "<<ptHigh<<endl;

		TLatex* texPtY = new TLatex(0.32,0.82,Form("%.1f < p_{T} < %.1f GeV/c      |y| < 1.0",ptLow,ptHigh));
		texPtY->SetNDC();
		texPtY->SetTextFont(42);
		texPtY->SetTextSize(0.06);
		texPtY->SetLineWidth(2);

		TLatex* texPt = new TLatex(0.18,0.82,Form("%.1f < p_{T} < %.1f GeV/c",ptLow,ptHigh));
		texPt->SetNDC();
		texPt->SetTextFont(42);
		texPt->SetTextSize(0.06);
		texPt->SetLineWidth(2);

		TLatex* texY = new TLatex(0.18,0.74,Form("|y| < 1.0"));
		texY->SetNDC();
		texY->SetTextFont(42);
		texY->SetTextSize(0.06);
		texY->SetLineWidth(2);

		c2->cd(1);

		hPtMD0Dca->GetZaxis()->SetRange(1,100);
		hPtMD0Dca->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hPtMD0DcaMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hPtMD0DcaMCPSwapped->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		TH1D* hMData = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_%1.1f_%1.1f", ptLow, ptHigh));
		TH1D* hMMCSignal = (TH1D*)hPtMD0DcaMCPSignal->Project3D("y");
		TH1D* hMMCSwapped = (TH1D*)hPtMD0DcaMCPSwapped->Project3D("y");

		setColorTitleLabel(hMData);
		setColorTitleLabel(hMMCSignal);
		setColorTitleLabel(hMMCSwapped);

		TF1* fMass = fitMass(hMData, hMMCSignal, hMMCSwapped);

		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		TF1* fSignalAndSwapped = new TF1("fSignalAndSwapped","[0]*([3]*([5]*Gaus(x,[1],[2]*(1+[7]))/(sqrt(2*3.1415927)*[2]*(1+[7]))+(1-[5])*Gaus(x,[1],[6]*(1+[7]))/(sqrt(2*3.1415927)*[6]*(1+[7])))+(1-[3])*Gaus(x,[1],[4]*(1+[7]))/(sqrt(2*3.1415927)*[4]*(1+[7])))", 1.7, 2.0);      
		fSignalAndSwapped->SetParameter(0,fMass->GetParameter(0));
		fSignalAndSwapped->SetParameter(1,fMass->GetParameter(1));
		fSignalAndSwapped->SetParameter(2,fMass->GetParameter(2));
		fSignalAndSwapped->SetParameter(3,fMass->GetParameter(7));
		fSignalAndSwapped->SetParameter(4,fMass->GetParameter(8));
		fSignalAndSwapped->SetParameter(5,fMass->GetParameter(9));
		fSignalAndSwapped->SetParameter(6,fMass->GetParameter(10));
		fSignalAndSwapped->SetParameter(7,fMass->GetParameter(11));

		TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x");
		background->SetParameter(0,fMass->GetParameter(3));
		background->SetParameter(1,fMass->GetParameter(4));
		background->SetParameter(2,fMass->GetParameter(5));
		background->SetParameter(3,fMass->GetParameter(6));

		cout<<"MC signal width: "<<fMass->GetParameter(2)<<"   "<<fMass->GetParameter(10)<<endl;
		cout<<"MC swapped width: "<<fMass->GetParameter(8)<<endl;

		float massD = 1.8649;
		float massSignal1 = massD-0.025;
		float massSignal2 = massD+0.025;
		float massSideBand1 = massD-0.1;
		float massSideBand2 = massD-0.075;
		float massSideBand3 = massD+0.075;
		float massSideBand4 = massD+0.1;

		float scaleSideBandBackground = background->Integral(massSignal1, massSignal2)/(background->Integral(massSideBand1, massSideBand2)+background->Integral(massSideBand3, massSideBand4));
		cout<<"scaleSideBandBackground: "<<scaleSideBandBackground<<endl;
		totalYieldInvMassFit[i-1] = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1);
		totalYieldInvMassFitError[i-1] = fMass->GetParError(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1);
		cout<<"totalYieldInvMassFit: "<<totalYieldInvMassFit[i-1]<<" +- "<<totalYieldInvMassFitError[i-1]<<endl;
		float scaleSideBandMethodSignal = fSignalAndSwapped->GetParameter(0)*fSignalAndSwapped->GetParameter(3) / (fSignalAndSwapped->Integral(massSignal1, massSignal2)-fSignalAndSwapped->Integral(massSideBand1, massSideBand2)-fSignalAndSwapped->Integral(massSideBand3, massSideBand4));
		cout<<"scaleSideBandMethodSignal: "<<scaleSideBandMethodSignal<<endl;

		TLatex* texScale = new TLatex(0.18,0.66,Form("side band bg scale: %1.3f", scaleSideBandBackground));
		texScale->SetNDC();
		texScale->SetTextFont(42);
		texScale->SetTextSize(0.06);
		texScale->SetLineWidth(2);
		texScale->Draw();

		TLine* lineSignal1 = new TLine(massSignal1, 0, massSignal1, hMData->GetMaximum()*0.5);
		TLine* lineSignal2 = new TLine(massSignal2, 0, massSignal2, hMData->GetMaximum()*0.5);
		TLine* lineSideBand1 = new TLine(massSideBand1, 0, massSideBand1, hMData->GetMaximum()*0.5);
		TLine* lineSideBand2 = new TLine(massSideBand2, 0, massSideBand2, hMData->GetMaximum()*0.5);
		TLine* lineSideBand3 = new TLine(massSideBand3, 0, massSideBand3, hMData->GetMaximum()*0.5);
		TLine* lineSideBand4 = new TLine(massSideBand4, 0, massSideBand4, hMData->GetMaximum()*0.5);
		lineSignal1->Draw();
		lineSignal2->Draw();
		lineSideBand1->Draw();
		lineSideBand2->Draw();
		lineSideBand3->Draw();
		lineSideBand4->Draw();

		c2->cd(2);
		gPad->SetLogy();

		hData->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hSideband->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hMCNPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);

		TH1D* hD0DcaData0 = (TH1D*)hData->Project3D("y")->Clone("hD0DcaData0");
		TH1D* hD0DcaSideband = (TH1D*)hSideband->Project3D("y")->Clone("hD0DcaSideband");
		TH1D* hD0DcaMCPSignal0 = (TH1D*)hMCPSignal->Project3D("y")->Clone("hD0DcaMCPSignal0");
		TH1D* hD0DcaMCNPSignal0 = (TH1D*)hMCNPSignal->Project3D("y")->Clone("hD0DcaMCNPSignal0");

		float integralRawYieldMCP = hD0DcaMCPSignal0->Integral();
		float integralRawYieldMCNP = hD0DcaMCNPSignal0->Integral();
		cout<<"integralRawYieldMCP: "<<integralRawYieldMCP<<endl;
		cout<<"integralRawYieldMCNP: "<<integralRawYieldMCNP<<endl;

		hD0DcaMCPSignal = hD0DcaMCPSignal0;
		hD0DcaMCNPSignal = hD0DcaMCNPSignal0;

		divideBinWidth(hD0DcaData0);
		divideBinWidth(hD0DcaSideband);
		setColorTitleLabel(hD0DcaData0, 1);
		hD0DcaData0->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaData0->GetYaxis()->SetTitle("counts per cm");

		TH1D* hD0DcaSideband0 = (TH1D*)hD0DcaSideband->Clone("hD0DcaSideband0");
		hD0DcaSideband->Scale(scaleSideBandBackground);

		TH1D* hD0DcaDataSubSideBand = (TH1D*)hD0DcaData0->Clone("hD0DcaDataSubSideBand");
		hD0DcaDataSubSideBand->Add(hD0DcaSideband,-1);
		hD0DcaDataSubSideBand->Scale(scaleSideBandMethodSignal);

		hD0DcaData0->SetMarkerSize(0.6);
		hD0DcaData0->Draw();
		hD0DcaSideband->Draw("hsame");
		hD0DcaSideband0->SetLineStyle(2);
		hD0DcaSideband0->Draw("hsame");

		TLegend* leg1 = new TLegend(0.44,0.6,0.90,0.76,NULL,"brNDC");
		leg1->SetBorderSize(0);
		leg1->SetTextSize(0.06);
		leg1->SetTextFont(42);
		leg1->SetFillStyle(0);
		leg1->AddEntry(hD0DcaData0,"D^{0} candidate","pl");
		leg1->AddEntry(hD0DcaSideband,"side band","l");
		leg1->AddEntry(hD0DcaSideband0,"side band unscaled","l");
		leg1->Draw("same");

		texCms->Draw();
		texCol->Draw();
		texPtY->Draw();

		c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_sideBand.pdf",ptLow,ptHigh));

		c2->cd(1);
		hMMCSignal->Draw();
		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		c2->cd(2);
		gPad->SetLogy(0);
		hMMCSwapped->Draw();
		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_McInvMassFit.pdf",ptLow,ptHigh));

		c15->cd(1);

		fitMass(hMData, hMMCSignal, hMMCSwapped);

		texPt->Draw();
		texY->Draw();

		TH1D* hD0DcaDataFit = new TH1D("hD0DcaDataFit", ";D^{0} DCA (cm);dN / d(D^{0} DCA) (cm^{-1})", nBinY, binsY);

		for(int j=1; j<=14; j++)
		{
			c15->cd(j+1);
			hPtMD0Dca->GetZaxis()->SetRange(j,j);
			float D0DcaLow = hPtMD0Dca->GetZaxis()->GetBinLowEdge(j);
			float D0DcaHigh = hPtMD0Dca->GetZaxis()->GetBinUpEdge(j);
			TH1D* hMData_D0Dca = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_pt_%1.1f_%1.1f_D0Dca_%1.4f_%1.4f", ptLow, ptHigh, D0DcaLow, D0DcaHigh));
			setColorTitleLabel(hMData_D0Dca);
			fMass = fitMass(hMData_D0Dca, hMMCSignal, hMMCSwapped);

			float yield = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1);
			float yieldError = fMass->GetParError(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1);

			hD0DcaDataFit->SetBinContent(j, yield);
			hD0DcaDataFit->SetBinError(j, yieldError);

			TLatex* texD0Dca = new TLatex(0.18,0.82,Form("D^{0} DCA: %1.4f - %1.4f",D0DcaLow,D0DcaHigh));
			texD0Dca->SetNDC();
			texD0Dca->SetTextFont(42);
			texD0Dca->SetTextSize(0.06);
			texD0Dca->SetLineWidth(2);
			texD0Dca->Draw();

			TLatex* texYield = new TLatex(0.18,0.74,Form("D^{0} yield: %1.0f #pm %1.0f",yield,yieldError));
			texYield->SetNDC();
			texYield->SetTextFont(42);
			texYield->SetTextSize(0.06);
			texYield->SetLineWidth(2);
			texYield->Draw();
		}

		c15->SaveAs(Form("plots/PbPb_%.0f_%.0f_invMassFit.pdf",ptLow,ptHigh));

		divideBinWidth(hD0DcaDataFit);

		c4->cd(1);
		gPad->SetLogy();

		normalize(hD0DcaMCPSignal);
		setColorTitleLabel(hD0DcaMCPSignal, 2);
		hD0DcaMCPSignal->GetXaxis()->SetRangeUser(0,0.07);

		normalize(hD0DcaMCNPSignal);
		setColorTitleLabel(hD0DcaMCNPSignal, 4);
		hD0DcaMCNPSignal->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaMCNPSignal->GetYaxis()->SetTitle("dN / d(D^{0} DCA) (cm^{-1})");
		hD0DcaMCNPSignal->GetXaxis()->SetTitle("D^{0} DCA (cm)");
		hD0DcaMCNPSignal->SetMaximum(hD0DcaMCPSignal->GetMaximum()*3.);

		hD0DcaMCNPSignal->Draw("");
		hD0DcaMCPSignal->Draw("same");

		TLegend* leg2 = new TLegend(0.54,0.72,0.90,0.88,NULL,"brNDC");
		leg2->SetBorderSize(0);
		leg2->SetTextSize(0.06);
		leg2->SetTextFont(42);
		leg2->SetFillStyle(0);
		leg2->AddEntry(hD0DcaMCPSignal,"MC Prompt D^{0}","pl");
		leg2->AddEntry(hD0DcaMCNPSignal,"MC Non-prompt D^{0}","pl");
		leg2->Draw("same");

		c4->cd(2);
		gPad->SetLogy();

		TH1D* hD0DcaData = hD0DcaDataFit;
		if(pts[i-1]>20) hD0DcaData = hD0DcaDataSubSideBand;

		setColorTitleLabel(hD0DcaData, 1);

		double integralTotalYield = hD0DcaData->Integral(1,hD0DcaData->GetXaxis()->GetNbins(),"width");
		cout<<"integralTotalYield: "<<integralTotalYield<<endl;

		TF1* fMix = new TF1("fMix",&funMix, 0., 0.5, 2);
		fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
		fMix->SetParLimits(0,0,2*integralTotalYield);
		fMix->SetParLimits(1,0,2*integralTotalYield);

		fMix->SetLineColor(2);
		fMix->SetFillColor(kRed-9);
		fMix->SetFillStyle(1001);

		float fitRangeL = 0;
		float fitRangeH = 0.08;

		hD0DcaData->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaData->Draw();
		int fitStatus = 1;
		TFitResultPtr fitResult;
		double fitPrecision = 1.e-6;
		while(fitStatus)
		{
			TFitter::SetPrecision(fitPrecision);
			fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
			fMix->SetParError(0,0.1*integralTotalYield);
			fMix->SetParError(1,0.1*integralTotalYield);
			fitResult = hD0DcaData->Fit("fMix","E SNQ0", "", fitRangeL, fitRangeH);
			fitStatus = fitResult->Status();
			cout<<"fit precision: "<<TFitter::GetPrecision()<<"   status: "<<fitStatus<<endl;
			if(fitStatus)
				fitPrecision *= 10;
		}
		cout<<"============== do main fit ============"<<endl;
		fMix->SetParameters(integralTotalYield,0.9);
		fMix->SetParError(0,0.1*integralTotalYield);
		fMix->SetParError(1,0.1);
		fMix->SetNpx(10000);
		fitResult = hD0DcaData->Fit("fMix","E S0", "", fitRangeL, fitRangeH);
		hD0DcaData->GetFunction("fMix")->Draw("flsame");
		fitStatus = fitResult->Status();
		cout<<"fit precision: "<<TFitter::GetPrecision()<<"   status: "<<fitStatus<<endl;

		TF1* fNP = new TF1("fNP",&funNonPrompt, 0., 0.5, 2);
		fNP->SetParameters(fMix->GetParameter(0),fMix->GetParameter(1));
		fNP->SetRange(fitRangeL,fitRangeH);
		fNP->SetLineColor(4);
		fNP->SetFillStyle(1001);
		fNP->SetFillColor(kBlue-9);
		fNP->SetNpx(10000);
		fNP->Draw("same");  

		hD0DcaData->Draw("same");

		promptDYield[i-1] = fMix->GetParameter(0);
		promptDYieldErrorDataOnly[i-1] = fMix->GetParError(0);
		bToDYield[i-1] = fMix->GetParameter(1);
		bToDYieldErrorDataOnly[i-1] = fMix->GetParError(1);
		totalYield[i-1] = promptDYield[i-1]+bToDYield[i-1];
		promptFraction[i-1] = promptDYield[i-1]/totalYield[i-1];

		cout<<"chi2 / NDF: "<<fitResult->Chi2()<<" / "<<fitResult->Ndf()<<endl;

		texCms->Draw();
		texCol->Draw();
		texPtY->Draw();

		TLatex* texPrompt = new TLatex(0.4,0.73,Form("Prompt D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(0),fMix->GetParError(0)));
		texPrompt->SetNDC();
		texPrompt->SetTextFont(42);
		texPrompt->SetTextSize(0.06);
		texPrompt->SetLineWidth(2);
		texPrompt->Draw();

		TLatex* texNonPrompt = new TLatex(0.4,0.65,Form("B to D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(1),fMix->GetParError(1)));
		texNonPrompt->SetNDC();
		texNonPrompt->SetTextFont(42);
		texNonPrompt->SetTextSize(0.06);
		texNonPrompt->SetLineWidth(2);
		texNonPrompt->Draw();

		TLegend* leg4 = new TLegend(0.56,0.38,0.90,0.62);
		leg4->SetBorderSize(0);
		leg4->SetTextSize(0.06);
		leg4->SetTextFont(42);
		leg4->SetFillStyle(0);
		leg4->AddEntry(hD0DcaData,"Data","pl");
		leg4->AddEntry(fMix,"Prompt D^{0}","f");
		leg4->AddEntry(fNP,"B to D^{0}","f");
		leg4->Draw("same");

		//smear MC smaple with the error, to simulate the MC statistic error effect.
		c4->cd(3);

		hD0DcaMCPSignal = (TH1D*)hD0DcaMCPSignal0->Clone("hMCPSignal");
		hD0DcaMCNPSignal = (TH1D*)hD0DcaMCNPSignal0->Clone("hMCNPSignal");

		TH1D* hNPYield = new TH1D("hNPYield", ";hNPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1)));
		TH1D* hPYield = new TH1D("hPYield", ";hPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1)));
		setColorTitleLabel(hNPYield, 1);
		setColorTitleLabel(hPYield, 1);

		int nSmear = 1000;

		for(int j=0; j<nSmear; j++)
		{
			RandomSmear(hD0DcaMCPSignal0, hD0DcaMCPSignal);
			RandomSmear(hD0DcaMCNPSignal0, hD0DcaMCNPSignal);
			fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
			fMix->SetParError(0,0.1*integralTotalYield);
			fMix->SetParError(1,0.1*integralTotalYield);

			hD0DcaData->Fit("fMix","E QN0");

			hPYield->Fill(fMix->GetParameter(0));
			hNPYield->Fill(fMix->GetParameter(1));
		}

		hPYield->GetXaxis()->SetTitle("prompt D^{0} yield");
		hPYield->GetYaxis()->SetTitle("counts");
		hPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hPYield->GetMaximum());
		hPYield->SetMarkerStyle(20);
		hPYield->SetStats(0);
		hPYield->Draw("e");
		hPYield->Fit("gaus");

		TLatex* texGaussMeanSigmaP = new TLatex(0.27,0.83,Form("#mu: %.0f              #sigma: %.0f",hPYield->GetFunction("gaus")->GetParameter(1),hPYield->GetFunction("gaus")->GetParameter(2)));
		texGaussMeanSigmaP->SetNDC();
		texGaussMeanSigmaP->SetTextFont(42);
		texGaussMeanSigmaP->SetTextSize(0.06);
		texGaussMeanSigmaP->SetLineWidth(2);
		texGaussMeanSigmaP->Draw();

		float promptYieldErrorMc = hPYield->GetFunction("gaus")->GetParameter(2);
		promptDYieldError[i-1] = sqrt(pow(promptDYieldErrorDataOnly[i-1],2)+pow(promptYieldErrorMc,2));

		c4->cd(4);

		hNPYield->GetXaxis()->SetTitle("B to D^{0} yield");
		hNPYield->GetYaxis()->SetTitle("counts");
		hNPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hNPYield->GetMaximum());
		hNPYield->SetMarkerStyle(20);
		hNPYield->SetStats(0);
		hNPYield->Draw("e");
		hNPYield->Fit("gaus");

		TLatex* texGaussMeanSigmaNP = new TLatex(0.27,0.83,Form("#mu: %.0f              #sigma: %.0f",hNPYield->GetFunction("gaus")->GetParameter(1),hNPYield->GetFunction("gaus")->GetParameter(2)));
		texGaussMeanSigmaNP->SetNDC();
		texGaussMeanSigmaNP->SetTextFont(42);
		texGaussMeanSigmaNP->SetTextSize(0.06);
		texGaussMeanSigmaNP->SetLineWidth(2);
		texGaussMeanSigmaNP->Draw();

		float bToDYieldErrorMc = hNPYield->GetFunction("gaus")->GetParameter(2);
		bToDYieldError[i-1] = sqrt(pow(bToDYieldErrorDataOnly[i-1],2)+pow(bToDYieldErrorMc,2));

		cout<<"prompt D yield: "<<promptDYield[i-1]<<" +- "<<promptDYieldError[i-1]<<" (+- "<<promptDYieldErrorDataOnly[i-1]<<" +- "<<promptYieldErrorMc<<" )"<<endl;
		cout<<"B to D yield: "<<bToDYield[i-1]<<" +- "<<bToDYieldError[i-1]<<" (+- "<<bToDYieldErrorDataOnly[i-1]<<" +- "<<bToDYieldErrorMc<<" )"<<endl;
		cout<<"total yield: "<<totalYield[i-1]<<endl;
		cout<<"prompt fraction: "<<promptFraction[i-1]<<endl;

		float promptMCScale = promptDYield[i-1]/integralRawYieldMCP;
		float nonPromptMCScale = bToDYield[i-1]/integralRawYieldMCNP;

		cout<<"promptMCScale: "<<promptMCScale<<endl;
		cout<<"nonPromptMCScale: "<<nonPromptMCScale<<endl;

		//restore original unsmeared histograms before saving plots
		delete hD0DcaMCPSignal;
		delete hD0DcaMCNPSignal;
		hD0DcaMCPSignal = hD0DcaMCPSignal0;
		hD0DcaMCNPSignal = hD0DcaMCNPSignal0;
		hD0DcaData->Fit("fMix","E QN0");

		c4->SaveAs(Form("plots/PbPb_%.0f_%.0f_fit.pdf",ptLow,ptHigh));

		c1->cd();

		TH1D* hD0DcaDataOverFit = (TH1D*)hD0DcaData->Clone("hD0DcaDataOverFit");
		hD0DcaDataOverFit->Divide(fMix);
		hD0DcaDataOverFit->GetYaxis()->SetTitle("data / fit");
		hD0DcaDataOverFit->GetYaxis()->SetRangeUser(0,5);
		hD0DcaDataOverFit->GetXaxis()->SetRangeUser(0,0.07);
		setColorTitleLabel(hD0DcaDataOverFit, 1);
		hD0DcaDataOverFit->Draw("e");

		TF1* fLine1 = new TF1("fLine1", "1", 0,1);
		fLine1->Draw("same");
		hD0DcaDataOverFit->Draw("esame");

		c1->SaveAs(Form("plots/dataOverFit_%.0f_%.0f_fit.pdf",ptLow,ptHigh));

		delete hD0DcaMCPSignal;
		delete hD0DcaMCNPSignal;

	} // end for i ptbins
	c1->cd();

	TH1D* hStupidJie = new TH1D("hStupidJie", "", 100, 0, 100);
	hStupidJie->GetYaxis()->SetRangeUser(0,1);
	hStupidJie->GetXaxis()->SetTitle("p_{T} (GeV/c)");
	hStupidJie->GetYaxis()->SetTitle("prompt fraction");
	hStupidJie->SetStats(0);
	hStupidJie->Draw();
	TGraph* grFraction = new TGraph(nPtBins, pts, promptFraction);
	grFraction->SetName("grPromptFraction");
	grFraction->SetMarkerStyle(20);
	grFraction->Draw("psame");

	c1->SaveAs("promptFraction.pdf");

	c1->SetLogy();

	TH1D* hBtoDRawYield = new TH1D("hBtoDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(bToDYield[i-1] <= 0) continue;
		hBtoDRawYield->SetBinContent(i, bToDYield[i-1]);
		hBtoDRawYield->SetBinError(i, bToDYieldError[i-1]);
	}
	divideBinWidth(hBtoDRawYield);
	setColorTitleLabel(hBtoDRawYield, 1);
	c1->SetBottomMargin(0.14);
	hBtoDRawYield->Draw("p");
	c1->SaveAs("BtoD.pdf");

	TH1D* hPromptDRawYield = new TH1D("hPromptDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(promptDYield[i-1] <= 0) continue;
		hPromptDRawYield->SetBinContent(i, promptDYield[i-1]);
		hPromptDRawYield->SetBinError(i, promptDYieldError[i-1]);
	}
	divideBinWidth(hPromptDRawYield);
	setColorTitleLabel(hPromptDRawYield, 1);
	c1->SetBottomMargin(0.14);
	hPromptDRawYield->Draw("p");
	c1->SaveAs("promptD.pdf");

	TH1D* hTotalDYieldInvMassFit = new TH1D("hTotalDYieldInvMassFit", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(totalYieldInvMassFit[i-1] <= 0) continue;
		hTotalDYieldInvMassFit->SetBinContent(i, totalYieldInvMassFit[i-1]);
		hTotalDYieldInvMassFit->SetBinError(i, totalYieldInvMassFitError[i-1]);
	}
	divideBinWidth(hTotalDYieldInvMassFit);
	setColorTitleLabel(hTotalDYieldInvMassFit, 1);
	hTotalDYieldInvMassFit->Draw("p");
	c1->SaveAs("totalDInvMassFit.pdf");

	TFile* fOut = new TFile("bFeedDownResult.root", "recreate");
	fOut->WriteTObject(grFraction);
	fOut->WriteTObject(hBtoDRawYield);
	fOut->WriteTObject(hPromptDRawYield);
	fOut->WriteTObject(hTotalDYieldInvMassFit);
	fOut->Write();
	fOut->Close();
}
コード例 #27
0
void makeNice(TString fileName, TString nice = "nicePlot"){

  TFile *f = TFile::Open(fileName);
  //  TFile *f = TFile::Open("out_Parameters_bkg1_3vtx.root");
  TGraphErrors * gRgre = (TGraphErrors*)f->Get("gR");
  TGraphErrors * gXgre = (TGraphErrors*)f->Get("gX");
  TGraphErrors * gYgre = (TGraphErrors*)f->Get("gY");

  TGraphErrors * rRgre = (TGraphErrors*)f->Get("rR");
  TGraphErrors * rXgre = (TGraphErrors*)f->Get("rX");
  TGraphErrors * rYgre = (TGraphErrors*)f->Get("rY");



//=========Macro generated from canvas: c1_n2/c1_n2
//=========  (Fri May 27 11:43:08 2011) by ROOT version5.27/06b
   TCanvas *c1_n2 = new TCanvas("c1_n2","c1_n2",700,1500);
   gStyle->SetOptFit(0);
   gStyle->SetOptStat(0);
   c1_n2->Range(0,0,1,1);
   c1_n2->SetFillColor(0);
   c1_n2->SetBorderMode(0);
   c1_n2->SetBorderSize(2);
   c1_n2->SetTickx(1);
   c1_n2->SetTicky(1);
   c1_n2->SetLeftMargin(0.13);
   c1_n2->SetRightMargin(0.05);
   c1_n2->SetTopMargin(0.05);
   c1_n2->SetBottomMargin(0.13);
   c1_n2->SetFrameFillStyle(0);
   c1_n2->SetFrameBorderMode(0);
  
// ------------>Primitives in pad: c1_n2_1
   TPad *c1_n2_1 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.67,0.99,0.99);
   c1_n2_1->Draw();
   c1_n2_1->cd();
   c1_n2_1->Range(-52.68293,-0.03170732,44.87805,0.2121951);
   c1_n2_1->SetFillColor(0);
   c1_n2_1->SetBorderMode(0);
   c1_n2_1->SetBorderSize(2);
   c1_n2_1->SetTickx(1);
   c1_n2_1->SetTicky(1);
   c1_n2_1->SetLeftMargin(0.12);
   c1_n2_1->SetRightMargin(0.02);
   c1_n2_1->SetTopMargin(0.05);
   c1_n2_1->SetBottomMargin(0.2);
   c1_n2_1->SetFrameFillStyle(0);
   c1_n2_1->SetFrameBorderMode(0);
   c1_n2_1->SetFrameFillStyle(0);
   c1_n2_1->SetFrameBorderMode(0);
   
   TH1D *PLOTTERX = new TH1D("PLOTTERX","",1,-40,40);
   PLOTTERX->SetMinimum(-0.19);
   PLOTTERX->SetMaximum(+0.19);
   PLOTTERX->SetFillColor(63);
   PLOTTERX->SetLineStyle(0);
   PLOTTERX->SetMarkerStyle(20);
   PLOTTERX->GetXaxis()->SetLabelFont(42);
   PLOTTERX->GetXaxis()->SetLabelOffset(0.007);
   PLOTTERX->GetXaxis()->SetLabelSize(0.09);
   PLOTTERX->GetXaxis()->SetTitleSize(0.1);
   PLOTTERX->GetXaxis()->SetTitleOffset(0.9);
   PLOTTERX->GetXaxis()->SetTitleFont(42);
   PLOTTERX->GetXaxis()->SetTitle("z [cm]");
   PLOTTERX->GetYaxis()->SetNdivisions(505);
   PLOTTERX->GetYaxis()->SetTitle("x_{0} [cm] ");
   PLOTTERX->GetYaxis()->SetLabelFont(42);
   PLOTTERX->GetYaxis()->SetLabelOffset(0.007);
   PLOTTERX->GetYaxis()->SetLabelSize(0.09);
   PLOTTERX->GetYaxis()->SetTitleSize(0.1);
   PLOTTERX->GetYaxis()->SetTitleOffset(0.5);
   PLOTTERX->GetYaxis()->SetTitleFont(42);
   PLOTTERX->GetZaxis()->SetLabelFont(42);
   PLOTTERX->GetZaxis()->SetLabelOffset(0.007);
   PLOTTERX->GetZaxis()->SetLabelSize(0.05);
   PLOTTERX->GetZaxis()->SetTitleSize(0.06);
   PLOTTERX->GetZaxis()->SetTitleFont(42);
   PLOTTERX->Draw("");
   
   gXgre->SetFillColor(kBlack);
   gXgre->SetMarkerStyle(20);
   gXgre->SetMarkerColor(kBlack);
   gXgre->SetLineColor(kBlack);
   gXgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   gXgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   gXgre->SetLineWidth(2);
   gXgre->Draw("P");

   rXgre->SetFillColor(kBlue);
   rXgre->SetMarkerStyle(20);
   rXgre->SetMarkerColor(kBlue);
   rXgre->SetLineColor(kBlue);
   rXgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   rXgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   rXgre->SetLineWidth(2);
   rXgre->Draw("P");

   TLatex *CMSPrel = new TLatex(-37.0,PLOTTERX->GetMaximum()-0.025,"CMS Preliminary 2011");
   CMSPrel->SetTextSize(0.06);
   //   CMSPrel->Draw();
   c1_n2_1->Modified();
   c1_n2->cd();
  
// ------------>Primitives in pad: c1_n2_2
   TPad *c1_n2_2 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.34,0.99,0.66);
   //   TPad *c1_n2_1 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.01,0.99,0.33);
   c1_n2_2->Draw();
   c1_n2_2->cd();
   c1_n2_2->Range(-52.68293,-0.3317073,44.87805,-0.08780488);
   c1_n2_2->SetFillColor(0);
   c1_n2_2->SetBorderMode(0);
   c1_n2_2->SetBorderSize(2);
   c1_n2_2->SetTickx(1);
   c1_n2_2->SetTicky(1);
   c1_n2_2->SetLeftMargin(0.12);
   c1_n2_2->SetRightMargin(0.02);
   c1_n2_2->SetTopMargin(0.05);
   c1_n2_2->SetBottomMargin(0.2);
   c1_n2_2->SetFrameFillStyle(0);
   c1_n2_2->SetFrameBorderMode(0);
   c1_n2_2->SetFrameFillStyle(0);
   c1_n2_2->SetFrameBorderMode(0);
   
   TH1D *PLOTTERY = new TH1D("PLOTTERY","",1,-40,40);
   PLOTTERY->SetMinimum(-0.29);
   PLOTTERY->SetMaximum(+0.09);
   PLOTTERY->SetFillColor(63);
   PLOTTERY->SetLineStyle(0);
   PLOTTERY->SetMarkerStyle(20);
   PLOTTERY->GetXaxis()->SetLabelFont(42);
   PLOTTERY->GetXaxis()->SetLabelOffset(0.007);
   PLOTTERY->GetXaxis()->SetLabelSize(0.09);
   PLOTTERY->GetXaxis()->SetTitleSize(0.1);
   PLOTTERY->GetXaxis()->SetTitleFont(42);
   PLOTTERY->GetXaxis()->SetTitleOffset(0.9);
   PLOTTERY->GetXaxis()->SetTitle("z [cm]");
   PLOTTERY->GetYaxis()->SetNdivisions(505);
   PLOTTERY->GetYaxis()->SetTitle("y_{0} [cm] ");
   PLOTTERY->GetYaxis()->SetLabelFont(42);
   PLOTTERY->GetYaxis()->SetLabelOffset(0.007);
   PLOTTERY->GetYaxis()->SetLabelSize(0.09);
   PLOTTERY->GetYaxis()->SetTitleSize(0.1);
   PLOTTERY->GetYaxis()->SetTitleOffset(0.5);
   PLOTTERY->GetYaxis()->SetTitleFont(42);
   PLOTTERY->GetZaxis()->SetLabelFont(42);
   PLOTTERY->GetZaxis()->SetLabelOffset(0.007);
   PLOTTERY->GetZaxis()->SetLabelSize(0.05);
   PLOTTERY->GetZaxis()->SetTitleSize(0.06);
   PLOTTERY->GetZaxis()->SetTitleFont(42);
   PLOTTERY->Draw("");
   
   gYgre->SetFillColor(kBlack);
   gYgre->SetMarkerStyle(20);
   gYgre->SetMarkerColor(kBlack);
   gYgre->SetLineColor(kBlack);
   gYgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   gYgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   gYgre->SetLineWidth(2);
   gYgre->Draw("P");

   rYgre->SetFillColor(kBlue);
   rYgre->SetMarkerStyle(20);
   rYgre->SetMarkerColor(kBlue);
   rYgre->SetLineColor(kBlue);
   rYgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   rYgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   rYgre->SetLineWidth(2);
   rYgre->Draw("P");

   TLatex *CMSPrel = new TLatex(-37.0,PLOTTERY->GetMaximum()-0.025,"CMS Preliminary 2011");
   CMSPrel->SetTextSize(0.06);
   //   CMSPrel->Draw();
   c1_n2_2->Modified();
   c1_n2->cd();
  

// ------------>Primitives in pad: c1_n2_2
   TPad *c1_n2_3 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.01,0.99,0.33);
   //   TPad *c1_n2_1 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.01,0.99,0.33);
   c1_n2_3->Draw();
   c1_n2_3->cd();
   c1_n2_3->Range(-52.68293,-0.3317073,44.87805,-0.08780488);
   c1_n2_3->SetFillColor(0);
   c1_n2_3->SetBorderMode(0);
   c1_n2_3->SetBorderSize(2);
   c1_n2_3->SetTickx(1);
   c1_n2_3->SetTicky(1);
   c1_n2_3->SetLeftMargin(0.12);
   c1_n2_3->SetRightMargin(0.02);
   c1_n2_3->SetTopMargin(0.05);
   c1_n2_3->SetBottomMargin(0.2);
   c1_n2_3->SetFrameFillStyle(0);
   c1_n2_3->SetFrameBorderMode(0);
   c1_n2_3->SetFrameFillStyle(0);
   c1_n2_3->SetFrameBorderMode(0);
   
   TH1D *PLOTTERR = new TH1D("PLOTTERR","",1,-40,40);
   PLOTTERR->SetMinimum(2.87);
   PLOTTERR->SetMaximum(2.97);
   PLOTTERR->SetFillColor(63);
   PLOTTERR->SetLineStyle(0);
   PLOTTERR->SetMarkerStyle(20);
   PLOTTERR->GetXaxis()->SetLabelFont(42);
   PLOTTERR->GetXaxis()->SetLabelOffset(0.007);
   PLOTTERR->GetXaxis()->SetLabelSize(0.09);
   PLOTTERR->GetXaxis()->SetTitleSize(0.1);
   PLOTTERR->GetXaxis()->SetTitleFont(42);
   PLOTTERR->GetXaxis()->SetTitleOffset(0.9);
   PLOTTERR->GetXaxis()->SetTitle("z [cm]");
   PLOTTERR->GetYaxis()->SetNdivisions(505);
   PLOTTERR->GetYaxis()->SetTitle("R [cm] ");
   PLOTTERR->GetYaxis()->SetLabelFont(42);
   PLOTTERR->GetYaxis()->SetLabelOffset(0.007);
   PLOTTERR->GetYaxis()->SetLabelSize(0.09);
   PLOTTERR->GetYaxis()->SetTitleSize(0.1);
   PLOTTERR->GetYaxis()->SetTitleOffset(0.5);
   PLOTTERR->GetYaxis()->SetTitleFont(42);
   PLOTTERR->GetZaxis()->SetLabelFont(42);
   PLOTTERR->GetZaxis()->SetLabelOffset(0.007);
   PLOTTERR->GetZaxis()->SetLabelSize(0.05);
   PLOTTERR->GetZaxis()->SetTitleSize(0.06);
   PLOTTERR->GetZaxis()->SetTitleFont(42);
   PLOTTERR->Draw("");
   
   gRgre->SetFillColor(kBlack);
   gRgre->SetMarkerStyle(20);
   gRgre->SetMarkerColor(kBlack);
   gRgre->SetLineColor(kBlack);
   gRgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   gRgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   gRgre->SetLineWidth(2);
   gRgre->Draw("P");

   rRgre->SetFillColor(kBlue);
   rRgre->SetMarkerStyle(20);
   rRgre->SetMarkerColor(kBlue);
   rRgre->SetLineColor(kBlue);
   rRgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   rRgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   rRgre->SetLineWidth(2);
   rRgre->Draw("P");

   TLatex *CMSPrel = new TLatex(-37.0,PLOTTERR->GetMaximum()-0.025,"CMS Preliminary 2011");
   CMSPrel->SetTextSize(0.06);
   //   CMSPrel->Draw();
   c1_n2_3->Modified();
   c1_n2->cd();
 
   

   TF1* fX = new TF1("fX", "[0]+[1]*x", -35, 35); 
   TF1* fY = new TF1("fY", "[0]+[1]*x", -35, 35); 
   TF1* fR = new TF1("fR", "[0]+[1]*x", -35, 35); 

   fX->SetParameter(0, 0.1);
   fX->SetParameter(1, -0.0007);

   fY->SetParameter(0, -0.2);
   fY->SetParameter(1, +0.0007);

   fR->SetParameter(0, 2.94);
   fR->SetParameter(1, 0.0);

   gXgre->Fit(fX);
   gYgre->Fit(fY);
   gRgre->Fit(fR);

   //
   c1_n2->cd();
   c1_n2->Modified();
   c1_n2->cd();
   c1_n2->SetSelected(c1_n2);

   c1_n2->SaveAs(nice+".png"); //!Serve!!!!
   c1_n2->SaveAs(nice+".gif");
   c1_n2->SaveAs(nice+".png");


}
コード例 #28
0
void AxEffSyst(TString modOCDBOutputPath, TString stdOCDBOutputPath){

  gStyle->SetOptStat(0);

  TFile *axEffModOCDBFile = new TFile(modOCDBOutputPath.Data(),"READONLY");
  TFile *axEffStdOCDBFile = new TFile(stdOCDBOutputPath.Data(),"READONLY");

  TH1D *axEffModOCDBHisto = 0x0;
  axEffModOCDBFile->GetObject("ratio1", axEffModOCDBHisto);
  axEffModOCDBHisto->SetLineColor(kBlue);
  axEffModOCDBHisto->SetLineWidth(2);
  axEffModOCDBHisto->SetTitle("A#times#epsilon");
  axEffModOCDBHisto->GetXaxis()->SetTitle("Rapidity");
  axEffModOCDBHisto->GetYaxis()->SetTitle("A#times#epsilon");

  TH1D *axEffStdOCDBHisto = 0x0;
  axEffStdOCDBFile->GetObject("ratio1", axEffStdOCDBHisto);
  axEffStdOCDBHisto->SetLineColor(kRed);
  axEffStdOCDBHisto->SetTitle("A#times#epsilon Std OCDB");
  axEffStdOCDBHisto->GetXaxis()->SetTitle("Rapidity");
  axEffStdOCDBHisto->GetYaxis()->SetTitle("A#times#epsilon");

  axEffModOCDBHisto->Sumw2(kTRUE);
  axEffStdOCDBHisto->Sumw2(kTRUE);

  TH1D *ratio = (TH1D*)axEffStdOCDBHisto->Clone();
  ratio->Sumw2(kTRUE);
  ratio->SetLineWidth(1);
  ratio->Add(axEffModOCDBHisto, -1.);
  ratio->Divide(axEffStdOCDBHisto);
  ratio->SetLineColor(kBlack);
  ratio->SetTitle("#frac{A#times#epsilon_{Std OCDB}-A#times#epsilon_{Mod OCDB}}{A#times#epsilon_{Std OCDB}}");
  ratio->GetXaxis()->SetTitle("Rapidity");
  ratio->GetYaxis()->SetTitle("Ratio (%)");

  for (Int_t iBinsRatio = 0; iBinsRatio <= ratio->GetNbinsX()+1; iBinsRatio++) {
    Double_t binContent = ratio->GetBinContent(iBinsRatio);
    cout<<binContent<<"->";
    if ( binContent<0. ) ratio->SetBinContent(iBinsRatio, -binContent*100.);
    else ratio->SetBinContent(iBinsRatio, binContent*100.);
    binContent = ratio->GetBinContent(iBinsRatio);
    cout<<binContent<<endl;
  }

  TCanvas *canv = new TCanvas("canv");
  canv->Divide(2,1);

  canv->cd(1);
  axEffModOCDBHisto->SetDirectory(0);
  axEffModOCDBHisto->Draw("E");
  axEffStdOCDBHisto->SetDirectory(0);
  axEffStdOCDBHisto->Draw("SAME E");

  canv->cd(2);
  ratio->GetYaxis()->SetRangeUser(-0.5,ratio->GetMaximum()*2);
  ratio->SetDirectory(0);
  ratio->Draw("E");

  axEffModOCDBFile->Close();
  axEffStdOCDBFile->Close();
}
コード例 #29
0
TF1* fitDstar(TTree* nt, TTree* ntMC, Float_t ptmin, Bool_t plotgenmatch)
{
  TCanvas* c = new TCanvas(Form("c_5p_%.0f",ptmin),"",600,600);
  TH1D* h = new TH1D(Form("h_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);
  TH1D* hMCSignal = new TH1D(Form("hMCSignal_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);
  TH1D* hMCSignalplot = new TH1D(Form("hMCSignalplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);
  TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);
  TH1D* hMCSwappedplot = new TH1D(Form("hMCSwappedplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);

  TF1* f = new TF1(Form("f_5p_%.0f",ptmin),"[0]*([4]*([6]*([12]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[12])*Gaus(x,[1],[11])/(sqrt(2*3.14159)*[11]))+(1-[6])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5]))+(1-[4])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3]))+[10]*((1-exp((0.13957-x)/[7]))*pow(x/0.13957,[8])+[9]*(x/0.13957-1))",BINMIN,BINMAX);
  nt->Project(Form("h_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightdata[isData].Data(),seldata5p[isData].Data(),triggerselectiondata[isData].Data(),ptmin));
  ntMC->Project(Form("hMCSignal_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selmc5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin));
  ntMC->Project(Form("hMCSwapped_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selswp5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin));
  for(int ibin=0;ibin<BINNUM;ibin++) hMCSignalplot->SetBinContent(ibin+1,hMCSignal->GetBinContent(ibin+1));
  for(int ibin=0;ibin<BINNUM;ibin++) hMCSwappedplot->SetBinContent(ibin+1,hMCSwapped->GetBinContent(ibin+1));
  f->FixParameter(4,1.);
  f->FixParameter(1,0.145491);
  f->FixParameter(10,0);

  f->SetParLimits(0,0,1.e+5);
  f->SetParLimits(6,0,1.);
  f->SetParLimits(12,0,1.);
  f->SetParLimits(2,3.e-4,1.e-3);
  f->SetParameter(2,5.e-4);
  f->SetParLimits(11,1.6e-4,3.e-4);//1.5e-4 keyong
  f->SetParameter(11,2.e-4);
  f->SetParLimits(5,1.e-3,1.6e-3);
  f->SetParameter(5,1.e-3);
  hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);
  hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);
  f->ReleaseParameter(1);
  f->SetParLimits(1,minmass,maxmass);
  hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass);
  hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass);

  f->FixParameter(1,f->GetParameter(1));
  f->FixParameter(2,f->GetParameter(2));
  f->FixParameter(5,f->GetParameter(5));
  f->FixParameter(11,f->GetParameter(11));
  f->FixParameter(6,f->GetParameter(6));
  f->FixParameter(12,f->GetParameter(12));
  f->FixParameter(4,0);
  f->SetParLimits(3,2.e-4,2.e-3);
  f->SetParameter(3,1.e-3);

  hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX);
  hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX);
  hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass);
  hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass);

  f->FixParameter(4,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000)));
  f->FixParameter(3,f->GetParameter(3));

  f->SetParLimits(7,5.e-4,1.e-2);
  f->SetParameter(7,1.6e-3);
  f->SetParLimits(8,0.,15.);
  f->SetParameter(8,0.35);
  f->SetParLimits(9,-2.e+1,2.e+1);
  f->SetParameter(9,13.);

  f->ReleaseParameter(10);
  f->SetParLimits(10,0,1.e+6);

  h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);
  h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);

  f->ReleaseParameter(1);
  f->SetParLimits(1,minmass,maxmass);
  f->SetParameter(1,f->GetParameter(1));
  h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);
  h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);

  TF1* background = new TF1(Form("background_5p_%.0f",ptmin),"[3]*((1-exp((0.13957-x)/[0]))*pow(x/0.13957,[1])+[2]*(x/0.13957-1))");
  background->SetParameters(f->GetParameter(7),f->GetParameter(8),f->GetParameter(9),f->GetParameter(10));
  background->SetRange(BINMIN,BINMAX);
  background->SetLineColor(4);
  background->SetLineWidth(3);
  background->SetLineStyle(2);

  TF1* mass = new TF1(Form("fmass_5p_%.0f",ptmin),"[0]*[3]*([5]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))+(1-[5])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))");
  mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(4),f->GetParameter(5),f->GetParameter(6),f->GetParameter(11),f->GetParameter(12));
  mass->SetParError(0,f->GetParError(0));
  mass->SetParError(1,f->GetParError(1));
  mass->SetParError(2,f->GetParError(2));
  mass->SetParError(3,f->GetParError(4));
  mass->SetParError(4,f->GetParError(5));
  mass->SetParError(5,f->GetParError(6));
  mass->SetRange(BINMIN,BINMAX);
  mass->SetFillColor(kOrange-3);
  mass->SetFillStyle(3002);
  mass->SetLineColor(kOrange-3);
  mass->SetLineWidth(3);
  mass->SetLineStyle(2);

  TF1* massSwap = new TF1(Form("fmassSwap_5p_%.0f",ptmin),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])");
  massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(4),f->GetParameter(3));
  massSwap->SetRange(BINMIN,BINMAX);
  massSwap->SetFillColor(kGreen+4);
  massSwap->SetFillStyle(3005);
  massSwap->SetLineColor(kGreen+4);
  massSwap->SetLineWidth(3);
  massSwap->SetLineStyle(1);

  h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})");
  h->SetYTitle("Entries / (0.4 MeV/c^{2})");
  h->SetStats(0);
  h->SetAxisRange(0,h->GetMaximum()*1.3,"Y");
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  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");
  mass->Draw("same");
  massSwap->Draw("same");
  background->Draw("same");
  f->Draw("same");

  if(plotgenmatch&&(isData==MC_MB||isData==MC))
    {
      hMCSignalplot->SetMarkerSize(0.8);
      hMCSignalplot->SetMarkerColor(kMagenta+2);
      hMCSignalplot->Draw("psame");
      hMCSwappedplot->SetMarkerSize(0.8);
      hMCSwappedplot->SetMarkerColor(kGray+2);
      hMCSwappedplot->Draw("psame");
    }

  Float_t yield = mass->Integral(BINMIN,BINMAX)/BINWID;
  Float_t yieldErr = mass->Integral(BINMIN,BINMAX)/BINWID*mass->GetParError(0)/mass->GetParameter(0);
  cout<<mass->GetParameter(0)<<" "<<mass->Integral(BINMIN,BINMAX)<<endl;

  TLatex* tex;
  TLegend* leg = new TLegend(0.60,0.57,0.85,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f");
  leg->AddEntry(massSwap,"K-#pi swapped","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  tex = new TLatex(0.61,0.52,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.20,0.79,"|y| < 1.0");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();
  tex = new TLatex(0.20,0.84,Form("p_{T} > %.1f GeV/c",ptmin));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  c->SaveAs(Form("plots/pp/fitDstar5p/DMass_%s_%.0f.pdf",texData[isData].Data(),ptmin));

  return mass;
}
コード例 #30
0
ファイル: fitDstar.C プロジェクト: KiSooLee/DntupleRunII
void fitDstar(char *infname = "/data/wangj/MC2015/Dntuple/PbPb/ntD_Pythia8_5020GeV_DstarD0kpipipi_755patch3_GEN_SIM_PU_20151120_Dstar5p_tkPt2_20151126_Evt_All.root") {

    TFile *inf = new TFile(infname);
    //TTree *ntmix=(TTree*)inf->Get("ntDD0kpipipipi");
    TTree *ntmix=(TTree*)inf->Get("ntDD0kpipi");
    TH1D *h = new TH1D("h","",100,0.139,0.159);
    TCut cutTrk = "";//"trk1PixelHit>=2&&trk1StripHit>=10&&trk1Chi2ndf<5&&trk2PixelHit>=2&&trk2StripHit>=10&&trk2Chi2ndf<5";

    TCanvas *c = new TCanvas("c","",750,750);
    ntmix->Draw("Dmass-DtktkResmass>>h","abs(DtktkResmass-1.86486)<0.015&&Dpt>10&&(DsvpvDistance/DsvpvDisErr)>0.&&Dchi2cl>0.05&&Dalpha<1."&&cutTrk,"",10000000);
    //ntmix->Draw("Dmass-DtktkResmass>>h","abs(DtktkResmass-1.86486)<0.015&&Dpt>10&&Dtrk1Pt>0.5&&DRestrk1Pt>0.5&&DRestrk2Pt>0.5&&DRestrk3Pt>0.5&&DRestrk4Pt>0.5&&Dchi2cl>0.1&&Dalpha<0.2&&(DsvpvDistance/DsvpvDisErr)>.0"&&cutTrk,"",10000000);
    h->Sumw2();
    //   TF1 *f = new TF1("f","(1-exp(-(x-[8])/[0]))*(((x)/[8])**[1]+[2]*(((x)/[8])-1))*[3]+[4]*(TMath::Voigt(x-[5],[6],[7]))");
    TF1* f = new TF1("f","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*((1-[8])*TMath::Gaus(x,[6],[7])/(sqrt(2*3.14159)*[7])+[8]*TMath::Gaus(x,[6],[9])/(sqrt(2*3.14159)*[9]))",minmass3prong,maxmass3prong);
//   TF1 *f = new TF1("f","(1-exp(-(x-0.13957018)/[0]))*(((x)/0.13957018)**[1]+[2]*(((x)/0.13957018)-1))*[3]+[4]*(TMath::Gaus(x,[5],[6]))");
    //TF1 *f = new TF1("f","(1-exp(-(x-1.86486-0.13957018)/[0]))*(((x-1.86486)/0.13957018)**[1]+[2]*(((x-1.86486)/0.13957018)-1))*[3]+[4]*TMath::Gaus(x,[5],[6])");
    f->SetLineColor(4);
//   f->SetParameters(-2.3825e6,-7.99713e-1,-1.42957,-5.50069e10,5.33573,1.45491e-1,2.78677e-6,1.43145e-3,0.13957018);
//   f->SetParameters(-7.3e5,-2.2e1,5.24e-1,-7.18e9,2e2,1.45491e-1,9e-4,0.1,8e-4);
    f->SetParameters(0,0,0,0,0,2e2,1.45491e-1,9e-4,0.1,8e-4);
    f->FixParameter(9,15e-4);
    f->FixParameter(6,0.145491);
    f->FixParameter(7,8e-4);
    f->SetParLimits(8,0,1);
    h->Fit("f","LL");
    h->Fit("f","LL");
    h->Fit("f","LL","",0.142,0.147);
    f->ReleaseParameter(6);
    f->ReleaseParameter(7);
    f->ReleaseParameter(9);
    f->SetParLimits(7,1e-4,9e-4);
    f->SetParLimits(9,1e-4,9e-4);
    h->Fit("f","LL","",0.142,0.148);
    h->Fit("f","LL","",0.142,0.16);
    h->Fit("f","LL","",0.142,0.16);
    h->Fit("f","LL","",0.141,0.16);
    h->Fit("f","LL","",0.141,0.16);
    h->Fit("f","LL","",0.141,0.16);

    h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})");
    h->SetYTitle("Entries");
    h->SetStats(0);
    h->SetAxisRange(1,h->GetMaximum()*1.3,"Y");
    TF1 *f2 = (TF1*)f->Clone("f2");
    f2->SetParameter(5,0);
    f2->SetRange(0.141,0.16);
    TF1 *f3 = (TF1*)f->Clone("f3");
    f3->SetParameter(0,0);
    f3->SetParameter(1,0);
    f3->SetParameter(2,0);
    f3->SetParameter(3,0);
    f3->SetParameter(4,0);

    f->SetLineColor(4);
    f2->SetLineColor(4);
    f2->SetLineStyle(2);
    f3->SetLineStyle(2);
    f2->Draw("same");
    f3->SetLineColor(2);
    f3->SetFillStyle(3004);
    f3->SetFillColor(2);
    f3->Draw("same");

    c->SaveAs("canvasDstar.pdf");
}