5 # First attempt to make a GDML fragment generator for the DUNE vertical drift
6 # 10kt detector geometry with 3 views (2 orthogonal + induction at angle)
7 # The lower chamber is not added yet.
8 # !!!NOTE!!!: the readout is on a positive Y plane (drift along horizontal X)
9 # due to current reco limitations)
10 # No photon detectors declared
11 # Simplified treatment of inter-module dead spaces
13 # Created: Thu Oct 1 16:45:27 CEST 2020
14 # Vyacheslav Galymov <vgalymov@ipnl.in2p3.fr>
17 # VG: Added defs to enable use in the refactored sim framework
18 # VG: 23.02.21 Adjust plane dimensions to fit a given number of ch per side
19 # VG: 23.02.21 Group CRUs in CRPs
22 #################################################################################
24 # Each subroutine generates a fragment GDML file, and the last subroutine
25 # creates an XML file that make_gdml.pl will use to appropriately arrange
26 # the fragment GDML files to create the final desired DUNE GDML file,
27 # to be named by make_gdml output command
29 ##################################################################################
37 Math::BigFloat->precision(-16);
40 GetOptions( "help|h" => \$help,
41 "suffix|s:s" => \$suffix,
42 "output|o:s" => \$output,
43 "wires|w:s" => \$wires,
44 "workspace|k:s" => \$wkspc);
46 my $FieldCage_switch="off";
47 my $Cathode_switch="off";
51 # If the user requested help, print the usage notes and exit.
56 if ( ! defined $suffix )
58 # The user didn't supply a suffix, so append nothing to the file
64 # Otherwise, stick a "-" before the suffix, so that a suffix of
65 # "test" applied to filename.gdml becomes "filename-test.gdml".
66 $suffix = "-" . $suffix;
75 elsif ( $workspace != 0 )
77 print "\t\tCreating smaller workspace geometry.\n";
80 # set wires on to be the default, unless given an input by the user
81 $wires_on = 1; # 1=on, 0=off
91 ##################################################################
92 ############## Parameters for One Readout Panel ##################
94 # parameters for 1.5 x 1.7 sub-unit Charge Readout Module / Unit
95 #$widthPCBActive = 169.0; # cm
96 #$lengthPCBActive = 150.0; # cm
98 # views and channel counts
99 %nChans = ('Ind1', 256, 'Ind1Bot', 128, 'Ind2', 320, 'Col', 288);
100 $nViews = keys %nChans;
101 #print "$nViews %nChans\n";
103 # first induction view
104 $wirePitchU = 0.8695; # cm
105 $wireAngleU = 131.63; #-48.37; # deg
107 # second induction view
109 $widthPCBActive = 168.00; #$wirePitchY * $nChans{'Ind2'};
111 # last collection view
113 $lengthPCBActive = 148.9009; #$wirePitchZ * $nChans{'Col'};
116 $borderCRM = 0.0; # border space aroud each CRM
118 $widthCRM_active = $widthPCBActive;
119 $lengthCRM_active = $lengthPCBActive;
121 $widthCRM = $widthPCBActive + 2 * $borderCRM;
122 $lengthCRM = $lengthPCBActive + 2 * $borderCRM;
124 $borderCRP = 0.5; # cm
126 # number of CRMs in y and z
130 # create a smaller geometry
131 if( $workspace == 1 )
137 # create a smaller geometry
138 if( $workspace == 2 )
144 # create a smaller geometry
145 if( $workspace == 3 )
152 # calculate tpc area based on number of CRMs and their dimensions
153 # each CRP should have a 2x2 CRMs
154 $widthTPCActive = $nCRM_x * $widthCRM + $nCRM_x * $borderCRP; # around 1200 for full module
155 $lengthTPCActive = $nCRM_z * $lengthCRM + $nCRM_z * $borderCRP; # around 6000 for full module
157 # active volume dimensions
158 $driftTPCActive = 650.0;
160 # model anode strips as wires of some diameter
162 $ReadoutPlane = $nViews * $padWidth; # 3 readout planes (no space b/w)!
164 ##################################################################
165 ############## Parameters for TPC and inner volume ###############
167 # inner volume dimensions of the cryostat
172 # width of gas argon layer on top
173 $HeightGaseousAr = 100;
175 if( $workspace != 0 )
177 #active tpc + 1.0 m buffer on each side
178 $Argon_x = $driftTPCActive + $HeightGaseousAr + $ReadoutPlane + 100;
179 $Argon_y = $widthTPCActive + 200;
180 $Argon_z = $lengthTPCActive + 200;
184 # size of liquid argon buffer
185 $xLArBuffer = $Argon_x - $driftTPCActive - $HeightGaseousAr - $ReadoutPlane;
186 $yLArBuffer = 0.5 * ($Argon_y - $widthTPCActive);
187 $zLArBuffer = 0.5 * ($Argon_z - $lengthTPCActive);
190 $SteelThickness = 0.12; # membrane
192 $Cryostat_x = $Argon_x + 2*$SteelThickness;
193 $Cryostat_y = $Argon_y + 2*$SteelThickness;
194 $Cryostat_z = $Argon_z + 2*$SteelThickness;
196 ##################################################################
197 ############## DetEnc and World relevant parameters #############
199 $SteelSupport_x = 100;
200 $SteelSupport_y = 100;
201 $SteelSupport_z = 100;
203 $FracMassOfSteel = 0.5; #The steel support is not a solid block, but a mixture of air and steel
204 $FracMassOfAir = 1 - $FracMassOfSteel;
207 $SpaceSteelSupportToWall = 100;
208 $SpaceSteelSupportToCeiling = 100;
210 $DetEncX = $Cryostat_x
211 + 2*($SteelSupport_x + $FoamPadding) + $SpaceSteelSupportToCeiling;
213 $DetEncY = $Cryostat_y
214 + 2*($SteelSupport_y + $FoamPadding) + 2*$SpaceSteelSupportToWall;
216 $DetEncZ = $Cryostat_z
217 + 2*($SteelSupport_z + $FoamPadding) + 2*$SpaceSteelSupportToWall;
219 $posCryoInDetEnc_x = - $DetEncX/2 + $SteelSupport_x + $FoamPadding + $Cryostat_x/2;
222 $RockThickness = 4000;
224 # We want the world origin to be vertically centered on active TPC
225 # This is to be added to the x and y position of every volume in volWorld
227 $OriginXSet = $DetEncX/2.0
232 - $driftTPCActive/2.0;
234 $OriginYSet = $DetEncY/2.0
235 - $SpaceSteelSupportToWall
240 - $widthTPCActive/2.0;
242 # We want the world origin to be at the very front of the fiducial volume.
243 # move it to the front of the enclosure, then back it up through the concrete/foam,
244 # then through the Cryostat shell, then through the upstream dead LAr (including the
245 # dead LAr on the edge of the TPC)
246 # This is to be added to the z position of every volume in volWorld
248 $OriginZSet = $DetEncZ/2.0
249 - $SpaceSteelSupportToWall
256 ##################################################################
257 ############## Field Cage Parameters ###############
258 $FieldShaperLongTubeLength = $lengthTPCActive;
259 $FieldShaperShortTubeLength = $widthTPCActive;
260 $FieldShaperInnerRadius = 1.485;
261 $FieldShaperOuterRadius = 1.685;
262 $FieldShaperTorRad = 1.69;
264 $FieldShaperLength = $FieldShaperLongTubeLength + 2*$FieldShaperOuterRadius+ 2*$FieldShaperTorRad;
265 $FieldShaperWidth = $FieldShaperShortTubeLength + 2*$FieldShaperOuterRadius+ 2*$FieldShaperTorRad;
267 $FieldShaperSeparation = 5.0;
268 $NFieldShapers = ($driftTPCActive/$FieldShaperSeparation) - 1;
270 $FieldCageSizeX = $FieldShaperSeparation*$NFieldShapers+2;
271 $FieldCageSizeY = $FieldShaperWidth+2;
272 $FieldCageSizeZ = $FieldShaperLength+2;
275 #+++++++++++++++++++++++++ End defining variables ++++++++++++++++++++++++++
278 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
279 #+++++++++++++++++++++++++++++++++++++++++ usage +++++++++++++++++++++++++++++++++++++++++
280 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
284 print "Usage: $0 [-h|--help] [-o|--output <fragments-file>] [-s|--suffix <string>]\n";
285 print " if -o is omitted, output goes to STDOUT; <fragments-file> is input to make_gdml.pl\n";
286 print " -s <string> appends the string to the file names; useful for multiple detector versions\n";
287 print " -h prints this message, then quits\n";
294 # Create the <define> fragment file name,
295 # add file to list of fragments,
297 $DEF = $basename."_Ext" . $suffix . ".gdml";
298 push (@gdmlFiles, $DEF);
300 open(DEF) or die("Could not open file $DEF for writing");
303 <?xml version='1.0'?>
306 <color name="magenta" R="0.0" G="1.0" B="0.0" A="1.0" />
307 <color name="green" R="0.0" G="1.0" B="0.0" A="1.0" />
308 <color name="red" R="1.0" G="0.0" B="0.0" A="1.0" />
309 <color name="blue" R="0.0" G="0.0" B="1.0" A="1.0" />
310 <color name="yellow" R="1.0" G="1.0" B="0.0" A="1.0" />
317 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
318 #++++++++++++++++++++++++++++++++++++++ gen_Define +++++++++++++++++++++++++++++++++++++++
319 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
324 # Create the <define> fragment file name,
325 # add file to list of fragments,
327 $DEF = $basename."_Def" . $suffix . ".gdml";
328 push (@gdmlFiles, $DEF);
330 open(DEF) or die("Could not open file $DEF for writing");
334 <?xml version='1.0'?>
344 <position name="posCryoInDetEnc" unit="cm" x="$posCryoInDetEnc_x" y="0" z="0"/>
345 <position name="posCenter" unit="cm" x="0" y="0" z="0"/>
346 <rotation name="rUWireAboutX" unit="deg" x="$wireAngleU" y="0" z="0"/>
347 <rotation name="rPlus90AboutX" unit="deg" x="90" y="0" z="0"/>
348 <rotation name="rPlus90AboutY" unit="deg" x="0" y="90" z="0"/>
349 <rotation name="rPlus90AboutXPlus90AboutY" unit="deg" x="90" y="90" z="0"/>
350 <rotation name="rMinus90AboutX" unit="deg" x="270" y="0" z="0"/>
351 <rotation name="rMinus90AboutY" unit="deg" x="0" y="270" z="0"/>
352 <rotation name="rMinus90AboutYMinus90AboutX" unit="deg" x="270" y="270" z="0"/>
353 <rotation name="rPlus180AboutX" unit="deg" x="180" y="0" z="0"/>
354 <rotation name="rPlus180AboutY" unit="deg" x="0" y="180" z="0"/>
355 <rotation name="rPlus180AboutXPlus180AboutY" unit="deg" x="180" y="180" z="0"/>
356 <rotation name="rIdentity" unit="deg" x="0" y="0" z="0"/>
363 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
364 #+++++++++++++++++++++++++++++++++++++ gen_Materials +++++++++++++++++++++++++++++++++++++
365 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
370 # Create the <materials> fragment file name,
371 # add file to list of output GDML fragments,
373 $MAT = $basename."_Materials" . $suffix . ".gdml";
374 push (@gdmlFiles, $MAT);
377 open(MAT) or die("Could not open file $MAT for writing");
379 # Add any materials special to this geometry by defining a mulitline string
380 # and passing it to the gdmlMaterials::gen_Materials() function.
382 <!-- preliminary values -->
383 <material name="AirSteelMixture" formula="AirSteelMixture">
384 <D value=" 0.001205*(1-$FracMassOfSteel) + 7.9300*$FracMassOfSteel " unit="g/cm3"/>
385 <fraction n="$FracMassOfSteel" ref="STEEL_STAINLESS_Fe7Cr2Ni"/>
386 <fraction n="$FracMassOfAir" ref="Air"/>
388 <material name="vm2000" formula="vm2000">
389 <D value="1.2" unit="g/cm3"/>
390 <composite n="2" ref="carbon"/>
391 <composite n="4" ref="hydrogen"/>
395 # add the general materials used anywere
396 print MAT gdmlMaterials::gen_Materials( $asmix );
402 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
403 #++++++++++++++++++++++++++++++++++++++++ gen_TPC ++++++++++++++++++++++++++++++++++++++++
404 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
405 # line clip on the rectangle boundary
416 if( abs( nx ) < tol ){
417 push( @endpts, ($x0, 0) );
418 push( @endpts, ($x0, $rcw) );
421 if( abs( ny ) < tol ){
422 push( @endpts, (0, $y0) );
423 push( @endpts, ($rcl, $y0) );
427 # left border at x = 0
428 my $y = $y0 - $x0 * $ny/$nx;
429 if( $y >= 0 && $y <= $rcw ){
430 push( @endpts, (0, $y) );
433 # right border at x = l
434 $y = $y0 + ($rcl-$x0) * $ny/$nx;
435 if( $y >= 0 && $y <= $rcw ){
436 push( @endpts, ($rcl, $y) );
437 if( scalar(@endpts) == 4 ){
442 # bottom border at y = 0
443 my $x = $x0 - $y0 * $nx/$ny;
444 if( $x >= 0 && $x <= $rcl ){
445 push( @endpts, ($x, 0) );
446 if( scalar(@endpts) == 4 ){
451 # top border at y = w
452 $x = $x0 + ($rcw-$y0)* $nx/$ny;
453 if( $x >= 0 && $x <= $rcl ){
454 push( @endpts, ($x, $rcw) );
462 my $length = $_[0]; #
465 my $nchb = $_[3]; # nch per bottom side
467 my $theta = $_[5]; # deg
470 $theta = $theta * pi()/180.0;
471 my @dirw = (cos($theta), sin($theta));
472 my @dirp = (cos($theta - pi()/2), sin($theta - pi()/2));
476 if( $alpha > pi()/2 ){
477 $alpha = pi() - $alpha;
479 my $dX = $pitch / sin( $alpha );
480 my $dY = $pitch / sin( pi()/2 - $alpha );
482 $length = $dX * $nchb;
485 $width = $dY * ($nch - $nchb);
496 #print "origin : @orig\n";
497 #print "pitch dir : @dirp\n";
498 #print "wire dir : @dirw\n";
499 #print "$length x $width cm2\n";
503 my $offset = $pitch/2;
504 foreach my $ch (0..$nch-1){
505 #print "Processing $ch\n";
507 # calculate reference point for this strip
509 $wcn[0] = $orig[0] + $offset * $dirp[0];
510 $wcn[1] = $orig[1] + $offset * $dirp[1];
512 # line clip on the rectangle boundary
513 @endpts = lineClip( $wcn[0], $wcn[1], $dirw[0], $dirw[1], $length, $width );
515 if( scalar(@endpts) != 4 ){
516 print "Could not find end points for wire $ch : @endpts\n";
517 $offset = $offset + $pitch;
521 # re-center on the mid-point
522 $endpts[0] -= $length/2;
523 $endpts[2] -= $length/2;
524 $endpts[1] -= $width/2;
525 $endpts[3] -= $width/2;
527 # calculate the strip center in the rectangle of CRU
528 $wcn[0] = ($endpts[0] + $endpts[2])/2;
529 $wcn[1] = ($endpts[1] + $endpts[3])/2;
531 # calculate the length
532 my $dx = $endpts[0] - $endpts[2];
533 my $dy = $endpts[1] - $endpts[3];
534 my $wlen = sqrt($dx**2 + $dy**2);
536 # put all info together
537 my @wire = ($ch, $wcn[0], $wcn[1], $wlen);
538 push( @wire, @endpts );
539 push( @winfo, \@wire);
540 $offset = $offset + $pitch;
550 my $TPCActive_x = $driftTPCActive;
551 my $TPCActive_y = $widthCRM_active;
552 my $TPCActive_z = $lengthCRM_active;
555 my $TPC_x = $TPCActive_x + $ReadoutPlane;
556 my $TPC_y = $widthCRM;
557 my $TPC_z = $lengthCRM;
559 print " TPC dimensions : $TPC_x x $TPC_y x $TPC_z\n";
561 $TPC = $basename."_TPC" . $suffix . ".gdml";
562 push (@gdmlFiles, $TPC);
564 open(TPC) or die("Could not open file $TPC for writing");
566 # The standard XML prefix and starting the gdml
568 <?xml version='1.0'?>
572 # compute wires for 1st induction
574 if( $wires_on == 1 ){
575 @winfo = gen_Wires( 0, 0, # $TPCActive_y,
576 $nChans{'Ind1'}, $nChans{'Ind1Bot'},
577 $wirePitchU, $wireAngleU, $padWidth );
580 # All the TPC solids save the wires.
591 <box name="CRMUPlane"
596 <box name="CRMYPlane"
601 <box name="CRMZPlane"
606 <box name="CRMActive"
613 #++++++++++++++++++++++++++++ Wire Solids ++++++++++++++++++++++++++++++
616 foreach my $wire (@winfo) {
617 my $wid = $wire->[0];
618 my $wln = $wire->[3];
620 <tube name="CRMWireU$wid"
624 aunit="deg" lunit="cm"/>
629 <tube name="CRMWireY"
633 aunit="deg" lunit="cm"/>
634 <tube name="CRMWireZ"
638 aunit="deg" lunit="cm"/>
646 # Begin structure and create wire logical volumes
649 <volume name="volTPCActive">
650 <materialref ref="LAr"/>
651 <solidref ref="CRMActive"/>
652 <auxiliary auxtype="SensDet" auxvalue="SimEnergyDeposit"/>
653 <auxiliary auxtype="StepLimit" auxunit="cm" auxvalue="0.5208*cm"/>
654 <auxiliary auxtype="Efield" auxunit="V/cm" auxvalue="500*V/cm"/>
655 <colorref ref="blue"/>
661 foreach my $wire (@winfo)
663 my $wid = $wire->[0];
665 <volume name="volTPCWireU$wid">
666 <materialref ref="Copper_Beryllium_alloy25"/>
667 <solidref ref="CRMWireU$wid"/>
673 <volume name="volTPCWireY">
674 <materialref ref="Copper_Beryllium_alloy25"/>
675 <solidref ref="CRMWireY"/>
677 <volume name="volTPCWireZ">
678 <materialref ref="Copper_Beryllium_alloy25"/>
679 <solidref ref="CRMWireZ"/>
683 # 1st induction plane
685 <volume name="volTPCPlaneU">
686 <materialref ref="LAr"/>
687 <solidref ref="CRMUPlane"/>
689 if ($wires_on==1) # add wires to U plane
691 # the coordinates were computed with a corner at (0,0)
692 # so we need to move to plane coordinates
693 my $offsetZ = 0; #-0.5 * $TPCActive_z;
694 my $offsetY = 0; #-0.5 * $TPCActive_y;
696 foreach my $wire (@winfo) {
697 my $wid = $wire->[0];
698 my $zpos = $wire->[1] + $offsetZ;
699 my $ypos = $wire->[2] + $offsetY;
702 <volumeref ref="volTPCWireU$wid"/>
703 <position name="posWireU$wid" unit="cm" x="0" y="$ypos" z="$zpos"/>
704 <rotationref ref="rUWireAboutX"/>
713 # 2nd induction plane
715 <volume name="volTPCPlaneY">
716 <materialref ref="LAr"/>
717 <solidref ref="CRMYPlane"/>
720 if ($wires_on==1) # add wires to Y plane (plane with wires reading y position)
722 for(my $i=0;$i<$nChans{'Ind2'};++$i)
724 #my $ypos = -0.5 * $TPCActive_y + ($i+0.5)*$wirePitchY + 0.5*$padWidth;
725 my $ypos = ($i + 0.5 - $nChans{'Ind2'}/2)*$wirePitchY;
726 if( (0.5 * $TPCActive_y - abs($ypos)) < 0 ){
727 die "Cannot place wire $i in view Y, as plane is too small\n";
731 <volumeref ref="volTPCWireY"/>
732 <position name="posWireY$i" unit="cm" x="0" y="$ypos" z="0"/>
733 <rotationref ref="rIdentity"/>
744 <volume name="volTPCPlaneZ">
745 <materialref ref="LAr"/>
746 <solidref ref="CRMZPlane"/>
748 if ($wires_on==1) # add wires to Z plane (plane with wires reading z position)
750 for(my $i=0;$i<$nChans{'Col'};++$i)
752 #my $zpos = -0.5 * $TPCActive_z + ($i+0.5)*$wirePitchZ + 0.5*$padWidth;
753 my $zpos = ($i + 0.5 - $nChans{'Col'}/2)*$wirePitchZ;
754 if( (0.5 * $TPCActive_z - abs($zpos)) < 0 ){
755 die "Cannot place wire $i in view Z, as plane is too small\n";
759 <volumeref ref="volTPCWireZ"/>
760 <position name="posWireZ$i" unit="cm" x="0" y="0" z="$zpos"/>
761 <rotationref ref="rPlus90AboutX"/>
771 $posUplane[0] = 0.5*$TPC_x - 2.5*$padWidth;
775 $posYplane[0] = 0.5*$TPC_x - 1.5*$padWidth;
779 $posZplane[0] = 0.5*$TPC_x - 0.5*$padWidth;
783 $posTPCActive[0] = -$ReadoutPlane/2;
784 $posTPCActive[1] = 0;
785 $posTPCActive[2] = 0;
788 #wrap up the TPC file
790 <volume name="volTPC">
791 <materialref ref="LAr"/>
792 <solidref ref="CRM"/>
794 <volumeref ref="volTPCPlaneU"/>
795 <position name="posPlaneU" unit="cm"
796 x="$posUplane[0]" y="$posUplane[1]" z="$posUplane[2]"/>
797 <rotationref ref="rIdentity"/>
800 <volumeref ref="volTPCPlaneY"/>
801 <position name="posPlaneY" unit="cm"
802 x="$posYplane[0]" y="$posYplane[1]" z="$posYplane[2]"/>
803 <rotationref ref="rIdentity"/>
806 <volumeref ref="volTPCPlaneZ"/>
807 <position name="posPlaneZ" unit="cm"
808 x="$posZplane[0]" y="$posZplane[1]" z="$posZplane[2]"/>
809 <rotationref ref="rIdentity"/>
812 <volumeref ref="volTPCActive"/>
813 <position name="posActive" unit="cm"
814 x="$posTPCActive[0]" y="$posTPCAtive[1]" z="$posTPCActive[2]"/>
815 <rotationref ref="rIdentity"/>
819 ## x="@{[$posTPCActive[0]+$padWidth]}" y="$posTPCActive[1]" z="$posTPCActive[2]"/>
829 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
830 #++++++++++++++++++++++++++++++++++++++ gen_FieldCage ++++++++++++++++++++++++++++++++++++
831 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
835 $FieldCage = $basename."_FieldCage" . $suffix . ".gdml";
836 push (@gdmlFiles, $FieldCage);
837 $FieldCage = ">" . $FieldCage;
838 open(FieldCage) or die("Could not open file $FieldCage for writing");
840 # The standard XML prefix and starting the gdml
841 print FieldCage <<EOF;
842 <?xml version='1.0'?>
845 # The printing solids used in the Field Cage
846 #print "lengthTPCActive : $lengthTPCActive \n";
847 #print "widthTPCActive : $widthTPCActive \n";
850 print FieldCage <<EOF;
852 <torus name="FieldShaperCorner" rmin="$FieldShaperInnerRadius" rmax="$FieldShaperOuterRadius" rtor="$FieldShaperTorRad" deltaphi="90" startphi="0" aunit="deg" lunit="cm"/>
853 <tube name="FieldShaperLongtube" rmin="$FieldShaperInnerRadius" rmax="$FieldShaperOuterRadius" z="$FieldShaperLongTubeLength" deltaphi="360" startphi="0" aunit="deg" lunit="cm"/>
854 <tube name="FieldShaperShorttube" rmin="$FieldShaperInnerRadius" rmax="$FieldShaperOuterRadius" z="$FieldShaperShortTubeLength" deltaphi="360" startphi="0" aunit="deg" lunit="cm"/>
856 <union name="FSunion1">
857 <first ref="FieldShaperLongtube"/>
858 <second ref="FieldShaperCorner"/>
859 <position name="esquinapos1" unit="cm" x="@{[-$FieldShaperTorRad]}" y="0" z="@{[0.5*$FieldShaperLongTubeLength]}"/>
860 <rotation name="rot1" unit="deg" x="90" y="0" z="0" />
863 <union name="FSunion2">
864 <first ref="FSunion1"/>
865 <second ref="FieldShaperShorttube"/>
866 <position name="esquinapos2" unit="cm" x="@{[-0.5*$FieldShaperShortTubeLength-$FieldShaperTorRad]}" y="0" z="@{[+0.5*$FieldShaperLongTubeLength+$FieldShaperTorRad]}"/>
867 <rotation name="rot2" unit="deg" x="0" y="90" z="0" />
870 <union name="FSunion3">
871 <first ref="FSunion2"/>
872 <second ref="FieldShaperCorner"/>
873 <position name="esquinapos3" unit="cm" x="@{[-$FieldShaperShortTubeLength-$FieldShaperTorRad]}" y="0" z="@{[0.5*$FieldShaperLongTubeLength]}"/>
874 <rotation name="rot3" unit="deg" x="90" y="270" z="0" />
877 <union name="FSunion4">
878 <first ref="FSunion3"/>
879 <second ref="FieldShaperLongtube"/>
880 <position name="esquinapos4" unit="cm" x="@{[-$FieldShaperShortTubeLength-2*$FieldShaperTorRad]}" y="0" z="0"/>
883 <union name="FSunion5">
884 <first ref="FSunion4"/>
885 <second ref="FieldShaperCorner"/>
886 <position name="esquinapos5" unit="cm" x="@{[-$FieldShaperShortTubeLength-$FieldShaperTorRad]}" y="0" z="@{[-0.5*$FieldShaperLongTubeLength]}"/>
887 <rotation name="rot5" unit="deg" x="90" y="180" z="0" />
890 <union name="FSunion6">
891 <first ref="FSunion5"/>
892 <second ref="FieldShaperShorttube"/>
893 <position name="esquinapos6" unit="cm" x="@{[-0.5*$FieldShaperShortTubeLength-$FieldShaperTorRad]}" y="0" z="@{[-0.5*$FieldShaperLongTubeLength-$FieldShaperTorRad]}"/>
894 <rotation name="rot6" unit="deg" x="0" y="90" z="0" />
897 <union name="FieldShaperSolid">
898 <first ref="FSunion6"/>
899 <second ref="FieldShaperCorner"/>
900 <position name="esquinapos7" unit="cm" x="@{[-$FieldShaperTorRad]}" y="0" z="@{[-0.5*$FieldShaperLongTubeLength]}"/>
901 <rotation name="rot7" unit="deg" x="90" y="90" z="0" />
907 print FieldCage <<EOF;
910 <volume name="volFieldShaper">
911 <materialref ref="Al2O3"/>
912 <solidref ref="FieldShaperSolid"/>
918 print FieldCage <<EOF;
927 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
928 #++++++++++++++++++++++++++++++++++++++ gen_Cryostat +++++++++++++++++++++++++++++++++++++
929 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
934 # Create the cryostat fragment file name,
935 # add file to list of output GDML fragments,
937 $CRYO = $basename."_Cryostat" . $suffix . ".gdml";
938 push (@gdmlFiles, $CRYO);
940 open(CRYO) or die("Could not open file $CRYO for writing");
943 # The standard XML prefix and starting the gdml
945 <?xml version='1.0'?>
949 # All the cryostat solids.
952 <box name="Cryostat" lunit="cm"
957 <box name="ArgonInterior" lunit="cm"
962 <box name="GaseousArgon" lunit="cm"
967 <subtraction name="SteelShell">
968 <first ref="Cryostat"/>
969 <second ref="ArgonInterior"/>
978 <volume name="volSteelShell">
979 <materialref ref="STEEL_STAINLESS_Fe7Cr2Ni" />
980 <solidref ref="SteelShell" />
982 <volume name="volGaseousArgon">
983 <materialref ref="ArGas"/>
984 <solidref ref="GaseousArgon"/>
990 <volume name="volCryostat">
991 <materialref ref="LAr" />
992 <solidref ref="Cryostat" />
994 <volumeref ref="volGaseousArgon"/>
995 <position name="posGaseousArgon" unit="cm" x="@{[$Argon_x/2-$HeightGaseousAr/2]}" y="0" z="0"/>
998 <volumeref ref="volSteelShell"/>
999 <position name="posSteelShell" unit="cm" x="0" y="0" z="0"/>
1004 if ($tpc_on==1) # place TPC inside croysotat offsetting each pair of CRMs by borderCRP
1006 $posX = $Argon_x/2 - $HeightGaseousAr - 0.5*($driftTPCActive + $ReadoutPlane);
1008 my $posZ = -0.5*$Argon_z + $zLArBuffer + 0.5*$lengthCRM;
1009 for(my $ii=0;$ii<$nCRM_z;$ii++)
1012 $posZ += $borderCRP;
1014 $posZ += $borderCRP;
1017 my $posY = -0.5*$Argon_y + $yLArBuffer + 0.5*$widthCRM;
1018 for(my $jj=0;$jj<$nCRM_x;$jj++)
1021 $posY += $borderCRP;
1023 $posY += $borderCRP;
1028 <volumeref ref="volTPC"/>
1029 <position name="posTPC\-$idx" unit="cm"
1030 x="$posX" y="$posY" z="$posZ"/>
1037 $posZ += $lengthCRM;
1042 #The +50 in the x positions must depend on some other parameter
1043 if ( $FieldCage_switch eq "on" ) {
1044 for ( $i=0; $i<$NFieldShapers; $i=$i+1 ) { # pmts with coating
1045 $posX = $Argon_x/2 - $HeightGaseousAr - 0.5*($driftTPCActive + $ReadoutPlane);
1048 <volumeref ref="volFieldShaper"/>
1049 <position name="posFieldShaper$i" unit="cm" x="@{[-$OriginXSet+50+($i-$NFieldShapers*0.5)*$FieldShaperSeparation]}" y="@{[-0.5*$FieldShaperShortTubeLength-$FieldShaperTorRad]}" z="0" />
1050 <rotation name="rotFS$i" unit="deg" x="0" y="0" z="90" />
1057 $CathodePosX =-$OriginXSet+50+(-1-$NFieldShapers*0.5)*$FieldShaperSeparation;
1060 if ( $Cathode_switch eq "on" )
1064 <volumeref ref="volGroundGrid"/>
1065 <position name="posGroundGrid01" unit="cm" x="$CathodePosX" y="@{[-$CathodePosY]}" z="@{[$CathodePosZ]}"/>
1066 <rotation name="rotGG01" unit="deg" x="0" y="0" z="90" />
1084 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1085 #+++++++++++++++++++++++++++++++++++++ gen_Enclosure +++++++++++++++++++++++++++++++++++++
1086 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1091 # Create the detector enclosure fragment file name,
1092 # add file to list of output GDML fragments,
1094 $ENCL = $basename."_DetEnclosure" . $suffix . ".gdml";
1095 push (@gdmlFiles, $ENCL);
1096 $ENCL = ">" . $ENCL;
1097 open(ENCL) or die("Could not open file $ENCL for writing");
1100 # The standard XML prefix and starting the gdml
1102 <?xml version='1.0'?>
1107 # All the detector enclosure solids.
1111 <box name="FoamPadBlock" lunit="cm"
1112 x="@{[$Cryostat_x + 2*$FoamPadding]}"
1113 y="@{[$Cryostat_y + 2*$FoamPadding]}"
1114 z="@{[$Cryostat_z + 2*$FoamPadding]}" />
1116 <subtraction name="FoamPadding">
1117 <first ref="FoamPadBlock"/>
1118 <second ref="Cryostat"/>
1119 <positionref ref="posCenter"/>
1122 <box name="SteelSupportBlock" lunit="cm"
1123 x="@{[$Cryostat_x + 2*$FoamPadding + 2*$SteelSupport_x]}"
1124 y="@{[$Cryostat_y + 2*$FoamPadding + 2*$SteelSupport_y]}"
1125 z="@{[$Cryostat_z + 2*$FoamPadding + 2*$SteelSupport_z]}" />
1127 <subtraction name="SteelSupport">
1128 <first ref="SteelSupportBlock"/>
1129 <second ref="FoamPadBlock"/>
1130 <positionref ref="posCenter"/>
1133 <box name="DetEnclosure" lunit="cm"
1142 # Detector enclosure structure
1145 <volume name="volFoamPadding">
1146 <materialref ref="fibrous_glass"/>
1147 <solidref ref="FoamPadding"/>
1150 <volume name="volSteelSupport">
1151 <materialref ref="AirSteelMixture"/>
1152 <solidref ref="SteelSupport"/>
1155 <volume name="volDetEnclosure">
1156 <materialref ref="Air"/>
1157 <solidref ref="DetEnclosure"/>
1160 <volumeref ref="volFoamPadding"/>
1161 <positionref ref="posCryoInDetEnc"/>
1164 <volumeref ref="volSteelSupport"/>
1165 <positionref ref="posCryoInDetEnc"/>
1168 <volumeref ref="volCryostat"/>
1169 <positionref ref="posCryoInDetEnc"/>
1188 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1189 #+++++++++++++++++++++++++++++++++++++++ gen_World +++++++++++++++++++++++++++++++++++++++
1190 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1195 # Create the WORLD fragment file name,
1196 # add file to list of output GDML fragments,
1198 $WORLD = $basename."_World" . $suffix . ".gdml";
1199 push (@gdmlFiles, $WORLD);
1200 $WORLD = ">" . $WORLD;
1201 open(WORLD) or die("Could not open file $WORLD for writing");
1204 # The standard XML prefix and starting the gdml
1206 <?xml version='1.0'?>
1211 # All the World solids.
1214 <box name="World" lunit="cm"
1215 x="@{[$DetEncX+2*$RockThickness]}"
1216 y="@{[$DetEncY+2*$RockThickness]}"
1217 z="@{[$DetEncZ+2*$RockThickness]}"/>
1224 <volume name="volWorld" >
1225 <materialref ref="DUSEL_Rock"/>
1226 <solidref ref="World"/>
1229 <volumeref ref="volDetEnclosure"/>
1230 <position name="posDetEnclosure" unit="cm" x="$OriginXSet" y="$OriginYSet" z="$OriginZSet"/>
1238 # make_gdml.pl will take care of <setup/>
1245 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1246 #++++++++++++++++++++++++++++++++++++ write_fragments ++++++++++++++++++++++++++++++++++++
1247 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1249 sub write_fragments()
1251 # This subroutine creates an XML file that summarizes the the subfiles output
1252 # by the other sub routines - it is the input file for make_gdml.pl which will
1253 # give the final desired GDML file. Specify its name with the output option.
1254 # (you can change the name when running make_gdml)
1256 # This code is taken straigh from the similar MicroBooNE generate script, Thank you.
1258 if ( ! defined $output )
1260 $output = "-"; # write to STDOUT
1263 # Set up the output file.
1264 $OUTPUT = ">" . $output;
1265 open(OUTPUT) or die("Could not open file $OUTPUT");
1268 <?xml version='1.0'?>
1270 <!-- Input to Geometry/gdml/make_gdml.pl; define the GDML fragments
1271 that will be zipped together to create a detector description.
1278 <!-- These files contain GDML <constant></constant>
1279 blocks. They are read in separately, so they can be
1280 interpreted into the remaining GDML. See make_gdml.pl for
1286 foreach $filename (@defFiles)
1289 <filename> $filename </filename>
1299 <!-- The GDML file fragments to be zipped together. -->
1303 foreach $filename (@gdmlFiles)
1306 <filename> $filename </filename>
1321 print "Some of the principal parameters for this TPC geometry (unit cm unless noted otherwise)\n";
1322 print " CRM active area : $widthCRM_active x $lengthCRM_active\n";
1323 print " CRM total area : $widthCRM x $lengthCRM\n";
1324 print " Wire pitch in U, Y, Z : $wirePitchU, $wirePitchY, $wirePitchZ\n";
1325 print " TPC active volume : $driftTPCActive x $widthTPCActive x $lengthTPCActive\n";
1326 print " Argon volume : ($Argon_x, $Argon_y, $Argon_z) \n";
1327 print " Argon buffer : ($xLArBuffer, $yLArBuffer, $zLArBuffer) \n";
1328 print " Detector enclosure : $DetEncX x $DetEncY x $DetEncZ\n";
1329 print " TPC Origin : ($OriginXSet, $OriginYSet, $OriginZSet) \n";
1330 print " Field Cage : $FieldCage_switch \n";
1331 print " Cathode : $Cathode_switch \n";
1332 print " Workspace : $workspace \n";
1333 print " Wires : $wires_on \n";
1335 # run the sub routines that generate the fragments
1336 if ( $FieldCage_switch eq "on" ) { gen_FieldCage(); }
1337 #if ( $Cathode_switch eq "on" ) { gen_Cathode(); } #Cathode for now has the same geometry as the Ground Grid
1339 gen_Extend(); # generates the GDML color extension for the refactored geometry
1340 gen_Define(); # generates definitions at beginning of GDML
1341 gen_Materials(); # generates materials to be used
1342 gen_TPC(); # generate TPC for a given unit CRM
1345 gen_World(); # places the enclosure among DUSEL Rock
1346 write_fragments(); # writes the XML input for make_gdml.pl
1347 # which zips together the final GDML
1348 print "--- done\n\n\n";