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 DetectorConstruction.cc << 26 /// \file analysis/shared/src/DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConst 27 /// \brief Implementation of the DetectorConstruction class >> 28 // >> 29 // >> 30 // $Id: DetectorConstruction.cc 77206 2013-11-22 01:33:52Z adotti $ >> 31 // >> 32 // 28 33 29 //....oooOO0OOooo........oooOO0OOooo........oo 34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 30 //....oooOO0OOooo........oooOO0OOooo........oo 35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 36 32 #include "DetectorConstruction.hh" 37 #include "DetectorConstruction.hh" 33 << 34 #include "DetectorMessenger.hh" 38 #include "DetectorMessenger.hh" 35 39 36 #include "G4Box.hh" << 37 #include "G4Colour.hh" << 38 #include "G4GeometryManager.hh" << 39 #include "G4LogicalVolume.hh" << 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4Material.hh" 40 #include "G4Material.hh" 42 #include "G4NistManager.hh" 41 #include "G4NistManager.hh" >> 42 >> 43 #include "G4Box.hh" >> 44 #include "G4LogicalVolume.hh" 43 #include "G4PVPlacement.hh" 45 #include "G4PVPlacement.hh" 44 #include "G4PVReplica.hh" 46 #include "G4PVReplica.hh" >> 47 >> 48 #include "G4GeometryManager.hh" 45 #include "G4PhysicalVolumeStore.hh" 49 #include "G4PhysicalVolumeStore.hh" 46 #include "G4RunManager.hh" << 50 #include "G4LogicalVolumeStore.hh" 47 #include "G4SolidStore.hh" 51 #include "G4SolidStore.hh" 48 #include "G4StateManager.hh" << 52 49 #include "G4SystemOfUnits.hh" << 50 #include "G4VisAttributes.hh" 53 #include "G4VisAttributes.hh" >> 54 #include "G4Colour.hh" >> 55 #include "G4SystemOfUnits.hh" >> 56 #include "G4RunManager.hh" 51 57 52 //....oooOO0OOooo........oooOO0OOooo........oo 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 59 54 DetectorConstruction::DetectorConstruction() 60 DetectorConstruction::DetectorConstruction() 55 { << 61 :G4VUserDetectorConstruction(), >> 62 fAbsorberMaterial(0),fGapMaterial(0),fDefaultMaterial(0), >> 63 fSolidWorld(0),fLogicWorld(0),fPhysiWorld(0), >> 64 fSolidCalor(0),fLogicCalor(0),fPhysiCalor(0), >> 65 fSolidLayer(0),fLogicLayer(0),fPhysiLayer(0), >> 66 fSolidAbsorber(0),fLogicAbsorber(0),fPhysiAbsorber(0), >> 67 fSolidGap (0),fLogicGap (0),fPhysiGap (0), >> 68 fDetectorMessenger(0) >> 69 { >> 70 // default parameter values of the calorimeter >> 71 fAbsorberThickness = 10.*mm; >> 72 fGapThickness = 5.*mm; >> 73 fNbOfLayers = 10; >> 74 fCalorSizeYZ = 10.*cm; 56 ComputeCalorParameters(); 75 ComputeCalorParameters(); 57 << 76 58 // materials 77 // materials 59 DefineMaterials(); 78 DefineMaterials(); 60 SetAbsorberMaterial("G4_Pb"); 79 SetAbsorberMaterial("G4_Pb"); 61 SetGapMaterial("G4_lAr"); 80 SetGapMaterial("G4_lAr"); 62 << 81 63 // create commands for interactive definitio 82 // create commands for interactive definition of the calorimeter 64 fDetectorMessenger = new DetectorMessenger(t 83 fDetectorMessenger = new DetectorMessenger(this); 65 } 84 } 66 85 67 //....oooOO0OOooo........oooOO0OOooo........oo 86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 68 87 69 DetectorConstruction::~DetectorConstruction() 88 DetectorConstruction::~DetectorConstruction() 70 { << 89 { delete fDetectorMessenger;} 71 delete fDetectorMessenger; << 72 } << 73 90 74 //....oooOO0OOooo........oooOO0OOooo........oo 91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 75 92 76 G4VPhysicalVolume* DetectorConstruction::Const 93 G4VPhysicalVolume* DetectorConstruction::Construct() 77 { 94 { 78 return ConstructCalorimeter(); 95 return ConstructCalorimeter(); 79 } 96 } 80 97 81 //....oooOO0OOooo........oooOO0OOooo........oo 98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 82 99 83 void DetectorConstruction::DefineMaterials() 100 void DetectorConstruction::DefineMaterials() 84 { << 101 { 85 // use G4-NIST materials data base << 102 // use G4-NIST materials data base 86 // << 103 // 87 G4NistManager* man = G4NistManager::Instance << 104 G4NistManager* man = G4NistManager::Instance(); 88 fDefaultMaterial = man->FindOrBuildMaterial( << 105 fDefaultMaterial = man->FindOrBuildMaterial("G4_Galactic"); 89 man->FindOrBuildMaterial("G4_Pb"); << 106 man->FindOrBuildMaterial("G4_Pb"); 90 man->FindOrBuildMaterial("G4_lAr"); << 107 man->FindOrBuildMaterial("G4_lAr"); 91 << 108 92 // print table << 109 // print table 93 // << 110 // 94 G4cout << *(G4Material::GetMaterialTable()) << 111 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 95 } 112 } 96 113 97 //....oooOO0OOooo........oooOO0OOooo........oo 114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 98 115 99 G4VPhysicalVolume* DetectorConstruction::Const 116 G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter() 100 { 117 { >> 118 101 // Clean old geometry, if any 119 // Clean old geometry, if any 102 // 120 // 103 G4GeometryManager::GetInstance()->OpenGeomet 121 G4GeometryManager::GetInstance()->OpenGeometry(); 104 G4PhysicalVolumeStore::GetInstance()->Clean( 122 G4PhysicalVolumeStore::GetInstance()->Clean(); 105 G4LogicalVolumeStore::GetInstance()->Clean() 123 G4LogicalVolumeStore::GetInstance()->Clean(); 106 G4SolidStore::GetInstance()->Clean(); 124 G4SolidStore::GetInstance()->Clean(); 107 125 108 // complete the Calor parameters definition 126 // complete the Calor parameters definition 109 ComputeCalorParameters(); 127 ComputeCalorParameters(); 110 << 128 111 // << 129 // 112 // World 130 // World 113 // 131 // 114 fSolidWorld = new G4Box("World", // its nam << 132 fSolidWorld = new G4Box("World", //its name 115 fWorldSizeX / 2, fWo << 133 fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //its size 116 << 134 117 fLogicWorld = new G4LogicalVolume(fSolidWorl << 135 fLogicWorld = new G4LogicalVolume(fSolidWorld, //its solid 118 fDefaultMa << 136 fDefaultMaterial, //its material 119 "World"); << 137 "World"); //its name 120 << 138 121 fPhysiWorld = new G4PVPlacement(nullptr, // << 139 fPhysiWorld = new G4PVPlacement(0, //no rotation 122 G4ThreeVecto << 140 G4ThreeVector(), //at (0,0,0) 123 fLogicWorld, << 141 fLogicWorld, //its logical volume 124 "World", // << 142 "World", //its name 125 nullptr, // << 143 0, //its mother volume 126 false, // n << 144 false, //no boolean operation 127 0); // copy << 145 0); //copy number 128 << 146 129 // << 147 // 130 // Calorimeter 148 // Calorimeter 131 // << 149 // 132 fSolidCalor = nullptr; << 150 fSolidCalor=0; fLogicCalor=0; fPhysiCalor=0; 133 fLogicCalor = nullptr; << 151 fSolidLayer=0; fLogicLayer=0; fPhysiLayer=0; 134 fPhysiCalor = nullptr; << 152 135 fSolidLayer = nullptr; << 153 if (fCalorThickness > 0.) 136 fLogicLayer = nullptr; << 154 { fSolidCalor = new G4Box("Calorimeter", //its name 137 fPhysiLayer = nullptr; << 155 fCalorThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2);//size 138 << 156 139 if (fCalorThickness > 0.) { << 157 fLogicCalor = new G4LogicalVolume(fSolidCalor, //its solid 140 fSolidCalor = new G4Box("Calorimeter", // << 158 fDefaultMaterial, //its material 141 fCalorThickness / << 159 "Calorimeter"); //its name 142 << 160 143 fLogicCalor = new G4LogicalVolume(fSolidCa << 161 fPhysiCalor = new G4PVPlacement(0, //no rotation 144 fDefault << 162 G4ThreeVector(), //at (0,0,0) 145 "Calorim << 163 fLogicCalor, //its logical volume 146 << 164 "Calorimeter", //its name 147 fPhysiCalor = new G4PVPlacement(nullptr, << 165 fLogicWorld, //its mother volume 148 G4ThreeVec << 166 false, //no boolean operation 149 fLogicCalo << 167 0); //copy number 150 "Calorimet << 168 151 fLogicWorl << 169 // 152 false, // << 170 // Layer 153 0); // co << 171 // 154 << 172 fSolidLayer = new G4Box("Layer", //its name 155 // << 173 fLayerThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2); //size 156 // Layer << 174 157 // << 175 fLogicLayer = new G4LogicalVolume(fSolidLayer, //its solid 158 fSolidLayer = new G4Box("Layer", // its n << 176 fDefaultMaterial, //its material 159 fLayerThickness / << 177 "Layer"); //its name 160 << 178 if (fNbOfLayers > 1) 161 fLogicLayer = new G4LogicalVolume(fSolidLa << 179 fPhysiLayer = new G4PVReplica("Layer", //its name 162 fDefault << 180 fLogicLayer, //its logical volume 163 "Layer") << 181 fLogicCalor, //its mother 164 if (fNbOfLayers > 1) { << 182 kXAxis, //axis of replication 165 fPhysiLayer = new G4PVReplica("Layer", << 183 fNbOfLayers, //number of replica 166 fLogicLaye << 184 fLayerThickness); //witdth of replica 167 fLogicCalo << 185 else 168 kXAxis, / << 186 fPhysiLayer = new G4PVPlacement(0, //no rotation 169 fNbOfLayer << 187 G4ThreeVector(), //at (0,0,0) 170 fLayerThic << 188 fLogicLayer, //its logical volume 171 } << 189 "Layer", //its name 172 else { << 190 fLogicCalor, //its mother volume 173 fPhysiLayer = new G4PVPlacement(nullptr, << 191 false, //no boolean operation 174 G4ThreeV << 192 0); //copy number 175 fLogicLa << 193 } 176 "Layer", << 194 177 fLogicCa << 195 // 178 false, << 179 0); // << 180 } << 181 } << 182 << 183 // << 184 // Absorber 196 // Absorber 185 // 197 // 186 fSolidAbsorber = nullptr; << 198 fSolidAbsorber=0; fLogicAbsorber=0; fPhysiAbsorber=0; 187 fLogicAbsorber = nullptr; << 199 188 fPhysiAbsorber = nullptr; << 200 if (fAbsorberThickness > 0.) 189 << 201 { fSolidAbsorber = new G4Box("Absorber", //its name 190 if (fAbsorberThickness > 0.) { << 202 fAbsorberThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2); 191 fSolidAbsorber = new G4Box("Absorber", // << 203 192 fAbsorberThickn << 204 fLogicAbsorber = new G4LogicalVolume(fSolidAbsorber, //its solid 193 << 205 fAbsorberMaterial, //its material 194 fLogicAbsorber = new G4LogicalVolume(fSoli << 206 fAbsorberMaterial->GetName());//name 195 fAbso << 207 196 fAbso << 208 fPhysiAbsorber = new G4PVPlacement(0, //no rotation 197 << 209 G4ThreeVector(-fGapThickness/2,0.,0.), //its position 198 fPhysiAbsorber = new G4PVPlacement(nullptr << 210 fLogicAbsorber, //its logical volume 199 G4Three << 211 fAbsorberMaterial->GetName(), //its name 200 fLogicA << 212 fLogicLayer, //its mother 201 fAbsorb << 213 false, //no boulean operat 202 fLogicL << 214 0); //copy number 203 false, << 215 204 0); // << 216 } 205 } << 217 206 << 218 // 207 // << 208 // Gap 219 // Gap 209 // 220 // 210 fSolidGap = nullptr; << 221 fSolidGap=0; fLogicGap=0; fPhysiGap=0; 211 fLogicGap = nullptr; << 222 212 fPhysiGap = nullptr; << 223 if (fGapThickness > 0.) 213 << 224 { fSolidGap = new G4Box("Gap", 214 if (fGapThickness > 0.) { << 225 fGapThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2); 215 fSolidGap = new G4Box("Gap", fGapThickness << 226 216 << 227 fLogicGap = new G4LogicalVolume(fSolidGap, 217 fLogicGap = new G4LogicalVolume(fSolidGap, << 228 fGapMaterial, 218 << 229 fGapMaterial->GetName()); 219 fPhysiGap = new G4PVPlacement(nullptr, // << 230 220 G4ThreeVecto << 231 fPhysiGap = new G4PVPlacement(0, //no rotation 221 fLogicGap, << 232 G4ThreeVector(fAbsorberThickness/2,0.,0.), //its position 222 fGapMaterial << 233 fLogicGap, //its logical volume 223 fLogicLayer, << 234 fGapMaterial->GetName(), //its name 224 false, // n << 235 fLogicLayer, //its mother 225 0); // copy << 236 false, //no boulean operat 226 } << 237 0); //copy number 227 << 238 } 228 PrintCalorParameters(); << 239 229 << 240 PrintCalorParameters(); 230 // << 241 >> 242 // 231 // Visualization attributes 243 // Visualization attributes 232 // 244 // 233 fLogicWorld->SetVisAttributes(G4VisAttribute << 245 fLogicWorld->SetVisAttributes (G4VisAttributes::Invisible); 234 246 235 auto simpleBoxVisAtt = new G4VisAttributes(G << 247 G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0)); 236 simpleBoxVisAtt->SetVisibility(true); 248 simpleBoxVisAtt->SetVisibility(true); 237 fLogicCalor->SetVisAttributes(simpleBoxVisAt 249 fLogicCalor->SetVisAttributes(simpleBoxVisAtt); 238 250 239 // 251 // 240 // always return the physical World << 252 //always return the physical World 241 // 253 // 242 return fPhysiWorld; 254 return fPhysiWorld; 243 } 255 } 244 256 245 //....oooOO0OOooo........oooOO0OOooo........oo 257 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 246 258 247 void DetectorConstruction::PrintCalorParameter 259 void DetectorConstruction::PrintCalorParameters() 248 { 260 { 249 G4cout << "\n------------------------------- 261 G4cout << "\n------------------------------------------------------------" 250 << "\n---> The calorimeter is " << fN 262 << "\n---> The calorimeter is " << fNbOfLayers << " layers of: [ " 251 << fAbsorberThickness / mm << "mm of << 263 << fAbsorberThickness/mm << "mm of " << fAbsorberMaterial->GetName() 252 << fGapThickness / mm << "mm of " << << 264 << " + " >> 265 << fGapThickness/mm << "mm of " << fGapMaterial->GetName() << " ] " 253 << "\n------------------------------- 266 << "\n------------------------------------------------------------\n"; 254 } 267 } 255 268 256 //....oooOO0OOooo........oooOO0OOooo........oo 269 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 257 270 258 void DetectorConstruction::SetAbsorberMaterial << 271 void DetectorConstruction::SetAbsorberMaterial(G4String materialChoice) 259 { 272 { 260 // search the material by its name << 273 // search the material by its name 261 auto material = G4NistManager::Instance()->F << 274 G4Material* pttoMaterial = 262 if (material != nullptr) { << 275 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 263 fAbsorberMaterial = material; << 276 if (pttoMaterial) 264 if (fLogicAbsorber != nullptr) { << 277 { 265 fLogicAbsorber->SetMaterial(fAbsorberMat << 278 fAbsorberMaterial = pttoMaterial; 266 G4RunManager::GetRunManager()->PhysicsHa << 279 if ( fLogicAbsorber ) 267 } << 280 { >> 281 fLogicAbsorber->SetMaterial(fAbsorberMaterial); >> 282 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); >> 283 } 268 } 284 } 269 } 285 } 270 286 271 //....oooOO0OOooo........oooOO0OOooo........oo 287 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 272 288 273 void DetectorConstruction::SetGapMaterial(cons << 289 void DetectorConstruction::SetGapMaterial(G4String materialChoice) 274 { 290 { 275 auto material = G4NistManager::Instance()->F << 291 // search the material by its name 276 if (material != nullptr) { << 292 G4Material* pttoMaterial = 277 fGapMaterial = material; << 293 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 278 if (fLogicGap != nullptr) { << 294 if (pttoMaterial) 279 fLogicGap->SetMaterial(fGapMaterial); << 295 { 280 G4RunManager::GetRunManager()->PhysicsHa << 296 fGapMaterial = pttoMaterial; 281 } << 297 if ( fLogicGap ) >> 298 { >> 299 fLogicGap->SetMaterial(fGapMaterial); >> 300 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); >> 301 } 282 } 302 } 283 } 303 } 284 304 285 //....oooOO0OOooo........oooOO0OOooo........oo 305 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 286 306 287 void DetectorConstruction::SetAbsorberThicknes << 307 void DetectorConstruction::SetAbsorberThickness(G4double val) 288 { 308 { 289 // change Absorber thickness and recompute t 309 // change Absorber thickness and recompute the calorimeter parameters 290 fAbsorberThickness = value; << 310 fAbsorberThickness = val; 291 if (G4StateManager::GetStateManager()->GetCu << 311 G4RunManager::GetRunManager()->ReinitializeGeometry(); 292 G4RunManager::GetRunManager()->Reinitializ << 293 } << 294 } 312 } 295 313 296 //....oooOO0OOooo........oooOO0OOooo........oo 314 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 297 315 298 void DetectorConstruction::SetGapThickness(G4d << 316 void DetectorConstruction::SetGapThickness(G4double val) 299 { 317 { 300 // change Gap thickness and recompute the ca 318 // change Gap thickness and recompute the calorimeter parameters 301 fGapThickness = value; << 319 fGapThickness = val; 302 if (G4StateManager::GetStateManager()->GetCu << 320 G4RunManager::GetRunManager()->ReinitializeGeometry(); 303 G4RunManager::GetRunManager()->Reinitializ << 304 } << 305 } 321 } 306 322 307 //....oooOO0OOooo........oooOO0OOooo........oo 323 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 308 324 309 void DetectorConstruction::SetCalorSizeYZ(G4do << 325 void DetectorConstruction::SetCalorSizeYZ(G4double val) 310 { 326 { 311 // change the transverse size and recompute 327 // change the transverse size and recompute the calorimeter parameters 312 fCalorSizeYZ = value; << 328 fCalorSizeYZ = val; 313 if (G4StateManager::GetStateManager()->GetCu << 329 G4RunManager::GetRunManager()->ReinitializeGeometry(); 314 G4RunManager::GetRunManager()->Reinitializ << 315 } << 316 } 330 } 317 331 318 //....oooOO0OOooo........oooOO0OOooo........oo 332 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 319 333 320 void DetectorConstruction::SetNbOfLayers(G4int << 334 void DetectorConstruction::SetNbOfLayers(G4int val) 321 { 335 { 322 fNbOfLayers = value; << 336 fNbOfLayers = val; 323 if (G4StateManager::GetStateManager()->GetCu << 337 G4RunManager::GetRunManager()->ReinitializeGeometry(); 324 G4RunManager::GetRunManager()->Reinitializ << 325 } << 326 } 338 } 327 339 328 //....oooOO0OOooo........oooOO0OOooo........oo 340 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 329 341