From a2844ad03de9eb04bc00d1314d456e18c629a169 Mon Sep 17 00:00:00 2001 From: nemu Date: Tue, 2 Jun 2009 07:58:33 +0000 Subject: [PATCH] first implementation of 'use_fit_ranges' and 'sub_ranges' in the PLOT block. Testing still to be performed. --- src/classes/PMsrHandler.cpp | 13 --- src/classes/PMusrCanvas.cpp | 166 ++++++++++++++++++++++++++++++------ src/include/PMusrCanvas.h | 2 + 3 files changed, 142 insertions(+), 39 deletions(-) diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index 26a878be..3337ff25 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -2471,24 +2471,12 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) delete tokens; tokens = 0; } -cout << endl << ">> PMsrHandler::HandlePlotEntry(): will eventually handle sub_ranges ..." << endl; -cout << endl << ">> time ranges: "; -for (unsigned int i=0; i 0) { - cout << endl << " >> y-range: " << param.fYmin[0] << ", " << param.fYmax[0]; -} -cout << endl; } else if (iter1->fLine.Contains("use_fit_ranges", TString::kIgnoreCase)) { param.fUseFitRanges = true; -cout << endl << ">> PMsrHandler::HandlePlotEntry(): will eventually use fit ranges for plotting ..." << endl; } else if (iter1->fLine.Contains("logx", TString::kIgnoreCase)) { param.fLogX = true; -cout << endl << ">> PMsrHandler::HandlePlotEntry(): will eventually plot log x-axis ..." << endl; } else if (iter1->fLine.Contains("logy", TString::kIgnoreCase)) { param.fLogY = true; -cout << endl << ">> PMsrHandler::HandlePlotEntry(): will eventually plot log y-axis ..." << endl; } else if (iter1->fLine.Contains("view_packing", TString::kIgnoreCase)) { tokens = iter1->fLine.Tokenize(" \t"); if (!tokens) { @@ -2511,7 +2499,6 @@ cout << endl << ">> PMsrHandler::HandlePlotEntry(): will eventually plot log y-a error = true; } } -cout << endl << ">> PMsrHandler::HandlePlotEntry(): will eventually handle view_packing = " << param.fViewPacking << endl; // clean up if (tokens) { diff --git a/src/classes/PMusrCanvas.cpp b/src/classes/PMusrCanvas.cpp index 464c17ed..695ef1f2 100644 --- a/src/classes/PMusrCanvas.cpp +++ b/src/classes/PMusrCanvas.cpp @@ -1357,11 +1357,13 @@ void PMusrCanvas::CleanupDataSet(PMusrCanvasNonMusrDataSet &dataSet) /** *

* - * \param runNo + * \param plotNo is the number of the histo within the run list (fPlotNumber is the number of the plot BLOCK) + * \param runNo is the number of the run * \param data */ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunData *data) { +//cout << endl << ">> PMusrCanvas::HandleDataSet(): start ...; plotNo = " << plotNo << ", fPlotNumber = " << fPlotNumber << ", runNo = " << runNo << endl; PMusrCanvasDataSet dataSet; TH1F *dataHisto; TH1F *theoHisto; @@ -1369,8 +1371,10 @@ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunDat TString name; double start; double end; + int size; InitDataSet(dataSet); +//cout << endl << ">> PMusrCanvas::HandleDataSet(): after InitDataSet ..." << endl; // dataHisto ------------------------------------------------------------- // create histo specific infos @@ -1380,14 +1384,50 @@ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunDat name += fPlotNumber; start = data->fDataTimeStart - data->fDataTimeStep/2.0; end = data->fDataTimeStart + data->fValue.size()*data->fDataTimeStep; + size = data->fValue.size(); + +//cout << endl << ">> PMusrCanvas::HandleDataSet(): after create histo info ..." << endl; + + // check if 'use_fit_range' plotting is whished + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fUseFitRanges) { + start = fMsrHandler->GetMsrRunList()->at(runNo).fFitRange[0] - data->fDataTimeStep/2.0; + end = fMsrHandler->GetMsrRunList()->at(runNo).fFitRange[1] + data->fDataTimeStep/2.0; + size = (int) ((end - start) / data->fDataTimeStep) + 1; + } + + // check if 'sub_ranges' plotting is whished + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin.size() > 1) { + start = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin[runNo] - data->fDataTimeStep/2.0; + end = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax[runNo] + data->fDataTimeStep/2.0; + size = (int) ((end - start) / data->fDataTimeStep) + 1; + } + +//cout << endl << ">> PMusrCanvas::HandleDataSet(): start = " << start << ", end = " << end << ", size = " << size << ", data->fDataTimeStep = " << data->fDataTimeStep << endl; // invoke histo - dataHisto = new TH1F(name, name, data->fValue.size(), start, end); + dataHisto = new TH1F(name, name, size, start, end); // fill histogram - for (unsigned int i=0; ifValue.size(); i++) { - dataHisto->SetBinContent(i+1, data->fValue[i]); - dataHisto->SetBinError(i+1, data->fError[i]); + // 1st calculate the bin-range according to the plot options + UInt_t startBin = 0; + UInt_t endBin = data->fValue.size(); + + // check if 'use_fit_range' plotting is whished + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fUseFitRanges) { + startBin = (UInt_t)((fMsrHandler->GetMsrRunList()->at(runNo).fFitRange[0] - data->fDataTimeStart)/data->fDataTimeStep); + endBin = (UInt_t)((fMsrHandler->GetMsrRunList()->at(runNo).fFitRange[1] - data->fDataTimeStart)/data->fDataTimeStep); + } +//cout << endl << ">> PMusrCanvas::HandleDataSet(): data: startBin = " << startBin << ", endBin = " << endBin << endl; + + // check if 'sub_ranges' plotting is whished + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin.size() > 1) { + startBin = (UInt_t)((fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin[runNo] - data->fDataTimeStart)/data->fDataTimeStep); + endBin = (UInt_t)((fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax[runNo] - data->fDataTimeStart)/data->fDataTimeStep); + } + + for (UInt_t i=startBin; iSetBinContent(i-startBin+1, data->fValue[i]); + dataHisto->SetBinError(i-startBin+1, data->fError[i]); } // set marker and line color @@ -1418,16 +1458,49 @@ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunDat name += fPlotNumber; start = data->fTheoryTimeStart - data->fTheoryTimeStep/2.0; end = data->fTheoryTimeStart + data->fTheory.size()*data->fTheoryTimeStep; + size = data->fTheory.size(); -//cout << endl << ">> start = " << start << ", end = " << end << endl; + // check if 'use_fit_range' plotting is whished + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fUseFitRanges) { + start = fMsrHandler->GetMsrRunList()->at(runNo).fFitRange[0] - data->fTheoryTimeStep/2.0; + end = fMsrHandler->GetMsrRunList()->at(runNo).fFitRange[1] + data->fTheoryTimeStep/2.0; + size = (int) ((end - start) / data->fTheoryTimeStep) + 1; + } + + // check if 'sub_ranges' plotting is whished + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin.size() > 1) { + start = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin[runNo] - data->fTheoryTimeStep/2.0; + end = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax[runNo] + data->fTheoryTimeStep/2.0; + size = (int) ((end - start) / data->fTheoryTimeStep) + 1; + } + +//cout << endl << ">> PMusrCanvas::HandleDataSet(): start = " << start << ", end = " << end << ", size = " << size << ", data->fTheoryTimeStep = " << data->fTheoryTimeStep << endl; // invoke histo - theoHisto = new TH1F(name, name, data->fTheory.size(), start, end); + theoHisto = new TH1F(name, name, size, start, end); // fill histogram - for (unsigned int i=0; ifTheory.size(); i++) { - theoHisto->SetBinContent(i+1, data->fTheory[i]); + startBin = 0; + endBin = data->fTheory.size(); + + // check if 'use_fit_range' plotting is whished + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fUseFitRanges) { + startBin = (UInt_t)((fMsrHandler->GetMsrRunList()->at(runNo).fFitRange[0] - data->fDataTimeStart)/data->fTheoryTimeStep); + endBin = (UInt_t)((fMsrHandler->GetMsrRunList()->at(runNo).fFitRange[1] - data->fDataTimeStart)/data->fTheoryTimeStep); } +//cout << endl << ">> PMusrCanvas::HandleDataSet(): theory: startBin = " << startBin << ", endBin = " << endBin << endl; + + // check if 'sub_ranges' plotting is whished + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin.size() > 1) { + startBin = (UInt_t)((fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin[runNo] -data->fDataTimeStart)/data->fTheoryTimeStep); + endBin = (UInt_t)((fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax[runNo] -data->fDataTimeStart)/data->fTheoryTimeStep); + } + + for (UInt_t i=startBin; iSetBinContent(i-startBin+1, data->fTheory[i]); + } + +//cout << endl << ">> PMusrCanvas::HandleDataSet(): after fill theory histo" << endl; // set the line color if (plotNo < fColorList.size()) { @@ -1443,6 +1516,9 @@ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunDat dataSet.theory = theoHisto; fData.push_back(dataSet); + +//cout << endl << ">> PMusrCanvas::HandleDataSet(): after data push_back"; +//cout << endl << ">> --------------------------------------- <<" << endl; } //-------------------------------------------------------------------------- @@ -2206,21 +2282,59 @@ void PMusrCanvas::PlotData() if (fPlotType != MSR_PLOT_NON_MUSR) { if (fData.size() > 0) { - fData[0].data->Draw("pe"); - // set time range if present - if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin.size() > 0) { - Double_t xmin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin[0]; - Double_t xmax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax[0]; - fData[0].data->GetXaxis()->SetRangeUser(xmin, xmax); + + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fUseFitRanges) { // use fit ranges + fXmin = fData[0].data->GetXaxis()->GetXmin(); + fXmax = fData[0].data->GetXaxis()->GetXmax(); + fYmin = fData[0].data->GetMinimum(); + fYmax = fData[0].data->GetMaximum(); + for (unsigned int i=1; iGetXaxis()->GetXmin() < fXmin) + fXmin = fData[i].data->GetXaxis()->GetXmin(); + if (fData[i].data->GetXaxis()->GetXmax() > fXmax) + fXmax = fData[i].data->GetXaxis()->GetXmax(); + if (fData[i].data->GetMinimum() < fYmin) + fYmin = fData[i].data->GetMinimum(); + if (fData[i].data->GetMaximum() > fYmax) + fYmax = fData[i].data->GetMaximum(); + } + } else if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin.size() > 1) { // sub range plot + fXmin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin[0]; + fXmax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax[0]; + fYmin = fData[0].data->GetMinimum(); + fYmax = fData[0].data->GetMaximum(); + for (unsigned int i=1; iGetMsrPlotList()->at(fPlotNumber).fTmin.size(); i++) { + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin[i] < fXmin) + fXmin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin[i]; + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax[i] > fXmax) + fXmax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax[i]; + } // check if it is necessary to set the y-axis range if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmin.size() > 0) { - Double_t ymin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmin[0]; - Double_t ymax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmax[0]; - fData[0].data->GetYaxis()->SetRangeUser(ymin, ymax); + fYmin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmin[0]; + fYmax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmax[0]; + } + } else { // standard range plot + // set time range if present + fXmin = fData[0].data->GetXaxis()->GetXmin(); + fXmax = fData[0].data->GetXaxis()->GetXmax(); + fYmin = fData[0].data->GetMinimum(); + fYmax = fData[0].data->GetMaximum(); + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin.size() > 0) { + fXmin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin[0]; + fXmax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax[0]; + // check if it is necessary to set the y-axis range + if (fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmin.size() > 0) { + fYmin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmin[0]; + fYmax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmax[0]; + } } } + + TH1F *hframe = fDataTheoryPad->DrawFrame(fXmin, fYmin, fXmax, fYmax); + // set x-axis label - fData[0].data->GetXaxis()->SetTitle("time (#mus)"); + hframe->GetXaxis()->SetTitle("time (#mus)"); // set y-axis label TString yAxisTitle; PMsrRunList *runList = fMsrHandler->GetMsrRunList(); @@ -2240,9 +2354,9 @@ void PMusrCanvas::PlotData() yAxisTitle = "??"; break; } - fData[0].data->GetYaxis()->SetTitle(yAxisTitle.Data()); - // plot all remaining data - for (unsigned int i=1; iGetYaxis()->SetTitle(yAxisTitle.Data()); + // plot all data + for (unsigned int i=0; iDraw("pesame"); } // plot all the theory @@ -2351,13 +2465,13 @@ void PMusrCanvas::PlotDifference() if (fPlotType != MSR_PLOT_NON_MUSR) { //cout << endl << ">> PlotDifference(): going to plot diff spectra ... (" << fData[0].diff->GetNbinsX() << ")" << endl; - fData[0].diff->Draw("pe"); + TH1F *hframe = fDataTheoryPad->DrawFrame(fXmin, fYmin, fXmax, fYmax); // set x-axis label - fData[0].diff->GetXaxis()->SetTitle("time (#mus)"); + hframe->GetXaxis()->SetTitle("time (#mus)"); // set y-axis label - fData[0].diff->GetYaxis()->SetTitle("data-theory"); + hframe->GetYaxis()->SetTitle("data-theory"); // plot all remaining diff data - for (unsigned int i=1; iDraw("pesame"); } } else { // fPlotType == MSR_PLOT_NON_MUSR diff --git a/src/include/PMusrCanvas.h b/src/include/PMusrCanvas.h index 3104502e..76d846d9 100644 --- a/src/include/PMusrCanvas.h +++ b/src/include/PMusrCanvas.h @@ -182,6 +182,8 @@ class PMusrCanvas : public TObject, public TQObject Int_t fPlotType; Int_t fPlotNumber; + Double_t fXmin, fXmax, fYmin, fYmax; /// data/theory frame range + Double_t fCurrentFourierPhase; /// holds the current Fourier phase TLatex *fCurrentFourierPhaseText; /// used in Re/Im Fourier to show the current phase in the pad