bug fix on filling Historgram 1D

This commit is contained in:
Ryan Tang 2024-08-23 18:26:56 -04:00
parent 823adf67eb
commit f3fea48bf6

View File

@ -244,7 +244,8 @@ public:
addGraph(); addGraph();
graph(nData - 1)->setName(title); graph(nData - 1)->setName(title);
SetColor(color, nData-1); SetColor(color, nData-1);
yList[nData-1] = yList[0]; yList[nData-1].clear();
for( int i = 0; i < xList.count(); i++) yList[nData-1].append(0);
} }
void UpdatePlot(){ void UpdatePlot(){
@ -263,7 +264,7 @@ public:
void Clear(){ void Clear(){
DebugPrint("%s", "Histogram1D"); DebugPrint("%s", "Histogram1D");
for( int ID = 0 ; ID < nData; ID ++) { for( int ID = 0 ; ID < nData; ID ++) {
for( int i = 0; i <= yList[ID].count(); i++) yList[ID][i] = 0; for( int i = 0; i < xList.count(); i++) yList[ID][i] = 0;
} }
yMax = 0; yMax = 0;
txt[0]->setText("Under Flow : 0"); txt[0]->setText("Under Flow : 0");
@ -324,10 +325,12 @@ public:
txt[2]->setText("Over Flow : "+ QString::number(overFlow)); txt[2]->setText("Over Flow : "+ QString::number(overFlow));
return; return;
} }
}else{
if( value < xMin || value > xMax ) return;
} }
double bin = (value - xMin)/dX; int bin = qFloor((value - xMin)/dX);
int index1 = 2*qFloor(bin) + 1; int index1 = 2*bin + 1;
int index2 = index1 + 1; int index2 = index1 + 1;
if( 0 <= index1 && index1 <= 2*xBin) yList[ID][index1] += 1; if( 0 <= index1 && index1 <= 2*xBin) yList[ID][index1] += 1;