Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 /// \file exoticphysics/monopole/src/DetectorC << 26 // $Id: DetectorConstruction.cc,v 1.1 2007/08/16 10:32:04 vnivanch Exp $ 27 /// \brief Implementation of the DetectorConst << 27 // GEANT4 tag $Name: geant4-09-02-patch-03 $ 28 // << 29 // 28 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 31 33 #include "DetectorConstruction.hh" 32 #include "DetectorConstruction.hh" 34 << 35 #include "DetectorMessenger.hh" 33 #include "DetectorMessenger.hh" 36 34 >> 35 #include "G4Material.hh" 37 #include "G4Box.hh" 36 #include "G4Box.hh" 38 #include "G4GeometryManager.hh" << 39 #include "G4LogicalVolume.hh" 37 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4Material.hh" << 42 #include "G4MonopoleFieldSetup.hh" << 43 #include "G4NistManager.hh" << 44 #include "G4PVPlacement.hh" 38 #include "G4PVPlacement.hh" >> 39 #include "G4UniformMagField.hh" >> 40 >> 41 #include "G4GeometryManager.hh" >> 42 #include "G4UserLimits.hh" 45 #include "G4PhysicalVolumeStore.hh" 43 #include "G4PhysicalVolumeStore.hh" >> 44 #include "G4LogicalVolumeStore.hh" 46 #include "G4SolidStore.hh" 45 #include "G4SolidStore.hh" 47 #include "G4StateManager.hh" << 46 48 #include "G4UniformMagField.hh" << 49 #include "G4UnitsTable.hh" 47 #include "G4UnitsTable.hh" 50 #include "G4UserLimits.hh" << 48 #include "G4NistManager.hh" 51 // #include "G4FieldManager.hh" << 52 // #include "G4TransportationManager.hh" << 53 #include "G4AutoDelete.hh" << 54 #include "G4GlobalMagFieldMessenger.hh" << 55 #include "G4RunManager.hh" << 56 #include "G4SystemOfUnits.hh" << 57 #include "G4ThreeVector.hh" << 58 49 59 //....oooOO0OOooo........oooOO0OOooo........oo 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 60 51 61 DetectorConstruction::DetectorConstruction() 52 DetectorConstruction::DetectorConstruction() 62 : G4VUserDetectorConstruction(), << 63 fWorldMaterial(0), << 64 fAbsorMaterial(0), << 65 fLogAbsor(0), << 66 fMonFieldSetup(), << 67 fDetectorMessenger(0) << 68 { 53 { 69 // default parameter values 54 // default parameter values 70 fAbsorSizeX = fAbsorSizeYZ = 10 * cm; << 55 absorSizeX = absorSizeYZ = 10 * cm; 71 fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSiz << 56 worldSizeX = worldSizeYZ = 1.2 * absorSizeX; 72 fMaxStepSize = 5 * mm; << 57 maxStepSize = 5 * mm; >> 58 >> 59 worldMaterial = absorMaterial = 0; >> 60 magField = 0; >> 61 lAbsor = 0; 73 62 >> 63 DefineMaterials(); 74 SetMaterial("G4_Al"); 64 SetMaterial("G4_Al"); 75 fWorldMaterial = G4NistManager::Instance()-> << 76 65 77 // create commands for interactive definitio 66 // create commands for interactive definition of the detector 78 fDetectorMessenger = new DetectorMessenger(t << 67 detectorMessenger = new DetectorMessenger(this); 79 } 68 } 80 69 81 //....oooOO0OOooo........oooOO0OOooo........oo << 70 82 71 83 DetectorConstruction::~DetectorConstruction() 72 DetectorConstruction::~DetectorConstruction() 84 { << 73 {delete detectorMessenger;} 85 delete fDetectorMessenger; << 86 // delete fMonFieldSetup; << 87 } << 88 74 89 //....oooOO0OOooo........oooOO0OOooo........oo << 90 75 91 G4VPhysicalVolume* DetectorConstruction::Const 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() 92 { 113 { 93 G4GeometryManager::GetInstance()->OpenGeomet 114 G4GeometryManager::GetInstance()->OpenGeometry(); 94 G4PhysicalVolumeStore::GetInstance()->Clean( 115 G4PhysicalVolumeStore::GetInstance()->Clean(); 95 G4LogicalVolumeStore::GetInstance()->Clean() 116 G4LogicalVolumeStore::GetInstance()->Clean(); 96 G4SolidStore::GetInstance()->Clean(); 117 G4SolidStore::GetInstance()->Clean(); 97 118 98 /**************************** World *** << 99 G4Box* sWorld = new G4Box("world", fWorldSiz << 100 119 101 G4LogicalVolume* lWorld = new G4LogicalVolum << 102 120 103 G4VPhysicalVolume* pWorld = new G4PVPlacemen << 121 /**************************** World *****************************/ 104 << 122 G4Box * sWorld = new G4Box("world", //name 105 << 123 worldSizeX / 2, worldSizeYZ / 2, worldSizeYZ / 2); //dimensions 106 << 107 << 108 << 109 << 110 124 111 /************************** Absorber * << 125 G4LogicalVolume * lWorld = new G4LogicalVolume(sWorld, //shape 112 G4Box* sAbsor = new G4Box("Absorber", fAbsor << 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 113 136 114 fLogAbsor = new G4LogicalVolume(sAbsor, fAbs << 115 137 116 new G4PVPlacement(0, // no rotation << 138 /************************** Absorber ***************************/ 117 G4ThreeVector(), // at (0 << 139 G4Box * sAbsor = new G4Box("Absorber", //name 118 fLogAbsor, // logical vol << 140 absorSizeX / 2, absorSizeYZ / 2, absorSizeYZ / 2); //dimensions 119 "Absorber", // name << 141 120 lWorld, // mother volume << 142 lAbsor = new G4LogicalVolume(sAbsor, //shape 121 false, // no boolean oper << 143 absorMaterial, //material 122 0); // copy number << 144 "Absorber"); //name 123 fLogAbsor->SetUserLimits(new G4UserLimits(fM << 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)); 124 155 125 PrintParameters(); 156 PrintParameters(); 126 157 127 /************ always return the World vo 158 /************ always return the World volume *****************/ 128 return pWorld; 159 return pWorld; 129 } 160 } 130 161 131 //....oooOO0OOooo........oooOO0OOooo........oo << 132 162 >> 163 >> 164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 133 void DetectorConstruction::PrintParameters() 165 void DetectorConstruction::PrintParameters() 134 { 166 { 135 G4cout << "\n------------------------------- 167 G4cout << "\n---------------------------------------------------------\n"; 136 G4cout << "---> The Absorber is " << G4BestU << 168 G4cout << "---> The Absorber is " << G4BestUnit(absorSizeX, "Length") 137 << fAbsorMaterial->GetName() << G4end << 169 << " of " << absorMaterial->GetName() << G4endl; 138 G4cout << "\n------------------------------- 170 G4cout << "\n---------------------------------------------------------\n"; >> 171 139 } 172 } 140 173 141 //....oooOO0OOooo........oooOO0OOooo........oo << 142 174 >> 175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 143 void DetectorConstruction::SetSizeX(G4double v 176 void DetectorConstruction::SetSizeX(G4double value) 144 { 177 { 145 if (value > 0.0) { << 178 absorSizeX = value; worldSizeX = 1.2 * absorSizeX; 146 fAbsorSizeX = value; << 147 fWorldSizeX = 1.2 * fAbsorSizeX; << 148 if (G4StateManager::GetStateManager()->Get << 149 G4RunManager::GetRunManager()->Reinitial << 150 } << 151 } << 152 } 179 } >> 180 153 181 154 //....oooOO0OOooo........oooOO0OOooo........oo 182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 155 << 156 void DetectorConstruction::SetSizeYZ(G4double 183 void DetectorConstruction::SetSizeYZ(G4double value) 157 { 184 { 158 if (value > 0.0) { << 185 absorSizeYZ = value; 159 fAbsorSizeYZ = value; << 186 worldSizeYZ = 1.2 * absorSizeYZ; 160 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; << 187 } 161 if (G4StateManager::GetStateManager()->Get << 188 162 G4RunManager::GetRunManager()->Reinitial << 189 163 } << 190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 164 } << 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; 165 } 197 } 166 198 >> 199 167 //....oooOO0OOooo........oooOO0OOooo........oo 200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 201 #include "G4FieldManager.hh" >> 202 #include "G4TransportationManager.hh" 168 203 169 void DetectorConstruction::SetMaterial(const G << 204 void DetectorConstruction::SetMagField(G4double fieldValue) 170 { 205 { 171 // search the material by its name << 206 //apply a global uniform magnetic field along Z axis 172 G4Material* mat = G4NistManager::Instance()- << 207 G4FieldManager * fieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager(); 173 if (!mat) { << 208 174 G4cout << "!!! DetectorConstruction::SetMa << 209 if (magField) delete magField; //delete the existing magn field 175 << "> does not exist in DB" << G4en << 210 176 return; << 211 if (fieldValue != 0.) // create a new one if non nul 177 } << 212 { 178 // new material is found out << 213 magField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue)); 179 if (mat != fAbsorMaterial) { << 214 fieldMgr->SetDetectorField(magField); 180 fAbsorMaterial = mat; << 215 fieldMgr->CreateChordFinder(magField); 181 if (fLogAbsor) { << 216 } 182 fLogAbsor->SetMaterial(mat); << 217 else >> 218 { >> 219 magField = 0; >> 220 fieldMgr->SetDetectorField(magField); 183 } 221 } 184 G4RunManager::GetRunManager()->PhysicsHasB << 185 } << 186 } 222 } 187 223 188 //....oooOO0OOooo........oooOO0OOooo........oo << 189 224 190 void DetectorConstruction::ConstructSDandField << 225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 226 void DetectorConstruction::SetMaxStepSize(G4double step_) 191 { 227 { 192 // Define magnetic field << 228 maxStepSize = step_; 193 if (!fMonFieldSetup.Get()) { << 229 if(lAbsor) lAbsor->SetUserLimits(new G4UserLimits(maxStepSize)); 194 G4MonopoleFieldSetup* fieldSetup = new G4M << 195 G4AutoDelete::Register(fieldSetup); // Ke << 196 fMonFieldSetup.Put(fieldSetup); << 197 } << 198 fMonFieldSetup.Get()->ConstructMagField(); << 199 } 230 } 200 231 >> 232 201 //....oooOO0OOooo........oooOO0OOooo........oo 233 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 234 #include "G4RunManager.hh" 202 235 203 void DetectorConstruction::SetMaxStepSize(G4do << 236 void DetectorConstruction::UpdateGeometry() 204 { 237 { 205 fMaxStepSize = step; << 238 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); 206 if (fLogAbsor) { << 207 fLogAbsor->SetUserLimits(new G4UserLimits( << 208 } << 209 } 239 } 210 240 211 //....oooOO0OOooo........oooOO0OOooo........oo 241 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 212 242