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