Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F04ElementField.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 "G4GeometryManager.hh"
31 
32 #include "F04ElementField.hh"
33 
34 #include "F04GlobalField.hh"
35 
36 #include "G4SystemOfUnits.hh"
37 
38 G4Navigator* F04ElementField::fNavigator;
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41 
43 {
44  fCenter = c;
45 
46  fMinX = fMinY = fMinZ = -DBL_MAX;
47  fMaxX = fMaxY = fMaxZ = DBL_MAX;
48 
50 
51  fColor = "1,1,1";
52 
53  fUserLimits = new G4UserLimits();
54 
55  fVolume = lv;
57 
58  fMaxStep = 1*mm;
59 
60  fUserLimits->SetMaxAllowedStep(fMaxStep);
61 
62  fUserLimits->SetUserMaxTrackLength(500.*m);
63  fUserLimits->SetUserMaxTime(10*ms);
64  fUserLimits->SetUserMinEkine(0.1*MeV);
65 // fUserLimits->SetUserMinRange(1*mm);
66 
67  fVolume->SetUserLimits(fUserLimits);
68 }
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
73 {
74  G4Navigator* theNavigator =
76  GetNavigatorForTracking();
77 
78  if (!fNavigator) {
79  fNavigator = new G4Navigator();
80  if ( theNavigator->GetWorldVolume() )
81  fNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
82  }
83 
85 
86  if (!geomManager->IsGeometryClosed()) {
87  geomManager->OpenGeometry();
88  geomManager->CloseGeometry(true);
89  }
90 
91  fNavigator->LocateGlobalPointAndSetup(fCenter,0,false);
92 
93  G4TouchableHistoryHandle touchable = fNavigator->
94  CreateTouchableHistoryHandle();
95 
96  G4int depth = touchable->GetHistoryDepth();
97  for (G4int i = 0; i<depth; ++i) {
98  if(touchable->GetVolume()->GetLogicalVolume() == fVolume)break;
99  touchable->MoveUpHistory();
100  }
101 
102  // set fGlobal2local transform
103  fGlobal2local = touchable->GetHistory()->GetTopTransform();
104 
105  // set global bounding box
106  G4double local[4], global[4];
107 
108  G4ThreeVector globalPosition;
109  local[3] = 0.0;
110  for (int i=0; i<2; ++i) {
111  local[0] = (i==0 ? -1.0 : 1.0) * GetWidth()/2.;
112  for (int j=0; j<2; ++j) {
113  local[1] = (j==0 ? -1.0 : 1.0) * GetHeight()/2.;
114  for (int k=0; k<2; ++k) {
115  local[2] = (k==0 ? -1.0 : 1.0) * GetLength()/2.;
116  G4ThreeVector localPosition(local[0],local[1],local[2]);
117  globalPosition =
118  fGlobal2local.Inverse().TransformPoint(localPosition);
119  global[0] = globalPosition.x();
120  global[1] = globalPosition.y();
121  global[2] = globalPosition.z();
122  SetGlobalPoint(global);
123  }
124  }
125  }
126 }
127 
128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
129 
131 {
132  G4VisAttributes* p = NULL;
133  if(color.size() > 0 &&
134  (isdigit(color.c_str()[0]) || color.c_str()[0] == '.')) {
135  G4double red=0.0, green=0.0, blue=0.0;
136  if (sscanf(color.c_str(),"%lf,%lf,%lf",&red,&green,&blue) == 3) {
137  p = new G4VisAttributes(true,G4Color(red,green,blue));
138  } else {
139  G4cout << " Invalid color " << color << G4endl;
140  }
141  }
142 
144  p->SetDaughtersInvisible(false);
145 
146  return p;
147 }