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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/TestEm5/src/DetectorConstruction.cc (Version 11.3.0) and /examples/extended/electromagnetic/TestEm5/src/DetectorConstruction.cc (Version 3.1)


  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/TestEm5/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 "G4AutoDelete.hh"                        
 38 #include "G4Box.hh"                               
 39 #include "G4GeometryManager.hh"                   
 40 #include "G4GlobalMagFieldMessenger.hh"           
 41 #include "G4LogicalVolume.hh"                     
 42 #include "G4LogicalVolumeStore.hh"                
 43 #include "G4Material.hh"                          
 44 #include "G4NistManager.hh"                       
 45 #include "G4PVPlacement.hh"                       
 46 #include "G4PhysicalConstants.hh"                 
 47 #include "G4PhysicalVolumeStore.hh"               
 48 #include "G4RunManager.hh"                        
 49 #include "G4SolidStore.hh"                        
 50 #include "G4SystemOfUnits.hh"                     
 51 #include "G4UniformMagField.hh"                   
 52 #include "G4UnitsTable.hh"                        
 53                                                   
 54 //....oooOO0OOooo........oooOO0OOooo........oo    
 55                                                   
 56 DetectorConstruction::DetectorConstruction()      
 57 {                                                 
 58   // default parameter values of the calorimet    
 59   fAbsorberThickness = 1. * cm;                   
 60   fAbsorberSizeYZ = 2. * cm;                      
 61   fXposAbs = 0. * cm;                             
 62   ComputeGeomParameters();                        
 63                                                   
 64   // materials                                    
 65   DefineMaterials();                              
 66   SetWorldMaterial("G4_Galactic");                
 67   SetAbsorberMaterial("G4_Si");                   
 68                                                   
 69   // create commands for interactive definitio    
 70   fDetectorMessenger = new DetectorMessenger(t    
 71 }                                                 
 72                                                   
 73 //....oooOO0OOooo........oooOO0OOooo........oo    
 74                                                   
 75 DetectorConstruction::~DetectorConstruction()     
 76 {                                                 
 77   delete fDetectorMessenger;                      
 78 }                                                 
 79                                                   
 80 //....oooOO0OOooo........oooOO0OOooo........oo    
 81                                                   
 82 void DetectorConstruction::DefineMaterials()      
 83 {                                                 
 84   // This function illustrates the possible wa    
 85                                                   
 86   G4String symbol;  // a=mass of a mole;          
 87   G4double a, z, density;  // z=mean number of    
 88                                                   
 89   G4int ncomponents, natoms;                      
 90   G4double fractionmass;                          
 91   G4double temperature, pressure;                 
 92                                                   
 93   //                                              
 94   // define Elements                              
 95   //                                              
 96                                                   
 97   G4Element* H = new G4Element("Hydrogen", sym    
 98   G4Element* C = new G4Element("Carbon", symbo    
 99   G4Element* N = new G4Element("Nitrogen", sym    
100   G4Element* O = new G4Element("Oxygen", symbo    
101   G4Element* Na = new G4Element("Sodium", symb    
102   G4Element* Ar = new G4Element("Argon", symbo    
103   G4Element* I = new G4Element("Iodine", symbo    
104   G4Element* Xe = new G4Element("Xenon", symbo    
105                                                   
106   //                                              
107   // define simple materials                      
108   //                                              
109                                                   
110   new G4Material("H2Liq", z = 1, a = 1.01 * g     
111   new G4Material("Beryllium", z = 4, a = 9.01     
112   new G4Material("Aluminium", z = 13, a = 26.9    
113   new G4Material("Silicon", z = 14, a = 28.09     
114                                                   
115   G4Material* lAr = new G4Material("liquidArgo    
116   lAr->AddElement(Ar, natoms = 1);                
117                                                   
118   new G4Material("Iron", z = 26, a = 55.85 * g    
119   new G4Material("Copper", z = 29, a = 63.55 *    
120   new G4Material("Germanium", z = 32, a = 72.6    
121   new G4Material("Silver", z = 47, a = 107.87     
122   new G4Material("Tungsten", z = 74, a = 183.8    
123   new G4Material("Gold", z = 79, a = 196.97 *     
124   new G4Material("Lead", z = 82, a = 207.19 *     
125                                                   
126   //                                              
127   // define a material from elements.   case 1    
128   //                                              
129                                                   
130   G4Material* H2O = new G4Material("Water", de    
131   H2O->AddElement(H, natoms = 2);                 
132   H2O->AddElement(O, natoms = 1);                 
133   H2O->GetIonisation()->SetMeanExcitationEnerg    
134                                                   
135   G4Material* CH = new G4Material("Plastic", d    
136   CH->AddElement(C, natoms = 1);                  
137   CH->AddElement(H, natoms = 1);                  
138                                                   
139   G4Material* NaI = new G4Material("NaI", dens    
140   NaI->AddElement(Na, natoms = 1);                
141   NaI->AddElement(I, natoms = 1);                 
142   NaI->GetIonisation()->SetMeanExcitationEnerg    
143                                                   
144   //                                              
145   // define a material from elements.   case 2    
146   //                                              
147                                                   
148   G4Material* Air = new G4Material("Air", dens    
149   Air->AddElement(N, fractionmass = 0.7);         
150   Air->AddElement(O, fractionmass = 0.3);         
151                                                   
152   G4Material* Air20 = new G4Material("Air20",     
153                                      kStateGas    
154   Air20->AddElement(N, fractionmass = 0.7);       
155   Air20->AddElement(O, fractionmass = 0.3);       
156                                                   
157   // Graphite                                     
158   //                                              
159   G4Material* Graphite = new G4Material("Graph    
160   Graphite->AddElement(C, fractionmass = 1.);     
161                                                   
162   // Havar                                        
163   //                                              
164   G4Element* Cr = new G4Element("Chrome", "Cr"    
165   G4Element* Fe = new G4Element("Iron", "Fe",     
166   G4Element* Co = new G4Element("Cobalt", "Co"    
167   G4Element* Ni = new G4Element("Nickel", "Ni"    
168   G4Element* W = new G4Element("Tungsten", "W"    
169                                                   
170   G4Material* Havar = new G4Material("Havar",     
171   Havar->AddElement(Cr, fractionmass = 0.1785)    
172   Havar->AddElement(Fe, fractionmass = 0.1822)    
173   Havar->AddElement(Co, fractionmass = 0.4452)    
174   Havar->AddElement(Ni, fractionmass = 0.1310)    
175   Havar->AddElement(W, fractionmass = 0.0631);    
176                                                   
177   //                                              
178   // examples of gas                              
179   //                                              
180   new G4Material("ArgonGas", z = 18, a = 39.94    
181                  273.15 * kelvin, 1 * atmosphe    
182                                                   
183   new G4Material("XenonGas", z = 54, a = 131.2    
184                  293.15 * kelvin, 1 * atmosphe    
185                                                   
186   G4Material* CO2 = new G4Material("CarbonicGa    
187   CO2->AddElement(C, natoms = 1);                 
188   CO2->AddElement(O, natoms = 2);                 
189                                                   
190   G4Material* ArCO2 = new G4Material("ArgonCO2    
191   ArCO2->AddElement(Ar, fractionmass = 0.7844)    
192   ArCO2->AddMaterial(CO2, fractionmass = 0.215    
193                                                   
194   // another way to define mixture of gas per     
195   G4Material* NewArCO2 =                          
196     new G4Material("NewArgonCO2", density = 1.    
197   NewArCO2->AddElement(Ar, natoms = 8);           
198   NewArCO2->AddElement(C, natoms = 2);            
199   NewArCO2->AddElement(O, natoms = 4);            
200                                                   
201   G4Material* ArCH4 = new G4Material("ArgonCH4    
202   ArCH4->AddElement(Ar, natoms = 93);             
203   ArCH4->AddElement(C, natoms = 7);               
204   ArCH4->AddElement(H, natoms = 28);              
205                                                   
206   G4Material* XeCH = new G4Material("XenonMeth    
207                                     ncomponent    
208   XeCH->AddElement(Xe, natoms = 875);             
209   XeCH->AddElement(C, natoms = 225);              
210   XeCH->AddElement(H, natoms = 700);              
211                                                   
212   G4Material* steam = new G4Material("WaterSte    
213   steam->AddMaterial(H2O, fractionmass = 1.);     
214   steam->GetIonisation()->SetMeanExcitationEne    
215                                                   
216   G4Material* rock1 = new G4Material("Standard    
217   rock1->AddElement(Na, 1);                       
218                                                   
219   //                                              
220   // example of vacuum                            
221   //                                              
222   density = universe_mean_density;  // from Ph    
223   pressure = 3.e-18 * pascal;                     
224   temperature = 2.73 * kelvin;                    
225   new G4Material("Galactic", z = 1, a = 1.01 *    
226 }                                                 
227                                                   
228 //....oooOO0OOooo........oooOO0OOooo........oo    
229                                                   
230 void DetectorConstruction::ComputeGeomParamete    
231 {                                                 
232   // Compute derived parameters of the calorim    
233   fXstartAbs = fXposAbs - 0.5 * fAbsorberThick    
234   fXendAbs = fXposAbs + 0.5 * fAbsorberThickne    
235                                                   
236   G4double xmax = std::max(std::abs(fXstartAbs    
237   fWorldSizeX = 2.4 * xmax;                       
238   fWorldSizeYZ = 1.2 * fAbsorberSizeYZ;           
239   if (nullptr != fPhysiWorld) {                   
240     ChangeGeometry();                             
241   }                                               
242 }                                                 
243                                                   
244 //....oooOO0OOooo........oooOO0OOooo........oo    
245                                                   
246 G4VPhysicalVolume* DetectorConstruction::Const    
247 {                                                 
248   if (nullptr != fPhysiWorld) {                   
249     return fPhysiWorld;                           
250   }                                               
251   // World                                        
252   //                                              
253   fSolidWorld = new G4Box("World",  // its nam    
254                           fWorldSizeX / 2, fWo    
255                                                   
256   fLogicWorld = new G4LogicalVolume(fSolidWorl    
257                                     fWorldMate    
258                                     "World");     
259                                                   
260   fPhysiWorld = new G4PVPlacement(0,  // no ro    
261                                   G4ThreeVecto    
262                                   fLogicWorld,    
263                                   "World",  //    
264                                   0,  // its m    
265                                   false,  // n    
266                                   0);  // copy    
267                                                   
268   // Absorber                                     
269   //                                              
270   fSolidAbsorber =                                
271     new G4Box("Absorber", fAbsorberThickness /    
272                                                   
273   fLogicAbsorber = new G4LogicalVolume(fSolidA    
274                                        fAbsorb    
275                                        "Absorb    
276                                                   
277   fPhysiAbsorber = new G4PVPlacement(0,  // no    
278                                      G4ThreeVe    
279                                      fLogicAbs    
280                                      "Absorber    
281                                      fLogicWor    
282                                      false,  /    
283                                      0);  // c    
284                                                   
285   PrintGeomParameters();                          
286                                                   
287   // always return the physical World             
288   //                                              
289   return fPhysiWorld;                             
290 }                                                 
291                                                   
292 //....oooOO0OOooo........oooOO0OOooo........oo    
293                                                   
294 void DetectorConstruction::PrintGeomParameters    
295 {                                                 
296   G4cout << "\n" << fWorldMaterial << G4endl;     
297   G4cout << "\n" << fAbsorberMaterial << G4end    
298                                                   
299   G4cout << "\n The  WORLD   is made of " << G    
300          << fWorldMaterial->GetName();            
301   G4cout << ". The transverse size (YZ) of the    
302          << G4endl;                               
303   G4cout << " The ABSORBER is made of " << G4B    
304          << fAbsorberMaterial->GetName();         
305   G4cout << ". The transverse size (YZ) is " <    
306   G4cout << " X position of the middle of the     
307   G4cout << G4endl;                               
308 }                                                 
309                                                   
310 //....oooOO0OOooo........oooOO0OOooo........oo    
311                                                   
312 void DetectorConstruction::SetAbsorberMaterial    
313 {                                                 
314   // search the material by its name              
315   G4Material* pttoMaterial = G4NistManager::In    
316                                                   
317   if (pttoMaterial && fAbsorberMaterial != ptt    
318     fAbsorberMaterial = pttoMaterial;             
319     if (fLogicAbsorber) {                         
320       fLogicAbsorber->SetMaterial(fAbsorberMat    
321     }                                             
322     G4RunManager::GetRunManager()->PhysicsHasB    
323   }                                               
324 }                                                 
325                                                   
326 //....oooOO0OOooo........oooOO0OOooo........oo    
327                                                   
328 void DetectorConstruction::SetWorldMaterial(co    
329 {                                                 
330   // search the material by its name              
331   G4Material* pttoMaterial = G4NistManager::In    
332                                                   
333   if (pttoMaterial && fWorldMaterial != pttoMa    
334     fWorldMaterial = pttoMaterial;                
335     if (fLogicWorld) {                            
336       fLogicWorld->SetMaterial(fWorldMaterial)    
337     }                                             
338     G4RunManager::GetRunManager()->PhysicsHasB    
339   }                                               
340 }                                                 
341                                                   
342 //....oooOO0OOooo........oooOO0OOooo........oo    
343                                                   
344 void DetectorConstruction::SetAbsorberThicknes    
345 {                                                 
346   fAbsorberThickness = val;                       
347   ComputeGeomParameters();                        
348 }                                                 
349                                                   
350 //....oooOO0OOooo........oooOO0OOooo........oo    
351                                                   
352 void DetectorConstruction::SetAbsorberSizeYZ(G    
353 {                                                 
354   fAbsorberSizeYZ = val;                          
355   ComputeGeomParameters();                        
356 }                                                 
357                                                   
358 //....oooOO0OOooo........oooOO0OOooo........oo    
359                                                   
360 void DetectorConstruction::SetWorldSizeX(G4dou    
361 {                                                 
362   fWorldSizeX = val;                              
363   ComputeGeomParameters();                        
364 }                                                 
365                                                   
366 //....oooOO0OOooo........oooOO0OOooo........oo    
367                                                   
368 void DetectorConstruction::SetWorldSizeYZ(G4do    
369 {                                                 
370   fWorldSizeYZ = val;                             
371   ComputeGeomParameters();                        
372 }                                                 
373                                                   
374 //....oooOO0OOooo........oooOO0OOooo........oo    
375                                                   
376 void DetectorConstruction::SetAbsorberXpos(G4d    
377 {                                                 
378   fXposAbs = val;                                 
379   ComputeGeomParameters();                        
380 }                                                 
381                                                   
382 //....oooOO0OOooo........oooOO0OOooo........oo    
383                                                   
384 void DetectorConstruction::ConstructSDandField    
385 {                                                 
386   if (fFieldMessenger.Get() == 0) {               
387     // Create global magnetic field messenger.    
388     // Uniform magnetic field is then created     
389     // the field value is not zero.               
390     G4ThreeVector fieldValue = G4ThreeVector()    
391     G4GlobalMagFieldMessenger* msg = new G4Glo    
392     // msg->SetVerboseLevel(1);                   
393     G4AutoDelete::Register(msg);                  
394     fFieldMessenger.Put(msg);                     
395   }                                               
396 }                                                 
397                                                   
398 //....oooOO0OOooo........oooOO0OOooo........oo    
399                                                   
400 void DetectorConstruction::ChangeGeometry()       
401 {                                                 
402   fSolidWorld->SetXHalfLength(fWorldSizeX * 0.    
403   fSolidWorld->SetYHalfLength(fWorldSizeYZ * 0    
404   fSolidWorld->SetZHalfLength(fWorldSizeYZ * 0    
405                                                   
406   fSolidAbsorber->SetXHalfLength(fAbsorberThic    
407   fSolidAbsorber->SetYHalfLength(fAbsorberSize    
408   fSolidAbsorber->SetZHalfLength(fAbsorberSize    
409 }                                                 
410                                                   
411 //....oooOO0OOooo........oooOO0OOooo........oo    
412