Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exrdmDetectorConstruction.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 //
31 //#include "exrdmDetectorSD.hh"
32 #include "G4UImanager.hh"
33 #include "G4Tubs.hh"
34 #include "G4LogicalVolume.hh"
35 #include "G4PVPlacement.hh"
36 //#include "G4SDManager.hh"
37 #include "G4Region.hh"
38 #include "G4RegionStore.hh"
39 
40 #include "exrdmMaterial.hh"
41 
42 #include "G4VisAttributes.hh"
43 #include "G4Colour.hh"
44 #include "G4PhysicalConstants.hh"
45 #include "G4SystemOfUnits.hh"
46 
47 #include "G4ios.hh"
48 #include <sstream>
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51 
53 :fSolidWorld(0), fLogicWorld(0), fPhysiWorld(0),
54  fSolidTarget(0), fLogicTarget(0), fPhysiTarget(0),
55  fSolidDetector(0),fLogicDetector(0),fPhysiDetector(0),
56  fMaterialsManager(0),
57  fDefaultMater(0),fTargetMater(0),fDetectorMater(0),
58  fTargetLength (1.*cm), fTargetRadius(0.5*cm),
59  fDetectorLength(5.0 * cm), fDetectorThickness(2.0 * cm),
60  fWorldLength (std::max(fTargetLength,fDetectorLength)),
61  fWorldRadius (fTargetRadius + fDetectorThickness),
62  fTargetRegion(0), fDetectorRegion(0)
63 {
64  fDetectorMessenger = new exrdmDetectorMessenger(this);
65  DefineMaterials();
66 }
67 
68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69 
71 {
72  delete fDetectorMessenger;
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
77 void exrdmDetectorConstruction::DefineMaterials()
78 {
79 //--------- Material definition ---------
80 
81  fMaterialsManager = new exrdmMaterial();
82  // Lead
83  fMaterialsManager->AddMaterial("Lead","Pb",11.3*g/cm3,"");
84  //Germanium detector
85  fMaterialsManager->AddMaterial("Germanium","Ge",5.323*g/cm3,"");
86  //CsI
87  fMaterialsManager->AddMaterial("CsI","Cs-I",4.51*g/cm3,"");
88 
89  // G4cout << G4endl << "The materials defined are : " << G4endl << G4endl;
90  // G4cout << *(G4Material::GetMaterialTable()) << G4endl;
91 
92  fDefaultMater = fMaterialsManager->GetMaterial("Air");
93  fTargetMater = fMaterialsManager->GetMaterial("CsI");
94  fDetectorMater = fMaterialsManager->GetMaterial("Germanium");
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 
100 {
101 //--------- Definitions of Solids, Logical Volumes, Physical Volumes ---------
102  //--------- Sizes of the principal geometrical components (solids) ---------
103 
104  fWorldLength = std::max(fTargetLength,fDetectorLength);
105  fWorldRadius = fTargetRadius + fDetectorThickness;
106 
107  //------------------------------
108  // World
109  //------------------------------
110 
111  fSolidWorld= new G4Tubs("world",0.,fWorldRadius,fWorldLength/2.,0.,twopi);
112  fLogicWorld= new G4LogicalVolume( fSolidWorld, fDefaultMater, "World", 0, 0, 0);
113 
114  // Must place the World Physical volume unrotated at (0,0,0).
115  //
116  fPhysiWorld = new G4PVPlacement(0, // no rotation
117  G4ThreeVector(), // at (0,0,0)
118  fLogicWorld, // its logical volume
119  "World", // its name
120  0, // its mother volume
121  false, // no boolean operations
122  0); // no field specific to volume
123 
124  //------------------------------
125  // Target
126  //------------------------------
127 
128  G4ThreeVector positionTarget = G4ThreeVector(0,0,0);
129 
130  fSolidTarget = new G4Tubs("target",0.,fTargetRadius,fTargetLength/2.,0.,twopi);
131  fLogicTarget = new G4LogicalVolume(fSolidTarget,fTargetMater,"Target",0,0,0);
132  fPhysiTarget = new G4PVPlacement(0, // no rotation
133  positionTarget, // at (x,y,z)
134  fLogicTarget, // its logical volume
135  "Target", // its name
136  fLogicWorld, // its mother volume
137  false, // no boolean operations
138  0); // no particular field
139 
140  // G4cout << "Target is a cylinder with rdius of " << targetradius/cm << " cm of "
141  // << fTargetMater->GetName() << G4endl;
142 
143  //------------------------------
144  // Detector
145  //------------------------------
146 
147  G4ThreeVector positionDetector = G4ThreeVector(0,0,0);
148 
149  fSolidDetector = new G4Tubs("detector",fTargetRadius,fWorldRadius,
150  fDetectorLength/2.,0.,twopi);
151  fLogicDetector = new G4LogicalVolume(fSolidDetector ,fDetectorMater,
152  "Detector",0,0,0);
153  fPhysiDetector = new G4PVPlacement(0, // no rotation
154  positionDetector, // at (x,y,z)
155  fLogicDetector, // its logical volume
156  "Detector", // its name
157  fLogicWorld, // its mother volume
158  false, // no boolean operations
159  0); // no particular field
160 
161  //------------------------------------------------
162  // Sensitive detectors
163  //------------------------------------------------
164 
165  // G4SDManager* SDman = G4SDManager::GetSDMpointer();
166 
167  // G4String detectortargetSDname = "exrdm/DetectorTargetSD";
168  // exrdmDetectorSD* aDetectorSD = new exrdmDetectorSD( detectorTargetSDname );
169  // SDman->AddNewDetector( aDetectorSD );
170  //fLogicTarget->SetSensitiveDetector( aDetectorSD );
171  // fLogicDetector->SetSensitiveDetector( aDetectorSD );
172  //
173  //-------------------------------------------------
174  // regions
175  //
176  // if(fTargetRegion) delete fTargetRegion;
177  // if(fDetectorRegion) delete fDetectorRegion;
178  fTargetRegion = new G4Region("Target");
179  fDetectorRegion = new G4Region("Detector");
180  fTargetRegion->AddRootLogicalVolume(fLogicTarget);
181  fDetectorRegion->AddRootLogicalVolume(fLogicDetector);
182 
183  //--------- Visualization attributes -------------------------------
185  G4VisAttributes* TargetVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
186  fLogicTarget ->SetVisAttributes(TargetVisAtt);
187  G4VisAttributes* DetectorVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,.0));
188  fLogicDetector->SetVisAttributes(DetectorVisAtt);
189 
190 
191  //------------ set the incident position ------
192 
193  // get the pointer to the User Interface manager
194 
196  // UI->ApplyCommand("/run/verbose 1");
197  // UI->ApplyCommand("/event/verbose 2");
198  // UI->ApplyCommand("/tracking/verbose 1");
199 
200  G4double zpos = -fWorldLength/2.;
201  G4String command = "/gps/pos/centre ";
202  std::ostringstream os;
203  os << zpos ;
204  G4String xs = os.str();
205  UI->ApplyCommand(command+"0. 0. "+xs+" mm");
206  UI->ApplyCommand("/gps/pos/type Point");
207  command = "/gps/position ";
208  // UI->ApplyCommand(command+"0. 0. "+xs+" mm");
209  UI->ApplyCommand("/gps/particle proton");
210  UI->ApplyCommand("/gps/direction 0 0 1");
211  UI->ApplyCommand("/gps/energy 100 MeV");
212  //
213 
214  return fPhysiWorld;
215 }
216 
217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218 
220 {
221  // search the material by its name
222  G4Material* pttoMaterial = G4Material::GetMaterial(materialName);
223  if (pttoMaterial)
224  {fTargetMater = pttoMaterial;
225  if (fLogicTarget) fLogicTarget->SetMaterial(pttoMaterial);
226  G4cout << "\n----> The target has been changed to " << fTargetLength/cm
227  << " cm of "
228  << materialName << G4endl;
229  }
230 }
231 
232 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
233 
235 {
236  // search the material by its name
237  G4Material* pttoMaterial = G4Material::GetMaterial(materialName);
238  if (pttoMaterial)
239  {fDetectorMater = pttoMaterial;
240  if (fLogicDetector) fLogicDetector->SetMaterial(pttoMaterial);
241  G4cout << "\n----> The Deetctor has been changed to" << fDetectorLength/cm
242  << " cm of "
243  << materialName << G4endl;
244  }
245 }
246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....