예제 #1
0
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()));

}
예제 #2
0
//__________________________________________________________________________
void drawDum(float min, float max, double drawXLabel)
{

  TH1D *hdum = new TH1D("hdum","",20,0,1);
  hdum->SetMaximum(max);

  hdum->SetStats(0);

  if(drawXLabel) hdum->SetXTitle("A_{J} = (E_{T}^{j1}-E_{T}^{j2})/(E_{T}^{j1}+E_{T}^{j2})");
  hdum->GetXaxis()->SetLabelSize(20);
  hdum->GetXaxis()->SetLabelFont(43);
  hdum->GetXaxis()->SetTitleSize(22);
  hdum->GetXaxis()->SetTitleFont(43);
  hdum->GetXaxis()->SetTitleOffset(1.5);
  hdum->GetXaxis()->CenterTitle();

  hdum->GetXaxis()->SetNdivisions(905,true);

  hdum->SetYTitle("Ratio");

  hdum->GetYaxis()->SetLabelSize(20);
  hdum->GetYaxis()->SetLabelFont(43);
  hdum->GetYaxis()->SetTitleSize(20);
  hdum->GetYaxis()->SetTitleFont(43);
  hdum->GetYaxis()->SetTitleOffset(2.5);
  hdum->GetYaxis()->CenterTitle();

  hdum->SetAxisRange(0,0.2,"Y");

  hdum->Draw("");

}
예제 #3
0
bool DrawPileupCorr(Str jetAlgo) {
  JetCalibrationTool *theJES = new JetCalibrationTool(jetAlgo,_jesFile,false);
  bool residual = theJES->JetAreaJES();

  TH1D *temp = new TH1D("","",100,-5,5);
  temp->SetXTitle("Jet #eta"); temp->SetYTitle("Jet offset at "+GetConstScale(jetAlgo)+"-scale [GeV]");
  if (residual) temp->SetYTitle("Residual jet offset at "+GetConstScale(jetAlgo)+"-scale [GeV]");
  temp->SetMinimum(-20); temp->SetMaximum(15); temp->SetStats(0);
  if ( residual && theJES->ResidualOffsetCorr_Description() == "" ) return false;
  Can->Clear(); temp->Draw();
  for (int npv=0;npv<9;++npv) {
    double NPV=(npv%3)*10, mu=(npv/3)*10;
    if (NPV==0) NPV=1;
    Graph *g = new Graph();
    FormatGraph(g,npv);
    for (int ieta=-50;ieta<50;++ieta) {
      double eta=0.05 + 0.1*ieta;
      double O = residual ? theJES->GetResidualOffset(eta,mu,NPV)/1000 :
	theJES->GetOffset(eta,mu,NPV)/1000; // convert to GeV
      g->SetPoint(g->GetN(),eta,O);
    }
    if (npv<4) DrawLabel(Form("N_{PV} = %.0f, #LT#mu#GT = %.0f",NPV,mu),0.18,0.35-0.04*npv,npv);
    else DrawLabel(Form("N_{PV} = %.0f, #LT#mu#GT = %.0f",NPV,mu),0.48,0.35-0.04*(npv-4),npv);
    
    g->Draw("P");
  }
  tex->SetNDC(); tex->SetTextAlign(12);
  if (residual)
    tex->DrawLatex(0.18,0.975,theJES->ResidualOffsetCorr_Description());
  else 
    tex->DrawLatex(0.18,0.975,theJES->OffsetCorr_Description());
  tex->DrawLatex(0.18,0.9,GetJetDesc(jetAlgo));
  return true;
}
예제 #4
0
void RunTest(const char* name, int numentries, int BufferSize) {
   char title[200];
   sprintf(title, "%d events, 10 branches, 10 floats in brunch, Basket size = %d", numentries, BufferSize*sizeof(Float_t)*10);

   TH1D* histoRes = new TH1D(name, title, 10, 0.5, 10.5);
   histoRes->GetXaxis()->SetTitle("Number of active branches");
   histoRes->GetYaxis()->SetTitle("Real time (s)");
   histoRes->SetDirectory(0);
   histoRes->SetStats(kFALSE);
   ProduceTree("TreeFile.root","TestTree", numentries, 0, 10, 10, BufferSize);

   Float_t RealTime, CpuTime;
    
   for(int ActiveBranches=1;ActiveBranches<=10;ActiveBranches++) {
      ReadDummyTree();
      cout << "Buffer size = " << BufferSize*sizeof(Float_t)*10 << " ActiveBranches = " << ActiveBranches << endl;
      MakeDelay(10);
      TestTree("TreeFile.root","TestTree", 10, 10, ActiveBranches, &RealTime, &CpuTime);
      histoRes->SetBinContent(ActiveBranches, RealTime);
   } 
   
   TCanvas* c1 = new TCanvas(TString(name)+"_canvas", title);
   histoRes->Draw();
   c1->SaveAs(TString(name)+".gif");
}
void drawDum(float min, float max, double drawXLabel){

   TH1D *hdum = new  TH1D("h","",10,120,220);
  hdum->SetMaximum(max);

  hdum->SetStats(0);

  if(drawXLabel) hdum->SetXTitle("(p_{T}^{j1}-p_{T}^{j2})/(p_{T}^{j1}+p_{T}^{j2})");
  hdum->GetXaxis()->SetLabelSize(20);
  hdum->GetXaxis()->SetLabelFont(43);
  hdum->GetXaxis()->SetTitleSize(22);
  hdum->GetXaxis()->SetTitleFont(43);
  hdum->GetXaxis()->SetTitleOffset(1.5);
  hdum->GetXaxis()->CenterTitle();

  hdum->GetXaxis()->SetNdivisions(905,true);

  hdum->SetYTitle("Event Fraction");

  hdum->GetYaxis()->SetLabelSize(20);
  hdum->GetYaxis()->SetLabelFont(43);
  hdum->GetYaxis()->SetTitleSize(20);
  hdum->GetYaxis()->SetTitleFont(43);
  hdum->GetYaxis()->SetTitleOffset(2.5);
  hdum->GetYaxis()->CenterTitle();

  hdum->SetAxisRange(0,0.2,"Y");

  hdum->Draw("");

}
예제 #6
0
void RunTest(const char* name, const char* uselesstitle, int numentries, int BufferSize) {
   TString title;
   title += numentries;
   title.Append(" events, 10 branches, 10 floats in brunch, Basket size = ");
   title += ( BufferSize*10*10*4 );
   TH1D* histoRes = new TH1D(name, title, 10, 0.5, 10.5);
   histoRes->GetXaxis()->SetTitle("Number of active branches");
   histoRes->GetYaxis()->SetTitle("Real time (s)");
   histoRes->SetDirectory(0);
   histoRes->SetStats(kFALSE);
   ProduceTree("TreeFile.root","TestTree", numentries, 0, 10, 10, BufferSize);

   Float_t RealTime, CpuTime;
    
   for(int ActiveBranches=1;ActiveBranches<=10;ActiveBranches++) {
      PurgeMemory();  
      cout << "Buffer size = " << BufferSize*sizeof(Float_t)*10 << " ActiveBranches = " << ActiveBranches << endl;
      MakeDelay(5);
      TestTree("TreeFile.root","TestTree", 10, 10, ActiveBranches, RealTime, CpuTime);
      histoRes->SetBinContent(ActiveBranches, RealTime);
   } 
    
   TCanvas* c1 = new TCanvas(TString(name)+"_canvas",title);
   histoRes->Draw();
   c1->SaveAs(TString(name)+".gif");
}
예제 #7
0
void plotTurnOn(TTree* inttree, TString triggerpass, TString variable, TString varname, TString varlatex, Int_t BIN_NUM, Double_t BIN_MIN, Double_t BIN_MAX, TString addcut="")
{
  TLatex* tex = new TLatex(0.18,0.96,triggerpass);
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);

  TH1D* hinclusive = new TH1D(Form("hinclusive_%s_%s",triggerpass.Data(),varname.Data()),Form(";Matched reco D^{0} %s;Candidates",varlatex.Data()),BIN_NUM,BIN_MIN,BIN_MAX);
  inttree->Project(Form("hinclusive_%s_%s",triggerpass.Data(),varname.Data()),variable,Form("%s%s",prefilter.Data(),addcut.Data()));
  hinclusive->Sumw2();
  if(triggerpass=="HLT_DmesonTrackingGlobalPt8_Dpt20_v1"||triggerpass=="HLT_DmesonPPTrackingGlobal_Dpt20_v1")
    {
      TCanvas* chinclusive = new TCanvas(Form("chinclusive_%s",varname.Data()),"",500,500);
      hinclusive->Draw();
      hinclusive->SetStats(0);
      tex->Draw();
      if(isPbPb) chinclusive->SaveAs(Form("triggerturnonPlots/pthat%.0f/MBseed/pbpb/chinclusive_%s.pdf",pthat,varname.Data()));
      else chinclusive->SaveAs(Form("triggerturnonPlots/pthat%.0f/MBseed/pp/chinclusive_%s.pdf",pthat,varname.Data()));
    }
  TH2D* hempty = new TH2D(Form("hempty_%s_%s",triggerpass.Data(),varname.Data()),Form(";Matched reco D^{0} %s;Pass efficiency (ZB seed)",varlatex.Data()),BIN_NUM,BIN_MIN,BIN_MAX,10,0,1.2);
  hempty->SetStats(0);
  TH1D* hMBseed = new TH1D(Form("h%s_MBseed_%s",triggerpass.Data(),varname.Data()),"",BIN_NUM,BIN_MIN,BIN_MAX);
  inttree->Project(Form("h%s_MBseed_%s",triggerpass.Data(),varname.Data()),variable,Form("%s%s&&%s",prefilter.Data(),addcut.Data(),triggerpass.Data()));
  hMBseed->Sumw2();
  TEfficiency* pEffMBseed = new TEfficiency(*hMBseed,*hinclusive);
  TCanvas* cMBseed = new TCanvas(Form("c%s_MBseed_%s",triggerpass.Data(),varname.Data()),"",500,500);
  hempty->Draw();
  pEffMBseed->Draw("PSAME");
  tex->Draw();
  /*
  if(isPbPb) cMBseed->SaveAs(Form("triggerturnonPlots/pthat%.0f/MBseed/pbpb/c%s_MBseed_%s.pdf",pthat,triggerpass.Data(),varname.Data()));
  else cMBseed->SaveAs(Form("triggerturnonPlots/pthat%.0f/MBseed/pp/c%s_MBseed_%s.pdf",pthat,triggerpass.Data(),varname.Data()));
  */
  cMBseed->SaveAs(Form("triggerturnonPlots/pthat%.0f/ZBseed/pp/c%s_MBseed_%s.pdf",pthat,triggerpass.Data(),varname.Data()));
}
예제 #8
0
TH1D* CutFlow::hashErrors(AllSamples samples, Variable variable){
	TH1D * hashErrors = allMChisto(samples, variable);

	hashErrors->SetFillColor(kBlack);
	hashErrors->SetFillStyle(3354);
	hashErrors->SetMarkerSize(0.);
	hashErrors->SetStats(0);

	return hashErrors;
}
예제 #9
0
void nu_spect(const std::string& filename) {

  TFile* file = new TFile(filename.c_str(), "read");
  TTree* tree = NULL;
  file->GetObject("MARLEY_event_tree", tree);
  if (!tree) {
    std::cout << "MARLEY event tree not found" << '\n';
    return;
  }

  marley::Event* ev = new marley::Event;
  tree->SetBranchAddress("event", &ev);

  size_t num_events = tree->GetEntries();

  std::vector<double> E_vec;

  for (size_t i = 0; i < num_events; ++i) {

    tree->GetEntry(i);

    E_vec.push_back(ev->projectile().total_energy());

    if (i % 1000 == 0) std::cout << "Event " << i << '\n';
  }

  double E_max = -1e30;
  double E_min = 1e30;
  for (size_t k = 0; k < E_vec.size(); ++k) {
    double e = E_vec.at(k);
    if (e > E_max) E_max = e;
    else if (e < E_min) E_min = e;
  }

  TString title_str;

  TH1D* Es = new TH1D("nu_Es", "reacting neutrino spectrum", 100,
    E_max, E_min);

  for (size_t j = 0; j < E_vec.size(); ++j) {
    Es->Fill(E_vec.at(j));
  }

  TCanvas* c = new TCanvas;
  c->cd();

  gStyle->SetOptStat();

  Es->SetStats(true);
  Es->SetLineColor(kBlue);
  Es->SetLineWidth(2);
  Es->Draw();

  //c->SaveAs("nu_Es.pdf");
}
예제 #10
0
TH1D* getYield(TTree* nt, TString triggerpass, TString triggername, TString prescale, TString variable, TString varname, TString varlatex, Int_t BIN_NUM, Double_t BIN_MIN, Double_t BIN_MAX, TString addcut="")
{
  TH1D* hDistrib = new TH1D(Form("h%s_Distrib_%s",triggername.Data(),varname.Data()),Form(";D %s;Event",varlatex.Data()),BIN_NUM,BIN_MIN,BIN_MAX);
  nt->Project(Form("h%s_Distrib_%s",triggername.Data(),varname.Data()),Form("%s%s",variable.Data(),prescale.Data()),Form("%s%s%s",prefilter.Data(),addcut.Data(),triggerpass.Data()));
  hDistrib->Sumw2();
  TCanvas* cDistrib = new TCanvas(Form("c%s_Distrib_%s",triggername.Data(),varname.Data()),"",500,500);
  hDistrib->Draw();
  hDistrib->SetStats(0);
  if(isPbPb) cDistrib->SaveAs(Form("triggerturnonPlots/data/pbpb/c%s_Distrib_%s.pdf",triggername.Data(),varname.Data()));
  else cDistrib->SaveAs(Form("triggerturnonPlots/data/pp/c%s_Distrib_%s.pdf",triggername.Data(),varname.Data()));

  return hDistrib;
}
void savePlots2(const std::string& canvasName, TH1D& dataPlot, TH1D& fitPlot,
		TH1D& signalPlot, TH1D& bkgPlot) {
  TCanvas c(canvasName.c_str(), canvasName.c_str()) ;
  TPad mainPad("mainPad", "mainPad", 0., 0.2, 1., 1.) ;
  mainPad.Draw() ;
  TPad pullPad("pullPad", "pullPad", 0., 0., 1., 0.2) ;
  pullPad.Draw() ;

  mainPad.cd() ;
  dataPlot.SetStats(true) ;
  //dataPlot.SetOptStat(111111111);
  dataPlot.SetLineWidth(2) ;
  dataPlot.Draw() ;
  fitPlot.SetLineWidth(2) ;
  fitPlot.SetLineColor(kBlue) ;
  fitPlot.Draw("same") ;
  signalPlot.SetLineWidth(2) ;
  signalPlot.SetLineColor(kGreen) ;
  signalPlot.Draw("same") ;
  bkgPlot.SetLineColor(kRed) ;
  bkgPlot.SetLineWidth(2) ;
  bkgPlot.Draw("same") ;

  TLegend leg(0.6, 0.7, 0.9, 0.9) ;
  leg.AddEntry(&dataPlot, "Data") ;
  leg.AddEntry(&fitPlot, "Fit") ;
  leg.AddEntry(&signalPlot, "Signal") ;
  leg.AddEntry(&bkgPlot, "Background") ;
  leg.SetFillStyle(0) ;
  leg.SetBorderSize(0) ;
  leg.Draw() ;

  pullPad.cd() ;
  pullPad.SetGridy() ;
  TH1D* h_residuals(NULL), *h_pulls(NULL), *h_pullDistribution(NULL) ;
  FitterTools::makePullPlot(dataPlot, fitPlot, h_residuals, h_pulls, h_pullDistribution) ;
  h_pulls->Draw() ;

  c.Write() ;

  h_pulls->Write() ;
  delete h_pulls ;
  h_residuals->Write() ;
  delete h_residuals ;
  h_pullDistribution->Write() ;
  delete h_pullDistribution ;

  dataPlot.Write() ;
  fitPlot.Write() ;
}
TH1D* readHist(TString nameHist,TString nameFile, int rebin)
{
 TFile* file = new TFile(nameFile);

 TH1D* hist = (TH1D*)file->Get(nameHist);
 hist->GetSumw2();
 // hist->SetLineWidth(2);
 if(rebin>0) hist->Rebin(rebin);
 hist->GetXaxis()->SetTitleSize(.055);
 hist->GetYaxis()->SetTitleSize(.055);
 hist->GetXaxis()->SetLabelSize(.05);
 hist->GetYaxis()->SetLabelSize(.05);
 hist->SetStats(kFALSE);
 return hist;
}
예제 #13
0
TH1D* GetDummyHist(Float_t xmax, Float_t min, Float_t max,Char_t *xttl,Char_t *yttl) {

    TH1D *dum;
    dum = new TH1D("dum","",100,0.0,xmax);
    //dum = new TH1D("dum","",100,0.2,xmax);

    dum->SetMinimum(min);
    dum->SetMaximum(max);
    dum->SetStats(0);

    dum->GetYaxis()->SetTitle(yttl);
    dum->GetYaxis()->CenterTitle();
    dum->GetXaxis()->SetTitle(xttl);
    dum->GetXaxis()->CenterTitle();

    return dum;

}
예제 #14
0
파일: momres.C 프로젝트: CmsHI/CVS_edwenger
TH1D* momResHist(TFile* f, int i) {

  Double_t xbins[33] = {0,0.2,0.4,0.6,0.8,
			1.0,1.6,2.2,2.8,3.4,
			4.4,5.4,6.0,8.0,10.0,
			12.0,14.0,18.0,22.0,26.0,
			30.0,36.0,42.0,50.0,55.0,
			60.0,70.0,80.0,100.0,120.0,
			140.0,160.0,200.0};

  TH3F *hRes3D = (TH3F*) f->Get("trkEffAnalyzer/hresStoR3D");
  
  double feta = 2.4;
  int binMaxEta = hRes3D->GetXaxis()->FindBin(feta);
  int binMinEta = hRes3D->GetXaxis()->FindBin(-1.0*feta);

  hRes3D->GetXaxis()->SetRange(binMinEta,binMaxEta);
  TH2D *hRes2D = (TH2D*) hRes3D->Project3D("zy");  // zy: rec-> y axis, sim -> x axis
  hRes2D->SetName("hRes2D");

  hRes2D->FitSlicesY(0,0,-1,10);

  TH1D *h1 = (TH1D*)gDirectory->Get("hRes2D_1");
  TH1D *h2 = (TH1D*)gDirectory->Get("hRes2D_2");

  h1->Rebin(32,Form("h1new%d",i),xbins);
  h2->Rebin(32,Form("h2new%d",i),xbins);
  TH1D* h1new = (TH1D*) gDirectory->Get(Form("h1new%d",i));
  TH1D* h2new = (TH1D*) gDirectory->Get(Form("h2new%d",i));


  TH1D *momres = (TH1D*) h2new->Clone("momres");
  momres->SetName(Form("momres_%d",i));
  momres->SetMaximum(0.15); momres->SetMinimum(0.0);
  momres->SetTitle("Momentum resolution;p_{T} [GeV/c]");
  momres->SetStats(0);
  momres->SetMarkerStyle(20);
  momres->Divide(h1new);

  return momres;

}
예제 #15
0
TCanvas* Com(TString plot,TString plot_dir,UInt_t rbin, TString xtitle, Double_t max, TString title){
  gROOT->SetStyle("Plain");
  gStyle->SetTitleFontSize(0.07);
 TH1D *Sig = ((TH1D*)Sig->Get(plot_dir+"/"+plot))->Clone();
 TH1D *Bkgd= ((TH1D*)Bkgd->Get(plot_dir+"/"+plot))->Clone();
 Sig->Rebin(rbin);
 Bkgd->Rebin(rbin);
 Sig->Scale(1/(Sig->Integral()));
 Bkgd->Scale(1/(Bkgd->Integral()));
 //TLine *li =new TLine(0.55,0.,0.55,100000);
TCanvas* c = new TCanvas(plot_dir+plot,plot_dir+plot);
 c->SetLogy();

 TLegend *leg = new TLegend(0.5,0.8,0.99,0.99);
 leg->SetFillColor(0);
 leg->AddEntry(Sig,"Selected events","L");
 leg->AddEntry(Bkgd,"Anti-selected events","L");
 Sig->SetLineColor(kRed);
 Sig->SetLineWidth(2);
 Bkgd->SetLineColor(kBlue);
 Bkgd->SetLineWidth(2);
 Sig->Draw("EHIST");
 Bkgd->Draw("HISTSAME");
 leg->Draw("SAME");
 //      li->Draw("SAME");
 Sig->SetTitle(title);

Sig->SetStats(kFALSE);
 Sig->GetXaxis()->SetTitle(xtitle);
 if (max == 999999){

 }
 else{
   Sig->GetXaxis()->SetRangeUser(0.2,max);}
 Sig->GetYaxis()->SetTitle("");
 c->Update();
 c->SaveAs(saving+"IDinv_Delta_"+plot_dir+plot+".png");
 return c;


}
예제 #16
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;
}
예제 #17
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;
}
예제 #18
0
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;
}
예제 #19
0
void drawLatinoTree(const TString inputFileName = "giveMeMyMoney.root") {


  TH1::SetDefaultSumw2();

  //
  // Settings
  //
  gStyle->SetOptStat(0);
  //
  Int_t NVTXBINS = 30;
  //
  // Setup input ntuple
  //
  TFile* inputFile = new TFile(inputFileName);
  TTree* inputTree = (TTree*)inputFile->Get("latino");

  TString path = Form("Results");
  gSystem->mkdir(path, kTRUE);
  TFile* outFile = new TFile(path + "/out.root", "recreate");

  //
  // Declare variables to read in ntuple
  //
  Int_t nEvents;
  Float_t nvtx;
  Float_t metPfType1, metPfType1Phi, corrMetPfType1, corrMetPfType1Phi;
  Float_t metPfRaw, metPfRawPhi, corrMetPfRaw, corrMetPfRawPhi;

  //TVector2 *t2_slimMet=0, *t2_slimMetTxy=0;

  inputTree->SetBranchAddress("nvtx",         &nvtx);        // number of vertices
  inputTree->SetBranchAddress("std_vector_lepton_pt", &std_vector_lepton_pt);
  inputTree->SetBranchAddress("std_vector_lepton_flavour", &std_vector_lepton_flavour);
  inputTree->SetBranchAddress("std_vector_lepton_eta", &std_vector_lepton_eta);
  inputTree->SetBranchAddress("std_vector_lepton_phi", &std_vector_lepton_phi);
  inputTree->SetBranchAddress("metPfType1",       &metPfType1);
  inputTree->SetBranchAddress("metPfType1Phi",    &metPfType1Phi);
  inputTree->SetBranchAddress("corrMetPfType1",   &corrMetPfType1);
  inputTree->SetBranchAddress("corrMetPfType1Phi",   &corrMetPfType1Phi);
           
  inputTree->SetBranchAddress("metPfRaw",       &metPfRaw);
  inputTree->SetBranchAddress("metPfRawPhi",    &metPfRawPhi);
  inputTree->SetBranchAddress("corrMetPfRaw",   &corrMetPfRaw);
  inputTree->SetBranchAddress("corrMetPfRawPhi",   &corrMetPfRawPhi);
  //
  // Declare histograms
  //
  TH1D *hSlimMet  = new TH1D("hSlimMet","",100,0,150);
        hSlimMet->SetStats(0);
        hSlimMet->SetLineColor(1);
  TH1D *hSlimMetTxy  = new TH1D("hSlimMetTxy","",100,0,150);
        hSlimMetTxy->SetStats(0);
        hSlimMetTxy->SetLineColor(2);

  TH1D *hMetDiff  = new TH1D("hMetDiff","",100,-15,15);
        hMetDiff->SetStats(0);
        hMetDiff->GetXaxis()->SetTitle("Corr. - PfType1Met");
  TH1D *hMetPull  = new TH1D("hMetPull","",100,-1,1);
        hMetPull->SetStats(0);
        hMetPull->GetXaxis()->SetTitle("[Corr. - PfType1Met]/PfType1Met");
  TH1D *hPhiDiff  = new TH1D("hPhiDiff","",100,-1,1);
        hPhiDiff->SetStats(0);
        hPhiDiff->GetXaxis()->SetTitle("Corr.Phi - PfType1Phi");

  TH1D *hPhi = new TH1D("hPhi","",20,-3.5,3.5);
        hPhi->SetStats(0);
        hPhi->SetLineColor(1);
  TH1D *hPhiTxy  = new TH1D("hPhiTxy","",20,-3.5,3.5);
        hPhiTxy->SetStats(0);
        hPhiTxy->SetLineColor(4);

  TH1D *hMetRaw  = new TH1D("hMetRaw","",100,0,150);
        hMetRaw->SetStats(0);
        hMetRaw->SetLineColor(1);
  TH1D *hMetRawTxy  = new TH1D("hMetRawTxy","",100,0,150);
        hMetRawTxy->SetStats(0);
        hMetRawTxy->SetLineColor(2);

  TH1D *hMetRawDiff  = new TH1D("hMetRawDiff","",100,-15,15);
        hMetRawDiff->SetStats(0);
        hMetRawDiff->GetXaxis()->SetTitle("Corr. - MetPfRaw");
  TH1D *hMetRawPull  = new TH1D("hMetRawPull","",100,-1,1);
        hMetRawPull->SetStats(0);
        hMetRawPull->GetXaxis()->SetTitle("[Corr. - MetPfRaw]/MetPfRaw");
  TH1D *hRawPhiDiff  = new TH1D("hRawPhiDiff","",100,-1,1);
        hRawPhiDiff->SetStats(0);
        hRawPhiDiff->GetXaxis()->SetTitle("Corr.Phi - PfRawPhi");

  TH1D *hRawPhi = new TH1D("hRawPhi","",20,-3.5,3.5);
        hRawPhi->SetStats(0);
        hRawPhi->SetLineColor(1);
  TH1D *hRawPhiTxy  = new TH1D("hRawPhiTxy","",20,-3.5,3.5);
        hRawPhiTxy->SetStats(0);
        hRawPhiTxy->SetLineColor(4);


  TH1D *hPhi_VtxRange[4];
  TH1D *hPhiTxy_VtxRange[4];
  for(int i=0;i<4;i++)
  {
    TString Tname = Form("hPhi_VtxRange_%d", i);
    hPhi_VtxRange[i]     = new TH1D(Tname,"",20,-3.5,3.5);
    hPhiTxy_VtxRange[i]  = new TH1D(Tname,"",20,-3.5,3.5);
    hPhi_VtxRange[i]->SetStats(0);
    hPhi_VtxRange[i]->SetLineColor(1);
    hPhiTxy_VtxRange[i]->SetStats(0);
    hPhiTxy_VtxRange[i]->SetLineColor(4);
  }

  TH1D *hPhi_NoCut = new TH1D("hPhi_NoCut","",20,-3.5,3.5);
        hPhi_NoCut->SetStats(0);
        hPhi_NoCut->SetLineColor(1);
  TH1D *hPhiTxy_NoCut  = new TH1D("hPhiTxy_NoCut","",20,-3.5,3.5);
        hPhiTxy_NoCut->SetStats(0);
        hPhiTxy_NoCut->SetLineColor(4);

  TH2D *hMETnVtx_x = new TH2D("hMETnVtx_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150);
        hMETnVtx_x->GetXaxis()->SetTitle("Number of vertices");
        hMETnVtx_x->GetYaxis()->SetTitle("MET_{x} [GeV]");
  TH2D *hMETnVtx_y = new TH2D("hMETnVtx_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150);
        hMETnVtx_y->GetXaxis()->SetTitle("Number of vertices");
        hMETnVtx_y->GetYaxis()->SetTitle("MET_{y} [GeV]");
  TH2D *hMETnVtx_Txy_x = new TH2D("hMETnVtx_Txy_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150);
        hMETnVtx_Txy_x->GetXaxis()->SetTitle("Number of vertices");
        hMETnVtx_Txy_x->GetYaxis()->SetTitle("MET_{x} [GeV]");
  TH2D *hMETnVtx_Txy_y = new TH2D("hMETnVtx_Txy_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150);
        hMETnVtx_Txy_y->GetXaxis()->SetTitle("Number of vertices");
        hMETnVtx_Txy_y->GetYaxis()->SetTitle("MET_{y} [GeV]");

  TH1D *hRawPhi_NoCut = new TH1D("hRawPhi_NoCut","",20,-3.5,3.5);
        hRawPhi_NoCut->SetStats(0);
        hRawPhi_NoCut->SetLineColor(1);
  TH1D *hRawPhiTxy_NoCut  = new TH1D("hRawPhiTxy_NoCut","",20,-3.5,3.5);
        hRawPhiTxy_NoCut->SetStats(0);
        hRawPhiTxy_NoCut->SetLineColor(4);

  TH2D *hMETRawNvtx_x = new TH2D("hMETRawNvtx_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150);
        hMETRawNvtx_x->GetXaxis()->SetTitle("Number of vertices");
        hMETRawNvtx_x->GetYaxis()->SetTitle("MET_{x} [GeV]");
  TH2D *hMETRawNvtx_y = new TH2D("hMETRawNvtx_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150);
        hMETRawNvtx_y->GetXaxis()->SetTitle("Number of vertices");
        hMETRawNvtx_y->GetYaxis()->SetTitle("MET_{y} [GeV]");
  TH2D *hMETRawNvtx_Txy_x = new TH2D("hMETRawNvtx_Txy_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150);
        hMETRawNvtx_Txy_x->GetXaxis()->SetTitle("Number of vertices");
        hMETRawNvtx_Txy_x->GetYaxis()->SetTitle("MET_{x} [GeV]");
  TH2D *hMETRawNvtx_Txy_y = new TH2D("hMETRawNvtx_Txy_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150);
        hMETRawNvtx_Txy_y->GetXaxis()->SetTitle("Number of vertices");
        hMETRawNvtx_Txy_y->GetYaxis()->SetTitle("MET_{y} [GeV]");

  Int_t totalEvents=0;

  double phi;
  int ttNtry = inputTree->GetEntries();
  for(int jentry=0; jentry<ttNtry; jentry++) {
    inputTree->GetEntry(jentry);
    totalEvents += nEvents;

    hPhi_NoCut->Fill(metPfType1Phi);
    hPhiTxy_NoCut->Fill(corrMetPfType1Phi);
    hRawPhi_NoCut->Fill(metPfRawPhi);
    hRawPhiTxy_NoCut->Fill(corrMetPfRawPhi);

    if (std_vector_lepton_pt->size() < 2) continue;
    if( (*std_vector_lepton_flavour)[0]*(*std_vector_lepton_flavour)[1] !=-13*13) continue;
    double pt1=(*std_vector_lepton_pt)[0];
    double pt2=(*std_vector_lepton_pt)[1];
    double eta1=(*std_vector_lepton_eta)[0];
    double eta2=(*std_vector_lepton_eta)[1];
    double phi1=(*std_vector_lepton_phi)[0];
    double phi2=(*std_vector_lepton_phi)[1];
    if ( pt1< 20) continue;
    if ( pt2 < 10) continue;
    //TLorentzVector a, b;
    //a.SetPtEtaPhiM(pt1,eta1,phi1,0.1);
    //b.SetPtEtaPhiM(pt2,eta2,phi2,0.1);
    //double zmass = (a+b).M();
    //if(fabs(zmass-91.2)>15 ) continue;


    if( metPfType1 < 20) continue;
    //if( metPfType1 > 30) continue;
    //
    // Fill histograms
    //
    hMetDiff->Fill(corrMetPfType1 - metPfType1);
    hMetPull->Fill( (corrMetPfType1 - metPfType1)/metPfType1 );
    hPhiDiff->Fill(corrMetPfType1Phi - metPfType1Phi);
    hMETnVtx_x->Fill(nvtx,metPfType1*TMath::Cos(metPfType1Phi));
    hMETnVtx_y->Fill(nvtx,metPfType1*TMath::Sin(metPfType1Phi));
    hMETnVtx_Txy_x->Fill(nvtx,corrMetPfType1*TMath::Cos(corrMetPfType1Phi));
    hMETnVtx_Txy_y->Fill(nvtx,corrMetPfType1*TMath::Sin(corrMetPfType1Phi));

    hSlimMet      ->Fill(metPfType1);
    hSlimMetTxy   ->Fill(corrMetPfType1);

    hPhi->Fill(metPfType1Phi);
    hPhiTxy->Fill(corrMetPfType1Phi);

    hMetRawDiff->Fill(corrMetPfRaw - metPfRaw);
    hMetRawPull->Fill( (corrMetPfRaw - metPfRaw)/metPfRaw);
    hRawPhiDiff->Fill(corrMetPfRawPhi - metPfRawPhi);
    hMETRawNvtx_x->Fill(nvtx,metPfRaw*TMath::Cos(metPfRawPhi));
    hMETRawNvtx_y->Fill(nvtx,metPfRaw*TMath::Sin(metPfRawPhi));
    hMETRawNvtx_Txy_x->Fill(nvtx,corrMetPfRaw*TMath::Cos(corrMetPfRawPhi));
    hMETRawNvtx_Txy_y->Fill(nvtx,corrMetPfRaw*TMath::Sin(corrMetPfRawPhi));

    hMetRaw      ->Fill(metPfRaw);
    hMetRawTxy   ->Fill(corrMetPfRaw);

    hRawPhi->Fill(metPfRawPhi);
    hRawPhiTxy->Fill(corrMetPfRawPhi);


    if(nvtx < 5)
    {
      hPhi_VtxRange[0]->Fill(metPfType1Phi);
      hPhiTxy_VtxRange[0]->Fill(corrMetPfType1Phi);
    }else if(nvtx >=5 && nvtx <15){
      hPhi_VtxRange[1]->Fill(metPfType1Phi);
      hPhiTxy_VtxRange[1]->Fill(corrMetPfType1Phi);
    }else if(nvtx >=15 && nvtx <25){
      hPhi_VtxRange[2]->Fill(metPfType1Phi);
      hPhiTxy_VtxRange[2]->Fill(corrMetPfType1Phi);
    }else if(nvtx >=25 ){
      hPhi_VtxRange[3]->Fill(metPfType1Phi);
      hPhiTxy_VtxRange[3]->Fill(corrMetPfType1Phi);
    }

  }

  cout << "totalEvents is " << totalEvents << endl;

  // Loop through nVtx bins and find the mean value of metx and mety in each bin
  // Plot nVtx v. mean values of metx/mety in a separate histogram (1 for metx and 1 for mety)
  TH1D* hmetx_proj = new TH1D();
  TH1D* hmety_proj = new TH1D();
  Double_t meanmetx, meanmety;

  TH2D* hMEtMeanVtx_x = new TH2D("hMEtMeanVtx_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15);
        hMEtMeanVtx_x->GetXaxis()->SetTitle("Number of vertices");
        hMEtMeanVtx_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]");
  TH2D* hMEtMeanVtx_y = new TH2D("hMEtMeanVtx_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15);
        hMEtMeanVtx_y->GetXaxis()->SetTitle("Number of vertices");
        hMEtMeanVtx_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]");

  TH2D* hMEtMeanVtx_Txy_x = new TH2D("hMEtMeanVtx_Txy_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15);
        hMEtMeanVtx_Txy_x->GetXaxis()->SetTitle("Number of vertices");
        hMEtMeanVtx_Txy_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]");
  TH2D* hMEtMeanVtx_Txy_y = new TH2D("hMEtMeanVtx_Txy_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15);
        hMEtMeanVtx_Txy_y->GetXaxis()->SetTitle("Number of vertices");
        hMEtMeanVtx_Txy_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]");


  for(int jbin=1;jbin<hMEtMeanVtx_x->GetNbinsX()+1;jbin++) {
    hmetx_proj = hMETnVtx_x->ProjectionY("metx_proj",jbin,jbin+1,"");
    hmety_proj = hMETnVtx_y->ProjectionY("mety_proj",jbin,jbin+1,"");
    meanmetx = hmetx_proj->GetMean();
    meanmety = hmety_proj->GetMean();
    hMEtMeanVtx_x->Fill(jbin,meanmetx);
    hMEtMeanVtx_y->Fill(jbin,meanmety);

    hmetx_proj = hMETnVtx_Txy_x->ProjectionY("metx_proj",jbin,jbin+1,"");
    hmety_proj = hMETnVtx_Txy_y->ProjectionY("mety_proj",jbin,jbin+1,"");
    meanmetx = hmetx_proj->GetMean();
    meanmety = hmety_proj->GetMean();
    hMEtMeanVtx_Txy_x->Fill(jbin,meanmetx);
    hMEtMeanVtx_Txy_y->Fill(jbin,meanmety);
  }

  TH2D* hMEtRawMeanVtx_x = new TH2D("hMEtRawMeanVtx_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15);
        hMEtRawMeanVtx_x->GetXaxis()->SetTitle("Number of vertices");
        hMEtRawMeanVtx_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]");
  TH2D* hMEtRawMeanVtx_y = new TH2D("hMEtRawMeanVtx_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15);
        hMEtRawMeanVtx_y->GetXaxis()->SetTitle("Number of vertices");
        hMEtRawMeanVtx_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]");

  TH2D* hMEtRawMeanVtx_Txy_x = new TH2D("hMEtRawMeanVtx_Txy_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15);
        hMEtRawMeanVtx_Txy_x->GetXaxis()->SetTitle("Number of vertices");
        hMEtRawMeanVtx_Txy_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]");
  TH2D* hMEtRawMeanVtx_Txy_y = new TH2D("hMEtRawMeanVtx_Txy_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15);
        hMEtRawMeanVtx_Txy_y->GetXaxis()->SetTitle("Number of vertices");
        hMEtRawMeanVtx_Txy_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]");


  for(int jbin=1;jbin<hMEtRawMeanVtx_x->GetNbinsX()+1;jbin++) {
    hmetx_proj = hMETRawNvtx_x->ProjectionY("metx_proj",jbin,jbin+1,"");
    hmety_proj = hMETRawNvtx_y->ProjectionY("mety_proj",jbin,jbin+1,"");
    meanmetx = hmetx_proj->GetMean();
    meanmety = hmety_proj->GetMean();
    hMEtRawMeanVtx_x->Fill(jbin,meanmetx);
    hMEtRawMeanVtx_y->Fill(jbin,meanmety);

    hmetx_proj = hMETRawNvtx_Txy_x->ProjectionY("metx_proj",jbin,jbin+1,"");
    hmety_proj = hMETRawNvtx_Txy_y->ProjectionY("mety_proj",jbin,jbin+1,"");
    meanmetx = hmetx_proj->GetMean();
    meanmety = hmety_proj->GetMean();
    hMEtRawMeanVtx_Txy_x->Fill(jbin,meanmetx);
    hMEtRawMeanVtx_Txy_y->Fill(jbin,meanmety);
  }

  //
  // Save plots
  //
  TLegend *leg_Vtx_x = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC");
  leg_Vtx_x->SetTextFont(62);
  leg_Vtx_x->SetTextSize(0.03330866);
  leg_Vtx_x->SetLineColor(1);
  leg_Vtx_x->SetLineStyle(1);
  leg_Vtx_x->SetLineWidth(1);
  leg_Vtx_x->SetFillColor(0);
  leg_Vtx_x->SetFillStyle(1001);
  leg_Vtx_x->SetBorderSize(0);
  leg_Vtx_x->AddEntry(hMEtMeanVtx_x,"Type1PfMet","p");
  leg_Vtx_x->AddEntry(hMEtMeanVtx_Txy_x,"Type1PfMet + Txy","p");


  TLine *metZeroLine=new TLine(0,0,NVTXBINS,0);
  metZeroLine->SetLineColor(kRed);
  metZeroLine->SetLineStyle(2);
  metZeroLine->SetLineWidth(2);

  TCanvas* tc_metVtx_x = new TCanvas();
  tc_metVtx_x->cd();
  hMEtMeanVtx_x->SetMarkerStyle(24);
  hMEtMeanVtx_x->SetMarkerSize(1);
  hMEtMeanVtx_x->SetMarkerColor(kRed);
  hMEtMeanVtx_x->Draw("p0");
  //hSlimMet->Draw("p9");
  hMEtMeanVtx_Txy_x->SetMarkerStyle(26);
  hMEtMeanVtx_Txy_x->SetMarkerSize(1);
  hMEtMeanVtx_Txy_x->SetMarkerColor(kBlue);
  hMEtMeanVtx_Txy_x->Draw("samep0");
  metZeroLine->Draw("same");
  leg_Vtx_x->Draw("same");
  tc_metVtx_x->Print(path+"/MetvsVtx_x.png");
  tc_metVtx_x->Print(path+"/MetvsVtx_x.pdf");

  TLegend *lRa_Vtx_x = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC");
  lRa_Vtx_x->SetTextFont(62);
  lRa_Vtx_x->SetTextSize(0.03330866);
  lRa_Vtx_x->SetLineColor(1);
  lRa_Vtx_x->SetLineStyle(1);
  lRa_Vtx_x->SetLineWidth(1);
  lRa_Vtx_x->SetFillColor(0);
  lRa_Vtx_x->SetFillStyle(1001);
  lRa_Vtx_x->SetBorderSize(0);
  lRa_Vtx_x->AddEntry(hMEtRawMeanVtx_x,"MetPfRaw","p");
  lRa_Vtx_x->AddEntry(hMEtRawMeanVtx_Txy_x,"MetPfRaw + Txy","p");



  TCanvas* tc_metRawVtx_x = new TCanvas();
  tc_metRawVtx_x->cd();
  hMEtRawMeanVtx_x->SetMarkerStyle(24);
  hMEtRawMeanVtx_x->SetMarkerSize(1);
  hMEtRawMeanVtx_x->SetMarkerColor(kRed);
  hMEtRawMeanVtx_x->Draw("p0");
  //hSlimMet->Draw("p9");
  hMEtRawMeanVtx_Txy_x->SetMarkerStyle(26);
  hMEtRawMeanVtx_Txy_x->SetMarkerSize(1);
  hMEtRawMeanVtx_Txy_x->SetMarkerColor(kBlue);
  hMEtRawMeanVtx_Txy_x->Draw("samep0");
  metZeroLine->Draw("same");
  lRa_Vtx_x->Draw("same");
  tc_metRawVtx_x->Print(path+"/MetRawvsVtx_x.png");
  tc_metRawVtx_x->Print(path+"/MetRawvsVtx_x.pdf");

  //-------------------
  // Met vs Vtx y-axis
  //-------------------
  TLegend *leg_Vtx_y = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC");
  leg_Vtx_y->SetTextFont(62);
  leg_Vtx_y->SetTextSize(0.03330866);
  leg_Vtx_y->SetLineColor(1);
  leg_Vtx_y->SetLineStyle(1);
  leg_Vtx_y->SetLineWidth(1);
  leg_Vtx_y->SetFillColor(0);
  leg_Vtx_y->SetFillStyle(1001);
  leg_Vtx_y->SetBorderSize(0);
  leg_Vtx_y->AddEntry(hMEtMeanVtx_y,"Type1PfMet","p");
  leg_Vtx_y->AddEntry(hMEtMeanVtx_Txy_y,"Type1PfMet + Txy","p");


  TCanvas* tc_metVtx_y = new TCanvas();
  tc_metVtx_y->cd();
  hMEtMeanVtx_y->SetMarkerStyle(24);
  hMEtMeanVtx_y->SetMarkerSize(1);
  hMEtMeanVtx_y->SetMarkerColor(kRed);
  hMEtMeanVtx_y->Draw("p0");
  //hSlimMet->Draw("p9");
  hMEtMeanVtx_Txy_y->SetMarkerStyle(26);
  hMEtMeanVtx_Txy_y->SetMarkerSize(1);
  hMEtMeanVtx_Txy_y->SetMarkerColor(kBlue);
  hMEtMeanVtx_Txy_y->Draw("same");
  metZeroLine->Draw("same");
  leg_Vtx_y->Draw("same");
  tc_metVtx_y->Print(path+"/MetvsVtx_y.png");
  tc_metVtx_y->Print(path+"/MetvsVtx_y.pdf");

  TLegend *lRa_Vtx_y = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC");
  lRa_Vtx_y->SetTextFont(62);
  lRa_Vtx_y->SetTextSize(0.03330866);
  lRa_Vtx_y->SetLineColor(1);
  lRa_Vtx_y->SetLineStyle(1);
  lRa_Vtx_y->SetLineWidth(1);
  lRa_Vtx_y->SetFillColor(0);
  lRa_Vtx_y->SetFillStyle(1001);
  lRa_Vtx_y->SetBorderSize(0);
  lRa_Vtx_y->AddEntry(hMEtRawMeanVtx_y,"MetPfRaw","p");
  lRa_Vtx_y->AddEntry(hMEtRawMeanVtx_Txy_y,"MetPfRaw + Txy","p");


  TCanvas* tc_metRawVtx_y = new TCanvas();
  tc_metRawVtx_y->cd();
  hMEtRawMeanVtx_y->SetMarkerStyle(24);
  hMEtRawMeanVtx_y->SetMarkerSize(1);
  hMEtRawMeanVtx_y->SetMarkerColor(kRed);
  hMEtRawMeanVtx_y->Draw("p0");
  //hSlimMet->Draw("p9");
  hMEtRawMeanVtx_Txy_y->SetMarkerStyle(26);
  hMEtRawMeanVtx_Txy_y->SetMarkerSize(1);
  hMEtRawMeanVtx_Txy_y->SetMarkerColor(kBlue);
  hMEtRawMeanVtx_Txy_y->Draw("same");
  metZeroLine->Draw("same");
  lRa_Vtx_y->Draw("same");
  tc_metRawVtx_y->Print(path+"/MetRawvsVtx_y.png");
  tc_metRawVtx_y->Print(path+"/MetRawvsVtx_y.pdf");
  //---------------------
  // phi distribution
  //---------------------
  TCanvas* tc_phi = new TCanvas();
  tc_phi->cd();
  hPhi->SetLineColor(kRed);
  hPhi->SetLineWidth(2);
  hPhi->Draw("");
  hPhiTxy->SetLineColor(kBlue);
  hPhiTxy->SetLineWidth(2);
  hPhiTxy->Draw("same");
  TLegend *leg_Phi = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC");
  leg_Phi->SetTextFont(62);
  leg_Phi->SetTextSize(0.03330866);
  leg_Phi->SetLineColor(1);
  leg_Phi->SetLineStyle(1);
  leg_Phi->SetLineWidth(1);
  leg_Phi->SetFillColor(0);
  leg_Phi->SetFillStyle(1001);
  leg_Phi->SetBorderSize(0);
  leg_Phi->AddEntry(hPhi,"Type1PfMet Phi","l");
  leg_Phi->AddEntry(hPhiTxy,"corrected Phi","l");
  leg_Phi->Draw("same");
  tc_phi->Print(path+"/phi.png");
  tc_phi->Print(path+"/phi.pdf");


  TCanvas* tc_RawPhi = new TCanvas();
  tc_RawPhi->cd();
  hRawPhi->SetLineColor(kRed);
  hRawPhi->SetLineWidth(2);
  hRawPhi->Draw("");
  hRawPhiTxy->SetLineColor(kBlue);
  hRawPhiTxy->SetLineWidth(2);
  hRawPhiTxy->Draw("same");
  TLegend *lRa_Phi = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC");
  lRa_Phi->SetTextFont(62);
  lRa_Phi->SetTextSize(0.03330866);
  lRa_Phi->SetLineColor(1);
  lRa_Phi->SetLineStyle(1);
  lRa_Phi->SetLineWidth(1);
  lRa_Phi->SetFillColor(0);
  lRa_Phi->SetFillStyle(1001);
  lRa_Phi->SetBorderSize(0);
  lRa_Phi->AddEntry(hRawPhi,"MetPfRaw Phi","l");
  lRa_Phi->AddEntry(hRawPhiTxy,"corrected Phi","l");
  lRa_Phi->Draw("same");
  tc_RawPhi->Print(path+"/RawPhi.png");
  tc_RawPhi->Print(path+"/RawPhi.pdf");

  TCanvas *c_phi[4];
  TLegend *l_Phi[4];
  for(int i=0;i<4;i++){

    //TString Cname = Form("C_Phi_VtxRange_%d", i);
    c_phi[i] = new TCanvas();
    c_phi[i]->cd();
    hPhi_VtxRange[i]->SetLineColor(kRed);
    hPhi_VtxRange[i]->SetLineWidth(2);
    hPhi_VtxRange[i]->Draw("");
    hPhiTxy_VtxRange[i]->SetLineColor(kBlue);
    hPhiTxy_VtxRange[i]->SetLineWidth(2);
    hPhiTxy_VtxRange[i]->Draw("same");
    l_Phi[i] = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC");
    l_Phi[i]->SetTextFont(62);
    l_Phi[i]->SetTextSize(0.03330866);
    l_Phi[i]->SetLineColor(1);
    l_Phi[i]->SetLineStyle(1);
    l_Phi[i]->SetLineWidth(1);
    l_Phi[i]->SetFillColor(0);
    l_Phi[i]->SetFillStyle(1001);
    l_Phi[i]->SetBorderSize(0);
    l_Phi[i]->AddEntry(hPhi_VtxRange[i],"Type1PfMet Phi","l");
    l_Phi[i]->AddEntry(hPhiTxy_VtxRange[i],"corrected Phi","l");
    l_Phi[i]->Draw("same");
    TString Oname = Form("Phi_VtxRange_%d", i);
    c_phi[i]->Print(path+"/"+Oname+".png");
    c_phi[i]->Print(path+"/"+Oname+".pdf");

  }

  TCanvas* tc_phi_NoCut = new TCanvas();
  tc_phi_NoCut->cd();
  hPhi_NoCut->SetLineColor(kRed);
  hPhi_NoCut->SetLineWidth(2);
  hPhi_NoCut->Draw("");
  hPhiTxy_NoCut->SetLineColor(kBlue);
  hPhiTxy_NoCut->SetLineWidth(2);
  hPhiTxy_NoCut->Draw("same");
  TLegend *leg_Phi_NoCut = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC");
  leg_Phi_NoCut->SetTextFont(62);
  leg_Phi_NoCut->SetTextSize(0.03330866);
  leg_Phi_NoCut->SetLineColor(1);
  leg_Phi_NoCut->SetLineStyle(1);
  leg_Phi_NoCut->SetLineWidth(1);
  leg_Phi_NoCut->SetFillColor(0);
  leg_Phi_NoCut->SetFillStyle(1001);
  leg_Phi_NoCut->SetBorderSize(0);
  leg_Phi_NoCut->AddEntry(hPhi,"Type1PfMet Phi","l");
  leg_Phi_NoCut->AddEntry(hPhiTxy,"corrected Phi","l");
  leg_Phi_NoCut->Draw("same");
  tc_phi_NoCut->Print(path+"/phi_NoCut.png");
  tc_phi_NoCut->Print(path+"/phi_NoCut.pdf");

  TCanvas* tc_RawPhi_NoCut = new TCanvas();
  tc_RawPhi_NoCut->cd();
  hRawPhi_NoCut->SetLineColor(kRed);
  hRawPhi_NoCut->SetLineWidth(2);
  hRawPhi_NoCut->Draw("");
  hRawPhiTxy_NoCut->SetLineColor(kBlue);
  hRawPhiTxy_NoCut->SetLineWidth(2);
  hRawPhiTxy_NoCut->Draw("same");
  TLegend *lRa_Phi_NoCut = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC");
  lRa_Phi_NoCut->SetTextFont(62);
  lRa_Phi_NoCut->SetTextSize(0.03330866);
  lRa_Phi_NoCut->SetLineColor(1);
  lRa_Phi_NoCut->SetLineStyle(1);
  lRa_Phi_NoCut->SetLineWidth(1);
  lRa_Phi_NoCut->SetFillColor(0);
  lRa_Phi_NoCut->SetFillStyle(1001);
  lRa_Phi_NoCut->SetBorderSize(0);
  lRa_Phi_NoCut->AddEntry(hRawPhi,"MetPfRaw Phi","l");
  lRa_Phi_NoCut->AddEntry(hRawPhiTxy,"corrected Phi","l");
  lRa_Phi_NoCut->Draw("same");
  tc_RawPhi_NoCut->Print(path+"/RawPhi_NoCut.png");
  tc_RawPhi_NoCut->Print(path+"/RawPhi_NoCut.pdf");
  //---------------------
  // corr-org 
  //---------------------
  TCanvas* tc_metDiff = new TCanvas();
  tc_metDiff->cd();
  hMetDiff->SetMarkerStyle(21);
  hMetDiff->Draw("e");
  tc_metDiff->Print(path+"/MetDiff.png");
  tc_metDiff->Print(path+"/MetDiff.pdf");

  TCanvas* tc_metPull = new TCanvas();
  tc_metPull->cd();
  hMetPull->SetMarkerStyle(21);
  hMetPull->Draw("e");
  tc_metPull->Print(path+"/MetPull.png");
  tc_metPull->Print(path+"/MetPull.pdf");

  TCanvas* tc_phiDiff = new TCanvas();
  tc_phiDiff->cd();
  hPhiDiff->SetMarkerStyle(21);
  hPhiDiff->Draw("e");
  tc_phiDiff->Print(path+"/PhiDiff.png");
  tc_phiDiff->Print(path+"/PhiDiff.pdf");

  outFile->cd();
  outFile->Write("", TObject::kOverwrite);
  outFile->Close();
}
예제 #20
0
파일: tStudent.C 프로젝트: MycrofD/root
void tStudent()
{

   //gSystem->Load("libMathMore");
   // this is the way to force load of MathMore in Cling
   ROOT::Math::MathMoreLibrary::Load();

   int n=100;
   double a=-5.;
   double b=5.;
   //double r  = 3;
   TF1* pdf = new TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a,b);
   TF1* cum = new TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a,b);

   TH1D* quant = new TH1D("quant", "", 9, 0, 0.9);

   for(int i=1; i < 10; i++)
      quant->Fill((i-0.5)/10.0, ROOT::Math::tdistribution_quantile((1.0*i)/10, 3.0 ) );

   double xx[10];
   xx[0] = -1.5;
   for(int i=1; i<9; i++)
      xx[i]= quant->GetBinContent(i);
   xx[9] = 1.5;
   TH1D* pdfq[10];
   //int nbin = n/10.0;
   for(int i=0; i < 9; i++) {
      int nbin = n * (xx[i+1]-xx[i])/3.0 + 1.0;
      TString name = "pdf";
      name += i;
      pdfq[i]= new TH1D(name, "", nbin,xx[i],xx[i+1] );
      for(int j=1; j<nbin; j++) {
         double x= j*(xx[i+1]-xx[i])/nbin + xx[i];
         pdfq[i]->SetBinContent(j, ROOT::Math::tdistribution_pdf(x,3));
      }
   }

   TCanvas *Canvas = new TCanvas("DistCanvas", "Student Distribution graphs", 10, 10, 800, 700);
   pdf->SetTitle("Student t distribution function");
   cum->SetTitle("Cumulative for Student t");
   quant->SetTitle("10-quantiles  for Student t");
   Canvas->Divide(2, 2);
   Canvas->cd(1);
   pdf->SetLineWidth(2);
   pdf->DrawCopy();
   Canvas->cd(2);
   cum->SetLineWidth(2);
   cum->SetLineColor(kRed);
   cum->Draw();
   Canvas->cd(3);
   quant->Draw();
   quant->SetLineWidth(2);
   quant->SetLineColor(kBlue);
   quant->SetStats(0);
   Canvas->cd(4);
   pdfq[0]->SetTitle("Student t & its quantiles");
   pdf->SetTitle("");
   pdf->Draw();
   //pdfq[0]->SetAxisRange(-1.5, 0, 1.5,1.0);
   pdfq[0]->SetTitle("Student t & its quantiles");
   for(int i=0; i < 9; i++) {
      pdfq[i]->SetStats(0);
      pdfq[i]->SetFillColor(i+1);
      pdfq[i]->Draw("same");
   }
   Canvas->Modified();
   Canvas->cd();
}
예제 #21
0
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");
}
예제 #22
0
파일: test.cpp 프로젝트: ariostas/LQCD
void test()
{
//Illustrates TVirtualFitter::GetConfidenceIntervals
//This method computes confidence intervals for the fitted function
//Author: Anna Kreshuk

   TCanvas *myc = new TCanvas("myc",
      "Confidence intervals on the fitted function",1200, 500);
   myc->Divide(3,1);

/////1. A graph
   //Create and fill a graph
   Int_t ngr = 100;
   TGraph *gr = new TGraph(ngr);
   gr->SetName("GraphNoError");
   Double_t x, y;
   Int_t i;
   for (i=0; i<ngr; i++){
      x = gRandom->Uniform(-1, 1);
      y = -1 + 2*x + gRandom->Gaus(0, 1);
      gr->SetPoint(i, x, y);
   }
   //Create the fitting function
   TF1 *fpol = new TF1("fpol", "pol1", -1, 1);
   fpol->SetLineWidth(2);
   gr->Fit(fpol, "Q");

   //Create a TGraphErrors to hold the confidence intervals
   TGraphErrors *grint = new TGraphErrors(ngr);
   grint->SetTitle("Fitted line with .95 conf. band");
   for (i=0; i<ngr; i++)
      grint->SetPoint(i, gr->GetX()[i], 0);
   //Compute the confidence intervals at the x points of the created graph
   (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint);
   //Now the "grint" graph contains function values as its y-coordinates
   //and confidence intervals as the errors on these coordinates
   //Draw the graph, the function and the confidence intervals
   myc->cd(1);
   grint->SetLineColor(kRed);
   grint->Draw("ap");
   gr->SetMarkerStyle(5);
   gr->SetMarkerSize(0.7);
   gr->Draw("psame");

/////2. A histogram
   myc->cd(2);
   //Create, fill and fit a histogram
   Int_t nh=5000;
   TH1D *h = new TH1D("h",
      "Fitted gaussian with .95 conf.band", 100, -3, 3);
   h->FillRandom("gaus", nh);
   TF1 *f = new TF1("fgaus", "gaus", -3, 3);
   f->SetLineWidth(2);
   h->Fit(f, "Q");
   h->Draw();

   //Create a histogram to hold the confidence intervals
   TH1D *hint = new TH1D("hint",
      "Fitted gaussian with .95 conf.band", 100, -3, 3);
   (TVirtualFitter::GetFitter())->GetConfidenceIntervals(hint);
   //Now the "hint" histogram has the fitted function values as the
   //bin contents and the confidence intervals as bin errors
   hint->SetStats(kFALSE);
   hint->SetFillColor(2);
   hint->Draw("e3 same");

/////3. A 2d graph
   //Create and fill the graph
   Int_t ngr2 = 100;
   Double_t z, rnd, e=0.3;
   TGraph2D *gr2 = new TGraph2D(ngr2);
   gr2->SetName("Graph2DNoError");
   TF2  *f2 = new TF2("f2",
      "1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+250",-6,6,-6,6);
   f2->SetParameters(1,1);
   for (i=0; i<ngr2; i++){
      f2->GetRandom2(x,y);
      // Generate a random number in [-e,e]
      rnd = 2*gRandom->Rndm()*e-e;
      z = f2->Eval(x,y)*(1+rnd);
      gr2->SetPoint(i,x,y,z);
   }
   //Create a graph with errors to store the intervals
   TGraph2DErrors *grint2 = new TGraph2DErrors(ngr2);
   for (i=0; i<ngr2; i++)
      grint2->SetPoint(i, gr2->GetX()[i], gr2->GetY()[i], 0);

   //Fit the graph
   f2->SetParameters(0.5,1.5);
   gr2->Fit(f2, "Q");
   //Compute the confidence intervals
   (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint2);
   //Now the "grint2" graph contains function values as z-coordinates
   //and confidence intervals as their errors
   //draw
   myc->cd(3);
   f2->SetNpx(30);
   f2->SetNpy(30);
   f2->SetFillColor(kBlue);
   f2->Draw("surf4");
   grint2->SetNpx(20);
   grint2->SetNpy(20);
   grint2->SetMarkerStyle(24);
   grint2->SetMarkerSize(0.7);
   grint2->SetMarkerColor(kRed);
   grint2->SetLineColor(kRed);
   grint2->Draw("E0 same");
   grint2->SetTitle("Fitted 2d function with .95 error bars");

   myc->cd();

}
예제 #23
0
//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;
}
예제 #24
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();
}
void plotLeadingJet(int cbin,
		    TString infname,
		    TString pythia,
		    TString mix,
		    bool useWeight,
		    bool drawXLabel,
		    bool drawLeg)
{

  TString cut="et1>120 && et2>50 && dphi>2.5";
  TString cutpp="et1>120 && et2>50 && dphi>2.5";
  TString cstring = "";
  if(cbin==0) {
    cstring = "0-10%";
    cut+=" && bin>=0 && bin<4";
    cut+=" && ((et1-et2)/(et1+et2) > 0.3)";
  } else if (cbin==1) {
     cstring = "10-30%";
     cut+=" && bin>=4 && bin<12";
     cut+=" && ((et1-et2)/(et1+et2) > 0.3)";
  } else {
     cstring = "30-100%";
     cut+=" && bin>=12 && bin<40";
     cut+=" && ((et1-et2)/(et1+et2) > 0.3)";
  }
  
  // open the data file
  TFile *inf = new TFile(infname.Data());
  TTree *nt =(TTree*)inf->FindObjectAny("nt");

  // open the pythia (MC) file
  TFile *infPythia = new TFile(pythia.Data());
  TTree *ntPythia = (TTree*) infPythia->FindObjectAny("nt");

  // open the datamix file
  TFile *infMix = new TFile(mix.Data());
  TTree *ntMix =(TTree*)infMix->FindObjectAny("nt");


  // projection histogram
  TH1D *h = new TH1D("h","",10,60,135);
  TH1D *hPythia = new TH1D("hPythia","",10,60,135);
  TH1D *hDataMix = new TH1D("hDataMix","",10,60,135);
  nt->Draw("et2>>h",Form("(%s)",cut.Data())); 
   
  if (useWeight) {
    // use the weight value caluculated by Matt's analysis macro
    ntMix->Draw("et2>>hDataMix",Form("(%s)*weight",cut.Data())); 
  } else {
    // ignore centrality reweighting
    ntMix->Draw("et2>>hDataMix",Form("(%s)",cut.Data()));  
  }
    ntPythia->Draw("et2>>hPythia",Form("(%s)",cutpp.Data())); 
  // calculate the statistical error and normalize
  h->Sumw2();
  h->Scale(1./h->GetEntries());
  h->SetMarkerStyle(20);

  hPythia->Scale(1./hPythia->Integral(0,20));
  hPythia->SetLineColor(kBlue);
  hPythia->SetFillColor(kAzure-8);
  hPythia->SetFillStyle(3005);
   
  hPythia->SetStats(0);
  hPythia->Draw("hist");
  if(drawXLabel) hPythia->SetXTitle("Subleading Jet E_{T} (GeV)");

  hPythia->GetXaxis()->SetLabelSize(20);
  hPythia->GetXaxis()->SetLabelFont(43);
  hPythia->GetXaxis()->SetTitleSize(22);
  hPythia->GetXaxis()->SetTitleFont(43);
  hPythia->GetXaxis()->SetTitleOffset(1.5);
  hPythia->GetXaxis()->CenterTitle();

  hPythia->GetXaxis()->SetNdivisions(904,true);

  hPythia->SetYTitle("Event Fraction");

  hPythia->GetYaxis()->SetLabelSize(20);
  hPythia->GetYaxis()->SetLabelFont(43);
  hPythia->GetYaxis()->SetTitleSize(20);
  hPythia->GetYaxis()->SetTitleFont(43);
  hPythia->GetYaxis()->SetTitleOffset(2.5);
  hPythia->GetYaxis()->CenterTitle();

  hPythia->SetAxisRange(2E-3,3,"Y");
  hDataMix->SetAxisRange(2E-3,3,"Y");
  h->SetAxisRange(2E-3,3,"Y");


  h->Draw("same");

  hDataMix->Scale(1./hDataMix->Integral(0,20));
  hDataMix->SetLineColor(kRed);
  hDataMix->SetFillColor(kRed-9);
  hDataMix->SetFillStyle(3004);
  hDataMix->Draw("same");

  if(drawLeg){
     TLegend *t3=new TLegend(0.25,0.74,0.79,0.90);
    t3->AddEntry(h,"Pb+Pb  #sqrt{s}_{_{NN}}=2.76 TeV","pl");
    t3->AddEntry(hPythia,"PYTHIA","lf");
    t3->AddEntry(hDataMix,"embedded PYTHIA","lf");
    t3->SetFillColor(0);
    t3->SetBorderSize(0);
    t3->SetFillStyle(0);
    t3->SetTextFont(63);
    t3->SetTextSize(15);
    t3->Draw();
  }
  
}
예제 #26
0
TF1 *bFeedDownFraction(double ptMin=20,double ptMax=25)
{
/*
   TFile *infMCP = new TFile("miniNtuplePrompt.root");
   TFile *infMCNP = new TFile("miniNtupleNonPrompt.root");
   TFile *infData = new TFile("miniData.root");
*/

   TFile *infMCP = new TFile("ntD_EvtBase_20160303_Dfinder_20160302_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root");
   TFile *infMCNP = new TFile("ntD_EvtBase_20160303_Dfinder_20160302_pp_Pythia8_nonprompt_D0_dPt0tkPt0p5_pthatweight.root");
   // TFile *infData = new TFile("miniData.root");
   TFile *infData = new TFile("ppData.root");
    
   TTree *tMCP = (TTree*)infMCP->Get("ntDkpi");
   TTree *tMCNP = (TTree*)infMCNP->Get("ntDkpi");
   TTree *tMCPHI = (TTree*)infMCP->Get("ntHi");
   TTree *tMCNPHI = (TTree*)infMCNP->Get("ntHi");
   TTree *tData = (TTree*)infData->Get("ntDkpi");
   tMCP->AddFriend(tMCPHI);
   tMCNP->AddFriend(tMCNPHI);
   
   
   TFile *outf = new TFile(Form("output-%.0f-%.0f.root",ptMin,ptMax),"recreate");
   TNtuple *nt = new TNtuple("nt","","ptMin:ptMax:Frac:FracErr");
   TCanvas *cSideband = new TCanvas("cSideband","Data Sideband",1200,1200);
   cSideband->Divide(2,2);
   cSideband->cd(1);


   TCut cutpp ="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>2.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&&(Dtrk2PixelHit+Dtrk2StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)";
   TCut cutmc="(Dgen==23333||Dgen==23344)";
   TCut cutpt=Form("Dpt>%f&&Dpt<%f",ptMin,ptMax);
   TCut cutSignal = "abs(Dmass-1.8649)<0.025";
   TCut cutSideband = "abs(Dmass-1.8649)>0.075&&abs(Dmass-1.8649)<0.1";
 //  TCut weightfuncFtionreco="((TMath::Erf((log(DsvpvDisErr))*(Dgenpt*Dgenpt*(-0.001)+0.1021*Dgenpt+1.247)+(Dgenpt*Dgenpt*(-0.0032)+0.2912*Dgenpt+6.8275))+1))*(pow(10,-0.168499*Dgenpt+3.872855+Dgenpt*Dgenpt*0.000556)+pow(10,-0.068599*Dgenpt+2.512265+Dgenpt*Dgenpt*0.000331))";
   TCut weightfunctionreco = "pthatweight";
   int nBin=20;
   double binL=3.5;
   double binH=103.5;
   double fitRangeL=3.5;
   double fitRangeH=100.5;

   if (ptMax<=6) {
      fitRangeH=43.5;
      binH=43.5;
   }

   float bins[6+1]={3.5,5.5,8.5,10.5,20.5,30.5,50.5};
   
   TH1D *hSideband = new TH1D("hSideband","Sideband",nBin,binL,binH);
   TH1D *hData = new TH1D("hData","Data",nBin,binL,binH);
   TH1D *hMCPSignal = new TH1D("hMCPSignal","Prompt",nBin,binL,binH);
   TH1D *hMCNPSignal = new TH1D("hMCNPSignal","Non-prompt",nBin,binL,binH);
   TH1D *hMCPSideband = new TH1D("hMCPSideband","",nBin,binL,binH);
   TH1D *hMCNPSideband = new TH1D("hMCNPSideband","",nBin,binL,binH);
   hSideband->Sumw2();
   hData->Sumw2();
   hMCPSignal->Sumw2();
   hMCNPSignal->Sumw2();

   
   tData->Draw("(DsvpvDistance/DsvpvDisErr)>>hSideband",cutpt&&cutpp&&cutSideband);
   tData->Draw("(DsvpvDistance/DsvpvDisErr)>>hData",cutpt&&cutpp&&cutSignal);
   tMCP->Draw("(DsvpvDistance/DsvpvDisErr)>>hMCPSignal",weightfunctionreco*(cutpt&&cutpp&&cutSignal&&cutmc));
   //tMCP->Draw("(DsvpvDistance/DsvpvDisErr)>>hMCPSideband",cutpt&&cutpp&&cutSideband);
   tMCNP->Draw("(DsvpvDistance/DsvpvDisErr)>>hMCNPSignal",weightfunctionreco*(cutpt&&cutpp&&cutSignal&&cutmc));
   //tMCNP->Draw("(DsvpvDistance/DsvpvDisErr)>>hMCNPSideband",cutpt&&cutpp&&cutSideband);
   
   hSideband->Scale(1./1.);
   hData->Add(hSideband,-1);
   normalize(hData,1);
   normalize(hMCPSignal,2);
   normalize(hMCNPSignal,4);
   normalize(hSideband,kGreen+2);
   
   
   
   TF1 *fSideband = new TF1("fSideband","[0]*(exp([1]*x+[2])+[3]*exp([4]*x+[5])+[6]*exp([7]*x+[8]))");     
   TF1 *fMCPSignal = new TF1("fMCPSignal","[0]*(exp([1]*x+[2])+[3]*exp([4]*x+[5])+[6]*exp([7]*x+[8]))");
   TF1 *fMCNPSignal = new TF1("fMCNPSignal","[0]*(exp([1]*x+[2])+[3]*exp([4]*x+[5])+[6]*exp([7]*x+[8]))");
   
   fSideband->SetParameters(0,-0.1,0.2,-0,-2,0.006,-0.01,-0.11,-0.04,0,0.001);
   fMCNPSignal->SetParameters(0,-0.1,0.1,-0,-0.02,0.006,-0.01,-0.11,-0.04,0,0.001);
   fMCPSignal->SetParameters(0,-0.1,0.1,-0,-0.02,0.006,-0.01,-0.11,-0.04,0,0.001);
//   fMCNPSignal->FixParameter(3,0);
//   fMCPSignal->FixParameter(3,0);
   fMCPSignal->SetParLimits(1,-100,0);   
   fMCPSignal->SetParLimits(4,-100,0);   
   fMCPSignal->SetParLimits(7,-100,0);   
   fMCNPSignal->SetParLimits(1,-100,0);   
   fMCNPSignal->SetParLimits(4,-100,0);   
   fMCNPSignal->SetParLimits(7,-100,0);   
   fMCPSignal->SetParLimits(0,0,1e10);   
   fMCPSignal->SetParLimits(3,0,1e10);   
   fMCPSignal->SetParLimits(6,0,1e10);   
   fMCNPSignal->SetParLimits(0,0,1e10);   
   fMCNPSignal->SetParLimits(3,0,1e10);   
   fMCNPSignal->SetParLimits(6,0,1e10);   

   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   
   
   hSideband->Fit("fSideband","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","m q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","m q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","m q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   double normSideband = hSideband->Integral(0,0.12);
   
   cSideband->cd(2);
   hMCPSignal->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","m q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","m q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","m q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," m q","",fitRangeL,fitRangeH);
   double normMCPSignal = hMCPSignal->Integral(0,0.12);

   cSideband->cd(3);
   hMCNPSignal->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal"," q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal"," q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal"," q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal"," q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","m q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","m q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","m q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","m q","",fitRangeL,fitRangeH);
   
   double normMCNPSignal = hMCNPSignal->Integral(0,0.12);
   
   
   string sSideband = Form("(%e)*(exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e)))",fSideband->GetParameter(0),fSideband->GetParameter(1),fSideband->GetParameter(2),fSideband->GetParameter(3),fSideband->GetParameter(4),fSideband->GetParameter(5),fSideband->GetParameter(6),fSideband->GetParameter(7),fSideband->GetParameter(8));
   string sMCPSignal = Form("(%e)*(exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e)))",fMCPSignal->GetParameter(0),fMCPSignal->GetParameter(1),fMCPSignal->GetParameter(2),fMCPSignal->GetParameter(3),fMCPSignal->GetParameter(4),fMCPSignal->GetParameter(5),fMCPSignal->GetParameter(6),fMCPSignal->GetParameter(7),fMCPSignal->GetParameter(8));
   
   string sMCNPSignal = Form("(%e)*(exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e)))",fMCNPSignal->GetParameter(0),fMCNPSignal->GetParameter(1),fMCNPSignal->GetParameter(2),fMCNPSignal->GetParameter(3),fMCNPSignal->GetParameter(4),fMCNPSignal->GetParameter(5),fMCNPSignal->GetParameter(6),fMCNPSignal->GetParameter(7),fMCNPSignal->GetParameter(8));
   
   
   string function;
   function="0*("+sSideband+")+[1]*([2]*"+sMCPSignal+"+(1-[2])*("+sMCNPSignal+"))";
   string functionNP;
   functionNP="0*("+sSideband+")+[1]*(0*"+sMCPSignal+"+(1-[2])*("+sMCNPSignal+"))";
   
    
   TCanvas *cFit = new TCanvas("cFit","Fit",600,600);
   TF1 *f = new TF1("f",function.c_str());
   f->SetParameters(1,0.1,0.9,0,0.1);
   f->SetParLimits(0,0,1000);
   f->SetParLimits(2,-1,2);
   f->SetLineColor(2);
   f->SetFillColor(2);
   f->SetFillStyle(3001);
   f->Draw("same");   
   hData->SetAxisRange(fitRangeL,fitRangeH,"X");
   hData->Fit("f","LL");
   hData->Fit("f","LL");
   hData->Fit("f","LL");
   hData->Fit("f","LL");
   hData->Fit("f","m");
   hData->SetXTitle("Flight Distance Significance");
   hData->SetYTitle("Event Fraction");
   
   TF1 *fNP = new TF1("fNP",functionNP.c_str());
   fNP->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2));
   fNP->SetRange(fitRangeL,fitRangeH*2);
   fNP->SetLineColor(4);
   fNP->SetFillStyle(3001);
   fNP->SetFillColor(4);
   hData->SetStats(0);
   hData->Draw("same");
   fNP->Draw("same");  

   cout <<fNP->Integral(3.5,60)/f->Integral(3.5,60)<<endl;

   TLegend *leg = new TLegend(0.5,0.7,0.9,0.9);
   leg->SetBorderSize(0);
   leg->SetFillStyle(0);
   leg->AddEntry(hData,"pp data","pl");
   leg->AddEntry(f,Form("Prompt Fraction %.1f #pm %.1f %%",100*f->GetParameter(2),100*f->GetParError(2)),""); 
   leg->AddEntry(f,"Prompt D^{0}","f");
   leg->AddEntry(fNP,"Non-Prompt D^{0}","f");
   
   leg->Draw();
   
   cSideband->cd(4);
   hMCPSignal->Draw("hist");
   hSideband->Draw("hist same");
   hMCNPSignal->Draw("hist same");
   hData->Draw("same");
   nt->Fill(ptMin,ptMax,f->GetParameter(2),f->GetParError(2));
   nt->Write();
   outf->Write();
//   outf->Close();	
   return f;
}
//_________________________________________________________________________________
void multipleSplinesWithHistogramsVb(int iEventLook = 163, int nEvents = 1000, int nPoints = 9, double seed = 231) 
{
	double lowerBound = 10; //bounds for random vector function
	double upperBound = 20;
	double lowerErrorBound = 1;
	double upperErrorBound = 2;

	//Load the data
	vector< vector<double> > xEvents, yEvents, yErrorEvents; //each of these is a vector of vectors (of randomized data points)
	for(int i = 0; i < nEvents; i++) 
	{
		vector <double> xData, yData, yErrorData; //temporary vectors that are only used to get random values from FillRand function
		FillRandVectors(nPoints, xData, yData, yErrorData, seed*(i+1), lowerBound, upperBound, lowerErrorBound, upperErrorBound); //populates random vectors for y values and y error vector
		xEvents.push_back(xData);
		yEvents.push_back(yData);
		yErrorEvents.push_back(yErrorData);
	}

	//Intialization of the variables
	const int npar = nPoints;
	const int orderSpline = 4;
	const int nbreak = npar+2-orderSpline;
	double stepSpline = 0.01;
	double xminBSplineWorkspace = 0;
	double xmaxBSplineWorkspace = 9;
	double startCSplineWorkspace = 15.;
	double stepCSplineWorkspace = 1.5;

	acc_GLOB = gsl_interp_accel_alloc ();
	spline_GLOB = gsl_spline_alloc (gsl_interp_cspline, nPoints);	
	bw_GLOB = gsl_bspline_alloc(orderSpline, nbreak);
	
	//B- and C-splines
	clock_t tbstart, tbstop, tcstart, tcstop;
	vector <double> timeb, timec;

	vector< vector<double> > xBSplineValues, yBSplineValues;
	vector< vector<double> > xCSplineValues, yCSplineValues; 

//Setup for the C-spline_________________________________________________________________________
	TMinuit *myMinuit = new TMinuit(npar);  //initialize TMinuit with a maximum of npar 
	myMinuit->SetFCN(fcn);
	myMinuit->SetPrintLevel(-1);//No output: -1, output:1

	double arglist[10];
	int ierflg = 0;
	arglist[0] = 1;
	myMinuit->mnexcm("SET ERR", arglist, 1, ierflg);

	//Initialize Minuit
	vector<double> vstart, vstep;
	for(int i=0; i<npar; i++) 	//set starting values and step sizes for parameters
	{
		vstart.push_back(startCSplineWorkspace);
		vstep.push_back(stepCSplineWorkspace);
	}

	for (int i = 0; i < npar; i++) {
		stringstream ss;
		ss<<"a"<<i;
		myMinuit->mnparm(i, ss.str().c_str(), vstart.at(i), vstep.at(i), 0, 0, ierflg);
	}

//Setup for the B-spline_________________________________________________________________________

	//Looping begins for the calculations of the B and C-splines for each event
	for(int i = 0; i < (int)xEvents.size(); i++)
	{
		//Populate the global variables
		xData_GLOB = xEvents.at(i);
		yData_GLOB = yEvents.at(i);
		yErrorData_GLOB = yErrorEvents.at(i);

		tbstart = clock();
		vector< vector<double> > bSplineValues = bSpline(nPoints, npar, xEvents.at(i), yEvents.at(i), yErrorEvents.at(i), stepSpline, xminBSplineWorkspace, xmaxBSplineWorkspace);
		tbstop = clock();
		timeb.push_back(((float)tbstop-(float)tbstart)/ (CLOCKS_PER_SEC/1000.) );		

		std::cout<<timeb.back()<<std::endl;

		xBSplineValues.push_back(bSplineValues.at(0));
		yBSplineValues.push_back(bSplineValues.at(1));

		tcstart = clock();
		vector< vector<double> > cSplineValues = cSpline(nPoints, npar, xEvents.at(i), stepSpline, myMinuit);
		tcstop = clock();
		timec.push_back(((float)tcstop-(float)tcstart)/ (CLOCKS_PER_SEC/1000.) );		

		xCSplineValues.push_back(cSplineValues.at(0));
		yCSplineValues.push_back(cSplineValues.at(1));
	}

	//Histograms______________________________________________________________________________________

	//Time
	int nbins = 100;
	double xlow = 0;
	double xup = 1.;

	TH1D *hTimeB = new TH1D("Time","Timing; time [ms]; Number of Events", nbins, xlow, xup); 
	hTimeB->SetStats(0);
	hTimeB->SetMarkerStyle(10);
	TH1D *hTimeC = new TH1D("TimeC","Timing; time [ms]; Number of Events", nbins, xlow, xup); 
	hTimeC->SetLineColor(kRed);
	hTimeC->SetMarkerStyle(10);
	hTimeC->SetStats(0);

	for(int i=0; i<(int)timec.size(); i++) 
	{
		hTimeB->Fill(timeb.at(i));
		hTimeC->Fill(timec.at(i));	
	}

	//Interpolation
	vector <double> interpB, interpC;
	for(int i = 0; i < (int)yEvents.size(); i++)
	{
		for(int j = 0; j < (int)yEvents[i].size(); j++)
		{
			int indexForB = binarySearch(xBSplineValues[i], xEvents[i][j]);
			int indexForC = binarySearch(xCSplineValues[i], xEvents[i][j]);

			interpB.push_back( (yEvents[i][j]-yBSplineValues[i][indexForB])/yErrorEvents[i][j] );
			interpC.push_back( (yEvents[i][j]-yCSplineValues[i][indexForC])/yErrorEvents[i][j] );
		}
	}	

	//Test graphs for splines
	TGraph *GCspline = new TGraph(xCSplineValues[iEventLook].size(), &xCSplineValues[iEventLook][0], &yCSplineValues[iEventLook][0]);
	GCspline->SetLineColor(kRed);
	TGraph *GBspline = new TGraph(xBSplineValues[iEventLook].size(), &xBSplineValues[iEventLook][0], &yBSplineValues[iEventLook][0]);
	TGraph *Gdata = new TGraph(xEvents[0].size(), &xEvents[iEventLook][0], &yEvents[iEventLook][0]);
		Gdata->SetMarkerStyle(20);

	int nbinsI = 101;
	double xlowI = -0.1;
	double xupI = 0.1;
	TH1D *hInterpB = new TH1D("Interp B","Interpolation; Distance between spline and data normalized by error; Number of Events", nbinsI, xlowI, xupI); 
	for(int i=0; i<(int)interpB.size(); i++) hInterpB->Fill(interpB.at(i));
	hInterpB->SetStats(0);

	TH1D *hInterpC = new TH1D("Interp C","Interpolation; Distance between spline and data normalized by error; Number of Events", nbinsI, xlowI, xupI); 
	for (int i=0; i<(int)interpC.size(); i++) hInterpC->Fill(interpC.at(i));
	hInterpC->SetLineColor(kGreen);
	hInterpC->SetStats(0);	

	//Draws______________________________________________________________________________________

	//Interpolation 
	TLegend *legInterp = new TLegend(0.9,0.70,0.75,0.85);
	legInterp->SetLineColor(kWhite); 
	legInterp->SetFillColor(kWhite);
	legInterp->SetMargin(0.3); 
	legInterp->AddEntry(hInterpB,"b-spline","l");
	legInterp->AddEntry(hInterpC,"c-spline","l");
	legInterp->SetTextSize(0.05);

	TCanvas *c1 = new TCanvas("c1", "Interpolation distance");
	c1->cd();
	hInterpB->Draw("");
	hInterpC->Draw("same");
	legInterp->Draw();

	//Time
	TLegend *legTime = new TLegend(0.9,0.70,0.75,0.85);
	legTime->SetLineColor(kWhite); 
	legTime->SetFillColor(kWhite);
	legTime->SetMargin(0.3); 
	legTime->AddEntry(hTimeB,"b-spline","l");
	legTime->AddEntry(hTimeC,"c-spline","l");
	legTime->SetTextSize(0.05);

	TCanvas *c2 = new TCanvas("c2", "Computation time");
	c2->cd();
	hTimeB->Draw();
//	hTimeC->Draw("same");
	legTime-> Draw();

	TCanvas *c3 = new TCanvas("c3", "Test splines");
	c3->cd();
	Gdata->Draw("ap");
	GCspline->Draw("samel");
	GBspline->Draw("samel");

	//Free the memory used
	gsl_spline_free (spline_GLOB); 
 	gsl_interp_accel_free (acc_GLOB);
	gsl_bspline_free(bw_GLOB);
}
예제 #28
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;
}
예제 #29
0
void plot_stuff(){
  
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  
  gROOT->ForceStyle();
  TFile *in = TFile::Open("IncLusive_Plots_vmd.root");
  
  TH1D *hIVEpEmGam = (TH1D*)in->Get("hIVEpEmGam");
  TH1D *hIVEpEmGam_cut = (TH1D*)in->Get("hIVEpEmGam_cut");
  
  hIVEpEmGam->SetLineColor(kBlack);
  hIVEpEmGam->SetStats(false);
  hIVEpEmGam_cut->SetStats(false);
  hIVEpEmGam->GetXaxis()->SetTitle("M(e^{+}e^{-}#gamma) [GeV]");
  hIVEpEmGam->GetXaxis()->SetTitleSize(0.05);
  hIVEpEmGam->GetXaxis()->SetTitleOffset(0.8);
  hIVEpEmGam->GetYaxis()->SetTitle("Counts / 35.5 MeV");
  hIVEpEmGam->GetYaxis()->SetTitleSize(0.05);
  hIVEpEmGam->GetYaxis()->SetTitleOffset(1.0);
  
  hIVEpEmGam->SetLineWidth(2);
  
  hIVEpEmGam_cut->SetLineColor(kRed);
  hIVEpEmGam_cut->SetFillColor(kRed);
  hIVEpEmGam_cut->SetFillStyle(3001);
  
  TH1D *hMMPEmX = (TH1D*)in->Get("hMMPEmX");
  TH1D *hMMPEmX_cut = (TH1D*)in->Get("hMMPEmX_cut");
  
  hMMPEmX->SetLineColor(kBlack);
  hMMPEmX->SetLineWidth(2);
  
  hMMPEmX->GetXaxis()->SetTitle("M_{x}(pe^{-}) [GeV]");
  hMMPEmX->SetStats(false);
  hMMPEmX_cut->SetStats(false);
  hMMPEmX->GetXaxis()->SetTitleSize(0.05);
  hMMPEmX->GetXaxis()->SetTitleOffset(0.8);
  hMMPEmX->GetYaxis()->SetTitle("Counts / 35.5 MeV");
  hMMPEmX->GetYaxis()->SetTitleSize(0.05);
  hMMPEmX->GetYaxis()->SetTitleOffset(1.0);
  
  hMMPEmX_cut->SetLineColor(kRed);
  hMMPEmX_cut->SetFillColor(kRed);
  hMMPEmX_cut->SetFillStyle(3001);
  
  
  
  TH1D *IVrest = (TH1D*)hIVEpEmGam->Clone();
  int critIVbin = IVrest->GetXaxis()->FindFixBin(1.5);
  
  TH1D *MMrest = (TH1D*)hMMPEmX->Clone();
  int critMMbin = MMrest->GetXaxis()->FindFixBin(1.2);
  
  for(int i=1;i<= IVrest->GetNbinsX();i++){
    if(i<critIVbin){
      IVrest->SetBinContent(i,0);
    }
  }
  IVrest->SetFillStyle(3001);
  IVrest->SetFillColor(8);
  IVrest->SetLineColor(8);
  
  
  for(int i=1;i<= MMrest->GetNbinsX();i++){
    if(i>critMMbin){
      MMrest->SetBinContent(i,0);
    }
  }
    MMrest->SetFillStyle(3001);
    MMrest->SetFillColor(8);
    MMrest->SetLineColor(8);
    
    TLegend *leg1 = new TLegend(0.25,0.7,0.9,0.9);
    leg1->SetFillColor(0);
    leg1->AddEntry(IVrest,"Select e^{-}' from e^{-}p#rightarrow e^{-}'pX");
    leg1->AddEntry(hIVEpEmGam_cut,"Select e^{-} from #eta'#rightarrow e^{+}e^{-}#gamma");
    
    TLegend *leg2 = new TLegend(0.25,0.7,0.9,0.9);
    leg2->SetFillColor(0);
    leg2->AddEntry(MMrest,"Select e^{-}' from e^{-}p#rightarrow e^{-}'pX");
    leg2->AddEntry(hMMPEmX_cut,"Select e^{-} from #eta'#rightarrow e^{+}e^{-}#gamma");
    
    TCanvas *c = new TCanvas("c","",1200,500);
    c->Divide(2);
    c->cd(1);
    
  //IVrest->Draw();
  hIVEpEmGam->Draw();

    fitMKVoight(hIVEpEmGam, 0.6, 2.1, 0, 0, 0, 0, 0.957, 0.01, 0.001, 2.5, 1);
  

  
    hIVEpEmGam_cut->Draw("same");
    //hIVEpEmGam->Draw("same");
    IVrest->Draw("same");
    leg1->Draw("same");
    c->cd(2);
    
    MMrest->Draw();
    fitMKVoight(hMMPEmX, 0.6, 2.1, 0, 0, 0, 0, 0.957, 0.01, 0.001, 2.5, 1);
    
    hMMPEmX_cut->Draw("same");
    hMMPEmX->Draw("same");
    leg2->Draw("same");
    c->cd();
    
    TH1D *hIVEpEm = (TH1D*)in->Get("hIVEpEm");
    TH1D *hIVEpEm_cut = (TH1D*)in->Get("hIVEpEm_cut");
    TH1D *hEpEm_contam = (TH1D*)in->Get("hEpEm_contam");
    
    
    hIVEpEm->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
    hIVEpEm->GetXaxis()->SetTitleSize(0.05);
    hIVEpEm->GetXaxis()->SetTitleOffset(0.8);
    
    hIVEpEm->GetYaxis()->SetTitle("Counts / 40 MeV");
    hIVEpEm->GetYaxis()->SetTitleSize(0.05);
    hIVEpEm->GetYaxis()->SetTitleOffset(0.8);
    
    hIVEpEm->SetLineColor(kBlack);
    hIVEpEm->SetLineWidth(2);
    
    
    hIVEpEm_cut->SetLineColor(kRed);
    hIVEpEm_cut->SetFillColor(kRed);
    hIVEpEm_cut->SetFillStyle(3001);
    
    
    hEpEm_contam->SetLineColor(8);
    hEpEm_contam->SetFillColor(8);
    hEpEm_contam->SetFillStyle(3001);
    
    TLegend *leg3 = new TLegend(0.6,0.6,0.9,0.9);
    leg3->SetFillColor(0);
    leg3->AddEntry(hIVEpEm_cut,"Select e^{-} from #eta'#rightarrowe^{+}e^{-}#gamma");
    leg3->AddEntry(hEpEm_contam,"Select e^{-}' from e^{-}p#rightarrow e^{-}'pX");
    
    TCanvas *c2 = new TCanvas("c2","",1);
    hIVEpEm->Draw();
    hIVEpEm_cut->Rebin(4);
    hIVEpEm_cut->Draw("same");
    hEpEm_contam->Rebin(4);
    hEpEm_contam->Draw("same");
    hIVEpEm->Draw("same");
    leg3->Draw("same");
    c2->SetLogy();
    
    
    TH1D *hEmP = (TH1D*)in->Get("hEmP");
    TH1D *hEmP_cut = (TH1D*)in->Get("hEmP_cut");
    
    hEmP->GetXaxis()->SetTitle("Momentum of e^{-} [GeV/c]");
    hEmP->GetXaxis()->SetTitleSize(0.05);
    hEmP->GetXaxis()->SetTitleOffset(0.8);
    
    hEmP->GetYaxis()->SetTitle("Counts / 110 MeV");
    hEmP->GetYaxis()->SetTitleSize(0.05);
    hEmP->GetYaxis()->SetTitleOffset(0.8);
    
    hEmP->SetLineColor(kBlack);
    hEmP->SetLineWidth(2);
    
    hEmP_cut->SetLineColor(kRed);
    hEmP_cut->SetFillColor(kRed);
    hEmP_cut->SetFillStyle(3001);
    
    TLegend *leg4 = new TLegend(0.6,0.6,0.9,0.9);
    leg4->SetFillStyle(0);
    leg4->AddEntry(hEmP_cut,"Select e^{-} from #eta'#rightarrow e^{+}e^{-}#gamma");
    
    TCanvas *c3 = new TCanvas("c3","",1);
    hEmP->Draw();
    hEmP_cut->Draw("same");
    leg4->Draw("same");
    c3->cd();
    
    
    

  
  
  
  
  //MK stuff
  
  /*
   TCanvas *cmkII =  new TCanvas("cmkII","cmkII",1200,500);
   //cmkII->Divide(1,2);
   cmkII->cd();
   cmkII->SetLogy();
   TH1D *hIVEpEm_cut_clone = (TH1D*)in->Get("hIVEpEm_cut_clone");
   hIVEpEm_cut_clone->SetLineColor(kRed);
   hIVEpEm_cut_clone->SetYTitle("Expected Counts / 10 MeV");
   hIVEpEm_cut_clone->GetYaxis()->SetTitleSize(0.05);
   hIVEpEm_cut_clone->GetYaxis()->SetTitleOffset(0.8);
   hIVEpEm_cut_clone->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hIVEpEm_cut_clone->GetXaxis()->SetTitleSize(0.05);
   hIVEpEm_cut_clone->GetXaxis()->SetTitleOffset(0.8);
   TH1D *hEpEm_corrected = (TH1D*)in->Get("hEpEm_corrected");
   hEpEm_corrected->SetYTitle("Counts / 10 MeV");
   hEpEm_corrected->GetYaxis()->SetTitleSize(0.05);
   hEpEm_corrected->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_corrected->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_corrected->GetXaxis()->SetTitleSize(0.05);
   hEpEm_corrected->Draw("EP");
   hIVEpEm_cut_clone->Draw("EP same");
   
   TLegend *legmkII = new TLegend(0.45,0.7,0.9,0.9);
   legmkII->SetTextSize(0.05);
   legmkII->SetFillColor(0);
   legmkII->AddEntry(hIVEpEm_cut_clone,"Expected counts in 80 days","l");
   
   legmkII->AddEntry(hEpEm_corrected,"Accepted corrected counts in 80 days","l");
   legmkII->Draw("same");
   
   
   TCanvas *cmkIII =  new TCanvas("cmkIII","cmkIII",1200,500);
   cmkIII->cd();
   TH1D *hEpEm_acceptance = (TH1D*)in->Get("hEpEm_acceptance");
   hEpEm_acceptance->SetLineColor(kRed);
   hEpEm_acceptance->SetYTitle("Acceptance / 10 MeV");
   hEpEm_acceptance->GetYaxis()->SetTitleSize(0.05);
   hEpEm_acceptance->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_acceptance->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_acceptance->GetXaxis()->SetTitleSize(0.05);
   hEpEm_acceptance->GetXaxis()->SetTitleOffset(0.8);
   TH1D *hEpEm_acceptance_flat = (TH1D*)inflat->Get("hEpEm_acceptance");
   hEpEm_acceptance_flat->SetYTitle("Acceptance / 10 MeV");
   hEpEm_acceptance_flat->GetYaxis()->SetTitleSize(0.05);
   hEpEm_acceptance_flat->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_acceptance_flat->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_acceptance_flat->GetXaxis()->SetTitleSize(0.05);
   hEpEm_acceptance_flat->GetXaxis()->SetTitleOffset(0.8);
   hEpEm_acceptance->GetYaxis()->SetRangeUser(0,0.16);
   hEpEm_acceptance->Draw("EP");
   hEpEm_acceptance_flat->Draw("EP same");
   
   TLegend *legmkIII = new TLegend(0.11,0.7,0.45,0.9);
   legmkIII->SetTextSize(0.05);
   legmkIII->SetFillColor(0);
   legmkIII->AddEntry(hEpEm_acceptance,"QED+VMD M(e^{+}e^{-}) Acceptance","l");
   
   legmkIII->AddEntry(hEpEm_acceptance_flat,"Flat M(e^{+}e^{-}) Acceptance","l");
   legmkIII->Draw("same");
   
   
   //
   double QED_par[8] = {0.957}; //{Mass}
   TF1 *QED_norm = new TF1("QED_norm",Eval_Kroll_wada,0.,1.,1);
   QED_norm->SetParameters(&QED_par[0]);
   
   TH1D *hEpEm_corrected_flat = new TH1D("hEpEm_corrected_flat","hEpEm_corrected_flat",100,0.0,1);
   TH1D *hEpEm_QEDnorm_flat = new TH1D("hEpEm_QEDnorm_flat","hEpEm_QEDnorm_flat",100,0.0,1);
   for (int i = 1; i<hIVEpEm_cut_clone->GetNbinsX(); i++) {
   
   Double_t bin_factor = 1.65; //this needs to be solved at somepoint
   Double_t intotal_acceptance = hEpEm_acceptance_flat->GetBinContent(i)*bin_factor;
   Double_t intotal_events_upper;
   if (intotal_acceptance == 0) {
   intotal_events_upper = 0;
   }else{
   intotal_events_upper = hIVEpEm_cut_clone->GetBinContent(i)/intotal_acceptance;
   }
   hEpEm_corrected_flat->SetBinContent(i,intotal_events_upper);
   hEpEm_corrected_flat->SetBinError(i,sqrt(intotal_events_upper));
   
   Double_t QED_factor = QED_norm->Eval(hIVEpEm_cut_clone->GetBinCenter(i));//2.0e-06;
   
   hEpEm_QEDnorm_flat->SetBinContent(i,intotal_events_upper/QED_factor);
   //hEpEm_QEDnorm->SetBinError(i,sqrt(intotal_events_upper/QED_factor));
   
   }
   
   
   
   //
   
   double pole_par[3] = {10, 0.59,0.0144}; //{A,Lambda,Gamma}
   
   TF1 *FF_fittepole = new TF1("FF_fittepole", Pole_FFII,0.02,0.92,3);
   FF_fittepole->SetParameters(&pole_par[0]);
   FF_fittepole->SetParLimits(0,0.,100.);
   FF_fittepole->SetParLimits(1,pole_par[1] - pole_par[1]*0.1,pole_par[1] + pole_par[1]*0.1);
   FF_fittepole->SetParLimits(2,pole_par[2] - pole_par[2]*0.5,pole_par[2] + pole_par[2]*0.5);
   
   //for flat
   double pole_parII[3] = {10, 0.59,0.0144}; //{A,Lambda,Gamma}
   
   TF1 *FF_fittepoleII = new TF1("FF_fittepoleII", Pole_FFII,0.02,0.85,3);
   FF_fittepoleII->SetParameters(&pole_parII[0]);
   FF_fittepoleII->SetParLimits(0,0.,100.);
   FF_fittepoleII->SetParLimits(1,pole_parII[1] - pole_parII[1]*0.1,pole_parII[1] + pole_parII[1]*0.1);
   FF_fittepoleII->SetParLimits(2,pole_parII[2] - pole_parII[2]*0.5,pole_parII[2] + pole_parII[2]*0.5);
   FF_fittepoleII->SetLineColor(kBlue);
   //TF1 *FF_fitterGaus = new TF1("FF_fitterGaus","gaus",0.55,0.92);
   
   TCanvas *cmkI =  new TCanvas("cmkI","cmkI",1200,500);
   
   TH1D *hEpEm_QEDnorm = (TH1D*)in->Get("hEpEm_QEDnorm");
   cmkI->cd();
   hEpEm_QEDnorm->SetTitle("Expected distribution of |F(q^{2})|^{2}");
   hEpEm_QEDnorm->SetLineColor(kBlack);
   hEpEm_QEDnorm->SetYTitle("|F(q^{2})|^{2}");
   hEpEm_QEDnorm->GetYaxis()->SetTitleSize(0.05);
   hEpEm_QEDnorm->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_QEDnorm->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_QEDnorm->GetXaxis()->SetTitleSize(0.05);
   hEpEm_QEDnorm->GetXaxis()->SetTitleOffset(0.8);
   hEpEm_QEDnorm->Draw("EP");
   hEpEm_QEDnorm_flat->SetLineColor(8);
   hEpEm_QEDnorm_flat->Draw("EP same");
   hEpEm_QEDnorm_flat->Fit("FF_fittepoleII","REM");
   hEpEm_QEDnorm->Fit("FF_fittepole","REM+");
   
   Double_t Lambda = FF_fittepole->GetParameter(1);
   Double_t Lambdaerr = FF_fittepole->GetParError(1);
   Double_t bn = 1./Lambda;
   Double_t bn_err = Lambdaerr/(bn*bn);
   
   
   Double_t Lambda_flat = FF_fittepoleII->GetParameter(1);
   Double_t Lambdaerr_flat = FF_fittepoleII->GetParError(1);
   Double_t bn_flat = 1./Lambda_flat;
   Double_t bn_err_flat = Lambdaerr_flat/(bn_flat*bn_flat);
   
   
   TString sLambda = Form("#Lambda^{2}_{fit}  = %2.4f #pm %2.4f  ", Lambda,Lambdaerr);
   TString sbn = Form("b_{n} = %2.4f #pm %2.4f  ", bn,bn_err);
   
   TString sLambda_gen = Form("#Lambda^{2}_{gen}  = %2.4f  ", 0.5776);
   TString sbn_gen = Form("b_{n gen} = %2.4f  ", 1./0.5776);
   
   TString sLambda_flat = Form("#Lambda^{2}_{fit}  = %2.4f #pm %2.4f  ", Lambda_flat,Lambdaerr_flat);
   TString sbn_flat = Form("b_{n} = %2.4f #pm %2.4f  ", bn_flat,bn_err_flat);
   >>>>>>> master
   
   TCanvas *cmkII =  new TCanvas("cmkII","cmkII",1200,500);
   //cmkII->Divide(1,2);
   cmkII->cd();
   cmkII->SetLogy();
   TH1D *hIVEpEm_cut_clone = (TH1D*)in->Get("hIVEpEm_cut_clone");
   hIVEpEm_cut_clone->SetLineColor(kRed);
   hIVEpEm_cut_clone->SetYTitle("Expected Counts / 10 MeV");
   hIVEpEm_cut_clone->GetYaxis()->SetTitleSize(0.05);
   hIVEpEm_cut_clone->GetYaxis()->SetTitleOffset(0.8);
   hIVEpEm_cut_clone->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hIVEpEm_cut_clone->GetXaxis()->SetTitleSize(0.05);
   hIVEpEm_cut_clone->GetXaxis()->SetTitleOffset(0.8);
   TH1D *hEpEm_corrected = (TH1D*)in->Get("hEpEm_corrected");
   hEpEm_corrected->SetYTitle("Counts / 10 MeV");
   hEpEm_corrected->GetYaxis()->SetTitleSize(0.05);
   hEpEm_corrected->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_corrected->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_corrected->GetXaxis()->SetTitleSize(0.05);
   hEpEm_corrected->Draw("EP");
   hIVEpEm_cut_clone->Draw("EP same");
   
   TLegend *legmkII = new TLegend(0.45,0.7,0.9,0.9);
   legmkII->SetTextSize(0.05);
   legmkII->SetFillColor(0);
   legmkII->AddEntry(hIVEpEm_cut_clone,"Expected counts in 80 days","l");
   
   legmkII->AddEntry(hEpEm_corrected,"Accepted corrected counts in 80 days","l");
   legmkII->Draw("same");
   
   
   TCanvas *cmkIII =  new TCanvas("cmkIII","cmkIII",1200,500);
   cmkIII->cd();
   TH1D *hEpEm_acceptance = (TH1D*)in->Get("hEpEm_acceptance");
   hEpEm_acceptance->SetLineColor(kRed);
   hEpEm_acceptance->SetYTitle("Acceptance / 10 MeV");
   hEpEm_acceptance->GetYaxis()->SetTitleSize(0.05);
   hEpEm_acceptance->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_acceptance->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_acceptance->GetXaxis()->SetTitleSize(0.05);
   hEpEm_acceptance->GetXaxis()->SetTitleOffset(0.8);
   TH1D *hEpEm_acceptance_flat = (TH1D*)inflat->Get("hEpEm_acceptance");
   hEpEm_acceptance_flat->SetYTitle("Acceptance / 10 MeV");
   hEpEm_acceptance_flat->GetYaxis()->SetTitleSize(0.05);
   hEpEm_acceptance_flat->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_acceptance_flat->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_acceptance_flat->GetXaxis()->SetTitleSize(0.05);
   hEpEm_acceptance_flat->GetXaxis()->SetTitleOffset(0.8);
   hEpEm_acceptance->GetYaxis()->SetRangeUser(0,0.16);
   hEpEm_acceptance->Draw("EP");
   hEpEm_acceptance_flat->Draw("EP same");
   
   TLegend *legmkIII = new TLegend(0.11,0.7,0.45,0.9);
   legmkIII->SetTextSize(0.05);
   legmkIII->SetFillColor(0);
   legmkIII->AddEntry(hEpEm_acceptance,"QED+VMD M(e^{+}e^{-}) Acceptance","l");
   
   legmkIII->AddEntry(hEpEm_acceptance_flat,"Flat M(e^{+}e^{-}) Acceptance","l");
   legmkIII->Draw("same");
   
   
   //
   double QED_par[8] = {0.957}; //{Mass}
   TF1 *QED_norm = new TF1("QED_norm",Eval_Kroll_wada,0.,1.,1);
   QED_norm->SetParameters(&QED_par[0]);
   
   TH1D *hEpEm_corrected_flat = new TH1D("hEpEm_corrected_flat","hEpEm_corrected_flat",100,0.0,1);
   TH1D *hEpEm_QEDnorm_flat = new TH1D("hEpEm_QEDnorm_flat","hEpEm_QEDnorm_flat",100,0.0,1);
   for (int i = 1; i<hIVEpEm_cut_clone->GetNbinsX(); i++) {
   
   Double_t bin_factor = 1.65; //this needs to be solved at somepoint
   Double_t intotal_acceptance = hEpEm_acceptance_flat->GetBinContent(i)*bin_factor;
   Double_t intotal_events_upper;
   if (intotal_acceptance == 0) {
   intotal_events_upper = 0;
   }else{
   intotal_events_upper = hIVEpEm_cut_clone->GetBinContent(i)/intotal_acceptance;
   }
   hEpEm_corrected_flat->SetBinContent(i,intotal_events_upper);
   hEpEm_corrected_flat->SetBinError(i,sqrt(intotal_events_upper));
   
   Double_t QED_factor = QED_norm->Eval(hIVEpEm_cut_clone->GetBinCenter(i));//2.0e-06;
   
   hEpEm_QEDnorm_flat->SetBinContent(i,intotal_events_upper/QED_factor);
   //hEpEm_QEDnorm->SetBinError(i,sqrt(intotal_events_upper/QED_factor));
   
   }
   
   
   
   //
   
   double pole_par[3] = {10, 0.59,0.0144}; //{A,Lambda,Gamma}
   
   TF1 *FF_fittepole = new TF1("FF_fittepole", Pole_FFII,0.02,0.92,3);
   FF_fittepole->SetParameters(&pole_par[0]);
   FF_fittepole->SetParLimits(0,0.,100.);
   FF_fittepole->SetParLimits(1,pole_par[1] - pole_par[1]*0.1,pole_par[1] + pole_par[1]*0.1);
   FF_fittepole->SetParLimits(2,pole_par[2] - pole_par[2]*0.5,pole_par[2] + pole_par[2]*0.5);
   
   //for flat
   double pole_parII[3] = {10, 0.59,0.0144}; //{A,Lambda,Gamma}
   
   TF1 *FF_fittepoleII = new TF1("FF_fittepoleII", Pole_FFII,0.02,0.85,3);
   FF_fittepoleII->SetParameters(&pole_parII[0]);
   FF_fittepoleII->SetParLimits(0,0.,100.);
   FF_fittepoleII->SetParLimits(1,pole_parII[1] - pole_parII[1]*0.1,pole_parII[1] + pole_parII[1]*0.1);
   FF_fittepoleII->SetParLimits(2,pole_parII[2] - pole_parII[2]*0.5,pole_parII[2] + pole_parII[2]*0.5);
   FF_fittepoleII->SetLineColor(kBlue);
   //TF1 *FF_fitterGaus = new TF1("FF_fitterGaus","gaus",0.55,0.92);
   
   TCanvas *cmkI =  new TCanvas("cmkI","cmkI",1200,500);
   
   TH1D *hEpEm_QEDnorm = (TH1D*)in->Get("hEpEm_QEDnorm");
   cmkI->cd();
   hEpEm_QEDnorm->SetTitle("Expected distribution of |F(q^{2})|^{2}");
   hEpEm_QEDnorm->SetLineColor(kBlack);
   hEpEm_QEDnorm->SetYTitle("|F(q^{2})|^{2}");
   hEpEm_QEDnorm->GetYaxis()->SetTitleSize(0.05);
   hEpEm_QEDnorm->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_QEDnorm->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_QEDnorm->GetXaxis()->SetTitleSize(0.05);
   hEpEm_QEDnorm->GetXaxis()->SetTitleOffset(0.8);
   hEpEm_QEDnorm->Draw("EP");
   hEpEm_QEDnorm_flat->SetLineColor(8);
   hEpEm_QEDnorm_flat->Draw("EP same");
   hEpEm_QEDnorm_flat->Fit("FF_fittepoleII","REM");
   hEpEm_QEDnorm->Fit("FF_fittepole","REM+");
   
   Double_t Lambda = FF_fittepole->GetParameter(1);
   Double_t Lambdaerr = FF_fittepole->GetParError(1);
   Double_t bn = 1./Lambda;
   Double_t bn_err = Lambdaerr/(bn*bn);
   
   
   Double_t Lambda_flat = FF_fittepoleII->GetParameter(1);
   Double_t Lambdaerr_flat = FF_fittepoleII->GetParError(1);
   Double_t bn_flat = 1./Lambda_flat;
   Double_t bn_err_flat = Lambdaerr_flat/(bn_flat*bn_flat);
   
   
   TString sLambda = Form("#Lambda^{2}_{fit}  = %2.4f #pm %2.4f  ", Lambda,Lambdaerr);
   TString sbn = Form("b_{n} = %2.4f #pm %2.4f  ", bn,bn_err);
   
   TString sLambda_gen = Form("#Lambda^{2}_{gen}  = %2.4f  ", 0.5776);
   TString sbn_gen = Form("b_{n gen} = %2.4f  ", 1./0.5776);
   
   TString sLambda_flat = Form("#Lambda^{2}_{fit}  = %2.4f #pm %2.4f  ", Lambda_flat,Lambdaerr_flat);
   TString sbn_flat = Form("b_{n} = %2.4f #pm %2.4f  ", bn_flat,bn_err_flat);
   
   TLegend *legmkII = new TLegend(0.45,0.7,0.9,0.9);
   legmkII->SetTextSize(0.05);
   legmkII->SetFillColor(0);
   legmkII->AddEntry(hIVEpEm_cut_clone,"Expected counts in 80 days","l");
   
   legmkII->AddEntry(hEpEm_corrected,"Accepted corrected counts in 80 days","l");
   legmkII->Draw("same");
   
   
   TCanvas *cmkIII =  new TCanvas("cmkIII","cmkIII",1200,500);
   cmkIII->cd();
   TH1D *hEpEm_acceptance = (TH1D*)in->Get("hEpEm_acceptance");
   hEpEm_acceptance->SetLineColor(kRed);
   hEpEm_acceptance->SetYTitle("Acceptance / 10 MeV");
   hEpEm_acceptance->GetYaxis()->SetTitleSize(0.05);
   hEpEm_acceptance->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_acceptance->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_acceptance->GetXaxis()->SetTitleSize(0.05);
   hEpEm_acceptance->GetXaxis()->SetTitleOffset(0.8);
   TH1D *hEpEm_acceptance_flat = (TH1D*)inflat->Get("hEpEm_acceptance");
   hEpEm_acceptance_flat->SetYTitle("Acceptance / 10 MeV");
   hEpEm_acceptance_flat->GetYaxis()->SetTitleSize(0.05);
   hEpEm_acceptance_flat->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_acceptance_flat->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_acceptance_flat->GetXaxis()->SetTitleSize(0.05);
   hEpEm_acceptance_flat->GetXaxis()->SetTitleOffset(0.8);
   hEpEm_acceptance->GetYaxis()->SetRangeUser(0,0.16);
   hEpEm_acceptance->Draw("EP");
   hEpEm_acceptance_flat->Draw("EP same");
   
   TLegend *legmkIII = new TLegend(0.11,0.7,0.45,0.9);
   legmkIII->SetTextSize(0.05);
   legmkIII->SetFillColor(0);
   legmkIII->AddEntry(hEpEm_acceptance,"QED+VMD M(e^{+}e^{-}) Acceptance","l");
   
   legmkIII->AddEntry(hEpEm_acceptance_flat,"Flat M(e^{+}e^{-}) Acceptance","l");
   legmkIII->Draw("same");
   
   
   //
   double QED_par[8] = {0.957}; //{Mass}
   TF1 *QED_norm = new TF1("QED_norm",Eval_Kroll_wada,0.,1.,1);
   QED_norm->SetParameters(&QED_par[0]);
   
   TH1D *hEpEm_corrected_flat = new TH1D("hEpEm_corrected_flat","hEpEm_corrected_flat",100,0.0,1);
   TH1D *hEpEm_QEDnorm_flat = new TH1D("hEpEm_QEDnorm_flat","hEpEm_QEDnorm_flat",100,0.0,1);
   for (int i = 1; i<hIVEpEm_cut_clone->GetNbinsX(); i++) {
   
   Double_t bin_factor = 1.65; //this needs to be solved at somepoint
   Double_t intotal_acceptance = hEpEm_acceptance_flat->GetBinContent(i)*bin_factor;
   Double_t intotal_events_upper;
   if (intotal_acceptance == 0) {
   intotal_events_upper = 0;
   }else{
   intotal_events_upper = hIVEpEm_cut_clone->GetBinContent(i)/intotal_acceptance;
   }
   hEpEm_corrected_flat->SetBinContent(i,intotal_events_upper);
   hEpEm_corrected_flat->SetBinError(i,sqrt(intotal_events_upper));
   
   Double_t QED_factor = QED_norm->Eval(hIVEpEm_cut_clone->GetBinCenter(i));//2.0e-06;
   
   hEpEm_QEDnorm_flat->SetBinContent(i,intotal_events_upper/QED_factor);
   //hEpEm_QEDnorm->SetBinError(i,sqrt(intotal_events_upper/QED_factor));
   
   }
   
   
   
   //
   
   double pole_par[3] = {10, 0.59,0.0144}; //{A,Lambda,Gamma}
   
   TF1 *FF_fittepole = new TF1("FF_fittepole", Pole_FFII,0.02,0.92,3);
   FF_fittepole->SetParameters(&pole_par[0]);
   FF_fittepole->SetParLimits(0,0.,100.);
   FF_fittepole->SetParLimits(1,pole_par[1] - pole_par[1]*0.1,pole_par[1] + pole_par[1]*0.1);
   FF_fittepole->SetParLimits(2,pole_par[2] - pole_par[2]*0.5,pole_par[2] + pole_par[2]*0.5);
   
   //for flat
   double pole_parII[3] = {10, 0.59,0.0144}; //{A,Lambda,Gamma}
   
   TF1 *FF_fittepoleII = new TF1("FF_fittepoleII", Pole_FFII,0.02,0.85,3);
   FF_fittepoleII->SetParameters(&pole_parII[0]);
   FF_fittepoleII->SetParLimits(0,0.,100.);
   FF_fittepoleII->SetParLimits(1,pole_parII[1] - pole_parII[1]*0.1,pole_parII[1] + pole_parII[1]*0.1);
   FF_fittepoleII->SetParLimits(2,pole_parII[2] - pole_parII[2]*0.5,pole_parII[2] + pole_parII[2]*0.5);
   FF_fittepoleII->SetLineColor(kBlue);
   //TF1 *FF_fitterGaus = new TF1("FF_fitterGaus","gaus",0.55,0.92);
   
   TCanvas *cmkI =  new TCanvas("cmkI","cmkI",1200,500);
   
   TH1D *hEpEm_QEDnorm = (TH1D*)in->Get("hEpEm_QEDnorm");
   cmkI->cd();
   hEpEm_QEDnorm->SetTitle("Expected distribution of |F(q^{2})|^{2}");
   hEpEm_QEDnorm->SetLineColor(kBlack);
   hEpEm_QEDnorm->SetYTitle("|F(q^{2})|^{2}");
   hEpEm_QEDnorm->GetYaxis()->SetTitleSize(0.05);
   hEpEm_QEDnorm->GetYaxis()->SetTitleOffset(0.8);
   hEpEm_QEDnorm->GetXaxis()->SetTitle("M(e^{+}e^{-}) [GeV]");
   hEpEm_QEDnorm->GetXaxis()->SetTitleSize(0.05);
   hEpEm_QEDnorm->GetXaxis()->SetTitleOffset(0.8);
   hEpEm_QEDnorm->Draw("EP");
   hEpEm_QEDnorm_flat->SetLineColor(8);
   hEpEm_QEDnorm_flat->Draw("EP same");
   hEpEm_QEDnorm_flat->Fit("FF_fittepoleII","REM");
   hEpEm_QEDnorm->Fit("FF_fittepole","REM+");
   
   Double_t Lambda = FF_fittepole->GetParameter(1);
   Double_t Lambdaerr = FF_fittepole->GetParError(1);
   Double_t bn = 1./Lambda;
   Double_t bn_err = Lambdaerr/(bn*bn);
   
   
   Double_t Lambda_flat = FF_fittepoleII->GetParameter(1);
   Double_t Lambdaerr_flat = FF_fittepoleII->GetParError(1);
   Double_t bn_flat = 1./Lambda_flat;
   Double_t bn_err_flat = Lambdaerr_flat/(bn_flat*bn_flat);
   
   
   TString sLambda = Form("#Lambda^{2}_{fit}  = %2.4f #pm %2.4f  ", Lambda,Lambdaerr);
   TString sbn = Form("b_{n} = %2.4f #pm %2.4f  ", bn,bn_err);
   
   TString sLambda_gen = Form("#Lambda^{2}_{gen}  = %2.4f  ", 0.5776);
   TString sbn_gen = Form("b_{n gen} = %2.4f  ", 1./0.5776);
   
   TString sLambda_flat = Form("#Lambda^{2}_{fit}  = %2.4f #pm %2.4f  ", Lambda_flat,Lambdaerr_flat);
   TString sbn_flat = Form("b_{n} = %2.4f #pm %2.4f  ", bn_flat,bn_err_flat);
   
   
   TLegend *legmkI = new TLegend(0.12,0.55,0.37,0.9);
   legmkI->SetTextSize(0.04);
   
   legmkI->SetHeader("\t QED+VMD M(e^{+}e^{-}) Acceptance");
   legmkI->SetFillColor(0);
   legmkI->AddEntry(FF_fittepole,sLambda,"l");
   legmkI->AddEntry((TObject*)0,sbn,"");
   legmkI->AddEntry((TObject*)0,sLambda_gen,"");
   legmkI->AddEntry((TObject*)0,sbn_gen,"");
   legmkI->Draw("same");
   
   TLegend *legmkI_I = new TLegend(0.37,0.55,0.57,0.9);
   legmkI_I->SetTextSize(0.04);
   
   legmkI_I->SetHeader("\t Flat M(e^{+}e^{-}) Acceptance");
   legmkI_I->SetFillColor(0);
   legmkI_I->AddEntry(FF_fittepoleII,sLambda_flat,"l");
   legmkI_I->AddEntry((TObject*)0,sbn_flat,"");
   legmkI_I->AddEntry((TObject*)0,"","");
   legmkI_I->AddEntry((TObject*)0,"","");
   
   legmkI_I->Draw("same");
   */
}
예제 #30
0
파일: dimuonDM.C 프로젝트: KiSooLee/Bntuple
void dimuonLoop(float ptmin, float ptmax, float ymin, float ymax, int i)
{
  TFile *infData = new TFile(inputdata);
  TFile *infMC = new TFile(inputmc);
  TTree *ntData = (TTree*) infData->Get("ntKp");
  TTree *ntMC = (TTree*) infMC->Get("ntKp");

  TCanvas *c = new TCanvas(Form("c%i",i),"",600,600);
  //if (logy) c->SetLogy();
  
  TH1D* hData = new TH1D("hData","",50,2.85,3.35);
  TH1D* hMC = new TH1D("hMC","",50,2.85,3.35);

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

  hData->Sumw2();

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

  hData->Sumw2();

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

  //hData->SetLineColor(kBlue+1);
  //hData->SetFillStyle(1001);
  //hData->SetFillColor(kBlue-9);
  //hData->SetLineWidth(3);
  hData->SetMarkerStyle(8);
  hData->SetStats(0);

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

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

  c->SaveAs(Form("MuonResult/plot_Bplus_chi2_trkPt/dimuon_yDM_%i.pdf",i));
  //c->SaveAs(Form("MuonResult/plot_Bplus_chi2_trkPt/dimuon_DM_%i.pdf",i));
  //c->SaveAs("MuonResult/plot_Bplus_chi2_trkPt/dimuon_DM_incl_1.pdf");
}