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