[807] | 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.1 2007/08/16 10:32:04 vnivanch Exp $ |
---|
| 27 | // GEANT4 tag $Name: $ |
---|
| 28 | // |
---|
| 29 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 31 | |
---|
| 32 | #include "DetectorConstruction.hh" |
---|
| 33 | #include "DetectorMessenger.hh" |
---|
| 34 | |
---|
| 35 | #include "G4Material.hh" |
---|
| 36 | #include "G4Box.hh" |
---|
| 37 | #include "G4LogicalVolume.hh" |
---|
| 38 | #include "G4PVPlacement.hh" |
---|
| 39 | #include "G4UniformMagField.hh" |
---|
| 40 | |
---|
| 41 | #include "G4GeometryManager.hh" |
---|
| 42 | #include "G4UserLimits.hh" |
---|
| 43 | #include "G4PhysicalVolumeStore.hh" |
---|
| 44 | #include "G4LogicalVolumeStore.hh" |
---|
| 45 | #include "G4SolidStore.hh" |
---|
| 46 | |
---|
| 47 | #include "G4UnitsTable.hh" |
---|
| 48 | #include "G4NistManager.hh" |
---|
| 49 | |
---|
| 50 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 51 | |
---|
| 52 | DetectorConstruction::DetectorConstruction() |
---|
| 53 | { |
---|
| 54 | // default parameter values |
---|
| 55 | absorSizeX = absorSizeYZ = 10 * cm; |
---|
| 56 | worldSizeX = worldSizeYZ = 1.2 * absorSizeX; |
---|
| 57 | maxStepSize = 5 * mm; |
---|
| 58 | |
---|
| 59 | worldMaterial = absorMaterial = 0; |
---|
| 60 | magField = 0; |
---|
| 61 | lAbsor = 0; |
---|
| 62 | |
---|
| 63 | DefineMaterials(); |
---|
| 64 | SetMaterial("G4_Al"); |
---|
| 65 | |
---|
| 66 | // create commands for interactive definition of the detector |
---|
| 67 | detectorMessenger = new DetectorMessenger(this); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | DetectorConstruction::~DetectorConstruction() |
---|
| 73 | {delete detectorMessenger;} |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | G4VPhysicalVolume* DetectorConstruction::Construct() |
---|
| 77 | { return ConstructVolumes();} |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | void DetectorConstruction::DefineMaterials() |
---|
| 81 | { |
---|
| 82 | /*********************** define Elements *********************/ |
---|
| 83 | G4double z, a; |
---|
| 84 | |
---|
| 85 | G4Element* N = new G4Element("Nitrogen", "N", z= 7, a= 14.01*g/mole); |
---|
| 86 | G4Element* O = new G4Element("Oxygen" , "O", z= 8, a= 16.00*g/mole); |
---|
| 87 | |
---|
| 88 | /*********************** define Materials **********************/ |
---|
| 89 | G4double density, temperature, pressure; |
---|
| 90 | G4int ncomponents; |
---|
| 91 | G4double fractionmass; |
---|
| 92 | |
---|
| 93 | G4Material* Air = new G4Material("Air" , density = 1.290 * mg/cm3, ncomponents=2); |
---|
| 94 | Air->AddElement(N, fractionmass = 0.7); |
---|
| 95 | Air->AddElement(O, fractionmass = 0.3); |
---|
| 96 | |
---|
| 97 | density = universe_mean_density; //from PhysicalConstants.h |
---|
| 98 | pressure = 3.e-18 * pascal; |
---|
| 99 | temperature = 2.73 * kelvin; |
---|
| 100 | |
---|
| 101 | G4Material* vacuum = new G4Material("Galactic", z = 1, a = 1.008 * g/mole, density, |
---|
| 102 | kStateGas, temperature, pressure); |
---|
| 103 | |
---|
| 104 | G4cout << *(G4Material::GetMaterialTable()) << G4endl; |
---|
| 105 | |
---|
| 106 | //default materials |
---|
| 107 | worldMaterial = vacuum; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 112 | G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() |
---|
| 113 | { |
---|
| 114 | G4GeometryManager::GetInstance()->OpenGeometry(); |
---|
| 115 | G4PhysicalVolumeStore::GetInstance()->Clean(); |
---|
| 116 | G4LogicalVolumeStore::GetInstance()->Clean(); |
---|
| 117 | G4SolidStore::GetInstance()->Clean(); |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | /**************************** World *****************************/ |
---|
| 122 | G4Box * sWorld = new G4Box("world", //name |
---|
| 123 | worldSizeX / 2, worldSizeYZ / 2, worldSizeYZ / 2); //dimensions |
---|
| 124 | |
---|
| 125 | G4LogicalVolume * lWorld = new G4LogicalVolume(sWorld, //shape |
---|
| 126 | worldMaterial, //material |
---|
| 127 | "world"); //name |
---|
| 128 | |
---|
| 129 | G4VPhysicalVolume * pWorld = new G4PVPlacement(0, //no rotation |
---|
| 130 | G4ThreeVector(), //at (0,0,0) |
---|
| 131 | lWorld, //logical volume |
---|
| 132 | "world", //name |
---|
| 133 | 0, //mother volume |
---|
| 134 | false, //no boolean operation |
---|
| 135 | 0); //copy number |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | /************************** Absorber ***************************/ |
---|
| 139 | G4Box * sAbsor = new G4Box("Absorber", //name |
---|
| 140 | absorSizeX / 2, absorSizeYZ / 2, absorSizeYZ / 2); //dimensions |
---|
| 141 | |
---|
| 142 | lAbsor = new G4LogicalVolume(sAbsor, //shape |
---|
| 143 | absorMaterial, //material |
---|
| 144 | "Absorber"); //name |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | new G4PVPlacement(0, //no rotation |
---|
| 148 | G4ThreeVector(), //at (0,0,0) |
---|
| 149 | lAbsor, //logical volume |
---|
| 150 | "Absorber", //name |
---|
| 151 | lWorld, //mother volume |
---|
| 152 | false, //no boolean operation |
---|
| 153 | 0); //copy number |
---|
| 154 | lAbsor->SetUserLimits(new G4UserLimits(maxStepSize)); |
---|
| 155 | |
---|
| 156 | PrintParameters(); |
---|
| 157 | |
---|
| 158 | /************ always return the World volume *****************/ |
---|
| 159 | return pWorld; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 165 | void DetectorConstruction::PrintParameters() |
---|
| 166 | { |
---|
| 167 | G4cout << "\n---------------------------------------------------------\n"; |
---|
| 168 | G4cout << "---> The Absorber is " << G4BestUnit(absorSizeX, "Length") |
---|
| 169 | << " of " << absorMaterial->GetName() << G4endl; |
---|
| 170 | G4cout << "\n---------------------------------------------------------\n"; |
---|
| 171 | |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 176 | void DetectorConstruction::SetSizeX(G4double value) |
---|
| 177 | { |
---|
| 178 | absorSizeX = value; worldSizeX = 1.2 * absorSizeX; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 183 | void DetectorConstruction::SetSizeYZ(G4double value) |
---|
| 184 | { |
---|
| 185 | absorSizeYZ = value; |
---|
| 186 | worldSizeYZ = 1.2 * absorSizeYZ; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 191 | void DetectorConstruction::SetMaterial(G4String materialChoice) |
---|
| 192 | { |
---|
| 193 | // search the material by its name |
---|
| 194 | G4Material * pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); |
---|
| 195 | if (pttoMaterial) absorMaterial = pttoMaterial; |
---|
| 196 | else G4cout << "Material does not exist in DB" << G4endl; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 201 | #include "G4FieldManager.hh" |
---|
| 202 | #include "G4TransportationManager.hh" |
---|
| 203 | |
---|
| 204 | void DetectorConstruction::SetMagField(G4double fieldValue) |
---|
| 205 | { |
---|
| 206 | //apply a global uniform magnetic field along Z axis |
---|
| 207 | G4FieldManager * fieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager(); |
---|
| 208 | |
---|
| 209 | if (magField) delete magField; //delete the existing magn field |
---|
| 210 | |
---|
| 211 | if (fieldValue != 0.) // create a new one if non nul |
---|
| 212 | { |
---|
| 213 | magField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue)); |
---|
| 214 | fieldMgr->SetDetectorField(magField); |
---|
| 215 | fieldMgr->CreateChordFinder(magField); |
---|
| 216 | } |
---|
| 217 | else |
---|
| 218 | { |
---|
| 219 | magField = 0; |
---|
| 220 | fieldMgr->SetDetectorField(magField); |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 226 | void DetectorConstruction::SetMaxStepSize(G4double step_) |
---|
| 227 | { |
---|
| 228 | maxStepSize = step_; |
---|
| 229 | if(lAbsor) lAbsor->SetUserLimits(new G4UserLimits(maxStepSize)); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 234 | #include "G4RunManager.hh" |
---|
| 235 | |
---|
| 236 | void DetectorConstruction::UpdateGeometry() |
---|
| 237 | { |
---|
| 238 | G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|