VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
Monopole
src
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
27
using namespace
std;
28
29
/// \cond CLASSIMP
30
ClassImp(
VMC::Monopole::DetectorConstruction
)
31
/// \endcond
32
33
namespace
VMC
34
{
35
namespace
Monopole
36
{
37
38
//_____________________________________________________________________________
39
DetectorConstruction::DetectorConstruction
()
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
//_____________________________________________________________________________
54
DetectorConstruction::~DetectorConstruction
()
55
{
56
/// Destructor
57
}
58
59
//
60
// private methods
61
//
62
63
//
64
// public methods
65
//
66
67
//_____________________________________________________________________________
68
void
DetectorConstruction::ConstructMaterials
()
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
//_____________________________________________________________________________
127
void
DetectorConstruction::ConstructGeometry
()
128
{
129
/// Contruct volumes using TGeo modeller
130
131
// Construct materials
132
ConstructMaterials
();
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
173
PrintParameters
();
174
}
175
176
//_____________________________________________________________________________
177
void
DetectorConstruction::PrintParameters
()
178
{
179
cout <<
"\n---------------------------------------------------------\n"
;
180
cout <<
"---> The Absorber is "
<<
fAbsorberSizeX
<<
" of "
181
<<
fAbsorberMaterial
<< endl;
182
cout <<
"\n---------------------------------------------------------\n"
;
183
}
184
185
//_____________________________________________________________________________
186
void
DetectorConstruction::SetAbsorberSizeX
(Double_t value)
187
{
188
if
(
fGeometryInitialized
) {
189
cerr <<
"Geometry alredy initialized: cannot set absorber sizeX"
<< endl;
190
return
;
191
}
192
193
if
(value > 0.0) {
194
fAbsorberSizeX
= value;
195
fWorldSizeX
= 1.2 *
fAbsorberSizeX
;
196
}
197
}
198
199
//_____________________________________________________________________________
200
void
DetectorConstruction::SetAbsorberSizeYZ
(Double_t value)
201
{
202
if
(
fGeometryInitialized
) {
203
cerr <<
"Geometry alredy initialized: cannot set absorber sizeXY"
<< endl;
204
return
;
205
}
206
207
if
(value > 0.0) {
208
fAbsorberSizeYZ
= value;
209
fWorldSizeYZ
= 1.2 *
fAbsorberSizeYZ
;
210
}
211
}
212
213
//_____________________________________________________________________________
214
void
DetectorConstruction::SetAbsorberMaterial
(
const
TString& name)
215
{
216
// search the material by its name
217
if
(
fGeometryInitialized
) {
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
//_____________________________________________________________________________
286
void
DetectorConstruction::SetMaxStepSize
(Double_t step)
287
{
288
if
(
fGeometryInitialized
) {
289
cerr <<
"Geometry alredy initialized: cannot set max step size"
<< endl;
290
return
;
291
}
292
293
fMaxStepSize
= step;
294
}
295
296
}
// namespace Monopole
297
}
TObject
VMC::Monopole::DetectorConstruction
The detector construction (via TGeo ).
Definition
DetectorConstruction.h:38
VMC::Monopole::DetectorConstruction::DetectorConstruction
DetectorConstruction()
Definition
DetectorConstruction.cxx:39
VMC::Monopole::DetectorConstruction::fWorldSizeYZ
Double_t fWorldSizeYZ
Definition
DetectorConstruction.h:73
VMC::Monopole::DetectorConstruction::fWorldSizeX
Double_t fWorldSizeX
Definition
DetectorConstruction.h:72
VMC::Monopole::DetectorConstruction::SetAbsorberSizeYZ
void SetAbsorberSizeYZ(Double_t sizeYZ)
Definition
DetectorConstruction.cxx:200
VMC::Monopole::DetectorConstruction::fAbsorberSizeX
Double_t fAbsorberSizeX
Definition
DetectorConstruction.h:70
VMC::Monopole::DetectorConstruction::SetAbsorberSizeX
void SetAbsorberSizeX(Double_t sizeX)
Definition
DetectorConstruction.cxx:186
VMC::Monopole::DetectorConstruction::fAbsorberMaterial
TString fAbsorberMaterial
Definition
DetectorConstruction.h:69
VMC::Monopole::DetectorConstruction::ConstructGeometry
void ConstructGeometry()
Definition
DetectorConstruction.cxx:127
VMC::Monopole::DetectorConstruction::~DetectorConstruction
virtual ~DetectorConstruction()
Definition
DetectorConstruction.cxx:54
VMC::Monopole::DetectorConstruction::SetMaxStepSize
void SetMaxStepSize(Double_t maxStepSize)
Definition
DetectorConstruction.cxx:286
VMC::Monopole::DetectorConstruction::fGeometryInitialized
Bool_t fGeometryInitialized
Definition
DetectorConstruction.h:75
VMC::Monopole::DetectorConstruction::PrintParameters
void PrintParameters()
Definition
DetectorConstruction.cxx:177
VMC::Monopole::DetectorConstruction::fMaxStepSize
Double_t fMaxStepSize
Definition
DetectorConstruction.h:74
VMC::Monopole::DetectorConstruction::fAbsorberSizeYZ
Double_t fAbsorberSizeYZ
Definition
DetectorConstruction.h:71
VMC::Monopole::DetectorConstruction::SetAbsorberMaterial
void SetAbsorberMaterial(const TString &name)
Definition
DetectorConstruction.cxx:214
VMC::Monopole::DetectorConstruction::ConstructMaterials
void ConstructMaterials()
Definition
DetectorConstruction.cxx:68
VMC::Monopole::DetectorConstruction::fWorldMaterial
TString fWorldMaterial
Definition
DetectorConstruction.h:68
VMC::Monopole
Definition
DetectorConstruction.h:29
VMC
Definition
FastSimulation.h:26
Generated on
for VMC Examples by
1.17.0