Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:39

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