00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020 #include <iostream.h>
00021 #include <fstream.h>
00022 #include "TObject.h"
00023 #include "TH1.h"
00024 #include "TH2.h"
00025 #include "TFile.h"
00026 #include "TKey.h"
00027 #include "TChain.h"
00028
00029 void doFlowSumAll(Int_t firstCenNo, Int_t lastCenNo, char* dirName = "", Int_t outputRunNo=99) {
00030
00031 const int nSels = 2;
00032 const int nHars = 4;
00033 bool LYZ = kFALSE;
00034 bool reCent = kFALSE;
00035
00036 char rootFileName[80];
00037 char logFileName[80];
00038 char listFileName[80];
00039 char rootOutName[80];
00040 char logOutName[80];
00041 char logTitle[80];
00042 char lsCommand[80];
00043 char cpCommand[80];
00044 char logTitleCommand[80];
00045 char logCommand[80];
00046 char firstPassCommand[80];
00047 char secondPassCommand[80];
00048 char rmCommand[80];
00049 TFile* histFile[1000];
00050 Float_t j01 = 2.405;
00051
00052
00053 const char* baseName[] = {
00054 "Flow_Res_",
00055 "Flow_v2D_",
00056 "Flow_vEta_",
00057 "Flow_vPt_",
00058 "Flow_v_",
00059 "Flow_q_",
00060 "Flow_v2D_ScalarProd_",
00061 "Flow_vEta_ScalarProd_",
00062 "Flow_vPt_ScalarProd_",
00063 "Flow_v_ScalarProd_",
00064 "Flow_Cumul_vEta_Order2_",
00065 "Flow_Cumul_vPt_Order2_",
00066 "Flow_Cumul_v_Order2_",
00067 "Flow_Cumul_vEta_Order4_",
00068 "Flow_Cumul_vPt_Order4_",
00069 "Flow_Cumul_v_Order4_",
00070 "FlowLYZ_r0theta_",
00071 "FlowLYZ_Vtheta_",
00072 "FlowLYZ_V_",
00073 "FlowLYZ_vr0_",
00074 "FlowLYZ_vEta_",
00075 "FlowLYZ_vPt_",
00076 "FlowLYZ_v_",
00077 "FlowLYZ_Gtheta0_",
00078 "FlowLYZ_Gtheta1_",
00079 "FlowLYZ_Gtheta2_",
00080 "FlowLYZ_Gtheta3_",
00081 "FlowLYZ_Gtheta4_"
00082 };
00083
00084 const int nNames = 6;
00085
00086
00087 sprintf(logOutName, "ana%2d.log", outputRunNo);
00088 sprintf(logTitle, " Combination of centralities %2d to %2d", firstCenNo, lastCenNo);
00089 sprintf(logTitleCommand, "echo %s > %s", logTitle, logOutName);
00090 system(logTitleCommand);
00091
00092
00093 Int_t nFile = 0;
00094 for (int nc = firstCenNo; nc <= lastCenNo; nc++) {
00095 sprintf(listFileName, "root.files.%2d", nc);
00096
00097 sprintf(lsCommand, "ls -1 outDir/%s*-%2d/flow.hist.root > %s", dirName, nc, listFileName);
00098 system(lsCommand);
00099 sprintf(cpCommand, "cat %s >> %s", listFileName, logOutName);
00100 system(cpCommand);
00101 fstream ascii_in;
00102 ascii_in.open(listFileName, ios::in);
00103
00104 while(!ascii_in.eof()) {
00105 ascii_in >> rootFileName;
00106 if (strstr(rootFileName,".root")==0) continue;
00107 histFile[nFile] = new TFile(rootFileName);
00108 char* cp = strstr(rootFileName, "flow.");
00109 if (cp) *cp = '\0';
00110 sprintf(firstPassCommand, "test -f %sflowPhiWgtNew.hist.root", rootFileName);
00111 sprintf(secondPassCommand, "test -f %sflowPhiWgt.hist.root", rootFileName);
00112 if (LYZ) sprintf(secondPassCommand, "test -f %sflow.firstPassLYZNew.root", rootFileName);
00113 if (reCent) {
00114 sprintf(firstPassCommand, "test -f %sflow.reCentAnaNew.root", rootFileName);
00115 sprintf(secondPassCommand, "test -f %sflow.reCentAna.root", rootFileName);
00116 }
00117 if (system(firstPassCommand) && system(secondPassCommand)) {
00118 cout << "####################################" << endl;
00119 cout << "### No 2nd pass for " << rootFileName << endl;
00120 cout << "####################################" << endl;
00121 delete histFile[nFile];
00122 continue;
00123 }
00124 cout << nFile+1 << " directory name = " << rootFileName << endl;
00125 sprintf(logFileName, "%sana.log", rootFileName);
00126 sprintf(logCommand, "cat %s >> %s", logFileName, logOutName);
00127 system(logCommand);
00128 nFile++;
00129 }
00130 }
00131 const Int_t nFiles = nFile;
00132 cout << endl;
00133 cout << "input files: " << nFiles << endl;
00134 if (!nFiles) {
00135 cout << "#### no files" << endl;
00136 return;
00137 }
00138
00139 TH2* yieldPartHist[nFiles];
00140 TH1* hist[nFiles+1];
00141 TH1* yieldPartHistPt[nFiles];
00142 TH1* yieldPartHistEta[nFiles];
00143 Float_t yieldTotal[nFiles];
00144 TH1* hist_r0theta[nSels][nHars];
00145
00146
00147 sprintf(rootOutName, "ana%2d.root", outputRunNo);
00148 cout << " output file name = " << rootOutName << endl;
00149 histFile[nFiles] = new TFile(rootOutName, "RECREATE");
00150 cout << " log file name = " << logOutName << endl << endl;
00151
00152
00153
00154
00155 TKey* key;
00156 TObject* obj;
00157 const char* objName = 0;
00158 TIter nextkey(histFile[0]->GetListOfKeys());
00159 while ((key = (TKey*)nextkey())) {
00160 histFile[0]->cd();
00161
00162 obj = key->ReadObj();
00163 if (obj->InheritsFrom("TH1")) {
00164 hist[0] = (TH1*)obj;
00165 objName = key->GetName();
00166 cout << " hist name= " << objName << endl;
00167 for (int n = 1; n < nFiles; n++) {
00168 hist[1] = (TH1*)histFile[n]->Get(objName);
00169 hist[0]->Add(hist[1]);
00170 }
00171 }
00172 histFile[nFiles]->cd();
00173 obj->Write(objName);
00174 delete obj;
00175 obj = NULL;
00176 }
00177
00178
00179 for (int n = 0; n < nFiles; n++) {
00180 yieldPartHist[n] = dynamic_cast<TH2*>(histFile[n]->Get("Flow_YieldPart2D"));
00181 yieldPartHistPt[n] = dynamic_cast<TH1*>(histFile[n]->Get("FlowLYZ_YieldPartPt"));
00182 yieldPartHistEta[n] = dynamic_cast<TH1*>(histFile[n]->Get("FlowLYZ_YieldPartEta"));
00183 if (yieldPartHistPt[n]) { yieldTotal[n] = yieldPartHistPt[n]->Integral(); }
00184 }
00185
00186 cout << endl << "with weighting" << endl;
00187 TH1F* yieldY;
00188 TH1F* yieldPt;
00189 for (int pageNumber = 0; pageNumber < nNames; pageNumber++ ) {
00190 nextPage:
00191 bool twoD = kFALSE;
00192 if (strstr(baseName[pageNumber],"v2D")) twoD = kTRUE;
00193
00194 for (int selN = 0; selN < nSels; selN++) {
00195
00196
00197 bool noHars = kFALSE;
00198 int nHar = nHars;
00199 if (strstr(baseName[pageNumber],"_v_")!=0 ||
00200 strcmp(baseName[pageNumber],"Flow_Cos_")==0 ||
00201 strstr(baseName[pageNumber],"Res")!=0 ||
00202 strstr(baseName[pageNumber],"_V_")!=0 ||
00203 strstr(baseName[pageNumber],"_vr0_")!=0) {
00204 noHars = kTRUE;
00205 nHar = 1;
00206 }
00207
00208
00209 if (strstr(baseName[pageNumber],"theta_")!=0) {
00210 nHar = 2;
00211 }
00212
00213 for (int harN = 0; harN < nHar; harN++) {
00214
00215
00216 TString histName(baseName[pageNumber]);
00217 histName += "Sel";
00218 histName += selN+1;
00219 if (!noHars) {
00220 histName += "_Har";
00221 histName += harN+1;
00222 }
00223
00224 if (strstr(histName.Data(), "_Gtheta") && harN > 1) { continue; }
00225
00226
00227 for (int n = 0; n < nFiles+1; n++) {
00228 hist[n] = dynamic_cast<TH1*>(histFile[n]->Get(histName));
00229 if (!hist[n]) {
00230 if (pageNumber < nNames) {
00231 pageNumber++;
00232 goto nextPage;
00233 } else {
00234 cout << endl;
00235 cout << "*** Error: Correct nNames in macro" << endl;
00236 }
00237 } else if (n == 0) {
00238 cout << " hist name= " << histName << endl;
00239 }
00240 }
00241
00242
00243 if (strstr(histName.Data(), "r0theta")) {
00244 hist_r0theta[selN][harN] = dynamic_cast<TH1*>(histFile[nFiles]->Get(histName));
00245 }
00246
00247
00248 if (!hist[0]) { continue; }
00249 int nBins;
00250 int xBins = hist[0]->GetNbinsX();
00251 int yBins = 0.;
00252 if (twoD) {
00253 yBins = hist[0]->GetNbinsY();
00254 nBins = xBins + (xBins + 2) * yBins;
00255 float yMax = hist[0]->GetXaxis()->GetXmax();
00256 float yMin = hist[0]->GetXaxis()->GetXmin();
00257 yieldY = new TH1F("Yield_Y", "Yield_Y", xBins, yMin, yMax);
00258 yieldY->SetXTitle("Rapidity");
00259 yieldY->SetYTitle("Counts");
00260 float ptMax = hist[0]->GetYaxis()->GetXmax();
00261 yieldPt = new TH1F("Yield_Pt", "Yield_Pt", yBins, 0., ptMax);
00262 yieldPt->SetXTitle("Pt (GeV/c)");
00263 yieldPt->SetYTitle("Counts");
00264 } else {
00265 nBins = xBins + 2;
00266 }
00267
00268
00269 if (strstr(baseName[pageNumber],"LYZ")) {
00270 cout << " with LYZ yield weighted averaging" << endl;
00271 double v, yield, content, error, Vtheta, VthetaErr, r0, r0Err;
00272 double vSum, v2Sum, error2Sum, yieldSum, yieldSum2, yield2Sum;
00273
00274 for (int bin = 1; bin < nBins-1; bin++) {
00275 v = 0.;
00276 vSum = 0.;
00277 v2Sum = 0.;
00278 content = 0.;
00279 error = 0.;
00280 error2Sum = 0.;
00281 yield = 0.;
00282 yieldSum = 0.;
00283 yield2Sum = 0.;
00284 for (int n = 0; n < nFiles; n++) {
00285 if (hist[n]) {
00286 if (strstr(histName.Data(), "vEta")) {
00287 yield = yieldPartHistEta[n]->GetBinContent(bin);
00288 } else if (strstr(histName.Data(), "vPt")) {
00289 yield = yieldPartHistPt[n]->GetBinContent(bin);
00290 } else {
00291 yield = yieldTotal[n];
00292 }
00293 v = hist[n]->GetBinContent(bin);
00294 if (v != 0 && yield > 1.) {
00295 yieldSum += yield;
00296 yield2Sum += yield*yield;
00297 vSum += yield * v;
00298 v2Sum += yield * v*v;
00299 error2Sum += pow(yield * hist[n]->GetBinError(bin), 2.);
00300 }
00301 }
00302 }
00303 if (yieldSum) {
00304 content = vSum / yieldSum;
00305 v2Sum /= yieldSum;
00306 yieldSum2 = yieldSum*yieldSum;
00307 yield2Sum /= yieldSum2;
00308 error2Sum /= yieldSum2;
00309 if (strstr(baseName[pageNumber],"_G")) {
00310 error = 0.;
00311 } else if (nFiles > 1 && yield2Sum != 1.) {
00312 error = sqrt(error2Sum + (v2Sum - content*content) / (1/yield2Sum - 1));
00313 } else {
00314 error = sqrt(error2Sum);
00315 }
00316 if (strstr(histName.Data(), "v")) {
00317
00318 }
00319
00320 }
00321 hist[nFiles]->SetBinContent(bin, content);
00322 hist[nFiles]->SetBinError(bin, error);
00323 if (strstr(histName.Data(), "Vtheta")) {
00324
00325 Vtheta = hist[nFiles]->GetBinContent(bin);
00326 VthetaErr = hist[nFiles]->GetBinError(bin);
00327 if (VthetaErr > 0.001) {
00328
00329
00330 r0 = Vtheta ? j01 / Vtheta : 0.;
00331 r0Err = Vtheta ? r0 * VthetaErr / Vtheta : 0.;
00332
00333 hist_r0theta[selN][harN]->SetBinContent(bin, r0);
00334 hist_r0theta[selN][harN]->SetBinError(bin, r0Err);
00335
00336 }
00337 }
00338 }
00339 } else if ((strstr(baseName[pageNumber],"Cos")) ||
00340 (strstr(baseName[pageNumber],"Res"))) {
00341 cout << " With error weighting" << endl;
00342 double content, error, errorSq, meanContent, meanError, weight;
00343 for (int bin = 0; bin < nBins; bin++) {
00344 meanContent = 0.;
00345 meanError = 0.;
00346 weight = 0.;
00347 for (int n = 0; n < nFiles; n++) {
00348 if (hist[n]) {
00349 content = hist[n]->GetBinContent(bin);
00350 error = hist[n]->GetBinError(bin);
00351 errorSq = error * error;
00352 if (errorSq > 0.) {
00353 meanContent += content / errorSq;
00354 weight += 1. / errorSq;
00355 }
00356 }
00357 }
00358 if (weight > 0.) {
00359 meanContent /= weight;
00360 meanError = sqrt(1. / weight);
00361 hist[nFiles]->SetBinContent(bin, meanContent);
00362 hist[nFiles]->SetBinError(bin, meanError);
00363 }
00364 }
00365 } else {
00366 cout << " with yield weighted averaging" << endl;
00367 double v, yield, content, error, y, pt;
00368 double vSum, error2sum, yieldSum;
00369 for (int bin = 0; bin < nBins; bin++) {
00370 v = 0.;
00371 vSum = 0.;
00372 content = 0.;
00373 error = 0.;
00374 error2sum = 0.;
00375 yield = 0.;
00376 yieldSum = 0.;
00377 for (int n = 0; n < nFiles; n++) {
00378 if (hist[n]) {
00379 if (strstr(histName.Data(),"v2D")) {
00380 yield = yieldPartHist[n]->GetBinContent(bin);
00381 } else if (strstr(histName.Data(),"vEta")) {
00382 yield = yieldPartHist[n]->Integral(bin, bin, 1, yBins);
00383 if (selN==0 && harN==0) {
00384 y = yieldPartHist[n]->GetXaxis()->GetBinCenter(bin);
00385 yieldY->Fill(y, yield);
00386 }
00387 } else if (strstr(histName.Data(),"vPt")) {
00388 yield = yieldPartHist[n]->Integral(1, xBins, bin, bin);
00389 if (selN==0 && harN==0) {
00390 pt = yieldPartHist[n]->GetYaxis()->GetBinCenter(bin);
00391 yieldPt->Fill(pt, yield);
00392 }
00393 } else {
00394 yield = yieldPartHist[n]->Integral();
00395 }
00396 v = hist[n]->GetBinContent(bin);
00397 if (v != 0. && yield > 1.) {
00398 yieldSum += yield;
00399 vSum += yield * v;
00400 error2sum += pow(yield * hist[n]->GetBinError(bin), 2.);
00401 }
00402 }
00403 }
00404 if (yieldSum) {
00405 content = vSum / yieldSum;
00406 error = sqrt(error2sum) / yieldSum;
00407 }
00408 hist[nFiles]->SetBinContent(bin, content);
00409 hist[nFiles]->SetBinError(bin, error);
00410 }
00411 }
00412 }
00413 }
00414 cout << endl;
00415 }
00416
00417 cout << endl;
00418
00419 histFile[nFiles]->Write(0, TObject::kOverwrite);
00420 histFile[nFiles]->Close();
00421 delete histFile[nFiles];
00422 sprintf(rmCommand, "rm %s", listFileName);
00423 system(rmCommand);
00424 }
00425
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447