VMC Examples Version 6.8
Loading...
Searching...
No Matches
Ex03DetectorConstructionOld.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2014 - 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 Ex03DetectorConstructionOld.cxx
11/// \brief Implementation of the Ex03DetectorConstructionOld class
12///
13/// Geant4 ExampleN03 adapted to Virtual Monte Carlo \n
14/// Id: ExN03DetectorConstruction.cc,v 1.11 2002/01/09 17:24:12 ranjard Exp \n
15/// GEANT4 tag $Name: $
16///
17/// 11/12/2008:
18/// Added new material (Mylar)according to:
19/// Id: ExN03DetectorConstruction.cc,v 1.24 2008/08/12 20:00:03 gum Exp
20/// GEANT4 tag Name: geant4-09-01-ref-09
21///
22/// \date 06/03/2002
23/// \author I. Hrivnacova; IPN, Orsay
24
25#include <Riostream.h>
26#include <TGeoManager.h>
27#include <TGeoMatrix.h>
28#include <TGeoVolume.h>
29#include <TVirtualMC.h>
30
31#include "Ex03DetectorConstructionOld.h"
32
33using namespace std;
34
35/// \cond CLASSIMP
37 /// \endcond
38
39 //_____________________________________________________________________________
41 : TObject(),
42 fNbOfLayers(0),
43 fWorldSizeX(0.),
44 fWorldSizeYZ(0.),
45 fCalorSizeYZ(0.),
46 fCalorThickness(0.),
47 fLayerThickness(0.),
48 fAbsorberThickness(0.),
49 fGapThickness(0.),
50 fDefaultMaterial("Galactic"),
51 fAbsorberMaterial("Lead"),
52 fGapMaterial("liquidArgon")
53{
54 /// Default constuctor
55
56 // default parameter values of the calorimeter (in cm)
57 fAbsorberThickness = 1.;
58 fGapThickness = 0.5;
59 fNbOfLayers = 10;
60 fCalorSizeYZ = 10.;
61
62 ComputeCalorParameters();
63}
64
65//_____________________________________________________________________________
67{
68 /// Destructor
69}
70
71//
72// private methods
73//
74
75//_____________________________________________________________________________
77{
78 /// Compute derived parameters of the calorimeter
79
82
85}
86
87//
88// public methods
89//
90
91//_____________________________________________________________________________
93{
94 /// Construct materials using VMC functions
95
96 //
97 // Tracking medias (defaut parameters)
98 //
99
100 Int_t ifield = 2; // User defined magnetic field
101 Double_t fieldm = 10.; // Maximum field value (in kiloGauss)
102 Double_t epsil = .001; // Tracking precision,
103 Double_t stemax = -0.01; // Maximum displacement for multiple scat
104 Double_t tmaxfd = -20.; // Maximum angle due to field deflection
105 Double_t deemax = -.3; // Maximum fractional energy loss, DLS
106 Double_t stmin = -.8;
107
108 // stemax = 1.0; // Maximum step limit
109
110 //--------- Material definition ---------
111
112 TString name;
113 Double_t a;
114 Double_t z;
115 Double_t density;
116 Double_t radl;
117 Double_t absl;
118 Float_t* ubuf = 0;
119
120 //
121 // define simple materials
122 //
123
124 name = "Aluminium";
125 a = 26.98;
126 z = 13.;
127 density = 2.700;
128 radl = 8.893;
129 absl = 0.1;
130 Int_t imat;
131 gMC->Material(imat, name.Data(), a, z, density, radl, absl, ubuf, 0);
132 Int_t mediumId;
133 gMC->Medium(mediumId, name.Data(), imat, 0, ifield, fieldm, tmaxfd, stemax,
134 deemax, epsil, stmin, ubuf, 0);
135
136 name = "liquidArgon";
137 a = 39.95;
138 z = 18.;
139 density = 1.390;
140 radl = 14.064;
141 absl = 0.1;
142 gMC->Material(imat, name.Data(), a, z, density, radl, absl, ubuf, 0);
143 gMC->Medium(mediumId, name.Data(), imat, 0, ifield, fieldm, tmaxfd, stemax,
144 deemax, epsil, stmin, ubuf, 0);
145
146 name = "Lead";
147 a = 207.19;
148 z = 82.;
149 density = 11.35;
150 radl = 0.5612;
151 absl = 0.1;
152 gMC->Material(imat, name.Data(), a, z, density, radl, absl, ubuf, 0);
153 gMC->Medium(mediumId, name.Data(), imat, 0, ifield, fieldm, tmaxfd, stemax,
154 deemax, epsil, stmin, ubuf, 0);
155
156 //
157 // define a material from elements. case 1: chemical molecule
158 //
159
160 name = "Water";
161 Double_t aw2[2] = { 1.01, 16.00 };
162 Double_t zw2[2] = { 1.0, 8.0 };
163 Double_t ww2[2] = { 2., 1. };
164 density = 1.000;
165 gMC->Mixture(imat, name.Data(), aw2, zw2, density, -2, ww2);
166 gMC->Medium(mediumId, name.Data(), imat, 0, ifield, fieldm, tmaxfd, stemax,
167 deemax, epsil, stmin, ubuf, 0);
168
169 name = "Scintillator";
170 Double_t as2[2] = { 1.01, 12.01 };
171 Double_t zs2[2] = { 1.0, 6.0 };
172 Double_t ws2[2] = { 10., 9. };
173 density = 1.032;
174 gMC->Mixture(imat, name.Data(), as2, zs2, density, -2, ws2);
175 gMC->Medium(mediumId, name.Data(), imat, 0, ifield, fieldm, tmaxfd, stemax,
176 deemax, epsil, stmin, ubuf, 0);
177
178 name = "Mylar";
179 Double_t am2[3] = { 12.01, 1.01, 16.00 };
180 Double_t zm2[3] = { 6.0, 1.0, 8.0 };
181 Double_t wm2[3] = { 10., 8., 4. };
182 density = 1.397;
183 gMC->Mixture(imat, name.Data(), am2, zm2, density, -3, wm2);
184 gMC->Medium(mediumId, name.Data(), imat, 0, ifield, fieldm, tmaxfd, stemax,
185 deemax, epsil, stmin, ubuf, 0);
186
187 name = "quartz";
188 Double_t aq2[2] = { 28.09, 16.00 };
189 Double_t zq2[2] = { 14.0, 8.0 };
190 Double_t wq2[2] = { 1., 2. };
191 density = 2.200;
192 gMC->Mixture(imat, name.Data(), aq2, zq2, density, -2, wq2);
193 gMC->Medium(mediumId, name.Data(), imat, 0, ifield, fieldm, tmaxfd, stemax,
194 deemax, epsil, stmin, ubuf, 0);
195
196 //
197 // define a material from elements. case 2: mixture by fractional mass
198 //
199
200 name = "Air";
201 Double_t aa2[2] = { 14.01, 16.00 };
202 Double_t za2[2] = { 7.0, 8.0 };
203 Double_t wa2[2] = { 0.7, 0.3 };
204 density = 1.29e-03;
205 gMC->Mixture(imat, name.Data(), aa2, za2, density, 2, wa2);
206 gMC->Medium(mediumId, name.Data(), imat, 0, ifield, fieldm, tmaxfd, stemax,
207 deemax, epsil, stmin, ubuf, 0);
208
209 //
210 // !! NOT SUPPORTED BY VMC
211 //
212 // define a material from elements and/or others materials (mixture of
213 // mixtures)
214 //
215 // density = 0.200*g/cm3;
216 // G4Material* Aerog = new G4Material(name="Aerogel", density, ncomponents=3);
217 // Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent);
218 // Aerog->AddMaterial(H2O , fractionmass=37.4*perCent);
219 // Aerog->AddElement (C , fractionmass= 0.1*perCent);
220
221 //
222 // !! NOT SUPPORTED BY VMC
223 //
224 // examples of gas in non STP conditions
225 //
226 //
227 // density = 27.*mg/cm3;
228 // pressure = 50.*atmosphere;
229 // temperature = 325.*kelvin;
230 // G4Material* CO2 = new G4Material(name="CarbonicGas", density,
231 // ncomponents=2,
232 // kStateGas,temperature,pressure);
233 // CO2->AddElement(C, natoms=1);
234 // CO2->AddElement(O, natoms=2);
235 //
236 //
237 // !! NOT SUPPORTED BY VMC
238 //
239 // density = 0.3*mg/cm3;
240 // pressure = 2.*atmosphere;
241 // temperature = 500.*kelvin;
242 // G4Material* steam = new G4Material(name="WaterSteam", density,
243 // ncomponents=1,
244 // kStateGas,temperature,pressure);
245 // steam->AddMaterial(H2O, fractionmass=1.);
246
247 name = "Galactic";
248 a = 1.e-16;
249 z = 1.e-16;
250 density = 1.e-16;
251 radl = 1.e16;
252 absl = 1.e16; //??
253 gMC->Material(imat, name.Data(), a, z, density, radl, absl, ubuf, 0);
254 gMC->Medium(mediumId, name.Data(), imat, 0, ifield, fieldm, tmaxfd, stemax,
255 deemax, epsil, stmin, ubuf, 0);
256}
257
258//_____________________________________________________________________________
259void Ex03DetectorConstructionOld::ConstructGeometry(Bool_t useReflection)
260{
261 /// Construct volumes using VMC functions. In the optional mixed-geometry
262 /// test, add the reflected sensitive placements directly with TGeo.
263 /// \param useReflection Enable the mixed VMC/ROOT reflected-volume test
264
265 // Complete the Calor parameters definition
267
268 //
269 // World
270 //
271
272 Double_t world[3];
273 world[0] = fWorldSizeX / 2.;
274 world[1] = fWorldSizeYZ / 2.;
275 world[2] = fWorldSizeYZ / 2.;
276 gMC->Gsvolu("WRLD", "BOX", gMC->MediumId(fDefaultMaterial.Data()), world, 3);
277
278 //
279 // Calorimeter
280 //
281 if (fCalorThickness > 0.) {
282
283 Double_t calo[3];
284 calo[0] = fCalorThickness / 2.;
285 calo[1] = fCalorSizeYZ / 2.;
286 calo[2] = fCalorSizeYZ / 2.;
287 gMC->Gsvolu("CALO", "BOX", gMC->MediumId(fDefaultMaterial.Data()), calo, 3);
288
289 Double_t posX = 0.;
290 Double_t posY = 0.;
291 Double_t posZ = 0.;
292 gMC->Gspos("CALO", 1, "WRLD", posX, posY, posZ, 0, "ONLY");
293
294 // Divide calorimeter along X axis to place layers
295 //
296 gMC->Gsdvn("CELL", "CALO", fNbOfLayers, 1);
297
298 //
299 // Layer
300 //
301 Double_t layer[3];
302 layer[0] = fLayerThickness / 2.;
303 layer[1] = fCalorSizeYZ / 2.;
304 layer[2] = fCalorSizeYZ / 2.;
305 gMC->Gsvolu(
306 "LAYE", "BOX", gMC->MediumId(fDefaultMaterial.Data()), layer, 3);
307
308 posX = 0.;
309 posY = 0.;
310 posZ = 0.;
311 gMC->Gspos("LAYE", 1, "CELL", posX, posY, posZ, 0, "ONLY");
312 }
313
314 //
315 // Absorber
316 //
317
318 if (fAbsorberThickness > 0.) {
319
320 Double_t abso[3];
321 abso[0] = fAbsorberThickness / (useReflection ? 4. : 2.);
322 abso[1] = fCalorSizeYZ / 2.;
323 abso[2] = fCalorSizeYZ / 2.;
324 gMC->Gsvolu(
325 "ABSO", "BOX", gMC->MediumId(fAbsorberMaterial.Data()), abso, 3);
326
327 Double_t posX = -fGapThickness / 2.;
328 Double_t posY = 0.;
329 Double_t posZ = 0.;
330 if (useReflection) {
331 // VMC defines the ordinary placement; ROOT adds its reflected copy.
332 gMC->Gspos("ABSO", 1, "LAYE", posX + abso[0], posY, posZ, 0, "ONLY");
333 auto volume = gGeoManager ? gGeoManager->GetVolume("ABSO") : nullptr;
334 auto mother = gGeoManager ? gGeoManager->GetVolume("LAYE") : nullptr;
335 if (!volume || !mother || gGeoManager->IsClosed()) {
336 Fatal("ConstructGeometry",
337 "Reflected VMC geometry requires geomVMC+RootToGeant4");
338 return;
339 }
340 auto reflection = new TGeoHMatrix();
341 reflection->ReflectX(kTRUE);
342 reflection->SetDx(posX - abso[0]);
343 mother->AddNode(volume, 2, reflection);
344 }
345 else {
346 gMC->Gspos("ABSO", 1, "LAYE", posX, posY, posZ, 0, "ONLY");
347 }
348 }
349
350 //
351 // Gap
352 //
353
354 if (fGapThickness > 0.) {
355
356 Double_t gap[3];
357 gap[0] = fGapThickness / (useReflection ? 4. : 2.);
358 gap[1] = fCalorSizeYZ / 2.;
359 gap[2] = fCalorSizeYZ / 2.;
360 gMC->Gsvolu("GAPX", "BOX", gMC->MediumId(fGapMaterial.Data()), gap, 3);
361
362 Double_t posX = fAbsorberThickness / 2.;
363 Double_t posY = 0.;
364 Double_t posZ = 0.;
365 if (useReflection) {
366 // VMC defines the ordinary placement; ROOT adds its reflected copy.
367 gMC->Gspos("GAPX", 1, "LAYE", posX + gap[0], posY, posZ, 0, "ONLY");
368 auto volume = gGeoManager ? gGeoManager->GetVolume("GAPX") : nullptr;
369 auto mother = gGeoManager ? gGeoManager->GetVolume("LAYE") : nullptr;
370 if (!volume || !mother || gGeoManager->IsClosed()) {
371 Fatal("ConstructGeometry",
372 "Reflected VMC geometry requires geomVMC+RootToGeant4");
373 return;
374 }
375 auto reflection = new TGeoHMatrix();
376 reflection->ReflectX(kTRUE);
377 reflection->SetDx(posX - gap[0]);
378 mother->AddNode(volume, 2, reflection);
379 }
380 else {
381 gMC->Gspos("GAPX", 1, "LAYE", posX, posY, posZ, 0, "ONLY");
382 }
383 }
384
385 /*
386 //
387 // Visualization attributes
388 //
389 logicWorld->SetVisAttributes (G4VisAttributes::Invisible);
390 G4VisAttributes* simpleBoxVisAtt= new
391 G4VisAttributes(G4Colour(1.0,1.0,1.0));
392 simpleBoxVisAtt->SetVisibility(true);
393 logicCalor->SetVisAttributes(simpleBoxVisAtt);
394 */
395
397}
398
399//_____________________________________________________________________________
401{
402 /// Print calorimeter parameters
403
404 cout << "\n------------------------------------------------------------"
405 << "\n---> The calorimeter is " << fNbOfLayers << " layers of: [ "
406 << fAbsorberThickness << "cm of " << fAbsorberMaterial << " + "
407 << fGapThickness << "cm of " << fGapMaterial << " ] "
408 << "\n------------------------------------------------------------\n";
409}
410
411//_____________________________________________________________________________
413{
414 /// Set the number of layers.
415 /// \param value The new number of calorimeter layers
416
417 fNbOfLayers = value;
418}
419
420//_____________________________________________________________________________
422 const TString& materialName)
423{
424 /// Set default material
425 /// \param materialName The new default material name.
426
427 fDefaultMaterial = materialName;
428}
429
430//_____________________________________________________________________________
432 const TString& materialName)
433{
434 /// Set absorer material
435 /// \param materialName The new absorber material name.
436
437 fAbsorberMaterial = materialName;
438}
439
440//_____________________________________________________________________________
441void Ex03DetectorConstructionOld::SetGapMaterial(const TString& materialName)
442{
443 /// Set gap material
444 /// \param materialName The new gap material name.
445
446 fGapMaterial = materialName;
447}
448
449//_____________________________________________________________________________
451{
452 /// Change the transverse size and recompute the calorimeter parameters
453 /// \param value The new calorimeter tranverse size
454
455 fCalorSizeYZ = value;
456}
457
458//_____________________________________________________________________________
460{
461 /// Change the absorber thickness and recompute the calorimeter parameters
462 /// \param value The new absorber thickness
463
464 fAbsorberThickness = value;
465}
466
467//_____________________________________________________________________________
469{
470 /// Change the gap thickness and recompute the calorimeter parameters
471 /// \param value The new gap thickness
472
473 fGapThickness = value;
474}
475
476/*
477//_____________________________________________________________________________
478void Ex03DetectorConstructionOld::UpdateGeometry()
479{
480// Not available in VMC
481}
482*/
The old detector construction (via VMC functions).
Int_t fNbOfLayers
The number of calorimeter layers.
TString fGapMaterial
The gap material name.
Double_t fWorldSizeYZ
The world size y,z component.
Double_t fCalorSizeYZ
The calorimeter size y,z component.
TString fDefaultMaterial
The default material name.
void SetGapMaterial(const TString &materialName)
TString fAbsorberMaterial
The absorber material name.
void SetAbsorberMaterial(const TString &materialName)
Double_t fWorldSizeX
The world size x component.
Double_t fAbsorberThickness
The absorber thickness.
Double_t fCalorThickness
The calorimeter thickness.
void SetDefaultMaterial(const TString &materialName)
Double_t fLayerThickness
The calorimeter layer thickness.
Double_t fGapThickness
The gap thickness.