Updates
authorakalweit <akalweit@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 7 Nov 2013 10:34:34 +0000 (10:34 +0000)
committerakalweit <akalweit@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 7 Nov 2013 10:34:34 +0000 (10:34 +0000)
PWGPP/EvTrkSelection/macros/MakeSensitivityPlots.C

index 3bf9163..5fdd881 100644 (file)
 #include "TList.h"
 #include "TStyle.h"
 #include "TLegend.h"
+#include "TLatex.h"
 
 void MakeSensitivityPlots();
-TH1D * GetAcceptedFractionNclCut(Int_t nclCut = 80, const Char_t * inFileName = "output/Data_LHC13b.root");
+//
+TCanvas * GetSensitivityPlot(TString cutname = "Ncl",  
+                            Int_t projectionAxis = 1,
+                            Int_t particleType = 5,
+                            Double_t lowCut = 80.,
+                            Double_t highCut = 1e4, 
+                            TString inFileNameData = "output/LHC10b_data.root", 
+                            TString inFileNameMC = "output/LHC10b_MC.root");
+//
+TH1D   * GetAcceptedFraction(TString cutname = "Ncl",  
+                            Int_t projectionAxis = 1,
+                            Int_t particleType = 5,
+                            Double_t lowCut = 80.,
+                            Double_t highCut = 1e4, 
+                            TString inFileName = "output/LHC10b_data.root");
+//
+void PrintCutGallery(TString inFileNameData = "output/LHC10b_data.root", 
+                    TString inFileNameMC   = "output/LHC10b_MC.root", 
+                    TString outFileName    = "plots/10b.pdf");
 
+//______________________________________________________________________________
 void MakeSensitivityPlots() {
   //
-  //  -> THIS MACRO SHOULD BE COMPILABLE.
-  //  -> ALL PLOTS SHOULD BE LABELED (ESPECIALLY THE AXES).
-  //  -> DATA RED AND MC BLUE.
+  // make all the senstivity plots
   //
+  PrintCutGallery("output/LHC10b_data.root", "output/LHC10b_MC.root", "plots/10b.pdf");
+  PrintCutGallery("output/LHC10d_data.root", "output/LHC10d_MC.root", "plots/10d.pdf");
+  PrintCutGallery("output/LHC10e_data.root", "output/LHC10e_MC.root", "plots/10e.pdf");
+  PrintCutGallery("output/LHC10h_data.root", "output/LHC10h_MC.root", "plots/10h.pdf");
 
-  Int_t nclCut = 120;
+}
 
