generate_3x1x1dphase_driftY.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 ##################################################################################
4 #
5 # This script is based on generate_dunedphase10kt_v2.pl (see description
6 # in there file for more info). Some parameters were changed to generate
7 # a first version of the 3x1x1 dual phase geometry (e.g. driftTPCActive
8 # and number of CRM's).
9 # More detector elements are going to be added (e.g. PMTs, field cage, ...)
10 # For more info, please contact Christoph Alt: christoph.alt@cern.ch
11 #
12 # !!!NOTE!!!: the readout is on a positive Y
13 ##################################################################################
14 # Updates:
15 # 26/11/2018 - j.soto@cern.ch - This updates are not included in the drift in X geometries!
16 # Added Field Cage, Ground Grid, LEMS, Extraction Grid, Cathode and corrected the PMT positions.
17 # All these new elements are included by default.
18 ##################################################################################
19 
20 
21 #use warnings;
22 use gdmlMaterials;
23 use Math::Trig;
24 use Getopt::Long;
25 use Math::BigFloat;
26 Math::BigFloat->precision(-16);
27 
28 GetOptions( "help|h" => \$help,
29  "suffix|s:s" => \$suffix,
30  "output|o:s" => \$output,
31  "wires|w:s" => \$wires);
32 
33 my $pmt_switch="on";
34 my $FieldCage_switch="on";
35 my $Cathode_switch="on";
36 my $GroundGrid_switch="on";
37 my $ExtractionGrid_switch="on";
38 my $LEMs_switch="on";
39 
40 
41 if ( defined $help )
42 {
43  # If the user requested help, print the usage notes and exit.
44  usage();
45  exit;
46 }
47 
48 if ( ! defined $suffix )
49 {
50  # The user didn't supply a suffix, so append nothing to the file
51  # names.
52  $suffix = "";
53 }
54 else
55 {
56  # Otherwise, stick a "-" before the suffix, so that a suffix of
57  # "test" applied to filename.gdml becomes "filename-test.gdml".
58  $suffix = "-" . $suffix;
59 }
60 
61 #if ( ! defined $workspace ) # not done
62 #{
63 # $workspace = 0;
64 #}
65 #elsif ( $workspace == 1)
66 #{
67 # print "\t\tCreating smaller workspace geometry.\n";
68 #}
69 
70 # set wires on to be the default, unless given an input by the user
71 $wires_on = 1; # 1=on, 0=off
72 if (defined $wires)
73 {
74  $wires_on = $wires
75 }
76 
77 $tpc_on = 1;
78 
79 $basename = "3x1x1dphase_driftY";
80 if ( $wires_on == 0 )
81 {
82  $basename = $basename."_nowires";
83 }
84 
85 #if ( $workspace == 1 )
86 #{
87 # $basename = $basename."_workspace";
88 #}
89 
90 
91 ##################################################################
92 ############## Parameters for Charge Readout Plane ###############
93 
94 # 3x1x1 dual-phase
95 $wirePitch = 0.3125; # channel pitch
96 $nChannelsLengthPerCRM = 960; # channels along the length of the CRM
97 $nChannelsWidthPerCRM = 320; # channels along the width of the CRM
98 $borderCRM = 0.5; # dead space at the border of each CRM
99 
100 # dimensions of a single Charge Readout Module (CRM)
101 $widthCRM_active = $wirePitch * $nChannelsWidthPerCRM;
102 $lengthCRM_active = $wirePitch * $nChannelsLengthPerCRM;
103 
104 $widthCRM = $widthCRM_active + 2 * $borderCRM;
105 $lengthCRM = $lengthCRM_active + 2 * $borderCRM;
106 
107 # number of CRMs in y and z
108 $nCRM_x = 1;
109 $nCRM_z = 1;
110 
111 # calculate tpc area based on number of CRMs and their dimensions
112 $widthTPCActive = $nCRM_x * $widthCRM; # around 100
113 $lengthTPCActive = $nCRM_z * $lengthCRM; # around 300
114 
115 # active volume dimensions
116 $driftTPCActive = 100.0;
117 
118 # model anode strips as wires
119 $padWidth = 0.015;
120 $ReadoutPlane = 2 * $padWidth;
121 
122 #$padHeight = 0.0035;
123 
124 ##################################################################
125 ############## Parameters for TPC and inner volume ###############
126 
127 # inner volume dimensions of the cryostat
128 $Argon_x = 202.5;
129 $Argon_y = 238.1;
130 $Argon_z = 478.2;
131 
132 # height of gas argon layer on top
133 $HeightGaseousAr = 50.8;
134 
135 # size of liquid argon buffer
136 $xLArBuffer = 0.5 * ($Argon_x - $widthTPCActive);
137 $yLArBuffer = $Argon_y - $driftTPCActive - $HeightGaseousAr - $ReadoutPlane;
138 $zLArBuffer = 0.5 * ($Argon_z - $lengthTPCActive);
139 
140 # cryostat
141 $SteelThickness = 0.12; # membrane
142 
143 $Cryostat_x = $Argon_x + 2*$SteelThickness;
144 $Cryostat_y = $Argon_y + 2*$SteelThickness;
145 $Cryostat_z = $Argon_z + 2*$SteelThickness;
146 
147 ##################################################################
148 ############## DetEnc and World relevant parameters #############
149 
150 $SteelSupport_x = 0.6;
151 $SteelSupport_y = 0.6;
152 $SteelSupport_z = 0.6;
153 $FoamPadding = 102.3;
154 $FracMassOfSteel = 0.5; #The steel support is not a solid block, but a mixture of air and steel
155 $FracMassOfAir = 1 - $FracMassOfSteel;
156 
157 
158 $SpaceSteelSupportToWall = 0;
159 $SpaceSteelSupportToCeiling = 0;
160 
161 $DetEncX = $Cryostat_x
162  + 2*($SteelSupport_x + $FoamPadding) + 2*$SpaceSteelSupportToWall;
163 
164 $DetEncY = $Cryostat_y
165  + 2*($SteelSupport_y + $FoamPadding) + $SpaceSteelSupportToCeiling;
166 
167 $DetEncZ = $Cryostat_z
168  + 2*($SteelSupport_z + $FoamPadding) + 2*$SpaceSteelSupportToWall;
169 
170 $posCryoInDetEnc_y = - $DetEncY/2 + $SteelSupport_y + $FoamPadding + $Cryostat_y/2;
171 
172 
173 # 2*AirThickness is added to the world volume in x, y and z
174 $AirThickness = 3000;
175 
176  # We want the world origin to be vertically centered on active TPC
177  # This is to be added to the x and y position of every volume in volWorld
178 
179 $OriginXSet = $DetEncX/2.0
180  -$SpaceSteelSupportToWall
181  -$SteelSupport_x
182  -$FoamPadding
183  -$SteelThickness
184  -$xLArBuffer
185  -$widthTPCActive/2.0;
186 
187 $OriginYSet = $DetEncY/2.0
188  - $SteelSupport_y
189  - $FoamPadding
190  - $SteelThickness
191  - $yLArBuffer
192  - $driftTPCActive/2.0;
193 
194  # We want the world origin to be at the very front of the fiducial volume.
195  # move it to the front of the enclosure, then back it up through the concrete/foam,
196  # then through the Cryostat shell, then through the upstream dead LAr (including the
197  # dead LAr on the edge of the TPC)
198  # This is to be added to the z position of every volume in volWorld
199 
200 $OriginZSet = $DetEncZ/2.0
201  - $SpaceSteelSupportToWall
202  - $SteelSupport_z
203  - $FoamPadding
204  - $SteelThickness
205  - $zLArBuffer
206  - $borderCRM;
207 
208 
209 ##################################################################
210 ############### Parameters for det elements ######################
211 ##################################################################
212 ############## Field Cage, Cathode and Ground Grid Parameters ###############
213 
214 $FieldShaperLongTubeLength = 312.17;
215 $FieldShaperShortTubeLength = 112.17;
216 $FieldShaperInnerRadius = 1.485;
217 $FieldShaperOuterRadius = 1.685;
218 $FieldShaperTorRad = 1.69;
219 
220 $FieldShaperLength = $FieldShaperLongTubeLength + 2*$FieldShaperOuterRadius+ 2*$FieldShaperTorRad;
221 $FieldShaperWidth = $FieldShaperShortTubeLength + 2*$FieldShaperOuterRadius+ 2*$FieldShaperTorRad;
222 
223 $FieldShaperSeparation = 5.0;
224 $NFieldShapers = ($driftTPCActive/$FieldShaperSeparation) - 1;
225 
226 $FieldCageSizeX = $FieldShaperWidth+2;
227 $FieldCageSizeY = $FieldShaperSeparation*$NFieldShapers+2;
228 $FieldCageSizeZ = $FieldShaperLength+2;
229 
230 $CathodeCableRadius=0.38;
231 $CathodeCableSeparation=4;
232 $CathodeCableLength=112.18;
233 $CathodeNumberOfCables=76;
234 
235 $CathodeHeight=2*$FieldShaperOuterRadius+0.05;
236 $CathodeLength=$FieldShaperLength+0.5;
237 $CathodeWidth=$FieldShaperWidth+0.5;
238 $CathodeGroundGridSeparation=20;
239 $GroundPMTSeparation=1.727;
240 
241 
242 $LEMsFFSSeparation=3.0;
243 $FFSPositionHeight=$Argon_y/2-$HeightGaseousAr-$LEMsFFSSeparation+0.5;
244 $CathodePositionHeight=$FFSPositionHeight-($NFieldShapers*$FieldShaperSeparation);
245 $GroundGridPositionHeight=$CathodePositionHeight-$CathodeGroundGridSeparation;
246 $PMTposHeight=$CathodePositionHeight-$CathodeGroundGridSeparation-$GroundPMTSeparation;
247 $PMTposHeight=-65.114;
248 
249 #-$OriginYSet+(1+$i-$NFieldShapers*0.5)*$FieldShaperSeparation
250 
251 
252 ##################################################################
253 ############## Parameters for PMTs ###############
254 
255 #pos in cm inside the cryostat X coordinate: 2.3cm from the ground grid
256  @pmt_pos = ( " x=\"0\" y=\"$PMTposHeight\" z=\"-92.246\"", #-92.246"', #PMT1 - negative base - direct coating #x="-50-4.5+5.5*2.54-1.27*2.54-2.3"
257  " x=\"0\" y=\"$PMTposHeight\" z=\"-46.123\"", #-46.123"', #PMT2- negative base - plate
258  " x=\"0\" y=\"$PMTposHeight\" z=\"0\"", #PMT3 - positive base - direct coating
259  " x=\"0\" y=\"$PMTposHeight\" z=\"46.123\"", #46.123"', #PMT4 - positive base - plate
260  " x=\"0\" y=\"$PMTposHeight\" z=\"92.246\""); #92.246"'); #PMT5 - negative base - direct coating
261 
262 
263 #+++++++++++++++++++++++++ End defining variables ++++++++++++++++++++++++++
264 
265 
266 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
267 #+++++++++++++++++++++++++++++++++++++++++ usage +++++++++++++++++++++++++++++++++++++++++
268 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
269 
270 sub usage()
271 {
272  print "Usage: $0 [-h|--help] [-o|--output <fragments-file>] [-s|--suffix <string>]\n";
273  print " if -o is omitted, output goes to STDOUT; <fragments-file> is input to make_gdml.pl\n";
274  print " -s <string> appends the string to the file names; useful for multiple detector versions\n";
275  print " -h prints this message, then quits\n";
276 }
277 
278 
279 
280 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
281 #++++++++++++++++++++++++++++++++++++++ gen_Define +++++++++++++++++++++++++++++++++++++++
282 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
283 
284 sub gen_Define()
285 {
286 
287 # Create the <define> fragment file name,
288 # add file to list of fragments,
289 # and open it
290  $DEF = $basename."_Def" . $suffix . ".gdml";
291  push (@gdmlFiles, $DEF);
292  $DEF = ">" . $DEF;
293  open(DEF) or die("Could not open file $DEF for writing");
294 
295 
296 print DEF <<EOF;
297 <?xml version='1.0'?>
298 <gdml>
299 <define>
300 
301 <!--
302 
303 
304 
305 -->
306 
307  <position name="posCryoInDetEnc" unit="cm" x="0" y="$posCryoInDetEnc_y" z="0"/>
308  <position name="posCenter" unit="cm" x="0" y="0" z="0"/>
309  <rotation name="rPlus90AboutX" unit="deg" x="90" y="0" z="0"/>
310  <rotation name="rPlus90AboutY" unit="deg" x="0" y="90" z="0"/>
311  <rotation name="rPlus90AboutXPlus90AboutY" unit="deg" x="90" y="90" z="0"/>
312  <rotation name="rMinus90AboutX" unit="deg" x="270" y="0" z="0"/>
313  <rotation name="rMinus90AboutY" unit="deg" x="0" y="270" z="0"/>
314  <rotation name="rMinus90AboutYMinus90AboutX" unit="deg" x="270" y="270" z="0"/>
315  <rotation name="rPlus180AboutX" unit="deg" x="180" y="0" z="0"/>
316  <rotation name="rPlus180AboutY" unit="deg" x="0" y="180" z="0"/>
317  <rotation name="rPlus180AboutXPlus180AboutY" unit="deg" x="180" y="180" z="0"/>
318  <rotation name="rIdentity" unit="deg" x="0" y="0" z="0"/>
319 </define>
320 </gdml>
321 EOF
322  close (DEF);
323 }
324 
325 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
326 #+++++++++++++++++++++++++++++++++++++ gen_Materials +++++++++++++++++++++++++++++++++++++
327 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
328 
329 sub gen_Materials()
330 {
331 
332 # Create the <materials> fragment file name,
333 # add file to list of output GDML fragments,
334 # and open it
335  $MAT = $basename."_Materials" . $suffix . ".gdml";
336  push (@gdmlFiles, $MAT);
337  $MAT = ">" . $MAT;
338 
339  open(MAT) or die("Could not open file $MAT for writing");
340 
341  # Add any materials special to this geometry by defining a mulitline string
342  # and passing it to the gdmlMaterials::gen_Materials() function.
343 my $asmix = <<EOF;
344  <!-- preliminary values -->
345  <material name="AirSteelMixture" formula="AirSteelMixture">
346  <D value=" @{[0.001205*(1-$FracMassOfSteel) + 7.9300*$FracMassOfSteel]} " unit="g/cm3"/>
347  <fraction n="$FracMassOfSteel" ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
348  <fraction n="$FracMassOfAir" ref="Air"/>
349  </material>
350 EOF
351 
352  # add the general materials used anywere
353  print MAT gdmlMaterials::gen_Materials( $asmix );
354 
355  close(MAT);
356 }
357 
358 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
359 #++++++++++++++++++++++++++++++++++++++++ gen_TPC ++++++++++++++++++++++++++++++++++++++++
360 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
361 sub gen_TPC()
362 {
363  # CRM active volume
364  my $TPCActive_x = $widthCRM_active;
365  my $TPCActive_y = $driftTPCActive;
366  my $TPCActive_z = $lengthCRM_active;
367 
368  # CRM total volume
369  my $TPC_x = $widthCRM;
370  my $TPC_y = $TPCActive_y + $ReadoutPlane;
371  my $TPC_z = $lengthCRM;
372 
373 
374  $TPC = $basename."_TPC" . $suffix . ".gdml";
375  push (@gdmlFiles, $TPC);
376  $TPC = ">" . $TPC;
377  open(TPC) or die("Could not open file $TPC for writing");
378 
379 # The standard XML prefix and starting the gdml
380  print TPC <<EOF;
381 <?xml version='1.0'?>
382 <gdml>
383 EOF
384 
385 
386  # All the TPC solids save the wires.
387  print TPC <<EOF;
388 <solids>
389  <box name="CRM" lunit="cm"
390  x="$TPC_x"
391  y="$TPC_y"
392  z="$TPC_z"/>
393  <box name="CRMXPlane" lunit="cm"
394  x="$TPCActive_x"
395  y="$padWidth"
396  z="$TPCActive_z"/>
397  <box name="CRMZPlane" lunit="cm"
398  x="$TPCActive_x"
399  y="$padWidth"
400  z="$TPCActive_z"/>
401  <box name="CRMActive" lunit="cm"
402  x="$TPCActive_x"
403  y="$TPCActive_y"
404  z="$TPCActive_z"/>
405 EOF
406 
407 
408 #++++++++++++++++++++++++++++ Wire Solids ++++++++++++++++++++++++++++++
409 # in principle we only need only one wire solid, since CRM is a square
410 # but to be more general ...
411 
412 print TPC <<EOF;
413 
414  <tube name="CRMWireX"
415  rmax="@{[0.5*$padWidth]}"
416  z="$TPCActive_z"
417  deltaphi="360"
418  aunit="deg"
419  lunit="cm"/>
420  <tube name="CRMWireZ"
421  rmax="@{[0.5*$padWidth]}"
422  z="$TPCActive_x"
423  deltaphi="360"
424  aunit="deg"
425  lunit="cm"/>
426 </solids>
427 
428 EOF
429 
430 
431 # Begin structure and create wire logical volumes
432 print TPC <<EOF;
433 <structure>
434  <volume name="volTPCActive">
435  <materialref ref="LAr"/>
436  <solidref ref="CRMActive"/>
437  <auxiliary auxtype="SensDet" auxvalue="SimEnergyDeposit"/>
438  </volume>
439 EOF
440 
441 if ($wires_on==1)
442 {
443  print TPC <<EOF;
444  <volume name="volTPCWireX">
445  <materialref ref="Copper_Beryllium_alloy25"/>
446  <solidref ref="CRMWireX"/>
447  </volume>
448 
449  <volume name="volTPCWireZ">
450  <materialref ref="Copper_Beryllium_alloy25"/>
451  <solidref ref="CRMWireZ"/>
452  </volume>
453 EOF
454 }
455 
456 print TPC <<EOF;
457 
458  <volume name="volTPCPlaneX">
459  <materialref ref="LAr"/>
460  <solidref ref="CRMXPlane"/>
461 EOF
462 
463 if ($wires_on==1) # add wires to X plane (plane with wires reading x position)
464 {
465 for($i=0;$i<$nChannelsWidthPerCRM;++$i)
466 {
467 my $xpos = -0.5 * $TPCActive_x + ($i+0.5)*$wirePitch + 0.5*$padWidth;
468 
469 print TPC <<EOF;
470  <physvol>
471  <volumeref ref="volTPCWireX"/>
472  <position name="posWireX$i" unit="cm" x="$xpos" y="0" z="0"/>
473  <rotationref ref="rIdentity"/>
474  </physvol>
475 EOF
476 }
477 }
478 
479 print TPC <<EOF;
480  </volume>
481 
482  <volume name="volTPCPlaneZ">
483  <materialref ref="LAr"/>
484  <solidref ref="CRMZPlane"/>
485 EOF
486 
487 
488 if ($wires_on==1) # add wires to Z plane (plane with wires reading z position)
489 {
490 for($i=0;$i<$nChannelsLengthPerCRM;++$i)
491 {
492 
493 my $zpos = -0.5 * $TPCActive_z + ($i+0.5)*$wirePitch + 0.5*$padWidth;
494 print TPC <<EOF;
495  <physvol>
496  <volumeref ref="volTPCWireZ"/>
497  <position name="posWireZ$i" unit="cm" x="0" y="0" z="$zpos"/>
498  <rotationref ref="rPlus90AboutXPlus90AboutY"/>
499  </physvol>
500 EOF
501 }
502 }
503 
504 
505 print TPC <<EOF;
506  </volume>
507 EOF
508 
509 
510 $posXplane[0] = 0;
511 $posXplane[1] = 0.5*$TPC_y - 1.5*$padWidth;
512 $posXplane[2] = 0;
513 
514 $posZplane[0] = 0;
515 $posZplane[1] = 0.5*$TPC_y - 0.5*$padWidth;
516 $posZplane[2] = 0;
517 
518 $posTPCActive[0] = 0;
519 $posTPCActive[1] = -$ReadoutPlane;
520 $posTPCActive[2] = 0;
521 
522 
523 #wrap up the TPC file
524 print TPC <<EOF;
525 
526  <volume name="volTPC">
527  <materialref ref="LAr"/>
528  <solidref ref="CRM"/>
529  <physvol>
530  <volumeref ref="volTPCPlaneX"/>
531  <position name="posPlaneX" unit="cm"
532  x="$posXplane[0]" y="$posXplane[1]" z="$posXplane[2]"/>
533  <rotationref ref="rIdentity"/>
534  </physvol>
535  <physvol>
536  <volumeref ref="volTPCPlaneZ"/>
537  <position name="posPlaneZ" unit="cm"
538  x="$posZplane[0]" y="$posZplane[1]" z="$posZplane[2]"/>
539  <rotationref ref="rIdentity"/>
540  </physvol>
541  <physvol>
542  <volumeref ref="volTPCActive"/>
543  <position name="posActive" unit="cm"
544  x="$posTPCActive[0]" y="@{[$posTPCActive[1]+$padWidth]}" z="$posTPCActive[2]"/>
545  <rotationref ref="rIdentity"/>
546  </physvol>
547  </volume>
548 EOF
549 
550 
551 print TPC <<EOF;
552 </structure>
553 </gdml>
554 EOF
555 
556 close(TPC);
557 }
558 
559 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
560 #++++++++++++++++++++++++++++++++++++++ gen_FieldCage +++++++++++++++++++++++++++++++++++++
561 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
562 
563 sub gen_FieldCage {
564 
565  $FieldCage = $basename."_FieldCage" . $suffix . ".gdml";
566  push (@gdmlFiles, $FieldCage);
567  $FieldCage = ">" . $FieldCage;
568  open(FieldCage) or die("Could not open file $FieldCage for writing");
569 
570 # The standard XML prefix and starting the gdml
571 print FieldCage <<EOF;
572  <?xml version='1.0'?>
573  <gdml>
574 EOF
575 # The printing solids used in the Field Cage
576 #print "lengthTPCActive : $lengthTPCActive \n";
577 #print "widthTPCActive : $widthTPCActive \n";
578 
579 
580 print FieldCage <<EOF;
581 <solids>
582  <torus name="FieldShaperCorner" rmin="$FieldShaperInnerRadius" rmax="$FieldShaperOuterRadius" rtor="$FieldShaperTorRad" deltaphi="90" startphi="0" aunit="deg" lunit="cm"/>
583  <tube name="FieldShaperLongtube" rmin="$FieldShaperInnerRadius" rmax="$FieldShaperOuterRadius" z="$FieldShaperLongTubeLength" deltaphi="360" startphi="0" aunit="deg" lunit="cm"/>
584  <tube name="FieldShaperShorttube" rmin="$FieldShaperInnerRadius" rmax="$FieldShaperOuterRadius" z="$FieldShaperShortTubeLength" deltaphi="360" startphi="0" aunit="deg" lunit="cm"/>
585 
586  <union name="FSunion1">
587  <first ref="FieldShaperLongtube"/>
588  <second ref="FieldShaperCorner"/>
589  <position name="esquinapos1" unit="cm" x="@{[-$FieldShaperTorRad]}" y="0" z="@{[0.5*$FieldShaperLongTubeLength]}"/>
590  <rotation name="rot1" unit="deg" x="90" y="0" z="0" />
591  </union>
592 
593  <union name="FSunion2">
594  <first ref="FSunion1"/>
595  <second ref="FieldShaperShorttube"/>
596  <position name="esquinapos2" unit="cm" x="@{[-0.5*$FieldShaperShortTubeLength-$FieldShaperTorRad]}" y="0" z="@{[+0.5*$FieldShaperLongTubeLength+$FieldShaperTorRad]}"/>
597  <rotation name="rot2" unit="deg" x="0" y="90" z="0" />
598  </union>
599 
600  <union name="FSunion3">
601  <first ref="FSunion2"/>
602  <second ref="FieldShaperCorner"/>
603  <position name="esquinapos3" unit="cm" x="@{[-$FieldShaperShortTubeLength-$FieldShaperTorRad]}" y="0" z="@{[0.5*$FieldShaperLongTubeLength]}"/>
604  <rotation name="rot3" unit="deg" x="90" y="270" z="0" />
605  </union>
606 
607  <union name="FSunion4">
608  <first ref="FSunion3"/>
609  <second ref="FieldShaperLongtube"/>
610  <position name="esquinapos4" unit="cm" x="@{[-$FieldShaperShortTubeLength-2*$FieldShaperTorRad]}" y="0" z="0"/>
611  </union>
612 
613  <union name="FSunion5">
614  <first ref="FSunion4"/>
615  <second ref="FieldShaperCorner"/>
616  <position name="esquinapos5" unit="cm" x="@{[-$FieldShaperShortTubeLength-$FieldShaperTorRad]}" y="0" z="@{[-0.5*$FieldShaperLongTubeLength]}"/>
617  <rotation name="rot5" unit="deg" x="90" y="180" z="0" />
618  </union>
619 
620  <union name="FSunion6">
621  <first ref="FSunion5"/>
622  <second ref="FieldShaperShorttube"/>
623  <position name="esquinapos6" unit="cm" x="@{[-0.5*$FieldShaperShortTubeLength-$FieldShaperTorRad]}" y="0" z="@{[-0.5*$FieldShaperLongTubeLength-$FieldShaperTorRad]}"/>
624  <rotation name="rot6" unit="deg" x="0" y="90" z="0" />
625  </union>
626 
627  <union name="FieldShaperSolid">
628  <first ref="FSunion6"/>
629  <second ref="FieldShaperCorner"/>
630  <position name="esquinapos7" unit="cm" x="@{[-$FieldShaperTorRad]}" y="0" z="@{[-0.5*$FieldShaperLongTubeLength]}"/>
631  <rotation name="rot7" unit="deg" x="90" y="90" z="0" />
632  </union>
633 </solids>
634 
635 EOF
636 
637 print FieldCage <<EOF;
638 
639 <structure>
640 <volume name="volFieldShaper">
641  <materialref ref="Al2O3"/>
642  <solidref ref="FieldShaperSolid"/>
643 </volume>
644 </structure>
645 
646 EOF
647 
648 print FieldCage <<EOF;
649 
650 </gdml>
651 EOF
652 close(FieldCage);
653 }
654 
655 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
656 #++++++++++++++++++++++++++++++++++++++ gen_Cathode +++++++++++++++++++++++++++++++++++++
657 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
658 
659 sub gen_Cathode {
660 
661  $Cathode = $basename."_Cathode" . $suffix . ".gdml";
662  push (@gdmlFiles, $Cathode);
663  $Cathode = ">" . $Cathode;
664  open(Cathode) or die("Could not open file $Cathode for writing");
665 
666 # The standard XML prefix and starting the gdml
667 print Cathode <<EOF;
668  <?xml version='1.0'?>
669  <gdml>
670 EOF
671 
672 print Cathode <<EOF;
673 
674 <solids>
675  <tube name="solCathodeCable" rmin="0" rmax="@{[$CathodeCableRadius]}" z="@{[$CathodeCableLength]}" deltaphi="360" startphi="0" aunit="deg" lunit="cm"/>
676  <box name="solCathode" x="@{[$CathodeWidth]}" y="@{[$CathodeHeight]}" z="@{[$CathodeLength]}" lunit="cm"/>
677 
678 </solids>
679 
680 EOF
681 
682 print Cathode <<EOF;
683 
684 
685 <structure>
686 <volume name="volCathodeCable">
687  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
688  <solidref ref="solCathodeCable"/>
689 </volume>
690 
691 <volume name="volCathode">
692  <materialref ref="LAr"/>
693  <solidref ref="solCathode"/>
694 
695  <physvol>
696  <volumeref ref="volFieldShaper"/>
697  <position name="posFS" unit="cm" x="@{[0.5*$FieldShaperShortTubeLength+$FieldShaperTorRad]}" y="@{[0]}" z="@{[0]}"/>
698  </physvol>
699 EOF
700 for($ii=0;$ii<$CathodeNumberOfCables;$ii++)
701 {
702  print Cathode <<EOF;
703  <physvol>
704  <volumeref ref="volCathodeCable"/>
705  <position name="posCathodeCable$ii" unit="cm" x="@{[0]}" y="@{[0]}" z="@{[-0.5*$CathodeCableSeparation*$CathodeNumberOfCables+($ii)*$CathodeCableSeparation]}"/>
706  <rotation name="rotCC$ii" unit="deg" x="0" y="90" z="0" />
707  </physvol>
708 EOF
709 
710 }
711 print Cathode <<EOF;
712 </volume>
713 </structure>
714 
715 EOF
716 
717 print Cathode <<EOF;
718 
719 </gdml>
720 EOF
721 close(Cathode);
722 }
723 
724 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
725 #++++++++++++++++++++++++++++++++++++++ gen_pmt +++++++++++++++++++++++++++++++++++++
726 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
727 
728 sub gen_pmt {
729 
730 
731 #PMTs
732 
733 #$PMT_COATING_THICKNESS=0.2;
734 #$PMT_PLATE_THICKNESS=0.4;
735 #$PMT_GLASS_THICKNESS=0.2;
736 
737  $PMT = $basename."_PMT" . $suffix . ".gdml";
738  push (@gdmlFiles, $PMT);
739  $PMT = ">" . $PMT;
740  open(PMT) or die("Could not open file $PMT for writing");
741 
742 
743  print PMT <<EOF;
744 
745 <solids>
746  <tube name="PMTVolume"
747  rmax="(6.5*2.54)"
748  z="(11.1*2.54)"
749  deltaphi="360"
750  aunit="deg"
751  lunit="cm"/>
752 
753  <tube name="PMT_AcrylicPlate"
754  rmax="11.4"
755  z="0.4"
756  deltaphi="360"
757  aunit="deg"
758  lunit="cm"/>
759 
760  <tube name="PMT_plate_coat"
761  rmax="11.4"
762  z="0.02"
763  deltaphi="360"
764  aunit="deg"
765  lunit="cm"/>
766 
767 
768  <tube aunit="deg" deltaphi="360" lunit="mm" name="pmtMiddleCylinder" rmax="102.351822048586" rmin="100.351822048586" startphi="0" z="54"/>
769  <sphere aunit="deg" deltaphi="360" deltatheta="50" lunit="mm" name="sphPartTop" rmax="133" rmin="131" startphi="0" starttheta="0"/>
770  <union name="pmt0x7fb8f489dfe0">
771  <first ref="pmtMiddleCylinder"/>
772  <second ref="sphPartTop"/>
773  <position name="pmt0x7fb8f489dfe0_pos" unit="mm" x="0" y="0" z="-57.2051768689367"/>
774  </union>
775  <sphere aunit="deg" deltaphi="360" deltatheta="31.477975238527" lunit="mm" name="sphPartBtm" rmax="133" rmin="131" startphi="0" starttheta="130"/>
776  <union name="pmt0x7fb8f48a0d50">
777  <first ref="pmt0x7fb8f489dfe0"/>
778  <second ref="sphPartBtm"/>
779  <position name="pmt0x7fb8f48a0d50_pos" unit="mm" x="0" y="0" z="57.2051768689367"/>
780  </union>
781  <tube aunit="deg" deltaphi="360" lunit="mm" name="pmtBtmTube" rmax="44.25" rmin="42.25" startphi="0" z="72"/>
782  <union name="solidpmt">
783  <first ref="pmt0x7fb8f48a0d50"/>
784  <second ref="pmtBtmTube"/>
785  <position name="solidpmt_pos" unit="mm" x="0" y="0" z="-104.905637496842"/>
786  </union>
787  <sphere aunit="deg" deltaphi="360" deltatheta="50" lunit="mm" name="pmt0x7fb8f48a1eb0" rmax="133.2" rmin="133" startphi="0" starttheta="0"/>
788  <sphere aunit="deg" deltaphi="360" deltatheta="46.5" lunit="mm" name="pmt0x7fb8f48a4860" rmax="131" rmin="130.999" startphi="0" starttheta="0"/>
789 
790 
791 </solids>
792 
793 <structure>
794 
795  <volume name="volPMTplatecoat">
796  <materialref ref="TPB"/>
797  <solidref ref="PMT_plate_coat"/>
798  <auxiliary auxtype="SensDet" auxvalue="PhotonDetector"/>
799  </volume>
800 
801  <volume name="vol_PMT_AcrylicPlate">
802  <materialref ref="Acrylic"/>
803  <solidref ref="PMT_AcrylicPlate"/>
804  </volume>
805 
806  <volume name="pmtCoatVol">
807  <materialref ref="TPB"/>
808  <solidref ref="pmt0x7fb8f48a1eb0"/>
809  <auxiliary auxtype="SensDet" auxvalue="PhotonDetector"/>
810  </volume>
811 
812  <volume name="allpmt">
813  <materialref ref="Glass"/>
814  <solidref ref="solidpmt"/>
815  </volume>
816 
817 
818 
819  <volume name="volPMT_plate">
820  <materialref ref="LAr"/>
821  <solidref ref="PMTVolume"/>
822 
823  <physvol>
824  <volumeref ref="allpmt"/>
825  <position name="posallpmt" unit="cm" x="0" y="0" z="1.27*2.54+2.5"/>
826  </physvol>
827 
828  <physvol name="volOpDetSensitive">
829  <volumeref ref="volPMTplatecoat"/>
830  <position name="posOpDetSensitive" unit="cm" x="0" y="0" z="1.27*2.54+2.5*2.54 + 1.7+2.5"/>
831  </physvol>
832 
833  <physvol>
834  <volumeref ref="vol_PMT_AcrylicPlate"/>
835  <position name="pos_PMT_AcrylicPlate" unit="cm" x="0" y="0" z="1.27*2.54+2.5*2.54 + 1.5+2.5"/>
836  </physvol>
837  </volume>
838 
839 <volume name="volPMT_coated">
840  <materialref ref="LAr"/>
841  <solidref ref="PMTVolume"/>
842 
843  <physvol>
844  <volumeref ref="allpmt"/>
845  <position name="posallpmt" unit="cm" x="0" y="0" z="1.27*2.54+2.5"/>
846  </physvol>
847 
848  <physvol name="volOpDetSensitive">
849  <volumeref ref="pmtCoatVol"/>
850  <position name="posOpDetSensitive" unit="cm" x="0" y="0" z="1.27*2.54- (2.23*2.54)+2.5"/>
851  </physvol>
852 
853  </volume>
854 
855 </structure>
856 
857 EOF
858 }
859 
860 
861 
862 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
863 #++++++++++++++++++++++++++++++++++++++ gen_ExtractionGrid +++++++++++++++++++++++++++++++++++
864 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
865 
866 sub gen_ExtractionGrid {
867 
868  $ExtractionGrid = $basename."_ExtractionGrid" . $suffix . ".gdml";
869  push (@gdmlFiles, $ExtractionGrid);
870  $ExtractionGrid = ">" . $ExtractionGrid;
871  open(ExtractionGrid) or die("Could not open file $ExtractionGrid for writing");
872 
873 # The standard XML prefix and starting the gdml
874 print ExtractionGrid <<EOF;
875 <?xml version='1.0'?>
876 <gdml>
877 EOF
878 
879 $ExtractionGridRadius = 0.05;
880 $ExtractionGridPitch = 0.3;
881 
882 $ExtractionGridSizeX = $widthTPCActive;
883 $ExtractionGridSizeY = 2*$ExtractionGridRadius;
884 $ExtractionGridSizeZ = $lengthTPCActive;
885 
886 
887 print ExtractionGrid <<EOF;
888 
889 <solids>
890  <tube name="solExtractionGridCable" rmin="0" rmax="$ExtractionGridRadius" z="$ExtractionGridSizeZ" deltaphi="360" startphi="0" aunit="deg" lunit="cm"/>
891  <box name="solExtractionGrid" x="@{[$ExtractionGridSizeX]}" y="@{[$ExtractionGridSizeY]}" z="@{[$ExtractionGridSizeZ]}" lunit="cm"/>
892 </solids>
893 
894 EOF
895 
896 
897 print ExtractionGrid <<EOF;
898 
899 <structure>
900 
901 <volume name="volExtractionGridCable">
902  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
903  <solidref ref="solExtractionGridCable"/>
904 </volume>
905 
906 <volume name="volExtractionGrid">
907  <materialref ref="LAr"/>
908  <solidref ref="solExtractionGrid"/>
909 EOF
910 
911 for($ii=0;$ii<$$ExtractionGridSizeX;$ii=$ii+$ExtractionGridPitch)
912 {
913  print ExtractionGrid <<EOF;
914  <physvol>
915  <volumeref ref="volExtractionGridCable"/>
916  <position name="posExtractionGridCable$ii" unit="cm" x="@{[$ii-0.5*$ExtractionGridSizeX]}" y="0" z="0"/>
917  <rotation name="GGrot$aux2" unit="deg" x="90" y="0" z="0" />
918  </physvol>
919 EOF
920 
921 }
922 
923 for($jj=0;$jj<$$ExtractionGridSizeZ;$jj=$jj+$ExtractionGridPitch)
924 {
925  print ExtractionGrid <<EOF;
926  <physvol>
927  <volumeref ref="volExtractionGridCable"/>
928  <position name="posExtractionGridCableLat$jj" unit="cm" x="0" y="0" z="@{[$jj-0.5*$ExtractionGridSizeZ]}"/>
929  <rotation name="GGrot$aux2" unit="deg" x="90" y="0" z="0" />
930  </physvol>
931 EOF
932 
933 }
934 
935  print ExtractionGrid <<EOF;
936 
937  </volume>
938 </structure>
939 </gdml>
940 EOF
941 close(ExtractionGrid);
942 }
943 
944 
945 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
946 #++++++++++++++++++++++++++++++++++++++ gen_LEMs +++++++++++++++++++++++++++++++++++++
947 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
948 
949 sub gen_LEMs {
950 
951 
952  $LEMs = $basename."_LEMs" . $suffix . ".gdml";
953  push (@gdmlFiles, $LEMs);
954  $LEMs = ">" . $LEMs;
955  open(LEMs) or die("Could not open file $LEMs for writing");
956 
957 # The standard XML prefix and starting the gdml
958 print LEMs <<EOF;
959 <?xml version='1.0'?>
960 <gdml>
961 EOF
962 
963 $LEMsSizeX=$widthTPCActive;
964 $LEMsSizeY=0.1;
965 $LEMsSizeZ=$lengthTPCActive;
966 
967 print LEMs <<EOF;
968 
969 <solids>
970  <box name="solLEMs" x="@{[$LEMsSizeX]}" y="$LEMsSizeY" z="@{[$LEMsSizeZ]}" lunit="cm"/>
971 
972 </solids>
973 
974 EOF
975 print LEMs <<EOF;
976 
977 
978 <structure>
979  <volume name="volLEMs">
980  <materialref ref="Copper_Beryllium_alloy25"/>
981  <solidref ref="solLEMs"/>
982  </volume>
983 </structure>
984 </gdml>
985 EOF
986 close(LEMs);
987 }
988 
989 
990 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
991 #++++++++++++++++++++++++++++++++++++++ gen_Cryostat +++++++++++++++++++++++++++++++++++++
992 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
993 
994 sub gen_Cryostat()
995 {
996 
997 # Create the cryostat fragment file name,
998 # add file to list of output GDML fragments,
999 # and open it
1000  $CRYO = $basename."_Cryostat" . $suffix . ".gdml";
1001  push (@gdmlFiles, $CRYO);
1002  $CRYO = ">" . $CRYO;
1003  open(CRYO) or die("Could not open file $CRYO for writing");
1004 
1005 
1006 # The standard XML prefix and starting the gdml
1007  print CRYO <<EOF;
1008 <?xml version='1.0'?>
1009 <gdml>
1010 EOF
1011 
1012 # All the cryostat solids.
1013 print CRYO <<EOF;
1014 <solids>
1015  <box name="Cryostat" lunit="cm"
1016  x="$Cryostat_x"
1017  y="$Cryostat_y"
1018  z="$Cryostat_z"/>
1019 
1020  <box name="ArgonInterior" lunit="cm"
1021  x="$Argon_x"
1022  y="$Argon_y"
1023  z="$Argon_z"/>
1024 
1025  <box name="GaseousArgon" lunit="cm"
1026  x="$Argon_x"
1027  y="$HeightGaseousAr"
1028  z="$Argon_z"/>
1029 
1030  <subtraction name="SteelShell">
1031  <first ref="Cryostat"/>
1032  <second ref="ArgonInterior"/>
1033  </subtraction>
1034 
1035 </solids>
1036 EOF
1037 
1038 # Cryostat structure
1039 print CRYO <<EOF;
1040 <structure>
1041  <volume name="volSteelShell">
1042  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni" />
1043  <solidref ref="SteelShell" />
1044  </volume>
1045  <volume name="volGaseousArgon">
1046  <materialref ref="ArGas"/>
1047  <solidref ref="GaseousArgon"/>
1048 EOF
1049  if ( $LEMs_switch eq "on" )
1050  {
1051 $posLEMsX = 0;
1052 $posLEMsY = -0.5*$HeightGaseousAr+0.5+0.5*$LEMsSizeY;
1053 $posLEMsZ = 0;
1054 
1055  print CRYO <<EOF;
1056  <physvol>
1057  <volumeref ref="volLEMs"/>
1058  <position name="posLEMs" unit="cm" x="$posLEMsX" y="$posLEMsY" z="$posLEMsZ"/>
1059  </physvol>
1060 EOF
1061  }
1062 
1063  print CRYO <<EOF;
1064  </volume>
1065 
1066  <volume name="volCryostat">
1067  <materialref ref="LAr" />
1068  <solidref ref="Cryostat" />
1069  <physvol>
1070  <volumeref ref="volGaseousArgon"/>
1071  <position name="posGaseousArgon" unit="cm" x="0" y="$Argon_y/2-$HeightGaseousAr/2" z="0"/>
1072  </physvol>
1073  <physvol>
1074  <volumeref ref="volSteelShell"/>
1075  <position name="posSteelShell" unit="cm" x="0" y="0" z="0"/>
1076  </physvol>
1077 EOF
1078 
1079 
1080 if ($tpc_on==1) # place TPC inside croysotat
1081 {
1082 
1083 $posY = $Argon_y/2 - $HeightGaseousAr - 0.5*($driftTPCActive + $ReadoutPlane);
1084 for($ii=0;$ii<$nCRM_z;$ii++)
1085 {
1086  $posZ = -0.5*$Argon_z + $zLArBuffer + ($ii+0.5)*$lengthCRM;
1087 
1088  for($jj=0;$jj<$nCRM_x;$jj++)
1089  {
1090  $posX = -0.5*$Argon_x + $xLArBuffer + ($jj+0.5)*$widthCRM;
1091  print CRYO <<EOF;
1092  <physvol>
1093  <volumeref ref="volTPC"/>
1094  <position name="posTPC\-$ii\-$jj" unit="cm"
1095  x="$posX" y="$posY" z="$posZ"/>
1096  </physvol>
1097 EOF
1098  }
1099 }
1100 
1101 }
1102 
1103 
1104  if ( $pmt_switch eq "on" ) {
1105  for ( $i=0; $i<5; $i=$i+1 ) { # pmts with coating
1106  print CRYO <<EOF;
1107  <physvol>
1108 EOF
1109  if ( $i eq "1" || $i eq "3") {
1110  print CRYO <<EOF;
1111  <volumeref ref="volPMT_plate"/>
1112 EOF
1113  }
1114  else {
1115  print CRYO <<EOF;
1116  <volumeref ref="volPMT_coated"/>
1117 EOF
1118  }
1119  print CRYO <<EOF;
1120 
1121  <position name="posPMT$i" unit="cm" @pmt_pos[$i]/>
1122  <rotationref ref="rPlus90AboutX"/>
1123  </physvol>
1124 EOF
1125  }
1126 
1127 
1128  }
1129 
1130 #The +50 in the y positions must depend on some other parameter
1131  if ( $FieldCage_switch eq "on" ) {
1132  for ( $i=0; $i<$NFieldShapers; $i=$i+1 ) { # pmts with coating
1133 $posY = $Argon_y/2 - $HeightGaseousAr - 0.5*($driftTPCActive + $ReadoutPlane);
1134 
1135  print CRYO <<EOF;
1136  <physvol>
1137  <volumeref ref="volFieldShaper"/>
1138  <position name="posFieldShaper$i" unit="cm" x="@{[-1*(-0.5*$FieldShaperShortTubeLength-$FieldShaperTorRad)]}" y="@{[$FFSPositionHeight-$i*$FieldShaperSeparation]}" z="0" />
1139  <rotation name="rotFS$i" unit="deg" x="0" y="0" z="0" />
1140  </physvol>
1141 EOF
1142  }
1143  }
1144 
1145  if ( $Cathode_switch eq "on" ) {
1146 $posY = $Argon_y/2 - $HeightGaseousAr - 0.5*($driftTPCActive + $ReadoutPlane);
1147  print CRYO <<EOF;
1148  <physvol>
1149  <volumeref ref="volCathode"/>
1150  <position name="posCathode" unit="cm" x="@{[0]}" y="@{[$CathodePositionHeight]}" z="0" />
1151  <rotation name="rotCath" unit="deg" x="0" y="0" z="0" />
1152  </physvol>
1153 EOF
1154  }
1155 
1156  if ( $GroundGrid_switch eq "on" ) {
1157 $posY = $Argon_y/2 - $HeightGaseousAr - 0.5*($driftTPCActive + $ReadoutPlane);
1158  print CRYO <<EOF;
1159  <physvol>
1160  <volumeref ref="volCathode"/>
1161  <position name="posGroundGrid" unit="cm" x="@{[0]}" y="@{[$GroundGridPositionHeight]}" z="0" />
1162  <rotation name="rotGroundGrid" unit="deg" x="0" y="0" z="0" />
1163  </physvol>
1164 EOF
1165  }
1166 
1167  if ( $ExtractionGrid_switch eq "on" )
1168  {
1169 
1170 $ExtractionGridX = 0;
1171 $ExtractionGridY = 0.5*$Argon_y-$HeightGaseousAr-0.5-0.5*$ExtractionGridSizeY;
1172 $ExtractionGridZ = 0;
1173 
1174  print CRYO <<EOF;
1175  <physvol>
1176  <volumeref ref="volExtractionGrid"/>
1177  <position name="posExtractionGrid" unit="cm" x="$ExtractionGridX" y="$ExtractionGridY" z="$ExtractionGridZ"/>
1178 
1179  </physvol>
1180 EOF
1181 
1182  }
1183 
1184 
1185  print CRYO <<EOF;
1186  </volume>
1187 </structure>
1188 </gdml>
1189 EOF
1190 
1191 
1192 close(CRYO);
1193 }
1194 
1195 
1196 
1197 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1198 #+++++++++++++++++++++++++++++++++++++ gen_Enclosure +++++++++++++++++++++++++++++++++++++
1199 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1200 
1201 sub gen_Enclosure()
1202 {
1203 
1204 # Create the detector enclosure fragment file name,
1205 # add file to list of output GDML fragments,
1206 # and open it
1207  $ENCL = $basename."_DetEnclosure" . $suffix . ".gdml";
1208  push (@gdmlFiles, $ENCL);
1209  $ENCL = ">" . $ENCL;
1210  open(ENCL) or die("Could not open file $ENCL for writing");
1211 
1212 
1213 # The standard XML prefix and starting the gdml
1214  print ENCL <<EOF;
1215 <?xml version='1.0'?>
1216 <gdml>
1217 EOF
1218 
1219 
1220 # All the detector enclosure solids.
1221 print ENCL <<EOF;
1222 <solids>
1223 
1224  <box name="FoamPadBlock" lunit="cm"
1225  x="@{[$Cryostat_x + 2*$FoamPadding]}"
1226  y="@{[$Cryostat_y + 2*$FoamPadding]}"
1227  z="@{[$Cryostat_z + 2*$FoamPadding]}" />
1228 
1229  <subtraction name="FoamPadding">
1230  <first ref="FoamPadBlock"/>
1231  <second ref="Cryostat"/>
1232  <positionref ref="posCenter"/>
1233  </subtraction>
1234 
1235  <box name="SteelSupportBlock" lunit="cm"
1236  x="@{[$Cryostat_x + 2*$FoamPadding + 2*$SteelSupport_x]}"
1237  y="@{[$Cryostat_y + 2*$FoamPadding + 2*$SteelSupport_y]}"
1238  z="@{[$Cryostat_z + 2*$FoamPadding + 2*$SteelSupport_z]}" />
1239 
1240  <subtraction name="SteelSupport">
1241  <first ref="SteelSupportBlock"/>
1242  <second ref="FoamPadBlock"/>
1243  <positionref ref="posCenter"/>
1244  </subtraction>
1245 
1246  <box name="DetEnclosure" lunit="cm"
1247  x="$DetEncX"
1248  y="$DetEncY"
1249  z="$DetEncZ"/>
1250 
1251 </solids>
1252 EOF
1253 
1254 
1255 # Detector enclosure structure
1256  print ENCL <<EOF;
1257 <structure>
1258  <volume name="volFoamPadding">
1259  <materialref ref="foam_3x1x1dp"/>
1260  <solidref ref="FoamPadding"/>
1261  </volume>
1262 
1263  <volume name="volSteelSupport">
1264  <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
1265  <solidref ref="SteelSupport"/>
1266  </volume>
1267 
1268  <volume name="volDetEnclosure">
1269  <materialref ref="Air"/>
1270  <solidref ref="DetEnclosure"/>
1271 
1272  <physvol>
1273  <volumeref ref="volFoamPadding"/>
1274  <positionref ref="posCryoInDetEnc"/>
1275  </physvol>
1276  <physvol>
1277  <volumeref ref="volSteelSupport"/>
1278  <positionref ref="posCryoInDetEnc"/>
1279  </physvol>
1280  <physvol>
1281  <volumeref ref="volCryostat"/>
1282  <positionref ref="posCryoInDetEnc"/>
1283  </physvol>
1284 EOF
1285 
1286 
1287 print ENCL <<EOF;
1288  </volume>
1289 EOF
1290 
1291 print ENCL <<EOF;
1292 </structure>
1293 </gdml>
1294 EOF
1295 
1296 close(ENCL);
1297 }
1298 
1299 
1300 
1301 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1302 #+++++++++++++++++++++++++++++++++++++++ gen_World +++++++++++++++++++++++++++++++++++++++
1303 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1304 
1305 sub gen_World()
1306 {
1307 
1308 # Create the WORLD fragment file name,
1309 # add file to list of output GDML fragments,
1310 # and open it
1311  $WORLD = $basename."_World" . $suffix . ".gdml";
1312  push (@gdmlFiles, $WORLD);
1313  $WORLD = ">" . $WORLD;
1314  open(WORLD) or die("Could not open file $WORLD for writing");
1315 
1316 
1317 # The standard XML prefix and starting the gdml
1318  print WORLD <<EOF;
1319 <?xml version='1.0'?>
1320 <gdml>
1321 EOF
1322 
1323 
1324 # All the World solids.
1325 print WORLD <<EOF;
1326 <solids>
1327  <box name="World" lunit="cm"
1328  x="@{[$DetEncX+2*$AirThickness]}"
1329  y="@{[$DetEncY+2*$AirThickness]}"
1330  z="@{[$DetEncZ+2*$AirThickness]}"/>
1331 </solids>
1332 EOF
1333 
1334 # World structure
1335 print WORLD <<EOF;
1336 <structure>
1337  <volume name="volWorld" >
1338  <materialref ref="Air"/>
1339  <solidref ref="World"/>
1340 
1341  <physvol>
1342  <volumeref ref="volDetEnclosure"/>
1343  <position name="posDetEnclosure" unit="cm" x="$OriginXSet" y="$OriginYSet" z="$OriginZSet"/>
1344  </physvol>
1345 
1346  </volume>
1347 </structure>
1348 </gdml>
1349 EOF
1350 
1351 # make_gdml.pl will take care of <setup/>
1352 
1353 close(WORLD);
1354 }
1355 
1356 
1357 
1358 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1359 #++++++++++++++++++++++++++++++++++++ write_fragments ++++++++++++++++++++++++++++++++++++
1360 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1361 
1362 sub write_fragments()
1363 {
1364  # This subroutine creates an XML file that summarizes the the subfiles output
1365  # by the other sub routines - it is the input file for make_gdml.pl which will
1366  # give the final desired GDML file. Specify its name with the output option.
1367  # (you can change the name when running make_gdml)
1368 
1369  # This code is taken straigh from the similar MicroBooNE generate script, Thank you.
1370 
1371  if ( ! defined $output )
1372  {
1373  $output = "-"; # write to STDOUT
1374  }
1375 
1376  # Set up the output file.
1377  $OUTPUT = ">" . $output;
1378  open(OUTPUT) or die("Could not open file $OUTPUT");
1379 
1380  print OUTPUT <<EOF;
1381 <?xml version='1.0'?>
1382 
1383 <!-- Input to Geometry/gdml/make_gdml.pl; define the GDML fragments
1384  that will be zipped together to create a detector description.
1385  -->
1386 
1387 <config>
1388 
1389  <constantfiles>
1390 
1391  <!-- These files contain GDML <constant></constant>
1392  blocks. They are read in separately, so they can be
1393  interpreted into the remaining GDML. See make_gdml.pl for
1394  more information.
1395  -->
1396 
1397 EOF
1398 
1399  foreach $filename (@defFiles)
1400  {
1401  print OUTPUT <<EOF;
1402  <filename> $filename </filename>
1403 EOF
1404  }
1405 
1406  print OUTPUT <<EOF;
1407 
1408  </constantfiles>
1409 
1410  <gdmlfiles>
1411 
1412  <!-- The GDML file fragments to be zipped together. -->
1413 
1414 EOF
1415 
1416  foreach $filename (@gdmlFiles)
1417  {
1418  print OUTPUT <<EOF;
1419  <filename> $filename </filename>
1420 EOF
1421  }
1422 
1423  print OUTPUT <<EOF;
1424 
1425  </gdmlfiles>
1426 
1427 </config>
1428 EOF
1429 
1430  close(OUTPUT);
1431 }
1432 
1433 
1434 print "Some key parameters for dual-phase LAr TPC (unit cm unless noted otherwise)\n";
1435 print "CRM active area : $widthCRM_active x $lengthCRM_active\n";
1436 print "CRM total area : $widthCRM x $lengthCRM\n";
1437 print "TPC active volume : $driftTPCActive x $widthTPCActive x $lengthTPCActive\n";
1438 print "Argon buffer : ($xLArBuffer, $yLArBuffer, $zLArBuffer) \n";
1439 print "Detector enclosure : $DetEncX x $DetEncY x $DetEncZ\n";
1440 print "TPC Origin : ($OriginXSet, $OriginYSet, $OriginZSet) \n";
1441 print "PMTs : $pmt_switch \n";
1442 
1443 # run the sub routines that generate the fragments
1444 if ( $pmt_switch eq "on" ) { gen_pmt(); }
1445 if ( $FieldCage_switch eq "on" ) { gen_FieldCage(); }
1446 if ( $Cathode_switch eq "on" ) { gen_Cathode(); }
1447 if ( $ExtractionGrid_switch eq "on" ) { gen_ExtractionGrid(); }
1448 if ( $LEMs_switch eq "on" ) { gen_LEMs(); }
1449 
1450 
1451 gen_Define(); # generates definitions at beginning of GDML
1452 gen_Materials(); # generates materials to be used
1453 gen_TPC(); # generate TPC for a given unit CRM
1454 gen_Cryostat(); #
1455 gen_Enclosure(); #
1456 gen_World(); # places the enclosure among DUSEL Rock
1457 
1458 
1459 write_fragments(); # writes the XML input for make_gdml.pl
1460  # which zips together the final GDML
1461 exit;