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 electromagnetic/TestEm2/src/Detector << 26 // 27 /// \brief Implementation of the DetectorConst << 27 // $Id: DetectorConstruction.cc,v 1.14 2009/09/16 18:07:30 maire Exp $ 28 // << 28 // GEANT4 tag $Name: geant4-09-03-patch-02 $ >> 29 29 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 32 32 #include "DetectorConstruction.hh" 33 #include "DetectorConstruction.hh" 33 << 34 #include "DetectorMessenger.hh" 34 #include "DetectorMessenger.hh" 35 35 36 #include "G4AutoDelete.hh" << 36 #include "G4Tubs.hh" 37 #include "G4GeometryManager.hh" << 38 #include "G4GlobalMagFieldMessenger.hh" << 39 #include "G4LogicalVolume.hh" 37 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4NistManager.hh" << 42 #include "G4PVPlacement.hh" 38 #include "G4PVPlacement.hh" >> 39 #include "G4UniformMagField.hh" >> 40 >> 41 #include "G4GeometryManager.hh" 43 #include "G4PhysicalVolumeStore.hh" 42 #include "G4PhysicalVolumeStore.hh" 44 #include "G4RunManager.hh" << 43 #include "G4LogicalVolumeStore.hh" 45 #include "G4SolidStore.hh" 44 #include "G4SolidStore.hh" 46 #include "G4SystemOfUnits.hh" << 45 47 #include "G4Tubs.hh" << 46 #include "G4FieldManager.hh" >> 47 #include "G4TransportationManager.hh" >> 48 >> 49 #include "G4NistManager.hh" >> 50 #include "G4RunManager.hh" >> 51 48 #include "G4UnitsTable.hh" 52 #include "G4UnitsTable.hh" 49 53 50 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 55 52 DetectorConstruction::DetectorConstruction() 56 DetectorConstruction::DetectorConstruction() >> 57 :nLtot(40),nRtot(50),dLradl(0.5),dRradl(0.1), >> 58 dLlength(0.),dRlength(0.), >> 59 myMaterial(0),magField(0), >> 60 EcalLength(0.),EcalRadius(0.), >> 61 solidEcal(0),logicEcal(0),physiEcal(0) 53 { 62 { 54 DefineMaterials(); 63 DefineMaterials(); 55 SetMaterial("G4_PbWO4"); 64 SetMaterial("G4_PbWO4"); 56 fDetectorMessenger = new DetectorMessenger(t << 65 detectorMessenger = new DetectorMessenger(this); 57 } 66 } 58 67 59 //....oooOO0OOooo........oooOO0OOooo........oo 68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 60 69 61 DetectorConstruction::~DetectorConstruction() 70 DetectorConstruction::~DetectorConstruction() >> 71 { delete detectorMessenger;} >> 72 >> 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 74 >> 75 G4VPhysicalVolume* DetectorConstruction::Construct() 62 { 76 { 63 delete fDetectorMessenger; << 77 return ConstructVolumes(); 64 } 78 } 65 79 66 //....oooOO0OOooo........oooOO0OOooo........oo 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 67 81 68 void DetectorConstruction::DefineMaterials() 82 void DetectorConstruction::DefineMaterials() 69 { 83 { 70 // 84 // 71 // define few Elements by hand 85 // define few Elements by hand 72 // 86 // 73 G4double a, z; 87 G4double a, z; 74 << 88 75 G4Element* H = new G4Element("Hydrogen", "H" << 89 G4Element* H = new G4Element("Hydrogen", "H", z= 1., a= 1.01*g/mole); 76 G4Element* O = new G4Element("Oxygen", "O", << 90 G4Element* O = new G4Element("Oxygen" , "O", z= 8., a= 16.00*g/mole); 77 G4Element* Ge = new G4Element("Germanium", " << 91 G4Element* Ge = new G4Element("Germanium", "Ge",z=32., a= 72.59*g/mole); 78 G4Element* Bi = new G4Element("Bismuth", "Bi << 92 G4Element* Bi = new G4Element("Bismuth", "Bi",z=83., a= 208.98*g/mole); 79 93 80 // 94 // 81 // define materials 95 // define materials 82 // 96 // 83 G4double density; 97 G4double density; 84 G4int ncomponents, natoms; 98 G4int ncomponents, natoms; 85 99 86 // water with ionisation potential 78 eV << 100 // water with ionisation potential 75 eV 87 G4Material* H2O = new G4Material("Water", de << 101 G4Material* H2O = 88 H2O->AddElement(H, natoms = 2); << 102 new G4Material("Water", density= 1.00*g/cm3, ncomponents=2); 89 H2O->AddElement(O, natoms = 1); << 103 H2O->AddElement(H, natoms=2); 90 H2O->GetIonisation()->SetMeanExcitationEnerg << 104 H2O->AddElement(O, natoms=1); >> 105 H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV); 91 106 92 // pure materails 107 // pure materails 93 new G4Material("liquidArgon", z = 18., a = 3 << 108 new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3); 94 new G4Material("Aluminium", z = 13., a = 26. << 109 new G4Material("Aluminium", z=13., a= 26.98*g/mole, density= 2.7*g/cm3); 95 new G4Material("Iron", z = 26., a = 55.85 * << 110 new G4Material("Iron", z=26., a= 55.85*g/mole, density= 7.87*g/cm3); 96 new G4Material("Copper", z = 29., a = 63.55 << 111 new G4Material("Copper", z=29., a= 63.55*g/mole, density= 8.960*g/cm3); 97 new G4Material("Tungsten", z = 74., a = 183. << 112 new G4Material("Tungsten", z=74., a=183.84*g/mole, density=19.35*g/cm3); 98 new G4Material("Lead", z = 82., a = 207.19 * << 113 new G4Material("Lead", z=82., a=207.19*g/mole, density=11.35*g/cm3); 99 new G4Material("Uranium", z = 92., a = 238.0 << 114 new G4Material("Uranium" , z=92., a=238.03*g/mole, density= 18.95*g/cm3); 100 115 101 // compound material 116 // compound material 102 G4Material* BGO = new G4Material("BGO", dens << 117 G4Material* BGO = 103 BGO->AddElement(O, natoms = 12); << 118 new G4Material("BGO", density= 7.10*g/cm3, ncomponents=3); 104 BGO->AddElement(Ge, natoms = 3); << 119 BGO->AddElement(O , natoms=12); 105 BGO->AddElement(Bi, natoms = 4); << 120 BGO->AddElement(Ge, natoms= 3); >> 121 BGO->AddElement(Bi, natoms= 4); 106 122 107 ////G4cout << *(G4Material::GetMaterialTable << 123 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 108 } 124 } 109 125 110 //....oooOO0OOooo........oooOO0OOooo........oo 126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 111 127 112 void DetectorConstruction::UpdateParameters() << 128 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 113 { 129 { 114 G4double Radl = fMaterial->GetRadlen(); << 130 G4double Radl = myMaterial->GetRadlen(); 115 fDLlength = fDLradl * Radl; << 116 fDRlength = fDRradl * Radl; << 117 fEcalLength = fNLtot * fDLlength; << 118 fEcalRadius = fNRtot * fDRlength; << 119 if (fSolidEcal) { << 120 fSolidEcal->SetOuterRadius(fEcalRadius); << 121 fSolidEcal->SetZHalfLength(0.5 * fEcalLeng << 122 } << 123 } << 124 131 125 //....oooOO0OOooo........oooOO0OOooo........oo << 132 dLlength = dLradl*Radl; dRlength = dRradl*Radl; >> 133 EcalLength = nLtot*dLlength; EcalRadius = nRtot*dRlength; >> 134 >> 135 // Cleanup old geometry >> 136 G4GeometryManager::GetInstance()->OpenGeometry(); >> 137 G4PhysicalVolumeStore::GetInstance()->Clean(); >> 138 G4LogicalVolumeStore::GetInstance()->Clean(); >> 139 G4SolidStore::GetInstance()->Clean(); 126 140 127 G4VPhysicalVolume* DetectorConstruction::Const << 128 { << 129 UpdateParameters(); << 130 // 141 // 131 // Ecal 142 // Ecal 132 // 143 // 133 if (!fPhysiEcal) { << 144 solidEcal = new G4Tubs("Ecal",0.,EcalRadius,0.5*EcalLength,0.,360*deg); 134 fSolidEcal = new G4Tubs("Ecal", 0., fEcalR << 145 logicEcal = new G4LogicalVolume( solidEcal,myMaterial,"Ecal",0,0,0); 135 fLogicEcal = new G4LogicalVolume(fSolidEca << 146 physiEcal = new G4PVPlacement(0,G4ThreeVector(), 136 fPhysiEcal = new G4PVPlacement(0, G4ThreeV << 147 logicEcal,"Ecal",0,false,0); 137 } << 148 138 G4cout << "\n Absorber is " << G4BestUnit(fE << 149 G4cout << "Absorber is " << G4BestUnit(EcalLength,"Length") 139 << " R= " << fEcalRadius / cm << " c << 150 << " of " << myMaterial->GetName() << G4endl; 140 << G4endl; << 151 G4cout << myMaterial << G4endl; 141 G4cout << fMaterial << G4endl; << 152 142 // 153 // 143 // always return the physical World << 154 //always return the physical World 144 // 155 // 145 return fPhysiEcal; << 156 return physiEcal; 146 } 157 } 147 158 148 //....oooOO0OOooo........oooOO0OOooo........oo 159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 149 160 150 void DetectorConstruction::SetMaterial(const G 161 void DetectorConstruction::SetMaterial(const G4String& materialChoice) 151 { 162 { 152 // search the material by its name 163 // search the material by its name 153 G4Material* pttoMaterial = G4NistManager::In << 164 G4Material* pttoMaterial = >> 165 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 154 166 155 if (pttoMaterial && fMaterial != pttoMateria << 167 if (pttoMaterial) { 156 fMaterial = pttoMaterial; << 168 myMaterial = pttoMaterial; 157 if (fLogicEcal) { << 169 if(logicEcal) logicEcal->SetMaterial(myMaterial); 158 fLogicEcal->SetMaterial(fMaterial); << 159 } << 160 G4RunManager::GetRunManager()->PhysicsHasB 170 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 161 } 171 } 162 } 172 } 163 173 164 //....oooOO0OOooo........oooOO0OOooo........oo 174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 165 175 166 void DetectorConstruction::SetLBining(G4ThreeV 176 void DetectorConstruction::SetLBining(G4ThreeVector Value) 167 { 177 { 168 fNLtot = (G4int)Value(0); << 178 nLtot = (G4int)Value(0); 169 if (fNLtot > kMaxBin) { << 179 if (nLtot > MaxBin) { 170 G4cout << "\n ---> warning from SetLBining << 180 G4cout << "\n ---> warning from SetLBining: " 171 << G4endl; << 181 << nLtot << " truncated to " << MaxBin << G4endl; 172 fNLtot = kMaxBin; << 182 nLtot = MaxBin; 173 } << 183 } 174 fDLradl = Value(1); << 184 dLradl = Value(1); 175 UpdateParameters(); << 176 } 185 } 177 186 178 //....oooOO0OOooo........oooOO0OOooo........oo 187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 179 188 180 void DetectorConstruction::SetRBining(G4ThreeV 189 void DetectorConstruction::SetRBining(G4ThreeVector Value) 181 { 190 { 182 fNRtot = (G4int)Value(0); << 191 nRtot = (G4int)Value(0); 183 if (fNRtot > kMaxBin) { << 192 if (nRtot > MaxBin) { 184 G4cout << "\n ---> warning from SetRBining << 193 G4cout << "\n ---> warning from SetRBining: " 185 << G4endl; << 194 << nRtot << " truncated to " << MaxBin << G4endl; 186 fNRtot = kMaxBin; << 195 nRtot = MaxBin; 187 } << 196 } 188 fDRradl = Value(1); << 197 dRradl = Value(1); 189 UpdateParameters(); << 190 } 198 } 191 199 192 //....oooOO0OOooo........oooOO0OOooo........oo 200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 193 201 194 void DetectorConstruction::ConstructSDandField << 202 void DetectorConstruction::SetMagField(G4double fieldValue) 195 { 203 { 196 if (fFieldMessenger.Get() == nullptr) { << 204 //apply a global uniform magnetic field along Z axis 197 // Create global magnetic field messenger. << 205 G4FieldManager* fieldMgr 198 // Uniform magnetic field is then created << 206 = G4TransportationManager::GetTransportationManager()->GetFieldManager(); 199 // the field value is not zero. << 207 200 G4ThreeVector fieldValue = G4ThreeVector() << 208 if(magField) delete magField; //delete the existing magn field 201 G4GlobalMagFieldMessenger* msg = new G4Glo << 209 202 // msg->SetVerboseLevel(1); << 210 if(fieldValue!=0.) // create a new one if non nul 203 G4AutoDelete::Register(msg); << 211 { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue)); 204 fFieldMessenger.Put(msg); << 212 fieldMgr->SetDetectorField(magField); >> 213 fieldMgr->CreateChordFinder(magField); >> 214 } else { >> 215 magField = 0; >> 216 fieldMgr->SetDetectorField(magField); 205 } 217 } >> 218 } >> 219 >> 220 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 221 >> 222 void DetectorConstruction::UpdateGeometry() >> 223 { >> 224 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); 206 } 225 } 207 226 208 //....oooOO0OOooo........oooOO0OOooo........oo 227 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 209 228