]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/STRANGENESS/LambdaK0PbPb/DrawSpectraAndRatios.C
An effective FD corretion
[u/mrichter/AliRoot.git] / PWGLF / STRANGENESS / LambdaK0PbPb / DrawSpectraAndRatios.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2    #include <TMath.h>
3    #include <TROOT.h>
4    #include <Riostream.h>
5    #include <TCanvas.h>
6    #include <TColor.h>
7    #include <TLatex.h>
8    #include <TLegend.h>
9    #include <TLegendEntry.h>
10
11    #include <TStyle.h>
12    #include <TString.h>
13    #include <TASImage.h>
14
15    #include <TFile.h>
16    #include <TList.h>
17    #include <TH1F.h>
18    #include <TH1D.h>
19    #include <TF2.h>
20    #include <TFitResult.h>
21    #include <TFitResultPtr.h>
22    #include <TH2F.h>
23    #include <TH3F.h>
24 #endif
25
26 extern TStyle *gStyle;
27
28 static Double_t xBins[]={
29    0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,
30    1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,
31    2.2,2.4,2.6,2.8,3.0,3.2,3.4,3.6,3.8,4.0,
32    4.5,5.0,5.5,6.5,8.0,10.0,12.0
33 };
34 const Int_t nBins=sizeof(xBins)/sizeof(Double_t) - 1; //37
35
36 static Bool_t gFlag=kFALSE;
37
38 //*** The systematic uncertainties for combining
39 // TPC crossed/findable
40 // cos(PA)
41 // DCA between V0 daughters
42 // TPC crossed pad rows
43 // DCA daughters <-> PV
44 // c*tau
45 static 
46 Double_t sysEffK0s[nBins]={//Efficiency, combined over cuts mentioned above
47   0.0,
48   0.05,0.05,0.04,0.03,  //Dominated by cos(PA)
49   0.04,0.05,0.06,0.07,0.08,0.09, //Dominated by TPC crossed/findable
50   0.10,0.10,0.11,0.12,0.12,0.13,0.13,0.13,0.14,0.14,0.14,
51   0.14,0.13,0.13,0.12,0.11,0.11,0.11,0.10,0.09,0.08,
52   0.08,0.05,0.04,0.03,0.03
53 };
54 /*
55 static Double_t sysSigK0s[nBins]={//Signal extraction
56   0.00728589, 0.00728589, 0.00728539, 0.0073469, 0.00737846, 0.00741705,
57   0.00750887, 0.00753641, 0.00769012, 0.00789154, 0.00796624, 0.00822856,
58   0.00838203, 0.00864603, 0.00906498, 0.00923208, 0.00931179, 0.0100081,
59   0.0100768, 0.0105292, 0.0112067, 0.0122143, 0.0130162, 0.0139799, 0.0155215,
60   0.0158903, 0.0168517, 0.0189316, 0.0188103, 0.020233, 0.0223704, 0.0260327,
61   0.0260327, 0.0260327, 0.0260327, 0.0260327, 0.0260327
62 };
63 */
64 static Double_t sysSigK0s[nBins]={//Signal extraction
65   0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
66   0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
67   0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
68   0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
69   0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
70   0.03, 0.03, 0.03, 0.03, 0.03
71 };
72
73 static 
74 Double_t sysEffLam[nBins]={//Efficiency, combined over cuts mentioned above
75   0.0,0.0,0.0,
76   0.20,0.12,0.05, //Dominated by cos(PA)+FD
77   0.06,0.06,0.06,0.06,0.06,  //Dominated by c*tau
78   0.06,0.06, //Dominated by TPC crossed/findable
79   0.07,0.09,0.09,0.10,0.10,0.11,0.11,0.11,0.10,0.10,0.09,
80   0.08,0.08,0.07,0.07,0.07,0.06,0.07,0.06,0.07,0.05,
81   0.06,0.08,0.04
82 };
83 static Double_t sysSigLam[nBins]={//Signal extraction
84   0.0447214, 0.0447214, 0.0447214, 0.0447214, 0.0447214,
85   0.0447214, 0.0447214, 0.0447214, 0.0447214, 0.0447214,
86   0.0447214, 0.0447214, 0.0447214, 0.0447214, 0.0447214,
87   0.0447214, 0.0447214, 0.0447214, 0.0447214, 0.0447214,
88   0.0447214, 0.0447214, 0.0447214, 0.0447214, 0.0447214,
89   0.0447214, 0.0447214, 0.0447214, 0.0447214, 0.0465862,
90   0.0472600, 0.0488576, 0.0526797, 0.0575355, 0.0651647,
91   0.0721110, 0.072111
92 };
93
94 const Double_t sysPID=0.02; //PID
95 const Double_t sysArm=0.01; //Armenteros cut
96 const Double_t sysFD=0.05;  //Feed down
97
98 const Double_t sysRatio=0.05;//Efficiency systematics for the L/K ratio
99
100 const Double_t fdCorr=0.81;  //Feed down correction value 
101
102
103 TH1 *MapHisto(const TH1 *h) {
104   const Double_t eps=0.0001;
105   TString name("m");
106   name = name + h->GetName(); 
107   TH1F *mh=new TH1F(name.Data(),h->GetTitle(),nBins,xBins);
108   mh->GetXaxis()->SetTitle("p_{t} (GeV/c)");
109   mh->GetYaxis()->SetTitle("1/N_{ev}d^{2}N/dp_{t}/dy (GeV/c)^{-1}");
110
111   Double_t xh=h->GetBinCenter(1), xmh=0.;
112
113   Int_t n=1;
114   for (; n<=nBins; n++) {
115     xmh=mh->GetBinCenter(n);
116     if (TMath::Abs(xh-xmh)<eps) break; 
117   }
118
119   Int_t iii=h->GetNbinsX();
120   //if (gFlag) iii--;
121   for (Int_t i=1; i<=iii; i++) {
122     Int_t ni1=n+i-1;
123
124     if (ni1 > nBins) {
125       cerr<<"Input number of bins is larger than the output number of bins!\n";
126       delete mh;
127       return 0;
128     }
129
130     xh = h->GetBinCenter(i);
131     xmh=mh->GetBinCenter(ni1);
132     if (TMath::Abs(xh-xmh)>eps) {
133       cerr<<"Wrong binning !\n";
134       delete mh;
135       return 0;
136     }
137
138     Double_t c=h->GetBinContent(i);
139     Double_t e=h->GetBinError(i);
140     mh->SetBinContent(ni1,c);
141     mh->SetBinError(ni1,e);
142   }
143   
144   return mh;
145 }
146
147 Bool_t 
148 GetHistos(const Char_t *rName[], const Char_t *eName[], TH1 *&raw, TH1 *&eff) {
149
150   /*TFile *fr=*/TFile::Open(rName[0]);
151   //TList *lst=(TList*)gFile->Get("c1DataYields");
152   TList *lst=(TList*)gFile->Get("cLK0Spectra");
153
154   raw=(TH1F*)lst->FindObject(rName[1]);
155   if (!raw) {
156      cerr<<"No raw yield !"<<eName[0]<<' '<<eName[1]<<endl; 
157      return kFALSE;
158   }
159
160   ///*TFile *fe=*/TFile::Open(eName[0]);
161   //eff=(TH1F*)gFile->Get(eName[1]);
162   eff=(TH1F*)lst->FindObject(eName[1]);
163   if (!eff) {
164      cerr<<"No efficiency ! "<<eName[0]<<' '<<eName[1]<<endl; 
165      return kFALSE;
166   }
167   return kTRUE;
168 }
169
170 void SetAttributes(TH1 *h,const Char_t *tit,Int_t col,Int_t mar,Float_t siz,
171 Float_t max=1000., Float_t min=1e-6, Float_t factor=1, Int_t range=nBins) {
172   h->SetTitle(tit);
173   h->SetLineColor(col); 
174   h->SetMarkerColor(col);
175   h->SetMarkerStyle(mar);
176   h->SetMarkerSize(siz);
177   h->Scale(factor);
178   h->SetMaximum(max);
179   h->SetMinimum(min);
180   h->GetXaxis()->SetRange(1,range);
181 }
182
183 void 
184 DrawHisto(TH1 *h, const Option_t *option, Double_t *sysEff, Double_t *sysSig) {
185   TH1F *hh=new TH1F(*((TH1F*)h));
186   Int_t nb=hh->GetNbinsX();
187
188   for (Int_t i=1; i<=nb; i++) {
189       Double_t c=hh->GetBinContent(i);
190       Double_t e=hh->GetBinError(i);
191       Int_t j=i-1;
192       e = sysEff[j]*sysEff[j] + sysSig[j]*sysSig[j];
193
194       if (sysEff==sysEffLam) {// for Lambda
195          e += sysFD*sysFD;
196          if (i<13) e += sysPID*sysPID;
197       } else {// for K0s
198          e += sysArm*sysArm;
199       }
200
201       e=c*TMath::Sqrt(e); 
202
203       hh->SetBinError(i,e);
204   }
205   hh->SetFillColor(17);
206   TString opt("E5"); opt+=option;
207   //TString opt("E2"); opt+=option;
208   hh->Draw(opt.Data());
209   h->Draw("e x0 same");
210 }
211
212 void DrawRatio(TH1 *h, const Option_t *option) {
213   TH1F *hh=new TH1F(*((TH1F*)h));
214   Int_t nb=hh->GetNbinsX();
215
216   for (Int_t i=1; i<=nb; i++) {
217       Double_t c=hh->GetBinContent(i);
218       Double_t e=hh->GetBinError(i);
219       Int_t j=i-1;
220       e = sysSigK0s[j]*sysSigK0s[j] + sysSigLam[j]*sysSigLam[j];
221
222       e += sysRatio*sysRatio;
223
224       e += sysArm*sysArm;
225       e += sysFD*sysFD;
226       if (i<13) e += sysPID*sysPID;
227  
228       e=c*TMath::Sqrt(e); 
229
230       hh->SetBinError(i,e);
231   }
232   hh->SetFillColor(17);
233   TString opt("E5"); opt+=option;
234   hh->Draw(opt.Data());
235   h->Draw("e x0 same");
236 }
237
238 void DrawALICELogo(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
239 {
240 // Correct for aspect ratio of figure plus aspect ratio of pad.
241 // Coordinates are NDC!
242
243   x2 = x1 + (y2 - y1)*0.891*gPad->GetCanvas()->GetWindowHeight()*gPad->GetHNDC() / (gPad->GetWNDC() * gPad->GetCanvas()->GetWindowWidth());
244   
245   TPad *myPadLogo = new TPad("myPadLogo","Pad for ALICE Logo", x1, y1, x2, y2);
246   myPadLogo->SetLeftMargin(0);
247   myPadLogo->SetTopMargin(0);
248   myPadLogo->SetRightMargin(0);
249   myPadLogo->SetBottomMargin(0);
250   myPadLogo->Draw();
251   myPadLogo->cd();
252   TASImage *myAliceLogo = 
253   new TASImage("alice_logo_preliminary.eps");
254   myAliceLogo->Draw("same");
255 }
256
257 void DrawFit(const Char_t *nam[], const Float_t *fac, Int_t n){
258   for (Int_t i=0; i<n; i++) {
259       const Char_t *name=nam[i];
260       Float_t factor=fac[i];
261       TF1 *f=(TF1*)gROOT->FindObject(name);
262       TH1 *h=f->GetHistogram();
263       h->Scale(factor);
264       h->SetLineColor(1);
265       h->SetLineWidth(1);
266       h->SetLineStyle(1);
267       h->Draw("Lsame");
268   }
269 }
270
271 void DrawSpectraAndRatios() {
272
273   const Int_t nCent=6;
274   const Int_t nCent1=nCent-1;
275
276   const Char_t *title[nCent]={
277     "0-10 %",
278     "10-20 %",
279     "20-40 %, x1.2",
280     "40-60 %, x2.0",
281     "60-80 %, x3.0",
282     "80-90 %"
283   };
284   const Int_t   colour[nCent]={2,   635, 419, 4 , 6,  1  };
285   const Int_t   marker[nCent]={22,  34,  21,  23, 33, 20 };
286   const Float_t masize[nCent]={1.6, 1.3, 1.3, 1.6,2,  1.3};
287   const Float_t factor[nCent]={1.0, 1.0, 1.2, 2.0,3.0,0.0}; //scale for drawing
288   
289   const Char_t *rNameL[2*nCent]={ // file name, histo name
290     "LK0Spectra_WeightMean_100712.root", "Data_La_0010", 
291     "LK0Spectra_WeightMean_100712.root", "Data_La_1020", 
292     "LK0Spectra_WeightMean_100712.root", "Data_La_2040", 
293     "LK0Spectra_WeightMean_100712.root", "Data_La_4060", 
294     "LK0Spectra_WeightMean_100712.root", "Data_La_6080", 
295     "LK0Spectra_WeightMean_100712.root", "Data_La_8090" 
296   };
297   const Char_t *eNameL[2*nCent]={ // file name, histo name
298     "LK0Spectra_WeightMean_100712.root", "Efficiency_La_0010",
299     "LK0Spectra_WeightMean_100712.root", "Efficiency_La_1020",
300     "LK0Spectra_WeightMean_100712.root", "Efficiency_La_2040",
301     "LK0Spectra_WeightMean_100712.root", "Efficiency_La_4060",
302     "LK0Spectra_WeightMean_100712.root", "Efficiency_La_6080",
303     "LK0Spectra_WeightMean_100712.root", "Efficiency_La_8090"
304   };
305
306   const Char_t *rNameK[2*nCent]={ // file name, histo name
307     "LK0Spectra_WeightMean_100712.root", "Data_K0_0010", 
308     "LK0Spectra_WeightMean_100712.root", "Data_K0_1020", 
309     "LK0Spectra_WeightMean_100712.root", "Data_K0_2040", 
310     "LK0Spectra_WeightMean_100712.root", "Data_K0_4060", 
311     "LK0Spectra_WeightMean_100712.root", "Data_K0_6080", 
312     "LK0Spectra_WeightMean_100712.root", "Data_K0_8090" 
313   };
314   const Char_t *eNameK[2*nCent]={ // file name, histo name
315     "LK0Spectra_WeightMean_100712.root", "Efficiency_K0_0010",
316     "LK0Spectra_WeightMean_100712.root", "Efficiency_K0_1020",
317     "LK0Spectra_WeightMean_100712.root", "Efficiency_K0_2040",
318     "LK0Spectra_WeightMean_100712.root", "Efficiency_K0_4060",
319     "LK0Spectra_WeightMean_100712.root", "Efficiency_K0_6080",
320     "LK0Spectra_WeightMean_100712.root", "Efficiency_K0_8090"
321   };
322
323   gStyle->SetOptStat(0);
324   gStyle->SetOptTitle(0);
325   gStyle->SetLegendFillColor(0);
326
327   TH1 *raw=0;
328   TH1 *eff=0;
329   TString option(""), ratio("ratio");
330
331   TCanvas *c1=new TCanvas; c1->SetLogy();
332   c1->SetLeftMargin(0.13); c1->SetBottomMargin(0.13);
333   TCanvas *c1lin=new TCanvas;
334   c1lin->SetLeftMargin(0.13); c1lin->SetBottomMargin(0.13);
335
336   TCanvas *c2=new TCanvas; c2->SetLogy();
337   c2->SetLeftMargin(0.13); c2->SetBottomMargin(0.13);
338   TCanvas *c2lin=new TCanvas;
339   c2lin->SetLeftMargin(0.13); c2lin->SetBottomMargin(0.13);
340
341   TCanvas *c3=new TCanvas;
342   c3->SetLeftMargin(0.13); c3->SetBottomMargin(0.13);
343
344   TH1 *lkRatio[nCent]={0};
345
346   for (Int_t cent=0; cent<nCent1; cent++) {
347       const Char_t *tit=title[cent];
348       Int_t col=colour[cent];
349       Int_t mar=marker[cent];
350       Float_t siz=masize[cent];
351       Float_t fac=factor[cent];
352  
353       // Lambda
354       if (!GetHistos(rNameL+2*cent, eNameL+2*cent, raw, eff)) return;
355       TH1 *rawHl=MapHisto(raw);
356       TH1 *effHl=MapHisto(eff);
357
358       effHl->Scale(1/fdCorr); //Feed down
359
360       rawHl->Divide(effHl);
361       SetAttributes(rawHl,tit,col,mar,siz);
362       c1->cd();
363       DrawHisto(rawHl, option.Data(), sysEffLam, sysSigLam);
364
365       TH1 *linHl=(TH1*)rawHl->Clone();
366       SetAttributes(linHl,tit,col,mar,siz,25.0*fdCorr,0.,fac,32); 
367       c1lin->cd();
368       DrawHisto(linHl, option.Data(), sysEffLam, sysSigLam);
369
370       // K0s
371     if (cent==nCent1) gFlag=kTRUE;
372       if (!GetHistos(rNameK+2*cent, eNameK+2*cent, raw, eff)) return;
373       TH1 *rawHk=MapHisto(raw);
374       TH1 *effHk=MapHisto(eff);
375       rawHk->Divide(effHk);
376       SetAttributes(rawHk,tit,col,mar,siz);
377       c2->cd();
378       DrawHisto(rawHk, option.Data(), sysEffK0s, sysSigK0s);
379
380       TH1 *linHk=(TH1*)rawHk->Clone();
381       SetAttributes(linHk,tit,col,mar,siz,120.,0.,fac,32); 
382       c2lin->cd();
383       DrawHisto(linHk, option.Data(), sysEffK0s, sysSigK0s);
384
385       // Lambda/K0s
386       TH1 *rawHlk=(TH1*)rawHl->Clone();
387       lkRatio[cent]=rawHlk;
388       TString name=ratio+rawHlk->GetName();
389       rawHlk->SetName(name.Data());      
390       rawHlk->SetMaximum(1.7);      
391       rawHlk->Divide(rawHk);
392       rawHlk->GetYaxis()->SetTitle("#Lambda/K^{0}_{S}");
393       c3->cd();
394       if (cent!=1)
395       DrawRatio(rawHlk,option.Data());
396
397       option+="same";
398   }
399   for (Int_t cent=0; cent<nCent; cent++) {
400     lkRatio[cent]->Draw("same");
401   }
402
403   Float_t offx=0.15, offy=0.16, sizx=0.22, sizy=0.22;
404   TLegend *leg=c1->BuildLegend(0.68,0.46,0.88,0.82,"Centrality:");
405   leg->SetBorderSize(0);
406   leg->SetFillColor(0);
407
408   TLegendEntry *entry=leg->AddEntry("NULL","systematic uncertainty","lpf");
409   Int_t ci = TColor::GetColor("#cccccc");
410   entry->SetLineColor(ci);
411   entry->SetLineStyle(1);
412   entry->SetLineWidth(10);
413   entry->SetMarkerColor(ci);
414
415   c1->cd(); 
416   TLatex *   tex = new TLatex(5.5,5.0,"#Lambda");
417   tex->SetTextFont(42);
418   tex->SetTextSize(0.11);
419   tex->SetLineWidth(2);
420   tex->Draw();
421   tex = new TLatex(2.18,200.,"Pb-Pb at #sqrt{s_{NN}}=2.76 TeV, |y|<0.5");
422   tex->SetTextFont(42);
423   tex->SetLineWidth(2);
424   tex->Draw();
425   DrawALICELogo(offx,offy,offx+sizx,offy+sizy);
426
427    leg=c1lin->BuildLegend(0.69,0.43,0.88,0.80,"Centrality:");
428    leg->SetBorderSize(0);
429    leg->SetFillColor(0);
430
431    entry=leg->AddEntry("NULL","systematic uncertainty","lpf");
432    entry->SetLineColor(ci);
433    entry->SetLineStyle(1);
434    entry->SetLineWidth(10);
435    entry->SetMarkerColor(ci);
436    entry=leg->AddEntry("NULL","BGBW fit","l");
437    entry->SetLineColor(1);
438    entry->SetLineStyle(1);
439    entry->SetLineWidth(1);
440    entry->SetMarkerColor(1);
441    entry->SetMarkerStyle(21);
442    entry->SetMarkerSize(1);
443
444    c1lin->cd();
445    tex=new TLatex(1.04,22.7*fdCorr,"Pb-Pb at #sqrt{s_{NN}}=2.76 TeV, |y|<0.5");
446    tex->Draw();
447       tex = new TLatex(2.38,18.5*fdCorr,"#Lambda");  
448    tex->SetTextSize(0.11);
449    tex->Draw();
450    {
451      TFile::Open("LamFitResults20120711.root");
452      const Char_t *name[nCent]={
453        "fitBWLambda010","fitBWLambda1020","fitBWLambda2040",
454        "fitBWLambda4060","fitBWLambda6080","fitBWLambda8090"
455      };
456      Float_t fac[nCent]; for (Int_t i=0; i<nCent; i++) fac[i]=fdCorr*factor[i];
457      DrawFit(name, fac, nCent1);
458    }
459    Float_t offx1=0.70, offy1=0.18;
460    DrawALICELogo(offx1,offy1,offx1+sizx,offy1+sizy);
461        
462
463
464
465   leg=c2->BuildLegend(0.68,0.46,0.88,0.82,"Centrality:");
466   leg->SetBorderSize(0);
467   leg->SetFillColor(0);
468
469   entry=leg->AddEntry("NULL","systematic uncertainty","lpf");
470   entry->SetLineColor(ci);
471   entry->SetLineStyle(1);
472   entry->SetLineWidth(10);
473   entry->SetMarkerColor(ci);
474
475   c2->cd(); 
476   tex = new TLatex(5.5,5.0,"K^{0}_{S}");
477   tex->SetTextFont(42);
478   tex->SetTextSize(0.089);
479   tex->SetLineWidth(2);
480   tex->Draw();
481   tex = new TLatex(2.18,200.,"Pb-Pb at #sqrt{s_{NN}}=2.76 TeV, |y|<0.5");
482   tex->SetTextFont(42);
483   tex->SetLineWidth(2);
484   tex->Draw();
485   DrawALICELogo(offx,offy,offx+sizx,offy+sizy);
486
487    leg=c2lin->BuildLegend(0.69,0.43,0.88,0.80,"Centrality:");
488    leg->SetBorderSize(0);
489    leg->SetFillColor(0);
490
491    entry=leg->AddEntry("NULL","systematic uncertainty","lpf");
492    entry->SetLineColor(ci);
493    entry->SetLineStyle(1);
494    entry->SetLineWidth(10);
495    entry->SetMarkerColor(ci);
496    entry=leg->AddEntry("NULL","BGBW fit","l");
497    entry->SetLineColor(1);
498    entry->SetLineStyle(1);
499    entry->SetLineWidth(1);
500    entry->SetMarkerColor(1);
501    entry->SetMarkerStyle(21);
502    entry->SetMarkerSize(1);
503
504    c2lin->cd();
505       tex = new TLatex(1.04,109.,"Pb-Pb at #sqrt{s_{NN}}=2.76 TeV, |y|<0.5");
506    tex->Draw();
507       tex = new TLatex(2.122705,87.70856,"K^{0}_{S}");  
508    tex->SetTextSize(0.089);
509    tex->Draw();
510    {
511      TFile::Open("K0FitResults20120711.root");
512      const Char_t *name[nCent]={
513        "fitBWK0s0010","fitBWK0s1020","fitBWK0s2040",
514        "fitBWK0s4060","fitBWK0s6080","fitBWK0s8090"
515      };
516      DrawFit(name, factor, nCent1);
517    }
518    DrawALICELogo(offx1,offy1,offx1+sizx,offy1+sizy);
519        
520    
521    //leg=c3->BuildLegend(0.74,0.62,0.88,0.88,"Centrality:");
522   leg=c3->BuildLegend(0.55,0.55,0.88,0.88,"Centrality:");
523   leg->SetBorderSize(0);
524   leg->SetFillColor(0);
525
526   entry=leg->AddEntry("NULL","systematic uncertainty","lpf");
527   entry->SetLineColor(ci);
528   entry->SetLineStyle(1);
529   entry->SetLineWidth(10);
530   entry->SetMarkerColor(ci);
531
532   return;
533 }
534