Changeset 1337 for trunk/examples/extended/medical/DICOM/src
- Timestamp:
- Sep 30, 2010, 2:47:17 PM (14 years ago)
- Location:
- trunk/examples/extended/medical/DICOM/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/extended/medical/DICOM/src/DicomDetectorConstruction.cc
r1230 r1337 314 314 G4double densityDiff = 0.1; 315 315 std::map<G4int,G4double> fDensityDiffs; // to be able to use a different densityDiff for each material 316 for( size_t ii = 0; ii < fOriginalMaterials.size(); ii++ ){316 for( unsigned int ii = 0; ii < fOriginalMaterials.size(); ii++ ){ 317 317 fDensityDiffs[ii] = densityDiff; //currently all materials with same difference 318 318 } … … 327 327 //--- If first slice, initiliaze fMateIDs 328 328 if( fZSliceHeaders.size() == 1 ) { 329 //fMateIDs = new unsigned int[fNoFiles*nVoxels]; 329 330 fMateIDs = new size_t[fNoFiles*nVoxels]; 330 } 331 332 size_t mateID; 331 332 } 333 334 unsigned int mateID; 333 335 G4int voxelCopyNo = (fZSliceHeaders.size()-1)*nVoxels; // number of voxels from previously read slices 334 336 for( G4int ii = 0; ii < nVoxels; ii++, voxelCopyNo++ ){ … … 353 355 354 356 //-- Look if a material with this name is already created (because a previous voxel was already in this density bin) 355 size_t im;357 unsigned int im; 356 358 for( im = 0; im < fMaterials.size(); im++ ){ 357 359 if( fMaterials[im]->GetName() == newMateName ) { … … 377 379 //----- Images must have the same dimension ... 378 380 fZSliceHeaderMerged = new DicomPatientZSliceHeader( *fZSliceHeaders[0] ); 379 for( size_t ii = 1; ii < fZSliceHeaders.size(); ii++ ) {381 for( unsigned int ii = 1; ii < fZSliceHeaders.size(); ii++ ) { 380 382 *fZSliceHeaderMerged += *fZSliceHeaders[ii]; 381 383 }; -
trunk/examples/extended/medical/DICOM/src/DicomEventAction.cc
r807 r1337 42 42 #include "DicomEventAction.hh" 43 43 #include "G4Event.hh" 44 #include "G4TrajectoryContainer.hh"45 #include "G4Trajectory.hh"46 #include "G4VVisManager.hh"47 44 48 45 DicomEventAction::DicomEventAction():drawFlag("all") … … 55 52 { 56 53 G4cout << "EV: " << evt->GetEventID() << G4endl; 57 }58 59 void DicomEventAction::EndOfEventAction(const G4Event* evt)60 {61 // extract the trajectories and draw them62 63 if (G4VVisManager::GetConcreteInstance())64 {65 G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer();66 G4int nTrajectories = 0;67 if ( trajectoryContainer )68 nTrajectories = trajectoryContainer->entries();69 70 for ( G4int i = 0;i < nTrajectories; i++ )71 {72 G4Trajectory* trj = (G4Trajectory*)((*(evt->GetTrajectoryContainer()))[i]);73 if (drawFlag == "all")74 trj->DrawTrajectory(50);75 else if ((drawFlag == "charged")&&(trj->GetCharge() != 0.))76 trj->DrawTrajectory(50);77 else if ((drawFlag == "neutral")&&(trj->GetCharge() == 0.))78 trj->DrawTrajectory(50);79 }80 }81 54 } 82 55 56 void DicomEventAction::EndOfEventAction(const G4Event*) 57 { 58 } -
trunk/examples/extended/medical/DICOM/src/DicomHandler.cc
r807 r1337 61 61 62 62 DicomHandler::DicomHandler() 63 : DATABUFFSIZE(8192), LINEBUFFSIZE( 128), FILENAMESIZE(512),63 : DATABUFFSIZE(8192), LINEBUFFSIZE(5020), FILENAMESIZE(512), 64 64 compression(0), nFiles(0), rows(0), columns(0), 65 65 bitAllocated(0), maxPixelValue(0), minPixelValue(0), … … 98 98 short readElementId; // identify a particular type information 99 99 short elementLength2; // deal with element length in 2 bytes 100 //unsigned int elementLength4; // deal with element length in 4 bytes 100 101 G4int elementLength4; // deal with element length in 4 bytes 101 102 102 103 char * data = new char[DATABUFFSIZE]; 103 104 105 104 106 // Read information up to the pixel data 105 107 while(true) { … … 117 119 // Creating a tag to be identified afterward 118 120 G4int tagDictionary = readGroupId*0x10000 + readElementId; 119 120 121 // VR or element length 121 122 // beginning of the pixels 123 if(tagDictionary == 0x7FE00010) break; 124 125 // VR or element length 122 126 std::fread(buffer,2,1,dicom); 123 127 GetValue(buffer, elementLength2); 124 125 // If value representation (VR) is OB, OW, SQ, UN,128 129 // If value representation (VR) is OB, OW, SQ, UN, added OF and UT 126 130 //the next length is 32 bits 127 131 if((elementLength2 == 0x424f || // "OB" 128 132 elementLength2 == 0x574f || // "OW" 129 elementLength2 == 0x5153 || // "SQ" 133 elementLength2 == 0x464f || // "OF" 134 elementLength2 == 0x5455 || // "UT" 135 elementLength2 == 0x5153 || // "SQ" 130 136 elementLength2 == 0x4e55) && // "UN" 131 137 !implicitEndian ) { // explicit VR … … 136 142 std::fread(buffer, 4, 1, dicom); 137 143 GetValue(buffer, elementLength4); 138 139 // beginning of the pixels 140 if(tagDictionary == 0x7FE00010) break; 141 144 145 if(elementLength2 == 0x5153) 146 { 147 if(elementLength4 == 0xFFFFFFFF) 148 read_undefined_nested( dicom ); 149 else{ 150 if(read_defined_nested( dicom, elementLength4 )==0){ 151 G4cerr << "Reading defined nested functin failed!" << G4endl; 152 exit(-10); } 153 } 154 } else { 142 155 // Reading the information with data 143 156 std::fread(data, elementLength4,1,dicom); 144 145 146 } else { // length is 16 bits : 147 148 if(!implicitEndian || readGroupId == 2) { 149 // element length (2 bytes) 150 std::fread(buffer, 2, 1, dicom); 151 GetValue(buffer, elementLength2); 152 elementLength4 = elementLength2; 153 154 } else { 155 // element length (4 bytes) 156 if(std::fseek(dicom, -2, SEEK_CUR) != 0) { 157 G4cerr << "[DicomHandler] fseek failed" << G4endl; 158 exit(-10); 159 } 160 std::fread(buffer, 4, 1, dicom); 161 GetValue(buffer, elementLength4); 162 } 163 164 // beginning of the pixels 165 if(tagDictionary == 0x7FE00010) break; 166 167 std::fread(data, elementLength4, 1, dicom); 157 } 158 159 160 } else { 161 162 if(!implicitEndian || readGroupId == 2) { // explicit with VR different than previous ones 163 164 //G4cout << "Reading DICOM files with Explicit VR"<< G4endl; 165 // element length (2 bytes) 166 std::fread(buffer, 2, 1, dicom); 167 GetValue(buffer, elementLength2); 168 elementLength4 = elementLength2; 169 170 171 172 std::fread(data, elementLength4, 1, dicom); 173 174 } else { // Implicit VR 175 176 //G4cout << "Reading DICOM files with Implicit VR"<< G4endl; 177 178 // element length (4 bytes) 179 if(std::fseek(dicom, -2, SEEK_CUR) != 0) { 180 G4cerr << "[DicomHandler] fseek failed" << G4endl; 181 exit(-10);} 182 183 std::fread(buffer, 4, 1, dicom); 184 GetValue(buffer, elementLength4); 185 186 //G4cout << std::hex<< elementLength4 << G4endl; 187 188 if(elementLength4 == 0xFFFFFFFF) 189 read_undefined_nested(dicom); 190 else { 191 192 193 std::fread(data, elementLength4, 1, dicom); 194 195 } 196 197 } 168 198 } 169 199 … … 179 209 G4String fnameG4DCM = G4String(filename2) + ".g4dcm"; 180 210 foutG4DCM.open(fnameG4DCM); 181 G4cout << " opened fnameG4DCM file " << fnameG4DCM<< G4endl;211 G4cout << "### Writing of " << fnameG4DCM << " ### " << G4endl; 182 212 183 213 foutG4DCM << fMaterialIndices.size() << G4endl; 184 214 //--- Write materials 185 size_t ii = 0;186 std::map<G4 double,G4String>::const_iterator ite;215 unsigned int ii = 0; 216 std::map<G4float,G4String>::const_iterator ite; 187 217 for( ite = fMaterialIndices.begin(); ite != fMaterialIndices.end(); ite++, ii++ ){ 188 218 foutG4DCM << ii << " " << (*ite).second << G4endl; … … 194 224 foutG4DCM << -pixelSpacingY*columns/2 << " " << pixelSpacingY*columns/2 << G4endl; 195 225 foutG4DCM << sliceLocation-sliceThickness/2. << " " << sliceLocation+sliceThickness/2. << G4endl; 226 // foutG4DCM << compression << G4endl; 196 227 197 228 ReadData( dicom, filename2 ); … … 431 462 void DicomHandler::ReadMaterialIndices( std::ifstream& finData) 432 463 { 433 size_t nMate;464 unsigned int nMate; 434 465 G4String mateName; 435 G4 doubledensityMax;466 G4float densityMax; 436 467 finData >> nMate; 437 468 if( finData.eof() ) return; 438 469 439 470 G4cout << " ReadMaterialIndices " << nMate << G4endl; 440 for( size_t ii = 0; ii < nMate; ii++ ){471 for( unsigned int ii = 0; ii < nMate; ii++ ){ 441 472 finData >> mateName >> densityMax; 442 473 fMaterialIndices[densityMax] = mateName; … … 446 477 } 447 478 448 size_t DicomHandler::GetMaterialIndex( G4doubledensity )479 unsigned int DicomHandler::GetMaterialIndex( G4float density ) 449 480 { 450 size_t mateID; 451 std::map<G4double,G4String>::reverse_iterator ite; 481 std::map<G4float,G4String>::reverse_iterator ite; 452 482 G4int ii = fMaterialIndices.size(); 453 483 for( ite = fMaterialIndices.rbegin(); ite != fMaterialIndices.rend(); ite++, ii-- ) { … … 508 538 509 539 // Creation of .g4 files wich contains averaged density data 510 511 540 char * nameProcessed = new char[FILENAMESIZE]; 512 FILE* processed;513 514 std::sprintf(nameProcessed,"%s.g4 ",filename2);515 processed= std::fopen(nameProcessed,"w+b");541 FILE* fileOut; 542 543 std::sprintf(nameProcessed,"%s.g4dcmb",filename2); 544 fileOut = std::fopen(nameProcessed,"w+b"); 516 545 std::printf("### Writing of %s ###\n",nameProcessed); 517 546 518 std::fwrite(&rows, 2, 1, processed); 519 std::fwrite(&columns, 2, 1, processed); 520 std::fwrite(&pixelSpacingX, 8, 1, processed); 521 std::fwrite(&pixelSpacingY, 8, 1, processed); 522 std::fwrite(&sliceThickness, 8, 1, processed); 523 std::fwrite(&sliceLocation, 8, 1, processed); 524 std::fwrite(&compression, 2, 1, processed); 547 unsigned int nMate = fMaterialIndices.size(); 548 std::fwrite(&nMate, sizeof(unsigned int), 1, fileOut); 549 //--- Write materials 550 std::map<G4float,G4String>::const_iterator ite; 551 for( ite = fMaterialIndices.begin(); ite != fMaterialIndices.end(); ite++ ){ 552 G4String mateName = (*ite).second; 553 for( G4int ii = (*ite).second.length(); ii < 40; ii++ ) { 554 mateName += " "; 555 } //mateName = const_cast<char*>(((*ite).second).c_str()); 556 557 const char* mateNameC = mateName.c_str(); 558 std::fwrite(mateNameC, sizeof(char),40, fileOut); 559 } 560 561 unsigned int rowsC = rows/compression; 562 unsigned int columnsC = columns/compression; 563 unsigned int planesC = 1; 564 G4float pixelLocationXM = -pixelSpacingX*rows/2.; 565 G4float pixelLocationXP = pixelSpacingX*rows/2.; 566 G4float pixelLocationYM = -pixelSpacingY*rows/2.; 567 G4float pixelLocationYP = pixelSpacingY*rows/2.; 568 G4float sliceLocationZM = sliceLocation-sliceThickness/2.; 569 G4float sliceLocationZP = sliceLocation+sliceThickness/2.; 570 //--- Write number of voxels (assume only one voxel in Z) 571 std::fwrite(&rowsC, sizeof(unsigned int), 1, fileOut); 572 std::fwrite(&columnsC, sizeof(unsigned int), 1, fileOut); 573 std::fwrite(&planesC, sizeof(unsigned int), 1, fileOut); 574 //--- Write minimum and maximum extensions 575 std::fwrite(&pixelLocationXM, sizeof(G4float), 1, fileOut); 576 std::fwrite(&pixelLocationXP, sizeof(G4float), 1, fileOut); 577 std::fwrite(&pixelLocationYM, sizeof(G4float), 1, fileOut); 578 std::fwrite(&pixelLocationYP, sizeof(G4float), 1, fileOut); 579 std::fwrite(&sliceLocationZM, sizeof(G4float), 1, fileOut); 580 std::fwrite(&sliceLocationZP, sizeof(G4float), 1, fileOut); 581 // std::fwrite(&compression, sizeof(unsigned int), 1, fileOut); 525 582 526 583 std::printf("%8i %8i\n",rows,columns); … … 532 589 G4int compSize = compression; 533 590 G4int mean; 534 G4 doubledensity;591 G4float density; 535 592 G4bool overflow = false; 536 593 G4int cpt=1; 537 594 595 //----- Write index of material for each pixel 538 596 if(compSize == 1) { // no compression: each pixel has a density value) 539 for( G4int ww = 0; ww < rows; ww++) { 540 for( G4int xx = 0; xx < columns; xx++) { 541 mean = tab[ww][xx]; 542 density = Pixel2density(mean); 543 std::fwrite(&density, sizeof(G4double), 1, processed); 544 } 545 } 597 for( G4int ww = 0; ww < rows; ww++) { 598 for( G4int xx = 0; xx < columns; xx++) { 599 mean = tab[ww][xx]; 600 density = Pixel2density(mean); 601 unsigned int mateID = GetMaterialIndex( density ); 602 std::fwrite(&mateID, sizeof(unsigned int), 1, fileOut); 603 } 604 } 546 605 547 606 } else { 548 // density value is the average of a square region of 549 // compression*compression pixels 550 for(G4int ww = 0; ww < rows ;ww += compSize ) { 551 for(G4int xx = 0; xx < columns ;xx +=compSize ) { 552 overflow = false; 553 mean = 0; 554 for(int sumx = 0; sumx < compSize; sumx++) { 555 for(int sumy = 0; sumy < compSize; sumy++) { 556 if(ww+sumy >= rows || xx+sumx >= columns) overflow = true; 557 mean += tab[ww+sumy][xx+sumx]; 558 } 559 if(overflow) break; 560 } 561 mean /= compSize*compSize; 562 cpt = 1; 563 564 if(!overflow) { 565 G4double density = Pixel2density(mean); 566 std::fwrite(&density, sizeof(G4double), 1, processed); 567 } 607 // density value is the average of a square region of 608 // compression*compression pixels 609 for(G4int ww = 0; ww < rows ;ww += compSize ) { 610 for(G4int xx = 0; xx < columns ;xx +=compSize ) { 611 overflow = false; 612 mean = 0; 613 for(int sumx = 0; sumx < compSize; sumx++) { 614 for(int sumy = 0; sumy < compSize; sumy++) { 615 if(ww+sumy >= rows || xx+sumx >= columns) overflow = true; 616 mean += tab[ww+sumy][xx+sumx]; 568 617 } 569 570 } 571 } 572 std::fclose(processed); 573 618 if(overflow) break; 619 } 620 mean /= compSize*compSize; 621 cpt = 1; 622 623 if(!overflow) { 624 density = Pixel2density(mean); 625 unsigned int mateID = GetMaterialIndex( density ); 626 std::fwrite(&mateID, sizeof(unsigned int), 1, fileOut); 627 } 628 } 629 630 } 631 } 632 633 //----- Write density for each pixel 634 if(compSize == 1) { // no compression: each pixel has a density value) 635 for( G4int ww = 0; ww < rows; ww++) { 636 for( G4int xx = 0; xx < columns; xx++) { 637 mean = tab[ww][xx]; 638 density = Pixel2density(mean); 639 std::fwrite(&density, sizeof(G4float), 1, fileOut); 640 } 641 } 642 643 } else { 644 // density value is the average of a square region of 645 // compression*compression pixels 646 for(G4int ww = 0; ww < rows ;ww += compSize ) { 647 for(G4int xx = 0; xx < columns ;xx +=compSize ) { 648 overflow = false; 649 mean = 0; 650 for(int sumx = 0; sumx < compSize; sumx++) { 651 for(int sumy = 0; sumy < compSize; sumy++) { 652 if(ww+sumy >= rows || xx+sumx >= columns) overflow = true; 653 mean += tab[ww+sumy][xx+sumx]; 654 } 655 if(overflow) break; 656 } 657 mean /= compSize*compSize; 658 cpt = 1; 659 660 if(!overflow) { 661 density = Pixel2density(mean); 662 std::fwrite(&density, sizeof(G4float), 1, fileOut); 663 } 664 } 665 666 } 667 } 668 669 std::fclose(fileOut); 670 574 671 delete [] nameProcessed; 575 672 … … 595 692 */ 596 693 597 G4 doubleDicomHandler::Pixel2density(G4int pixel)694 G4float DicomHandler::Pixel2density(G4int pixel) 598 695 { 599 G4 doubledensity = -1.;696 G4float density = -1.; 600 697 G4int nbrequali = 0; 601 698 G4double deltaCT = 0; … … 752 849 _rval = *(Type *)_val; 753 850 } 851 852 G4int DicomHandler::read_defined_nested(FILE * nested,G4int SQ_Length) 853 { 854 // VARIABLES 855 unsigned short item_GroupNumber; 856 unsigned short item_ElementNumber; 857 G4int item_Length; 858 G4int items_array_length=0; 859 char * buffer= new char[LINEBUFFSIZE]; 860 861 862 while(items_array_length < SQ_Length) 863 { 864 std::fread(buffer, 2, 1, nested); 865 GetValue(buffer, item_GroupNumber); 866 867 std::fread(buffer, 2, 1, nested); 868 GetValue(buffer, item_ElementNumber); 869 870 std::fread(buffer, 4, 1, nested); 871 GetValue(buffer, item_Length); 872 873 std::fread(buffer, item_Length, 1, nested); 874 875 items_array_length= items_array_length+8+item_Length; 876 } 877 878 delete []buffer; 879 880 if(SQ_Length>items_array_length) 881 return 0; 882 else 883 return 1; 884 885 } 886 887 void DicomHandler::read_undefined_nested(FILE * nested) 888 { 889 // VARIABLES 890 unsigned short item_GroupNumber; 891 unsigned short item_ElementNumber; 892 G4int item_Length; 893 char * buffer= new char[LINEBUFFSIZE]; 894 895 896 do 897 { 898 std::fread(buffer, 2, 1, nested); 899 GetValue(buffer, item_GroupNumber); 900 901 std::fread(buffer, 2, 1, nested); 902 GetValue(buffer, item_ElementNumber); 903 904 std::fread(buffer, 4, 1, nested); 905 GetValue(buffer, item_Length); 906 907 if(item_Length!=0xffffffff) 908 std::fread(buffer, item_Length, 1, nested); 909 else 910 read_undefined_item(nested); 911 912 913 }while(item_GroupNumber!=0xFFFE || item_ElementNumber!=0xE0DD || item_Length!=0); 914 915 delete [] buffer; 916 917 } 918 919 void DicomHandler::read_undefined_item(FILE * nested) 920 { 921 // VARIABLES 922 unsigned short item_GroupNumber; 923 unsigned short item_ElementNumber; 924 G4int item_Length; 925 char *buffer= new char[LINEBUFFSIZE]; 926 927 do 928 { 929 std::fread(buffer, 2, 1, nested); 930 GetValue(buffer, item_GroupNumber); 931 932 std::fread(buffer, 2, 1, nested); 933 GetValue(buffer, item_ElementNumber); 934 935 std::fread(buffer, 4, 1, nested); 936 GetValue(buffer, item_Length); 937 938 939 if(item_Length!=0) 940 std::fread(buffer,item_Length,1,nested); 941 942 } 943 while(item_GroupNumber!=0xFFFE || item_ElementNumber!=0xE00D || item_Length!=0); 944 945 delete []buffer; 946 947 } -
trunk/examples/extended/medical/DICOM/src/DicomNestedPhantomParameterisation.cc
r1230 r1337 24 24 // ******************************************************************** 25 25 // 26 // $Id: DicomNestedPhantomParameterisation.cc,v 1. 5 2009/01/27 10:44:58 gcosmoExp $27 // GEANT4 tag $Name: geant4-09-0 3-cand-01 $26 // $Id: DicomNestedPhantomParameterisation.cc,v 1.6 2009/11/10 18:48:46 arce Exp $ 27 // GEANT4 tag $Name: geant4-09-04-beta-01 $ 28 28 // 29 29 // -------------------------------------------------------------------- … … 53 53 54 54 void DicomNestedPhantomParameterisation:: 55 SetNoVoxel( size_t nx, size_t ny, size_t nz )55 SetNoVoxel( unsigned int nx, unsigned int ny, unsigned int nz ) 56 56 { 57 57 fnX = nx; … … 80 80 G4int copyNo = ix + fnX*iy + fnX*fnY*iz; 81 81 82 size_t matIndex = GetMaterialIndex(copyNo);82 unsigned int matIndex = GetMaterialIndex(copyNo); 83 83 84 84 return fMaterials[ matIndex ]; … … 86 86 87 87 //------------------------------------------------------------------ 88 size_t DicomNestedPhantomParameterisation::89 GetMaterialIndex( size_t copyNo ) const88 unsigned int DicomNestedPhantomParameterisation:: 89 GetMaterialIndex( unsigned int copyNo ) const 90 90 { 91 91 return *(fMaterialIndices+copyNo); -
trunk/examples/extended/medical/DICOM/src/DicomPatientZSliceHeader.cc
r807 r1337 148 148 G4Exception(""); 149 149 } 150 for( size_t ii = 0; ii < fMaterialNames.size(); ii++ ) {150 for( unsigned int ii = 0; ii < fMaterialNames.size(); ii++ ) { 151 151 if( fMaterialNames[ii] != fMaterialNames2[ii] ) { 152 152 G4cerr << "DicomPatientZSliceHeader error adding two slice headers: !!! Different material number " << ii << " : " << fMaterialNames[ii] << " =? " << fMaterialNames2[ii] << G4endl; -
trunk/examples/extended/medical/DICOM/src/DicomPhantomParameterisationColour.cc
r807 r1337 77 77 if( physVol ) { 78 78 G4String mateName = mate->GetName(); 79 size_t iuu = mateName.find("__");79 unsigned int iuu = mateName.find("__"); 80 80 if( iuu != std::string::npos ) { 81 81 mateName = mateName.substr( 0, iuu ); -
trunk/examples/extended/medical/DICOM/src/DicomPhysicsList.cc
r1230 r1337 24 24 // ******************************************************************** 25 25 // 26 // The code was written by : 27 // *Louis Archambault louis.archambault@phy.ulaval.ca, 28 // *Luc Beaulieu beaulieu@phy.ulaval.ca 29 // +Vincent Hubert-Tremblay at tigre.2@sympatico.ca 30 // 31 // 32 // *Centre Hospitalier Universitaire de Quebec (CHUQ), 33 // Hotel-Dieu de Quebec, departement de Radio-oncologie 34 // 11 cote du palais. Quebec, QC, Canada, G1R 2J6 35 // tel (418) 525-4444 #6720 36 // fax (418) 691 5268 37 // 38 // + Université Laval, Québec (QC) Canada 39 // 40 // History: 30.11.07 P.Arce default cut changed to 1 mm 41 //******************************************************* 42 43 #include "DicomPhysicsList.hh" 26 // ------------------------------------------------------------------- 27 // $Id: DicomPhysicsList.cc,v 1.11 2009/10/26 11:20:49 chauvie Exp $ 28 // ------------------------------------------------------------------- 44 29 45 30 #include "G4ParticleDefinition.hh" 46 #include "G4ParticleWithCuts.hh"47 31 #include "G4ProcessManager.hh" 48 32 #include "G4ParticleTypes.hh" 49 #include "G4ParticleTable.hh" 50 #include "G4Material.hh" 51 #include "G4UnitsTable.hh" 52 #include "G4ios.hh" 33 #include "G4StepLimiter.hh" 34 #include "G4BaryonConstructor.hh" 35 #include "G4IonConstructor.hh" 36 #include "G4MesonConstructor.hh" 37 38 #include "DicomPhysicsList.hh" 39 40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 53 41 54 42 DicomPhysicsList::DicomPhysicsList(): G4VUserPhysicsList() 55 43 { 56 defaultCutValue = 1.*mm;57 cutForGamma = 1.*mm;44 defaultCutValue = 0.01*micrometer; 45 cutForGamma = defaultCutValue; 58 46 cutForElectron = defaultCutValue; 59 47 cutForPositron = defaultCutValue; 60 61 SetVerboseLevel(0); 62 } 48 SetVerboseLevel(1); 49 } 50 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 63 52 64 53 DicomPhysicsList::~DicomPhysicsList() 65 54 {} 66 55 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 57 67 58 void DicomPhysicsList::ConstructParticle() 68 59 { 69 // In this method, static member functions should be called70 // for all particles which you want to use.71 // This ensures that objects of these particle types will be72 // created in the program.73 74 60 ConstructBosons(); 75 61 ConstructLeptons(); 76 } 62 ConstructBaryons(); 63 } 64 65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 77 66 78 67 void DicomPhysicsList::ConstructBosons() 79 { 68 { 80 69 // gamma 81 70 G4Gamma::GammaDefinition(); 82 71 83 } 72 // optical photon 73 G4OpticalPhoton::OpticalPhotonDefinition(); 74 } 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 84 76 85 77 void DicomPhysicsList::ConstructLeptons() … … 90 82 } 91 83 84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 85 86 void DicomPhysicsList::ConstructBaryons() 87 { 88 // baryons 89 G4BaryonConstructor bConstructor; 90 bConstructor.ConstructParticle(); 91 92 G4IonConstructor iConstructor; 93 iConstructor.ConstructParticle(); 94 95 G4MesonConstructor mConstructor; 96 mConstructor.ConstructParticle(); 97 } 98 99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 100 92 101 void DicomPhysicsList::ConstructProcess() 93 102 { 94 103 AddTransportation(); 95 104 ConstructEM(); 96 } 97 98 #include "G4MultipleScattering.hh" 105 ConstructHad(); 106 ConstructGeneral(); 107 } 108 109 // *** Processes and models 110 99 111 // gamma 100 #include "G4LowEnergyRayleigh.hh" 101 #include "G4LowEnergyPhotoElectric.hh" 102 #include "G4LowEnergyCompton.hh" 103 #include "G4LowEnergyGammaConversion.hh" 112 113 #include "G4PhotoElectricEffect.hh" 114 #include "G4LivermorePhotoElectricModel.hh" 115 116 #include "G4ComptonScattering.hh" 117 #include "G4LivermoreComptonModel.hh" 118 119 #include "G4GammaConversion.hh" 120 #include "G4LivermoreGammaConversionModel.hh" 121 122 #include "G4RayleighScattering.hh" 123 #include "G4LivermoreRayleighModel.hh" 124 104 125 // e- 105 #include "G4LowEnergyIonisation.hh" 106 #include "G4LowEnergyBremsstrahlung.hh" 126 127 #include "G4eMultipleScattering.hh" 128 #include "G4UniversalFluctuation.hh" 129 130 #include "G4eIonisation.hh" 131 #include "G4LivermoreIonisationModel.hh" 132 133 #include "G4eBremsstrahlung.hh" 134 #include "G4LivermoreBremsstrahlungModel.hh" 135 107 136 // e+ 108 #include "G4eIonisation.hh" 109 #include "G4eBremsstrahlung.hh" 137 110 138 #include "G4eplusAnnihilation.hh" 111 139 140 // mu 141 142 #include "G4MuIonisation.hh" 143 #include "G4MuBremsstrahlung.hh" 144 #include "G4MuPairProduction.hh" 145 146 // hadrons 147 148 #include "G4hMultipleScattering.hh" 149 #include "G4MscStepLimitType.hh" 150 151 #include "G4hBremsstrahlung.hh" 152 #include "G4hPairProduction.hh" 153 154 #include "G4hIonisation.hh" 155 #include "G4ionIonisation.hh" 156 #include "G4IonParametrisedLossModel.hh" 157 158 // 159 160 #include "G4LossTableManager.hh" 161 #include "G4EmProcessOptions.hh" 162 163 164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 165 112 166 void DicomPhysicsList::ConstructEM() 113 167 { 168 theParticleIterator->reset(); 169 170 while( (*theParticleIterator)() ){ 171 172 G4ParticleDefinition* particle = theParticleIterator->value(); 173 G4ProcessManager* pmanager = particle->GetProcessManager(); 174 G4String particleName = particle->GetParticleName(); 175 176 if (particleName == "gamma") { 177 178 179 G4PhotoElectricEffect* thePhotoElectricEffect = new G4PhotoElectricEffect(); 180 G4LivermorePhotoElectricModel* theLivermorePhotoElectricModel = new G4LivermorePhotoElectricModel(); 181 thePhotoElectricEffect->AddEmModel(0, theLivermorePhotoElectricModel); 182 pmanager->AddDiscreteProcess(thePhotoElectricEffect); 183 184 G4ComptonScattering* theComptonScattering = new G4ComptonScattering(); 185 G4LivermoreComptonModel* theLivermoreComptonModel = new G4LivermoreComptonModel(); 186 theComptonScattering->AddEmModel(0, theLivermoreComptonModel); 187 pmanager->AddDiscreteProcess(theComptonScattering); 188 189 G4GammaConversion* theGammaConversion = new G4GammaConversion(); 190 G4LivermoreGammaConversionModel* theLivermoreGammaConversionModel = new G4LivermoreGammaConversionModel(); 191 theGammaConversion->AddEmModel(0, theLivermoreGammaConversionModel); 192 pmanager->AddDiscreteProcess(theGammaConversion); 193 194 G4RayleighScattering* theRayleigh = new G4RayleighScattering(); 195 G4LivermoreRayleighModel* theRayleighModel = new G4LivermoreRayleighModel(); 196 theRayleigh->AddEmModel(0, theRayleighModel); 197 pmanager->AddDiscreteProcess(theRayleigh); 198 199 pmanager->AddProcess(new G4StepLimiter(), -1, -1, 5); 200 201 } else if (particleName == "e-") { 202 203 G4eMultipleScattering* msc = new G4eMultipleScattering(); 204 msc->SetStepLimitType(fUseDistanceToBoundary); 205 pmanager->AddProcess(msc, -1, 1, 1); 206 207 // Ionisation 208 G4eIonisation* eIoni = new G4eIonisation(); 209 eIoni->AddEmModel(0, new G4LivermoreIonisationModel(), new G4UniversalFluctuation() ); 210 eIoni->SetStepFunction(0.2, 100*um); // 211 pmanager->AddProcess(eIoni, -1, 2, 2); 212 213 // Bremsstrahlung 214 G4eBremsstrahlung* eBrem = new G4eBremsstrahlung(); 215 eBrem->AddEmModel(0, new G4LivermoreBremsstrahlungModel()); 216 pmanager->AddProcess(eBrem, -1,-3, 3); 217 218 pmanager->AddProcess(new G4StepLimiter(), -1, -1, 4); 219 220 } else if (particleName == "e+") { 221 222 // Identical to G4EmStandardPhysics_option3 223 224 G4eMultipleScattering* msc = new G4eMultipleScattering(); 225 msc->SetStepLimitType(fUseDistanceToBoundary); 226 pmanager->AddProcess(msc, -1, 1, 1); 227 228 G4eIonisation* eIoni = new G4eIonisation(); 229 eIoni->SetStepFunction(0.2, 100*um); 230 pmanager->AddProcess(eIoni, -1, 2, 2); 231 232 pmanager->AddProcess(new G4eBremsstrahlung, -1,-3, 3); 233 234 pmanager->AddProcess(new G4eplusAnnihilation,0,-1, 4); 235 236 pmanager->AddProcess(new G4StepLimiter(), -1, -1, 5); 237 238 } else if (particleName == "GenericIon") { 239 240 pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); 241 242 G4ionIonisation* ionIoni = new G4ionIonisation(); 243 ionIoni->SetEmModel(new G4IonParametrisedLossModel()); 244 ionIoni->SetStepFunction(0.1, 20*um); 245 pmanager->AddProcess(ionIoni, -1, 2, 2); 246 247 pmanager->AddProcess(new G4StepLimiter(), -1, -1, 3); 248 249 } else if (particleName == "alpha" || 250 particleName == "He3" ) { 251 252 // Identical to G4EmStandardPhysics_option3 253 254 pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); 255 256 G4ionIonisation* ionIoni = new G4ionIonisation(); 257 ionIoni->SetStepFunction(0.1, 20*um); 258 pmanager->AddProcess(ionIoni, -1, 2, 2); 259 260 pmanager->AddProcess(new G4StepLimiter(), -1, -1, 3); 261 } 262 263 // 264 265 } 266 } 267 268 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 269 270 #include "G4HadronElasticProcess.hh" 271 #include "G4LElastic.hh" 272 273 #include "G4AlphaInelasticProcess.hh" 274 #include "G4BinaryLightIonReaction.hh" 275 #include "G4TripathiCrossSection.hh" 276 #include "G4IonsShenCrossSection.hh" 277 #include "G4LEAlphaInelastic.hh" 278 279 void DicomPhysicsList::ConstructHad() 280 { 281 282 G4HadronElasticProcess * theElasticProcess = new G4HadronElasticProcess; 283 theElasticProcess->RegisterMe( new G4LElastic() ); 284 114 285 theParticleIterator->reset(); 115 286 while( (*theParticleIterator)() ) 116 { 117 G4ParticleDefinition* particle = theParticleIterator->value(); 118 G4ProcessManager* pmanager = particle->GetProcessManager(); 119 G4String particleName = particle->GetParticleName(); 120 121 //processes 122 lowePhot = new G4LowEnergyPhotoElectric("LowEnPhotoElec"); 123 loweIon = new G4LowEnergyIonisation("LowEnergyIoni"); 124 loweBrem = new G4LowEnergyBremsstrahlung("LowEnBrem"); 125 126 if (particleName == "gamma") 127 { 128 //gamma 129 pmanager->AddDiscreteProcess(new G4LowEnergyRayleigh); 130 pmanager->AddDiscreteProcess(lowePhot); 131 pmanager->AddDiscreteProcess(new G4LowEnergyCompton); 132 pmanager->AddDiscreteProcess(new G4LowEnergyGammaConversion); 133 134 } 135 else if (particleName == "e-") 136 { 137 //electron 138 pmanager->AddProcess(new G4MultipleScattering, -1, 1,1); 139 pmanager->AddProcess(loweIon, -1, 2,2); 140 pmanager->AddProcess(loweBrem, -1,-1,3); 141 142 } 143 else if (particleName == "e+") 144 { 145 //positron 146 pmanager->AddProcess(new G4MultipleScattering, -1, 1,1); 147 pmanager->AddProcess(new G4eIonisation, -1, 2,2); 148 pmanager->AddProcess(new G4eBremsstrahlung, -1,-1,3); 149 pmanager->AddProcess(new G4eplusAnnihilation, 0,-1,4); 150 151 } 152 } 153 } 154 #include "G4Decay.hh" 287 { 288 G4ParticleDefinition* particle = theParticleIterator->value(); 289 G4ProcessManager* pManager = particle->GetProcessManager(); 290 291 if (particle->GetParticleName() == "alpha") 292 { 293 294 // INELASTIC SCATTERING 295 // Binary Cascade 296 G4BinaryLightIonReaction* theBC = new G4BinaryLightIonReaction(); 297 theBC -> SetMinEnergy(80.*MeV); 298 theBC -> SetMaxEnergy(40.*GeV); 299 300 // TRIPATHI CROSS SECTION 301 // Implementation of formulas in analogy to NASA technical paper 3621 by 302 // Tripathi, et al. Cross-sections for ion ion scattering 303 G4TripathiCrossSection* TripathiCrossSection = new G4TripathiCrossSection; 304 305 // IONS SHEN CROSS SECTION 306 // Implementation of formulas 307 // Shen et al. Nuc. Phys. A 491 130 (1989) 308 // Total Reaction Cross Section for Heavy-Ion Collisions 309 G4IonsShenCrossSection* aShen = new G4IonsShenCrossSection; 310 311 // Final state production model for Alpha inelastic scattering below 20 GeV 312 G4LEAlphaInelastic* theAIModel = new G4LEAlphaInelastic; 313 theAIModel -> SetMaxEnergy(100.*MeV); 314 315 G4AlphaInelasticProcess * theIPalpha = new G4AlphaInelasticProcess; 316 theIPalpha->AddDataSet(TripathiCrossSection); 317 theIPalpha->AddDataSet(aShen); 318 319 // Register the Alpha Inelastic and Binary Cascade Model 320 theIPalpha->RegisterMe(theAIModel); 321 theIPalpha->RegisterMe(theBC); 322 323 // Activate the alpha inelastic scattering using the alpha inelastic and binary cascade model 324 pManager -> AddDiscreteProcess(theIPalpha); 325 326 // Activate the Hadron Elastic Process 327 pManager -> AddDiscreteProcess(theElasticProcess); 328 329 } 330 } 331 332 } 333 334 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 335 155 336 void DicomPhysicsList::ConstructGeneral() 156 { 157 // Add Decay Process 158 G4Decay* theDecayProcess = new G4Decay(); 159 theParticleIterator->reset(); 160 while( (*theParticleIterator)() ) 161 { 162 G4ParticleDefinition* particle = theParticleIterator->value(); 163 G4ProcessManager* pmanager = particle->GetProcessManager(); 164 if (theDecayProcess->IsApplicable(*particle)) 165 { 166 pmanager ->AddProcess(theDecayProcess); 167 // set ordering for PostStepDoIt and AtRestDoIt 168 pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep); 169 pmanager ->SetProcessOrdering(theDecayProcess, idxAtRest); 170 } 171 } 172 } 337 { } 338 339 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 173 340 174 341 void DicomPhysicsList::SetCuts() 175 342 { 176 if (verboseLevel >0) 177 { 178 G4cout << "DicomPhysicsList::SetCuts:"; 179 G4cout << "CutLength : " << G4BestUnit(defaultCutValue,"Length") << G4endl; 180 } 181 343 if (verboseLevel >0){ 344 G4cout << "DicomPhysicsList::SetCuts:"; 345 G4cout << "CutLength : " << G4BestUnit(defaultCutValue,"Length") << G4endl; 346 } 347 182 348 // set cut values for gamma at first and for e- second and next for e+, 183 // because some processes for e+/e- need cut values for gamma 349 // because some processes for e+/e- need cut values for gamma 184 350 SetCutValue(cutForGamma, "gamma"); 185 351 SetCutValue(cutForElectron, "e-"); 186 352 SetCutValue(cutForPositron, "e+"); 187 188 189 if (verboseLevel>0) 190 DumpCutValuesTable(); 191 } 192 193 void DicomPhysicsList::SetGammaCut(G4double val) 194 { 195 ResetCuts(); 196 cutForGamma = val; 197 } 198 199 void DicomPhysicsList::SetElectronCut(G4double val) 200 { 201 // ResetCuts(); 202 cutForElectron = val; 203 } 204 205 void DicomPhysicsList::SetPositronCut(G4double val) 206 { 207 // ResetCuts(); 208 cutForPositron = val; 209 } 210 353 354 if (verboseLevel>0) DumpCutValuesTable(); 355 356 } 357 -
trunk/examples/extended/medical/DICOM/src/DicomPrimaryGeneratorAction.cc
r1230 r1337 74 74 particleGun->SetParticleEnergy(5.*MeV); 75 75 //put it at SAD = 1 m on xy plane of central slice 76 particleGun->SetParticlePosition(G4ThreeVector(0.,-99.9*cm, -27.));76 particleGun->SetParticlePosition(G4ThreeVector(0.,-99.9*cm,87.5*mm)); 77 77 //particleGun->SetParticlePosition(G4ThreeVector(0.,0.,-22.)); 78 78 particleGun->GeneratePrimaryVertex(anEvent);
Note: See TracChangeset
for help on using the changeset viewer.