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.5 2004/12/02 06:53:56 kurasige Exp $ >> 25 // GEANT4 tag $Name: geant4-07-00-cand-03 $ 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 G4ProductionCuts; 42 55 43 #include "globals.hh" 56 #include "globals.hh" >> 57 #include <cmath> 44 #include "G4ios.hh" 58 #include "G4ios.hh" >> 59 #include <vector> 45 #include "G4MaterialCutsCouple.hh" 60 #include "G4MaterialCutsCouple.hh" 46 #include "G4MCCIndexConversionTable.hh" 61 #include "G4MCCIndexConversionTable.hh" 47 #include "G4Region.hh" 62 #include "G4Region.hh" 48 63 49 class G4RegionStore; << 50 class G4VRangeToEnergyConverter; << 51 class G4LogicalVolume; << 52 class G4VPhysicalVolume; << 53 class G4ProductionCuts; << 54 class G4ProductionCutsTableMessenger; << 55 64 56 class G4ProductionCutsTable 65 class G4ProductionCutsTable 57 { 66 { 58 public: << 67 public: // with description 59 << 60 static G4ProductionCutsTable* GetProductio 68 static G4ProductionCutsTable* GetProductionCutsTable(); 61 // This static method returns the single << 69 // This static method returns the singleton pointer of this class object. 62 // At first invocation, the singleton ob << 70 // At the first invokation of this method, the singleton object is instantiated. 63 71 64 G4ProductionCutsTable(const G4ProductionCu << 72 protected: 65 G4ProductionCutsTable& operator=(const G4P << 73 G4ProductionCutsTable(); >> 74 private: >> 75 G4ProductionCutsTable(const G4ProductionCutsTable& right); 66 76 >> 77 public: 67 virtual ~G4ProductionCutsTable(); 78 virtual ~G4ProductionCutsTable(); 68 79 69 void CreateCoupleTables(); << 80 public: // with description 70 // Creates material cuts couples table a << 81 void UpdateCoupleTable(); 71 << 82 // This method triggers an update of the table of G4ProductionCuts objects. 72 void UpdateCoupleTable(G4VPhysicalVolume* << 73 // Triggers an update of the table of G4 << 74 83 75 void SetEnergyRange(G4double lowedge, G4do 84 void SetEnergyRange(G4double lowedge, G4double highedge); 76 // Sets the limits of energy cuts for al << 85 // This method sets the limits of energy cuts for all particles. 77 86 78 G4double GetLowEdgeEnergy() const; 87 G4double GetLowEdgeEnergy() const; 79 G4double GetHighEdgeEnergy() const; 88 G4double GetHighEdgeEnergy() const; 80 // Get the limits of energy cuts for all << 89 // 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 90 87 void DumpCouples() const; 91 void DumpCouples() const; 88 // Displays a list of registered couples << 92 // Display a list of registored couples 89 93 90 const G4MCCIndexConversionTable* GetMCCInd 94 const G4MCCIndexConversionTable* GetMCCIndexConversionTable() const; 91 // Gives the pointer to the MCCIndexConv << 95 // gives the pointer to the MCCIndexConversionTable 92 << 93 const std::vector<G4double>* GetRangeCutsV << 94 const std::vector<G4double>* GetEnergyCuts << 95 << 96 std::size_t GetTableSize() const; << 97 // Returns the size of the couple table << 98 96 99 const G4MaterialCutsCouple* GetMaterialCut << 97 private: 100 // Returns the pointer to the couple << 101 98 102 const G4MaterialCutsCouple* GetMaterialCut << 99 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 100 112 G4bool IsModified() const; << 101 typedef std::vector<G4MaterialCutsCouple*> G4CoupleTable; 113 // Returns TRUE if at least one producti << 102 typedef std::vector<G4MaterialCutsCouple*>::const_iterator CoupleTableIterator; >> 103 typedef std::vector<G4double> G4CutVectorForAParticle; >> 104 typedef std::vector<G4CutVectorForAParticle*> G4CutTable; >> 105 G4CoupleTable coupleTable; >> 106 G4CutTable rangeCutTable; >> 107 G4CutTable energyCutTable; >> 108 >> 109 G4RegionStore* fG4RegionStore; >> 110 G4VRangeToEnergyConverter* converters[NumberOfG4CutIndex]; >> 111 >> 112 G4ProductionCuts* defaultProductionCuts; >> 113 >> 114 G4MCCIndexConversionTable mccConversionTable; >> 115 >> 116 // These two vectors are for the backward comparibility >> 117 G4double* rangeDoubleVector[NumberOfG4CutIndex]; >> 118 G4double* energyDoubleVector[NumberOfG4CutIndex]; >> 119 >> 120 public: >> 121 const std::vector<G4double>* GetRangeCutsVector(size_t pcIdx) const; >> 122 const std::vector<G4double>* GetEnergyCutsVector(size_t pcIdx) const; >> 123 >> 124 // These two vectors are for the backward comparibility >> 125 G4double* GetRangeCutsDoubleVector(size_t pcIdx) const; >> 126 G4double* GetEnergyCutsDoubleVector(size_t pcIdx) const; 114 127 115 void PhysicsTableUpdated(); << 128 public: // with description 116 // Resets the status of IsModified(). Th << 129 size_t GetTableSize() const; 117 // used by the RunManager when physics t << 130 // This method returns the size of the couple table. 118 << 131 119 G4ProductionCuts* GetDefaultProductionCuts << 132 const G4MaterialCutsCouple* GetMaterialCutsCouple(G4int i) const; 120 // Returns the default production cuts << 133 // This method returns the pointer to the couple. 121 << 134 122 G4double ConvertRangeToEnergy(const G4Part << 135 const G4MaterialCutsCouple* 123 const G4Mate << 136 GetMaterialCutsCouple(const G4Material* aMat, 124 G4doub << 137 const G4ProductionCuts* aCut) const; 125 // Gives energy corresponding to range v << 138 // This method returns the pointer to the couple. 126 // -1 is returned if particle or materia << 139 127 << 140 G4int GetCoupleIndex(const G4MaterialCutsCouple* aCouple) const; 128 void ResetConverters(); << 141 G4int GetCoupleIndex(const G4Material* aMat, 129 // Resets all range to energy converters << 142 const G4ProductionCuts* aCut) const; 130 << 143 // These methods return the index of the couple. 131 G4bool StoreCutsTable(const G4String& dire << 144 // -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 145 >> 146 G4bool IsModified() const; >> 147 // This method returns TRUE if at least one production cut value is modified. >> 148 >> 149 void PhysicsTableUpdated(); >> 150 // This method resets the status of IsModified(). This method must >> 151 // be exclusively used by RunManager when physics tables are built. >> 152 >> 153 G4ProductionCuts* GetDefaultProductionCuts() const; >> 154 // This method returns the default production cuts. >> 155 192 private: 156 private: 193 << 194 void ScanAndSetCouple(G4LogicalVolume* aLV 157 void ScanAndSetCouple(G4LogicalVolume* aLV, 195 G4MaterialCutsCouple << 158 G4MaterialCutsCouple* aCouple, 196 G4Region* aRegion); << 159 G4Region* aRegion); 197 160 198 G4bool IsCoupleUsedInTheRegion(const G4Mat << 161 bool IsCoupleUsedInTheRegion(const G4MaterialCutsCouple* aCouple, 199 const G4Reg << 162 const G4Region* aRegion) const; 200 163 >> 164 public: // with description >> 165 // Store cuts and material information in files under the specified directory. >> 166 G4bool StoreCutsTable(const G4String& directory, >> 167 G4bool ascii = false); >> 168 >> 169 // Retrieve material cut couple information >> 170 // in files under the specified directory. >> 171 G4bool RetrieveCutsTable(const G4String& directory, >> 172 G4bool ascii = false); >> 173 >> 174 // check stored material and cut values are consistent with the current detector setup. >> 175 G4bool CheckForRetrieveCutsTable(const G4String& directory, >> 176 G4bool ascii = false); 201 177 202 private: << 178 protected: 203 << 204 static G4ProductionCutsTable* fProductionC << 205 << 206 std::vector<G4MaterialCutsCouple*> coupleT << 207 std::vector<std::vector<G4double>*> rangeC << 208 std::vector<std::vector<G4double>*> energy << 209 << 210 std::vector<G4double>* userEnergyCuts[4] = << 211 << 212 G4RegionStore* fG4RegionStore = nullptr; << 213 G4VRangeToEnergyConverter* converters[Numb << 214 179 215 G4ProductionCuts* defaultProductionCuts = << 180 // Store material information in files under the specified directory. >> 181 virtual G4bool StoreMaterialInfo(const G4String& directory, >> 182 G4bool ascii = false); >> 183 >> 184 // check stored material is consistent with the current detector setup. >> 185 virtual G4bool CheckMaterialInfo(const G4String& directory, >> 186 G4bool ascii = false); >> 187 >> 188 // Store materialCutsCouple information in files under the specified directory. >> 189 virtual G4bool StoreMaterialCutsCoupleInfo(const G4String& directory, >> 190 G4bool ascii = false); >> 191 >> 192 // check stored materialCutsCouple is consistent with the current detector setup. >> 193 virtual G4bool CheckMaterialCutsCoupleInfo(const G4String& directory, >> 194 G4bool ascii = false); >> 195 >> 196 // Store cut values information in files under the specified directory. >> 197 virtual G4bool StoreCutsInfo(const G4String& directory, >> 198 G4bool ascii = false); >> 199 >> 200 // Retrieve cut values information in files under the specified directory. >> 201 virtual G4bool RetrieveCutsInfo(const G4String& directory, >> 202 G4bool ascii = false); 216 203 217 G4MCCIndexConversionTable mccConversionTab << 204 private: >> 205 G4bool firstUse; >> 206 enum { FixedStringLengthForStore = 32 }; 218 207 219 // These two vectors are for backward comp << 208 public: // with description 220 G4double* rangeDoubleVector[NumberOfG4CutI << 209 void SetVerboseLevel(G4int value); 221 G4double* energyDoubleVector[NumberOfG4Cut << 210 G4int GetVerboseLevel() const; >> 211 // controle flag for output message >> 212 // 0: Silent >> 213 // 1: Warning message >> 214 // 2: More 222 215 223 enum { FixedStringLengthForStore = 32 }; << 216 private: >> 217 G4int verboseLevel; 224 218 225 G4ProductionCutsTableMessenger* fMessenger << 226 G4int verboseLevel = 1; << 227 G4bool firstUse = true; << 228 }; 219 }; 229 220 230 // ------------------ << 231 // Inline methods << 232 // ------------------ << 233 << 234 inline 221 inline 235 const std::vector<G4double>* << 222 const std::vector<G4double>* G4ProductionCutsTable::GetRangeCutsVector(size_t pcIdx) const 236 G4ProductionCutsTable::GetRangeCutsVector(std: << 237 { 223 { 238 return rangeCutTable[pcIdx]; 224 return rangeCutTable[pcIdx]; 239 } 225 } 240 226 241 inline 227 inline 242 const std::vector<G4double>* << 228 const std::vector<G4double>* G4ProductionCutsTable::GetEnergyCutsVector(size_t pcIdx) const 243 G4ProductionCutsTable::GetEnergyCutsVector(std << 244 { 229 { 245 return energyCutTable[pcIdx]; << 230 return energyCutTable[pcIdx]; 246 } 231 } 247 232 248 inline 233 inline 249 std::size_t G4ProductionCutsTable::GetTableSiz << 234 size_t G4ProductionCutsTable::GetTableSize() const 250 { 235 { 251 return coupleTable.size(); 236 return coupleTable.size(); 252 } 237 } 253 238 254 inline 239 inline 255 const G4MaterialCutsCouple* << 240 const G4MaterialCutsCouple* G4ProductionCutsTable::GetMaterialCutsCouple(G4int i) const 256 G4ProductionCutsTable::GetMaterialCutsCouple(G << 257 { 241 { 258 return coupleTable[std::size_t(i)]; << 242 return coupleTable[size_t(i)]; 259 } 243 } 260 244 261 inline 245 inline 262 G4bool G4ProductionCutsTable::IsModified() con << 246 G4bool G4ProductionCutsTable::IsModified() const 263 { 247 { 264 if(firstUse) return true; 248 if(firstUse) return true; 265 for(auto itr=coupleTable.cbegin(); itr!=coup << 249 for(G4ProductionCutsTable::CoupleTableIterator itr=coupleTable.begin(); 266 { << 250 itr!=coupleTable.end();itr++){ 267 if((*itr)->IsRecalcNeeded()) 251 if((*itr)->IsRecalcNeeded()) 268 { 252 { 269 return true; 253 return true; 270 } 254 } 271 } 255 } 272 return false; 256 return false; 273 } 257 } 274 258 275 inline 259 inline 276 void G4ProductionCutsTable::PhysicsTableUpdate << 260 void G4ProductionCutsTable::PhysicsTableUpdated() 277 { 261 { 278 for(auto itr=coupleTable.cbegin(); itr!=coup << 262 for(G4ProductionCutsTable::CoupleTableIterator itr=coupleTable.begin();itr!=coupleTable.end();itr++){ 279 { << 280 (*itr)->PhysicsTableUpdated(); 263 (*itr)->PhysicsTableUpdated(); 281 } 264 } 282 } 265 } 283 266 284 inline 267 inline 285 G4double* << 268 G4double* G4ProductionCutsTable::GetRangeCutsDoubleVector(size_t pcIdx) const 286 G4ProductionCutsTable::GetRangeCutsDoubleVecto << 269 { return rangeDoubleVector[pcIdx]; } 287 { << 288 return rangeDoubleVector[pcIdx]; << 289 } << 290 270 291 inline 271 inline 292 G4double* << 272 G4double* G4ProductionCutsTable::GetEnergyCutsDoubleVector(size_t pcIdx) const 293 G4ProductionCutsTable::GetEnergyCutsDoubleVect << 273 { return energyDoubleVector[pcIdx]; } 294 { << 295 return energyDoubleVector[pcIdx]; << 296 } << 297 274 298 inline 275 inline 299 G4ProductionCuts* G4ProductionCutsTable::GetDe << 276 G4ProductionCuts* G4ProductionCutsTable::GetDefaultProductionCuts() const 300 { << 277 { return defaultProductionCuts; } 301 return defaultProductionCuts; << 302 } << 303 278 304 inline 279 inline 305 G4bool G4ProductionCutsTable::IsCoupleUsedInTh << 280 bool G4ProductionCutsTable::IsCoupleUsedInTheRegion( 306 const G4Mater 281 const G4MaterialCutsCouple* aCouple, 307 const G4Regio 282 const G4Region* aRegion) const 308 { 283 { 309 G4ProductionCuts* fProductionCut = aRegion-> 284 G4ProductionCuts* fProductionCut = aRegion->GetProductionCuts(); 310 auto mItr = aRegion->GetMaterialIterator(); << 285 std::vector<G4Material*>::const_iterator mItr = aRegion->GetMaterialIterator(); 311 std::size_t nMaterial = aRegion->GetNumberOf << 286 size_t nMaterial = aRegion->GetNumberOfMaterials(); 312 for(std::size_t iMate=0;iMate<nMaterial; ++i << 287 for(size_t iMate=0;iMate<nMaterial;iMate++, mItr++){ 313 { << 314 if(aCouple->GetMaterial()==(*mItr) && 288 if(aCouple->GetMaterial()==(*mItr) && 315 aCouple->GetProductionCuts()==fProducti << 289 aCouple->GetProductionCuts()==fProductionCut){ 316 { << 317 return true; 290 return true; 318 } 291 } 319 } 292 } 320 return false; 293 return false; 321 } 294 } 322 295 323 inline 296 inline 324 const G4MaterialCutsCouple* 297 const G4MaterialCutsCouple* 325 G4ProductionCutsTable::GetMaterialCutsCouple(c << 298 G4ProductionCutsTable::GetMaterialCutsCouple(const G4Material* aMat, 326 c << 299 const G4ProductionCuts* aCut) const 327 { << 300 { 328 for(auto cItr=coupleTable.cbegin(); cItr!=co << 301 for(CoupleTableIterator cItr=coupleTable.begin();cItr!=coupleTable.end();cItr++) 329 { 302 { 330 if((*cItr)->GetMaterial()!=aMat) continue; 303 if((*cItr)->GetMaterial()!=aMat) continue; 331 if((*cItr)->GetProductionCuts()==aCut) ret 304 if((*cItr)->GetProductionCuts()==aCut) return (*cItr); 332 } 305 } 333 return nullptr; << 306 return 0; 334 } 307 } 335 308 336 inline 309 inline 337 G4int << 310 G4int G4ProductionCutsTable::GetCoupleIndex(const G4MaterialCutsCouple* aCouple) const 338 G4ProductionCutsTable::GetCoupleIndex(const G4 << 339 { 311 { 340 G4int idx = 0; 312 G4int idx = 0; 341 for(auto cItr=coupleTable.cbegin(); cItr!=co << 313 for(CoupleTableIterator cItr=coupleTable.begin();cItr!=coupleTable.end();cItr++) 342 { 314 { 343 if((*cItr)==aCouple) return idx; 315 if((*cItr)==aCouple) return idx; 344 ++idx; << 316 idx++; 345 } 317 } 346 return -1; 318 return -1; 347 } 319 } 348 320 349 inline 321 inline 350 G4int G4ProductionCutsTable::GetCoupleIndex(co << 322 G4int G4ProductionCutsTable:: GetCoupleIndex(const G4Material* aMat, 351 co << 323 const G4ProductionCuts* aCut) const 352 { 324 { 353 const G4MaterialCutsCouple* aCouple = GetMat 325 const G4MaterialCutsCouple* aCouple = GetMaterialCutsCouple(aMat,aCut); 354 return GetCoupleIndex(aCouple); 326 return GetCoupleIndex(aCouple); 355 } 327 } 356 328 357 inline 329 inline 358 G4int G4ProductionCutsTable::GetVerboseLevel() << 330 void G4ProductionCutsTable::SetVerboseLevel(G4int value) 359 { 331 { 360 return verboseLevel; << 332 verboseLevel = value; >> 333 } >> 334 >> 335 inline >> 336 G4int G4ProductionCutsTable::GetVerboseLevel() const >> 337 { >> 338 return verboseLevel; 361 } 339 } 362 340 363 inline 341 inline 364 const G4MCCIndexConversionTable* << 342 const G4MCCIndexConversionTable* 365 G4ProductionCutsTable::GetMCCIndexConversionTa << 343 G4ProductionCutsTable::GetMCCIndexConversionTable() const 366 { 344 { 367 return &mccConversionTable; 345 return &mccConversionTable; 368 } 346 } 369 347 370 #endif 348 #endif >> 349 >> 350 >> 351 >> 352 >> 353 >> 354 371 355