]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/vertexingHF/macros/HFPtSpectrumRaa.C
temporary hijack for the systematic uncertainties of pPb vs centrality (assigned...
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / macros / HFPtSpectrumRaa.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include "TFile.h"
3 #include "TH1.h"
4 #include "TH1D.h"
5 #include "TH2.h"
6 #include "TH2D.h"
7 #include "TH3.h"
8 #include "TH3D.h"
9 #include "TNtuple.h"
10 #include "TGraphAsymmErrors.h"
11 #include "TMath.h"
12 #include "TCanvas.h"
13 #include "TLegend.h"
14 #include "TROOT.h"
15 #include "TStyle.h"
16 #include "TLine.h"
17 #include "TLatex.h"
18
19 #include "AliHFSystErr.h"
20 #include <Riostream.h>
21 #endif
22
23 /* $Id$ */
24 ///////////////////////////////////////////////////////////////////////////////
25 //
26 // Macro to compute the Raa, taking as inputs the output of the corrected yields
27 //  and the pp reference
28 //
29 // R_AB =  [ ( dsigma/dpt )_AB / sigma_AB ]  / <TAB> *  ( dsigma/dpt )_pp
30 //
31 // 
32 // Parameters: 
33 //      1. ppfile = reference pp in the same pt binning
34 //      2. ABfile = corrected AB yields 
35 //      3. outfile = output file name
36 //      4. decay = decay as in HFSystErr class
37 //      5. sigmaABCINT1B = cross section for normalization (**USE THE SAME AS ON 2.**)
38 //      6. fdMethod = feed-down subtraction method (kNb, kfc)
39 //      7. cc = centrality class
40 //      8. Energy = colliding energy (k276,k55)
41 //      9. MinHypo  = minimum energy loss hypothesis (Default 1./3.)
42 //      10. MaxHypo = maximum energy loss hypothesis (Default 3.0)
43 //      11. MaxRb = maximum Raa(b) hypothesis (Default 6.0, won't do anything)
44 //      12. RbHypo : flag to decide whether the Eloss hypothesis is Rb or Rb/Rc
45 //      13. CentralHypo = central energy loss hypothesis, DEFAULT TO 1.0
46 //      14. isRaavsEP = flag to compute the Raa IN/OUT of plane, divides the reference by 2.0
47 //      15. ScaledAndExtrapRef: flag to tag scaled+reference pp-scaled-data
48 //
49 //  Complains to : Zaida Conesa del Valle
50 //
51 ///////////////////////////////////////////////////////////////////////////////
52
53 enum centrality{ kpp, k07half, kpPb0100, k010, k1020, k020, k2040, k2030, k3040, k4050, k3050, k5060, k4060, k6080, k4080, k5080, k80100, kpPb020, kpPb2040, kpPb4060, kpPb60100 };
54 enum centestimator{ kV0M, kV0A, kZNA };
55 enum energy{ k276, k5dot023, k55 };
56 enum BFDSubtrMethod { kfc, kNb };
57 enum RaavsEP {kPhiIntegrated, kInPlane, kOutOfPlane};
58
59 Bool_t printout = false;
60 Double_t ptprintout = 1.5;
61 Double_t NormPPUnc = 0.035;
62 Double_t NormABUnc = 0.037;
63 Bool_t elossFDQuadSum = true;
64
65 //____________________________________________________________
66 Bool_t PbPbDataSyst(AliHFSystErr *syst, Double_t pt, Int_t cc, Double_t &dataSystUp, Double_t &dataSystDown);
67
68 //____________________________________________________________
69 Double_t ExtractFDSyst(Double_t total, Double_t fd) {
70   // total^2 = data^2 + fd^2
71   Double_t data2 = total*total - fd*fd ;
72   return TMath::Sqrt( data2 );
73 }
74
75 //____________________________________________________________
76 Int_t FindGraphBin(TGraphAsymmErrors *gr, Double_t pt)
77 {
78   Int_t istart =0;
79   Int_t npoints = gr->GetN();
80   for(Int_t i=0; i<=npoints; i++){
81     Double_t x=0.,y=0.;
82     gr->GetPoint(i,x,y);
83     if ( TMath::Abs ( x - pt ) < 0.4 ) { 
84       istart = i; 
85       break;
86     }
87   }
88   return istart;
89 }
90
91
92 //
93 //
94 // R_AB =  [ ( dsigma/dpt )_AB / sigma_AB ]  / <TAB> *  ( dsigma/dpt )_pp
95 //
96 //
97 //____________________________________________________________
98 void HFPtSpectrumRaa(const char *ppfile="HFPtSpectrum_D0Kpi_method2_rebinnedth_230311_newsigma.root",
99                      const char *ABfile="HFPtSpectrum_D0Kpi_PbPbcuts_method2_rebinnedth_230311_newsigma.root",
100                      const char *outfile="HFPtSpectrumRaa.root",
101                      Int_t decay=1,
102                      Double_t sigmaABCINT1B=54.e9,
103                      Int_t fdMethod = kNb, Int_t cc=kpp, Int_t Energy=k276,
104                      Double_t MinHypo=1./3., Double_t MaxHypo=3.0, Double_t MaxRb=6.0,
105                      Bool_t isRbHypo=false, Double_t CentralHypo = 1.0,
106                      Int_t ccestimator = kV0M,
107                      Bool_t isUseTaaForRaa=true, const char *shadRbcFile="", Int_t nSigmaShad=3.0,
108                      Int_t isRaavsEP=kPhiIntegrated, Bool_t isScaledAndExtrapRef=kFALSE)
109 {
110
111   gROOT->Macro("$ALICE_ROOT/PWGHF/vertexingHF/macros/LoadLibraries.C");
112
113   //
114   // Defining the TAB values for the given centrality class
115   //
116   Double_t Tab = 1., TabSyst = 0., A=207.2, B=207.2;
117   if ( Energy!=k276 && Energy!=k5dot023) {
118     printf("\n The Tab values for this cms energy have not yet been implemented, please do it ! \n");
119     return;
120   }
121   if ( cc == kpp ){
122     Tab = 1.;
123   }
124   // Values from Alberica's twiki:
125   //   https://twiki.cern.ch/twiki/bin/viewauth/ALICE/CentStudies
126   if( ccestimator == kV0M ) {
127     if ( cc == k07half ) {
128       Tab = 24.81; TabSyst = 0.8037;
129     } else if ( cc == k010 ) {
130       Tab = 23.48; TabSyst = 0.97;
131     } else if ( cc == k1020 ) {
132       Tab = 14.4318; TabSyst = 0.5733;
133     } else if ( cc == k020 ) {
134       Tab = 18.93; TabSyst = 0.74;
135     } else if ( cc == k2040 ) {
136       Tab = 6.86; TabSyst = 0.28;
137     } else if ( cc == k2030 ) {
138       Tab = 8.73769; TabSyst = 0.370219;
139     } else if ( cc == k3040 ) {
140       Tab = 5.02755; TabSyst = 0.22099;
141     } else if ( cc == k4050 ) {
142       Tab = 2.68327; TabSyst = 0.137073;
143     } else if ( cc == k3050 ) {
144       Tab = 3.87011; TabSyst = 0.183847;
145     } else if ( cc == k4060 ) {
146       Tab = 2.00;  TabSyst= 0.11;
147     } else if ( cc == k4080 ) {
148       Tab = 1.20451; TabSyst = 0.071843;
149     } else if ( cc == k5060 ) {
150       Tab = 1.32884; TabSyst = 0.0929536;
151     } else if ( cc == k6080 ) {
152       Tab = 0.419; TabSyst = 0.033;
153     } else if ( cc == k5080 ) {
154       Tab = 0.719; TabSyst = 0.054;
155     } else if ( cc == k80100 ){
156       Tab = 0.0690; TabSyst = 0.0062;
157     }
158   }
159
160   // pPb Glauber (A. Toia)
161   // https://twiki.cern.ch/twiki/bin/viewauth/ALICE/PACentStudies#Glauber_Calculations_with_sigma
162   if( cc == kpPb0100 ){
163     Tab = 0.098334; TabSyst = 0.0070679;
164     A=207.2; B=1.;
165   }
166   else if( ccestimator == kV0A ){
167     if ( cc == kpPb020 ) {
168       Tab = 0.183; TabSyst = 0.0201;
169     } else if ( cc == kpPb2040 ) {
170       Tab = 0.134; TabSyst = 0.0134;
171     } else if ( cc == kpPb4060 ) {
172       Tab = 0.0918; TabSyst = 0.0073;
173     } else if ( cc == kpPb60100 ) {
174       Tab = 0.0366; TabSyst = 0.00183;
175     }
176   }
177   else if( ccestimator == kZNA ){
178     if ( cc == kpPb020 ) {
179       Tab = 0.1650; TabSyst = 0.0550;
180     } else if ( cc == kpPb2040 ) {
181       Tab = 0.137; TabSyst = 0.0372;
182     } else if ( cc == kpPb4060 ) {
183       Tab = 0.1001; TabSyst = 0.0690;
184     } else if ( cc == kpPb60100 ) {
185       Tab = 0.045; TabSyst = 0.1029;
186     }
187   }
188
189   //
190   // Reading the pp file 
191   //
192   TFile * ppf = new TFile(ppfile,"read");
193   TH1D * hSigmaPP;
194   TGraphAsymmErrors * gSigmaPPSyst;
195   TGraphAsymmErrors * gSigmaPPSystData = (TGraphAsymmErrors*)ppf->Get("gScaledDataSystData");
196   TGraphAsymmErrors * gSigmaPPSystTheory = (TGraphAsymmErrors*)ppf->Get("gScaledDataSystExtrap");
197   TGraphAsymmErrors * gSigmaPPSystFeedDown = (TGraphAsymmErrors*)ppf->Get("gScaledDataSystFeedDown");
198   TH1I * hCombinedReferenceFlag;
199   TGraphAsymmErrors * gReferenceFdSyst;
200   if(isScaledAndExtrapRef){
201     hCombinedReferenceFlag = (TH1I*)ppf->Get("hCombinedReferenceFlag");
202     hSigmaPP = (TH1D*)ppf->Get("hReference");
203     gSigmaPPSyst = (TGraphAsymmErrors*)ppf->Get("gReferenceSyst");
204     gReferenceFdSyst = (TGraphAsymmErrors*)ppf->Get("gReferenceFdSyst");
205   } else { 
206     hSigmaPP = (TH1D*)ppf->Get("fhScaledData");
207     gSigmaPPSyst = (TGraphAsymmErrors*)ppf->Get("gScaledData");
208   }
209   
210   // Call the systematics uncertainty class for a given decay
211   AliHFSystErr *systematicsPP = new AliHFSystErr();
212   systematicsPP->Init(decay);
213
214   //
215   // Reading the AB collisions file
216   // 
217   TFile * ABf = new TFile(ABfile,"read");
218   TH1D *hSigmaAB = (TH1D*)ABf->Get("histoSigmaCorr");
219   TH2D *hSigmaABRcb = (TH2D*)ABf->Get("histoSigmaCorrRcb");
220   TGraphAsymmErrors * gSigmaABSyst = (TGraphAsymmErrors*)ABf->Get("gSigmaCorr");
221   TGraphAsymmErrors * gSigmaABSystFeedDown = (TGraphAsymmErrors*)ABf->Get("gSigmaCorrConservative");
222   TNtuple * nSigmaAB = (TNtuple*)ABf->Get("fnSigma");
223   //
224   TH1D *hMassAB = (TH1D*)ABf->Get("hRECpt");
225   TH1D *hDirectEffptAB = (TH1D*)ABf->Get("hDirectEffpt");
226   TH1D *histofcAB = (TH1D*)ABf->Get("histofc");
227   //
228   TH1D* fhStatUncEffcSigmaAB = (TH1D*)ABf->Get("fhStatUncEffcSigma");
229   TH1D* fhStatUncEffbSigmaAB = (TH1D*)ABf->Get("fhStatUncEffbSigma");
230   TH1D* fhStatUncEffcFDAB = (TH1D*)ABf->Get("fhStatUncEffcFD");
231   TH1D* fhStatUncEffbFDAB = (TH1D*)ABf->Get("fhStatUncEffbFD");
232   //
233   TH1D* fhStatUncEffcSigmaAB_Raa = (TH1D*)fhStatUncEffcSigmaAB->Clone("fhStatUncEffcSigmaAB_Raa");
234   TH1D* fhStatUncEffbSigmaAB_Raa = (TH1D*)fhStatUncEffbSigmaAB->Clone("fhStatUncEffbSigmaAB_Raa");
235   TH1D* fhStatUncEffcFDAB_Raa = (TH1D*)fhStatUncEffcFDAB->Clone("fhStatUncEffcFDAB_Raa");
236   TH1D* fhStatUncEffbFDAB_Raa = (TH1D*)fhStatUncEffbFDAB->Clone("fhStatUncEffbFDAB_Raa");
237   fhStatUncEffcSigmaAB_Raa->Reset();
238   fhStatUncEffbSigmaAB_Raa->Reset();
239   fhStatUncEffcFDAB_Raa->Reset();
240   fhStatUncEffbFDAB_Raa->Reset();
241   fhStatUncEffcSigmaAB_Raa->SetName("fhStatUncEffcSigmaAB_Raa");
242   fhStatUncEffbSigmaAB_Raa->SetName("fhStatUncEffbSigmaAB_Raa");
243   fhStatUncEffcFDAB_Raa->SetName("fhStatUncEffcFDAB_Raa");
244   fhStatUncEffbFDAB_Raa->SetName("fhStatUncEffvFDAB_Raa");
245
246
247   //
248   // Call the systematics uncertainty class for a given decay
249   AliHFSystErr *systematicsAB = new AliHFSystErr();
250   systematicsAB->SetCollisionType(1);
251   if ( cc == k07half ) systematicsAB->SetCentrality("07half");
252   else if ( cc == k010 ) systematicsAB->SetCentrality("010");
253   else if ( cc == k1020 ) systematicsAB->SetCentrality("1020");
254   else if ( cc == k020 ) systematicsAB->SetCentrality("020");
255   else if ( cc == k2040 || cc == k2030 || cc == k3040 ) {
256     systematicsAB->SetCentrality("2040");
257     systematicsAB->SetIsPbPb2010EnergyScan(true);
258   }
259   else if ( cc == k4060 || cc == k4050 || cc == k5060 ) systematicsAB->SetCentrality("4060");
260   else if ( cc == k6080 || cc == k5080 ) systematicsAB->SetCentrality("6080");
261   else if ( cc == k4080 ) systematicsAB->SetCentrality("4080");
262   else if ( cc == k3050 ) {
263     if (isRaavsEP == kPhiIntegrated) systematicsAB->SetCentrality("4080");
264     else if (isRaavsEP == kInPlane) systematicsAB->SetCentrality("3050InPlane");
265     else if (isRaavsEP == kOutOfPlane) systematicsAB->SetCentrality("3050OutOfPlane");
266   }
267   //
268   else if ( cc == kpPb0100 || cc == kpPb020 || cc == kpPb2040 || cc == kpPb4060 || cc == kpPb60100 ) {
269     systematicsAB->SetCollisionType(2); 
270   }
271   else { 
272     cout << " Systematics not yet implemented " << endl;
273     return;
274   }
275   //
276   systematicsAB->Init(decay);
277
278   //
279   Int_t entries = nSigmaAB->GetEntries();
280   Float_t pt=0., signal=0., Rb=0., Rcb=0., fcAB=0., yieldAB=0., sigmaAB=0., statUncSigmaAB=0., sigmaABMin=0.,sigmaABMax=0.;
281   nSigmaAB->SetBranchAddress("pt",&pt);
282   nSigmaAB->SetBranchAddress("Signal",&signal);
283   if (fdMethod==kNb) nSigmaAB->SetBranchAddress("Rb",&Rb);
284   else if (fdMethod==kfc) nSigmaAB->SetBranchAddress("Rcb",&Rcb);
285   nSigmaAB->SetBranchAddress("fc",&fcAB);
286   nSigmaAB->SetBranchAddress("Yield",&yieldAB);
287   nSigmaAB->SetBranchAddress("Sigma",&sigmaAB);
288   nSigmaAB->SetBranchAddress("SigmaStatUnc",&statUncSigmaAB);
289   nSigmaAB->SetBranchAddress("SigmaMax",&sigmaABMax);
290   nSigmaAB->SetBranchAddress("SigmaMin",&sigmaABMin);
291         
292   
293   // define the binning
294   Int_t nbins = hSigmaAB->GetNbinsX();
295   Double_t binwidth = hSigmaAB->GetBinWidth(1);
296   Double_t *limits = new Double_t[nbins+1];
297   Double_t *binwidths = new Double_t[nbins];
298   Double_t xlow=0.;
299   for (Int_t i=1; i<=nbins; i++) {
300     binwidth = hSigmaAB->GetBinWidth(i);
301     xlow = hSigmaAB->GetBinLowEdge(i);
302     limits[i-1] = xlow;
303     binwidths[i-1] = binwidth;
304   }
305   limits[nbins] = xlow + binwidth;
306
307
308   //
309   // Read the shadowing file if given as input
310   //
311   Double_t centralRbcShad[nbins+1], minRbcShad[nbins+1], maxRbcShad[nbins+1];
312   for(Int_t i=0; i<=nbins; i++) { centralRbcShad[i]=1.0; minRbcShad[i]=6.0; maxRbcShad[i]=0.0; }
313   Bool_t isShadHypothesis = false;
314   if( strcmp(shadRbcFile,"")!=0 ) {
315     isShadHypothesis = true;
316     cout<<endl<<">>  Beware, using the shadowing prediction file with an "<<nSigmaShad<<"*sigma <<"<<endl<<endl;
317     TFile *fshad = new TFile(shadRbcFile,"read");
318     if(!fshad){ cout <<" >> Shadowing file not properly opened!!!"<<endl<<endl; return;}
319     // TH1D *hRbcShadCentral = (TH1D*)fshad->Get("hDfromBoverPromptD_Shadowing_central");
320     // TH1D *hRbcShadMin = (TH1D*)fshad->Get("hDfromBoverPromptD_Shadowing_upper");
321     // TH1D *hRbcShadMax = (TH1D*)fshad->Get("hDfromBoverPromptD_Shadowing_lower");
322     TH1D *hRbcShadCentral = (TH1D*)fshad->Get("hDfromBoverDfromc_L0");
323     TH1D *hRbcShadMin = (TH1D*)fshad->Get("hDfromBoverDfromc_L0");
324     TH1D *hRbcShadMax = (TH1D*)fshad->Get("hDfromBoverDfromc_L1");
325     if(!hRbcShadCentral || !hRbcShadMin || !hRbcShadMax) {
326       cout<< endl <<">> Shadowing input histograms are not ok !! "<<endl<<endl;
327       return;
328     }
329     //       nSigmaShad
330     //    nSigmaShad
331     for(Int_t i=1; i<=nbins; i++) {
332       Double_t xpt = hSigmaAB->GetBinCenter(i);
333       if(xpt>24) xpt = 20;
334       centralRbcShad[i] = hRbcShadCentral->GetBinContent( hRbcShadCentral->FindBin(xpt) );
335       Double_t minValue0 = hRbcShadMin->GetBinContent( hRbcShadMin->FindBin(xpt) );
336       Double_t maxValue0 = hRbcShadMax->GetBinContent( hRbcShadMax->FindBin(xpt) );
337       Double_t arrayEl[3] = {minValue0,maxValue0, centralRbcShad[i]};
338       Double_t minValue = TMath::MinElement(3,arrayEl);
339       Double_t maxValue = TMath::MaxElement(3,arrayEl);
340       cout<<">> Shadowing pt="<<xpt<<"  central="<<centralRbcShad[i]<<"  min="<<minValue<<"  max="<<maxValue<<endl;
341       if(minValue>centralRbcShad[i]){ minValue = centralRbcShad[i]; }
342       if(maxValue<centralRbcShad[i]){ maxValue = centralRbcShad[i]; }
343       minRbcShad[i] = centralRbcShad[i] - nSigmaShad*(centralRbcShad[i] - minValue);
344       maxRbcShad[i] = centralRbcShad[i] + nSigmaShad*(maxValue - centralRbcShad[i]);
345       cout<<">> Shadowing hypothesis pt="<<xpt<<"  central="<<centralRbcShad[i]<<"  min="<<minRbcShad[i]<<"  max="<<maxRbcShad[i]<<endl;
346     }
347   }
348
349   //
350   // define the bins correspondence bw histos/files/graphs
351   //
352   //
353   TH2D * hRABvsRcb = new TH2D("hRABvsRcb"," R_{AB}(c) vs Rcb Eloss hypothesis; p_{T} [GeV/c] ;  R_{AB}(c) ; Rcb Eloss hypothesis  ",nbins,limits,800,0.,4.);
354   TH2D * hRABvsRb = new TH2D("hRABvsRb"," R_{AB}(c) vs Rb Eloss hypothesis; p_{T} [GeV/c] ;  R_{AB}(c) ; Rb Eloss hypothesis ",nbins,limits,800,0.,4.);
355   TH2D * hRABBeautyvsRCharm = new TH2D("hRABBeautyvsRCharm"," R_{AB}(c) vs Rb Eloss hypothesis; p_{T} [GeV/c] ;  R_{AB}(b) ;  R_{AB}(c) ",nbins,limits,800,0.,4.);
356   Int_t nbinsHypo=800;//200;
357   Double_t *limitsHypo = new Double_t[nbinsHypo+1];
358   for(Int_t i=1; i<=nbinsHypo+1; i++) limitsHypo[i-1]= i*4./800.;
359   TH3D * hRABCharmVsRBeautyVsPt = new TH3D("hRABCharmVsRBeautyVsPt"," R_{AB}(c) vs Rb vs p_{T} Eloss hypothesis; p_{T} [GeV/c] ;  R_{AB}(b) ;  R_{AB}(c) ",nbins,limits,nbinsHypo,limitsHypo,nbinsHypo,limitsHypo);
360   TH2D *hRCharmVsRBeauty[nbins+1];
361   for(Int_t i=0; i<=nbins; i++) hRCharmVsRBeauty[i] = new TH2D(Form("hRCharmVsRBeauty_%i",i),Form("RAB(c) vs RAB(b) for pt bin %i ; R_{AB}(b) ;  R_{AB}(c)",i),nbinsHypo,limitsHypo,nbinsHypo,limitsHypo);
362   TH2D *hRCharmVsElossHypo[nbins+1];
363   for(Int_t i=0; i<=nbins; i++) hRCharmVsElossHypo[i] = new TH2D(Form("hRCharmVsElossHypo_%i",i),Form("RAB(c) vs ElossHypo for pt bin %i ; Eloss Hypothesis (c/b) ;  R_{AB}(c)",i),nbinsHypo,limitsHypo,nbinsHypo,limitsHypo);
364   //
365   TH1D *hRABEloss00= new TH1D("hRABEloss00","hRABEloss00",nbins,limits);
366   TH1D *hRABEloss05= new TH1D("hRABEloss05","hRABEloss05",nbins,limits);
367   TH1D *hRABEloss10= new TH1D("hRABEloss10","hRABEloss10",nbins,limits);
368   TH1D *hRABEloss15= new TH1D("hRABEloss15","hRABEloss15",nbins,limits);
369   TH1D *hRABEloss20= new TH1D("hRABEloss20","hRABEloss20",nbins,limits);
370   //
371   TH2D * hRABvsRbFDlow = new TH2D("hRABvsRbFDlow"," R_{AB}(c) vs Rb Eloss hypothesis (FD low); p_{T} [GeV/c] ; Rb Eloss hypothesis ; R_{AB}(c) ",nbins,limits,800,0.,4.);
372   TH2D * hRABvsRbFDhigh = new TH2D("hRABvsRbFDhigh"," R_{AB}(c) vs Rb Eloss hypothesis (FD high); p_{T} [GeV/c] ; Rb Eloss hypothesis ; R_{AB}(c) ",nbins,limits,800,0.,4.);
373   //
374   TH1D * hRABvsRbFDhigh_proj = new TH1D("hRABvsRbFDhigh_proj","hRABvsRbFDhigh_proj",nbins,limits);
375   TH1D * hRABvsRbFDlow_proj = new TH1D("hRABvsRbFDlow_proj","hRABvsRbFDlow_proj",nbins,limits);
376   //
377   TNtuple *ntupleRAB=0x0 ;
378   if (fdMethod==kNb) {
379     ntupleRAB = new TNtuple("ntupleRAB","ntupleRAB (Nb)","pt:TAB:sigmaPP:sigmaAB:invyieldAB:invyieldABFDHigh:invyieldABFDLow:RABCharm:RABCharmFDHigh:RABCharmFDLow:RABBeauty:fc",100000);
380   } else if (fdMethod==kfc) {
381     ntupleRAB = new TNtuple("ntupleRAB","ntupleRAB (fc)","pt:TAB:sigmaPP:sigmaAB:invyieldAB:invyieldABFDHigh:invyieldABFDLow:Rcb:RABCharm:RABCharmFDHigh:RABCharmFDLow:RABBeauty:RABBeautyFDHigh:RABBeautyFDLow:fc",100000);
382   }
383   if(!ntupleRAB) printf("ERROR: Wrong method option");
384
385   TH1D * hYieldABvsPt = new TH1D("hYieldABvsPt"," Yield_{AB}(c) vs p_{T} (no Eloss hypothesis); p_{T} [GeV/c] ; Yield_{charm} ",nbins,limits);
386   TH1D * hRABvsPt = new TH1D("hRABvsPt"," R_{AB}(c) vs p_{T} (no Eloss hypothesis); p_{T} [GeV/c] ; R_{charm} ",nbins,limits);
387   TH1D * hRABvsPt_DataSystematics = new TH1D("hRABvsPt_DataSystematics"," Systematics of R_{AB} (c) vs p_{T} (no Eloss hypothesis); p_{T} [GeV/c] ; R_{charm} ",nbins,limits);
388   TGraphAsymmErrors *gRAB_ElossHypothesis = new TGraphAsymmErrors(nbins+1);
389   gRAB_ElossHypothesis->SetNameTitle("gRAB_ElossHypothesis","RAB Eloss systematics");
390   TGraphAsymmErrors *gRAB_FeedDownSystematics = new TGraphAsymmErrors(nbins+1);
391   gRAB_FeedDownSystematics->SetNameTitle("gRAB_FeedDownSystematics","RAB Feed-Down systematics");
392   TGraphAsymmErrors *gRAB_fcFeedDownOnly = new TGraphAsymmErrors(nbins+1);
393   gRAB_fcFeedDownOnly->SetNameTitle("gRAB_fcFeedDownOnly","RAB fc Feed-Down Only");
394   TGraphAsymmErrors *gRAB_FeedDownSystematicsElossHypothesis = new TGraphAsymmErrors(nbins+1);
395   gRAB_FeedDownSystematicsElossHypothesis->SetNameTitle("gRAB_FeedDownSystematicsElossHypothesis","RAB Feed-Down systematics considering Eloss hypothesis");
396   TGraphAsymmErrors *gRAB_DataSystematics = new TGraphAsymmErrors(nbins+1);
397   gRAB_DataSystematics->SetNameTitle("gRAB_DataSystematics","RAB Measurement (no FD, no Eloss) systematics");
398   TGraphAsymmErrors *gRAB_DataSystematicsPP = new TGraphAsymmErrors(nbins+1);
399   gRAB_DataSystematicsPP->SetNameTitle("gRAB_DataSystematicsPP","RAB Measurement PP meas. systematics (data+scaling)");
400   TGraphAsymmErrors *gRAB_DataSystematicsAB = new TGraphAsymmErrors(nbins+1);
401   gRAB_DataSystematicsAB->SetNameTitle("gRAB_DataSystematicsAB","RAB Measurement AB (no FD, no Eloss, no PP data) systematics");
402   TGraphAsymmErrors *gRAB_GlobalSystematics = new TGraphAsymmErrors(nbins+1);
403   gRAB_GlobalSystematics->SetNameTitle("gRAB_GlobalSystematics","RAB Measurement global (data, FD, Eloss) systematics");
404   Double_t ElossMax[nbins+1], ElossMin[nbins+1];
405   for(Int_t i=0; i<=nbins; i++) { ElossMax[i]=0.; ElossMin[i]=6.; }
406   Double_t fcElossMax[nbins+1], fcElossMin[nbins+1];
407   for(Int_t i=0; i<=nbins; i++) { fcElossMax[i]=0.; fcElossMin[i]=6.; }
408   Double_t FDElossMax[nbins+1], FDElossMin[nbins+1];
409   for(Int_t i=0; i<=nbins; i++) { FDElossMax[i]=0.; FDElossMin[i]=6.; }
410
411   TGraphAsymmErrors *gRAB_Norm = new TGraphAsymmErrors(1);
412   gRAB_Norm->SetNameTitle("gRAB_Norm","RAB Normalization systematics (pp norm + Tab)");
413   Double_t normUnc = TMath::Sqrt ( NormPPUnc*NormPPUnc + (TabSyst/Tab)*(TabSyst/Tab) );
414   if(!isUseTaaForRaa) normUnc = TMath::Sqrt ( NormPPUnc*NormPPUnc + NormABUnc*NormABUnc );
415   gRAB_Norm->SetPoint(1,0.5,1.);
416   gRAB_Norm->SetPointError(1,0.25,0.25,normUnc,normUnc);
417
418   //
419   // R_AB =  ( dN/dpt )_AB  / <Ncoll_AB> *  ( dN/dpt )_pp ; <Ncoll> = <Tab> * sigma_NN^inel
420   // R_AB =  [ ( dsigma/dpt )_AB / sigma_AB ]  / <TAB> *  ( dsigma/dpt )_pp
421   //
422   Int_t istartPPfd=0, istartPPsyst=0, istartABfd=0, istartPPextr=0;
423   Double_t yPPh=0., yPPl=0., yABh=0., yABl=0.;
424   Double_t RaaCharm =0., RaaBeauty=0.;
425   Double_t RaaCharmFDhigh = 0., RaaCharmFDlow = 0.;
426   Double_t RaaBeautyFDhigh = 0., RaaBeautyFDlow = 0.;
427   Double_t systUp=0., systLow=0., systPPUp=0., systPPLow=0., systABUp=0., systABLow=0.;
428   //
429   //
430   // Search the central value of the energy loss hypothesis Rb = Rc (bin)
431   //
432   Double_t ElossCentral[nbins+1];
433   for(Int_t i=0; i<=nbins; i++) { ElossCentral[i]=0.; }
434   //
435   for(Int_t ientry=0; ientry<=entries; ientry++){
436
437     nSigmaAB->GetEntry(ientry);
438     //    cout << " pt="<< pt<<" sigma-AB="<<sigmaAB<<endl;
439     if ( !(sigmaAB>0.) ) continue;
440     //if(decay==2 && pt<2.) continue;
441
442     // Compute RAB and the statistical uncertainty
443     Int_t hppbin = hSigmaPP->FindBin( pt );
444     Int_t hABbin = hSigmaAB->FindBin( pt );
445     Double_t sigmapp = hSigmaPP->GetBinContent( hppbin );
446     //    cout << " pt="<< pt<<", sigma-pp="<< sigmapp<<endl;
447     if (isRaavsEP>0.) sigmapp = 0.5*sigmapp;
448     if ( !(sigmapp>0.) ) continue;
449
450     RaaCharm =  ( sigmaAB / sigmaABCINT1B ) / ((Tab*1e3) * sigmapp *1e-12 ) ;
451     if(!isUseTaaForRaa) { 
452       RaaCharm =  ( sigmaAB ) / ( (A*B) * sigmapp ) ;
453     }
454
455     if (fdMethod==kNb) {
456       RaaBeauty = Rb ; 
457     }
458     else if (fdMethod==kfc) {
459       RaaBeauty = ( RaaCharm / Rcb ) ;
460     }
461
462     Double_t ElossHypo = 0.;
463     if (fdMethod==kfc) { ElossHypo = 1. / Rcb; }
464     else  { ElossHypo = 1. / (RaaCharm / RaaBeauty) ; }
465     if(isRbHypo) ElossHypo = RaaBeauty;
466
467     // If using shadowing hypothesis, change the central hypothesis too
468     if(isShadHypothesis) CentralHypo = centralRbcShad[hABbin];
469
470     //    cout <<" pt "<< pt << " Raa charm " << RaaCharm << " Raa beauty " << RaaBeauty << " eloss hypo "<< ElossHypo<<endl; 
471     //
472     // Find the bin for the central Eloss hypo
473     //
474     if( TMath::Abs( ElossHypo - CentralHypo ) < 0.075 ){
475       Double_t DeltaIni = TMath::Abs( ElossCentral[ hABbin ] - CentralHypo );
476       Double_t DeltaV = TMath::Abs( ElossHypo - CentralHypo );
477       //      cout << " pt " << pt << " ECentral " << ElossCentral[ hABbin ] << " Ehypo "<< ElossHypo ;
478       if ( DeltaV < DeltaIni ) ElossCentral[ hABbin ] = ElossHypo;
479       //      cout << " final ECentral " << ElossCentral[ hABbin ] << endl;
480     }
481   }
482   //
483   // Calculation of the Raa and its uncertainties
484   //
485   for(Int_t ientry=0; ientry<entries; ientry++){
486
487     nSigmaAB->GetEntry(ientry);
488     if ( !(sigmaAB>0.) ) continue;
489     //    if ( pt<2 || pt>16) continue;
490
491
492     // Compute RAB and the statistical uncertainty
493     Int_t hppbin = hSigmaPP->FindBin( pt );
494     Double_t sigmapp = hSigmaPP->GetBinContent( hppbin );
495     if (isRaavsEP>0.) sigmapp = 0.5*sigmapp;
496     if ( !(sigmapp>0.) ) continue;
497
498     RaaCharm =  ( sigmaAB / sigmaABCINT1B ) / ((Tab*1e3) * sigmapp *1e-12 );
499     if(!isUseTaaForRaa) {
500       RaaCharm =  ( sigmaAB ) / ( (A*B) * sigmapp ) ;
501     }
502
503     // Flag to know if it is an scaled or extrapolated point of the pp reference
504     Bool_t isExtrapolatedBin = kFALSE;
505     if(isScaledAndExtrapRef) isExtrapolatedBin = hCombinedReferenceFlag->GetBinContent( hppbin );
506     istartPPsyst = -1;
507     istartPPsyst = FindGraphBin(gSigmaPPSyst,pt);
508
509     //
510     // FONLL Feed-Down systematics
511     //
512     istartPPfd = -1;
513     if(!isExtrapolatedBin) istartPPfd = FindGraphBin(gSigmaPPSystFeedDown,pt);
514     istartABfd = -1;
515     istartABfd = FindGraphBin(gSigmaABSystFeedDown,pt);
516
517     //      cout << " Starting bin for pp is "<< istartPPfd <<", for AA is "<<istartABfd << endl;
518     if(isExtrapolatedBin){
519       Int_t ibinfd = FindGraphBin(gReferenceFdSyst,pt);
520       yPPh = gReferenceFdSyst->GetErrorYhigh(ibinfd);
521       yPPl = gReferenceFdSyst->GetErrorYlow(ibinfd);
522     } else { 
523       yPPh = gSigmaPPSystFeedDown->GetErrorYhigh(istartPPfd);
524       yPPl = gSigmaPPSystFeedDown->GetErrorYlow(istartPPfd);
525     }
526     if (isRaavsEP>0.) {
527       yPPh = yPPh*0.5;
528       yPPl = yPPl*0.5;
529     }
530
531     yABh = gSigmaABSystFeedDown->GetErrorYhigh(istartABfd);
532     yABl = gSigmaABSystFeedDown->GetErrorYlow(istartABfd);
533
534
535     RaaCharmFDhigh = ( sigmaABMax / sigmaABCINT1B ) / ((Tab*1e3) * (sigmapp+yPPh) *1e-12 ) ;
536     RaaCharmFDlow =  ( sigmaABMin / sigmaABCINT1B ) / ((Tab*1e3) * (sigmapp-yPPl) *1e-12 ) ;
537     if(printout && TMath::Abs(ptprintout-pt)<0.1 ) cout << endl<<" pt "<< pt << " Raa " << RaaCharm <<" high "<< RaaCharmFDhigh << " low "<< RaaCharmFDlow<<endl;
538     if(!isUseTaaForRaa) {
539       RaaCharmFDhigh = ( sigmaABMax ) / ( (A*B)* (sigmapp+yPPh) ) ;
540       RaaCharmFDlow =  ( sigmaABMin ) / ( (A*B)* (sigmapp-yPPl) ) ;
541     }
542
543
544     if (fdMethod==kNb) {
545       RaaBeauty = Rb ; 
546       RaaBeautyFDlow = Rb ;
547       RaaBeautyFDhigh = Rb ;
548       ntupleRAB->Fill( pt, Tab*1e3, sigmapp*1e-12, sigmaAB*1e-12, sigmaAB/sigmaABCINT1B,
549                        sigmaABMax / sigmaABCINT1B, sigmaABMin / sigmaABCINT1B,
550                        RaaCharm, RaaCharmFDhigh, RaaCharmFDlow, RaaBeauty, fcAB );
551     }
552     else if (fdMethod==kfc) {
553       RaaBeauty = ( RaaCharm / Rcb ) ;
554       RaaBeautyFDlow = ( RaaCharmFDlow / Rcb ) ;
555       RaaBeautyFDhigh = ( RaaCharmFDhigh / Rcb ) ;
556       hRABvsRcb->Fill( pt, RaaCharm, RaaBeauty );
557       ntupleRAB->Fill( pt, Tab*1e3, sigmapp*1e-12, sigmaAB*1e-12, sigmaAB/sigmaABCINT1B,
558                        sigmaABMax / sigmaABCINT1B, sigmaABMin / sigmaABCINT1B,
559                        Rcb, RaaCharm, RaaCharmFDhigh, RaaCharmFDlow, RaaBeauty, RaaBeautyFDhigh, RaaBeautyFDlow, fcAB );
560     }
561     hRABvsRb->Fill( pt, RaaCharm, RaaBeauty );
562     hRABvsRbFDlow->Fill( pt, RaaCharmFDlow, RaaBeautyFDlow );
563     hRABvsRbFDhigh->Fill( pt, RaaCharmFDhigh, RaaBeautyFDhigh );
564     if(printout && TMath::Abs(ptprintout-pt)<0.1) cout << " pt "<< pt << " Rb " << RaaBeauty <<" high "<< RaaBeautyFDhigh << " low "<< RaaBeautyFDlow <<endl;
565
566     hRABCharmVsRBeautyVsPt->Fill( pt, RaaBeauty, RaaCharm );
567     Int_t ptbin = hRABvsPt->FindBin( pt );
568     hRCharmVsRBeauty[ptbin]->Fill( RaaBeauty, RaaCharm );
569     hRCharmVsRBeauty[ptbin]->Fill( RaaBeautyFDlow, RaaCharmFDlow );
570     hRCharmVsRBeauty[ptbin]->Fill( RaaBeautyFDhigh, RaaCharmFDhigh );
571
572
573     if (fdMethod==kfc) {
574       if( TMath::Abs(Rcb-0.015)<0.009 ) hRABEloss00->Fill(pt,RaaCharm);
575       if( TMath::Abs(Rcb-0.5)<0.009 ) hRABEloss05->Fill(pt,RaaCharm);
576       if( TMath::Abs(Rcb-1.0)<0.009 ) {
577         hRABEloss10->Fill(pt,RaaCharm);
578         hRABvsRbFDhigh_proj->Fill(pt,RaaCharmFDhigh);
579         hRABvsRbFDlow_proj->Fill(pt,RaaCharmFDlow);
580       }
581       if( TMath::Abs(Rcb-1.5)<0.009 ) hRABEloss15->Fill(pt,RaaCharm);
582       if( TMath::Abs(Rcb-2.0)<0.009 ) hRABEloss20->Fill(pt,RaaCharm);
583     }
584     else if (fdMethod==kNb) {
585       if( TMath::Abs(RaaBeauty-0.015)<0.009 ) hRABEloss00->Fill(pt,RaaCharm);
586       if( TMath::Abs(RaaBeauty-0.5)<0.009 ) hRABEloss05->Fill(pt,RaaCharm);
587       if( TMath::Abs(RaaBeauty-1.0)<0.009 ) {
588         hRABEloss10->Fill(pt,RaaCharm);
589         hRABvsRbFDhigh_proj->Fill(pt,RaaCharmFDhigh);
590         hRABvsRbFDlow_proj->Fill(pt,RaaCharmFDlow);
591       }
592       if( TMath::Abs(RaaBeauty-1.5)<0.009 ) hRABEloss15->Fill(pt,RaaCharm);
593       if( TMath::Abs(RaaBeauty-2.0)<0.009 ) hRABEloss20->Fill(pt,RaaCharm);
594     }
595
596
597     Int_t hABbin = hMassAB->FindBin( pt );
598     if(isShadHypothesis) CentralHypo = centralRbcShad[hABbin];
599
600     if(printout && TMath::Abs(ptprintout-pt)<0.1)
601     if ( fdMethod==kNb && TMath::Abs(Rb -CentralHypo)< 0.05) {
602       cout << " pt "<< pt <<", at bin "<<hABbin<<endl;
603       cout<<" entries "<<entries<<", i="<<ientry<<", pt="<<pt<<", Rb="<<Rb<<", Tab="<<Tab<<", sigmaAB="<<sigmaAB<<", sigmapp="<<sigmapp<<", Raacharm="<<RaaCharm<<", RaaBeauty="<<RaaBeauty<<endl;
604       cout << "  AB  basis: mass "<< hMassAB->GetBinContent(hABbin)<<", eff "<< hDirectEffptAB->GetBinContent(hABbin)<<endl;
605       cout<<"   FD low,  err low AB "<< (sigmaAB-sigmaABMin)<<"  err low PP "<< yPPl<<" Raacharm="<<RaaCharmFDlow<<", RaaBeauty="<<RaaBeautyFDlow<<endl;
606       cout<<"   FD high, err high AB "<< (sigmaABMax-sigmaAB)<<"  err high PP "<< yPPh<<" Raacharm="<<RaaCharmFDhigh<<", RaaBeauty="<<RaaBeautyFDhigh<<endl;
607     }
608     if(printout && TMath::Abs(ptprintout-pt)<0.1)
609     if ( fdMethod==kfc) if(TMath::Abs(Rcb -CentralHypo)< 0.05 ){
610       cout << " pt "<< pt <<", at bin "<<hABbin<<endl;
611       cout<<" entries "<<entries<<", i="<<ientry<<", pt="<<pt<<", Rcb="<<Rcb<<", Tab="<<Tab<<", sigmaAB="<<sigmaAB<<", sigmapp="<<sigmapp<<", Raacharm="<<RaaCharm<<", RaaBeauty="<<RaaBeauty<<endl;
612       cout << "  AB  basis: mass "<< hMassAB->GetBinContent(hABbin)<<", eff "<< hDirectEffptAB->GetBinContent(hABbin)<<", fc "<<histofcAB->GetBinContent(hABbin)<< endl;       
613       cout<<"   FD low,  err low AB "<< (sigmaAB-sigmaABMin)<<"  err low PP "<< yPPl<<" Raacharm="<<RaaCharmFDlow<<", RaaBeauty="<<RaaBeautyFDlow<<endl;
614       cout<<"   FD high, err high AB "<< (sigmaABMax-sigmaAB)<<"  err high PP "<< yPPh<<" Raacharm="<<RaaCharmFDhigh<<", RaaBeauty="<<RaaBeautyFDhigh<<endl;
615     }
616
617
618     //
619     // Fill in the global properties ?
620     //
621     Double_t ElossHypo = 0.;
622     if (fdMethod==kfc) { ElossHypo = 1./ Rcb; }
623     else  { ElossHypo = 1. / (RaaCharm / RaaBeauty); }
624     if(isRbHypo) ElossHypo = RaaBeauty;
625     hRCharmVsElossHypo[ptbin]->Fill( ElossHypo, RaaCharm );
626
627    // If using shadowing hypothesis, change the limit hypothesis too
628     if(isShadHypothesis) {
629       MinHypo = minRbcShad[ hABbin ];
630       MaxHypo = maxRbcShad[ hABbin ];
631     }
632
633     //    cout <<" pt "<< pt << " Raa charm " << RaaCharm << " Raa beauty " << RaaBeauty << " eloss hypo "<< ElossHypo
634     if(ientry==0) cout<<" pt"<< pt<< " ElossCentral "<< ElossCentral[hABbin] << " min-hypo "<<MinHypo << " max-hypo "<<MaxHypo<<endl;
635
636     //
637     // Fill in histos charm (null Eloss hypothesis)
638     //
639     Double_t minFdSyst = 0., maxFdSyst = 0.;
640     if ( ElossHypo == ElossCentral[ hABbin ] ) {
641
642       //
643       // Data stat uncertainty
644       //
645       Double_t sigmappStat = hSigmaPP->GetBinError( hppbin );
646       if (isRaavsEP>0.) sigmappStat = sigmappStat*0.5;
647       Int_t hRABbin = hRABvsPt->FindBin( pt );
648       Double_t stat = RaaCharm * TMath::Sqrt( (statUncSigmaAB/sigmaAB)*(statUncSigmaAB/sigmaAB) + 
649                                               (sigmappStat/sigmapp)*(sigmappStat/sigmapp) ) ;
650       if ( RaaCharm==0 ) stat =0.;
651       if ( RaaCharm>0 ) {
652         hRABvsPt->SetBinContent( hRABbin, RaaCharm );
653         hRABvsPt->SetBinError( hRABbin, stat );
654         hYieldABvsPt->SetBinContent( hRABbin, sigmaAB/sigmaABCINT1B );
655         hYieldABvsPt->SetBinError( hRABbin, statUncSigmaAB/sigmaABCINT1B );
656         
657         cout << "pt="<< pt<< " Raa " << RaaCharm << " stat unc. "<<
658           " sigma-pp "<< sigmapp <<" sigma-AB "<< sigmaAB<<endl;
659         if(printout && TMath::Abs(ptprintout-pt)<0.1) {
660           cout << " Raa " << RaaCharm << " stat unc. "<< stat << " is "<< stat/RaaCharm * 100. <<
661             "%, stat-pp "<< sigmappStat/sigmapp*100. <<"% stat-AB "<< statUncSigmaAB/sigmaAB*100.<<"%"<<endl;
662         }
663
664         Double_t errstatEff = fhStatUncEffcSigmaAB->GetBinError( hRABbin );
665         fhStatUncEffcSigmaAB_Raa->SetBinError( hRABbin, errstatEff*RaaCharm );
666         errstatEff = fhStatUncEffbSigmaAB->GetBinError( hRABbin );
667         fhStatUncEffbSigmaAB_Raa->SetBinError( hRABbin, errstatEff*RaaCharm );
668         errstatEff = fhStatUncEffcFDAB->GetBinError( hRABbin );
669         fhStatUncEffcFDAB_Raa->SetBinError( hRABbin, errstatEff*RaaCharm );
670         errstatEff = fhStatUncEffbFDAB->GetBinError( hRABbin );
671         fhStatUncEffbFDAB_Raa->SetBinError( hRABbin, errstatEff*RaaCharm );
672       }
673
674
675       //
676       //
677       // Data systematics (sigma syst-but FD + extrap) syst
678       //
679       //
680       // Data syst: a) Syst in p-p 
681       //
682       Double_t ptwidth = hSigmaAB->GetBinWidth(hABbin) / 2. ;
683       istartPPextr = -1;
684       if(!isExtrapolatedBin) istartPPextr = FindGraphBin(gSigmaPPSystTheory,pt);
685
686       Double_t dataPPUp=0., dataPPLow=0.;
687       if(isExtrapolatedBin) {
688         dataPPUp = gSigmaPPSyst->GetErrorYhigh(istartPPsyst);
689         dataPPLow = gSigmaPPSyst->GetErrorYlow(istartPPsyst);
690         systPPUp = dataPPUp;
691         systPPLow = dataPPLow;
692       } else { 
693         dataPPUp = ExtractFDSyst( gSigmaPPSystData->GetErrorYhigh(istartPPextr), gSigmaPPSystFeedDown->GetErrorYhigh(istartPPfd) );
694         dataPPLow = ExtractFDSyst( gSigmaPPSystData->GetErrorYlow(istartPPextr), gSigmaPPSystFeedDown->GetErrorYlow(istartPPfd) );
695         systPPUp = TMath::Sqrt( dataPPUp*dataPPUp + gSigmaPPSystTheory->GetErrorYhigh(istartPPextr)*gSigmaPPSystTheory->GetErrorYhigh(istartPPextr) );
696         systPPLow = TMath::Sqrt( dataPPLow*dataPPLow + gSigmaPPSystTheory->GetErrorYlow(istartPPextr)*gSigmaPPSystTheory->GetErrorYlow(istartPPextr) );
697       }
698       if (isRaavsEP>0.) {
699         dataPPUp = dataPPUp*0.5;
700         dataPPLow = dataPPLow*0.5;
701         if(isExtrapolatedBin) {
702           systPPUp = dataPPUp;
703           systPPLow = dataPPLow;
704         } else {  
705           systPPUp = TMath::Sqrt( dataPPUp*dataPPUp + 0.5*gSigmaPPSystTheory->GetErrorYhigh(istartPPextr)*0.5*gSigmaPPSystTheory->GetErrorYhigh(istartPPextr) );
706           systPPLow = TMath::Sqrt( dataPPLow*dataPPLow + 0.5*gSigmaPPSystTheory->GetErrorYlow(istartPPextr)*0.5*gSigmaPPSystTheory->GetErrorYlow(istartPPextr) );
707         }
708       }
709
710
711       if(printout && TMath::Abs(ptprintout-pt)<0.1) {
712         cout << " pt : "<< pt<<" Syst-pp-data "<< dataPPUp/sigmapp << "%, ";
713         if(!isExtrapolatedBin){
714           if (isRaavsEP>0.) cout <<" extr unc + "<< 0.5*gSigmaPPSystTheory->GetErrorYhigh(istartPPextr)/sigmapp <<" - "<< 0.5*gSigmaPPSystTheory->GetErrorYlow(istartPPextr)/sigmapp <<" %";
715           else cout <<" extr unc + "<< gSigmaPPSystTheory->GetErrorYhigh(istartPPextr)/sigmapp <<" - "<< gSigmaPPSystTheory->GetErrorYlow(istartPPextr)/sigmapp <<" %";
716         }
717         cout << endl;
718       }
719
720       //
721       // Data syst: b) Syst in PbPb
722       //
723       Double_t dataSystUp=0., dataSystDown=0.;
724       Bool_t PbPbDataSystOk = PbPbDataSyst(systematicsAB,pt,cc,dataSystUp,dataSystDown);
725       if (!PbPbDataSystOk) { cout <<" There is some issue with the PbPb data systematics, please check and rerun"<<endl; return; }
726       systABUp = sigmaAB * TMath::Sqrt( dataSystUp*dataSystUp + 
727                                         (hDirectEffptAB->GetBinError(hABbin)/hDirectEffptAB->GetBinContent(hABbin))*(hDirectEffptAB->GetBinError(hABbin)/hDirectEffptAB->GetBinContent(hABbin)) );
728
729       systABLow = sigmaAB * TMath::Sqrt( dataSystDown*dataSystDown + 
730                                         (hDirectEffptAB->GetBinError(hABbin)/hDirectEffptAB->GetBinContent(hABbin))*(hDirectEffptAB->GetBinError(hABbin)/hDirectEffptAB->GetBinContent(hABbin)) );
731       //
732       // Data syst : c) combine pp & PbPb
733       //
734       systLow = sigmapp>0. ? 
735         RaaCharm * TMath::Sqrt( (systABLow/sigmaAB)*(systABLow/sigmaAB) + (systPPUp/sigmapp)*(systPPUp/sigmapp) )
736         : 0.;
737
738       systUp = sigmapp>0. ? 
739         RaaCharm * TMath::Sqrt( (systABUp/sigmaAB)*(systABUp/sigmaAB) + (systPPLow/sigmapp)*(systPPLow/sigmapp) )
740         : 0.;
741       if ( RaaCharm==0 ) { systPPUp =0.; systPPLow =0.; }
742       
743       //      if(printout) 
744         cout << " Syst-pp-up "<< systPPUp/sigmapp <<"%, syst-pp-low "<< systPPLow/sigmapp <<"%, syst-AB-up "<<systABUp/sigmaAB<<"%, syst-AB-low "<<systABLow/sigmaAB<<"%, tot-syst-up "<<systUp/RaaCharm<<"%, tot-syst-low "<<systLow/RaaCharm<<"%"<<endl;
745
746       if ( RaaCharm>0 ) {
747         hRABvsPt_DataSystematics->SetBinContent( hRABbin, RaaCharm );
748         hRABvsPt_DataSystematics->SetBinError( hRABbin, systUp );
749         gRAB_DataSystematics->SetPoint( hABbin, pt, RaaCharm ); // i, x, y
750         gRAB_DataSystematics->SetPointError( hABbin, ptwidth, ptwidth, systLow, systUp );
751         gRAB_DataSystematics->SetPointEXlow(hABbin, 0.4); gRAB_DataSystematics->SetPointEXhigh(hABbin,0.4);
752         gRAB_DataSystematicsPP->SetPoint( hABbin, pt, RaaCharm ); // i, x, y
753         gRAB_DataSystematicsPP->SetPointError( hABbin, ptwidth, ptwidth, RaaCharm *(systPPUp/sigmapp), RaaCharm *systPPLow/sigmapp );
754         gRAB_DataSystematicsAB->SetPoint( hABbin, pt, RaaCharm ); // i, x, y
755         gRAB_DataSystematicsAB->SetPointError( hABbin, ptwidth, ptwidth, RaaCharm *systABLow/sigmaAB, RaaCharm *systABUp/sigmaAB );
756       }
757
758       //
759       // Feed-down Systematics
760       //
761       Double_t FDL=0., FDH=0.;
762       if ( RaaCharmFDhigh > RaaCharmFDlow ){
763         FDH = RaaCharmFDhigh; FDL = RaaCharmFDlow;
764       } else {
765         FDL = RaaCharmFDhigh; FDH = RaaCharmFDlow;
766       } 
767       
768       if(printout && TMath::Abs(ptprintout-pt)<0.1) cout<<" Raa "<<RaaCharm<<", Raa-fd-low "<<RaaCharmFDlow <<", Raa-fd-high "<<RaaCharmFDhigh <<endl;
769       maxFdSyst = TMath::Abs(FDH - RaaCharm);
770       minFdSyst = TMath::Abs(RaaCharm - FDL);
771       if ( RaaCharm>0 ) {
772         gRAB_FeedDownSystematics->SetPoint( hABbin, pt, RaaCharm ); // i, x, y
773         gRAB_FeedDownSystematics->SetPointError( hABbin, 0.3, 0.3, minFdSyst, maxFdSyst ); // i, x, y
774         gRAB_fcFeedDownOnly->SetPoint( hABbin, pt,fcAB );
775         gRAB_fcFeedDownOnly->SetPointError(hABbin, 0.3, 0.3, fcAB-(sigmaABMin/sigmaAB*fcAB), (sigmaABMax/sigmaAB*fcAB)-fcAB );
776       }
777       
778       //      if(printout) { 
779         cout<<" FD syst  +"<< maxFdSyst/RaaCharm <<" - "<<minFdSyst/RaaCharm<<endl;
780         cout<<"  fc = "<<fcAB<<", ("<< sigmaABMax/sigmaAB * fcAB <<","<< sigmaABMin/sigmaAB * fcAB <<")"<<endl;
781         //      }
782
783       //
784       // Filling part of the Eloss scenarii information
785       //
786       if(RaaCharm>0 ) {
787         gRAB_ElossHypothesis->SetPoint( hABbin, pt, RaaCharm ); // i, x, y
788         gRAB_ElossHypothesis->SetPointEXlow( hABbin, ptwidth);
789         gRAB_ElossHypothesis->SetPointEXhigh( hABbin, ptwidth);
790         gRAB_FeedDownSystematicsElossHypothesis->SetPoint( hABbin, pt, RaaCharm ); // i, x, y
791         gRAB_FeedDownSystematicsElossHypothesis->SetPointEXlow( hABbin, ptwidth);
792         gRAB_FeedDownSystematicsElossHypothesis->SetPointEXhigh( hABbin, ptwidth);
793         gRAB_GlobalSystematics->SetPoint( hABbin, pt, RaaCharm ); // i, x, y
794         gRAB_GlobalSystematics->SetPointEXlow(hABbin,0.4); gRAB_GlobalSystematics->SetPointEXhigh(hABbin,0.4);
795       }
796     }
797
798     //
799     // Filling Eloss scenarii information
800     //
801     //    trick in case not fine enough Rb hypothesis to cope with the min/max range
802     //    if( RaaCharm>0 && ( (ElossHypo >= MinHypo && ElossHypo <=MaxHypo) || ElossHypo == ElossCentral[ hABbin ] ) && RaaBeauty<=MaxRb ) {
803     //      by default better not use it, to monitor when this happens (could affect results)
804     if( RaaCharm>0 && ElossHypo >= MinHypo && ElossHypo <=MaxHypo && RaaBeauty<=MaxRb ) {
805
806       Double_t Ehigh =  ElossMax[ hABbin ] ;
807       Double_t Elow =  ElossMin[ hABbin ] ;
808       if ( RaaCharm > Ehigh ) ElossMax[ hABbin ] = RaaCharm ;
809       if ( RaaCharm < Elow ) ElossMin[ hABbin ] = RaaCharm ;
810       if(printout && TMath::Abs(ptprintout-pt)<0.1) {
811         cout<<" Hypothesis " << ElossHypo << " sigma-AB "<< sigmaAB <<", Raa "<< RaaCharm <<", Raa Eloss max "<< ElossMax[hABbin] <<" Raa Eloss min "<< ElossMin[hABbin] << " Rb="<< RaaBeauty <<endl;
812         cout<<"  Rb="<< RaaBeauty <<" max "<< RaaBeautyFDhigh <<" min "<< RaaBeautyFDlow <<endl;
813       }
814       Double_t fcEhigh =  fcElossMax[ hABbin ] ;
815       Double_t fcElow =  fcElossMin[ hABbin ] ;
816       if ( fcAB > fcEhigh ) fcElossMax[ hABbin ] = fcAB ;
817       if ( fcAB < fcElow ) fcElossMin[ hABbin ] = fcAB ;
818       Double_t FDEhigh = FDElossMax[ hABbin ];
819       Double_t FDEmin = FDElossMin[ hABbin ];
820       Double_t RFDhigh = RaaCharmFDhigh>RaaCharmFDlow ? RaaCharmFDhigh : RaaCharmFDlow;
821       Double_t RFDlow = RaaCharmFDlow<RaaCharmFDhigh ? RaaCharmFDlow : RaaCharmFDhigh;
822       if ( RFDhigh > FDEhigh ) FDElossMax[ hABbin ] = RFDhigh ;
823       if ( RFDlow < FDEmin ) FDElossMin[ hABbin ] = RFDlow ;
824       if(printout && TMath::Abs(ptprintout-pt)<0.1) 
825         cout<<" Hypothesis " << ElossHypo << " sigma-AB "<< sigmaAB <<", Raa FD-max Eloss max "<< FDElossMax[hABbin] <<" Raa FD-min Eloss min "<< FDElossMin[hABbin] <<endl;
826     }
827
828
829   }
830   delete [] limits;
831   delete [] binwidths;
832
833
834   // Finish filling the y-uncertainties of the Eloss scenarii 
835   for (Int_t ibin=0; ibin<=nbins; ibin++){
836     Double_t ipt=0., value =0.;
837     gRAB_ElossHypothesis->GetPoint(ibin,ipt,value);
838     if(ipt<=0) continue;
839     //
840     // Uncertainty on Raa due to the Eloss hypothesis
841     Double_t elossYhigh = TMath::Abs( ElossMax[ibin] - value );
842     Double_t elossYlow = TMath::Abs( value - ElossMin[ibin] );
843     gRAB_ElossHypothesis->SetPointEYhigh(ibin, elossYhigh );
844     gRAB_ElossHypothesis->SetPointEYlow(ibin, elossYlow );
845     gRAB_ElossHypothesis->SetPointEXhigh(ibin, 0.2);
846     gRAB_ElossHypothesis->SetPointEXlow(ibin, 0.2);
847     cout << " pt "<< ipt << " Raa "<< value <<" max "<< ElossMax[ibin] << " min " <<ElossMin[ibin] <<endl;
848     cout<<" Eloss syst  +"<< elossYhigh <<" - "<< elossYlow <<endl; 
849     //    cout << " fc max "<< fcElossMax[ibin] << " fc min " <<fcElossMin[ibin] <<endl;   
850     //
851     // Uncertainty on Raa due to the FD unc & Eloss hypothesis
852     Double_t fdElossEYhigh = TMath::Abs( FDElossMax[ibin] - value );
853     Double_t fdElossEYlow = TMath::Abs( value - FDElossMin[ibin] );
854     if(elossFDQuadSum){
855       Double_t fdEYhigh = gRAB_FeedDownSystematics->GetErrorYhigh(ibin);
856       fdElossEYhigh = TMath::Sqrt( elossYhigh*elossYhigh + fdEYhigh*fdEYhigh );
857       Double_t fdEYlow = gRAB_FeedDownSystematics->GetErrorYlow(ibin);
858       fdElossEYlow = TMath::Sqrt( elossYlow*elossYlow + fdEYlow*fdEYlow );
859     }
860     gRAB_FeedDownSystematicsElossHypothesis->SetPointEYhigh(ibin, fdElossEYhigh );
861     gRAB_FeedDownSystematicsElossHypothesis->SetPointEYlow(ibin, fdElossEYlow );
862     gRAB_FeedDownSystematicsElossHypothesis->SetPointEXhigh(ibin, 0.25);
863     gRAB_FeedDownSystematicsElossHypothesis->SetPointEXlow(ibin, 0.25);
864     cout<<" FD & Eloss syst  +"<< fdElossEYhigh <<" - "<< fdElossEYlow 
865         <<" = + "<< fdElossEYhigh/value <<" - "<< fdElossEYlow/value <<" %" <<endl; 
866     //
867     // All uncertainty on Raa (FD unc & Eloss + data)
868     Double_t systdatal = gRAB_DataSystematics->GetErrorYlow(ibin);
869     Double_t systdatah = gRAB_DataSystematics->GetErrorYhigh(ibin);
870     Double_t systgbhUnc = TMath::Sqrt( systdatah*systdatah + fdElossEYhigh*fdElossEYhigh );
871     Double_t systgblUnc = TMath::Sqrt( systdatal*systdatal + fdElossEYlow*fdElossEYlow );
872     gRAB_GlobalSystematics->SetPointEYhigh(ibin,systgbhUnc);
873     gRAB_GlobalSystematics->SetPointEYlow(ibin,systgblUnc);
874     cout<<" Data syst  +"<< systdatah <<" - "<<  systdatal <<" = + "<< systdatah/value <<" - " <<  systdatal/value << " % "<<endl; 
875     cout<<" Global syst  +"<< systgbhUnc <<" - "<<  systgblUnc << " = + "<< systgbhUnc/value <<" - "<<  systgblUnc/value << " %" <<endl; 
876     //
877   }
878
879
880   gROOT->SetStyle("Plain");
881   gStyle->SetPalette(1);
882   gStyle->SetOptStat(0);
883
884
885   TCanvas *cRABvsRb = new TCanvas("RABvsRb","RAB vs Rb");
886   hRABvsRb->Draw("colz");
887   cRABvsRb->Update();
888
889   TCanvas *cRABvsRbvsPt = new TCanvas("cRABvsRbvsPt","RAB vs Rb vs pt");
890   hRABCharmVsRBeautyVsPt->Draw("lego3z");
891   cRABvsRbvsPt->Update();
892
893
894   TCanvas *cRABvsRbFDl = new TCanvas("RABvsRbFDl","RAB vs Rb (FD low)");
895   hRABvsRbFDlow->Draw("cont4z");
896   cRABvsRbFDl->Update();
897   TCanvas *cRABvsRbFDh = new TCanvas("RABvsRbFDh","RAB vs Rb (FD high)");
898   hRABvsRbFDhigh->Draw("cont4z");
899   cRABvsRbFDh->Update();
900
901   TCanvas * cSigmaABptEloss = new TCanvas("cSigmaABptEloss","SigmaAB vs pt, Eloss hypothesis");
902   TH1D *hSigmaABEloss00= new TH1D("hSigmaABEloss00","hSigmaABEloss00",nbins,limits);
903   TH1D *hSigmaABEloss05= new TH1D("hSigmaABEloss05","hSigmaABEloss05",nbins,limits);
904   TH1D *hSigmaABEloss10= new TH1D("hSigmaABEloss10","hSigmaABEloss10",nbins,limits);
905   TH1D *hSigmaABEloss15= new TH1D("hSigmaABEloss15","hSigmaABEloss15",nbins,limits);
906   TH1D *hSigmaABEloss20= new TH1D("hSigmaABEloss20","hSigmaABEloss20",nbins,limits);
907   for (Int_t i=0; i<=nSigmaAB->GetEntriesFast(); i++) {
908     nSigmaAB->GetEntry(i);
909     if (fdMethod==kfc) {
910       if( TMath::Abs(Rcb-0.015)<0.009 ) hSigmaABEloss00->Fill(pt,sigmaAB);
911       if( TMath::Abs(Rcb-0.5)<0.009 ) hSigmaABEloss05->Fill(pt,sigmaAB);
912       if( TMath::Abs(Rcb-1.0)<0.009 ) hSigmaABEloss10->Fill(pt,sigmaAB);
913       if( TMath::Abs(Rcb-1.5)<0.009 ) hSigmaABEloss15->Fill(pt,sigmaAB);
914       if( TMath::Abs(Rcb-2.0)<0.009 ) hSigmaABEloss20->Fill(pt,sigmaAB);
915     }
916     else if (fdMethod==kNb) {
917       if( TMath::Abs(Rb-0.015)<0.009 ) hSigmaABEloss00->Fill(pt,sigmaAB);
918       if( TMath::Abs(Rb-0.5)<0.009 ) hSigmaABEloss05->Fill(pt,sigmaAB);
919       if( TMath::Abs(Rb-1.0)<0.009 ) hSigmaABEloss10->Fill(pt,sigmaAB);
920       if( TMath::Abs(Rb-1.5)<0.009 ) hSigmaABEloss15->Fill(pt,sigmaAB);
921       if( TMath::Abs(Rb-2.0)<0.009 ) hSigmaABEloss20->Fill(pt,sigmaAB);
922     }
923   }
924   hSigmaABEloss00->SetLineColor(2);
925   hSigmaABEloss05->SetLineColor(3);
926   hSigmaABEloss10->SetLineColor(4);
927   hSigmaABEloss15->SetLineColor(kMagenta+1);
928   hSigmaABEloss20->SetLineColor(kGreen+2);
929   hSigmaABEloss00->SetMarkerStyle(22);
930   hSigmaABEloss05->SetMarkerStyle(26);
931   hSigmaABEloss10->SetMarkerStyle(20);
932   hSigmaABEloss15->SetMarkerStyle(25);
933   hSigmaABEloss20->SetMarkerStyle(21);
934   if (fdMethod==kNb) {
935     hSigmaABEloss05->Draw("ph");
936     hSigmaABEloss10->Draw("phsame");
937     hSigmaABEloss15->Draw("phsame");
938     hSigmaABEloss20->Draw("phsame");
939   }
940   else {
941     hSigmaABEloss20->Draw("p");
942     hSigmaABEloss00->Draw("phsame");
943     hSigmaABEloss05->Draw("phsame");
944     hSigmaABEloss10->Draw("phsame");
945     hSigmaABEloss15->Draw("phsame");
946     hSigmaABEloss20->Draw("phsame");
947   }
948   TLegend *legrcb = new TLegend(0.8,0.8,0.95,0.9);
949   legrcb->SetFillColor(0);
950   legrcb->AddEntry(hSigmaABEloss00,"Rc/b=0.0","lp");
951   legrcb->AddEntry(hSigmaABEloss05,"Rc/b=0.5","lp");
952   legrcb->AddEntry(hSigmaABEloss10,"Rc/b=1.0","lp");
953   legrcb->AddEntry(hSigmaABEloss15,"Rc/b=1.5","lp");
954   legrcb->AddEntry(hSigmaABEloss20,"Rc/b=2.0","lp");
955   legrcb->Draw();
956   cSigmaABptEloss->Update();
957
958
959   TCanvas * cRABptEloss = new TCanvas("cRABptEloss","RAB vs pt, Eloss hypothesis");
960   hRABEloss00->SetLineColor(2);
961   hRABEloss05->SetLineColor(3);
962   hRABEloss10->SetLineColor(4);
963   hRABEloss15->SetLineColor(kMagenta+1);
964   hRABEloss20->SetLineColor(kGreen+2);
965   hRABEloss00->SetMarkerStyle(22);
966   hRABEloss05->SetMarkerStyle(26);
967   hRABEloss10->SetMarkerStyle(20);
968   hRABEloss15->SetMarkerStyle(25);
969   hRABEloss20->SetMarkerStyle(21);
970   if (fdMethod==kNb) {
971     hRABEloss05->Draw("ph");
972     hRABEloss10->Draw("phsame");
973     hRABEloss15->Draw("phsame");
974     hRABEloss20->Draw("phsame");
975   }
976   else {
977     hRABEloss20->Draw("p");
978     hRABEloss00->Draw("phsame");
979     hRABEloss05->Draw("phsame");
980     hRABEloss10->Draw("phsame");
981     hRABEloss15->Draw("phsame");
982     hRABEloss20->Draw("phsame");
983   }
984   legrcb = new TLegend(0.8,0.8,0.95,0.9);
985   legrcb->SetFillColor(0);
986   if (fdMethod==kfc) {
987     legrcb->AddEntry(hRABEloss00,"Rc/b=0.0","lp");
988     legrcb->AddEntry(hRABEloss05,"Rc/b=0.5","lp");
989     legrcb->AddEntry(hRABEloss10,"Rc/b=1.0","lp");
990     legrcb->AddEntry(hRABEloss15,"Rc/b=0.5","lp");
991     legrcb->AddEntry(hRABEloss20,"Rc/b=2.0","lp");
992   }
993   else if (fdMethod==kNb) {
994     legrcb->AddEntry(hRABEloss00,"Rb=0.0","lp");
995     legrcb->AddEntry(hRABEloss05,"Rb=0.5","lp");
996     legrcb->AddEntry(hRABEloss10,"Rb=1.0","lp");
997     legrcb->AddEntry(hRABEloss15,"Rb=0.5","lp");
998     legrcb->AddEntry(hRABEloss20,"Rb=2.0","lp");
999   }     
1000   legrcb->Draw();
1001   cRABptEloss->Update();
1002
1003
1004   TCanvas * cRABpt = new TCanvas("cRABpt","RAB vs pt, no hypothesis");
1005   hRABEloss10->Draw("");
1006   cRABpt->Update();
1007
1008   TCanvas * cRABptFDUnc = new TCanvas("cRABptFDUnc","RAB vs pt, FD Uncertainties");
1009   hRABvsRbFDlow_proj->Draw("");
1010   hRABEloss10->Draw("phsame");
1011   hRABvsRbFDhigh_proj->SetLineColor(kMagenta+1);
1012   hRABvsRbFDhigh_proj->Draw("same");
1013   hRABvsRbFDlow_proj->SetLineColor(kGreen+2);
1014   hRABvsRbFDlow_proj->Draw("same");
1015   legrcb = new TLegend(0.8,0.8,0.95,0.9);
1016   legrcb->SetFillColor(0);
1017   legrcb->AddEntry(hRABEloss10,"FD Central","lp");
1018   legrcb->AddEntry(hRABvsRbFDhigh_proj,"FD Upper unc.","l");
1019   legrcb->AddEntry(hRABvsRbFDlow_proj,"FD Lower unc.","l");
1020   legrcb->Draw();
1021   cRABptFDUnc->Update();
1022
1023   TCanvas *RaaPlot = new TCanvas("RaaPlot","RAB vs pt, plot all");
1024   RaaPlot->SetTopMargin(0.085);
1025   RaaPlot->SetBottomMargin(0.1);
1026   RaaPlot->SetTickx();
1027   RaaPlot->SetTicky();
1028   TH2D *hRaaCanvas = new TH2D("hRaaCanvas"," R_{AB}(c) vs p_{T} (no Eloss hypothesis); p_{t} [GeV/c] ; R_{AA} prompt D",40,0.,40.,100,0.,3.0);
1029   hRaaCanvas->GetXaxis()->SetTitleSize(0.05);
1030   hRaaCanvas->GetXaxis()->SetTitleOffset(0.9);
1031   hRaaCanvas->GetYaxis()->SetTitleSize(0.05);
1032   hRaaCanvas->GetYaxis()->SetTitleOffset(0.9);
1033   hRaaCanvas->Draw();
1034   gRAB_Norm->SetFillStyle(1001);
1035   gRAB_Norm->SetFillColor(kGray+2);
1036   gRAB_Norm->Draw("2");
1037   TLine *line = new TLine(0.0172415,1.0,40.,1.0);
1038   line->SetLineStyle(2);
1039   line->Draw();
1040   hRABvsPt->SetMarkerColor(kBlue);
1041   hRABvsPt->SetMarkerColor(kBlue);
1042   hRABvsPt->SetMarkerStyle(21);
1043   hRABvsPt->SetMarkerSize(1.1);
1044   hRABvsPt->SetLineWidth(2);
1045   hRABvsPt->Draw("psame");
1046   gRAB_DataSystematics->SetLineColor(kBlue);
1047   gRAB_DataSystematics->SetLineWidth(3);
1048   gRAB_DataSystematics->SetLineWidth(2);
1049   gRAB_DataSystematics->SetFillColor(kRed);
1050   gRAB_DataSystematics->SetFillStyle(0);
1051   gRAB_DataSystematics->Draw("2");
1052   gRAB_FeedDownSystematics->SetFillColor(kViolet+1);
1053   gRAB_FeedDownSystematics->SetFillStyle(1001);
1054   gRAB_FeedDownSystematics->Draw("2");
1055   gRAB_ElossHypothesis->SetLineColor(kMagenta-7);
1056   gRAB_ElossHypothesis->SetFillColor(kMagenta-7);
1057   gRAB_ElossHypothesis->SetFillStyle(1001);
1058   gRAB_ElossHypothesis->Draw("2");
1059   hRABvsPt->Draw("psame");
1060   gRAB_DataSystematics->Draw("2");
1061   legrcb = new TLegend(0.5517241,0.6504237,0.8520115,0.8728814,NULL,"brNDC");
1062   legrcb->SetBorderSize(0);
1063   legrcb->SetTextSize(0.03389831);
1064   legrcb->SetLineColor(1);
1065   legrcb->SetLineStyle(1);
1066   legrcb->SetLineWidth(1);
1067   legrcb->SetFillColor(0);
1068   legrcb->SetFillStyle(1001);
1069   if(cc==k020) legrcb->AddEntry(hRABvsPt,"R_{AA} 0-20% CC","pe");
1070   else if(cc==k4080) legrcb->AddEntry(hRABvsPt,"R_{AA} 40-80% CC","pe");
1071   else legrcb->AddEntry(hRABvsPt,"R_{AA} and stat. unc.","pe");
1072   legrcb->AddEntry(gRAB_DataSystematics,"Syst. from data","f");
1073   legrcb->AddEntry(gRAB_ElossHypothesis,"Syst. from R_{AA}(B)","f");
1074   legrcb->AddEntry(gRAB_FeedDownSystematics,"Syst. from B feed-down","f");
1075   legrcb->Draw();
1076   TLatex* tc;
1077   TString system = "Pb-Pb   #sqrt{s_{NN}}=2.76 TeV";
1078   if( cc==kpPb0100 || cc==kpPb020 || cc==kpPb2040 || cc==kpPb4060 || cc==kpPb60100 ) system = "p-Pb   #sqrt{s_{NN}}=5.023 TeV";
1079   if(decay==1) tc =new TLatex(0.18,0.82,Form("D^{0},  %s ",system.Data()));
1080   else if(decay==2) tc =new TLatex(0.18,0.82,Form("D^{+},  %s ",system.Data()));
1081   else if(decay==3) tc =new TLatex(0.18,0.82,Form("D^{*+},  %s ",system.Data()));
1082   else if(decay==4) tc =new TLatex(0.18,0.82,Form("D_{s}^{+},  %s ",system.Data()));
1083   else  tc =new TLatex(0.18,0.82,Form("any (?) D meson,  %s ",system.Data()));
1084   tc->SetNDC();
1085   tc->SetTextSize(0.038);
1086   tc->SetTextFont(42);
1087   tc->Draw();
1088   RaaPlot->Update();
1089
1090
1091   TCanvas *RaaPlotFDEloss = new TCanvas("RaaPlotFDEloss","RAB vs pt, plot FD & ElossUnc");
1092   RaaPlotFDEloss->SetTopMargin(0.085);
1093   RaaPlotFDEloss->SetBottomMargin(0.1);
1094   hRaaCanvas->Draw();
1095   line->Draw();
1096   hRABvsPt->Draw("psame");
1097   gRAB_FeedDownSystematics->SetFillColor(kViolet+1);
1098   gRAB_FeedDownSystematics->SetFillStyle(1001);
1099   gRAB_FeedDownSystematics->Draw("2");
1100   gRAB_ElossHypothesis->SetLineColor(kMagenta-7);
1101   gRAB_ElossHypothesis->SetFillColor(kMagenta-7);
1102   gRAB_ElossHypothesis->SetFillStyle(1001);
1103   gRAB_ElossHypothesis->Draw("2");
1104   gRAB_FeedDownSystematicsElossHypothesis->SetLineColor(kBlack);
1105   gRAB_FeedDownSystematicsElossHypothesis->SetFillStyle(0);
1106   gRAB_FeedDownSystematicsElossHypothesis->SetFillColor(kViolet+1);
1107   gRAB_FeedDownSystematicsElossHypothesis->Draw("2");
1108   hRABvsPt->Draw("psame");
1109   legrcb = new TLegend(0.6,0.6,0.9,0.9);
1110   legrcb->SetBorderSize(0);
1111   legrcb->SetTextSize(0.03389831);
1112   legrcb->SetLineColor(1);
1113   legrcb->SetLineStyle(1);
1114   legrcb->SetLineWidth(1);
1115   legrcb->SetFillColor(0);
1116   legrcb->SetFillStyle(1001);
1117   legrcb->AddEntry(hRABvsPt,"R_{PbPb} and stat. unc.","pe");
1118   legrcb->AddEntry(gRAB_ElossHypothesis,"Energy loss syst.","f");
1119   legrcb->AddEntry(gRAB_FeedDownSystematics,"Feed down syst.","f");
1120   legrcb->AddEntry(gRAB_FeedDownSystematicsElossHypothesis,"Feed down & Eloss syst.","f");
1121   legrcb->Draw();
1122   RaaPlotFDEloss->Update();
1123   
1124
1125   TCanvas *RaaPlotGlob = new TCanvas("RaaPlotGlob","RAB vs pt, plot Global unc");
1126   RaaPlotGlob->SetTopMargin(0.085);
1127   RaaPlotGlob->SetBottomMargin(0.1);
1128   RaaPlotGlob->SetTickx();
1129   RaaPlotGlob->SetTicky();
1130   hRaaCanvas->Draw();
1131   line->Draw();
1132   hRABvsPt->Draw("psame");
1133   gRAB_DataSystematics->Draw("2");
1134   gRAB_FeedDownSystematicsElossHypothesis->Draw("2");
1135   gRAB_GlobalSystematics->SetLineColor(kRed);
1136   gRAB_GlobalSystematics->SetLineWidth(2);
1137   gRAB_GlobalSystematics->SetFillColor(kRed);
1138   gRAB_GlobalSystematics->SetFillStyle(3002);
1139   gRAB_GlobalSystematics->Draw("2");
1140   hRABvsPt->Draw("psame");
1141   legrcb = new TLegend(0.6,0.6,0.9,0.9);
1142   legrcb->SetBorderSize(0);
1143   legrcb->SetTextSize(0.03389831);
1144   legrcb->SetLineColor(1);
1145   legrcb->SetLineStyle(1);
1146   legrcb->SetLineWidth(1);
1147   legrcb->SetFillColor(0);
1148   legrcb->SetFillStyle(1001);
1149   legrcb->AddEntry(hRABvsPt,"R_{PbPb} and stat. unc.","pe");
1150   legrcb->AddEntry(gRAB_DataSystematics,"Data syst.","f");
1151   legrcb->AddEntry(gRAB_FeedDownSystematicsElossHypothesis,"Feed down & Eloss syst.","f");
1152   legrcb->AddEntry(gRAB_GlobalSystematics,"Global syst.","f");
1153   legrcb->Draw();
1154   RaaPlotGlob->Update();
1155
1156
1157   
1158   TCanvas *RaaPlotSimple = new TCanvas("RaaPlotSimple","RAB vs pt, plot Simple unc");
1159   RaaPlotSimple->SetTopMargin(0.085);
1160   RaaPlotSimple->SetBottomMargin(0.1);
1161   RaaPlotSimple->SetTickx();
1162   RaaPlotSimple->SetTicky();
1163   hRaaCanvas->Draw();
1164   line->Draw();
1165   hRABvsPt->Draw("psame");
1166   gRAB_GlobalSystematics->SetLineColor(kBlue);
1167   gRAB_GlobalSystematics->SetLineWidth(2);
1168   gRAB_GlobalSystematics->SetFillStyle(0);
1169   gRAB_GlobalSystematics->Draw("2");
1170   gRAB_Norm->Draw("2");
1171   hRABvsPt->Draw("psame");
1172   legrcb = new TLegend(0.5991379,0.6949153,0.8534483,0.8559322,NULL,"brNDC");
1173   legrcb->SetBorderSize(0);
1174   legrcb->SetTextSize(0.03389831);
1175   legrcb->SetLineColor(1);
1176   legrcb->SetLineStyle(1);
1177   legrcb->SetLineWidth(1);
1178   legrcb->SetFillColor(0);
1179   legrcb->SetFillStyle(1001); 
1180   if(cc==k020) legrcb->AddEntry(hRABvsPt,"R_{AA} 0-20% CC","pe");
1181   else if(cc==k4080) legrcb->AddEntry(hRABvsPt,"R_{AA} 40-80% CC","pe");
1182   else legrcb->AddEntry(hRABvsPt,"R_{AA} and stat. unc.","pe");
1183   legrcb->AddEntry(gRAB_GlobalSystematics,"Systematics","f");
1184   legrcb->Draw();
1185   tc->Draw();
1186   RaaPlotSimple->Update();
1187
1188
1189   TCanvas *c = new TCanvas("c","");
1190   systematicsAB->DrawErrors();
1191   c->Update();
1192
1193   TCanvas *cStatUnc = new TCanvas("cStatUnc","stat unc");
1194   cStatUnc->Divide(2,2);
1195   cStatUnc->cd(1);
1196   fhStatUncEffcSigmaAB_Raa->Draw("e");
1197   cStatUnc->cd(2);
1198   fhStatUncEffbSigmaAB_Raa->Draw("e");
1199   cStatUnc->cd(3);
1200   fhStatUncEffcFDAB_Raa->Draw("e");
1201   cStatUnc->cd(4);
1202   fhStatUncEffbFDAB_Raa->Draw("e");
1203   cStatUnc->Update();
1204
1205   //
1206   // Write the information to a file
1207   //
1208   TFile * out = new TFile(outfile,"recreate");
1209
1210   ntupleRAB->Write();
1211   hRABvsRcb->Write();
1212   hRABvsRb->Write();
1213   hRABCharmVsRBeautyVsPt->Write();
1214   for(Int_t j=0; j<=nbins; j++) hRCharmVsRBeauty[j]->Write();
1215   //  for(Int_t j=0; j<=nbins; j++) hRCharmVsElossHypo[j]->Write();
1216   hRABvsPt->Write();
1217   hRABvsPt_DataSystematics->Write();
1218   gRAB_ElossHypothesis->Write();
1219   gRAB_FeedDownSystematics->Write();
1220   gRAB_fcFeedDownOnly->Write();
1221   gRAB_DataSystematics->Write();
1222   gRAB_DataSystematicsPP->Write();
1223   gSigmaPPSystTheory->Write();
1224   gRAB_DataSystematicsAB->Write();
1225   gRAB_Norm->Write();
1226   gRAB_FeedDownSystematicsElossHypothesis->Write();
1227   gRAB_GlobalSystematics->Write();
1228   if(isScaledAndExtrapRef) hCombinedReferenceFlag->Write();
1229
1230   out->Write();
1231
1232 }
1233
1234 //____________________________________________________________
1235 Bool_t PbPbDataSyst(AliHFSystErr *syst, Double_t pt, Int_t cc, Double_t &dataSystUp, Double_t &dataSystDown)
1236 {
1237
1238   Double_t err=0., errUp=1., errDown=1.;
1239   Bool_t isOk=false;
1240   Double_t pidunc=0.;
1241
1242   err = syst->GetTotalSystErr(pt)*syst->GetTotalSystErr(pt);
1243   errUp = err ;
1244   errDown = err ;
1245
1246   // Apply an asymetric PID uncertainty for 2010 PbPb data only
1247   if( syst->GetRunNumber()==10 && syst->GetCollisionType()==1 ) {
1248     if( cc==k07half || cc==k020 || cc==k010 || cc==k1020 || cc==k2040 ) {
1249       if(pt<6) pidunc = 0.15;
1250       else pidunc = 0.05;
1251       errUp = err + pidunc*pidunc - syst->GetPIDEffErr(pt)*syst->GetPIDEffErr(pt);
1252       isOk = true;
1253     }
1254     else if ( cc==k3050 || cc==k4080 || cc==k4060 || cc==k6080 ){
1255       if(pt<3.1) pidunc = 0.10;
1256       else pidunc = 0.05;
1257       errUp = err + pidunc*pidunc - syst->GetPIDEffErr(pt)*syst->GetPIDEffErr(pt);
1258       isOk = true;
1259     }
1260   }
1261   else { isOk = true; }
1262
1263   dataSystUp = TMath::Sqrt(errUp);
1264   dataSystDown = TMath::Sqrt(errDown);
1265
1266   return isOk;
1267 }