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