ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
nucleus.C
Go to the documentation of this file.
1 // Model of a nucleus built from TGeo classes.
2 //
3 // Author: Otto Schaile
4 
5 void nucleus(Int_t nProtons = 40,Int_t nNeutrons = 60)
6 {
7  Double_t NeutronRadius = 60,
8  ProtonRadius = 60,
9  NucleusRadius,
10  distance = 60;
11  Double_t vol = nProtons + nNeutrons;
12  vol = 3 * vol / (4 * TMath::Pi());
13 
14  NucleusRadius = distance * TMath::Power(vol, 1./3.);
15 // cout << "NucleusRadius: " << NucleusRadius << endl;
16 
17  TGeoManager * geom = new TGeoManager("nucleus", "Model of a nucleus");
18  geom->SetNsegments(40);
19  TGeoMaterial *matEmptySpace = new TGeoMaterial("EmptySpace", 0, 0, 0);
20  TGeoMaterial *matProton = new TGeoMaterial("Proton" , .938, 1., 10000.);
21  TGeoMaterial *matNeutron = new TGeoMaterial("Neutron" , .935, 0., 10000.);
22 
23  TGeoMedium *EmptySpace = new TGeoMedium("Empty", 1, matEmptySpace);
24  TGeoMedium *Proton = new TGeoMedium("Proton", 1, matProton);
25  TGeoMedium *Neutron = new TGeoMedium("Neutron",1, matNeutron);
26 
27 // the space where the nucleus lives (top container volume)
28 
29  Double_t worldx = 200.;
30  Double_t worldy = 200.;
31  Double_t worldz = 200.;
32 
33  TGeoVolume *top = geom->MakeBox("WORLD", EmptySpace, worldx, worldy, worldz);
34  geom->SetTopVolume(top);
35 
36  TGeoVolume * proton = geom->MakeSphere("proton", Proton, 0., ProtonRadius);
37  TGeoVolume * neutron = geom->MakeSphere("neutron", Neutron, 0., NeutronRadius);
38  proton->SetLineColor(kRed);
39  neutron->SetLineColor(kBlue);
40 
41  Double_t x, y, z, dummy;
42  Int_t i = 0;
43  while ( i< nProtons) {
44  gRandom->Rannor(x, y);
45  gRandom->Rannor(z,dummy);
46  if ( TMath::Sqrt(x*x + y*y + z*z) < 1) {
47  x = (2 * x - 1) * NucleusRadius;
48  y = (2 * y - 1) * NucleusRadius;
49  z = (2 * z - 1) * NucleusRadius;
50  top->AddNode(proton, i, new TGeoTranslation(x, y, z));
51  i++;
52  }
53  }
54  i = 0;
55  while ( i < nNeutrons) {
56  gRandom->Rannor(x, y);
57  gRandom->Rannor(z,dummy);
58  if ( TMath::Sqrt(x*x + y*y + z*z) < 1) {
59  x = (2 * x - 1) * NucleusRadius;
60  y = (2 * y - 1) * NucleusRadius;
61  z = (2 * z - 1) * NucleusRadius;
62  top->AddNode(neutron, i + nProtons, new TGeoTranslation(x, y, z));
63  i++;
64  }
65  }
66  geom->CloseGeometry();
67  geom->SetVisLevel(4);
68  top->Draw("ogl");
69 }
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition: TRandom.cxx:460
Definition: Rtypes.h:61
Double_t distance(const TPoint2 &p1, const TPoint2 &p2)
Definition: CsgOps.cxx:467
virtual void Draw(Option_t *option="")
draw top volume according to option
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
int Int_t
Definition: RtypesCore.h:41
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:501
TGeoVolume * MakeSphere(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t themin=0, Double_t themax=180, Double_t phimin=0, Double_t phimax=360)
Make in one step a volume pointing to a sphere shape with given medium.
Double_t x[n]
Definition: legend1.C:17
TGeoVolume * MakeBox(const char *name, TGeoMedium *medium, Double_t dx, Double_t dy, Double_t dz)
Make in one step a volume pointing to a box shape with given medium.
Float_t z[5]
Definition: Ifit.C:16
virtual void AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:948
void nucleus(Int_t nProtons=40, Int_t nNeutrons=60)
Definition: nucleus.C:5
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
Double_t Pi()
Definition: TMath.h:44
double Double_t
Definition: RtypesCore.h:55
static RooMathCoreReg dummy
Double_t y[n]
Definition: legend1.C:17
virtual void SetLineColor(Color_t lcolor)
Set the line color.
void SetNsegments(Int_t nseg)
Set number of segments for approximating circles in drawing.
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
Definition: Rtypes.h:61
Double_t Sqrt(Double_t x)
Definition: TMath.h:464