00001 #ifndef __INCLUDE_SFIT_H__
00002 #define __INCLUDE_SFIT_H__
00003
00004 #include <cmath>
00005 #include <cstdio>
00006 #include <cstring>
00007 #include <cstdlib>
00008 #include <string>
00009
00010 #include "coral.h"
00011
00012
00013 #include "minimization.h"
00014 using namespace std;
00015
00016 class CParInfo{
00017 public :
00018 bool fixed;
00019
00020 double xmin,xmax,error,xbar;
00021 double bestx,currentx;
00022 char *name;
00023 void Set(string sname, double xset, double error,
00024 double xminset, double xmaxset);
00025 CParInfo();
00026 ~CParInfo();
00027 };
00028
00029
00030 class CCF2SFit : public CMinimization{
00031 public :
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 void SetCalcFlag( int calcflagset);
00042 void SetMCSourceFlag( bool MCsourceflagset);
00043
00044 void SetPar(string parstring, double value);
00045 void SetPar(string parstring, double value, double error,double xmin, double xmax);
00046 double GetPar(string parstring);
00047 void AddPar(string parstring, double value, double error,double xmin, double xmax);
00048 void PrintPars();
00049 void PrintErrorMatrix();
00050 void PrintStepMatrix();
00051 void FixPar(string parname);
00052 void FreePar(string parname);
00053 void UseBestPars();
00054 void SetL( int lxset, int lyset, int lzset);
00055
00056
00057 void ConjugateGradient( int maxcalls);
00058 double fn( double * x);
00059 bool dfn( double * x);
00060
00061 void Metropolis( int maxcalls);
00062 void SteepestDescent( int maxtries);
00063 void Newton( int maxtries);
00064 void UpdateStepMatrix();
00065 void InitErrorMatrix();
00066
00067
00068 CSourceCalc *sourcecalc;
00069
00070
00071
00072 CCHArray *sourceCH;
00073 C3DArray *source3D;
00074 CMCList *lista;
00075 CMCList *listb;
00076
00077
00078 CKernel *kernel;
00079 CKernelWF *kernelwf;
00080 CWaveFunction *wf;
00081
00082
00083 C3DArray *cexp3D;
00084 C3DArray *cerror3D;
00085 C3DArray *ctheory3D;
00086 CCHArray *cexpCH;
00087 CCHArray *cerrorCH;
00088 CCHArray *ctheoryCH;
00089
00090
00091
00092 void ResetChiSquared();
00093 CCF2SFit();
00094 CCF2SFit(CCHArray *sourceCHset,C3DArray *source3Dset,
00095 CMCList *listaset,CMCList *listbset,
00096 CKernel *kernelset,CKernelWF *kernelwfset,
00097 CWaveFunction *wfset,
00098 C3DArray *cexp3Dset,C3DArray *cerror3Dset,
00099 C3DArray *ctheory3Dset,CCHArray *cexpCHset,
00100 CCHArray *cerrorCHset,CCHArray *ctheoryCHset);
00101 ~CCF2SFit();
00102
00103 protected :
00104 int calcflag;
00105 static bool MCsourceflag;
00106
00107
00108 CParInfo **par;
00109 static int nmaxpars;
00110 int nfreepars,npars;
00111 double **ErrorMatrix;
00112 double currentchisquared,bestchisquared;
00113
00114 int lx,ly,lz;
00115
00116
00117 CRandom *randy;
00118 void SwitchPars( int ipara, int iparb);
00119 void SwitchValues( double *a, double *b);
00120
00121 int ncalls;
00122 double **StepMatrix;
00123 void Init();
00124 double GetChiSquared( double *x);
00125 void CalcErrorMatrixFromCurvature( double **C);
00126 };
00127
00128 class CCF2SFit_Blast : public CCF2SFit{
00129 public :
00130 CCF2SFit_Blast(CSourceCalc *scset,C3DArray *cexpset,
00131 C3DArray *cerrorset,C3DArray *ctheory3Dset,
00132 CCHArray *ctheoryset,CCHArray *sourceset,
00133 CKernel *kernelset);
00134 };
00135
00136 class CCF2SFit_GX1D : public CCF2SFit{
00137 public :
00138 CCF2SFit_GX1D(CSourceCalc *scset,CCHArray *cexpset,
00139 CCHArray *cerrorset,CCHArray *ctheoryset,
00140 CCHArray *sourceset,CKernel *kernelset);
00141 };
00142
00143 class CCF2SFit_3DGaussian : public CCF2SFit{
00144 public :
00145 CCF2SFit_3DGaussian(CSourceCalc *scset,C3DArray *cexpset,
00146 C3DArray *cerrorset,C3DArray *ctheory3Dset,
00147 CCHArray *ctheoryset,CCHArray *sourceset,
00148 CKernel *kernelset);
00149 };
00150
00151 #endif