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