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 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/electromagnetic/TestEm7/src/DetectorConstruction.cc (Version 11.3.0) and /examples/extended/electromagnetic/TestEm7/src/DetectorConstruction.cc (Version 6.2.p1)


  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 /// \file electromagnetic/TestEm7/src/Detector    
 27 /// \brief Implementation of the DetectorConst    
 28 //                                                
 29 //                                                
 30 //....oooOO0OOooo........oooOO0OOooo........oo    
 31 //....oooOO0OOooo........oooOO0OOooo........oo    
 32                                                   
 33 #include "DetectorConstruction.hh"                
 34                                                   
 35 #include "DetectorMessenger.hh"                   
 36                                                   
 37 #include "G4Box.hh"                               
 38 #include "G4FieldManager.hh"                      
 39 #include "G4GeometryManager.hh"                   
 40 #include "G4LogicalVolume.hh"                     
 41 #include "G4LogicalVolumeStore.hh"                
 42 #include "G4Material.hh"                          
 43 #include "G4NistManager.hh"                       
 44 #include "G4PVPlacement.hh"                       
 45 #include "G4PhysicalConstants.hh"                 
 46 #include "G4PhysicalVolumeStore.hh"               
 47 #include "G4RunManager.hh"                        
 48 #include "G4SolidStore.hh"                        
 49 #include "G4SystemOfUnits.hh"                     
 50 #include "G4TransportationManager.hh"             
 51 #include "G4UniformMagField.hh"                   
 52 #include "G4UnitsTable.hh"                        
 53                                                   
 54 //....oooOO0OOooo........oooOO0OOooo........oo    
 55                                                   
 56 DetectorConstruction::DetectorConstruction()      
 57   : G4VUserDetectorConstruction(), fMagField(n    
 58 {                                                 
 59   // default parameter values                     
 60   fAbsorSizeX = fAbsorSizeYZ = 20 * cm;           
 61   fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSiz    
 62                                                   
 63   fTallyNumber = 0;                               
 64   for (G4int j = 0; j < kMaxTally; j++) {         
 65     fTallySize[j] = fTallyPosition[j] = G4Thre    
 66     fTallyMass[j] = 0.;                           
 67     fLTally[j] = nullptr;                         
 68   }                                               
 69                                                   
 70   DefineMaterials();                              
 71                                                   
 72   // create commands for interactive definitio    
 73   fDetectorMessenger = new DetectorMessenger(t    
 74 }                                                 
 75                                                   
 76 //....oooOO0OOooo........oooOO0OOooo........oo    
 77                                                   
 78 DetectorConstruction::~DetectorConstruction()     
 79 {                                                 
 80   delete fDetectorMessenger;                      
 81 }                                                 
 82                                                   
 83 //....oooOO0OOooo........oooOO0OOooo........oo    
 84                                                   
 85 void DetectorConstruction::DefineMaterials()      
 86 {                                                 
 87   //                                              
 88   // define Elements                              
 89   //                                              
 90   G4double z, a;                                  
 91                                                   
 92   G4Element* H = new G4Element("Hydrogen", "H"    
 93   G4Element* N = new G4Element("Nitrogen", "N"    
 94   G4Element* O = new G4Element("Oxygen", "O",     
 95                                                   
 96   //                                              
 97   // define Materials.                            
 98   //                                              
 99   G4double density, temperature, pressure;        
100   G4int ncomponents, natoms;                      
101   G4double fractionmass;                          
102                                                   
103   G4Material* H2O = new G4Material("Water", de    
104   H2O->AddElement(H, natoms = 2);                 
105   H2O->AddElement(O, natoms = 1);                 
106   H2O->GetIonisation()->SetMeanExcitationEnerg    
107                                                   
108   // In this line both G4_WATER and Water_1.05    
109   G4NistManager::Instance()->BuildMaterialWith    
110                                                   
111   G4Material* Air = new G4Material("Air", dens    
112   Air->AddElement(N, fractionmass = 0.7);         
113   Air->AddElement(O, fractionmass = 0.3);         
114                                                   
115   density = 1.e-5 * g / cm3;                      
116   pressure = 2.e-2 * bar;                         
117   temperature = STP_Temperature;  // From Phys    
118   G4Material* vac = new G4Material("TechVacuum    
119   vac->AddMaterial(Air, 1.);                      
120                                                   
121   density = universe_mean_density;  // from Ph    
122   pressure = 3.e-18 * pascal;                     
123   temperature = 2.73 * kelvin;                    
124   G4Material* vacuum = new G4Material("Galacti    
125                                       temperat    
126                                                   
127   // default materials                            
128   fAbsorMaterial = H2O;                           
129   fWorldMaterial = vacuum;                        
130 }                                                 
131                                                   
132 //....oooOO0OOooo........oooOO0OOooo........oo    
133                                                   
134 G4VPhysicalVolume* DetectorConstruction::Const    
135 {                                                 
136   // World                                        
137   //                                              
138   G4Box* sWorld = new G4Box("World",  // name     
139                             fWorldSizeX / 2, f    
140                                                   
141   fLWorld = new G4LogicalVolume(sWorld,  // sh    
142                                 fWorldMaterial    
143                                 "World");  //     
144                                                   
145   G4VPhysicalVolume* pWorld = new G4PVPlacemen    
146                                                   
147                                                   
148                                                   
149                                                   
150                                                   
151                                                   
152   //                                              
153   // Absorber                                     
154   //                                              
155   G4Box* sAbsor = new G4Box("Absorber",  // na    
156                             fAbsorSizeX / 2, f    
157                                                   
158   fLAbsor = new G4LogicalVolume(sAbsor,  // sh    
159                                 fAbsorMaterial    
160                                 "Absorber");      
161                                                   
162   new G4PVPlacement(0,  // no rotation            
163                     G4ThreeVector(0., 0., 0.),    
164                     fLAbsor,  // logical volum    
165                     "Absorber",  // name          
166                     fLWorld,  // mother  volum    
167                     false,  // no boolean oper    
168                     0);  // copy number           
169   //                                              
170   // Tallies (optional)                           
171   //                                              
172   if (fTallyNumber > 0) {                         
173     for (G4int j = 0; j < fTallyNumber; ++j) {    
174       G4Box* sTally =                             
175         new G4Box("Tally", fTallySize[j].x() /    
176                                                   
177       fLTally[j] = new G4LogicalVolume(sTally,    
178                                                   
179       new G4PVPlacement(0,  // no rotation        
180                         fTallyPosition[j],  //    
181                         fLTally[j],  // logica    
182                         "Tally",  // name         
183                         fLAbsor,  // mother  v    
184                         false,  // no boolean     
185                         j + 1);  // copy numbe    
186                                                   
187       fTallyMass[j] =                             
188         fTallySize[j].x() * fTallySize[j].y()     
189     }                                             
190   }                                               
191                                                   
192   PrintParameters();                              
193                                                   
194   //                                              
195   // always return the World volume               
196   //                                              
197   return pWorld;                                  
198 }                                                 
199                                                   
200 //....oooOO0OOooo........oooOO0OOooo........oo    
201                                                   
202 void DetectorConstruction::PrintParameters() c    
203 {                                                 
204   G4cout << *(G4Material::GetMaterialTable())     
205   G4cout << "\n-------------------------------    
206   G4cout << "---> The Absorber is " << G4BestU    
207          << fAbsorMaterial->GetName() << G4end    
208   G4cout << "\n-------------------------------    
209                                                   
210   if (fTallyNumber > 0) {                         
211     G4cout << "---> There are " << fTallyNumbe    
212     for (G4int j = 0; j < fTallyNumber; ++j) {    
213       G4cout << "fTally " << j << ": " << fAbs    
214              << ",  mass = " << G4BestUnit(fTa    
215              << " size = " << G4BestUnit(fTall    
216              << " position = " << G4BestUnit(f    
217     }                                             
218     G4cout << "\n-----------------------------    
219   }                                               
220 }                                                 
221                                                   
222 //....oooOO0OOooo........oooOO0OOooo........oo    
223                                                   
224 void DetectorConstruction::SetSizeX(G4double v    
225 {                                                 
226   fAbsorSizeX = value;                            
227   fWorldSizeX = 1.2 * fAbsorSizeX;                
228 }                                                 
229                                                   
230 //....oooOO0OOooo........oooOO0OOooo........oo    
231                                                   
232 void DetectorConstruction::SetSizeYZ(G4double     
233 {                                                 
234   fAbsorSizeYZ = value;                           
235   fWorldSizeYZ = 1.2 * fAbsorSizeYZ;              
236 }                                                 
237                                                   
238 //....oooOO0OOooo........oooOO0OOooo........oo    
239                                                   
240 void DetectorConstruction::SetMaterial(const G    
241 {                                                 
242   // search the material by its name              
243   G4Material* pttoMaterial = G4NistManager::In    
244   if (pttoMaterial && pttoMaterial != fAbsorMa    
245     // change target material everywhere          
246     fAbsorMaterial = pttoMaterial;                
247     for (G4int j = 0; j < fTallyNumber; ++j) {    
248       if (fLTally[j]) {                           
249         fLTally[j]->SetMaterial(pttoMaterial);    
250         fTallyMass[j] =                           
251           fTallySize[j].x() * fTallySize[j].y(    
252       }                                           
253     }                                             
254     if (fLAbsor) {                                
255       fLAbsor->SetMaterial(fAbsorMaterial);       
256       G4RunManager::GetRunManager()->PhysicsHa    
257     }                                             
258   }                                               
259 }                                                 
260                                                   
261 //....oooOO0OOooo........oooOO0OOooo........oo    
262                                                   
263 void DetectorConstruction::SetWorldMaterial(co    
264 {                                                 
265   // search the material by its name              
266   G4Material* pttoMaterial = G4NistManager::In    
267   if (pttoMaterial && pttoMaterial != fWorldMa    
268     fWorldMaterial = pttoMaterial;                
269     if (fLWorld) {                                
270       fLWorld->SetMaterial(fAbsorMaterial);       
271       G4RunManager::GetRunManager()->PhysicsHa    
272     }                                             
273   }                                               
274 }                                                 
275                                                   
276 //....oooOO0OOooo........oooOO0OOooo........oo    
277                                                   
278 void DetectorConstruction::SetMagField(G4doubl    
279 {                                                 
280   // apply a global uniform magnetic field alo    
281   G4FieldManager* fieldMgr = G4TransportationM    
282                                                   
283   if (fMagField) delete fMagField;  // delete     
284                                                   
285   if (fieldValue != 0.)  // create a new one i    
286   {                                               
287     fMagField = new G4UniformMagField(G4ThreeV    
288     fieldMgr->SetDetectorField(fMagField);        
289     fieldMgr->CreateChordFinder(fMagField);       
290   }                                               
291   else {                                          
292     fMagField = nullptr;                          
293     fieldMgr->SetDetectorField(fMagField);        
294   }                                               
295 }                                                 
296 //....oooOO0OOooo........oooOO0OOooo........oo    
297                                                   
298 void DetectorConstruction::SetTallyNumber(G4in    
299 {                                                 
300   if (value >= 0 && value < kMaxTally) {          
301     fTallyNumber = value;                         
302   }                                               
303   else {                                          
304     G4cout << "### DetectorConstruction::SetTa    
305            << "number " << value << " is ignor    
306   }                                               
307 }                                                 
308                                                   
309 //....oooOO0OOooo........oooOO0OOooo........oo    
310                                                   
311 void DetectorConstruction::SetTallySize(G4int     
312 {                                                 
313   if (j >= 0 && j < kMaxTally) {                  
314     fTallySize[j] = value;                        
315   }                                               
316   else {                                          
317     G4cout << "### DetectorConstruction::SetTa    
318            << "number " << j << " is ignored"     
319   }                                               
320 }                                                 
321                                                   
322 //....oooOO0OOooo........oooOO0OOooo........oo    
323                                                   
324 void DetectorConstruction::SetTallyPosition(G4    
325 {                                                 
326   if (j >= 0 && j < kMaxTally) {                  
327     fTallyPosition[j] = value;                    
328   }                                               
329   else {                                          
330     G4cout << "### DetectorConstruction::SetTa    
331            << "number " << j << " is ignored"     
332   }                                               
333 }                                                 
334                                                   
335 G4double DetectorConstruction::GetTallyMass(G4    
336 {                                                 
337   if (j >= 0 && j < kMaxTally) {                  
338     return fTallyMass[j];                         
339   }                                               
340   else {                                          
341     G4cout << "### DetectorConstruction::GetTa    
342            << "number " << j << " is ignored"     
343     return 0.0;                                   
344   }                                               
345 }                                                 
346                                                   
347 const G4LogicalVolume* DetectorConstruction::G    
348 {                                                 
349   if (j >= 0 && j < kMaxTally) {                  
350     return fLTally[j];                            
351   }                                               
352   else {                                          
353     G4cout << "### DetectorConstruction::GetLO    
354            << "number " << j << " is ignored"     
355     return nullptr;                               
356   }                                               
357 }                                                 
358                                                   
359 //....oooOO0OOooo........oooOO0OOooo........oo    
360