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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/basic/B2/B2b/src/DetectorConstruction.cc (Version 11.3.0) and /examples/basic/B2/B2b/src/DetectorConstruction.cc (Version 8.0.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 //                                                
 27 /// \file B2/B2b/src/DetectorConstruction.cc      
 28 /// \brief Implementation of the B2b::Detector    
 29                                                   
 30 #include "DetectorConstruction.hh"                
 31                                                   
 32 #include "ChamberParameterisation.hh"             
 33 #include "DetectorMessenger.hh"                   
 34 #include "TrackerSD.hh"                           
 35                                                   
 36 #include "G4AutoDelete.hh"                        
 37 #include "G4Box.hh"                               
 38 #include "G4Colour.hh"                            
 39 #include "G4GeometryManager.hh"                   
 40 #include "G4GeometryTolerance.hh"                 
 41 #include "G4GlobalMagFieldMessenger.hh"           
 42 #include "G4LogicalVolume.hh"                     
 43 #include "G4Material.hh"                          
 44 #include "G4NistManager.hh"                       
 45 #include "G4PVParameterised.hh"                   
 46 #include "G4PVPlacement.hh"                       
 47 #include "G4SDManager.hh"                         
 48 #include "G4SystemOfUnits.hh"                     
 49 #include "G4ThreeVector.hh"                       
 50 #include "G4Tubs.hh"                              
 51 #include "G4UserLimits.hh"                        
 52 #include "G4VisAttributes.hh"                     
 53                                                   
 54 using namespace B2;                               
 55                                                   
 56 namespace B2b                                     
 57 {                                                 
 58                                                   
 59 //....oooOO0OOooo........oooOO0OOooo........oo    
 60                                                   
 61 G4ThreadLocal G4GlobalMagFieldMessenger* Detec    
 62                                                   
 63 DetectorConstruction::DetectorConstruction()      
 64 {                                                 
 65   fMessenger = new DetectorMessenger(this);       
 66 }                                                 
 67                                                   
 68 //....oooOO0OOooo........oooOO0OOooo........oo    
 69                                                   
 70 DetectorConstruction::~DetectorConstruction()     
 71 {                                                 
 72   delete fStepLimit;                              
 73   delete fMessenger;                              
 74 }                                                 
 75                                                   
 76 //....oooOO0OOooo........oooOO0OOooo........oo    
 77                                                   
 78 G4VPhysicalVolume* DetectorConstruction::Const    
 79 {                                                 
 80   // Define materials                             
 81   DefineMaterials();                              
 82                                                   
 83   // Define volumes                               
 84   return DefineVolumes();                         
 85 }                                                 
 86                                                   
 87 //....oooOO0OOooo........oooOO0OOooo........oo    
 88                                                   
 89 void DetectorConstruction::DefineMaterials()      
 90 {                                                 
 91   // Material definition                          
 92                                                   
 93   G4NistManager* nistManager = G4NistManager::    
 94                                                   
 95   // Air defined using NIST Manager               
 96   nistManager->FindOrBuildMaterial("G4_AIR");     
 97                                                   
 98   // Lead defined using NIST Manager              
 99   fTargetMaterial = nistManager->FindOrBuildMa    
100                                                   
101   // Xenon gas defined using NIST Manager         
102   fChamberMaterial = nistManager->FindOrBuildM    
103                                                   
104   // Print materials                              
105   G4cout << *(G4Material::GetMaterialTable())     
106 }                                                 
107                                                   
108 //....oooOO0OOooo........oooOO0OOooo........oo    
109                                                   
110 G4VPhysicalVolume* DetectorConstruction::Defin    
111 {                                                 
112   G4Material* air = G4Material::GetMaterial("G    
113                                                   
114   // Sizes of the principal geometrical compon    
115                                                   
116   G4int NbOfChambers = 5;                         
117   G4double chamberSpacing = 80 * cm;  // from     
118                                                   
119   G4double chamberWidth = 20.0 * cm;  // width    
120   G4double targetLength = 5.0 * cm;  // full l    
121                                                   
122   G4double trackerLength = (NbOfChambers + 1)     
123                                                   
124   G4double worldLength = 1.2 * (2 * targetLeng    
125                                                   
126   G4double targetRadius = 0.5 * targetLength;     
127   targetLength = 0.5 * targetLength;  // Half     
128   G4double trackerSize = 0.5 * trackerLength;     
129                                                   
130   // Definitions of Solids, Logical Volumes, P    
131                                                   
132   // World                                        
133                                                   
134   G4GeometryManager::GetInstance()->SetWorldMa    
135                                                   
136   G4cout << "Computed tolerance = "               
137          << G4GeometryTolerance::GetInstance()    
138                                                   
139   auto worldS = new G4Box("world",  // its nam    
140                           worldLength / 2, wor    
141   auto worldLV = new G4LogicalVolume(worldS,      
142                                      air,  //     
143                                      "World");    
144                                                   
145   //  Must place the World Physical volume unr    
146   //                                              
147   auto worldPV = new G4PVPlacement(nullptr,  /    
148                                    G4ThreeVect    
149                                    worldLV,  /    
150                                    "World",  /    
151                                    nullptr,  /    
152                                    false,  //     
153                                    0,  // copy    
154                                    fCheckOverl    
155                                                   
156   // Target                                       
157                                                   
158   G4ThreeVector positionTarget = G4ThreeVector    
159                                                   
160   auto targetS = new G4Tubs("target", 0., targ    
161   fLogicTarget = new G4LogicalVolume(targetS,     
162   new G4PVPlacement(nullptr,  // no rotation      
163                     positionTarget,  // at (x,    
164                     fLogicTarget,  // its logi    
165                     "Target",  // its name        
166                     worldLV,  // its mother vo    
167                     false,  // no boolean oper    
168                     0,  // copy number            
169                     fCheckOverlaps);  // check    
170                                                   
171   G4cout << "Target is " << 2 * targetLength /    
172          << G4endl;                               
173                                                   
174   // Tracker                                      
175                                                   
176   G4ThreeVector positionTracker = G4ThreeVecto    
177                                                   
178   auto trackerS = new G4Tubs("tracker", 0, tra    
179   auto trackerLV = new G4LogicalVolume(tracker    
180   new G4PVPlacement(nullptr,  // no rotation      
181                     positionTracker,  // at (x    
182                     trackerLV,  // its logical    
183                     "Tracker",  // its name       
184                     worldLV,  // its mother  v    
185                     false,  // no boolean oper    
186                     0,  // copy number            
187                     fCheckOverlaps);  // check    
188                                                   
189   // Tracker segments                             
190                                                   
191   // An example of Parameterised volumes          
192   // Dummy values for G4Tubs -- modified by pa    
193                                                   
194   auto chamberS = new G4Tubs("tracker", 0, 100    
195   fLogicChamber =                                 
196     new G4LogicalVolume(chamberS, fChamberMate    
197                                                   
198   G4double firstPosition = -trackerSize + cham    
199   G4double firstLength = trackerLength / 10;      
200   G4double lastLength = trackerLength;            
201                                                   
202   G4VPVParameterisation* chamberParam =           
203     new ChamberParameterisation(NbOfChambers,     
204                                 firstPosition,    
205                                 chamberSpacing    
206                                 chamberWidth,     
207                                 firstLength,      
208                                 lastLength);      
209                                                   
210   // dummy value : kZAxis -- modified by param    
211                                                   
212   new G4PVParameterised("Chamber",  // their n    
213                         fLogicChamber,  // the    
214                         trackerLV,  // Mother     
215                         kZAxis,  // Are placed    
216                         NbOfChambers,  // Numb    
217                         chamberParam,  // The     
218                         fCheckOverlaps);  // c    
219                                                   
220   G4cout << "There are " << NbOfChambers << "     
221          << "The chambers are " << chamberWidt    
222          << G4endl << "The distance between ch    
223                                                   
224   // Visualization attributes                     
225                                                   
226   G4VisAttributes boxVisAtt(G4Colour::White())    
227                                                   
228   worldLV->SetVisAttributes(boxVisAtt);           
229   fLogicTarget->SetVisAttributes(boxVisAtt);      
230   trackerLV->SetVisAttributes(boxVisAtt);         
231                                                   
232   G4VisAttributes chamberVisAtt(G4Colour::Yell    
233   fLogicChamber->SetVisAttributes(chamberVisAt    
234                                                   
235   // Example of User Limits                       
236   //                                              
237   // Below is an example of how to set trackin    
238   // logical volume                               
239   //                                              
240   // Sets a max step length in the tracker reg    
241                                                   
242   G4double maxStep = 0.5 * chamberWidth;          
243   fStepLimit = new G4UserLimits(maxStep);         
244   trackerLV->SetUserLimits(fStepLimit);           
245                                                   
246   /// Set additional contraints on the track,     
247   ///                                             
248   /// G4double maxLength = 2*trackerLength, ma    
249   /// trackerLV->SetUserLimits(new G4UserLimit    
250   ///                                             
251   ///                                             
252   ///                                             
253                                                   
254   // Always return the physical world             
255                                                   
256   return worldPV;                                 
257 }                                                 
258                                                   
259 //....oooOO0OOooo........oooOO0OOooo........oo    
260                                                   
261 void DetectorConstruction::ConstructSDandField    
262 {                                                 
263   // Sensitive detectors                          
264                                                   
265   G4String trackerChamberSDname = "B2/TrackerC    
266   auto trackerSD = new TrackerSD(trackerChambe    
267   G4SDManager::GetSDMpointer()->AddNewDetector    
268   SetSensitiveDetector(fLogicChamber, trackerS    
269                                                   
270   // Create global magnetic field messenger.      
271   // Uniform magnetic field is then created au    
272   // the field value is not zero.                 
273   G4ThreeVector fieldValue = G4ThreeVector();     
274   fMagFieldMessenger = new G4GlobalMagFieldMes    
275   fMagFieldMessenger->SetVerboseLevel(1);         
276                                                   
277   // Register the field messenger for deleting    
278   G4AutoDelete::Register(fMagFieldMessenger);     
279 }                                                 
280                                                   
281 //....oooOO0OOooo........oooOO0OOooo........oo    
282                                                   
283 void DetectorConstruction::SetTargetMaterial(G    
284 {                                                 
285   G4NistManager* nistManager = G4NistManager::    
286                                                   
287   G4Material* pttoMaterial = nistManager->Find    
288                                                   
289   if (fTargetMaterial != pttoMaterial) {          
290     if (pttoMaterial) {                           
291       fTargetMaterial = pttoMaterial;             
292       if (fLogicTarget) fLogicTarget->SetMater    
293       G4cout << G4endl << "----> The target is    
294     }                                             
295     else {                                        
296       G4cout << G4endl << "-->  WARNING from S    
297              << G4endl;                           
298     }                                             
299   }                                               
300 }                                                 
301                                                   
302 //....oooOO0OOooo........oooOO0OOooo........oo    
303                                                   
304 void DetectorConstruction::SetChamberMaterial(    
305 {                                                 
306   G4NistManager* nistManager = G4NistManager::    
307                                                   
308   G4Material* pttoMaterial = nistManager->Find    
309                                                   
310   if (fChamberMaterial != pttoMaterial) {         
311     if (pttoMaterial) {                           
312       fChamberMaterial = pttoMaterial;            
313       if (fLogicChamber) fLogicChamber->SetMat    
314       G4cout << G4endl << "----> The chambers     
315     }                                             
316     else {                                        
317       G4cout << G4endl << "-->  WARNING from S    
318              << G4endl;                           
319     }                                             
320   }                                               
321 }                                                 
322                                                   
323 //....oooOO0OOooo........oooOO0OOooo........oo    
324                                                   
325 void DetectorConstruction::SetMaxStep(G4double    
326 {                                                 
327   if ((fStepLimit) && (maxStep > 0.)) fStepLim    
328 }                                                 
329                                                   
330 //....oooOO0OOooo........oooOO0OOooo........oo    
331                                                   
332 }  // namespace B2b                               
333