Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

XRXPS.H

Go to the documentation of this file.
00001 //: xrxps.h
00010 #if defined (__GNUG__)
00011     #pragma interface "xrxps.h"
00012 #endif
00013 
00014 #ifndef xrxps_h
00015 #define xrxps_h
00016 
00017 #include <wx/wxprec.h>
00018 
00019 #ifdef __BORLANDC__
00020     #pragma hdrstop
00021 #endif
00022 
00023 #ifndef WX_PRECOMP
00024     #include <wx/wx.h>
00025 #endif
00026 
00027 #include    "xps4xps.h"
00028 #include    "utils.h"
00029 
00030 extern float E4Background; 
00031 
00036 class   xpRuleXPS : public xpRuleGeneric
00037 {   protected:
00038     public:
00041         xpRuleXPS(  xpAgent *MyAgent=NULL)
00042         :xpRuleGeneric(MyAgent)
00043         {   }// of xpRuleXPS::xpRuleXPS
00045         xpRuleXPS(const xpRuleXPS &xr) 
00046         {   }
00047 };//xpRuleXPS
00048 
00052 class xrIsEnergyBE : public xpRuleXPS
00053 {
00054     public:
00056         xrIsEnergyBE(   xpAgent *MyAgent=NULL);
00058         xpRuleGeneric   Fire(void);
00059 };// of xrIsEnergyBE
00060 
00062 
00063 class xrIsEnergyKE : public xpRuleXPS
00064 {
00065     public:
00067         xrIsEnergyKE(   xpAgent *MyAgent=NULL);
00069         xpRuleGeneric   Fire(void);
00070 };// of xrIsEnergyKE
00071 
00073 
00075 class xrIsXEnergyKnown : public xpRuleXPS
00076 {
00077     public:
00079         xrIsXEnergyKnown(   xpAgent *MyAgent=NULL)
00080         :xpRuleXPS(MyAgent)
00081         {   Name = _("Exciting energy known"); }
00084         xpRuleGeneric   Fire(void)
00085         {   xpSpectrumBase *xpS = (xpSpectrumBase *) Agent;
00086             if(xpS)
00087                 value = xpS->GetXEnergyKnown();
00088             else
00089             {
00090                 value = Unknown; HistoryString << _("No spectrum known");
00091                 return *this;
00092             }
00093             if(xboolean::True == value)
00094                 HistoryString << _("Excitation energy is given");
00095             else if (xboolean::False == value)
00096                 HistoryString << _("Excitation energy is NOT given");
00097             else HistoryString << _("Excitation energy is unknown");
00098             return *this;
00099         }
00100 };// of xrIsXEnergyKnown
00101 
00103 
00113 class xrIsEnergyAvailBE : public xpRuleXPS
00114 {
00115     public:
00117         xrIsEnergyAvailBE(  xpAgent *MyAgent=NULL)
00118         :xpRuleXPS(MyAgent)
00119         {   Name = _("Binding energy available");  }
00121         xpRuleGeneric   Fire(void)
00122         {
00123             return  xrIsEnergyBE(Agent).Fire()
00124                       OR
00125                       ( xrIsEnergyKE(Agent).Fire()
00126                         AND
00127                         xrIsXEnergyKnown(Agent).Fire()
00128                       );
00129         }
00130 };// of xrIsEnergyAvailBE
00131 
00133 
00143 class xrIsEnergyAvailKE : public xpRuleXPS
00144 {
00145     public:
00147         xrIsEnergyAvailKE(  xpAgent *MyAgent=NULL)
00148         :xpRuleXPS(MyAgent)
00149         {   Name = _("Kinetic energy available");  }
00151         xpRuleGeneric   Fire(void)
00152         {   
00153             return xrIsEnergyKE(Agent).Fire()
00154                       OR
00155                       ( xrIsEnergyBE(Agent).Fire()
00156                         AND
00157                         xrIsXEnergyKnown(Agent).Fire()
00158                       );
00159         }
00160 };// of xrIsEnergyAvailKE
00161 
00163 
00172 class xrIsRegionMeasuredBE : public xpRuleXPS
00173 {   protected:
00174         float   BELow,      
00175             BEHigh;     
00176     public:
00178         xrIsRegionMeasuredBE(   xpAgent *MyAgent, float Low, float High)
00179         :xpRuleXPS(MyAgent)
00180         {   Name << wxString::Format(_("BE region [%s,%s] is measured")
00181                     , GetFormatted(Low), GetFormatted(High)); 
00182             BELow = Low; BEHigh = High;
00183         }
00185         xpRuleGeneric   Fire(void)
00186         {   xpSpectrumBase *xpS = (xpSpectrumBase *) Agent;
00187             if(xpS )
00188             {   // Yes, we have a spectrum
00189                 float MyLow, MyHigh, MyE = 0.0f;
00190                 if (!( xboolean::Unknown == xpS->GetEnergyBE()) )
00191                     // return the charging-correction energy
00192                     MyE = xpS->GetChargingEnergy();
00193                 if( xpS->IsEnergyBE())
00194                 {// the energy data are given on BE scale
00195                     MyLow = xpS->GetMinEnergy()+MyE;
00196                     MyHigh = xpS->GetMaxEnergy()+MyE;
00197                 }
00198                 else if(( xpS->IsEnergyKE()) AND ( xpS->IsXEnergyKnown()))
00199                 {// then we have to calculate the value from the kinetic energy
00200                     MyLow = xpS->ToBE(xpS->GetMaxEnergy()+MyE);
00201                     MyHigh = xpS->ToBE(xpS->GetMinEnergy()+MyE);
00202                 }
00203                 else
00204                 {   value = Unknown; HistoryString << _("No energy info given"); return *this;}
00205                 // Now we know that the energy type is known and MyLow and MyHigh contain 
00206                 // the correct values, on binding scale
00207                 value = (xboolean::xbool)
00208                         (xpSpectrumBase::IsInRangeE(MyLow,MyHigh, BELow)
00209                            &&
00210                          xpSpectrumBase::IsInRangeE(MyLow,MyHigh, BEHigh)
00211                         );
00212                 if(xboolean::True == value)
00213                     HistoryString << wxString::Format(_("BE region [%s,%s] is within measured range [%s,%s] ")
00214                                     , GetFormatted(BELow), GetFormatted(BEHigh), GetFormatted(MyLow), GetFormatted(MyHigh));
00215                 else if (xboolean::False == value)
00216                     HistoryString << wxString::Format(_("BE region [%s,%s] is NOT within measured range [%s,%s] ")
00217                                     , GetFormatted(BELow), GetFormatted(BEHigh), GetFormatted(MyLow), GetFormatted(MyHigh) );
00218                 else HistoryString << _("Some error occurred");
00219                     return *this;
00220             }
00221             else 
00222             {   value = Unknown;  HistoryString << _("No spectrum known"); 
00223                 return *this;
00224             }
00225         }// of Fire
00226 };// of xrIsRegionMeasuredBE
00227 
00229 
00237 class xrIsRegionMeasuredKE : public xpRuleXPS
00238 {   protected:
00239         float   KELow,      
00240                 KEHigh;     
00241     public:
00243         xrIsRegionMeasuredKE(   xpAgent *MyAgent, float Low, float High)
00244         :xpRuleXPS(MyAgent)
00245         {   Name << wxString::Format(_("KE region [%s,%s] is measured")
00246                         , GetFormatted(Low), GetFormatted(High));
00247              KELow = Low; KEHigh = High;
00248         }
00250         xpRuleGeneric   Fire(void)
00251         {   xpSpectrumBase *xpS = (xpSpectrumBase *) Agent;
00252             if(xpS )
00253             {   // Yes, we have a spectrum
00254                 float MyLow, MyHigh, MyE = 0.0f;
00255                 if (!( xboolean::Unknown == xpS->GetEnergyBE()) )
00256                     // return the charging-correction energy
00257                     MyE = xpS->GetChargingEnergy();
00258                 if( xpS->IsEnergyKE())
00259                 {// the energy data are given on KE scale
00260                     MyLow = xpS->GetMinEnergy()+MyE;
00261                     MyHigh = xpS->GetMaxEnergy()+MyE;
00262                 }
00263                 else if(( xpS->IsEnergyBE()) AND ( xpS->IsXEnergyKnown()))
00264                 {// then we have to calculate the value from the bindinf energy
00265                     MyLow = xpS->ToKE(xpS->GetMaxEnergy()+MyE);
00266                     MyHigh = xpS->ToKE(xpS->GetMinEnergy()+MyE);
00267                 }
00268                 else
00269                 {   value = Unknown; HistoryString << _("No energy info given"); return *this;}
00270                     // Now we know that the energy type is known and MyLow and MyHigh contain 
00271                     // the correct values, on kinetic scale
00272                 value = (xboolean::xbool)
00273                         (
00274                             xpSpectrumBase::IsInRangeE(MyLow,MyHigh, KELow)
00275                                 &&
00276                             xpSpectrumBase::IsInRangeE(MyLow,MyHigh, KEHigh)
00277                         );
00278                 if(xboolean::True == value)
00279                     HistoryString << wxString::Format(_("KE region [%s,%s] is within measured range [%s,%s] ")
00280                                     , GetFormatted(KELow), GetFormatted(KEHigh), GetFormatted(MyLow), GetFormatted(MyHigh) );
00281                  else if (xboolean::False == value)
00282                      HistoryString << wxString::Format(_("KE region [%s,%s] is NOT within measured range [%s,%s] ")
00283                                     , GetFormatted(KELow), GetFormatted(KEHigh), GetFormatted(MyLow), GetFormatted(MyHigh) );
00284                  else HistoryString << _("Some error occurred");
00285                 return *this;
00286             }
00287             else 
00288             {   value = Unknown;  HistoryString << _("No spectrum known"); 
00289                 return *this;
00290             }
00291         }// of Fire
00292 };// of xrIsRegionMeasuredKE
00293 
00295 
00302 class xrIsPeakInRangeBE : public xpRuleXPS
00303 {   protected:
00304         float   BELow,      
00305                 BEHigh;     
00306     public:
00309         xrIsPeakInRangeBE(  xpAgent *MyAgent, float Low, float High)
00310         :xpRuleXPS(MyAgent)
00311         {
00312             Name << wxString::Format(_("Peak is in BE range [%s,%s] ")
00313                     , GetFormatted(Low), GetFormatted(High));
00314             BELow = Low; BEHigh = High;
00315         }
00317         xpRuleGeneric   Fire(void)
00318         {   xpPeakBase *xpP = (xpPeakBase *) Agent;
00319             if(xpP )
00320             {   // Yes, we have a peak
00321                 float MyEnergy ;
00322                 // Now calculate peak energy and put it on binding scale
00323                 if( xpP->IsEnergyBE())
00324                 {// the peak energy data is given on BE scale
00325                     MyEnergy = xpP->GetEnergy(true);
00326                 }
00327                 else if(( xpP->IsEnergyKE()) AND ( xpP->IsXEnergyKnown()))
00328                 {// then we have to calculate the value from the kinetic energy
00329                     MyEnergy = xpP->ToBE(xpP->GetEnergy(true));
00330                 }
00331                 else
00332                 {   value = Unknown; HistoryString << _("No peak energy info given"); return *this;}
00333                 // Now calculate the peak energy limits, on BE scale
00334                 xpSpectrumBase *xpS = xpP->GetSpectrum();
00335                 //OK, let see if region is measured for peak + background
00336                 xpRuleGeneric a = xrIsRegionMeasuredBE(xpS,BELow-E4Background,BEHigh+E4Background).Fire();
00337                 if(!a.IsTrue())
00338                     {// The region is not measured, or the background region is not long enough
00339                         value = a.GetValue();
00340                         HistoryString = a.GetHistoryString();
00341                         return *this;
00342                     }
00343                 // OK, the region is measured, with sufficiently long background
00344                 value = (xboolean::xbool) (xpSpectrumBase::IsInRangeE(BELow, BEHigh, MyEnergy));
00345                 if(xboolean::True == value)
00346                     HistoryString << wxString::Format(_("Peak energy %s is in BE range [%s,%s] ")
00347                                 , GetFormatted(xpP->GetEnergy(true)), GetFormatted(BELow), GetFormatted(BEHigh));
00348                 else if (xboolean::False == value)
00349                     HistoryString << wxString::Format(_("Peak energy %s is NOT in BE range [%s,%s] ")
00350                                 , GetFormatted(xpP->GetEnergy(true)), GetFormatted(BELow), GetFormatted(BEHigh));
00351                 else HistoryString << _("Some error occurred");
00352                 return *this;
00353             }
00354             else 
00355             {   value = Unknown; return *this;}
00356         }// of Fire
00357 };// of xrIsPeakInRangeBE
00358 
00360 
00367 class xrIsPeakInRangeKE : public xpRuleXPS
00368 {   protected:
00369         float   KELow,      
00370                 KEHigh;     
00371     public:
00373         xrIsPeakInRangeKE(  xpAgent *MyAgent, float Low, float High)
00374         :xpRuleXPS(MyAgent)
00375         {   Name << wxString::Format(_("Peak is in KE range [%s,%s] ")
00376                     , GetFormatted(Low), GetFormatted(High));
00377             KELow = Low; KEHigh = High;
00378         }
00380         xpRuleGeneric   Fire(void)
00381         {   xpPeakBase *xpP = (xpPeakBase *) Agent;
00382             if(xpP )
00383             {   // Yes, we have a peak
00384                 float MyEnergy ;
00385                 // Now calculate peak energy and put it on kinetic scale
00386                 if( xpP->IsEnergyKE())
00387                 {// the peak energy data is given on KE scale
00388                     MyEnergy = xpP->GetEnergy(true);
00389                 }
00390                 else if(( xpP->IsEnergyBE()) AND ( xpP->IsXEnergyKnown()))
00391                 {// then we have to calculate the value from the binding energy
00392                     MyEnergy = xpP->ToKE(xpP->GetEnergy(true));
00393                 }
00394                 else
00395                 {   value = Unknown; HistoryString << _("No peak energy info given"); return *this;}
00396                 // Now calculate the peak energy limits, on KE scale
00397                 xpSpectrumBase *xpS = xpP->GetSpectrum();
00398                 //OK, let see if region is measured for peak + background
00399                 xpRuleGeneric a = xrIsRegionMeasuredKE(xpS,KELow-E4Background,KEHigh+E4Background).Fire();
00400                 if(!a.IsTrue())
00401                 {// The region is not measured, or the background region is not long enough
00402                     value = a.GetValue();
00403                     HistoryString = a.GetHistoryString();
00404                     return *this;
00405                 }
00406                 // OK, the region is measured, with sufficiently long background
00407                 value = (xboolean::xbool) (xpSpectrumBase::IsInRangeE(KELow, KEHigh, MyEnergy));
00408                 if(xboolean::True == value)
00409                     HistoryString << wxString::Format(_("Peak energy %s is in KE range [%s,%s] ")
00410                                     , GetFormatted(xpP->GetEnergy(true)), GetFormatted(KELow), GetFormatted(KEHigh));
00411                 else if (xboolean::False == value)
00412                     HistoryString << wxString::Format(_("Peak energy %s is NOT in KE range [%s,%s] ")
00413                                     , GetFormatted(xpP->GetEnergy(true)), GetFormatted(KELow), GetFormatted(KEHigh));
00414                 else HistoryString << _("Some error occurred");
00415                 return *this;
00416             }
00417             else 
00418             {   value = Unknown; return *this;}
00419         }// of Fire
00420 };// of xrIsPeakInRangeKE
00421 
00423 
00428 class xrHasPeakInRangeBE : public xpRuleXPS
00429 {   protected:
00430         float   BELow,      
00431                 BEHigh;     
00432     public:
00434         xrHasPeakInRangeBE( xpAgent *MyAgent, float Low, float High);
00435 /*        :xpRuleXPS(MyAgent);
00436         {   Name << wxString::Format(_("Has peak in BE range [%s,%s]")
00437                     , GetFormatted(Low) , GetFormatted(High));
00438             BELow = Low; BEHigh = High;
00439         }*/
00441         xpRuleGeneric   Fire(void);
00442 /*        {   xpSpectrumBase *xpS = (xpSpectrumBase *) Agent;
00443             if(!xpS) 
00444             {
00445                 value = Unknown; 
00446                 HistoryString << _("No spectrum is present");
00447                 return *this;
00448             }
00449             // Yes, we have a spectrum, check if BE available
00450             xpRuleGeneric a = xrIsEnergyAvailBE(xpS).Fire();
00451             if(!a.IsTrue())
00452             {
00453                 value = a.value;
00454                 HistoryString = a.GetHistoryString();
00455                 return *this;
00456             }
00457             // Check if we have spectrum
00458             int NP = xpS->GetPeaks()->Number();
00459             if(!NP)
00460             {   
00461                 value = False;
00462                 HistoryString << _("No peaks found in the spectrum");
00463             }
00464             else
00465             {// we have at least one peak
00466                 xboolean Found = xboolean::False;
00467                 xpPeakBase *xpP = (xpPeakBase *) NULL; 
00468                 for(int i = 0; (i < NP) AND !Found.IsTrue(); i++)
00469                 {   // Check all peaks if their energy is within the BE range
00470                     xpP = (xpPeakBase *)xpS->GetPeaks()->Nth(i)->GetData();
00471                     if(xrIsPeakInRangeBE(xpP,BELow,BEHigh).Fire().IsTrue())
00472                     {   
00473                         Found = xboolean::True;
00474                         HistoryString << wxString::Format(_("Peak at BE %s found in the BE range [%s,%s] ")
00475                                     , GetFormatted(xpP->GetEnergy()), GetFormatted(BELow), GetFormatted(BEHigh));
00476                         break;
00477                     }
00478                 }
00479                 value = Found.GetValue();
00480                 if(Found.IsFalse())
00481                 {
00482                     HistoryString << wxString::Format(_("No peak found in BE range [%s,%s] ")
00483                                 , GetFormatted(BELow), GetFormatted(BEHigh) );
00484                     value = False;
00485                 }
00486             }
00487             return *this;
00488         }// of Fire*/
00489 };// of xrHasPeakInRangeBE
00490 
00492 
00497 class xrHasPeakInRangeKE : public xpRuleXPS
00498 {   protected:
00499         float   KELow,      
00500                 KEHigh;     
00501     public:
00503         xrHasPeakInRangeKE( xpAgent *MyAgent, float Low, float High);
00505         xpRuleGeneric   Fire(void);
00506 };// of xrHasPeakInRangeKE
00507 
00508 #endif //xrxps_h

Generated on Tue Dec 23 10:24:08 2003 for xps4xps by doxygen 1.3.5