All checks were successful
Build and Deploy Documentation / build-and-deploy (push) Successful in 26s
319 lines
14 KiB
C++
319 lines
14 KiB
C++
/***************************************************************************
|
|
|
|
PMusrT0.h
|
|
|
|
Author: Andreas Suter
|
|
e-mail: andreas.suter@psi.ch
|
|
|
|
***************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* Copyright (C) 2007-2026 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 _PMUSRT0_H_
|
|
#define _PMUSRT0_H_
|
|
|
|
#include <memory>
|
|
|
|
#include <TObject.h>
|
|
#include <TQObject.h>
|
|
#include <TStyle.h>
|
|
#include <TRootCanvas.h>
|
|
#include <TGMenu.h>
|
|
#include <TCanvas.h>
|
|
#include <TH1.h>
|
|
#include <TLine.h>
|
|
#include <TLatex.h>
|
|
#include <TTimer.h>
|
|
|
|
#include "PMusr.h"
|
|
#ifndef __MAKECLING__
|
|
#include "PMsrHandler.h"
|
|
#endif // __MAKECLING__
|
|
|
|
//--------------------------------------------------------------------------
|
|
// Detector tags
|
|
//--------------------------------------------------------------------------
|
|
#define PMUSRT0_FORWARD 0 ///< Forward detector tag
|
|
#define PMUSRT0_BACKWARD 1 ///< Backward detector tag
|
|
|
|
//--------------------------------------------------------------------------
|
|
// Command/mode tags
|
|
//--------------------------------------------------------------------------
|
|
#define PMUSRT0_GET_T0 0 ///< Mode: Determine t0 only
|
|
#define PMUSRT0_GET_DATA_AND_BKG_RANGE 1 ///< Mode: Determine data and background ranges only
|
|
#define PMUSRT0_GET_T0_DATA_AND_BKG_RANGE 2 ///< Mode: Determine t0, data range, and background range
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
/**
|
|
* \brief Data container for musrt0 raw run data and histogram information.
|
|
*
|
|
* PMusrT0Data manages the raw histogram data needed for interactive t0 and
|
|
* range determination in the musrt0 tool. It stores:
|
|
* - Raw run data (main run and optional addruns)
|
|
* - Histogram numbers and detector grouping
|
|
* - Current and saved t0 bin values
|
|
* - Data and background range information
|
|
*
|
|
* The class supports both single histogram and asymmetry fit modes, and
|
|
* handles complex run configurations including addrun combinations.
|
|
*
|
|
* \see PMusrT0 for the GUI interface using this data
|
|
* \see PRawRunData for the underlying raw data structure
|
|
*/
|
|
class PMusrT0Data {
|
|
public:
|
|
/// Default constructor
|
|
PMusrT0Data();
|
|
/// Destructor
|
|
virtual ~PMusrT0Data();
|
|
|
|
/// Initializes data structures (currently empty implementation)
|
|
virtual void InitData();
|
|
|
|
/// Returns true if single histogram fit mode
|
|
virtual Bool_t IsSingleHisto() { return fSingleHisto; }
|
|
/// Returns number of raw run data entries (1 + number of addruns)
|
|
virtual UInt_t GetRawRunDataSize() { return fRawRunData.size(); }
|
|
/// Returns raw run data for given index (0=main run, >0=addruns)
|
|
virtual PRawRunData* GetRawRunData(Int_t idx);
|
|
/// Returns MSR file run number
|
|
virtual Int_t GetRunNo() { return fRunNo; }
|
|
/// Returns current addrun index
|
|
virtual Int_t GetAddRunIdx() { return fAddRunIdx; }
|
|
/// Returns current histogram number index
|
|
virtual Int_t GetHistoNoIdx() { return fHistoNoIdx; }
|
|
/// Returns number of histogram numbers
|
|
virtual UInt_t GetHistoNoSize() { return fHistoNo.size(); }
|
|
/// Returns histogram number at given index
|
|
virtual Int_t GetHistoNo(UInt_t idx);
|
|
/// Returns detector tag (PMUSRT0_FORWARD or PMUSRT0_BACKWARD)
|
|
virtual Int_t GetDetectorTag() { return fDetectorTag; }
|
|
/// Returns command tag (mode for t0/range determination)
|
|
virtual Int_t GetCmdTag() { return fCmdTag; }
|
|
/// Returns number of t0 bins for main run
|
|
virtual UInt_t GetT0BinSize() { return fT0.size(); }
|
|
/// Returns t0 bin value at given index
|
|
virtual Int_t GetT0Bin(UInt_t idx);
|
|
/// Returns number of addrun entries with t0 values
|
|
virtual UInt_t GetAddT0Entries() { return fAddT0.size(); }
|
|
/// Returns number of t0 bins for given addrun
|
|
virtual UInt_t GetAddT0BinSize(UInt_t idx);
|
|
/// Returns t0 bin for specific addrun and histogram
|
|
virtual Int_t GetAddT0Bin(UInt_t addRunIdx, UInt_t idx);
|
|
/// Returns t0 bin found from data file
|
|
virtual Int_t GetT0BinData() { return fT0Data; }
|
|
|
|
/// Sets single histogram fit mode flag
|
|
virtual void SetSingleHisto(const Bool_t flag) { fSingleHisto = flag; }
|
|
/// Sets vector of raw run data pointers
|
|
virtual void SetRawRunData(const std::vector<PRawRunData*> rawRunData) { fRawRunData = rawRunData; }
|
|
/// Sets MSR file run number
|
|
virtual void SetRunNo(const UInt_t runNo) { fRunNo = runNo; }
|
|
/// Sets current addrun index
|
|
virtual void SetAddRunIdx(const UInt_t addRunIdx) { fAddRunIdx = addRunIdx; }
|
|
/// Sets current histogram number index
|
|
virtual void SetHistoNoIdx(const UInt_t histoNoIdx) { fHistoNoIdx = histoNoIdx; }
|
|
/// Sets vector of histogram numbers
|
|
virtual void SetHistoNo(const PIntVector histoNo) { fHistoNo = histoNo; }
|
|
/// Sets detector tag (forward/backward)
|
|
virtual void SetDetectorTag(const UInt_t detectorTag) { fDetectorTag = detectorTag; }
|
|
/// Sets command/mode tag
|
|
virtual void SetCmdTag(const UInt_t cmdTag) { fCmdTag = cmdTag; }
|
|
/// Sets t0 bin value at given index
|
|
virtual void SetT0Bin(UInt_t val, UInt_t idx);
|
|
/// Sets t0 bin value for specific addrun and index
|
|
virtual void SetAddT0Bin(UInt_t val, UInt_t addRunIdx, UInt_t idx);
|
|
/// Sets t0 bin value found from data file
|
|
virtual void SetT0BinData(UInt_t val) { fT0Data = val; }
|
|
|
|
private:
|
|
Bool_t fSingleHisto; ///< True for single histogram fit, false for asymmetry fit
|
|
std::vector<PRawRunData*> fRawRunData; ///< Raw data: index 0 = main run, index >0 = addruns
|
|
Int_t fRunNo; ///< MSR file run block number
|
|
Int_t fAddRunIdx; ///< Current addrun index being processed
|
|
Int_t fHistoNoIdx; ///< Current histogram number index
|
|
PIntVector fHistoNo; ///< Histogram numbers (with Red/Green offset applied)
|
|
Int_t fDetectorTag; ///< Detector: PMUSRT0_FORWARD (0) or PMUSRT0_BACKWARD (1)
|
|
Int_t fCmdTag; ///< Mode: 0=t0 only, 1=ranges only, 2=both t0 and ranges
|
|
PIntVector fT0; ///< t0 bin values for main run histograms
|
|
std::vector<PIntVector> fAddT0; ///< t0 bin values for addrun histograms
|
|
Int_t fT0Data; ///< t0 bin found in current data file
|
|
};
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
/**
|
|
* \brief Interactive GUI for determining t0 and data/background ranges in μSR experiments.
|
|
*
|
|
* PMusrT0 provides a ROOT-based graphical interface for interactively determining:
|
|
* - t0 values (time zero calibration for detector histograms)
|
|
* - Data ranges (first good bin, last good bin)
|
|
* - Background ranges (background start/end bins)
|
|
*
|
|
* The tool displays raw histogram data and allows users to set these parameters
|
|
* through keyboard interactions. It supports:
|
|
* - Single histogram and asymmetry fit modes
|
|
* - Multiple histograms and addrun configurations
|
|
* - Visual markers for t0, data ranges, and background ranges
|
|
* - Zoom capabilities for precise bin selection
|
|
*
|
|
* \par Keyboard Controls:
|
|
* - 't': Set t0 at cursor position
|
|
* - 'e': Set estimated t0
|
|
* - 'f': Set first good data bin
|
|
* - 'l': Set last good data bin
|
|
* - 'b': Set background start bin
|
|
* - 'n': Set background end bin
|
|
* - 'u': Unzoom to full histogram
|
|
* - 'z': Zoom to t0 region
|
|
* - 'd': Toggle data file t0 display
|
|
* - 'q': Quit/advance to next histogram
|
|
*
|
|
* \note The preprocessor tag __MAKECLING__ is used to hide away from rootcling
|
|
* the overly complex spirit header files.
|
|
*
|
|
* \see PMusrT0Data for the underlying data container
|
|
* \see PMsrHandler for MSR file management
|
|
*/
|
|
class PMusrT0 : public TObject, public TQObject
|
|
{
|
|
public:
|
|
/// Default constructor (creates invalid instance)
|
|
PMusrT0();
|
|
/**
|
|
* \brief Main constructor that initializes the interactive GUI.
|
|
* \param data Reference to PMusrT0Data containing raw run data and configuration
|
|
*/
|
|
PMusrT0(PMusrT0Data &data);
|
|
|
|
/**
|
|
* \brief Returns validity status of the PMusrT0 instance.
|
|
* \return True if raw data sets are available and GUI is functional, false otherwise
|
|
*/
|
|
virtual Bool_t IsValid() { return fValid; }
|
|
|
|
/**
|
|
* \brief Emits signal indicating completion of t0/range determination.
|
|
* \param status Exit status: 0=local quit (single canvas), 1=quit entire application
|
|
*/
|
|
virtual void Done(Int_t status=0); // *SIGNAL*
|
|
|
|
/**
|
|
* \brief Handles keyboard input for interactive t0 and range selection.
|
|
* \param event Keyboard event code
|
|
* \param x Mouse x-coordinate in pixels
|
|
* \param y Mouse y-coordinate in pixels
|
|
* \param selected Pointer to selected ROOT object (unused)
|
|
*
|
|
* Processes keyboard commands for setting t0, data ranges, background ranges,
|
|
* and zoom controls. See class documentation for complete key bindings.
|
|
*/
|
|
virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected); // SLOT
|
|
|
|
/// Quit slot that emits Done signal to close the current canvas
|
|
virtual void Quit(); // SLOT
|
|
|
|
/**
|
|
* \brief Sets automatic timeout for the interactive session.
|
|
* \param timeout Timeout in milliseconds (≤0 disables timeout)
|
|
*
|
|
* If timeout expires without user interaction, the Done signal is automatically emitted.
|
|
*/
|
|
virtual void SetTimeout(Int_t timeout);
|
|
|
|
#ifndef __MAKECLING__
|
|
/**
|
|
* \brief Sets the MSR file handler for accessing run configuration.
|
|
* \param msrHandler Pointer to initialized PMsrHandler instance
|
|
*/
|
|
virtual void SetMsrHandler(PMsrHandler *msrHandler);
|
|
#endif // __MAKECLING__
|
|
|
|
/// Initializes GUI for interactive t0 determination
|
|
virtual void InitT0();
|
|
|
|
/// Initializes GUI for interactive data and background range determination
|
|
virtual void InitDataAndBkg();
|
|
|
|
/**
|
|
* \brief Returns current exit status.
|
|
* \return 0=local quit (single canvas terminates), 1=quit entire application
|
|
*/
|
|
virtual Int_t GetStatus() { return fStatus; }
|
|
|
|
private:
|
|
#ifndef __MAKECLING__
|
|
PMsrHandler *fMsrHandler; ///< MSR file handler for accessing run configuration
|
|
#endif // __MAKECLING__
|
|
Int_t fTimeout; ///< Timeout in ms after which Done signal is emitted (≤0 disables timeout)
|
|
|
|
Bool_t fValid; ///< True if raw data sets are available and GUI is functional
|
|
|
|
Int_t fStatus; ///< Exit status: 0=local quit (single canvas), 1=quit application
|
|
|
|
PMusrT0Data fMusrT0Data; ///< Container for raw μSR run data and histogram information
|
|
|
|
Bool_t fDataAndBkgEnabled; ///< Enable/disable data and background range handling (required for grouping/addrun)
|
|
Bool_t fT0Enabled; ///< Enable/disable t0 handling (required for grouping/addrun)
|
|
Int_t fT0Estimated; ///< Estimated t0 value in bins (used as initial guess)
|
|
Bool_t fShowT0DataChannel; ///< Flag to show/hide t0 value from data file
|
|
|
|
std::unique_ptr<TTimer> fTimeoutTimer; ///< Timer to emit Done signal if no user interaction occurs
|
|
|
|
// Canvas related variables
|
|
std::unique_ptr<TCanvas> fMainCanvas; ///< Main ROOT canvas for the interactive GUI
|
|
|
|
std::unique_ptr<TH1F> fHisto; ///< Full raw data histogram (all bins)
|
|
std::unique_ptr<TH1F> fData; ///< Data region histogram (first good bin to last good bin)
|
|
std::unique_ptr<TH1F> fBkg; ///< Background region histogram (background start to end)
|
|
|
|
std::unique_ptr<TLatex> fToDoInfo; ///< Text display showing current instructions to user
|
|
|
|
std::unique_ptr<TLine> fT0Line; ///< Vertical line marking current t0 position
|
|
std::unique_ptr<TLine> fT0DataLine; ///< Vertical line marking t0 found in data file
|
|
std::unique_ptr<TLine> fFirstBkgLine; ///< Vertical line marking background start bin
|
|
std::unique_ptr<TLine> fLastBkgLine; ///< Vertical line marking background end bin
|
|
std::unique_ptr<TLine> fFirstDataLine; ///< Vertical line marking first good data bin
|
|
std::unique_ptr<TLine> fLastDataLine; ///< Vertical line marking last good data bin
|
|
|
|
Int_t fPx; ///< Current cursor x-position in pixel coordinates
|
|
Int_t fPy; ///< Current cursor y-position in pixel coordinates
|
|
|
|
Int_t fDataRange[2]; ///< Data range in bins: [0]=first good bin, [1]=last good bin
|
|
Int_t fBkgRange[2]; ///< Background range in bins: [0]=first bkg bin, [1]=last bkg bin
|
|
|
|
void ShowDataFileT0Channel(); ///< Displays vertical line showing t0 from data file
|
|
void HideDataFileT0Channel(); ///< Hides vertical line showing t0 from data file
|
|
void SetT0Channel(); ///< Sets t0 to cursor position and updates display
|
|
void SetEstimatedT0Channel(); ///< Sets t0 to estimated value and updates display
|
|
void SetDataFirstChannel(); ///< Sets first good data bin to cursor position
|
|
void SetDataLastChannel(); ///< Sets last good data bin to cursor position
|
|
void SetBkgFirstChannel(); ///< Sets background start bin to cursor position
|
|
void SetBkgLastChannel(); ///< Sets background end bin to cursor position
|
|
void UnZoom(); ///< Resets zoom to show full histogram range
|
|
void ZoomT0(); ///< Zooms to region around t0 for precise adjustment
|
|
|
|
ClassDef(PMusrT0, 1)
|
|
};
|
|
|
|
#endif // _PMUSRT0_H_
|