!Pasttrec Baseline table
# Serial # PT # C0 # C1 # C2 # C3 # C4 # C5 # C6 # C7 #
############################################################################################
- 60031 0 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02
- 60031 1 0x03 0x03 0x03 0x03 0x03 0x03 0x03 0x03
- 60031 2 0x04 0x04 0x04 0x04 0x04 0x04 0x04 0x04
- 60031 3 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
-
- 70031 0 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02
- 70031 1 0x03 0x03 0x03 0x03 0x03 0x03 0x03 0x03
- 70031 2 0x04 0x04 0x04 0x04 0x04 0x04 0x04 0x04
- 70031 3 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
+
+ 60111 0 30 20 23 28 26 27 27 24
+ 60111 1 27 22 30 27 21 29 27 19
+ 60111 2 28 62 62 30 62 62 22 62
+ 60111 3 22 23 19 23 62 62 24 62
+ 60121 0 23 25 16 25 24 29 19 28
+ 60121 1 31 25 21 24 24 25 26 28
+ 60121 2 24 20 19 24 23 21 30 22
+ 60121 3 18 24 26 18 19 25 21 21
+ 70121 0 29 26 26 31 29 31 28 62
+ 70121 1 25 28 17 16 27 28 22 15
+ 70121 2 19 18 28 24 27 25 27 22
+ 70121 3 23 22 25 31 12 24 28 24
+ 70111 0 20 25 62 62 20 62 62 62
+ 70111 1 24 62 25 62 26 24 62 18
+ 70111 2 62 24 22 62 28 62 24 28
+ 70111 3 62 20 23 62 21 62 19 16
+
+
+
+ 60031 0 02 02 02 02 02 02 02 02
+ 60031 1 03 03 03 03 03 03 03 03
+ 60031 2 04 04 04 04 04 04 04 04
+ 60031 3 01 01 01 01 01 01 01 01
+
+ 70031 0 02 02 02 02 02 02 02 02
+ 70031 1 03 03 03 03 03 03 03 03
+ 70031 2 04 04 04 04 04 04 04 04
+ 70031 3 01 01 01 01 01 01 01 01
- 60161 0 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02
- 60161 1 0x03 0x03 0x03 0x03 0x03 0x03 0x03 0x03
-# 60161 2 0x04 0x04 0x04 0x04 0x04 0x04 0x04 0x04
- 60161 3 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
-
-# 70161 0 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02
-# 70161 1 0x03 0x03 0x03 0x03 0x03 0x03 0x03 0x03
-# 70161 2 0x04 0x04 0x04 0x04 0x04 0x04 0x04 0x04
-# 70161 3 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
+ 60161 0 02 02 02 02 02 02 02 02
+ 60161 1 03 03 03 03 03 03 03 03
+ 60161 2 04 04 04 04 04 04 04 04
+ 60161 3 01 01 01 01 01 01 01 01
+
+ 70161 0 02 02 02 02 02 02 02 02
+ 70161 1 03 03 03 03 03 03 03 03
+ 70161 2 04 04 04 04 04 04 04 04
+ 70161 3 01 01 01 01 01 01 01 01
+
+
+ 60011 0 02 02 02 02 02 02 02 02
+ 60011 1 03 03 03 03 03 03 03 03
+ 60011 2 04 04 04 04 04 04 04 04
+ 60011 3 01 01 01 01 01 01 01 01
+
+# 60081 0 0x17 0x16 0x0a 0x1b 0x12 0x18 0x15 0x0e
+# 60081 0 0x1e 0x1e 0x1e 0x1e 0x1e 0x1e 0x1e 0x1e
+# 60081 1 0x14 0x18 0x10 0x16 0x15 0x15 0x16 0x18
+# 60081 2 0x18 0x19 0x15 0x0f 0x1b 0x18 0x19 0x1a
+# 60081 3 0x13 0x14 0x15 0x18 0x18 0x17 0x1b 0x16
+#
+# 70081 0 0x00 0x16 0x0a 0x1b 0x12 0x16 0x15 0x0e
+# 70081 1 0x14 0x18 0x10 0x16 0x15 0x15 0x16 0x18
+# 70081 2 0x18 0x19 0x15 0x0f 0x1b 0x18 0x19 0x1a
+# 70081 3 0x13 0x14 0x15 0x18 0x18 0x17 0x1b 0x16
+#
+#
+# 60121 0 0x00 0x16 0x0a 0x1b 0x12 0x16 0x15 0x0e
+# 60121 1 0x14 0x18 0x10 0x16 0x15 0x15 0x16 0x18
+# 60121 2 0x18 0x19 0x15 0x0f 0x1b 0x18 0x19 0x1a
+# 60121 3 0x13 0x14 0x15 0x18 0x18 0x17 0x1b 0x16
my $LOAD_DIRECT = 1; #load settings and initialize
my $WRITE_FILES = 1; #write configration files
-my @default_settings = (0x50018, #1:0 peaking 10ns, 3:2 gain 1mV, 4 internal bandgap
+my @default_settings = (0x50010, #1:0 peaking 10ns, 3:2 gain 4mV, 4 internal bandgap
0x5011e, #2:0 tail1 R 27k, 5:3 tail1 C 10pF
0x50215, #2:0 tail1 R 23k, 5:3 tail1 C 0.9pF
- 0x50305, #6:0 global threshold 5=10mV
+ 0x50302, #6:0 global threshold 5=10mV
0x50400,0x50500,0x50600,0x50700,0x50800,0x50900,0x50a00,0x50b00,
0,0,0,0);
-my $baselines; #serial->pt->@baselines (in hex!)
+my $baselines; #serial->pt->@baselines
my $serials; #uid -> serial
my $addresses; #addr -> serial
my $settings; #addr -> @registers(0xa040-0xa07F)
###############################################################################
open FILE, "../pasttrec/pasttrec_baseline.db" or die $!."\npasttrec_baseline.db not found.";
while (my $a = <FILE>) {
- if(my @values = $a =~ /^\s*(\d+)\s+(\d)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s*$/) {
+ if(my @values = $a =~ /^\s*(\d+)\s+(\d)\s+(\w\w)\s+(\w\w)\s+(\w\w)\s+(\w\w)\s+(\w\w)\s+(\w\w)\s+(\w\w)\s+(\w\w)\s*$/) {
my $s = shift @values;
my $pt = shift @values;
$baselines->{$s}{$pt}=\@values;
foreach my $i (0..7) { #replace baselines
my $t = $settings->{$a}[$pt*16+4+$i];
$t &= 0xFFF00;
- $t += hex($baselines->{$addresses->{$a}}{$pt}[$i]);
+ $t += $baselines->{$addresses->{$a}}{$pt}[$i];
$settings->{$a}[$pt*16+4+$i] = $t;
}
}
--- /dev/null
+#!/usr/bin/perl -w
+use warnings;
+no warnings "portable";
+use FileHandle;
+use Getopt::Long;
+use Data::Dumper;
+use HADES::TrbNet;
+
+my $DEBUG = 0; #print debug messages
+my $LOAD_DIRECT = 1; #load settings and initialize
+my $WRITE_FILES = 1; #write configration files
+
+my @default_settings = (0x50010, #1:0 peaking 10ns, 3:2 gain 4mV, 4 internal bandgap
+ 0x5011e, #2:0 tail1 R 27k, 5:3 tail1 C 10pF
+ 0x50215, #2:0 tail1 R 23k, 5:3 tail1 C 0.9pF
+ 0x50302, #6:0 global threshold 5=10mV
+ 0x50400,0x50500,0x50600,0x50700,0x50800,0x50900,0x50a00,0x50b00,
+ 0,0,0,0);
+
+
+my $serials; #uid -> serial
+my $addresses; #addr -> serial
+my $settings; #addr -> @registers(0xa040-0xa07F)
+trb_init_ports() or die trb_strerror();
+
+sub init_pasttrecs {
+ foreach my $a (keys %$addresses) {
+ printf("board %04x found.\n",$a) if $DEBUG;
+ trb_register_write_mem($a,0xa002,0,[0x4c304c30,0x4c304c30],2);#set register sets
+ trb_register_write($a,0xaa00,1); #init Pasttrec
+
+ foreach my $pt (0..3) {
+ foreach my $i (0..11) {
+ trb_register_write($a,0xa200+($pt << 4)+$i,$default_settings[$i]);
+ }
+ }
+ }
+ }
+
+
+sub set_baseline {
+ my $baseline = $_[0] // 0;
+
+ foreach my $a (keys %$addresses) {
+ printf("board %04x found.\n",$a) if $DEBUG;
+ foreach my $pt (0..3) {
+ foreach my $i (4..11) {
+ trb_register_write($a,0xa200+($pt << 4)+$i,$default_settings[$i]+$baseline);
+ }
+ }
+ }
+ }
+
+
+
+###############################################################################
+#Read serials file and store values
+###############################################################################
+open FILE, "../serials/serials_mdcmbo.db" or die $!."\nserials_mdcmbo.db not found.";
+while (my $a = <FILE>) {
+ if(my @values = $a =~ /^\s*(\d+)\s+0x([\w]{16})\s*$/) {
+ my $s = shift @values;
+ my $uid = shift @values;
+ $serials->{hex($uid)} = $s;
+ }
+ }
+close FILE;
+
+###############################################################################
+#Find available boards
+###############################################################################
+my $boards = trb_read_uid(0xfe91);
+foreach my $uid (keys %$boards) {
+ foreach my $k (keys %{$boards->{$uid}}) {
+ $addresses->{$boards->{$uid}{$k}} = $serials->{$uid};
+ }
+ }
+
+ my $counters;
+ my $counters2;
+ my $rates;
+ my $baselines;
+###############################################################################
+#Prepare Scan
+###############################################################################
+init_pasttrecs();
+set_baseline(0);
+foreach my $i (0..31) {
+ print("Set baseline $i\n");
+ set_baseline($i);
+ $counters = trb_register_read_mem(0xfe91,0xdfc0,0,32);
+ sleep(1);
+ $counters2 = trb_register_read_mem(0xfe91,0xdfc0,0,32);
+
+ foreach my $b (keys %{$counters}) {
+ foreach my $c (0..31) {
+ my $tmp = ($counters2->{$b}[$c]&0xffffff) - ($counters->{$b}[$c]&0xffffff);
+ $tmp += 2**24 if $tmp < 0;
+ $rates->{$b}[$c][$i] = $tmp;
+ }
+ }
+ }
+
+
+foreach my $b (keys %{$rates}) {
+ foreach my $c (0..31) {
+ my $sum=0; my $tot=0;
+ foreach my $i (0..31) {
+ $sum += $rates->{$b}[$c][$i]*$i;
+ $tot += $rates->{$b}[$c][$i];
+ }
+ $baselines->{$b}[$c] = $sum/($tot||1);
+ if($tot==0) {$baselines->{$b}[$c]=0x63;}
+ }
+ }
+print Dumper $baselines;
+
+foreach my $b (sort keys %{$rates}) {
+ foreach my $p (0..3) {
+ printf(" %i\t%i\t%02i\t%02i\t%02i\t%02i\t%02i\t%02i\t%02i\t%02i\n",
+ $addresses->{$b}, $p,
+ $baselines->{$b}[$p*8+0]+0.5,
+ $baselines->{$b}[$p*8+1]+0.5,
+ $baselines->{$b}[$p*8+2]+0.5,
+ $baselines->{$b}[$p*8+3]+0.5,
+ $baselines->{$b}[$p*8+4]+0.5,
+ $baselines->{$b}[$p*8+5]+0.5,
+ $baselines->{$b}[$p*8+6]+0.5,
+ $baselines->{$b}[$p*8+7]+0.5,
+ );
+ }
+ }
+
# Serial # Unique ID
########################################
-#first version misses endpoint IDs, prefix with 8 and 6/7
-80021 0x0000e4b3001f2941
+#first version misses endpoint IDs, prefix with 8 (oep) and 6/7 (near and far tdc)
+80011 0x0000e4b3001f2941
+60011 0x0000f34c001f2941
+70011
+
+80021 0x0000e4b3001f2941
60021 0x0000f34c001f2941
70021 0x00009c7d00202941
60031 0x000099bd00202941
70031 0x0000dfab001f2941
+80081 0x000009d700762941
+60081 0x000090d700752941
+70081 0x0000766e00752941
+
+80111 0x0000904400752941
+60111 0x000024b200752941
+70111 0x00003be300752941
+
+80121 0x00001ea600752941
+60121 0x0000028200752941
+70121 0x0000ede000742941
+
80161 0x000084d200202941
-60161 0x00004f3800202941
+60161 0x00004f3800202941
70161 0x0000e820001f2941
+
+
+
+
+
+