plotCumulant.C 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // $Id: plotCumulant.C,v 1.11 2007/02/06 19:00:52 posk Exp $
  4. //
  5. // Author: Art Poskanzer, LBNL, Nov 2001
  6. // Description: Macro to plot histograms made by StFlowCumulantMaker.
  7. // If orderN = 0 plot all selections and harmonics.
  8. // First time type .x plotCumulant.C() to see the menu.
  9. // Run Number appended to "ana" is entered in the bottom, left box.
  10. // Hist file is anaXX.root where XX is the number.
  11. // Default hist file is flow.cumulant.root .
  12. // After the first execution, just type plotCumulant(N) .
  13. // A negative N plots all pages starting with page N.
  14. // Place a symbolic link to this file in StRoot/macros/analysis .
  15. //
  16. ///////////////////////////////////////////////////////////////////////////////
  17. #include <math.h>
  18. const Int_t nHars = 2; // 2
  19. const Int_t nOrders = 2;
  20. Int_t runNumber = 0;
  21. char runName[6];
  22. char fileNum[4] = "x";
  23. char fileName[30];
  24. TFile* histFile;
  25. char tmp[10];
  26. TCanvas* c;
  27. TCanvas* plotCumulant(Int_t pageNumber=0, Int_t selN=2, Int_t orderN=0, Int_t harN=0){
  28. bool multiGraph = kFALSE; // set flags
  29. bool singleGraph = kFALSE;
  30. if (orderN == 0) multiGraph = kTRUE;
  31. bool mixGraph = kFALSE;
  32. TCanvas* cOld = (TCanvas*)gROOT->GetListOfCanvases(); // delete old canvas
  33. if (cOld) cOld->Delete();
  34. gROOT->SetStyle("Bold"); // set style
  35. gROOT->ForceStyle();
  36. // names of histograms made by StFlowCumulantMaker
  37. const char* baseName[] = {
  38. "Flow_Cumul_v_Order2",
  39. "Flow_Cumul_v_Order4",
  40. "Flow_CumulMix_v",
  41. "Flow_CumulMix_vEta",
  42. "Flow_CumulMix_vPt",
  43. "Flow_Cumul_vEta_Order",
  44. "Flow_Cumul_vPt_Order"
  45. //"Flow_Cumul_v2D_Order"
  46. };
  47. const int nNames = sizeof(baseName) / sizeof(char*);
  48. const int nSingles = 5;
  49. float Ycm = 0.0;
  50. // construct array of short names
  51. char* shortName[] = new char*[nNames];
  52. for (int n = 0; n < nNames; n++) {
  53. shortName[n] = new char[30];
  54. strcpy(shortName[n], baseName[n]);
  55. char* cp = strstr(shortName[n],"Order");
  56. if (cp) *cp = '\0'; // truncate
  57. }
  58. // input the run number
  59. if (runNumber == 0) {
  60. cout << " run number? ";
  61. fgets(tmp, sizeof(tmp), stdin);
  62. runNumber = atoi(tmp);
  63. sprintf(runName, "ana%2d", runNumber); // add ana prefix
  64. cout << " run name = " << runName << endl;
  65. }
  66. // input the file number (0 opens flow.hist.root)
  67. if (strstr(fileNum, "x")!=0) {
  68. cout << " anaXX.root file number? [0= flow.hist.root] ";
  69. fgets(fileNum, sizeof(fileNum), stdin);
  70. fileNum[strlen(fileNum)-1] = '\0';
  71. if (strlen(fileNum) == 1 && strstr(fileNum,"0")) {
  72. sprintf(fileName, "flow.hist.root");
  73. } else {
  74. sprintf(fileName, "ana%s.root", fileNum); // insert
  75. }
  76. cout << " file name = " << fileName << endl;
  77. histFile = new TFile(fileName);
  78. }
  79. // input the page number
  80. while (pageNumber <= 0 || pageNumber > nNames) {
  81. if (pageNumber < 0) { // plot all
  82. plotCumulantAll(nNames, orderN, selN, harN, -pageNumber);
  83. return c;
  84. }
  85. cout << "-1: \t All" << endl; // print menu
  86. for (int i = 0; i < nNames; i++) {
  87. cout << i+1 << ":\t " << baseName[i] << endl;
  88. }
  89. cout << " page number? ";
  90. fgets(tmp, sizeof(tmp), stdin);
  91. pageNumber = atoi(tmp);
  92. }
  93. if (pageNumber > 0 && pageNumber <= nSingles) { // plot singles
  94. singleGraph = kTRUE;
  95. multiGraph = kFALSE;
  96. strcpy(shortName[pageNumber-1], baseName[pageNumber-1]);
  97. }
  98. pageNumber--;
  99. cout << " graph name= " << shortName[pageNumber] << endl;
  100. if (strstr(shortName[pageNumber],"Mix")!=0) { // Mixed harmonic v1
  101. mixGraph = kTRUE;
  102. harN = 1;
  103. }
  104. // set row and column numbers
  105. int columns = nOrders;
  106. int rows = nHars;
  107. int pads = rows*columns;
  108. // make the graph page
  109. if (multiGraph) {
  110. int canvasWidth = 600, canvasHeight = 780; // portrait
  111. } else {
  112. int canvasWidth = 780, canvasHeight = 600; // landscape
  113. }
  114. c = new TCanvas(shortName[pageNumber], shortName[pageNumber],
  115. canvasWidth, canvasHeight);
  116. c->ToggleEventStatus();
  117. if (multiGraph) {
  118. TPaveLabel* title = new TPaveLabel(0.1,0.96,0.9,0.99,shortName[pageNumber]);
  119. title->Draw();
  120. }
  121. TPaveLabel* run = new TPaveLabel(0.1,0.01,0.2,0.03,runName);
  122. run->Draw();
  123. TDatime now;
  124. TPaveLabel* date = new TPaveLabel(0.7,0.01,0.9,0.03,now.AsString());
  125. date->Draw();
  126. TPad* graphPad = new TPad("Graphs","Graphs",0.01,0.05,0.97,0.95);
  127. graphPad->Draw();
  128. graphPad->cd();
  129. if (multiGraph) { // many graphs on one page
  130. graphPad->Divide(columns,rows);
  131. int firstK = 0, firstJ = 0, lastK = columns, lastJ = rows;
  132. } else if (singleGraph) { // single graph on a page
  133. int firstK = 0, firstJ = 0, lastK = 1, lastJ = 1;
  134. } else { // one graph from a multi graph page
  135. int firstK = orderN/2 -1, firstJ = harN -1, lastK = orderN/2, lastJ = harN;
  136. }
  137. for (int j = firstJ; j < lastJ; j++) {
  138. for (int k = firstK ; k < lastK; k++) {
  139. char countOrder[2];
  140. sprintf(countOrder,"%d",2*(k+1));
  141. int padN = j*columns + k + 1; // pad number
  142. // construct histName
  143. TString* histName = new TString(baseName[pageNumber]);
  144. if (multiGraph) {
  145. histName->Append(*countOrder);
  146. }
  147. histName->Append("_Sel");
  148. *histName += selN;
  149. if (multiGraph) {
  150. histName->Append("_Har");
  151. *histName += j+1;
  152. } else if (mixGraph && strcmp(shortName[pageNumber],"Flow_CumulMix_v") != 0) {
  153. histName->Append("_Har");
  154. *histName += j+1;
  155. }
  156. cout << " col= " << k+1 << " row= " << j+1 << " pad= " << padN << "\t"
  157. << histName->Data() << endl;
  158. // get the histogram
  159. bool twoD;
  160. if (strstr(shortName[pageNumber],"2D")!=0) { // 2D
  161. twoD = kTRUE;
  162. TH2* hist2D = dynamic_cast<TH2*>(histFile->Get(histName->Data()));
  163. if (!hist2D) {
  164. cout << "### Can't find histogram " << histName->Data() << endl;
  165. return c;
  166. }
  167. } else { // 1D
  168. TH1* hist = dynamic_cast<TH1*>(histFile->Get(histName->Data()));
  169. if (!hist) {
  170. cout << "### Can't find histogram " << histName->Data() << endl;
  171. return c;
  172. }
  173. float xMax = hist->GetXaxis()->GetXmax();
  174. }
  175. // make the plots
  176. if (multiGraph) graphPad->cd(padN);
  177. if (twoD) { // 2D
  178. gStyle->SetOptStat(10);
  179. //hist2D->Draw("COLZ");
  180. hist2D->Draw("LEGO1");
  181. } else { // all other 1D
  182. gStyle->SetOptStat(100110);
  183. hist->Draw();
  184. float yMax, yMin;
  185. if (strstr(shortName[pageNumber],"Eta")!=0) {
  186. if (strstr(shortName[pageNumber],"_v")!=0) {
  187. yMax = 10.;
  188. yMin = -10.;
  189. } else {
  190. yMax = 0.005;
  191. yMin = -0.005;
  192. }
  193. hist->SetMaximum(yMax);
  194. hist->SetMinimum(yMin);
  195. TLine* lineZeroEta = new TLine(-xMax, 0., xMax, 0.);
  196. lineZeroEta->Draw();
  197. TLine* lineEtaCM = new TLine(Ycm, yMin, Ycm, yMax);
  198. lineEtaCM->Draw();
  199. } else if (strstr(shortName[pageNumber],"Pt")!=0) {
  200. if (strstr(shortName[pageNumber],"_v")!=0) {
  201. yMax = 30.;
  202. yMin = -10.;
  203. } else {
  204. yMax = 0.02;
  205. yMin = -0.02;
  206. }
  207. hist->SetMaximum(yMax);
  208. hist->SetMinimum(yMin);
  209. TLine* lineZeroPt = new TLine(0., 0., xMax, 0.);
  210. lineZeroPt->Draw();
  211. } else {
  212. hist->SetMinimum(0.);
  213. TLine* lineZeroHar = new TLine(0.5, 0., nHars+0.5, 0.);
  214. lineZeroHar->Draw();
  215. }
  216. }
  217. delete histName;
  218. }
  219. }
  220. for (int m = 0; m < nNames; m++) {
  221. delete [] shortName[m];
  222. }
  223. delete [] shortName;
  224. return c;
  225. }
  226. void plotCumulantAll(Int_t nNames, Int_t orderN, Int_t selN, Int_t harN, Int_t first = 1) {
  227. for (int i = first; i < nNames + 1; i++) {
  228. c = plotCumulant(i, selN, orderN, harN);
  229. c->Update();
  230. cout << "save? y/[n], quit? q" << endl;
  231. fgets(tmp, sizeof(tmp), stdin);
  232. if (strstr(tmp,"y")!=0) c->Print(".ps");
  233. else if (strstr(tmp,"q")!=0) return;
  234. }
  235. cout << " plotCumulantAll Done" << endl;
  236. }
  237. ///////////////////////////////////////////////////////////////////////////////
  238. //
  239. // $Log: plotCumulant.C,v $
  240. // Revision 1.11 2007/02/06 19:00:52 posk
  241. // In Lee Yang Zeros method, introduced recentering of Q vector.
  242. // Reactivated eta symmetry cut.
  243. //
  244. // Revision 1.10 2006/02/24 18:13:39 posk
  245. // Reduced number of histograms.
  246. //
  247. // Revision 1.9 2004/12/09 23:47:12 posk
  248. // Minor changes in code formatting.
  249. // Added hist for TPC primary dca to AnalysisMaker.
  250. //
  251. // Revision 1.8 2004/03/01 22:43:45 posk
  252. // Changed some "->" to ".".
  253. //
  254. // Revision 1.7 2003/08/26 21:10:14 posk
  255. // Calculates v8 if nHars=8.
  256. //
  257. // Revision 1.6 2003/06/27 21:25:46 posk
  258. // v4 and v6 are with repect to the 2nd harmonic event plane.
  259. //
  260. // Revision 1.5 2003/02/25 19:25:34 posk
  261. // Improved plotting.
  262. //
  263. // Revision 1.4 2002/01/14 23:43:06 posk
  264. // Renamed ScalerProd histograms. Moved print commands to FlowMaker::Finish().
  265. //
  266. // Revision 1.3 2001/12/18 19:27:44 posk
  267. // "proton" and "antiproton" replaced by "pr+" and "pr-".
  268. //
  269. // Revision 1.2 2001/12/11 22:04:22 posk
  270. // Four sets of phiWgt histograms.
  271. // StFlowMaker StFlowEvent::PhiWeight() changes.
  272. // Cumulant histogram names changed.
  273. //
  274. // Revision 1.1 2001/11/09 21:15:14 posk
  275. // Switched from CERNLIB to TMath. Using global dca instead of dca.
  276. //
  277. //
  278. ///////////////////////////////////////////////////////////////////////////////