From dcc9783f6260cd20c2e74923faa4238d4801e3c6 Mon Sep 17 00:00:00 2001 From: nemu Date: Mon, 5 Jan 2009 13:15:01 +0000 Subject: [PATCH] added phase label to Re/Im Fourier part. Some bug fixing in phase handling --- src/classes/PMusrCanvas.cpp | 120 ++++++++++++++++++++++++++++++++---- src/include/PMusrCanvas.h | 5 ++ 2 files changed, 112 insertions(+), 13 deletions(-) diff --git a/src/classes/PMusrCanvas.cpp b/src/classes/PMusrCanvas.cpp index 55335a7c..a6a30417 100644 --- a/src/classes/PMusrCanvas.cpp +++ b/src/classes/PMusrCanvas.cpp @@ -71,6 +71,9 @@ PMusrCanvas::PMusrCanvas() fInfoPad = 0; InitFourier(); + + fCurrentFourierPhase = fFourier.fPhaseIncrement; + fCurrentFourierPhaseText = 0; } //-------------------------------------------------------------------------- @@ -86,6 +89,9 @@ PMusrCanvas::PMusrCanvas(const int number, const char* title, InitFourier(); CreateStyle(); InitMusrCanvas(title, wtopx, wtopy, ww, wh); + + fCurrentFourierPhase = fFourier.fPhaseIncrement; + fCurrentFourierPhaseText = 0; } //-------------------------------------------------------------------------- @@ -103,6 +109,9 @@ PMusrCanvas::PMusrCanvas(const int number, const char* title, { CreateStyle(); InitMusrCanvas(title, wtopx, wtopy, ww, wh); + + fCurrentFourierPhase = fFourier.fPhaseIncrement; + fCurrentFourierPhaseText = 0; } //-------------------------------------------------------------------------- @@ -152,6 +161,10 @@ cout << "~PMusrCanvas() called. fMainCanvas name=" << fMainCanvas->GetName() << CleanupDataSet(fNonMusrData[i]); fNonMusrData.clear(); } + if (fCurrentFourierPhaseText) { + delete fCurrentFourierPhaseText; + fCurrentFourierPhaseText = 0; + } } //-------------------------------------------------------------------------- @@ -1596,10 +1609,11 @@ cout << endl << ">> in PlotFourier() ..." << endl; xAxisTitle = TString("??"); } + // plot data double min, max, binContent; switch (fCurrentPlotView) { - case PV_FOURIER_REAL: + case PV_FOURIER_REAL: //cout << endl << ">> fData[0].dataFourierRe->GetNbinsX() = " << fData[0].dataFourierRe->GetNbinsX(); // plot first histo fData[0].dataFourierRe->Draw("pe"); @@ -1647,6 +1661,9 @@ cout << endl << ">> in PlotFourier() ..." << endl; for (unsigned int i=0; iDraw("esame"); } + + PlotFourierPhaseValue(); + break; case PV_FOURIER_IMAG: // plot first histo @@ -1691,6 +1708,9 @@ cout << endl << ">> in PlotFourier() ..." << endl; for (unsigned int i=0; iDraw("esame"); } + + PlotFourierPhaseValue(); + break; case PV_FOURIER_REAL_AND_IMAG: break; @@ -1792,6 +1812,42 @@ cout << endl << ">> in PlotFourier() ..." << endl; fMainCanvas->Update(); } +//-------------------------------------------------------------------------- +// PlotFourierPhaseValue +//-------------------------------------------------------------------------- +/** + *

