The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

SOOT::Examples::Geometry - SOOT Examples for Geometry

DESCRIPTION

This is a listing of all SOOT examples for Geometry.

EXAMPLES

assembly.pl

use strict;
use SOOT ':all';
use Math::Trig;

#--- Definition of a simple geometry
$gSystem->Load("libGeom");
$gSystem->Load("libGeomBuilder");
$gSystem->Load("libGeomPainter");
SOOT->UpdateClasses();

my $geom = TGeoManager->new("Assemblies", "Geometry using assemblies");

#--- define some materials
my $matVacuum = TGeoMaterial->new("Vacuum", 0,0,0);
my $matAl     = TGeoMaterial->new("Al", 26.98,13,2.7);

#--- define some media
my $Vacuum = TGeoMedium->new("Vacuum",    1, $matVacuum);
my $Al     = TGeoMedium->new("Aluminium", 2, $matAl);

#--- make the top container volume
my $top = $geom->MakeBox("TOP", $Vacuum, 1000., 1000., 100.);
$geom->SetTopVolume($top);

# Make the elementary assembly of the whole structure
my $tplate = TGeoVolumeAssembly->new("TOOTHPLATE"); # FIXME This segfaults!?

my $ntooth = 5;
my $xplate = 25.0;
my $yplate = 50.0;
my $xtooth = 10.0;
my $ytooth = 0.5*$yplate/$ntooth;
my $dshift = 2.*$xplate + $xtooth;

my $plate = $geom->MakeBox("PLATE", $Al, $xplate, $yplate, 1);
$plate->SetLineColor(kBlue);

my $tooth = $geom->MakeBox("TOOTH", $Al, $xtooth, $ytooth, 1);
$tooth->SetLineColor(kBlue);
$tplate->AddNode($plate, 1);

my ($xt, $yt);
for my $i (0..$ntooth)
{
  $xt = $xplate + $xtooth;
  $yt = -$yplate + (4*$i+1)*$ytooth;
  $tplate->AddNode($tooth, $i+1, TGeoTranslation->new($xt,$yt,0)->keep);
  $xt = -$xplate-$xtooth;
  $yt = -$yplate + (4*$i+3)*$ytooth;
  $tplate->AddNode($tooth, $ntooth+$i+1, TGeoTranslation->new($xt,$yt,0)->keep);
}

my $rot1 = TGeoRotation->new();
$rot1->RotateX(90);
my $rot;
my $trans;

# Make a hexagone cell out of 6 toothplates. These can zip togeather
# without generating overlaps (they are self-contained)
my $cell = TGeoVolumeAssembly->new("CELL");
for my $i (0..6) {
  my    $phi = 60.*$i;
  my $phirad = deg2rad($phi);
  my     $xp = $dshift*sin($phirad);
  my     $yp = -$dshift*cos($phirad);
  $rot = TGeoRotation->new($rot1);
  $rot->RotateZ($phi);
  $trans = TGeoCombiTrans->new($xp,$yp,0,$rot);
  $cell->AddNode($tplate, $i+1, $trans); # FIXME SEGV here
}

# Make a row as an assembly of cells, then combine rows in a honeycomb
# structure. This again works without any need to define rows as "overlapping"
my $row = TGeoVolumeAssembly->new("ROW");
my $ncells = 5;
for my $i (0..$ncells-1) {
  my $ycell = (2*$i+1)*($dshift+10);
  $row->AddNode($cell, $ncells+$i+1, TGeoTranslation->new(0,$ycell,0)->keep);
  $row->AddNode($cell, $ncells-$i,   TGeoTranslation->new(0,-$ycell,0)->keep);
}

my $dxrow = 3.*($dshift+10.)*tan(deg2rad(30.0));
my $dyrow = $dshift+10.;
my $nrows = 5;
for my $i (0..$nrows)
{
  my $xrow = 0.5*(2*$i+1)*$dxrow;
  my $yrow = 0.5*$dyrow;
  if (($i%2)==0) {
    $yrow = -$yrow;
  }
  $top->AddNode($row, $nrows+$i+1, TGeoTranslation->new($xrow,$yrow,0)->keep);
  $top->AddNode($row, $nrows-$i,    TGeoTranslation->new(-$xrow,-$yrow,0)->keep);
}

#--- close the geometry
$geom->CloseGeometry();

$geom->SetVisLevel(4);
$geom->SetVisOption(0);
$top->Draw();

$gApplication->Run;

nucleus.pl

