Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F04DetectorConstruction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 //
30 #include "G4ios.hh"
31 #include "globals.hh"
32 
34 #include "F04DetectorMessenger.hh"
35 
36 #include "F04GlobalField.hh"
37 
38 #include "G4Tubs.hh"
39 #include "G4LogicalVolume.hh"
40 #include "G4PVPlacement.hh"
41 
42 #include "G4Material.hh"
43 #include "G4NistManager.hh"
44 
45 #include "G4FieldManager.hh"
46 #include "G4UniformMagField.hh"
48 
49 #include "G4GeometryManager.hh"
50 
51 #include "G4SolidStore.hh"
52 #include "G4RegionStore.hh"
53 #include "G4LogicalVolumeStore.hh"
54 #include "G4PhysicalVolumeStore.hh"
55 
56 #include "G4RunManager.hh"
57 
58 #include "G4PhysicalConstants.hh"
59 #include "G4SystemOfUnits.hh"
60 
62 #include "F04DetectorMessenger.hh"
63 #include "F04Materials.hh"
64 
65 #include "G4RotationMatrix.hh"
66 
67 #include "F04SimpleSolenoid.hh"
68 #include "F04FocusSolenoid.hh"
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
73  : fSolidWorld(0), fLogicWorld(0), fPhysiWorld(0),
74  fSolidTarget(0), fLogicTarget(0), fPhysiTarget(0),
75  fSolidDegrader(0), fLogicDegrader(0), fPhysiDegrader(0),
76  fSolidCaptureMgnt(0), fLogicCaptureMgnt(0), fPhysiCaptureMgnt(0),
77  fSolidTransferMgnt(0), fLogicTransferMgnt(0), fPhysiTransferMgnt(0),
78  fWorldMaterial(0), fTargetMaterial(0), fDegraderMaterial(0),
79  fFocusSolenoid(0), fSimpleSolenoid(0)
80 {
81  fWorldSizeZ = 50.*m;
82  fWorldSizeR = 5.*m;
83 
84  fTargetRadius = 0.4*cm;
85  fTargetThickness = 16.0*cm;
86 
87  SetTargetAngle(170);
88 
89  fDegraderRadius = 30.0*cm;
90  fDegraderThickness = 0.1*cm;
91 
92  fCaptureMgntRadius = 0.6*m;
93  fCaptureMgntLength = 4.0*m;
94 
97 
98  fTransferMgntRadius = 0.3*m;
99  fTransferMgntLength = 15.0*m;
100 
101  SetTransferMgntB(5.0*tesla);
102 
103  fDegraderPos = -fTransferMgntLength/2. + fDegraderThickness/2.;
104 
105  // ensure the global field is initialized
107 
108  fDetectorMessenger = new F04DetectorMessenger(this);
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112 
114 {
115  delete fDetectorMessenger;
116 }
117 
118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119 
121 {
122  fMaterials = F04Materials::GetInstance();
123 
124  DefineMaterials();
125 
126  return ConstructDetector();
127 }
128 
129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
130 
131 void F04DetectorConstruction::DefineMaterials()
132 {
133  //define materials for the experiment
134 
135  fVacuum = fMaterials->GetMaterial("G4_Galactic");
136 
137  fWorldMaterial = fMaterials->GetMaterial("G4_AIR");
138  fDegraderMaterial = fMaterials->GetMaterial("G4_Pb");
139  fTargetMaterial = fMaterials->GetMaterial("G4_W");
140 }
141 
142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
143 
145 {
146  fSolidWorld = new G4Tubs("World",
147  0.,GetWorldSizeR(),GetWorldSizeZ()/2.,0.,twopi);
148 
149  fLogicWorld = new G4LogicalVolume(fSolidWorld,
151  "World");
152 
153  fPhysiWorld = new G4PVPlacement(0,
154  G4ThreeVector(),
155  "World",
156  fLogicWorld,
157  0,
158  false,
159  0);
160 
161  // Capture Magnet
162 
163  fSolidCaptureMgnt = new G4Tubs("CaptureMgnt",
165  GetCaptureMgntLength()/2.,0.,twopi);
166 
167  fLogicCaptureMgnt = new G4LogicalVolume(fSolidCaptureMgnt,
168  fVacuum,
169  "CaptureMgnt");
170 
171  G4ThreeVector captureMgntCenter = G4ThreeVector();
172 
173  fPhysiCaptureMgnt = new G4PVPlacement(0,
174  captureMgntCenter,
175  "CaptureMgnt",
176  fLogicCaptureMgnt,
177  fPhysiWorld,
178  false,
179  0);
180 
181  // Transfer Magnet
182 
183  fSolidTransferMgnt = new G4Tubs("TransferMgnt",
185  GetTransferMgntLength()/2.,0.,twopi);
186 
187  fLogicTransferMgnt = new G4LogicalVolume(fSolidTransferMgnt,
188  fVacuum,
189  "TransferMgnt");
190 
192  + GetTransferMgntPos();
194 
195  G4ThreeVector transferMgntCenter = G4ThreeVector(x,0.,z);
196 
197  G4RotationMatrix* g4rot = new G4RotationMatrix();
198  *g4rot = StringToRotationMatrix("Y30,X10");
199  *g4rot = g4rot->inverse();
200  if (*g4rot == G4RotationMatrix()) g4rot = NULL;
201 
202  fPhysiTransferMgnt = new G4PVPlacement(g4rot,
203  transferMgntCenter,
204  "TransferMgnt",
205  fLogicTransferMgnt,
206  fPhysiWorld,
207  false,
208  0);
209 
210  // Test Plane
211 
212  G4Tubs* solidTestPlane = new G4Tubs("TestPlane",
214  1.*mm,0.,twopi);
215 
216  G4LogicalVolume* logicTestPlane = new G4LogicalVolume(solidTestPlane,
217  fVacuum,
218  "TestPlane");
219 
220  z = GetTransferMgntLength()/2. - 1.*mm;
221 
222  G4ThreeVector testPlaneCenter = G4ThreeVector(0.,0.,z);
223 
224  new G4PVPlacement(0,
225  testPlaneCenter,
226  "TestPlane",
227  logicTestPlane,
228  fPhysiTransferMgnt,
229  false,
230  0);
231 
232  // Target
233 
234  if (GetTargetThickness() > 0.)
235  {
236  fSolidTarget = new G4Tubs("Target",
237  0.,GetTargetRadius(),
238  GetTargetThickness()/2.,0.,twopi);
239 
240  fLogicTarget = new G4LogicalVolume(fSolidTarget,
242  "Target");
243 
244  G4int i = GetTargetAngle();
245 
246  char c[4];
247  sprintf(c,"%d",i);
248  G4String angle = c;
249  angle = angle.strip(G4String::both,' ');
250  angle = "Y" + angle;
251 
252  g4rot = new G4RotationMatrix();
253  *g4rot = StringToRotationMatrix(angle);
254  *g4rot = g4rot->inverse();
255  if (*g4rot == G4RotationMatrix()) g4rot = NULL;
256 
257  G4ThreeVector targetCenter(0.,0.,GetTargetPos());
258 
259  fPhysiTarget = new G4PVPlacement(g4rot,
260  targetCenter,
261  "Target",
262  fLogicTarget,
263  fPhysiCaptureMgnt,
264  false,
265  0);
266  }
267 
268  // Degrader
269 
270  if (GetDegraderThickness() > 0.)
271  {
272  fSolidDegrader = new G4Tubs("Degrader",
273  0., GetDegraderRadius(),
274  GetDegraderThickness()/2., 0.,twopi);
275 
276  fLogicDegrader = new G4LogicalVolume(fSolidDegrader,
278  "Degrader");
279 
280  G4ThreeVector degraderCenter = G4ThreeVector(0.,0.,GetDegraderPos());
281 
282  fPhysiDegrader = new G4PVPlacement(0,
283  degraderCenter,
284  "Degrader",
285  fLogicDegrader,
286  fPhysiTransferMgnt,
287  false,
288  0);
289  }
290 
291  G4double l = 0.0;
292  G4double B1 = GetCaptureMgntB1();
293  G4double B2 = GetCaptureMgntB2();
294 
295  if (fFocusSolenoid) delete fFocusSolenoid;
296  fFocusSolenoid = new F04FocusSolenoid(B1, B2, l,
297  fLogicCaptureMgnt,captureMgntCenter);
298  fFocusSolenoid -> SetHalf(true);
299 
300  l = 0.0;
302 
303  if (fSimpleSolenoid) delete fSimpleSolenoid;
304  fSimpleSolenoid = new F04SimpleSolenoid(B, l,
305  fLogicTransferMgnt,transferMgntCenter);
306 
307  fSimpleSolenoid->SetColor("1,0,1");
308  fSimpleSolenoid->SetColor("0,1,1");
309  fSimpleSolenoid->SetMaxStep(1.5*mm);
310  fSimpleSolenoid->SetMaxStep(2.5*mm);
311 
312  return fPhysiWorld;
313 }
314 
315 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
316 
318 {
319  G4Material* pttoMaterial =
320  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
321 
322  if (pttoMaterial != fWorldMaterial) {
323  if ( pttoMaterial ) {
324  fWorldMaterial = pttoMaterial;
325  } else {
326  G4cout << "\n--> WARNING from SetWorldMaterial : "
327  << materialChoice << " not found" << G4endl;
328  }
329  }
330 }
331 
332 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
333 
335 {
336  G4Material* pttoMaterial =
337  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
338 
339  if (pttoMaterial != fTargetMaterial) {
340  if ( pttoMaterial ) {
341  fTargetMaterial = pttoMaterial;
342  } else {
343  G4cout << "\n--> WARNING from SetTargetMaterial : "
344  << materialChoice << " not found" << G4endl;
345  }
346  }
347 }
348 
349 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
350 
352 
353 {
354  G4Material* pttoMaterial =
355  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
356 
357  if (pttoMaterial != fDegraderMaterial) {
358  if ( pttoMaterial ) {
359  fDegraderMaterial = pttoMaterial;
360  } else {
361  G4cout << "\n--> WARNING from SetDegraderMaterial : "
362  << materialChoice << " not found" << G4endl;
363  }
364  }
365 }
366 
367 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
368 
370 {
371  fWorldSizeZ = val;
372 }
373 
374 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
375 
377 {
378  fWorldSizeR = val;
379 }
380 
381 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
382 
384 {
385  fCaptureMgntRadius = val;
386 }
387 
388 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
389 
391 {
392  fCaptureMgntLength = val;
393 }
394 
395 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
396 
398 {
399  fCaptureMgntB1 = val;
400 }
401 
402 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
403 
405 {
406  fCaptureMgntB2 = val;
407 }
408 
409 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
410 
412 {
413  fTransferMgntRadius = val;
414 }
415 
416 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
417 
419 {
420  fTransferMgntLength = val;
421 }
422 
423 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
424 
426 {
427  fTransferMgntB = val;
428 }
429 
430 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
431 
433 {
434  fTransferMgntPos = val;
435 }
436 
437 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
438 
440 {
441  fTargetRadius = val;
442 }
443 
444 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
445 
447 {
448  fTargetThickness = val;
449 }
450 
451 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
452 
454 {
455  fTargetPos = val;
456 }
457 
458 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
459 
461 {
462  fTargetAngle = val;
463 }
464 
465 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
466 
468 {
469  fDegraderRadius = val;
470 }
471 
472 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
473 
475 {
476  fDegraderThickness = val;
477 }
478 
479 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
480 
482 {
483  fDegraderPos = val;
484 }
485 
486 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
487 
489 {
490  if (!fPhysiWorld) return;
491 
492  // clean-up previous geometry
494 
498 
499  //define new one
501 
504 
506 
507 }
508 
509 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
510 
513 {
514  // We apply successive rotations OF THE OBJECT around the FIXED
515  // axes of the parent's local coordinates; rotations are applied
516  // left-to-right (rotation="r1,r2,r3" => r1 then r2 then r3).
517 
518  G4RotationMatrix rot;
519 
520  unsigned int place = 0;
521 
522  while (place < rotation.size()) {
523 
524  G4double angle;
525  char* p(0);
526  G4String current=rotation.substr(place+1);
527  angle = strtod(current.c_str(),&p) * deg;
528 
529  if (!p || (*p != ',' && *p != '\0')) {
530  G4cerr << "Invalid rotation specification: " <<
531  rotation.c_str() << G4endl;
532 
533  return rot;
534  }
535 
536  G4RotationMatrix thisRotation;
537 
538  switch(rotation.substr(place,1).c_str()[0]) {
539  case 'X': case 'x':
540  thisRotation = G4RotationMatrix(CLHEP::HepRotationX(angle));
541  break;
542  case 'Y': case 'y':
543  thisRotation = G4RotationMatrix(CLHEP::HepRotationY(angle));
544  break;
545  case 'Z': case 'z':
546  thisRotation = G4RotationMatrix(CLHEP::HepRotationZ(angle));
547  break;
548  default:
549  G4cerr << " Invalid rotation specification: "
550  << rotation << G4endl;
551  return rot;
552  }
553 
554  rot = thisRotation * rot;
555  place = rotation.find(',',place);
556  if (place > rotation.size()) break;
557  ++place;
558  }
559 
560  return rot;
561 
562 }