int PlotSignals(char *filename, int plfrom=0, int plto=100, int same=1) { bragg_signal signal; TFile *fin=new TFile(filename); if (!fin->IsOpen()) { std::cout << "file not found! " << std::endl; return -1; } TTree *tree = (TTree*)fin->Get("bragg"); if (!tree) { std::cout << "Bragg tree not found! " << std::endl; return -2; } TBranch *br = tree->GetBranch("signals"); if (!br) { std::cout << "Signal branch not found! " << std::endl; return -3; } br->SetAddress(&signal); int nev = br->GetEntries(); std::cout << "Number of events in file : " << nev << std::endl; for (int i=plfrom; i<plto; i++) { br->GetEntry(i); plotSignal(signal,same); } return 0; }
void RImageDock::drawHist() { cv::Mat tempHist; matHist.convertTo(tempHist, CV_64F); int nBins = matHist.rows; double minHist; double maxHist; cv::minMaxLoc(matHist, &minHist, &maxHist); QVector<double> x(nBins); // y must be the histogram values for (int i=0; i< nBins; ++i) { x[i] = dataMin + histWidth*i; // x goes from 0 to nBins-1 } // Pointer to matHist data. const double* matHistPtr = tempHist.ptr<double>(0); std::vector<double> matHistStdVect(matHistPtr, matHistPtr + matHist.rows); QVector<double> y = QVector<double>::fromStdVector(matHistStdVect); // create graph and assign data to it: customPlot = new QCustomPlot(); customPlot->xAxis->setLabel("Intensity bins"); customPlot->yAxis->setLabel("Pixels"); QCPBars *myBars = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(myBars); myBars->setData(x, y); myBars->setWidth(1); // customPlot->addGraph(); // customPlot->graph(0)->setData(x, y); customPlot->yAxis->setScaleType(QCPAxis::stLogarithmic); customPlot->rescaleAxes(); // set axes ranges, so we see all data: //customPlot->xAxis->setRange(0, nBins+100); double maxXRange = std::min(dataMax, (double) 4*percentileHigh); double minXRange = std::min(0.0, (double) percentileLow); customPlot->xAxis->setRange(minXRange, maxXRange); customPlot->yAxis->setRange(1, maxHist); // customPlot->plottable(0)->setPen(QPen(QColor(0, 0, 255, 50))); // line color blue for first graph // customPlot->plottable(0)->setBrush(QBrush(QColor(0, 0, 255, 50))); customPlot->plottable(0)->setPen(QPen(QColor(125, 125, 125, 50))); // line color blue for first graph customPlot->plottable(0)->setBrush(QBrush(QColor(125, 125, 125, 50))); customPlot->setInteraction(QCP::iRangeDrag, true); customPlot->setInteraction(QCP::iRangeZoom, true); customPlot->axisRect(0)->setRangeDrag(Qt::Horizontal); customPlot->axisRect(0)->setRangeZoom(Qt::Horizontal); qDebug("customPlot ready for emit signal."); emit plotSignal(customPlot); }