source: trunk/examples/extended/field/field04/src/F04ElementField.cc@ 812

Last change on this file since 812 was 807, checked in by garnier, 17 years ago

update

File size: 4.7 KB
RevLine 
[807]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//
27//
28
29#include "G4GeometryManager.hh"
30
31#include "F04ElementField.hh"
32
33#include "F04GlobalField.hh"
34
35G4Navigator* F04ElementField::aNavigator;
36
37F04ElementField::F04ElementField(G4ThreeVector c, G4LogicalVolume* lv)
38{
39 center = c;
40
41 minX = minY = minZ = -DBL_MAX;
42 maxX = maxY = maxZ = DBL_MAX;
43
44 F04GlobalField::getObject()->addElementField(this);
45
46 color = "1,1,1";
47
48 userLimits = new G4UserLimits();
49
50 lvolume = lv;
51 lvolume->SetVisAttributes(getVisAttribute(color));
52
53 maxStep = 1*mm;
54
55 userLimits->SetMaxAllowedStep(maxStep);
56
57 userLimits->SetUserMaxTrackLength(500.*m);
58 userLimits->SetUserMaxTime(10*ms);
59 userLimits->SetUserMinEkine(0.1*MeV);
60// userLimits->SetUserMinRange(1*mm);
61
62 lvolume->SetUserLimits(userLimits);
63}
64
65void F04ElementField::construct()
66{
67 G4Navigator* theNavigator =
68 G4TransportationManager::GetTransportationManager()->
69 GetNavigatorForTracking();
70
71 if (!aNavigator) {
72 aNavigator = new G4Navigator();
73 if ( theNavigator->GetWorldVolume() )
74 aNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
75 }
76
77 G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
78
79 if (!geomManager->IsGeometryClosed()) {
80 geomManager->OpenGeometry();
81 geomManager->CloseGeometry(true);
82 }
83
84 aNavigator->LocateGlobalPointAndSetup(center,0,false);
85
86 G4TouchableHistoryHandle fTouchable = aNavigator->
87 CreateTouchableHistoryHandle();
88
89 G4int depth = fTouchable->GetHistoryDepth();
90 for (G4int i = 0; i<depth; ++i) {
91 if(fTouchable->GetVolume()->GetLogicalVolume() == lvolume)break;
92 fTouchable->MoveUpHistory();
93 }
94
95 // set global2local transform
96 global2local = fTouchable->GetHistory()->GetTopTransform();
97
98 // set global bounding box
99 G4double local[4], global[4];
100
101 G4ThreeVector globalPosition;
102 local[3] = 0.0;
103 for (int i=0; i<2; ++i) {
104 local[0] = (i==0 ? -1.0 : 1.0) * getWidth()/2.;
105 for (int j=0; j<2; ++j) {
106 local[1] = (j==0 ? -1.0 : 1.0) * getHeight()/2.;
107 for (int k=0; k<2; ++k) {
108 local[2] = (k==0 ? -1.0 : 1.0) * getLength()/2.;
109 G4ThreeVector localPosition(local[0],local[1],local[2]);
110 globalPosition =
111 global2local.Inverse().TransformPoint(localPosition);
112 global[0] = globalPosition.x();
113 global[1] = globalPosition.y();
114 global[2] = globalPosition.z();
115 setGlobalPoint(global);
116 }
117 }
118 }
119}
120
121G4VisAttributes* F04ElementField::getVisAttribute(G4String color)
122{
123 G4VisAttributes* p = NULL;
124 if(color.size() > 0 &&
125 (isdigit(color.c_str()[0]) || color.c_str()[0] == '.')) {
126 G4double red=0.0, green=0.0, blue=0.0;
127 if (sscanf(color.c_str(),"%lf,%lf,%lf",&red,&green,&blue) == 3) {
128 p = new G4VisAttributes(true,G4Color(red,green,blue));
129 } else {
130 G4cout << " Invalid color " << color << G4endl;
131 }
132 }
133
134 if (!p) p = new G4VisAttributes(G4VisAttributes::Invisible);
135 p->SetDaughtersInvisible(false);
136
137 return p;
138}
Note: See TracBrowser for help on using the repository browser.