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 104872 2017-06-23 14:19:16Z 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 >> 59 #include "G4GlobalMagFieldMessenger.hh" >> 60 #include "G4AutoDelete.hh" 58 61 59 //....oooOO0OOooo........oooOO0OOooo........oo 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 60 63 61 DetectorConstruction::DetectorConstruction() 64 DetectorConstruction::DetectorConstruction() 62 : G4VUserDetectorConstruction(), << 65 : G4VUserDetectorConstruction(), 63 fWorldMaterial(0), << 66 fWorldMaterial(0), 64 fAbsorMaterial(0), << 67 fAbsorMaterial(0), 65 fLogAbsor(0), << 68 fLogAbsor(0), 66 fMonFieldSetup(), << 69 fMonFieldSetup(0), 67 fDetectorMessenger(0) << 70 fZMagFieldValue(0.), >> 71 fDetectorMessenger(0) 68 { 72 { 69 // default parameter values 73 // default parameter values 70 fAbsorSizeX = fAbsorSizeYZ = 10 * cm; 74 fAbsorSizeX = fAbsorSizeYZ = 10 * cm; 71 fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSiz 75 fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSizeX; 72 fMaxStepSize = 5 * mm; 76 fMaxStepSize = 5 * mm; 73 77 >> 78 // fMonFieldSetup = G4MonopoleFieldSetup::GetMonopoleFieldSetup(); >> 79 fMonFieldSetup = new G4MonopoleFieldSetup(); >> 80 74 SetMaterial("G4_Al"); 81 SetMaterial("G4_Al"); 75 fWorldMaterial = G4NistManager::Instance()-> << 82 fWorldMaterial = >> 83 G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic"); 76 84 77 // create commands for interactive definitio 85 // create commands for interactive definition of the detector 78 fDetectorMessenger = new DetectorMessenger(t 86 fDetectorMessenger = new DetectorMessenger(this); 79 } 87 } 80 88 81 //....oooOO0OOooo........oooOO0OOooo........oo 89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 82 90 83 DetectorConstruction::~DetectorConstruction() 91 DetectorConstruction::~DetectorConstruction() 84 { 92 { 85 delete fDetectorMessenger; 93 delete fDetectorMessenger; 86 // delete fMonFieldSetup; 94 // delete fMonFieldSetup; 87 } 95 } 88 96 89 //....oooOO0OOooo........oooOO0OOooo........oo 97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 90 98 91 G4VPhysicalVolume* DetectorConstruction::Const 99 G4VPhysicalVolume* DetectorConstruction::Construct() 92 { << 100 { 93 G4GeometryManager::GetInstance()->OpenGeomet 101 G4GeometryManager::GetInstance()->OpenGeometry(); 94 G4PhysicalVolumeStore::GetInstance()->Clean( 102 G4PhysicalVolumeStore::GetInstance()->Clean(); 95 G4LogicalVolumeStore::GetInstance()->Clean() 103 G4LogicalVolumeStore::GetInstance()->Clean(); 96 G4SolidStore::GetInstance()->Clean(); 104 G4SolidStore::GetInstance()->Clean(); 97 105 98 /**************************** World *** 106 /**************************** World *****************************/ 99 G4Box* sWorld = new G4Box("world", fWorldSiz << 107 G4Box * sWorld = new G4Box("world", >> 108 fWorldSizeX / 2, fWorldSizeYZ / 2, fWorldSizeYZ / 2); 100 109 101 G4LogicalVolume* lWorld = new G4LogicalVolum << 110 G4LogicalVolume * lWorld = new G4LogicalVolume(sWorld, >> 111 fWorldMaterial, >> 112 "world"); >> 113 >> 114 G4VPhysicalVolume * pWorld = new G4PVPlacement(0, //no rotation >> 115 G4ThreeVector(), //at (0,0,0) >> 116 lWorld, //logical volume >> 117 "world", //name >> 118 0, //mother volume >> 119 false, //no boolean operation >> 120 0); //copy number 102 121 103 G4VPhysicalVolume* pWorld = new G4PVPlacemen << 104 << 105 << 106 << 107 << 108 << 109 << 110 122 111 /************************** Absorber * 123 /************************** Absorber ***************************/ 112 G4Box* sAbsor = new G4Box("Absorber", fAbsor << 124 G4Box * sAbsor = new G4Box("Absorber", >> 125 fAbsorSizeX / 2, fAbsorSizeYZ / 2, fAbsorSizeYZ / 2); 113 126 114 fLogAbsor = new G4LogicalVolume(sAbsor, fAbs << 127 fLogAbsor = new G4LogicalVolume(sAbsor, 115 << 128 fAbsorMaterial, 116 new G4PVPlacement(0, // no rotation << 129 "Absorber"); 117 G4ThreeVector(), // at (0 << 130 118 fLogAbsor, // logical vol << 131 new G4PVPlacement(0, //no rotation 119 "Absorber", // name << 132 G4ThreeVector(), //at (0,0,0) 120 lWorld, // mother volume << 133 fLogAbsor, //logical volume 121 false, // no boolean oper << 134 "Absorber", //name 122 0); // copy number << 135 lWorld, //mother volume >> 136 false, //no boolean operation >> 137 0); //copy number 123 fLogAbsor->SetUserLimits(new G4UserLimits(fM 138 fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize)); 124 139 125 PrintParameters(); 140 PrintParameters(); 126 141 127 /************ always return the World vo 142 /************ always return the World volume *****************/ 128 return pWorld; 143 return pWorld; 129 } 144 } 130 145 131 //....oooOO0OOooo........oooOO0OOooo........oo 146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 132 147 133 void DetectorConstruction::PrintParameters() 148 void DetectorConstruction::PrintParameters() 134 { 149 { 135 G4cout << "\n------------------------------- 150 G4cout << "\n---------------------------------------------------------\n"; 136 G4cout << "---> The Absorber is " << G4BestU << 151 G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeX, "Length") 137 << fAbsorMaterial->GetName() << G4end << 152 << " of " << fAbsorMaterial->GetName() << G4endl; 138 G4cout << "\n------------------------------- 153 G4cout << "\n---------------------------------------------------------\n"; >> 154 139 } 155 } 140 156 141 //....oooOO0OOooo........oooOO0OOooo........oo 157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 142 158 143 void DetectorConstruction::SetSizeX(G4double v 159 void DetectorConstruction::SetSizeX(G4double value) 144 { 160 { 145 if (value > 0.0) { << 161 if(value > 0.0) { 146 fAbsorSizeX = value; << 162 fAbsorSizeX = value; 147 fWorldSizeX = 1.2 * fAbsorSizeX; 163 fWorldSizeX = 1.2 * fAbsorSizeX; 148 if (G4StateManager::GetStateManager()->Get << 164 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 149 G4RunManager::GetRunManager()->Reinitial << 150 } << 151 } 165 } 152 } 166 } 153 << 167 154 //....oooOO0OOooo........oooOO0OOooo........oo 168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 155 169 156 void DetectorConstruction::SetSizeYZ(G4double 170 void DetectorConstruction::SetSizeYZ(G4double value) 157 { 171 { 158 if (value > 0.0) { << 172 if(value > 0.0) { 159 fAbsorSizeYZ = value; << 173 fAbsorSizeYZ = value; 160 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; 174 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; 161 if (G4StateManager::GetStateManager()->Get << 175 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 162 G4RunManager::GetRunManager()->Reinitial << 163 } << 164 } 176 } 165 } << 177 } 166 178 167 //....oooOO0OOooo........oooOO0OOooo........oo 179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 168 180 169 void DetectorConstruction::SetMaterial(const G 181 void DetectorConstruction::SetMaterial(const G4String& namemat) 170 { 182 { 171 // search the material by its name << 183 // search the material by its name 172 G4Material* mat = G4NistManager::Instance()- 184 G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(namemat); 173 if (!mat) { << 185 if(!mat) { 174 G4cout << "!!! DetectorConstruction::SetMa << 186 G4cout << "!!! DetectorConstruction::SetMaterial: WARNING Material <" 175 << "> does not exist in DB" << G4en << 187 << namemat << "> does not exist in DB" << G4endl; 176 return; 188 return; 177 } 189 } 178 // new material is found out 190 // new material is found out 179 if (mat != fAbsorMaterial) { 191 if (mat != fAbsorMaterial) { 180 fAbsorMaterial = mat; 192 fAbsorMaterial = mat; 181 if (fLogAbsor) { << 193 if(fLogAbsor) { fLogAbsor->SetMaterial(mat); } 182 fLogAbsor->SetMaterial(mat); << 183 } << 184 G4RunManager::GetRunManager()->PhysicsHasB 194 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 185 } 195 } 186 } 196 } 187 197 >> 198 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 199 >> 200 >> 201 // void DetectorConstruction::SetMagField(G4double fieldValue) >> 202 // { >> 203 // fMonFieldSetup->SetMagField(fieldValue); >> 204 >> 205 // //apply a global uniform magnetic field along Z axis >> 206 // G4FieldManager * fieldMgr = >> 207 // G4TransportationManager::GetTransportationManager()->GetFieldManager(); >> 208 >> 209 // if (fMagField) { delete fMagField; } //delete the existing magn field >> 210 >> 211 // if (fieldValue != 0.) // create a new one if non nul >> 212 // { >> 213 // fMagField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue)); >> 214 // fieldMgr->SetDetectorField(fMagField); >> 215 // fieldMgr->CreateChordFinder(fMagField); >> 216 // } >> 217 // else >> 218 // { >> 219 // fMagField = 0; >> 220 // fieldMgr->SetDetectorField(fMagField); >> 221 // } >> 222 // } >> 223 188 //....oooOO0OOooo........oooOO0OOooo........oo 224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 189 225 190 void DetectorConstruction::ConstructSDandField 226 void DetectorConstruction::ConstructSDandField() 191 { 227 { >> 228 192 // Define magnetic field 229 // Define magnetic field 193 if (!fMonFieldSetup.Get()) { << 230 bool bNewFieldValue = false; 194 G4MonopoleFieldSetup* fieldSetup = new G4M << 231 if ( fFieldMessenger.Get() != 0 ) { 195 G4AutoDelete::Register(fieldSetup); // Ke << 232 G4ThreeVector fieldSet = fFieldMessenger.Get()->GetFieldValue(); 196 fMonFieldSetup.Put(fieldSetup); << 233 if(fieldSet.z()!=fZMagFieldValue) bNewFieldValue = true; >> 234 } >> 235 else bNewFieldValue = true; >> 236 >> 237 // Monopole particule specific magnetic field >> 238 if(bNewFieldValue&&fZMagFieldValue!=0.) >> 239 fMonFieldSetup->SetMagField(fZMagFieldValue, true); >> 240 >> 241 if ( bNewFieldValue ) { >> 242 // Create global magnetic field messenger. >> 243 // Uniform magnetic field is then created automatically if >> 244 // the field value is not zero. >> 245 >> 246 if(fZMagFieldValue!=0.) >> 247 { >> 248 G4ThreeVector fieldValue = G4ThreeVector(0.,0.,fZMagFieldValue); >> 249 G4GlobalMagFieldMessenger* msg = >> 250 new G4GlobalMagFieldMessenger(fieldValue); >> 251 msg->SetVerboseLevel(1); >> 252 G4AutoDelete::Register(msg); >> 253 fFieldMessenger.Put( msg ); >> 254 } 197 } 255 } 198 fMonFieldSetup.Get()->ConstructMagField(); << 256 199 } 257 } 200 258 201 //....oooOO0OOooo........oooOO0OOooo........oo 259 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 202 260 203 void DetectorConstruction::SetMaxStepSize(G4do 261 void DetectorConstruction::SetMaxStepSize(G4double step) 204 { 262 { 205 fMaxStepSize = step; 263 fMaxStepSize = step; 206 if (fLogAbsor) { << 264 if(fLogAbsor) { fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize)); } 207 fLogAbsor->SetUserLimits(new G4UserLimits( << 265 } 208 } << 266 >> 267 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 268 >> 269 void DetectorConstruction::UpdateGeometry() >> 270 { >> 271 G4RunManager::GetRunManager()->ReinitializeGeometry(); 209 } 272 } 210 273 211 //....oooOO0OOooo........oooOO0OOooo........oo 274 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 212 275