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