Skip to content

Instantly share code, notes, and snippets.

@admorris
Created March 11, 2016 12:33
Show Gist options
  • Save admorris/45066fedb281b3a4e17c to your computer and use it in GitHub Desktop.
Save admorris/45066fedb281b3a4e17c to your computer and use it in GitHub Desktop.
#include <cstdlib>
#include <complex>
#include <iostream>
#include <cstring>
using namespace std;
void PrintPhysicsParameterXML(string name, double value, double min, double max, string unit)
{
cout << " <PhysicsParameter>" << endl;
cout << " <Name>" << name << "</Name>" << endl;
cout << " <Value>" << value << "</Value>" << endl;
cout << " <Minimum>" << min << "</Minimum>" << endl;
cout << " <Maximum>" << max << "</Maximum>" << endl;
cout << " <Type>Fixed</Type>" << endl;
cout << " <Unit>" << unit << "</Unit>" << endl;
cout << " </PhysicsParameter>" << endl << endl;
}
int main(int argc, char* argv[])
{
if(argc!=6)
{
cout << "Usage: " << argv[0] << " <fwd/bkd> <Magnitude 1> <Phase 1> <Magnitude 2> <Phase 2>" << endl;
cout << "If fwd: amplitude 1 is A+, and amplitude 2 is A−" << endl;
cout << "If bkd: amplitude 1 is A‖, and amplitude 2 is A⊥" << endl;
return 1;
}
if(strcmp(argv[1],"fwd") == 0)
{
complex<double> Aplus = polar(atof(argv[2]),atof(argv[3]));
complex<double> Aminus = polar(atof(argv[4]),atof(argv[5]));
cout << "Input:\tA+ = " << abs(Aplus) << " × Exp(i × " << arg(Aplus) << ")" << "\t A− = " << abs(Aminus) << " × Exp(i × " << arg(Aminus) << ")" << endl;
complex<double> Apara = (Aplus + Aminus) / sqrt(2);
complex<double> Aperp = (Aplus - Aminus) / sqrt(2);
cout << "Output:\tA‖ = " << abs(Apara) << " × Exp(i × " << arg(Apara) << ")" << "\t A⊥ = " << abs(Aperp) << " × Exp(i × " << arg(Aperp) << ")" << endl;
}
else if(strcmp(argv[1],"bkd") == 0)
{
complex<double> Apara = polar(atof(argv[2]),atof(argv[3]));
complex<double> Aperp = polar(atof(argv[4]),atof(argv[5]));
cout << "Input:\tA‖ = " << abs(Apara) << " × Exp(i × " << arg(Apara) << ")" << "\t A⊥ = " << abs(Aperp) << " × Exp(i × " << arg(Aperp) << ")" << endl;
complex<double> Aplus = (Apara + Aperp) / sqrt(2);
complex<double> Aminus = (Apara - Aperp) / sqrt(2);
cout << "Output:\tA+ = " << abs(Aplus) << " × Exp(i × " << arg(Aplus) << ")" << "\t A− = " << abs(Aminus) << " × Exp(i × " << arg(Aminus) << ")" << endl;
cout << endl << "RapidFit XML" << endl << endl;
PrintPhysicsParameterXML("APminus2",pow(abs(Aminus),2),0,1,"Unitless");
PrintPhysicsParameterXML("APplus2" ,pow(abs(Aplus ),2),0,1,"Unitless");
PrintPhysicsParameterXML("deltaPminus",arg(Aminus),-3.1415927,3.1415927,"Unitless");
PrintPhysicsParameterXML("deltaPplus" ,arg(Aplus ),-3.1415927,3.1415927,"Unitless");
}
else
{
cout << "First argument must be 'fwd' or 'bkd'." << endl;
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment