VMC Examples Version 6.6
Loading...
Searching...
No Matches
DetectorConstruction.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2018 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
10/// \file DetectorConstruction.cxx
11/// \brief Implementation of the DetectorConstruction class
12///
13/// Geant4 Monopole example adapted to Virtual Monte Carlo \n
14///
15/// \date 15/07/2018
16/// \author I. Hrivnacova; IPN, Orsay
17
18#include <Riostream.h>
19#include <TGeoElement.h>
20#include <TGeoManager.h>
21#include <TGeoMaterial.h>
22#include <TList.h>
23#include <TVirtualMC.h>
24
25#include "DetectorConstruction.h"
26
27using namespace std;
28
29/// \cond CLASSIMP
31 /// \endcond
32
33 namespace VMC
34{
35 namespace Monopole
36 {
37
38 //_____________________________________________________________________________
40 : TObject(),
41 fWorldMaterial("Galactic"),
42 fAbsorberMaterial("Aluminium"),
43 fAbsorberSizeX(10.),
44 fAbsorberSizeYZ(10.),
45 fWorldSizeX(1.2 * fAbsorberSizeX),
46 fWorldSizeYZ(1.2 * fAbsorberSizeYZ),
47 fMaxStepSize(0.5),
48 fGeometryInitialized(false)
49 {
50 /// Default constuctor
51 }
52
53 //_____________________________________________________________________________
55 {
56 /// Destructor
57 }
58
59 //
60 // private methods
61 //
62
63 //
64 // public methods
65 //
66
67 //_____________________________________________________________________________
69 {
70 /// Construct materials using TGeo modeller
71
72 //
73 // Tracking medias (defaut parameters)
74 //
75
76 // Create Root geometry manager
77 new TGeoManager("Monopole_geometry", "Monopole VMC example geometry");
78
79 //--------- Material definition ---------
80
81 TString name; // Material name
82 Double_t a; // Mass of a mole in g/mole
83 Double_t z; // Atomic number
84 Double_t density; // Material density in g/cm3
85
86 //
87 // define simple materials
88 //
89
90 new TGeoMaterial("Aluminium", a = 26.98, z = 13., density = 2.700);
91 new TGeoMaterial("Si", a = 28.085, z = 14., density = 2.330);
92 new TGeoMaterial("Galactic", a = 1.e-16, z = 1.e-16, density = 1.e-16);
93
94 //
95 // Tracking media
96 //
97
98 // Paremeter for tracking media
99 Double_t param[20];
100 param[0] = 0; // isvol - Not used
101 param[1] = 2; // ifield - User defined magnetic field
102 param[2] = 10.; // fieldm - Maximum field value (in kiloGauss)
103 param[3] = -20.; // tmaxfd - Maximum angle due to field deflection
104 param[4] = -0.01; // stemax - Maximum displacement for multiple scat
105 param[5] = -.3; // deemax - Maximum fractional energy loss, DLS
106 param[6] = .001; // epsil - Tracking precision
107 param[7] = -.8; // stmin
108 for (Int_t i = 8; i < 20; ++i) param[i] = 0.;
109
110 Int_t mediumId = 0;
111 TList* materials = gGeoManager->GetListOfMaterials();
112 TIter next(materials);
113 while (TObject* obj = next()) {
114 TGeoMaterial* material = (TGeoMaterial*)obj;
115 // set step limit to other than world material
116 if (material->GetName() != TString("Galactic")) {
117 param[4] = fMaxStepSize;
118 }
119 else {
120 param[4] = -0.01;
121 }
122 new TGeoMedium(material->GetName(), ++mediumId, material, param);
123 }
124 }
125
126 //_____________________________________________________________________________
128 {
129 /// Contruct volumes using TGeo modeller
130
131 // Construct materials
133
134 // Media Ids
135 Int_t worldMediumId =
136 gGeoManager->GetMedium(fWorldMaterial.Data())->GetId();
137 Int_t absorberMediumId =
138 gGeoManager->GetMedium(fAbsorberMaterial.Data())->GetId();
139
140 //
141 // World
142 //
143
144 Double_t world[3];
145 world[0] = fWorldSizeX / 2.;
146 world[1] = fWorldSizeYZ / 2.;
147 world[2] = fWorldSizeYZ / 2.;
148 TGeoVolume* top =
149 gGeoManager->Volume("World", "BOX", worldMediumId, world, 3);
150 gGeoManager->SetTopVolume(top);
151
152 //
153 // Absorber
154 //
155 Double_t absorber[3];
156 absorber[0] = fAbsorberSizeX / 2.;
157 absorber[1] = fAbsorberSizeYZ / 2.;
158 absorber[2] = fAbsorberSizeYZ / 2.;
159 gGeoManager->Volume("Absorber", "BOX", absorberMediumId, absorber, 3);
160
161 Double_t posX = 0.;
162 Double_t posY = 0.;
163 Double_t posZ = 0.;
164 Double_t* ubuf = 0;
165 gGeoManager->Node("Absorber", 1, "World", posX, posY, posZ, 0, kTRUE, ubuf);
166
167 // close geometry
168 gGeoManager->CloseGeometry();
169
170 // notify VMC about Root geometry
171 gMC->SetRootGeometry();
172
174 }
175
176 //_____________________________________________________________________________
178 {
179 cout << "\n---------------------------------------------------------\n";
180 cout << "---> The Absorber is " << fAbsorberSizeX << " of "
181 << fAbsorberMaterial << endl;
182 cout << "\n---------------------------------------------------------\n";
183 }
184
185 //_____________________________________________________________________________
187 {
189 cerr << "Geometry alredy initialized: cannot set absorber sizeX" << endl;
190 return;
191 }
192
193 if (value > 0.0) {
194 fAbsorberSizeX = value;
196 }
197 }
198
199 //_____________________________________________________________________________
201 {
203 cerr << "Geometry alredy initialized: cannot set absorber sizeXY" << endl;
204 return;
205 }
206
207 if (value > 0.0) {
208 fAbsorberSizeYZ = value;
210 }
211 }
212
213 //_____________________________________________________________________________
215 {
216 // search the material by its name
218 cerr << "Geometry alredy initialized: cannot set absorber material"
219 << endl;
220 return;
221 }
222
223 fAbsorberMaterial = name;
224 }
225
226 //_____________________________________________________________________________
227
228 // void DetectorConstruction::SetMagField(Double_t fieldValue)
229 // {
230 // fMonFieldSetup->SetMagField(fieldValue);
231
232 // //apply a global uniform magnetic field along Z axis
233 // G4FieldManager * fieldMgr =
234 // G4TransportationManager::GetTransportationManager()->GetFieldManager();
235
236 // if (fMagField) { delete fMagField; } //delete the existing magn field
237
238 // if (fieldValue != 0.) // create a new one if non nul
239 // {
240 // fMagField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue));
241 // fieldMgr->SetDetectorField(fMagField);
242 // fieldMgr->CreateChordFinder(fMagField);
243 // }
244 // else
245 // {
246 // fMagField = 0;
247 // fieldMgr->SetDetectorField(fMagField);
248 // }
249 // }
250
251 // //_____________________________________________________________________________
252 // void DetectorConstruction::ConstructSDandField()
253 // {
254
255 // // Define magnetic field
256 // bool bNewFieldValue = false;
257 // if ( fFieldMessenger.Get() != 0 ) {
258 // G4ThreeVector fieldSet = fFieldMessenger.Get()->GetFieldValue();
259 // if(fieldSet.z()!=fZMagFieldValue) bNewFieldValue = true;
260 // }
261 // else bNewFieldValue = true;
262
263 // // Monopole particule specific magnetic field
264 // if(bNewFieldValue&&fZMagFieldValue!=0.)
265 // fMonFieldSetup->SetMagField(fZMagFieldValue, true);
266
267 // if ( bNewFieldValue ) {
268 // // Create global magnetic field messenger.
269 // // Uniform magnetic field is then created automatically if
270 // // the field value is not zero.
271
272 // if(fZMagFieldValue!=0.)
273 // {
274 // G4ThreeVector fieldValue = G4ThreeVector(0.,0.,fZMagFieldValue);
275 // G4GlobalMagFieldMessenger* msg =
276 // new G4GlobalMagFieldMessenger(fieldValue);
277 // msg->SetVerboseLevel(1);
278 // G4AutoDelete::Register(msg);
279 // fFieldMessenger.Put( msg );
280 // }
281 // }
282
283 // }
284
285 //_____________________________________________________________________________
287 {
289 cerr << "Geometry alredy initialized: cannot set max step size" << endl;
290 return;
291 }
292
293 fMaxStepSize = step;
294 }
295
296 } // namespace Monopole
297}
The detector construction (via TGeo )
void SetAbsorberMaterial(const TString &name)