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