generate_35t4apa_v5.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 # Much of this program is taken straight from generate_gdml.pl that
4 # generates MicroBooNE fragment files (Thank you.)
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 vars;
15 #use strict;
16 #use warnings;
17 use Switch;
18 use Math::Trig;
19 use Getopt::Long;
20 use Math::BigFloat;
21 Math::BigFloat->precision(-15);
22 
23 GetOptions( "help|h" => \$help,
24  "suffix|s:s" => \$suffix,
25  "output|o:s" => \$output,
26  "wires|w:s" => \$wires,
27  "helpcube|c" => \$helpcube);
28 
29 if ( defined $help )
30 {
31  # If the user requested help, print the usage notes and exit.
32  usage();
33  exit;
34 }
35 
36 if ( ! defined $suffix )
37 {
38  # The user didn't supply a suffix, so append nothing to the file
39  # names.
40  $suffix = "";
41 }
42 else
43 {
44  # Otherwise, stick a "-" before the suffix, so that a suffix of
45  # "test" applied to filename.gdml becomes "filename-test.gdml".
46  $suffix = "-" . $suffix;
47 }
48 
49 
50 
51 
52 #++++++++++++++++++++++++ Begin defining variables +++++++++++++++++++++++++
53 
54 # Define detector geometry variables - later to be put in a parameters
55 # XML file to be parsed as an input?
56 
57 # set wires on to be the default, unless given an input by the user
58 $wires_on = 1; # 1=on, 0=off
59 if (defined $wires)
60 {
61 $wires_on = $wires
62 }
63 
64 $tpc_on=1;
65 $inch = 2.54;
66 
67 
68 
69 #################################################
70 #### 4APA 35t parameters from DocDb 7550 ####
71 #################################################
72 
73 
74 
75 ##################################################################
76 ##################### wire plane parameters ######################
77 
78 
79 $UVReadoutBoardPitch = 0.698516;
80 #$UVReadoutBoardPitch = 0.7;
81 
82 $UAng[0] = 45.705;
83 $VAng[0] = 44.274;
84 $UAng[1] = 45.705;
85 $VAng[1] = 44.274;
86 $UAng[2] = 45.705;
87 $VAng[2] = 44.274;
88 $UAng[3] = 45.705;
89 $VAng[3] = 44.274;
90 # WARM
91 # $UAng[0] = 45.707;
92 # $VAng[0] = 44.275;
93 # $UAng[1] = 45.707;
94 # $VAng[1] = 44.275;
95 # $UAng[2] = 45.707;
96 # $VAng[2] = 44.275;
97 # $UAng[3] = 45.707;
98 # $VAng[3] = 44.275;
99 
100 $UWirePitch = $UVReadoutBoardPitch*cos(deg2rad($UAng[0]));
101 $VWirePitch = $UVReadoutBoardPitch*cos(deg2rad($VAng[0]));
102 $XWirePitch = 0.449055;
103 
104 
105 ##################################################################
106 ######################## TPC parameters ##########################
107 
108 $G10thickness = 0.3155;
109 $WrapCover = 0.1578;
110 #$G10thickness = $inch/8;
111 #$WrapCover = $inch/16;
112 
113 $LongDrift = 222.46;
114 $ShortDrift = 27.16;
115 $APAFrame_x = 5.0661; # ~2in -- this does not include the wire spacing
116 
117 $TPCWireThickness = 0.015;
118 $TPCWirePlaneThickness = $TPCWireThickness;
119 $APAWirePlaneSpacing = 0.4730488 + $TPCWirePlaneThickness; # center to center spacing between all of the wire planes (g, u, v, and x)
120 
121 # At creation of the plane volumes, the y and z boundaries will be increased
122 # by this much at each of the 4 edges. this is so the corners of the wire
123 # tubes don't extrude. For all other purposes, the plane dimensions stay as originally defined
124 $UVPlaneBoundNudge = $TPCWireThickness;
125 
126 # The following are all widths about the same z center,
127 # namely the center of the corresponding APA
128 #$Zactive_z = 49.8441 + $TPCWireThickness;
129 $Zactive_z = 112*$XWirePitch + $TPCWireThickness;
130 $APAFrame_z = 50.2619;
131 #$Vactive_z = 50.8929 - 2*$G10thickness;
132 #$Uactive_z = 51.5240 - 2*$G10thickness;
133 $Vactive_z = $APAFrame_z;
134 $Uactive_z = $APAFrame_z + 2*$G10thickness;
135 $APAphys_z = 51.8395;
136 
137 
138  # NUMBER VERTICAL WIRES = (Zview_z / pitch) + 1
139  # Since Zview_z is defined in docdb 7550 to be distance
140  # between outer vertical wires, + 1 since the floor of this
141  # division will be one under, giveing the amt of spaces, not wires
142  # POSITIONING: plane centered between +/- APAActive_z/2
143 
144 # Let APAs be numbered as follows
145 # 0 & 3 - Largest
146 # 1 - Middle (Middle Top)
147 # 2 - Smallest (Middle Bottom)
148 # APA heights and positions will be indexed by APA number
149 
150 $APAFrame_y[0] = 203.06;
151 $APAFrame_y[1] = 119.29;
152 $APAFrame_y[2] = 91.37;
153 $APAFrame_y[3] = $APAFrame_y[0];
154 
155 # the physical assembply includes 4 boards to anchor Grid, U, V, and Z, then a cover
156 for($apa = 0; $apa < 4; ++$apa){
157  $APAphys_y[$apa] = $APAFrame_y[$apa] + 4*$G10thickness + $WrapCover;
158 }
159 
160 # The field cage dictates the boundaries of the active volumes.
161 $ReadoutBoardOverlap = 7.61; #board overlaps wires, chop this off of their active height
162 $OuterWireToCage = 2.33;
163 $TopAPAToCage = -5.6647; # negative because the cage is actually lower than the APA frame
164 $BottomTallAPAToCage = 0.673;
165 $BottomShortAPAToCage = $BottomTallAPAToCage
166  - ($APAphys_y[1] + $APAGap_y + $APAphys_y[2] - $APAphys_y[0]); # also negative
167 
168 for($apa = 0; $apa < 4; ++$apa){
169 
170  $overlap = $ReadoutBoardOverlap;
171 
172  # the smallest bottom APA wire planes extrude ~1cm past the field cage
173  # before being overlapped by the readout board. For the purposes of the
174  # LArSoft Geometry interface, we want to end the wires at the edge of the
175  # active volume, or rather the edge of the cage.
176  if($apa==2){ $overlap = -$BottomShortAPAToCage + $UVPlaneBoundNudge; }
177  # negative sign so overlap is positive
178 
179  # each view has its own G10 board to wrap around at the bottom
180  # and is covered by the readout board at the top
181  $Zactive_y[$apa] = $APAFrame_y[$apa] + 0*$G10thickness - $overlap;
182  $Vactive_y[$apa] = $APAFrame_y[$apa] + 1*$G10thickness - $overlap;
183  $Uactive_y[$apa] = $APAFrame_y[$apa] + 2*$G10thickness - $overlap;
184 
185 }
186 
187 
188 $APAGap_y = 0.0845; #separation between APAs along the incident beam axis
189 $APAGap_z = 0.0845; #separation between APAs along the vertical axis
190 
191 
192  # include APA spacing in y and z so volTPCs touch in y and z directions with correct APA
193  # spacing - this makes for smoother event generation.
194 
195 $TPCLongDrift_x = $LongDrift + 3*$APAWirePlaneSpacing + $TPCWirePlaneThickness;
196 $TPCShortDrift_x = $ShortDrift + 3*$APAWirePlaneSpacing + $TPCWirePlaneThickness;
197 
198 
199 
200 ############################################################
201 #################### AuxDet parameters #####################
202 
203 $AuxDetHousingHeight = 27.72*$inch;
204 $AuxDetHousingLongSide = 13.07*$inch;
205 $AuxDetHousingShortSide = 10.64*$inch;
206 $AuxDetHousingThickness = 3;
207 $AuxDetScintillatorHeight = 24.80*$inch;
208 $AuxDetScintillatorLongSide = 12.82*$inch;
209 $AuxDetScintillatorShortSide = 10.65*$inch;
210 $AuxDetScintillatorThickness = 0.95;
211 
212 # email from Michelle:
213 # the housing (AL box) is 13.07/10.64 x 27.72 (inches)
214 # the actual scintillator is 12.82/10.65 x 24.80 (inches)
215 
216 
217 # AuxDet configuration:
218 #
219 # / \ _______ / \ _______ } This spacing is only in the housing,
220 # / \\ // \\ / so it is not implimented in AuDet
221 #/______\\ //______\\ / which only represents the scintillator
222 # \_/ \_/
223 
224 
225 # email from Michelle:
226 # Assume that the telescope scintillator is a rectangle, 64 3/4" x 6 5/8" x 3/4".
227 
228 $AuxDetBSUScintWidth = (6+5/8)*$inch;
229 $AuxDetBSUScintHeight = 0.75*$inch;
230 $AuxDetBSUScintLength = 64.75*$inch;
231 
232 
233 # these positions pulled from a coordinate system with positive x and z are reversed
234 # positions are from a particular corner of the scintillators
235 ############################
236 ############################
237 @BSULayer1_xpos = ( 16.21, 9.46, 2.71, -4.04,
238  -17.33, -24.08, -30.83, -37.58,
239  -44.33, -51.08, -57.83, -64.58, -71.33 );
240 for($i = 0; $i < 13; ++$i){
241  $BSULayer1_xpos[$i] *= -$inch; # negative reverses coordinate system back
242  $BSULayer1_xpos[$i] -= $AuxDetBSUScintWidth/2; # move to center of volume
243 }
244 $BSULayer1_ypos = 75.14*$inch;
245 $BSULayer1_zpos = -1.21*$inch;
246 $BSULayer1_zpos = -1*$BSULayer1_zpos + $AuxDetBSUScintLength/2; # correct coordinates and move to center of scint
247 ############################
248 ############################
249 $BSULayer2_xpos = -67.24*$inch;
250 $BSULayer2_xpos = -1*$BSULayer2_xpos - $AuxDetBSUScintLength/2;
251 $BSULayer2_ypos = 89.49*$inch;
252 #@BSULayer2_zpos = ( -0.56, -7.31, -18.84, -25.59,
253 # -32.34, -39.09, -45.84, -52.59, -59.34 );
254 # assume pitch of 6.75:
255 @BSULayer2_zpos = ( 6.19, -0.56, -7.31, -18.84, -25.59,
256  -32.34, -39.09, -45.84, -52.59, -59.34 );
257 for($i = 0; $i < 10; ++$i){
258  $BSULayer2_zpos[$i] *= -$inch;
259  $BSULayer2_zpos[$i] -= $AuxDetBSUScintWidth/2;
260 }
261 ############################
262 ############################
263 @BSULayer3_xpos = ( 16.21, 9.46, 2.71, -4.04,
264  -10.79, -17.54, -24.29, -31.04,
265  -37.79, -44.54, -51.29, -58.04,
266  -64.79, -71.54, -78.29, -85.04 );
267 for($i = 0; $i < 16; ++$i){
268  $BSULayer3_xpos[$i] *= -$inch;
269  $BSULayer3_xpos[$i] -= $AuxDetBSUScintWidth/2;
270 }
271 $BSULayer3_ypos = 306.55*$inch;
272 $BSULayer3_zpos = -1.21*$inch;
273 $BSULayer3_zpos = -1*$BSULayer3_zpos + $AuxDetBSUScintLength/2;
274 ############################
275 ############################
276 $BSULayer4_xpos = -67.24*$inch;
277 $BSULayer4_xpos = -1*$BSULayer4_xpos - $AuxDetBSUScintLength/2;
278 $BSULayer4_ypos = 310.80*$inch;
279 @BSULayer4_zpos = ( 1.42, -5.34, -12.09, -18.84,
280  -25.59, -32.34, -39.09, -45.84,
281  -52.59, -59.34 );
282 for($i = 0; $i < 10; ++$i){
283  $BSULayer4_zpos[$i] *= -$inch;
284  $BSULayer4_zpos[$i] -= $AuxDetBSUScintWidth/2;
285 }
286 ############################
287 ## Layer 5 is not included in the final gdml
288 ############################
289 @BSULayer5_xpos = ( 16.21, 9.46, 2.71, -4.04,
290  -10.79, -17.54, -24.29, -31.04,
291  -37.79, -44.54, -51.29, -58.04,
292  -64.79, -71.54, -78.29, -85.04 );
293 for($i = 0; $i < 16; ++$i){
294  $BSULayer5_xpos[$i] *= -$inch;
295  $BSULayer5_xpos[$i] -= $AuxDetBSUScintWidth/2;
296 }
297 $BSULayer5_ypos = 314.55*$inch;
298 $BSULayer5_zpos = -1.21*$inch;
299 $BSULayer5_zpos = -1*$BSULayer5_zpos + $AuxDetBSUScintLength/2;
300 
301 
302 
303 ############################################################
304 ############### Optical Detector parameters ################
305 
306 # TODO: while the structure is exactly what we need, the parameters for
307 # paddle height and positioning are all placeholders
308 
309 $nPaddlesInAPA[0] = 3;
310 $nPaddlesInAPA[1] = 1;
311 $nPaddlesInAPA[2] = 1;
312 $nPaddlesInAPA[3] = $nPaddlesInAPA[0]; # for now, this one is the same as 0
313 
314 $SiPM_y = 0;
315 $LightPaddle_x = 0.476;
316 $LightPaddle_y = 56; # in cm from docDb 7803
317 $LightPaddle_z = 4*$inch;
318 
319 # z and x are given by APA frame center.
320 # Hardcode y distance of each paddle from the
321 # bottom of the APA to the paddle y-center.
322 # To be used in make_APA like [apa#][paddle#]
323 
324 $PaddleYPositions[0][0] = $APAFrame_y[0]/2; # this puts it in the y center
325 $PaddleYPositions[1][0] = $APAFrame_y[1] - 4*$inch - $LightPaddle_y/2;
326 $PaddleYPositions[2][0] = $APAFrame_y[2] - 4*$inch - $LightPaddle_y/2;
327 $PaddleYPositions[3][0] = $PaddleYPositions[0][0];
328 
329 $PaddleYPositions[0][1] = $APAFrame_y[0] - 4*$inch - $LightPaddle_y/2;
330 $PaddleYPositions[3][1] = $PaddleYPositions[0][1];
331 
332 $PaddleYPositions[0][2] = 4*$inch + $LightPaddle_y/2;
333 $PaddleYPositions[3][2] = $PaddleYPositions[0][2];
334 
335 
336 
337 ##################################################################
338 ###################### Cryostat parameters #######################
339 
340 
341 $HeightGaseousAr = 14;
342 $FloorToSmallAPAFrame = 22.432;
343 $APAToTopCryo = 34.441;
344 $ClosestAPAToEastWall = 33.225; # To G10 cover, places all of the APAs in z
345 
346 # Long West Short
347 # Drift __________ Drift
348 # | |
349 # | | |
350 # South | | | North Wall
351 # |__________|
352 #
353 # East
354 
355 $CPAToFloor = 26.955;
356 $CPAToCeiling = 36.010;
357 $CPAToEastWall = 27.994;
358 $CPAToWestWall = 76.234;
359 $CPAToSouthWall = 121.945;
360 $CPAToNorthWall = 22.907;
361 
362 
363 
364 
365 $CPATube_OD = 5.066;
366 $CPATube_ID = 4.747;
367 
368 $CPATubeYSide_CenterToCenter = 166.269; # length in *z* direction
369 $CPATubeZSide_CenterToCenter = 207.532; # height in *y* direction
370 
371 $Cathode_x = 0.016;
372 $Cathode_y = $CPATubeZSide_CenterToCenter - $CPATube_OD;
373 $Cathode_z = $CPATubeYSide_CenterToCenter - $CPATube_OD;
374 
375 # Liquid and Gaseous Argon dimensions
376 $Argon_x = $TPCShortDrift_x
377  + $APAFrame_x
378  + $TPCLongDrift_x
379  + $CPAToNorthWall
380  + $CPAToSouthWall + $CPATube_OD;
381 # note that the height y includes liquid and gaseous argon
382 $Argon_y = $APAphys_y[1]
383  + $APAGap_y
384  + $APAphys_y[2]
385  + $APAToTopCryo
386  + $FloorToSmallAPAFrame; # assuming mid_y+smallest_y > largest_y
387 
388 $Argon_z = $CPATubeYSide_CenterToCenter
389  + $CPAToEastWall
390  + $CPAToWestWall;
391 
392 
393 # try hardcoding parameters now that placements/dimensions are more accurate
394 # inside cryostat parameters
395 #$Argon_x = 400.497;
396 #$Argon_y = 270.497;
397 #$Argon_z = 270.497;
398 $NeckInside_x = 100;
399 $NeckInside_y = 75;
400 
401 # Cryostat Dimensions
402 $SteelShellThickness = 0.5*$inch;
403 
404 $Cryostat_x = $Argon_x; # move the steel shell out of volCryostat
405 $Cryostat_y = $Argon_y;
406 $Cryostat_z = $Argon_z;
407 
408 
409 
410 ##################################################################
411 ################# Detector Enclosure parameters ##################
412 
413 
414 # Around the cryostat
415 $ConcretePadding = 30;
416 $FoamPadding = 39.75148;
417 $TotalPadding = $ConcretePadding + $FoamPadding;
418 $CryoWithPadding_x = $Argon_x + 2*$SteelShellThickness + 2*$TotalPadding;
419 $CryoWithPadding_y_noneck = $Argon_y + 2*$SteelShellThickness + 2*$FoamPadding + $ConcretePadding;
420 $CryoWithPadding_y_neck = ($Argon_y + $NeckInside_y) + 2*$SteelShellThickness + $TotalPadding;
421 $CryoWithPadding_z = $Argon_z + 2*$SteelShellThickness + 2*$TotalPadding;
422 
423 print "CryoWithPadding: x=$CryoWithPadding_x, y=$CryoWithPadding_y_noneck ($CryoWithPadding_y_neck), z=$CryoWithPadding_z\n";
424 print "Cryo: x=$Argon_x, y=$Argon_y (+$NeckInside_y), z=$Argon_z\n";
425 
426 
427 # The actual enclosure
428 $TrenchLength = 9*$CryoWithPadding_x; # make this a reasonable length, still guessing
429  # quick measurments by Michelle Stancari, definitely good enough for now
430 $TrenchWallThickness = 14*$inch;
431 $WalkwayWidth = 34.5*$inch;
432 $EastWallToTrench = 10*$inch;
433 $PlateAToGroundLevel = 50*$inch;
434 
435 
436 # Bird's eye view of trench, walkway is on the west side
437 # | |
438 # | |<-- trench wall
439 # | |
440 # | ___N__ |
441 # | | ____ ||
442 # | | ||
443 # | W|______||E +z <---| (+y out of screen)
444 # | |______|| |
445 # | ^ | v
446 # | Neck | +x
447 # | |
448 # | |
449 # | |
450 
451 # the container volume dimensions
452 $DetEnc_x = $TrenchLength;
453 $DetEnc_y = $TrenchWallThickness # use this for thickness of floor too
454  + $CryoWithPadding_y_noneck
455  + $PlateAToGroundLevel; # Make ground level the top of the DetEnc
456 $DetEnc_z = $CryoWithPadding_z
457  + $WalkwayWidth + $EastWallToTrench
458  + 2*$TrenchWallThickness;
459 
460 
461 $posCryoInDetEnc_x = 0;
462 $posCryoInDetEnc_y = - $DetEnc_y/2 + $TrenchWallThickness + $TotalPadding + $SteelShellThickness + $Argon_y/2;
463 $posCryoInDetEnc_z = - $DetEnc_z/2 + $TrenchWallThickness + $EastWallToTrench + $CryoWithPadding_z/2;
464 
465 
466 
467 
468 $PosDirCubeSide = 0;
469 if (defined $helpcube)
470 {
471 $PosDirCubeSide = $ArToAr; #seems to be a good proportion
472 }
473 
474 
475 # The world dimensions are critical in the CRY cosmics generator
476 # following uboone's lead, make world much larger
477 # the cry helper needs a lot of room
478 
479 
480 $World_x = 5*$DetEnc_x;
481 $World_y = 25*$DetEnc_y;
482 $World_z = 25*$DetEnc_z;
483 
484 $BermRadius = 5*12*$inch;
485 
486 
487 
488 
489 
490 ##################################################################
491 ######################### TPC positions ##########################
492 
493 
494 $APA_Xcenter = $Argon_x/2
495  - $CPAToSouthWall # to center CPATube
496  - $CPATube_OD
497  - $TPCLongDrift_x
498  - $APAFrame_x/2;
499 
500 # 0: One of the 2 identical tall APAs (Largest), call it the "upstream" one
501 $APACenter[0][0] = $APA_Xcenter;
502 $APACenter[0][1] = $Argon_y/2
503  - $APAToTopCryo # This subsumes the half vertical gap on the top...
504  - $APAphys_y[0]/2; # ... so use APAphys_y instead of TPC_y
505 $APACenter[0][2] = - $Argon_z/2
506  + $ClosestAPAToEastWall # ..Similarly, this already steps into the APAGap_z/2
507  + $APAphys_z/2;
508 
509 
510 # 1: The top middle APA (Mid)
511 $APACenter[1][0] = $APA_Xcenter;
512 $APACenter[1][1] = $Argon_y/2
513  - $APAToTopCryo
514  - $APAphys_y[1]/2;
515 $APACenter[1][2] = $APACenter[0][2]
516  + $APAphys_z + $APAGap_z;
517 
518 # 2: The bottom middle APA (Smallest)
519 $APACenter[2][0] = $APA_Xcenter;
520 $APACenter[2][1] = $APACenter[1][1] # place relative to APA above it
521  - $APAphys_y[1]/2
522  - $APAGap_y
523  - $APAphys_y[2]/2;
524 $APACenter[2][2] = $APACenter[0][2]
525  + $APAphys_z + $APAGap_z;
526 
527 # 3: The other tall APA, call it the "downstream" one
528 $APACenter[3][0] = $APACenter[0][0];
529 $APACenter[3][1] = $APACenter[0][1];
530 $APACenter[3][2] = $APACenter[1][2]
531  + $APAphys_z + $APAGap_z;
532 
533 $posTPCShortDrift_x = $APACenter[0][0]
534  - $APAFrame_x/2
535  - $TPCShortDrift_x/2;
536 
537 $posTPCLongDrift_x = $APACenter[0][0]
538  + $APAFrame_x/2
539  + $TPCLongDrift_x/2;
540 
541 
542 
543 
544 # We want the active volumes to extend all the way to the field cage
545 # so that LArG4 tracks everything inside the cage.
546 $TPCActive_z[0] = $APAphys_z
547  - ($APAphys_z-$Zactive_z)/2
548  + $APAGap_z/2
549  + $OuterWireToCage;
550 $TPCActive_z[1] = $APAphys_z + $APAGap_z;
551 $TPCActive_z[2] = $APAphys_z + $APAGap_z;
552 $TPCActive_z[3] = $TPCActive_z[0];
553 
554 
555 $TPCActive_y[0] = $APAphys_y[0]
556  + $TopAPAToCage
557  + $BottomTallAPAToCage;
558 $TPCActive_y[1] = $APAphys_y[1]
559  + $APAGap_y/2
560  + $TopAPAToCage;
561 $TPCActive_y[2] = $APAphys_y[2]
562  + $APAGap_y/2
563  + $BottomShortAPAToCage
564  + $UVPlaneBoundNudge; # Without this relatively negligible addition, the nudge
565  # further downstream on the plane causes the planes to extrude
566  # the TPC volume, whose height is TPCActive_y.
567  # The plane nudge is to avoid many overlaps between the wire
568  # corners and the plane boundaries.
569 $TPCActive_y[3] = $TPCActive_y[0];
570 
571 
572 
573 
574 $TPCCenter[0][2] = $APACenter[0][2]
575  - $Zactive_z/2
576  - $OuterWireToCage
577  + $TPCActive_z[0]/2;
578 $TPCCenter[1][2] = $APACenter[1][2];
579 $TPCCenter[2][2] = $APACenter[2][2];
580 $TPCCenter[3][2] = $APACenter[3][2]
581  + $Zactive_z/2
582  + $OuterWireToCage
583  - $TPCActive_z[0]/2;
584 
585 
586 
587 $TPCCenter[0][1] = $APACenter[0][1]
588  - $APAphys_y[0]/2
589  - $BottomTallAPAToCage
590  + $TPCActive_y[0]/2;
591 $TPCCenter[1][1] = $APACenter[1][1]
592  + $APAphys_y[1]/2
593  + $TopAPAToCage
594  - $TPCActive_y[1]/2;
595 $TPCCenter[2][1] = $APACenter[2][1]
596  - $APAphys_y[2]/2
597  - $BottomShortAPAToCage
598  + $TPCActive_y[2]/2;
599 $TPCCenter[3][1] = $TPCCenter[0][1];
600 
601 
602 
603 
604 
605  # We want the world origin to be at the very front of the fiducial volume.
606  # move it to the front of the enclosure, then back it up through the concrete/foam,
607  # then through the Cryostat shell, then through the upstream dead LAr (including the
608  # dead LAr on the edge of the TPC, but this is covered in $UpstreamLArPadding).
609  # This is to be added to the z position of every volume in volWorld
610 
611 $OriginZSet =
612  - $DetEnc_z/2
613  + $TrenchWallThickness
614  + $WalkwayWidth
615  + $TotalPadding
616  + $SteelShellThickness
617  + $Argon_z/2 # at this point, we are at the center of the cryostat...
618  - $APACenter[0][2] # ... and now at the center of the East-most APA
619  + $Uactive_z/2;
620 
621  # We want the world origin to be vertically centered between the two stacked APAs.
622  # (for now, that is, so the sorting works. this is quite asymetric, but then again
623  # so is the entire 35t geometry. this may be kept.)
624  # the cryostat sits on top of concrete padding, move the detector enclosure back
625  # and then move the world origin to the bottom of the smallest/lowest TPC, then
626  # and then up through the TPC, then back up to being centered between the stacked APAs.
627  # This is to be added to the y/x position of every volume in volWorld
628 
629 $OriginYSet =
630  $DetEnc_y/2
631  - $TrenchWallThickness
632  - $TotalPadding
633  - $SteelShellThickness
634  - $Argon_y
635  + $APAToTopCryo
636  + $APAphys_y[1]
637  + $APAGap_y/2;
638 
639 
640 
641 
642 #$OriginXSet = $DetEnc_x/2
643 # - $TotalPadding
644 # - $SteelShellThickness
645 # - $CPAToNorthWall
646 # - $CPATube_OD
647 # - $ShortDrift ... through APA frame
648 
649 $OriginXSet =
650  - $CryoWithPadding_x/2
651  + $TotalPadding
652  + $SteelShellThickness
653  + $Argon_x/2 # at this point, we are at the center of the cryostat...
654  - $APA_Xcenter # ... and now at the APA's center x coordinate
655  - $APAFrame_x/2
656  - 3*$APAWirePlaneSpacing
657  - $TPCWirePlaneThickness;
658 
659 
660 
661 ##
662 ## Correct Telescope Aux Det vertical position if necessary
663 ##
664 if( $posCryoInDetEnc_y
665  + $Argon_y/2
666  + $SteelShellThickness
667  + $FoamPadding
668  + $AuxDetBSUScintHeight/2 > $BSULayer1_ypos - $OriginYSet ){
669 
670  $nudge_y = ( $posCryoInDetEnc_y
671  + $Argon_y/2
672  + $SteelShellThickness
673  + $FoamPadding
674  + $AuxDetBSUScintHeight/2
675  + $OriginYSet ) - $BSULayer1_ypos;
676 
677  print "--- NOTE: nudging telescope counters $nudge_y cm up to sit on top of GDML cryostat\n";
678 
679  $BSULayer1_ypos += $nudge_y;
680  $BSULayer2_ypos += $nudge_y;
681  $BSULayer3_ypos += $nudge_y;
682  $BSULayer4_ypos += $nudge_y;
683  $BSULayer5_ypos += $nudge_y;
684 
685 }
686 
687 
688 
689 ##################################################################
690 ######################### CPA positions ##########################
691 
692 # Long West Short
693 # Drift __________ Drift
694 # | |
695 # | | |
696 # South | | | North Wall
697 # |__________|
698 #
699 # East
700 
701 #$posCPAShortDrift_x = - $Argon_x/2 + $CPAToNorthWall + $CPATube_OD/2;
702 #$posCPALongDrift_x = $Argon_x/2 - $CPAToSouthWall - $CPATube_OD/2;
703 
704 # ^^^ these would be ideal, but quick fix to check in
705 # v3 without overlaps:
706 
707 #$posCPAShortDrift_x = - $Argon_x/2 + $CPAToNorthWall + $CPATube_OD/2;
708 #$posCPALongDrift_x = $Argon_x/2 - $CPAToSouthWall - $CPATube_OD/2;
709 $posCPAShortDrift_x = $posTPCShortDrift_x - $TPCShortDrift_x/2
710  - $CPATube_OD; #<-- temp overlap fix
711 $posCPALongDrift_x = $posTPCLongDrift_x + $TPCLongDrift_x/2
712  + $CPATube_OD; #<-- temp overlap fix
713 
714 
715 $posCPAShortDrift_y = - $Argon_y/2 + $CPAToFloor
716  + ($CPATubeZSide_CenterToCenter + $CPATube_OD)/2;
717 $posCPAShortDrift_z = - $Argon_z/2 + $CPAToEastWall
718  + ($CPATubeYSide_CenterToCenter + $CPATube_OD)/2;
719 
720 $posCPALongDrift_y = $posCPAShortDrift_y;
721 $posCPALongDrift_z = $posCPAShortDrift_z;
722 
723 
724 
725 
726 
727 ##################################################################
728 #################### Bar Fiber Module numbers ####################
729 $numberofbarmodules=4;
730 $numberoffibermodules=3;
731 $numberofplankmodules=1;
732 
733 $PaddleCenterX=$APA_Xcenter;
734 $PaddleCenterY[0][0]=$APACenter[0][1]-$APAFrame_y[0]/2+ $PaddleYPositions[0][0];
735 $PaddleCenterY[0][1]=$APACenter[0][1]-$APAFrame_y[0]/2+ $PaddleYPositions[0][1];
736 $PaddleCenterY[0][2]=$APACenter[0][1]-$APAFrame_y[0]/2+ $PaddleYPositions[0][2];
737 $PaddleCenterY[1][0]=$APACenter[1][1]-$APAFrame_y[1]/2+ $PaddleYPositions[1][0];
738 $PaddleCenterY[2][0]=$APACenter[2][1]-$APAFrame_y[2]/2+ $PaddleYPositions[2][0];
739 $PaddleCenterY[3][0]=$PaddleCenterY[0][0];
740 $PaddleCenterY[3][1]=$PaddleCenterY[0][1];
741 $PaddleCenterY[3][2]=$PaddleCenterY[0][2];
742 $PaddleCenterZ[0]=$APACenter[0][2];
743 $PaddleCenterZ[1]=$APACenter[1][2];
744 $PaddleCenterZ[2]=$APACenter[2][2];
745 $PaddleCenterZ[3]=$APACenter[3][2];
746 ################
747 
748 #+++++++++++++++++++++++++ End defining variables ++++++++++++++++++++++++++
749 
750 
751 
752 # run the sub routines that generate the fragments
753 
754 gen_Define(); # generates definitions at beginning of GDML
755 gen_Materials(); # generates materials to be used
756 
757 
758 # gen_TPC( x dimension, y, z, string appended to TPC for name, APA number)
759 # generate the short drift and long drift sides of the APA as seperate TPCs
760 
761 open(my $wout, '>', 'gdmlWireCenters.txt');
762 
763  gen_TPC( $TPCLongDrift_x, $TPCActive_y[0], $TPCActive_z[0], 'LargestLongDriftUpstream', 0);
764  gen_TPC( $TPCShortDrift_x, $TPCActive_y[0], $TPCActive_z[0], 'LargestShortDriftUpstream', 0);
765 
766  gen_TPC( $TPCLongDrift_x, $TPCActive_y[2], $TPCActive_z[2], 'SmallestLongDrift', 2);
767  gen_TPC( $TPCShortDrift_x, $TPCActive_y[2], $TPCActive_z[2], 'SmallestShortDrift', 2);
768 
769  gen_TPC( $TPCLongDrift_x, $TPCActive_y[1], $TPCActive_z[1], 'MidLongDrift', 1);
770  gen_TPC( $TPCShortDrift_x, $TPCActive_y[1], $TPCActive_z[1], 'MidShortDrift', 1);
771 
772  gen_TPC( $TPCLongDrift_x, $TPCActive_y[0], $TPCActive_z[3], 'LargestLongDriftDownstream', 3);
773  gen_TPC( $TPCShortDrift_x, $TPCActive_y[0], $TPCActive_z[3], 'LargestShortDriftDownstream', 3);
774 
775 close $wout;
776 
777 gen_Cryostat();
778 gen_Enclosure();
779 gen_World();
780 
781 
782 write_fragments(); # writes the XML input for make_gdml.pl
783  # which zips together the final GDML
784 exit;
785 
786 
787 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
788 #+++++++++++++++++++++++++++++++++++++++++ usage +++++++++++++++++++++++++++++++++++++++++
789 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
790 
791 sub usage()
792 {
793  print "Usage: $0 [-h|--help] [-o|--output <fragments-file>] [-s|--suffix <string>]\n";
794  print " if -o is omitted, output goes to STDOUT; <fragments-file> is input to make_gdml.pl\n";
795  print " -s <string> appends the string to the file names; useful for multiple detector versions\n";
796  print " -h prints this message, then quits\n";
797 }
798 
799 
800 
801 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
802 #++++++++++++++++++++++++++++++++++++++ gen_Define +++++++++++++++++++++++++++++++++++++++
803 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
804 
805 sub gen_Define()
806 {
807 
808 # Create the <define> fragment file name,
809 # add file to list of fragments,
810 # and open it
811  $DEF = "dune_10kT_Def" . $suffix . ".gdml";
812  push (@gdmlFiles, $DEF);
813  $DEF = ">" . $DEF;
814  open(DEF) or die("Could not open file $DEF for writing");
815 
816 
817 print DEF <<EOF;
818 <?xml version='1.0'?>
819 <gdml>
820 <define>
821 
822 <!--
823 
824 
825 
826 -->
827 
828  <position name="posOriginSet" unit="cm" x="$OriginXSet" y="$OriginYSet" z="$OriginZSet"/>
829 
830  <position name="posTPCLargestShortDrift_Pos" unit="cm" x="$posTPCShortDrift_x" y="$TPCCenter[3][1]" z="$TPCCenter[3][2]"/>
831  <position name="posTPCLargestLongDrift_Pos" unit="cm" x="$posTPCLongDrift_x" y="$TPCCenter[3][1]" z="$TPCCenter[3][2]"/>
832  <position name="posTPCLargestShortDrift_Neg" unit="cm" x="$posTPCShortDrift_x" y="$TPCCenter[0][1]" z="$TPCCenter[0][2]"/>
833  <position name="posTPCLargestLongDrift_Neg" unit="cm" x="$posTPCLongDrift_x" y="$TPCCenter[0][1]" z="$TPCCenter[0][2]"/>
834  <position name="posTPCSmallestShortDrift" unit="cm" x="$posTPCShortDrift_x" y="$TPCCenter[2][1]" z="$TPCCenter[2][2]"/>
835  <position name="posTPCSmallestLongDrift" unit="cm" x="$posTPCLongDrift_x" y="$TPCCenter[2][1]" z="$TPCCenter[2][2]"/>
836  <position name="posTPCMidShortDrift" unit="cm" x="$posTPCShortDrift_x" y="$TPCCenter[1][1]" z="$TPCCenter[1][2]"/>
837  <position name="posTPCMidLongDrift" unit="cm" x="$posTPCLongDrift_x" y="$TPCCenter[1][1]" z="$TPCCenter[1][2]"/>
838 
839 
840  <position name="posCathodeLongDrift" unit="cm" x="$posCPAShortDrift_x" y="$posCPAShortDrift_y" z="$posCPAShortDrift_z"/>
841  <position name="posCathodeShortDrift" unit="cm" x="$posCPALongDrift_x" y="$posCPALongDrift_y" z="$posCPALongDrift_z"/>
842 
843  <rotation name="rAuxDetNSWallUp" unit="deg" x="90" y="0" z="90"/>
844  <rotation name="rAuxDetNSWallDown" unit="deg" x="270" y="0" z="90"/>
845  <rotation name="rAuxDetEWWallUp" unit="deg" x="90" y="0" z="0"/>
846  <rotation name="rAuxDetEWWallDown" unit="deg" x="270" y="0" z="0"/>
847 
848  <position name="posCenter" unit="cm" x="0" y="0" z="0"/>
849  <rotation name="rPlus90AboutX" unit="deg" x="90" y="0" z="0"/>
850  <rotation name="rPlus90AboutY" unit="deg" x="0" y="90" z="0"/>
851  <rotation name="rMinus90AboutY" unit="deg" x="0" y="270" z="0"/>
852  <rotation name="rMinus90AboutYMinus90AboutX" unit="deg" x="270" y="270" z="0"/>
853  <rotation name="rPlus180AboutY" unit="deg" x="0" y="180" z="0"/>
854  <rotation name="rPlus180AboutX" unit="deg" x="180" y="0" z="0"/>
855  <rotation name="rPlus180AboutXandY" unit="deg" x="180" y="180" z="0"/>
856  <rotation name="rIdentity" unit="deg" x="0" y="0" z="0"/>
857 EOF
858 
859 ##################################################################
860 ###################### Bar Module Position #######################
861 for ($k=1; $k<$numberofbarmodules+1; ++$k)
862 {
863 if($k==1) {$APA_i=1;$p=0;$PD_zoffset=0;}
864 elsif($k==2) {$APA_i=0;$p=1;$PD_zoffset=0;}
865 elsif($k==3) {$APA_i=0;$p=2;$PD_zoffset=-0.00051;}
866 elsif($k==4) {$APA_i=3;$p=0;$PD_zoffset=0;}
867 
868 #for ($j=1; $j<$numberofbars+1; ++$j)
869 #{
870 #$bar_z=-4.11 + 2.74*($j-1)+$PaddleCenterZ[$APA_i];
871 $bar_z=$PaddleCenterZ[$APA_i]+2.794*1.5+$PD_zoffset;
872 $bar_name="Bar" . $k . "Pos";
873 print DEF <<EOF;
874  <position name="$bar_name" x="$PaddleCenterX" y="$PaddleCenterY[$APA_i][$p]" z="$bar_z" unit="cm"/>
875 EOF
876 #}
877 }
878 
879 ##################################################################
880 ##################### Plank Module Position ######################
881 for ($k=1; $k<$numberofplankmodules+1; ++$k)
882 {
883 if($k==1) {$APA_i=3;$p=2;}
884 
885 $plank_name="PlankPos";
886 print DEF <<EOF;
887  <position name="$plank_name" x="$PaddleCenterX" y="$PaddleCenterY[$APA_i][$p]" z="$PaddleCenterZ[$APA_i]" unit="cm"/>
888 EOF
889 
890 }
891 ##################################################################
892 ##################### Fiber Module Position ######################
893 
894 for ($k=1; $k<$numberoffibermodules+1; ++$k)
895 {
896 if($k==1) {$APA_i=2;$p=0;$PD_zoffset=0;}
897 elsif($k==2) {$APA_i=0;$p=0;$PD_zoffset=0;}
898 elsif($k==3) {$APA_i=3;$p=1;$PD_zoffset=0.00051;}
899 
900 $fiber_x=$PaddleCenterX+0.1445;
901 $fiber_y=$PaddleCenterY[$APA_i][$p];
902 $fiber_z=$PaddleCenterZ[$APA_i]+4.1905+$PD_zoffset;
903 
904 $fiber_name="Fiber" . $k. "Pos";
905 print DEF <<EOF;
906  <position name="$fiber_name" x="$fiber_x" y="$fiber_y" z="$fiber_z" unit="cm"/>
907 EOF
908 
909 }
910 
911 print DEF <<EOF;
912 </define>
913 </gdml>
914 EOF
915  close (DEF);
916 }
917 
918 
919 
920 
921 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
922 #+++++++++++++++++++++++++++++++++++++ gen_Materials +++++++++++++++++++++++++++++++++++++
923 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
924 
925 sub gen_Materials()
926 {
927 
928 # Create the <materials> fragment file name,
929 # add file to list of output GDML fragments,
930 # and open it
931  $MAT = "dune_10kT_Materials" . $suffix . ".gdml";
932  push (@gdmlFiles, $MAT);
933  $MAT = ">" . $MAT;
934  open(MAT) or die("Could not open file $MAT for writing");
935 
936 
937  print MAT <<EOF;
938 <materials>
939  <element name="videRef" formula="VACUUM" Z="1"> <atom value="1"/> </element>
940  <element name="hydrogen" formula="H" Z="1"> <atom value="1.0079"/> </element>
941  <element name="beryllium" formula="Be" Z="4"> <atom value="9.0121831"/> </element>
942  <element name="carbon" formula="C" Z="6"> <atom value="12.0107"/> </element>
943  <element name="nitrogen" formula="N" Z="7"> <atom value="14.0067"/> </element>
944  <element name="oxygen" formula="O" Z="8"> <atom value="15.999"/> </element>
945  <element name="sodium" formula="Na" Z="11"> <atom value="22.99"/> </element>
946  <element name="magnesium" formula="Mg" Z="12"> <atom value="24.305"/> </element>
947  <element name="aluminum" formula="Al" Z="13"> <atom value="26.9815"/> </element>
948  <element name="silicon" formula="Si" Z="14"> <atom value="28.0855"/> </element>
949  <element name="phosphorus" formula="P" Z="15"> <atom value="30.973"/> </element>
950  <element name="sulphur" formula="S" Z="16"> <atom value="32.065"/> </element>
951  <element name="argon" formula="Ar" Z="18"> <atom value="39.9480"/> </element>
952  <element name="potassium" formula="K" Z="19"> <atom value="39.0983"/> </element>
953  <element name="calcium" formula="Ca" Z="20"> <atom value="40.078"/> </element>
954  <element name="titanium" formula="Ti" Z="22"> <atom value="47.867"/> </element>
955  <element name="chromium" formula="Cr" Z="24"> <atom value="51.9961"/> </element>
956  <element name="iron" formula="Fe" Z="26"> <atom value="55.8450"/> </element>
957  <element name="nickel" formula="Ni" Z="28"> <atom value="58.6934"/> </element>
958  <element name="copper" formula="Cu" Z="29"> <atom value="63.546"/> </element>
959  <element name="bromine" formula="Br" Z="35"> <atom value="79.904"/> </element>
960 
961  <material name="Vacuum" formula="Vacuum">
962  <D value="1.e-25" unit="g/cm3"/>
963  <fraction n="1.0" ref="videRef"/>
964  </material>
965 
966  <material name="ALUMINUM_Al" formula="ALUMINUM_Al">
967  <D value="2.6990" unit="g/cm3"/>
968  <fraction n="1.0000" ref="aluminum"/>
969  </material>
970 
971  <material name="SILICON_Si" formula="SILICON_Si">
972  <D value="2.3300" unit="g/cm3"/>
973  <fraction n="1.0000" ref="silicon"/>
974  </material>
975 
976  <material name="epoxy_resin" formula="C38H40O6Br4">
977  <D value="1.1250" unit="g/cm3"/>
978  <composite n="38" ref="carbon"/>
979  <composite n="40" ref="hydrogen"/>
980  <composite n="6" ref="oxygen"/>
981  <composite n="4" ref="bromine"/>
982  </material>
983 
984  <material name="SiO2" formula="SiO2">
985  <D value="2.2" unit="g/cm3"/>
986  <composite n="1" ref="silicon"/>
987  <composite n="2" ref="oxygen"/>
988  </material>
989 
990  <material name="Al2O3" formula="Al2O3">
991  <D value="3.97" unit="g/cm3"/>
992  <composite n="2" ref="aluminum"/>
993  <composite n="3" ref="oxygen"/>
994  </material>
995 
996  <material name="Polystyrene" formula="C8H8">
997  <D value="1.05" unit="g/cm3"/>
998  <composite n="8" ref="carbon"/>
999  <composite n="8" ref="hydrogen"/>
1000  </material>
1001 
1002  <material name="Fe2O3" formula="Fe2O3">
1003  <D value="5.24" unit="g/cm3"/>
1004  <composite n="2" ref="iron"/>
1005  <composite n="3" ref="oxygen"/>
1006  </material>
1007 
1008  <material name="CaO" formula="CaO">
1009  <D value="3.35" unit="g/cm3"/>
1010  <composite n="1" ref="calcium"/>
1011  <composite n="1" ref="oxygen"/>
1012  </material>
1013 
1014  <material name="MgO" formula="MgO">
1015  <D value="3.58" unit="g/cm3"/>
1016  <composite n="1" ref="magnesium"/>
1017  <composite n="1" ref="oxygen"/>
1018  </material>
1019 
1020  <material name="Na2O" formula="Na2O">
1021  <D value="2.27" unit="g/cm3"/>
1022  <composite n="2" ref="sodium"/>
1023  <composite n="1" ref="oxygen"/>
1024  </material>
1025 
1026  <material name="TiO2" formula="TiO2">
1027  <D value="4.23" unit="g/cm3"/>
1028  <composite n="1" ref="titanium"/>
1029  <composite n="2" ref="oxygen"/>
1030  </material>
1031 
1032  <material name="FeO" formula="FeO">
1033  <D value="5.745" unit="g/cm3"/>
1034  <composite n="1" ref="iron"/>
1035  <composite n="1" ref="oxygen"/>
1036  </material>
1037 
1038  <material name="CO2" formula="CO2">
1039  <D value="1.562" unit="g/cm3"/>
1040  <composite n="1" ref="carbon"/>
1041  <composite n="2" ref="oxygen"/>
1042  </material>
1043 
1044  <material name="P2O5" formula="P2O5">
1045  <D value="1.562" unit="g/cm3"/>
1046  <composite n="2" ref="phosphorus"/>
1047  <composite n="5" ref="oxygen"/>
1048  </material>
1049 
1050  <material formula=" " name="DUSEL_Rock">
1051  <D value="2.82" unit="g/cm3"/>
1052  <fraction n="0.5267" ref="SiO2"/>
1053  <fraction n="0.1174" ref="FeO"/>
1054  <fraction n="0.1025" ref="Al2O3"/>
1055  <fraction n="0.0473" ref="MgO"/>
1056  <fraction n="0.0422" ref="CO2"/>
1057  <fraction n="0.0382" ref="CaO"/>
1058  <fraction n="0.0240" ref="carbon"/>
1059  <fraction n="0.0186" ref="sulphur"/>
1060  <fraction n="0.0053" ref="Na2O"/>
1061  <fraction n="0.00070" ref="P2O5"/>
1062  <fraction n="0.0771" ref="oxygen"/>
1063  </material>
1064 
1065  <material name="fibrous_glass">
1066  <D value="2.58" unit="g/cm3"/>
1067  <fraction n="0.600" ref="SiO2"/>
1068  <fraction n="0.118" ref="Al2O3"/>
1069  <fraction n="0.001" ref="Fe2O3"/>
1070  <fraction n="0.224" ref="CaO"/>
1071  <fraction n="0.034" ref="MgO"/>
1072  <fraction n="0.010" ref="Na2O"/>
1073  <fraction n="0.013" ref="TiO2"/>
1074  </material>
1075 
1076 <!-- The following fractional components are placeholders,
1077  to be fixed (though they have very little effect,
1078  as long as the density is correct) -->
1079  <material name="polyurethane_foam">
1080  <D value=".13" unit="g/cm3"/>
1081  <fraction n="0.600" ref="SiO2"/>
1082  <fraction n="0.118" ref="Al2O3"/>
1083  <fraction n="0.001" ref="Fe2O3"/>
1084  <fraction n="0.224" ref="CaO"/>
1085  <fraction n="0.034" ref="MgO"/>
1086  <fraction n="0.010" ref="Na2O"/>
1087  <fraction n="0.013" ref="TiO2"/>
1088  </material>
1089 
1090 <!-- for the cryostat foam insulation -->
1091  <material name="R-PUF">
1092  <D value=".2525" unit="g/cm3"/>
1093  <fraction n="0.95" ref="polyurethane_foam"/>
1094  <fraction n="0.05" ref="fibrous_glass"/>
1095  </material>
1096 
1097  <material name="FR4">
1098  <D value="1.98281" unit="g/cm3"/>
1099  <fraction n="0.47" ref="epoxy_resin"/>
1100  <fraction n="0.53" ref="fibrous_glass"/>
1101  </material>
1102 
1103  <material name="STEEL_STAINLESS_Fe7Cr2Ni" formula="STEEL_STAINLESS_Fe7Cr2Ni">
1104  <D value="7.9300" unit="g/cm3"/>
1105  <fraction n="0.0010" ref="carbon"/>
1106  <fraction n="0.1792" ref="chromium"/>
1107  <fraction n="0.7298" ref="iron"/>
1108  <fraction n="0.0900" ref="nickel"/>
1109  </material>
1110 
1111  <material name="Copper_Beryllium_alloy25" formula="Copper_Beryllium_alloy25">
1112  <D value="8.26" unit="g/cm3"/>
1113  <fraction n="0.981" ref="copper"/>
1114  <fraction n="0.019" ref="beryllium"/>
1115  </material>
1116 
1117  <material name="LAr" formula="LAr">
1118  <D value="1.40" unit="g/cm3"/>
1119  <fraction n="1.0000" ref="argon"/>
1120  </material>
1121 
1122  <material name="ArGas" formula="ArGas">
1123  <D value="0.00166" unit="g/cm3"/>
1124  <fraction n="1.0" ref="argon"/>
1125  </material>
1126 
1127  <material formula=" " name="Air">
1128  <D value="0.001205" unit="g/cm3"/>
1129  <fraction n="0.781154" ref="nitrogen"/>
1130  <fraction n="0.209476" ref="oxygen"/>
1131  <fraction n="0.00934" ref="argon"/>
1132  </material>
1133 
1134  <material formula=" " name="G10">
1135  <D value="1.7" unit="g/cm3"/>
1136  <fraction n="0.2805" ref="silicon"/>
1137  <fraction n="0.3954" ref="oxygen"/>
1138  <fraction n="0.2990" ref="carbon"/>
1139  <fraction n="0.0251" ref="hydrogen"/>
1140  </material>
1141 
1142  <material formula=" " name="Granite">
1143  <D value="2.7" unit="g/cm3"/>
1144  <fraction n="0.438" ref="oxygen"/>
1145  <fraction n="0.257" ref="silicon"/>
1146  <fraction n="0.222" ref="sodium"/>
1147  <fraction n="0.049" ref="aluminum"/>
1148  <fraction n="0.019" ref="iron"/>
1149  <fraction n="0.015" ref="potassium"/>
1150  </material>
1151 
1152  <material formula=" " name="ShotRock">
1153  <D value="2.7*0.6" unit="g/cm3"/>
1154  <fraction n="0.438" ref="oxygen"/>
1155  <fraction n="0.257" ref="silicon"/>
1156  <fraction n="0.222" ref="sodium"/>
1157  <fraction n="0.049" ref="aluminum"/>
1158  <fraction n="0.019" ref="iron"/>
1159  <fraction n="0.015" ref="potassium"/>
1160  </material>
1161 
1162  <material formula=" " name="Dirt">
1163  <D value="1.7" unit="g/cm3"/>
1164  <fraction n="0.438" ref="oxygen"/>
1165  <fraction n="0.257" ref="silicon"/>
1166  <fraction n="0.222" ref="sodium"/>
1167  <fraction n="0.049" ref="aluminum"/>
1168  <fraction n="0.019" ref="iron"/>
1169  <fraction n="0.015" ref="potassium"/>
1170  </material>
1171 
1172  <material formula=" " name="Concrete">
1173  <D value="2.3" unit="g/cm3"/>
1174  <fraction n="0.530" ref="oxygen"/>
1175  <fraction n="0.335" ref="silicon"/>
1176  <fraction n="0.060" ref="calcium"/>
1177  <fraction n="0.015" ref="sodium"/>
1178  <fraction n="0.020" ref="iron"/>
1179  <fraction n="0.040" ref="aluminum"/>
1180  </material>
1181 
1182  <material formula="H2O" name="Water">
1183  <D value="1.0" unit="g/cm3"/>
1184  <fraction n="0.1119" ref="hydrogen"/>
1185  <fraction n="0.8881" ref="oxygen"/>
1186  </material>
1187 
1188  <material formula="Ti" name="Titanium">
1189  <D value="4.506" unit="g/cm3"/>
1190  <fraction n="1." ref="titanium"/>
1191  </material>
1192 
1193  <material name="TPB" formula="TPB">
1194  <D value="1.40" unit="g/cm3"/>
1195  <fraction n="1.0000" ref="argon"/>
1196  </material>
1197 
1198  <material name="Glass">
1199  <D value="2.74351" unit="g/cm3"/>
1200  <fraction n="0.600" ref="SiO2"/>
1201  <fraction n="0.118" ref="Al2O3"/>
1202  <fraction n="0.001" ref="Fe2O3"/>
1203  <fraction n="0.224" ref="CaO"/>
1204  <fraction n="0.034" ref="MgO"/>
1205  <fraction n="0.010" ref="Na2O"/>
1206  <fraction n="0.013" ref="TiO2"/>
1207  </material>
1208 
1209  <material name="Acrylic">
1210  <D value="1.19" unit="g/cm3"/>
1211  <fraction n="0.600" ref="carbon"/>
1212  <fraction n="0.320" ref="oxygen"/>
1213  <fraction n="0.080" ref="hydrogen"/>
1214  </material>
1215 
1216  <material name="Plastic" formula="Plastic">
1217  <D value="1.032" unit="g/cm3"/>
1218  <fraction n=".474" ref="carbon"/>
1219  <fraction n=".526" ref="hydrogen"/>
1220  </material>
1221 
1222 </materials>
1223 EOF
1224 
1225 close(MAT);
1226 }
1227 
1228 
1229 
1230 
1231 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1232 #++++++++++++++++++++++++++++++++++++++++ gen_TPC ++++++++++++++++++++++++++++++++++++++++
1233 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1234 
1235 
1236 sub gen_TPC()
1237 {
1238 
1239 # $_[0] = $TPC_x
1240 # $_[1] = $TPC_y
1241 # $_[2] = $TPC_z
1242 # $_[3] = 'name'
1243 # $_[4] = APA number
1244 
1245  my $apa = $_[4];
1246 
1247  my $TPCActive_x = $_[0]-(3*$APAWirePlaneSpacing);
1248  my $TPCActive_y = $_[1] - $APAGap_y/2 - $ReadoutBoardOverlap;
1249 
1250  my $UAngle = $UAng[$apa];
1251  my $VAngle = $VAng[$apa];
1252 
1253  my $SinUAngle = sin( deg2rad($UAngle) );
1254  my $CosUAngle = cos( deg2rad($UAngle) );
1255  my $TanUAngle = tan( deg2rad($UAngle) );
1256 
1257  my $SinVAngle = sin( deg2rad($VAngle) );
1258  my $CosVAngle = cos( deg2rad($VAngle) );
1259  my $TanVAngle = tan( deg2rad($VAngle) );
1260 
1261  my $UWire_yint = $UWirePitch/$SinUAngle;
1262  my $UWire_zint = $UVReadoutBoardPitch ;
1263 
1264  my $VWire_yint = $VWirePitch/$SinVAngle;
1265  my $VWire_zint = $UVReadoutBoardPitch ;
1266 
1267 #constructs everything inside volTPC, namely
1268 # (moving from left to right, or from +x to -x)
1269 # -volCPActive
1270 # -volTPCPlaneU: with wires angled from vertical slightly different than in V
1271 # -volTPCPlaneV: with wires angled from vertical slightly differently than in U
1272 # -volTPCPlaneX: with vertical wires
1273 
1274 
1275 # Create the TPC fragment file name,
1276 # add file to list of output GDML fragments,
1277 # and open it
1278  $TPC = "35t_TPC_${_[3]}" . $suffix . ".gdml";
1279  push (@gdmlFiles, $TPC);
1280  $TPC = ">" . $TPC;
1281  open(TPC) or die("Could not open file $TPC for writing");
1282 
1283 
1284 print $wout "\n\n\n----- Wires for $_[3] -----\n\n\n";
1285 
1286 
1287 # The standard XML prefix and starting the gdml
1288  print TPC <<EOF;
1289 <?xml version='1.0'?>
1290 <gdml>
1291 EOF
1292 
1293 
1294 # All the TPC solids save the wires.
1295 print TPC <<EOF;
1296 <solids>
1297  <box name="$_[3]" lunit="cm"
1298  x="$_[0]"
1299  y="$_[1]"
1300  z="$_[2]"/>
1301  <box name="${_[3]}UPlane" lunit="cm"
1302  x="$TPCWirePlaneThickness"
1303  y="$Uactive_y[$apa] + $UVPlaneBoundNudge"
1304  z="$Uactive_z + $UVPlaneBoundNudge"/>
1305  <box name="${_[3]}VPlane" lunit="cm"
1306  x="$TPCWirePlaneThickness"
1307  y="$Vactive_y[$apa] + $UVPlaneBoundNudge"
1308  z="$Vactive_z + $UVPlaneBoundNudge"/>
1309  <box name="${_[3]}ZPlane" lunit="cm"
1310  x="$TPCWirePlaneThickness"
1311  y="$Zactive_y[$apa]"
1312  z="$Zactive_z"/>
1313  <box name="${_[3]}Active" lunit="cm"
1314  x="$TPCActive_x"
1315  y="$TPCActive_y[$apa]"
1316  z="$TPCActive_z[$apa]"/>
1317 EOF
1318 
1319 
1320 #++++++++++++++++++++++++++++ Wire Solids ++++++++++++++++++++++++++++++
1321 
1322 print TPC <<EOF;
1323 
1324  <tube name="${_[3]}WireVert"
1325  rmax="0.5*$TPCWireThickness"
1326  z="$Zactive_y[$apa]"
1327  deltaphi="360"
1328  aunit="deg"
1329  lunit="cm"/>
1330 EOF
1331 
1332 # Set number of wires to default to zero, when $wires_on = 0, for a low memory
1333 # version. But if $wires_on = 1, calculate the number of wires on each side of each
1334 # plane to be used in the for loops
1335 
1336 my $NumberCornerUWires = 0;
1337 my $NumberSideUWires = 0;
1338 my $NumberCommonUWires = 0;
1339 my $NumberCornerVWires = 0;
1340 my $NumberSideVWires = 0;
1341 my $NumberCommonVWires = 0;
1342 my $NumberVerticalWires = 0;
1343 
1344 if ($wires_on == 1)
1345 {
1346  # Number of wires in one corner
1347 #$NumberCornerUWires = int( $APAFrame_z/($UWirePitch/$CosUAngle) );
1348 $NumberCornerUWires = 72;
1349 
1350 #$NumberCornerVWires = int( $APAFrame_z/($VWirePitch/$CosVAngle) );
1351 $NumberCornerVWires = 72;
1352 
1353  # Total number of wires touching one vertical (longer) side
1354  # Note that the total number of wires per plane is this + another set of corner wires
1355 $NumberSideUWires = int( $Uactive_y[$apa]/($UWirePitch/$SinUAngle) );
1356 
1357 $NumberSideVWires = int( $Vactive_y[$apa]/($VWirePitch/$SinVAngle) );
1358 
1359  # Number of wires per side that aren't cut off by the corner
1360 $NumberCommonUWires = $NumberSideUWires - $NumberCornerUWires;
1361 
1362 $NumberCommonVWires = $NumberSideVWires - $NumberCornerVWires;
1363 
1364  # Number of wires on the vertical plane
1365  # Since APA Active z is defined in docdb 7550 to be distance
1366  # between outer vertical wires, + 1 since the floor of this
1367  # division will be one under, giveing the amt of spaces, not wires
1368 # $NumberVerticalWires = int( $Zactive_z/$XWirePitch ) + 1;
1369 $NumberVerticalWires = 112; # Zactive now defined in terms of 112,
1370 
1371 
1372 $nUchans = 2*$NumberCornerUWires;
1373 $nVchans = 2*$NumberCornerVWires;
1374 
1375 print $wout "$nUchans U channels\n";
1376 print $wout "$nVchans V channels\n";
1377 print $wout "$NumberVerticalWires Z channels per side\n";
1378 
1379 }
1380 
1381 
1382 my $FirstUWireOffset = .35 + $G10thickness + 2*$G10thickness*$TanUAngle - $UVReadoutBoardPitch;
1383 my $FirstVWireOffset = .35; # doesnt include a G10 board in width
1384 
1385 my $FirstTopUWire_yspan =
1386  $Uactive_y[$apa]/2
1387  - ( - $Uactive_y[$apa]/2
1388  + $FirstUWireOffset/$TanUAngle # walk us up to the first wire
1389  + $UWire_yint*($NumberSideUWires-1) # up to the top of the top common wire
1390  - $Uactive_z/$TanUAngle # back to the bottom of the top common wire
1391  + $UWire_yint); # nudge up to bottom of the first top corner wire
1392 
1393 my $FirstTopVWire_yspan =
1394  $Vactive_y[$apa]/2
1395  - ( - $Vactive_y[$apa]/2
1396  + $FirstVWireOffset/$TanVAngle # walk us up to the first wire
1397  + $VWire_yint*($NumberSideVWires-1) # up to the top of the top common wire
1398  - $Vactive_z/$TanVAngle # back to the bottom of the top common wire
1399  + $VWire_yint); # nudge up to bottom of the first top corner wire
1400 
1401 # The corner wires for the U plane
1402 if ($wires_on==1)
1403 {
1404  for ($i = 0; $i < $NumberCornerUWires; $i++)
1405  {
1406  $CornerUWireLength[$i] = ($FirstUWireOffset + $i*$UVReadoutBoardPitch)/$SinUAngle;
1407 
1408  print TPC <<EOF;
1409  <tube name="${_[3]}WireU$i"
1410  rmax="0.5*$TPCWireThickness"
1411  z="$CornerUWireLength[$i]"
1412  deltaphi="360"
1413  aunit="deg"
1414  lunit="cm"/>
1415 EOF
1416 
1417  }
1418 
1419  $CommonUWireLength = $Uactive_z/$SinUAngle;
1420 
1421  print TPC <<EOF;
1422  <tube name="${_[3]}WireUCommon"
1423  rmax="0.5*$TPCWireThickness"
1424  z="$CommonUWireLength"
1425  deltaphi="360"
1426  aunit="deg"
1427  lunit="cm"/>
1428 EOF
1429 
1430  for ($i = 0; $i < $NumberCornerUWires; $i++)
1431  {
1432 
1433  $TopCornerUWireLength[$i] = ($FirstTopUWire_yspan - $i*$UWire_yint)/$CosUAngle;
1434 
1435  $j = $i + $NumberSideUWires;
1436 
1437  print TPC <<EOF;
1438  <tube name="${_[3]}WireU$j"
1439  rmax="0.5*$TPCWireThickness"
1440  z="$TopCornerUWireLength[$i]"
1441  deltaphi="360"
1442  aunit="deg"
1443  lunit="cm"/>
1444 EOF
1445 
1446  }
1447 
1448 }
1449 
1450 
1451 # The corner wires for the V plane
1452 if ($wires_on==1)
1453 {
1454  for ($i = 0; $i < $NumberCornerVWires; ++$i)
1455  {
1456  $CornerVWireLength[$i] = ($FirstVWireOffset + $i*$UVReadoutBoardPitch)/$SinVAngle;
1457 
1458  print TPC <<EOF;
1459 
1460  <tube name="${_[3]}WireV$i"
1461  rmax="0.5*$TPCWireThickness"
1462  z="$CornerVWireLength[$i]"
1463  deltaphi="360"
1464  aunit="deg"
1465  lunit="cm"/>
1466 
1467 EOF
1468 
1469  }
1470 
1471  # The wire used many times in the middle of the V plane
1472  # Same subtraction as U common
1473 
1474  $CommonVWireLength = $Vactive_z/$SinVAngle;
1475 
1476  print TPC <<EOF;
1477  <tube name="${_[3]}WireVCommon"
1478  rmax="0.5*$TPCWireThickness"
1479  z="$CommonVWireLength"
1480  deltaphi="360"
1481  aunit="deg"
1482  lunit="cm"/>
1483 EOF
1484 
1485  for ($i = 0; $i < $NumberCornerVWires; $i++)
1486  {
1487 
1488  $TopCornerVWireLength[$i] = ($FirstTopVWire_yspan - $i*$VWire_yint)/$CosVAngle;
1489 
1490  $j = $i + $NumberSideVWires;
1491 
1492  print TPC <<EOF;
1493  <tube name="${_[3]}WireV$j"
1494  rmax="0.5*$TPCWireThickness"
1495  z="$TopCornerVWireLength[$i]"
1496  deltaphi="360"
1497  aunit="deg"
1498  lunit="cm"/>
1499 EOF
1500 
1501  }
1502 
1503 
1504 }
1505 
1506 # make the solids only once per APA
1507 # (here only from the lang drift TPC)
1508 if($_[0]>100){ solid_TPCG10( $_[4], $_[0], $_[1], $_[2]); }
1509 
1510 # Begin structure and create the vertical wire logical volume
1511 print TPC <<EOF;
1512 </solids>
1513 <structure>
1514  <volume name="volTPCActive${_[3]}">
1515  <materialref ref="LAr"/>
1516  <solidref ref="${_[3]}Active"/>
1517  </volume>
1518 
1519 EOF
1520 
1521 
1522 if ($wires_on==1)
1523 {
1524  print TPC <<EOF;
1525  <volume name="volTPCWireVert${_[3]}">
1526  <materialref ref="Copper_Beryllium_alloy25"/>
1527  <solidref ref="${_[3]}WireVert"/>
1528  </volume>
1529 EOF
1530 
1531  # Corner U wires logical volumes
1532  for ($i = 0; $i < $NumberCornerUWires; ++$i)
1533  {
1534  print TPC <<EOF;
1535  <volume name="volTPCWireU$i${_[3]}">
1536  <materialref ref="Copper_Beryllium_alloy25"/>
1537  <solidref ref="${_[3]}WireU$i"/>
1538  </volume>
1539 EOF
1540  }
1541 
1542 
1543  # Top Corner U wires logical volumes
1544  for ($j = $NumberSideUWires; $j < $NumberSideUWires + $NumberCornerUWires; ++$j)
1545  {
1546  print TPC <<EOF;
1547  <volume name="volTPCWireU$j${_[3]}">
1548  <materialref ref="Copper_Beryllium_alloy25"/>
1549  <solidref ref="${_[3]}WireU$j"/>
1550  </volume>
1551 EOF
1552  }
1553 
1554 
1555  # Common U wire logical volume, referenced many times
1556  print TPC <<EOF;
1557  <volume name="volTPCWireUCommon${_[3]}">
1558  <materialref ref="Copper_Beryllium_alloy25"/>
1559  <solidref ref="${_[3]}WireUCommon"/>
1560  </volume>
1561 EOF
1562 
1563  # Corner V wires logical volumes
1564  for ($i = 0; $i < $NumberCornerVWires; ++$i)
1565  {
1566  print TPC <<EOF;
1567  <volume name="volTPCWireV$i${_[3]}">
1568  <materialref ref="Copper_Beryllium_alloy25"/>
1569  <solidref ref="${_[3]}WireV$i"/>
1570  </volume>
1571 EOF
1572 
1573  }
1574 
1575  # Top Corner V wires logical volumes
1576  for ($j = $NumberSideVWires; $j < $NumberSideVWires + $NumberCornerVWires; ++$j)
1577  {
1578  print TPC <<EOF;
1579  <volume name="volTPCWireV$j${_[3]}">
1580  <materialref ref="Copper_Beryllium_alloy25"/>
1581  <solidref ref="${_[3]}WireV$j"/>
1582  </volume>
1583 EOF
1584  }
1585 
1586  # Common V wire logical volume, referenced many times
1587  print TPC <<EOF;
1588  <volume name="volTPCWireVCommon${_[3]}">
1589  <materialref ref="Copper_Beryllium_alloy25"/>
1590  <solidref ref="${_[3]}WireVCommon"/>
1591  </volume>
1592 EOF
1593 
1594 }
1595 
1596 # generate the G10 board solids and logical volumes
1597 # make the volumes only once per APA
1598 # (here only from the lang drift TPC)
1599 if($_[0]>100){ vol_TPCG10( $_[4] ); }
1600 
1601 my $lastYpos = 0;
1602 my $lastZpos = 0;
1603 
1604 
1605 #+++++++++++++++++++++++++ Position physical wires ++++++++++++++++++++++++++
1606 
1607 # ++++++++++++++++++++++ U Plane +++++++++++++++++++++++
1608 
1609 # Create U plane logical volume
1610 print TPC <<EOF;
1611  <volume name="volTPCPlaneU${_[3]}">
1612  <materialref ref="LAr"/>
1613  <solidref ref="${_[3]}UPlane"/>
1614 EOF
1615 
1616 
1617 print $wout "\n- Wires for U plane -\n\n";
1618 print $wout " Uplane_y: $Uactive_y[$apa]\n";
1619 print $wout " Uplane_z: $Uactive_z\n";
1620 
1621 
1622 if ($wires_on==1)
1623 {
1624 
1625 # Starting with the bottom left corner wires:
1626  # x=0 to center the wires in the plane
1627  # y positioning: (-0.5*$TPCWirePlaneHeight) starts the incremental increase
1628  # from the bottom of the plane, and trigonometry gives the increment
1629  # z positioning: Looking at the plane from the positive x direction,
1630  # (0.5*$TPCWirePlaneLength) starts the incremental increase from
1631  # the lower left corner.
1632  # rotation: same as common wire in code below
1633 
1634  $FirstU_ypos = - $Uactive_y[$apa]/2 + $FirstUWireOffset/$TanUAngle/2;
1635  $FirstU_zpos = + $Uactive_z/2 - $FirstUWireOffset/2;
1636 
1637 for ($i = 0; $i < $NumberCornerUWires; ++$i)
1638 {
1639 
1640 my $ypos = $FirstU_ypos + ($i)*0.5*$UWire_yint;
1641 my $zpos = $FirstU_zpos - ($i)*0.5*$UVReadoutBoardPitch;
1642 
1643 # cant actually define like this:
1644  # my $ypos = (-0.5*$Uactive_y[$apa]) + $CornerUWireLength[$i]*$CosUAngle/2;
1645  # my $zpos = (+0.5*$Uactive_z) - $CornerUWireLength[$i]*$SinUAngle/2;
1646 # since the wire lengths need to be slightly reduced to avoid the
1647 # wire corner's overlap with the plane boundary
1648 
1649 print TPC <<EOF;
1650  <physvol>
1651  <volumeref ref="volTPCWireU$i${_[3]}"/>
1652  <position name="pos${_[3]}WireU$i" unit="cm" x="0" y="$ypos " z="$zpos"/>
1653  <rotation name="rUAngle$i" unit="deg" x="90-$UAngle" y="0" z="0"/>
1654  </physvol>
1655 EOF
1656 
1657 $topY = $ypos + ($CosUAngle*$CornerUWireLength[$i]/2);
1658 $bottomY = $ypos - ($CosUAngle*$CornerUWireLength[$i]/2);
1659 $edgeZ_p = $zpos + ($SinUAngle*$CornerUWireLength[$i]/2);
1660 $edgeZ_m = $zpos - ($SinUAngle*$CornerUWireLength[$i]/2);
1661 print $wout "U$i: ( $ypos , $zpos ) \n";
1662 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1663 
1664 $lastYpos = $ypos;
1665 $lastZpos = $zpos;
1666 
1667 }
1668 
1669 
1670 # Moving upwards to the common wires:
1671  # x and z are zero to center the wires along a vertical axis
1672  # y positioning: The trick is positioning the lowest common wire so that the pitch
1673  # is consistent, then the increment is double the increment of
1674  # the corner wires since there is no z incriment.
1675  # rotation: wires in \\\\ direction, so +90deg to bring them to vertical and
1676  # +UAngle counterclockwise to arrive at proper orientation
1677 # Note that the counter maintains wire number (in pos. name) counting bottom to top
1678 
1679 
1680 my $StartCommonUWires_ypos = $lastYpos + $UWire_yint - abs( $lastZpos )/$TanUAngle;
1681 #print "$StartCommonUWires_ypos = $lastYpos + $UWire_yint - abs( $lastZpos )/$TanUAngle\n";
1682 
1683 
1684 for ($i = $NumberCornerUWires; $i < $NumberSideUWires; ++$i)
1685 {
1686 
1687  $j = $i - $NumberCornerUWires;
1688 
1689 #my $ypos = (-0.5*$Uactive_y[$apa])
1690 # + 0.5*($NumberCornerUWires)*$UWire_yint+($i+1-$NumberCornerUWires)*$UWire_yint;
1691  my $ypos = $StartCommonUWires_ypos + $UWire_yint*($j);
1692 
1693 print TPC <<EOF;
1694  <physvol>
1695  <volumeref ref="volTPCWireUCommon${_[3]}"/>
1696  <position name="pos${_[3]}WireU$i" unit="cm" x="0" y="$ypos " z="0"/>
1697  <rotation name="rUAngle$i" unit="deg" x="90-$UAngle" y="0" z="0"/>
1698  </physvol>
1699 EOF
1700 
1701 $topY = $ypos + ($CosUAngle*$CommonUWireLength/2);
1702 $bottomY = $ypos - ($CosUAngle*$CommonUWireLength/2);
1703 $edgeZ_p = + ($SinUAngle*$CommonUWireLength/2);
1704 $edgeZ_m = - ($SinUAngle*$CommonUWireLength/2);
1705 print $wout "U$i: ( $ypos , 0 ) \n";
1706 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1707 
1708 $lastYpos = $ypos;
1709 #$lastZpos = $zpos; always 0
1710 
1711 }
1712 
1713 
1714 
1715 my $FirstTopUWire_zspan = $FirstTopUWire_yspan*$TanUAngle;
1716 my $StartTopUWires_ypos = + $Uactive_y[$apa]/2 - $FirstTopUWire_yspan/2;
1717 my $StartTopUWires_zpos = - $Uactive_z/2 + $FirstTopUWire_zspan/2;
1718 
1719 # Finally moving to the corner wires on the top right:
1720  # x=0 to center the wires in the plane
1721  # y positioning: plug wire number into same equation
1722  # z positioning: start at z=0 and go negatively at the same z increment
1723  # rotation: same as common wire in code above
1724 # note that the counter maintains wire number shown in the position name
1725 
1726 for ($j = $NumberSideUWires; $j < $NumberSideUWires+$NumberCornerUWires; ++$j)
1727 {
1728 
1729 $i = $j - $NumberSideUWires;
1730 
1731 my $ypos = $StartTopUWires_ypos + ($i)*0.5*$UWire_yint;
1732 my $zpos = $StartTopUWires_zpos - ($i)*0.5*$UVReadoutBoardPitch;
1733 
1734 
1735 print TPC <<EOF;
1736  <physvol>
1737  <volumeref ref="volTPCWireU$j${_[3]}"/>
1738  <position name="pos${_[3]}WireU$j" unit="cm" x="0" y="$ypos " z="$zpos"/>
1739  <rotation name="rUAngle$j" unit="deg" x="90-$UAngle" y="0" z="0"/>
1740  </physvol>
1741 EOF
1742 
1743 $topY = $ypos + ($CosUAngle*$TopCornerUWireLength[$i]/2);
1744 $bottomY = $ypos - ($CosUAngle*$TopCornerUWireLength[$i]/2);
1745 $edgeZ_p = $zpos + ($SinUAngle*$TopCornerUWireLength[$i]/2);
1746 $edgeZ_m = $zpos - ($SinUAngle*$TopCornerUWireLength[$i]/2);
1747 print $wout "U$i: ( $ypos , $zpos ) \n";
1748 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1749 
1750 }
1751 
1752 } #ends if wires on
1753 
1754 
1755 # ++++++++++++++++++++++ V Plane +++++++++++++++++++++++
1756 
1757 # End U plane and create V plane logical volume
1758 print TPC <<EOF;
1759  </volume>
1760 
1761  <volume name="volTPCPlaneV${_[3]}">
1762  <materialref ref="LAr"/>
1763  <solidref ref="${_[3]}VPlane"/>
1764 EOF
1765 
1766 print $wout "\n- Wires for V plane -\n\n";
1767 print $wout " Vplane_y: $Vactive_y[$apa]\n";
1768 print $wout " Vplane_z: $Vactive_z\n";
1769 
1770 if ($wires_on==1)
1771 {
1772 
1773 
1774 # Starting with the bottom right corner wires:
1775  # x=0 to center the wires in the plane
1776  # y positioning: (-0.5*$TPCWirePlaneHeight) starts the incremental increase
1777  # from the bottom of the plane, and trigonometry gives the increment
1778  # z positioning: Looking at the plane from the positive x direction,
1779  # (-0.5*$TPCWirePlaneLength) starts the incremental increase from
1780  # the lower right corner.
1781  # rotation: same as common wire in code below
1782 
1783  $FirstV_ypos = - $Vactive_y[$apa]/2 + $FirstVWireOffset/$TanVAngle/2;
1784  $FirstV_zpos = - $Vactive_z/2 + $FirstVWireOffset/2;
1785 
1786 for ($i = 0; $i < $NumberCornerVWires; ++$i)
1787 {
1788 
1789 my $ypos = $FirstV_ypos + ($i)*0.5*$VWire_yint;
1790 my $zpos = $FirstV_zpos + ($i)*0.5*$UVReadoutBoardPitch;
1791 
1792 print TPC <<EOF;
1793  <physvol>
1794  <volumeref ref="volTPCWireV$i${_[3]}"/>
1795  <position name="pos${_[3]}WireV$i" unit="cm" x="0" y="$ypos " z="$zpos"/>
1796  <rotation name="rVAngle$i" unit="deg" x="90+$VAngle" y="0" z="0"/>
1797  </physvol>
1798 EOF
1799 
1800 $topY = $ypos + ($CosVAngle*$CornerVWireLength[$i]/2);
1801 $bottomY = $ypos - ($CosVAngle*$CornerVWireLength[$i]/2);
1802 $edgeZ_p = $zpos + ($SinVAngle*$CornerVWireLength[$i]/2);
1803 $edgeZ_m = $zpos - ($SinVAngle*$CornerVWireLength[$i]/2);
1804 print $wout "V$i: ( $ypos , $zpos ) \n";
1805 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1806 
1807 $lastYpos = $ypos;
1808 $lastZpos = $zpos;
1809 
1810 }
1811 
1812 
1813 # Moving upwards to the common wires:
1814  # x and z are zero to center the wires along a vertical axis
1815  # y positioning: Plug wire number into the same corner ypos equation
1816  # rotation: wires in //// direction, so +90deg to bring them to vertical and
1817  # --VAngle counterclockwise to arrive at proper orientation
1818 # Note that the counter maintains wire number in the position name
1819 
1820 my $StartCommonVWires_ypos = $lastYpos + $VWire_yint - abs( $lastZpos )/$TanVAngle;
1821 
1822 for ($i = $NumberCornerVWires; $i < $NumberSideVWires; ++$i)
1823 {
1824 
1825  $j = $i - $NumberCornerVWires;
1826  my $ypos = $StartCommonVWires_ypos + $VWire_yint*($j);
1827 
1828 print TPC <<EOF;
1829  <physvol>
1830  <volumeref ref="volTPCWireVCommon${_[3]}"/>
1831  <position name="pos${_[3]}WireV$i" unit="cm" x="0" y="$ypos " z="0"/>
1832  <rotation name="rVAngle$i" unit="deg" x="90+$VAngle" y="0" z="0"/>
1833  </physvol>
1834 EOF
1835 
1836 $topY = $ypos + ($CosVAngle*$CommonVWireLength/2);
1837 $bottomY = $ypos - ($CosVAngle*$CommonVWireLength/2);
1838 $edgeZ_p = + ($SinVAngle*$CommonVWireLength/2);
1839 $edgeZ_m = - ($SinVAngle*$CommonVWireLength/2);
1840 print $wout "V$i: ( $ypos , 0 ) \n";
1841 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1842 
1843 $lastYpos = $ypos;
1844 #$lastZpos = $zpos; always 0
1845 
1846 }
1847 
1848 
1849 my $FirstTopVWire_zspan = $FirstTopVWire_yspan*$TanVAngle;
1850 my $StartTopVWires_ypos = + $Vactive_y[$apa]/2 - $FirstTopVWire_yspan/2;
1851 my $StartTopVWires_zpos = + $Vactive_z/2 - $FirstTopVWire_zspan/2;
1852 
1853 # Finally moving to the corner wires on the top right:
1854  # x=0 to center the wires in the plane
1855  # y positioning: plug wire number into same equation
1856  # z positioning: start at z=0 and go positively at the same z increment
1857  # rotation: same as common wire in code above
1858 # note that the counter maintains wire number shown in the position name
1859 
1860 for ($j = $NumberSideVWires; $j < $NumberSideVWires+$NumberCornerVWires; ++$j)
1861 {
1862 
1863 $i = $j - $NumberSideVWires;
1864 
1865 my $ypos = $StartTopVWires_ypos + ($i)*0.5*$VWire_yint;
1866 my $zpos = $StartTopVWires_zpos + ($i)*0.5*$UVReadoutBoardPitch;
1867 
1868 print TPC <<EOF;
1869  <physvol>
1870  <volumeref ref="volTPCWireV$j${_[3]}"/>
1871  <position name="pos${_[3]}WireV$j" unit="cm" x="0" y="$ypos " z="$zpos"/>
1872  <rotation name="rVAngle$j" unit="deg" x="90+$VAngle" y="0" z="0"/>
1873  </physvol>
1874 EOF
1875 
1876 $topY = $ypos + ($CosVAngle*$TopCornerVWireLength[$i]/2);
1877 $bottomY = $ypos - ($CosVAngle*$TopCornerVWireLength[$i]/2);
1878 $edgeZ_p = $zpos + ($SinVAngle*$TopCornerVWireLength[$i]/2);
1879 $edgeZ_m = $zpos - ($SinVAngle*$TopCornerVWireLength[$i]/2);
1880 print $wout "V$i: ( $ypos , $zpos ) \n";
1881 print $wout " -- Y: $bottomY to $topY -- Z: $edgeZ_m to $edgeZ_p \n";
1882 
1883 }
1884 
1885 
1886 
1887 
1888 
1889 
1890 } #ends if wires on
1891 
1892 
1893 
1894 # ++++++++++++++++++++++ Z Plane +++++++++++++++++++++++
1895 
1896 # End V plane and create Z plane logical volume
1897 print TPC <<EOF;
1898  </volume>
1899 
1900  <volume name="volTPCPlaneZ${_[3]}">
1901  <materialref ref="LAr"/>
1902  <solidref ref="${_[3]}ZPlane"/>
1903 EOF
1904 
1905 if ($wires_on==1)
1906 {
1907 
1908 # This is the simplest plane, one loop creates all of the wires
1909  # x and y position at zero to center the wires
1910  # z position: moving from front of detector to back, in the positive z direction,
1911  # starting at (-0.5*$TPCWirePlaneLength), the right side looking from
1912  # the +x direction
1913 
1914 for ($i=0; $i<$NumberVerticalWires; ++$i)
1915 {
1916 my $zpos = (-0.5*$Zactive_z) + $i*$XWirePitch + $TPCWireThickness/2;
1917 
1918 print TPC <<EOF;
1919  <physvol>/
1920  <volumeref ref="volTPCWireVert${_[3]}"/>
1921  <position name="pos${_[3]}WireZ$i" unit="cm" x="0" y="0 " z="$zpos"/>
1922  <rotationref ref="rPlus90AboutX"/>
1923  </physvol>
1924 EOF
1925 
1926 }
1927 
1928 } #ends if wires on
1929 
1930 print TPC <<EOF;
1931  </volume>
1932 EOF
1933 
1934 #+++++++++++++++++++++ ^^ Position physical wires Above ^^ +++++++++++++++++++++
1935 
1936 ## make the TPC active volume extend down to the G10 for the grid
1937 
1938  my $BottomOfAPA = - $TPC_y[$apa]/2 + $APAGap_y/2;
1939 
1940 
1941 if ($apa==0){
1942  $BottomOfAPA = -$TPCActive_y[0]/2 + $BottomTallAPAToCage;
1943  $zz = -1;
1944 } elsif($apa==1){
1945  $BottomOfAPA = -$TPCActive_y[1]/2 + $APAGap_y/2;
1946  $zz = 0;
1947 } elsif($apa==2){
1948  $BottomOfAPA = -$TPCActive_y[2]/2 + $APAGap_y/2;
1949  $zz = 0;
1950 } elsif($apa==3){
1951  $BottomOfAPA = -$TPCActive_y[3]/2 + $BottomTallAPAToCage;
1952  $zz = 1;
1953 }
1954 
1955 if ($TPCActive_x<100){ $xx = -1; }
1956 else { $xx = 1; }
1957 
1958  $posZplane[0] = $xx*(-$_[0]/2 + $APAWirePlaneSpacing - $TPCWirePlaneThickness/2);
1959  $posZplane[1] = $BottomOfAPA + $WrapCover + 4*$G10thickness + $Zactive_y[$apa]/2;
1960  $posZplane[2] = $zz*(-$_[2]/2 + $APAGap_z/2 + $APAphys_z/2);
1961 
1962  $posVplane[0] = $posZplane[0] + $xx*$APAWirePlaneSpacing;
1963  $posVplane[1] = $BottomOfAPA + $WrapCover + 3*$G10thickness + $Vactive_y[$apa]/2;
1964  $posVplane[2] = $posZplane[2];
1965 
1966  $posUplane[0] = $posVplane[0] + $xx*$APAWirePlaneSpacing;
1967  $posUplane[1] = $BottomOfAPA + $WrapCover + 2*$G10thickness + $Uactive_y[$apa]/2;
1968  $posUplane[2] = $posZplane[2];
1969 
1970  $posTPCActive[0] = $posUplane[0] + $xx*($TPCWirePlaneThickness/2 + $TPCActive_x/2);
1971  $posTPCActive[1] = 0;
1972  $posTPCActive[2] = 0;
1973 
1974 if ($TPCActive_x<100){ $planeRot = "rIdentity"; }
1975 else { $planeRot = "rPlus180AboutY"; }
1976 
1977 
1978 #wrap up the TPC file
1979 print TPC <<EOF;
1980  <volume name="volTPC${_[3]}">
1981  <materialref ref="LAr"/>
1982  <solidref ref="${_[3]}"/>
1983  <physvol>
1984  <volumeref ref="volTPCPlaneZ${_[3]}"/>
1985  <position name="pos${_[3]}PlaneZ" unit="cm"
1986  x="$posZplane[0]" y="$posZplane[1]" z="$posZplane[2]"/>
1987  <rotationref ref="rIdentity"/>
1988  </physvol>
1989  <physvol>
1990  <volumeref ref="volTPCPlaneV${_[3]}"/>
1991  <position name="pos${_[3]}PlaneV" unit="cm"
1992  x="$posVplane[0]" y="$posVplane[1]" z="$posVplane[2]"/>
1993  <rotationref ref="$planeRot"/>
1994  </physvol>
1995  <physvol>
1996  <volumeref ref="volTPCPlaneU${_[3]}"/>
1997  <position name="pos${_[3]}PlaneU" unit="cm"
1998  x="$posUplane[0]" y="$posUplane[1]" z="$posUplane[2]"/>
1999  <rotationref ref="$planeRot"/>
2000  </physvol>
2001  <physvol>
2002  <volumeref ref="volTPCActive${_[3]}"/>
2003  <position name="pos${_[3]}Active" unit="cm"
2004  x="$posTPCActive[0]" y="$posTPCActive[1]" z="$posTPCActive[2]"/>
2005  </physvol>
2006 EOF
2007 
2008 # place the G10 board extensions to the portions placed directly in volCryostat
2009 #place_TPCG10( $_[4], $_[0], $_[1], $_[2] );
2010 
2011 print TPC <<EOF;
2012  </volume>
2013 </structure>
2014 </gdml>
2015 EOF
2016 
2017  close(GDML);
2018 
2019 } #end of sub gen_TPC
2020 
2021 
2022 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2023 #++++++++++++++++++++++++++++++++++++++ solid_TPCG10 +++++++++++++++++++++++++++++++++++++
2024 #++++++++++++++++++++++++++++++++++++++++ vol_TPCG10 +++++++++++++++++++++++++++++++++++++
2025 #++++++++++++++++++++++++++++++++++++++ place_TPCG10 +++++++++++++++++++++++++++++++++++++
2026 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2027 
2028 
2029 # Must be called only within gen_TPC(),
2030 
2031 
2032 # $_[0] = APA number
2033 # convention: 0 is Largest, 1 is Mid, 2 is Smallest
2034 
2035 sub solid_TPCG10()
2036 {
2037 
2038  $apa = $_[0];
2039 
2040 
2041 $G10BoardYSide_V_x = 2*$APAWirePlaneSpacing; # The rest of the x-direction extension
2042  # out to the V plane wires
2043 $G10BoardYSide_V_y = $APAFrame_y[$apa]; # Y and Z are the same as the center
2044 $G10BoardYSide_V_z = $G10thickness; # parts placed in volCryostat
2045 
2046 
2047 $G10BoardYSide_U_x = 3*$APAWirePlaneSpacing; # The rest of the x-direction extension
2048  # out to the U plane wires
2049 $G10BoardYSide_U_y = $APAFrame_y[$apa]; # Y and Z are the same as the center
2050 $G10BoardYSide_U_z = $G10thickness; # parts placed in volCryostat
2051 
2052 
2053 $G10BoardZSide_V_x = 2*$APAWirePlaneSpacing;
2054 $G10BoardZSide_V_y = $G10thickness;
2055 $G10BoardZSide_V_z = $APAFrame_z;
2056 $G10BoardZSide_U_x = 3*$APAWirePlaneSpacing;
2057 $G10BoardZSide_U_y = $G10thickness;
2058 $G10BoardZSide_U_z = $APAFrame_z;
2059 $G10BoardZSide_Grid_x = 4*$APAWirePlaneSpacing;
2060 $G10BoardZSide_Grid_y = $G10thickness;
2061 $G10BoardZSide_Grid_z = $APAFrame_z;
2062 
2063  print TPC <<EOF;
2064 
2065  <box name="G10BoardYSideVSeg\-$apa" lunit="cm"
2066  x="$G10BoardYSide_V_x"
2067  y="$G10BoardYSide_V_y"
2068  z="$G10BoardYSide_V_z"/>
2069 
2070  <box name="G10BoardYSideUSeg\-$apa" lunit="cm"
2071  x="$G10BoardYSide_U_x"
2072  y="$G10BoardYSide_U_y"
2073  z="$G10BoardYSide_U_z"/>
2074 
2075  <box name="G10BoardZSideVSeg\-$apa" lunit="cm"
2076  x="$G10BoardZSide_V_x"
2077  y="$G10BoardZSide_V_y"
2078  z="$G10BoardZSide_V_z"/>
2079 
2080  <box name="G10BoardZSideUSeg\-$apa" lunit="cm"
2081  x="$G10BoardZSide_U_x"
2082  y="$G10BoardZSide_U_y"
2083  z="$G10BoardZSide_U_z"/>
2084 
2085  <box name="G10BoardZSideGridSeg\-$apa" lunit="cm"
2086  x="$G10BoardZSide_Grid_x"
2087  y="$G10BoardZSide_Grid_y"
2088  z="$G10BoardZSide_Grid_z"/>
2089 
2090 EOF
2091 
2092 }
2093 
2094 
2095 sub vol_TPCG10()
2096 {
2097 
2098  $apa = $_[0];
2099 
2100  print TPC <<EOF;
2101 
2102  <volume name="volG10BoardYSideVSeg\-$apa">
2103  <materialref ref="G10"/>
2104  <solidref ref="G10BoardYSideVSeg\-$apa"/>
2105  </volume>
2106  <volume name="volG10BoardYSideUSeg\-$apa">
2107  <materialref ref="G10"/>
2108  <solidref ref="G10BoardYSideUSeg\-$apa"/>
2109  </volume>
2110 
2111  <volume name="volG10BoardZSideVSeg\-$apa">
2112  <materialref ref="G10"/>
2113  <solidref ref="G10BoardZSideVSeg\-$apa"/>
2114  </volume>
2115  <volume name="volG10BoardZSideUSeg\-$apa">
2116  <materialref ref="G10"/>
2117  <solidref ref="G10BoardZSideUSeg\-$apa"/>
2118  </volume>
2119  <volume name="volG10BoardZSideGridSeg\-$apa">
2120  <materialref ref="G10"/>
2121  <solidref ref="G10BoardZSideGridSeg\-$apa"/>
2122  </volume>
2123 
2124 EOF
2125 
2126 }
2127 
2128 
2129 sub place_TPCG10()
2130 {
2131 
2132  $apa = $_[0];
2133 
2134  $ThisTPC_x = $_[1];
2135  $ThisTPC_y = $_[2];
2136  $ThisTPC_z = $_[3];
2137 
2138 
2139 $G10BoardYSide_V_x = 1*$APAWirePlaneSpacing; # The rest of the x-direction extension
2140  # out to the V plane wires
2141 $G10BoardYSide_V_y = $APAFrame_y[$APA_i]; # Y and Z are the same as the center
2142 $G10BoardYSide_V_z = $G10thickness; # parts placed in volCryostat
2143 
2144 
2145 $G10BoardYSide_U_x = 2*$APAWirePlaneSpacing; # The rest of the x-direction extension
2146  # out to the U plane wires
2147 $G10BoardYSide_U_y = $APAFrame_y[$APA_i]; # Y and Z are the same as the center
2148 $G10BoardYSide_U_z = $G10thickness; # parts placed in volCryostat
2149 
2150 
2151 $G10BoardZSide_V_x = 1*$APAWirePlaneSpacing;
2152 $G10BoardZSide_V_y = $G10thickness;
2153 $G10BoardZSide_V_z = $APAFrame_z;
2154 $G10BoardZSide_U_x = 2*$APAWirePlaneSpacing;
2155 $G10BoardZSide_U_y = $G10thickness;
2156 $G10BoardZSide_U_z = $APAFrame_z;
2157 $G10BoardZSide_Grid_x = 3*$APAWirePlaneSpacing;
2158 $G10BoardZSide_Grid_y = $G10thickness;
2159 $G10BoardZSide_Grid_z = $APAFrame_z;
2160 
2161 
2162 $posG10ZSideZ_y = $APAFrameCenter_y - $APAFrame_y[$APA_i]/2 - (0+.5)*($G10BoardZSide_y);
2163 $posG10ZSideV_y = $APAFrameCenter_y - $APAFrame_y[$APA_i]/2 - (1+.5)*($G10BoardZSide_y);
2164 $posG10ZSideU_y = $APAFrameCenter_y - $APAFrame_y[$APA_i]/2 - (2+.5)*($G10BoardZSide_y);
2165 $posG10ZSideGrid_y = $APAFrameCenter_y - $APAFrame_y[$APA_i]/2 - (3+.5)*($G10BoardZSide_y);
2166 
2167 # ... but the smallest APA is upside-down, so put the G10 boards at the top in that case
2168  if($apa == 2)
2169  {
2170  $posG10ZSideZ_y = $APAFrameCenter_y + $APAFrame_y[$APA_i]/2 + (0+.5)*($G10BoardZSide_y);
2171  $posG10ZSideV_y = $APAFrameCenter_y + $APAFrame_y[$APA_i]/2 + (1+.5)*($G10BoardZSide_y);
2172  $posG10ZSideU_y = $APAFrameCenter_y + $APAFrame_y[$APA_i]/2 + (2+.5)*($G10BoardZSide_y);
2173  $posG10ZSideGrid_y = $APAFrameCenter_y + $APAFrame_y[$APA_i]/2 + (3+.5)*($G10BoardZSide_y);
2174  }
2175 
2176 
2177  print TPC <<EOF;
2178 
2179  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2180  - Add the *parts* of the G10 boards that extend those directly in volCryostat.
2181  - There are two side boards on each the up and downstream end,
2182  one each to wrap the U and V views around the APA frame
2183  - There are 4 on the bottom which anchor the U V and Z wires and the grid plane
2184  - The center parts of the G10 boards must be placed directly in volCryostat
2185 
2186  APA $apa
2187 
2188  -->
2189 
2190  <physvol>
2191  <volumeref ref="volG10BoardYSideVSeg\-$apa"/>
2192  <position name="posG10BoardYSideVSeg\-up\-$apa" unit="cm"
2193  x=" - $ThisTPC_x/2 + $G10BoardYSide_V_x/2"
2194  y=" - $APAphys_y[$apa]/2 + $WrapCover + 4*$G10thickness + $APAFrame_y[$apa]/2 "
2195  z=" - $APAFrame_z/2 - (0+.5)*($G10BoardYSide_V_z)"/>
2196  <rotationref ref="rIdentity"/>
2197  </physvol>
2198  <physvol>
2199  <volumeref ref="volG10BoardYSideUSeg\-$apa"/>
2200  <position name="posG10BoardYSideUSeg\-up\-$apa" unit="cm"
2201  x=" - $ThisTPC_x/2 + $G10BoardYSide_U_x/2"
2202  y=" - $APAphys_y[$apa]/2 + $WrapCover + 4*$G10thickness + $APAFrame_y[$apa]/2"
2203  z=" - $APAFrame_z/2 - (1+.5)*($G10BoardYSide_U_z)"/>
2204  <rotationref ref="rIdentity"/>
2205  </physvol>
2206 
2207  <physvol>
2208  <volumeref ref="volG10BoardYSideVSeg\-$apa"/>
2209  <position name="posG10BoardYSideVSeg\-down\-$apa" unit="cm"
2210  x=" - $ThisTPC_x/2 + $G10BoardYSide_V_x/2"
2211  y=" - $APAphys_y[$apa]/2 + $WrapCover + 4*$G10thickness + $APAFrame_y[$apa]/2 "
2212  z=" + $APAFrame_z/2 + (0+.5)*($G10BoardYSide_V_z)"/>
2213  <rotationref ref="rIdentity"/>
2214  </physvol>
2215  <physvol>
2216  <volumeref ref="volG10BoardYSideUSeg\-$apa"/>
2217  <position name="posG10BoardYSideUSeg\-down\-$apa" unit="cm"
2218  x=" - $ThisTPC_x/2 + $G10BoardYSide_U_x/2"
2219  y=" - $APAphys_y[$apa]/2 + $WrapCover + 4*$G10thickness + $APAFrame_y[$apa]/2"
2220  z=" + $APAFrame_z/2 + (1+.5)*($G10BoardYSide_U_z)"/>
2221  <rotationref ref="rIdentity"/>
2222  </physvol>
2223 
2224 
2225 
2226  <physvol>
2227  <volumeref ref="volG10BoardZSideVSeg\-$apa"/>
2228  <position name="posG10BoardZSideVSeg\-$apa" unit="cm"
2229  x=" - $ThisTPC_x/2 + $G10BoardZSide_V_x/2"
2230  y=" - $APAphys_y[$apa]/2 + $WrapCover + 2.5*$G10thickness"
2231  z="0"/>
2232  <rotationref ref="rIdentity"/>
2233  </physvol>
2234  <physvol>
2235  <volumeref ref="volG10BoardZSideUSeg\-$apa"/>
2236  <position name="posG10BoardZSideUSeg\-$apa" unit="cm"
2237  x=" - $ThisTPC_x/2 + $G10BoardZSide_U_x/2"
2238  y=" - $APAphys_y[$apa]/2 + $WrapCover + 1.5*$G10thickness"
2239  z="0"/>
2240  <rotationref ref="rIdentity"/>
2241  </physvol>
2242  <physvol>
2243  <volumeref ref="volG10BoardZSideGridSeg\-$apa"/>
2244  <position name="posG10BoardZSideGridSeg\-$apa" unit="cm"
2245  x=" - $ThisTPC_x/2 + $G10BoardZSide_Grid_x/2"
2246  y=" - $APAphys_y[$apa]/2 + $WrapCover + 0.5*$G10thickness"
2247  z="0"/>
2248  <rotationref ref="rIdentity"/>
2249  </physvol>
2250 
2251 
2252 
2253 EOF
2254 
2255 }
2256 
2257 
2258 
2259 
2260 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2261 #++++++++++++++++++++++++++++++++++++++ gen_Cryostat +++++++++++++++++++++++++++++++++++++
2262 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2263 
2264 sub gen_Cryostat()
2265 {
2266 
2267 # Create the cryostat fragment file name,
2268 # add file to list of output GDML fragments,
2269 # and open it
2270  $CRYO = "35t_Cryostat" . $suffix . ".gdml";
2271  push (@gdmlFiles, $CRYO);
2272  $CRYO = ">" . $CRYO;
2273  open(CRYO) or die("Could not open file $CRYO for writing");
2274 
2275 
2276 # The standard XML prefix and starting the gdml
2277  print CRYO <<EOF;
2278 <?xml version='1.0'?>
2279 <gdml>
2280 EOF
2281 
2282 
2283 # All the cryostat solids.
2284 print CRYO <<EOF;
2285 <solids>
2286  <box name="Cryostat" lunit="cm"
2287  x="$Cryostat_x"
2288  y="$Cryostat_y"
2289  z="$Cryostat_z"/>
2290 
2291  <box name="GaseousArgon" lunit="cm"
2292  x="$Argon_x"
2293  y="$HeightGaseousAr"
2294  z="$Argon_z"/>
2295 
2296  <box name="LightPaddle" lunit="cm"
2297  x="$LightPaddle_x"
2298  y="$LightPaddle_y + $SiPM_y"
2299  z="$LightPaddle_z"/>
2300 
2301 <box name="Bar" lunit="cm"
2302  x="0.6"
2303  y="50.8"
2304  z="2.54"/>
2305 
2306  <union name="TwoBars">
2307  <first ref="Bar"/> <second ref="Bar"/>
2308  <position name="bs2" z="-2.794" unit="cm"/>
2309  </union>
2310 
2311  <union name="FourBars">
2312  <first ref="TwoBars"/> <second ref="TwoBars"/>
2313  <position name="bs4" z="-5.588" unit="cm"/>
2314  </union>
2315 
2316  <box name="Plank" lunit="cm"
2317  x="0.635"
2318  y="50.8"
2319  z="11.0"/>
2320 
2321  <box name="Fiber" lunit="cm"
2322  x="0.289"
2323  y="50.8"
2324  z="0.289"/>
2325 
2326  <box name="FiberBottom" lunit="cm"
2327  x="0.289"
2328  y="43.18"
2329  z="0.289"/>
2330 
2331  <box name="FiberTop" lunit="cm"
2332  x="0.289"
2333  y="2.2225"
2334  z="0.289"/>
2335 
2336  <para name="FiberRight" x="0.289" y="0.289" z="5.3975" alpha="0" theta="3.0649" phi="0" aunit="deg" lunit="cm"/>
2337 
2338  <para name="FiberLeft" x="0.289" y="0.289" z="5.3975" alpha="0" theta="-3.0649" phi="0" aunit="deg" lunit="cm"/>
2339 
2340  <union name="FF">
2341  <first ref="Fiber"/> <second ref="Fiber"/>
2342  <position name="ff" x="-0.289" z="-0.289" unit="cm"/>
2343  </union>
2344 
2345  <union name="FFB">
2346  <first ref="FF"/> <second ref="FiberBottom"/>
2347  <position name="ffb" x="-0.289" y="-3.81" z="0.289" unit="cm"/>
2348  </union>
2349 
2350  <union name="FFBB">
2351  <first ref="FFB"/> <second ref="FiberBottom"/>
2352  <position name="ffbb" y="-3.81" z="-0.578" unit="cm"/>
2353  </union>
2354 
2355  <union name="FFBBT">
2356  <first ref="FFBB"/> <second ref="FiberTop"/>
2357  <position name="ffbbt" x="-0.289" y="24.28875" unit="cm"/>
2358  </union>
2359 
2360  <union name="FFBBTT">
2361  <first ref="FFBBT"/> <second ref="FiberTop"/>
2362  <position name="ffbbtt" y="24.28875" z="-0.289" unit="cm"/>
2363  </union>
2364 
2365  <union name="FFBBTTL">
2366  <first ref="FFBBTT"/> <second ref="FiberLeft"/>
2367  <position name="ffbbttl" x="0" y="20.47875" z="-0.4335" unit="cm"/> <rotation name="FiberRotLeft" x="-90" y="90" unit="deg"/>
2368  </union>
2369 
2370  <union name="FourFibers">
2371  <first ref="FFBBTTL"/> <second ref="FiberRight"/>
2372  <position name="fs4" x="-0.289" y="20.47875" z="0.1445" unit="cm"/> <rotation name="FiberRotRight" x="-90" y="90" unit="deg"/>
2373  </union>
2374 
2375  <union name="EightFibers">
2376  <first ref="FourFibers"/> <second ref="FourFibers"/>
2377  <position name="fs8" z="-1.2" unit="cm"/>
2378  </union>
2379 
2380  <union name="SixteenFibers">
2381  <first ref="EightFibers"/> <second ref="EightFibers"/>
2382  <position name="fs16" z="-2.4" unit="cm"/>
2383  </union>
2384 
2385  <union name="ThirtyTwoFibers">
2386  <first ref="SixteenFibers"/> <second ref="SixteenFibers"/>
2387  <position name="fs32" z="-4.8" unit="cm"/>
2388  </union>
2389 
2390 EOF
2391 
2392 
2393  # Add APA frames with G10 boards on them
2394  solid_APA( 0 );
2395  solid_APA( 1 );
2396  solid_APA( 2 );
2397  solid_APA( 3 );
2398 
2399  solid_CPA(); # no need for multiple sets of solids, the only 2 CPAs are identical
2400 
2401 
2402 # Cryostat structure
2403 print CRYO <<EOF;
2404 </solids>
2405 <structure>
2406 
2407  <volume name="volGaseousArgon">
2408  <materialref ref="ArGas"/>
2409  <solidref ref="GaseousArgon"/>
2410  </volume>
2411 
2412  <volume name="volOpDetSensitive_Bar">
2413  <materialref ref="LAr"/>
2414  <solidref ref="FourBars"/>
2415  </volume>
2416 
2417  <volume name="volOpDetSensitive_Plank">
2418  <materialref ref="LAr"/>
2419  <solidref ref="Plank"/>
2420  </volume>
2421 
2422  <volume name="volOpDetSensitive_Fiber">
2423  <materialref ref="LAr"/>
2424  <solidref ref="ThirtyTwoFibers"/>
2425  </volume>
2426 
2427 EOF
2428 
2429  vol_APA( 0 );
2430  vol_APA( 1 );
2431  vol_APA( 2 );
2432  vol_APA( 3 );
2433 
2434  vol_CPA();
2435 
2436 print CRYO <<EOF;
2437 
2438  <volume name="volCryostat">
2439  <materialref ref="LAr"/>
2440  <solidref ref="Cryostat"/>
2441 
2442  <physvol>
2443  <volumeref ref="volGaseousArgon"/>
2444  <position name="posGaseousArgon" unit="cm" x="0" y="$Argon_y/2 - $HeightGaseousAr/2" z="0"/>
2445  </physvol>
2446 
2447  <physvol>
2448  <volumeref ref="volCathode"/>
2449  <positionref ref="posCathodeShortDrift"/>
2450  </physvol>
2451  <physvol>
2452  <volumeref ref="volCathode"/>
2453  <positionref ref="posCathodeLongDrift"/>
2454  </physvol>
2455 
2456 
2457 
2458 
2459  <!-- The Smallest APA -->
2460  <!-- Note this is the only APA with a readout
2461  at the bottom. TPCs are constructed with
2462  readouts at the top, so rotate the two APAs
2463  180 around X to flip upside down -->
2464 
2465  <physvol>
2466  <volumeref ref="volTPCSmallestLongDrift"/>
2467  <positionref ref="posTPCSmallestLongDrift"/>
2468  <rotationref ref="rPlus180AboutX"/>
2469  </physvol>
2470 
2471  <physvol>
2472  <volumeref ref="volTPCSmallestShortDrift"/>
2473  <positionref ref="posTPCSmallestShortDrift"/>
2474  <rotationref ref="rPlus180AboutX"/>
2475  </physvol>
2476 
2477 
2478 EOF
2479 
2480 place_APA($APACenter[2][0], $APACenter[2][1], $APACenter[2][2], 2);
2481 
2482 
2483 
2484 print CRYO <<EOF;
2485  <!-- The Middle-sized APA -->
2486 
2487  <physvol>
2488  <volumeref ref="volTPCMidLongDrift"/>
2489  <positionref ref="posTPCMidLongDrift"/>
2490  <rotationref ref="rIdentity"/>
2491  </physvol>
2492 
2493  <physvol>
2494  <volumeref ref="volTPCMidShortDrift"/>
2495  <positionref ref="posTPCMidShortDrift"/>
2496  <rotationref ref="rIdentity"/>
2497  </physvol>
2498 
2499 
2500 EOF
2501 
2502 place_APA($APACenter[1][0], $APACenter[1][1], $APACenter[1][2], 1);
2503 
2504 
2505 
2506 print CRYO <<EOF;
2507  <!-- The Largest APAs, Upstream and Downstream -->
2508 
2509  <physvol>
2510  <volumeref ref="volTPCLargestLongDriftUpstream"/>
2511  <positionref ref="posTPCLargestLongDrift_Neg"/>
2512  <rotationref ref="rIdentity"/>
2513  </physvol>
2514  <physvol>
2515  <volumeref ref="volTPCLargestShortDriftUpstream"/>
2516  <positionref ref="posTPCLargestShortDrift_Neg"/>
2517  <rotationref ref="rIdentity"/>
2518  </physvol>
2519 
2520  <physvol>
2521  <volumeref ref="volTPCLargestLongDriftDownstream"/>
2522  <positionref ref="posTPCLargestLongDrift_Pos"/>
2523  <rotationref ref="rIdentity"/>
2524  </physvol>
2525  <physvol>
2526  <volumeref ref="volTPCLargestShortDriftDownstream"/>
2527  <positionref ref="posTPCLargestShortDrift_Pos"/>
2528  <rotationref ref="rIdentity"/>
2529  </physvol>
2530 
2531 EOF
2532 
2533 place_APA($APACenter[0][0], $APACenter[0][1], $APACenter[0][2], 0);
2534 place_APA($APACenter[3][0], $APACenter[3][1], $APACenter[3][2], 3);
2535 
2536 place_CPA(0, $posCPAShortDrift_x, $posCPAShortDrift_y, $posCPAShortDrift_z);
2537 place_CPA(1, $posCPALongDrift_x, $posCPALongDrift_y, $posCPALongDrift_z);
2538 
2539 
2540 print CRYO <<EOF;
2541  </volume>
2542 </structure>
2543 </gdml>
2544 EOF
2545 
2546 close(CRYO);
2547 }
2548 
2549 
2550 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2551 #++++++++++++++++++++++++++++++++++++++ solid_APA ++++++++++++++++++++++++++++++++++++++++
2552 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2553 
2554 
2555 # Must be called only within gen_Cryostat(),
2556 
2557 
2558 # $_[0] = APA number
2559 # convention: 0 is Largest, 1 is Mid, 2 is Smallest
2560 
2561 sub solid_APA()
2562 {
2563 
2564  $APA_i = $_[0];
2565 
2566 ####################################################################
2567 ################# APA Frame and Paddle Dimensions ##################
2568 
2569  $APA_y = $APAFrame_y[$APA_i];
2570 
2571 $APAFrameZSide_x = $APAFrame_x;
2572 $APAFrameZSide_y = 4*$inch;
2573 $APAFrameZSide_z = $APAFrame_z;
2574 
2575 $APAFrameYSide_x = $APAFrame_x;
2576 $APAFrameYSide_y = $APA_y-2*$APAFrameZSide_y;
2577 $APAFrameYSide_z = 4*$inch;
2578 
2579 # Two outer Y supports will sandwich the light paddles
2580 $APAFrameYOuterSupport_x = ($APAFrame_x-$LightPaddle_x)/2;
2581 $APAFrameYOuterSupport_y = $APA_y-2*$APAFrameZSide_y;
2582 $APAFrameYOuterSupport_z = 4*$inch;
2583 
2584 $EdgeFrameSteelThickness = 0.12*$inch;
2585 $InnerFrameSteelThickness = 0.062*$inch;
2586 
2587 
2588 $G10BoardYSide_x = $APAFrame_x;
2589 $G10BoardYSide_y = $APAFrame_y[$APA_i];
2590 $G10BoardYSide_z = $G10thickness;
2591 
2592 $G10BoardZSide_x = $APAFrame_x;
2593 $G10BoardZSide_y = $G10thickness;
2594 $G10BoardZSide_z = $APAFrame_z;
2595 
2596 
2597  print CRYO <<EOF;
2598  <box name="APAFrameYSideHollow\-$APA_i" lunit="cm"
2599  x="$APAFrameYSide_x-2*$EdgeFrameSteelThickness"
2600  y="$APAFrameYSide_y-2*$EdgeFrameSteelThickness"
2601  z="$APAFrameYSide_z"/>
2602  <box name="APAFrameYSideShell\-$APA_i" lunit="cm"
2603  x="$APAFrameYSide_x"
2604  y="$APAFrameYSide_y"
2605  z="$APAFrameYSide_z"/>
2606  <subtraction name="APAFrameYSide\-$APA_i">
2607  <first ref="APAFrameYSideShell\-$APA_i"/>
2608  <second ref="APAFrameYSideHollow\-$APA_i"/>
2609  <positionref ref="posCenter"/>
2610  <rotationref ref="rIdentity"/>
2611  </subtraction>
2612 
2613  <box name="APAFrameZSideHollow\-$APA_i" lunit="cm"
2614  x="$APAFrameZSide_x-2*$EdgeFrameSteelThickness"
2615  y="$APAFrameZSide_y-2*$EdgeFrameSteelThickness"
2616  z="$APAFrameZSide_z"/>
2617  <box name="APAFrameZSideShell\-$APA_i" lunit="cm"
2618  x="$APAFrameZSide_x"
2619  y="$APAFrameZSide_y"
2620  z="$APAFrameZSide_z"/>
2621  <subtraction name="APAFrameZSide\-$APA_i">
2622  <first ref="APAFrameZSideShell\-$APA_i"/>
2623  <second ref="APAFrameZSideHollow\-$APA_i"/>
2624  <positionref ref="posCenter"/>
2625  <rotationref ref="rIdentity"/>
2626  </subtraction>
2627 
2628  <box name="APAFrameYOuterSupport\-$APA_i" lunit="cm"
2629  x="$EdgeFrameSteelThickness"
2630  y="$APAFrameYOuterSupport_y"
2631  z="$APAFrameYOuterSupport_z"/>
2632 
2633 
2634  <box name="G10BoardYSideCenterSeg\-$APA_i" lunit="cm"
2635  x="$G10BoardYSide_x"
2636  y="$G10BoardYSide_y"
2637  z="$G10BoardYSide_z"/>
2638 
2639  <box name="G10BoardZSideCenterSeg\-$APA_i" lunit="cm"
2640  x="$G10BoardZSide_x"
2641  y="$G10BoardZSide_y"
2642  z="$G10BoardZSide_z"/>
2643 
2644 EOF
2645 
2646 }
2647 
2648 
2649 
2650 
2651 
2652 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2653 #++++++++++++++++++++++++++++++++++++++ vol_APA ++++++++++++++++++++++++++++++++++++++++
2654 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2655 
2656 
2657 # Must be called only within gen_Cryostat(),
2658 
2659 
2660 # $_[0] = x APA center
2661 # $_[1] = y APA center
2662 # $_[2] = z APA center
2663 # $_[3] = APA number
2664 # convention: 0 and 3 are Largest, 1 is Mid, 2 is Smallest
2665 
2666 sub vol_APA()
2667 {
2668 
2669  $APA_i = $_[0];
2670 
2671 print CRYO <<EOF;
2672 
2673  <volume name="volAPAFrameYSide\-$APA_i">
2674  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2675  <solidref ref="APAFrameYSide\-$APA_i"/>
2676  </volume>
2677 
2678  <volume name="volAPAFrameZSide\-$APA_i">
2679  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2680  <solidref ref="APAFrameZSide\-$APA_i"/>
2681  </volume>
2682 
2683  <volume name="volAPAFrameYOuterSupport\-$APA_i">
2684  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
2685  <solidref ref="APAFrameYOuterSupport\-$APA_i"/>
2686  </volume>
2687 
2688  <volume name="volG10BoardYSideCenterSeg\-$APA_i">
2689  <materialref ref="G10"/>
2690  <solidref ref="G10BoardYSideCenterSeg\-$APA_i"/>
2691  </volume>
2692 
2693  <volume name="volG10BoardZSideCenterSeg\-$APA_i">
2694  <materialref ref="G10"/>
2695  <solidref ref="G10BoardZSideCenterSeg\-$APA_i"/>
2696  </volume>
2697 
2698 
2699 EOF
2700 
2701 }
2702 
2703 
2704 
2705 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2706 #++++++++++++++++++++++++++++++++++++++ place_APA ++++++++++++++++++++++++++++++++++++++++
2707 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2708 
2709 
2710 # Must be called only within gen_Cryostat(),
2711 
2712 
2713 # $_[0] = x APA physical center
2714 # $_[1] = y APA physical center
2715 # $_[2] = z APA physical center
2716 # $_[3] = APA number
2717 # convention: 0 and 3 are Largest, 1 is Mid, 2 is Smallest
2718 
2719 sub place_APA()
2720 {
2721 
2722  $APA_i = $_[3];
2723 
2724 ####################################################################
2725 ################# APA Frame and Paddle Dimensions ##################
2726 
2727  $APA_y = $APAFrame_y[$APA_i];
2728 
2729 
2730 # The center passed to this function is the physical APA center,
2731 # which is not quite the frame's center, since there are more boards
2732 # at the bottom. Transform them:
2733 
2734  $APAFrameCenter_x = $_[0];
2735  $APAFrameCenter_y = $_[1] - $APAphys_y[$APA_i]/2
2736  + $WrapCover + 4*$G10thickness
2737  + $APAFrame_y[$APA_i]/2;
2738  $APAFrameCenter_z = $_[2];
2739 
2740 # the smallest APA is different (upside down)
2741  if($APA_i == 2)
2742  {
2743  $APAFrameCenter_y = $_[1] + $APAphys_y[$APA_i]/2
2744  - $WrapCover - 4*$G10thickness
2745  - $APAFrame_y[$APA_i]/2;
2746  }
2747 
2748 
2749 $APAFrameZSide_x = $APAFrame_x;
2750 $APAFrameZSide_y = 4*$inch;
2751 $APAFrameZSide_z = $APAFrame_z;
2752 
2753 $APAFrameYSide_x = $APAFrame_x;
2754 $APAFrameYSide_y = $APA_y-2*$APAFrameZSide_y;
2755 $APAFrameYSide_z = 4*$inch;
2756 
2757 # Two outer Y supports will sandwich the light paddles
2758 $APAFrameYOuterSupport_x = ($APAFrame_x-$LightPaddle_x)/2;
2759 $APAFrameYOuterSupport_y = $APA_y-2*$APAFrameZSide_y;
2760 $APAFrameYOuterSupport_z = 4*$inch;
2761 
2762 # if there were an inner support to fill the hole
2763 $APAFrameYInnerSupport_x = $LightPaddle_x;
2764 
2765 $EdgeFrameSteelThickness = 0.12*$inch;
2766 $InnerFrameSteelThickness = 0.062*$inch;
2767 
2768 
2769 $G10BoardYSide_x = $APAFrame_x;
2770 $G10BoardYSide_y = $APAFrame_y[$APA_i];
2771 $G10BoardYSide_z = $G10thickness;
2772 
2773 $G10BoardZSide_x = $APAFrame_x;
2774 $G10BoardZSide_y = $G10thickness;
2775 $G10BoardZSide_z = $APAFrame_z;
2776 
2777 $posG10ZSideZ_y = $APAFrameCenter_y - $APAFrame_y[$APA_i]/2 - (0+.5)*($G10BoardZSide_y);
2778 $posG10ZSideV_y = $APAFrameCenter_y - $APAFrame_y[$APA_i]/2 - (1+.5)*($G10BoardZSide_y);
2779 $posG10ZSideU_y = $APAFrameCenter_y - $APAFrame_y[$APA_i]/2 - (2+.5)*($G10BoardZSide_y);
2780 $posG10ZSideGrid_y = $APAFrameCenter_y - $APAFrame_y[$APA_i]/2 - (3+.5)*($G10BoardZSide_y);
2781 
2782 # ... but the smallest APA is upside-down, so put the G10 boards at the top in that case
2783  if($APA_i == 2)
2784  {
2785  $posG10ZSideZ_y = $APAFrameCenter_y + $APAFrame_y[$APA_i]/2 + (0+.5)*($G10BoardZSide_y);
2786  $posG10ZSideV_y = $APAFrameCenter_y + $APAFrame_y[$APA_i]/2 + (1+.5)*($G10BoardZSide_y);
2787  $posG10ZSideU_y = $APAFrameCenter_y + $APAFrame_y[$APA_i]/2 + (2+.5)*($G10BoardZSide_y);
2788  $posG10ZSideGrid_y = $APAFrameCenter_y + $APAFrame_y[$APA_i]/2 + (3+.5)*($G10BoardZSide_y);
2789  }
2790 
2791  # First put in the frame
2792  print CRYO <<EOF;
2793 
2794 <!--
2795 
2796 -->
2797 
2798 
2799 <!--
2800  <physvol>
2801  <volumeref ref="volAPAFrameYOuterSupport\-$APA_i"/>
2802  <position name="posAPAFrameYOuterSupportNeg\-$APA_i" unit="cm"
2803  x="$APAFrameCenter_x - ($APAFrameYOuterSupport_x + $APAFrameYInnerSupport_x/2 - $EdgeFrameSteelThickness/2)"
2804  y="$APAFrameCenter_y"
2805  z="$APAFrameCenter_z"/>
2806  <rotationref ref="rIdentity"/>
2807  </physvol>
2808  <physvol>
2809  <volumeref ref="volAPAFrameYOuterSupport\-$APA_i"/>
2810  <position name="posAPAFrameYOuterSupportPos\-$APA_i" unit="cm"
2811  x="$APAFrameCenter_x + ($APAFrameYOuterSupport_x + $APAFrameYInnerSupport_x/2 - $EdgeFrameSteelThickness/2)"
2812  y="$APAFrameCenter_y"
2813  z="$APAFrameCenter_z"/>
2814  <rotationref ref="rIdentity"/>
2815  </physvol>
2816 -->
2817 
2818  <physvol>
2819  <volumeref ref="volAPAFrameYSide\-$APA_i"/>
2820  <position name="posAPAFrameYSideNeg\-$_[3]" unit="cm"
2821  x="$APAFrameCenter_x"
2822  y="$APAFrameCenter_y"
2823  z="$APAFrameCenter_z - $APAFrame_z/2 + $APAFrameYSide_z/2"/>
2824  <rotationref ref="rIdentity"/>
2825  </physvol>
2826  <physvol>
2827  <volumeref ref="volAPAFrameYSide\-$APA_i"/>
2828  <position name="posAPAFrameYSidePos\-$_[3]" unit="cm"
2829  x="$APAFrameCenter_x"
2830  y="$APAFrameCenter_y"
2831  z="$APAFrameCenter_z + $APAFrame_z/2 - $APAFrameYSide_z/2"/>
2832  <rotationref ref="rIdentity"/>
2833  </physvol>
2834  <physvol>
2835  <volumeref ref="volAPAFrameZSide\-$APA_i"/>
2836  <position name="posAPAFrameZSidePos\-$_[3]" unit="cm"
2837  x="$APAFrameCenter_x"
2838  y="$APAFrameCenter_y + $APAFrame_y[$APA_i]/2 - $APAFrameZSide_y/2"
2839  z="$APAFrameCenter_z"/>
2840  <rotationref ref="rIdentity"/>
2841  </physvol>
2842  <physvol>
2843  <volumeref ref="volAPAFrameZSide\-$APA_i"/>
2844  <position name="posAPAFrameZSideNeg\-$_[3]" unit="cm"
2845  x="$APAFrameCenter_x"
2846  y="$APAFrameCenter_y - $APAFrame_y[$APA_i]/2 + $APAFrameZSide_y/2"
2847  z="$APAFrameCenter_z"/>
2848  <rotationref ref="rIdentity"/>
2849  </physvol>
2850 
2851 
2852  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2853  - Add the *parts* of the G10 boards that exist directly in volCryostat.
2854  - There are two boards on each the up and downstream end,
2855  one each to wrap the U and V views around the APA frame
2856  - There are 4 on the bottom which anchor the U V and Z wires and the grid plane
2857  - The rest of the parts of the G10 boards must be placed directly in volTPC -->
2858 
2859  <physvol>
2860  <volumeref ref="volG10BoardYSideCenterSeg\-$APA_i"/>
2861  <position name="posG10BoardYSideCenterSeg\-Vup\-$APA_i" unit="cm"
2862  x="$APAFrameCenter_x"
2863  y="$APAFrameCenter_y"
2864  z="$APAFrameCenter_z - $APAFrame_z/2 - (0+.5)*($G10BoardYSide_z)"/>
2865  <rotationref ref="rIdentity"/>
2866  </physvol>
2867  <physvol>
2868  <volumeref ref="volG10BoardYSideCenterSeg\-$APA_i"/>
2869  <position name="posG10BoardYSideCenterSeg\-Uup\-$APA_i" unit="cm"
2870  x="$APAFrameCenter_x"
2871  y="$APAFrameCenter_y"
2872  z="$APAFrameCenter_z - $APAFrame_z/2 - (1+.5)*($G10BoardYSide_z)"/>
2873  <rotationref ref="rIdentity"/>
2874  </physvol>
2875 
2876  <physvol>
2877  <volumeref ref="volG10BoardYSideCenterSeg\-$APA_i"/>
2878  <position name="posG10BoardYSideCenterSeg\-Vdown\-$APA_i" unit="cm"
2879  x="$APAFrameCenter_x"
2880  y="$APAFrameCenter_y"
2881  z="$APAFrameCenter_z + $APAFrame_z/2 + (0+.5)*($G10BoardYSide_z)"/>
2882  <rotationref ref="rIdentity"/>
2883  </physvol>
2884  <physvol>
2885  <volumeref ref="volG10BoardYSideCenterSeg\-$APA_i"/>
2886  <position name="posG10BoardYSideCenterSeg\-Udown\-$APA_i" unit="cm"
2887  x="$APAFrameCenter_x"
2888  y="$APAFrameCenter_y"
2889  z="$APAFrameCenter_z + $APAFrame_z/2 + (1+.5)*($G10BoardYSide_z)"/>
2890  <rotationref ref="rIdentity"/>
2891  </physvol>
2892 
2893  <physvol>
2894  <volumeref ref="volG10BoardZSideCenterSeg\-$APA_i"/>
2895  <position name="posG10BoardZSideCenterSeg\-Z\-$APA_i" unit="cm"
2896  x="$APAFrameCenter_x"
2897  y="$posG10ZSideZ_y"
2898  z="$APAFrameCenter_z"/>
2899  <rotationref ref="rIdentity"/>
2900  </physvol>
2901  <physvol>
2902  <volumeref ref="volG10BoardZSideCenterSeg\-$APA_i"/>
2903  <position name="posG10BoardZSideCenterSeg\-V\-$APA_i" unit="cm"
2904  x="$APAFrameCenter_x"
2905  y="$posG10ZSideV_y"
2906  z="$APAFrameCenter_z"/>
2907  <rotationref ref="rIdentity"/>
2908  </physvol>
2909  <physvol>
2910  <volumeref ref="volG10BoardZSideCenterSeg\-$APA_i"/>
2911  <position name="posG10BoardZSideCenterSeg\-U\-$APA_i" unit="cm"
2912  x="$APAFrameCenter_x"
2913  y="$posG10ZSideU_y"
2914  z="$APAFrameCenter_z"/>
2915  <rotationref ref="rIdentity"/>
2916  </physvol>
2917  <physvol>
2918  <volumeref ref="volG10BoardZSideCenterSeg\-$APA_i"/>
2919  <position name="posG10BoardZSideCenterSeg\-Grid\-$APA_i" unit="cm"
2920  x="$APAFrameCenter_x"
2921  y="$posG10ZSideGrid_y"
2922  z="$APAFrameCenter_z"/>
2923  <rotationref ref="rIdentity"/>
2924  </physvol>
2925 
2926 
2927 
2928 EOF
2929 
2930 
2931  # Now loop through paddle y positions and place them
2932  #for( $p=0; $p<$nPaddlesInAPA[$APA_i]; $p++ ){
2933 
2934 #if($nPaddlesInAPA[$APA_i]!=1)
2935 #{
2936 #print CRYO <<EOF;
2937 
2938 # <physvol>
2939 # <volumeref ref="volOpDetSensitive"/>
2940 # <position name="posPaddle\-$p\-APA\-$APA_i" unit="cm"
2941 # x="$APAFrameCenter_x"
2942 # y="$APAFrameCenter_y - $APAHeight[$APA_i]/2 + $PaddleYPositions[$APA_i][$p]"
2943 # z="$APAFrameCenter_z"/>
2944 # <rotationref ref="rIdentity"/>
2945 # </physvol>
2946 
2947 #EOF
2948 
2949 switch($APA_i){
2950 case 0 { place_bar(2);
2951  place_fiber(2);
2952  place_bar(3); }
2953 case 1 { place_bar(1); }
2954 case 2 { place_fiber(1); }
2955 case 3 { place_bar(4);
2956  place_fiber(3);
2957  place_plank(); }
2958 }
2959 
2960 
2961 }
2962 
2963 
2964 
2965 
2966 
2967 
2968 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2969 #++++++++++++++++++++++++++++++++++++++ solid_CPA +++++++++++++++++++++++++++++++++++++
2970 #++++++++++++++++++++++++++++++++++++++++ vol_CPA +++++++++++++++++++++++++++++++++++++
2971 #++++++++++++++++++++++++++++++++++++++ place_CPA +++++++++++++++++++++++++++++++++++++
2972 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2973 
2974 # Must be called only within gen_Cryostat(),
2975 
2976 sub solid_CPA()
2977 {
2978 
2979  $apa = $_[0];
2980 
2981 print CRYO <<EOF;
2982 
2983  <box name="Cathode" lunit="cm"
2984  x="$Cathode_x"
2985  y="$Cathode_y"
2986  z="$Cathode_z"/>
2987 
2988  <tube name="CPATubeYSide"
2989  rmin="$CPATube_ID"
2990  rmax="$CPATube_OD"
2991  z="$Cathode_y"
2992  deltaphi="360"
2993  aunit="deg"
2994  lunit="cm"/>
2995 
2996  <tube name="CPATubeZSide"
2997  rmin="$CPATube_ID"
2998  rmax="$CPATube_OD"
2999  z="$Cathode_z"
3000  deltaphi="360"
3001  aunit="deg"
3002  lunit="cm"/>
3003 
3004 EOF
3005 
3006 }
3007 
3008 
3009 sub vol_CPA()
3010 {
3011 
3012  print CRYO <<EOF;
3013 
3014  <volume name="volCathode">
3015  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3016  <solidref ref="Cathode"/>
3017  </volume>
3018  <volume name="volCPATubeYSide">
3019  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3020  <solidref ref="CPATubeYSide"/>
3021  </volume>
3022  <volume name="volCPATubeZSide">
3023  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3024  <solidref ref="CPATubeZSide"/>
3025  </volume>
3026 
3027 
3028 EOF
3029 
3030 }
3031 
3032 
3033 sub place_CPA()
3034 {
3035 
3036  $cpa = $_[0];
3037  $cpaCenter_x = $_[1];
3038  $cpaCenter_y = $_[2];
3039  $cpaCenter_z = $_[3];
3040 
3041 print CRYO <<EOF;
3042 
3043 
3044  <physvol>
3045  <volumeref ref="volCathode"/>
3046  <position name="posCathode\-$cpa" unit="cm"
3047  x="$cpaCenter_x - $Cathode_x/2"
3048  y="$cpaCenter_y"
3049  z="$cpaCenter_z"/>
3050  <rotationref ref="rIdentity"/>
3051  </physvol>
3052 
3053 <!--
3054  Curious... The CPATube_OD used here should be CPATube_OD/2,
3055  but that causes a baffling overlap. look into later!
3056 -->
3057 
3058  <physvol>
3059  <volumeref ref="volCPATubeYSide"/>
3060  <position name="posCPATubeYSideUp\-$cpa" unit="cm"
3061  x="$cpaCenter_x"
3062  y="$cpaCenter_y"
3063  z="$cpaCenter_z - $Cathode_z/2 - $CPATube_OD"/>
3064  <rotationref ref="rPlus90AboutX"/>
3065  </physvol>
3066  <physvol>
3067  <volumeref ref="volCPATubeYSide"/>
3068  <position name="posCPATubeYSideDown\-$cpa" unit="cm"
3069  x="$cpaCenter_x"
3070  y="$cpaCenter_y"
3071  z="$cpaCenter_z + $Cathode_z/2 + $CPATube_OD"/>
3072  <rotationref ref="rPlus90AboutX"/>
3073  </physvol>
3074 
3075  <physvol>
3076  <volumeref ref="volCPATubeZSide"/>
3077  <position name="posCPATubeZSideBottom\-$cpa" unit="cm"
3078  x="$cpaCenter_x"
3079  y="$cpaCenter_y - $Cathode_y/2 - $CPATube_OD"
3080  z="$cpaCenter_z"/>
3081  <rotationref ref="rIdentity"/>
3082  </physvol>
3083  <physvol>
3084  <volumeref ref="volCPATubeZSide"/>
3085  <position name="posCPATubeZSideTop\-$cpa" unit="cm"
3086  x="$cpaCenter_x"
3087  y="$cpaCenter_y + $Cathode_y/2 + $CPATube_OD"
3088  z="$cpaCenter_z"/>
3089  <rotationref ref="rIdentity"/>
3090  </physvol>
3091 
3092 
3093 EOF
3094 
3095 }
3096 
3097 
3098 
3099 
3100 
3101 
3102 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3103 #+++++++++++++++++++++++++++++++++++++ gen_Enclosure +++++++++++++++++++++++++++++++++++++
3104 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3105 
3106 sub gen_Enclosure()
3107 {
3108 
3109 # Create the detector enclosure fragment file name,
3110 # add file to list of output GDML fragments,
3111 # and open it
3112  $ENCL = "35t_DetEnclosure" . $suffix . ".gdml";
3113  push (@gdmlFiles, $ENCL);
3114  $ENCL = ">" . $ENCL;
3115  open(ENCL) or die("Could not open file $ENCL for writing");
3116 
3117 
3118 # The standard XML prefix and starting the gdml
3119  print ENCL <<EOF;
3120 <?xml version='1.0'?>
3121 <gdml>
3122 EOF
3123 
3124 
3125 
3126 $TopSteelShell_x = $Argon_x - $NeckInside_x;
3127 
3128  $FoamSouth_y = $Argon_y + $NeckInside_y + 2*$SteelShellThickness;
3129  $FoamTop_x = $Argon_x - $NeckInside_x;
3130  $NeckConcreteShell_x = $TotalPadding + 2*$SteelShellThickness + $NeckInside_x + $FoamPadding;
3131 
3132  $TrenchTopConcrete_x = ($DetEnc_x - $CryoWithPadding_x)/2;
3133 
3134 # All the detector enclosure solids.
3135 print ENCL <<EOF;
3136 <solids>
3137 
3138  <box name="DetEnclosure" lunit="cm"
3139  x="$DetEnc_x"
3140  y="$DetEnc_y"
3141  z="$DetEnc_z"/>
3142 
3143  <trd name="AuxDetTrap" lunit="cm"
3144  x1="$AuxDetScintillatorLongSide" x2="$AuxDetScintillatorShortSide"
3145  y1="$AuxDetScintillatorThickness" y2="$AuxDetScintillatorThickness"
3146  z="$AuxDetScintillatorHeight"/>
3147 
3148  <box name="TrenchBottomConcrete" lunit="cm"
3149  x="$DetEnc_x"
3150  y="$DetEnc_y"
3151  z="$DetEnc_z"/>
3152  <box name="TrenchBottomConcreteSubtract" lunit="cm"
3153  x="$DetEnc_x"
3154  y="$DetEnc_y - $TrenchWallThickness"
3155  z="$DetEnc_z - 2*$TrenchWallThickness"/>
3156  <subtraction name="TrenchBottomConcreteShell">
3157  <first ref="TrenchBottomConcrete"/>
3158  <second ref="TrenchBottomConcreteSubtract"/>
3159  <position name="posHoleInTrench" unit="cm" x="0" y="$TrenchWallThickness/2" z="0"/>
3160  </subtraction>
3161 
3162  <box name="TrenchTopConcrete" lunit="cm"
3163  x="$TrenchTopConcrete_x"
3164  y="$TrenchWallThickness"
3165  z="$DetEnc_z - 2*$TrenchWallThickness"/>
3166 
3167 
3168  <box name="BottomSteel" lunit="cm"
3169  x="$Cryostat_x + 2*$SteelShellThickness"
3170  y="$Cryostat_y + $SteelShellThickness"
3171  z="$Cryostat_z + 2*$SteelShellThickness"/>
3172  <subtraction name="BottomSteelShell">
3173  <first ref="BottomSteel"/>
3174  <second ref="Cryostat"/>
3175  <position name="posLArInShell" unit="cm" x="0" y="$SteelShellThickness/2" z="0"/>
3176  </subtraction>
3177 
3178 
3179  <box name="Neck" lunit="cm"
3180  x="$NeckInside_x + 2*$SteelShellThickness"
3181  y="$NeckInside_y + $SteelShellThickness"
3182  z="$Cryostat_z + 2*$SteelShellThickness"/>
3183  <box name="NeckArgon" lunit="cm"
3184  x="$NeckInside_x"
3185  y="$NeckInside_y"
3186  z="$Cryostat_z"/>
3187  <subtraction name="NeckSteelShell">
3188  <first ref="Neck"/>
3189  <second ref="NeckArgon"/>
3190  <position name="posLArInNeckShell" unit="cm" x="0" y="-$SteelShellThickness/2" z="0"/>
3191  </subtraction>
3192 
3193 
3194  <box name="TopSteelShell" lunit="cm"
3195  x="$TopSteelShell_x"
3196  y="$SteelShellThickness"
3197  z="$Cryostat_z + 2*$SteelShellThickness"/>
3198 
3199 
3200  <box name="FoamSouth" lunit="cm"
3201  x="$FoamPadding"
3202  y="$FoamSouth_y"
3203  z="$Argon_z + 2*$SteelShellThickness + 2*$FoamPadding"/>
3204 
3205  <box name="FoamNorth" lunit="cm"
3206  x="$FoamPadding"
3207  y="$Argon_y + 2*$SteelShellThickness"
3208  z="$Argon_z + 2*$SteelShellThickness + 2*$FoamPadding"/>
3209 
3210  <box name="FoamEastWest" lunit="cm"
3211  x="$Argon_x + 2*$SteelShellThickness"
3212  y="$Argon_y + 2*$SteelShellThickness"
3213  z="$FoamPadding"/>
3214 
3215  <box name="FoamEastWestNeck" lunit="cm"
3216  x="$NeckInside_x + 2*$SteelShellThickness"
3217  y="$NeckInside_y + $SteelShellThickness"
3218  z="$FoamPadding"/>
3219 
3220  <box name="FoamBottom" lunit="cm"
3221  x="$Argon_x + 2*$SteelShellThickness + 2*$FoamPadding"
3222  y="$FoamPadding"
3223  z="$Argon_z + 2*$SteelShellThickness + 2*$FoamPadding"/>
3224 
3225  <box name="FoamTop" lunit="cm"
3226  x="$FoamTop_x"
3227  y="$FoamPadding"
3228  z="$Argon_z + 2*$SteelShellThickness + 2*$FoamPadding"/>
3229 
3230  <box name="FoamNorthNeck" lunit="cm"
3231  x="$FoamPadding"
3232  y="$NeckInside_y"
3233  z="$Argon_z + 2*$SteelShellThickness + 2*$FoamPadding"/>
3234 
3235 
3236  <box name="BottomConcrete" lunit="cm"
3237  x="$Argon_x + 2*($SteelShellThickness+$FoamPadding) + 2*$ConcretePadding"
3238  y="$Argon_y + 2*($SteelShellThickness+$FoamPadding) + $ConcretePadding"
3239  z="$Argon_z + 2*($SteelShellThickness+$FoamPadding) + 2*$ConcretePadding"/>
3240  <box name="BottomConcreteSubtract" lunit="cm"
3241  x="$Argon_x + 2*($SteelShellThickness+$FoamPadding)"
3242  y="$Argon_y + 2*($SteelShellThickness+$FoamPadding)"
3243  z="$Argon_z + 2*($SteelShellThickness+$FoamPadding)"/>
3244  <subtraction name="BottomConcreteShell">
3245  <first ref="BottomConcrete"/>
3246  <second ref="BottomConcreteSubtract"/>
3247  <position name="posHoleInConcrete" unit="cm" x="0" y="$ConcretePadding/2" z="0"/>
3248  </subtraction>
3249 
3250 
3251  <box name="NeckConcrete" lunit="cm"
3252  x="$NeckConcreteShell_x"
3253  y="$NeckInside_y + $SteelShellThickness - $FoamPadding"
3254  z="$Cryostat_z + 2*($SteelShellThickness+$FoamPadding) + 2*$ConcretePadding"/>
3255  <box name="NeckConcreteSubtract" lunit="cm"
3256  x="$NeckInside_x + 2*($SteelShellThickness+$FoamPadding)"
3257  y="$NeckInside_y + $SteelShellThickness - $FoamPadding"
3258  z="$Cryostat_z + 2*($SteelShellThickness+$FoamPadding)"/>
3259  <subtraction name="NeckConcreteShell">
3260  <first ref="NeckConcrete"/>
3261  <second ref="NeckConcreteSubtract"/>
3262  <position name="posHoleInNeckConcrete" unit="cm" x="-$ConcretePadding/2" y="0" z="0"/>
3263  </subtraction>
3264 
3265 
3266 
3267 </solids>
3268 EOF
3269 
3270 
3271 
3272 # Detector enclosure structure
3273  print ENCL <<EOF;
3274 <structure>
3275 
3276  <volume name="volBotSteelShell">
3277  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3278  <solidref ref="BottomSteelShell"/>
3279  </volume>
3280 
3281  <volume name="volTopSteelShell">
3282  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3283  <solidref ref="TopSteelShell"/>
3284  </volume>
3285 
3286  <volume name="volNeckSteelShell">
3287  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
3288  <solidref ref="NeckSteelShell"/>
3289  </volume>
3290 
3291  <volume name="volNeck">
3292  <materialref ref="ArGas"/>
3293  <solidref ref="Neck"/>
3294  <physvol>
3295  <volumeref ref="volNeckSteelShell"/>
3296  <position name="posNeckSteelShell" unit="cm" x="0" y="0" z="0"/>
3297  </physvol>
3298  </volume>
3299 
3300 
3301  <volume name="volFoamSouth">
3302  <materialref ref="polyurethane_foam"/>
3303  <solidref ref="FoamSouth"/>
3304  </volume>
3305  <volume name="volFoamNorth">
3306  <materialref ref="polyurethane_foam"/>
3307  <solidref ref="FoamNorth"/>
3308  </volume>
3309  <volume name="volFoamEastWest">
3310  <materialref ref="polyurethane_foam"/>
3311  <solidref ref="FoamEastWest"/>
3312  </volume>
3313  <volume name="volFoamEastWestNeck">
3314  <materialref ref="polyurethane_foam"/>
3315  <solidref ref="FoamEastWestNeck"/>
3316  </volume>
3317  <volume name="volFoamBottom">
3318  <materialref ref="polyurethane_foam"/>
3319  <solidref ref="FoamBottom"/>
3320  </volume>
3321  <volume name="volFoamTop">
3322  <materialref ref="polyurethane_foam"/>
3323  <solidref ref="FoamTop"/>
3324  </volume>
3325  <volume name="volFoamNorthNeck">
3326  <materialref ref="polyurethane_foam"/>
3327  <solidref ref="FoamNorthNeck"/>
3328  </volume>
3329 
3330  <volume name="volBottomConcreteShell">
3331  <materialref ref="Concrete"/>
3332  <solidref ref="BottomConcreteShell"/>
3333  </volume>
3334  <volume name="volNeckConcreteShell">
3335  <materialref ref="Concrete"/>
3336  <solidref ref="NeckConcreteShell"/>
3337  </volume>
3338 
3339  <volume name="volTrenchBottomConcreteShell">
3340  <materialref ref="Concrete"/>
3341  <solidref ref="TrenchBottomConcreteShell"/>
3342  </volume>
3343  <volume name="volTrenchTopConcrete">
3344  <materialref ref="Concrete"/>
3345  <solidref ref="TrenchTopConcrete"/>
3346  </volume>
3347 EOF
3348 
3349 for($i = 1; $i <= 13; ++$i){
3350  print ENCL <<EOF;
3351  <volume name="volAuxDetBoxBSU-L1-$i" >
3352  <materialref ref="Acrylic"/>
3353  <solidref ref="AuxDetBoxBSU"/>
3354  </volume>
3355 EOF
3356 }
3357 for($i = 1; $i <= 10; ++$i){
3358  print ENCL <<EOF;
3359  <volume name="volAuxDetBoxBSU-L2-$i" >
3360  <materialref ref="Acrylic"/>
3361  <solidref ref="AuxDetBoxBSU"/>
3362  </volume>
3363 EOF
3364 }
3365 for($i = 1; $i <= 16; ++$i){
3366  print ENCL <<EOF;
3367  <volume name="volAuxDetBoxBSU-L3-$i" >
3368  <materialref ref="Acrylic"/>
3369  <solidref ref="AuxDetBoxBSU"/>
3370  </volume>
3371 EOF
3372 }
3373 for($i = 1; $i <= 10; ++$i){
3374  print ENCL <<EOF;
3375  <volume name="volAuxDetBoxBSU-L4-$i" >
3376  <materialref ref="Acrylic"/>
3377  <solidref ref="AuxDetBoxBSU"/>
3378  </volume>
3379 EOF
3380 }
3381 
3382 for ($i=1; $i<=12; ++$i) {
3383  print ENCL <<EOF;
3384  <volume name="volAuxDetTrap-South-$i" >
3385  <materialref ref="Acrylic"/>
3386  <solidref ref="AuxDetTrap"/>
3387  </volume>
3388  <volume name="volAuxDetTrap-North-$i" >
3389  <materialref ref="Acrylic"/>
3390  <solidref ref="AuxDetTrap"/>
3391  </volume>
3392 EOF
3393 }
3394 for ($i=1; $i<=10; ++$i) {
3395  print ENCL <<EOF;
3396  <volume name="volAuxDetTrap-East-$i" >
3397  <materialref ref="Acrylic"/>
3398  <solidref ref="AuxDetTrap"/>
3399  </volume>
3400  <volume name="volAuxDetTrap-West-$i" >
3401  <materialref ref="Acrylic"/>
3402  <solidref ref="AuxDetTrap"/>
3403  </volume>
3404 EOF
3405 }
3406 
3407  print ENCL <<EOF;
3408  <volume name="volDetEnclosure">
3409  <materialref ref="Air"/>
3410  <solidref ref="DetEnclosure"/>
3411 
3412  <physvol>
3413  <volumeref ref="volCryostat"/>
3414  <position name="posCryo" unit="cm" x="$posCryoInDetEnc_x" y="$posCryoInDetEnc_y" z="$posCryoInDetEnc_z"/>
3415  </physvol>
3416 
3417  <physvol>
3418  <volumeref ref="volNeck"/>
3419  <position name="posNeck" unit="cm"
3420  x="$posCryoInDetEnc_x + $Argon_x/2 - $NeckInside_x/2"
3421  y="$posCryoInDetEnc_y + $Argon_y/2 + ($NeckInside_y + $SteelShellThickness)/2"
3422  z="$posCryoInDetEnc_z"/>
3423  </physvol>
3424  <physvol>
3425  <volumeref ref="volTopSteelShell"/>
3426  <position name="posTopSteelShell" unit="cm"
3427  x="$posCryoInDetEnc_x - $Argon_x/2 - $SteelShellThickness + $TopSteelShell_x/2"
3428  y="$posCryoInDetEnc_y + $Argon_y/2 + $SteelShellThickness/2"
3429  z="$posCryoInDetEnc_z"/>
3430  </physvol>
3431  <physvol>
3432  <volumeref ref="volBotSteelShell"/>
3433  <position name="posBotSteelShell" unit="cm"
3434  x="$posCryoInDetEnc_x"
3435  y="$posCryoInDetEnc_y - $SteelShellThickness/2"
3436  z="$posCryoInDetEnc_z"/>
3437  </physvol>
3438 
3439 
3440  <physvol>
3441  <volumeref ref="volFoamSouth"/>
3442  <position name="posFoamSouth" unit="cm"
3443  x="$posCryoInDetEnc_x + $Argon_x/2 + $SteelShellThickness + $FoamPadding/2"
3444  y="$posCryoInDetEnc_y - $Argon_y/2 - $SteelShellThickness + $FoamSouth_y/2"
3445  z="$posCryoInDetEnc_z"/>
3446  </physvol>
3447  <physvol>
3448  <volumeref ref="volFoamNorth"/>
3449  <position name="posFoamNorth" unit="cm"
3450  x="$posCryoInDetEnc_x - $Argon_x/2 - $SteelShellThickness - $FoamPadding/2"
3451  y="$posCryoInDetEnc_y"
3452  z="$posCryoInDetEnc_z"/>
3453  </physvol>
3454  <physvol>
3455  <volumeref ref="volFoamEastWest"/>
3456  <position name="posFoamEast" unit="cm"
3457  x="$posCryoInDetEnc_x"
3458  y="$posCryoInDetEnc_y"
3459  z="$posCryoInDetEnc_z - $Argon_z/2 - $SteelShellThickness - $FoamPadding/2"/>
3460  </physvol>
3461  <physvol>
3462  <volumeref ref="volFoamEastWest"/>
3463  <position name="posFoamWest" unit="cm"
3464  x="$posCryoInDetEnc_x"
3465  y="$posCryoInDetEnc_y"
3466  z="$posCryoInDetEnc_z + $Argon_z/2 + $SteelShellThickness + $FoamPadding/2"/>
3467  </physvol>
3468  <physvol>
3469  <volumeref ref="volFoamEastWestNeck"/>
3470  <position name="posFoamEastNeck" unit="cm"
3471  x="$posCryoInDetEnc_x + $Argon_x/2 - $NeckInside_x/2"
3472  y="$posCryoInDetEnc_y + $Argon_y/2 + ($NeckInside_y + $SteelShellThickness)/2"
3473  z="$posCryoInDetEnc_z - $Argon_z/2 - $SteelShellThickness - $FoamPadding/2"/>
3474  </physvol>
3475  <physvol>
3476  <volumeref ref="volFoamEastWestNeck"/>
3477  <position name="posFoamWestNeck" unit="cm"
3478  x="$posCryoInDetEnc_x + $Argon_x/2 - $NeckInside_x/2"
3479  y="$posCryoInDetEnc_y + $Argon_y/2 + ($NeckInside_y + $SteelShellThickness)/2"
3480  z="$posCryoInDetEnc_z + $Argon_z/2 + $SteelShellThickness + $FoamPadding/2"/>
3481  </physvol>
3482  <physvol>
3483  <volumeref ref="volFoamBottom"/>
3484  <position name="posFoamBottom" unit="cm"
3485  x="$posCryoInDetEnc_x"
3486  y="$posCryoInDetEnc_y - $Argon_y/2 - $SteelShellThickness - $FoamPadding/2"
3487  z="$posCryoInDetEnc_z"/>
3488  </physvol>
3489  <physvol>
3490  <volumeref ref="volFoamTop"/>
3491  <position name="posFoamTop" unit="cm"
3492  x="$posCryoInDetEnc_x - $Argon_x/2 - $SteelShellThickness - $FoamPadding + $FoamTop_x/2"
3493  y="$posCryoInDetEnc_y + $Argon_y/2 + $SteelShellThickness + $FoamPadding/2"
3494  z="$posCryoInDetEnc_z"/>
3495  </physvol>
3496  <physvol>
3497  <volumeref ref="volFoamNorthNeck"/>
3498  <position name="posFoamNorthNeck" unit="cm"
3499  x="$posCryoInDetEnc_x + $Argon_x/2 - $NeckInside_x - $SteelShellThickness - $FoamPadding/2"
3500  y="$posCryoInDetEnc_y + $Argon_y/2 + $SteelShellThickness + $NeckInside_y/2"
3501  z="$posCryoInDetEnc_z"/>
3502  </physvol>
3503 
3504 
3505  <physvol>
3506  <volumeref ref="volBottomConcreteShell"/>
3507  <position name="posBottomConcreteShell" unit="cm"
3508  x="$posCryoInDetEnc_x"
3509  y="$posCryoInDetEnc_y - $ConcretePadding/2"
3510  z="$posCryoInDetEnc_z"/>
3511  </physvol>
3512  <physvol>
3513  <volumeref ref="volNeckConcreteShell"/>
3514  <position name="posNeckConcreteShell" unit="cm"
3515  x="$posCryoInDetEnc_x + $Argon_x/2 +$SteelShellThickness + $TotalPadding - $NeckConcreteShell_x/2"
3516  y="$posCryoInDetEnc_y + $Argon_y/2 + $FoamPadding + ($NeckInside_y + $SteelShellThickness - $FoamPadding)/2"
3517  z="$posCryoInDetEnc_z"/>
3518  </physvol>
3519 
3520 
3521 
3522  <physvol>
3523  <volumeref ref="volTrenchBottomConcreteShell"/>
3524  <position name="posTrenchConcrete" unit="cm" x="0" y="0" z="0"/>
3525  </physvol>
3526 <!-- Concrete is too heavy for the roof
3527  <physvol>
3528  <volumeref ref="volTrenchTopConcrete"/>
3529  <position name="posTrenchConcreteTop_Pos" unit="cm"
3530  x=" + $DetEnc_x/2 - $TrenchTopConcrete_x/2"
3531  y="$DetEnc_y/2 - $TrenchWallThickness/2"
3532  z="0"/>
3533  </physvol>
3534  <physvol>
3535  <volumeref ref="volTrenchTopConcrete"/>
3536  <position name="posTrenchConcreteTop_Neg" unit="cm"
3537  x=" - $DetEnc_x/2 + $TrenchTopConcrete_x/2"
3538  y="$DetEnc_y/2 - $TrenchWallThickness/2"
3539  z="0"/>
3540  </physvol>
3541 -->
3542 
3543 
3544 EOF
3545 
3546 
3547 # place the 12 North Wall AuxDets
3548 #$NorthWallInt_z = ((95+108)/2 - (35+48)/2)*$inch/5;
3549 $NorthWallInt_z = ( 274.32-(274.32-213.36)/4 - (88.9+121.92)/2 )/5;
3550  # these numbers from a spreadsheet emailed by Ohana Rodrigues
3551 for ($i=1; $i<=12; ++$i)
3552 {
3553  #$FromCryoCorner_z = (35+48)/2*$inch + (($i-1) % 6)*$NorthWallInt_z;
3554  $FromCryoCorner_z = (88.9+121.92)/2 + (($i-1) % 6)*$NorthWallInt_z;
3555  if($i%2==1){
3556  $rotation = "rAuxDetNSWallUp";
3557  if($i>6) { $FromCryoCorner_y = (259.08 + 0.12*$inch) + $AuxDetScintillatorHeight/2; }
3558  else { $FromCryoCorner_y = (66.04 + 0.12*$inch) + $AuxDetScintillatorHeight/2; }
3559  }
3560  else {
3561  $rotation = "rAuxDetNSWallDown";
3562  if($i>6) { $FromCryoCorner_y = (325.12 - 0.12*$inch) - $AuxDetScintillatorHeight/2; }
3563  else { $FromCryoCorner_y = (132.08 - 0.12*$inch) - $AuxDetScintillatorHeight/2; }
3564  }
3565 
3566  $posAuxDet_y = $posCryoInDetEnc_y - 375.92/2 + $FromCryoCorner_y;
3567 
3568 print ENCL <<EOF;
3569  <physvol>
3570  <volumeref ref="volAuxDetTrap-North-$i"/>
3571  <position name="posAuxDet-North-$i" unit="cm"
3572  x=" $posCryoInDetEnc_x - $CryoWithPadding_x/2 - $AuxDetHousingThickness/2"
3573  y=" $posAuxDet_y"
3574  z=" $posCryoInDetEnc_z - 411.99/2 + $FromCryoCorner_z"/>
3575  <rotationref ref="$rotation"/>
3576  </physvol>
3577 EOF
3578 
3579 }
3580 
3581 # place the 12 South Wall AuxDets
3582 #$SouthWallInt_z = ((96.5+109.6)/2 - (36.8+49.5)/2)*$inch/5;
3583 $SouthWallInt_z = ( (245.11+278.38)/2 - (93.47+(153.67-93.47)/4) )/5;
3584  # these numbers from a spreadsheet emailed by Ohana Rodrigues
3585 for ($i=1; $i<=12; ++$i)
3586 {
3587  #$FromCryoCorner_z = (96.5+109.6)/2*$inch - (($i-1) % 6)*$SouthWallInt_z;
3588  $FromCryoCorner_z = (245.11+278.38)/2 - (($i-1) % 6)*$SouthWallInt_z;
3589  if($i%2==1){
3590  $rotation = "rAuxDetNSWallUp";
3591  if($i>6) { $FromCryoCorner_y = (272.11 + 0.12*$inch) + $AuxDetScintillatorHeight/2; }
3592  else { $FromCryoCorner_y = (31.5 + 0.12*$inch) + $AuxDetScintillatorHeight/2; }
3593  }
3594  else {
3595  $rotation = "rAuxDetNSWallDown";
3596  if($i>6) { $FromCryoCorner_y = (335.61 - 0.12*$inch) - $AuxDetScintillatorHeight/2; }
3597  else { $FromCryoCorner_y = (93.98 - 0.12*$inch) - $AuxDetScintillatorHeight/2; }
3598  }
3599 
3600  $posAuxDet_y = $posCryoInDetEnc_y - 375.92/2 + $FromCryoCorner_y;
3601 
3602 print ENCL <<EOF;
3603  <physvol>
3604  <volumeref ref="volAuxDetTrap-South-$i"/>
3605  <position name="posAuxDet-South-$i" unit="cm"
3606  x=" $posCryoInDetEnc_x + $CryoWithPadding_x/2 + $AuxDetHousingThickness/2"
3607  y=" $posAuxDet_y"
3608  z=" $posCryoInDetEnc_z - 411.99/2 + $FromCryoCorner_z"/>
3609  <rotationref ref="$rotation"/>
3610  </physvol>
3611 EOF
3612 
3613 }
3614 
3615 # place the 10 East Wall AuxDets
3616 #$EastWallInt_x = ((136.7+149.9)/2 - (28.4+41.4)/2)*$inch/9;
3617 $EastWallInt_x = ( (347.48+380.75)/2 - (72.14+(133.1-72.14)/4) )/9;
3618  # these numbers from a spreadsheet emailed by Ohana Rodrigues
3619 for ($i=1; $i<=10; ++$i)
3620 {
3621 
3622  # +6cm shift (towards the south wall) as requested by Michelle Stancari
3623  $FromCryoCorner_x = (347.48+380.75)/2 - ($i-1)*$EastWallInt_x + 6;
3624  if($i%2==1){ $rotation = "rAuxDetEWWallUp";
3625  $FromCryoCorner_y = ( 47 + 0.12*$inch) + $AuxDetScintillatorHeight/2; }
3626  else { $rotation = "rAuxDetEWWallDown";
3627  $FromCryoCorner_y = (112.45 - 0.12*$inch) - $AuxDetScintillatorHeight/2; }
3628 
3629  $posAuxDet_y = $posCryoInDetEnc_y - 375.92/2 + $FromCryoCorner_y;
3630 
3631 print ENCL <<EOF;
3632  <physvol>
3633  <volumeref ref="volAuxDetTrap-East-$i"/>
3634  <position name="posAuxDet-East-$i" unit="cm"
3635  x=" $posCryoInDetEnc_x - 541.53/2 + $FromCryoCorner_x"
3636  y=" $posAuxDet_y"
3637  z=" $posCryoInDetEnc_z - $CryoWithPadding_z/2 - $AuxDetHousingThickness/2"/>
3638  <rotationref ref="$rotation"/>
3639  </physvol>
3640 EOF
3641 
3642 }
3643 
3644 
3645 # place the 10 West Wall AuxDets
3646 #$WestWallInt_x = ((134+147)/2 - (26.3+39.3)/2)*$inch/9;
3647 $WestWallInt_x = ( (344.42+312.42)/2 - (66.37+99.82)/2 )/8;
3648  # these numbers from a spreadsheet emailed by Ohana Rodrigues
3649 for ($i=1; $i<=10; ++$i)
3650 {
3651 
3652  # +6cm shift (towards the south wall) as requested by Michelle Stancari
3653  $FromCryoCorner_x = (66.11+99.82)/2 + ($i-1)*$WestWallInt_x + 6;
3654  if($i%2==1){ $rotation = "rAuxDetEWWallUp";
3655  $FromCryoCorner_y = (264.44 + 0.12*$inch) + $AuxDetScintillatorHeight/2 }
3656  else { $rotation = "rAuxDetEWWallDown";
3657  $FromCryoCorner_y = (329.95 - 0.12*$inch) - $AuxDetScintillatorHeight/2 }
3658 
3659  $posAuxDet_y = $posCryoInDetEnc_y - 375.92/2 + $FromCryoCorner_y;
3660 
3661 print ENCL <<EOF;
3662  <physvol>
3663  <volumeref ref="volAuxDetTrap-West-$i"/>
3664  <position name="posAuxDet-West-$i" unit="cm"
3665  x=" $posCryoInDetEnc_x - 541.53/2 + $FromCryoCorner_x"
3666  y=" $posAuxDet_y"
3667  z=" $posCryoInDetEnc_z + $CryoWithPadding_z/2 + $AuxDetHousingThickness/2"/>
3668  <rotationref ref="$rotation"/>
3669  </physvol>
3670 EOF
3671 
3672 }
3673 
3674 # place the 13 Layer 1 telescope counters
3675 for ($i=1; $i<=13; ++$i)
3676 {
3677 print ENCL <<EOF;
3678  <physvol>
3679  <volumeref ref="volAuxDetBoxBSU-L1-$i"/>
3680  <position name="posAuxDet-BSU-L1-$i" unit="cm"
3681  x="$BSULayer1_xpos[$i-1] - $OriginXSet"
3682  y="$BSULayer1_ypos - $OriginYSet"
3683  z="$BSULayer1_zpos - $OriginZSet"/>
3684  </physvol>
3685 EOF
3686 }
3687 
3688 # place the 9 Layer 2 telescope counters
3689 for ($i=1; $i<=10; ++$i)
3690 {
3691 print ENCL <<EOF;
3692  <physvol>
3693  <volumeref ref="volAuxDetBoxBSU-L2-$i"/>
3694  <position name="posAuxDet-BSU-L2-$i" unit="cm"
3695  x="$BSULayer2_xpos - $OriginXSet"
3696  y="$BSULayer2_ypos - $OriginYSet"
3697  z="$BSULayer2_zpos[$i-1] - $OriginZSet"/>
3698  <rotationref ref="rPlus90AboutY"/>
3699  </physvol>
3700 EOF
3701 }
3702 
3703 
3704 
3705 print ENCL <<EOF;
3706  </volume>
3707 </structure>
3708 </gdml>
3709 EOF
3710 
3711 close(ENCL);
3712 }
3713 
3714 
3715 
3716 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3717 #+++++++++++++++++++++++++++++++++++++++ gen_World +++++++++++++++++++++++++++++++++++++++
3718 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3719 
3720 sub gen_World()
3721 {
3722 
3723 # Create the WORLD fragment file name,
3724 # add file to list of output GDML fragments,
3725 # and open it
3726  $WORLD = "35t_World" . $suffix . ".gdml";
3727  push (@gdmlFiles, $WORLD);
3728  $WORLD = ">" . $WORLD;
3729  open(WORLD) or die("Could not open file $WORLD for writing");
3730 
3731 
3732 # The standard XML prefix and starting the gdml
3733  print WORLD <<EOF;
3734 <?xml version='1.0'?>
3735 <gdml>
3736 EOF
3737 
3738 $Dirt_y = $OriginYSet + $World_y/2 + $DetEnc_y/2;
3739 
3740 # All the World solids.
3741 print WORLD <<EOF;
3742 <solids>
3743  <box name="World" lunit="cm"
3744  x="$World_x"
3745  y="$World_y"
3746  z="$World_z"/>
3747 
3748  <box name="AuxDetBoxBSU" lunit="cm"
3749  x="$AuxDetBSUScintWidth"
3750  y="$AuxDetBSUScintHeight"
3751  z="$AuxDetBSUScintLength"/>
3752 
3753  <box name="DirtBlock" lunit="cm"
3754  x="$World_x"
3755  y="$Dirt_y"
3756  z="$World_z"/>
3757  <subtraction name="DirtWithHole">
3758  <first ref="DirtBlock"/>
3759  <second ref="DetEnclosure"/>
3760  <position name="posHoleInDirt" unit="cm"
3761  x="$OriginXSet"
3762  y="$Dirt_y/2 - $DetEnc_y/2"
3763  z="$OriginZSet"/>
3764  </subtraction>
3765 
3766  <tube name="Berm"
3767  rmax="$BermRadius"
3768  z="$DetEnc_x"
3769  deltaphi="180"
3770  aunit="deg"
3771  lunit="cm"/>
3772 
3773 
3774 </solids>
3775 EOF
3776 
3777 # World structure
3778 print WORLD <<EOF;
3779 <structure>
3780 
3781  <volume name="volDirtWithHole" >
3782  <materialref ref="Dirt"/>
3783  <solidref ref="DirtWithHole"/>
3784  </volume>
3785  <volume name="volBerm" >
3786  <materialref ref="Dirt"/>
3787  <solidref ref="Berm"/>
3788  </volume>
3789 
3790  <volume name="volWorld" >
3791  <materialref ref="Air"/>
3792  <solidref ref="World"/>
3793  <physvol>
3794  <volumeref ref="volDetEnclosure"/>
3795  <position name="posDetEnclosure" unit="cm"
3796  x="$OriginXSet"
3797  y="$OriginYSet"
3798  z="$OriginZSet"/>
3799  </physvol>
3800  <physvol>
3801  <volumeref ref="volDirtWithHole"/>
3802  <position name="posDirtWithHole" unit="cm"
3803  x="0"
3804  y=" -$World_y/2 + $Dirt_y/2 "
3805  z="0"/>
3806  </physvol>
3807  <physvol>
3808  <volumeref ref="volBerm"/>
3809  <position name="posBerm" unit="cm"
3810  x="0"
3811  y="$OriginYSet + $DetEnc_y/2 "
3812  z="$OriginZSet + $DetEnc_z/2 + $BermRadius"/>
3813  <rotationref ref="rPlus90AboutY"/>
3814  </physvol>
3815 
3816 EOF
3817 
3818 
3819 # place the 16 Layer 3 telescope counters
3820 for ($i=1; $i<=16; ++$i)
3821 {
3822 print WORLD <<EOF;
3823  <physvol>
3824  <volumeref ref="volAuxDetBoxBSU-L3-$i"/>
3825  <position name="posAuxDetBox-BSU-L3-$i" unit="cm"
3826  x="$BSULayer3_xpos[$i-1]"
3827  y="$BSULayer3_ypos"
3828  z="$BSULayer3_zpos"/>
3829  </physvol>
3830 EOF
3831 }
3832 
3833 # place the 10 Layer 4 telescope counters
3834 for ($i=1; $i<=10; ++$i)
3835 {
3836 print WORLD <<EOF;
3837  <physvol>
3838  <volumeref ref="volAuxDetBoxBSU-L4-$i"/>
3839  <position name="posAuxDetBox-BSU-L4-$i" unit="cm"
3840  x="$BSULayer4_xpos"
3841  y="$BSULayer4_ypos"
3842  z="$BSULayer4_zpos[$i-1]"/>
3843  <rotationref ref="rPlus90AboutY"/>
3844  </physvol>
3845 EOF
3846 }
3847 
3848 # place the 16 Layer 5 telescope counters
3849 #for ($i=1; $i<=16; ++$i)
3850 #{
3851 #print WORLD <<EOF;
3852 #<!--
3853 # <physvol>
3854 # <volumeref ref="volAuxDetBoxBSU-L5-$i"/>
3855 # <position name="posAuxDet-BSU-L5-$i" unit="cm"
3856 # x="$BSULayer5_xpos[$i-1]"
3857 # y="$BSULayer5_ypos"
3858 # z="$BSULayer5_zpos"/>
3859 # </physvol>
3860 #-->
3861 #EOF
3862 #}
3863 
3864 print WORLD <<EOF;
3865 
3866  </volume>
3867 </structure>
3868 </gdml>
3869 EOF
3870 
3871 # make_gdml.pl will take care of <setup/>
3872 
3873 close(WORLD);
3874 }
3875 
3876 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3877 #++++++++++++++++++++++++++++++++++++ write_fragments ++++++++++++++++++++++++++++++++++++
3878 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3879 
3880 sub write_fragments()
3881 {
3882  # This subroutine creates an XML file that summarizes the the subfiles output
3883  # by the other sub routines - it is the input file for make_gdml.pl which will
3884  # give the final desired GDML file. Specify its name with the output option.
3885  # (you can change the name when running make_gdml)
3886 
3887  if ( ! defined $output )
3888  {
3889  $output = "-"; # write to STDOUT
3890  }
3891 
3892  # Set up the output file.
3893  $OUTPUT = ">" . $output;
3894  open(OUTPUT) or die("Could not open file $OUTPUT");
3895 
3896  print OUTPUT <<EOF;
3897 <?xml version='1.0'?>
3898 
3899 <!-- Input to Geometry/gdml/make_gdml.pl; define the GDML fragments
3900  that will be zipped together to create a detector description.
3901  -->
3902 
3903 <config>
3904 
3905  <constantfiles>
3906 
3907  <!-- These files contain GDML <constant></constant>
3908  blocks. They are read in separately, so they can be
3909  interpreted into the remaining GDML. See make_gdml.pl for
3910  more information.
3911  -->
3912 
3913 EOF
3914 
3915  foreach $filename (@defFiles)
3916  {
3917  print OUTPUT <<EOF;
3918  <filename> $filename </filename>
3919 EOF
3920  }
3921 
3922  print OUTPUT <<EOF;
3923 
3924  </constantfiles>
3925 
3926  <gdmlfiles>
3927 
3928  <!-- The GDML file fragments to be zipped together. -->
3929 
3930 EOF
3931 
3932  foreach $filename (@gdmlFiles)
3933  {
3934  print OUTPUT <<EOF;
3935  <filename> $filename </filename>
3936 EOF
3937  }
3938 
3939  print OUTPUT <<EOF;
3940 
3941  </gdmlfiles>
3942 
3943 </config>
3944 EOF
3945 
3946  close(OUTPUT);
3947 }
3948 
3949 
3950 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3951 #++++++++++++++++++++++++++++++++++++++ place_bars +++++++++++++++++++++++++++++++++++++++
3952 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3953 
3954 sub place_bar()
3955 {
3956 print CRYO <<EOF;
3957  <!-- Bar$_[0]-->
3958 EOF
3959 # for($j=1; $j<$numberofbars+1; $j++)
3960 # {
3961 
3962  $pos_ref_name="Bar" . $_[0] . "Pos";
3963 print CRYO <<EOF;
3964  <physvol>
3965  <volumeref ref="volOpDetSensitive_Bar"/>
3966  <positionref ref="$pos_ref_name"/>
3967  </physvol>
3968 
3969 EOF
3970 # }
3971 
3972 }
3973 
3974 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3975 #++++++++++++++++++++++++++++++++++++++ place_plank ++++++++++++++++++++++++++++++++++++++
3976 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3977 
3978 sub place_plank()
3979 {
3980 print CRYO <<EOF;
3981  <!-- Plank-->
3982 EOF
3983 
3984 $pos_ref_name="PlankPos";
3985 print CRYO <<EOF;
3986  <physvol>
3987  <volumeref ref="volOpDetSensitive_Plank"/>
3988  <positionref ref="$pos_ref_name"/>
3989  </physvol>
3990 EOF
3991 }
3992 
3993 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3994 #++++++++++++++++++++++++++++++++++++++ place_fibers +++++++++++++++++++++++++++++++++++++
3995 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3996 
3997 sub place_fiber()
3998 {
3999 print CRYO <<EOF;
4000  <!-- 32 Fiber Module $_[0]-->
4001 
4002 EOF
4003 
4004 ############################# Fiber ##############################
4005 $pos_ref_name="Fiber" . $_[0] . "Pos";
4006 print CRYO <<EOF;
4007  <physvol>
4008  <volumeref ref="volOpDetSensitive_Fiber"/>
4009  <positionref ref="$pos_ref_name"/>
4010  </physvol>
4011 
4012 EOF
4013 }