61 fPartialPhantomParam(0),
108 ConstructPhantomContainer();
115 void DicomPartialDetectorConstruction::ReadPhantomData()
118 std::ifstream finDF(dataFile.c_str());
120 if(finDF.good() != 1 ) {
121 G4Exception(
" DicomPartialDetectorConstruction::ReadPhantomData",
124 " Problem reading data file: Data.dat");
128 finDF >> compression;
132 if( numFiles != 1 ) {
133 G4Exception(
"DicomPartialDetectorConstruction::ReadPhantomData",
136 "More than 1 DICOM file is not supported");
138 for(
G4int i = 0; i < numFiles; i++ ) {
142 ReadPhantomDataFile(fname);
150 void DicomPartialDetectorConstruction::ReadPhantomDataFile(
const G4String& fname)
154 G4cout <<
" DicomDetectorConstruction::ReadPhantomDataFile opening file " << fname <<
G4endl;
157 if( !
fin.is_open() ) {
158 G4Exception(
"DicomPartialDetectorConstruction::ReadPhantomDataFile",
161 G4String(
"File not found " + fname).c_str());
167 for(
G4int ii = 0; ii < nMaterials; ii++ ){
168 fin >> nmate >> stemp;
169 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData reading nmate "
170 << ii <<
" = " << nmate <<
" mate " << stemp <<
G4endl;
171 if( ii != nmate )
G4Exception(
"DicomPartialDetectorConstruction::ReadPhantomData",
174 "Material number should be in increasing order: \
175 wrong material number ");
180 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData nVoxel X/Y/Z "
182 fin >> fOffsetX >> fDimX;
183 fDimX = (fDimX - fOffsetX)/
fNVoxelX;
184 fin >> fOffsetY >> fDimY;
185 fDimY = (fDimY - fOffsetY)/
fNVoxelY;
186 fin >> fOffsetZ >> fDimZ;
187 fDimZ = (fDimZ - fOffsetZ)/fNVoxelZ;
188 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData voxelDimX "
189 << fDimX <<
" fOffsetX " << fOffsetX <<
G4endl;
190 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData voxelDimY "
191 << fDimY <<
" fOffsetY " << fOffsetY <<
G4endl;
192 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData voxelDimZ "
193 << fDimZ <<
" fOffsetZ " << fOffsetZ <<
G4endl;
200 int ifxmin1, ifxmax1;
202 std::map< G4int, G4int > ifmin, ifmax;
204 fin >> ifxmin1 >> ifxmax1;
209 G4int ifxdiff = ifxmax1-ifxmin1+1;
210 if( ifxmax1 == -1 && ifxmin1 == -1 ) ifxdiff = 0;
212 fFilledIDs.insert(std::pair<size_t,size_t>(ifxdiff+fNVoxels-1, ifxmin1));
213 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData insert FilledIDs "
214 << ifxdiff+fNVoxels-1 <<
" min " << ifxmin1 <<
" N= " << fFilledIDs.size() <<
G4endl;
221 if( ix >=
G4int(ifxmin1) && ix <=
G4int(ifxmax1) ) {
229 fFilledMins[
iz] = ifmin;
230 fFilledMaxs[
iz] = ifmax;
235 fMateIDs =
new size_t[fNVoxelX*fNVoxelY*
fNVoxelZ];
238 std::map< G4int, G4int > ifmin = fFilledMins[
iz];
239 std::map< G4int, G4int > ifmax = fFilledMaxs[
iz];
244 if( ix >=
G4int(ifxmin1) && ix <=
G4int(ifxmax1) ) {
246 if( mateID1 < 0 || mateID1 >= nMaterials ) {
247 G4Exception(
"DicomPartialDetectorConstruction::ReadPhantomData",
250 G4String(
"Wrong index in phantom file: It should be between 0 and "
255 fMateIDs[copyNo] = mateID1;
262 ReadVoxelDensitiesPartial(
fin );
268 void DicomPartialDetectorConstruction::ReadVoxelDensitiesPartial( std::ifstream&
fin )
270 std::map<G4int, std::pair<G4double,G4double> > densiMinMax;
271 std::map<G4int, std::pair<G4double,G4double> >::iterator mpite;
277 char*
part = getenv(
"DICOM_CHANGE_MATERIAL_DENSITY" );
280 std::map<G4int,G4double> densityDiffs;
281 if( densityDiff != -1. ) {
283 densityDiffs[ii] = densityDiff;
296 std::map< std::pair<G4Material*,G4int>,
matInfo* > newMateDens;
299 size_t ifxmin1, ifxmax1;
304 std::map< G4int, G4int > ifmin = fFilledMins[
iz];
305 std::map< G4int, G4int > ifmax = fFilledMaxs[
iz];
310 if( ix >=
G4int(ifxmin1) && ix <=
G4int(ifxmax1) ) {
316 mpite = densiMinMax.find( fMateIDs[copyNo] );
317 if( dens1 < (*mpite).second.first ) (*mpite).second.first = dens1;
318 if( dens1 > (*mpite).second.second ) (*mpite).second.second = dens1;
321 int mateID = fMateIDs[copyNo];
325 if( std::fabs(dens1 - mate->
GetDensity()/
g*
cm3 ) < 1.e-9 )
continue;
332 G4int densityBin = 0;
336 if( densityDiff != -1.) {
337 densityBin = (
G4int(dens1/densityDiffs[mateID]));
342 std::pair<G4Material*,G4int> matdens(mate, densityBin );
344 std::map< std::pair<G4Material*,G4int>,
matInfo* >::iterator mppite
345 = newMateDens.find( matdens );
346 if( mppite != newMateDens.end() ){
347 matInfo* mi = (*mppite).second;
357 mi->
id = newMateDens.size()+1;
358 newMateDens[matdens] = mi;
374 std::vector<G4Material*>::const_iterator mimite;
376 fPhantomMaterials.push_back( (*mimite) );
380 std::map< std::pair<G4Material*,G4int>,
matInfo* >::iterator mppite;
381 for( mppite= newMateDens.begin(); mppite != newMateDens.end(); mppite++ ){
382 G4double averdens = (*mppite).second->
sumdens/(*mppite).second->nvoxels;
384 G4cout <<
"GmReadPhantomGeometry::ReadVoxelDensities AVER DENS " << averdens <<
" -> "
385 << saverdens <<
" -> " <<
G4int(1000*averdens) <<
" " <<
G4int(1000*averdens)/1000 <<
" "
388 G4cout <<
"GmReadPhantomGeometry::ReadVoxelDensities AVER DENS " << averdens <<
" -> "
390 <<(*mppite).second->nvoxels <<
G4endl;
391 G4String mateName = ((*mppite).first).
first->GetName() +
"_" +
394 averdens, mateName ) );
400 void DicomPartialDetectorConstruction::ConstructPhantomContainer()
406 G4String contname=
"PhantomContainer";
409 G4Tubs* container_tube =
new G4Tubs(contname,0., 200., 100., 0., 360*
deg);
433 void DicomPartialDetectorConstruction::ConstructPhantom()
436 G4bool bSkipEqualMaterials = 0;
437 G4int regStructureID = 2;
443 G4Box* phantom_solid =
new G4Box(voxelName, fDimX/2., fDimY/2., fDimZ/2. );
461 fPartialPhantomParam->
SetMaterials( fPhantomMaterials );
463 fPartialPhantomParam->
SetNoVoxel( fNVoxelX, fNVoxelY, fNVoxelZ );
476 if( OptimAxis ==
"kUndefined" ) {
479 }
else if( OptimAxis ==
"kXAxis" ) {
483 kXAxis, fNVoxels, fPartialPhantomParam);
486 G4Exception(
"GmReadPhantomGeometry::ConstructPhantom",
489 (
G4String(
"Wrong argument to parameter GmReadPhantomGeometry:Phantom:OptimAxis:\
490 Only allowed 'kUndefined' or 'kXAxis', it is: "+OptimAxis).c_str()));
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
G4LogicalVolume * fWorld_logic
const G4String & GetName() const
G4double GetDensity() const
static G4String ConvertToString(G4bool boolVal)
void SetFilledIDs(std::multimap< G4int, G4int > fid)
G4LogicalVolume * fContainer_logic
void InitialisationOfMaterials()
~DicomPartialDetectorConstruction()
G4Material * BuildMaterialWithChangingDensity(const G4Material *origMate, float density, G4String newMateName)
G4GLOB_DLL std::ostream G4cout
void SetVoxelDimensions(G4double halfx, G4double halfy, G4double halfz)
Definition of the DicomPartialDetectorConstruction class.
void SetFilledMins(std::map< G4int, std::map< G4int, G4int > > fmins)
static G4double ConvertToDouble(const char *st)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual void SetRegularStructureId(G4int Code)
G4VPhysicalVolume * fContainer_phys
virtual G4VPhysicalVolume * Construct()
void SetSmartless(G4double s)
void BuildContainerWalls()
void SetNoVoxel(size_t nx, size_t ny, size_t nz)
void SetMaterialIndices(size_t *matInd)
DicomPartialDetectorConstruction()
void SetMaterials(std::vector< G4Material * > &mates)
std::vector< G4Material * > fMaterials
std::vector< G4Material * > fOriginalMaterials
void SetVisAttributes(const G4VisAttributes *pVA)
void SetSkipEqualMaterials(G4bool skip)