aboutsummaryrefslogtreecommitdiff
path: root/scripts/observed-peak-rate
blob: 00e0ba4d134194e2a91013d6c828f52de14b18e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl -w

use strict;
use File::Basename;

open(FH, $ARGV[0]);
open(HITRATE, "> hitrate.dat");
open(NPEAKS, "> npeaks.dat");

my $line;
my $filename = "";
my $full_filename;
my $np;
my $year;
my $month;
my $day;
my $hour;
my $min;
my $sec = -1;
my $nh = 0;
my $ns = 0;

while ( $line = <FH> ) {

	chomp($line);

	if ( $line =~ /^\s+[0-9\.]+\s+[0-9\.]+\s+[0-9\.]+\s+[0-9\.]+$/ ) {
		$np++;
	}

	unless ( $line =~ /^Peaks\ from\ peak\ search\ in\ (.+)$/ ) {
		next;
	}

	$full_filename = $1;

	# Process last image
	if ( $filename ) {

		unless ( $filename =~
		   /LCLS_(\d+)_([A-Za-z]+)(\d+)_(\d\d)(\d\d)(\d\d)_/ ) {
			printf(STDERR "Wrong filename format '%s'!\n",
			       $filename);
			exit(1);
		}

		my $new_year = $1;
		my $new_month = $2;
		my $new_day = $3;
		my $new_hour = $4;
		my $new_min = $5;
		my $new_sec = $6;

		if ( $new_sec != $sec ) {

			if ( $ns > 0 ) {

				printf(HITRATE "%s/%s/%s-%s:%s:%s %f\n",
				               $year, $month, $day,
			                       $hour, $min, $sec,
			                       $nh);

			}

			$year = $new_year;
			$month = $new_month;
			$day = $new_day;
			$hour = $new_hour;
			$min = $new_min;
			$sec = $new_sec;

			$nh = 0;
			$ns = 0;

		}

		printf(NPEAKS "%s/%s/%s-%s:%s:%s %f\n",
		              $year, $month, $day, $hour, $min, $sec, $np);

		printf("%s: %i peaks\n", $filename, $np);
		if ( $np > 10 ) {
			$nh++;
		}
		$ns++;

	}

	$filename = basename($full_filename);
	$np = 0;

}

close(FH);
close(HITRATE);
close(NPEAKS);

open(GP, "| gnuplot");

print(GP "set term postscript enhanced font \"Helvetica,20\"\n");
print(GP "set output \"hitrate.ps\"\n");
print(GP "set title \"Hit rate\"\n");
print(GP "set xtics nomirror rotate by -60\n");
print(GP "set xdata time\n");
print(GP "set timefmt \"%Y/%b/%d-%H:%M:%S\"\n");
print(GP "set format x \"%d/%b %H:%M\"\n");
print(GP "set rmargin 6\n");
print(GP "unset key\n");
print(GP "plot [] [] \"hitrate.dat\" u 1:2 w points\n");

print(GP "set xtics nomirror rotate by -60\n");
print(GP "set title \"Number of Peaks per Image\"\n");
print(GP "set xdata time\n");
print(GP "set timefmt \"%Y/%b/%d-%H:%M:%S\"\n");
print(GP "set format x \"%d/%b %H:%M\"\n");
print(GP "unset key\n");
print(GP "plot [] [] \"npeaks.dat\" u 1:2 w points\n");

close(GP);

system("ps2pdf hitrate.ps");
unlink("hitrate.dat");
unlink("hitrate.ps");