Commit 9b98eaac authored by TOUZE Francois's avatar TOUZE Francois
Browse files

redesign part of the madx:tunes - add checkboxes on outputs:plots view

parent 191cf5fc
......@@ -84,7 +84,7 @@ bool softwareElegant::createInputFile(particleBeam *beamBefore)
outfile << run_setup( lattice );
outfile << "&twiss_output\n";
outfile << twiss_options( amap ) << endl;
outfile << twiss_options( amap );
// the Twiss parameters file => xxx-twiss.sdds
outfile << " filename = " << simulationId_+"-twiss.sdds" << endl;
outfile << "&end\n" << endl;
......
......@@ -129,6 +129,92 @@ bool softwareMadx::createInputFile(particleBeam *beamBefore)
return true;
}
string softwareMadx::tunesStatement(const std::vector<smap>& v)
{
if(debug > 0) cout << "softwareMadx::tunesStatement()\n";
// accesses value for last element
abstractElement* elPtr;
elPtr= getComputingBlock()->getLastElement();
string label= elPtr->getLabel();
if(debug > 0) cout << "last element = " << label << endl;
ostringstream os;
os << "u0= " << v[1].find("start")->second.at(0) << ";\n";
os << "KMax= " << v[1].find("points")->second.at(0) << ";\n";
os << "du= " << v[1].find("range")->second.at(0) << "/KMax;\n";
os << "INTQx= " << v[2].find("INTQx")->second.at(0) << ";\n";
os << "INTQy= " << v[2].find("INTQy")->second.at(0) << ";\n";
string key= v[0].find("tunes_option")->second.at(0);
if (key.find("option 1") != string::npos) {
os << "create,table=T1,column= dp,Qx,Qy,bx,by,ax,ay;\n";
// Qx/Qy = horizontal/vertical tune versus DELTAP
os << "Qx:= table(summ,Q1) - INTQx;\n";
os << "Qy:= table(summ,Q2) - INTQy;\n";
// bx/by = amplitude functions beta versus DELTAP
os << "bx:= table(twiss," << label << ",betx);\n";
os << "by:= table(twiss," << label << ",bety);\n";
// ax/ay = correlation function alpha versus DELTAP
os << "ax:= table(twiss," << label << ",alfx);\n";
os << "ay:= table(twiss," << label << ",alfy);\n\n";
os << "k= 0;\n";
os << "while (k <= KMAX)\n";
os << "{\n";
os << " dp= u0 + k*du;\n";
os << " twiss, deltap= dp;\n";
os << " fill,table= T1;\n";
os << " k= k+1;\n";
os << "}\n";
// creates the table => xxx-Etunes.txt
os << "write,table=T1,file=" + getFileName("Etunes",true) << ";\n";
} else if (key.find("option 2") != string::npos ) {
os << "create,table=T2,column= uk,Qx,Qy;\n";
// tunes versus x position
os << "Qx:= table(summ,Q1) - INTQx;\n";
os << "Qy:= table(summ,Q2) - INTQy;\n";
os << "k= 0;\n";
os << "while (k <= KMAX)\n";
os << "{\n";
os << " uk= u0 + k*du;\n";
os << " twiss, x= uk;\n";
os << " fill,table= T2;\n";
os << " k= k+1;\n";
os << "}\n";
// creates the table => xxx-Xtunes.txt
os << "write,table=T2,file=" + getFileName("Xtunes",true) << ";\n";
} else if (key.find("option 3") != string::npos ) {
os << "create,table=T3,column= uk,Qx,Qy;\n";
// tunes versus y position
os << "Qx:= table(summ,Q1) - INTQx;\n";
os << "Qy:= table(summ,Q2) - INTQy;\n";
os << "k= 0;\n";
os << "while (k <= KMAX)\n";
os << "{\n";
os << " uk= u0 + k*du;\n";
os << " twiss, y= uk;\n";
os << " fill,table= T3;\n";
os << " k= k+1;\n";
os << "}\n";
// creates the table => xxx-Ytunes.txt
os << "write,table=T3,file=" + getFileName("Ytunes",true) << ";\n";
} else {
cout << "ERROR in softwareMadx::tunesStatements option= " << key << " not defined\n";
return string();
}
return os.str();
}
/**
string softwareMadx::tunesStatement(const std::vector<smap>& v)
{
if(debug > 0) cout << "softwareMadx::tunesStatement()\n";
......@@ -253,6 +339,8 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
return os.str();
}
*/
string softwareMadx::twissStatement(const std::vector<smap>& v)
{
......@@ -663,7 +751,6 @@ string softwareMadx::fromDistribution(const vector<psvs>& v)
string softwareMadx::beamData(particleBeam *beam)
{
debug = 999;
if(debug > 0) cout << "softwareMadx::beamData( 2 )\n";
double p0= beam->getP0Transport(); // GeV
......@@ -1411,11 +1498,11 @@ void softwareMadx::TEtune(json& j)
}
ifs.close();
smap::const_iterator it= vmap.find("deltap");
smap::const_iterator it= vmap.find("deltap"); // Z! en %
for(int k = 0; k < it->second.size(); k++)
{
double xcoor= atof( it->second.at(k).c_str() );
j["deltap"].push_back( xcoor );
j["deltap"].push_back( 100.*xcoor );
}
it= vmap.find("qx");
......@@ -1482,29 +1569,29 @@ void softwareMadx::TXtune(json& j)
ifs >> buf;
vmap[ "qx" ].push_back( buf );
ifs >> buf;
vmap[ "qy" ].push_back( buf );
vmap[ "qx" ].push_back( buf );
}
ifs.close();
smap::const_iterator it= vmap.find("Ax");
smap::const_iterator it= vmap.find("Ax"); // Z! en mm
for(int k = 0; k < it->second.size(); k++)
{
double xcoor= atof( it->second.at(k).c_str() );
j["Ax"].push_back( xcoor );
j["Ax"].push_back( 1000*xcoor );
}
it= vmap.find("qx");
for(int k = 0; k < it->second.size(); k++)
{
double ycoor= atof( it->second.at(k).c_str() );
j["qx"].push_back( ycoor );
j["q1x"].push_back( ycoor );
}
it= vmap.find("qy");
for(int k = 0; k < it->second.size(); k++)
{
double ycoor= atof( it->second.at(k).c_str() );
j["qy"].push_back( ycoor );
j["q2x"].push_back( ycoor );
}
}
......@@ -1533,25 +1620,25 @@ void softwareMadx::TYtune(json& j)
}
ifs.close();
smap::const_iterator it= vmap.find("Ay");
smap::const_iterator it= vmap.find("Ay"); // Z! en mm
for(int k = 0; k < it->second.size(); k++)
{
double xcoor= atof( it->second.at(k).c_str() );
j["Ay"].push_back( xcoor );
j["Ay"].push_back( 1000*xcoor );
}
it= vmap.find("qx");
for(int k = 0; k < it->second.size(); k++)
{
double ycoor= atof( it->second.at(k).c_str() );
j["qx"].push_back( ycoor );
j["q1y"].push_back( ycoor );
}
it= vmap.find("qy");
for(int k = 0; k < it->second.size(); k++)
{
double ycoor= atof( it->second.at(k).c_str() );
j["qy"].push_back( ycoor );
j["q2y"].push_back( ycoor );
}
}
......
......@@ -59,6 +59,13 @@ json pspaplot::phaseSpace(json j, string opt)
ifs >> obj;
ifs.close();
// check if the horizontal r.m.s table exists
it= obj.find("xsigma");
if (it == obj.end()) {
cout << "select the Beam parameters option in Twiss commands\n";
return json({});
}
// displays the horizontal (xx') ellipse at the beginning/end of the beam line
vector<double> Xaxis, Yaxis;
......@@ -77,10 +84,24 @@ json pspaplot::phaseSpace(json j, string opt)
cout << "option error in the ellipse plot => " << opt << endl;
return json({});
}
xrms *= 0.001;
int n= 50;
double h= 2.0*xrms/n;
for (int k = 0; k < n; ++k)
int m= 10;
for (int j = 0; j < m; ++j)
{
double xk= -xrms + j*h/m;
Xaxis.push_back( xk );
double aux= xrms*xrms - xk*xk;
double yk= -alfa*xk + sqrt(fabs(aux));
yk /= beta;
Yaxis.push_back( yk );
}
for (int k = 1; k < n-1; ++k)
{
double xk= -xrms + k*h;
Xaxis.push_back( xk );
......@@ -89,7 +110,28 @@ json pspaplot::phaseSpace(json j, string opt)
yk /= beta;
Yaxis.push_back( yk );
}
for (int k = 0; k < n+1; ++k)
for (int j = 0; j < m; ++j)
{
double xk= -xrms + (n-1)*h + j*h/m;
Xaxis.push_back( xk );
double aux= xrms*xrms - xk*xk;
double yk= -alfa*xk + sqrt(fabs(aux));
yk /= beta;
Yaxis.push_back( yk );
}
for (int j = 0; j < m; ++j)
{
double xk= xrms - j*h/m;
Xaxis.push_back( xk );
double aux= xrms*xrms - xk*xk;
double yk= -alfa*xk - sqrt(fabs(aux));
yk /= beta;
Yaxis.push_back( yk );
}
for (int k = 1; k < n-1; ++k)
{
double xk= xrms - k*h;
Xaxis.push_back( xk );
......@@ -99,6 +141,16 @@ json pspaplot::phaseSpace(json j, string opt)
Yaxis.push_back( yk );
}
for (int j = 0; j < m+1; ++j)
{
double xk= xrms - (n-1)*h - j*h/m;
Xaxis.push_back( xk );
double aux= xrms*xrms - xk*xk;
double yk= -alfa*xk - sqrt(fabs(aux));
yk /= beta;
Yaxis.push_back( yk );
}
json jx;
jx["type"]= "line";
......@@ -143,6 +195,10 @@ json pspaplot::beamParameters(json j)
{
auto ids= j.find( "plotSimulation" );
string item= j.find( "plotItem" ).value();
std::cout << std::boolalpha;
//cout << "ids is_array? " << ids->is_array() << "\n";
//cout << "ids size? " << ids->size() << "\n";
vector<double> Xaxis;
map<string,vector<double> > Ymaps;
......@@ -162,26 +218,14 @@ json pspaplot::beamParameters(json j)
ifs >> obj;
ifs.close();
submenu1(item,obj,xshift,Xaxis);
submenu2(item,obj,Ymaps);
string softw= obj.find( "software" ).value();
//cout << "softw => " << softw << endl;
//cout << "softw => " << softw << endl;
string action= obj.find( "action" ).value();
cout << "pspaplot::beamParameters: action => " << action << endl;
if (action == "tunes") {
submenu1(item,obj,Xaxis,Ymaps);
break;
} else {
json::iterator xaxis= obj.find( "zcoor" );
for(unsigned int i = 0; i < xaxis->size(); ++i)
{
double zcoor= xaxis->at( i );
zcoor+= xshift;
Xaxis.push_back( zcoor );
}
xshift= xaxis->back();
submenu2(item,obj,Ymaps);
}
if (action == "tunes") break;
}
json jx;
......@@ -194,53 +238,35 @@ json pspaplot::beamParameters(json j)
return jx;
}
void pspaplot::submenu1(string key,json obj,vector<double>& Xaxis,map<string,vector<double> >& Ymaps)
{
void pspaplot::submenu1(string key,json obj,double& xshift,vector<double>& Xaxis)
{
json::iterator xaxis= obj.end();
if (key == "tunesVSdelta") {
xaxis= obj.find( "deltap" );
if( xaxis == obj.end() ) return;
menu("qx",obj,Ymaps);
menu("qy",obj,Ymaps);
}
if (key == "betaVSdelta") {
} else if (key == "betaVSdelta") {
xaxis= obj.find( "deltap" );
if( xaxis == obj.end() ) return;
menu("bx",obj,Ymaps);
menu("by",obj,Ymaps);
}
if (key == "alfaVSdelta") {
} else if (key == "alfaVSdelta") {
xaxis= obj.find( "deltap" );
if( xaxis == obj.end() ) return;
menu("ax",obj,Ymaps);
menu("ay",obj,Ymaps);
}
if (key == "tunesVSx") {
} else if (key == "tunesVSx") {
xaxis= obj.find( "Ax" );
if( xaxis == obj.end() ) return;
menu("qx",obj,Ymaps);
menu("qy",obj,Ymaps);
}
if (key == "tunesVSy") {
} else if (key == "tunesVSy") {
xaxis= obj.find( "Ay" );
if( xaxis == obj.end() ) return;
menu("qx",obj,Ymaps);
menu("qy",obj,Ymaps);
} else {
xaxis= obj.find( "zcoor" );
}
if( xaxis == obj.end() ) return;
if (xaxis == obj.end()) return;
for(unsigned int i = 0; i < xaxis->size(); ++i)
{
Xaxis.push_back( xaxis->at( i ) );
double zcoor= xaxis->at( i );
zcoor+= xshift;
Xaxis.push_back( zcoor );
}
xshift= xaxis->back();
}
void pspaplot::submenu2(string key,json obj,map<string,vector<double> >& Ymaps)
{
{
if (key == "rms-emittance") { // valid only for track
menu("xemit",obj,Ymaps);
menu("yemit",obj,Ymaps);
......@@ -288,7 +314,33 @@ void pspaplot::submenu2(string key,json obj,map<string,vector<double> >& Ymaps)
menu("wx",obj,Ymaps);
menu("wy",obj,Ymaps);
menu("xetap",obj,Ymaps);
}
}
if (key == "tunesVSdelta") { // valid only for tunes
menu("qx",obj,Ymaps);
menu("qy",obj,Ymaps);
}
if (key == "betaVSdelta") { // valid only for tunes
menu("bx",obj,Ymaps);
menu("by",obj,Ymaps);
}
if (key == "alfaVSdelta") { // valid only for tunes
menu("ax",obj,Ymaps);
menu("ay",obj,Ymaps);
}
if (key == "tunesVSx") { // valid only for tunes
menu("q1x",obj,Ymaps);
menu("q2x",obj,Ymaps);
}
if (key == "tunesVSy") { // valid only for tunes
menu("q1y",obj,Ymaps);
menu("q2y",obj,Ymaps);
}
}
void pspaplot::menu(string key,json obj,map<string,vector<double> >& Ymaps)
......@@ -309,8 +361,10 @@ json pspaplot::lineplots(vector<double> Xaxis,map<string,vector<double> > Ymaps)
json x;
string title;
string leftLabel;
string xcoor= "z [m]";
///// First dataset (on left y-axis) /////
map<string,vector<double> >::iterator it;
if (Ymaps.find("xemit") != Ymaps.end()) {
x["label"]= "εx [π.mrad.mm]";
......@@ -369,26 +423,40 @@ json pspaplot::lineplots(vector<double> Xaxis,map<string,vector<double> > Ymaps)
if (Ymaps.find("qx") != Ymaps.end()) {
x["label"]= "Qx";
it= Ymaps.find("qx");
title= "Tunes VS Δp/p (%)";
xcoor= "Δp/p";
title= "Tunes VS Δp/p";
xcoor= "Δp/p (%)";
leftLabel= "Qx";
}
if (Ymaps.find("bx") != Ymaps.end()) {
x["label"]= "βx";
it= Ymaps.find("bx");
title= "β VS Δp/p (%), SS centre";
xcoor= "Δp/p";
title= "β VS Δp/p, SS centre";
xcoor= "Δp/p (%)";
leftLabel= "βx";
}
if (Ymaps.find("ax") != Ymaps.end()) {
x["label"]= "αx*10⁻³";
it= Ymaps.find("ax");
title= "α VS Δp/p (%), SS centre";
xcoor= "Δp/p";
title= "α VS Δp/p, SS centre";
xcoor= "Δp/p (%)";
leftLabel= "αx*10⁻³";
}
if (Ymaps.find("q1x") != Ymaps.end()) {
x["label"]= "Qx";
it= Ymaps.find("q1x");
title= "Tunes VS x";
xcoor= "x (mm)";
leftLabel= "Qx";
}
if (Ymaps.find("q1y") != Ymaps.end()) {
x["label"]= "Qx";
it= Ymaps.find("q1y");
title= "Tunes VS y";
xcoor= "y (mm)";
leftLabel= "Qx";
}
// First dataset (left)
// write dataset
x["backgroundColor"]= "#74B9FF";
x["borderColor"]= "#74B9FF";
x["fill"]= false;
......@@ -401,48 +469,38 @@ json pspaplot::lineplots(vector<double> Xaxis,map<string,vector<double> > Ymaps)
}
j["data"]["datasets"].push_back( x );
x.clear();
///// Second dataset (on left y-axis) /////
bool addDataset= false;
if (Ymaps.find("yemit") != Ymaps.end()) {
x["label"]= "εy [π.mrad.mm]";
it= Ymaps.find("yemit");
addDataset= true;
leftLabel += ",εy";
addDataset= true;
}
if (Ymaps.find("ysigma") != Ymaps.end()) {
x["label"]= "σy [mm]";
it= Ymaps.find("ysigma");
addDataset= true;
leftLabel += ",σy";
addDataset= true;
}
if (Ymaps.find("ybeta") != Ymaps.end()) {
if (Ymaps.find("xeta") != Ymaps.end()) {
x["label"]= "βy [m]";
it= Ymaps.find("ybeta");
leftLabel+= ",βy";
addDataset= true;
leftLabel += ",βy";
}
}
if (Ymaps.find("yalfa") != Ymaps.end()) {
x["label"]= "αy [m]";
it= Ymaps.find("yalfa");
addDataset= true;
leftLabel += ",αy";
}
if (Ymaps.find("ymu") != Ymaps.end()) {
x["label"]= "μy [2π]";
it= Ymaps.find("ymu");
addDataset= true;
leftLabel += ",μy";
}
if (Ymaps.find("wy") != Ymaps.end()) {
x["label"]= "wy";
it= Ymaps.find("wy");
addDataset= true;
leftLabel += ",wy";
addDataset= true;
}
// Second dataset (left)
// write dataset
if (addDataset) {
x["backgroundColor"]= "#FF6384";
x["borderColor"]= "#FF6384";
......@@ -458,26 +516,60 @@ json pspaplot::lineplots(vector<double> Xaxis,map<string,vector<double> > Ymaps)
x.clear();
}
string rightLabel;
///// Third dataset (on left y-axis) /////
addDataset= false;
if (Ymaps.find("ybeta") != Ymaps.end()) {
if (Ymaps.find("xeta") != Ymaps.end()) {
if (Ymaps.find("xeta") != Ymaps.end()) {
x["label"]= "ηₓ [m]";
it= Ymaps.find("xeta");
rightLabel= "ηₓ";
leftLabel+= ", and ηₓ";
addDataset= true;
} else {
}
if (Ymaps.find("xetap") != Ymaps.end()) {
x["label"]= "η'ₓ [m]";
it= Ymaps.find("xetap");
leftLabel+= "η'ₓ";
addDataset= true;
}
// write dataset
if (addDataset) {
x["backgroundColor"]= "#2CA02C";
x["borderColor"]= "#2CA02C";
x["fill"]= false;
x["yAxisID"]= "y-axis-1";
x["pointRadius"]= 0;
for(unsigned int k = 0; k < Xaxis.size(); ++k)
{
json xy= {{"x",Xaxis.at(k)},{"y",it->second.at(k)}};
x["data"].push_back( xy );
}
j["data"]["datasets"].push_back( x );
x.clear();
}
///// second dataset (on right y-axis) /////
addDataset= false;
string rightLabel;
if (Ymaps.find("ybeta") != Ymaps.end()) {
if (Ymaps.find("xeta") == Ymaps.end()) {
x["label"]= "βy [m]";
it= Ymaps.find("ybeta");
rightLabel += "βy";
rightLabel= "βy";
addDataset= true;
}
}
if (Ymaps.find