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