00001
00002
00003
00004 #ifndef SCALA_NORMALISE
00005 #define SCALA_NORMALISE
00006
00007 #include "hkl_merged_list.hh"
00008 #include "hkl_unmerge.hh"
00009 #include "spline.hh"
00010 #include "icering.hh"
00011 #include "score_datatypes.hh"
00012 #include "linearlsq.hh"
00013 #define ASSERT assert
00014 #include <assert.h>
00015
00016 namespace scala
00017 {
00018
00019 class BinSums {
00020 public:
00021 BinSums(const Rtype& Time0=0.0) : sum_I(0.0), sum_sSqr(0.0), sum_time(0.0), N(0),
00022 max_time(0.0)
00023 {time0=Time0;}
00024
00025 void clear(const Rtype& Time0=0.0) {sum_I=0.0;sum_sSqr=0.0;N=0;sum_time=0.0;
00026 time0=Time0;max_time=0.0;}
00027
00028
00029 void add(const Rtype& I, const Rtype& sSqr, const Rtype& Time=0.0);
00030
00031
00032 double MeanI() const;
00033
00034 double MeanSSqr() const;
00035
00036 int num() const {return N;}
00037
00038 double MeanTime() const;
00039
00040 double Time0() const {return time0;}
00041
00042 double MaxTime() const {return max_time;}
00043
00044 private:
00045
00046 double sum_I;
00047 double sum_sSqr;
00048 int N;
00049
00050 double sum_time;
00051 double time0;
00052 double max_time;
00053 };
00054
00055 class BfactorModel {
00056
00057
00058
00059
00060
00061
00062
00063
00064 public:
00065 BfactorModel() : nparam(3), time0(0.0), valid(false), dtime(0.0) {}
00066
00067 BfactorModel(const bool& Constant) : valid(false), dtime(0.0) {
00068 Setup(Constant);}
00069
00070
00071 void Setup(const bool& Constant, const double& Time0=0.0);
00072
00073 int Nparam() const {return nparam;}
00074
00075
00076 void Set(const std::vector<double>& params);
00077
00078
00079 void Invalid() {valid = false;}
00080 bool Valid() const {return valid;}
00081
00082
00083 std::vector<double> MeasurementVector(const double& sSqr, const double& t);
00084
00085
00086 double C0() const {return exp(lnC0);}
00087
00088 double Bfac() const {return B0;}
00089
00090
00091 std::vector<double> Params() const;
00092
00093
00094 double DTime() const {return dtime;}
00095 double& DTime() {return dtime;}
00096
00097
00098
00099 double Factor(const double& sSqr, const double& t=0.0) const;
00100
00101 double FactorT(const double& sSqr, const double& t=0.0) const;
00102
00103 private:
00104 bool valid;
00105 double lnC0;
00106 double B0;
00107 double B;
00108 double time0;
00109 double dtime;
00110 int nparam;
00111 };
00112
00113 class Normalise
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 {
00144 public:
00145 Normalise() : validAll(false), validRun(false) {type=-1;}
00146
00147 Normalise(const std::vector<clipper::Array2d<BinSums> >& sums_st);
00148
00149
00150 void SetE2max(const float& EEmax) {E2max = EEmax;}
00151
00152
00153 float SclCor() const {return AvgFactor.C0();}
00154
00155
00156 float Bcorr() const {return AvgFactor.Bfac();}
00157
00158
00159 float Corr(const float& sSqr,
00160 const int& irun, const float& time) const;
00161
00162 std::vector<BfactorModel> BfactorCorr() const {return Bfactors;}
00163
00164
00165
00166
00167
00168 float apply(const float& I, const float& sSqr,
00169 const int& irun, const float& time) const;
00170 IsigI apply(const IsigI& Is, const float& sSqr,
00171 const int& irun, const float& time) const;
00172
00173 float applyAvg(const float& I, const float& sSqr) const;
00174 IsigI applyAvg(const IsigI& Is, const float& sSqr) const;
00175
00176
00177 float Imean() const {return imean;}
00178
00179 float Imax() const {return imax;}
00180
00181
00182 bool NotTooLarge(const float& EE) const
00183 {
00184 return (EE < E2max);
00185 }
00186
00187 bool NotTooLarge(const IsigI& Is) const
00188 {
00189 return (Is.I() < E2max);
00190 }
00191
00192
00193 private:
00194 bool validRun;
00195 bool validAll;
00196 int type;
00197 float bcmin;
00198 int Nbins;
00199 int Nruns;
00200 std::vector<LinearLSQ> RunFactor;
00201 std::vector<BfactorModel> Bfactors;
00202 float SclCorr;
00203 BfactorModel AvgFactor;
00204
00205 float imean;
00206 float imax;
00207
00208 std::vector<BinSums> sSqrmnI;
00209 std::vector<RPair> sSqrmnIcorr;
00210 Spline bincorr;
00211 float E2max;
00212
00213
00214 };
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 Normalise SetNormalise(const hkl_unmerge_list& ref_list,
00230 const double& MinIsigRatio,
00231 const bool& Overall,
00232 ResoRange& ResRange,
00233 Rings& Icerings,
00234 const int PrintLevel);
00235
00236
00237
00238
00239
00240
00241
00242
00243 Normalise SetNormaliseMerged(const hkl_merged_list& ref_list,
00244 const double& MinIsigRatio,
00245 ResoRange& ResRange);
00246
00247 }
00248
00249
00250 #endif