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