UltraScan III
us_resplot_2d.cpp
Go to the documentation of this file.
1 
3 #include "us_resplot_2d.h"
4 #include "us_2dsa.h"
5 #include "us_settings.h"
6 #include "us_gui_settings.h"
7 #include "us_math2.h"
8 #include "us_constants.h"
9 
10 #include <qwt_legend.h>
11 
12 // constructor: residuals plot widget
13 US_ResidPlot2D::US_ResidPlot2D( QWidget* parent = 0 )
14  : US_WidgetsDialog( 0, 0 )
15 {
16  // lay out the GUI
17  setWindowTitle( tr( "2-D Spectrum Analysis Data/Residuals Viewer" ) );
18  setPalette( US_GuiSettings::frameColor() );
19 
20  QSize p1size( 560, 240 );
21  QSize p2size( 560, 240 );
22 
24  resbmap = 0;
25 
26  mainLayout = new QHBoxLayout( this );
27  leftLayout = new QVBoxLayout();
28  rightLayout = new QVBoxLayout();
29  datctrlsLayout = new QGridLayout();
30  resctrlsLayout = new QGridLayout();
31  buttonsLayout = new QVBoxLayout();
32 
33  mainLayout->setSpacing ( 2 );
34  mainLayout->setContentsMargins( 2, 2, 2, 2 );
35 
36  QLabel* lb_datctrls = us_banner( tr( "2DSA Data Viewer" ) );
37  QLabel* lb_resctrls = us_banner( tr( "2DSA Residuals Viewer" ) );
38  QLabel* lb_vari = us_label( tr( "Variance:" ) );
39  QLabel* lb_rmsd = us_label( tr( "RMSD:" ) );
40 
41  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
42 
43  QLayout* lo_plteda =
44  us_checkbox( tr( "Plot Experimental Data" ), ck_plteda, true );
45  QLayout* lo_subtin =
46  us_checkbox( tr( "Subtract Time Invariant Noise" ), ck_subtin );
47  QLayout* lo_subrin =
48  us_checkbox( tr( "Subtract Radially Invariant Noise" ), ck_subrin );
49  QLayout* lo_pltsda =
50  us_checkbox( tr( "Plot Simulated/Modeled Data" ), ck_pltsda, true );
51  QLayout* lo_addtin =
52  us_checkbox( tr( "Add Time Invariant Noise" ), ck_addtin );
53  QLayout* lo_addrin =
54  us_checkbox( tr( "Add Radially Invariant Noise" ), ck_addrin );
55  QLayout* lo_pltres =
56  us_checkbox( tr( "Plot Residuals" ), ck_pltres, true );
57  QLayout* lo_plttin =
58  us_checkbox( tr( "Plot Time Invariant Noise" ), ck_plttin );
59  QLayout* lo_pltrin =
60  us_checkbox( tr( "Plot Radially Invariant Noise" ), ck_pltrin );
61  QLayout* lo_pltran =
62  us_checkbox( tr( "Plot Random Noise" ), ck_pltran );
63  QLayout* lo_shorbm =
64  us_checkbox( tr( "Show Residuals Bitmap" ), ck_shorbm );
65 
66  le_vari = us_lineedit( "", -1, true );
67  le_rmsd = us_lineedit( "", -1, true );
68 
69  datctrlsLayout->addWidget( lb_datctrls, 0, 0, 1, 8 );
70  datctrlsLayout->addLayout( lo_plteda, 1, 0, 1, 8 );
71  datctrlsLayout->addLayout( lo_subtin, 2, 1, 1, 7 );
72  datctrlsLayout->addLayout( lo_subrin, 3, 1, 1, 7 );
73  datctrlsLayout->addLayout( lo_pltsda, 4, 0, 1, 8 );
74  datctrlsLayout->addLayout( lo_addtin, 5, 1, 1, 7 );
75  datctrlsLayout->addLayout( lo_addrin, 6, 1, 1, 7 );
76 
77  resctrlsLayout->addWidget( lb_resctrls, 0, 0, 1, 8 );
78  resctrlsLayout->addLayout( lo_pltres, 1, 0, 1, 8 );
79  resctrlsLayout->addLayout( lo_plttin, 2, 0, 1, 8 );
80  resctrlsLayout->addLayout( lo_pltrin, 3, 0, 1, 8 );
81  resctrlsLayout->addLayout( lo_pltran, 4, 0, 1, 8 );
82  resctrlsLayout->addLayout( lo_shorbm, 5, 0, 1, 8 );
83  resctrlsLayout->addWidget( lb_vari, 6, 0, 1, 3 );
84  resctrlsLayout->addWidget( le_vari, 6, 3, 1, 5 );
85  resctrlsLayout->addWidget( lb_rmsd, 7, 0, 1, 3 );
86  resctrlsLayout->addWidget( le_rmsd, 7, 3, 1, 5 );
87 
88  buttonsLayout ->addWidget( pb_close );
89 
91  tr( "Experimental Data" ),
92  tr( "Radius (cm)" ),
93  tr( "Absorbance" ) );
94 
96  tr( "Residuals" ),
97  tr( "Radius (cm)" ),
98  tr( "OD Difference" ) );
99 
100  data_plot1->setCanvasBackground( Qt::black );
101  data_plot2->setCanvasBackground( Qt::black );
102  data_plot1->setMinimumSize( p1size );
103  data_plot2->setMinimumSize( p2size );
104 
105  rightLayout->addLayout( plotLayout1 );
106  rightLayout->addLayout( plotLayout2 );
107 
108  leftLayout ->addLayout( datctrlsLayout );
109  leftLayout ->addLayout( resctrlsLayout );
110  leftLayout ->addStretch();
111  leftLayout ->addLayout( buttonsLayout );
112 
113  mainLayout->addLayout( leftLayout );
114  mainLayout->addLayout( rightLayout );
115 
116  connect( ck_plteda, SIGNAL( toggled( bool ) ),
117  this, SLOT( pedaCheck( bool ) ) );
118  connect( ck_subtin, SIGNAL( toggled( bool ) ),
119  this, SLOT( stinCheck( bool ) ) );
120  connect( ck_subrin, SIGNAL( toggled( bool ) ),
121  this, SLOT( srinCheck( bool ) ) );
122  connect( ck_pltsda, SIGNAL( toggled( bool ) ),
123  this, SLOT( psdaCheck( bool ) ) );
124  connect( ck_addtin, SIGNAL( toggled( bool ) ),
125  this, SLOT( atinCheck( bool ) ) );
126  connect( ck_addrin, SIGNAL( toggled( bool ) ),
127  this, SLOT( arinCheck( bool ) ) );
128  connect( ck_pltres, SIGNAL( toggled( bool ) ),
129  this, SLOT( presCheck( bool ) ) );
130  connect( ck_plttin, SIGNAL( toggled( bool ) ),
131  this, SLOT( ptinCheck( bool ) ) );
132  connect( ck_pltrin, SIGNAL( toggled( bool ) ),
133  this, SLOT( prinCheck( bool ) ) );
134  connect( ck_pltran, SIGNAL( toggled( bool ) ),
135  this, SLOT( pranCheck( bool ) ) );
136  connect( ck_shorbm, SIGNAL( toggled( bool ) ),
137  this, SLOT( srbmCheck( bool ) ) );
138 
139  connect( pb_close, SIGNAL( clicked() ),
140  this, SLOT( close_all() ) );
141 
142  // get data pointers from parent widget
143 
144  have_ed = false;
145  have_sd = false;
146  have_ti = false;
147  have_ri = false;
148  have_bm = false;
149  skip_plot = true;
150 DbgLv(1) << "RP: P" << ( parent != 0 );
151 
152  if ( parent )
153  {
154  US_2dsa* mainw = (US_2dsa*)parent;
155  edata = mainw->mw_editdata();
156  sdata = mainw->mw_simdata();
157  excllist = mainw->mw_excllist();
158  ti_noise = mainw->mw_ti_noise();
159  ri_noise = mainw->mw_ri_noise();
160  have_ed = ( edata != 0 );
161  have_sd = ( sdata != 0 );
162  have_ti = ( ti_noise != 0 && ti_noise->count > 0 );
163  have_ri = ( ri_noise != 0 && ri_noise->count > 0 );
164 DbgLv(1) << "RP:edata " << have_ed << edata;
165 DbgLv(1) << "RP:sdata " << have_sd << sdata;
166 DbgLv(1) << "RP:ti_noise count" << (have_ti ? ti_noise->count : 0);
167 DbgLv(1) << "RP:ri_noise count" << (have_ri ? ri_noise->count : 0);
168  }
169 
170  else
171  {
172 DbgLv(1) << "RP:edata " << have_ed;
173  qDebug() << "*ERROR* unable to get RP parent";
174  }
175 
176  ck_subtin->setEnabled( have_ti );
177  ck_subrin->setEnabled( have_ri );
178  ck_addtin->setEnabled( have_ti );
179  ck_addrin->setEnabled( have_ri );
180  ck_plttin->setEnabled( have_ti );
181  ck_pltrin->setEnabled( have_ri );
182 
183  ck_plteda->setChecked( true );
184  ck_subtin->setChecked( have_ti );
185  ck_subrin->setChecked( have_ri );
186 
187  skip_plot = false;
188  data_plot1->resize( p1size );
189  data_plot2->resize( p2size );
190 
191  plot_data();
192 
193  setVisible( true );
194  resize( p2size );
195 }
196 
197 // plot-experimental-data box [un]checked
198 void US_ResidPlot2D::pedaCheck( bool chkd )
199 {
200  if ( chkd )
201  { // box is being checked: sub boxes enabled if data present
202  ck_subtin->setEnabled( have_ti );
203  ck_subrin->setEnabled( have_ri );
204  }
205 
206  else
207  { // box is being unchecked: sub boxes disabled
208  ck_subtin->setEnabled( false );
209  ck_subrin->setEnabled( false );
210  }
211 
212  plot_data();
213 }
214 
215 // subtract-ti-noise box [un]checked
217 {
218  plot_data();
219 }
220 
221 // subtract-ri-noise box [un]checked
223 {
224  plot_data();
225 }
226 
227 // plot-simulation-data box [un]checked
228 void US_ResidPlot2D::psdaCheck( bool chkd )
229 {
230  if ( chkd )
231  { // box is being checked: sub boxes enabled if data present
232  ck_addtin->setEnabled( have_ti );
233  ck_addrin->setEnabled( have_ri );
234  }
235 
236  else
237  { // box is being unchecked: sub boxes disabled
238  ck_addtin->setEnabled( false );
239  ck_addrin->setEnabled( false );
240  }
241 
242  plot_data();
243 }
244 
245 // add-ti-noise box [un]checked
247 {
248  plot_data();
249 }
250 
251 // add-ri-noise box [un]checked
253 {
254  plot_data();
255 }
256 
257 // plot-residuals box [un]checked
258 void US_ResidPlot2D::presCheck( bool chkd )
259 {
260  skip_plot = true;
261 
262  if ( chkd )
263  { // alternate residual plots unchecked
264  ck_plttin->setChecked( false );
265  ck_pltrin->setChecked( false );
266  ck_pltran->setChecked( false );
267  }
268 
269  skip_plot = false;
270 
271  plot_data();
272 }
273 
274 // plot-ti-noise box [un]checked
275 void US_ResidPlot2D::ptinCheck( bool chkd )
276 {
277  skip_plot = true;
278 
279  if ( chkd )
280  { // alternate residual plots unchecked
281  ck_pltres->setChecked( false );
282  ck_pltrin->setChecked( false );
283  ck_pltran->setChecked( false );
284  }
285 
286  skip_plot = false;
287 
288  plot_data();
289 }
290 
291 // plot-ri-noise box [un]checked
292 void US_ResidPlot2D::prinCheck( bool chkd )
293 {
294  skip_plot = true;
295 
296  if ( chkd )
297  { // alternate residual plots unchecked
298  ck_pltres->setChecked( false );
299  ck_plttin->setChecked( false );
300  ck_pltran->setChecked( false );
301  }
302 
303  skip_plot = false;
304 
305  plot_data();
306 }
307 
308 // plot-random-noise box [un]checked
309 void US_ResidPlot2D::pranCheck( bool chkd )
310 {
311  skip_plot = true;
312 
313  if ( chkd )
314  { // alternate residual plots unchecked
315  ck_pltres->setChecked( false );
316  ck_plttin->setChecked( false );
317  ck_pltrin->setChecked( false );
318  }
319 
320  skip_plot = false;
321 
322  plot_data();
323 }
324 
325 // show-residual-bitmap box [un]checked
326 void US_ResidPlot2D::srbmCheck( bool chkd )
327 {
328  if ( chkd )
329  { // bitmap checked: replot to possibly build new map
330 
331  if ( have_bm )
332  { // if bitmap exists already, detect when closed
333  connect( resbmap, SIGNAL( destroyed() ),
334  this, SLOT( resids_closed() ) );
335  }
336 
337  plot_data();
338  }
339 }
340 
341 // close button clicked
343 {
344  if ( resbmap != 0 )
345  {
346  resbmap->close();
347  }
348 
349  close();
350 }
351 
352 // plot the data
354 {
355  if ( skip_plot ) // avoid redundant successive calls
356  return;
357 
358  plot_edata(); // plot experimental
359 
360  plot_rdata(); // plot residuals
361 }
362 
363 // plot the experimental data
365 {
366  data_plot1->detachItems();
367  data_plot1->clear();
368 
369  bool do_plteda = have_ed && ck_plteda->isChecked();
370  bool do_pltsda = have_sd && ck_pltsda->isChecked();
371  bool do_addtin = have_ti && ck_addtin->isChecked();
372  bool do_subtin = have_ti && ck_subtin->isChecked();
373  bool do_addrin = have_ri && ck_addrin->isChecked();
374  bool do_subrin = have_ri && ck_subrin->isChecked();
375 
376  int points = 0;
377  int count = 0;
378  double tinoi = 0.0;
379  double rinoi = 0.0;
380  double rl = 0.0;
381  //double vh = 9999.0;
382  double sval;
383 
384  if ( have_ed )
385  {
386  points = edata->pointCount();
387  rl = edata->radius( 0 );
388  //vh = edata->value( 0, points - 1 );
389  //vh *= 1.05;
390  }
391 
392  if ( !do_plteda && !do_pltsda )
393  { // no real experimental plot specified: re-do plot and return
394  data_plot1->replot();
395  return;
396  }
397 
398  if ( do_plteda && ! do_pltsda )
399  data_plot1->setTitle( tr( "Experimental Data" ) );
400 
401  else if ( do_plteda && do_pltsda )
402  data_plot1->setTitle( tr( "Experimental and Simulated Data" ) );
403 
404  else
405  data_plot1->setTitle( tr( "Simulated Data" ) );
406 
407  us_grid( data_plot1 );
408 
409  if ( do_plteda )
410  { // set title and values count for experimental data
411  data_plot1->setAxisTitle( QwtPlot::yLeft,
412  tr( "Absorbance at " ) + edata->wavelength + tr( " nm" ) );
413  points = edata->pointCount();
414  }
415 
416  if ( do_pltsda )
417  { // set title and values count for simulation data
418  if ( have_ed )
419  data_plot1->setAxisTitle( QwtPlot::yLeft,
420  tr( "Absorbance at " ) + edata->wavelength + tr( " nm" ) );
421  else
422  data_plot1->setAxisTitle( QwtPlot::yLeft, tr( "Absorbance" ) );
423 
424  count = sdata->pointCount();
425  }
426 
427  count = ( points > count ) ? points : count; // maximum array count
428 
429  QVector< double > rvec( count, 0.0 );
430  QVector< double > vvec( count, 0.0 );
431 
432  double* rr = rvec.data();
433  double* vv = vvec.data();
434 
435  QString title;
436  QwtPlotCurve* curv;
437  QPen pen_red( Qt::red );
438  QPen pen_plot( US_GuiSettings::plotCurve() );
439 
440  if ( do_plteda )
441  { // plot experimental curves
442  points = edata->pointCount();
443  count = edata->scanCount();
444  rinoi = 0.0;
445  tinoi = 0.0;
446 
447  for ( int jj = 0; jj < points; jj++ )
448  { // get radii (x) just once
449  rr[ jj ] = edata->radius( jj );
450  }
451 
452  for ( int ii = 0; ii < count; ii++ )
453  { // get readings (y) for each scan
454  if ( excllist->contains( ii ) ) continue;
455 
456  if ( do_subrin )
457  rinoi = ri_noise->values[ ii ];
458 
459  for ( int jj = 0; jj < points; jj++ )
460  { // each y is reading, optionally minus some noise
461  if ( do_subtin )
462  tinoi = ti_noise->values[ jj ];
463 
464  vv[ jj ] = edata->value( ii, jj ) - rinoi - tinoi;
465  }
466 
467  title = tr( "Curve " ) + QString::number( ii );
468  curv = us_curve( data_plot1, title );
469 
470  curv->setPen( pen_plot );
471  curv->setData( rr, vv, points );
472  }
473  }
474 
475  if ( do_pltsda )
476  { // plot simulation curves
477  points = sdata->pointCount();
478  count = sdata->scanCount();
479  rinoi = 0.0;
480  tinoi = 0.0;
481 
482  for ( int jj = 0; jj < points; jj++ )
483  { // get radii (x) just once
484  rr[ jj ] = sdata->radius( jj );
485  }
486 
487  for ( int ii = 0; ii < count; ii++ )
488  { // get readings (y) for each scan
489  if ( excllist->contains( ii ) ) continue;
490 
491  if ( do_addrin )
492  rinoi = ri_noise->values[ ii ];
493 
494  for ( int jj = 0; jj < points; jj++ )
495  { // each y is reading, optionally plus some noise
496  if ( do_addtin )
497  tinoi = ti_noise->values[ jj ];
498 
499  if ( rr[ jj ] >= rl )
500  sval = sdata->value( ii, jj ) + rinoi + tinoi;
501 
502  else
503  sval = edata->value( ii, jj ) - rinoi - tinoi;
504 
505  //if ( sval > vh )
506  // sval = vv[ jj - 1 ];
507 
508  vv[ jj ] = sval;
509  }
510 
511  title = tr( "S-Curve " ) + QString::number( ii );
512  curv = us_curve( data_plot1, title );
513 
514  curv->setPen( pen_red );
515  curv->setData( rr, vv, points );
516  }
517  }
518 
519  data_plot1->replot();
520 }
521 
522 // plot the residual data
524 {
525  data_plot2->detachItems();
526  data_plot2->clear();
527 
528  bool do_pltres = have_ed && ck_pltres->isChecked() && have_sd;
529  bool do_plttin = have_ti && ck_plttin->isChecked();
530  bool do_pltrin = have_ri && ck_pltrin->isChecked();
531  bool do_pltran = have_ed && ck_pltran->isChecked() && have_sd;
532  bool do_shorbm = have_ed && ck_shorbm->isChecked() && have_sd;
533  bool do_addtin = have_ti && ck_addtin->isChecked();
534  bool do_subtin = have_ti && ck_subtin->isChecked();
535  bool do_addrin = have_ri && ck_addrin->isChecked();
536  bool do_subrin = have_ri && ck_subrin->isChecked();
537 
538  int points = edata->pointCount();
539  int count = edata->scanCount();
540  double tinoi = 0.0;
541  double rinoi = 0.0;
542  double rmsd = 0.0;
543 
544  if ( !do_pltres && !do_plttin && !do_pltrin &&
545  !do_pltran && !do_shorbm )
546  { // if no plots specified, just clean up plot and return
547  data_plot2->replot();
548  return;
549  }
550 
551  us_grid( data_plot2 );
552  data_plot2->setAxisTitle( QwtPlot::xBottom, tr( "Radius (cm)" ) );
553 
554  int vsize = qMax( sdata->pointCount(), qMax( points, count ) );
555 
556  QVector< double > rvec( vsize, 0.0 );
557  QVector< double > vvec( vsize, 0.0 );
558 
559  double* rr = rvec.data();
560  double* vv = vvec.data();
561 
562  QString title;
563  QwtPlotCurve* curv;
564  QPen pen_plot( Qt::green );
565 
566  // plot a zero line in red
567  double xlo = edata->radius( 0 ) - 0.05;
568  double xhi = edata->radius( points - 1 ) + 0.05;
569  rr[ 0 ] = !do_pltrin ? xlo : 0.0;
570  rr[ 1 ] = !do_pltrin ? xhi : double( count );
571  vv[ 0 ] = 0.0;
572  vv[ 1 ] = 0.0;
573  curv = us_curve( data_plot2, "zero-line" );
574  curv->setPen( QPen( QBrush( Qt::red ), 2 ) );
575  curv->setData( rr, vv, 2 );
576 
577  if ( do_pltres )
578  { // plot residuals
579  data_plot2->setTitle( tr( "Residuals" ) );
580 
581  for ( int jj = 0; jj < points; jj++ )
582  { // get radii (x) just once
583  rr[ jj ] = sdata->radius( jj );
584  }
585 
586  int kntva = 0;
587 
588  for ( int ii = 0; ii < count; ii++ )
589  { // get readings (y) for each scan
590  if ( excllist->contains( ii ) ) continue;
591 
592  rinoi = 0.0;
593  if ( do_subrin )
594  rinoi = ri_noise->values[ ii ];
595  if ( do_addrin )
596  rinoi += ri_noise->values[ ii ];
597 
598  for ( int jj = 0; jj < points; jj++ )
599  { // each residual is e-value minus s-value
600  tinoi = 0.0;
601  if ( do_subtin )
602  tinoi = ti_noise->values[ jj ];
603  if ( do_addtin )
604  tinoi += ti_noise->values[ jj ];
605 
606  vv[ jj ] = edata->value( ii, jj ) - sdata->value( ii, jj )
607  - rinoi - tinoi;
608  rmsd += sq( vv[ jj ] );
609  kntva++;
610  }
611 
612  title = tr( "resids " ) + QString::number( ii );
613  curv = us_curve( data_plot2, title );
614 
615  curv->setPen( pen_plot );
616  curv->setStyle( QwtPlotCurve::Dots );
617  curv->setData( rr, vv, points );
618  }
619 
620  // display variance and RMSD
621  rmsd /= (double)( kntva );
622  le_vari->setText( QString::number( rmsd ) );
623  rmsd = sqrt( rmsd );
624  le_rmsd->setText( QString::number( rmsd ) );
625 //DbgLv(1) << "RP:(1res)rmsd" << rmsd;
626 //*Debug
627 //DbgLv(1) << "BEFORE data00" << edata->value(0,0);
628 //ti_noise->apply_to_data(*edata);
629 //DbgLv(1) << " TIrmv data00" << edata->value(0,0);
630 //ti_noise->apply_to_data(*edata,false);
631 //DbgLv(1) << " TIadd data00" << edata->value(0,0);
632 //ri_noise->apply_to_data(*edata);
633 //DbgLv(1) << " RIrmv data00" << edata->value(0,0);
634 //ri_noise->apply_to_data(*edata,false);
635 //DbgLv(1) << " RIadd data00" << edata->value(0,0);
636 //US_Noise::apply_noise(*edata,ti_noise);
637 //DbgLv(1) << " TIrmv data00" << edata->value(0,0);
638 //US_Noise::apply_noise(*edata,ti_noise,false);
639 //DbgLv(1) << " TIadd data00" << edata->value(0,0);
640 //US_Noise::apply_noise(*edata,ri_noise);
641 //DbgLv(1) << " RIrmv data00" << edata->value(0,0);
642 //US_Noise::apply_noise(*edata,ri_noise,false);
643 //DbgLv(1) << " RIadd data00" << edata->value(0,0);
644  }
645 
646  else if ( do_plttin )
647  { // plot time-invariant noise
648  data_plot2->setTitle( tr( "Time-Invariant Noise" ) );
649 
650  for ( int jj = 0; jj < points; jj++ )
651  { // accumulate radii and noise values
652  rr[ jj ] = edata->radius( jj );
653  vv[ jj ] = ti_noise->values[ jj ];
654  }
655 
656  title = tr( "ti_noise" );
657  curv = us_curve( data_plot2, title );
658 
659  curv->setPen( pen_plot );
660  curv->setData( rr, vv, points );
661  }
662 
663  else if ( do_pltrin )
664  { // plot radially-invariant noise
665  data_plot2->setTitle( tr( "Radially-Invariant Noise" ) );
666 
667  for ( int ii = 0; ii < count; ii++ )
668  { // accumulate scan numbers and noise values
669  rr[ ii ] = (double)( ii + 1 );
670  vv[ ii ] = ri_noise->values[ ii ];
671  }
672 
673  title = tr( "ri_noise" );
674  curv = us_curve( data_plot2, title );
675 
676  data_plot2->setAxisTitle( QwtPlot::xBottom, tr( "Scan Number" ) );
677  curv->setPen( pen_plot );
678  curv->setData( rr, vv, count );
679  }
680 
681  else if ( do_pltran )
682  { // plot random noise
683  data_plot2->setTitle( tr( "Random Noise" ) );
684 
685  for ( int jj = 0; jj < points; jj++ )
686  { // get radii (x) just once
687  rr[ jj ] = sdata->radius( jj );
688  }
689 
690  int kntva = 0;
691 
692  for ( int ii = 0; ii < count; ii++ )
693  { // get random noise (y) for each scan
694  if ( excllist->contains( ii ) ) continue;
695 
696  rinoi = have_ri ? ri_noise->values[ ii ] : 0.0;
697 
698  for ( int jj = 0; jj < points; jj++ )
699  { // each random value is e-value minus s-value with optional noise
700  tinoi = have_ti ? ti_noise->values[ jj ] : 0.0;
701 
702  vv[ jj ] = edata->value( ii, jj ) - sdata->value( ii, jj )
703  - rinoi - tinoi;
704  rmsd += sq( vv[ jj ] );
705  kntva++;
706  }
707 
708  title = tr( "random noise " ) + QString::number( ii );
709  curv = us_curve( data_plot2, title );
710 
711  curv->setPen( pen_plot );
712  curv->setStyle( QwtPlotCurve::Dots );
713  curv->setData( rr, vv, points );
714  }
715 
716  // display variance and RMSD
717  rmsd /= (double)( kntva );
718  le_vari->setText( QString::number( rmsd ) );
719  rmsd = sqrt( rmsd );
720  le_rmsd->setText( QString::number( rmsd ) );
721 //DbgLv(1) << "RP:(2ran)rmsd" << rmsd;
722  }
723 
724 
725  if ( do_shorbm )
726  { // show residuals bitmap (if not already shown)
727 
728  QVector< QVector< double > > resids;
729  QVector< double > resscan;
730 
731  resids .resize( count );
732  resscan.resize( points );
733  rmsd = 0.0;
734  int kntva = 0;
735 
736  for ( int ii = 0; ii < count; ii++ )
737  { // build a vector for each scan
738  if ( excllist->contains( ii ) )
739  {
740  resscan.fill( 0.0 );
741  resids[ ii ] = resscan;
742  continue;
743  }
744 
745  rinoi = 0.0;
746  if ( do_subrin )
747  rinoi = ri_noise->values[ ii ];
748  if ( do_addrin )
749  rinoi += ri_noise->values[ ii ];
750 
751  for ( int jj = 0; jj < points; jj++ )
752  { // build residual values within a scan
753  tinoi = 0.0;
754  if ( do_subtin )
755  tinoi = ti_noise->values[ jj ];
756  if ( do_addtin )
757  tinoi += ti_noise->values[ jj ];
758 
759 
760  resscan[ jj ] = edata->value( ii, jj ) - sdata->value( ii, jj )
761  - rinoi - tinoi;
762  rmsd += sq( resscan[ jj ] );
763  kntva++;
764  }
765 
766  resids[ ii ] = resscan;
767  }
768 
769  rmsd /= (double)( kntva );
770  le_vari->setText( QString::number( rmsd ) );
771  rmsd = sqrt( rmsd );
772  le_rmsd->setText( QString::number( rmsd ) );
773 
774  if ( resbmap )
775  { // already have resbmap: just replot residuals bitmap
776  resbmap->replot( resids );
777  resbmap->raise();
778  }
779 
780  else
781  { // pop up a little dialog with residuals bitmap
782  resbmap = new US_ResidsBitmap( resids );
783  connect( resbmap, SIGNAL( destroyed() ),
784  this, SLOT( resids_closed() ) );
785  resbmap->move( this->pos() + QPoint( 100, 100 ) );
786  resbmap->show();
787  resbmap->raise();
788  }
789 
790  qApp->processEvents();
791  }
792 
793  // display curves we have created; then clean up
794 
795  data_plot2->setAxisScale( QwtPlot::xBottom, xlo, xhi );
796  data_plot2->replot();
797 }
798 
799 // react to residual bitmap having been closed
801 {
802 DbgLv(1) << "Resids BitMap Closed!!!";
803  resbmap = 0;
804  have_bm = false;
805  ck_shorbm->setChecked( false );
806 }
807