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