/*************************************************************************** PMusrCanvas.cpp Author: Andreas Suter e-mail: andreas.suter@psi.ch $Id$ ***************************************************************************/ /*************************************************************************** * Copyright (C) 2007 by Andreas Suter * * andreas.suter@psi.ch * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include using namespace std; #include #include #include #include "PMusrCanvas.h" ClassImpQ(PMusrCanvas) //-------------------------------------------------------------------------- // Constructor //-------------------------------------------------------------------------- /** * */ PMusrCanvas::PMusrCanvas() { fValid = false; fDifferencePlot = false; fPlotType = -1; fPlotNumber = -1; fStyle = 0; fMainCanvas = 0; fTitlePad = 0; fDataTheoryPad = 0; fParameterTheoryPad = 0; fInfoPad = 0; } //-------------------------------------------------------------------------- // Constructor //-------------------------------------------------------------------------- /** * */ PMusrCanvas::PMusrCanvas(const int number, const char* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh) : fPlotNumber(number) { CreateStyle(); InitMusrCanvas(title, wtopx, wtopy, ww, wh); } //-------------------------------------------------------------------------- // Constructor //-------------------------------------------------------------------------- /** * */ PMusrCanvas::PMusrCanvas(const int number, const char* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh, const PIntVector markerList, const PIntVector colorList) : fPlotNumber(number), fMarkerList(markerList), fColorList(colorList) { CreateStyle(); InitMusrCanvas(title, wtopx, wtopy, ww, wh); } //-------------------------------------------------------------------------- // Destructor //-------------------------------------------------------------------------- /** * */ PMusrCanvas::~PMusrCanvas() { cout << "~PMusrCanvas() called. fMainCanvas name=" << fMainCanvas->GetName() << endl; // cleanup if (fStyle) { delete fStyle; fStyle = 0; } if (fTitlePad) { fTitlePad->Clear(); delete fTitlePad; fTitlePad = 0; } if (fDataTheoryPad) { delete fDataTheoryPad; fDataTheoryPad = 0; } if (fParameterTheoryPad) { fParameterTheoryPad->Clear(); delete fParameterTheoryPad; fParameterTheoryPad = 0; } if (fInfoPad) { fInfoPad->Clear(); delete fInfoPad; fInfoPad = 0; } if (fMainCanvas) { delete fMainCanvas; fMainCanvas = 0; } if (fData.size() > 0) { for (unsigned int i=0; i 0) { for (unsigned int i=0; i Set styles for the canvas. Perhaps one could transfer them to the startup-file in the future. */ void PMusrCanvas::CreateStyle() { fStyle = new TStyle("musrStyle", "musrStyle"); fStyle->SetOptStat(0); // no statistics options fStyle->SetOptTitle(0); // no title fStyle->cd(); } //-------------------------------------------------------------------------- // InitMusrCanvas //-------------------------------------------------------------------------- /** *

