73 : firstUse(
true),verboseLevel(1),fMessenger(nullptr)
155 (*CoupleItr)->SetUseFlag(
false);
159 typedef std::vector<G4Region*>::iterator regionIterator;
166 if((*rItr)->IsInMassGeometry() || (*rItr)->IsInParallelGeometry())
170 std::vector<G4Material*>::const_iterator mItr =
171 (*rItr)->GetMaterialIterator();
172 size_t nMaterial = (*rItr)->GetNumberOfMaterials();
175 for(
size_t iMate=0;iMate<nMaterial;iMate++){
177 G4bool coupleAlreadyDefined =
false;
181 if( (*cItr)->GetMaterial()==(*mItr) &&
182 (*cItr)->GetProductionCuts()==fProductionCut){
183 coupleAlreadyDefined =
true;
190 if(!coupleAlreadyDefined){
197 (*rItr)->RegisterMaterialCouplePair((*mItr),aCouple);
202 std::vector<G4LogicalVolume*>::iterator rootLVItr
203 = (*rItr)->GetRootLogicalVolumeIterator();
204 size_t nRootLV = (*rItr)->GetNumberOfRootVolumes();
205 for(
size_t iLV=0;iLV<nRootLV;iLV++) {
228 G4bool newCoupleAppears = nCouple>nTable;
229 if(newCoupleAppears) {
230 for(
size_t n=nCouple-nTable;
n>0;
n--) {
248 if((*cItr)->IsRecalcNeeded()) {
264 G4cout <<
"G4ProductionCutsTable::UpdateCoupleTable "
265 <<
" elapsed time for calculation of energy cuts " <<
G4endl;
270 if(newCoupleAppears){
274 if(rangeVOld)
delete [] rangeVOld;
275 if(energyVOld)
delete [] energyVOld;
307 ed <<
"G4ProductionCutsTable::ConvertRangeToEnergy is invoked prematurely "
308 <<
"before it is fully initialized.";
309 G4Exception(
"G4ProductionCutsTable::ConvertRangeToEnergy",
"CUTS0100",
317 if (material ==
nullptr)
return -1.0;
320 if (range ==0.0)
return 0.0;
321 if (range <0.0)
return -1.0;
326 if (index<0 ||
converters[index] ==
nullptr) {
331 ed <<
"G4ProductionCutsTable::ConvertRangeToEnergy is invoked ";
332 if(particle !=
nullptr)
335 { ed <<
"without valid particle pointer."; }
336 G4Exception(
"G4ProductionCutsTable::ConvertRangeToEnergy",
"CUTS0101",
381 if((aRegion!=
nullptr) && aLV->
GetRegion()!=aRegion)
return;
389 if(noDaughters==0)
return;
392 for(
size_t i=0;i<noDaughters;i++){
402 G4cout <<
"========= Table of registered couples =============================="
410 <<
" used in the geometry : ";
418 G4cout <<
" Range cuts : "
424 G4cout <<
" Energy thresholds : " ;
436 G4cout <<
" Region(s) which use this couple : " <<
G4endl;
437 typedef std::vector<G4Region*>::iterator regionIterator;
441 G4cout <<
" " << (*rItr)->GetName() <<
G4endl;
447 G4cout <<
"====================================================================" <<
G4endl;
463 G4cout <<
"G4ProductionCutsTable::StoreCutsTable " ;
464 G4cout <<
" Material/Cuts information have been successfully stored ";
466 G4cout <<
" in Ascii mode ";
468 G4cout <<
" in Binary mode ";
484 G4cout <<
"G4ProductionCutsTable::RetrieveCutsTable " ;
485 G4cout <<
" Material/Cuts information have been successfully retrieved ";
487 G4cout <<
" in Ascii mode ";
489 G4cout <<
" in Binary mode ";
505 G4cerr <<
"G4ProductionCutsTable::CheckForRetrieveCutsTable!!"<<
G4endl;
509 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo passed !!"<<
G4endl;
513 G4cerr <<
"G4ProductionCutsTable::CheckMaterialCutsCoupleInfo passed !!"<<
G4endl;
524 const G4String fileName = directory +
"/" +
"material.dat";
525 const G4String key =
"MATERIAL-V3.0";
530 fOut.open(fileName,std::ios::out|std::ios::binary);
532 fOut.open(fileName,std::ios::out);
539 G4cerr <<
"G4ProductionCutsTable::StoreMaterialInfo ";
543 G4Exception(
"G4ProductionCutsTable::StoreMaterialInfo()",
551 G4int numberOfMaterial = matTable->size();
559 fOut << numberOfMaterial <<
G4endl;
561 fOut.setf(std::ios::scientific);
564 for (
size_t idx=0;
static_cast<G4int>(
idx)<numberOfMaterial; ++
idx){
566 << ((*matTable)[
idx])->GetName();
568 << ((*matTable)[
idx])->GetDensity()/(
g/
cm3) << G4endl;
571 fOut.unsetf(std::ios::scientific);
582 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i){
585 fOut.write(temp, FixedStringLengthForStore);
588 fOut.write( (
char*)(&numberOfMaterial),
sizeof (
G4int));
591 for (
size_t imat=0;
static_cast<G4int>(imat)<numberOfMaterial; ++imat){
593 G4double density = ((*matTable)[imat])->GetDensity();
595 for (i=0; i<name.length() && i<FixedStringLengthForStore-1; ++i)
597 fOut.write(temp, FixedStringLengthForStore);
598 fOut.write( (
char*)(&density),
sizeof (
G4double));
611 const G4String fileName = directory +
"/" +
"material.dat";
612 const G4String key =
"MATERIAL-V3.0";
625 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo ";
629 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
643 keyword = (
const char*)(temp);
648 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo ";
649 G4cerr <<
" Key word in " << fileName <<
"= " << keyword ;
653 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
664 fIn.read( (
char*)(&nmat),
sizeof (
G4int));
666 if ((nmat<=0) || (nmat >100000)){
667 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
669 "Number of materials is less than zero or too big");
679 G4cout <<
"G4ProductionCutsTable::CheckMaterialInfo ";
680 G4cout <<
" encountered End of File " ;
692 fIn >> name >> density;
697 fIn.read((
char*)(&density),
sizeof (
G4double));
702 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo ";
703 G4cerr <<
" Bad data format ";
707 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
715 if (aMaterial ==
nullptr )
continue;
718 if ((0.999>ratio) || (ratio>1.001) ){
721 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo ";
725 G4cerr <<
"Density:" << std::setiosflags(std::ios::scientific) << density / (
g/
cm3) ;
727 G4cerr << std::resetiosflags(std::ios::scientific);
730 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
752 const G4String fileName = directory +
"/" +
"couple.dat";
759 fOut.open(fileName,std::ios::out|std::ios::binary);
761 fOut.open(fileName,std::ios::out);
768 G4cerr <<
"G4ProductionCutsTable::StoreMaterialCutsCoupleInfo ";
772 G4Exception(
"G4ProductionCutsTable::StoreMaterialCutsCoupleInfo()",
784 fOut << numberOfCouples <<
G4endl;
790 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i)
792 fOut.write(temp, FixedStringLengthForStore);
795 fOut.write( (
char*)(&numberOfCouples),
sizeof (
G4int));
814 typedef std::vector<G4Region*>::iterator regionIterator;
818 regionName = (*rItr)->GetName();
835 fOut.setf(std::ios::scientific);
841 fOut.unsetf(std::ios::scientific);
846 fOut.write( (
char*)(&index),
sizeof (
G4int));
851 for (i=0; i<materialName.length() && i<FixedStringLengthForStore-1; ++i) {
852 temp[i]=materialName[i];
854 fOut.write(temp, FixedStringLengthForStore);
858 for (i=0; i<regionName.length() && i<FixedStringLengthForStore-1; ++i) {
859 temp[i]=regionName[i];
861 fOut.write(temp, FixedStringLengthForStore);
865 fOut.write( (
char*)(&(cutValues[
idx])),
sizeof (
G4double));
883 const G4String fileName = directory +
"/" +
"couple.dat";
897 G4cerr <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
901 G4Exception(
"G4ProductionCutsTable::CheckMaterialCutsCoupleInfo()",
915 keyword = (
const char*)(temp);
920 G4cerr <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
921 G4cerr <<
" Key word in " << fileName <<
"= " << keyword ;
925 G4Exception(
"G4ProductionCutsTable::CheckMaterialCutsCoupleInfo()",
933 G4int numberOfCouples;
935 fIn >> numberOfCouples;
937 fIn.read( (
char*)(&numberOfCouples),
sizeof (
G4int));
950 fIn.read( (
char*)(&index),
sizeof (
G4int));
971 cutValues[i] *= (
mm);
973 fIn.read( (
char*)(&(cutValues[i])),
sizeof (
G4double));
992 fRatio = fRatio && (0.999<
ratio) && (ratio<1.001) ;
995 if (!fRatio)
continue;
1008 if ( regionname !=
"NONE" ) {
1010 if (fRegion ==
nullptr) {
1011 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
1012 G4cout <<
"Region " << regionname <<
" is not found ";
1016 if ( ( (regionname ==
"NONE") && (aCouple->
IsUsed()) ) ||
1018 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
1019 G4cout <<
"A Couple is used differnt region in the current setup ";
1021 G4cout <<
" material: " << mat_name ;
1024 G4cout <<
"cut[" << ii <<
"]=" << cutValues[ii]/
mm;
1028 }
else if ( index != aCouple->
GetIndex() ) {
1029 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
1032 G4cout <<
" is defined as " ;
1033 G4cout << index <<
":" << mat_name <<
" in " << fileName <<
G4endl;
1035 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
1036 G4cout << index <<
":" << mat_name <<
" in " << fileName ;
1037 G4cout <<
" is consistent with current setup" <<
G4endl;
1044 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
1045 G4cout <<
"Couples is not defined in the current detector setup ";
1047 G4cout <<
" material: " << mat_name ;
1050 G4cout <<
"cut[" << ii <<
"]=" << cutValues[ii]/
mm;
1070 const G4String fileName = directory +
"/" +
"cut.dat";
1077 fOut.open(fileName,std::ios::out|std::ios::binary);
1079 fOut.open(fileName,std::ios::out);
1085 G4cerr <<
"G4ProductionCutsTable::StoreCutsInfo ";
1088 G4Exception(
"G4ProductionCutsTable::StoreCutsInfo()",
1101 fOut << numberOfCouples <<
G4endl;
1107 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i)
1109 fOut.write(temp, FixedStringLengthForStore);
1112 fOut.write( (
char*)(&numberOfCouples),
sizeof (
G4int));
1125 fOut.setf(std::ios::scientific);
1126 fOut << std::setw(20) << (*fRange)[i]/
mm ;
1127 fOut << std::setw(20) << (*fEnergy)[i]/
keV <<
G4endl;
1128 fOut.unsetf(std::ios::scientific);
1132 fOut.write((
char*)(&cut),
sizeof (
G4double));
1133 cut = (*fEnergy)[i];
1134 fOut.write((
char*)(&cut),
sizeof (
G4double));
1148 const G4String fileName = directory +
"/" +
"cut.dat";
1161 G4cerr <<
"G4ProductionCutTable::RetrieveCutsInfo ";
1164 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1178 keyword = (
const char*)(temp);
1182 G4cerr <<
"G4ProductionCutTable::RetrieveCutsInfo ";
1183 G4cerr <<
" Key word in " << fileName <<
"= " << keyword ;
1186 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1193 G4int numberOfCouples;
1195 fIn >> numberOfCouples;
1197 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1203 fIn.read( (
char*)(&numberOfCouples),
sizeof (
G4int));
1207 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1209 "Number of Couples in the file exceeds defined couples ");
1220 for (
size_t i=0;
static_cast<G4int>(i)< numberOfCouples; i++){
1223 fIn >> rcut >> ecut;
1225 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1233 fIn.read((
char*)(&rcut),
sizeof (
G4double));
1234 fIn.read((
char*)(&ecut),
sizeof (
G4double));
1238 (*fRange)[new_index] = rcut;
1239 (*fEnergy)[new_index] = ecut;