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