Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4ProductionCutsTable 26 // G4ProductionCutsTable 27 // 27 // 28 // Class description: 28 // Class description: 29 // 29 // 30 // G4ProductionCutsTable is a singleton class 30 // G4ProductionCutsTable is a singleton class for a table of 31 // G4ProductionCuts objects. This class manage 31 // G4ProductionCuts objects. This class manages tables of production 32 // cuts and energy cuts for each particle type 32 // cuts and energy cuts for each particle type. 33 33 34 // Author: M.Asai, 5 October 2002 - First impl 34 // Author: M.Asai, 5 October 2002 - First implementation 35 // Modifications: H.Kurashige, 2004-2008 35 // Modifications: H.Kurashige, 2004-2008 36 // ------------------------------------------- 36 // -------------------------------------------------------------------- 37 #ifndef G4ProductionCutsTable_hh 37 #ifndef G4ProductionCutsTable_hh 38 #define G4ProductionCutsTable_hh 1 38 #define G4ProductionCutsTable_hh 1 39 39 40 #include <cmath> 40 #include <cmath> 41 #include <vector> 41 #include <vector> 42 42 43 #include "globals.hh" 43 #include "globals.hh" 44 #include "G4ios.hh" 44 #include "G4ios.hh" 45 #include "G4MaterialCutsCouple.hh" 45 #include "G4MaterialCutsCouple.hh" 46 #include "G4MCCIndexConversionTable.hh" 46 #include "G4MCCIndexConversionTable.hh" 47 #include "G4Region.hh" 47 #include "G4Region.hh" 48 48 49 class G4RegionStore; 49 class G4RegionStore; 50 class G4VRangeToEnergyConverter; 50 class G4VRangeToEnergyConverter; 51 class G4LogicalVolume; 51 class G4LogicalVolume; 52 class G4VPhysicalVolume; 52 class G4VPhysicalVolume; 53 class G4ProductionCuts; 53 class G4ProductionCuts; 54 class G4ProductionCutsTableMessenger; 54 class G4ProductionCutsTableMessenger; 55 55 56 class G4ProductionCutsTable 56 class G4ProductionCutsTable 57 { 57 { 58 public: 58 public: 59 59 60 static G4ProductionCutsTable* GetProductio 60 static G4ProductionCutsTable* GetProductionCutsTable(); 61 // This static method returns the single 61 // This static method returns the singleton pointer of this class object. 62 // At first invocation, the singleton ob 62 // At first invocation, the singleton object is instantiated 63 63 64 G4ProductionCutsTable(const G4ProductionCu 64 G4ProductionCutsTable(const G4ProductionCutsTable&) = delete; 65 G4ProductionCutsTable& operator=(const G4P 65 G4ProductionCutsTable& operator=(const G4ProductionCutsTable&) = delete; 66 66 67 virtual ~G4ProductionCutsTable(); 67 virtual ~G4ProductionCutsTable(); 68 68 69 void CreateCoupleTables(); << 70 // Creates material cuts couples table a << 71 << 72 void UpdateCoupleTable(G4VPhysicalVolume* 69 void UpdateCoupleTable(G4VPhysicalVolume* currentWorld); 73 // Triggers an update of the table of G4 70 // Triggers an update of the table of G4ProductionCuts objects 74 71 75 void SetEnergyRange(G4double lowedge, G4do 72 void SetEnergyRange(G4double lowedge, G4double highedge); 76 // Sets the limits of energy cuts for al 73 // Sets the limits of energy cuts for all particles 77 74 78 G4double GetLowEdgeEnergy() const; 75 G4double GetLowEdgeEnergy() const; 79 G4double GetHighEdgeEnergy() const; 76 G4double GetHighEdgeEnergy() const; 80 // Get the limits of energy cuts for all 77 // Get the limits of energy cuts for all particles 81 78 82 G4double GetMaxEnergyCut(); 79 G4double GetMaxEnergyCut(); 83 void SetMaxEnergyCut(G4double value); 80 void SetMaxEnergyCut(G4double value); 84 // Get/set max cut energy of RangeToEner 81 // Get/set max cut energy of RangeToEnergy converter 85 // for all particle types 82 // for all particle types 86 83 87 void DumpCouples() const; 84 void DumpCouples() const; 88 // Displays a list of registered couples 85 // Displays a list of registered couples 89 86 90 const G4MCCIndexConversionTable* GetMCCInd 87 const G4MCCIndexConversionTable* GetMCCIndexConversionTable() const; 91 // Gives the pointer to the MCCIndexConv 88 // Gives the pointer to the MCCIndexConversionTable 92 89 93 const std::vector<G4double>* GetRangeCutsV 90 const std::vector<G4double>* GetRangeCutsVector(std::size_t pcIdx) const; 94 const std::vector<G4double>* GetEnergyCuts 91 const std::vector<G4double>* GetEnergyCutsVector(std::size_t pcIdx) const; 95 92 96 std::size_t GetTableSize() const; 93 std::size_t GetTableSize() const; 97 // Returns the size of the couple table 94 // Returns the size of the couple table 98 95 99 const G4MaterialCutsCouple* GetMaterialCut 96 const G4MaterialCutsCouple* GetMaterialCutsCouple(G4int i) const; 100 // Returns the pointer to the couple 97 // Returns the pointer to the couple 101 98 102 const G4MaterialCutsCouple* GetMaterialCut 99 const G4MaterialCutsCouple* GetMaterialCutsCouple(const G4Material* aMat, 103 co 100 const G4ProductionCuts* aCut) const; 104 // Returns the pointer to the couple 101 // Returns the pointer to the couple 105 102 106 G4int GetCoupleIndex(const G4MaterialCutsC 103 G4int GetCoupleIndex(const G4MaterialCutsCouple* aCouple) const; 107 G4int GetCoupleIndex(const G4Material* aMa 104 G4int GetCoupleIndex(const G4Material* aMat, 108 const G4ProductionCut 105 const G4ProductionCuts* aCut) const; 109 // Return the index of the couple. 106 // Return the index of the couple. 110 // -1 is returned if index is not found 107 // -1 is returned if index is not found 111 108 112 G4bool IsModified() const; 109 G4bool IsModified() const; 113 // Returns TRUE if at least one producti 110 // Returns TRUE if at least one production cut value is modified 114 111 115 void PhysicsTableUpdated(); 112 void PhysicsTableUpdated(); 116 // Resets the status of IsModified(). Th 113 // Resets the status of IsModified(). This method must be exclusively 117 // used by the RunManager when physics t 114 // used by the RunManager when physics tables are built 118 115 119 G4ProductionCuts* GetDefaultProductionCuts 116 G4ProductionCuts* GetDefaultProductionCuts() const; 120 // Returns the default production cuts 117 // Returns the default production cuts 121 118 122 G4double ConvertRangeToEnergy(const G4Part 119 G4double ConvertRangeToEnergy(const G4ParticleDefinition* particle, 123 const G4Mate 120 const G4Material* material, 124 G4doub 121 G4double range); 125 // Gives energy corresponding to range v 122 // Gives energy corresponding to range value. 126 // -1 is returned if particle or materia 123 // -1 is returned if particle or material is not found 127 124 128 void ResetConverters(); 125 void ResetConverters(); 129 // Resets all range to energy converters 126 // Resets all range to energy converters 130 127 131 G4bool StoreCutsTable(const G4String& dire 128 G4bool StoreCutsTable(const G4String& directory, 132 G4bool ascii = false 129 G4bool ascii = false); 133 // Stores cuts and material information 130 // Stores cuts and material information in files under the 134 // the specified directory 131 // the specified directory 135 132 136 G4bool RetrieveCutsTable(const G4String& d 133 G4bool RetrieveCutsTable(const G4String& directory, 137 G4bool ascii = fa 134 G4bool ascii = false); 138 // Retrieve material cut couple informat 135 // Retrieve material cut couple information 139 // in files under the specified director 136 // in files under the specified directory 140 137 141 G4bool CheckForRetrieveCutsTable(const G4S 138 G4bool CheckForRetrieveCutsTable(const G4String& directory, 142 G4bool as 139 G4bool ascii = false); 143 // Checks stored material and cut values 140 // Checks stored material and cut values are consistent 144 // with the current detector setup 141 // with the current detector setup 145 142 146 G4double* GetRangeCutsDoubleVector(std::si 143 G4double* GetRangeCutsDoubleVector(std::size_t pcIdx) const; 147 G4double* GetEnergyCutsDoubleVector(std::s 144 G4double* GetEnergyCutsDoubleVector(std::size_t pcIdx) const; 148 // Methods for backward compatibility 145 // Methods for backward compatibility 149 146 150 void SetEnergyCutVector(const std::vector< << 151 // User defined cut vectors (idx < 4) ra << 152 // to avoid inconsistency in physics << 153 << 154 void SetVerboseLevel(G4int value); 147 void SetVerboseLevel(G4int value); 155 G4int GetVerboseLevel() const; 148 G4int GetVerboseLevel() const; 156 // Control flag for output message 149 // Control flag for output message 157 // 0: Silent 150 // 0: Silent 158 // 1: Warning message 151 // 1: Warning message 159 // 2: More 152 // 2: More 160 153 161 protected: 154 protected: 162 155 163 G4ProductionCutsTable(); 156 G4ProductionCutsTable(); 164 157 165 virtual G4bool StoreMaterialInfo(const G4S 158 virtual G4bool StoreMaterialInfo(const G4String& directory, 166 G4bool as 159 G4bool ascii = false); 167 // Stores material information in files 160 // Stores material information in files under the specified directory 168 161 169 virtual G4bool CheckMaterialInfo(const G4S 162 virtual G4bool CheckMaterialInfo(const G4String& directory, 170 G4bool as 163 G4bool ascii = false); 171 // Checks stored material is consistent 164 // Checks stored material is consistent with the current detector setup 172 165 173 virtual G4bool StoreMaterialCutsCoupleInfo 166 virtual G4bool StoreMaterialCutsCoupleInfo(const G4String& directory, 174 167 G4bool ascii = false); 175 // Stores materialCutsCouple information 168 // Stores materialCutsCouple information in files under the 176 // specified directory 169 // specified directory 177 170 178 virtual G4bool CheckMaterialCutsCoupleInfo 171 virtual G4bool CheckMaterialCutsCoupleInfo(const G4String& directory, 179 172 G4bool ascii = false); 180 // Checks stored materialCutsCouple is c 173 // Checks stored materialCutsCouple is consistent with 181 // the current detector setup 174 // the current detector setup 182 175 183 virtual G4bool StoreCutsInfo(const G4Strin 176 virtual G4bool StoreCutsInfo(const G4String& directory, 184 G4bool ascii 177 G4bool ascii = false); 185 // Stores cut values information in file 178 // Stores cut values information in files under the specified directory 186 179 187 virtual G4bool RetrieveCutsInfo(const G4S 180 virtual G4bool RetrieveCutsInfo(const G4String& directory, 188 G4bool as 181 G4bool ascii = false); 189 // Retrieves cut values information in f 182 // Retrieves cut values information in files under the 190 // specified directory 183 // specified directory 191 184 192 private: 185 private: 193 186 194 void ScanAndSetCouple(G4LogicalVolume* aLV 187 void ScanAndSetCouple(G4LogicalVolume* aLV, 195 G4MaterialCutsCouple 188 G4MaterialCutsCouple* aCouple, 196 G4Region* aRegion); 189 G4Region* aRegion); 197 190 198 G4bool IsCoupleUsedInTheRegion(const G4Mat 191 G4bool IsCoupleUsedInTheRegion(const G4MaterialCutsCouple* aCouple, 199 const G4Reg 192 const G4Region* aRegion) const; 200 193 201 << 202 private: 194 private: 203 195 204 static G4ProductionCutsTable* fProductionC 196 static G4ProductionCutsTable* fProductionCutsTable; 205 197 206 std::vector<G4MaterialCutsCouple*> coupleT 198 std::vector<G4MaterialCutsCouple*> coupleTable; 207 std::vector<std::vector<G4double>*> rangeC 199 std::vector<std::vector<G4double>*> rangeCutTable; 208 std::vector<std::vector<G4double>*> energy 200 std::vector<std::vector<G4double>*> energyCutTable; 209 << 210 std::vector<G4double>* userEnergyCuts[4] = << 211 201 212 G4RegionStore* fG4RegionStore = nullptr; 202 G4RegionStore* fG4RegionStore = nullptr; 213 G4VRangeToEnergyConverter* converters[Numb 203 G4VRangeToEnergyConverter* converters[NumberOfG4CutIndex]; 214 204 215 G4ProductionCuts* defaultProductionCuts = 205 G4ProductionCuts* defaultProductionCuts = nullptr; 216 206 217 G4MCCIndexConversionTable mccConversionTab 207 G4MCCIndexConversionTable mccConversionTable; 218 208 219 // These two vectors are for backward comp 209 // These two vectors are for backward compatibility 220 G4double* rangeDoubleVector[NumberOfG4CutI 210 G4double* rangeDoubleVector[NumberOfG4CutIndex]; 221 G4double* energyDoubleVector[NumberOfG4Cut 211 G4double* energyDoubleVector[NumberOfG4CutIndex]; 222 212 223 enum { FixedStringLengthForStore = 32 }; 213 enum { FixedStringLengthForStore = 32 }; 224 214 225 G4ProductionCutsTableMessenger* fMessenger 215 G4ProductionCutsTableMessenger* fMessenger = nullptr; 226 G4int verboseLevel = 1; 216 G4int verboseLevel = 1; 227 G4bool firstUse = true; 217 G4bool firstUse = true; 228 }; 218 }; 229 219 230 // ------------------ 220 // ------------------ 231 // Inline methods 221 // Inline methods 232 // ------------------ 222 // ------------------ 233 223 234 inline 224 inline 235 const std::vector<G4double>* 225 const std::vector<G4double>* 236 G4ProductionCutsTable::GetRangeCutsVector(std: 226 G4ProductionCutsTable::GetRangeCutsVector(std::size_t pcIdx) const 237 { 227 { 238 return rangeCutTable[pcIdx]; 228 return rangeCutTable[pcIdx]; 239 } 229 } 240 230 241 inline 231 inline 242 const std::vector<G4double>* 232 const std::vector<G4double>* 243 G4ProductionCutsTable::GetEnergyCutsVector(std 233 G4ProductionCutsTable::GetEnergyCutsVector(std::size_t pcIdx) const 244 { 234 { 245 return energyCutTable[pcIdx]; 235 return energyCutTable[pcIdx]; 246 } 236 } 247 237 248 inline 238 inline 249 std::size_t G4ProductionCutsTable::GetTableSiz 239 std::size_t G4ProductionCutsTable::GetTableSize() const 250 { 240 { 251 return coupleTable.size(); 241 return coupleTable.size(); 252 } 242 } 253 243 254 inline 244 inline 255 const G4MaterialCutsCouple* 245 const G4MaterialCutsCouple* 256 G4ProductionCutsTable::GetMaterialCutsCouple(G 246 G4ProductionCutsTable::GetMaterialCutsCouple(G4int i) const 257 { 247 { 258 return coupleTable[std::size_t(i)]; 248 return coupleTable[std::size_t(i)]; 259 } 249 } 260 250 261 inline 251 inline 262 G4bool G4ProductionCutsTable::IsModified() con 252 G4bool G4ProductionCutsTable::IsModified() const 263 { 253 { 264 if(firstUse) return true; 254 if(firstUse) return true; 265 for(auto itr=coupleTable.cbegin(); itr!=coup 255 for(auto itr=coupleTable.cbegin(); itr!=coupleTable.cend(); ++itr) 266 { 256 { 267 if((*itr)->IsRecalcNeeded()) 257 if((*itr)->IsRecalcNeeded()) 268 { 258 { 269 return true; 259 return true; 270 } 260 } 271 } 261 } 272 return false; 262 return false; 273 } 263 } 274 264 275 inline 265 inline 276 void G4ProductionCutsTable::PhysicsTableUpdate 266 void G4ProductionCutsTable::PhysicsTableUpdated() 277 { 267 { 278 for(auto itr=coupleTable.cbegin(); itr!=coup 268 for(auto itr=coupleTable.cbegin(); itr!=coupleTable.cend(); ++itr) 279 { 269 { 280 (*itr)->PhysicsTableUpdated(); 270 (*itr)->PhysicsTableUpdated(); 281 } 271 } 282 } 272 } 283 273 284 inline 274 inline 285 G4double* 275 G4double* 286 G4ProductionCutsTable::GetRangeCutsDoubleVecto 276 G4ProductionCutsTable::GetRangeCutsDoubleVector(std::size_t pcIdx) const 287 { 277 { 288 return rangeDoubleVector[pcIdx]; 278 return rangeDoubleVector[pcIdx]; 289 } 279 } 290 280 291 inline 281 inline 292 G4double* 282 G4double* 293 G4ProductionCutsTable::GetEnergyCutsDoubleVect 283 G4ProductionCutsTable::GetEnergyCutsDoubleVector(std::size_t pcIdx) const 294 { 284 { 295 return energyDoubleVector[pcIdx]; 285 return energyDoubleVector[pcIdx]; 296 } 286 } 297 287 298 inline 288 inline 299 G4ProductionCuts* G4ProductionCutsTable::GetDe 289 G4ProductionCuts* G4ProductionCutsTable::GetDefaultProductionCuts() const 300 { 290 { 301 return defaultProductionCuts; 291 return defaultProductionCuts; 302 } 292 } 303 293 304 inline 294 inline 305 G4bool G4ProductionCutsTable::IsCoupleUsedInTh 295 G4bool G4ProductionCutsTable::IsCoupleUsedInTheRegion( 306 const G4Mater 296 const G4MaterialCutsCouple* aCouple, 307 const G4Regio 297 const G4Region* aRegion) const 308 { 298 { 309 G4ProductionCuts* fProductionCut = aRegion-> 299 G4ProductionCuts* fProductionCut = aRegion->GetProductionCuts(); 310 auto mItr = aRegion->GetMaterialIterator(); 300 auto mItr = aRegion->GetMaterialIterator(); 311 std::size_t nMaterial = aRegion->GetNumberOf 301 std::size_t nMaterial = aRegion->GetNumberOfMaterials(); 312 for(std::size_t iMate=0;iMate<nMaterial; ++i 302 for(std::size_t iMate=0;iMate<nMaterial; ++iMate, ++mItr) 313 { 303 { 314 if(aCouple->GetMaterial()==(*mItr) && 304 if(aCouple->GetMaterial()==(*mItr) && 315 aCouple->GetProductionCuts()==fProducti 305 aCouple->GetProductionCuts()==fProductionCut) 316 { 306 { 317 return true; 307 return true; 318 } 308 } 319 } 309 } 320 return false; 310 return false; 321 } 311 } 322 312 323 inline 313 inline 324 const G4MaterialCutsCouple* 314 const G4MaterialCutsCouple* 325 G4ProductionCutsTable::GetMaterialCutsCouple(c 315 G4ProductionCutsTable::GetMaterialCutsCouple(const G4Material* aMat, 326 c 316 const G4ProductionCuts* aCut) const 327 { 317 { 328 for(auto cItr=coupleTable.cbegin(); cItr!=co 318 for(auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr) 329 { 319 { 330 if((*cItr)->GetMaterial()!=aMat) continue; 320 if((*cItr)->GetMaterial()!=aMat) continue; 331 if((*cItr)->GetProductionCuts()==aCut) ret 321 if((*cItr)->GetProductionCuts()==aCut) return (*cItr); 332 } 322 } 333 return nullptr; 323 return nullptr; 334 } 324 } 335 325 336 inline 326 inline 337 G4int 327 G4int 338 G4ProductionCutsTable::GetCoupleIndex(const G4 328 G4ProductionCutsTable::GetCoupleIndex(const G4MaterialCutsCouple* aCouple) const 339 { 329 { 340 G4int idx = 0; 330 G4int idx = 0; 341 for(auto cItr=coupleTable.cbegin(); cItr!=co 331 for(auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr) 342 { 332 { 343 if((*cItr)==aCouple) return idx; 333 if((*cItr)==aCouple) return idx; 344 ++idx; 334 ++idx; 345 } 335 } 346 return -1; 336 return -1; 347 } 337 } 348 338 349 inline 339 inline 350 G4int G4ProductionCutsTable::GetCoupleIndex(co 340 G4int G4ProductionCutsTable::GetCoupleIndex(const G4Material* aMat, 351 co 341 const G4ProductionCuts* aCut) const 352 { 342 { 353 const G4MaterialCutsCouple* aCouple = GetMat 343 const G4MaterialCutsCouple* aCouple = GetMaterialCutsCouple(aMat,aCut); 354 return GetCoupleIndex(aCouple); 344 return GetCoupleIndex(aCouple); 355 } 345 } 356 346 357 inline 347 inline 358 G4int G4ProductionCutsTable::GetVerboseLevel() 348 G4int G4ProductionCutsTable::GetVerboseLevel() const 359 { 349 { 360 return verboseLevel; 350 return verboseLevel; 361 } 351 } 362 352 363 inline 353 inline 364 const G4MCCIndexConversionTable* 354 const G4MCCIndexConversionTable* 365 G4ProductionCutsTable::GetMCCIndexConversionTa 355 G4ProductionCutsTable::GetMCCIndexConversionTable() const 366 { 356 { 367 return &mccConversionTable; 357 return &mccConversionTable; 368 } 358 } 369 359 370 #endif 360 #endif 371 361