CAMLprim value ml_gsl_histogram_scale(value vh, value s) { gsl_histogram h; histo_of_val(&h, vh); gsl_histogram_scale(&h, Double_val(s)); return Val_unit; }
gsl_histogram * calc_hist(const gsl_vector * v, int nbins) { double max; double min; unsigned int i; double binwidth; double sum = 0; double val; gsl_histogram * h; gsl_vector_minmax(v, &min, &max); binwidth = (max - min) / nbins; dump_d("min", min); dump_d("max", max); debug("allocating the histogram"); h = gsl_histogram_alloc(v->size); debug("setting range"); require(gsl_histogram_set_ranges_uniform (h, min, max)); /* with out the following, the max element doesn't fall in the last bin */ h->range[h->n] += 1; debug("summing up"); for (i = 0; i < v->size; i++) { val = gsl_vector_get(v, i); sum += val; require(gsl_histogram_increment (h, val)); } debug("scaling"); /* double gsl_histogram_sum (const gsl_histogram * h) */ require(gsl_histogram_scale (h, 1/sum)); debug("done"); return h; }
void BurstSearchWidget::on_pushButtonBurstView_clicked() { qDebug("on_pushButtonBurstView_clicked"); if(ad->isEmpty()) return; JKQtPlotter* plot = new JKQtPlotter(true,NULL); getParameters(); double binwidth=5e-6, alternationPeriod=ad->getExcitationPeriodDonor(); int nbins=(int)(alternationPeriod/binwidth+1); gsl_histogram * histCh1 = gsl_histogram_alloc (nbins); gsl_histogram * histCh2 = gsl_histogram_alloc (nbins); gsl_histogram_set_ranges_uniform (histCh1, 0, alternationPeriod*1.1); gsl_histogram_set_ranges_uniform (histCh2, 0, alternationPeriod*1.1); int last=0; int lastExc=0; while(ad->photons.at(last).time<ad->markerTimeDexc.at(lastExc)) ++last; uint ch1=ui->comboBoxChannel1->channel(); uint ch2=ui->comboBoxChannel2->channel(); while((lastExc<1e4)&&(lastExc<ad->markerTimeDexc.size()+1)) { // average first 10000 periods while ((last<ad->photons.size()) && ad->photons[last].time<ad->markerTimeDexc.at(lastExc+1)) { // qDebug()<<QString::number(ad->photons[last].flags,2)+"\t"<<ch1<<ch2<<"\t"<<ad->photons[last].isPhotonFlag(ch1)<<ad->photons[last].isPhotonFlag(ch2); #ifdef PHOTONMACRO if(isPhotonFlag(ad->photons[last],ch1)) gsl_histogram_increment (histCh1, ad->photons[last].time-ad->markerTimeDexc[lastExc]); if(isPhotonFlag(ad->photons[last],ch2)) gsl_histogram_increment (histCh2, ad->photons[last].time-ad->markerTimeDexc[lastExc]); #else if(ad->photons[last].isPhotonFlag(ch1)) gsl_histogram_increment (histCh1, ad->photons[last].time-ad->markerTimeDexc[lastExc]); if(ad->photons[last].isPhotonFlag(ch2)) gsl_histogram_increment (histCh2, ad->photons[last].time-ad->markerTimeDexc[lastExc]); #endif last++; } // end of excitation period lastExc++; } JKQTPdatastore* ds=plot->get_plotter()->getDatastore(); ds->clear(); plot->get_plotter()->clearGraphs(true); plot->get_plotter()->setGrid(false); qDebug("plotHist DA"); unsigned long long nrows=(unsigned long long)histCh1->n; for(size_t i=0;i<histCh1->n;++i) histCh1->range[i] *= 1e6; plot->get_xAxis()->set_axisLabel("time in us"); plot->get_yAxis()->set_axisLabel("countrate in Hz"); gsl_histogram_scale(histCh1,(1.0)/(lastExc*binwidth)); // convert bins to countrate in Hz (counts averaged over lastDex excitation periods in bin of width binwidth) gsl_histogram_scale(histCh2,(1.0)/(lastExc*binwidth)); size_t xColumn=ds->addCopiedColumn(histCh1->range, nrows, "time"); // adds column (copies values!) and returns column ID QVector<size_t> yColumns; yColumns.push_back(ds->addCopiedColumn(histCh1->bin, nrows, "Channel 1")); yColumns.push_back(ds->addCopiedColumn(histCh2->bin, nrows, "Channel 2")); QList<QColor> colors; colors.append(QColor(COUNTRATE_COLOR_CH1)); colors.append(QColor(COUNTRATE_COLOR_CH2)); gsl_histogram_free(histCh1); gsl_histogram_free(histCh2); // plot double width=0.5; double s=-0.5+width/2.0; for (int i=0; i<yColumns.size(); ++i) { JKQTPbarHorizontalGraph* g=new JKQTPbarHorizontalGraph(plot->get_plotter()); g->set_xColumn(xColumn); g->set_yColumn(yColumns[i]); g->set_shift(s); g->set_width(width); g->set_style(Qt::NoPen); g->set_fillColor(colors.at(i)); s=s+width; plot->addGraph(g); } plot->get_plotter()->set_keyPosition(JKQTPkeyInsideTopRight); // set legend position plot->get_plotter()->set_showKey(true); plot->zoomToFit(); plot->show(); // old: // if(ad->burstVectorDual.isEmpty()) // runBurstSearch(); // analysisFRET(ad->burstVectorDual,ad->FRETparams); // BurstView *burstView= new BurstView(this, ad); // burstView->exec(); }