Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:51:58

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 GB06ParallelWorldForSlices.cc
0027 /// \brief Implementation of the GB06ParallelWorldForSlices class
0028 
0029 #include "GB06ParallelWorldForSlices.hh"
0030 
0031 #include "GB06BOptrSplitAndKillByImportance.hh"
0032 
0033 #include "G4Box.hh"
0034 #include "G4LogicalVolume.hh"
0035 #include "G4LogicalVolumeStore.hh"
0036 #include "G4PVPlacement.hh"
0037 #include "G4PVReplica.hh"
0038 #include "G4PhysicalVolumeStore.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4ThreeVector.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 GB06ParallelWorldForSlices::GB06ParallelWorldForSlices(G4String worldName, G4bool bf)
0045   : G4VUserParallelWorld(worldName), fBiasingFlag(bf)
0046 {}
0047 
0048 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0049 
0050 GB06ParallelWorldForSlices::~GB06ParallelWorldForSlices()
0051 {
0052   ;
0053 }
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 void GB06ParallelWorldForSlices::Construct()
0058 {
0059   // -- Inform about construction:
0060   // -- (fWorldName is a protected data member of the base parallel world class)
0061   G4cout << "Parallel World `" << fWorldName << "' constructed." << G4endl;
0062 
0063   // -------------------------
0064   //  Build parallel geometry:
0065   // -------------------------
0066 
0067   // -- Obtain clone of mass geometry world from GetWorld() base class utility:
0068   G4VPhysicalVolume* physicalParallelWorld = GetWorld();
0069   G4LogicalVolume* logicalParallelWorld = physicalParallelWorld->GetLogicalVolume();
0070 
0071   // -- We overlay a sliced geometry on top of the block of concrete in the mass geometry
0072   // -- (ie, in the detector construction class), using the same dimensions.
0073   // -- [Note that this is a choice : we can use different dimensions and shapes, creating
0074   // -- a new solid for that.]
0075   // -- For this we:
0076   // --     - 1) get back the solid used to create the concrete shield;
0077   // --     - 2) create a new logical volume of same shape than the shield and we place
0078   // --          inside the slices
0079   // --     - 3) place the sliced structure, using the placement of the physical volume of
0080   // --          the concrete shield
0081   // -- In all this construction, no materials are used, as only the volumes boundaries
0082   // -- are of interest. Note that the absence of materials is only possible in parallel
0083   // -- geometries.
0084 
0085   // -- 1) get back the solid used to create the concrete shield:
0086   //       ------------------------------------------------------
0087 
0088   // -- get back the logical volume of the shield, using its name:
0089   G4LogicalVolume* shieldLogical = G4LogicalVolumeStore::GetInstance()->GetVolume("shield.logical");
0090 
0091   // -- get back the solid, a G4box in this case. We cast the pointer to access later on
0092   // -- the G4Box class specific methods:
0093   auto shieldSolid = (G4Box*)shieldLogical->GetSolid();
0094 
0095   // -- we now re-create a logical volume for the mother volume of the slices:
0096   auto motherForSlicesLogical = new G4LogicalVolume(shieldSolid,  // its solid
0097                                                     nullptr,  // no material
0098                                                     "motherForSlices.logical");  // its name
0099 
0100   // -- 2) new logical volume of same shape than the shield and place inside the slices:
0101   //       -----------------------------------------------------------------------------
0102 
0103   // -- We create now the slices; we choose 20 slices:
0104   const G4int nSlices(20);
0105   // -- the solid for slices:
0106   G4double halfSliceZ = shieldSolid->GetZHalfLength() / nSlices;
0107   auto sliceSolid = new G4Box("slice.solid", shieldSolid->GetXHalfLength(),
0108                               shieldSolid->GetYHalfLength(), halfSliceZ);
0109 
0110   // -- the logical volume for slices:
0111   sliceLogical = new G4LogicalVolume(sliceSolid,  // its solid
0112                                      nullptr,  // no material
0113                                      "slice.logical");  // its name
0114 
0115   // -- we use a replica, to place the 20 slices in one go, along the Z axis:
0116   slicePhysical = new G4PVReplica("slice.physical",  // its name
0117                                   sliceLogical,  // its logical volume
0118                                   motherForSlicesLogical,  // its mother volume
0119                                   kZAxis,  // axis of replication
0120                                   nSlices,  // number of replica
0121                                   2 * halfSliceZ);  // width of replica
0122 
0123   // -- 3) place the sliced structure, using the concrete shield placement:
0124   //       ----------------------------------------------------------------
0125 
0126   // -- get back the physical volume of the shield, using its name:
0127   // -- (note that we know we have only one physical volume with this name. If we had
0128   // -- several, we should loop by ourselves on the store which is of
0129   // -- std::vector<G4VPhysicalVolume*> type.)
0130   G4VPhysicalVolume* shieldPhysical =
0131     G4PhysicalVolumeStore::GetInstance()->GetVolume("shield.physical");
0132 
0133   // -- get back the translation
0134   // -- (we don't try to get back the rotation, we know we used nullptr):
0135   G4ThreeVector translation = shieldPhysical->GetObjectTranslation();
0136 
0137   // -- finally, we place the sliced structure:
0138   new G4PVPlacement(nullptr,  // no rotation
0139                     translation,  // translate as for the shield
0140                     motherForSlicesLogical,  // its logical volume
0141                     "motherForSlices.physical",  // its name
0142                     logicalParallelWorld,  // its mother  volume
0143                     false,  // no boolean operation
0144                     0);  // copy number
0145 }
0146 
0147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0148 
0149 void GB06ParallelWorldForSlices::ConstructSD()
0150 {
0151   if (fBiasingFlag) {
0152     // -- Create the biasing operator:
0153     auto biasingOperator = new GB06BOptrSplitAndKillByImportance("neutron", "parallelOptr");
0154     // -- Tell it it is active for this parallel geometry, passing the world
0155     // -- volume of this geometry :
0156     biasingOperator->SetParallelWorld(GetWorld());
0157 
0158     // -- Attach to the logical volume where the biasing has to be applied:
0159     biasingOperator->AttachTo(sliceLogical);
0160 
0161     // -- Create a simple "volume importance" map, linking replica numbers to importances:
0162     //    --------------------------------------------------------------------------------
0163     // -- we define the map as going from an importance to 2*importance when going from
0164     // -- a slice to the next one, in the Z direction.
0165     // -- Get back the replica of slices:
0166     G4int nReplica = slicePhysical->GetMultiplicity();
0167     // -- We use and fill the map we defined in the biasing operator:
0168     G4int importance = 1;
0169     for (G4int iReplica = 0; iReplica < nReplica; ++iReplica) {
0170       (biasingOperator->GetImportanceMap())[iReplica] = importance;
0171       importance *= 2;
0172     }
0173   }
0174 }