/*************************************************************************** PInstrumentDef.h Author: Andreas Suter e-mail: andreas.suter@psi.ch ***************************************************************************/ /*************************************************************************** * Copyright (C) 2007-2025 by Andreas Suter * * andreas.suter@psi.ch * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef _PINSTRUMENTDEF_H_ #define _PINSTRUMENTDEF_H_ #include #include /** * @brief The PDetector class represents a logical muon detector. * * This class encapsulates the properties of a detector configuration including * its name, relative geometric phase, forward/backward detector indices, and * alpha parameter (for asymmetry fits). It is used in the instrument definition * to specify detector groupings for different measurement setups. */ class PDetector { public: /** * @brief Constructor. */ PDetector() {} /** * @brief Destructor. */ ~PDetector() {} /** * @brief Sets the detector name. * @param str Detector name (e.g., "Forward", "Backward", "Left"). */ void setName(QString str) { fName = str; } /** * @brief Sets the relative geometric phase. * @param phase Phase angle in degrees relative to a reference detector. */ void setRelGeomPhase(double phase) { fRelGeomPhase = phase; } /** * @brief Sets the forward detector indices. * @param num Vector of physical detector numbers forming the forward group. */ void setForwards(QVector num) { fForward = num; } /** * @brief Sets the backward detector indices. * @param num Vector of physical detector numbers forming the backward group. */ void setBackwards(QVector num) { fBackward = num; } /** * @brief Sets the alpha correction factor. * @param alpha Alpha value for asymmetry correction. */ void setAlpha(double alpha) { fAlpha = alpha; } /** * @brief Returns the detector name. * @return Detector name. */ QString getName() { return fName; } /** * @brief Returns the relative geometric phase. * @return Phase angle in degrees. */ double getRelGeomPhase() { return fRelGeomPhase; } /** * @brief Returns the forward detector indices. * @return Vector of forward detector numbers. */ QVector getForwards() { return fForward; } /** * @brief Returns the backward detector indices. * @return Vector of backward detector numbers. */ QVector getBackwards() { return fBackward; } /** * @brief Returns the alpha correction factor. * @return Alpha value. */ double getAlpha() { return fAlpha; } private: QString fName; ///< detector name QVector fForward; ///< forward detector indices QVector fBackward; ///< backward detector indices double fAlpha; ///< alpha correction factor double fRelGeomPhase; ///< relative geometric phase in degrees }; /** * @brief The PSetup class represents a measurement setup configuration. * * This class defines a specific detector setup for a measurement type (ZF, TF, or LF). * It includes information about the number of detectors, good bin ranges, background * ranges, and logical detector groupings for both single-histogram and asymmetry fits. */ class PSetup { public: /** * @brief Constructor. Initializes all values to -1/empty. */ PSetup(); /** * @brief Destructor. */ ~PSetup() {} /** * @brief Sets the setup name. * @param str Setup name (e.g., "Default", "Veto"). */ void setName(QString str) { fName = str; } /** * @brief Sets the total number of physical detectors. * @param no Number of detectors. */ void setNoOfDetectors(int no) { fNoOfDetectors = no; } /** * @brief Sets the first good bin offset from t0. * @param fgbOffset Offset in bins from t0 to first good bin. */ void setFgbOffset(int fgbOffset) { fFgbOffset = fgbOffset; } /** * @brief Sets the last good bin. * @param lgb Last good bin number. */ void setLgb(int lgb) { fLgb = lgb; } /** * @brief Sets the background range for asymmetry fits. * @param start Start bin for background estimation. * @param end End bin for background estimation. */ void setBkgRange(int start, int end) { fBkgStartBin = start; fBkgEndBin = end; } /** * @brief Adds a logical detector for single-histogram fits. * @param detector Detector configuration to add. */ void addDetector(PDetector detector) { fLogicDetectors.push_back(detector); } /** * @brief Adds a logical detector for asymmetry fits. * @param detector Detector configuration to add (with forward/backward groups). */ void addAsymDetector(PDetector detector) { fLogicAsymDetectors.push_back(detector); } /** * @brief Returns the setup name. * @return Setup name. */ QString getName() { return fName; } /** * @brief Returns the total number of physical detectors. * @return Number of detectors. */ int getNoOfDetectors() { return fNoOfDetectors; } /** * @brief Returns the number of logical detectors for single-histogram fits. * @return Number of logical detectors. */ int getNoOfLogicalDetectors() { return fLogicDetectors.size(); } /** * @brief Returns the number of logical detectors for asymmetry fits. * @return Number of asymmetry detectors. */ int getNoOfLogicalAsymDetectors() { return fLogicAsymDetectors.size(); } /** * @brief Returns the first good bin offset. * @return Offset in bins from t0. */ int getFgbOffset() { return fFgbOffset; } /** * @brief Returns the last good bin. * @return Last good bin number. */ int getLgb() { return fLgb; } /** * @brief Returns the background range start bin. * @return Background start bin. */ int getBkgStartBin() { return fBkgStartBin; } /** * @brief Returns the background range end bin. * @return Background end bin. */ int getBkgEndBin() { return fBkgEndBin; } /** * @brief Returns a pointer to a single-histogram logical detector. * @param idx Index of the detector. * @return Pointer to PDetector, or nullptr if index out of range. */ PDetector* getDetector(int idx); /** * @brief Returns a pointer to an asymmetry logical detector. * @param idx Index of the detector. * @return Pointer to PDetector, or nullptr if index out of range. */ PDetector* getAsymDetector(int idx); private: QString fName; ///< setup name int fNoOfDetectors; ///< total number of physical detectors int fFgbOffset; ///< first good bin offset from t0 int fLgb; ///< last good bin int fBkgStartBin; ///< background range start bin int fBkgEndBin; ///< background range end bin QVector fLogicDetectors; ///< logical detectors for single-histogram fits QVector fLogicAsymDetectors; ///< logical detectors for asymmetry fits }; /** * @brief The PInstrument class represents a muon spectrometer instrument. * * This class contains all information about a specific muon instrument including * its name, beamline, run name template, data file format, and measurement setups * for ZF (zero field), TF (transverse field), and LF (longitudinal field) configurations. */ class PInstrument { public: /** * @brief Constructor. Initializes all strings to empty. */ PInstrument(); /** * @brief Destructor. */ ~PInstrument() {} /** * @brief Sets the run name template for data file naming. * @param str Template string (e.g., "deltat_tdc_gps_[yyyy]_[nnnn].bin"). */ void setRunNameTemplate(QString str) { fRunNameTemplate = str; } /** * @brief Sets the beamline name. * @param str Beamline identifier (e.g., "piM3.2"). */ void setBeamline(QString str) { fBeamline = str; } /** * @brief Sets the data file format. * @param str File format (e.g., "PsiMdu", "NeXus", "WKM"). */ void setDataFileFormat(QString str) { fDataFileFormat = str; } /** * @brief Sets the institute name. * @param str Institute name (e.g., "PSI"). */ void setInstitue(QString str) { fInstitue = str; } /** * @brief Sets the instrument name. * @param str Instrument name (e.g., "GPS", "HAL9500"). */ void setName(QString str) { fName = str; } /** * @brief Adds a zero-field (ZF) setup configuration. * @param zf Setup object to add. */ void addSetupZF(PSetup zf) { fZF.push_back(zf); } /** * @brief Adds a transverse-field (TF) setup configuration. * @param tf Setup object to add. */ void addSetupTF(PSetup tf) { fTF.push_back(tf); } /** * @brief Adds a longitudinal-field (LF) setup configuration. * @param lf Setup object to add. */ void addSetupLF(PSetup lf) { fLF.push_back(lf); } /** * @brief Returns the run name template. * @return Run name template string. */ QString getRunNameTemplate() { return fRunNameTemplate; } /** * @brief Returns the beamline name. * @return Beamline name. */ QString getBeamline() { return fBeamline; } /** * @brief Returns the data file format. * @return Data file format string. */ QString getDataFileFormat() { return fDataFileFormat; } /** * @brief Returns the institute name. * @return Institute name. */ QString getInstitute() { return fInstitue; } /** * @brief Returns the instrument name. * @return Instrument name. */ QString getName() { return fName; } /** * @brief Returns all ZF setups. * @return Vector of ZF setup configurations. */ QVector getZFSetups() { return fZF; } /** * @brief Returns all TF setups. * @return Vector of TF setup configurations. */ QVector getTFSetups() { return fTF; } /** * @brief Returns all LF setups. * @return Vector of LF setup configurations. */ QVector getLFSetups() { return fLF; } /** * @brief Returns a ZF setup by name. * @param name Setup name (default: first available). * @return Pointer to PSetup, or nullptr if not found. */ PSetup* getZFSetup(QString name=""); /** * @brief Returns a TF setup by name. * @param name Setup name (default: first available). * @return Pointer to PSetup, or nullptr if not found. */ PSetup* getTFSetup(QString name=""); /** * @brief Returns a LF setup by name. * @param name Setup name (default: first available). * @return Pointer to PSetup, or nullptr if not found. */ PSetup* getLFSetup(QString name=""); private: QString fRunNameTemplate; ///< template for run file names QString fBeamline; ///< beamline identifier QString fDataFileFormat; ///< data file format QString fInstitue; ///< institute name QString fName; ///< instrument name QVector fZF; ///< zero-field setups QVector fTF; ///< transverse-field setups QVector fLF; ///< longitudinal-field setups }; /** * @brief The PInstitute class represents a muon research facility/institute. * * This class groups multiple muon instruments belonging to the same research * facility (e.g., PSI, TRIUMF, ISIS, J-PARC). */ class PInstitute { public: /** * @brief Constructor. Initializes the name to empty. */ PInstitute(); /** * @brief Destructor. */ ~PInstitute() {} /** * @brief Sets the institute name. * @param str Institute name (e.g., "PSI", "TRIUMF"). */ void setName(QString str) { fName = str; } /** * @brief Adds an instrument to this institute. * @param instrument Instrument object to add. */ void addInstrument(PInstrument instrument) { fInstrument.push_back(instrument); } /** * @brief Returns the institute name. * @return Institute name. */ QString getName() { return fName; } /** * @brief Returns all instruments belonging to this institute. * @return Vector of PInstrument objects. */ QVector getInstruments() { return fInstrument; } /** * @brief Returns an instrument by name. * @param name Instrument name. * @return Pointer to PInstrument, or nullptr if not found. */ PInstrument *getInstrument(QString name); private: QString fName; ///< institute name QVector fInstrument; ///< list of instruments at this institute }; #endif // _PINSTRUMENTDEF_H_