ROOTPWA
plotMassDepFitResult.C
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "TList.h"
3 #include "TStyle.h"
4 #include "TKey.h"
5 #include "TString.h"
6 #include "TCanvas.h"
7 #include "TGraph.h"
8 #include "TGraphErrors.h"
9 #include "TH1F.h"
10 #include "TMultiGraph.h"
11 #include "TAxis.h"
12 #include "TGaxis.h"
13 #include "TLatex.h"
14 #include "TFrame.h"
15 #include "TObjArray.h"
16 #include "TROOT.h"
17 //#include "TQSender.h"
18 
19 #include <iostream>
20 #include <fstream>
21 #include <sstream>
22 #include <map>
23 using namespace std;
24 
25 #define RECOLOR kYellow-9
26 #define IMCOLOR kSpring-9
27 
28 
29 TString fitname;
30 
31 TString parseTitle(TString l, unsigned int level=10){
32  // setup isobar dictionary key->tex
33  map<TString, TString> isobars;
34  isobars["pi+" ] = "\\pi^{+}";
35  isobars["pi-" ] = "\\pi^{-}";
36  isobars["pi+-" ] = "\\pi^{\\pm}";
37  isobars["pi-+" ] = "\\pi^{\\pm}";
38  isobars["sigma" ] = "\\sigma";
39  isobars["rho770" ] = "\\rho(770)";
40  isobars["a11269" ] = "a_{1}(1269)";
41  isobars["a21320" ] = "a_{2}(1320)";
42  isobars["rho1450" ] = "\\rho(1450)";
43  isobars["rho1600" ] = "\\rho(1600)";
44  isobars["rho1700" ] = "\\rho(1700)";
45  isobars["pi1300" ] = "\\pi(1300)";
46  isobars["pi1800" ] = "\\pi(1800)";
47  isobars["pi21670" ] = "\\pi_2(1670)";
48  isobars["f01370" ] = "f_{0}(1370)";
49  isobars["f01500" ] = "f_{0}(1500)";
50  isobars["f01700" ] = "f_{0}(1700)";
51  isobars["f11285" ] = "f_{1}(1285)";
52  isobars["f11420" ] = "f_{1}(1420)";
53  isobars["b11235" ] = "b_{1}(1235)";
54  isobars["b11800" ] = "b_{1}(1800)";
55  isobars["b11500" ] = "b_{1}(1500)";
56  isobars["f21270" ] = "f_{2}(1270)";
57  isobars["f21950" ] = "f_{2}(1950)";
58  isobars["f21565" ] = "f_{2}(1565)";
59  isobars["f21270" ] = "f_{2}(1270)";
60  isobars["f22010" ] = "f_{2}(2010)";
61  isobars["f11420" ] = "f_{1}(1420)";
62  isobars["eta1440" ] = "\\eta(1420)";
63  isobars["eta11600" ] = "\\eta_{1}(1600)";
64  isobars["eta21645"] = "\\eta_{2}(1645)";
65  isobars["rho31690"] = "\\rho_{3(1690)";
66 
67  // remove file extension
68  l.Remove(l.Length() - 4);
69  // extract X quantum numbers
70  const TString head = l(0, 7);
71  const TString I = head(0, 1);
72  const TString G = head(1, 1);
73  const TString J = head(2, 1);
74  const TString P = head(3, 1);
75  const TString C = head(4, 1);
76  const TString M = head(5, 1);
77  const TString refl = head(6, 1);
78  l.Remove(0, 7);
79  // print X quantum numbers
80 
81  stringstream res;
82  res << I << "^{" << G <<"}(" << J << "^{" << P << C << "}" << M << "^{" << refl << "})";
83 
84  // tokenize input
85  TObjArray* tokens = l.Tokenize("_=");
86  int mode = 0;
87  unsigned int counter=0;
88  for (int i = 0; i < tokens->GetEntries(); ++i) {
89  const TString token = ((TObjString*)tokens->At(i))->GetString();
90  cerr << " " << mode << ": '" << token << "'" << endl;
91  if (mode == 0) { // isobar mode
92  if (isobars.find(token) != isobars.end())
93  res << isobars[token];
94  else
95  res << token;
96  res << " ";
97  // check which mode to switch to depending whether we get _ or =
98  l.Remove(0, token.Length());
99  if (l(0, 1) == "_")
100  mode = 1;
101  else
102  mode = 2;
103  } else if (mode == 1) { // ls mode
104  if (token.Length() == 1) // only l
105  res << "[" << token << "] ";
106  else
107  res << "\\left[#splitline{" << token(0, 1) << "}{"
108  << token(1, 1) << "}\\right]";
109  l.Remove(0, token.Length());
110  mode = 0;
111  } else if (mode == 2) {
112  if(level<=counter) break;
113  ++counter;
114  res << "\\rightarrow ";
115  if (isobars.find(token) != isobars.end())
116  res << isobars[token];
117  else
118  res << token;
119  res << " ";
120  l.Remove(0, token.Length());
121  if (l(0, 1) == "_" )
122  mode = 1;
123  else
124  mode = 2;
125  }
126  l.Remove(0, 1); // remove delimiter
127  }
128  res;
129 
130  tokens->Delete();
131  delete tokens;
132  TString result(res.str().c_str());
133  return result;
134 }
135 
136 void plotNice(TVirtualPad* pad, TString plotDir=""){
137  TCanvas* cpopup=(TCanvas*)gROOT->FindObjectAny("cpopup");
138  if(cpopup==NULL){
139  cerr << "Popupo Window not found! RESPAWNING" << endl;
140  cpopup=new TCanvas("cpopup","PopUp",50,50,700,700);
141  }
142 
143  cpopup->Clear("");
144  cpopup->cd();
145  TVirtualPad* clone=(TVirtualPad*)pad->Clone();
146  if(clone==NULL){
147  cerr << "Cloning pad failed!" << endl;
148  return;
149  }
150 
151 
152  clone->SetFillStyle(1);
153  clone->Draw();
154  clone->SetPad("pu","PopUp",0,0,1,1,0);
155  cpopup->cd(1);
156  cpopup->Update();
157 
158  TMultiGraph* gr=(TMultiGraph*)clone->GetListOfPrimitives()->At(1);
159  if(gr==NULL){
160  cerr << "Cloning graphs failed!" << endl;
161  return;
162  }
163 
164 
165 
166 
167  TString title=gr->GetName();
168  TH1* hx=NULL;
169  if(!title.Contains("dPhi") && !title.Contains("Re") && !title.Contains("Im"))hx=(TH1*)clone->GetListOfPrimitives()->At(2);
170 
171 
172 
173  TGraphErrors* gdata=(TGraphErrors*)gr->GetListOfGraphs()->At(1);
174  if(gdata==NULL){
175  cerr << "Cloning data failed!" << endl;
176  return;
177  }
178  gdata->SetLineWidth(2);
179 
180 
181  double xmax=gr->GetXaxis()->GetBinCenter(gr->GetXaxis()->GetLast());
182  double xmin=gr->GetXaxis()->GetBinCenter(gr->GetXaxis()->GetFirst());
183  double max=-1E6;
184  double min=1E6;
185  TGraphErrors* fitg=(TGraphErrors*)gr->GetListOfGraphs()->At(2);
186 
187  if(fitg!=NULL){
188  fitg->SetLineWidth(2);
189  double* yp=fitg->GetY();
190  for(unsigned int i=0;i<fitg->GetN();++i){
191  if(max<yp[i])max=yp[i];
192  if(min>yp[i])min=yp[i];
193  }
194  }
195  else {
196  max=0;
197  min=0;
198  }
199  // this works nly for phase plots
200  double ymin=0.5*(max+min)-220;
201  double ymax=0.5*(max+min)+220;
202 
203  if(title.Contains("dPhi")){
204  cerr << "Ymin: " << ymin << " Ymax: " << ymax << endl;
205  // for phase plots manually cut the systematic errors!
206  TGraphErrors* gsys=(TGraphErrors*)gr->GetListOfGraphs()->At(0);
207  //gsys->GetYaxis()->SetRangeUser(ymin,ymax);
208  unsigned int n=gsys->GetN();
209  for(unsigned int i=0;i<n;++i){
210  double y, x, ey, ex;
211  gsys->GetPoint(i,x,y);
212  ey=gsys->GetErrorY(i);
213  ex=gsys->GetErrorX(i);
214 
215  // check if error band is in limits
216  if(y+ey>ymax){
217  cerr << "correcting upper" << endl;
218  double dy=0.5*(y+ey-ymax);
219  y-=dy;
220  ey-=dy;
221  }
222  if(y-ey<ymin){
223  double dy=0.5*(ymin-y+ey);
224  y+=dy;
225  ey-=dy;
226  }
227  gsys->SetPoint(i,x,y);
228  gsys->SetPointError(i,ex,ey);
229  }
230  }
231  if(hx!=NULL)hx->SetLineColor(kMagenta);
232  clone->Draw();
233  clone->cd();
234  clone->GetFrame()->Draw();
235  clone->SetBorderMode(0);
236 
237 
238 
239 
240  double xcenter=0.5;
241  double ycenter=0.5;
242 
243  double x=xcenter-0.25;
244  double y=xcenter-0.2;
245 
246  // preliminary
247  TLatex* prelim=new TLatex(x,y,"preliminary");
248  prelim->SetNDC();
249  prelim->SetTextColor(kGray);
250  prelim->SetTextSize(0.1);
251  prelim->SetTextAngle(20);
252  prelim->Draw();
253 
254  // compass 2004
255  //double xc=xcenter+0.05;
256  double xc=0.105;//xcenter+0.05;
257 
258  //if(right)xc=xcenter+0.1;
259  //double yc=ycenter+0.35;
260  double yc=ycenter+0.45;
261  TLatex* com04=new TLatex(xc,yc,"COMPASS 2004");
262  com04->SetNDC();
263  com04->SetTextSize(0.05);
264  com04->Draw();
265 
266  // 5 pi on pb
267  yc=yc-0.04;
268  TLatex* react=new TLatex(xc,yc,"#pi^{-} Pb #rightarrow #pi^{-}#pi^{+}#pi^{-}#pi^{+}#pi^{-} Pb");
269  react->SetNDC();
270  react->SetTextSize(0.039);
271  react->Draw();
272 
273  // add waves
274  //cout << "####### Title:" << endl;
275 
276 
277 
278  if(ymax > 0 && ymin < 0){
279  TLine* zeroline=new TLine(xmin,0,xmax,0);
280  zeroline->SetLineStyle(7);
281  zeroline->Draw();
282  }
283 
284  // gr->GetListOfGraphs()->RemoveAt(2);
285  gr->GetXaxis()->SetTitle("mass (GeV/c^{2})");
286  gr->GetXaxis()->Draw();
287  gr->GetYaxis()->Draw();
288 
289 
290  //cout << title << endl;
291  // check if this is intensity or off diagonal
292  TString wave;
293  bool isIntens=false;
294  if(!title.Contains("---")){
295  cout << "Processing Intensity:" << endl;
296  wave=parseTitle(title,1);
297  //cout << wave << endl;
298  yc=ycenter+0.44;
299  isIntens=true;
300  }
301  else {
302  // Split
303  //cout << title << endl;
304 
305  unsigned int offset=3;
306  wave="#splitline{Interference - ";
307  if(title.Contains("Re"))wave+= "real part";
308  else if(title.Contains("Im"))wave+="imaginary part";
309  else {
310  wave+="phase difference";
311  offset=5;
312  }
313 
314  unsigned int i = title.Index("---");
315  TString wave1=title(offset,i-offset);
316  TString wave2=title(i+3,title.Length());
317 
318  //cout << parseTitle(wave1,1) << endl;
319  //cout << parseTitle(wave2,1) << endl;
320 
321 
322 
323  wave="#splitline{";
324  wave+=parseTitle(wave1,1);
325  wave+="}{";
326  wave+=parseTitle(wave2,1);
327  wave+="}";
328  // check if we put text up or down
329  double max=gr->GetYaxis()->GetXmax();
330  double min=gr->GetYaxis()->GetXmin();
331  // get last data point
332  TGraph* g=(TGraph*)gr->GetListOfGraphs()->At(1);
333  double yg,xg;
334  g->GetPoint((int)(g->GetN()*0.6),xg,yg);
335  if(fabs(max-yg)>fabs(min-yg)){
336  yc=ycenter+0.44;
337  }
338  else{
339  yc=ycenter+0.44;
340  }
341 
342 
343  }
344 
345  xc=xcenter-0.05;
346  //xc=xcenter+0.1;
347 
348  TLatex* waveL=new TLatex(xc,yc,wave);
349  waveL->SetNDC();
350  if(isIntens)waveL->SetTextSize(0.03);
351  else waveL->SetTextSize(0.02);
352  waveL->Draw();
353 
354 
355  // fitname
356  xc=xcenter-0.03;
357  //if(right)xc=xcenter+0.1;
358  yc=ycenter+0.35;
359  TLatex* fitNameL=new TLatex(xc,yc,fitname);
360  fitNameL->SetNDC();
361  fitNameL->SetTextSize(0.05);
362  fitNameL->Draw();
363 
364  cpopup->UseCurrentStyle();
365  if(hx!=NULL)hx->SetLineColor(kMagenta);
366  cpopup->Update();
367 
368  if(plotDir.Length()>1){
369  TString filename=plotDir+title+".eps";
370  filename.ReplaceAll(".amp","");
371  filename.ReplaceAll("+","p");
372  filename.ReplaceAll("---","___");
373  filename.ReplaceAll("-","m");
374  filename.ReplaceAll("=","_to_");
375  cpopup->SaveAs(filename);
376  }
377 
378  //cpopup->Flush();
379  cerr << "###### end of plotnice" << endl;
380 }// end plotnice
381 
382 
383 void exec3event(Int_t event, Int_t x, Int_t y, TObject *selected)
384 {
385  TCanvas *c = (TCanvas *) gTQSender;
386  //if(selected->IsA()->GetName())
387  //printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s\n", c->GetName(),event, x, y, selected->IsA()->GetName());
388 
389  if(event==1){ // clicked
390 
391  // figure out which pad we clicked onto
392  TVirtualPad* pad=c->GetClickSelectedPad();
393 
394  plotNice(pad);
395  }
396 }
397 
398 //------------------------------------------------------
399 //------------------------------------------------------
400 //------------------------------------------------------
401 //------------------------------------------------------
402 //------------------------------------------------------
403 
404 // plotlevel:
405 // 0 = data + fit + component
406 // 1 = data + fit
407 // 2 = data only
408 
409 void plotMassDepFitResult(TString infilename, TString plotdir="plots/", TString fittitle="", double mmin=0, double mmax=0, unsigned int plotLevel=0 , TString xcheckfile="", bool onlyDiag=false){
410  if(fittitle.Length()<=1)fitname=infilename;
411  else fitname=fittitle;
412  TFile* infile=TFile::Open(infilename);
413  Int_t font=132;
414  gStyle->SetTextFont(font);
415  gStyle->SetLabelFont(font,"xy");
416  gStyle->SetTitleFont(font,"xy");
417  gStyle->SetOptStat(0);
418  gStyle->SetOptTitle(0);
419  gStyle->SetStripDecimals(1);
420  TGaxis::SetMaxDigits(4);
421  gStyle->SetFrameFillStyle(0);
422  gStyle->SetFrameBorderMode(0);
423 
424  gROOT->ForceStyle();
425 
426  TFile* xcheck=NULL;
427  ifstream xcheckmapfile;
428  map<TString,TString> xcheckmap;
429  if(xcheckfile.Length()>2){
430  cerr << "Found XCheck File " << xcheckfile << endl;
431  xcheck=TFile::Open(xcheckfile);
432  xcheckfile.ReplaceAll(".root",".map");
433  xcheckmapfile.open(xcheckfile.Data());
434  TString wave, key;
435  while(xcheckmapfile.good()){
436  xcheckmapfile >> wave >> key;
437  xcheckmap[wave]=key;
438  cerr << wave << " ---> " << key << endl;
439  }
440  }
441 
442 
443 
444 
445  TList* keylist=infile->GetListOfKeys();
446  unsigned int num=keylist->GetEntries();
447 
448  // loop over keys and count waves
449  vector<TString> wavenames;
450 
451  for(unsigned int i=0;i<num;++i){
452  TString keyname(((TKey*)keylist->At(i))->GetName());
453  if(keyname.Contains("dPhi") || keyname.Contains("Re") || keyname.Contains("Im") || keyname.Contains("fPS"))continue;
454  wavenames.push_back(keyname);
455  }
456 
457 
458 
459  unsigned int nwaves=wavenames.size();
460  std::cout << nwaves << " waves used in fit" << endl;
461 
462  map<TString,TString> xcheckmapReIm;
463  for(unsigned int i=0;i<nwaves;++i){
464 TString map1=xcheckmap[wavenames[i]];
465  unsigned int index1=atoi(map1(1,2).Data());
466  for(unsigned int j=i+1;j<nwaves;++j){
467  TString keyRe="Re_"+wavenames[i]+"---"+wavenames[j];
468  TString keyIm="Im_"+wavenames[i]+"---"+wavenames[j];
469  TString map2=xcheckmap[wavenames[j]];
470  // extract index number
471  unsigned int index2=atoi(map2(1,2).Data());
472  TString ReMapper="h";ReMapper+= 10000+100*index1+index2;
473  TString ImMapper="h";ImMapper+= 20000+100*index1+index2;
474  xcheckmapReIm[keyRe]=ReMapper;
475  xcheckmapReIm[keyIm]=ImMapper;
476  }
477  } // end loop to build xcheckmap
478 
479 
480 
481  TCanvas* cS=new TCanvas("cS","Spin Density Matrix",10,10,1000,1000);
482  cS->Divide(nwaves,nwaves,0,0);
483  TCanvas* cRe=new TCanvas("cRe","Spin Density Matrix - RealImagPart",10,10,1000,1000);
484  cRe->Divide(nwaves,nwaves,0,0);
485  cRe->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0,"exec3event(Int_t,Int_t,Int_t,TObject*)");
486  cS->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0,"exec3event(Int_t,Int_t,Int_t,TObject*)");
487 
488  TCanvas* cpopup=new TCanvas("cpopup","PopUp",50,50,700,700);
489 
490 
491  // TCanvas* cIm=new TCanvas("cIm","Spin Density Matrix - ImagPart",10,10,1000,1000);
492  //cIm->Divide(nwaves,nwaves,0,0);
493 
494  // cRe->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0,
495  // "exec3event(Int_t,Int_t,Int_t,TObject*)");
496  //c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0,
497  // "exec3event(Int_t,Int_t,Int_t,TObject*)");
498 
499  // do plotting
500  for(unsigned int ip=0;ip<nwaves;++ip){
501  for(unsigned int jp=ip;jp<nwaves;++jp){
502  cS->cd(jp+ip*nwaves+1);
503  cerr << " ##### " << ip << "-" << jp << " ###### " << endl;
504  if(ip==jp){
505  TMultiGraph* g=(TMultiGraph*)infile->Get(wavenames[ip]);
506 
507  // remove components and phase space graphs
508  // plotlevel:
509  // 0 = data + fit + component
510  // 1 = data + fit
511  // 2 = data only
512  if(plotLevel>0){
513  for(unsigned int i=g->GetListOfGraphs()->GetSize()-1;i>2;--i){
514  g->GetListOfGraphs()->RemoveAt(i);
515  }
516  }
517  // remove only ps
518  else g->GetListOfGraphs()->RemoveAt(3);
519 
520 
521 
522  if(plotLevel>1)g->GetListOfGraphs()->RemoveAt(2); // remove fit
523  g->Draw("APC");
524 
525 // rescale
526  TGraphErrors* datag=(TGraphErrors*)g->GetListOfGraphs()->At(1);
527  double* y=datag->GetY();
528  double max=-1E6;
529  double min=1E6;
530  for(unsigned int i=0;i<datag->GetN();++i){
531  if(max<y[i])max=y[i];
532  if(min>y[i])min=y[i];
533  }
534  cout << min << " " << max << endl;
535  //g->GetYaxis()->SetRangeUser(0 < min ? -0.8*min : 1.2*min,1.2*max);
536  g->GetYaxis()->SetTitle("intensity");
537  g->GetYaxis()->SetTitleOffset(1.3);
538 
539  if(mmin!=0 || mmax!=0){
540  g->GetXaxis()->SetRangeUser(mmin,mmax);
541  }
542  //g->GetHistogram()->Draw();//gPad->Update();
543  //g->Draw("APC");
544  cRe->cd(jp+ip*nwaves+1);
545  g->Draw("APC");
546 
547  if(xcheck!=NULL){
548  // get key
549  TString xcheckkey=xcheckmap[wavenames[ip]];
550  cerr << "Adding xcheckplot " << xcheckkey << endl;
551  if(xcheckkey!=""){
552  TH1* xh=(TH1*)xcheck->Get(xcheckkey);
553  if(xh!=NULL){
554  xh->SetLineColor(kMagenta);
555  xh->Draw("same");
556  }
557  else cerr << "Did not find xcheckPlot!" << endl;
558  }
559  }
560  /*
561  TCanvas* c2=new TCanvas();
562  g->Draw("APC");
563  g->GetXaxis()->SetTitle("mass (MeV/c^{2})");
564  g->GetYaxis()->SetTitle("Intensity");
565  g->GetYaxis()->SetTitleOffset(1.2);
566  g->SaveAs(TString(plotdir+wavenames[ip]+".eps"));
567  delete c2;
568  */
569  plotNice(cRe->GetPad(jp+ip*nwaves+1),plotdir);
570  }
571  else {
572  if(onlyDiag)continue;
573  TString key="dPhi_"+wavenames[ip]+"---"+wavenames[jp];
574  cerr << key << endl;
575  TMultiGraph* g=(TMultiGraph*)infile->Get(key);
576  if(g!=NULL){
577  TString title=g->GetName();
578  unsigned int i = title.Index("---");
579  TString wave1=title(5,i-5);
580  TString wave2=title(i+3,title.Length());
581  // check for same reflectivity
582  if(wave1(6)!=wave2(6)) continue;
583 
584  if(plotLevel>1)g->GetListOfGraphs()->RemoveAt(2); // remove fit
585  g->Draw("AN");
586  if(mmin!=0 || mmax!=0){
587  g->GetXaxis()->SetRangeUser(mmin,mmax);
588  }
589  double max=-1E6;
590  double min=1E6;
591  TGraphErrors* fitg=(TGraphErrors*)g->GetListOfGraphs()->At(2);
592  if(fitg!=NULL){
593  double* y=fitg->GetY();
594  for(unsigned int i=0;i<fitg->GetN();++i){
595  if(max<y[i])max=y[i];
596  if(min>y[i])min=y[i];
597  }
598  }
599  TAxis* a=g->GetYaxis();
600  if(a!=NULL)a->SetRangeUser(0.5*(max+min)-220,0.5*(max+min)+220);
601  a->SetTitle("#Delta#phi");
602  a->SetTitleOffset(1.3);
603  g->Draw("A");
604  plotNice(cS->GetPad(jp+ip*nwaves+1),plotdir);
605  //TCanvas* c2=new TCanvas();
606  //g->Draw("A");
607  //g->GetXaxis()->SetTitle("mass (MeV/c^{2})");
608  //g->GetYaxis()->SetTitle("#Delta #phi");
609  //g->GetYaxis()->SetTitleOffset(1.2);
610  //c2->SaveAs(TString(plotdir+key+".eps"));
611  //delete c2;
612  key.ReplaceAll("dPhi","Re");
613  TMultiGraph* g2=(TMultiGraph*)infile->Get(key);
614  if(plotLevel>1)g2->GetListOfGraphs()->RemoveAt(2);
615  TVirtualPad* pa= cRe->cd(jp+ip*nwaves+1);
616  pa->SetFillColor(RECOLOR);
617  g2->Draw("A");
618  if(mmin!=0 || mmax!=0){
619  g2->GetXaxis()->SetRangeUser(mmin,mmax);
620  }
621  g2->GetXaxis()->SetTitle("mass (MeV/c^{2})");
622  g2->GetYaxis()->SetTitle("real part");
623  g2->GetYaxis()->SetTitleOffset(1.3);
624 
625  if(xcheck!=NULL){
626  // get key
627  TString xcheckkey=xcheckmapReIm[key];
628  cerr << "Adding xcheckplot " << xcheckkey << endl;
629  if(xcheckkey!=""){
630  TH1* xh=(TH1*)xcheck->Get(xcheckkey);
631  if(xh!=NULL){
632  xh->SetLineColor(kMagenta);
633  xh->Draw("same");
634  }
635  else cerr << "Did not find xcheckPlot!" << endl;
636  }
637  }
638 
639 
640  plotNice(cRe->GetPad(jp+ip*nwaves+1),plotdir);
641  //c2=new TCanvas();
642  //g2->Draw("A");
643  //g2->GetXaxis()->SetTitle("mass (MeV/c^{2})");
644  //g2->GetYaxis()->SetTitle("Re(#rho_{ij})");
645  //g2->GetYaxis()->SetTitleOffset(1.2);
646  //c2->SaveAs(TString(plotdir+key+".eps"));
647  //delete c2;
648  key.ReplaceAll("Re","Im");
649  TMultiGraph* g3=(TMultiGraph*)infile->Get(key);
650  if(plotLevel>1)g3->GetListOfGraphs()->RemoveAt(2);
651  //cIm->cd(jp+ip*nwaves+1);
652  pa=cRe->cd(ip+jp*nwaves+1);
653  pa->SetFillColor(IMCOLOR);
654  g3->Draw("A");
655  if(mmin!=0 || mmax!=0){
656  g3->GetXaxis()->SetRangeUser(mmin,mmax);
657  }
658  g3->GetXaxis()->SetTitle("mass (MeV/c^{2})");
659  g3->GetYaxis()->SetTitle("imaginary part");
660  g3->GetYaxis()->SetTitleOffset(1.3);
661 
662 if(xcheck!=NULL){
663  // get key
664  TString xcheckkey=xcheckmapReIm[key];
665  cerr << "Adding xcheckplot " << xcheckkey << endl;
666  if(xcheckkey!=""){
667  TH1* xh=(TH1*)xcheck->Get(xcheckkey);
668 
669  if(xh!=NULL){
670  xh->Scale(-1);
671  xh->SetLineColor(kMagenta);
672  xh->Draw("same");
673  }
674  else cerr << "Did not find xcheckPlot!" << endl;
675  }
676  }
677 
678 
679  plotNice(cRe->GetPad(ip+jp*nwaves+1),plotdir);
680  //c2=new TCanvas();
681  //g3->Draw("A");
682  //g3->GetXaxis()->SetTitle("mass (MeV/c^{2})");
683  // g3->GetYaxis()->SetTitle("Im(#rho_{ij})");
684  //g2->GetYaxis()->SetTitleOffset(1.2);
685  //c2->SaveAs(TString(plotdir+key+".eps"));
686  //delete c2;
687 
688  }// end if g!=NULL
689  } // end else
690  } // end inner loop
691  } // end plotting loop
692 
693  cS->SaveAs(TString(plotdir+"/spindensitymatrix.eps"));
694  cRe->SaveAs(TString(plotdir+"/spindensitymatrixRe.eps"));
695  //cIm->SaveAs(TString(plotdir+"/spindensitymatrixIm.eps"));
696 }
697 
698 
699