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