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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/field04/src/F04DetectorConstruction.cc (Version 11.3.0) and /examples/extended/field/field04/src/F04DetectorConstruction.cc (Version 7.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 //                                                
 27 /// \file field/field04/src/F04DetectorConstru    
 28 /// \brief Implementation of the F04DetectorCo    
 29 //                                                
 30 //....oooOO0OOooo........oooOO0OOooo........oo    
 31 //....oooOO0OOooo........oooOO0OOooo........oo    
 32                                                   
 33 #include "F04DetectorConstruction.hh"             
 34                                                   
 35 #include "F04DetectorMessenger.hh"                
 36 #include "F04FocusSolenoid.hh"                    
 37 #include "F04GlobalField.hh"                      
 38 #include "F04Materials.hh"                        
 39 #include "F04SimpleSolenoid.hh"                   
 40                                                   
 41 #include "G4AutoDelete.hh"                        
 42 #include "G4GeometryManager.hh"                   
 43 #include "G4LogicalVolume.hh"                     
 44 #include "G4LogicalVolumeStore.hh"                
 45 #include "G4Material.hh"                          
 46 #include "G4NistManager.hh"                       
 47 #include "G4PVPlacement.hh"                       
 48 #include "G4PhysicalConstants.hh"                 
 49 #include "G4PhysicalVolumeStore.hh"               
 50 #include "G4RotationMatrix.hh"                    
 51 #include "G4RunManager.hh"                        
 52 #include "G4SolidStore.hh"                        
 53 #include "G4StateManager.hh"                      
 54 #include "G4SystemOfUnits.hh"                     
 55 #include "G4Tubs.hh"                              
 56 #include "globals.hh"                             
 57                                                   
 58 //....oooOO0OOooo........oooOO0OOooo........oo    
 59                                                   
 60 F04DetectorConstruction::F04DetectorConstructi    
 61 {                                                 
 62   SetTargetAngle(170);                            
 63   SetCaptureMgntB1(2.5 * tesla);                  
 64   SetCaptureMgntB2(5.0 * tesla);                  
 65   SetTransferMgntB(5.0 * tesla);                  
 66                                                   
 67   fDegraderPos = -fTransferMgntLength / 2. + f    
 68                                                   
 69   fDetectorMessenger = new F04DetectorMessenge    
 70 }                                                 
 71                                                   
 72 //....oooOO0OOooo........oooOO0OOooo........oo    
 73                                                   
 74 F04DetectorConstruction::~F04DetectorConstruct    
 75 {                                                 
 76   delete fDetectorMessenger;                      
 77 }                                                 
 78                                                   
 79 //....oooOO0OOooo........oooOO0OOooo........oo    
 80                                                   
 81 G4VPhysicalVolume* F04DetectorConstruction::Co    
 82 {                                                 
 83   if (fPhysiWorld) {                              
 84     G4GeometryManager::GetInstance()->OpenGeom    
 85     G4PhysicalVolumeStore::GetInstance()->Clea    
 86     G4LogicalVolumeStore::GetInstance()->Clean    
 87     G4SolidStore::GetInstance()->Clean();         
 88   }                                               
 89                                                   
 90   fMaterials = F04Materials::GetInstance();       
 91                                                   
 92   DefineMaterials();                              
 93                                                   
 94   return ConstructDetector();                     
 95 }                                                 
 96                                                   
 97 //....oooOO0OOooo........oooOO0OOooo........oo    
 98                                                   
 99 void F04DetectorConstruction::DefineMaterials(    
100 {                                                 
101   // define materials for the experiment          
102                                                   
103   fVacuum = fMaterials->GetMaterial("G4_Galact    
104                                                   
105   fWorldMaterial = fMaterials->GetMaterial("G4    
106   fDegraderMaterial = fMaterials->GetMaterial(    
107   fTargetMaterial = fMaterials->GetMaterial("G    
108 }                                                 
109                                                   
110 //....oooOO0OOooo........oooOO0OOooo........oo    
111                                                   
112 G4VPhysicalVolume* F04DetectorConstruction::Co    
113 {                                                 
114   fSolidWorld = new G4Tubs("World", 0., GetWor    
115                                                   
116   fLogicWorld = new G4LogicalVolume(fSolidWorl    
117                                                   
118   fPhysiWorld =                                   
119     new G4PVPlacement(nullptr, G4ThreeVector()    
120                                                   
121   // Capture Magnet                               
122                                                   
123   fSolidCaptureMgnt =                             
124     new G4Tubs("CaptureMgnt", 0., GetCaptureMg    
125                                                   
126   fLogicCaptureMgnt = new G4LogicalVolume(fSol    
127                                                   
128   fCaptureMgntCenter = G4ThreeVector();           
129                                                   
130   fPhysiCaptureMgnt = new G4PVPlacement(nullpt    
131                                         fLogic    
132                                                   
133   // Transfer Magnet                              
134                                                   
135   fSolidTransferMgnt = new G4Tubs("TransferMgn    
136                                   GetTransferM    
137                                                   
138   fLogicTransferMgnt = new G4LogicalVolume(fSo    
139                                                   
140   G4double z = GetCaptureMgntLength() / 2. + G    
141   G4double x = GetTransferMgntPos() / 2.;         
142                                                   
143   fTransferMgntCenter = G4ThreeVector(x, 0., z    
144                                                   
145   auto g4rot = new G4RotationMatrix();            
146   *g4rot = StringToRotationMatrix("Y30,X10");     
147   *g4rot = g4rot->inverse();                      
148   if (*g4rot == G4RotationMatrix()) g4rot = nu    
149                                                   
150   fPhysiTransferMgnt = new G4PVPlacement(g4rot    
151                                          fLogi    
152                                                   
153   // Test Plane                                   
154                                                   
155   auto solidTestPlane = new G4Tubs("TestPlane"    
156                                                   
157   auto logicTestPlane = new G4LogicalVolume(so    
158                                                   
159   z = GetTransferMgntLength() / 2. - 1. * mm;     
160                                                   
161   G4ThreeVector testPlaneCenter = G4ThreeVecto    
162                                                   
163   new G4PVPlacement(nullptr, testPlaneCenter,     
164                     false, 0);                    
165                                                   
166   // Target                                       
167                                                   
168   if (GetTargetThickness() > 0.) {                
169     fSolidTarget =                                
170       new G4Tubs("Target", 0., GetTargetRadius    
171                                                   
172     fLogicTarget = new G4LogicalVolume(fSolidT    
173                                                   
174     G4int i = GetTargetAngle();                   
175                                                   
176     G4String angle = std::to_string(i);           
177     G4StrUtil::strip(angle);                      
178     angle = "Y" + angle;                          
179                                                   
180     g4rot = new G4RotationMatrix();               
181     *g4rot = StringToRotationMatrix(angle);       
182     *g4rot = g4rot->inverse();                    
183     if (*g4rot == G4RotationMatrix()) g4rot =     
184                                                   
185     G4ThreeVector targetCenter(0., 0., GetTarg    
186                                                   
187     fPhysiTarget =                                
188       new G4PVPlacement(g4rot, targetCenter, "    
189   }                                               
190                                                   
191   // Degrader                                     
192                                                   
193   if (GetDegraderThickness() > 0.) {              
194     fSolidDegrader =                              
195       new G4Tubs("Degrader", 0., GetDegraderRa    
196                                                   
197     fLogicDegrader = new G4LogicalVolume(fSoli    
198                                                   
199     G4ThreeVector degraderCenter = G4ThreeVect    
200                                                   
201     fPhysiDegrader = new G4PVPlacement(nullptr    
202                                        fPhysiT    
203   }                                               
204                                                   
205   return fPhysiWorld;                             
206 }                                                 
207                                                   
208 //....oooOO0OOooo........oooOO0OOooo........oo    
209                                                   
210 void F04DetectorConstruction::SetWorldMaterial    
211 {                                                 
212   G4Material* pttoMaterial = G4NistManager::In    
213                                                   
214   if (pttoMaterial != fWorldMaterial) {           
215     if (pttoMaterial) {                           
216       fWorldMaterial = pttoMaterial;              
217       G4RunManager::GetRunManager()->PhysicsHa    
218     }                                             
219     else {                                        
220       G4cout << "\n--> WARNING from SetWorldMa    
221              << G4endl;                           
222     }                                             
223   }                                               
224 }                                                 
225                                                   
226 //....oooOO0OOooo........oooOO0OOooo........oo    
227                                                   
228 void F04DetectorConstruction::SetTargetMateria    
229 {                                                 
230   G4Material* pttoMaterial = G4NistManager::In    
231                                                   
232   if (pttoMaterial != fTargetMaterial) {          
233     if (pttoMaterial) {                           
234       fTargetMaterial = pttoMaterial;             
235       G4RunManager::GetRunManager()->PhysicsHa    
236     }                                             
237     else {                                        
238       G4cout << "\n-->  WARNING from SetTarget    
239              << G4endl;                           
240     }                                             
241   }                                               
242 }                                                 
243                                                   
244 //....oooOO0OOooo........oooOO0OOooo........oo    
245                                                   
246 void F04DetectorConstruction::SetDegraderMater    
247                                                   
248 {                                                 
249   G4Material* pttoMaterial = G4NistManager::In    
250                                                   
251   if (pttoMaterial != fDegraderMaterial) {        
252     if (pttoMaterial) {                           
253       fDegraderMaterial = pttoMaterial;           
254       G4RunManager::GetRunManager()->PhysicsHa    
255     }                                             
256     else {                                        
257       G4cout << "\n--> WARNING from SetDegrade    
258              << G4endl;                           
259     }                                             
260   }                                               
261 }                                                 
262                                                   
263 //....oooOO0OOooo........oooOO0OOooo........oo    
264                                                   
265 void F04DetectorConstruction::SetWorldSizeZ(G4    
266 {                                                 
267   fWorldSizeZ = val;                              
268   if (G4StateManager::GetStateManager()->GetCu    
269     G4RunManager::GetRunManager()->GeometryHas    
270 }                                                 
271                                                   
272 //....oooOO0OOooo........oooOO0OOooo........oo    
273                                                   
274 void F04DetectorConstruction::SetWorldSizeR(G4    
275 {                                                 
276   fWorldSizeR = val;                              
277   if (G4StateManager::GetStateManager()->GetCu    
278     G4RunManager::GetRunManager()->GeometryHas    
279 }                                                 
280                                                   
281 //....oooOO0OOooo........oooOO0OOooo........oo    
282                                                   
283 void F04DetectorConstruction::SetCaptureMgntRa    
284 {                                                 
285   fCaptureMgntRadius = val;                       
286   if (G4StateManager::GetStateManager()->GetCu    
287     G4RunManager::GetRunManager()->GeometryHas    
288 }                                                 
289                                                   
290 //....oooOO0OOooo........oooOO0OOooo........oo    
291                                                   
292 void F04DetectorConstruction::SetCaptureMgntLe    
293 {                                                 
294   fCaptureMgntLength = val;                       
295   if (G4StateManager::GetStateManager()->GetCu    
296     G4RunManager::GetRunManager()->GeometryHas    
297 }                                                 
298                                                   
299 //....oooOO0OOooo........oooOO0OOooo........oo    
300                                                   
301 void F04DetectorConstruction::SetCaptureMgntB1    
302 {                                                 
303   fCaptureMgntB1 = val;                           
304   if (G4StateManager::GetStateManager()->GetCu    
305     G4RunManager::GetRunManager()->GeometryHas    
306 }                                                 
307                                                   
308 //....oooOO0OOooo........oooOO0OOooo........oo    
309                                                   
310 void F04DetectorConstruction::SetCaptureMgntB2    
311 {                                                 
312   fCaptureMgntB2 = val;                           
313   if (G4StateManager::GetStateManager()->GetCu    
314     G4RunManager::GetRunManager()->GeometryHas    
315 }                                                 
316                                                   
317 //....oooOO0OOooo........oooOO0OOooo........oo    
318                                                   
319 void F04DetectorConstruction::SetTransferMgntR    
320 {                                                 
321   fTransferMgntRadius = val;                      
322   if (G4StateManager::GetStateManager()->GetCu    
323     G4RunManager::GetRunManager()->GeometryHas    
324 }                                                 
325                                                   
326 //....oooOO0OOooo........oooOO0OOooo........oo    
327                                                   
328 void F04DetectorConstruction::SetTransferMgntL    
329 {                                                 
330   fTransferMgntLength = val;                      
331   if (G4StateManager::GetStateManager()->GetCu    
332     G4RunManager::GetRunManager()->GeometryHas    
333 }                                                 
334                                                   
335 //....oooOO0OOooo........oooOO0OOooo........oo    
336                                                   
337 void F04DetectorConstruction::SetTransferMgntB    
338 {                                                 
339   fTransferMgntB = val;                           
340   if (G4StateManager::GetStateManager()->GetCu    
341     G4RunManager::GetRunManager()->GeometryHas    
342 }                                                 
343                                                   
344 //....oooOO0OOooo........oooOO0OOooo........oo    
345                                                   
346 void F04DetectorConstruction::SetTransferMgntP    
347 {                                                 
348   fTransferMgntPos = val;                         
349   if (G4StateManager::GetStateManager()->GetCu    
350     G4RunManager::GetRunManager()->GeometryHas    
351 }                                                 
352                                                   
353 //....oooOO0OOooo........oooOO0OOooo........oo    
354                                                   
355 void F04DetectorConstruction::SetTargetRadius(    
356 {                                                 
357   fTargetRadius = val;                            
358   if (G4StateManager::GetStateManager()->GetCu    
359     G4RunManager::GetRunManager()->GeometryHas    
360 }                                                 
361                                                   
362 //....oooOO0OOooo........oooOO0OOooo........oo    
363                                                   
364 void F04DetectorConstruction::SetTargetThickne    
365 {                                                 
366   fTargetThickness = val;                         
367   if (G4StateManager::GetStateManager()->GetCu    
368     G4RunManager::GetRunManager()->GeometryHas    
369 }                                                 
370                                                   
371 //....oooOO0OOooo........oooOO0OOooo........oo    
372                                                   
373 void F04DetectorConstruction::SetTargetPos(G4d    
374 {                                                 
375   fTargetPos = val;                               
376   if (G4StateManager::GetStateManager()->GetCu    
377     G4RunManager::GetRunManager()->GeometryHas    
378 }                                                 
379                                                   
380 //....oooOO0OOooo........oooOO0OOooo........oo    
381                                                   
382 void F04DetectorConstruction::SetTargetAngle(G    
383 {                                                 
384   fTargetAngle = val;                             
385   if (G4StateManager::GetStateManager()->GetCu    
386     G4RunManager::GetRunManager()->GeometryHas    
387 }                                                 
388                                                   
389 //....oooOO0OOooo........oooOO0OOooo........oo    
390                                                   
391 void F04DetectorConstruction::SetDegraderRadiu    
392 {                                                 
393   fDegraderRadius = val;                          
394   if (G4StateManager::GetStateManager()->GetCu    
395     G4RunManager::GetRunManager()->GeometryHas    
396 }                                                 
397                                                   
398 //....oooOO0OOooo........oooOO0OOooo........oo    
399                                                   
400 void F04DetectorConstruction::SetDegraderThick    
401 {                                                 
402   fDegraderThickness = val;                       
403   if (G4StateManager::GetStateManager()->GetCu    
404     G4RunManager::GetRunManager()->GeometryHas    
405 }                                                 
406                                                   
407 //....oooOO0OOooo........oooOO0OOooo........oo    
408                                                   
409 void F04DetectorConstruction::SetDegraderPos(G    
410 {                                                 
411   fDegraderPos = val;                             
412   if (G4StateManager::GetStateManager()->GetCu    
413     G4RunManager::GetRunManager()->GeometryHas    
414 }                                                 
415                                                   
416 //....oooOO0OOooo........oooOO0OOooo........oo    
417                                                   
418 void F04DetectorConstruction::ConstructSDandFi    
419 {                                                 
420   if (!fFieldSetUp.Get()) {                       
421     F04GlobalField* field = F04GlobalField::Ge    
422     G4AutoDelete::Register(field);  // Kernel     
423     fFieldSetUp.Put(field);                       
424   }                                               
425 }                                                 
426                                                   
427 //....oooOO0OOooo........oooOO0OOooo........oo    
428                                                   
429 G4RotationMatrix F04DetectorConstruction::Stri    
430 {                                                 
431   // We apply successive rotations OF THE OBJE    
432   // axes of the parent's local coordinates; r    
433   // left-to-right (rotation="r1,r2,r3" => r1     
434                                                   
435   G4RotationMatrix rot;                           
436                                                   
437   unsigned int place = 0;                         
438                                                   
439   while (place < rotation.size()) {               
440     G4double angle;                               
441     char* p(nullptr);                             
442     G4String current = rotation.substr(place +    
443     angle = strtod(current.c_str(), &p) * deg;    
444                                                   
445     if (!p || (*p != ',' && *p != '\0')) {        
446       G4cerr << "Invalid rotation specificatio    
447                                                   
448       return rot;                                 
449     }                                             
450                                                   
451     G4RotationMatrix thisRotation;                
452                                                   
453     switch (rotation.substr(place, 1).c_str()[    
454       case 'X':                                   
455       case 'x':                                   
456         thisRotation = G4RotationMatrix(CLHEP:    
457         break;                                    
458       case 'Y':                                   
459       case 'y':                                   
460         thisRotation = G4RotationMatrix(CLHEP:    
461         break;                                    
462       case 'Z':                                   
463       case 'z':                                   
464         thisRotation = G4RotationMatrix(CLHEP:    
465         break;                                    
466       default:                                    
467         G4cerr << " Invalid rotation specifica    
468         return rot;                               
469     }                                             
470                                                   
471     rot = thisRotation * rot;                     
472     place = rotation.find(',', place);            
473     if (place > rotation.size()) break;           
474     ++place;                                      
475   }                                               
476                                                   
477   return rot;                                     
478 }                                                 
479