Geant4  10.03
ML2PhantomConstruction.cc
Go to the documentation of this file.
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 // The code was written by :
27 // ^Claudio Andenna claudio.andenna@ispesl.it, claudio.andenna@iss.infn.it
28 // *Barbara Caccia barbara.caccia@iss.it
29 // with the support of Pablo Cirrone (LNS, INFN Catania Italy)
30 // with the contribute of Alessandro Occhigrossi*
31 //
32 // ^INAIL DIPIA - ex ISPESL and INFN Roma, gruppo collegato Sanità, Italy
33 // *Istituto Superiore di Sanità and INFN Roma, gruppo collegato Sanità, Italy
34 // Viale Regina Elena 299, 00161 Roma (Italy)
35 // tel (39) 06 49902246
36 // fax (39) 06 49387075
37 //
38 // more information:
39 // http://g4advancedexamples.lngs.infn.it/Examples/medical-linac
40 //
41 //*******************************************************//
42 
45 #include "G4SystemOfUnits.hh"
46 
47 CML2PhantomConstruction::CML2PhantomConstruction(void): PVPhmWorld(0), sensDet(0)
48 {
51 }
52 
54 {
55  if (phantomName=="fullWater")
56  {
57  delete Ph_fullWater;
58  }
59  else if (phantomName=="boxInBox")
60  {
61  delete Ph_BoxInBox;
62  }
63 }
64 
66 
68 {
69  if (instance == 0)
70  {
72 
73  }
74  return instance;
75 }
77 {
78 // switch between two different phantoms according to the main macro selection
79  bool bPhanExists=false;
80 
81  std::cout << "I'm building "<< phantomName<<" phantom"<< G4endl;
82 
83  if (phantomName=="fullWater")
84  {
85  Ph_fullWater=new CML2Ph_FullWater();bPhanExists=true;
87  }
88  else if (phantomName=="boxInBox")
89  {
90  Ph_BoxInBox=new CML2Ph_BoxInBox();bPhanExists=true;
92  }
93 
94  if (centre.size()<1)
95  {addNewCentre(G4ThreeVector(0.,0.,0.));}
96  return bPhanExists;
97 }
99 {
100  if (phantomName=="fullWater")
102  else if (phantomName=="boxInBox")
104  return 0;
105 }
106 
108  G4int saving_in_ROG_Voxels_every_events, G4int seed,
109  G4String ROGOutFile, G4bool bSaveROG, G4bool bOV)
110 {
111  idVolumeName=0;
112  bOnlyVisio=bOV;
113 // a call to select the right phantom
114  if(design())
115  {
116  phantomContstructionMessenger->SetReferenceWorld(bOV); // create the phantom-world box
117  G4Material *Vacuum=G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
118 
119  G4Box *phmWorldB = new G4Box("phmWorldG", halfPhantomInsideSize.getX(), halfPhantomInsideSize.getY(), halfPhantomInsideSize.getZ());
120  G4LogicalVolume *phmWorldLV = new G4LogicalVolume(phmWorldB, Vacuum, "phmWorldL", 0, 0, 0);
121  G4VisAttributes* simpleAlSVisAtt= new G4VisAttributes(G4Colour::White());
122  simpleAlSVisAtt->SetVisibility(false);
123 // simpleAlSVisAtt->SetForceWireframe(false);
124  phmWorldLV->SetVisAttributes(simpleAlSVisAtt);
125 
126 
127  PVPhmWorld= new G4PVPlacement(0, G4ThreeVector(0.,0.,0.), "phmWorldPV", phmWorldLV, PVWorld, false, 0);
128 
129  // create the actual phantom
130  if (phantomName=="fullWater")
131  {
132  Ph_fullWater->Construct(PVPhmWorld, saving_in_ROG_Voxels_every_events, seed, ROGOutFile, bSaveROG);
136  }
137  else if (phantomName=="boxInBox")
138  {
139  Ph_BoxInBox->Construct(PVPhmWorld, saving_in_ROG_Voxels_every_events, seed, ROGOutFile, bSaveROG);
143  }
144  // I create the data base volumeName-volumeID in the sensitive detector
145 
147  }
148  else
149  {
150  return false;
151  }
152  return true;
153 }
155 {
156  SvolumeNameId svnid;
157  for (int i=0;i< nMatNames; i++)
158  {
159  svnid.volumeId=i;
160  svnid.volumeName=matNames[i];
161  volumeNameIdLink.push_back(svnid);
162  }
163 }
165 {
166  int nLVD1;
167  nLVD1=(int) PV->GetLogicalVolume()->GetNoDaughters();
168  SvolumeNameId svnid;
169  std::cout << "PV in name: " <<PV->GetName() << G4endl;
170  if (nLVD1>0)
171  {
172  for (int i=0; i <nLVD1; i++)
173  {
175  }
176  idVolumeName++;
177  svnid.volumeId=idVolumeName;
179  volumeNameIdLink.push_back(svnid);
180  std::cout << "physical volume name: " <<svnid.volumeName << G4endl;
181  }
182  else
183  {
184  idVolumeName++;
185  svnid.volumeId=idVolumeName;
187  volumeNameIdLink.push_back(svnid);
188  std::cout << "physical volume name: " <<svnid.volumeName << G4endl;
189  }
190 }
192 {
193  if (idCurrentCentre <(int) centre.size())
194  {
197  idCurrentCentre++;
198  return true;
199  }
200  return false;
201 }
203 {
204  if (!bOnlyVisio)
205  {std::cout <<"Actual centre: "<<idCurrentCentre<<"/"<<centre.size() <<" "<< G4endl;}
206  std::cout <<"Phantom and its ROG centre: " << currentCentre<< G4endl;
207 }
209 {
210  if (sensDet!=0)
211  {
212  currentCentre=ctr;
219  }
220 }
222 {
223  char cT[5];
224  G4int cTI;
225  G4String translationName;
226  cTI=(G4int)((currentCentre.getX()/mm));
227  sprintf(cT,"%d",cTI);
228  translationName="_TrX"+G4String(cT)+"_";
229  cTI=(G4int)((currentCentre.getY()/mm));
230  sprintf(cT,"%d",cTI);
231  translationName+="Y"+G4String(cT)+"_";
232  cTI=(G4int)((currentCentre.getZ()/mm));
233  sprintf(cT,"%d",cTI);
234  translationName+="Z"+G4String(cT);
235  return translationName;
236 }
237 
CML2SDWithVoxels * getSensDet()
void GeometryHasBeenModified(G4bool prop=true)
void setVolumeNameIdLink(std::vector< SvolumeNameId > volNameIdLink)
G4ThreeVector getHalfContainerSize()
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static constexpr double mm
Definition: G4SIunits.hh:115
G4Material * GetMaterial() const
G4ThreeVector getHalfContainerSize()
CLHEP::Hep3Vector G4ThreeVector
bool Construct(G4VPhysicalVolume *PVWorld, G4int saving_in_ROG_Voxels_every_events, G4int seed, G4String ROGOutFile, G4bool bSaveROG, G4bool bOnlyVisio)
static CML2PhantomConstruction * instance
Definition: G4Box.hh:64
const G4String & GetName() const
Definition: G4Material.hh:178
G4VPhysicalVolume * GetDaughter(const G4int i) const
G4int getTotalNumberOfEvents()
G4VPhysicalVolume * getPhysicalVolume()
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
void addNewCentre(G4ThreeVector val)
G4int getTotalNumberOfEvents()
G4String volumeName
const G4String & GetName() const
long seed
Definition: chem4.cc:68
void SetVisibility(G4bool=true)
bool G4bool
Definition: G4Types.hh:79
void SetTranslation(const G4ThreeVector &v)
G4VReadOutGeometry * GetROgeometry() const
static G4GeometryManager * GetInstance()
G4int GetNoDaughters() const
G4VPhysicalVolume * getPhysicalVolume()
G4VPhysicalVolume * PVPhmWorld
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4LogicalVolume * GetLogicalVolume() const
CML2SDWithVoxels * getSensDet()
bool Construct(G4VPhysicalVolume *PVWorld, G4int saving_in_ROG_Voxels_every_events, G4int seed, G4String ROGOutFile, G4bool bSaveROG)
void createPhysicalVolumeNamesList(G4String *matNames, G4int nMatNames)
bool Construct(G4VPhysicalVolume *PVWorld, G4int saving_in_ROG_Voxels_every_events, G4int seed, G4String ROGOutFile, G4bool bSaveROG)
std::vector< SvolumeNameId > volumeNameIdLink
#define G4endl
Definition: G4ios.hh:61
void OpenGeometry(G4VPhysicalVolume *vol=0)
std::vector< G4ThreeVector > centre
CML2PhantomConstructionMessenger * phantomContstructionMessenger
static CML2PhantomConstruction * GetInstance(void)
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=0)
static G4Colour White()
Definition: G4Colour.hh:143
G4VPhysicalVolume * GetROWorld() const