Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-10 08:06:17

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 //
0030 
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0033 
0034 #include "DetectorConstruction.hh"
0035 
0036 #include "DetectorMessenger.hh"
0037 #include "PrimaryGeneratorAction.hh"
0038 
0039 #include "G4Box.hh"
0040 #include "G4GeometryManager.hh"
0041 #include "G4LogicalVolume.hh"
0042 #include "G4LogicalVolumeStore.hh"
0043 #include "G4Material.hh"
0044 #include "G4NistManager.hh"
0045 #include "G4PVPlacement.hh"
0046 #include "G4PhysicalConstants.hh"
0047 #include "G4PhysicalVolumeStore.hh"
0048 #include "G4RunManager.hh"
0049 #include "G4SolidStore.hh"
0050 #include "G4SystemOfUnits.hh"
0051 #include "G4ThreeVector.hh"
0052 #include "G4Tubs.hh"
0053 #include "globals.hh"
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 DetectorConstruction::DetectorConstruction()
0058   : fMaterial(nullptr),
0059     fExperimentalHall_log(nullptr),
0060     fExperimentalHall_phys(nullptr),
0061     fLogicLayer(nullptr),
0062     fPhysiLayer(nullptr),
0063     fLogicScoringUpDown(nullptr),
0064     fPhysiScoringUpstream(nullptr),
0065     fPhysiScoringDownstream(nullptr),
0066     fLogicScoringSide(nullptr),
0067     fPhysiScoringSide(nullptr),
0068     fDetectorMessenger(nullptr),
0069     fThickness(2.0 * CLHEP::m),
0070     fDiameter(2.0 * CLHEP::m)  //***LOOKHERE*** Default values
0071 {
0072   fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");  //***LOOKHERE***
0073                                                                         // Default material
0074   fDetectorMessenger = new DetectorMessenger(this);
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0078 
0079 DetectorConstruction::~DetectorConstruction()
0080 {
0081   delete fDetectorMessenger;
0082 }
0083 
0084 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0085 
0086 G4VPhysicalVolume* DetectorConstruction::Construct()
0087 {
0088   return ConstructLayer();
0089 }
0090 
0091 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0092 
0093 G4VPhysicalVolume* DetectorConstruction::ConstructLayer()
0094 {
0095   // Clean old geometry, if any.
0096   G4GeometryManager::GetInstance()->OpenGeometry();
0097   G4PhysicalVolumeStore::GetInstance()->Clean();
0098   G4LogicalVolumeStore::GetInstance()->Clean();
0099   G4SolidStore::GetInstance()->Clean();
0100 
0101   // The target layer is a cylinder, with axis along the z-direction,
0102   // and positioned at the center, (0.0, 0.0, 0.0).
0103   // The world volume (experimental hall) is a box 20% bigger than the target layer,
0104   // and it is filled of "G4_Galactic" material.
0105 
0106   G4double expHall_x = 0.6 * fDiameter;  // half dimension along x : 20% bigger than the radius
0107                                          //                          of the target layer
0108   G4double expHall_y = 0.6 * fDiameter;  // half dimension along y : 20% bigger than the radius
0109                                          //                          of the target layer
0110   G4double expHall_z = 0.6 * fThickness;  // half dimension along z : 20% bigger than the half
0111                                           //                          thickness of the target layer
0112 
0113   G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0114 
0115   // Experimental hall
0116   G4Box* experimentalHall_box = new G4Box("expHall_box", expHall_x, expHall_y, expHall_z);
0117   fExperimentalHall_log = new G4LogicalVolume(experimentalHall_box,  // solid
0118                                               vacuum,  // material
0119                                               "expHall_log",  // name
0120                                               0,  // field manager
0121                                               0,  // sensitive detector
0122                                               0);  // user limits
0123   fExperimentalHall_phys = new G4PVPlacement(0,  // rotation
0124                                              G4ThreeVector(),  // translation
0125                                              "expHall",  // name
0126                                              fExperimentalHall_log,  // logical volume
0127                                              0,  // mother physical volume
0128                                              false,  // boolean operation
0129                                              0);  // copy number
0130 
0131   // Target
0132   G4Tubs* solidLayer = new G4Tubs("solidLayer",  // name
0133                                   0.0,  // inner radius
0134                                   0.5 * fDiameter,  // outer radius
0135                                   0.5 * fThickness,  // half cylinder length in z
0136                                   0.0,  // starting phi angle in rad
0137                                   2.0 * pi);  // final phi angle in rad
0138   fLogicLayer = new G4LogicalVolume(solidLayer,  // solid
0139                                     fMaterial,  // material
0140                                     "logicLayer",  // name
0141                                     0,  // field manager
0142                                     0,  // sensitive detector
0143                                     0);  // user limits
0144   fPhysiLayer = new G4PVPlacement(0,  // rotation
0145                                   G4ThreeVector(),  // translation
0146                                   "physiLayer",  // name
0147                                   fLogicLayer,  // logical volume
0148                                   fExperimentalHall_phys,  // mother physical volume
0149                                   false,  // boolean operation
0150                                   0);  // copy number
0151 
0152   // Three scoring volumes: one thin layer downstream of the target ("down")
0153   //                        one thin layer surrounding (lateral) of the target ("side")
0154   //                        one thin layer upstream of the target ("up")
0155   G4Tubs* solidScoringUpDown = new G4Tubs("solidScoringUpDown",  // name
0156                                           0.0,  // inner radius
0157                                           0.5 * fDiameter,  // outer radius
0158                                           0.5 * fScoringThickness,  // half cylinder length in z
0159                                           0.0,  // starting phi angle in rad
0160                                           2.0 * pi);  // final phi angle in rad
0161   fLogicScoringUpDown = new G4LogicalVolume(solidScoringUpDown,  // solid
0162                                             vacuum,  // material
0163                                             "logicScoringUpDown",  // name
0164                                             0,  // field manager
0165                                             0,  // sensitive detector
0166                                             0);  // user limits
0167   G4double zScoringUpDown = 0.5 * (fThickness + fScoringThickness);
0168   fPhysiScoringUpstream = new G4PVPlacement(0,  // rotation
0169                                             G4ThreeVector(0.0, 0.0, -zScoringUpDown),
0170                                             // translation
0171                                             "physiScoringUpstream",  // name
0172                                             fLogicScoringUpDown,  // logical volume
0173                                             fExperimentalHall_phys,  // mother physical volume
0174                                             false,  // boolean operation
0175                                             0);  // copy number
0176   fPhysiScoringDownstream = new G4PVPlacement(0,  // rotation
0177                                               G4ThreeVector(0.0, 0.0, zScoringUpDown),
0178                                               // translation
0179                                               "physiScoringDownstream",  // name
0180                                               fLogicScoringUpDown,  // logical volume
0181                                               fExperimentalHall_phys,  // mother physical volume
0182                                               false,  // boolean operation
0183                                               0);  // copy number
0184 
0185   G4Tubs* solidScoringSide = new G4Tubs("solidScoringSide",  // name
0186                                         0.5 * fDiameter,  // inner radius
0187                                         0.5 * fDiameter + fScoringThickness,  // outer radius
0188                                         0.5 * fThickness,  // half cylinder length in z
0189                                         0.0,  // starting phi angle in rad
0190                                         2.0 * pi);  // final phi angle in rad
0191   fLogicScoringSide = new G4LogicalVolume(solidScoringSide,  // solid
0192                                           vacuum,  // material
0193                                           "logicScoringSide",  // name
0194                                           0,  // field manager
0195                                           0,  // sensitive detector
0196                                           0);  // user limits
0197   fPhysiScoringSide = new G4PVPlacement(0,  // rotation
0198                                         G4ThreeVector(0.0, 0.0, 0.0),  // translation
0199                                         "physiScoringSide",  // name
0200                                         fLogicScoringSide,  // logical volume
0201                                         fExperimentalHall_phys,  // mother physical volume
0202                                         false,  // boolean operation
0203                                         0);  // copy number
0204 
0205   G4cout << G4endl << "DetectorConstruction::ConstructLayer() : " << G4endl
0206          << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;"
0207          << "\t y : -/+ " << expHall_y << " mm ;"
0208          << "\t z : -/+ " << expHall_z << " mm ;" << G4endl
0209          << "\t Target layer (cylinder) size: " << G4endl << "\t \t x : -/+ " << 0.5 * fDiameter
0210          << " mm ;"
0211          << "\t y : -/+ " << 0.5 * fDiameter << " mm ;"
0212          << "\t z : -/+ " << 0.5 * fThickness << " mm ;" << G4endl << G4endl << G4endl;
0213 
0214   return fExperimentalHall_phys;
0215 }
0216 
0217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0218 
0219 void DetectorConstruction::SetMaterial(const G4String name)
0220 {
0221   fMaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
0222   if (!fMaterial) {
0223     G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
0224            << G4endl << "     ===> the default  * G4_Fe *  will be used." << G4endl << G4endl;
0225     fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");
0226   }
0227   if (fLogicLayer) fLogicLayer->SetMaterial(fMaterial);
0228 }
0229 
0230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0231 
0232 void DetectorConstruction::UpdateGeometry()
0233 {
0234   G4RunManager::GetRunManager()->ReinitializeGeometry();
0235   PrintParameters();
0236   // Update also the position of the gun
0237   const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>(
0238     G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0239   if (pPrimaryAction) pPrimaryAction->SetGunPosition();
0240 }
0241 
0242 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0243 
0244 void DetectorConstruction::PrintParameters()
0245 {
0246   G4cout << G4endl << G4endl << " ------  DetectorConstruction::PrintParameters() ------ " << G4endl
0247          << " Material         = " << fMaterial->GetName() << G4endl
0248          << " Thickness        = " << fThickness << " mm" << G4endl
0249          << " Diameter         = " << fDiameter << " mm" << G4endl
0250          << " ScoringThickness = " << fScoringThickness << " mm" << G4endl
0251          << " ------------------------------------------------------ " << G4endl << G4endl;
0252 }
0253 
0254 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......