Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // Code developed by: 27 // S.Larsson 28 // 29 // **************************************** 30 // * 31 // * PurgMagDetectorConstruction.cc 32 // * 33 // **************************************** 34 // 35 // 36 #include "PurgMagDetectorConstruction.hh" 37 #include "PurgMagTabulatedField3D.hh" 38 #include "globals.hh" 39 #include "G4PhysicalConstants.hh" 40 #include "G4SystemOfUnits.hh" 41 #include "G4ThreeVector.hh" 42 #include "G4Material.hh" 43 #include "G4Box.hh" 44 #include "G4Trd.hh" 45 #include "G4Tubs.hh" 46 #include "G4LogicalVolume.hh" 47 #include "G4PVPlacement.hh" 48 #include "G4PVReplica.hh" 49 #include "G4PVParameterised.hh" 50 #include "G4Mag_UsualEqRhs.hh" 51 #include "G4FieldManager.hh" 52 #include "G4TransportationManager.hh" 53 #include "G4EqMagElectricField.hh" 54 55 #include "G4ChordFinder.hh" 56 #include "G4UniformMagField.hh" 57 #include "G4ExplicitEuler.hh" 58 #include "G4ImplicitEuler.hh" 59 #include "G4SimpleRunge.hh" 60 #include "G4SimpleHeum.hh" 61 #include "G4ClassicalRK4.hh" 62 #include "G4HelixExplicitEuler.hh" 63 #include "G4HelixImplicitEuler.hh" 64 #include "G4HelixSimpleRunge.hh" 65 #include "G4CashKarpRKF45.hh" 66 #include "G4RKG3_Stepper.hh" 67 68 #include "G4VisAttributes.hh" 69 #include "G4Colour.hh" 70 #include "G4UnitsTable.hh" 71 #include "G4ios.hh" 72 73 //....oooOO0OOooo........oooOO0OOooo........oo 74 // Possibility to turn off (0) magnetic field 75 #define GAP 1 // Magnet geometric vol 76 #define MAG 1 // Magnetic field grid 77 #define MEASUREVOL 1 // Volume for measureme 78 79 //....oooOO0OOooo........oooOO0OOooo........oo 80 81 PurgMagDetectorConstruction::PurgMagDetectorCo 82 83 :physiWorld(NULL), logicWorld(NULL), solidWo 84 physiGap1(NULL), logicGap1(NULL), solidGap1 85 physiGap2(NULL), logicGap2(NULL), solidGap2 86 physiMeasureVolume(NULL), logicMeasureVolum 87 solidMeasureVolume(NULL), 88 WorldMaterial(NULL), 89 GapMaterial(NULL) 90 91 { 92 fField.Put(0); 93 WorldSizeXY=WorldSizeZ=0; 94 GapSizeX1=GapSizeX2=GapSizeY1=GapSizeY2=GapS 95 MeasureVolumeSizeXY=MeasureVolumeSizeZ=0; 96 } 97 98 //....oooOO0OOooo........oooOO0OOooo........oo 99 100 PurgMagDetectorConstruction::~PurgMagDetectorC 101 {} 102 103 //....oooOO0OOooo........oooOO0OOooo........oo 104 105 G4VPhysicalVolume* PurgMagDetectorConstruction 106 107 { 108 DefineMaterials(); 109 return ConstructCalorimeter(); 110 } 111 112 //....oooOO0OOooo........oooOO0OOooo........oo 113 114 void PurgMagDetectorConstruction::DefineMateri 115 { 116 //This function illustrates the possible way 117 //Density and mass per mole taken from Physi 118 //and engineering, sixth edition. This is a 119 //with extra materials for other examples. 120 121 G4String name, symbol; 122 G4double density; 123 124 G4int ncomponents, natoms; 125 G4double fractionmass; 126 G4double temperature, pressure; 127 128 // Define Elements 129 // Example: G4Element* Notation = new G4Ele 130 G4Element* H = new G4Element ("Hydrogen", 131 G4Element* N = new G4Element ("Nitrogen", 132 G4Element* O = new G4Element ("Oxygen" , 133 G4Element* Ar = new G4Element ("Argon" , " 134 135 136 // Define Material 137 // Example: G4Material* Notation = new G4Mat 138 /* Not used in this setup, will be used in f 139 G4Material* He = new G4Material("Helium", 2. 140 G4Material* Be = new G4Material("Beryllium", 141 G4Material* W = new G4Material("Tungsten", 142 G4Material* Cu = new G4Material("Copper", 29 143 */ 144 G4Material* Fe = new G4Material("Iron", 26., 145 146 // Define materials from elements. 147 148 // Case 1: chemical molecule 149 // Water 150 density = 1.000*g/cm3; 151 G4Material* H2O = new G4Material(name="H2O" 152 H2O->AddElement(H, natoms=2); 153 H2O->AddElement(O, natoms=1); 154 155 // Case 2: mixture by fractional mass. 156 // Air 157 density = 1.290*mg/cm3; 158 G4Material* Air = new G4Material(name="Air" 159 Air->AddElement(N, fractionmass=0.7); 160 Air->AddElement(O, fractionmass=0.3); 161 162 // Vacuum 163 density = 1.e-5*g/cm3; 164 pressure = 2.e-2*bar; 165 temperature = STP_Temperature; //fro 166 G4Material* vacuum = new G4Material(name="va 167 kStateGa 168 vacuum->AddMaterial(Air, fractionmass=1.); 169 170 171 // Laboratory vacuum: Dry air (average compo 172 density = 1.7836*mg/cm3 ; // STP 173 G4Material* Argon = new G4Material(name="Arg 174 Argon->AddElement(Ar, 1); 175 176 density = 1.25053*mg/cm3 ; // STP 177 G4Material* Nitrogen = new G4Material(name=" 178 Nitrogen->AddElement(N, 2); 179 180 density = 1.4289*mg/cm3 ; // STP 181 G4Material* Oxygen = new G4Material(name="O2 182 Oxygen->AddElement(O, 2); 183 184 185 density = 1.2928*mg/cm3 ; // STP 186 density *= 1.0e-8 ; // pumped v 187 188 temperature = STP_Temperature; 189 pressure = 1.0e-8*STP_Pressure; 190 191 G4Material* LaboratoryVacuum = new G4Materia 192 density,ncomponents=3, 193 kStateGas,temperature,pressure); 194 LaboratoryVacuum->AddMaterial( Nitrogen, fra 195 LaboratoryVacuum->AddMaterial( Oxygen, fra 196 LaboratoryVacuum->AddMaterial( Argon, fra 197 198 199 G4cout << G4endl << *(G4Material::GetMateria 200 201 202 // Default materials in setup. 203 WorldMaterial = LaboratoryVacuum; 204 GapMaterial = Fe; 205 206 207 G4cout << "end material"<< G4endl; 208 } 209 210 //....oooOO0OOooo........oooOO0OOooo........oo 211 G4VPhysicalVolume* PurgMagDetectorConstruction 212 { 213 // Complete the parameters definition 214 215 //The World 216 WorldSizeXY = 300.*cm; // Cube 217 WorldSizeZ = 300.*cm; 218 219 //Measurement volume 220 MeasureVolumeSizeXY = 280.*cm; // Cubic sli 221 MeasureVolumeSizeZ = 1.*cm; 222 223 // Position of measurement volume. 224 // SSD is Source to Surface Distance. Source 225 // below in the z-direction (symbolizin a pa 226 227 SSD = 50.*cm; 228 MeasureVolumePosition = -(SSD + MeasureVolum 229 230 231 // Geometric definition of the gap of the pu 232 // the shape of the pole gap. 233 234 GapSizeY1 = 10.*cm; // length along x at 235 GapSizeY2 = 10.*cm; // length along x at 236 GapSizeX1 = 10.*cm; // length along y at 237 GapSizeX2 = 18.37*cm; // length along y at 238 GapSizeZ = 11.5*cm; // length along z axi 239 240 Gap1PosY = 0.*cm; 241 Gap1PosX = -9.55*cm; 242 Gap1PosZ = -6.89*cm; 243 244 Gap2PosY = 0.*cm; 245 Gap2PosX = 9.55*cm; 246 Gap2PosZ = -6.89*cm; 247 248 249 // Coordinate correction for field grif. 250 // Gap opening at z = -11.4 mm. 251 // In field grid coordonates gap at z = -0.0 252 // z = 0.087m. 253 // -> zOffset = -11.4-(-7) = 4.4 mm 254 255 zOffset = 4.4*mm; 256 257 //....oooOO0OOooo........oooOO0OOooo........oo 258 // 259 //....oooOO0OOooo........oooOO0OOooo........oo 260 261 // Some out prints of the setup. 262 263 G4cout << "\n------------------------------- 264 << "\n Geometry and materials" 265 << "\n------------------------------------- 266 << "\n ---> World:" 267 << "\n ---> " << WorldMaterial->GetName() < 268 << "\n ---> " << "WorldSizeXY: " << G4BestU 269 << "\n ---> " << "WorldSizeZ: " << G4BestUn 270 271 #if GAP 272 G4cout << "\n------------------------------- 273 << "\n ---> Purging Magnet:" 274 << "\n ---> " << "Gap made of "<< GapMateri 275 << "\n ---> " << "GapSizeY1: " << G4BestUni 276 << "\n ---> " << "GapSizeY2: " << G4BestUni 277 << "\n ---> " << "GapSizeX1: " << G4BestUni 278 << "\n ---> " << "GapSizeX2: " << G4BestUni 279 #endif 280 281 #if MEASUREVOL 282 G4cout << "\n------------------------------- 283 << "\n ---> Measurement Volume:" 284 << "\n ---> " << WorldMaterial->GetName() < 285 << "\n ---> " << "MeasureVolumeXY: " << G4B 286 << "\n ---> " << "MeasureVolumeZ: " << G4Be 287 << "\n ---> " << "At SSD = " << G4BestUnit 288 #endif 289 290 G4cout << "\n------------------------------- 291 292 293 //....oooOO0OOooo........oooOO0OOooo........oo 294 // 295 // World 296 // 297 298 299 solidWorld = new G4Box("World", 300 WorldSizeXY/2,WorldSizeXY/2,WorldSize 301 302 303 logicWorld = new G4LogicalVolume(solidWorld, 304 WorldMaterial, //its material 305 "World"); //its name 306 307 physiWorld = new G4PVPlacement(0, //no r 308 G4ThreeVector(), //at (0,0,0) 309 "World", // 310 logicWorld, 311 NULL, // 312 false, // 313 0); //co 314 315 // Visualization attributes 316 G4VisAttributes* simpleWorldVisAtt= new G4Vi 317 simpleWorldVisAtt->SetVisibility(true); 318 logicWorld->SetVisAttributes(simpleWorldVisA 319 320 321 //....oooOO0OOooo........oooOO0OOooo........oo 322 // 323 // Measurement Volume 324 // 325 326 #if MEASUREVOL 327 328 solidMeasureVolume = new G4Box("MeasureVolum 329 MeasureVolumeSizeXY/2,Measu 330 331 logicMeasureVolume = new G4LogicalVolume(sol 332 WorldMateri 333 "MeasureVol 334 335 physiMeasureVolume = new G4PVPlacement(0, 336 G4ThreeVector(0.,0.,MeasureVolumePo 337 "MeasureVolum 338 logicMeasureV 339 physiWorld, 340 false, 341 0); 342 343 // Visualization attributes 344 G4VisAttributes* simpleMeasureVolumeVisAtt= 345 simpleMeasureVolumeVisAtt->SetVisibility(tru 346 simpleMeasureVolumeVisAtt->SetForceSolid(tru 347 logicMeasureVolume->SetVisAttributes(simpleM 348 349 #endif 350 351 //....oooOO0OOooo........oooOO0OOooo........oo 352 // 353 //Gap cone. Opening 20 deg. Two separate tra 354 // 355 356 #if GAP 357 358 //Gap part 1, placed in negative x-direction 359 360 solidGap1 = new G4Trd("Gap1", 361 GapSizeX1/2, // Half-length along x at 362 GapSizeX2/2, // Half-length along x at 363 GapSizeY1/2, // Half-length along y at 364 GapSizeY2/2, // Half-length along y at 365 GapSizeZ/2 ); // Half-length along z axi 366 367 logicGap1 = new G4LogicalVolume(solidGap1, 368 GapMaterial, //its material 369 "Gap1"); //its name 370 371 physiGap1 = new G4PVPlacement(0, 372 G4ThreeVector(Gap1PosX,Gap1PosY,Gap1Po 373 "Gap1", //its na 374 logicGap1, //it 375 physiWorld, //it 376 false, //no b 377 0); //copy num 378 379 //Gap part 2, placed in positive x-direction 380 381 solidGap2 = new G4Trd("Gap2", 382 GapSizeX1/2, // Half-length 383 GapSizeX2/2, // Half-length along 384 GapSizeY1/2, // Half-length 385 GapSizeY2/2, // Half-length along y at 386 GapSizeZ/2 ); // Half-length 387 388 logicGap2 = new G4LogicalVolume(solidGap2, 389 GapMaterial, //its material 390 "Gap2"); //its name 391 392 physiGap2 = new G4PVPlacement(0, 393 G4ThreeVector(Gap2PosX,Gap2PosY,Gap2Po 394 "Gap2", //its 395 logicGap2, //its 396 physiWorld, //its 397 false, //no boo 398 0); //copy numbe 399 400 // Visualization attributes 401 G4VisAttributes* simpleGap1VisAtt= new G4Vis 402 simpleGap1VisAtt->SetVisibility(true); 403 simpleGap1VisAtt->SetForceSolid(true); 404 logicGap1->SetVisAttributes(simpleGap1VisAtt 405 406 G4VisAttributes* simpleGap2VisAtt= new G4Vis 407 simpleGap2VisAtt->SetVisibility(true); 408 simpleGap2VisAtt->SetForceSolid(true); 409 logicGap2->SetVisAttributes(simpleGap2VisAtt 410 411 #endif 412 413 //....oooOO0OOooo........oooOO0OOooo........oo 414 415 return physiWorld; 416 } 417 //....oooOO0OOooo........oooOO0OOooo........oo 418 419 void PurgMagDetectorConstruction::ConstructSDa 420 { 421 // Magnetic Field - Purging magnet 422 // 423 #if MAG 424 425 if (fField.Get() == 0) 426 { 427 //Field grid in A9.TABLE. File must be i 428 G4MagneticField* PurgMagField= new PurgM 429 fField.Put(PurgMagField); 430 431 //This is thread-local 432 G4FieldManager* pFieldMgr = 433 G4TransportationManager::GetTransportationMa 434 435 G4cout<< "DeltaStep "<<pFieldMgr->GetDel 436 //G4ChordFinder *pChordFinder = new G4Ch 437 438 pFieldMgr->SetDetectorField(fField.Get() 439 pFieldMgr->CreateChordFinder(fField.Get( 440 441 } 442 #endif 443 } 444