-  TH1D * nclAcceptedData80 = GetAcceptedFractionNclCut(nclCut, "output/Data_LHC13b.root");
-  nclAcceptedData80->SetNameTitle(Form("nr clusters cut %d",nclCut),Form("nr clusters cut %d",nclCut));
-  nclAcceptedData80->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
-  nclAcceptedData80->GetYaxis()->SetTitle("accepted fraction");
-  nclAcceptedData80->GetXaxis()->SetTitleOffset(1.2);
-  nclAcceptedData80->GetYaxis()->SetTitleOffset(1.2);
-  nclAcceptedData80->GetYaxis()->SetTitleSize(0.045);
-  nclAcceptedData80->SetMaximum(1.07);
-  nclAcceptedData80->SetMinimum(0.57);
-  nclAcceptedData80->SetLineColor(kRed -3);
-  //
-  TH1D * nclAcceptedMc80   = GetAcceptedFractionNclCut(nclCut, "output/MC_LHC13b.root");
-  nclAcceptedMc80->SetLineColor(kBlue -3);
-  //
-  TCanvas * canvNclCut = new TCanvas("canvNclCut","sensitivity to ncl cut",600,800);
-  gStyle->SetOptStat(0);
-  canvNclCut->Divide(1,2,0,0);
-  canvNclCut->cd(1)->SetLogx();
-  gPad->SetTicky(2);
-  gPad->SetFillStyle(0);
+//______________________________________________________________________________
+void PrintCutGallery(TString inFileNameData, TString inFileNameMC, TString outFileName) {
+  //
+  // print a gallery of cuts
+  //
+  TCanvas * canvMaster = new TCanvas("canvMaster","canvMaster");
+  canvMaster->Divide(3,2);
+  //TCanvas * canv = GetSensitivityPlot();
+  //
+  TCanvas * canvSens[6]; 
+  for(Int_t i=0; i < 6; i++) {
+    canvSens[i]= GetSensitivityPlot("Ncl", 1, 5, 50 + i*10, 1e4, inFileNameData.Data(),  inFileNameMC.Data());
+    //canvSens[i]= GetSensitivityPlot("Chi2Tpc", 1, 5, -1e4, 2.5 + i*0.5, inFileNameData.Data(),  inFileNameMC.Data());
+    canvSens[i]->SetName(Form("canvSens_%i",i));
+    canvMaster->cd(i+1);
+    canvSens[i]->DrawClonePad();
+      
+  }
+  canvMaster->Print(outFileName.Data());
+
+}
+
+
+//______________________________________________________________________________
+TCanvas * GetSensitivityPlot(TString cutname,  
+                            Int_t projectionAxis,
+                            Int_t particleType,
+                            Double_t lowCut,
+                            Double_t highCut, 
+                            TString inFileNameData, 
+                            TString inFileNameMC) {
   //
-  nclAcceptedData80->GetYaxis()->SetLabelFont(62);
-  nclAcceptedData80->DrawCopy();
-  nclAcceptedMc80->DrawCopy("SAME");
-    
-  TLegend *leg = new TLegend(0.75,0.2,.9,0.3);
-  leg->AddEntry(nclAcceptedData80,"Data","f");
-  leg->AddEntry(nclAcceptedMc80,"MC","f");
+  // make a single plot
+  //
+  TH1D * nclAcceptedData = GetAcceptedFraction(cutname.Data(), projectionAxis, particleType, lowCut, highCut, inFileNameData);
+  nclAcceptedData->SetNameTitle(Form("%s_DATA",nclAcceptedData->GetName()), Form("%s_DATA",nclAcceptedData->GetName()));
+  //
+  //
+  nclAcceptedData->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
+  nclAcceptedData->GetYaxis()->SetTitle("accepted fraction");
+  nclAcceptedData->GetYaxis()->SetLabelSize(0.04);
+  nclAcceptedData->GetYaxis()->SetTitleSize(0.06);
+  nclAcceptedData->GetYaxis()->SetTitleOffset(1);
+  nclAcceptedData->SetMaximum(1.07);
+  nclAcceptedData->SetMinimum(0.625);
+  nclAcceptedData->SetLineColor(kRed -3);
+  //
+  TH1D * nclAcceptedMc   = GetAcceptedFraction(cutname.Data(), projectionAxis, particleType, lowCut, highCut, inFileNameMC);
+  nclAcceptedMc->SetNameTitle(Form("%s_MC",nclAcceptedMc->GetName()), Form("%s_MC",nclAcceptedMc->GetName()));
+  nclAcceptedMc->SetLineColor(kBlue -3);
+  //
+  // create the complicated splitted canvas
+  //
+  gStyle->SetOptStat(0);
+  gStyle->SetOptTitle(0);
+  TCanvas * canvCut = new TCanvas("canvCut",Form("sensitivity to %s cut",cutname.Data()),600,600);
+  canvCut->Divide(1,2);
+  //
+  TPad* canvas_up = (TPad*) canvCut->GetListOfPrimitives()->FindObject(Form("canvCut_1"));
+  TPad* canvas_dw = (TPad*) canvCut->GetListOfPrimitives()->FindObject(Form("canvCut_2"));
+  //
+  canvas_up->SetLogx();
+  canvas_dw->SetLogx();
+  //
+  // define the size
+  double up_height     = 0.75; // please tune so that the upper figures size will meet your requirement
+  double dw_correction = 1.30; // please tune so that the smaller canvas size will work in your environment
+  //
+  //double font_size_dw  = 0.1; // please tune the font size parameter for bottom figure
+  double dw_height    = (1. - up_height) * dw_correction;
+  // set pad size
+  canvas_up->SetPad(0., 1 - up_height, 1., 1.);
+  canvas_dw->SetPad(0., 0., 1., dw_height);
+  canvas_up->SetFrameFillColor(0);
+  canvas_up->SetFillColor(0);
+  canvas_dw->SetFillColor(0);
+  canvas_dw->SetFrameFillColor(0);
+  //
+  // set top margin 0 for bottom figure
+  canvas_dw->SetTopMargin(0);
+  canvas_dw->SetLeftMargin(0.12);
+  canvas_dw->SetBottomMargin(0.3);
+  //
+  //set margins for top figure
+  canvas_up->SetLeftMargin(0.12);
+  //
+  canvas_up->cd();
+  nclAcceptedData->GetYaxis()->SetLabelFont(62);
+  nclAcceptedData->SetObjectStat(0);
+  nclAcceptedMc->SetObjectStat(0);
+  //
+  nclAcceptedData->DrawCopy();
+  nclAcceptedMc->DrawCopy("SAME");
+  //
+  TLegend *leg = new TLegend(0.65,0.2,.85,0.4);
+  leg->AddEntry(nclAcceptedData,"Data","f");
+  leg->AddEntry(nclAcceptedMc,"MC","f");
   leg->SetBorderSize(0);
   gStyle->SetFillColor(0);
   leg->Draw();
+  Float_t lowCutTitle = lowCut < -999. ? 0 : lowCut;
+  TLatex *   tex = new TLatex(0.9654768,1.032485,Form("%4.2f < %s < %4.2f", lowCutTitle, cutname.Data(), highCut));
+  tex->Draw();
   //
+  // Draw the ratio
+  //    
+  TH1D * nclAcceptedMcDataRatio = (TH1D*)nclAcceptedData->Clone();
   //
-  //
-    
-  TH1D * nclAcceptedMcDataRatio = (TH1D*)nclAcceptedData80->Clone();
-  //
-  canvNclCut->cd(2)->SetLogx();
-  gPad->SetTicky(2);
+  canvCut->cd(2)->SetLogx();
+  // gPad->SetTicky(2);
   gPad->SetFillStyle(0);
   //
-  nclAcceptedMcDataRatio->Divide(nclAcceptedMc80);
+  nclAcceptedMcDataRatio->Divide(nclAcceptedMc);
   nclAcceptedMcDataRatio->GetYaxis()->SetTitle("ratio");
-  nclAcceptedMcDataRatio->GetYaxis()->SetTitleSize(0.045);
-  nclAcceptedMcDataRatio->GetYaxis()->SetTitleOffset(1.1);
+  nclAcceptedMcDataRatio->GetXaxis()->SetLabelSize(0.1);
+  nclAcceptedMcDataRatio->GetXaxis()->SetTitleSize(0.11);
+  nclAcceptedMcDataRatio->GetYaxis()->SetLabelSize(0.07);
+  nclAcceptedMcDataRatio->GetYaxis()->SetTitleSize(0.11);
+  nclAcceptedMcDataRatio->GetXaxis()->SetTitleOffset(1.23);
+  nclAcceptedMcDataRatio->GetYaxis()->SetTitleOffset(0.5);
+  nclAcceptedMcDataRatio->GetYaxis()->CenterTitle();
   nclAcceptedMcDataRatio->SetMaximum(1.18);
   nclAcceptedMcDataRatio->SetMinimum(0.8);
   nclAcceptedMcDataRatio->GetYaxis()->SetLabelFont(62);
-  nclAcceptedMcDataRatio->DrawCopy();
-
+  nclAcceptedMcDataRatio->SetLineColor(kGreen+2);
+  nclAcceptedMcDataRatio->Draw();
+  canvas_dw->SetFillStyle(1001);
+  //
+  //
+  //
+  return canvCut;
+  
 }
 
 
