File indexing completed on 2025-02-23 09:21:18
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
0030
0031 #include "F04ElementField.hh"
0032
0033 #include "F04GlobalField.hh"
0034
0035 #include "G4SystemOfUnits.hh"
0036 #include "G4TouchableHandle.hh"
0037
0038
0039
0040 G4ThreadLocal G4Navigator* F04ElementField::fNavigator = nullptr;
0041
0042
0043
0044 F04ElementField::F04ElementField(G4ThreeVector c, G4LogicalVolume* lv) : fVolume(lv), fCenter(c)
0045 {
0046 F04GlobalField::GetObject()->AddElementField(this);
0047
0048 fUserLimits = new G4UserLimits();
0049 fUserLimits->SetMaxAllowedStep(fMaxStep);
0050 fUserLimits->SetUserMaxTrackLength(500. * m);
0051 fUserLimits->SetUserMaxTime(10 * ms);
0052 fUserLimits->SetUserMinEkine(0.1 * MeV);
0053
0054
0055 fVolume->SetVisAttributes(GetVisAttribute(fColor));
0056 fVolume->SetUserLimits(fUserLimits);
0057 }
0058
0059
0060
0061 void F04ElementField::Construct()
0062 {
0063 G4Navigator* theNavigator =
0064 G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
0065 if (!fNavigator) {
0066 fNavigator = new G4Navigator();
0067 if (theNavigator->GetWorldVolume()) fNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
0068 }
0069
0070 fNavigator->LocateGlobalPointAndSetup(fCenter, nullptr, false);
0071
0072 G4TouchableHandle touchable = fNavigator->CreateTouchableHistoryHandle();
0073
0074 G4int depth = touchable->GetHistoryDepth();
0075 for (G4int i = 0; i < depth; ++i) {
0076 if (touchable->GetVolume()->GetLogicalVolume() == fVolume) break;
0077 touchable->MoveUpHistory();
0078 }
0079
0080
0081 fGlobal2local = touchable->GetHistory()->GetTopTransform();
0082
0083
0084 G4double local[4], global[4];
0085
0086 G4ThreeVector globalPosition;
0087 local[3] = 0.0;
0088 for (G4int i = 0; i < 2; ++i) {
0089 local[0] = (i == 0 ? -1.0 : 1.0) * GetWidth() / 2.;
0090 for (G4int j = 0; j < 2; ++j) {
0091 local[1] = (j == 0 ? -1.0 : 1.0) * GetHeight() / 2.;
0092 for (G4int k = 0; k < 2; ++k) {
0093 local[2] = (k == 0 ? -1.0 : 1.0) * GetLength() / 2.;
0094 G4ThreeVector localPosition(local[0], local[1], local[2]);
0095 globalPosition = fGlobal2local.Inverse().TransformPoint(localPosition);
0096 global[0] = globalPosition.x();
0097 global[1] = globalPosition.y();
0098 global[2] = globalPosition.z();
0099 SetGlobalPoint(global);
0100 }
0101 }
0102 }
0103 }
0104
0105
0106
0107 G4VisAttributes* F04ElementField::GetVisAttribute(G4String color)
0108 {
0109 G4VisAttributes* p = nullptr;
0110 if (color.size() > 0 && (isdigit(color.c_str()[0]) || color.c_str()[0] == '.')) {
0111 G4double red = 0.0, green = 0.0, blue = 0.0;
0112 if (sscanf(color.c_str(), "%lf,%lf,%lf", &red, &green, &blue) == 3) {
0113 p = new G4VisAttributes(true, G4Color(red, green, blue));
0114 }
0115 else {
0116 G4cout << " Invalid color " << color << G4endl;
0117 }
0118 }
0119
0120 if (!p) p = new G4VisAttributes(G4VisAttributes::GetInvisible());
0121 p->SetDaughtersInvisible(false);
0122
0123 return p;
0124 }