00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef HKL_UNMERGE_HEADER
00011 #define HKL_UNMERGE_HEADER
00012
00013 #include <map>
00014 #include "hkl_datatypes.hh"
00015 #include "hkl_controls.hh"
00016 #include "controls.hh"
00017 #include "hkl_symmetry.hh"
00018 #include "icering.hh"
00019 #include "observationflags.hh"
00020 #include "range.hh"
00021 #include "hash.hh"
00022 #include "runthings.hh"
00023
00024 namespace scala
00025 {
00026
00027 class data_flags
00029
00030 {
00031 public:
00032 data_flags();
00033 void print() const;
00034
00035 bool is_h, is_k, is_l, is_misym, is_batch,
00036 is_I, is_sigI, is_Ipr, is_sigIpr, is_fractioncalc,
00037 is_Xdet, is_Ydet, is_Rot, is_Width, is_LP, is_Mpart,
00038 is_ObsFlag, is_BgPkRatio, is_scale, is_sigscale, is_time;
00039 };
00040
00041
00042 class SelectI
00043 {
00045
00046
00047 public:
00048 SelectI(){}
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 static bool Combine() {return (selecticolflag > 0);}
00063
00064
00065 static void SetIcolFlag(const int& IcolFlag, const double& Imid, const int Ipower=3);
00066
00067 static int& SelectIcolFlag() {return selecticolflag;}
00068
00069 static void SetAverageIntensity(const double& meanI);
00070
00071 static IsigI GetCombinedI(const Rtype& Ic, const Rtype& varIc,
00072 const Rtype& Ipr, const Rtype& varIpr);
00073
00074 static std::string format();
00075
00076 private:
00077 static int selecticolflag;
00078 static int ipowercomb;
00079 static double imid;
00080
00081 };
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 enum PartFlagSwitch
00092 {EMPTY, FULL, COMPLETE_CHECKED, COMPLETE, SCALE, INCOMPLETE, EXCLUDED};
00093
00095 class observation_part
00096
00097
00098 {
00099 public:
00100
00101
00102 observation_part();
00103 observation_part(const Hkl& hkl_in,
00104 const int& isym_in, const int& batch_in,
00105 const Rtype& I_in, const Rtype& sigI_in,
00106 const Rtype& I_pr, const Rtype& sigIpr_in,
00107 const Rtype& Xdet_in, const Rtype& Ydet_in,
00108 const Rtype& phi_in, const Rtype& time_in,
00109 const Rtype& fraction_calc_in, const Rtype& width_in,
00110 const Rtype& LP_in,
00111 const int& Npart_in, const int& Ipart_in,
00112 const ObservationFlag& ObsFlag_in);
00113
00114
00115
00116
00117
00118 void set_run(const int& run) {run_ = run;}
00119
00120
00121 inline IsigI I_sigI() const {return IsigI(I_, sigI_);}
00122 inline Rtype Ic() const {return I_;}
00123 inline Rtype sigIc() const {return sigI_;}
00124 inline IsigI I_sigIpr() const {return IsigI(Ipr_, sigIpr_);}
00125 inline Rtype Ipr() const {return Ipr_;}
00126 inline Rtype sigIpr() const {return sigIpr_;}
00127
00128 void StoreIsigI(const IsigI& Is) {I_ = Is.I(); sigI_ = Is.sigI();}
00129 void StoreIsigIpr(const IsigI& Ipr) {Ipr_ = Ipr.I(); sigIpr_ = Ipr.sigI();}
00130
00131
00132
00133 inline Rtype Ic(const int& selIcolFlag) const
00134 {return (selIcolFlag == 0) ? I_ : Ipr_;}
00135 inline Rtype sigIc(const int& selIcolFlag) const
00136 {return (selIcolFlag == 0) ? sigI_ : sigIpr_;}
00137
00138
00139 inline Rtype Xdet() const {return Xdet_;}
00140 inline Rtype Ydet() const {return Ydet_;}
00141 inline Rtype phi() const {return phi_;}
00142 inline Rtype time() const {return time_;}
00143 inline Rtype fraction_calc() const {return fraction_calc_;}
00144 inline Rtype width() const {return width_;}
00145 inline Rtype LP() const {return LP_;}
00146
00147 inline int isym() const {return isym_;}
00148 inline int batch() const {return batch_;}
00149 inline int Npart() const {return Npart_;}
00150 inline int Ipart() const {return Ipart_;}
00151 inline ObservationFlag ObsFlag() const {return ObsFlag_;}
00152 inline int run() const {return run_;}
00153 inline Hkl hkl() const {return hkl_;};
00154
00155 void set_isym(const int& isym) {isym_ = isym;}
00156 void set_hkl(const Hkl& hkl) {hkl_ = hkl;}
00157 void set_batch(const int& Batch) {batch_ = Batch;}
00158 void set_phi(const Rtype& Phi) {phi_ = Phi;}
00159 void offset_phi(const Rtype& Offset) {phi_ += Offset;}
00160 void offset_time(const Rtype& Offset) {time_ += Offset;}
00161 void negate_time() {time_ = -time_;}
00162
00163 private:
00164 Hkl hkl_;
00165 int isym_, batch_;
00166 Rtype I_, sigI_;
00167 Rtype Ipr_, sigIpr_;
00168 Rtype Xdet_, Ydet_, phi_, time_;
00169 Rtype fraction_calc_, width_, LP_;
00170 int Npart_, Ipart_;
00171 ObservationFlag ObsFlag_;
00172 int run_;
00173 };
00174
00175
00177 class observation
00178 {
00179
00180 public:
00181 observation();
00182 observation(const Hkl hkl_in,
00183 const int& isym_in,
00184 const int& run_in,
00185 const int& datasetIndex_in,
00186 const int& Npart_in,
00187 observation_part ** const part1_in,
00188 const Rtype& TotFrac,
00189 const PartFlagSwitch& partialstatus_in,
00190 const ObservationFlag& obsflag_in);
00191
00192
00193 Rtype I() const {return I_;}
00194 Rtype sigI() const {return sigI_;}
00195 IsigI I_sigI() const {return IsigI(I_,sigI_);}
00196
00197 Rtype kI() const {return I_/gscale;}
00198 Rtype ksigI() const {return sigI_/gscale;}
00199 IsigI kI_sigI() const {return IsigI(I_/gscale,sigI_/gscale);}
00200
00201
00202 Rtype phi() const {return phi_;}
00203 Rtype time() const {return time_;}
00204 int Isym() const {return isym_;}
00205 Rtype LP() const {return LP_;}
00206
00208 int run() const {return run_;};
00209
00210 int datasetIndex() const {return datasetIndex_;}
00211 bool IsAccepted() const {return obs_status.IsAccepted();}
00212
00213 int num_parts() const;
00214 observation_part get_part(const int& kpart) const;
00215 void replace_part(const int& kpart, const observation_part& obs_part);
00216
00217 Hkl hkl_original() const {return hkl_original_;}
00218 bool IsFull() const {return part_flag == FULL;}
00219 Rtype Gscale() const {return gscale;}
00220 std::pair<float,float> XYdet() const;
00221 float TotalFraction() const {return totalfraction;}
00222 int Batch() const;
00223
00224
00225 PartFlagSwitch PartFlag() const {return part_flag;}
00226
00228 bool set_IsigI_phi_time(const Rtype& I, const Rtype& sigI,
00229 const Rtype& phi, const Rtype& time,
00230 const Rtype& LP);
00232 void set_batch(const int& batch) {batch_ = batch;}
00234 void set_sigI(Rtype& sigI) {sigI_ = sigI;}
00236 void SetGscale(const Rtype& g) {gscale = g;}
00238 void StoreS2(const float& Thetap, const float& Phip)
00239 {thetap=Thetap; phip=Phip;}
00241 void GetS2(double& Thetap, double& Phip) const
00242 {Thetap=thetap; Phip=phip;}
00244 void StoreS(const FVect3& dStarvec) {s_dif = dStarvec;}
00246 FVect3 GetS() const {return s_dif;}
00248
00254 void ResetObsAccept(ObservationFlagControl& ObsFlagControl);
00256 ObservationFlag Observationflag() const {return obs_flag;}
00257
00259 ObservationStatus ObsStatus() const {return obs_status;}
00261 void UpdateStatus(const ObservationStatus& Status) {obs_status = Status;}
00262
00263 private:
00264 Hkl hkl_original_;
00265 int isym_;
00266 int run_;
00267 int datasetIndex_;
00268 int Npart_;
00269 observation_part ** part1;
00270 int batch_;
00271 Rtype totalfraction;
00272 PartFlagSwitch part_flag;
00273 ObservationFlag obs_flag;
00274 Rtype gscale;
00275 Rtype I_, sigI_;
00276 Rtype phi_;
00277 Rtype time_;
00278 Rtype LP_;
00279 ObservationStatus obs_status;
00280 Rtype thetap, phip;
00281 FVect3 s_dif;
00282 };
00283
00284
00286 class reflection
00287 {
00288 public:
00289 reflection();
00290
00292
00296 reflection(const Hkl& hkl, const int& index_obs1, const Dtype& s);
00297 reflection(const reflection& refl);
00298
00299 reflection& operator= (const reflection& refl);
00300
00301
00303 void store_last_index(const int& index_obs2);
00304 inline int first_index() const {return index_first_obs_;}
00305 inline int last_index() const {return index_last_obs_;}
00306 inline Hkl hkl() const {return hkl_reduced_;}
00307
00309 void add_observation_list(const std::vector<observation>& obs_in);
00310
00312
00314 Rtype sum_partials(int& Nfull, int& Npart, int& Nscaled);
00315
00316
00317 int num_observations() const;
00318 int NvalidObservations() const;
00319 observation get_observation(const int& lobs) const;
00320
00322 int next_observation(observation& obs) const;
00324 void reset() const {NextObs = -1;}
00326 void replace_observation(const observation& obs);
00328 void replace_observation(const observation& obs, const int& lobs);
00329
00330 void CountNValid();
00331
00332 Rtype invresolsq() const {return invresolsq_;}
00333
00335
00336 void ResetObsAccept(ObservationFlagControl& ObsFlagControl);
00337
00338 void SetStatus(const int& istat) {statusflag = istat;}
00339 int Status() const {return statusflag;}
00340
00341 private:
00342 Hkl hkl_reduced_;
00343 std::vector<observation> observations;
00344 int index_first_obs_, index_last_obs_;
00345 Rtype invresolsq_;
00346 mutable int NextObs;
00347 int NvalidObs;
00348 int statusflag;
00349 };
00350
00351
00352 class hkl_unmerge_list
00354
00381 {
00382 public:
00384 hkl_unmerge_list(): status(EMPTY) {};
00386 void init(const std::string& Title,
00387 const int& NreflReserve,
00388 const hkl_symmetry& symmetry,
00389 const all_controls& controls,
00390 const std::vector<Xdataset>& DataSets,
00391 const std::vector<Batch>& Batches);
00393 void init(const std::string& Title,
00394 const int& NreflReserve,
00395 const hkl_symmetry& symmetry,
00396 const all_controls& controls);
00398 void clear();
00399
00401 bool IsEmpty() const {return (status == EMPTY);}
00402
00404 bool IsReady() const {return (status == SUMMED);}
00405
00407 void StoreDatasetBatch(const std::vector<Xdataset>& DataSets,
00408 const std::vector<Batch>& Batches);
00409
00411
00412 void AddDatasetBatch(const std::vector<Xdataset>& DataSets,
00413 const std::vector<Batch>& Batches);
00414
00416
00418 int append(const hkl_unmerge_list& OtherList);
00419
00420
00422 hkl_unmerge_list(const hkl_unmerge_list& List);
00424 hkl_unmerge_list& operator= (const hkl_unmerge_list& List);
00425
00426
00427
00428 void SetResoLimits(const float& LowReso, const float& HighReso);
00429
00431 void ResetResoLimits();
00433 void SetIceRings(const Rings& rings);
00434
00436
00437 void ImposeResoByRunLimits();
00438
00439
00441 int num_reflections() const;
00443 int num_reflections_valid() const {return Nref_valid;}
00445 int num_reflections_icering() const {return Nref_icering;}
00446
00448 int num_observations() const;
00450 int num_observations_full() const {return Nobs_full;}
00452 int num_observations_part() const {return Nobs_partial;}
00454 int num_observations_scaled() const {return Nobs_scaled;}
00456 int num_observations_rejected_FracTooSmall() const
00457 {return partial_flags.NrejFractionTooSmall();}
00459 int num_observations_rejected_FracTooLarge() const
00460 {return partial_flags.NrejFractionTooLarge();}
00462 int num_observations_rejected_Gap() const {return partial_flags.NrejGap();}
00464 Rtype MinSigma() const {return sigmamin;}
00466 Scell cell(const PxdName& PXDsetName = PxdName()) const;
00467 Scell Cell() const {return cell(PxdName());}
00468
00470 hkl_symmetry symmetry() const {return refl_symm;}
00471
00473 void SetMtzSym(const CMtz::SYMGRP& Mtzsym) {mtzsym = Mtzsym;}
00475 CMtz::SYMGRP MtzSym() const {return mtzsym;}
00476
00478 ReindexOp TotalReindex() const {return totalreindex;}
00479
00480 ResoRange ResRange() const {return ResolutionRange;}
00481 Range Srange() const {return ResolutionRange.SRange();}
00482 Range RRange() const {return ResolutionRange.RRange();}
00483 ResoRange ResLimRange() const {return ResoLimRange;}
00484 Rtype DstarMax() const;
00485
00486 int num_datasets() const {return ndatasets;}
00487 Xdataset xdataset(const int& jset) const {return datasets.at(jset);}
00488 std::vector<Xdataset> AllXdatasets() const {return datasets;}
00489
00490 int num_batches() const {return nbatches;}
00491 std::vector<Batch> Batches() const {return batches;}
00492
00494 Batch batch(const int& jbat) const {return batches.at(jbat);}
00496 int batch_serial(const int& batch) const {return batch_lookup.lookup(batch);}
00497
00498
00499
00500
00501 int NextBatchSerial(const int& batchnum, const int& maxbatchnum) const;
00502
00503
00504
00505 int LastBatchSerial(const int& batchnum) const;
00506
00507
00508 int num_runs() const {return runlist.size();}
00509 std::vector<Run> RunList() const {return runlist;}
00510
00512 void OffsetBatchNumbers(const std::vector<int>& runOffsets);
00514
00515 void RejectBatch(const int& batch);
00517
00518 void RejectBatchSerial(const int& jbat);
00519
00521 int PurgeRejectedBatches();
00523
00524 int EliminateBatches(const std::vector<int> RejectedBatches);
00525
00527 std::string Title() const {return FileTitle;}
00528
00530 void AppendFileName(const std::string& Name);
00531 std::string Filename() const {return filename;}
00532
00534 reflection get_reflection(const int& lref) const;
00536
00537 int get_reflection(reflection& refl, const Hkl& hkl) const;
00539 int next_reflection(reflection& refl) const;
00541 void replace_reflection(const reflection& refl);
00542
00544 void replace_observation(const observation& obs, const int& lobs);
00545
00547
00548 void rewind() const;
00549
00551 observation_part& find_part(const int& i) const;
00553 int num_parts() const {return N_part_list;}
00554
00555
00556
00558
00561 int change_symmetry(const hkl_symmetry& new_symm,
00562 const ReindexOp& reindex_op,
00563 const bool& AllowFractIndex = false);
00564
00566
00568 int prepare();
00570
00571 int sum_partials();
00572
00574
00578 void CalcSecondaryBeams(const int& pole);
00579
00581 void SetPoles(const int& pole);
00582
00584
00592 std::pair<float, float> CalcSecondaryBeamPolar
00593 (const int& batchNum, const Hkl& hkl_original, const float& phi,
00594 DVect3& sPhi) const;
00595
00597
00605 DVect3 CalcSecondaryBeam
00606 (const int& batchNum, const Hkl& hkl_original, const float& phi,
00607 DVect3& sPhi) const;
00608
00610
00613 void ResetObsAccept(ObservationFlagControl& ObsFlagControl);
00615 void ResetReflAccept();
00616
00618 void store_part(const Hkl& hkl_in,
00619 const int& isym_in, const int& batch_in,
00620 const Rtype& I_in, const Rtype& sigI_in,
00621 const Rtype& Ipr, const Rtype& sigIpr,
00622 const Rtype& Xdet_in, const Rtype& Ydet_in,
00623 const Rtype& phi_in, const Rtype& time_in,
00624 const Rtype& fraction_calc_in, const Rtype& width_in,
00625 const Rtype& LP_in,
00626 const int& Npart_in, const int& Ipart_in,
00627 const ObservationFlag& ObsFlag_in);
00629 int close_part_list(const ResoRange& RRange,
00630 const bool& Sorted);
00631
00633 void StoreDataFlags(const data_flags& DataFlags) {dataflags = DataFlags;}
00635 data_flags DataFlags() const {return dataflags;}
00636
00637
00638 void dump_reflection(const Hkl& hkl) const;
00639
00640
00641 void AutoSetRun();
00642
00643
00644 private:
00645 void initialise(const int NreflReserve,
00646 const hkl_symmetry& symmetry);
00647
00648
00649 int organise();
00650
00651 int partials();
00652 void MakeHklLookup() const;
00653
00654 void SetBatchList();
00655 void AverageBatchData();
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666 enum rfl_status
00667 {EMPTY, RAWLIST, SORTED, ORGANISED, PREPARED, SUMMED};
00668 rfl_status status;
00669 bool ChangeIndex;
00670 ReindexOp totalreindex;
00671
00672 std::vector <observation_part> obs_part_list;
00673 std::vector <observation_part *> obs_part_pointer;
00674 std::vector <reflection> refl_list;
00675 Rtype sigmamin;
00676 int N_part_list;
00677 int Nref;
00678 int Nref_valid;
00679
00680 int Nobservations;
00681 int Nobs_full;
00682 int Nobs_partial;
00683 int Nobs_scaled;
00684
00685 mutable clipper::HKL_lookup hkl_lookup;
00686 mutable bool is_hkl_lookup;
00687
00688 mutable int Nref_icering;
00689
00690 mutable int NextRefNum;
00691
00692 hkl_symmetry refl_symm;
00693 CMtz::SYMGRP mtzsym;
00694
00695
00696
00697 Scell averagecell;
00698 ResoRange ResolutionRange;
00699 ResoRange ResoLimRange;
00700
00701
00702
00703
00704 int run_set;
00705
00706 run_controls run_flags;
00707
00708 bool partial_set;
00709 partial_controls partial_flags;
00710
00711
00712 Rings Icerings;
00713
00714
00715 std::vector<Xdataset> datasets;
00716 int ndatasets;
00717 std::vector<Batch> batches;
00718 int nbatches;
00719 hash_table batch_lookup;
00720
00721
00722
00723
00724
00725
00726
00727 bool IsPhiOffset;
00728
00729
00730 std::vector<Run> runlist;
00731
00732 std::string FileTitle;
00733 std::string filename;
00734
00735
00736 data_flags dataflags;
00737
00738
00739
00740 void sort();
00741
00742 void add_refl(const Hkl& hkl_red, const int& index, const Dtype& s);
00743 void end_refl(const int& index);
00744
00745
00746 void set_run();
00747
00748 bool accept() const;
00749
00750
00752 void SetUpRuns();
00753 void CheckAllRuns();
00754 void SetRunInput();
00755
00756
00757
00758
00759 bool StoreOrientationRun();
00760
00761
00762
00763
00764 void MergeDatasetLists(const std::vector<Xdataset>& otherDatasets,
00765 const std::vector<Batch>& otherBatches);
00766
00767 struct ComparePartOrder
00768
00769
00770 {
00771 bool operator()(const observation_part * part1,
00772 const observation_part * part2);
00773 };
00774 };
00775 }
00776
00777 #endif
00778