generate_refactored_protodune-sp_v8.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 $LightPaddleIU_x = 0.863;
850 $LightPaddleIU_y = 8.23;
851 $LightPaddleIU_z = 200.074;
852 $LightPaddleMIT_x = 0.551;
853 $LightPaddleMIT_y = 8.37;
854 $LightPaddleMIT_z = 203.925;
855 $LightPaddle_z = $APAFrame_z - 2*$APAFrameYSide_z; #Length of the APA Frame --> used for rails
856 $nLightPaddlesPerAPA = 10; # 10, or 20 for double coverage (for now)
857 $PaddleYInterval = 59.2;
858 $FrameToPaddleSpace = 30.412;
859 $SiPM_z = 0;
860 
861 $LightPaddleIUOut_x = 0.86; #IU Rail
862 $LightPaddleMITOut_x = 0.55; #MIT Rail
863 $LightPaddleIUOut_y = 8.47; #IU Rail
864 $LightPaddleMITOut_y = 8.61; #MIT Rail
865 $LightPaddleOut_z = $LightPaddle_z;
866 $list_sub_paddle[0]=$APACenter_y-$APAphys_y/2+$FrameToPaddleSpace+$LightPaddle_y/2;
867 for($list=1; $list<10; $list++){
868 $list_sub_paddle[$list]=$list_pos[$i-1]+$LightPaddle_y/2+$PaddleYInterval;
869 }
870 
871 # $PaddleYInterval is defined so that the center-to-center distance in the
872 # y direction between paddles is uniform between vertically stacked APAs.
873 # $FrameToPaddleSpace is from the BOTTOM of the APA frame (4" in y direction)
874 # to the CENTER of a paddle, including the 4" part of the frame. This variable's
875 # primary purpose is to position the lowest paddle in each APA.
876 
877 
878 ####################################################################
879 ######################## ARAPUCA Dimensions ########################
880 
881 $ArapucaOut_x = 16.0;
882 $ArapucaOut_y = 96.0;
883 $ArapucaOut_z = 10.0*$LightPaddle_z;
884 $ArapucaIn_x = 15.0;
885 $ArapucaIn_y = 80.0;
886 $ArapucaIn_z = 100.0;
887 $ArapucaAcceptanceWindow_x =1.0;
888 $ArapucaAcceptanceWindow_y =80.0;
889 $ArapucaAcceptanceWindow_z =100.0;
890 $pos_subtraction_arapuca_x = 2.0;
891 $gapCenterLeft_arapuca_z = 50.0;#if not simmetrical, positioning of windows for odd APAs needs to change
892 $gapCenterRight_arapuca_z = 100.0-$gapCenterLeft_arapuca_z;
893 $nAraAPA1 = 0;
894 $nAraAPA2 = 3;
895 $nSlotAra1 = 6;
896 $nSlotAra2 = 4;
897 
898 $list_pos[0]=-$gapCenterLeft_arapuca_z-0.5*$ArapucaIn_z;
899 for($list=1; $list<8; $list++){
900 $list_pos[$list]=$list_pos[$i-1]-1.0*$ArapucaIn_z-2.0;
901 }
902 $list_pos[8]=$gapCenterRight_arapuca_z+0.5*$ArapucaIn_z;
903 for($list=9; $list<16; $list++){
904 $list_pos[$list]=$list_pos[$i-1]+$ArapucaIn_z+2.0;
905 }
906 
907 #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.
908 
909 
910 
911 
912 #+++++++++++++++++++++++++ End defining variables ++++++++++++++++++++++++++
913 
914 
915 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
916 #+++++++++++++++++++++++++++++++++++++++++ usage +++++++++++++++++++++++++++++++++++++++++
917 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
918 
919 sub usage()
920 {
921  print "Usage: $0 [-h|--help] [-o|--output <fragments-file>] [-s|--suffix <string>]\n";
922  print " if -o is omitted, output goes to STDOUT; <fragments-file> is input to make_gdml.pl\n";
923  print " -s <string> appends the string to the file names; useful for multiple detector versions\n";
924  print " -h prints this message, then quits\n";
925 }
926 
927 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
928 #++++++++++++++++++++++++++++++++++++++ gen_Extend +++++++++++++++++++++++++++++++++++++++
929 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
930 
931 sub gen_Extend()
932 {
933 
934 # Create the <define> fragment file name,
935 # add file to list of fragments,
936 # and open it
937  $DEF = "subfile_protodune_v7_Ext" . $suffix . ".gdml";
938  push (@gdmlFiles, $DEF);
939  $DEF = ">" . $DEF;
940  open(DEF) or die("Could not open file $DEF for writing");
941 
942 print DEF <<EOF;
943 <?xml version='1.0'?>
944 <gdml>
945 <extension>
946  <color name="magenta" R="0.0" G="1.0" B="0.0" A="1.0" />
947  <color name="green" R="0.0" G="1.0" B="0.0" A="1.0" />
948  <color name="red" R="1.0" G="0.0" B="0.0" A="1.0" />
949  <color name="blue" R="0.0" G="0.0" B="1.0" A="1.0" />
950  <color name="yellow" R="1.0" G="1.0" B="0.0" A="1.0" />
951 </extension>
952 </gdml>
953 EOF
954  close (DEF);
955 }
956 
957 
958 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
959 #++++++++++++++++++++++++++++++++++++++ gen_Define +++++++++++++++++++++++++++++++++++++++
960 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
961 
962 sub gen_Define()
963 {
964 
965 # Create the <define> fragment file name,
966 # add file to list of fragments,
967 # and open it
968  $DEF = "subfile_protodune_v7_Def" . $suffix . ".gdml";
969  push (@gdmlFiles, $DEF);
970  $DEF = ">" . $DEF;
971  open(DEF) or die("Could not open file $DEF for writing");
972 
973 $UWireAngle = 90-$UAngle;
974 $VWireAngle = 90+$VAngle;
975 print DEF <<EOF;
976 <?xml version='1.0'?>
977 <gdml>
978 <define>
979 
980 <!--
981 
982 
983 
984 -->
985 
986  <position name="posCryoInDetEnc" unit="cm" x="0" y="$posCryoInDetEnc_y" z="0"/>
987  <position name="posCenter" unit="cm" x="0" y="0" z="0"/>
988  <position name="posBeamWAr3" unit="cm" x="$BeamPlug_x" y="$BeamPlug_y" z="$BeamPlug_z"/>
989  <rotation name="rPlus90AboutX" unit="deg" x="90" y="0" z="0"/>
990  <rotation name="rMinus90AboutY" unit="deg" x="0" y="270" z="0"/>
991  <rotation name="rMinus90AboutYMinus90AboutX" unit="deg" x="270" y="270" z="0"/>
992  <rotation name="rPlusUAngleAboutX" unit="deg" x="$UWireAngle" y="0" z="0"/>
993  <rotation name="rPlusVAngleAboutX" unit="deg" x="$VWireAngle" y="0" z="0"/>
994  <rotation name="rPlus180AboutX" unit="deg" x="180" y="0" z="0"/>
995  <rotation name="rPlus180AboutY" unit="deg" x="0" y="180" z="0"/>
996  <rotation name="rPlus180AboutZ" unit="deg" x="0" y="0" z="180"/>
997  <rotation name="rPlus180AboutXPlus180AboutY" unit="deg" x="180" y="180" z="0"/>
998  <rotation name="rPlus90AboutXPlus90AboutZ" unit="deg" x="90" y="0" z="90"/>
999  <rotation name="rPlus180AboutXPlus180AboutZ" unit="deg" x="180" y="0" z="180"/>
1000  <rotation name="rIdentity" unit="deg" x="0" y="0" z="0"/>
1001  <rotation name="rBeamW2" unit="deg" x="0" y="-$BeamTheta2Deg" z="$BeamPhi2Deg"/>
1002  <rotation name="rBeamWRev2" unit="deg" x="-11.342" y="8.03118195044" z="-55.1415281209"/>
1003  <rotation name="rBeamW3" unit="deg" x="0" y="-$BeamTheta3Deg" z="$BeamPhi3Deg"/>
1004  <rotation name="rBeamWRev3" unit="deg" x="-11.342" y="11.6190450403" z="-44.8829268772"/>
1005  <position name="posArapucaSub0" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[0]]}"/>
1006  <position name="posArapucaSub1" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[1]]}"/>
1007  <position name="posArapucaSub2" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[2]]}"/>
1008  <position name="posArapucaSub3" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[3]]}"/>
1009  <position name="posArapucaSub4" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[4]]}"/>
1010  <position name="posArapucaSub5" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[5]]}"/>
1011  <position name="posArapucaSub6" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[6]]}"/>
1012  <position name="posArapucaSub7" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[7]]}"/>
1013  <position name="posArapucaSub8" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[8]]}"/>
1014  <position name="posArapucaSub9" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[9]]}"/>
1015  <position name="posArapucaSub10" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[10]]}"/>
1016  <position name="posArapucaSub11" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[11]]}"/>
1017  <position name="posArapucaSub12" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[12]]}"/>
1018  <position name="posArapucaSub13" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[13]]}"/>
1019  <position name="posArapucaSub14" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[14]]}"/>
1020  <position name="posArapucaSub15" unit="mm" x="@{[$pos_subtraction_arapuca_x]}" y="0" z="@{[$list_pos[15]]}"/>
1021  <position name="posPaddleSub0" unit="mm" x="0" y="@{[$list_sub_paddle[0]]}" z="0"/>
1022  <position name="posPaddleSub1" unit="mm" x="0" y="@{[$list_sub_paddle[1]]}" z="0"/>
1023  <position name="posPaddleSub2" unit="mm" x="0" y="@{[$list_sub_paddle[2]]}" z="0"/>
1024  <position name="posPaddleSub3" unit="mm" x="0" y="@{[$list_sub_paddle[3]]}" z="0"/>
1025  <position name="posPaddleSub4" unit="mm" x="0" y="@{[$list_sub_paddle[4]]}" z="0"/>
1026  <position name="posPaddleSub5" unit="mm" x="0" y="@{[$list_sub_paddle[5]]}" z="0"/>
1027  <position name="posPaddleSub6" unit="mm" x="0" y="@{[$list_sub_paddle[6]]}" z="0"/>
1028  <position name="posPaddleSub7" unit="mm" x="0" y="@{[$list_sub_paddle[7]]}" z="0"/>
1029  <position name="posPaddleSub8" unit="mm" x="0" y="@{[$list_sub_paddle[8]]}" z="0"/>
1030  <position name="posPaddleSub9" unit="mm" x="0" y="@{[$list_sub_paddle[9]]}" z="0"/>
1031  <position name="posSubRailIU" unit="cm" x="0" y="0" z="-4.80425"/>
1032  <position name="posSubRailMIT" unit="cm" x="0" y="0" z="-2.87875"/>
1033 
1034 </define>
1035 </gdml>
1036 EOF
1037  close (DEF);
1038 }
1039 
1040 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1041 #+++++++++++++++++++++++++++++++++++++ gen_Materials +++++++++++++++++++++++++++++++++++++
1042 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1043 
1044 sub gen_Materials()
1045 {
1046 
1047 # Create the <materials> fragment file name,
1048 # add file to list of output GDML fragments,
1049 # and open it
1050  $MAT = "subfile_protodune_v7_Materials" . $suffix . ".gdml";
1051  push (@gdmlFiles, $MAT);
1052  $MAT = ">" . $MAT;
1053 
1054  open(MAT) or die("Could not open file $MAT for writing");
1055 
1056  # Add any materials special to this geometry by defining a mulitline string
1057  # and passing it to the gdmlMaterials::gen_Materials() function.
1058  $spdensity = 0.001205*(1-$FracVolOfSteel) + 7.9300*$FracVolOfSteel;
1059  $ssairfrac = (1-$FracMassOfSteel);
1060 my $asmix = <<EOF;
1061  <!-- preliminary values -->
1062  <material name="AirSteelMixture" formula="AirSteelMixture">
1063  <D value="$spdensity" unit="g/cm3"/>
1064  <fraction n="$FracMassOfSteel" ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
1065  <fraction n="$ssairfrac" ref="Air"/>
1066  </material>
1067 EOF
1068 
1069  # add the general materials used anywere
1070  print MAT gdmlMaterials::gen_Materials( $asmix );
1071 
1072  close(MAT);
1073 }
1074 
1075 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1076 #++++++++++++++++++++++++++++++++++++++++ gen_TPC ++++++++++++++++++++++++++++++++++++++++
1077 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1078 
1079 
1080 sub gen_TPC
1081 {
1082 
1083 # $_[0] = $TPC_x
1084 # $_[1] = $TPC_y
1085 # $_[2] = $TPC_z
1086 # $_[3] = 'name'
1087 
1088  my $TPCActive_x = $_[0] - 3*$APAWirePlaneSpacing -3*$TPCWirePlaneThickness;
1089  if( ($protoDune == 1) && ($_[3] eq 'Outer') ){
1090  $TPCActive_x = 3*($APAWirePlaneSpacing + $TPCWirePlaneThickness);
1091  }
1092  my $TPCActive_y = $_[1] - $APAGap_y/2 - $ReadoutBoardOverlap + $G10thickness; #TODO: make the Active height more accurate
1093  my $TPCActive_z = $_[2];
1094 
1095 
1096 #constructs everything inside volTPC, namely
1097 # (moving from left to right, or from +x to -x)
1098 # -volCPActive
1099 # -volTPCPlaneU: with wires angled from vertical slightly different than in V
1100 # -volTPCPlaneV: with wires angled from vertical slightly differently than in U
1101 # -volTPCPlaneX: with vertical wires
1102 
1103 
1104 # Create the TPC fragment file name,
1105 # add file to list of output GDML fragments,
1106 # and open it
1107  $TPC = "subfile_protodune_v7_TPC_${_[3]}" . $suffix . ".gdml";
1108  push (@gdmlFiles, $TPC);
1109  $TPC = ">" . $TPC;
1110  open(TPC) or die("Could not open file $TPC for writing");
1111 
1112 
1113 print $wout "\n\n\n----- Wires for $_[3] -----\n\n\n";
1114 
1115 
1116 # The standard XML prefix and starting the gdml
1117  print TPC <<EOF;
1118 <?xml version='1.0'?>
1119 <gdml>
1120 EOF
1121 
1122 
1123 # All the TPC solids save the wires.
1124  $uplact_y = $Uactive_y + $UVPlaneBoundNudge;
1125  $uplact_z = $Uactive_z + $UVPlaneBoundNudge;
1126  $vplact_y = $Vactive_y + $UVPlaneBoundNudge;
1127  $vplact_z = $Vactive_z + $UVPlaneBoundNudge;
1128 print TPC <<EOF;
1129 <solids>
1130  <box name="$_[3]" lunit="cm"
1131  x="$_[0]"
1132  y="$_[1]"
1133  z="$_[2]"/>
1134  <box name="${_[3]}UPlane" lunit="cm"
1135  x="$TPCWirePlaneThickness"
1136  y="$uplact_y"
1137  z="$uplact_z"/>
1138  <box name="${_[3]}VPlane" lunit="cm"
1139  x="$TPCWirePlaneThickness"
1140  y="$vplact_y"
1141  z="$vplact_z"/>
1142  <box name="${_[3]}ZPlane" lunit="cm"
1143  x="$TPCWirePlaneThickness"
1144  y="$Zactive_y"
1145  z="$Zactive_z"/>
1146 EOF
1147 #if(${_[3]} eq "Inner"){
1148 #print TPC <<EOF;
1149 # <box name="${_[3]}Active_NoCPA" lunit="cm"
1150 # x="$TPCActive_x"
1151 # y="$TPCActive_y"
1152 # z="$TPCActive_z"/>
1153 #EOF
1154 #}
1155 #else{
1156 print TPC <<EOF;
1157  <box name="${_[3]}Active" lunit="cm"
1158  x="$TPCActive_x"
1159  y="$TPCActive_y"
1160  z="$TPCActive_z"/>
1161 EOF
1162 #}
1163 
1164 
1165 #++++++++++++++++++++++++++++ Wire Solids ++++++++++++++++++++++++++++++
1166 $wirerad = 0.5*$TPCWireThickness;
1167 print TPC <<EOF;
1168 
1169  <tube name="${_[3]}WireVert"
1170  rmax="$wirerad"
1171  z="$Zactive_y"
1172  deltaphi="360"
1173  aunit="deg"
1174  lunit="cm"/>
1175 EOF
1176 
1177 # Set number of wires to default to zero, when $wires_on = 0, for a low memory
1178 # version. But if $wires_on = 1, calculate the number of wires on each side of each
1179 # plane to be used in the for loops
1180 
1181 my $NumberCornerUWires = 0;
1182 my $NumberSideUWires = 0;
1183 my $NumberCommonUWires = 0;
1184 my $NumberCornerVWires = 0;
1185 my $NumberSideVWires = 0;
1186 my $NumberCommonVWires = 0;
1187 my $NumberVerticalWires = 0;
1188 
1189 if ($wires_on == 1)
1190 {
1191  # Number of wires in one corner
1192 $NumberCornerUWires = int( $APAFrame_z/($UWirePitch/$CosUAngle) );
1193 
1194 $NumberCornerVWires = int( $APAFrame_z/($VWirePitch/$CosVAngle) );
1195 
1196 
1197  # Total number of wires touching one vertical (longer) side
1198  # Note that the total number of wires per plane is this + another set of corner wires
1199 $NumberSideUWires = int( $Uactive_y/$UWire_yint );
1200 if($Pitch3mmVersion==1){ $NumberSideUWires = $NumberSideUWires-1; }
1201 
1202 $NumberSideVWires = int( $Vactive_y/$VWire_yint );
1203 
1204  # Number of wires per side that aren't cut off by the corner
1205 $NumberCommonUWires = $NumberSideUWires - $NumberCornerUWires;
1206 
1207 $NumberCommonVWires = $NumberSideVWires - $NumberCornerVWires;
1208 
1209  # Number of wires on the vertical plane
1210  # Since APA Active z is defined in docdb 3383 to be distance
1211  # between outer vertical wires, + 1 since the floor of this
1212  # division will be one under, giving the amt of spaces, not wires
1213 $NumberVerticalWires = int( $Zactive_z/$XWirePitch ) + 1;
1214 #$NumberVerticalWires = 960;
1215 
1216 
1217 $nUchans = 2*$NumberCornerUWires;
1218 $nVchans = 2*$NumberCornerVWires;
1219 
1220 print $wout "$nUchans U channels\n";
1221 print $wout "$nVchans V channels\n";
1222 print $wout "$NumberVerticalWires Z channels per side\n";
1223 
1224 print $wout "$NumberCornerUWires U corner wires\n";
1225 print $wout "$NumberCommonUWires U common wires\n";
1226 print $wout "$NumberCornerVWires V corner wires\n";
1227 print $wout "$NumberCommonVWires V common wires\n";
1228 
1229 }
1230 
1231 # hard codeed number will be a factor determined from engineering spreadsheets on wire endpoints,
1232 # but since that won't exist for a while, use this number to avoid overlaps
1233 my $FirstUWireOffset = .55 + $G10thickness + 2*$G10thickness*$TanUAngle - $UWire_zint;
1234 my $FirstVWireOffset = .5; # doesnt include a G10 board in width
1235 
1236 if($Pitch3mmVersion==1){
1237  my $FirstUWireOffset = .15 + $G10thickness + 2*$G10thickness*$TanUAngle - $UWire_zint;
1238  my $FirstVWireOffset = .15; # doesnt include a G10 board in width
1239 }
1240 
1241 if($UVAngle45Option==1){$FirstVWireOffset = .7;}
1242 
1243 
1244 my $FirstTopUWire_yspan =
1245  $Uactive_y/2
1246  - ( - $Uactive_y/2
1247  + $FirstUWireOffset/$TanUAngle # walk us up to the first wire
1248  + $UWire_yint*($NumberSideUWires-1) # up to the top of the top common wire
1249  - $Uactive_z/$TanUAngle # back to the bottom of the top common wire
1250  + $UWire_yint); # nudge up to bottom of the first top corner wire
1251 
1252 my $FirstTopVWire_yspan =
1253  $Vactive_y/2
1254  - ( - $Vactive_y/2
1255  + $FirstVWireOffset/$TanVAngle # walk us up to the first wire
1256  + $VWire_yint*($NumberSideVWires-1) # up to the top of the top common wire
1257  - $Vactive_z/$TanVAngle # back to the bottom of the top common wire
1258  + $VWire_yint); # nudge up to bottom of the first top corner wire
1259 
1260 
1261 # The corner wires for the U plane
1262 if ($wires_on==1)
1263 {
1264  for ($i = 0; $i < $NumberCornerUWires; $i++)
1265  {
1266  $CornerUWireLength[$i] = ($FirstUWireOffset + $i*$UWire_zint)/$SinUAngle;
1267 
1268  print TPC <<EOF;
1269  <tube name="${_[3]}WireU$i"
1270  rmax="$wirerad"
1271  z="$CornerUWireLength[$i]"
1272  deltaphi="360"
1273  aunit="deg"
1274  lunit="cm"/>
1275 EOF
1276 
1277  }
1278 
1279  $CommonUWireLength = $Uactive_z/$SinUAngle;
1280 
1281  print TPC <<EOF;
1282  <tube name="${_[3]}WireUCommon"
1283  rmax="$wirerad"
1284  z="$CommonUWireLength"
1285  deltaphi="360"
1286  aunit="deg"
1287  lunit="cm"/>
1288 EOF
1289 
1290  for ($i = 0; $i < $NumberCornerUWires; $i++)
1291  {
1292 
1293  $TopCornerUWireLength[$i] = ($FirstTopUWire_yspan - $i*$UWire_yint)/$CosUAngle;
1294 
1295  $j = $i + $NumberSideUWires;
1296 
1297  print TPC <<EOF;
1298  <tube name="${_[3]}WireU$j"
1299  rmax="$wirerad"
1300  z="$TopCornerUWireLength[$i]"
1301  deltaphi="360"
1302  aunit="deg"
1303  lunit="cm"/>
1304 EOF
1305 
1306  }
1307 
1308 }
1309 
1310 
1311 # The corner wires for the V plane
1312 if ($wires_on==1)
1313 {
1314  for ($i = 0; $i < $NumberCornerVWires; ++$i)
1315  {
1316  $CornerVWireLength[$i] = ($FirstVWireOffset + $i*$VWire_zint)/$SinVAngle;
1317 
1318  print TPC <<EOF;
1319 
1320  <tube name="${_[3]}WireV$i"
1321  rmax="$wirerad"
1322  z="$CornerVWireLength[$i]"
1323  deltaphi="360"
1324  aunit="deg"
1325  lunit="cm"/>
1326 
1327 EOF
1328 
1329  }
1330 
1331  # The wire used many times in the middle of the V plane
1332  # Same subtraction as U common
1333 
1334  $CommonVWireLength = $Vactive_z/$SinVAngle;
1335 
1336  print TPC <<EOF;
1337  <tube name="${_[3]}WireVCommon"
1338  rmax="$wirerad"
1339  z="$CommonVWireLength"
1340  deltaphi="360"
1341  aunit="deg"
1342  lunit="cm"/>
1343 EOF
1344 
1345  for ($i = 0; $i < $NumberCornerVWires; $i++)
1346  {
1347 
1348  $TopCornerVWireLength[$i] = ($FirstTopVWire_yspan - $i*$VWire_yint)/$CosVAngle;
1349 
1350  $j = $i + $NumberSideVWires;
1351 
1352  print TPC <<EOF;
1353  <tube name="${_[3]}WireV$j"
1354  rmax="$wirerad"
1355  z="$TopCornerVWireLength[$i]"
1356  deltaphi="360"
1357  aunit="deg"
1358  lunit="cm"/>
1359 EOF
1360 
1361  }
1362 
1363 
1364 }
1365 
1366 # The active inner and active outer volumes are treated slightly differently
1367 my $subname = '';
1368 my $fieldStrength = '500';
1369 if ( ${_[3]} ne 'Inner' ){
1370  $fieldStrength = '0'; #assumption: no field in outer volume. This is currently unused in larg4
1371  $subname = ${_[3]}; #The volume name has to be "volTPCActive" for Inner
1372  #Can be anything for the outer volumes
1373 }
1374 
1375 # Begin structure and create the vertical wire logical volume
1376 # D.R. Add auxtypes utilized by larg4
1377 print TPC <<EOF;
1378 </solids>
1379 <structure>
1380  <volume name="volTPCActive${subname}">
1381  <materialref ref="LAr"/>
1382  <solidref ref="${_[3]}Active"/>
1383  <auxiliary auxtype="SensDet" auxvalue="SimEnergyDeposit"/>
1384  <auxiliary auxtype="StepLimit" auxunit="cm" auxvalue="0.47625*cm"/>
1385  <auxiliary auxtype="Efield" auxunit="V/cm" auxvalue="${fieldStrength}*V/cm"/>
1386  <colorref ref="blue"/>
1387  </volume>
1388 
1389 EOF
1390 
1391 
1392 if ($wires_on==1)
1393 {
1394  print TPC <<EOF;
1395  <volume name="volTPCWireVert${_[3]}">
1396  <materialref ref="Copper_Beryllium_alloy25"/>
1397  <solidref ref="${_[3]}WireVert"/>
1398  </volume>
1399 EOF
1400 
1401  # Corner U wires logical volumes
1402  for ($i = 0; $i < $NumberCornerUWires; ++$i)
1403  {
1404  print TPC <<EOF;
1405  <volume name="volTPCWireU$i${_[3]}">
1406  <materialref ref="Copper_Beryllium_alloy25"/>
1407  <solidref ref="${_[3]}WireU$i"/>
1408  </volume>
1409 EOF
1410  }
1411 
1412 
1413  # Top Corner U wires logical volumes
1414  for ($j = $NumberSideUWires; $j < $NumberSideUWires + $NumberCornerUWires; ++$j)
1415  {
1416  print TPC <<EOF;
1417  <volume name="volTPCWireU$j${_[3]}">
1418  <materialref ref="Copper_Beryllium_alloy25"/>
1419  <solidref ref="${_[3]}WireU$j"/>
1420  </volume>
1421 EOF
1422  }
1423 
1424 
1425  # Common U wire logical volume, referenced many times
1426  print TPC <<EOF;
1427  <volume name="volTPCWireUCommon${_[3]}">
1428  <materialref ref="Copper_Beryllium_alloy25"/>
1429  <solidref ref="${_[3]}WireUCommon"/>
1430  </volume>
1431 EOF
1432 
1433 
1434  # Corner V wires logical volumes
1435  for ($i = 0; $i < $NumberCornerVWires; ++$i)
1436  {
1437  print TPC <<EOF;
1438  <volume name="volTPCWireV$i${_[3]}">
1439  <materialref ref="Copper_Beryllium_alloy25"/>
1440  <solidref ref="${_[3]}WireV$i"/>
1441  </volume>
1442 EOF
1443 
1444  }
1445 
1446  # Top Corner V wires logical volumes
1447  for ($j = $NumberSideVWires; $j < $NumberSideVWires + $NumberCornerVWires; ++$j)
1448  {
1449  print TPC <<EOF;
1450  <volume name="volTPCWireV$j${_[3]}">
1451  <materialref ref="Copper_Beryllium_alloy25"/>
1452  <solidref ref="${_[3]}WireV$j"/>
1453  </volume>
1454 EOF
1455  }
1456 
1457  # Common V wire logical volume, referenced many times
1458  print TPC <<EOF;
1459  <volume name="volTPCWireVCommon${_[3]}">
1460  <materialref ref="Copper_Beryllium_alloy25"/>
1461  <solidref ref="${_[3]}WireVCommon"/>
1462  </volume>
1463 EOF
1464 
1465 }
1466 
1467 
1468 my $lastYpos = 0;
1469 my $lastZpos = 0;
1470 
1471 
1472 #+++++++++++++++++++++++++ Position physical wires ++++++++++++++++++++++++++
1473 
1474 # ++++++++++++++++++++++ U Plane +++++++++++++++++++++++
1475 
1476 # Create U plane logical volume
1477 print TPC <<EOF;
1478  <volume name="volTPCPlaneU${_[3]}">
1479  <materialref ref="LAr"/>
1480  <solidref ref="${_[3]}UPlane"/>
1481 EOF
1482 
1483 
1484 print $wout "\n- Wires for U plane -\n\n";
1485 print $wout " Uplane_y: $Uactive_y\n";
1486 print $wout " Uplane_z: $Uactive_z\n";
1487 
1488 
1489 if ($wires_on==1)
1490 {
1491 
1492 # Starting with the bottom left corner wires:
1493  # x=0 to center the wires in the plane
1494  # y positioning: (-0.5*$TPCWirePlaneHeight) starts the incremental increase
1495  # from the bottom of the plane, and trigonometry gives the increment
1496  # z positioning: Looking at the plane from the positive x direction,
1497  # (0.5*$TPCWirePlaneLength) starts the incremental increase from
1498  # the lower left corner.
1499  # rotation: same as common wire in code below
1500 
1501  $FirstU_ypos = - $Uactive_y/2 + $FirstUWireOffset/$TanUAngle/2;
1502  $FirstU_zpos = + $Uactive_z/2 - $FirstUWireOffset/2;
1503 
1504 for ($i = 0; $i < $NumberCornerUWires; ++$i)
1505 {
1506 
1507 my $ypos = $FirstU_ypos + ($i)*0.5*$UWire_yint;
1508 my $zpos = $FirstU_zpos - ($i)*0.5*$UWire_zint;
1509 
1510 $pitch = ($ypos - $lastYpos) * $SinUAngle
1511  - ($zpos - $lastZpos) * $CosUAngle;
1512 
1513 $xrotUAang = 90-$UAngle;
1514 print TPC <<EOF;
1515  <physvol>
1516  <volumeref ref="volTPCWireU$i${_[3]}"/>
1517  <position name="pos${_[3]}WireU$i" unit="cm" x="0" y="$ypos " z="$zpos"/>
1518  <rotation name="rUAngle$i" unit="deg" x="$xrotUAang" y="0" z="0"/>
1519  </physvol>
1520 EOF
1521 
1522 $topY = $ypos + ($CosUAngle*$CornerUWireLength[$i]/2);
1523 $bottomY = $ypos - ($CosUAngle*$CornerUWireLength[$i]/2);
1524 $edgeZ_p = $zpos + ($SinUAngle*$CornerUWireLength[$i]/2);
1525 $edgeZ_m = $zpos - ($SinUAngle*$CornerUWireLength[$i]/2);
1526 print $wout "U$i: ( $ypos , $zpos ) (pitch = $pitch)\n";
1527 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1528 
1529 $lastYpos = $ypos;
1530 $lastZpos = $zpos;
1531 
1532 }
1533 
1534 
1535 # Moving upwards to the common wires:
1536  # x and z are zero to center the wires along a vertical axis
1537  # y positioning: The trick is positioning the lowest common wire so that the pitch
1538  # is consistent, then the increment is double the increment of
1539  # the corner wires since there is no z incriment.
1540  # rotation: wires in \\\\ direction, so +90deg to bring them to vertical and
1541  # +UAngle counterclockwise to arrive at proper orientation
1542 # Note that the counter maintains wire number (in pos. name) counting bottom to top
1543 
1544 
1545 my $StartCommonUWires_ypos = $lastYpos + $UWire_yint - abs( $lastZpos )/$TanUAngle;
1546 
1547 for ($i = $NumberCornerUWires; $i < $NumberSideUWires; ++$i)
1548 {
1549 
1550  $j = $i - $NumberCornerUWires;
1551  my $ypos = $StartCommonUWires_ypos + $UWire_yint*($j);
1552 
1553  $lastWnum = $i-1;
1554  if ( $ypos < $lastYpos ){ print "WARNING: y position dropped from $lastYpos (wire U$lastWnum) to $ypos (wire U$i)\n"; }
1555  if ( $ypos == $lastYpos ){ print "WARNING: y position between wire U$lastWnum and U$lastWnum did not move: $ypos\n"; }
1556 
1557 
1558 $pitch = ($ypos - $lastYpos) * $SinUAngle - ($zpos - $lastZpos) * $CosUAngle ;
1559 
1560 $xrotUAang = 90-$UAngle;
1561 print TPC <<EOF;
1562  <physvol>
1563  <volumeref ref="volTPCWireUCommon${_[3]}"/>
1564  <position name="pos${_[3]}WireU$i" unit="cm" x="0" y="$ypos " z="0"/>
1565  <rotation name="rUAngle$i" unit="deg" x="$xrotUAang" y="0" z="0"/>
1566  </physvol>
1567 EOF
1568 
1569 $topY = $ypos + ($CosUAngle*$CommonUWireLength/2);
1570 $bottomY = $ypos - ($CosUAngle*$CommonUWireLength/2);
1571 $edgeZ_p = + ($SinUAngle*$CommonUWireLength/2);
1572 $edgeZ_m = - ($SinUAngle*$CommonUWireLength/2);
1573 print $wout "U$i: ( $ypos , 0 ) (pitch = $pitch)\n";
1574 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1575 
1576 $lastYpos = $ypos;
1577 $lastZpos = 0;
1578 
1579 }
1580 
1581 
1582 
1583 my $FirstTopUWire_zspan = $FirstTopUWire_yspan*$TanUAngle;
1584 my $StartTopUWires_ypos = + $Uactive_y/2 - $FirstTopUWire_yspan/2;
1585 my $StartTopUWires_zpos = - $Uactive_z/2 + $FirstTopUWire_zspan/2;
1586 
1587 # Finally moving to the corner wires on the top right:
1588  # x=0 to center the wires in the plane
1589  # y positioning: plug wire number into same equation
1590  # z positioning: start at z=0 and go negatively at the same z increment
1591  # rotation: same as common wire in code above
1592 # note that the counter maintains wire number shown in the position name
1593 
1594 for ($j = $NumberSideUWires; $j < $NumberSideUWires+$NumberCornerUWires; ++$j)
1595 {
1596 
1597 $i = $j - $NumberSideUWires;
1598 
1599 my $ypos = $StartTopUWires_ypos + ($i)*0.5*$UWire_yint;
1600 my $zpos = $StartTopUWires_zpos - ($i)*0.5*$UWire_zint;
1601 
1602  $lastWnum = $j-1;
1603  if ( $ypos < $lastYpos ){ print "WARNING: y position dropped from $lastYpos (wire U$lastWnum) to $ypos (wire U$j)\n"; }
1604  if ( $ypos == $lastYpos ){ print "WARNING: y position between wire U$lastWnum and U$j did not move: $ypos\n"; }
1605 
1606 $pitch = ($ypos - $lastYpos) * $SinUAngle - ($zpos - $lastZpos) * $CosUAngle ;
1607 
1608 $xrotUAang = 90-$UAngle;
1609 print TPC <<EOF;
1610  <physvol>
1611  <volumeref ref="volTPCWireU$j${_[3]}"/>
1612  <position name="pos${_[3]}WireU$j" unit="cm" x="0" y="$ypos " z="$zpos"/>
1613  <rotation name="rUAngle$j" unit="deg" x="$xrotUAang" y="0" z="0"/>
1614  </physvol>
1615 EOF
1616 
1617 $topY = $ypos + ($CosUAngle*$TopCornerUWireLength[$i]/2);
1618 $bottomY = $ypos - ($CosUAngle*$TopCornerUWireLength[$i]/2);
1619 $edgeZ_p = $zpos + ($SinUAngle*$TopCornerUWireLength[$i]/2);
1620 $edgeZ_m = $zpos - ($SinUAngle*$TopCornerUWireLength[$i]/2);
1621 print $wout "U$j: ( $ypos , $zpos ) (pitch = $pitch)\n";
1622 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1623 
1624 $lastYpos = $ypos;
1625 $lastZpos = $zpos;
1626 
1627 }
1628 
1629 } #ends if wires on
1630 
1631 
1632 # ++++++++++++++++++++++ V Plane +++++++++++++++++++++++
1633 
1634 # End U plane and create V plane logical volume
1635 print TPC <<EOF;
1636  </volume>
1637 
1638  <volume name="volTPCPlaneV${_[3]}">
1639  <materialref ref="LAr"/>
1640  <solidref ref="${_[3]}VPlane"/>
1641 EOF
1642 
1643 print $wout "\n- Wires for V plane -\n\n";
1644 print $wout " Vplane_y: $Vactive_y\n";
1645 print $wout " Vplane_z: $Vactive_z\n";
1646 
1647 if ($wires_on==1)
1648 {
1649 
1650 
1651 # Starting with the bottom right corner wires:
1652  # x=0 to center the wires in the plane
1653  # y positioning: (-0.5*$TPCWirePlaneHeight) starts the incremental increase
1654  # from the bottom of the plane, and trigonometry gives the increment
1655  # z positioning: Looking at the plane from the positive x direction,
1656  # (-0.5*$TPCWirePlaneLength) starts the incremental increase from
1657  # the lower right corner.
1658  # rotation: same as common wire in code below
1659 
1660  $FirstV_ypos = - $Vactive_y/2 + $FirstVWireOffset/$TanVAngle/2;
1661  $FirstV_zpos = - $Vactive_z/2 + $FirstVWireOffset/2;
1662 
1663 for ($i = 0; $i < $NumberCornerVWires; ++$i)
1664 {
1665 
1666 my $ypos = $FirstV_ypos + ($i)*0.5*$VWire_yint;
1667 my $zpos = $FirstV_zpos + ($i)*0.5*$VWire_zint;
1668 
1669 $xrotVAang = 90+$VAngle;
1670 print TPC <<EOF;
1671  <physvol>
1672  <volumeref ref="volTPCWireV$i${_[3]}"/>
1673  <position name="pos${_[3]}WireV$i" unit="cm" x="0" y="$ypos " z="$zpos"/>
1674  <rotation name="rVAngle$i" unit="deg" x="$xrotVAang" y="0" z="0"/>
1675  </physvol>
1676 EOF
1677 
1678 $topY = $ypos + ($CosVAngle*$CornerVWireLength[$i]/2);
1679 $bottomY = $ypos - ($CosVAngle*$CornerVWireLength[$i]/2);
1680 $edgeZ_p = $zpos + ($SinVAngle*$CornerVWireLength[$i]/2);
1681 $edgeZ_m = $zpos - ($SinVAngle*$CornerVWireLength[$i]/2);
1682 print $wout "V$i: ( $ypos , $zpos ) \n";
1683 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1684 
1685 $lastYpos = $ypos;
1686 $lastZpos = $zpos;
1687 
1688 }
1689 
1690 
1691 # Moving upwards to the common wires:
1692  # x and z are zero to center the wires along a vertical axis
1693  # y positioning: Plug wire number into the same corner ypos equation
1694  # rotation: wires in //// direction, so +90deg to bring them to vertical and
1695  # --VAngle counterclockwise to arrive at proper orientation
1696 # Note that the counter maintains wire number in the position name
1697 
1698 my $StartCommonVWires_ypos = $lastYpos + $VWire_yint - abs( $lastZpos )/$TanVAngle;
1699 
1700 for ($i = $NumberCornerVWires; $i < $NumberSideVWires; ++$i)
1701 {
1702 
1703  $j = $i - $NumberCornerVWires;
1704  my $ypos = $StartCommonVWires_ypos + $VWire_yint*($j);
1705 
1706 $xrotVAang = 90+$VAngle;
1707 print TPC <<EOF;
1708  <physvol>
1709  <volumeref ref="volTPCWireVCommon${_[3]}"/>
1710  <position name="pos${_[3]}WireV$i" unit="cm" x="0" y="$ypos " z="0"/>
1711  <rotation name="rVAngle$i" unit="deg" x="$xrotVAang" y="0" z="0"/>
1712  </physvol>
1713 EOF
1714 
1715 $topY = $ypos + ($CosVAngle*$CommonVWireLength/2);
1716 $bottomY = $ypos - ($CosVAngle*$CommonVWireLength/2);
1717 $edgeZ_p = + ($SinVAngle*$CommonVWireLength/2);
1718 $edgeZ_m = - ($SinVAngle*$CommonVWireLength/2);
1719 print $wout "V$i: ( $ypos , 0 ) \n";
1720 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1721 
1722 $lastYpos = $ypos;
1723 #$lastZpos = $zpos; always 0
1724 
1725 }
1726 
1727 
1728 my $FirstTopVWire_zspan = $FirstTopVWire_yspan*$TanVAngle;
1729 my $StartTopVWires_ypos = + $Vactive_y/2 - $FirstTopVWire_yspan/2;
1730 my $StartTopVWires_zpos = + $Vactive_z/2 - $FirstTopVWire_zspan/2;
1731 
1732 # Finally moving to the corner wires on the top right:
1733  # x=0 to center the wires in the plane
1734  # y positioning: plug wire number into same equation
1735  # z positioning: start at z=0 and go positively at the same z increment
1736  # rotation: same as common wire in code above
1737 # note that the counter maintains wire number shown in the position name
1738 
1739 for ($j = $NumberSideVWires; $j < $NumberSideVWires+$NumberCornerVWires; ++$j)
1740 {
1741 
1742 $i = $j - $NumberSideVWires;
1743 
1744 my $ypos = $StartTopVWires_ypos + ($i)*0.5*$VWire_yint;
1745 my $zpos = $StartTopVWires_zpos + ($i)*0.5*$VWire_zint;
1746 
1747 $xrotVAang = 90+$VAngle;
1748 print TPC <<EOF;
1749  <physvol>
1750  <volumeref ref="volTPCWireV$j${_[3]}"/>
1751  <position name="pos${_[3]}WireV$j" unit="cm" x="0" y="$ypos " z="$zpos"/>
1752  <rotation name="rVAngle$j" unit="deg" x="$xrotVAang" y="0" z="0"/>
1753  </physvol>
1754 EOF
1755 
1756 $topY = $ypos + ($CosVAngle*$TopCornerVWireLength[$i]/2);
1757 $bottomY = $ypos - ($CosVAngle*$TopCornerVWireLength[$i]/2);
1758 $edgeZ_p = $zpos + ($SinVAngle*$TopCornerVWireLength[$i]/2);
1759 $edgeZ_m = $zpos - ($SinVAngle*$TopCornerVWireLength[$i]/2);
1760 print $wout "V$j: ( $ypos , $zpos ) \n";
1761 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1762 
1763 }
1764 
1765 
1766 
1767 
1768 
1769 
1770 } #ends if wires on
1771 
1772 
1773 
1774 # ++++++++++++++++++++++ Z Plane +++++++++++++++++++++++
1775 
1776 # End V plane and create Z plane logical volume
1777 print TPC <<EOF;
1778  </volume>
1779 
1780  <volume name="volTPCPlaneZ${_[3]}">
1781  <materialref ref="LAr"/>
1782  <solidref ref="${_[3]}ZPlane"/>
1783 EOF
1784 
1785 if ($wires_on==1)
1786 {
1787 
1788 # This is the simplest plane, one loop creates all of the wires
1789  # x and y position at zero to center the wires
1790  # z position: moving from front of detector to back, in the positive z direction,
1791  # starting at (-0.5*$TPCWirePlaneLength), the right side looking from
1792  # the +x direction
1793 
1794 for ($i=0; $i<$NumberVerticalWires; ++$i)
1795 {
1796 my $zpos = (-0.5*$Zactive_z) + $i*$XWirePitch + $TPCWireThickness/2;
1797 
1798 print TPC <<EOF;
1799  <physvol>/
1800  <volumeref ref="volTPCWireVert${_[3]}"/>
1801  <position name="pos${_[3]}WireZ$i" unit="cm" x="0" y="0 " z="$zpos"/>
1802  <rotationref ref="rPlus90AboutX"/>
1803  </physvol>
1804 EOF
1805 
1806 }
1807 
1808 } #ends if wires on
1809 
1810 print TPC <<EOF;
1811  </volume>
1812 EOF
1813 
1814 #+++++++++++++++++++++ ^^ Position physical wires Above ^^ +++++++++++++++++++++
1815 
1816 ## make the TPC active volume extend down to the G10 for the grid
1817 
1818  my $BottomOfAPA = - $TPC_y/2 + $APAGap_y/2;
1819 
1820 
1821  $posZplane[0] = -$_[0]/2 + $APAWirePlaneSpacing + $TPCWirePlaneThickness/2;
1822  $posZplane[1] = $BottomOfAPA + $WrapCover + 4*$G10thickness + $Zactive_y/2;
1823  $posZplane[2] = 0;
1824 
1825  $posVplane[0] = $posZplane[0] + $APAWirePlaneSpacing + $TPCWirePlaneThickness;
1826  $posVplane[1] = $BottomOfAPA + $WrapCover + 3*$G10thickness + $Vactive_y/2;
1827  $posVplane[2] = $posZplane[2];
1828 
1829  $posUplane[0] = $posVplane[0] + $APAWirePlaneSpacing + $TPCWirePlaneThickness;
1830  $posUplane[1] = $BottomOfAPA + $WrapCover + 2*$G10thickness + $Uactive_y/2;
1831  $posUplane[2] = $posZplane[2];
1832 
1833  $posTPCActive[0] = $posUplane[0] + $TPCWirePlaneThickness/2 + $TPCActive_x/2;
1834  $posTPCActive[1] = -$_[1]/2 + $TPCActive_y/2;
1835  $posTPCActive[2] = 0;
1836 
1837 #wrap up the TPC file
1838 print TPC <<EOF;
1839  <volume name="volTPC${_[3]}">
1840  <materialref ref="LAr"/>
1841  <solidref ref="${_[3]}"/>
1842  <physvol>
1843  <volumeref ref="volTPCPlaneZ${_[3]}"/>
1844  <position name="pos${_[3]}PlaneZ" unit="cm"
1845  x="$posZplane[0]" y="$posZplane[1]" z="$posZplane[2]"/>
1846  <rotationref ref="rIdentity"/>
1847  </physvol>
1848  <physvol>
1849  <volumeref ref="volTPCPlaneV${_[3]}"/>
1850  <position name="pos${_[3]}PlaneV" unit="cm"
1851  x="$posVplane[0]" y="$posVplane[1]" z="$posVplane[2]"/>
1852  <rotationref ref="rIdentity"/>
1853  </physvol>
1854  <physvol>
1855  <volumeref ref="volTPCPlaneU${_[3]}"/>
1856  <position name="pos${_[3]}PlaneU" unit="cm"
1857  x="$posUplane[0]" y="$posUplane[1]" z="$posUplane[2]"/>
1858  <rotationref ref="rIdentity"/>
1859  </physvol>
1860 EOF
1861 
1862 # Option to omit the active volume on the outside for the prototype.
1863 if( !($killOuterActive==1 && $_[3] eq 'Outer') ){
1864 print TPC <<EOF;
1865  <physvol>
1866  <volumeref ref="volTPCActive${subname}"/>
1867  <position name="pos${_[3]}Active" unit="cm"
1868  x="$posTPCActive[0]" y="$posTPCActive[1]" z="$posTPCActive[2]"/>
1869  <rotationref ref="rIdentity"/>
1870  </physvol>
1871 EOF
1872 }
1873 
1874 print TPC <<EOF;
1875  </volume>
1876 </structure>
1877 </gdml>
1878 EOF
1879 
1880  close(TPC);
1881 
1882 } #end of sub gen_TPC
1883 
1884 
1885 
1886 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1887 #++++++++++++++++++++++++++++++++++++++ gen_Cryostat +++++++++++++++++++++++++++++++++++++
1888 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1889 
1890 sub gen_Cryostat()
1891 {
1892 
1893 # Create the cryostat fragment file name,
1894 # add file to list of output GDML fragments,
1895 # and open it
1896  $CRYO = "subfile_protodune_v7_Cryostat" . $suffix . ".gdml";
1897  push (@gdmlFiles, $CRYO);
1898  $CRYO = ">" . $CRYO;
1899  open(CRYO) or die("Could not open file $CRYO for writing");
1900 
1901 
1902 # The standard XML prefix and starting the gdml
1903  print CRYO <<EOF;
1904 <?xml version='1.0'?>
1905 <gdml>
1906 EOF
1907 
1908 $APAFrameZSide_x = $APAFrame_x;
1909 $APAFrameZSide_y = 4*$inch;
1910 $APAFrameZSide_z = $APAFrame_z;
1911 
1912 $APAFrameYSide_x = $APAFrame_x;
1913 $APAFrameYSide_y = $APAFrame_y-2*$APAFrameZSide_y;
1914 $APAFrameYSide_z = 4*$inch;
1915 $APAFrameYCenter_x = 2*$inch;
1916 $APAFrameYCenter_z = 3*$inch;
1917 
1918 # Two outer Y supports will sandwich the light paddles
1919 $APAFrameYOuterSupport_x = ($APAFrame_x-$LightPaddle_x)/2;
1920 $APAFrameYOuterSupport_y = $APAFrame_y-2*$APAFrameZSide_y;
1921 $APAFrameYOuterSupport_z = 4*$inch;
1922 
1923 $EdgeFrameSteelThickness = 0.12*$inch;
1924 $InnerFrameSteelThickness = 0.062*$inch;
1925 
1926 
1927 $G10BoardYSide_x = $APAFrame_x;
1928 $G10BoardYSide_y = $APAFrame_y;
1929 $G10BoardYSide_z = $G10thickness;
1930 
1931 $G10BoardZSide_x = $APAFrame_x;
1932 $G10BoardZSide_y = $G10thickness;
1933 $G10BoardZSide_z = $APAFrame_z;
1934 
1935 #Cathode dimensions
1936 $CathFrame_x = 2.5*$inch;
1937 $CathFrame_y = 237.51*$inch;
1938 $CathFrame_z = 91.14*$inch;
1939 
1940 $CathTop_x = 1.185*$inch;
1941 $CathTop_y = 76.42*$inch;
1942 $CathTop_z = 43.47*$inch;
1943 
1944 $CathMid_x = 1.185*$inch;
1945 $CathMid_y = 76.67*$inch;
1946 $CathMid_z = 43.47*$inch;
1947 
1948 $CathPos_z = $CathFrame_z/2 - $CathTop_z/2 - 1*$inch;
1949 $CathPos_x = $CathFrame_x/2 - $CathTop_x/2 + 0.001; # 0.001 is for clean cut
1950 $CathTopPos_y= $CathFrame_y/2 - $CathTop_y/2 - 3*$inch;
1951 $CathBotPos_y= -$CathFrame_y/2 + $CathTop_y/2 + 3*$inch;
1952 $CathMidPos_y= 0.;
1953 print "CathMidPos_y = $CathMidPos_y"."\n";
1954 
1955 # All the cryostat solids.
1956 print CRYO <<EOF;
1957 <solids>
1958  <box name="Cryostat" lunit="cm"
1959  x="$Cryostat_x"
1960  y="$Cryostat_y"
1961  z="$Cryostat_z"/>
1962 
1963  <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"/>
1964 
1965  <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"/>
1966 
1967  <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"/>
1968 
1969  <torus name="TorRing" rmin="0" rmax="1.7" rtor="10.1" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1970  <tube name="TubeRing1" rmin="$BeamPlugNiRad" rmax="$BeamPlugRad" z="0.5" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1971  <tube name="TubeRing2" rmin="$BeamPlugNiRad" rmax="$BeamPlugRad" z="3.4" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1972 
1973  <tube name="TubeBePlFlangeOut" rmin="0" rmax="15" z="3.6" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1974  <tube name="TubeBePlFlangeIn" rmin="0" rmax="8.25" z="3.2" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1975  <tube name="TubeBePlFlangeCut" rmin="12.5" rmax="15.01" z="2.302" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1976  <tube name="TubeBePlFlangeTPCRem" rmin="0." rmax="12.5" z="0.91" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
1977 
1978  <subtraction name="BPRing">
1979  <first ref="TorRing"/>
1980  <second ref="TubeRing2"/>
1981  </subtraction>
1982  <union name="BeamPlugERing">
1983  <first ref="BPRing"/>
1984  <second ref="TubeRing1"/>
1985  </union>
1986 
1987  <subtraction name="BePlFlangeSolid">
1988  <first ref="TubeBePlFlangeOut"/>
1989  <second ref="TubeBePlFlangeCut"/>
1990  <position name="posSubBePlFlangeSolid" x="0" y="0" z="0.651" unit="cm"/>
1991  </subtraction>
1992  <subtraction name="BePlFlange">
1993  <first ref="BePlFlangeSolid"/>
1994  <second ref="TubeBePlFlangeIn"/>
1995  <position name="posSubBePlFlange" x="0" y="0" z="-0.20" unit="cm"/>
1996  </subtraction>
1997 
1998 EOF
1999 
2000 for($i=0 ; $i<7 ; $i++){
2001 
2002 $old_i = $i;
2003 $new_i = $i+1;
2004 $BeamPlugERing_z = $BeamPlugERingPosZ + $i*5.7;
2005 $BeamPlugNiERing_z = $BeamPlugERingPosZ + $i*5.7 - $BeamPlugNiPos_z;
2006 
2007 print CRYO <<EOF;
2008  <subtraction name="BeamPlug_$new_i">
2009  <first ref="BeamPlug_$old_i"/>
2010  <second ref="BeamPlugERing"/>
2011  <position name="posBeamPlugSubtr_$new_i" x="0" y="0" z="$BeamPlugERing_z" unit="cm"/>
2012  </subtraction>
2013  <subtraction name="BeamPlugNi_$new_i">
2014  <first ref="BeamPlugNi_$old_i"/>
2015  <second ref="BeamPlugERing"/>
2016  <position name="posBeamPlugNiSubtr_$new_i" x="0" y="0" z="$BeamPlugNiERing_z" unit="cm"/>
2017  </subtraction>
2018 EOF
2019 }
2020 
2021 print CRYO <<EOF;
2022  <box name="ArgonInterior" lunit="cm"
2023  x="$Argon_x"
2024  y="$Argon_y"
2025  z="$Argon_z"/>
2026 
2027  <box name="GaseousArgon" lunit="cm"
2028  x="$Argon_x"
2029  y="$HeightGaseousAr"
2030  z="$Argon_z"/>
2031 
2032  <subtraction name="SteelShell">
2033  <first ref="Cryostat"/>
2034  <second ref="ArgonInterior"/>
2035  </subtraction>
2036 
2037  <box name="Cathode" lunit="cm"
2038  x="$Cathode_x"
2039  y="$CathFrame_y"
2040  z="$CathFrame_z"/>
2041 
2042 
2043 EOF
2044 # <box name="CathFrame" lunit="cm"
2045 # x="$CathFrame_x"
2046 # y="$CathFrame_y"
2047 # z="$CathFrame_z"/>
2048 
2049 # <box name="CathTop" lunit="cm"
2050 # x="$CathTop_x"
2051 # y="$CathTop_y"
2052 # z="$CathTop_z"/>
2053 
2054 # <box name="CathMid" lunit="cm"
2055 # x="$CathMid_x"
2056 # y="$CathMid_y"
2057 # z="$CathMid_z"/>
2058 
2059 # <subtraction name="Cath-1">
2060 # <first ref="CathFrame"/>
2061 # <second ref="CathTop"/>
2062 # <position name="posCath-1" x="$CathPos_x" y="$CathTopPos_y" z="$CathPos_z" unit="cm"/>
2063 # </subtraction>
2064 # <subtraction name="Cath-2">
2065 # <first ref="Cath-1"/>
2066 # <second ref="CathTop"/>
2067 # <position name="posCath-2" x="-$CathPos_x" y="$CathTopPos_y" z="$CathPos_z" unit="cm"/>
2068 # </subtraction>
2069 # <subtraction name="Cath-3">
2070 # <first ref="Cath-2"/>
2071 # <second ref="CathTop"/>
2072 # <position name="posCath-3" x="$CathPos_x" y="$CathTopPos_y" z="-$CathPos_z" unit="cm"/>
2073 # </subtraction>
2074 # <subtraction name="Cath-4">
2075 # <first ref="Cath-3"/>
2076 # <second ref="CathTop"/>
2077 # <position name="posCath-4" x="-$CathPos_x" y="$CathTopPos_y" z="-$CathPos_z" unit="cm"/>
2078 # </subtraction>
2079 
2080 # <subtraction name="Cath-5">
2081 # <first ref="Cath-4"/>
2082 # <second ref="CathMid"/>
2083 # <position name="posCath-5" x="$CathPos_x" y="$CathMidPos_y" z="$CathPos_z" unit="cm"/>
2084 # </subtraction>
2085 # <subtraction name="Cath-6">
2086 # <first ref="Cath-5"/>
2087 # <second ref="CathMid"/>
2088 # <position name="posCath-6" x="-$CathPos_x" y="$CathMidPos_y" z="$CathPos_z" unit="cm"/>
2089 # </subtraction>
2090 # <subtraction name="Cath-7">
2091 # <first ref="Cath-6"/>
2092 # <second ref="CathMid"/>
2093 # <position name="posCath-7" x="$CathPos_x" y="$CathMidPos_y" z="-$CathPos_z" unit="cm"/>
2094 # </subtraction>
2095 # <subtraction name="Cath-8">
2096 # <first ref="Cath-7"/>
2097 # <second ref="CathMid"/>
2098 # <position name="posCath-8" x="-$CathPos_x" y="$CathMidPos_y" z="-$CathPos_z" unit="cm"/>
2099 # </subtraction>
2100 
2101 
2102 # <subtraction name="Cath-9">
2103 # <first ref="Cath-8"/>
2104 # <second ref="CathTop"/>
2105 # <position name="posCath-9" x="$CathPos_x" y="$CathBotPos_y" z="$CathPos_z" unit="cm"/>
2106 # </subtraction>
2107 # <subtraction name="Cath-10">
2108 # <first ref="Cath-9"/>
2109 # <second ref="CathTop"/>
2110 # <position name="posCath-10" x="-$CathPos_x" y="$CathBotPos_y" z="$CathPos_z" unit="cm"/>
2111 # </subtraction>
2112 # <subtraction name="Cath-11">
2113 # <first ref="Cath-10"/>
2114 # <second ref="CathTop"/>
2115 # <position name="posCath-11" x="$CathPos_x" y="$CathBotPos_y" z="-$CathPos_z" unit="cm"/>
2116 # </subtraction>
2117 # <subtraction name="Cath-12">
2118 # <first ref="Cath-11"/>
2119 # <second ref="CathTop"/>
2120 # <position name="posCath-12" x="-$CathPos_x" y="$CathBotPos_y" z="-$CathPos_z" unit="cm"/>
2121 # </subtraction>
2122 #EOF
2123 
2124 # <subtraction name="InnerActive">
2125 # <first ref="InnerActive_NoCPA"/>
2126 # <second ref="Cath-12"/>
2127 # <position name="posCPAInnerRem" x="179.23175" y="-3.805" z="0." unit="cm"/>
2128 # </subtraction>
2129 #
2130 #################################
2131 print CRYO <<EOF;
2132  <box name="boxFCEWmod" x="354.3" y="151.2" z="12.8" lunit="cm"/>
2133  <box name="boxFCEWHorSuppOut" x="354.3" y="15.2" z="10.2" lunit="cm"/>
2134  <box name="boxFCEWHorSuppInn" x="354.301" y="14.0" z="9.0" lunit="cm"/>
2135  <box name="boxFCEWRem" x="354.301" y="15.201" z="1.3" lunit="cm"/>
2136  <box name="boxFCEWFieldShaping" x="354.3" y="151.2" z="1.3" lunit="cm"/>
2137  <box name="boxFCEWVerSupp" x="15.2" y="151.2" z="1.3" lunit="cm"/>
2138 
2139  <subtraction name="FCEWHorSupp">
2140  <first ref="boxFCEWHorSuppOut"/>
2141  <second ref="boxFCEWHorSuppInn"/>
2142  </subtraction>
2143  <subtraction name="FCEWHorSuppBar">
2144  <first ref="FCEWHorSupp"/>
2145  <second ref="boxFCEWRem"/>
2146  <position name="posFCEWHorSuppBar" x="0" y="0" z="2." unit="cm"/>
2147  </subtraction>
2148 
2149  <box name="boxFCEW-BP-Subtract" x="50.8" y="151.2" z="1.301" lunit="cm"/>
2150  <tube name="tubBePlHolemod" rmin="0" rmax="15.25" z="12.801" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
2151  <tube name="tubBePlHoleFiSh" rmin="0" rmax="15.25" z="1.301" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
2152  <box name="boxFCEW-BPFla-VerSupp" x="50.8" y="151.2" z="1.3" lunit="cm"/>
2153  <box name="boxFCEW-BPFla-Subtr" x="25.4" y="64" z="1.301" lunit="cm"/>
2154  <tube name="tubFCEW-BPFla-Subtr" rmin="0" rmax="14.0" z="1.301" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
2155  <tube name="tubFCEW-BPVer-Subtr" rmin="0" rmax="12.5" z="1.301" deltaphi="360." startphi="0" aunit="deg" lunit="cm"/>
2156 
2157  <subtraction name="boxFCEW-BP-NoHole">
2158  <first ref="boxFCEWmod"/>
2159  <second ref="boxFCEW-BP-Subtract"/>
2160  <position name="posFCEW-BP-NoHole" x="147.8" y="0" z="5.7505" unit="cm"/>
2161  </subtraction>
2162  <subtraction name="boxFCEW-BP-mod">
2163  <first ref="boxFCEW-BP-NoHole"/>
2164  <second ref="tubBePlHolemod"/>
2165  <position name="posboxFCEW-BP-mod" x="146" y="41.6" z="0" unit="cm"/>
2166  </subtraction>
2167  <subtraction name="FCEW-BP-FieldShaping">
2168  <first ref="boxFCEWFieldShaping"/>
2169  <second ref="tubBePlHoleFiSh"/>
2170  <position name="posFCEW-BP-FieldShapingSol" x="146" y="41.6" z="0" unit="cm"/>
2171  </subtraction>
2172 
2173  <subtraction name="FCEW-BPFla-Ver">
2174  <first ref="boxFCEW-BPFla-VerSupp"/>
2175  <second ref="boxFCEW-BPFla-Subtr"/>
2176  <position name="posFCEW-BPFla-Ver" x="0." y="-11.6" z="0." unit="cm"/>
2177  </subtraction>
2178  <subtraction name="FCEW-BPFla">
2179  <first ref="FCEW-BPFla-Ver"/>
2180  <second ref="tubFCEW-BPFla-Subtr"/>
2181  <position name="posFCEW-BPFlaSolid" x="-1.35" y="41.4" z="0." unit="cm"/>
2182  </subtraction>
2183 
2184  <subtraction name="FCEW-BPVer">
2185  <first ref="boxFCEWVerSupp"/>
2186  <second ref="tubFCEW-BPVer-Subtr"/>
2187  <position name="posFCEW-BP-Ver" x="-14.9" y="43.3" z="0." unit="cm"/>
2188  </subtraction>
2189 
2190  <box name="boxFCMod" x="352" y="27.4" z="230" lunit="cm"/>
2191  <box name="boxShieldPlate" x="264" y="2" z="230" lunit="cm"/>
2192  <box name="boxFCXBarOut" x="352" y="15.2" z="7.6" lunit="cm"/>
2193  <box name="boxFCXBarRem" x="352.001" y="13.9" z="3.501" lunit="cm"/>
2194  <box name="boxFCXFieldBarRem" x="352.001" y="1.3" z="0.61" lunit="cm"/>
2195  <box name="boxFCZBarOut" x="3.8" y="7.6" z="115.4" lunit="cm"/>
2196  <box name="boxFCZBarRem" x="1.58" y="6.3" z="115.401" lunit="cm"/>
2197  <box name="boxFCFieldBarPlane" x="352" y="1.3" z="230" lunit="cm"/>
2198 
2199  <subtraction name="FCXBarOut-1">
2200  <first ref="boxFCXBarOut"/>
2201  <second ref="boxFCXBarRem"/>
2202  <position name="posFCXBarOutSol-1" x="0" y="0" z="2.05" unit="cm"/>
2203  </subtraction>
2204  <subtraction name="FCXBarOut-2">
2205  <first ref="FCXBarOut-1"/>
2206  <second ref="boxFCXBarRem"/>
2207  <position name="posFCXBarOutSol-2" x="0" y="0" z="-2.05" unit="cm"/>
2208  </subtraction>
2209  <subtraction name="FCXBarOut">
2210  <first ref="FCXBarOut-2"/>
2211  <second ref="boxFCXFieldBarRem"/>
2212  <position name="posFCXBarOut" x="0" y="-3.3" z="0" unit="cm"/>
2213  </subtraction>
2214  <subtraction name="FCZBarOut-1">
2215  <first ref="boxFCZBarOut"/>
2216  <second ref="boxFCZBarRem"/>
2217  <position name="posFCZBarOut-1" x="1.111" y="0" z="0" unit="cm"/>
2218  </subtraction>
2219  <subtraction name="FCZBar">
2220  <first ref="FCZBarOut-1"/>
2221  <second ref="boxFCZBarRem"/>
2222  <position name="posFCZBar" x="-1.111" y="0" z="0" unit="cm"/>
2223  </subtraction>
2224 
2225 
2226 EOF
2227 
2228 $LightPaddleIUSiPM_z = $LightPaddleIU_z + $SiPM_z;
2229 $LightPaddleMITSiPM_z = $LightPaddleMIT_z + $SiPM_z;
2230 $LightPaddleSiPM_z = $LightPaddle_z + $SiPM_z;
2231 $APAFrameYSideHollow_x = $APAFrameYSide_x-2*$EdgeFrameSteelThickness;
2232 $APAFrameYSideHollow_y = $APAFrameYSide_y-2*$EdgeFrameSteelThickness;
2233 $APAFrameZSideHollow_x = $APAFrameZSide_x-2*$EdgeFrameSteelThickness;
2234 $APAFrameZSideHollow_y = $APAFrameZSide_y-2*$EdgeFrameSteelThickness;
2235 $APAFrameYCenterHollow_x = $APAFrameYCenter_x-2*$EdgeFrameSteelThickness;
2236 print CRYO <<EOF;
2237  <box name="LightPaddleIU" lunit="cm"
2238  x="$LightPaddleIU_x"
2239  y="$LightPaddleIU_y"
2240  z="$LightPaddleIUSiPM_z"/>
2241 
2242  <box name="LightPaddleIUOut" lunit="cm"
2243  x="$LightPaddleIUOut_x"
2244  y="$LightPaddleIUOut_y"
2245  z="$LightPaddleSiPM_z"/>
2246  <subtraction name="PaddleRailIU">
2247  <first ref="LightPaddleIUOut"/>
2248  <second ref="LightPaddleIU"/>
2249  <positionref ref="posSubRailIU"/>
2250  </subtraction>
2251 
2252  <box name="LightPaddleMIT" lunit="cm"
2253  x="$LightPaddleMIT_x"
2254  y="$LightPaddleMIT_y"
2255  z="$LightPaddleMITSiPM_z"/>
2256 
2257  <box name="LightPaddleMITOut" lunit="cm"
2258  x="$LightPaddleMITOut_x"
2259  y="$LightPaddleMITOut_y"
2260  z="$LightPaddleSiPM_z"/>
2261  <subtraction name="PaddleRailMIT">
2262  <first ref="LightPaddleMITOut"/>
2263  <second ref="LightPaddleMIT"/>
2264  <positionref ref="posSubRailMIT"/>
2265  </subtraction>
2266 
2267  <box name="ArapucaOut" lunit="mm"
2268  x="@{[$ArapucaOut_x]}"
2269  y="@{[$ArapucaOut_y]}"
2270  z="@{[$ArapucaOut_z]}"/>
2271 
2272  <box name="ArapucaIn" lunit="mm"
2273  x="@{[$ArapucaIn_x]}"
2274  y="@{[$ArapucaIn_y]}"
2275  z="@{[$ArapucaIn_z]}"/>
2276 
2277  <subtraction name="ArapucaWalls0">
2278  <first ref="ArapucaOut"/>
2279  <second ref="ArapucaIn"/>
2280  <positionref ref="posArapucaSub0"/>
2281  </subtraction>
2282  <subtraction name="ArapucaWalls1">
2283  <first ref="ArapucaWalls0"/>
2284  <second ref="ArapucaIn"/>
2285  <positionref ref="posArapucaSub1"/>
2286  </subtraction>
2287  <subtraction name="ArapucaWalls2">
2288  <first ref="ArapucaWalls1"/>
2289  <second ref="ArapucaIn"/>
2290  <positionref ref="posArapucaSub2"/>
2291  </subtraction>
2292  <subtraction name="ArapucaWalls3">
2293  <first ref="ArapucaWalls2"/>
2294  <second ref="ArapucaIn"/>
2295  <positionref ref="posArapucaSub3"/>
2296  </subtraction>
2297  <subtraction name="ArapucaWalls4">
2298  <first ref="ArapucaWalls3"/>
2299  <second ref="ArapucaIn"/>
2300  <positionref ref="posArapucaSub4"/>
2301  </subtraction>
2302  <subtraction name="ArapucaWalls5">
2303  <first ref="ArapucaWalls4"/>
2304  <second ref="ArapucaIn"/>
2305  <positionref ref="posArapucaSub5"/>
2306  </subtraction>
2307  <subtraction name="ArapucaWalls6">
2308  <first ref="ArapucaWalls5"/>
2309  <second ref="ArapucaIn"/>
2310  <positionref ref="posArapucaSub6"/>
2311  </subtraction>
2312  <subtraction name="ArapucaWalls7">
2313  <first ref="ArapucaWalls6"/>
2314  <second ref="ArapucaIn"/>
2315  <positionref ref="posArapucaSub7"/>
2316  </subtraction>
2317  <subtraction name="ArapucaWalls8">
2318  <first ref="ArapucaWalls7"/>
2319  <second ref="ArapucaIn"/>
2320  <positionref ref="posArapucaSub8"/>
2321  </subtraction>
2322  <subtraction name="ArapucaWalls9">
2323  <first ref="ArapucaWalls8"/>
2324  <second ref="ArapucaIn"/>
2325  <positionref ref="posArapucaSub9"/>
2326  </subtraction>
2327  <subtraction name="ArapucaWalls10">
2328  <first ref="ArapucaWalls9"/>
2329  <second ref="ArapucaIn"/>
2330  <positionref ref="posArapucaSub10"/>
2331  </subtraction>
2332  <subtraction name="ArapucaWalls11">
2333  <first ref="ArapucaWalls10"/>
2334  <second ref="ArapucaIn"/>
2335  <positionref ref="posArapucaSub11"/>
2336  </subtraction>
2337  <subtraction name="ArapucaWalls12">
2338  <first ref="ArapucaWalls11"/>
2339  <second ref="ArapucaIn"/>
2340  <positionref ref="posArapucaSub12"/>
2341  </subtraction>
2342  <subtraction name="ArapucaWalls13">
2343  <first ref="ArapucaWalls12"/>
2344  <second ref="ArapucaIn"/>
2345  <positionref ref="posArapucaSub13"/>
2346  </subtraction>
2347  <subtraction name="ArapucaWalls14">
2348  <first ref="ArapucaWalls13"/>
2349  <second ref="ArapucaIn"/>
2350  <positionref ref="posArapucaSub14"/>
2351  </subtraction>
2352  <subtraction name="ArapucaWalls">
2353  <first ref="ArapucaWalls14"/>
2354  <second ref="ArapucaIn"/>
2355  <positionref ref="posArapucaSub15"/>
2356  </subtraction>
2357 
2358 
2359  <box name="ArapucaAcceptanceWindow" lunit="mm"
2360  x="@{[$ArapucaAcceptanceWindow_x]}"
2361  y="@{[$ArapucaAcceptanceWindow_y]}"
2362  z="@{[$ArapucaAcceptanceWindow_z]}"/>
2363 
2364  <box name="APAFrameYSideHollow" lunit="cm"
2365  x="$APAFrameYSideHollow_x"
2366  y="$APAFrameYSideHollow_y"
2367  z="$APAFrameYSide_z"/>
2368  <box name="APAFrameYSideShell" lunit="cm"
2369  x="$APAFrameYSide_x"
2370  y="$APAFrameYSide_y"
2371  z="$APAFrameYSide_z"/>
2372 
2373  <subtraction name="APAFrameYSide">
2374  <first ref="APAFrameYSideShell"/>
2375  <second ref="APAFrameYSideHollow"/>
2376  <positionref ref="posCenter"/>
2377  <rotationref ref="rIdentity"/>
2378  </subtraction>
2379 
2380  <box name="APAFrameYCenterHollow" lunit="cm"
2381  x="$APAFrameYCenterHollow_x"
2382  y="$APAFrameYSideHollow_y"
2383  z="$APAFrameYCenter_z"/>
2384  <box name="APAFrameYCenterShell" lunit="cm"
2385  x="$APAFrameYCenter_x"
2386  y="$APAFrameYSide_y"
2387  z="$APAFrameYCenter_z"/>
2388 
2389  <subtraction name="APAFrameYCenter_v1">
2390  <first ref="APAFrameYCenterShell"/>
2391  <second ref="APAFrameYCenterHollow"/>
2392  <positionref ref="posCenter"/>
2393  <rotationref ref="rIdentity"/>
2394  </subtraction>
2395 
2396  <subtraction name="APAFrameYCenter0">
2397  <first ref="APAFrameYCenter_v1"/>
2398  <second ref="ArapucaOut"/>
2399  <positionref ref="posPaddleSub0"/>
2400  </subtraction>
2401  <subtraction name="APAFrameYCenter1">
2402  <first ref="APAFrameYCenter0"/>
2403  <second ref="ArapucaOut"/>
2404  <positionref ref="posPaddleSub1"/>
2405  </subtraction>
2406  <subtraction name="APAFrameYCenter2">
2407  <first ref="APAFrameYCenter1"/>
2408  <second ref="ArapucaOut"/>
2409  <positionref ref="posPaddleSub2"/>
2410  </subtraction>
2411  <subtraction name="APAFrameYCenter3">
2412  <first ref="APAFrameYCenter2"/>
2413  <second ref="ArapucaOut"/>
2414  <positionref ref="posPaddleSub3"/>
2415  </subtraction>
2416  <subtraction name="APAFrameYCenter4">
2417  <first ref="APAFrameYCenter3"/>
2418  <second ref="ArapucaOut"/>
2419  <positionref ref="posPaddleSub4"/>
2420  </subtraction>
2421  <subtraction name="APAFrameYCenter5">
2422  <first ref="APAFrameYCenter4"/>
2423  <second ref="ArapucaOut"/>
2424  <positionref ref="posPaddleSub5"/>
2425  </subtraction>
2426  <subtraction name="APAFrameYCenter6">
2427  <first ref="APAFrameYCenter5"/>
2428  <second ref="ArapucaOut"/>
2429  <positionref ref="posPaddleSub6"/>
2430  </subtraction>
2431  <subtraction name="APAFrameYCenter7">
2432  <first ref="APAFrameYCenter6"/>
2433  <second ref="ArapucaOut"/>
2434  <positionref ref="posPaddleSub7"/>
2435  </subtraction>
2436  <subtraction name="APAFrameYCenter8">
2437  <first ref="APAFrameYCenter7"/>
2438  <second ref="ArapucaOut"/>
2439  <positionref ref="posPaddleSub8"/>
2440  </subtraction>
2441  <subtraction name="APAFrameYCenter">
2442  <first ref="APAFrameYCenter8"/>
2443  <second ref="ArapucaOut"/>
2444  <positionref ref="posPaddleSub9"/>
2445  </subtraction>
2446 
2447  <box name="APAFrameZSideHollow" lunit="cm"
2448  x="$APAFrameZSideHollow_x"
2449  y="$APAFrameZSideHollow_y"
2450  z="$APAFrameZSide_z"/>
2451  <box name="APAFrameZSideShell" lunit="cm"
2452  x="$APAFrameZSide_x"
2453  y="$APAFrameZSide_y"
2454  z="$APAFrameZSide_z"/>
2455  <subtraction name="APAFrameZSide">
2456  <first ref="APAFrameZSideShell"/>
2457  <second ref="APAFrameZSideHollow"/>
2458  <positionref ref="posCenter"/>
2459  <rotationref ref="rIdentity"/>
2460  </subtraction>
2461 
2462  <box name="APAFrameYOuterSupport" lunit="cm"
2463  x="$EdgeFrameSteelThickness"
2464  y="$APAFrameYOuterSupport_y"
2465  z="$APAFrameYOuterSupport_z"/>
2466 
2467 
2468  <box name="G10BoardYSideCenterSeg" lunit="cm"
2469  x="$G10BoardYSide_x"
2470  y="$G10BoardYSide_y"
2471  z="$G10BoardYSide_z"/>
2472 
2473  <box name="G10BoardZSideCenterSeg" lunit="cm"
2474  x="$G10BoardZSide_x"
2475  y="$G10BoardZSide_y"
2476  z="$G10BoardZSide_z"/>
2477 
2478 </solids>
2479 EOF
2480 
2481 # Cryostat structure
2482 print CRYO <<EOF;
2483 <structure>
2484  <volume name="volSteelShell">
2485  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni" />
2486  <solidref ref="SteelShell" />
2487  </volume>
2488  <volume name="volGaseousArgon">
2489  <materialref ref="ArGas"/>
2490  <solidref ref="GaseousArgon"/>
2491  </volume>
2492 
2493  <volume name="volBeamPlugNi">
2494  <materialref ref="NiGas1atm80K"/>
2495  <solidref ref="BeamPlugNi_7"/>
2496  </volume>
2497  <volume name="volBeamPlugG10">
2498  <materialref ref="G10"/>
2499  <solidref ref="BeamPlug_7"/>
2500  <physvol>
2501  <volumeref ref="volBeamPlugNi"/>
2502  <position name="posBeamPlugNi" x="0" y="0" z="$BeamPlugNiPos_z" unit="cm"/>
2503  </physvol>
2504  </volume>
2505 
2506  <volume name="volBeamPlugERing">
2507  <materialref ref="ALUMINUM_Al"/>
2508  <solidref ref="BeamPlugERing"/>
2509  </volume>
2510 
2511  <volume name="volBeamPlugMod">
2512  <materialref ref="LAr"/>
2513  <solidref ref="BeamPlugMod"/>
2514  <physvol>
2515  <volumeref ref="volBeamPlugG10"/>
2516  <positionref ref="posCenter"/>
2517  </physvol>
2518 EOF
2519 
2520 for($i=0 ; $i<7 ; $i++){
2521 $BeamPlugERing_z = $BeamPlugERingPosZ + $i*5.7;
2522 print CRYO <<EOF;
2523  <physvol name="volBeamPlugERing_$i">
2524  <volumeref ref="volBeamPlugERing"/>
2525  <position name="posBeamPlugERing_$i" x="0" y="0" z="$BeamPlugERing_z" unit="cm"/>
2526  </physvol>
2527 EOF
2528 }
2529 print CRYO <<EOF;
2530  </volume>
2531 
2532  <volume name="volBePlFlangeNi">
2533  <materialref ref="NiGas1atm80K"/>
2534  <solidref ref="TubeBePlFlangeIn"/>
2535  </volume>
2536  <volume name="volBePlFlange">
2537  <materialref ref="G10"/>
2538  <solidref ref="BePlFlange"/>
2539  </volume>
2540  <volume name="volCathode">
2541  <materialref ref="G10" />
2542  <solidref ref="Cathode" />
2543  </volume>
2544 EOF
2545 
2546 for($i=0 ; $i<$nAPAs ; $i++){
2547 for($p=0 ; $p<10 ; $p++){
2548 if($p % 2 == 0){
2549 print CRYO <<EOF;
2550  <volume name="volOpDetSensitive_$i\-$p">
2551  <materialref ref="LAr"/>
2552  <solidref ref="LightPaddleIU"/>
2553  </volume>
2554 EOF
2555 print CRYO <<EOF;
2556  <volume name="volPaddleRail_$i\-$p">
2557  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2558  <solidref ref="PaddleRailIU"/>
2559  </volume>
2560 EOF
2561 }else{
2562 print CRYO <<EOF;
2563  <volume name="volOpDetSensitive_$i\-$p">
2564  <materialref ref="LAr"/>
2565  <solidref ref="LightPaddleMIT"/>
2566  </volume>
2567 EOF
2568 print CRYO <<EOF;
2569  <volume name="volPaddleRail_$i\-$p">
2570  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2571  <solidref ref="PaddleRailMIT"/>
2572  </volume>
2573 EOF
2574 }
2575 }
2576 }
2577 
2578 for($i=0 ; $i<$nAPAs ; $i++){
2579 if($i==$nAraAPA1 || $i==$nAraAPA2){
2580 print CRYO <<EOF;
2581  <volume name="volArapuca_$i">
2582  <materialref ref="G10" />
2583  <solidref ref="ArapucaWalls" />
2584  </volume>
2585 EOF
2586 for($p=0 ; $p<16 ; $p++){
2587 print CRYO <<EOF;
2588  <volume name="volOpDetSensitive_Arapuca_$i\-$p">
2589  <materialref ref="LAr"/>
2590  <solidref ref="ArapucaAcceptanceWindow"/>
2591  </volume>
2592 EOF
2593 }
2594 }
2595 }
2596 
2597 #### End wall field cage module
2598 print CRYO <<EOF;
2599  <volume name="volFCEWHorSuppBar">
2600  <materialref ref="FR4"/>
2601  <solidref ref="FCEWHorSuppBar"/>
2602  </volume>
2603  <volume name="volFCEWFieldBarPlane">
2604  <materialref ref="ALUMINUM_Al"/>
2605  <solidref ref="boxFCEWFieldShaping"/>
2606  </volume>
2607  <volume name="volFCEWVerSuppBar">
2608  <materialref ref="FR4"/>
2609  <solidref ref="boxFCEWVerSupp"/>
2610  </volume>
2611  <volume name="volFCEWmod">
2612  <materialref ref="LAr"/>
2613  <solidref ref="boxFCEWmod"/>
2614  <physvol name="volFCEWHorSuppBar-1">
2615  <volumeref ref="volFCEWHorSuppBar"/>
2616  <position name="posFCEWHorSuppBar-1" x="0" y="54.5" z="0" unit="cm"/>
2617  </physvol>
2618  <physvol name="volFCEWHorSuppBar-2">
2619  <volumeref ref="volFCEWHorSuppBar"/>
2620  <position name="posFCEWHorSuppBar-2" x="0" y="-54.5" z="0" unit="cm"/>
2621  </physvol>
2622  <physvol>
2623  <volumeref ref="volFCEWFieldBarPlane"/>
2624  <position name="posFCEWFieldBarPlane" x="0" y="0" z="2" unit="cm"/>
2625  </physvol>
2626  <physvol name="volFCEWVerSuppBar-1">
2627  <volumeref ref="volFCEWVerSuppBar"/>
2628  <position name="posFCEWVerSuppBar-1" x="-165.75" y="0" z="5.75" unit="cm"/>
2629  </physvol>
2630  <physvol name="volFCEWVerSuppBar-2">
2631  <volumeref ref="volFCEWVerSuppBar"/>
2632  <position name="posFCEWVerSuppBar-2" x="74.2" y="0" z="5.75" unit="cm"/>
2633  </physvol>
2634  <physvol name="volFCEWVerSuppBar-3">
2635  <volumeref ref="volFCEWVerSuppBar"/>
2636  <position name="posFCEWVerSuppBar-3" x="164.2" y="0" z="5.75" unit="cm"/>
2637  </physvol>
2638  <physvol name="volFCEWVerSuppBar-4">
2639  <volumeref ref="volFCEWVerSuppBar"/>
2640  <position name="posFCEWVerSuppBar-4" x="-165.75" y="0" z="-5.75" unit="cm"/>
2641  </physvol>
2642  <physvol name="volFCEWVerSuppBar-5">
2643  <volumeref ref="volFCEWVerSuppBar"/>
2644  <position name="posFCEWVerSuppBar-5" x="74.2" y="0" z="-5.75" unit="cm"/>
2645  </physvol>
2646  <physvol name="volFCEWVerSuppBar-6">
2647  <volumeref ref="volFCEWVerSuppBar"/>
2648  <position name="posFCEWVerSuppBar-6" x="164.2" y="0" z="-5.75" unit="cm"/>
2649  </physvol>
2650  </volume>
2651 
2652 
2653 EOF
2654 ##### Beam plug end wall module
2655 
2656 print CRYO <<EOF;
2657 
2658  <volume name="volFCEW-BP-FieldShaping">
2659  <materialref ref="ALUMINUM_Al"/>
2660  <solidref ref="FCEW-BP-FieldShaping"/>
2661  </volume>
2662  <volume name="volFCEW-BPFla">
2663  <materialref ref="FR4"/>
2664  <solidref ref="FCEW-BPFla"/>
2665  </volume>
2666  <volume name="volFCEW-BPVer">
2667  <materialref ref="FR4"/>
2668  <solidref ref="FCEW-BPVer"/>
2669  </volume>
2670 
2671  <volume name="volFCEW-BP-mod">
2672  <materialref ref="LAr"/>
2673  <solidref ref="boxFCEW-BP-mod"/>
2674  <physvol name="volFCEW-BP-HorSuppBar-1">
2675  <volumeref ref="volFCEWHorSuppBar"/>
2676  <position name="posFCEW-BP-HorSuppBar-1" x="0" y="64.5" z="0" unit="cm"/>
2677  </physvol>
2678  <physvol name="volFCEW-BP-HorSuppBar-2">
2679  <volumeref ref="volFCEWHorSuppBar"/>
2680  <position name="posFCEW-BP-HorSuppBar-2" x="0" y="-54.5" z="0" unit="cm"/>
2681  </physvol>
2682  <physvol>
2683  <volumeref ref="volFCEW-BP-FieldShaping"/>
2684  <position name="posFCEW-BP-FieldShaping" x="0" y="0" z="2" unit="cm"/>
2685  </physvol>
2686  <physvol name="volFCEW-BP-VerSuppBar-1">
2687  <volumeref ref="volFCEWVerSuppBar"/>
2688  <position name="posFCEW-BP-VerSuppBar-1" x="-74.2" y="0" z="5.75" unit="cm"/>
2689  </physvol>
2690  <physvol name="volFCEW-BP-VerSuppBar-2">
2691  <volumeref ref="volFCEWVerSuppBar"/>
2692  <position name="posFCEW-BP-VerSuppBar-2" x="-164.2" y="0" z="5.75" unit="cm"/>
2693  </physvol>
2694  <physvol name="volFCEW-BP-VerSuppBar-3">
2695  <volumeref ref="volFCEWVerSuppBar"/>
2696  <position name="posFCEW-BP-VerSuppBar-3" x="-74.2" y="0" z="-5.75" unit="cm"/>
2697  </physvol>
2698  <physvol name="volFCEW-BP-VerSuppBar-4">
2699  <volumeref ref="volFCEWVerSuppBar"/>
2700  <position name="posFCEW-BP-VerSuppBar-4" x="-164.2" y="0" z="-5.75" unit="cm"/>
2701  </physvol>
2702  <physvol name="volFCEW-BP-VerSuppBar-5">
2703  <volumeref ref="volFCEWVerSuppBar"/>
2704  <position name="posFCEW-BP-VerSuppBar-5" x="122.5" y="0" z="-5.75" unit="cm"/>
2705  </physvol>
2706  <physvol>
2707  <volumeref ref="volFCEW-BPVer"/>
2708  <position name="posFCEW-BPVer" x="169.4" y="0" z="-5.75" unit="cm"/>
2709  </physvol>
2710  </volume>
2711 
2712 EOF
2713 
2714 ##### Top and bottom field cage module volume
2715 
2716 print CRYO <<EOF;
2717 
2718  <volume name="volFCXBarOut">
2719  <materialref ref="FR4"/>
2720  <solidref ref="FCXBarOut"/>
2721  </volume>
2722  <volume name="volFCZBar">
2723  <materialref ref="FR4"/>
2724  <solidref ref="FCZBar"/>
2725  </volume>
2726  <volume name="volFCFieldBarPlane">
2727  <materialref ref="ALUMINUM_Al"/>
2728  <solidref ref="boxFCFieldBarPlane"/>
2729  </volume>
2730  <volume name="volShieldPlate">
2731  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2732  <solidref ref="boxShieldPlate"/>
2733  </volume>
2734  <volume name="volFCMod">
2735  <materialref ref="LAr"/>
2736  <solidref ref="boxFCMod"/>
2737  <physvol name="volFCXBarOut-1">
2738  <volumeref ref="volFCXBarOut"/>
2739  <position name="posFCXBarOut-1" x="0" y="-6.1" z="58" unit="cm"/>
2740  </physvol>
2741  <physvol name="volFCXBarOut-2">
2742  <volumeref ref="volFCXBarOut"/>
2743  <position name="posFCXBarOut-2" x="0" y="-6.1" z="-58" unit="cm"/>
2744  </physvol>
2745  <physvol>
2746  <volumeref ref="volFCFieldBarPlane"/>
2747  <position name="posFCFieldBarPlane" x="0" y="-9.4" z="0" unit="cm"/>
2748  </physvol>
2749  <physvol name="volFCZBar-1">
2750  <volumeref ref="volFCZBar"/>
2751  <position name="posFCZBar-1" x="141.6" y="-4.1" z="0" unit="cm"/>
2752  </physvol>
2753  <physvol name="volFCZBar-2">
2754  <volumeref ref="volFCZBar"/>
2755  <position name="posFCZBar-2" x="-41" y="-4.1" z="0" unit="cm"/>
2756  </physvol>
2757  <physvol name="volFCZBar-3">
2758  <volumeref ref="volFCZBar"/>
2759  <position name="posFCZBar-3" x="-143.5" y="-4.1" z="0" unit="cm"/>
2760  </physvol>
2761  <physvol>
2762  <volumeref ref="volShieldPlate"/>
2763  <position name="posShieldPlate" x="44" y="12.7" z="0" unit="cm"/>
2764  </physvol>
2765  </volume>
2766 EOF
2767 
2768 
2769 $posGaseousArgon_y = $Argon_y/2-$HeightGaseousAr/2;
2770 $BePlFlangeNi_z = $BePlFlange_z - 0.2;
2771 print CRYO <<EOF;
2772 
2773  <volume name="volAPAFrameYSide">
2774  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2775  <solidref ref="APAFrameYSide"/>
2776  </volume>
2777 
2778  <volume name="volAPAFrameYCenter">
2779  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2780  <solidref ref="APAFrameYCenter"/>
2781  </volume>
2782 
2783  <volume name="volAPAFrameZSide">
2784  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2785  <solidref ref="APAFrameZSide"/>
2786  </volume>
2787 
2788  <volume name="volAPAFrameYOuterSupport">
2789  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2790  <solidref ref="APAFrameYOuterSupport"/>
2791  </volume>
2792 
2793  <volume name="volG10BoardYSideCenterSeg">
2794  <materialref ref="G10"/>
2795  <solidref ref="G10BoardYSideCenterSeg"/>
2796  </volume>
2797 
2798  <volume name="volG10BoardZSideCenterSeg">
2799  <materialref ref="G10"/>
2800  <solidref ref="G10BoardZSideCenterSeg"/>
2801  </volume>
2802 
2803  <volume name="volCryostat">
2804  <materialref ref="LAr" />
2805  <solidref ref="Cryostat" />
2806  <physvol>
2807  <volumeref ref="volGaseousArgon"/>
2808  <position name="posGaseousArgon" unit="cm" x="0" y="$posGaseousArgon_y" z="0"/>
2809  </physvol>
2810  <physvol>
2811  <volumeref ref="volSteelShell"/>
2812  <position name="posSteelShell" unit="cm" x="0" y="0" z="0"/>
2813  </physvol>
2814  <physvol>
2815  <volumeref ref="volBeamPlugMod"/>
2816  <positionref ref="posBeamWAr3"/>
2817  <rotationref ref="rBeamWRev3"/>
2818  </physvol>
2819  <physvol>
2820  <volumeref ref="volBePlFlange"/>
2821  <position name="posBePlFlange" unit="cm" x="$BePlFlange_x" y="$BePlFlange_y" z="$BePlFlange_z"/>
2822  </physvol>
2823  <physvol>
2824  <volumeref ref="volBePlFlangeNi"/>
2825  <position name="posBePlFlangeNi" x="$BePlFlange_x" y="$BePlFlange_y" z="$BePlFlangeNi_z" unit="cm"/>
2826  </physvol>
2827 
2828 EOF
2829 print "Beam Plug position x=".$BePlFlange_x." y=".$BePlFlange_y." z=".$BePlFlange_z."\n";
2830 # nested for loops to place the non-rotated AND rotated volTPC
2831  # x loop rotation: There are six drift volumes. Looking into the
2832  # detector from incident direction, and counting from right (-x) to
2833  # left (+x), odd number volumes need to be rotated 180deg about Y in
2834  # order for the cathode to be on the right of the APA.
2835 
2836 if ($tpc_on==1) {
2837 
2838  $apa_i=0;
2839  $cpa_i=0;
2840 
2841  for($k=0 ; $k<$nAPALong ; $k++)
2842  {
2843  $APACenter_z = - $Argon_z/2
2844  + $UpstreamLArPadding
2845  + $APAphys_z/2
2846  + $k*($APAphys_z+$APAGap_z);
2847 
2848 
2849  for($j=0 ; $j<$nAPAHigh ; $j++) # nAPAHigh always going to be 2
2850  { # $j=0 for bottom APAs
2851  # $j=1 for top APAs
2852  $APACenter_y = - $Argon_y/2 + $SpaceAPAToFloor
2853  + $APAphys_y/2
2854  + $j*($APAphys_y+$APAGap_y);
2855 
2856  if( $workspace == 0 )
2857  {
2858 
2859  for($i=0 ; $i<$nAPAWide ; $i++)
2860  {
2861 
2862  $APACenter_x = - $Argon_x/2
2863  + $SpaceAPAToCryoWall + $APA_UtoU_x/2 + $TPCWirePlaneThickness/2
2864  + $i*$APAToAPA;
2865 
2866  $CPA_x = $APACenter_x + $CPAToAPA;
2867 # print "$i".", $nAPAWide".", CPA_x = $CPA_x"."\n";
2868 
2869  place_APA($APACenter_x, $APACenter_y, $APACenter_z, $apa_i, $j);
2870  place_OpDets($APACenter_x, $APACenter_y, $APACenter_z, $apa_i);
2871  $tpc_0 = 2*$apa_i+0;
2872  $tpc_1 = 2*$apa_i+1;
2873  $apa_i++;
2874 
2875  $SelectTPC_0 = "Inner";
2876  $SelectTPC_1 = "Inner";
2877  $TPC_0_x = $TPCInner_x;
2878  $TPC_1_x = $TPCInner_x;
2879  $rot_0 = "rPlus180AboutY";
2880  $rot_1 = "rIdentity";
2881  if($i == 0) { $SelectTPC_0 = "Outer"; $TPC_0_x = $TPCOuter_x; }
2882  if($i == $nAPAWide-1) { $SelectTPC_1 = "Outer"; $TPC_1_x = $TPCOuter_x; }
2883  if($j == 0) { $rot_0 = "rPlus180AboutXPlus180AboutY";
2884  $rot_1 = "rPlus180AboutX"; } #put the readout end at the bottom for bottom APAs
2885 
2886 
2887 $posvolTPC0_x = $APACenter_x - $APAFrame_x/2 - $TPC_0_x/2;
2888 $posvolTPC1_x = $APACenter_x + $APAFrame_x/2 + $TPC_1_x/2;
2889 print CRYO <<EOF;
2890 
2891  <physvol>
2892  <volumeref ref="volTPC$SelectTPC_0"/>
2893  <position name="posTPC\-$tpc_0" unit="cm"
2894  x="$posvolTPC0_x"
2895  y="$APACenter_y"
2896  z="$APACenter_z"/>
2897  <rotationref ref="$rot_0"/>
2898  </physvol>
2899  <physvol>
2900  <volumeref ref="volTPC$SelectTPC_1"/>
2901  <position name="posTPC\-$tpc_1" unit="cm"
2902  x="$posvolTPC1_x"
2903  y="$APACenter_y"
2904  z="$APACenter_z"/>
2905  <rotationref ref="$rot_1"/>
2906  </physvol>
2907 
2908 EOF
2909 
2910 
2911 if( $i < $nAPAWide - 1 ){ # avoid placeing the last row of CPAs since the APAs are on the outside
2912 
2913 print "$cpa_i".". CPA_x = $CPA_x".", APACenter_y = $APACenter_y".", APACenter_z = $APACenter_z"."\n";
2914 $CPAmodbarGap = 1.8*$inch;
2915 $FCmodRight_x[$cpa_i] = $CPA_x + 3 + 352/2; # CPAmodCenter_x to FCmodCenter_x
2916 $FCmodLeft_x[$cpa_i] = $CPA_x - 3 - 352/2;
2917 $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
2918 $FCmodBottom_y[$cpa_i] = $APACenter_y - 603.3/2 - $CPAmodbarGap - 9.4 - 1.83;
2919 $FCmod_z[$cpa_i] = $APACenter_z;
2920 
2921 $FCEWmodRight_x = $CPA_x + 3 + 354.3/2;
2922 $FCEWmodLeft_x = $CPA_x - 3 - 354.3/2;
2923 if($cpa_i == 0) {
2924  $FCEWmodUS_z = $APACenter_z - 231.5/2 - $CPAmodbarGap - 2; #CPAmodCenter_z to FCEWmod
2925  for($fcewy_i = 0; $fcewy_i < 4; $fcewy_i++){
2926 
2927  $FCEWmod_y[$fcewy_i] = $APACenter_y + (-3 + 2*$fcewy_i)*77; #distance between FCEW module is 2.8 cm (originally 0.8 cm)
2928 
2929  }
2930 }
2931 if($cpa_i == 2) {
2932  $FCEWmodDS_z = $APACenter_z + 231.5/2 + $CPAmodbarGap + 2;
2933 }
2934 
2935 print CRYO <<EOF;
2936  <physvol>
2937  <volumeref ref="volCathode"/>
2938  <position name="posCathode\-$cpa_i" unit="cm"
2939  x="$CPA_x"
2940  y="$APACenter_y"
2941  z="$APACenter_z"/>
2942  <rotationref ref="rIdentity"/>
2943  </physvol>
2944  <physvol name="volFCModTopRight\-$cpa_i">
2945  <volumeref ref="volFCMod"/>
2946  <position name="posFCModTopRight\-$cpa_i" unit="cm"
2947  x="$FCmodRight_x[$cpa_i]"
2948  y="$FCmodTop_y[$cpa_i]"
2949  z="$FCmod_z[$cpa_i]"/>
2950  <rotationref ref="rPlus180AboutY"/>
2951  </physvol>
2952  <physvol name="volFCModTopLeft\-$cpa_i">
2953  <volumeref ref="volFCMod"/>
2954  <position name="posFCModTopLeft\-$cpa_i" unit="cm"
2955  x="$FCmodLeft_x[$cpa_i]"
2956  y="$FCmodTop_y[$cpa_i]"
2957  z="$FCmod_z[$cpa_i]"/>
2958  <rotationref ref="rIdentity"/>
2959  </physvol>
2960  <physvol name="volFCModBottomRight\-$cpa_i">
2961  <volumeref ref="volFCMod"/>
2962  <position name="posFCModBottomRight\-$cpa_i" unit="cm"
2963  x="$FCmodRight_x[$cpa_i]"
2964  y="$FCmodBottom_y[$cpa_i]"
2965  z="$FCmod_z[$cpa_i]"/>
2966  <rotationref ref="rPlus180AboutXPlus180AboutY"/>
2967  </physvol>
2968  <physvol name="volFCModBottomLeft\-$cpa_i">
2969  <volumeref ref="volFCMod"/>
2970  <position name="posFCModBottomLeft\-$cpa_i" unit="cm"
2971  x="$FCmodLeft_x[$cpa_i]"
2972  y="$FCmodBottom_y[$cpa_i]"
2973  z="$FCmod_z[$cpa_i]"/>
2974  <rotationref ref="rPlus180AboutX"/>
2975  </physvol>
2976 
2977 
2978 
2979 EOF
2980  $cpa_i++;
2981 }
2982 
2983 ################################## End Wall Field Cage Placement
2984 
2985 
2986  } #wide
2987 
2988 
2989 
2990  } # end if not the smaller workspace
2991 
2992 
2993  # Make the workspace have only one center APA with CPAs and the full drift on either side
2994  elsif( $workspace == 1 ){
2995 
2996  $APACenter_x = 0;
2997  $CPA_0_x = $APACenter_x - $CPAToAPA;
2998  $CPA_1_x = $APACenter_x + $CPAToAPA;
2999 
3000 
3001  place_APA($APACenter_x, $APACenter_y, $APACenter_z, $apa_i, $j);
3002  place_OpDets($APACenter_x, $APACenter_y, $APACenter_z, $apa_i);
3003 
3004  $tpc_0 = 2*$apa_i+0;
3005  $tpc_1 = 2*$apa_i+1;
3006  $apa_i++;
3007 
3008  $rot_0 = "rPlus180AboutY";
3009  $rot_1 = "rIdentity";
3010  if($j == 0) { $rot_0 = "rPlus180AboutXPlus180AboutY";
3011  $rot_1 = "rPlus180AboutX"; } #put the readout end at the bottom for bottom APAs
3012 
3013 $posvolTPCInner0_x = $APACenter_x - $APAFrame_x/2 - $TPCInner_x/2;
3014 $posvolTPCInner1_x = $APACenter_x + $APAFrame_x/2 + $TPCInner_x/2;
3015 print CRYO <<EOF;
3016 
3017  <physvol>
3018  <volumeref ref="volTPCInner"/>
3019  <position name="posTPC\-$tpc_0" unit="cm"
3020  x="$posvolTPCInner0_x"
3021  y="$APACenter_y"
3022  z="$APACenter_z"/>
3023  <rotationref ref="$rot_0"/>
3024  </physvol>
3025  <physvol>
3026  <volumeref ref="volTPCInner"/>
3027  <position name="posTPC\-$tpc_1" unit="cm"
3028  x="$posvolTPCInner1_x"
3029  y="$APACenter_y"
3030  z="$APACenter_z"/>
3031  <rotationref ref="$rot_1"/>
3032  </physvol>
3033 
3034  <physvol>
3035  <volumeref ref="volCathode"/>
3036  <position name="posCathode\-$apa_i-0" unit="cm"
3037  x="$CPA_0_x"
3038  y="$APACenter_y"
3039  z="$APACenter_z"/>
3040  <rotationref ref="rIdentity"/>
3041  </physvol>
3042  <physvol>
3043  <volumeref ref="volCathode"/>
3044  <position name="posCathode\-$apa_i-1" unit="cm"
3045  x="$CPA_1_x"
3046  y="$APACenter_y"
3047  z="$APACenter_z"/>
3048  <rotationref ref="rIdentity"/>
3049  </physvol>
3050 
3051 EOF
3052 
3053  } # if the smaller workspace
3054 
3055 
3056  } #high
3057  } #long
3058 
3059 }# end if tpc
3060 
3061 for($fcewy_i = 0; $fcewy_i < 4; $fcewy_i++){
3062 if($fcewy_i !=2){
3063 print CRYO <<EOF;
3064  <physvol name="volFCEWModUSLeft\-$fcewy_i">
3065  <volumeref ref="volFCEWmod"/>
3066  <position name="posFCEWModUSLeft\-$fcewy_i" unit="cm"
3067  x="$FCEWmodLeft_x"
3068  y="$FCEWmod_y[$fcewy_i]"
3069  z="$FCEWmodUS_z"/>
3070  <rotationref ref="rPlus180AboutZ"/>
3071  </physvol>
3072 EOF
3073 }
3074 print CRYO <<EOF;
3075  <physvol name="volFCEWModUSRight\-$fcewy_i">
3076  <volumeref ref="volFCEWmod"/>
3077  <position name="posFCEWModUSRight\-$fcewy_i" unit="cm"
3078  x="$FCEWmodRight_x"
3079  y="$FCEWmod_y[$fcewy_i]"
3080  z="$FCEWmodUS_z"/>
3081  <rotationref ref="rIdentity"/>
3082  </physvol>
3083  <physvol name="volFCEWModDSRight\-$fcewy_i">
3084  <volumeref ref="volFCEWmod"/>
3085  <position name="posFCEWModDSRight\-$fcewy_i" unit="cm"
3086  x="$FCEWmodRight_x"
3087  y="$FCEWmod_y[$fcewy_i]"
3088  z="$FCEWmodDS_z"/>
3089  <rotationref ref="rPlus180AboutX"/>
3090  </physvol>
3091  <physvol name="volFCEWModDSLeft\-$fcewy_i">
3092  <volumeref ref="volFCEWmod"/>
3093  <position name="posFCEWModDSLeft\-$fcewy_i" unit="cm"
3094  x="$FCEWmodLeft_x"
3095  y="$FCEWmod_y[$fcewy_i]"
3096  z="$FCEWmodDS_z"/>
3097  <rotationref ref="rPlus180AboutXPlus180AboutZ"/>
3098  </physvol>
3099 EOF
3100 }
3101 
3102 $FCEWBPmod_x = $FCEWmodLeft_x + 2.8;
3103 $FCEWBPmod_y = $FCEWmod_y[2] + 0.9;
3104 $FCEWBPmod_z = $FCEWmodUS_z;
3105 
3106 $FCEWBPFla_x = $FCEWBPmod_x + 147.8;
3107 $FCEWBPFla_y = $FCEWBPmod_y + 0;
3108 $FCEWBPFla_z = $FCEWBPmod_z + 5.75;
3109 
3110 print "volFCEW-BPFla pos x=".$FCEWBPFla_x." y=".$FCEWBPFla_y." z=".$FCEWBPFla_z."\n";
3111 
3112 print CRYO <<EOF;
3113  <physvol>
3114  <volumeref ref="volFCEW-BP-mod"/>
3115  <position name="posFCEW-BP-mod" unit="cm"
3116  x="$FCEWBPmod_x"
3117  y="$FCEWBPmod_y"
3118  z="$FCEWBPmod_z"/>
3119  </physvol>
3120 
3121  <physvol>
3122  <volumeref ref="volFCEW-BPFla"/>
3123  <position name="posFCEW-BPFla" unit="cm"
3124  x="$FCEWBPFla_x"
3125  y="$FCEWBPFla_y"
3126  z="$FCEWBPFla_z"/>
3127  </physvol>
3128 EOF
3129 
3130 print CRYO <<EOF;
3131  </volume>
3132 </structure>
3133 </gdml>
3134 EOF
3135 
3136 close(CRYO);
3137 }
3138 
3139 
3140 
3141 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3142 #++++++++++++++++++++++++++++++++++++ place_OpDets +++++++++++++++++++++++++++++++++++++++
3143 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3144 
3145 sub place_OpDets()
3146 {
3147 
3148  $APACenter_x = $_[0];
3149  $APACenter_y = $_[1];
3150  $APACenter_z = $_[2];
3151  $apa_i = $_[3];
3152 
3153  $test = 0;
3154 
3155 for ($paddle = 0; $paddle<$nLightPaddlesPerAPA; $paddle++)
3156 {
3157 
3158  # All Light Paddle centers will have the same
3159  # X coordinate as the center of the current APA
3160  # Z coordinate as the current TPC pair
3161  # The Y coordinate must be looped over:
3162 
3163  #the multiplication by j here is a temporary dirty trick to get around some strange behavior
3164 
3165  $Paddle_Y = $APACenter_y
3166  - $APAphys_y/2
3167  + $FrameToPaddleSpace
3168  + (1-$j)*($LightPaddleMIT_y/2)
3169  + $PaddleYInterval*$paddle;
3170 
3171  if($apa_i==$nAraAPA1){
3172  if($paddle==$nSlotAra1) {$test=1;}
3173  } #where the arapuca bar goes for pDUNE
3174  if($apa_i==$nAraAPA2){
3175  if($paddle==$nSlotAra2) {$test=1;}
3176  }
3177 
3178  if(($test!=1)){
3179  # Alternate the paddle orientations
3180  if ( $paddle % 2 == 0 ) { $rot = "rIdentity"; }
3181  else { $rot = "rPlus180AboutY"; }
3182 
3183  $posvolRail_z = $APACenter_z + $SiPM_z/2;
3184 
3185  if ( $paddle % 2 == 0 ) { $posvolOpDetSensitive_z = $APACenter_z + $SiPM_z/2 - 4.80425; } #IU bar
3186  else { $posvolOpDetSensitive_z = $APACenter_z + $SiPM_z/2 + 2.87875; }
3187 
3188  print CRYO <<EOF;
3189  <physvol>
3190  <volumeref ref="volOpDetSensitive_$apa_i\-$paddle"/>
3191  <position name="posPaddle\-$paddle\-TPC\-$i\-$j\-$k" unit="cm"
3192  x="$APACenter_x"
3193  y="$Paddle_Y"
3194  z="$posvolOpDetSensitive_z"/>
3195  <rotationref ref="$rot"/>
3196  </physvol>
3197 EOF
3198 
3199  print CRYO <<EOF;
3200  <physvol>
3201  <volumeref ref="volPaddleRail_$apa_i\-$paddle"/>
3202  <position name="posPaddleRail\-$paddle\-TPC\-$i\-$j\-$k" unit="cm"
3203  x="$APACenter_x"
3204  y="$Paddle_Y"
3205  z="$posvolRail_z"/>
3206  <rotationref ref="$rot"/>
3207  </physvol>
3208 EOF
3209 
3210 $test = 0;
3211  }else{
3212  if ( $apa_i % 2 == 0 ) {
3213  $rot = "rIdentity";
3214  $posArax = ($APACenter_x+0.05*$ArapucaOut_x-0.05*$ArapucaAcceptanceWindow_x-0.01);
3215  }else{
3216  $rot = "rPlus180AboutY";
3217  $posArax = ($APACenter_x-0.05*$ArapucaOut_x+0.05*$ArapucaAcceptanceWindow_x+0.01);
3218  }
3219 
3220  print CRYO <<EOF;
3221  <physvol>
3222  <volumeref ref="volArapuca_$apa_i"/>
3223  <position name="posArapuca$apa_i-TPC\-$i\-$j\-$k" unit="cm"
3224  x="@{[$APACenter_x]}"
3225  y="@{[$Paddle_Y]}"
3226  z="@{[$APACenter_z]}"/>
3227  <rotationref ref="$rot"/>
3228  </physvol>
3229 EOF
3230  for ($ara = 0; $ara<16; $ara++){
3231  print CRYO <<EOF;
3232  <physvol>
3233  <volumeref ref="volOpDetSensitive_Arapuca_$apa_i\-$ara"/>
3234  <position name="posOpArapuca$apa_i\-$ara\-TPC\-$i\-$j\-$k" unit="cm"
3235  x="@{[$posArax]}"
3236  y="@{[$Paddle_Y]}"
3237  z="@{[(0.1*$list_pos[$ara]+$APACenter_z)]}"/>
3238  </physvol>
3239 EOF
3240 }
3241 $test = 0;
3242 }
3243 }#end Paddle for-loop
3244 
3245 }
3246 
3247 
3248 
3249 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3250 #++++++++++++++++++++++++++++++++++++++ place_APA ++++++++++++++++++++++++++++++++++++++++
3251 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3252 
3253 
3254 # Must be called only within gen_Cryostat(),
3255 
3256 
3257 # $_[0] = x APA physical center
3258 # $_[1] = y APA physical center
3259 # $_[2] = z APA physical center
3260 # $_[3] = APA number
3261 # $_[4] = 0 for APA with readout on bottom
3262 # 1 for APA with readout on top
3263 
3264 sub place_APA()
3265 {
3266 
3267  $APA_i = $_[3];
3268 
3269 ####################################################################
3270 ################# APA Frame and Paddle Dimensions ##################
3271 
3272 # The center passed to this function is the physical APA center,
3273 # which is not quite the frame's center, since there are more boards
3274 # at the bottom. Transform them:
3275 
3276  $APAFrameCenter_x = $_[0];
3277  $APAFrameCenter_z = $_[2];
3278 
3279 # The bottom APAs are upside down relative to how the TPC is initially generated,
3280 # and the center needs to be slightly shifted since there is extra G10 on the
3281 # end that doesn't read out.
3282 
3283  if($_[4]==1) # top APAs
3284  {
3285  $APAFrameCenter_y = $_[1] - $APAphys_y/2
3286  + $WrapCover + 4*$G10thickness
3287  + $APAFrame_y/2;
3288  }
3289  elsif($_[4]==0) # bottom APAs
3290  {
3291  $APAFrameCenter_y = $_[1] + $APAphys_y/2
3292  - $WrapCover - 4*$G10thickness
3293  - $APAFrame_y/2;
3294  }
3295  else{ print "APA not labeled as top or bottom"; }
3296 
3297 $APAFrameZSide_x = $APAFrame_x;
3298 $APAFrameZSide_y = 4*$inch;
3299 $APAFrameZSide_z = $APAFrame_z;
3300 
3301 $APAFrameYSide_x = $APAFrame_x;
3302 $APAFrameYSide_y = $APAFrame_y-2*$APAFrameZSide_y;
3303 $APAFrameYSide_z = 4*$inch;
3304 
3305 # Two outer Y supports will sandwich the light paddles
3306 $APAFrameYOuterSupport_x = ($APAFrame_x-$LightPaddle_x)/2;
3307 $APAFrameYOuterSupport_y = $APAFrame_y-2*$APAFrameZSide_y;
3308 $APAFrameYOuterSupport_z = 4*$inch;
3309 
3310 # if there were an inner support to fill the hole
3311 $APAFrameYInnerSupport_x = $LightPaddle_x;
3312 
3313 $EdgeFrameSteelThickness = 0.12*$inch;
3314 $InnerFrameSteelThickness = 0.062*$inch;
3315 
3316 
3317 $G10BoardYSide_x = $APAFrame_x;
3318 $G10BoardYSide_y = $APAFrame_y;
3319 $G10BoardYSide_z = $G10thickness;
3320 
3321 $G10BoardZSide_x = $APAFrame_x;
3322 $G10BoardZSide_y = $G10thickness;
3323 $G10BoardZSide_z = $APAFrame_z;
3324 
3325 if($_[4]==1) # top APAs
3326 {
3327  $posG10ZSideZ_y = $APAFrameCenter_y - $APAFrame_y/2 - (0+.5)*($G10BoardZSide_y);
3328  $posG10ZSideV_y = $APAFrameCenter_y - $APAFrame_y/2 - (1+.5)*($G10BoardZSide_y);
3329  $posG10ZSideU_y = $APAFrameCenter_y - $APAFrame_y/2 - (2+.5)*($G10BoardZSide_y);
3330  $posG10ZSideGrid_y = $APAFrameCenter_y - $APAFrame_y/2 - (3+.5)*($G10BoardZSide_y);
3331 }
3332 elsif($_[4]==0) # bottom APAs
3333 {
3334  $posG10ZSideZ_y = $APAFrameCenter_y + $APAFrame_y/2 + (0+.5)*($G10BoardZSide_y);
3335  $posG10ZSideV_y = $APAFrameCenter_y + $APAFrame_y/2 + (1+.5)*($G10BoardZSide_y);
3336  $posG10ZSideU_y = $APAFrameCenter_y + $APAFrame_y/2 + (2+.5)*($G10BoardZSide_y);
3337  $posG10ZSideGrid_y = $APAFrameCenter_y + $APAFrame_y/2 + (3+.5)*($G10BoardZSide_y);
3338 }
3339 else{ print "APA not labeled as top or bottom"; }
3340 
3341  # First put in the frame
3342 # print CRYO <<EOF;
3343 #<!--
3344 # <physvol>
3345 # <volumeref ref="volAPAFrameYOuterSupport\-$APA_i"/>
3346 # <position name="posAPAFrameYOuterSupportNeg\-$APA_i" unit="cm"
3347 # x="$APAFrameCenter_x - ($APAFrameYOuterSupport_x + $APAFrameYInnerSupport_x/2 - $EdgeFrameSteelThickness/2)"
3348 # y="$APAFrameCenter_y"
3349 # z="$APAFrameCenter_z"/>
3350 # <rotationref ref="rIdentity"/>
3351 # </physvol>
3352 # <physvol>
3353 # <volumeref ref="volAPAFrameYOuterSupport\-$APA_i"/>
3354 # <position name="posAPAFrameYOuterSupportPos\-$APA_i" unit="cm"
3355 # x="$APAFrameCenter_x + ($APAFrameYOuterSupport_x + $APAFrameYInnerSupport_x/2 - $EdgeFrameSteelThickness/2)"
3356 # y="$APAFrameCenter_y"
3357 # z="$APAFrameCenter_z"/>
3358 # <rotationref ref="rIdentity"/>
3359 # </physvol>
3360 #-->
3361 #EOF
3362 
3363  $posvolAPAFrameYSideNeg_z = $APAFrameCenter_z - $APAFrame_z/2 + $APAFrameYSide_z/2;
3364  $posvolAPAFrameYSidePos_z = $APAFrameCenter_z + $APAFrame_z/2 - $APAFrameYSide_z/2;
3365  $posvolAPAFrameZSidePos_y = $APAFrameCenter_y + $APAFrame_y/2 - $APAFrameZSide_y/2;
3366  $posvolAPAFrameZSideNeg_y = $APAFrameCenter_y - $APAFrame_y/2 + $APAFrameZSide_y/2;
3367  print CRYO <<EOF;
3368  <physvol>
3369  <volumeref ref="volAPAFrameYSide"/>
3370  <position name="posAPAFrameYSideNeg\-$APA_i" unit="cm"
3371  x="$APAFrameCenter_x"
3372  y="$APAFrameCenter_y"
3373  z="$posvolAPAFrameYSideNeg_z"/>
3374  <rotationref ref="rIdentity"/>
3375  </physvol>
3376  <physvol>
3377  <volumeref ref="volAPAFrameYSide"/>
3378  <position name="posAPAFrameYSidePos\-$APA_i" unit="cm"
3379  x="$APAFrameCenter_x"
3380  y="$APAFrameCenter_y"
3381  z="$posvolAPAFrameYSidePos_z"/>
3382  <rotationref ref="rIdentity"/>
3383  </physvol>
3384  <physvol>
3385  <volumeref ref="volAPAFrameYCenter"/>
3386  <position name="posFrameYCenter$apa_i" unit="cm"
3387  x="$APAFrameCenter_x"
3388  y="$APAFrameCenter_y"
3389  z="$APAFrameCenter_z"/>
3390  </physvol>
3391  <physvol>
3392  <volumeref ref="volAPAFrameZSide"/>
3393  <position name="posAPAFrameZSidePos\-$APA_i" unit="cm"
3394  x="$APAFrameCenter_x"
3395  y="$posvolAPAFrameZSidePos_y"
3396  z="$APAFrameCenter_z"/>
3397  <rotationref ref="rIdentity"/>
3398  </physvol>
3399  <physvol>
3400  <volumeref ref="volAPAFrameZSide"/>
3401  <position name="posAPAFrameZSideNeg\-$APA_i" unit="cm"
3402  x="$APAFrameCenter_x"
3403  y="$posvolAPAFrameZSideNeg_y"
3404  z="$APAFrameCenter_z"/>
3405  <rotationref ref="rIdentity"/>
3406  </physvol>
3407 
3408 
3409  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3410  - Add the *parts* of the G10 boards that exist directly in volCryostat.
3411  - There are two boards on each the up and downstream end,
3412  one each to wrap the U and V views around the APA frame
3413  - There are 4 on the bottom which anchor the U V and Z wires and the grid plane
3414  - The rest of the parts of the G10 boards must be placed directly in volTPC -->
3415 EOF
3416 
3417  $posvolG10BoardYSideCenterSegVup_z = $APAFrameCenter_z - $APAFrame_z/2 - (0+.5)*($G10BoardYSide_z);
3418  $posvolG10BoardYSideCenterSegUup_z = $APAFrameCenter_z - $APAFrame_z/2 - (1+.5)*($G10BoardYSide_z);
3419  $posvolG10BoardYSideCenterSegVdo_z = $APAFrameCenter_z + $APAFrame_z/2 + (0+.5)*($G10BoardYSide_z);
3420  $posvolG10BoardYSideCenterSegUdo_z = $APAFrameCenter_z + $APAFrame_z/2 + (1+.5)*($G10BoardYSide_z);
3421  print CRYO <<EOF;
3422  <physvol>
3423  <volumeref ref="volG10BoardYSideCenterSeg"/>
3424  <position name="posG10BoardYSideCenterSeg\-Vup\-$APA_i" unit="cm"
3425  x="$APAFrameCenter_x"
3426  y="$APAFrameCenter_y"
3427  z="$posvolG10BoardYSideCenterSegVup_z"/>
3428  <rotationref ref="rIdentity"/>
3429  </physvol>
3430  <physvol>
3431  <volumeref ref="volG10BoardYSideCenterSeg"/>
3432  <position name="posG10BoardYSideCenterSeg\-Uup\-$APA_i" unit="cm"
3433  x="$APAFrameCenter_x"
3434  y="$APAFrameCenter_y"
3435  z="$posvolG10BoardYSideCenterSegUup_z"/>
3436  <rotationref ref="rIdentity"/>
3437  </physvol>
3438 
3439  <physvol>
3440  <volumeref ref="volG10BoardYSideCenterSeg"/>
3441  <position name="posG10BoardYSideCenterSeg\-Vdown\-$APA_i" unit="cm"
3442  x="$APAFrameCenter_x"
3443  y="$APAFrameCenter_y"
3444  z="$posvolG10BoardYSideCenterSegVdo_z"/>
3445  <rotationref ref="rIdentity"/>
3446  </physvol>
3447  <physvol>
3448  <volumeref ref="volG10BoardYSideCenterSeg"/>
3449  <position name="posG10BoardYSideCenterSeg\-Udown\-$APA_i" unit="cm"
3450  x="$APAFrameCenter_x"
3451  y="$APAFrameCenter_y"
3452  z="$posvolG10BoardYSideCenterSegUdo_z"/>
3453  <rotationref ref="rIdentity"/>
3454  </physvol>
3455 
3456  <physvol>
3457  <volumeref ref="volG10BoardZSideCenterSeg"/>
3458  <position name="posG10BoardZSideCenterSeg\-Z\-$APA_i" unit="cm"
3459  x="$APAFrameCenter_x"
3460  y="$posG10ZSideZ_y"
3461  z="$APAFrameCenter_z"/>
3462  <rotationref ref="rIdentity"/>
3463  </physvol>
3464  <physvol>
3465  <volumeref ref="volG10BoardZSideCenterSeg"/>
3466  <position name="posG10BoardZSideCenterSeg\-V\-$APA_i" unit="cm"
3467  x="$APAFrameCenter_x"
3468  y="$posG10ZSideV_y"
3469  z="$APAFrameCenter_z"/>
3470  <rotationref ref="rIdentity"/>
3471  </physvol>
3472  <physvol>
3473  <volumeref ref="volG10BoardZSideCenterSeg"/>
3474  <position name="posG10BoardZSideCenterSeg\-U\-$APA_i" unit="cm"
3475  x="$APAFrameCenter_x"
3476  y="$posG10ZSideU_y"
3477  z="$APAFrameCenter_z"/>
3478  <rotationref ref="rIdentity"/>
3479  </physvol>
3480  <physvol>
3481  <volumeref ref="volG10BoardZSideCenterSeg"/>
3482  <position name="posG10BoardZSideCenterSeg\-Grid\-$APA_i" unit="cm"
3483  x="$APAFrameCenter_x"
3484  y="$posG10ZSideGrid_y"
3485  z="$APAFrameCenter_z"/>
3486  <rotationref ref="rIdentity"/>
3487  </physvol>
3488 
3489 EOF
3490 
3491 
3492 }
3493 
3494 
3495 
3496 
3497 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3498 #+++++++++++++++++++++++++++++++++++++ gen_Enclosure +++++++++++++++++++++++++++++++++++++
3499 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3500 
3501 sub gen_Enclosure()
3502 {
3503 
3504 # Create the detector enclosure fragment file name,
3505 # add file to list of output GDML fragments,
3506 # and open it
3507  $ENCL = "subfile_protodune_v7_DetEnclosure" . $suffix . ".gdml";
3508  push (@gdmlFiles, $ENCL);
3509  $ENCL = ">" . $ENCL;
3510  open(ENCL) or die("Could not open file $ENCL for writing");
3511 
3512 
3513 # The standard XML prefix and starting the gdml
3514  print ENCL <<EOF;
3515 <?xml version='1.0'?>
3516 <gdml>
3517 EOF
3518 
3519 
3520 # All the detector enclosure solids.
3521 $dimFoamPadBlock_x = $Cryostat_x + 2*$FoamPadding;
3522 $dimFoamPadBlock_y = $Cryostat_y + 2*$FoamPadding;
3523 $dimFoamPadBlock_z = $Cryostat_z + 2*$FoamPadding;
3524 $dimSteelSupportBlock_x = $Cryostat_x + 2*$FoamPadding + 2*$SteelSupport_x;
3525 $dimSteelSupportBlock_y = $Cryostat_y + 2*$FoamPadding + 2*$SteelSupport_y;
3526 $dimSteelSupportBlock_z = $Cryostat_z + 2*$FoamPadding + 2*$SteelSupport_z;
3527 $dimSteelPlateBlock_x = $Cryostat_x + 2*$FoamPadding + 2*$SteelPlate;
3528 $dimSteelPlateBlock_y = $Cryostat_y + 2*$FoamPadding + 2*$SteelPlate;
3529 $dimSteelPlateBlock_z = $Cryostat_z + 2*$FoamPadding + 2*$SteelPlate;
3530 
3531 $dimPitDepth = 900;
3532 $dimPitWidth = 1650;
3533 $dimStSuToDSPitWall = 160;
3534 $dimPitLength = $DetEncLength/2 + $dimSteelSupportBlock_z/2 + $dimStSuToDSPitWall;
3535 $dimEnclConcrete_y = $SpaceSteelSupportToWall + $dimPitDepth;
3536 $DetCentToJuraPit = 958;
3537 
3538 $dimPit_y = $dimPitDepth + 0.1; # try to avoid overlap
3539 $dimPit_z = $dimPitLength + 0.1;
3540 $posPitInConcrete_x = $DetCentToJuraPit - $dimPitWidth/2;
3541 $posPitInConcrete_y = $dimEnclConcrete_y/2 - $dimPitDepth/2 ;
3542 $posPitInConcrete_z = - $DetEncLength/2 + $dimPitLength/2 ;
3543 $posSurrConcrete_y = - $DetEncHeight/2 + $dimEnclConcrete_y/2 ;
3544 
3545 print "FoamPad x=$dimFoamPadBlock_x".", y=$dimFoamPadBlock_y".", z=$dimFoamPadBlock_z"."\n";
3546 print "SteelPlate x=$dimSteelPlateBlock_x".", y=$dimSteelPlateBlock_y".", z=$dimSteelPlateBlock_z"."\n";
3547 print "SteelSupport x=$dimSteelSupportBlock_x".", y=$dimSteelSupportBlock_y".", z=$dimSteelSupportBlock_z"."\n";
3548 print ENCL <<EOF;
3549 <solids>
3550  <box name="FoamPadBlock" lunit="cm"
3551  x="$dimFoamPadBlock_x"
3552  y="$dimFoamPadBlock_y"
3553  z="$dimFoamPadBlock_z" />
3554 
3555  <box name="SteelPlateBlock" lunit="cm"
3556  x="$dimSteelPlateBlock_x"
3557  y="$dimSteelPlateBlock_y"
3558  z="$dimSteelPlateBlock_z" />
3559 
3560  <subtraction name="SteelPlateNoBW">
3561  <first ref="SteelPlateBlock"/>
3562  <second ref="FoamPadBlock"/>
3563  <positionref ref="posCenter"/>
3564  </subtraction>
3565 
3566  <subtraction name="FoamPaddingNoBW">
3567  <first ref="FoamPadBlock"/>
3568  <second ref="Cryostat"/>
3569  <positionref ref="posCenter"/>
3570  </subtraction>
3571 EOF
3572 
3573 # <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"/>
3574 
3575 # <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"/>
3576 
3577  print ENCL <<EOF;
3578 
3579  <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"/>
3580 
3581  <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"/>
3582 
3583  <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"/>
3584 
3585  <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"/>
3586 
3587  <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"/>
3588 
3589  <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"/>
3590 
3591  <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"/>
3592 
3593  <subtraction name="SteelPlate">
3594  <first ref="SteelPlateNoBW"/>
3595  <second ref="BeamWindowStPlate"/>
3596  <position name="posBWStPl" x="$BeamWStPlate_x" y="$BeamWStPlate_y" z="$BeamWStPlate_z" unit="cm"/>
3597  <rotationref ref="rBeamW3"/>
3598  </subtraction>
3599 
3600  <subtraction name="FoamPadding">
3601  <first ref="FoamPaddingNoBW"/>
3602  <second ref="BeamWindowFoamRem"/>
3603  <position name="posBWFoPa" x="$BeamWFoRem_x" y="$BeamWFoRem_y" z="$BeamWFoRem_z" unit="cm"/>
3604  <rotationref ref="rBeamW3"/>
3605  </subtraction>
3606 
3607  <box name="CRTPaddle" lunit="cm"
3608  x="$CRTPaddleWidth"
3609  y="$CRTPaddleHeight"
3610  z="$CRTPaddleLength"/>
3611 
3612  <box name="CRTModule" lunit="cm"
3613  x="$CRTModWidth"
3614  y="$CRTModHeight"
3615  z="$CRTModLength"/>
3616 
3617  <box name="DetEnclosure" lunit="cm"
3618  x="$DetEncWidth"
3619  y="$DetEncHeight"
3620  z="$DetEncLength"/>
3621 
3622  <box name="SurrConcreteBox" lunit="cm"
3623  x="$DetEncWidth"
3624  y="$dimEnclConcrete_y"
3625  z="$DetEncLength"/>
3626 
3627  <box name="PitBox" lunit="cm"
3628  x="$dimPitWidth"
3629  y="$dimPit_y"
3630  z="$dimPit_z"/>
3631 
3632  <subtraction name="SurrConcrete">
3633  <first ref="SurrConcreteBox"/>
3634  <second ref="PitBox"/>
3635  <position name="posPitInConcrete" x="$posPitInConcrete_x" y="$posPitInConcrete_y" z="$posPitInConcrete_z" unit="cm"/>
3636  </subtraction>
3637 
3638 
3639 EOF
3640 if($simpleStSu == 1)
3641 {
3642  print ENCL <<EOF;
3643 
3644  <box name="SteelSupportBlock" lunit="cm"
3645  x="$dimSteelSupportBlock_x"
3646  y="$dimSteelSupportBlock_y"
3647  z="$dimSteelSupportBlock_z" />
3648 
3649  <subtraction name="SteelSupportNoBW">
3650  <first ref="SteelSupportBlock"/>
3651  <second ref="SteelPlateBlock"/>
3652  <positionref ref="posCenter"/>
3653  </subtraction>
3654 
3655  <subtraction name="SteelSupport">
3656  <first ref="SteelSupportNoBW"/>
3657  <second ref="BeamWindowStSu"/>
3658  <position name="posBWStSu" x="$BeamWStSu_x" y="$BeamWStSu_y" z="$BeamWStSu_z" unit="cm"/>
3659  <rotationref ref="rBeamW3"/>
3660  </subtraction>
3661 
3662 EOF
3663 }
3664 elsif($simpleStSu == 0)
3665 {
3666  print ENCL <<EOF;
3667 
3668  <box name="boxCryoTop" x="1016.8" y="1016.8" z="61.8" lunit="cm"/>
3669  <box name="boxCryoWallLg" x="1140.4" y="1075.6" z="61.8" lunit="cm"/>
3670  <box name="boxCryoWallSm" x="1016.8" y="1075.6" z="61.8" lunit="cm"/>
3671  <box name="box1" x="160" y="160" z="61.8" lunit="cm"/>
3672  <box name="box2" x="158.2" y="158.2" z="56.2" lunit="cm"/>
3673  <box name="box3" x="137.2" y="137.2" z="61.801" lunit="cm"/>
3674  <box name="box4" x="158.2" y="13.6" z="27.4" lunit="cm"/>
3675  <box name="box5" x="158.2" y="6.425" z="24.96" lunit="cm"/>
3676  <box name="box11" x="108.4" y="160" z="61.8" lunit="cm"/>
3677  <box name="box12" x="107.5" y="158.2" z="56.2" lunit="cm"/>
3678  <box name="box13" x="97" y="137.2" z="61.81" lunit="cm"/>
3679  <box name="box16" x="107.5" y="13.6" z="27.4" lunit="cm"/>
3680  <box name="box17" x="107.5" y="6.425" z="24.96" lunit="cm"/>
3681  <box name="box21" x="137.8" y="160" z="61.8" lunit="cm"/>
3682  <box name="box22" x="136.9" y="158.2" z="56.2" lunit="cm"/>
3683  <box name="box23" x="126.4" y="137.2" z="61.801" lunit="cm"/>
3684  <box name="box26" x="102.5" y="13.6" z="27.4" lunit="cm"/>
3685  <box name="box27" x="102.5" y="6.425" z="24.96" lunit="cm"/>
3686  <box name="box31" x="170.2" y="160" z="61.8" lunit="cm"/>
3687  <box name="box32" x="169.3" y="158.2" z="56.2" lunit="cm"/>
3688  <box name="box33" x="158.8" y="137.2" z="61.801" lunit="cm"/>
3689  <box name="box36" x="135.8" y="13.6" z="27.4" lunit="cm"/>
3690  <box name="box37" x="135.8" y="6.425" z="24.96" lunit="cm"/>
3691 
3692 
3693  <subtraction name="boxHoll">
3694  <first ref="box1"/>
3695  <second ref="box2"/>
3696  </subtraction>
3697  <subtraction name="boxLargeCent">
3698  <first ref="boxHoll"/>
3699  <second ref="box3"/>
3700  </subtraction>
3701  <subtraction name="boxBarI">
3702  <first ref="box4"/>
3703  <second ref="box5"/>
3704  <position name="posBoxBarI" x="0" y="3.5876" z="0" unit="cm"/>
3705  </subtraction>
3706  <subtraction name="boxBarCent">
3707  <first ref="boxBarI"/>
3708  <second ref="box5"/>
3709  <position name="posBoxBarCent" x="0" y="-3.5876" z="0" unit="cm"/>
3710  </subtraction>
3711  <union name="boxUniCent">
3712  <first ref="boxLargeCent"/>
3713  <second ref="boxBarCent"/>
3714  <position name="posBoxUniCent" x="0" y="0" z="-17.2" unit="cm"/>
3715  </union>
3716  <union name="UnitCent">
3717  <first ref="boxUniCent"/>
3718  <second ref="boxBarCent"/>
3719  <position name="posUnitCent" x="0" y="0" z="-17.2" unit="cm"/>
3720  <rotation name="rotUnitCent" x="0" y="0" z="90" unit="deg"/>
3721  </union>
3722 
3723  <subtraction name="boxTopHoll">
3724  <first ref="box11"/>
3725  <second ref="box12"/>
3726  <position name="posboxTopHoll" x="0.451" y="0" z="0" unit="cm"/>
3727  </subtraction>
3728  <subtraction name="boxLargeTop">
3729  <first ref="boxTopHoll"/>
3730  <second ref="box13"/>
3731  <position name="posboxLargeTop" x="5.701" y="0" z="0" unit="cm"/>
3732  </subtraction>
3733  <subtraction name="boxBarTopI">
3734  <first ref="box16"/>
3735  <second ref="box17"/>
3736  <position name="posboxBarTopI" x="0" y="3.5876" z="0" unit="cm"/>
3737  </subtraction>
3738  <subtraction name="boxBarTop">
3739  <first ref="boxBarTopI"/>
3740  <second ref="box17"/>
3741  <position name="posboxBarTop" x="0" y="-3.5876" z="0" unit="cm"/>
3742  </subtraction>
3743  <union name="boxUniTop">
3744  <first ref="boxLargeTop"/>
3745  <second ref="boxBarCent"/>
3746  <position name="posboxUni1" x="5.6" y="0" z="-17.2" unit="cm"/>
3747  <rotation name="rotUni1" x="0" y="0" z="90" unit="deg"/>
3748  </union>
3749  <union name="UnitTop">
3750  <first ref="boxUniTop"/>
3751  <second ref="boxBarTop"/>
3752  <position name="posUniTop" x="0.45" y="0" z="-17.2" unit="cm"/>
3753  </union>
3754 
3755  <subtraction name="boxCryoWallSmUS">
3756  <first ref="boxCryoWallSm"/>
3757  <second ref="BeamWindowStSu"/>
3758  <position name="posBWCryoWallUS" x="$BeamWStSu_x" y="$BeamWStSu_y" z="0." unit="cm"/>
3759  <rotationref ref="rBeamW3"/>
3760  </subtraction>
3761 
3762  <subtraction name="boxWallUHoll">
3763  <first ref="box21"/>
3764  <second ref="box22"/>
3765  <position name="posboxWallUHoll" x="0.451" y="0" z="0" unit="cm"/>
3766  </subtraction>
3767  <subtraction name="boxLargeWallU">
3768  <first ref="boxWallUHoll"/>
3769  <second ref="box23"/>
3770  <position name="posboxLargeWallU" x="5.701" y="0" z="0" unit="cm"/>
3771  </subtraction>
3772  <subtraction name="boxBarWallUI">
3773  <first ref="box26"/>
3774  <second ref="box27"/>
3775  <position name="posboxBarWallUI" x="0" y="3.5876" z="0" unit="cm"/>
3776  </subtraction>
3777  <subtraction name="boxBarWallU">
3778  <first ref="boxBarWallUI"/>
3779  <second ref="box27"/>
3780  <position name="posboxBarWallU" x="0" y="-3.5876" z="0" unit="cm"/>
3781  </subtraction>
3782  <union name="boxUniWallU">
3783  <first ref="boxLargeWallU"/>
3784  <second ref="boxBarCent"/>
3785  <position name="posboxUni2" x="-9.1" y="0" z="-17.2" unit="cm"/>
3786  <rotation name="rotUni2" x="0" y="0" z="90" unit="deg"/>
3787  </union>
3788  <union name="UnitWallU">
3789  <first ref="boxUniWallU"/>
3790  <second ref="boxBarWallU"/>
3791  <position name="posUniWallU" x="-16.75" y="0" z="-17.2" unit="cm"/>
3792  </union>
3793 
3794  <subtraction name="boxWallLHoll">
3795  <first ref="box31"/>
3796  <second ref="box32"/>
3797  <position name="posboxWallLHoll" x="0.451" y="0" z="0" unit="cm"/>
3798  </subtraction>
3799  <subtraction name="boxLargeWallL">
3800  <first ref="boxWallLHoll"/>
3801  <second ref="box33"/>
3802  <position name="posboxLargeWallL" x="5.701" y="0" z="0" unit="cm"/>
3803  </subtraction>
3804  <subtraction name="boxBarWallLI">
3805  <first ref="box36"/>
3806  <second ref="box37"/>
3807  <position name="posboxBarWallLI" x="0" y="3.5876" z="0" unit="cm"/>
3808  </subtraction>
3809  <subtraction name="boxBarWallL">
3810  <first ref="boxBarWallLI"/>
3811  <second ref="box37"/>
3812  <position name="posboxBarWallL" x="0" y="-3.5876" z="0" unit="cm"/>
3813  </subtraction>
3814  <union name="boxUniWallL">
3815  <first ref="boxLargeWallL"/>
3816  <second ref="boxBarCent"/>
3817  <position name="posboxUni3" x="-25.3" y="0" z="-17.2" unit="cm"/>
3818  <rotation name="rotUni3" x="0" y="0" z="90" unit="deg"/>
3819  </union>
3820  <union name="UnitWallL">
3821  <first ref="boxUniWallL"/>
3822  <second ref="boxBarWallL"/>
3823  <position name="posUniWallL" x="-16.3" y="0" z="-17.2" unit="cm"/>
3824  </union>
3825 EOF
3826 }
3827 
3828  print ENCL <<EOF;
3829 </solids>
3830 EOF
3831 
3832 
3833 
3834 # Detector enclosure structure
3835  print ENCL <<EOF;
3836 <structure>
3837  <volume name="volBeamWinFoam">
3838  <materialref ref="ProtoDUNEBWFoam"/>
3839  <solidref ref="BeamWindowFoam"/>
3840  </volume>
3841  <volume name="volBeamWinGlassWool">
3842  <materialref ref="GlassWool"/>
3843  <solidref ref="BeamWindowGlassWool"/>
3844  </volume>
3845  <volume name="volBeamPipeVac">
3846  <materialref ref="Vacuum"/>
3847  <solidref ref="BeamPipeVacuum"/>
3848  </volume>
3849  <volume name="volBeamPipe">
3850  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3851  <solidref ref="BeamPipe"/>
3852  <physvol>
3853  <volumeref ref="volBeamPipeVac"/>
3854  <positionref ref="posCenter"/>
3855  </physvol>
3856  </volume>
3857  <volume name="volFoamPadding">
3858  <materialref ref="ProtoDUNEFoam"/>
3859  <solidref ref="FoamPadding"/>
3860  </volume>
3861  <volume name="volSteelPlate">
3862  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3863  <solidref ref="SteelPlate"/>
3864  </volume>
3865  <volume name="volSurrConcrete">
3866  <materialref ref="Concrete"/>
3867  <solidref ref="SurrConcrete"/>
3868  </volume>
3869 EOF
3870 
3871 
3872  print ENCL <<EOF;
3873  <volume name="volAuxDetSensitiveCRTPaddle">
3874  <materialref ref="G4_POLYSTYRENE"/>
3875  <solidref ref="CRTPaddle"/>
3876  <auxiliary auxtype="SensDet" auxvalue="AuxDet"/>
3877  <auxiliary auxtype="Solid" auxvalue="True"/>
3878  </volume>
3879 EOF
3880 
3881 
3882 for($imod=0 ; $imod<16 ; $imod++){
3883  $modnum = $imod + 1;
3884  print ENCL <<EOF;
3885  <volume name="volAuxDetCRTModuleU$modnum">
3886  <materialref ref="Air"/>
3887  <solidref ref="CRTModule"/>
3888 EOF
3889 for($i=0 ; $i<32 ; $i++){
3890  $paddle_x1 = - $CRTModWidth/2 + $CRTPaddleWidth*($i + 0.5);
3891  $paddle_x2 = - $CRTModWidth/2 + $CRTPaddleWidth*($i + 1);
3892  $paddle_y1 = $CRTPaddleHeight/2;
3893  $paddle_y2 = - $CRTPaddleHeight/2;
3894  $paddle_z = 0;
3895  $padnum1 = 2*$i+(($modnum-1)*64);
3896  $padnum2 = (2*$i+1)+(($modnum-1)*64);
3897  $padnum1id = 2*$i+1;
3898  $padnum2id = 2*$i+2;
3899  $paddleid1 = "$padnum1id"."U$modnum";
3900  $paddleid2 = "$padnum2id"."U$modnum";
3901  print ENCL <<EOF;
3902  <physvol name="CRTPaddle$paddleid1" copynumber="$padnum1">
3903  <volumeref ref="volAuxDetSensitiveCRTPaddle"/>
3904  <position name="posCRTPaddleSensitive$paddleid1" unit="cm"
3905  x="$paddle_x1"
3906  y="$paddle_y1"
3907  z="$paddle_z"/>
3908  <rotationref ref="rIdentity"/>
3909  </physvol>
3910  <physvol name="CRTPaddle$paddleid2" copynumber="$padnum2">
3911  <volumeref ref="volAuxDetSensitiveCRTPaddle"/>
3912  <position name="posCRTPaddleSensitive$paddleid2" unit="cm"
3913  x="$paddle_x2"
3914  y="$paddle_y2"
3915  z="$paddle_z"/>
3916  <rotationref ref="rIdentity"/>
3917  </physvol>
3918 EOF
3919 }
3920  print ENCL <<EOF;
3921  </volume>
3922 EOF
3923 }
3924 
3925 
3926 
3927 
3928 for($imod=0 ; $imod<16 ; $imod++){
3929  $modnum = $imod + 1;
3930 
3931  print ENCL <<EOF;
3932  <volume name="volAuxDetCRTModuleD$modnum">
3933  <materialref ref="Air"/>
3934  <solidref ref="CRTModule"/>
3935 EOF
3936 for($i=0 ; $i<32 ; $i++){
3937  $paddle_x1 = - $CRTModWidth/2 + $CRTPaddleWidth*($i + 0.5);
3938  $paddle_x2 = - $CRTModWidth/2 + $CRTPaddleWidth*($i + 1);
3939  $paddle_y1 = $CRTPaddleHeight/2;
3940  $paddle_y2 = - $CRTPaddleHeight/2;
3941  $paddle_z = 0;
3942  $padnum1 = 2*$i+64*(($modnum-1)+16);
3943  $padnum2 = (2*$i+1)+64*(($modnum-1)+16);
3944  $padnum1id = 2*$i+1;
3945  $padnum2id = 2*$i+2;
3946  $paddleid1 = "$padnum1id"."D$modnum";
3947  $paddleid2 = "$padnum2id"."D$modnum";
3948  print ENCL <<EOF;
3949  <physvol name="CRTPaddle$paddleid1" copynumber="$padnum1">
3950  <volumeref ref="volAuxDetSensitiveCRTPaddle"/>
3951  <position name="posCRTPaddleSensitive$paddleid1" unit="cm"
3952  x="$paddle_x1"
3953  y="$paddle_y1"
3954  z="$paddle_z"/>
3955  <rotationref ref="rIdentity"/>
3956  </physvol>
3957  <physvol name="CRTPaddle$paddleid2" copynumber="$padnum2">
3958  <volumeref ref="volAuxDetSensitiveCRTPaddle"/>
3959  <position name="posCRTPaddleSensitive$paddleid2" unit="cm"
3960  x="$paddle_x2"
3961  y="$paddle_y2"
3962  z="$paddle_z"/>
3963  <rotationref ref="rIdentity"/>
3964  </physvol>
3965 EOF
3966 }
3967  print ENCL <<EOF;
3968  </volume>
3969 EOF
3970 }
3971 # for($i=0 ; $i<5 ; $i++){
3972 # for($j=0 ; $j<5 ; $j++){
3973 # $suffix = "$i"."-$j";
3974 #
3975 
3976 if($simpleStSu == 0)
3977 {
3978 print ENCL <<EOF;
3979  <volume name="volUnitCent">
3980  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3981  <solidref ref="UnitCent"/>
3982  </volume>
3983  <volume name="volUnitTop">
3984  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3985  <solidref ref="UnitTop"/>
3986  </volume>
3987  <volume name="volUnitWallS">
3988  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3989  <solidref ref="UnitWallU"/>
3990  </volume>
3991  <volume name="volUnitWallL">
3992  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3993  <solidref ref="UnitWallL"/>
3994  </volume>
3995 EOF
3996 
3997 #}}
3998 
3999 print ENCL <<EOF;
4000  <volume name="volSteelSupport_TB">
4001  <materialref ref="Air"/>
4002  <solidref ref="boxCryoTop"/>
4003 EOF
4004 
4005  for($i=0 ; $i<5 ; $i++){
4006  for($j=0 ; $j<5 ; $j++){
4007  $xupos = -320+160*$i;
4008  $yupos = -320+160*$j;
4009  $stsuind = "$i"."-$j";
4010 print ENCL <<EOF;
4011  <physvol name="volUnitTBCent_$stsuind">
4012  <volumeref ref="volUnitCent"/>
4013  <position name="posUnitTBCent_$stsuind" x="$xupos" y="$yupos" z="0" unit="cm"/>
4014  </physvol>
4015 EOF
4016 }
4017 print ENCL <<EOF;
4018  <physvol name="volUnitTBE_$i">
4019  <volumeref ref="volUnitTop"/>
4020  <position name="posUnitTBE_$i" x="454.2" y="$xupos" z="0" unit="cm"/>
4021  </physvol>
4022  <physvol name="volUnitTBS_$i">
4023  <volumeref ref="volUnitTop"/>
4024  <position name="posUnitTBS_$i" x="$xupos" y="454.2" z="0" unit="cm"/>
4025  <rotation name="rotUnitTBS_$i" x="0" y="0" z="-90" unit="deg"/>
4026  </physvol>
4027  <physvol name="volUnitTBW_$i">
4028  <volumeref ref="volUnitTop"/>
4029  <position name="posUnitTBW_$i" x="-454.2" y="$xupos" z="0" unit="cm"/>
4030  <rotation name="rotUnitTBW_$i" x="0" y="0" z="-180" unit="deg"/>
4031  </physvol>
4032  <physvol name="volUnitTBN_$i">
4033  <volumeref ref="volUnitTop"/>
4034  <position name="posUnitTBN_$i" x="$xupos" y="-454.2" z="0" unit="cm"/>
4035  <rotation name="rotUnitTBN_$i" x="0" y="0" z="-270" unit="deg"/>
4036  </physvol>
4037 EOF
4038 
4039 }
4040 
4041  print ENCL <<EOF;
4042  </volume>
4043 EOF
4044 
4045 print ENCL <<EOF;
4046  <volume name="volSteelSupport_WS">
4047  <materialref ref="Air"/>
4048  <solidref ref="boxCryoWallSm"/>
4049 EOF
4050 
4051  for($i=0 ; $i<5 ; $i++){
4052  for($j=0 ; $j<5 ; $j++){
4053  $xupos = -320+160*$i;
4054  $yupos = -320+160*$j;
4055  $stsuind = "$i"."-$j";
4056 print ENCL <<EOF;
4057  <physvol name="volUnitWSCent_$stsuind">
4058  <volumeref ref="volUnitCent"/>
4059  <position name="posUnitWSCent_$stsuind" x="$xupos" y="$yupos" z="0" unit="cm"/>
4060  </physvol>
4061 EOF
4062 }
4063 print ENCL <<EOF;
4064  <physvol name="volUnitWSE_$i">
4065  <volumeref ref="volUnitTop"/>
4066  <position name="posUnitWSE_$i" x="454.2" y="$xupos" z="0" unit="cm"/>
4067  </physvol>
4068  <physvol name="volUnitWSS_$i">
4069  <volumeref ref="volUnitWallS"/>
4070  <position name="posUnitWSS_$i" x="$xupos" y="468.9" z="0" unit="cm"/>
4071  <rotation name="rotUnitWSS_$i" x="0" y="0" z="-90" unit="deg"/>
4072  </physvol>
4073  <physvol name="volUnitWSW_$i">
4074  <volumeref ref="volUnitTop"/>
4075  <position name="posUnitWSW_$i" x="-454.2" y="$xupos" z="0" unit="cm"/>
4076  <rotation name="rotUnitWSW_$i" x="0" y="0" z="-180" unit="deg"/>
4077  </physvol>
4078  <physvol name="volUnitWSN_$i">
4079  <volumeref ref="volUnitWallS"/>
4080  <position name="posUnitWSN_$i" x="$xupos" y="-468.9" z="0" unit="cm"/>
4081  <rotation name="rotUnitWSN_$i" x="0" y="0" z="-270" unit="deg"/>
4082  </physvol>
4083 EOF
4084 
4085 }
4086  print ENCL <<EOF;
4087  </volume>
4088 EOF
4089 
4090 print ENCL <<EOF;
4091  <volume name="volSteelSupport_US">
4092  <materialref ref="Air"/>
4093  <solidref ref="boxCryoWallSmUS"/>
4094 EOF
4095 
4096  for($i=0 ; $i<5 ; $i++){
4097  for($j=0 ; $j<5 ; $j++){
4098  $xupos = -320+160*$i;
4099  $yupos = -320+160*$j;
4100  $stsuind = "$i"."-$j";
4101 print ENCL <<EOF;
4102 
4103  <physvol name="volUnitUSCent_$stsuind">
4104  <volumeref ref="volUnitCent"/>
4105  <position name="posUnitUSCent_$stsuind" x="$xupos" y="$yupos" z="0" unit="cm"/>
4106  <rotationref ref="rPlus180AboutY"/>
4107  </physvol>
4108 EOF
4109 }
4110 print ENCL <<EOF;
4111  <physvol name="volUnitUSE_$i">
4112  <volumeref ref="volUnitTop"/>
4113  <position name="posUnitUSE_$i" x="454.2" y="$xupos" z="0" unit="cm"/>
4114  <rotationref ref="rPlus180AboutX"/>
4115  </physvol>
4116  <physvol name="volUnitUSS_$i">
4117  <volumeref ref="volUnitWallS"/>
4118  <position name="posUnitUSS_$i" x="$xupos" y="468.9" z="0" unit="cm"/>
4119  <rotation name="rotUnitUSS_$i" x="0" y="180" z="-90" unit="deg"/>
4120  </physvol>
4121  <physvol name="volUnitUSW_$i">
4122  <volumeref ref="volUnitTop"/>
4123  <position name="posUnitUSW_$i" x="-454.2" y="$xupos" z="0" unit="cm"/>
4124  <rotation name="rotUnitUSW_$i" x="180" y="0" z="-180" unit="deg"/>
4125  </physvol>
4126  <physvol name="volUnitUSN_$i">
4127  <volumeref ref="volUnitWallS"/>
4128  <position name="posUnitUSN_$i" x="$xupos" y="-468.9" z="0" unit="cm"/>
4129  <rotation name="rotUnitUSN_$i" x="0" y="180" z="-270" unit="deg"/>
4130  </physvol>
4131 
4132 EOF
4133 
4134 }
4135  print ENCL <<EOF;
4136  </volume>
4137 EOF
4138 
4139 
4140 print ENCL <<EOF;
4141  <volume name="volSteelSupport_LR">
4142  <materialref ref="Air"/>
4143  <solidref ref="boxCryoWallLg"/>
4144 EOF
4145 
4146  for($i=0 ; $i<5 ; $i++){
4147  for($j=0 ; $j<5 ; $j++){
4148  $xupos = -320+160*$i;
4149  $yupos = -320+160*$j;
4150  $stsuind = "$i"."-$j";
4151 print ENCL <<EOF;
4152  <physvol name="volUnitLRCent_$stsuind">
4153  <volumeref ref="volUnitCent"/>
4154  <position name="posUnitLRCent_$stsuind" x="$xupos" y="$yupos" z="0" unit="cm"/>
4155  </physvol>
4156 EOF
4157 }
4158 print ENCL <<EOF;
4159  <physvol name="volUnitLRE_$i">
4160  <volumeref ref="volUnitWallL"/>
4161  <position name="posUnitLRE_$i" x="485.1" y="$xupos" z="0" unit="cm"/>
4162  </physvol>
4163  <physvol name="volUnitLRS_$i">
4164  <volumeref ref="volUnitWallS"/>
4165  <position name="posUnitLRS_$i" x="$xupos" y="468.9" z="0" unit="cm"/>
4166  <rotation name="rotUnitLRS_$i" x="0" y="0" z="-90" unit="deg"/>
4167  </physvol>
4168  <physvol name="volUnitLRW_$i">
4169  <volumeref ref="volUnitWallL"/>
4170  <position name="posUnitLRW_$i" x="-485.1" y="$xupos" z="0" unit="cm"/>
4171  <rotation name="rotUnitLRW_$i" x="0" y="0" z="-180" unit="deg"/>
4172  </physvol>
4173  <physvol name="volUnitLRN_$i">
4174  <volumeref ref="volUnitWallS"/>
4175  <position name="posUnitLRN_$i" x="$xupos" y="-468.9" z="0" unit="cm"/>
4176  <rotation name="rotUnitLRN_$i" x="0" y="0" z="-270" unit="deg"/>
4177  </physvol>
4178 EOF
4179 
4180 }
4181  print ENCL <<EOF;
4182  </volume>
4183 EOF
4184 } # if(simpleStSu == 0)
4185 elsif($simpleStSu==1){
4186 print ENCL <<EOF;
4187  <volume name="volSteelSupportMod">
4188  <materialref ref="AirSteelMixture"/>
4189  <solidref ref="SteelSupport"/>
4190  </volume>
4191 EOF
4192 }
4193 
4194  print ENCL <<EOF;
4195 
4196  <volume name="volDetEnclosure">
4197  <materialref ref="Air"/>
4198  <solidref ref="DetEnclosure"/>
4199 
4200 EOF
4201 if($simpleStSu==1){
4202  print ENCL <<EOF;
4203  <physvol>
4204  <volumeref ref="volSteelSupportMod"/>
4205  <positionref ref="posCryoInDetEnc"/>
4206  </physvol>
4207 EOF
4208 }
4209 elsif ($simpleStSu==0)
4210 {
4211  $stsuTop_y = 506.9 + $posCryoInDetEnc_y;
4212  $stsuBot_y = -506.9 + $posCryoInDetEnc_y;
4213  $stsuOther_y = $posCryoInDetEnc_y;
4214 
4215  print ENCL <<EOF;
4216 
4217  <physvol name="volSteelSupport_Top">
4218  <volumeref ref="volSteelSupport_TB"/>
4219  <position name="posSteelSupport_Top" x="0" y="$stsuTop_y" z="0" unit="cm"/>
4220  <rotation name="rotSteelSupport_Top" x="90" y="0" z="0" unit="deg"/>
4221  </physvol>
4222  <physvol name="volSteelSupport_Bottom">
4223  <volumeref ref="volSteelSupport_TB"/>
4224  <position name="posSteelSupport_Bottom" x="0" y="$stsuBot_y" z="0" unit="cm"/>
4225  <rotation name="rotSteelSupport_Bottom" x="-90" y="0" z="0" unit="deg"/>
4226  </physvol>
4227  <physvol>
4228  <volumeref ref="volSteelSupport_US"/>
4229  <position name="posSteelSupport_US" x="0" y="$stsuOther_y" z="-539.3" unit="cm"/>
4230  </physvol>
4231  <physvol name="volSteelSupport_DS">
4232  <volumeref ref="volSteelSupport_WS"/>
4233  <position name="posSteelSupport_DS" x="0" y="$stsuOther_y" z="539.3" unit="cm"/>
4234  </physvol>
4235  <physvol name="volSteelSupport_LS">
4236  <volumeref ref="volSteelSupport_LR"/>
4237  <position name="posSteelSupport_LS" x="539.3" y="$stsuOther_y" z="0" unit="cm"/>
4238  <rotation name="rotSteelSupport_LS" x="0" y="-90" z="0" unit="deg"/>
4239  </physvol>
4240  <physvol name="volSteelSupport_RS">
4241  <volumeref ref="volSteelSupport_LR"/>
4242  <position name="posSteelSupport_RS" x="-539.3" y="$stsuOther_y" z="0" unit="cm"/>
4243  <rotation name="rotSteelSupport_RS" x="0" y="90" z="0" unit="deg"/>
4244  </physvol>
4245 
4246 EOF
4247 }
4248  print ENCL <<EOF;
4249 
4250  <physvol>
4251  <volumeref ref="volFoamPadding"/>
4252  <positionref ref="posCryoInDetEnc"/>
4253  </physvol>
4254  <physvol>
4255  <volumeref ref="volSteelPlate"/>
4256  <positionref ref="posCryoInDetEnc"/>
4257  </physvol>
4258  <physvol>
4259  <volumeref ref="volBeamWinFoam"/>
4260  <position name="posBeamWinFoam" unit="cm"
4261  x="$BeamWFo_x"
4262  y="$BeamWFo_y"
4263  z="$BeamWFo_z"/>
4264  <rotationref ref="rBeamWRev3"/>
4265  </physvol>
4266  <physvol>
4267  <volumeref ref="volBeamWinGlassWool"/>
4268  <position name="posBeamWinGlassWool" unit="cm"
4269  x="$BeamWGl_x"
4270  y="$BeamWGl_y"
4271  z="$BeamWGl_z"/>
4272  <rotationref ref="rBeamWRev3"/>
4273  </physvol>
4274  <physvol>
4275  <volumeref ref="volBeamPipe"/>
4276  <position name="posBeamPipe" unit="cm"
4277  x="$BeamWVa_x"
4278  y="$BeamWVa_y"
4279  z="$BeamWVa_z"/>
4280  <rotationref ref="rBeamWRev3"/>
4281  </physvol>
4282  <physvol>
4283  <volumeref ref="volCryostat"/>
4284  <positionref ref="posCryoInDetEnc"/>
4285  </physvol>
4286  <physvol>
4287  <volumeref ref="volSurrConcrete"/>
4288  <position name="posSurrConcrete" unit="cm"
4289  x="0"
4290  y="$posSurrConcrete_y"
4291  z="0"/>
4292  </physvol>
4293 EOF
4294 
4295  for($i=0 ; $i<16 ; $i++){
4296  $modnum = $i + 1;
4297  $modid = "U$modnum";
4298 
4299 print ENCL <<EOF;
4300  <physvol>
4301  <volumeref ref="volAuxDetCRTModule$modid"/>
4302  <position name="posvolAuxDetCRTModule$modid" unit="cm"
4303  x="$posCRTUS_x[$i]"
4304  y="$posCRTUS_y[$i]"
4305  z="$posCRTUS_z[$i]"/>
4306  <rotationref ref="$posCRTUS_rot[$i]"/>
4307  </physvol>
4308 EOF
4309  }
4310 
4311  for($i=0 ; $i<16 ; $i++){
4312  $modnum = $i + 1;
4313  $modid = "D$modnum";
4314 
4315 print ENCL <<EOF;
4316  <physvol>
4317  <volumeref ref="volAuxDetCRTModule$modid"/>
4318  <position name="posvolAuxDetCRTModule$modid" unit="cm"
4319  x="$posCRTDS_x[$i]"
4320  y="$posCRTDS_y[$i]"
4321  z="$posCRTDS_z[$i]"/>
4322  <rotationref ref="$posCRTDS_rot[$i]"/>
4323  </physvol>
4324 EOF
4325  }
4326 
4327 print ENCL <<EOF;
4328 
4329  </volume>
4330 
4331 </structure>
4332 </gdml>
4333 EOF
4334 
4335 close(ENCL);
4336 }
4337 
4338 
4339 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4340 #+++++++++++++++++++++++++++++++++++++++ gen_World +++++++++++++++++++++++++++++++++++++++
4341 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4342 
4343 sub gen_World()
4344 {
4345 
4346 # Create the WORLD fragment file name,
4347 # add file to list of output GDML fragments,
4348 # and open it
4349  $WORLD = "subfile_protodune_v7_World" . $suffix . ".gdml";
4350  push (@gdmlFiles, $WORLD);
4351  $WORLD = ">" . $WORLD;
4352  open(WORLD) or die("Could not open file $WORLD for writing");
4353 
4354 
4355 # The standard XML prefix and starting the gdml
4356  print WORLD <<EOF;
4357 <?xml version='1.0'?>
4358 <gdml>
4359 EOF
4360 
4361 
4362 # All the World solids.
4363 $dimWorld_x = $DetEncWidth+2*$RockThickness;
4364 $dimWorld_y = $DetEncHeight+2*$RockThickness;
4365 $dimWorld_z = $DetEncLength+2*$RockThickness;
4366 
4367 print WORLD <<EOF;
4368 <solids>
4369  <box name="World" lunit="cm"
4370  x="$dimWorld_x"
4371  y="$dimWorld_y"
4372  z="$dimWorld_z"/>
4373 </solids>
4374 EOF
4375 
4376 # World structure
4377 print WORLD <<EOF;
4378 <structure>
4379  <volume name="volWorld" >
4380  <materialref ref="Air"/>
4381  <solidref ref="World"/>
4382 
4383  <physvol>
4384  <volumeref ref="volDetEnclosure"/>
4385  <position name="posDetEnclosure" unit="cm" x="$OriginXSet" y="$OriginYSet" z="$OriginZSet"/>
4386  </physvol>
4387 
4388  </volume>
4389 </structure>
4390 </gdml>
4391 EOF
4392 
4393 # make_gdml.pl will take care of <setup/>
4394 
4395 close(WORLD);
4396 }
4397 
4398 
4399 
4400 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4401 #++++++++++++++++++++++++++++++++++++ write_fragments ++++++++++++++++++++++++++++++++++++
4402 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4403 
4404 sub write_fragments()
4405 {
4406  # This subroutine creates an XML file that summarizes the the subfiles output
4407  # by the other sub routines - it is the input file for make_gdml.pl which will
4408  # give the final desired GDML file. Specify its name with the output option.
4409  # (you can change the name when running make_gdml)
4410 
4411  # This code is taken straigh from the similar MicroBooNE generate script, Thank you.
4412 
4413  if ( ! defined $output )
4414  {
4415  $output = "-"; # write to STDOUT
4416  }
4417 
4418  # Set up the output file.
4419  $OUTPUT = ">" . $output;
4420  open(OUTPUT) or die("Could not open file $OUTPUT");
4421 
4422  print OUTPUT <<EOF;
4423 <?xml version='1.0'?>
4424 
4425 <!-- Input to Geometry/gdml/make_gdml.pl; define the GDML fragments
4426  that will be zipped together to create a detector description.
4427  -->
4428 
4429 <config>
4430 
4431  <constantfiles>
4432 
4433  <!-- These files contain GDML <constant></constant>
4434  blocks. They are read in separately, so they can be
4435  interpreted into the remaining GDML. See make_gdml.pl for
4436  more information.
4437  -->
4438 
4439 EOF
4440 
4441  foreach $filename (@defFiles)
4442  {
4443  print OUTPUT <<EOF;
4444  <filename> $filename </filename>
4445 EOF
4446  }
4447 
4448  print OUTPUT <<EOF;
4449 
4450  </constantfiles>
4451 
4452  <gdmlfiles>
4453 
4454  <!-- The GDML file fragments to be zipped together. -->
4455 
4456 EOF
4457 
4458  foreach $filename (@gdmlFiles)
4459  {
4460  print OUTPUT <<EOF;
4461  <filename> $filename </filename>
4462 EOF
4463  }
4464 
4465  print OUTPUT <<EOF;
4466 
4467  </gdmlfiles>
4468 
4469 </config>
4470 EOF
4471 
4472  close(OUTPUT);
4473 }
4474 
4475 
4476 
4477 # run the sub routines that generate the fragments
4478 
4479 gen_Extend(); #generates the GDML color extension for the refactored geometry
4480 
4481 gen_Define(); # generates definitions at beginning of GDML
4482 gen_Materials(); # generates materials to be used
4483 
4484 
4485  gen_TPC( $TPCInner_x, $TPC_y, $TPC_z, 'Inner');
4486  gen_TPC( $TPCOuter_x, $TPC_y, $TPC_z, 'Outer');
4487 
4488 close $wout;
4489 
4490 gen_Cryostat(); # places (2*nAPAWide x nAPAHigh x nAPALong) volTPC,
4491  # half rotated 180 about Y
4492 gen_Enclosure(); # places two cryostats and concrete volumes
4493 
4494 gen_World(); # places the enclosure among DUSEL Rock
4495 
4496 
4497 write_fragments(); # writes the XML input for make_gdml.pl
4498  # which zips together the final GDML
4499 exit;