@@ -84,7 +84,8 @@ const string & CylinderAbsCorr::GetClassName() const
8484void CylinderAbsCorr::CalcCorr () const
8585{
8686 mpData->GetTheta (); // Make sure theta is up-to-date
87- if (mpPowderPatternDiff->GetParentPowderPattern ().GetClockPowderPatternAbsCorr () < mClockCorrCalc ) return ;
87+ if ((mpPowderPatternDiff->GetParentPowderPattern ().GetClockPowderPatternAbsCorr () < mClockCorrCalc )
88+ && (mpData->GetClockTheta ()<mClockCorrCalc )) return ;
8889 TAU_PROFILE (" CylinderAbsCorr::CalcCorr()" ," void ()" ,TAU_DEFAULT);
8990 mCorr .resize (mpData->GetNbRefl ());
9091 const REAL muR = mpPowderPatternDiff->GetParentPowderPattern ().GetMuR ();
@@ -1194,6 +1195,7 @@ void PowderPatternDiffraction::ExtractLeBail(unsigned int nbcycle)
11941195 }
11951196 mClockFhklObsSq .Click ();
11961197 // cout<<"PowderPatternDiffraction::ExtractLeBail():results (scale factor="<<mpParentPowderPattern->GetScaleFactor(*this)*1e6<<")" <<endl<< FormatVertVectorHKLFloats<REAL>(mH,mK,mL,this->GetFhklCalcSq(),mFhklObsSq,10,4,nbrefl)<<endl;
1198+ mClockIhklCalc .Reset (); // During Le Bail
11971199 }
11981200 // Store extracted data in a single crystal data object
11991201 if (mpLeBailData==0 ) mpLeBailData=new DiffractionDataSingleCrystal (*mpCrystal,false );
@@ -1278,9 +1280,9 @@ unsigned int PowderPatternDiffraction::GetProfileFitNetNbObs()const
12781280 irefl++;
12791281 if (irefl>=this ->GetNbReflBelowMaxSinThetaOvLambda ()) break ;
12801282 }
1281- REAL stol=mSinThetaLambda (irefl);
12821283 while (irefl<this ->GetNbReflBelowMaxSinThetaOvLambda ())
12831284 {
1285+ const REAL stol = mSinThetaLambda (irefl);
12841286 while (mSinThetaLambda (irefl)==stol)
12851287 {
12861288 // cout<<int(mH(irefl))<<" "<<int(mK(irefl))<<" "<<int(mL(irefl))<<endl;
@@ -1291,7 +1293,6 @@ unsigned int PowderPatternDiffraction::GetProfileFitNetNbObs()const
12911293 if (nbnew>1 ) nb += nbnew-1 ;
12921294 // cout<<" => Added "<< nbnew-1<< "net observed points ("<<this->GetParentPowderPattern().STOL2Pixel(stol)<<"-"<<ilast<<")"<<endl;
12931295 ilast=this ->GetParentPowderPattern ().STOL2Pixel (stol);
1294- stol = mSinThetaLambda (irefl);
12951296 }
12961297 // cout<<"Final number of net observed points: "<<nb<<endl;
12971298 return nb;
@@ -2387,6 +2388,7 @@ void PowderPatternDiffraction::CalcFrozenBMatrix()const
23872388void PowderPatternDiffraction::PrepareIntegratedProfile ()const
23882389{
23892390 this ->CalcPowderReflProfile ();
2391+ this ->GetNbReflBelowMaxSinThetaOvLambda ();
23902392
23912393 if ( (mClockIntegratedProfileFactor >mClockProfileCalc )
23922394 &&(mClockIntegratedProfileFactor >mpParentPowderPattern->GetIntegratedProfileLimitsClock ())
@@ -4508,7 +4510,7 @@ void PowderPattern::FitScaleFactorForR()const
45084510 -mScaleFactor (mScalableComponentIndex (i));
45094511 if (ISNAN_OR_INF (s))
45104512 {
4511- (*fpObjCrystInformUser)(" Warning: working around NaN scale factor..." );
4513+ (*fpObjCrystInformUser)(" Warning:FitScaleFactorForR: working around NaN scale factor..." );
45124514 continue ;
45134515 }
45144516 for (unsigned long j=0 ;j<mNbPointUsed ;j++) *p0++ += s * *p1++;
@@ -4657,7 +4659,7 @@ void PowderPattern::FitScaleFactorForIntegratedR()const
46574659 -mScaleFactor (mScalableComponentIndex (i));
46584660 if (ISNAN_OR_INF (s))
46594661 {
4660- (*fpObjCrystInformUser)(" Warning: working around NaN scale factor..." );
4662+ (*fpObjCrystInformUser)(" Warning:FitScaleFactorForIntegratedR: working around NaN scale factor..." );
46614663 continue ;
46624664 }
46634665 for (unsigned long j=0 ;j<mNbPointUsed ;j++) *p0++ += s * *p1++;
@@ -4833,7 +4835,7 @@ void PowderPattern::FitScaleFactorForRw()const
48334835 -mScaleFactor (mScalableComponentIndex (i));
48344836 if (ISNAN_OR_INF (s))
48354837 {
4836- (*fpObjCrystInformUser)(" Warning: working around NaN scale factor..." );
4838+ (*fpObjCrystInformUser)(" Warning:FitScaleFactorForRw working around NaN scale factor..." );
48374839 continue ;
48384840 }
48394841 for (unsigned long j=0 ;j<mNbPointUsed ;j++) *p0++ += s * *p1++;
@@ -5065,7 +5067,7 @@ void PowderPattern::FitScaleFactorForIntegratedRw()const
50655067 -mScaleFactor (mScalableComponentIndex (i));
50665068 if (ISNAN_OR_INF (s))
50675069 {
5068- (*fpObjCrystInformUser)(" Warning: working around NaN scale factor..." );
5070+ (*fpObjCrystInformUser)(" Warning:FitScaleFactorForIntegratedRw: working around NaN scale factor..." );
50695071 continue ;
50705072 }
50715073 if (nbVarCalc>0 )
@@ -6779,14 +6781,14 @@ WXCrystObjBasic* PowderPattern::WXCreate(wxWindow* parent)
67796781/* * Structure to hold the score corresponding to a given spacegroup.
67806782 *
67816783 */
6782- SPGScore::SPGScore (const string &s, const REAL r, const REAL g, const unsigned int nbextinct, const REAL ngof):
6783- hm (s),rw(r),gof(g),ngof(ngof),nbextinct446(nbextinct)
6784+ SPGScore::SPGScore (const string &s, const REAL r, const REAL g, const unsigned int nbextinct, const REAL ngof, const unsigned int nbrefl ):
6785+ hm (s),rw(r),gof(g),ngof(ngof),nbextinct446(nbextinct),nbreflused(nbrefl)
67846786 {};
67856787
67866788
67876789bool compareSPGScore (const SPGScore &s1, const SPGScore &s2)
67886790{
6789- if (s1.ngof > 0.01 && s2.ngof >0.01 ) return s1.ngof < s2.ngof ;
6791+ if (s1.ngof > 0.00001 && s2.ngof >0.00001 ) return s1.ngof < s2.ngof ;
67906792 return s1.gof < s2.gof ;
67916793}
67926794
@@ -6855,7 +6857,6 @@ SPGScore SpaceGroupExplorer::Run(const cctbx::sgtbx::space_group &spg, const boo
68556857 TAU_PROFILE_TIMER (timer1," SpaceGroupExplorer::Run()LSQ-P1" ," " , TAU_FIELD);
68566858 TAU_PROFILE_TIMER (timer2," SpaceGroupExplorer::Run()LSQ1" ," " , TAU_FIELD);
68576859 TAU_PROFILE_TIMER (timer3," SpaceGroupExplorer::Run()LSQ2" ," " , TAU_FIELD);
6858- mpDiff->SetExtractionMode (true ,true );
68596860 Crystal *pCrystal=&(mpDiff->GetCrystal ());
68606861 // Keep initial lattice parameters & spg
68616862 const REAL a=pCrystal->GetLatticePar (0 ),
@@ -6875,6 +6876,7 @@ SPGScore SpaceGroupExplorer::Run(const cctbx::sgtbx::space_group &spg, const boo
68756876 throw ObjCrystException (" Spacegroup is not compatible with unit cell." );
68766877 }
68776878 mpDiff->GetCrystal ().Init (a,b,c,d,e,f,hm,name);
6879+ mpDiff->SetExtractionMode (true ,true );
68786880 unsigned int nbcycle=1 ;
68796881 if (update_display) mpDiff->GetParentPowderPattern ().UpdateDisplay ();
68806882 // Number of free parameters (not taking into account refined profile/background parameters)
@@ -6897,7 +6899,7 @@ SPGScore SpaceGroupExplorer::Run(const cctbx::sgtbx::space_group &spg, const boo
68976899 if (verbose) cout<<" Doing Le Bail, t=" <<FormatFloat (t0,6 ,2 )<<" s" ;
68986900 mpDiff->ExtractLeBail (5 );
68996901 if (verbose) cout<<" , dt=" <<FormatFloat (chrono.seconds ()-t0,6 ,2 )<<" s" <<endl;
6900- mpDiff->GetParentPowderPattern ().FitScaleFactorForRw ();
6902+ // mpDiff->GetParentPowderPattern().FitScaleFactorForIntegratedRw ();
69016903 if (fitprofile)
69026904 {// Perform LSQ
69036905 TAU_PROFILE_START (timer2);
@@ -6943,7 +6945,7 @@ SPGScore SpaceGroupExplorer::Run(const cctbx::sgtbx::space_group &spg, const boo
69436945 lsq.SafeRefine (vnewpar,vnewpartype,1.01 ,3 ,true ,true );
69446946 TAU_PROFILE_STOP (timer3);
69456947 // mpLog->AppendText(wxString::Format(_T("%5.2f%%/"),pDiff->GetParentPowderPattern().GetRw()*100));
6946- mpDiff->GetParentPowderPattern ().FitScaleFactorForRw ();
6948+ // mpDiff->GetParentPowderPattern().FitScaleFactorForIntegratedRw ();
69476949 }
69486950 if (update_display) mpDiff->GetParentPowderPattern ().UpdateDisplay ();
69496951 const REAL rw=mpDiff->GetParentPowderPattern ().GetRw ()*100 ;
@@ -6952,10 +6954,12 @@ SPGScore SpaceGroupExplorer::Run(const cctbx::sgtbx::space_group &spg, const boo
69526954 }
69536955 const REAL rw=mpDiff->GetParentPowderPattern ().GetRw ()*100 ;
69546956 const REAL gof=mpDiff->GetParentPowderPattern ().GetChi2 ()/nbfreepar;
6957+ const REAL ngof = this ->GetP1IntegratedGoF ();
69556958 unsigned int nbextinct446=0 ;
69566959 std::vector<bool > fgp=spgExtinctionFingerprint (*pCrystal,spg);
69576960 for (unsigned int i=6 ;i<fgp.size ();++i) nbextinct446+=(unsigned int )(fgp[i]);
6958- if (verbose>0 ) cout << boost::format (" Rwp= %5.2f%% GoF=%9.2f (%2u extinct refls)" ) % rw % gof % nbextinct446<<endl;
6961+ const unsigned int nbrefl = mpDiff->GetNbReflBelowMaxSinThetaOvLambda ();
6962+ if (verbose>0 ) cout << boost::format (" Rwp= %5.2f%% GoF=%9.2f nGoF =%9.2f (%3u reflections, %3u extinct)" ) % rw % gof % ngof % nbrefl % nbextinct446<<endl;
69596963
69606964 if (restore_orig)
69616965 {
@@ -6968,7 +6972,7 @@ SPGScore SpaceGroupExplorer::Run(const cctbx::sgtbx::space_group &spg, const boo
69686972 }
69696973 }
69706974
6971- return SPGScore (hm.c_str (),rw,gof,nbextinct446);
6975+ return SPGScore (hm.c_str (),rw,gof,nbextinct446, ngof, nbrefl );
69726976}
69736977
69746978void SpaceGroupExplorer::RunAll (const bool fitprofile_all, const bool verbose, const bool keep_best,
@@ -7027,18 +7031,24 @@ void SpaceGroupExplorer::RunAll(const bool fitprofile_all, const bool verbose, c
70277031 std::map<std::vector<bool >,SPGScore>::iterator posfgp=mvSPGExtinctionFingerprint.find (fgp);
70287032 if (posfgp!=mvSPGExtinctionFingerprint.end ())
70297033 {
7030- mvSPG.push_back (SPGScore (hm.c_str (),posfgp->second .rw ,posfgp->second .gof ,posfgp->second .nbextinct446 , posfgp->second .ngof ));
7031- if (verbose) cout<<" Spacegroup:" <<hm<<" has same extinctions as:" <<posfgp->second .hm <<endl;
7034+ pCrystal->Init (a,b,c,d,e,f,hm,name);
7035+ mpDiff->SetExtractionMode (true ,true ); // :TODO: why is this needed to actually get the updated GetNbReflBelowMaxSinThetaOvLambda ?
7036+ unsigned int nbrefl = mpDiff->GetNbReflBelowMaxSinThetaOvLambda ();
7037+ REAL ngof = (posfgp->second .ngof * nbrefl) / posfgp->second .nbreflused ;
7038+ mvSPG.push_back (SPGScore (hm.c_str (),posfgp->second .rw ,posfgp->second .gof ,posfgp->second .nbextinct446 , ngof, posfgp->second .nbreflused ));
7039+ if (verbose) cout<<boost::format (" (#%3d) %-14s: Rwp= %5.2f%% GoF=%9.2f nGoF=%9.2f (%3u reflections, %3u extinct)" )
7040+ % s.number () % hm.c_str () % mvSPG.back ().rw % mvSPG.back ().gof % mvSPG.back ().ngof % mvSPG.back ().nbreflused % mvSPG.back ().nbextinct446
7041+ <<" [same extinctions as:" <<posfgp->second .hm <<" ]\n " ;
70327042 }
70337043 else
70347044 {
70357045 if (((s.number ()==1 ) && fitprofile_p1) || fitprofile_all) mvSPG.push_back (this ->Run (spg, true , false , false , update_display));
70367046 else mvSPG.push_back (this ->Run (spg, false , false , true , update_display));
7037- mvSPG.back ().ngof = mvSPG. back (). gof * mpDiff->GetNbReflBelowMaxSinThetaOvLambda () / (float )nb_refl_p1;
7047+ mvSPG.back ().ngof *= mpDiff->GetNbReflBelowMaxSinThetaOvLambda () / (float )nb_refl_p1;
70387048 mvSPGExtinctionFingerprint.insert (make_pair (fgp, mvSPG.back ()));
70397049
7040- if (verbose) cout<<boost::format (" (#%3d) %-14s: Rwp= %5.2f%% GoF=%9.2f nGoF=%9.2f (%2u extinct refls )\n " )
7041- % s.number () % hm.c_str () % mvSPG.back ().rw % mvSPG.back ().gof % mvSPG.back ().ngof % mvSPG.back ().nbextinct446 ;
7050+ if (verbose) cout<<boost::format (" (#%3d) %-14s: Rwp= %5.2f%% GoF=%9.2f nGoF=%9.2f (%3u reflections, %3u extinct )\n " )
7051+ % s.number () % hm.c_str () % mvSPG.back ().rw % mvSPG.back ().gof % mvSPG.back ().ngof % mvSPG.back ().nbreflused % mvSPG. back (). nbextinct446 ;
70427052 }
70437053 }
70447054 }
@@ -7067,5 +7077,46 @@ const list<SPGScore>& SpaceGroupExplorer::GetScores() const
70677077{
70687078 return mvSPG;
70697079}
7080+
7081+ REAL SpaceGroupExplorer::GetP1IntegratedGoF ()
7082+ {
7083+ if (mpDiff->GetCrystal ().GetSpaceGroup ().GetSpaceGroupNumber ()==1 )
7084+ {
7085+ mpDiff->GetPowderPatternIntegratedCalc ();
7086+ mP1IntegratedProfileMin = mpDiff->GetParentPowderPattern ().GetIntegratedProfileMin ();
7087+ mP1IntegratedProfileMax = mpDiff->GetParentPowderPattern ().GetIntegratedProfileMax ();
7088+ cout<<" Updating mP1IntegratedProfileMin/Max:" <<endl
7089+ <<FormatVertVectorHKLFloats<REAL>(mP1IntegratedProfileMin , mP1IntegratedProfileMax ,mP1IntegratedProfileMax )<<endl;
7090+ }
7091+ else if (mP1IntegratedProfileMin .size ()==0 ) return 0 ;
7092+
7093+ // cout<<FormatVertVectorHKLFloats<REAL>(mpDiff->GetH(), mpDiff->GetK(), mpDiff->GetL(), mpDiff->GetFhklCalcSq());
7094+ REAL integratedChi2=0 .;
7095+ REAL integratedChi2LikeNorm=0 .;
7096+ const REAL * RESTRICT p1, * RESTRICT p2, * RESTRICT p3;
7097+ CrystVector_REAL const * pcalc = &(mpDiff->GetParentPowderPattern ().GetPowderPatternCalc ());
7098+ CrystVector_REAL const * pobs = &(mpDiff->GetParentPowderPattern ().GetPowderPatternObs ());
7099+ CrystVector_REAL const * psigma = &(mpDiff->GetParentPowderPattern ().GetPowderPatternObsSigma ());
7100+ const unsigned int jmax = mpDiff->GetParentPowderPattern ().GetNbPointUsed ();
7101+ REAL chi2=0 ;
7102+ unsigned int nbpoint = 0 ;
7103+ for (unsigned long i=0 ;i<mP1IntegratedProfileMin .size ();i++)
7104+ {
7105+ if (mP1IntegratedProfileMin (i) > jmax) break ;
7106+ if (mP1IntegratedProfileMax (i) < 0 ) continue ;
7107+ REAL v=0 , c=0 , o=0 ;
7108+ for (unsigned long j=mP1IntegratedProfileMin (i); j<=mP1IntegratedProfileMax (i); j++)
7109+ {
7110+ if (j<0 ) continue ;
7111+ if (j >= jmax) break ;
7112+ nbpoint++;
7113+ c += (*pcalc)(j); // calc
7114+ o += (*pobs)(j); // obs
7115+ v += (*psigma)(j)*(*psigma)(j); // variance
7116+ }
7117+ if (v>0 ) chi2 += (c-o)*(c-o)/v;
7118+ }
7119+ return chi2 / nbpoint;
7120+ }
70707121
70717122}// namespace ObjCryst
0 commit comments