generate_refactored_protodune-sp_v7.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 # contact tylerdalion@gmail.com for any GDML/generate questions
4 # I would love to help!
5 
6 # Each subroutine generates a fragment GDML file, and the last subroutine
7 # creates an XML file that make_gdml.pl will use to appropriately arrange
8 # the fragment GDML files to create the final desired DUNE GDML file,
9 # to be named by make_gdml output command
10 
11 # If you are playing with different geometries, you can use the
12 # suffix command to help organize your work.
13 
14 #use warnings;
15 use gdmlMaterials;
16 use Math::Trig;
17 use Getopt::Long;
18 use Math::BigFloat;
19 Math::BigFloat->precision(-16);
20 
21 open(my $wout, '>', 'gdmlWireCenters.txt');
22 
23 GetOptions( "help|h" => \$help,
24  "suffix|s:s" => \$suffix,
25  "output|o:s" => \$output,
26  "wires|w:s" => \$wires,
27  "protoDune|p:s" => \$protoDune,
28  "workspace|k:s" => \$workspace,
29  "simpleStSu|u:s" => \$simpleStSu);
30 
31 if ( defined $help )
32 {
33  # If the user requested help, print the usage notes and exit.
34  usage();
35  exit;
36 }
37 
38 if ( ! defined $suffix )
39 {
40  # The user didn't supply a suffix, so append nothing to the file
41  # names.
42  $suffix = "";
43 }
44 else
45 {
46  # Otherwise, stick a "-" before the suffix, so that a suffix of
47  # "test" applied to filename.gdml becomes "filename-test.gdml".
48  $suffix = "-" . $suffix;
49 }
50 
51 if ( ! defined $workspace )
52 {
53  $workspace = 0;
54  if ( ! defined $protoDune )
55  {
56  $protoDune = 0;
57  $simpleStSu = 1;
58  print "\t\tCreating full geometry.\n";
59  }
60  elsif ( $protoDune == 1 )
61  {
62  print "\t\tCreating rough version of protoDUNE.\n";
63  if ( ! defined $simpleStSu )
64  {
65  $simpleStSu = 0;
66  }
67  elsif ( $simpleStSu == 1 )
68  {
69  print "\t\tUsing simple steel support geometry for protoDUNE.\n";
70  }
71  }
72  if($protoDune == 0 && $simpleStSu == 0)
73  {
74  print "\t\tThis version of the steel support is only compatible with protoDUNE.\n";
75  exit;
76  }
77 }
78 elsif ( $workspace == 1)
79 {
80  print "\t\tCreating smaller workspace geometry.\n";
81 }
82 # set wires on to be the default, unless given an input by the user
83 $wires_on = 1; # 1=on, 0=off
84 if (defined $wires)
85 {
86 $wires_on = $wires
87 }
88 
89 $tpc_on=1;
90 
91 $killOuterActive = 0;
92 
93 # options for different parameters
94 $Pitch3mmVersion = 0;
95 $UVAngle45Option = 0;
96 
97 
98 
99 #++++++++++++++++++++++++ Begin defining variables +++++++++++++++++++++++++
100 
101 ## The GDML is build from the inside out to avoid overlaps, but that means
102 ## that the larger dimensions (such as the cryostat dimensions) are calculated
103 ## to be slightly different than the parameters calculated and reported by
104 ## engineers. All of this error is within reason and for the better, since
105 ## we don't want this Geometry to be overly complex or long.
106 
107 
108 $inch = 2.54;
109 
110 ##################################################################
111 ##################### Wire Plane Parameters ######################
112 
113 # dune10kt
114 $UWirePitch = 0.4669;
115 $VWirePitch = 0.4669;
116 $XWirePitch = 0.4792;
117 $UAngle = 35.707;
118 $VAngle = 35.707;
119 $nZChannelsPerAPA = 960;
120 
121 # dune10kt 3mm version
122 if($Pitch3mmVersion==1){
123  $UWirePitch = 0.3;
124  $VWirePitch = 0.3;
125  $XWirePitch = 0.3;
126  $nZChannelsPerAPA = 2*(229.44/0.3 + 1);
127 }
128 
129 # dune10kt ~45 deg UV wires version
130 if($UVAngle45Option==1){
131  $UAngle = 45.7;
132  $VAngle = 44.3;
133 }
134 
135 $nAPAWide = 3;
136 $nAPAHigh = 2;
137 $nAPALong = 25;
138 
139 if($protoDune==1){
140  $nAPAWide = 2;
141  $nAPAHigh = 1;
142  $nAPALong = 3;
143 }
144 
145 $SinUAngle = sin( deg2rad($UAngle) );
146 $CosUAngle = cos( deg2rad($UAngle) );
147 $TanUAngle = tan( deg2rad($UAngle) );
148 
149 $SinVAngle = sin( deg2rad($VAngle) );
150 $CosVAngle = cos( deg2rad($VAngle) );
151 $TanVAngle = tan( deg2rad($VAngle) );
152 
153 $UWire_yint = $UWirePitch/$SinUAngle;
154 $UWire_zint = $UWirePitch/$CosUAngle;
155 
156 $VWire_yint = $VWirePitch/$SinVAngle;
157 $VWire_zint = $VWirePitch/$CosVAngle;
158 
159 $TPCWireThickness = 0.015;
160 
161 $TPCWirePlaneThickness = $TPCWireThickness;
162 #height and length defined lower
163 
164 
165 
166 ##################################################################
167 ################### Cryostat/APA parameters ######################
168 
169 if($workspace==1){
170  $nAPAWide = 1;
171  $nAPALong = 2;
172 }
173 
174 $nAPAs = $nAPAWide*$nAPAHigh*$nAPALong;
175 
176 
177 #$G10thickness = $inch/8;
178 $G10thickness = 0.335; #1/8 inch plus epoxy
179 $WrapCover = $inch/16;
180 
181 #$SpaceAPAToCryoWall = 15;
182 #$SpaceAPAToFloor = 59.4 - 10.2; # 10.2cm just adjusts for how spaces are reported
183 #$SpaceAPAToTopLAr = 50.9 - 10.2;
184 #$UpstreamLArPadding = 311.4 - 10.2;
185 #$DownstreamLArPadding = 59.4 - 10.2;
186 
187 $Argon_x = 854.8; #inside dimension of the cryostat
188 $Argon_y = 790.0;
189 $Argon_z = 854.8;
190 
191 if($protoDune==1){
192  $APAToSouthCrWall = 27.7; #center APA to cryostat
193  $CPAToWestCrWall = 45.5; #center CPA to beam window side
194  $DetCentToFloor = 376.0; # center CPA to cryostat floor, y axis
195  $CPACentToWestWall = 396.2; # center CPA to beam window side, z axis
196  $CPACentToEastWall = 458.6;
197  $CPACentToSaleWall = 391.4; # center CPA to Saleve, x axis
198  $CPACentToJuraWall = 463.4; # center CPA to Jura, x axis
199  $APAGap_y = 0;
200 
201 #Beam direction
202 #Distance to upstream wall 3962 mm
203 #Distance to downstream wall 4586 mm
204 #Distance wall to wall 8548 mm
205 
206 #Drift direction
207 #Distance to Jura wall 4634 mm
208 #Distance to Saleve wall 3914 mm
209 #Distance wall to wall 8548 mm
210 
211 #Vertical
212 #Distance to floor 3760.2 mm
213 #Distance to ceiling 4139.8 mm
214 #Floor to ceiling 7900
215 }
216 
217  #InnerDrift is the max distance form the edge of the CPA to the edge of the first wire plane
218 #$InnerDrift = 359.4;
219 $InnerDrift = 357.135;
220 $APAFrame_x = 3*$inch; # ~2in -- this does not include the wire spacing
221 
222 $TPCWireThickness = 0.015;
223 $TPCWirePlaneThickness = $TPCWireThickness;
224 #$APAWirePlaneSpacing = 0.4730488 + $TPCWirePlaneThickness; # center to center spacing between all of the wire planes (g, u, v, and x)
225 
226 if($Pitch3mmVersion==1){
227  $APAWirePlaneSpacing = 0.3;
228 } else {
229  $APAWirePlaneSpacing = 3/16*$inch;
230 }
231 
232 # At creation of the plane volumes, the y and z boundaries will be increased
233 # by this much at each of the 4 edges. this is so the corners of the wire
234 # tubes don't extrude. For all other purposes, the plane dimensions stay as originally defined
235 $UVPlaneBoundNudge = $TPCWireThickness;
236 
237 
238 # APA z-dimensions:
239 # The following are all widths about the z center of an APA
240 $APAphys_z = 231.66;
241 $Zactive_z = ($nZChannelsPerAPA/2-1)*$XWirePitch;# + $TPCWireThickness;
242 $APAFrame_z = $APAphys_z - 2*(2*$G10thickness+$WrapCover);
243 $Vactive_z = $APAFrame_z;
244 $Uactive_z = $APAFrame_z + 2*$G10thickness;
245 $APAGap_z = 0.4; #separation between APAs (cover to cover) along the vertical axis
246 
247 print "Zactive_z=".$Zactive_z."\n";
248 print "APAFrame_z=".$APAFrame_z."\n";
249 #print "=".$."\n";
250 #print "=".$."\n";
251 
252 
253 # APA y-dimensions:
254 $ReadoutBoardOverlap = 7.61; #board overlaps wires, chop this off of their active height
255 $APAFrame_y = 606.0;
256 $Zactive_y = $APAFrame_y + 0*$G10thickness - $ReadoutBoardOverlap;
257 $Vactive_y = $APAFrame_y + 1*$G10thickness - $ReadoutBoardOverlap;
258 $Uactive_y = $APAFrame_y + 2*$G10thickness - $ReadoutBoardOverlap;
259  # the last G10 board for the grid, then a cover. This is not "covered" by the board
260 $APAphys_y = $APAFrame_y + 4*$G10thickness + $WrapCover;
261 #$APAGap_y = 0.4; #separation between APAs (cover to cover) along the incident beam axis
262 
263  # include APA spacing in y and z so volTPCs touch in y and z directions with correct APA
264  # spacing - this makes for smoother event generation.
265 
266 print "Zactive_y=".$Zactive_y."\n";
267 print "APAphys_y=".$APAphys_y."\n";
268 #print "=".$."\n";
269 #print "=".$."\n";
270 
271 $APA_UtoU_x = $APAFrame_x + 6*$APAWirePlaneSpacing + (6-1)*$TPCWirePlaneThickness; # thickness of APA between center U wire to center U wire
272 #$SpaceAPAToCryoWall = $APAToSouthCrWall - ($APA_UtoU_x + $TPCWireThickness)/2;
273 #$OuterDrift = $SpaceAPAToCryoWall - 20.; #Subtract some to avoid overlaping.
274  # outer wire planes (center to center)
275 #$TPCInner_x = $InnerDrift + $APAWirePlaneSpacing;# + $TPCWirePlaneThickness;
276 $TPCInner_x = $InnerDrift + 4*$APAWirePlaneSpacing + 4*$TPCWirePlaneThickness;
277 #$TPCOuter_x = $OuterDrift + $APAWirePlaneSpacing;# + $TPCWirePlaneThickness; Making it smaller than the distance to the wall.
278 $TPCOuter_x = 4*$APAWirePlaneSpacing + 4*$TPCWirePlaneThickness + 8;
279 
280 print "TPCInner_x=".$TPCInner_x."\n";
281 print "TPCOuter_x=".$TPCOuter_x."\n";
282 print "APA_UtoU_x=".$APA_UtoU_x."\n";
283 
284 $TPC_z = $APAphys_z;# + $APAGap_z;
285 $TPC_y = $APAphys_y;# + $APAGap_y;
286 
287 #print "TPC_x=".$TPC_x."\n";
288 print "TPC_y=".$TPC_y."\n";
289 print "TPC_z=".$TPC_z."\n";
290 
291 #$CPATube_OD = 5.08;
292 #$CPATube_ID = 4.747;
293 
294 #$Cathode_x = 0.016;
295 $Cathode_x = 0.13*$inch;
296 #$Cathode_y = $APAphys_y - $CPATube_OD;
297 #$Cathode_z = $APAphys_z - $CPATube_OD;
298 #$Cathode_y = 610.4;
299 $Cathode_z = 715.5;
300 
301 $APAToAPA = $APAFrame_x
302  + 2*$TPCInner_x
303  + $Cathode_x; # center to center
304 
305 $CPAToAPA = $APAFrame_x/2
306  + $TPCInner_x #2*$APAWirePlaneSpacing
307  + $Cathode_x/2; # center to center
308 
309 $SpaceAPAToCryoWall = $CPACentToSaleWall
310  - $CPAToAPA
311  - ($APA_UtoU_x + $TPCWireThickness)/2;
312 
313 print "SpaceAPAToCryoWall=".$SpaceAPAToCryoWall."\n";
314 print "APAToAPA=".$APAToAPA."\n";
315 print "CPAToAPA=".$CPAToAPA."\n";
316 
317 $SteelThickness = 0.12; #half inch
318 $HeightGaseousAr = 80;
319 
320 
321 #$Argon_x = 854.8; #inside dimension of the cryostat
322 #$Argon_x = ($nAPAWide-1)*$APAToAPA
323 # + $APA_UtoU_x + $TPCWirePlaneThickness
324 # + 2*$SpaceAPAToCryoWall;
325 
326 if($workspace==1){ # this is arbitrary for the workspace, but size down a little
327 $Argon_x = 2*$CPAToAPA + $Cathode_x + 2*$SpaceAPAToCryoWall;
328 }
329 
330 #$Argon_y = 790.0; #inside dimension of the cryostat
331 #$Argon_y = $nAPAHigh*$APAphys_y
332 # + ($nAPAHigh-1)*$APAGap_y
333 # + $SpaceAPAToFloor + $SpaceAPAToTopLAr
334 # + $HeightGaseousAr;
335  # both liquid AND gaseous argon
336  #
337 #$Argon_z = 854.8; #inside dimension of the cryostat
338 #$Argon_z = $nAPALong*$APAphys_z
339 # + ($nAPALong-1)*$APAGap_z
340 # + $UpstreamLArPadding + $DownstreamLArPadding;
341 
342 print "Argon_x=".$Argon_x."\n";
343 print "Argon_y=".$Argon_y."\n";
344 print "Argon_z=".$Argon_z."\n";
345 print "APAToAPA =".$APAToAPA."\n";
346 print "APAToSouthCrWall =".$APAToSouthCrWall."\n";
347 
348 $APAToNorthCrWall = $Argon_x
349  - $APAToAPA - $APAToSouthCrWall;
350 
351 #$CPAToEastCrWall = $Argon_z
352 # - ($Cathode_z - $CPATube_OD) - $CPAToWestCrWall;
353 
354 $SpaceAPAToFloor = $DetCentToFloor - $APAphys_y/2;
355 
356 $SpaceAPAToTopLAr = $Argon_y
357  - $APAphys_y
358  - $SpaceAPAToFloor
359  - $HeightGaseousAr;
360 
361 $UpstreamLArPadding = $CPACentToWestWall +
362  - ($nAPALong*$APAphys_z + ($nAPALong-1)*$APAGap_z)/2;
363 
364 $DownstreamLArPadding = $CPACentToEastWall +
365  - ($nAPALong*$APAphys_z + ($nAPALong-1)*$APAGap_z)/2;
366 
367 $Cryostat_x = $Argon_x + 2*$SteelThickness;
368 $Cryostat_y = $Argon_y + 2*$SteelThickness;
369 $Cryostat_z = $Argon_z + 2*$SteelThickness;
370 
371 print "Cryo_x=".$Cryostat_x."\n";
372 print "Cryo_y=".$Cryostat_y."\n";
373 print "Cryo_z=".$Cryostat_z."\n";
374 ##################################################################
375 ############## DetEnc and World relevant parameters #############
376 
377 
378 $SteelSupport_x = 62.8;
379 $SteelSupport_y = 62.8;
380 $SteelSupport_z = 62.8;
381 $SteelPlate = 1.0;
382 $FoamPadding = 80. - $SteelThickness;
383 $FracVolOfSteel = 0.08; #The steel support is not a solid block, but a mixture of air and steel
384 $FracMassOfSteel = $FracVolOfSteel/($FracVolOfSteel+1.205/7930*(1-$FracVolOfSteel)); #The steel support is not a solid block, but a mixture of air and steel
385 
386 $SpaceSteelSupportToWall = 900;
387 $SpaceSteelSupportToCeiling = 900;
388 
389 $DetEncWidth = ($Cryostat_x
390  + 2*($SteelSupport_x + $FoamPadding) + 2*$SpaceSteelSupportToCeiling);
391 $DetEncHeight = ($Cryostat_y
392  + 2*($SteelSupport_y + $FoamPadding) + 2*$SpaceSteelSupportToWall);
393 $DetEncLength = ($Cryostat_z
394  + 2*($SteelSupport_z + $FoamPadding) + 2*$SpaceSteelSupportToWall);
395 
396 $posCryoInDetEnc_x = 0;
397 #$posCryoInDetEnc_y = - $DetEncHeight/2 + $SteelSupport_y + $FoamPadding + $Cryostat_y/2;
398 $posCryoInDetEnc_y = 0;
399 
400 $RockThickness = 400;
401 
402  # We want the world origin to be at the very front of the fiducial volume.
403  # move it to the front of the enclosure, then back it up through the concrete/foam,
404  # then through the Cryostat shell, then through the upstream dead LAr (including the
405  # dead LAr on the edge of the TPC, but this is covered in $UpstreamLArPadding).
406  # This is to be added to the z position of every volume in volWorld
407 
408 $OriginZSet = $APAphys_z
409  + $APAGap_z
410  + $Uactive_z/2
411  + ($CPACentToEastWall - $CPACentToWestWall)/2;
412 $ZAssym=($CPACentToEastWall - $CPACentToWestWall)/2;
413 print "Z assym ".$ZAssym."\n";
414 #$OriginZSet = $DetEncLength/2
415 # - $SpaceSteelSupportToWall
416 # - $SteelSupport_z
417 # - $FoamPadding
418 # - $SteelThickness
419 # - $UpstreamLArPadding
420 # - ($APAphys_z - $Uactive_z)/2;
421 
422  # We want the world origin to be vertically centered between the stacked APAs.
423  # This is to be added to the y position of every volume in volWorld
424 
425 $OriginYSet = $APAphys_y/2
426  + $Argon_y/2
427  - $DetCentToFloor
428 # + $SpaceSteelSupportToWall;
429  - $posCryoInDetEnc_y;
430 
431 print "DetCentToFloor = ".$DetCentToFloor."\n";
432 #$OriginYSet = $DetEncHeight/2
433 # - $SteelSupport_y
434 # - $FoamPadding
435 # - $SteelThickness
436 # - $SpaceAPAToFloor
437 # - $APAphys_y
438 # - $APAGap_y/2;
439 
440 #if($protoDune==1){ # bring the origin to the bottom of the APAs for protoDUNE
441 # $OriginYSet = $OriginYSet + $APAphys_y + $APAGap_y/2;
442 #}
443 
444 #$OriginXSet = ($APAToNorthCrWall - $APAToSouthCrWall)/2;
445 $OriginXSet = ($CPACentToJuraWall - $CPACentToSaleWall)/2;
446 
447 print "OriginXSet =".$OriginXSet.", OriginYSet =".$OriginYSet.", OriginZSet =".$OriginZSet."\n";
448 
449 #$OriginXSet = 0; # centered for now
450 
451 #$Cathode_z = $Cathode_z/3 - $CPATube_OD;
452 
453 ###################################################################
454 ######################## Beam Window 2 Parameters ###################
455 
456 $thetaYZ = 11.342;
457 $theta2XZ = 8.189;
458 
459 $BeamTheta2 = atan (sqrt(tan(deg2rad($theta2XZ))**2 +tan(deg2rad($thetaYZ))**2));
460 $BeamPhi2 = atan (tan(deg2rad($thetaYZ))/tan(deg2rad($theta2XZ)));
461 
462 $thetaYZprime = rad2deg(atan(sin($BeamTheta2)*sin($BeamPhi2+deg2rad(180))/sqrt(cos($BeamTheta2)**2 + sin($BeamTheta2)**2*cos($BeamPhi2)**2)));
463 
464 print "thetaYZprime =".$thetaYZprime."\n";
465 
466 $DeltaXZ2 = tan($BeamTheta2)*cos($BeamPhi2);
467 $DeltaYZ2 = tan($BeamTheta2)*sin($BeamPhi2);
468 
469 print "DeltaXZ2 = ".$DeltaXZ2."\n";
470 print "DeltaYZ2 = ".$DeltaYZ2."\n";
471 
472 $BeamTheta2Deg = rad2deg($BeamTheta2);
473 $BeamPhi2Deg = rad2deg($BeamPhi2);
474 
475 ######################### Beam Window 3 Parameters ###################
476 
477 $thetaYZ = 11.342;
478 $theta3XZ = 11.844;
479 
480 $BeamTheta3 = atan (sqrt(tan(deg2rad($theta3XZ))**2 +tan(deg2rad($thetaYZ))**2));
481 $BeamPhi3 = atan (tan(deg2rad($thetaYZ))/tan(deg2rad($theta3XZ)));
482 
483 print "BeamTheta3 = ".$BeamTheta3."\n";
484 print "BeamPhi3 = ".$BeamPhi3."\n";
485 
486 
487 $thetaYZ3prime = rad2deg(atan(sin($BeamTheta3)*sin($BeamPhi3+deg2rad(180))/sqrt(cos($BeamTheta3)**2 + sin($BeamTheta3)**2*cos($BeamPhi3)**2)));
488 
489 print "thetaYZ3prime =".$thetaYZ3prime."\n";
490 
491 $DeltaXZ3 = tan($BeamTheta3)*cos($BeamPhi3);
492 $DeltaYZ3 = tan($BeamTheta3)*sin($BeamPhi3);
493 
494 $BeamPipeRad = 12.5;
495 $BeamVaPipeRad = $BeamPipeRad - 0.2;
496 $BeamPipeLe = 900.0;
497 $BeamVaPipeLe = $BeamPipeLe;
498 $BeamWFoLe = 52.0;
499 $BeamWGlLe = 10.0;
500 $BeamWStPlateFF_x = - 41.0;
501 $BeamWStPlateFF_y = 125.7;
502 $BeamWStPlateFF_z = - ($Cryostat_z/2 + $FoamPadding + $SteelPlate);
503 print "BeamWStPlateFF_z = ".$BeamWStPlateFF_z."\n";
504 #$BeamWStPlateFF_z = -508.4;
505 
506 $BeamWStPlateLe = $SteelPlate/cos($BeamTheta3)+0.001;
507 $BeamWStPlate_x = $BeamWStPlateFF_x - ($SteelPlate/2)*$DeltaXZ3;
508 $BeamWStPlate_y = $BeamWStPlateFF_y - ($SteelPlate/2)*$DeltaYZ3;
509 $BeamWStPlate_z = $BeamWStPlateFF_z + $SteelPlate/2;
510 
511 $BeamWFoRemLe = $FoamPadding/cos($BeamTheta3)+0.001;
512 $BeamWFoRemPosDZ = $SteelPlate + $FoamPadding/2;
513 $BeamWFoRem_x = $BeamWStPlateFF_x - $BeamWFoRemPosDZ*$DeltaXZ3;
514 $BeamWFoRem_y = $BeamWStPlateFF_y - $BeamWFoRemPosDZ*$DeltaYZ3;
515 $BeamWFoRem_z = $BeamWStPlateFF_z + $BeamWFoRemPosDZ;
516 
517 $BeamWStSuLe = ($SteelSupport_z - $SteelPlate)/cos($BeamTheta3)+0.001;
518 $BeamWStSuPosDZ = - ($SteelSupport_z - $SteelPlate)/2; # going upstream from the steel plate
519 $BeamWStSu_x = $BeamWStPlateFF_x - $BeamWStSuPosDZ*$DeltaXZ3;
520 $BeamWStSu_y = $BeamWStPlateFF_y - $BeamWStSuPosDZ*$DeltaYZ3;
521 $BeamWStSu_z = $BeamWStPlateFF_z + $BeamWStSuPosDZ;
522 
523 $BeamWFoPosDZ = $SteelPlate + $FoamPadding - $BeamWFoLe*cos($BeamTheta3)/2;
524 $BeamWFo_x = $BeamWStPlateFF_x - $BeamWFoPosDZ*$DeltaXZ3;
525 $BeamWFo_y = $BeamWStPlateFF_y - $BeamWFoPosDZ*$DeltaYZ3 + $posCryoInDetEnc_y;
526 $BeamWFo_z = $BeamWStPlateFF_z + $BeamWFoPosDZ;
527 
528 $BeamWGlPosDZ = $SteelPlate + $FoamPadding - ($BeamWFoLe + $BeamWGlLe/2)*cos($BeamTheta3);
529 $BeamWGl_x = $BeamWStPlateFF_x - $BeamWGlPosDZ*$DeltaXZ3;
530 $BeamWGl_y = $BeamWStPlateFF_y - $BeamWGlPosDZ*$DeltaYZ3 + $posCryoInDetEnc_y;
531 $BeamWGl_z = $BeamWStPlateFF_z + $BeamWGlPosDZ;
532 
533 $BeamWVaPosDZ = $SteelPlate + $FoamPadding - ($BeamWFoLe + $BeamWGlLe + $BeamPipeLe/2)*cos($BeamTheta3);
534 $BeamWVa_x = $BeamWStPlateFF_x - $BeamWVaPosDZ*$DeltaXZ3;
535 $BeamWVa_y = $BeamWStPlateFF_y - $BeamWVaPosDZ*$DeltaYZ3 + $posCryoInDetEnc_y;
536 $BeamWVa_z = $BeamWStPlateFF_z + $BeamWVaPosDZ;
537 
538 $BeamPlugRad = 10.48;
539 $BeamPlugNiRad = 9.72;
540 $BeamPlugUSAr = 1/cos($BeamTheta3); # 1 cm US LAr layer between beam plug and primary membrane
541 $BeamPlugLe = (44.6)/cos($BeamTheta3) - $BeamPlugUSAr; #with current geometry and 49.22 Dz the flange's front face just touches the active volume.
542 $BeamPlugNiLe = $BeamPlugLe-0.59/cos($BeamTheta3);
543 
544 $BeamPlugPosDZ = $SteelPlate + $FoamPadding + $SteelThickness + $BeamPlugUSAr + $BeamPlugLe*cos($BeamTheta3)/2;
545 $BeamPlug_x = $BeamWStPlateFF_x - $BeamPlugPosDZ*$DeltaXZ3;
546 $BeamPlug_y = $BeamWStPlateFF_y - $BeamPlugPosDZ*$DeltaYZ3;
547 $BeamPlug_z = $BeamWStPlateFF_z + $BeamPlugPosDZ;
548 
549 $BePlFlangePosDZ = $SteelPlate + $FoamPadding + $SteelThickness + $BeamPlugUSAr + $BeamPlugLe*cos($BeamTheta3); #This is Dz to the end of the beam plug pipe needed for x,y position.
550 $BePlFlange_x = $BeamWStPlateFF_x - $BePlFlangePosDZ*$DeltaXZ3;
551 $BePlFlange_y = $BeamWStPlateFF_y - $BePlFlangePosDZ*$DeltaYZ3;
552 $BePlFlange_z = $BeamWStPlateFF_z + $BePlFlangePosDZ + 1.8; # Adding the half the thickness of the flange.
553 
554 #$BeamPlugERingPosZ = -$BeamPlugLe/2 + 6.83;
555 $BeamPlugERingPosZ = -$BeamPlugLe/2 + 5.5;
556 $BeamPlugNiPos_z = 0.59/2/cos($BeamTheta3);
557 
558 print "BeamPlugLe = $BeamPlugLe"."\n";
559 print "BeamTheta3 = $BeamTheta3"."\n";
560 print "BeamWStPlate x=$BeamWStPlate_x".", y=$BeamWStPlate_y".", z=$BeamWStPlate_z"."\n";
561 print "BeamWStSu x=$BeamWStSu_x".", y=$BeamWStSu_y".", z=$BeamWStSu_z"."\n";
562 print "BeamWFoRem x=$BeamWFoRem_x".", y=$BeamWFoRem_y".", z=$BeamWFoRem_z"."\n";
563 print "BeamWFo x=$BeamWFo_x".", y=$BeamWFo_y".", z=$BeamWFo_z"."\n";
564 print "BeamWGl x=$BeamWGl_x".", y=$BeamWGl_y".", z=$BeamWGl_z"."\n";
565 print "BeamWVa x=$BeamWVa_x".", y=$BeamWVa_y".", z=$BeamWVa_z"."\n";
566 print "CPAToWestCrWall=$CPAToWestCrWall"."\n";
567 print "BeamPlug x=$BeamPlug_x".", y=$BeamPlug_y".", z=$BeamPlug_z"."\n";
568 print "BeamPlugFlange x=$BePlFlange_x".", y=$BePlFlange_y".", z=$BePlFlange_z"."\n";
569 
570 $BeamTheta3Deg = rad2deg($BeamTheta3);
571 $BeamPhi3Deg = rad2deg($BeamPhi3);
572 
573 
574 $BWFFCoord3X = $BeamWStPlateFF_x - $BeamWStSuPosDZ*$DeltaXZ3*2
575  + $OriginXSet;
576 $BWFFCoord3Y = $BeamWStPlateFF_y - $BeamWStSuPosDZ*$DeltaYZ3*2
577  + $OriginYSet + $posCryoInDetEnc_y;
578 $BWFFCoord3Z = - ($Cryostat_z/2 + $SteelSupport_z + $FoamPadding)
579  + $OriginZSet;
580 print "BeamWStPlateFF_x=".$BeamWStPlateFF_x.", BeamWStPlateFF_y=".$BeamWStPlateFF_y."\n";
581 print "BeamWStSuPosDZ= $BeamWStSuPosDZ; "." DeltaYZ3=".$DeltaYZ3."\n";
582 print "BWFFCoord3X =".$BWFFCoord3X."\n";
583 print "BWFFCoord3Y =".$BWFFCoord3Y."\n";
584 print "BWFFCoord3Z =".$BWFFCoord3Z."\n";
585 
586 $BW3StPlCoordX = $BeamWStPlateFF_x + $OriginXSet;
587 $BW3StPlCoordY = $BeamWStPlateFF_y + $OriginYSet + $posCryoInDetEnc_y;
588 $BW3StPlCoordZ = $BeamWStPlateFF_z + $OriginZSet;
589 
590 print "BW3StPlCoordX =".$BW3StPlCoordX."\n";
591 print "BW3StPlCoordY =".$BW3StPlCoordY."\n";
592 print "BW3StPlCoordZ =".$BW3StPlCoordZ."\n";
593 
594 
595 ###################################################################
596 ######################## CRT Dimensions ##########################
597 
598 $CRTPaddleWidth = 5.0;
599 $CRTPaddleHeight = 1.0;
600 $CRTPaddleLength = 322.5;
601 
602 $CRTModWidth = 162.5;
603 $CRTModHeight = 2.0;
604 $CRTModLength = 322.5;
605 
606 # SuperModule Centers as per Survey Document
607 $CRT_DSTopLeft_x = 171.2;
608 $CRT_DSTopLeft_y = -473.88;
609 $CRT_DSTopLeftFr_z = 1042.13;
610 $CRT_DSTopLeftBa_z = 1050.13;
611 
612 $CRT_DSBotLeft_x = 176.51;
613 $CRT_DSBotLeft_y = -840.6;
614 $CRT_DSBotLeftFr_z = 1041.74;
615 $CRT_DSBotLeftBa_z = 1050.13;
616 
617 $CRT_DSTopRight_x = -176.23;
618 $CRT_DSTopRight_y = -474.85;
619 $CRT_DSTopRightFr_z = 1042.64;
620 $CRT_DSTopRightBa_z = 1050.85;
621 
622 $CRT_DSBotRight_x = -169.6;
623 $CRT_DSBotRight_y = -840.55;
624 $CRT_DSBotRightFr_z = 1042.88;
625 $CRT_DSBotRightBa_z = 1051.93;
626 
627 $CRT_USTopLeft_x = 393.6;
628 $CRT_USTopLeft_y = -401.33;
629 $CRT_USTopLeftFr_z = -295.05;
630 $CRT_USTopLeftBa_z = -286.85;
631 
632 $CRT_USBotLeft_x = 394.14;
633 $CRT_USBotLeft_y = -734.48;
634 $CRT_USBotLeftFr_z = -320.24;
635 $CRT_USBotLeftBa_z = -310.88;
636 
637 $CRT_USTopRight_x = -38.85;
638 $CRT_USTopRight_y = -400.85;
639 $CRT_USTopRightFr_z = -998.95;
640 $CRT_USTopRightBa_z = -990.97;
641 
642 $CRT_USBotRight_x = -31.47;
643 $CRT_USBotRight_y = -735.13;
644 $CRT_USBotRightFr_z = -1022.25;
645 $CRT_USBotRightBa_z = -1015.01;
646 
647 # Coordinates of Survey origin w.r.t. Steel Plate box center as per penetrations steel plate drawing (flange 1.2)
648 $CRTSurveyOrigin_x = -36.0;
649 $CRTSurveyOrigin_y = 534.43;
650 $CRTSurveyOrigin_z = -344.1;
651 
652 # Distance between CRT module centers and CRT SuperModule Centers
653 $ModuleSMDist = 85.6;
654 $ModuleOff_z = 1; # approx. correction for the center of a Module. Survey measures Z to the outside surface. Negative for the most US CRTs (surveyed from behind).
655 $ModuleLongCorr = 5.6; # allign the the modules at the frame's edge
656 
657 # Beam Spot on the inside of the cryostat
658 
659 $BeamSpotDSS_x = -20.58;
660 $BeamSpotDSS_y = -425.41;
661 $BeamSpotDSS_z = -82.96;
662 
663 $BeamSpot_x = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $BeamSpotDSS_x + $OriginXSet;;
664 $BeamSpot_y = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $BeamSpotDSS_y + $OriginYSet;;
665 $BeamSpot_z = $posCryoInDetEnc_z + $CRTSurveyOrigin_z + $BeamSpotDSS_z + $OriginZSet;;
666 
667 print "BeamSpot_x =".$BeamSpot_x.", BeamSpot_y =".$BeamSpot_y.", BeamSpot_z =".$BeamSpot_z."\n";
668 
669 ####################### End of Survey data ##########
670 
671 
672 my @posCRTDS_x = ();
673 my @posCRTDS_y = ();
674 my @posCRTDS_z = ();
675 my @posCRTDS_rot = ();
676 
677 $posCRTDS_x[0] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSTopLeft_x - $ModuleSMDist;
678 $posCRTDS_y[0] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSTopLeft_y - $ModuleLongCorr;
679 $posCRTDS_z[0] = $CRTSurveyOrigin_z + $CRT_DSTopLeftBa_z + $ModuleOff_z;
680 $posCRTDS_rot[0] = "rPlus90AboutX";
681 
682 $posCRTDS_x[1] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSTopLeft_x + $ModuleSMDist;
683 $posCRTDS_y[1] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSTopLeft_y - $ModuleLongCorr;
684 $posCRTDS_z[1] = $CRTSurveyOrigin_z + $CRT_DSTopLeftBa_z + $ModuleOff_z;
685 $posCRTDS_rot[1] = "rPlus90AboutX";
686 
687 $posCRTDS_x[2] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSTopLeft_x - $ModuleLongCorr;
688 $posCRTDS_y[2] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSTopLeft_y - $ModuleSMDist;
689 $posCRTDS_z[2] = $CRTSurveyOrigin_z + $CRT_DSTopLeftFr_z + $ModuleOff_z;
690 $posCRTDS_rot[2] = "rMinus90AboutYMinus90AboutX";
691 
692 $posCRTDS_x[3] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSTopLeft_x - $ModuleLongCorr;
693 $posCRTDS_y[3] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSTopLeft_y + $ModuleSMDist;
694 $posCRTDS_z[3] = $CRTSurveyOrigin_z + $CRT_DSTopLeftFr_z + $ModuleOff_z;
695 $posCRTDS_rot[3] = "rMinus90AboutYMinus90AboutX";
696 
697 $posCRTDS_x[4] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSBotLeft_x - $ModuleSMDist;
698 $posCRTDS_y[4] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSBotLeft_y + $ModuleLongCorr;
699 $posCRTDS_z[4] = $CRTSurveyOrigin_z + $CRT_DSBotLeftFr_z + $ModuleOff_z;
700 $posCRTDS_rot[4] = "rPlus90AboutX";
701 
702 $posCRTDS_x[5] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSBotLeft_x + $ModuleSMDist;
703 $posCRTDS_y[5] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSBotLeft_y + $ModuleLongCorr;
704 $posCRTDS_z[5] = $CRTSurveyOrigin_z + $CRT_DSBotLeftFr_z + $ModuleOff_z;
705 $posCRTDS_rot[5] = "rPlus90AboutX";
706 
707 $posCRTDS_x[6] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSBotLeft_x - $ModuleLongCorr;
708 $posCRTDS_y[6] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSBotLeft_y - $ModuleSMDist;
709 $posCRTDS_z[6] = $CRTSurveyOrigin_z + $CRT_DSBotLeftBa_z + $ModuleOff_z;
710 $posCRTDS_rot[6] = "rMinus90AboutYMinus90AboutX";
711 
712 $posCRTDS_x[7] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSBotLeft_x - $ModuleLongCorr;
713 $posCRTDS_y[7] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSBotLeft_y + $ModuleSMDist;
714 $posCRTDS_z[7] = $CRTSurveyOrigin_z + $CRT_DSBotLeftBa_z + $ModuleOff_z;
715 $posCRTDS_rot[7] = "rMinus90AboutYMinus90AboutX";
716 
717 $posCRTDS_x[8] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSTopRight_x - $ModuleSMDist;
718 $posCRTDS_y[8] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSTopRight_y - $ModuleLongCorr;
719 $posCRTDS_z[8] = $CRTSurveyOrigin_z + $CRT_DSTopRightFr_z + $ModuleOff_z;
720 $posCRTDS_rot[8] = "rPlus90AboutX";
721 
722 $posCRTDS_x[9] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSTopRight_x + $ModuleSMDist;
723 $posCRTDS_y[9] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSTopRight_y - $ModuleLongCorr;
724 $posCRTDS_z[9] = $CRTSurveyOrigin_z + $CRT_DSTopRightFr_z + $ModuleOff_z;
725 $posCRTDS_rot[9] = "rPlus90AboutX";
726 
727 $posCRTDS_x[10] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSTopRight_x + $ModuleLongCorr;
728 $posCRTDS_y[10] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSTopRight_y - $ModuleSMDist;
729 $posCRTDS_z[10] = $CRTSurveyOrigin_z + $CRT_DSTopRightBa_z + $ModuleOff_z;
730 $posCRTDS_rot[10] = "rMinus90AboutYMinus90AboutX";
731 
732 $posCRTDS_x[11] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSTopRight_x + $ModuleLongCorr;
733 $posCRTDS_y[11] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSTopRight_y + $ModuleSMDist;
734 $posCRTDS_z[11] = $CRTSurveyOrigin_z + $CRT_DSTopRightBa_z + $ModuleOff_z;
735 $posCRTDS_rot[11] = "rMinus90AboutYMinus90AboutX";
736 
737 $posCRTDS_x[12] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSBotRight_x - $ModuleSMDist;
738 $posCRTDS_y[12] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSBotRight_y + $ModuleLongCorr;
739 $posCRTDS_z[12] = $CRTSurveyOrigin_z + $CRT_DSBotRightBa_z + $ModuleOff_z;
740 $posCRTDS_rot[12] = "rPlus90AboutX";
741 
742 $posCRTDS_x[13] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSBotRight_x + $ModuleSMDist;
743 $posCRTDS_y[13] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSBotRight_y + $ModuleLongCorr;
744 $posCRTDS_z[13] = $CRTSurveyOrigin_z + $CRT_DSBotRightBa_z + $ModuleOff_z;
745 $posCRTDS_rot[13] = "rPlus90AboutX";
746 
747 $posCRTDS_x[14] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSBotRight_x + $ModuleLongCorr;
748 $posCRTDS_y[14] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSBotRight_y - $ModuleSMDist;
749 $posCRTDS_z[14] = $CRTSurveyOrigin_z + $CRT_DSBotRightFr_z + $ModuleOff_z;
750 $posCRTDS_rot[14] = "rMinus90AboutYMinus90AboutX";
751 
752 $posCRTDS_x[15] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_DSBotRight_x + $ModuleLongCorr;
753 $posCRTDS_y[15] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_DSBotRight_y + $ModuleSMDist;
754 $posCRTDS_z[15] = $CRTSurveyOrigin_z + $CRT_DSBotRightFr_z + $ModuleOff_z;
755 $posCRTDS_rot[15] = "rMinus90AboutYMinus90AboutX";
756 
757 
758 my @posCRTUS_x = ();
759 my @posCRTUS_y = ();
760 my @posCRTUS_z = ();
761 my @posCRTUS_rot = ();
762 
763 
764 $posCRTUS_x[0] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USTopLeft_x - $ModuleSMDist;
765 $posCRTUS_y[0] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USTopLeft_y - $ModuleLongCorr;
766 $posCRTUS_z[0] = $CRTSurveyOrigin_z + $CRT_USTopLeftBa_z + $ModuleOff_z;
767 $posCRTUS_rot[0] = "rPlus90AboutX";
768 
769 $posCRTUS_x[1] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USTopLeft_x + $ModuleSMDist;
770 $posCRTUS_y[1] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USTopLeft_y - $ModuleLongCorr;
771 $posCRTUS_z[1] = $CRTSurveyOrigin_z + $CRT_USTopLeftBa_z + $ModuleOff_z;
772 $posCRTUS_rot[1] = "rPlus90AboutX";
773 
774 $posCRTUS_x[2] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USTopLeft_x - $ModuleLongCorr;
775 $posCRTUS_y[2] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USTopLeft_y - $ModuleSMDist;
776 $posCRTUS_z[2] = $CRTSurveyOrigin_z + $CRT_USTopLeftFr_z + $ModuleOff_z;
777 $posCRTUS_rot[2] = "rMinus90AboutYMinus90AboutX";
778 
779 $posCRTUS_x[3] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USTopLeft_x - $ModuleLongCorr;
780 $posCRTUS_y[3] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USTopLeft_y + $ModuleSMDist;
781 $posCRTUS_z[3] = $CRTSurveyOrigin_z + $CRT_USTopLeftFr_z + $ModuleOff_z;
782 $posCRTUS_rot[3] = "rMinus90AboutYMinus90AboutX";
783 
784 $posCRTUS_x[4] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USBotLeft_x - $ModuleSMDist;
785 $posCRTUS_y[4] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USBotLeft_y + $ModuleLongCorr;
786 $posCRTUS_z[4] = $CRTSurveyOrigin_z + $CRT_USBotLeftFr_z + $ModuleOff_z;
787 $posCRTUS_rot[4] = "rPlus90AboutX";
788 
789 $posCRTUS_x[5] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USBotLeft_x + $ModuleSMDist;
790 $posCRTUS_y[5] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USBotLeft_y + $ModuleLongCorr;
791 $posCRTUS_z[5] = $CRTSurveyOrigin_z + $CRT_USBotLeftFr_z + $ModuleOff_z;
792 $posCRTUS_rot[5] = "rPlus90AboutX";
793 
794 $posCRTUS_x[6] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USBotLeft_x - $ModuleLongCorr;
795 $posCRTUS_y[6] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USBotLeft_y - $ModuleSMDist;
796 $posCRTUS_z[6] = $CRTSurveyOrigin_z + $CRT_USBotLeftBa_z + $ModuleOff_z;
797 $posCRTUS_rot[6] = "rMinus90AboutYMinus90AboutX";
798 
799 $posCRTUS_x[7] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USBotLeft_x - $ModuleLongCorr;
800 $posCRTUS_y[7] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USBotLeft_y + $ModuleSMDist;
801 $posCRTUS_z[7] = $CRTSurveyOrigin_z + $CRT_USBotLeftBa_z + $ModuleOff_z;
802 $posCRTUS_rot[7] = "rMinus90AboutYMinus90AboutX";
803 
804 $posCRTUS_x[8] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USTopRight_x - $ModuleSMDist;
805 $posCRTUS_y[8] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USTopRight_y - $ModuleLongCorr;
806 $posCRTUS_z[8] = $CRTSurveyOrigin_z + $CRT_USTopRightFr_z - $ModuleOff_z;
807 $posCRTUS_rot[8] = "rPlus90AboutX";
808 
809 $posCRTUS_x[9] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USTopRight_x + $ModuleSMDist;
810 $posCRTUS_y[9] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USTopRight_y - $ModuleLongCorr;
811 $posCRTUS_z[9] = $CRTSurveyOrigin_z + $CRT_USTopRightFr_z - $ModuleOff_z;
812 $posCRTUS_rot[9] = "rPlus90AboutX";
813 
814 $posCRTUS_x[10] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USTopRight_x + $ModuleLongCorr;
815 $posCRTUS_y[10] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USTopRight_y - $ModuleSMDist;
816 $posCRTUS_z[10] = $CRTSurveyOrigin_z + $CRT_USTopRightBa_z - $ModuleOff_z;
817 $posCRTUS_rot[10] = "rMinus90AboutYMinus90AboutX";
818 
819 $posCRTUS_x[11] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USTopRight_x + $ModuleLongCorr;
820 $posCRTUS_y[11] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USTopRight_y + $ModuleSMDist;
821 $posCRTUS_z[11] = $CRTSurveyOrigin_z + $CRT_USTopRightBa_z - $ModuleOff_z;
822 $posCRTUS_rot[11] = "rMinus90AboutYMinus90AboutX";
823 
824 $posCRTUS_x[12] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USBotRight_x - $ModuleSMDist;
825 $posCRTUS_y[12] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USBotRight_y + $ModuleLongCorr;
826 $posCRTUS_z[12] = $CRTSurveyOrigin_z + $CRT_USBotRightBa_z - $ModuleOff_z;
827 $posCRTUS_rot[12] = "rPlus90AboutX";
828 
829 $posCRTUS_x[13] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USBotRight_x + $ModuleSMDist;
830 $posCRTUS_y[13] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USBotRight_y + $ModuleLongCorr;
831 $posCRTUS_z[13] = $CRTSurveyOrigin_z + $CRT_USBotRightBa_z - $ModuleOff_z;
832 $posCRTUS_rot[13] = "rPlus90AboutX";
833 
834 $posCRTUS_x[14] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USBotRight_x + $ModuleLongCorr;
835 $posCRTUS_y[14] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USBotRight_y - $ModuleSMDist;
836 $posCRTUS_z[14] = $CRTSurveyOrigin_z + $CRT_USBotRightFr_z - $ModuleOff_z;
837 $posCRTUS_rot[14] = "rMinus90AboutYMinus90AboutX";
838 
839 $posCRTUS_x[15] = $posCryoInDetEnc_x + $CRTSurveyOrigin_x + $CRT_USBotRight_x + $ModuleLongCorr;
840 $posCRTUS_y[15] = $posCryoInDetEnc_y + $CRTSurveyOrigin_y + $CRT_USBotRight_y + $ModuleSMDist;
841 $posCRTUS_z[15] = $CRTSurveyOrigin_z + $CRT_USBotRightFr_z - $ModuleOff_z;
842 $posCRTUS_rot[15] = "rMinus90AboutYMinus90AboutX";
843 
844 ###################################################################
845 ######################## Paddle Dimensions ########################
846 
847 $APAFrameZSide_y = 4*$inch;
848 $APAFrameYSide_z = 4*$inch;
849 $LightPaddle_x = 0.476;
850 $LightPaddle_y = 4*$inch;
851 $LightPaddle_z = $APAFrame_z - 2*$APAFrameYSide_z;
852 $nLightPaddlesPerAPA = 10; # 10, or 20 for double coverage (for now)
853 #$PaddleYInterval = (2*$APAphys_y+$APAGap_y-$LightPaddle_y-2*$APAFrameZSide_y)
854 # /(2*$nLightPaddlesPerAPA-1);
855 $PaddleYInterval = 59.2;
856 #$FrameToPaddleSpace = ($PaddleYInterval-$APAGap_y)/2;
857 $FrameToPaddleSpace = 30.412;
858 $SiPM_z = 0;
859 
860 # $PaddleYInterval is defined so that the center-to-center distance in the
861 # y direction between paddles is uniform between vertically stacked APAs.
862 # $FrameToPaddleSpace is from the BOTTOM of the APA frame (4" in y direction)
863 # to the CENTER of a paddle, including the 4" part of the frame. This variable's
864 # primary purpose is to position the lowest paddle in each APA.
865 
866 
867 ####################################################################
868 ######################## ARAPUCA Dimensions ########################
869 
870 $ArapucaOut_x = 16.0;
871 $ArapucaOut_y = 96.0;
872 $ArapucaOut_z = 10.0*$LightPaddle_z;
873 $ArapucaIn_x = 15.0;
874 $ArapucaIn_y = 80.0;
875 $ArapucaIn_z = 100.0;
876 $ArapucaAcceptanceWindow_x =1.0;
877 $ArapucaAcceptanceWindow_y =80.0;
878 $ArapucaAcceptanceWindow_z =100.0;
879 $pos_subtraction_arapuca_x = 2.0;
880 $gapCenterLeft_arapuca_z = 50.0;#if not simmetrical, positioning of windows for odd APAs needs to change
881 $gapCenterRight_arapuca_z = 100.0-$gapCenterLeft_arapuca_z;
882 $nAraAPA1 = 0;
883 $nAraAPA2 = 3;
884 $nSlotAra1 = 6;
885 $nSlotAra2 = 4;
886 
887 $list_pos[0]=-$gapCenterLeft_arapuca_z-0.5*$ArapucaIn_z;
888 for($list=1; $list<8; $list++){
889 $list_pos[$list]=$list_pos[$i-1]-1.0*$ArapucaIn_z-2.0;
890 }
891 $list_pos[8]=$gapCenterRight_arapuca_z+0.5*$ArapucaIn_z;
892 for($list=9; $list<16; $list++){
893 $list_pos[$list]=$list_pos[$i-1]+$ArapucaIn_z+2.0;
894 }
895 
896 #nAraAPAi is the number of the APA that the ith arapuca bar goes into and nSlotArai, its slot in that APA. These numbers are valid for the protodune-sp geometry.
897 
898 
899 
900 
901 #+++++++++++++++++++++++++ End defining variables ++++++++++++++++++++++++++
902 
903 
904 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
905 #+++++++++++++++++++++++++++++++++++++++++ usage +++++++++++++++++++++++++++++++++++++++++
906 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
907 
908 sub usage()
909 {
910  print "Usage: $0 [-h|--help] [-o|--output <fragments-file>] [-s|--suffix <string>]\n";
911  print " if -o is omitted, output goes to STDOUT; <fragments-file> is input to make_gdml.pl\n";
912  print " -s <string> appends the string to the file names; useful for multiple detector versions\n";
913  print " -h prints this message, then quits\n";
914 }
915 
916 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
917 #++++++++++++++++++++++++++++++++++++++ gen_Extend +++++++++++++++++++++++++++++++++++++++
918 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
919 
920 sub gen_Extend()
921 {
922 
923 # Create the <define> fragment file name,
924 # add file to list of fragments,
925 # and open it
926  $DEF = "subfile_protodune_v7_Ext" . $suffix . ".gdml";
927  push (@gdmlFiles, $DEF);
928  $DEF = ">" . $DEF;
929  open(DEF) or die("Could not open file $DEF for writing");
930 
931 print DEF <<EOF;
932 <?xml version='1.0'?>
933 <gdml>
934 <extension>
935  <color name="magenta" R="0.0" G="1.0" B="0.0" A="1.0" />
936  <color name="green" R="0.0" G="1.0" B="0.0" A="1.0" />
937  <color name="red" R="1.0" G="0.0" B="0.0" A="1.0" />
938  <color name="blue" R="0.0" G="0.0" B="1.0" A="1.0" />
939  <color name="yellow" R="1.0" G="1.0" B="0.0" A="1.0" />
940 </extension>
941 </gdml>
942 EOF
943  close (DEF);
944 }
945 
946 
947 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
948 #++++++++++++++++++++++++++++++++++++++ gen_Define +++++++++++++++++++++++++++++++++++++++
949 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
950 
951 sub gen_Define()
952 {
953 
954 # Create the <define> fragment file name,
955 # add file to list of fragments,
956 # and open it
957  $DEF = "subfile_protodune_v7_Def" . $suffix . ".gdml";
958  push (@gdmlFiles, $DEF);
959  $DEF = ">" . $DEF;
960  open(DEF) or die("Could not open file $DEF for writing");
961 
962 $UWireAngle = 90-$UAngle;
963 $VWireAngle = 90+$VAngle;
964 print DEF <<EOF;
965 <?xml version='1.0'?>
966 <gdml>
967 <define>
968 
969 <!--
970 
971 
972 
973 -->
974 
975  <position name="posCryoInDetEnc" unit="cm" x="0" y="$posCryoInDetEnc_y" z="0"/>
976  <position name="posCenter" unit="cm" x="0" y="0" z="0"/>
977  <position name="posBeamWAr3" unit="cm" x="$BeamPlug_x" y="$BeamPlug_y" z="$BeamPlug_z"/>
978  <rotation name="rPlus90AboutX" unit="deg" x="90" y="0" z="0"/>
979  <rotation name="rMinus90AboutY" unit="deg" x="0" y="270" z="0"/>
980  <rotation name="rMinus90AboutYMinus90AboutX" unit="deg" x="270" y="270" z="0"/>
981  <rotation name="rPlusUAngleAboutX" unit="deg" x="$UWireAngle" y="0" z="0"/>
982  <rotation name="rPlusVAngleAboutX" unit="deg" x="$VWireAngle" y="0" z="0"/>
983  <rotation name="rPlus180AboutX" unit="deg" x="180" y="0" z="0"/>
984  <rotation name="rPlus180AboutY" unit="deg" x="0" y="180" z="0"/>
985  <rotation name="rPlus180AboutZ" unit="deg" x="0" y="0" z="180"/>
986  <rotation name="rPlus180AboutXPlus180AboutY" unit="deg" x="180" y="180" z="0"/>
987  <rotation name="rPlus90AboutXPlus90AboutZ" unit="deg" x="90" y="0" z="90"/>
988  <rotation name="rPlus180AboutXPlus180AboutZ" unit="deg" x="180" y="0" z="180"/>
989  <rotation name="rIdentity" unit="deg" x="0" y="0" z="0"/>
990  <rotation name="rBeamW2" unit="deg" x="0" y="-$BeamTheta2Deg" z="$BeamPhi2Deg"/>
991  <rotation name="rBeamWRev2" unit="deg" x="-11.342" y="8.03118195044" z="-55.1415281209"/>
992  <rotation name="rBeamW3" unit="deg" x="0" y="-$BeamTheta3Deg" z="$BeamPhi3Deg"/>
993  <rotation name="rBeamWRev3" unit="deg" x="-11.342" y="11.6190450403" z="-44.8829268772"/>
994  <position name="posArapucaSub0" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[0]]}"/>
995  <position name="posArapucaSub1" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[1]]}"/>
996  <position name="posArapucaSub2" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[2]]}"/>
997  <position name="posArapucaSub3" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[3]]}"/>
998  <position name="posArapucaSub4" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[4]]}"/>
999  <position name="posArapucaSub5" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[5]]}"/>
1000  <position name="posArapucaSub6" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[6]]}"/>
1001  <position name="posArapucaSub7" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[7]]}"/>
1002  <position name="posArapucaSub8" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[8]]}"/>
1003  <position name="posArapucaSub9" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[9]]}"/>
1004  <position name="posArapucaSub10" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[10]]}"/>
1005  <position name="posArapucaSub11" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[11]]}"/>
1006  <position name="posArapucaSub12" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[12]]}"/>
1007  <position name="posArapucaSub13" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[13]]}"/>
1008  <position name="posArapucaSub14" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[14]]}"/>
1009  <position name="posArapucaSub15" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[15]]}"/>
1010 </define>
1011 </gdml>
1012 EOF
1013  close (DEF);
1014 }
1015 
1016 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1017 #+++++++++++++++++++++++++++++++++++++ gen_Materials +++++++++++++++++++++++++++++++++++++
1018 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1019 
1020 sub gen_Materials()
1021 {
1022 
1023 # Create the <materials> fragment file name,
1024 # add file to list of output GDML fragments,
1025 # and open it
1026  $MAT = "subfile_protodune_v7_Materials" . $suffix . ".gdml";
1027  push (@gdmlFiles, $MAT);
1028  $MAT = ">" . $MAT;
1029 
1030  open(MAT) or die("Could not open file $MAT for writing");
1031 
1032  # Add any materials special to this geometry by defining a mulitline string
1033  # and passing it to the gdmlMaterials::gen_Materials() function.
1034  $spdensity = 0.001205*(1-$FracVolOfSteel) + 7.9300*$FracVolOfSteel;
1035  $ssairfrac = (1-$FracMassOfSteel);
1036 my $asmix = <<EOF;
1037  <!-- preliminary values -->
1038  <material name="AirSteelMixture" formula="AirSteelMixture">
1039  <D value="$spdensity" unit="g/cm3"/>
1040  <fraction n="$FracMassOfSteel" ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
1041  <fraction n="$ssairfrac" ref="Air"/>
1042  </material>
1043 EOF
1044 
1045  # add the general materials used anywere
1046  print MAT gdmlMaterials::gen_Materials( $asmix );
1047 
1048  close(MAT);
1049 }
1050 
1051 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1052 #++++++++++++++++++++++++++++++++++++++++ gen_TPC ++++++++++++++++++++++++++++++++++++++++
1053 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1054 
1055 
1056 sub gen_TPC
1057 {
1058 
1059 # $_[0] = $TPC_x
1060 # $_[1] = $TPC_y
1061 # $_[2] = $TPC_z
1062 # $_[3] = 'name'
1063 
1064  my $TPCActive_x = $_[0] - 3*$APAWirePlaneSpacing -3*$TPCWirePlaneThickness;
1065  if( ($protoDune == 1) && ($_[3] eq 'Outer') ){
1066  $TPCActive_x = 3*($APAWirePlaneSpacing + $TPCWirePlaneThickness);
1067  }
1068  my $TPCActive_y = $_[1] - $APAGap_y/2 - $ReadoutBoardOverlap + $G10thickness; #TODO: make the Active height more accurate
1069  my $TPCActive_z = $_[2];
1070 
1071 
1072 #constructs everything inside volTPC, namely
1073 # (moving from left to right, or from +x to -x)
1074 # -volCPActive
1075 # -volTPCPlaneU: with wires angled from vertical slightly different than in V
1076 # -volTPCPlaneV: with wires angled from vertical slightly differently than in U
1077 # -volTPCPlaneX: with vertical wires
1078 
1079 
1080 # Create the TPC fragment file name,
1081 # add file to list of output GDML fragments,
1082 # and open it
1083  $TPC = "subfile_protodune_v7_TPC_${_[3]}" . $suffix . ".gdml";
1084  push (@gdmlFiles, $TPC);
1085  $TPC = ">" . $TPC;
1086  open(TPC) or die("Could not open file $TPC for writing");
1087 
1088 
1089 print $wout "\n\n\n----- Wires for $_[3] -----\n\n\n";
1090 
1091 
1092 # The standard XML prefix and starting the gdml
1093  print TPC <<EOF;
1094 <?xml version='1.0'?>
1095 <gdml>
1096 EOF
1097 
1098 
1099 # All the TPC solids save the wires.
1100  $uplact_y = $Uactive_y + $UVPlaneBoundNudge;
1101  $uplact_z = $Uactive_z + $UVPlaneBoundNudge;
1102  $vplact_y = $Vactive_y + $UVPlaneBoundNudge;
1103  $vplact_z = $Vactive_z + $UVPlaneBoundNudge;
1104 print TPC <<EOF;
1105 <solids>
1106  <box name="$_[3]" lunit="cm"
1107  x="$_[0]"
1108  y="$_[1]"
1109  z="$_[2]"/>
1110  <box name="${_[3]}UPlane" lunit="cm"
1111  x="$TPCWirePlaneThickness"
1112  y="$uplact_y"
1113  z="$uplact_z"/>
1114  <box name="${_[3]}VPlane" lunit="cm"
1115  x="$TPCWirePlaneThickness"
1116  y="$vplact_y"
1117  z="$vplact_z"/>
1118  <box name="${_[3]}ZPlane" lunit="cm"
1119  x="$TPCWirePlaneThickness"
1120  y="$Zactive_y"
1121  z="$Zactive_z"/>
1122 EOF
1123 #if(${_[3]} eq "Inner"){
1124 #print TPC <<EOF;
1125 # <box name="${_[3]}Active_NoCPA" lunit="cm"
1126 # x="$TPCActive_x"
1127 # y="$TPCActive_y"
1128 # z="$TPCActive_z"/>
1129 #EOF
1130 #}
1131 #else{
1132 print TPC <<EOF;
1133  <box name="${_[3]}Active" lunit="cm"
1134  x="$TPCActive_x"
1135  y="$TPCActive_y"
1136  z="$TPCActive_z"/>
1137 EOF
1138 #}
1139 
1140 
1141 #++++++++++++++++++++++++++++ Wire Solids ++++++++++++++++++++++++++++++
1142 $wirerad = 0.5*$TPCWireThickness;
1143 print TPC <<EOF;
1144 
1145  <tube name="${_[3]}WireVert"
1146  rmax="$wirerad"
1147  z="$Zactive_y"
1148  deltaphi="360"
1149  aunit="deg"
1150  lunit="cm"/>
1151 EOF
1152 
1153 # Set number of wires to default to zero, when $wires_on = 0, for a low memory
1154 # version. But if $wires_on = 1, calculate the number of wires on each side of each
1155 # plane to be used in the for loops
1156 
1157 my $NumberCornerUWires = 0;
1158 my $NumberSideUWires = 0;
1159 my $NumberCommonUWires = 0;
1160 my $NumberCornerVWires = 0;
1161 my $NumberSideVWires = 0;
1162 my $NumberCommonVWires = 0;
1163 my $NumberVerticalWires = 0;
1164 
1165 if ($wires_on == 1)
1166 {
1167  # Number of wires in one corner
1168 $NumberCornerUWires = int( $APAFrame_z/($UWirePitch/$CosUAngle) );
1169 
1170 $NumberCornerVWires = int( $APAFrame_z/($VWirePitch/$CosVAngle) );
1171 
1172 
1173  # Total number of wires touching one vertical (longer) side
1174  # Note that the total number of wires per plane is this + another set of corner wires
1175 $NumberSideUWires = int( $Uactive_y/$UWire_yint );
1176 if($Pitch3mmVersion==1){ $NumberSideUWires = $NumberSideUWires-1; }
1177 
1178 $NumberSideVWires = int( $Vactive_y/$VWire_yint );
1179 
1180  # Number of wires per side that aren't cut off by the corner
1181 $NumberCommonUWires = $NumberSideUWires - $NumberCornerUWires;
1182 
1183 $NumberCommonVWires = $NumberSideVWires - $NumberCornerVWires;
1184 
1185  # Number of wires on the vertical plane
1186  # Since APA Active z is defined in docdb 3383 to be distance
1187  # between outer vertical wires, + 1 since the floor of this
1188  # division will be one under, giving the amt of spaces, not wires
1189 $NumberVerticalWires = int( $Zactive_z/$XWirePitch ) + 1;
1190 #$NumberVerticalWires = 960;
1191 
1192 
1193 $nUchans = 2*$NumberCornerUWires;
1194 $nVchans = 2*$NumberCornerVWires;
1195 
1196 print $wout "$nUchans U channels\n";
1197 print $wout "$nVchans V channels\n";
1198 print $wout "$NumberVerticalWires Z channels per side\n";
1199 
1200 print $wout "$NumberCornerUWires U corner wires\n";
1201 print $wout "$NumberCommonUWires U common wires\n";
1202 print $wout "$NumberCornerVWires V corner wires\n";
1203 print $wout "$NumberCommonVWires V common wires\n";
1204 
1205 }
1206 
1207 # hard codeed number will be a factor determined from engineering spreadsheets on wire endpoints,
1208 # but since that won't exist for a while, use this number to avoid overlaps
1209 my $FirstUWireOffset = .55 + $G10thickness + 2*$G10thickness*$TanUAngle - $UWire_zint;
1210 my $FirstVWireOffset = .5; # doesnt include a G10 board in width
1211 
1212 if($Pitch3mmVersion==1){
1213  my $FirstUWireOffset = .15 + $G10thickness + 2*$G10thickness*$TanUAngle - $UWire_zint;
1214  my $FirstVWireOffset = .15; # doesnt include a G10 board in width
1215 }
1216 
1217 if($UVAngle45Option==1){$FirstVWireOffset = .7;}
1218 
1219 
1220 my $FirstTopUWire_yspan =
1221  $Uactive_y/2
1222  - ( - $Uactive_y/2
1223  + $FirstUWireOffset/$TanUAngle # walk us up to the first wire
1224  + $UWire_yint*($NumberSideUWires-1) # up to the top of the top common wire
1225  - $Uactive_z/$TanUAngle # back to the bottom of the top common wire
1226  + $UWire_yint); # nudge up to bottom of the first top corner wire
1227 
1228 my $FirstTopVWire_yspan =
1229  $Vactive_y/2
1230  - ( - $Vactive_y/2
1231  + $FirstVWireOffset/$TanVAngle # walk us up to the first wire
1232  + $VWire_yint*($NumberSideVWires-1) # up to the top of the top common wire
1233  - $Vactive_z/$TanVAngle # back to the bottom of the top common wire
1234  + $VWire_yint); # nudge up to bottom of the first top corner wire
1235 
1236 
1237 # The corner wires for the U plane
1238 if ($wires_on==1)
1239 {
1240  for ($i = 0; $i < $NumberCornerUWires; $i++)
1241  {
1242  $CornerUWireLength[$i] = ($FirstUWireOffset + $i*$UWire_zint)/$SinUAngle;
1243 
1244  print TPC <<EOF;
1245  <tube name="${_[3]}WireU$i"
1246  rmax="$wirerad"
1247  z="$CornerUWireLength[$i]"
1248  deltaphi="360"
1249  aunit="deg"
1250  lunit="cm"/>
1251 EOF
1252 
1253  }
1254 
1255  $CommonUWireLength = $Uactive_z/$SinUAngle;
1256 
1257  print TPC <<EOF;
1258  <tube name="${_[3]}WireUCommon"
1259  rmax="$wirerad"
1260  z="$CommonUWireLength"
1261  deltaphi="360"
1262  aunit="deg"
1263  lunit="cm"/>
1264 EOF
1265 
1266  for ($i = 0; $i < $NumberCornerUWires; $i++)
1267  {
1268 
1269  $TopCornerUWireLength[$i] = ($FirstTopUWire_yspan - $i*$UWire_yint)/$CosUAngle;
1270 
1271  $j = $i + $NumberSideUWires;
1272 
1273  print TPC <<EOF;
1274  <tube name="${_[3]}WireU$j"
1275  rmax="$wirerad"
1276  z="$TopCornerUWireLength[$i]"
1277  deltaphi="360"
1278  aunit="deg"
1279  lunit="cm"/>
1280 EOF
1281 
1282  }
1283 
1284 }
1285 
1286 
1287 # The corner wires for the V plane
1288 if ($wires_on==1)
1289 {
1290  for ($i = 0; $i < $NumberCornerVWires; ++$i)
1291  {
1292  $CornerVWireLength[$i] = ($FirstVWireOffset + $i*$VWire_zint)/$SinVAngle;
1293 
1294  print TPC <<EOF;
1295 
1296  <tube name="${_[3]}WireV$i"
1297  rmax="$wirerad"
1298  z="$CornerVWireLength[$i]"
1299  deltaphi="360"
1300  aunit="deg"
1301  lunit="cm"/>
1302 
1303 EOF
1304 
1305  }
1306 
1307  # The wire used many times in the middle of the V plane
1308  # Same subtraction as U common
1309 
1310  $CommonVWireLength = $Vactive_z/$SinVAngle;
1311 
1312  print TPC <<EOF;
1313  <tube name="${_[3]}WireVCommon"
1314  rmax="$wirerad"
1315  z="$CommonVWireLength"
1316  deltaphi="360"
1317  aunit="deg"
1318  lunit="cm"/>
1319 EOF
1320 
1321  for ($i = 0; $i < $NumberCornerVWires; $i++)
1322  {
1323 
1324  $TopCornerVWireLength[$i] = ($FirstTopVWire_yspan - $i*$VWire_yint)/$CosVAngle;
1325 
1326  $j = $i + $NumberSideVWires;
1327 
1328  print TPC <<EOF;
1329  <tube name="${_[3]}WireV$j"
1330  rmax="$wirerad"
1331  z="$TopCornerVWireLength[$i]"
1332  deltaphi="360"
1333  aunit="deg"
1334  lunit="cm"/>
1335 EOF
1336 
1337  }
1338 
1339 
1340 }
1341 
1342 # The active inner and active outer volumes are treated slightly differently
1343 my $subname = '';
1344 my $fieldStrength = '500';
1345 if ( ${_[3]} ne 'Inner' ){
1346  $fieldStrength = '0'; #assumption: no field in outer volume. This is currently unused in larg4
1347  $subname = ${_[3]}; #The volume name has to be "volTPCActive" for Inner
1348  #Can be anything for the outer volumes
1349 }
1350 
1351 # Begin structure and create the vertical wire logical volume
1352 # D.R. Add auxtypes utilized by larg4
1353 print TPC <<EOF;
1354 </solids>
1355 <structure>
1356  <volume name="volTPCActive${subname}">
1357  <materialref ref="LAr"/>
1358  <solidref ref="${_[3]}Active"/>
1359  <auxiliary auxtype="SensDet" auxvalue="SimEnergyDeposit"/>
1360  <auxiliary auxtype="StepLimit" auxunit="cm" auxvalue="0.47625*cm"/>
1361  <auxiliary auxtype="Efield" auxunit="V/cm" auxvalue="${fieldStrength}*V/cm"/>
1362  <colorref ref="blue"/>
1363  </volume>
1364 
1365 EOF
1366 
1367 
1368 if ($wires_on==1)
1369 {
1370  print TPC <<EOF;
1371  <volume name="volTPCWireVert${_[3]}">
1372  <materialref ref="Copper_Beryllium_alloy25"/>
1373  <solidref ref="${_[3]}WireVert"/>
1374  </volume>
1375 EOF
1376 
1377  # Corner U wires logical volumes
1378  for ($i = 0; $i < $NumberCornerUWires; ++$i)
1379  {
1380  print TPC <<EOF;
1381  <volume name="volTPCWireU$i${_[3]}">
1382  <materialref ref="Copper_Beryllium_alloy25"/>
1383  <solidref ref="${_[3]}WireU$i"/>
1384  </volume>
1385 EOF
1386  }
1387 
1388 
1389  # Top Corner U wires logical volumes
1390  for ($j = $NumberSideUWires; $j < $NumberSideUWires + $NumberCornerUWires; ++$j)
1391  {
1392  print TPC <<EOF;
1393  <volume name="volTPCWireU$j${_[3]}">
1394  <materialref ref="Copper_Beryllium_alloy25"/>
1395  <solidref ref="${_[3]}WireU$j"/>
1396  </volume>
1397 EOF
1398  }
1399 
1400 
1401  # Common U wire logical volume, referenced many times
1402  print TPC <<EOF;
1403  <volume name="volTPCWireUCommon${_[3]}">
1404  <materialref ref="Copper_Beryllium_alloy25"/>
1405  <solidref ref="${_[3]}WireUCommon"/>
1406  </volume>
1407 EOF
1408 
1409 
1410  # Corner V wires logical volumes
1411  for ($i = 0; $i < $NumberCornerVWires; ++$i)
1412  {
1413  print TPC <<EOF;
1414  <volume name="volTPCWireV$i${_[3]}">
1415  <materialref ref="Copper_Beryllium_alloy25"/>
1416  <solidref ref="${_[3]}WireV$i"/>
1417  </volume>
1418 EOF
1419 
1420  }
1421 
1422  # Top Corner V wires logical volumes
1423  for ($j = $NumberSideVWires; $j < $NumberSideVWires + $NumberCornerVWires; ++$j)
1424  {
1425  print TPC <<EOF;
1426  <volume name="volTPCWireV$j${_[3]}">
1427  <materialref ref="Copper_Beryllium_alloy25"/>
1428  <solidref ref="${_[3]}WireV$j"/>
1429  </volume>
1430 EOF
1431  }
1432 
1433  # Common V wire logical volume, referenced many times
1434  print TPC <<EOF;
1435  <volume name="volTPCWireVCommon${_[3]}">
1436  <materialref ref="Copper_Beryllium_alloy25"/>
1437  <solidref ref="${_[3]}WireVCommon"/>
1438  </volume>
1439 EOF
1440 
1441 }
1442 
1443 
1444 my $lastYpos = 0;
1445 my $lastZpos = 0;
1446 
1447 
1448 #+++++++++++++++++++++++++ Position physical wires ++++++++++++++++++++++++++
1449 
1450 # ++++++++++++++++++++++ U Plane +++++++++++++++++++++++
1451 
1452 # Create U plane logical volume
1453 print TPC <<EOF;
1454  <volume name="volTPCPlaneU${_[3]}">
1455  <materialref ref="LAr"/>
1456  <solidref ref="${_[3]}UPlane"/>
1457 EOF
1458 
1459 
1460 print $wout "\n- Wires for U plane -\n\n";
1461 print $wout " Uplane_y: $Uactive_y\n";
1462 print $wout " Uplane_z: $Uactive_z\n";
1463 
1464 
1465 if ($wires_on==1)
1466 {
1467 
1468 # Starting with the bottom left corner wires:
1469  # x=0 to center the wires in the plane
1470  # y positioning: (-0.5*$TPCWirePlaneHeight) starts the incremental increase
1471  # from the bottom of the plane, and trigonometry gives the increment
1472  # z positioning: Looking at the plane from the positive x direction,
1473  # (0.5*$TPCWirePlaneLength) starts the incremental increase from
1474  # the lower left corner.
1475  # rotation: same as common wire in code below
1476 
1477  $FirstU_ypos = - $Uactive_y/2 + $FirstUWireOffset/$TanUAngle/2;
1478  $FirstU_zpos = + $Uactive_z/2 - $FirstUWireOffset/2;
1479 
1480 for ($i = 0; $i < $NumberCornerUWires; ++$i)
1481 {
1482 
1483 my $ypos = $FirstU_ypos + ($i)*0.5*$UWire_yint;
1484 my $zpos = $FirstU_zpos - ($i)*0.5*$UWire_zint;
1485 
1486 $pitch = ($ypos - $lastYpos) * $SinUAngle
1487  - ($zpos - $lastZpos) * $CosUAngle;
1488 
1489 $xrotUAang = 90-$UAngle;
1490 print TPC <<EOF;
1491  <physvol>
1492  <volumeref ref="volTPCWireU$i${_[3]}"/>
1493  <position name="pos${_[3]}WireU$i" unit="cm" x="0" y="$ypos " z="$zpos"/>
1494  <rotation name="rUAngle$i" unit="deg" x="$xrotUAang" y="0" z="0"/>
1495  </physvol>
1496 EOF
1497 
1498 $topY = $ypos + ($CosUAngle*$CornerUWireLength[$i]/2);
1499 $bottomY = $ypos - ($CosUAngle*$CornerUWireLength[$i]/2);
1500 $edgeZ_p = $zpos + ($SinUAngle*$CornerUWireLength[$i]/2);
1501 $edgeZ_m = $zpos - ($SinUAngle*$CornerUWireLength[$i]/2);
1502 print $wout "U$i: ( $ypos , $zpos ) (pitch = $pitch)\n";
1503 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1504 
1505 $lastYpos = $ypos;
1506 $lastZpos = $zpos;
1507 
1508 }
1509 
1510 
1511 # Moving upwards to the common wires:
1512  # x and z are zero to center the wires along a vertical axis
1513  # y positioning: The trick is positioning the lowest common wire so that the pitch
1514  # is consistent, then the increment is double the increment of
1515  # the corner wires since there is no z incriment.
1516  # rotation: wires in \\\\ direction, so +90deg to bring them to vertical and
1517  # +UAngle counterclockwise to arrive at proper orientation
1518 # Note that the counter maintains wire number (in pos. name) counting bottom to top
1519 
1520 
1521 my $StartCommonUWires_ypos = $lastYpos + $UWire_yint - abs( $lastZpos )/$TanUAngle;
1522 
1523 for ($i = $NumberCornerUWires; $i < $NumberSideUWires; ++$i)
1524 {
1525 
1526  $j = $i - $NumberCornerUWires;
1527  my $ypos = $StartCommonUWires_ypos + $UWire_yint*($j);
1528 
1529  $lastWnum = $i-1;
1530  if ( $ypos < $lastYpos ){ print "WARNING: y position dropped from $lastYpos (wire U$lastWnum) to $ypos (wire U$i)\n"; }
1531  if ( $ypos == $lastYpos ){ print "WARNING: y position between wire U$lastWnum and U$lastWnum did not move: $ypos\n"; }
1532 
1533 
1534 $pitch = ($ypos - $lastYpos) * $SinUAngle - ($zpos - $lastZpos) * $CosUAngle ;
1535 
1536 $xrotUAang = 90-$UAngle;
1537 print TPC <<EOF;
1538  <physvol>
1539  <volumeref ref="volTPCWireUCommon${_[3]}"/>
1540  <position name="pos${_[3]}WireU$i" unit="cm" x="0" y="$ypos " z="0"/>
1541  <rotation name="rUAngle$i" unit="deg" x="$xrotUAang" y="0" z="0"/>
1542  </physvol>
1543 EOF
1544 
1545 $topY = $ypos + ($CosUAngle*$CommonUWireLength/2);
1546 $bottomY = $ypos - ($CosUAngle*$CommonUWireLength/2);
1547 $edgeZ_p = + ($SinUAngle*$CommonUWireLength/2);
1548 $edgeZ_m = - ($SinUAngle*$CommonUWireLength/2);
1549 print $wout "U$i: ( $ypos , 0 ) (pitch = $pitch)\n";
1550 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1551 
1552 $lastYpos = $ypos;
1553 $lastZpos = 0;
1554 
1555 }
1556 
1557 
1558 
1559 my $FirstTopUWire_zspan = $FirstTopUWire_yspan*$TanUAngle;
1560 my $StartTopUWires_ypos = + $Uactive_y/2 - $FirstTopUWire_yspan/2;
1561 my $StartTopUWires_zpos = - $Uactive_z/2 + $FirstTopUWire_zspan/2;
1562 
1563 # Finally moving to the corner wires on the top right:
1564  # x=0 to center the wires in the plane
1565  # y positioning: plug wire number into same equation
1566  # z positioning: start at z=0 and go negatively at the same z increment
1567  # rotation: same as common wire in code above
1568 # note that the counter maintains wire number shown in the position name
1569 
1570 for ($j = $NumberSideUWires; $j < $NumberSideUWires+$NumberCornerUWires; ++$j)
1571 {
1572 
1573 $i = $j - $NumberSideUWires;
1574 
1575 my $ypos = $StartTopUWires_ypos + ($i)*0.5*$UWire_yint;
1576 my $zpos = $StartTopUWires_zpos - ($i)*0.5*$UWire_zint;
1577 
1578  $lastWnum = $j-1;
1579  if ( $ypos < $lastYpos ){ print "WARNING: y position dropped from $lastYpos (wire U$lastWnum) to $ypos (wire U$j)\n"; }
1580  if ( $ypos == $lastYpos ){ print "WARNING: y position between wire U$lastWnum and U$j did not move: $ypos\n"; }
1581 
1582 $pitch = ($ypos - $lastYpos) * $SinUAngle - ($zpos - $lastZpos) * $CosUAngle ;
1583 
1584 $xrotUAang = 90-$UAngle;
1585 print TPC <<EOF;
1586  <physvol>
1587  <volumeref ref="volTPCWireU$j${_[3]}"/>
1588  <position name="pos${_[3]}WireU$j" unit="cm" x="0" y="$ypos " z="$zpos"/>
1589  <rotation name="rUAngle$j" unit="deg" x="$xrotUAang" y="0" z="0"/>
1590  </physvol>
1591 EOF
1592 
1593 $topY = $ypos + ($CosUAngle*$TopCornerUWireLength[$i]/2);
1594 $bottomY = $ypos - ($CosUAngle*$TopCornerUWireLength[$i]/2);
1595 $edgeZ_p = $zpos + ($SinUAngle*$TopCornerUWireLength[$i]/2);
1596 $edgeZ_m = $zpos - ($SinUAngle*$TopCornerUWireLength[$i]/2);
1597 print $wout "U$j: ( $ypos , $zpos ) (pitch = $pitch)\n";
1598 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1599 
1600 $lastYpos = $ypos;
1601 $lastZpos = $zpos;
1602 
1603 }
1604 
1605 } #ends if wires on
1606 
1607 
1608 # ++++++++++++++++++++++ V Plane +++++++++++++++++++++++
1609 
1610 # End U plane and create V plane logical volume
1611 print TPC <<EOF;
1612  </volume>
1613 
1614  <volume name="volTPCPlaneV${_[3]}">
1615  <materialref ref="LAr"/>
1616  <solidref ref="${_[3]}VPlane"/>
1617 EOF
1618 
1619 print $wout "\n- Wires for V plane -\n\n";
1620 print $wout " Vplane_y: $Vactive_y\n";
1621 print $wout " Vplane_z: $Vactive_z\n";
1622 
1623 if ($wires_on==1)
1624 {
1625 
1626 
1627 # Starting with the bottom right corner wires:
1628  # x=0 to center the wires in the plane
1629  # y positioning: (-0.5*$TPCWirePlaneHeight) starts the incremental increase
1630  # from the bottom of the plane, and trigonometry gives the increment
1631  # z positioning: Looking at the plane from the positive x direction,
1632  # (-0.5*$TPCWirePlaneLength) starts the incremental increase from
1633  # the lower right corner.
1634  # rotation: same as common wire in code below
1635 
1636  $FirstV_ypos = - $Vactive_y/2 + $FirstVWireOffset/$TanVAngle/2;
1637  $FirstV_zpos = - $Vactive_z/2 + $FirstVWireOffset/2;
1638 
1639 for ($i = 0; $i < $NumberCornerVWires; ++$i)
1640 {
1641 
1642 my $ypos = $FirstV_ypos + ($i)*0.5*$VWire_yint;
1643 my $zpos = $FirstV_zpos + ($i)*0.5*$VWire_zint;
1644 
1645 $xrotVAang = 90+$VAngle;
1646 print TPC <<EOF;
1647  <physvol>
1648  <volumeref ref="volTPCWireV$i${_[3]}"/>
1649  <position name="pos${_[3]}WireV$i" unit="cm" x="0" y="$ypos " z="$zpos"/>
1650  <rotation name="rVAngle$i" unit="deg" x="$xrotVAang" y="0" z="0"/>
1651  </physvol>
1652 EOF
1653 
1654 $topY = $ypos + ($CosVAngle*$CornerVWireLength[$i]/2);
1655 $bottomY = $ypos - ($CosVAngle*$CornerVWireLength[$i]/2);
1656 $edgeZ_p = $zpos + ($SinVAngle*$CornerVWireLength[$i]/2);
1657 $edgeZ_m = $zpos - ($SinVAngle*$CornerVWireLength[$i]/2);
1658 print $wout "V$i: ( $ypos , $zpos ) \n";
1659 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1660 
1661 $lastYpos = $ypos;
1662 $lastZpos = $zpos;
1663 
1664 }
1665 
1666 
1667 # Moving upwards to the common wires:
1668  # x and z are zero to center the wires along a vertical axis
1669  # y positioning: Plug wire number into the same corner ypos equation
1670  # rotation: wires in //// direction, so +90deg to bring them to vertical and
1671  # --VAngle counterclockwise to arrive at proper orientation
1672 # Note that the counter maintains wire number in the position name
1673 
1674 my $StartCommonVWires_ypos = $lastYpos + $VWire_yint - abs( $lastZpos )/$TanVAngle;
1675 
1676 for ($i = $NumberCornerVWires; $i < $NumberSideVWires; ++$i)
1677 {
1678 
1679  $j = $i - $NumberCornerVWires;
1680  my $ypos = $StartCommonVWires_ypos + $VWire_yint*($j);
1681 
1682 $xrotVAang = 90+$VAngle;
1683 print TPC <<EOF;
1684  <physvol>
1685  <volumeref ref="volTPCWireVCommon${_[3]}"/>
1686  <position name="pos${_[3]}WireV$i" unit="cm" x="0" y="$ypos " z="0"/>
1687  <rotation name="rVAngle$i" unit="deg" x="$xrotVAang" y="0" z="0"/>
1688  </physvol>
1689 EOF
1690 
1691 $topY = $ypos + ($CosVAngle*$CommonVWireLength/2);
1692 $bottomY = $ypos - ($CosVAngle*$CommonVWireLength/2);
1693 $edgeZ_p = + ($SinVAngle*$CommonVWireLength/2);
1694 $edgeZ_m = - ($SinVAngle*$CommonVWireLength/2);
1695 print $wout "V$i: ( $ypos , 0 ) \n";
1696 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1697 
1698 $lastYpos = $ypos;
1699 #$lastZpos = $zpos; always 0
1700 
1701 }
1702 
1703 
1704 my $FirstTopVWire_zspan = $FirstTopVWire_yspan*$TanVAngle;
1705 my $StartTopVWires_ypos = + $Vactive_y/2 - $FirstTopVWire_yspan/2;
1706 my $StartTopVWires_zpos = + $Vactive_z/2 - $FirstTopVWire_zspan/2;
1707 
1708 # Finally moving to the corner wires on the top right:
1709  # x=0 to center the wires in the plane
1710  # y positioning: plug wire number into same equation
1711  # z positioning: start at z=0 and go positively at the same z increment
1712  # rotation: same as common wire in code above
1713 # note that the counter maintains wire number shown in the position name
1714 
1715 for ($j = $NumberSideVWires; $j < $NumberSideVWires+$NumberCornerVWires; ++$j)
1716 {
1717 
1718 $i = $j - $NumberSideVWires;
1719 
1720 my $ypos = $StartTopVWires_ypos + ($i)*0.5*$VWire_yint;
1721 my $zpos = $StartTopVWires_zpos + ($i)*0.5*$VWire_zint;
1722 
1723 $xrotVAang = 90+$VAngle;
1724 print TPC <<EOF;
1725  <physvol>
1726  <volumeref ref="volTPCWireV$j${_[3]}"/>
1727  <position name="pos${_[3]}WireV$j" unit="cm" x="0" y="$ypos " z="$zpos"/>
1728  <rotation name="rVAngle$j" unit="deg" x="$xrotVAang" y="0" z="0"/>
1729  </physvol>
1730 EOF
1731 
1732 $topY = $ypos + ($CosVAngle*$TopCornerVWireLength[$i]/2);
1733 $bottomY = $ypos - ($CosVAngle*$TopCornerVWireLength[$i]/2);
1734 $edgeZ_p = $zpos + ($SinVAngle*$TopCornerVWireLength[$i]/2);
1735 $edgeZ_m = $zpos - ($SinVAngle*$TopCornerVWireLength[$i]/2);
1736 print $wout "V$j: ( $ypos , $zpos ) \n";
1737 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1738 
1739 }
1740 
1741 
1742 
1743 
1744 
1745 
1746 } #ends if wires on
1747 
1748 
1749 
1750 # ++++++++++++++++++++++ Z Plane +++++++++++++++++++++++
1751 
1752 # End V plane and create Z plane logical volume
1753 print TPC <<EOF;
1754  </volume>
1755 
1756  <volume name="volTPCPlaneZ${_[3]}">
1757  <materialref ref="LAr"/>
1758  <solidref ref="${_[3]}ZPlane"/>
1759 EOF
1760 
1761 if ($wires_on==1)
1762 {
1763 
1764 # This is the simplest plane, one loop creates all of the wires
1765  # x and y position at zero to center the wires
1766  # z position: moving from front of detector to back, in the positive z direction,
1767  # starting at (-0.5*$TPCWirePlaneLength), the right side looking from
1768  # the +x direction
1769 
1770 for ($i=0; $i<$NumberVerticalWires; ++$i)
1771 {
1772 my $zpos = (-0.5*$Zactive_z) + $i*$XWirePitch + $TPCWireThickness/2;
1773 
1774 print TPC <<EOF;
1775  <physvol>/
1776  <volumeref ref="volTPCWireVert${_[3]}"/>
1777  <position name="pos${_[3]}WireZ$i" unit="cm" x="0" y="0 " z="$zpos"/>
1778  <rotationref ref="rPlus90AboutX"/>
1779  </physvol>
1780 EOF
1781 
1782 }
1783 
1784 } #ends if wires on
1785 
1786 print TPC <<EOF;
1787  </volume>
1788 EOF
1789 
1790 #+++++++++++++++++++++ ^^ Position physical wires Above ^^ +++++++++++++++++++++
1791 
1792 ## make the TPC active volume extend down to the G10 for the grid
1793 
1794  my $BottomOfAPA = - $TPC_y/2 + $APAGap_y/2;
1795 
1796 
1797  $posZplane[0] = -$_[0]/2 + $APAWirePlaneSpacing + $TPCWirePlaneThickness/2;
1798  $posZplane[1] = $BottomOfAPA + $WrapCover + 4*$G10thickness + $Zactive_y/2;
1799  $posZplane[2] = 0;
1800 
1801  $posVplane[0] = $posZplane[0] + $APAWirePlaneSpacing + $TPCWirePlaneThickness;
1802  $posVplane[1] = $BottomOfAPA + $WrapCover + 3*$G10thickness + $Vactive_y/2;
1803  $posVplane[2] = $posZplane[2];
1804 
1805  $posUplane[0] = $posVplane[0] + $APAWirePlaneSpacing + $TPCWirePlaneThickness;
1806  $posUplane[1] = $BottomOfAPA + $WrapCover + 2*$G10thickness + $Uactive_y/2;
1807  $posUplane[2] = $posZplane[2];
1808 
1809  $posTPCActive[0] = $posUplane[0] + $TPCWirePlaneThickness/2 + $TPCActive_x/2;
1810  $posTPCActive[1] = -$_[1]/2 + $TPCActive_y/2;
1811  $posTPCActive[2] = 0;
1812 
1813 #wrap up the TPC file
1814 print TPC <<EOF;
1815  <volume name="volTPC${_[3]}">
1816  <materialref ref="LAr"/>
1817  <solidref ref="${_[3]}"/>
1818  <physvol>
1819  <volumeref ref="volTPCPlaneZ${_[3]}"/>
1820  <position name="pos${_[3]}PlaneZ" unit="cm"
1821  x="$posZplane[0]" y="$posZplane[1]" z="$posZplane[2]"/>
1822  <rotationref ref="rIdentity"/>
1823  </physvol>
1824  <physvol>
1825  <volumeref ref="volTPCPlaneV${_[3]}"/>
1826  <position name="pos${_[3]}PlaneV" unit="cm"
1827  x="$posVplane[0]" y="$posVplane[1]" z="$posVplane[2]"/>
1828  <rotationref ref="rIdentity"/>
1829  </physvol>
1830  <physvol>
1831  <volumeref ref="volTPCPlaneU${_[3]}"/>
1832  <position name="pos${_[3]}PlaneU" unit="cm"
1833  x="$posUplane[0]" y="$posUplane[1]" z="$posUplane[2]"/>
1834  <rotationref ref="rIdentity"/>
1835  </physvol>
1836 EOF
1837 
1838 # Option to omit the active volume on the outside for the prototype.
1839 if( !($killOuterActive==1 && $_[3] eq 'Outer') ){
1840 print TPC <<EOF;
1841  <physvol>
1842  <volumeref ref="volTPCActive${subname}"/>
1843  <position name="pos${_[3]}Active" unit="cm"
1844  x="$posTPCActive[0]" y="$posTPCActive[1]" z="$posTPCActive[2]"/>
1845  <rotationref ref="rIdentity"/>
1846  </physvol>
1847 EOF
1848 }
1849 
1850 print TPC <<EOF;
1851  </volume>
1852 </structure>
1853 </gdml>
1854 EOF
1855 
1856  close(TPC);
1857 
1858 } #end of sub gen_TPC
1859 
1860 
1861 
1862 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1863 #++++++++++++++++++++++++++++++++++++++ gen_Cryostat +++++++++++++++++++++++++++++++++++++
1864 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1865 
1866 sub gen_Cryostat()
1867 {
1868 
1869 # Create the cryostat fragment file name,
1870 # add file to list of output GDML fragments,
1871 # and open it
1872  $CRYO = "subfile_protodune_v7_Cryostat" . $suffix . ".gdml";
1873  push (@gdmlFiles, $CRYO);
1874  $CRYO = ">" . $CRYO;
1875  open(CRYO) or die("Could not open file $CRYO for writing");
1876 
1877 
1878 # The standard XML prefix and starting the gdml
1879  print CRYO <<EOF;
1880 <?xml version='1.0'?>
1881 <gdml>
1882 EOF
1883 
1884 $APAFrameZSide_x = $APAFrame_x;
1885 $APAFrameZSide_y = 4*$inch;
1886 $APAFrameZSide_z = $APAFrame_z;
1887 
1888 $APAFrameYSide_x = $APAFrame_x;
1889 $APAFrameYSide_y = $APAFrame_y-2*$APAFrameZSide_y;
1890 $APAFrameYSide_z = 4*$inch;
1891 
1892 # Two outer Y supports will sandwich the light paddles
1893 $APAFrameYOuterSupport_x = ($APAFrame_x-$LightPaddle_x)/2;
1894 $APAFrameYOuterSupport_y = $APAFrame_y-2*$APAFrameZSide_y;
1895 $APAFrameYOuterSupport_z = 4*$inch;
1896 
1897 $EdgeFrameSteelThickness = 0.12*$inch;
1898 $InnerFrameSteelThickness = 0.062*$inch;
1899 
1900 
1901 $G10BoardYSide_x = $APAFrame_x;
1902 $G10BoardYSide_y = $APAFrame_y;
1903 $G10BoardYSide_z = $G10thickness;
1904 
1905 $G10BoardZSide_x = $APAFrame_x;
1906 $G10BoardZSide_y = $G10thickness;
1907 $G10BoardZSide_z = $APAFrame_z;
1908 
1909 #Cathode dimensions
1910 $CathFrame_x = 2.5*$inch;
1911 $CathFrame_y = 237.51*$inch;
1912 $CathFrame_z = 91.14*$inch;
1913 
1914 $CathTop_x = 1.185*$inch;
1915 $CathTop_y = 76.42*$inch;
1916 $CathTop_z = 43.47*$inch;
1917 
1918 $CathMid_x = 1.185*$inch;
1919 $CathMid_y = 76.67*$inch;
1920 $CathMid_z = 43.47*$inch;
1921 
1922 $CathPos_z = $CathFrame_z/2 - $CathTop_z/2 - 1*$inch;
1923 $CathPos_x = $CathFrame_x/2 - $CathTop_x/2 + 0.001; # 0.001 is for clean cut
1924 $CathTopPos_y= $CathFrame_y/2 - $CathTop_y/2 - 3*$inch;
1925 $CathBotPos_y= -$CathFrame_y/2 + $CathTop_y/2 + 3*$inch;
1926 $CathMidPos_y= 0.;
1927 print "CathMidPos_y = $CathMidPos_y"."\n";
1928 
1929 # All the cryostat solids.
1930 print CRYO <<EOF;
1931 <solids>
1932  <box name="Cryostat" lunit="cm"
1933  x="$Cryostat_x"
1934  y="$Cryostat_y"
1935  z="$Cryostat_z"/>
1936 
1937  <cutTube name="BeamPlugMod" rmin="0" rmax="12.0" z="$BeamPlugLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="0" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
1938 
1939  <cutTube name="BeamPlug_0" rmin="0" rmax="$BeamPlugRad" z="$BeamPlugLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="0" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
1940 
1941  <cutTube name="BeamPlugNi_0" rmin="0" rmax="$BeamPlugNiRad" z="$BeamPlugNiLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="0" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
1942 
1943  <torus name="TorRing" rmin="0" rmax="1.7" rtor="10.1" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1944  <tube name="TubeRing1" rmin="$BeamPlugNiRad" rmax="$BeamPlugRad" z="0.5" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1945  <tube name="TubeRing2" rmin="$BeamPlugNiRad" rmax="$BeamPlugRad" z="3.4" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1946 
1947  <tube name="TubeBePlFlangeOut" rmin="0" rmax="15" z="3.6" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1948  <tube name="TubeBePlFlangeIn" rmin="0" rmax="8.25" z="3.2" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1949  <tube name="TubeBePlFlangeCut" rmin="12.5" rmax="15.01" z="2.302" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1950  <tube name="TubeBePlFlangeTPCRem" rmin="0." rmax="12.5" z="0.91" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1951 
1952  <subtraction name="BPRing">
1953  <first ref="TorRing"/>
1954  <second ref="TubeRing2"/>
1955  </subtraction>
1956  <union name="BeamPlugERing">
1957  <first ref="BPRing"/>
1958  <second ref="TubeRing1"/>
1959  </union>
1960 
1961  <subtraction name="BePlFlangeSolid">
1962  <first ref="TubeBePlFlangeOut"/>
1963  <second ref="TubeBePlFlangeCut"/>
1964  <position name="posSubBePlFlangeSolid" x="0" y="0" z="0.651" unit="cm"/>
1965  </subtraction>
1966  <subtraction name="BePlFlange">
1967  <first ref="BePlFlangeSolid"/>
1968  <second ref="TubeBePlFlangeIn"/>
1969  <position name="posSubBePlFlange" x="0" y="0" z="-0.20" unit="cm"/>
1970  </subtraction>
1971 
1972 EOF
1973 
1974 for($i=0 ; $i<7 ; $i++){
1975 
1976 $old_i = $i;
1977 $new_i = $i+1;
1978 $BeamPlugERing_z = $BeamPlugERingPosZ + $i*5.7;
1979 $BeamPlugNiERing_z = $BeamPlugERingPosZ + $i*5.7 - $BeamPlugNiPos_z;
1980 
1981 print CRYO <<EOF;
1982  <subtraction name="BeamPlug_$new_i">
1983  <first ref="BeamPlug_$old_i"/>
1984  <second ref="BeamPlugERing"/>
1985  <position name="posBeamPlugSubtr_$new_i" x="0" y="0" z="$BeamPlugERing_z" unit="cm"/>
1986  </subtraction>
1987  <subtraction name="BeamPlugNi_$new_i">
1988  <first ref="BeamPlugNi_$old_i"/>
1989  <second ref="BeamPlugERing"/>
1990  <position name="posBeamPlugNiSubtr_$new_i" x="0" y="0" z="$BeamPlugNiERing_z" unit="cm"/>
1991  </subtraction>
1992 EOF
1993 }
1994 
1995 print CRYO <<EOF;
1996  <box name="ArgonInterior" lunit="cm"
1997  x="$Argon_x"
1998  y="$Argon_y"
1999  z="$Argon_z"/>
2000 
2001  <box name="GaseousArgon" lunit="cm"
2002  x="$Argon_x"
2003  y="$HeightGaseousAr"
2004  z="$Argon_z"/>
2005 
2006  <subtraction name="SteelShell">
2007  <first ref="Cryostat"/>
2008  <second ref="ArgonInterior"/>
2009  </subtraction>
2010 
2011  <box name="Cathode" lunit="cm"
2012  x="$Cathode_x"
2013  y="$CathFrame_y"
2014  z="$CathFrame_z"/>
2015 
2016 
2017 EOF
2018 # <box name="CathFrame" lunit="cm"
2019 # x="$CathFrame_x"
2020 # y="$CathFrame_y"
2021 # z="$CathFrame_z"/>
2022 
2023 # <box name="CathTop" lunit="cm"
2024 # x="$CathTop_x"
2025 # y="$CathTop_y"
2026 # z="$CathTop_z"/>
2027 
2028 # <box name="CathMid" lunit="cm"
2029 # x="$CathMid_x"
2030 # y="$CathMid_y"
2031 # z="$CathMid_z"/>
2032 
2033 # <subtraction name="Cath-1">
2034 # <first ref="CathFrame"/>
2035 # <second ref="CathTop"/>
2036 # <position name="posCath-1" x="$CathPos_x" y="$CathTopPos_y" z="$CathPos_z" unit="cm"/>
2037 # </subtraction>
2038 # <subtraction name="Cath-2">
2039 # <first ref="Cath-1"/>
2040 # <second ref="CathTop"/>
2041 # <position name="posCath-2" x="-$CathPos_x" y="$CathTopPos_y" z="$CathPos_z" unit="cm"/>
2042 # </subtraction>
2043 # <subtraction name="Cath-3">
2044 # <first ref="Cath-2"/>
2045 # <second ref="CathTop"/>
2046 # <position name="posCath-3" x="$CathPos_x" y="$CathTopPos_y" z="-$CathPos_z" unit="cm"/>
2047 # </subtraction>
2048 # <subtraction name="Cath-4">
2049 # <first ref="Cath-3"/>
2050 # <second ref="CathTop"/>
2051 # <position name="posCath-4" x="-$CathPos_x" y="$CathTopPos_y" z="-$CathPos_z" unit="cm"/>
2052 # </subtraction>
2053 
2054 # <subtraction name="Cath-5">
2055 # <first ref="Cath-4"/>
2056 # <second ref="CathMid"/>
2057 # <position name="posCath-5" x="$CathPos_x" y="$CathMidPos_y" z="$CathPos_z" unit="cm"/>
2058 # </subtraction>
2059 # <subtraction name="Cath-6">
2060 # <first ref="Cath-5"/>
2061 # <second ref="CathMid"/>
2062 # <position name="posCath-6" x="-$CathPos_x" y="$CathMidPos_y" z="$CathPos_z" unit="cm"/>
2063 # </subtraction>
2064 # <subtraction name="Cath-7">
2065 # <first ref="Cath-6"/>
2066 # <second ref="CathMid"/>
2067 # <position name="posCath-7" x="$CathPos_x" y="$CathMidPos_y" z="-$CathPos_z" unit="cm"/>
2068 # </subtraction>
2069 # <subtraction name="Cath-8">
2070 # <first ref="Cath-7"/>
2071 # <second ref="CathMid"/>
2072 # <position name="posCath-8" x="-$CathPos_x" y="$CathMidPos_y" z="-$CathPos_z" unit="cm"/>
2073 # </subtraction>
2074 
2075 
2076 # <subtraction name="Cath-9">
2077 # <first ref="Cath-8"/>
2078 # <second ref="CathTop"/>
2079 # <position name="posCath-9" x="$CathPos_x" y="$CathBotPos_y" z="$CathPos_z" unit="cm"/>
2080 # </subtraction>
2081 # <subtraction name="Cath-10">
2082 # <first ref="Cath-9"/>
2083 # <second ref="CathTop"/>
2084 # <position name="posCath-10" x="-$CathPos_x" y="$CathBotPos_y" z="$CathPos_z" unit="cm"/>
2085 # </subtraction>
2086 # <subtraction name="Cath-11">
2087 # <first ref="Cath-10"/>
2088 # <second ref="CathTop"/>
2089 # <position name="posCath-11" x="$CathPos_x" y="$CathBotPos_y" z="-$CathPos_z" unit="cm"/>
2090 # </subtraction>
2091 # <subtraction name="Cath-12">
2092 # <first ref="Cath-11"/>
2093 # <second ref="CathTop"/>
2094 # <position name="posCath-12" x="-$CathPos_x" y="$CathBotPos_y" z="-$CathPos_z" unit="cm"/>
2095 # </subtraction>
2096 #EOF
2097 
2098 # <subtraction name="InnerActive">
2099 # <first ref="InnerActive_NoCPA"/>
2100 # <second ref="Cath-12"/>
2101 # <position name="posCPAInnerRem" x="179.23175" y="-3.805" z="0." unit="cm"/>
2102 # </subtraction>
2103 #
2104 #################################
2105 print CRYO <<EOF;
2106  <box name="boxFCEWmod" x="354.3" y="151.2" z="12.8" lunit="cm"/>
2107  <box name="boxFCEWHorSuppOut" x="354.3" y="15.2" z="10.2" lunit="cm"/>
2108  <box name="boxFCEWHorSuppInn" x="354.301" y="14.0" z="9.0" lunit="cm"/>
2109  <box name="boxFCEWRem" x="354.301" y="15.201" z="1.3" lunit="cm"/>
2110  <box name="boxFCEWFieldShaping" x="354.3" y="151.2" z="1.3" lunit="cm"/>
2111  <box name="boxFCEWVerSupp" x="15.2" y="151.2" z="1.3" lunit="cm"/>
2112 
2113  <subtraction name="FCEWHorSupp">
2114  <first ref="boxFCEWHorSuppOut"/>
2115  <second ref="boxFCEWHorSuppInn"/>
2116  </subtraction>
2117  <subtraction name="FCEWHorSuppBar">
2118  <first ref="FCEWHorSupp"/>
2119  <second ref="boxFCEWRem"/>
2120  <position name="posFCEWHorSuppBar" x="0" y="0" z="2." unit="cm"/>
2121  </subtraction>
2122 
2123  <box name="boxFCEW-BP-Subtract" x="50.8" y="151.2" z="1.301" lunit="cm"/>
2124  <tube name="tubBePlHolemod" rmin="0" rmax="15.25" z="12.801" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
2125  <tube name="tubBePlHoleFiSh" rmin="0" rmax="15.25" z="1.301" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
2126  <box name="boxFCEW-BPFla-VerSupp" x="50.8" y="151.2" z="1.3" lunit="cm"/>
2127  <box name="boxFCEW-BPFla-Subtr" x="25.4" y="64" z="1.301" lunit="cm"/>
2128  <tube name="tubFCEW-BPFla-Subtr" rmin="0" rmax="14.0" z="1.301" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
2129  <tube name="tubFCEW-BPVer-Subtr" rmin="0" rmax="12.5" z="1.301" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
2130 
2131  <subtraction name="boxFCEW-BP-NoHole">
2132  <first ref="boxFCEWmod"/>
2133  <second ref="boxFCEW-BP-Subtract"/>
2134  <position name="posFCEW-BP-NoHole" x="147.8" y="0" z="5.7505" unit="cm"/>
2135  </subtraction>
2136  <subtraction name="boxFCEW-BP-mod">
2137  <first ref="boxFCEW-BP-NoHole"/>
2138  <second ref="tubBePlHolemod"/>
2139  <position name="posboxFCEW-BP-mod" x="146" y="41.6" z="0" unit="cm"/>
2140  </subtraction>
2141  <subtraction name="FCEW-BP-FieldShaping">
2142  <first ref="boxFCEWFieldShaping"/>
2143  <second ref="tubBePlHoleFiSh"/>
2144  <position name="posFCEW-BP-FieldShapingSol" x="146" y="41.6" z="0" unit="cm"/>
2145  </subtraction>
2146 
2147  <subtraction name="FCEW-BPFla-Ver">
2148  <first ref="boxFCEW-BPFla-VerSupp"/>
2149  <second ref="boxFCEW-BPFla-Subtr"/>
2150  <position name="posFCEW-BPFla-Ver" x="0." y="-11.6" z="0." unit="cm"/>
2151  </subtraction>
2152  <subtraction name="FCEW-BPFla">
2153  <first ref="FCEW-BPFla-Ver"/>
2154  <second ref="tubFCEW-BPFla-Subtr"/>
2155  <position name="posFCEW-BPFlaSolid" x="-1.35" y="41.4" z="0." unit="cm"/>
2156  </subtraction>
2157 
2158  <subtraction name="FCEW-BPVer">
2159  <first ref="boxFCEWVerSupp"/>
2160  <second ref="tubFCEW-BPVer-Subtr"/>
2161  <position name="posFCEW-BP-Ver" x="-14.9" y="43.3" z="0." unit="cm"/>
2162  </subtraction>
2163 
2164  <box name="boxFCMod" x="352" y="27.4" z="230" lunit="cm"/>
2165  <box name="boxShieldPlate" x="264" y="2" z="230" lunit="cm"/>
2166  <box name="boxFCXBarOut" x="352" y="15.2" z="7.6" lunit="cm"/>
2167  <box name="boxFCXBarRem" x="352.001" y="13.9" z="3.501" lunit="cm"/>
2168  <box name="boxFCXFieldBarRem" x="352.001" y="1.3" z="0.61" lunit="cm"/>
2169  <box name="boxFCZBarOut" x="3.8" y="7.6" z="115.4" lunit="cm"/>
2170  <box name="boxFCZBarRem" x="1.58" y="6.3" z="115.401" lunit="cm"/>
2171  <box name="boxFCFieldBarPlane" x="352" y="1.3" z="230" lunit="cm"/>
2172 
2173  <subtraction name="FCXBarOut-1">
2174  <first ref="boxFCXBarOut"/>
2175  <second ref="boxFCXBarRem"/>
2176  <position name="posFCXBarOutSol-1" x="0" y="0" z="2.05" unit="cm"/>
2177  </subtraction>
2178  <subtraction name="FCXBarOut-2">
2179  <first ref="FCXBarOut-1"/>
2180  <second ref="boxFCXBarRem"/>
2181  <position name="posFCXBarOutSol-2" x="0" y="0" z="-2.05" unit="cm"/>
2182  </subtraction>
2183  <subtraction name="FCXBarOut">
2184  <first ref="FCXBarOut-2"/>
2185  <second ref="boxFCXFieldBarRem"/>
2186  <position name="posFCXBarOut" x="0" y="-3.3" z="0" unit="cm"/>
2187  </subtraction>
2188  <subtraction name="FCZBarOut-1">
2189  <first ref="boxFCZBarOut"/>
2190  <second ref="boxFCZBarRem"/>
2191  <position name="posFCZBarOut-1" x="1.111" y="0" z="0" unit="cm"/>
2192  </subtraction>
2193  <subtraction name="FCZBar">
2194  <first ref="FCZBarOut-1"/>
2195  <second ref="boxFCZBarRem"/>
2196  <position name="posFCZBar" x="-1.111" y="0" z="0" unit="cm"/>
2197  </subtraction>
2198 
2199 
2200 EOF
2201 
2202 $LigthPaddleSiPM_z = $LightPaddle_z + $SiPM_z;
2203 $APAFrameYSideHollow_x = $APAFrameYSide_x-2*$EdgeFrameSteelThickness;
2204 $APAFrameYSideHollow_y = $APAFrameYSide_y-2*$EdgeFrameSteelThickness;
2205 $APAFrameZSideHollow_x = $APAFrameZSide_x-2*$EdgeFrameSteelThickness;
2206 $APAFrameZSideHollow_y = $APAFrameZSide_y-2*$EdgeFrameSteelThickness;
2207 print CRYO <<EOF;
2208  <box name="LightPaddle" lunit="cm"
2209  x="$LightPaddle_x"
2210  y="$LightPaddle_y"
2211  z="$LigthPaddleSiPM_z"/>
2212 
2213  <box name="ArapucaOut" lunit="mm"
2214  x="@{[$ArapucaOut_x]}"
2215  y="@{[$ArapucaOut_y]}"
2216  z="@{[$ArapucaOut_z]}"/>
2217 
2218  <box name="ArapucaIn" lunit="mm"
2219  x="@{[$ArapucaIn_x]}"
2220  y="@{[$ArapucaIn_y]}"
2221  z="@{[$ArapucaIn_z]}"/>
2222 
2223  <subtraction name="ArapucaWalls0">
2224  <first ref="ArapucaOut"/>
2225  <second ref="ArapucaIn"/>
2226  <positionref ref="posArapucaSub0"/>
2227  </subtraction>
2228  <subtraction name="ArapucaWalls1">
2229  <first ref="ArapucaWalls0"/>
2230  <second ref="ArapucaIn"/>
2231  <positionref ref="posArapucaSub1"/>
2232  </subtraction>
2233  <subtraction name="ArapucaWalls2">
2234  <first ref="ArapucaWalls1"/>
2235  <second ref="ArapucaIn"/>
2236  <positionref ref="posArapucaSub2"/>
2237  </subtraction>
2238  <subtraction name="ArapucaWalls3">
2239  <first ref="ArapucaWalls2"/>
2240  <second ref="ArapucaIn"/>
2241  <positionref ref="posArapucaSub3"/>
2242  </subtraction>
2243  <subtraction name="ArapucaWalls4">
2244  <first ref="ArapucaWalls3"/>
2245  <second ref="ArapucaIn"/>
2246  <positionref ref="posArapucaSub4"/>
2247  </subtraction>
2248  <subtraction name="ArapucaWalls5">
2249  <first ref="ArapucaWalls4"/>
2250  <second ref="ArapucaIn"/>
2251  <positionref ref="posArapucaSub5"/>
2252  </subtraction>
2253  <subtraction name="ArapucaWalls6">
2254  <first ref="ArapucaWalls5"/>
2255  <second ref="ArapucaIn"/>
2256  <positionref ref="posArapucaSub6"/>
2257  </subtraction>
2258  <subtraction name="ArapucaWalls7">
2259  <first ref="ArapucaWalls6"/>
2260  <second ref="ArapucaIn"/>
2261  <positionref ref="posArapucaSub7"/>
2262  </subtraction>
2263  <subtraction name="ArapucaWalls8">
2264  <first ref="ArapucaWalls7"/>
2265  <second ref="ArapucaIn"/>
2266  <positionref ref="posArapucaSub8"/>
2267  </subtraction>
2268  <subtraction name="ArapucaWalls9">
2269  <first ref="ArapucaWalls8"/>
2270  <second ref="ArapucaIn"/>
2271  <positionref ref="posArapucaSub9"/>
2272  </subtraction>
2273  <subtraction name="ArapucaWalls10">
2274  <first ref="ArapucaWalls9"/>
2275  <second ref="ArapucaIn"/>
2276  <positionref ref="posArapucaSub10"/>
2277  </subtraction>
2278  <subtraction name="ArapucaWalls11">
2279  <first ref="ArapucaWalls10"/>
2280  <second ref="ArapucaIn"/>
2281  <positionref ref="posArapucaSub11"/>
2282  </subtraction>
2283  <subtraction name="ArapucaWalls12">
2284  <first ref="ArapucaWalls11"/>
2285  <second ref="ArapucaIn"/>
2286  <positionref ref="posArapucaSub12"/>
2287  </subtraction>
2288  <subtraction name="ArapucaWalls13">
2289  <first ref="ArapucaWalls12"/>
2290  <second ref="ArapucaIn"/>
2291  <positionref ref="posArapucaSub13"/>
2292  </subtraction>
2293  <subtraction name="ArapucaWalls14">
2294  <first ref="ArapucaWalls13"/>
2295  <second ref="ArapucaIn"/>
2296  <positionref ref="posArapucaSub14"/>
2297  </subtraction>
2298  <subtraction name="ArapucaWalls">
2299  <first ref="ArapucaWalls14"/>
2300  <second ref="ArapucaIn"/>
2301  <positionref ref="posArapucaSub15"/>
2302  </subtraction>
2303 
2304 
2305  <box name="ArapucaAcceptanceWindow" lunit="mm"
2306  x="@{[$ArapucaAcceptanceWindow_x]}"
2307  y="@{[$ArapucaAcceptanceWindow_y]}"
2308  z="@{[$ArapucaAcceptanceWindow_z]}"/>
2309 
2310  <box name="APAFrameYSideHollow" lunit="cm"
2311  x="$APAFrameYSideHollow_x"
2312  y="$APAFrameYSideHollow_y"
2313  z="$APAFrameYSide_z"/>
2314  <box name="APAFrameYSideShell" lunit="cm"
2315  x="$APAFrameYSide_x"
2316  y="$APAFrameYSide_y"
2317  z="$APAFrameYSide_z"/>
2318 
2319  <subtraction name="APAFrameYSide">
2320  <first ref="APAFrameYSideShell"/>
2321  <second ref="APAFrameYSideHollow"/>
2322  <positionref ref="posCenter"/>
2323  <rotationref ref="rIdentity"/>
2324  </subtraction>
2325 
2326  <box name="APAFrameZSideHollow" lunit="cm"
2327  x="$APAFrameZSideHollow_x"
2328  y="$APAFrameZSideHollow_y"
2329  z="$APAFrameZSide_z"/>
2330  <box name="APAFrameZSideShell" lunit="cm"
2331  x="$APAFrameZSide_x"
2332  y="$APAFrameZSide_y"
2333  z="$APAFrameZSide_z"/>
2334  <subtraction name="APAFrameZSide">
2335  <first ref="APAFrameZSideShell"/>
2336  <second ref="APAFrameZSideHollow"/>
2337  <positionref ref="posCenter"/>
2338  <rotationref ref="rIdentity"/>
2339  </subtraction>
2340 
2341  <box name="APAFrameYOuterSupport" lunit="cm"
2342  x="$EdgeFrameSteelThickness"
2343  y="$APAFrameYOuterSupport_y"
2344  z="$APAFrameYOuterSupport_z"/>
2345 
2346 
2347  <box name="G10BoardYSideCenterSeg" lunit="cm"
2348  x="$G10BoardYSide_x"
2349  y="$G10BoardYSide_y"
2350  z="$G10BoardYSide_z"/>
2351 
2352  <box name="G10BoardZSideCenterSeg" lunit="cm"
2353  x="$G10BoardZSide_x"
2354  y="$G10BoardZSide_y"
2355  z="$G10BoardZSide_z"/>
2356 
2357 </solids>
2358 EOF
2359 
2360 # Cryostat structure
2361 print CRYO <<EOF;
2362 <structure>
2363  <volume name="volSteelShell">
2364  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni" />
2365  <solidref ref="SteelShell" />
2366  </volume>
2367  <volume name="volGaseousArgon">
2368  <materialref ref="ArGas"/>
2369  <solidref ref="GaseousArgon"/>
2370  </volume>
2371 
2372  <volume name="volBeamPlugNi">
2373  <materialref ref="NiGas1atm80K"/>
2374  <solidref ref="BeamPlugNi_7"/>
2375  </volume>
2376  <volume name="volBeamPlugG10">
2377  <materialref ref="G10"/>
2378  <solidref ref="BeamPlug_7"/>
2379  <physvol>
2380  <volumeref ref="volBeamPlugNi"/>
2381  <position name="posBeamPlugNi" x="0" y="0" z="$BeamPlugNiPos_z" unit="cm"/>
2382  </physvol>
2383  </volume>
2384 
2385  <volume name="volBeamPlugERing">
2386  <materialref ref="ALUMINUM_Al"/>
2387  <solidref ref="BeamPlugERing"/>
2388  </volume>
2389 
2390  <volume name="volBeamPlugMod">
2391  <materialref ref="LAr"/>
2392  <solidref ref="BeamPlugMod"/>
2393  <physvol>
2394  <volumeref ref="volBeamPlugG10"/>
2395  <positionref ref="posCenter"/>
2396  </physvol>
2397 EOF
2398 
2399 for($i=0 ; $i<7 ; $i++){
2400 $BeamPlugERing_z = $BeamPlugERingPosZ + $i*5.7;
2401 print CRYO <<EOF;
2402  <physvol name="volBeamPlugERing_$i">
2403  <volumeref ref="volBeamPlugERing"/>
2404  <position name="posBeamPlugERing_$i" x="0" y="0" z="$BeamPlugERing_z" unit="cm"/>
2405  </physvol>
2406 EOF
2407 }
2408 print CRYO <<EOF;
2409  </volume>
2410 
2411  <volume name="volBePlFlangeNi">
2412  <materialref ref="NiGas1atm80K"/>
2413  <solidref ref="TubeBePlFlangeIn"/>
2414  </volume>
2415  <volume name="volBePlFlange">
2416  <materialref ref="G10"/>
2417  <solidref ref="BePlFlange"/>
2418  </volume>
2419  <volume name="volCathode">
2420  <materialref ref="G10" />
2421  <solidref ref="Cathode" />
2422  </volume>
2423 EOF
2424 
2425 for($i=0 ; $i<$nAPAs ; $i++){
2426 for($p=0 ; $p<10 ; $p++){
2427 print CRYO <<EOF;
2428  <volume name="volOpDetSensitive_$i\-$p">
2429  <materialref ref="LAr"/>
2430  <solidref ref="LightPaddle"/>
2431  </volume>
2432 EOF
2433 }
2434 }
2435 
2436 for($i=0 ; $i<$nAPAs ; $i++){
2437 if($i==$nAraAPA1 || $i==$nAraAPA2){
2438 print CRYO <<EOF;
2439  <volume name="volArapuca_$i">
2440  <materialref ref="G10" />
2441  <solidref ref="ArapucaWalls" />
2442  </volume>
2443 EOF
2444 for($p=0 ; $p<16 ; $p++){
2445 print CRYO <<EOF;
2446  <volume name="volOpDetSensitive_Arapuca_$i\-$p">
2447  <materialref ref="LAr"/>
2448  <solidref ref="ArapucaAcceptanceWindow"/>
2449  </volume>
2450 EOF
2451 }
2452 }
2453 }
2454 
2455 #### End wall field cage module
2456 print CRYO <<EOF;
2457  <volume name="volFCEWHorSuppBar">
2458  <materialref ref="FR4"/>
2459  <solidref ref="FCEWHorSuppBar"/>
2460  </volume>
2461  <volume name="volFCEWFieldBarPlane">
2462  <materialref ref="ALUMINUM_Al"/>
2463  <solidref ref="boxFCEWFieldShaping"/>
2464  </volume>
2465  <volume name="volFCEWVerSuppBar">
2466  <materialref ref="FR4"/>
2467  <solidref ref="boxFCEWVerSupp"/>
2468  </volume>
2469  <volume name="volFCEWmod">
2470  <materialref ref="LAr"/>
2471  <solidref ref="boxFCEWmod"/>
2472  <physvol name="volFCEWHorSuppBar-1">
2473  <volumeref ref="volFCEWHorSuppBar"/>
2474  <position name="posFCEWHorSuppBar-1" x="0" y="54.5" z="0" unit="cm"/>
2475  </physvol>
2476  <physvol name="volFCEWHorSuppBar-2">
2477  <volumeref ref="volFCEWHorSuppBar"/>
2478  <position name="posFCEWHorSuppBar-2" x="0" y="-54.5" z="0" unit="cm"/>
2479  </physvol>
2480  <physvol>
2481  <volumeref ref="volFCEWFieldBarPlane"/>
2482  <position name="posFCEWFieldBarPlane" x="0" y="0" z="2" unit="cm"/>
2483  </physvol>
2484  <physvol name="volFCEWVerSuppBar-1">
2485  <volumeref ref="volFCEWVerSuppBar"/>
2486  <position name="posFCEWVerSuppBar-1" x="-165.75" y="0" z="5.75" unit="cm"/>
2487  </physvol>
2488  <physvol name="volFCEWVerSuppBar-2">
2489  <volumeref ref="volFCEWVerSuppBar"/>
2490  <position name="posFCEWVerSuppBar-2" x="74.2" y="0" z="5.75" unit="cm"/>
2491  </physvol>
2492  <physvol name="volFCEWVerSuppBar-3">
2493  <volumeref ref="volFCEWVerSuppBar"/>
2494  <position name="posFCEWVerSuppBar-3" x="164.2" y="0" z="5.75" unit="cm"/>
2495  </physvol>
2496  <physvol name="volFCEWVerSuppBar-4">
2497  <volumeref ref="volFCEWVerSuppBar"/>
2498  <position name="posFCEWVerSuppBar-4" x="-165.75" y="0" z="-5.75" unit="cm"/>
2499  </physvol>
2500  <physvol name="volFCEWVerSuppBar-5">
2501  <volumeref ref="volFCEWVerSuppBar"/>
2502  <position name="posFCEWVerSuppBar-5" x="74.2" y="0" z="-5.75" unit="cm"/>
2503  </physvol>
2504  <physvol name="volFCEWVerSuppBar-6">
2505  <volumeref ref="volFCEWVerSuppBar"/>
2506  <position name="posFCEWVerSuppBar-6" x="164.2" y="0" z="-5.75" unit="cm"/>
2507  </physvol>
2508  </volume>
2509 
2510 
2511 EOF
2512 ##### Beam plug end wall module
2513 
2514 print CRYO <<EOF;
2515 
2516  <volume name="volFCEW-BP-FieldShaping">
2517  <materialref ref="ALUMINUM_Al"/>
2518  <solidref ref="FCEW-BP-FieldShaping"/>
2519  </volume>
2520  <volume name="volFCEW-BPFla">
2521  <materialref ref="FR4"/>
2522  <solidref ref="FCEW-BPFla"/>
2523  </volume>
2524  <volume name="volFCEW-BPVer">
2525  <materialref ref="FR4"/>
2526  <solidref ref="FCEW-BPVer"/>
2527  </volume>
2528 
2529  <volume name="volFCEW-BP-mod">
2530  <materialref ref="LAr"/>
2531  <solidref ref="boxFCEW-BP-mod"/>
2532  <physvol name="volFCEW-BP-HorSuppBar-1">
2533  <volumeref ref="volFCEWHorSuppBar"/>
2534  <position name="posFCEW-BP-HorSuppBar-1" x="0" y="64.5" z="0" unit="cm"/>
2535  </physvol>
2536  <physvol name="volFCEW-BP-HorSuppBar-2">
2537  <volumeref ref="volFCEWHorSuppBar"/>
2538  <position name="posFCEW-BP-HorSuppBar-2" x="0" y="-54.5" z="0" unit="cm"/>
2539  </physvol>
2540  <physvol>
2541  <volumeref ref="volFCEW-BP-FieldShaping"/>
2542  <position name="posFCEW-BP-FieldShaping" x="0" y="0" z="2" unit="cm"/>
2543  </physvol>
2544  <physvol name="volFCEW-BP-VerSuppBar-1">
2545  <volumeref ref="volFCEWVerSuppBar"/>
2546  <position name="posFCEW-BP-VerSuppBar-1" x="-74.2" y="0" z="5.75" unit="cm"/>
2547  </physvol>
2548  <physvol name="volFCEW-BP-VerSuppBar-2">
2549  <volumeref ref="volFCEWVerSuppBar"/>
2550  <position name="posFCEW-BP-VerSuppBar-2" x="-164.2" y="0" z="5.75" unit="cm"/>
2551  </physvol>
2552  <physvol name="volFCEW-BP-VerSuppBar-3">
2553  <volumeref ref="volFCEWVerSuppBar"/>
2554  <position name="posFCEW-BP-VerSuppBar-3" x="-74.2" y="0" z="-5.75" unit="cm"/>
2555  </physvol>
2556  <physvol name="volFCEW-BP-VerSuppBar-4">
2557  <volumeref ref="volFCEWVerSuppBar"/>
2558  <position name="posFCEW-BP-VerSuppBar-4" x="-164.2" y="0" z="-5.75" unit="cm"/>
2559  </physvol>
2560  <physvol name="volFCEW-BP-VerSuppBar-5">
2561  <volumeref ref="volFCEWVerSuppBar"/>
2562  <position name="posFCEW-BP-VerSuppBar-5" x="122.5" y="0" z="-5.75" unit="cm"/>
2563  </physvol>
2564  <physvol>
2565  <volumeref ref="volFCEW-BPVer"/>
2566  <position name="posFCEW-BPVer" x="169.4" y="0" z="-5.75" unit="cm"/>
2567  </physvol>
2568  </volume>
2569 
2570 EOF
2571 
2572 ##### Top and bottom field cage module volume
2573 
2574 print CRYO <<EOF;
2575 
2576  <volume name="volFCXBarOut">
2577  <materialref ref="FR4"/>
2578  <solidref ref="FCXBarOut"/>
2579  </volume>
2580  <volume name="volFCZBar">
2581  <materialref ref="FR4"/>
2582  <solidref ref="FCZBar"/>
2583  </volume>
2584  <volume name="volFCFieldBarPlane">
2585  <materialref ref="ALUMINUM_Al"/>
2586  <solidref ref="boxFCFieldBarPlane"/>
2587  </volume>
2588  <volume name="volShieldPlate">
2589  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2590  <solidref ref="boxShieldPlate"/>
2591  </volume>
2592  <volume name="volFCMod">
2593  <materialref ref="LAr"/>
2594  <solidref ref="boxFCMod"/>
2595  <physvol name="volFCXBarOut-1">
2596  <volumeref ref="volFCXBarOut"/>
2597  <position name="posFCXBarOut-1" x="0" y="-6.1" z="58" unit="cm"/>
2598  </physvol>
2599  <physvol name="volFCXBarOut-2">
2600  <volumeref ref="volFCXBarOut"/>
2601  <position name="posFCXBarOut-2" x="0" y="-6.1" z="-58" unit="cm"/>
2602  </physvol>
2603  <physvol>
2604  <volumeref ref="volFCFieldBarPlane"/>
2605  <position name="posFCFieldBarPlane" x="0" y="-9.4" z="0" unit="cm"/>
2606  </physvol>
2607  <physvol name="volFCZBar-1">
2608  <volumeref ref="volFCZBar"/>
2609  <position name="posFCZBar-1" x="141.6" y="-4.1" z="0" unit="cm"/>
2610  </physvol>
2611  <physvol name="volFCZBar-2">
2612  <volumeref ref="volFCZBar"/>
2613  <position name="posFCZBar-2" x="-41" y="-4.1" z="0" unit="cm"/>
2614  </physvol>
2615  <physvol name="volFCZBar-3">
2616  <volumeref ref="volFCZBar"/>
2617  <position name="posFCZBar-3" x="-143.5" y="-4.1" z="0" unit="cm"/>
2618  </physvol>
2619  <physvol>
2620  <volumeref ref="volShieldPlate"/>
2621  <position name="posShieldPlate" x="44" y="12.7" z="0" unit="cm"/>
2622  </physvol>
2623  </volume>
2624 EOF
2625 
2626 
2627 $posGaseousArgon_y = $Argon_y/2-$HeightGaseousAr/2;
2628 $BePlFlangeNi_z = $BePlFlange_z - 0.2;
2629 print CRYO <<EOF;
2630 
2631  <volume name="volAPAFrameYSide">
2632  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2633  <solidref ref="APAFrameYSide"/>
2634  </volume>
2635 
2636  <volume name="volAPAFrameZSide">
2637  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2638  <solidref ref="APAFrameZSide"/>
2639  </volume>
2640 
2641  <volume name="volAPAFrameYOuterSupport">
2642  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2643  <solidref ref="APAFrameYOuterSupport"/>
2644  </volume>
2645 
2646  <volume name="volG10BoardYSideCenterSeg">
2647  <materialref ref="G10"/>
2648  <solidref ref="G10BoardYSideCenterSeg"/>
2649  </volume>
2650 
2651  <volume name="volG10BoardZSideCenterSeg">
2652  <materialref ref="G10"/>
2653  <solidref ref="G10BoardZSideCenterSeg"/>
2654  </volume>
2655 
2656  <volume name="volCryostat">
2657  <materialref ref="LAr" />
2658  <solidref ref="Cryostat" />
2659  <physvol>
2660  <volumeref ref="volGaseousArgon"/>
2661  <position name="posGaseousArgon" unit="cm" x="0" y="$posGaseousArgon_y" z="0"/>
2662  </physvol>
2663  <physvol>
2664  <volumeref ref="volSteelShell"/>
2665  <position name="posSteelShell" unit="cm" x="0" y="0" z="0"/>
2666  </physvol>
2667  <physvol>
2668  <volumeref ref="volBeamPlugMod"/>
2669  <positionref ref="posBeamWAr3"/>
2670  <rotationref ref="rBeamWRev3"/>
2671  </physvol>
2672  <physvol>
2673  <volumeref ref="volBePlFlange"/>
2674  <position name="posBePlFlange" unit="cm" x="$BePlFlange_x" y="$BePlFlange_y" z="$BePlFlange_z"/>
2675  </physvol>
2676  <physvol>
2677  <volumeref ref="volBePlFlangeNi"/>
2678  <position name="posBePlFlangeNi" x="$BePlFlange_x" y="$BePlFlange_y" z="$BePlFlangeNi_z" unit="cm"/>
2679  </physvol>
2680 
2681 EOF
2682 print "Beam Plug position x=".$BePlFlange_x." y=".$BePlFlange_y." z=".$BePlFlange_z."\n";
2683 # nested for loops to place the non-rotated AND rotated volTPC
2684  # x loop rotation: There are six drift volumes. Looking into the
2685  # detector from incident direction, and counting from right (-x) to
2686  # left (+x), odd number volumes need to be rotated 180deg about Y in
2687  # order for the cathode to be on the right of the APA.
2688 
2689 if ($tpc_on==1) {
2690 
2691  $apa_i=0;
2692  $cpa_i=0;
2693 
2694  for($k=0 ; $k<$nAPALong ; $k++)
2695  {
2696  $APACenter_z = - $Argon_z/2
2697  + $UpstreamLArPadding
2698  + $APAphys_z/2
2699  + $k*($APAphys_z+$APAGap_z);
2700 
2701 
2702  for($j=0 ; $j<$nAPAHigh ; $j++) # nAPAHigh always going to be 2
2703  { # $j=0 for bottom APAs
2704  # $j=1 for top APAs
2705  $APACenter_y = - $Argon_y/2 + $SpaceAPAToFloor
2706  + $APAphys_y/2
2707  + $j*($APAphys_y+$APAGap_y);
2708 
2709  if( $workspace == 0 )
2710  {
2711 
2712  for($i=0 ; $i<$nAPAWide ; $i++)
2713  {
2714 
2715  $APACenter_x = - $Argon_x/2
2716  + $SpaceAPAToCryoWall + $APA_UtoU_x/2 + $TPCWirePlaneThickness/2
2717  + $i*$APAToAPA;
2718 
2719  $CPA_x = $APACenter_x + $CPAToAPA;
2720 # print "$i".", $nAPAWide".", CPA_x = $CPA_x"."\n";
2721 
2722  place_APA($APACenter_x, $APACenter_y, $APACenter_z, $apa_i, $j);
2723  place_OpDets($APACenter_x, $APACenter_y, $APACenter_z, $apa_i);
2724  $tpc_0 = 2*$apa_i+0;
2725  $tpc_1 = 2*$apa_i+1;
2726  $apa_i++;
2727 
2728  $SelectTPC_0 = "Inner";
2729  $SelectTPC_1 = "Inner";
2730  $TPC_0_x = $TPCInner_x;
2731  $TPC_1_x = $TPCInner_x;
2732  $rot_0 = "rPlus180AboutY";
2733  $rot_1 = "rIdentity";
2734  if($i == 0) { $SelectTPC_0 = "Outer"; $TPC_0_x = $TPCOuter_x; }
2735  if($i == $nAPAWide-1) { $SelectTPC_1 = "Outer"; $TPC_1_x = $TPCOuter_x; }
2736  if($j == 0) { $rot_0 = "rPlus180AboutXPlus180AboutY";
2737  $rot_1 = "rPlus180AboutX"; } #put the readout end at the bottom for bottom APAs
2738 
2739 
2740 $posvolTPC0_x = $APACenter_x - $APAFrame_x/2 - $TPC_0_x/2;
2741 $posvolTPC1_x = $APACenter_x + $APAFrame_x/2 + $TPC_1_x/2;
2742 print CRYO <<EOF;
2743 
2744  <physvol>
2745  <volumeref ref="volTPC$SelectTPC_0"/>
2746  <position name="posTPC\-$tpc_0" unit="cm"
2747  x="$posvolTPC0_x"
2748  y="$APACenter_y"
2749  z="$APACenter_z"/>
2750  <rotationref ref="$rot_0"/>
2751  </physvol>
2752  <physvol>
2753  <volumeref ref="volTPC$SelectTPC_1"/>
2754  <position name="posTPC\-$tpc_1" unit="cm"
2755  x="$posvolTPC1_x"
2756  y="$APACenter_y"
2757  z="$APACenter_z"/>
2758  <rotationref ref="$rot_1"/>
2759  </physvol>
2760 
2761 EOF
2762 
2763 
2764 if( $i < $nAPAWide - 1 ){ # avoid placeing the last row of CPAs since the APAs are on the outside
2765 
2766 print "$cpa_i".". CPA_x = $CPA_x".", APACenter_y = $APACenter_y".", APACenter_z = $APACenter_z"."\n";
2767 $CPAmodbarGap = 1.8*$inch;
2768 $FCmodRight_x[$cpa_i] = $CPA_x + 3 + 352/2; # CPAmodCenter_x to FCmodCenter_x
2769 $FCmodLeft_x[$cpa_i] = $CPA_x - 3 - 352/2;
2770 $FCmodTop_y[$cpa_i] = $APACenter_y + 603.3/2 + $CPAmodbarGap + 9.4 + 1.83; # CPAmodCenter_y to FCmodCenter_y with 1.5 inch distance between CPA and module bars
2771 $FCmodBottom_y[$cpa_i] = $APACenter_y - 603.3/2 - $CPAmodbarGap - 9.4 - 1.83;
2772 $FCmod_z[$cpa_i] = $APACenter_z;
2773 
2774 $FCEWmodRight_x = $CPA_x + 3 + 354.3/2;
2775 $FCEWmodLeft_x = $CPA_x - 3 - 354.3/2;
2776 if($cpa_i == 0) {
2777  $FCEWmodUS_z = $APACenter_z - 231.5/2 - $CPAmodbarGap - 2; #CPAmodCenter_z to FCEWmod
2778  for($fcewy_i = 0; $fcewy_i < 4; $fcewy_i++){
2779 
2780  $FCEWmod_y[$fcewy_i] = $APACenter_y + (-3 + 2*$fcewy_i)*77; #distance between FCEW module is 2.8 cm (originally 0.8 cm)
2781 
2782  }
2783 }
2784 if($cpa_i == 2) {
2785  $FCEWmodDS_z = $APACenter_z + 231.5/2 + $CPAmodbarGap + 2;
2786 }
2787 
2788 print CRYO <<EOF;
2789  <physvol>
2790  <volumeref ref="volCathode"/>
2791  <position name="posCathode\-$cpa_i" unit="cm"
2792  x="$CPA_x"
2793  y="$APACenter_y"
2794  z="$APACenter_z"/>
2795  <rotationref ref="rIdentity"/>
2796  </physvol>
2797  <physvol name="volFCModTopRight\-$cpa_i">
2798  <volumeref ref="volFCMod"/>
2799  <position name="posFCModTopRight\-$cpa_i" unit="cm"
2800  x="$FCmodRight_x[$cpa_i]"
2801  y="$FCmodTop_y[$cpa_i]"
2802  z="$FCmod_z[$cpa_i]"/>
2803  <rotationref ref="rPlus180AboutY"/>
2804  </physvol>
2805  <physvol name="volFCModTopLeft\-$cpa_i">
2806  <volumeref ref="volFCMod"/>
2807  <position name="posFCModTopLeft\-$cpa_i" unit="cm"
2808  x="$FCmodLeft_x[$cpa_i]"
2809  y="$FCmodTop_y[$cpa_i]"
2810  z="$FCmod_z[$cpa_i]"/>
2811  <rotationref ref="rIdentity"/>
2812  </physvol>
2813  <physvol name="volFCModBottomRight\-$cpa_i">
2814  <volumeref ref="volFCMod"/>
2815  <position name="posFCModBottomRight\-$cpa_i" unit="cm"
2816  x="$FCmodRight_x[$cpa_i]"
2817  y="$FCmodBottom_y[$cpa_i]"
2818  z="$FCmod_z[$cpa_i]"/>
2819  <rotationref ref="rPlus180AboutXPlus180AboutY"/>
2820  </physvol>
2821  <physvol name="volFCModBottomLeft\-$cpa_i">
2822  <volumeref ref="volFCMod"/>
2823  <position name="posFCModBottomLeft\-$cpa_i" unit="cm"
2824  x="$FCmodLeft_x[$cpa_i]"
2825  y="$FCmodBottom_y[$cpa_i]"
2826  z="$FCmod_z[$cpa_i]"/>
2827  <rotationref ref="rPlus180AboutX"/>
2828  </physvol>
2829 
2830 
2831 
2832 EOF
2833  $cpa_i++;
2834 }
2835 
2836 ################################## End Wall Field Cage Placement
2837 
2838 
2839  } #wide
2840 
2841 
2842 
2843  } # end if not the smaller workspace
2844 
2845 
2846  # Make the workspace have only one center APA with CPAs and the full drift on either side
2847  elsif( $workspace == 1 ){
2848 
2849  $APACenter_x = 0;
2850  $CPA_0_x = $APACenter_x - $CPAToAPA;
2851  $CPA_1_x = $APACenter_x + $CPAToAPA;
2852 
2853 
2854  place_APA($APACenter_x, $APACenter_y, $APACenter_z, $apa_i, $j);
2855  place_OpDets($APACenter_x, $APACenter_y, $APACenter_z, $apa_i);
2856 
2857  $tpc_0 = 2*$apa_i+0;
2858  $tpc_1 = 2*$apa_i+1;
2859  $apa_i++;
2860 
2861  $rot_0 = "rPlus180AboutY";
2862  $rot_1 = "rIdentity";
2863  if($j == 0) { $rot_0 = "rPlus180AboutXPlus180AboutY";
2864  $rot_1 = "rPlus180AboutX"; } #put the readout end at the bottom for bottom APAs
2865 
2866 $posvolTPCInner0_x = $APACenter_x - $APAFrame_x/2 - $TPCInner_x/2;
2867 $posvolTPCInner1_x = $APACenter_x + $APAFrame_x/2 + $TPCInner_x/2;
2868 print CRYO <<EOF;
2869 
2870  <physvol>
2871  <volumeref ref="volTPCInner"/>
2872  <position name="posTPC\-$tpc_0" unit="cm"
2873  x="$posvolTPCInner0_x"
2874  y="$APACenter_y"
2875  z="$APACenter_z"/>
2876  <rotationref ref="$rot_0"/>
2877  </physvol>
2878  <physvol>
2879  <volumeref ref="volTPCInner"/>
2880  <position name="posTPC\-$tpc_1" unit="cm"
2881  x="$posvolTPCInner1_x"
2882  y="$APACenter_y"
2883  z="$APACenter_z"/>
2884  <rotationref ref="$rot_1"/>
2885  </physvol>
2886 
2887  <physvol>
2888  <volumeref ref="volCathode"/>
2889  <position name="posCathode\-$apa_i-0" unit="cm"
2890  x="$CPA_0_x"
2891  y="$APACenter_y"
2892  z="$APACenter_z"/>
2893  <rotationref ref="rIdentity"/>
2894  </physvol>
2895  <physvol>
2896  <volumeref ref="volCathode"/>
2897  <position name="posCathode\-$apa_i-1" unit="cm"
2898  x="$CPA_1_x"
2899  y="$APACenter_y"
2900  z="$APACenter_z"/>
2901  <rotationref ref="rIdentity"/>
2902  </physvol>
2903 
2904 EOF
2905 
2906  } # if the smaller workspace
2907 
2908 
2909  } #high
2910  } #long
2911 
2912 }# end if tpc
2913 
2914 for($fcewy_i = 0; $fcewy_i < 4; $fcewy_i++){
2915 if($fcewy_i !=2){
2916 print CRYO <<EOF;
2917  <physvol name="volFCEWModUSLeft\-$fcewy_i">
2918  <volumeref ref="volFCEWmod"/>
2919  <position name="posFCEWModUSLeft\-$fcewy_i" unit="cm"
2920  x="$FCEWmodLeft_x"
2921  y="$FCEWmod_y[$fcewy_i]"
2922  z="$FCEWmodUS_z"/>
2923  <rotationref ref="rPlus180AboutZ"/>
2924  </physvol>
2925 EOF
2926 }
2927 print CRYO <<EOF;
2928  <physvol name="volFCEWModUSRight\-$fcewy_i">
2929  <volumeref ref="volFCEWmod"/>
2930  <position name="posFCEWModUSRight\-$fcewy_i" unit="cm"
2931  x="$FCEWmodRight_x"
2932  y="$FCEWmod_y[$fcewy_i]"
2933  z="$FCEWmodUS_z"/>
2934  <rotationref ref="rIdentity"/>
2935  </physvol>
2936  <physvol name="volFCEWModDSRight\-$fcewy_i">
2937  <volumeref ref="volFCEWmod"/>
2938  <position name="posFCEWModDSRight\-$fcewy_i" unit="cm"
2939  x="$FCEWmodRight_x"
2940  y="$FCEWmod_y[$fcewy_i]"
2941  z="$FCEWmodDS_z"/>
2942  <rotationref ref="rPlus180AboutX"/>
2943  </physvol>
2944  <physvol name="volFCEWModDSLeft\-$fcewy_i">
2945  <volumeref ref="volFCEWmod"/>
2946  <position name="posFCEWModDSLeft\-$fcewy_i" unit="cm"
2947  x="$FCEWmodLeft_x"
2948  y="$FCEWmod_y[$fcewy_i]"
2949  z="$FCEWmodDS_z"/>
2950  <rotationref ref="rPlus180AboutXPlus180AboutZ"/>
2951  </physvol>
2952 EOF
2953 }
2954 
2955 $FCEWBPmod_x = $FCEWmodLeft_x + 2.8;
2956 $FCEWBPmod_y = $FCEWmod_y[2] + 0.9;
2957 $FCEWBPmod_z = $FCEWmodUS_z;
2958 
2959 $FCEWBPFla_x = $FCEWBPmod_x + 147.8;
2960 $FCEWBPFla_y = $FCEWBPmod_y + 0;
2961 $FCEWBPFla_z = $FCEWBPmod_z + 5.75;
2962 
2963 print "volFCEW-BPFla pos x=".$FCEWBPFla_x." y=".$FCEWBPFla_y." z=".$FCEWBPFla_z."\n";
2964 
2965 print CRYO <<EOF;
2966  <physvol>
2967  <volumeref ref="volFCEW-BP-mod"/>
2968  <position name="posFCEW-BP-mod" unit="cm"
2969  x="$FCEWBPmod_x"
2970  y="$FCEWBPmod_y"
2971  z="$FCEWBPmod_z"/>
2972  </physvol>
2973 
2974  <physvol>
2975  <volumeref ref="volFCEW-BPFla"/>
2976  <position name="posFCEW-BPFla" unit="cm"
2977  x="$FCEWBPFla_x"
2978  y="$FCEWBPFla_y"
2979  z="$FCEWBPFla_z"/>
2980  </physvol>
2981 EOF
2982 
2983 print CRYO <<EOF;
2984  </volume>
2985 </structure>
2986 </gdml>
2987 EOF
2988 
2989 close(CRYO);
2990 }
2991 
2992 
2993 
2994 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2995 #++++++++++++++++++++++++++++++++++++ place_OpDets +++++++++++++++++++++++++++++++++++++++
2996 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2997 
2998 sub place_OpDets()
2999 {
3000 
3001  $APACenter_x = $_[0];
3002  $APACenter_y = $_[1];
3003  $APACenter_z = $_[2];
3004  $apa_i = $_[3];
3005 
3006  $test = 0;
3007 
3008 for ($paddle = 0; $paddle<$nLightPaddlesPerAPA; $paddle++)
3009 {
3010 
3011  # All Light Paddle centers will have the same
3012  # X coordinate as the center of the current APA
3013  # Z coordinate as the current TPC pair
3014  # The Y coordinate must be looped over:
3015 
3016  #the multiplication by j here is a temporary dirty trick to get around some strange behavior
3017 
3018  $Paddle_Y = $APACenter_y
3019  - $APAphys_y/2
3020  + $FrameToPaddleSpace
3021  + (1-$j)*($LightPaddle_y/2)
3022  + $PaddleYInterval*$paddle;
3023 
3024  if($apa_i==$nAraAPA1){
3025  if($paddle==$nSlotAra1) {$test=1;}
3026  } #where the arapuca bar goes for pDUNE
3027  if($apa_i==$nAraAPA2){
3028  if($paddle==$nSlotAra2) {$test=1;}
3029  }
3030 
3031  if(($test!=1)){
3032  # Alternate the paddle orientations
3033  if ( $paddle % 2 == 0 ) { $rot = "rIdentity"; }
3034  else { $rot = "rPlus180AboutY"; }
3035 
3036  $posvolOpDetSensitive_z = $APACenter_z + $SiPM_z/2;
3037  print CRYO <<EOF;
3038  <physvol>
3039  <volumeref ref="volOpDetSensitive_$apa_i\-$paddle"/>
3040  <position name="posPaddle\-$paddle\-TPC\-$i\-$j\-$k" unit="cm"
3041  x="$APACenter_x"
3042  y="$Paddle_Y"
3043  z="$posvolOpDetSensitive_z"/>
3044  <rotationref ref="$rot"/>
3045  </physvol>
3046 EOF
3047 
3048 $test = 0;
3049  }else{
3050  if ( $apa_i % 2 == 0 ) {
3051  $rot = "rIdentity";
3052  $posArax = ($APACenter_x+0.05*$ArapucaOut_x-0.05*$ArapucaAcceptanceWindow_x-0.01);
3053  }else{
3054  $rot = "rPlus180AboutY";
3055  $posArax = ($APACenter_x-0.05*$ArapucaOut_x+0.05*$ArapucaAcceptanceWindow_x+0.01);
3056  }
3057 
3058  print CRYO <<EOF;
3059  <physvol>
3060  <volumeref ref="volArapuca_$apa_i"/>
3061  <position name="posArapuca$apa_i-TPC\-$i\-$j\-$k" unit="cm"
3062  x="@{[$APACenter_x]}"
3063  y="@{[$Paddle_Y]}"
3064  z="@{[$APACenter_z]}"/>
3065  <rotationref ref="$rot"/>
3066  </physvol>
3067 EOF
3068  for ($ara = 0; $ara<16; $ara++){
3069  print CRYO <<EOF;
3070  <physvol>
3071  <volumeref ref="volOpDetSensitive_Arapuca_$apa_i\-$ara"/>
3072  <position name="posOpArapuca$apa_i\-$ara\-TPC\-$i\-$j\-$k" unit="cm"
3073  x="@{[$posArax]}"
3074  y="@{[$Paddle_Y]}"
3075  z="@{[(0.1*$list_pos[$ara]+$APACenter_z)]}"/>
3076  </physvol>
3077 EOF
3078 }
3079 $test = 0;
3080 }
3081 }#end Paddle for-loop
3082 
3083 }
3084 
3085 
3086 
3087 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3088 #++++++++++++++++++++++++++++++++++++++ place_APA ++++++++++++++++++++++++++++++++++++++++
3089 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3090 
3091 
3092 # Must be called only within gen_Cryostat(),
3093 
3094 
3095 # $_[0] = x APA physical center
3096 # $_[1] = y APA physical center
3097 # $_[2] = z APA physical center
3098 # $_[3] = APA number
3099 # $_[4] = 0 for APA with readout on bottom
3100 # 1 for APA with readout on top
3101 
3102 sub place_APA()
3103 {
3104 
3105  $APA_i = $_[3];
3106 
3107 ####################################################################
3108 ################# APA Frame and Paddle Dimensions ##################
3109 
3110 # The center passed to this function is the physical APA center,
3111 # which is not quite the frame's center, since there are more boards
3112 # at the bottom. Transform them:
3113 
3114  $APAFrameCenter_x = $_[0];
3115  $APAFrameCenter_z = $_[2];
3116 
3117 # The bottom APAs are upside down relative to how the TPC is initially generated,
3118 # and the center needs to be slightly shifted since there is extra G10 on the
3119 # end that doesn't read out.
3120 
3121  if($_[4]==1) # top APAs
3122  {
3123  $APAFrameCenter_y = $_[1] - $APAphys_y/2
3124  + $WrapCover + 4*$G10thickness
3125  + $APAFrame_y/2;
3126  }
3127  elsif($_[4]==0) # bottom APAs
3128  {
3129  $APAFrameCenter_y = $_[1] + $APAphys_y/2
3130  - $WrapCover - 4*$G10thickness
3131  - $APAFrame_y/2;
3132  }
3133  else{ print "APA not labeled as top or bottom"; }
3134 
3135 $APAFrameZSide_x = $APAFrame_x;
3136 $APAFrameZSide_y = 4*$inch;
3137 $APAFrameZSide_z = $APAFrame_z;
3138 
3139 $APAFrameYSide_x = $APAFrame_x;
3140 $APAFrameYSide_y = $APAFrame_y-2*$APAFrameZSide_y;
3141 $APAFrameYSide_z = 4*$inch;
3142 
3143 # Two outer Y supports will sandwich the light paddles
3144 $APAFrameYOuterSupport_x = ($APAFrame_x-$LightPaddle_x)/2;
3145 $APAFrameYOuterSupport_y = $APAFrame_y-2*$APAFrameZSide_y;
3146 $APAFrameYOuterSupport_z = 4*$inch;
3147 
3148 # if there were an inner support to fill the hole
3149 $APAFrameYInnerSupport_x = $LightPaddle_x;
3150 
3151 $EdgeFrameSteelThickness = 0.12*$inch;
3152 $InnerFrameSteelThickness = 0.062*$inch;
3153 
3154 
3155 $G10BoardYSide_x = $APAFrame_x;
3156 $G10BoardYSide_y = $APAFrame_y;
3157 $G10BoardYSide_z = $G10thickness;
3158 
3159 $G10BoardZSide_x = $APAFrame_x;
3160 $G10BoardZSide_y = $G10thickness;
3161 $G10BoardZSide_z = $APAFrame_z;
3162 
3163 if($_[4]==1) # top APAs
3164 {
3165  $posG10ZSideZ_y = $APAFrameCenter_y - $APAFrame_y/2 - (0+.5)*($G10BoardZSide_y);
3166  $posG10ZSideV_y = $APAFrameCenter_y - $APAFrame_y/2 - (1+.5)*($G10BoardZSide_y);
3167  $posG10ZSideU_y = $APAFrameCenter_y - $APAFrame_y/2 - (2+.5)*($G10BoardZSide_y);
3168  $posG10ZSideGrid_y = $APAFrameCenter_y - $APAFrame_y/2 - (3+.5)*($G10BoardZSide_y);
3169 }
3170 elsif($_[4]==0) # bottom APAs
3171 {
3172  $posG10ZSideZ_y = $APAFrameCenter_y + $APAFrame_y/2 + (0+.5)*($G10BoardZSide_y);
3173  $posG10ZSideV_y = $APAFrameCenter_y + $APAFrame_y/2 + (1+.5)*($G10BoardZSide_y);
3174  $posG10ZSideU_y = $APAFrameCenter_y + $APAFrame_y/2 + (2+.5)*($G10BoardZSide_y);
3175  $posG10ZSideGrid_y = $APAFrameCenter_y + $APAFrame_y/2 + (3+.5)*($G10BoardZSide_y);
3176 }
3177 else{ print "APA not labeled as top or bottom"; }
3178 
3179  # First put in the frame
3180 # print CRYO <<EOF;
3181 #<!--
3182 # <physvol>
3183 # <volumeref ref="volAPAFrameYOuterSupport\-$APA_i"/>
3184 # <position name="posAPAFrameYOuterSupportNeg\-$APA_i" unit="cm"
3185 # x="$APAFrameCenter_x - ($APAFrameYOuterSupport_x + $APAFrameYInnerSupport_x/2 - $EdgeFrameSteelThickness/2)"
3186 # y="$APAFrameCenter_y"
3187 # z="$APAFrameCenter_z"/>
3188 # <rotationref ref="rIdentity"/>
3189 # </physvol>
3190 # <physvol>
3191 # <volumeref ref="volAPAFrameYOuterSupport\-$APA_i"/>
3192 # <position name="posAPAFrameYOuterSupportPos\-$APA_i" unit="cm"
3193 # x="$APAFrameCenter_x + ($APAFrameYOuterSupport_x + $APAFrameYInnerSupport_x/2 - $EdgeFrameSteelThickness/2)"
3194 # y="$APAFrameCenter_y"
3195 # z="$APAFrameCenter_z"/>
3196 # <rotationref ref="rIdentity"/>
3197 # </physvol>
3198 #-->
3199 #EOF
3200 
3201  $posvolAPAFrameYSideNeg_z = $APAFrameCenter_z - $APAFrame_z/2 + $APAFrameYSide_z/2;
3202  $posvolAPAFrameYSidePos_z = $APAFrameCenter_z + $APAFrame_z/2 - $APAFrameYSide_z/2;
3203  $posvolAPAFrameZSidePos_y = $APAFrameCenter_y + $APAFrame_y/2 - $APAFrameZSide_y/2;
3204  $posvolAPAFrameZSideNeg_y = $APAFrameCenter_y - $APAFrame_y/2 + $APAFrameZSide_y/2;
3205  print CRYO <<EOF;
3206  <physvol>
3207  <volumeref ref="volAPAFrameYSide"/>
3208  <position name="posAPAFrameYSideNeg\-$APA_i" unit="cm"
3209  x="$APAFrameCenter_x"
3210  y="$APAFrameCenter_y"
3211  z="$posvolAPAFrameYSideNeg_z"/>
3212  <rotationref ref="rIdentity"/>
3213  </physvol>
3214  <physvol>
3215  <volumeref ref="volAPAFrameYSide"/>
3216  <position name="posAPAFrameYSidePos\-$APA_i" unit="cm"
3217  x="$APAFrameCenter_x"
3218  y="$APAFrameCenter_y"
3219  z="$posvolAPAFrameYSidePos_z"/>
3220  <rotationref ref="rIdentity"/>
3221  </physvol>
3222  <physvol>
3223  <volumeref ref="volAPAFrameZSide"/>
3224  <position name="posAPAFrameZSidePos\-$APA_i" unit="cm"
3225  x="$APAFrameCenter_x"
3226  y="$posvolAPAFrameZSidePos_y"
3227  z="$APAFrameCenter_z"/>
3228  <rotationref ref="rIdentity"/>
3229  </physvol>
3230  <physvol>
3231  <volumeref ref="volAPAFrameZSide"/>
3232  <position name="posAPAFrameZSideNeg\-$APA_i" unit="cm"
3233  x="$APAFrameCenter_x"
3234  y="$posvolAPAFrameZSideNeg_y"
3235  z="$APAFrameCenter_z"/>
3236  <rotationref ref="rIdentity"/>
3237  </physvol>
3238 
3239 
3240  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3241  - Add the *parts* of the G10 boards that exist directly in volCryostat.
3242  - There are two boards on each the up and downstream end,
3243  one each to wrap the U and V views around the APA frame
3244  - There are 4 on the bottom which anchor the U V and Z wires and the grid plane
3245  - The rest of the parts of the G10 boards must be placed directly in volTPC -->
3246 EOF
3247 
3248  $posvolG10BoardYSideCenterSegVup_z = $APAFrameCenter_z - $APAFrame_z/2 - (0+.5)*($G10BoardYSide_z);
3249  $posvolG10BoardYSideCenterSegUup_z = $APAFrameCenter_z - $APAFrame_z/2 - (1+.5)*($G10BoardYSide_z);
3250  $posvolG10BoardYSideCenterSegVdo_z = $APAFrameCenter_z + $APAFrame_z/2 + (0+.5)*($G10BoardYSide_z);
3251  $posvolG10BoardYSideCenterSegUdo_z = $APAFrameCenter_z + $APAFrame_z/2 + (1+.5)*($G10BoardYSide_z);
3252  print CRYO <<EOF;
3253  <physvol>
3254  <volumeref ref="volG10BoardYSideCenterSeg"/>
3255  <position name="posG10BoardYSideCenterSeg\-Vup\-$APA_i" unit="cm"
3256  x="$APAFrameCenter_x"
3257  y="$APAFrameCenter_y"
3258  z="$posvolG10BoardYSideCenterSegVup_z"/>
3259  <rotationref ref="rIdentity"/>
3260  </physvol>
3261  <physvol>
3262  <volumeref ref="volG10BoardYSideCenterSeg"/>
3263  <position name="posG10BoardYSideCenterSeg\-Uup\-$APA_i" unit="cm"
3264  x="$APAFrameCenter_x"
3265  y="$APAFrameCenter_y"
3266  z="$posvolG10BoardYSideCenterSegUup_z"/>
3267  <rotationref ref="rIdentity"/>
3268  </physvol>
3269 
3270  <physvol>
3271  <volumeref ref="volG10BoardYSideCenterSeg"/>
3272  <position name="posG10BoardYSideCenterSeg\-Vdown\-$APA_i" unit="cm"
3273  x="$APAFrameCenter_x"
3274  y="$APAFrameCenter_y"
3275  z="$posvolG10BoardYSideCenterSegVdo_z"/>
3276  <rotationref ref="rIdentity"/>
3277  </physvol>
3278  <physvol>
3279  <volumeref ref="volG10BoardYSideCenterSeg"/>
3280  <position name="posG10BoardYSideCenterSeg\-Udown\-$APA_i" unit="cm"
3281  x="$APAFrameCenter_x"
3282  y="$APAFrameCenter_y"
3283  z="$posvolG10BoardYSideCenterSegUdo_z"/>
3284  <rotationref ref="rIdentity"/>
3285  </physvol>
3286 
3287  <physvol>
3288  <volumeref ref="volG10BoardZSideCenterSeg"/>
3289  <position name="posG10BoardZSideCenterSeg\-Z\-$APA_i" unit="cm"
3290  x="$APAFrameCenter_x"
3291  y="$posG10ZSideZ_y"
3292  z="$APAFrameCenter_z"/>
3293  <rotationref ref="rIdentity"/>
3294  </physvol>
3295  <physvol>
3296  <volumeref ref="volG10BoardZSideCenterSeg"/>
3297  <position name="posG10BoardZSideCenterSeg\-V\-$APA_i" unit="cm"
3298  x="$APAFrameCenter_x"
3299  y="$posG10ZSideV_y"
3300  z="$APAFrameCenter_z"/>
3301  <rotationref ref="rIdentity"/>
3302  </physvol>
3303  <physvol>
3304  <volumeref ref="volG10BoardZSideCenterSeg"/>
3305  <position name="posG10BoardZSideCenterSeg\-U\-$APA_i" unit="cm"
3306  x="$APAFrameCenter_x"
3307  y="$posG10ZSideU_y"
3308  z="$APAFrameCenter_z"/>
3309  <rotationref ref="rIdentity"/>
3310  </physvol>
3311  <physvol>
3312  <volumeref ref="volG10BoardZSideCenterSeg"/>
3313  <position name="posG10BoardZSideCenterSeg\-Grid\-$APA_i" unit="cm"
3314  x="$APAFrameCenter_x"
3315  y="$posG10ZSideGrid_y"
3316  z="$APAFrameCenter_z"/>
3317  <rotationref ref="rIdentity"/>
3318  </physvol>
3319 
3320 EOF
3321 
3322 
3323 }
3324 
3325 
3326 
3327 
3328 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3329 #+++++++++++++++++++++++++++++++++++++ gen_Enclosure +++++++++++++++++++++++++++++++++++++
3330 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3331 
3332 sub gen_Enclosure()
3333 {
3334 
3335 # Create the detector enclosure fragment file name,
3336 # add file to list of output GDML fragments,
3337 # and open it
3338  $ENCL = "subfile_protodune_v7_DetEnclosure" . $suffix . ".gdml";
3339  push (@gdmlFiles, $ENCL);
3340  $ENCL = ">" . $ENCL;
3341  open(ENCL) or die("Could not open file $ENCL for writing");
3342 
3343 
3344 # The standard XML prefix and starting the gdml
3345  print ENCL <<EOF;
3346 <?xml version='1.0'?>
3347 <gdml>
3348 EOF
3349 
3350 
3351 # All the detector enclosure solids.
3352 $dimFoamPadBlock_x = $Cryostat_x + 2*$FoamPadding;
3353 $dimFoamPadBlock_y = $Cryostat_y + 2*$FoamPadding;
3354 $dimFoamPadBlock_z = $Cryostat_z + 2*$FoamPadding;
3355 $dimSteelSupportBlock_x = $Cryostat_x + 2*$FoamPadding + 2*$SteelSupport_x;
3356 $dimSteelSupportBlock_y = $Cryostat_y + 2*$FoamPadding + 2*$SteelSupport_y;
3357 $dimSteelSupportBlock_z = $Cryostat_z + 2*$FoamPadding + 2*$SteelSupport_z;
3358 $dimSteelPlateBlock_x = $Cryostat_x + 2*$FoamPadding + 2*$SteelPlate;
3359 $dimSteelPlateBlock_y = $Cryostat_y + 2*$FoamPadding + 2*$SteelPlate;
3360 $dimSteelPlateBlock_z = $Cryostat_z + 2*$FoamPadding + 2*$SteelPlate;
3361 
3362 $dimPitDepth = 900;
3363 $dimPitWidth = 1650;
3364 $dimStSuToDSPitWall = 160;
3365 $dimPitLength = $DetEncLength/2 + $dimSteelSupportBlock_z/2 + $dimStSuToDSPitWall;
3366 $dimEnclConcrete_y = $SpaceSteelSupportToWall + $dimPitDepth;
3367 $DetCentToJuraPit = 958;
3368 
3369 $dimPit_y = $dimPitDepth + 0.1; # try to avoid overlap
3370 $dimPit_z = $dimPitLength + 0.1;
3371 $posPitInConcrete_x = $DetCentToJuraPit - $dimPitWidth/2;
3372 $posPitInConcrete_y = $dimEnclConcrete_y/2 - $dimPitDepth/2 ;
3373 $posPitInConcrete_z = - $DetEncLength/2 + $dimPitLength/2 ;
3374 $posSurrConcrete_y = - $DetEncHeight/2 + $dimEnclConcrete_y/2 ;
3375 
3376 print "FoamPad x=$dimFoamPadBlock_x".", y=$dimFoamPadBlock_y".", z=$dimFoamPadBlock_z"."\n";
3377 print "SteelPlate x=$dimSteelPlateBlock_x".", y=$dimSteelPlateBlock_y".", z=$dimSteelPlateBlock_z"."\n";
3378 print "SteelSupport x=$dimSteelSupportBlock_x".", y=$dimSteelSupportBlock_y".", z=$dimSteelSupportBlock_z"."\n";
3379 print ENCL <<EOF;
3380 <solids>
3381  <box name="FoamPadBlock" lunit="cm"
3382  x="$dimFoamPadBlock_x"
3383  y="$dimFoamPadBlock_y"
3384  z="$dimFoamPadBlock_z" />
3385 
3386  <box name="SteelPlateBlock" lunit="cm"
3387  x="$dimSteelPlateBlock_x"
3388  y="$dimSteelPlateBlock_y"
3389  z="$dimSteelPlateBlock_z" />
3390 
3391  <subtraction name="SteelPlateNoBW">
3392  <first ref="SteelPlateBlock"/>
3393  <second ref="FoamPadBlock"/>
3394  <positionref ref="posCenter"/>
3395  </subtraction>
3396 
3397  <subtraction name="FoamPaddingNoBW">
3398  <first ref="FoamPadBlock"/>
3399  <second ref="Cryostat"/>
3400  <positionref ref="posCenter"/>
3401  </subtraction>
3402 EOF
3403 
3404 # <cutTube name="BeamWindowStPlate" rmin="0" rmax="$BeamPipeRad" z="$BeamWStPlateLe" startphi="0" deltaphi="360" lowX="-0.239669734044" lowY="0" lowZ="-0.970854478582" highX="0.239669734044" highY="0" highZ="0.970854478582" aunit="deg" lunit="cm"/>
3405 
3406 # <cutTube name="BeamWindowFoam" rmin="0" rmax="$BeamPipeRad" z="$BeamWFoLe" startphi="0" deltaphi="360" lowX="-0.239669734044" lowY="0" lowZ="-0.970854478582" highX="0.239669734044" highY="0" highZ="0.970854478582" aunit="deg" lunit="cm"/>
3407 
3408  print ENCL <<EOF;
3409 
3410  <cutTube name="BeamWindowStPlate" rmin="0" rmax="$BeamPipeRad" z="$BeamWStPlateLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="3.41304459712e-17" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
3411 
3412  <cutTube name="BeamWindowFoam" rmin="0" rmax="$BeamPipeRad" z="$BeamWFoLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="3.41304459712e-17" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
3413 
3414  <cutTube name="BeamWindowFoamRem" rmin="0" rmax="$BeamPipeRad" z="$BeamWFoRemLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="3.41304459712e-17" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
3415 
3416  <cutTube name="BeamWindowStSu" rmin="0" rmax="$BeamPipeRad" z="$BeamWStSuLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="3.41304459712e-17" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
3417 
3418  <cutTube name="BeamWindowGlassWool" rmin="0" rmax="$BeamPipeRad" z="$BeamWGlLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="3.41304459712e-17" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
3419 
3420  <cutTube name="BeamPipe" rmin="0" rmax="$BeamPipeRad" z="$BeamPipeLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="3.41304459712e-17" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
3421 
3422  <cutTube name="BeamPipeVacuum" rmin="0" rmax="$BeamVaPipeRad" z="$BeamVaPipeLe" startphi="0" deltaphi="360" lowX="-0.278696241193" lowY="3.41304459712e-17" lowZ="-0.960379302747" highX="0.278696241193" highY="0" highZ="0.960379302747" aunit="deg" lunit="cm"/>
3423 
3424  <subtraction name="SteelPlate">
3425  <first ref="SteelPlateNoBW"/>
3426  <second ref="BeamWindowStPlate"/>
3427  <position name="posBWStPl" x="$BeamWStPlate_x" y="$BeamWStPlate_y" z="$BeamWStPlate_z" unit="cm"/>
3428  <rotationref ref="rBeamW3"/>
3429  </subtraction>
3430 
3431  <subtraction name="FoamPadding">
3432  <first ref="FoamPaddingNoBW"/>
3433  <second ref="BeamWindowFoamRem"/>
3434  <position name="posBWFoPa" x="$BeamWFoRem_x" y="$BeamWFoRem_y" z="$BeamWFoRem_z" unit="cm"/>
3435  <rotationref ref="rBeamW3"/>
3436  </subtraction>
3437 
3438  <box name="CRTPaddle" lunit="cm"
3439  x="$CRTPaddleWidth"
3440  y="$CRTPaddleHeight"
3441  z="$CRTPaddleLength"/>
3442 
3443  <box name="CRTModule" lunit="cm"
3444  x="$CRTModWidth"
3445  y="$CRTModHeight"
3446  z="$CRTModLength"/>
3447 
3448  <box name="DetEnclosure" lunit="cm"
3449  x="$DetEncWidth"
3450  y="$DetEncHeight"
3451  z="$DetEncLength"/>
3452 
3453  <box name="SurrConcreteBox" lunit="cm"
3454  x="$DetEncWidth"
3455  y="$dimEnclConcrete_y"
3456  z="$DetEncLength"/>
3457 
3458  <box name="PitBox" lunit="cm"
3459  x="$dimPitWidth"
3460  y="$dimPit_y"
3461  z="$dimPit_z"/>
3462 
3463  <subtraction name="SurrConcrete">
3464  <first ref="SurrConcreteBox"/>
3465  <second ref="PitBox"/>
3466  <position name="posPitInConcrete" x="$posPitInConcrete_x" y="$posPitInConcrete_y" z="$posPitInConcrete_z" unit="cm"/>
3467  </subtraction>
3468 
3469 
3470 EOF
3471 if($simpleStSu == 1)
3472 {
3473  print ENCL <<EOF;
3474 
3475  <box name="SteelSupportBlock" lunit="cm"
3476  x="$dimSteelSupportBlock_x"
3477  y="$dimSteelSupportBlock_y"
3478  z="$dimSteelSupportBlock_z" />
3479 
3480  <subtraction name="SteelSupportNoBW">
3481  <first ref="SteelSupportBlock"/>
3482  <second ref="SteelPlateBlock"/>
3483  <positionref ref="posCenter"/>
3484  </subtraction>
3485 
3486  <subtraction name="SteelSupport">
3487  <first ref="SteelSupportNoBW"/>
3488  <second ref="BeamWindowStSu"/>
3489  <position name="posBWStSu" x="$BeamWStSu_x" y="$BeamWStSu_y" z="$BeamWStSu_z" unit="cm"/>
3490  <rotationref ref="rBeamW3"/>
3491  </subtraction>
3492 
3493 EOF
3494 }
3495 elsif($simpleStSu == 0)
3496 {
3497  print ENCL <<EOF;
3498 
3499  <box name="boxCryoTop" x="1016.8" y="1016.8" z="61.8" lunit="cm"/>
3500  <box name="boxCryoWallLg" x="1140.4" y="1075.6" z="61.8" lunit="cm"/>
3501  <box name="boxCryoWallSm" x="1016.8" y="1075.6" z="61.8" lunit="cm"/>
3502  <box name="box1" x="160" y="160" z="61.8" lunit="cm"/>
3503  <box name="box2" x="158.2" y="158.2" z="56.2" lunit="cm"/>
3504  <box name="box3" x="137.2" y="137.2" z="61.801" lunit="cm"/>
3505  <box name="box4" x="158.2" y="13.6" z="27.4" lunit="cm"/>
3506  <box name="box5" x="158.2" y="6.425" z="24.96" lunit="cm"/>
3507  <box name="box11" x="108.4" y="160" z="61.8" lunit="cm"/>
3508  <box name="box12" x="107.5" y="158.2" z="56.2" lunit="cm"/>
3509  <box name="box13" x="97" y="137.2" z="61.81" lunit="cm"/>
3510  <box name="box16" x="107.5" y="13.6" z="27.4" lunit="cm"/>
3511  <box name="box17" x="107.5" y="6.425" z="24.96" lunit="cm"/>
3512  <box name="box21" x="137.8" y="160" z="61.8" lunit="cm"/>
3513  <box name="box22" x="136.9" y="158.2" z="56.2" lunit="cm"/>
3514  <box name="box23" x="126.4" y="137.2" z="61.801" lunit="cm"/>
3515  <box name="box26" x="102.5" y="13.6" z="27.4" lunit="cm"/>
3516  <box name="box27" x="102.5" y="6.425" z="24.96" lunit="cm"/>
3517  <box name="box31" x="170.2" y="160" z="61.8" lunit="cm"/>
3518  <box name="box32" x="169.3" y="158.2" z="56.2" lunit="cm"/>
3519  <box name="box33" x="158.8" y="137.2" z="61.801" lunit="cm"/>
3520  <box name="box36" x="135.8" y="13.6" z="27.4" lunit="cm"/>
3521  <box name="box37" x="135.8" y="6.425" z="24.96" lunit="cm"/>
3522 
3523 
3524  <subtraction name="boxHoll">
3525  <first ref="box1"/>
3526  <second ref="box2"/>
3527  </subtraction>
3528  <subtraction name="boxLargeCent">
3529  <first ref="boxHoll"/>
3530  <second ref="box3"/>
3531  </subtraction>
3532  <subtraction name="boxBarI">
3533  <first ref="box4"/>
3534  <second ref="box5"/>
3535  <position name="posBoxBarI" x="0" y="3.5876" z="0" unit="cm"/>
3536  </subtraction>
3537  <subtraction name="boxBarCent">
3538  <first ref="boxBarI"/>
3539  <second ref="box5"/>
3540  <position name="posBoxBarCent" x="0" y="-3.5876" z="0" unit="cm"/>
3541  </subtraction>
3542  <union name="boxUniCent">
3543  <first ref="boxLargeCent"/>
3544  <second ref="boxBarCent"/>
3545  <position name="posBoxUniCent" x="0" y="0" z="-17.2" unit="cm"/>
3546  </union>
3547  <union name="UnitCent">
3548  <first ref="boxUniCent"/>
3549  <second ref="boxBarCent"/>
3550  <position name="posUnitCent" x="0" y="0" z="-17.2" unit="cm"/>
3551  <rotation name="rotUnitCent" x="0" y="0" z="90" unit="deg"/>
3552  </union>
3553 
3554  <subtraction name="boxTopHoll">
3555  <first ref="box11"/>
3556  <second ref="box12"/>
3557  <position name="posboxTopHoll" x="0.451" y="0" z="0" unit="cm"/>
3558  </subtraction>
3559  <subtraction name="boxLargeTop">
3560  <first ref="boxTopHoll"/>
3561  <second ref="box13"/>
3562  <position name="posboxLargeTop" x="5.701" y="0" z="0" unit="cm"/>
3563  </subtraction>
3564  <subtraction name="boxBarTopI">
3565  <first ref="box16"/>
3566  <second ref="box17"/>
3567  <position name="posboxBarTopI" x="0" y="3.5876" z="0" unit="cm"/>
3568  </subtraction>
3569  <subtraction name="boxBarTop">
3570  <first ref="boxBarTopI"/>
3571  <second ref="box17"/>
3572  <position name="posboxBarTop" x="0" y="-3.5876" z="0" unit="cm"/>
3573  </subtraction>
3574  <union name="boxUniTop">
3575  <first ref="boxLargeTop"/>
3576  <second ref="boxBarCent"/>
3577  <position name="posboxUni1" x="5.6" y="0" z="-17.2" unit="cm"/>
3578  <rotation name="rotUni1" x="0" y="0" z="90" unit="deg"/>
3579  </union>
3580  <union name="UnitTop">
3581  <first ref="boxUniTop"/>
3582  <second ref="boxBarTop"/>
3583  <position name="posUniTop" x="0.45" y="0" z="-17.2" unit="cm"/>
3584  </union>
3585 
3586  <subtraction name="boxCryoWallSmUS">
3587  <first ref="boxCryoWallSm"/>
3588  <second ref="BeamWindowStSu"/>
3589  <position name="posBWCryoWallUS" x="$BeamWStSu_x" y="$BeamWStSu_y" z="0." unit="cm"/>
3590  <rotationref ref="rBeamW3"/>
3591  </subtraction>
3592 
3593  <subtraction name="boxWallUHoll">
3594  <first ref="box21"/>
3595  <second ref="box22"/>
3596  <position name="posboxWallUHoll" x="0.451" y="0" z="0" unit="cm"/>
3597  </subtraction>
3598  <subtraction name="boxLargeWallU">
3599  <first ref="boxWallUHoll"/>
3600  <second ref="box23"/>
3601  <position name="posboxLargeWallU" x="5.701" y="0" z="0" unit="cm"/>
3602  </subtraction>
3603  <subtraction name="boxBarWallUI">
3604  <first ref="box26"/>
3605  <second ref="box27"/>
3606  <position name="posboxBarWallUI" x="0" y="3.5876" z="0" unit="cm"/>
3607  </subtraction>
3608  <subtraction name="boxBarWallU">
3609  <first ref="boxBarWallUI"/>
3610  <second ref="box27"/>
3611  <position name="posboxBarWallU" x="0" y="-3.5876" z="0" unit="cm"/>
3612  </subtraction>
3613  <union name="boxUniWallU">
3614  <first ref="boxLargeWallU"/>
3615  <second ref="boxBarCent"/>
3616  <position name="posboxUni2" x="-9.1" y="0" z="-17.2" unit="cm"/>
3617  <rotation name="rotUni2" x="0" y="0" z="90" unit="deg"/>
3618  </union>
3619  <union name="UnitWallU">
3620  <first ref="boxUniWallU"/>
3621  <second ref="boxBarWallU"/>
3622  <position name="posUniWallU" x="-16.75" y="0" z="-17.2" unit="cm"/>
3623  </union>
3624 
3625  <subtraction name="boxWallLHoll">
3626  <first ref="box31"/>
3627  <second ref="box32"/>
3628  <position name="posboxWallLHoll" x="0.451" y="0" z="0" unit="cm"/>
3629  </subtraction>
3630  <subtraction name="boxLargeWallL">
3631  <first ref="boxWallLHoll"/>
3632  <second ref="box33"/>
3633  <position name="posboxLargeWallL" x="5.701" y="0" z="0" unit="cm"/>
3634  </subtraction>
3635  <subtraction name="boxBarWallLI">
3636  <first ref="box36"/>
3637  <second ref="box37"/>
3638  <position name="posboxBarWallLI" x="0" y="3.5876" z="0" unit="cm"/>
3639  </subtraction>
3640  <subtraction name="boxBarWallL">
3641  <first ref="boxBarWallLI"/>
3642  <second ref="box37"/>
3643  <position name="posboxBarWallL" x="0" y="-3.5876" z="0" unit="cm"/>
3644  </subtraction>
3645  <union name="boxUniWallL">
3646  <first ref="boxLargeWallL"/>
3647  <second ref="boxBarCent"/>
3648  <position name="posboxUni3" x="-25.3" y="0" z="-17.2" unit="cm"/>
3649  <rotation name="rotUni3" x="0" y="0" z="90" unit="deg"/>
3650  </union>
3651  <union name="UnitWallL">
3652  <first ref="boxUniWallL"/>
3653  <second ref="boxBarWallL"/>
3654  <position name="posUniWallL" x="-16.3" y="0" z="-17.2" unit="cm"/>
3655  </union>
3656 EOF
3657 }
3658 
3659  print ENCL <<EOF;
3660 </solids>
3661 EOF
3662 
3663 
3664 
3665 # Detector enclosure structure
3666  print ENCL <<EOF;
3667 <structure>
3668  <volume name="volBeamWinFoam">
3669  <materialref ref="ProtoDUNEBWFoam"/>
3670  <solidref ref="BeamWindowFoam"/>
3671  </volume>
3672  <volume name="volBeamWinGlassWool">
3673  <materialref ref="GlassWool"/>
3674  <solidref ref="BeamWindowGlassWool"/>
3675  </volume>
3676  <volume name="volBeamPipeVac">
3677  <materialref ref="Vacuum"/>
3678  <solidref ref="BeamPipeVacuum"/>
3679  </volume>
3680  <volume name="volBeamPipe">
3681  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3682  <solidref ref="BeamPipe"/>
3683  <physvol>
3684  <volumeref ref="volBeamPipeVac"/>
3685  <positionref ref="posCenter"/>
3686  </physvol>
3687  </volume>
3688  <volume name="volFoamPadding">
3689  <materialref ref="ProtoDUNEFoam"/>
3690  <solidref ref="FoamPadding"/>
3691  </volume>
3692  <volume name="volSteelPlate">
3693  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3694  <solidref ref="SteelPlate"/>
3695  </volume>
3696  <volume name="volSurrConcrete">
3697  <materialref ref="Concrete"/>
3698  <solidref ref="SurrConcrete"/>
3699  </volume>
3700 EOF
3701 
3702 
3703  print ENCL <<EOF;
3704  <volume name="volAuxDetSensitiveCRTPaddle">
3705  <materialref ref="G4_POLYSTYRENE"/>
3706  <solidref ref="CRTPaddle"/>
3707  <auxiliary auxtype="SensDet" auxvalue="AuxDet"/>
3708  <auxiliary auxtype="Solid" auxvalue="True"/>
3709  </volume>
3710 EOF
3711 
3712 
3713 for($imod=0 ; $imod<16 ; $imod++){
3714  $modnum = $imod + 1;
3715  print ENCL <<EOF;
3716  <volume name="volAuxDetCRTModuleU$modnum">
3717  <materialref ref="Air"/>
3718  <solidref ref="CRTModule"/>
3719 EOF
3720 for($i=0 ; $i<32 ; $i++){
3721  $paddle_x1 = - $CRTModWidth/2 + $CRTPaddleWidth*($i + 0.5);
3722  $paddle_x2 = - $CRTModWidth/2 + $CRTPaddleWidth*($i + 1);
3723  $paddle_y1 = $CRTPaddleHeight/2;
3724  $paddle_y2 = - $CRTPaddleHeight/2;
3725  $paddle_z = 0;
3726  $padnum1 = 2*$i+(($modnum-1)*64);
3727  $padnum2 = (2*$i+1)+(($modnum-1)*64);
3728  $padnum1id = 2*$i+1;
3729  $padnum2id = 2*$i+2;
3730  $paddleid1 = "$padnum1id"."U$modnum";
3731  $paddleid2 = "$padnum2id"."U$modnum";
3732  print ENCL <<EOF;
3733  <physvol name="CRTPaddle$paddleid1" copynumber="$padnum1">
3734  <volumeref ref="volAuxDetSensitiveCRTPaddle"/>
3735  <position name="posCRTPaddleSensitive$paddleid1" unit="cm"
3736  x="$paddle_x1"
3737  y="$paddle_y1"
3738  z="$paddle_z"/>
3739  <rotationref ref="rIdentity"/>
3740  </physvol>
3741  <physvol name="CRTPaddle$paddleid2" copynumber="$padnum2">
3742  <volumeref ref="volAuxDetSensitiveCRTPaddle"/>
3743  <position name="posCRTPaddleSensitive$paddleid2" unit="cm"
3744  x="$paddle_x2"
3745  y="$paddle_y2"
3746  z="$paddle_z"/>
3747  <rotationref ref="rIdentity"/>
3748  </physvol>
3749 EOF
3750 }
3751  print ENCL <<EOF;
3752  </volume>
3753 EOF
3754 }
3755 
3756 
3757 
3758 
3759 for($imod=0 ; $imod<16 ; $imod++){
3760  $modnum = $imod + 1;
3761 
3762  print ENCL <<EOF;
3763  <volume name="volAuxDetCRTModuleD$modnum">
3764  <materialref ref="Air"/>
3765  <solidref ref="CRTModule"/>
3766 EOF
3767 for($i=0 ; $i<32 ; $i++){
3768  $paddle_x1 = - $CRTModWidth/2 + $CRTPaddleWidth*($i + 0.5);
3769  $paddle_x2 = - $CRTModWidth/2 + $CRTPaddleWidth*($i + 1);
3770  $paddle_y1 = $CRTPaddleHeight/2;
3771  $paddle_y2 = - $CRTPaddleHeight/2;
3772  $paddle_z = 0;
3773  $padnum1 = 2*$i+64*(($modnum-1)+16);
3774  $padnum2 = (2*$i+1)+64*(($modnum-1)+16);
3775  $padnum1id = 2*$i+1;
3776  $padnum2id = 2*$i+2;
3777  $paddleid1 = "$padnum1id"."D$modnum";
3778  $paddleid2 = "$padnum2id"."D$modnum";
3779  print ENCL <<EOF;
3780  <physvol name="CRTPaddle$paddleid1" copynumber="$padnum1">
3781  <volumeref ref="volAuxDetSensitiveCRTPaddle"/>
3782  <position name="posCRTPaddleSensitive$paddleid1" unit="cm"
3783  x="$paddle_x1"
3784  y="$paddle_y1"
3785  z="$paddle_z"/>
3786  <rotationref ref="rIdentity"/>
3787  </physvol>
3788  <physvol name="CRTPaddle$paddleid2" copynumber="$padnum2">
3789  <volumeref ref="volAuxDetSensitiveCRTPaddle"/>
3790  <position name="posCRTPaddleSensitive$paddleid2" unit="cm"
3791  x="$paddle_x2"
3792  y="$paddle_y2"
3793  z="$paddle_z"/>
3794  <rotationref ref="rIdentity"/>
3795  </physvol>
3796 EOF
3797 }
3798  print ENCL <<EOF;
3799  </volume>
3800 EOF
3801 }
3802 # for($i=0 ; $i<5 ; $i++){
3803 # for($j=0 ; $j<5 ; $j++){
3804 # $suffix = "$i"."-$j";
3805 #
3806 
3807 if($simpleStSu == 0)
3808 {
3809 print ENCL <<EOF;
3810  <volume name="volUnitCent">
3811  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3812  <solidref ref="UnitCent"/>
3813  </volume>
3814  <volume name="volUnitTop">
3815  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3816  <solidref ref="UnitTop"/>
3817  </volume>
3818  <volume name="volUnitWallS">
3819  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3820  <solidref ref="UnitWallU"/>
3821  </volume>
3822  <volume name="volUnitWallL">
3823  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3824  <solidref ref="UnitWallL"/>
3825  </volume>
3826 EOF
3827 
3828 #}}
3829 
3830 print ENCL <<EOF;
3831  <volume name="volSteelSupport_TB">
3832  <materialref ref="Air"/>
3833  <solidref ref="boxCryoTop"/>
3834 EOF
3835 
3836  for($i=0 ; $i<5 ; $i++){
3837  for($j=0 ; $j<5 ; $j++){
3838  $xupos = -320+160*$i;
3839  $yupos = -320+160*$j;
3840  $stsuind = "$i"."-$j";
3841 print ENCL <<EOF;
3842  <physvol name="volUnitTBCent_$stsuind">
3843  <volumeref ref="volUnitCent"/>
3844  <position name="posUnitTBCent_$stsuind" x="$xupos" y="$yupos" z="0" unit="cm"/>
3845  </physvol>
3846 EOF
3847 }
3848 print ENCL <<EOF;
3849  <physvol name="volUnitTBE_$i">
3850  <volumeref ref="volUnitTop"/>
3851  <position name="posUnitTBE_$i" x="454.2" y="$xupos" z="0" unit="cm"/>
3852  </physvol>
3853  <physvol name="volUnitTBS_$i">
3854  <volumeref ref="volUnitTop"/>
3855  <position name="posUnitTBS_$i" x="$xupos" y="454.2" z="0" unit="cm"/>
3856  <rotation name="rotUnitTBS_$i" x="0" y="0" z="-90" unit="deg"/>
3857  </physvol>
3858  <physvol name="volUnitTBW_$i">
3859  <volumeref ref="volUnitTop"/>
3860  <position name="posUnitTBW_$i" x="-454.2" y="$xupos" z="0" unit="cm"/>
3861  <rotation name="rotUnitTBW_$i" x="0" y="0" z="-180" unit="deg"/>
3862  </physvol>
3863  <physvol name="volUnitTBN_$i">
3864  <volumeref ref="volUnitTop"/>
3865  <position name="posUnitTBN_$i" x="$xupos" y="-454.2" z="0" unit="cm"/>
3866  <rotation name="rotUnitTBN_$i" x="0" y="0" z="-270" unit="deg"/>
3867  </physvol>
3868 EOF
3869 
3870 }
3871 
3872  print ENCL <<EOF;
3873  </volume>
3874 EOF
3875 
3876 print ENCL <<EOF;
3877  <volume name="volSteelSupport_WS">
3878  <materialref ref="Air"/>
3879  <solidref ref="boxCryoWallSm"/>
3880 EOF
3881 
3882  for($i=0 ; $i<5 ; $i++){
3883  for($j=0 ; $j<5 ; $j++){
3884  $xupos = -320+160*$i;
3885  $yupos = -320+160*$j;
3886  $stsuind = "$i"."-$j";
3887 print ENCL <<EOF;
3888  <physvol name="volUnitWSCent_$stsuind">
3889  <volumeref ref="volUnitCent"/>
3890  <position name="posUnitWSCent_$stsuind" x="$xupos" y="$yupos" z="0" unit="cm"/>
3891  </physvol>
3892 EOF
3893 }
3894 print ENCL <<EOF;
3895  <physvol name="volUnitWSE_$i">
3896  <volumeref ref="volUnitTop"/>
3897  <position name="posUnitWSE_$i" x="454.2" y="$xupos" z="0" unit="cm"/>
3898  </physvol>
3899  <physvol name="volUnitWSS_$i">
3900  <volumeref ref="volUnitWallS"/>
3901  <position name="posUnitWSS_$i" x="$xupos" y="468.9" z="0" unit="cm"/>
3902  <rotation name="rotUnitWSS_$i" x="0" y="0" z="-90" unit="deg"/>
3903  </physvol>
3904  <physvol name="volUnitWSW_$i">
3905  <volumeref ref="volUnitTop"/>
3906  <position name="posUnitWSW_$i" x="-454.2" y="$xupos" z="0" unit="cm"/>
3907  <rotation name="rotUnitWSW_$i" x="0" y="0" z="-180" unit="deg"/>
3908  </physvol>
3909  <physvol name="volUnitWSN_$i">
3910  <volumeref ref="volUnitWallS"/>
3911  <position name="posUnitWSN_$i" x="$xupos" y="-468.9" z="0" unit="cm"/>
3912  <rotation name="rotUnitWSN_$i" x="0" y="0" z="-270" unit="deg"/>
3913  </physvol>
3914 EOF
3915 
3916 }
3917  print ENCL <<EOF;
3918  </volume>
3919 EOF
3920 
3921 print ENCL <<EOF;
3922  <volume name="volSteelSupport_US">
3923  <materialref ref="Air"/>
3924  <solidref ref="boxCryoWallSmUS"/>
3925 EOF
3926 
3927  for($i=0 ; $i<5 ; $i++){
3928  for($j=0 ; $j<5 ; $j++){
3929  $xupos = -320+160*$i;
3930  $yupos = -320+160*$j;
3931  $stsuind = "$i"."-$j";
3932 print ENCL <<EOF;
3933 
3934  <physvol name="volUnitUSCent_$stsuind">
3935  <volumeref ref="volUnitCent"/>
3936  <position name="posUnitUSCent_$stsuind" x="$xupos" y="$yupos" z="0" unit="cm"/>
3937  <rotationref ref="rPlus180AboutY"/>
3938  </physvol>
3939 EOF
3940 }
3941 print ENCL <<EOF;
3942  <physvol name="volUnitUSE_$i">
3943  <volumeref ref="volUnitTop"/>
3944  <position name="posUnitUSE_$i" x="454.2" y="$xupos" z="0" unit="cm"/>
3945  <rotationref ref="rPlus180AboutX"/>
3946  </physvol>
3947  <physvol name="volUnitUSS_$i">
3948  <volumeref ref="volUnitWallS"/>
3949  <position name="posUnitUSS_$i" x="$xupos" y="468.9" z="0" unit="cm"/>
3950  <rotation name="rotUnitUSS_$i" x="0" y="180" z="-90" unit="deg"/>
3951  </physvol>
3952  <physvol name="volUnitUSW_$i">
3953  <volumeref ref="volUnitTop"/>
3954  <position name="posUnitUSW_$i" x="-454.2" y="$xupos" z="0" unit="cm"/>
3955  <rotation name="rotUnitUSW_$i" x="180" y="0" z="-180" unit="deg"/>
3956  </physvol>
3957  <physvol name="volUnitUSN_$i">
3958  <volumeref ref="volUnitWallS"/>
3959  <position name="posUnitUSN_$i" x="$xupos" y="-468.9" z="0" unit="cm"/>
3960  <rotation name="rotUnitUSN_$i" x="0" y="180" z="-270" unit="deg"/>
3961  </physvol>
3962 
3963 EOF
3964 
3965 }
3966  print ENCL <<EOF;
3967  </volume>
3968 EOF
3969 
3970 
3971 print ENCL <<EOF;
3972  <volume name="volSteelSupport_LR">
3973  <materialref ref="Air"/>
3974  <solidref ref="boxCryoWallLg"/>
3975 EOF
3976 
3977  for($i=0 ; $i<5 ; $i++){
3978  for($j=0 ; $j<5 ; $j++){
3979  $xupos = -320+160*$i;
3980  $yupos = -320+160*$j;
3981  $stsuind = "$i"."-$j";
3982 print ENCL <<EOF;
3983  <physvol name="volUnitLRCent_$stsuind">
3984  <volumeref ref="volUnitCent"/>
3985  <position name="posUnitLRCent_$stsuind" x="$xupos" y="$yupos" z="0" unit="cm"/>
3986  </physvol>
3987 EOF
3988 }
3989 print ENCL <<EOF;
3990  <physvol name="volUnitLRE_$i">
3991  <volumeref ref="volUnitWallL"/>
3992  <position name="posUnitLRE_$i" x="485.1" y="$xupos" z="0" unit="cm"/>
3993  </physvol>
3994  <physvol name="volUnitLRS_$i">
3995  <volumeref ref="volUnitWallS"/>
3996  <position name="posUnitLRS_$i" x="$xupos" y="468.9" z="0" unit="cm"/>
3997  <rotation name="rotUnitLRS_$i" x="0" y="0" z="-90" unit="deg"/>
3998  </physvol>
3999  <physvol name="volUnitLRW_$i">
4000  <volumeref ref="volUnitWallL"/>
4001  <position name="posUnitLRW_$i" x="-485.1" y="$xupos" z="0" unit="cm"/>
4002  <rotation name="rotUnitLRW_$i" x="0" y="0" z="-180" unit="deg"/>
4003  </physvol>
4004  <physvol name="volUnitLRN_$i">
4005  <volumeref ref="volUnitWallS"/>
4006  <position name="posUnitLRN_$i" x="$xupos" y="-468.9" z="0" unit="cm"/>
4007  <rotation name="rotUnitLRN_$i" x="0" y="0" z="-270" unit="deg"/>
4008  </physvol>
4009 EOF
4010 
4011 }
4012  print ENCL <<EOF;
4013  </volume>
4014 EOF
4015 } # if(simpleStSu == 0)
4016 elsif($simpleStSu==1){
4017 print ENCL <<EOF;
4018  <volume name="volSteelSupportMod">
4019  <materialref ref="AirSteelMixture"/>
4020  <solidref ref="SteelSupport"/>
4021  </volume>
4022 EOF
4023 }
4024 
4025  print ENCL <<EOF;
4026 
4027  <volume name="volDetEnclosure">
4028  <materialref ref="Air"/>
4029  <solidref ref="DetEnclosure"/>
4030 
4031 EOF
4032 if($simpleStSu==1){
4033  print ENCL <<EOF;
4034  <physvol>
4035  <volumeref ref="volSteelSupportMod"/>
4036  <positionref ref="posCryoInDetEnc"/>
4037  </physvol>
4038 EOF
4039 }
4040 elsif ($simpleStSu==0)
4041 {
4042  $stsuTop_y = 506.9 + $posCryoInDetEnc_y;
4043  $stsuBot_y = -506.9 + $posCryoInDetEnc_y;
4044  $stsuOther_y = $posCryoInDetEnc_y;
4045 
4046  print ENCL <<EOF;
4047 
4048  <physvol name="volSteelSupport_Top">
4049  <volumeref ref="volSteelSupport_TB"/>
4050  <position name="posSteelSupport_Top" x="0" y="$stsuTop_y" z="0" unit="cm"/>
4051  <rotation name="rotSteelSupport_Top" x="90" y="0" z="0" unit="deg"/>
4052  </physvol>
4053  <physvol name="volSteelSupport_Bottom">
4054  <volumeref ref="volSteelSupport_TB"/>
4055  <position name="posSteelSupport_Bottom" x="0" y="$stsuBot_y" z="0" unit="cm"/>
4056  <rotation name="rotSteelSupport_Bottom" x="-90" y="0" z="0" unit="deg"/>
4057  </physvol>
4058  <physvol>
4059  <volumeref ref="volSteelSupport_US"/>
4060  <position name="posSteelSupport_US" x="0" y="$stsuOther_y" z="-539.3" unit="cm"/>
4061  </physvol>
4062  <physvol name="volSteelSupport_DS">
4063  <volumeref ref="volSteelSupport_WS"/>
4064  <position name="posSteelSupport_DS" x="0" y="$stsuOther_y" z="539.3" unit="cm"/>
4065  </physvol>
4066  <physvol name="volSteelSupport_LS">
4067  <volumeref ref="volSteelSupport_LR"/>
4068  <position name="posSteelSupport_LS" x="539.3" y="$stsuOther_y" z="0" unit="cm"/>
4069  <rotation name="rotSteelSupport_LS" x="0" y="-90" z="0" unit="deg"/>
4070  </physvol>
4071  <physvol name="volSteelSupport_RS">
4072  <volumeref ref="volSteelSupport_LR"/>
4073  <position name="posSteelSupport_RS" x="-539.3" y="$stsuOther_y" z="0" unit="cm"/>
4074  <rotation name="rotSteelSupport_RS" x="0" y="90" z="0" unit="deg"/>
4075  </physvol>
4076 
4077 EOF
4078 }
4079  print ENCL <<EOF;
4080 
4081  <physvol>
4082  <volumeref ref="volFoamPadding"/>
4083  <positionref ref="posCryoInDetEnc"/>
4084  </physvol>
4085  <physvol>
4086  <volumeref ref="volSteelPlate"/>
4087  <positionref ref="posCryoInDetEnc"/>
4088  </physvol>
4089  <physvol>
4090  <volumeref ref="volBeamWinFoam"/>
4091  <position name="posBeamWinFoam" unit="cm"
4092  x="$BeamWFo_x"
4093  y="$BeamWFo_y"
4094  z="$BeamWFo_z"/>
4095  <rotationref ref="rBeamWRev3"/>
4096  </physvol>
4097  <physvol>
4098  <volumeref ref="volBeamWinGlassWool"/>
4099  <position name="posBeamWinGlassWool" unit="cm"
4100  x="$BeamWGl_x"
4101  y="$BeamWGl_y"
4102  z="$BeamWGl_z"/>
4103  <rotationref ref="rBeamWRev3"/>
4104  </physvol>
4105  <physvol>
4106  <volumeref ref="volBeamPipe"/>
4107  <position name="posBeamPipe" unit="cm"
4108  x="$BeamWVa_x"
4109  y="$BeamWVa_y"
4110  z="$BeamWVa_z"/>
4111  <rotationref ref="rBeamWRev3"/>
4112  </physvol>
4113  <physvol>
4114  <volumeref ref="volCryostat"/>
4115  <positionref ref="posCryoInDetEnc"/>
4116  </physvol>
4117  <physvol>
4118  <volumeref ref="volSurrConcrete"/>
4119  <position name="posSurrConcrete" unit="cm"
4120  x="0"
4121  y="$posSurrConcrete_y"
4122  z="0"/>
4123  </physvol>
4124 EOF
4125 
4126  for($i=0 ; $i<16 ; $i++){
4127  $modnum = $i + 1;
4128  $modid = "U$modnum";
4129 
4130 print ENCL <<EOF;
4131  <physvol>
4132  <volumeref ref="volAuxDetCRTModule$modid"/>
4133  <position name="posvolAuxDetCRTModule$modid" unit="cm"
4134  x="$posCRTUS_x[$i]"
4135  y="$posCRTUS_y[$i]"
4136  z="$posCRTUS_z[$i]"/>
4137  <rotationref ref="$posCRTUS_rot[$i]"/>
4138  </physvol>
4139 EOF
4140  }
4141 
4142  for($i=0 ; $i<16 ; $i++){
4143  $modnum = $i + 1;
4144  $modid = "D$modnum";
4145 
4146 print ENCL <<EOF;
4147  <physvol>
4148  <volumeref ref="volAuxDetCRTModule$modid"/>
4149  <position name="posvolAuxDetCRTModule$modid" unit="cm"
4150  x="$posCRTDS_x[$i]"
4151  y="$posCRTDS_y[$i]"
4152  z="$posCRTDS_z[$i]"/>
4153  <rotationref ref="$posCRTDS_rot[$i]"/>
4154  </physvol>
4155 EOF
4156  }
4157 
4158 print ENCL <<EOF;
4159 
4160  </volume>
4161 
4162 </structure>
4163 </gdml>
4164 EOF
4165 
4166 close(ENCL);
4167 }
4168 
4169 
4170 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4171 #+++++++++++++++++++++++++++++++++++++++ gen_World +++++++++++++++++++++++++++++++++++++++
4172 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4173 
4174 sub gen_World()
4175 {
4176 
4177 # Create the WORLD fragment file name,
4178 # add file to list of output GDML fragments,
4179 # and open it
4180  $WORLD = "subfile_protodune_v7_World" . $suffix . ".gdml";
4181  push (@gdmlFiles, $WORLD);
4182  $WORLD = ">" . $WORLD;
4183  open(WORLD) or die("Could not open file $WORLD for writing");
4184 
4185 
4186 # The standard XML prefix and starting the gdml
4187  print WORLD <<EOF;
4188 <?xml version='1.0'?>
4189 <gdml>
4190 EOF
4191 
4192 
4193 # All the World solids.
4194 $dimWorld_x = $DetEncWidth+2*$RockThickness;
4195 $dimWorld_y = $DetEncHeight+2*$RockThickness;
4196 $dimWorld_z = $DetEncLength+2*$RockThickness;
4197 
4198 print WORLD <<EOF;
4199 <solids>
4200  <box name="World" lunit="cm"
4201  x="$dimWorld_x"
4202  y="$dimWorld_y"
4203  z="$dimWorld_z"/>
4204 </solids>
4205 EOF
4206 
4207 # World structure
4208 print WORLD <<EOF;
4209 <structure>
4210  <volume name="volWorld" >
4211  <materialref ref="Air"/>
4212  <solidref ref="World"/>
4213 
4214  <physvol>
4215  <volumeref ref="volDetEnclosure"/>
4216  <position name="posDetEnclosure" unit="cm" x="$OriginXSet" y="$OriginYSet" z="$OriginZSet"/>
4217  </physvol>
4218 
4219  </volume>
4220 </structure>
4221 </gdml>
4222 EOF
4223 
4224 # make_gdml.pl will take care of <setup/>
4225 
4226 close(WORLD);
4227 }
4228 
4229 
4230 
4231 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4232 #++++++++++++++++++++++++++++++++++++ write_fragments ++++++++++++++++++++++++++++++++++++
4233 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4234 
4235 sub write_fragments()
4236 {
4237  # This subroutine creates an XML file that summarizes the the subfiles output
4238  # by the other sub routines - it is the input file for make_gdml.pl which will
4239  # give the final desired GDML file. Specify its name with the output option.
4240  # (you can change the name when running make_gdml)
4241 
4242  # This code is taken straigh from the similar MicroBooNE generate script, Thank you.
4243 
4244  if ( ! defined $output )
4245  {
4246  $output = "-"; # write to STDOUT
4247  }
4248 
4249  # Set up the output file.
4250  $OUTPUT = ">" . $output;
4251  open(OUTPUT) or die("Could not open file $OUTPUT");
4252 
4253  print OUTPUT <<EOF;
4254 <?xml version='1.0'?>
4255 
4256 <!-- Input to Geometry/gdml/make_gdml.pl; define the GDML fragments
4257  that will be zipped together to create a detector description.
4258  -->
4259 
4260 <config>
4261 
4262  <constantfiles>
4263 
4264  <!-- These files contain GDML <constant></constant>
4265  blocks. They are read in separately, so they can be
4266  interpreted into the remaining GDML. See make_gdml.pl for
4267  more information.
4268  -->
4269 
4270 EOF
4271 
4272  foreach $filename (@defFiles)
4273  {
4274  print OUTPUT <<EOF;
4275  <filename> $filename </filename>
4276 EOF
4277  }
4278 
4279  print OUTPUT <<EOF;
4280 
4281  </constantfiles>
4282 
4283  <gdmlfiles>
4284 
4285  <!-- The GDML file fragments to be zipped together. -->
4286 
4287 EOF
4288 
4289  foreach $filename (@gdmlFiles)
4290  {
4291  print OUTPUT <<EOF;
4292  <filename> $filename </filename>
4293 EOF
4294  }
4295 
4296  print OUTPUT <<EOF;
4297 
4298  </gdmlfiles>
4299 
4300 </config>
4301 EOF
4302 
4303  close(OUTPUT);
4304 }
4305 
4306 
4307 
4308 # run the sub routines that generate the fragments
4309 
4310 gen_Extend(); #generates the GDML color extension for the refactored geometry
4311 
4312 gen_Define(); # generates definitions at beginning of GDML
4313 gen_Materials(); # generates materials to be used
4314 
4315 
4316  gen_TPC( $TPCInner_x, $TPC_y, $TPC_z, 'Inner');
4317  gen_TPC( $TPCOuter_x, $TPC_y, $TPC_z, 'Outer');
4318 
4319 close $wout;
4320 
4321 gen_Cryostat(); # places (2*nAPAWide x nAPAHigh x nAPALong) volTPC,
4322  # half rotated 180 about Y
4323 gen_Enclosure(); # places two cryostats and concrete volumes
4324 
4325 gen_World(); # places the enclosure among DUSEL Rock
4326 
4327 
4328 write_fragments(); # writes the XML input for make_gdml.pl
4329  # which zips together the final GDML
4330 exit;