Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-17 08:04:49

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 #include "FlashSensitiveDetector.hh"
0071 
0072 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0073 
0074 FlashDetectorConstruction::FlashDetectorConstruction()
0075     : G4VUserDetectorConstruction(), physicalTreatmentRoom(0),logicTreatmentRoom(0), Collimator(0), fPhantom(0),
0076 fPhantomLogicalVolume(0),fPhant_phys(0),
0077       fCheckOverlaps(true),
0078       fActivateDet(false)
0079        {
0080 
0081   DefineMaterials();
0082   fDetectorMessenger = new FlashDetectorMessenger(this);
0083 
0084   SetPhantomSize(30. *cm, 30. *cm, 30. *cm);
0085   SetAirGap(0*cm); // Set the air gap between the water phantom and the end of the applicator
0086   SetDetectorThickness(10*um); //Set the SiC detector thickness
0087   SetDetector_subThickness(370*um);
0088   SetDetectorWidth(2*mm); //Set the SiC detector width
0089   SetDetectorPosition(13*mm); // Position of the single detector and of the SiC array within the water phantom
0090   
0091   // Change the following parameters to change the number of detectors and center to center distance of the SiC array
0092   nDet = 40;
0093   fDet_ctc = 3 * mm;
0094   
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0098 
0099 FlashDetectorConstruction::~FlashDetectorConstruction() {
0100 
0101   delete fDetectorMessenger;
0102 }
0103 
0104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0105 
0106 void FlashDetectorConstruction::DefineMaterials() {
0107   nist = G4NistManager::Instance();
0108 //write here a function to define custom materials
0109 G4bool isotopes = false;
0110  Si = nist->FindOrBuildElement("Si", isotopes);
0111  C = nist->FindOrBuildElement("C", isotopes);
0112 
0113   }
0114 
0115 
0116 //
0117 G4VPhysicalVolume *
0118 FlashDetectorConstruction::ConstructPhantom(G4double CollPos) {
0119 //This function creates a cubic phantom with the point Collpos on the surface of the cube.
0120 
0121  fPhantomMaterial = nist->FindOrBuildMaterial("G4_WATER");
0122 
0123  fPosition_coefficient = CollPos;
0124  
0125  fPhantom_coordinateX = (fPosition_coefficient * mm + fPhantomSizeX / 2);
0126 
0127  fPhantomPosition =  G4ThreeVector(fPhantom_coordinateX, 0. * mm, 0. * mm); //phantom is constructed with the entrance surface attached to the applicator 
0128   
0129 
0130   // Definition of the solid volume of the Phantom
0131   fPhantom = new G4Box("Phantom", fPhantomSizeX / 2, fPhantomSizeY / 2,
0132                       fPhantomSizeZ / 2);
0133 
0134   // Definition of the logical volume of the Phantom
0135   fPhantomLogicalVolume =
0136       new G4LogicalVolume(fPhantom, fPhantomMaterial, "phantomLog", 0, 0, 0);
0137 
0138   // Definition of the physical volume of the Phantom
0139   fPhant_phys =
0140       new G4PVPlacement(0, fPhantomPosition, "phantomPhys", fPhantomLogicalVolume,
0141                         physicalTreatmentRoom, false, 0);
0142 //define the region to set cuts in FlashPhysicsList.cc and step limit
0143   G4Region *PhantomRegion = new G4Region("Phantom_reg");
0144   fPhantomLogicalVolume->SetRegion(PhantomRegion);
0145   PhantomRegion->AddRootLogicalVolume(fPhantomLogicalVolume);
0146 
0147   // Visualisation attributes of the phantom
0148   red = new G4VisAttributes(G4Colour(0 / 255., 255 / 255., 0 / 255.));
0149   red->SetVisibility(true);
0150 
0151   blue = new G4VisAttributes(G4Colour(0 / 255., 0. / 255., 255. / 255.));
0152   blue->SetVisibility(true);
0153 
0154   fPhantomLogicalVolume->SetVisAttributes(red);
0155 //set step limit in phantom
0156   G4double maxStep = 0.1 * mm;
0157   fStepLimit = new G4UserLimits(maxStep);
0158   fPhantomLogicalVolume->SetUserLimits(fStepLimit);
0159 
0160   return fPhant_phys;
0161 }
0162 
0163 
0164 void FlashDetectorConstruction::ConstructDetector(){
0165  //Detector
0166   
0167 
0168   G4double fDensity_SiC=3.22*g/cm3;
0169 
0170   SiC=new G4Material("SiC", fDensity_SiC,2);
0171   SiC->AddElement(Si,1);
0172   SiC->AddElement(C,1);
0173  
0174  fDetectorMaterial=SiC;
0175 
0176 
0177 
0178  fDet_box = new G4Box("Detector",fDet_thickness/2,fDet_width/2,fDet_width/2);
0179  
0180   // Definition of the logical volume of the Detector
0181   fDetLogicalVolume =
0182       new G4LogicalVolume(fDet_box, fDetectorMaterial, "DetectorLog", 0, 0, 0);
0183 
0184 
0185   fDet_sub = new G4Box("Det_sub",fDet_sub_thickness/2,fDet_width/2,fDet_width/2);
0186  
0187     // Definition of the logical volume of the Detector substrate
0188     fDet_sub_LogicalVolume =
0189         new G4LogicalVolume(fDet_sub, fDetectorMaterial, "Det_sub_Log", 0, 0, 0);
0190 
0191     
0192   G4double posInit = (nDet - 1) * fDet_ctc / 2; 
0193 
0194 
0195 if (fActivateDet) {
0196     // Placement physical volumes of the detector array
0197     for (int i = 0; i < nDet; i++){
0198 
0199     std::ostringstream os;
0200     os << "Det_Phys_";
0201     if (i < 10)
0202     {
0203         os << "00";
0204     } else if (i < 100){
0205         os << "0";
0206     }
0207     os << i ;
0208     G4String name = os.str();
0209 
0210     G4cout << "Position: " << -posInit + fDet_ctc * i << G4endl;
0211 
0212     fDet_phys.push_back(new G4PVPlacement(
0213         0,
0214     //  G4ThreeVector(fDetectorPosition, 0, -posInit + fDet_ctc * i),
0215     G4ThreeVector(-fPhantomSizeX/2+fDetectorPosition, 0, -posInit + fDet_ctc * i), 
0216         name,
0217         fDetLogicalVolume, 
0218         fPhant_phys,
0219         false, 
0220         i, 
0221         fCheckOverlaps
0222     ));
0223 
0224 
0225     fDet_sub_phys.push_back (new G4PVPlacement
0226                  (0,
0227                   G4ThreeVector(-fPhantomSizeX/2+fDetectorPosition+fDet_thickness/2+fDet_sub_thickness/2, 0. * mm, -posInit + fDet_ctc * i),
0228                   "Det_sub_Phys",
0229                   fDet_sub_LogicalVolume,
0230                   fPhant_phys,
0231                   false,
0232                   i,
0233                   fCheckOverlaps));
0234 
0235   
0236     
0237     }
0238 }
0239 
0240 }
0241 
0242 G4VPhysicalVolume *FlashDetectorConstruction::Construct() {
0243   // -----------------------------
0244   // Treatment room - World volume
0245   //------------------------------
0246   // Treatment room sizes
0247   const G4double worldX = 400.0 * cm;
0248   const G4double worldY = 400.0 * cm;
0249   const G4double worldZ = 400.0 * cm;
0250   G4bool isotopes = false;
0251 
0252   airNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR", isotopes);
0253   // Air
0254   //
0255 
0256   G4Box *treatmentRoom = new G4Box("TreatmentRoom", worldX, worldY, worldZ);
0257   logicTreatmentRoom = new G4LogicalVolume(treatmentRoom, airNist,
0258                                            "logicTreatmentRoom", 0, 0, 0);
0259   physicalTreatmentRoom =
0260       new G4PVPlacement(0, G4ThreeVector(), "physicalTreatmentRoom",
0261                         logicTreatmentRoom, 0, false, 0);
0262 
0263   // The treatment room is invisible in the Visualisation
0264   logicTreatmentRoom->SetVisAttributes(G4VisAttributes::GetInvisible());
0265 
0266   // -----------------------------
0267   // Applicator + phantom +Default dimensions
0268   //------------------------------
0269  
0270 
0271   
0272 
0273   Collimator = new FlashApplicator(physicalTreatmentRoom);
0274   
0275 
0276    
0277  fPhantom_physical =
0278         ConstructPhantom(Collimator->fFinalApplicatorXPositionFlash +
0279     Collimator->fHightFinalApplicatorFlash+fAirGap);
0280  
0281 
0282   ConstructDetector();
0283  
0284   return physicalTreatmentRoom;
0285 }
0286 
0287 
0288 
0289 void FlashDetectorConstruction::ConstructSDandField() {
0290 if (fActivateDet){
0291   
0292     G4SDManager * SDman = G4SDManager::GetSDMpointer();
0293 
0294     // Sensitive detector
0295     FlashSensitiveDetector *fSensDet = new FlashSensitiveDetector("fSensitiveDetector");
0296     
0297     SDman->AddNewDetector(fSensDet);
0298     fDetLogicalVolume->SetSensitiveDetector(fSensDet);
0299 
0300 }    
0301 
0302 }
0303 
0304 
0305 /////MESSANGER ///
0306 
0307 G4bool FlashDetectorConstruction::SetPhantomMaterial(G4String material)
0308 {
0309 
0310     if (G4Material* pMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
0311     {
0312     fPhantomMaterial  = pMat;
0313 
0314     if (fPhantomLogicalVolume) 
0315     {
0316         
0317         fPhantomLogicalVolume ->  SetMaterial(pMat);
0318 
0319         G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
0320         G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0321         G4cout << "The material of Phantom/Detector has been changed to " << material << G4endl;
0322     }
0323     }
0324     else
0325     {
0326     G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
0327         " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl; 
0328     G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl; 
0329     return false;
0330     }
0331 
0332     return true;
0333 }
0334 
0335 
0336 void FlashDetectorConstruction::SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ)
0337 {
0338     if (sizeX > 0.) fPhantomSizeX = sizeX;
0339     if (sizeY > 0.) fPhantomSizeY = sizeY;
0340     if (sizeZ > 0.) fPhantomSizeZ = sizeZ;
0341 }
0342 
0343 void FlashDetectorConstruction::SetAirGap(G4double displ)
0344 {
0345   
0346    fAirGap=displ;
0347 }
0348 
0349 G4bool FlashDetectorConstruction::SetDetectorMaterial(G4String material)
0350 {
0351 
0352     if (G4Material* pMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
0353     {
0354     fDetectorMaterial  = pMat;
0355 
0356     if (fDetLogicalVolume) 
0357     {
0358         
0359         fDetLogicalVolume ->  SetMaterial(pMat);
0360 
0361         G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
0362         G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0363         G4cout << "The material of Phantom/Detector has been changed to " << material << G4endl;
0364     }
0365     }
0366     else
0367     {
0368     G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
0369         " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl; 
0370     G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl; 
0371     return false;
0372     }
0373 
0374     return true;
0375 }
0376 
0377 
0378 
0379 
0380 void FlashDetectorConstruction::SetDetectorThickness(G4double thickness)
0381 {
0382  
0383    fDet_thickness=thickness;
0384 }
0385 
0386 void FlashDetectorConstruction::SetDetectorWidth(G4double width)
0387 {
0388  
0389    fDet_width=width;
0390 }
0391 
0392 void FlashDetectorConstruction::SetDetector_subThickness(G4double thickness_sub)
0393 {
0394  
0395     fDet_sub_thickness= thickness_sub;
0396 }
0397 
0398 
0399 void FlashDetectorConstruction::SetDetectorPosition(G4double position)
0400 {
0401 
0402    fDetectorPosition=position;
0403 }
0404 
0405 void FlashDetectorConstruction::ActivateDetArray(G4bool fbool){
0406     fActivateDet = fbool;
0407 }