My Project
 All Classes Functions Variables Pages
fitmodel.h
1 #ifndef FITMODEL_H
2 #define FITMODEL_H
3 #define MAX_PC 200
4 
5 #include "musr.h"
6 #include "fitthread.h"
7 #include "plot2D.h"
8 #include "Moesscalc.h"
9 #include "array.h"
10 #include "fparser.hh"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <QDir>
14 #include <QFileInfo>
15 #include <QMessageBox>
16 #include <QStringList>
17 #include <QString>
18 #include <QtConcurrentRun>
19 #include <QFutureSynchronizer>
20 #include <QFutureWatcher>
21 #include <QTimer>
22 #include <QMutex>
23 #include <QProgressBar>
24 #include <QLocale>
25 #include "fmpanel.h"
26 
27 /*Fitmodel definieren*/
28 enum ObjTyp{funtyp,partyp,maptyp,numtyp,runspecificparameter};
29 enum ParameterTyp{pObj,pDISTR, pDISTREXT,pMEM,pHR};
30 enum MSTyp{SHcrystal,afmBexpowder,fmBexpowder,PseudoVoigt,MLR,SHpowder,mSSH,BL, FeCal, FeCaltriang,AnyFit,FeAspowder,DynDiagDiagDiag,DynDiagDiag,Dyn};
31 enum AdditionalFunTypes{TAbsDeb,TQuadDop,SwaveSFD,Hc2WHH,GLBrandttriang,GLBrandtquad,Errorfunction,OrderParameterDistrTN};
33 
40 class Obj{
41  public:
43  Obj(QString name,ObjTyp typ, int i);
44  Obj(QString name,double i);
45  Obj(QString name);
46  ~Obj();
47  bool operator==(QString name);
48  bool operator==(Obj o);
49  bool operator<(const Obj o2)const;
50  double dnumber;
51  QString name;
52  ObjTyp typ;
53  int ref;
54 };
55 typedef struct Parameter{
56  ParameterTyp typ;
57  QStringList argv;
58  int arg[6];
59 }Parameter;
60 
62 
68 class RUN{
69  public:
70  RUN();
71  ~RUN();
72  void init(int Speccount, int MEMsamplecount);
73  double T;
74  int cc;
75  int ccr;
76  double *v;
77  double *I;
78  double *err2rec;
79 
84  double **Ith;
85  double *nI;
86  double *nIth;
87 
91  QStringList maplist;
92  int* map;
93  double I0;
94  double A;
95  double chi2;
96  double *rho;
97  double *rhoerror;
98  double MEMstatus[5];
99  private:
100  int cmbs;
101  int cMEM;
102 };
103 
105 typedef struct MoessbauerSpectrum{
106  MSTyp typ;
107  Parameter p[MAX_PC];
109 
111 typedef struct fmPara{
112  double value;
113  double step;
114  QString name;
115  bool runspecific;
117 }fmPara;
118 
120 typedef struct AdditionalFun{
121  AdditionalFunTypes typ;
122  int cpara;
123  int arg[6];
125 
127 typedef struct FunctionStruct{
128  QString name;
129  QString body;
131  QList<int> arg;
132  QList<AdditionalFun> addfunlist;
134 
136 typedef struct SortContainer{
137  double x,y,err2;
139 
141 
159 class fitmodel:public QWidget{
160  Q_OBJECT
161 public:
162  fitmodel(QString filename);
163  fitmodel();
164  ~fitmodel();
165  void plot(plot2D *plotter, plot2D *MEM);
167 
175  void fit();
176  void fit_hidden_wait();
177  void errors();
178  double get_total_chi2();
179  double get_run_chi2(int runi);
180  double calc_changed_runs();
181 
187  int get_affect(int i);
188  int calc_run(int i);
189  int is_valid();
190  void close_fmpa();
191  void generate_default(QStringList flds);
193  short from_fld(char* filename,double** xdata, double** ydata,
194  int* count);
195  fmPanel* get_pannel();
198  int cpara;
202  int crun;
205 private slots:
207  void update_fit_progressbar(int ID, int citer, double chi2);
208  void finish_fitting(int ID);
209  void error_message(int runi, QString message);
211 public slots:
213  void panel_input(int irun, int ipara);
214  void view_run(int i);
215  void view_run_only(int i);
216  void hide_run(int i);
217  void reset_error(int runi, int parai, bool fit);
219  void add_noise();
220 private:
222 
230  int link();
231  void interprete_commands(int* linkOK);
232  void parse_functions(int* linkOK);
233  int find_obj(QString name);
235  int set_obj(int i, int irun, double v);
236  int set_error(int i, int irun, double v);
237  fmPanel* fmpa;
238  QString InputFile;
239  QString ErrorMessage;
240  QList<Obj> obj;
241  int read_fitparameters(FILE*f);
242  int read_functions(FILE*f);
243  int read_theory(FILE*f);
244  int read_run(char* mbspath, FILE*f);
245  int read_plot(FILE*f);
246  int read_commands(FILE*f);
247  int read_fitdata();
248  int read_MEMdata();
249  int process_theory();
251  bool blockend(char* line);
252  bool validline(char* line);
253  void print_fitdata();
254  short from_fld(char* filename,double** xdata, double** ydata,
256  double**yerror, int* count);
258 
268  void build_iterator(double* p, int ip, int spectrumi,
269  int irun, int ims,
270  MoessCalc *mc, bool sumweightonly,
271  double weight, double* integratedweight,
272  double **MEMIm, int MEMIndex, int maxMEMIndex);
274  void build_spectrum(double* p, int ip, int spectrumi,
275  int irun, int ims,
276  MoessCalc *mc,
277  double weight, double* integratedweight,
278  double **MEMIm, int MEMIndex, int maxMEMIndex);
280  void WeightSum(double* p, int ip, int spectrumi, int irun, int ims,
281  double weight, double* integratedweight);
282  void init();
283  short load_run(char* mbspath, char* T,int index);
286  int load_run(char* fldpath, double UseT, int index);
288 
293  double KSconfidence(int irun);
295  void anyfit(int irun, int ims);
297  void merge(SortContainer*,SortContainer*,int,int,int);
299  void mergesort(SortContainer *a, SortContainer*b, int low, int high);
300  double eval_error(int iobj, int irun);
301  double eval(int iobj, int irun);
302  double fv(int ir, int ifun);
305  void get_MEMcode(int istep, char* code);
307  double get_MEMcode(int istep, int ipara);
308 
309  int pc(MSTyp m);
310  int pc(int spectrumi);
311  int ac(ParameterTyp m);
312  void restrict_fitrange(double* mins, double* maxs, int crange, int irun);
314 
315 
316  int isvalid;
317  int cfun;
318  FunctionStruct* fun;
321  int cmbs;
323  int cMEMsubspec;
325  int i1stMEMspec;
327  int cMEMpara;
329 
336  MoessbauerSpectrum* spectra;
337  int AnyFit_in;
338 
345  ParameterTyp Distrtyp;
346 
348 
359  double *pData;
361  double *pError;
362 
364 
369  int *pIsChanged;
371 
374  double ***rData;
376 
379  double ***rError;
380  int cSpec;
381  int cGlobal;
382  int cConst;
383 
387  int *affect;
389  int ***raffect;
390  int fitruns;
391 
396  ErrMod errormode;
397 
398 
400  int autorange;
401 
404  QString sautoI0, sautoA, sMEMsteps, sMaxIter, sconv, sMEMmaxlambda, sMEMmaxlambdaI0,
405  sMEMtollerance, sMEMstepsize,sta,somegasrc,somegaabs,sfr,sHR,sHRc,sMCi;
409  int autoI0, autoA, MEMsteps, MaxIter, conv, MEMmaxlambda, MEMmaxlambdaI0,
410  MEMtollerance, MEMstepsize,ta,omegasrc,omegaabs,fr,HR,HRc,MCi;
413  bool forcesimplex;
415  QList<double> plotrunlist;
416  double plotxmin;
417  double plotxmax;
418  double plotymin;
419  double plotymax;
420 
422 
428  bool ProgressPrint;
430  QMutex fmutex;
432  QProgressDialog pbinstance;
434 
437  int* pgvs;
439 
442  double* pgchi2;
444  int runiterations;
445 
446  int is_seriell_fit();
447  fitthread** ft;
450 
455  void fgetss(char* buffer,int max,FILE* f);
456 
457 
458 signals:
460 
465  void ready_to_plot();
467  void all_fitting_finished();
468 };
469 
470 #endif // FITMODEL_H
void hide_run(int i)
set initial value from parameter declaration if fit, else set -1
Definition: fitmodel.cpp:2779
information of the subspectra defined in the THEORY block of a mbs file
Definition: fitmodel.h:105
ObjTyp typ
specifies how to evaluate this Obj
Definition: fitmodel.h:52
double dnumber
float value if it is const. number
Definition: fitmodel.h:50
double step
stepsize, 0 corresponds to &quot;const&quot;
Definition: fitmodel.h:113
void fit()
creates fitthread instances to fit the whole data set
Definition: fitmodel - Kopie.cpp:1544
double calc_changed_runs()
Definition: fitmodel - Kopie.cpp:1649
int arg[6]
argument refer. to fitmodel::obj
Definition: fitmodel.h:123
thread class to perform fitting and error calculation tasks
Definition: fitthread.h:95
void ready_to_plot()
indicates that data is processed and can be viewed
void close_fmpa()
Definition: fitmodel - Kopie.cpp:2167
void add_noise()
statistical noise to current model
Definition: fitmodel.cpp:2840
contains all information related to the run
Definition: fitmodel.h:68
calculation of moessbauer spectra
Definition: Moesscalc.h:65
specific functions which are available for FUNCTIONS defintions
Definition: fitmodel.h:120
int get_affect(int i)
returns, which run is affected by the i-th parameter
Definition: fitmodel - Kopie.cpp:1679
int ref
index to fitmodel::rData it belongs to
Definition: fitmodel.h:53
fmPara * fmp
fitparameters used in model, count saved in fitmodel::cpara
Definition: fitmodel.h:200
void view_run_only(int i)
show only run i on the plot
Definition: fitmodel.cpp:2774
fmPanel * get_pannel()
return pointer to fitmodel::fmpa, used by mainwindow to set up widget
Definition: fitmodel.cpp:2837
RUN * run
runs used in model, count saved in fitmodel::crun
Definition: fitmodel.h:204
int printDigits
number of digits at FITDATA output
Definition: fitmodel.h:116
QList< int > arg
argument refer. to fitmodel::obj
Definition: fitmodel.h:131
Obj(QString name, ObjTyp typ, int i)
create am onject of specific type, with reference i fitmodel::rData
Definition: fitmodel - Kopie.cpp:2270
QString body
function body string
Definition: fitmodel.h:129
FunctionParser f
parser working upon body
Definition: fitmodel.h:130
double A
preestimated/updated spectral area
Definition: fitmodel.h:94
enable sorting of data in RUN
Definition: fitmodel.h:136
double * err2rec
Definition: fitmodel.h:78
double get_run_chi2(int runi)
chi2 value of the runi-th run
Definition: fitmodel - Kopie.cpp:1670
double get_total_chi2()
sum of chi2 values of all runs
Definition: fitmodel - Kopie.cpp:1664
double * rho
MEM-distribution.
Definition: fitmodel.h:96
Definition: plot2D.h:18
double MEMstatus[5]
latest statistics of MEM calcul.
Definition: fitmodel.h:98
functions as defined on FUNCTIONS block of a mbs file
Definition: fitmodel.h:127
double * v
x-data (i.e. velocity for Moessb.)
Definition: fitmodel.h:76
QString name
declaration name
Definition: fitmodel.h:51
int cpara
count of fit parameters of model, size of fitmodel::fmp array
Definition: fitmodel.h:198
double T
run specif. param. (usual. temp.)
Definition: fitmodel.h:73
void view_run(int i)
add run i to the plot
Definition: fitmodel.cpp:2768
QString name
user defined parameter name
Definition: fitmodel.h:114
Definition: fitmodel.h:55
void generate_default(QStringList flds)
generates default mbs-file working upon the flds files
Definition: fitmodel.cpp:2793
int cpara
argument count
Definition: fitmodel.h:122
QList< AdditionalFun > addfunlist
list of used preimplemented funct.
Definition: fitmodel.h:132
double chi2
current fit quality measure
Definition: fitmodel.h:95
QStringList maplist
map parameter names
Definition: fitmodel.h:91
MSTyp typ
model to describe the spectrum
Definition: fitmodel.h:106
void panel_input(int irun, int ipara)
&lt; parameter ipara of run irun was modified, recalc model
Definition: fitmodel - Kopie.cpp:2155
double * nI
normalized data
Definition: fitmodel.h:85
void all_fitting_finished()
uses in fit_hidden_wait() to stop QEventLoop and proceed in code
void fit_hidden_wait()
like fit, but without progressbar
Definition: fitmodel.cpp:2041
double I0
preestimate data base line
Definition: fitmodel.h:93
Graphical User Interface generated upon fitmodel.
Definition: fmpanel.h:20
double * rhoerror
MEM-dostribution errors.
Definition: fitmodel.h:97
int calc_run(int i)
recalculates the i-th run
Definition: fitmodel - Kopie.cpp:1038
void errors()
like fit, but error calculation
Definition: fitmodel - Kopie.cpp:1594
fitmodel parameters, as defines in the FITPARAMETER block of a mbs file
Definition: fitmodel.h:111
bool runspecific
name does not start with &quot;global_&quot;
Definition: fitmodel.h:115
double * nIth
Definition: fitmodel.h:86
symbol class to organize complex us er imput
Definition: fitmodel.h:40
Parameter p[MAX_PC]
parameters of the specific model
Definition: fitmodel.h:107
double * I
y-data (i.e. intensity for Moessb.)
Definition: fitmodel.h:77
int cc
channel count (= data point count)
Definition: fitmodel.h:74
bool operator==(QString name)
to compare Obj with each other
Definition: fitmodel - Kopie.cpp:2299
int is_valid()
returns fitmodel::isvalid
Definition: fitmodel - Kopie.cpp:992
int * map
map indeces in fitmodel::obj
Definition: fitmodel.h:92
short from_fld(char *filename, double **xdata, double **ydata, int *count)
Definition: fitmodel - Kopie.cpp:156
int crun
count of runs in the model, size of fitmodel::run array
Definition: fitmodel.h:202
double value
initial value
Definition: fitmodel.h:112
parser and handler of user input mbs-files
Definition: fitmodel.h:159
Definition: fparser.hh:185
double ** Ith
simulated spectra including RUN::cmbs subspectra
Definition: fitmodel.h:84
int ccr
channel count, restricted by user
Definition: fitmodel.h:75