60 fPartialPhantomParam = 0;
107 ConstructPhantomContainer();
114 void DicomPartialDetectorConstruction::ReadPhantomData()
116 std::ifstream finDF(
"Data.dat");
118 if(finDF.good() != 1 ) {
119 G4Exception(
" DicomPartialDetectorConstruction::ReadPhantomData",
122 " Problem reading data file: Data.dat");
126 finDF >> compression;
130 if( numFiles != 1 ) {
131 G4Exception(
"DicomPartialDetectorConstruction::ReadPhantomData",
134 "More than 1 DICOM file is not supported");
136 for(
G4int i = 0; i < numFiles; i++ ) {
140 ReadPhantomDataFile(fname);
148 void DicomPartialDetectorConstruction::ReadPhantomDataFile(
const G4String& fname)
152 G4cout <<
" DicomDetectorConstruction::ReadPhantomDataFile opening file " << fname <<
G4endl;
155 if( !
fin.is_open() ) {
156 G4Exception(
"DicomPartialDetectorConstruction::ReadPhantomDataFile",
159 G4String(
"File not found " + fname).c_str());
165 for(
G4int ii = 0; ii < nMaterials; ii++ ){
166 fin >> nmate >> stemp;
167 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData reading nmate " << ii <<
" = " << nmate <<
" mate " << stemp <<
G4endl;
168 if( ii != nmate )
G4Exception(
"DicomPartialDetectorConstruction::ReadPhantomData",
171 "Material number should be in increasing order: wrong material number ");
176 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData nVoxel X/Y/Z " <<
fNVoxelX <<
" " <<
fNVoxelY <<
" " << fNVoxelZ <<
G4endl;
177 fin >> fOffsetX >> fDimX;
178 fDimX = (fDimX - fOffsetX)/
fNVoxelX;
179 fin >> fOffsetY >> fDimY;
180 fDimY = (fDimY - fOffsetY)/
fNVoxelY;
181 fin >> fOffsetZ >> fDimZ;
182 fDimZ = (fDimZ - fOffsetZ)/fNVoxelZ;
183 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData voxelDimX " << fDimX <<
" fOffsetX " << fOffsetX <<
G4endl;
184 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData voxelDimY " << fDimY <<
" fOffsetY " << fOffsetY <<
G4endl;
185 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData voxelDimZ " << fDimZ <<
" fOffsetZ " << fOffsetZ <<
G4endl;
192 int ifxmin1, ifxmax1;
194 std::map< G4int, G4int > ifmin, ifmax;
196 fin >> ifxmin1 >> ifxmax1;
201 G4int ifxdiff = ifxmax1-ifxmin1+1;
202 if( ifxmax1 == -1 && ifxmin1 == -1 ) ifxdiff = 0;
204 fFilledIDs.insert(std::pair<size_t,size_t>(ifxdiff+fNVoxels-1, ifxmin1));
205 G4cout <<
"DicomPartialDetectorConstruction::ReadPhantomData insert FilledIDs " << ifxdiff+fNVoxels-1 <<
" min " << ifxmin1 <<
" N= " << fFilledIDs.size() <<
G4endl;
210 if( ix >=
G4int(ifxmin1) && ix <=
G4int(ifxmax1) ) {
218 fFilledMins[
iz] = ifmin;
219 fFilledMaxs[
iz] = ifmax;
224 fMateIDs =
new size_t[fNVoxelX*fNVoxelY*
fNVoxelZ];
227 std::map< G4int, G4int > ifmin = fFilledMins[
iz];
228 std::map< G4int, G4int > ifmax = fFilledMaxs[
iz];
233 if( ix >=
G4int(ifxmin1) && ix <=
G4int(ifxmax1) ) {
235 if( mateID1 < 0 || mateID1 >= nMaterials ) {
236 G4Exception(
"DicomPartialDetectorConstruction::ReadPhantomData",
239 G4String(
"Wrong index in phantom file: It should be between 0 and "
244 fMateIDs[copyNo] = mateID1;
251 ReadVoxelDensitiesPartial(
fin );
257 void DicomPartialDetectorConstruction::ReadVoxelDensitiesPartial( std::ifstream&
fin )
259 std::map<G4int, std::pair<G4double,G4double> > densiMinMax;
260 std::map<G4int, std::pair<G4double,G4double> >::iterator mpite;
266 char*
part = getenv(
"DICOM_CHANGE_MATERIAL_DENSITY" );
270 std::map<G4int,G4double> densityDiffs;
271 if( densityDiff != -1. ) {
273 densityDiffs[ii] = densityDiff;
286 std::map< std::pair<G4Material*,G4int>,
matInfo* > newMateDens;
289 size_t ifxmin1, ifxmax1;
294 std::map< G4int, G4int > ifmin = fFilledMins[
iz];
295 std::map< G4int, G4int > ifmax = fFilledMaxs[
iz];
300 if( ix >=
G4int(ifxmin1) && ix <=
G4int(ifxmax1) ) {
305 mpite = densiMinMax.find( fMateIDs[copyNo] );
306 if( dens1 < (*mpite).second.first ) (*mpite).second.first = dens1;
307 if( dens1 > (*mpite).second.second ) (*mpite).second.second = dens1;
310 int mateID = fMateIDs[copyNo];
320 G4int densityBin = 0;
323 if( densityDiff != -1.) {
324 densityBin = (
G4int(dens1/densityDiffs[mateID]));
329 std::pair<G4Material*,G4int> matdens(mate, densityBin );
331 std::map< std::pair<G4Material*,G4int>,
matInfo* >::iterator mppite = newMateDens.find( matdens );
332 if( mppite != newMateDens.end() ){
333 matInfo* mi = (*mppite).second;
342 mi->
id = newMateDens.size()+1;
343 newMateDens[matdens] = mi;
357 std::vector<G4Material*>::const_iterator mimite;
359 fPhantomMaterials.push_back( (*mimite) );
363 std::map< std::pair<G4Material*,G4int>,
matInfo* >::iterator mppite;
364 for( mppite= newMateDens.begin(); mppite != newMateDens.end(); mppite++ ){
365 G4double averdens = (*mppite).second->
sumdens/(*mppite).second->nvoxels;
367 G4cout <<
"GmReadPhantomGeometry::ReadVoxelDensities AVER DENS " << averdens <<
" -> " << saverdens <<
" -> " <<
G4int(1000*averdens) <<
" " <<
G4int(1000*averdens)/1000 <<
" " <<
G4int(1000*averdens)/1000. <<
G4endl;
369 G4cout <<
"GmReadPhantomGeometry::ReadVoxelDensities AVER DENS " << averdens <<
" -> " << saverdens <<
" -> " <<
G4UIcommand::ConvertToString(saverdens) <<
" Nvoxels " <<(*mppite).second->nvoxels <<
G4endl;
377 void DicomPartialDetectorConstruction::ConstructPhantomContainer()
383 G4String contname=
"PhantomContainer";
386 G4Tubs* container_tube =
new G4Tubs(contname,0., 200., 100., 0., 360*
deg);
410 void DicomPartialDetectorConstruction::ConstructPhantom()
413 G4bool bSkipEqualMaterials = 0;
414 G4int regStructureID = 2;
420 G4Box* phantom_solid =
new G4Box(voxelName, fDimX/2., fDimY/2., fDimZ/2. );
438 fPartialPhantomParam->
SetMaterials( fPhantomMaterials );
440 fPartialPhantomParam->
SetNoVoxel( fNVoxelX, fNVoxelY, fNVoxelZ );
453 if( OptimAxis ==
"kUndefined" ) {
456 }
else if( OptimAxis ==
"kXAxis" ) {
460 kXAxis, fNVoxels, fPartialPhantomParam);
463 G4Exception(
"GmReadPhantomGeometry::ConstructPhantom",
466 (
G4String(
"Wrong argument to parameter GmReadPhantomGeometry:Phantom:OptimAxis: Only allowed 'kUndefined' or 'kXAxis', it is: "+OptimAxis).c_str()));