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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/field/field02/src/F02DetectorConstruction.cc (Version 11.3.0) and /examples/extended/field/field02/src/F02DetectorConstruction.cc (Version 11.0.p3,)


** Warning: Cannot open xref database.

  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 field/field02/src/F02DetectorConstru    
 27 /// \brief Implementation of the F02DetectorCo    
 28 //                                                
 29 //                                                
 30 //                                                
 31 //                                                
 32 //....oooOO0OOooo........oooOO0OOooo........oo    
 33 //....oooOO0OOooo........oooOO0OOooo........oo    
 34                                                   
 35 #include "F02DetectorConstruction.hh"             
 36                                                   
 37 #include "F02CalorimeterSD.hh"                    
 38 #include "F02DetectorMessenger.hh"                
 39                                                   
 40 #include "G4AutoDelete.hh"                        
 41 #include "G4GeometryManager.hh"                   
 42 #include "G4FieldBuilder.hh"                      
 43 #include "G4LogicalVolume.hh"                     
 44 #include "G4LogicalVolumeStore.hh"                
 45 #include "G4Material.hh"                          
 46 #include "G4PVPlacement.hh"                       
 47 #include "G4PhysicalConstants.hh"                 
 48 #include "G4PhysicalVolumeStore.hh"               
 49 #include "G4RunManager.hh"                        
 50 #include "G4SDManager.hh"                         
 51 #include "G4SolidStore.hh"                        
 52 #include "G4SystemOfUnits.hh"                     
 53 #include "G4Tubs.hh"                              
 54 #include "G4UniformElectricField.hh"              
 55                                                   
 56 //....oooOO0OOooo........oooOO0OOooo........oo    
 57                                                   
 58 F02DetectorConstruction::F02DetectorConstructi    
 59 {                                                 
 60   // create commands for interactive definitio    
 61                                                   
 62   fDetectorMessenger = new F02DetectorMessenge    
 63                                                   
 64   // create field builder                         
 65   // this will create commands for field confi    
 66   G4FieldBuilder::Instance();                     
 67   // G4FieldBuilder::Instance()->SetVerboseLev    
 68                                                   
 69   // create materials                             
 70   DefineMaterials();                              
 71 }                                                 
 72                                                   
 73 //....oooOO0OOooo........oooOO0OOooo........oo    
 74                                                   
 75 F02DetectorConstruction::~F02DetectorConstruct    
 76 {                                                 
 77   delete fDetectorMessenger;                      
 78 }                                                 
 79                                                   
 80 //....oooOO0OOooo........oooOO0OOooo........oo    
 81                                                   
 82 G4VPhysicalVolume* F02DetectorConstruction::Co    
 83 {                                                 
 84   return ConstructCalorimeter();                  
 85 }                                                 
 86                                                   
 87 //....oooOO0OOooo........oooOO0OOooo........oo    
 88                                                   
 89 void F02DetectorConstruction::DefineMaterials(    
 90 {                                                 
 91   // This function illustrates the possible wa    
 92                                                   
 93   G4String name, symbol;  // a=mass of a mole;    
 94   G4double a, z, density;  // z=mean number of    
 95   G4int nel;                                      
 96   G4int ncomponents;                              
 97   G4double fractionmass, pressure, temperature    
 98                                                   
 99   //                                              
100   // define Elements                              
101   //                                              
102                                                   
103   a = 1.01 * g / mole;                            
104   auto elH = new G4Element(name = "Hydrogen",     
105                                                   
106   a = 12.01 * g / mole;                           
107   auto elC = new G4Element(name = "Carbon", sy    
108                                                   
109   a = 14.01 * g / mole;                           
110   auto elN = new G4Element(name = "Nitrogen",     
111                                                   
112   a = 16.00 * g / mole;                           
113   auto elO = new G4Element(name = "Oxygen", sy    
114                                                   
115   a = 39.948 * g / mole;                          
116   auto elAr = new G4Element(name = "Argon", sy    
117                                                   
118   //                                              
119   // define simple materials                      
120   //                                              
121                                                   
122   // Mylar                                        
123                                                   
124   density = 1.39 * g / cm3;                       
125   auto mylar = new G4Material(name = "Mylar",     
126   mylar->AddElement(elO, 2);                      
127   mylar->AddElement(elC, 5);                      
128   mylar->AddElement(elH, 4);                      
129                                                   
130   // Polypropelene                                
131                                                   
132   auto CH2 = new G4Material("Polypropelene", 0    
133   CH2->AddElement(elH, 2);                        
134   CH2->AddElement(elC, 1);                        
135                                                   
136   // Krypton as detector gas, STP                 
137                                                   
138   density = 3.700 * mg / cm3;                     
139   a = 83.80 * g / mole;                           
140   auto Kr = new G4Material(name = "Kr", z = 36    
141                                                   
142   // Dry air (average composition)                
143                                                   
144   density = 1.7836 * mg / cm3;  // STP            
145   auto argon = new G4Material(name = "Argon",     
146   argon->AddElement(elAr, 1);                     
147                                                   
148   density = 1.25053 * mg / cm3;  // STP           
149   auto nitrogen = new G4Material(name = "N2",     
150   nitrogen->AddElement(elN, 2);                   
151                                                   
152   density = 1.4289 * mg / cm3;  // STP            
153   auto oxygen = new G4Material(name = "O2", de    
154   oxygen->AddElement(elO, 2);                     
155                                                   
156   density = 1.2928 * mg / cm3;  // STP            
157                                                   
158   temperature = STP_Temperature;                  
159   pressure = 1.0e-0 * STP_Pressure;               
160                                                   
161   auto air =                                      
162     new G4Material(name = "Air", density, ncom    
163   air->AddMaterial(nitrogen, fractionmass = 0.    
164   air->AddMaterial(oxygen, fractionmass = 0.23    
165   air->AddMaterial(argon, fractionmass = 0.012    
166                                                   
167   // Xenon as detector gas, STP                   
168                                                   
169   density = 5.858 * mg / cm3;                     
170   a = 131.29 * g / mole;                          
171   auto Xe = new G4Material(name = "Xenon", z =    
172                                                   
173   // Carbon dioxide, STP                          
174                                                   
175   density = 1.842 * mg / cm3;                     
176   auto CarbonDioxide = new G4Material(name = "    
177   CarbonDioxide->AddElement(elC, 1);              
178   CarbonDioxide->AddElement(elO, 2);              
179                                                   
180   // 80% Xe + 20% CO2, STP                        
181                                                   
182   density = 5.0818 * mg / cm3;                    
183   auto Xe20CO2 = new G4Material(name = "Xe20CO    
184   Xe20CO2->AddMaterial(Xe, fractionmass = 0.92    
185   Xe20CO2->AddMaterial(CarbonDioxide, fraction    
186                                                   
187   // 80% Kr + 20% CO2, STP                        
188                                                   
189   density = 3.601 * mg / cm3;                     
190   auto Kr20CO2 = new G4Material(name = "Kr20CO    
191   Kr20CO2->AddMaterial(Kr, fractionmass = 0.89    
192   Kr20CO2->AddMaterial(CarbonDioxide, fraction    
193                                                   
194   G4cout << *(G4Material::GetMaterialTable())     
195                                                   
196   // default materials of the calorimeter         
197                                                   
198   fAbsorberMaterial = Kr20CO2;  // XeCO2CF4;      
199                                                   
200   fWorldMaterial = air;                           
201 }                                                 
202                                                   
203 //....oooOO0OOooo........oooOO0OOooo........oo    
204                                                   
205 G4VPhysicalVolume* F02DetectorConstruction::Co    
206 {                                                 
207   // Cleanup old geometry                         
208                                                   
209   if (fPhysiWorld) {                              
210     G4GeometryManager::GetInstance()->OpenGeom    
211     G4PhysicalVolumeStore::GetInstance()->Clea    
212     G4LogicalVolumeStore::GetInstance()->Clean    
213     G4SolidStore::GetInstance()->Clean();         
214   }                                               
215                                                   
216   // complete the Calor parameters definition     
217                                                   
218   ComputeCalorParameters();                       
219   PrintCalorParameters();                         
220                                                   
221   // World                                        
222                                                   
223   fSolidWorld = new G4Tubs("World",  // its na    
224                            0., fWorldSizeR, fW    
225                                                   
226   fLogicWorld = new G4LogicalVolume(fSolidWorl    
227                                     fWorldMate    
228                                     "World");     
229                                                   
230   fPhysiWorld = new G4PVPlacement(nullptr,  //    
231                                   G4ThreeVecto    
232                                   "World",  //    
233                                   fLogicWorld,    
234                                   nullptr,  //    
235                                   false,  // n    
236                                   0);  // copy    
237   // Absorber                                     
238                                                   
239   fSolidAbsorber = new G4Tubs("Absorber", 0.,     
240                                                   
241   fLogicAbsorber = new G4LogicalVolume(fSolidA    
242                                                   
243   fPhysiAbsorber = new G4PVPlacement(nullptr,     
244                                      fLogicAbs    
245                                                   
246   return fPhysiWorld;                             
247 }                                                 
248                                                   
249 //....oooOO0OOooo........oooOO0OOooo........oo    
250                                                   
251 void F02DetectorConstruction::PrintCalorParame    
252 {                                                 
253   G4cout << "\n The  WORLD   is made of " << f    
254          << fWorldMaterial->GetName();            
255   G4cout << ", the transverse size (R) of the     
256   G4cout << " The ABSORBER is made of " << fAb    
257          << fAbsorberMaterial->GetName();         
258   G4cout << ", the transverse size (R) is " <<    
259   G4cout << " Z position of the (middle of the    
260   G4cout << G4endl;                               
261 }                                                 
262                                                   
263 //....oooOO0OOooo........oooOO0OOooo........oo    
264                                                   
265 void F02DetectorConstruction::SetAbsorberMater    
266 {                                                 
267   // get the pointer to the material table        
268   const G4MaterialTable* theMaterialTable = G4    
269                                                   
270   // search the material by its name              
271   G4Material* material;                           
272   for (size_t j = 0; j < theMaterialTable->siz    
273     material = (*theMaterialTable)[j];            
274     if (material->GetName() == materialChoice)    
275       fAbsorberMaterial = material;               
276       fLogicAbsorber->SetMaterial(material);      
277       G4RunManager::GetRunManager()->PhysicsHa    
278     }                                             
279   }                                               
280 }                                                 
281                                                   
282 //....oooOO0OOooo........oooOO0OOooo........oo    
283                                                   
284 void F02DetectorConstruction::SetWorldMaterial    
285 {                                                 
286   // get the pointer to the material table        
287   const G4MaterialTable* theMaterialTable = G4    
288                                                   
289   // search the material by its name              
290   G4Material* material;                           
291   for (size_t j = 0; j < theMaterialTable->siz    
292     material = (*theMaterialTable)[j];            
293     if (material->GetName() == materialChoice)    
294       fWorldMaterial = material;                  
295       fLogicWorld->SetMaterial(material);         
296       G4RunManager::GetRunManager()->PhysicsHa    
297     }                                             
298   }                                               
299 }                                                 
300                                                   
301 //....oooOO0OOooo........oooOO0OOooo........oo    
302                                                   
303 void F02DetectorConstruction::SetAbsorberThick    
304 {                                                 
305   // change Absorber thickness and recompute t    
306   fAbsorberThickness = val;                       
307   ComputeCalorParameters();                       
308   G4RunManager::GetRunManager()->GeometryHasBe    
309 }                                                 
310                                                   
311 //....oooOO0OOooo........oooOO0OOooo........oo    
312                                                   
313 void F02DetectorConstruction::SetAbsorberRadiu    
314 {                                                 
315   // change the transverse size and recompute     
316   fAbsorberRadius = val;                          
317   ComputeCalorParameters();                       
318   G4RunManager::GetRunManager()->GeometryHasBe    
319 }                                                 
320                                                   
321 //....oooOO0OOooo........oooOO0OOooo........oo    
322                                                   
323 void F02DetectorConstruction::SetWorldSizeZ(G4    
324 {                                                 
325   fWorldChanged = true;                           
326   fWorldSizeZ = val;                              
327   ComputeCalorParameters();                       
328   G4RunManager::GetRunManager()->GeometryHasBe    
329 }                                                 
330                                                   
331 //....oooOO0OOooo........oooOO0OOooo........oo    
332                                                   
333 void F02DetectorConstruction::SetWorldSizeR(G4    
334 {                                                 
335   fWorldChanged = true;                           
336   fWorldSizeR = val;                              
337   ComputeCalorParameters();                       
338   G4RunManager::GetRunManager()->GeometryHasBe    
339 }                                                 
340                                                   
341 //....oooOO0OOooo........oooOO0OOooo........oo    
342                                                   
343 void F02DetectorConstruction::SetAbsorberZpos(    
344 {                                                 
345   fZAbsorber = val;                               
346   ComputeCalorParameters();                       
347   G4RunManager::GetRunManager()->GeometryHasBe    
348 }                                                 
349                                                   
350 //....oooOO0OOooo........oooOO0OOooo........oo    
351                                                   
352 void F02DetectorConstruction::SetFieldValue(G4    
353 {                                                 
354   fFieldVector = value;                           
355                                                   
356   G4UniformElectricField* elField = nullptr;      
357   if (fFieldVector != G4ThreeVector(0.,0.,0.))    
358     elField = new G4UniformElectricField(fFiel    
359   }                                               
360                                                   
361   // Set field to the field builder               
362   auto fieldBuilder = G4FieldBuilder::Instance    
363   fieldBuilder->SetGlobalField(elField);          
364 }                                                 
365                                                   
366 //....oooOO0OOooo........oooOO0OOooo........oo    
367                                                   
368 void F02DetectorConstruction::ConstructSDandFi    
369 {                                                 
370   // Sensitive Detectors: Absorber                
371                                                   
372   if (!fCalorimeterSD.Get()) {                    
373     auto calorimeterSD = new F02CalorimeterSD(    
374     fCalorimeterSD.Put(calorimeterSD);            
375   }                                               
376   G4SDManager::GetSDMpointer()->AddNewDetector    
377   SetSensitiveDetector(fLogicAbsorber, fCalori    
378                                                   
379   // Create detector field                        
380   SetFieldValue(fFieldVector);                    
381                                                   
382   // Construct all Geant4 field objects           
383   auto fieldBuilder = G4FieldBuilder::Instance    
384   fieldBuilder->SetFieldType(kElectroMagnetic)    
385   fieldBuilder->ConstructFieldSetup();            
386 }                                                 
387                                                   
388 //....oooOO0OOooo........oooOO0OOooo........oo    
389