00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "compilopt.h"
00031
00032 #define LONGSTRINGLENGTH 256
00033 #define FILENMLENGTH LONGSTRINGLENGTH
00034
00035
00036 #define DEG2RAD (M_PI/180.0)
00037
00038 #define MEVAMU 931.52181
00039 #define UATMASS (1./1822.887)
00040
00041
00042 #define BARNTOM2 1.0e-28
00043
00044
00045 typedef char STATFILENAME[FILENMLENGTH] ;
00046
00047 typedef char ChemSymb[3];
00048
00049 typedef int atomicnumber;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 typedef double SecXL[4];
00062
00063 typedef enum { K, L, M } FwTipo;
00064
00065
00066
00067
00068 typedef struct ELEMENT
00069 {
00070 char symbol[3];
00071 int Z;
00072 int A;
00073 double M;
00074 double IM;
00075 }ELEMENT;
00076
00077
00078 typedef struct COMPOUND
00079 {
00080 char name[30];
00081 double sumX;
00082 int nelem;
00083 ELEMENT *elem;
00084 double *X;
00085 double *xn;
00086 double *w;
00087 }COMPOUND;
00088
00089
00090
00091 typedef struct SPT
00092 {
00093 char ID[30];
00094 int nrows;
00095 int logmode;
00096 double Emax;
00097 double Estep;
00098 double Smax;
00099 double *E;
00100 double *S;
00101 double *dSdE;
00102 }SPT;
00103
00104
00105
00106 typedef struct absorber
00107 {
00108 int number;
00109 char name[6];
00110 int nreg;
00111 double ereg[11];
00112 double coef[11][3];
00113 double h[3];
00114 } absorber;
00115
00116
00117
00118 typedef struct SIM_PARAM
00119 {
00120 int MaxZinsample;
00121 int AllowSXFCorr;
00122 int AllowXEqCalc;
00123 double DTCC;
00124
00125 double ColCharge;
00126 double CalEner;
00127 int useFilter;
00128 }SIM_PARAM;
00129
00130
00131
00132
00133 typedef struct EXP_PARAM
00134 {
00135 ELEMENT ion;
00136 double BeamEner;
00137 double BeamCol;
00138 double DetColFac;
00139 double IncAng;
00140 double DetAng;
00141 double cosDet;
00142 double cosInc;
00143 double cosFac;
00144 double BeamCross;
00145 double FinalEner;
00146 SIM_PARAM simpar;
00147 }EXP_PARAM;
00148
00149
00150 typedef struct EXTRAINFO
00151 {
00152 char *SampleFileNm;
00153 char *FilterFileNm;
00154 char *XYldFileNm;
00155 char *AreasFileNm;
00156 char *DBpath;
00157 char *OutputFileNm;
00158 int AreasFormat;
00159 int WantOutputfile;
00160 int DoCalibration;
00161 }EXTRAINFO;
00162
00163
00164 typedef struct PeakArea {
00165 ChemSymb symb;
00166 atomicnumber atnum;
00167 int area[5][3];
00168 int erro[5][3];
00169 } PeakArea;
00170
00171
00172 typedef struct CalibYld {
00173 double K_[4];
00174 double L_[4][4];
00175 double M_[4];
00176 } CalibYld;
00177
00178
00179
00180 typedef struct XrayYield {
00181 ChemSymb symb;
00182 atomicnumber atnum;
00183 CalibYld ener;
00184 CalibYld XYld;
00185 } XrayYield;
00186
00187
00188 typedef struct FluorCKCoef {
00189 atomicnumber atnum;
00190 double w[10];
00191 double ck[3];
00192 CalibYld k;
00193 } FluorCKCoef;
00194
00195
00196 typedef struct SRType {
00197 CalibYld AbsFact;
00198 CalibYld Xeq;
00199 CalibYld SFCr;
00200 CalibYld DetLim;
00201 CalibYld ConcErr;
00202 CalibYld MDV;
00203 } SRType;
00204
00205
00206
00207 typedef struct SecResType {
00208 PeakArea Pk;
00209 SRType SR;
00210 } SecResType;
00211
00212
00213
00214
00215 typedef struct ESxType {
00216 double ep;
00217 double stpp;
00218 double x;
00219 } ESxType;
00220
00221
00222 typedef struct foil {
00223 double thick;
00224 int nfoilelm;
00225 COMPOUND comp;
00226 } foil;
00227
00228
00229
00230 typedef struct
00231 {
00232 int NumOfTrc;
00233 int *TrcAtnum;
00234 int dimTrans;
00235 CalibYld *Trans;
00236
00237
00238 XrayYield *ResYldArray;
00239 SecResType *SecResArray;
00240 int *TrcUse;
00241 int *NeedSFC;
00242 ESxType *ESxArray;
00243 int FESxlen;
00244 CalibYld *SSTrsArray;
00245 CalibYld *SSYldArray;
00246 double ThickIn;
00247 double FoilInEner;
00248 double FoilOutEner;
00249 double absolutepos;
00250 const foil *pFoil;
00251 } LYR;
00252
00253
00254
00255 typedef struct AbsCoef {
00256 atomicnumber atnum;
00257 double coefstd[23];
00258 double enr[10];
00259 double coefenr[9][2];
00260 } AbsCoef;
00261
00262
00263 typedef struct FILTER {
00264 int nlyr;
00265 int MaxZ;
00266 int *FilterElems;
00267 double geomcorr;
00268 foil *foil;
00269 int dimTrans;
00270 CalibYld *Trans;
00271 int changes;
00272 int FilterType;
00273 absorber Calibflt;
00274 }FILTER;
00275
00276
00277 typedef struct CPIXERESULTS{
00278 int atnum;
00279 CalibYld simareas;
00280 CalibYld err;
00281 }CPIXERESULTS;
00282
00283
00284
00285
00286 typedef struct SFCListElem {
00287 atomicnumber Za;
00288 atomicnumber Zb;
00289 int epri;
00290 int esec;
00291 int abs;
00292 double Ea;
00293 double sigmaphoto;
00294 } SFCListElem;
00295
00296
00297
00298
00299
00300
00301
00302 static const atomicnumber minK = 11, maxK = 54, minL = 30, minM = 60;
00303
00304 static const CalibYld CYldNul = { { 0.0, 0.0, 0.0, 0.0 },
00305 { { 0.0, 0.0, 0.0, 0.0 },
00306 { 0.0, 0.0, 0.0, 0.0 },
00307 { 0.0, 0.0, 0.0, 0.0 },
00308 { 0.0, 0.0, 0.0, 0.0 }},
00309 { 0.0, 0.0, 0.0, 0.0 }};
00310
00311
00312
00313
00314 static char LineNm[6][4][11] = {
00315 { "--", " -- ", " -- ", " -- " },
00316 { "--", "K_alpha1,2", "K_beta_1 ", "K_beta_2 " },
00317 { "--", "L_alpha1,2", "L_beta_2 ", "L_l " },
00318 { "--", "L_beta_1 ", "L_gamma_1 ", "L_eta " },
00319 { "--", "L_beta_3 ", "L_beta_4 ", "L_gamma_3 " },
00320 { "--", "M_alpha1,2", "M_beta ", "M_gamma " }
00321 };
00322
00323
00324
00325
00326
00327 void testlib(int **testarray,int *n);
00328
00329 int symbol2Z(char *symbol);
00330
00331 int Z2mass(int Z, double *mass, char option);
00332
00333 int readCOMPOUND(FILE *f, int nelem, COMPOUND *c);
00334
00335 int readINPUT(const char *InputFileNm, EXP_PARAM *pexppar, EXTRAINFO *pExtraInfo);
00336
00337 int readEXP_PARAM(char *ExpParFileNm, EXP_PARAM *pexppar);
00338
00339 int readSIM_PARAM(char *SampleParamFileNm, SIM_PARAM *simpar,char *IniMatFileNm, char *FilterFileNm, char *XYldFileNm);
00340
00341 int readsample(char *SampleDefFileNm, int *MaxZ, int *NFoil, foil **Sample);
00342
00343 int readFilter(const char *FilterDefFileNm, FILTER *Filter);
00344
00345 int createPresentElems(int MaxZ, int NFoil,const foil *MatArray, int **PresentElems);
00346
00347 int readCalcFlags(const char *CalcFlagsFileNm, const int *PresentElems, int MaxZinsample, int AreasFormat, CPIXERESULTS **CalcFlags);
00348
00349 int readXYld(const char *XYldFileNm, const int *PresentElems, const CPIXERESULTS *CalcFlags, int MaxZinsample, double *CalEner, XrayYield **XYldArray);
00350
00351 int readFCK(char *FCKCoefFileNm, int MaxZinsample, FluorCKCoef **FCKCoefArray);
00352
00353 int readAbsCoef(char *TotAbsCoefFileNm, int MaxZinsample, const int *PresentElems, const FILTER *Filter, AbsCoef **TotAbsCoefArray);
00354
00355 int createSPTs(const char *path, const EXP_PARAM *pexp, int MaxZinsample, const int *PresentElems, double step, SPT **SPTArray);
00356
00357 double getSP(const COMPOUND *pcmp, const SPT *SPTArray, double E);
00358
00359 int initlyrarray(const EXP_PARAM *pexp, const foil *MatArray, const XrayYield *XYldArray, const AbsCoef *TotAbsCoefArray, const SPT *SPTArray, const int *PresentElems, int NFoil, int *NFoilUsed, LYR **plyrarray);
00360
00361 int initlyr(const EXP_PARAM *pexp, const XrayYield *XYldArray, const AbsCoef *TotAbsCoefArray, const int *PresentElems, LYR *plyr, double *MACoef);
00362
00363 int FilterTrans(const EXP_PARAM *pexp, const XrayYield *XYldArray, const AbsCoef *TotAbsCoefArray, const int *PresentElems, FILTER *Filter);
00364
00365 int Transmission(const XrayYield *XYldArray, const AbsCoef *TotAbsCoefArray, int Z, const foil *pFoil, double geomcorr, const CalibYld *pTransOld, CalibYld *pTrans);
00366
00367 double TotAbsor(const AbsCoef *TotAbsCoefArray, const COMPOUND *cmp, double Xray);
00368
00369 double TotAbsor_elemental(int iener, const AbsCoef *Absco, int Z, double Xray);
00370
00371 int createsublyrs(const EXP_PARAM *pexp, const foil *pMat, const SPT *SPTArray, double MajAbsCoef, LYR *plyr);
00372
00373 int SSThick(const EXP_PARAM *pexp, const foil *pMat, const SPT *SPTArray, double MajAbsCoef, double LayerThickness, ESxType ESxin,
00374 ESxType *ESxfin, int *pFpos, double *thick, ESxType **ESxA);
00375
00376 int integrate_Simpson(const EXP_PARAM *pexp, const AbsCoef *TotAbsCoefArray, const FluorCKCoef *FCKCoefArray, const XrayYield *XYldArray, int NFoilUsed, const FILTER *Filter, LYR *plyrarray, CalibYld *XYldSums);
00377
00378 int Xprod(const AbsCoef *AbsC, const FluorCKCoef *pFCK, atomicnumber Z1, atomicnumber Z2, double M2 , double ener, CalibYld *XYld);
00379
00380 double PaulX(double ener, atomicnumber z);
00381
00382 double PaulX_y(double MeV, atomicnumber z);
00383
00384 double PaulX_lp(double x, long p);
00385
00386 int ReisX(const AbsCoef *AbsC, const FluorCKCoef *pFCK, double ener, atomicnumber z, double M2, double *sigmaXL);
00387
00388 double ReisX_gs(FwTipo T, int SS, double ksis);
00389
00390 double ReisX_hs(FwTipo T, int SS, double ksih, double thet);
00391
00392 double ReisX_En(double z, int niu);
00393
00394 double ReisX_polisec(int ssind, double kz, double tz);
00395
00396 double ReisX_g(int ss, atomicnumber Zg, double xi);
00397
00398 void PenInteg(atomicnumber atnumb, const CalibYld *absc, const ESxType *ESA,
00399 const CalibYld *YldA, const CalibYld *TrsA, const CalibYld *pTrs0,
00400 int FExlen, int NeedSFC, int AllowXEqCalc,
00401 double x0, double CosInc,
00402 CalibYld *XYld, CalibYld *XSFCr, CalibYld *XYldxmed);
00403
00404 double Simps(double a, double b, double fa, double fi, double fb);
00405
00406 void deNormalize(const EXP_PARAM *pexp, const AbsCoef *AbsC,
00407 const FluorCKCoef *pFCK, atomicnumber Z2, double M2, double attfraction,
00408 const CalibYld *pXYld, XrayYield *ResY, CalibYld *XYldSum);
00409
00410 void freeFilter(FILTER *Filter);
00411
00412 void freeReusable(int NFoils, LYR **plyrarray, foil **MatArray, CalibYld **XYldSums );
00413
00414 void safefree(void **ptr);
00415
00416 void fprintCALIBYLD(FILE *f,const CalibYld *pCYld);
00417
00418 int createSFCList(const EXP_PARAM *pexp, const int *PresentElems, const XrayYield *XYldArray, const AbsCoef *TotAbsCoefArray, int *dimList, SFCListElem **SFCList);
00419
00420 int needSFC(atomicnumber Za, atomicnumber Zb, const CalibYld *enerA, const AbsCoef *AbsC, int *dimList, SFCListElem **SFCList );
00421
00422 double sigmaphoto(int iabs, const AbsCoef *AbsC, atomicnumber Zb, double Xray);
00423
00424 int inrange(double value,double min, double max);
00425