1 #if !defined (__CINT__) || (defined(__MAKECINT__))
7 #include "TObjString.h"
8 #include "AliParticleYield.h"
9 #include "TGraphErrors.h"
12 #include "TVirtualFitter.h"
14 #include "TFitResult.h"
17 #include "TDatabasePDG.h"
26 std::map<TString,Float_t> npartPbPb;
27 std::map<TString,Float_t> npartPbPbErr;
29 void ReadCentralityFromFile() ;
30 Double_t FitShiftedGraphAndExtrapolate(TGraphErrors * gr, Int_t shift, TF1 * f1, const char * centr, Color_t color, Bool_t draw = kFALSE) ;
31 Double_t ErrorFunction (Double_t *xx, Double_t *p ) ;
32 Double_t FuncPlusErr (Double_t *xx, Double_t *p) ;
34 enum {kNoShift, kShiftUp, kShiftDown, kShiftHarder, kShiftSofter};
39 Double_t matrix[npar][npar];
41 TString systemAndEnergy;
43 TString label = "#frac{d#it{N}}{d#it{y}} = #it{a} + #it{b} #times (#it{N}_{part})^{#it{c}}";
44 //TString label = "#frac{d#it{N}}{d#it{y}} = #it{a} + #it{b} #times (d#it{N}/d#it{#eta})^{#it{c}}";
46 Float_t energy = 2760;
48 void FitNPartDependence() {
50 // This macro can be used to fit the centrality dependence of
51 // different particles in order to extrapolate or interpolate the
52 // yield as a function of centrality.
53 // The value of npart or dndeta is read from a text file, which must
54 // be in the format "centrTag value error"
56 // The particle yields are taken from the machine readable files.
57 // If you want to fit a different particle, you have to uncomment
58 // the corresponding section below. if you want to try a different
59 // function, scroll down to the definition of f1
61 // For the estimate of the systematic uncertainties, the syst graph
62 // is shifted up and down within its uncertainties. Few strategies
63 // are possible (see the call to FitShiftedGraphAndExtrapolate below
64 // to change the behavior):
65 // 1. All points are coherently shifted up and down by 1 syst bar
66 // (kShiftUp, kShiftDown)
67 // 2. A worst case scenario is implemented, where the first point is
68 // shifted by +- 1 sigma, the last one by -+ 1 sigma and all the
69 // other points are shifted smoothly in between (kShiftHarder,
72 //__________________________________________________________________//
75 centrFile = "npart_PbPb.txt";
76 // centrFile = "dndeta_PbPb.txt";
78 systemAndEnergy = "Pb-Pb #sqrt{#it{s}}_{NN} = 2.76 TeV";
79 const char * centralityToPlot[] = { "V0M0020" , "V0M2040" , "V0M4060" , "V0M6080" , 0};
80 const char * centrToExtrapolate = "V0M0010";
82 TClonesArray * arr = AliParticleYield::ReadFromASCIIFile("./PbPb_2760_Kstar892.txt");
84 // gROOT->ProcessLine(".x figTemplate.C(0,0.00001,400,0.2)");
85 // const char * centralityToPlot[] = { "V0M0010" , "V0M1020" , "V0M2040" , "V0M4060" , "V0M6080",0 };
86 // const char * centrToExtrapolate = "V0M0010";
87 // Int_t pdg = 1000010020;
88 // TClonesArray * arr = AliParticleYield::ReadFromASCIIFile("PbPb_2760_DeuHelium3.txt");
90 // centrFile = "dndeta_pPb.txt";
91 // const char * centralityToPlot[] = { "V0A0010", "V0A1020", "V0A2040", "V0A4060", "V0A6000" ,0};
92 // // const char * centrToExtrapolate = "V0A0005";
93 // const char * centrToExtrapolate = "V0A6080";
94 // Int_t pdg = 1000010020;
95 // TClonesArray * arr = AliParticleYield::ReadFromASCIIFile("pPb_5020_deuteron.txt");
97 // systemAndEnergy = "p-Pb #sqrt{#it{s}}_{NN} = 5.02 TeV";
101 // gROOT->ProcessLine(".x figTemplate.C(0,0.00001,400,0.2)");
102 // const char * centralityToPlot[] = { "V0M0020" , "V0M2080" ,0};
103 // const char * centrToExtrapolate = "V0M0010";
104 // Int_t pdg = 1000020030;
105 // TClonesArray * arr = AliParticleYield::ReadFromASCIIFile("PbPb_2760_DeuHelium3.txt");
110 // gPad->GetCanvas()->SetTitle(Form("c%s", TDatabasePDG::Instance()->GetParticle(pdg)->GetName()));
112 ReadCentralityFromFile();
113 TGraphErrors * grSyst = new TGraphErrors;
114 TGraphErrors * grStat = new TGraphErrors;
115 Double_t maxx = 1.1*npartPbPb[centrToExtrapolate];
116 //Double_t maxx = 1.1*npartPbPb["V0A0005"];
118 // TF1 * f1 = new TF1 ("f1", "[0] + [1]*x", 0, maxx);
119 // f1->SetParameters(1,1);
120 TF1 * f1 = new TF1 ("f1", "[0] + [1]*x^[2]", 0, maxx);
121 f1->SetParameters(0, 6.3266e-04, 8.99883e-01);
124 gROOT->ProcessLine(Form(".x figTemplate.C(0,0.1,%f,%f)", maxx, maxy));
125 gPad->GetCanvas()->SetTitle("cKstar");
127 // f1->FixParameter(0, 0);
129 AliParticleYield * part = 0;
130 while (centralityToPlot[icentr]) {
131 part = AliParticleYield::FindParticle(arr, pdg, collSystem, energy, centralityToPlot[icentr]);
133 grSyst->SetPoint (icentr , npartPbPb[centralityToPlot[icentr]] , part->GetYield());
134 grSyst->SetPointError(icentr , npartPbPbErr[centralityToPlot[icentr]] , part->GetSystError());
135 grStat->SetPoint (icentr , npartPbPb[centralityToPlot[icentr]] , part->GetYield());
136 grStat->SetPointError(icentr , npartPbPbErr[centralityToPlot[icentr]] , part->GetStatError());
143 grStat->SetMarkerStyle(24);
145 grSyst->SetFillStyle(0);
146 Double_t yield = FitShiftedGraphAndExtrapolate(grStat, kNoShift , f1, centrToExtrapolate, kRed );
148 // We need to cache the covariance matrix and the function here, otherwise things get messed up
149 fForErrors = (TF1*) f1->Clone();
150 fForErrors->SetLineColor(kRed);
151 fForErrors->SetLineStyle(0);
152 fForErrors->Draw("same");
153 gMinuit->mnemat(&matrix[0][0],npar);
154 // The statistical error is computed propagating the uncertainty on the parameters to the function via the covariance matrix
155 TF1 * fShiftedPlus = new TF1("fShiftedPlus" , FuncPlusErr, 0, maxx,1); fShiftedPlus->SetParameter(0,+1);
156 TF1 * fShiftedMinus = new TF1("fShiftedMinus" , FuncPlusErr, 0, maxx,1); fShiftedMinus->SetParameter(0,-1);
157 fShiftedMinus->SetLineStyle(kDotted);
158 fShiftedPlus->SetLineStyle (kDotted);
159 fShiftedPlus ->Draw("same");
160 fShiftedMinus->Draw("same");
161 TF1 * fError = new TF1("fError", ErrorFunction, 0,maxx, 0);
163 // The uncertainty on the systematics is computed shifting the graph up and down + refitting
164 // Double_t errorSystPlus = FitShiftedGraphAndExtrapolate(grSyst, kShiftUp , f1, centrToExtrapolate, kRed)-yield;
165 // Double_t errorSystMinus = FitShiftedGraphAndExtrapolate(grSyst, kShiftDown, f1, centrToExtrapolate, kRed)-yield;
166 Double_t errorSystPlus = TMath::Abs(FitShiftedGraphAndExtrapolate(grSyst, kShiftHarder, f1, centrToExtrapolate, kRed)-yield);
167 Double_t errorSystMinus = TMath::Abs(FitShiftedGraphAndExtrapolate(grSyst, kShiftSofter, f1, centrToExtrapolate, kRed)-yield);
169 // Double_t errorStatPlus = FitShiftedGraphAndExtrapolate(grStat, kShiftUp , f1, centrToExtrapolate, kBlue) -yield;
170 // Double_t errorStatMinus = FitShiftedGraphAndExtrapolate(grStat, kShiftDown, f1, centrToExtrapolate, kBlue) -yield;
172 Double_t errorStat = fError->Eval(npartPbPb[centrToExtrapolate]);
175 std::cout << "Yield from fit: ("<<centrToExtrapolate<< "="<<npartPbPb[centrToExtrapolate]<<")"
177 << " +" << errorStat << " "
178 << " +" << errorSystPlus << " " << errorSystMinus//<< std::endl;
179 << " +" << fError->Eval(npartPbPb[centrToExtrapolate]) << std::endl;
180 std::cout << yield << " "
182 << (errorSystPlus+errorSystMinus)/2 << std::endl;
185 TGraphErrors * gExtrap = new TGraphErrors();
186 gExtrap->SetMarkerStyle(20);
187 gExtrap->SetPoint(0, npartPbPb[centrToExtrapolate], yield);
188 gExtrap->SetPointError(0, 0, (errorSystPlus+errorSystMinus)/2);
191 TLatex * text = new TLatex (0.2,0.81,systemAndEnergy);
194 TLatex * text2 = new TLatex (0.2,0.72,part->GetLatexName());
198 TLatex * func = new TLatex(0.53,0.23,label);
205 Double_t ErrorFunction (Double_t *xx, Double_t *p ) {
209 // Double_t x = xx[0];
212 // func[1] = TMath::Power(x, fForErrors->GetParameter(2));
213 // func[2] = fForErrors->GetParameter(1)*TMath::Power(x, fForErrors->GetParameter(2))*TMath::Log(x);
214 // In general, one can compute the derivative numerically using root.
215 for(Int_t ipar = 0; ipar < npar; ipar++){
216 func[ipar] = fForErrors->GradientPar(ipar, xx);
221 Double_t variance = 0;
223 for(Int_t ipar = 0; ipar < npar; ipar++){
224 for(Int_t jpar = 0; jpar < npar; jpar++){
225 variance = variance + func[ipar]*func[jpar] * matrix[ipar][jpar];
229 Double_t error = TMath::Sqrt(variance);
233 Double_t FuncPlusErr (Double_t *xx, Double_t *p) {
235 Double_t value = fForErrors->Eval(xx[0]);
236 Double_t error = ErrorFunction(xx, p);
239 return value + error;
245 Double_t FitShiftedGraphAndExtrapolate(TGraphErrors * gr, Int_t shift, TF1 * f1, const char * centr, Color_t color, Bool_t draw) {
250 TGraphErrors * grLocal = (TGraphErrors*) gr->Clone();
251 Int_t npoint = grLocal->GetN() ;
252 if(shift != kNoShift) {
253 for(Int_t ipoint = 0; ipoint < npoint; ipoint++){
254 Double_t relError = grLocal->GetEY()[ipoint]/grLocal->GetY()[ipoint];
255 Double_t value = grLocal->GetY() [ipoint];
256 if(shift == kShiftUp ) value += grLocal->GetEY()[ipoint];
257 if(shift == kShiftDown) value -= grLocal->GetEY()[ipoint];
258 if(shift == kShiftHarder) {
259 Double_t valueShift = -1. + 2.*Float_t(ipoint)/(npoint-1);
260 value += valueShift*grLocal->GetEY()[ipoint];
261 std::cout << "valueShift " << valueShift << std::endl;
263 if(shift == kShiftSofter) {
264 Double_t valueShift = +1. - 2.*Float_t(ipoint)/(npoint-1);
265 value += valueShift*grLocal->GetEY()[ipoint];
266 std::cout << "valueShift " << valueShift << std::endl;
268 grLocal->SetPoint (ipoint, grLocal->GetX() [ipoint], value);
269 grLocal->SetPointError(ipoint, grLocal->GetEX()[ipoint], relError*value);
272 grLocal->Fit(f1, "", "Q");
275 Double_t yield = f1->Eval(npartPbPb[centr]);
276 TF1 * clone = (TF1*) f1->Clone();
277 clone->SetLineWidth(1);
278 clone->SetLineStyle(kDashed);
279 clone->SetLineColor(color);
282 TVirtualPad * oldPad = gPad;
283 new TCanvas(Form("shifted_%d", shift), Form("shifted_%d", shift));
294 void ReadCentralityFromFile() {
295 ifstream filein (centrFile);
297 while (line.ReadLine((filein))) {
298 TObjArray * tokens = line.Tokenize(" ");
299 if(tokens->GetEntries() != 3) {
303 TString str = ((TObjString*)tokens->At(0))->String();
304 Float_t npart = ((TObjString*)tokens->At(1))->String().Atof();
305 Float_t npartErr = ((TObjString*)tokens->At(2))->String().Atof();
306 // std::cout << "["<<str.Data() <<"]" << npart << " " << npartErr << std::endl;
308 npartPbPb [str] = npart;
309 npartPbPbErr[str] = npartErr;