minBias.C 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // $Id: minBias.C,v 1.15 2007/02/06 19:00:51 posk Exp $
  4. //
  5. // Author: Art Poskanzer and Alexander Wetzler, Mar 2001
  6. // Kirill Filimonov treated the one count case
  7. // Description: Macro to add histograms together.
  8. // The v histograms will be added with yield weighting.
  9. // First file anaXX.root given by first run number XX.
  10. // Last file anaXX.root given by last run number XX.
  11. // Output file given by output run number.
  12. // For 10-50% centrality: minBias(X4,X7,X0)
  13. //
  14. //
  15. ///////////////////////////////////////////////////////////////////////////////
  16. #ifndef __CINT__
  17. #include <fstream.h>
  18. #include "TSystem.h"
  19. #include <TFile.h>
  20. #include "TH1.h"
  21. #include "TH2.h"
  22. #include "TProfile.h"
  23. #include "TKey.h"
  24. #include "TObject.h"
  25. #endif
  26. void minBias(Int_t firstRunNo, Int_t lastRunNo, Int_t outputRunNo=99) {
  27. const int nCens = lastRunNo - firstRunNo + 1;
  28. int nSels = 2;
  29. const int nHars = 4;
  30. char fileName[80];
  31. TFile* histFile[nCens+1];
  32. TH1* hist[nCens+1];
  33. TH2* yieldPartHist[nCens];
  34. TH1* yieldPartHistPt[nCens];
  35. TH1* yieldPartHistEta[nCens];
  36. Float_t yieldTotal[nCens];
  37. // names of histograms to be added with weighting
  38. const char* baseName[] = {
  39. "Flow_Res_",
  40. "Flow_v2D_", // must be before vEta and vPt
  41. "Flow_vEta_",
  42. "Flow_vPt_",
  43. "Flow_v_",
  44. "FlowLYZ_r0theta_",
  45. "FlowLYZ_Vtheta_",
  46. "FlowLYZ_V_",
  47. "FlowLYZ_vr0_",
  48. "FlowLYZ_vEta_",
  49. "FlowLYZ_vPt_",
  50. "FlowLYZ_v_",
  51. "Flow_v2D_ScalarProd_",
  52. "Flow_vEta_ScalarProd_",
  53. "Flow_vPt_ScalarProd_",
  54. "Flow_v_ScalarProd_",
  55. "Flow_Cumul_vEta_Order2_",
  56. "Flow_Cumul_vPt_Order2_",
  57. "Flow_Cumul_v_Order2_",
  58. "Flow_Cumul_vEta_Order4_",
  59. "Flow_Cumul_vPt_Order4_",
  60. "Flow_Cumul_v_Order4_"
  61. };
  62. const int nNames = sizeof(baseName) / sizeof(char*);
  63. // open the files
  64. for (int n = 0; n < nCens; n++) {
  65. sprintf(fileName, "ana%2d.root", firstRunNo + n);
  66. cout << " file name = " << fileName << endl;
  67. histFile[n] = new TFile(fileName);
  68. if (!histFile[n]) {
  69. cout << "### Can't find file " << fileName << endl;
  70. return;
  71. }
  72. }
  73. sprintf(fileName, "ana%2d.root", outputRunNo);
  74. cout << " output file name = " << fileName << endl << endl;
  75. histFile[nCens] = new TFile(fileName, "RECREATE");
  76. // add all histograms with no weighting
  77. TKey* key;
  78. TObject* obj;
  79. TIter nextkey(histFile[0]->GetListOfKeys());
  80. while (key = (TKey*)nextkey()) {
  81. histFile[0]->cd();
  82. //key->ls();
  83. obj = key->ReadObj();
  84. const char* objName;
  85. if (obj->InheritsFrom("TH1")) { // TH1 or TProfile
  86. hist[0] = (TH1*)obj;
  87. objName = key->GetName();
  88. cout << "hist name= " << objName << endl;
  89. for (int n = 1; n < nCens; n++) {
  90. hist[1] = (TH1*)histFile[n]->Get(objName);
  91. hist[0]->Add(hist[1]);
  92. }
  93. }
  94. histFile[nCens]->cd();
  95. obj->Write(objName);
  96. delete obj;
  97. obj = NULL;
  98. }
  99. // get yield histogram
  100. cout<<endl;
  101. for (int n = 0; n < nCens; n++) {
  102. yieldPartHist[n] = dynamic_cast<TH2*>(histFile[n]->Get("Flow_YieldPart2D"));
  103. yieldPartHistPt[n] = dynamic_cast<TH1*>(histFile[n]->Get("FlowLYZ_YieldPartPt"));
  104. yieldPartHistEta[n] = dynamic_cast<TH1*>(histFile[n]->Get("FlowLYZ_YieldPartEta"));
  105. if (yieldPartHistPt[n]) { yieldTotal[n] = yieldPartHistPt[n]->Integral(); }
  106. }
  107. for (int pageNumber = 0; pageNumber < nNames; pageNumber++ ) {
  108. bool twoD = kFALSE;
  109. if (strstr(baseName[pageNumber],"v2D")) twoD = kTRUE;
  110. for (int selN = 0; selN < nSels; selN++) {
  111. // no harmonics
  112. bool noHars = kFALSE;
  113. int nHar = nHars;
  114. if (strstr(baseName[pageNumber],"_v_")!=0 ||
  115. strstr(baseName[pageNumber],"Res")!=0 ||
  116. strstr(baseName[pageNumber],"_V_")!=0 ||
  117. strstr(baseName[pageNumber],"_vr0_")!=0) {
  118. noHars = kTRUE;
  119. nHar = 1;
  120. }
  121. for (int harN = 0; harN < nHar; harN++) {
  122. // construct histName
  123. TString* histName = new TString(baseName[pageNumber]);
  124. *histName += "Sel";
  125. *histName += selN+1;
  126. if (!noHars) {
  127. *histName += "_Har";
  128. *histName += harN+1;
  129. }
  130. // get the histograms
  131. for (int n = 0; n < nCens+1; n++) {
  132. hist[n] = dynamic_cast<TH1*>(histFile[n]->Get(histName->Data()));
  133. }
  134. if (hist[0]) { cout << "hist name= " << histName->Data() << endl; }
  135. const int lastHist = nCens;
  136. int nBins; // set by 2D of centrality lastHist
  137. if (!hist[lastHist]) continue;
  138. int xBins = hist[lastHist]->GetNbinsX();
  139. int yBins;
  140. TH1F *yieldY, *yieldPt;
  141. if (twoD) {
  142. yBins = hist[lastHist]->GetNbinsY();
  143. nBins = xBins + (xBins + 2) * yBins;
  144. float yMax = hist[lastHist]->GetXaxis()->GetXmax();
  145. float yMin = hist[lastHist]->GetXaxis()->GetXmin();
  146. yieldY = new TH1F("Yield_Y", "Yield_Y", xBins, yMin, yMax);
  147. yieldY->SetXTitle("Rapidity");
  148. yieldY->SetYTitle("Counts");
  149. float ptMax = hist[lastHist]->GetYaxis()->GetXmax();
  150. yieldPt = new TH1F("Yield_Pt", "Yield_Pt", yBins, 0., ptMax);
  151. yieldPt->SetXTitle("Pt (GeV/c)");
  152. yieldPt->SetYTitle("Counts");
  153. } else {
  154. nBins = xBins + 2;
  155. }
  156. // loop over the bins
  157. if (strstr(baseName[pageNumber],"Res") ||
  158. strstr(baseName[pageNumber],"Cumul")) { // with error weighting
  159. cout << " With error weighting" << endl;
  160. float content, error, errorSq, meanContent, meanError, weight;
  161. for (int bin = 0; bin < nBins; bin++) {
  162. meanContent = 0.;
  163. meanError = 0.;
  164. weight = 0.;
  165. for (int n = 0; n < nCens; n++) {
  166. if (hist[n]) {
  167. content = hist[n]->GetBinContent(bin);
  168. error = hist[n]->GetBinError(bin);
  169. errorSq = error * error;
  170. if (errorSq > 0.) {
  171. meanContent += content / errorSq;
  172. weight += 1. / errorSq;
  173. }
  174. }
  175. }
  176. if (weight > 0.) {
  177. meanContent /= weight;
  178. meanError = sqrt(1. / weight);
  179. hist[nCens]->SetBinContent(bin, meanContent);
  180. hist[nCens]->SetBinError(bin, meanError);
  181. }
  182. }
  183. } else { // with yield weighting
  184. cout << " With yield weighting" << endl;
  185. float v, verr, content, error, yield, y, pt;
  186. double vSum, vSum2, error2sum, yieldSum, vRms, verrRms, vSumRms, yieldSumRms, vSumRms2;
  187. for (int bin = 0; bin < nBins; bin++) {
  188. v = 0.;
  189. verr = 0.;
  190. vSum = 0.;
  191. vSum2 = 0.;
  192. content = 0.;
  193. error = 0.;
  194. error2sum = 0.;
  195. yield = 0.;
  196. yieldSum = 0.;
  197. vRms = 0.;
  198. verrRms = 0.;
  199. vSumRms = 0.;
  200. yieldSumRms = 0.;
  201. vSumRms2 = 0.;
  202. for (int n = 0; n < nCens; n++) {
  203. if (hist[n]) {
  204. if (strstr(baseName[pageNumber],"LYZ")) {
  205. if (strstr(histName->Data(), "vEta")) {
  206. yield = yieldPartHistEta[n]->GetBinContent(bin);
  207. } else if (strstr(histName->Data(), "vPt")) {
  208. yield = yieldPartHistPt[n]->GetBinContent(bin);
  209. } else { // r0theta, Vtheta, _V_, vr0, _v_, Gtheta
  210. yield = yieldTotal[n];
  211. }
  212. } else {
  213. if (strstr(histName->Data(),"v2D")) {
  214. yield = yieldPartHist[n]->GetBinContent(bin);
  215. } else if (strstr(histName->Data(),"vEta")) {
  216. yield = yieldPartHist[n]->Integral(bin, bin, 1, yBins);
  217. if (selN==0 && harN==0) {
  218. y = yieldPartHist[n]->GetXaxis()->GetBinCenter(bin);
  219. yieldY->Fill(y, yield);
  220. }
  221. } else if (strstr(histName->Data(),"vPt")) {
  222. yield = yieldPartHist[n]->Integral(1, xBins, bin, bin);
  223. if (selN==0 && harN==0) {
  224. pt = yieldPartHist[n]->GetYaxis()->GetBinCenter(bin);
  225. yieldPt->Fill(pt, yield);
  226. }
  227. } else { // _v
  228. yield = yieldPartHist[n]->Integral();
  229. }
  230. }
  231. v = hist[n]->GetBinContent(bin);
  232. if (yield==1) { // special case to calculate the correct error
  233. vSumRms += v;
  234. yieldSumRms += yield;
  235. vSumRms2 += v*v;
  236. } else {
  237. verr = hist[n]->GetBinError(bin);
  238. if (v != 0 ) {
  239. yieldSum += yield;
  240. vSum += yield * v;
  241. vSum2 += v * v * yield;
  242. error2sum += pow(yield * verr, 2.);
  243. }
  244. }
  245. }
  246. }
  247. if (yieldSumRms) vRms = vSumRms / yieldSumRms;
  248. if (yieldSumRms>1) {
  249. verrRms = sqrt(vSumRms2 - vSumRms*vSumRms / yieldSumRms)
  250. / yieldSumRms;
  251. yieldSum += yieldSumRms;
  252. vSum += vSumRms;
  253. error2sum += pow(yieldSumRms * verrRms, 2.);
  254. vSum2 += vRms * vRms * yieldSumRms;
  255. }
  256. if (yieldSum) {
  257. content = vSum / yieldSum;
  258. if (yieldSumRms==1) {
  259. error = sqrt(error2sum + vSum2 - vSum*vSum / yieldSum) / yieldSum;
  260. error = yieldSum / (yieldSum+1) * sqrt(error*error +
  261. (vRms - content)*(vRms - content) / (yieldSum * (yieldSum+1)));
  262. } else {
  263. error = sqrt(error2sum + vSum2 - vSum*vSum/yieldSum) / yieldSum;
  264. }
  265. hist[nCens]->SetBinContent(bin, content);
  266. hist[nCens]->SetBinError(bin, error);
  267. }
  268. }
  269. }
  270. delete histName;
  271. }
  272. }
  273. }
  274. //histFile[nCens]->ls();
  275. histFile[nCens]->Write(0, TObject::kOverwrite);
  276. histFile[nCens]->Close();
  277. delete histFile[nCens];
  278. }
  279. ///////////////////////////////////////////////////////////////////////////////
  280. //
  281. // $Log: minBias.C,v $
  282. // Revision 1.15 2007/02/06 19:00:51 posk
  283. // In Lee Yang Zeros method, introduced recentering of Q vector.
  284. // Reactivated eta symmetry cut.
  285. //
  286. // Revision 1.13 2006/03/22 22:02:07 posk
  287. // Updates to macros.
  288. //
  289. // Revision 1.12 2006/02/24 18:36:04 posk
  290. // Updated for LeeYangZerosMaker histograms.
  291. //
  292. // Revision 1.11 2004/03/01 22:43:42 posk
  293. // Changed some "->" to ".".
  294. //
  295. // Revision 1.10 2003/08/26 21:10:12 posk
  296. // Calculates v8 if nHars=8.
  297. //
  298. // Revision 1.9 2003/06/27 21:25:44 posk
  299. // v4 and v6 are with repect to the 2nd harmonic event plane.
  300. //
  301. // Revision 1.8 2003/03/11 23:03:07 posk
  302. // Includes scalar product and cumulant hists.
  303. //
  304. // Revision 1.7 2002/06/11 21:54:15 posk
  305. // Kirill's further correction to minBias.C for bins with one count.
  306. //
  307. // Revision 1.6 2002/05/21 18:42:18 posk
  308. // Kirill's correction to minBias.C for bins with one count.
  309. //
  310. // Revision 1.5 2001/11/09 21:15:00 posk
  311. // Switched from CERNLIB to TMath. Using global dca instead of dca.
  312. //
  313. // Revision 1.4 2001/05/22 20:05:47 posk
  314. // Now outputs a hist.root file.
  315. // The v values are averaged with yield weighting.
  316. //
  317. // Revision 1.3 2000/09/29 22:53:17 posk
  318. // More histograms.
  319. //
  320. // Revision 1.2 2000/09/26 20:54:11 posk
  321. // Updated documentation.
  322. //
  323. // Revision 1.1 2000/09/26 00:19:43 posk
  324. // New macro to add centrality-selected histograms with proper weights, to make
  325. // minimum bias histogram.
  326. //
  327. //
  328. ///////////////////////////////////////////////////////////////////////////////