Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/advanced/amsEcal/src/DetectorConstruction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: DetectorConstruction.cc 68740 2013-04-05 09:56:39Z gcosmo $
27 //
28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30 
31 #include "DetectorConstruction.hh"
32 #include "DetectorMessenger.hh"
33 
34 #include "G4SystemOfUnits.hh"
35 #include "G4PhysicalConstants.hh"
36 #include "G4Material.hh"
37 #include "G4Tubs.hh"
38 #include "G4Box.hh"
39 #include "G4LogicalVolume.hh"
40 #include "G4PVPlacement.hh"
41 #include "G4PVReplica.hh"
42 #include "G4RotationMatrix.hh"
43 
44 #include "G4UniformMagField.hh"
45 
46 #include "G4GeometryManager.hh"
47 #include "G4PhysicalVolumeStore.hh"
48 #include "G4LogicalVolumeStore.hh"
49 #include "G4SolidStore.hh"
50 
51 #include "G4UnitsTable.hh"
52 
53 #include "G4VisAttributes.hh"
54 
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
59 :fiberMat(0),lvol_fiber(0), absorberMat(0),lvol_layer(0),
60  moduleMat(0),lvol_module(0), calorimeterMat(0),lvol_calorimeter(0),
61  worldMat(0),pvol_world(0), defaultMat(0), magField(0)
62 {
63  // materials
64  DefineMaterials();
65 
66  // default parameter values of calorimeter
67  //
68  fiberDiameter = 1.13*mm; //1.08*mm
69  nbOfFibers = 490; //490
70  distanceInterFibers = 1.35*mm; //1.35*mm
71  layerThickness = 1.73*mm; //1.68*mm
72  milledLayer = 1.00*mm; //1.40*mm ?
73  nbOfLayers = 10; //10
74  nbOfModules = 9; //9
75 
76  fiberLength = (nbOfFibers+1)*distanceInterFibers; //658*mm
77 
78  //pixels readout
79  //
80  G4int nSubModul = 2; //2
81  n1pxl = nbOfModules*nSubModul; //18
82  n2pxl = 72; //72
83 
84  n1shift = 1;
85  if (n1pxl > 1) n1shift = 10;
86  if (n1pxl > 10) n1shift = 100;
87  if (n1pxl > 100) n1shift = 1000;
88 
89  sizeVectorPxl = n1pxl*n1shift; //1800
90 
91  // create commands for interactive definition of the calorimeter
92  detectorMessenger = new DetectorMessenger(this);
93 }
94 
95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
96 
98 {
99  delete detectorMessenger;
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 
105 {
106  return ConstructCalorimeter();
107 }
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110 
111 void DetectorConstruction::DefineMaterials()
112 {
113  // define Elements
114  //
115  G4Element* H = new G4Element("Hydrogen","H", 1, 1.01*g/mole);
116  G4Element* C = new G4Element("Carbon", "C", 6, 12.01*g/mole);
117  G4Element* N = new G4Element("Nitrogen","N", 7, 14.01*g/mole);
118  G4Element* O = new G4Element("Oxygen", "O", 8, 16.00*g/mole);
119 
120  G4int natoms, ncomponents;
121  G4double density, massfraction;
122 
123  // Lead
124  //
125  G4Material* Pb =
126  new G4Material("Lead", 82., 207.20*g/mole, density= 0.98*11.20*g/cm3);
127 
128  // Scintillator
129  //
130  G4Material* Sci =
131  new G4Material("Scintillator", density= 1.032*g/cm3, ncomponents=2);
132  Sci->AddElement(C, natoms=8);
133  Sci->AddElement(H, natoms=8);
134 
135  Sci->GetIonisation()->SetBirksConstant(0.126*mm/MeV);
136 
137  // Air
138  //
139  G4Material* Air =
140  new G4Material("Air", density= 1.290*mg/cm3, ncomponents=2);
141  Air->AddElement(N, massfraction=70*perCent);
142  Air->AddElement(O, massfraction=30.*perCent);
143 
144  // example of vacuum
145  //
146  density = universe_mean_density; //from PhysicalConstants.h
147  G4double pressure = 3.e-18*pascal;
148  G4double temperature = 2.73*kelvin;
149  G4Material* Vacuum =
150  new G4Material("Galactic", 1., 1.008*g/mole, density,
151  kStateGas,temperature,pressure);
152 
153  //attribute materials
154  //
155  defaultMat = Vacuum;
156  fiberMat = Sci;
157  absorberMat = Pb;
158  moduleMat = defaultMat;
159  calorimeterMat = defaultMat;
160  worldMat = defaultMat;
161 
162  // print table
163  //
165 }
166 
167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
168 
169 G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter()
170 {
171  // Cleanup old geometry
172  //
177 
178  // fibers
179  //
180  G4Tubs*
181  svol_fiber = new G4Tubs("fiber", //name
182  0*mm, 0.5*fiberDiameter, //r1, r2
183  0.5*fiberLength, //half-length
184  0., twopi); //theta1, theta2
185 
186  lvol_fiber = new G4LogicalVolume(svol_fiber, //solid
187  fiberMat, //material
188  "fiber"); //name
189 
190  // layer
191  //
192  G4double sizeX = layerThickness;
193  G4double sizeY = distanceInterFibers*nbOfFibers;
194  G4double sizeZ = fiberLength;
195 
196  G4Box*
197  svol_layer = new G4Box("layer", //name
198  0.5*sizeX, 0.5*sizeY, 0.5*sizeZ); //size
199 
200 
201  lvol_layer = new G4LogicalVolume(svol_layer, //solid
202  absorberMat, //material
203  "layer"); //name
204 
205  // put fibers within layer
206  //
207  G4double Xcenter = 0.;
208  G4double Ycenter = -0.5*(sizeY + distanceInterFibers);
209 
210  for (G4int k=0; k<nbOfFibers; k++) {
211  Ycenter += distanceInterFibers;
212  new G4PVPlacement(0, //no rotation
213  G4ThreeVector(Xcenter,Ycenter,0.), //position
214  lvol_fiber, //logical volume
215  "fiber", //name
216  lvol_layer, //mother
217  false, //no boulean operat
218  k); //copy number
219 
220  }
221 
222  // modules
223  //
224  moduleThickness = layerThickness*nbOfLayers + milledLayer;
225  sizeX = moduleThickness;
226  sizeY = fiberLength;
227  sizeZ = fiberLength;
228 
229  G4Box*
230  svol_module = new G4Box("module", //name
231  0.5*sizeX, 0.5*sizeY, 0.5*sizeZ); //size
232 
233  lvol_module = new G4LogicalVolume(svol_module, //solid
234  absorberMat, //material
235  "module"); //name
236 
237  // put layers within module
238  //
239  Xcenter = -0.5*(nbOfLayers+1)*layerThickness;
240  Ycenter = 0.25*distanceInterFibers;
241 
242  for (G4int k=0; k<nbOfLayers; k++) {
243  Xcenter += layerThickness;
244  Ycenter = - Ycenter;
245  new G4PVPlacement(0, //no rotation
246  G4ThreeVector(Xcenter,Ycenter,0.), //position
247  lvol_layer, //logical volume
248  "layer", //name
249  lvol_module, //mother
250  false, //no boulean operat
251  k); //copy number
252 
253  }
254 
255  // calorimeter
256  //
257  calorThickness = moduleThickness*nbOfModules;
258  sizeX = calorThickness;
259  sizeY = fiberLength;
260  sizeZ = fiberLength;
261 
262  G4Box*
263  svol_calorimeter = new G4Box("calorimeter", //name
264  0.5*sizeX, 0.5*sizeY, 0.5*sizeZ); //size
265 
266 
267  lvol_calorimeter = new G4LogicalVolume(svol_calorimeter, //solid
268  calorimeterMat, //material
269  "calorimeter"); //name
270 
271  // put modules inside calorimeter
272  //
273  Xcenter = -0.5*(calorThickness + moduleThickness);
274 
275  //rotation matrix to place modules
276  G4RotationMatrix* rotm = 0;
277  G4RotationMatrix* rotmX = new G4RotationMatrix();
278  rotmX->rotateX(90*deg);
279 
280  for (G4int k=0; k<nbOfModules; k++) {
281  rotm = 0;
282  if ((k+1)%2 == 0) rotm = rotmX;
283  Xcenter += moduleThickness;
284  new G4PVPlacement(rotm, //rotation
285  G4ThreeVector(Xcenter,0.,0.), //position
286  lvol_module, //logical volume
287  "module", //name
288  lvol_calorimeter, //mother
289  false, //no boulean operat
290  k); //copy number
291  }
292 
293  // world
294  //
295  sizeX = 1.2*calorThickness;
296  sizeY = 1.2*fiberLength;
297  sizeZ = 1.2*fiberLength;
298 
299  worldSizeX = sizeX;
300 
301  G4Box*
302  svol_world = new G4Box("world", //name
303  0.5*sizeX, 0.5*sizeY, 0.5*sizeZ); //size
304 
305  lvol_world = new G4LogicalVolume(svol_world, //solid
306  worldMat, //material
307  "world"); //name
308 
309  pvol_world = new G4PVPlacement(0, //no rotation
310  G4ThreeVector(), //at (0,0,0)
311  lvol_world, //logical volume
312  "world", //name
313  0, //mother volume
314  false, //no boolean operation
315  0); //copy number
316 
317  //put calorimeter in world
318  //
319  new G4PVPlacement(0, //no rotation
320  G4ThreeVector(), //at (0,0,0)
321  lvol_calorimeter, //logical volume
322  "calorimeter", //name
323  lvol_world, //mother volume
324  false, //no boolean operation
325  0); //copy number
326 
328 
329  // Visualization attributes
330  //
334 
335  // Pixels readout
336  //
337  d1pxl = calorThickness/n1pxl;
338  d2pxl = fiberLength/n2pxl;
339 
340  //always return the physical World
341  //
342  return pvol_world;
343 }
344 
345 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
346 
348 {
349  G4cout << "\n-------------------------------------------------------------"
350  << "\n ---> The calorimeter is " << nbOfModules << " Modules"
351  << "\n ---> A Module is " << nbOfLayers << " Layers + 1 milled Layer";
352 
353  G4cout
354  << "\n ---> A Layer is " << G4BestUnit(layerThickness,"Length")
355  << " thickness of " << absorberMat->GetName();
356 
357  G4cout
358  << "\n ---> A Layer includes " << nbOfFibers << " fibers of "
359  << fiberMat->GetName();
360 
361  G4cout
362  << "\n ---> diameter : " << G4BestUnit(fiberDiameter,"Length")
363  << "\n ---> length : " << G4BestUnit(fiberLength,"Length")
364  << "\n ---> distance : " << G4BestUnit(distanceInterFibers,"Length");
365 
366  G4cout
367  << "\n ---> The milled Layer is " << G4BestUnit(milledLayer,"Length")
368  << " thickness of " << absorberMat->GetName();
369 
370  G4cout
371  << "\n\n ---> Module thickness " << G4BestUnit(moduleThickness,"Length");
372 
373  G4cout
374  << "\n\n ---> Total calor thickness " << G4BestUnit(calorThickness,"Length")
375  << "\n Tranverse size " << G4BestUnit(fiberLength,"Length");
376 
377  G4cout << "\n-------------------------------------------------------------\n";
378  G4cout << G4endl;
379 }
380 
381 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
382 
383 #include "G4FieldManager.hh"
385 
387 {
388  //apply a global uniform magnetic field along Z axis
389  //
390  G4FieldManager* fieldMgr
392 
393  if(magField) delete magField; //delete the existing magn field
394 
395  if(fieldValue!=0.) // create a new one if non nul
396  { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
397  fieldMgr->SetDetectorField(magField);
398  fieldMgr->CreateChordFinder(magField);
399  } else {
400  magField = 0;
401  fieldMgr->SetDetectorField(magField);
402  }
403 }
404 
405 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
406 
407 #include "G4RunManager.hh"
408 
410 {
411  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructCalorimeter());
412 }
413 
414 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:224
G4Material * Air
Definition: TRTMaterials.hh:57
CLHEP::Hep3Vector G4ThreeVector
HepRotation & rotateX(double delta)
Definition: Rotation.cc:66
CLHEP::HepRotation G4RotationMatrix
G4bool SetDetectorField(G4Field *detectorField)
int universe_mean_density
Definition: hepunit.py:307
Definition: G4Box.hh:63
const G4String & GetName() const
Definition: G4Material.hh:176
void SetBirksConstant(G4double value)
Definition: G4Tubs.hh:84
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:564
static void Clean()
Definition: G4SolidStore.cc:79
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
static G4PhysicalVolumeStore * GetInstance()
G4double density
Definition: TRTMaterials.hh:39
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
#define pascal
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
static G4GeometryManager * GetInstance()
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
static const G4VisAttributes Invisible
float perCent
Definition: hepunit.py:239
#define G4endl
Definition: G4ios.hh:61
**D E S C R I P T I O N
void OpenGeometry(G4VPhysicalVolume *vol=0)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:345
double G4double
Definition: G4Types.hh:76
void CreateChordFinder(G4MagneticField *detectorMagField)
void SetVisAttributes(const G4VisAttributes *pVA)