From: Ron F. <ro...@us...> - 2006-10-06 11:15:28
|
Update of /cvsroot/nsclspectcl/SpecTcl/Fits In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv3751/Fits Modified Files: CFit.cpp CFit.h CFitCreator.h CFitFactory.cpp CFitFactory.h CLinearFit.cpp CLinearFit.h CLinearFitCreator.cpp CLinearFitCreator.h Makefile.am Added Files: CSpectrumFit.cpp CSpectrumFit.h Log Message: - Got good compilation on CSpectrumFit.{cpp,h}... did a bit of - Needed to construct fits with names. - Did a bit more opportunistic shortening of the license header. Index: CLinearFitCreator.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/CLinearFitCreator.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CLinearFitCreator.cpp 6 Oct 2006 09:03:22 -0000 1.1 --- CLinearFitCreator.cpp 6 Oct 2006 11:15:25 -0000 1.2 *************** *** 101,107 **** */ CFit* ! CLinearFitCreator::operator()() { ! return new CLinearFit; } /*! --- 101,107 ---- */ CFit* ! CLinearFitCreator::operator()(STD(string) name, int id) { ! return new CLinearFit(name, id); } /*! Index: CFitCreator.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/CFitCreator.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CFitCreator.h 6 Oct 2006 09:03:22 -0000 1.1 --- CFitCreator.h 6 Oct 2006 11:15:25 -0000 1.2 *************** *** 56,60 **** public: ! virtual CFit* operator() () = 0 ; virtual STD(string) DescribeFit() = 0; }; --- 56,60 ---- public: ! virtual CFit* operator() (STD(string) name, int id=0) = 0 ; virtual STD(string) DescribeFit() = 0; }; Index: CFitFactory.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/CFitFactory.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CFitFactory.cpp 6 Oct 2006 09:51:36 -0000 1.2 --- CFitFactory.cpp 6 Oct 2006 11:15:25 -0000 1.3 *************** *** 98,102 **** */ CFit* ! CFitFactory::Create(string sFitType, string sFitName) { --- 98,102 ---- */ CFit* ! CFitFactory::Create(string sFitType, string sFitName, int id) { *************** *** 109,113 **** } CFitCreator* pCreator = i->second; ! CFit* pFit = (*pCreator)(); CHECK(pFit, "Null Fit created"); --- 109,113 ---- } CFitCreator* pCreator = i->second; ! CFit* pFit = (*pCreator)(sFitName, id); CHECK(pFit, "Null Fit created"); Index: CFitFactory.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/CFitFactory.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CFitFactory.h 6 Oct 2006 09:51:36 -0000 1.2 --- CFitFactory.h 6 Oct 2006 11:15:25 -0000 1.3 *************** *** 83,87 **** static void AddFitType (const STD(string) & rType, CFitCreator* pCreator) ; ! static CFit* Create (STD(string) sFitType, STD(string) sFitName) ; static FitCreatorIterator beginCreators(); --- 83,87 ---- static void AddFitType (const STD(string) & rType, CFitCreator* pCreator) ; ! static CFit* Create (STD(string) sFitType, STD(string) sFitName, int id = 0) ; static FitCreatorIterator beginCreators(); Index: CFit.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/CFit.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CFit.cpp 6 Oct 2006 09:51:36 -0000 1.2 --- CFit.cpp 6 Oct 2006 11:15:25 -0000 1.3 *************** *** 27,31 **** Create an object of type CFit */ ! CFit::CFit (): m_eState(Accepting) { --- 27,32 ---- Create an object of type CFit */ ! CFit::CFit (string name, int id) : ! CNamedItem(name, id), m_eState(Accepting) { *************** *** 45,49 **** The object that we will dupliate. */ ! CFit::CFit (const CFit& aCFit ) { CopyIn(aCFit); --- 46,51 ---- The object that we will dupliate. */ ! CFit::CFit (const CFit& aCFit ) : ! CNamedItem(aCFit) { CopyIn(aCFit); *************** *** 59,62 **** --- 61,65 ---- { if(this != &rhs) { + CNamedItem::operator=(rhs); CopyIn(rhs); // See why we bothered? } *************** *** 78,82 **** { return ((m_eState == rhs.m_eState) && ! (m_afpPoints == rhs.m_afpPoints)); } --- 81,86 ---- { return ((m_eState == rhs.m_eState) && ! (m_afpPoints == rhs.m_afpPoints) && ! CNamedItem::operator==(rhs)); } --- NEW FILE: CSpectrumFit.cpp --- /* This software is Copyright by the Board of Trustees of Michigan State University (c) Copyright 2005. You may use this software under the terms of the GNU public license (GPL). The terms of this license are described at: http://www.gnu.org/licenses/gpl.txt Author: Ron Fox NSCL Michigan State University East Lansing, MI 48824-1321 */ #include <config.h> #include "CSpectrumFit.h" #include "CFit.h" #include <SpecTcl.h> #include <Spectrum.h> #include <RangeError.h> #include <DictionaryException.h> #include <SpectrumFactoryException.h> #include <DesignByContract.h> #ifdef HAVE_STD_NAMESPACE using namespace std; #endif using namespace DesignByContract; /*! Construct a Spectrum fit out of whole cloth. \param spectrumName : std::string Name of the spectrum on which the fit is being defined. The spectrum must exist in SpecTcl and have dimensionality 1. This is the least restrictive condition and allows fits on e.g. Gamma or trendline spectra. \param myId : int Id of the fit. For use with SpecTcl/Xamine display bindings of the fitline, this should be a unique id in the same id namespace as gates. \param low, high : int The region of interest over which the fit is done. These values are channel numbers and must be within the raw channel numbers of the spectra. If you want to use axis units, it's up to some external guy to convert these and the fit parameters when done. \param fit : CFit& Reference to the fit to create. This fit carries the fit type (e.g. linear of gaussian) in its dynamic type. Exceptions can be thrown which will abort the construction: \throw CRangeError - low or high are outside the spectrum channel limits. \throw CDictionaryException - The spectrum name cannot be found. \throw CSpectrumFactoryException(keBadSpectrumType) - The spectrum passed in was found but does not have dimensionality 1. */ CSpectrumFit::CSpectrumFit(string spectrumName, int myId, int low, int high, CFit& fit) : CNamedItem(spectrumName, myId), m_low(low), m_high(high), m_ownFit(false), m_pFit(&fit) { // now invoke update to get the spectrum, perform the fit etc. update(); // That's the guy that really throws exceptions. } /*! Copy construction. This is just a matter of copying our base class, low/high and cloning our fit. This results in m_ownFit true. See the initial constructor for exceptions. */ CSpectrumFit::CSpectrumFit(const CSpectrumFit& rhs) : CNamedItem(rhs), m_low(rhs.m_low), m_high(rhs.m_high), m_ownFit(true), m_pFit(rhs.m_pFit->clone()) { update(); } /*! Assignment is similar to copy construction. See the initial constructor for exceptions that can be thrown. */ CSpectrumFit& CSpectrumFit::operator=(const CSpectrumFit& rhs) { if (&rhs != this) { if (m_ownFit) delete m_pFit; // Get rid of dynamically created fit. CNamedItem::operator=(rhs); m_low = rhs.m_low; m_high = rhs.m_high; m_ownFit = true; m_pFit = rhs.m_pFit->clone(); update(); } return *this; } /*! Comparison for equality is comparison of all our elements. */ int CSpectrumFit::operator==(const CSpectrumFit& rhs) const { return (CNamedItem::operator==(rhs) && (m_low == rhs.m_low) && (m_high == rhs.m_high) && ((*m_pFit) == *(rhs.m_pFit)));// don't care about dynamic-ness of fit. } /*! Comparison for inequality is the logical negation of equality above. */ int CSpectrumFit::operator!=(const CSpectrumFit& rhs) const { return !(*this == rhs); } ////////////////////////////////////////////////////////////////////////// //////////////// Functions that delegate to the fit object /////////////// ////////////////////////////////////////////////////////////////////////// /*! Start of iteration over points in the fit. */ CFit::PointIterator CSpectrumFit::begin() { return m_pFit->begin(); } /*! End of iteration over points in the fit. */ CFit::PointIterator CSpectrumFit::end() { return m_pFit->end(); } /*! Number of points in the fit: */ size_t CSpectrumFit::size() { return m_pFit->size(); } /*! Get the fit state.. note that this should really always be performed due to how and when we call update(). */ CFit::FitState CSpectrumFit::GetState() { return m_pFit->GetState(); } /*! Evaluate the fit at a point. */ double CSpectrumFit::operator()(double x) { return (*m_pFit)(x); } /*! Get the fit parameters. */ CFit::FitParameterList CSpectrumFit::getParameters() { return m_pFit->GetParameters(); } /*! Return the textual type of the fit e.g. 'gaussian'. */ string CSpectrumFit::fitType() { return m_pFit->Type(); } /*! Create a tcl script that consists of a proc named fitline that can be evaluated for channel numbers to produce the height of the fit over the ROI. */ string CSpectrumFit::makeTclFitScript() { return m_pFit->makeTclFitScript(); } /*! Return the name of the fit. This distinct from our name which can be gotten by getName().. this is the name of m_pFit. */ string CSpectrumFit::fitName() { return m_pFit->getName(); } /*! Clone ourselves. This is essentially copy construction. */ CSpectrumFit* CSpectrumFit::clone() { return new CSpectrumFit(*this); } /*! Update the fit: - Locate the spectrum - Validate the spectrum dimensionality. - validate low/high limits. - Clear the fit points. - Add points to the fit for each channel in the roi [m_low, m_high]. - Perform the fit. */ void CSpectrumFit::update() { CSpectrum* pSpectrum = findSpectrum(); if (!pSpectrum) { throw CDictionaryException(static_cast<Int_t>(CDictionaryException::knNoSuchKey), "Locating spectrum in CSpectrumFit::update()", getName()); } // Ensure the spectrum has dimensionality 1: if (pSpectrum->Dimensionality() != 1) { // not a 1d. throw CSpectrumFactoryException(pSpectrum->StorageType(), pSpectrum->getSpectrumType(), getName(), CSpectrumFactoryException::keBadSpectrumType, "CSpectrumFit::update() - fits can only be done on spectra with dimensionality 1"); } Size_t channelCount = pSpectrum->Dimension(0); if ((m_low < 0) || (m_low >= channelCount)) { throw CRangeError(0, channelCount, m_low, "CSpectrumFit::update - fit ROI low limit out of range"); } if ((m_high < 0) || (m_high >= channelCount)) { throw CRangeError(0, channelCount, m_low, "CSpectrumFit::update - fit ROI high limit is out of range"); } // Now compute the new fit: m_pFit->ClearPoints(); for(UInt_t i = m_low; i<= m_high; i++) { CFit::Point pt; pt.x = (double)i; pt.y = (double)((*pSpectrum)[&i]); m_pFit->AddPoint(pt); } m_pFit->Perform(); } /////////////////////////////////////////////////////////////////////////// ///////////////////////// Private utilities /////////////////////////////// /////////////////////////////////////////////////////////////////////////// /* Locate our spectrum.. returns a pointer to it or NULL if not found. */ CSpectrum* CSpectrumFit::findSpectrum() { SpecTcl* papi = SpecTcl::getInstance(); return papi->FindSpectrum(getName()); } Index: CLinearFit.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/CLinearFit.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CLinearFit.h 6 Oct 2006 09:51:36 -0000 1.2 --- CLinearFit.h 6 Oct 2006 11:15:25 -0000 1.3 *************** *** 48,52 **** // implement assignment/copy construction. // safely. ! CLinearFit (); //!< Constructor. virtual ~ CLinearFit ( ); //!< Destructor. CLinearFit (const CLinearFit& rSource ); //!< Copy construction. --- 48,52 ---- // implement assignment/copy construction. // safely. ! CLinearFit (STD(string) name, int id=0); //!< Constructor. virtual ~ CLinearFit ( ); //!< Destructor. CLinearFit (const CLinearFit& rSource ); //!< Copy construction. --- NEW FILE: CSpectrumFit.h --- /* This software is Copyright by the Board of Trustees of Michigan State University (c) Copyright 2005. You may use this software under the terms of the GNU public license (GPL). The terms of this license are described at: http://www.gnu.org/licenses/gpl.txt Author: Ron Fox NSCL Michigan State University East Lansing, MI 48824-1321 */ #ifndef __CSPECTRUMFIT_H #define __CSpECTRUMFIT_H #ifndef __NAMEDITEM_H #include <NamedItem.h> // base class #endif #ifndef __CFIT_H #include "CFit.h" // Need this for CFitParameterList. #endif #ifndef __STL_STRING #include <string> #ifndef __STL_STRING #define __STL_STRING #endif #endif // Forward class definitions: class CSpectrum; /*! This class defines a fit on a region of interest of a spectrum The spectrum must be a 1-d spectrum. The idea is that you can create one of these on a spectrum, it will take care of loading the spectrum channels/counts into the fit and perform the fit. The fit can be updated (which means clearing and reloading the points). - Item name is the spectrum name on which this is defined. - Id will be a unique id in the namespace of gate ids. if used in SpecTcl. */ class CSpectrumFit : public CNamedItem { // Member data: private: int m_low; // Channel coordinates of left side of ROI. int m_high; // Channel coordinates of right side of ROI. bool m_ownFit; // true if we dynamically created the fit. CFit* m_pFit; // Pointer to the fit object. // Canonicals.. note that since fits can clone, we can support copy construction. public: CSpectrumFit(STD(string) spectrumName, int myId, int low, int high, CFit& fit); CSpectrumFit(const CSpectrumFit& rhs); virtual ~CSpectrumFit(); CSpectrumFit& operator=(const CSpectrumFit& rhs); int operator==(const CSpectrumFit& rhs) const; int operator!=(const CSpectrumFit& rhs) const; // Delegations to the fit: CFit::PointIterator begin(); CFit::PointIterator end(); size_t size(); CFit::FitState GetState(); // although this should always be CFit::Performed. double operator()(double x); CFit::FitParameterList getParameters(); STD(string) fitType(); STD(string) makeTclFitScript(); STD(string) fitName(); // Functions that are implemented (not as delegations to m_pFit) in this // class: CSpectrumFit* clone(); // Clone self. void update(); // Private utilities. private: CSpectrum* findSpectrum(); }; #endif Index: CLinearFit.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/CLinearFit.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CLinearFit.cpp 6 Oct 2006 09:51:36 -0000 1.2 --- CLinearFit.cpp 6 Oct 2006 11:15:25 -0000 1.3 *************** *** 37,42 **** Create an object of type CLinearFit */ ! CLinearFit::CLinearFit () ! : m_fSlope(0), m_fOffset(0), m_fChiSquare(0) --- 37,44 ---- Create an object of type CLinearFit */ ! CLinearFit::CLinearFit (STD(string) name, int id) ! : ! CFit(name, id), ! m_fSlope(0), m_fOffset(0), m_fChiSquare(0) Index: CFit.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/CFit.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CFit.h 6 Oct 2006 09:51:36 -0000 1.2 --- CFit.h 6 Oct 2006 11:15:25 -0000 1.3 *************** *** 89,93 **** // implement assignment/copy construction. // safely. ! CFit (); //!< Constructor. virtual ~ CFit ( ); //!< Destructor. CFit (const CFit& rSource ); //!< Copy construction. --- 89,93 ---- // implement assignment/copy construction. // safely. ! CFit (STD(string) name, int id = 0); //!< Constructor. virtual ~ CFit ( ); //!< Destructor. CFit (const CFit& rSource ); //!< Copy construction. Index: Makefile.am =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile.am 6 Oct 2006 09:51:36 -0000 1.1 --- Makefile.am 6 Oct 2006 11:15:25 -0000 1.2 *************** *** 1,5 **** INCLUDES = -I@top_srcdir@/Utility \ ! -I@top_srcdir@/Xamine lib_LTLIBRARIES=libFits.la --- 1,15 ---- INCLUDES = -I@top_srcdir@/Utility \ ! -I@top_srcdir@/Xamine \ ! -I@top_srcdir@/Exception \ ! -I@top_srcdir@/Sorter \ ! -I@top_srcdir@/SpecTcl \ ! -I@top_srcdir@/Events \ ! -I@top_srcdir@/Display \ ! -I@top_srcdir@/Gates \ ! -I@top_srcdir@/Filter \ ! -I@top_srcdir@/TCL \ ! $(TCL_FLAGS) ! lib_LTLIBRARIES=libFits.la *************** *** 7,15 **** -Wl,"-rpath-link=$(libdir)" ! libFits_la_SOURCES = CFit.cpp \ ! CFitCreator.cpp \ ! CFitFactory.cpp \ ! CLinearFit.cpp \ ! CLinearFitCreator.cpp include_HEADERS = CFit.h \ --- 17,26 ---- -Wl,"-rpath-link=$(libdir)" ! libFits_la_SOURCES = CFit.cpp \ ! CFitCreator.cpp \ ! CFitFactory.cpp \ ! CLinearFit.cpp \ ! CLinearFitCreator.cpp \ ! CSpectrumFit.cpp include_HEADERS = CFit.h \ *************** *** 17,20 **** CFitFactory.h \ CLinearFit.h \ ! CLinearFitCreator.h --- 28,32 ---- CFitFactory.h \ CLinearFit.h \ ! CLinearFitCreator.h \ ! CSpectrumFit.h Index: CLinearFitCreator.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/Fits/CLinearFitCreator.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CLinearFitCreator.h 6 Oct 2006 09:03:22 -0000 1.1 --- CLinearFitCreator.h 6 Oct 2006 11:15:25 -0000 1.2 *************** *** 52,56 **** public: ! virtual CFit* operator() () ; virtual STD(string) DescribeFit(); --- 52,56 ---- public: ! virtual CFit* operator() (STD(string) name, int id=0) ; virtual STD(string) DescribeFit(); |