-TH1D * GetAcceptedFractionNclCut(Int_t nclCut, const Char_t * inFileName) {
+//______________________________________________________________________________
+TH1D * GetAcceptedFraction(TString cutname,  
+                          Int_t projectionAxis,
+                          Int_t particleType,
+                          Double_t lowCut,
+                          Double_t highCut, 
+                          TString inFileName) {
   //
   // accepted fraction of tracks for ncl cut vs. pT
   //
   TFile * inFileData = TFile::Open(inFileName);
   TList * l = (TList * ) inFileData->Get("akalweit_TrackingUncert");
-  THnF * histNcl = (THnF *) l->FindObject("histNcl");
-  //  histNcl->GetListOfAxes()->Print();
+  THnF * histNcl = (THnF *) l->FindObject(Form("hist%s",cutname.Data()));
+  //
+  // select particleType
+  //
+  histNcl->GetAxis(4)->SetRangeUser(particleType, particleType);
+  //
+  // restrict eta-range
+  //
+  histNcl->GetAxis(2)->SetRangeUser(-0.75, 0.75);
   //
   // determine sensitivities
   //
-  TH1D * hAll = histNcl->Projection(1);
+  TH1D * hAll = histNcl->Projection(projectionAxis);
   hAll->SetNameTitle("hAll","hAll");  
   //
   const Int_t kVeryBig = 10000;
-  histNcl->GetAxis(0)->SetRangeUser(nclCut, kVeryBig);
+  histNcl->GetAxis(0)->SetRangeUser(lowCut, highCut);
   TH1D * hAccepted = histNcl->Projection(1);
-  hAccepted->SetNameTitle(Form("hAccepted%d",nclCut),Form("hAccepted%d",nclCut));
-  //
-  histNcl->GetAxis(0)->SetRangeUser(0,nclCut);
-  TH1D * hRejected = histNcl->Projection(1);
-  hRejected->SetNameTitle("hRejected","hRejected");
-  //
+  hAccepted->SetNameTitle(Form("hAccepted_%s_%f_%f",cutname.Data(),lowCut,highCut),Form("hAccepted_%s_%f_%f",cutname.Data(),lowCut,highCut));
   //
   hAccepted->Divide(hAll);
-  hRejected->Divide(hAll);
   //
   // some cosmetics
   //
-  hAccepted->SetLineWidth(2);
+  hAccepted->SetLineWidth(3);
+  hAccepted->SetDirectory(0);
+  //
+  delete l;
+  inFileData->Close();
   //
   return hAccepted;