Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
10{
12 ProtonRadius = 60,
14 distance = 60;
16 vol = 3 * vol / (4 * TMath::Pi());
17
18 NucleusRadius = distance * TMath::Power(vol, 1./3.);
19// cout << "NucleusRadius: " << NucleusRadius << endl;
20
21 TGeoManager * geom = new TGeoManager("nucleus", "Model of a nucleus");
22 geom->SetNsegments(40);
23 TGeoMaterial *matEmptySpace = new TGeoMaterial("EmptySpace", 0, 0, 0);
24 TGeoMaterial *matProton = new TGeoMaterial("Proton" , .938, 1., 10000.);
25 TGeoMaterial *matNeutron = new TGeoMaterial("Neutron" , .935, 0., 10000.);
26
28 TGeoMedium *Proton = new TGeoMedium("Proton", 1, matProton);
29 TGeoMedium *Neutron = new TGeoMedium("Neutron",1, matNeutron);
30
31// the space where the nucleus lives (top container volume)
32
33 Double_t worldx = 200.;
34 Double_t worldy = 200.;
35 Double_t worldz = 200.;
36
37 TGeoVolume *top = geom->MakeBox("WORLD", EmptySpace, worldx, worldy, worldz);
38 geom->SetTopVolume(top);
39
40 TGeoVolume * proton = geom->MakeSphere("proton", Proton, 0., ProtonRadius);
41 TGeoVolume * neutron = geom->MakeSphere("neutron", Neutron, 0., NeutronRadius);
42 proton->SetLineColor(kRed);
43 neutron->SetLineColor(kBlue);
44
45 Double_t x, y, z, dummy;
46 Int_t i = 0;
47 while ( i< nProtons) {
48 gRandom->Rannor(x, y);
49 gRandom->Rannor(z,dummy);
50 if ( TMath::Sqrt(x*x + y*y + z*z) < 1) {
51 x = (2 * x - 1) * NucleusRadius;
52 y = (2 * y - 1) * NucleusRadius;
53 z = (2 * z - 1) * NucleusRadius;
54 top->AddNode(proton, i, new TGeoTranslation(x, y, z));
55 i++;
56 }
57 }
58 i = 0;
59 while ( i < nNeutrons) {
60 gRandom->Rannor(x, y);
61 gRandom->Rannor(z,dummy);
62 if ( TMath::Sqrt(x*x + y*y + z*z) < 1) {
63 x = (2 * x - 1) * NucleusRadius;
64 y = (2 * y - 1) * NucleusRadius;
65 z = (2 * z - 1) * NucleusRadius;
66 top->AddNode(neutron, i + nProtons, new TGeoTranslation(x, y, z));
67 i++;
68 }
69 }
70 geom->CloseGeometry();
71 geom->SetVisLevel(4);
72 top->Draw("ogl");
73}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
The manager class for any TGeo geometry.
Definition TGeoManager.h:44
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
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:662
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:721
constexpr Double_t Pi()
Definition TMath.h:37