Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-14 07:53: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 #include "DetectorConstruction.hh"
0030 
0031 #include "DetectorMessenger.hh"
0032 
0033 #include "G4Box.hh"
0034 #include "G4GeometryManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4Material.hh"
0038 #include "G4MonopoleFieldSetup.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4PVPlacement.hh"
0041 #include "G4PhysicalVolumeStore.hh"
0042 #include "G4SolidStore.hh"
0043 #include "G4StateManager.hh"
0044 #include "G4UniformMagField.hh"
0045 #include "G4UnitsTable.hh"
0046 #include "G4UserLimits.hh"
0047 // #include "G4FieldManager.hh"
0048 // #include "G4TransportationManager.hh"
0049 #include "G4AutoDelete.hh"
0050 #include "G4GlobalMagFieldMessenger.hh"
0051 #include "G4RunManager.hh"
0052 #include "G4SystemOfUnits.hh"
0053 #include "G4ThreeVector.hh"
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 DetectorConstruction::DetectorConstruction()
0058   : G4VUserDetectorConstruction(),
0059     fWorldMaterial(0),
0060     fAbsorMaterial(0),
0061     fLogAbsor(0),
0062     fMonFieldSetup(),
0063     fDetectorMessenger(0)
0064 {
0065   // default parameter values
0066   fAbsorSizeX = fAbsorSizeYZ = 10 * cm;
0067   fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSizeX;
0068   fMaxStepSize = 5 * mm;
0069 
0070   SetMaterial("G4_Al");
0071   fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0072 
0073   // create commands for interactive definition of the detector
0074   fDetectorMessenger = new DetectorMessenger(this);
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0078 
0079 DetectorConstruction::~DetectorConstruction()
0080 {
0081   delete fDetectorMessenger;
0082   //  delete fMonFieldSetup;
0083 }
0084 
0085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0086 
0087 G4VPhysicalVolume* DetectorConstruction::Construct()
0088 {
0089   G4GeometryManager::GetInstance()->OpenGeometry();
0090   G4PhysicalVolumeStore::GetInstance()->Clean();
0091   G4LogicalVolumeStore::GetInstance()->Clean();
0092   G4SolidStore::GetInstance()->Clean();
0093 
0094   /****************************    World   *****************************/
0095   G4Box* sWorld = new G4Box("world", fWorldSizeX / 2, fWorldSizeYZ / 2, fWorldSizeYZ / 2);
0096 
0097   G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld, fWorldMaterial, "world");
0098 
0099   G4VPhysicalVolume* pWorld = new G4PVPlacement(0,  // no rotation
0100                                                 G4ThreeVector(),  // at (0,0,0)
0101                                                 lWorld,  // logical volume
0102                                                 "world",  // name
0103                                                 0,  // mother  volume
0104                                                 false,  // no boolean operation
0105                                                 0);  // copy number
0106 
0107   /**************************    Absorber    ***************************/
0108   G4Box* sAbsor = new G4Box("Absorber", fAbsorSizeX / 2, fAbsorSizeYZ / 2, fAbsorSizeYZ / 2);
0109 
0110   fLogAbsor = new G4LogicalVolume(sAbsor, fAbsorMaterial, "Absorber");
0111 
0112   new G4PVPlacement(0,  // no rotation
0113                     G4ThreeVector(),  // at (0,0,0)
0114                     fLogAbsor,  // logical volume
0115                     "Absorber",  // name
0116                     lWorld,  // mother  volume
0117                     false,  // no boolean operation
0118                     0);  // copy number
0119   fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize));
0120 
0121   PrintParameters();
0122 
0123   /************     always return the World volume     *****************/
0124   return pWorld;
0125 }
0126 
0127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0128 
0129 void DetectorConstruction::PrintParameters()
0130 {
0131   G4cout << "\n---------------------------------------------------------\n";
0132   G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeX, "Length") << " of "
0133          << fAbsorMaterial->GetName() << G4endl;
0134   G4cout << "\n---------------------------------------------------------\n";
0135 }
0136 
0137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0138 
0139 void DetectorConstruction::SetSizeX(G4double value)
0140 {
0141   if (value > 0.0) {
0142     fAbsorSizeX = value;
0143     fWorldSizeX = 1.2 * fAbsorSizeX;
0144     if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit) {
0145       G4RunManager::GetRunManager()->ReinitializeGeometry();
0146     }
0147   }
0148 }
0149 
0150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0151 
0152 void DetectorConstruction::SetSizeYZ(G4double value)
0153 {
0154   if (value > 0.0) {
0155     fAbsorSizeYZ = value;
0156     fWorldSizeYZ = 1.2 * fAbsorSizeYZ;
0157     if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit) {
0158       G4RunManager::GetRunManager()->ReinitializeGeometry();
0159     }
0160   }
0161 }
0162 
0163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0164 
0165 void DetectorConstruction::SetMaterial(const G4String& namemat)
0166 {
0167   // search the material by its name
0168   G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(namemat);
0169   if (!mat) {
0170     G4cout << "!!! DetectorConstruction::SetMaterial: WARNING Material <" << namemat
0171            << "> does not exist in DB" << G4endl;
0172     return;
0173   }
0174   // new material is found out
0175   if (mat != fAbsorMaterial) {
0176     fAbsorMaterial = mat;
0177     if (fLogAbsor) {
0178       fLogAbsor->SetMaterial(mat);
0179     }
0180     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0181   }
0182 }
0183 
0184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0185 
0186 void DetectorConstruction::ConstructSDandField()
0187 {
0188   // Define magnetic field
0189   if (!fMonFieldSetup.Get()) {
0190     G4MonopoleFieldSetup* fieldSetup = new G4MonopoleFieldSetup();
0191     G4AutoDelete::Register(fieldSetup);  // Kernel will delete the F01FieldSetup
0192     fMonFieldSetup.Put(fieldSetup);
0193   }
0194   fMonFieldSetup.Get()->ConstructMagField();  // add field value
0195 }
0196 
0197 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0198 
0199 void DetectorConstruction::SetMaxStepSize(G4double step)
0200 {
0201   fMaxStepSize = step;
0202   if (fLogAbsor) {
0203     fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize));
0204   }
0205 }
0206 
0207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......