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