Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-03 09:21:23

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