Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 07:50:31

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 DetectorConstruction.cc
0027 /// \brief Implementation of the DetectorConstruction class
0028 
0029 #include "DetectorConstruction.hh"
0030 
0031 #include "ChemistryWorld.hh"
0032 #include "PeriodicBoundaryBuilder.hh"
0033 #include "Scorer.hh"
0034 
0035 #include "G4Box.hh"
0036 #include "G4Electron_aq.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4MultiFunctionalDetector.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4PVPlacement.hh"
0041 #include "G4SDManager.hh"
0042 #include "G4UnitsTable.hh"
0043 #include "G4VPrimitiveScorer.hh"
0044 #include "G4VisAttributes.hh"
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 DetectorConstruction::DetectorConstruction() : G4VUserDetectorConstruction()
0049 {
0050   fpChemistryWorld = std::make_unique<ChemistryWorld>();
0051   fpChemistryWorld->ConstructChemistryBoundary();
0052   DefineCommands();
0053 }
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 G4VPhysicalVolume* DetectorConstruction::Construct()
0058 {
0059   auto water = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER");
0060   auto boudingBox = fpChemistryWorld->GetChemistryBoundary();
0061   G4double world_sizeXYZ = 2 * boudingBox->halfSideLengthInY();
0062 
0063   G4cout << "Volume size : " << G4BestUnit(world_sizeXYZ, "Length") << G4endl;
0064 
0065   G4double buffer;
0066   if (fPBC) {
0067     G4cout << "PeriodicBoundaryCondition is applied " << G4endl;
0068     buffer = 0.01 * nanometer;
0069   }
0070   else {
0071     buffer = 0;
0072     G4cout << "PeriodicBoundaryCondition is not applied " << G4endl;
0073   }
0074 
0075   auto solidWorld = new G4Box("World", 0.5 * (world_sizeXYZ - buffer),
0076                               0.5 * (world_sizeXYZ - buffer), 0.5 * (world_sizeXYZ - buffer));
0077 
0078   auto logicWorld = new G4LogicalVolume(solidWorld, water, "World");
0079 
0080   if (fPBC) {
0081     auto pbb = std::make_unique<PeriodicBoundaryBuilder>();
0082     fpPBCLogicVolume = pbb->Construct(logicWorld);
0083   }
0084 
0085   fpPhysWorld = new G4PVPlacement(nullptr,  // no rotation
0086                                   G4ThreeVector(),  // its position at (0,0,0)
0087                                   logicWorld,  // its logical volume
0088                                   "World",  // its name
0089                                   nullptr,  // its mother  volume
0090                                   false,  // no boolean operation
0091                                   0,  // copy number
0092                                   true);  // checking overlaps
0093 
0094   return fpPhysWorld;
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0098 
0099 void DetectorConstruction::ConstructSDandField()
0100 {
0101   G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
0102   auto mfDetector = new G4MultiFunctionalDetector("mfDetector");
0103   // the order of G4VPrimitiveScorer to define ID number
0104   G4VPrimitiveScorer* pDose = new Scorer<Dose>();
0105   dynamic_cast<Scorer<Dose>*>(pDose)->SetChemistryWorld(fpChemistryWorld.get());
0106   mfDetector->RegisterPrimitive(pDose);
0107   G4VPrimitiveScorer* gValues = new Scorer<Gvalues>();
0108   dynamic_cast<Scorer<Gvalues>*>(gValues)->SetChemistryWorld(fpChemistryWorld.get());
0109   mfDetector->RegisterPrimitive(gValues);
0110   G4SDManager::GetSDMpointer()->AddNewDetector(mfDetector);
0111   G4String SDName;
0112   if (fPBC) {
0113     SDName = fpPBCLogicVolume->GetName();
0114   }
0115   else {
0116     SDName = fpPhysWorld->GetName();
0117   }
0118   SetSensitiveDetector(SDName, mfDetector);
0119 }
0120 
0121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0122 
0123 void DetectorConstruction::DefineCommands()
0124 {
0125   fPBCMessenger =
0126     std::make_unique<G4GenericMessenger>(this, "/UHDR/Detector/", "Periodic Boundary Condition");
0127   auto& PBC = fPBCMessenger->DeclareProperty("PBC", fPBC);
0128   PBC.SetParameterName("PeriodicBoundaryCondition", true);
0129   PBC.SetDefaultValue("false");
0130 }
0131 
0132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....