Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:18

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 /// \file field/field04/src/F04ElementField.cc
0028 /// \brief Implementation of the F04ElementField class
0029 //
0030 
0031 #include "F04ElementField.hh"
0032 
0033 #include "F04GlobalField.hh"
0034 
0035 #include "G4SystemOfUnits.hh"
0036 #include "G4TouchableHandle.hh"
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 G4ThreadLocal G4Navigator* F04ElementField::fNavigator = nullptr;
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   //  fUserLimits->SetUserMinRange(1*mm);
0054 
0055   fVolume->SetVisAttributes(GetVisAttribute(fColor));
0056   fVolume->SetUserLimits(fUserLimits);
0057 }
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   // set fGlobal2local transform
0081   fGlobal2local = touchable->GetHistory()->GetTopTransform();
0082 
0083   // set global bounding box
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 }