Back to home page

EIC code displayed by LXR

 
 

    


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

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 VG01DetectorConstruction.cc
0028 /// \brief Implementation of the VG01DetectorConstruction class
0029 
0030 //  Authors:   J. Apostolakis & S. Wenzel (CERN)   2018-2021
0031 //
0032 //  Derived from FullCMS code by Mihaly Novak  (2017-18)
0033 
0034 #include "VG01DetectorConstruction.hh"
0035 
0036 #include "G4VecGeomConverter.h"
0037 #include "VG01DetectorMessenger.hh"
0038 
0039 #include "G4FieldManager.hh"
0040 #include "G4PropagatorInField.hh"
0041 #include "G4RunManager.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4TransportationManager.hh"
0044 #include "G4UniformMagField.hh"
0045 #include "G4VPhysicalVolume.hh"
0046 #include "G4VisAttributes.hh"
0047 #include "globals.hh"
0048 
0049 #include <VecGeom/management/GeoManager.h>
0050 
0051 G4double VG01DetectorConstruction::fglobFieldValue = 0.0;
0052 
0053 VG01DetectorConstruction::VG01DetectorConstruction()
0054   : G4VUserDetectorConstruction(),
0055     fWorld(nullptr),
0056     fFieldMgr(nullptr),
0057     fUniformMagField(nullptr),
0058     fDetectorMessenger(nullptr)
0059 {
0060   fGDMLFileName = "TestNTST.gdml";
0061   fDetectorMessenger = new VG01DetectorMessenger(this);
0062 }
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0065 
0066 VG01DetectorConstruction::~VG01DetectorConstruction()
0067 {
0068   delete fDetectorMessenger;
0069   if (fUniformMagField) {
0070     delete fUniformMagField;
0071   }
0072 }
0073 
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0075 
0076 G4VPhysicalVolume* VG01DetectorConstruction::Construct()
0077 {
0078   //  parser.SetOverlapCheck(true);
0079   G4TransportationManager* trMgr = G4TransportationManager::GetTransportationManager();
0080   assert(trMgr);
0081 
0082   fParser.Read(fGDMLFileName, false);
0083   fWorld = (G4VPhysicalVolume*)fParser.GetWorldVolume();
0084 
0085   // enabling 'check' mode in G4 Navigator
0086   G4Navigator* nav = trMgr->GetNavigatorForTracking();
0087   assert(nav);
0088   nav->CheckMode(true);
0089   // nav->SetVerboseLevel(1);
0090   std::cout << "Enabled Check mode in G4Navigator";
0091 
0092   // write back
0093   // fParser.Write("out.gdml", fWorld);
0094 
0095   fFieldMgr = trMgr->GetFieldManager();
0096   fWorld->GetLogicalVolume()->SetVisAttributes(G4VisAttributes::GetInvisible());
0097   if (fWorld == nullptr) {
0098     G4ExceptionDescription ed;
0099     ed << "World volume not set properly check your setup selection criteria"
0100        << "or GDML input!" << G4endl;
0101     G4Exception("VG01DetectorConstruction::Construct()", "G4VecGeomNavExtExample_0001",
0102                 FatalException, ed);
0103   }
0104   CreateMagFieldAndIntegrator();
0105 
0106   if (fUseVecGeom) {
0107     // This is converting the geometry to VecGeom and implicitely also setting
0108     // the navigator; We should pull this out really
0109     G4VecGeomConverter::Instance().SetVerbose(1);
0110     G4VecGeomConverter::Instance().ConvertG4Geometry(fWorld);
0111     G4cout << vecgeom::GeoManager::Instance().getMaxDepth() << "\n";
0112   }
0113   return fWorld;
0114 }
0115 
0116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0117 
0118 void VG01DetectorConstruction::CreateMagFieldAndIntegrator()
0119 {
0120   delete fUniformMagField;
0121 
0122   if (std::abs(fglobFieldValue) > 0.0) {
0123     // Apply a global uniform magnetic field along the Z axis.
0124     // Note:  only when the magnetic field (pointer) is NOT zero,
0125     //        does the Geant4 transportion in field get activated.
0126     fUniformMagField = new G4UniformMagField(G4ThreeVector(0.0, 0.0, fglobFieldValue));
0127     fFieldMgr->SetDetectorField(fUniformMagField);
0128     fFieldMgr->CreateChordFinder(fUniformMagField);
0129     G4cout << G4endl << " *** SETTING MAGNETIC FIELD in Z direction : fieldValue = "
0130            << fglobFieldValue / tesla << " tesla *** " << G4endl << G4endl;
0131   }
0132   else {
0133     fFieldMgr->SetDetectorField(nullptr);
0134     G4cout << G4endl << " *** NO MAGNETIC FIELD SET  *** " << G4endl << G4endl;
0135   }
0136 }