]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/vertexingHF/AliHFSystErr.cxx
Bug fix (Francesco)
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliHFSystErr.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2010, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /////////////////////////////////////////////////////////////
17 //
18 // Class to handle systematic errors for charm hadrons
19 //
20 // Usage:
21 // AliHFSystEff syst(DECAY); // DECAY = 1 for D0, 2, for D+, 3 for D* 
22 // syst.DrawErrors(); // to see a plot of the error contributions
23 // syst.GetTotalSystErr(pt); // to get the total err at pt 
24 //
25 // Author: A.Dainese, andrea.dainese@pd.infn.it
26 /////////////////////////////////////////////////////////////
27
28 #include <TStyle.h>
29 #include <TGraphAsymmErrors.h>
30 #include <TMath.h>
31 #include <TCanvas.h>
32 #include <TH2F.h>
33 #include <TLegend.h>
34 #include <TColor.h>
35
36 #include "AliHFSystErr.h"
37
38
39 ClassImp(AliHFSystErr)
40
41 //--------------------------------------------------------------------------
42 AliHFSystErr::AliHFSystErr(const Char_t* name, const Char_t* title) : 
43 TNamed(name,title),
44 fNorm(0),
45 fRawYield(0),
46 fTrackingEff(0),
47 fBR(0),
48 fCutsEff(0),
49 fPIDEff(0),
50 fMCPtShape(0),
51 fPartAntipart(0)
52 {
53   //
54   // Default Constructor
55   //
56 }
57 //--------------------------------------------------------------------------
58 AliHFSystErr::AliHFSystErr(Int_t decay,const Char_t* name, const Char_t* title) : 
59 TNamed(name,title),
60 fNorm(0),
61 fRawYield(0),
62 fTrackingEff(0),
63 fBR(0),
64 fCutsEff(0),
65 fPIDEff(0),
66 fMCPtShape(0),
67 fPartAntipart(0)
68 {
69   //
70   // Standard Constructor
71   //
72
73   switch(decay) {
74   case 1: // D0->Kpi
75     InitD0toKpi();
76     break;
77   case 2: // D+->Kpipi
78     InitDplustoKpipi();
79     break;
80   case 3: // D*->D0pi
81     InitDstartoD0pi();
82     break;
83   default:
84     printf("Invalid decay type: %d\n",decay);
85     break;
86   }
87
88
89 }
90 //--------------------------------------------------------------------------
91 AliHFSystErr::~AliHFSystErr() {
92   //  
93   // Default Destructor
94   //
95
96   if(fNorm)         { delete fNorm; fNorm=0; }
97   if(fRawYield)     { delete fRawYield; fRawYield=0; }
98   if(fTrackingEff)  { delete fTrackingEff; fTrackingEff=0; }
99   if(fBR)           { delete fBR; fBR=0; }
100   if(fCutsEff)      { delete fCutsEff; fCutsEff=0; }
101   if(fPIDEff)       { delete fPIDEff; fPIDEff=0; }
102   if(fMCPtShape)    { delete fMCPtShape; fMCPtShape=0; }
103   if(fPartAntipart) { delete fPartAntipart; fPartAntipart=0; }
104
105 }
106 //--------------------------------------------------------------------------
107 void AliHFSystErr::InitD0toKpi() {
108   // 
109   // D0->Kpi syst errors. Responsible: A. Rossi
110   //
111   
112   // Normalization
113   fNorm = new TH1F("fNorm","fNorm",20,0,20);
114   for(Int_t i=4;i<=20;i++) fNorm->SetBinContent(i,0.10); // 10% error on sigmaV0and
115
116   // Branching ratio 
117   fBR = new TH1F("fBR","fBR",20,0,20);
118   for(Int_t i=4;i<=20;i++) fBR->SetBinContent(i,0.012); // 1.2% PDG2010
119
120   // Tracking efficiency
121   fTrackingEff = new TH1F("fTrackingEff","fTrackingEff",20,0,20);
122   for(Int_t i=4;i<=20;i++) fTrackingEff->SetBinContent(i,0.02); // 2% (1% per track)
123
124   // Raw yield extraction
125   fRawYield = new TH1F("fRawYield","fRawYield",20,0,20);
126   fRawYield->SetBinContent(1,1);
127   fRawYield->SetBinContent(2,1);
128   fRawYield->SetBinContent(3,0.15);
129   for(Int_t i=4;i<=20;i++) fRawYield->SetBinContent(i,0.065);
130
131   // Cuts efficiency (from cuts variation)
132   fCutsEff = new TH1F("fCutsEff","fCutsEff",20,0,20);
133   for(Int_t i=1;i<=20;i++) fCutsEff->SetBinContent(i,0.10); // 10%
134
135   // PID efficiency (from PID/noPID)
136   fPIDEff = new TH1F("fPIDEff","fPIDEff",20,0,20);
137   for(Int_t i=1;i<=20;i++) fPIDEff->SetBinContent(i,0.03); // 3%
138   fPIDEff->SetBinContent(4,0.15); // 15%
139
140   // MC dN/dpt
141   fMCPtShape = new TH1F("fMCPtShape","fMCPtShape",20,0,20);
142   for(Int_t i=1;i<=20;i++) fMCPtShape->SetBinContent(i,(Float_t)i*0.006);
143
144   // particle-antiparticle
145   fPartAntipart = new TH1F("fPartAntipart","fPartAntipart",20,0,20);
146   fPartAntipart->SetBinContent(1,1);
147   fPartAntipart->SetBinContent(2,1);
148   fPartAntipart->SetBinContent(3,0.20);
149   for(Int_t i=4;i<=20;i++) fPartAntipart->SetBinContent(i,0.05);
150   
151   return;
152 }
153 //--------------------------------------------------------------------------
154 void AliHFSystErr::InitDplustoKpipi() {
155   // 
156   // D+->Kpipi syst errors. Responsible: R. Bala
157   //
158
159  // Normalization
160   fNorm = new TH1F("fNorm","fNorm",20,0,20);
161   for(Int_t i=4;i<=20;i++) fNorm->SetBinContent(i,0.10); // 10% error on sigmaV0and
162
163   // Branching ratio 
164   fBR = new TH1F("fBR","fBR",20,0,20);
165   for(Int_t i=4;i<=20;i++) fBR->SetBinContent(i,0.04); // 4% PDG2010
166
167   // Tracking efficiency
168   fTrackingEff = new TH1F("fTrackingEff","fTrackingEff",20,0,20);
169   for(Int_t i=4;i<=20;i++) fTrackingEff->SetBinContent(i,0.03); // 3% (1% per track)
170
171
172   // Raw yield extraction
173   fRawYield = new TH1F("fRawYield","fRawYield",20,0,20);
174   fRawYield->SetBinContent(1,1);
175   fRawYield->SetBinContent(2,1);
176   fRawYield->SetBinContent(3,0.10);
177   for(Int_t i=4;i<=20;i++) fRawYield->SetBinContent(i,0.055);  //5 to 10%
178
179   // Cuts efficiency (from cuts variation)
180   fCutsEff = new TH1F("fCutsEff","fCutsEff",20,0,20);
181   for(Int_t i=1;i<=20;i++) fCutsEff->SetBinContent(i,0.10); // 10%
182
183   // PID efficiency (from PID/noPID)
184   fPIDEff = new TH1F("fPIDEff","fPIDEff",20,0,20);
185   for(Int_t i=1;i<=20;i++) fPIDEff->SetBinContent(i,0.05); // 5%
186   fPIDEff->SetBinContent(3,0.13); // 13%
187  
188
189   // MC dN/dpt  (copied from D0 : will update later)
190   fMCPtShape = new TH1F("fMCPtShape","fMCPtShape",20,0,20);
191   for(Int_t i=1;i<=20;i++) fMCPtShape->SetBinContent(i,(Float_t)i*0.006);
192
193
194   // particle-antiparticle
195   /*
196   fPartAntipart = new TH1F("fPartAntipart","fPartAntipart",20,0,20);
197   fPartAntipart->SetBinContent(1,1);
198   fPartAntipart->SetBinContent(2,1);
199   fPartAntipart->SetBinContent(3,0.12);
200   for(Int_t i=4;i<=20;i++) fPartAntipart->SetBinContent(i,0.05);   //5 to 12%
201   */
202   return;
203 }
204 //--------------------------------------------------------------------------
205 void AliHFSystErr::InitDstartoD0pi() {
206   // 
207   // D*+->D0pi syst errors. Responsible: tbd
208   //
209
210   return;
211 }
212 //--------------------------------------------------------------------------
213 Double_t AliHFSystErr::GetCutsEffErr(Double_t pt) const {
214   // 
215   // Get error
216   //
217
218   Int_t bin=fCutsEff->FindBin(pt);
219
220   return fCutsEff->GetBinContent(bin);
221 }
222 //--------------------------------------------------------------------------
223 Double_t AliHFSystErr::GetMCPtShapeErr(Double_t pt) const {
224   // 
225   // Get error
226   //
227
228   Int_t bin=fMCPtShape->FindBin(pt);
229
230   return fMCPtShape->GetBinContent(bin);
231 }
232 //--------------------------------------------------------------------------
233 Double_t AliHFSystErr::GetSeleEffErr(Double_t pt) const {
234   // 
235   // Get error
236   //
237
238   Double_t err=GetCutsEffErr(pt)*GetCutsEffErr(pt)+GetMCPtShapeErr(pt)*GetMCPtShapeErr(pt);
239
240   return TMath::Sqrt(err);
241 }
242 //--------------------------------------------------------------------------
243 Double_t AliHFSystErr::GetPIDEffErr(Double_t pt) const {
244   // 
245   // Get error
246   //
247
248   Int_t bin=fPIDEff->FindBin(pt);
249
250   return fPIDEff->GetBinContent(bin);
251 }
252 //--------------------------------------------------------------------------
253 Double_t AliHFSystErr::GetTrackingEffErr(Double_t pt) const {
254   // 
255   // Get error
256   //
257
258   Int_t bin=fTrackingEff->FindBin(pt);
259
260   return fTrackingEff->GetBinContent(bin);
261 }
262 //--------------------------------------------------------------------------
263 Double_t AliHFSystErr::GetRawYieldErr(Double_t pt) const {
264   // 
265   // Get error
266   //
267
268   Int_t bin=fRawYield->FindBin(pt);
269
270   return fRawYield->GetBinContent(bin);
271 }
272 //--------------------------------------------------------------------------
273 Double_t AliHFSystErr::GetPartAntipartErr(Double_t pt) const {
274   // 
275   // Get error
276   //
277
278   Int_t bin=fPartAntipart->FindBin(pt);
279
280   return fPartAntipart->GetBinContent(bin);
281 }
282 //--------------------------------------------------------------------------
283 Double_t AliHFSystErr::GetTotalSystErr(Double_t pt,Double_t feeddownErr) const {
284   // 
285   // Get total syst error (except norm. error)
286   //
287
288   Double_t err=0.;
289
290   if(fRawYield) err += GetRawYieldErr(pt)*GetRawYieldErr(pt);
291   if(fTrackingEff) err += GetTrackingEffErr(pt)*GetTrackingEffErr(pt);
292   if(fBR) err += GetBRErr()*GetBRErr();
293   if(fCutsEff) err += GetCutsEffErr(pt)*GetCutsEffErr(pt);
294   if(fPIDEff) err += GetPIDEffErr(pt)*GetPIDEffErr(pt);
295   if(fMCPtShape) err += GetMCPtShapeErr(pt)*GetMCPtShapeErr(pt);
296   if(fPartAntipart) err += GetPartAntipartErr(pt)*GetPartAntipartErr(pt);
297
298   err += feeddownErr*feeddownErr;
299
300   return TMath::Sqrt(err);
301 }
302 //---------------------------------------------------------------------------
303 void AliHFSystErr::DrawErrors(TGraphAsymmErrors *grErrFeeddown) const {
304   //
305   // Draw errors
306   //
307   gStyle->SetOptStat(0);
308
309   TCanvas *cSystErr = new TCanvas("cSystErr","Systematic Errors",0,0,500,500);
310   cSystErr->SetFillColor(0);
311
312   TH2F *hFrame = new TH2F("hFrame","Systematic errors; p_{t} [GeV/c]; Relative Error",20,0,20,100,-1,+1);
313   hFrame->SetAxisRange(2.,11.9,"X");
314   hFrame->SetAxisRange(-0.6,0.6,"Y");
315   hFrame->Draw();
316
317   TLegend *leg=new TLegend(0.5,0.5,0.9,0.9);
318   leg->SetFillStyle(0);
319   leg->SetBorderSize(0);
320   
321   TH1F *hTotErr=new TH1F("hTotErr","",20,0,20);
322   Int_t nbins = fNorm->GetNbinsX();
323   TGraphAsymmErrors *gTotErr = new TGraphAsymmErrors(nbins);
324   for(Int_t i=1;i<=20;i++) {
325     Double_t pt = hTotErr->GetBinCenter(i);
326     Double_t ptwidth = hTotErr->GetBinWidth(i);
327
328     if(grErrFeeddown) {
329       Double_t x=0., y=0., errxl=0., errxh=0., erryl=0., erryh=0.;
330       Double_t toterryl=0., toterryh=0.;
331       for(Int_t j=0; j<grErrFeeddown->GetN(); j++) {
332         grErrFeeddown->GetPoint(j,x,y);
333         errxh = grErrFeeddown->GetErrorXhigh(j);
334         errxl = grErrFeeddown->GetErrorXlow(j);
335         if ( ( (x-errxl) >= pt) && ( (x+errxl) <= pt) ) {
336           erryh = grErrFeeddown->GetErrorYhigh(j);
337           erryl = grErrFeeddown->GetErrorYlow(j);
338         }
339       }
340       if (erryl>=1e-3) toterryl = GetTotalSystErr(pt,erryl);
341       else toterryl = GetTotalSystErr(pt);
342       if (erryh>=1e-3) toterryh = GetTotalSystErr(pt,erryh);
343       else toterryh = GetTotalSystErr(pt);
344
345       hTotErr->SetBinContent(i,toterryh);
346       gTotErr->SetPoint(i,pt,0.);
347       gTotErr->SetPointError(i,ptwidth/2.,ptwidth/2.,toterryl,toterryh); // i, exl, exh, eyl, eyh
348     }
349     else {
350       hTotErr->SetBinContent(i,GetTotalSystErr(pt));
351       gTotErr->SetPoint(i,pt,0.);
352       gTotErr->SetPointError(i,ptwidth/2.,ptwidth/2.,GetTotalSystErr(pt),GetTotalSystErr(pt)); // i, exl, exh, eyl, eyh
353     }
354
355   }
356   gTotErr->SetLineColor(kBlack);
357   gTotErr->SetFillColor(kRed);
358   gTotErr->SetFillStyle(3002);
359   gTotErr->Draw("2");
360   leg->AddEntry(gTotErr,"Total (excl. norm.)","f");
361 //   hTotErr->SetLineColor(1);
362 //   hTotErr->SetLineWidth(3);
363 //   hTotErr->Draw("same");
364 //   leg->AddEntry(hTotErr,"Total (excl. norm.)","l");
365   
366
367   if(fNorm) {
368     fNorm->SetFillColor(1);
369     fNorm->SetFillStyle(3002);
370     fNorm->Draw("same");
371     TH1F *hNormRefl = ReflectHisto(fNorm);
372     hNormRefl->Draw("same");
373     leg->AddEntry(fNorm,"Normalization","f");
374   }
375   if(grErrFeeddown) {
376     grErrFeeddown->SetFillColor(kTeal-8);
377     grErrFeeddown->SetFillStyle(3001);
378     grErrFeeddown->Draw("2");
379     leg->AddEntry(grErrFeeddown,"Feed-down from B","f");
380   }
381   if(fTrackingEff) {
382     fTrackingEff->SetFillColor(4);
383     fTrackingEff->SetFillStyle(3006);
384     fTrackingEff->Draw("same");
385     TH1F *hTrackingEffRefl = ReflectHisto(fTrackingEff);
386     hTrackingEffRefl->Draw("same");
387     leg->AddEntry(fTrackingEff,"Tracking efficiency","f");
388   }
389   if(fBR) {
390     fBR->SetFillColor(6);
391     fBR->SetFillStyle(3005);
392     //fBR->SetFillStyle(3020);
393     fBR->Draw("same");
394     TH1F *hBRRefl = ReflectHisto(fBR);
395     hBRRefl->Draw("same");
396     leg->AddEntry(fBR,"Branching ratio","f");
397   }
398   if(fRawYield) {
399     Int_t ci;   // for color index setting
400     ci = TColor::GetColor("#00cc00");
401     fRawYield->SetLineColor(ci);
402     //    fRawYield->SetLineColor(3);
403     fRawYield->SetLineWidth(3);
404     fRawYield->Draw("same");
405     TH1F *hRawYieldRefl = ReflectHisto(fRawYield);
406     hRawYieldRefl->Draw("same");
407     leg->AddEntry(fRawYield,"Inv. mass analysis","l");
408   }
409   if(fCutsEff) {
410     fCutsEff->SetLineColor(4);
411     fCutsEff->SetLineWidth(3);
412     fCutsEff->Draw("same");
413     TH1F *hCutsEffRefl = ReflectHisto(fCutsEff);
414     hCutsEffRefl->Draw("same");
415     leg->AddEntry(fCutsEff,"Cuts efficiency","l");
416   }
417   if(fPIDEff) {
418     fPIDEff->SetLineColor(7);
419     fPIDEff->SetLineWidth(3);
420     fPIDEff->Draw("same");
421     TH1F *hPIDEffRefl = ReflectHisto(fPIDEff);
422     hPIDEffRefl->Draw("same");
423     leg->AddEntry(fPIDEff,"PID efficiency","l");
424   }
425   if(fMCPtShape) {
426     Int_t ci = TColor::GetColor("#9933ff");
427     fMCPtShape->SetLineColor(ci);
428     //    fMCPtShape->SetLineColor(8);
429     fMCPtShape->SetLineWidth(3);
430     fMCPtShape->Draw("same");
431     TH1F *hMCPtShapeRefl = ReflectHisto(fMCPtShape);
432     hMCPtShapeRefl->Draw("same");
433     leg->AddEntry(fMCPtShape,"MC p_{t} shape","l");
434   }
435   if(fPartAntipart) {
436     Int_t ci = TColor::GetColor("#ff6600");
437     fPartAntipart->SetLineColor(ci);
438     //    fPartAntipart->SetLineColor(9);
439     fPartAntipart->SetLineWidth(3);
440     fPartAntipart->Draw("same");
441     TH1F *hPartAntipartRefl = ReflectHisto(fPartAntipart);
442     hPartAntipartRefl->Draw("same");
443     leg->AddEntry(fPartAntipart,"D = #bar{D}","l");
444   }
445
446
447   leg->Draw();
448
449   cSystErr->SaveAs("RelativeSystematics.eps");
450
451   return;
452 }
453 //-------------------------------------------------------------------------
454 TH1F* AliHFSystErr::ReflectHisto(TH1F *hin) const {
455   //
456   // Clones and reflects histogram 
457   // 
458   TH1F *hout=(TH1F*)hin->Clone("hout");
459   hout->Scale(-1.);
460
461   return hout;
462 }