22 void centrality(
const char* infile) {
24 tf =
new TFile(infile);
25 TH1F* nev = tf->Get(
"hNEvent");
26 TH1F* hvar = tf->Get(
"hvar");
28 nev->SetBinContent(1,0);
30 nev->Scale( 1.0/nev->Integral() );
31 hvar->Scale( 1.0/hvar->Integral(
"width") );
34 float gx1[1199], gx2[1199], gy[1199];
35 for(
int i=1; i<=nev->GetNbinsX(); i++) {
36 x1 = nev->GetBinLowEdge(i);
38 y1 = nev->GetBinContent(i);
39 y2 = pow(x1, 0.75)*y1;
40 if (i>1) { gx1[i-2]=x1; gx2[i-2]=x2; gy[i-2]=y2; }
42 TGraph* tg =
new TGraph(1199, gx2,gy);
47 const float cent[]={0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.05, -1};
49 cout <<
"*** Using dN/dnch " << endl;
53 float width = nev->GetBinWidth(1);
54 TH1F* nevint = nev->Clone(
"nevint");
55 for(i=1; i<=nev->GetNbinsX(); i++) {
56 sum+=nev->GetBinContent(i);
57 nevint->SetBinContent(i,sum);
58 if(1-sum<=cent[num]) {
59 y2 = nev->GetBinContent(i-1);
60 xint = (1-cent[num]-y2)*width/(sum-y2);
61 cout <<
"Crossed " << cent[num] <<
" at " << nev->GetBinCenter(i);
62 cout <<
"\t\tInterpolated value = " << nev->GetBinLowEdge(i-1)+xint << endl;
71 hvar->Scale( 1.0/hvar->Integral(
"width") );
75 TH1F* hvarint = hvar->Clone(
"hvarint");
76 for(i=1; i<=hvar->GetNbinsX(); i++) {
77 sum+=hvar->GetBinContent(i) * hvar->GetBinWidth(i);
78 hvarint->SetBinContent(i,sum);
79 if(1-sum<=cent[num]) {
85 cout << endl <<
"*** Using graph" << endl;
87 for(i=0; i<1199-1; i++) gsum+= gy[i] * (gx2[i+1]-gx2[i]);
92 for(i=0; i<1199-1; i++) {
93 sum += (gy[i]/gsum) * (gx2[i+1]-gx2[i]);
95 if(1-sum<=cent[num]) {
96 if (i>0) xint = (1-cent[num]-gyint[i-1])*(gx1[i]-gx1[i-1])/(gyint[i]-gyint[i-1]);
98 int foo = (int)(xint + 0.5);
99 cout <<
"Crossed " << cent[num] <<
" at " << gx1[i];
100 cout <<
"\t\tInterpolated value = " << gx1[i-1]+xint << endl;
107 tgint =
new TGraph(1199, gx2, gyint);
108 tgint2 =
new TGraph(1199, gx1, gyint);
122 c1 =
new TCanvas(
"c1",
"STAR Standard: dNevent/dnch",800,450);
124 c1->GetPad(1)->SetLogy();
125 c1->cd(1); nev->Draw();
127 c1->cd(2); nevint->Draw();
129 c2 =
new TCanvas(
"c2",
"dNevent/dnch^{1/4}", 900,350);
131 tg->SetMarkerStyle(7);
132 c2->cd(1); tg->Draw(
"ALP");
133 c2->cd(2); tgint->Draw(
"ALP");
134 c2->cd(3); tgint2->Draw(
"ALP");
136 c3 =
new TCanvas(
"c3",
"TEST: comparison with hvar",800,450);
138 c3->cd(1); hvar->Draw();
139 hvarint->SetStats(0);
140 c3->cd(2); hvarint->Draw();