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4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 //
 27 /// \file FlashDetectorConstruction.cc
 28 /// \brief Implementation of the FlashDetectorConstruction class
 29 
 30 
 31 #include "FlashDetectorConstruction.hh"
 32 
 33 #include "G4RunManager.hh"
 34 
 35 #include "G4Material.hh"
 36 #include "G4NistManager.hh"
 37 #include "G4Region.hh"
 38 #include "G4SDManager.hh"
 39 
 40 #include "G4AutoDelete.hh"
 41 #include "G4Box.hh"
 42 #include "G4GlobalMagFieldMessenger.hh"
 43 #include "G4LogicalVolume.hh"
 44 #include "G4PVParameterised.hh"
 45 #include "G4PVPlacement.hh"
 46 #include "G4Tubs.hh"
 47 
 48 #include "G4GeometryManager.hh"
 49 #include "G4GeometryTolerance.hh"
 50 
 51 #include "G4UserLimits.hh"
 52 
 53 #include "G4Colour.hh"
 54 #include "G4VisAttributes.hh"
 55 
 56 #include "G4SystemOfUnits.hh"
 57 
 58 #include "FlashApplicator.hh"
 59 
 60 
 61 #include "G4MaterialPropertiesTable.hh"
 62 
 63 #include "G4PSEnergyDeposit.hh"
 64 #include "G4PhysicalConstants.hh"
 65 #include "G4SystemOfUnits.hh"
 66 #include "G4VPrimitiveScorer.hh"
 67 #include "G4VisAttributes.hh"
 68 #include "FlashDetectorMessenger.hh"
 69 
 70 #include "FlashSensitiveDetector.hh"
 71 
 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 73 
 74 FlashDetectorConstruction::FlashDetectorConstruction()
 75     : G4VUserDetectorConstruction(), physicalTreatmentRoom(0),logicTreatmentRoom(0), Collimator(0), fPhantom(0),
 76 fPhantomLogicalVolume(0),fPhant_phys(0),
 77       fCheckOverlaps(true),
 78       fActivateDet(false)
 79        {
 80 
 81   DefineMaterials();
 82   fDetectorMessenger = new FlashDetectorMessenger(this);
 83 
 84   SetPhantomSize(30. *cm, 30. *cm, 30. *cm);
 85   SetAirGap(0*cm); // Set the air gap between the water phantom and the end of the applicator
 86   SetDetectorThickness(10*um); //Set the SiC detector thickness
 87   SetDetector_subThickness(370*um);
 88   SetDetectorWidth(2*mm); //Set the SiC detector width
 89   SetDetectorPosition(13*mm); // Position of the single detector and of the SiC array within the water phantom
 90   
 91   // Change the following parameters to change the number of detectors and center to center distance of the SiC array
 92   nDet = 40;
 93   fDet_ctc = 3 * mm;
 94   
 95 }
 96 
 97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 98 
 99 FlashDetectorConstruction::~FlashDetectorConstruction() {
100 
101   delete fDetectorMessenger;
102 }
103 
104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105 
106 void FlashDetectorConstruction::DefineMaterials() {
107   nist = G4NistManager::Instance();
108 //write here a function to define custom materials
109 G4bool isotopes = false;
110  Si = nist->FindOrBuildElement("Si", isotopes);
111  C = nist->FindOrBuildElement("C", isotopes);
112 
113   }
114 
115 
116 //
117 G4VPhysicalVolume *
118 FlashDetectorConstruction::ConstructPhantom(G4double CollPos) {
119 //This function creates a cubic phantom with the point Collpos on the surface of the cube.
120 
121  fPhantomMaterial = nist->FindOrBuildMaterial("G4_WATER");
122 
123  fPosition_coefficient = CollPos;
124  
125  fPhantom_coordinateX = (fPosition_coefficient * mm + fPhantomSizeX / 2);
126 
127  fPhantomPosition =  G4ThreeVector(fPhantom_coordinateX, 0. * mm, 0. * mm); //phantom is constructed with the entrance surface attached to the applicator 
128   
129 
130   // Definition of the solid volume of the Phantom
131   fPhantom = new G4Box("Phantom", fPhantomSizeX / 2, fPhantomSizeY / 2,
132                       fPhantomSizeZ / 2);
133 
134   // Definition of the logical volume of the Phantom
135   fPhantomLogicalVolume =
136       new G4LogicalVolume(fPhantom, fPhantomMaterial, "phantomLog", 0, 0, 0);
137 
138   // Definition of the physical volume of the Phantom
139   fPhant_phys =
140       new G4PVPlacement(0, fPhantomPosition, "phantomPhys", fPhantomLogicalVolume,
141                         physicalTreatmentRoom, false, 0);
142 //define the region to set cuts in FlashPhysicsList.cc and step limit
143   G4Region *PhantomRegion = new G4Region("Phantom_reg");
144   fPhantomLogicalVolume->SetRegion(PhantomRegion);
145   PhantomRegion->AddRootLogicalVolume(fPhantomLogicalVolume);
146 
147   // Visualisation attributes of the phantom
148   red = new G4VisAttributes(G4Colour(0 / 255., 255 / 255., 0 / 255.));
149   red->SetVisibility(true);
150 
151   blue = new G4VisAttributes(G4Colour(0 / 255., 0. / 255., 255. / 255.));
152   blue->SetVisibility(true);
153 
154   fPhantomLogicalVolume->SetVisAttributes(red);
155 //set step limit in phantom
156   G4double maxStep = 0.1 * mm;
157   fStepLimit = new G4UserLimits(maxStep);
158   fPhantomLogicalVolume->SetUserLimits(fStepLimit);
159 
160   return fPhant_phys;
161 }
162 
163 
164 void FlashDetectorConstruction::ConstructDetector(){
165  //Detector
166   
167 
168   G4double fDensity_SiC=3.22*g/cm3;
169 
170   SiC=new G4Material("SiC", fDensity_SiC,2);
171   SiC->AddElement(Si,1);
172   SiC->AddElement(C,1);
173  
174  fDetectorMaterial=SiC;
175 
176 
177 
178  fDet_box = new G4Box("Detector",fDet_thickness/2,fDet_width/2,fDet_width/2);
179  
180   // Definition of the logical volume of the Detector
181   fDetLogicalVolume =
182       new G4LogicalVolume(fDet_box, fDetectorMaterial, "DetectorLog", 0, 0, 0);
183 
184 
185   fDet_sub = new G4Box("Det_sub",fDet_sub_thickness/2,fDet_width/2,fDet_width/2);
186  
187     // Definition of the logical volume of the Detector substrate
188     fDet_sub_LogicalVolume =
189         new G4LogicalVolume(fDet_sub, fDetectorMaterial, "Det_sub_Log", 0, 0, 0);
190 
191     
192   G4double posInit = (nDet - 1) * fDet_ctc / 2; 
193 
194 
195 if (fActivateDet) {
196     // Placement physical volumes of the detector array
197     for (int i = 0; i < nDet; i++){
198 
199     std::ostringstream os;
200     os << "Det_Phys_";
201     if (i < 10)
202     {
203         os << "00";
204     } else if (i < 100){
205         os << "0";
206     }
207     os << i ;
208     G4String name = os.str();
209 
210     G4cout << "Position: " << -posInit + fDet_ctc * i << G4endl;
211 
212     fDet_phys.push_back(new G4PVPlacement(
213         0,
214   //  G4ThreeVector(fDetectorPosition, 0, -posInit + fDet_ctc * i),
215   G4ThreeVector(-fPhantomSizeX/2+fDetectorPosition, 0, -posInit + fDet_ctc * i), 
216         name,
217         fDetLogicalVolume, 
218         fPhant_phys,
219         false, 
220         i, 
221         fCheckOverlaps
222     ));
223 
224 
225     fDet_sub_phys.push_back (new G4PVPlacement
226            (0,
227             G4ThreeVector(-fPhantomSizeX/2+fDetectorPosition+fDet_thickness/2+fDet_sub_thickness/2, 0. * mm, -posInit + fDet_ctc * i),
228             "Det_sub_Phys",
229             fDet_sub_LogicalVolume,
230             fPhant_phys,
231             false,
232             i,
233             fCheckOverlaps));
234 
235   
236     
237     }
238 }
239 
240 }
241 
242 G4VPhysicalVolume *FlashDetectorConstruction::Construct() {
243   // -----------------------------
244   // Treatment room - World volume
245   //------------------------------
246   // Treatment room sizes
247   const G4double worldX = 400.0 * cm;
248   const G4double worldY = 400.0 * cm;
249   const G4double worldZ = 400.0 * cm;
250   G4bool isotopes = false;
251 
252   airNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR", isotopes);
253   // Air
254   //
255 
256   G4Box *treatmentRoom = new G4Box("TreatmentRoom", worldX, worldY, worldZ);
257   logicTreatmentRoom = new G4LogicalVolume(treatmentRoom, airNist,
258                                            "logicTreatmentRoom", 0, 0, 0);
259   physicalTreatmentRoom =
260       new G4PVPlacement(0, G4ThreeVector(), "physicalTreatmentRoom",
261                         logicTreatmentRoom, 0, false, 0);
262 
263   // The treatment room is invisible in the Visualisation
264   logicTreatmentRoom->SetVisAttributes(G4VisAttributes::GetInvisible());
265 
266   // -----------------------------
267   // Applicator + phantom +Default dimensions
268   //------------------------------
269  
270 
271   
272 
273   Collimator = new FlashApplicator(physicalTreatmentRoom);
274   
275 
276    
277  fPhantom_physical =
278         ConstructPhantom(Collimator->fFinalApplicatorXPositionFlash +
279   Collimator->fHightFinalApplicatorFlash+fAirGap);
280  
281 
282   ConstructDetector();
283  
284   return physicalTreatmentRoom;
285 }
286 
287 
288 
289 void FlashDetectorConstruction::ConstructSDandField() {
290 if (fActivateDet){
291   
292     G4SDManager * SDman = G4SDManager::GetSDMpointer();
293 
294     // Sensitive detector
295     FlashSensitiveDetector *fSensDet = new FlashSensitiveDetector("fSensitiveDetector");
296     
297     SDman->AddNewDetector(fSensDet);
298     fDetLogicalVolume->SetSensitiveDetector(fSensDet);
299 
300 }    
301 
302 }
303 
304 
305 /////MESSANGER ///
306 
307 G4bool FlashDetectorConstruction::SetPhantomMaterial(G4String material)
308 {
309 
310     if (G4Material* pMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
311     {
312   fPhantomMaterial  = pMat;
313 
314   if (fPhantomLogicalVolume) 
315   {
316       
317       fPhantomLogicalVolume ->  SetMaterial(pMat);
318 
319       G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
320       G4RunManager::GetRunManager() -> GeometryHasBeenModified();
321       G4cout << "The material of Phantom/Detector has been changed to " << material << G4endl;
322   }
323     }
324     else
325     {
326   G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
327       " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl; 
328   G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl; 
329   return false;
330     }
331 
332     return true;
333 }
334 
335 
336 void FlashDetectorConstruction::SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ)
337 {
338     if (sizeX > 0.) fPhantomSizeX = sizeX;
339     if (sizeY > 0.) fPhantomSizeY = sizeY;
340     if (sizeZ > 0.) fPhantomSizeZ = sizeZ;
341 }
342 
343 void FlashDetectorConstruction::SetAirGap(G4double displ)
344 {
345   
346    fAirGap=displ;
347 }
348 
349 G4bool FlashDetectorConstruction::SetDetectorMaterial(G4String material)
350 {
351 
352     if (G4Material* pMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
353     {
354   fDetectorMaterial  = pMat;
355 
356   if (fDetLogicalVolume) 
357   {
358       
359       fDetLogicalVolume ->  SetMaterial(pMat);
360 
361       G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
362       G4RunManager::GetRunManager() -> GeometryHasBeenModified();
363       G4cout << "The material of Phantom/Detector has been changed to " << material << G4endl;
364   }
365     }
366     else
367     {
368   G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
369       " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl; 
370   G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl; 
371   return false;
372     }
373 
374     return true;
375 }
376 
377 
378 
379 
380 void FlashDetectorConstruction::SetDetectorThickness(G4double thickness)
381 {
382  
383    fDet_thickness=thickness;
384 }
385 
386 void FlashDetectorConstruction::SetDetectorWidth(G4double width)
387 {
388  
389    fDet_width=width;
390 }
391 
392 void FlashDetectorConstruction::SetDetector_subThickness(G4double thickness_sub)
393 {
394  
395     fDet_sub_thickness= thickness_sub;
396 }
397 
398 
399 void FlashDetectorConstruction::SetDetectorPosition(G4double position)
400 {
401 
402    fDetectorPosition=position;
403 }
404 
405 void FlashDetectorConstruction::ActivateDetArray(G4bool fbool){
406     fActivateDet = fbool;
407 }
408