29 #include "cctbx/sgtbx/space_group.h"
31 #include "ObjCryst/ObjCryst/PowderPattern.h"
32 #include "ObjCryst/ObjCryst/Molecule.h"
33 #include "ObjCryst/ObjCryst/PowderPatternBackgroundBayesianMinimiser.h"
34 #include "ObjCryst/RefinableObj/Simplex.h"
35 #include "ObjCryst/Quirks/VFNDebug.h"
36 #include "ObjCryst/Quirks/VFNStreamFormat.h"
37 #include "ObjCryst/ObjCryst/CIF.h"
39 #include "ObjCryst/wxCryst/wxPowderPattern.h"
46 #ifdef _MSC_VER // MS VC++ predefined macros....
60 ObjRegistry<PowderPatternComponent>
63 PowderPatternComponent::PowderPatternComponent():
64 mIsScalable(false),mpParentPowderPattern(0)
67 mClockMaster.AddChild(mClockBraggLimits);
70 PowderPatternComponent::PowderPatternComponent(
const PowderPatternComponent &old):
71 mIsScalable(old.mIsScalable),
72 mpParentPowderPattern(old.mpParentPowderPattern)
74 mClockMaster.AddChild(mClockBraggLimits);
75 if(mpParentPowderPattern!=0)
77 mClockMaster.AddChild(mpParentPowderPattern->GetClockPowderPatternPar());
78 mClockMaster.AddChild(mpParentPowderPattern->GetClockPowderPatternXCorr());
79 mClockMaster.AddChild(mpParentPowderPattern->GetClockPowderPatternRadiation());
83 PowderPatternComponent::~PowderPatternComponent()
88 const string& PowderPatternComponent::GetClassName()
const
90 const static string className=
"PowderPatternComponent";
94 const PowderPattern& PowderPatternComponent::GetParentPowderPattern()
const
96 return *mpParentPowderPattern;
99 std::map<RefinablePar*,CrystVector_REAL>& PowderPatternComponent::GetPowderPattern_FullDeriv(std::set<RefinablePar *> &vPar)
101 this->CalcPowderPattern_FullDeriv(vPar);
102 return mPowderPattern_FullDeriv;
105 std::map<RefinablePar*,CrystVector_REAL>& PowderPatternComponent::GetPowderPatternIntegrated_FullDeriv(std::set<RefinablePar *> &vPar)
107 this->CalcPowderPatternIntegrated_FullDeriv(vPar);
108 return mPowderPatternIntegrated_FullDeriv;
113 return *mpParentPowderPattern;
116 bool PowderPatternComponent::IsScalable()
const {
return mIsScalable;}
120 return mClockPowderPatternCalc;
124 return mClockBraggLimits;
127 const list<pair<const REAL, const string> >& PowderPatternComponent::GetPatternLabelList()
const
132 void PowderPatternComponent::CalcPowderPattern_FullDeriv(std::set<RefinablePar *> &vPar)
134 TAU_PROFILE(
"PowderPatternComponent::CalcPowderPattern_FullDeriv()",
"void ()",TAU_DEFAULT);
135 mPowderPattern_FullDeriv.clear();
136 for(std::set<RefinablePar *>::iterator par=vPar.begin();par!=vPar.end();par++)
140 mPowderPattern_FullDeriv[*par]=this->GetPowderPatternCalc();
143 const REAL step=(*par)->GetDerivStep();
144 (*par)->Mutate(step);
145 mPowderPattern_FullDeriv[*par] =this->GetPowderPatternCalc();
146 (*par)->Mutate(-2*step);
147 mPowderPattern_FullDeriv[*par]-=this->GetPowderPatternCalc();
148 (*par)->Mutate(step);
149 mPowderPattern_FullDeriv[*par]/= step*2;
150 if(MaxAbs(mPowderPattern_FullDeriv[*par])==0)
151 mPowderPattern_FullDeriv[*par].resize(0);
155 void PowderPatternComponent::CalcPowderPatternIntegrated_FullDeriv(std::set<RefinablePar *> &vPar)
157 TAU_PROFILE(
"PowderPatternComponent::CalcPowderPatternIntegrated_FullDeriv()",
"void ()",TAU_DEFAULT);
158 mPowderPatternIntegrated_FullDeriv.clear();
159 for(std::set<RefinablePar *>::iterator par=vPar.begin();par!=vPar.end();par++)
163 mPowderPatternIntegrated_FullDeriv[*par]=*(this->GetPowderPatternIntegratedCalc().first);
166 const REAL step=(*par)->GetDerivStep();
167 (*par)->Mutate(step);
168 mPowderPatternIntegrated_FullDeriv[*par] =*(this->GetPowderPatternIntegratedCalc().first);
169 (*par)->Mutate(-2*step);
170 mPowderPatternIntegrated_FullDeriv[*par]-=*(this->GetPowderPatternIntegratedCalc().first);
171 (*par)->Mutate(step);
172 mPowderPatternIntegrated_FullDeriv[*par]/= step*2;
173 if(MaxAbs(mPowderPatternIntegrated_FullDeriv[*par])==0)
174 mPowderPatternIntegrated_FullDeriv[*par].resize(0);
183 PowderPatternBackground::PowderPatternBackground():
184 mBackgroundNbPoint(0),
185 mMaxSinThetaOvLambda(10),mModelVariance(0)
191 PowderPatternBackground::PowderPatternBackground(
const PowderPatternBackground &old):
192 mBackgroundNbPoint(old.mBackgroundNbPoint),
193 mBackgroundInterpPointX(old.mBackgroundInterpPointX),
194 mBackgroundInterpPointIntensity(old.mBackgroundInterpPointIntensity),
195 mMaxSinThetaOvLambda(10),mModelVariance(0)
199 mInterpolationModel.SetChoice(old.mInterpolationModel.GetChoice());
202 PowderPatternBackground::~PowderPatternBackground(){}
205 const static string className=
"PowderPatternBackground";
225 pair<const CrystVector_REAL*,const RefinableObjClock*>
228 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::GetPowderPatternIntegratedCalc()",3)
229 this->CalcPowderPatternIntegrated();
235 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::ImportUserBackground():"<<filename,5)
236 ifstream fin (filename.c_str());
240 Error opening file for input:"+filename);
243 CrystVector_REAL bckgd2Theta(max),bckgd(max);
248 fin >> bckgd2Theta(nbPoints);
249 fin >> bckgd(nbPoints);
251 VFN_DEBUG_MESSAGE(
"Background=" << bckgd(nbPoints)\
252 <<
" at 2theta="<<bckgd2Theta(nbPoints),3)
257 bckgd2Theta.resizeAndPreserve(max);
258 bckgd.resizeAndPreserve(max);
260 }
while(fin.eof() ==
false);
262 bckgd2Theta.resizeAndPreserve(nbPoints);
263 bckgd.resizeAndPreserve(nbPoints);
267 bckgd2Theta*= DEG2RAD;
268 }
else bckgd2Theta*= DEG2RAD;
270 this->SetInterpPoints(bckgd2Theta,bckgd);
271 this->InitRefParList();
275 sprintf(buf,
"Imported %d background points",(
int)nbPoints);
276 (*fpObjCrystInformUser)((string)buf);
279 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::ImportUserBackground():finished",5)
281 void PowderPatternBackground::SetInterpPoints(
const CrystVector_REAL tth,
282 const CrystVector_REAL backgd)
284 VFN_DEBUG_ENTRY(
"PowderPatternBackground::SetInterpPoints():",5)
285 if( (tth.numElements()!=backgd.numElements())
286 ||(tth.numElements()<2))
289 number of points differ or less than 2 points !");
303 this->InitRefParList();
305 VFN_DEBUG_EXIT(
"PowderPatternBackground::SetInterpPoints()",5)
308 const pair<const CrystVector_REAL*,const CrystVector_REAL*> PowderPatternBackground::GetInterpPoints()
const
314 CrystVector_uint & groupIndex,
315 unsigned int &first)
const
318 unsigned int index=0;
319 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::GetGeneGroup()",4)
321 for(
long j=0;j<this->
GetNbPar();j++)
324 if(index==0) index=first++;
330 const bool enableRestraints)
341 pair<const CrystVector_REAL*,const RefinableObjClock*>
344 this->CalcPowderPatternIntegrated();
351 #ifdef USE_BACKGROUND_MAXLIKE_ERROR
364 VFN_DEBUG_ENTRY(
"PowderPatternBackground::OptimizeBayesianBackground()",5);
365 TAU_PROFILE(
"PowderPatternBackground::OptimizeBayesianBackground()",
"void ()",TAU_DEFAULT);
373 cout<<
"Initial Chi^2(BayesianBackground)="<<llk<<endl;
379 sprintf(buf,
"Optimizing Background, Cycle %d, Chi^2(Background)=%f",
381 (*fpObjCrystInformUser)((string)buf);
386 cout<<ct<<
", Chi^2(BayesianBackground)="<<llk<<endl;
391 sprintf(buf,
"Done Optimizing Bayesian Background, Chi^2(Background)=%f",(
float)llk);
392 (*fpObjCrystInformUser)((string)buf);
399 try {lsq.
Refine(10,
true,
false);}
403 VFN_DEBUG_EXIT(
"PowderPatternBackground::OptimizeBayesianBackground()",5);
426 TAU_PROFILE(
"PowderPatternBackground::CalcPowderPattern()",
"void ()",TAU_DEFAULT);
427 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::CalcPowderPattern()",3);
434 case POWDER_BACKGROUND_LINEAR:
436 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::CalcPowderPattern()..Linear",2)
439 if(mBackgroundNbPoint==0)
444 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::CalcPowderPattern()"<<nb,2)
452 for(
unsigned long i=0;i<nb;i++)
456 if(point < mBackgroundNbPoint-1)
465 *b = (b1*(p2-i)+b2*(i-p1))/(p2-p1) ;
470 case POWDER_BACKGROUND_CUBIC_SPLINE:
481 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::CalcPowderPattern()",3);
482 #ifdef USE_BACKGROUND_MAXLIKE_ERROR
488 for(
long i=0;i<nb;i++) {*p++ = var;var +=step;}
493 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::CalcPowderPattern():End",3);
496 void PowderPatternBackground::CalcPowderPattern_FullDeriv(std::set<RefinablePar*> &vPar)
498 TAU_PROFILE(
"PowderPatternBackground::CalcPowderPattern_FullDeriv()",
"void ()",TAU_DEFAULT);
500 mPowderPattern_FullDeriv.clear();
501 if((nb==0)||(mBackgroundNbPoint==0))
return;
502 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
509 const REAL step=(*par)->GetDerivStep();
510 (*par)->Mutate(step);
512 (*par)->Mutate(-2*step);
514 (*par)->Mutate(step);
515 mPowderPattern_FullDeriv[*par]/= step*2;
516 if(MaxAbs(mPowderPattern_FullDeriv[*par])==0)
517 mPowderPattern_FullDeriv[*par].resize(0);
522 void PowderPatternBackground::CalcPowderPatternIntegrated()
const
531 VFN_DEBUG_ENTRY(
"PowderPatternBackground::CalcPowderPatternIntegrated()",3)
532 TAU_PROFILE("PowderPatternBackground::CalcPowderPatternIntegrated()","
void ()",TAU_DEFAULT);
536 const
long numInterval=pMin->numElements();
539 for(
int j=0;j<numInterval;j++)
541 const long max=(*pMax)(j);
544 for(
int k=(*pMin)(j);k<=max;k++) *p2 += *p1++;
547 #ifdef USE_BACKGROUND_MAXLIKE_ERROR
550 for(
int j=0;j<numInterval;j++)
552 const long max=(*pMax)(j);
555 for(
int k=(*pMin)(j);k<=max;k++) *p2 += *p1++;
561 VFN_DEBUG_EXIT(
"PowderPatternBackground::CalcPowderPatternIntegrated()",3)
566 TAU_PROFILE(
"PowderPatternBackground::CalcPowderPatternIntegrated_FullDeriv()",
"void ()",TAU_DEFAULT);
569 mPowderPatternIntegrated_FullDeriv.clear();
570 if((nb==0)||(mBackgroundNbPoint==0))
return;
571 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
578 const REAL step=(*par)->GetDerivStep();
579 (*par)->Mutate(step);
581 (*par)->Mutate(-2*step);
583 (*par)->Mutate(step);
584 mPowderPatternIntegrated_FullDeriv[*par]/= step*2;
585 if(MaxAbs(mPowderPatternIntegrated_FullDeriv[*par])==0)
586 mPowderPatternIntegrated_FullDeriv[*par].resize(0);
590 std::map<RefinablePar*, CrystVector_REAL> newDeriv=mPowderPatternIntegrated_FullDeriv;
592 std::vector<const CrystVector_REAL*> v;
594 for(std::map<RefinablePar*, CrystVector_REAL>::reverse_iterator pos=mPowderPatternIntegrated_FullDeriv.rbegin();pos!=mPowderPatternIntegrated_FullDeriv.rend();++pos)
596 cout<<pos->first->GetName()<<
":"<<pos->second.size()<<
","<<newDeriv[pos->first].size()<<endl;
597 if(pos->second.size()==0)
continue;
598 v.push_back(&(pos->second));
599 v.push_back(&(newDeriv[pos->first]));
602 if(v.size()>0) cout<<
"PowderPatternBackground::CalcPowderPatternIntegrated_FullDeriv():"<<endl<<
FormatVertVector<REAL>(v,12,1,20)<<endl;
623 void PowderPatternBackground::InitRefParList()
628 string str=
"Background_Point_";
635 false,
true,
true,
false,1.);
636 tmp.SetGlobalOptimStep(10.);
638 tmp.SetDerivStep(1e-3);
641 #ifdef USE_BACKGROUND_MAXLIKE_ERROR
645 true,
true,
true,
false,1.);
647 tmp.SetDerivStep(1e-3);
656 void PowderPatternBackground::InitOptions()
658 VFN_DEBUG_MESSAGE(
"PowderPatternBackground::InitOptions()",5)
659 static
string InterpolationModelName;
660 static
string InterpolationModelChoices[2];
662 static
bool needInitNames=true;
663 if(true==needInitNames)
665 InterpolationModelName=
"Interpolation Model";
666 InterpolationModelChoices[0]=
"Linear";
667 InterpolationModelChoices[1]=
"Spline";
678 void PowderPatternBackground::InitSpline()
const
699 CrystVector_REAL ipixel(mBackgroundNbPoint);
713 WXCrystObjBasic* PowderPatternBackground::WXCreate(wxWindow* parent)
716 mpWXCrystObj=
new WXPowderPatternBackground(parent,
this);
725 PowderPatternDiffraction::PowderPatternDiffraction():
726 mpReflectionProfile(0),
727 mCorrLorentz(*this),mCorrPolar(*this),mCorrSlitAperture(*this),
728 mCorrTextureMarchDollase(*this),mCorrTextureEllipsoid(*this),mCorrTOF(*this),mExtractionMode(false),
729 mpLeBailData(0),mFrozenLatticePar(6),mFreezeLatticePar(false),mFrozenBMatrix(3,3)
731 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::PowderPatternDiffraction()",10)
734 this->SetProfile(new ReflectionProfilePseudoVoigt);
735 this->SetIsIgnoringImagScattFact(true);
741 for(
unsigned int i=0;i<3;++i) mFrozenLatticePar(i)=5;
742 for(
unsigned int i=3;i<6;++i) mFrozenLatticePar(i)=M_PI/2;
745 PowderPatternDiffraction::PowderPatternDiffraction(const PowderPatternDiffraction &old):
746 mpReflectionProfile(0),
747 mCorrLorentz(*this),mCorrPolar(*this),mCorrSlitAperture(*this),
748 mCorrTextureMarchDollase(*this),mCorrTextureEllipsoid(*this),mCorrTOF(*this),mExtractionMode(false),
749 mpLeBailData(0),mFrozenLatticePar(6),mFreezeLatticePar(old.FreezeLatticePar()),mFrozenBMatrix(3,3)
753 this->SetIsIgnoringImagScattFact(
true);
754 this->SetProfile(old.mpReflectionProfile->CreateCopy());
756 if(old.mpLeBailData!=0)
758 mpLeBailData=
new DiffractionDataSingleCrystal(
false);
759 *mpLeBailData = *(old.mpLeBailData);
765 for(
unsigned int i=0;i<6;++i) mFrozenLatticePar(i)=old.GetFrozenLatticePar(i);
766 mFrozenBMatrix=old.GetBMatrix();
769 PowderPatternDiffraction::~PowderPatternDiffraction()
771 if(mpReflectionProfile!=0)
774 delete mpReflectionProfile;
779 const static string className=
"PowderPatternDiffraction";
805 pair<const CrystVector_REAL*,const RefinableObjClock*>
808 this->CalcPowderPatternIntegrated();
813 const REAL w,
const REAL u,
const REAL v,
814 const REAL eta0,
const REAL eta1)
816 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::SetReflectionProfilePar()",5)
817 ReflectionProfilePseudoVoigt* p=
new ReflectionProfilePseudoVoigt();
824 if(p==mpReflectionProfile)
return;
825 if(mpReflectionProfile!=0)
828 delete mpReflectionProfile;
830 mpReflectionProfile= p;
837 return *mpReflectionProfile;
842 return *mpReflectionProfile;
846 void PowderPatternDiffraction::GenHKLFullSpace(
847 const REAL maxTheta,
const bool useMultiplicity)
853 void PowderPatternDiffraction::GenHKLFullSpace()
855 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::GenHKLFullSpace():",5)
857 if(this->GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
863 if((mExtractionMode) && (mFhklObsSq.numElements()!=this->GetNbRefl()))
865 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::GenHKLFullSpace(): need to reset observed intensities",7)
866 mFhklObsSq.resize(this->GetNbRefl());
869 mCorrTextureEllipsoid.InitRefParList();
873 const
bool enableRestraints)
875 if(mUseFastLessPreciseFunc!=allowApproximations)
877 mClockProfileCalc.Reset();
878 mClockGeomStructFact.Reset();
879 mClockStructFactor.Reset();
882 mUseFastLessPreciseFunc=allowApproximations;
883 this->GetNbReflBelowMaxSinThetaOvLambda();
890 if(mUseFastLessPreciseFunc==
true)
892 mClockProfileCalc.Reset();
893 mClockGeomStructFact.Reset();
894 mClockStructFactor.Reset();
897 mUseFastLessPreciseFunc=
false;
898 this->GetNbReflBelowMaxSinThetaOvLambda();
905 if(mUseFastLessPreciseFunc!=allow)
907 mClockProfileCalc.Reset();
908 mClockGeomStructFact.Reset();
909 mClockStructFactor.Reset();
912 mUseFastLessPreciseFunc=allow;
913 this->GetNbReflBelowMaxSinThetaOvLambda();
918 CrystVector_uint & groupIndex,
919 unsigned int &first)
const
922 unsigned int index=0;
923 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::GetGeneGroup()",4)
925 for(
long j=0;j<this->
GetNbPar();j++)
930 if(index==0) index=first++;
943 pair<const CrystVector_REAL*,const RefinableObjClock*>
946 this->CalcPowderPatternIntegrated();
958 bool reprep=(mpCrystal!=0);
961 if(mpReflectionProfile!=0)
962 if(mpReflectionProfile->GetClassName()==
"ReflectionProfileDoubleExponentialPseudoVoigt")
977 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::SetExtractionMode(),ExtractionMode="<<mExtractionMode<<
", nbrefl="<<this->GetNbRefl(),7)
978 mExtractionMode=extract;
982 this->FreezeLatticePar(
false);
984 mFhklObsSq.resizeAndPreserve(this->GetNbRefl());
986 if(extract && (!init) && (mpLeBailData!=0))
989 const long nbrefl=this->GetNbReflBelowMaxSinThetaOvLambda();
990 if(nbrefl==mpLeBailData->GetNbRefl())
992 for(
int i=0;i<nbrefl;++i)
994 if( (mpLeBailData->GetH()(i)==this->GetH()(i))
995 &&(mpLeBailData->GetK()(i)==this->GetK()(i))
996 &&(mpLeBailData->GetL()(i)==this->GetL()(i)))
998 mFhklObsSq(i)=mpLeBailData->GetFhklObsSq()(i);
1003 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::SetExtractionMode():: Forcing initialize, cannot re-use: hkl list differs",10);
1012 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::SetExtractionMode():: Forcing initialize, cannot re-use: different number of reflections",10);
1015 if((extract && init) || needInit)
1017 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::SetExtractionMode():: Initializing intensities to 100",10);
1020 if((mExtractionMode==
false)&&(mFhklObsSq.numElements()>0))
1022 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::SetExtractionMode(),LEAVING Le Bail Mode",7)
1025 mpLeBailData->SetWavelength(this->GetRadiation().GetWavelength()(0));
1026 mpLeBailData->SetRadiationType(this->GetRadiation().GetRadiationType());
1029 mpLeBailData->SetName(
string(buf)+this->GetCrystal().
GetName());
1031 const unsigned long nbrefl=this->GetNbReflBelowMaxSinThetaOvLambda();
1032 CrystVector_REAL iobs(nbrefl),sigma(nbrefl);
1033 CrystVector_long h(nbrefl),k(nbrefl),l(nbrefl);
1035 for(
unsigned long i=0;i<nbrefl;++i)
1040 iobs(i)=mFhklObsSq(i);
1042 mpLeBailData->SetHklIobs(h,k,l,iobs,sigma);
1044 mFhklObsSq.resize(0);
1047 mClockFhklObsSq.Click();
1048 VFN_DEBUG_EXIT(
"PowderPatternDiffraction::SetExtractionMode(),ExtractionMode="<<mExtractionMode<<
", nbrefl="<<this->GetNbRefl(),7)
1055 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::ExtractLeBail()",7)
1056 TAU_PROFILE(
"PowderPatternDiffraction::ExtractLeBail()",
"void (int)",TAU_DEFAULT);
1058 if(mExtractionMode==
false) this->SetExtractionMode(
true,
true);
1059 if(mFhklObsSq.numElements()!=this->GetNbRefl())
1061 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::ExtractLeBail() mFhklObsSq.size() != NbRefl !!!!!!",7)
1062 mFhklObsSq.resize(this->GetNbRefl());
1066 CrystVector_REAL obs,iextract,calc;
1067 iextract=mFhklObsSq;
1069 mClockFhklObsSq.Click();
1073 mFhklObsSq=iextract;
1074 mClockFhklObsSq.Click();
1080 for(;nbcycle>0;nbcycle--)
1084 for(
unsigned int k0=0;k0<nbrefl;++k0)
1088 long last=mvReflProfile[k0].last,first;
1090 if(mvReflProfile[k0].first<0)first=0;
1091 else first=(mvReflProfile[k0].first);
1092 const REAL *p1=mvReflProfile[k0].profile.data()+(first-mvReflProfile[k0].first);
1093 const REAL *p2=calc.data()+first;
1094 const REAL *pobs=obs.data()+first;
1095 for(
unsigned int i=first;i<=last;++i)
1097 const REAL s2=*p2++;
1098 const REAL tmp=*pobs++ * *p1++;
1107 if((s1>1e-8)&&(!
ISNAN_OR_INF(s1))) iextract(k0)=s1*mFhklObsSq(k0);
1108 else iextract(k0)=1e-8;
1111 mFhklObsSq=iextract;
1112 if(this->GetCrystal().GetScatteringComponentList().GetNbComponent()>0)
1114 const REAL* p1=this->GetFhklCalcSq() .data();
1115 const REAL* p2=mFhklObsSq.data();
1117 for(
long i=nbrefl;i>0;i--)
1119 tmp1 += (*p1) * (*p2++);
1120 tmp2 += (*p1) * (*p1);
1124 mFhklObsSq*=tmp2/tmp1;
1126 mClockFhklObsSq.Click();
1132 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::ExtractLeBail(): creating single crystal extracted data",7)
1133 CrystVector_REAL iobs(nbrefl),sigma(nbrefl);
1134 CrystVector_long h(nbrefl),k(nbrefl),l(nbrefl);
1136 for(
unsigned long i=0;i<nbrefl;++i)
1141 iobs(i)=mFhklObsSq(i);
1143 mpLeBailData->SetHklIobs(h,k,l,iobs,sigma);
1145 VFN_DEBUG_EXIT(
"PowderPatternDiffraction::ExtractLeBail()mFhklObsSq.size()=="<<mFhklObsSq.numElements(),7)
1150 VFN_DEBUG_MESSAGE(
"PowderPattern::GetNbReflBelowMaxSinThetaOvLambda()",4)
1151 this->CalcPowderReflProfile();
1153 if((mNbReflUsed>0)&&(mNbReflUsed<mNbRefl))
1155 if( (mvReflProfile[mNbReflUsed ].first>nbpoint)
1156 &&(mvReflProfile[mNbReflUsed-1].first<=nbpoint))
return mNbReflUsed;
1159 if((mNbReflUsed==mNbRefl) && (mvReflProfile[mNbReflUsed-1].profile.numElements()>0))
1160 if(mvReflProfile[mNbReflUsed-1].first<=nbpoint)
return mNbReflUsed;
1164 for(i=0;i<mNbRefl;i++)
1166 if(mvReflProfile[i].first>nbpoint)
break;
1171 mClockNbReflUsed.Click();
1173 <<
" nb refl="<<mNbReflUsed,4)
1180 const REAL old=mFrozenLatticePar(i);
1181 cout<<
"PowderPatternDiffraction::SetFrozenLatticePar("<<i<<
":"<<v<<
")"<<endl;
1183 mFrozenLatticePar(i)=v;
1184 this->CalcFrozenBMatrix();
1191 cout<<
"PowderPatternDiffraction::FreezeLatticePar("<<use<<
")"<<endl;
1192 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::FreezeLatticePar("<<use<<
")", 10)
1193 if(use==mFreezeLatticePar)
return;
1194 mFreezeLatticePar=use;
1195 mFrozenLatticePar=this->GetCrystal().GetLatticePar();
1196 if(use) this->CalcFrozenBMatrix();
1197 mClockTheta.Reset();
1205 this->GetNbReflBelowMaxSinThetaOvLambda();
1207 TAU_PROFILE(
"PowderPatternDiffraction::CalcPowderPattern()-Apply profiles",
"void (bool)",TAU_DEFAULT);
1209 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::CalcPowderPattern():",3)
1219 this->CalcPowderReflProfile();
1226 const long nbRefl=this->GetNbRefl();
1227 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderPattern\
1228 Applying profiles for "<<nbRefl<<
" reflections",2)
1233 const bool useML= (mIhklCalcVariance.numElements() != 0);
1240 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderPattern() Has variance:"<<useML,2)
1242 for(
long i=0;i<mNbRefl;i += step)
1244 if(mvReflProfile[i].profile.numElements()==0)
1247 if(i>=mNbReflUsed)
break;
1251 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderPattern()#"<<i,2)
1258 intensity += mIhklCalc(i + step);
1259 if(useML) var += mIhklCalcVariance(i + step);
1261 if(mpReflectionProfile->IsAnisotropic())
break;
1262 if( (i+step) >= nbRefl)
break;
1263 if(mSinThetaLambda(i+step) > (mSinThetaLambda(i)+1e-5) )
break;
1265 VFN_DEBUG_MESSAGE(
"Apply profile(Monochromatic)Refl("<<i<<
")"\
1266 <<mIntH(i)<<
" "<<mIntK(i)<<
" "<<mIntL(i)<<
" "\
1267 <<
" I="<<intensity<<
" stol="<<mSinThetaLambda(i)\
1268 <<
",pixel #"<<mvReflProfile[i].first<<
"->"<<mvReflProfile[i].last,2)
1270 const unsigned long first=mvReflProfile[i].first,last=mvReflProfile[i].last;
1271 const REAL *p2 = mvReflProfile[i].profile.data();
1273 for(
unsigned long j=first;j<=last;j++) *p3++ += *p2++ * intensity;
1276 const REAL *p2 = mvReflProfile[i].profile.data();
1278 for(
unsigned long j=first;j<=last;j++) *p3++ += *p2++ * var;
1287 FAST option not yet implemented !");
1290 VFN_DEBUG_EXIT(
"PowderPatternDiffraction::CalcPowderPattern: End.",3)
1293 void PowderPatternDiffraction::CalcPowderPattern_FullDeriv(std::set<RefinablePar*> &vPar)
1295 TAU_PROFILE(
"PowderPatternDiffraction::CalcPowderPattern_FullDeriv()",
"void ()",TAU_DEFAULT);
1298 bool notYetDerivProfiles=
true;
1299 mIhkl_FullDeriv.clear();
1300 mvReflProfile_FullDeriv.clear();
1301 mPowderPattern_FullDeriv.clear();
1302 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
1304 if(*par==0)
continue;
1305 if((*par)->IsFixed())
continue;
1306 if((*par)->IsUsed()==
false)
continue;
1307 if( (*par)->GetType()->IsDescendantFromOrSameAs(gpRefParTypeScatt)
1308 ||(*par)->GetType()->IsDescendantFromOrSameAs(gpRefParTypeScattPow))
1310 this->CalcIhkl_FullDeriv(vPar);
1312 if(notYetDerivProfiles)
1314 if( (*par)->GetType()->IsDescendantFromOrSameAs(gpRefParTypeRadiation)
1315 ||(*par)->GetType()->IsDescendantFromOrSameAs(gpRefParTypeUnitCell)
1319 this->CalcPowderReflProfile_FullDeriv(vPar);
1320 notYetDerivProfiles=
false;
1326 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
1331 if((*par)->IsFixed())
continue;
1332 if((*par)->IsUsed()==
false)
continue;
1333 if(mIhkl_FullDeriv[*par].size()!=0)
1335 const long nbRefl=this->GetNbRefl();
1338 mPowderPattern_FullDeriv[*par].resize(specNbPoints);
1339 mPowderPattern_FullDeriv[*par]=0;
1341 for(
long i=0;i<mNbReflUsed;i += step)
1343 if(mvReflProfile[i].profile.numElements()==0)
1346 if(i>=mNbReflUsed)
break;
1355 intensity += mIhkl_FullDeriv[*par](i + step);
1357 if(mpReflectionProfile->IsAnisotropic())
break;
1358 if( (i+step) >= nbRefl)
break;
1359 if(mSinThetaLambda(i+step) > (mSinThetaLambda(i)+1e-5) )
break;
1362 const unsigned long first=mvReflProfile[i].first,last=mvReflProfile[i].last;
1363 const REAL *p2 = mvReflProfile[i].profile.data();
1364 REAL *p3 = mPowderPattern_FullDeriv[*par].data()+first;
1365 for(
unsigned long j=first;j<=last;j++) *p3++ += *p2++ * intensity;
1369 if(mvReflProfile_FullDeriv[*par].size()!=0)
1371 const long nbRefl=this->GetNbRefl();
1374 mPowderPattern_FullDeriv[*par].resize(specNbPoints);
1375 mPowderPattern_FullDeriv[*par]=0;
1376 cout<<__FILE__<<
":"<<__LINE__<<
":PowderPatternDiffraction::CalcPowderPattern_FullDeriv():par="<<(*par)->GetName()<<endl;
1377 for(
long i=0;i<mNbReflUsed;i += step)
1379 if(mvReflProfile[i].profile.numElements()==0)
1382 if(i>=mNbReflUsed)
break;
1391 intensity += mIhklCalc(i + step);
1393 if(mpReflectionProfile->IsAnisotropic())
break;
1394 if( (i+step) >= nbRefl)
break;
1395 if(mSinThetaLambda(i+step) > (mSinThetaLambda(i)+1e-5) )
break;
1397 if(mvReflProfile_FullDeriv[*par][i].size()>0)
1399 const unsigned long first=mvReflProfile[i].first,last=mvReflProfile[i].last;
1400 const REAL *p2 = mvReflProfile_FullDeriv[*par][i].data();
1401 REAL *p3 = mPowderPattern_FullDeriv[*par].data()+first;
1402 for(
unsigned long j=first;j<=last;j++) *p3++ += *p2++ * intensity;
1409 std::map<RefinablePar*, CrystVector_REAL> newDeriv=mPowderPattern_FullDeriv;
1410 this->PowderPatternComponent::CalcPowderPattern_FullDeriv(vPar);
1411 std::vector<const CrystVector_REAL*> v;
1413 for(std::map<RefinablePar*, CrystVector_REAL>::reverse_iterator pos=mPowderPattern_FullDeriv.rbegin();pos!=mPowderPattern_FullDeriv.rend();++pos)
1415 if(pos->first==0)
continue;
1416 if(pos->second.size()==0)
continue;
1417 v.push_back(&(newDeriv[pos->first]));
1418 v.push_back(&(pos->second));
1419 cout<<pos->first->GetName()<<
":"<<pos->second.size()<<
","<<newDeriv[pos->first].size()<<endl;
1422 cout<<FormatVertVector<REAL>(v,16,4,1000)<<endl;
1427 void PowderPatternDiffraction::CalcPowderPatternIntegrated()
const
1429 this->GetNbReflBelowMaxSinThetaOvLambda();
1431 TAU_PROFILE(
"PowderPatternDiffraction::CalcPowderPatternIntegrated()",
"void (bool)",TAU_DEFAULT);
1432 TAU_PROFILE_TIMER(timer1,
"PowderPatternDiffraction::CalcPowderPatternIntegrated()1",
"", TAU_FIELD);
1433 TAU_PROFILE_TIMER(timer2,
"PowderPatternDiffraction::CalcPowderPatternIntegrated()2",
"", TAU_FIELD);
1436 TAU_PROFILE_START(timer1);
1437 this->PrepareIntegratedProfile();
1438 TAU_PROFILE_STOP(timer1);
1444 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::CalcPowderPatternIntegrated()",3)
1445 const
long nbRefl=this->GetNbRefl();
1450 const
bool useML= (mIhklCalcVariance.numElements() != 0);
1457 const REAL * RESTRICT psith=mSinThetaLambda.data();
1458 const REAL * RESTRICT pI=mIhklCalc.data();
1459 const REAL * RESTRICT pIvar=mIhklCalcVariance.data();
1460 vector< pair<unsigned long, CrystVector_REAL> >::const_iterator pos;
1461 pos=mIntegratedProfileFactor.begin();
1462 TAU_PROFILE_START(timer2);
1463 for(
long i=0;i<mNbReflUsed;)
1465 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderPatternIntegrated():"<<i,2)
1468 const REAL thmax=*psith+1e-5;
1474 if(useML) var += *pIvar++;
1475 if( ++i >= nbRefl)
break;
1476 if( *(++psith) > thmax )
break;
1477 if(mpReflectionProfile->IsAnisotropic())
break;
1480 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderPatternIntegrated():"<<i,2)
1482 const REAL * RESTRICT pFact=pos->second.data();
1483 const
unsigned long nb=pos->second.numElements();
1485 for(
unsigned long j=nb;j>0;j--)
1488 *pData++ += intensity * *pFact++ ;
1494 const REAL * RESTRICT pFact=pos->second.data();
1496 for(
unsigned long j=nb;j>0;j--) *pVar++ += var * *pFact++ ;
1500 TAU_PROFILE_STOP(timer2);
1502 if(gVFNDebugMessageLevel<3)
1505 CrystVector_REAL integr(nb),min(nb),max(nb),diff(nb),index(nb);
1507 for(
long i=0;i<nb;i++)
1520 cout <<
"Integrated intensities, Component"<<endl
1526 VFN_DEBUG_EXIT(
"PowderPatternDiffraction::CalcPowderPatternIntegrated",3)
1531 TAU_PROFILE(
"PowderPatternDiffraction::CalcPowderPatternIntegrated_FullDeriv()",
"void ()",TAU_DEFAULT);
1536 this->CalcPowderPatternIntegrated();
1537 this->CalcIhkl_FullDeriv(vPar);
1538 const long nbRefl=this->GetNbRefl();
1540 #ifdef PowderPatternDiffraction_CalcPowderPatternIntegrated_FullDerivDEBUG
1542 std::map<RefinablePar*, CrystVector_REAL> oldDeriv=mPowderPatternIntegrated_FullDeriv;
1546 mPowderPatternIntegrated_FullDeriv.clear();
1547 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
1552 if(mIhkl_FullDeriv[*par].size()==0)
continue;
1553 if(mPowderPatternIntegrated_FullDeriv[*par].size()==0)
1555 mPowderPatternIntegrated_FullDeriv[*par].resize(nbprof);
1556 mPowderPatternIntegrated_FullDeriv[*par]=0;
1558 const REAL * RESTRICT psith=mSinThetaLambda.data();
1559 const REAL * RESTRICT pI=mIhkl_FullDeriv[*par].data();
1562 vector< pair<unsigned long, CrystVector_REAL> >::const_iterator pos=mIntegratedProfileFactor.begin();
1564 for(
long i=0;i<mNbReflUsed;)
1567 const REAL thmax=*psith+1e-5;
1571 if( ++i >= nbRefl)
break;
1572 if( *(++psith) > thmax )
break;
1573 if(mpReflectionProfile->IsAnisotropic())
break;
1576 REAL * RESTRICT pData=mPowderPatternIntegrated_FullDeriv[*par].data()+pos->first;
1577 const REAL * RESTRICT pFact=pos->second.data();
1578 const unsigned long nb=pos->second.numElements();
1579 #ifdef PowderPatternDiffraction_CalcPowderPatternIntegrated_FullDerivDEBUG
1580 if((i<5)&&(ctpar<8)) cout<<__FILE__<<
":"<<__LINE__<<
":"<<(*par)->GetName()<<
"i="<<setw(16)<<i<<
":I="<<setw(16)<<intensity<<endl;
1582 for(
unsigned long j=nb;j>0;j--)
1584 #ifdef PowderPatternDiffraction_CalcPowderPatternIntegrated_FullDerivDEBUG
1585 *pData += intensity * *pFact ;
1586 if((i<5)&&((*par)->GetName()==
"Cimetidine_C11_x")&&(pos->first==0)&&(nb==j)) cout<<nb-j<<
" SUM1"<<setw(16)<<*pData<<
", dI="<<setw(16)<<intensity<<
", prof="<<setw(16)<<*pFact<<endl;
1589 *pData++ += intensity * *pFact++ ;
1597 #ifdef PowderPatternDiffraction_CalcPowderPatternIntegrated_FullDerivDEBUG
1598 std::vector<const CrystVector_REAL*> v;
1600 cout<<
"PowderPatternDiffraction::CalcPowderPatternIntegrated_FullDeriv():parameters:"<<endl;
1601 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
1603 if(mPowderPatternIntegrated_FullDeriv[*par].size()==0)
continue;
1604 v.push_back(&(mPowderPatternIntegrated_FullDeriv[*par]));
1605 v.push_back(&(oldDeriv[*par]));
1606 cout<<(*par)->GetName()<<
":"<<mPowderPatternIntegrated_FullDeriv[*par].size()<<
","<<oldDeriv[*par].size()<<endl;
1609 cout<<
"PowderPatternDiffraction::CalcPowderPatternIntegrated_FullDeriv():"<<endl<<FormatVertVector<REAL>(v,12,1,20)<<endl;
1616 this->CalcSinThetaLambda();
1618 if( (mClockProfileCalc>mClockProfilePar)
1619 &&(mClockProfileCalc>mpReflectionProfile->GetClockMaster())
1620 &&(mClockProfileCalc>mClockTheta)
1621 &&(mClockProfileCalc>this->GetRadiation().GetClockWavelength())
1623 &&(mClockProfileCalc>mClockHKL)
1626 TAU_PROFILE(
"PowderPatternDiffraction::CalcPowderReflProfile()",
"void (bool)",TAU_DEFAULT);
1627 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::CalcPowderReflProfile()",5)
1633 unsigned int nbLine=1;
1634 CrystVector_REAL spectrumDeltaLambdaOvLambda;
1635 CrystVector_REAL spectrumFactor;
1636 switch(this->GetRadiation().GetWavelengthType())
1638 case WAVELENGTH_MONOCHROMATIC:
1640 spectrumDeltaLambdaOvLambda.resize(1);spectrumDeltaLambdaOvLambda=0.0;
1641 spectrumFactor.resize(1);spectrumFactor=1.0;
1644 case WAVELENGTH_ALPHA12:
1647 spectrumDeltaLambdaOvLambda.resize(2);
1648 spectrumDeltaLambdaOvLambda(0)
1649 =-this->GetRadiation().GetXRayTubeDeltaLambda()
1650 *this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio()
1651 /(1+this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio())
1652 /this->GetRadiation().GetWavelength()(0);
1653 spectrumDeltaLambdaOvLambda(1)
1654 = this->GetRadiation().GetXRayTubeDeltaLambda()
1655 /(1+this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio())
1656 /this->GetRadiation().GetWavelength()(0);
1658 spectrumFactor.resize(2);
1659 spectrumFactor(0)=1./(1.+this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio());
1660 spectrumFactor(1)=this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio()
1661 /(1.+this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio());
1664 case WAVELENGTH_TOF:
1666 spectrumDeltaLambdaOvLambda.resize(1);spectrumDeltaLambdaOvLambda=0.0;
1667 spectrumFactor.resize(1);spectrumFactor=1.0;
1670 default:
throw ObjCrystException(
"PowderPatternDiffraction::PrepareIntegratedProfile():\
1671 Radiation must be either monochromatic, from an X-Ray Tube, or neutron TOF !!");
1675 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderReflProfile():\
1676 Computing all Profiles",5)
1680 CrystVector_REAL vx,reflProfile,tmpV;
1681 mvReflProfile.resize(this->GetNbRefl());
1682 for(
unsigned int i=0;i<this->GetNbRefl();i++)
1684 mvReflProfile[i].first=0;
1685 mvReflProfile[i].last=0;
1686 mvReflProfile[i].profile.resize(0);
1688 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderReflProfile()",5)
1690 for(
unsigned int line=0;line<nbLine;line++)
1692 for(
long i=0;i<this->GetNbRefl();i++)
1694 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::CalcPowderReflProfile()#"<<i,5)
1697 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderReflProfile()#"<<i,5)
1701 x0+2*tan(x0/2.0)*spectrumDeltaLambdaOvLambda(line));
1705 if(!mUseFastLessPreciseFunc) fact=5.0;
1706 const REAL halfwidth=mpReflectionProfile->GetFullProfileWidth(0.04,center,mH(i),mK(i),mL(i))*fact;
1711 label<<mIntH(i)<<
" "<<mIntK(i)<<
" "<<mIntL(i);
1712 mvLabel.push_back(make_pair(center,label.str()));
1713 REAL spectrumwidth=0.0;
1714 if(this->GetRadiation().GetWavelengthType()==WAVELENGTH_ALPHA12)
1716 spectrumwidth=2*this->GetRadiation().GetXRayTubeDeltaLambda()
1717 /this->GetRadiation().GetWavelength()(0)*tan(x0/2.0);
1721 if(this->GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
1729 cout<<
"PowderPatternDiffraction::CalcPowderReflProfile(), line"<<__LINE__<<
"first>last !! :"<<first<<
","<<last<<endl;
1730 first=(first+last)/2;
1735 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderReflProfile():"<<first<<
","<<last<<
","<<center,3)
1738 cout<<__FILE__<<__LINE__<<endl;
1743 if(first<0) first=0;
1746 vx.resize(last-first+1);
1749 mvReflProfile[i].first=first;
1750 mvReflProfile[i].last=last;
1754 first=mvReflProfile[i].first;
1755 last=mvReflProfile[i].last;
1757 vx.resize(last-first+1);
1759 vx.resize(last-first+1);
1766 for(
long i=first;i<=last;i++) *p1++ = *p0++;
1769 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderReflProfile():"<<first<<
","<<last<<
","<<center,3)
1770 reflProfile=mpReflectionProfile->GetProfile(vx,center,mH(i),mK(i),mL(i));
1771 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcPowderReflProfile()",2)
1772 if(nbLine>1) reflProfile *=spectrumFactor(line);
1773 if(line==0) mvReflProfile[i].profile = reflProfile;
1774 else mvReflProfile[i].profile += reflProfile;
1778 mvReflProfile[i].profile.resize(0);
1780 VFN_DEBUG_EXIT(
"PowderPatternDiffraction::CalcPowderReflProfile():\
1781 Computing all Profiles: Reflection #"<<i,5)
1785 mClockProfileCalc.Click();
1786 VFN_DEBUG_EXIT(
"PowderPatternDiffraction::CalcPowderReflProfile()",5)
1791 TAU_PROFILE(
"PowderPatternDiffraction::CalcPowderReflProfile_FullDeriv()",
"void (bool)",TAU_DEFAULT);
1792 cout<<__FILE__<<
":"<<__LINE__<<
":PowderPatternDiffraction::CalcPowderReflProfile_FullDeriv()"<<endl;
1793 this->CalcPowderReflProfile();
1794 unsigned int nbLine=1;
1795 CrystVector_REAL spectrumDeltaLambdaOvLambda;
1796 CrystVector_REAL spectrumFactor;
1797 switch(this->GetRadiation().GetWavelengthType())
1799 case WAVELENGTH_MONOCHROMATIC:
1801 spectrumDeltaLambdaOvLambda.resize(1);spectrumDeltaLambdaOvLambda=0.0;
1802 spectrumFactor.resize(1);spectrumFactor=1.0;
1805 case WAVELENGTH_ALPHA12:
1808 spectrumDeltaLambdaOvLambda.resize(2);
1809 spectrumDeltaLambdaOvLambda(0)
1810 =-this->GetRadiation().GetXRayTubeDeltaLambda()
1811 *this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio()
1812 /(1+this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio())
1813 /this->GetRadiation().GetWavelength()(0);
1814 spectrumDeltaLambdaOvLambda(1)
1815 = this->GetRadiation().GetXRayTubeDeltaLambda()
1816 /(1+this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio())
1817 /this->GetRadiation().GetWavelength()(0);
1819 spectrumFactor.resize(2);
1820 spectrumFactor(0)=1./(1.+this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio());
1821 spectrumFactor(1)=this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio()
1822 /(1.+this->GetRadiation().GetXRayTubeAlpha2Alpha1Ratio());
1825 case WAVELENGTH_TOF:
1827 spectrumDeltaLambdaOvLambda.resize(1);spectrumDeltaLambdaOvLambda=0.0;
1828 spectrumFactor.resize(1);spectrumFactor=1.0;
1831 default:
throw ObjCrystException(
"PowderPatternDiffraction::CalcPowderReflProfile_FullDeriv():\
1832 Radiation must be either monochromatic, from an X-Ray Tube, or neutron TOF !!");
1837 CrystVector_REAL vx,reflProfile,tmpV;
1840 vector<CrystVector_REAL> vReflProfile_DerivCenter(mNbReflUsed);
1842 mvReflProfile_FullDeriv.clear();
1843 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
1845 if(*par==0)
continue;
1846 if( (*par)->GetType()->IsDescendantFromOrSameAs(gpRefParTypeRadiation)
1847 ||(*par)->GetType()->IsDescendantFromOrSameAs(gpRefParTypeUnitCell)
1851 mvReflProfile_FullDeriv[*par].resize(mNbReflUsed);
1853 for(
unsigned int line=0;line<nbLine;line++)
1855 for(
long i=0;i<mNbReflUsed;i++)
1862 x0+2*tan(x0/2.0)*spectrumDeltaLambdaOvLambda(line));
1866 if(!mUseFastLessPreciseFunc) fact=5.0;
1868 first=mvReflProfile[i].first;
1869 last=mvReflProfile[i].last;
1871 vx.resize(last-first+1);
1873 vx.resize(last-first+1);
1879 for(
long i=first;i<=last;i++) *p1++ = *p0++;
1886 const REAL step=(*par)->GetDerivStep();
1887 (*par)->Mutate(step);
1888 reflProfile=mpReflectionProfile->GetProfile(vx,center,mH(i),mK(i),mL(i));
1889 (*par)->Mutate(-2*step);
1890 reflProfile-=mpReflectionProfile->GetProfile(vx,center,mH(i),mK(i),mL(i));
1891 (*par)->Mutate(step);
1892 reflProfile/=2*step;
1899 const REAL step=(*par)->GetDerivStep();
1900 (*par)->Mutate(step);
1904 (*par)->Mutate(-2*step);
1908 (*par)->Mutate(step);
1915 if(vReflProfile_DerivCenter[i].size()==0)
1917 const REAL step=1e-4;
1918 vReflProfile_DerivCenter[i] =mpReflectionProfile->GetProfile(vx,center+step,mH(i),mK(i),mL(i));
1919 vReflProfile_DerivCenter[i]-=mpReflectionProfile->GetProfile(vx,center-step,mH(i),mK(i),mL(i));
1920 vReflProfile_DerivCenter[i]/=2*step;
1922 reflProfile=vReflProfile_DerivCenter[i];
1923 reflProfile*=dcenter;
1928 reflProfile.resize(0);
1931 if(reflProfile.size()>0)
1933 if(nbLine>1) reflProfile *=spectrumFactor(line);
1934 if(line==0) mvReflProfile_FullDeriv[*par][i] = reflProfile;
1935 else mvReflProfile_FullDeriv[*par][i] += reflProfile;
1946 bool needRecalc=
false;
1948 this->CalcSinThetaLambda();
1949 if((mClockIntensityCorr<mClockTheta)||(mClockIntensityCorr<this->GetClockNbReflBelowMaxSinThetaOvLambda())) needRecalc=
true;
1951 const CrystVector_REAL *mpCorr[5] = {0, 0, 0, 0, 0};
1953 if(this->GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
1955 mpCorr[0]=&(mCorrTOF.GetCorr());
1956 if(mClockIntensityCorr<mCorrTOF.GetClockCorr()) needRecalc=
true;
1960 mpCorr[0]=&(mCorrLorentz.GetCorr());
1961 if(mClockIntensityCorr<mCorrLorentz.GetClockCorr()) needRecalc=
true;
1963 if(this->GetRadiation().GetRadiationType()==RAD_XRAY)
1965 mpCorr[1]=&(mCorrPolar.GetCorr());
1966 if(mClockIntensityCorr<mCorrPolar.GetClockCorr()) needRecalc=
true;
1969 mpCorr[2]=&(mCorrSlitAperture.GetCorr());
1970 if(mClockIntensityCorr<mCorrSlitAperture.GetClockCorr()) needRecalc=
true;
1973 if(mCorrTextureMarchDollase.GetNbPhase()>0)
1975 mpCorr[3]=&(mCorrTextureMarchDollase.GetCorr());
1976 if(mClockIntensityCorr<mCorrTextureMarchDollase.GetClockCorr()) needRecalc=
true;
1978 mpCorr[4]=&(mCorrTextureEllipsoid.GetCorr());
1979 if(mClockIntensityCorr<mCorrTextureEllipsoid.GetClockCorr()) needRecalc=
true;
1982 if(needRecalc==
false)
return;
1984 TAU_PROFILE(
"PowderPatternDiffraction::CalcIntensityCorr()",
"void ()",TAU_DEFAULT);
1985 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcIntensityCorr()",2)
1986 mIntensityCorr.resize(mNbRefl);
1987 REAL *pCorr=mIntensityCorr.data();
1988 const REAL *p=mpCorr[0]->data();
1989 for(
long i=mNbReflUsed;i>0;i--) *pCorr++ = *p++;
1990 if(this->GetRadiation().GetWavelengthType()!=WAVELENGTH_TOF)
1992 if(this->GetRadiation().GetRadiationType()==RAD_XRAY)
1994 pCorr=mIntensityCorr.data();
1995 p=mpCorr[1]->data();
1996 const REAL* p2=mpCorr[2]->data();
1997 for(
long i=mNbReflUsed;i>0;i--) *pCorr++ *= *p++ * *p2++;
2001 pCorr=mIntensityCorr.data();
2002 p=mpCorr[2]->data();
2003 for(
long i=mNbReflUsed;i>0;i--) *pCorr++ *= *p++;
2006 if(mCorrTextureMarchDollase.GetNbPhase()>0)
2008 pCorr=mIntensityCorr.data();
2009 p=mpCorr[3]->data();
2010 for(
long i=mNbReflUsed;i>0;i--) *pCorr++ *= *p++;
2012 if(mpCorr[4]->numElements()>0)
2014 pCorr=mIntensityCorr.data();
2015 p=mpCorr[4]->data();
2016 for(
long i=mNbReflUsed;i>0;i--) *pCorr++ *= *p++;
2018 mClockIntensityCorr.Click();
2019 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcIntensityCorr():finished",2)
2024 this->CalcIntensityCorr();
2025 if(mExtractionMode==
true)
2027 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcIhkl():"<<mFhklObsSq.numElements()<<
","<<mIntensityCorr.numElements()<<
","<<mMultiplicity.numElements(),7);
2028 mIhklCalc=mFhklObsSq;
2029 mIhklCalc*=mIntensityCorr;
2030 mIhklCalc*=mMultiplicity;
2031 mClockIhklCalc.Click();
2034 this->CalcStructFactor();
2035 if( (mClockIhklCalc>mClockIntensityCorr)
2036 &&(mClockIhklCalc>mClockStructFactor)
2037 &&(mClockIhklCalc>mClockNbReflUsed))
return;
2039 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcIhkl()",3)
2040 TAU_PROFILE(
"PowderPatternDiffraction::CalcIhkl()",
"void ()",TAU_DEFAULT);
2041 const REAL * RESTRICT pr,* RESTRICT pi,* RESTRICT pcorr;
2042 const int * RESTRICT mult;
2045 pr=mFhklCalcReal.data();
2046 pi=mFhklCalcImag.data();
2047 pcorr=mIntensityCorr.data();
2049 mult=mMultiplicity.data();
2050 mIhklCalc.resize(mNbRefl);
2052 if(mFhklCalcVariance.numElements()>0)
2054 const REAL * RESTRICT pv=mFhklCalcVariance.data();
2055 for(
long i=mNbReflUsed;i>0;i--)
2057 *p++ = *mult++ * (*pr * *pr + *pi * *pi + 2 * *pv++) * *pcorr++;
2064 for(
long i=mNbReflUsed;i>0;i--)
2066 *p++ = *mult++ * (*pr * *pr + *pi * *pi) * *pcorr++;
2071 if(mFhklCalcVariance.numElements()==0)
2073 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcIhkl(): No Calc Variance",2)
2074 mIhklCalcVariance.resize(0);
2075 VFN_DEBUG_MESSAGE(endl<<
2085 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcIhkl(): Calc Variance",2)
2086 mIhklCalcVariance.resize(mNbRefl);
2087 REAL * RESTRICT pVar2=mIhklCalcVariance.data();
2089 const REAL * RESTRICT pInt=mIhklCalc.data();
2090 const REAL * RESTRICT pVar=mFhklCalcVariance.data();
2091 pcorr=mIntensityCorr.data();
2092 mult=mMultiplicity.data();
2094 for(
long j=mNbReflUsed;j>0;j--)
2096 *pVar2++ = (4* *mult) * *pcorr * *pVar *(*pInt++ - (*mult * *pcorr) * *pVar);
2097 pVar++;mult++;pcorr++;
2099 VFN_DEBUG_MESSAGE(endl<<
2103 mExpectedIntensityFactor,
2106 mvLuzzatiFactor[&(mpCrystal->GetScatteringPowerRegistry().GetObj(0))],
2108 mIhklCalcVariance),2);
2109 VFN_DEBUG_MESSAGE(mNbRefl<<
" "<<mNbReflUsed,2)
2114 mClockIhklCalc.Click();
2115 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcIhkl():End",3)
2118 void PowderPatternDiffraction::CalcIhkl_FullDeriv(std::set<RefinablePar*> &vPar)
2120 TAU_PROFILE(
"PowderPatternDiffraction::CalcIhkl_FullDeriv()",
"void ()",TAU_DEFAULT);
2122 this->CalcIntensityCorr();
2123 mIhkl_FullDeriv.clear();
2124 if(mExtractionMode==
true)
2129 this->CalcStructFactor_FullDeriv(vPar);
2131 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
2133 if(*par==0) mIhkl_FullDeriv[*par]=mIhklCalc;
2136 if(mFhklCalcReal_FullDeriv[*par].size()==0)
continue;
2137 const REAL * RESTRICT pr,* RESTRICT pi,* RESTRICT prd,* RESTRICT pid,* RESTRICT pcorr;
2138 const int * RESTRICT mult;
2141 pr=mFhklCalcReal.data();
2142 pi=mFhklCalcImag.data();
2143 prd=mFhklCalcReal_FullDeriv[*par].data();
2144 pid=mFhklCalcImag_FullDeriv[*par].data();
2145 pcorr=mIntensityCorr.data();
2147 mult=mMultiplicity.data();
2148 mIhkl_FullDeriv[*par].resize(mNbRefl);
2149 p=mIhkl_FullDeriv[*par].data();
2150 if(mFhklCalcImag_FullDeriv[*par].size()==0)
2151 for(
long i=mNbReflUsed;i>0;i--) *p++ = *mult++ * 2 * *pr++ * *prd++ * *pcorr++;
2153 for(
long i=mNbReflUsed;i>0;i--) *p++ = *mult++ * 2 *(*pr++ * *prd++ + *pi++ * *pid++) * *pcorr++;
2157 std::map<RefinablePar*, CrystVector_REAL> oldDeriv;
2158 std::vector<const CrystVector_REAL*> v;
2165 v.push_back(&mIntensityCorr);
2167 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
2169 if((*par)==0)
continue;
2170 if(mIhkl_FullDeriv[*par].size()==0)
continue;
2172 const REAL step=(*par)->GetDerivStep();
2173 (*par)->Mutate(step);
2175 oldDeriv[*par]=mIhklCalc;
2176 (*par)->Mutate(-2*step);
2178 oldDeriv[*par]-=mIhklCalc;
2179 oldDeriv[*par]/=2*step;
2180 (*par)->Mutate(step);
2182 v.push_back(&(mIhkl_FullDeriv[*par]));
2183 v.push_back(&(oldDeriv[*par]));
2184 cout<<(*par)->GetName()<<
":"<<mIhkl_FullDeriv[*par].size()<<
","<<oldDeriv[*par].size()<<
", step="<<setw(16)<<step<<endl;
2187 cout<<
"PowderPatternDiffraction::CalcIhkl_FullDeriv():"<<endl<<FormatVertVectorHKLFloats<REAL>(v,12,1,20)<<endl;
2194 if( (this->GetCrystal().GetSpaceGroup().GetClockSpaceGroup()>mClockHKL)
2195 ||(this->GetCrystal().GetClockLatticePar()>mClockHKL)
2196 ||(this->GetRadiation().GetClockWavelength()>mClockHKL)
2198 this->GenHKLFullSpace();
2201 void PowderPatternDiffraction::InitOptions()
2203 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::InitOptions()",5)
2205 static string ReflectionProfileTypeName;
2206 static string ReflectionProfileTypeChoices[3];
2208 static bool needInitNames=
true;
2209 if(
true==needInitNames)
2211 ReflectionProfileTypeName=
"Profile Type";
2212 ReflectionProfileTypeChoices[0]=
"Gaussian";
2213 ReflectionProfileTypeChoices[1]=
"Lorentzian";
2214 ReflectionProfileTypeChoices[2]=
"Pseudo-Voigt";
2216 needInitNames=
false;
2218 mReflectionProfileType.Init(3,&ReflectionProfileTypeName,ReflectionProfileTypeChoices);
2219 this->
AddOption(&mReflectionProfileType);
2224 this->CalcPowderReflProfile();
2225 if((mClockProfileCalc>
mClockBraggLimits)&&(this->GetNbReflBelowMaxSinThetaOvLambda()>0))
2227 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::GetBraggLimits(*min,*max)",3)
2228 TAU_PROFILE(
"PowderPatternDiffraction::GetBraggLimits()",
"void ()",TAU_DEFAULT);
2232 for(;i<(this->GetNbReflBelowMaxSinThetaOvLambda()-1);++i)
2233 mIntegratedReflLimits(i+1)=(mvReflProfile[i].first+mvReflProfile[i].last+mvReflProfile[i+1].first+mvReflProfile[i+1].last)/4;
2236 VFN_DEBUG_EXIT(
"PowderPatternDiffraction::GetBraggLimits(*min,*max)",3)
2246 if(mFreezeLatticePar)
return mFrozenBMatrix;
2252 VFN_DEBUG_MESSAGE(
"PowderPatternDiffraction::CalcFrozenBMatrix()", 10)
2253 REAL a,b,c,alpha,beta,gamma;
2254 REAL aa,bb,cc,alphaa,betaa,gammaa;
2256 a=mFrozenLatticePar(0);
2257 b=mFrozenLatticePar(1);
2258 c=mFrozenLatticePar(2);
2259 alpha=mFrozenLatticePar(3);
2260 beta=mFrozenLatticePar(4);
2261 gamma=mFrozenLatticePar(5);
2263 v=sqrt(1-cos(alpha)*cos(alpha)-cos(beta)*cos(beta)-cos(gamma)*cos(gamma)
2264 +2*cos(alpha)*cos(beta)*cos(gamma));
2270 alphaa=acos( (cos(beta )*cos(gamma)-cos(alpha))/sin(beta )/sin(gamma) );
2271 betaa =acos( (cos(alpha)*cos(gamma)-cos(beta ))/sin(alpha)/sin(gamma) );
2272 gammaa=acos( (cos(alpha)*cos(beta )-cos(gamma))/sin(alpha)/sin(beta ) );
2274 mFrozenBMatrix = aa , bb*cos(gammaa) , cc*cos(betaa) ,
2275 0 , bb*sin(gammaa) ,-cc*sin(betaa)*cos(alpha),
2279 void PowderPatternDiffraction::PrepareIntegratedProfile()
const
2281 this->CalcPowderReflProfile();
2283 if( (mClockIntegratedProfileFactor>mClockProfileCalc)
2285 &&(mClockIntegratedProfileFactor>mClockNbReflUsed))
2287 VFN_DEBUG_ENTRY(
"PowderPatternDiffraction::PrepareIntegratedProfile()",7)
2292 const
long numInterval=pMin->numElements();
2294 vector< map<
long, REAL> > vIntegratedProfileFactor;
2295 vIntegratedProfileFactor.resize(mNbReflUsed);
2296 vector< map<
long, REAL> >::iterator pos1;
2297 pos1=vIntegratedProfileFactor.begin();
2299 mIntegratedProfileFactor.resize(mNbReflUsed);
2300 vector< pair<
unsigned long, CrystVector_REAL> >::iterator pos2;
2301 pos2=mIntegratedProfileFactor.begin();
2302 for(
long i=0;i<mNbReflUsed;i++)
2305 long firstInterval=numInterval;
2306 for(
long j=0;j<numInterval;j++)
2308 const long first0 = mvReflProfile[i].first;
2309 const long last0 = mvReflProfile[i].last ;
2310 const long first= first0>(*pMin)(j) ? first0:(*pMin)(j);
2311 const long last = last0 <(*pMax)(j) ? last0 :(*pMax)(j);
2312 if((first<=last) && (mvReflProfile[i].profile.size()>0))
2314 if(firstInterval>j) firstInterval=j;
2315 if(pos1->find(j) == pos1->end()) (*pos1)[j]=0.;
2316 REAL *fact = &((*pos1)[j]);
2317 const REAL *p2 = mvReflProfile[i].profile.data()+(first-first0);
2319 for(
int k=first;k<=last;k++) *fact += *p2++;
2322 pos2->first=firstInterval;
2323 pos2->second.resize(pos1->size());
2324 REAL *pFact=pos2->second.data();
2325 for(map<long, REAL>::const_iterator pos=pos1->begin();pos!=pos1->end();++pos)
2326 *pFact++ = pos->second;
2330 mClockIntegratedProfileFactor.Click();
2332 if(gVFNDebugMessageLevel<3)
2335 for(vector< pair<unsigned long, CrystVector_REAL> >::const_iterator
2336 pos=mIntegratedProfileFactor.begin();
2337 pos!=mIntegratedProfileFactor.end();++pos)
2339 cout <<
"Integrated profile factors for reflection #"<<i++<<
" ";
2340 for(
int j=0;j<pos->second.numElements();++j)
2341 cout << j+pos->first<<
"("<<pos->second(j)<<
") ";
2347 VFN_DEBUG_EXIT(
"PowderPatternDiffraction::PrepareIntegratedProfile()",7)
2350 #ifdef __WX__CRYST__
2351 WXCrystObjBasic* PowderPatternDiffraction::WXCreate(wxWindow* parent)
2354 mpWXCrystObj=
new WXPowderPatternDiffraction(parent,
this);
2355 return mpWXCrystObj;
2364 ObjRegistry<PowderPattern>
2365 gPowderPatternRegistry(
"List of all PowderPattern objects");
2367 PowderPattern::PowderPattern():
2368 mIsXAscending(true),mNbPoint(0),
2369 mXZero(0.),m2ThetaDisplacement(0.),m2ThetaTransparency(0.),
2370 mDIFC(48277.14),mDIFA(-6.7),
2371 mScaleFactor(20),mUseFastLessPreciseFunc(false),
2376 mPowderPatternComponentRegistry.SetName(
"Powder Pattern Components");
2379 gPowderPatternRegistry.Register(*
this);
2388 PowderPattern::PowderPattern(
const PowderPattern &old):
2389 mIsXAscending(old.mIsXAscending),mNbPoint(old.mNbPoint),
2390 mRadiation(old.mRadiation),
2391 mXZero(old.mXZero),m2ThetaDisplacement(old.m2ThetaDisplacement),
2392 m2ThetaTransparency(old.m2ThetaTransparency),
2393 mDIFC(old.mDIFC),mDIFA(old.mDIFA),
2394 mPowderPatternComponentRegistry(old.mPowderPatternComponentRegistry),
2395 mScaleFactor(old.mScaleFactor),
2396 mUseFastLessPreciseFunc(old.mUseFastLessPreciseFunc),
2397 mStatisticsExcludeBackground(old.mStatisticsExcludeBackground),
2398 mMaxSinThetaOvLambda(old.mMaxSinThetaOvLambda),mNbPointUsed(old.mNbPointUsed)
2403 gPowderPatternRegistry.Register(*
this);
2413 PowderPattern::~PowderPattern()
2415 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
2417 mPowderPatternComponentRegistry.GetObj(i).DeRegisterClient(*
this);
2419 delete &(mPowderPatternComponentRegistry.GetObj(i));
2421 gPowderPatternRegistry.DeRegister(*
this);
2426 const static string className=
"PowderPattern";
2432 VFN_DEBUG_ENTRY(
"PowderPattern::AddPowderPatternComponent():"<<comp.
GetName(),5)
2437 mClockIntegratedFactorsPrep.Reset();
2438 mPowderPatternComponentRegistry.Register(comp);
2441 mScaleFactor(mPowderPatternComponentRegistry.GetNb()-1)=1.;
2445 RefinablePar tmp(
"Scale_"+comp.
GetName(),mScaleFactor.data()+mPowderPatternComponentRegistry.GetNb()-1,
2447 false,
true,
true,
false,1.);
2454 VFN_DEBUG_EXIT(
"PowderPattern::AddPowderPatternComponent():"<<comp.
GetName(),5)
2459 return mPowderPatternComponentRegistry.GetNb();
2463 (
const string &name)
const
2465 return mPowderPatternComponentRegistry.GetObj(name);
2471 return mPowderPatternComponentRegistry.GetObj(i);
2475 (
const string &name)
2477 return mPowderPatternComponentRegistry.GetObj(name);
2483 return mPowderPatternComponentRegistry.GetObj(i);
2491 for(;i<mPowderPatternComponentRegistry.GetNb();++i)
2493 if(&(mPowderPatternComponentRegistry.GetObj(i))==&comp)
break;
2495 if(i==mPowderPatternComponentRegistry.GetNb())
2496 throw ObjCrystException(
"PowderPattern::GetScaleFactor(comp) : no such component");
2497 return mScaleFactor(i);
2504 for(;i<mPowderPatternComponentRegistry.GetNb();++i)
2506 if(&(mPowderPatternComponentRegistry.GetObj(i))==&comp)
break;
2508 if(i==mPowderPatternComponentRegistry.GetNb())
2509 throw ObjCrystException(
"PowderPattern::GetScaleFactor(comp) : no such component");
2515 unsigned long nbPoint)
2517 VFN_DEBUG_MESSAGE(
"PowderPattern::SetPowderPatternPar():"<<min<<
","<<step<<
","<<nbPoint,3)
2520 for(
unsigned long i=0;i<
mNbPoint;i++)
mX(i)=min+step*i;
2536 VFN_DEBUG_MESSAGE(
"PowderPattern::SetPowderPatternX() is ascending="<<
mIsXAscending,5)
2544 return mNbPointUsed;
2566 VFN_DEBUG_MESSAGE(
"PowderPattern::SetWavelength(lambda)",3)
2572 VFN_DEBUG_MESSAGE(
"PowderPattern::SetWavelength(wavelength)",3)
2584 std::map<RefinablePar*,CrystVector_REAL>& PowderPattern::GetPowderPattern_FullDeriv(std::set<RefinablePar *> &vPar)
2586 this->CalcPowderPattern_FullDeriv(vPar);
2587 return mPowderPattern_FullDeriv;
2636 VFN_DEBUG_ENTRY(
"PowderPattern::GetChi2Cumul()",3)
2638 if(0 == mOptProfileIntegration.GetChoice())
2641 if(mNbIntegrationUsed==0)
2645 const REAL *pObs=mIntegratedObs.data();
2647 const REAL *pWeight;
2648 if(mIntegratedWeight.numElements()==0) pWeight=mIntegratedWeightObs.data();
2649 else pWeight=mIntegratedWeight.data();
2652 for(
int i=0;i<mIntegratedPatternMin(0);i++) *pC2Cu++ = 0;
2653 REAL chi2cumul=0,tmp;
2654 for(
unsigned long j=1;j<mNbIntegrationUsed;j++)
2656 tmp=(*pObs++ - *pCalc++) ;
2657 chi2cumul += *pWeight++ * tmp*tmp;
2658 for(
int i=mIntegratedPatternMin(j-1);i<mIntegratedPatternMin(j);i++) *pC2Cu++ =chi2cumul;
2660 if(mIntegratedPatternMin(j)>(int)mNbPointUsed)
2662 for(
unsigned int i=mIntegratedPatternMin(j);i<
mNbPoint;i++) *pC2Cu++ =chi2cumul;
2666 pC2Cu=
mChi2Cumul.data()+mIntegratedPatternMin(mNbIntegrationUsed-1);
2667 for(
unsigned int i=mIntegratedPatternMin(mNbIntegrationUsed-1);i<
mNbPoint;i++) *pC2Cu++ =chi2cumul;
2677 REAL chi2cumul=0,tmp;
2678 for(
unsigned int i=0;i<mNbPointUsed;i++)
2680 VFN_DEBUG_MESSAGE(
"PowderPattern::GetChi2Cumul():"<<mIntegratedPatternMin(i)<<
"->"<<mIntegratedPatternMax(i)<<
":obs-calc="<<*pObs - *pCalc<<
", weight="<<*pWeight,5);
2681 tmp = (*pObs++ - *pCalc++) ;
2682 chi2cumul += *pWeight++ * tmp*tmp;
2683 *pC2Cu++ = chi2cumul;
2686 VFN_DEBUG_EXIT(
"PowderPattern::GetChi2Cumul()",3)
2710 m2ThetaDisplacement=displacement;
2716 m2ThetaTransparency=transparency;
2725 x += m2ThetaDisplacement*cos(x/2) +m2ThetaTransparency*sin(x);
2742 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel()",1)
2744 if((pix>0)&&(pix<((long)
mNbPoint-1)))
2747 const REAL localStep=
mX(pix)-
mX(pix+1);
2748 if(localStep>0) pix -= (long)((x-
mX(pix))/localStep);
2750 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix,1)
2753 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix<<
","<<
mX(pix),1)
2758 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix<<
","<<
mX(pix),1)
2759 if(
mX(pix)>=x)
break;
2767 if(
mX(pix)<=x) {pix--;
break;}
2772 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix<<
","<<
mX(pix),1)
2773 const REAL localStep=
mX(pix)-
mX(pix+1);
2774 pixx = (REAL)pix-(x-
mX(pix))/localStep;
2775 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix<<
","<<
mX(pix),1)
2781 if((pix>0)&&(pix<((long)
mNbPoint-1)))
2784 const REAL localStep=
mX(pix+1)-
mX(pix);
2785 if(localStep>0) pix += (long)((x-
mX(pix))/localStep);
2787 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix,1)
2790 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix<<
","<<
mX(pix),1)
2795 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix<<
","<<
mX(pix),1)
2796 if(
mX(pix)<=x)
break;
2804 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix<<
","<<
mX(pix),1)
2805 if(
mX(pix)>=x) {pix-- ;
break;}
2809 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix<<
","<<
mX(pix),1)
2812 const REAL localStep=
mX(pix+1)-
mX(pix);
2813 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pix<<
","<<
mX(pix)<<
","<<localStep,1)
2814 pixx = (REAL)pix+(x-
mX(pix))/localStep;
2816 VFN_DEBUG_MESSAGE(
"PowderPattern::X2Pixel():"<<x<<
","<<pixx,1)
2825 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternFullprof() : \
2826 from file : "+filename,5)
2827 ifstream fin(filename.c_str());
2831 Error opening file for input:"+filename);
2834 fin >> min >> step >> max;
2839 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternFullprof() :"\
2840 <<
" 2Theta min=" << min*RAD2DEG <<
" 2Theta max=" << max*RAD2DEG \
2846 char tmpComment[200];
2847 fin.getline(tmpComment,100);
2858 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
2859 (
int)
mNbPoint,min*RAD2DEG,max*RAD2DEG,step*RAD2DEG);
2860 (*fpObjCrystInformUser)((string)buf);
2862 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportFullProfPattern():finished:"<<
mNbPoint<<
" points",5)
2867 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternPSI_DMC() : \
2868 from file : "+filename,5)
2869 ifstream fin(filename.c_str());
2873 Error opening file for input:"+filename);
2876 char tmpComment[200];
2877 fin.getline(tmpComment,190);
2878 fin.getline(tmpComment,190);
2880 fin >> min >> step >> max;
2885 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternPSI_DMC() :"\
2886 <<
" 2Theta min=" << min*RAD2DEG <<
" 2Theta max=" << max*RAD2DEG \
2892 fin.getline(tmpComment,100);
2903 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
2904 (
int)
mNbPoint,min*RAD2DEG,max*RAD2DEG,step*RAD2DEG);
2905 (*fpObjCrystInformUser)((string)buf);
2907 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternPSI_DMC():finished",5)
2912 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternILL_D1AD2B() : \
2913 from file : "+filename,5)
2914 ifstream fin(filename.c_str());
2918 Error opening file for input:"+filename);
2921 char tmpComment[200];
2922 fin.getline(tmpComment,190);
2923 fin.getline(tmpComment,190);
2924 fin.getline(tmpComment,190);
2927 fin.getline(tmpComment,190);
2933 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternILL_D1AD2B() :"\
2934 <<
" 2Theta min=" << min*RAD2DEG <<
" 2Theta max=" << min*RAD2DEG+mNbPoint*step*RAD2DEG \
2935 <<
" NbPoints=" << mNbPoint,5)
2950 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
2951 (
int)mNbPoint,min*RAD2DEG,(min+step*(mNbPoint-1))*RAD2DEG,
2953 (*fpObjCrystInformUser)((string)buf);
2955 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternILL_D1AD2B():finished",5)
2960 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternXdd():from file :" \
2962 ifstream fin (filename.c_str());
2966 Error opening file for input:"+filename);
2968 char tmpComment[200];
2969 fin.getline(tmpComment,100);
2971 REAL min,max,step,tmp;
2972 fin >> min >> step >> max;
2994 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
2995 (
int)
mNbPoint,min*RAD2DEG,max*RAD2DEG,step*RAD2DEG);
2996 (*fpObjCrystInformUser)((string)buf);
2998 VFN_DEBUG_MESSAGE(
"DiffractionDataPowder::ImportXddPattern() :finished",5)
3003 VFN_DEBUG_ENTRY(
"PowderPattern::ImportPowderPatternSietronicsCPI():from file :" \
3005 ifstream fin (filename.c_str());
3009 Error opening file for input:"+filename);
3011 char tmpComment[300];
3012 fin.getline(tmpComment,100);
3013 VFN_DEBUG_MESSAGE(
" ->Discarded comment :"<<tmpComment,1)
3015 fin >> min >> max >> step;
3031 VFN_DEBUG_MESSAGE(
" ->Read :"<<str,1)
3032 }
while (
"SCANDATA"!=str);
3042 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
3043 (
int)
mNbPoint,min*RAD2DEG,max*RAD2DEG,step*RAD2DEG);
3044 (*fpObjCrystInformUser)((string)buf);
3046 VFN_DEBUG_EXIT(
"DiffractionDataPowder::ImportPowderPatternSietronicsCPI()",5)
3051 VFN_DEBUG_MESSAGE(
"DiffractionDataPowder::ImportPowderPattern2ThetaObsSigma():from:" \
3053 ifstream fin (filename.c_str());
3057 Error opening file for input:"+filename);
3060 char tmpComment[200];
3061 for(
int i=0;i<nbSkip;i++) fin.getline(tmpComment,150);
3080 mX.resizeAndPreserve(
mNbPoint+500);
3081 mPowderPatternObs.resizeAndPreserve(
mNbPoint+500);
3082 mPowderPatternObsSigma.resizeAndPreserve(
mNbPoint+500);
3084 }
while(fin.eof() ==
false);
3099 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
3103 (*fpObjCrystInformUser)((string)buf);
3105 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPattern2ThetaObsSigma()\
3106 :finished: "<<
mNbPoint<<
" points",5)
3111 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPattern2ThetaObs():from:" \
3113 ifstream fin (filename.c_str());
3117 Error opening file for input:"+filename);
3120 char tmpComment[200];
3121 for(
int i=0;i<nbSkip;i++) fin.getline(tmpComment,150);
3138 mX.resizeAndPreserve(
mNbPoint+500);
3139 mPowderPatternObs.resizeAndPreserve(
mNbPoint+500);
3142 }
while(fin.eof() ==
false);
3158 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
3162 (*fpObjCrystInformUser)((string)buf);
3164 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPattern2ThetaObs():finished",5)
3184 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternMultiDetectorLLBG42() : \
3185 from file : "+filename,5)
3186 ifstream fin(filename.c_str());
3189 throw ObjCrystException(
"PowderPattern::ImportPowderPatternMultiDetectorLLBG42() : \
3190 Error opening file for input:"+filename);
3197 fin >>junk>>junk>>step>>junk>>junk>>junk>>min>>junk>>junk>>junk>>junk;
3200 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternMultiDetectorLLBG42() :"\
3201 <<
" 2Theta min=" << min*RAD2DEG <<
" 2Theta step=" << step*RAD2DEG,5)
3214 sscanf(str.c_str(),
"%f",&tmp);
3216 const unsigned int nb=str.length()/8;
3217 for(
unsigned int i=0;i<nb;i++)
3224 sub=str.substr(i*8,8);
3225 sscanf(sub.c_str(),
"%2f%6f",&ct,&iobs);
3242 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
3243 (
int)
mNbPoint,min*RAD2DEG,
mX(mNbPoint-1)*RAD2DEG,step*RAD2DEG);
3244 (*fpObjCrystInformUser)((string)buf);
3246 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternMultiDetectorLLBG42():finished:"<<
mNbPoint<<
" points",5)
3256 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternFullprof4() : \
3257 from file : "+filename,5)
3258 ifstream fin(filename.c_str());
3262 Error opening file for input:"+filename);
3265 fin >> min >> step >> max;
3270 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternFullprof4() :"\
3271 <<
" 2Theta min=" << min*RAD2DEG <<
" 2Theta max=" << max*RAD2DEG \
3286 for(
unsigned int i=0;i<str.size();i++)
if(
' '==str[i]) str[i]=
'0';
3287 sscanf(str.c_str(),
"%8f%8f%8f%8f%8f%8f%8f%8f%8f%8f",
3288 line+0,line+1,line+2,line+3,line+4,line+5,line+6,line+7,line+8,line+9);
3289 for(
unsigned int j=0;j<10;j++)
3292 for(
unsigned int i=0;i<str.size();i++)
if(
' '==str[i]) str[i]=
'0';
3293 sscanf(str.c_str(),
"%8f%8f%8f%8f%8f%8f%8f%8f%8f%8f",
3294 line+0,line+1,line+2,line+3,line+4,line+5,line+6,line+7,line+8,line+9);
3295 for(
unsigned int j=0;j<10;j++)
3304 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
3305 (
int)mNbPoint,min*RAD2DEG,max*RAD2DEG,
3307 (*fpObjCrystInformUser)((string)buf);
3309 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportFullProfPattern4():finished:"<<mNbPoint<<
" points",5)
3314 VFN_DEBUG_MESSAGE(
"DiffractionDataPowder::ImportPowderPatternTOF_ISIS_XYSigma():from:" \
3316 ifstream fin (filename.c_str());
3320 Error opening file for input:"+filename);
3324 fin.getline(junk,150);
3343 mX.resizeAndPreserve(
mNbPoint+500);
3344 mPowderPatternObs.resizeAndPreserve(
mNbPoint+500);
3345 mPowderPatternObsSigma.resizeAndPreserve(
mNbPoint+500);
3347 }
while(fin.eof() ==
false);
3357 for(
unsigned long i=0;i<(
mNbPoint/2);i++)
3380 sprintf(buf,
"Imported TOF powder pattern: %d points, TOF=%7.3f -> %7.3f",
3383 (*fpObjCrystInformUser)((string)buf);
3385 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternTOF_ISIS_XYSigma()\
3386 :finished: "<<
mNbPoint<<
" points",5)
3391 VFN_DEBUG_ENTRY(
"PowderPattern::ImportPowderPatternGSAS():file:"<<filename,5)
3392 ifstream fin (filename.c_str());
3396 Error opening file for input:"+filename);
3401 while(isprint(fin.peek())==
false)
3403 if(fin.eof())
break;
3406 cout<<
"Title:"<<title<<endl;
3411 int numBank,nbRecords;
3412 string binType, type;
3419 fin.getline(line,80);
3420 while(isprint(fin.peek())==
false)
3422 if(fin.eof())
break;
3425 sscanf(line,
"%4s",bank);
3428 Could not find BANK statement !! In file: "+filename);
3430 while(
string(bank)!=string(
"BANK"));
3434 char binTypeC[20],typeC[20];
3435 sscanf(line,
"%4s%d %ld %d %s %f %f %f %f %s",bank,&numBank,&
mNbPoint,&nbRecords,
3436 binTypeC,&bcoeff[0],&bcoeff[1],&bcoeff[2],&bcoeff[3],typeC);
3440 if(binType==
"CONST") binType=
"CONS";
3441 if((type!=
"ALT")&&(type!=
"ESD")) type=
"STD";
3443 cout<<
"BANK #"<<numBank<<endl;
3444 cout<<
"Number of data points:"<<
mNbPoint<<endl;
3445 cout<<
"Number of records:"<<nbRecords<<endl;
3446 cout<<
"BinType:"<<binType<<endl;
3447 cout<<
"BCoeff[1-4]:"<<bcoeff[0]<<
","<<bcoeff[1]<<
","<<bcoeff[2]<<
","<<bcoeff[3]<<endl;
3448 cout<<
"Type:"<<type<<endl;
3453 bool importOK=
false;
3454 if((binType==
"CONS") && (type==
"ESD"))
3458 unsigned long point=0;
3461 for(
long i=0;i<nbRecords;i++)
3465 while(isprint(fin.peek())==
false)
3467 if(fin.eof())
break;
3470 for(
unsigned int j=0;j<5;j++)
3476 substr=string(line).substr(j*16+0 ,8);
3477 istringstream(substr) >> iobs;
3478 substr=string(line).substr(j*16+8 ,8);
3479 istringstream(substr) >> isig;
3489 if((binType==
"CONS") && (type==
"STD"))
3492 unsigned long point=0;
3496 for(
long i=0;i<nbRecords;i++)
3500 while(isprint(fin.peek())==
false)
3502 if(fin.eof())
break;
3505 for(
unsigned int j=0;j<10;j++)
3516 substr=string(line).substr(j*8+0 ,2);
3517 if(substr==
" ") nc=1;
3518 else sscanf(substr.c_str(),
"%d",&nc);
3519 substr=string(line).substr(j*8+2 ,6);
3520 istringstream(substr) >> iobs;
3529 if((binType==
"RALF") && (type==
"ALT"))
3535 unsigned long point=0;
3536 REAL x,iobs,iobssigma;
3538 for(
long i=0;i<nbRecords;i++)
3542 while(isprint(fin.peek())==
false)
3544 if(fin.eof())
break;
3547 for(
unsigned int j=0;j<4;j++)
3553 substr=string(line).substr(j*20+0 ,8);
3554 istringstream(substr) >> x;
3555 substr=string(line).substr(j*20+8 ,7);
3556 istringstream(substr) >> iobs;
3557 substr=string(line).substr(j*20+15,5);
3558 istringstream(substr) >> iobssigma;
3568 for(
unsigned long i=0;i<(
mNbPoint/2);i++)
3592 this type of format is not handled yet (send an example file to the Fox author)!:"+filename);
3599 if(this->
GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
3602 sprintf(buf,
"Imported powder pattern: %d points, tof=%7.3f us-> %7.3f us",
3605 (*fpObjCrystInformUser)((string)buf);
3610 sprintf(buf,
"Imported powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
3614 (*fpObjCrystInformUser)((string)buf);
3616 VFN_DEBUG_EXIT(
"PowderPattern::ImportPowderPatternGSAS():file:"<<filename,5)
3621 VFN_DEBUG_ENTRY(
"PowderPattern::ImportPowderPatternCIF():file:",5)
3622 for(map<string,CIFData>::const_iterator pos=cif.
mvData.begin();pos!=cif.
mvData.end();++pos)
3623 if(pos->second.mPowderPatternObs.size()>10)
3625 mNbPoint=pos->second.mPowderPatternObs.size();
3630 if(pos->second.mDataType==WAVELENGTH_TOF)
3637 for(
unsigned long i=0;i<
mNbPoint;++i)
3640 mX(i)=pos->second.mPowderPatternX[i];
3646 VFN_DEBUG_EXIT(
"PowderPattern::ImportPowderPatternCIF():file:",5)
3652 VFN_DEBUG_MESSAGE(
"PowderPattern::ImportPowderPatternObs()",5)
3653 if((
unsigned long)obs.numElements() !=
mNbPoint)
3655 cout << obs.numElements()<<
" "<<
mNbPoint<<
" "<<
this<<endl;
3657 supplied vector of observed intensities does not have the expected number of points!"));
3666 mClockIntegratedFactorsPrep.Reset();
3669 sprintf(buf,
"Changed powder pattern: %d points, 2theta=%7.3f -> %7.3f, step=%6.3f",
3671 (
mX(mNbPoint-1)-
mX(0))/(mNbPoint-1)*RAD2DEG);
3672 (*fpObjCrystInformUser)((string)buf);
3677 VFN_DEBUG_MESSAGE(
"PowderPattern::SavePowderPattern",5)
3679 ofstream out(filename.c_str());
3680 CrystVector_REAL ttheta;
3684 CrystVector_REAL diff;
3687 out <<
"# 2Theta/TOF Iobs ICalc Iobs-Icalc Weight Comp0" << endl;
3688 out << FormatVertVector<REAL>(ttheta,
3692 mPowderPatternComponentRegistry.GetObj(0).mPowderPatternCalc,16,8);
3694 VFN_DEBUG_MESSAGE(
"DiffractionDataPowder::SavePowderPattern:End",3)
3699 VFN_DEBUG_MESSAGE(
"DiffractionDataPowder::PrintObsCalcData()",5);
3700 CrystVector_REAL ttheta;
3702 if(this->
GetRadiation().GetWavelengthType()!=WAVELENGTH_TOF) ttheta *= RAD2DEG;
3703 os <<
"PowderPattern : " <<
mName <<endl;
3704 os <<
" 2Theta/TOF Obs Sigma Calc Weight" <<endl;
3718 TAU_PROFILE(
"PowderPattern::GetR()",
"void ()",TAU_DEFAULT);
3723 unsigned long maxPoints=mNbPointUsed;
3724 if( (
true==mStatisticsExcludeBackground)
3727 const REAL *p1, *p2, *p3;
3734 VFN_DEBUG_MESSAGE(
"PowderPattern::GetR():Exclude Backgd",4);
3735 for(
unsigned long i=0;i<maxPoints;i++)
3737 tmp1 += ((*p1)-(*p2)) * ((*p1)-(*p2));
3738 tmp2 += ((*p2)-(*p3)) * ((*p2)-(*p3));
3744 VFN_DEBUG_MESSAGE(
"PowderPattern::GetR():Exclude Backgd,Exclude regions",4);
3745 unsigned long min,max;
3747 for(
int j=0;j<nbExclude;j++)
3751 if(min>maxPoints)
break;
3752 if(max>maxPoints)max=maxPoints;
3755 tmp1 += ((*p1)-(*p2)) * ((*p1)-(*p2));
3756 tmp2 += ((*p2)-(*p3)) * ((*p2)-(*p3));
3764 for(;i<maxPoints;i++)
3766 tmp1 += ((*p1)-(*p2)) * ((*p1)-(*p2));
3767 tmp2 += ((*p2)-(*p3)) * ((*p2)-(*p3));
3775 const REAL *p1, *p2;
3781 VFN_DEBUG_MESSAGE(
"PowderPattern::GetR()",4);
3782 for(
unsigned long i=0;i<maxPoints;i++)
3784 tmp1 += ((*p1)-(*p2))*((*p1)-(*p2));
3785 tmp2 += (*p2) * (*p2);
3792 VFN_DEBUG_MESSAGE(
"PowderPattern::GetR(),Exclude regions",4);
3793 unsigned long min,max;
3795 for(
int j=0;j<nbExclude;j++)
3799 if(min>maxPoints)
break;
3800 if(max>maxPoints)max=maxPoints;
3803 tmp1 += ((*p1)-(*p2))*((*p1)-(*p2));
3804 tmp2 += (*p2) * (*p2);
3811 for(;i<maxPoints;i++)
3813 tmp1 += ((*p1)-(*p2))*((*p1)-(*p2));
3814 tmp2 += (*p2) * (*p2);
3820 VFN_DEBUG_MESSAGE(
"PowderPattern::GetR()="<<sqrt(tmp1/tmp2),4);
3824 return sqrt(tmp1/tmp2);
3827 REAL PowderPattern::GetIntegratedR()
const
3836 VFN_DEBUG_ENTRY(
"PowderPattern::GetIntegratedR()",4);
3837 TAU_PROFILE(
"PowderPattern::GetIntegratedR()",
"void ()",TAU_DEFAULT);
3841 const long numInterval=mIntegratedPatternMin.numElements();
3842 if( (
true==mStatisticsExcludeBackground)
3845 const REAL *p1, *p2, *p3;
3846 CrystVector_REAL integratedCalc(numInterval);
3848 CrystVector_REAL backgdCalc(numInterval);
3850 REAL *pp1=integratedCalc.data();
3851 REAL *pp2=backgdCalc.data();
3852 for(
int i=0;i<numInterval;i++)
3854 const long max=mIntegratedPatternMax(i);
3856 for(
int j=mIntegratedPatternMin(i);j<=max;j++) *pp1 += *p1++;
3859 for(
int j=mIntegratedPatternMin(i);j<=max;j++) *pp2 += *p1++;
3863 p1=integratedCalc.data();
3864 p2=mIntegratedObs.data();
3865 p3=backgdCalc.data();
3866 VFN_DEBUG_MESSAGE(
"PowderPattern::GetIntegratedR():Exclude Backgd",2);
3867 for(
long i=0;i<numInterval;i++)
3869 tmp1 += ((*p1)-(*p2)) * ((*p1)-(*p2));
3870 tmp2 += ((*p2)-(*p3)) * ((*p2)-(*p3));
3876 const REAL *p1, *p2;
3877 CrystVector_REAL integratedCalc(numInterval);
3879 REAL *pp1=integratedCalc.data();
3880 for(
int i=0;i<numInterval;i++)
3882 const long max=mIntegratedPatternMax(i);
3884 for(
int j=mIntegratedPatternMin(i);j<=max;j++) *pp1 += *p1++;
3887 p1=integratedCalc.data();
3888 p2=mIntegratedObs.data();
3889 VFN_DEBUG_MESSAGE(
"PowderPattern::GetIntegratedR()",2);
3890 for(
long i=0;i<numInterval;i++)
3892 tmp1 += ((*p1)-(*p2))*((*p1)-(*p2));
3893 tmp2 += (*p2) * (*p2);
3899 VFN_DEBUG_EXIT(
"PowderPattern::GetIntegratedR()="<<sqrt(tmp1/tmp2),4);
3900 return sqrt(tmp1/tmp2);
3911 TAU_PROFILE(
"PowderPattern::GetRw()",
"void ()",TAU_DEFAULT);
3912 VFN_DEBUG_MESSAGE(
"PowderPattern::GetRw()",3);
3921 unsigned long maxPoints=mNbPointUsed;
3923 if( (
true==mStatisticsExcludeBackground)
3926 VFN_DEBUG_MESSAGE(
"PowderPattern::GetRw():Exclude Backgd",3);
3927 const REAL *p1, *p2, *p3, *p4;
3935 for(
unsigned long i=0;i<maxPoints;i++)
3937 tmp1 += *p4 * ((*p1)-(*p2)) * ((*p1)-(*p2));
3938 tmp2 += *p4++ * ((*p2)-(*p3)) * ((*p2)-(*p3));
3944 unsigned long min,max;
3946 for(
int j=0;j<nbExclude;j++)
3950 if(min>maxPoints)
break;
3951 if(max>maxPoints)max=maxPoints;
3954 tmp1 += *p4 * ((*p1)-(*p2)) * ((*p1)-(*p2));
3955 tmp2 += *p4++ * ((*p2)-(*p3)) * ((*p2)-(*p3));
3964 for(;i<maxPoints;i++)
3966 tmp1 += *p4 * ((*p1)-(*p2)) * ((*p1)-(*p2));
3967 tmp2 += *p4++ * ((*p2)-(*p3)) * ((*p2)-(*p3));
3975 VFN_DEBUG_MESSAGE(
"PowderPattern::GetRw()",3);
3976 const REAL *p1, *p2, *p4;
3983 for(
unsigned long i=0;i<maxPoints;i++)
3985 tmp1 += *p4 * ((*p1)-(*p2))*((*p1)-(*p2));
3986 tmp2 += *p4++ * (*p2) * (*p2);
3992 unsigned long min,max;
3994 for(
int j=0;j<nbExclude;j++)
3998 if(min>maxPoints)
break;
3999 if(max>maxPoints)max=maxPoints;
4002 tmp1 += *p4 * ((*p1)-(*p2))*((*p1)-(*p2));
4003 tmp2 += *p4++ * (*p2) * (*p2);
4011 for(;i<maxPoints;i++)
4013 tmp1 += *p4 * ((*p1)-(*p2))*((*p1)-(*p2));
4014 tmp2 += *p4++ * (*p2) * (*p2);
4019 VFN_DEBUG_MESSAGE(
"PowderPattern::GetRw()="<<sqrt(tmp1/tmp2),3);
4020 return sqrt(tmp1/tmp2);
4022 REAL PowderPattern::GetIntegratedRw()
const
4031 TAU_PROFILE(
"PowderPattern::GetIntegratedRw()",
"void ()",TAU_DEFAULT);
4035 const long numInterval=mIntegratedPatternMin.numElements();
4036 if( (
true==mStatisticsExcludeBackground)
4039 const REAL *p1, *p2, *p3, *p4;
4040 CrystVector_REAL integratedCalc(numInterval);
4042 CrystVector_REAL backgdCalc(numInterval);
4044 REAL *pp1=integratedCalc.data();
4045 REAL *pp2=backgdCalc.data();
4046 for(
int i=0;i<numInterval;i++)
4048 const long max=mIntegratedPatternMax(i);
4050 for(
int j=mIntegratedPatternMin(i);j<=max;j++) *pp1 += *p1++;
4053 for(
int j=mIntegratedPatternMin(i);j<=max;j++) *pp2 += *p1++;
4057 p1=integratedCalc.data();
4058 p2=mIntegratedObs.data();
4059 p3=backgdCalc.data();
4060 if(mIntegratedWeight.numElements()==0) p4=mIntegratedWeightObs.data();
4061 else p4=mIntegratedWeight.data();
4062 VFN_DEBUG_MESSAGE(
"PowderPattern::GetIntegratedRw():Exclude Backgd",4);
4063 for(
long i=0;i<numInterval;i++)
4065 tmp1 += *p4 * ((*p1)-(*p2)) * ((*p1)-(*p2));
4066 tmp2 += *p4++ * ((*p2)-(*p3)) * ((*p2)-(*p3));
4074 const REAL *p1, *p2, *p4;
4075 CrystVector_REAL integratedCalc(numInterval);
4077 REAL *pp1=integratedCalc.data();
4078 for(
int i=0;i<numInterval;i++)
4080 const long max=mIntegratedPatternMax(i);
4082 for(
int j=mIntegratedPatternMin(i);j<=max;j++) *pp1 += *p1++;
4085 p1=integratedCalc.data();
4086 p2=mIntegratedObs.data();
4087 if(mIntegratedWeight.numElements()==0) p4=mIntegratedWeightObs.data();
4088 else p4=mIntegratedWeight.data();
4089 VFN_DEBUG_MESSAGE(
"PowderPattern::GetIntegratedRw()",4);
4090 for(
long i=0;i<numInterval;i++)
4092 tmp1 += *p4 * ((*p1)-(*p2))*((*p1)-(*p2));
4093 tmp2 += *p4++ * (*p2) * (*p2);
4099 VFN_DEBUG_MESSAGE(
"PowderPattern::GetIntegratedRw()="<<sqrt(tmp1/tmp2),4);
4103 return sqrt(tmp1/tmp2);
4124 TAU_PROFILE(
"PowderPattern::GetChi2()",
"void ()",TAU_DEFAULT);
4126 VFN_DEBUG_ENTRY(
"PowderPattern::GetChi2()",3);
4128 const unsigned long maxPoints=mNbPointUsed;
4132 VFN_DEBUG_MESSAGE(
"PowderPattern::GetChi2()Integrated profiles",3);
4133 const REAL * RESTRICT p1, * RESTRICT p2, * RESTRICT p3;
4140 for(
unsigned long i=0;i<maxPoints;i++)
4142 mChi2 += *p3 * ((*p1)-(*p2))*((*p1)-(*p2));
4144 else mChi2LikeNorm -= log(*p3++);
4150 unsigned long min,max;
4152 for(
int j=0;j<nbExclude;j++)
4156 if(min>maxPoints)
break;
4157 if(max>maxPoints)max=maxPoints;
4160 mChi2 += *p3 * ((*p1)-(*p2))*((*p1)-(*p2));
4162 else mChi2LikeNorm -= log(*p3++);
4170 for(;i<maxPoints;i++)
4172 mChi2 += *p3 * ((*p1)-(*p2))*((*p1)-(*p2));
4174 else mChi2LikeNorm -= log(*p3++);
4179 VFN_DEBUG_MESSAGE(
"Chi^2="<<mChi2<<
", log(norm)="<<mChi2LikeNorm,3)
4181 VFN_DEBUG_EXIT(
"PowderPattern::GetChi2()="<<mChi2,3);
4191 return mIntegratedChi2;
4194 if(mClockIntegratedChi2>
mClockMaster)
return mIntegratedChi2;
4202 this->FitScaleFactorForIntegratedRw();
4204 TAU_PROFILE(
"PowderPattern::GetIntegratedChi2()",
"void ()",TAU_DEFAULT);
4206 VFN_DEBUG_ENTRY(
"PowderPattern::GetIntegratedChi2()",3);
4209 mIntegratedChi2LikeNorm=0.;
4210 VFN_DEBUG_MESSAGE(
"PowderPattern::GetIntegratedChi2()",3);
4211 const REAL * RESTRICT p1, * RESTRICT p2, * RESTRICT p3;
4213 p2=mIntegratedObs.data();
4214 if(mIntegratedWeight.numElements()==0) p3=mIntegratedWeightObs.data();
4215 else p3=mIntegratedWeight.data();
4216 double weightProd=1.;
4217 VFN_DEBUG_MESSAGE(
"PowderPattern::GetIntegratedIntegratedRw()",4);
4218 for(
unsigned long i=0;i<mNbIntegrationUsed;)
4222 for(
unsigned long j=0;j<32;++j)
4224 mIntegratedChi2 += *p3 * ((*p1)-(*p2))*((*p1)-(*p2));
4225 if(*p3>0) weightProd *= *p3;
4227 if(++i == mNbIntegrationUsed)
break;
4229 mIntegratedChi2LikeNorm -= log(weightProd);
4232 mIntegratedChi2LikeNorm/=2;
4233 VFN_DEBUG_MESSAGE(
"Chi^2="<<mIntegratedChi2<<
", log(norm)="<<mIntegratedChi2LikeNorm,3)
4234 mClockIntegratedChi2.Click();
4235 VFN_DEBUG_EXIT(
"PowderPattern::GetChi2()="<<mIntegratedChi2,3);
4236 return mIntegratedChi2;
4253 TAU_PROFILE(
"PowderPattern::FitScaleFactorForR()",
"void ()",TAU_DEFAULT);
4254 VFN_DEBUG_ENTRY(
"PowderPattern::FitScaleFactorForR()",3);
4256 mScalableComponentIndex.resize(mPowderPatternComponentRegistry.GetNb());
4258 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
4260 if(mPowderPatternComponentRegistry.GetObj(i).IsScalable())
4261 mScalableComponentIndex(nbScale++)=i;
4263 VFN_DEBUG_MESSAGE(
"-> Number of Scale Factors:"<<nbScale<<
":Index:"<<endl<<mScalableComponentIndex,3);
4266 VFN_DEBUG_EXIT(
"PowderPattern::FitScaleFactorForR(): No scalable component!",3);
4269 mScalableComponentIndex.resizeAndPreserve(nbScale);
4271 mFitScaleFactorM.resize(nbScale,nbScale);
4272 mFitScaleFactorB.resize(nbScale,1);
4273 mFitScaleFactorX.resize(nbScale,1);
4278 for(
int i=0;i<nbScale;i++)
4280 for(
int j=i;j<nbScale;j++)
4284 const REAL *p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4285 .mPowderPatternCalc.data();
4286 const REAL *p2=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(j))
4287 .mPowderPatternCalc.data();
4289 for(
unsigned long k=0;k<mNbPointUsed;k++) m += *p1++ * *p2++;
4290 mFitScaleFactorM(i,j)=m;
4291 mFitScaleFactorM(j,i)=m;
4294 for(
int i=0;i<nbScale;i++)
4297 const REAL *p2=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4298 .mPowderPatternCalc.data();
4301 for(
unsigned long k=0;k<mNbPointUsed;k++) b += *p1++ * *p2++;
4305 for(
unsigned long k=0;k<mNbPointUsed;k++) b += (*p1++ - *p3++) * *p2++;
4307 mFitScaleFactorB(i,0) =b;
4312 unsigned long min,max;
4313 for(
int i=0;i<nbScale;i++)
4315 for(
int j=i;j<nbScale;j++)
4319 const REAL *p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4320 .mPowderPatternCalc.data();
4321 const REAL *p2=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(j))
4322 .mPowderPatternCalc.data();
4325 for(
int k=0;k<nbExclude;k++)
4329 if(min>mNbPointUsed)
break;
4330 if(max>mNbPointUsed)max=mNbPointUsed;
4332 for(;l<min;l++) m += *p1++ * *p2++;
4337 for(;l<mNbPointUsed;l++) m += *p1++ * *p2++;
4338 mFitScaleFactorM(i,j)=m;
4339 mFitScaleFactorM(j,i)=m;
4342 for(
int i=0;i<nbScale;i++)
4345 const REAL *p2=mPowderPatternComponentRegistry
4346 .GetObj(mScalableComponentIndex(i))
4347 .mPowderPatternCalc.data();
4352 for(
int k=0;k<nbExclude;k++)
4356 if(min>mNbPointUsed)
break;
4357 if(max>mNbPointUsed)max=mNbPointUsed;
4359 for(;l<min;l++) b += *p1++ * *p2++;
4364 for(;l<mNbPointUsed;l++) b += *p1++ * *p2++;
4369 for(
int k=0;k<nbExclude;k++)
4373 if(min>mNbPointUsed)
break;
4374 if(max>mNbPointUsed)max=mNbPointUsed;
4376 for(;l<min;l++) b += (*p1++ - *p3++) * *p2++;
4381 for(;l<mNbPointUsed;l++) b += (*p1++ - *p3++) * *p2++;
4383 mFitScaleFactorB(i,0) =b;
4386 if(1==nbScale) mFitScaleFactorX=mFitScaleFactorB(0)/mFitScaleFactorM(0);
4388 mFitScaleFactorX=product(InvertMatrix(mFitScaleFactorM),mFitScaleFactorB);
4389 VFN_DEBUG_MESSAGE(
"B, M, X"<<endl<<mFitScaleFactorB<<endl<<mFitScaleFactorM<<endl<<mFitScaleFactorX,2)
4390 for(
int i=0;i<nbScale;i++)
4392 const REAL * p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4393 .mPowderPatternCalc.data();
4395 const REAL s = mFitScaleFactorX(i)
4396 -mScaleFactor(mScalableComponentIndex(i));
4399 (*fpObjCrystInformUser)(
"Warning: working around NaN scale factor...");
4402 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += s * *p1++;
4403 VFN_DEBUG_MESSAGE(
"-> Old:"<<mScaleFactor(mScalableComponentIndex(i)) <<
" Change:"<<mFitScaleFactorX(i),2);
4404 mScaleFactor(mScalableComponentIndex(i)) = mFitScaleFactorX(i);
4408 VFN_DEBUG_EXIT(
"PowderPattern::FitScaleFactorForR():End",3);
4411 void PowderPattern::FitScaleFactorForIntegratedR()
const
4420 VFN_DEBUG_ENTRY(
"PowderPattern::FitScaleFactorForIntegratedR()",3);
4421 TAU_PROFILE(
"PowderPattern::FitScaleFactorForIntegratedR()",
"void ()",TAU_DEFAULT);
4423 mScalableComponentIndex.resize(mPowderPatternComponentRegistry.GetNb());
4425 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
4427 if(mPowderPatternComponentRegistry.GetObj(i).IsScalable())
4428 mScalableComponentIndex(nbScale++)=i;
4430 VFN_DEBUG_MESSAGE(
"-> Number of Scale Factors:"<<nbScale<<
":Index:"<<endl<<mScalableComponentIndex,2);
4433 VFN_DEBUG_EXIT(
"PowderPattern::FitScaleFactorForIntegratedR(): No scalable component!",3);
4436 mScalableComponentIndex.resizeAndPreserve(nbScale);
4438 mFitScaleFactorM.resize(nbScale,nbScale);
4439 mFitScaleFactorB.resize(nbScale,1);
4440 mFitScaleFactorX.resize(nbScale,1);
4442 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedR():1",2);
4443 const long numInterval=mIntegratedPatternMin.numElements();
4444 CrystVector_REAL *integratedCalc=
new CrystVector_REAL[nbScale];
4445 for(
int i=0;i<nbScale;i++)
4447 integratedCalc[i].resize(numInterval);
4451 const REAL *p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4452 .mPowderPatternCalc.data();
4454 REAL *p2=integratedCalc[i].data();
4455 for(
int j=0;j<numInterval;j++)
4457 const long max=mIntegratedPatternMax(j);
4458 p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4459 .mPowderPatternCalc.data()+mIntegratedPatternMin(j);
4461 for(
int k=mIntegratedPatternMin(j);k<=max;k++) *p2 += *p1++;
4468 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedR():2",2);
4469 CrystVector_REAL backdIntegrated(numInterval);
4473 REAL *p2=backdIntegrated.data();
4474 for(
int j=0;j<numInterval;j++)
4476 const long max=mIntegratedPatternMax(j);
4479 for(
int k=mIntegratedPatternMin(j);k<=max;k++) *p2 += *p1++;
4491 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedR():3",2);
4492 for(
int i=0;i<nbScale;i++)
4494 for(
int j=i;j<nbScale;j++)
4496 const REAL *p1=integratedCalc[i].data();
4497 const REAL *p2=integratedCalc[j].data();
4499 for(
long k=0;k<numInterval;k++)
4504 mFitScaleFactorM(i,j)=m;
4505 mFitScaleFactorM(j,i)=m;
4508 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedR():4",2);
4509 for(
int i=0;i<nbScale;i++)
4511 const REAL *p1=mIntegratedObs.data();
4512 const REAL *p2=integratedCalc[i].data();
4515 for(
long k=0;k<numInterval;k++)
4522 const REAL *p3=backdIntegrated.data();
4523 for(
long k=0;k<numInterval;k++)
4528 b += (*p1++ - *p3++) * *p2++;
4531 mFitScaleFactorB(i,0) =b;
4533 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedR():5",2);
4535 if(1==nbScale) mFitScaleFactorX=mFitScaleFactorB(0)/mFitScaleFactorM(0);
4537 mFitScaleFactorX=product(InvertMatrix(mFitScaleFactorM),mFitScaleFactorB);
4538 VFN_DEBUG_MESSAGE(
"B, M, X"<<endl<<mFitScaleFactorB<<endl<<mFitScaleFactorM<<endl<<mFitScaleFactorX,3)
4539 for(
int i=0;i<nbScale;i++)
4541 const REAL * p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4542 .mPowderPatternCalc.data();
4544 const REAL s = mFitScaleFactorX(i)
4545 -mScaleFactor(mScalableComponentIndex(i));
4548 (*fpObjCrystInformUser)(
"Warning: working around NaN scale factor...");
4551 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += s * *p1++;
4552 VFN_DEBUG_MESSAGE(
"-> Old:"<<mScaleFactor(mScalableComponentIndex(i)) <<
" New:"<<mFitScaleFactorX(i),3);
4553 mScaleFactor(mScalableComponentIndex(i)) = mFitScaleFactorX(i);
4557 delete[] integratedCalc;
4558 VFN_DEBUG_EXIT(
"PowderPattern::FitScaleFactorForIntegratedR():End",3);
4568 TAU_PROFILE(
"PowderPattern::FitScaleFactorForRw()",
"void ()",TAU_DEFAULT);
4569 VFN_DEBUG_ENTRY(
"PowderPattern::FitScaleFactorForRw()",3);
4573 mScalableComponentIndex.resize(mPowderPatternComponentRegistry.GetNb());
4575 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
4577 if(mPowderPatternComponentRegistry.GetObj(i).IsScalable())
4578 mScalableComponentIndex(nbScale++)=i;
4580 VFN_DEBUG_MESSAGE(
"-> Number of Scale Factors:"<<nbScale<<
":Index:"<<endl<<mScalableComponentIndex,2);
4583 VFN_DEBUG_EXIT(
"PowderPattern::FitScaleFactorForRw(): No scalable component!",3);
4586 mScalableComponentIndex.resizeAndPreserve(nbScale);
4588 mFitScaleFactorM.resize(nbScale,nbScale);
4589 mFitScaleFactorB.resize(nbScale,1);
4590 mFitScaleFactorX.resize(nbScale,1);
4595 for(
int i=0;i<nbScale;i++)
4597 for(
int j=i;j<nbScale;j++)
4601 const REAL *p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4602 .mPowderPatternCalc.data();
4603 const REAL *p2=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(j))
4604 .mPowderPatternCalc.data();
4607 for(
unsigned long k=0;k<mNbPointUsed;k++) m += *p1++ * *p2++ * *p3++;
4608 mFitScaleFactorM(i,j)=m;
4609 mFitScaleFactorM(j,i)=m;
4612 for(
int i=0;i<nbScale;i++)
4615 const REAL *p2=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4616 .mPowderPatternCalc.data();
4620 for(
unsigned long k=0;k<mNbPointUsed;k++) b += *p1++ * *p2++ * *p3++;
4624 for(
unsigned long k=0;k<mNbPointUsed;k++)
4625 b += (*p1++ - *p4++) * *p2++ * *p3++;
4627 mFitScaleFactorB(i,0) =b;
4632 unsigned long min,max;
4633 for(
int i=0;i<nbScale;i++)
4635 for(
int j=i;j<nbScale;j++)
4639 const REAL *p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4640 .mPowderPatternCalc.data();
4641 const REAL *p2=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(j))
4642 .mPowderPatternCalc.data();
4646 for(
int k=0;k<nbExclude;k++)
4650 if(min>mNbPointUsed)
break;
4651 if(max>mNbPointUsed)max=mNbPointUsed;
4653 for(;l<min;l++) m += *p1++ * *p2++ * *p3++;
4659 for(;l<mNbPointUsed;l++) m += *p1++ * *p2++ * *p3++;
4660 mFitScaleFactorM(i,j)=m;
4661 mFitScaleFactorM(j,i)=m;
4664 for(
int i=0;i<nbScale;i++)
4667 const REAL *p2=mPowderPatternComponentRegistry
4668 .GetObj(mScalableComponentIndex(i))
4669 .mPowderPatternCalc.data();
4675 for(
int k=0;k<nbExclude;k++)
4679 if(min>mNbPointUsed)
break;
4680 if(max>mNbPointUsed)max=mNbPointUsed;
4682 for(;l<min;l++) b += *p1++ * *p2++ * *p3++;
4688 for(;l<mNbPointUsed;l++) b += *p1++ * *p2++ * *p3++;
4693 for(
int k=0;k<nbExclude;k++)
4697 if(min>mNbPointUsed)
break;
4698 if(max>mNbPointUsed)max=mNbPointUsed;
4700 for(;l<min;l++) b += (*p1++ - *p4++) * *p2++ * *p3++;
4706 for(;l<mNbPointUsed;l++) b += (*p1++ - *p4++) * *p2++ * *p3++;
4708 mFitScaleFactorB(i,0) =b;
4711 if(1==nbScale) mFitScaleFactorX=mFitScaleFactorB(0)/mFitScaleFactorM(0);
4713 mFitScaleFactorX=product(InvertMatrix(mFitScaleFactorM),mFitScaleFactorB);
4714 VFN_DEBUG_MESSAGE(
"B, M, X"<<endl<<mFitScaleFactorB<<endl<<mFitScaleFactorM<<endl<<mFitScaleFactorX,2)
4715 for(
int i=0;i<nbScale;i++)
4717 const REAL * p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4718 .mPowderPatternCalc.data();
4720 const REAL s = mFitScaleFactorX(i)
4721 -mScaleFactor(mScalableComponentIndex(i));
4724 (*fpObjCrystInformUser)(
"Warning: working around NaN scale factor...");
4727 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += s * *p1++;
4728 VFN_DEBUG_MESSAGE(
"-> Old:"<<mScaleFactor(mScalableComponentIndex(i)) <<
" Change:"<<mFitScaleFactorX(i),3);
4729 mScaleFactor(mScalableComponentIndex(i)) = mFitScaleFactorX(i);
4733 VFN_DEBUG_EXIT(
"PowderPattern::FitScaleFactorForRw():End",3);
4736 void PowderPattern::FitScaleFactorForIntegratedRw()
const
4745 VFN_DEBUG_ENTRY(
"PowderPattern::FitScaleFactorForIntegratedRw()",3);
4746 TAU_PROFILE(
"PowderPattern::FitScaleFactorForIntegratedRw()",
"void ()",TAU_DEFAULT);
4748 mScalableComponentIndex.resize(mPowderPatternComponentRegistry.GetNb());
4749 CrystVector_REAL vScalableVarianceIndex(mPowderPatternComponentRegistry.GetNb());
4752 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
4754 if(mPowderPatternComponentRegistry.GetObj(i).IsScalable())
4755 mScalableComponentIndex(nbScale++)=i;
4756 if(mPowderPatternComponentRegistry.GetObj(i).HasPowderPatternCalcVariance())
4758 if(0!=mPowderPatternComponentRegistry.GetObj(i)
4759 .GetPowderPatternIntegratedCalcVariance().first->numElements())
4760 vScalableVarianceIndex(nbVarCalc++)=i;
4763 VFN_DEBUG_MESSAGE(
"-> Number of Scale Factors:"<<nbScale<<
"("<<nbVarCalc
4764 <<
"with variance). Index:"<<endl<<mScalableComponentIndex,2);
4767 VFN_DEBUG_EXIT(
"PowderPattern::FitScaleFactorForIntegratedRw(): No scalable component!",3);
4771 unsigned int ctagain=0;
4772 RECALC_SCALE_FACTOR_VARIANCE_FitScaleFactorForIntegratedRw:
4776 double a=0.,b=0.,c=0.;
4779 const REAL * RESTRICT p1=mIntegratedObs.data();
4780 const REAL * RESTRICT p2=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(0))
4781 .GetPowderPatternIntegratedCalc().first->data();
4782 const REAL * RESTRICT p1v=mIntegratedVarianceObs.data();
4783 const REAL * RESTRICT p2v=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(0))
4784 .GetPowderPatternIntegratedCalcVariance().first->data();
4787 for(
unsigned long k=mNbIntegrationUsed;k>0;k--)
4789 a += *p2v * *p1 * *p2;
4790 b += *p2 * *p2 * *p1v - *p1 * *p1 * *p2v;
4791 c -= *p1 * *p2 * *p1v;
4792 p1++;p2++;p1v++;p2v++;
4798 for(
unsigned long k=mNbIntegrationUsed;k>0;k--)
4800 a += *p2v * (*p1 - *p3) * *p2;
4801 b += *p2 * *p2 * *p1v - (*p1 - *p3) * (*p1 - *p3) * *p2v;
4802 c -= (*p1 - *p3) * *p2 * *p1v;
4803 p1++;p2++;p1v++;p2v++;p3++;
4807 newscale=(REAL)((-b+sqrt(b*b-4*a*c))/(2*a));
4810 const REAL s = newscale-mScaleFactor(mScalableComponentIndex(0));
4811 const REAL s2 = newscale*newscale
4812 -mScaleFactor(mScalableComponentIndex(0))
4813 *mScaleFactor(mScalableComponentIndex(0));
4815 const REAL * RESTRICT p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(0))
4816 .GetPowderPatternIntegratedCalc().first->data();
4818 const REAL * RESTRICT p1v=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(0))
4819 .GetPowderPatternIntegratedCalcVariance().first->data();
4820 REAL * RESTRICT p0w = mIntegratedWeight.data();
4821 for(
unsigned long j=mNbIntegrationUsed;j>0;j--)
4824 *p0v += s2 * *p1v++;
4825 if(*p0v <=0) {*p0w++ =0;p0v++;}
else *p0w++ = 1. / *p0v++;
4828 mScaleFactor(mScalableComponentIndex(0)) = newscale;
4835 mScalableComponentIndex.resizeAndPreserve(nbScale);
4837 mFitScaleFactorM.resize(nbScale,nbScale);
4838 mFitScaleFactorB.resize(nbScale,1);
4839 mFitScaleFactorX.resize(nbScale,1);
4841 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedRw():1",2);
4842 vector<const CrystVector_REAL*> integratedCalc;
4843 for(
int i=0;i<nbScale;i++)
4845 integratedCalc.push_back(mPowderPatternComponentRegistry.
4846 GetObj(mScalableComponentIndex(i))
4847 .GetPowderPatternIntegratedCalc().first);
4849 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedRw():3",2);
4850 for(
int i=0;i<nbScale;i++)
4852 for(
int j=i;j<nbScale;j++)
4854 const REAL * RESTRICT p1=integratedCalc[i]->data();
4855 const REAL * RESTRICT p2=integratedCalc[j]->data();
4856 const REAL * RESTRICT p3;
4857 if(mIntegratedWeight.numElements()==0)
4859 p3=mIntegratedWeightObs.data();
4860 if(ctagain>5) VFN_DEBUG_MESSAGE(
"ctagain="<<ctagain<<
", using mIntegratedWeightObs",5);
4864 p3=mIntegratedWeight.data();
4865 if(ctagain>5) VFN_DEBUG_MESSAGE(
"ctagain="<<ctagain<<
", using mIntegratedWeight",5);
4869 for(
unsigned long k=mNbIntegrationUsed;k>0;k--)
4870 {m += *p1 * *p1 * *p3++; p1++;}
4872 for(
unsigned long k=mNbIntegrationUsed;k>0;k--)
4873 m += *p1++ * *p2++ * *p3++;
4874 mFitScaleFactorM(i,j)=m;
4875 mFitScaleFactorM(j,i)=m;
4878 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedRw():4",2);
4879 for(
int i=0;i<nbScale;i++)
4881 const REAL * RESTRICT p1=mIntegratedObs.data();
4882 const REAL * RESTRICT p2=integratedCalc[i]->data();
4883 const REAL * RESTRICT p4;
4884 if(mIntegratedWeight.numElements()==0) p4=mIntegratedWeightObs.data();
4885 else p4=mIntegratedWeight.data();
4889 for(
unsigned long k=mNbIntegrationUsed;k>0;k--)
4891 b += *p1++ * *p2++ * *p4++;
4898 for(
unsigned long k=mNbIntegrationUsed;k>0;k--)
4903 b += (*p1++ - *p3++) * *p2++ * *p4++;
4906 mFitScaleFactorB(i,0) =b;
4908 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedRw():5",2);
4910 if(1==nbScale) mFitScaleFactorX=mFitScaleFactorB(0)/mFitScaleFactorM(0);
4912 mFitScaleFactorX=product(InvertMatrix(mFitScaleFactorM),mFitScaleFactorB);
4913 VFN_DEBUG_MESSAGE(
"B, M, X"<<endl<<mFitScaleFactorB<<endl<<mFitScaleFactorM<<endl<<mFitScaleFactorX,3)
4918 for(
int i=0;i<nbScale;i++)
4920 if(mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i)).HasPowderPatternCalcVariance())
4922 if(0!=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4923 .GetPowderPatternIntegratedCalcVariance().first->numElements())
4925 const REAL * RESTRICT p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4926 .GetPowderPatternIntegratedCalcVariance().first->data();
4930 const REAL s2 = mFitScaleFactorX(i)*mFitScaleFactorX(i)
4931 -mScaleFactor(mScalableComponentIndex(i))
4932 *mScaleFactor(mScalableComponentIndex(i));
4933 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ += s2 * *p1++;
4939 REAL * RESTRICT p0 = mIntegratedWeight.data();
4941 for(
unsigned long j=mNbIntegrationUsed;j>0;j--)
4942 if(*p1 <=0) {*p0++ =0;p1++;}
4943 else *p0++ = 1. / *p1++;
4947 for(
int i=0;i<nbScale;i++)
4949 const REAL * RESTRICT p1=mPowderPatternComponentRegistry.GetObj(mScalableComponentIndex(i))
4950 .GetPowderPatternIntegratedCalc().first->data();
4952 const REAL s = mFitScaleFactorX(i)
4953 -mScaleFactor(mScalableComponentIndex(i));
4956 (*fpObjCrystInformUser)(
"Warning: working around NaN scale factor...");
4961 if(abs(s/mFitScaleFactorX(i))>0.001)
4967 if((!again)&&(ctagain>0))
4969 VFN_DEBUG_MESSAGE(
"log(scale) :"<<log(mScaleFactor(mScalableComponentIndex(i)))
4970 <<
"->"<<log(mFitScaleFactorX(i))<<
" Again="<<ctagain,5);
4973 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ += s * *p1++;
4976 VFN_DEBUG_MESSAGE(
"->log(scale) Old :"<<log(mScaleFactor(mScalableComponentIndex(i))) <<
" New:"<<log(mFitScaleFactorX(i)),10);
4978 mScaleFactor(mScalableComponentIndex(i)) = mFitScaleFactorX(i);
4984 if(again && (ctagain<20))
4989 VFN_DEBUG_MESSAGE(
"PowderPattern::FitScaleFactorForIntegratedRw(), scaling again #"<<ctagain,10)
4991 goto RECALC_SCALE_FACTOR_VARIANCE_FitScaleFactorForIntegratedRw;
4993 VFN_DEBUG_EXIT(
"PowderPattern::FitScaleFactorForIntegratedRw():End",3);
4998 VFN_DEBUG_MESSAGE(
"PowderPattern::SetSigmaToSqrtIobs()",5);
5004 VFN_DEBUG_MESSAGE(
"PowderPattern::SetWeightToInvSigmaSq()",5);
5018 VFN_DEBUG_MESSAGE(
"PowderPattern::SetWeightToSinTheta()",5);
5024 const REAL minRelatIobs)
5026 VFN_DEBUG_MESSAGE(
"PowderPattern::SetWeightPolynomial()",5);
5039 const bool enableRestraints)
5042 if(0 == mOptProfileIntegration.GetChoice()) this->FitScaleFactorForIntegratedRw();
5064 VFN_DEBUG_MESSAGE(
"PowderPattern::AddExcludedRegion()",5)
5080 CrystVector_long subs;
5082 CrystVector_REAL tmp1,tmp2;
5091 VFN_DEBUG_MESSAGE(
"PowderPattern::Add2ThetaExcludedRegion():End",5)
5097 if(mOptProfileIntegration.GetChoice()==0) tmp+=mIntegratedChi2LikeNorm;
5098 else tmp+=mChi2LikeNorm;
5104 const CrystVector_REAL&
5107 TAU_PROFILE(
"PowderPattern::GetLSQCalc()",
"void ()",TAU_DEFAULT);
5126 const CrystVector_REAL&
5129 TAU_PROFILE(
"PowderPattern::GetLSQObs()",
"void ()",TAU_DEFAULT);
5148 const CrystVector_REAL&
5151 TAU_PROFILE(
"PowderPattern::GetLSQWeight()",
"void ()",TAU_DEFAULT);
5159 if(mIntegratedWeight.numElements()==0)
5176 TAU_PROFILE(
"PowderPattern::GetLSQ_FullDeriv()",
"void ()",TAU_DEFAULT);
5180 this->CalcPowderPatternIntegrated_FullDeriv(vPar);
5182 std::map<RefinablePar*, CrystVector_REAL> fullderiv_old;
5183 std::vector<const CrystVector_REAL*> v;
5186 cout<<
"PowderPattern::GetLSQ_FullDeriv(integrated):parameters:"<<endl;
5187 for(std::set<RefinablePar*>::iterator par=vPar.begin();par!=vPar.end();++par)
5189 v.push_back(&(mPowderPatternIntegrated_FullDeriv[*par]));
5190 fullderiv_old[*par]=this->
GetLSQDeriv(idx,*(*par));
5191 v.push_back(&(fullderiv_old[*par]));
5192 cout<<(*par)->GetName()<<
":"<<mPowderPatternIntegrated_FullDeriv[*par].size()<<
","<<fullderiv_old[*par].size()<<endl;
5195 cout<<
"PowderPattern::GetLSQ_FullDeriv(integrated):"<<endl<<FormatVertVector<REAL>(v,12,1,20)<<endl;
5198 return mPowderPatternIntegrated_FullDeriv;
5200 mPowderPattern_FullDeriv=this->GetPowderPattern_FullDeriv(vPar);
5201 return mPowderPattern_FullDeriv;
5206 VFN_DEBUG_MESSAGE(
"PowderPattern::Prepare()",5);
5207 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
5210 mPowderPatternComponentRegistry.GetObj(i).Prepare();
5214 CrystVector_uint & groupIndex,
5215 unsigned int &first)
const
5218 unsigned int scaleIndex=0;
5219 unsigned int thetaIndex=0;
5220 VFN_DEBUG_MESSAGE(
"PowderPattern::GetGeneGroup()",4)
5222 for(
long j=0;j<this->
GetNbPar();j++)
5227 if(scaleIndex==0) scaleIndex=first++;
5228 groupIndex(i)=scaleIndex;
5232 if(thetaIndex==0) thetaIndex=first++;
5233 groupIndex(i)=thetaIndex;
5245 return mIntegratedPatternMin;
5251 return mIntegratedPatternMax;
5256 return mClockIntegratedFactorsPrep;
5262 if(this->
GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
5264 if(stol>0) x = 1.0/(2*stol);
else return 0;
5265 x = mDIFC*x+mDIFA*x*x;
5266 VFN_DEBUG_MESSAGE(
"PowderPattern::STOL2X("<<stol<<
","<<1.0/(2*stol)<<
")="<<x,2)
5271 if(abs(x)<1.0) x=2*asin(x);
else x=2*M_PI;
5279 if(this->
GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
5281 if(abs(mDIFA)>abs(mDIFC*1e-6))
5283 const REAL delta=mDIFC*mDIFC+4.0*mDIFA*x;
5284 stol = (-mDIFC+sqrt(delta))/(2.0*mDIFA);
5285 stol = 1/(2.0*stol);
5287 else stol=mDIFC/(2.0*x);
5291 VFN_DEBUG_MESSAGE(
"PowderPattern::X2STOL("<<x<<
")="<<stol,2)
5305 if(this->
GetRadiation().GetWavelengthType()!=WAVELENGTH_TOF)
5308 for(finish=0;finish<nb;++finish)
5317 for(start=nb-1;start>=0;--start)
5324 unsigned int width_golay=10;
5326 CrystVector_REAL obs;
5327 const int nbwidth=9;
5328 CrystVector_long width(nbwidth);
5331 const long nb=obs.numElements();
5332 for(
int j=0;j<nbwidth;j++)
5334 const long imax=obs.imax(nb/10,nb-1);
5335 const REAL iobs_max=obs(imax);
5336 REAL thres=iobs_max;
5338 for(i=imax-100;i<(imax+100);++i)
5340 if(i<0){i=0;
continue;}
5342 if(obs(i)<thres) thres=obs(i);
5344 thres=(iobs_max+thres)/2;
5346 while(obs(i)>=thres)
5354 while(obs(i)>=thres)
5361 cout<<endl<<
" => "<<width(j)<<endl;
5362 for(i=imax-width(j)*2;i<(imax+width(j)*2);++i)
5369 cout<<
"Width of "<<nbwidth<<
" strongest peaks:"<<endl<<width;
5370 width_golay=width(SortSubs(width)(nbwidth/2));
5371 cout<<
"median width:"<<width_golay<<endl;
5372 if(width_golay<=4)width_golay=4;
5373 if(width_golay>=16)width_golay=16;
5377 CrystVector_REAL obsd2;
5379 const float norm=-obsd2.min();
5386 CrystVector_REAL tmp;
5388 tmp.resizeAndPreserve(tmp.numElements()/4);
5390 QuickSortSubs(tmp,sub,tmp.numElements()-1,0);
5391 min_iobs=5*(tmp(tmp.numElements()/2)-tmp(tmp.numElements()/4));
5398 const long imax=obsd2.imax(start,finish);
5399 REAL iobs=obsd2(imax);
5401 REAL xmax=
mX(imax)*iobs;
5404 REAL lastiobs=obsd2(i);
5405 const REAL iobs_max=lastiobs;
5410 if(obsd2(--i)>=lastiobs)
break;
5414 xmax+=
mX(i)*lastiobs;nbav++;
5415 if(lastiobs<=0)
break;
5418 float dleft=
mX(i+1);
5423 if(i>=(nb-2))
break;
5424 if(obsd2(++i)>=lastiobs)
break;
5428 xmax+=
mX(i)*lastiobs;nbav++;
5429 if(lastiobs<=0)
break;
5432 float dright=
mX(i-1);
5435 REAL dmax=this->
X2STOL(xmax)*2;
5436 dright=this->
X2STOL(dright)*2;
5437 dleft =this->
X2STOL(dleft)*2;
5442 min_iobs=iobs/nbav*maxratio;
5448 if(nbav_min<3)nbav_min=3;
5454 cout<<
"Peak #"<<pl.
GetPeakList().size()<<
"imax="<<imax<<
", x="<<xmax<<
",d="<<1/dmax<<
", d2iobs_max="<<iobs_max
5455 <<
", d2Iobs="<<iobs<<
", nbav="<<nbav<<
", min_iobs="<<min_iobs<<
",sigma="<<sigma<<endl;
5456 if( ((nbav>=nbav_min) &&(iobs_max>min_iobs)&&((iobs/nbav)>min_iobs))
5457 ||((nbav>=nbav_min) &&(iobs_max>min_iobs)&&((iobs/nbav)>min_iobs*.2)&&((iobs/nbav)>3*sigma))
5458 ||((nbav>=nbav_min/2)&&(iobs_max>min_iobs)&&((iobs/nbav)>min_iobs*2 )&&((iobs/nbav)>6*sigma)))
5460 pl.
AddPeak(dmax,iobs,abs(dright-dleft)*.25);
5461 if((pl.
GetPeakList().size()==1)&&(maxratio<0)&&(min_iobs<0.005*iobs/nbav)) min_iobs=0.005*iobs/nbav;
5475 exportAtom(
string n,REAL X, REAL Y, REAL Z,REAL b,REAL o,
const ScatteringPower *pow):
5476 name(n),x(X),y(Y),z(Z),biso(b),occ(o),occMult(1),mpScattPow(pow){}
5478 REAL x,y,z,biso,occ;
5481 const ScatteringPower *mpScattPow;
5486 exportBond(
const string &a1,
const string &a2, REAL d, REAL s):
5487 at1(a1),at2(a2),dist(d),sigma(s){}
5494 exportAngle(
const string &a1,
const string &a2,
const string &a3, REAL a, REAL s):
5495 at1(a1),at2(a2),at3(a3),ang(a),sigma(s){}
5504 vector<const PowderPatternDiffraction*> vDiff;
5510 vDiff.push_back(dynamic_cast<const PowderPatternDiffraction*>(&(this->GetPowderPatternComponent(i))));
5512 if((pBackground==0)||vDiff.size()==0)
return;
5515 ofstream dat((prefix+
".dat").c_str());
5517 <<
"INTER 1.0 1.0 0"<<endl<<endl<<endl<<endl<<endl;
5519 CrystVector_REAL ttheta;
5521 if(this->
GetRadiation().GetWavelengthType()!=WAVELENGTH_TOF) ttheta *= RAD2DEG;
5526 ofstream pcr((prefix+
".pcr").c_str());
5530 pcr<<
"Fox/ObjCryst exported file:"<<this->
GetName()<<endl;
5532 pcr<<
"NPATT 1"<<endl;
5534 pcr<<
"W_PAT 1.0"<<endl;
5536 pcr<<
"! Nph Dum Ias Nre Cry Opt Aut"<<endl;
5537 pcr<<
" "<<vDiff.size()
5538 <<
" 0 0 0 0 1 1 "<<endl;
5545 pcr<<
"! Job Npr Nba Nex Nsc Nor Iwg Ilo Res Ste Uni Cor Anm"<<endl
5547 <<
" 5 "<<pBackground->GetInterpPoints().first->numElements()
5548 <<
" 0 0 1 0 0 0 1 0 0 0"<<endl;
5553 std::string::size_type idx =prefix.rfind(
"/");
5554 std::string::size_type idx2=prefix.rfind(
"\\");
5555 std::string::size_type idx3=prefix.rfind(
":");
5556 if(((
long)idx2!=(
long)string::npos)&&((
long)idx2>(
long)idx))idx=idx2;
5557 if(((
long)idx3!=(
long)string::npos)&&((
long)idx3>(
long)idx))idx=idx3;
5558 if(idx==string::npos)
5561 shortName=prefix.substr(idx+1);
5563 pcr<<
"! File names of data files"<<endl;
5564 pcr<<shortName<<
".dat"<<endl;
5566 pcr<<
"! Mat Pcr Syo Rpa Sym Sho"<<endl
5567 <<
" 1 1 0 -1 0 0 "<<endl;
5569 pcr<<
"! Ipr Ppl Ioc Ls1 Ls2 Ls3 Prf Ins Hkl Fou Ana"<<endl
5570 <<
" 0 0 0 0 0 0 1 10 0 0 1 "<<endl;
5574 pcr<<
"!lambda1 lambda2 Ratio Bkpos Wdt Cthm muR AsyLim Rpolarz -> Patt #1"<<endl
5577 <<
" 0 0 0 0.95"<<endl;
5579 pcr<<
"!NCY Eps R_at R_an R_pr R_gl"<<endl
5580 <<
" 5 0.2 1.0 1.0 1.0 1.0"<<endl;
5582 pcr<<
"! Thmin Step Thmax PSD Sent0 -> Patt #1"<<endl
5583 <<
" 0 0 0 0 0"<<endl;
5585 pcr<<
"!2Theta Background for Pattern #1"<<endl;
5586 for(
long i=0;i<pBackground->GetInterpPoints().first->numElements();i++)
5587 pcr<<(*(pBackground->GetInterpPoints().first))(i)*RAD2DEG<<
" "
5588 <<(*(pBackground->GetInterpPoints().second))(i)<<
" 0.0"<<endl;
5590 pcr<<
"!"<<endl<<
"!"<<endl<<
"1 !Number of refined parameters"<<endl;
5592 pcr<<
"! Zero Code Sycos Code Sysin Code Lambda Code More -> Patt #1"<<endl;
5593 pcr<<
" "<<
mXZero*RAD2DEG <<
" 0.0 "
5594 <<m2ThetaDisplacement*RAD2DEG <<
" 0.0 "
5595 <<m2ThetaTransparency*RAD2DEG <<
" 0.0 "
5596 <<
"0.000 0.0 0"<<endl;
5598 for(
unsigned int i=0;i<vDiff.size();++i)
5600 pcr<<
"!-------------------------------------------------------------------------------"<<endl
5601 <<
"! Data for PHASE number: "<<i<<
" ==> Current R_Bragg for Pattern# 1: 0.00 "<<endl
5602 <<
"!-------------------------------------------------------------------------------"<<endl;
5604 pcr<<vDiff[i]->GetCrystal().GetName()<<endl;
5607 map<int,exportAtom> vExportAtom;
5608 list<exportBond> vExportBond;
5609 list<exportAngle> vExportAngle;
5611 CrystMatrix_REAL minDistTable;
5612 minDistTable=vDiff[i]->GetCrystal().GetMinDistanceTable(-1.);
5617 for(
int s=0;s<vDiff[i]->GetCrystal().GetScattererRegistry().GetNb();s++)
5624 if(vDiff[i]->GetCrystal().GetScatt(s).
GetClassName()==
"Molecule")
5625 pMol=
dynamic_cast<const Molecule*
>(&(vDiff[i]->GetCrystal().GetScatt(s)));
5626 map<const MolAtom*,string> vMolAtomName;
5630 if(0==list(j).mpScattPow)
continue;
5631 bool redundant=
false;
5632 for(
unsigned long l=0;l<k;++l)
5633 if(abs(minDistTable(l,k))<0.5)
5635 map<int,exportAtom>::iterator pos=vExportAtom.find(l);
5636 if(pos!=vExportAtom.end()) pos->second.occMult+=1;
5643 name<<list(j).mpScattPow->GetName()<<k+1;
5644 vExportAtom.insert(make_pair(k,exportAtom(name.str(),
5645 list(j).mX,list(j).mY,list(j).mZ,
5646 list(j).mpScattPow->GetBiso(),
5647 list(j).mOccupancy*list0(k).mDynPopCorr,
5648 list(j).mpScattPow)));
5649 if(pMol!=0) vMolAtomName.insert(make_pair(pMol->GetAtomList()[j],name.str()));
5655 for(vector<MolBond*>::const_iterator pos=pMol->GetBondList().begin();
5656 pos!=pMol->GetBondList().end();++pos)
5658 map<const MolAtom*,string>::const_iterator p1,p2;
5659 p1=vMolAtomName.find(&((*pos)->GetAtom1()));
5660 p2=vMolAtomName.find(&((*pos)->GetAtom2()));
5661 if( (p1!=vMolAtomName.end()) && (p2!=vMolAtomName.end()))
5662 vExportBond.push_back(exportBond(p1->second, p2->second,
5663 (*pos)->GetLength0(),(*pos)->GetLengthSigma()));
5666 for(vector<MolBondAngle*>::const_iterator pos=pMol->GetBondAngleList().begin();
5667 pos!=pMol->GetBondAngleList().end();++pos)
5669 map<const MolAtom*,string>::const_iterator p1,p2,p3;
5670 p1=vMolAtomName.find(&((*pos)->GetAtom1()));
5671 p2=vMolAtomName.find(&((*pos)->GetAtom2()));
5672 p3=vMolAtomName.find(&((*pos)->GetAtom3()));
5673 if( (p1!=vMolAtomName.end()) && (p2!=vMolAtomName.end()) && (p3!=vMolAtomName.end()))
5674 vExportAngle.push_back(exportAngle(p1->second, p2->second,p3->second,
5675 (*pos)->GetAngle0(),(*pos)->GetAngleSigma()));
5686 pcr<<
"!Nat Dis Ang Jbt Isy Str Furth ATZ Nvk More"<<endl
5687 << vExportAtom.size() <<
" "<<vExportBond.size()<<
" "<<vExportAngle.size()
5688 <<
" 0 0 0 0 1.0 0 1"<<endl;
5689 pcr<<
"!Jvi Jdi Hel Sol Mom Ter N_Domains"<<endl
5690 <<
" 0 3 0 0 0 0 0"<<endl;
5692 pcr<<
"!Contributions (0/1) of this phase to the patterns"<<endl
5695 pcr<<
"!Irf Npr Jtyp Nsp_Ref Ph_Shift for Pattern#"<<i<<endl
5696 <<
" 0 0 0 0 0"<<endl;
5697 pcr<<
"! Pr1 Pr2 Pr3 Brind. Rmua Rmub Rmuc for Pattern#"<<i<<endl
5698 <<
" 1.0 1.0 1.0 1.0 0.0 0.0 0.0"<<endl;
5701 pcr<<
"! Max_dst(dist) (angles) Bond-Valence Calc."<<endl
5702 <<
" 2.7000 1.5000 0"<<endl;
5705 pcr<<vDiff[i]->GetCrystal().GetSpaceGroup().GetCCTbxSpg().match_tabulated_settings().hermann_mauguin()
5706 <<
" <- Space Group Symbol"<<endl;
5708 pcr<<
"!Atom Typ X Y Z Biso Occ In Fin N_t Spc / Codes"<<endl;
5709 for(map<int,exportAtom>::const_iterator pos=vExportAtom.begin();pos!=vExportAtom.end();++pos)
5711 pcr<<pos->second.name
5712 <<
" "<<pos->second.mpScattPow->GetSymbol()<<
" "
5713 <<pos->second.x<<
" "<<pos->second.y<<
" "<<pos->second.z<<
" "
5714 <<pos->second.biso<<
" "
5715 <<pos->second.occ*pos->second.occMult<<
" 0 0 0 0"<<endl
5716 <<
" 0 0 0 0 0"<<endl;
5719 REAL eta0=vDiff[0]->GetProfile().GetPar(
"Eta0").GetHumanValue();
5720 if(eta0<.01) eta0=.01;
5721 else if(eta0>.99) eta0=.99;
5722 pcr<<
"!Scale Shape1 Bov Str1 Str2 Str3 Strain-Model"<<endl
5724 <<
" 0.0 0.0 0.0 0.0 0"<<endl
5725 <<
" 1.0 0.0 0.0 0.0 0.0 0.0 0"<<endl;
5728 pcr<<
"! U V W X Y GauSiz LorSiz Size-Model"<<endl;
5731 pcr<<vDiff[i]->GetProfile().GetPar(
"U").GetHumanValue()<<
" ";
5732 pcr<<vDiff[i]->GetProfile().GetPar(
"V").GetHumanValue()<<
" ";
5733 pcr<<vDiff[i]->GetProfile().GetPar(
"W").GetHumanValue()<<
" ";
5734 pcr<<
" 0.0 0.0 0.0 0.0 "<<endl
5735 <<
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 "<<endl;
5737 pcr<<
"! a b c alpha beta gamma #Cell Info"<<endl
5738 <<vDiff[i]->GetCrystal().GetLatticePar(0)<<
" "
5739 <<vDiff[i]->GetCrystal().GetLatticePar(1)<<
" "
5740 <<vDiff[i]->GetCrystal().GetLatticePar(2)<<
" "
5741 <<vDiff[i]->GetCrystal().GetLatticePar(3)*RAD2DEG<<
" "
5742 <<vDiff[i]->GetCrystal().GetLatticePar(4)*RAD2DEG<<
" "
5743 <<vDiff[i]->GetCrystal().GetLatticePar(5)*RAD2DEG<<endl
5744 <<
" 0.0 0.0 0.0 0.0 0.0 0.0"<<endl;
5745 pcr<<
"! Pref1 Pref2 alpha0 beta0 alpha1 beta1 ?"<<endl
5746 <<
" 0.0 0.0 0.0 0.0 0.0 0.0"<<endl
5747 <<
" 0.0 0.0 0.0 0.0 0.0 0.0"<<endl;
5751 if(vExportBond.size()>0)
5753 pcr<<
"!Soft distance constraints"<<endl;
5754 for(list<exportBond>::const_iterator pos=vExportBond.begin();pos!=vExportBond.end();++pos)
5756 pcr<<pos->at1<<
" "<<pos->at2<<
" 1 0 0 0 "<<pos->dist<<
" "<<pos->sigma<<endl;
5759 if(vExportBond.size()>0)
5761 pcr<<
"!Soft angle constraints"<<endl;
5762 for(list<exportAngle>::const_iterator pos=vExportAngle.begin();pos!=vExportAngle.end();++pos)
5764 pcr<<pos->at1<<
" "<<pos->at2<<
" "<<pos->at3<<
" 1 1 0 0 0 0 0 0 "
5765 <<pos->ang*RAD2DEG<<
" "<<pos->sigma*RAD2DEG<<endl;
5777 TAU_PROFILE(
"PowderPattern::CalcPowderPattern()",
"void ()",TAU_DEFAULT);
5778 VFN_DEBUG_ENTRY(
"PowderPattern::CalcPowderPattern()",3);
5779 if(mPowderPatternComponentRegistry.GetNb()==0)
5790 for(
unsigned long j=0;j<
mNbPoint;j++)
5792 if(*p0 <=0) {*p1 =0.;}
5793 else *p1 = 1. / *p0;
5796 VFN_DEBUG_EXIT(
"PowderPattern::CalcPowderPattern():no components!",3);
5799 TAU_PROFILE_TIMER(timer1,
"PowderPattern::CalcPowderPattern1()Calc components",
"", TAU_FIELD);
5800 TAU_PROFILE_TIMER(timer2,
"PowderPattern::CalcPowderPattern2(Add spectrums-scaled)"\
5802 TAU_PROFILE_TIMER(timer3,
"PowderPattern::CalcPowderPattern2(Add spectrums-backgd1)"\
5804 TAU_PROFILE_TIMER(timer4,
"PowderPattern::CalcPowderPattern2(Add spectrums-backgd2)"\
5806 TAU_PROFILE_TIMER(timer5,
"PowderPattern::CalcPowderPattern3(Variance)",
"", TAU_FIELD);
5807 TAU_PROFILE_START(timer1);
5808 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
5809 mPowderPatternComponentRegistry.GetObj(i).CalcPowderPattern();
5810 TAU_PROFILE_STOP(timer1);
5811 VFN_DEBUG_MESSAGE(
"PowderPattern::CalcPowderPattern():Calculated components..",3);
5818 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
5820 mPowderPatternComponentRegistry.GetObj(i).GetClockPowderPatternCalc())
5828 VFN_DEBUG_EXIT(
"PowderPattern::CalcPowderPattern():no need to recalc",3);
5833 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
5835 VFN_DEBUG_MESSAGE(
"PowderPattern::CalcPowderPattern():Adding "<< mPowderPatternComponentRegistry.GetObj(i).GetName(),3);
5836 if(
true==mPowderPatternComponentRegistry.GetObj(i).IsScalable())
5838 TAU_PROFILE_START(timer2);
5841 const REAL * p1=mPowderPatternComponentRegistry.GetObj(i)
5842 .mPowderPatternCalc.data();
5844 const REAL s = mScaleFactor(i);
5845 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ = s * *p1++;
5850 const REAL * p1=mPowderPatternComponentRegistry.GetObj(i)
5851 .mPowderPatternCalc.data();
5853 const REAL s = mScaleFactor(i);
5854 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += s * *p1++;
5856 TAU_PROFILE_STOP (timer2);
5860 TAU_PROFILE_START(timer3);
5863 const REAL * p1=mPowderPatternComponentRegistry.GetObj(i)
5864 .mPowderPatternCalc.data();
5866 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ = *p1++;
5871 const REAL * p1=mPowderPatternComponentRegistry.GetObj(i)
5872 .mPowderPatternCalc.data();
5874 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += *p1++;
5877 TAU_PROFILE_STOP(timer3);
5878 TAU_PROFILE_START(timer4);
5884 const REAL *p1=mPowderPatternComponentRegistry.GetObj(i)
5885 .mPowderPatternCalc.data();
5886 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ = *p1++;
5892 const REAL *p1=mPowderPatternComponentRegistry.GetObj(i)
5893 .mPowderPatternCalc.data();
5894 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += *p1++;
5897 TAU_PROFILE_STOP(timer4);
5902 TAU_PROFILE_START(timer5);
5905 VFN_DEBUG_MESSAGE(
"PowderPattern::CalcPowderPattern():variance",2);
5908 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
5910 if(mPowderPatternComponentRegistry.GetObj(i).HasPowderPatternCalcVariance())
5912 if(0==mPowderPatternComponentRegistry.GetObj(i).GetPowderPatternCalcVariance()
5913 .numElements())
break;
5916 const REAL *p1=mPowderPatternComponentRegistry.GetObj(i)
5917 .GetPowderPatternCalcVariance().data();
5919 if(
true==mPowderPatternComponentRegistry.GetObj(i).IsScalable())
5921 const REAL s2 = mScaleFactor(i) * mScaleFactor(i);
5922 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += s2 * *p1++;
5924 else for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += *p1++;
5929 for(
unsigned long j=0;j<mNbPointUsed;j++)
5930 if(*p1 <=0) {*p0++ =0;p1++;}
5931 else *p0++ = 1. / *p1++;
5934 TAU_PROFILE_STOP(timer5);
5935 VFN_DEBUG_EXIT(
"PowderPattern::CalcPowderPattern():End",3);
5938 void PowderPattern::CalcPowderPattern_FullDeriv(std::set<RefinablePar*> &vPar)
5940 TAU_PROFILE(
"PowderPattern::CalcPowderPattern_FullDeriv()",
"void ()",TAU_DEFAULT);
5942 mPowderPattern_FullDeriv.clear();
5943 if(mPowderPatternComponentRegistry.GetNb()==0)
return;
5944 std::vector<std::map<RefinablePar*,CrystVector_REAL>*> comps;
5945 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
5946 comps.push_back(&(mPowderPatternComponentRegistry.GetObj(i).GetPowderPattern_FullDeriv(vPar)));
5948 for(std::set<RefinablePar *>::iterator par=vPar.begin();par!=vPar.end();++par)
5950 if(*par==0)
continue;
5951 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
5953 if((*par)->GetPointer()==mScaleFactor.data()+i)
5955 mPowderPattern_FullDeriv[*par]=mPowderPatternComponentRegistry.GetObj(i).GetPowderPatternCalc();
5960 if((*(comps[i]))[*par].size()==0)
continue;
5962 if(
true==mPowderPatternComponentRegistry.GetObj(i).IsScalable())
5964 if(mPowderPattern_FullDeriv[*par].size()==0)
5966 mPowderPattern_FullDeriv[*par].resize(
mNbPoint);
5967 const REAL * p1=(*comps[i])[*par].data();
5968 REAL * p0 = mPowderPattern_FullDeriv[*par].data();
5969 const REAL s = mScaleFactor(i);
5970 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ = s * *p1++;
5971 for(
unsigned long j=mNbPointUsed;j<
mNbPoint;j++) *p0++ = 0;
5975 const REAL * p1=(*comps[i])[*par].data();
5976 REAL * p0 = mPowderPattern_FullDeriv[*par].data();
5977 const REAL s = mScaleFactor(i);
5978 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += s * *p1++;
5983 if(mPowderPattern_FullDeriv[*par].size()==0)
5985 mPowderPattern_FullDeriv[*par].resize(
mNbPoint);
5986 const REAL * p1=(*comps[i])[*par].data();
5987 REAL * p0 = mPowderPattern_FullDeriv[*par].data();
5988 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ = *p1++;
5989 for(
unsigned long j=mNbPointUsed;j<
mNbPoint;j++) *p0++ = 0;
5993 const REAL * p1=(*comps[i])[*par].data();
5994 REAL * p0 = mPowderPattern_FullDeriv[*par].data();
5995 for(
unsigned long j=0;j<mNbPointUsed;j++) *p0++ += *p1++;
6002 std::map<RefinablePar*, CrystVector_REAL> oldDeriv;
6003 std::vector<const CrystVector_REAL*> v;
6005 for(std::map<RefinablePar*, CrystVector_REAL>::reverse_iterator pos=mPowderPattern_FullDeriv.rbegin();pos!=mPowderPattern_FullDeriv.rend();++pos)
6007 if(pos->first==0)
continue;
6008 if(pos->second.size()==0)
continue;
6010 const REAL step=pos->first->GetDerivStep();
6011 pos->first->Mutate(step);
6014 pos->first->Mutate(-2*step);
6017 oldDeriv[pos->first]/=2*step;
6018 pos->first->Mutate(step);
6020 v.push_back(&(pos->second));
6021 v.push_back(&(oldDeriv[pos->first]));
6022 cout<<pos->first->GetName()<<
":"<<pos->second.size()<<
","<<oldDeriv[pos->first].size()<<endl;
6025 cout<<FormatVertVector<REAL>(v,16)<<endl;
6036 TAU_PROFILE(
"PowderPattern::CalcPowderPatternIntegrated()",
"void ()",TAU_DEFAULT);
6037 VFN_DEBUG_ENTRY(
"PowderPattern::CalcPowderPatternIntegrated()",4);
6038 if(mPowderPatternComponentRegistry.GetNb()==0)
6042 VFN_DEBUG_EXIT(
"PowderPattern::CalcPowderPatternIntegrated():no components!",4);
6045 TAU_PROFILE_TIMER(timer1,
"PowderPattern::CalcPowderPatternIntegrated()1:Calc components",\
6047 TAU_PROFILE_TIMER(timer2,
"PowderPattern::CalcPowderPatternIntegrated()2:Add comps-scaled"\
6049 TAU_PROFILE_TIMER(timer3,
"PowderPattern::CalcPowderPatternIntegrated()2:Add backgd1"\
6051 TAU_PROFILE_TIMER(timer4,
"PowderPattern::CalcPowderPatternIntegrated()2:Add backgd2"\
6053 TAU_PROFILE_TIMER(timer5,
"PowderPattern::CalcPowderPatternIntegrated()3:Variance"
6055 TAU_PROFILE_START(timer1);
6056 vector< pair<const CrystVector_REAL*,const RefinableObjClock*> > comps;
6057 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
6059 comps.push_back(mPowderPatternComponentRegistry.GetObj(i).
6060 GetPowderPatternIntegratedCalc());
6062 TAU_PROFILE_STOP(timer1);
6069 for(vector< pair<const CrystVector_REAL*,const RefinableObjClock*> >::iterator
6070 pos=comps.begin();pos!=comps.end();++pos)
6079 VFN_DEBUG_EXIT(
"PowderPattern::CalcPowderPatternIntegrated():no need to recalc",4);
6082 VFN_DEBUG_MESSAGE(
"PowderPattern::CalcPowderPatternIntegrated():Recalc",3);
6085 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
6087 VFN_DEBUG_MESSAGE(
"PowderPattern::CalcPowderPatternIntegrated():Adding "\
6088 << mPowderPatternComponentRegistry.GetObj(i).GetName(),3);
6089 if(
true==mPowderPatternComponentRegistry.GetObj(i).IsScalable())
6091 TAU_PROFILE_START(timer2);
6094 const REAL * RESTRICT p1= comps[i].first->data();
6096 const REAL s = mScaleFactor(i);
6097 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ = s * *p1++;
6101 const REAL * RESTRICT p1= comps[i].first->data();
6103 const REAL s = mScaleFactor(i);
6104 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ += s * *p1++;
6106 TAU_PROFILE_STOP (timer2);
6110 TAU_PROFILE_START(timer3);
6113 const REAL * RESTRICT p1= comps[i].first->data();
6115 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ = *p1++;
6119 const REAL * RESTRICT p1= comps[i].first->data();
6121 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ += *p1++;
6124 TAU_PROFILE_STOP(timer3);
6125 TAU_PROFILE_START(timer4);
6130 const REAL * RESTRICT p1= comps[i].first->data();
6132 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ = *p1++;
6136 const REAL * RESTRICT p1= comps[i].first->data();
6138 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ += *p1++;
6141 TAU_PROFILE_STOP(timer4);
6144 TAU_PROFILE_START(timer5);
6147 bool useCalcVariance=
false;
6148 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
6149 if(mPowderPatternComponentRegistry.GetObj(i).HasPowderPatternCalcVariance())
6150 if(mPowderPatternComponentRegistry.GetObj(i)
6151 .GetPowderPatternIntegratedCalcVariance().first->numElements() !=0)
6152 useCalcVariance=
true;
6155 VFN_DEBUG_MESSAGE(
"PowderPattern::CalcPowderPatternIntegrated():variance",3);
6158 mIntegratedWeight.resize(mNbIntegrationUsed);
6159 const REAL * RESTRICT p1= mIntegratedVarianceObs.data();
6161 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ = *p1++;
6165 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
6167 if(mPowderPatternComponentRegistry.GetObj(i).HasPowderPatternCalcVariance())
6169 if(0==mPowderPatternComponentRegistry.GetObj(i)
6170 .GetPowderPatternIntegratedCalcVariance().first->numElements())
break;
6172 const REAL * RESTRICT p1= mPowderPatternComponentRegistry.GetObj(i)
6173 .GetPowderPatternIntegratedCalcVariance().first->data();
6178 if(
true==mPowderPatternComponentRegistry.GetObj(i).IsScalable())
6180 const REAL s2 = mScaleFactor(i) * mScaleFactor(i);
6181 for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ += s2 * *p1++;
6183 else for(
unsigned long j=mNbIntegrationUsed;j>0;j--) *p0++ += *p1++;
6188 REAL *p0 = mIntegratedWeight.data();
6190 for(
unsigned long j=mNbIntegrationUsed;j>0;j--)
6191 if(*p1 <=0) {*p0++ =0;p1++;}
6192 else *p0++ = 1. / *p1++;
6194 else mIntegratedWeight.resize(0);
6196 TAU_PROFILE_STOP(timer5);
6222 VFN_DEBUG_EXIT(
"PowderPattern::CalcPowderPatternIntegrated():End",4);
6225 void PowderPattern::CalcPowderPatternIntegrated_FullDeriv(std::set<RefinablePar *> &vPar)
6227 TAU_PROFILE(
"PowderPattern::CalcPowderPatternIntegrated_FullDeriv()",
"void ()",TAU_DEFAULT);
6232 mPowderPatternUsed_FullDeriv.clear();
6233 if(mPowderPatternComponentRegistry.GetNb()==0)
return;
6234 std::vector<map<RefinablePar*,CrystVector_REAL>*> comps;
6235 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
6237 comps.push_back(&(mPowderPatternComponentRegistry.GetObj(i).
6238 GetPowderPatternIntegrated_FullDeriv(vPar)));
6242 mPowderPatternIntegrated_FullDeriv.clear();
6243 for(std::set<RefinablePar *>::iterator par=vPar.begin();par!=vPar.end();++par)
6245 if(*par==0)
continue;
6246 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
6248 if((*par)->GetPointer()==mScaleFactor.data()+i)
6251 mPowderPatternIntegrated_FullDeriv[*par]=*(mPowderPatternComponentRegistry.GetObj(i).GetPowderPatternIntegratedCalc().first);
6257 if((*(comps[i]))[*par].size()==0)
continue;
6259 if(
true==mPowderPatternComponentRegistry.GetObj(i).IsScalable())
6261 if(mPowderPatternIntegrated_FullDeriv[*par].size()==0)
6263 mPowderPatternIntegrated_FullDeriv[*par].resize(mNbIntegrationUsed);
6264 const REAL * RESTRICT p1= (*(comps[i]))[*par].data();
6265 REAL * RESTRICT p0 = mPowderPatternIntegrated_FullDeriv[*par].data();
6266 const REAL s = mScaleFactor(i);
6267 for(
unsigned long j=mNbIntegrationUsed;j>0;j--)
6273 if((j==mNbIntegrationUsed)&&((*par)->GetName()==
"Cimetidine_C11_x")) cout<<__FILE__<<
":"<<__LINE__<<
":"<<*p0<<
","<<s<<
"*"<<*p1<<endl;
6280 const REAL * RESTRICT p1= (*(comps[i]))[*par].data();
6281 REAL * RESTRICT p0 = mPowderPatternIntegrated_FullDeriv[*par].data();
6282 const REAL s = mScaleFactor(i);
6283 for(
unsigned long j=mNbIntegrationUsed;j>0;j--)
6289 if((j==mNbIntegrationUsed)&&((*par)->GetName()==
"Cimetidine_C11_x")) cout<<__FILE__<<
":"<<__LINE__<<
":"<<*p0<<
","<<s<<
"*"<<*p1<<endl;
6297 if(mPowderPatternIntegrated_FullDeriv[*par].size()==0)
6299 mPowderPatternIntegrated_FullDeriv[*par].resize(mNbIntegrationUsed);
6300 const REAL * RESTRICT p1= (*(comps[i]))[*par].data();
6301 REAL * RESTRICT p0 = mPowderPatternIntegrated_FullDeriv[*par].data();
6302 for(
unsigned long j=mNbIntegrationUsed;j>0;j--)
6308 if((j==mNbIntegrationUsed)&&((*par)->GetName()==
"Cimetidine_C11_x")) cout<<__FILE__<<
":"<<__LINE__<<
":"<<*p0<<
","<<*p1<<endl;
6315 const REAL * RESTRICT p1= (*(comps[i]))[*par].data();
6316 REAL * RESTRICT p0 = mPowderPatternIntegrated_FullDeriv[*par].data();
6317 for(
unsigned long j=mNbIntegrationUsed;j>0;j--)
6323 if((j==mNbIntegrationUsed)&&((*par)->GetName()==
"Cimetidine_C11_x")) cout<<__FILE__<<
":"<<__LINE__<<
":"<<*p0<<
","<<*p1<<endl;
6330 if((*par)->GetName()==
"Cimetidine_C11_x")
6331 cout<<
"PowderPattern::CalcPowderPatternIntegrated_FullDeriv():"
6332 <<(*par)->GetName()<<
":s="<<mScaleFactor(i)<<
", d[0]="<<(*(comps[i]))[*par](0)
6333 <<
", integ="<<mPowderPatternIntegrated_FullDeriv[*par](0)<<endl;
6347 REFPAR_DERIV_STEP_ABSOLUTE,
true,
true,
true,
false,RAD2DEG);
6354 REFPAR_DERIV_STEP_ABSOLUTE,
true,
true,
true,
false,RAD2DEG);
6361 REFPAR_DERIV_STEP_ABSOLUTE,
true,
true,
true,
false,RAD2DEG);
6368 REFPAR_DERIV_STEP_ABSOLUTE,
true,
true,
true,
false,1.0);
6375 REFPAR_DERIV_STEP_ABSOLUTE,
true,
true,
true,
false,1.0);
6383 bool needPrep=
false;
6384 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
6386 mPowderPatternComponentRegistry.GetObj(i).GetBraggLimits();
6387 if(mPowderPatternComponentRegistry.GetObj(i).GetClockBraggLimits()
6388 >mClockIntegratedFactorsPrep)
6397 if(mClockIntegratedFactorsPrep<mClockNbPointUsed) needPrep=
true;
6399 if(
false==needPrep)
return;
6400 VFN_DEBUG_ENTRY(
"PowderPattern::PrepareIntegratedRfactor()",3);
6401 TAU_PROFILE(
"PowderPattern::PrepareIntegratedRfactor()",
"void ()",TAU_DEFAULT);
6407 for(
int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
6409 const CrystVector_long vLim=mPowderPatternComponentRegistry.GetObj(i).GetBraggLimits();
6410 for(i=0;i<vLim.numElements();i++) vLimits.push_back(vLim(i));
6412 if(vLimits.size()<2)
6414 mIntegratedPatternMin.resize(0);
6415 mIntegratedPatternMax.resize(0);
6416 mNbIntegrationUsed=0;
6417 mClockIntegratedFactorsPrep.Click();
6419 VFN_DEBUG_EXIT(
"PowderPattern::PrepareIntegratedRfactor(): no intervals !",3);
6422 if(*(vLimits.begin())<0)
6424 vLimits.push_back(0);
6427 for(list<long>::iterator pos=vLimits.begin();pos!=vLimits.end();)
6429 if( (*pos<0) || (*pos>=long(mNbPointUsed)) ) pos=vLimits.erase(pos);
6434 list<long> vLimits2;
6435 list<long>::iterator pos1=vLimits.begin();
6436 list<long>::iterator pos2=pos1;pos2++;
6437 for(;pos2!=vLimits.end();)
6439 const long pix1=*pos1;
6441 vLimits2.push_back(pix1);
6445 if(pos2==vLimits.end())
break;
6446 if(*pos2>(pix1+8))
break;
6449 vLimits2.push_back(*pos1);
6452 pos1=vLimits2.begin();
6454 for(;pos2!=vLimits2.end();)
6457 if( *pos2<=((*pos1)+2))
6460 pos2=vLimits2.erase(pos2);
6463 else {pos1++;pos2++;}
6467 list<pair<long,long> > vLimits3;
6468 pos1=vLimits2.begin();
6470 for(;pos2!=vLimits2.end();)
6472 if(*pos2!=(
long(mNbPointUsed)-1)) vLimits3.push_back(make_pair(*pos1++,*pos2++-1));
6473 else vLimits3.push_back(make_pair(*pos1++,*pos2++));
6477 mIntegratedPatternMin.resize(vLimits3.size());
6478 mIntegratedPatternMax.resize(vLimits3.size());
6480 for(list<pair<long,long> >::iterator pos=vLimits3.begin();pos!=vLimits3.end();++pos)
6482 mIntegratedPatternMin(i)=pos->first;
6483 mIntegratedPatternMax(i++)=pos->second;
6486 long numInterval=mIntegratedPatternMin.numElements();
6487 CrystVector_bool keep(numInterval);
6494 VFN_DEBUG_MESSAGE(
"PowderPattern::PrepareIntegratedRfactor():5:Excluded regions("<<nbExclude<<
")",3);
6496 long minExcl,maxExcl;
6499 for(
int i=0;i<nbExclude;i++)
6501 while(mIntegratedPatternMax(j)<minExcl)
6504 if(j>=numInterval)
break;
6506 if(j>=numInterval)
break;
6507 while(mIntegratedPatternMin(j)<maxExcl)
6509 if( (mIntegratedPatternMin(j)>minExcl) &&(mIntegratedPatternMax(j)<maxExcl))
6511 if( (mIntegratedPatternMin(j)<minExcl) &&(mIntegratedPatternMax(j)<maxExcl))
6512 mIntegratedPatternMax(j)=minExcl;
6513 if( (mIntegratedPatternMin(j)>minExcl) &&(mIntegratedPatternMax(j)>maxExcl))
6514 mIntegratedPatternMin(j)=maxExcl;
6515 if(j==(numInterval-1))
break;
6522 while(mIntegratedPatternMax(j)>=minExcl)
6530 VFN_DEBUG_MESSAGE(
"PowderPattern::PrepareIntegratedRfactor():6",3);
6532 for(
int i=0;i<numInterval;i++)
6536 mIntegratedPatternMin(j )=mIntegratedPatternMin(i);
6537 mIntegratedPatternMax(j++)=mIntegratedPatternMax(i);
6541 mIntegratedPatternMax.resizeAndPreserve(numInterval);
6542 mIntegratedPatternMin.resizeAndPreserve(numInterval);
6544 VFN_DEBUG_MESSAGE(
"PowderPattern::PrepareIntegratedRfactor():intervals"<<endl\
6547 mIntegratedObs.resize(numInterval);
6548 mIntegratedVarianceObs.resize(numInterval);
6549 mIntegratedVarianceObs=0;
6551 mIntegratedWeightObs.resize(numInterval);
6552 for(
int i=0;i<numInterval;i++)
6554 for(
int j=mIntegratedPatternMin(i);j<=mIntegratedPatternMax(i);j++)
6559 if(mIntegratedVarianceObs(i) <= 0) mIntegratedWeightObs(i)=0;
6560 else mIntegratedWeightObs(i)=1./mIntegratedVarianceObs(i);
6567 mNbIntegrationUsed=mIntegratedPatternMin.numElements();
6568 mClockIntegratedFactorsPrep.Click();
6569 VFN_DEBUG_EXIT(
"PowderPattern::PrepareIntegratedRfactor()",3);
6576 if(this->
GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
6583 if(1>fabs(sinth)) tmp=(
unsigned long)(this->
X2PixelCorr(2*asin(sinth)));
else tmp=
mNbPoint;
6586 if(tmp !=mNbPointUsed)
6589 mClockNbPointUsed.Click();
6596 VFN_DEBUG_MESSAGE(
"PowderPattern::InitOptions()",5)
6597 static string OptProfileIntegrationName;
6598 static string OptProfileIntegrationChoices[2];
6600 static bool needInitNames=
true;
6601 if(
true==needInitNames)
6603 OptProfileIntegrationName=
"Use Integrated Profiles";
6604 OptProfileIntegrationChoices[0]=
"Yes (recommended)";
6605 OptProfileIntegrationChoices[1]=
"No";
6607 needInitNames=
false;
6609 mOptProfileIntegration.Init(2,&OptProfileIntegrationName,OptProfileIntegrationChoices);
6610 this->
AddOption(&mOptProfileIntegration);
6613 #ifdef __WX__CRYST__
6618 return mpWXCrystObj;
virtual const CrystVector_REAL & GetLSQWeight(const unsigned int) const
Get the weight values for the LSQ function.
void SetFrozenLatticePar(const unsigned int i, REAL v)
Change one parameter in mFrozenLatticePar. This triggers a call to CalcLocalBMatrix() if the paramete...
REAL X2Pixel(const REAL x) const
Get the pixel number on the experimental pattern, corresponding to a given (experimental) x coordinat...
void SetDerivStep(const REAL)
Fixed step to use to compute numerical derivative.
void FitScaleFactorForR() const
Fit the scale(s) factor of each component to minimize R.
virtual void GetGeneGroup(const RefinableObj &obj, CrystVector_uint &groupIndex, unsigned int &firstGroup) const
Get the gene group assigned to each parameter.
CrystVector_REAL mPowderPatternUsedCalc
The calculated powder pattern. Cropped to the maximum sin(theta)/lambda for LSQ.
virtual void BeginOptimization(const bool allowApproximations=false, const bool enableRestraints=false)
This should be called by any optimization class at the begining of an optimization.
virtual long GetNbReflBelowMaxSinThetaOvLambda() const
Recalc, and get the number of reflections which should be actually used, due to the maximuml sin(thet...
const RefinableObjClock & GetClockNbPointUsed() const
Clock corresponding to the last time the number of points used was changed.
void OptimizeBayesianBackground()
Optimize the background using a Bayesian approach.
void AddSubRefObj(RefinableObj &)
void SavePowderPattern(const string &filename="powderPattern.out") const
Save powder pattern to one file, text format, 3 columns theta Iobs Icalc.
const CrystVector_REAL & GetPowderPatternCalc() const
Get the calculated powder pattern.
void AddExcludedRegion(const REAL min2Theta, const REAL max2theta)
Add an Exclusion region, in 2theta, which will be ignored when computing R's XMLInput values must be...
vector< hkl > & GetPeakList()
Get peak list.
void AddPar(const RefinablePar &newRefPar)
Add a refinable parameter.
Conjugate Gradient Algorithm object.
const CrystVector_REAL & GetPowderPatternWeight() const
Get the weight for each point of the powder pattern.
CrystVector_REAL mBackgroundInterpPointIntensity
Values of background at interpolating points.
virtual void UpdateDisplay() const
If there is an interface, this should be automatically be called each time there is a 'new...
void ImportPowderPatternTOF_ISIS_XYSigma(const string &fileName)
Import TOF file (ISIS type, 3 columns t, Iobs, sigma(Iobs))
RefinableObjClock mClockScaleFactor
Last modification of the scale factor.
CrystVector_REAL mExcludedRegionMaxX
Max coordinate for 2theta for all excluded regions.
int mBackgroundNbPoint
Number of fitting points for background.
Double-Exponential Pseudo-Voigt profile for TOF.
CrystVector_REAL mPowderPatternCalc
The calculated powder pattern.
void ImportPowderPatternFullprof(const string &fullprofFileName)
Import fullprof-style diffraction data.
virtual void BeginOptimization(const bool allowApproximations=false, const bool enableRestraints=false)
This should be called by any optimization class at the begining of an optimization.
const RefParType * gpRefParTypeScattDataCorrPos
Parameter type for correction to peak positions.
void SetReflectionProfilePar(const ReflectionProfileType prof, const REAL fwhmCagliotiW, const REAL fwhmCagliotiU=0, const REAL fwhmCagliotiV=0, const REAL eta0=0.5, const REAL eta1=0.)
Set reflection profile parameters.
void SetWeightToInvSigmaSq(const REAL minRelatSigma=1e-3)
Set w = 1/sigma^2.
Output vectors as column arrays, with the first 3 columns printed as integers.
void PrepareRefParList(const bool copy_param=false)
Prepare the full parameter list for the refinement.
virtual void Init()
Init parameters and options.
CrystVector_REAL mExcludedRegionMinX
Min coordinate for for all excluded regions.
const Radiation & GetRadiation() const
Neutron or x-ray experiment ?
void CalcPowderReflProfile_FullDeriv(std::set< RefinablePar * > &vPar)
long GetNbComponent() const
Number of components.
const CrystVector_REAL & GetPowderPatternObsSigma() const
Get the sigma for each point of the observed powder pattern.
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
bool IsBeingRefined() const
Is the object being refined ? (Can be refined by one algorithm at a time only.)
RefinableObjClock mClockPowderPatternIntegratedCalc
When was the 'integrated' powder pattern last computed ?
virtual std::map< RefinablePar *, CrystVector_REAL > & GetLSQ_FullDeriv(const unsigned int, std::set< RefinablePar * > &vPar)
Get the first derivative for the LSQ function for each parameter supplied in a list.
virtual void SetParentPowderPattern(PowderPattern &)
Set the PowderPattern object which uses this component.
RefinableObjClock mClockPowderPatternRadiation
When were the radiation parameter (radiation type, wavelength) changed ?
virtual void GlobalOptRandomMove(const REAL mutationAmplitude, const RefParType *type=gpRefParTypeObjCryst)
Make a random move of the current configuration.
void SetRadiation(const Radiation &radiation)
Set the radiation.
void SetUnitCell(const UnitCell &cell)
Set unit cell.
virtual bool HasPowderPatternCalcVariance() const
Does this component have a variance associated with each calculated point ? i.e., do we use maximum l...
void AddRefinableObj(RefinableObj &)
Add a refined object. All sub-objects are also added.
bool FreezeLatticePar() const
Do we use local cell parameters ? (see mFrozenLatticePar)
bool ISNAN_OR_INF(REAL r)
Test if the value is a NaN.
void SetRefinedObj(RefinableObj &obj, const unsigned int LSQFuncIndex=0, const bool init=true, const bool recursive=false)
Choose the object to refine.
RefinableObjClock mClockPowderPatternXCorr
Corrections to 2Theta.
ReflectionProfileType
Profile type for powder (could it be used fopr single crystals on 2D detectors ?) ...
CrystVector_REAL mPowderPatternIntegratedCalcVariance
The variance associated to each point of the calculated powder pattern, integrated.
virtual void BeginOptimization(const bool allowApproximations=false, const bool enableRestraints=false)
This should be called by any optimization class at the begining of an optimization.
RefinableObjClock mClockPowderPatternIntegratedCalc
When was the powder pattern (integrated) last computed ?
CrystVector_REAL mvSplinePixel
Vector of pixel values between each interval, for faster CubicSpline calculations.
const ReflectionProfile & GetProfile() const
Get reflection profile.
virtual void SetMaxSinThetaOvLambda(const REAL max)
Set the maximum value for sin(theta)/lambda.
void ExtractLeBail(unsigned int nbcycle=1)
Extract intensities using Le Bail method.
void ImportPowderPatternFullprof4(const string &fileName)
Import diffraction data from a file, with the first line has 2ThetaMin, step, 2thetaMax, and the following lines alternate 10 Iobs and 10 sigma.
REAL mMaxSinThetaOvLambda
Displacement correction : REAL m2ThetaDisplacement; Transparency correction : REAL m2ThetaTranspare...
CrystVector_REAL mPowderPatternObs
The observed powder pattern.
virtual void Optimize(long &nbSteps, const bool silent=false, const REAL finalcost=0, const REAL maxTime=-1)
Launch optimization (a single run) for N steps.
void ImportPowderPatternSietronicsCPI(const string &fileName)
Import *.cpi Sietronics diffraction data.
const RefinableObjClock & GetClockPowderPatternRadiation() const
When were the radiation parameter (radiation type, wavelength) changed ?
virtual void SetMaxSinThetaOvLambda(const REAL max)
Set the maximum value for sin(theta)/lambda.
RefinableObjClock mClockPowderPatternCalc
When was the powder pattern last computed ?
Phase to compute a background contribution to a powder pattern using an interpolation.
void Click()
Record an event for this clock (generally, the 'time' an object has been modified, or some computation has been made)
const RefinableObjClock & GetIntegratedProfileLimitsClock() const
When were the integration intervals last changed ?
void RemoveSubRefObj(RefinableObj &)
long GetNbPar() const
Total number of refinable parameter in the object.
unsigned long mNbPoint
Number of points in the pattern.
void AddChild(const RefinableObjClock &)
Add a 'child' clock.
REAL GetChi2_Option() const
Return the conventionnal or integrated Chi^2, depending on the option.
void ImportPowderPatternGSAS(const string &fileName)
Import GSAS standard powder pattern data (see GSAS manual).
RefinablePar & GetPar(const long i)
Access all parameters in the order they were inputted.
virtual void SetParentPowderPattern(PowderPattern &)=0
Set the PowderPattern object which uses this component.
RefinableObjClock mClockPowderPatternVarianceCalc
When was the powder pattern variance last computed ?
CrystVector_REAL mX
Vector of x coordinates (either 2theta or time-of-flight) for the pattern.
const RefinableObjClock & GetClockPowderPatternPar() const
When were the pattern parameters (2theta range, step) changed ?
virtual void SetCrystal(Crystal &crystal)
Set the crystal for this experiment.
Class to compute the contribution to a powder pattern from a crystalline phase.
RefinableObjClock mClockPowderPatternIntegratedVarianceCalc
When was the 'integrated' powder pattern variance last computed ?
void CalcPowderPatternIntegrated() const
Calc the integrated powder pattern.
void FixParametersBeyondMaxresolution(RefinableObj &obj)
Fix parameters corresponding to points of the pattern that are not actually calculated.
void CalcNbPointUsed() const
Calculate the number of points of the pattern actually used, from the maximum value of sin(theta)/lam...
const RefParType * gpRefParTypeScattDataProfile
Type for reflection profile.
output one or several vectors as (a) column(s):
void SetPowderPatternObs(const CrystVector_REAL &obs)
Set observed powder pattern from vector array.
RadiationType GetRadiationType() const
Get the radiation type (X-Rays, Neutron)
virtual void RegisterClient(RefinableObj &) const
Register a new object using this object.
bool GetExtractionMode() const
Return true if in extraction mode, i.e. using extracted intensities instead of computed structure fac...
const PowderPatternComponent & GetPowderPatternComponent(const string &name) const
Access to a component of the powder pattern.
Class to compute structure factors for a set of reflections and a Crystal.
ObjRegistry< RefinableObj > gTopRefinableObjRegistry("Global Top RefinableObj registry")
This is a special registry for 'top' object for an optimization.
virtual void SetMaxSinThetaOvLambda(const REAL max)
Set the maximum value for sin(theta)/lambda.
RefinableObjClock mClockMaster
Master clock, which is changed whenever the object has been altered.
REAL GetR() const
Unweighted R-factor.
virtual unsigned int GetNbLSQFunction() const
Number of LSQ functions.
virtual void SetApproximationFlag(const bool allow)
Enable or disable numerical approximations.
const RefinableObjClock & GetClockWavelength() const
Last time the wavelength has been changed.
void SetProfile(ReflectionProfile *prof)
Assign a new profile.
Generic Refinable Object.
CrystVector_REAL mPowderPatternVarianceIntegrated
The complete variance associated to each point of the powder pattern, taking into account observation...
const RefParType * gpRefParTypeScattDataScale
Type for scattering data scale factors.
virtual void CalcPowderPattern() const
Calc the powder pattern.
void ImportPowderPattern2ThetaObsSigma(const string &fileName, const int nbSkip=0)
Import file with 3 columns 2Theta Iobs Sigma.
const CrystVector_long & GetIntegratedProfileMin() const
Get the list of first pixels for the integration intervals.
virtual void SetParentPowderPattern(PowderPattern &)
Set the PowderPattern object which uses this component.
void ResetParList()
Re-init the list of refinable parameters, removing all parameters.
Class to store positions of observed reflections.
ObjRegistry< PowderPatternComponent > gPowderPatternComponentRegistry("List of all PowderPattern Components")
Global registry for all PowderPatternComponent objects.
REAL GetWavelength() const
wavelength of the experiment (in Angstroems)
const RefinableObjClock & GetClockMaster() const
This clocks records any change in the object. See refinableObj::mClockMaster.
virtual pair< const CrystVector_REAL *, const RefinableObjClock * > GetPowderPatternIntegratedCalcVariance() const
Get the variance associated to each point of the calculated powder pattern, for this component (integ...
CrystVector_REAL mPowderPatternCalcVariance
The variance associated to each point of the calculated powder pattern.
virtual pair< const CrystVector_REAL *, const RefinableObjClock * > GetPowderPatternIntegratedCalc() const
Get the integrated values of the powder pattern.
const RefParType * gpRefParTypeScattDataBackground
Parameter type for background intensity.
REAL X2STOL(const REAL x) const
Convert X (either 2theta or TOF) to sin(theta)/lambda, depending on the type of radiation.
Abstract base class for all objects in wxCryst.
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
Abstract base class for reflection profiles.
void ImportUserBackground(const string &filename)
Import background points from a file (with two columns 2theta (or tof), intensity) ...
virtual void TagNewBestConfig() const
During a global optimization, tells the object that the current config is the latest "best" config...
WX Class for PowderPattern objects.
string mName
Name for this RefinableObject. Should be unique, at least in the same scope.+.
CrystVector_REAL mPowderPatternVariance
The complete variance associated to each point of the powder pattern, taking into account observation...
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
PowderPattern * mpParentPowderPattern
The PowderPattern object in which this component is included.
virtual void CalcPowderPattern() const
Calc the powder pattern.
virtual void CalcIhkl() const
CrystVector_REAL mPowderPatternBackgroundCalc
The calculated powder pattern part which corresponds to 'background' (eg non-scalable components)...
virtual const CrystVector_REAL & GetLSQDeriv(const unsigned int, RefinablePar &)
Get the first derivative values for the LSQ function, for a given parameter.
void CalcPowderPattern() const
Calc the powder pattern.
virtual const CrystVector_long & GetBraggLimits() const
Get the pixel positions separating the integration intervals around reflections.
virtual const Radiation & GetRadiation() const
Get the radiation object for this data.
REAL GetRw() const
Get the weighted R-factor.
void SetScaleFactor(const int i, REAL s)
Access to the scale factor of components (will be 1 for background components)
const CrystVector_REAL & GetPowderPatternX() const
Get the vector of X (2theta or time-of-flight) coordinates.
const RefinableObjClock & GetClockPowderPatternCalc() const
Last time the pattern was calculated.
void Set2ThetaTransparency(const REAL transparency)
Change transparency correction .
virtual pair< const CrystVector_REAL *, const RefinableObjClock * > GetPowderPatternIntegratedCalcVariance() const
Get the variance associated to each point of the calculated powder pattern, for this component (integ...
Molecule : class for complex scatterer descriptions using cartesian coordinates with bond length/angl...
void ImportPowderPattern2ThetaObs(const string &fileName, const int nbSkip=0)
Import file with 2 columns 2Theta Iobs.
void ImportPowderPatternMultiDetectorLLBG42(const string &fileName)
diffraction data in a multi-detector format (fullprof format #6).
CrystVector_REAL mPowderPatternBackgroundIntegratedCalc
The calculated powder pattern part which corresponds to 'background' (eg non-scalable components)...
virtual pair< const CrystVector_REAL *, const RefinableObjClock * > GetPowderPatternIntegratedCalc() const
Get the integrated values of the powder pattern.
virtual void GetGeneGroup(const RefinableObj &obj, CrystVector_uint &groupIndex, unsigned int &firstGroup) const
Get the gene group assigned to each parameter.
virtual const CrystMatrix_REAL & GetBMatrix() const
Get access to the B matrix used to compute reflection positions.
void ImportPowderPatternCIF(const CIF &cif)
Import CIF powder pattern data.
Generic class to compute components (eg the contribution of a given phase, or background) of a powder...
void SetPowderPatternX(const CrystVector_REAL &x)
Set the x coordinate of the powder pattern : either the 2theta or time-of-flight values for each reco...
virtual void SetApproximationFlag(const bool allow)
Enable or disable numerical approximations.
WavelengthType GetWavelengthType() const
Get the Wavelength type (monochromatic, Alpha1+Alpha2, Time Of Flight...)
REAL STOL2X(const REAL stol) const
Convert sin(theta)/lambda to X (i.e.
void AssignClock(RefinableObjClock &clock)
DiffractionData object for Single Crystal analysis.
void AddPowderPatternComponent(PowderPatternComponent &)
Add a component (phase, backround) to this pattern.
virtual bool HasPowderPatternCalcVariance() const
Does this component have a variance associated with each calculated point ? i.e., do we use maximum l...
RefinableObjClock mClockSpline
Initialization of the spline.
RefinableObjClock mClockPowderPatternCalc
When was the powder pattern last computed ?
void PrepareIntegratedRfactor() const
Prepare the calculation of the integrated R-factors.
void RemoveChild(const RefinableObjClock &)
remove a child clock. This also tells the child clock to remove the parent.
void SetWavelength(const REAL)
Set the (monochromatic) wavelength of the beam.
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
Vector library (Blitz++ mimic) for ObjCryst++.
CrystVector_REAL mPowderPatternWeight
The weight for each point of the pattern.
bool mIsScalable
Scalable ? (crystal phase = scalable, background= not scalable)
void Init(const CrystVector_REAL &x, const CrystVector_REAL &y, const REAL yp1, const REAL ypn)
Spline with given extremum derivatives.
virtual void CalcPowderPatternIntegrated_FullDeriv(std::set< RefinablePar * > &vPar)
Calc the integrated powder pattern.
RefinableObjClock mClockBraggLimits
Get last time the Bragg Limits were changed.
virtual PowderPatternDiffraction * CreateCopy() const
So-called virtual copy constructor.
virtual void CalcPowderPatternIntegrated_FullDeriv(std::set< RefinablePar * > &vPar)
Calc the integrated powder pattern.
virtual void SetMaxSinThetaOvLambda(const REAL max)
Set the maximum value for sin(theta)/lambda.
Powder pattern class, with an observed pattern and several calculated components to modelize the patt...
CrystVector_REAL mPowderPatternIntegratedCalc
The calculated powder pattern, integrated.
void SetPowderPatternPar(const REAL min, const REAL step, unsigned long nbPoint)
the powder pattern angular range & resolution parameter.
REAL mModelVariance
Constant error (sigma) on the calculated pattern, due to an incomplete model.
void SetRadiationType(const RadiationType radiation)
Set the radiation type.
virtual void CalcPowderPatternIntegrated_FullDeriv(std::set< RefinablePar * > &vPar)
Calc the integrated powder pattern.
virtual void GetGeneGroup(const RefinableObj &obj, CrystVector_uint &groupIndex, unsigned int &firstGroup) const
Get the gene group assigned to each parameter.
virtual REAL GetLogLikelihood() const
Get -log(likelihood) of the current configuration for the object.
const RefinableObjClock & GetClockPowderPatternXCorr() const
When were the parameters for 2theta/TOF correction (zero, transparency, displacement) last changed ...
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
virtual void SetCrystal(Crystal &crystal)
Set the crystal for this experiment.
Main CIF class - parses the stream and separates data blocks, comments, items, loops.
list< pair< const REAL,const string > > mvLabel
The labels associated to different points of the pattern.
CrystVector_REAL mBackgroundInterpPointX
Vector of 2theta values for the fitting points of the background.
REAL STOL2Pixel(const REAL stol) const
Convert sin(theta)/lambda to pixel, depending on the type of radiation.
const CrystVector_REAL & GetPowderPatternObs() const
Get the observed powder pattern.
void AddPeak(const float d, const float iobs=1.0, const float dobssigma=0.0, const float iobssigma=0.0, const int h=0, const int k=0, const int l=0, const float d2calc=0)
Add one peak.
void CalcFrozenBMatrix() const
Calculate the local BMatrix, used if mFreezeLatticePar is true.
virtual long GetNbReflBelowMaxSinThetaOvLambda() const
Recalc, and get the number of reflections which should be actually used, due to the maximuml sin(thet...
CubicSpline mvSpline
Spline used for interpolation.
void SetRadiationType(const RadiationType)
Set the radiation type (X-Rays, Neutron)
REAL GetIntegratedChi2() const
Return integrated Chi^2.
REAL X2XCorr(const REAL x) const
Get the experimental x (2theta, tof) from the theoretical value, taking into account all corrections ...
virtual const CrystVector_REAL & GetPowderPatternCalcVariance() const
Get the variance associated to each point of the calculated powder pattern, for this component...
const CrystVector_REAL & GetWavelength() const
Get the wavelength(s) in Angstroems.
const CrystVector_REAL & GetChi2Cumul() const
Get the powder pattern cumulative Chi^2.
RefObjOpt mInterpolationModel
Type of interpolation performed: linear or cubic spline.
RefinableObjClock mClockBackgroundPoint
Modification of the interpolated points.
CrystVector_REAL mPowderPatternIntegratedCalc
The calculated powder pattern, integrated.
const CrystVector_REAL & GetPowderPatternVariance() const
Get the variance (obs+model) for each point of the powder pattern.
std::map< std::string, CIFData > mvData
The data blocks, after parsing. The key is the name of the data block.
void CalcIntensityCorr() const
REAL GetFrozenLatticePar(const unsigned int i) const
Access to one parameter in mFrozenLatticePar.
ObjRegistry< RefinableObj > mSubObjRegistry
Registry of RefinableObject needed for this object (owned by this object or not)
virtual const CrystVector_REAL & GetPowderPatternCalcVariance() const
Get the variance associated to each point of the calculated powder pattern, for this component...
Radiation mRadiation
The Radiation corresponding to this experiment.
CrystVector_REAL mPowderPatternCalc
The calculated component of a powder pattern.
bool IsDescendantFromOrSameAs(const RefParType *type) const
Returns true if the parameter is a descendant of 'type'.
void Reset()
Reset a Clock to 0, to force an update.
void SetWeightPolynomial(const REAL a, const REAL b, const REAL c, const REAL minRelatIobs=1e-3)
Set w = 1/(a+ Iobs + b*Iobs^2+c*Iobs^3)
bool IsScalable() const
Is this component scalable ?
CrystVector_REAL mPowderPatternObsSigma
The sigma of the observed pattern.
Exception class for ObjCryst++ library.
virtual void EndOptimization()
This should be called by any optimization class at the end of an optimization.
const CrystVector_long & GetIntegratedProfileMax() const
Get the list of last pixels for the integration intervals.
void PrintObsCalcData(ostream &os=cout) const
Print to thee screen/console the observed and calculated pattern (long, mostly useful for debugging) ...
REAL GetPowderPatternXStep() const
Get the average step in 2theta.
void ImportPowderPatternXdd(const string &fileName)
Import *.xdd diffraction data (Topas,...).
void SetExtractionMode(const bool extract=true, const bool init=false)
Prepare intensity extraction (Le Bail or Pawley)
void ImportPowderPatternILL_D1A5(const string &filename)
Import powder pattern, format from ILL D1A/D2B (format without counter info)
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
CrystVector_REAL mPowderPatternUsedObs
The calculated powder pattern. Cropped to the maximum sin(theta)/lambda for LSQ.
const PowderPattern & GetParentPowderPattern() const
Get the PowderPattern object which uses this component.
RefinableObjClock mClockPowderPatternPar
When were the pattern parameters (2theta or time-of-flight range) changed ?
virtual void EndOptimization()
This should be called by any optimization class at the end of an optimization.
Unit Cell class: Unit cell with spacegroup information.
virtual void GlobalOptRandomMove(const REAL mutationAmplitude, const RefParType *type=gpRefParTypeObjCryst)
Make a random move of the current configuration.
Generic class for parameters of refinable objects.
void CalcPowderReflProfile() const
PeakList FindPeaks(const float dmin=2.0, const float maxratio=0.01, const unsigned int maxpeak=100)
Find peaks in the pattern.
virtual void InitOptions()
Initialize options.
const CrystVector_REAL & GetScaleFactor() const
Access the scale factors (see PowderPattern::mScaleFactor)
void Set2ThetaDisplacement(const REAL displacement)
Change displacement correction .
virtual const string & GetName() const
Name of the object.
void SetWavelength(const REAL lambda)
Set the wavelength of the experiment (in Angstroems).
unsigned long GetNbPoint() const
Number of points ?
virtual const CrystVector_REAL & GetLSQObs(const unsigned int) const
Get the observed values for the LSQ function.
void SetXZero(const REAL newZero)
Change Zero in x (2theta,tof)
void SetParIsUsed(const std::string &parName, const bool use)
Set a parameter to be used.
virtual const CrystVector_REAL & GetPowderPatternCalc() const
Get the calculated powder pattern for this component.
REAL X2PixelCorr(const REAL x) const
Get the pixel number on the experimental pattern, from the theoretical (uncorrected) x coordinate...
RadiationType
Type of radiation used.
void SetSigmaToSqrtIobs()
Set sigma=sqrt(Iobs)
virtual const CrystVector_long & GetBraggLimits() const
Get the pixel positions separating the integration intervals around reflections.
CrystVector_REAL mChi2Cumul
The cumulative Chi^2 (integrated or not, depending on the option)
RadiationType GetRadiationType() const
Neutron or x-ray experiment ?
virtual const CrystMatrix_REAL & GetBMatrix() const
This can use either locally stored lattice parameters from mLocalLatticePar, or the Crystal's...
Crystal class: Unit cell, spacegroup, scatterers.
void SetWavelengthType(const WavelengthType &type)
Set the Wavelength type (monochromatic, Alpha1+Alpha2, Time Of Flight...)
REAL GetPowderPatternXMax() const
Get the maximum 2theta.
void ImportPowderPatternPSI_DMC(const string &filename)
Import powder pattern, format DMC from PSI.
This object is used to estimate the background in a powder pattern, using a Bayesian approach (David ...
void SetGlobalOptimStep(const RefParType *type, const REAL step)
Change the maximum step to use during Global Optimization algorithms.
(Quick & dirty) Least-Squares Refinement Object with Numerical derivatives
REAL GetPowderPatternXMin() const
Get the Minimum 2theta.
REAL GetChi2() const
Return conventionnal Chi^2.
CrystVector_REAL mPowderPatternUsedWeight
The weight for each point of the pattern. Cropped to the maximum sin(theta)/lambda for LSQ...
CrystVector_long mPointOrder
Subscript of the points, sorted the correct order, taking into account the type of radiation (monochr...
class of refinable parameter types.
list of scattering positions in a crystal, associated with the corresponding occupancy and a pointer ...
unsigned long GetNbPointUsed() const
Number of points actually calculated (below the chosen max(sin(theta)/lambda)) ?
REAL GetMaxSinThetaOvLambda() const
Get the maximum value for sin(theta)/lambda.
void SetWeightToUnit()
Set w = 1.
Class to define the radiation (type, monochromaticity, wavelength(s)) of an experiment.
virtual const CrystVector_REAL & GetLSQCalc(const unsigned int) const
Get the current calculated value for the LSQ function.
CrystVector_long mIntegratedReflLimits
Interval limits around each reflection, for integrated R-factors.
int mOptimizationDepth
Is the object being refined or optimized ? if mOptimizationDepth=0, no optimization is taking place...
void SetProfilePar(const REAL fwhmCagliotiW, const REAL fwhmCagliotiU=0, const REAL fwhmCagliotiV=0, const REAL eta0=0.5, const REAL eta1=0.)
Set reflection profile parameters.
void FitScaleFactorForRw() const
Fit the scale(s) factor of each component to minimize Rw.
void ExportFullprof(const std::string &prefix) const
Export powder pattern & crystal structure in Fullprof format.
const RefParType * gpRefParTypeObjCryst
Top RefParType for the ObjCryst++ library.
void AddOption(RefObjOpt *opt)
void SetGlobalOptimStep(const REAL)
Maximum step to use during Global Optimization algorithms.
bool mIsXAscending
Is the mX vector sorted in ascending order ? (true for 2theta, false for TOF)
REAL mMaxSinThetaOvLambda
Maximum sin(theta)/lambda for all calculations (10 by default).
virtual void SetName(const string &name)
Name of the object.
virtual REAL GetLogLikelihood() const
The optimized (minimized, actually) function.
REAL mXZero
Zero correction : Thus mPowderPattern2ThetaMin=(mPowderPattern2ThetaMin-m2ThetaZero) ...
virtual const CrystVector_REAL & GetPowderPatternCalc() const
Get the calculated powder pattern for this component.
void Refine(int nbCycle=1, bool useLevenbergMarquardt=false, const bool silent=false, const bool callBeginEndOptimization=true, const float minChi2var=0.01)
Do the refinement.
unsigned int GetNbPowderPatternComponent() const
Number of components.
CrystVector_REAL mX
reflection coordinates in an orthonormal base
Abstract Base Class to describe the scattering power of any Scatterer component in a crystal...