Commit f7cfae77 authored by TOUZE Francois's avatar TOUZE Francois
Browse files

update the tunes computation

parent 20d22a1a
......@@ -1119,19 +1119,39 @@ void computingBlock::jtunesOutput(json& j,const vector<smap>& v)
// **** TUNES Vs Y POSITIONS ****
if( str.find("option 3") != string::npos )
j["tunesOption"]= "tunesYPositions";
smap::const_iterator kt;
kt= v[ 1 ].find("range");
if (kt != v[1].end()) {
j["scan"]["range"]= kt->second.at(0);
} else {
j["scan"]["range"]= nullptr;
}
kt= v[ 1 ].find("start");
if (kt != v[1].end()) {
j["scan"]["start"]= kt->second.at(0);
} else {
j["scan"]["start"]= nullptr;
}
kt= v[ 1 ].find("points");
if (kt != v[1].end()) {
j["scan"]["points"]= kt->second.at(0);
} else {
j["scan"]["points"]= nullptr;
}
string tx;
tx= v[ 1 ].find("range")->second.at(0);
j["scan"]["range"]= atof( tx.c_str() );
tx= v[ 1 ].find("start")->second.at(0);
j["scan"]["start"]= atof( tx.c_str() );
tx= v[ 1 ].find("points")->second.at(0);
j["scan"]["points"]= atoi( tx.c_str() );
tx= v[ 2 ].find("INTQx")->second.at(0);
j["scan"]["inqX"]= atoi( tx.c_str() );
tx= v[ 2 ].find("INTQy")->second.at(0);
j["scan"]["inqY"]= atoi( tx.c_str() );
kt= v[ 2 ].find("INTQx");
if (kt != v[2].end()) {
j["scan"]["inqX"]= kt->second.at(0);
} else {
j["scan"]["inqX"]= nullptr;
}
kt= v[ 2 ].find("INTQy");
if (kt != v[2].end()) {
j["scan"]["inqY"]= kt->second.at(0);
} else {
j["scan"]["inqY"]= nullptr;
}
}
void computingBlock::jmatchOutput(json& j,const vector<smap>& v)
......@@ -1320,7 +1340,6 @@ void computingBlock::jmatchOutput(json& j,const vector<smap>& v)
bool computingBlock::fromJSON(json j)
{
if (debug > 0) cout << "\ncomputingBlock::fromJSON\n";
bool status= true;
string s1= j.find( "id" ).value();
......@@ -1613,6 +1632,8 @@ std::vector<smap> computingBlock::jtwissInput(json j)
std::vector<smap> computingBlock::jtunesInput(json j)
{
if (debug > 0) cout << "computingBlock::jtunesInput()\n";
auto z1= j.find( "parameters" );
string option= z1->find( "tunesOption" ).value();
......@@ -1629,21 +1650,24 @@ std::vector<smap> computingBlock::jtunesInput(json j)
auto z2= z1->find( "scan" ).value();
if( !amap.empty() ) amap.clear();
json::iterator it;
it = z2.find("range");
amap[ "range" ].push_back(mixedTools::doubleToString(it.value()));
if (!it->is_null()) amap[ "range" ].push_back( it.value() );
it = z2.find("start");
amap[ "start" ].push_back(mixedTools::doubleToString(it.value()));
if (!it->is_null()) amap[ "start" ].push_back( it.value() );
it = z2.find("points");
amap[ "points" ].push_back(mixedTools::intToString(it.value()));
if (!it->is_null()) amap[ "points" ].push_back( it.value() );
v.push_back( amap );
if( !amap.empty() ) amap.clear();
it = z2.find("inqX");
amap[ "INTQx" ].push_back(mixedTools::intToString(it.value()));
if (!it->is_null()) amap[ "INTQx" ].push_back( it.value() );
it = z2.find("inqY");
amap[ "INTQy" ].push_back(mixedTools::intToString(it.value()));
if (!it->is_null()) amap[ "INTQy" ].push_back( it.value() );
v.push_back( amap );
// mixedTools::print( v );
return v;
}
......
......@@ -134,6 +134,8 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
if(debug > 0) cout << "softwareMadx::tunesStatement()\n";
ostringstream os;
// accesses value for last element
abstractElement* elPtr;
elPtr= getComputingBlock()->getLastElement();
string label= elPtr->getLabel();
......@@ -141,16 +143,22 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
string str= v[0].find("tunes_option")->second.at(0);
if( str.find("option 1") != string::npos ) {
os<< "create, table=Etunes, column= delta_p,Qx,Qy,bx,by,ax,ay;\n";
// optical functions versus DELTAP at the end of the beam line expanded by USE
// Qx/Qy = horizontal/vertical tune
// bx/by = amplitude functions beta
// ax/ay = correlation function alpha
os<< "create, table=Etunes, column= z,Qx,Qy,bx,by,ax,ay;\n";
} else if( str.find("option 2") != string::npos ) {
os<< "create, table=Xtunes, column= Ax,Ay,Qx,Qy;\n";
// tunes versus x position at the end of the beam line expanded by USE
os<< "create, table=Xtunes, column= z,Qx,Qy;\n";
} else if( str.find("option 3") != string::npos ) {
os<< "create, table=Ytunes, column= Ax,Ay,Qx,Qy;\n";
// tunes versus y position at the end of the beam line expanded by USE
os<< "create, table=Ytunes, column= z,Qx,Qy;\n";
} else {
cout << "ERROR in softwareMadx::tunesStatements option= " << str << " not defined\n";
......@@ -159,67 +167,59 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
string tx= v[2].find("INTQx")->second.at(0);
os << "INTQx:= " << tx << ";\n";
// if( tx.find("none") == string::npos )
// os << "INTQx:= " << tx << ";\n";
// else
// os << "INTQx:= 0.0;\n";
tx= v[2].find("INTQy")->second.at(0);
os << "INTQy:= " << tx << ";\n";
// if( tx.find("none") == string::npos )
// os << "INTQy:= " << tx << ";\n";
// else
// os << "INTQy:= 0.0;\n";
os<< "du:= " << v[1].find("range")->second.at(0) << ";\n";
os<< "u0:= " << v[1].find("start")->second.at(0) << ";\n";
os<< "KMax= " << v[1].find("points")->second.at(0) << ";\n";
os<< "k= 1;\n";
os<< "uk:= u0;\n";
os<< "while (k < KMAX+1)\n";
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<< "k= 0;\n";
os<< "while (k <= KMAX)\n";
os<< "{\n";
os<< " uk = u0 + k*du;\n";
// **** TUNES, BETAS AND ALFAS @ SS CENTRE Vs ENERGY DEVIATION
if( str.find("option 1") != string::npos ) {
os<< " twiss, deltap= uk;\n";
os<< " delta_p:= 100*uk;\n";
os<< " bx:=table(twiss," << label << ",betx);\n";
os<< " by:=table(twiss," << label << ",bety);\n";
os<< " ax:=table(twiss," << label << ",alfx);\n";
os<< " ay:=table(twiss," << label << ",alfy);\n";
os<< " Qx:=table(twiss," << label << ",mux) - INTQx;\n";
os<< " Qy:=table(twiss," << label << ",muy) - INTQy;\n";
os<< " if(bx > 1e-100 && by > 1e-100) {\n";
os<< " fill,table= Etunes;\n";
os<< " z = 100*uk;\n";
os<< " Qx = table(twiss," << label << ",mux) - INTQx;\n";
os<< " Qy = table(twiss," << label << ",muy) - INTQy;\n";
os<< " bx = table(twiss," << label << ",betx);\n";
os<< " by = table(twiss," << label << ",bety);\n";
os<< " ax = table(twiss," << label << ",alfx);\n";
os<< " ay = table(twiss," << label << ",alfy);\n";
os<< " if (bx > 1e-100 && by > 1e-100) {\n";
os<< " fill,table = Etunes;\n";
os<< " }\n";
}
// **** TUNES Vs X POSITIONS ****
if( str.find("option 2") != string::npos ) {
os<< " twiss, x= uk;\n";
os<< " Ax:= 1000*uk;\n";
os<< " Ay:= 0.0;\n";
os<< " Qx:=table(twiss," << label << ",mux) - INTQx;\n";
os<< " Qy:=table(twiss," << label << ",muy) - INTQy;\n";
os<< " if(Qx < 1 && Qy < 1) {\n";
os<< " fill,table= Xtunes;\n";
os<< " z = 1000*uk;\n";
os<< " Qx = table(twiss," << label << ",mux) - INTQx;\n";
os<< " Qy = table(twiss," << label << ",muy) - INTQy;\n";
os<< " if (Qx < 1 && Qy < 1) {\n";
os<< " fill,table = Xtunes;\n";
os<< " }\n";
}
// **** TUNES Vs Y POSITIONS ****
if( str.find("option 3") != string::npos ) {
os<< " twiss, y= uk;\n";
os<< " Ax:= 0.0;\n";
os<< " Ay:= 1000*uk;\n";
os<< " Qx:=table(twiss," << label << ",mux) - INTQx;\n";
os<< " Qy:=table(twiss," << label << ",muy) - INTQy;\n";
os<< " if(Qx < 1 && Qy < 1) {\n";
os<< " fill,table= Ytunes;\n";
os<< " z = 1000*uk;\n";
os<< " Qx = table(twiss," << label << ",mux) - INTQx;\n";
os<< " Qy = table(twiss," << label << ",muy) - INTQy;\n";
os<< " if (Qx < 1 && Qy < 1) {\n";
os<< " fill,table = Ytunes;\n";
os<< " }\n";
}
os<< " uk:= u0 + k*du/KMax;\n";
os<< " k= k+1;\n";
os<< " k = k+1;\n";
os<< "};\n";
// plots
......@@ -228,16 +228,11 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
if( str.find("option 1") != string::npos ) {
// creates the TUNES table => xxx-Etunes.txt
os << "write, table=Etunes, file= "+getFileName("Etunes",true) << ";\n";
os << "plot, table=Etunes, haxis=delta_p, vaxis1=Qx, vaxis2=Qy, style=100, symbol=4, title=" << str1+"Tunes Vs Dp/p [%]"+str1 << ", noversion,file= " + setPlotsFile() << ";\n";
os << "write, table=Etunes, file= " + getFileName("Etunes",true) << ";\n";
// creates the TEND table => xxx-tend.txt
//os << "write, table=tend, file= "+getFileName("tend",true) << ";\n";
os << "plot, table=Etunes, haxis=delta_p, vaxis1=bx, vaxis2=by, style=100, symbol=4, title=" << str1+"Beta Vs Dp/p [%], SS centre"+str1 << ", noversion;\n";
os << "plot, table=Etunes, haxis=delta_p, vaxis1=ax, vaxis2=ay, style=100, symbol=4, title=" << str1+"Alfa Vs Dp/p [%], SS centre"+str1 << ", noversion;\n";
os << "plot, table=Etunes, haxis=z, vaxis1=Qx, vaxis2=Qy, style=100, symbol=4, title=" << str1+"Tunes Vs Dp/p [%]"+str1 << ", noversion,file= " + setPlotsFile() << ";\n";
os << "plot, table=Etunes, haxis=z, vaxis1=bx, vaxis2=by, style=100, symbol=4, title=" << str1+"Beta Vs Dp/p [%], SS centre"+str1 << ", noversion;\n";
os << "plot, table=Etunes, haxis=z, vaxis1=ax, vaxis2=ay, style=100, symbol=4, title=" << str1+"Alfa Vs Dp/p [%], SS centre"+str1 << ", noversion;\n";
}
if( str.find("option 2") != string::npos ) {
......@@ -245,7 +240,7 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
// creates the XTUNES table => xxx-Xtunes.txt
os << "write, table=Xtunes, file= "+getFileName("Xtunes",true) << ";\n";
os << "plot, table=Xtunes, haxis=Ax, vaxis1=Qx, vaxis2=Qy, style=100, symbol=4, title=" << str1+"Tunes Vs X position [mm]"+str1 << ", noversion, file= " + setPlotsFile() << ";\n";
os << "plot, table=Xtunes, haxis=z, vaxis1=Qx, vaxis2=Qy, style=100, symbol=4, title=" << str1+"Tunes Vs X position [mm]"+str1 << ", noversion, file= " + setPlotsFile() << ";\n";
}
if( str.find("option 3") != string::npos ) {
......@@ -253,7 +248,7 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
// creates the YTUNES table => xxx-Ytunes.txt
os << "write, table=Ytunes, file= "+getFileName("Ytunes",true) << ";\n";
os << "plot, table=Ytunes, haxis=Ay, vaxis1=Qx, vaxis2=Qy, style=100, symbol=4, title=" << str1+"Tunes Vs Y position [mm]"+str1 << ", noversion, file= " + setPlotsFile() << ";\n";
os << "plot, table=Ytunes, haxis=z, vaxis1=Qx, vaxis2=Qy, style=100, symbol=4, title=" << str1+"Tunes Vs Y position [mm]"+str1 << ", noversion, file= " + setPlotsFile() << ";\n";
}
return os.str();
......@@ -1116,8 +1111,6 @@ smap softwareMadx::getTableContents(ifstream& infile)
{
if(debug > 0) cout << "softwareMadx::getTableContents()\n";
cout << "softwareMadx::getTableContents()\n";
// format of the twiss file:
// the header
// element keywords
......@@ -1132,8 +1125,6 @@ smap softwareMadx::getTableContents(ifstream& infile)
{
if ( buf.find("* NAME") != string::npos ) break;
}
cout << "buf => " << buf << endl;
vector<string> vaxis;
if ( buf.find("BETX") != string::npos ) vaxis.push_back("betx");
......@@ -1145,8 +1136,6 @@ smap softwareMadx::getTableContents(ifstream& infile)
if ( buf.find("ALFY") != string::npos ) vaxis.push_back("alfy");
if ( buf.find("MUY" ) != string::npos ) vaxis.push_back("muy");
cout << "vaxis.size => " << vaxis.size() << endl;
//
// skip formats
//
......@@ -1167,8 +1156,6 @@ smap softwareMadx::getTableContents(ifstream& infile)
infile >> buf; // name
}
cout << "vmap.size => " << vmap.size() << endl;
return vmap;
}
......@@ -1425,7 +1412,7 @@ void softwareMadx::TEtune(json& j)
if ( buf.find("*") != string::npos ) break;
}
getline(ifs,buf); // skip formats
while (ifs >> buf) // deltap
while (ifs >> buf) // z=deltap
{
vmap[ "deltap" ].push_back( buf );
ifs >> buf;
......@@ -1508,12 +1495,10 @@ void softwareMadx::TXtune(json& j)
if ( buf.find("*") != string::npos ) break;
}
getline(ifs,buf); // skip formats
while (ifs >> buf) // Ax
while (ifs >> buf) // z
{
vmap[ "Ax" ].push_back( buf );
ifs >> buf;
vmap[ "Ay" ].push_back( buf ); // 0.0
ifs >> buf;
vmap[ "qx" ].push_back( buf );
ifs >> buf;
vmap[ "qy" ].push_back( buf );
......@@ -1557,10 +1542,8 @@ void softwareMadx::TYtune(json& j)
if ( buf.find("*") != string::npos ) break;
}
getline(ifs,buf); // skip formats
while (ifs >> buf) // Ax
while (ifs >> buf) // z
{
vmap[ "Ax" ].push_back( buf ); // 0.0
ifs >> buf;
vmap[ "Ay" ].push_back( buf );
ifs >> buf;
vmap[ "qx" ].push_back( buf );
......
......@@ -24,8 +24,11 @@ void pspaplot::settings(string str)
//cout << "item choisi => " << item << endl;
json obj;
if (item == "phase-space") obj= phaseSpace( j );
else obj= beamParameters( j );
if (item == "phase-space") {
obj= phaseSpace( j );
} else {
obj= beamParameters( j );
}
string fname= userDir_+"simulator-plot.txt";
ofstream outfile;
......@@ -129,13 +132,10 @@ json pspaplot::phaseSpace(json j)
return jx;
}
json pspaplot::beamParameters(json j)
{
auto ids= j.find( "plotSimulation" );
//std::cout << std::boolalpha;
//cout << "ids is_array? " << ids->is_array() << "\n";
string item= j.find( "plotItem" ).value();
vector<double> Xaxis;
......@@ -160,91 +160,126 @@ json pspaplot::beamParameters(json j)
//cout << "softw => " << softw << endl;
string action= obj.find( "action" ).value();
//cout << "pspaplot::beamParameters: action => " << action << endl;
json::iterator xaxis;
if (action == "tunes")
xaxis= obj.find( "deltap" );
else
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();
if (item == "rms-emittance") { // valid only for track
menu("xemit",obj,Ymaps);
menu("yemit",obj,Ymaps);
}
if (item == "beam-size") {
menu("xsigma",obj,Ymaps);
menu("ysigma",obj,Ymaps);
}
cout << "pspaplot::beamParameters: action => " << action << endl;
if (item == "bunch-length") { // valid only for track
menu("zsigma",obj,Ymaps);
}
if (item == "energy-spread") { // valid only for track
menu("spread",obj,Ymaps);
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 (item == "H-function") { // valid only for twiss
menu("xHinv",obj,Ymaps);
}
if (item == "beta-functions") {
if (action == "tunes") {
menu("bx",obj,Ymaps);
menu("by",obj,Ymaps);
} else {
menu("xbeta",obj,Ymaps);
menu("ybeta",obj,Ymaps);
if (action != "track") menu("xeta",obj,Ymaps);
}
}
if (item == "alfa-functions") {
if (action == "tunes") {
menu("ax",obj,Ymaps);
menu("ay",obj,Ymaps);
} else {
menu("xalfa",obj,Ymaps);
menu("yalfa",obj,Ymaps);
}
}
if (item == "phase-functions") { // valid only for twiss
menu("xmu",obj,Ymaps);
menu("ymu",obj,Ymaps);
}
if (item == "chromatic-functions") { // valid only for twiss
cout << "chromatic-functions\n";
menu("wx",obj,Ymaps);
menu("wy",obj,Ymaps);
menu("xetap",obj,Ymaps);
cout << "chromatic-functions.... done\n";
}
if (item == "tune-functions") { // valid only for tunes
menu("qx",obj,Ymaps);
menu("qy",obj,Ymaps);
}
}
json jx;
if (!Ymaps.empty()) jx= lineplots(Xaxis,Ymaps);
if (Ymaps.empty()) {
cout << "pspaplot::bad plot item... check your choice\n";
jx= json({});
} else {
jx= lineplots(Xaxis,Ymaps);
}
return jx;
}
void pspaplot::submenu1(string key,json obj,vector<double>& Xaxis,map<string,vector<double> >& Ymaps)
{
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") {
xaxis= obj.find( "deltap" );
if( xaxis == obj.end() ) return;
menu("bx",obj,Ymaps);
menu("by",obj,Ymaps);
}
if (key == "alfaVSdelta") {
xaxis= obj.find( "deltap" );
if( xaxis == obj.end() ) return;
menu("ax",obj,Ymaps);
menu("ay",obj,Ymaps);
}
if (key == "tunesVSx") {
xaxis= obj.find( "Ax" );
if( xaxis == obj.end() ) return;
menu("qx",obj,Ymaps);
menu("qy",obj,Ymaps);
}
if (key == "tunesVSy") {
xaxis= obj.find( "Ay" );
if( xaxis == obj.end() ) return;
menu("qx",obj,Ymaps);
menu("qy",obj,Ymaps);
}
if( xaxis == obj.end() ) return;
for(unsigned int i = 0; i < xaxis->size(); ++i)
{
Xaxis.push_back( xaxis->at( i ) );
}
}
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);
}
if (key == "beam-size") {
menu("xsigma",obj,Ymaps);
menu("ysigma",obj,Ymaps);
}
if (key == "bunch-length") { // valid only for track
menu("zsigma",obj,Ymaps);
}
if (key == "energy-spread") { // valid only for track
menu("spread",obj,Ymaps);
}
if (key == "H-function") { // valid only for twiss
menu("xHinv",obj,Ymaps);
}
if (key == "beta-functions") {
menu("xbeta",obj,Ymaps);
menu("ybeta",obj,Ymaps);
menu("xeta",obj,Ymaps);
}
if (key == "alfa-functions") {
menu("xalfa",obj,Ymaps);
menu("yalfa",obj,Ymaps);
}
if (key == "phase-functions") { // valid only for twiss
menu("xmu",obj,Ymaps);
menu("ymu",obj,Ymaps);
}
if (key == "chromatic-functions") { // valid only for twiss
menu("wx",obj,Ymaps);
menu("wy",obj,Ymaps);
menu("xetap",obj,Ymaps);
}
}
void pspaplot::menu(string key,json obj,map<string,vector<double> >& Ymaps)
{
auto it= obj.find( key );
......
......@@ -15,9 +15,12 @@ class pspaplot
json phaseSpace(json);
json beamParameters(json);
void submenu1(string,json,vector<double>&,map<string,vector<double> >&);
void submenu2(string,json,map<string,vector<double> >&);
void menu(string,json,map<string,vector<double> >&);
json lineplots(vector<double>,map<string,vector<double> >);
public:
pspaplot();
......