void Histogram::internalUpdate() { writeLockInputsAndOutputs(); int i_bin, i_pt, ns; double y = 0.0; double MaxY = 0.0; // do auto-binning if necessary if (_realTimeAutoBin) { int temp_NumberOfBins; double temp_xMin, temp_xMax; Histogram::AutoBin(_inputVectors[RAWVECTOR], &temp_NumberOfBins, &temp_xMax, &temp_xMin); internalSetNumberOfBins(temp_NumberOfBins); internalSetXRange(temp_xMin, temp_xMax); } _NS = 3 * _NumberOfBins + 1; _W = (_MaxX - _MinX)/double(_NumberOfBins); memset(_Bins, 0, _NumberOfBins*sizeof(*_Bins)); ns = _inputVectors[RAWVECTOR]->length(); for (i_pt = 0; i_pt < ns ; ++i_pt) { y = _inputVectors[RAWVECTOR]->interpolate(i_pt, ns); i_bin = (int)floor((y-_MinX)/_W); if (i_bin >= 0 && i_bin < _NumberOfBins) { _Bins[i_bin]++; } else { // the top boundary of the top bin is included in the top bin. // for all other bins, the top boundary is included in the next bin if (y == _MaxX) { _Bins[_NumberOfBins-1]++; } } } for (i_bin=0; i_bin<_NumberOfBins; ++i_bin) { y = _Bins[i_bin]; if (y > MaxY) { MaxY = y; } } LabelInfo label_info; switch (_NormalizationMode) { case Number: _Normalization = 1.0; label_info.quantity = tr("Number"); break; case Percent: if (ns > 0) { _Normalization = 100.0/(double)ns; } else { _Normalization = 1.0; } label_info.quantity = tr("Percent"); break; case Fraction: if (ns > 0) { _Normalization = 1.0/(double)ns; } else { _Normalization = 1.0; } label_info.quantity = tr("Fraction"); break; case MaximumOne: if (MaxY > 0) { _Normalization = 1.0/MaxY; } else { _Normalization = 1.0; } label_info.quantity = tr("Normalized Frequency"); break; default: _Normalization = 1.0; label_info.quantity = tr("Number"); break; } _bVector->setLabelInfo(_inputVectors[RAWVECTOR]->labelInfo()); label_info.quantity.clear(); label_info.units.clear(); label_info.name = tr( "Histogram of %1").arg(_bVector->labelInfo().name); label_info.file = _bVector->labelInfo().file; _hVector->setTitleInfo(label_info); double *bins = _bVector->value(); double *hist = _hVector->value(); for ( i_bin = 0; i_bin<_NumberOfBins; ++i_bin ) { bins[i_bin] = ( double( i_bin ) + 0.5 )*_W + _MinX; hist[i_bin] = _Bins[i_bin]*_Normalization; } unlockInputsAndOutputs(); }
void Histogram::setXRange(double xmin_in, double xmax_in) { internalSetXRange(xmin_in, xmax_in); }
void Histogram::internalUpdate() { writeLockInputsAndOutputs(); int i_bin, i_pt, ns; double y = 0.0; double MaxY = 0.0; // do auto-binning if necessary if (_realTimeAutoBin) { int temp_NumberOfBins; double temp_xMin, temp_xMax; Histogram::AutoBin(_inputVectors[RAWVECTOR], &temp_NumberOfBins, &temp_xMax, &temp_xMin); internalSetNumberOfBins(temp_NumberOfBins); internalSetXRange(temp_xMin, temp_xMax); } _NS = 3 * _NumberOfBins + 1; _W = (_MaxX - _MinX)/double(_NumberOfBins); memset(_Bins, 0, _NumberOfBins*sizeof(*_Bins)); ns = _inputVectors[RAWVECTOR]->length(); for (i_pt = 0; i_pt < ns ; i_pt++) { y = _inputVectors[RAWVECTOR]->interpolate(i_pt, ns); i_bin = (int)floor((y-_MinX)/_W); if (i_bin >= 0 && i_bin < _NumberOfBins) { _Bins[i_bin]++; } else { // the top boundry of the top bin is included in the top bin. // for all other bins, the top boundry is included in the next bin if (y == _MaxX) { _Bins[_NumberOfBins-1]++; } } } for (i_bin=0; i_bin<_NumberOfBins; i_bin++) { y = _Bins[i_bin]; if (y > MaxY) { MaxY = y; } } switch (_NormalizationMode) { case Number: _Normalization = 1.0; _hVector->setLabel(i18n("Number in bin")); break; case Percent: if (ns > 0) { _Normalization = 100.0/(double)ns; } else { _Normalization = 1.0; } _hVector->setLabel(i18n("Percent in bin")); break; case Fraction: if (ns > 0) { _Normalization = 1.0/(double)ns; } else { _Normalization = 1.0; } _hVector->setLabel(i18n("Fraction in bin")); break; case MaximumOne: if (MaxY > 0) { _Normalization = 1.0/MaxY; } else { _Normalization = 1.0; } _hVector->setLabel(""); break; default: _Normalization = 1.0; break; } _bVector->setLabel(_inputVectors[RAWVECTOR]->descriptiveName()); double *bins = _bVector->value(); double *hist = _hVector->value(); for ( i_bin = 0; i_bin<_NumberOfBins; i_bin++ ) { bins[i_bin] = ( double( i_bin ) + 0.5 )*_W + _MinX; hist[i_bin] = _Bins[i_bin]*_Normalization; } // these will get updated by the update manager now // that their provider been changed. //_bVector->update(); //_hVector->update(); unlockInputsAndOutputs(); }