StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StGlauberCumulantHistogramMaker.cxx
1 /******************************************************************************
2  * $Id: StGlauberCumulantHistogramMaker.cxx,v 1.2 2012/04/25 05:03:31 hmasui Exp $
3  * $Log: StGlauberCumulantHistogramMaker.cxx,v $
4  * Revision 1.2 2012/04/25 05:03:31 hmasui
5  * Use STAR logger
6  *
7 ******************************************************************************/
8 
9 #include <assert.h>
10 #include <fstream>
11 #include <vector>
12 
13 #include "StMessMgr.h"
14 
15 #include "TH1.h"
16 #include "TMath.h"
17 #include "TProfile.h"
18 
19 #include "StGlauberCumulantHistogramMaker.h"
20 
22 
23 using std::ofstream ;
24 using std::vector ;
25 
26 //____________________________________________________________________________________________________
27 StGlauberCumulantHistogramMaker::StGlauberCumulantHistogramMaker(const TString name, const TString title, const TString ytitle,
28  const Int_t ybin, const Double_t ymin, const Double_t ymax, const Bool_t isUnitWeight)
29  : StGlauberHistogramMaker(name, title, ytitle, ybin, ymin, ymax, isUnitWeight)
30 {
31  Init() ;
32 }
33 
34 //____________________________________________________________________________________________________
35 // Default destructor
36 StGlauberCumulantHistogramMaker::~StGlauberCumulantHistogramMaker()
37 {
38  Reset() ;
39 }
40 
41 //____________________________________________________________________________________________________
43 {
45 
47  for(UInt_t io=0; io<mNOrder; io++){
48  const UInt_t order = GetOrder(io);
49 
50  for(UInt_t ix=0; ix<GetNXaxis(); ix++){
51  // 1D (will be used later to store Profile/Weight)
52  TH1* h1D = (TH1D*) GetTH1D(Form("%s_%d", GetName().Data(), order), ix) ;
53  mHistogram1DCumulant[io].push_back( (TH1D*) h1D );
54 
55  // Profile
56  TProfile* hProfile = (TProfile*) GetTProfile(Form("%s_%d", GetName().Data(), order), ix, "Profile");
57  mProfileCumulant[io].push_back( (TProfile*) hProfile );
58  }
59 
60  // Print info.
61  for(vector<TProfile*>::iterator iter = mProfileCumulant[io].begin();
62  iter != mProfileCumulant[io].end(); iter++){
63  TProfile* h = (TProfile*) (*iter);
64  LOG_INFO << Form("StGlauberCumulantHistogramMaker::Init Initialize TProfile: %s (%s), x:(bin, min, max) = (%4d, %1.2f, %1.2f)",
65  h->GetName(), h->GetTitle(), h->GetNbinsX(), h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax())
66  << endm;
67  }
68 
69  }// cumulant order loop
70 
71 }
72 
73 //____________________________________________________________________________________________________
74 void StGlauberCumulantHistogramMaker::Reset()
75 {
77 
78  for(UInt_t io=0; io<mNOrder; io++){
79  mProfileCumulant[io].clear() ;
80  mHistogram1DCumulant[io].clear() ;
81  }
82 }
83 
84 //____________________________________________________________________________________________________
85 void StGlauberCumulantHistogramMaker::Fill(const Double_t y, const Double_t weight)
86 {
89 
91  for(UInt_t io=0; io<mNOrder; io++){
92  Double_t yval = y*y ;
93  if( io == 1 ) yval = y*y*y*y ;
94  if( io == 2 ) yval = y*y*y*y*y*y ;
95 
96  FillProfile(mProfileCumulant[io], yval*weight);
97  }
98 }
99 
100 
101 //____________________________________________________________________________________________________
103 {
106 
108  for(UInt_t io=0; io<mNOrder; io++){
109  DoWeightCorrection(mHistogram1DCumulant[io], mProfileCumulant[io]);
110  }
111 
113  LOG_INFO << "StGlauberCumulantHistogramMaker::Finish Calculate cumulant" << endm;
114 
115  for(UInt_t ix=0; ix<mHistogram1DCumulant[0].size(); ix++){
116  // Weight has already corrected, so this should contain val^{mOrder}
117  TH1* h1raw2 = (TH1D*) mHistogram1DCumulant[0][ix]->Clone() ;
118  TH1* h1raw4 = (TH1D*) mHistogram1DCumulant[1][ix]->Clone() ;
119  TH1* h1raw6 = (TH1D*) mHistogram1DCumulant[2][ix]->Clone() ;
120 
121  for(Int_t i=0; i<h1raw2->GetNbinsX(); i++){
122  const Double_t val[] = { h1raw2->GetBinContent(i+1), h1raw4->GetBinContent(i+1), h1raw6->GetBinContent(i+1) } ;
123  const Double_t err[] = { h1raw2->GetBinError(i+1), h1raw4->GetBinError(i+1), h1raw6->GetBinError(i+1) } ;
124 
125  for(Int_t io=0; io<mNOrder; io++){
126  const UInt_t order = GetOrder(io) ;
127  mHistogram1DCumulant[io][ix]->SetBinContent(i+1, GetCumulant(order, val));
128  mHistogram1DCumulant[io][ix]->SetBinError(i+1, GetCumulantError(order, val, err));
129  }// cumulant order loop
130  }
131 
132  delete h1raw2 ;
133  delete h1raw4 ;
134  delete h1raw6 ;
135  }// x-axis loop
136 
137  // Write table
138  for(Int_t io=0; io<mNOrder; io++){
139  const TString name(type + "_" + GetName()) ;
140  WriteTable(mHistogram1DCumulant[io], Form("%s_%d", name.Data(), GetOrder(io))) ;
141  }
142 
143  // Write graph
144  for(Int_t io=0; io<mNOrder; io++){
145  WriteGraphs(mHistogram1DCumulant[io]);
146  }
147 }
148 
149 //____________________________________________________________________________________________________
150 UInt_t StGlauberCumulantHistogramMaker::GetOrder(const UInt_t io) const
151 {
152  return (io+1)*2 ;
153 }
154 
155 //____________________________________________________________________________________________________
156 Double_t StGlauberCumulantHistogramMaker::Get4thOrderCumulant(const Double_t c2, const Double_t c4) const
157 {
158  const Double_t raw = 2.0*c2*c2 - c4 ;
159  const Double_t sign = (raw>0.0) ? 1.0 : -1.0 ;
160 
161  return TMath::Power(sign*raw, 0.25) ;
162 }
163 
164 //____________________________________________________________________________________________________
165 Double_t StGlauberCumulantHistogramMaker::Get6thOrderCumulant(const Double_t c2, const Double_t c4, const Double_t c6) const
166 {
167  const Double_t raw = 0.25*(c6 - 9.0*c4*c2 + 12.0*c2*c2*c2) ;
168  const Double_t sign = (raw>0.0) ? 1.0 : -1.0 ;
169 
170  return TMath::Power(sign*raw, 1.0/6.0) ;
171 }
172 
173 //____________________________________________________________________________________________________
174 Double_t StGlauberCumulantHistogramMaker::GetNthOrderCumulantError(const Double_t order, const Double_t val, const Double_t err) const
175 {
176  if( val == 0.0 ) return 0.0 ;
177 
178  return TMath::Abs(order) * TMath::Power(TMath::Abs(val), order-1.0) * err ;
179 }
180 
181 //____________________________________________________________________________________________________
182 Double_t StGlauberCumulantHistogramMaker::Get2ndOrderCumulantError(const Double_t c2, const Double_t c2error) const
183 {
184  return GetNthOrderCumulantError(0.5, c2, c2error) ;
185 }
186 
187 //____________________________________________________________________________________________________
188 Double_t StGlauberCumulantHistogramMaker::Get4thOrderCumulantError(const Double_t c2, const Double_t c4,
189  const Double_t c2error, const Double_t c4error) const
190 {
191  const Double_t cumulant = Get4thOrderCumulant(c2, c4) ;
192  const Double_t error = TMath::Sqrt(16.0*c2*c2*c2error*c2error + c4error*c4error) ;
193 
194  return GetNthOrderCumulantError(0.25, cumulant, error) ;
195 }
196 
197 //____________________________________________________________________________________________________
198 Double_t StGlauberCumulantHistogramMaker::Get6thOrderCumulantError(const Double_t c2, const Double_t c4, const Double_t c6,
199  const Double_t c2error, const Double_t c4error, const Double_t c6error) const
200 {
201  const Double_t cumulant = Get6thOrderCumulant(c2, c4, c6) ;
202  const Double_t error1 = (c4!=0.0 && c2!=0.0) ?
203  9.0 * TMath::Abs(c4*c2) * TMath::Sqrt(TMath::Power(c4error/c4, 2.0) + TMath::Power(c2error/c2, 2.0)) : 0.0;
204  const Double_t error2 = 12.0 * 3.0 * c2*c2*c2error ;
205  const Double_t error = 0.25 * TMath::Sqrt(c6error*c6error + error1*error1 + error2*error2) ;
206 
207  return GetNthOrderCumulantError(1.0/6.0, cumulant, error) ;
208 }
209 
210 //____________________________________________________________________________________________________
211 Double_t StGlauberCumulantHistogramMaker::GetCumulant(const UInt_t order, const Double_t* val) const
212 {
214  if(!val) return -9999. ;
215 
216  const Double_t invalid = -9999. ;
217 
218  switch ( order ){
219  case 2: // 2nd order cumulant
220  return (val[0]<0.0) ? invalid : TMath::Sqrt(val[0]) ;
221 
222  case 4: // 4th order cumulant
223  return Get4thOrderCumulant(val[0], val[1]) ;
224 
225  case 6: // 6th order cumulant
226  return Get6thOrderCumulant(val[0], val[1], val[2]) ;
227 
228  default:
229  Error("StGlauberCumulantHistogramMaker::GetCumulant", "Unknown order, order=%3d. abort", order);
230  assert(0);
231  }
232 
233  return -9999. ;
234 }
235 
236 //____________________________________________________________________________________________________
237 Double_t StGlauberCumulantHistogramMaker::GetCumulantError(const UInt_t order, const Double_t* val, const Double_t* err) const
238 {
240  if(!val) return -9999. ;
241  if(!err) return -9999. ;
242 
243  switch ( order ){
244  case 2: // 2nd order cumulant
245  return Get2ndOrderCumulantError(val[0], err[0]);
246 
247  case 4: // 4th order cumulant
248  return Get4thOrderCumulantError(val[0], val[1], err[0], err[1]) ;
249 
250  case 6: // 6th order cumulant
251  return Get6thOrderCumulantError(val[0], val[1], val[2], err[0], err[1], err[2]) ;
252 
253  default:
254  Error("StGlauberCumulantHistogramMaker::GetCumulantError", "Unknown order, order=%3d. abort", order);
255  assert(0);
256  }
257 
258  return -9999. ;
259 }
260 
261 
Definition: FJcore.h:367
void FillProfile(std::vector< TProfile * > collection, const Double_t y)
void WriteTable(std::vector< TH1 * > collection, const TString name)
Write text table, average quantity vs centrality (table: table_{mName}_vs_centrality.txt)
void DoWeightCorrection(std::vector< TH1 * > collection1d, std::vector< TProfile * > collectionp)
Calculate sum(w*val)/sum(w) for each profile histogram.
virtual void Reset()
Debug flag.
virtual void Fill(const Double_t y, const Double_t weight)
Set X-axis variable.
void Fill(const Double_t y, const Double_t weight)
Set X-axis variable.
UInt_t GetNXaxis() const
Naxis.
virtual void Finish(const TString type)
Fill histogram &#39;y&#39; value with &#39;weight&#39;.
void WriteGraphs(std::vector< TH1 * > collection)
Write TGraphErrors (vs centrality, 0-80%)