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