Two types of functional GUI's can be made

This commit is contained in:
Peter DeRosa 2022-07-13 02:44:11 -04:00
parent 4f617e27e3
commit b3c257fff2
10 changed files with 739 additions and 686 deletions

Binary file not shown.

2
.gitignore vendored
View File

@ -1 +1,3 @@
ADEX
ADT
.gitignore

View File

@ -1,4 +0,0 @@
angle,Y,Yerr
45,1.29,.10
90,1.10,.10
135,1.29,.10
1 angle Y Yerr
2 45 1.29 .10
3 90 1.10 .10
4 135 1.29 .10

187
AD.cxx
View File

@ -1,6 +1,6 @@
#include "global.h"
//#include "GUI.h"
#include "GUI_AD.h"
#include "GUI_Base.h"
#include "Functlib.h"
#include "QDK.h"
@ -15,7 +15,6 @@ using namespace std;
int main(int argc,char **argv){
HistoGUI gui;
double j1, j2;
@ -26,7 +25,7 @@ int main(int argc,char **argv){
//input .csv file
double Sigma;
//--------------------------------
//--------------------------------
detradius = 3.;
targetdistance = 4.;
@ -38,9 +37,9 @@ int main(int argc,char **argv){
j1 = 2.;
j2 = 1.;
//--------------------------------
//--------------------------------
//TEST MODE? y : 1 || n = 0
//TEST MODE? y : 1 || n = 0
int test = 1;
@ -59,8 +58,8 @@ int main(int argc,char **argv){
j1j2token = 1;
}
if( test == 0 ) {
}
if( test == 0 ) {
printf("Input detector radius, target distance, and detector thickness : ");
scanf("%lf,%lf,%lf",&detradius,&targetdistance,&detthickness);
@ -97,15 +96,15 @@ if( test == 0 ) {
}
//then calucate QD2 and QD4, and replace the 0 with them.
}
}
double QD2 = QK2(Energy, detradius, targetdistance, detthickness); ;
//.82;//NEED TO READ FROM ad.txt in the future.
double QD4 = QK4(Energy, detradius, targetdistance, detthickness); ;
//.44;
// cout << "QD2 = " << " " << QD2 << " QD4 = " << " " << QD4 << "\n";
// cout << "QD2 = " << " " << QD2 << " QD4 = " << " " << QD4 << "\n";
//input data file of Angular Data (theta, Yexp, Yerr)
//input data file of Angular Data (theta, Yexp, Yerr)
vector<vector<string> > content;
vector<string> row;
@ -177,12 +176,12 @@ if( test == 0 ) {
}
for(int i = 0; i< adata.size();i++){
// cout << adata[i] << "\n";
// cout << ydata[i] << "\n";
// cout << eydata[i] << "\n";
// cout << adata[i] << "\n";
// cout << ydata[i] << "\n";
// cout << eydata[i] << "\n";
}
// Legendre Polinomial fit using adata, ydata, eydata;
// Legendre Polinomial fit using adata, ydata, eydata;
adata.erase(adata.begin());
ydata.erase(ydata.begin());
@ -200,6 +199,8 @@ if( test == 0 ) {
dangler.push_back(aa*3.14159/180.);
printf("dangle = %lf\n",dangler[i]);
}
// if you need to scale the y data by sin(theta)
/*
for(int i=0; i<content.size(); i++){
@ -210,7 +211,7 @@ if( test == 0 ) {
}
*/
//legendre fitting
// F[xi] = A0 + A2(P2(xi)) + A4(P4(xi))
// F[xi] = A0(1) + A2(P2(cos(xi))) + A4(P4(cos(xi)))
//xi data is angle data in radians.
//yi data is y-intensity data.
@ -222,21 +223,23 @@ if( test == 0 ) {
//[a5 a6 a7] [A2] = [a8]
//[a9 a10 a11] [A4] = [a12]
double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12 = 0.;
// Note, the y data must be scaled by sin(theta) of the given angle.
double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12 = 0.;
/*
for(int i = 0; i< dangler.size(); i++){
//eq1
//eq1
a1 += 1; //how many data points, not intensional but convientient.
a2 += (1.5 * pow(dangler[i],2) - .5);
a3 += (35./8. * pow(dangler[i],4) - 30./8. * pow(dangler[i],2) + 3./8. );
a4 += dydata[i];
//eq2
//eq2
a5 += (1.5 * pow(dangler[i],2) - .5);
a6 += (1.5 * pow(dangler[i],2) - .5)*(1.5 * pow(dangler[i],2) - .5);
a7 += (1.5 * pow(dangler[i],2) - .5)*(35./8. * pow(dangler[i],4) - 30./8. * pow(dangler[i],2) + 3./8. );
a8 += (1.5 * pow(dangler[i],2) - .5)*dydata[i];
//eq4
//eq4
a9 += (35./8. * pow(dangler[i],4) - 30./8. * pow(dangler[i],2) + 3./8. );
a10 += (1.5 * pow(dangler[i],2) - .5)*(35./8. * pow(dangler[i],4) - 30./8. * pow(dangler[i],2) + 3./8. );
a11 +=(35./8. * pow(dangler[i],4) - 30./8. * pow(dangler[i],2) + 3./8. )* (35./8. * pow(dangler[i],4) - 30./8. * pow(dangler[i],2) + 3./8. );
@ -244,7 +247,30 @@ if( test == 0 ) {
}
/*
*/
for(int i = 0; i< dangler.size(); i++){
//eq1
a1 += 1; //how many data points, not intensional but convientient.
a2 += (1.5 * pow(cos(dangler[i]),2) - .5);
a3 += (35./8. * pow(cos(dangler[i]),4) - 30./8. * pow(cos(dangler[i]),2) + 3./8. );
a4 += dydata[i];
//eq2
a5 += (1.5 * pow(cos(dangler[i]),2) - .5);
a6 += (1.5 * pow(cos(dangler[i]),2) - .5)*(1.5 * pow(cos(dangler[i]),2) - .5);
a7 += (1.5 * pow(cos(dangler[i]),2) - .5)*(35./8. * pow(cos(dangler[i]),4) - 30./8. * pow(cos(dangler[i]),2) + 3./8. );
a8 += (1.5 * pow(cos(dangler[i]),2) - .5)*dydata[i];
//eq4
a9 += (35./8. * pow(cos(dangler[i]),4) - 30./8. * pow(cos(dangler[i]),2) + 3./8. );
a10 += (1.5 * pow(cos(dangler[i]),2) - .5)*(35./8. * pow(cos(dangler[i]),4) - 30./8. * pow(cos(dangler[i]),2) + 3./8. );
a11 +=(35./8. * pow(cos(dangler[i]),4) - 30./8. * pow(cos(dangler[i]),2) + 3./8. )* (35./8. * pow(cos(dangler[i]),4) - 30./8. * pow(cos(dangler[i]),2) + 3./8. );
a12 += (35./8. * pow(cos(dangler[i]),4) - 30./8. * pow(cos(dangler[i]),2) + 3./8. )*dydata[i];
}
/*
printf("a1 = %lf\n",a1);
printf("a2 = %lf\n",a2);
printf("a3 = %lf\n",a3);
@ -257,11 +283,11 @@ if( test == 0 ) {
printf("a10 = %lf\n",a10);
printf("a11 = %lf\n",a11);
printf("a12 = %lf\n",a12);
*/
//here number of equations are 3 because its a 3 coeff. fit.
*/
//here number of equations are 3 because its a 3 coeff. fit.
int n = 3;
double mat[3][4] = {{a1,a2,a3,a4},{a5,a6,a7,a8},{a9,a10,a11,a12}};
//where A0,A2,A4 are stored
//where A0,A2,A4 are stored
double residual[n];
for(int i = 0; i<n;i++){
@ -278,7 +304,7 @@ if( test == 0 ) {
}
}
}
//performing gaussian elimination.
//performing gaussian elimination.
for(int i = 0; i< n-1; i++) {
@ -293,7 +319,7 @@ if( test == 0 ) {
}
}
//backwards substitution for unknowns.
//backwards substitution for unknowns.
for( int i = n-1; i >= 0; i--){
@ -316,7 +342,7 @@ if( test == 0 ) {
if(test == 0){
if(test == 0){
printf("Please enter sigma, sigma = 0 for perfect allignment : ");
scanf("%lf", &Sigma);
@ -347,10 +373,10 @@ if(test == 0){
j1j2token = 1; printf(" --- J1 & J2 Loaded --- \n");
}
}
}
// Calculate BK(j1) for perfect allignment
//
// Calculate BK(j1) for perfect allignment
//
double A[6];
double js = sqrt(2*j1 +1);
@ -422,8 +448,8 @@ if(test == 0){
printf("cg2 = %lf\n",cg2);
}
}
//normalize W(m1)
//
//normalize W(m1)
//
j12 = 2*j1;
double j14 = 4*j1;
@ -432,7 +458,7 @@ if(test == 0){
double sum1 = 0.;
double am1,amsq,x,ex = 0.;
//-------------------------------------------------------SOMETHING WRONG WITH CN1.
//-------------------------------------------------------SOMETHING WRONG WITH CN1.
for(int i = 0; i <= j14; i = i + 2){
am1 = 0.5*(i - j12);
amsq = pow(am1,2);
@ -443,7 +469,7 @@ if(test == 0){
}
double cn1 = 1./sum1;
// cout << "cn1" << " " << cn1 << "\n";
// cout << "cn1" << " " << cn1 << "\n";
double AL0 = 0.;
double A0 = j1 - j2;
@ -455,9 +481,9 @@ if(test == 0){
double AL1 = AL0 +1;
double am11,amsq1,x1,ex1 = 0.;
//calculate Bk(j1) for gaussian W(m1) or non zero Sigma
//calculate Bk(j1) for gaussian W(m1) or non zero Sigma
//NEEDS VALUE FIX
//NEEDS VALUE FIX
if(Sigma != 0){
double A[6];
A[0] = j1;
@ -566,10 +592,10 @@ if(test == 0){
}
}
// cout << j1<< " " << j2 << " "<< nn << "\n";
// cout << j1<< " " << j2 << " "<< nn << "\n";
// rk01,rk11,rk21, rk02, rk12,rk22 //READ OUT OF Rk TABLE
// rk01,rk11,rk21, rk02, rk12,rk22 //READ OUT OF Rk TABLE
double rk01 = rk20datad[nn];
double rk11 = rk21datad[nn];
@ -579,8 +605,8 @@ if(test == 0){
double rk22 = rk42datad[nn];
// printf("Bk1 = %lf\n",Bk11);
// printf("Bk2 = %lf\n",Bk12);
// printf("Bk1 = %lf\n",Bk11);
// printf("Bk2 = %lf\n",Bk12);
printf("rk01 = %lf\n",rk01);
printf("rk11 = %lf\n",rk11);
@ -598,7 +624,7 @@ if(test == 0){
double step = 0.001;
double delta = 0.;
double tan_delta =0.;
double atan_delta =0.;
double A0E = residual[0];//NEED FrOM AF FIT
double A2E = residual[1];
double A4E = residual[2];
@ -619,8 +645,8 @@ if(test == 0){
vector<double> tdelta;
for(int i = 0; i< points; i++){
tan_delta = i*step + delta_min;
delta = tan(tan_delta);
atan_delta = i*step + delta_min;
delta = tan(atan_delta);
rd2T = (rk01 + 2*delta*rk11 + pow(delta,2)*rk21)/(1+pow(delta,2));
A2T = QD2*Bk11*rd2T;
a2T = A2T/A0E;
@ -635,38 +661,48 @@ if(test == 0){
X2_total = (X22 + X24)/2;
chisqr.push_back(-log(X2_total));
tdelta.push_back(tan_delta);
tdelta.push_back(atan_delta);
}
//NEEDS FIX
//If gui does this how does the vector pushback here make sense.
vector<double> Theta;
vector<double> AD_I;
double ad_start = -3.1415/2;
double ad_start = 0.;
int adpoints = (3.1415)/(step);
double theta,Iad = 0.;
double aaa,aab,aac = 0.;
for(int i = 0; i < adpoints; i++){
theta = i*step + ad_start;
aaa = A0E;
aab = A2E*(1.5 * pow(theta,2) - .5);
aac = A4E*(35./8. * pow(theta,4) - 30./8. * pow(theta,2) + 3./8. );
aaa = 1.;
aab = (A2E/A0E)*(1.5 * pow(cos(theta),2) - .5);
aac = (A4E/A0E)*(35./8. * pow(cos(theta),4) - 30./8. * pow(cos(theta),2) + 3./8. );
Iad = aaa + aab + aac;
AD_I.push_back(Iad);
Theta.push_back(theta);
//these arrays arent used, but they are the function (if one just wanted to the legendre fit function that goes over the data.
}
vector<double> dydatas;
for(int i = 0; i < dydata.size(); i++){
double bbb = dydata[i];
dydatas.push_back(bbb/A0E);
printf("Normalized y-intensity %i = %lf\n",i+1,dydatas[i]);
}
//This is to temporarily fix the issue with the AD distribution, it takes off the last point in the arrays when plotting or doesnt see them. NEED FIX
dydatas.push_back(A0E);
dangler.push_back(3.1415/2.);
int param;
param = param_run(det_param_token, gamma_energy_token, ang_file_token, sigma_token, j1j2token);
/*
/*
cout << det_param_token << "\n";
cout << gamma_energy_token << "\n";
cout << ang_file_token << "\n";
@ -674,7 +710,16 @@ if(test == 0){
cout << j1j2token << "\n";
cout << param << "\n";
*/
*/
//Initialize Graphics Here.
HistoGUI gui;
HistoGUIad gui_ad;
int optnum = -1;
menu();
@ -704,34 +749,40 @@ if(test == 0){
//y will be log(X^2);
gui.SetData(tdelta,chisqr);
//gui.SetData(Theta,AD_I);
gui.Init();
gui.Loop();
gui.Close();
// printf("Input option : ");
// scanf("%d", &optnum);
// if(optnum < 0){
// printf("Input option : ");
// scanf("%d", &optnum);
// }
// printf("Input option : ");
// scanf("%d", &optnum);
// if(optnum < 0){
// printf("Input option : ");
// scanf("%d", &optnum);
// }
}
//Plot Angular distribution fit, with points and error bars.
//Plot Angular distribution fit, with points and error bars.
if(param == 1 and optnum == 2){
/*
gui.SetData(dangler,dydata);
gui.SetErrors(deydata);
gui.SetFit(residual[0],residual[1],residual[2]);
/*
gui.SetData(Theta,AD_I);
gui.Init();
gui.Loop();
gui.Close();
*/
*/
gui_ad.SetData(dangler,dydatas);
gui_ad.SetErrors(deydata);
gui_ad.SetFit(residual[0],residual[1],residual[2]);
gui_ad.Init();
gui_ad.Loop();
gui_ad.Close();
}
//exit
//exit
if(param == 1 and optnum == 3){
return 0;

View File

@ -55,6 +55,7 @@ class HistoGUIad{
double A0;
double A2E;
double A4E;
double Ierr;
int SetFit(double a, double b, double c){
A0 = a;
A2E = b;
@ -385,7 +386,7 @@ int HistoGUIad::DrawData(double x_low_win, double y_low_win, double x_hi_win, do
for(int i=0; i < x.size() - 1; i++){
x_wid = (x[i] + x_offset) / width_scale;
y_wid = (y[i] + y_offset) / height_scale;
y_errors_wid = (y_errors[i] / height_scale);
y_errors_wid = ((y_errors[i]/A0) / height_scale);
// x_wid2 = (x[i + 1] + x_offset) / width_scale;
// y_wid2 = (y[i + 1] + y_offset) / height_scale;
//printf("(%f, %f), (%f,%f)\n", x_wid,y_wid,x_wid2,y_wid2);
@ -424,14 +425,14 @@ int HistoGUIad::DrawData(double x_low_win, double y_low_win, double x_hi_win, do
for(int i=0; i < (int) width; i += w_step){
double x_val = i * width_scale - x_offset;
sprintf(axis_val, "%.1f", x_val);
XDrawString(disp, wind, DefaultGC(disp, screen), i, axis_y + 10, axis_val, strlen(axis_val));
XDrawString(disp, wind, DefaultGC(disp, screen), i, axis_y + 10/A0, axis_val, strlen(axis_val));
}
int h_step = height / 10;
for(int i=0; i < (int) height; i += h_step){
double y_val = i * height_scale - y_offset;
sprintf(axis_val, "%.1f", y_val);
XDrawString(disp, wind, DefaultGC(disp, screen), axis_x + 10, i, axis_val, strlen(axis_val));
XDrawString(disp, wind, DefaultGC(disp, screen), axis_x + 10/A0, i, axis_val, strlen(axis_val));
}
@ -447,7 +448,7 @@ int HistoGUIad::DrawData(double x_low_win, double y_low_win, double x_hi_win, do
x_wid = (x[i] + x_offset) / width_scale;
y_wid = (y[i] + y_offset) / height_scale;
y_errors_wid = (y_errors[i] / height_scale);
y_errors_wid = ((y_errors[i]/A0) / height_scale);
// x_wid2 = (x[i + 1] + x_offset) / width_scale;
// y_wid2 = (y[i + 1] + y_offset) / height_scale;

Binary file not shown.

Binary file not shown.

View File

@ -210,9 +210,9 @@ double HistoGUI::legval(double theta){
double lg;
double aaa = A0;
double aab = A2E*(1.5 * pow(theta,2) - .5);
double aac = A4E*(35./8. * pow(theta,4) - 30./8. * pow(theta,2) + 3./8. );
double aaa = A0/A0;
double aab = (A2E/A0)*(1.5 * pow(cos(theta),2) - .5);
double aac = (A4E/A0)*(35./8. * pow(cos(theta),4) - 30./8. * pow(cos(theta),2) + 3./8. );
lg = aaa + aab + aac;

View File

@ -5,10 +5,13 @@ int main ( int argc, char** argv){
HistoGUI gui;
double A0E = 134.327;
double A2E = -11.7874;
double A4E = 0.760896;
double A0E = 111.514;
double A2E = -54.3312;
double A4E = -76.4778;
//double A0E = 134.327;
//double A2E = -11.7874;
//double A4E = 0.760896;
double step = 0.0001;
vector<double> Theta;
@ -27,7 +30,7 @@ int main ( int argc, char** argv){
Iad = aaa + aab + aac;
cout << theta << "\n";
// cout << theta << "\n";
AD_I.push_back(Iad);
Theta.push_back(theta);
@ -43,16 +46,16 @@ int main ( int argc, char** argv){
dangle.push_back(1.5619);
vector<double> dydata;
//= {129.,110.,129.};
dydata.push_back(129.);
dydata.push_back(110.);
dydata.push_back(129.);
dydata.push_back(115.);
dydata.push_back(129./A0E);
dydata.push_back(110./A0E);
dydata.push_back(129./A0E);
dydata.push_back(115./A0E);
vector<double> deydata;
//= {10.,10.,10.};
deydata.push_back(10.);
deydata.push_back(10.);
deydata.push_back(10.);
deydata.push_back(10.);
deydata.push_back(5.);
deydata.push_back(5.);
deydata.push_back(5.);
deydata.push_back(5.);

View File

@ -5,7 +5,7 @@
using namespace std;
//this program doesnt work and it is not used, I spent so much time transcribing it that maybe, one day some poor soul will come and try to fix it to match rose and brinks.
double RACAH(double A[6]){