use strict;
use warnings;
use SOOT ':all';
use Math::Trig; 

$gSystem->Load("libGeom");
$gSystem->Load("libGeomBuilder");
$gSystem->Load("libGeomPainter");
SOOT->UpdateClasses();

# use TGeo classes to draw a model of a nucleus
# 
# Author: Otto Schaile
my $nProtons  = shift || 40;
my $nNeutrons = shift || 60;

my $NeutronRadius = 60;
my $ProtonRadius = 60;
my $NucleusRadius;
my $distance = 60;

my $vol = $nProtons + $nNeutrons;
$vol = 3 * $vol / (4 * pi);

$NucleusRadius = $distance * $vol**(1./3.);

my $geom = TGeoManager->new("nucleus", "Model of a nucleus");
$geom->SetNsegments(40);
my $matEmptySpace = TGeoMaterial->new("EmptySpace", 0, 0, 0);
my $matProton     = TGeoMaterial->new("Proton"    , .938, 1., 10000.);
my $matNeutron    = TGeoMaterial->new("Neutron"   , .935, 0., 10000.);

my $EmptySpace = TGeoMedium->new("Empty", 1, $matEmptySpace);
my $Proton     = TGeoMedium->new("Proton", 1, $matProton);
my $Neutron    = TGeoMedium->new("Neutron",1, $matNeutron);

#  the space where the nucleus lives (top container volume)

my $worldx = 200.;
my $worldy = 200.;
my $worldz = 200.;

my $top = $geom->MakeBox("WORLD", $EmptySpace, $worldx, $worldy, $worldz); 
$geom->SetTopVolume($top);

my $proton  = $geom->MakeSphere("proton",  $Proton,  0., $ProtonRadius); 
my $neutron = $geom->MakeSphere("neutron", $Neutron, 0., $NeutronRadius); 
$proton->SetLineColor(kRed);
$neutron->SetLineColor(kBlue);

my ($x, $y, $z); 
my $i = 0; 
while ($i < $nProtons) {
  $x = $gRandom->Gaus(0.0, 1.0);
  $y = $gRandom->Gaus(0.0, 1.0);
  $z = $gRandom->Gaus(0.0, 1.0);
  printf "%f %f %f\n", $x, $y, $z;
  if (sqrt($x**2 + $y**2 + $z**2) < 1) {
     $x = (2 * $x - 1) * $NucleusRadius;
     $y = (2 * $y - 1) * $NucleusRadius;
     $z = (2 * $z - 1) * $NucleusRadius;
     my $trans = TGeoTranslation->new($x*1.0, $y*1.0, $z*1.0)->keep;
     $top->AddNode($proton, $i, $trans);
     $i++;
  }
}
$i = 0; 
while ($i < $nNeutrons) {
  $x = $gRandom->Gaus(0.0, 1.0);
  $y = $gRandom->Gaus(0.0, 1.0);
  $z = $gRandom->Gaus(0.0, 1.0);
  if (sqrt($x**2 + $y**2 + $z**2) < 1) {
     $x = (2 * $x - 1) * $NucleusRadius;
     $y = (2 * $y - 1) * $NucleusRadius;
     $z = (2 * $z - 1) * $NucleusRadius;
     my $trans = TGeoTranslation->new($x*1.0, $y*1.0, $z*1.0)->keep;
     $top->AddNode($neutron, $i + $nProtons, $trans);
     $i++;
  }
}
$geom->CloseGeometry();
$geom->SetVisLevel(4);
$top->Draw("ogl");

$gApplication->Run;

shapes.pl

use strict;
use warnings;
use SOOT ':all';

$gSystem->Load("libGeom");
$gSystem->Load("libGeomBuilder");
$gSystem->Load("libGeomPainter");
SOOT->UpdateClasses();

$gROOT->Reset();
my $c1 = TCanvas->new('c1', 'Geometry Shapes', 200, 10, 700, 500);

