Example #1
0
void checkRsnPIDqa(TString filename, TString foldername, Bool_t savePng,
		   TString plotTPCpi, TString plotTPCka, TString plotTPCpro,
		   TString plotTTOFpi, TString plotTOFka, TString plotTOFpro)
{
  //Open input file 
  TFile * fin = TFile::Open(filename.Data());
  if (!fin) return 0x0;
  
  //Access output of specific wagon
  TList * list = (TList*) fin->Get(foldername.Data());
  if (!list) return 0x0;

  //Set range for fit
  Float_t RangeFitMomMin = 0.1; //range in momentum where to check the mean and pull
  Float_t RangeFitMomMax = 2.0;
  Int_t xbinFitMin = 0;
  Int_t xbinFitMax = -1;
  Float_t RangeFitNsigmaPIDmin = -2.0; //range in Nsigma where the fit is to be performed
  Float_t RangeFitNsigmaPIDmax = 2.0;

  //Set range for visualisation
  Float_t RangeShowTPC[2] = {0.1, 2.0}; 
  Float_t RangeShowTOF[2] = {0.25, 2.0};
    
  //--------------------------
  // TPC PID Nsigma
  // fit with simple gaussian
  //--------------------------
  //Gaussian function
  TF1 *fGaus = new TF1("f","gaus", -7.0, 7.0);

  //--- pions
  TH2F * hTPCsigmaPi = (TH2F*)list->FindObject(plotTPCpi.Data());
  hTPCsigmaPi->RebinX(2);
  hTPCsigmaPi->SetTitle("TPC Pions");
  MakeUpHisto(hTPCsigmaPi,"p_{TPC} (GeV/c)", "N#sigma_{TPC}", 1, kBlack, 2);
  hTPCsigmaPi->GetYaxis()->SetRangeUser(-5.1,5.1);
  hTPCsigmaPi->GetXaxis()->SetRangeUser(RangeShowTPC[0], RangeShowTPC[1]);
  xbinFitMin = hTPCsigmaPi->GetXaxis()->FindBin(RangeFitMomMin);
  xbinFitMax = hTPCsigmaPi->GetXaxis()->FindBin(RangeFitMomMax);
  hTPCsigmaPi->FitSlicesY(fGaus, xbinFitMin, xbinFitMax );
  TH1D * hTPCsigmaPi_mean = ((TH1D*)gDirectory->FindObject(Form("%s_1", plotTPCpi.Data())))->Clone("hNsigmaTPCpi_mean");
  TH1D * hTPCsigmaPi_pull = ((TH1D*)gDirectory->FindObject(Form("%s_2", plotTPCpi.Data())))->Clone("hNsigmaTPCpi_pull");
  MakeUpHisto(hTPCsigmaPi_mean, "", "", 1, kBlack, 2);
  MakeUpHisto(hTPCsigmaPi_pull, "", "", 1, kRed+2, 2);

  //--- kaons
  TH2F * hTPCsigmaKa = (TH2F*)list->FindObject(plotTPCka.Data());
  hTPCsigmaKa->RebinX(2);
  hTPCsigmaKa->SetTitle("TPC Kaons");
  hTPCsigmaKa->GetYaxis()->SetRangeUser(-5.1,5.1);
  hTPCsigmaKa->GetXaxis()->SetRangeUser(RangeShowTPC[0], RangeShowTPC[1]);
  hTPCsigmaKa->FitSlicesY(fGaus, xbinFitMin, xbinFitMax );
  MakeUpHisto(hTPCsigmaKa,"p_{TPC} (GeV/c)", "N#sigma_{TPC}", 1, kBlack, 2);
  TH1D * hTPCsigmaKa_mean = ((TH1D*)gDirectory->FindObject(Form("%s_1", plotTPCka.Data())))->Clone("hNsigmaTPCka_mean");
  TH1D * hTPCsigmaKa_pull = ((TH1D*)gDirectory->FindObject(Form("%s_2", plotTPCka.Data())))->Clone("hNsigmaTPCka_pull");
  MakeUpHisto(hTPCsigmaKa_mean, "", "", 1, kBlack, 2);
  MakeUpHisto(hTPCsigmaKa_pull, "", "", 1, kRed+2, 2);

  //--- protons
  TH2F * hTPCsigmaPro = (TH2F*)list->FindObject(plotTPCpro.Data());
  hTPCsigmaPro->RebinX(2);
  hTPCsigmaPro->SetTitle("TPC Protons");
  MakeUpHisto(hTPCsigmaPro,"p_{TPC} (GeV/c)", "N#sigma_{TPC}", 1, kBlack, 2);
  hTPCsigmaPro->GetYaxis()->SetRangeUser(-5.1,5.1);
  hTPCsigmaPro->GetXaxis()->SetRangeUser(RangeShowTPC[0], RangeShowTPC[1]);
  hTPCsigmaPro->FitSlicesY(fGaus, xbinFitMin, xbinFitMax );
  TH1D * hTPCsigmaPro_mean = ((TH1D*)gDirectory->FindObject(Form("%s_1", plotTPCpro.Data())))->Clone("hNsigmaTPCpro_mean");
  TH1D * hTPCsigmaPro_pull = ((TH1D*)gDirectory->FindObject(Form("%s_2", plotTPCpro.Data())))->Clone("hNsigmaTPCpro_pull");
  MakeUpHisto(hTPCsigmaPro_mean, "", "", 1, kBlack, 2);
  MakeUpHisto(hTPCsigmaPro_pull, "", "", 1, kRed+2, 2);

   //--- plot TPC
  TLine *l11=new TLine(RangeShowTPC[0],0.,RangeShowTPC[1],0.); l11->SetLineWidth(1); l11->SetLineStyle(7);
  TLine *l12=new TLine(RangeShowTPC[0],1.,RangeShowTPC[1],1.); l12->SetLineWidth(1); l12->SetLineStyle(7);

  gStyle->SetOptStat(0);
  TCanvas *cPidPerformance4 = new TCanvas("cPIDperformance4","TPC PID",1200,500);
  cPidPerformance4->Divide(3,1);
  cPidPerformance4->cd(1);
  gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
  hTPCsigmaPi->DrawCopy("colz");
  hTPCsigmaPi_mean->DrawCopy("same");
  hTPCsigmaPi_pull->DrawCopy("same");
  l11->Draw("same"); l12->Draw("same");

  cPidPerformance4->cd(2);
  gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
  hTPCsigmaKa->DrawCopy("colz");
  hTPCsigmaKa_mean->DrawCopy("same");
  hTPCsigmaKa_pull->DrawCopy("same");
  l11->Draw("same"); l12->Draw("same");

  cPidPerformance4->cd(3);
  gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
  hTPCsigmaPro->DrawCopy("colz");
  hTPCsigmaPro_mean->DrawCopy("same");
  hTPCsigmaPro_pull->DrawCopy("same");
  l11->Draw("same"); l12->Draw("same");

  TLegend * pidLegTPC = new TLegend(0.15,0.8,0.88,0.88);
  pidLegTPC->SetBorderSize(0); pidLegTPC->SetFillStyle(1001); pidLegTPC->SetFillColor(kWhite);
  pidLegTPC->SetTextSize(0.04); pidLegTPC->SetNColumns(2);
  pidLegTPC->AddEntry(hTPCsigmaPro_mean,"Mean","lp");
  pidLegTPC->AddEntry(hTPCsigmaPro_pull,Form("#sigma, Gaus fit (%2.1f,%2.1f)",RangeFitNsigmaPIDmin,RangeFitNsigmaPIDmax),"lp");
  pidLegTPC->Draw("same");

  if (savePng) cPidPerformance4->SaveAs("RsnQA_TPC_Nsigma.png");
  
  //----------------------------------------------------
  // TOF
  // fit with signal model = gaussian + exponential tail
  //----------------------------------------------------
  //Signal model for TOF signal = gaus + exp tail
  const Int_t npars = 6;
  TF1 *fSignalModel = new TF1("fSignalModel", TOFsignal, -7.0, 7.0, npars);
  fSignalModel->SetTitle("TOF Signal");
  fSignalModel->SetParameter(0, 1.);
  fSignalModel->SetParameter(1, 0.);
  fSignalModel->SetParLimits(1, -2., 1.);
  fSignalModel->SetParameter(2, 1.);
  fSignalModel->SetParLimits(2, 0.5, 2.);
  fSignalModel->SetParameter(3, 1.);
  fSignalModel->SetParLimits(3, 0.5, 1.5);
  fSignalModel->SetParameter(4, 1.);
  fSignalModel->SetParLimits(4, 0., 1.e8);
  fSignalModel->SetParameter(5, 0.);
  fSignalModel->SetParLimits(5, -10., 10.);
  fSignalModel->SetNpx(2000);
  fSignalModel->SetParNames("Norm", "Mean", "Sigma", "Tail", "Shift", "Slope"/*, "Square"*/);
  fSignalModel->SetLineColor(kRed+1);

  //results
  TObjArray *results[3];
  for(Int_t i = 0; i < 3; i++){
    results[i] = new TObjArray(10);
  }
  TH1D * par[3][npars];
  //--- pions
  TH2F * hTOFsigmaPi = (TH2F*)list->FindObject(plotTOFpi.Data());
  hTOFsigmaPi->SetTitle("TOF Pions");
  hTOFsigmaPi->RebinX(2);
  MakeUpHisto(hTOFsigmaPi,"p (GeV/c)", "N#sigma_{TOF}", 1, kBlack, 2);
  hTOFsigmaPi->GetYaxis()->SetRangeUser(-5.1,5.1);
  hTOFsigmaPi->GetXaxis()->SetRangeUser(RangeShowTOF[0], RangeShowTOF[1]);
  fSignalModel->SetParLimits(4, 0., hTOFsigmaPi->GetMaximum()*0.5);
  fSignalModel->SetParLimits(0, 0., hTOFsigmaPi->GetMaximum()*1.2);
  hTOFsigmaPi->FitSlicesY(fSignalModel, xbinFitMin, xbinFitMax, 0, "QR", results[0] );
  for(Int_t cc = 0; cc < npars ; cc++) {
    par[0][cc] = (TH1D*)gDirectory->FindObject(Form("%s_%i", plotTOFpi.Data(), cc));
  }
  MakeUpHisto(par[0][1], "", "", 1, kBlue, 2);
  MakeUpHisto(par[0][2], "", "", 1, kMagenta+2, 2);
  
  //--- KAONS
  TH2F * hTOFsigmaKa = (TH2F*)list->FindObject(plotTOFka.Data());
  hTOFsigmaKa->SetTitle("TOF Kaons");
  hTOFsigmaKa->RebinX(2);
  MakeUpHisto(hTOFsigmaKa,"p (GeV/c)", "N#sigma_{TOF}", 1, kBlack, 2);
  hTOFsigmaKa->GetYaxis()->SetRangeUser(-5.1,5.1);
  hTOFsigmaKa->GetXaxis()->SetRangeUser(RangeShowTOF[0], RangeShowTOF[1]);
  fSignalModel->SetParLimits(4, 0., hTOFsigmaKa->GetMaximum()*0.5);
  fSignalModel->SetParLimits(0, 0., hTOFsigmaKa->GetMaximum()*1.2);
  hTOFsigmaKa->FitSlicesY(fSignalModel, xbinFitMin, xbinFitMax, 0, "QR", results[0] );
  for(Int_t cc = 0; cc < npars ; cc++) {
    par[1][cc] = (TH1D*)gDirectory->FindObject(Form("%s_%i", plotTOFka.Data(), cc));
  }
  MakeUpHisto(par[1][1], "", "", 1, kBlue, 2);
  MakeUpHisto(par[1][2], "", "", 1, kMagenta+2, 2);

  //--- protons
  TH2F * hTOFsigmaPro = (TH2F*)list->FindObject(plotTOFpro.Data());
  hTOFsigmaPro->SetTitle("TOF Protons");
  hTOFsigmaPro->RebinX(2);
  MakeUpHisto(hTOFsigmaPro,"p (GeV/c)", "N#sigma_{TOF}", 1, kBlack, 2);
  hTOFsigmaPro->GetYaxis()->SetRangeUser(-5.1,5.1);
  hTOFsigmaPro->GetXaxis()->SetRangeUser(RangeShowTOF[0], RangeShowTOF[1]);
  fSignalModel->SetParLimits(4, 0., hTOFsigmaPro->GetMaximum()*0.5);
  fSignalModel->SetParLimits(0, 0., hTOFsigmaPro->GetMaximum()*1.2);
  hTOFsigmaPro->FitSlicesY(fSignalModel, xbinFitMin, xbinFitMax, 0, "QR", results[0] );
  for(Int_t cc = 0; cc < npars ; cc++) {
    par[2][cc] = (TH1D*)gDirectory->FindObject(Form("%s_%i", plotTOFpro.Data(), cc));
  }
  MakeUpHisto(par[2][1], "", "", 1, kBlue, 2);
  MakeUpHisto(par[2][2], "", "", 1, kMagenta+2, 2);

  //--- plot TOF
  gStyle->SetOptStat(0);
  TCanvas *cPidPerformance3 = new TCanvas("cPidPerformance3","TOF PID performance",1200,500);
  cPidPerformance3->Divide(3,1);
  cPidPerformance3->cd(1);
  gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
  hTOFsigmaPi->DrawCopy("colz");
  if(par[0][1]) par[0][1]->DrawCopy("same");
  if(par[0][2]) par[0][2]->DrawCopy("same");
  l11->Draw("same"); l12->Draw("same");

  cPidPerformance3->cd(2);
  gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
  hTOFsigmaKa->DrawCopy("colz");
  if(par[1][1]) par[1][1]->DrawCopy("same");
  if(par[1][2]) par[1][2]->DrawCopy("same");
  l11->Draw("same"); l12->Draw("same");

  cPidPerformance3->cd(3);
  gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
  hTOFsigmaPro->DrawCopy("colz");
  if(par[2][1]) par[2][1]->DrawCopy("same");
  if(par[2][2]) par[2][2]->DrawCopy("same");
  l11->Draw("same"); l12->Draw("same");

  TLegend * pidLegTOF = new TLegend(0.15,0.8,0.88,0.88);
  pidLegTOF->SetBorderSize(0); pidLegTOF->SetFillStyle(1001); pidLegTOF->SetFillColor(kWhite);
  pidLegTOF->SetTextSize(0.04); pidLegTOF->SetNColumns(2);
  pidLegTOF->AddEntry(par[0][1],"Mean","lp");
  pidLegTOF->AddEntry(par[0][2], Form("#sigma, Gaus+Tail fit (%2.1f,%2.1f)",RangeFitNsigmaPIDmin, RangeFitNsigmaPIDmax),"lp");
  pidLegTOF->Draw("same");
  
  if (savePng) cPidPerformance3->Print("RsnQA_TOF_Nsigma.png");
  return;
}
Example #2
0
void ana_Run11_eff()
{

  const int rebin = 1;

  TFile *f = TFile::Open("Rootfiles/Run11_eff.root","read");

  // Run with weigth
  TH2F *hMcPtVsEta = (TH2F*)f->Get("mcJpsiPtY");
  TH2F *hRcPtVsEta = (TH2F*)f->Get("hHt2JpsiPE");

  draw2D(hMcPtVsEta);
  draw2D(hRcPtVsEta);

  hMcPtVsEta->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6);
  TH1F *hMcPt = (TH1F*)hMcPtVsEta->ProjectionY("hMcPt");
  hMcPt->Rebin(rebin);
  hMcPt->SetMarkerStyle(20);
  draw1D(hMcPt,"",kTRUE);

  hRcPtVsEta->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6);
  TH1F *hRcPt = (TH1F*)hRcPtVsEta->ProjectionY("hRcPt");
  hRcPt->Rebin(rebin);
  hRcPt->SetMarkerStyle(21);
  hRcPt->SetMarkerColor(2);
  hRcPt->SetLineColor(2);
  hRcPt->Draw("sames P");

  TH1F *hRatio = (TH1F*)hRcPt->Clone("hRatio_fromRunning");
  hRatio->Rebin(100);
  hMcPt->Rebin(100);
  hRatio->Divide(hMcPt);
  cEff = draw1D(hRatio,"");

  // Run without weight
  TH2F *hMcPtVsEtaNoWeight = (TH2F*)f->Get("mcJpsiPtY_Or");
  draw2D(hMcPtVsEtaNoWeight);  

  TH2F *hMcPtVsRcNoWeight = (TH2F*)f->Get("hJpsiRcvsMC_Cut1");
  hMcPtVsRcNoWeight->RebinX(rebin);
  hMcPtVsRcNoWeight->RebinY(rebin);
  draw2D(hMcPtVsRcNoWeight);

  hMcPtVsEtaNoWeight->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6);
  TH1F *hMcPtNoWeight = (TH1F*)hMcPtVsEtaNoWeight->ProjectionY("hMcPtNoWeight");
  hMcPtNoWeight->Rebin(rebin);
  hMcPtNoWeight->SetMarkerStyle(20);
  hMcPtNoWeight->SetMinimum(1);
  draw1D(hMcPtNoWeight,"",kTRUE);

  TH1F *hRcPtNoWeight = (TH1F*)hMcPtVsRcNoWeight->ProjectionX("hRcPtNoWeight");
  hRcPtNoWeight->SetMarkerStyle(21);
  hRcPtNoWeight->SetMarkerColor(2);
  hRcPtNoWeight->SetLineColor(2);
  hRcPtNoWeight->Draw("sames P");

  TH1F *hRatioNoWeight = (TH1F*)hRcPtNoWeight->Clone("hRatioNoWeight");
  hRatioNoWeight->Divide(hMcPtNoWeight);
  cEff->cd();
  hRatioNoWeight->SetMarkerColor(4);
  hRatioNoWeight->Draw("samesP");

  // weight with input histogram
  TH1F *hMcPtWeight = (TH1F*)hMcPtNoWeight->Clone("hMcPtWeight");
  TH2F *hMcPtVsRcWeight = (TH2F*)hMcPtVsRcNoWeight->Clone("hMcPtVsRcWeight");
  for(int ibin=1; ibin<=hMcPtVsRcNoWeight->GetNbinsX(); ibin++)
    {
      double scale = hMcPt->GetBinContent(ibin);
      hMcPtWeight->SetBinContent(ibin,hMcPtWeight->GetBinContent(ibin)*scale);
      hMcPtWeight->SetBinError(ibin,hMcPtWeight->GetBinError(ibin)*scale);
      for(int jbin=1; jbin<=hMcPtVsRcNoWeight->GetNbinsY(); jbin++)
	{
	  hMcPtVsRcWeight->SetBinContent(ibin,jbin,hMcPtVsRcWeight->GetBinContent(ibin,jbin)*scale);
	  hMcPtVsRcWeight->SetBinError(ibin,jbin,hMcPtVsRcWeight->GetBinError(ibin,jbin)*scale);
	}
    }
  TH1F *hRcPtWeight = (TH1F*)hMcPtVsRcWeight->ProjectionY("hRcPtWeight");
  hRcPtWeight->SetMarkerStyle(21);
  hRcPtWeight->SetMarkerColor(2);
  hRcPtWeight->SetLineColor(2);

  draw2D(hMcPtVsRcWeight);
  draw1D(hMcPtWeight,"",kTRUE);
  hRcPtWeight->Draw("sames P");
  
  TH1F *hRatioWeight = (TH1F*)hRcPtWeight->Clone("hRatioWeight");
  hRatioWeight->Divide(hMcPtWeight);
  cEff->cd();
  hRatioWeight->SetMarkerColor(6);
  hRatioWeight->Draw("samesP");

  TH1F *hCheck = (TH1F*)hRatioWeight->Clone("check");
  hCheck->Divide(hRatio);
  draw1D(hCheck);

  // weight with fitted function
  TCanvas *c = new TCanvas("Fit","Fit",800,600);
  SetPadMargin(gPad,0.15,0.15);
  gPad->SetLogy();
  TH1F *h = new TH1F("histogram",";;;",7,0,30);
  h->GetYaxis()->SetRangeUser(1e-7,100);
  h->Draw();

  TFile *fdata = TFile::Open("Rootfiles/Spectrum_in_bin.root","read");
  TGraphErrors	*gr = (TGraphErrors*)fdata->Get("gall");
  gr->SetMarkerColor(1);
  gr->SetLineColor(1);
  gr->GetXaxis()->SetRangeUser(0,30);
  gr->Draw("sames PE");
  TF1 *func = new TF1("func",InvPt,0,30,4);
  func->SetParameters(0.4,-0.4796,4.229,-7.54);
  gr->Fit(func,"RL");

  TH1F *hMcPtFunc = (TH1F*)hMcPtNoWeight->Clone("hMcPtFunc");
  TH2F *hMcPtVsRcFunc = (TH2F*)hMcPtVsRcNoWeight->Clone("hMcPtVsRcFunc");
  for(int ibin=1; ibin<=hMcPtVsRcFunc->GetNbinsX(); ibin++)
    {
      double scale = func->Eval(hMcPtFunc->GetBinCenter(ibin));
      hMcPtFunc->SetBinContent(ibin,hMcPtFunc->GetBinContent(ibin)*scale);
      hMcPtFunc->SetBinError(ibin,hMcPtFunc->GetBinError(ibin)*scale);
      for(int jbin=1; jbin<=hMcPtVsRcNoWeight->GetNbinsY(); jbin++)
	{
	  hMcPtVsRcFunc->SetBinContent(ibin,jbin,hMcPtVsRcFunc->GetBinContent(ibin,jbin)*scale);
	  hMcPtVsRcFunc->SetBinError(ibin,jbin,hMcPtVsRcFunc->GetBinError(ibin,jbin)*scale);
	}
    }
  TH1F *hRcPtFunc = (TH1F*)hMcPtVsRcFunc->ProjectionY("hRcPtFunc");
  hRcPtFunc->SetMarkerStyle(21);
  hRcPtFunc->SetMarkerColor(2);
  hRcPtFunc->SetLineColor(2);
  hMcPtVsRcFunc->GetZaxis()->SetRangeUser(1e-4,1e2);
  draw2D(hMcPtVsRcFunc);
  hMcPtFunc->GetYaxis()->SetRangeUser(1e-4,5e4);
  draw1D(hMcPtFunc,"",kTRUE);
  hRcPtFunc->Draw("sames P");

  TH1F *hRatioFunc = (TH1F*)hRcPtFunc->Clone("hRatioFunc");
  hRatioFunc->Rebin(100);
  hMcPtFunc->Rebin(100);
  hRatioFunc->Divide(hMcPtFunc);
  cEff->cd();
  hRatioFunc->SetMarkerColor(5);
  hRatioFunc->Draw("samesP");
  
  TH1F *hCheck2 = (TH1F*)hRatioFunc->Clone("check2");
  hCheck2->Divide(hRatio);
  draw1D(hCheck2);

}