* * \param title * \param wtopx * \param wtopy * \param ww * \param wh */ void PMusrCanvas::InitMusrCanvas(const char* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh) { fValid = false; fDifferencePlot = false; fPlotType = -1; fMainCanvas = 0; fTitlePad = 0; fDataTheoryPad = 0; fParameterTheoryPad = 0; fInfoPad = 0; // invoke canvas TString canvasName = TString("fMainCanvas"); canvasName += fPlotNumber; fMainCanvas = new TCanvas(canvasName.Data(), title, wtopx, wtopy, ww, wh); if (fMainCanvas == 0) { cout << endl << "PMusrCanvas::PMusrCanvas: **PANIC ERROR**: Couldn't invoke " << canvasName.Data(); cout << endl; return; } // divide the canvas into 4 pads // title pad fTitlePad = new TPaveText(0.0, YTITLE, 1.0, 1.0, "NDC"); if (fTitlePad == 0) { cout << endl << "PMusrCanvas::PMusrCanvas: **PANIC ERROR**: Couldn't invoke fTitlePad"; cout << endl; return; } fTitlePad->SetFillColor(TColor::GetColor(255,255,255)); fTitlePad->SetTextAlign(12); // middle, left fTitlePad->AddText(title); fTitlePad->Draw(); // data/theory pad fDataTheoryPad = new TPad("dataTheoryCanvas", "dataTheoryCanvas", 0.0, YINFO, XTHEO, YTITLE); if (fDataTheoryPad == 0) { cout << endl << "PMusrCanvas::PMusrCanvas: **PANIC ERROR**: Couldn't invoke fDataTheoryPad"; cout << endl; return; } fDataTheoryPad->SetFillColor(TColor::GetColor(255,255,255)); fDataTheoryPad->Draw(); // parameter/theory pad fParameterTheoryPad = new TPaveText(XTHEO, 0.1, 1.0, YTITLE, "NDC"); if (fParameterTheoryPad == 0) { cout << endl << "PMusrCanvas::PMusrCanvas: **PANIC ERROR**: Couldn't invoke fParameterTheoryPad"; cout << endl; return; } fParameterTheoryPad->SetFillColor(TColor::GetColor(255,255,255)); fParameterTheoryPad->SetTextAlign(13); // top, left fParameterTheoryPad->SetTextFont(102); // courier bold, scalable so that greek parameters will be plotted properly // info pad fInfoPad = new TLegend(0.0, 0.0, 1.0, YINFO, "NDC"); if (fInfoPad == 0) { cout << endl << "PMusrCanvas::PMusrCanvas: **PANIC ERROR**: Couldn't invoke fInfoPad"; cout << endl; return; } fInfoPad->SetFillColor(TColor::GetColor(255,255,255)); fInfoPad->SetTextAlign(12); // middle, left fValid = true; fMainCanvas->cd(); fMainCanvas->Show(); fMainCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "PMusrCanvas", this, "HandleCmdKey(Int_t,Int_t,Int_t,TObject*)"); // cout << "this " << this << endl; // cout << "fMainCanvas " << fMainCanvas << endl; // cout << "fTitlePad " << fTitlePad << endl; // cout << "fDataTheoryPad " << fDataTheoryPad << endl; // cout << "fParameterTheoryPad " << fParameterTheoryPad << endl; // cout << "fInfoPad " << fInfoPad << endl; } //-------------------------------------------------------------------------- // Done (SIGNAL) //-------------------------------------------------------------------------- /** *

* */ void PMusrCanvas::Done(Int_t status) { Emit("Done(Int_t)", status); } //-------------------------------------------------------------------------- // HandleCmdKey (SLOT) //-------------------------------------------------------------------------- /** *

* */ void PMusrCanvas::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected) { if (event != kKeyPress) return; // cout << ">this " << this << endl; // cout << ">fMainCanvas " << fMainCanvas << endl; // cout << ">selected " << selected << endl; // cout << "x : " << (char)x << endl; cout << "px: " << (char)fMainCanvas->GetEventX() << endl; if (x == 'q') { Done(0); } else if (x == 'd') { HandleDifference(); } else if (x == 'f') { cout << endl << ">> will show the Fourier transform, to be implemented yet." << endl; } else if (x == 'S') { cout << endl << ">> will save the shown data into a file, to be implemented yet." << endl; } else { // do all the necessary stuff **TO BE DONE** fMainCanvas->Update(); } } //-------------------------------------------------------------------------- // LastCanvasClosed (SLOT) //-------------------------------------------------------------------------- /** *

* */ void PMusrCanvas::LastCanvasClosed() { // cout << endl << ">> in last canvas closed check ..."; if (gROOT->GetListOfCanvases()->IsEmpty()) { Done(0); } } //-------------------------------------------------------------------------- // UpdateParamTheoryPad //-------------------------------------------------------------------------- /** *

*/ void PMusrCanvas::UpdateParamTheoryPad() { if (!fValid) return; TString str; char cnum[128]; int maxLength = 0; Double_t ypos; int idx; // add parameters ------------------------------------------------------------ PMsrParamList param = *fMsrHandler->GetMsrParamList(); // get maximal parameter name string length for (unsigned int i=0; i maxLength) maxLength = param[i].fName.Length(); } maxLength += 2; // add parameters to the pad for (unsigned int i=0; iAddText(0.03, ypos, str.Data()); } // add theory ------------------------------------------------------------ ypos -= 0.025; PMsrLines theory = *fMsrHandler->GetMsrTheory(); for (unsigned int i=1; i 0) { // comment present str.Resize(idx-1); str.Resize(str.Strip().Length()); } ypos -= 0.025; fParameterTheoryPad->AddText(0.03, ypos, str.Data()); } // add functions -------------------------------------------------------- ypos -= 0.025; PMsrLines functions = *fMsrHandler->GetMsrFunctions(); for (unsigned int i=1; iAddText(0.03, ypos, functions[i].fLine.Data()); } fParameterTheoryPad->Draw(); fMainCanvas->cd(); fMainCanvas->Update(); } //-------------------------------------------------------------------------- // UpdateDataTheoryPad //-------------------------------------------------------------------------- /** *

*/ void PMusrCanvas::UpdateDataTheoryPad() { /* // NonMusr axis titles TString xAxisTitle; TString yAxisTitle; */ // some checks first unsigned int runNo; PMsrPlotStructure plotInfo = fMsrHandler->GetMsrPlotList()->at(fPlotNumber); PMsrRunList runs = *fMsrHandler->GetMsrRunList(); fPlotType = plotInfo.fPlotType; for (unsigned int i=0; i (int)runs.size()) { fValid = false; cout << endl << "PMusrCanvas::UpdateDataTheoryPad: **ERROR** run plot number " << (int)plotInfo.fRuns[i].Re() << " is larger than the number of runs " << runs.size(); cout << endl; return; } // check that the plottype and the fittype do correspond runNo = (unsigned int)plotInfo.fRuns[i].Re()-1; cout << endl << ">> runNo = " << runNo; cout << endl; if (fPlotType != runs[runNo].fFitType) { fValid = false; cout << endl << "PMusrCanvas::UpdateDataTheoryPad: **ERROR** plottype = " << fPlotType << ", fittype = " << runs[runNo].fFitType << ", however they have to correspond!"; cout << endl; return; } /* // check if NonMusr type plot and if yes get x- and y-axis title if (fPlotType == MSR_PLOT_NON_MUSR) { xAxisTitle = fRunList->GetXAxisTitle(runs[runNo].fRunName); yAxisTitle = fRunList->GetYAxisTitle(runs[runNo].fRunName); } */ } PRunData *data; for (unsigned int i=0; iGetSingleHisto(runNo, PRunListCollection::kRunNo); if (!data) { // something wrong fValid = false; // error message cout << endl << "PMusrCanvas::UpdateDataTheoryPad: **ERROR** couldn't obtain run no " << runNo << " for a single histogram plot"; cout << endl; return; } // handle data HandleDataSet(i, runNo, data); break; case MSR_FITTYPE_ASYM: data = fRunList->GetAsymmetry(runNo, PRunListCollection::kRunNo); if (!data) { // something wrong fValid = false; // error message cout << endl << "PMusrCanvas::UpdateDataTheoryPad: **ERROR** couldn't obtain run no " << runNo << " for a asymmetry plot"; cout << endl; return; } // handle data HandleDataSet(i, runNo, data); break; case MSR_FITTYPE_ASYM_RRF: data = fRunList->GetRRF(runNo, PRunListCollection::kRunNo); if (!data) { // something wrong fValid = false; // error message cout << endl << "PMusrCanvas::UpdateDataTheoryPad: **ERROR** couldn't obtain run no " << runNo << " for a RRF plot"; cout << endl; return; } // handle data HandleDataSet(i, runNo, data); break; case MSR_FITTYPE_NON_MUSR: data = fRunList->GetNonMusr(runNo, PRunListCollection::kRunNo); if (!data) { // something wrong fValid = false; // error message cout << endl << "PMusrCanvas::UpdateDataTheoryPad: **ERROR** couldn't obtain run no " << runNo << " for a none musr data plot"; cout << endl; return; } // handle data HandleNonMusrDataSet(i, runNo, data); break; default: fValid = false; // error message cout << endl << "PMusrCanvas::UpdateDataTheoryPad: **ERROR** wrong plottype tag?!"; cout << endl; return; break; } } // generate the histo plot PlotData(); } //-------------------------------------------------------------------------- // UpdateInfoPad //-------------------------------------------------------------------------- /** *

*/ void PMusrCanvas::UpdateInfoPad() { if (!fValid) return; PMsrStatisticStructure statistic = *fMsrHandler->GetMsrStatistic(); TString tstr, tsubstr; tstr = "musrfit: "; // get fit date tstr += statistic.fDate; tstr += TString(", "); // get chisq if not a max likelihood fit if (statistic.fChisq) { // chisq tstr += TString("chisq = "); } else { // max. likelihood tstr += TString("maxLH = "); } tstr += statistic.fMin; tstr += TString(" , NDF = "); tstr += statistic.fNdf; if (statistic.fChisq) { // chisq tstr += TString(" , chisq/NDF = "); } else { // max. likelihood tstr += TString(" , maxLH/NDF = "); } if (statistic.fNdf != 0) { tstr += statistic.fMin/statistic.fNdf; } else { tstr += TString("undefined"); } fInfoPad->SetHeader(tstr); // get/set run plot info double dval; char sval[128]; unsigned int runNo; PMsrPlotStructure plotInfo = fMsrHandler->GetMsrPlotList()->at(fPlotNumber); PMsrRunList runs = *fMsrHandler->GetMsrRunList(); for (unsigned int i=0; iGetTemp(runs[runNo].fRunName); if (dval == -9.9e99) { tstr += TString("??,"); } else { sprintf(sval, "%0.2lf", dval); tstr += TString(sval) + TString("(K),"); } // field if present tstr += TString("B="); dval = fRunList->GetField(runs[runNo].fRunName); if (dval == -9.9e99) { tstr += TString("??,"); } else { sprintf(sval, "%0.2lf", dval); tstr += TString(sval) + TString("(G),"); } // energy if present tstr += TString("E="); dval = fRunList->GetEnergy(runs[runNo].fRunName); if (dval == -9.9e99) { tstr += TString("??,"); } else { sprintf(sval, "%0.2lf", dval); tstr += TString(sval) + TString("(keV),"); } // setup if present tstr += fRunList->GetSetup(runs[runNo].fRunName); // add entry fInfoPad->AddEntry(fData[i].data, tstr.Data(), "p"); } fInfoPad->Draw(); fMainCanvas->cd(); fMainCanvas->Update(); } //-------------------------------------------------------------------------- // InitDataSet //-------------------------------------------------------------------------- /** *

* * \param dataSet */ void PMusrCanvas::InitDataSet(PMusrCanvasDataSet &dataSet) { dataSet.data = 0; dataSet.dataFourierRe = 0; dataSet.dataFourierIm = 0; dataSet.dataFourierPwr = 0; dataSet.dataFourierPhase = 0; dataSet.theory = 0; dataSet.theoryFourierRe = 0; dataSet.theoryFourierIm = 0; dataSet.theoryFourierPwr = 0; dataSet.theoryFourierPhase = 0; dataSet.diff = 0; dataSet.diffFourierRe = 0; dataSet.diffFourierIm = 0; dataSet.diffFourierPwr = 0; dataSet.diffFourierPhase = 0; } //-------------------------------------------------------------------------- // InitDataSet //-------------------------------------------------------------------------- /** *

* * \param dataSet */ void PMusrCanvas::InitDataSet(PMusrCanvasNonMusrDataSet &dataSet) { dataSet.data = 0; dataSet.dataFourierRe = 0; dataSet.dataFourierIm = 0; dataSet.dataFourierPwr = 0; dataSet.dataFourierPhase = 0; dataSet.theory = 0; dataSet.theoryFourierRe = 0; dataSet.theoryFourierIm = 0; dataSet.theoryFourierPwr = 0; dataSet.theoryFourierPhase = 0; dataSet.diff = 0; dataSet.diffFourierRe = 0; dataSet.diffFourierIm = 0; dataSet.diffFourierPwr = 0; dataSet.diffFourierPhase = 0; } //-------------------------------------------------------------------------- // CleanupDataSet //-------------------------------------------------------------------------- /** *

* * \param dataSet */ void PMusrCanvas::CleanupDataSet(PMusrCanvasDataSet &dataSet) { if (dataSet.data) { delete dataSet.data; dataSet.data = 0; } if (dataSet.dataFourierRe) { delete dataSet.dataFourierRe; dataSet.dataFourierRe = 0; } if (dataSet.dataFourierIm) { delete dataSet.dataFourierIm; dataSet.dataFourierIm = 0; } if (dataSet.dataFourierPwr) { delete dataSet.dataFourierPwr; dataSet.dataFourierPwr = 0; } if (dataSet.dataFourierPhase) { delete dataSet.dataFourierPhase; dataSet.dataFourierPhase = 0; } if (dataSet.theory) { delete dataSet.theory; dataSet.theory = 0; } if (dataSet.theoryFourierRe) { delete dataSet.theoryFourierRe; dataSet.theoryFourierRe = 0; } if (dataSet.theoryFourierIm) { delete dataSet.theoryFourierIm; dataSet.theoryFourierIm = 0; } if (dataSet.theoryFourierPwr) { delete dataSet.theoryFourierPwr; dataSet.theoryFourierPwr = 0; } if (dataSet.theoryFourierPhase) { delete dataSet.theoryFourierPhase; dataSet.theoryFourierPhase = 0; } if (dataSet.diff) { delete dataSet.diff; dataSet.diff = 0; } if (dataSet.diffFourierRe) { delete dataSet.diffFourierRe; dataSet.diffFourierRe = 0; } if (dataSet.diffFourierIm) { delete dataSet.diffFourierIm; dataSet.diffFourierIm = 0; } if (dataSet.diffFourierPwr) { delete dataSet.diffFourierPwr; dataSet.diffFourierPwr = 0; } if (dataSet.diffFourierPhase) { delete dataSet.diffFourierPhase; dataSet.diffFourierPhase = 0; } } //-------------------------------------------------------------------------- // CleanupDataSet //-------------------------------------------------------------------------- /** *

* * \param dataSet */ void PMusrCanvas::CleanupDataSet(PMusrCanvasNonMusrDataSet &dataSet) { if (dataSet.data) { delete dataSet.data; dataSet.data = 0; } if (dataSet.dataFourierRe) { delete dataSet.dataFourierRe; dataSet.dataFourierRe = 0; } if (dataSet.dataFourierIm) { delete dataSet.dataFourierIm; dataSet.dataFourierIm = 0; } if (dataSet.dataFourierPwr) { delete dataSet.dataFourierPwr; dataSet.dataFourierPwr = 0; } if (dataSet.dataFourierPhase) { delete dataSet.dataFourierPhase; dataSet.dataFourierPhase = 0; } if (dataSet.theory) { delete dataSet.theory; dataSet.theory = 0; } if (dataSet.theoryFourierRe) { delete dataSet.theoryFourierRe; dataSet.theoryFourierRe = 0; } if (dataSet.theoryFourierIm) { delete dataSet.theoryFourierIm; dataSet.theoryFourierIm = 0; } if (dataSet.theoryFourierPwr) { delete dataSet.theoryFourierPwr; dataSet.theoryFourierPwr = 0; } if (dataSet.theoryFourierPhase) { delete dataSet.theoryFourierPhase; dataSet.theoryFourierPhase = 0; } if (dataSet.diff) { delete dataSet.diff; dataSet.diff = 0; } if (dataSet.diffFourierRe) { delete dataSet.diffFourierRe; dataSet.diffFourierRe = 0; } if (dataSet.diffFourierIm) { delete dataSet.diffFourierIm; dataSet.diffFourierIm = 0; } if (dataSet.diffFourierPwr) { delete dataSet.diffFourierPwr; dataSet.diffFourierPwr = 0; } if (dataSet.diffFourierPhase) { delete dataSet.diffFourierPhase; dataSet.diffFourierPhase = 0; } } //-------------------------------------------------------------------------- // HandleDataSet //-------------------------------------------------------------------------- /** *

* * \param runNo * \param data */ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunData *data) { PMusrCanvasDataSet dataSet; TH1F *dataHisto; TH1F *theoHisto; TString name; double start; double end; InitDataSet(dataSet); // dataHisto ------------------------------------------------------------- // create histo specific infos name = fMsrHandler->GetMsrRunList()->at(runNo).fRunName + "_DataRunNo"; name += (int)runNo; start = data->fDataTimeStart - data->fDataTimeStep/2.0; end = data->fDataTimeStart + data->fValue.size()*data->fDataTimeStep + data->fDataTimeStep/2.0; // invoke histo dataHisto = new TH1F(name, name, data->fValue.size()+2, 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]); } // set marker and line color if (plotNo < fColorList.size()) { dataHisto->SetMarkerColor(fColorList[plotNo]); dataHisto->SetLineColor(fColorList[plotNo]); } else { TRandom rand(plotNo); Int_t color = TColor::GetColor((Int_t)rand.Integer(255), (Int_t)rand.Integer(255), (Int_t)rand.Integer(255)); dataHisto->SetMarkerColor(color); dataHisto->SetLineColor(color); } // set marker size dataHisto->SetMarkerSize(1); // set marker type if (plotNo < fMarkerList.size()) { dataHisto->SetMarkerStyle(fMarkerList[plotNo]); } else { TRandom rand(plotNo); dataHisto->SetMarkerStyle(20+(Int_t)rand.Integer(10)); } // theoHisto ------------------------------------------------------------- // create histo specific infos name = fMsrHandler->GetMsrRunList()->at(runNo).fRunName + "_TheoRunNo"; name += (int)runNo; start = data->fTheoryTimeStart - data->fTheoryTimeStep/2.0; end = data->fTheoryTimeStart + data->fTheory.size()*data->fTheoryTimeStep + data->fTheoryTimeStep/2.0; //cout << endl << ">> start = " << start << ", end = " << end << endl; // invoke histo theoHisto = new TH1F(name, name, data->fTheory.size()+2, start, end); // fill histogram for (unsigned int i=0; ifTheory.size(); i++) { theoHisto->SetBinContent(i+1, data->fTheory[i]); } // set the line color if (plotNo < fColorList.size()) { theoHisto->SetLineColor(fColorList[plotNo]); } else { TRandom rand(plotNo); Int_t color = TColor::GetColor((Int_t)rand.Integer(255), (Int_t)rand.Integer(255), (Int_t)rand.Integer(255)); theoHisto->SetLineColor(color); } // fill handler list ----------------------------------------------------- dataSet.data = dataHisto; dataSet.theory = theoHisto; fData.push_back(dataSet); } //-------------------------------------------------------------------------- // HandleNonMusrDataSet //-------------------------------------------------------------------------- /** *

* * \param runNo * \param data */ void PMusrCanvas::HandleNonMusrDataSet(unsigned int plotNo, unsigned int runNo, PRunData *data) { PMusrCanvasNonMusrDataSet dataSet; TGraphErrors *dataHisto; TGraphErrors *theoHisto; InitDataSet(dataSet); // dataHisto ------------------------------------------------------------- // invoke graph dataHisto = new TGraphErrors(data->fX.size()); // fill graph for (unsigned int i=0; ifX.size(); i++) { dataHisto->SetPoint(i, data->fX[i], data->fValue[i]); dataHisto->SetPointError(i, 0.0, data->fError[i]); } // set marker and line color if (plotNo < fColorList.size()) { dataHisto->SetMarkerColor(fColorList[plotNo]); dataHisto->SetLineColor(fColorList[plotNo]); } else { TRandom rand(plotNo); Int_t color = TColor::GetColor((Int_t)rand.Integer(255), (Int_t)rand.Integer(255), (Int_t)rand.Integer(255)); dataHisto->SetMarkerColor(color); dataHisto->SetLineColor(color); } // set marker size dataHisto->SetMarkerSize(1); // set marker type if (plotNo < fMarkerList.size()) { dataHisto->SetMarkerStyle(fMarkerList[plotNo]); } else { TRandom rand(plotNo); dataHisto->SetMarkerStyle(20+(Int_t)rand.Integer(10)); } // theoHisto ------------------------------------------------------------- // invoke graph theoHisto = new TGraphErrors(data->fXTheory.size()); // fill graph for (unsigned int i=0; ifXTheory.size(); i++) { theoHisto->SetPoint(i, data->fXTheory[i], data->fTheory[i]); theoHisto->SetPointError(i, 0.0, 0.0); } // set the line color if (plotNo < fColorList.size()) { theoHisto->SetLineColor(fColorList[plotNo]); } else { TRandom rand(plotNo); Int_t color = TColor::GetColor((Int_t)rand.Integer(255), (Int_t)rand.Integer(255), (Int_t)rand.Integer(255)); theoHisto->SetLineColor(color); } // fill handler list ----------------------------------------------------- dataSet.data = dataHisto; dataSet.theory = theoHisto; fNonMusrData.push_back(dataSet); } //-------------------------------------------------------------------------- // HandleDifference //-------------------------------------------------------------------------- /** *

* */ void PMusrCanvas::HandleDifference() { cout << endl << ">> will show the difference between the theory and the signal, to be implemented yet. fMainCanvas name = " << fMainCanvas->GetName(); cout << endl; if (fDifferencePlot) fDifferencePlot = kFALSE; else fDifferencePlot = kTRUE; // difference plot wished hence feed difference data and plot them if (fDifferencePlot) { // check if it is necessary to calculate diff data if ((fPlotType != MSR_PLOT_NON_MUSR) && (fData[0].diff == 0)) { TH1F *diffHisto; TString name; // loop over all histos for (unsigned int i=0; iGetTitle()) + "_diff"; 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()); // set marker and line color if (i < fColorList.size()) { diffHisto->SetMarkerColor(fColorList[i]); diffHisto->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)); diffHisto->SetMarkerColor(color); diffHisto->SetLineColor(color); } // set marker size diffHisto->SetMarkerSize(1); // set marker type if (i < fMarkerList.size()) { diffHisto->SetMarkerStyle(fMarkerList[i]); } else { TRandom rand(i); diffHisto->SetMarkerStyle(20+(Int_t)rand.Integer(10)); } // keep difference histo fData[i].diff = diffHisto; // calculate diff histo entry double value; for (int j=1; jGetNbinsX()-1; j++) { // set diff bin value value = CalculateDiff(fData[i].data->GetBinCenter(j), fData[i].data->GetBinContent(j), fData[i].theory); fData[i].diff->SetBinContent(j, value); // set error diff bin value value = fData[i].data->GetBinError(j); fData[i].diff->SetBinError(j, value); } } } else if ((fPlotType == MSR_PLOT_NON_MUSR) && (fNonMusrData[0].diff == 0)) { TGraphErrors *diffHisto; TString name; // loop over all histos for (unsigned int i=0; iGetN()); // create difference histos name = TString(fNonMusrData[i].data->GetTitle()) + "_diff"; cout << endl << ">> diff-name = " << name.Data() << endl; diffHisto->SetNameTitle(name.Data(), name.Data()); // set marker and line color if (i < fColorList.size()) { diffHisto->SetMarkerColor(fColorList[i]); diffHisto->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)); diffHisto->SetMarkerColor(color); diffHisto->SetLineColor(color); } // set marker size diffHisto->SetMarkerSize(1); // set marker type if (i < fMarkerList.size()) { diffHisto->SetMarkerStyle(fMarkerList[i]); } else { TRandom rand(i); diffHisto->SetMarkerStyle(20+(Int_t)rand.Integer(10)); } // keep difference histo fNonMusrData[i].diff = diffHisto; // calculate diff histo entry double value; double x, y; for (int j=0; jGetN(); j++) { // set diff bin value fNonMusrData[i].data->GetPoint(j, x, y); value = CalculateDiff(x, y, fNonMusrData[i].theory); fNonMusrData[i].diff->SetPoint(j, x, value); // set error diff bin value value = fNonMusrData[i].data->GetErrorY(j); fNonMusrData[i].diff->SetPointError(j, 0.0, value); } } } } // switch back to the "normal" view if (!fDifferencePlot) { // set current x-axis range PlotData(); } else { if (fPlotType != MSR_PLOT_NON_MUSR) { // set current x-axis range Int_t xminBin = fData[0].data->GetXaxis()->GetFirst(); // first bin of the zoomed range Int_t xmaxBin = fData[0].data->GetXaxis()->GetLast(); // last bin of the zoomed range Double_t xmin = fData[0].data->GetXaxis()->GetBinCenter(xminBin); Double_t xmax = fData[0].data->GetXaxis()->GetBinCenter(xmaxBin); fData[0].diff->GetXaxis()->SetRangeUser(xmin, xmax); } PlotDifference(); } } //-------------------------------------------------------------------------- // CalculateDiff //-------------------------------------------------------------------------- /** *

* * \param x x-value of the data * \param y y-value of the data * \param theo theory histogram */ double PMusrCanvas::CalculateDiff(const double x, const double y, TH1F *theo) { Int_t bin = theo->FindBin(x); return y - theo->GetBinContent(bin); } //-------------------------------------------------------------------------- // CalculateDiff //-------------------------------------------------------------------------- /** *

* * \param x x-value of the data * \param y y-value of the data * \param theo theory error graph */ double PMusrCanvas::CalculateDiff(const double x, const double y, TGraphErrors *theo) { Int_t i, bin = 0; Double_t *xTheo = theo->GetX(); Double_t xVal, yVal; // find proper bin of the theory for (i=0; iGetN(); i++) { if (*(xTheo+i) >= x) { bin = i; break; } } // in case it is the last point if (i == theo->GetN()) { bin = i; } theo->GetPoint(bin, xVal, yVal); cout << endl << ">> bin=" << bin << ", x=" << xVal << " (xData=" << x << "), y=" << yVal; return y - yVal; } //-------------------------------------------------------------------------- // PlotData //-------------------------------------------------------------------------- /** *

* */ void PMusrCanvas::PlotData() { fDataTheoryPad->cd(); if (fPlotType < 0) // plot type not defined return; 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 x-axis label fData[0].data->GetXaxis()->SetTitle("time (#mus)"); // set y-axis label TString yAxisTitle; PMsrRunList *runList = fMsrHandler->GetMsrRunList(); switch (fPlotType) { case MSR_PLOT_SINGLE_HISTO: if (runList->at(0).fLifetimeCorrection) { // lifetime correction yAxisTitle = "asymmetry"; } else { // no liftime correction yAxisTitle = "N(t) per bin"; } break; case MSR_PLOT_ASYM: case MSR_PLOT_ASYM_RRF: yAxisTitle = "asymmetry"; break; default: yAxisTitle = "??"; break; } fData[0].data->GetYaxis()->SetTitle(yAxisTitle.Data()); // plot all remaining data for (unsigned int i=1; iDraw("pesame"); } // plot all the theory for (unsigned int i=0; iDraw("csame"); } } } else { // fPlotType == MSR_PLOT_NO_MUSR PMsrRunList runs = *fMsrHandler->GetMsrRunList(); PMsrPlotStructure plotInfo = fMsrHandler->GetMsrPlotList()->at(fPlotNumber); unsigned int runNo = (unsigned int)plotInfo.fRuns[0].Re()-1; TString xAxisTitle = fRunList->GetXAxisTitle(runs[runNo].fRunName); TString yAxisTitle = fRunList->GetYAxisTitle(runs[runNo].fRunName); if (fNonMusrData.size() > 0) { fNonMusrData[0].data->Draw("ap"); // set x-range Double_t xmin = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmin; Double_t xmax = fMsrHandler->GetMsrPlotList()->at(fPlotNumber).fTmax; fNonMusrData[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)) { fNonMusrData[0].data->GetYaxis()->SetRangeUser(ymin, ymax); } // set x-axis label fNonMusrData[0].data->GetXaxis()->SetTitle(xAxisTitle.Data()); // set y-axis label fNonMusrData[0].data->GetYaxis()->SetTitle(yAxisTitle.Data()); // plot all remaining data for (unsigned int i=1; iDraw("psame"); } // plot all the theory for (unsigned int i=0; iDraw("csame"); } } } fDataTheoryPad->Update(); fMainCanvas->cd(); fMainCanvas->Update(); } //-------------------------------------------------------------------------- // PlotDifference //-------------------------------------------------------------------------- /** *

* */ void PMusrCanvas::PlotDifference() { fDataTheoryPad->cd(); if (fPlotType < 0) // plot type not defined return; if (fPlotType != MSR_PLOT_NON_MUSR) { cout << endl << ">> going to plot diff spectra ... (" << fData[0].diff->GetNbinsX() << ")" << endl; fData[0].diff->Draw("pe"); // set x-axis label fData[0].diff->GetXaxis()->SetTitle("time (#mus)"); // set y-axis label fData[0].diff->GetYaxis()->SetTitle("data-theory"); // plot all remaining diff data for (unsigned int i=1; iDraw("pesame"); } } else { // fPlotType == MSR_PLOT_NON_MUSR PMsrRunList runs = *fMsrHandler->GetMsrRunList(); PMsrPlotStructure plotInfo = fMsrHandler->GetMsrPlotList()->at(fPlotNumber); unsigned int runNo = (unsigned int)plotInfo.fRuns[0].Re()-1; TString xAxisTitle = fRunList->GetXAxisTitle(runs[runNo].fRunName); fNonMusrData[0].diff->Draw("ap"); // set x-axis label fNonMusrData[0].diff->GetXaxis()->SetTitle(xAxisTitle.Data()); // set y-axis label fNonMusrData[0].diff->GetYaxis()->SetTitle("data-theory"); // plot all remaining diff data for (unsigned int i=1; iDraw("psame"); } } fDataTheoryPad->Update(); fMainCanvas->cd(); fMainCanvas->Update(); } //-------------------------------------------------------------------------- // PlotFourier //-------------------------------------------------------------------------- /** *

* * \param fourierType flag showing if real-, imaginary-, power-, or phase-spectra are wished */ void PMusrCanvas::PlotFourier(int fourierType) { }