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