Warning, file /geant4/examples/extended/field/field04/src/F04ElementField.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "F04ElementField.hh"
0030
0031 #include "F04GlobalField.hh"
0032
0033 #include "G4SystemOfUnits.hh"
0034 #include "G4TouchableHandle.hh"
0035
0036
0037
0038 G4ThreadLocal G4Navigator* F04ElementField::fNavigator = nullptr;
0039
0040
0041
0042 F04ElementField::F04ElementField(G4ThreeVector c, G4LogicalVolume* lv) : fVolume(lv), fCenter(c)
0043 {
0044 F04GlobalField::GetObject()->AddElementField(this);
0045
0046 fUserLimits = new G4UserLimits();
0047 fUserLimits->SetMaxAllowedStep(fMaxStep);
0048 fUserLimits->SetUserMaxTrackLength(500. * m);
0049 fUserLimits->SetUserMaxTime(10 * ms);
0050 fUserLimits->SetUserMinEkine(0.1 * MeV);
0051
0052
0053 fVolume->SetVisAttributes(GetVisAttribute(fColor));
0054 fVolume->SetUserLimits(fUserLimits);
0055 }
0056
0057
0058
0059 void F04ElementField::Construct()
0060 {
0061 G4Navigator* theNavigator =
0062 G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
0063 if (!fNavigator) {
0064 fNavigator = new G4Navigator();
0065 if (theNavigator->GetWorldVolume()) fNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
0066 }
0067
0068 fNavigator->LocateGlobalPointAndSetup(fCenter, nullptr, false);
0069
0070 G4TouchableHandle touchable = fNavigator->CreateTouchableHistoryHandle();
0071
0072 G4int depth = touchable->GetHistoryDepth();
0073 for (G4int i = 0; i < depth; ++i) {
0074 if (touchable->GetVolume()->GetLogicalVolume() == fVolume) break;
0075 touchable->MoveUpHistory();
0076 }
0077
0078
0079 fGlobal2local = touchable->GetHistory()->GetTopTransform();
0080
0081
0082 G4double local[4], global[4];
0083
0084 G4ThreeVector globalPosition;
0085 local[3] = 0.0;
0086 for (G4int i = 0; i < 2; ++i) {
0087 local[0] = (i == 0 ? -1.0 : 1.0) * GetWidth() / 2.;
0088 for (G4int j = 0; j < 2; ++j) {
0089 local[1] = (j == 0 ? -1.0 : 1.0) * GetHeight() / 2.;
0090 for (G4int k = 0; k < 2; ++k) {
0091 local[2] = (k == 0 ? -1.0 : 1.0) * GetLength() / 2.;
0092 G4ThreeVector localPosition(local[0], local[1], local[2]);
0093 globalPosition = fGlobal2local.Inverse().TransformPoint(localPosition);
0094 global[0] = globalPosition.x();
0095 global[1] = globalPosition.y();
0096 global[2] = globalPosition.z();
0097 SetGlobalPoint(global);
0098 }
0099 }
0100 }
0101 }
0102
0103
0104
0105 G4VisAttributes* F04ElementField::GetVisAttribute(G4String color)
0106 {
0107 G4VisAttributes* p = nullptr;
0108 if (color.size() > 0 && (isdigit(color.c_str()[0]) || color.c_str()[0] == '.')) {
0109 G4double red = 0.0, green = 0.0, blue = 0.0;
0110 if (sscanf(color.c_str(), "%lf,%lf,%lf", &red, &green, &blue) == 3) {
0111 p = new G4VisAttributes(true, G4Color(red, green, blue));
0112 }
0113 else {
0114 G4cout << " Invalid color " << color << G4endl;
0115 }
0116 }
0117
0118 if (!p) p = new G4VisAttributes(G4VisAttributes::GetInvisible());
0119 p->SetDaughtersInvisible(false);
0120
0121 return p;
0122 }