Back to home page

EIC code displayed by LXR

 
 

    


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

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