Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:23

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 //  History :
0027 //     21/10/2021 : DLa update to modify the material and the size
0028 // -------------------------------------------------------------------
0029 // -------------------------------------------------------------------
0030 
0031 #include "DetectorConstruction.hh"
0032 #include "DetectorMessenger.hh"
0033 #include "G4SystemOfUnits.hh"
0034 #include "G4Region.hh"
0035 #include "G4ProductionCuts.hh"
0036 #include "G4RunManager.hh"
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0039 
0040 DetectorConstruction::DetectorConstruction()
0041 :G4VUserDetectorConstruction(), fPhysiWorld(nullptr), fLogicWorld(nullptr),    fSolidWorld(nullptr),  fWorldMaterial(nullptr),  flogicTarget(nullptr),  ftargetSolid(nullptr),  fMaterial(nullptr),   fRegion(nullptr)
0042 {
0043   fBoxSize = 1.0*um;
0044   DefineMaterials();
0045   SetMaterial("G4_Si");  
0046   fDetectorMessenger = new DetectorMessenger(this);
0047 }  
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0050 
0051 DetectorConstruction::~DetectorConstruction()
0052 {
0053   delete fPhysiWorld;
0054   delete fLogicWorld;  
0055   delete fSolidWorld;  
0056   //delete fWorldMaterial;   // no delete because link to database
0057   delete flogicTarget;
0058   delete ftargetSolid;
0059   delete fMaterial; 
0060   delete fRegion;
0061   delete fDetectorMessenger;
0062 }
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0065 
0066 G4VPhysicalVolume* DetectorConstruction::Construct()
0067 
0068 {
0069   DefineMaterials();
0070   return ConstructDetector();
0071 }
0072 
0073 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0074 
0075 void DetectorConstruction::DefineMaterials()
0076 { 
0077 
0078   // Silicon is defined from NIST material database
0079   G4NistManager * man = G4NistManager::Instance();
0080   fMaterial =  man->FindOrBuildMaterial("G4_Si");
0081   fWorldMaterial =  man->FindOrBuildMaterial("G4_Si");  // world material;
0082   
0083 }
0084 
0085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0086 
0087 
0088 
0089 void DetectorConstruction::SetMaterial(const G4String& materialChoice)
0090 {
0091   // search the material by its name
0092   G4Material* pttoMaterial = 
0093      G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0094   
0095   if (pttoMaterial) {
0096     fMaterial = pttoMaterial;
0097     if ( flogicTarget ) { flogicTarget->SetMaterial(fMaterial); }
0098   } else {
0099     G4cout << "\n--> warning from DetectorConstruction::SetMaterial : "
0100            << materialChoice << " not found" << G4endl;
0101   }
0102   G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0103 }
0104 
0105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0106 
0107 
0108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0109 G4VPhysicalVolume* DetectorConstruction::ConstructDetector()
0110 {
0111 
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0114 
0115   // WORLD VOLUME
0116   
0117   
0118     G4double TargetSizeX =  1*um; 
0119   G4double TargetSizeY =  TargetSizeX; 
0120   G4double TargetSizeZ =  TargetSizeX; 
0121   fBoxSize = TargetSizeX;
0122 
0123   fWorldSizeX  = TargetSizeX*2; 
0124   fWorldSizeY  = TargetSizeY*2; 
0125   fWorldSizeZ  = TargetSizeZ*2; 
0126 
0127   fSolidWorld = new G4Box("World",                   //its name
0128                fWorldSizeX/2,fWorldSizeY/2,fWorldSizeZ/2);  //its size
0129   
0130 
0131   fLogicWorld = new G4LogicalVolume(fSolidWorld,    //its solid
0132                    fWorldMaterial,      //its material
0133                    "World");        //its name
0134   
0135   fPhysiWorld = new G4PVPlacement(0,            //no rotation
0136                  G4ThreeVector(),   //at (0,0,0)
0137                                  "World",       //its name
0138                                  fLogicWorld,       //its logical volume
0139                                  0,         //its mother  volume
0140                                  false,         //no boolean operation
0141                                  0);            //copy number
0142 
0143 
0144 
0145   ftargetSolid = new G4Box("Target",                     //its name
0146                  TargetSizeX/2,TargetSizeY/2,TargetSizeZ/2);   //its size
0147   
0148 
0149   flogicTarget = new G4LogicalVolume(ftargetSolid,       //its solid
0150                              fMaterial, //its material
0151                              "Target");     //its name
0152   
0153   new G4PVPlacement(0,                                         //no rotation
0154             G4ThreeVector(),                                   //at (0,0,0)
0155             "Target",       //its name
0156             flogicTarget,   //its logical volume
0157             fPhysiWorld,        //its mother  volume
0158             false,      //no boolean operation
0159             0);         //copy number
0160 
0161   // Visualization attributes
0162   G4VisAttributes* worldVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0)); //White
0163   worldVisAtt->SetVisibility(true);
0164   fLogicWorld->SetVisAttributes(worldVisAtt);
0165 
0166   G4VisAttributes* worldVisAtt1 = new G4VisAttributes(G4Colour(1.0,0.0,0.0)); 
0167   worldVisAtt1->SetVisibility(true);
0168   flogicTarget->SetVisAttributes(worldVisAtt1);
0169 
0170   // Create Target G4Region and add logical volume
0171   
0172   fRegion = new G4Region("Target");
0173   
0174   G4ProductionCuts* cuts = new G4ProductionCuts();
0175   
0176   G4double defCut = 1*nanometer;
0177   cuts->SetProductionCut(defCut,"gamma");
0178   cuts->SetProductionCut(defCut,"e-");
0179   cuts->SetProductionCut(defCut,"e+");
0180   cuts->SetProductionCut(defCut,"proton");
0181   
0182   fRegion->SetProductionCuts(cuts);
0183   fRegion->AddRootLogicalVolume(flogicTarget); 
0184 
0185   return fPhysiWorld;
0186 }
0187  
0188  
0189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0190 
0191 void DetectorConstruction::SetSize(G4double value)
0192 {
0193   fBoxSize = value;
0194   if(ftargetSolid) {
0195     ftargetSolid->SetXHalfLength(fBoxSize/2);
0196     ftargetSolid->SetYHalfLength(fBoxSize/2);
0197     ftargetSolid->SetZHalfLength(fBoxSize/2);
0198   }
0199   fWorldSizeX = value*2.0;
0200   fWorldSizeY = value*2.0;
0201   fWorldSizeZ = value*2.0;
0202   
0203   if(fSolidWorld) {
0204     fSolidWorld->SetXHalfLength(fWorldSizeX/2);
0205     fSolidWorld->SetYHalfLength(fWorldSizeY/2);
0206     fSolidWorld->SetZHalfLength(fWorldSizeZ/2);
0207   }
0208   
0209 }
0210