From Salvatore:
[u/mrichter/AliRoot.git] / PWGPP / pid / doeffPi.C
CommitLineData
a8ad4709 1TObject* fContPid1;
2TObject* fContPid2;
3const Int_t nBinPid = 14; // pt,eta, ptPip, ptPin, PPip, PPin, TOF3sigmaPip, TOF3sigmaPin, isPhiTrue, nsigmaPip, nsigmaPin
4// 0.985 < mass < 1.045 (60) and 0 < centrality < 100 (10)
5Int_t binPid[nBinPid] = {1/*ptPhi*/,8/*EtaPi*/,20/*pt+*/,20/*pt-*/,5/*P+*/,1/*P-*/,2/*TOFmatch+*/,2/*TOFmatch-*/,2/*istrue*/,4/*Nsigma+*/,4/*Nsigma-*/,1/*DeltaPhi+*/,1/*DeltaPhi-*/,1/*Psi*/};
6Float_t xmin[nBinPid] = {1,-0.8,0.3,0.3,0,0,-0.5,-0.5,-0.5,0,0,-TMath::Pi(),-TMath::Pi(),-TMath::Pi()/2};
7Float_t xmax[nBinPid] = {5,0.8,4.3,4.3,1,1,1.5,1.5,1.5,7.5,7.5,TMath::Pi(),TMath::Pi(),TMath::Pi()/2};
8
9TF1 *fsign;
10TF1 *fall;
11TF1 *fback;
12
13Int_t ifunc=0;
14
15Float_t fitmin = 0.3;
16Float_t fitmax = 0.7;
17
08b5b548 18Int_t cmin = 1; // min 1
19Int_t cmax = 10;//max 10
a8ad4709 20
21Float_t weightS = -1.;
22
23Int_t rebinsize = 4;
24
25Int_t parplotted = 2;
26
27Bool_t isMC = kFALSE; // don't change this (is set automatically)
28Bool_t selectTrue = kTRUE; // put it to true to remove background (only for MC)
29Bool_t keepTrue = kFALSE; // put it to false to fit only background (only for MC)
30
31Bool_t kGoodMatch = kFALSE; // to check good matching
32
33Bool_t kSigma2vs3 = kFALSE; // to check good matching
34
35Bool_t require5sigma = kFALSE; // don't touch this flag
36
37Bool_t bayesVsigma = kFALSE; // only to do checks
38
39Bool_t kTOFmatch = kFALSE; // for combined PID requires TOF matching
40
08b5b548 41Bool_t kOverAll = kFALSE;
e34b28fe 42Bool_t kOverAllTOFmatch = kFALSE;
08b5b548 43Bool_t kOverAll2Sigma = kFALSE;
e34b28fe 44
08b5b548 45TH2F *hmatched;
46TH2F *htracked;
a8ad4709 47
48Bool_t kLoaded=kFALSE;
49LoadLib(){
50 weightS = -1.;
51
52 if(! kLoaded){
53 gSystem->Load("libVMC.so");
54 gSystem->Load("libPhysics.so");
55 gSystem->Load("libTree.so");
56 gSystem->Load("libMinuit.so");
57 gSystem->Load("libSTEERBase.so");
58 gSystem->Load("libANALYSIS.so");
59 gSystem->Load("libAOD.so");
60 gSystem->Load("libESD.so");
61 gSystem->Load("libANALYSIS.so");
62 gSystem->Load("libANALYSISalice.so");
63 gSystem->Load("libCORRFW.so");
64 gSystem->Load("libNetx.so");
65 gSystem->Load("libPWGPPpid.so");
66
67 TFile *f = new TFile("AnalysisResults.root");
68 f->ls();
69 TList *l = (TList *) f->Get("contK0sBayes1");
08b5b548 70 TList *l2 = (TList *) f->Get("contK0sBayes2");
a8ad4709 71 l->ls();
08b5b548 72 fContPid1 = (AliPIDperfContainer *) l->FindObject("contPID");
73 fContPid2 = (AliPIDperfContainer *) l->FindObject("contPID2");
74 hmatched = (TH2F *) l2->FindObject("hMatchPi");
75 htracked = (TH2F *) l2->FindObject("hTrackingPi");
a8ad4709 76 }
77 kLoaded = kTRUE;
78
79 // check if MC
80 Float_t x[] = {xmin[0]+0.001,xmin[1]+0.001,xmin[2]+0.001,xmin[3]+0.001,xmin[4]+0.001,xmin[5]+0.001,xmin[6]+0.001,xmin[7]+0.001,1/*trueMC*/,xmin[9],xmin[10]};
81 Float_t x2[] = {xmax[0],xmax[1],xmax[2],xmax[3],xmax[4],xmax[5],xmax[6],xmax[7],xmax[8],xmax[9],xmax[10]};
82
83 AliPIDperfContainer *tmp = fContPid1;
84 TH1D *h = tmp->GetQA(0, x, x2)->ProjectionX("checkMC");
85
86 if(h->GetEntries()) isMC = kTRUE;
87 else isMC=kFALSE;
88
89 if(!isMC){
90 selectTrue = kFALSE;
91 keepTrue = kTRUE;
92 }
93 else{
94 printf("MC truth found!!!!!!\nIt is MC!!!!!!");
95 }
96
97 fsign = new TF1("fsign","[0]*TMath::Voigt(x-[1],[3],[2])",fitmin,fitmax);
98 fback = new TF1("fback","pol1",fitmin,fitmax);
99 fall = new TF1("fall","[0]*TMath::Voigt(x-[1],[3],[2]) + pol1(4)",fitmin,fitmax);
100
101 fsign->SetLineColor(2);
102 fback->SetLineColor(4);
103
104 if(kSigma2vs3){
105 kGoodMatch=kFALSE;
106 kOverAll = 0;
107 }
108
109 if(bayesVsigma){
110 kOverAll = 0;
111 kGoodMatch=kFALSE;
112 kSigma2vs3=kFALSE;
113 kTOFmatch=kTRUE;
114 weightS = -0.7;
115 }
116}
117
118doeffPi(Int_t pos=1,Float_t prob=0.1,Float_t etaminkp=-0.8,Float_t etamaxkp=0.8){
119 LoadLib();
08b5b548 120 TH1D *hm = hmatched->ProjectionX("matchingPiEff",cmin,cmax);
121 TH1D *ht = htracked->ProjectionX("tracking",cmin,cmax);
122
123 hm->GetYaxis()->SetTitle("TOF matching eff.");
124 hm->SetTitle("Using probability as weights");
125
126 hm->Sumw2();
127 ht->Sumw2();
128
129 hm->Divide(hm,ht,1,1,"B");
a8ad4709 130
131 Int_t nptbin = binPid[2];
132 Float_t minptbin = xmin[2];
133 Float_t maxptbin = xmax[2];
134
135 if(pos == 0){
136 nptbin = binPid[3];
137 minptbin = xmin[3];
138 maxptbin = xmax[3];
139 }
140
141 if(prob > 0.1999){
142 kGoodMatch = kFALSE;
143 kSigma2vs3 = kFALSE;
144 if(! kOverAll) require5sigma = kTRUE;
145 if(!isMC) weightS = -0.95;
146 }
147
148 TCanvas *c = new TCanvas();
149 c->Divide((nptbin+1)/2,2);
150 TH2F *hh.*hh2;
151 TH1D *h,*h2;
152 char name[100];
153 Float_t b[50][3];
154
155 Double_t xx[50],yy[50];
156 Double_t exx[50],eyy[50];
157
158 for(Int_t i=0;i < nptbin;i++){
08b5b548 159 c->cd(i+1);//->SetLogy();
a8ad4709 160 Float_t ptmin = minptbin+(maxptbin-minptbin)/nptbin*(i);
161 Float_t ptmax = minptbin+(maxptbin-minptbin)/nptbin*(i+1);
162
163 xx[i] = (ptmin+ptmax)/2;
164 exx[i] = (-ptmin+ptmax)/2;
165
166 Float_t pp=0.1;
167 if(prob < 0.2) pp = 0.;
168 if(pos) hh=GetHistoPip(ptmin,ptmax,pp,0.0,etaminkp,etamaxkp);
169 else hh=GetHistoPin(ptmin,ptmax,pp,0.0);
170 sprintf(name,"TOF matched: %f < p_{T} < %f GeV/#it{c}",ptmin,ptmax);
171 hh->SetTitle(name);
172 sprintf(name,"hNoPid%i",i);
173
174 pp=prob;
175 if(prob < 0.2) pp = 0.1;
176 if(pos) hh2=GetHistoPip(ptmin,ptmax,pp,0.0,etaminkp,etamaxkp);
177 else hh2=GetHistoPin(ptmin,ptmax,pp,0.0);
178 AddHisto(hh,hh2,weightS);
179
180 h = hh->ProjectionX(name,cmin,cmax);
181 h->RebinX(rebinsize);
182 h->Draw("ERR");
183 h->SetMarkerStyle(24);
184 b[i][0]=-1;
185 Int_t ntrial = 0;
186 Float_t chi2 = 10000;
08b5b548 187 while(ntrial < 3 && (chi2 > 20 + 1000*selectTrue)){
a8ad4709 188 fit(h,b[i],"WW","",xx[i]);
189 c1->Update();
190// getchar();
191 fit(h,b[i],"","",xx[i]);
192 ntrial++;
193 chi2 = b[i][2];
194 printf("chi2 = %f\n",chi2);
195 c1->Update();
196// getchar();
197
198 }
199
200 yy[i] = fall->GetParameter(parplotted);
201 eyy[i] = fall->GetParError(parplotted);
202 }
203
204 TGraphErrors *gpar = new TGraphErrors(nptbin,xx,yy,exx,eyy);
205 c->cd(8);
08b5b548 206// gpar->Draw("AP");
a8ad4709 207 gpar->SetMarkerStyle(20);
208
209 TCanvas *c2 = new TCanvas();
210 c2->Divide((nptbin+1)/2,2);
211 Float_t b2[50][3];
212
213 for(Int_t i=0;i < nptbin;i++){
214 c2->cd(i+1);
215 Float_t ptmin = minptbin+(maxptbin-minptbin)/nptbin*(i);
216 Float_t ptmax = minptbin+(maxptbin-minptbin)/nptbin*(i+1);
217
218 Float_t pp=prob;
219 if(prob < 0.2) pp = 0.1;
220 if(pos) hh=GetHistoPip(ptmin,ptmax,pp,0.0,etaminkp,etamaxkp);
221 else hh=GetHistoPin(ptmin,ptmax,pp,0.0);
222 sprintf(name,"P_{TOF} > 0.8: %f < p_{T} < %f GeV/#it{c}",ptmin,ptmax);
223 hh->SetTitle(name);
224 sprintf(name,"hPid60_%i",i);
225 h = hh->ProjectionX(name,cmin,cmax);
226 h->RebinX(rebinsize);
227 h->Draw("ERR");
228 h->SetMarkerStyle(24);
229 b2[i][0]=-1;
230 Int_t ntrial = 0;
231 Float_t chi2 = 10000;
08b5b548 232 while(ntrial < 3 && (chi2 > 20 + 1000*selectTrue)){
a8ad4709 233 fit(h,b2[i],"WW","");
234 fit(h,b2[i],"","");
235 ntrial++;
236 chi2 = b2[i][2];
237 printf("chi2 = %f\n",chi2);
238 }
239 yy[i] = fall->GetParameter(parplotted);
240 eyy[i] = fall->GetParError(parplotted);
241
242 }
243
244 TGraphErrors *gpar2 = new TGraphErrors(nptbin,xx,yy,exx,eyy);
245 c2->cd(8);
08b5b548 246// gpar2->Draw("AP");
a8ad4709 247 gpar2->SetMarkerStyle(20);
248
249 Double_t xpt[50],expt[50],eff[50],efferr[50];
250 for(Int_t i=0;i<nptbin;i++){
251 printf("%f +/- %f - %f +/- %f\n",b[i][0],b[i][1],b2[i][0],b2[i][1]);
252
253 Float_t ptmin = minptbin+(maxptbin-minptbin)/nptbin*(i);
254 Float_t ptmax = minptbin+(maxptbin-minptbin)/nptbin*(i+1);
255
256 xpt[i] = (ptmin+ptmax)/2;
257 expt[i] = (-ptmin+ptmax)/2;
258 eff[i] = b2[i][0]/(b[i][0]-b2[i][0]*weightS);
259
260 b[i][0] = b[i][0]-b2[i][0]*weightS;
261
262 efferr[i] = TMath::Sqrt(b[i][1]*b[i][1]/b[i][0]/b[i][0] + b2[i][1]*b2[i][1]/b2[i][0]/b2[i][0])*(b2[i][0]+b2[i][1])*(1+weightS*(b2[i][0]-b2[i][1])/b[i][0])/b[i][0];//*(1-eff[i]);//der2*der2*(b[i][1]*b[i][1] - b2[i][1]*b2[i][1]));
263
264 if(TMath::Abs(efferr[i]) > 1)efferr[i]=1;
265 }
266 new TCanvas();
267 TGraphErrors *geff = new TGraphErrors(nptbin,xpt,eff,expt,efferr);
268 geff->Draw("AP");
269
270 char flag[100];
271 sprintf(flag,"");
272
273 if(isMC){
274 if(selectTrue) sprintf(flag,"true");
275 else if(!keepTrue) sprintf(flag,"back");
276 }
277
08b5b548 278 Bool_t kWriteME = kFALSE;
279
a8ad4709 280 char flag2[100];
281 sprintf(flag2,"");
282
283 char etarange[100];
284 sprintf(etarange,"_%.1f-%.1f_",etaminkp,etamaxkp);
285
286 if(kGoodMatch)
287 sprintf(flag2,"GM");
288
289 if(bayesVsigma)
290 sprintf(flag2,"BayesVsSigma");
291
292 if(kSigma2vs3)
293 sprintf(flag2,"Sigma2vs3");
294
295 if(kOverAll)
296 sprintf(flag2,"OverAll");
e34b28fe 297 if(kOverAllTOFmatch)
298 sprintf(flag2,"OverAllTOF");
299 if(kOverAll2Sigma)
300 sprintf(flag2,"OverAll2sigma");
a8ad4709 301
302 if(pos){
303 if(prob >=0.2) sprintf(name,"pionPos%sP%iEff%i_%i%s%s.root",etarange,Int_t(prob*100),(cmin-1)*10,cmax*10,flag,flag2);
08b5b548 304 else{
305 sprintf(name,"pionPos%sMatchEff%i_%i%s%s.root",etarange,(cmin-1)*10,cmax*10,flag,flag2);
306 if(!(kOverAll || bayesVsigma || kGoodMatch || kSigma2vs3)) kWriteME = kTRUE;
307 }
a8ad4709 308 }
309 else{
310 if(prob >=0.2) sprintf(name,"pionNeg%sP%iEff%i_%i%s%s.root",etarange,Int_t(prob*100),(cmin-1)*10,cmax*10,flag,flag2);
311 else sprintf(name,"pionNeg%sMatchEff%i_%i%s%s.root",etarange,(cmin-1)*10,cmax*10,flag,flag2);
312 }
313
08b5b548 314 geff->SetTitle("#pi efficiency (from K^{0}_{s});p_{T} (GeV/#it{c};efficiency");
a8ad4709 315 TFile *fout = new TFile(name,"RECREATE");
316 geff->Write();
08b5b548 317 if(kWriteME) hm->Write();
a8ad4709 318 fout->Close();
319
08b5b548 320 if(kWriteME) hm->Draw("SAME");
a8ad4709 321}
322
323TH2F *GetHistoPip(Float_t pt=1,Float_t ptM=1.1,Float_t pMinkp=0,Float_t pMinkn=0.,Float_t etaminkp=-0.8,Float_t etamaxkp=0.8){
324
325 Float_t x[] = {xmin[0]+0.001,etaminkp+0.001,pt+0.001,xmin[3]+0.001,pMinkp+0.001,pMinkn+0.001,(pMinkp>0.09)+0.001,kTOFmatch+0.001,selectTrue,xmin[9],xmin[10],xmin[11],xmin[12],xmin[13]};
326 Float_t x2[] = {xmax[0],etamaxkp-0.001,ptM-0.001,xmax[3],xmax[4],xmax[5],xmax[6],xmax[7],keepTrue,xmax[9],xmax[10],xmax[11],xmax[12],xmax[13]};
327
e34b28fe 328 if(kOverAll){
329 x[6] = 0.0001;
330 x2[9] = 5.9;
331 if(pMinkp > 0.19) x2[9] = 4.9;
332 }
333
334 if(kOverAllTOFmatch && pMinkp > 0.19){
335 x[6] = 1.0001;
336 x2[9] = 4.9;
337 }
338
339 if(kOverAll2Sigma && pMinkp > 0.09){
08b5b548 340 x2[9] = 2.;
e34b28fe 341 x[6] = 1.0001;
342 }
343
a8ad4709 344 if(kGoodMatch){
345 x[6] = 1.0001;
346 if(pMinkp > 0)
347 x2[9] = 4.9;
348
349 }
350
351 if(kTOFmatch){
352 x[6] = 1.0001;
353 }
354
355 if(kSigma2vs3){
356 x[6] = 1.0001;
357 x2[9] = 3;
358 if(pMinkp > 0)
359 x2[9] = 2;
360 }
361
362 if(bayesVsigma){
363 if(pMinkp > 0){
364 x[4] = 0.2001;
365 x2[9] = 5;
366 }
367 else{
368 x2[9] = 3;
369 }
370
371
372 }
373
374 if(require5sigma) x2[9] = 4.9;
375
376 AliPIDperfContainer *tmp = fContPid1;
377
378 TH2F *h = tmp->GetQA(0, x, x2);
379
380 h->GetXaxis()->SetTitle("M_{K^{0}_{s}} (GeV/#it{c}^{2})");
381 h->GetYaxis()->SetTitle("centrality [%]");
382
383 return h;
384}
385
386TH2F *GetHistoPin(Float_t pt=1,Float_t ptM=1.1,Float_t pMinkn=0,Float_t pMinkp=0.,Float_t etaminkp=-0.8,Float_t etamaxkp=0.8){
387
388 Float_t x[] = {xmin[0]+0.001,etaminkp+0.001,xmin[2]+0.001,pt+0.001,pMinkp+0.001,pMinkn+0.001,kTOFmatch+0.001,(pMinkn>0.09)+0.001,selectTrue,xmin[9],xmin[10],xmin[11],xmin[12],xmin[13]};
389 Float_t x2[] = {xmax[0],etamaxkp-0.001,xmax[2],ptM-0.001,xmax[4],xmax[5],xmax[6],xmax[7],keepTrue,xmax[9],xmax[10],xmax[11],xmax[12],xmax[13]};
390
e34b28fe 391 if(kOverAll){
392 x[7] = 0.0001;
393 x2[10] = 5.9;
394 if(pMinkn > 0.19) x2[10] = 4.9;
395 }
396
397 if(kOverAllTOFmatch && pMinkn > 0.19){
398 x[7] = 1.0001;
399 x2[10] = 4.9;
400 }
401
402 if(kOverAll2Sigma && pMinkn > 0.09){
403 x2[10] = 2;
404 x[7] = 1.0001;
405 }
406
a8ad4709 407 if(kGoodMatch){
408 x[7] = 1.0001;
409 if(pMinkn > 0)
410 x2[10] = 4.9;
411
412 }
413
414 if(kTOFmatch){
415 x[7] = 1.0001;
416 }
417
418 if(kSigma2vs3){
419 x[7] = 1.0001;
420 x2[10] = 3;
421 if(pMinkn > 0)
422 x2[10] = 2;
423 }
424
425 if(bayesVsigma){
426 if(pMinkn > 0){
427 x[5] = 0.2001;
428 x2[10] = 5;
429 }
430 else{
431 x2[10] = 3;
432 }
433 }
434
435 if(require5sigma) x2[10] = 4.9;
436
437 AliPIDperfContainer *tmp = fContPid2;
438
439 TH2F *h = tmp->GetQA(0, x, x2);
440
441 h->GetXaxis()->SetTitle("M_{K^{0}_{s}} (GeV/#it{c}^{2})");
442 h->GetYaxis()->SetTitle("centrality [%]");
443
444 return h;
445}
446
447
448fit(TH1D *h,Float_t *a=NULL,char *opt="",char *opt2="",Float_t pt=1.5){
449 if(h->Integral(1,h->GetNbinsX()) < 1){
450 if(a){
451 a[0]=0.001;
452 a[1]=1;
453 }
454 return;
455 }
456
457
458 fall->SetParameter(0,100);
459 fall->SetParameter(1,0.4971);
460 fall->SetParameter(2,0.00006);
461 fall->SetParameter(3,0.0035);
462
463 fall->SetParLimits(0,0.00001,10000);
464 fall->SetParLimits(1,0.4965,0.4985);
465 fall->SetParLimits(2,0.00005,0.001);
466 fall->SetParLimits(3,0.002,0.01);
467
468 fall->ReleaseParameter(4);
469 fall->ReleaseParameter(5);
470
471 if(selectTrue){
472 fall->FixParameter(4,0);
473 fall->FixParameter(5,0);
474 }
475
476 char name[100];
477 TF1 *ftmp=fall;
478
479 TF1 *ftmp2=new TF1(*fsign);
480 sprintf(name,"fsign%i",ifunc);
481 ftmp2->SetName(name);
482
483 TF1 *ftmp3=new TF1(*fback);
484 sprintf(name,"ftmp3%i",ifunc);
485 ftmp3->SetName(name);
486
487 ifunc++;
488
489 h->Fit(ftmp,opt,opt2,fitmin,fitmax);
490 h->Draw("ERR");
491
492 ftmp2->SetParameter(0,ftmp->GetParameter(0));
493 ftmp2->SetParameter(1,ftmp->GetParameter(1));
494 ftmp2->SetParameter(2,ftmp->GetParameter(2));
495 ftmp2->SetParameter(3,ftmp->GetParameter(3));
496 ftmp2->Draw("SAME");
497 ftmp3->SetParameter(0,ftmp->GetParameter(4));
498 ftmp3->SetParameter(1,ftmp->GetParameter(5));
499 ftmp3->Draw("SAME");
500
501 Float_t mean = ftmp->GetParameter(1);
502 Float_t sigma = 0.0044;
503
504 Float_t signI = ftmp2->Integral(mean-10*sigma,mean+10*sigma)/h->GetBinWidth(1);
505 Float_t backI = ftmp3->Integral(mean-3*sigma,mean+3*sigma)/h->GetBinWidth(1);
506
507 Float_t errI = TMath::Sqrt(ftmp->GetParError(0)*ftmp->GetParError(0)/(0.001+ftmp->GetParameter(0))/(0.001+ftmp->GetParameter(0)));
508
509 printf("signal(5 sigma) = %f +/- %f(fit) +/- %f(stat)\n",signI,errI*signI,TMath::Sqrt(signI));
510 printf("backgr(3sigma) = %f\n",backI);
511 printf("significance(3 sigma) = %f\n",signI/sqrt(signI+backI));
512
513 if(a){
514 a[0]=signI;
515 a[1]=signI*errI*signI*errI + signI;
516 a[1] = TMath::Sqrt(a[1]);
517 if(ftmp->GetNDF()) a[2] = ftmp->GetChisquare()/ftmp->GetNDF();
518
519
520 if(selectTrue){
521 a[0] = h->Integral(1,h->GetNbinsX());
522 a[1] = TMath::Sqrt(a[0]);
523 }
524 }
525}
526
527AddHisto(TH2F *h1,TH2F *h2,Float_t w){
528 Int_t nbinx = h1->GetNbinsX();
529 Int_t nbiny = h1->GetNbinsY();
530
531 for(Int_t i=1;i<=nbinx;i++){
532 for(Int_t j=1;j<=nbiny;j++){
533 Float_t val = h1->GetBinContent(i,j) + h2->GetBinContent(i,j)*w;
534 Float_t err = TMath::Min(TMath::Sqrt(val),val);
535 h1->SetBinContent(i,j,val);
536 h1->SetBinError(i,j,err);
537 }
538 }
539}