1 #include "commonmacro/common.h"
2 #include "common/Name.cc"
3 #include "commonmacro/histutil.h"
7 void backgroundDca(
const char* inName=
8 "links/P01hi.minbias.2000.hist/hianalysis_1000.hist.root",
9 const char* psDir=
"ps",
11 const char* outDir=
"./",
12 const char* more =
"west",
15 cout <<
"--------------------------" << endl;
16 cout <<
"in name=" << inName << endl
17 <<
"ps dir=" << psDir << endl
18 <<
"cut=" << cut << endl;
19 cout <<
"--------------------------" << endl;
24 inRoot[0] =
new TFile(inName);
27 inRoot[1] =
new TFile(more);
29 if(!inRoot[0] || !inRoot[1]){
30 cout <<
"cannot find input file" << endl;
return;
33 gSystem->Load(
"StHiMicroAnalysis");
38 cout <<
"cannot find the infile" << endl;
43 TString sOutDir=inName;
44 sOutDir.Remove(sOutDir.Last(
'/'),sOutDir.Length());
45 cout << sOutDir << endl;
51 {1.7, 1.8, 1.9, 2.0, 2.2, 2.45, 2.7, 3.0, 3.35, 3.8, 4.4, 5.1, 6.0}
53 char* ptType[] = {
"PtPr",
"PtGl"};
54 char* chargeType[]= {
"",
"Pos",
"Neg"};
55 char* dcaType[] = {
"DcaXYGl",
"DcaGl",
"SDcaGl"};
56 char* ptRebin[] = {
"",
"Rebin" };
57 int nDcaRebin[] = {2,2,2};
58 float bkgMin[] = {-3, 2, -3 };
59 float bkgMax[] = {-2, 3, -2 };
60 float dcaCut = fabs(Cut::mSDcaGl[0]);
61 float sigMin[] = {-dcaCut,0,-dcaCut};
62 float sigMax[] = {dcaCut,dcaCut,dcaCut};
64 TCanvas c1(
"c1",
"c1",400,500);
65 TCanvas c2(
"c2",
"c2",400,500);
67 TH2* h2[2], *h2b[2], *h2temp[2]; TH1* h1a[2], *h1b[2];
68 TH2* h2Real; TH2* h2Mc, *h2Contam;
69 TH1* h1Real; TH1* h1Mc, *h1Contam;
75 int nx[]={2,3};
int ny[]={3,4};
77 gStyle->SetOptStat(0); gStyle->SetOptLogy(1);
81 for(
int iPtRebin=0; iPtRebin<2; iPtRebin++){
83 for(
int iDcaType=0; iDcaType<nDcaType; iDcaType++){
84 for(
int ic=0;ic<nc;ic++){
86 sprintf(name,
"%s.h2%sPtPrRebin",sPM[ic].Data(),dcaType[iDcaType]);
89 h2Real=(TH2*)inRoot[0]->Get(name);
92 h2Mc=(TH2*)inRoot[1]->Get(name);
94 sprintf(name,
"%s.h2Contam%sPtPrRebin",
95 sPM[ic].Data(),dcaType[iDcaType]);
97 h2Contam=(TH2*)inRoot[1]->Get(name);
102 sprintf(name,
"Plus.h2%sPtPrRebin",
104 h2Real=(TH2*)inRoot[0]->Get(name);
105 sprintf(name,
"Minus.h2%sPtPrRebin",
106 dcaType[iDcaType],ptRebin[iPtRebin]);
107 h2temp=(TH2*)inRoot[0]->Get(name);
111 sprintf(name,
"Plus.h2%sPtPrRebin",
113 h2Mc=(TH2*)inRoot[1]->Get(name);
114 sprintf(name,
"Minus.h2%sPtPrRebin",
116 h2temp=(TH2*)inRoot[1]->Get(name);
120 sprintf(name,
"Plus.h2Contam%sPtPrRebin",
122 h2Contam=(TH2*)inRoot[1]->Get(name);
123 sprintf(name,
"Minus.h2Contam%sPtPrRebin",
125 h2temp=(TH2*)inRoot[1]->Get(name);
126 h2Contam->Add(h2temp);
128 cout <<
"### " << h2Real->GetName() << endl;
131 sprintf(title,
"bkg + signal%s %s (cut %d)",
132 dcaType[iDcaType],chargeType[ic],cut);
133 Divide(&c1,nx[iPtRebin],ny[iPtRebin],title,inName);
138 sprintf(title,
"h1Background%s%s%s",
139 dcaType[iDcaType],chargeType[ic],ptRebin[iPtRebin]);
141 TH1D* hb=
new TH1D(title,title,npt[iPtRebin],ptAry[iPtRebin]);
143 for(
int ipt=0;ipt<npt[iPtRebin];ipt++){
145 h1Real=HistSlice(h2Real,
"",
"",0,
146 ptAry[iPtRebin][ipt],ptAry[iPtRebin][ipt+1],
148 h1Mc=HistSlice(h2Mc,
"",
"",0,
149 ptAry[iPtRebin][ipt],ptAry[iPtRebin][ipt+1],
"x");
150 h1Contam=HistSlice(h2Contam,
"",
"",0,
151 ptAry[iPtRebin][ipt],ptAry[iPtRebin][ipt+1],
"x");
154 if(nDcaRebin[iDcaType]>1){
155 h1Real->Rebin(nDcaRebin[iDcaType]);
156 h1Mc->Rebin(nDcaRebin[iDcaType]);
157 h1Contam->Rebin(nDcaRebin[iDcaType]);
160 if(h1Real->GetNbinsX() != h1Mc->GetNbinsX()){
161 cout <<
"different bin widths? " << endl;
return;
174 if(show)cout << h1Real->GetTitle() << endl;
177 int lowBin = h1Contam->FindBin(bkgMin[iDcaType]);
178 int upBin = h1Contam->FindBin(bkgMax[iDcaType]-.0000001);
180 TAxis* axis=h1Contam->GetXaxis();
182 cout <<
"bkg region : " << axis->GetBinLowEdge(lowBin) <<
" -- "
183 << axis->GetBinUpEdge(upBin) << endl;
186 float badBkgCount = h1Contam->Integral(lowBin,upBin);
187 if(show)cout <<
"\tbad bkg count=" << badBkgCount << endl;
189 if(badBkgCount<1)
continue;
192 float allBadCount = h1Mc->Integral(lowBin,upBin);
194 if(show)cout <<
"\tall bad count=" << allBadCount << endl;
197 float fractionBkg = badBkgCount/allBadCount;
199 if(show)cout <<
"\tfraction bkg=" << fractionBkg << endl;
202 lowBin = h1Contam->FindBin(sigMin[iDcaType]);
203 upBin = h1Contam->FindBin(sigMax[iDcaType]-.0000001);
205 if(show)cout <<
"signal region : "
206 << axis->GetBinLowEdge(lowBin) <<
" -- "
207 << axis->GetBinUpEdge(upBin) << endl;
211 float signalBkgCount = h1Contam->Integral(lowBin,upBin);
212 if(show)cout <<
"\tsignal bkg count=" << signalBkgCount << endl;
214 float signalBkgOverBkg = signalBkgCount/badBkgCount;
216 if(show)cout <<
"\tsignal background/background="
217 << signalBkgOverBkg << endl;
220 lowBin = h1Real->FindBin(bkgMin[iDcaType]);
221 upBin = h1Real->FindBin(bkgMax[iDcaType]-.0000001);
223 axis = h1Real->GetXaxis();
224 if(show)cout <<
"real bkg region : "
225 << axis->GetBinLowEdge(lowBin) <<
" -- "
226 << axis->GetBinUpEdge(upBin) << endl;
229 float realBadCount =h1Real->Integral(lowBin,upBin);
230 if(show)cout <<
"\treal bad count=" << realBadCount << endl;
232 if(realBadCount<1)
continue;
235 float realSignalBkgCount = realBadCount*fractionBkg*signalBkgOverBkg;
236 if(show)cout <<
"\treal signal bkg=" << realSignalBkgCount << endl;
239 lowBin = h1Real->FindBin(sigMin[iDcaType]);
240 upBin = h1Real->FindBin(sigMax[iDcaType]-.0000001);
242 float bkgPlusSignal = h1Real->Integral(lowBin,upBin);
243 if(show)cout <<
"real bkg+sig=" << bkgPlusSignal << endl;
245 float bkgOverData=realSignalBkgCount/bkgPlusSignal;
247 if(show)cout <<
"fraction of bkg under signal region real="
248 << bkgOverData << endl;
250 hb->SetBinContent(ipt+1,bkgOverData);
253 h1Contam->SetFillColor(17);
255 if(h1Mc->Integral())h1Mc->Scale(1./h1Mc->Integral());
256 if(h1Contam->Integral())h1Contam->Scale(1./h1Contam->Integral());
257 if(h1Real->Integral())h1Real->Scale(1./h1Real->Integral());
260 h1Contam->Draw(
"same");
261 h1Real->SetMarkerStyle(8); h1Real->SetMarkerSize(0.6);
262 h1Real->Draw(
"esame");
269 Print(&c2,psDir,hb->GetName());
270 sprintf(name,
"contam%s%s%s",
271 dcaType[iDcaType],chargeType[ic],ptRebin[iPtRebin]);
272 Print(&c1,psDir,name);