+ * + */ +void PMusrCanvas::PlotFourierPhaseValue() +{ + // check if phase TLatex object is present + if (fCurrentFourierPhaseText) { + delete fCurrentFourierPhaseText; + fCurrentFourierPhaseText = 0; + } + + double x, y; + TString str; + + // plot Fourier phase + str = TString("phase = "); + str += fCurrentFourierPhase; + x = 0.7; + y = 0.85; + fCurrentFourierPhaseText = new TLatex(); + fCurrentFourierPhaseText->SetNDC(kTRUE); + fCurrentFourierPhaseText->SetText(x, y, str.Data()); + fCurrentFourierPhaseText->SetTextFont(62); + fCurrentFourierPhaseText->SetTextSize(0.03); + + fDataTheoryPad->cd(); + + fCurrentFourierPhaseText->Draw(); + + fDataTheoryPad->Update(); +} + //-------------------------------------------------------------------------- // SaveDataAscii //-------------------------------------------------------------------------- @@ -2457,6 +2513,38 @@ cout << endl << ">> theory scale = " << scale << ", data.res/theory.res = " << f fData[i].theoryFourierPwr->SetLineColor(fData[i].theory->GetLineColor()); fData[i].theoryFourierPhase->SetLineColor(fData[i].theory->GetLineColor()); } + + // apply global phase + if (fFourier.fPhase != 0.0) { + double re, im; + const double cp = TMath::Cos(fFourier.fPhase/180.0*TMath::Pi()); + const double sp = TMath::Sin(fFourier.fPhase/180.0*TMath::Pi()); + + fCurrentFourierPhase = fFourier.fPhase; + + for (unsigned int i=0; iGetNbinsX(); j++) { // loop over a fourier data set + // calculate new fourier data set value + re = fData[i].dataFourierRe->GetBinContent(j) * cp + fData[i].dataFourierIm->GetBinContent(j) * sp; + im = fData[i].dataFourierIm->GetBinContent(j) * cp - fData[i].dataFourierRe->GetBinContent(j) * sp; + // overwrite fourier data set value + fData[i].dataFourierRe->SetBinContent(j, re); + fData[i].dataFourierIm->SetBinContent(j, im); + } + } + if ((fData[i].theoryFourierRe != 0) && (fData[i].theoryFourierIm != 0)) { + for (int j=0; jGetNbinsX(); j++) { // loop over a fourier data set + // calculate new fourier data set value + re = fData[i].theoryFourierRe->GetBinContent(j) * cp + fData[i].theoryFourierIm->GetBinContent(j) * sp; + im = fData[i].theoryFourierIm->GetBinContent(j) * cp - fData[i].theoryFourierRe->GetBinContent(j) * sp; + // overwrite fourier data set value + fData[i].theoryFourierRe->SetBinContent(j, re); + fData[i].theoryFourierIm->SetBinContent(j, im); + } + } + } + } } else { // calculate diff fourier // delete fourier components for (unsigned int i=0; iGetNbinsX()-1; j++) { // loop over a fourier data set + for (int j=0; jGetNbinsX(); j++) { // loop over a fourier data set // calculate new fourier data set value - re = fData[i].dataFourierRe->GetBinContent(j) * cp - fData[i].dataFourierIm->GetBinContent(j) * sp; - im = fData[i].dataFourierIm->GetBinContent(j) * cp + fData[i].dataFourierIm->GetBinContent(j) * sp; + re = fData[i].dataFourierRe->GetBinContent(j) * cp + fData[i].dataFourierIm->GetBinContent(j) * sp; + im = fData[i].dataFourierIm->GetBinContent(j) * cp - fData[i].dataFourierRe->GetBinContent(j) * sp; // overwrite fourier data set value fData[i].dataFourierRe->SetBinContent(j, re); fData[i].dataFourierIm->SetBinContent(j, im); } } if ((fData[i].theoryFourierRe != 0) && (fData[i].theoryFourierIm != 0)) { - for (int j=1; jGetNbinsX()-1; j++) { // loop over a fourier data set + for (int j=0; jGetNbinsX(); j++) { // loop over a fourier data set // calculate new fourier data set value - re = fData[i].theoryFourierRe->GetBinContent(j) * cp - fData[i].theoryFourierIm->GetBinContent(j) * sp; - im = fData[i].theoryFourierIm->GetBinContent(j) * cp + fData[i].theoryFourierIm->GetBinContent(j) * sp; + re = fData[i].theoryFourierRe->GetBinContent(j) * cp + fData[i].theoryFourierIm->GetBinContent(j) * sp; + im = fData[i].theoryFourierIm->GetBinContent(j) * cp - fData[i].theoryFourierRe->GetBinContent(j) * sp; // overwrite fourier data set value fData[i].theoryFourierRe->SetBinContent(j, re); fData[i].theoryFourierIm->SetBinContent(j, im); @@ -2570,22 +2661,25 @@ void PMusrCanvas::DecrementFourierPhase() const double cp = TMath::Cos(fFourier.fPhaseIncrement/180.0*TMath::Pi()); const double sp = TMath::Sin(fFourier.fPhaseIncrement/180.0*TMath::Pi()); + fCurrentFourierPhase -= fFourier.fPhaseIncrement; + PlotFourierPhaseValue(); + for (unsigned int i=0; iGetNbinsX()-1; j++) { // loop over a fourier data set + for (int j=0; jGetNbinsX(); j++) { // loop over a fourier data set // calculate new fourier data set value - re = fData[i].dataFourierRe->GetBinContent(j) * cp + fData[i].dataFourierIm->GetBinContent(j) * sp; - im = fData[i].dataFourierIm->GetBinContent(j) * cp - fData[i].dataFourierIm->GetBinContent(j) * sp; + re = fData[i].dataFourierRe->GetBinContent(j) * cp - fData[i].dataFourierIm->GetBinContent(j) * sp; + im = fData[i].dataFourierIm->GetBinContent(j) * cp + fData[i].dataFourierRe->GetBinContent(j) * sp; // overwrite fourier data set value fData[i].dataFourierRe->SetBinContent(j, re); fData[i].dataFourierIm->SetBinContent(j, im); } } if ((fData[i].theoryFourierRe != 0) && (fData[i].theoryFourierIm != 0)) { - for (int j=1; jGetNbinsX()-1; j++) { // loop over a fourier data set + for (int j=0; jGetNbinsX(); j++) { // loop over a fourier data set // calculate new fourier data set value - re = fData[i].theoryFourierRe->GetBinContent(j) * cp + fData[i].theoryFourierIm->GetBinContent(j) * sp; - im = fData[i].theoryFourierIm->GetBinContent(j) * cp - fData[i].theoryFourierIm->GetBinContent(j) * sp; + re = fData[i].theoryFourierRe->GetBinContent(j) * cp - fData[i].theoryFourierIm->GetBinContent(j) * sp; + im = fData[i].theoryFourierIm->GetBinContent(j) * cp + fData[i].theoryFourierRe->GetBinContent(j) * sp; // overwrite fourier data set value fData[i].theoryFourierRe->SetBinContent(j, re); fData[i].theoryFourierIm->SetBinContent(j, im); diff --git a/src/include/PMusrCanvas.h b/src/include/PMusrCanvas.h index 5d216128..dd365d56 100644 --- a/src/include/PMusrCanvas.h +++ b/src/include/PMusrCanvas.h @@ -43,6 +43,7 @@ #include #include #include +#include #include "PMusr.h" #ifndef __MAKECINT__ @@ -176,6 +177,9 @@ class PMusrCanvas : public TObject, public TQObject Int_t fPlotType; Int_t fPlotNumber; + Double_t fCurrentFourierPhase; /// holds the current Fourier phase + TLatex *fCurrentFourierPhaseText; /// used in Re/Im Fourier to show the current phase in the pad + TStyle *fStyle; // canvas menu related variables @@ -226,6 +230,7 @@ class PMusrCanvas : public TObject, public TQObject virtual void PlotData(); virtual void PlotDifference(); virtual void PlotFourier(); + virtual void PlotFourierPhaseValue(); virtual void IncrementFourierPhase(); virtual void DecrementFourierPhase();