Geant4_10
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 //
26 // $Id: F04DetectorConstruction.cc 77884 2013-11-29 08:41:11Z gcosmo $
27 //
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "globals.hh"
35 
37 #include "F04DetectorMessenger.hh"
38 
39 #include "G4Tubs.hh"
40 #include "G4LogicalVolume.hh"
41 #include "G4PVPlacement.hh"
42 
43 #include "G4Material.hh"
44 #include "G4NistManager.hh"
45 
46 #include "F04GlobalField.hh"
47 
48 #include "G4GeometryManager.hh"
49 
50 #include "G4SolidStore.hh"
51 #include "G4RegionStore.hh"
52 #include "G4LogicalVolumeStore.hh"
53 #include "G4PhysicalVolumeStore.hh"
54 
55 #include "G4RunManager.hh"
56 
57 #include "G4PhysicalConstants.hh"
58 #include "G4SystemOfUnits.hh"
59 
60 #include "F04Materials.hh"
61 
62 #include "G4RotationMatrix.hh"
63 
64 #include "F04SimpleSolenoid.hh"
65 #include "F04FocusSolenoid.hh"
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
69 G4ThreadLocal F04GlobalField* F04DetectorConstruction::fField = 0;
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
72 
74  : fSolidWorld(0), fLogicWorld(0), fPhysiWorld(0),
75  fSolidTarget(0), fLogicTarget(0), fPhysiTarget(0),
76  fSolidDegrader(0), fLogicDegrader(0), fPhysiDegrader(0),
77  fSolidCaptureMgnt(0), fLogicCaptureMgnt(0), fPhysiCaptureMgnt(0),
78  fSolidTransferMgnt(0), fLogicTransferMgnt(0), fPhysiTransferMgnt(0),
79  fWorldMaterial(0), fTargetMaterial(0), fDegraderMaterial(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  fDetectorMessenger = new F04DetectorMessenger(this);
106 }
107 
108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109 
111 {
112 // delete fField;
113  delete fDetectorMessenger;
114 }
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117 
119 {
120  fMaterials = F04Materials::GetInstance();
121 
122  DefineMaterials();
123 
124  return ConstructDetector();
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 
129 void F04DetectorConstruction::DefineMaterials()
130 {
131  //define materials for the experiment
132 
133  fVacuum = fMaterials->GetMaterial("G4_Galactic");
134 
135  fWorldMaterial = fMaterials->GetMaterial("G4_AIR");
136  fDegraderMaterial = fMaterials->GetMaterial("G4_Pb");
137  fTargetMaterial = fMaterials->GetMaterial("G4_W");
138 }
139 
140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
141 
143 {
144  fSolidWorld = new G4Tubs("World",
145  0.,GetWorldSizeR(),GetWorldSizeZ()/2.,0.,twopi);
146 
147  fLogicWorld = new G4LogicalVolume(fSolidWorld,
149  "World");
150 
151  fPhysiWorld = new G4PVPlacement(0,
152  G4ThreeVector(),
153  "World",
154  fLogicWorld,
155  0,
156  false,
157  0);
158 
159  // Capture Magnet
160 
161  fSolidCaptureMgnt = new G4Tubs("CaptureMgnt",
163  GetCaptureMgntLength()/2.,0.,twopi);
164 
165  fLogicCaptureMgnt = new G4LogicalVolume(fSolidCaptureMgnt,
166  fVacuum,
167  "CaptureMgnt");
168 
169  fCaptureMgntCenter = G4ThreeVector();
170 
171  fPhysiCaptureMgnt = new G4PVPlacement(0,
172  fCaptureMgntCenter,
173  "CaptureMgnt",
174  fLogicCaptureMgnt,
175  fPhysiWorld,
176  false,
177  0);
178 
179  // Transfer Magnet
180 
181  fSolidTransferMgnt = new G4Tubs("TransferMgnt",
183  GetTransferMgntLength()/2.,0.,twopi);
184 
185  fLogicTransferMgnt = new G4LogicalVolume(fSolidTransferMgnt,
186  fVacuum,
187  "TransferMgnt");
188 
190  + GetTransferMgntPos();
192 
193  fTransferMgntCenter = G4ThreeVector(x,0.,z);
194 
195  G4RotationMatrix* g4rot = new G4RotationMatrix();
196  *g4rot = StringToRotationMatrix("Y30,X10");
197  *g4rot = g4rot->inverse();
198  if (*g4rot == G4RotationMatrix()) g4rot = NULL;
199 
200  fPhysiTransferMgnt = new G4PVPlacement(g4rot,
201  fTransferMgntCenter,
202  "TransferMgnt",
203  fLogicTransferMgnt,
204  fPhysiWorld,
205  false,
206  0);
207 
208  // Test Plane
209 
210  G4Tubs* solidTestPlane = new G4Tubs("TestPlane",
212  1.*mm,0.,twopi);
213 
214  G4LogicalVolume* logicTestPlane = new G4LogicalVolume(solidTestPlane,
215  fVacuum,
216  "TestPlane");
217 
218  z = GetTransferMgntLength()/2. - 1.*mm;
219 
220  G4ThreeVector testPlaneCenter = G4ThreeVector(0.,0.,z);
221 
222  new G4PVPlacement(0,
223  testPlaneCenter,
224  "TestPlane",
225  logicTestPlane,
226  fPhysiTransferMgnt,
227  false,
228  0);
229 
230  // Target
231 
232  if (GetTargetThickness() > 0.)
233  {
234  fSolidTarget = new G4Tubs("Target",
235  0.,GetTargetRadius(),
236  GetTargetThickness()/2.,0.,twopi);
237 
238  fLogicTarget = new G4LogicalVolume(fSolidTarget,
240  "Target");
241 
242  G4int i = GetTargetAngle();
243 
244  char c[4];
245  sprintf(c,"%d",i);
246  G4String angle = c;
247  angle = angle.strip(G4String::both,' ');
248  angle = "Y" + angle;
249 
250  g4rot = new G4RotationMatrix();
251  *g4rot = StringToRotationMatrix(angle);
252  *g4rot = g4rot->inverse();
253  if (*g4rot == G4RotationMatrix()) g4rot = NULL;
254 
255  G4ThreeVector targetCenter(0.,0.,GetTargetPos());
256 
257  fPhysiTarget = new G4PVPlacement(g4rot,
258  targetCenter,
259  "Target",
260  fLogicTarget,
261  fPhysiCaptureMgnt,
262  false,
263  0);
264  }
265 
266  // Degrader
267 
268  if (GetDegraderThickness() > 0.)
269  {
270  fSolidDegrader = new G4Tubs("Degrader",
271  0., GetDegraderRadius(),
272  GetDegraderThickness()/2., 0.,twopi);
273 
274  fLogicDegrader = new G4LogicalVolume(fSolidDegrader,
276  "Degrader");
277 
278  G4ThreeVector degraderCenter = G4ThreeVector(0.,0.,GetDegraderPos());
279 
280  fPhysiDegrader = new G4PVPlacement(0,
281  degraderCenter,
282  "Degrader",
283  fLogicDegrader,
284  fPhysiTransferMgnt,
285  false,
286  0);
287  }
288 
289  return fPhysiWorld;
290 }
291 
292 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
293 
295 {
296  G4Material* pttoMaterial =
297  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
298 
299  if (pttoMaterial != fWorldMaterial) {
300  if ( pttoMaterial ) {
301  fWorldMaterial = pttoMaterial;
302  } else {
303  G4cout << "\n--> WARNING from SetWorldMaterial : "
304  << materialChoice << " not found" << G4endl;
305  }
306  }
307 }
308 
309 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
310 
312 {
313  G4Material* pttoMaterial =
314  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
315 
316  if (pttoMaterial != fTargetMaterial) {
317  if ( pttoMaterial ) {
318  fTargetMaterial = pttoMaterial;
319  } else {
320  G4cout << "\n--> WARNING from SetTargetMaterial : "
321  << materialChoice << " not found" << G4endl;
322  }
323  }
324 }
325 
326 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
327 
329 
330 {
331  G4Material* pttoMaterial =
332  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
333 
334  if (pttoMaterial != fDegraderMaterial) {
335  if ( pttoMaterial ) {
336  fDegraderMaterial = pttoMaterial;
337  } else {
338  G4cout << "\n--> WARNING from SetDegraderMaterial : "
339  << materialChoice << " not found" << G4endl;
340  }
341  }
342 }
343 
344 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
345 
347 {
348  fWorldSizeZ = val;
349 }
350 
351 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
352 
354 {
355  fWorldSizeR = val;
356 }
357 
358 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
359 
361 {
362  fCaptureMgntRadius = val;
363 }
364 
365 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
366 
368 {
369  fCaptureMgntLength = val;
370 }
371 
372 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
373 
375 {
376  fCaptureMgntB1 = val;
377 }
378 
379 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
380 
382 {
383  fCaptureMgntB2 = val;
384 }
385 
386 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
387 
389 {
390  fTransferMgntRadius = val;
391 }
392 
393 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
394 
396 {
397  fTransferMgntLength = val;
398 }
399 
400 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
401 
403 {
404  fTransferMgntB = val;
405 }
406 
407 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
408 
410 {
411  fTransferMgntPos = val;
412 }
413 
414 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
415 
417 {
418  fTargetRadius = val;
419 }
420 
421 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
422 
424 {
425  fTargetThickness = val;
426 }
427 
428 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
429 
431 {
432  fTargetPos = val;
433 }
434 
435 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
436 
438 {
439  fTargetAngle = val;
440 }
441 
442 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
443 
445 {
446  fDegraderRadius = val;
447 }
448 
449 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
450 
452 {
453  fDegraderThickness = val;
454 }
455 
456 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
457 
459 {
460  fDegraderPos = val;
461 }
462 
463 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
464 
466 {
467  // ensure the global field is initialized
468  if (!fField)
469  {
470  fField = F04GlobalField::GetObject(this);
471 
472  G4double l = 0.0;
473  G4double B1 = GetCaptureMgntB1();
474  G4double B2 = GetCaptureMgntB2();
475 
476  F04FocusSolenoid* focusSolenoid =
477  new F04FocusSolenoid(B1, B2, l, fLogicCaptureMgnt,fCaptureMgntCenter);
478  focusSolenoid -> SetHalf(true);
479 
481 
482  F04SimpleSolenoid* simpleSolenoid =
483  new F04SimpleSolenoid(B, l,fLogicTransferMgnt,fTransferMgntCenter);
484  simpleSolenoid->SetColor("1,0,1");
485  simpleSolenoid->SetColor("0,1,1");
486  simpleSolenoid->SetMaxStep(1.5*mm);
487  simpleSolenoid->SetMaxStep(2.5*mm);
488 
489  FieldList* fields = fField->GetFields();
490 
491  if (fields) {
492  if (fields->size()>0) {
493  FieldList::iterator i;
494  for (i=fields->begin(); i!=fields->end(); ++i)
495  { (*i)->Construct(fPhysiWorld); }
496  }
497  }
498  }
499  else
500  {
501  FieldList* fields = fField->GetFields();
502 
503  if (fields) {
504  if (fields->size()>0) {
505  FieldList::iterator i;
506  for (i=fields->begin(); i!=fields->end(); ++i)
507  { (*i)->UpdateWorld(fPhysiWorld); }
508  }
509  }
510  }
511 }
512 
513 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
514 
516 {
517  if (!fPhysiWorld) return;
518 
519  // clean-up previous geometry
521 
525 
526  //define new one
528 
530 
532 
533 }
534 
535 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
536 
539 {
540  // We apply successive rotations OF THE OBJECT around the FIXED
541  // axes of the parent's local coordinates; rotations are applied
542  // left-to-right (rotation="r1,r2,r3" => r1 then r2 then r3).
543 
544  G4RotationMatrix rot;
545 
546  unsigned int place = 0;
547 
548  while (place < rotation.size()) {
549 
550  G4double angle;
551  char* p(0);
552  G4String current=rotation.substr(place+1);
553  angle = strtod(current.c_str(),&p) * deg;
554 
555  if (!p || (*p != ',' && *p != '\0')) {
556  G4cerr << "Invalid rotation specification: " <<
557  rotation.c_str() << G4endl;
558 
559  return rot;
560  }
561 
562  G4RotationMatrix thisRotation;
563 
564  switch(rotation.substr(place,1).c_str()[0]) {
565  case 'X': case 'x':
566  thisRotation = G4RotationMatrix(CLHEP::HepRotationX(angle));
567  break;
568  case 'Y': case 'y':
569  thisRotation = G4RotationMatrix(CLHEP::HepRotationY(angle));
570  break;
571  case 'Z': case 'z':
572  thisRotation = G4RotationMatrix(CLHEP::HepRotationZ(angle));
573  break;
574  default:
575  G4cerr << " Invalid rotation specification: "
576  << rotation << G4endl;
577  return rot;
578  }
579 
580  rot = thisRotation * rot;
581  place = rotation.find(',',place);
582  if (place > rotation.size()) break;
583  ++place;
584  }
585 
586  return rot;
587 
588 }
void SetMaxStep(G4double stp)
SetMaxStep(G4double) sets the max. step size.
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=0)
Definition of the F04Materials class.
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
G4VPhysicalVolume * ConstructDetector()
Definition of the F04GlobalField class.
G4String strip(G4int strip_Type=trailing, char c=' ')
const char * p
Definition: xmltok.h:285
Definition: G4Tubs.hh:84
static void Clean()
Definition: G4SolidStore.cc:79
tuple x
Definition: test.py:50
G4Material * GetMaterial(G4String)
Definition: F04Materials.cc:71
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
void SetColor(G4String c)
SetColor(G4String) sets the color.
HepRotation inverse() const
static G4PhysicalVolumeStore * GetInstance()
static G4RegionStore * GetInstance()
static F04GlobalField * GetObject()
Definition of the F04DetectorConstruction class.
virtual G4VPhysicalVolume * Construct()
G4GLOB_DLL std::ostream G4cout
std::vector< F04ElementField * > FieldList
Definition of the F04DetectorMessenger class.
void PhysicsHasBeenModified()
Definition of the F04FocusSolenoid class.
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
static G4GeometryManager * GetInstance()
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
static F04Materials * GetInstance()
Definition: F04Materials.cc:60
tuple z
Definition: test.py:28
Definition of the F04SimpleSolenoid class.
#define G4endl
Definition: G4ios.hh:61
void OpenGeometry(G4VPhysicalVolume *vol=0)
double G4double
Definition: G4Types.hh:76
tuple c
Definition: test.py:13
static G4RotationMatrix StringToRotationMatrix(G4String rotation)
FieldList * GetFields()
Return the list of Element Fields.
G4GLOB_DLL std::ostream G4cerr