1 #include "commonmacro/common.h"
2 #include "common/Name.cc"
3 #include "commonmacro/histutil.h"
5 void compareVertex(
const char* inName=
6 "links/P01hi.minbias.2000.hist/hianalysis_1000.hist.root",
7 const char* psDir=
"ps",
9 const char* outDir=
"./",
10 const char* more =
"embeddingfile",
15 gSystem->Load(
"StHiMicroEvent");
16 gSystem->Load(
"StHiMicroAnalysis");
18 TFile* inRoot =
new TFile(inName);
23 else if(extraValue>0){
26 char* trigger = (s.Contains(
"central")) ?
"central" :
"minbias";
27 sprintf(name,
"~/wrk/assoc/links/P01hi.central.HighpT_piminus_%d.hist/assoc_cut%d.hist.root",(
int)extraValue,cut);
30 cout <<
"Unknown embed file" << endl;
return;
32 embedRoot =
new TFile(name);
34 cout <<
"--------------------------" << endl;
35 cout <<
"in name=" << inName << endl
36 <<
"ps dir=" << psDir << endl
37 <<
"cut=" << cut << endl
38 <<
"embed name=" << name << endl;
39 cout <<
"--------------------------" << endl;
42 cout <<
"cannot find the infile" << endl;
46 cout <<
"cannot find " << more << endl;
50 h1[0]=(TH1*)inRoot.Get(
"h1VtxZCentCut");
51 h1[1]=(TH1*)embedRoot.Get(
"h1VtxZCentCut");
52 if(!h1[0] || !h1[1]) { cout <<
"cannot find histo" << endl;
return; }
55 h1[0]->Rebin(nrebin); h1[1]->Rebin(nrebin);
58 char* type[] = {
"real",
"embed"};
60 TCanvas c1(
"c1",
"c1",400,500);
62 float minZ=-80,maxZ=80;
64 gStyle->SetOptStat(0);
66 TLegend l(0.15,0.65,0.25,0.85);
67 l.SetFillColor(kWhite); l.SetBorderSize(0);
69 int lowBin=h1[0]->GetXaxis()->FindBin(minZ);
70 int upBin =h1[1]->GetXaxis()->FindBin(maxZ-0.0001);
73 sprintf(title,
"vertexZ (cut %d)",cut);
74 Divide(&c1,1,2,title,inName);
75 for(
int i=0; i<2; i++){
76 c1.cd(i+1); h1[i]->SetTitle(title); h1[i]->Draw();
77 PrintMeanRms(h1[i],0.7,0.8);
79 Print(&c1,psDir,
"vertexZ");
82 sprintf(title,
"vertex z scaled (cut %d)",cut);
83 Divide(&c1,1,2,title,inName);
84 c1.cd(1); ha=(TH1*)h1[0]->Clone(); hb=(TH1*)h1[1]->Clone();
85 ha->SetTitle(
"scaled");
86 ha->Scale(1./ha->Integral());
87 hb->Scale(1./hb->Integral());
88 ha->SetMarkerStyle(4); hb->SetMarkerStyle(8);
89 ha->Draw(
"p"); hb->Draw(
"psame");
90 l.AddEntry(ha,
"real",
"p"); l.AddEntry(hb,
"embed",
"p"); l.Draw();
92 c1.cd(2); ha=(TH1*)h1[0]->Clone(); hb=(TH1*)h1[1]->Clone();
93 ha->SetTitle(
"weighted");
94 cout <<
"min = " << ha->GetXaxis()->GetBinLowEdge(lowBin)
95 <<
",max = " << ha->GetXaxis()->GetBinUpEdge(upBin) << endl;
97 double realPeak = ha->Integral(lowBin,upBin);
98 double realOut = ha->Integral()-realPeak;
99 double realFrac = realPeak/realOut;
100 double embedPeak = hb->Integral(lowBin,upBin);
101 double embedOut = hb->Integral()-hb->Integral(lowBin,upBin);
102 double embedFrac = embedPeak/embedOut;
103 double weight=realFrac/embedFrac;
105 cout <<
"real frac="<<realFrac <<
", embedFrac="<<embedFrac
106 <<
", weight = " << weight << endl;
107 for(
int i=lowBin;i<=upBin;i++){
108 hb->SetBinContent(i,hb->GetBinContent(i)*weight);
111 ha->Scale(1./ha->Integral()); hb->Scale(1./hb->Integral());
112 ha->SetMarkerStyle(4); hb->SetMarkerStyle(8);
113 ha->Draw(
"p"); hb->Draw(
"psame");
114 sprintf(name,
"weight %.2f",weight); t->DrawTextNDC(0.15,0.75,name);
116 Print(&c1,psDir,
"vertexZScaled");