Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:51:10

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 "ScreenSD.hh"
0032 
0033 #include "G4AutoDelete.hh"
0034 #include "G4Box.hh"
0035 #include "G4Colour.hh"
0036 #include "G4GlobalMagFieldMessenger.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4Material.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4PVPlacement.hh"
0041 #include "G4SDManager.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4VisAttributes.hh"
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 
0047 G4ThreadLocal G4GlobalMagFieldMessenger* DetectorConstruction::fMagFieldMessenger = nullptr;
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 
0051 G4VPhysicalVolume* DetectorConstruction::Construct()
0052 {
0053   // Get nist material manager
0054   G4NistManager* nistManager = G4NistManager::Instance();
0055 
0056   // Build materials
0057   G4Material* air = nistManager->FindOrBuildMaterial("G4_AIR");
0058   G4Material* csi = nistManager->FindOrBuildMaterial("G4_CESIUM_IODIDE");
0059   // There is no need to test if materials were built/found
0060   // as G4NistManager would issue an error otherwise
0061   // Try the code with "XYZ".
0062 
0063   // Print all materials
0064   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0065 
0066   // Option to switch on/off checking of volumes overlaps
0067   G4bool checkOverlaps = true;
0068 
0069   //
0070   // World
0071   //
0072 
0073   // The world dimensions
0074   G4double worldHxyz = 2. * m;
0075 
0076   // world volume
0077   auto worldS = new G4Box("World", worldHxyz, worldHxyz, worldHxyz);
0078 
0079   auto worldLV = new G4LogicalVolume(worldS, air, "World");
0080 
0081   G4VPhysicalVolume* worldPV =
0082     new G4PVPlacement(nullptr, G4ThreeVector(), worldLV, "World", nullptr, false, 0, checkOverlaps);
0083 
0084   //
0085   // Box
0086   //
0087 
0088   // The box dimensions
0089   G4double boxHxy = 1. * m;
0090   G4double boxHz = 10. * cm;
0091 
0092   // box volume
0093   auto boxS = new G4Box("World", boxHxy, boxHxy, boxHz);
0094 
0095   auto boxLV = new G4LogicalVolume(boxS, csi, "Box");
0096 
0097   // The box position
0098   G4double posz = 0. * m;
0099 
0100   new G4PVPlacement(nullptr, G4ThreeVector(0, 0, posz), boxLV, "Box", worldLV, false, 0,
0101                     checkOverlaps);
0102 
0103   //
0104   // Scoring screen
0105   //
0106   // The screen dimensions
0107   G4double screenHxy = 1.999 * m;
0108   G4double screenHz = 1. * mm;
0109 
0110   // Screen volume
0111   auto screenS = new G4Box("World", screenHxy, screenHxy, screenHz);
0112 
0113   auto screenLV = new G4LogicalVolume(screenS, air, "Screen");
0114 
0115   // The screen position
0116   posz += boxHz + screenHz;
0117 
0118   new G4PVPlacement(nullptr, G4ThreeVector(0, 0, posz), screenLV, "Screen", worldLV, false, 0,
0119                     checkOverlaps);
0120 
0121   //
0122   // Visualization attributes
0123   //
0124   worldLV->SetVisAttributes(G4VisAttributes::GetInvisible());
0125 
0126   auto simpleBoxVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
0127   simpleBoxVisAtt->SetVisibility(true);
0128   boxLV->SetVisAttributes(simpleBoxVisAtt);
0129   screenLV->SetVisAttributes(simpleBoxVisAtt);
0130 
0131   //
0132   // Always return the physical World
0133   //
0134   return worldPV;
0135 }
0136 
0137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0138 
0139 void DetectorConstruction::ConstructSDandField()
0140 {
0141   // G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
0142 
0143   //
0144   // Sensitive detectors
0145   //
0146   auto screenSD = new ScreenSD("ScreenSD");
0147   G4SDManager::GetSDMpointer()->AddNewDetector(screenSD);
0148   SetSensitiveDetector("Screen", screenSD);
0149 
0150   //
0151   // Magnetic field
0152   //
0153   // Create global magnetic field messenger.
0154   // Uniform magnetic field is then created automatically if
0155   // the field value is not zero.
0156   G4ThreeVector fieldValue;
0157   fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
0158   fMagFieldMessenger->SetVerboseLevel(1);
0159 
0160   // Register the field messenger for deleting
0161   G4AutoDelete::Register(fMagFieldMessenger);
0162 }
0163 
0164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......