61 if(fProductionCutsTable ==
nullptr)
63 fProductionCutsTable = &theProductionCutsTable;
65 return fProductionCutsTable;
73 rangeCutTable.push_back(
new std::vector<G4double>);
74 energyCutTable.push_back(
new std::vector<G4double>);
75 rangeDoubleVector[i] =
nullptr;
76 energyDoubleVector[i] =
nullptr;
77 converters[i] =
nullptr;
89 delete defaultProductionCuts;
90 defaultProductionCuts =
nullptr;
92 for(
auto itr=coupleTable.cbegin(); itr!=coupleTable.cend(); ++itr)
100 delete rangeCutTable[i];
101 delete energyCutTable[i];
102 delete converters[i];
103 if(rangeDoubleVector[i] !=
nullptr)
delete [] rangeDoubleVector[i];
104 if(energyDoubleVector[i] !=
nullptr)
delete [] energyDoubleVector[i];
105 rangeCutTable[i] =
nullptr;
106 energyCutTable[i] =
nullptr;
107 converters[i] =
nullptr;
108 rangeDoubleVector[i] =
nullptr;
109 energyDoubleVector[i] =
nullptr;
111 fProductionCutsTable =
nullptr;
114 fMessenger =
nullptr;
146 for(
auto CoupleItr=coupleTable.cbegin();
147 CoupleItr!=coupleTable.cend(); ++CoupleItr)
149 (*CoupleItr)->SetUseFlag(
false);
153 for(
auto rItr=fG4RegionStore->cbegin(); rItr!=fG4RegionStore->cend(); ++rItr)
159 if( (*rItr)->IsInMassGeometry() || (*rItr)->IsInParallelGeometry() )
162 auto mItr = (*rItr)->GetMaterialIterator();
163 std::size_t nMaterial = (*rItr)->GetNumberOfMaterials();
166 for(std::size_t iMate=0; iMate<nMaterial; ++iMate)
169 G4bool coupleAlreadyDefined =
false;
171 for(
auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
173 if( (*cItr)->GetMaterial()==(*mItr)
174 && (*cItr)->GetProductionCuts()==fProductionCut)
176 coupleAlreadyDefined =
true;
183 if(!coupleAlreadyDefined)
186 coupleTable.push_back(aCouple);
191 (*rItr)->RegisterMaterialCouplePair((*mItr),aCouple);
196 auto rootLVItr = (*rItr)->GetRootLogicalVolumeIterator();
197 std::size_t nRootLV = (*rItr)->GetNumberOfRootVolumes();
198 for(std::size_t iLV=0; iLV<nRootLV; ++iLV)
204 ScanAndSetCouple(aLV,aCouple,aR);
220 std::size_t nCouple = coupleTable.size();
221 std::size_t nTable = energyCutTable[0]->size();
222 G4bool newCoupleAppears = nCouple>nTable;
225 for(std::size_t n=nCouple-nTable; n>0; --n)
229 rangeCutTable[nn]->push_back(-1.);
230 energyCutTable[nn]->push_back(-1.);
242 for(
auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
246 if((*cItr)->IsRecalcNeeded())
251 (*(rangeCutTable[ptcl]))[idx] = rCut;
255 (*(energyCutTable[ptcl]))[idx] = converters[ptcl]->
Convert(rCut,aMat);
259 (*(energyCutTable[ptcl]))[idx] = -1.;
268 G4cout <<
"G4ProductionCutsTable::UpdateCoupleTable() - "
269 <<
"Elapsed time for calculation of energy cuts: " <<
G4endl;
278 G4double* rangeVOld = rangeDoubleVector[ix];
279 G4double* energyVOld = energyDoubleVector[ix];
280 if(rangeVOld)
delete [] rangeVOld;
281 if(energyVOld)
delete [] energyVOld;
282 rangeDoubleVector[ix] =
new G4double[(*(rangeCutTable[ix])).size()];
283 energyDoubleVector[ix] =
new G4double[(*(energyCutTable[ix])).size()];
290 for(std::size_t ixx=0; ixx<(*(rangeCutTable[ix])).size(); ++ixx)
292 rangeDoubleVector[ix][ixx] = (*(rangeCutTable[ix]))[ixx];
293 energyDoubleVector[ix][ixx] = (*(energyCutTable[ix]))[ixx];
313 ed <<
"Invoked prematurely before it is fully initialized.";
314 G4Exception(
"G4ProductionCutsTable::ConvertRangeToEnergy()",
322 if (material ==
nullptr)
return -1.0;
325 if (range == 0.0)
return 0.0;
326 if (range <0.0)
return -1.0;
331 if (index<0 || converters[index] ==
nullptr)
338 if(particle !=
nullptr)
341 { ed <<
"without valid particle pointer."; }
342 G4Exception(
"G4ProductionCutsTable::ConvertRangeToEnergy()",
349 return converters[index]->
Convert(range, material);
380 if((aRegion!=
nullptr) && aLV->
GetRegion()!=aRegion)
return;
389 if(noDaughters==0)
return;
392 for(std::size_t i=0; i<noDaughters; ++i)
395 ScanAndSetCouple(daughterLVol,aCouple,aRegion);
403 G4cout <<
"========= Table of registered couples ============================"
405 for(
auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
411 <<
" used in the geometry : ";
419 G4cout <<
" Range cuts : "
425 G4cout <<
" Energy thresholds : " ;
438 G4cout <<
" Region(s) which use this couple : " <<
G4endl;
439 for(
auto rItr=fG4RegionStore->cbegin();
440 rItr!=fG4RegionStore->cend(); ++rItr)
442 if (IsCoupleUsedInTheRegion(aCouple, *rItr) )
450 G4cout <<
"==================================================================" <<
G4endl;
467 G4cout <<
"G4ProductionCutsTable::StoreCutsTable()" <<
G4endl;
468 G4cout <<
" Material/Cuts information have been successfully stored ";
471 G4cout <<
" in Ascii mode ";
475 G4cout <<
" in Binary mode ";
492 G4cout <<
"G4ProductionCutsTable::RetrieveCutsTable()" <<
G4endl;
493 G4cout <<
" Material/Cuts information have been successfully retrieved ";
496 G4cout <<
" in Ascii mode ";
500 G4cout <<
" in Binary mode ";
516 G4cerr <<
"G4ProductionCutsTable::CheckForRetrieveCutsTable()"<<
G4endl;
521 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo passed !!"<<
G4endl;
526 G4cerr <<
"G4ProductionCutsTable::CheckMaterialCutsCoupleInfo passed !!"
538 const G4String fileName = directory +
"/" +
"material.dat";
539 const G4String key =
"MATERIAL-V3.0";
543 if (!ascii ) fOut.open(fileName,std::ios::out|std::ios::binary);
544 else fOut.open(fileName,std::ios::out);
552 G4cerr <<
"G4ProductionCutsTable::StoreMaterialInfo() - ";
556 G4Exception(
"G4ProductionCutsTable::StoreMaterialInfo()",
563 G4int numberOfMaterial = (
G4int)matTable->size();
572 fOut << numberOfMaterial <<
G4endl;
574 fOut.setf(std::ios::scientific);
577 for (std::size_t idx=0;
static_cast<G4int>(idx)<numberOfMaterial; ++idx)
579 fOut << std::setw(FixedStringLengthForStore)
580 << ((*matTable)[idx])->GetName();
581 fOut << std::setw(FixedStringLengthForStore)
582 << ((*matTable)[idx])->GetDensity()/(g/cm3) <<
G4endl;
585 fOut.unsetf(std::ios::scientific);
591 char temp[FixedStringLengthForStore];
595 for (i=0; i<FixedStringLengthForStore; ++i)
599 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i)
601 temp[i]=key[(
G4int)i];
603 fOut.write(temp, FixedStringLengthForStore);
606 fOut.write( (
char*)(&numberOfMaterial),
sizeof(
G4int));
609 for (std::size_t imat=0;
static_cast<G4int>(imat)<numberOfMaterial; ++imat)
611 G4String name = ((*matTable)[imat])->GetName();
612 G4double density = ((*matTable)[imat])->GetDensity();
613 for (i=0; i<FixedStringLengthForStore; ++i)
615 for (i=0; i<name.length() && i<FixedStringLengthForStore-1; ++i)
616 temp[i]=name[(
G4int)i];
617 fOut.write(temp, FixedStringLengthForStore);
618 fOut.write( (
char*)(&density),
sizeof(
G4double));
632 const G4String fileName = directory +
"/" +
"material.dat";
633 const G4String key =
"MATERIAL-V3.0";
637 if (!ascii ) fIn.open(fileName,std::ios::in|std::ios::binary);
638 else fIn.open(fileName,std::ios::in);
646 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo() - ";
650 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
655 char temp[FixedStringLengthForStore];
665 fIn.read(temp, FixedStringLengthForStore);
666 keyword = (
const char*)(temp);
673 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo() - ";
674 G4cerr <<
"Key word in " << fileName <<
"= " << keyword ;
678 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
691 fIn.read( (
char*)(&nmat),
sizeof(
G4int));
693 if ((nmat<=0) || (nmat >100000))
695 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
697 "Number of materials is less than zero or too big");
702 for (
G4int idx=0; idx<nmat ; ++idx)
710 G4cout <<
"G4ProductionCutsTable::CheckMaterialInfo() - ";
711 G4cout <<
"Encountered End of File " ;
720 char name[FixedStringLengthForStore];
724 fIn >> name >> density;
730 fIn.read(name, FixedStringLengthForStore);
731 fIn.read((
char*)(&density),
sizeof(
G4double));
738 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo() - ";
739 G4cerr <<
"Bad data format ";
743 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
750 if (aMaterial ==
nullptr )
continue;
753 if ((0.999>ratio) || (ratio>1.001) )
758 G4cerr <<
"G4ProductionCutsTable::CheckMaterialInfo() - ";
762 G4cerr <<
"Density:" << std::setiosflags(std::ios::scientific)
763 << density / (g/cm3) ;
766 G4cerr << std::resetiosflags(std::ios::scientific);
769 G4Exception(
"G4ProductionCutsTable::CheckMaterialInfo()",
770 "ProcCuts104",
JustWarning,
"Inconsistent material density");
787 const G4String fileName = directory +
"/" +
"couple.dat";
790 char temp[FixedStringLengthForStore];
793 if (!ascii ) fOut.open(fileName,std::ios::out|std::ios::binary);
794 else fOut.open(fileName,std::ios::out);
803 G4cerr <<
"G4ProductionCutsTable::StoreMaterialCutsCoupleInfo() - ";
807 G4Exception(
"G4ProductionCutsTable::StoreMaterialCutsCoupleInfo()",
812 G4int numberOfCouples = (
G4int)coupleTable.size();
817 fOut << std::setw(FixedStringLengthForStore) << key <<
G4endl;
820 fOut << numberOfCouples <<
G4endl;
827 for (i=0; i<FixedStringLengthForStore; ++i)
829 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i)
830 temp[i]=key[(
G4int)i];
831 fOut.write(temp, FixedStringLengthForStore);
834 fOut.write( (
char*)(&numberOfCouples),
sizeof(
G4int));
838 for (
auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
854 for(
auto rItr=fG4RegionStore->cbegin();
855 rItr!=fG4RegionStore->cend(); ++rItr)
857 if (IsCoupleUsedInTheRegion(aCouple, *rItr))
859 regionName = (*rItr)->GetName();
872 fOut << std::setw(FixedStringLengthForStore) << materialName<<
G4endl;
875 fOut << std::setw(FixedStringLengthForStore) << regionName<<
G4endl;
877 fOut.setf(std::ios::scientific);
881 fOut << std::setw(FixedStringLengthForStore) << cutValues[idx]/(mm)
884 fOut.unsetf(std::ios::scientific);
891 fOut.write( (
char*)(&index),
sizeof(
G4int));
895 for (i=0; i<FixedStringLengthForStore; ++i)
897 for (i=0; i<materialName.length() && i<FixedStringLengthForStore-1; ++i)
898 temp[i]=materialName[(
G4int)i];
899 fOut.write(temp, FixedStringLengthForStore);
902 for (i=0; i<FixedStringLengthForStore; ++i)
904 for (i=0; i<regionName.length() && i<FixedStringLengthForStore-1; ++i)
905 temp[i]=regionName[(
G4int)i];
906 fOut.write(temp, FixedStringLengthForStore);
911 fOut.write( (
char*)(&(cutValues[idx])),
sizeof(
G4double));
927 const G4String fileName = directory +
"/" +
"couple.dat";
932 if (!ascii ) fIn.open(fileName,std::ios::in|std::ios::binary);
933 else fIn.open(fileName,std::ios::in);
941 G4cerr <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo() - ";
945 G4Exception(
"G4ProductionCutsTable::CheckMaterialCutsCoupleInfo()",
950 char temp[FixedStringLengthForStore];
960 fIn.read(temp, FixedStringLengthForStore);
961 keyword = (
const char*)(temp);
968 G4cerr <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo() - ";
969 G4cerr <<
"Key word in " << fileName <<
"= " << keyword ;
973 G4Exception(
"G4ProductionCutsTable::CheckMaterialCutsCoupleInfo()",
980 G4int numberOfCouples;
983 fIn >> numberOfCouples;
987 fIn.read( (
char*)(&numberOfCouples),
sizeof(
G4int));
991 mccConversionTable.
Reset(numberOfCouples);
994 for (
G4int idx=0; idx<numberOfCouples; ++idx)
1004 fIn.read( (
char*)(&index),
sizeof(
G4int));
1007 char mat_name[FixedStringLengthForStore];
1014 fIn.read(mat_name, FixedStringLengthForStore);
1017 char region_name[FixedStringLengthForStore];
1024 fIn.read(region_name, FixedStringLengthForStore);
1032 fIn >> cutValues[i];
1033 cutValues[i] *= (mm);
1037 fIn.read( (
char*)(&(cutValues[i])),
sizeof(
G4double));
1044 for (
auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
1058 fRatio = fRatio && (0.999<ratio) && (ratio<1.001) ;
1061 if (!fRatio)
continue;
1072 if (verboseLevel >1)
1076 if ( regionname !=
"NONE" )
1078 fRegion = fG4RegionStore->
GetRegion(region_name);
1079 if (fRegion ==
nullptr)
1081 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo() - ";
1082 G4cout <<
"Region " << regionname <<
" is not found ";
1086 if (((regionname ==
"NONE") && (aCouple->
IsUsed()))
1087 || ((fRegion!=
nullptr) && !IsCoupleUsedInTheRegion(aCouple, fRegion)))
1089 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo()"
1091 G4cout <<
"A Couple is used different region in the current setup ";
1093 G4cout <<
" material: " << mat_name ;
1097 G4cout <<
"cut[" << ii <<
"]=" << cutValues[ii]/mm;
1102 else if ( index != aCouple->
GetIndex() )
1104 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo() - ";
1108 G4cout <<
" is defined as " ;
1109 G4cout << index <<
":" << mat_name <<
" in " << fileName <<
G4endl;
1113 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo() - ";
1114 G4cout << index <<
":" << mat_name <<
" in " << fileName ;
1115 G4cout <<
" is consistent with current setup" <<
G4endl;
1123 if (verboseLevel >0)
1125 G4cout <<
"G4ProductionCutTable::CheckMaterialCutsCoupleInfo()"
1127 G4cout <<
"Couples are not defined in the current detector setup ";
1129 G4cout <<
" material: " << mat_name ;
1133 G4cout <<
"cut[" << ii <<
"]=" << cutValues[ii]/mm;
1151 const G4String fileName = directory +
"/" +
"cut.dat";
1154 char temp[FixedStringLengthForStore];
1157 if (!ascii ) fOut.open(fileName,std::ios::out|std::ios::binary);
1158 else fOut.open(fileName,std::ios::out);
1165 G4cerr <<
"G4ProductionCutsTable::StoreCutsInfo() - ";
1168 G4Exception(
"G4ProductionCutsTable::StoreCutsInfo()",
1173 G4int numberOfCouples = (
G4int)coupleTable.size();
1181 fOut << numberOfCouples <<
G4endl;
1188 for (i=0; i<FixedStringLengthForStore; ++i)
1190 for (i=0; i<key.length() && i<FixedStringLengthForStore-1; ++i)
1191 temp[i]=key[(
G4int)i];
1192 fOut.write(temp, FixedStringLengthForStore);
1195 fOut.write( (
char*)(&numberOfCouples),
sizeof(
G4int));
1204 for (
auto cItr=coupleTable.cbegin();cItr!=coupleTable.cend(); ++cItr, ++i)
1209 fOut.setf(std::ios::scientific);
1210 fOut << std::setw(20) << (*fRange)[i]/mm ;
1211 fOut << std::setw(20) << (*fEnergy)[i]/keV <<
G4endl;
1212 fOut.unsetf(std::ios::scientific);
1218 fOut.write((
char*)(&cut),
sizeof(
G4double));
1219 cut = (*fEnergy)[i];
1220 fOut.write((
char*)(&cut),
sizeof(
G4double));
1234 const G4String fileName = directory +
"/" +
"cut.dat";
1239 if (!ascii ) fIn.open(fileName,std::ios::in|std::ios::binary);
1240 else fIn.open(fileName,std::ios::in);
1245 if (verboseLevel >0)
1247 G4cerr <<
"G4ProductionCutTable::RetrieveCutsInfo() - ";
1250 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1255 char temp[FixedStringLengthForStore];
1265 fIn.read(temp, FixedStringLengthForStore);
1266 keyword = (
const char*)(temp);
1270 if (verboseLevel >0)
1272 G4cerr <<
"G4ProductionCutTable::RetrieveCutsInfo() - ";
1273 G4cerr <<
"Key word in " << fileName <<
"= " << keyword ;
1276 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1282 G4int numberOfCouples;
1285 fIn >> numberOfCouples;
1288 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1295 fIn.read( (
char*)(&numberOfCouples),
sizeof(
G4int));
1298 if (numberOfCouples >
static_cast<G4int>(mccConversionTable.
size()) )
1300 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1302 "Number of Couples in the file exceeds defined couples");
1304 numberOfCouples = (
G4int)mccConversionTable.
size();
1308 std::vector<G4double>* fRange = rangeCutTable[idx];
1309 std::vector<G4double>* fEnergy = energyCutTable[idx];
1314 for (std::size_t i=0;
static_cast<G4int>(i)< numberOfCouples; ++i)
1319 fIn >> rcut >> ecut;
1322 G4Exception(
"G4ProductionCutsTable::RetrieveCutsInfo()",
1331 fIn.read((
char*)(&rcut),
sizeof(
G4double));
1332 fIn.read((
char*)(&ecut),
sizeof(
G4double));
1334 if (!mccConversionTable.
IsUsed(i))
continue;
1335 std::size_t new_index = mccConversionTable.
GetIndex(i);
1336 (*fRange)[new_index] = rcut;
1337 (*fEnergy)[new_index] = ecut;
1348 verboseLevel = value;
1351 if (converters[ip] !=
nullptr )
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::vector< G4Material * > G4MaterialTable
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
std::size_t GetNoDaughters() const
G4Region * GetRegion() const
G4Material * GetMaterial() const
G4VPhysicalVolume * GetDaughter(const std::size_t i) const
void SetMaterialCutsCouple(G4MaterialCutsCouple *cuts)
void SetNewIndex(std::size_t index, std::size_t new_value)
G4bool IsUsed(std::size_t index) const
G4int GetIndex(std::size_t index) const
void Reset(std::size_t size)
const G4Material * GetMaterial() const
void SetUseFlag(G4bool flg=true)
G4ProductionCuts * GetProductionCuts() const
G4double GetDensity() const
static G4MaterialTable * GetMaterialTable()
const G4String & GetName() const
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
const G4String & GetParticleName() const
static G4ParticleTable * GetParticleTable()
const std::vector< G4double > * GetRangeCutsVector(std::size_t pcIdx) const
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)
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(std::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
static void SetMaxEnergyCut(const G4double value)
void SetVerboseLevel(G4int value)
static G4double GetMaxEnergyCut()
virtual G4double Convert(const G4double rangeCut, const G4Material *material)
static void SetEnergyRange(const G4double lowedge, const G4double highedge)
static G4double GetLowEdgeEnergy()
static G4double GetHighEdgeEnergy()