SpectraPac 2.0(r200)
Evaluates PAC Measurements

PacCoincidenceSpectrum.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008-2010 by Matthias Nagl                              *
00003  *   mnagl@uni-goettingen.de                                               *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef PACCOINCIDENCEPARAMETERS_H
00022 #define PACCOINCIDENCEPARAMETERS_H
00023 
00024 #include <QObject>
00025 #include <QVector>
00026 #include <QPointer>
00027 #include <QPair>
00028 #include <QMutex>
00029 #include <qwt_double_rect.h>
00030 #include "PacParameterState.h"
00031 #include <Minuit2/FunctionMinimum.h>
00032 //#include "PacCoincidenceControlWidget.h"
00033 #include "PacCoincidenceParameterDialog.h"
00034 #include "pacCoincidenceDefinitions.h"
00035 
00036 class QPushButton;
00037 class QRadioButton;
00038 class QDoubleSpinBox;
00039 class QDomElement;
00040 class QwtPlotMarker;
00041 class QwtPlotCurve;
00042 class PacPlot;
00043 class PacCoincidenceContainer;
00044 class PacAbstractFitFunction;
00045 class PacBasicMeasurementInfo;
00046 
00052 class PacCoincidenceSpectrum : public QObject
00053 {
00054   Q_OBJECT
00055 public:
00056   PacCoincidenceSpectrum(
00057       PacCoincidenceContainer *container,
00058       const PacBasicMeasurementInfo *basicinfo,
00059       QPair<quint8,quint8> &detectoridxs
00060   );
00061   ~PacCoincidenceSpectrum();
00062 
00063   QWidget * plotWidget();
00064   QWidget * controlWidget();
00065   QWidget * parameterDialogWidget();
00066 
00067   void setSpectrum(const QVector<quint64> &spectY, bool addendum);
00068 
00070 
00071   QVector<double> spectrumX() const;
00072   QVector<quint64> spectrumY() const;
00073   QVector<double> doubleSpectrumY() const;
00074   quint64 maxY() const;
00075   quint32 maxIdx() const;
00076   double angle() const;
00077   quint8 startNodeId() const;
00078   quint8 stopNodeId() const;
00079   qreal timeResolutionFWHM() const;
00081 
00083 
00084   bool ignoreThisSpectrum() const;
00085   Pac::ParameterDeterminationMethod determinationMethod() const;
00086   qreal t0FitCutterPosition() const;
00087   qreal backgroundFitStartPosition() const;
00088   qreal timeOffset() const;
00089   qreal backgroundLevel() const;
00091 
00093 
00094   void receiveFitResult(const ROOT::Minuit2::ParametricFunction *fitfunc, const ROOT::Minuit2::FunctionMinimum &result);
00096 
00100   void updateButtonBackground();
00106   void appendToDomNode(QDomElement &node) const;
00112   void initializeFromDomNode(const QDomElement &node);
00113 
00114 public slots:
00116 
00117   void setIgnoreThisSpectrum(bool ignore);
00118   void setDeterminationMethod(Pac::ParameterDeterminationMethod m);
00119   void setT0FitCutterPosition(double percent);
00120   void setBackgroundFitStartPosition(double starttime, bool refit=true);
00121   void setTimeOffset(double timeoffset);
00122   void setBackgroundLevel(double counts);
00123   void t0ParametersUpdated();
00124   void backgroundParametersUpdated();
00126 
00128 
00129   void autoEstimateT0FitParameters();
00130   void autoEstimateBgFitParameters();
00132 
00134 
00135   void restartFitting();
00136   void sendT0FunctionToFitThread(bool force = false);
00137   void sendBackgroundFunctionToFitThread(bool force = false);
00139 
00141 
00142   void setButton(QPushButton *button);
00144 
00145 private slots:
00151   void loadReceivedT0FitResults();
00157   void loadReceivedBgFitResults();
00158   void selectMarker(QwtDoublePoint p);
00159   void applyNewMarkerPosition(QwtDoublePoint p);
00160   void methodChanged(bool usefit);
00161   void updateLockButtons();
00162   void setMethodLock(bool locked);
00163   void setT0Lock(bool locked);
00164   void setBgLock(bool locked);
00165 
00166 signals:
00167   void timeOffsetChanged(double newtimeoffset);
00168   void backgroundLevelChanged(double newcounts);
00169   void updateRTSpectrum();
00170 
00171 private:
00172   void setT0FitCurve();
00173   void setBackgroundFitCurve();
00174   void plotSpectrum();
00175   void lockT0Widgets();
00176   void lockBackgroundWidgets();
00177   qreal autoEstimateBackground() const;
00178   qreal autoEstimateHalfLife() const;
00179   qreal autoEstimateExponentialAmplitude() const;
00180 
00182 
00183   PacCoincidenceContainer *container;
00184   const PacBasicMeasurementInfo *basicinfo;
00185   QPointer<QPushButton> button; 
00186 
00187 
00189 
00190   QPair<quint8,quint8> detectoridxs; 
00191 
00192 
00194 
00195   QVector<quint64> spectY;
00197 
00199 
00200   Pac::ParameterDeterminationMethod method;
00201   qreal t0fitcutterposition; 
00202   qreal bgfitcutterposition; 
00203   qreal toffset; 
00204   qreal bglevel;
00205   bool ignorethisspectrum; 
00206 
00207   PacParameterState t0fitparams;
00208   bool t0successfullyfitted;
00209   PacParameterState bgfitparams;
00210   bool bgsuccessfullyfitted;
00212 
00214 
00215   QPointer<QWidget> plotwidget;
00216   QPointer<QWidget> controlwidget;
00217   QPointer<PacCoincidenceParameterDialog> parameterdialog;
00218 
00219   PacPlot *plot;
00220   QwtPlotMarker *convfitcutter, *expfitcutter, *backgroundlevelmarker, *toffsetmarker;
00221   QwtPlotCurve *coincidencespectrum, *convfitcurve, *expfitcurve;
00222 
00223   QRadioButton *usefitmethod, *manuallysetparams;
00224   QDoubleSpinBox *tospinbox, *bgspinbox, *t0fitcutterpos, *bgfitstartpos;
00225   QToolButton *methodlock, *t0lock, *bglock;
00226   QGroupBox *methodgroupbox;
00228 
00230 
00231   mutable qreal detectorangle;
00232   mutable QVector<double> doublespecty;
00233   mutable quint64 max;
00234   mutable qint32 maxidx;
00235   mutable qreal bgautoestimate;
00236   mutable qreal hlautoestimate;
00237   mutable qreal expamplitudeautoestimate;
00238   const PacAbstractFitFunction *t0fitfunction;
00239   const PacAbstractFitFunction *bgfitfunction;
00240   ROOT::Minuit2::FunctionMinimum *receivedt0minimum, *receivedbgminimum;
00241   QTimer *processt0fit, *processbgfit, *startdeferredt0fit, *startdeferredbgfit;
00242   bool restartt0fitasap, restartbgfitasap;
00243   double commitbgfitstartposchangeasap;
00244   QMutex newparammutex;
00245   bool t0locked, bglocked; 
00246   enum CoincidenceMarkerSelection {
00247     Background,
00248     Offset,
00249     ConvolvedCutter,
00250     ExponentialCutter
00251   } selectedcoincidencemarker;
00253 };
00254 
00255 #endif // PACCOINCIDENCEPARAMETERS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines