]> jspc29.x-matter.uni-frankfurt.de Git - coral.git/commitdiff
improvements to the spectrum viewer
authorMaps <maps@ikf>
Wed, 27 May 2015 18:27:17 +0000 (20:27 +0200)
committerMaps <maps@ikf>
Wed, 27 May 2015 18:27:17 +0000 (20:27 +0200)
user_interface/coral_scanner.js
user_interface/coral_scanner.pm
user_interface/pmt_ro.pl
user_interface/pmt_ro.pm

index 5c4e239560a8fcdec7f49bb3d77a8b6f4e3ba5a1..d3145a0f89db115c743264e4a9ee13cbdd6c5c50 100644 (file)
@@ -88,6 +88,9 @@ $(document).ready(function(){
   $("#button_clear_spectrum").click(function(){
     clear_spectrum();
   });
+  $("#button_delete_selected").click(function(){
+    spectrum_delete();
+  });
   $("#button_record_spectrum").click(function(){
     record_spectrum();
   });
@@ -125,6 +128,10 @@ $(document).ready(function(){
 //     alert($(this).prop('checked'));
     plot_spectrum();
   });
+  $('#checkbox_diff_spectrum').change(function(){
+//     alert($(this).prop('checked'));
+    plot_spectrum();
+  });
   
   $( "#progressbar" ).progressbar({
     value: 1000
@@ -210,8 +217,19 @@ function plot_choices() {
         "<label for='id" + key + "'>"
         + key + "</label>");
     });
-    
     choiceContainer.find("input").click(function(){plot_spectrum();});
+    
+    
+    // select all or none with one master checkbox
+    choiceContainer.append("<br><hr><input type='checkbox' id='checkbox_allnone' checked='true'></input>"
+    + "<label for='checkbox_allnone'>select all/none</label>");
+    $('#checkbox_allnone').click(function(){
+      var master = $(this);
+      choiceContainer.find("input").each(function(){
+        $(this).prop( "checked", master.prop("checked") );
+      });
+      plot_spectrum();
+    });
   
   
 }
@@ -231,11 +249,25 @@ function plot_spectrum() {
   
   $('#choices').find("input:checked").each(function () {
         var key = $(this).attr("name");
+        
+        
         if (key && spectrum[key]) {
 //           data.push(datasets[key]);
+          var dataset = spectrum[key].data;
+          
+          if($('#checkbox_diff_spectrum').prop('checked') == true){
+            var diff = [];
+            
+            for (var i = 0; i < dataset.length; i++) {
+              if(i > 0) {
+                diff.push([(dataset[i][0]+dataset[i-1][0])/2, dataset[i][1]-dataset[i-1][1] ]);
+              }
+            }
+            dataset = diff;
+          }
           data.push(
             {
-              data: spectrum[key].data,
+              data: dataset,
               bars: { show: true ,  barWidth: 0.8*parseFloat(spectrum[key].meta.bin_width), align: "center" },
               label: key
             }
@@ -565,4 +597,25 @@ function record_spectrum(){
           plot_spectrum();
         }
      });
+}
+
+function spectrum_delete(){
+  var runs = $('#choices input[type=checkbox]:checked').map(function() {
+    return $(this).attr("name");
+  }).get().join(',');
+  $.ajax({
+        url:       "pmt_ro.pl",
+        cache:     false,
+        async:     true,
+        dataType:  "text",
+        data:      {
+            sub      : "spectrum_delete",
+            runs     : runs
+        },
+        success:   function(answer) {
+          spectrum = get_spectrum_JSON();
+          plot_choices();
+          plot_spectrum();
+        }
+     });
 }
\ No newline at end of file
index aec62a61f5116fbf020a5eeeca483cdb6a8cb09e..64d5682d1cd160df691ec60fc3de71234160e907 100644 (file)
@@ -189,7 +189,9 @@ sub main_html {
   print "</td></tr></table>";
   print "<input type='button' id='button_plot_spectrum' value='plot spectrum'>";
   print "<input type='button' id='button_clear_spectrum' value='clear spectrum'>";
+  print "<input type='button' id='button_delete_selected' value='delete selected'>";
   print "<label><input type='checkbox' id='checkbox_log_spectrum' >log y</label>";
+  print "<label><input type='checkbox' id='checkbox_diff_spectrum' >diff</label>";
   print br;
   print "record name: ";
   print "<input type='text' id='text_spectrum_name' value='signal'>";
index 88adc61ac9d79f062ae89efa6fdcfbca6c3fb5c9..f8dd8ac53536080c1e241d0528895f0198d2f0ed 100755 (executable)
@@ -33,6 +33,8 @@ my $dispatch_table = {
   dead_time => 1,
   apply_device_settings => 1,
   spectrum_JSON => 1,
+  spectrum_csv  => 1,
+  spectrum_delete  => 1,
   clear_spectrum => 1,
   acquisition_time => 1
 };
index b0d6fccdd44fedd8fe0f75c8d026ebea0255960f..a06689c01de5e4b36a3c0af1e51a9d0e3c40f420 100644 (file)
@@ -229,6 +229,46 @@ sub spectrum_JSON {
 
 }
 
+sub spectrum_delete {
+  my $self = shift;
+  my %options = @_;
+  
+  my @runs = split(",",$options{runs});
+  
+  my $spectrum = $self->{spectrum_shm}->readShm();
+  for my $run (@runs){
+    delete $spectrum->{$run};
+  }
+  $self->{spectrum_shm}->writeShm($spectrum);
+  return " ";
+
+}
+
+sub spectrum_csv {
+  my $self = shift;
+  
+  my $spectrum = $self->{spectrum_shm}->readShm();
+  
+  for my $key (keys %$spectrum){
+    my $run = $spectrum->{$key};
+    print "run name:\t".$key."\n";
+    for my $info (sort keys %{$run->{meta}}){
+      print $info.":\t".$run->{meta}->{$info}."\n";
+    }
+    print "\n";
+    print "threshold\tcounts\n";
+    for my $data_pair (@{$run->{data}}){
+      print $data_pair->[0]."\t".$data_pair->[1]."\n";
+    }
+    
+    print "\n";
+    print "\n";
+  
+  }
+  return " ";
+
+}
+
 sub clear_spectrum {
   my $self = shift;