From fe48da74a14963c3dc98709c5136d8cdab904691 Mon Sep 17 00:00:00 2001 From: Suter Andreas Date: Tue, 23 Feb 2016 13:22:41 +0100 Subject: [PATCH] It is now possible to export the averaged data/Fourier --- ChangeLog | 2 +- src/classes/PMusrCanvas.cpp | 754 +++++++++++++----------------------- src/include/PMusrCanvas.h | 5 +- 3 files changed, 274 insertions(+), 487 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd3ab127..4bbe7137 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,7 @@ changes since 0.17.0 =================================== - +NEW 2016-02-23 It is now possible to export the averaged data/Fourier changes since 0.16.0 =================================== diff --git a/src/classes/PMusrCanvas.cpp b/src/classes/PMusrCanvas.cpp index ec99e93a..54bcc51c 100644 --- a/src/classes/PMusrCanvas.cpp +++ b/src/classes/PMusrCanvas.cpp @@ -1516,7 +1516,6 @@ void PMusrCanvas::ExportData(const Char_t *fileName) Int_t xmaxBin; Double_t xmin; Double_t xmax; - Double_t time, freq; Double_t xval, yval; switch (fPlotType) { @@ -1533,29 +1532,12 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fHistoFrame->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get time - time = fData[i].diff->GetBinCenter(j); - // check if time is in the current range - if ((time >= xmin) && (time <= xmax)) { - dump.dataX.push_back(time); - dump.data.push_back(fData[i].diff->GetBinContent(j)); - dump.dataErr.push_back(fData[i].diff->GetBinError(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.diff, xmin, xmax, dumpVector); + } else { // go through all the histogramms + for (UInt_t i=0; i 0) - dumpVector.push_back(dump); } break; case PV_FOURIER_REAL: @@ -1566,28 +1548,12 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fData[0].diffFourierRe->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].diffFourierRe->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].diffFourierRe->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.diffFourierRe, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; i 0) - dumpVector.push_back(dump); } break; case PV_FOURIER_IMAG: @@ -1598,28 +1564,12 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fData[0].diffFourierIm->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].diffFourierIm->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].diffFourierIm->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.diffFourierIm, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; i 0) - dumpVector.push_back(dump); } break; case PV_FOURIER_REAL_AND_IMAG: @@ -1630,37 +1580,14 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fData[0].diffFourierRe->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].diffFourierRe->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].diffFourierRe->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.diffFourierRe, xmin, xmax, dumpVector, false); + GetExportDataSet(fDataAvg.diffFourierIm, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].diffFourierIm->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].diffFourierIm->GetBinContent(j)); - } - } - - // if anything found keep it - if (dump.dataX.size() > 0) - dumpVector.push_back(dump); } break; case PV_FOURIER_PWR: @@ -1671,28 +1598,12 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fData[0].diffFourierPwr->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].diffFourierPwr->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].diffFourierPwr->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.diffFourierPwr, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; i 0) - dumpVector.push_back(dump); } break; case PV_FOURIER_PHASE: @@ -1703,28 +1614,12 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fData[0].diffFourierPhase->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].diffFourierPhase->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].diffFourierPhase->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.diffFourierPhase, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; i 0) - dumpVector.push_back(dump); } break; default: @@ -1740,40 +1635,14 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fHistoFrame->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get time - time = fData[i].data->GetBinCenter(j); - // check if time is in the current range - if ((time >= xmin) && (time <= xmax)) { - dump.dataX.push_back(time); - dump.data.push_back(fData[i].data->GetBinContent(j)); - dump.dataErr.push_back(fData[i].data->GetBinError(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.data, xmin, xmax, dumpVector); + GetExportDataSet(fDataAvg.theory, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; iGetNbinsX(); j++) { - // get time - time = fData[i].theory->GetBinCenter(j); - // check if time is in the current range - if ((time >= xmin) && (time <= xmax)) { - dump.theoryX.push_back(time); - dump.theory.push_back(fData[i].theory->GetBinContent(j)); - } - } - - // if anything found keep it - if (dump.dataX.size() > 0) - dumpVector.push_back(dump); } break; @@ -1785,39 +1654,14 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fData[0].dataFourierRe->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].dataFourierRe->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].dataFourierRe->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.dataFourierRe, xmin, xmax, dumpVector, false); + GetExportDataSet(fDataAvg.theoryFourierRe, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].theoryFourierRe->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.theoryX.push_back(freq); - dump.theory.push_back(fData[i].theoryFourierRe->GetBinContent(j)); - } - } - - // if anything found keep it - if (dump.dataX.size() > 0) - dumpVector.push_back(dump); } break; case PV_FOURIER_IMAG: @@ -1828,39 +1672,14 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fData[0].dataFourierIm->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].dataFourierIm->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].dataFourierIm->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.dataFourierIm, xmin, xmax, dumpVector, false); + GetExportDataSet(fDataAvg.theoryFourierIm, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].theoryFourierIm->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.theoryX.push_back(freq); - dump.theory.push_back(fData[i].theoryFourierIm->GetBinContent(j)); - } - } - - // if anything found keep it - if (dump.dataX.size() > 0) - dumpVector.push_back(dump); } break; case PV_FOURIER_REAL_AND_IMAG: @@ -1870,80 +1689,18 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmin = fData[0].dataFourierRe->GetXaxis()->GetBinCenter(xminBin); xmax = fData[0].dataFourierRe->GetXaxis()->GetBinCenter(xmaxBin); - // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].dataFourierRe->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].dataFourierRe->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.dataFourierRe, xmin, xmax, dumpVector, false); + GetExportDataSet(fDataAvg.theoryFourierRe, xmin, xmax, dumpVector, false); + GetExportDataSet(fDataAvg.dataFourierIm, xmin, xmax, dumpVector, false); + GetExportDataSet(fDataAvg.theoryFourierIm, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].theoryFourierRe->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.theoryX.push_back(freq); - dump.theory.push_back(fData[i].theoryFourierRe->GetBinContent(j)); - } - } - - // if anything found keep it - if (dump.dataX.size() > 0) - dumpVector.push_back(dump); - - //----------------------------- - // Im - //----------------------------- - // clean up dump - dump.dataX.clear(); - dump.data.clear(); - dump.dataErr.clear(); - dump.theoryX.clear(); - dump.theory.clear(); - - // go through all data bins - for (Int_t j=1; jGetNbinsX(); j++) { - // get frequency - freq = fData[i].dataFourierIm->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].dataFourierIm->GetBinContent(j)); - } - } - - // go through all theory bins - for (Int_t j=1; jGetNbinsX(); j++) { - // get frequency - freq = fData[i].theoryFourierIm->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.theoryX.push_back(freq); - dump.theory.push_back(fData[i].theoryFourierIm->GetBinContent(j)); - } - } - - // if anything found keep it - if (dump.dataX.size() > 0) - dumpVector.push_back(dump); - } break; case PV_FOURIER_PWR: @@ -1954,39 +1711,14 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fData[0].dataFourierPwr->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].dataFourierPwr->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].dataFourierPwr->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.dataFourierPwr, xmin, xmax, dumpVector, false); + GetExportDataSet(fDataAvg.theoryFourierPwr, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].theoryFourierPwr->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.theoryX.push_back(freq); - dump.theory.push_back(fData[i].theoryFourierPwr->GetBinContent(j)); - } - } - - // if anything found keep it - if (dump.dataX.size() > 0) - dumpVector.push_back(dump); } break; case PV_FOURIER_PHASE: @@ -1997,39 +1729,14 @@ void PMusrCanvas::ExportData(const Char_t *fileName) xmax = fData[0].dataFourierPhase->GetXaxis()->GetBinCenter(xmaxBin); // fill ascii dump data - for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].dataFourierPhase->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.dataX.push_back(freq); - dump.data.push_back(fData[i].dataFourierPhase->GetBinContent(j)); - } + if (fAveragedView) { + GetExportDataSet(fDataAvg.dataFourierPhase, xmin, xmax, dumpVector, false); + GetExportDataSet(fDataAvg.theoryFourierPhase, xmin, xmax, dumpVector, false); + } else { // go through all the histogramms + for (UInt_t i=0; iGetNbinsX(); j++) { - // get frequency - freq = fData[i].theoryFourierPhase->GetBinCenter(j); - // check if time is in the current range - if ((freq >= xmin) && (freq <= xmax)) { - dump.theoryX.push_back(freq); - dump.theory.push_back(fData[i].theoryFourierPhase->GetBinContent(j)); - } - } - - // if anything found keep it - if (dump.dataX.size() > 0) - dumpVector.push_back(dump); } break; default: @@ -2053,8 +1760,6 @@ void PMusrCanvas::ExportData(const Char_t *fileName) dump.dataX.clear(); dump.data.clear(); dump.dataErr.clear(); - dump.theoryX.clear(); - dump.theory.clear(); // go through all data bins for (Int_t j=0; jGetN(); j++) { @@ -2102,8 +1807,6 @@ void PMusrCanvas::ExportData(const Char_t *fileName) dump.dataX.clear(); dump.data.clear(); dump.dataErr.clear(); - dump.theoryX.clear(); - dump.theory.clear(); // go through all data bins for (Int_t j=0; jGetN(); j++) { @@ -2123,8 +1826,8 @@ void PMusrCanvas::ExportData(const Char_t *fileName) fNonMusrData[i].theory->GetPoint(j,xval,yval); // check if time is in the current range if ((xval >= xmin) && (xval <= xmax)) { - dump.theoryX.push_back(xval); - dump.theory.push_back(yval); + dump.dataX.push_back(xval); + dump.data.push_back(yval); } } @@ -2164,72 +1867,95 @@ void PMusrCanvas::ExportData(const Char_t *fileName) } // find out what is the longest data/theory vector - UInt_t maxDataLength = 0; - UInt_t maxTheoryLength = 0; + UInt_t maxLength = 0; for (UInt_t i=0; i maxTheoryLength) - maxLength = maxDataLength; - else - maxLength = maxTheoryLength; - // write data and theory for (UInt_t i=0; i extract data for export. + * + * \param data + * \param xmin + * \param xmax + * \param dumpData + * \param hasError + */ +void PMusrCanvas::GetExportDataSet(const TH1F *data, const Double_t xmin, const Double_t xmax, + PMusrCanvasAsciiDumpVector &dumpData, const Bool_t hasError) +{ + PMusrCanvasAsciiDump dump; + Double_t x=0.0; + + // go through all difference data bins + for (Int_t j=1; jGetNbinsX(); j++) { + // get time/freq + x = data->GetBinCenter(j); + // check if x is in the current range + if ((x >= xmin) && (x <= xmax)) { + dump.dataX.push_back(x); + dump.data.push_back(data->GetBinContent(j)); + if (hasError) + dump.dataErr.push_back(data->GetBinError(j)); + } + } + + // if anything found keep it + if (dump.dataX.size() > 0) + dumpData.push_back(dump); +} + //-------------------------------------------------------------------------- // CreateStyle (private) //-------------------------------------------------------------------------- diff --git a/src/include/PMusrCanvas.h b/src/include/PMusrCanvas.h index 735af4f4..42e73dcc 100644 --- a/src/include/PMusrCanvas.h +++ b/src/include/PMusrCanvas.h @@ -181,8 +181,6 @@ typedef struct { PDoubleVector dataX; ///< x-axis data set PDoubleVector data; ///< y-axis data set PDoubleVector dataErr; ///< error of the y-axis data set - PDoubleVector theoryX; ///< x-axis theory set - PDoubleVector theory; ///< y-axis theory set } PMusrCanvasAsciiDump; //------------------------------------------------------------------------ @@ -333,6 +331,9 @@ class PMusrCanvas : public TObject, public TQObject virtual Double_t GetInterpolatedValue(TH1F* histo, Double_t xVal); + virtual void GetExportDataSet(const TH1F *data, const Double_t xmin, const Double_t xmax, + PMusrCanvasAsciiDumpVector &dumpData, const Bool_t hasError=true); + ClassDef(PMusrCanvas, 1) };