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 : ";
390 G4cout <<
" Range cuts : "
396 G4cout <<
" Energy thresholds : " ;
400 G4cout <<
" gamma " <<
G4BestUnit((*(energyCutTable[0]))[aCouple->
GetIndex()],
"Energy")
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) ){
413 G4cout <<
" " << (*rItr)->GetName() <<
G4endl;
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){
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;
977 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;
1015 if (verboseLevel >0) {
1016 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo ";
1017 G4cout <<
"Couples is not defined in the current detector setup ";
1019 G4cout <<
" material: " << mat_name ;
1022 G4cout <<
"cut[" << ii <<
"]=" << cutValues[ii]/
mm;
1042 const G4String fileName = directory +
"/" +
"cut.dat";
1045 char temp[FixedStringLengthForStore];
1049 fOut.open(fileName,std::ios::out|std::ios::binary);
1051 fOut.open(fileName,std::ios::out);
1056 if(verboseLevel>0) {
1057 G4cerr <<
"G4ProductionCutsTable::StoreCutsInfo ";
1060 G4Exception(
"G4ProductionCutsTable::StoreCutsInfo()",
1066 G4int numberOfCouples = coupleTable.size();
1073 fOut << numberOfCouples <<
G4endl;
1078 for (i=0; i<FixedStringLengthForStore; ++i) temp[i] =
'\0';
1079 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i)
1081 fOut.write(temp, FixedStringLengthForStore);
1084 fOut.write( (
char*)(&numberOfCouples),
sizeof (
G4int));
1093 CoupleTableIterator cItr;
1094 for (cItr=coupleTable.begin();cItr!=coupleTable.end();cItr++, i++){
1097 fOut.setf(std::ios::scientific);
1098 fOut << std::setw(20) << (*fRange)[i]/
mm ;
1099 fOut << std::setw(20) << (*fEnergy)[i]/
keV <<
G4endl;
1100 fOut.unsetf(std::ios::scientific);
1104 fOut.write((
char*)(&cut),
sizeof (
G4double));
1105 cut = (*fEnergy)[i];
1106 fOut.write((
char*)(&cut),
sizeof (
G4double));
1120 const G4String fileName = directory +
"/" +
"cut.dat";
1126 fIn.open(fileName,std::ios::in|std::ios::binary);
1128 fIn.open(fileName,std::ios::in);
1132 if (verboseLevel >0) {
1133 G4cerr <<
"G4ProductionCutTable::RetrieveCutsInfo ";
1136 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1142 char temp[FixedStringLengthForStore];
1149 fIn.read(temp, FixedStringLengthForStore);
1150 keyword = (
const char*)(temp);
1153 if (verboseLevel >0) {
1154 G4cerr <<
"G4ProductionCutTable::RetrieveCutsInfo ";
1155 G4cerr <<
" Key word in " << fileName <<
"= " << keyword ;
1158 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1165 G4int numberOfCouples;
1167 fIn >> numberOfCouples;
1169 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1175 fIn.read( (
char*)(&numberOfCouples),
sizeof (
G4int));
1178 if (numberOfCouples > static_cast<G4int>(mccConversionTable.
size()) ){
1179 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1181 "Number of Couples in the file exceeds defined couples ");
1183 numberOfCouples = mccConversionTable.
size();
1186 G4CutVectorForAParticle* fRange = rangeCutTable[idx];
1187 G4CutVectorForAParticle* fEnergy = energyCutTable[idx];
1192 for (
size_t i=0;
static_cast<G4int>(i)< numberOfCouples; i++){
1195 fIn >> rcut >> ecut;
1197 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1205 fIn.read((
char*)(&rcut),
sizeof (
G4double));
1206 fIn.read((
char*)(&ecut),
sizeof (
G4double));
1208 if (!mccConversionTable.
IsUsed(i))
continue;
1209 size_t new_index = mccConversionTable.
GetIndex(i);
1210 (*fRange)[new_index] = rcut;
1211 (*fEnergy)[new_index] = ecut;
1222 verboseLevel =
value;
1224 if (converters[ip] !=0 ){
virtual G4bool StoreMaterialInfo(const G4String &directory, G4bool ascii=false)
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
const std::vector< G4double > * GetEnergyCutsVector(size_t pcIdx) const
G4double GetHighEdgeEnergy() const
static G4int GetIndex(const G4String &name)
static constexpr double mm
G4Material * GetMaterial() const
G4int GetIndex(size_t index) const
void SetEnergyRange(G4double lowedge, G4double highedge)
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
G4bool CheckForRetrieveCutsTable(const G4String &directory, G4bool ascii=false)
G4double GetProductionCut(G4int index) const
const G4String & GetName() const
void SetNewIndex(size_t index, size_t new_value)
static G4MaterialTable * GetMaterialTable()
std::vector< G4Material * > G4MaterialTable
G4double GetDensity() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
static G4double GetLowEdgeEnergy()
virtual G4bool CheckMaterialCutsCoupleInfo(const G4String &directory, G4bool ascii=false)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4Region * GetRegion() const
G4bool IsUsed(size_t index) const
const G4String & GetParticleName() const
static G4double GetMaxEnergyCut()
static G4RegionStore * GetInstance()
G4GLOB_DLL std::ostream G4cout
virtual G4double Convert(G4double rangeCut, const G4Material *material)
const XML_Char int const XML_Char * value
const G4ParticleDefinition const G4Material *G4double range
virtual ~G4ProductionCutsTable()
virtual G4bool RetrieveCutsInfo(const G4String &directory, G4bool ascii=false)
void SetVerboseLevel(G4int value)
G4bool RetrieveCutsTable(const G4String &directory, G4bool ascii=false)
static void SetMaxEnergyCut(G4double value)
void SetMaterialCutsCouple(G4MaterialCutsCouple *cuts)
static void SetEnergyRange(G4double lowedge, G4double highedge)
const std::vector< G4double > * GetRangeCutsVector(size_t pcIdx) const
static constexpr double cm3
G4int GetNoDaughters() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
const std::vector< G4double > & GetProductionCuts() const
G4double GetLowEdgeEnergy() const
static G4ProductionCutsTable * GetProductionCutsTable()
G4LogicalVolume * GetLogicalVolume() const
static G4ParticleTable * GetParticleTable()
virtual G4bool StoreMaterialCutsCoupleInfo(const G4String &directory, G4bool ascii=false)
void SetUseFlag(G4bool flg=true)
G4bool StoreCutsTable(const G4String &directory, G4bool ascii=false)
G4double GetMaxEnergyCut()
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
G4double ConvertRangeToEnergy(const G4ParticleDefinition *particle, const G4Material *material, G4double range)
virtual G4bool CheckMaterialInfo(const G4String &directory, G4bool ascii=false)
G4ProductionCuts * GetProductionCuts() const
static constexpr double keV
void SetMaxEnergyCut(G4double value)
G4int GetVerboseLevel() const
static G4double GetHighEdgeEnergy()
virtual G4bool StoreCutsInfo(const G4String &directory, G4bool ascii=false)
const G4Material * GetMaterial() const
G4GLOB_DLL std::ostream G4cerr
void SetVerboseLevel(G4int value)