From 70f95dae98ecd1a1daca61e74f007cb64b04642e Mon Sep 17 00:00:00 2001 From: Cbm Rich Date: Mon, 17 Nov 2014 10:18:35 +0100 Subject: [PATCH] Update off scripts for CBM RICH --- dmon/scripts/dmon_billboard.pl | 10 ++-- thresholds/thresholds_automatic_jan.pl | 48 +++++++------------ thresholds/write_thresholds.pl | 7 +-- .../prepare_padiwas_invert_leds.pl | 11 +++++ users/cern_cbmrich/startup.sh | 4 ++ .../thresh/thresholds_padiwa_amps.thr | 1 + users/cern_cbmrich/thresholds_compare.pl | 2 +- 7 files changed, 43 insertions(+), 40 deletions(-) diff --git a/dmon/scripts/dmon_billboard.pl b/dmon/scripts/dmon_billboard.pl index 68345fa..a1e1ba5 100755 --- a/dmon/scripts/dmon_billboard.pl +++ b/dmon/scripts/dmon_billboard.pl @@ -15,7 +15,7 @@ my %config = Dmon::StartUp(); my $t0; for(my $i = 0; $i< 16 ; $i++) { - Perl2Epics::Connect("PC".$i, sprintf('CBM:PWRSWITCH:GetCurrent%02x',$i)); + Perl2Epics::Connect("PC".$i, sprintf('CBM:PWRSWITCH:GetCurrent%02X',$i)); Perl2Epics::Connect("HV_U".$i, sprintf('OUTPUT_TERMINAL_VOLTAGE_U%d',$i)); Perl2Epics::Connect("HV_I".$i, sprintf('MEASUREMENT_CURRENT_U%d',$i)); @@ -42,12 +42,14 @@ while(1) { my $milAmp = $epicsData->{"PC".$i}->{"val"} * 1000; $reg = 0 unless $i & 1; $reg |= ($milAmp & 0xffff) << (16 * ($i&1)); - push @billboardValues, $reg if $i & 1; + + push(@billboardValues, $reg) if ($i & 1); } + # threshold timestamp - my $threshTime = do($config{UserDirectory} . '/thresh/billboard_info') || 0; - push @billboardValues, $threshTime & 0xffffffff; + my $threshTime = do($config{UserDirectory} . '/thresh/billboard_info'); + push @billboardValues, ($threshTime & 0xffffffff); # hv values for(my $i=0; $i < 16; $i++) { diff --git a/thresholds/thresholds_automatic_jan.pl b/thresholds/thresholds_automatic_jan.pl index 2987bc4..4c87e64 100755 --- a/thresholds/thresholds_automatic_jan.pl +++ b/thresholds/thresholds_automatic_jan.pl @@ -4,9 +4,7 @@ use strict; use warnings; use Data::Dumper; -use lib "/home/hadaq/trbsoft/daqtools/dmon/code"; use Dmon; - use Getopt::Long; use Time::HiRes qw(time usleep); use Log::Log4perl qw(get_logger); @@ -14,19 +12,6 @@ use List::Util qw(min max); use POSIX qw(strftime); use HADES::TrbNet; -# use IPC::ShareLite qw( :lock ); - -use constant false => 0; -use constant true => 1; - -# my $share = IPC::ShareLite->new( -# -key => 3214, -# -create => 'yes', -# -destroy => 'yes' -# ) or die $!; -# -# $share->store("dummy text"); -#print "store res: $r\n"; my $hitregister = 0xc001; @@ -35,7 +20,7 @@ my $start_value = 0x7000; my $sleep_time = 1.0; my $accepted_dark_rate = 150; -my $number_of_iterations = 50; # at least 15 are recommended +my $number_of_iterations = 50; my $endpoint = 0x0303; my $mode = "padiwa"; @@ -44,7 +29,7 @@ my $offset = 0; my $polarity = 1; my @channels = (); my $channel32 = undef; -my $opt_finetune = false; +my $opt_finetune = 0; our $chain = 0; @@ -117,20 +102,19 @@ my @current_thresh = ($start_value) x 16; my @best_thresh = (0) x 16; my @hit_diff = (0) x 16; my @crossed_thresh = (0) x 16; -my @interval_step = ($interval_step) x 16; + my @make_it_quiet; my $rh_res; my $old_rh_res; -if ($opt_finetune == true) { - my $ra_thresh = read_thresholds("padiwa", $chain); - @current_thresh = @$ra_thresh; - print Dumper \@current_thresh; - - $interval_step = 4; - -} +if ($opt_finetune) { + my $ra_thresh = read_thresholds("padiwa", $chain); + @current_thresh = @$ra_thresh; +# print Dumper \@current_thresh; + $interval_step = 2; + } +my @interval_step = ($interval_step) x 16; # foreach my $i (0..15) { @@ -170,7 +154,7 @@ while ($number_of_steps < $number_of_iterations) { $hit_diff += 2**24 if $hit_diff < 0; $hit_diff[$i] = $hit_diff; - if($number_of_steps > $number_of_iterations - 10) { + if($number_of_steps > $number_of_iterations - 10 || $opt_finetune) { # select best threshold, closest from bottom if( $hit_diff[$i] <= $accepted_dark_rate && $best_thresh[$i] <= $current_thresh[$i] @@ -191,11 +175,11 @@ while ($number_of_steps < $number_of_iterations) { } elsif ($hit_diff > $accepted_dark_rate && $hit_diff < 10000 ) { - $current_thresh[$i] -= max($interval_step * $polarity , 0x10); + $current_thresh[$i] -= max($interval_step * $polarity , $opt_finetune?0x2:0x10); $interval_step = max(int($interval_step/2),4); } elsif ($hit_diff > $accepted_dark_rate ) { - $current_thresh[$i] -= max($interval_step * 2 * $polarity , 0x50); + $current_thresh[$i] -= max($interval_step * 2 * $polarity , $opt_finetune?0x4:0x50); $interval_step = max(int($interval_step/2),0x10); if ($hit_diff > 20000) { $make_it_quiet[$i] = 1; @@ -240,7 +224,7 @@ foreach my $i (reverse (0..3)) { my $str; -$logger_data->info(time); +$logger_data->info("\t".time); foreach my $i (0..15) { $logger_data->info(sprintf "endpoint: 0x%04x, chain: %02d, channel: %2d threshold: 0x%04x, uid: %s", $endpoint, $chain, $i, $best_thresh[$i], $uid ); } @@ -271,8 +255,8 @@ sub read_thresholds { } $command = $fixed_bits | ($current_channel << 16) ; - my $rh_res = Dmon::PadiwaSendCmd($endpoint, $chain, $command); - push (@thresh , $rh_res->{$endpoint}); + my $rh_res = Dmon::PadiwaSendCmd($command, $endpoint, $chain, ); + push (@thresh , $rh_res->{$endpoint} & 0xFFFF); } diff --git a/thresholds/write_thresholds.pl b/thresholds/write_thresholds.pl index 486d894..cc18e8d 100755 --- a/thresholds/write_thresholds.pl +++ b/thresholds/write_thresholds.pl @@ -49,11 +49,12 @@ my @f = <$fh>; #Put Information to logfile and timestamp to billboard information chomp $f[0]; -system("echo ".time.' '.strftime("%Y-%m-%d %H:%M:%S",localtime()).' '." $f[0]>>threshold_log.txt"); +system("echo \"".strftime("%Y-%m-%d %H:%M:%S",localtime()).'\t'.time.'\t'. + $offset.'\t'.$f[0]."\">>threshold_log.txt"); my ($t) = $f[0] =~ /(\d{10})/; -system("echo $t>billboard_info"); +system("echo $t>thresh/billboard_info"); + -exit; my $count=0; foreach my $cl (@f) { (my $ep, my $chain, my $channel, my $thresh, my $uid) = diff --git a/users/cern_cbmrich/prepare_padiwas_invert_leds.pl b/users/cern_cbmrich/prepare_padiwas_invert_leds.pl index 0ab3d36..4a373cb 100755 --- a/users/cern_cbmrich/prepare_padiwas_invert_leds.pl +++ b/users/cern_cbmrich/prepare_padiwas_invert_leds.pl @@ -41,6 +41,17 @@ foreach (@padiwas) { $pm->finish; # Terminates the child process }; +# print "padiwas: set temperature compensation: "; +# +# foreach (@padiwas) { +# my $pid = $pm->start and next; +# print "$_ "; +# my $c="/home/hadaq/trbsoft/daqtools/padiwa.pl $_ 0 comp 0x02c0 >/dev/null"; +# qx($c); die "could not execute command $c" if $?; +# $pm->finish; # Terminates the child process +# }; + + $pm->wait_all_children; print "\n"; diff --git a/users/cern_cbmrich/startup.sh b/users/cern_cbmrich/startup.sh index 832cdc9..0a14b21 100755 --- a/users/cern_cbmrich/startup.sh +++ b/users/cern_cbmrich/startup.sh @@ -191,8 +191,12 @@ echo "Disable noisy pixel in Padiwa" #trbcmd clearbit 0x8103 0xc1 0xf6 #trbcmd clearbit 0x8103 0xc3 0xf6 +# trbcmd setbit 0x7005 0xa00c 0x80000000 + echo "Wait a sec (http://goo.gl/bdWW1g)" sleep 1 trbcmd w 0x7005 0xa101 0xffff6004 # trg_channel_mask: edge=1111 1111 1111 1111, mask=0110 0000 0000 0100 echo "Trigger activated. I'm done" + + diff --git a/users/cern_cbmrich/thresh/thresholds_padiwa_amps.thr b/users/cern_cbmrich/thresh/thresholds_padiwa_amps.thr index 7581a16..a58402c 100644 --- a/users/cern_cbmrich/thresh/thresholds_padiwa_amps.thr +++ b/users/cern_cbmrich/thresh/thresholds_padiwa_amps.thr @@ -1,3 +1,4 @@ +2000/00/00 00:00:00 0000000000.00000 Padiwa Amps Thresholds 2014/10/20 00:00:00 endpoint: 0x0111, chain: 00, channel: 00 threshold: 0x0697, uid: 0 2014/10/20 00:00:00 endpoint: 0x0111, chain: 00, channel: 01 threshold: 0xDA00, uid: 0 2014/10/20 00:00:00 endpoint: 0x0111, chain: 00, channel: 02 threshold: 0x0744, uid: 0 diff --git a/users/cern_cbmrich/thresholds_compare.pl b/users/cern_cbmrich/thresholds_compare.pl index 5efffc4..ebc2c1b 100755 --- a/users/cern_cbmrich/thresholds_compare.pl +++ b/users/cern_cbmrich/thresholds_compare.pl @@ -43,11 +43,11 @@ sub readSettings { close $fh; my %thresholds = (); - my $count=0; foreach my $cl (@f) { (my $ep, my $chain, my $channel, my $thresh, my $uid) = $cl =~ /endpoint:\s+(\w+), chain:\s+(\d+), channel:\s+(\d+) threshold:\s+(\w+), uid: (\w+)/; + next unless defined $ep; $thresholds{hex($ep) .":". int($channel)} = hex $thresh; } -- 2.43.0