Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:03

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 FlashDetectorConstruction.cc
0028 /// \brief Implementation of the FlashDetectorConstruction class
0029 
0030 
0031 #include "FlashDetectorConstruction.hh"
0032 
0033 #include "G4RunManager.hh"
0034 
0035 #include "G4Material.hh"
0036 #include "G4NistManager.hh"
0037 #include "G4Region.hh"
0038 #include "G4SDManager.hh"
0039 
0040 #include "G4AutoDelete.hh"
0041 #include "G4Box.hh"
0042 #include "G4GlobalMagFieldMessenger.hh"
0043 #include "G4LogicalVolume.hh"
0044 #include "G4PVParameterised.hh"
0045 #include "G4PVPlacement.hh"
0046 #include "G4Tubs.hh"
0047 
0048 #include "G4GeometryManager.hh"
0049 #include "G4GeometryTolerance.hh"
0050 
0051 #include "G4UserLimits.hh"
0052 
0053 #include "G4Colour.hh"
0054 #include "G4VisAttributes.hh"
0055 
0056 #include "G4SystemOfUnits.hh"
0057 
0058 #include "FlashApplicator.hh"
0059 
0060 
0061 #include "G4MaterialPropertiesTable.hh"
0062 
0063 #include "G4PSEnergyDeposit.hh"
0064 #include "G4PhysicalConstants.hh"
0065 #include "G4SystemOfUnits.hh"
0066 #include "G4VPrimitiveScorer.hh"
0067 #include "G4VisAttributes.hh"
0068 #include "FlashDetectorMessenger.hh"
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 FlashDetectorConstruction::FlashDetectorConstruction()
0073     : G4VUserDetectorConstruction(), physicalTreatmentRoom(0),logicTreatmentRoom(0), Collimator(0), fPhantom(0),
0074 fPhantomLogicalVolume(0),fPhant_phys(0),
0075       fCheckOverlaps(true) {
0076 
0077   DefineMaterials();
0078   fDetectorMessenger = new FlashDetectorMessenger(this);
0079 
0080   SetPhantomSize(30. *cm, 30. *cm, 30. *cm);
0081   SetAirGap(0*cm); // Set the air gap between the water phantom and the end of the applicator
0082   SetDetectorThickness(10*um);
0083   SetDetector_subThickness(370*um);
0084   SetDetectorWidth(5*mm);
0085   SetAirGap_water_detector(0*cm); // Set the air gap between the end of the water phantom and the entrance of the detector
0086 
0087   
0088   
0089 }
0090 
0091 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0092 
0093 FlashDetectorConstruction::~FlashDetectorConstruction() {
0094 
0095   delete fDetectorMessenger;
0096 }
0097 
0098 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0099 
0100 void FlashDetectorConstruction::DefineMaterials() {
0101   nist = G4NistManager::Instance();
0102 //write here a function to define custom materials
0103 G4bool isotopes = false;
0104  Si = nist->FindOrBuildElement("Si", isotopes);
0105  C = nist->FindOrBuildElement("C", isotopes);
0106 
0107   }
0108 
0109 
0110 //
0111 G4VPhysicalVolume *
0112 FlashDetectorConstruction::ConstructPhantom(G4double CollPos) {
0113 //This function creates a cubic phantom with the point Collpos on the surface of the cube.
0114 
0115  fPhantomMaterial = nist->FindOrBuildMaterial("G4_WATER");
0116 
0117  fPosition_coefficient = CollPos;
0118  
0119  fPhantom_coordinateX = (fPosition_coefficient * mm + fPhantomSizeX / 2);
0120 
0121  fPhantomPosition =  G4ThreeVector(fPhantom_coordinateX, 0. * mm, 0. * mm); //phantom is constructed with the entrance surface attached to the applicator 
0122   
0123 
0124   // Definition of the solid volume of the Phantom
0125   fPhantom = new G4Box("Phantom", fPhantomSizeX / 2, fPhantomSizeY / 2,
0126                       fPhantomSizeZ / 2);
0127 
0128   // Definition of the logical volume of the Phantom
0129   fPhantomLogicalVolume =
0130       new G4LogicalVolume(fPhantom, fPhantomMaterial, "phantomLog", 0, 0, 0);
0131 
0132   // Definition of the physical volume of the Phantom
0133   fPhant_phys =
0134       new G4PVPlacement(0, fPhantomPosition, "phantomPhys", fPhantomLogicalVolume,
0135                         physicalTreatmentRoom, false, 0);
0136 //define the region to set cuts in FlashPhysicsList.cc and step limit
0137   G4Region *PhantomRegion = new G4Region("Phantom_reg");
0138   fPhantomLogicalVolume->SetRegion(PhantomRegion);
0139   PhantomRegion->AddRootLogicalVolume(fPhantomLogicalVolume);
0140 
0141   // Visualisation attributes of the phantom
0142   red = new G4VisAttributes(G4Colour(0 / 255., 255 / 255., 0 / 255.));
0143   red->SetVisibility(true);
0144 
0145   blue = new G4VisAttributes(G4Colour(0 / 255., 0. / 255., 255. / 255.));
0146   blue->SetVisibility(true);
0147 
0148   fPhantomLogicalVolume->SetVisAttributes(red);
0149 //set step limit in phantom
0150   G4double maxStep = 0.1 * mm;
0151   fStepLimit = new G4UserLimits(maxStep);
0152   fPhantomLogicalVolume->SetUserLimits(fStepLimit);
0153 
0154   return fPhant_phys;
0155 }
0156 
0157 G4VPhysicalVolume *
0158 FlashDetectorConstruction::ConstructDetector(){
0159  //Detector
0160 
0161 
0162   G4double fDensity_SiC=3.22*g/cm3;
0163 
0164   SiC=new G4Material("SiC", fDensity_SiC,2);
0165   SiC->AddElement(Si,1);
0166   SiC->AddElement(C,1);
0167  
0168  fDetectorMaterial=SiC;
0169 
0170 
0171  fDetectorPosition=fPhantom_coordinateX+fAirGap+fPhantomSizeX/2+fDet_thickness/2+fAirGap_phantom_det;
0172  
0173  fDet_box = new G4Box("Detector",fDet_thickness/2,fDet_width/2,fDet_width/2);
0174  
0175   // Definition of the logical volume of the Detector
0176   fDetLogicalVolume =
0177       new G4LogicalVolume(fDet_box, fDetectorMaterial, "DetectorLog", 0, 0, 0);
0178   fDet_phys = new G4PVPlacement(0,G4ThreeVector(fDetectorPosition, 0. * mm, 0. * mm), "DetPhys",fDetLogicalVolume,physicalTreatmentRoom,false, 0, fCheckOverlaps);
0179 
0180   
0181   fDet_sub = new G4Box("Det_sub",fDet_sub_thickness/2,fDet_width/2,fDet_width/2);
0182  
0183   // Definition of the logical volume of the Detector 
0184   fDet_sub_LogicalVolume =
0185       new G4LogicalVolume(fDet_sub, fDetectorMaterial, "Det_sub_Log", 0, 0, 0);
0186   fDet_sub_phys = new G4PVPlacement(0,G4ThreeVector(fDetectorPosition+fDet_thickness+fDet_sub_thickness/2, 0. * mm, 0. * mm), "Det_sub_Phys",fDet_sub_LogicalVolume,physicalTreatmentRoom,false, 0, fCheckOverlaps);
0187 
0188 
0189     return fDet_phys;
0190 
0191 }
0192 
0193 G4VPhysicalVolume *FlashDetectorConstruction::Construct() {
0194   // -----------------------------
0195   // Treatment room - World volume
0196   //------------------------------
0197   // Treatment room sizes
0198   const G4double worldX = 400.0 * cm;
0199   const G4double worldY = 400.0 * cm;
0200   const G4double worldZ = 400.0 * cm;
0201   G4bool isotopes = false;
0202 
0203   airNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR", isotopes);
0204   // Air
0205   //
0206 
0207   G4Box *treatmentRoom = new G4Box("TreatmentRoom", worldX, worldY, worldZ);
0208   logicTreatmentRoom = new G4LogicalVolume(treatmentRoom, airNist,
0209                                            "logicTreatmentRoom", 0, 0, 0);
0210   physicalTreatmentRoom =
0211       new G4PVPlacement(0, G4ThreeVector(), "physicalTreatmentRoom",
0212                         logicTreatmentRoom, 0, false, 0);
0213 
0214   // The treatment room is invisible in the Visualisation
0215   logicTreatmentRoom->SetVisAttributes(G4VisAttributes::GetInvisible());
0216 
0217   // -----------------------------
0218   // Applicator + phantom +Default dimensions
0219   //------------------------------
0220  
0221 
0222   
0223 
0224   Collimator = new FlashApplicator(physicalTreatmentRoom);
0225   
0226 
0227    
0228  fPhantom_physical =
0229         ConstructPhantom(Collimator->fFinalApplicatorXPositionFlash +
0230     Collimator->fHightFinalApplicatorFlash+fAirGap);
0231  ConstructDetector();
0232    
0233 
0234   return physicalTreatmentRoom;
0235 }
0236 
0237 
0238 
0239 void FlashDetectorConstruction::ConstructSDandField() {
0240 //modify this function if you want to insert a sensitive detector
0241 }
0242 
0243 
0244 /////MESSANGER ///
0245 
0246 G4bool FlashDetectorConstruction::SetPhantomMaterial(G4String material)
0247 {
0248 
0249     if (G4Material* pMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
0250     {
0251     fPhantomMaterial  = pMat;
0252 
0253     if (fPhantomLogicalVolume) 
0254     {
0255         
0256         fPhantomLogicalVolume ->  SetMaterial(pMat);
0257 
0258         G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
0259         G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0260         G4cout << "The material of Phantom/Detector has been changed to " << material << G4endl;
0261     }
0262     }
0263     else
0264     {
0265     G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
0266         " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl; 
0267     G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl; 
0268     return false;
0269     }
0270 
0271     return true;
0272 }
0273 
0274 
0275 void FlashDetectorConstruction::SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ)
0276 {
0277     if (sizeX > 0.) fPhantomSizeX = sizeX;
0278     if (sizeY > 0.) fPhantomSizeY = sizeY;
0279     if (sizeZ > 0.) fPhantomSizeZ = sizeZ;
0280 }
0281 
0282 void FlashDetectorConstruction::SetAirGap(G4double displ)
0283 {
0284   
0285    fAirGap=displ;
0286 }
0287 
0288 G4bool FlashDetectorConstruction::SetDetectorMaterial(G4String material)
0289 {
0290 
0291     if (G4Material* pMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
0292     {
0293     fDetectorMaterial  = pMat;
0294 
0295     if (fDetLogicalVolume) 
0296     {
0297         
0298         fDetLogicalVolume ->  SetMaterial(pMat);
0299 
0300         G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
0301         G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0302         G4cout << "The material of Phantom/Detector has been changed to " << material << G4endl;
0303     }
0304     }
0305     else
0306     {
0307     G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
0308         " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl; 
0309     G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl; 
0310     return false;
0311     }
0312 
0313     return true;
0314 }
0315 
0316 
0317 
0318 
0319 void FlashDetectorConstruction::SetDetectorThickness(G4double thickness)
0320 {
0321  
0322    fDet_thickness=thickness;
0323 }
0324 
0325 void FlashDetectorConstruction::SetDetectorWidth(G4double width)
0326 {
0327  
0328    fDet_width=width;
0329 }
0330 
0331 void FlashDetectorConstruction::SetDetector_subThickness(G4double thickness_sub)
0332 {
0333  
0334     fDet_sub_thickness= thickness_sub;
0335 }
0336 
0337 
0338  
0339 
0340 
0341  void FlashDetectorConstruction::SetAirGap_water_detector(G4double spost)
0342 {
0343   
0344   fAirGap_phantom_det=spost;
0345 }
0346 
0347 
0348 void FlashDetectorConstruction::SetDetectorPosition(G4double position)
0349 {
0350  
0351    fDetectorPosition=position;
0352 }