Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
28 //
29 //
30 // $Id$
31 //
32 //
34 //
35 // TestEm9: Crystal calorimeter
36 //
37 // Created: 31.01.03 V.Ivanchenko
38 //
39 // Modified:
40 //
42 //
43 
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
48 #include "DetectorConstruction.hh"
49 #include "DetectorMessenger.hh"
50 
51 #include "G4Box.hh"
52 #include "G4LogicalVolume.hh"
53 #include "G4PVPlacement.hh"
54 #include "G4PVReplica.hh"
55 
57 
58 #include "G4GeometryManager.hh"
59 #include "G4RunManager.hh"
60 #include "G4Region.hh"
61 #include "G4RegionStore.hh"
62 #include "G4ProductionCuts.hh"
63 #include "G4PhysicalVolumeStore.hh"
64 #include "G4LogicalVolumeStore.hh"
65 #include "G4SolidStore.hh"
66 #include "G4NistManager.hh"
67 
68 #include "G4VisAttributes.hh"
69 #include "G4Colour.hh"
70 
71 #include "G4UnitsTable.hh"
72 #include "G4SystemOfUnits.hh"
73 #include "G4ios.hh"
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
79 {
80  fDetectorMessenger = new DetectorMessenger(this);
81 
82  fEcalLength = 36.*cm;
83  fEcalWidth = 6.*cm;
84  fVertexLength = 3.*cm;
85  fPadLength = 0.1*mm;
86  fPadWidth = 0.02*mm;
87  fAbsLength = 2.*mm;
88  fWorldZ = 0.0;
89  fLogicWorld = 0;
90  fLogicCal = 0;
91  fLogicA1 = 0;
92  fLogicA2 = 0;
93  fLogicA3 = 0;
94  fLogicA4 = 0;
95  fVertexRegion = 0;
96  fMuonRegion = 0;
97 
98  DefineMaterials();
99  fVertexDetectorCuts = new G4ProductionCuts();
100  fMuonDetectorCuts = new G4ProductionCuts();
101 }
102 
103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
104 
106 {
107  delete fDetectorMessenger;
108  delete fVertexDetectorCuts;
109  delete fMuonDetectorCuts;
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113 
115 {
116  return ConstructVolumes();
117 }
118 
119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
120 
121 void DetectorConstruction::DefineMaterials()
122 {
123  // Default materials
124 
126  // man->SetVerbose(1);
127  fWorldMaterial = man->FindOrBuildMaterial("G4_AIR");
128  fAbsMaterial = man->FindOrBuildMaterial("G4_Al");
129  fVertMaterial = man->FindOrBuildMaterial("G4_Si");
130  fYorkMaterial = man->FindOrBuildMaterial("G4_Fe");
131  fCalMaterial = man->FindOrBuildMaterial("G4_CESIUM_IODIDE");
132 }
133 
134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
135 
136 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
137 {
138  // Cleanup old geometry
139 
141 
142  if(G4NistManager::Instance()->GetVerbose() > 0)
144 
145  if(fVertexRegion) {
146  delete fVertexRegion;
147  delete fMuonRegion;
148  }
149  fVertexRegion = new G4Region("VertexDetector");
150  fVertexRegion->SetProductionCuts(fVertexDetectorCuts);
151 
152  fMuonRegion = new G4Region("MuonDetector");
153  fMuonRegion->SetProductionCuts(fMuonDetectorCuts);
154 
158 
159  if(fVertexLength < fPadLength*5.0) fVertexLength = fPadLength*5.0;
160  G4double gap = 0.01*mm;
161  G4double biggap = 2.*cm;
162  G4double york = 10.*cm;
163 
164  fWorldZ = 2.*fVertexLength + 3.*fAbsLength + 0.5*(fEcalLength + york) + biggap*2.;
165 
166  G4double worldX = fEcalWidth*3.0;
167  G4double vertexZ= -fWorldZ + fVertexLength*2.0 + fAbsLength + biggap;
168  G4double absZ2 = -fWorldZ + fVertexLength*4.0 + fAbsLength*3.5 + biggap;
169  G4double ecalZ = -fWorldZ + fVertexLength*4.0 + fAbsLength*4.0 + fEcalLength*0.5
170  + 2.*biggap;
171  G4double yorkZ = -fWorldZ + fVertexLength*4.0 + fAbsLength*5.0 + fEcalLength
172  + york*0.5 + 3.*biggap;
173 
174  //
175  // World
176  //
177  G4Box* solidW = new G4Box("World",worldX,worldX,fWorldZ);
178  fLogicWorld = new G4LogicalVolume( solidW,fWorldMaterial,"World");
180  "World",fLogicWorld,0,false,0);
181 
182  //
183  // Ecal
184  //
185  G4Box* solidE = new G4Box("VolE",worldX,worldX,fEcalLength*0.5 + gap);
186  G4LogicalVolume* logicECal =
187  new G4LogicalVolume( solidE,fWorldMaterial,"VolE");
188  G4VPhysicalVolume* physE = new G4PVPlacement(0,G4ThreeVector(0.,0.,ecalZ),
189  "VolE",logicECal,world,false,0);
190 
191  G4Box* solidC = new G4Box("Ecal",fEcalWidth*0.5,fEcalWidth*0.5,fEcalLength*0.5);
192  fLogicCal = new G4LogicalVolume( solidC,fCalMaterial,"Ecal");
193 
194  G4cout << "Ecal is " << G4BestUnit(fEcalLength,"Length")
195  << " of " << fCalMaterial->GetName() << G4endl;
196 
197  // Crystals
198 
199  G4double x0 = -(fEcalWidth + gap)*2.0;
200  G4double y = x0;
201  G4double x;
202  G4int k = 0;
203  G4int i,j;
204 
205  for (i=0; i<5; i++) {
206  x = x0;
207  for (j=0; j<5; j++) {
208 
209  new G4PVPlacement(0,G4ThreeVector(x,y,0.),"Ecal",fLogicCal,
210  physE,false,k);
211  k++;
212  x += fEcalWidth + gap;
213  }
214  y += fEcalWidth + gap;
215  }
216 
217  //Absorber
218 
219  G4Box* solidA = new G4Box("Abso",worldX,worldX,fAbsLength*0.5);
220  fLogicA2 = new G4LogicalVolume( solidA,fAbsMaterial,"Abs2");
221  new G4PVPlacement(0,G4ThreeVector(0.,0.,absZ2),
222  "Abs2",fLogicA2,world,false,0);
223 
224  G4cout << "Absorber is " << G4BestUnit(fAbsLength,"Length")
225  << " of " << fAbsMaterial->GetName() << G4endl;
226 
227  //York
228 
229  G4Box* solidYV = new G4Box("VolY",worldX,worldX,york*0.5+fAbsLength);
230  G4LogicalVolume* logicYV =
231  new G4LogicalVolume( solidYV,fYorkMaterial,"VolY");
232  G4VPhysicalVolume* physYV = new G4PVPlacement(0,G4ThreeVector(0.,0.,yorkZ),
233  "VolY",logicYV,world,false,0);
234 
235  G4Box* solidY = new G4Box("York",worldX,worldX,york*0.5);
236  G4LogicalVolume* logicY =
237  new G4LogicalVolume( solidY,fYorkMaterial,"York");
239  "York",logicY,physYV,false,0);
240 
241  fLogicA3 = new G4LogicalVolume( solidA,fAbsMaterial,"Abs3");
242  fLogicA4 = new G4LogicalVolume( solidA,fAbsMaterial,"Abs4");
243 
244  new G4PVPlacement(0,G4ThreeVector(0.,0.,-(york+fAbsLength)*0.5),
245  "Abs3",fLogicA3,physYV,false,0);
246  new G4PVPlacement(0,G4ThreeVector(0.,0.,(york+fAbsLength)*0.5),
247  "Abs4",fLogicA4,physYV,false,0);
248 
249  //Vertex volume
250  G4Box* solidVV = new G4Box("VolV",worldX,worldX,fVertexLength*2.+fAbsLength+gap);
251  G4LogicalVolume* logicVV =
252  new G4LogicalVolume( solidVV,fWorldMaterial,"VolV");
253  G4VPhysicalVolume* physVV = new G4PVPlacement(0,G4ThreeVector(0.,0.,vertexZ),
254  "VolV",logicVV,world,false,0);
255 
256  //Absorber
257  fLogicA1 = new G4LogicalVolume( solidA,fAbsMaterial,"Abs1");
258  new G4PVPlacement(0,G4ThreeVector(0.,0.,fVertexLength*2.-fAbsLength*0.5),
259  "Abs1",fLogicA1,physVV,false,0);
260 
261  //Vertex
262  G4double vertWidth = fEcalWidth/5.;
263  G4int npads = (G4int)(vertWidth/fPadWidth);
264  //G4cout << " vertWidth= " << vertWidth << " padWidth= " << padWidth
265  // << " npads= " << npads << G4endl;
266  // insure beam to hit a middle of central pad
267  npads = (npads/2)*2 + 1;
268  x0 = -0.5*(fPadWidth + vertWidth);
269  G4double x1 = 0.5*vertWidth + gap;
270  G4double z = -(fVertexLength+fAbsLength);
271 
272  G4Box* solidVD = new G4Box("VertDet",x1,fEcalWidth*0.5+gap,fPadLength*0.5);
273  G4LogicalVolume* logicVD =
274  new G4LogicalVolume( solidVD,fVertMaterial,"VertDet");
275  logicVD->SetSolid(solidVD);
276 
277  G4Box* solidV = new G4Box("Vert",fPadWidth*0.5,fEcalWidth*0.5,fPadLength*0.5);
278  G4LogicalVolume* logicV = new G4LogicalVolume( solidV,fVertMaterial,"Vert");
279 
280  for (i=0; i<3; i++) {
281  new G4PVPlacement(0,G4ThreeVector(0.,0.,z),"VertDet",logicVD,
282  physVV,false,i);
283  z += fVertexLength;
284  }
285  x = x0;
286 
287  for (j=0; j<npads; j++) {
288 
289  new G4PVPlacement(0,G4ThreeVector(x,0.,0.),logicV,"Vert",logicVD,
290  false,k);
291  x += fPadWidth;
292  }
293 
294  G4cout << "Vertex is " << G4BestUnit(fVertexLength,"Length")
295  << " of 3 layers of Si of " << G4BestUnit(fPadLength,"Length")
296  << " npads= " << npads
297  << G4endl;
298 
299  // Define region for the vertex detector
300  fVertexRegion->AddRootLogicalVolume(logicVV);
301  fVertexRegion->AddRootLogicalVolume(fLogicA3);
302 
303  // Define region for the muon detector
304  fMuonRegion->AddRootLogicalVolume(logicYV);
305 
306  // color regions
307  logicVV-> SetVisAttributes(G4VisAttributes::Invisible);
308  logicV-> SetVisAttributes(G4VisAttributes::Invisible);
309  logicECal-> SetVisAttributes(G4VisAttributes::Invisible);
310  logicYV-> SetVisAttributes(G4VisAttributes::Invisible);
311 
312  G4VisAttributes* regWcolor = new G4VisAttributes(G4Colour(0.3, 0.3, 0.3));
313  fLogicWorld->SetVisAttributes(regWcolor);
314 
315  G4VisAttributes* regVcolor = new G4VisAttributes(G4Colour(0., 0.3, 0.7));
316  logicVD->SetVisAttributes(regVcolor);
317 
318  G4VisAttributes* regCcolor = new G4VisAttributes(G4Colour(0., 0.7, 0.3));
319  fLogicCal->SetVisAttributes(regCcolor);
320 
321  G4VisAttributes* regAcolor = new G4VisAttributes(G4Colour(1., 0.5, 0.5));
322  fLogicA1->SetVisAttributes(regAcolor);
323  fLogicA2->SetVisAttributes(regAcolor);
324  fLogicA3->SetVisAttributes(regAcolor);
325  fLogicA4->SetVisAttributes(regAcolor);
326 
327  G4VisAttributes* regMcolor = new G4VisAttributes(G4Colour(1., 1., 0.));
328  logicY->SetVisAttributes(regMcolor);
329 
330  // always return world
331  G4cout << "### New geometry is constructed" << G4endl;
332 
333  return world;
334 }
335 
336 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
337 
339 {
340  // search the material by its name
341  G4Material* pttoMaterial =
343  if (pttoMaterial && pttoMaterial != fCalMaterial) {
344  fCalMaterial = pttoMaterial;
345  if(fLogicCal) {
346  fLogicCal->SetMaterial(fCalMaterial);
348  }
349  }
350 }
351 
352 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
353 
355 {
356  // search the material by its name
357  G4Material* pttoMaterial =
359  if (pttoMaterial && pttoMaterial != fAbsMaterial) {
360  fAbsMaterial = pttoMaterial;
361  if(fLogicA1) {
362  fLogicA1->SetMaterial(fAbsMaterial);
363  fLogicA2->SetMaterial(fAbsMaterial);
364  fLogicA3->SetMaterial(fAbsMaterial);
365  fLogicA4->SetMaterial(fAbsMaterial);
367  }
368  }
369 }
370 
371 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
372 
374 {
376  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
377 }
378 
379 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
380 
382 {
383  if(val > 0.0) {
384  fEcalLength = val;
386  }
387 }
388 
389 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
390 
392 {
393  if(val > 0.0) {
394  fEcalWidth = val;
396  }
397 }
398 
399 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
400 
402 {
403  if(val > 0.0) {
404  fVertexLength = val;
406  }
407 }
408 
409 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
410 
412 {
413  if(val > 0.0) {
414  fPadLength = val;
416  }
417 }
418 
419 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
420 
422 {
423  if(val > 0.0) {
424  fPadWidth = val;
426  }
427 }
428 
429 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
430 
432 {
433  if(val > 0.0) {
434  fAbsLength = val;
436  }
437 }
438 
439 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......