ROOT logo
// Model of a nucleus built from TGeo classes.
// 
// Author: Otto Schaile

void nucleus(Int_t nProtons  = 40,Int_t  nNeutrons = 60) 
{
   Double_t NeutronRadius = 60,
            ProtonRadius = 60,
            NucleusRadius,
            distance = 60;
   Double_t vol = nProtons + nNeutrons;
   vol = 3 * vol / (4 * TMath::Pi());

   NucleusRadius = distance * TMath::Power(vol, 1./3.);
//   cout << "NucleusRadius: " << NucleusRadius << endl;

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

   TGeoMedium *EmptySpace = new TGeoMedium("Empty", 1, matEmptySpace);
   TGeoMedium *Proton     = new TGeoMedium("Proton", 1, matProton);
   TGeoMedium *Neutron    = new TGeoMedium("Neutron",1, matNeutron);

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

   Double_t worldx = 200.;
   Double_t worldy = 200.;
   Double_t worldz = 200.;
 
   TGeoVolume *top = geom->MakeBox("WORLD", EmptySpace, worldx, worldy, worldz); 
   geom->SetTopVolume(top);

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

   Double_t x, y, z, dummy;
   Int_t i = 0; 
   while ( i<  nProtons) {
      gRandom->Rannor(x, y);
      gRandom->Rannor(z,dummy);
      if ( TMath::Sqrt(x*x + y*y + z*z) < 1) {
         x = (2 * x - 1) * NucleusRadius;
         y = (2 * y - 1) * NucleusRadius;
         z = (2 * z - 1) * NucleusRadius;
         top->AddNode(proton, i, new TGeoTranslation(x, y, z));
         i++;
      }
   }
   i = 0; 
   while ( i <  nNeutrons) {
      gRandom->Rannor(x, y);
      gRandom->Rannor(z,dummy);
      if ( TMath::Sqrt(x*x + y*y + z*z) < 1) {
         x = (2 * x - 1) * NucleusRadius;
         y = (2 * y - 1) * NucleusRadius;
         z = (2 * z - 1) * NucleusRadius;
         top->AddNode(neutron, i + nProtons, new TGeoTranslation(x, y, z));
         i++;
      }
   }
   geom->CloseGeometry();
   geom->SetVisLevel(4);
   top->Draw("ogl");
}
 nucleus.C:1
 nucleus.C:2
 nucleus.C:3
 nucleus.C:4
 nucleus.C:5
 nucleus.C:6
 nucleus.C:7
 nucleus.C:8
 nucleus.C:9
 nucleus.C:10
 nucleus.C:11
 nucleus.C:12
 nucleus.C:13
 nucleus.C:14
 nucleus.C:15
 nucleus.C:16
 nucleus.C:17
 nucleus.C:18
 nucleus.C:19
 nucleus.C:20
 nucleus.C:21
 nucleus.C:22
 nucleus.C:23
 nucleus.C:24
 nucleus.C:25
 nucleus.C:26
 nucleus.C:27
 nucleus.C:28
 nucleus.C:29
 nucleus.C:30
 nucleus.C:31
 nucleus.C:32
 nucleus.C:33
 nucleus.C:34
 nucleus.C:35
 nucleus.C:36
 nucleus.C:37
 nucleus.C:38
 nucleus.C:39
 nucleus.C:40
 nucleus.C:41
 nucleus.C:42
 nucleus.C:43
 nucleus.C:44
 nucleus.C:45
 nucleus.C:46
 nucleus.C:47
 nucleus.C:48
 nucleus.C:49
 nucleus.C:50
 nucleus.C:51
 nucleus.C:52
 nucleus.C:53
 nucleus.C:54
 nucleus.C:55
 nucleus.C:56
 nucleus.C:57
 nucleus.C:58
 nucleus.C:59
 nucleus.C:60
 nucleus.C:61
 nucleus.C:62
 nucleus.C:63
 nucleus.C:64
 nucleus.C:65
 nucleus.C:66
 nucleus.C:67
 nucleus.C:68
 nucleus.C:69
 nucleus.C:70
thumb