From f287ef666ce5ca14ea956567126e69838df2d7d7 Mon Sep 17 00:00:00 2001 From: nemu Date: Thu, 28 May 2009 08:49:42 +0000 Subject: [PATCH] added skeleton for some additional PLOT block commands. No functionality yet. --- src/Makefile | 4 +- src/classes/PMsrHandler.cpp | 179 +++++++++++++++--- src/classes/PMusrCanvas.cpp | 42 ++-- src/classes/PRunListCollection.cpp | 4 +- src/classes/PRunNonMusr.cpp | 10 +- src/include/PMusr.h | 12 +- src/tests/skewedGaussianTest/skewedGaussian.C | 10 +- 7 files changed, 198 insertions(+), 63 deletions(-) diff --git a/src/Makefile b/src/Makefile index 16537e0c..582f156c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -120,5 +120,5 @@ $(OBJS): %.o: %.cpp $(CXX) $(INCLUDES) $(CXXFLAGS) -c $< install: all - cp -p $(EXEC) $(INSTALLPATH) - cp -p musrfit_startup.xml $(INSTALLPATH) + cp -fp $(EXEC) $(INSTALLPATH) + cp -fp musrfit_startup.xml $(INSTALLPATH) diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index fd29b58f..20220fb5 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -796,9 +796,9 @@ int PMsrHandler::WriteMsrLogFile(const bool messages) } else if (sstr.BeginsWith("range")) { fout << "range "; fout.precision(2); - fout << fPlots[plotNo].fTmin << " " << fPlots[plotNo].fTmax; - if (fPlots[plotNo].fYmin != -999.0) { - fout << " " << fPlots[plotNo].fYmin << " " << fPlots[plotNo].fYmax; + fout << fPlots[plotNo].fTmin[0] << " " << fPlots[plotNo].fTmax[0]; + if (fPlots[plotNo].fYmin.size() > 0) { + fout << " " << fPlots[plotNo].fYmin[0] << " " << fPlots[plotNo].fYmax[0]; } fout << endl; } else { @@ -2234,10 +2234,10 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) // initialize param structure param.fPlotType = -1; - param.fTmin = -999.0; - param.fTmax = -999.0; - param.fYmin = -999.0; - param.fYmax = -999.0; + param.fUseFitRanges = false; // i.e. if not overwritten use the range info of the plot block + param.fLogX = false; // i.e. if not overwritten use linear x-axis + param.fLogY = false; // i.e. if not overwritten use linear y-axis + param.fViewPacking = -1; // i.e. if not overwritten use the packing of the run blocks // find next plot if any is present iter2 = iter1; @@ -2272,9 +2272,7 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) delete tokens; tokens = 0; } - } - - if (iter1->fLine.Contains("runs")) { // handle plot runs + } else if (iter1->fLine.Contains("runs", TString::kIgnoreCase)) { // handle plot runs TComplex run; switch (param.fPlotType) { case -1: @@ -2353,9 +2351,13 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) error = true; break; } - } + } else if (iter1->fLine.Contains("range ", TString::kIgnoreCase)) { // handle plot range + // remove previous entries + param.fTmin.clear(); + param.fTmax.clear(); + param.fYmin.clear(); + param.fYmax.clear(); - if (iter1->fLine.Contains("range")) { // handle plot range tokens = iter1->fLine.Tokenize(" \t"); if (!tokens) { cout << endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize PLOT in line " << iter1->fLineNo; @@ -2370,7 +2372,7 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) ostr = dynamic_cast(tokens->At(1)); str = ostr->GetString(); if (str.IsFloat()) - param.fTmin = (double)str.Atof(); + param.fTmin.push_back((double)str.Atof()); else error = true; @@ -2378,7 +2380,7 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) ostr = dynamic_cast(tokens->At(2)); str = ostr->GetString(); if (str.IsFloat()) - param.fTmax = (double)str.Atof(); + param.fTmax.push_back((double)str.Atof()); else error = true; @@ -2388,7 +2390,7 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) ostr = dynamic_cast(tokens->At(3)); str = ostr->GetString(); if (str.IsFloat()) - param.fYmin = (double)str.Atof(); + param.fYmin.push_back((double)str.Atof()); else error = true; @@ -2396,7 +2398,7 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) ostr = dynamic_cast(tokens->At(4)); str = ostr->GetString(); if (str.IsFloat()) - param.fYmax = (double)str.Atof(); + param.fYmax.push_back((double)str.Atof()); else error = true; } @@ -2406,6 +2408,117 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) delete tokens; tokens = 0; } + } else if (iter1->fLine.Contains("sub_ranges", TString::kIgnoreCase)) { + // remove previous entries + param.fTmin.clear(); + param.fTmax.clear(); + param.fYmin.clear(); + param.fYmax.clear(); + + tokens = iter1->fLine.Tokenize(" \t"); + if (!tokens) { + cout << endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize PLOT in line " << iter1->fLineNo; + cout << endl << endl; + return false; + } + if ((tokens->GetEntries() != (int)(2*param.fRuns.size() + 1)) && (tokens->GetEntries() != (int)(2*param.fRuns.size() + 3))) { + error = true; + } else { + // get all the times + for (unsigned int i=0; i(tokens->At(2*i+1)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fTmin.push_back((double)str.Atof()); + else + error = true; + + // handle t_max + ostr = dynamic_cast(tokens->At(2*i+2)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fTmax.push_back((double)str.Atof()); + else + error = true; + } + + // get y-range if present + if (tokens->GetEntries() == (int)(2*param.fRuns.size() + 3)) { + + // handle y_min + ostr = dynamic_cast(tokens->At(2*param.fRuns.size()+1)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fYmin.push_back((double)str.Atof()); + else + error = true; + + // handle y_max + ostr = dynamic_cast(tokens->At(2*param.fRuns.size()+2)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fYmax.push_back((double)str.Atof()); + else + error = true; + } + } + + // clean up + if (tokens) { + 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) { + cout << endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize PLOT in line " << iter1->fLineNo; + cout << endl << endl; + return false; + } + if (tokens->GetEntries() != 2) { + error = true; + } else { + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + int val = str.Atoi(); + if (val > 0) + param.fViewPacking = val; + else + error = true; + } else { + error = true; + } + } +cout << endl << ">> PMsrHandler::HandlePlotEntry(): will eventually handle view_packing = " << param.fViewPacking << endl; + + // clean up + if (tokens) { + delete tokens; + tokens = 0; + } + } else { + error = true; } ++iter1; @@ -2413,23 +2526,28 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) } // analyze if the plot block is valid + double keep; if (!error) { if (param.fRuns.empty()) { // there was no run tag error = true; } else { // everything ok - if ((param.fTmin != -999.0) || (param.fTmax != -999.0)) { // if range is given, check that it is ordered properly - if (param.fTmin > param.fTmax) { - double keep = param.fTmin; - param.fTmin = param.fTmax; - param.fTmax = keep; + if ((param.fTmin.size() > 0) || (param.fTmax.size() > 0)) { // if range is given, check that it is ordered properly + for (unsigned int i=0; i param.fTmax[i]) { + keep = param.fTmin[i]; + param.fTmin[i] = param.fTmax[i]; + param.fTmax[i] = keep; + } } } - if ((param.fYmin != -999.0) || (param.fYmax != -999.0)) { // if range is given, check that it is ordered properly - if (param.fYmin > param.fYmax) { - double keep = param.fYmin; - param.fYmin = param.fYmax; - param.fYmax = keep; + if ((param.fYmin.size() > 0) || (param.fYmax.size() > 0)) { // if range is given, check that it is ordered properly + for (unsigned int i=0; i param.fYmax[i]) { + keep = param.fYmin[i]; + param.fYmin[i] = param.fYmax[i]; + param.fYmax[i] = keep; + } } } @@ -2445,6 +2563,10 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) cout << endl << "PLOT "; cout << endl << "runs "; cout << endl << "[range tmin tmax [ymin ymax]]"; + cout << endl << "[sub_ranges tmin1 tmax1 tmin2 tmax2 ... tminN tmaxN [ymin ymax]"; + cout << endl << "[logx | logy]"; + cout << endl << "[use_fit_ranges]"; + cout << endl << "[view_packing n]"; cout << endl; cout << endl << "where is: 0=single histo asym,"; cout << endl << " 2=forward-backward asym,"; @@ -2457,6 +2579,11 @@ bool PMsrHandler::HandlePlotEntry(PMsrLines &lines) cout << endl << " imaginary one is 1=real part or 2=imag part, e.g."; cout << endl << " runs 1,1 1,2"; cout << endl << "range is optional"; + cout << endl << "sub_ranges (if present) will plot the N given runs each on its own sub-range"; + cout << endl << "logx, logy (if present) will present the x-, y-axis in log-scale"; + cout << endl << "use_fit_ranges (if present) will plot each run on its fit-range"; + cout << endl << "view_packing n (if present) will bin all data by n (> 0) rather than the binning of the fit"; + cout << endl; } param.fRuns.clear(); diff --git a/src/classes/PMusrCanvas.cpp b/src/classes/PMusrCanvas.cpp index c3388685..e7894659 100644 --- a/src/classes/PMusrCanvas.cpp +++ b/src/classes/PMusrCanvas.cpp @@ -2202,15 +2202,17 @@ void PMusrCanvas::PlotData() if (fPlotType != MSR_PLOT_NON_MUSR) { if (fData.size() > 0) { fData[0].data->Draw("pe"); - // set time range - Double_t xmin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin; - Double_t xmax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax; - fData[0].data->GetXaxis()->SetRangeUser(xmin, xmax); - // check if it is necessary to set the y-axis range - Double_t ymin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmin; - Double_t ymax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmax; - if ((ymin != -999.0) && (ymax != -999.0)) { - fData[0].data->GetYaxis()->SetRangeUser(ymin, ymax); + // 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); + // 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); + } } // set x-axis label fData[0].data->GetXaxis()->SetTitle("time (#mus)"); @@ -2276,16 +2278,18 @@ void PMusrCanvas::PlotData() fMultiGraphData->Draw("a"); // set x-range - Double_t xmin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin; - Double_t xmax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax; - fMultiGraphData->GetXaxis()->SetRangeUser(xmin, xmax); - // check if it is necessary to set the y-axis range - Double_t ymin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmin; - Double_t ymax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fYmax; - if ((ymin != -999.0) && (ymax != -999.0)) { - fMultiGraphData->GetYaxis()->SetRangeUser(ymin, ymax); - } else { - fMultiGraphData->GetYaxis()->UnZoom(); + 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]; + fMultiGraphData->GetXaxis()->SetRangeUser(xmin, xmax); + // 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]; + fMultiGraphData->GetYaxis()->SetRangeUser(ymin, ymax); + } else { + fMultiGraphData->GetYaxis()->UnZoom(); + } } // set x-, y-axis label only if there is just one data set diff --git a/src/classes/PRunListCollection.cpp b/src/classes/PRunListCollection.cpp index 3826c946..5a4166c8 100644 --- a/src/classes/PRunListCollection.cpp +++ b/src/classes/PRunListCollection.cpp @@ -338,7 +338,7 @@ PRunData* PRunListCollection::GetAsymmetry(unsigned int index, EDataSwitch tag) PRunData *data = 0; switch (tag) { - case kIndex: + case kIndex: // called from musrfit when dumping the data if ((index < 0) || (index > fRunAsymmetryList.size())) { cout << endl << "PRunListCollection::GetAsymmetry: index = " << index << " out of bounds"; return 0; @@ -347,7 +347,7 @@ PRunData* PRunListCollection::GetAsymmetry(unsigned int index, EDataSwitch tag) fRunAsymmetryList[index]->CalcTheory(); data = fRunAsymmetryList[index]->GetData(); break; - case kRunNo: + case kRunNo: // called from PMusrCanvas for (unsigned int i=0; iGetRunNo() == index) { data = fRunAsymmetryList[i]->GetData(); diff --git a/src/classes/PRunNonMusr.cpp b/src/classes/PRunNonMusr.cpp index e352ffb1..20586967 100644 --- a/src/classes/PRunNonMusr.cpp +++ b/src/classes/PRunNonMusr.cpp @@ -317,15 +317,15 @@ bool PRunNonMusr::PrepareViewData() if (fRunNo == plotBlock.fRuns[j].Re()-1) { // run found if (first) { first = false; - xMin = plotBlock.fTmin; - xMax = plotBlock.fTmax; + xMin = plotBlock.fTmin[0]; + xMax = plotBlock.fTmax[0]; xAbsMin = xMin; xAbsMax = xMax; // cout << endl << ">> first: xMin=" << xMin << ", xMax=" << xMax << endl; } else { - if (fabs(xMax-xMin) > fabs(plotBlock.fTmax-plotBlock.fTmin)) { - xMin = plotBlock.fTmin; - xMax = plotBlock.fTmax; + if (fabs(xMax-xMin) > fabs(plotBlock.fTmax[0]-plotBlock.fTmin[0])) { + xMin = plotBlock.fTmin[0]; + xMax = plotBlock.fTmax[0]; } if (xMin < xAbsMin) xAbsMin = xMin; diff --git a/src/include/PMusr.h b/src/include/PMusr.h index 30ad1990..fcbccf7b 100644 --- a/src/include/PMusr.h +++ b/src/include/PMusr.h @@ -301,11 +301,15 @@ typedef struct { */ typedef struct { int fPlotType; ///< plot type + bool fUseFitRanges; ///< yes -> use the fit ranges to plot the data, no (default) -> use range information if present + bool fLogX; ///< yes -> x-axis in log-scale, no (default) -> x-axis in lin-scale + bool fLogY; ///< yes -> y-axis in log-scale, no (default) -> y-axis in lin-scale + int fViewPacking; ///< -1 -> use the run packing to generate the view, otherwise is fViewPacking for the binning of ALL runs. PComplexVector fRuns; ///< list of runs to be plotted - double fTmin; ///< time minimum - double fTmax; ///< time maximum - double fYmin; ///< asymmetry/counts minimum - double fYmax; ///< asymmetry/counts maximum + PDoubleVector fTmin; ///< time minimum + PDoubleVector fTmax; ///< time maximum + PDoubleVector fYmin; ///< asymmetry/counts minimum + PDoubleVector fYmax; ///< asymmetry/counts maximum } PMsrPlotStructure; //------------------------------------------------------------- diff --git a/src/tests/skewedGaussianTest/skewedGaussian.C b/src/tests/skewedGaussianTest/skewedGaussian.C index 68048f53..08b9085f 100644 --- a/src/tests/skewedGaussianTest/skewedGaussian.C +++ b/src/tests/skewedGaussianTest/skewedGaussian.C @@ -42,11 +42,11 @@ void skewedGaussian() char fln[256]; const Double_t w = 1.0; // weight of the skewed Gaussian - const Double_t B0 = 30.0; // skewed Gaussian B0 (G) - const Double_t sm = 2.0; // skewed Gaussian sigma- (G) - const Double_t sp = 2.0; // skewed Gaussian sigma+ (G) + const Double_t B0 = 1000.0; // skewed Gaussian B0 (G) + const Double_t sm = 5.0; // skewed Gaussian sigma- (G) + const Double_t sp = 5.0; // skewed Gaussian sigma+ (G) - const Double_t B0ext = 30.0; // external field Gaussian B0 (G) + const Double_t B0ext = 1000.0; // external field Gaussian B0 (G) const Double_t sext = 10; // external field Gaussian sigma (G) sprintf(fln, "skewedGauss-B%0.2lf-sm%0.2lf-sp%0.2lf-w%0.1lf-Bext%0.2lf-sext%0.2lf.dat", @@ -54,7 +54,7 @@ void skewedGaussian() const Int_t noOfPoints = 8000; - const Double_t res = 0.1; + const Double_t res = 0.25; fp = fopen(fln, "w");