Ejemplo n.º 1
0
ReverseXAxis (TGraphAsymmErrors *g, double  size)
{
// Remove the current axis
   g->GetXaxis()->SetLabelOffset(999);
   g->GetXaxis()->SetTickLength(0);

//  Redraw the new axis 
   gPad->Update();

	g->GetYaxis()->SetTitle("Event Selection Efficiency");
   TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
                                gPad->GetUymin(),
                                gPad->GetUxmin(),
                                gPad->GetUymin(),
                                g->GetXaxis()->GetXmin(),
                                g->GetXaxis()->GetXmax(),
                                510,"-");
   newaxis->SetLabelOffset(-0.04);
   newaxis->SetTitle("Centrality");
   newaxis->SetTitleFont(42);
   newaxis->SetTitleSize(size);
   newaxis->SetLabelSize(size);
   newaxis->CenterTitle();
   newaxis->SetLabelFont(42);
   newaxis->Draw();


}
Ejemplo n.º 2
0
//==========================================
//==========================================
void plotPair(TH1F *h1,TH1F *h0 ) {
  h1->Draw();

  // edit fonts/sizes
  TAxis *ax =h1->GetYaxis(); 
  float ss=ax->GetTitleSize();
  //printf("ss=%f\n",ss);
  ax->SetTitleSize(2*ss);
  ax->SetTitleOffset(0.5);
  ax =h1->GetXaxis(); 
 ax->SetTitleSize(1.5*ss);
 ax->SetLabelSize(1.5*ss);
 ax->SetTitleOffset(0.7);
 

  // edit fonts/sizes DONE



  gPad->Update();
  //scale hint1 to the pad coordinates
  Float_t rightmax = 1.1*h0->GetMaximum();
  Float_t scale = gPad->GetUymax()/rightmax;
  h0->Scale(scale);
  h0->Draw("same");
   
  //draw an axis on the right side
  TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
	      gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"-R");
  int col=h0->GetLineColor();
  axis->SetLineColor(col);
  
  axis->SetTextColor(col);
  axis->SetLabelColor(col);
  axis ->SetTitle("LCP yield");
 axis->SetTitleSize(2*ss);
 axis->SetTitleOffset(.5);

  axis->Draw();
  
  
  TPaveStats *st =( TPaveStats *)gPad->GetPrimitive("stats");
  st->SetX1NDC(0.35);
  st->SetX2NDC(0.5);
  st->SetY1NDC(0.7);
  st->SetY2NDC(1.);
}
Ejemplo n.º 3
0
void plot_figure(TString fn,TPad *thePad,bool saxis=false,float ymin=-2.0,float ymax=1.0,bool with_d=false) {
//cout<<"wit"<<with_d<<endl;

gStyle->SetOptFit();
gStyle->SetPadTickY(1);

gStyle->SetLineStyleString(11,"40 20");
float xmin=0,xmax=2;

thePad->cd();
//thePad->SetGrid();

/*****************************************************
 Colors
*****************************************************/
int HRMcol=kRed+2;
int RNAcol=kMagenta;
int QGScol=kGreen+1;

float kb2b=1000;
Double_t x,y;
/*****************************************************
 Format the pad
*****************************************************/

thePad->SetTopMargin(0.15);
TH1F *hr = thePad->DrawFrame(xmin,ymin,xmax,ymax);
hr->SetXTitle("Q (GeV)");
hr->SetYTitle("t_{20}");
/*hr->GetYaxis()->SetTitleOffset(1.5);
hr->GetYaxis()->SetTitleSize(.06);
hr->GetYaxis()->SetTitleFont(42);
hr->GetYaxis()->CenterTitle();
hr->GetXaxis()->SetTitleSize(.06);
hr->GetXaxis()->SetTitleFont(42);
*//*****************************************************
  Draw legend
*****************************************************/

TLegend *dummylegend=new TLegend();
TLegend *legend=new TLegend(0.59,0.17,0.94,0.55);
legend->SetMargin(0.2);
legend->SetTextFont(72);
legend->SetTextSize(0.035);
legend->SetFillStyle(0);
legend->SetBorderSize(0);
legend->Draw();

TLegend *thlegend=new TLegend(0.23,0.64,0.57,0.84);
thlegend->SetMargin(0.2);
thlegend->SetTextFont(72);
thlegend->SetTextSize(0.035);
thlegend->SetFillStyle(0);
thlegend->SetBorderSize(0);
thlegend->Draw();

thePad->SetLeftMargin(0.19);
/*****************************************************
  Draw top axis
*****************************************************/
float titlex1=0.47, titley1=0.85,titlex2=0.56,titley2=0.95;

if (saxis) {
  titley1=0.72;titley2=0.82;
  TGaxis *axispp = new TGaxis(thePad->GetUxmin(),thePad->GetUymax()*1,
		 thePad->GetUxmax(),
		 thePad->GetUymax()*1,
		 xmin*0.1973,
		 xmax*0.1973,510,"-R");
  axispp->SetTitle("Q (GeV)");
  axispp->SetLabelFont(42);
  axispp->SetLabelSize(0.04);
  axispp->SetTitleFont(42);
  axispp->SetTitleSize(.055);
  axispp->Draw();
}
/*****************************************************
    Make Title
*****************************************************/
//TPaveLabel *label = new TPaveLabel(titlex1,titley1,titlex2,titley2,"^{3}He(#gamma,pp)n","NDC");
//label->SetTextSize(0.7);
//label->SetFillStyle(0);
//label->SetTextFont(42);
//label->SetBorderSize(0);
//label->Draw();
//TPaveLabel *label = new TPaveLabel(titlex1,titley1-0.06,titlex2,titley2-0.06,"90#circc.m.","NDC");
//label->SetTextSize(0.5);
//label->SetFillStyle(0);
//label->SetTextFont(42);
//label->SetBorderSize(0);
//label->Draw();
/*--------------------------------------------------------------------------------------
    Constants?
---------------------------------------------------------------------------------------*/
  Double_t xmd = 1.875613;
  Double_t xmdsq = xmd*xmd;
  Double_t q0sq = 1.15;
  Double_t degr = 0.01745329252;
  Double_t xhbarc = 0.1973;

/*--------------------------------------------------------------------------------------
    Plot IMII modelfor t20
 ---------------------------------------------------------------------------------------*/
  const Int_t npt = 94;
  //Double_t x, y;
  Double_t qfm[npt];
  Double_t qsqpt[npt] = {0.0003893797, 0.003893797, 0.03893797, 0.05840695, 0.07787593, 0.09734491, 0.1168139, 0.1362829, 
		       0.1557519, 0.1752208, 0.1946898, 0.2530968, 0.3115037, 0.3893797, 0.4672556, 0.5451315, 
		       0.6230075, 0.7008834, 0.7787593, 0.8566352, 0.9345112, 1.012387, 1.090263, 1.168139, 1.246015, 
		       1.323891, 1.401767, 1.479643, 1.557519, 1.596457, 1.635395, 1.674333, 1.71327, 1.752208, 
		       1.810615, 1.830084, 1.869022, 1.90796, 1.946898, 1.985836, 2.024774, 2.063712, 2.10265, 
		       2.141588, 2.180526, 2.219464, 2.258402, 2.29734, 2.336278, 2.375216, 2.414154, 2.453092, 
		       2.49203, 2.530968, 2.569906, 2.608844, 2.647782, 2.68672, 2.725658, 2.803534, 2.881409, 
		       2.959285, 3.037161, 3.115037, 3.309727, 3.504417, 3.699107, 3.893797, 4.088486, 4.283176, 
		       4.477866, 4.672556, 4.867246, 5.061936, 5.256625, 5.451315, 5.646005, 5.840695, 6.035385, 
		       6.230075, 6.424764, 6.619454, 6.716799, 6.814144, 6.911489, 7.008834, 7.106179, 7.203524, 
		       7.300869, 7.398214, 7.495558, 7.592903, 7.690248, 7.787593};
  Double_t t20theory[npt] = {-0.001309568, -0.0131055, -0.1318868, -0.1984704, -0.2654408, -0.3327329, -0.4002368, -0.4677915,
			 -0.5351828, -0.6021447, -0.668362, -0.8587877, -1.027779, -1.198694, -1.286326, -1.282388,
			 -1.197382, -1.054978, -0.8820486, -0.7009335, -0.5265257, -0.3668914, -0.2252485, -0.1019077,
			 0.004321276, 0.09524616, 0.1728195, 0.238883, 0.2950801, 0.3199333, 0.3428342, 0.3639258,
			 0.3833423, 0.4012027, 0.4253075, 0.432676, 0.4464807, 0.4591073, 0.4706305, 0.4811208, 
			 0.4906344, 0.4992296, 0.506956, 0.5138575, 0.5199757, 0.5253475, 0.5300049, 0.5339787, 
			 0.5372949, 0.539977, 0.5420477, 0.5435232, 0.5444235, 0.5447623, 0.5445543, 0.5438103, 
			 0.5425456, 0.540766, 0.5384844, 0.5324458, 0.5245013, 0.514713, 0.5031468, 0.4898722, 
			 0.4497016, 0.4006593, 0.3444063, 0.2827923, 0.2178549, 0.1514989, 0.08547981, 0.02124835, 
			 -0.04018853, -0.09806195, -0.1520174, -0.2019219, -0.2477681, -0.2898, -0.3282607, -0.3633281,
			 -0.3951718, -0.4241511, -0.4375907, -0.4502916, -0.4622216, -0.473322, -0.4835232, -0.4927239, 
			 -0.500801, -0.5076282, -0.513053, -0.516797, -0.5184837, -0.5176145};
  //FILE *fp = fopen("im2.dat","r");
  for (Int_t i=0;i<npt;i++) {
  //  Int_t ncols = fscanf(fp,"%f, %f",&x, &y);
  //  qsqpt[i] = x;
  //  t20theory[i] = y;
    qfm[i] = qsqpt[i]**(0.5)/xhbarc;
    //  printf(" line %d read: %f %f \n",i,qsqpt[i],t20theory[i]);
  }
  //fclose(fp);
//TGraph* gQGS=new TGraph("log170_89.dat","%lg %lg");
  gQGS = new TGraph(npt,qsqpt,t20theory);
  gQGS->SetLineColor(kMagenta);
  gQGS->SetMarkerStyle(20);
  gQGS->SetMarkerSize(1.3);
  gQGS->SetLineStyle(11);
  gQGS->SetLineWidth(2);
gQGS->Draw("l");
thlegend->AddEntry(gQGS,"IMII","L");
/*--------------------------------------------------------------------------------------
    Plot IMII+ME modelfor t20
 ---------------------------------------------------------------------------------------*/
  Double_t t20theoryme[npt] = {-0.001325945, -0.01328168, -0.1349228, -0.2041014, -0.2743705, -0.3456319, -0.4177289, -0.4904376,
			       -0.5634585, -0.6364107, -0.7088243, -0.9168859, -1.095754, -1.251422, -1.277469, -1.170903,
			       -0.9677308, -0.7200701, -0.4713423, -0.2466468, -0.05555869, 0.101535, 0.2283672, 0.3298602,
			       0.4107891, 0.4752683, 0.5266488, 0.567598, 0.6002075, 0.6139116, 0.6261154, 0.6369641,
			       0.6465931, 0.6551208, 0.6660647, 0.6692667, 0.6750632, 0.6801088, 0.6844693, 0.6882072,
			       0.6913724, 0.694014, 0.6961743, 0.6978924, 0.6992062, 0.7001432, 0.7007343, 0.701005,
			       0.7009771, 0.7006715, 0.7001097, 0.6993112, 0.6982906, 0.6970643, 0.6956426, 0.6940377,
			       0.6922587, 0.6903158, 0.6882191, 0.6836015, 0.6784688, 0.6728624, 0.6668122, 0.6603509,
			       0.6425963, 0.622676, 0.6008623, 0.5773537, 0.5521636, 0.5259722, 0.4991099, 0.4706432,
			       0.4410795, 0.4127616, 0.3872456, 0.3640124, 0.3422358, 0.3246932, 0.3143134, 0.3116054,
			       0.3142227, 0.3184956, 0.3200235, 0.3212056, 0.3227668, 0.3250734, 0.3281051, 0.3321319,
			       0.3372873, 0.3437867, 0.351448, 0.3600231, 0.3689893, 0.3779735};
TGraph* gRNA=new TGraph(npt,qsqpt,t20theoryme);
gRNA->SetLineColor(kRed);
gRNA->SetMarkerStyle(1);
gRNA->SetMarkerSize(1.3);
gRNA->SetLineStyle(11);
gRNA->SetLineWidth(3);
gRNA->Draw("l");
thlegend->AddEntry(gRNA,"IM+E II","L");
/*--------------------------------------------------------------------------------------
    Dan Phillips no rpg(f/g=0)
 ---------------------------------------------------------------------------------------*/
 const Int_t nph = 66;
 Double_t qph[nph] = { 0.01, 0.25,  0.5,  0.75,   1.0,    1.5,    2.0,    2.5,    3.0,    4.0,
		        5.0,  6.0,  7.0,   8.0,   9.0,   10.0,   11.0,   12.0,   13.0,   14.0,
		       15.0, 16.0, 17.0,  18.0,  19.0,   20.0,   21.0,   22.0,   23.0,   24.0,
		       25.0, 26.0, 27.0,  28.0,  29.0,   30.0,   31.0,   32.0,   33.0,   34.0,
		       35.0, 36.0, 37.0,  38.0,  39.0,   40.0,   41.0,   42.0,   43.0,   44.0,
		       45.0, 47.5, 50.0,  52.5,  55.0,   57.5,   60.0,   62.5,   65.0,   70.0,
		       75.0, 80.0, 85.0,  90.0,  95.0,  100.0};
 for (Int_t i=0;i<nph;i++) {qph[i] = qph[i]*xhbarc**2;}
 Double_t tphrpg0[nph] = {-0.00139028, -0.0347797, -0.0705278, -0.106823, -0.143214, -0.215941, -0.28903, -0.36176, -0.437352, -0.594782,
			  -0.753442, -0.905365, -1.04209, -1.14824, -1.2301, -1.27076, -1.26585, -1.21681, -1.13043, -1.01648,
			  -0.885684, -0.7701, -0.630809, -0.495011, -0.366781, -0.248492, -0.141153, -0.0449377, 0.0407569, 0.116675,
			  0.183835, 0.230211, 0.284553, 0.332797, 0.375647, 0.41358, 0.447136, 0.476061, 0.502346, 0.525668,
			  0.546396, 0.561598, 0.57851, 0.593626, 0.607141, 0.619222, 0.630017, 0.638943, 0.647659, 0.655433,
			  0.662379, 0.675447, 0.686163, 0.693653, 0.698255, 0.70103, 0.701985, 0.701414, 0.699577, 0.696913,
			  0.68897, 0.68092, 0.673572, 0.668027, 0.665207, 0.664439};

TGraph* gph=new TGraph(nph,qph,tphrpg0);
gph->SetLineColor(9);
gph->SetMarkerStyle(1);
gph->SetMarkerSize(1.3);
gph->SetLineStyle(1);
gph->SetLineWidth(3);
gph->Draw("l");
thlegend->AddEntry(gph,"#rho#pi#gamma f/g=0","L");

 Double_t tphrpg3[nph] = {-0.00139212, -0.0348353, -0.0706589, -0.10705, -0.143559, -0.216597, -0.290087, -0.363321, -0.439532, -0.598654,
			  -0.759312, -0.913351, -1.0519, -1.15918, -1.24066, -1.27901, -1.2698, -1.21493, -1.12197, -1.00156,
			  -0.865071, -0.744981, -0.60214, -0.464095, -0.334789, -0.216384, -0.109662, -0.0145868, 0.069612, 0.143819,
			  0.20915, 0.254731, 0.307099, 0.353368, 0.394259, 0.43028, 0.461982, 0.489554, 0.51413, 0.535803,
			  0.554941, 0.568991, 0.584356, 0.59797, 0.610026, 0.620686, 0.630093, 0.63772, 0.645084, 0.651525,
			  0.657156, 0.666024, 0.673624, 0.678127, 0.679481, 0.67949, 0.677837, 0.674823, 0.670722, 0.662356,
			  0.650039, 0.638996, 0.628928, 0.620671, 0.614933, 0.610454};

 //TGraph* gph3=new TGraph(nph,qph,tphrpg3);
 //gph3->SetLineColor(39);
 //gph3->SetMarkerStyle(1);
 //gph3->SetMarkerSize(1.3);
 //gph3->SetLineStyle(2);
 //gph3->SetLineWidth(2);

 //TPaveLabel * Label = new TPaveLabel(0.20,0.66,0.48,0.71,"Propagator f/g=3","NDC");
 //Label->SetTextSize(0.6);
 //Label->SetLineColor(kWhite);
 //Label->SetFillColor(kWhite);
//Label->SetTextColor(39);
//Label->SetBorderSize(0);
//Label->Draw();
//gph3->Draw("l");

 Double_t tphrpg6[nph] = {-0.00139403, -0.0348929, -0.0707944, -0.107286, -0.143917, -0.217276, -0.29118, -0.364936, -0.441787, -0.602659,
			  -0.765378, -0.921581, -1.06195, -1.17027, -1.25116, -1.28686, -1.27292, -1.21183, -1.11202, -0.985056,
			  -0.84299, -0.718589, -0.572616, -0.432822, -0.302967, -0.184961, -0.0793357, 0.0141671, 0.0964853, 0.168642,
			  0.231842, 0.276257, 0.326398, 0.370465, 0.409197, 0.443123, 0.472809, 0.498773, 0.52149, 0.541377,
			  0.558796, 0.571442, 0.58515, 0.597161, 0.607665, 0.616818, 0.624764, 0.630973, 0.636932, 0.642002,
			  0.646291, 0.650319, 0.654857, 0.656509, 0.654827, 0.652371, 0.648479, 0.643459, 0.637587, 0.622962,
			  0.607813, 0.595048, 0.583592, 0.574033, 0.566854, 0.560502};

 TGraph* gph6=new TGraph(nph,qph,tphrpg6);
 gph6->SetLineColor(49);
 gph6->SetMarkerStyle(1);
 gph6->SetMarkerSize(1.3);
 gph6->SetLineStyle(1);
 gph6->SetLineWidth(2);
gph6->Draw("l");
thlegend->AddEntry(gph6,"#rho#pi#gamma f/g=6.1","L");

/*--------------------------------------------------------------------------------------
    put line at -root(2)
---------------------------------------------------------------------------------------*/
Int_t n = 2;
float xfm[2] = {0., 9.};
float yt20[2] = {0., 0.}; 
TGraph* g0=new TGraph(n,xfm,yt20);
g0->SetLineColor(1);
g0->SetMarkerStyle(1);
g0->SetMarkerSize(1.3);
g0->SetLineStyle(1);
g0->SetLineWidth(1);
g0->Draw("l");
yt20[0] = -1.*2**(0.5);
yt20[1] = yt20[0];
xfm[1] = 1.;
TGraph* g1=new TGraph(n,xfm,yt20);
g1->SetLineColor(1);
g1->SetMarkerStyle(1);
g1->SetMarkerSize(1.3);
g1->SetLineStyle(3);
g1->SetLineWidth(1);
g1->Draw("l");

/*  sanity checks
plots11dsdtSet(100,0.040,0.020,0.05,0.000,0.140,kBlack,legend,"E03-101 140 MeV Bins Pn< 100 Mev/c 80 mr X 40 mr");
*/

/*  PRL */
//plotSet(kBlue,legend,"T_{20}");
//plotSet(kBlue,legend,"");
plotSet(kBlue,legend,"");
//plots11dsdtSet(kBlue,legend,"");


/*****************************************************
 Add the rest of the legend enteries
*****************************************************/

//if(!with_d){
//legend->AddEntry(gQGS,"QGS","l");
//legend->AddEntry(gRNA,"RNA","l");
//legend->AddEntry(gHRM,"HRM","F");
//};
gStyle->SetPaperSize(20,26);  //default
//TPaveLabel *label = new TPaveLabel(0.5,0.4,0.85,0.5,"Preliminary","NDC");
//label->SetTextColor(kBlue);
//label->Draw();
//cout<<with_d<<endl;
c->SaveAs(fn+".pdf");
c->SaveAs(fn+".eps");
c->SaveAs(fn+".png");
}
Ejemplo n.º 4
0
void plot_figure(TString fn,TPad *thePad,bool saxis=false,float ymin=1.0e-10,float ymax=1.0e-02,bool with_d=false) {
//cout<<"wit"<<with_d<<endl;

gStyle->SetOptFit();
gStyle->SetPadTickY(1);
//gStyle->SetLogY();

gStyle->SetLineStyleString(11,"40 20");
float xmin=0,xmax=4;

thePad->cd();
thePad->SetLogy();
//thePad->SetGrid();

/*****************************************************
 Colors
*****************************************************/
int HRMcol=kRed+2;
int RNAcol=kMagenta;
int QGScol=kGreen+1;

Double_t x,y;
/*****************************************************
 Format the pad
*****************************************************/

thePad->SetTopMargin(0.15);
TH1F *hr = thePad->DrawFrame(xmin,ymin,xmax,ymax);
hr->SetXTitle("Q^{2} (GeV^{2})");
hr->SetYTitle("B");
hr->GetYaxis()->SetTitleOffset(1.5);
hr->GetYaxis()->SetTitleSize(.06);
hr->GetYaxis()->SetTitleFont(42);
hr->GetYaxis()->CenterTitle();
hr->GetXaxis()->SetTitleSize(.06);
hr->GetXaxis()->SetTitleFont(42);
/*****************************************************
  Draw legend
*****************************************************/

TLegend *dummylegend=new TLegend();
TLegend *legend=new TLegend(0.66,0.64,0.93,0.84);
legend->SetMargin(0.2);
legend->SetTextFont(72);
legend->SetTextSize(0.035);
legend->SetFillStyle(0);
legend->SetBorderSize(0);
legend->Draw();

TLegend *thlegend=new TLegend(0.33,0.64,0.66,0.84);
thlegend->SetMargin(0.2);
thlegend->SetTextFont(72);
thlegend->SetTextSize(0.035);
thlegend->SetFillStyle(0);
thlegend->SetBorderSize(0);
thlegend->Draw();

thePad->SetLeftMargin(0.19);
/*****************************************************
  Draw top axis
*****************************************************/
float titlex1=0.47, titley1=0.85,titlex2=0.56,titley2=0.95;

if (saxis) {
  titley1=0.72;titley2=0.82;
  TGaxis *axispp = new TGaxis(thePad->GetUxmin(),thePad->GetUymax(),
		 thePad->GetUxmax(),
		 thePad->GetUymax(),
		 xmin/0.1973**2,
		 xmax/0.1973**2,510,"-R");
  axispp->SetTitle("Q^{2} (fm^{-2})");
  axispp->SetLabelFont(42);
  axispp->SetLabelSize(0.04);
  axispp->SetTitleFont(42);
  axispp->SetTitleSize(.055);
  axispp->Draw();
}
/*****************************************************
    Make Title
*****************************************************/
//TPaveLabel *label = new TPaveLabel(titlex1,titley1,titlex2,titley2,"^{3}He(#gamma,pp)n","NDC");
//label->SetTextSize(0.7);
//label->SetFillStyle(0);
//label->SetTextFont(42);
//label->SetBorderSize(0);
//label->Draw();
//TPaveLabel *label = new TPaveLabel(titlex1,titley1-0.06,titlex2,titley2-0.06,"90#circc.m.","NDC");
//label->SetTextSize(0.5);
//label->SetFillStyle(0);
//label->SetTextFont(42);
//label->SetBorderSize(0);
//label->Draw();
/*--------------------------------------------------------------------------------------
    Constants?
---------------------------------------------------------------------------------------*/
  Double_t xmd = 1.875613;
  Double_t xmdsq = xmd*xmd;
  Double_t q0sq = 1.15;
  Double_t degr = 0.01745329252;
  Double_t xhbarc = 0.1973;

/*--------------------------------------------------------------------------------------
    Plot IMII modelfor B
 ---------------------------------------------------------------------------------------*/
  const Int_t npt = 95;
  //Double_t x, y;
  Double_t qfm[npt];
  Double_t qsqpt[npt] = {  0.0000,  0.0004,  0.0039,  0.0389,  0.0584,  0.0779,  0.0973,  0.1168,  0.1363,  0.1558, 
			   0.1752,  0.1947,  0.2531,  0.3115,  0.3894,  0.4673,  0.5451,  0.6230,  0.7009,  0.7788, 
			   0.8566,  0.9345,  1.0124,  1.0903,  1.1681,  1.2460,  1.3239,  1.4018,  1.4796,  1.5575, 
			   1.5965,  1.6354,  1.6743,  1.7133,  1.7522,  1.8106,  1.8301,  1.8690,  1.9080,  1.9469, 
			   1.9858,  2.0248,  2.0637,  2.1026,  2.1416,  2.1805,  2.2195,  2.2584,  2.2973,  2.3363, 
			   2.3752,  2.4142,  2.4531,  2.4920,  2.5310,  2.5699,  2.6088,  2.6478,  2.6867,  2.7257, 
			   2.8035,  2.8814,  2.9593,  3.0372,  3.1150,  3.3097,  3.5044,  3.6991,  3.8938,  4.0885, 
			   4.2832,  4.4779,  4.6726,  4.8672,  5.0619,  5.2566,  5.4513,  5.6460,  5.8407,  6.0354, 
			   6.2301,  6.4248,  6.6195,  6.7168,  6.8141,  6.9115,  7.0088,  7.1062,  7.2035,  7.3009, 
			   7.3982,  7.4956,  7.5929,  7.6902,  7.7876};
  Double_t atheory[npt]   = { 1.0710E-05,  1.0574E-04,  9.3420E-04,  3.5050E-03,  3.4115E-03, 
			      3.0845E-03,  2.6987E-03,  2.3221E-03,  1.9803E-03,  1.6807E-03, 
			      1.4229E-03,  1.2034E-03,  7.2925E-04,  4.4651E-04,  2.3739E-04, 
			      1.2959E-04,  7.2494E-05,  4.1431E-05,  2.4107E-05,  1.4229E-05, 
			      8.4877E-06,  5.0970E-06,  3.0687E-06,  1.8439E-06,  1.0999E-06, 
			      6.4724E-07,  3.7264E-07,  2.0753E-07,  1.0994E-07,  5.3905E-08, 
			      3.6143E-08,  2.3248E-08,  1.4106E-08,  7.8561E-09,  3.8096E-09, 
			      7.1157E-10,  2.6517E-10,  7.6047E-12,  3.8643E-10,  1.1987E-09, 
			      2.2880E-09,  3.5354E-09,  4.8498E-09,  6.1665E-09,  7.4371E-09, 
			      8.6270E-09,  9.7149E-09,  1.0688E-08,  1.1537E-08,  1.2263E-08, 
			      1.2867E-08,  1.3352E-08,  1.3726E-08,  1.3996E-08,  1.4171E-08, 
			      1.4259E-08,  1.4270E-08,  1.4209E-08,  1.4089E-08,  1.3914E-08, 
			      1.3434E-08,  1.2822E-08,  1.2120E-08,  1.1364E-08,  1.0584E-08, 
			      8.6526E-09,  6.8980E-09,  5.4000E-09,  4.1725E-09,  3.1908E-09, 
			      2.4208E-09,  1.8250E-09,  1.3673E-09,  1.0200E-09,  7.5739E-10, 
			      5.5948E-10,  4.1182E-10,  3.0194E-10,  2.2009E-10,  1.5958E-10, 
			      1.1516E-10,  8.2658E-11,  5.8806E-11,  4.9418E-11,  4.1436E-11, 
			      3.4661E-11,  2.8921E-11,  2.4066E-11,  1.9968E-11,  1.6516E-11, 
			      1.3608E-11,  1.1156E-11,  9.0935E-12,  7.3668E-12,  5.9294E-12};
//TGraph* gQGS=new TGraph("log170_89.dat","%lg %lg");
  gQGS = new TGraph(npt,qsqpt,atheory);
  gQGS->SetLineColor(kMagenta);
  gQGS->SetMarkerStyle(20);
  gQGS->SetMarkerSize(1.3);
  gQGS->SetLineStyle(11);
  gQGS->SetLineWidth(2);
  //TPaveLabel * Label = new TPaveLabel(0.74,0.24,0.84,0.30,"IMII","NDC");
  //Label->SetTextSize(0.6);
  //Label->SetLineColor(kWhite);
  //Label->SetFillColor(kWhite);
  //Label->SetTextColor(kMagenta);
  //Label->SetBorderSize(0);
  //Label->Draw();
gQGS->Draw("l");
thlegend->AddEntry(gQGS,"IMII","L");
/*--------------------------------------------------------------------------------------
    Plot IMII+ME modelfor B
 ---------------------------------------------------------------------------------------*/
  Double_t atheoryme[npt] =   { 1.0806E-05,  1.0669E-04,  9.4299E-04,  3.5533E-03,  3.4668E-03, 
				3.1422E-03,  2.7561E-03,  2.3777E-03,  2.0331E-03,  1.7302E-03, 
				1.4689E-03,  1.2459E-03,  7.6183E-04,  4.7094E-04,  2.5382E-04, 
				1.4061E-04,  7.9917E-05,  4.6454E-05,  2.7523E-05,  1.6562E-05, 
				1.0086E-05,  6.1936E-06,  3.8206E-06,  2.3582E-06,  1.4498E-06, 
				8.8327E-07,  5.2973E-07,  3.1019E-07,  1.7528E-07,  9.3887E-08, 
				6.6801E-08,  4.6325E-08,  3.1059E-08,  1.9921E-08,  1.1991E-08, 
				4.6073E-09,  3.0706E-09,  1.0502E-09,  1.3882E-10,  4.4654E-11, 
				5.3635E-10,  1.4329E-09,  2.5922E-09,  3.9043E-09,  5.2841E-09, 
				6.6632E-09,  8.0019E-09,  9.2634E-09,  1.0425E-08,  1.1476E-08, 
				1.2409E-08,  1.3215E-08,  1.3893E-08,  1.4448E-08,  1.4882E-08, 
				1.5208E-08,  1.5432E-08,  1.5567E-08,  1.5619E-08,  1.5596E-08, 
				1.5350E-08,  1.4883E-08,  1.4254E-08,  1.3528E-08,  1.2744E-08, 
				1.0662E-08,  8.6328E-09,  6.8749E-09,  5.3894E-09,  4.1719E-09, 
				3.2238E-09,  2.4857E-09,  1.9002E-09,  1.4523E-09,  1.1197E-09, 
				8.7045E-10,  6.7932E-10,  5.3066E-10,  4.1792E-10,  3.3449E-10, 
				2.7250E-10,  2.2493E-10,  1.8672E-10,  1.7020E-10,  1.5532E-10, 
				1.4219E-10,  1.3070E-10,  1.2068E-10,  1.1198E-10,  1.0447E-10, 
				9.8023E-11,  9.2442E-11,  8.7575E-11,  8.3244E-11,  7.9331E-11};
TGraph* gRNA=new TGraph(npt,qsqpt,atheoryme);
gRNA->SetLineColor(kRed);
gRNA->SetMarkerStyle(1);
gRNA->SetMarkerSize(1.3);
gRNA->SetLineStyle(11);
gRNA->SetLineWidth(3);

//TPaveLabel * Label = new TPaveLabel(0.72,0.34,0.89,0.40,"IM+E II","NDC");
//Label->SetTextSize(0.6);
//Label->SetLineColor(kWhite);
//Label->SetFillColor(kWhite);
//Label->SetTextColor(kRed);
//Label->SetBorderSize(0);
//Label->Draw();
gRNA->Draw("l");
thlegend->AddEntry(gRNA,"IM+E II","L");
/*--------------------------------------------------------------------------------------
    Dan Phillips no rpg(f/g=0)
 ---------------------------------------------------------------------------------------*/
 const Int_t nph = 66;
 Double_t qph[nph] = {      0.0,    0.2,    0.5,    0.8,    1.0,    1.5,    2.0,    2.5,    3.0,    4.0, 
			    5.0,    6.0,    7.0,    8.0,    9.0,   10.0,   11.0,   12.0,   13.0,   14.0, 
			   15.0,   16.0,   17.0,   18.0,   19.0,   20.0,   21.0,   22.0,   23.0,   24.0, 
			   25.0,   26.0,   27.0,   28.0,   29.0,   30.0,   31.0,   32.0,   33.0,   34.0, 
			   35.0,   36.0,   37.0,   38.0,   39.0,   40.0,   41.0,   42.0,   43.0,   44.0, 
			   45.0,   47.5,   50.0,   52.5,   55.0,   57.5,   60.0,   62.5,   65.0,   70.0, 
			   75.0,   80.0,   85.0,   90.0,   95.0,  100.0};
 for (Int_t i=0;i<nph;i++) {qph[i] = qph[i]*xhbarc**2;}
 Double_t tphrpg0[nph] = { 1.0947E-04,  1.9851E-03,  2.9335E-03,  3.3468E-03,  3.4916E-03, 
			   3.4072E-03,  3.1031E-03,  2.7207E-03,  2.3330E-03,  1.6663E-03, 
			   1.1822E-03,  8.4372E-04,  6.0546E-04,  4.3536E-04,  3.1518E-04, 
			   2.3030E-04,  1.6981E-04,  1.2638E-04,  9.4826E-05,  7.1682E-05, 
			   5.4533E-05,  4.1635E-05,  3.1895E-05,  2.4516E-05,  1.8919E-05, 
			   1.4661E-05,  1.1401E-05,  8.8907E-06,  6.9517E-06,  5.4487E-06, 
			   4.2756E-06,  3.3572E-06,  2.6366E-06,  2.0698E-06,  1.6242E-06, 
			   1.2738E-06,  9.9798E-07,  7.9339E-07,  6.2007E-07,  4.8291E-07, 
			   3.7446E-07,  2.8884E-07,  2.2138E-07,  1.6846E-07,  1.2710E-07, 
			   9.4863E-08,  6.9878E-08,  5.0644E-08,  3.5914E-08,  2.4760E-08, 
			   1.6446E-08,  7.0652E-09,  1.2173E-09,  7.6159E-12,  9.6591E-10, 
			   2.6954E-09,  4.5038E-09,  6.0939E-09,  7.3450E-09,  6.3859E-09, 
			   6.7640E-09,  6.3279E-09,  5.5286E-09,  4.5850E-09,  3.6182E-09, 
			   2.7204E-09};

TGraph* gph=new TGraph(nph,qph,tphrpg0);
gph->SetLineColor(9);
gph->SetMarkerStyle(1);
gph->SetMarkerSize(1.3);
gph->SetLineStyle(1);
gph->SetLineWidth(3);

//TPaveLabel * Label = new TPaveLabel(0.545,0.16,0.755,0.22,"#rho#pi#gamma f/g=0","NDC");
//Label->SetTextSize(0.6);
//Label->SetLineColor(kWhite);
//Label->SetFillColor(kWhite);
//Label->SetTextColor(9);
//Label->SetBorderSize(0);
//Label->Draw();
gph->Draw("l");
thlegend->AddEntry(gph,"#rho#pi#gamma f/g=0","L");

 Double_t tphrpg3[nph] = {1.0907E-04,  1.9766E-03,  2.9192E-03,  3.3286E-03,  3.4707E-03, 
			  3.3824E-03,  3.0769E-03,  2.6944E-03,  2.3073E-03,  1.6423E-03, 
			  1.1612E-03,  8.2554E-04,  5.8989E-04,  4.2211E-04,  3.0392E-04, 
			  2.2073E-04,  1.6165E-04,  1.1941E-04,  8.8865E-05,  6.6570E-05, 
			  5.0141E-05,  3.7859E-05,  2.8647E-05,  2.1720E-05,  1.6508E-05, 
			  1.2580E-05,  9.6042E-06,  7.3376E-06,  5.6085E-06,  4.2865E-06, 
			  3.2703E-06,  2.4882E-06,  1.8860E-06,  1.4224E-06,  1.0665E-06, 
			  7.9418E-07,  5.8638E-07,  4.3319E-07,  3.1260E-07,  2.2158E-07, 
			  1.5352E-07,  1.0325E-07,  6.6740E-08,  4.0856E-08,  2.3101E-08, 
			  1.1490E-08,  4.5140E-09,  9.8979E-10,  3.1737E-13,  8.5748E-10, 
			  3.0274E-09,  9.8315E-09,  1.9608E-08,  2.8845E-08,  3.6378E-08, 
			  4.1832E-08,  4.5388E-08,  4.7378E-08,  4.8091E-08,  4.4323E-08, 
			  4.0773E-08,  3.5870E-08,  3.0742E-08,  2.5819E-08,  2.1278E-08, 
			  1.7241E-08};

 //TGraph* gph3=new TGraph(nph,qph,tphrpg3);
//gph3->SetLineColor(39);
//gph3->SetMarkerStyle(1);
//gph3->SetMarkerSize(1.3);
//gph3->SetLineStyle(2);
//gph3->SetLineWidth(2);

//TPaveLabel * Label = new TPaveLabel(0.60,0.49,0.82,0.55,"Propagator f/g=3","NDC");
//Label->SetTextSize(0.6);
//Label->SetLineColor(kWhite);
//Label->SetFillColor(kWhite);
//Label->SetTextColor(39);
//Label->SetBorderSize(0);
//Label->Draw();
//gph3->Draw("l");

 Double_t tphrpg6[nph] = {1.0866E-04,  1.9679E-03,  2.9046E-03,  3.3099E-03,  3.4491E-03, 
			  3.3569E-03,  3.0500E-03,  2.6674E-03,  2.2810E-03,  1.6177E-03, 
			  1.1396E-03,  8.0697E-04,  5.7402E-04,  4.0863E-04,  2.9249E-04, 
			  2.1104E-04,  1.5343E-04,  1.1242E-04,  8.2908E-05,  6.1486E-05, 
			  4.5796E-05,  3.4145E-05,  2.5473E-05,  1.9008E-05,  1.4190E-05, 
			  1.0598E-05,  7.9092E-06,  5.8892E-06,  4.3719E-06,  3.2319E-06, 
			  2.3729E-06,  1.7267E-06,  1.2421E-06,  8.8052E-07,  6.1299E-07, 
			  4.1706E-07,  2.7536E-07,  1.7461E-07,  1.0443E-07,  5.7152E-08, 
			  2.7017E-08,  9.6080E-09,  1.5284E-09,  1.7233E-10,  3.5226E-09, 
			  1.0061E-08,  1.8644E-08,  2.8417E-08,  3.8799E-08,  4.9346E-08, 
			  5.9730E-08,  8.3215E-08,  1.0290E-07,  1.1730E-07,  1.2653E-07, 
			  1.3121E-07,  1.3238E-07,  1.3099E-07,  1.2769E-07,  1.1937E-07, 
			  1.0601E-07,  9.1747E-08,  7.8220E-08,  6.5922E-08,  5.4966E-08, 
			  4.5409E-08};

TGraph* gph6=new TGraph(nph,qph,tphrpg6);
gph6->SetLineColor(49);
gph6->SetMarkerStyle(1);
gph6->SetMarkerSize(1.3);
gph6->SetLineStyle(1);
gph6->SetLineWidth(2);

//TPaveLabel * Label = new TPaveLabel(0.23,0.16,0.45,0.22,"#rho#pi#gamma f/g=6.1","NDC");
//Label->SetTextSize(0.6);
//Label->SetLineColor(kWhite);
//Label->SetFillColor(kWhite);
//Label->SetTextColor(49);
//Label->SetBorderSize(0);
//Label->Draw();
gph6->Draw("l");
thlegend->AddEntry(gph6,"#rho#pi#gamma f/g=6.1","L");

/*  sanity checks
plots11dsdtSet(100,0.040,0.020,0.05,0.000,0.140,kBlack,legend,"E03-101 140 MeV Bins Pn< 100 Mev/c 80 mr X 40 mr");
*/

/*  PRL */
//plotSet(kBlue,legend,"T_{20}");
//plotSet(kBlue,legend,"");
plotSet(kBlue,legend,"");
//plots11dsdtSet(kBlue,legend,"");

/*****************************************************
 Add the rest of the legend enteries
*****************************************************/

//if(!with_d){
//legend->AddEntry(gQGS,"QGS","l");
//legend->AddEntry(gRNA,"RNA","l");
//legend->AddEntry(gHRM,"HRM","F");
//};
gStyle->SetPaperSize(20,26);  //default
//TPaveLabel *label = new TPaveLabel(0.5,0.4,0.85,0.5,"Preliminary","NDC");
//label->SetTextColor(kBlue);
//label->Draw();
//cout<<with_d<<endl;
c->SaveAs(fn+".pdf");
c->SaveAs(fn+".eps");
c->SaveAs(fn+".png");
}
Ejemplo n.º 5
0
void PlotPotential2D( const TString &sim, Int_t time, Int_t zoom=2, Int_t Nbins=2, const TString &options="") {

#ifdef __CINT__
    gSystem->Load("libplasma.so");
#endif

    PlasmaGlob::Initialize();

    // Palettes!
    gROOT->Macro("PlasmaPalettes.C");

    // Init Units table
    PUnits::UnitsTable::Get();

    // Load PData
    PData *pData = PData::Get(sim.Data());
    pData->LoadFileNames(time);
    if(!pData->IsInit()) return;

    TString opt = options;

    // More makeup
    gStyle->SetPadGridY(0);
    if(opt.Contains("gridx")) {
        gStyle->SetPadGridX(1);
    }
    if(opt.Contains("gridy")) {
        gStyle->SetPadGridY(1);
    }


    // Some plasma constants
    Double_t n0 = pData->GetPlasmaDensity();
    Double_t omegap = pData->GetPlasmaFrequency();
    Double_t timedepth = 1.;
    if(omegap!=0.0) timedepth = 1/omegap;
    Double_t kp = pData->GetPlasmaK();
    Double_t skindepth = 1.;
    if(kp!=0.0) skindepth = 1/kp;
    Double_t E0 = pData->GetPlasmaE0();

    // Some beam properties:
    Double_t Ebeam = pData->GetBeamEnergy();
    Double_t gamma = pData->GetBeamGamma();
    Double_t vbeam = pData->GetBeamVelocity();

    cout << Form(" - Bunch gamma      = %8.4f", gamma ) << endl;
    cout << Form(" - Bunch velocity   = %8.4f c", vbeam ) << endl;

    // Other parameters
    Float_t trapPotential = 1.0 - (1.0/gamma);
    cout << Form(" - Trap. potential  = %8.4f mc2/e",trapPotential) << endl;
    cout << endl;

    // Time in OU
    Float_t Time = pData->GetRealTime();
    // z start of the plasma in normalized units.
    Float_t zStartPlasma = pData->GetPlasmaStart()*kp;
    // z start of the beam in normalized units.
    Float_t zStartBeam = pData->GetBeamStart()*kp;
    // z start of the neutral in normalized units.
    Float_t zStartNeutral = pData->GetNeutralStart()*kp;
    // z end of the neutral in normalized units.
    Float_t zEndNeutral = pData->GetNeutralEnd()*kp;

    if(opt.Contains("center")) {
        Time -= zStartPlasma;
        if(opt.Contains("comov"))      // Centers on the head of the beam.
            Time += zStartBeam;
    }
    Float_t shiftz = pData->Shift(opt);
    //  cout << "Shift = " << shiftz << endl;


    // Calculate the "axis range" in number of bins. If Nbins==0 a RMS width is taken.
    Double_t rms0 = pData->GetBeamRmsY() * kp;
    if(pData->IsCyl())  rms0  = pData->GetBeamRmsR() * kp;

    Int_t FirstyBin = 0;
    Int_t LastyBin = 0;
    if(Nbins==0) {
        if(rms0>0.0)
            Nbins =  TMath::Nint(rms0 / pData->GetDX(1));
        else
            Nbins = 1;
    }

    // Slice width limits.
    if(!pData->IsCyl()) {
        FirstyBin = pData->GetNX(1)/2 + 1 - Nbins;
        LastyBin =  pData->GetNX(1)/2 + Nbins;
    } else {
        FirstyBin = 1;
        LastyBin  = Nbins;
    }
    // ----------------------------------------------------------------------------------


    // Get charge density histos
    Int_t Nspecies = pData->NSpecies();
    TH2F **hDen2D = new TH2F*[Nspecies];
    // Get charge density on-axis
    TH1F **hDen1D = new TH1F*[Nspecies];
    // And electric current (integrated)
    TH1F **hCur1D = new TH1F*[Nspecies];
    for(Int_t i=0; i<Nspecies; i++) {

        hDen2D[i] = NULL;

        if(!pData->GetChargeFileName(i))
            continue;

        cout << Form(" Getting charge density of specie: ") << i << endl;


        char hName[24];
        sprintf(hName,"hDen2D_%i",i);
        hDen2D[i] = (TH2F*) gROOT->FindObject(hName);
        if(hDen2D[i]) delete hDen2D[i];

        if(!pData->Is3D())
            hDen2D[i] = pData->GetCharge(i,opt);
        else
            hDen2D[i] = pData->GetCharge2DSliceZY(i,-1,Nbins,opt+"avg");

        hDen2D[i]->SetName(hName);
        hDen2D[i]->GetXaxis()->CenterTitle();
        hDen2D[i]->GetYaxis()->CenterTitle();
        hDen2D[i]->GetZaxis()->CenterTitle();

        if(opt.Contains("comov"))
            hDen2D[i]->GetXaxis()->SetTitle("k_{p} #zeta");
        else
            hDen2D[i]->GetXaxis()->SetTitle("k_{p} z");

        if(pData->IsCyl())
            hDen2D[i]->GetYaxis()->SetTitle("k_{p} r");
        else
            hDen2D[i]->GetYaxis()->SetTitle("k_{p} y");

        hDen2D[i]->GetZaxis()->SetTitle("n [n_{0}]");


        hDen1D[i] = NULL;
        hCur1D[i] = NULL;

        if(!pData->GetEfieldFileName(i))
            continue;

        sprintf(hName,"hDen1D_%i",i);
        hDen1D[i] = (TH1F*) gROOT->FindObject(hName);
        if(hDen1D[i]) delete hDen1D[i];

        // 1D histograms
        if(pData->Is3D()) {
            hDen1D[i] = pData->GetH1SliceZ3D(pData->GetChargeFileName(i)->c_str(),"charge",-1,Nbins,-1,Nbins,opt+"avg");
        } else if(pData->IsCyl()) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0).
            hDen1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",1,Nbins,opt+"avg");
        } else { // 2D cartesian
            hDen1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",-1,Nbins,opt+"avg");
        }
        hDen1D[i]->SetName(hName);

        // if(hDen1D[i]) delete hDen1D[i];
        // hDen1D[i] = (TH1F*) hE2D[i]->ProjectionX(hName,FirstyBin,LastyBin);
        // hDen1D[i]->Scale(1.0/(LastyBin-FirstyBin+1));

        if(opt.Contains("comov"))
            hDen1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
        else
            hDen1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");

        if(i==0)
            hDen1D[i]->GetYaxis()->SetTitle("n/n_{0}");
        else if(i==1)
            hDen1D[i]->GetYaxis()->SetTitle("n_{b}/n_{0}");
        else
            hDen1D[i]->GetYaxis()->SetTitle("n_{i}/n_{0}");

        // Get the current:
        if(i==0) continue;

        sprintf(hName,"hCur1D_%i",i);
        hCur1D[i] = (TH1F*) gROOT->FindObject(hName);
        if(hCur1D[i]) delete hCur1D[i];

        if(opt.Contains("curr")) {
            // To get the current is needed to read in a wider transverse range which includes all the charge.
            Int_t NbinsT = 100;
            if(pData->Is3D()) {
                hCur1D[i] = pData->GetH1SliceZ3D(pData->GetChargeFileName(i)->c_str(),"charge",-1,NbinsT,-1,NbinsT,opt+"int");
            } else if(pData->IsCyl()) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0).
                hCur1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",1,NbinsT,opt+"int");
            } else { // 2D cartesian
                hCur1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",-1,NbinsT,opt+"int");
            }
            hCur1D[i]->SetName(hName);

            if(opt.Contains("comov")) {
                hCur1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
                hCur1D[i]->GetYaxis()->SetTitle("dn/d#zeta [(n_{0}/k_{p}^{3}) (#omega_{p}/c)]");
            } else {
                hCur1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
                hCur1D[i]->GetYaxis()->SetTitle("dn/dz [(n_{0}/k_{p}^{3}) (#omega_{p}/c)]");
            }

            Int_t NB = hCur1D[i]->GetNbinsX();
            Float_t dx = (hCur1D[i]->GetBinLowEdge(1)-hCur1D[i]->GetBinLowEdge(NB+1))/NB;

            // hCur1D[i]->Scale(dx);
            Float_t Charge = hCur1D[i]->Integral() * dx;

            cout << Form(" Integrated charge of specie %3i = %8.4f n0 * kp^-3",i,Charge) << endl;
        }
    }


    // Get electric fields 2D
    const Int_t Nfields = 3;
    TH2F **hE2D = new TH2F*[Nfields];
    TH1F **hE1D = new TH1F*[Nfields];
    TH2F *hV2D = NULL;
    TH1F *hV1D = NULL;
    for(Int_t i=0; i<Nfields; i++) {
        hE2D[i] = NULL;
        hE1D[i] = NULL;

        if(!pData->GetEfieldFileName(i))
            continue;

        cout << Form(" Getting electric field number ") << i+1 << endl;

        char hName[24];
        sprintf(hName,"hE2D_%i",i);
        hE2D[i] = (TH2F*) gROOT->FindObject(hName);
        if(hE2D[i]) delete hE2D[i];

        if(!pData->Is3D())
            hE2D[i] = pData->GetEField(i,opt);
        else
            hE2D[i] = pData->GetEField2DSliceZY(i,-1,Nbins,opt+"avg");

        hE2D[i]->SetName(hName);
        hE2D[i]->GetXaxis()->CenterTitle();
        hE2D[i]->GetYaxis()->CenterTitle();
        hE2D[i]->GetZaxis()->CenterTitle();
        if(opt.Contains("comov"))
            hE2D[i]->GetXaxis()->SetTitle("k_{p} #zeta");
        else
            hE2D[i]->GetXaxis()->SetTitle("k_{p} z");

        if(pData->IsCyl())
            hE2D[i]->GetYaxis()->SetTitle("k_{p} r");
        else
            hE2D[i]->GetYaxis()->SetTitle("k_{p} y");

        if(i==0)
            hE2D[i]->GetZaxis()->SetTitle("E_{z}/E_{0}");
        else if(i==1)
            hE2D[i]->GetZaxis()->SetTitle("E_{y}/E_{0}");
        else if(i==2)
            hE2D[i]->GetZaxis()->SetTitle("E_{x}/E_{0}");

        sprintf(hName,"hE1D_%i",i);
        hE1D[i] = (TH1F*) gROOT->FindObject(hName);
        if(hE1D[i]) delete hE1D[i];

        // 1D histograms
        char nam[3];
        sprintf(nam,"e%i",i+1);
        if(pData->Is3D()) {

            if(i==0)
                hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,-1,Nbins,opt+"avg");
            else
                hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,-Nbins,Nbins,opt+"avg");

        } else if(pData->IsCyl()) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0).

            hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opt+"avg");

        } else { // 2D cartesian

            if(i==0)
                hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,opt+"avg");
            else
                hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,opt+"avg");
        }

        hE1D[i]->SetName(hName);
        if(opt.Contains("comov"))
            hE1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
        else
            hE1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");

        if(i==0)
            hE1D[i]->GetYaxis()->SetTitle("E_{z} [E_{0}]");
        else if(i==1)
            hE1D[i]->GetYaxis()->SetTitle("E_{y} [E_{0}]");
        else if(i==2)
            hE1D[i]->GetYaxis()->SetTitle("E_{x} [E_{0}]");

        // Alternative
        // if(hE1D[i]) delete hE1D[i];
        // hE1D[i] = (TH1F*) hE2D[i]->ProjectionX(hName,FirstyBin,LastyBin);
        // hE1D[i]->Scale(1.0/(LastyBin-FirstyBin+1));

        if(i==0) {
            Int_t   NbinsX = hE2D[i]->GetNbinsX();
            Int_t   NbinsY = hE2D[i]->GetNbinsY();

            Float_t dx = pData->GetDX(0);

            sprintf(hName,"hV2D");
            hV2D = (TH2F*) hE2D[i]->Clone(hName);
            hV2D->Reset();

            sprintf(hName,"hV1D");
            hV1D = (TH1F*) hE1D[i]->Clone(hName);
            hV1D->Reset();

            for(Int_t j=NbinsY; j>0; j--) {
                Double_t integral = 0.0;
                for(Int_t k=NbinsX; k>0; k--) {
                    integral += hE2D[i]->GetBinContent(k,j) * dx;
                    hV2D->SetBinContent(k,j,integral);
                }
            }

            Double_t integral = 0.0;
            for(Int_t k=NbinsX; k>0; k--) {
                integral += hE1D[i]->GetBinContent(k) * dx;
                hV1D->SetBinContent(k,integral);
            }

        }

    }

    // Now, combine the electric field components into the total |E|
    // and calculate ionization probability for He:
    // Outter Helium electron
    Double_t Eion0 = 24.59 * PUnits::eV;
    Double_t Z     = 1;

    TH2F *hETotal2D = (TH2F*) hE2D[0]->Clone("hETotal2D");
    hETotal2D->Reset();
    TH2F *hIonProb2D = (TH2F*) hE2D[0]->Clone("hIonProb2D");
    hIonProb2D->Reset();
    TH1F *hETotal1D = (TH1F*) hE1D[0]->Clone("hETotal1D");
    hETotal1D->Reset();
    TH1F *hIonProb1D = (TH1F*) hE1D[0]->Clone("hIonProb1D");
    hIonProb1D->Reset();
    {
        Int_t NbinsX = hE2D[0]->GetNbinsX();
        Int_t NbinsY = hE2D[0]->GetNbinsY();
        for(Int_t j=0; j<NbinsX; j++) {
            for(Int_t k=0; k<NbinsY; k++) {
                Double_t E1 = hE2D[0]->GetBinContent(j,k);
                Double_t E2 = hE2D[1]->GetBinContent(j,k);
                Double_t E3 = hE2D[2]->GetBinContent(j,k);
                Double_t E  = TMath::Sqrt(E1*E1+E2*E2+E3*E3);

                hETotal2D->SetBinContent(j,k,E);

                E *= E0;

                // Double_t IonProb = (PFunc::ADK(E,Eion0,Z,l,m)/PUnits::atomictime)*PUnits::femtosecond;
                Double_t IonProb = PFunc::ADK_ENG(E,Eion0,Z) * PUnits::femtosecond;
                // if(IonProb>1) IonProb = 1.0;
                // cout << "Ion prob = " << IonProb << endl;
                hIonProb2D->SetBinContent(j,k,IonProb);
            }
            Double_t E1 = hE1D[0]->GetBinContent(j);
            Double_t E2 = hE1D[1]->GetBinContent(j);
            Double_t E3 = hE1D[2]->GetBinContent(j);
            Double_t E  = TMath::Sqrt(E1*E1+E2*E2+E3*E3);

            hETotal1D->SetBinContent(j,E);

            E *= E0;

            // Double_t IonProb = (PFunc::ADK(E,Eion0,Z,l,m)/PUnits::atomictime)*PUnits::femtosecond;
            Double_t IonProb = PFunc::ADK_ENG(E,Eion0,Z) * PUnits::femtosecond;
            // cout << "Ion prob = " << IonProb << endl;

            hIonProb1D->SetBinContent(j,IonProb);


        }
    }
    hETotal2D->GetZaxis()->SetTitle("E [E_{0}]");
    hIonProb2D->GetZaxis()->SetTitle("W_{ADK} [fs^{-1}]");
    hETotal1D->GetYaxis()->SetTitle("E [E_{0}]");
    hIonProb1D->GetYaxis()->SetTitle("W_{ADK} [fs^{-1}]");



    // Tunning the Histograms
    // ---------------------

    // Chaning to user units:
    // --------------------------

    if(opt.Contains("units") && n0) {

        for(Int_t i=0; i<Nspecies; i++) {

            if(!hDen2D[i]) continue;

            Int_t NbinsX = hDen2D[i]->GetNbinsX();
            Float_t xMin = skindepth * hDen2D[i]->GetXaxis()->GetXmin() / PUnits::um;
            Float_t xMax = skindepth * hDen2D[i]->GetXaxis()->GetXmax() / PUnits::um;
            Int_t NbinsY = hDen2D[i]->GetNbinsY();
            Float_t ymin = skindepth * hDen2D[i]->GetYaxis()->GetXmin() / PUnits::um;
            Float_t ymax = skindepth * hDen2D[i]->GetYaxis()->GetXmax() / PUnits::um;
            hDen2D[i]->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
            // for(Int_t j=0;j<hDen2D[i]->GetNbinsX();j++) {
            // 	for(Int_t k=0;k<hDen2D[i]->GetNbinsY();k++) {
            // 	  hDen2D[i]->SetBinContent(j,k, hDen2D[i]->GetBinContent(j,k) * n0 / (1e17/PUnits::cm3) );
            // 	}
            // }

            if(pData->IsCyl())
                hDen2D[i]->GetYaxis()->SetTitle("r [#mum]");
            else
                hDen2D[i]->GetYaxis()->SetTitle("y [#mum]");

            if(opt.Contains("comov"))
                hDen2D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
            else
                hDen2D[i]->GetXaxis()->SetTitle("z [#mum]");

            // if(i==0)
            // 	hDen2D[i]->GetZaxis()->SetTitle("n_{e} [10^{17}/cm^{3}]");
            // else if(i==1)
            // 	hDen2D[i]->GetZaxis()->SetTitle("n_{b} [10^{17}/cm^{3}]");
            // else
            // 	hDen2D[i]->GetZaxis()->SetTitle("n_{i} [10^{17}/cm^{3}]");

            hDen1D[i]->SetBins(NbinsX,xMin,xMax);
            // for(Int_t j=0;j<hDen1D[i]->GetNbinsX();j++) {
            // 	hDen1D[i]->SetBinContent(j, hDen1D[i]->GetBinContent(j) * n0 / (1e17/PUnits::cm3) );
            // }


            if(opt.Contains("comov"))
                hDen1D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
            else
                hDen1D[i]->GetXaxis()->SetTitle("z [#mum]");

            if(hCur1D[i]) {

                hCur1D[i]->SetBins(NbinsX,xMin,xMax);
                Double_t binSize = (xMax - xMin)/NbinsX;  // bin size in um.

                Double_t dV = skindepth * skindepth * skindepth;
                Double_t lightspeed =  PConst::c_light / (PUnits::um/PUnits::femtosecond);

                hCur1D[i]->Scale(TMath::Abs(n0 * dV * (PConst::ElectronCharge/PUnits::picocoulomb) * (kp * PConst::c_light * PUnits::femtosecond)));

                hCur1D[i]->GetYaxis()->SetTitle("I[kA]");
                hCur1D[i]->GetYaxis()->SetTitle("");
                if(opt.Contains("comov"))
                    hCur1D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
                else
                    hCur1D[i]->GetXaxis()->SetTitle("z [#mum]");


                Float_t Charge = hCur1D[i]->Integral() * (binSize / lightspeed);
                cout << Form(" Integrated charge of specie %3i = %8f pC",i,Charge) << endl;
            }
        }


        for(Int_t i=0; i<Nfields; i++) {
            Int_t NbinsX = hE2D[i]->GetNbinsX();
            Float_t xMin = skindepth * hE2D[i]->GetXaxis()->GetXmin() / PUnits::um;
            Float_t xMax = skindepth * hE2D[i]->GetXaxis()->GetXmax() / PUnits::um;
            Int_t NbinsY = hE2D[i]->GetNbinsY();
            Float_t ymin = skindepth * hE2D[i]->GetYaxis()->GetXmin() / PUnits::um;
            Float_t ymax = skindepth * hE2D[i]->GetYaxis()->GetXmax() / PUnits::um;
            hE2D[i]->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
            hE1D[i]->SetBins(NbinsX,xMin,xMax);

            for(Int_t j=0; j<hE2D[i]->GetNbinsX(); j++) {
                for(Int_t k=0; k<hE2D[i]->GetNbinsY(); k++) {
                    hE2D[i]->SetBinContent(j,k, hE2D[i]->GetBinContent(j,k) * ( E0 / (PUnits::GV/PUnits::m) ) );
                }
                hE1D[i]->SetBinContent(j, hE1D[i]->GetBinContent(j) * ( E0 / (PUnits::GV/PUnits::m) ) );
            }

            if(pData->IsCyl())
                hE2D[i]->GetYaxis()->SetTitle("r [#mum]");
            else
                hE2D[i]->GetYaxis()->SetTitle("y [#mum]");

            if(opt.Contains("comov"))
                hE2D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
            else
                hE2D[i]->GetXaxis()->SetTitle("z [#mum]");

            if(i==0)
                hE2D[i]->GetZaxis()->SetTitle("E_{z} [GV/m]");
            else if(i==1)
                hE2D[i]->GetZaxis()->SetTitle("E_{y} [GV/m]");
            else if(i==2)
                hE2D[i]->GetZaxis()->SetTitle("E_{x} [GV/m]");


            if(opt.Contains("comov"))
                hE1D[i]->GetXaxis()->SetTitle("#zeta [mm]");
            else
                hE1D[i]->GetXaxis()->SetTitle("z [mm]");

            if(i==0)
                hE1D[i]->GetYaxis()->SetTitle("E_{z} [GV/m]");
            else if(i==1)
                hE1D[i]->GetYaxis()->SetTitle("E_{y} [GV/m]");
            else if(i==2)
                hE1D[i]->GetYaxis()->SetTitle("E_{x} [GV/m]");


            if(i==0) {
                hV2D->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
                hETotal2D->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
                hIonProb2D->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
                hV1D->SetBins(NbinsX,xMin,xMax);
                hETotal1D->SetBins(NbinsX,xMin,xMax);
                hIonProb1D->SetBins(NbinsX,xMin,xMax);
                for(Int_t j=0; j<NbinsX; j++) {
                    for(Int_t k=0; k<NbinsY; k++) {
                        hV2D->SetBinContent(j,k, hV2D->GetBinContent(j,k) * E0 * skindepth / (PUnits::MV));
                        hETotal2D->SetBinContent(j,k, hETotal2D->GetBinContent(j,k) * ( E0 / (PUnits::GV/PUnits::m) ) );
                    }
                    hV1D->SetBinContent(j, hV1D->GetBinContent(j) * ( E0 * skindepth / (PUnits::MV) ) );
                    hETotal1D->SetBinContent(j, hETotal1D->GetBinContent(j) * ( E0 / (PUnits::GV/PUnits::m) ) );
                }

                if(pData->IsCyl()) {
                    hV2D->GetYaxis()->SetTitle("r [#mum]");
                    hETotal2D->GetYaxis()->SetTitle("r [#mum]");
                } else {
                    hV2D->GetYaxis()->SetTitle("y [#mum]");
                    hETotal2D->GetYaxis()->SetTitle("y [#mum]");

                }

                if(opt.Contains("comov")) {
                    hV2D->GetXaxis()->SetTitle("#zeta [#mum]");
                    hV1D->GetXaxis()->SetTitle("#zeta [#mum]");
                    hETotal2D->GetXaxis()->SetTitle("#zeta [#mum]");
                    hETotal1D->GetXaxis()->SetTitle("#zeta [#mum]");
                } else {
                    hV2D->GetXaxis()->SetTitle("z [#mum]");
                    hV2D->GetXaxis()->SetTitle("z [#mum]");
                    hETotal2D->GetXaxis()->SetTitle("z [#mum]");
                    hETotal1D->GetXaxis()->SetTitle("z [#mum]");
                }

                hV2D->GetZaxis()->SetTitle("#Psi-#Psi_{t} [MV]");
                hV1D->GetYaxis()->SetTitle("#Psi-#Psi_{t} [MV]");
                hETotal2D->GetZaxis()->SetTitle("E [GV/m]");
                hETotal1D->GetYaxis()->SetTitle("E [GV/m]");
            }
        }
    }


    // --------------------------------------------------- Vertical Zoom ------------

    Float_t yRange    = (hDen2D[0]->GetYaxis()->GetXmax() - hDen2D[0]->GetYaxis()->GetXmin())/zoom;
    Float_t midPoint = (hDen2D[0]->GetYaxis()->GetXmax() + hDen2D[0]->GetYaxis()->GetXmin())/2.;
    Float_t yMin = midPoint-yRange/2;
    Float_t yMax = midPoint+yRange/2;
    if(pData->IsCyl()) {
        yMin = pData->GetXMin(1);
        yMax = yRange;
    }

    for(Int_t i=0; i<Nspecies; i++) {
        if(!hDen2D[i]) continue;
        hDen2D[i]->GetYaxis()->SetRangeUser(yMin,yMax);
    }

    for(Int_t i=0; i<Nfields; i++) {
        if(!hE2D[i]) continue;
        hE2D[i]->GetYaxis()->SetRangeUser(yMin,yMax);
    }

    hETotal2D->GetYaxis()->SetRangeUser(yMin,yMax);

    Float_t xMin = hDen2D[0]->GetXaxis()->GetXmin();
    Float_t xMax = hDen2D[0]->GetXaxis()->GetXmax();
    Float_t xRange = xMax - xMin;

    // ------------- z Zoom --------------------------------- Plasma palette -----------
    // Set the range of the plasma charge density histogram for maximum constrast
    // using a dynamic palette wich adjust the nominal value to a certain color.


    Float_t density = 1;
    Float_t Base  = density;

    Float_t *Max = new Float_t[Nspecies];
    Float_t *Min = new Float_t[Nspecies];

    for(Int_t i=0; i<Nspecies; i++) {
        if(!hDen2D[i]) continue;

        Max[i] = hDen2D[i]->GetMaximum();
        Min[i] = 1.01E-1 * Base;
        if(i==1) Min[i] = 1.01E-1 * Base;
        if(i==2) Min[i] = 1.01E-4 * Base;
        hDen2D[i]->GetZaxis()->SetRangeUser(Min[i],Max[i]);
    }

    // Dynamic plasma palette
    const Int_t plasmaDNRGBs = 3;
    const Int_t plasmaDNCont = 64;
    Float_t basePos = 0.5;
    if(Max[0]!=Min[0]) {
        if(opt.Contains("logz")) {
            Float_t a = 1.0/(TMath::Log10(Max[0])-TMath::Log10(Min[0]));
            Float_t b = TMath::Log10(Min[0]);
            basePos = a*(TMath::Log10(Base) - b);

        } else {
            basePos = (1.0/(Max[0]-Min[0]))*(Base - Min[0]);
        }
    }

    Double_t plasmaDStops[plasmaDNRGBs] = { 0.00, basePos, 1.00 };
    Double_t plasmaDRed[plasmaDNRGBs]   = { 0.99, 0.90, 0.00 };
    Double_t plasmaDGreen[plasmaDNRGBs] = { 0.99, 0.90, 0.00 };
    Double_t plasmaDBlue[plasmaDNRGBs]  = { 0.99, 0.90, 0.00 };

    PPalette * plasmaPalette = (PPalette*) gROOT->FindObject("plasma");
    plasmaPalette->CreateGradientColorTable(plasmaDNRGBs, plasmaDStops,
                                            plasmaDRed, plasmaDGreen, plasmaDBlue, plasmaDNCont);
    // Change the range of z axis for the fields to be symmetric.
    Float_t *Emax = new Float_t[Nfields];
    Float_t *Emin = new Float_t[Nfields];
    for(Int_t i=0; i<Nfields; i++) {
        Emax[i] = hE2D[i]->GetMaximum();
        Emin[i] = hE2D[i]->GetMinimum();
        if(Emax[i] > TMath::Abs(Emin[i]))
            Emin[i] = -Emax[i];
        else
            Emax[i] = -Emin[i];
        hE2D[i]->GetZaxis()->SetRangeUser(Emin[i],Emax[i]);
    }


    // Potential
    if(opt.Contains("units")) {
        trapPotential *=  ( E0 * skindepth / (PUnits::MV) );
    }

    Float_t Vmin = hV1D->GetMinimum();
    {   // Shift potential
        Int_t   NbinsX = hV2D->GetNbinsX();
        Int_t   NbinsY = hV2D->GetNbinsY();
        for(Int_t j=0; j<NbinsX; j++) {
            for(Int_t k=0; k<NbinsY; k++) {
                hV2D->SetBinContent(j,k, hV2D->GetBinContent(j,k) - Vmin -trapPotential);
            }
            hV1D->SetBinContent(j, hV1D->GetBinContent(j) - Vmin -trapPotential);
        }
    }

    Vmin = hV1D->GetMinimum();
    Float_t Vmax = hV1D->GetMaximum();

    // Dynamic potential palette
    const Int_t potPNRGBs = 5;
    const Int_t potPNCont = 64;
    Float_t zeroPos = -Vmin/(Vmax-Vmin);

    Double_t potPStops[potPNRGBs] = { 0.00, zeroPos-3.0/potPNCont,zeroPos, zeroPos+3.0/potPNCont, 1.00 };
    Double_t potPRed[potPNRGBs]   = { 0.518, 0.965, 0.90, 0.498, 0.106 };
    Double_t potPGreen[potPNRGBs] = { 0.078, 0.925, 0.90, 0.718, 0.078 };
    Double_t potPBlue[potPNRGBs]  = { 0.106, 0.353, 0.90, 0.780, 0.518 };

    PPalette * potentialPalette = (PPalette*) gROOT->FindObject("rbow2inv");
    potentialPalette->CreateGradientColorTable(potPNRGBs, potPStops,
            potPRed, potPGreen, potPBlue, potPNCont);

    // Extract contours
    TCanvas* c = new TCanvas("c","Contour List",0,0,600,600);
    c->cd();

    // Potential
    TH2F *hV2Dc = (TH2F*) hV2D->Clone("hV2Dc");
    const Int_t Ncontours = 25;
    Double_t contours[Ncontours];
    for(Int_t i=0; i<Ncontours; i++) {
        contours[i] = i*(trapPotential/5.0) - trapPotential;
    }
    hV2Dc->SetContour(Ncontours, contours);
    hV2Dc->Draw("cont list");

    c->Update();
    TObjArray *contsV2D = (TObjArray*) gROOT->GetListOfSpecials()->FindObject("contours");
    TClonesArray graphsV2D("TGraph",Ncontours);
    {
        Int_t ncontours = contsV2D->GetSize();
        TList* clist = NULL;
        Int_t nGraphs = 0;
        TGraph *gr = NULL;
        for(Int_t i = 0; i < ncontours; i++) {
            if(i==0) continue;

            clist = (TList*) contsV2D->At(i);

            for(Int_t j = 0 ; j < clist->GetSize(); j++) {
                gr = (TGraph*) clist->At(j);
                if(!gr) continue;

                gr->SetLineWidth(1);
                gr->SetLineColor(kGray+1);

                if( !((i)%5) ) {
                    gr->SetLineWidth(2);
                    gr->SetLineColor(kGray+2);
                }
                new(graphsV2D[nGraphs]) TGraph(*gr) ;
                nGraphs++;
            }
        }
    }

    // Ion probability
    hIonProb2D->GetZaxis()->SetRangeUser(0.00501,80);

    TH2F *hIonProb2Dc = (TH2F*) hIonProb2D->Clone("hIonProb2Dc");
    const Int_t NcontI = 4;
    Double_t contI[NcontI] = {0.01,0.1,1.0,10.0};
    hIonProb2Dc->SetContour(NcontI, contI);
    hIonProb2Dc->Draw("cont list");

    c->Update();
    TObjArray *contsI2D = (TObjArray*) gROOT->GetListOfSpecials()->FindObject("contours");
    TClonesArray graphsI2D("TGraph",NcontI);
    {
        Int_t ncontours = contsI2D->GetSize();
        TList* clist = NULL;
        Int_t nGraphs = 0;
        TGraph *gr = NULL;
        for(Int_t i = 0; i < ncontours; i++) {
            clist = (TList*) contsI2D->At(i);

            for(Int_t j = 0 ; j < clist->GetSize(); j++) {
                gr = (TGraph*) clist->At(j);
                if(!gr) continue;

                if( !(i%2) ) {
                    gr->SetLineWidth(1);
                    gr->SetLineStyle(2);
                    gr->SetLineColor(kOrange-3);
                } else {
                    gr->SetLineWidth(1);
                    gr->SetLineStyle(1);
                    gr->SetLineColor(kOrange-3);
                }

                new(graphsI2D[nGraphs]) TGraph(*gr) ;
                nGraphs++;
            }
        }
    }




    // "Axis range" in Osiris units:
    Double_t ylow  = hDen2D[0]->GetYaxis()->GetBinLowEdge(FirstyBin);
    Double_t yup = hDen2D[0]->GetYaxis()->GetBinUpEdge(LastyBin);
    Double_t xmin = hDen2D[0]->GetXaxis()->GetXmin();
    Double_t xmax = hDen2D[0]->GetXaxis()->GetXmax();

    TLine *lineYzero = new TLine(xmin,0.0,xmax,0.0);
    lineYzero->SetLineColor(kGray+2);
    lineYzero->SetLineStyle(2);

    TLine *lineYup = new TLine(xmin,yup,xmax,yup);
    lineYup->SetLineColor(kGray+1);
    lineYup->SetLineStyle(2);

    TLine *lineYdown = new TLine(xmin,ylow,xmax,ylow);
    lineYdown->SetLineColor(kGray+1);
    lineYdown->SetLineStyle(2);

    zStartPlasma -= shiftz;
    zStartNeutral -= shiftz;
    zEndNeutral -= shiftz;

    if(opt.Contains("units")) {
        zStartPlasma *= skindepth / PUnits::um;
        zStartNeutral *= skindepth / PUnits::um;
        zEndNeutral *= skindepth / PUnits::um;
    }

    //  cout << "Start plasma = " << zStartPlasma << endl;
    TLine *lineStartPlasma = new TLine(zStartPlasma,yMin,zStartPlasma,yMax);
    lineStartPlasma->SetLineColor(kGray+2);
    lineStartPlasma->SetLineStyle(2);
    lineStartPlasma->SetLineWidth(3);

    //  cout << "Start plasma = " << zStartNeutral << endl;
    TLine *lineStartNeutral = new TLine(zStartNeutral,yMin,zStartNeutral,yMax);
    lineStartNeutral->SetLineColor(kGray+1);
    lineStartNeutral->SetLineStyle(2);
    lineStartNeutral->SetLineWidth(3);

    //  cout << "End plasma = " << zEndNeutral << endl;
    TLine *lineEndNeutral = new TLine(zEndNeutral,yMin,zEndNeutral,yMax);
    lineEndNeutral->SetLineColor(kGray+1);
    lineEndNeutral->SetLineStyle(2);
    lineEndNeutral->SetLineWidth(3);


    // Plotting
    // -----------------------------------------------

    // Canvas setup
    TCanvas *C = new TCanvas("C","2D Charge density and Electric field",750,666);

    // Palettes setup
    TExec *exPlasma = new TExec("exPlasma","plasmaPalette->cd();");
    TExec *exElec   = new TExec("exElec","redelectronPalette->cd();");
    TExec *exHot    = new TExec("exHot","hotPalette->cd();");
    TExec *exField  = new TExec("exField","rbow2Palette->cd();");
    TExec *exFieldT = new TExec("exFieldT","redPalette->cd();");
    TExec *exIonP   = new TExec("exIonP","redPalette->cd();");
    TExec *exPot    = new TExec("exPot","rbow2invPalette->cd();");

    // Actual Plotting!
    // ------------------------------------------------------------

    // Output file
    TString fOutName = Form("./%s/Plots/Potential2D/Potential2D",pData->GetPath().c_str());
    fOutName += Form("-%s_%i",pData->GetName(),time);

    // Setup Pad layout:
    Float_t lMargin = 0.15;
    Float_t rMargin = 0.18;
    Float_t bMargin = 0.15;
    Float_t tMargin = 0.04;
    Float_t factor = 1.0;
    PlasmaGlob::CanvasAsymPartition(C,2,lMargin,rMargin,bMargin,tMargin,factor);

    TPad *pad[2];
    TString sLabels[] = {"(a)","(b)"};
    // Text objects
    TPaveText **textLabel = new TPaveText*[2];

    C->cd(0);
    char pname[16];
    sprintf(pname,"pad_%i",1);
    pad[0] = (TPad*) gROOT->FindObject(pname);
    pad[0]->Draw();
    pad[0]->cd(); // <---------------------------------------------- Top Plot ---------
    if(opt.Contains("logz")) {
        pad[0]->SetLogz(1);
    } else {
        pad[0]->SetLogz(0);
    }
    pad[0]->SetFrameLineWidth(3);
    pad[0]->SetTickx(1);

    // Re-range:
    for(Int_t i=0; i<Nspecies; i++) {
        if(!hDen2D[i]) continue;
        hDen2D[i]->GetYaxis()->SetRangeUser(yMin -(factor-1)*yRange, yMax);
    }


    TH2F *hFrame = (TH2F*) gROOT->FindObject("hFrame1");
    if(hFrame) delete hFrame;
    hFrame = (TH2F*) hDen2D[0]->Clone("hFrame1");
    hFrame->Reset();

    hFrame->SetLabelFont(42,"xyz");
    hFrame->SetTitleFont(42,"xyz");

    hFrame->GetYaxis()->SetNdivisions(505);
    hFrame->GetYaxis()->SetLabelSize(0.085);
    hFrame->GetYaxis()->SetTitleSize(0.09);
    hFrame->GetYaxis()->SetTitleOffset(0.7);
    hFrame->GetYaxis()->SetTickLength(0.02);

    hFrame->GetXaxis()->SetLabelOffset(999.);
    hFrame->GetXaxis()->SetTitleOffset(999.);
    hFrame->GetXaxis()->SetTickLength(0.04);

    // Frame asymmetry:
    hFrame->Draw("col");

    // hDen2D[0]->GetZaxis()->SetNdivisions(505);

    // Injected electrons if any
    if(Nspecies>=3) {
        if(hDen2D[2]) {
            exHot->Draw();
            hDen2D[2]->Draw("colz same");
        }
    }

    // Plasma
    hDen2D[0]->GetZaxis()->SetTitleFont(42);
    exPlasma->Draw();
    hDen2D[0]->Draw("colz same");

    // Beam driver.
    if(hDen2D[1]) {
        //    hDen2D[1]->GetZaxis()->SetNdivisions(505);
        exElec->Draw();
        hDen2D[1]->Draw("colz same");
    }

    {
        TGraph *gr = (TGraph*) graphsV2D.At(4);
        gr->Draw("C");
    }

    {
        TGraph *gr = (TGraph*) graphsI2D.At(1);
        gr->Draw("C");
    }


    if(opt.Contains("1dline")) {
        lineYzero->Draw();
        lineYdown->Draw();
        lineYup->Draw();
    }

    if(opt.Contains("sline")) {
        if(zStartPlasma>xmin && zStartPlasma<xmax)
            lineStartPlasma->Draw();
        if(zStartNeutral>xmin && zStartNeutral<xmax)
            lineStartNeutral->Draw();
        if(zEndNeutral>xmin && zEndNeutral<xmax)
            lineEndNeutral->Draw();
    }

    // lineYdown->Draw();
    // lineYup->Draw();

    // Palettes re-arrangement
    pad[0]->Update();
    Float_t y1 = pad[0]->GetBottomMargin();
    Float_t y2 = 1 - pad[0]->GetTopMargin();
    Float_t x1 = pad[0]->GetLeftMargin();
    Float_t x2 = 1 - pad[0]->GetRightMargin();

    TPaletteAxis *palette = NULL;
    if(Nspecies>=3) {
        if(hDen2D[2]) {
            palette = (TPaletteAxis*)hDen2D[2]->GetListOfFunctions()->FindObject("palette");
        }
    }
    if(palette) {
        palette->SetY2NDC(y2 - 0.00);
        palette->SetY1NDC(0.66*(y1+y2) + 0.00);
        palette->SetX1NDC(x2 + 0.005);
        palette->SetX2NDC(x2 + 0.03);
        //  palette->SetTitleFont(42);
        //  palette->SetTitleOffset(0.85);
        palette->SetTitleOffset(999.9);
        palette->SetTitleSize(0.075);
        palette->SetLabelFont(42);
        palette->SetLabelSize(0.075);
        palette->SetLabelOffset(0.001);
        palette->SetBorderSize(2);
        palette->SetLineColor(1);
    }

    palette = (TPaletteAxis*)hDen2D[0]->GetListOfFunctions()->FindObject("palette");
    if(palette) {
        palette->SetY2NDC(0.66*(y1+y2) - 0.00);
        palette->SetY1NDC(0.33*(y1+y2) + 0.00);
        palette->SetX1NDC(x2 + 0.005);
        palette->SetX2NDC(x2 + 0.03);
        // palette->SetTitleFont(42);
        palette->SetTitleOffset(0.80);
        palette->SetTitleSize(0.075);
        palette->SetLabelFont(42);
        palette->SetLabelSize(0.075);
        palette->SetLabelOffset(0.001);
        palette->SetBorderSize(2);
        palette->SetLineColor(1);
    }

    palette = (TPaletteAxis*)hDen2D[1]->GetListOfFunctions()->FindObject("palette");
    if(palette) {
        palette->SetY2NDC(0.33*(y1+y2) - 0.00);
        palette->SetY1NDC(y1 + 0.00);
        palette->SetX1NDC(x2 + 0.005);
        palette->SetX2NDC(x2 + 0.03);
        //palette->SetTitleFont(42);
        //palette->SetTitleOffset(0.85);
        palette->SetTitleOffset(999.9);
        palette->SetTitleSize(0.075);
        palette->SetLabelFont(42);
        palette->SetLabelSize(0.075);
        palette->SetLabelOffset(0.001);
        palette->SetBorderSize(2);
        palette->SetLineColor(1);
    }


    // 1D charge density plots:
    Float_t yaxismin  =  pad[0]->GetUymin();
    Float_t yaxismax  =  pad[0]->GetUymin() + 0.33*(pad[0]->GetUymax() - pad[0]->GetUymin()) - 0.00;
    Float_t denmin = Min[1];
    Float_t denmax = Max[1];
    if(opt.Contains("logz")) {
        denmin = TMath::Log10(denmin);
        denmax = TMath::Log10(denmax);
    }

    Float_t curmin = 0.0;
    Float_t curmax = 0.0;
    if(opt.Contains("curr")) {
        curmin = 0.0;
        curmax = hCur1D[1]->GetMaximum();

        cout << Form(" Maximum driver  current = %6.2f kA ", curmax) << endl ;
        if(Nspecies>=3)
            if(hCur1D[2])
                cout << Form(" Maximum witness current = %6.2f kA ", hCur1D[2]->GetMaximum()) << endl ;

        // Round for better plotting
        curmax = 0.1*TMath::Nint(curmax*10);
    }

    for(Int_t i=0; i<Nspecies; i++) {
        if(!hDen1D[i]) continue;

        Float_t slope = (yaxismax - yaxismin)/(denmax - denmin);

        for(Int_t j=0; j<hDen1D[i]->GetNbinsX(); j++) {
            Float_t content = hDen1D[i]->GetBinContent(j+1);
            if(opt.Contains("logz")) content = TMath::Log10(content);

            if(content<denmin)
                hDen1D[i]->SetBinContent(j+1,yaxismin);
            else
                hDen1D[i]->SetBinContent(j+1,(content - denmin) * slope + yaxismin);


        }

        if(hCur1D[i]) {
            slope = (yaxismax - yaxismin)/(curmax - curmin);

            for(Int_t j=0; j<hCur1D[i]->GetNbinsX(); j++) {
                Float_t content = hCur1D[i]->GetBinContent(j+1);

                if(content<curmin)
                    hCur1D[i]->SetBinContent(j+1,yaxismin);
                else
                    hCur1D[i]->SetBinContent(j+1,(content - curmin) * slope + yaxismin);
            }

        }

    }

    // Plasma on-axis density:
    // hDen1D[0]->SetLineWidth(2);
    // hDen1D[0]->SetLineColor(kGray+1);
    // // // PlasmaGlob::SetH1Style(hDen1D[0],1);
    // hDen1D[0]->Draw("same C");


    if(opt.Contains("curr")) {
        hCur1D[1]->SetLineWidth(2);
        hCur1D[1]->SetLineColor(PlasmaGlob::elecLine);
        hCur1D[1]->Draw("same C");
    } else {
        hDen1D[1]->SetLineWidth(2);
        hDen1D[1]->SetLineColor(PlasmaGlob::elecLine);
        //    hDen1D[1]->Draw("same C");
    }

    if(Nspecies>=3) {
        if(hDen1D[2]) {
            if(opt.Contains("curr")) {
                hCur1D[2]->SetLineWidth(2);
                hCur1D[2]->SetLineColor(kOrange+8);
                hCur1D[2]->Draw("same C");
            } else {
                hDen1D[2]->SetLineWidth(2);
                hDen1D[2]->SetLineColor(kOrange+8);
                //   hDen1D[2]->Draw("same C");
            }
        }
    }

    // Current axis
    TGaxis *axis = NULL;
    if(opt.Contains("curr")) {
        axis = new TGaxis(xMax-xRange/6.0,yMin - (factor-1)*yRange,
                          xMax-xRange/6.0,yaxismax,
                          0.001,curmax,503,"+LS");

        axis->SetLineWidth(1);
        axis->SetLineColor(kGray+3);//PlasmaGlob::elecLine);
        axis->SetLabelColor(kGray+3);//PlasmaGlob::elecLine);
        axis->SetLabelSize(0.06);
        axis->SetLabelOffset(0.01);
        axis->SetLabelFont(42);
        axis->SetTitleColor(kGray+3);//PlasmaGlob::elecLine);
        axis->SetTitleSize(0.06);
        axis->SetTitleOffset(0.6);
        axis->SetTitleFont(42);
        axis->SetTickSize(0.03);
        axis->SetTitle("I [kA]");
        axis->CenterTitle();
        axis->SetNdivisions(505);

        axis->Draw();
    }


    TPaveText *textTime = new TPaveText(xMax - 0.3*xRange, yMax-0.15*yRange, xMax-0.1, yMax-0.05*yRange);
    //x2-0.17,y2-0.12,x2-0.02,y2-0.02,"NDC");
    PlasmaGlob::SetPaveTextStyle(textTime,32);
    char ctext[128];
    if(opt.Contains("units") && n0)
        sprintf(ctext,"z = %5.1f #mum", Time * skindepth / PUnits::um);
    else
        sprintf(ctext,"t = %5.1f #omega_{p}^{-1}",Time);
    textTime->SetTextFont(42);
    textTime->AddText(ctext);

    textTime->Draw();
    // textDen->Draw();
    // if(opt.Contains("units"))
    //   textWav->Draw();

    textLabel[0] = new TPaveText(xMin + 0.02*xRange, yMax-0.2*yRange, xMin+0.30*xRange, yMax-0.05*yRange);
    PlasmaGlob::SetPaveTextStyle(textLabel[0],12);
    textLabel[0]->SetTextFont(42);
    textLabel[0]->AddText(sLabels[0]);
    textLabel[0]->Draw();


    pad[0]->RedrawAxis();

    C->cd(0);
    sprintf(pname,"pad_%i",0);
    pad[1] = (TPad*) gROOT->FindObject(pname);
    pad[1]->Draw();
    pad[1]->cd(); // <--------------------------------------------------------- Bottom Plot
    pad[1]->SetFrameLineWidth(3);
    pad[1]->SetTickx(1);

    hFrame = (TH2F*) gROOT->FindObject("hFrame2");
    if(hFrame) delete hFrame;
    hFrame = (TH2F*) hDen2D[0]->Clone("hFrame2");
    hFrame->Reset();

    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[1]->GetAbsHNDC();


    hFrame->GetYaxis()->SetLabelSize(yFactor*0.085);
    hFrame->GetYaxis()->SetTitleSize(yFactor*0.09);
    hFrame->GetYaxis()->SetTitleOffset(0.7/yFactor);
    hFrame->GetYaxis()->SetTickLength(0.02/yFactor);

    hFrame->GetXaxis()->SetTitleSize(0.10);
    hFrame->GetXaxis()->SetLabelSize(0.08);
    hFrame->GetXaxis()->SetLabelOffset(0.02);
    hFrame->GetXaxis()->SetTitleOffset(1.0);
    hFrame->GetXaxis()->SetTickLength(0.04*yFactor);

    hFrame->SetLabelFont(42,"xyz");
    hFrame->SetTitleFont(42,"xyz");

    hFrame->Draw("col");

    //  hE2D[0]->GetZaxis()->SetNdivisions(505);
    hV2D->GetZaxis()->SetTitleFont(42);
    hV2D->GetZaxis()->SetTickLength(0.02/yFactor);


    exPot->Draw();

    hV2D->Draw("col z same");

    for(Int_t i=0; i<graphsV2D.GetEntriesFast(); i++) {
        TGraph *gr = (TGraph*) graphsV2D.At(i);
        if(!gr) continue;
        gr->Draw("C");
    }

    for(Int_t i=0; i<graphsI2D.GetEntriesFast(); i++) {
        //if(i!=2) continue;
        TGraph *gr = (TGraph*) graphsI2D.At(i);
        if(!gr) continue;
        gr->Draw("C");
    }


    if(opt.Contains("1dline")) {
        lineYzero->Draw();
        lineYdown->Draw();
        lineYup->Draw();
    }

    if(opt.Contains("sline")) {
        if(zStartPlasma>xmin && zStartPlasma<xmax)
            lineStartPlasma->Draw();
        if(zStartNeutral>xmin && zStartNeutral<xmax)
            lineStartNeutral->Draw();
        if(zEndNeutral>xmin && zEndNeutral<xmax)
            lineEndNeutral->Draw();
    }


    pad[1]->Update();

    y1 = pad[1]->GetBottomMargin();
    y2 = 1 - pad[1]->GetTopMargin();
    x1 = pad[1]->GetLeftMargin();
    x2 = 1 - pad[1]->GetRightMargin();

    palette = (TPaletteAxis*)hV2D->GetListOfFunctions()->FindObject("palette");
    if(palette) {
        palette->SetY2NDC(y2 - 0.00);
        palette->SetY1NDC(y1 + 0.00);
        palette->SetX1NDC(x2 + 0.005);
        palette->SetX2NDC(x2 + 0.03);
        // palette->SetTitleFont(42);
        palette->SetTitleSize(yFactor*0.075);
        palette->SetTitleOffset(0.80/yFactor);
        palette->SetLabelSize(yFactor*0.075);
        palette->SetLabelFont(42);
        palette->SetLabelOffset(0.01/yFactor);
        palette->SetBorderSize(2);
        palette->SetLineColor(1);
    }



    pad[1]->RedrawAxis();

    textLabel[1] = new TPaveText(xMin + 0.02*xRange, yMax-0.2*yRange, xMin+0.30*xRange, yMax-0.05*yRange);
    PlasmaGlob::SetPaveTextStyle(textLabel[1],12);
    textLabel[1]->SetTextFont(42);
    textLabel[1]->AddText(sLabels[1]);
    textLabel[1]->Draw();

    C->cd();

    // Print to a file
    PlasmaGlob::imgconv(C,fOutName,opt);
    // ---------------------------------------------------------

    PlasmaGlob::DestroyCanvases();
}
Ejemplo n.º 6
0
void PlotField1D( const TString &sim, Int_t time, Int_t Nbins=1, const TString &options="") { 
  
#ifdef __CINT__  
  gSystem->Load("libplasma.so");
#endif

  PlasmaGlob::Initialize();
    
  TString opt = options;

  gStyle->SetPadLeftMargin(0.10);  // Margin left axis  
  gStyle->SetPadRightMargin(0.12); // Margin right axis 
  if(opt.Contains("grid")) {
    gStyle->SetPadGridX(1);
    gStyle->SetPadGridY(1);
  }

  // Load PData
  PData *pData = PData::Get(sim.Data());
  pData->LoadFileNames(time);
  if(!pData->IsInit()) return;

  Bool_t CYL = kFALSE;
  if(sim.Contains("cyl")) { CYL = kTRUE; opt += "cyl"; } 
    
  Bool_t ThreeD = kFALSE;
  if(sim.Contains("3D")) ThreeD = kTRUE; 

  // Some plasma constants
  Double_t n0 = pData->GetPlasmaDensity();
  Double_t kp = pData->GetPlasmaK();
  Double_t skindepth = 1/kp;
  Double_t E0 = pData->GetPlasmaE0();

  // Some beam properties:
  Float_t Ebeam = pData->GetBeamEnergy() * PUnits::MeV;
  Float_t gamma = Ebeam / PConst::ElectronMassE;
  Float_t vbeam = TMath::Sqrt(1 - 1/(gamma*gamma));
  // cout << Form(" - Bunch gamma      = %8.4f", gamma ) << endl;
  // cout << Form(" - Bunch velocity   = %8.4f c", vbeam ) << endl;

  Float_t Time = pData->GetRealTime();
  // z start of the plasma in normalized units.
  Float_t zStartPlasma = pData->GetPlasmaStart()*kp;
  // z start of the beam in normalized units.
  Float_t zStartBeam = pData->GetBeamStart()*kp;
  Time -= zStartPlasma - zStartBeam;

  // 1D histograms
  TString opth1 = opt;
  opth1 += "avg";
  // Get electric fields
  const Int_t Nfields = 1;
  TH1F **hE1D = new TH1F*[Nfields];
  for(Int_t i=0;i<Nfields;i++) {
    hE1D[i] = NULL;
    if(!pData->GetEfieldFileName(i))
      continue;
    
    char nam[3]; sprintf(nam,"e%i",i+1);
    if(ThreeD) {
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,-1,Nbins,opth1.Data());
      else  
	hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,-Nbins,Nbins,opth1.Data());
    } else if(CYL) { // Cylindrical: The firt bin with r>0 is actually the number 1 (not the 0).
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data());
      else
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data());
    } else { // 2D cartesian
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,opth1.Data());
      else 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,opth1.Data());
    }
    
    char hName[24];
    sprintf(hName,"hE_%i",i);
    hE1D[i]->SetName(hName);
    if(opt.Contains("comov"))
      hE1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
    else
      hE1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
   
    if(i==0)
      hE1D[i]->GetYaxis()->SetTitle("E_{z} [E_{0}]");
    else if(i==1)
      hE1D[i]->GetYaxis()->SetTitle("E_{y} [E_{0}}]");
    else if(i==2)
      hE1D[i]->GetYaxis()->SetTitle("E_{x} [E_{0}}]");
    
    
  }  
  
  // Chaning to user units: 
  if(opt.Contains("units") && n0) {
    for(Int_t i=0;i<Nfields;i++) {
      Int_t NbinsX = hE1D[i]->GetNbinsX();
      Float_t xMin = (skindepth/PUnits::mm) * hE1D[i]->GetXaxis()->GetXmin();
      Float_t xMax = (skindepth/PUnits::mm) * hE1D[i]->GetXaxis()->GetXmax();
      
      hE1D[i]->SetBins(NbinsX,xMin,xMax);
      
      for(Int_t j=0;j<NbinsX;j++) {
	hE1D[i]->SetBinContent(j, hE1D[i]->GetBinContent(j) * ( E0 / (PUnits::GV/PUnits::m) ) );
      }
      
      if(opt.Contains("comov"))
	hE1D[i]->GetXaxis()->SetTitle("#zeta [mm]");
      else
	hE1D[i]->GetXaxis()->SetTitle("z [mm]");
      
      if(i==0)
	hE1D[i]->GetYaxis()->SetTitle("E_{z} [GV/m]");
      else if(i==1)
	hE1D[i]->GetYaxis()->SetTitle("E_{y} [GV/m]");
      else if(i==2)
	hE1D[i]->GetYaxis()->SetTitle("E_{x} [GV/m]");
    }
  }
  
  // Calculate wave positions:
  // ----------------------------------------------------------------
  
  // Retrieve the previous time TGraph if any;
  // Open TGraph
  TString filename = Form("./%s/Plots/Field1D/Field1D-%s.root",sim.Data(),sim.Data());
  TFile * ifile = (TFile*) gROOT->GetListOfFiles()->FindObject(filename);
  // if doesn't exist the directory should be created
  if (!ifile) {
    TString f = filename;
    TString dir2 = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) );
    TString dir1 = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) );
    gSystem->mkdir( dir1 );
    gSystem->mkdir( dir2 );
    ifile = new TFile(filename,"UPDATE");
  }  
  
  
  
  Float_t *EMaxPos = new Float_t[Nfields];
  Float_t *EMaxValue = new Float_t[Nfields];
  
  // Get the Graph with the x1 positions of the maximum E_1
  TGraph **graph = new TGraph*[Nfields];
  char gName[24];
  for(Int_t i=0;i<Nfields;i++) {
    if(!hE1D[i]) continue;
    
    EMaxPos[i] = EMaxValue[i] = -999;
    
    // Initial time search window:
    Float_t xCenter = (hE1D[i]->GetXaxis()->GetXmin()+hE1D[i]->GetXaxis()->GetXmax())/2.; 
    Float_t xs1min = 0.5*(hE1D[i]->GetXaxis()->GetXmin()+xCenter);
    Float_t xs1max = xCenter;

    // For focusing fields i==1,2 we use a narrower window based on the previosly found 
    // minimum for the accelerating fields i==0.
    if(i>0) {
      xCenter = EMaxPos[0];
      if(opt.Contains("units") && n0) {
	xs1min = xCenter - (0.25*TMath::Pi() * 1e3 * skindepth);
	xs1max = xCenter + (0.25*TMath::Pi() * 1e3 * skindepth);
      } else {
	xs1min = xCenter - 0.25*TMath::Pi();
	xs1max = xCenter + 0.25*TMath::Pi();
      }
    }

    sprintf(gName,"gEMaxPos_%i",i);
    graph[i] =  (TGraph*) ifile->Get(gName);
    if(graph[i]) {
      Double_t *y = graph[i]->GetY();
      
      // Setup the searching windows to +/- pi/2 respect the last found minimum.
      if(opt.Contains("units") && n0) {
	xs1min = y[graph[i]->GetN()-1] - (0.5*TMath::Pi() * 1e3 * skindepth);
	xs1max = y[graph[i]->GetN()-1] + (0.5*TMath::Pi() * 1e3 * skindepth);
      } else {
	xs1min = y[graph[i]->GetN()-1] - 0.5*TMath::Pi();
	xs1max = y[graph[i]->GetN()-1] + 0.5*TMath::Pi();
      }
      
      delete graph[i];
    }
    
    TH1F *htemp = (TH1F*) hE1D[i]->Clone("htemp");
    htemp->GetXaxis()->SetRangeUser(xs1min,xs1max);
    
    //htemp->Smooth(1,"R");
    Int_t binMax = htemp->GetMinimumBin();
    EMaxPos[i] = (Float_t) htemp->GetBinCenter(binMax);
    EMaxValue[i] = (Float_t) htemp->GetBinContent(binMax);
    delete htemp;
    
  }
  
  
  // Tunning the Histograms
  // ---------------------
  
  
  // Plotting
  // -----------------------------------------------
  
  // Output file
  TString fOutName = Form("./%s/Plots/Field1D/Field1D",sim.Data());
  fOutName += Form("-%s_%i",sim.Data(),time);
  
  // Canvas setup
  TCanvas *C = new TCanvas("C","Electric wakefield on axis",850,1000);
  C->Divide(1,2);

  // Draw objects
  TPaveText *textTime = new TPaveText(0.70,0.87,0.85,0.92,"NDC");
  PlasmaGlob::SetPaveTextStyle(textTime); 
  char ctext[128];
  if(opt.Contains("units") && n0) 
    sprintf(ctext,"Z = %5.1f mm", 1e3 * skindepth * Time);
  else
    sprintf(ctext,"T = %5.1f 1/#omega_{p}",Time);
  textTime->AddText(ctext);
  
  // Colors
  Int_t fieldC  = PlasmaGlob::fieldLine;
  Int_t phaseC  = kGray+1;
 
  // Actual Plotting!
  // ------------------------------------------------------------

  // More makeup
  C->cd(1);
  gPad->SetGridy(0);
  gPad->SetGridx(0);
  gPad->SetFrameLineWidth(2);  

  hE1D[0]->SetLineWidth(1);
  hE1D[0]->GetYaxis()->CenterTitle();
  hE1D[0]->GetXaxis()->CenterTitle();
  hE1D[0]->SetLineStyle(1);
  hE1D[0]->SetLineWidth(3);
  hE1D[0]->SetLineColor(fieldC);
  hE1D[0]->SetMarkerStyle(20);

  if(Nfields>1) {
    hE1D[1]->GetYaxis()->CenterTitle();
    hE1D[1]->GetXaxis()->CenterTitle();
    hE1D[1]->SetLineStyle(1);
    hE1D[1]->SetLineWidth(1);  
    hE1D[1]->SetLineColor(fieldC);
    hE1D[1]->SetMarkerStyle(24);
  }

  Float_t factor = 1.5;
  Float_t minimum = factor * hE1D[0]->GetMinimum();
  Float_t maximum = factor * hE1D[0]->GetMaximum();
    
  if(Nfields>1) {
    if(hE1D[1]->GetMaximum() > hE1D[0]->GetMaximum()) {
      maximum = factor * hE1D[1]->GetMaximum();
    } 
    
    if(hE1D[1]->GetMinimum() < hE1D[0]->GetMinimum()) {
    minimum = factor * hE1D[1]->GetMinimum();
    } 
  }
  
  if( maximum >= TMath::Abs(minimum)) minimum = -maximum;
  else maximum = - minimum;
  
  hE1D[0]->GetYaxis()->SetRangeUser(minimum,maximum);
  hE1D[0]->Draw("C");
  
  if(Nfields>1)
    hE1D[1]->Draw("C same");
  
  C->Update();
  
  TLine *line0 = new TLine(hE1D[0]->GetXaxis()->GetXmin(),
			   (gPad->GetUymin()+gPad->GetUymax())/2.,
			   hE1D[0]->GetXaxis()->GetXmax(),
			   (gPad->GetUymin()+gPad->GetUymax())/2.);
  line0->SetLineColor(kGray+1);
  line0->SetLineStyle(2);
  line0->Draw();
  
  TMarker *markEMax0 = new TMarker(EMaxPos[0],EMaxValue[0], 24);
  markEMax0->SetMarkerColor(fieldC);
  markEMax0->SetMarkerSize(1.6);
  markEMax0->Draw();

  if(Nfields>1) {
    TMarker *markEMax1 = new TMarker(EMaxPos[1],EMaxValue[1], 24);
    markEMax1->SetMarkerColor(fieldC);
    markEMax1->SetMarkerSize(1.4);
    markEMax1->Draw();
  }
  
  textTime->Draw();

  // ----
  
  // Define the TGraphs
  Int_t nPoints = 0;  
  TGraph **gEMaxPos = new TGraph*[Nfields];
  TGraph **gEMaxValue = new TGraph*[Nfields];
  for(Int_t i=0;i<Nfields;i++) {
    if(!hE1D[i]) continue;

    sprintf(gName,"gEMaxPos_%i",i);
    gEMaxPos[i] = (TGraph*) ifile->Get(gName);
    if(gEMaxPos[i]==NULL) {
      gEMaxPos[i] = new TGraph();
      gEMaxPos[i]->SetName(gName);
    } else {
      nPoints = gEMaxPos[i]->GetN(); 
    }  
    gEMaxPos[i]->Set(nPoints+1);
    if(opt.Contains("units") && n0) 
      gEMaxPos[i]->SetPoint(nPoints, 1e3 * skindepth * Time,EMaxPos[i]);
    else
      gEMaxPos[i]->SetPoint(nPoints,Time,EMaxPos[i]);
    
    if(opt.Contains("units") && n0) {
      gEMaxPos[i]->GetYaxis()->SetTitle("#zeta_{min} [mm]");
      gEMaxPos[i]->GetXaxis()->SetTitle("Z [mm]");
    } else {
      gEMaxPos[i]->GetYaxis()->SetTitle("#zeta_{min} [c/#omega_{p}]");
      gEMaxPos[i]->GetXaxis()->SetTitle("T [c/#omega_{p}]");
    }

    gEMaxPos[i]->Write(gEMaxPos[i]->GetName(),TObject::kOverwrite);

    sprintf(gName,"gEMaxValue_%i",i);
    gEMaxValue[i] = (TGraph*) ifile->Get(gName);
    if(gEMaxValue[i]==NULL) {
      gEMaxValue[i] = new TGraph();  
      gEMaxValue[i]->SetName(gName);
    } else {
      nPoints = gEMaxValue[i]->GetN(); 
    }  
    gEMaxValue[i]->Set(nPoints+1);
    if(opt.Contains("units") && n0) 
      gEMaxValue[i]->SetPoint(nPoints, 1e3 * skindepth * Time,EMaxValue[i]);
    else
      gEMaxValue[i]->SetPoint(nPoints,Time,EMaxValue[i]);
    
    if(opt.Contains("units") && n0) {
      gEMaxValue[i]->GetYaxis()->SetTitle("E_{min} [GV/m]");
      gEMaxValue[i]->GetXaxis()->SetTitle("Z [mm]");
    } else {
      gEMaxValue[i]->GetYaxis()->SetTitle("E_{min} [E_{0}]");
      gEMaxValue[i]->GetXaxis()->SetTitle("T [c/#omega_{p}]");
    }
    
    gEMaxValue[i]->Write(gEMaxValue[i]->GetName(),TObject::kOverwrite);    
  }


  C->cd(2);
  gPad->SetGridy(1);
  gPad->SetGridx(0);
  gPad->SetFrameLineWidth(2);  

  Float_t minPhase = 99.;
  Float_t maxPhase = -99.;
  Float_t minField = 99.;
  Float_t maxField = -99.;

  Double_t *yEMaxPos[Nfields];
  Double_t *yEMaxValue[Nfields];

  for(Int_t i=0;i<Nfields;i++) {
    yEMaxPos[i]   = gEMaxPos[i]->GetY();
    yEMaxValue[i] = gEMaxValue[i]->GetY();
    
    for(Int_t j=0;j<gEMaxPos[0]->GetN();j++) {
      if(yEMaxPos[i][j]>maxPhase)
	maxPhase = yEMaxPos[i][j];
      if(yEMaxPos[i][j]<minPhase)
	minPhase = yEMaxPos[i][j];
 
      if(yEMaxValue[i][j]>maxField)
	maxField = yEMaxValue[i][j];
      if(yEMaxValue[i][j]<minField)
	minField = yEMaxValue[i][j];
    }
  }

  Float_t margin = (maxPhase - minPhase)/10;
  gEMaxPos[0]->GetYaxis()->SetRangeUser(minPhase-margin,maxPhase+margin);
  gEMaxPos[0]->GetYaxis()->CenterTitle();
  gEMaxPos[0]->GetXaxis()->CenterTitle();
  gEMaxPos[0]->SetLineColor(phaseC);
  gEMaxPos[0]->SetMarkerColor(phaseC);
  gEMaxPos[0]->SetLineWidth(3);
  gEMaxPos[0]->SetMarkerStyle(20);
  gEMaxPos[0]->SetMarkerSize(1.4);
  gEMaxPos[0]->Draw("APC");

  if(Nfields>1) {
    gEMaxPos[1]->SetLineStyle(1);
    gEMaxPos[1]->SetLineColor(phaseC);
    gEMaxPos[1]->SetMarkerColor(phaseC);
    gEMaxPos[1]->SetLineWidth(1);
    gEMaxPos[1]->SetMarkerStyle(24);
    gEMaxPos[1]->SetMarkerSize(1.4);
    gEMaxPos[1]->Draw("PC");
  }

  // Emax value
  // New axis first:
  C->Update();  // Needed for the axis!

  margin = (maxField - minField)/10;
  if (margin==0) margin = 1; 
  Float_t rightmin = minField-margin;
  Float_t rightmax = maxField+margin;
  Float_t slope = (gPad->GetUymax() - gPad->GetUymin())/(rightmax-rightmin);
  TGaxis *axisEmax = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(),
				gPad->GetUymax(),rightmin,rightmax,505,"+L");
  axisEmax->SetLineWidth(1);
  axisEmax->SetLineColor(fieldC);
  axisEmax->SetLabelColor(fieldC);
  axisEmax->SetTitleColor(fieldC);
  if(opt.Contains("units") && n0) 
    axisEmax->SetTitle("E_{min} [GV/m]");
  else
    axisEmax->SetTitle("E_{min} [E_{0}]");
  axisEmax->CenterTitle();
  axisEmax->SetTitleSize(0.05);
  axisEmax->SetTitleOffset(1.2);
  axisEmax->SetLabelSize(0.05);
  axisEmax->SetLabelOffset(0.006);
  
  axisEmax->Draw();
  
  // Adjust the TGraph
  Double_t *x = gEMaxValue[0]->GetX();
  Double_t *y = gEMaxValue[0]->GetY();
  for(Int_t i=0;i<gEMaxValue[0]->GetN();i++) {
    gEMaxValue[0]->SetPoint(i,x[i],(y[i]-rightmin)*slope + gPad->GetUymin());
  }  
  gEMaxValue[0]->SetLineColor(fieldC);
  gEMaxValue[0]->SetMarkerColor(fieldC);
  gEMaxValue[0]->SetLineWidth(3);
  gEMaxValue[0]->SetMarkerStyle(20);
  gEMaxValue[0]->SetMarkerSize(1.4);
  gEMaxValue[0]->Draw("PC");

   if(Nfields>1) {
    x = gEMaxValue[1]->GetX();
    y = gEMaxValue[1]->GetY();
    for(Int_t i=0;i<gEMaxValue[1]->GetN();i++) {
      gEMaxValue[1]->SetPoint(i,x[i],(y[i]-rightmin)*slope + gPad->GetUymin());
    }  
    gEMaxValue[1]->SetLineColor(fieldC);
    gEMaxValue[1]->SetMarkerColor(fieldC);
    gEMaxValue[1]->SetLineWidth(1);
    gEMaxValue[1]->SetMarkerStyle(24);
    gEMaxValue[1]->SetMarkerSize(1.4);
    gEMaxValue[1]->Draw("PC");
  }

  // Emax value
  // New axis first:
  C->Update();  // Needed for the axis!

  C->cd();

  ifile->Close();
  
  // Print to a file
  PlasmaGlob::imgconv(C,fOutName,opt);
  // ---------------------------------------------------------
  
  }