StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
centrality.C
1 /********************************************************************
2 
3 Author: Mike Daugherity
4 Description: This macro reads a dNevent/dNch distribution and finds arbitrary centrality bins
5  based on the number of analyzed tracks (surviving cuts) per event.
6  Assumes that we're taking output from doEStructEmpty.C
7 
8 
9 Finding Centrality Bins:
10 1) Fix all track and event cuts first, everything else depends on these.
11 2) Produce a histogram of dNevent/dNch with decent statistics using above cuts.
12  The fastest way is to run an 'empty' analysis (no pair analysis) using
13  doEStructEmpty.C. You can also use the NEventsSame plot from a standard
14  correlations analysis (rename the plot loaded into nev).
15 3) Set the bins (given a percent of cross-section) in the const cent[] array below.
16  Terminate this list with a -1.
17 4) Run this macro, the (text) output will show the number of tracks that corresponds
18  to each centrality bin division.
19 
20 **********************************************************************/
21 
22 void centrality(const char* infile) {
23 
24  tf = new TFile(infile);
25  TH1F* nev = tf->Get("hNEvent"); // load dN/dnch; change this line if not using output from doEStructEmpty.C
26  TH1F* hvar = tf->Get("hvar"); // a test to compare with, not used in centrality
27 
28  nev->SetBinContent(1,0); // make sure we have no events with zero mult.
29 
30  nev->Scale( 1.0/nev->Integral() );
31  hvar->Scale( 1.0/hvar->Integral("width") );
32 
33  float x1,y1,x2,y2;
34  float gx1[1199], gx2[1199], gy[1199];
35  for(int i=1; i<=nev->GetNbinsX(); i++) {
36  x1 = nev->GetBinLowEdge(i);
37  x2 = pow(x1, 0.25); // x2 = n^1/4
38  y1 = nev->GetBinContent(i);
39  y2 = pow(x1, 0.75)*y1; // y2 = n^3/4 * dNev/dNch
40  if (i>1) { gx1[i-2]=x1; gx2[i-2]=x2; gy[i-2]=y2; } // skipping 1st bin (nch=0)
41  }
42  TGraph* tg = new TGraph(1199, gx2,gy);
43 
44  float sum;
45  int num,i;
46 
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}; // centrality bins; don't erase the -1 !
48 
49  cout << "*** Using dN/dnch " << endl;
50  sum=0;
51  num=0;
52  float xint = 0;
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); // interpolate
61  cout << "Crossed " << cent[num] << " at " << nev->GetBinCenter(i);
62  cout << "\t\tInterpolated value = " << nev->GetBinLowEdge(i-1)+xint << endl;
63  num++;
64  }
65  }
66 
67  // Finds bins using several methods, eventually I choose just one....
68 
69  //cout << endl << "*** Using hvar" << endl;
70  //for(i=1; i<=hvar->GetNbinsX(); i++) hvar->SetBinContent(i, hvar->GetBinContent(i)*4*pow(hvar->GetBinLowEdge(i),3) );
71  hvar->Scale( 1.0/hvar->Integral("width") );
72  //c1->cd(2); hvar->Draw();
73  sum=0;
74  num=0;
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]) {
80  //cout << cent[num] << " at " << pow(hvar->GetBinCenter(i),4) << endl;
81  num++;
82  }
83  }
84 
85  cout << endl << "*** Using graph" << endl;
86  float gsum = 0;
87  for(i=0; i<1199-1; i++) gsum+= gy[i] * (gx2[i+1]-gx2[i]);
88  sum=0;
89  num=0;
90  float gyint[1199];
91  float xint; //interpolated value
92  for(i=0; i<1199-1; i++) {
93  sum += (gy[i]/gsum) * (gx2[i+1]-gx2[i]);
94  gyint[i]=sum;
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]);
97  else xint = 0;
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;
101  num++;
102  }
103  }
104  // I skipped the endpoints above to avoid i+1 boundary problems, need to correct for this
105  gyint[1198]=1.0;
106 
107  tgint = new TGraph(1199, gx2, gyint);
108  tgint2 = new TGraph(1199, gx1, gyint);
109 
110  /*
111  // single window output
112  c1 = new TCanvas(infile,infile, 700,700);
113  c1->Divide(2,2);
114  c1->GetPad(1)->SetLogy();
115  c1->cd(1); nev->Draw();
116  c1->cd(2); hvar->Draw();
117  c1->cd(3); tg->Draw("ALP");
118  c1->cd(4); tgint->Draw("ALP");
119  */
120 
121  // Multiple-window output
122  c1 = new TCanvas("c1","STAR Standard: dNevent/dnch",800,450);
123  c1->Divide(2,1);
124  c1->GetPad(1)->SetLogy();
125  c1->cd(1); nev->Draw();
126  nevint->SetStats(0);
127  c1->cd(2); nevint->Draw();
128 
129  c2 = new TCanvas("c2","dNevent/dnch^{1/4}", 900,350);
130  c2->Divide(3,1);
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");
135 
136  c3 = new TCanvas("c3","TEST: comparison with hvar",800,450);
137  c3->Divide(2,1);
138  c3->cd(1); hvar->Draw();
139  hvarint->SetStats(0);
140  c3->cd(2); hvarint->Draw();
141 
142  //c4 = new TCanvas();
143 
144 }