musrfit 1.10.0
PMusrCanvas.h
Go to the documentation of this file.
1/***************************************************************************
2
3 PMusrCanvas.h
4
5 Author: Andreas Suter
6 e-mail: andreas.suter@psi.ch
7
8***************************************************************************/
9
10/***************************************************************************
11 * Copyright (C) 2007-2026 by Andreas Suter *
12 * andreas.suter@psi.ch *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28 ***************************************************************************/
29
30#ifndef _PMUSRCANVAS_H_
31#define _PMUSRCANVAS_H_
32
33#include <TObject.h>
34#include <TQObject.h>
35#include <TStyle.h>
36#include <TRootCanvas.h>
37#include <TGMenu.h>
38#include <TCanvas.h>
39#include <TPaveText.h>
40#include <TLegend.h>
41#include <TPad.h>
42#include <TH1F.h>
43#include <TGraphErrors.h>
44#include <TMultiGraph.h>
45#include <TLatex.h>
46
47#include "PMusr.h"
48#ifndef __MAKECLING__
49#include "PMsrHandler.h"
50#include "PRunListCollection.h"
51#endif // __MAKECLING__
52
53//--------------------------------------------------------------------------
54// Layout constants
55//--------------------------------------------------------------------------
56#define YINFO 0.1
57#define YTITLE 0.95
58#define XTHEO 0.75
59
60//--------------------------------------------------------------------------
61// Current Plot Views
62//--------------------------------------------------------------------------
63#define PV_DATA 1
64#define PV_FOURIER_REAL 2
65#define PV_FOURIER_IMAG 3
66#define PV_FOURIER_REAL_AND_IMAG 4
67#define PV_FOURIER_PWR 5
68#define PV_FOURIER_PHASE 6
69#define PV_FOURIER_PHASE_OPT_REAL 7
70
71//--------------------------------------------------------------------------
72// Canvas menu IDs
73//--------------------------------------------------------------------------
74#define P_MENU_ID_DATA 10001
75#define P_MENU_ID_FOURIER 10002
76#define P_MENU_ID_DIFFERENCE 10003
77#define P_MENU_ID_AVERAGE 10004
78#define P_MENU_ID_EXPORT_DATA 10005
79
80#define P_MENU_PLOT_OFFSET 1000
81
82//--------------------------------------------------------------------------
83// Fourier submenu IDs
84//--------------------------------------------------------------------------
85#define P_MENU_ID_FOURIER_REAL 100
86#define P_MENU_ID_FOURIER_IMAG 101
87#define P_MENU_ID_FOURIER_REAL_AND_IMAG 102
88#define P_MENU_ID_FOURIER_PWR 103
89#define P_MENU_ID_FOURIER_PHASE 104
90#define P_MENU_ID_FOURIER_PHASE_OPT_REAL 105
91#define P_MENU_ID_FOURIER_PHASE_PLUS 106
92#define P_MENU_ID_FOURIER_PHASE_MINUS 107
93
94//------------------------------------------------------------------------
102class PMusrCanvasPlotRange : public TObject
103{
104 public:
109
111 virtual void SetXRange(Double_t xmin, Double_t xmax);
113 virtual void SetYRange(Double_t ymin, Double_t ymax);
114
116 virtual Bool_t IsXRangePresent() { return fXRangePresent; }
118 virtual Bool_t IsYRangePresent() { return fYRangePresent; }
119
121 virtual Double_t GetXmin() { return fXmin; }
123 virtual Double_t GetXmax() { return fXmax; }
125 virtual Double_t GetYmin() { return fYmin; }
127 virtual Double_t GetYmax() { return fYmax; }
128
129 private:
132 Double_t fXmin;
133 Double_t fXmax;
134 Double_t fYmin;
135 Double_t fYmax;
136
137 ClassDef(PMusrCanvasPlotRange, 1)
138};
139
140//------------------------------------------------------------------------
167
168//------------------------------------------------------------------------
172typedef std::vector<PMusrCanvasDataSet> PMusrCanvasDataList;
173
174//------------------------------------------------------------------------
180 TGraphErrors *data;
181 TGraphErrors *dataFourierRe;
182 TGraphErrors *dataFourierIm;
183 TGraphErrors *dataFourierPwr;
184 TGraphErrors *dataFourierPhase;
185 TGraphErrors *theory;
186 TGraphErrors *theoryFourierRe;
187 TGraphErrors *theoryFourierIm;
188 TGraphErrors *theoryFourierPwr;
189 TGraphErrors *theoryFourierPhase;
190 TGraphErrors *diff;
191 TGraphErrors *diffFourierRe;
192 TGraphErrors *diffFourierIm;
193 TGraphErrors *diffFourierPwr;
194 TGraphErrors *diffFourierPhase;
197};
198
199//------------------------------------------------------------------------
203typedef std::vector<PMusrCanvasNonMusrDataSet> PMusrCanvasNonMusrDataList;
204
205//------------------------------------------------------------------------
214
215//------------------------------------------------------------------------
220typedef std::vector<PMusrCanvasAsciiDump> PMusrCanvasAsciiDumpVector;
221
222//--------------------------------------------------------------------------
270class PMusrCanvas : public TObject, public TQObject
271{
272 public:
275
276 //----------------------------------------------------------------------
291 PMusrCanvas(const Int_t number, const Char_t* title,
292 Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh, const Bool_t batch,
293 const Bool_t fourier=false, const Bool_t avg=false, const Bool_t theoAsData=false);
294
295 //----------------------------------------------------------------------
313 PMusrCanvas(const Int_t number, const Char_t* title,
314 Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh,
315 PMsrFourierStructure fourierDefault,
316 const PIntVector markerList, const PIntVector colorList, const Bool_t batch,
317 const Bool_t fourier=false, const Bool_t avg=false, const Bool_t theoAsData=false);
318
320 virtual ~PMusrCanvas();
321
323 virtual Bool_t IsValid() { return fValid; }
324
325#ifndef __MAKECLING__
327 virtual void SetMsrHandler(PMsrHandler *msrHandler);
329 virtual void SetRunListCollection(PRunListCollection *runList) { fRunList = runList; }
330#endif // __MAKECLING__
331
333 virtual void SetTimeout(Int_t ival);
335 virtual void UpdateParamTheoryPad();
337 virtual void UpdateDataTheoryPad();
339 virtual void UpdateInfoPad();
340
342 virtual void Done(Int_t status=0); // *SIGNAL*
344 virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected); // SLOT
346 virtual void HandleMenuPopup(Int_t id); // SLOT
348 virtual void LastCanvasClosed(); // SLOT
350 virtual void WindowClosed(); // SLOT
351
353 virtual void SaveGraphicsAndQuit(Char_t *fileName, Char_t *graphicsFormat);
355 virtual void ExportData(const Char_t *fileName);
356
357 private:
358 Bool_t fTheoAsData;
361 Int_t fTimeout;
363 Bool_t fBatchMode;
364 Bool_t fValid;
370 Int_t fPlotType;
372
374 Double_t fXmin, fXmax, fYmin, fYmax;
375
377 std::unique_ptr<TLatex> fCurrentFourierPhaseText;
378 std::unique_ptr<TString> fRRFText;
379 std::unique_ptr<TLatex> fRRFLatexText;
380
381 std::unique_ptr<TStyle> fStyle;
382
383 std::unique_ptr<TTimer> fTimeoutTimer;
384
385 // canvas menu related variables
386 TRootCanvas *fImp;
387 TGMenuBar *fBar;
388 TGPopupMenu *fPopupMain;
389 std::unique_ptr<TGPopupMenu> fPopupFourier;
390
391 // canvas related variables
392 std::unique_ptr<TCanvas> fMainCanvas;
393 std::unique_ptr<TPaveText> fTitlePad;
394 std::unique_ptr<TPad> fDataTheoryPad;
395 std::unique_ptr<TPaveText> fParameterPad;
396 std::unique_ptr<TPaveText> fTheoryPad;
397 std::unique_ptr<TLegend> fInfoPad;
398 std::unique_ptr<TLegend> fMultiGraphLegend;
399
401
402#ifndef __MAKECLING__
405#endif // __MAKECLING__
406
408
411 TMultiGraph *fMultiGraphData;
412 TMultiGraph *fMultiGraphDiff;
413
417
418 virtual void CreateStyle();
419 virtual void InitFourier();
420 virtual void InitAverage();
421 virtual void InitMusrCanvas(const Char_t* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh);
422 virtual void InitDataSet(PMusrCanvasDataSet &dataSet);
423 virtual void InitDataSet(PMusrCanvasNonMusrDataSet &dataSet);
424 virtual void CleanupDataSet(PMusrCanvasDataSet &dataSet);
425 virtual void CleanupDataSet(PMusrCanvasNonMusrDataSet &dataSet);
426 virtual void HandleDataSet(UInt_t plotNo, UInt_t runNo, PRunData *data);
427 virtual void HandleNonMusrDataSet(UInt_t plotNo, UInt_t runNo, PRunData *data);
428 virtual void HandleDifference();
429 virtual void HandleFourier();
430 virtual void HandleDifferenceFourier();
431 virtual void HandleFourierDifference();
432 virtual void HandleAverage();
433 virtual void CleanupDifference();
434 virtual void CleanupFourier();
435 virtual void CleanupFourierDifference();
436 virtual void CleanupAverage();
437
438 virtual void CalcPhaseOptReFT();
439 virtual Double_t CalculateDiff(const Double_t x, const Double_t y, TH1F *theo);
440 virtual Double_t CalculateDiff(const Double_t x, const Double_t y, TGraphErrors *theo);
441 virtual Int_t FindBin(const Double_t x, TGraphErrors *graph);
442
443 virtual Double_t GetMaximum(TH1F* histo, Double_t xmin=-1.0, Double_t xmax=-1.0);
444 virtual Double_t GetMinimum(TH1F* histo, Double_t xmin=-1.0, Double_t xmax=-1.0);
445 virtual Double_t GetMaximum(TGraphErrors* graph, Double_t xmin=-1.0, Double_t xmax=-1.0);
446 virtual Double_t GetMinimum(TGraphErrors* graph, Double_t xmin=-1.0, Double_t xmax=-1.0);
447
448 virtual void PlotData(Bool_t unzoom=false);
449 virtual void PlotDifference(Bool_t unzoom=false);
450 virtual void PlotFourier(Bool_t unzoom=false);
451 virtual void PlotFourierDifference(Bool_t unzoom=false);
452 virtual void PlotFourierPhaseValue(Bool_t unzoom=false);
453 virtual void PlotAverage(Bool_t unzoom=false);
454 virtual void IncrementFourierPhase();
455 virtual void DecrementFourierPhase();
456
457 virtual Bool_t IsScaleN0AndBkg();
458 virtual UInt_t GetNeededAccuracy(PMsrParamStructure param);
459
460 virtual Double_t GetInterpolatedValue(TH1F* histo, Double_t xVal);
461
462 virtual void GetExportDataSet(const TH1F *data, const Double_t xmin, const Double_t xmax,
463 PMusrCanvasAsciiDumpVector &dumpData, const Bool_t hasError=true);
464
465 ClassDef(PMusrCanvas, 1)
466};
467
468#endif // _PMUSRCANVAS_H_
std::vector< PMusrCanvasDataSet > PMusrCanvasDataList
std::vector< PMusrCanvasNonMusrDataSet > PMusrCanvasNonMusrDataList
std::vector< PMusrCanvasAsciiDump > PMusrCanvasAsciiDumpVector
std::vector< Int_t > PIntVector
Definition PMusr.h:367
std::vector< Double_t > PDoubleVector
Definition PMusr.h:385
return status
MSR file parser and manager for the musrfit framework.
Helper class for managing plot axis ranges.
Bool_t fXRangePresent
Flag: true if X-range explicitly set.
virtual void SetXRange(Double_t xmin, Double_t xmax)
Sets X-axis range and marks it as present.
Double_t fYmin
Minimum Y value.
PMusrCanvasPlotRange()
Default constructor.
virtual Double_t GetXmax()
Returns maximum X value.
virtual Bool_t IsYRangePresent()
Returns true if Y-axis range has been explicitly set.
Bool_t fYRangePresent
Flag: true if Y-range explicitly set.
virtual ~PMusrCanvasPlotRange()
Destructor.
Double_t fYmax
Maximum Y value.
virtual Double_t GetYmin()
Returns minimum Y value.
virtual Double_t GetXmin()
Returns minimum X value.
Double_t fXmax
Maximum X value.
virtual Double_t GetYmax()
Returns maximum Y value.
Double_t fXmin
Minimum X value.
virtual void SetYRange(Double_t ymin, Double_t ymax)
Sets Y-axis range and marks it as present.
virtual Bool_t IsXRangePresent()
Returns true if X-axis range has been explicitly set.
virtual Double_t CalculateDiff(const Double_t x, const Double_t y, TH1F *theo)
virtual Int_t FindBin(const Double_t x, TGraphErrors *graph)
PMsrFourierStructure fFourier
structure holding all the information necessary to perform the Fourier transform
virtual void CleanupFourier()
std::unique_ptr< TTimer > fTimeoutTimer
timeout timer in order to terminate if no action is taking place for too long
Bool_t fValid
if true, everything looks OK
virtual void InitMusrCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh)
Int_t fPreviousPlotView
tag showing the previous plot view
std::unique_ptr< TPaveText > fTitlePad
title pad used to display a title
PRunListCollection * fRunList
data handler
virtual void HandleFourier()
PMusrCanvasDataSet fDataAvg
set of all averaged data to be plotted (asymmetry/single histogram)
virtual void Done(Int_t status=0)
ROOT signal emitted when canvas is closed or timeout occurs.
virtual void SaveGraphicsAndQuit(Char_t *fileName, Char_t *graphicsFormat)
Saves canvas to graphics file and emits Done signal.
Bool_t fYRangePresent
flag indicating if x-/y-range is present
PIntVector fMarkerList
list of markers
virtual void CleanupAverage()
virtual void InitDataSet(PMusrCanvasDataSet &dataSet)
virtual void CreateStyle()
virtual void PlotFourierDifference(Bool_t unzoom=false)
virtual void HandleAverage()
std::unique_ptr< TGPopupMenu > fPopupFourier
popup menu of the Musrfit/Fourier sub menu
PDoubleVector fCurrentFourierPhase
holds the current Fourier phase(s)
Bool_t fTheoAsData
flag if true, calculate theory points only at the data points
Int_t fPlotType
plot type tag: -1 == undefined, MSR_PLOT_SINGLE_HISTO == single histogram, MSR_PLOT_ASYM == asymmetry...
Int_t fCurrentPlotView
tag showing what the current plot view is: data, fourier, ...
virtual void HandleDataSet(UInt_t plotNo, UInt_t runNo, PRunData *data)
Double_t fXmax
virtual void HandleDifferenceFourier()
virtual void CalcPhaseOptReFT()
PMusrCanvas::CalcPhaseOptReFT.
TGMenuBar * fBar
menu bar
virtual void SetMsrHandler(PMsrHandler *msrHandler)
Sets the MSR file handler for accessing fit parameters and configuration.
virtual Double_t GetMinimum(TH1F *histo, Double_t xmin=-1.0, Double_t xmax=-1.0)
std::unique_ptr< TPad > fDataTheoryPad
data/theory pad used to display the data/theory
std::unique_ptr< TLatex > fRRFLatexText
used to display RRF info
virtual void LastCanvasClosed()
ROOT slot called when this is the last canvas being closed.
virtual Double_t GetMaximum(TH1F *histo, Double_t xmin=-1.0, Double_t xmax=-1.0)
Bool_t fBatchMode
musrview in ROOT batch mode
virtual void CleanupDifference()
std::unique_ptr< TStyle > fStyle
A collection of all graphics attributes.
virtual void SetRunListCollection(PRunListCollection *runList)
Sets the run list collection for accessing fit data and results.
virtual void HandleDifference()
std::unique_ptr< TLegend > fInfoPad
info pad used to display a legend of the data plotted
std::unique_ptr< TCanvas > fMainCanvas
main canvas
TMultiGraph * fMultiGraphData
fMultiGraphData is a 'global' graph needed in order to plot error graphs (data) with (potentially) di...
PIntVector fColorList
list of colors
virtual Bool_t IsValid()
Returns true if canvas initialized successfully.
PMsrHandler * fMsrHandler
msr-file handler
PMusrCanvas()
Default constructor.
virtual void HandleFourierDifference()
PMusrCanvasDataList fData
list of all histogram data to be plotted (asymmetry/single histogram)
Bool_t fAveragedView
tag showing that the averaged view or normal view should be presented.
std::unique_ptr< TLatex > fCurrentFourierPhaseText
used in Re/Im Fourier to show the current phase in the pad
Double_t fYmax
data/theory frame range
TGPopupMenu * fPopupMain
popup menu Musrfit in the main menu bar
TH1F * fHistoFrame
fHistoFrame is a 'global' frame needed in order to plot histograms with (potentially) different x-fra...
virtual void InitAverage()
virtual void UpdateInfoPad()
Updates info/legend pad with run information.
Int_t fPlotNumber
plot number
Bool_t fStartWithFourier
flag if true, the Fourier transform will be presented bypassing the time domain representation
virtual void InitFourier()
virtual void CleanupFourierDifference()
virtual void PlotDifference(Bool_t unzoom=false)
virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected)
ROOT slot handling keyboard commands (e.g., 'f' for Fourier, 'd' for data)
virtual Bool_t IsScaleN0AndBkg()
virtual void SetTimeout(Int_t ival)
Sets timeout in seconds after which Done signal is emitted (0=no timeout)
virtual void IncrementFourierPhase()
virtual Double_t GetInterpolatedValue(TH1F *histo, Double_t xVal)
virtual void PlotData(Bool_t unzoom=false)
std::unique_ptr< TString > fRRFText
RRF information.
TMultiGraph * fMultiGraphDiff
fMultiGraphDiff is a 'global' graph needed in order to plot error graphs (data-theory) with (potentia...
Bool_t fStartWithAvg
flag if true, the averaged data/Fourier will be presented
virtual void CleanupDataSet(PMusrCanvasDataSet &dataSet)
TRootCanvas * fImp
ROOT native GUI version of main window with menubar and drawing area.
virtual void HandleMenuPopup(Int_t id)
ROOT slot handling menu selections.
Double_t fXmin
virtual UInt_t GetNeededAccuracy(PMsrParamStructure param)
virtual void PlotFourier(Bool_t unzoom=false)
std::unique_ptr< TLegend > fMultiGraphLegend
used for non-muSR plots to display a legend
Int_t fTimeout
timeout after which the Done signal should be emited. If timeout <= 0, no timeout is taking place
virtual void ExportData(const Char_t *fileName)
Exports displayed data to ASCII file.
Bool_t fToggleColor
tag showing if a single histo theory is color toggled
virtual void HandleNonMusrDataSet(UInt_t plotNo, UInt_t runNo, PRunData *data)
virtual void PlotFourierPhaseValue(Bool_t unzoom=false)
std::unique_ptr< TPaveText > fTheoryPad
theory pad used to display the theory and functions
Bool_t fXRangePresent
virtual void DecrementFourierPhase()
Bool_t fDifferenceView
tag showing that the shown data, fourier, are the difference between data and theory
virtual void UpdateParamTheoryPad()
Updates parameter and theory display pads with current fit results.
virtual void UpdateDataTheoryPad()
Updates main data/theory plotting pad.
virtual ~PMusrCanvas()
Destructor - cleans up all histograms, graphs, and ROOT objects.
std::unique_ptr< TPaveText > fParameterPad
parameter pad used to display the fitting parameters
Double_t fYmin
virtual void PlotAverage(Bool_t unzoom=false)
Bool_t fScaleN0AndBkg
true=N0 and background is scaled to (1/ns), otherwise (1/bin) for the single histogram case
virtual void WindowClosed()
ROOT slot called when canvas window is closed.
virtual void GetExportDataSet(const TH1F *data, const Double_t xmin, const Double_t xmax, PMusrCanvasAsciiDumpVector &dumpData, const Bool_t hasError=true)
PMusrCanvasNonMusrDataList fNonMusrData
list of all error graphs to be plotted (non-muSR)
Manager class for all processed μSR run data during fitting.
PDoubleVector dataErr
error of the y-axis data set
PDoubleVector dataX
x-axis data set
PDoubleVector data
y-axis data set
TH1F * theoryFourierIm
imaginary part of the Fourier transform of the theory histogram
TH1F * theoryFourierPwr
power spectrum of the Fourier transform of the theory histogram
UInt_t diffFourierTag
0=not relevant, 1=d-f (Fourier of difference time spectra), 2=f-d (difference of Fourier spectra)
TH1F * theory
theory histogram belonging to the data histogram
TH1F * dataFourierRe
real part of the Fourier transform of the data histogram
TH1F * diffFourierPhase
phase spectrum of the Fourier transform of the diff histogram
TH1F * dataFourierPhase
phase spectrum of the Fourier transform of the data histogram
TH1F * theoryFourierPhaseOptReal
phase optimized real part spectrum Fourier transform of the theory histogram
TH1F * diff
difference histogram, i.e. data-theory
TH1F * diffFourierPhaseOptReal
phase optimized real part spectrum Fourier transform of the diff histogram
TH1F * dataFourierIm
imaginary part of the Fourier transform of the data histogram
TH1F * data
data histogram
TH1F * diffFourierIm
imaginary part of the Fourier transform of the diff histogram
TH1F * theoryFourierPhase
phase spectrum of the Fourier transform of the theory histogram
TH1F * dataFourierPhaseOptReal
phase optimized real part spectrum Fourier transform of the data histogram
PMusrCanvasPlotRange * dataRange
keep the msr-file plot data range
TH1F * diffFourierPwr
power spectrum of the Fourier transform of the diff histogram
TH1F * dataFourierPwr
power spectrum of the Fourier transform of the data histogram
TH1F * diffFourierRe
real part of the Fourier transform of the diff histogram
TH1F * theoryFourierRe
real part of the Fourier transform of the theory histogram
TGraphErrors * dataFourierPhase
phase spectrum of the Fourier transform of the data error graph
TGraphErrors * theoryFourierRe
real part of the Fourier transform of the theory error graph
TGraphErrors * theoryFourierIm
imaginary part of the Fourier transform of the theory error graph
TGraphErrors * dataFourierRe
real part of the Fourier transform of the data error graph
TGraphErrors * theoryFourierPwr
power spectrum of the Fourier transform of the theory error graph
TGraphErrors * data
data error graph
TGraphErrors * theoryFourierPhase
phase spectrum of the Fourier transform of the theory error graph
UInt_t diffFourierTag
0=not relevant, 1=d-f (Fourier of difference time spectra), 2=f-d (difference of Fourier spectra)
TGraphErrors * diffFourierPhase
phase spectrum of the Fourier transform of the diff error graph
TGraphErrors * diffFourierPwr
power spectrum of the Fourier transform of the diff error graph
PMusrCanvasPlotRange * dataRange
keep the msr-file plot data range
TGraphErrors * diffFourierRe
real part of the Fourier transform of the diff error graph
TGraphErrors * dataFourierIm
imaginary part of the Fourier transform of the data error graph
TGraphErrors * diffFourierIm
imaginary part of the Fourier transform of the diff error graph
TGraphErrors * theory
theory histogram belonging to the data error graph
TGraphErrors * diff
difference error graph, i.e. data-theory
TGraphErrors * dataFourierPwr
power spectrum of the Fourier transform of the data error graph