next step towards Fourier
This commit is contained in:
parent
4a832f6fe8
commit
ce9f98c37d
@ -51,14 +51,9 @@ using namespace std;
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \dataType tag indicating if data is histogram, asymmetry, ...
|
||||
* \data vector with the real data
|
||||
*/
|
||||
PFourier::PFourier(int dataType, TH1F *data,
|
||||
double startTime, double endTime,
|
||||
unsigned int zeroPaddingPower, bool estimateN0AndBkg) :
|
||||
fDataType(dataType), fData(data),
|
||||
fStartTime(startTime), fEndTime(endTime),
|
||||
PFourier::PFourier(TH1F *data, int unitTag, double startTime, double endTime, unsigned int zeroPaddingPower) :
|
||||
fData(data), fUnitTag(unitTag), fStartTime(startTime), fEndTime(endTime),
|
||||
fZeroPaddingPower(zeroPaddingPower)
|
||||
{
|
||||
// some necessary checks and initialization
|
||||
@ -68,31 +63,23 @@ PFourier::PFourier(int dataType, TH1F *data,
|
||||
return;
|
||||
}
|
||||
|
||||
if ((fStartTime < 0.0) || (fEndTime < 0.0)) {
|
||||
cout << endl << "**ERROR** PFourier::PFourier: no valid start or end time." << endl << endl;
|
||||
fValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
fValid = true;
|
||||
fIn = 0;
|
||||
fOut = 0;
|
||||
|
||||
fApodization = F_APODIZATION_NONE;
|
||||
|
||||
// calculate time resolution in (ns)
|
||||
fTimeResolution = fData->GetBinWidth(1) * 1000.0;
|
||||
// calculate time resolution in (us)
|
||||
fTimeResolution = fData->GetBinWidth(1);
|
||||
cout << endl << ">> fTimeResolution = " << fTimeResolution;
|
||||
|
||||
// if endTime == 0 set it to the last time slot
|
||||
if (fEndTime == 0.0) {
|
||||
int last = fData->GetNbinsX()-1;
|
||||
fEndTime = fData->GetBinCenter(last);
|
||||
} else {
|
||||
fEndTime *= 1000.0; // us -> ns
|
||||
//cout << endl << ">> fEndTime = " << fEndTime;
|
||||
}
|
||||
|
||||
fStartTime *= 1000.0; // us -> ns
|
||||
|
||||
// swap start and end time if necessary
|
||||
if (fStartTime > fEndTime) {
|
||||
double keep = fStartTime;
|
||||
@ -100,29 +87,49 @@ PFourier::PFourier(int dataType, TH1F *data,
|
||||
fEndTime = keep;
|
||||
}
|
||||
|
||||
cout << endl << "dB = " << 1.0/(2.0 * F_GAMMA_BAR_MUON * (fEndTime-fStartTime)) << " (G), Bmax = " << 1.0/(2.0 * F_GAMMA_BAR_MUON * fTimeResolution) << " (G)" << endl;
|
||||
|
||||
// try to estimate N0 and Bkg just out of the raw data
|
||||
if (estimateN0AndBkg) {
|
||||
EstimateN0AndBkg();
|
||||
}
|
||||
|
||||
// calculate start and end bin
|
||||
unsigned int start = (unsigned int)(fStartTime/fTimeResolution);
|
||||
unsigned int end = (unsigned int)(fEndTime/fTimeResolution);
|
||||
fNoOfData = end-start;
|
||||
|
||||
// check if zero padding is whished
|
||||
//cout << endl << ">> fNoOfData = " << fNoOfData;
|
||||
|
||||
// check if zero padding is whished
|
||||
if (fZeroPaddingPower > 0) {
|
||||
fNoOfBins = static_cast<unsigned int>(pow(2.0, static_cast<double>(fZeroPaddingPower)));
|
||||
} else {
|
||||
fNoOfBins = fNoOfData;
|
||||
}
|
||||
|
||||
cout << endl << ">> fNoOfBins = " << fNoOfBins;
|
||||
|
||||
// calculate fourier resolution
|
||||
double resolution = 1.0/(fTimeResolution*fNoOfBins); // in MHz
|
||||
switch (fUnitTag) {
|
||||
case FOURIER_UNIT_FIELD:
|
||||
fResolution = resolution/F_GAMMA_BAR_MUON;
|
||||
break;
|
||||
case FOURIER_UNIT_FREQ:
|
||||
fResolution = resolution;
|
||||
break;
|
||||
case FOURIER_UNIT_CYCLES:
|
||||
fResolution = 2.0*PI*resolution;
|
||||
break;
|
||||
default:
|
||||
fValid = false;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
cout << endl << ">> fResolution = " << fResolution;
|
||||
|
||||
// allocate necessary memory
|
||||
fIn = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*fNoOfBins);
|
||||
fOut = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*fNoOfBins);
|
||||
|
||||
//cout << endl << ">> fIn = " << fIn;
|
||||
//cout << endl << ">> fOut = " << fOut;
|
||||
|
||||
// check if memory allocation has been successful
|
||||
if ((fIn == 0) || (fOut == 0)) {
|
||||
fValid = false;
|
||||
@ -134,6 +141,9 @@ cout << endl << "dB = " << 1.0/(2.0 * F_GAMMA_BAR_MUON * (fEndTime-fStartTime))
|
||||
if (!fFFTwPlan) {
|
||||
fValid = false;
|
||||
}
|
||||
|
||||
//cout << endl;
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -159,18 +169,16 @@ cout << endl << "in ~PFourier() ..." << endl;
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \param apodizationTag 0=no apod., 1=weak apod., 2=medium apod., 3=strong apod., 4=user apod.
|
||||
* \param apodizationTag 0=no apod., 1=weak apod., 2=medium apod., 3=strong apod.
|
||||
*/
|
||||
void PFourier::Transform(unsigned int apodizationTag)
|
||||
{
|
||||
if (!fValid)
|
||||
return;
|
||||
|
||||
if (fDataType == F_SINGLE_HISTO) {
|
||||
PrepareSingleHistoFFTwInputData(apodizationTag);
|
||||
} else {
|
||||
PrepareFFTwInputData(apodizationTag);
|
||||
}
|
||||
cout << endl << ">> PFourier::Transform ..." << endl;
|
||||
|
||||
PrepareFFTwInputData(apodizationTag);
|
||||
|
||||
fftw_execute(fFFTwPlan);
|
||||
}
|
||||
@ -181,34 +189,34 @@ void PFourier::Transform(unsigned int apodizationTag)
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \param realFourier
|
||||
* \param scale
|
||||
*/
|
||||
void PFourier::GetRealFourier(TH1F *realFourier)
|
||||
TH1F* PFourier::GetRealFourier(const double scale)
|
||||
{
|
||||
// check if valid flag is set
|
||||
if (!fValid)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
// reallocate realFourier
|
||||
// invoke realFourier
|
||||
char name[256];
|
||||
char title[256];
|
||||
strncpy(name, realFourier->GetName(), sizeof(name));
|
||||
strncpy(title, realFourier->GetTitle(), sizeof(title));
|
||||
if (realFourier) {
|
||||
delete realFourier;
|
||||
realFourier = 0;
|
||||
}
|
||||
realFourier = new TH1F(name, title, fNoOfBins, -fFieldResolution/2.0, fNoOfBins*fFieldResolution+fFieldResolution/2.0);
|
||||
snprintf(name, sizeof(name), "%s_Fourier_Re", fData->GetName());
|
||||
snprintf(title, sizeof(title), "%s_Fourier_Re", fData->GetTitle());
|
||||
|
||||
TH1F *realFourier = new TH1F(name, title, fNoOfBins/2, -fResolution/2.0, fNoOfBins/2.0*fResolution+fResolution/2.0);
|
||||
if (realFourier == 0) {
|
||||
fValid = false;
|
||||
cout << endl << "**SEVERE ERROR** couldn't allocate memory for the real part of the Fourier transform." << endl;
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fill realFourier vector
|
||||
for (unsigned int i=0; i<fNoOfBins; i++) {
|
||||
realFourier->SetBinContent(i+1, fOut[i][0]);
|
||||
for (unsigned int i=0; i<fNoOfBins/2; i++) {
|
||||
realFourier->SetBinContent(i+1, scale*fOut[i][0]);
|
||||
realFourier->SetBinError(i+1, 0.0);
|
||||
}
|
||||
cout << endl << ">> realFourier = " << realFourier;
|
||||
return realFourier;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -217,125 +225,123 @@ void PFourier::GetRealFourier(TH1F *realFourier)
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \param imaginaryFourier
|
||||
* \param scale
|
||||
*/
|
||||
void PFourier::GetImaginaryFourier(TH1F *imaginaryFourier)
|
||||
TH1F* PFourier::GetImaginaryFourier(const double scale)
|
||||
{
|
||||
// check if valid flag is set
|
||||
if (!fValid)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
// reallocate imaginaryFourier
|
||||
// invoke imaginaryFourier
|
||||
char name[256];
|
||||
char title[256];
|
||||
strncpy(name, imaginaryFourier->GetName(), sizeof(name));
|
||||
strncpy(title, imaginaryFourier->GetTitle(), sizeof(title));
|
||||
if (imaginaryFourier) {
|
||||
delete imaginaryFourier;
|
||||
imaginaryFourier = 0;
|
||||
}
|
||||
imaginaryFourier = new TH1F(name, title, fNoOfBins, -fFieldResolution/2.0, fNoOfBins*fFieldResolution+fFieldResolution/2.0);
|
||||
snprintf(name, sizeof(name), "%s_Fourier_Im", fData->GetName());
|
||||
snprintf(title, sizeof(title), "%s_Fourier_Im", fData->GetTitle());
|
||||
|
||||
TH1F* imaginaryFourier = new TH1F(name, title, fNoOfBins/2, -fResolution/2.0, fNoOfBins/2.0*fResolution+fResolution/2.0);
|
||||
if (imaginaryFourier == 0) {
|
||||
fValid = false;
|
||||
cout << endl << "**SEVERE ERROR** couldn't allocate memory for the imaginary part of the Fourier transform." << endl;
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fill imaginaryFourier vector
|
||||
for (unsigned int i=0; i<fNoOfBins; i++) {
|
||||
imaginaryFourier->SetBinContent(i+1, fOut[i][1]);
|
||||
for (unsigned int i=0; i<fNoOfBins/2; i++) {
|
||||
imaginaryFourier->SetBinContent(i+1, scale*fOut[i][1]);
|
||||
imaginaryFourier->SetBinError(i+1, 0.0);
|
||||
}
|
||||
|
||||
return imaginaryFourier;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// EstimateN0AndBkg
|
||||
// GetPowerFourier
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \param scale
|
||||
*/
|
||||
void PFourier::EstimateN0AndBkg()
|
||||
TH1F* PFourier::GetPowerFourier(const double scale)
|
||||
{
|
||||
int noOfBins = fData->GetNbinsX();
|
||||
// check if valid flag is set
|
||||
if (!fValid)
|
||||
return 0;
|
||||
|
||||
TH1F summHisto("summHisto", "summHisto", noOfBins,
|
||||
-fTimeResolution/2.0, (noOfBins-1)*fTimeResolution + fTimeResolution/2.0);
|
||||
// invoke powerFourier
|
||||
char name[256];
|
||||
char title[256];
|
||||
snprintf(name, sizeof(name), "%s_Fourier_Pwr", fData->GetName());
|
||||
snprintf(title, sizeof(title), "%s_Fourier_Pwr", fData->GetTitle());
|
||||
|
||||
// fill summHisto
|
||||
TH1F* pwrFourier = new TH1F(name, title, fNoOfBins/2, -fResolution/2.0, fNoOfBins/2.0*fResolution+fResolution/2.0);
|
||||
if (pwrFourier == 0) {
|
||||
fValid = false;
|
||||
cout << endl << "**SEVERE ERROR** couldn't allocate memory for the power part of the Fourier transform." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fill powerFourier vector
|
||||
for (unsigned int i=0; i<fNoOfBins/2; i++) {
|
||||
pwrFourier->SetBinContent(i+1, scale*sqrt(fOut[i][0]*fOut[i][0]+fOut[i][1]*fOut[i][1]));
|
||||
pwrFourier->SetBinError(i+1, 0.0);
|
||||
}
|
||||
|
||||
return pwrFourier;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// GetPhaseFourier
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \param scale
|
||||
*/
|
||||
TH1F* PFourier::GetPhaseFourier(const double scale)
|
||||
{
|
||||
// check if valid flag is set
|
||||
if (!fValid)
|
||||
return 0;
|
||||
|
||||
// invoke phaseFourier
|
||||
char name[256];
|
||||
char title[256];
|
||||
snprintf(name, sizeof(name), "%s_Fourier_Phase", fData->GetName());
|
||||
snprintf(title, sizeof(title), "%s_Fourier_Phase", fData->GetTitle());
|
||||
|
||||
TH1F* phaseFourier = new TH1F(name, title, fNoOfBins/2, -fResolution/2.0, fNoOfBins/2.0*fResolution+fResolution/2.0);
|
||||
if (phaseFourier == 0) {
|
||||
fValid = false;
|
||||
cout << endl << "**SEVERE ERROR** couldn't allocate memory for the phase part of the Fourier transform." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fill phaseFourier vector
|
||||
double value = 0.0;
|
||||
for (int i=1; i<noOfBins; i++) {
|
||||
value += fData->GetBinContent(i);
|
||||
summHisto.SetBinContent(i, value);
|
||||
summHisto.SetBinError(i, sqrt(value));
|
||||
for (unsigned int i=0; i<fNoOfBins/2; i++) {
|
||||
// calculate the phase
|
||||
if (fOut[i][0] == 0) {
|
||||
if (fOut[i][1] >= 0.0)
|
||||
value = PI_HALF;
|
||||
else
|
||||
value = -PI_HALF;
|
||||
} else {
|
||||
value = atan(fOut[i][1]/fOut[i][0]);
|
||||
// check sector
|
||||
if (fOut[i][0] < 0.0) {
|
||||
if (fOut[i][1] > 0.0)
|
||||
value = PI + value;
|
||||
else
|
||||
value = PI - value;
|
||||
}
|
||||
}
|
||||
phaseFourier->SetBinContent(i+1, scale*value);
|
||||
phaseFourier->SetBinError(i+1, 0.0);
|
||||
}
|
||||
|
||||
cout << endl << ">> max.summHisto=" << summHisto.GetBinContent(noOfBins-1) << endl << endl;
|
||||
|
||||
// define fit function
|
||||
TF1 *func = new TF1("func", "[0]*(1-TMath::Exp(-x/[1]))+[2]*x",
|
||||
-fTimeResolution/2.0, (noOfBins-1)*fTimeResolution +
|
||||
fTimeResolution/2.0);
|
||||
// parameter 0 ~ N0 tau
|
||||
func->SetParameter(0, summHisto.GetBinContent(noOfBins-1));
|
||||
// parameter 1 == tau
|
||||
func->FixParameter(1, PMUON_LIFETIME*1000.0);
|
||||
// parameter 2 ~ <Bkg>
|
||||
func->SetParameter(2, summHisto.GetBinContent(noOfBins-1)/(PMUON_LIFETIME*1000.0)*0.05);
|
||||
|
||||
// do the fit
|
||||
summHisto.Fit(func, "0QR"); // 0->no Graph, Q->quite, R->time range from function
|
||||
|
||||
// get out the parameters
|
||||
double A = func->GetParameter(0);
|
||||
double B = func->GetParameter(2);
|
||||
|
||||
cout << endl << ">> A=" << A << ", B=" << B;
|
||||
cout << endl << ">> N0/per bin=" << A/(PMUON_LIFETIME*1000.0)*fTimeResolution << ", <Bkg> per bin=" << B*fTimeResolution << endl << endl;
|
||||
|
||||
fN0 = A/(PMUON_LIFETIME*1000.0)*fTimeResolution;
|
||||
fBkg = B*fTimeResolution;
|
||||
|
||||
// clean up
|
||||
if (func) {
|
||||
delete func;
|
||||
func = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// PrepareSingleHistoFFTwInputData
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
*/
|
||||
void PFourier::PrepareSingleHistoFFTwInputData(unsigned int apodizationTag)
|
||||
{
|
||||
// 1st fill fIn
|
||||
unsigned int start = (unsigned int)(fStartTime/fTimeResolution);
|
||||
for (unsigned int i=0; i<fNoOfData-start; i++) {
|
||||
fIn[i][0] = fData->GetBinContent(i+start+1);
|
||||
fIn[i][1] = 0.0;
|
||||
}
|
||||
for (unsigned int i=fNoOfData; i<fNoOfBins; i++) {
|
||||
fIn[i][0] = 0.0;
|
||||
fIn[i][1] = 0.0;
|
||||
}
|
||||
|
||||
// 2nd subtract the Bkg from the data
|
||||
for (unsigned int i=0; i<fNoOfData; i++)
|
||||
fIn[i][0] -= fBkg;
|
||||
|
||||
// 3rd remove the lifetime term
|
||||
for (unsigned int i=0; i<fNoOfData; i++)
|
||||
fIn[i][0] *= exp((start+i)*fTimeResolution/(PMUON_LIFETIME*1000.0));
|
||||
|
||||
// 4th remove the constant N0 term
|
||||
for (unsigned int i=0; i<fNoOfData; i++)
|
||||
fIn[i][0] -= fN0;
|
||||
|
||||
// 5th apodize data (if wished)
|
||||
ApodizeData(apodizationTag);
|
||||
return phaseFourier;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -347,8 +353,17 @@ void PFourier::PrepareSingleHistoFFTwInputData(unsigned int apodizationTag)
|
||||
*/
|
||||
void PFourier::PrepareFFTwInputData(unsigned int apodizationTag)
|
||||
{
|
||||
// 1st fill fIn
|
||||
unsigned int start = (unsigned int)(fStartTime/fTimeResolution);
|
||||
// 1st find t==0. fData start at times t<0!!
|
||||
int t0bin = -1;
|
||||
for (int i=0; i<fData->GetNbinsX(); i++) {
|
||||
if (fData->GetBinCenter(i) >= 0.0) {
|
||||
t0bin = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 2nd fill fIn
|
||||
unsigned int start = (unsigned int)(fStartTime/fTimeResolution) + t0bin;
|
||||
for (unsigned int i=0; i<fNoOfData-start; i++) {
|
||||
fIn[i][0] = fData->GetBinContent(i+start+1);
|
||||
fIn[i][1] = 0.0;
|
||||
@ -358,7 +373,7 @@ void PFourier::PrepareFFTwInputData(unsigned int apodizationTag)
|
||||
fIn[i][1] = 0.0;
|
||||
}
|
||||
|
||||
// 2nd apodize data (if wished)
|
||||
// 3rd apodize data (if wished)
|
||||
ApodizeData(apodizationTag);
|
||||
}
|
||||
|
||||
|
@ -689,7 +689,7 @@ int PMsrHandler::WriteMsrLogFile()
|
||||
}
|
||||
|
||||
// write 'fourier_power' parameter if present
|
||||
if (fFourier.fFourierPower != 0) {
|
||||
if (fFourier.fFourierPower >= 0) {
|
||||
f << endl << "fourier_power " << fFourier.fFourierPower;
|
||||
CheckAndWriteComment(f, ++lineNo);
|
||||
}
|
||||
@ -1800,14 +1800,14 @@ bool PMsrHandler::HandleCommandsEntry(PMsrLines &lines)
|
||||
void PMsrHandler::InitFourierParameterStructure(PMsrFourierStructure &fourier)
|
||||
{
|
||||
fourier.fFourierBlockPresent = false; // fourier block present
|
||||
fourier.fUnits = FOURIER_UNIT_NOT_GIVEN; // fourier untis in field, i.e. Gauss
|
||||
fourier.fFourierPower = 0; // no zero padding
|
||||
fourier.fApodization = FOURIER_APOD_NOT_GIVEN; // no apodization
|
||||
fourier.fPlotTag = FOURIER_PLOT_NOT_GIVEN; // initial plot tag: show real and imaginary part at once
|
||||
fourier.fPhase = -999.0; // fourier phase
|
||||
fourier.fUnits = FOURIER_UNIT_NOT_GIVEN; // fourier untis, default: NOT GIVEN
|
||||
fourier.fFourierPower = -1; // zero padding, default: -1 = NOT GIVEN
|
||||
fourier.fApodization = FOURIER_APOD_NOT_GIVEN; // apodization, default: NOT GIVEN
|
||||
fourier.fPlotTag = FOURIER_PLOT_NOT_GIVEN; // initial plot tag, default: NOT GIVEN
|
||||
fourier.fPhase = -999.0; // fourier phase: -999 = NOT GIVEN
|
||||
for (unsigned int i=0; i<2; i++) {
|
||||
fourier.fRangeForPhaseCorrection[i] = -1.0; // frequency range for phase correction
|
||||
fourier.fPlotRange[i] = -1.0; // fourier plot range
|
||||
fourier.fRangeForPhaseCorrection[i] = -1.0; // frequency range for phase correction, default: {-1, -1} = NOT GIVEN
|
||||
fourier.fPlotRange[i] = -1.0; // fourier plot range, default: {-1, -1} = NOT GIVEN
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ using namespace std;
|
||||
#include <TObjString.h>
|
||||
|
||||
#include "PMusrCanvas.h"
|
||||
#include "PFourier.h"
|
||||
|
||||
ClassImpQ(PMusrCanvas)
|
||||
|
||||
@ -68,6 +69,8 @@ PMusrCanvas::PMusrCanvas()
|
||||
fDataTheoryPad = 0;
|
||||
fParameterTheoryPad = 0;
|
||||
fInfoPad = 0;
|
||||
|
||||
InitFourier();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -80,6 +83,7 @@ PMusrCanvas::PMusrCanvas(const int number, const char* title,
|
||||
Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh) :
|
||||
fPlotNumber(number)
|
||||
{
|
||||
InitFourier();
|
||||
CreateStyle();
|
||||
InitMusrCanvas(title, wtopx, wtopy, ww, wh);
|
||||
}
|
||||
@ -92,7 +96,7 @@ PMusrCanvas::PMusrCanvas(const int number, const char* title,
|
||||
*/
|
||||
PMusrCanvas::PMusrCanvas(const int number, const char* title,
|
||||
Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh,
|
||||
PMsrFourierStructure* fourierDefault,
|
||||
PMsrFourierStructure fourierDefault,
|
||||
const PIntVector markerList, const PIntVector colorList) :
|
||||
fPlotNumber(number), fFourier(fourierDefault),
|
||||
fMarkerList(markerList), fColorList(colorList)
|
||||
@ -150,6 +154,68 @@ cout << "~PMusrCanvas() called. fMainCanvas name=" << fMainCanvas->GetName() <<
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// InitFourier
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Initializes the Fourier structure.
|
||||
*/
|
||||
void PMusrCanvas::InitFourier()
|
||||
{
|
||||
fFourier.fFourierBlockPresent = false; // fourier block present
|
||||
fFourier.fUnits = FOURIER_UNIT_FIELD; // fourier untis
|
||||
fFourier.fFourierPower = 0; // no zero padding
|
||||
fFourier.fApodization = FOURIER_APOD_NONE; // no apodization
|
||||
fFourier.fPlotTag = FOURIER_PLOT_REAL_AND_IMAG; // initial plot tag, plot real and imaginary part
|
||||
fFourier.fPhase = 0.0; // fourier phase 0°
|
||||
for (unsigned int i=0; i<2; i++) {
|
||||
fFourier.fRangeForPhaseCorrection[i] = -1.0; // frequency range for phase correction, default: {-1, -1} = NOT GIVEN
|
||||
fFourier.fPlotRange[i] = -1.0; // fourier plot range, default: {-1, -1} = NOT GIVEN
|
||||
}
|
||||
fFourier.fPhaseIncrement = 1.0; // fourier phase increment
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// SetMsrHandler
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Keep the msr-handler object pointer and fill the Fourier structure if present.
|
||||
*/
|
||||
void PMusrCanvas::SetMsrHandler(PMsrHandler *msrHandler)
|
||||
{
|
||||
fMsrHandler = msrHandler;
|
||||
|
||||
// check if a fourier block is present in the msr-file, and if yes extract the given values
|
||||
if (fMsrHandler->GetMsrFourierList().fFourierBlockPresent) {
|
||||
fFourier.fFourierBlockPresent = true;
|
||||
if (fMsrHandler->GetMsrFourierList().fUnits != FOURIER_UNIT_NOT_GIVEN) {
|
||||
fFourier.fUnits = fMsrHandler->GetMsrFourierList().fUnits;
|
||||
}
|
||||
if (fMsrHandler->GetMsrFourierList().fFourierPower != -1) {
|
||||
fFourier.fFourierPower = fMsrHandler->GetMsrFourierList().fFourierPower;
|
||||
}
|
||||
if (fMsrHandler->GetMsrFourierList().fApodization != FOURIER_APOD_NOT_GIVEN) {
|
||||
fFourier.fApodization = fMsrHandler->GetMsrFourierList().fApodization;
|
||||
}
|
||||
if (fMsrHandler->GetMsrFourierList().fPlotTag != FOURIER_PLOT_NOT_GIVEN) {
|
||||
fFourier.fPlotTag = fMsrHandler->GetMsrFourierList().fPlotTag;
|
||||
}
|
||||
if (fMsrHandler->GetMsrFourierList().fPhase != -999.0) {
|
||||
fFourier.fPhase = fMsrHandler->GetMsrFourierList().fPhase;
|
||||
}
|
||||
if ((fMsrHandler->GetMsrFourierList().fRangeForPhaseCorrection[0] != -1.0) &&
|
||||
(fMsrHandler->GetMsrFourierList().fRangeForPhaseCorrection[1] != -1.0)) {
|
||||
fFourier.fRangeForPhaseCorrection[0] = fMsrHandler->GetMsrFourierList().fRangeForPhaseCorrection[0];
|
||||
fFourier.fRangeForPhaseCorrection[1] = fMsrHandler->GetMsrFourierList().fRangeForPhaseCorrection[1];
|
||||
}
|
||||
if ((fMsrHandler->GetMsrFourierList().fPlotRange[0] != -1.0) &&
|
||||
(fMsrHandler->GetMsrFourierList().fPlotRange[1] != -1.0)) {
|
||||
fFourier.fPlotRange[0] = fMsrHandler->GetMsrFourierList().fPlotRange[0];
|
||||
fFourier.fPlotRange[1] = fMsrHandler->GetMsrFourierList().fPlotRange[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// CreateStyle
|
||||
//--------------------------------------------------------------------------
|
||||
@ -334,9 +400,9 @@ void PMusrCanvas::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected)
|
||||
cout << endl << ">> will show the Fourier transform, to be implemented yet." << endl;
|
||||
}
|
||||
} else if (x == '+') {
|
||||
cout << endl << ">> if Fourier is shown, will add " << fFourier->fPhaseIncerement << "° to the Fourier." << endl;
|
||||
cout << endl << ">> if Fourier is shown, will add " << fFourier.fPhaseIncrement << "° to the Fourier." << endl;
|
||||
} else if (x == '-') {
|
||||
cout << endl << ">> if Fourier is shown, will subtract " << fFourier->fPhaseIncerement << "° to the Fourier." << endl;
|
||||
cout << endl << ">> if Fourier is shown, will subtract " << fFourier.fPhaseIncrement << "° to the Fourier." << endl;
|
||||
} else {
|
||||
// do all the necessary stuff **TO BE DONE**
|
||||
fMainCanvas->Update();
|
||||
@ -373,9 +439,9 @@ void PMusrCanvas::HandleMenuPopup(Int_t id)
|
||||
fPopupFourier->CheckEntry(id);
|
||||
HandleFourier(FOURIER_PLOT_PHASE);
|
||||
} else if (id == P_MENU_ID_FOURIER+P_MENU_PLOT_OFFSET*fPlotNumber+P_MENU_ID_FOURIER_PHASE_PLUS) {
|
||||
cout << endl << ">> will add +1° Phase to the Fourier ..." << endl;
|
||||
cout << endl << ">> will add " << fFourier.fPhaseIncrement << "° Phase to the Fourier ..." << endl;
|
||||
} else if (id == P_MENU_ID_FOURIER+P_MENU_PLOT_OFFSET*fPlotNumber+P_MENU_ID_FOURIER_PHASE_MINUS) {
|
||||
cout << endl << ">> will add -1° Phase to the Fourier ..." << endl;
|
||||
cout << endl << ">> will subtract " << fFourier.fPhaseIncrement << "° Phase to the Fourier ..." << endl;
|
||||
} else if (id == P_MENU_ID_DIFFERENCE+P_MENU_PLOT_OFFSET*fPlotNumber) {
|
||||
if (fPopupMain->IsEntryChecked(id))
|
||||
fPopupMain->UnCheckEntry(id);
|
||||
@ -1124,7 +1190,7 @@ void PMusrCanvas::HandleDifference()
|
||||
for (unsigned int i=0; i<fData.size(); i++) {
|
||||
// create difference histos
|
||||
name = TString(fData[i].data->GetTitle()) + "_diff";
|
||||
cout << endl << ">> diff-name = " << name.Data() << endl;
|
||||
//cout << endl << ">> diff-name = " << name.Data() << endl;
|
||||
diffHisto = new TH1F(name, name, fData[i].data->GetNbinsX(),
|
||||
fData[i].data->GetXaxis()->GetXmin(),
|
||||
fData[i].data->GetXaxis()->GetXmax());
|
||||
@ -1174,7 +1240,7 @@ cout << endl << ">> diff-name = " << name.Data() << endl;
|
||||
|
||||
// create difference histos
|
||||
name = TString(fNonMusrData[i].data->GetTitle()) + "_diff";
|
||||
cout << endl << ">> diff-name = " << name.Data() << endl;
|
||||
//cout << endl << ">> diff-name = " << name.Data() << endl;
|
||||
diffHisto->SetNameTitle(name.Data(), name.Data());
|
||||
|
||||
// set marker and line color
|
||||
@ -1305,6 +1371,54 @@ Int_t PMusrCanvas::FindBin(const double x, TGraphErrors *graph)
|
||||
return bin;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// GetGlobalMaximum
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>returns the global maximum of a histogram
|
||||
*
|
||||
* \param histo
|
||||
*/
|
||||
double PMusrCanvas::GetGlobalMaximum(TH1F* histo)
|
||||
{
|
||||
if (histo == 0)
|
||||
return 0.0;
|
||||
|
||||
double max = histo->GetBinContent(1);
|
||||
double binContent;
|
||||
for (int i=2; i < histo->GetNbinsX(); i++) {
|
||||
binContent = histo->GetBinContent(i);
|
||||
if (max < binContent)
|
||||
max = binContent;
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// GetGlobalMinimum
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>returns the global minimum of a histogram
|
||||
*
|
||||
* \param histo
|
||||
*/
|
||||
double PMusrCanvas::GetGlobalMinimum(TH1F* histo)
|
||||
{
|
||||
if (histo == 0)
|
||||
return 0.0;
|
||||
|
||||
double min = histo->GetBinContent(1);
|
||||
double binContent;
|
||||
for (int i=2; i < histo->GetNbinsX(); i++) {
|
||||
binContent = histo->GetBinContent(i);
|
||||
if (min > binContent)
|
||||
min = binContent;
|
||||
}
|
||||
|
||||
return min;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// PlotData
|
||||
//--------------------------------------------------------------------------
|
||||
@ -1457,10 +1571,225 @@ cout << endl << ">> going to plot diff spectra ... (" << fData[0].diff->GetNbins
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \param fourierType flag showing if real-, imaginary-, power-, or phase-spectra are wished
|
||||
*/
|
||||
void PMusrCanvas::PlotFourier(int fourierType)
|
||||
void PMusrCanvas::PlotFourier()
|
||||
{
|
||||
cout << endl << ">> in PlotFourier() ..." << endl;
|
||||
|
||||
fDataTheoryPad->cd();
|
||||
|
||||
if (fPlotType < 0) // plot type not defined
|
||||
return;
|
||||
|
||||
if (fData.size() == 0) // no data to be plotted
|
||||
return;
|
||||
|
||||
// define x-axis title
|
||||
TString xAxisTitle("");
|
||||
if (fFourier.fUnits == FOURIER_UNIT_FIELD) {
|
||||
xAxisTitle = TString("Field (G)");
|
||||
} else if (fFourier.fUnits == FOURIER_UNIT_FREQ) {
|
||||
xAxisTitle = TString("Frequency (MHz)");
|
||||
} else if (fFourier.fUnits == FOURIER_UNIT_CYCLES) {
|
||||
xAxisTitle = TString("Frequency (Mc/s)");
|
||||
} else {
|
||||
xAxisTitle = TString("??");
|
||||
}
|
||||
|
||||
// plot data
|
||||
double min, max, binContent;
|
||||
switch (fCurrentPlotView) {
|
||||
case PV_FOURIER_REAL:
|
||||
//cout << endl << ">> fData[0].dataFourierRe->GetNbinsX() = " << fData[0].dataFourierRe->GetNbinsX();
|
||||
// plot first histo
|
||||
fData[0].dataFourierRe->Draw("pe");
|
||||
|
||||
// set x-range
|
||||
//cout << endl << ">> fPlotRange = " << fFourier.fPlotRange[0] << ", " << fFourier.fPlotRange[1];
|
||||
if ((fFourier.fPlotRange[0] != -1) && (fFourier.fPlotRange[1] != -1)) {
|
||||
min = fFourier.fPlotRange[0];
|
||||
max = fFourier.fPlotRange[1];
|
||||
} else {
|
||||
min = fData[0].dataFourierRe->GetBinLowEdge(1);
|
||||
max = fData[0].dataFourierRe->GetBinLowEdge(fData[0].dataFourierRe->GetNbinsX())+fData[0].dataFourierRe->GetBinWidth(1);
|
||||
}
|
||||
//cout << endl << ">> x-range: min, max = " << min << ", " << max;
|
||||
fData[0].dataFourierRe->GetXaxis()->SetRangeUser(min, max);
|
||||
|
||||
// set y-range
|
||||
// first find minimum/maximum of all histos
|
||||
min = GetGlobalMinimum(fData[0].dataFourierRe);
|
||||
max = GetGlobalMaximum(fData[0].dataFourierRe);
|
||||
//cout << endl << ">> y-range: min, max = " << min << ", " << max;
|
||||
for (unsigned int i=1; i<fData.size(); i++) {
|
||||
binContent = GetGlobalMinimum(fData[i].dataFourierRe);
|
||||
if (binContent < min)
|
||||
min = binContent;
|
||||
binContent = GetGlobalMaximum(fData[i].dataFourierRe);
|
||||
if (binContent > max)
|
||||
max = binContent;
|
||||
}
|
||||
fData[0].dataFourierRe->GetYaxis()->SetRangeUser(1.05*min, 1.05*max);
|
||||
//cout << endl << "-> min, max = " << min << ", " << max;
|
||||
|
||||
// set x-axis title
|
||||
fData[0].dataFourierRe->GetXaxis()->SetTitle(xAxisTitle.Data());
|
||||
|
||||
// set y-axis title
|
||||
fData[0].dataFourierRe->GetYaxis()->SetTitle("Real Fourier");
|
||||
|
||||
// plot all remaining data
|
||||
for (unsigned int i=1; i<fData.size(); i++) {
|
||||
fData[i].dataFourierRe->Draw("pesame");
|
||||
}
|
||||
|
||||
// plot theories
|
||||
for (unsigned int i=0; i<fData.size(); i++) {
|
||||
fData[i].theoryFourierRe->Draw("esame");
|
||||
}
|
||||
break;
|
||||
case PV_FOURIER_IMAG:
|
||||
// plot first histo
|
||||
fData[0].dataFourierIm->Draw("pe");
|
||||
|
||||
// set x-range
|
||||
if ((fFourier.fPlotRange[0] != -1) && (fFourier.fPlotRange[1] != -1)) {
|
||||
min = fFourier.fPlotRange[0];
|
||||
max = fFourier.fPlotRange[1];
|
||||
} else {
|
||||
min = fData[0].dataFourierIm->GetBinLowEdge(1);
|
||||
max = fData[0].dataFourierIm->GetBinLowEdge(fData[0].dataFourierIm->GetNbinsX())+fData[0].dataFourierIm->GetBinWidth(1);
|
||||
}
|
||||
fData[0].dataFourierIm->GetXaxis()->SetRangeUser(min, max);
|
||||
|
||||
// set y-range
|
||||
// first find minimum/maximum of all histos
|
||||
min = GetGlobalMinimum(fData[0].dataFourierIm);
|
||||
max = GetGlobalMaximum(fData[0].dataFourierIm);
|
||||
for (unsigned int i=1; i<fData.size(); i++) {
|
||||
binContent = GetGlobalMinimum(fData[i].dataFourierIm);
|
||||
if (binContent < min)
|
||||
min = binContent;
|
||||
binContent = GetGlobalMaximum(fData[i].dataFourierIm);
|
||||
if (binContent > max)
|
||||
max = binContent;
|
||||
}
|
||||
fData[0].dataFourierIm->GetYaxis()->SetRangeUser(1.05*min, 1.05*max);
|
||||
|
||||
// set x-axis title
|
||||
fData[0].dataFourierIm->GetXaxis()->SetTitle(xAxisTitle.Data());
|
||||
|
||||
// set y-axis title
|
||||
fData[0].dataFourierIm->GetYaxis()->SetTitle("Imaginary Fourier");
|
||||
|
||||
// plot all remaining data
|
||||
for (unsigned int i=1; i<fData.size(); i++) {
|
||||
fData[i].dataFourierIm->Draw("pesame");
|
||||
}
|
||||
|
||||
// plot theories
|
||||
for (unsigned int i=0; i<fData.size(); i++) {
|
||||
fData[i].theoryFourierIm->Draw("esame");
|
||||
}
|
||||
break;
|
||||
case PV_FOURIER_REAL_AND_IMAG:
|
||||
break;
|
||||
case PV_FOURIER_PWR:
|
||||
// plot first histo
|
||||
fData[0].dataFourierPwr->Draw("pe");
|
||||
|
||||
// set x-range
|
||||
if ((fFourier.fPlotRange[0] != -1) && (fFourier.fPlotRange[1] != -1)) {
|
||||
min = fFourier.fPlotRange[0];
|
||||
max = fFourier.fPlotRange[1];
|
||||
} else {
|
||||
min = fData[0].dataFourierPwr->GetBinLowEdge(1);
|
||||
max = fData[0].dataFourierPwr->GetBinLowEdge(fData[0].dataFourierPwr->GetNbinsX())+fData[0].dataFourierPwr->GetBinWidth(1);
|
||||
}
|
||||
fData[0].dataFourierPwr->GetXaxis()->SetRangeUser(min, max);
|
||||
|
||||
// set y-range
|
||||
// first find minimum/maximum of all histos
|
||||
min = GetGlobalMinimum(fData[0].dataFourierPwr);
|
||||
max = GetGlobalMaximum(fData[0].dataFourierPwr);
|
||||
for (unsigned int i=1; i<fData.size(); i++) {
|
||||
binContent = GetGlobalMinimum(fData[i].dataFourierPwr);
|
||||
if (binContent < min)
|
||||
min = binContent;
|
||||
binContent = GetGlobalMaximum(fData[i].dataFourierPwr);
|
||||
if (binContent > max)
|
||||
max = binContent;
|
||||
}
|
||||
fData[0].dataFourierPwr->GetYaxis()->SetRangeUser(1.05*min, 1.05*max);
|
||||
|
||||
// set x-axis title
|
||||
fData[0].dataFourierPwr->GetXaxis()->SetTitle(xAxisTitle.Data());
|
||||
|
||||
// set y-axis title
|
||||
fData[0].dataFourierPwr->GetYaxis()->SetTitle("Power Fourier");
|
||||
|
||||
// plot all remaining data
|
||||
for (unsigned int i=1; i<fData.size(); i++) {
|
||||
fData[i].dataFourierPwr->Draw("pesame");
|
||||
}
|
||||
|
||||
// plot theories
|
||||
for (unsigned int i=0; i<fData.size(); i++) {
|
||||
fData[i].theoryFourierPwr->Draw("esame");
|
||||
}
|
||||
break;
|
||||
case PV_FOURIER_PHASE:
|
||||
// plot first histo
|
||||
fData[0].dataFourierPhase->Draw("pe");
|
||||
|
||||
// set x-range
|
||||
if ((fFourier.fPlotRange[0] != -1) && (fFourier.fPlotRange[1] != -1)) {
|
||||
min = fFourier.fPlotRange[0];
|
||||
max = fFourier.fPlotRange[1];
|
||||
} else {
|
||||
min = fData[0].dataFourierPhase->GetBinLowEdge(1);
|
||||
max = fData[0].dataFourierPhase->GetBinLowEdge(fData[0].dataFourierPhase->GetNbinsX())+fData[0].dataFourierPhase->GetBinWidth(1);
|
||||
}
|
||||
fData[0].dataFourierPhase->GetXaxis()->SetRangeUser(min, max);
|
||||
|
||||
// set y-range
|
||||
// first find minimum/maximum of all histos
|
||||
min = GetGlobalMinimum(fData[0].dataFourierPhase);
|
||||
max = GetGlobalMaximum(fData[0].dataFourierPhase);
|
||||
for (unsigned int i=1; i<fData.size(); i++) {
|
||||
binContent = GetGlobalMinimum(fData[i].dataFourierPhase);
|
||||
if (binContent < min)
|
||||
min = binContent;
|
||||
binContent = GetGlobalMaximum(fData[i].dataFourierPhase);
|
||||
if (binContent > max)
|
||||
max = binContent;
|
||||
}
|
||||
fData[0].dataFourierPhase->GetYaxis()->SetRangeUser(1.05*min, 1.05*max);
|
||||
|
||||
// set x-axis title
|
||||
fData[0].dataFourierPhase->GetXaxis()->SetTitle(xAxisTitle.Data());
|
||||
|
||||
// set y-axis title
|
||||
fData[0].dataFourierPhase->GetYaxis()->SetTitle("Phase Fourier");
|
||||
|
||||
// plot all remaining data
|
||||
for (unsigned int i=1; i<fData.size(); i++) {
|
||||
fData[i].dataFourierPhase->Draw("pesame");
|
||||
}
|
||||
|
||||
// plot theories
|
||||
for (unsigned int i=0; i<fData.size(); i++) {
|
||||
fData[i].theoryFourierPhase->Draw("esame");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
fDataTheoryPad->Update();
|
||||
|
||||
fMainCanvas->cd();
|
||||
fMainCanvas->Update();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -2008,32 +2337,198 @@ void PMusrCanvas::SaveDataDb()
|
||||
*/
|
||||
void PMusrCanvas::HandleFourier(int tag)
|
||||
{
|
||||
if (fMsrHandler->GetMsrFourierList()->fFourierBlockPresent) {
|
||||
cout << endl << ">> fourier block in msr-file present" << endl;
|
||||
fFourier = fMsrHandler->GetMsrFourierList();
|
||||
}
|
||||
|
||||
// if fourier was invoked via the 'f' cmd key, take the default plot tag
|
||||
if (tag == -1) { // called via cmd key 'f'
|
||||
tag = fFourier->fPlotTag;
|
||||
tag = fFourier.fPlotTag;
|
||||
}
|
||||
|
||||
|
||||
// if the current view is a data plot, fourier needs to be calculated
|
||||
if (fCurrentPlotView == PV_DATA) {
|
||||
if (!fDifferenceView) { // data view
|
||||
// delete fourier components
|
||||
for (unsigned int i=0; i<fData.size(); i++) {
|
||||
if (fData[i].dataFourierRe != 0) {
|
||||
delete fData[i].dataFourierRe;
|
||||
fData[i].dataFourierRe = 0;
|
||||
}
|
||||
if (fData[i].dataFourierIm != 0) {
|
||||
delete fData[i].dataFourierIm;
|
||||
fData[i].dataFourierIm = 0;
|
||||
}
|
||||
if (fData[i].dataFourierPwr != 0) {
|
||||
delete fData[i].dataFourierPwr;
|
||||
fData[i].dataFourierPwr = 0;
|
||||
}
|
||||
if (fData[i].dataFourierPhase != 0) {
|
||||
delete fData[i].dataFourierPhase;
|
||||
fData[i].dataFourierPhase = 0;
|
||||
}
|
||||
if (fData[i].theoryFourierRe != 0) {
|
||||
delete fData[i].theoryFourierRe;
|
||||
fData[i].theoryFourierRe = 0;
|
||||
}
|
||||
if (fData[i].theoryFourierIm != 0) {
|
||||
delete fData[i].theoryFourierIm;
|
||||
fData[i].theoryFourierIm = 0;
|
||||
}
|
||||
if (fData[i].theoryFourierPwr != 0) {
|
||||
delete fData[i].theoryFourierPwr;
|
||||
fData[i].theoryFourierPwr = 0;
|
||||
}
|
||||
if (fData[i].theoryFourierPhase != 0) {
|
||||
delete fData[i].theoryFourierPhase;
|
||||
fData[i].theoryFourierPhase = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int bin;
|
||||
bin = fData[0].data->GetXaxis()->GetFirst();
|
||||
double startTime = fData[0].data->GetBinCenter(bin);
|
||||
bin = fData[0].data->GetXaxis()->GetLast();
|
||||
double endTime = fData[0].data->GetBinCenter(bin);
|
||||
//cout << endl << ">> startTime = " << startTime << ", endTime = " << endTime << endl;
|
||||
for (unsigned int i=0; i<fData.size(); i++) {
|
||||
// calculate fourier transform of the data
|
||||
PFourier fourierData(fData[i].data, fFourier.fUnits, startTime, endTime, fFourier.fFourierPower);
|
||||
if (!fourierData.IsValid()) {
|
||||
cout << endl << "**SEVERE ERROR** PMusrCanvas::HandleFourier: couldn't invoke PFourier to calculate the Fourier data ..." << endl;
|
||||
return;
|
||||
}
|
||||
fourierData.Transform(fFourier.fApodization);
|
||||
double scale;
|
||||
scale = sqrt(fData[0].data->GetBinWidth(1)/(endTime-startTime));
|
||||
cout << endl << ">> data scale = " << scale;
|
||||
// get real part of the data
|
||||
fData[i].dataFourierRe = fourierData.GetRealFourier(scale);
|
||||
//cout << endl << ">> i: " << i << ", fData[i].dataFourierRe = " << fData[i].dataFourierRe;
|
||||
// get imaginary part of the data
|
||||
fData[i].dataFourierIm = fourierData.GetImaginaryFourier(scale);
|
||||
// get power part of the data
|
||||
fData[i].dataFourierPwr = fourierData.GetPowerFourier(scale);
|
||||
// get phase part of the data
|
||||
fData[i].dataFourierPhase = fourierData.GetPhaseFourier();
|
||||
|
||||
// set marker and line color
|
||||
if (i < fColorList.size()) {
|
||||
fData[i].dataFourierRe->SetMarkerColor(fColorList[i]);
|
||||
fData[i].dataFourierRe->SetLineColor(fColorList[i]);
|
||||
fData[i].dataFourierIm->SetMarkerColor(fColorList[i]);
|
||||
fData[i].dataFourierIm->SetLineColor(fColorList[i]);
|
||||
fData[i].dataFourierPwr->SetMarkerColor(fColorList[i]);
|
||||
fData[i].dataFourierPwr->SetLineColor(fColorList[i]);
|
||||
fData[i].dataFourierPhase->SetMarkerColor(fColorList[i]);
|
||||
fData[i].dataFourierPhase->SetLineColor(fColorList[i]);
|
||||
} else {
|
||||
TRandom rand(i);
|
||||
Int_t color = TColor::GetColor((Int_t)rand.Integer(255), (Int_t)rand.Integer(255), (Int_t)rand.Integer(255));
|
||||
fData[i].dataFourierRe->SetMarkerColor(color);
|
||||
fData[i].dataFourierRe->SetLineColor(color);
|
||||
fData[i].dataFourierIm->SetMarkerColor(color);
|
||||
fData[i].dataFourierIm->SetLineColor(color);
|
||||
fData[i].dataFourierPwr->SetMarkerColor(color);
|
||||
fData[i].dataFourierPwr->SetLineColor(color);
|
||||
fData[i].dataFourierPhase->SetMarkerColor(color);
|
||||
fData[i].dataFourierPhase->SetLineColor(color);
|
||||
}
|
||||
// set marker size
|
||||
fData[i].dataFourierRe->SetMarkerSize(1);
|
||||
fData[i].dataFourierIm->SetMarkerSize(1);
|
||||
fData[i].dataFourierPwr->SetMarkerSize(1);
|
||||
fData[i].dataFourierPhase->SetMarkerSize(1);
|
||||
// set marker type
|
||||
if (i < fMarkerList.size()) {
|
||||
fData[i].dataFourierRe->SetMarkerStyle(fMarkerList[i]);
|
||||
fData[i].dataFourierIm->SetMarkerStyle(fMarkerList[i]);
|
||||
fData[i].dataFourierPwr->SetMarkerStyle(fMarkerList[i]);
|
||||
fData[i].dataFourierPhase->SetMarkerStyle(fMarkerList[i]);
|
||||
} else {
|
||||
TRandom rand(i);
|
||||
int marker = 20+(Int_t)rand.Integer(10);
|
||||
fData[i].dataFourierRe->SetMarkerStyle(marker);
|
||||
fData[i].dataFourierIm->SetMarkerStyle(marker);
|
||||
fData[i].dataFourierPwr->SetMarkerStyle(marker);
|
||||
fData[i].dataFourierPhase->SetMarkerStyle(marker);
|
||||
}
|
||||
|
||||
// calculate fourier transform of the theory
|
||||
int powerPad = (int)round(log((endTime-startTime)/fData[i].theory->GetBinWidth(1))/log(2))+3;
|
||||
cout << endl << ">> powerPad = " << powerPad;
|
||||
PFourier fourierTheory(fData[i].theory, fFourier.fUnits, startTime, endTime, powerPad);
|
||||
if (!fourierTheory.IsValid()) {
|
||||
cout << endl << "**SEVERE ERROR** PMusrCanvas::HandleFourier: couldn't invoke PFourier to calculate the Fourier theory ..." << endl;
|
||||
return;
|
||||
}
|
||||
fourierTheory.Transform(fFourier.fApodization);
|
||||
scale = sqrt(fData[0].theory->GetBinWidth(1)/(endTime-startTime)*fData[0].theory->GetBinWidth(1)/fData[0].data->GetBinWidth(1));
|
||||
cout << endl << ">> theory scale = " << scale << ", data.res/theory.res = " << fData[0].theory->GetBinWidth(1)/fData[0].data->GetBinWidth(1);
|
||||
// get real part of the data
|
||||
fData[i].theoryFourierRe = fourierTheory.GetRealFourier(scale);
|
||||
//cout << endl << ">> i: " << i << ", fData[i].dataFourierRe = " << fData[i].dataFourierRe;
|
||||
// get imaginary part of the data
|
||||
fData[i].theoryFourierIm = fourierTheory.GetImaginaryFourier(scale);
|
||||
// get power part of the data
|
||||
fData[i].theoryFourierPwr = fourierTheory.GetPowerFourier(scale);
|
||||
// get phase part of the data
|
||||
fData[i].theoryFourierPhase = fourierTheory.GetPhaseFourier();
|
||||
}
|
||||
} else { // calculate diff fourier
|
||||
// delete fourier components
|
||||
for (unsigned int i=0; i<fData.size(); i++) {
|
||||
if (fData[i].diffFourierRe != 0) {
|
||||
delete fData[i].diffFourierRe;
|
||||
fData[i].diffFourierRe = 0;
|
||||
}
|
||||
if (fData[i].diffFourierIm != 0) {
|
||||
delete fData[i].diffFourierIm;
|
||||
fData[i].diffFourierIm = 0;
|
||||
}
|
||||
if (fData[i].diffFourierPwr != 0) {
|
||||
delete fData[i].diffFourierPwr;
|
||||
fData[i].diffFourierPwr = 0;
|
||||
}
|
||||
if (fData[i].diffFourierPhase != 0) {
|
||||
delete fData[i].diffFourierPhase;
|
||||
fData[i].diffFourierPhase = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int plotView = -1;
|
||||
switch (tag) { // called via popup menu
|
||||
case FOURIER_PLOT_REAL:
|
||||
plotView = PV_FOURIER_REAL;
|
||||
cout << endl << ">> will handle Real Part Fourier ..." << endl;
|
||||
break;
|
||||
case FOURIER_PLOT_IMAG:
|
||||
plotView = PV_FOURIER_IMAG;
|
||||
cout << endl << ">> will handle Imaginary Part Fourier ..." << endl;
|
||||
break;
|
||||
case FOURIER_PLOT_REAL_AND_IMAG:
|
||||
plotView = PV_FOURIER_REAL_AND_IMAG;
|
||||
cout << endl << ">> will handle Real+Imaginary Part Fourier ..." << endl;
|
||||
break;
|
||||
case FOURIER_PLOT_POWER:
|
||||
plotView = PV_FOURIER_PWR;
|
||||
cout << endl << ">> will handle Power Fourier ..." << endl;
|
||||
break;
|
||||
case FOURIER_PLOT_PHASE:
|
||||
plotView = PV_FOURIER_PHASE;
|
||||
cout << endl << ">> will handle Phase Fourier ..." << endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (plotView == fCurrentPlotView) { // twice checked the same -> switch back to data view
|
||||
fCurrentPlotView = PV_DATA;
|
||||
// uncheck fourier menu entries
|
||||
fPopupFourier->UnCheckEntries();
|
||||
// plot data
|
||||
PlotData();
|
||||
} else { // plot fourier
|
||||
fCurrentPlotView = plotView;
|
||||
PlotFourier();
|
||||
}
|
||||
}
|
||||
|
@ -81,11 +81,11 @@ void PStartupHandler::OnStartDocument()
|
||||
fFourierDefaults.fApodization = FOURIER_APOD_NONE;
|
||||
fFourierDefaults.fPlotTag = FOURIER_PLOT_REAL_AND_IMAG;
|
||||
fFourierDefaults.fPhase = 0.0;
|
||||
fFourierDefaults.fRangeForPhaseCorrection[0] = 0.0;
|
||||
fFourierDefaults.fRangeForPhaseCorrection[1] = 0.0;
|
||||
fFourierDefaults.fPlotRange[0] = 0.0;
|
||||
fFourierDefaults.fPlotRange[1] = 0.0;
|
||||
fFourierDefaults.fPhaseIncerement = 1.0;
|
||||
fFourierDefaults.fRangeForPhaseCorrection[0] = -1.0;
|
||||
fFourierDefaults.fRangeForPhaseCorrection[1] = -1.0;
|
||||
fFourierDefaults.fPlotRange[0] = -1.0;
|
||||
fFourierDefaults.fPlotRange[1] = -1.0;
|
||||
fFourierDefaults.fPhaseIncrement = 1.0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -305,7 +305,7 @@ void PStartupHandler::OnCharacters(const char *str)
|
||||
case ePhaseIncrement:
|
||||
tstr = TString(str);
|
||||
if (tstr.IsFloat()) {
|
||||
fFourierDefaults.fPhaseIncerement = tstr.Atof();
|
||||
fFourierDefaults.fPhaseIncrement = tstr.Atof();
|
||||
} else {
|
||||
cout << endl << "PStartupHandler **WARNING** '" << str << "' is not a valid phase increment, will ignore it.";
|
||||
cout << endl;
|
||||
|
@ -34,53 +34,45 @@
|
||||
|
||||
#include "fftw3.h"
|
||||
|
||||
#define F_ESTIMATE_N0_AND_BKG true
|
||||
|
||||
#define F_SINGLE_HISTO_RAW 0
|
||||
#define F_SINGLE_HISTO 1
|
||||
#define F_ASYMMETRY 2
|
||||
|
||||
#define F_APODIZATION_NONE 0
|
||||
#define F_APODIZATION_WEAK 1
|
||||
#define F_APODIZATION_MEDIUM 2
|
||||
#define F_APODIZATION_STRONG 3
|
||||
|
||||
// gamma_muon / (2 pi) = 1.355342e-5 (GHz/G)
|
||||
#define F_GAMMA_BAR_MUON 1.355342e-5
|
||||
// gamma_muon / (2 pi) = 1.355342e-2 (MHz/G)
|
||||
#define F_GAMMA_BAR_MUON 1.355342e-2
|
||||
|
||||
class PFourier
|
||||
{
|
||||
public:
|
||||
PFourier(int dataType, TH1F *data,
|
||||
PFourier(TH1F *data, int unitTag,
|
||||
double startTime = 0.0, double endTime = 0.0,
|
||||
unsigned int zeroPaddingPower = 0,
|
||||
bool estimateN0AndBkg = false);
|
||||
unsigned int zeroPaddingPower = 0);
|
||||
virtual ~PFourier();
|
||||
|
||||
virtual void Transform(unsigned int apodizationTag = 0);
|
||||
|
||||
virtual double GetFieldResolution() { return fFieldResolution; }
|
||||
virtual void GetRealFourier(TH1F *realFourier);
|
||||
virtual void GetImaginaryFourier(TH1F *imaginaryFourier);
|
||||
virtual double GetResolution() { return fResolution; }
|
||||
virtual TH1F* GetRealFourier(const double scale = 1.0);
|
||||
virtual TH1F* GetImaginaryFourier(const double scale = 1.0);
|
||||
virtual TH1F* GetPowerFourier(const double scale = 1.0);
|
||||
virtual TH1F* GetPhaseFourier(const double scale = 1.0);
|
||||
|
||||
virtual bool IsValid() { return fValid; }
|
||||
|
||||
private:
|
||||
TH1F *fData;
|
||||
|
||||
bool fValid;
|
||||
int fUnitTag; ///< 1=Field Units (G), 2=Frequency Units (MHz), 3=Angular Frequency Units (Mc/s)
|
||||
|
||||
int fDataType; ///< 0=Single Histo Raw, 1=Single Histo Life Time Corrected, 2=Asymmetry
|
||||
int fApodization; ///< 0=none, 1=weak, 2=medium, 3=strong
|
||||
|
||||
double fN0;
|
||||
double fBkg;
|
||||
|
||||
double fTimeResolution;
|
||||
double fStartTime;
|
||||
double fEndTime;
|
||||
unsigned int fZeroPaddingPower;
|
||||
double fFieldResolution;
|
||||
|
||||
TH1F *fData;
|
||||
double fResolution;
|
||||
|
||||
unsigned int fNoOfData;
|
||||
unsigned int fNoOfBins;
|
||||
@ -88,10 +80,8 @@ class PFourier
|
||||
fftw_complex *fIn;
|
||||
fftw_complex *fOut;
|
||||
|
||||
virtual void PrepareSingleHistoFFTwInputData(unsigned int apodizationTag);
|
||||
virtual void PrepareFFTwInputData(unsigned int apodizationTag);
|
||||
virtual void ApodizeData(int apodizationTag);
|
||||
virtual void EstimateN0AndBkg();
|
||||
};
|
||||
|
||||
#endif // _PFOURIER_H_
|
||||
|
@ -59,7 +59,7 @@ class PMsrHandler
|
||||
virtual PMsrLines* GetMsrFunctions() { return &fFunctions; }
|
||||
virtual PMsrRunList* GetMsrRunList() { return &fRuns; }
|
||||
virtual PMsrLines* GetMsrCommands() { return &fCommands; }
|
||||
virtual PMsrFourierStructure* GetMsrFourierList() { return &fFourier; }
|
||||
virtual PMsrFourierStructure GetMsrFourierList() { return fFourier; }
|
||||
virtual PMsrPlotList* GetMsrPlotList() { return &fPlots; }
|
||||
virtual PMsrStatisticStructure* GetMsrStatistic() { return &fStatistic; }
|
||||
|
||||
|
@ -286,14 +286,14 @@ typedef vector<PMsrRunStructure> PMsrRunList;
|
||||
*/
|
||||
typedef struct {
|
||||
bool fFourierBlockPresent; ///< flag indicating if a Fourier block is present in the msr-file
|
||||
bool fUnits; ///< flag used to indicate the units. 0=field units (G); 1=frequency units (MHz)
|
||||
int fUnits; ///< flag used to indicate the units. 0=field units (G); 1=frequency units (MHz); 2=Mc/s
|
||||
int fFourierPower; ///< i.e. zero padding up to 2^fFourierPower, default = 0 which means NO zero padding
|
||||
int fApodization; ///< tag indicating the kind of apodization wished, 0=no appodization (default), 1=weak, 2=medium, 3=strong (for details see the docu)
|
||||
int fPlotTag; ///< tag used for initial plot. 0=real, 1=imaginary, 2=real & imaginary (default), 3=power, 4=phase
|
||||
double fPhase; ///< phase
|
||||
double fRangeForPhaseCorrection[2]; ///< field/frequency range for automatic phase correction
|
||||
double fPlotRange[2]; ///< field/frequency plot range
|
||||
double fPhaseIncerement; ///< phase increment for manual phase optimization
|
||||
double fPhaseIncrement; ///< phase increment for manual phase optimization
|
||||
} PMsrFourierStructure;
|
||||
|
||||
//-------------------------------------------------------------
|
||||
|
@ -149,14 +149,14 @@ class PMusrCanvas : public TObject, public TQObject
|
||||
Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh);
|
||||
PMusrCanvas(const int number, const char* title,
|
||||
Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh,
|
||||
PMsrFourierStructure *fourierDefault,
|
||||
PMsrFourierStructure fourierDefault,
|
||||
const PIntVector markerList, const PIntVector colorList);
|
||||
virtual ~PMusrCanvas();
|
||||
|
||||
virtual Bool_t IsValid() { return fValid; }
|
||||
|
||||
#ifndef __MAKECINT__
|
||||
virtual void SetMsrHandler(PMsrHandler *msrHandler) { fMsrHandler = msrHandler; }
|
||||
virtual void SetMsrHandler(PMsrHandler *msrHandler);
|
||||
virtual void SetRunListCollection(PRunListCollection *runList) { fRunList = runList; }
|
||||
#endif // __MAKECINT__
|
||||
|
||||
@ -200,11 +200,12 @@ class PMusrCanvas : public TObject, public TQObject
|
||||
PMusrCanvasDataList fData;
|
||||
PMusrCanvasNonMusrDataList fNonMusrData;
|
||||
|
||||
PMsrFourierStructure *fFourier;
|
||||
PMsrFourierStructure fFourier;
|
||||
PIntVector fMarkerList;
|
||||
PIntVector fColorList;
|
||||
|
||||
virtual void CreateStyle();
|
||||
virtual void InitFourier();
|
||||
virtual void InitMusrCanvas(const char* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh);
|
||||
virtual void InitDataSet(PMusrCanvasDataSet &dataSet);
|
||||
virtual void InitDataSet(PMusrCanvasNonMusrDataSet &dataSet);
|
||||
@ -219,9 +220,12 @@ class PMusrCanvas : public TObject, public TQObject
|
||||
virtual double CalculateDiff(const double x, const double y, TGraphErrors *theo);
|
||||
virtual Int_t FindBin(const double x, TGraphErrors *graph);
|
||||
|
||||
virtual double GetGlobalMaximum(TH1F* histo);
|
||||
virtual double GetGlobalMinimum(TH1F* histo);
|
||||
|
||||
virtual void PlotData();
|
||||
virtual void PlotDifference();
|
||||
virtual void PlotFourier(int fourierType);
|
||||
virtual void PlotFourier();
|
||||
|
||||
virtual void SaveDataAscii();
|
||||
virtual void SaveDataDb();
|
||||
|
@ -58,10 +58,10 @@ class PStartupHandler : public TObject, public TQObject
|
||||
|
||||
virtual void CheckLists();
|
||||
|
||||
virtual PMsrFourierStructure* GetFourierDefaults() { return &fFourierDefaults; }
|
||||
virtual const PStringVector GetDataPathList() const { return fDataPathList; }
|
||||
virtual const PIntVector GetMarkerList() const { return fMarkerList; }
|
||||
virtual const PIntVector GetColorList() const { return fColorList; }
|
||||
virtual PMsrFourierStructure GetFourierDefaults() { return fFourierDefaults; }
|
||||
virtual const PStringVector GetDataPathList() const { return fDataPathList; }
|
||||
virtual const PIntVector GetMarkerList() const { return fMarkerList; }
|
||||
virtual const PIntVector GetColorList() const { return fColorList; }
|
||||
|
||||
private:
|
||||
enum EKeyWords {eEmpty, eComment, eDataPath,
|
||||
|
Loading…
x
Reference in New Issue
Block a user