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 /// \file exoticphysics/monopole/src/DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConst 27 /// \brief Implementation of the DetectorConstruction class 28 // 28 // >> 29 // $Id: DetectorConstruction.cc 66994 2013-01-29 14:34:08Z gcosmo $ 29 // 30 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 33 33 #include "DetectorConstruction.hh" 34 #include "DetectorConstruction.hh" 34 << 35 #include "DetectorMessenger.hh" 35 #include "DetectorMessenger.hh" 36 36 >> 37 #include "G4Material.hh" 37 #include "G4Box.hh" 38 #include "G4Box.hh" 38 #include "G4GeometryManager.hh" << 39 #include "G4LogicalVolume.hh" 39 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4Material.hh" << 42 #include "G4MonopoleFieldSetup.hh" << 43 #include "G4NistManager.hh" << 44 #include "G4PVPlacement.hh" 40 #include "G4PVPlacement.hh" >> 41 #include "G4UniformMagField.hh" >> 42 >> 43 #include "G4GeometryManager.hh" >> 44 #include "G4UserLimits.hh" 45 #include "G4PhysicalVolumeStore.hh" 45 #include "G4PhysicalVolumeStore.hh" >> 46 #include "G4LogicalVolumeStore.hh" 46 #include "G4SolidStore.hh" 47 #include "G4SolidStore.hh" 47 #include "G4StateManager.hh" << 48 48 #include "G4UniformMagField.hh" << 49 #include "G4UnitsTable.hh" 49 #include "G4UnitsTable.hh" 50 #include "G4UserLimits.hh" << 50 #include "G4NistManager.hh" 51 // #include "G4FieldManager.hh" << 51 52 // #include "G4TransportationManager.hh" << 52 #include "G4MonopoleFieldSetup.hh" 53 #include "G4AutoDelete.hh" << 53 #include "G4FieldManager.hh" 54 #include "G4GlobalMagFieldMessenger.hh" << 54 #include "G4TransportationManager.hh" 55 #include "G4RunManager.hh" << 56 #include "G4SystemOfUnits.hh" << 57 #include "G4ThreeVector.hh" 55 #include "G4ThreeVector.hh" >> 56 #include "G4RunManager.hh" >> 57 #include "G4SystemOfUnits.hh" 58 58 59 //....oooOO0OOooo........oooOO0OOooo........oo 59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 60 60 61 DetectorConstruction::DetectorConstruction() 61 DetectorConstruction::DetectorConstruction() 62 : G4VUserDetectorConstruction(), << 63 fWorldMaterial(0), << 64 fAbsorMaterial(0), << 65 fLogAbsor(0), << 66 fMonFieldSetup(), << 67 fDetectorMessenger(0) << 68 { 62 { 69 // default parameter values 63 // default parameter values 70 fAbsorSizeX = fAbsorSizeYZ = 10 * cm; 64 fAbsorSizeX = fAbsorSizeYZ = 10 * cm; 71 fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSiz 65 fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSizeX; 72 fMaxStepSize = 5 * mm; 66 fMaxStepSize = 5 * mm; 73 67 >> 68 fAbsorMaterial = 0; >> 69 fMagField = 0; >> 70 fLogAbsor = 0; >> 71 fMonFieldSetup = G4MonopoleFieldSetup::GetMonopoleFieldSetup(); >> 72 74 SetMaterial("G4_Al"); 73 SetMaterial("G4_Al"); 75 fWorldMaterial = G4NistManager::Instance()-> << 74 fWorldMaterial = >> 75 G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic"); 76 76 77 // create commands for interactive definitio 77 // create commands for interactive definition of the detector 78 fDetectorMessenger = new DetectorMessenger(t 78 fDetectorMessenger = new DetectorMessenger(this); 79 } 79 } 80 80 81 //....oooOO0OOooo........oooOO0OOooo........oo 81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 82 82 83 DetectorConstruction::~DetectorConstruction() 83 DetectorConstruction::~DetectorConstruction() 84 { 84 { 85 delete fDetectorMessenger; 85 delete fDetectorMessenger; 86 // delete fMonFieldSetup; << 87 } 86 } 88 87 89 //....oooOO0OOooo........oooOO0OOooo........oo 88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 90 89 91 G4VPhysicalVolume* DetectorConstruction::Const 90 G4VPhysicalVolume* DetectorConstruction::Construct() 92 { << 91 { 93 G4GeometryManager::GetInstance()->OpenGeomet 92 G4GeometryManager::GetInstance()->OpenGeometry(); 94 G4PhysicalVolumeStore::GetInstance()->Clean( 93 G4PhysicalVolumeStore::GetInstance()->Clean(); 95 G4LogicalVolumeStore::GetInstance()->Clean() 94 G4LogicalVolumeStore::GetInstance()->Clean(); 96 G4SolidStore::GetInstance()->Clean(); 95 G4SolidStore::GetInstance()->Clean(); 97 96 98 /**************************** World *** 97 /**************************** World *****************************/ 99 G4Box* sWorld = new G4Box("world", fWorldSiz << 98 G4Box * sWorld = new G4Box("world", >> 99 fWorldSizeX / 2, fWorldSizeYZ / 2, fWorldSizeYZ / 2); 100 100 101 G4LogicalVolume* lWorld = new G4LogicalVolum << 101 G4LogicalVolume * lWorld = new G4LogicalVolume(sWorld, >> 102 fWorldMaterial, >> 103 "world"); >> 104 >> 105 G4VPhysicalVolume * pWorld = new G4PVPlacement(0, //no rotation >> 106 G4ThreeVector(), //at (0,0,0) >> 107 lWorld, //logical volume >> 108 "world", //name >> 109 0, //mother volume >> 110 false, //no boolean operation >> 111 0); //copy number 102 112 103 G4VPhysicalVolume* pWorld = new G4PVPlacemen << 104 << 105 << 106 << 107 << 108 << 109 << 110 113 111 /************************** Absorber * 114 /************************** Absorber ***************************/ 112 G4Box* sAbsor = new G4Box("Absorber", fAbsor << 115 G4Box * sAbsor = new G4Box("Absorber", 113 << 116 fAbsorSizeX / 2, fAbsorSizeYZ / 2, fAbsorSizeYZ / 2); 114 fLogAbsor = new G4LogicalVolume(sAbsor, fAbs << 115 117 116 new G4PVPlacement(0, // no rotation << 118 fLogAbsor = new G4LogicalVolume(sAbsor, 117 G4ThreeVector(), // at (0 << 119 fAbsorMaterial, 118 fLogAbsor, // logical vol << 120 "Absorber"); 119 "Absorber", // name << 121 120 lWorld, // mother volume << 122 new G4PVPlacement(0, //no rotation 121 false, // no boolean oper << 123 G4ThreeVector(), //at (0,0,0) 122 0); // copy number << 124 fLogAbsor, //logical volume >> 125 "Absorber", //name >> 126 lWorld, //mother volume >> 127 false, //no boolean operation >> 128 0); //copy number 123 fLogAbsor->SetUserLimits(new G4UserLimits(fM 129 fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize)); 124 130 125 PrintParameters(); 131 PrintParameters(); 126 132 127 /************ always return the World vo 133 /************ always return the World volume *****************/ 128 return pWorld; 134 return pWorld; 129 } 135 } 130 136 131 //....oooOO0OOooo........oooOO0OOooo........oo 137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 132 138 133 void DetectorConstruction::PrintParameters() 139 void DetectorConstruction::PrintParameters() 134 { 140 { 135 G4cout << "\n------------------------------- 141 G4cout << "\n---------------------------------------------------------\n"; 136 G4cout << "---> The Absorber is " << G4BestU << 142 G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeX, "Length") 137 << fAbsorMaterial->GetName() << G4end << 143 << " of " << fAbsorMaterial->GetName() << G4endl; 138 G4cout << "\n------------------------------- 144 G4cout << "\n---------------------------------------------------------\n"; >> 145 139 } 146 } 140 147 141 //....oooOO0OOooo........oooOO0OOooo........oo 148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 142 149 143 void DetectorConstruction::SetSizeX(G4double v 150 void DetectorConstruction::SetSizeX(G4double value) 144 { 151 { 145 if (value > 0.0) { << 152 if(value > 0.0) { 146 fAbsorSizeX = value; << 153 fAbsorSizeX = value; 147 fWorldSizeX = 1.2 * fAbsorSizeX; 154 fWorldSizeX = 1.2 * fAbsorSizeX; 148 if (G4StateManager::GetStateManager()->Get << 155 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 149 G4RunManager::GetRunManager()->Reinitial << 150 } << 151 } 156 } 152 } 157 } 153 << 158 154 //....oooOO0OOooo........oooOO0OOooo........oo 159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 155 160 156 void DetectorConstruction::SetSizeYZ(G4double 161 void DetectorConstruction::SetSizeYZ(G4double value) 157 { 162 { 158 if (value > 0.0) { << 163 if(value > 0.0) { 159 fAbsorSizeYZ = value; << 164 fAbsorSizeYZ = value; 160 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; 165 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; 161 if (G4StateManager::GetStateManager()->Get << 166 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 162 G4RunManager::GetRunManager()->Reinitial << 163 } << 164 } 167 } 165 } << 168 } 166 169 167 //....oooOO0OOooo........oooOO0OOooo........oo 170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 168 171 169 void DetectorConstruction::SetMaterial(const G 172 void DetectorConstruction::SetMaterial(const G4String& namemat) 170 { 173 { 171 // search the material by its name << 174 // search the material by its name 172 G4Material* mat = G4NistManager::Instance()- 175 G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(namemat); 173 if (!mat) { << 176 if(!mat) { 174 G4cout << "!!! DetectorConstruction::SetMa << 177 G4cout << "!!! DetectorConstruction::SetMaterial: WARNING Material <" 175 << "> does not exist in DB" << G4en << 178 << namemat << "> does not exist in DB" << G4endl; 176 return; 179 return; 177 } 180 } 178 // new material is found out 181 // new material is found out 179 if (mat != fAbsorMaterial) { 182 if (mat != fAbsorMaterial) { 180 fAbsorMaterial = mat; 183 fAbsorMaterial = mat; 181 if (fLogAbsor) { << 184 if(fLogAbsor) { fLogAbsor->SetMaterial(mat); } 182 fLogAbsor->SetMaterial(mat); << 183 } << 184 G4RunManager::GetRunManager()->PhysicsHasB 185 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 185 } 186 } 186 } 187 } 187 188 188 //....oooOO0OOooo........oooOO0OOooo........oo << 189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 189 190 190 void DetectorConstruction::ConstructSDandField << 191 void DetectorConstruction::SetMagField(G4double fieldValue) 191 { 192 { 192 // Define magnetic field << 193 fMonFieldSetup->SetMagField(fieldValue); 193 if (!fMonFieldSetup.Get()) { << 194 194 G4MonopoleFieldSetup* fieldSetup = new G4M << 195 //apply a global uniform magnetic field along Z axis 195 G4AutoDelete::Register(fieldSetup); // Ke << 196 G4FieldManager * fieldMgr = 196 fMonFieldSetup.Put(fieldSetup); << 197 G4TransportationManager::GetTransportationManager()->GetFieldManager(); 197 } << 198 198 fMonFieldSetup.Get()->ConstructMagField(); << 199 if (fMagField) { delete fMagField; } //delete the existing magn field >> 200 >> 201 if (fieldValue != 0.) // create a new one if non nul >> 202 { >> 203 fMagField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue)); >> 204 fieldMgr->SetDetectorField(fMagField); >> 205 fieldMgr->CreateChordFinder(fMagField); >> 206 } >> 207 else >> 208 { >> 209 fMagField = 0; >> 210 fieldMgr->SetDetectorField(fMagField); >> 211 } 199 } 212 } 200 213 201 //....oooOO0OOooo........oooOO0OOooo........oo 214 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 202 215 203 void DetectorConstruction::SetMaxStepSize(G4do 216 void DetectorConstruction::SetMaxStepSize(G4double step) 204 { 217 { 205 fMaxStepSize = step; 218 fMaxStepSize = step; 206 if (fLogAbsor) { << 219 if(fLogAbsor) { fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize)); } 207 fLogAbsor->SetUserLimits(new G4UserLimits( << 220 } 208 } << 221 >> 222 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 223 >> 224 void DetectorConstruction::UpdateGeometry() >> 225 { >> 226 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 209 } 227 } 210 228 211 //....oooOO0OOooo........oooOO0OOooo........oo 229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 212 230