diff --git a/src/classes/PMusrCanvas.cpp b/src/classes/PMusrCanvas.cpp index 81b15743..6e426fea 100644 --- a/src/classes/PMusrCanvas.cpp +++ b/src/classes/PMusrCanvas.cpp @@ -3273,57 +3273,17 @@ void PMusrCanvas::DecrementFourierPhase() */ void PMusrCanvas::SaveDataAscii() { - // generate output filename + // collect relevant data + PMusrCanvasAsciiDump dump; + PMusrCanvasAsciiDumpVector dumpVector; - // in order to handle names with "." correctly this slightly odd data-filename generation - TObjArray *tokens = fMsrHandler->GetFileName().Tokenize("."); - TObjString *ostr; - TString str; - TString flnData = TString(""); - TString flnTheo = TString(""); - for (Int_t i=0; iGetEntries()-1; i++) { - ostr = dynamic_cast(tokens->At(i)); - flnData += ostr->GetString() + TString("."); - flnTheo += ostr->GetString() + TString("."); - } - if (!fDifferenceView) { - flnData += "data.ascii"; - } else { - flnData += "diff.ascii"; - } - flnTheo += "theo.ascii"; - - if (tokens) { - delete tokens; - tokens = 0; - } - - // open file - ofstream foutData; - ofstream foutTheo; - - // open output data-file - foutData.open(flnData.Data(), iostream::out); - if (!foutData.is_open()) { - cerr << endl << ">> PMusrCanvas::SaveDataAscii: **ERROR** couldn't open file " << flnData.Data() << " for writing." << endl; - return; - } - - if (!fDifferenceView) { - // open output theory-file - foutTheo.open(flnTheo.Data(), iostream::out); - if (!foutTheo.is_open()) { - cerr << endl << ">> PMusrCanvas::SaveDataAscii: **ERROR** couldn't open file " << flnTheo.Data() << " for writing." << endl; - return; - } - } - - // extract data - Double_t time, xval, yval; Int_t xminBin; Int_t xmaxBin; Double_t xmin; Double_t xmax; + Double_t time, freq; + Double_t xval, yval; + switch (fPlotType) { case MSR_PLOT_SINGLE_HISTO: case MSR_PLOT_ASYM: @@ -3331,39 +3291,206 @@ void PMusrCanvas::SaveDataAscii() if (fDifferenceView) { // difference view plot switch (fCurrentPlotView) { case PV_DATA: - // write header - foutData << "% time (us)"; - for (UInt_t j=0; jGetXaxis()->GetFirst(); // first bin of the zoomed range xmaxBin = fHistoFrame->GetXaxis()->GetLast(); // last bin of the zoomed range xmin = fHistoFrame->GetXaxis()->GetBinCenter(xminBin); xmax = fHistoFrame->GetXaxis()->GetBinCenter(xmaxBin); - // get difference data - for (Int_t i=1; iGetNbinsX()-1; i++) { - time = fData[0].diff->GetBinCenter(i); // get time - if ((time < xmin) || (time > xmax)) - continue; - foutData << time; - for (UInt_t j=0; jGetBinContent(i); - foutData << ", " << fData[j].diff->GetBinError(i); + + // 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)); + } } - foutData << endl; + + // if anything found keep it + if (dump.dataX.size() > 0) + dumpVector.push_back(dump); } break; case PV_FOURIER_REAL: + // get current x-range + xminBin = fData[0].diffFourierRe->GetXaxis()->GetFirst(); // first bin of the zoomed range + xmaxBin = fData[0].diffFourierRe->GetXaxis()->GetLast(); // last bin of the zoomed range + xmin = fData[0].diffFourierRe->GetXaxis()->GetBinCenter(xminBin); + 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 anything found keep it + if (dump.dataX.size() > 0) + dumpVector.push_back(dump); + } break; case PV_FOURIER_IMAG: + // get current x-range + xminBin = fData[0].diffFourierIm->GetXaxis()->GetFirst(); // first bin of the zoomed range + xmaxBin = fData[0].diffFourierIm->GetXaxis()->GetLast(); // last bin of the zoomed range + xmin = fData[0].diffFourierIm->GetXaxis()->GetBinCenter(xminBin); + 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 anything found keep it + if (dump.dataX.size() > 0) + dumpVector.push_back(dump); + } break; case PV_FOURIER_REAL_AND_IMAG: + // get current x-range + xminBin = fData[0].diffFourierRe->GetXaxis()->GetFirst(); // first bin of the zoomed range + xmaxBin = fData[0].diffFourierRe->GetXaxis()->GetLast(); // last bin of the zoomed range + xmin = fData[0].diffFourierRe->GetXaxis()->GetBinCenter(xminBin); + 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)); + } + } + for (Int_t j=1; jGetNbinsX(); 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: + // get current x-range + xminBin = fData[0].dataFourierPwr->GetXaxis()->GetFirst(); // first bin of the zoomed range + xmaxBin = fData[0].dataFourierPwr->GetXaxis()->GetLast(); // last bin of the zoomed range + xmin = fData[0].dataFourierPwr->GetXaxis()->GetBinCenter(xminBin); + 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 anything found keep it + if (dump.dataX.size() > 0) + dumpVector.push_back(dump); + } break; case PV_FOURIER_PHASE: + // get current x-range + xminBin = fData[0].dataFourierPhase->GetXaxis()->GetFirst(); // first bin of the zoomed range + xmaxBin = fData[0].dataFourierPhase->GetXaxis()->GetLast(); // last bin of the zoomed range + xmin = fData[0].dataFourierPhase->GetXaxis()->GetBinCenter(xminBin); + 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 anything found keep it + if (dump.dataX.size() > 0) + dumpVector.push_back(dump); + } break; default: break; @@ -3371,349 +3498,303 @@ void PMusrCanvas::SaveDataAscii() } else { // not a difference view plot switch (fCurrentPlotView) { case PV_DATA: - // write header - foutData << endl << "% timeData (us)"; - for (UInt_t j=0; jGetXaxis()->GetFirst(); // first bin of the zoomed range xmaxBin = fHistoFrame->GetXaxis()->GetLast(); // last bin of the zoomed range xmin = fHistoFrame->GetXaxis()->GetBinCenter(xminBin); xmax = fHistoFrame->GetXaxis()->GetBinCenter(xmaxBin); - // write data - for (Int_t i=1; iGetNbinsX()-1; i++) { - time = fData[0].data->GetBinCenter(i); // get time - if ((time < xmin) || (time > xmax)) - continue; - foutData << time << ", "; - for (UInt_t j=0; jGetBinContent(i) << ", "; - foutData << fData[j].data->GetBinError(i) << ", "; + + // 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)); + } } - // write last data set - foutData << fData[fData.size()-1].data->GetBinContent(i) << ", "; - foutData << fData[fData.size()-1].data->GetBinError(i) << ", "; - foutData << endl; + + // go through all theory bins + for (Int_t j=1; jGetNbinsX(); 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); } - // write theory - for (Int_t i=1; iGetNbinsX()-1; i++) { - time = fData[0].theory->GetBinCenter(i); // get time - if ((time < xmin) || (time > xmax)) - continue; - foutTheo << time << ", "; - for (UInt_t j=0; jGetBinContent(i) << ", "; - } - // write last data set - foutTheo << fData[fData.size()-1].theory->GetBinContent(i) << ", "; - foutTheo << endl; - } break; case PV_FOURIER_REAL: - // write header - str = TString("% "); - switch (fFourier.fUnits) { - case FOURIER_UNIT_FIELD: - str += TString(" Field (G)"); - break; - case FOURIER_UNIT_FREQ: - str += TString(" Frequency (MHz)"); - break; - case FOURIER_UNIT_CYCLES: - str += TString(" Angular Frequency (Mc/s)"); - break; - default: - str += TString(" ????"); - break; - } - foutData << str.Data(); - for (UInt_t j=0; jGetXaxis()->GetFirst(); // first bin of the zoomed range xmaxBin = fData[0].dataFourierRe->GetXaxis()->GetLast(); // last bin of the zoomed range xmin = fData[0].dataFourierRe->GetXaxis()->GetBinCenter(xminBin); xmax = fData[0].dataFourierRe->GetXaxis()->GetBinCenter(xmaxBin); - // write data - for (Int_t i=1; iGetNbinsX()-1; i++) { - xval = fData[0].dataFourierRe->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutData << xval; - for (UInt_t j=0; jGetBinContent(i); - } - foutData << endl; - } + // fill ascii dump data + for (UInt_t i=0; iGetNbinsX()-1; i++) { - xval = fData[0].theoryFourierRe->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutTheo << xval; - for (UInt_t j=0; jGetBinContent(i); + // go through all data bins + for (Int_t j=1; jGetNbinsX(); 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)); + } } - foutTheo << endl; + + // go through all theory bins + for (Int_t j=1; jGetNbinsX(); 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: - // write header - str = TString("% "); - switch (fFourier.fUnits) { - case FOURIER_UNIT_FIELD: - str += TString(" Field (G)"); - break; - case FOURIER_UNIT_FREQ: - str += TString(" Frequency (MHz)"); - break; - case FOURIER_UNIT_CYCLES: - str += TString(" Angular Frequency (Mc/s)"); - break; - default: - str += TString(" ????"); - break; - } - foutData << str.Data(); - for (UInt_t j=0; jGetXaxis()->GetFirst(); // first bin of the zoomed range xmaxBin = fData[0].dataFourierIm->GetXaxis()->GetLast(); // last bin of the zoomed range xmin = fData[0].dataFourierIm->GetXaxis()->GetBinCenter(xminBin); xmax = fData[0].dataFourierIm->GetXaxis()->GetBinCenter(xmaxBin); - // write data - for (Int_t i=1; iGetNbinsX()-1; i++) { - xval = fData[0].dataFourierIm->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutData << xval; - for (UInt_t j=0; jGetBinContent(i); - } - foutData << endl; - } + // fill ascii dump data + for (UInt_t i=0; iGetNbinsX()-1; i++) { - xval = fData[0].theoryFourierIm->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutTheo << xval; - for (UInt_t j=0; jGetBinContent(i); + // 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)); + } } - foutTheo << endl; + + // 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_REAL_AND_IMAG: - // write header - str = TString("% "); - switch (fFourier.fUnits) { - case FOURIER_UNIT_FIELD: - str += TString(" Field (G)"); - break; - case FOURIER_UNIT_FREQ: - str += TString(" Frequency (MHz)"); - break; - case FOURIER_UNIT_CYCLES: - str += TString(" Angular Frequency (Mc/s)"); - break; - default: - str += TString(" ????"); - break; - } - foutData << str.Data(); - for (UInt_t j=0; jGetXaxis()->GetFirst(); // first bin of the zoomed range xmaxBin = fData[0].dataFourierRe->GetXaxis()->GetLast(); // last bin of the zoomed range xmin = fData[0].dataFourierRe->GetXaxis()->GetBinCenter(xminBin); xmax = fData[0].dataFourierRe->GetXaxis()->GetBinCenter(xmaxBin); - // write data - for (Int_t i=1; iGetNbinsX()-1; i++) { - xval = fData[0].dataFourierRe->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutData << xval; - for (UInt_t j=0; jGetBinContent(i); - foutData << ", " << fData[j].dataFourierIm->GetBinContent(i); - } - foutData << endl; - } + // fill ascii dump data + for (UInt_t i=0; iGetNbinsX()-1; i++) { - xval = fData[0].theoryFourierRe->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutTheo << xval; - for (UInt_t j=0; jGetBinContent(i); - foutTheo << ", " << fData[j].theoryFourierIm->GetBinContent(i); + // go through all data bins + for (Int_t j=1; jGetNbinsX(); 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)); + } } - foutTheo << endl; + + // go through all theory bins + for (Int_t j=1; jGetNbinsX(); 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: - // write header - str = TString("% "); - switch (fFourier.fUnits) { - case FOURIER_UNIT_FIELD: - str += TString(" Field (G)"); - break; - case FOURIER_UNIT_FREQ: - str += TString(" Frequency (MHz)"); - break; - case FOURIER_UNIT_CYCLES: - str += TString(" Angular Frequency (Mc/s)"); - break; - default: - str += TString(" ????"); - break; - } - foutData << str.Data(); - for (UInt_t j=0; jGetXaxis()->GetFirst(); // first bin of the zoomed range xmaxBin = fData[0].dataFourierPwr->GetXaxis()->GetLast(); // last bin of the zoomed range xmin = fData[0].dataFourierPwr->GetXaxis()->GetBinCenter(xminBin); xmax = fData[0].dataFourierPwr->GetXaxis()->GetBinCenter(xmaxBin); - // write data - for (Int_t i=1; iGetNbinsX()-1; i++) { - xval = fData[0].dataFourierPwr->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutData << xval; - for (UInt_t j=0; jGetBinContent(i); - } - foutData << endl; - } + // fill ascii dump data + for (UInt_t i=0; iGetNbinsX()-1; i++) { - xval = fData[0].theoryFourierPwr->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutTheo << xval; - for (UInt_t j=0; jGetBinContent(i); + // go through all data bins + for (Int_t j=1; jGetNbinsX(); 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)); + } } - foutTheo << endl; + + // go through all theory bins + for (Int_t j=1; jGetNbinsX(); 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: - // write header - str = TString("% "); - switch (fFourier.fUnits) { - case FOURIER_UNIT_FIELD: - str += TString(" Field (G)"); - break; - case FOURIER_UNIT_FREQ: - str += TString(" Frequency (MHz)"); - break; - case FOURIER_UNIT_CYCLES: - str += TString(" Angular Frequency (Mc/s)"); - break; - default: - str += TString(" ????"); - break; - } - foutData << str.Data(); - for (UInt_t j=0; jGetXaxis()->GetFirst(); // first bin of the zoomed range xmaxBin = fData[0].dataFourierPhase->GetXaxis()->GetLast(); // last bin of the zoomed range xmin = fData[0].dataFourierPhase->GetXaxis()->GetBinCenter(xminBin); xmax = fData[0].dataFourierPhase->GetXaxis()->GetBinCenter(xmaxBin); - // write data - for (Int_t i=1; iGetNbinsX()-1; i++) { - xval = fData[0].dataFourierPhase->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutData << xval; - for (UInt_t j=0; jGetBinContent(i); - } - foutData << endl; - } + // fill ascii dump data + for (UInt_t i=0; iGetNbinsX()-1; i++) { - xval = fData[0].theoryFourierPhase->GetBinCenter(i); // get x-unit - if ((xval < xmin) || (xval > xmax)) - continue; - foutTheo << xval; - for (UInt_t j=0; jGetBinContent(i); + // go through all data bins + for (Int_t j=1; jGetNbinsX(); 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)); + } } - foutTheo << endl; + + // go through all theory bins + for (Int_t j=1; jGetNbinsX(); 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: @@ -3725,33 +3806,38 @@ void PMusrCanvas::SaveDataAscii() if (fDifferenceView) { // difference view plot switch (fCurrentPlotView) { case PV_DATA: - // write header - foutData << "% " << fNonMusrData[0].diff->GetXaxis()->GetTitle() << ", "; - for (UInt_t j=0; jGetXaxis()->GetFirst(); // first bin of the zoomed range - xmaxBin = fMultiGraphDiff->GetXaxis()->GetLast(); // last bin of the zoomed range - xmin = fMultiGraphDiff->GetXaxis()->GetBinCenter(xminBin); - xmax = fMultiGraphDiff->GetXaxis()->GetBinCenter(xmaxBin); + xminBin = fMultiGraphData->GetXaxis()->GetFirst(); // first bin of the zoomed range + xmaxBin = fMultiGraphData->GetXaxis()->GetLast(); // last bin of the zoomed range + xmin = fMultiGraphData->GetXaxis()->GetBinCenter(xminBin); + xmax = fMultiGraphData->GetXaxis()->GetBinCenter(xmaxBin); - // write data - for (Int_t i=0; iGetN(); i++) { - fNonMusrData[0].diff->GetPoint(i,xval,yval); // get values - if ((xval < xmin) || (xval > xmax)) - continue; - foutData << xval; - for (UInt_t j=0; jGetPoint(i,xval,yval); // get values - foutData << ", " << yval; - foutData << ", " << fNonMusrData[j].diff->GetErrorY(i); + // fill ascii dump data + for (UInt_t i=0; iGetN(); j++) { + // get x and y value + fNonMusrData[i].diff->GetPoint(j,xval,yval); + // check if time is in the current range + if ((xval >= xmin) && (xval <= xmax)) { + dump.dataX.push_back(xval); + dump.data.push_back(yval); + dump.dataErr.push_back(fNonMusrData[i].diff->GetErrorY(j)); + } } - foutData << endl; + + // if anything found keep it + if (dump.dataX.size() > 0) + dumpVector.push_back(dump); } + break; case PV_FOURIER_REAL: break; @@ -3769,51 +3855,49 @@ void PMusrCanvas::SaveDataAscii() } else { // not a difference view plot switch (fCurrentPlotView) { case PV_DATA: - // write header - foutData << "% " << fNonMusrData[0].data->GetXaxis()->GetTitle() << ", "; - for (UInt_t j=0; jGetXaxis()->GetTitle() << ", "; - for (UInt_t j=0; jGetXaxis()->GetFirst(); // first bin of the zoomed range xmaxBin = fMultiGraphData->GetXaxis()->GetLast(); // last bin of the zoomed range xmin = fMultiGraphData->GetXaxis()->GetBinCenter(xminBin); xmax = fMultiGraphData->GetXaxis()->GetBinCenter(xmaxBin); - // write data - for (Int_t i=0; iGetN(); i++) { - fNonMusrData[0].data->GetPoint(i,xval,yval); // get values - if ((xval < xmin) || (xval > xmax)) - continue; - foutData << xval; - for (UInt_t j=0; jGetPoint(i,xval,yval); // get values - foutData << ", " << yval; - foutData << ", " << fNonMusrData[j].data->GetErrorY(i); + // fill ascii dump data + for (UInt_t i=0; iGetN(); j++) { + // get x and y value + fNonMusrData[i].data->GetPoint(j,xval,yval); + // check if time is in the current range + if ((xval >= xmin) && (xval <= xmax)) { + dump.dataX.push_back(xval); + dump.data.push_back(yval); + dump.dataErr.push_back(fNonMusrData[i].data->GetErrorY(j)); + } } - foutData << endl; + + // go through all theory bins + for (Int_t j=1; jGetN(); j++) { + // get x and y value + 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); + } + } + + // if anything found keep it + if (dump.dataX.size() > 0) + dumpVector.push_back(dump); } - // write theory - for (Int_t i=0; iGetN(); i++) { - fNonMusrData[0].theory->GetPoint(i,xval,yval); // get values - if ((xval < xmin) || (xval > xmax)) - continue; - foutTheo << xval; - for (UInt_t j=0; jGetPoint(i,xval,yval); // get values - foutTheo << ", " << yval; - } - foutTheo << endl; - } break; case PV_FOURIER_REAL: break; @@ -3834,9 +3918,251 @@ void PMusrCanvas::SaveDataAscii() break; } + // generate output filename + + // in order to handle names with "." correctly this slightly odd data-filename generation + TObjArray *tokens = fMsrHandler->GetFileName().Tokenize("."); + TObjString *ostr; + TString str; + TString fln = TString(""); + for (Int_t i=0; iGetEntries()-1; i++) { + ostr = dynamic_cast(tokens->At(i)); + fln += ostr->GetString() + TString("."); + } + if (!fDifferenceView) { + fln += "data.ascii"; + } else { + fln += "diff.ascii"; + } + + if (tokens) { + delete tokens; + tokens = 0; + } + + // open file + ofstream fout; + + // open output data-file + fout.open(fln.Data(), iostream::out); + if (!fout.is_open()) { + cerr << endl << ">> PMusrCanvas::SaveDataAscii: **ERROR** couldn't open file " << fln.Data() << " for writing." << endl; + return; + } + + // find out what is the longest data/theory vector + UInt_t maxDataLength = 0; + UInt_t maxTheoryLength = 0; + for (UInt_t i=0; i 0) + fout << dumpVector[j].dataErr[i] << ", "; + } else { + if (dumpVector[j].dataErr.size() > 0) + fout << ", , , "; + else + fout << ", , "; + } + } + // write last difference entry + if (i 0) + fout << dumpVector[dumpVector.size()-1].dataErr[i]; + } else { + if (dumpVector[dumpVector.size()-1].dataErr.size() > 0) + fout << ", , "; + else + fout << ", "; + } + fout << endl; + } + } else { // no difference view + // write header + switch (fCurrentPlotView) { + case PV_DATA: + fout << "% "; + for (UInt_t i=0; i maxTheoryLength) + maxLength = maxDataLength; + else + maxLength = maxTheoryLength; + + // write data and theory + for (UInt_t i=0; i 0) + fout << dumpVector[j].dataErr[i] << ", "; + } else { + if (dumpVector[j].dataErr.size() > 0) + fout << ", , , "; + else + fout << ", , "; + } + } + // write theory + for (UInt_t j=0; j> Data windows saved in ascii format ..." << endl; } diff --git a/src/include/PMusrCanvas.h b/src/include/PMusrCanvas.h index 460d59ca..7e111a9e 100644 --- a/src/include/PMusrCanvas.h +++ b/src/include/PMusrCanvas.h @@ -138,6 +138,25 @@ typedef struct { */ typedef vector PMusrCanvasNonMusrDataList; +//------------------------------------------------------------------------ +/** + *

data structure needed for ascii dump within musrview. + */ +typedef struct { + PDoubleVector dataX; + PDoubleVector data; + PDoubleVector dataErr; + PDoubleVector theoryX; + PDoubleVector theory; +} PMusrCanvasAsciiDump; + +//------------------------------------------------------------------------ +/** + *

vectore of the above data structure. Used if there are multiple histogramms + * to be dumped. + */ +typedef vector PMusrCanvasAsciiDumpVector; + //-------------------------------------------------------------------------- /** *

The preprocessor tag __MAKECINT__ is used to hide away from rootcint