File indexing completed on 2025-01-18 09:58:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #ifndef G4ProductionCutsTable_hh
0038 #define G4ProductionCutsTable_hh 1
0039
0040 #include <cmath>
0041 #include <vector>
0042
0043 #include "globals.hh"
0044 #include "G4ios.hh"
0045 #include "G4MaterialCutsCouple.hh"
0046 #include "G4MCCIndexConversionTable.hh"
0047 #include "G4Region.hh"
0048
0049 class G4RegionStore;
0050 class G4VRangeToEnergyConverter;
0051 class G4LogicalVolume;
0052 class G4VPhysicalVolume;
0053 class G4ProductionCuts;
0054 class G4ProductionCutsTableMessenger;
0055
0056 class G4ProductionCutsTable
0057 {
0058 public:
0059
0060 static G4ProductionCutsTable* GetProductionCutsTable();
0061
0062
0063
0064 G4ProductionCutsTable(const G4ProductionCutsTable&) = delete;
0065 G4ProductionCutsTable& operator=(const G4ProductionCutsTable&) = delete;
0066
0067 virtual ~G4ProductionCutsTable();
0068
0069 void CreateCoupleTables();
0070
0071
0072 void UpdateCoupleTable(G4VPhysicalVolume* currentWorld);
0073
0074
0075 void SetEnergyRange(G4double lowedge, G4double highedge);
0076
0077
0078 G4double GetLowEdgeEnergy() const;
0079 G4double GetHighEdgeEnergy() const;
0080
0081
0082 G4double GetMaxEnergyCut();
0083 void SetMaxEnergyCut(G4double value);
0084
0085
0086
0087 void DumpCouples() const;
0088
0089
0090 const G4MCCIndexConversionTable* GetMCCIndexConversionTable() const;
0091
0092
0093 const std::vector<G4double>* GetRangeCutsVector(std::size_t pcIdx) const;
0094 const std::vector<G4double>* GetEnergyCutsVector(std::size_t pcIdx) const;
0095
0096 std::size_t GetTableSize() const;
0097
0098
0099 const G4MaterialCutsCouple* GetMaterialCutsCouple(G4int i) const;
0100
0101
0102 const G4MaterialCutsCouple* GetMaterialCutsCouple(const G4Material* aMat,
0103 const G4ProductionCuts* aCut) const;
0104
0105
0106 G4int GetCoupleIndex(const G4MaterialCutsCouple* aCouple) const;
0107 G4int GetCoupleIndex(const G4Material* aMat,
0108 const G4ProductionCuts* aCut) const;
0109
0110
0111
0112 G4bool IsModified() const;
0113
0114
0115 void PhysicsTableUpdated();
0116
0117
0118
0119 G4ProductionCuts* GetDefaultProductionCuts() const;
0120
0121
0122 G4double ConvertRangeToEnergy(const G4ParticleDefinition* particle,
0123 const G4Material* material,
0124 G4double range);
0125
0126
0127
0128 void ResetConverters();
0129
0130
0131 G4bool StoreCutsTable(const G4String& directory,
0132 G4bool ascii = false);
0133
0134
0135
0136 G4bool RetrieveCutsTable(const G4String& directory,
0137 G4bool ascii = false);
0138
0139
0140
0141 G4bool CheckForRetrieveCutsTable(const G4String& directory,
0142 G4bool ascii = false);
0143
0144
0145
0146 G4double* GetRangeCutsDoubleVector(std::size_t pcIdx) const;
0147 G4double* GetEnergyCutsDoubleVector(std::size_t pcIdx) const;
0148
0149
0150 void SetEnergyCutVector(const std::vector<G4double>& cutE, std::size_t idx);
0151
0152
0153
0154 void SetVerboseLevel(G4int value);
0155 G4int GetVerboseLevel() const;
0156
0157
0158
0159
0160
0161 protected:
0162
0163 G4ProductionCutsTable();
0164
0165 virtual G4bool StoreMaterialInfo(const G4String& directory,
0166 G4bool ascii = false);
0167
0168
0169 virtual G4bool CheckMaterialInfo(const G4String& directory,
0170 G4bool ascii = false);
0171
0172
0173 virtual G4bool StoreMaterialCutsCoupleInfo(const G4String& directory,
0174 G4bool ascii = false);
0175
0176
0177
0178 virtual G4bool CheckMaterialCutsCoupleInfo(const G4String& directory,
0179 G4bool ascii = false);
0180
0181
0182
0183 virtual G4bool StoreCutsInfo(const G4String& directory,
0184 G4bool ascii = false);
0185
0186
0187 virtual G4bool RetrieveCutsInfo(const G4String& directory,
0188 G4bool ascii = false);
0189
0190
0191
0192 private:
0193
0194 void ScanAndSetCouple(G4LogicalVolume* aLV,
0195 G4MaterialCutsCouple* aCouple,
0196 G4Region* aRegion);
0197
0198 G4bool IsCoupleUsedInTheRegion(const G4MaterialCutsCouple* aCouple,
0199 const G4Region* aRegion) const;
0200
0201
0202 private:
0203
0204 static G4ProductionCutsTable* fProductionCutsTable;
0205
0206 std::vector<G4MaterialCutsCouple*> coupleTable;
0207 std::vector<std::vector<G4double>*> rangeCutTable;
0208 std::vector<std::vector<G4double>*> energyCutTable;
0209
0210 std::vector<G4double>* userEnergyCuts[4] = {nullptr, nullptr, nullptr, nullptr};
0211
0212 G4RegionStore* fG4RegionStore = nullptr;
0213 G4VRangeToEnergyConverter* converters[NumberOfG4CutIndex];
0214
0215 G4ProductionCuts* defaultProductionCuts = nullptr;
0216
0217 G4MCCIndexConversionTable mccConversionTable;
0218
0219
0220 G4double* rangeDoubleVector[NumberOfG4CutIndex];
0221 G4double* energyDoubleVector[NumberOfG4CutIndex];
0222
0223 enum { FixedStringLengthForStore = 32 };
0224
0225 G4ProductionCutsTableMessenger* fMessenger = nullptr;
0226 G4int verboseLevel = 1;
0227 G4bool firstUse = true;
0228 };
0229
0230
0231
0232
0233
0234 inline
0235 const std::vector<G4double>*
0236 G4ProductionCutsTable::GetRangeCutsVector(std::size_t pcIdx) const
0237 {
0238 return rangeCutTable[pcIdx];
0239 }
0240
0241 inline
0242 const std::vector<G4double>*
0243 G4ProductionCutsTable::GetEnergyCutsVector(std::size_t pcIdx) const
0244 {
0245 return energyCutTable[pcIdx];
0246 }
0247
0248 inline
0249 std::size_t G4ProductionCutsTable::GetTableSize() const
0250 {
0251 return coupleTable.size();
0252 }
0253
0254 inline
0255 const G4MaterialCutsCouple*
0256 G4ProductionCutsTable::GetMaterialCutsCouple(G4int i) const
0257 {
0258 return coupleTable[std::size_t(i)];
0259 }
0260
0261 inline
0262 G4bool G4ProductionCutsTable::IsModified() const
0263 {
0264 if(firstUse) return true;
0265 for(auto itr=coupleTable.cbegin(); itr!=coupleTable.cend(); ++itr)
0266 {
0267 if((*itr)->IsRecalcNeeded())
0268 {
0269 return true;
0270 }
0271 }
0272 return false;
0273 }
0274
0275 inline
0276 void G4ProductionCutsTable::PhysicsTableUpdated()
0277 {
0278 for(auto itr=coupleTable.cbegin(); itr!=coupleTable.cend(); ++itr)
0279 {
0280 (*itr)->PhysicsTableUpdated();
0281 }
0282 }
0283
0284 inline
0285 G4double*
0286 G4ProductionCutsTable::GetRangeCutsDoubleVector(std::size_t pcIdx) const
0287 {
0288 return rangeDoubleVector[pcIdx];
0289 }
0290
0291 inline
0292 G4double*
0293 G4ProductionCutsTable::GetEnergyCutsDoubleVector(std::size_t pcIdx) const
0294 {
0295 return energyDoubleVector[pcIdx];
0296 }
0297
0298 inline
0299 G4ProductionCuts* G4ProductionCutsTable::GetDefaultProductionCuts() const
0300 {
0301 return defaultProductionCuts;
0302 }
0303
0304 inline
0305 G4bool G4ProductionCutsTable::IsCoupleUsedInTheRegion(
0306 const G4MaterialCutsCouple* aCouple,
0307 const G4Region* aRegion) const
0308 {
0309 G4ProductionCuts* fProductionCut = aRegion->GetProductionCuts();
0310 auto mItr = aRegion->GetMaterialIterator();
0311 std::size_t nMaterial = aRegion->GetNumberOfMaterials();
0312 for(std::size_t iMate=0;iMate<nMaterial; ++iMate, ++mItr)
0313 {
0314 if(aCouple->GetMaterial()==(*mItr) &&
0315 aCouple->GetProductionCuts()==fProductionCut)
0316 {
0317 return true;
0318 }
0319 }
0320 return false;
0321 }
0322
0323 inline
0324 const G4MaterialCutsCouple*
0325 G4ProductionCutsTable::GetMaterialCutsCouple(const G4Material* aMat,
0326 const G4ProductionCuts* aCut) const
0327 {
0328 for(auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
0329 {
0330 if((*cItr)->GetMaterial()!=aMat) continue;
0331 if((*cItr)->GetProductionCuts()==aCut) return (*cItr);
0332 }
0333 return nullptr;
0334 }
0335
0336 inline
0337 G4int
0338 G4ProductionCutsTable::GetCoupleIndex(const G4MaterialCutsCouple* aCouple) const
0339 {
0340 G4int idx = 0;
0341 for(auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
0342 {
0343 if((*cItr)==aCouple) return idx;
0344 ++idx;
0345 }
0346 return -1;
0347 }
0348
0349 inline
0350 G4int G4ProductionCutsTable::GetCoupleIndex(const G4Material* aMat,
0351 const G4ProductionCuts* aCut) const
0352 {
0353 const G4MaterialCutsCouple* aCouple = GetMaterialCutsCouple(aMat,aCut);
0354 return GetCoupleIndex(aCouple);
0355 }
0356
0357 inline
0358 G4int G4ProductionCutsTable::GetVerboseLevel() const
0359 {
0360 return verboseLevel;
0361 }
0362
0363 inline
0364 const G4MCCIndexConversionTable*
0365 G4ProductionCutsTable::GetMCCIndexConversionTable() const
0366 {
0367 return &mccConversionTable;
0368 }
0369
0370 #endif