]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/pid/doeffKa.C
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[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     if(xx[i] > 2.5) rebinsize = 2;
218
219     h = hh->ProjectionX(name,cmin,cmax);
220     h->RebinX(rebinsize);
221     h->Draw("ERR");
222     h->SetMarkerStyle(24);
223     b[i][0]=-1;
224     Int_t ntrial = 0;
225     Float_t chi2 = 10000;
226     while(ntrial < 3 && (chi2 > 20 + 1000*selectTrue)){
227       fit(h,b[i],"WW","",xx[i]);
228       c1->Update();
229 //       getchar();
230       fit(h,b[i],"","",xx[i]);
231       ntrial++;
232       chi2 = b[i][2];
233       printf("chi2 = %f\n",chi2);
234       c1->Update();
235 //       getchar();
236       
237     }
238
239     yy[i] = fall->GetParameter(parplotted);
240     eyy[i] = fall->GetParError(parplotted);
241   }
242
243   TGraphErrors *gpar = new TGraphErrors(nptbin,xx,yy,exx,eyy);
244   c1->cd(8);
245 //   gpar->Draw("AP");
246   gpar->SetMarkerStyle(20);
247
248   TCanvas *c2 = new TCanvas();
249   c2->Divide((nptbin+1)/2,2);
250   Float_t b2[50][3];
251
252   for(Int_t i=0;i < nptbin;i++){
253     c2->cd(i+1);
254     Float_t ptmin = minptbin+(maxptbin-minptbin)/nptbin*(i);
255     Float_t ptmax = minptbin+(maxptbin-minptbin)/nptbin*(i+1);
256
257     Float_t pp=prob;
258     if(prob < 0.2) pp = 0.1;
259     if(pos) hh=GetHistoKap(ptmin,ptmax,pp,0.0,etaminkp,etamaxkp);
260     else hh=GetHistoKan(ptmin,ptmax,pp,0.0);
261     sprintf(name,"P_{TOF} > 0.8: %f < p_{T} < %f GeV/#it{c}",ptmin,ptmax);
262     hh->SetTitle(name);
263     sprintf(name,"hPid60_%i",i);
264     h = hh->ProjectionX(name,cmin,cmax);
265     h->RebinX(rebinsize);
266     h->Draw("ERR");
267     h->SetMarkerStyle(24);
268     b2[i][0]=-1;
269     Int_t ntrial = 0;
270     Float_t chi2 = 10000;
271     while(ntrial < 3 && (chi2 > 20 + 1000*selectTrue)){
272       fit(h,b2[i],"WW","");
273       fit(h,b2[i],"","");
274       ntrial++;
275       chi2 = b2[i][2];
276       printf("chi2 = %f\n",chi2);
277     }
278     yy[i] = fall->GetParameter(parplotted);
279     eyy[i] = fall->GetParError(parplotted);
280
281   }
282
283   TGraphErrors *gpar2 = new TGraphErrors(nptbin,xx,yy,exx,eyy);
284   c2->cd(8);
285 //   gpar2->Draw("AP");
286   gpar2->SetMarkerStyle(20);
287   
288   Double_t xpt[50],expt[50],eff[50],efferr[50];
289   for(Int_t i=0;i<nptbin;i++){
290     printf("%f +/- %f -  %f +/- %f\n",b[i][0],b[i][1],b2[i][0],b2[i][1]);
291
292     Float_t ptmin = minptbin+(maxptbin-minptbin)/nptbin*(i);
293     Float_t ptmax = minptbin+(maxptbin-minptbin)/nptbin*(i+1);
294
295     xpt[i] = (ptmin+ptmax)/2;
296     expt[i] = (-ptmin+ptmax)/2;
297     eff[i] = b2[i][0]/(b[i][0]-b2[i][0]*weightS);
298
299     //    b[i][0] = b[i][0]-b2[i][0]*weightS;
300
301     //    if(b[i][0] < 0.5) b[i][0] = 0.5;
302     //    if(b2[i][0] < 0.5) b2[i][0] = 0.5;
303
304
305     //    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]));
306     //    efferr[i] = TMath::Sqrt(efferr[i]);
307     efferr[i] = 1./(b[i][0]-b2[i][0]*weightS)/(b[i][0]-b2[i][0]*weightS)*TMath::Sqrt(b[i][0]*b[i][0]*b2[i][1]*b2[i][1] + b2[i][0]*b2[i][0]*b[i][1]*b[i][1]);
308
309     if(TMath::Abs(efferr[i]) > 1)efferr[i]=1;
310   }
311   new TCanvas();
312   TGraphErrors *geff = new TGraphErrors(nptbin,xpt,eff,expt,efferr);
313   geff->Draw("AP");
314
315   char flag[100];
316   flag[0] = '\0';
317
318   if(isMC){
319     if(selectTrue) sprintf(flag,"true");
320     else if(!keepTrue) sprintf(flag,"back");
321   }
322
323   char flag2[100];
324   flag2[0] = '\0';
325
326   Bool_t kWriteME = kFALSE;
327
328   char etarange[100];
329   sprintf(etarange,"_%.1f-%.1f_",etaminkp,etamaxkp);
330
331   if(kGoodMatch)
332     sprintf(flag2,"GM");
333
334   if(bayesVsigma)
335     sprintf(flag2,"BayesVsSigma");
336
337   if(kSigma2vs3)
338     sprintf(flag2,"Sigma2vs3");
339
340   if(kOverAll)
341     sprintf(flag2,"OverAll");
342   if(kOverAllTOFmatch)
343     sprintf(flag2,"OverAllTOF"); 
344   if(kOverAll2Sigma)
345     sprintf(flag2,"OverAll2sigma"); 
346
347   if(kPid3Sigma)
348     sprintf(flag2,"pid3sigma");
349   if(kPid2Sigma)
350     sprintf(flag2,"pid2sigma");
351
352   if(pos){
353     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);
354     else{
355       sprintf(name,"kaonPos%sMatchEff%i_%i%s%s.root",etarange,(cmin-1)*10,cmax*10,flag,flag2);
356       if(!(kOverAll || bayesVsigma || kGoodMatch || kSigma2vs3)) kWriteME = kTRUE;
357     }
358   }
359   else{
360     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);
361     else sprintf(name,"kaonNeg%sMatchEff%i_%i%s%s.root",etarange,(cmin-1)*10,cmax*10,flag,flag2);
362   }
363
364   geff->SetTitle("K efficiency (from #phi);p_{T} (GeV/#it{c};efficiency");
365   TFile *fout = new TFile(name,"RECREATE");
366   geff->Write();
367   if(kWriteME) hm->Write();
368   fout->Close();
369
370   if(kWriteME) hm->Draw("SAME");
371 }
372
373 TH2F *GetHistoKap(Float_t pt,Float_t ptM,Float_t pMinkp,Float_t pMinkn,Float_t etaminkp,Float_t etamaxkp){
374
375   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]};
376   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]};
377
378   if(kOverAll){
379     x[6] = 0.0001;
380     x2[9] = 5.9;
381     if(pMinkp > 0.19) x2[9] = 4.9;
382   }
383
384   if(kOverAllTOFmatch && pMinkp > 0.19){
385     x[6] = 1.0001;
386     x2[9] = 4.9;
387   }
388
389   if(kOverAll2Sigma && pMinkp > 0.09){
390     x2[9] = 2;
391     x[6] = 1.0001;
392   }
393
394   if(kGoodMatch){
395     x[6] = 1.0001;
396     if(pMinkp > 0)
397       x2[9] = 4.9;
398       
399   }
400
401   if(kTOFmatch){
402     x[6] = 1.0001;
403   }
404
405   if(kSigma2vs3){
406     x[6] = 1.0001;
407     x2[9] = 3;
408     if(pMinkp > 0)
409       x2[9] = 2;
410   }
411
412   if(bayesVsigma){
413     if(pMinkp > 0){
414       x[4] = 0.2001;
415       x2[9] = 5;
416     }
417     else{
418       x2[9] = 3;
419     }
420
421     
422   }
423
424   if(require5sigma) x2[9] = 4.9;
425   if(kPid3Sigma && pMinkp>0.09) x2[9] = 2.9;
426   if(kPid2Sigma && pMinkp>0.09) x2[9] = 1.9;
427
428   AliPIDperfContainer *tmp = (AliPIDperfContainer *) fContPid1;
429
430   TH2F *h = tmp->GetQA(0, x, x2);
431
432   h->GetXaxis()->SetTitle("M_{#phi} (GeV/#it{c}^{2})");
433   h->GetYaxis()->SetTitle("centrality [%]");
434
435   return h;
436 }
437
438 TH2F *GetHistoKan(Float_t pt,Float_t ptM,Float_t pMinkn,Float_t pMinkp,Float_t etaminkp,Float_t etamaxkp){
439
440   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]};
441   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]};
442
443  if(kOverAll){
444     x[7] = 0.0001;
445     x2[10] = 5.9;
446     if(pMinkn > 0.19) x2[10] = 4.9;
447   }
448
449   if(kOverAllTOFmatch && pMinkn > 0.19){
450     x[7] = 1.0001;
451     x2[10] = 4.9;
452   }
453
454   if(kOverAll2Sigma && pMinkn > 0.09){
455     x2[10] = 2;
456     x[7] = 1.0001;
457   }
458
459   if(kGoodMatch){
460     x[7] = 1.0001;
461     if(pMinkn > 0)
462       x2[10] = 4.9;
463       
464   }
465
466   if(kTOFmatch){
467     x[7] = 1.0001;
468   }
469
470   if(kSigma2vs3){
471     x[7] = 1.0001;
472     x2[10] = 3;
473     if(pMinkn > 0)
474       x2[10] = 2;
475   }
476  
477  if(bayesVsigma){
478     if(pMinkn > 0){
479       x[5] = 0.2001;
480       x2[10] = 5;
481     }
482     else{
483       x2[10] = 3;
484     }    
485   }
486
487   if(require5sigma) x2[10] = 4.9;
488   if(kPid3Sigma && pMinkn>0.09) x2[10] = 2.9;
489   if(kPid2Sigma && pMinkn>0.09) x2[10] = 1.9;
490
491   AliPIDperfContainer *tmp = (AliPIDperfContainer *) fContPid2;
492
493   TH2F *h = tmp->GetQA(0, x, x2);
494
495   h->GetXaxis()->SetTitle("M_{#phi} (GeV/#it{c}^{2})");
496   h->GetYaxis()->SetTitle("centrality [%]");
497
498   return h;
499 }
500
501
502 void fit(TH1D *h,Float_t *a,char *opt,char *opt2,Float_t pt){
503   if(h->GetEntries() < 1){
504     if(a){
505       a[0]=0.01;
506       a[1]=1;
507     }
508     return;
509   }
510
511
512  fall->SetParameter(0,100);
513  fall->SetParameter(0,1.01898 + 2.4e-04*pt);
514  fall->SetParameter(2,0.0044);
515  fall->SetParameter(3,0.0015);
516
517  fall->SetParLimits(0,-100,100000);
518  fall->SetParLimits(1,1.01898 + 2.4e-04*pt-1e-03,1.01898 + 2.4e-04*pt+1e-03);
519  fall->SetParLimits(2,0.0005,0.006);
520  fall->SetParLimits(3,0.001,0.0017);
521
522  fall->FixParameter(1,1.01884 + 2.9891e-04*pt);
523  fall->FixParameter(2,0.0044);
524  fall->FixParameter(3,7.57574e-04 + 3.85408e-04*pt);
525
526  fall->ReleaseParameter(4);
527  fall->ReleaseParameter(5);
528  fall->ReleaseParameter(6);
529  fall->ReleaseParameter(7);
530  fall->ReleaseParameter(8);
531
532
533  if(!kGoodMatch && !kSigma2vs3){
534    if(pt > 1.5){
535      fall->FixParameter(7,0);   
536      fall->FixParameter(8,0);   
537    }
538    if(pt > 1.7){
539      fall->FixParameter(6,0);   
540    }
541  }
542
543  if(selectTrue){
544    fall->FixParameter(4,0);
545    fall->FixParameter(5,0);
546    fall->FixParameter(6,0);
547    fall->FixParameter(7,0);
548    fall->FixParameter(8,0);
549  }
550
551  char name[100];
552  TF1 *ftmp=fall;
553
554  TF1 *ftmp2=new TF1(*fsign);
555  sprintf(name,"fsign%i",ifunc);
556  ftmp2->SetName(name);
557
558  TF1 *ftmp3=new TF1(*fback);
559  sprintf(name,"ftmp3%i",ifunc);
560  ftmp3->SetName(name);
561
562  ifunc++;
563
564  h->Fit(ftmp,opt,opt2,fitmin,fitmax);
565  h->Draw("ERR");
566
567  ftmp2->SetParameter(0,ftmp->GetParameter(0));
568  ftmp2->SetParameter(1,ftmp->GetParameter(1));
569  ftmp2->SetParameter(2,ftmp->GetParameter(2));
570  ftmp2->SetParameter(3,ftmp->GetParameter(3));
571  ftmp2->Draw("SAME");
572  ftmp3->SetParameter(0,ftmp->GetParameter(4));
573  ftmp3->SetParameter(1,ftmp->GetParameter(5));
574  ftmp3->SetParameter(2,ftmp->GetParameter(6));
575  ftmp3->SetParameter(3,ftmp->GetParameter(7));
576  ftmp3->SetParameter(4,ftmp->GetParameter(8));
577  ftmp3->Draw("SAME");
578
579  Float_t mean = ftmp->GetParameter(1);
580  Float_t sigma = 0.0044;//TMath::Abs(ftmp->GetParameter(2));
581
582  Float_t signI = ftmp2->Integral(mean-10*sigma,mean+10*sigma)/h->GetBinWidth(1);
583  if(signI < 0.1) signI = 0.1;
584
585  Float_t backI = ftmp3->Integral(mean-3*sigma,mean+3*sigma)/h->GetBinWidth(1);
586  if(backI < 1) backI = 1;
587
588  Float_t errI = TMath::Abs(ftmp->GetParError(0)*ftmp->GetParError(0)/(0.001+ftmp->GetParameter(0))/(0.001+ftmp->GetParameter(0)));
589  errI = TMath::Sqrt(errI);
590
591  printf("signal(5 sigma) = %f +/- %f(fit) +/- %f(stat)\n",signI,errI*signI,TMath::Sqrt(signI));
592  printf("backgr(3sigma) = %f\n",backI);
593  printf("significance(3 sigma) = %f\n",signI/sqrt(signI+backI));
594
595  if(a){
596    a[0]=signI;
597    a[1]=signI*errI*signI*errI + signI;
598    a[1] = TMath::Sqrt(a[1]);
599    if(ftmp->GetNDF()) a[2] = ftmp->GetChisquare()/ftmp->GetNDF();
600
601
602    if(selectTrue){
603      a[0] = h->GetEntries();
604      a[1] = TMath::Sqrt(a[0]);
605    }
606  }
607 }
608
609 void AddHisto(TH2F *h1,TH2F *h2,Float_t w){
610   Int_t nbinx = h1->GetNbinsX();
611   Int_t nbiny = h1->GetNbinsY();
612
613   for(Int_t i=1;i<=nbinx;i++){
614     for(Int_t j=1;j<=nbiny;j++){
615       Double_t val = h1->GetBinContent(i,j) + h2->GetBinContent(i,j)*w;
616       Float_t err = TMath::Min(TMath::Sqrt(val),val);
617       h1->SetBinContent(i,j,val);
618       h1->SetBinError(i,j,err);
619     }
620   }
621 }