Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
nucleus.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gl
3/// Model of a nucleus built from TGeo classes.
4///
5/// \macro_code
6///
7/// \author Otto Schaile
8
9void nucleus(Int_t nProtons = 40, Int_t nNeutrons = 60)
10{
11 Double_t NeutronRadius = 60, ProtonRadius = 60, NucleusRadius, distance = 60;
12 Double_t vol = nProtons + nNeutrons;
13 vol = 3 * vol / (4 * TMath::Pi());
14
15 NucleusRadius = distance * TMath::Power(vol, 1. / 3.);
16 // cout << "NucleusRadius: " << NucleusRadius << endl;
17
18 TGeoManager *geom = new TGeoManager("nucleus", "Model of a nucleus");
19 geom->SetNsegments(40);
20 TGeoMaterial *matEmptySpace = new TGeoMaterial("EmptySpace", 0, 0, 0);
21 TGeoMaterial *matProton = new TGeoMaterial("Proton", .938, 1., 10000.);
22 TGeoMaterial *matNeutron = new TGeoMaterial("Neutron", .935, 0., 10000.);
23
24 TGeoMedium *EmptySpace = new TGeoMedium("Empty", 1, matEmptySpace);
25 TGeoMedium *Proton = new TGeoMedium("Proton", 1, matProton);
26 TGeoMedium *Neutron = new TGeoMedium("Neutron", 1, matNeutron);
27
28 // the space where the nucleus lives (top container volume)
29
30 Double_t worldx = 200.;
31 Double_t worldy = 200.;
32 Double_t worldz = 200.;
33
34 TGeoVolume *top = geom->MakeBox("WORLD", EmptySpace, worldx, worldy, worldz);
35 geom->SetTopVolume(top);
36
37 TGeoVolume *proton = geom->MakeSphere("proton", Proton, 0., ProtonRadius);
38 TGeoVolume *neutron = geom->MakeSphere("neutron", Neutron, 0., NeutronRadius);
39 proton->SetLineColor(kRed);
40 neutron->SetLineColor(kBlue);
41
42 Double_t x, y, z, dummy;
43 Int_t i = 0;
44 while (i < nProtons) {
45 gRandom->Rannor(x, y);
46 gRandom->Rannor(z, dummy);
47 if (TMath::Sqrt(x * x + y * y + z * z) < 1) {
48 x = (2 * x - 1) * NucleusRadius;
49 y = (2 * y - 1) * NucleusRadius;
50 z = (2 * z - 1) * NucleusRadius;
51 top->AddNode(proton, i, new TGeoTranslation(x, y, z));
52 i++;
53 }
54 }
55 i = 0;
56 while (i < nNeutrons) {
57 gRandom->Rannor(x, y);
58 gRandom->Rannor(z, dummy);
59 if (TMath::Sqrt(x * x + y * y + z * z) < 1) {
60 x = (2 * x - 1) * NucleusRadius;
61 y = (2 * y - 1) * NucleusRadius;
62 z = (2 * z - 1) * NucleusRadius;
63 top->AddNode(neutron, i + nProtons, new TGeoTranslation(x, y, z));
64 i++;
65 }
66 }
67 geom->CloseGeometry();
68 geom->SetVisLevel(4);
69 top->Draw("ogl");
70}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
The manager class for any TGeo geometry.
Definition TGeoManager.h:44
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
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.
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.
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
void SetNsegments(Int_t nseg)
Set number of segments for approximating circles in drawing.
Base class describing materials.
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:23
Class describing translations.
Definition TGeoMatrix.h:116
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
Add a TGeoNode to the list of nodes.
void Draw(Option_t *option="") override
draw top volume according to option
void SetLineColor(Color_t lcolor) override
Set the line color.
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:507
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:666
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:725
constexpr Double_t Pi()
Definition TMath.h:37