00001
00009 #if defined (__GNUG__)
00010 #pragma interface "xps4xps.h"
00011 #endif
00012
00013 #ifndef xps4xps_h
00014 #define xps4xps_h
00015
00016 #include <wx/wxprec.h>
00017
00018 #ifdef __BORLANDC__
00019 #pragma hdrstop
00020 #endif
00021
00022 #ifndef WX_PRECOMP
00023 #include <wx/wx.h>
00024 #endif
00025
00026 #include <math.h>
00027 #include "xprule.h"
00028
00029
00030 extern double EnergyTolerance;
00031
00032 class xpSpectrumBase;
00033 class xpPeakBase;
00034 class xpSampleBase;
00035 class xpPeakPanel;
00036
00038
00043 class xpSpectrumObjectAgent : public xpAgent
00044 { protected:
00045 float MaxEnergy;
00046 float MinEnergy;
00047 float XEnergy;
00048 xboolean::xbool EnergyBE;
00049 xboolean::xbool XEnergyKnown;
00050 public:
00058 xpSpectrumObjectAgent(void)
00059 { EnergyBE = xboolean::Unknown;
00060 XEnergyKnown= xboolean::Unknown;
00061 MinEnergy = 100; MaxEnergy = 1400;
00062 XEnergy = 1486.6f;
00063 }
00065 xpSpectrumObjectAgent(const xpSpectrumObjectAgent& S)
00066 {
00067 EnergyBE = S.EnergyBE;
00068 XEnergyKnown= S.XEnergyKnown;
00069 MinEnergy = S.MinEnergy; MaxEnergy = S.MaxEnergy;
00070 XEnergy = S.XEnergy;
00071 }
00074 xboolean::xbool GetEnergyBE(void)
00075 { return EnergyBE ; }
00079 float GetMaxEnergy(void)
00080 { return MaxEnergy;}
00084 float GetMinEnergy(void)
00085 { return MinEnergy;}
00089 float GetXEnergy(void)
00090 { return XEnergy;}
00094 xboolean::xbool GetXEnergyKnown(void)
00095 { return XEnergyKnown; }
00100 bool IsEnergyBE(void)
00101 { return static_cast<bool> (xboolean::True == EnergyBE); }
00106 bool IsEnergyKE(void)
00107 { return static_cast<bool> (xboolean::False == EnergyBE); }
00115 static bool IsInRangeE(float E1, float E2, float E)
00116 { return (E+EnergyTolerance >= E1) && (E-EnergyTolerance <= E2); }
00120 bool IsXEnergyKnown(void)
00121 { return static_cast<bool> (xboolean::True == XEnergyKnown); }
00125 void SetEnergyBE(xboolean::xbool B)
00126 { EnergyBE = B; }
00130 inline void SetMaxEnergy(float E)
00131 { MaxEnergy = E;}
00135 inline void SetMinEnergy(float E)
00136 { MinEnergy = E;}
00143 inline void SetXEnergy(float XE)
00144 { XEnergy = XE; SetXEnergyKnown( xboolean::True); }
00148 inline void SetXEnergyKnown(xboolean::xbool B)
00149 { XEnergyKnown = B;}
00153 float ToBE(float KE)
00154 { return XEnergy - KE;}
00158 float ToKE(float BE)
00159 { return XEnergy - BE;}
00160 };
00161
00163
00165 class xpSpectrumBase : public xpSpectrumObjectAgent
00166 { protected:
00167 float ChargingEnergy;
00168 float EnergySeparation;
00169 wxList PeakList;
00170 xpSampleBase *sample;
00171 public:
00174 xpSpectrumBase(void)
00175 {
00176 EnergySeparation = 12.0f;
00177 ChargingEnergy = 0.0f;
00178 sample = NULL;
00179 }
00183 xpSpectrumBase(const xpSpectrumBase& S)
00184 {
00185 sample = S.sample;
00186 ChargingEnergy = S.ChargingEnergy;
00187 EnergySeparation = S.EnergySeparation;
00188 }
00189
00191 virtual
00192 ~xpSpectrumBase(void) { };
00196 float GetChargingEnergy(void)
00197 { return ChargingEnergy;}
00201 float GetEnergySeparation(void)
00202 { return EnergySeparation;}
00205 wxList* GetPeaks(void)
00206 { return &PeakList;}
00210 xpSampleBase* GetSample(void)
00211 { return sample;}
00215 void SetChargingEnergy(float EC)
00216 { ChargingEnergy = EC;}
00220 void SetEnergySeparation(float ES)
00221 { EnergySeparation = ES;}
00225 void SetSample(xpSampleBase* S)
00226 { sample = S;}
00229 void SetConcentrations(void);
00230 };
00231
00232
00233
00234
00236
00238 class xpSampleBase : public xpAgent
00239 { protected:
00240 xboolean::xbool ContainsCarbon;
00241 xpSpectrumBase *ParentSpectrum;
00242 public:
00245 xpSampleBase()
00246 : xpAgent()
00247 { ParentSpectrum = NULL;
00248 ContainsCarbon = xboolean::Unknown;
00249 }
00253 xpSampleBase(xpSpectrumBase* Parent)
00254 : xpAgent()
00255 { ParentSpectrum = Parent;
00256 ParentSpectrum->SetSample(this);
00257 ContainsCarbon = xboolean::Unknown;
00258 }
00262 xboolean::xbool GetContainsCarbon(void)
00263 { return ContainsCarbon; }
00266 xpSpectrumBase* GetSpectrum()
00267 { return ParentSpectrum;}
00271 void SetContainsCarbon(xboolean::xbool B)
00272 { ContainsCarbon = B; }
00273 };
00274
00276
00279 class xpComponentBase : public xpSpectrumObjectAgent
00280 { protected:
00281 xpSpectrumBase *ParentSpectrum;
00282 public:
00284 xpComponentBase(void)
00285 : xpSpectrumObjectAgent()
00286 { ParentSpectrum = NULL;
00287 }
00293 xpComponentBase(xpSpectrumBase* Parent)
00294 : xpSpectrumObjectAgent()
00295 { ParentSpectrum = Parent;
00296 EnergyBE = ParentSpectrum->GetEnergyBE();
00297 XEnergyKnown = ParentSpectrum->GetXEnergyKnown();
00298 XEnergy = ParentSpectrum->GetXEnergy();
00299 }
00304 xpComponentBase(const xpComponentBase& C)
00305 { ParentSpectrum = C.ParentSpectrum;
00306 EnergyBE = C.EnergyBE;
00307 XEnergyKnown = C.XEnergyKnown;
00308 XEnergy = C.XEnergy;
00309 }
00312 xpSpectrumBase* GetSpectrum(void)
00313 { return ParentSpectrum;}
00314 };
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 class xpSpectrumBase;
00333
00335 class xpPeakBase : public xpComponentBase
00336 { protected:
00337 float Energy;
00338 float PostPeakSlope;
00339 float ShirleyTailHeight;
00340 float AngleRatio;
00341 float meastime,
00342 sensitivity,
00343 concentration,
00344 concentrationUncertainty,
00345 peakcounts,
00346 bgndcounts,
00347 peakrate,
00348 bgndrate,
00349 relprec;
00350 xboolean::xbool Carbon1sPeak;
00351 xpPeakPanel *m_peakpanel;
00352 public:
00357 xpPeakBase( xpSpectrumBase* Parent, float E = 0.0f)
00358 :xpComponentBase(Parent)
00359 {
00360 Energy = E;
00361 sensitivity = 1.0f;
00362 concentration = 0.0f;
00363 concentrationUncertainty = 0.0f;
00364 meastime = 1.0;
00365 peakcounts = 200.0;
00366 bgndcounts = 100.0;
00367 peakrate = GetRate(peakcounts);
00368 bgndrate = GetRate(bgndcounts);
00369 relprec = CalcRelPrec();
00370 PostPeakSlope = 0.03f;
00371 ShirleyTailHeight = 0.05f;
00372 AngleRatio = 0.6f;
00373 Carbon1sPeak = xboolean::Unknown;
00374 }
00378 xpPeakBase(const xpPeakBase& C )
00379 {
00380 Energy = C.Energy;
00381 sensitivity = C.sensitivity;
00382 concentration = C.concentration;
00383 concentrationUncertainty = C.concentrationUncertainty;
00384 meastime = C.meastime;
00385 peakcounts = C.peakcounts;
00386 bgndcounts = C.bgndcounts;
00387 peakrate = C.peakrate;
00388 bgndrate = C.bgndrate;
00389 relprec = C.relprec;
00390 PostPeakSlope = C.PostPeakSlope;
00391 ShirleyTailHeight = C.ShirleyTailHeight;
00392 AngleRatio = C.AngleRatio;
00393 Carbon1sPeak = C.Carbon1sPeak;
00394 }
00398 xboolean::xbool GetCarbon1sPeak(void) const
00399 { return Carbon1sPeak ; }
00400
00404 float GetRate(const float counts) const
00405 { return counts/meastime; }
00408 float GetMeasTime(void)
00409 { return meastime;}
00412 float GetSensitivity(void)
00413 { return sensitivity;}
00416 void SetSensitivity(const float S)
00417 { sensitivity = S;}
00418
00421 float GetConcentration(void)
00422 { return concentration;}
00425 void SetConcentration(const float C)
00426 { concentration = C;}
00429 float GetConcentrationUncertainty(void)
00430 { return concentrationUncertainty;}
00433 void SetConcentrationUncertainty(const float C)
00434 { concentrationUncertainty = C;}
00435
00439 void SetMeasTime(const float t)
00440 {
00441 meastime = t;
00442 peakcounts = peakrate*meastime;
00443 bgndcounts = bgndrate*meastime;
00444 CalcRelPrec();
00445 }
00448 float GetPeakCounts(void)
00449 { return peakcounts;}
00453 void SetPeakCounts(const float c)
00454 {
00455 peakcounts = c;
00456 peakrate = peakcounts/meastime;
00457 CalcRelPrec();
00458 }
00461 float GetBgndCounts(void)
00462 { return bgndcounts;}
00466 void SetBgndCounts(const float c)
00467 {
00468 bgndcounts = c;
00469 bgndrate = bgndcounts/meastime;
00470 CalcRelPrec();
00471 }
00474 float GetPeakRate(void)
00475 { return peakrate;}
00479 void SetPeakRate(const float r)
00480 {
00481 peakrate = r;
00482 peakcounts = peakrate * meastime;
00483 CalcRelPrec();
00484 }
00487 float GetBgndRate(void)
00488 { return bgndrate;}
00492 void SetBgndRate(const float r)
00493 {
00494 bgndrate = r;
00495 bgndcounts = bgndrate * meastime;
00496 CalcRelPrec();
00497 }
00500 float GetRelPrec(void)
00501 { return relprec; }
00504 float CalcRelPrec(void)
00505 { relprec = 100*sqrt(peakcounts+bgndcounts)/(peakcounts-bgndcounts);
00506 return relprec;
00507 }
00512 void SetRelPrec(const float r)
00513 { relprec = r;
00514 CalcRelPrec();
00515 }
00517
00530 float GetEstimatedPeakCounts( float rp )
00531 {
00532 return 100/rp*sqrt(GetPeakCounts()+GetBgndCounts()) + GetBgndCounts();
00533 }
00534
00537 float GetChargingEnergy(void) const
00538 { return ParentSpectrum->GetChargingEnergy(); }
00546 float GetEnergy(bool WithCharging = false)
00547 { float E = Energy;
00548 if(WithCharging && !( xboolean::Unknown == GetEnergyBE()) )
00549 {
00550 if(GetEnergyBE() == ParentSpectrum->GetEnergyBE())
00551
00552 E += GetChargingEnergy();
00553 else
00554
00555 E -= GetChargingEnergy();
00556 }
00557 return E;
00558 }
00562 xpPeakPanel* GetPanel(void) const
00563 { return m_peakpanel; }
00567 float GetPostPeakSlope(void) const
00568 { return PostPeakSlope;}
00572 float GetShirleyTailHeight(void) const
00573 { return ShirleyTailHeight;}
00577 float GetAngleRatio(void) const
00578 { return AngleRatio;}
00581 bool IsCarbon1sPeak(void)
00582 { return static_cast<bool> (xboolean::True == Carbon1sPeak); }
00588 bool IsPeakInRangeBE(const float BELow, const float BEHigh)
00589 { if( IsEnergyBE() )
00590 {
00591 return xpSpectrumBase::IsInRangeE(BELow, BEHigh, GetEnergy(true));
00592 }
00593 else if((IsEnergyKE()) && (IsXEnergyKnown()))
00594 {
00595 return xpSpectrumBase::IsInRangeE(BELow, BEHigh, ToBE( GetEnergy(true) ) );
00596 }
00597 else
00598 { return false;}
00599 }
00605 bool IsPeakInRangeKE(const float KELow, const float KEHigh)
00606 { if( IsEnergyKE())
00607 {
00608 return xpSpectrumBase::IsInRangeE(KELow, KEHigh, GetEnergy(true));
00609 }
00610 else if((IsEnergyBE()) && (IsXEnergyKnown()))
00611 {
00612 return xpSpectrumBase::IsInRangeE(KELow, KEHigh, ToKE( GetEnergy(true) ) );
00613 }
00614 else
00615 { return false;}
00616 }
00620 void SetCarbon1sPeak(const xboolean::xbool B)
00621 { Carbon1sPeak = B; }
00630 void SetEnergy(const float E, bool WithCharging = false)
00631 { if(WithCharging)
00632 ;
00633 else
00634 Energy = E;
00635 }
00639 void SetPanel(xpPeakPanel* PP)
00640 { m_peakpanel = PP; }
00645 void SetPostPeakSlope(const float PPS)
00646 { PostPeakSlope = PPS;}
00651 void SetShirleyTailHeight(const float STH)
00652 { ShirleyTailHeight = STH;}
00657 void SetAngleRatio(const float AR)
00658 { AngleRatio = AR;}
00659
00660 };
00661
00662 #endif //xps4xps_h