Back to home page

EIC code displayed by LXR

 
 

    


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

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