| 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 | // $Id: DetectorConstruction.cc,v 1.8 2007/11/07 17:22:16 maire Exp $
|
|---|
| 27 | // GEANT4 tag $Name: $
|
|---|
| 28 |
|
|---|
| 29 | //
|
|---|
| 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 32 |
|
|---|
| 33 | #include "DetectorConstruction.hh"
|
|---|
| 34 | #include "DetectorMessenger.hh"
|
|---|
| 35 |
|
|---|
| 36 | #include "G4NistManager.hh"
|
|---|
| 37 | #include "G4Box.hh"
|
|---|
| 38 | #include "G4LogicalVolume.hh"
|
|---|
| 39 | #include "G4VPhysicalVolume.hh"
|
|---|
| 40 | #include "G4PVPlacement.hh"
|
|---|
| 41 | #include "G4PVReplica.hh"
|
|---|
| 42 | #include "G4UniformMagField.hh"
|
|---|
| 43 |
|
|---|
| 44 | #include "G4GeometryManager.hh"
|
|---|
| 45 | #include "G4PhysicalVolumeStore.hh"
|
|---|
| 46 | #include "G4LogicalVolumeStore.hh"
|
|---|
| 47 | #include "G4SolidStore.hh"
|
|---|
| 48 |
|
|---|
| 49 | #include "G4UnitsTable.hh"
|
|---|
| 50 |
|
|---|
| 51 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 52 |
|
|---|
| 53 | DetectorConstruction::DetectorConstruction()
|
|---|
| 54 | {
|
|---|
| 55 | // default parameter values
|
|---|
| 56 | absorSizeX = absorSizeYZ = 1*mm;
|
|---|
| 57 | nbOfLayers = 1;
|
|---|
| 58 |
|
|---|
| 59 | absorMaterial = 0;
|
|---|
| 60 | magField = 0;
|
|---|
| 61 | pAbsor = 0;
|
|---|
| 62 |
|
|---|
| 63 | DefineMaterials();
|
|---|
| 64 | SetMaterial("G4_Si");
|
|---|
| 65 |
|
|---|
| 66 | // create commands for interactive definition of the detector
|
|---|
| 67 | detectorMessenger = new DetectorMessenger(this);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 71 |
|
|---|
| 72 | DetectorConstruction::~DetectorConstruction()
|
|---|
| 73 | { delete detectorMessenger;}
|
|---|
| 74 |
|
|---|
| 75 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 76 |
|
|---|
| 77 | G4VPhysicalVolume* DetectorConstruction::Construct()
|
|---|
| 78 | {
|
|---|
| 79 | return ConstructVolumes();
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 83 |
|
|---|
| 84 | void DetectorConstruction::DefineMaterials()
|
|---|
| 85 | {
|
|---|
| 86 | G4NistManager* man = G4NistManager::Instance();
|
|---|
| 87 |
|
|---|
| 88 | G4bool isotopes = false;
|
|---|
| 89 |
|
|---|
| 90 | man->FindOrBuildMaterial("G4_Al", isotopes);
|
|---|
| 91 | man->FindOrBuildMaterial("G4_Si", isotopes);
|
|---|
| 92 | man->FindOrBuildMaterial("G4_Fe", isotopes);
|
|---|
| 93 | man->FindOrBuildMaterial("G4_Ge", isotopes);
|
|---|
| 94 | man->FindOrBuildMaterial("G4_Mo", isotopes);
|
|---|
| 95 | man->FindOrBuildMaterial("G4_Ta", isotopes);
|
|---|
| 96 | man->FindOrBuildMaterial("G4_W" , isotopes);
|
|---|
| 97 | man->FindOrBuildMaterial("G4_Au", isotopes);
|
|---|
| 98 | man->FindOrBuildMaterial("G4_Pb", isotopes);
|
|---|
| 99 | man->FindOrBuildMaterial("G4_PbWO4", isotopes);
|
|---|
| 100 | man->FindOrBuildMaterial("G4_SODIUM_IODIDE", isotopes);
|
|---|
| 101 |
|
|---|
| 102 | man->FindOrBuildMaterial("G4_AIR" , isotopes);
|
|---|
| 103 | ///man->FindOrBuildMaterial("G4_WATER", isotopes);
|
|---|
| 104 |
|
|---|
| 105 | G4Element* H = man->FindOrBuildElement("H", isotopes);
|
|---|
| 106 | G4Element* O = man->FindOrBuildElement("O", isotopes);
|
|---|
| 107 |
|
|---|
| 108 | G4Material* H2O =
|
|---|
| 109 | new G4Material("Water", 1.000*g/cm3, 2);
|
|---|
| 110 | H2O->AddElement(H, 2);
|
|---|
| 111 | H2O->AddElement(O, 1);
|
|---|
| 112 | H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV);
|
|---|
| 113 |
|
|---|
| 114 | G4cout << *(G4Material::GetMaterialTable()) << G4endl;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 118 |
|
|---|
| 119 | G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
|
|---|
| 120 | {
|
|---|
| 121 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 122 | G4PhysicalVolumeStore::GetInstance()->Clean();
|
|---|
| 123 | G4LogicalVolumeStore::GetInstance()->Clean();
|
|---|
| 124 | G4SolidStore::GetInstance()->Clean();
|
|---|
| 125 |
|
|---|
| 126 | // Absorber
|
|---|
| 127 | //
|
|---|
| 128 | G4Box*
|
|---|
| 129 | sAbsor = new G4Box("Absorber", //name
|
|---|
| 130 | absorSizeX/2,absorSizeYZ/2,absorSizeYZ/2); //size
|
|---|
| 131 |
|
|---|
| 132 | G4LogicalVolume*
|
|---|
| 133 | lAbsor = new G4LogicalVolume(sAbsor, //solid
|
|---|
| 134 | absorMaterial, //material
|
|---|
| 135 | "Absorber"); //name
|
|---|
| 136 |
|
|---|
| 137 | pAbsor = new G4PVPlacement(0, //no rotation
|
|---|
| 138 | G4ThreeVector(), //at (0,0,0)
|
|---|
| 139 | lAbsor, //logical volume
|
|---|
| 140 | "Absorber", //name
|
|---|
| 141 | 0, //mother volume
|
|---|
| 142 | false, //no boolean operation
|
|---|
| 143 | 0); //copy number
|
|---|
| 144 |
|
|---|
| 145 | // Layers
|
|---|
| 146 | //
|
|---|
| 147 | layerThickness = absorSizeX/nbOfLayers;
|
|---|
| 148 |
|
|---|
| 149 | if (nbOfLayers > 1) {
|
|---|
| 150 |
|
|---|
| 151 | G4Box*
|
|---|
| 152 | sLayer = new G4Box("Layer", //name
|
|---|
| 153 | layerThickness/2,absorSizeYZ/2,absorSizeYZ/2); //dimensions
|
|---|
| 154 |
|
|---|
| 155 | G4LogicalVolume*
|
|---|
| 156 | lLayer = new G4LogicalVolume(sLayer, //shape
|
|---|
| 157 | absorMaterial, //material
|
|---|
| 158 | "Layer"); //name
|
|---|
| 159 |
|
|---|
| 160 | new G4PVReplica("Layer", //name
|
|---|
| 161 | lLayer, //logical volume
|
|---|
| 162 | lAbsor, //mother volume
|
|---|
| 163 | kXAxis, //axis of replica
|
|---|
| 164 | nbOfLayers, //number of replica
|
|---|
| 165 | layerThickness); //width of replica
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | PrintParameters();
|
|---|
| 169 |
|
|---|
| 170 | //
|
|---|
| 171 | //always return the root volume
|
|---|
| 172 | //
|
|---|
| 173 | return pAbsor;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 177 |
|
|---|
| 178 | void DetectorConstruction::PrintParameters()
|
|---|
| 179 | {
|
|---|
| 180 | G4cout << "\n---------------------------------------------------------\n";
|
|---|
| 181 | G4cout << "---> The Absorber is " << G4BestUnit(absorSizeX,"Length")
|
|---|
| 182 | << " of " << absorMaterial->GetName() << " divided in " << nbOfLayers
|
|---|
| 183 | << " slices of " << G4BestUnit(layerThickness,"Length") << G4endl;
|
|---|
| 184 | G4cout << "\n---------------------------------------------------------\n";
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 188 |
|
|---|
| 189 | void DetectorConstruction::SetSizeX(G4double value)
|
|---|
| 190 | {
|
|---|
| 191 | absorSizeX = value;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 195 |
|
|---|
| 196 | void DetectorConstruction::SetSizeYZ(G4double value)
|
|---|
| 197 | {
|
|---|
| 198 | absorSizeYZ = value;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 202 |
|
|---|
| 203 | void DetectorConstruction::SetMaterial(G4String materialChoice)
|
|---|
| 204 | {
|
|---|
| 205 | // search the material by its name
|
|---|
| 206 | G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
|
|---|
| 207 | if (pttoMaterial) absorMaterial = pttoMaterial;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 211 |
|
|---|
| 212 | void DetectorConstruction::SetNbOfLayers(G4int value)
|
|---|
| 213 | {
|
|---|
| 214 | nbOfLayers = value;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 218 |
|
|---|
| 219 | #include "G4FieldManager.hh"
|
|---|
| 220 | #include "G4TransportationManager.hh"
|
|---|
| 221 |
|
|---|
| 222 | void DetectorConstruction::SetMagField(G4double fieldValue)
|
|---|
| 223 | {
|
|---|
| 224 | //apply a global uniform magnetic field along Z axis
|
|---|
| 225 | G4FieldManager* fieldMgr
|
|---|
| 226 | = G4TransportationManager::GetTransportationManager()->GetFieldManager();
|
|---|
| 227 |
|
|---|
| 228 | if (magField) delete magField; //delete the existing magn field
|
|---|
| 229 |
|
|---|
| 230 | if (fieldValue!=0.) // create a new one if non nul
|
|---|
| 231 | {
|
|---|
| 232 | magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
|
|---|
| 233 | fieldMgr->SetDetectorField(magField);
|
|---|
| 234 | fieldMgr->CreateChordFinder(magField);
|
|---|
| 235 | }
|
|---|
| 236 | else
|
|---|
| 237 | {
|
|---|
| 238 | magField = 0;
|
|---|
| 239 | fieldMgr->SetDetectorField(magField);
|
|---|
| 240 | }
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 244 |
|
|---|
| 245 | #include "G4RunManager.hh"
|
|---|
| 246 |
|
|---|
| 247 | void DetectorConstruction::UpdateGeometry()
|
|---|
| 248 | {
|
|---|
| 249 | G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|