Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-17 07:40:18

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