Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 /// \file electromagnetic/TestEm2/src/Detector << 23 // 27 /// \brief Implementation of the DetectorConst << 24 // $Id: DetectorConstruction.cc,v 1.7 2004/06/18 15:43:41 maire Exp $ 28 // << 25 // GEANT4 tag $Name: geant4-08-00 $ >> 26 29 //....oooOO0OOooo........oooOO0OOooo........oo 27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 30 //....oooOO0OOooo........oooOO0OOooo........oo 28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 29 32 #include "DetectorConstruction.hh" 30 #include "DetectorConstruction.hh" 33 << 34 #include "DetectorMessenger.hh" 31 #include "DetectorMessenger.hh" 35 32 36 #include "G4AutoDelete.hh" << 33 #include "G4Tubs.hh" 37 #include "G4GeometryManager.hh" << 38 #include "G4GlobalMagFieldMessenger.hh" << 39 #include "G4LogicalVolume.hh" 34 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4NistManager.hh" << 42 #include "G4PVPlacement.hh" 35 #include "G4PVPlacement.hh" >> 36 #include "G4PVReplica.hh" >> 37 #include "G4UniformMagField.hh" >> 38 >> 39 #include "G4GeometryManager.hh" 43 #include "G4PhysicalVolumeStore.hh" 40 #include "G4PhysicalVolumeStore.hh" 44 #include "G4RunManager.hh" << 41 #include "G4LogicalVolumeStore.hh" 45 #include "G4SolidStore.hh" 42 #include "G4SolidStore.hh" 46 #include "G4SystemOfUnits.hh" << 43 47 #include "G4Tubs.hh" << 44 #include "G4VisAttributes.hh" 48 #include "G4UnitsTable.hh" 45 #include "G4UnitsTable.hh" 49 46 50 //....oooOO0OOooo........oooOO0OOooo........oo 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 48 52 DetectorConstruction::DetectorConstruction() 49 DetectorConstruction::DetectorConstruction() >> 50 :nLtot(20),nRtot(20),dLradl(1.),dRradl(0.25), >> 51 myMaterial(0),magField(0) , >> 52 EcalLength(0.),EcalRadius(0.) , >> 53 solidEcal(0) ,logicEcal(0) ,physiEcal(0), >> 54 solidSlice(0),logicSlice(0),physiSlice(0), >> 55 solidRing(0) ,logicRing(0) ,physiRing(0) 53 { 56 { 54 DefineMaterials(); 57 DefineMaterials(); 55 SetMaterial("G4_PbWO4"); << 58 SetMaterial("PbWO4"); 56 fDetectorMessenger = new DetectorMessenger(t << 59 detectorMessenger = new DetectorMessenger(this); 57 } 60 } 58 61 59 //....oooOO0OOooo........oooOO0OOooo........oo 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 60 63 61 DetectorConstruction::~DetectorConstruction() 64 DetectorConstruction::~DetectorConstruction() >> 65 { delete detectorMessenger;} >> 66 >> 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 68 >> 69 G4VPhysicalVolume* DetectorConstruction::Construct() 62 { 70 { 63 delete fDetectorMessenger; << 71 return ConstructVolumes(); 64 } 72 } 65 73 66 //....oooOO0OOooo........oooOO0OOooo........oo 74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 67 75 68 void DetectorConstruction::DefineMaterials() 76 void DetectorConstruction::DefineMaterials() 69 { 77 { 70 // 78 // 71 // define few Elements by hand << 79 // define few Elements 72 // 80 // 73 G4double a, z; 81 G4double a, z; 74 << 82 75 G4Element* H = new G4Element("Hydrogen", "H" << 83 G4Element* H = new G4Element("Hydrogen", "H", z= 1., a= 1.01*g/mole); 76 G4Element* O = new G4Element("Oxygen", "O", << 84 G4Element* N = new G4Element("Nitrogen", "N", z= 7., a= 14.01*g/mole); 77 G4Element* Ge = new G4Element("Germanium", " << 85 G4Element* O = new G4Element("Oxygen" , "O", z= 8., a= 16.00*g/mole); 78 G4Element* Bi = new G4Element("Bismuth", "Bi << 86 G4Element* Ge = new G4Element("Germanium", "Ge",z=32., a= 72.59*g/mole); >> 87 G4Element* W = new G4Element("Tungsten", "W", z=74., a= 183.84*g/mole); >> 88 G4Element* Pb = new G4Element("Lead", "Pb",z=82., a= 207.19*g/mole); >> 89 G4Element* Bi = new G4Element("Bismuth", "Bi",z=83., a= 208.98*g/mole); 79 90 80 // 91 // 81 // define materials 92 // define materials 82 // 93 // 83 G4double density; 94 G4double density; 84 G4int ncomponents, natoms; << 95 G4double fractionmass; G4int ncomponents, natoms; 85 96 86 // water with ionisation potential 78 eV << 97 G4Material* Air = 87 G4Material* H2O = new G4Material("Water", de << 98 new G4Material("Air", density= 1.29*mg/cm3, ncomponents=2); 88 H2O->AddElement(H, natoms = 2); << 99 Air->AddElement(N, fractionmass=0.7); 89 H2O->AddElement(O, natoms = 1); << 100 Air->AddElement(O, fractionmass=0.3); 90 H2O->GetIonisation()->SetMeanExcitationEnerg << 101 91 << 102 G4Material* H2O = 92 // pure materails << 103 new G4Material("Water", density= 1.00*g/cm3, ncomponents=2); 93 new G4Material("liquidArgon", z = 18., a = 3 << 104 H2O->AddElement(H, natoms=2); 94 new G4Material("Aluminium", z = 13., a = 26. << 105 H2O->AddElement(O, natoms=1); 95 new G4Material("Iron", z = 26., a = 55.85 * << 106 H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV); 96 new G4Material("Copper", z = 29., a = 63.55 << 107 97 new G4Material("Tungsten", z = 74., a = 183. << 108 new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3); 98 new G4Material("Lead", z = 82., a = 207.19 * << 109 99 new G4Material("Uranium", z = 92., a = 238.0 << 110 new G4Material("Aluminium", z=13., a= 26.98*g/mole, density= 2.7*g/cm3); 100 << 111 101 // compound material << 112 G4Material* Fe = 102 G4Material* BGO = new G4Material("BGO", dens << 113 new G4Material("Iron", z=26., a= 55.85*g/mole, density= 7.87*g/cm3); 103 BGO->AddElement(O, natoms = 12); << 114 G4Material* Ni = 104 BGO->AddElement(Ge, natoms = 3); << 115 new G4Material("Nickel", z=28., a= 58.69*g/mole, density= 8.96*g/cm3); 105 BGO->AddElement(Bi, natoms = 4); << 116 G4Material* Cu = 106 << 117 new G4Material("Copper", z=29., a= 63.54*g/mole, density= 8.96*g/cm3); 107 ////G4cout << *(G4Material::GetMaterialTable << 118 108 } << 119 G4Material* BGO = >> 120 new G4Material("BGO", density= 7.10*g/cm3, ncomponents=3); >> 121 BGO->AddElement(O , natoms=12); >> 122 BGO->AddElement(Ge, natoms= 3); >> 123 BGO->AddElement(Bi, natoms= 4); >> 124 >> 125 G4Material* PbWO = >> 126 new G4Material("PbWO4", density= 8.28*g/cm3, ncomponents=3); >> 127 PbWO->AddElement(O , natoms=4); >> 128 PbWO->AddElement(Pb, natoms=1); >> 129 PbWO->AddElement(W , natoms=1); >> 130 >> 131 G4Material* w = >> 132 new G4Material("Tungsten", density= 19.30*g/cm3, ncomponents=1); >> 133 w->AddElement(W, fractionmass=1.0); >> 134 >> 135 G4Material* ma1 = new G4Material("FCal2Slugs",density = 18.6*g/cm3, 3); >> 136 ma1->AddMaterial(w, fractionmass=0.97); >> 137 ma1->AddMaterial(Fe,fractionmass=0.01); >> 138 ma1->AddMaterial(Ni,fractionmass=0.02); >> 139 >> 140 G4Material* ma2 = new G4Material("FCal2Abs",density = 10.*g/cm3, 2); >> 141 ma2->AddMaterial(Cu, fractionmass=0.2); >> 142 ma2->AddMaterial(ma1,fractionmass=0.8); >> 143 >> 144 G4Material* pb = >> 145 new G4Material("Lead", density= 11.35*g/cm3, ncomponents=1); >> 146 pb->AddElement(Pb, fractionmass=1.0); 109 147 110 //....oooOO0OOooo........oooOO0OOooo........oo << 148 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 111 << 112 void DetectorConstruction::UpdateParameters() << 113 { << 114 G4double Radl = fMaterial->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 } 149 } 124 150 125 //....oooOO0OOooo........oooOO0OOooo........oo 151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 126 152 127 G4VPhysicalVolume* DetectorConstruction::Const << 153 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 128 { 154 { 129 UpdateParameters(); << 155 G4double Radl = myMaterial->GetRadlen(); >> 156 >> 157 G4double dL = dLradl*Radl, dR = dRradl*Radl; >> 158 EcalLength = nLtot*dL; EcalRadius = nRtot*dR; >> 159 >> 160 >> 161 // Cleanup old geometry >> 162 G4GeometryManager::GetInstance()->OpenGeometry(); >> 163 G4PhysicalVolumeStore::GetInstance()->Clean(); >> 164 G4LogicalVolumeStore::GetInstance()->Clean(); >> 165 G4SolidStore::GetInstance()->Clean(); >> 166 130 // 167 // 131 // Ecal 168 // Ecal 132 // 169 // 133 if (!fPhysiEcal) { << 170 solidEcal = new G4Tubs("Ecal",0.,EcalRadius,0.5*EcalLength,0.,360*deg); 134 fSolidEcal = new G4Tubs("Ecal", 0., fEcalR << 171 logicEcal = new G4LogicalVolume( solidEcal,myMaterial,"Ecal",0,0,0); 135 fLogicEcal = new G4LogicalVolume(fSolidEca << 172 physiEcal = new G4PVPlacement(0,G4ThreeVector(), 136 fPhysiEcal = new G4PVPlacement(0, G4ThreeV << 173 logicEcal,"Ecal",0,false,0); 137 } << 174 138 G4cout << "\n Absorber is " << G4BestUnit(fE << 175 // Ring 139 << " R= " << fEcalRadius / cm << " c << 176 // 140 << G4endl; << 177 for (G4int i=0; i<nRtot; i++) 141 G4cout << fMaterial << G4endl; << 178 { >> 179 solidRing = new G4Tubs("Ring",i*dR,(i+1)*dR,0.5*EcalLength,0.,360*deg); >> 180 logicRing = new G4LogicalVolume(solidRing,myMaterial,"Ring",0,0,0); >> 181 physiRing = new G4PVPlacement(0,G4ThreeVector(),logicRing,"Ring", >> 182 logicEcal,false,i); >> 183 >> 184 // Slice >> 185 solidSlice = new G4Tubs("Slice",i*dR,(i+1)*dR,0.5*dL,0.,360*deg); >> 186 logicSlice = new G4LogicalVolume(solidSlice,myMaterial,"Slice",0,0,0); >> 187 logicSlice-> SetVisAttributes(G4VisAttributes::Invisible); >> 188 if (nLtot >1) >> 189 physiSlice = new G4PVReplica("Slice",logicSlice,logicRing, >> 190 kZAxis,nLtot,dL); >> 191 else >> 192 physiSlice = new G4PVPlacement(0,G4ThreeVector(),logicSlice,"Slice", >> 193 logicRing,false,0); >> 194 } >> 195 >> 196 >> 197 G4cout << "Absorber is " << G4BestUnit(EcalLength,"Length") >> 198 << " of " << myMaterial->GetName() << G4endl; >> 199 G4cout << myMaterial << G4endl; >> 200 142 // 201 // 143 // always return the physical World << 202 //always return the physical World 144 // 203 // 145 return fPhysiEcal; << 204 return physiEcal; 146 } 205 } 147 206 148 //....oooOO0OOooo........oooOO0OOooo........oo 207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 149 208 150 void DetectorConstruction::SetMaterial(const G 209 void DetectorConstruction::SetMaterial(const G4String& materialChoice) 151 { 210 { 152 // search the material by its name 211 // search the material by its name 153 G4Material* pttoMaterial = G4NistManager::In << 212 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); 154 << 213 if (pttoMaterial) myMaterial = pttoMaterial; 155 if (pttoMaterial && fMaterial != pttoMateria << 156 fMaterial = pttoMaterial; << 157 if (fLogicEcal) { << 158 fLogicEcal->SetMaterial(fMaterial); << 159 } << 160 G4RunManager::GetRunManager()->PhysicsHasB << 161 } << 162 } 214 } 163 215 164 //....oooOO0OOooo........oooOO0OOooo........oo 216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 165 217 166 void DetectorConstruction::SetLBining(G4ThreeV 218 void DetectorConstruction::SetLBining(G4ThreeVector Value) 167 { 219 { 168 fNLtot = (G4int)Value(0); << 220 nLtot = (G4int)Value(0); 169 if (fNLtot > kMaxBin) { << 221 dLradl = Value(1); 170 G4cout << "\n ---> warning from SetLBining << 171 << G4endl; << 172 fNLtot = kMaxBin; << 173 } << 174 fDLradl = Value(1); << 175 UpdateParameters(); << 176 } 222 } 177 223 178 //....oooOO0OOooo........oooOO0OOooo........oo 224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 179 225 180 void DetectorConstruction::SetRBining(G4ThreeV 226 void DetectorConstruction::SetRBining(G4ThreeVector Value) 181 { 227 { 182 fNRtot = (G4int)Value(0); << 228 nRtot = (G4int)Value(0); 183 if (fNRtot > kMaxBin) { << 229 dRradl = Value(1); 184 G4cout << "\n ---> warning from SetRBining << 185 << G4endl; << 186 fNRtot = kMaxBin; << 187 } << 188 fDRradl = Value(1); << 189 UpdateParameters(); << 190 } 230 } 191 231 192 //....oooOO0OOooo........oooOO0OOooo........oo 232 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 193 233 194 void DetectorConstruction::ConstructSDandField << 234 #include "G4FieldManager.hh" >> 235 #include "G4TransportationManager.hh" >> 236 >> 237 void DetectorConstruction::SetMagField(G4double fieldValue) 195 { 238 { 196 if (fFieldMessenger.Get() == nullptr) { << 239 //apply a global uniform magnetic field along Z axis 197 // Create global magnetic field messenger. << 240 G4FieldManager* fieldMgr 198 // Uniform magnetic field is then created << 241 = G4TransportationManager::GetTransportationManager()->GetFieldManager(); 199 // the field value is not zero. << 242 200 G4ThreeVector fieldValue = G4ThreeVector() << 243 if(magField) delete magField; //delete the existing magn field 201 G4GlobalMagFieldMessenger* msg = new G4Glo << 244 202 // msg->SetVerboseLevel(1); << 245 if(fieldValue!=0.) // create a new one if non nul 203 G4AutoDelete::Register(msg); << 246 { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue)); 204 fFieldMessenger.Put(msg); << 247 fieldMgr->SetDetectorField(magField); >> 248 fieldMgr->CreateChordFinder(magField); >> 249 } else { >> 250 magField = 0; >> 251 fieldMgr->SetDetectorField(magField); 205 } 252 } >> 253 } >> 254 >> 255 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 256 >> 257 #include "G4RunManager.hh" >> 258 >> 259 void DetectorConstruction::UpdateGeometry() >> 260 { >> 261 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); 206 } 262 } 207 263 208 //....oooOO0OOooo........oooOO0OOooo........oo 264 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 209 265