Etch/Layout.pm

filter: Statementstmt 92.0% 139 / 151 Branchbran 80.3% 45 / 56 Conditioncond 66.1% 39 / 59 MC/DCmcdc 42.8% 15 / 35 Subroutinesub 84.0% 21 / 25 Podpod 35.2% 6 / 17 totaltotal 77.2% 265 / 343 CC 65 SCAR 22.7
CC
65
Cov
84%
density_map
18.6
_compute_bbox
15.9
features
13.1
CRAP 9.7
« Etch/Chamber.pm ↑ Summary Etch/DryEtch.pm »
1 package Physics::Etch::Layout;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Physics::Etch::GDSII;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 our $VERSION = '0.02';
10  
11 # ===========================================================================
12 # Geometric analysis of a mask layer for etch modelling.
13 #
14 # Construct from a GDSII object + layer, or from a list of polygons.
15 # Polygons are stored internally in microns.
16 #
17 # tone : 'clear' -> drawn polygons ARE the etch openings (default)
18 # 'dark' -> drawn polygons are the mask; openings = field - drawn
19 # field: [w, h] in microns (defaults to the polygon bounding box)
20 # ===========================================================================
21 3 ▶sub new {
Subroutine new: called CC=4 SCAR=15.0
Pod undocumented
22 3 my ( $class, %a ) = @_;
23  
24 3 my @polys;
25 3 ▶ if ( $a{gdsii} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($a{'gdsii'}) { } 0 3 3
elsif ($a{'polygons'}) { } 3 0 3
26 @polys = $a{gdsii}->polygons(
27 layer => $a{layer},
28 structure => $a{structure},
29 0 unit => 'um',
30 );
31 }
32 elsif ( $a{polygons} ) {
33 3 @polys = @{ $a{polygons} };
34 }
35 else {
36 0 croak "Layout: need 'gdsii' or 'polygons'";
37 }
38  
39 my $self = bless {
40 polygons => \@polys,
41 tone => $a{tone} // 'clear',
42 field => $a{field}, # [w,h] um or undef
43 layer => $a{layer},
44 3 ▶ }, $class;
Condition50%1/2
$a{"tone"} // "clear"
l!l
30
MC/DC0%0/1
$a{"tone"} // "clear"
$a{"tone"}
Truth table50%1/2
A
A= $a{"tone"}
Aresult
11
00
45  
46 3 $self->_compute_bbox;
47 3 return $self;
48 }
49  
50 0 ▶sub from_gdsii_file {
Subroutine from_gdsii_file: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my ( $class, $file, %a ) = @_;
52 0 my $g = Physics::Etch::GDSII->read($file);
53 0 return $class->new( gdsii => $g, %a );
54 }
55  
56 0 ▶sub polygons { @{ $_[0]->{polygons} } }
Subroutine polygons: not called CC=1 SCAR=6.9
Pod undocumented
57 3 ▶sub count { scalar @{ $_[0]->{polygons} } }
Subroutine count: called CC=1 SCAR=0.0
Pod undocumented
58 0 ▶sub tone { $_[0]->{tone} }
Subroutine tone: not called CC=1 SCAR=6.9
Pod undocumented
59  
60 # ---------------------------------------------------------------------------
61 # Bounding box / field (microns)
62 # ---------------------------------------------------------------------------
63 3 ▶sub _compute_bbox {
Subroutine _compute_bbox: called CC=15 SCAR=27.7
64 3 my ($self) = @_;
65 3 my ( $xmin, $ymin, $xmax, $ymax );
66 3 for my $p ( @{ $self->{polygons} } ) {
67 6 for my $pt (@$p) {
68 30 ▶ $xmin = $pt->[0] if !defined $xmin || $pt->[0] < $xmin;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $xmin or $pt->[0] < $xmin 3 27 30
Condition66%2/3
not defined $xmin or $pt->[0] < $xmin
l!l&&r!l&&!r
3027
MC/DC50%1/2
not defined $xmin or $pt->[0] < $xmin
not defined $xmin $pt->[0] < $xmin
Truth table66%2/3
not(A) or B
A= not defined $xminB= $pt->[0] < $xmin
ABresult
1X1
011
000
69 30 ▶ $ymin = $pt->[1] if !defined $ymin || $pt->[1] < $ymin;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ymin or $pt->[1] < $ymin 3 27 30
Condition66%2/3
not defined $ymin or $pt->[1] < $ymin
l!l&&r!l&&!r
3027
MC/DC50%1/2
not defined $ymin or $pt->[1] < $ymin
not defined $ymin $pt->[1] < $ymin
Truth table66%2/3
not(A) or B
A= not defined $yminB= $pt->[1] < $ymin
ABresult
1X1
011
000
70 30 ▶ $xmax = $pt->[0] if !defined $xmax || $pt->[0] > $xmax;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $xmax or $pt->[0] > $xmax 12 18 30
Condition100%3/3
not defined $xmax or $pt->[0] > $xmax
l!l&&r!l&&!r
3918
MC/DC100%2/2
not defined $xmax or $pt->[0] > $xmax
not defined $xmax $pt->[0] > $xmax
Truth table100%3/3
not(A) or B
A= not defined $xmaxB= $pt->[0] > $xmax
ABresult
1X1
011
000
71 30 ▶ $ymax = $pt->[1] if !defined $ymax || $pt->[1] > $ymax;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ymax or $pt->[1] > $ymax 10 20 30
Condition100%3/3
not defined $ymax or $pt->[1] > $ymax
l!l&&r!l&&!r
3720
MC/DC100%2/2
not defined $ymax or $pt->[1] > $ymax
not defined $ymax $pt->[1] > $ymax
Truth table100%3/3
not(A) or B
A= not defined $ymaxB= $pt->[1] > $ymax
ABresult
1X1
011
000
72 }
73 }
74 3 ▶ $self->{bbox} = [ $xmin // 0, $ymin // 0, $xmax // 0, $ymax // 0 ];
Condition50%4/8
$xmin // 0
l!l
30
$ymin // 0
l!l
30
$xmax // 0
l!l
30
$ymax // 0
l!l
30
MC/DC0%0/1
$xmin // 0
$xmin
MC/DC0%0/1
$ymin // 0
$ymin
MC/DC0%0/1
$xmax // 0
$xmax
MC/DC0%0/1
$ymax // 0
$ymax
Truth table50%1/2
A
A= $xmin
Aresult
11
00
Truth table50%1/2
A
A= $ymin
Aresult
11
00
Truth table50%1/2
A
A= $xmax
Aresult
11
00
Truth table50%1/2
A
A= $ymax
Aresult
11
00
75 }
76  
77 2 ▶sub bbox { @{ $_[0]->{bbox} } } # (xmin,ymin,xmax,ymax) um
Subroutine bbox: called CC=1 SCAR=0.0
Pod undocumented
78  
79 10 ▶sub field_wh {
Subroutine field_wh: called CC=2 SCAR=9.2
Pod undocumented
80 10 my ($self) = @_;
81 10 ▶ return @{ $self->{field} } if $self->{field};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"field"} 10 0 10
82 0 my ( $x0, $y0, $x1, $y1 ) = @{ $self->{bbox} };
83 0 return ( $x1 - $x0, $y1 - $y0 );
84 }
85  
86 8 ▶sub field_area_um2 { # um^2
Subroutine field_area_um2: called CC=1 SCAR=0.0
Pod undocumented
87 8 my ($self) = @_;
88 8 my ( $w, $h ) = $self->field_wh;
89 8 return $w * $h;
90 }
91  
92 # ---------------------------------------------------------------------------
93 # Areas (um^2 ; helpers to cm^2 for loading)
94 # ---------------------------------------------------------------------------
95 13 ▶sub drawn_area_um2 {
Subroutine drawn_area_um2: called CC=2 SCAR=6.9
Pod undocumented
96 13 my ($self) = @_;
97 13 my $a = 0;
98 13 $a += _polygon_area( $_[0], $_ ) for @{ $self->{polygons} };
99 13 return $a;
100 }
101  
102 12 ▶sub open_area_um2 {
Subroutine open_area_um2: called CC=2 SCAR=6.9
Pod documented
103 12 my ($self) = @_;
104 12 my $drawn = $self->drawn_area_um2;
105 12 ▶ return $self->{tone} eq 'dark'
Branch: 1 branch
BranchTrueFalseTotal
$self->{'tone'} eq 'dark' ? : 2 10 12
106 ? ( $self->field_area_um2 - $drawn )
107 : $drawn;
108 }
109  
110 2 ▶sub open_area_cm2 { $_[0]->open_area_um2 * 1e-8 } # 1 um^2 = 1e-8 cm^2
Subroutine open_area_cm2: called CC=1 SCAR=0.0
Pod documented
111 0 ▶sub field_area_cm2 { $_[0]->field_area_um2 * 1e-8 }
Subroutine field_area_cm2: not called CC=1 SCAR=6.9
Pod undocumented
112  
113 6 ▶sub open_fraction {
Subroutine open_fraction: called CC=2 SCAR=7.1
Pod documented
114 6 my ($self) = @_;
115 6 ▶ my $fa = $self->field_area_um2 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $fa = $self->field_area_um2 or return 0 6 0 6
116 6 return $self->open_area_um2 / $fa;
117 }
118  
119 # ---------------------------------------------------------------------------
120 # Per-feature critical dimension (nm). CD ~ narrow side of each polygon's
121 # bounding box (exact for axis-aligned rectangles/lines).
122 # ---------------------------------------------------------------------------
123 5 ▶sub features {
Subroutine features: called CC=13 SCAR=25.7
Pod documented
124 5 my ($self) = @_;
125 5 my @f;
126 5 for my $p ( @{ $self->{polygons} } ) {
127 10 my ( $x0, $y0, $x1, $y1 );
128 10 for my $pt (@$p) {
129 50 ▶ $x0 = $pt->[0] if !defined $x0 || $pt->[0] < $x0;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $x0 or $pt->[0] < $x0 10 40 50
Condition66%2/3
not defined $x0 or $pt->[0] < $x0
l!l&&r!l&&!r
10040
MC/DC50%1/2
not defined $x0 or $pt->[0] < $x0
not defined $x0 $pt->[0] < $x0
Truth table66%2/3
not(A) or B
A= not defined $x0B= $pt->[0] < $x0
ABresult
1X1
011
000
130 50 ▶ $y0 = $pt->[1] if !defined $y0 || $pt->[1] < $y0;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $y0 or $pt->[1] < $y0 10 40 50
Condition66%2/3
not defined $y0 or $pt->[1] < $y0
l!l&&r!l&&!r
10040
MC/DC50%1/2
not defined $y0 or $pt->[1] < $y0
not defined $y0 $pt->[1] < $y0
Truth table66%2/3
not(A) or B
A= not defined $y0B= $pt->[1] < $y0
ABresult
1X1
011
000
131 50 ▶ $x1 = $pt->[0] if !defined $x1 || $pt->[0] > $x1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $x1 or $pt->[0] > $x1 20 30 50
Condition100%3/3
not defined $x1 or $pt->[0] > $x1
l!l&&r!l&&!r
101030
MC/DC100%2/2
not defined $x1 or $pt->[0] > $x1
not defined $x1 $pt->[0] > $x1
Truth table100%3/3
not(A) or B
A= not defined $x1B= $pt->[0] > $x1
ABresult
1X1
011
000
132 50 ▶ $y1 = $pt->[1] if !defined $y1 || $pt->[1] > $y1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $y1 or $pt->[1] > $y1 20 30 50
Condition100%3/3
not defined $y1 or $pt->[1] > $y1
l!l&&r!l&&!r
101030
MC/DC100%2/2
not defined $y1 or $pt->[1] > $y1
not defined $y1 $pt->[1] > $y1
Truth table100%3/3
not(A) or B
A= not defined $y1B= $pt->[1] > $y1
ABresult
1X1
011
000
133 }
134 10 my $w = $x1 - $x0;
135 10 my $h = $y1 - $y0;
136 10 ▶ my $cd = $w < $h ? $w : $h; # microns
Branch: 1 branch
BranchTrueFalseTotal
$w < $h ? : 6 4 10
137 10 ▶ push @f,
Branch: 1 branch
BranchTrueFalseTotal
$w > $h ? : 0 10 10
138 {
139 cd_um => $cd,
140 cd_nm => $cd * 1000,
141 long_um => ( $w > $h ? $w : $h ),
142 area_um2 => _polygon_area( $self, $p ),
143 center => [ ( $x0 + $x1 ) / 2, ( $y0 + $y1 ) / 2 ],
144 };
145 }
146 5 return \@f;
147 }
148  
149 3 ▶sub cd_stats_nm {
Subroutine cd_stats_nm: called CC=5 SCAR=16.2
Pod documented
150 3 my ($self) = @_;
151 3 my @cd = map { $_->{cd_nm} } @{ $self->features };
152 3 ▶ return {} unless @cd;
Branch: 1 branch
BranchTrueFalseTotal
unless @cd 0 3 3
153 3 my ( $min, $max, $sum ) = ( $cd[0], $cd[0], 0 );
154 3 ▶ for (@cd) { $min = $_ if $_ < $min; $max = $_ if $_ > $max; $sum += $_; }
Branch: 2 branches
BranchTrueFalseTotal
if $_ < $min 0 6 6
if $_ > $max 3 3 6
155 3 return { min => $min, max => $max, mean => $sum / @cd, n => scalar @cd };
156 }
157  
158 # ---------------------------------------------------------------------------
159 # Local pattern-density map (open fraction per grid cell) for microloading.
160 # cell_um: grid pitch in microns. Returns { nx, ny, cell, min, max, mean,
161 # grid => [ [ frac, ... ], ... ] }.
162 # ---------------------------------------------------------------------------
163 3 ▶sub density_map {
Subroutine density_map: called CC=17 SCAR=29.2
Pod documented
164 3 my ( $self, %a ) = @_;
165 3 ▶ my $cell = $a{cell_um} // 10;
Condition50%1/2
$a{"cell_um"} // 10
l!l
30
MC/DC0%0/1
$a{"cell_um"} // 10
$a{"cell_um"}
Truth table50%1/2
A
A= $a{"cell_um"}
Aresult
11
00
166 3 ▶ my $sub = $a{subsamples} // 4; # NxN sample points per cell
Condition100%2/2
$a{"subsamples"} // 4
l!l
12
MC/DC100%1/1
$a{"subsamples"} // 4
$a{"subsamples"}
Truth table100%2/2
A
A= $a{"subsamples"}
Aresult
11
00
167 3 my ( $x0, $y0, $x1, $y1 ) = @{ $self->{bbox} };
168 3 ▶ my $w = $x1 - $x0 || $cell;
Condition33%1/3
$x1 - $x0 || $cell
l!l&&r!l&&!r
300
MC/DC0%0/2
$x1 - $x0 || $cell
$x1 - $x0 $cell
Truth table33%1/3
A || B
A= $x1 - $x0B= $cell
ABresult
1X1
011
000
169 3 ▶ my $h = $y1 - $y0 || $cell;
Condition33%1/3
$y1 - $y0 || $cell
l!l&&r!l&&!r
300
MC/DC0%0/2
$y1 - $y0 || $cell
$y1 - $y0 $cell
Truth table33%1/3
A || B
A= $y1 - $y0B= $cell
ABresult
1X1
011
000
170 3 ▶ my $nx = int( $w / $cell + 0.999 ) || 1;
Condition50%1/2
int $w / $cell + 0.999 || 1
l!l
30
MC/DC0%0/1
int $w / $cell + 0.999 || 1
int $w / $cell + 0.999
Truth table50%1/2
A
A= int $w / $cell + 0.999
Aresult
11
00
171 3 ▶ my $ny = int( $h / $cell + 0.999 ) || 1;
Condition50%1/2
int $h / $cell + 0.999 || 1
l!l
30
MC/DC0%0/1
int $h / $cell + 0.999 || 1
int $h / $cell + 0.999
Truth table50%1/2
A
A= int $h / $cell + 0.999
Aresult
11
00
172  
173 3 my @grid;
174 3 my ( $min, $max, $sum ) = ( 1, 0, 0 );
175 3 for my $iy ( 0 .. $ny - 1 ) {
176 7 my @row;
177 7 for my $ix ( 0 .. $nx - 1 ) {
178 31 my $inside = 0;
179 31 my $total = 0;
180 31 for my $sx ( 0 .. $sub - 1 ) {
181 149 for my $sy ( 0 .. $sub - 1 ) {
182 721 my $px = $x0 + ( $ix + ( $sx + 0.5 ) / $sub ) * $cell;
183 721 my $py = $y0 + ( $iy + ( $sy + 0.5 ) / $sub ) * $cell;
184 721 $total++;
185 721 ▶ $inside++ if $self->_point_drawn( $px, $py );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_point_drawn($px, $py) 129 592 721
186 }
187 }
188 31 ▶ my $drawn = $total ? $inside / $total : 0;
Branch: 1 branch
BranchTrueFalseTotal
$total ? : 31 0 31
189 31 ▶ my $open = $self->{tone} eq 'dark' ? 1 - $drawn : $drawn;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'tone'} eq 'dark' ? : 0 31 31
190 31 push @row, $open;
191 31 ▶ $min = $open if $open < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $open < $min 3 28 31
192 31 ▶ $max = $open if $open > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $open > $max 3 28 31
193 31 $sum += $open;
194 }
195 7 push @grid, \@row;
196 }
197 3 my $n = $nx * $ny;
198 return {
199 3 ▶ nx => $nx, ny => $ny, cell => $cell,
Branch: 1 branch
BranchTrueFalseTotal
$n ? : 3 0 3
200 grid => \@grid,
201 min => $min, max => $max, mean => ( $n ? $sum / $n : 0 ),
202 };
203 }
204  
205 723 ▶sub _point_drawn {
Subroutine _point_drawn: called CC=3 SCAR=11.0
206 723 my ( $self, $x, $y ) = @_;
207 723 for my $poly ( @{ $self->{polygons} } ) {
208 1420 ▶ return 1 if _point_in_polygon( $x, $y, $poly );
Branch: 1 branch
BranchTrueFalseTotal
if _point_in_polygon($x, $y, $poly) 130 1290 1420
209 }
210 593 return 0;
211 }
212  
213 # ---------------------------------------------------------------------------
214 # geometry primitives
215 # ---------------------------------------------------------------------------
216 36 ▶sub _polygon_area {
Subroutine _polygon_area: called CC=3 SCAR=11.0
217 36 my ( undef, $poly ) = @_;
218 36 my $n = @$poly;
219 36 ▶ return 0 if $n < 3;
Branch: 1 branch
BranchTrueFalseTotal
if $n < 3 0 36 36
220 36 my $a = 0;
221 36 for my $i ( 0 .. $n - 1 ) {
222 180 my $j = ( $i + 1 ) % $n;
223 180 $a += $poly->[$i][0] * $poly->[$j][1] - $poly->[$j][0] * $poly->[$i][1];
224 }
225 36 return abs($a) / 2;
226 }
227  
228 1420 ▶sub _point_in_polygon {
Subroutine _point_in_polygon: called CC=5 SCAR=16.1
229 1420 my ( $x, $y, $poly ) = @_;
230 1420 my $n = @$poly;
231 1420 my $in = 0;
232 1420 ▶ for ( my $i = 0, my $j = $n - 1; $i < $n; $j = $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 7100 1420 8520
233 7100 my ( $xi, $yi ) = @{ $poly->[$i] };
234 7100 my ( $xj, $yj ) = @{ $poly->[$j] };
235 7100 ▶ if ( ( $yi > $y ) != ( $yj > $y )
Branch: 1 branch
BranchTrueFalseTotal
if ($yi > $y != $yj > $y and $x < ($xj - $xi) * ($y - $yi) / ($yj - $yi || "1e-30") + $xi) 434 6666 7100
Condition80%4/5
$yi > $y != $yj > $y and $x < ($xj - $xi) * ($y - $yi) / ($yj - $yi || "1e-30") + $xi
!ll&&!rl&&r
6156510434
$yj - $yi || 1e-30
l!l
9440
MC/DC100%2/2
$yi > $y != $yj > $y and $x < ($xj - $xi) * ($y - $yi) / ($yj - $yi || "1e-30") + $xi
$yi > $y != $yj > $y $x < ($xj - $xi) * ($y - $yi) / ($yj - $yi || "1e-30") + $xi
MC/DC0%0/1
$yj - $yi || 1e-30
$yj - $yi
Truth table100%3/3
A and B
A= $yi > $y != $yj > $yB= $x < ($xj - $xi) * ($y - $yi) / ($yj - $yi || "1e-30") + $xi
ABresult
0X0
100
111
Truth table50%1/2
A
A= $yj - $yi
Aresult
11
00
236 && $x < ( $xj - $xi ) * ( $y - $yi ) / ( ( $yj - $yi ) || 1e-30 ) + $xi )
237 {
238 434 $in = !$in;
239 }
240 }
241 1420 return $in;
242 }
243  
244 # ---------------------------------------------------------------------------
245 2 ▶sub summary {
Subroutine summary: called CC=4 SCAR=14.9
Pod undocumented
246 2 my ($self) = @_;
247 2 my $cd = $self->cd_stats_nm;
248 2 my ( $fw, $fh ) = $self->field_wh;
249 return sprintf(
250 "Layout: %d features, tone=%s, field %.1f x %.1f um\n"
251 . " open area %.1f um^2 (%.1f%% open), CD min/mean/max = %.0f/%.0f/%.0f nm",
252 $self->count, $self->{tone}, $fw, $fh,
253 $self->open_area_um2, 100 * $self->open_fraction,
254 2 ▶ $cd->{min} // 0, $cd->{mean} // 0, $cd->{max} // 0,
Condition50%3/6
$cd->{"min"} // 0
l!l
20
$cd->{"mean"} // 0
l!l
20
$cd->{"max"} // 0
l!l
20
MC/DC0%0/1
$cd->{"min"} // 0
$cd->{"min"}
MC/DC0%0/1
$cd->{"mean"} // 0
$cd->{"mean"}
MC/DC0%0/1
$cd->{"max"} // 0
$cd->{"max"}
Truth table50%1/2
A
A= $cd->{"min"}
Aresult
11
00
Truth table50%1/2
A
A= $cd->{"mean"}
Aresult
11
00
Truth table50%1/2
A
A= $cd->{"max"}
Aresult
11
00
255 );
256 }
257  
258 4 1;
259  
260 __END__
« Etch/Chamber.pm ↑ Summary Etch/DryEtch.pm »