VMC Examples Version 6.6
Loading...
Searching...
No Matches
Ex03cDetectorConstruction.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 Ex03cDetectorConstruction.cxx
11/// \brief Implementation of the Ex03cDetectorConstruction 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///
16/// \date 21/08/2019
17/// \author Benedikt Volkel, CERN
18
19#include <Riostream.h>
20#include <TGeoElement.h>
21#include <TGeoManager.h>
22#include <TGeoMaterial.h>
23#include <TList.h>
24#include <TMCManager.h>
25#include <TThread.h>
26#include <TVirtualMC.h>
27
28#include <set>
29
31
32using namespace std;
33
34/// \cond CLASSIMP
36 /// \endcond
37
38 //_____________________________________________________________________________
40 : TObject(),
41 fNbOfLayers(0),
42 fWorldSizeX(0.),
43 fWorldSizeYZ(0.),
44 fCalorSizeYZ(0.),
45 fCalorThickness(0.),
46 fLayerThickness(0.),
47 fAbsorberThickness(0.),
48 fGapThickness(0.),
49 fDefaultMaterial("Galactic"),
50 fAbsorberMaterial("Lead"),
51 fGapMaterial("liquidArgon"),
52 fMC(nullptr),
53 fConnectedToMCManager(kFALSE)
54
55{
56 /// Default constuctor
57
58 // default parameter values of the calorimeter (in cm)
59 fAbsorberThickness = 1.;
60 fGapThickness = 0.5;
61 fNbOfLayers = 10;
62 fCalorSizeYZ = 10.;
63
64 ComputeCalorParameters();
65
66 if (TMCManager::Instance()) {
67 TMCManager::Instance()->ConnectEnginePointer(fMC);
68 fConnectedToMCManager = kTRUE;
69 }
70}
71
72//_____________________________________________________________________________
77
78//
79// private methods
80//
81
82//_____________________________________________________________________________
93
94//
95// public methods
96//
97
98//_____________________________________________________________________________
100{
101 /// Construct materials using TGeo modeller
102
103 //
104 // Tracking medias (defaut parameters)
105 //
106
107 // Create Root geometry manager
108 new TGeoManager("E03_geometry", "E03 VMC example geometry");
109
110 //--------- Material definition ---------
111
112 TString name; // Material name
113 Double_t a; // Mass of a mole in g/mole
114 Double_t z; // Atomic number
115 Double_t density; // Material density in g/cm3
116
117 //
118 // define simple materials
119 //
120
121 new TGeoMaterial("Aluminium", a = 26.98, z = 13., density = 2.700);
122
123 new TGeoMaterial("liquidArgon", a = 39.95, z = 18., density = 1.390);
124
125 new TGeoMaterial("Lead", a = 207.19, z = 82., density = 11.35);
126
127 //
128 // define a material from elements. case 1: chemical molecule
129 //
130
131 // Elements
132
133 TGeoElement* elH = new TGeoElement("Hydrogen", "H", z = 1, a = 1.01);
134 TGeoElement* elC = new TGeoElement("Carbon", "C", z = 6., a = 12.01);
135 TGeoElement* elN = new TGeoElement("Nitrogen", "N", z = 7., a = 14.01);
136 TGeoElement* elO = new TGeoElement("Oxygen", "O", z = 8., a = 16.00);
137 TGeoElement* elSi = new TGeoElement("Silicon", "Si", z = 14., a = 28.09);
138
139 /*
140 // define an Element from isotopes, by relative abundance
141 // (cannot be done with TGeo)
142
143 G4Isotope* U5 = new G4Isotope("U235", iz=92, n=235, a=235.01*g/mole);
144 G4Isotope* U8 = new G4Isotope("U238", iz=92, n=238, a=238.03*g/mole);
145
146 G4Element* U = new G4Element("enriched Uranium",symbol="U",ncomponents=2);
147 U->AddIsotope(U5, abundance= 90.*perCent);
148 U->AddIsotope(U8, abundance= 10.*perCent);
149 */
150
151 TGeoMixture* matH2O = new TGeoMixture("Water", 2, density = 1.000);
152 matH2O->AddElement(elH, 2);
153 matH2O->AddElement(elO, 1);
154 // overwrite computed meanExcitationEnergy with ICRU recommended value
155 // (cannot be done with TGeo)
156 // H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV);
157
158 TGeoMixture* matSci = new TGeoMixture("Scintillator", 2, density = 1.032);
159 matSci->AddElement(elC, 9);
160 matSci->AddElement(elH, 10);
161
162 TGeoMixture* matMyl = new TGeoMixture("Mylar", 3, density = 1.397);
163 matMyl->AddElement(elC, 10);
164 matMyl->AddElement(elH, 8);
165 matMyl->AddElement(elO, 4);
166
167 TGeoMixture* matSiO2 = new TGeoMixture("quartz", 2, density = 2.200);
168 matSiO2->AddElement(elSi, 1);
169 matSiO2->AddElement(elO, 2);
170
171 //
172 // define a material from elements. case 2: mixture by fractional mass
173 //
174
175 TGeoMixture* matAir = new TGeoMixture("Air", 2, density = 1.29e-03);
176 matAir->AddElement(elN, 0.7);
177 matAir->AddElement(elO, 0.3);
178
179 //
180 // Define a material from elements and/or others materials (mixture of
181 // mixtures)
182 //
183
184 TGeoMixture* matAerog = new TGeoMixture("Aerogel", 3, density = 0.200);
185 matAerog->AddElement(matSiO2, 0.625);
186 matAerog->AddElement(matH2O, 0.374);
187 matAerog->AddElement(elC, 0.001);
188
189 //
190 // examples of gas in non STP conditions
191 //
192
193 TGeoMixture* matCO2 = new TGeoMixture("CarbonicGas", 2, density = 1.842e-03);
194 matCO2->AddElement(elC, 1);
195 matCO2->AddElement(elO, 2);
196
197 Double_t atmosphere = 6.32421e+08;
198 Double_t pressure = 50. * atmosphere;
199 Double_t temperature = 325.;
200 matCO2->SetPressure(pressure);
201 matCO2->SetTemperature(temperature);
202 matCO2->SetState(TGeoMaterial::kMatStateGas);
203
204 TGeoMixture* matSteam = new TGeoMixture("WaterSteam", 1, density = 0.3e-03);
205 matSteam->AddElement(matH2O, 1.0);
206
207 pressure = 2. * atmosphere;
208 temperature = 500.;
209 matSteam->SetPressure(pressure);
210 matSteam->SetTemperature(temperature);
211 matSteam->SetState(TGeoMaterial::kMatStateGas);
212
213 //
214 // examples of vacuum
215 //
216
217 new TGeoMaterial("Galactic", a = 1.e-16, z = 1.e-16, density = 1.e-16);
218
219 TGeoMixture* matBeam = new TGeoMixture("Beam", 1, density = 1.e-5);
220 matBeam->AddElement(matAir, 1.0);
221
222 pressure = 2. * atmosphere;
223 temperature = STP_temperature;
224 matBeam->SetPressure(pressure);
225 matBeam->SetTemperature(temperature);
226 matBeam->SetState(TGeoMaterial::kMatStateGas);
227
228 //
229 // Tracking media
230 //
231
232 // Paremeter for tracking media
233 Double_t param[20];
234 param[0] = 0; // isvol - Not used
235 param[1] = 2; // ifield - User defined magnetic field
236 param[2] = 10.; // fieldm - Maximum field value (in kiloGauss)
237 param[3] = -20.; // tmaxfd - Maximum angle due to field deflection
238 param[4] = -0.01; // stemax - Maximum displacement for multiple scat
239 param[5] = -.3; // deemax - Maximum fractional energy loss, DLS
240 param[6] = .001; // epsil - Tracking precision
241 param[7] = -.8; // stmin
242 for (Int_t i = 8; i < 20; ++i) param[i] = 0.;
243
244 Int_t mediumId = 0;
245 TList* materials = gGeoManager->GetListOfMaterials();
246 TIter next(materials);
247 while (TObject* obj = next()) {
248 TGeoMaterial* material = (TGeoMaterial*)obj;
249 new TGeoMedium(material->GetName(), ++mediumId, material, param);
250 }
251}
252
253//_____________________________________________________________________________
255{
256 /// Contruct volumes using TGeo modeller
257
258 // Complete the Calor parameters definition
260
261 Double_t* ubuf = 0;
262
263 // Media Ids
264 Int_t defaultMediumId =
265 gGeoManager->GetMedium(fDefaultMaterial.Data())->GetId();
266 Int_t absorberMediumId =
267 gGeoManager->GetMedium(fAbsorberMaterial.Data())->GetId();
268 Int_t gapMediumId = gGeoManager->GetMedium(fGapMaterial.Data())->GetId();
269
270 //
271 // World
272 //
273
274 Double_t world[3];
275 world[0] = fWorldSizeX / 2.;
276 world[1] = fWorldSizeYZ / 2.;
277 world[2] = fWorldSizeYZ / 2.;
278 TGeoVolume* top =
279 gGeoManager->Volume("WRLD", "BOX", defaultMediumId, world, 3);
280 gGeoManager->SetTopVolume(top);
281
282 //
283 // Calorimeter
284 //
285 if (fCalorThickness > 0.) {
286
287 Double_t calo[3];
288 calo[0] = fCalorThickness / 2.;
289 calo[1] = fCalorSizeYZ / 2.;
290 calo[2] = fCalorSizeYZ / 2.;
291 gGeoManager->Volume("CALO", "BOX", defaultMediumId, calo, 3);
292
293 Double_t posX = 0.;
294 Double_t posY = 0.;
295 Double_t posZ = 0.;
296 gGeoManager->Node("CALO", 1, "WRLD", posX, posY, posZ, 0, kTRUE, ubuf);
297
298 // Divide calorimeter along X axis to place layers
299 //
300 Double_t start = -calo[0];
301 Double_t width = fCalorThickness / fNbOfLayers;
302 gGeoManager->Division("CELL", "CALO", 1, fNbOfLayers, start, width);
303
304 //
305 // Layer
306 //
307 Double_t layer[3];
308 layer[0] = fLayerThickness / 2.;
309 layer[1] = fCalorSizeYZ / 2.;
310 layer[2] = fCalorSizeYZ / 2.;
311 gGeoManager->Volume("LAYE", "BOX", defaultMediumId, layer, 3);
312
313 posX = 0.;
314 posY = 0.;
315 posZ = 0.;
316 gGeoManager->Node("LAYE", 1, "CELL", posX, posY, posZ, 0, kTRUE, ubuf);
317 }
318
319 //
320 // Absorber
321 //
322
323 if (fAbsorberThickness > 0.) {
324
325 Double_t abso[3];
326 abso[0] = fAbsorberThickness / 2;
327 abso[1] = fCalorSizeYZ / 2.;
328 abso[2] = fCalorSizeYZ / 2.;
329 gGeoManager->Volume("ABSO", "BOX", absorberMediumId, abso, 3);
330
331 Double_t posX = -fGapThickness / 2.;
332 Double_t posY = 0.;
333 Double_t posZ = 0.;
334 gGeoManager->Node("ABSO", 1, "LAYE", posX, posY, posZ, 0, kTRUE, ubuf);
335 }
336
337 //
338 // Gap
339 //
340
341 if (fGapThickness > 0.) {
342
343 Double_t gap[3];
344 gap[0] = fGapThickness / 2;
345 gap[1] = fCalorSizeYZ / 2.;
346 gap[2] = fCalorSizeYZ / 2.;
347 gGeoManager->Volume("GAPX", "BOX", gapMediumId, gap, 3);
348
349 Double_t posX = fAbsorberThickness / 2.;
350 Double_t posY = 0.;
351 Double_t posZ = 0.;
352 gGeoManager->Node("GAPX", 1, "LAYE", posX, posY, posZ, 0, kTRUE, ubuf);
353 }
354
355 /*
356 //
357 // Visualization attributes
358 //
359 logicWorld->SetVisAttributes (G4VisAttributes::Invisible);
360 G4VisAttributes* simpleBoxVisAtt= new
361 G4VisAttributes(G4Colour(1.0,1.0,1.0));
362 simpleBoxVisAtt->SetVisibility(true);
363 logicCalor->SetVisAttributes(simpleBoxVisAtt);
364 */
365
366 // close geometry
367 gGeoManager->CloseGeometry();
368
370}
371
372//_____________________________________________________________________________
374{
375 /// Set cuts for e-, gamma equivalent to 1mm cut in G4.
376
378 fMC = gMC;
379 }
380
381 // created material names
382 std::set<TString> createdMaterials;
383 createdMaterials.insert(fDefaultMaterial);
384 createdMaterials.insert(fAbsorberMaterial);
385 createdMaterials.insert(fGapMaterial);
386
387 // Cuts for e-, gamma equivalent to 1mm cut in G4,
388 // or 10keV (minimal value accepted by Geant3) if lower
389 std::vector<MaterialCuts> materialCutsVector = {
390 MaterialCuts("Aluminium", 10.e-06, 10.e-06, 597.e-06, 597.e-06),
391 MaterialCuts("liquidArgon", 10.e-06, 10.e-06, 342.9e-06, 342.9e-06),
392 MaterialCuts("Lead", 100.5e-06, 100.5e-06, 1.378e-03, 1.378e-03),
393 MaterialCuts("Water", 10.e-06, 10.e-06, 347.2e-06, 347.2e-06),
394 MaterialCuts("Scintillator", 10.e-06, 10.e-06, 355.8e-06, 355.8e-06),
395 MaterialCuts("Mylar", 10.e-06, 10.e-06, 417.5e-06, 417.5e-06),
396 MaterialCuts("quartz", 10.e-06, 10.e-06, 534.1e-06, 534.1e-06),
397 MaterialCuts("Air", 10.e-06, 10.e-06, 10.e-06, 10.e-06),
398 MaterialCuts("Aerogel", 10.e-06, 10.e-06, 119.0e-06, 119.0e-06),
399 MaterialCuts("CarbonicGas", 10.e-09, 10.e-06, 10.e-06, 10.e-06),
400 MaterialCuts("WaterSteam", 10.e-06, 10.e-06, 10.e-06, 10.e-06),
401 MaterialCuts("Galactic", 10.e-06, 10.e-06, 10.e-06, 10.e-06),
402 MaterialCuts("Beam", 10.e-06, 10.e-06, 10.e-06, 10.e-06)
403 };
404
405 // set VMC cutes for created media
406 for (auto materialCuts : materialCutsVector) {
407 // skip materials which were not created (to avoid warning)
408 if (createdMaterials.find(materialCuts.fName) == createdMaterials.end())
409 continue;
410 // set VMC cutes for the medium
411 Int_t mediumId = fMC->MediumId(materialCuts.fName);
412 if (mediumId) {
413 // Set cuts as defined in the vector
414 // gMC->Gstpar(mediumId, "CUTGAM", materialCuts.fCUTGAM);
415 // gMC->Gstpar(mediumId, "BCUTE", materialCuts.fBCUTE);
416 // gMC->Gstpar(mediumId, "CUTELE", materialCuts.fCUTELE);
417 // gMC->Gstpar(mediumId, "DCUTE", materialCuts.fDCUTE);
418 //
419 // Set 100 keV cut everywhere
420 Double_t cut = 100.e-06;
421 gMC->Gstpar(mediumId, "CUTGAM", cut);
422 gMC->Gstpar(mediumId, "BCUTE", cut);
423 gMC->Gstpar(mediumId, "CUTELE", cut);
424 gMC->Gstpar(mediumId, "DCUTE", cut);
425 }
426 }
427}
428
429//_____________________________________________________________________________
431{
432 /// This function demonstrate how to inactivate physics processes via VMC
433 /// controls. Here gamma processes are inactivated in Lead medium. Note that
434 /// while in Geant3 this mechanism is used to speed-up simulation, this may
435 /// cause slow down in Geant4 simulation where implementation of this
436 /// mechanism is quite tricky.
437
439 fMC = gMC;
440 }
441
442 Int_t mediumId = gMC->MediumId("Lead");
443 if (mediumId) {
444 fMC->Gstpar(mediumId, "COMP", 0);
445 fMC->Gstpar(mediumId, "PAIR", 0);
446 fMC->Gstpar(mediumId, "PHOT", 0);
447 }
448}
449
450//_____________________________________________________________________________
452{
453 /// Print calorimeter parameters
454
455 cout << "\n------------------------------------------------------------"
456 << "\n---> The calorimeter is " << fNbOfLayers << " layers of: [ "
457 << fAbsorberThickness << "cm of " << fAbsorberMaterial << " + "
458 << fGapThickness << "cm of " << fGapMaterial << " ] "
459 << "\n------------------------------------------------------------\n";
460}
461
462//_____________________________________________________________________________
464{
465 /// Set the number of layers.
466 /// \param value The new number of calorimeter layers
467
468 fNbOfLayers = value;
469}
470
471//_____________________________________________________________________________
472void Ex03cDetectorConstruction::SetDefaultMaterial(const TString& materialName)
473{
474 /// Set default material
475 /// \param materialName The new default material name.
476
477 fDefaultMaterial = materialName;
478}
479
480//_____________________________________________________________________________
481void Ex03cDetectorConstruction::SetAbsorberMaterial(const TString& materialName)
482{
483 /// Set absorer material
484 /// \param materialName The new absorber material name.
485
486 fAbsorberMaterial = materialName;
487}
488
489//_____________________________________________________________________________
490void Ex03cDetectorConstruction::SetGapMaterial(const TString& materialName)
491{
492 /// Set gap material
493 /// \param materialName The new gap material name.
494
495 fGapMaterial = materialName;
496}
497
498//_____________________________________________________________________________
500{
501 /// Change the transverse size and recompute the calorimeter parameters
502 /// \param value The new calorimeter tranverse size
503
504 fCalorSizeYZ = value;
505}
506
507//_____________________________________________________________________________
509{
510 /// Change the absorber thickness and recompute the calorimeter parameters
511 /// \param value The new absorber thickness
512
513 fAbsorberThickness = value;
514}
515
516//_____________________________________________________________________________
518{
519 /// Change the gap thickness and recompute the calorimeter parameters
520 /// \param value The new gap thickness
521
522 fGapThickness = value;
523}
524
525/*
526//_____________________________________________________________________________
527void Ex03cDetectorConstruction::UpdateGeometry()
528{
529// Not available in VMC
530}
531*/
Definition of the Ex03cDetectorConstruction class.
The detector construction (via TGeo )
Int_t fNbOfLayers
The number of calorimeter layers.
TString fDefaultMaterial
The default material name.
TVirtualMC * fMC
Stored pointer to current TVirtualMC.
Double_t fAbsorberThickness
The absorber thickness.
Double_t fCalorThickness
The calorimeter thickness.
Double_t fWorldSizeX
The world size x component.
Double_t fCalorSizeYZ
The calorimeter size y,z component.
Double_t fLayerThickness
The calorimeter layer thickness.
TString fGapMaterial
The gap material name.
TString fAbsorberMaterial
The absorber material name.
Double_t fWorldSizeYZ
The world size y,z component.
Double_t fGapThickness
The gap thickness.
void SetAbsorberMaterial(const TString &materialName)
void SetDefaultMaterial(const TString &materialName)
void SetGapMaterial(const TString &materialName)