#  Define some volumes
my $brik = TBRIK->new('BRIK', 'BRIK', 'void', 200, 150, 150);
my $trd1 = TTRD1->new('TRD1', 'TRD1', 'void', 200, 50, 100, 100);
my $trd2 = TTRD2->new('TRD2', 'TRD2', 'void', 200, 50, 200, 50, 100);
my $trap = TTRAP->new('TRAP', 'TRAP', 'void', 190, 0, 0, 60, 40, 90, 15, 120, 80, 180, 15);
my $para = TPARA->new('PARA', 'PARA', 'void', 100, 200, 200, 15, 30, 30);
my $gtra = TGTRA->new('GTRA', 'GTRA', 'void', 390, 0, 0, 20, 60, 40, 90, 15, 120, 80, 180, 15);
my $tube = TTUBE->new('TUBE', 'TUBE', 'void', 150, 200, 400);
my $tubs = TTUBS->new('TUBS', 'TUBS', 'void', 80, 100, 100, 90, 235);
my $cone = TCONE->new('CONE', 'CONE', 'void', 100, 50, 70, 120, 150);
my $cons = TCONS->new('CONS', 'CONS', 'void', 50, 100, 100, 200, 300, 90, 270);
my $sphe  = TSPHE->new('SPHE',  'SPHE',  'void', 25, 340, 45, 135,  0, 270);
my $sphe1 = TSPHE->new('SPHE1', 'SPHE1', 'void',  0, 140,  0, 180,  0, 360);
my $sphe2 = TSPHE->new('SPHE2', 'SPHE2', 'void',  0, 200, 10, 120, 45, 145);

my $pcon = TPCON->new('PCON', 'PCON', 'void', 180, 270, 4);
$pcon->DefineSection(0, -200, 50, 100);
$pcon->DefineSection(1,  -50, 50,  80);
$pcon->DefineSection(2,   50, 50,  80);
$pcon->DefineSection(3,  200, 50, 100);

my $pgon = TPGON->new('PGON', 'PGON', 'void', 180, 270, 8, 4);
$pgon->DefineSection(0, -200, 50, 100);
$pgon->DefineSection(1,  -50, 50,  80);
$pgon->DefineSection(2,   50, 50,  80);
$pgon->DefineSection(3,  200, 50, 100);

#  Set shapes attributes
$brik->SetLineColor(1);
$trd1->SetLineColor(2);
$trd2->SetLineColor(3);
$trap->SetLineColor(4);
$para->SetLineColor(5);
$gtra->SetLineColor(7);
$tube->SetLineColor(6);
$tubs->SetLineColor(7);
$cone->SetLineColor(2);
$cons->SetLineColor(3);
$pcon->SetLineColor(6);
$pgon->SetLineColor(2);
$sphe->SetLineColor(1);
$sphe1->SetLineColor(2);
$sphe2->SetLineColor(4);

#  Build the geometry hierarchy
my $node1 = TNode->new('NODE1', 'NODE1', 'BRIK');
$node1->cd();

my $node2  = TNode->new( 'NODE2',  'NODE2', 'TRD1',     0,     0, -1000);
my $node3  = TNode->new( 'NODE3',  'NODE3', 'TRD2',     0,     0,  1000);
my $node4  = TNode->new( 'NODE4',  'NODE4', 'TRAP',     0, -1000,     0);
my $node5  = TNode->new( 'NODE5',  'NODE5', 'PARA',     0,  1000,     0);
my $node6  = TNode->new( 'NODE6',  'NODE6', 'TUBE', -1000,     0,     0);
my $node7  = TNode->new( 'NODE7',  'NODE7', 'TUBS',  1000,     0,     0);
my $node8  = TNode->new( 'NODE8',  'NODE8', 'CONE',  -300,  -300,     0);
my $node9  = TNode->new( 'NODE9',  'NODE9', 'CONS',   300,   300,     0);
my $node10 = TNode->new('NODE10', 'NODE10', 'PCON',     0, -1000, -1000);
my $node11 = TNode->new('NODE11', 'NODE11', 'PGON',     0,  1000,  1000);
my $node12 = TNode->new('NODE12', 'NODE12', 'GTRA',     0,  -400,   700);
my $node13 = TNode->new('NODE13', 'NODE13', 'SPHE',    10,  -400,   500);
my $node14 = TNode->new('NODE14', 'NODE14', 'SPHE1',   10,   250,   300);
my $node15 = TNode->new('NODE15', 'NODE15', 'SPHE2',   10,  -100,  -200);

# Draw this geometry in the current canvas
$node1->cd();
$node1->Draw();
$c1->Update();

$c1->GetViewer3D;

$gApplication->Run;

SEE ALSO

SOOT

AUTHOR

Steffen Mueller, <smueller@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2010 by Steffen Mueller

SOOT, the Perl-ROOT wrapper, is free software; you can redistribute it and/or modify it under the same terms as ROOT itself, that is, the GNU Lesser General Public License. A copy of the full license text is available from the distribution as the LICENSE file.