8 #include"TGraphErrors.h"
9 #include"AliPIDperfContainer.h"
13 void doeffPr(Int_t pos=1,Float_t prob=0.1,Float_t etaminkp=-0.8,Float_t etamaxkp=0.8);
14 TH2F *GetHistoPrp(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);
15 TH2F *GetHistoPrn(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);
16 void fit(TH1D *h,Float_t *a=NULL,char *opt="",char *opt2="",Float_t pt=1.5);
17 void AddHisto(TH2F *h1,TH2F *h2,Float_t w);
21 const Int_t nBinPid = 14; // pt,eta, ptPip, ptPin, PPip, PPin, TOF3sigmaPip, TOF3sigmaPin, isPhiTrue, nsigmaPip, nsigmaPin
22 // 0.985 < mass < 1.045 (60) and 0 < centrality < 100 (10)
23 Int_t binPid[nBinPid] = {1/*ptPhi*/,8/*EtaPr*/,20/*pt+*/,20/*pt-*/,5/*P+*/,1/*P-*/,2/*TOFmatch+*/,2/*TOFmatch-*/,2/*istrue*/,4/*Nsigma+*/,4/*Nsigma-*/,1/*DeltaPhi+*/,1/*DeltaPhi-*/,1/*Psi*/};
24 Float_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};
25 Float_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};
33 Float_t fitmin = 1.08;
34 Float_t fitmax = 1.15;
36 Int_t cmin = 1; // min 1
37 Int_t cmax = 10; // max 10
39 Float_t weightS = -1.;
45 Bool_t isMC = kFALSE; // don't change this (is set automatically)
46 Bool_t selectTrue = kTRUE; // put it to true to remove background (only for MC)
47 Bool_t keepTrue = kFALSE; // put it to false to fit only background (only for MC)
49 Bool_t kGoodMatch = kFALSE; // to check good matching
51 Bool_t kSigma2vs3 = kFALSE; // to check good matching
53 Bool_t require5sigma = kFALSE; // don't touch this flag
55 Bool_t bayesVsigma = kFALSE; // only to do checks
57 Bool_t kTOFmatch = kFALSE; // for combined PID requires TOF matching
59 Bool_t kOverAll = kFALSE;
60 Bool_t kOverAllTOFmatch = kFALSE;
61 Bool_t kOverAll2Sigma = kFALSE;
62 Bool_t kPid2Sigma = kFALSE;
63 Bool_t kPid3Sigma = kFALSE;
68 Bool_t kLoaded=kFALSE;
72 require5sigma = kFALSE;
75 gSystem->Load("libVMC.so");
76 gSystem->Load("libPhysics.so");
77 gSystem->Load("libTree.so");
78 gSystem->Load("libMinuit.so");
79 gSystem->Load("libSTEERBase.so");
80 gSystem->Load("libANALYSIS.so");
81 gSystem->Load("libAOD.so");
82 gSystem->Load("libESD.so");
83 gSystem->Load("libANALYSIS.so");
84 gSystem->Load("libANALYSISalice.so");
85 gSystem->Load("libCORRFW.so");
86 gSystem->Load("libNetx.so");
87 gSystem->Load("libPWGPPpid.so");
89 TFile *f = new TFile("AnalysisResults.root");
90 TList *l = (TList *) f->Get("contLambdaBayes1");
91 TList *l2 = (TList *) f->Get("contLambdaBayes2");
93 if(!(l && l2)) return 0;
95 fContPid1 = (AliPIDperfContainer *) l->FindObject("contPID");
96 fContPid2 = (AliPIDperfContainer *) l->FindObject("contPID2");
98 hmatched = (TH2F *) l2->FindObject("hMatchPr");
99 htracked = (TH2F *) l2->FindObject("hTrackingPr");
104 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],xmin[11],xmin[12],xmin[13]};
105 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],xmax[11],xmax[12],xmax[13]};
107 AliPIDperfContainer *tmp = (AliPIDperfContainer *) fContPid1;
108 TH1D *h = tmp->GetQA(0, x, x2)->ProjectionX("checkMC");
110 if(h->GetEntries()) isMC = kTRUE;
118 printf("MC truth found!!!!!!\nIt is MC!!!!!!");
121 fsign = new TF1("fsign","gaus(0) +0.5*[0]*TMath::Exp(-[3]*TMath::Abs(x-[1]))",fitmin,fitmax);
122 fback = new TF1("fback","pol2",fitmin,fitmax);
123 fall = new TF1("fall","gaus(0) +0.5*[0]*TMath::Exp(-[3]*TMath::Abs(x-[1])) + pol2(4)",fitmin,fitmax);
125 fsign->SetLineColor(2);
126 fback->SetLineColor(4);
144 void doeffPr(Int_t pos,Float_t prob,Float_t etaminkp,Float_t etamaxkp){
146 TH1D *hm = hmatched->ProjectionX("matchingPrEff",cmin,cmax);
147 TH1D *ht = htracked->ProjectionX("tracking",cmin,cmax);
149 hm->GetYaxis()->SetTitle("TOF matching eff.");
150 hm->SetTitle("Using probability as weights");
155 hm->Divide(hm,ht,1,1,"B");
157 Int_t nptbin = binPid[2];
158 Float_t minptbin = xmin[2];
159 Float_t maxptbin = xmax[2];
167 if(prob > 0.1999|| kPid3Sigma ||kPid2Sigma){
170 // if(! kOverAll) require5sigma = kTRUE;
171 if(!isMC) weightS = -0.95;
174 TCanvas *c1 = new TCanvas();
175 c1->Divide((nptbin+1)/2,2);
181 Double_t xx[50],yy[50];
182 Double_t exx[50],eyy[50];
184 for(Int_t i=0;i < nptbin;i++){
185 c1->cd(i+1);//->SetLogy();
186 Float_t ptmin = minptbin+(maxptbin-minptbin)/nptbin*(i);
187 Float_t ptmax = minptbin+(maxptbin-minptbin)/nptbin*(i+1);
189 xx[i] = (ptmin+ptmax)/2;
190 exx[i] = (-ptmin+ptmax)/2;
193 if(prob < 0.2) pp = 0.;
194 if(pos) hh=GetHistoPrp(ptmin,ptmax,pp,0.0,etaminkp,etamaxkp);
195 else hh=GetHistoPrn(ptmin,ptmax,pp,0.0);
196 sprintf(name,"TOF matched: %f < p_{T} < %f GeV/#it{c}",ptmin,ptmax);
198 sprintf(name,"hNoPid%i",i);
201 if(prob < 0.2) pp = 0.1;
202 if(pos) hh2=GetHistoPrp(ptmin,ptmax,pp,0.0,etaminkp,etamaxkp);
203 else hh2=GetHistoPrn(ptmin,ptmax,pp,0.0);
204 AddHisto(hh,hh2,weightS);
206 h = hh->ProjectionX(name,cmin,cmax);
207 h->RebinX(rebinsize);
209 h->SetMarkerStyle(24);
212 Float_t chi2 = 10000;
213 while(ntrial < 3 && (chi2 > 20 + 1000*selectTrue)){
214 fit(h,b[i],"WW","",xx[i]);
217 fit(h,b[i],"","",xx[i]);
220 printf("chi2 = %f\n",chi2);
226 yy[i] = fall->GetParameter(parplotted);
227 eyy[i] = fall->GetParError(parplotted);
230 TGraphErrors *gpar = new TGraphErrors(nptbin,xx,yy,exx,eyy);
233 gpar->SetMarkerStyle(20);
235 TCanvas *c2 = new TCanvas();
236 c2->Divide((nptbin+1)/2,2);
239 for(Int_t i=0;i < nptbin;i++){
241 Float_t ptmin = minptbin+(maxptbin-minptbin)/nptbin*(i);
242 Float_t ptmax = minptbin+(maxptbin-minptbin)/nptbin*(i+1);
245 if(prob < 0.2) pp = 0.1;
246 if(pos) hh=GetHistoPrp(ptmin,ptmax,pp,0.0,etaminkp,etamaxkp);
247 else hh=GetHistoPrn(ptmin,ptmax,pp,0.0);
248 sprintf(name,"P_{TOF} > 0.8: %f < p_{T} < %f GeV/#it{c}",ptmin,ptmax);
250 sprintf(name,"hPid60_%i",i);
251 h = hh->ProjectionX(name,cmin,cmax);
252 h->RebinX(rebinsize);
254 h->SetMarkerStyle(24);
257 Float_t chi2 = 10000;
258 while(ntrial < 3 && (chi2 > 20 + 1000*selectTrue)){
259 fit(h,b2[i],"WW","",xx[i]);
260 fit(h,b2[i],"","",xx[i]);
263 printf("chi2 = %f\n",chi2);
265 yy[i] = fall->GetParameter(parplotted);
266 eyy[i] = fall->GetParError(parplotted);
270 TGraphErrors *gpar2 = new TGraphErrors(nptbin,xx,yy,exx,eyy);
272 // gpar2->Draw("AP");
273 gpar2->SetMarkerStyle(20);
275 Double_t xpt[50],expt[50],eff[50],efferr[50];
276 for(Int_t i=0;i<nptbin;i++){
277 printf("%f +/- %f - %f +/- %f\n",b[i][0],b[i][1],b2[i][0],b2[i][1]);
279 Float_t ptmin = minptbin+(maxptbin-minptbin)/nptbin*(i);
280 Float_t ptmax = minptbin+(maxptbin-minptbin)/nptbin*(i+1);
282 xpt[i] = (ptmin+ptmax)/2;
283 expt[i] = (-ptmin+ptmax)/2;
284 eff[i] = b2[i][0]/(b[i][0]-b2[i][0]*weightS);
286 b[i][0] = b[i][0]-b2[i][0]*weightS;
288 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]));
290 if(TMath::Abs(efferr[i]) > 1)efferr[i]=1;
293 TGraphErrors *geff = new TGraphErrors(nptbin,xpt,eff,expt,efferr);
300 if(selectTrue) sprintf(flag,"true");
301 else if(!keepTrue) sprintf(flag,"back");
307 Bool_t kWriteME = kFALSE;
310 sprintf(etarange,"_%.1f-%.1f_",etaminkp,etamaxkp);
316 sprintf(flag2,"BayesVsSigma");
319 sprintf(flag2,"Sigma2vs3");
322 sprintf(flag2,"OverAll");
324 sprintf(flag2,"OverAllTOF");
326 sprintf(flag2,"OverAll2sigma");
329 sprintf(flag2,"pid3sigma");
331 sprintf(flag2,"pid2sigma");
334 if(prob >=0.2) sprintf(name,"protonPos%sP%iEff%i_%i%s%s.root",etarange,Int_t(prob*100),(cmin-1)*10,cmax*10,flag,flag2);
336 sprintf(name,"protonPos%sMatchEff%i_%i%s%s.root",etarange,(cmin-1)*10,cmax*10,flag,flag2);
337 if(!(kOverAll || bayesVsigma || kGoodMatch || kSigma2vs3)) kWriteME = kTRUE;
341 if(prob >=0.2) sprintf(name,"protonNeg%sP%iEff%i_%i%s%s.root",etarange,Int_t(prob*100),(cmin-1)*10,cmax*10,flag,flag2);
342 else sprintf(name,"protonNeg%sMatchEff%i_%i%s%s.root",etarange,(cmin-1)*10,cmax*10,flag,flag2);
345 geff->SetTitle("p efficiency (from (anti)#Lambda);p_{T} (GeV/#it{c};efficiency");
346 TFile *fout = new TFile(name,"RECREATE");
348 if(kWriteME) hm->Write();
351 if(kWriteME) hm->Draw("SAME");
354 TH2F *GetHistoPrp(Float_t pt,Float_t ptM,Float_t pMinkp,Float_t pMinkn,Float_t etaminkp,Float_t etamaxkp){
356 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 || kPid3Sigma||kPid2Sigma)+0.001,kTOFmatch+0.001,selectTrue,xmin[9],xmin[10],xmin[11],xmin[12],xmin[13]};
357 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]};
362 if(pMinkp > 0.19) x2[9] = 4.9;
365 if(kOverAllTOFmatch && pMinkp > 0.19){
370 if(kOverAll2Sigma && pMinkp > 0.09){
405 if(require5sigma) x2[9] = 4.9;
406 if(kPid3Sigma && pMinkp>0.09) x2[9] = 2.9;
407 if(kPid2Sigma && pMinkp>0.09) x2[9] = 1.9;
409 AliPIDperfContainer *tmp = (AliPIDperfContainer *) fContPid1;
411 TH2F *h = tmp->GetQA(0, x, x2);
413 h->GetXaxis()->SetTitle("M_{#Lambda} (GeV/#it{c}^{2})");
414 h->GetYaxis()->SetTitle("centrality [%]");
419 TH2F *GetHistoPrn(Float_t pt,Float_t ptM,Float_t pMinkn,Float_t pMinkp,Float_t etaminkp,Float_t etamaxkp){
421 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 || kPid3Sigma||kPid2Sigma)+0.001,selectTrue,xmin[9],xmin[10],xmin[11],xmin[12],xmin[13]};
422 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]};
427 if(pMinkn > 0.19) x2[10] = 4.9;
430 if(kOverAllTOFmatch && pMinkn > 0.19){
435 if(kOverAll2Sigma && pMinkn > 0.09){
468 if(require5sigma) x2[10] = 4.9;
469 if(kPid3Sigma && pMinkn>0.09) x2[10] = 2.9;
470 if(kPid2Sigma && pMinkn>0.09) x2[10] = 1.9;
472 AliPIDperfContainer *tmp = (AliPIDperfContainer *) fContPid2;
474 TH2F *h = tmp->GetQA(0, x, x2);
476 h->GetXaxis()->SetTitle("M_{#Lambda} (GeV/#it{c}^{2})");
477 h->GetYaxis()->SetTitle("centrality [%]");
482 void fit(TH1D *h,Float_t *a,char *opt,char *opt2,Float_t pt){
483 if(h->Integral(1,h->GetNbinsX()) < 1){
492 fall->SetParameter(0,100);
493 fall->SetParameter(1,1.115);
494 fall->SetParameter(2,2.89748e-03);
495 fall->FixParameter(3,350+600/pt);
497 fall->SetParLimits(0,0.00001,10000);
498 fall->SetParLimits(1,1.105,1.125);//1.01898 + 2.4e-04*pt-1e-03,1.01898 + 2.4e-04*pt+1e-03);
499 fall->SetParLimits(2,0.0005,0.0015);
500 //fall->SetParLimits(3,200,350);
502 // fall->FixParameter(2,5E-4);
504 // fall->FixParameter(1,1.01884 + 2.9891e-04*pt);
505 // fall->FixParameter(2,0.0044);
506 // fall->FixParameter(3,7.57574e-04 + 3.85408e-04*pt);
508 fall->ReleaseParameter(4);
509 fall->ReleaseParameter(5);
510 fall->ReleaseParameter(6);
513 fall->FixParameter(4,0);
514 fall->FixParameter(5,0);
515 fall->FixParameter(6,0);
519 sprintf(namenew,"%s_%i",h->GetName(),Int_t(gRandom->Rndm()*10000));
520 TH1D *h2 = new TH1D(*h);
521 h2->SetName(namenew);
523 // Float_t entries = h2->GetBinContent(h2->FindBin(0.497));
524 // printf("entries under the peak = %f, pt = %f\n",entries,pt);
528 if(pt < 2.8) h2->RebinX(2);
529 else if(pt < 3) h2->RebinX(4);
538 TF1 *ftmp2=new TF1(*fsign);
539 sprintf(name,"fsign%i",ifunc);
540 ftmp2->SetName(name);
542 TF1 *ftmp3=new TF1(*fback);
543 sprintf(name,"ftmp3%i",ifunc);
544 ftmp3->SetName(name);
548 h->Fit(ftmp,opt,opt2,fitmin,fitmax);
551 ftmp2->SetParameter(0,ftmp->GetParameter(0));
552 ftmp2->SetParameter(1,ftmp->GetParameter(1));
553 ftmp2->SetParameter(2,ftmp->GetParameter(2));
554 ftmp2->SetParameter(3,ftmp->GetParameter(3));
556 ftmp3->SetParameter(0,ftmp->GetParameter(4));
557 ftmp3->SetParameter(1,ftmp->GetParameter(5));
558 ftmp3->SetParameter(2,ftmp->GetParameter(6));
561 Float_t mean = ftmp->GetParameter(1);
562 Float_t sigma = TMath::Abs(ftmp->GetParameter(2));
564 Float_t signI = ftmp2->Integral(mean-10*sigma,mean+10*sigma)/h->GetBinWidth(1);
565 Float_t backI = ftmp3->Integral(mean-3*sigma,mean+3*sigma)/h->GetBinWidth(1);
567 Float_t errI = TMath::Abs(ftmp->GetParError(0)*ftmp->GetParError(0)/(0.001+ftmp->GetParameter(0))/(0.001+ftmp->GetParameter(0)));
569 errI = TMath::Sqrt(errI);
571 if(signI < 1) signI = 1;
572 if(backI < 1) backI = 1;
574 printf("signal(5 sigma) = %f +/- %f(fit) +/- %f(stat)\n",signI,errI*signI,TMath::Sqrt(signI));
575 printf("backgr(3sigma) = %f\n",backI);
576 printf("significance(3 sigma) = %f\n",signI/sqrt(signI+backI));
580 a[1]=signI*errI*signI*errI + signI;
581 a[1] = TMath::Sqrt(a[1]);
582 if(ftmp->GetNDF()) a[2] = ftmp->GetChisquare()/ftmp->GetNDF();
586 a[0] = h->Integral(1,h->GetNbinsX());
587 a[1] = TMath::Sqrt(a[0]);
592 void AddHisto(TH2F *h1,TH2F *h2,Float_t w){
593 Int_t nbinx = h1->GetNbinsX();
594 Int_t nbiny = h1->GetNbinsY();
596 for(Int_t i=1;i<=nbinx;i++){
597 for(Int_t j=1;j<=nbiny;j++){
598 Double_t val = h1->GetBinContent(i,j) + h2->GetBinContent(i,j)*w;
599 Float_t err = TMath::Min(TMath::Sqrt(val),val);
600 h1->SetBinContent(i,j,val);
601 h1->SetBinError(i,j,err);