66 if(!fG4ProductionCutsTable){
67 fG4ProductionCutsTable = &theProductionCutsTable;
69 return fG4ProductionCutsTable;
74 : firstUse(true),verboseLevel(1),fMessenger(0)
78 rangeCutTable.push_back(
new G4CutVectorForAParticle);
79 energyCutTable.push_back(
new G4CutVectorForAParticle);
80 rangeDoubleVector[i] = 0;
81 energyDoubleVector[i] = 0;
95 defaultProductionCuts=0;
102 if (defaultProductionCuts !=0) {
103 delete defaultProductionCuts;
104 defaultProductionCuts =0;
107 for(CoupleTableIterator itr=coupleTable.begin();itr!=coupleTable.end();itr++){
113 delete rangeCutTable[i];
114 delete energyCutTable[i];
115 delete converters[i];
116 if(rangeDoubleVector[i]!=0)
delete [] rangeDoubleVector[i];
117 if(energyDoubleVector[i]!=0)
delete [] energyDoubleVector[i];
119 fG4ProductionCutsTable =0;
121 if (fMessenger !=0)
delete fMessenger;
148 for(CoupleTableIterator CoupleItr=coupleTable.begin();
149 CoupleItr!=coupleTable.end();CoupleItr++)
151 (*CoupleItr)->SetUseFlag(
false);
155 typedef std::vector<G4Region*>::iterator regionIterator;
156 for(regionIterator rItr=fG4RegionStore->begin();
157 rItr!=fG4RegionStore->end();rItr++)
162 if((*rItr)->IsInMassGeometry() || (*rItr)->IsInParallelGeometry())
166 std::vector<G4Material*>::const_iterator mItr =
167 (*rItr)->GetMaterialIterator();
168 size_t nMaterial = (*rItr)->GetNumberOfMaterials();
171 for(
size_t iMate=0;iMate<nMaterial;iMate++){
173 G4bool coupleAlreadyDefined =
false;
175 for(CoupleTableIterator cItr=coupleTable.begin();
176 cItr!=coupleTable.end();cItr++){
177 if( (*cItr)->GetMaterial()==(*mItr) &&
178 (*cItr)->GetProductionCuts()==fProductionCut){
179 coupleAlreadyDefined =
true;
186 if(!coupleAlreadyDefined){
188 coupleTable.push_back(aCouple);
189 aCouple->
SetIndex(coupleTable.size()-1);
193 (*rItr)->RegisterMaterialCouplePair((*mItr),aCouple);
198 std::vector<G4LogicalVolume*>::iterator rootLVItr
199 = (*rItr)->GetRootLogicalVolumeIterator();
200 size_t nRootLV = (*rItr)->GetNumberOfRootVolumes();
201 for(
size_t iLV=0;iLV<nRootLV;iLV++) {
206 ScanAndSetCouple(aLV,aCouple,aR);
222 size_t nCouple = coupleTable.size();
223 size_t nTable = energyCutTable[0]->size();
224 G4bool newCoupleAppears = nCouple>nTable;
225 if(newCoupleAppears) {
226 for(
size_t n=nCouple-nTable;n>0;n--) {
228 rangeCutTable[nn]->push_back(-1.);
229 energyCutTable[nn]->push_back(-1.);
237 if (verboseLevel>2) {
240 for(CoupleTableIterator cItr=coupleTable.begin();
241 cItr!=coupleTable.end();cItr++){
244 if((*cItr)->IsRecalcNeeded()) {
247 (*(rangeCutTable[ptcl]))[idx] = rCut;
249 if(converters[ptcl]) {
250 (*(energyCutTable[ptcl]))[idx] = converters[ptcl]->
Convert(rCut,aMat);
252 (*(energyCutTable[ptcl]))[idx] = -1.;
258 if (verboseLevel>2) {
260 G4cout <<
"G4ProductionCutsTable::UpdateCoupleTable "
261 <<
" elapsed time for calculation of energy cuts " <<
G4endl;
266 if(newCoupleAppears){
268 G4double* rangeVOld = rangeDoubleVector[ix];
269 G4double* energyVOld = energyDoubleVector[ix];
270 if(rangeVOld)
delete [] rangeVOld;
271 if(energyVOld)
delete [] energyVOld;
272 rangeDoubleVector[ix] =
new G4double[(*(rangeCutTable[ix])).size()];
273 energyDoubleVector[ix] =
new G4double[(*(energyCutTable[ix])).size()];
279 for(
size_t ixx=0;ixx<(*(rangeCutTable[ix])).size();ixx++) {
280 rangeDoubleVector[ix][ixx] = (*(rangeCutTable[ix]))[ixx];
281 energyDoubleVector[ix][ixx] = (*(energyCutTable[ix]))[ixx];
296 if (material ==0)
return -1.0;
299 if (range ==0.0)
return 0.0;
300 if (range <0.0)
return -1.0;
307 if (verboseLevel >1) {
308 G4cout <<
"G4ProductionCutsTable::ConvertRangeToEnergy" ;
315 return converters[index]->
Convert(range, material);
323 if (converters[i]!=0) converters[i]->
Reset();
353 if((aRegion!=0) && aLV->
GetRegion()!=aRegion)
return;
361 if(noDaughters==0)
return;
364 for(
size_t i=0;i<noDaughters;i++){
366 ScanAndSetCouple(daughterLVol,aCouple,aRegion);
374 G4cout <<
"========= Table of registered couples =============================="
376 for(CoupleTableIterator cItr=coupleTable.begin();
377 cItr!=coupleTable.end();cItr++) {
382 <<
" used in the geometry : ";
385 G4cout <<
" recalculation needed : ";
390 G4cout <<
" Range cuts : "
396 G4cout <<
" Energy thresholds : " ;
398 G4cout <<
" is not ready to print";
408 G4cout <<
" Region(s) which use this couple : " <<
G4endl;
409 typedef std::vector<G4Region*>::iterator regionIterator;
410 for(regionIterator rItr=fG4RegionStore->begin();
411 rItr!=fG4RegionStore->end();rItr++) {
412 if (IsCoupleUsedInTheRegion(aCouple, *rItr) ){
419 G4cout <<
"====================================================================" <<
G4endl;
434 if (verboseLevel >2) {
435 G4cout <<
"G4ProductionCutsTable::StoreCutsTable " ;
436 G4cout <<
" Material/Cuts information have been succesfully stored ";
438 G4cout <<
" in Ascii mode ";
440 G4cout <<
" in Binary mode ";
455 if (verboseLevel >2) {
456 G4cout <<
"G4ProductionCutsTable::RetrieveCutsTable " ;
457 G4cout <<
" Material/Cuts information have been succesfully retreived ";
459 G4cout <<
" in Ascii mode ";
461 G4cout <<
" in Binary mode ";
477 G4cerr <<
"G4ProductionCutsTable::CheckForRetrieveCutsTable!!"<<
G4endl;
480 if (verboseLevel >2) {
481 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo passed !!"<<
G4endl;
484 if (verboseLevel >2) {
485 G4cerr <<
"G4ProductionCutsTable::CheckMaterialCutsCoupleInfo passed !!"<<
G4endl;
496 const G4String fileName = directory +
"/" +
"material.dat";
497 const G4String key =
"MATERIAL-V3.0";
502 fOut.open(fileName,std::ios::out|std::ios::binary);
504 fOut.open(fileName,std::ios::out);
510 if (verboseLevel>0) {
511 G4cerr <<
"G4ProductionCutsTable::StoreMaterialInfo ";
515 G4Exception(
"G4ProductionCutsTable::StoreMaterialInfo()",
523 G4int numberOfMaterial = matTable->size();
531 fOut << numberOfMaterial <<
G4endl;
533 fOut.setf(std::ios::scientific);
536 for (
size_t idx=0;
static_cast<G4int>(idx)<numberOfMaterial; ++idx){
537 fOut << std::setw(FixedStringLengthForStore)
538 << ((*matTable)[idx])->GetName();
539 fOut << std::setw(FixedStringLengthForStore)
540 << ((*matTable)[idx])->GetDensity()/(g/cm3) <<
G4endl;
543 fOut.unsetf(std::ios::scientific);
547 char temp[FixedStringLengthForStore];
551 for (i=0; i<FixedStringLengthForStore; ++i){
554 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i){
557 fOut.write(temp, FixedStringLengthForStore);
560 fOut.write( (
char*)(&numberOfMaterial),
sizeof (
G4int));
563 for (
size_t imat=0;
static_cast<G4int>(imat)<numberOfMaterial; ++imat){
564 G4String name = ((*matTable)[imat])->GetName();
565 G4double density = ((*matTable)[imat])->GetDensity();
566 for (i=0; i<FixedStringLengthForStore; ++i) temp[i] =
'\0';
567 for (i=0; i<name.length() && i<FixedStringLengthForStore-1; ++i)
569 fOut.write(temp, FixedStringLengthForStore);
570 fOut.write( (
char*)(&density),
sizeof (
G4double));
583 const G4String fileName = directory +
"/" +
"material.dat";
584 const G4String key =
"MATERIAL-V3.0";
589 fIn.open(fileName,std::ios::in|std::ios::binary);
591 fIn.open(fileName,std::ios::in);
596 if (verboseLevel >0) {
597 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo ";
601 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
607 char temp[FixedStringLengthForStore];
614 fIn.read(temp, FixedStringLengthForStore);
615 keyword = (
const char*)(temp);
619 if (verboseLevel >0) {
620 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo ";
621 G4cerr <<
" Key word in " << fileName <<
"= " << keyword ;
625 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
636 fIn.read( (
char*)(&nmat),
sizeof (
G4int));
638 if ((nmat<=0) || (nmat >100000)){
639 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
641 "Number of materials is less than zero or too big");
646 for (
G4int idx=0; idx<nmat ; ++idx){
650 if (verboseLevel >0) {
651 G4cout <<
"G4ProductionCutsTable::CheckMaterialInfo ";
652 G4cout <<
" encountered End of File " ;
661 char name[FixedStringLengthForStore];
664 fIn >> name >> density;
668 fIn.read(name, FixedStringLengthForStore);
669 fIn.read((
char*)(&density),
sizeof (
G4double));
673 if (verboseLevel >0) {
674 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo ";
675 G4cerr <<
" Bad data format ";
679 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
687 if (aMaterial ==0 )
continue;
690 if ((0.999>ratio) || (ratio>1.001) ){
692 if (verboseLevel >0) {
693 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo ";
697 G4cerr <<
"Density:" << std::setiosflags(std::ios::scientific) << density / (g/cm3) ;
699 G4cerr << std::resetiosflags(std::ios::scientific);
702 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
724 const G4String fileName = directory +
"/" +
"couple.dat";
727 char temp[FixedStringLengthForStore];
731 fOut.open(fileName,std::ios::out|std::ios::binary);
733 fOut.open(fileName,std::ios::out);
739 if (verboseLevel >0) {
740 G4cerr <<
"G4ProductionCutsTable::StoreMaterialCutsCoupleInfo ";
744 G4Exception(
"G4ProductionCutsTable::StoreMaterialCutsCoupleInfo()",
749 G4int numberOfCouples = coupleTable.size();
753 fOut << std::setw(FixedStringLengthForStore) << key <<
G4endl;
756 fOut << numberOfCouples <<
G4endl;
761 for (i=0; i<FixedStringLengthForStore; ++i) temp[i] =
'\0';
762 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i)
764 fOut.write(temp, FixedStringLengthForStore);
767 fOut.write( (
char*)(&numberOfCouples),
sizeof (
G4int));
772 CoupleTableIterator cItr;
773 for (cItr=coupleTable.begin();cItr!=coupleTable.end();cItr++){
786 typedef std::vector<G4Region*>::iterator regionIterator;
787 for(regionIterator rItr=fG4RegionStore->begin();
788 rItr!=fG4RegionStore->end();rItr++){
789 if (IsCoupleUsedInTheRegion(aCouple, *rItr) ){
790 regionName = (*rItr)->GetName();
802 fOut << std::setw(FixedStringLengthForStore) << materialName<<
G4endl;
805 fOut << std::setw(FixedStringLengthForStore) << regionName<<
G4endl;
807 fOut.setf(std::ios::scientific);
810 fOut << std::setw(FixedStringLengthForStore) << cutValues[idx]/(mm)
813 fOut.unsetf(std::ios::scientific);
818 fOut.write( (
char*)(&index),
sizeof (
G4int));
822 for (i=0; i<FixedStringLengthForStore; ++i) temp[i] =
'\0';
823 for (i=0; i<materialName.length() && i<FixedStringLengthForStore-1; ++i) {
824 temp[i]=materialName[i];
826 fOut.write(temp, FixedStringLengthForStore);
829 for (i=0; i<FixedStringLengthForStore; ++i) temp[i] =
'\0';
830 for (i=0; i<regionName.length() && i<FixedStringLengthForStore-1; ++i) {
831 temp[i]=regionName[i];
833 fOut.write(temp, FixedStringLengthForStore);
837 fOut.write( (
char*)(&(cutValues[idx])),
sizeof (
G4double));
855 const G4String fileName = directory +
"/" +
"couple.dat";
861 fIn.open(fileName,std::ios::in|std::ios::binary);
863 fIn.open(fileName,std::ios::in);
868 if (verboseLevel >0) {
869 G4cerr <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
873 G4Exception(
"G4ProductionCutsTable::CheckMaterialCutsCoupleInfo()",
879 char temp[FixedStringLengthForStore];
886 fIn.read(temp, FixedStringLengthForStore);
887 keyword = (
const char*)(temp);
891 if (verboseLevel >0) {
892 G4cerr <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
893 G4cerr <<
" Key word in " << fileName <<
"= " << keyword ;
897 G4Exception(
"G4ProductionCutsTable::CheckMaterialCutsCoupleInfo()",
905 G4int numberOfCouples;
907 fIn >> numberOfCouples;
909 fIn.read( (
char*)(&numberOfCouples),
sizeof (
G4int));
913 mccConversionTable.
Reset(numberOfCouples);
916 for (
G4int idx=0; idx<numberOfCouples; idx+=1){
922 fIn.read( (
char*)(&index),
sizeof (
G4int));
925 char mat_name[FixedStringLengthForStore];
929 fIn.read(mat_name, FixedStringLengthForStore);
932 char region_name[FixedStringLengthForStore];
936 fIn.read(region_name, FixedStringLengthForStore);
943 cutValues[i] *= (mm);
945 fIn.read( (
char*)(&(cutValues[i])),
sizeof (
G4double));
950 CoupleTableIterator cItr;
953 for (cItr=coupleTable.begin();cItr!=coupleTable.end();cItr++){
964 fRatio = fRatio && (0.999<ratio) && (ratio<1.001) ;
967 if (!fRatio)
continue;
976 if (verboseLevel >1) {
980 if ( regionname !=
"NONE" ) {
981 fRegion = fG4RegionStore->
GetRegion(region_name);
983 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
984 G4cout <<
"Region " << regionname <<
" is not found ";
988 if ( ( (regionname ==
"NONE") && (aCouple->
IsUsed()) ) ||
989 ( (fRegion !=0) && !IsCoupleUsedInTheRegion(aCouple, fRegion) ) ) {
990 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
991 G4cout <<
"A Couple is used differnt region in the current setup ";
993 G4cout <<
" material: " << mat_name ;
996 G4cout <<
"cut[" << ii <<
"]=" << cutValues[ii]/mm;
1000 }
else if ( index != aCouple->
GetIndex() ) {
1001 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
1004 G4cout <<
" is defined as " ;
1005 G4cout << index <<
":" << mat_name <<
" in " << fileName <<
G4endl;
1007 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
1008 G4cout << index <<
":" << mat_name <<
" in " << fileName ;
1009 G4cout <<
" is consistent with current setup" <<
G4endl;
1013 if ((!fOK) && (verboseLevel >0)) {
1014 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
1015 G4cout <<
"Couples is not defined in the current detector setup ";
1017 G4cout <<
" material: " << mat_name ;
1020 G4cout <<
"cut[" << ii <<
"]=" << cutValues[ii]/mm;
1039 const G4String fileName = directory +
"/" +
"cut.dat";
1042 char temp[FixedStringLengthForStore];
1046 fOut.open(fileName,std::ios::out|std::ios::binary);
1048 fOut.open(fileName,std::ios::out);
1053 if(verboseLevel>0) {
1054 G4cerr <<
"G4ProductionCutsTable::StoreCutsInfo ";
1057 G4Exception(
"G4ProductionCutsTable::StoreCutsInfo()",
1063 G4int numberOfCouples = coupleTable.size();
1070 fOut << numberOfCouples <<
G4endl;
1075 for (i=0; i<FixedStringLengthForStore; ++i) temp[i] =
'\0';
1076 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i)
1078 fOut.write(temp, FixedStringLengthForStore);
1081 fOut.write( (
char*)(&numberOfCouples),
sizeof (
G4int));
1090 CoupleTableIterator cItr;
1091 for (cItr=coupleTable.begin();cItr!=coupleTable.end();cItr++, i++){
1094 fOut.setf(std::ios::scientific);
1095 fOut << std::setw(20) << (*fRange)[i]/mm ;
1096 fOut << std::setw(20) << (*fEnergy)[i]/keV <<
G4endl;
1097 fOut.unsetf(std::ios::scientific);
1101 fOut.write((
char*)(&cut),
sizeof (
G4double));
1102 cut = (*fEnergy)[i];
1103 fOut.write((
char*)(&cut),
sizeof (
G4double));
1117 const G4String fileName = directory +
"/" +
"cut.dat";
1123 fIn.open(fileName,std::ios::in|std::ios::binary);
1125 fIn.open(fileName,std::ios::in);
1129 if (verboseLevel >0) {
1130 G4cerr <<
"G4ProductionCutTable::RetrieveCutsInfo ";
1133 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1139 char temp[FixedStringLengthForStore];
1146 fIn.read(temp, FixedStringLengthForStore);
1147 keyword = (
const char*)(temp);
1150 if (verboseLevel >0) {
1151 G4cerr <<
"G4ProductionCutTable::RetrieveCutsInfo ";
1152 G4cerr <<
" Key word in " << fileName <<
"= " << keyword ;
1155 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1162 G4int numberOfCouples;
1164 fIn >> numberOfCouples;
1166 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1172 fIn.read( (
char*)(&numberOfCouples),
sizeof (
G4int));
1175 if (numberOfCouples >
static_cast<G4int>(mccConversionTable.
size()) ){
1176 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1178 "Number of Couples in the file exceeds defined couples ");
1180 numberOfCouples = mccConversionTable.
size();
1183 G4CutVectorForAParticle* fRange = rangeCutTable[idx];
1184 G4CutVectorForAParticle* fEnergy = energyCutTable[idx];
1189 for (
size_t i=0;
static_cast<G4int>(i)< numberOfCouples; i++){
1192 fIn >> rcut >> ecut;
1194 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1202 fIn.read((
char*)(&rcut),
sizeof (
G4double));
1203 fIn.read((
char*)(&ecut),
sizeof (
G4double));
1205 if (!mccConversionTable.
IsUsed(i))
continue;
1206 size_t new_index = mccConversionTable.
GetIndex(i);
1207 (*fRange)[new_index] = rcut;
1208 (*fEnergy)[new_index] = ecut;
1219 verboseLevel = value;
1221 if (converters[ip] !=0 ){
std::vector< G4Material * > G4MaterialTable
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4int GetNoDaughters() const
G4Region * GetRegion() const
G4Material * GetMaterial() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
void SetMaterialCutsCouple(G4MaterialCutsCouple *cuts)
void SetNewIndex(size_t index, size_t new_value)
G4int GetIndex(size_t index) const
G4bool IsUsed(size_t index) const
G4bool IsRecalcNeeded() const
const G4Material * GetMaterial() const
void SetUseFlag(G4bool flg=true)
G4ProductionCuts * GetProductionCuts() const
G4double GetDensity() const
static const G4MaterialTable * GetMaterialTable()
const G4String & GetName() const
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
const G4String & GetParticleName() const
static G4ParticleTable * GetParticleTable()
virtual G4bool RetrieveCutsInfo(const G4String &directory, G4bool ascii=false)
G4bool RetrieveCutsTable(const G4String &directory, G4bool ascii=false)
virtual G4bool StoreCutsInfo(const G4String &directory, G4bool ascii=false)
const std::vector< G4double > * GetRangeCutsVector(size_t pcIdx) const
G4double GetLowEdgeEnergy() const
void SetMaxEnergyCut(G4double value)
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
G4double GetMaxEnergyCut()
void SetVerboseLevel(G4int value)
virtual G4bool CheckMaterialInfo(const G4String &directory, G4bool ascii=false)
G4int GetVerboseLevel() const
virtual G4bool StoreMaterialInfo(const G4String &directory, G4bool ascii=false)
G4double GetHighEdgeEnergy() const
virtual ~G4ProductionCutsTable()
const std::vector< G4double > * GetEnergyCutsVector(size_t pcIdx) const
G4bool StoreCutsTable(const G4String &directory, G4bool ascii=false)
G4bool CheckForRetrieveCutsTable(const G4String &directory, G4bool ascii=false)
void SetEnergyRange(G4double lowedge, G4double highedge)
static G4ProductionCutsTable * GetProductionCutsTable()
virtual G4bool CheckMaterialCutsCoupleInfo(const G4String &directory, G4bool ascii=false)
G4double ConvertRangeToEnergy(const G4ParticleDefinition *particle, const G4Material *material, G4double range)
virtual G4bool StoreMaterialCutsCoupleInfo(const G4String &directory, G4bool ascii=false)
static G4int GetIndex(const G4String &name)
G4double GetProductionCut(G4int index) const
const std::vector< G4double > & GetProductionCuts() const
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
G4LogicalVolume * GetLogicalVolume() const
void SetVerboseLevel(G4int value)
virtual G4double Convert(G4double rangeCut, const G4Material *material)
static G4double GetMaxEnergyCut()
static void SetMaxEnergyCut(G4double value)
static G4double GetLowEdgeEnergy()
static void SetEnergyRange(G4double lowedge, G4double highedge)
static G4double GetHighEdgeEnergy()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)