Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 08:30:11

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 // DetectorConstruction
0032 //
0033 // Created: 31.01.2003 V.Ivanchenko
0034 //
0035 // Modified:
0036 // 04.06.2006 Adoptation of hadr01 (V.Ivanchenko)
0037 //
0038 ////////////////////////////////////////////////////////////////////////
0039 //
0040 
0041 #include "DetectorConstruction.hh"
0042 
0043 #include "DetectorMessenger.hh"
0044 #include "HistoManager.hh"
0045 #include "TargetSD.hh"
0046 
0047 #include "G4Colour.hh"
0048 #include "G4GeometryManager.hh"
0049 #include "G4LogicalVolume.hh"
0050 #include "G4LogicalVolumeStore.hh"
0051 #include "G4NistManager.hh"
0052 #include "G4PVPlacement.hh"
0053 #include "G4PhysicalConstants.hh"
0054 #include "G4PhysicalVolumeStore.hh"
0055 #include "G4RunManager.hh"
0056 #include "G4SDManager.hh"
0057 #include "G4SolidStore.hh"
0058 #include "G4SystemOfUnits.hh"
0059 #include "G4Tubs.hh"
0060 #include "G4UnitsTable.hh"
0061 #include "G4VisAttributes.hh"
0062 #include "G4ios.hh"
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0065 
0066 DetectorConstruction::DetectorConstruction()
0067   : G4VUserDetectorConstruction(),
0068     fRadius(10. * cm),
0069     fTargetMaterial(0),
0070     fWorldMaterial(0),
0071     fTargetSD(0),
0072     fLogicTarget(0),
0073     fLogicWorld(0),
0074     fDetectorMessenger(0)
0075 
0076 {
0077   fDetectorMessenger = new DetectorMessenger(this);
0078 
0079   fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
0080   fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0081   HistoManager::GetPointer()->SetTargetMaterial(fTargetMaterial);
0082 
0083   // Prepare sensitive detectors
0084   fTargetSD = new TargetSD("targetSD");
0085   G4SDManager::GetSDMpointer()->AddNewDetector(fTargetSD);
0086 }
0087 
0088 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0089 
0090 DetectorConstruction::~DetectorConstruction()
0091 {
0092   delete fDetectorMessenger;
0093 }
0094 
0095 G4VPhysicalVolume* DetectorConstruction::Construct()
0096 {
0097   // Cleanup old geometry
0098   G4GeometryManager::GetInstance()->OpenGeometry();
0099   G4PhysicalVolumeStore::GetInstance()->Clean();
0100   G4LogicalVolumeStore::GetInstance()->Clean();
0101   G4SolidStore::GetInstance()->Clean();
0102 
0103   // Sizes
0104   G4double checkR = fRadius + mm;
0105   G4double worldR = fRadius + cm;
0106   G4double targetZ = HistoManager::GetPointer()->Length() * 0.5;
0107   G4double checkZ = targetZ + mm;
0108   G4double worldZ = targetZ + cm;
0109 
0110   G4int nSlices = HistoManager::GetPointer()->NumberOfSlices();
0111   G4double sliceZ = targetZ / G4double(nSlices);
0112 
0113   //
0114   // World
0115   G4Tubs* solidW = new G4Tubs("World", 0., worldR, worldZ, 0., twopi);
0116   fLogicWorld = new G4LogicalVolume(solidW, fWorldMaterial, "World");
0117   G4VPhysicalVolume* world =
0118     new G4PVPlacement(0, G4ThreeVector(), fLogicWorld, "World", 0, false, 0);
0119   //
0120   // Check volume
0121   //
0122   G4Tubs* solidC = new G4Tubs("Check", 0., checkR, checkZ, 0., twopi);
0123   G4LogicalVolume* logicCheck = new G4LogicalVolume(solidC, fWorldMaterial, "World");
0124   new G4PVPlacement(0, G4ThreeVector(), logicCheck, "World", fLogicWorld, false, 0);
0125 
0126   //
0127   // Target volume
0128   //
0129   G4Tubs* solidA = new G4Tubs("Target", 0., fRadius, sliceZ, 0., twopi);
0130   fLogicTarget = new G4LogicalVolume(solidA, fTargetMaterial, "Target");
0131   fLogicTarget->SetSensitiveDetector(fTargetSD);
0132 
0133   G4double z = sliceZ - targetZ;
0134 
0135   for (G4int i = 0; i < nSlices; i++) {
0136     // physC =
0137     new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, z), fLogicTarget, "Target", logicCheck, false, i);
0138     z += 2.0 * sliceZ;
0139   }
0140   G4cout << "### Target consist of " << nSlices << " of " << fTargetMaterial->GetName()
0141          << " disks with R(mm)= " << fRadius / mm << "  Width(mm)= " << 2.0 * sliceZ / mm
0142          << "  Total Length(mm)= " << 2.0 * targetZ / mm << "  ###" << G4endl;
0143 
0144   // colors
0145   G4VisAttributes zero = G4VisAttributes::GetInvisible();
0146   fLogicWorld->SetVisAttributes(zero);
0147 
0148   G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 0.3));
0149   logicCheck->SetVisAttributes(regWcolor);
0150 
0151   G4VisAttributes regCcolor(G4Colour(0., 0.3, 0.7));
0152   fLogicTarget->SetVisAttributes(regCcolor);
0153 
0154   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0155 
0156   return world;
0157 }
0158 
0159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0160 
0161 void DetectorConstruction::SetTargetMaterial(const G4String& mat)
0162 {
0163   // search the material by its name
0164   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0165 
0166   if (material && material != fTargetMaterial) {
0167     HistoManager::GetPointer()->SetTargetMaterial(material);
0168     fTargetMaterial = material;
0169     if (fLogicTarget) {
0170       fLogicTarget->SetMaterial(fTargetMaterial);
0171     }
0172     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0173   }
0174 }
0175 
0176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0177 
0178 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
0179 {
0180   // search the material by its name
0181   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0182 
0183   if (material && material != fWorldMaterial) {
0184     fWorldMaterial = material;
0185     if (fLogicWorld) {
0186       fLogicWorld->SetMaterial(fWorldMaterial);
0187     }
0188     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0189   }
0190 }
0191 
0192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0193 
0194 void DetectorConstruction::SetTargetRadius(G4double val)
0195 {
0196   if (val > 0.0) {
0197     fRadius = val;
0198     G4RunManager::GetRunManager()->GeometryHasBeenModified();
0199   }
0200 }
0201 
0202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......