Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:22

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