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 // G4PhysicsTableHelper class implementation 26 // G4PhysicsTableHelper class implementation 27 // 27 // 28 // Author: H.Kurashige, 20 August 2004 - First 28 // Author: H.Kurashige, 20 August 2004 - First implementation 29 // ------------------------------------------- 29 // -------------------------------------------------------------------- 30 30 31 #include "G4PhysicsTableHelper.hh" 31 #include "G4PhysicsTableHelper.hh" 32 #include "G4ProductionCutsTable.hh" 32 #include "G4ProductionCutsTable.hh" 33 #include "G4MCCIndexConversionTable.hh" 33 #include "G4MCCIndexConversionTable.hh" 34 #include "G4Threading.hh" 34 #include "G4Threading.hh" 35 #include "G4ios.hh" 35 #include "G4ios.hh" 36 36 37 G4int G4PhysicsTableHelper::verboseLevel = 1; 37 G4int G4PhysicsTableHelper::verboseLevel = 1; 38 38 39 // ------------------------------------------- 39 // -------------------------------------------------------------------- 40 G4PhysicsTableHelper::G4PhysicsTableHelper() 40 G4PhysicsTableHelper::G4PhysicsTableHelper() 41 { 41 { 42 } 42 } 43 43 44 // ------------------------------------------- 44 // -------------------------------------------------------------------- 45 G4PhysicsTableHelper::~G4PhysicsTableHelper() 45 G4PhysicsTableHelper::~G4PhysicsTableHelper() 46 { 46 { 47 } 47 } 48 48 49 // ------------------------------------------- 49 // -------------------------------------------------------------------- 50 G4PhysicsTable* 50 G4PhysicsTable* 51 G4PhysicsTableHelper::PreparePhysicsTable(G4Ph 51 G4PhysicsTableHelper::PreparePhysicsTable(G4PhysicsTable* physTable) 52 { 52 { 53 G4ProductionCutsTable* cutTable 53 G4ProductionCutsTable* cutTable 54 = G4ProductionCutsTable::GetProductionCuts 54 = G4ProductionCutsTable::GetProductionCutsTable(); 55 std::size_t numberOfMCC = cutTable->GetTable 55 std::size_t numberOfMCC = cutTable->GetTableSize(); 56 56 57 if ( physTable != nullptr ) 57 if ( physTable != nullptr ) 58 { 58 { 59 // compare size of physics table and numbe 59 // compare size of physics table and number of material-cuts-couple 60 if ( physTable->size() < numberOfMCC ) 60 if ( physTable->size() < numberOfMCC ) 61 { 61 { 62 #ifdef G4VERBOSE 62 #ifdef G4VERBOSE 63 if (verboseLevel>2) 63 if (verboseLevel>2) 64 { 64 { 65 G4cout << "G4PhysicsTableHelper::Prepa 65 G4cout << "G4PhysicsTableHelper::PreparePhysicsTable: " 66 << " the table " << physTable < 66 << " the table " << physTable << " size=" 67 << physTable->size() 67 << physTable->size() 68 << " will be is resized to " << 68 << " will be is resized to " << numberOfMCC << G4endl; 69 } 69 } 70 #endif 70 #endif 71 // enlarge physics table 71 // enlarge physics table 72 physTable->resize(numberOfMCC, nullptr); 72 physTable->resize(numberOfMCC, nullptr); 73 } 73 } 74 else if ( physTable->size() > numberOfMCC 74 else if ( physTable->size() > numberOfMCC ) 75 { 75 { 76 // ERROR: this situation should not occu 76 // ERROR: this situation should not occur 77 // size of physics table is larger than 77 // size of physics table is larger than number of material-cuts-couple 78 G4ExceptionDescription ed; 78 G4ExceptionDescription ed; 79 ed << "table " << physTable << " size=" 79 ed << "table " << physTable << " size=" << physTable->size() 80 << " is longer than number of material-cuts 80 << " is longer than number of material-cuts-couple " << numberOfMCC; 81 G4Exception( "G4PhysicsTableHelper::Prep 81 G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()", 82 "ProcCuts001", FatalExcepti 82 "ProcCuts001", FatalException, ed); 83 } 83 } 84 } 84 } 85 else 85 else 86 { 86 { 87 // create PhysicsTable is given poitner is 87 // create PhysicsTable is given poitner is null 88 physTable = new G4PhysicsTable(); 88 physTable = new G4PhysicsTable(); 89 physTable->resize(numberOfMCC, nullptr); 89 physTable->resize(numberOfMCC, nullptr); 90 } 90 } 91 91 92 #ifdef G4VERBOSE 92 #ifdef G4VERBOSE 93 if (verboseLevel>2) 93 if (verboseLevel>2) 94 { 94 { 95 G4cout << "G4PhysicsTableHelper::PreparePh 95 G4cout << "G4PhysicsTableHelper::PreparePhysicsTable: " 96 << " the table "<< physTable 96 << " the table "<< physTable 97 << " size=" << numberOfMCC << G4endl; 97 << " size=" << numberOfMCC << G4endl; 98 } 98 } 99 #endif 99 #endif 100 100 101 // Reset recal-needed flag for all physics v 101 // Reset recal-needed flag for all physics vectors 102 physTable->ResetFlagArray(); 102 physTable->ResetFlagArray(); 103 103 104 for (std::size_t idx = 0; idx <numberOfMCC; 104 for (std::size_t idx = 0; idx <numberOfMCC; ++idx) 105 { 105 { 106 const G4MaterialCutsCouple* mcc = cutTable << 106 const G4MaterialCutsCouple* mcc = cutTable->GetMaterialCutsCouple(idx); 107 107 108 // check if re-calculation of the physics 108 // check if re-calculation of the physics vector is needed 109 // MCC is not used 109 // MCC is not used 110 if ( !mcc->IsUsed() ) physTable->ClearFlag 110 if ( !mcc->IsUsed() ) physTable->ClearFlag(idx); 111 111 112 // RecalcNeeded flag of MCC is not asserte 112 // RecalcNeeded flag of MCC is not asserted 113 if ( !mcc->IsRecalcNeeded() ) physTable->C 113 if ( !mcc->IsRecalcNeeded() ) physTable->ClearFlag(idx); 114 } 114 } 115 115 116 return physTable; 116 return physTable; 117 } 117 } 118 118 119 // ------------------------------------------- 119 // -------------------------------------------------------------------- 120 G4bool G4PhysicsTableHelper::RetrievePhysicsTa 120 G4bool G4PhysicsTableHelper::RetrievePhysicsTable(G4PhysicsTable* physTable, 121 121 const G4String& fileName, 122 122 G4bool ascii, G4bool spline) 123 { 123 { 124 if (physTable == nullptr ) return false; 124 if (physTable == nullptr ) return false; 125 125 126 // retrieve physics table from the given fil 126 // retrieve physics table from the given file 127 G4PhysicsTable* tempTable = new G4PhysicsTab 127 G4PhysicsTable* tempTable = new G4PhysicsTable(); 128 if (! tempTable->RetrievePhysicsTable(fileNa 128 if (! tempTable->RetrievePhysicsTable(fileName,ascii,spline) ) 129 { 129 { 130 G4ExceptionDescription ed; 130 G4ExceptionDescription ed; 131 ed << "Cannot retrieve physics table from 131 ed << "Cannot retrieve physics table from the file <" << fileName << ">"; 132 G4Exception( "G4ProductionCutsTable::Retri 132 G4Exception( "G4ProductionCutsTable::RetrievePhysicsTable()", 133 "ProcCuts105", JustWarning, e 133 "ProcCuts105", JustWarning, ed); 134 delete tempTable; 134 delete tempTable; 135 return false; 135 return false; 136 } 136 } 137 137 138 G4ProductionCutsTable* cutTable 138 G4ProductionCutsTable* cutTable 139 = G4ProductionCutsTable::GetProductionCuts 139 = G4ProductionCutsTable::GetProductionCutsTable(); 140 const G4MCCIndexConversionTable* converter 140 const G4MCCIndexConversionTable* converter 141 = cutTable->GetMCCIndexConversionTable(); 141 = cutTable->GetMCCIndexConversionTable(); 142 142 143 // check physics table size 143 // check physics table size 144 if ( tempTable->size() != converter->size()) 144 if ( tempTable->size() != converter->size()) 145 { 145 { 146 G4ExceptionDescription ed; 146 G4ExceptionDescription ed; 147 ed << "Physics table in " << fileName 147 ed << "Physics table in " << fileName 148 << "\n size=" << tempTable->size() << 148 << "\n size=" << tempTable->size() << " " 149 << " is inconsistent with material-cut- 149 << " is inconsistent with material-cut-couple " 150 << "size=" << converter->size() << " th 150 << "size=" << converter->size() << " the table is not retrieved!"; 151 G4Exception("G4ProductionCutsTable::Retrie 151 G4Exception("G4ProductionCutsTable::RetrievePhysicsTable()", 152 "ProcCuts106", JustWarning, ed 152 "ProcCuts106", JustWarning, ed); 153 delete tempTable; 153 delete tempTable; 154 return false; 154 return false; 155 } 155 } 156 156 157 // fill the given physics table with retriev 157 // fill the given physics table with retrieved physics vectors 158 for (std::size_t idx=0; idx<converter->size( 158 for (std::size_t idx=0; idx<converter->size(); ++idx) 159 { 159 { 160 if (converter->IsUsed(idx)) 160 if (converter->IsUsed(idx)) 161 { 161 { 162 G4int i = converter->GetIndex(idx); 162 G4int i = converter->GetIndex(idx); 163 if(i < 0) 163 if(i < 0) 164 { 164 { 165 tempTable->clearAndDestroy(); 165 tempTable->clearAndDestroy(); 166 delete tempTable; 166 delete tempTable; 167 return false; 167 return false; 168 } 168 } 169 G4PhysicsVector* vec = (*physTable)[i]; 169 G4PhysicsVector* vec = (*physTable)[i]; 170 if (vec != nullptr ) delete vec; 170 if (vec != nullptr ) delete vec; 171 (*physTable)[i] = (*tempTable)[idx]; 171 (*physTable)[i] = (*tempTable)[idx]; 172 physTable->ClearFlag(i); 172 physTable->ClearFlag(i); 173 } 173 } 174 } 174 } 175 tempTable->clear(); 175 tempTable->clear(); 176 delete tempTable; 176 delete tempTable; 177 177 178 return true; 178 return true; 179 } 179 } 180 180 181 // ------------------------------------------- 181 // -------------------------------------------------------------------- 182 void G4PhysicsTableHelper::SetPhysicsVector(G4 182 void G4PhysicsTableHelper::SetPhysicsVector(G4PhysicsTable* physTable, 183 st 183 std::size_t idx, 184 G4 184 G4PhysicsVector* vec) 185 { 185 { 186 if ( physTable == nullptr) { return; } 186 if ( physTable == nullptr) { return; } 187 187 188 if ( physTable->size() <= idx) 188 if ( physTable->size() <= idx) 189 { 189 { 190 G4ExceptionDescription ed; 190 G4ExceptionDescription ed; 191 ed << "Given index (" << idx << ") exceed 191 ed << "Given index (" << idx << ") exceeds " 192 << "the size of the physics table " 192 << "the size of the physics table " 193 << "( size =" << physTable->size() << " 193 << "( size =" << physTable->size() << ") the vector is not added!"; 194 G4Exception("G4ProductionCutsTable::SetPhy 194 G4Exception("G4ProductionCutsTable::SetPhysicsVector()", 195 "ProcCuts107", 195 "ProcCuts107", 196 JustWarning, ed); 196 JustWarning, ed); 197 return; 197 return; 198 } 198 } 199 199 200 // set physics vector 200 // set physics vector 201 (*physTable)[idx] = vec; 201 (*physTable)[idx] = vec; 202 // clear flag 202 // clear flag 203 physTable->ClearFlag(idx); 203 physTable->ClearFlag(idx); 204 } 204 } 205 205 206 // ------------------------------------------- 206 // -------------------------------------------------------------------- 207 void G4PhysicsTableHelper::SetVerboseLevel(G4i 207 void G4PhysicsTableHelper::SetVerboseLevel(G4int value) 208 { 208 { 209 if( !G4Threading::IsWorkerThread() ) verbose 209 if( !G4Threading::IsWorkerThread() ) verboseLevel = value; 210 } 210 } 211 211 212 // ------------------------------------------- 212 // -------------------------------------------------------------------- 213 G4int G4PhysicsTableHelper::GetVerboseLevel() 213 G4int G4PhysicsTableHelper::GetVerboseLevel() 214 { 214 { 215 return verboseLevel; 215 return verboseLevel; 216 } 216 } 217 217