29 void doFlowSumAll(Int_t firstCenNo, Int_t lastCenNo,
char* dirName =
"", Int_t outputRunNo=99) {
36 char rootFileName[80];
38 char listFileName[80];
44 char logTitleCommand[80];
46 char firstPassCommand[80];
47 char secondPassCommand[80];
49 TFile* histFile[1000];
53 const char* baseName[] = {
60 "Flow_v2D_ScalarProd_",
61 "Flow_vEta_ScalarProd_",
62 "Flow_vPt_ScalarProd_",
64 "Flow_Cumul_vEta_Order2_",
65 "Flow_Cumul_vPt_Order2_",
66 "Flow_Cumul_v_Order2_",
67 "Flow_Cumul_vEta_Order4_",
68 "Flow_Cumul_vPt_Order4_",
69 "Flow_Cumul_v_Order4_",
87 sprintf(logOutName,
"ana%2d.log", outputRunNo);
88 sprintf(logTitle,
" Combination of centralities %2d to %2d", firstCenNo, lastCenNo);
89 sprintf(logTitleCommand,
"echo %s > %s", logTitle, logOutName);
90 system(logTitleCommand);
94 for (
int nc = firstCenNo; nc <= lastCenNo; nc++) {
95 sprintf(listFileName,
"root.files.%2d", nc);
97 sprintf(lsCommand,
"ls -1 outDir/%s*-%2d/flow.hist.root > %s", dirName, nc, listFileName);
99 sprintf(cpCommand,
"cat %s >> %s", listFileName, logOutName);
102 ascii_in.open(listFileName, ios::in);
104 while(!ascii_in.eof()) {
105 ascii_in >> rootFileName;
106 if (strstr(rootFileName,
".root")==0)
continue;
107 histFile[nFile] =
new TFile(rootFileName);
108 char* cp = strstr(rootFileName,
"flow.");
110 sprintf(firstPassCommand,
"test -f %sflowPhiWgtNew.hist.root", rootFileName);
111 sprintf(secondPassCommand,
"test -f %sflowPhiWgt.hist.root", rootFileName);
112 if (LYZ) sprintf(secondPassCommand,
"test -f %sflow.firstPassLYZNew.root", rootFileName);
114 sprintf(firstPassCommand,
"test -f %sflow.reCentAnaNew.root", rootFileName);
115 sprintf(secondPassCommand,
"test -f %sflow.reCentAna.root", rootFileName);
117 if (system(firstPassCommand) && system(secondPassCommand)) {
118 cout <<
"####################################" << endl;
119 cout <<
"### No 2nd pass for " << rootFileName << endl;
120 cout <<
"####################################" << endl;
121 delete histFile[nFile];
124 cout << nFile+1 <<
" directory name = " << rootFileName << endl;
125 sprintf(logFileName,
"%sana.log", rootFileName);
126 sprintf(logCommand,
"cat %s >> %s", logFileName, logOutName);
131 const Int_t nFiles = nFile;
133 cout <<
"input files: " << nFiles << endl;
135 cout <<
"#### no files" << endl;
139 TH2* yieldPartHist[nFiles];
141 TH1* yieldPartHistPt[nFiles];
142 TH1* yieldPartHistEta[nFiles];
143 Float_t yieldTotal[nFiles];
144 TH1* hist_r0theta[nSels][nHars];
147 sprintf(rootOutName,
"ana%2d.root", outputRunNo);
148 cout <<
" output file name = " << rootOutName << endl;
149 histFile[nFiles] =
new TFile(rootOutName,
"RECREATE");
150 cout <<
" log file name = " << logOutName << endl << endl;
157 const char* objName = 0;
158 TIter nextkey(histFile[0]->GetListOfKeys());
159 while ((key = (TKey*)nextkey())) {
162 obj = key->ReadObj();
163 if (obj->InheritsFrom(
"TH1")) {
165 objName = key->GetName();
166 cout <<
" hist name= " << objName << endl;
167 for (
int n = 1; n < nFiles; n++) {
168 hist[1] = (TH1*)histFile[n]->Get(objName);
169 hist[0]->Add(hist[1]);
172 histFile[nFiles]->cd();
179 for (
int n = 0; n < nFiles; n++) {
180 yieldPartHist[n] =
dynamic_cast<TH2*
>(histFile[n]->Get(
"Flow_YieldPart2D"));
181 yieldPartHistPt[n] =
dynamic_cast<TH1*
>(histFile[n]->Get(
"FlowLYZ_YieldPartPt"));
182 yieldPartHistEta[n] =
dynamic_cast<TH1*
>(histFile[n]->Get(
"FlowLYZ_YieldPartEta"));
183 if (yieldPartHistPt[n]) { yieldTotal[n] = yieldPartHistPt[n]->Integral(); }
186 cout << endl <<
"with weighting" << endl;
189 for (
int pageNumber = 0; pageNumber < nNames; pageNumber++ ) {
192 if (strstr(baseName[pageNumber],
"v2D")) twoD = kTRUE;
194 for (
int selN = 0; selN < nSels; selN++) {
197 bool noHars = kFALSE;
199 if (strstr(baseName[pageNumber],
"_v_")!=0 ||
200 strcmp(baseName[pageNumber],
"Flow_Cos_")==0 ||
201 strstr(baseName[pageNumber],
"Res")!=0 ||
202 strstr(baseName[pageNumber],
"_V_")!=0 ||
203 strstr(baseName[pageNumber],
"_vr0_")!=0) {
209 if (strstr(baseName[pageNumber],
"theta_")!=0) {
213 for (
int harN = 0; harN < nHar; harN++) {
216 TString histName(baseName[pageNumber]);
224 if (strstr(histName.Data(),
"_Gtheta") && harN > 1) {
continue; }
227 for (
int n = 0; n < nFiles+1; n++) {
228 hist[n] =
dynamic_cast<TH1*
>(histFile[n]->Get(histName));
230 if (pageNumber < nNames) {
235 cout <<
"*** Error: Correct nNames in macro" << endl;
238 cout <<
" hist name= " << histName << endl;
243 if (strstr(histName.Data(),
"r0theta")) {
244 hist_r0theta[selN][harN] =
dynamic_cast<TH1*
>(histFile[nFiles]->Get(histName));
248 if (!hist[0]) {
continue; }
250 int xBins = hist[0]->GetNbinsX();
253 yBins = hist[0]->GetNbinsY();
254 nBins = xBins + (xBins + 2) * yBins;
255 float yMax = hist[0]->GetXaxis()->GetXmax();
256 float yMin = hist[0]->GetXaxis()->GetXmin();
257 yieldY =
new TH1F(
"Yield_Y",
"Yield_Y", xBins, yMin, yMax);
258 yieldY->SetXTitle(
"Rapidity");
259 yieldY->SetYTitle(
"Counts");
260 float ptMax = hist[0]->GetYaxis()->GetXmax();
261 yieldPt =
new TH1F(
"Yield_Pt",
"Yield_Pt", yBins, 0., ptMax);
262 yieldPt->SetXTitle(
"Pt (GeV/c)");
263 yieldPt->SetYTitle(
"Counts");
269 if (strstr(baseName[pageNumber],
"LYZ")) {
270 cout <<
" with LYZ yield weighted averaging" << endl;
271 double v, yield, content, error, Vtheta, VthetaErr, r0, r0Err;
272 double vSum, v2Sum, error2Sum, yieldSum, yieldSum2, yield2Sum;
274 for (
int bin = 1; bin < nBins-1; bin++) {
284 for (
int n = 0; n < nFiles; n++) {
286 if (strstr(histName.Data(),
"vEta")) {
287 yield = yieldPartHistEta[n]->GetBinContent(bin);
288 }
else if (strstr(histName.Data(),
"vPt")) {
289 yield = yieldPartHistPt[n]->GetBinContent(bin);
291 yield = yieldTotal[n];
293 v = hist[n]->GetBinContent(bin);
294 if (v != 0 && yield > 1.) {
296 yield2Sum += yield*yield;
298 v2Sum += yield * v*v;
299 error2Sum += pow(yield * hist[n]->GetBinError(bin), 2.);
304 content = vSum / yieldSum;
306 yieldSum2 = yieldSum*yieldSum;
307 yield2Sum /= yieldSum2;
308 error2Sum /= yieldSum2;
309 if (strstr(baseName[pageNumber],
"_G")) {
311 }
else if (nFiles > 1 && yield2Sum != 1.) {
312 error = sqrt(error2Sum + (v2Sum - content*content) / (1/yield2Sum - 1));
314 error = sqrt(error2Sum);
316 if (strstr(histName.Data(),
"v")) {
321 hist[nFiles]->SetBinContent(bin, content);
322 hist[nFiles]->SetBinError(bin, error);
323 if (strstr(histName.Data(),
"Vtheta")) {
325 Vtheta = hist[nFiles]->GetBinContent(bin);
326 VthetaErr = hist[nFiles]->GetBinError(bin);
327 if (VthetaErr > 0.001) {
330 r0 = Vtheta ? j01 / Vtheta : 0.;
331 r0Err = Vtheta ? r0 * VthetaErr / Vtheta : 0.;
333 hist_r0theta[selN][harN]->SetBinContent(bin, r0);
334 hist_r0theta[selN][harN]->SetBinError(bin, r0Err);
339 }
else if ((strstr(baseName[pageNumber],
"Cos")) ||
340 (strstr(baseName[pageNumber],
"Res"))) {
341 cout <<
" With error weighting" << endl;
342 double content, error, errorSq, meanContent, meanError, weight;
343 for (
int bin = 0; bin < nBins; bin++) {
347 for (
int n = 0; n < nFiles; n++) {
349 content = hist[n]->GetBinContent(bin);
350 error = hist[n]->GetBinError(bin);
351 errorSq = error * error;
353 meanContent += content / errorSq;
354 weight += 1. / errorSq;
359 meanContent /= weight;
360 meanError = sqrt(1. / weight);
361 hist[nFiles]->SetBinContent(bin, meanContent);
362 hist[nFiles]->SetBinError(bin, meanError);
366 cout <<
" with yield weighted averaging" << endl;
367 double v, yield, content, error, y, pt;
368 double vSum, error2sum, yieldSum;
369 for (
int bin = 0; bin < nBins; bin++) {
377 for (
int n = 0; n < nFiles; n++) {
379 if (strstr(histName.Data(),
"v2D")) {
380 yield = yieldPartHist[n]->GetBinContent(bin);
381 }
else if (strstr(histName.Data(),
"vEta")) {
382 yield = yieldPartHist[n]->Integral(bin, bin, 1, yBins);
383 if (selN==0 && harN==0) {
384 y = yieldPartHist[n]->GetXaxis()->GetBinCenter(bin);
385 yieldY->Fill(y, yield);
387 }
else if (strstr(histName.Data(),
"vPt")) {
388 yield = yieldPartHist[n]->Integral(1, xBins, bin, bin);
389 if (selN==0 && harN==0) {
390 pt = yieldPartHist[n]->GetYaxis()->GetBinCenter(bin);
391 yieldPt->Fill(pt, yield);
394 yield = yieldPartHist[n]->Integral();
396 v = hist[n]->GetBinContent(bin);
397 if (v != 0. && yield > 1.) {
400 error2sum += pow(yield * hist[n]->GetBinError(bin), 2.);
405 content = vSum / yieldSum;
406 error = sqrt(error2sum) / yieldSum;
408 hist[nFiles]->SetBinContent(bin, content);
409 hist[nFiles]->SetBinError(bin, error);
419 histFile[nFiles]->Write(0, TObject::kOverwrite);
420 histFile[nFiles]->Close();
421 delete histFile[nFiles];
422 sprintf(rmCommand,
"rm %s", listFileName);