From eaf3d71bc068a23c9972e596170d30ffad720281 Mon Sep 17 00:00:00 2001 From: Michael Traxler Date: Fri, 14 Nov 2014 21:33:46 +0100 Subject: [PATCH] Threshold compare --- users/cern_cbmrich/thresholds_compare.pl | 129 +++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100755 users/cern_cbmrich/thresholds_compare.pl diff --git a/users/cern_cbmrich/thresholds_compare.pl b/users/cern_cbmrich/thresholds_compare.pl new file mode 100755 index 0000000..b9dfeb9 --- /dev/null +++ b/users/cern_cbmrich/thresholds_compare.pl @@ -0,0 +1,129 @@ +#!/usr/bin/perl -w + +use warnings; +use strict; +use POSIX qw(strftime); +use FileHandle; +use lib "../../tools"; +use lib "."; +use HPlot; +use Data::Dumper; +use ChannelMapping; + +my $plot2 = (); +$plot2->{name} = "HeatmapRich"; +$plot2->{file} = "thresh_heatmap"; +$plot2->{entries} = 33; +$plot2->{curves} = 33; +$plot2->{type} = HPlot::TYPE_HEATMAP; +$plot2->{output} = HPlot::OUT_PNG; +$plot2->{zlabel} = "Hitrate"; +$plot2->{sizex} = 700; +$plot2->{sizey} = 650; +$plot2->{nokey} = 1; +$plot2->{buffer} = 1; +$plot2->{xmin} = 0.5; +$plot2->{xmax} = 32.5; +$plot2->{ymin} = 0.5; +$plot2->{ymax} = 32.5; +$plot2->{cbmin} = "-400<*"; +$plot2->{cbmax} = "*<400"; +$plot2->{showvalues} = 0; +$plot2->{xlabel} = "column"; +$plot2->{ylabel} = "row"; +$plot2->{addCmd} = "set lmargin at screen 0.07\nset rmargin at screen 0.85\nset bmargin at screen 0.07\nset tmargin at screen 0.95"; +$plot2->{palette} = "defined ( 0 0 0 1, 0.5 1 1 1, 1 1 0 0 )"; + +HPlot::PlotInit($plot2); + +sub readSettings { + my $fn = shift; + open(my $fh, $fn || die "could not open file '$ARGV[0]'"); + my @f = <$fh>; + 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+)/; + $thresholds{hex($ep) .":". int($channel)} = hex $thresh; + } + + return %thresholds; +} + +# load files + my $fn1 = $ARGV[0] or die("usage: thresholds_compare.pl file1 [file2]. omit file2 to get abs value, include for file1-file2"); + my $fn2 = $ARGV[1]; + + my %threshs1 = readSettings($fn1); + print "WARNING: Expected 1024 settings in $fn1. Got " . scalar(keys %threshs1) unless scalar(keys %threshs1) == 1024; + + my %threshs2 = (); + if ($fn2) { + %threshs2 = readSettings($fn2); + print "WARNING: Expected 1024 settings in $fn2. Got " . scalar(keys %threshs2) unless scalar(keys %threshs2) == 1024; + } + +# plot heatmap + for my $x (1..32) { + for my $y (1..32) { + my $fpga = $ChannelMapping::chanmap->{fpga}->[$x]->[$y]; + my $channel = ($ChannelMapping::chanmap->{chan}->[$x]->[$y]-1)/2; + + my $value = $threshs1{$fpga.":".$channel} or die(sprintf("endpoint 0x%04x, channel %d (%d:%d) not found in $fn1", $fpga, $channel, $fpga, $channel)); + if ($fn2) { + $value -= ($threshs2{$fpga.":".$channel} or die(sprintf("endpoint 0x%04x, channel %d (%d:%d) not found in $fn2", $fpga, $channel, $fpga, $channel))); + } + + HPlot::PlotFill('HeatmapRich',$value,$x,$y); + } + } + HPlot::PlotDraw('HeatmapRich'); + +# plot histogram + my @values = (); + + open DATA, ">", "/tmp/thresh_diff.dat"; + for my $key (keys %threshs1) { + print DATA $threshs1{$key} . " " . $threshs2{$key} . "\n"; + push @values, $threshs1{$key}; + push @values, $threshs2{$key}; + } + close DATA; + + @values = sort @values; + + my $min = $values[int($#values * 0.02)]; + my $max = $values[int($#values * 0.92)]; + my $range = $max-$min; + + $min -= $range * 0.1; + $max += $range * 0.1; + + + open GNUPLOT, '|gnuplot'; + print GNUPLOT <