Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 08:30:56

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 OpNoviceGDMLDetectorConstruction.cc
0027 /// \brief Implementation of the OpNoviceGDMLDetectorConstruction class
0028 
0029 #include "OpNoviceGDMLDetectorConstruction.hh"
0030 
0031 #include "OpNoviceDetectorMessenger.hh"
0032 
0033 #include "G4GDMLParser.hh"
0034 #include "G4LogicalVolumeStore.hh"
0035 #include "G4NistManager.hh"
0036 #include "G4PhysicalVolumeStore.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4VisAttributes.hh"
0039 #include "globals.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 OpNoviceGDMLDetectorConstruction::OpNoviceGDMLDetectorConstruction(G4String fname)
0043   : G4VUserDetectorConstruction()
0044 {
0045   fGdmlFile = fname;
0046   // create a messenger for this class
0047   fDetectorMessenger = new OpNoviceDetectorMessenger(this);
0048 
0049   G4cout << "Building detector from GDML file: " << fname << G4endl << G4endl;
0050 }
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 OpNoviceGDMLDetectorConstruction::~OpNoviceGDMLDetectorConstruction()
0054 {
0055   delete fDetectorMessenger;
0056   delete fParser;
0057 }
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 G4VPhysicalVolume* OpNoviceGDMLDetectorConstruction::Construct()
0061 {
0062   ReadGDML();
0063   G4VPhysicalVolume* worldPhysVol = fParser->GetWorldVolume();
0064   if (fDumpGdml) fParser->Write(fDumpGdmlFileName, worldPhysVol);
0065   return worldPhysVol;
0066 }
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0069 void OpNoviceGDMLDetectorConstruction::ConstructSDandField() {}
0070 
0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0072 void OpNoviceGDMLDetectorConstruction::ReadGDML()
0073 {
0074   fParser = new G4GDMLParser();
0075   fParser->Read(fGdmlFile, false);
0076   G4VPhysicalVolume* world = fParser->GetWorldVolume();
0077   // GDML parser makes world invisible. make it visible again.
0078   G4LogicalVolume* pworldLogical = world->GetLogicalVolume();
0079   pworldLogical->SetVisAttributes(nullptr);
0080   G4cout << world->GetTranslation() << G4endl << G4endl;
0081   if (fVerbose) {
0082     G4cout << "Found world:  " << world->GetName() << G4endl;
0083     G4cout << "world LV:  " << world->GetLogicalVolume()->GetName() << G4endl;
0084   }
0085   G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
0086   if (fVerbose) {
0087     G4cout << "Found " << pLVStore->size() << " logical volumes." << G4endl << G4endl;
0088   }
0089   G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
0090   if (fVerbose) {
0091     G4cout << "Found " << pPVStore->size() << " physical volumes." << G4endl << G4endl;
0092   }
0093 }
0094 
0095 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0096 void OpNoviceGDMLDetectorConstruction::UpdateGeometry()
0097 {
0098   G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
0099 }
0100 
0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0102 void OpNoviceGDMLDetectorConstruction::SetDumpGdml(G4bool val)
0103 {
0104   fDumpGdml = val;
0105 }
0106 
0107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0108 G4bool OpNoviceGDMLDetectorConstruction::IsDumpGdml() const
0109 {
0110   return fDumpGdml;
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0114 void OpNoviceGDMLDetectorConstruction::SetVerbose(G4bool val)
0115 {
0116   fVerbose = val;
0117 }
0118 
0119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0120 G4bool OpNoviceGDMLDetectorConstruction::IsVerbose() const
0121 {
0122   return fVerbose;
0123 }
0124 
0125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0126 void OpNoviceGDMLDetectorConstruction::SetDumpGdmlFile(G4String val)
0127 {
0128   fDumpGdmlFileName = val;
0129 }
0130 
0131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0132 G4String OpNoviceGDMLDetectorConstruction::GetDumpGdmlFileName() const
0133 {
0134   return fDumpGdmlFileName;
0135 }