13 #include "TGraphErrors.h"
18 #include "StMessMgr.h"
21 #include "StCentralityMaker/StCentralityMaker.h"
22 #include "StCentralityMaker/StCentrality.h"
23 #include "StGlauberConstUtilities.h"
24 #include "StGlauberTree/StGlauberTree.h"
25 #include "StGlauberHistogramMaker.h"
34 const TString StGlauberHistogramMaker::mXAxisTitle[] = {
"impact parameter (fm)",
"N_{part}",
"multiplicity",
"centrality (%)" };
35 const Int_t StGlauberHistogramMaker::mXAxisBin[] = {
39 StGlauberConstUtilities::GetCentralityBin()
43 const Double_t StGlauberHistogramMaker::mXAxisMax[] = {
47 StGlauberConstUtilities::GetCentralityBin()
52 StGlauberHistogramMaker::StGlauberHistogramMaker()
53 : mName(
"hTest"), mTitle(
"Test"), mYTitle(
"Test"), mYbin(1), mYmin(0), mYmax(1), mIsUnitWeight(kTRUE)
60 StGlauberHistogramMaker::StGlauberHistogramMaker(
const TString name,
const TString title,
const TString ytitle,
61 const Int_t ybin,
const Double_t ymin,
const Double_t ymax,
const Bool_t isUnitWeight)
62 : mName(name), mTitle(title), mYTitle(ytitle), mYbin(ybin), mYmin(ymin), mYmax(ymax), mIsUnitWeight(isUnitWeight)
69 StGlauberHistogramMaker::~StGlauberHistogramMaker()
77 mTableDirectory = directory ;
78 LOG_INFO <<
"StGlauberHistogramMaker::SetTableDirectory Set output directory for table : "
79 << mTableDirectory.Data() << endm;
91 for(UInt_t ix=0; ix<mNXaxis; ix++){
92 mXaxis.push_back( -9999.0 );
96 for(UInt_t ix=0; ix<mNXaxis; ix++){
99 TH1* h1D = (TH1D*) GetTH1D(mName, ix) ;
100 mHistogram1D.push_back( (TH1D*) h1D );
103 TH2* h2D = (TH2D*) GetTH2D(mName, ix) ;
104 mHistogram2D.push_back( (TH2D*) h2D );
107 TProfile* hProfile = (TProfile*) GetTProfile(mName, ix,
"Profile");
108 mProfile.push_back( (TProfile*) hProfile );
111 TProfile* hWeight = (TProfile*) GetTProfile(mName, ix,
"Weight");
112 mWeight.push_back( (TProfile*) hWeight);
116 for(vector<TProfile*>::iterator iter = mProfile.begin();
117 iter != mProfile.end(); iter++){
118 TProfile* h = (TProfile*) (*iter);
119 LOG_INFO << Form(
"StGlauberHistogramMaker::Init Initialize TProfile: %s (%s), x:(bin, min, max) = (%4d, %1.2f, %1.2f)",
120 h->GetName(), h->GetTitle(), h->GetNbinsX(), h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax())
128 mHistogram1D.clear();
129 mHistogram2D.clear();
139 mXaxis[0] = tree.GetB() ;
140 mXaxis[1] = tree.GetNpart() ;
143 mXaxis[2] = tree.GetMultiplicity() ;
147 if( type.CompareTo(
"smalltotal", TString::kIgnoreCase) == 0 ) mode = 1 ;
148 else if( type.CompareTo(
"largetotal", TString::kIgnoreCase) == 0 ) mode = 2 ;
150 const StCentrality* centrality = centralityMaker.GetCentrality() ;
153 LOG_INFO << Form(
"StGlauberHistogramMaker::SetXaxis mult=%6d, centrality: (default, -5%, +5%) = (%1.1f, %1.1f, %1.1f)",
154 static_cast<Int_t>(mXaxis[2]),
167 UInt_t isXaxisBad = 0 ;
169 for(vector<Double_t>::const_iterator iter=mXaxis.begin(); iter != mXaxis.end(); iter++){
170 if( (*iter) == -9999. ) isXaxisBad++ ;
173 return (isXaxisBad==0) ? kTRUE : kFALSE ;
180 if( mXaxis.size() != collection.size() ){
181 Error(
"StGlauberHistogramMaker::Fill2D", Form(
"Array size is different: (x-axis, 2D) = (%3d, %3d)",
182 mXaxis.size(), collection.size()));
186 for(UInt_t ix=0; ix<collection.size(); ix++){
187 TH2* h = (TH2D*) collection[ix] ;
188 const TString name(h->GetName());
191 if( name.Contains(
"cent") ){
192 const Double_t centrality = mXaxis[ix] ;
195 for(Int_t icent=0; icent<h->GetNbinsX(); icent++){
197 if(StGlauberConstUtilities::IsCentralityOk(icent, centrality)){
198 h->Fill(icent+0.5, y, weight);
204 h->Fill(mXaxis[ix], y, weight);
213 if( mXaxis.size() != collection.size() ){
214 Error(
"StGlauberHistogramMaker::FillProfile", Form(
"Array size is different: (x-axis, Weight) = (%3d, %3d)",
215 mXaxis.size(), collection.size()));
219 for(UInt_t ix=0; ix<collection.size(); ix++){
220 TProfile* h = (TProfile*) collection[ix] ;
221 const TString name(h->GetName());
224 if( name.Contains(
"cent") ){
225 const Double_t centrality = mXaxis[ix] ;
228 for(Int_t icent=0; icent<h->GetNbinsX(); icent++){
230 if(StGlauberConstUtilities::IsCentralityOk(icent, centrality)){
237 h->Fill(mXaxis[ix], y);
254 if( type.CompareTo(
"2d", TString::kIgnoreCase) == 0 ){
255 Fill2D(mHistogram2D, y, weight) ;
257 else if ( type.CompareTo(
"profile", TString::kIgnoreCase) == 0 ){
260 else if ( type.CompareTo(
"weight", TString::kIgnoreCase) == 0 ){
264 Error(
"StGlauberHistogramMaker::Fill",
"Unknown option, option=%s", type.Data());
278 Error(
"StGlauberHistogramMaker::Fill",
"x-axis has not defined yet for %s", mName.Data());
284 Fill(
"profile", y, weight);
285 Fill(
"weight", y, weight) ;
293 LOG_INFO << Form(
"StGlauberHistogramMaker::DoWeightCorrection %s: particle-wise weight correction, profile/weight",
294 mName.Data()) << endm;
296 for(UInt_t ix=0; ix<collectionp.size(); ix++){
297 TH1* h1 = collection1d[ix] ;
300 TH1* p1 = (TH1D*) collectionp[ix]->ProjectionX();
301 TH1* w1 = (TH1D*) mWeight[ix]->ProjectionX();
304 p1->SetXTitle(h1->GetXaxis()->GetTitle());
305 p1->SetYTitle(h1->GetXaxis()->GetTitle());
308 p1->SetMinimum(mYmin);
309 p1->SetMaximum(mYmax);
312 for(Int_t i=0; i<p1->GetNbinsX(); i++){
313 collection1d[ix]->SetBinContent(i+1, p1->GetBinContent(i+1));
314 collection1d[ix]->SetBinError(i+1, p1->GetBinError(i+1));
316 collection1d[ix]->SetEntries(p1->GetEntries());
317 collection1d[ix]->Print() ;
328 const TString tableName(Form(
"%s/table_%s_vs_centrality.txt",
329 mTableDirectory.Data(), name.Data()));
330 ofstream fout(tableName.Data());
331 LOG_INFO <<
"StGlauberHistogramMaker::WriteTable Write table " << tableName.Data() << endm;
333 const UInt_t centId = 3 ;
334 for(UInt_t ic=0; ic<StGlauberConstUtilities::GetCentralityBin(); ic++){
335 const Double_t val = collection[centId]->GetBinContent(ic+1);
336 const Double_t error = collection[centId]->GetBinError(ic+1);
338 const Double_t centmin = StGlauberConstUtilities::GetCentralityMin(ic) ;
339 const Double_t centmax = StGlauberConstUtilities::GetCentralityMax(ic) ;
340 fout << Form(
"%10d %1.1f %1.1f %1.5f %1.5f",
341 ic, centmin, centmax, val, error) << endl;
343 fout << endl << endl ;
344 fout <<
"# <centrality bin> <minimum centrality> <maximum centrality> <value> <stat. error>" << endl;
345 fout << Form(
"# %s", mTitle.Data()) << endl;
352 const UInt_t centId = 3;
354 TGraphErrors* graph =
new TGraphErrors() ;
356 TString name(collection[centId]->GetName());
357 name.Replace(0, 1,
"graph");
358 graph->SetName(name);
359 graph->SetTitle(collection[centId]->GetTitle());
361 LOG_INFO << Form(
"StGlauberHistogramMaker::WriteGraphs Write graph %s (vs centrality)", graph->GetName()) << endm;
364 const UInt_t ncentrality = 9 ;
365 for(UInt_t ic=0; ic<ncentrality; ic++){
366 const Double_t centmin = StGlauberConstUtilities::GetCentralityMin(ic) ;
367 const Double_t centmax = StGlauberConstUtilities::GetCentralityMax(ic) ;
369 const Double_t cent = ( centmin + centmax)/2.0 ;
370 const Double_t val = collection[centId]->GetBinContent(ic+1) ;
371 const Double_t err = collection[centId]->GetBinError(ic+1) ;
372 graph->SetPoint(ic, cent, val);
373 graph->SetPointError(ic, 0.0, err);
384 LOG_INFO <<
"StGlauberHistogramMaker::Finish ";
385 LOG_INFO << Form(
"Finish %s. Correction weight for TProfile, ", mName.Data());
386 LOG_INFO <<
"and store it into 1D. Write averate qunatity vs centrality" << endm;
392 const TString name(type +
"_" + mName);
400 const TString StGlauberHistogramMaker::GetHistogramName(
const TString name,
const UInt_t ix)
const
402 return Form(
"%s_%s", name.Data(), mXAxisName[ix].Data());
406 TH1* StGlauberHistogramMaker::GetTH1D(
const TString name,
const UInt_t ix)
408 TH1* h =
new TH1D(
"g" + GetHistogramName(name, ix),
409 Form(
"%s vs %s, %s", mYTitle.Data(), mXAxisTitle[ix].Data(), mTitle.Data()), mXAxisBin[ix], 0.0, mXAxisMax[ix]);
410 h->SetXTitle(mXAxisTitle[ix].Data());
411 h->SetYTitle(mYTitle.Data());
417 TH2* StGlauberHistogramMaker::GetTH2D(
const TString name,
const UInt_t ix)
419 TH2* h =
new TH2D(
"h" + GetHistogramName(name, ix),
420 Form(
"%s vs %s, %s (2D)", mYTitle.Data(), mXAxisTitle[ix].Data(), mTitle.Data()),
421 mXAxisBin[ix], 0.0, mXAxisMax[ix], mYbin, mYmin, mYmax);
422 h->SetXTitle(mXAxisTitle[ix].Data());
423 h->SetYTitle(mYTitle.Data());
429 TProfile* StGlauberHistogramMaker::GetTProfile(
const TString name,
const UInt_t ix,
const TString title)
431 const TString prefix = (title.CompareTo(
"profile", TString::kIgnoreCase)==0) ?
"p" :
"w" ;
432 TProfile* h =
new TProfile(prefix + GetHistogramName(name, ix),
433 Form(
"%s vs %s, %s (%s)", mYTitle.Data(), mXAxisTitle[ix].Data(), mTitle.Data(), title.Data()), mXAxisBin[ix], 0.0, mXAxisMax[ix]);
434 h->SetXTitle(mXAxisTitle[ix].Data());
435 h->SetYTitle(mYTitle.Data());
441 const TString StGlauberHistogramMaker::GetName()
const
450 LOG_INFO <<
"StGlauberHistogramMaker::DebugOn Print debug messages" << endm;
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 SetTableDirectory(const TString directory)
Default destructor.
void SetXaxis(const StGlauberTree &tree, const StCentralityMaker ¢ralityMaker, const TString type)
Initialize histograms.
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 DebugOn()
Get histogram name.
void Fill2D(std::vector< TH2 * > collection, const Double_t y, const Double_t weight)
Check xAxis has been filled, abort if empty.
virtual void Finish(const TString type)
Fill histogram 'y' value with 'weight'.
Bool_t IsXaxisOk() const
Reset all data members.
Double_t GetCentrality(const UInt_t multiplicity, const UInt_t mode=0) const
Print help messages.
void Init()
Default destructor.
void WriteGraphs(std::vector< TH1 * > collection)
Write TGraphErrors (vs centrality, 0-80%)