Program: 149587
Project: 149587
Buggy source:
private void analyse(MemoryPeakResults results){
  results.sort();
  int min=results.getResults().get(0).peak;
  int max=results.getResults().get(results.size() - 1).getEndFrame();
  double d=searchDistance / results.getCalibration().nmPerPixel;
  int range=max - min + 1;
  if (maxDarkTime > 0)   range=Math.max(1,(int)Math.round(maxDarkTime * 1000 / msPerFrame));
  IJTrackProgress tracker=new IJTrackProgress();
  tracker.status("String_Node_Str");
  Trace[] traces;
  ClusteringAlgorithm algorithm=ClusteringAlgorithm.ClosestParticleTimePriority;
switch (method) {
case 2:
    algorithm=ClusteringAlgorithm.ClosestParticleDistancePriority;
case 1:
  ClusteringEngine engine=new ClusteringEngine();
engine.setClusteringAlgorithm(algorithm);
engine.setThreadCount(Prefs.getThreads());
engine.setTracker(tracker);
List<PeakResult> peakResults=results.getResults();
ArrayList<Cluster> clusters=engine.findClusters(TraceMolecules.convertToClusterPoints(peakResults),d,range);
traces=TraceMolecules.convertToTraces(peakResults,clusters);
break;
case 0:
default :
TraceManager tm=new TraceManager(results);
tm.setTracker(tracker);
tm.traceMolecules(d,range);
traces=tm.getTraces();
}
tracker.status("String_Node_Str");
int[] times=new int[range];
StoredDataStatistics stats=new StoredDataStatistics();
for (Trace trace : traces) {
if (trace.getNBlinks() > 1) {
for (int t : trace.getOffTimes()) {
times[t]++;
}
stats.add(trace.getOffTimes());
}
}
plotDarkTimeHistogram(stats);
for (int i=1; i < times.length; i++) times[i]+=times[i - 1];
int total=times[times.length - 1];
double[] x=new double[range];
double[] y=new double[range];
int truncate=0;
for (int i=0; i < x.length; i++) {
x[i]=i * msPerFrame;
y[i]=(100.0 * times[i]) / total;
if (times[i] == total) {
truncate=i + 1;
break;
}
}
if (truncate > 0) {
x=Arrays.copyOf(x,truncate);
y=Arrays.copyOf(y,truncate);
}
String title="String_Node_Str";
Plot plot=new Plot(title,"String_Node_Str","String_Node_Str",x,y);
Utils.display(title,plot);
for (int i=0; i < y.length; i++) {
if (y[i] >= percentile) {
Utils.log("String_Node_Str",percentile,Utils.rounded(x[i]),Utils.rounded(x[i] / 1000));
break;
}
}
tracker.status("String_Node_Str");
}

Fixed version (ground truth):
private void analyse(MemoryPeakResults results){
  results.sort();
  int min=results.getResults().get(0).peak;
  int max=results.getResults().get(results.size() - 1).getEndFrame();
  double d=searchDistance / results.getCalibration().nmPerPixel;
  int range=max - min + 1;
  if (maxDarkTime > 0)   range=Math.max(1,(int)Math.round(maxDarkTime * 1000 / msPerFrame));
  IJTrackProgress tracker=new IJTrackProgress();
  tracker.status("String_Node_Str");
  tracker.log("String_Node_Str",Utils.rounded(searchDistance),Utils.rounded(d),Utils.rounded(range * msPerFrame / 1000.0),range);
  Trace[] traces;
  ClusteringAlgorithm algorithm=ClusteringAlgorithm.ClosestParticleDistancePriority;
switch (method) {
case 2:
    algorithm=ClusteringAlgorithm.ClosestParticleTimePriority;
case 1:
  ClusteringEngine engine=new ClusteringEngine();
engine.setClusteringAlgorithm(algorithm);
engine.setThreadCount(Prefs.getThreads());
engine.setTracker(tracker);
List<PeakResult> peakResults=results.getResults();
ArrayList<Cluster> clusters=engine.findClusters(TraceMolecules.convertToClusterPoints(peakResults),d,range);
traces=TraceMolecules.convertToTraces(peakResults,clusters);
break;
case 0:
default :
TraceManager tm=new TraceManager(results);
tm.setTracker(tracker);
tm.traceMolecules(d,range);
traces=tm.getTraces();
}
tracker.status("String_Node_Str");
int[] times=new int[range];
StoredDataStatistics stats=new StoredDataStatistics();
for (Trace trace : traces) {
if (trace.getNBlinks() > 1) {
for (int t : trace.getOffTimes()) {
times[t]++;
}
stats.add(trace.getOffTimes());
}
}
plotDarkTimeHistogram(stats);
for (int i=1; i < times.length; i++) times[i]+=times[i - 1];
int total=times[times.length - 1];
double[] x=new double[range];
double[] y=new double[range];
int truncate=0;
for (int i=0; i < x.length; i++) {
x[i]=i * msPerFrame;
y[i]=(100.0 * times[i]) / total;
if (times[i] == total) {
truncate=i + 1;
break;
}
}
if (truncate > 0) {
x=Arrays.copyOf(x,truncate);
y=Arrays.copyOf(y,truncate);
}
String title="String_Node_Str";
Plot plot=new Plot(title,"String_Node_Str","String_Node_Str",x,y);
Utils.display(title,plot);
for (int i=0; i < y.length; i++) {
if (y[i] >= percentile) {
Utils.log("String_Node_Str",percentile,Utils.rounded(x[i]),Utils.rounded(x[i] / 1000));
break;
}
}
tracker.status("String_Node_Str");
}