source: trunk/examples/extended/electromagnetic/TestEm9/src/DetectorConstruction.cc @ 1309

Last change on this file since 1309 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

File size: 13.4 KB
Line 
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//
27// $Id: DetectorConstruction.cc,v 1.11 2008/04/07 18:09:05 vnivanch Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30//
31/////////////////////////////////////////////////////////////////////////
32//
33// TestEm9: Crystal calorimeter
34//
35// Created: 31.01.03 V.Ivanchenko
36//
37// Modified:
38//
39////////////////////////////////////////////////////////////////////////
40//
41
42
43//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45
46#include "DetectorConstruction.hh"
47#include "DetectorMessenger.hh"
48
49#include "G4Box.hh"
50#include "G4LogicalVolume.hh"
51#include "G4PVPlacement.hh"
52#include "G4PVReplica.hh"
53
54#include "G4TransportationManager.hh"
55
56#include "G4GeometryManager.hh"
57#include "G4RunManager.hh"
58#include "G4Region.hh"
59#include "G4RegionStore.hh"
60#include "G4ProductionCuts.hh"
61#include "G4PhysicalVolumeStore.hh"
62#include "G4LogicalVolumeStore.hh"
63#include "G4SolidStore.hh"
64#include "G4NistManager.hh"
65
66#include "G4VisAttributes.hh"
67#include "G4Colour.hh"
68
69#include "G4UnitsTable.hh"
70#include "G4ios.hh"
71
72//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73
74DetectorConstruction::DetectorConstruction()
75  : G4VUserDetectorConstruction()
76{
77  detectorMessenger = new DetectorMessenger(this);
78
79  ecalLength   = 36.*cm;
80  ecalWidth    = 6.*cm;
81  vertexLength = 3.*cm;
82  padLength    = 0.1*mm;
83  padWidth     = 0.02*mm;
84  absLength    = 2.*mm;
85  vertexRegion = 0;
86  muonRegion   = 0;
87  logicWorld   = 0;
88  logicCal     = 0;
89  logicA1      = 0;
90  DefineMaterials();
91  vertexDetectorCuts = new G4ProductionCuts();
92  muonDetectorCuts   = new G4ProductionCuts();
93}
94
95//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
96
97DetectorConstruction::~DetectorConstruction()
98{ 
99  delete detectorMessenger;
100  delete vertexDetectorCuts;
101  delete muonDetectorCuts;
102}
103
104//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105
106G4VPhysicalVolume* DetectorConstruction::Construct()
107{
108  return ConstructVolumes();
109}
110
111//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112
113void DetectorConstruction::DefineMaterials()
114{
115  // Default materials
116
117  G4NistManager* man = G4NistManager::Instance();
118  //  man->SetVerbose(1);
119  worldMaterial = man->FindOrBuildMaterial("G4_AIR");
120  absMaterial   = man->FindOrBuildMaterial("G4_Al");
121  vertMaterial  = man->FindOrBuildMaterial("G4_Si");
122  yorkMaterial  = man->FindOrBuildMaterial("G4_Fe");
123  calMaterial   = man->FindOrBuildMaterial("G4_CESIUM_IODIDE");
124}
125
126//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127
128G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
129{
130  // Cleanup old geometry
131
132  G4GeometryManager::GetInstance()->OpenGeometry();
133
134  if(G4NistManager::Instance()->GetVerbose() > 0)
135    G4cout << *(G4Material::GetMaterialTable()) << G4endl;
136
137  if(vertexRegion) {
138    delete vertexRegion;
139    delete muonRegion;
140  }
141  vertexRegion = new G4Region("VertexDetector");
142  vertexRegion->SetProductionCuts(vertexDetectorCuts);
143
144  muonRegion   = new G4Region("MuonDetector");
145  muonRegion->SetProductionCuts(muonDetectorCuts);
146
147  G4SolidStore::GetInstance()->Clean();
148  G4LogicalVolumeStore::GetInstance()->Clean();
149  G4PhysicalVolumeStore::GetInstance()->Clean();
150
151  if(vertexLength < padLength*5.0) vertexLength = padLength*5.0;
152  G4double gap    = 0.01*mm;
153  G4double biggap = 2.*cm;
154  G4double york   = 10.*cm;
155
156  worldZ = 2.*vertexLength + 3.*absLength + 0.5*(ecalLength + york) + biggap*2.;
157
158  G4double worldX = ecalWidth*3.0;
159  G4double vertexZ= -worldZ + vertexLength*2.0 + absLength     + biggap;
160  G4double absZ2  = -worldZ + vertexLength*4.0 + absLength*3.5 + biggap;
161  G4double ecalZ  = -worldZ + vertexLength*4.0 + absLength*4.0 + ecalLength*0.5 
162    + 2.*biggap;
163  G4double yorkZ  = -worldZ + vertexLength*4.0 + absLength*5.0 + ecalLength
164    + york*0.5 + 3.*biggap;
165
166  //
167  // World
168  //
169  G4Box* solidW = new G4Box("World",worldX,worldX,worldZ);
170  logicWorld = new G4LogicalVolume( solidW,worldMaterial,"World");
171  G4VPhysicalVolume* world = new G4PVPlacement(0,G4ThreeVector(),
172                                               "World",logicWorld,0,false,0);
173
174  //
175  // Ecal
176  //
177  G4Box* solidE = new G4Box("VolE",worldX,worldX,ecalLength*0.5 + gap);
178  logicECal = new G4LogicalVolume( solidE,worldMaterial,"VolE");
179  G4VPhysicalVolume* physE = new G4PVPlacement(0,G4ThreeVector(0.,0.,ecalZ),
180                                               "VolE",logicECal,world,false,0);
181
182  G4Box* solidC = new G4Box("Ecal",ecalWidth*0.5,ecalWidth*0.5,ecalLength*0.5);
183  logicCal = new G4LogicalVolume( solidC,calMaterial,"Ecal");
184
185  G4cout << "Ecal is " << G4BestUnit(ecalLength,"Length")
186         << " of " << calMaterial->GetName() << G4endl;
187
188  // Crystals
189
190  G4double x0 = -(ecalWidth + gap)*2.0;
191  G4double y  = x0;
192  G4double x;
193  G4int k = 0;
194  G4VPhysicalVolume* pv;
195  G4int i,j;
196
197  for (i=0; i<5; i++) {
198    x  = x0;
199    for (j=0; j<5; j++) {
200
201      pv = new G4PVPlacement(0,G4ThreeVector(x,y,0.),"Ecal",logicCal,
202                                    physE,false,k);
203      k++;
204      x += ecalWidth + gap;
205    }
206    y += ecalWidth + gap;
207  }
208
209  //Absorber
210
211  G4Box* solidA = new G4Box("Abso",worldX,worldX,absLength*0.5);
212  logicA2 = new G4LogicalVolume( solidA,absMaterial,"Abs2");
213  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,absZ2),
214                         "Abs2",logicA2,world,false,0);
215
216  G4cout << "Absorber is " << G4BestUnit(absLength,"Length")
217         << " of " << absMaterial->GetName() << G4endl;
218
219  //York
220
221  G4Box* solidYV = new G4Box("VolY",worldX,worldX,york*0.5+absLength);
222  logicYV = new G4LogicalVolume( solidYV,yorkMaterial,"VolY");
223  G4VPhysicalVolume* physYV = new G4PVPlacement(0,G4ThreeVector(0.,0.,yorkZ),
224                                                "VolY",logicYV,world,false,0);
225
226  G4Box* solidY = new G4Box("York",worldX,worldX,york*0.5);
227  logicY = new G4LogicalVolume( solidY,yorkMaterial,"York");
228  pv = new G4PVPlacement(0,G4ThreeVector(),
229                         "York",logicY,physYV,false,0);
230
231  logicA3 = new G4LogicalVolume( solidA,absMaterial,"Abs3");
232  logicA4 = new G4LogicalVolume( solidA,absMaterial,"Abs4");
233
234  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,-(york+absLength)*0.5),
235                         "Abs3",logicA3,physYV,false,0);
236  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,(york+absLength)*0.5),
237                         "Abs4",logicA4,physYV,false,0);
238
239  //Vertex volume
240  G4Box* solidVV = new G4Box("VolV",worldX,worldX,vertexLength*2.+absLength+gap);
241  logicVV = new G4LogicalVolume( solidVV,worldMaterial,"VolV");
242  G4VPhysicalVolume* physVV = new G4PVPlacement(0,G4ThreeVector(0.,0.,vertexZ),
243                                                "VolV",logicVV,world,false,0);
244
245  //Absorber
246  logicA1 = new G4LogicalVolume( solidA,absMaterial,"Abs1");
247  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,vertexLength*2.-absLength*0.5),
248                         "Abs1",logicA1,physVV,false,0);
249
250  //Vertex
251  G4double vertWidth = ecalWidth/5.;
252  G4int npads = (G4int)(vertWidth/padWidth);
253  npads = (npads/2)*2 + 1;
254  x0 = -0.5*padWidth*((G4double)(npads-1));
255  G4double x1 = std::fabs(x0) + 0.5*padWidth + gap; 
256  G4double z  = -(vertexLength+absLength);
257
258  G4Box* solidVD = new G4Box("VertDet",x1,ecalWidth*0.5+gap,padLength*0.5);
259  logicVD = new G4LogicalVolume( solidVD,vertMaterial,"VertDet");
260  logicVD->SetSolid(solidVD);
261
262  G4Box* solidV = new G4Box("Vert",padWidth*0.5,ecalWidth*0.5,padLength*0.5);
263  logicV = new G4LogicalVolume( solidV,vertMaterial,"Vert");
264
265  for (i=0; i<3; i++) {
266    pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,z),"VertDet",logicVD,
267                                    physVV,false,i);
268    z += vertexLength;
269  }
270  x = x0;
271
272  for (j=0; j<npads; j++) {
273
274    pv = new G4PVPlacement(0,G4ThreeVector(x,0.,0.),logicV,"Vert",logicVD,
275                                    false,k);
276    x += padWidth;
277  }
278
279  G4cout << "Vertex is " << G4BestUnit(vertexLength,"Length")
280         << " of 3 layers of Si of " << G4BestUnit(padLength,"Length")
281         << " npads= " << npads
282         << G4endl;
283
284  // Define region for the vertex detector
285  vertexRegion->AddRootLogicalVolume(logicVV);
286  vertexRegion->AddRootLogicalVolume(logicA3);
287
288  // Define region for the muon detector
289  muonRegion->AddRootLogicalVolume(logicYV);
290
291  // color regions
292  logicVV-> SetVisAttributes(G4VisAttributes::Invisible);
293  logicV-> SetVisAttributes(G4VisAttributes::Invisible);
294  logicECal-> SetVisAttributes(G4VisAttributes::Invisible);
295  logicYV-> SetVisAttributes(G4VisAttributes::Invisible);
296
297  G4VisAttributes* regWcolor = new G4VisAttributes(G4Colour(0.3, 0.3, 0.3));
298  logicWorld->SetVisAttributes(regWcolor);
299
300  G4VisAttributes* regVcolor = new G4VisAttributes(G4Colour(0., 0.3, 0.7));
301  logicVD->SetVisAttributes(regVcolor);
302
303  G4VisAttributes* regCcolor = new G4VisAttributes(G4Colour(0., 0.7, 0.3));
304  logicCal->SetVisAttributes(regCcolor);
305
306  G4VisAttributes* regAcolor = new G4VisAttributes(G4Colour(1., 0.5, 0.5));
307  logicA1->SetVisAttributes(regAcolor);
308  logicA2->SetVisAttributes(regAcolor);
309  logicA3->SetVisAttributes(regAcolor);
310  logicA4->SetVisAttributes(regAcolor);
311
312  G4VisAttributes* regMcolor = new G4VisAttributes(G4Colour(1., 1., 0.));
313  logicY->SetVisAttributes(regMcolor);
314
315  // always return world
316  G4cout << "### New geometry is constructed" << G4endl;
317 
318  return world;
319}
320
321//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
322
323void DetectorConstruction::SetEcalMaterial(const G4String& mat)
324{
325  // search the material by its name
326  G4Material* pttoMaterial = 
327    G4NistManager::Instance()->FindOrBuildMaterial(mat, false);
328  if (pttoMaterial) {
329    calMaterial = pttoMaterial;
330    if(logicCal) {
331      logicCal->SetMaterial(calMaterial);
332      G4RunManager::GetRunManager()->PhysicsHasBeenModified();
333    }
334  }
335}
336
337//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
338
339void DetectorConstruction::SetAbsMaterial(const G4String& mat)
340{
341  // search the material by its name
342  G4Material* pttoMaterial = 
343    G4NistManager::Instance()->FindOrBuildMaterial(mat, false);
344  if (pttoMaterial) {
345    absMaterial = pttoMaterial;
346    if(logicA1) {
347      logicA1->SetMaterial(absMaterial);
348      logicA2->SetMaterial(absMaterial);
349      logicA3->SetMaterial(absMaterial);
350      logicA4->SetMaterial(absMaterial);
351      G4RunManager::GetRunManager()->PhysicsHasBeenModified();
352    }
353  }
354}
355
356//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
357
358void DetectorConstruction::UpdateGeometry()
359{
360  G4RunManager::GetRunManager()->PhysicsHasBeenModified();
361  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
362}
363
364//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
365
366void DetectorConstruction::SetEcalLength (G4double val)   
367{
368  if(val > 0.0) {
369    ecalLength = val;
370    G4RunManager::GetRunManager()->GeometryHasBeenModified();
371  }
372}
373
374//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
375
376void DetectorConstruction::SetEcalWidth  (G4double val)   
377{
378  if(val > 0.0) {
379    ecalWidth = val;
380    G4RunManager::GetRunManager()->GeometryHasBeenModified();
381  }
382}
383
384//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
385
386void DetectorConstruction::SetVertexLength (G4double val) 
387{
388  if(val > 0.0) {
389    vertexLength = val;
390    G4RunManager::GetRunManager()->GeometryHasBeenModified();
391  }
392}
393
394//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
395
396void DetectorConstruction::SetPadLength  (G4double val)   
397{
398  if(val > 0.0) {
399    padLength = val;
400    G4RunManager::GetRunManager()->GeometryHasBeenModified();
401  }
402}
403
404//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
405
406void DetectorConstruction::SetPadWidth  (G4double val)   
407{
408  if(val > 0.0) {
409    padWidth = val;
410    G4RunManager::GetRunManager()->GeometryHasBeenModified();
411  }
412}
413
414//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
415
416void DetectorConstruction::SetAbsLength(G4double val)     
417{
418  if(val > 0.0) {
419    absLength = val;
420    G4RunManager::GetRunManager()->GeometryHasBeenModified();
421  }
422}
423
424//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.