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