Back to home page

EIC code displayed by LXR

 
 

    


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 // * 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 /// \file F04ElementField.cc
0027 /// \brief Implementation of the F04ElementField class
0028 
0029 #include "F04ElementField.hh"
0030 
0031 #include "F04GlobalField.hh"
0032 
0033 #include "G4SystemOfUnits.hh"
0034 #include "G4TouchableHandle.hh"
0035 
0036 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0037 
0038 G4ThreadLocal G4Navigator* F04ElementField::fNavigator = nullptr;
0039 
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   //  fUserLimits->SetUserMinRange(1*mm);
0052 
0053   fVolume->SetVisAttributes(GetVisAttribute(fColor));
0054   fVolume->SetUserLimits(fUserLimits);
0055 }
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   // set fGlobal2local transform
0079   fGlobal2local = touchable->GetHistory()->GetTopTransform();
0080 
0081   // set global bounding box
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 }